3 const { TemplateHelper
} = require('@squeep/html-template-helper');
6 * Render a topic as a row of details.
7 * @param {Object} topic
8 * @param {Object[]} subscribers
9 * @param {Boolean} detailsLink
12 function renderTopicRow(topic
, subscribers
, detailsLink
= true) {
15 <th colspan="15">(topic not found)</th>
19 <th scope="row">${detailsLink ? '<a href="topic/' + topic.id + '">' : ''}${topic.url}${detailsLink ? '</a>' : ''}</th>
20 <td>${subscribers.length}</td>
21 <td>${TemplateHelper.dateFormat(topic.created, 'End of Time', 'Beginning of Time', 'Unknown')}</td>
22 <td>${TemplateHelper.secondsToPeriod(topic.leaseSecondsPreferred)}</td>
23 <td>${TemplateHelper.secondsToPeriod(topic.leaseSecondsMin)}</td>
24 <td>${TemplateHelper.secondsToPeriod(topic.leaseSecondsMax)}</td>
25 <td>${topic.publisherValidationUrl ? topic.publisherValidationUrl : 'None'}</td>
26 <td>${topic.isActive}</td>
27 <td>${topic.isDeleted}</td>
28 <td>${TemplateHelper.dateFormat(topic.lastPublish, 'End of Time', 'Never', 'Never')}</td>
29 <td>${TemplateHelper.dateFormat(topic.contentFetchNextAttempt, 'Next Publish', 'Pending', 'Next Publish')}</td>
30 <td>${topic.contentFetchAttemptsSinceSuccess}</td>
31 <td>${TemplateHelper.dateFormat(topic.contentUpdated, 'End of Time', 'Never', 'Never')}</td>
32 <td>${topic.contentType}</td>
39 * Render the header row for topic details.
42 function renderTopicRowHeader() {
44 <th scope="col">Topic URL</th>
45 <th scope="col">Subscribers</th>
46 <th scope="col">Created</th>
47 <th scope="col">Lease Time Preferred</th>
48 <th scope="col">Lease Time Minimum</th>
49 <th scope="col">Lease Time Maximum</th>
50 <th scope="col">Publisher Validation URL</th>
51 <th scope="col">Active</th>
52 <th scope="col">Deleted</th>
53 <th scope="col">Last Publish Notification</th>
54 <th scope="col">Next Content Fetch</th>
55 <th scope="col">Content Fetch Failures</th>
56 <th scope="col">Content Updated</th>
57 <th scope="col">Content Type</th>
58 <th scope="col">Internal Id</th>
64 * Render a subscription as a row of details.
65 * @param {Object} subscription
68 function renderSubscriptionRow(subscription
) {
71 <th colspan="12">(topic not found)</th>
75 <td scope="row">${subscription.callback}</td>
76 <td>${TemplateHelper.dateFormat(subscription.created, 'End of Time', 'Beginning of Time', 'Unknown')}</td>
77 <td>${TemplateHelper.dateFormat(subscription.verified, 'End of Time', 'Never', 'Never')}</td>
78 <td>${TemplateHelper.dateFormat(subscription.expires, 'Never', 'Beginning of Time', 'Never')}</td>
79 <td>${!!subscription.secret}</td>
80 <td>${subscription.signatureAlgorithm}</td>
81 <td>${subscription.httpRemoteAddr}</td>
82 <td>${subscription.httpFrom}</td>
83 <td>${TemplateHelper.dateFormat(subscription.contentDelivered, 'End of Time', 'Never', 'Never')}</td>
84 <td>${subscription.deliveryAttemptsSinceSuccess}</td>
85 <td>${TemplateHelper.dateFormat(subscription.deliveryNextAttempt, 'End of Time', 'Next Publish', 'Next Publish')}</td>
86 <td>${subscription.id}</td>
92 * Render a row of headers for subscription details.
95 function renderSubscriptionRowHeader() {
97 <th scope="col">Callback URL</th>
98 <th scope="col">Created</th>
99 <th scope="col">Verified</th>
100 <th scope="col">Expires</th>
101 <th scope="col">Using Secret</th>
102 <th scope="col">Signature Type</th>
103 <th scope="col">Remote Address</th>
104 <th scope="col">From</th>
105 <th scope="col">Content Delivered</th>
106 <th scope="col">Content Delivery Failures</th>
107 <th scope="col">Next Delivery</th>
108 <th scope="col">Internal Id</th>
115 * Escape some xml things in strings.
116 * @param {String} string
118 function xmlEscape(string
) {
119 if (typeof string
=== 'number') {
122 if (typeof string
!== 'string') {
125 // eslint-disable-next-line security/detect-object-injection
126 return string
.replace(/[<>&'"]/, (c
) => ({
135 module
.exports
= Object
.assign(Object
.create(TemplateHelper
), {
137 renderTopicRowHeader
,
139 renderSubscriptionRowHeader
,
140 renderSubscriptionRow
,