emailengine-app 2.78.0 → 2.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/.ncurc.js +23 -13
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +29 -0
  4. package/config/e2e.toml +2 -1
  5. package/config/test.toml +2 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/lib/account.js +70 -35
  8. package/lib/api-reference/format.js +91 -4
  9. package/lib/api-reference/model.js +144 -19
  10. package/lib/api-reference/schema-tree.js +282 -28
  11. package/lib/api-routes/account-routes.js +80 -34
  12. package/lib/api-routes/blocklist-routes.js +21 -47
  13. package/lib/api-routes/chat-routes.js +10 -12
  14. package/lib/api-routes/delivery-test-routes.js +6 -26
  15. package/lib/api-routes/export-routes.js +2 -0
  16. package/lib/api-routes/gateway-routes.js +52 -11
  17. package/lib/api-routes/license-routes.js +2 -0
  18. package/lib/api-routes/mailbox-routes.js +29 -26
  19. package/lib/api-routes/message-routes.js +27 -21
  20. package/lib/api-routes/oauth2-app-routes.js +11 -29
  21. package/lib/api-routes/operation-impact.js +80 -0
  22. package/lib/api-routes/outbox-routes.js +15 -5
  23. package/lib/api-routes/permission-map.js +397 -0
  24. package/lib/api-routes/route-helpers.js +223 -9
  25. package/lib/api-routes/route-metadata.js +28 -0
  26. package/lib/api-routes/settings-routes.js +30 -25
  27. package/lib/api-routes/stats-routes.js +2 -2
  28. package/lib/api-routes/submit-routes.js +53 -31
  29. package/lib/api-routes/template-routes.js +3 -0
  30. package/lib/api-routes/token-routes.js +319 -33
  31. package/lib/api-routes/webhook-route-routes.js +14 -4
  32. package/lib/auth-token.js +80 -8
  33. package/lib/consts.js +10 -0
  34. package/lib/db.js +20 -2
  35. package/lib/delivery-error.js +30 -1
  36. package/lib/email-client/base-client.js +27 -41
  37. package/lib/email-client/gmail-client.js +19 -10
  38. package/lib/email-client/imap/mailbox.js +23 -24
  39. package/lib/email-client/imap/subconnection.js +10 -7
  40. package/lib/email-client/imap/sync-operations.js +46 -46
  41. package/lib/email-client/imap-client.js +36 -26
  42. package/lib/email-client/message-builder.js +3 -3
  43. package/lib/email-client/notification-handler.js +1 -1
  44. package/lib/email-client/outlook/graph-api.js +10 -4
  45. package/lib/email-client/outlook-client.js +53 -54
  46. package/lib/email-client/smtp-pool-manager.js +1 -1
  47. package/lib/enum-descriptions.js +92 -2
  48. package/lib/export.js +1 -1
  49. package/lib/field-usage.js +133 -0
  50. package/lib/gateway.js +1 -1
  51. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  52. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  53. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  54. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  55. package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
  56. package/lib/imapproxy/imap-server.js +27 -7
  57. package/lib/license-beacon.js +4 -9
  58. package/lib/lists.js +49 -1
  59. package/lib/llm-pre-process.js +5 -5
  60. package/lib/logger.js +5 -1
  61. package/lib/metrics-collector.js +2 -2
  62. package/lib/oauth/gmail.js +9 -12
  63. package/lib/oauth/mail-ru.js +5 -7
  64. package/lib/oauth/outlook.js +9 -9
  65. package/lib/oauth/pubsub/google.js +25 -10
  66. package/lib/oauth/scope-checker.js +1 -1
  67. package/lib/oauth2-apps.js +223 -294
  68. package/lib/openapi/build-document.js +15 -7
  69. package/lib/openapi/joi-schema.js +20 -0
  70. package/lib/outbox.js +85 -17
  71. package/lib/pre-process.js +8 -8
  72. package/lib/queue-stats.js +49 -0
  73. package/lib/read-env-value.js +1 -1
  74. package/lib/reconnection-manager.js +2 -2
  75. package/lib/rewrite-text-nodes.js +4 -3
  76. package/lib/routes-ui.js +4 -0
  77. package/lib/schemas.js +216 -160
  78. package/lib/settings.js +84 -5
  79. package/lib/sub-script.js +2 -1
  80. package/lib/swagger-options.js +2 -1
  81. package/lib/templates.js +4 -4
  82. package/lib/threads.js +2 -2
  83. package/lib/token-audit-log.js +208 -0
  84. package/lib/token-permission-view.js +219 -0
  85. package/lib/token-permissions.js +172 -0
  86. package/lib/tokens.js +99 -15
  87. package/lib/tools.js +142 -37
  88. package/lib/ui-routes/account-routes.js +31 -11
  89. package/lib/ui-routes/admin-config-routes.js +18 -10
  90. package/lib/ui-routes/admin-entities-routes.js +66 -22
  91. package/lib/ui-routes/auth-routes.js +30 -24
  92. package/lib/ui-routes/export-routes.js +10 -4
  93. package/lib/ui-routes/oauth-config-routes.js +5 -5
  94. package/lib/ui-routes/reference-routes.js +3 -3
  95. package/lib/ui-routes/route-helpers.js +51 -2
  96. package/lib/ui-routes/settings-page.js +1 -1
  97. package/lib/ui-routes/smtp-test-routes.js +1 -1
  98. package/lib/ui-routes/suppression-list-routes.js +294 -0
  99. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  100. package/lib/utils/network.js +2 -2
  101. package/lib/web-safe-html.js +1 -1
  102. package/lib/webhook-routing.js +80 -0
  103. package/lib/webhooks.js +20 -14
  104. package/package.json +11 -10
  105. package/sbom.json +1 -1
  106. package/server.js +80 -41
  107. package/static/css/flyonui.css +1 -1
  108. package/static/css/src/app.tailwind.css +136 -9
  109. package/static/js/reference.js +456 -10
  110. package/static/js/ui.js +43 -0
  111. package/static/licenses.html +51 -41
  112. package/translations/messages.pot +59 -59
  113. package/views/accounts/account.hbs +69 -7
  114. package/views/accounts/browse.hbs +18 -35
  115. package/views/config/logging.hbs +6 -0
  116. package/views/config/oauth/app.hbs +0 -2
  117. package/views/config/security.hbs +13 -0
  118. package/views/partials/oauth_form.hbs +0 -15
  119. package/views/partials/reference/disclosure.hbs +8 -2
  120. package/views/partials/reference/operation.hbs +47 -13
  121. package/views/partials/reference/params.hbs +17 -1
  122. package/views/partials/reference/schema-node.hbs +110 -52
  123. package/views/partials/reference/schema-tools.hbs +25 -0
  124. package/views/partials/reference/try-it.hbs +84 -11
  125. package/views/partials/side_menu.hbs +1 -0
  126. package/views/partials/ui/checkbox.hbs +2 -2
  127. package/views/partials/ui/tabs.hbs +7 -1
  128. package/views/reference/token.hbs +4 -0
  129. package/views/suppression-lists/index.hbs +85 -0
  130. package/views/suppression-lists/list.hbs +87 -0
  131. package/views/templates/index.hbs +8 -2
  132. package/views/tokens/index.hbs +31 -4
  133. package/views/tokens/new.hbs +324 -2
  134. package/workers/api.js +146 -57
  135. package/workers/documents.js +46 -26
  136. package/workers/export.js +20 -8
  137. package/workers/imap-proxy.js +2 -2
  138. package/workers/imap.js +12 -6
  139. package/workers/smtp.js +13 -7
  140. package/workers/submit.js +40 -30
  141. package/workers/webhooks.js +59 -25
  142. package/lib/feature-flags.js +0 -48
@@ -25,14 +25,13 @@ const { STATUS_CODES } = require('node:http');
25
25
  const Joi = require('joi');
26
26
 
27
27
  const { SchemaConverter, deleteEmptyProperties } = require('./joi-schema');
28
+ const { pluginOptions } = require('../api-routes/route-metadata');
29
+ const { routeGrant } = require('../api-routes/permission-map');
28
30
 
29
31
  // Routes opt into the document by carrying this tag. It is an internal marker rather than a
30
32
  // documentation tag, so it is filtered back out of the published tag list.
31
33
  const API_ROUTE_TAG = 'api';
32
34
 
33
- // Where a route keeps the documentation metadata that its joi schemas cannot express
34
- const PLUGIN_OPTIONS_KEY = 'openapi';
35
-
36
35
  const DEFAULT_MEDIA_TYPE = 'application/json';
37
36
 
38
37
  // Operations of one path are documented in the order a reader expects to meet them
@@ -69,10 +68,6 @@ function statusText(code) {
69
68
  return (STATUS_CODES[code] || 'Successful').replace('OK', 'Successful');
70
69
  }
71
70
 
72
- function pluginOptions(route) {
73
- return (route.settings.plugins && route.settings.plugins[PLUGIN_OPTIONS_KEY]) || {};
74
- }
75
-
76
71
  // Copies x-* keys onto the target. Anything a route declares under a vendor extension is published
77
72
  // verbatim, which is how x-ee-behavior reaches the API reference.
78
73
  function assignVendorExtensions(target, source) {
@@ -128,6 +123,19 @@ class DocumentBuilder {
128
123
 
129
124
  assignVendorExtensions(operation, options);
130
125
 
126
+ // What a narrowed access token needs to call this operation. Published so a customer can
127
+ // read the requirement off the document instead of inferring it, and so anything deriving a
128
+ // tool list from /swagger.json (an MCP layer, say) gets the permission with it rather than
129
+ // hardcoding a second copy.
130
+ //
131
+ // Derived rather than declared, so it cannot disagree with what the auth strategy enforces -
132
+ // both call routeGrant(). An unresolved half is null, which deleteEmptyProperties drops
133
+ // below; that only happens when the route table and permission-map.js have diverged, which
134
+ // test/api-routes-table-test.js fails on.
135
+ const grant = routeGrant(route);
136
+ operation['x-ee-action'] = grant.action;
137
+ operation['x-ee-group'] = grant.group;
138
+
131
139
  return { path: route.path, method: route.method.toLowerCase(), operation: deleteEmptyProperties(operation) };
132
140
  }
133
141
 
@@ -275,6 +275,20 @@ class SchemaConverter {
275
275
  markRequired();
276
276
  }
277
277
 
278
+ // `then` only, and `otherwise` deliberately not. It looks like an omission - `imap.host` is
279
+ // required unless `disabled` is set, and an unbound access token has to set `permissions`,
280
+ // and both say so in `otherwise`, so reading only `then` publishes them as optional. Adding
281
+ // the second branch was tried and reverted, because a flat `required` array cannot hold two
282
+ // sides of an exclusive choice: `CreateOAuth2App` then required `clientId`, `clientSecret`
283
+ // and `redirectUrl` alongside `serviceClient` and `serviceClientEmail`, which are the
284
+ // gmailService half of the same `when` and forbid the other three. No request body satisfies
285
+ // that, where before at least the gmailService one did. Response schemas made it worse -
286
+ // `IMAPResponse` gained `host`/`port`, which a strict generated client refuses to
287
+ // deserialize when the server legitimately omits them.
288
+ //
289
+ // So the rule is: flatten a condition only where doing so cannot describe an impossible
290
+ // body. A requirement that lives in `otherwise` belongs in the field's description instead,
291
+ // which is where POST /v1/tokens states it.
278
292
  for (const when of description.whens || []) {
279
293
  if (when.then && when.then.flags && when.then.flags.presence === 'required') {
280
294
  markRequired();
@@ -385,6 +399,12 @@ class SchemaConverter {
385
399
  }
386
400
 
387
401
  parseObject(property, description, context) {
402
+ // The same pair parseArray() publishes, under the object spelling. `.min(1)` on an object is
403
+ // how "at least one of these axes" is said in joi, and a token narrowing that lists neither
404
+ // is refused - so leaving it out documented `{}` as an acceptable body.
405
+ property.minProperties = ruleArg(description.rules, 'min');
406
+ property.maxProperties = ruleArg(description.rules, 'max');
407
+
388
408
  property.properties = {};
389
409
 
390
410
  for (const key of Object.keys(description.keys || {})) {
package/lib/outbox.js CHANGED
@@ -3,10 +3,16 @@
3
3
  const { submitQueue, redis } = require('./db');
4
4
  const { REDIS_PREFIX } = require('../lib/consts');
5
5
 
6
- // Job removals are issued in bounded batches. ioredis writes each command as it is issued, so a
7
- // batch costs one round trip rather than one per job, while the bound keeps an account with a huge
8
- // outbox from putting an unlimited number of Lua scripts in flight at once.
9
- const REMOVE_BATCH_SIZE = 100;
6
+ // Job reads and removals are issued in bounded batches. ioredis writes each command as it is
7
+ // issued, so a batch costs one round trip rather than one per job, while the bound keeps an account
8
+ // with a huge outbox from putting an unlimited number of Lua scripts in flight at once.
9
+ const BATCH_SIZE = 100;
10
+
11
+ // The states an outbox entry can be in, in the order they concatenate into the listing. 'waiting',
12
+ // not 'wait': getRanges() accepts either, but getJobCounts() keys its result only by 'waiting', so
13
+ // 'wait' read back undefined and left total/pages at 0. There is no 'paused' either - BullMQ 6
14
+ // dropped it as a job state and reports the jobs of a paused queue as waiting.
15
+ const JOB_STATES = ['delayed', 'waiting', 'active', 'failed'];
10
16
 
11
17
  function outboxKey(account) {
12
18
  return `${REDIS_PREFIX}iaq:${account}`;
@@ -34,30 +40,88 @@ function formatQueueEntry(job) {
34
40
  });
35
41
  }
36
42
 
43
+ /**
44
+ * Maps a page of the outbox onto a sub-range of each job state.
45
+ *
46
+ * The outbox is the concatenation of the submit queue's per-state lists, in the order given, and
47
+ * the job counts already say how long each one is - which is enough to work out how much of the
48
+ * requested window falls in which state. Asking getRanges() for [start, end] across all the states
49
+ * at once instead (what this used to do) applies that range to every state separately, so a page
50
+ * came back holding up to pageSize entries PER state, and page 1 skipped the first pageSize entries
51
+ * of each state rather than the first pageSize entries overall.
52
+ *
53
+ * @param {String[]} jobStates - Job states, in the order they concatenate into the outbox
54
+ * @param {Object} jobCounts - Job count per state, as returned by Queue#getJobCounts()
55
+ * @param {Number} start - Index of the first entry of the page, within the concatenated list
56
+ * @param {Number} pageSize - How many entries the page holds at most
57
+ * @returns {Object[]} `{ state, start, end }` ranges, inclusive, totalling at most pageSize entries
58
+ */
59
+ function selectPageRanges(jobStates, jobCounts, start, pageSize) {
60
+ let ranges = [];
61
+ let remaining = pageSize;
62
+ // How many entries the states already walked hold between them
63
+ let precedingEntries = 0;
64
+
65
+ for (let state of jobStates) {
66
+ if (remaining <= 0) {
67
+ break;
68
+ }
69
+
70
+ let stateLength = Number(jobCounts[state]) || 0;
71
+ // Clamped to 0 once the page has started in an earlier state, in which case this one is
72
+ // read from its first entry
73
+ let from = Math.max(start - precedingEntries, 0);
74
+ precedingEntries += stateLength;
75
+
76
+ // Also covers a page that begins past the end of this state, where from >= stateLength
77
+ let take = Math.min(stateLength - from, remaining);
78
+ if (take > 0) {
79
+ ranges.push({ state, start: from, end: from + take - 1 });
80
+ remaining -= take;
81
+ }
82
+ }
83
+
84
+ return ranges;
85
+ }
86
+
37
87
  async function list(options) {
38
88
  options = options || {};
39
89
  let page = Number(options.page) || 0;
40
90
  let pageSize = Number(options.pageSize) || 20;
41
91
  let logger = options.logger;
42
92
 
43
- let jobCounts = await submitQueue.getJobCounts();
93
+ let jobCounts = await submitQueue.getJobCounts(...JOB_STATES);
44
94
 
45
- let jobStates = ['delayed', 'paused', 'wait', 'active', 'failed'];
95
+ let totalJobs = JOB_STATES.map(state => Number(jobCounts[state]) || 0).reduce((previousValue, currentValue) => previousValue + currentValue);
46
96
 
47
- let totalJobs = jobStates.map(state => Number(jobCounts[state]) || 0).reduce((previousValue, currentValue) => previousValue + currentValue);
97
+ // The counts above and the ranges below are separate reads, so a job that changes state in
98
+ // between can be listed twice or missed. That is inherent to paging a live queue without
99
+ // locking it, and the next request reflects the queue as it then stands.
100
+ let ranges = selectPageRanges(JOB_STATES, jobCounts, page * pageSize, pageSize);
48
101
 
49
- let jobIds = await submitQueue.getRanges(jobStates, page * pageSize, page * pageSize + pageSize - 1, true);
102
+ let idsPerRange = await Promise.all(ranges.map(range => submitQueue.getRanges([range.state], range.start, range.end, true)));
103
+ let jobIds = idsPerRange.flat();
50
104
 
105
+ // Queue#getJobs() is this same id-fetch-plus-getJob, but with an unbounded Promise.all and no
106
+ // per-entry error handling: one unreadable job would reject the whole page. Batched here
107
+ // instead, the same shape as removeJobs() below, because pageSize goes up to 1000.
51
108
  let messages = [];
109
+ for (let i = 0; i < jobIds.length; i += BATCH_SIZE) {
110
+ let batch = await Promise.all(
111
+ jobIds.slice(i, i + BATCH_SIZE).map(async jobId => {
112
+ try {
113
+ return await submitQueue.getJob(jobId);
114
+ } catch (err) {
115
+ logger.error({ msg: 'Failed to retrieve message info from outbox', jobId, err });
116
+ return null;
117
+ }
118
+ })
119
+ );
52
120
 
53
- for (let jobId of jobIds) {
54
- try {
55
- let job = await submitQueue.getJob(jobId);
121
+ for (let job of batch) {
56
122
  if (job) {
57
123
  messages.push(formatQueueEntry(job));
58
124
  }
59
- } catch (err) {
60
- logger.error({ msg: 'Failed to retrieve message info from outbox', jobId, err });
61
125
  }
62
126
  }
63
127
 
@@ -94,7 +158,7 @@ async function del(options) {
94
158
  // Delete job entry
95
159
  try {
96
160
  await job.remove();
97
- logger.info({ msg: 'Remove queue entry', account: job.data.account, queueId: job.data.queueId, messageId: job.data.messageId });
161
+ logger.info({ msg: 'Removed queue entry', account: job.data.account, queueId: job.data.queueId, messageId: job.data.messageId });
98
162
  return true;
99
163
  } catch (err) {
100
164
  logger.error({ msg: 'Failed to remove queue entry', account: job.data.account, queueId: job.data.queueId, messageId: job.data.messageId, err });
@@ -161,8 +225,8 @@ async function removeJobs(queueIds, options) {
161
225
 
162
226
  let removed = 0;
163
227
 
164
- for (let i = 0; i < queueIds.length; i += REMOVE_BATCH_SIZE) {
165
- let batch = queueIds.slice(i, i + REMOVE_BATCH_SIZE);
228
+ for (let i = 0; i < queueIds.length; i += BATCH_SIZE) {
229
+ let batch = queueIds.slice(i, i + BATCH_SIZE);
166
230
 
167
231
  let results = await Promise.all(
168
232
  batch.map(async queueId => {
@@ -184,4 +248,8 @@ async function removeJobs(queueIds, options) {
184
248
  return removed;
185
249
  }
186
250
 
187
- module.exports = { list, del, get, removeJobs };
251
+ // selectPageRanges is exported for its own tests: it is the pagination arithmetic, and exercising it
252
+ // through list() alone would need a queue populated across all four states to cover the cases.
253
+ // selectPageRanges and JOB_STATES are exported for the pagination tests: exercising the arithmetic
254
+ // through list() alone would need a queue populated across all four states to cover the cases.
255
+ module.exports = { list, del, get, removeJobs, selectPageRanges, JOB_STATES };
@@ -40,7 +40,7 @@ class PreProcessHandler {
40
40
  } catch (err) {
41
41
  await this.storeLog('filter', null, err.stack);
42
42
 
43
- logger.error({ msg: 'Compilation failed', type: 'filter', err });
43
+ logger.error({ msg: 'Failed to compile pre-processing script', component: 'pre-process', type: 'filter', err });
44
44
  preProcessData.compiledFn = null;
45
45
  preProcessData.compiledMap = null;
46
46
  }
@@ -55,7 +55,7 @@ class PreProcessHandler {
55
55
  } catch (err) {
56
56
  await this.storeLog('map', null, err.stack);
57
57
 
58
- logger.error({ msg: 'Compilation failed', type: 'map', err });
58
+ logger.error({ msg: 'Failed to compile pre-processing script', component: 'pre-process', type: 'map', err });
59
59
  preProcessData.compiledFn = null;
60
60
  preProcessData.compiledMap = null;
61
61
  }
@@ -67,7 +67,7 @@ class PreProcessHandler {
67
67
  return await preProcessData.compiledFn.exec(payload);
68
68
  } catch (err) {
69
69
  await this.storeLog('filter', payload, err.stack);
70
- logger.error({ msg: 'Exec failed', type: 'filter', err });
70
+ logger.error({ msg: 'Failed to execute pre-processing script', component: 'pre-process', type: 'filter', err });
71
71
  return null;
72
72
  }
73
73
  };
@@ -79,7 +79,7 @@ class PreProcessHandler {
79
79
  return preProcessData.compiledMap.exec(payload);
80
80
  } catch (err) {
81
81
  await this.storeLog('map', payload, err.stack);
82
- logger.error({ msg: 'Exec failed', type: 'map', err });
82
+ logger.error({ msg: 'Failed to execute pre-processing script', component: 'pre-process', type: 'map', err });
83
83
  return null;
84
84
  }
85
85
  };
@@ -111,7 +111,7 @@ class PreProcessHandler {
111
111
  try {
112
112
  await redis.multi().rpush(this.getPreProcessLogKey(), logRow).ltrim(this.getPreProcessLogKey(), -maxLogLines, -1).exec();
113
113
  } catch (err) {
114
- logger.error({ msg: 'Failed to insert error log entries', err });
114
+ logger.error({ msg: 'Failed to insert error log entries', component: 'pre-process', err });
115
115
  }
116
116
  }
117
117
 
@@ -128,7 +128,7 @@ class PreProcessHandler {
128
128
  let entry = msgpack.decode(line);
129
129
  logEntries.unshift(entry);
130
130
  } catch (err) {
131
- logger.error({ msg: 'Failed to retrieve log line', entry: line && line.toString('base64') });
131
+ logger.error({ msg: 'Failed to decode log line', component: 'pre-process', entry: line && line.toString('base64'), err });
132
132
  }
133
133
  }
134
134
 
@@ -155,7 +155,7 @@ class PreProcessHandler {
155
155
  } catch (err) {
156
156
  await this.storeLog('filter', payload, err.stack);
157
157
 
158
- logger.error({ msg: 'Exec failed', type: 'filter', err });
158
+ logger.error({ msg: 'Failed to execute pre-processing script', component: 'pre-process', type: 'filter', err });
159
159
  }
160
160
 
161
161
  if (canStore) {
@@ -176,7 +176,7 @@ class PreProcessHandler {
176
176
  } catch (err) {
177
177
  await this.storeLog('map', payload, err.stack);
178
178
 
179
- logger.error({ msg: 'Exec failed', type: 'map', err });
179
+ logger.error({ msg: 'Failed to execute pre-processing script', component: 'pre-process', type: 'map', err });
180
180
  canStore = false;
181
181
  }
182
182
  }
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Job counts for the BullMQ queues, read through BullMQ's own API.
5
+ *
6
+ * Both the /v1/stats payload and the GET /v1/settings/queue/{queue} route used to count queues by
7
+ * issuing raw llen/zcard/hget against BullMQ's internal key layout (`bull:<queue>:active`, `:wait`,
8
+ * `:delayed`, `:meta`). That layout is private and it moved under us in the 5.x -> 6.x bump, which
9
+ * removed the `<queue>:paused` list - and because `llen` on a missing key returns 0 rather than an
10
+ * error, both surfaces would have gone on silently reporting zeroes instead of failing. The public
11
+ * getter also subtracts the deprecated `0:` wait-list marker that a queue carried over from a 5.x
12
+ * install still holds, which a raw `llen` counts as if it were a job.
13
+ */
14
+
15
+ // Counted states, chosen to match the two payloads this backs rather than BullMQ's full set:
16
+ // completed and failed jobs are retained separately (see EENGINE_QUEUE_KEEP_FAILED) and are not
17
+ // pending work. `prioritized` is not counted either - nothing in EmailEngine queues with a
18
+ // priority, and adding it would add a key to two published payloads.
19
+ const COUNTED_STATES = ['active', 'delayed', 'waiting'];
20
+
21
+ /**
22
+ * Counts the pending jobs of a queue and reports whether the queue is paused.
23
+ *
24
+ * @param {Object} queueObj - BullMQ Queue instance
25
+ * @returns {Promise<Object>} `active`, `delayed` and `waiting` counts plus their `total`, the
26
+ * `isPaused` flag, and a `paused` count that is always 0 - BullMQ 6 no longer parks jobs in a
27
+ * separate paused list, so a paused queue holds them in `waiting` and they are counted there.
28
+ * The key is kept because it is part of both published payloads.
29
+ */
30
+ async function queueStats(queueObj) {
31
+ const [counts, isPaused] = await Promise.all([queueObj.getJobCounts(...COUNTED_STATES), queueObj.isPaused()]);
32
+
33
+ const stats = {
34
+ paused: 0,
35
+ isPaused: !!isPaused
36
+ };
37
+
38
+ let total = 0;
39
+ for (const state of COUNTED_STATES) {
40
+ const count = Number(counts[state]) || 0;
41
+ stats[state] = count;
42
+ total += count;
43
+ }
44
+ stats.total = total;
45
+
46
+ return stats;
47
+ }
48
+
49
+ module.exports = { queueStats, COUNTED_STATES };
@@ -27,7 +27,7 @@ function readEnvValue(key) {
27
27
  process.env[key] = Fs.readFileSync(process.env[`${key}_FILE`], 'utf-8').replace(/\r?\n/g, '\n').trim();
28
28
  logger.trace({ msg: 'Loaded environment value from file', key, file: process.env[`${key}_FILE`] });
29
29
  } catch (err) {
30
- logger.fatal({ msg: 'Failed to load environment value from file', key, file: process.env[`${key}_FILE`], err });
30
+ logger.error({ msg: 'Failed to load environment value from file', key, file: process.env[`${key}_FILE`], err });
31
31
  process.env[key] = '';
32
32
  }
33
33
  return process.env[key];
@@ -64,7 +64,7 @@ class ReconnectionManager {
64
64
  const delay = this.getNextDelay();
65
65
 
66
66
  if (this.logger) {
67
- this.logger.info({
67
+ this.logger.debug({
68
68
  msg: 'Waiting before reconnection attempt',
69
69
  delay,
70
70
  attempt: this.attempts
@@ -80,7 +80,7 @@ class ReconnectionManager {
80
80
  } catch (err) {
81
81
  // Don't reset, keep incrementing delay
82
82
  if (this.logger) {
83
- this.logger.error({
83
+ this.logger.warn({
84
84
  msg: 'Reconnection attempt failed',
85
85
  attempt: this.attempts,
86
86
  err
@@ -7,6 +7,7 @@ const encodingJapanese = require('encoding-japanese');
7
7
  const { Transform } = require('stream');
8
8
  const iconv = require('iconv-lite');
9
9
  const LeWindows = require('nodemailer/lib/mime-node/le-windows');
10
+ const logger = require('./logger').child({ component: 'rewrite-text-nodes' });
10
11
 
11
12
  class JPDecoder extends Transform {
12
13
  constructor(charset) {
@@ -40,7 +41,7 @@ class JPDecoder extends Transform {
40
41
  }
41
42
  this.push(output);
42
43
  } catch (err) {
43
- console.error(err);
44
+ logger.debug({ msg: 'Failed to convert Japanese charset, keeping original content', charset: this.charset, err });
44
45
  // keep as is on errors
45
46
  this.push(input);
46
47
  }
@@ -116,7 +117,7 @@ function rewriteTextNodes(source, options) {
116
117
  contentStream.pipe(decodeStream);
117
118
  decoder = decodeStream;
118
119
  } catch (err) {
119
- console.error(err);
120
+ logger.debug({ msg: 'Failed to create charset decode stream, keeping original charset', charset: data.node.charset, err });
120
121
  // do not decode charset
121
122
  }
122
123
  }
@@ -163,7 +164,7 @@ function rewriteTextNodes(source, options) {
163
164
  data.encoder.end(Buffer.from(formattedHtml, 'utf-8'));
164
165
  })
165
166
  .catch(err => {
166
- console.error(err);
167
+ logger.warn({ msg: 'Failed to rewrite text node, keeping original content', err });
167
168
  // keep original value
168
169
  data.encoder.end(htmlBuf);
169
170
  return;
package/lib/routes-ui.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const adminEntitiesRoutes = require('./ui-routes/admin-entities-routes');
4
4
  const smtpTestRoutes = require('./ui-routes/smtp-test-routes');
5
5
  const unsubscribeRoutes = require('./ui-routes/unsubscribe-routes');
6
+ const suppressionListRoutes = require('./ui-routes/suppression-list-routes');
6
7
  const internalsRoutes = require('./ui-routes/internals-routes');
7
8
  const dashboardRoutes = require('./ui-routes/dashboard-routes');
8
9
  const referenceRoutes = require('./ui-routes/reference-routes');
@@ -24,6 +25,9 @@ function applyRoutes(server, call) {
24
25
  // Public subscription-management (unsubscribe) routes
25
26
  unsubscribeRoutes({ server, call });
26
27
 
28
+ // Suppression list management (the store behind the Blocklists API)
29
+ suppressionListRoutes({ server });
30
+
27
31
  // System internals / threads tools routes
28
32
  internalsRoutes({ server, call });
29
33