emailengine-app 2.78.0 → 2.79.1
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.
- package/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +68 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +112 -36
- package/lib/api-reference/format.js +91 -4
- package/lib/api-reference/model.js +144 -19
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +80 -34
- package/lib/api-routes/blocklist-routes.js +21 -47
- package/lib/api-routes/chat-routes.js +10 -12
- package/lib/api-routes/delivery-test-routes.js +6 -26
- package/lib/api-routes/export-routes.js +2 -0
- package/lib/api-routes/gateway-routes.js +52 -11
- package/lib/api-routes/license-routes.js +2 -0
- package/lib/api-routes/mailbox-routes.js +29 -26
- package/lib/api-routes/message-routes.js +27 -21
- package/lib/api-routes/oauth2-app-routes.js +11 -29
- package/lib/api-routes/operation-impact.js +80 -0
- package/lib/api-routes/outbox-routes.js +15 -5
- package/lib/api-routes/permission-map.js +401 -0
- package/lib/api-routes/route-helpers.js +294 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +66 -38
- package/lib/api-routes/stats-routes.js +2 -2
- package/lib/api-routes/submit-routes.js +53 -31
- package/lib/api-routes/template-routes.js +3 -0
- package/lib/api-routes/token-routes.js +526 -72
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/arf-detect.js +17 -4
- package/lib/auth-token.js +80 -8
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +16 -0
- package/lib/db.js +26 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +23 -17
- package/lib/email-client/imap/mailbox.js +58 -59
- package/lib/email-client/imap/subconnection.js +10 -7
- package/lib/email-client/imap/sync-operations.js +46 -46
- package/lib/email-client/imap-client.js +85 -28
- package/lib/email-client/message-builder.js +3 -3
- package/lib/email-client/notification-handler.js +1 -1
- package/lib/email-client/outlook/graph-api.js +10 -4
- package/lib/email-client/outlook-client.js +56 -64
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +1 -1
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +1 -1
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
- package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
- package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
- package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
- package/lib/imapproxy/imap-server.js +27 -7
- package/lib/license-beacon.js +4 -9
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +5 -5
- package/lib/logger.js +5 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +290 -292
- package/lib/openapi/build-document.js +20 -8
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +85 -17
- package/lib/pre-process.js +8 -8
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +1 -1
- package/lib/reconnection-manager.js +2 -2
- package/lib/rewrite-text-nodes.js +4 -3
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +218 -162
- package/lib/settings.js +98 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +4 -4
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +231 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +247 -66
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +42 -15
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +117 -38
- package/lib/ui-routes/auth-routes.js +30 -24
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +12 -12
- package/lib/ui-routes/reference-routes.js +3 -3
- package/lib/ui-routes/route-helpers.js +78 -2
- package/lib/ui-routes/settings-page.js +1 -1
- package/lib/ui-routes/smtp-test-routes.js +1 -1
- package/lib/ui-routes/suppression-list-routes.js +299 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +84 -0
- package/lib/webhooks.js +48 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +116 -55
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +136 -9
- package/static/js/reference.js +456 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +51 -41
- package/translations/messages.pot +59 -59
- package/views/accounts/account.hbs +75 -13
- package/views/accounts/browse.hbs +19 -36
- package/views/accounts/edit.hbs +2 -2
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/operation.hbs +47 -13
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +110 -52
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/try-it.hbs +84 -11
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/checkbox.hbs +2 -2
- package/views/partials/ui/tabs.hbs +7 -1
- package/views/reference/token.hbs +4 -0
- package/views/suppression-lists/index.hbs +85 -0
- package/views/suppression-lists/list.hbs +87 -0
- package/views/templates/index.hbs +10 -4
- package/views/templates/template.hbs +1 -1
- package/views/tokens/index.hbs +53 -6
- package/views/tokens/new.hbs +334 -5
- package/workers/api.js +185 -102
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +77 -78
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +80 -26
- package/lib/feature-flags.js +0 -48
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
// response.schema -> the 200 response body
|
|
19
19
|
// plugins.openapi.responses -> the documented status codes (see apiResponses in lib/schemas.js)
|
|
20
20
|
// plugins.openapi.produces -> the media type for routes that do not return JSON
|
|
21
|
+
// plugins.openapi.deprecated -> the route is left out of the document (compatibility aliases)
|
|
21
22
|
// plugins.openapi['x-*'] -> vendor extensions on the operation, notably x-ee-behavior
|
|
22
23
|
|
|
23
24
|
const { STATUS_CODES } = require('node:http');
|
|
@@ -25,14 +26,13 @@ const { STATUS_CODES } = require('node:http');
|
|
|
25
26
|
const Joi = require('joi');
|
|
26
27
|
|
|
27
28
|
const { SchemaConverter, deleteEmptyProperties } = require('./joi-schema');
|
|
29
|
+
const { pluginOptions } = require('../api-routes/route-metadata');
|
|
30
|
+
const { routeGrant } = require('../api-routes/permission-map');
|
|
28
31
|
|
|
29
32
|
// Routes opt into the document by carrying this tag. It is an internal marker rather than a
|
|
30
33
|
// documentation tag, so it is filtered back out of the published tag list.
|
|
31
34
|
const API_ROUTE_TAG = 'api';
|
|
32
35
|
|
|
33
|
-
// Where a route keeps the documentation metadata that its joi schemas cannot express
|
|
34
|
-
const PLUGIN_OPTIONS_KEY = 'openapi';
|
|
35
|
-
|
|
36
36
|
const DEFAULT_MEDIA_TYPE = 'application/json';
|
|
37
37
|
|
|
38
38
|
// Operations of one path are documented in the order a reader expects to meet them
|
|
@@ -69,10 +69,6 @@ function statusText(code) {
|
|
|
69
69
|
return (STATUS_CODES[code] || 'Successful').replace('OK', 'Successful');
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
function pluginOptions(route) {
|
|
73
|
-
return (route.settings.plugins && route.settings.plugins[PLUGIN_OPTIONS_KEY]) || {};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
72
|
// Copies x-* keys onto the target. Anything a route declares under a vendor extension is published
|
|
77
73
|
// verbatim, which is how x-ee-behavior reaches the API reference.
|
|
78
74
|
function assignVendorExtensions(target, source) {
|
|
@@ -128,6 +124,19 @@ class DocumentBuilder {
|
|
|
128
124
|
|
|
129
125
|
assignVendorExtensions(operation, options);
|
|
130
126
|
|
|
127
|
+
// What a narrowed access token needs to call this operation. Published so a customer can
|
|
128
|
+
// read the requirement off the document instead of inferring it, and so anything deriving a
|
|
129
|
+
// tool list from /swagger.json (an MCP layer, say) gets the permission with it rather than
|
|
130
|
+
// hardcoding a second copy.
|
|
131
|
+
//
|
|
132
|
+
// Derived rather than declared, so it cannot disagree with what the auth strategy enforces -
|
|
133
|
+
// both call routeGrant(). An unresolved half is null, which deleteEmptyProperties drops
|
|
134
|
+
// below; that only happens when the route table and permission-map.js have diverged, which
|
|
135
|
+
// test/api-routes-table-test.js fails on.
|
|
136
|
+
const grant = routeGrant(route);
|
|
137
|
+
operation['x-ee-action'] = grant.action;
|
|
138
|
+
operation['x-ee-group'] = grant.group;
|
|
139
|
+
|
|
131
140
|
return { path: route.path, method: route.method.toLowerCase(), operation: deleteEmptyProperties(operation) };
|
|
132
141
|
}
|
|
133
142
|
|
|
@@ -274,7 +283,10 @@ function buildOpenApiDocument(routes, options) {
|
|
|
274
283
|
|
|
275
284
|
const paths = {};
|
|
276
285
|
|
|
277
|
-
|
|
286
|
+
// Routes marked `plugins.openapi.deprecated` are compatibility aliases: they stay registered
|
|
287
|
+
// (and keep the `api` tag, which also drives the CSRF skip list) but are left out of the
|
|
288
|
+
// published document and the reference page, so nothing steers a new integration onto them
|
|
289
|
+
for (const route of sortRoutes(routes.filter(route => (route.settings.tags || []).includes(API_ROUTE_TAG) && !pluginOptions(route).deprecated))) {
|
|
278
290
|
const { path, method, operation } = builder.buildOperation(route);
|
|
279
291
|
|
|
280
292
|
if (!paths[path]) {
|
|
@@ -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
|
|
7
|
-
// batch costs one round trip rather than one per job, while the bound keeps an account
|
|
8
|
-
// outbox from putting an unlimited number of Lua scripts in flight at once.
|
|
9
|
-
const
|
|
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
|
|
95
|
+
let totalJobs = JOB_STATES.map(state => Number(jobCounts[state]) || 0).reduce((previousValue, currentValue) => previousValue + currentValue);
|
|
46
96
|
|
|
47
|
-
|
|
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
|
|
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
|
-
|
|
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: '
|
|
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 +=
|
|
165
|
-
let batch = queueIds.slice(i, i +
|
|
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
|
-
|
|
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 };
|
package/lib/pre-process.js
CHANGED
|
@@ -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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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
|
|
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: '
|
|
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: '
|
|
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 };
|
package/lib/read-env-value.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|