"error",
"single"
],
+ "semi": [
+ "error",
+ "always"
+ ],
"strict": "error",
"vars-on-top": "error"
}
}
});
return o;
-}
+};
/**
let seconds = retryBackoffSeconds[attempt];
seconds += Math.floor(Math.random() * seconds * jitter);
return seconds;
-}
+};
/**
const arrayChunk = (array, per = 1) => {
const nChunks = Math.ceil(array.length / per);
return Array.from(Array(nChunks), (_, i) => array.slice(i * per, (i + 1) * per));
-}
+};
/**
arrayChunk(src, jsEngineMaxArguments).forEach((items) => {
Array.prototype.push.apply(dst, items);
});
-}
+};
/**
const topic = await this.db.topicGetById(dbCtx, verification.topicId);
if (!topic) {
- this.logger.error(_scope, 'no such topic id', { verification, requestId });
- throw new Errors.InternalInconsistencyError('no such topic id');
+ this.logger.error(_scope, Enum.Message.NoSuchTopicId, { verification, requestId });
+ throw new Errors.InternalInconsistencyError(Enum.Message.NoSuchTopicId);
}
if (!topic.isActive) {
const topic = await this.db.topicGetById(dbCtx, topicId);
if (topic === undefined) {
- this.logger.error(_scope, 'no such topic id', logInfoData);
- throw new Errors.InternalInconsistencyError('no such topic id');
+ this.logger.error(_scope, Enum.Message.NoSuchTopicId, logInfoData);
+ throw new Errors.InternalInconsistencyError(Enum.Message.NoSuchTopicId);
}
// Cull any expired subscriptions
* @param {Object} data
*/
_leaseDurationsValidate(data) {
- const leaseProperties = Object.keys(this.topicLeaseDefaults)
+ const leaseProperties = Object.keys(this.topicLeaseDefaults);
this._ensureTypes(data, leaseProperties, ['number', 'undefined', 'null']);
// Populate defaults on a copy of values so we can check proper numerical ordering
throw new DBErrors.UnexpectedResult('did not upsert authentication');
}
} catch (e) {
- this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential })
+ this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential });
throw e;
}
}
throw new DBErrors.UnexpectedResult('did not upsert authentication');
}
} catch (e) {
- this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential })
+ this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential });
throw e;
}
}
httpRemoteAddr: null,
httpFrom: null,
...data,
- }
+ };
this._subscriptionUpsertDataValidate(subscriptionData);
let result;
topicPublishHistory(dbCtx, topicId, days) {
const _scope = _fileScope('topicPublishHistory');
- this.logger.debug(_scope, 'called', { topicId, days })
+ this.logger.debug(_scope, 'called', { topicId, days });
const events = this.statement.topicPublishHistory.all({ topicId, daysAgo: days });
const history = Array.from({ length: days }, () => 0);
+ // eslint-disable-next-line security/detect-object-injection
events.forEach(({ daysAgo, contentUpdates }) => history[daysAgo] = Number(contentUpdates));
return history;
ImageSVG: 'image/svg+xml',
TextXML: 'text/xml',
},
+
+ Message : {
+ BeginningOfTime: 'Beginning of Time',
+ EndOfTime: 'End of Time',
+ Never: 'Never',
+ NextPublish: 'Next Publish',
+ NoSuchTopicId: 'no such topic id',
+ Pending: 'Pending',
+ Unknown: 'Unknown',
+ },
});
module.exports = common.freezeDeep(Enum);
\ No newline at end of file
'use strict';
const { TemplateHelper } = require('@squeep/html-template-helper');
+const { Message } = require('../enum');
/**
* Render a topic as a row of details.
return `<tr>
<th scope="row">${detailsLink ? '<a href="topic/' + topic.id + '">' : ''}${topic.url}${detailsLink ? '</a>' : ''}</th>
<td>${subscribers.length}</td>
- <td>${TemplateHelper.dateFormat(topic.created, 'End of Time', 'Beginning of Time', 'Unknown')}</td>
+ <td>${TemplateHelper.dateFormat(topic.created, Message.EndOfTime, Message.BeginningOfTime, Message.Unknown)}</td>
<td>${TemplateHelper.secondsToPeriod(topic.leaseSecondsPreferred)}</td>
<td>${TemplateHelper.secondsToPeriod(topic.leaseSecondsMin)}</td>
<td>${TemplateHelper.secondsToPeriod(topic.leaseSecondsMax)}</td>
<td>${topic.publisherValidationUrl ? topic.publisherValidationUrl : 'None'}</td>
<td>${topic.isActive}</td>
<td>${topic.isDeleted}</td>
- <td>${TemplateHelper.dateFormat(topic.lastPublish, 'End of Time', 'Never', 'Never')}</td>
- <td>${TemplateHelper.dateFormat(topic.contentFetchNextAttempt, 'Next Publish', 'Pending', 'Next Publish')}</td>
+ <td>${TemplateHelper.dateFormat(topic.lastPublish, Message.EndOfTime, Message.Never, Message.Never)}</td>
+ <td>${TemplateHelper.dateFormat(topic.contentFetchNextAttempt, Message.NextPublish, Message.Pending, Message.NextPublish)}</td>
<td>${topic.contentFetchAttemptsSinceSuccess}</td>
- <td>${TemplateHelper.dateFormat(topic.contentUpdated, 'End of Time', 'Never', 'Never')}</td>
+ <td>${TemplateHelper.dateFormat(topic.contentUpdated, Message.EndOfTime, Message.Never, Message.Never)}</td>
<td>${topic.contentType}</td>
<td>${topic.id}</td>
</tr>`;
}
return `<tr>
<td scope="row">${subscription.callback}</td>
- <td>${TemplateHelper.dateFormat(subscription.created, 'End of Time', 'Beginning of Time', 'Unknown')}</td>
- <td>${TemplateHelper.dateFormat(subscription.verified, 'End of Time', 'Never', 'Never')}</td>
- <td>${TemplateHelper.dateFormat(subscription.expires, 'Never', 'Beginning of Time', 'Never')}</td>
+ <td>${TemplateHelper.dateFormat(subscription.created, Message.EndOfTime, Message.BeginningOfTime, Message.Unknown)}</td>
+ <td>${TemplateHelper.dateFormat(subscription.verified, Message.EndOfTime, Message.Never, Message.Never)}</td>
+ <td>${TemplateHelper.dateFormat(subscription.expires, Message.Never, Message.BeginningOfTime, Message.Never)}</td>
<td>${!!subscription.secret}</td>
<td>${subscription.signatureAlgorithm}</td>
<td>${subscription.httpRemoteAddr}</td>
<td>${subscription.httpFrom}</td>
- <td>${TemplateHelper.dateFormat(subscription.contentDelivered, 'End of Time', 'Never', 'Never')}</td>
+ <td>${TemplateHelper.dateFormat(subscription.contentDelivered, Message.EndOfTime, Message.Never, Message.Never)}</td>
<td>${subscription.deliveryAttemptsSinceSuccess}</td>
- <td>${TemplateHelper.dateFormat(subscription.deliveryNextAttempt, 'End of Time', 'Next Publish', 'Next Publish')}</td>
+ <td>${TemplateHelper.dateFormat(subscription.deliveryNextAttempt, Message.EndOfTime, Message.NextPublish, Message.NextPublish)}</td>
<td>${subscription.id}</td>
</tr>`;
}