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.
Files changed (155) hide show
  1. package/.ncurc.js +23 -13
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +68 -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 +112 -36
  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 +401 -0
  24. package/lib/api-routes/route-helpers.js +294 -9
  25. package/lib/api-routes/route-metadata.js +28 -0
  26. package/lib/api-routes/settings-routes.js +66 -38
  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 +526 -72
  31. package/lib/api-routes/webhook-route-routes.js +14 -4
  32. package/lib/arf-detect.js +17 -4
  33. package/lib/auth-token.js +80 -8
  34. package/lib/bounce-detect.js +28 -17
  35. package/lib/consts.js +16 -0
  36. package/lib/db.js +26 -2
  37. package/lib/delivery-error.js +30 -1
  38. package/lib/email-client/base-client.js +27 -41
  39. package/lib/email-client/gmail-client.js +23 -17
  40. package/lib/email-client/imap/mailbox.js +58 -59
  41. package/lib/email-client/imap/subconnection.js +10 -7
  42. package/lib/email-client/imap/sync-operations.js +46 -46
  43. package/lib/email-client/imap-client.js +85 -28
  44. package/lib/email-client/message-builder.js +3 -3
  45. package/lib/email-client/notification-handler.js +1 -1
  46. package/lib/email-client/outlook/graph-api.js +10 -4
  47. package/lib/email-client/outlook-client.js +56 -64
  48. package/lib/email-client/smtp-pool-manager.js +1 -1
  49. package/lib/enum-descriptions.js +92 -2
  50. package/lib/export.js +1 -1
  51. package/lib/field-usage.js +133 -0
  52. package/lib/gateway.js +1 -1
  53. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  54. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  55. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  56. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  57. package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
  58. package/lib/imapproxy/imap-server.js +27 -7
  59. package/lib/license-beacon.js +4 -9
  60. package/lib/lists.js +49 -1
  61. package/lib/llm-pre-process.js +5 -5
  62. package/lib/logger.js +5 -1
  63. package/lib/lua/h-set-new-mark.lua +36 -0
  64. package/lib/message-port-stream.js +84 -1
  65. package/lib/metrics-collector.js +2 -2
  66. package/lib/oauth/gmail.js +9 -12
  67. package/lib/oauth/mail-ru.js +5 -7
  68. package/lib/oauth/outlook.js +9 -9
  69. package/lib/oauth/pubsub/google.js +25 -10
  70. package/lib/oauth/scope-checker.js +1 -1
  71. package/lib/oauth2-apps.js +290 -292
  72. package/lib/openapi/build-document.js +20 -8
  73. package/lib/openapi/joi-schema.js +20 -0
  74. package/lib/outbox.js +85 -17
  75. package/lib/pre-process.js +8 -8
  76. package/lib/queue-stats.js +49 -0
  77. package/lib/read-env-value.js +1 -1
  78. package/lib/reconnection-manager.js +2 -2
  79. package/lib/rewrite-text-nodes.js +4 -3
  80. package/lib/routes-ui.js +4 -0
  81. package/lib/schemas.js +218 -162
  82. package/lib/settings.js +98 -5
  83. package/lib/sub-script.js +2 -1
  84. package/lib/swagger-options.js +2 -1
  85. package/lib/templates.js +4 -4
  86. package/lib/threads.js +2 -2
  87. package/lib/token-audit-log.js +231 -0
  88. package/lib/token-permission-view.js +219 -0
  89. package/lib/token-permissions.js +172 -0
  90. package/lib/tokens.js +247 -66
  91. package/lib/tools.js +142 -37
  92. package/lib/ui-routes/account-routes.js +42 -15
  93. package/lib/ui-routes/admin-config-routes.js +18 -10
  94. package/lib/ui-routes/admin-entities-routes.js +117 -38
  95. package/lib/ui-routes/auth-routes.js +30 -24
  96. package/lib/ui-routes/export-routes.js +10 -4
  97. package/lib/ui-routes/oauth-config-routes.js +12 -12
  98. package/lib/ui-routes/reference-routes.js +3 -3
  99. package/lib/ui-routes/route-helpers.js +78 -2
  100. package/lib/ui-routes/settings-page.js +1 -1
  101. package/lib/ui-routes/smtp-test-routes.js +1 -1
  102. package/lib/ui-routes/suppression-list-routes.js +299 -0
  103. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  104. package/lib/utils/decode-headers.js +42 -0
  105. package/lib/utils/header-map.js +48 -0
  106. package/lib/utils/network.js +2 -2
  107. package/lib/utils/unsafe-key.js +59 -0
  108. package/lib/web-safe-html.js +1 -1
  109. package/lib/webhook-routing.js +84 -0
  110. package/lib/webhooks.js +48 -14
  111. package/package.json +11 -10
  112. package/sbom.json +1 -1
  113. package/server.js +116 -55
  114. package/static/css/flyonui.css +1 -1
  115. package/static/css/src/app.tailwind.css +136 -9
  116. package/static/js/reference.js +456 -10
  117. package/static/js/ui.js +43 -0
  118. package/static/licenses.html +51 -41
  119. package/translations/messages.pot +59 -59
  120. package/views/accounts/account.hbs +75 -13
  121. package/views/accounts/browse.hbs +19 -36
  122. package/views/accounts/edit.hbs +2 -2
  123. package/views/config/logging.hbs +6 -0
  124. package/views/config/oauth/app.hbs +0 -2
  125. package/views/config/security.hbs +13 -0
  126. package/views/gateways/edit.hbs +1 -1
  127. package/views/gateways/gateway.hbs +2 -2
  128. package/views/gateways/index.hbs +7 -7
  129. package/views/partials/accounts_table.hbs +7 -7
  130. package/views/partials/oauth_form.hbs +0 -15
  131. package/views/partials/reference/disclosure.hbs +8 -2
  132. package/views/partials/reference/operation.hbs +47 -13
  133. package/views/partials/reference/params.hbs +17 -1
  134. package/views/partials/reference/schema-node.hbs +110 -52
  135. package/views/partials/reference/schema-tools.hbs +25 -0
  136. package/views/partials/reference/try-it.hbs +84 -11
  137. package/views/partials/side_menu.hbs +1 -0
  138. package/views/partials/ui/checkbox.hbs +2 -2
  139. package/views/partials/ui/tabs.hbs +7 -1
  140. package/views/reference/token.hbs +4 -0
  141. package/views/suppression-lists/index.hbs +85 -0
  142. package/views/suppression-lists/list.hbs +87 -0
  143. package/views/templates/index.hbs +10 -4
  144. package/views/templates/template.hbs +1 -1
  145. package/views/tokens/index.hbs +53 -6
  146. package/views/tokens/new.hbs +334 -5
  147. package/workers/api.js +185 -102
  148. package/workers/documents.js +46 -26
  149. package/workers/export.js +20 -8
  150. package/workers/imap-proxy.js +2 -2
  151. package/workers/imap.js +77 -78
  152. package/workers/smtp.js +13 -7
  153. package/workers/submit.js +40 -30
  154. package/workers/webhooks.js +80 -26
  155. package/lib/feature-flags.js +0 -48
package/workers/submit.js CHANGED
@@ -16,7 +16,7 @@ initSentry('submit');
16
16
 
17
17
  const util = require('util');
18
18
  const { redis, queueConf, submitQueue } = require('../lib/db');
19
- const { Worker } = require('bullmq');
19
+ const { Worker, UnrecoverableError } = require('bullmq');
20
20
  const { Account } = require('../lib/account');
21
21
  const getSecret = require('../lib/get-secret');
22
22
  const msgpack = require('../lib/msgpack');
@@ -42,7 +42,7 @@ const SUBMIT_QC = (readEnvValue('EENGINE_SUBMIT_QC') && Number(readEnvValue('EEN
42
42
 
43
43
  const SUBMIT_DELAY = getDuration(readEnvValue('EENGINE_SUBMIT_DELAY') || config.submitDelay) || null;
44
44
 
45
- const { shouldDiscardJob } = require('../lib/delivery-error');
45
+ const { shouldDiscardJob, willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
46
46
  const { packRpcError, unpackRpcError } = require('../lib/worker-rpc-error');
47
47
 
48
48
  let callQueue = new Map();
@@ -157,7 +157,7 @@ const submitWorker = new Worker(
157
157
  try {
158
158
  queueEntry = msgpack.decode(queueEntryBuf);
159
159
  } catch (err) {
160
- logger.error({ msg: 'Failed to parse queued email entry', job: job.data, err });
160
+ logger.error({ msg: 'Failed to parse queued email entry', job: job.id, account: job.data.account, queueId: job.data.queueId, err });
161
161
  try {
162
162
  await redis.hdel(`${REDIS_PREFIX}iaq:${job.data.account}`, job.data.queueId);
163
163
  } catch (err) {
@@ -197,7 +197,7 @@ const submitWorker = new Worker(
197
197
  let backoffDelay = Number(job.opts.backoff && job.opts.backoff.delay) || 0;
198
198
  // job.attemptsMade is not yet incremented for the ongoing attempt, so the
199
199
  // next retry (if this attempt fails) is delayed by 2^attemptsMade * base
200
- let nextAttempt = job.attemptsMade + 1 < job.opts.attempts ? Math.round(job.processedOn + Math.pow(2, job.attemptsMade) * backoffDelay) : false;
200
+ let nextAttempt = !willBeFinalAttempt(job) ? Math.round(job.processedOn + Math.pow(2, job.attemptsMade) * backoffDelay) : false;
201
201
 
202
202
  queueEntry.job = {
203
203
  id: job.id,
@@ -248,13 +248,17 @@ const submitWorker = new Worker(
248
248
  }
249
249
  } catch (err) {
250
250
  logger.error({
251
- msg: 'Job listing failed',
251
+ msg: 'Failed to fetch job status',
252
252
  job: job.id,
253
+ account: job.data.account,
253
254
  err
254
255
  });
255
256
  }
256
257
 
257
- logger.error({
258
+ const discardJob = shouldDiscardJob(err, job);
259
+ const isFinalAttempt = discardJob || willBeFinalAttempt(job);
260
+
261
+ logger[isFinalAttempt ? 'error' : 'warn']({
258
262
  msg: 'Message submission failed',
259
263
  action: 'submit',
260
264
  queue: job.queue.name,
@@ -281,28 +285,30 @@ const submitWorker = new Worker(
281
285
  // ignore
282
286
  }
283
287
 
284
- if (shouldDiscardJob(err, job)) {
285
- try {
286
- // do not retry after 5xx error (except 503 which is transient)
287
- await job.discard();
288
- logger.info({
289
- msg: 'Job discarded',
290
- account: queueEntry.account,
291
- queueId: job.data.queueId
292
- });
293
- } catch (E) {
294
- logger.error({
295
- msg: 'Failed to discard job',
296
- action: 'submit',
297
- queue: job.queue.name,
298
- code: 'discard_fail',
299
- job: job.id,
300
- event: job.name,
301
- data: job.data,
302
- account: job.data.account,
303
- err: E
304
- });
305
- }
288
+ if (discardJob) {
289
+ // Do not retry after a permanent rejection (5xx except 503, which is transient).
290
+ // BullMQ 6 removed Job#discard(), so the way to end a job before its attempts are
291
+ // spent is to throw UnrecoverableError. The stack is carried over because the
292
+ // 'failed' handler reports job.stacktrace[0] as the error in the failure webhook -
293
+ // constructing a bare UnrecoverableError would replace the SMTP reason with
294
+ // "UnrecoverableError" there.
295
+ let unrecoverableErr = new UnrecoverableError(err.message);
296
+ unrecoverableErr.stack = err.stack;
297
+ unrecoverableErr.code = err.code;
298
+ unrecoverableErr.responseCode = err.responseCode;
299
+ unrecoverableErr.statusCode = err.statusCode;
300
+
301
+ logger.info({
302
+ msg: 'Job discarded',
303
+ job: job.id,
304
+ account: queueEntry.account,
305
+ queueId: job.data.queueId,
306
+ messageId: job.data.messageId,
307
+ errorCode: err.code,
308
+ responseCode: err.responseCode
309
+ });
310
+
311
+ throw unrecoverableErr;
306
312
  }
307
313
 
308
314
  throw err;
@@ -369,7 +375,9 @@ submitWorker.on('failed', async job => {
369
375
  status: 'failed'
370
376
  });
371
377
 
372
- if (job.finishedOn || job.discarded) {
378
+ // BullMQ sets finishedOn only when the job is done for good, which covers both exhausting its
379
+ // attempts and being ended early by the UnrecoverableError thrown for a permanent rejection.
380
+ if (job.finishedOn) {
373
381
  // this was final attempt, remove it
374
382
  if (!job.data.queueId && job.data.qId) {
375
383
  // this value was used to be called qId
@@ -403,7 +411,9 @@ submitWorker.on('failed', async job => {
403
411
  }
404
412
  }
405
413
 
406
- logger.info({
414
+ let isFinal = isFinalFailedAttempt(job);
415
+
416
+ logger[isFinal ? 'error' : 'debug']({
407
417
  msg: 'Submission queue entry failed',
408
418
  action: 'submit',
409
419
  queue: job.queue.name,
@@ -10,9 +10,11 @@ const { webhooks: Webhooks } = require('../lib/webhooks');
10
10
 
11
11
  const { GooglePubSub } = require('../lib/oauth/pubsub/google');
12
12
 
13
- const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, maybeReloadHttpProxyAgent } = require('../lib/tools');
13
+ const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, maybeReloadHttpProxyAgent, redactUrlCredentials } = require('../lib/tools');
14
14
  const { sendWebhookRequest } = require('../lib/webhook-request');
15
+ const { willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
15
16
  const { validateWebhookTarget } = require('../lib/webhook-egress');
17
+ const { resolveTargetUrl, isDeliverableRoute, eventAllowed } = require('../lib/webhook-routing');
16
18
 
17
19
  const { initSentry } = require('../lib/sentry');
18
20
  initSentry('webhooks');
@@ -40,6 +42,11 @@ const NOTIFY_QC = (readEnvValue('EENGINE_NOTIFY_QC') && Number(readEnvValue('EEN
40
42
  // DEFAULT_WEBHOOK_REQUEST_TIMEOUT baked into sendWebhookRequest when unset
41
43
  const WEBHOOK_TIMEOUT = getDuration(readEnvValue('EENGINE_WEBHOOK_TIMEOUT')) || false;
42
44
 
45
+ // Neither of these changes on a retry: the egress policy rejects the same destination every time,
46
+ // and an endpoint configured to redirect keeps redirecting. Such a delivery is final on its first
47
+ // failure, which decides both the log level and whether the remaining attempts are spent.
48
+ const isUnrecoverableWebhookError = err => !!err && (err.code === 'EEGRESSBLOCKED' || err.code === 'EREDIRECTNOTFOLLOWED');
49
+
43
50
  let callQueue = new Map();
44
51
  let mids = 0;
45
52
 
@@ -196,11 +203,18 @@ const notifyWorker = new Worker(
196
203
  //return new Promise((resolve, reject) => {});
197
204
  let accountKey = getAccountKey(job.data.account);
198
205
 
206
+ // Keep the route id reachable for the completed/failed event handlers, which see this same
207
+ // job instance after _route has been deleted from the payload. Stashed before the early
208
+ // returns below so a job that never reaches delivery still reports which route queued it.
209
+ if (job.data._route && job.data._route.id) {
210
+ job.__routeId = job.data._route.id;
211
+ }
212
+
199
213
  // validate if we should even process this webhook
200
214
  let accountExists = await redis.hexists(accountKey, 'account');
201
215
  if (!accountExists && job.name !== ACCOUNT_DELETED_NOTIFY) {
202
216
  logger.debug({
203
- msg: 'Account is not enabled',
217
+ msg: 'Account not found',
204
218
  action: 'webhook',
205
219
  queue: job.queue.name,
206
220
  code: 'account_not_found',
@@ -213,6 +227,15 @@ const notifyWorker = new Worker(
213
227
 
214
228
  let webhooksEnabled = await settings.get('webhooksEnabled');
215
229
  if (!webhooksEnabled) {
230
+ logger.debug({
231
+ msg: 'Webhooks are disabled',
232
+ action: 'webhook',
233
+ queue: job.queue.name,
234
+ code: 'webhooks_disabled',
235
+ job: job.id,
236
+ event: job.name,
237
+ account: job.data.account
238
+ });
216
239
  return;
217
240
  }
218
241
 
@@ -222,16 +245,28 @@ const notifyWorker = new Worker(
222
245
  customRoute = await Webhooks.getMeta(job.data._route.id);
223
246
  customMapping = job.data._route.mapping;
224
247
  delete job.data._route;
225
- if (!customRoute || !customRoute.enabled || !customRoute.targetUrl) {
248
+ if (!isDeliverableRoute(customRoute)) {
226
249
  return;
227
250
  }
228
251
  }
229
252
 
230
253
  let accountWebhooks = await redis.hget(accountKey, 'webhooks');
231
254
 
232
- let webhooks = (customRoute && customRoute.targetUrl) || accountWebhooks || (await settings.get('webhooks'));
255
+ // the global setting is only fetched when neither a custom route nor the account override decides the target
256
+ let webhooks = resolveTargetUrl(customRoute && customRoute.targetUrl, accountWebhooks, null).url || (await settings.get('webhooks'));
233
257
  if (!webhooks) {
234
- // logger.debug({ msg: 'Webhook URL is not set', action: 'webhook', event: job.name, account: job.data.account });
258
+ // A skipped delivery still reports the job as completed, so without this line a
259
+ // missing target is indistinguishable from a successful delivery - it reads as the
260
+ // receiver being slow rather than as nothing having been sent
261
+ logger.debug({
262
+ msg: 'Webhook URL is not set',
263
+ action: 'webhook',
264
+ queue: job.queue.name,
265
+ code: 'no_target_url',
266
+ job: job.id,
267
+ event: job.name,
268
+ account: job.data.account
269
+ });
235
270
  return;
236
271
  }
237
272
 
@@ -241,12 +276,13 @@ const notifyWorker = new Worker(
241
276
  try {
242
277
  accountWebhooksCustomHeaders = JSON.parse(accountWebhooksCustomHeadersJson);
243
278
  } catch (err) {
279
+ // do not log the header values, they may carry authentication secrets
244
280
  logger.debug({
245
281
  msg: 'Failed to parse custom webhook headers',
246
282
  action: 'webhook',
247
283
  event: job.name,
248
284
  account: job.data.account,
249
- json: accountWebhooksCustomHeadersJson,
285
+ jsonLength: accountWebhooksCustomHeadersJson.length,
250
286
  err
251
287
  });
252
288
  }
@@ -255,7 +291,7 @@ const notifyWorker = new Worker(
255
291
  if (!customRoute) {
256
292
  // custom routes have their own mappings
257
293
  let webhookEvents = (await settings.get('webhookEvents')) || [];
258
- if (!webhookEvents.includes('*') && !webhookEvents.includes(job.name)) {
294
+ if (!eventAllowed(webhookEvents, job.name)) {
259
295
  logger.trace({
260
296
  msg: 'Webhook event not in whitelist',
261
297
  action: 'webhook',
@@ -264,8 +300,7 @@ const notifyWorker = new Worker(
264
300
  job: job.id,
265
301
  event: job.name,
266
302
  account: job.data.account,
267
- webhookEvents,
268
- data: job.data
303
+ webhookEvents
269
304
  });
270
305
  return;
271
306
  }
@@ -331,13 +366,18 @@ const notifyWorker = new Worker(
331
366
  }
332
367
  }
333
368
 
369
+ // never log the raw target URL, it may embed basic auth credentials; keep the redacted
370
+ // form reachable for the failed event handler
371
+ let redactedWebhooks = redactUrlCredentials(webhooks);
372
+ job.__redactedTargetUrl = redactedWebhooks;
373
+
334
374
  logger.trace({
335
375
  msg: 'Processing webhook',
336
376
  action: 'webhook',
337
377
  queue: job.queue.name,
338
378
  code: 'processing',
339
379
  job: job.id,
340
- webhooks,
380
+ webhooks: redactedWebhooks,
341
381
  accountWebhooks: !!accountWebhooks,
342
382
  event: job.name,
343
383
  data: filteredData,
@@ -429,7 +469,7 @@ const notifyWorker = new Worker(
429
469
  queue: job.queue.name,
430
470
  code: 'result_success',
431
471
  job: job.id,
432
- webhooks,
472
+ webhooks: redactedWebhooks,
433
473
  requestBodySize: body.length,
434
474
  accountWebhooks: !!accountWebhooks,
435
475
  event: job.name,
@@ -455,13 +495,16 @@ const notifyWorker = new Worker(
455
495
  status: 'success'
456
496
  });
457
497
  } catch (err) {
458
- logger.error({
498
+ // egress and redirect failures are thrown as UnrecoverableError below, so they are final as well
499
+ let isFinalAttempt = willBeFinalAttempt(job) || isUnrecoverableWebhookError(err);
500
+
501
+ logger[isFinalAttempt ? 'error' : 'warn']({
459
502
  msg: 'Failed posting webhook',
460
503
  action: 'webhook',
461
504
  queue: job.queue.name,
462
505
  code: 'result_fail',
463
506
  job: job.id,
464
- webhooks,
507
+ webhooks: redactedWebhooks,
465
508
  requestBodySize: body.length,
466
509
  accountWebhooks: !!accountWebhooks,
467
510
  event: job.name,
@@ -516,12 +559,14 @@ const notifyWorker = new Worker(
516
559
  status: 'fail'
517
560
  });
518
561
 
519
- // Neither of these changes on a retry: the egress policy rejects the same destination
520
- // every time, and an endpoint configured to redirect keeps redirecting. Spending the
521
- // remaining attempts on them only delays the operator seeing the real reason in the
522
- // error flag. Fail the job now and keep the message.
523
- if (err.code === 'EEGRESSBLOCKED' || err.code === 'EREDIRECTNOTFOLLOWED') {
524
- throw new UnrecoverableError(err.message);
562
+ // Spending the remaining attempts on an unrecoverable failure only delays the operator
563
+ // seeing the real reason in the error flag. Fail the job now and keep the message.
564
+ if (isUnrecoverableWebhookError(err)) {
565
+ // UnrecoverableError copies the message only, and the failed-event handler logs the
566
+ // error it is given, so carry the code over or that log loses the actual reason
567
+ let unrecoverableErr = new UnrecoverableError(err.message);
568
+ unrecoverableErr.code = err.code;
569
+ throw unrecoverableErr;
525
570
  }
526
571
 
527
572
  throw err;
@@ -556,31 +601,40 @@ notifyWorker.on('completed', async job => {
556
601
  status: 'completed'
557
602
  });
558
603
 
559
- logger.info({
604
+ logger.debug({
560
605
  msg: 'Notification queue entry completed',
561
606
  action: 'webhook',
562
607
  queue: job.queue.name,
563
608
  code: 'completed',
564
609
  job: job.id,
610
+ event: job.name,
565
611
  account: job.data.account,
566
- route: job.data._route && job.data._route.id
612
+ // a completed job always ran the processor, which stashes this before any early return
613
+ route: job.__routeId
567
614
  });
568
615
  });
569
616
 
570
- notifyWorker.on('failed', async job => {
617
+ notifyWorker.on('failed', async (job, err) => {
571
618
  metrics(logger, 'queuesProcessed', 'inc', {
572
619
  queue: 'notify',
573
620
  status: 'failed'
574
621
  });
575
622
 
576
- logger.info({
623
+ let isFinal = isFinalFailedAttempt(job);
624
+
625
+ logger[isFinal ? 'error' : 'debug']({
577
626
  msg: 'Notification queue entry failed',
578
627
  action: 'webhook',
579
628
  queue: job.queue.name,
580
629
  code: 'failed',
581
630
  job: job.id,
631
+ event: job.name,
582
632
  account: job.data.account,
583
- route: job.data._route && job.data._route.id,
633
+ // the fallback covers jobs that stalled out before this worker instance ever processed
634
+ // them, where the stash was never set and _route is still in the payload
635
+ route: job.__routeId || (job.data._route && job.data._route.id),
636
+ webhooks: job.__redactedTargetUrl,
637
+ err,
584
638
 
585
639
  failedReason: job.failedReason,
586
640
  stacktrace: job.stacktrace,
@@ -601,10 +655,10 @@ let startRetryTimer = null;
601
655
  let delay;
602
656
  if (attempt < maxNormalAttempts) {
603
657
  delay = Math.min(5000 * Math.pow(2, Math.min(attempt, 10)), 60000);
604
- logger.error({ msg: 'Failed to start processing Google pub/sub', err, attempt: attempt + 1, retryMs: delay });
658
+ logger.warn({ msg: 'Failed to start processing Google pub/sub', err, attempt: attempt + 1, retryMs: delay });
605
659
  } else {
606
660
  delay = 5 * 60 * 1000;
607
- logger.warn({ msg: 'Failed to start processing Google pub/sub (reduced frequency)', err, attempt: attempt + 1, retryMs: delay });
661
+ logger.error({ msg: 'Failed to start processing Google pub/sub (reduced frequency)', err, attempt: attempt + 1, retryMs: delay });
608
662
  }
609
663
  startRetryTimer = setTimeout(() => startGooglePubSub(attempt + 1), delay);
610
664
  });
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- const logger = require('./logger');
4
-
5
- const FEATURES = new Set();
6
-
7
- const ENABLED_FEATURES = [];
8
-
9
- const formatFeatureKey = key =>
10
- (key || '')
11
- .toString()
12
- .trim()
13
- .toLowerCase()
14
- .replace(/[-_\s]+/g, '_');
15
-
16
- for (let feature of ENABLED_FEATURES) {
17
- FEATURES.add(formatFeatureKey(feature));
18
- }
19
-
20
- for (let key of Object.keys(process.env)) {
21
- if (/^EENGINE_FEATURE_/i.test(key)) {
22
- let feature = formatFeatureKey(key.substring('EENGINE_FEATURE_'.length));
23
- if (feature) {
24
- let value = /^(y|yes|true|t|1)$/i.test((process.env[key] || '').toString().trim());
25
- if (value) {
26
- FEATURES.add(feature);
27
- } else {
28
- FEATURES.delete(feature);
29
- }
30
- }
31
- }
32
- }
33
-
34
- module.exports = {
35
- enabled(key) {
36
- return FEATURES.has(formatFeatureKey(key));
37
- },
38
-
39
- // Sorted list of the currently enabled feature flag keys. Used by the license beacon
40
- // to report which EENGINE_FEATURE_* flags are active on this instance.
41
- listEnabled() {
42
- return Array.from(FEATURES).sort();
43
- }
44
- };
45
-
46
- if (FEATURES.size > 0) {
47
- logger.info({ msg: 'Enabled feature flags', featureFlags: Array.from(FEATURES) });
48
- }