emailengine-app 2.77.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 (189) hide show
  1. package/.github/workflows/test.yml +80 -0
  2. package/.ncurc.js +23 -13
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +60 -0
  5. package/bin/emailengine.js +1 -1
  6. package/config/e2e.toml +2 -1
  7. package/config/test.toml +2 -1
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +1 -1
  10. package/lib/account/expected-identity.js +88 -0
  11. package/lib/account.js +145 -61
  12. package/lib/api-reference/format.js +105 -4
  13. package/lib/api-reference/index.js +24 -7
  14. package/lib/api-reference/model.js +148 -21
  15. package/lib/api-reference/schema-tree.js +282 -28
  16. package/lib/api-routes/account-routes.js +99 -36
  17. package/lib/api-routes/behavior-notes.js +3 -0
  18. package/lib/api-routes/blocklist-routes.js +21 -47
  19. package/lib/api-routes/chat-routes.js +10 -12
  20. package/lib/api-routes/delivery-test-routes.js +6 -26
  21. package/lib/api-routes/export-routes.js +2 -0
  22. package/lib/api-routes/gateway-routes.js +52 -11
  23. package/lib/api-routes/license-routes.js +2 -0
  24. package/lib/api-routes/mailbox-routes.js +29 -26
  25. package/lib/api-routes/message-routes.js +27 -21
  26. package/lib/api-routes/oauth2-app-routes.js +11 -29
  27. package/lib/api-routes/operation-impact.js +80 -0
  28. package/lib/api-routes/outbox-routes.js +15 -5
  29. package/lib/api-routes/permission-map.js +397 -0
  30. package/lib/api-routes/route-helpers.js +223 -9
  31. package/lib/api-routes/route-metadata.js +28 -0
  32. package/lib/api-routes/settings-routes.js +30 -25
  33. package/lib/api-routes/stats-routes.js +2 -2
  34. package/lib/api-routes/submit-routes.js +53 -31
  35. package/lib/api-routes/template-routes.js +3 -0
  36. package/lib/api-routes/token-routes.js +319 -33
  37. package/lib/api-routes/webhook-route-routes.js +14 -4
  38. package/lib/append-list.js +3 -14
  39. package/lib/arf-detect.js +23 -1
  40. package/lib/auth-token.js +80 -8
  41. package/lib/autodetect-imap-settings.js +40 -16
  42. package/lib/base32.js +30 -0
  43. package/lib/bounce-detect.js +182 -62
  44. package/lib/consts.js +10 -0
  45. package/lib/db.js +20 -2
  46. package/lib/delivery-error.js +30 -1
  47. package/lib/egress-filter.js +89 -8
  48. package/lib/email-client/base-client.js +35 -113
  49. package/lib/email-client/gmail-client.js +22 -13
  50. package/lib/email-client/imap/listing-diff.js +3 -3
  51. package/lib/email-client/imap/mailbox.js +28 -93
  52. package/lib/email-client/imap/subconnection.js +10 -7
  53. package/lib/email-client/imap/sync-operations.js +46 -46
  54. package/lib/email-client/imap-client.js +39 -28
  55. package/lib/email-client/message-builder.js +15 -15
  56. package/lib/email-client/notification-handler.js +1 -1
  57. package/lib/email-client/outlook/graph-api.js +10 -4
  58. package/lib/email-client/outlook-client.js +54 -55
  59. package/lib/email-client/smtp-pool-manager.js +1 -1
  60. package/lib/enum-descriptions.js +92 -2
  61. package/lib/export.js +2 -2
  62. package/lib/field-usage.js +133 -0
  63. package/lib/gateway.js +2 -2
  64. package/lib/get-raw-email.js +1 -1
  65. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  66. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  67. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  68. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  69. package/lib/imapproxy/imap-core/lib/imap-connection.js +17 -7
  70. package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
  71. package/lib/imapproxy/imap-server.js +40 -10
  72. package/lib/license-beacon.js +5 -10
  73. package/lib/lists.js +49 -1
  74. package/lib/llm-pre-process.js +6 -6
  75. package/lib/logger.js +5 -1
  76. package/lib/metrics-collector.js +2 -2
  77. package/lib/msgpack.js +62 -0
  78. package/lib/oauth/decode-jwt-payload.js +39 -0
  79. package/lib/oauth/gmail.js +9 -12
  80. package/lib/oauth/mail-ru.js +5 -7
  81. package/lib/oauth/outlook-identity.js +61 -0
  82. package/lib/oauth/outlook.js +9 -9
  83. package/lib/oauth/pubsub/google.js +25 -10
  84. package/lib/oauth/retry-setup.js +38 -0
  85. package/lib/oauth/scope-checker.js +1 -1
  86. package/lib/oauth2-apps.js +224 -295
  87. package/lib/openapi/build-document.js +15 -7
  88. package/lib/openapi/joi-schema.js +20 -0
  89. package/lib/outbox.js +145 -14
  90. package/lib/pre-process.js +9 -9
  91. package/lib/queue-stats.js +49 -0
  92. package/lib/read-env-value.js +37 -0
  93. package/lib/reconnection-manager.js +2 -2
  94. package/lib/rewrite-text-nodes.js +4 -3
  95. package/lib/routes-ui.js +4 -0
  96. package/lib/schemas.js +223 -155
  97. package/lib/settings.js +84 -5
  98. package/lib/sub-script.js +2 -1
  99. package/lib/swagger-options.js +2 -1
  100. package/lib/templates.js +5 -5
  101. package/lib/threads.js +2 -2
  102. package/lib/token-audit-log.js +208 -0
  103. package/lib/token-permission-view.js +219 -0
  104. package/lib/token-permissions.js +172 -0
  105. package/lib/tokens.js +100 -16
  106. package/lib/tools.js +259 -85
  107. package/lib/totp.js +67 -0
  108. package/lib/ui-routes/account-routes.js +122 -26
  109. package/lib/ui-routes/admin-config-routes.js +20 -17
  110. package/lib/ui-routes/admin-entities-routes.js +66 -22
  111. package/lib/ui-routes/auth-routes.js +36 -48
  112. package/lib/ui-routes/export-routes.js +10 -4
  113. package/lib/ui-routes/oauth-config-routes.js +5 -5
  114. package/lib/ui-routes/reference-routes.js +11 -8
  115. package/lib/ui-routes/route-helpers.js +79 -2
  116. package/lib/ui-routes/settings-page.js +1 -1
  117. package/lib/ui-routes/smtp-test-routes.js +1 -1
  118. package/lib/ui-routes/suppression-list-routes.js +294 -0
  119. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  120. package/lib/utils/is-email.js +34 -0
  121. package/lib/utils/network.js +2 -2
  122. package/lib/utils/to-camel-case.js +17 -0
  123. package/lib/web-safe-html.js +1 -1
  124. package/lib/webhook-egress.js +37 -0
  125. package/lib/webhook-routing.js +80 -0
  126. package/lib/webhooks.js +21 -15
  127. package/package.json +26 -27
  128. package/sbom.json +1 -0
  129. package/server.js +81 -42
  130. package/static/css/flyonui.css +1 -1
  131. package/static/css/public.css +3 -0
  132. package/static/css/src/app.tailwind.css +159 -9
  133. package/static/js/app.js +69 -0
  134. package/static/js/reference.js +741 -10
  135. package/static/js/ui.js +43 -0
  136. package/static/licenses.html +698 -1590
  137. package/translations/README.md +64 -0
  138. package/translations/de.mo +0 -0
  139. package/translations/de.po +164 -120
  140. package/translations/en.po +200 -161
  141. package/translations/et.mo +0 -0
  142. package/translations/et.po +163 -120
  143. package/translations/fr.mo +0 -0
  144. package/translations/fr.po +163 -120
  145. package/translations/ja.mo +0 -0
  146. package/translations/ja.po +163 -120
  147. package/translations/messages.pot +94 -64
  148. package/translations/nl.mo +0 -0
  149. package/translations/nl.po +164 -120
  150. package/translations/pl.mo +0 -0
  151. package/translations/pl.po +163 -120
  152. package/views/account-identity-error.hbs +34 -0
  153. package/views/accounts/account.hbs +69 -7
  154. package/views/accounts/browse.hbs +18 -35
  155. package/views/accounts/edit.hbs +1 -0
  156. package/views/accounts/register/imap.hbs +12 -2
  157. package/views/config/logging.hbs +6 -0
  158. package/views/config/oauth/app.hbs +0 -2
  159. package/views/config/security.hbs +13 -0
  160. package/views/layout/app.hbs +29 -5
  161. package/views/oauth-scope-error.hbs +1 -1
  162. package/views/partials/oauth_form.hbs +0 -15
  163. package/views/partials/reference/disclosure.hbs +8 -2
  164. package/views/partials/reference/nav.hbs +36 -9
  165. package/views/partials/reference/operation.hbs +48 -14
  166. package/views/partials/reference/params.hbs +17 -1
  167. package/views/partials/reference/schema-node.hbs +112 -54
  168. package/views/partials/reference/schema-tools.hbs +25 -0
  169. package/views/partials/reference/token-alert.hbs +35 -10
  170. package/views/partials/reference/try-it.hbs +84 -11
  171. package/views/partials/side_menu.hbs +1 -0
  172. package/views/partials/ui/checkbox.hbs +2 -2
  173. package/views/partials/ui/tabs.hbs +7 -1
  174. package/views/reference/index.hbs +1 -1
  175. package/views/reference/token.hbs +4 -0
  176. package/views/suppression-lists/index.hbs +85 -0
  177. package/views/suppression-lists/list.hbs +87 -0
  178. package/views/templates/index.hbs +8 -2
  179. package/views/tokens/index.hbs +31 -4
  180. package/views/tokens/new.hbs +324 -2
  181. package/workers/api.js +299 -140
  182. package/workers/documents.js +46 -26
  183. package/workers/export.js +20 -8
  184. package/workers/imap-proxy.js +2 -2
  185. package/workers/imap.js +13 -7
  186. package/workers/smtp.js +13 -7
  187. package/workers/submit.js +41 -31
  188. package/workers/webhooks.js +60 -37
  189. package/lib/feature-flags.js +0 -48
@@ -4,13 +4,13 @@ const crypto = require('crypto');
4
4
  const { redis } = require('../db');
5
5
  const { Account } = require('../account');
6
6
  const getSecret = require('../get-secret');
7
- const { oauth2Apps, LEGACY_KEYS, SERVICE_ACCOUNT_PROVIDERS } = require('../oauth2-apps');
7
+ const { oauth2Apps, SERVICE_ACCOUNT_PROVIDERS } = require('../oauth2-apps');
8
8
  const settings = require('../settings');
9
9
  const { autodetectImapSettings } = require('../autodetect-imap-settings');
10
10
  const Boom = require('@hapi/boom');
11
11
  const Joi = require('joi');
12
12
  const { failAction, getSignedFormData, getLogs, verifyAccountInfo } = require('../tools');
13
- const { handleError } = require('./route-helpers');
13
+ const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers');
14
14
 
15
15
  const {
16
16
  settingsSchema,
@@ -34,6 +34,8 @@ const {
34
34
 
35
35
  const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES } = require('../consts');
36
36
  const BEHAVIOR = require('./behavior-notes');
37
+ const { IMPACT } = require('./operation-impact');
38
+ const { FIELD_USAGE } = require('../field-usage');
37
39
 
38
40
  // OAuth2 scope list stored on the account (accountData.oauth2.scope). Reused with a per-route
39
41
  // description/label where the same value is exposed under a different field name
@@ -218,14 +220,15 @@ async function init(args) {
218
220
  .max(256)
219
221
  .allow(null)
220
222
  .example('example')
221
- .description(
222
- 'Account ID. If set to `null`, a unique ID will be generated automatically. If you provide an existing account ID, the settings for that account will be updated instead'
223
- )
223
+ .description('Account ID. If set to `null`, a unique ID will be generated automatically')
224
+ .meta({ usage: FIELD_USAGE.accountId })
224
225
  .required(),
225
226
 
226
227
  name: Joi.string().max(256).required().example('My Email Account').description('Display name for the account'),
227
228
  email: Joi.string().empty('').email().example('user@example.com').description('Default email address of the account'),
228
229
 
230
+ expectedEmail: accountSchemas.expectedEmail,
231
+
229
232
  path: accountPathSchema.example(['*']).label('AccountPath'),
230
233
 
231
234
  subconnections: accountSchemas.subconnections,
@@ -254,11 +257,20 @@ async function init(args) {
254
257
 
255
258
  imapIndexer: accountSchemas.imapIndexer,
256
259
 
257
- imap: Joi.object(imapSchemaArg).allow(false).description('IMAP configuration').label('ImapConfiguration'),
260
+ imap: Joi.object(imapSchemaArg)
261
+ .allow(false)
262
+ .description('IMAP configuration. Set to `false` when there is no IMAP access to configure.')
263
+ .label('ImapConfiguration'),
258
264
 
259
- smtp: Joi.object(smtpSchemaArg).allow(false).description('SMTP configuration').label('SmtpConfiguration'),
265
+ smtp: Joi.object(smtpSchemaArg)
266
+ .allow(false)
267
+ .description('SMTP configuration. Set to `false` when there is no SMTP access to configure.')
268
+ .label('SmtpConfiguration'),
260
269
 
261
- oauth2: Joi.object(oauth2SchemaArg).allow(false).description('OAuth2 configuration').label('OAuth2'),
270
+ oauth2: Joi.object(oauth2SchemaArg)
271
+ .allow(false)
272
+ .description('OAuth2 configuration. Set to `false` when the account does not authenticate with OAuth2.')
273
+ .label('OAuth2'),
262
274
 
263
275
  webhooksCustomHeaders: settingsSchema.webhooksCustomHeaders.label('AccountWebhooksCustomHeaders'),
264
276
 
@@ -297,7 +309,8 @@ async function init(args) {
297
309
  state: Joi.string()
298
310
  .valid('existing', 'new')
299
311
  .example('new')
300
- .description('Is the account new or updated existing. Not present when a redirect URL is returned')
312
+ .description('Whether the account was created or updated. Not present when a redirect URL is returned')
313
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.entityState })
301
314
  .label('CreateAccountState'),
302
315
  redirect: Joi.string()
303
316
  .uri()
@@ -372,6 +385,8 @@ async function init(args) {
372
385
  name: Joi.string().max(256).example('My Email Account').description('Display name for the account'),
373
386
  email: Joi.string().empty('').email().example('user@example.com').description('Default email address of the account'),
374
387
 
388
+ expectedEmail: accountSchemas.expectedEmailUpdate,
389
+
375
390
  path: accountPathSchema.example(['*']).label('AccountPath'),
376
391
 
377
392
  subconnections: accountSchemas.subconnections,
@@ -398,9 +413,18 @@ async function init(args) {
398
413
  proxy: settingsSchema.proxyUrl,
399
414
  smtpEhloName: settingsSchema.smtpEhloName,
400
415
 
401
- imap: Joi.object(imapUpdateSchema).allow(false).description('IMAP configuration').label('IMAPUpdate'),
402
- smtp: Joi.object(smtpUpdateSchema).allow(false).description('SMTP configuration').label('SMTPUpdate'),
403
- oauth2: Joi.object(oauth2UpdateSchema).allow(false).description('OAuth2 configuration').label('OAuth2Update'),
416
+ imap: Joi.object(imapUpdateSchema)
417
+ .allow(false)
418
+ .description('IMAP configuration. Set to `false` to remove the stored IMAP configuration from the account.')
419
+ .label('IMAPUpdate'),
420
+ smtp: Joi.object(smtpUpdateSchema)
421
+ .allow(false)
422
+ .description('SMTP configuration. Set to `false` to remove the stored SMTP configuration from the account.')
423
+ .label('SMTPUpdate'),
424
+ oauth2: Joi.object(oauth2UpdateSchema)
425
+ .allow(false)
426
+ .description('OAuth2 configuration. Set to `false` to remove the stored OAuth2 configuration from the account.')
427
+ .label('OAuth2Update'),
404
428
 
405
429
  webhooksCustomHeaders: settingsSchema.webhooksCustomHeaders.label('AccountWebhooksCustomHeaders'),
406
430
 
@@ -598,12 +622,17 @@ async function init(args) {
598
622
  },
599
623
  options: {
600
624
  description: 'Remove account',
601
- notes: "Stop processing and clear the account's cache. Pass revoke=true to also attempt revocation of the upstream OAuth2 grant at the provider before the account is removed.",
625
+ notes: [
626
+ "Stop processing and clear the account's cache. Pass revoke=true to also attempt revocation of the upstream OAuth2 grant at the provider before the account is removed.",
627
+ BEHAVIOR.DELETION_SCOPE
628
+ ],
602
629
 
603
630
  tags: ['api', 'Account'],
604
631
 
605
632
  plugins: {
606
633
  openapi: {
634
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
635
+ 'x-ee-behavior': [BEHAVIOR.DELETION_SCOPE],
607
636
  responses: apiResponses(
608
637
  'Returns a deletion marker. The account stops syncing immediately; stored data is removed in the background.',
609
638
  400,
@@ -639,9 +668,8 @@ async function init(args) {
639
668
  .truthy('Y', 'true', '1')
640
669
  .falsy('N', 'false', 0)
641
670
  .default(false)
642
- .description(
643
- 'If true, EmailEngine attempts to revoke the upstream OAuth2 grant at the provider before deleting the account. Currently supported for individual Gmail OAuth grants. For Gmail Workspace service-account integrations (gmailService), Outlook, and non-OAuth2 accounts the flag is a no-op. Revoke failures are logged and do not block deletion.'
644
- )
671
+ .description('Revoke the upstream OAuth2 grant at the provider before deleting the account')
672
+ .meta({ usage: FIELD_USAGE.revokeGrant })
645
673
  })
646
674
  },
647
675
 
@@ -686,6 +714,7 @@ async function init(args) {
686
714
 
687
715
  plugins: {
688
716
  openapi: {
717
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
689
718
  'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
690
719
  responses: apiResponses(
691
720
  'Returns an acknowledgement. Cached message indexes are cleared and rebuilt in the background.',
@@ -749,7 +778,15 @@ async function init(args) {
749
778
  timeout: request.headers['x-ee-timeout']
750
779
  });
751
780
 
752
- return await accountObject.listAccounts(request.query.state, request.query.query, request.query.page, request.query.pageSize);
781
+ const listing = await accountObject.listAccounts(request.query.state, request.query.query, request.query.page, request.query.pageSize);
782
+
783
+ // The proxy and webhook URLs can carry inline credentials, and the listing returns
784
+ // one of each per account
785
+ for (const entry of listing.accounts || []) {
786
+ maskSecrets(entry);
787
+ }
788
+
789
+ return listing;
753
790
  } catch (err) {
754
791
  handleError(request, err);
755
792
  }
@@ -878,7 +915,7 @@ async function init(args) {
878
915
  if (accountData[type] && accountData[type].auth) {
879
916
  for (let key of ['pass', 'accessToken', 'refreshToken']) {
880
917
  if (key in accountData[type].auth) {
881
- accountData[type].auth[key] = '******';
918
+ accountData[type].auth[key] = MASKED;
882
919
  }
883
920
  }
884
921
  }
@@ -886,18 +923,24 @@ async function init(args) {
886
923
  if (accountData[type]) {
887
924
  for (let key of ['accessToken', 'refreshToken']) {
888
925
  if (key in accountData[type]) {
889
- accountData[type][key] = '******';
926
+ accountData[type][key] = MASKED;
890
927
  }
891
928
  }
892
929
  }
893
930
  }
894
931
 
932
+ // Credentials for systems other than the mail server, which the loop above does not
933
+ // reach: the proxy and webhook URLs, the webhook headers, and the proxy recorded a
934
+ // second time inside smtpStatus.networkRouting by a failed submission.
935
+ maskSecrets(accountData);
936
+
895
937
  let result = {};
896
938
 
897
939
  for (let key of [
898
940
  'account',
899
941
  'name',
900
942
  'email',
943
+ 'expectedEmail',
901
944
  'copy',
902
945
  'logs',
903
946
  'notifyFrom',
@@ -998,7 +1041,7 @@ async function init(args) {
998
1041
  },
999
1042
  options: {
1000
1043
  description: 'Get account info',
1001
- notes: ['Returns stored information about the account. Passwords are not included.', BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
1044
+ notes: [`Returns stored information about the account. ${MASK_NOTE}`, BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
1002
1045
  tags: ['api', 'Account'],
1003
1046
 
1004
1047
  plugins: {
@@ -1043,6 +1086,8 @@ async function init(args) {
1043
1086
  name: Joi.string().allow('').max(256).example('My Email Account').description('Display name for the account'),
1044
1087
  email: Joi.string().empty('').email().example('user@example.com').description('Default email address of the account'),
1045
1088
 
1089
+ expectedEmail: accountSchemas.expectedEmail,
1090
+
1046
1091
  copy: Joi.boolean().example(true).description('Copy submitted messages to Sent folder'),
1047
1092
  logs: Joi.boolean().example(false).description('Store recent logs'),
1048
1093
 
@@ -1106,6 +1151,7 @@ async function init(args) {
1106
1151
  networkRouting: Joi.object()
1107
1152
  .unknown()
1108
1153
  .allow(null)
1154
+ .example({ localAddress: '198.51.100.24', name: 'relay.example.com' })
1109
1155
  .description('Network routing information for the delivery attempt')
1110
1156
  .label('SMTPStatusNetworkRouting')
1111
1157
  })
@@ -1157,17 +1203,20 @@ async function init(args) {
1157
1203
  syncTime: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('Last sync time (IMAP accounts only)'),
1158
1204
 
1159
1205
  outlookSubscription: Joi.object({
1160
- id: Joi.string().description('Microsoft Graph subscription ID'),
1161
- expirationDateTime: Joi.date().iso().allow(null).description('When the subscription expires'),
1206
+ id: Joi.string().example('0fc0f6bb-a3e1-4f7a-9d3a-8e2f1f8b9c11').description('Microsoft Graph subscription ID'),
1207
+ expirationDateTime: Joi.date().iso().allow(null).example('2021-07-11T07:06:34.336Z').description('When the subscription expires'),
1162
1208
  state: Joi.object({
1163
1209
  state: Joi.string()
1164
1210
  .valid('creating', 'created', 'renewing', 'error')
1165
1211
  .description('Subscription state')
1166
1212
  .meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState }),
1167
- time: Joi.number().description('Timestamp of last state change'),
1168
- error: Joi.string().allow(null).description('Error message if state is error, null after a successful renewal'),
1169
- retryCount: Joi.number().integer().description('How many times the subscription renewal has been retried'),
1170
- createRetryCount: Joi.number().integer().description('How many times the subscription creation has been retried')
1213
+ time: Joi.number().example(1625727994336).description('Timestamp of last state change'),
1214
+ error: Joi.string()
1215
+ .allow(null)
1216
+ .example('Subscription renewal was rejected')
1217
+ .description('Error message if state is error, null after a successful renewal'),
1218
+ retryCount: Joi.number().integer().example(0).description('How many times the subscription renewal has been retried'),
1219
+ createRetryCount: Joi.number().integer().example(0).description('How many times the subscription creation has been retried')
1171
1220
  })
1172
1221
  .unknown()
1173
1222
  .description('Current subscription state')
@@ -1206,9 +1255,9 @@ async function init(args) {
1206
1255
  const tokenData = await accountObject.getActiveAccessTokenData();
1207
1256
 
1208
1257
  // Account data stores the OAuth2 app ID as the provider value. Resolve it to the
1209
- // provider name and expose the app ID separately. Legacy app IDs already equal
1210
- // their provider name, so skip the lookup for these.
1211
- if (tokenData.provider && !LEGACY_KEYS.includes(tokenData.provider)) {
1258
+ // provider name and expose the app ID separately. Migrated legacy app IDs equal
1259
+ // their provider name, so the lookup is a no-op rename for these.
1260
+ if (tokenData.provider) {
1212
1261
  let oauth2App = await oauth2Apps.get(tokenData.provider);
1213
1262
  if (oauth2App) {
1214
1263
  if (oauth2App.id !== oauth2App.provider) {
@@ -1368,6 +1417,7 @@ async function init(args) {
1368
1417
  account: request.payload.account,
1369
1418
  name: request.payload.name,
1370
1419
  email: request.payload.email,
1420
+ expectedEmail: request.payload.expectedEmail,
1371
1421
  syncFrom: request.payload.syncFrom,
1372
1422
  notifyFrom: request.payload.notifyFrom,
1373
1423
  subconnections: request.payload.subconnections,
@@ -1423,7 +1473,10 @@ async function init(args) {
1423
1473
 
1424
1474
  options: {
1425
1475
  description: 'Generate authentication link',
1426
- notes: 'Generates a redirect link to the hosted authentication form',
1476
+ notes: [
1477
+ 'Generates a redirect link to the hosted authentication form',
1478
+ 'If `expectedEmail` is set and the user completes the form as a different identity, the setup is rejected before any credentials are stored. The user stays on EmailEngine, which names both addresses and offers to restart the setup, so the browser is never redirected to `redirectUrl`.'
1479
+ ],
1427
1480
  tags: ['api', 'Account'],
1428
1481
 
1429
1482
  plugins: {
@@ -1454,9 +1507,8 @@ async function init(args) {
1454
1507
  .allow(null)
1455
1508
  .example('example')
1456
1509
  .default(null)
1457
- .description(
1458
- 'Account ID. If set to `null`, a unique ID will be generated automatically. If you provide an existing account ID, the settings for that account will be updated instead'
1459
- ),
1510
+ .description('Account ID. If set to `null`, a unique ID will be generated automatically')
1511
+ .meta({ usage: FIELD_USAGE.accountId }),
1460
1512
 
1461
1513
  name: Joi.string().empty('').max(256).example('My Email Account').description('Display name for the account'),
1462
1514
 
@@ -1466,6 +1518,8 @@ async function init(args) {
1466
1518
  .example('user@example.com')
1467
1519
  .description('Specifies the default email address for this account. Users can change it if needed.'),
1468
1520
 
1521
+ expectedEmail: accountSchemas.expectedEmail,
1522
+
1469
1523
  delegated: Joi.boolean()
1470
1524
  .empty('')
1471
1525
  .truthy('Y', 'true', '1')
@@ -1563,6 +1617,7 @@ async function init(args) {
1563
1617
 
1564
1618
  plugins: {
1565
1619
  openapi: {
1620
+ 'x-ee-impact': IMPACT.READONLY,
1566
1621
  responses: apiResponses(
1567
1622
  'Returns the outcome of the IMAP and SMTP connection tests, including per-protocol errors when a test failed.',
1568
1623
  400,
@@ -1590,8 +1645,14 @@ async function init(args) {
1590
1645
 
1591
1646
  payload: Joi.object({
1592
1647
  mailboxes: Joi.boolean().example(false).description('Include mailbox listing in response').default(false).label('IncludeMailboxes'),
1593
- imap: Joi.object(imapSchema).allow(false).description('IMAP configuration').label('ImapConfiguration'),
1594
- smtp: Joi.object(smtpSchema).allow(false).description('SMTP configuration').label('SmtpConfiguration'),
1648
+ imap: Joi.object(imapSchema)
1649
+ .allow(false)
1650
+ .description('IMAP configuration. Set to `false` when there is no IMAP access to configure.')
1651
+ .label('ImapConfiguration'),
1652
+ smtp: Joi.object(smtpSchema)
1653
+ .allow(false)
1654
+ .description('SMTP configuration. Set to `false` when there is no SMTP access to configure.')
1655
+ .label('SmtpConfiguration'),
1595
1656
  proxy: settingsSchema.proxyUrl,
1596
1657
  smtpEhloName: settingsSchema.smtpEhloName
1597
1658
  }).label('VerifyAccount')
@@ -1616,7 +1677,9 @@ async function init(args) {
1616
1677
  let serverSettings = await autodetectImapSettings(request.query.email, request.app.gt);
1617
1678
  return serverSettings;
1618
1679
  } catch (err) {
1619
- request.logger.error({ msg: 'API request failed', err });
1680
+ // autodiscovery fails routinely for unknown domains and the handler answers with a
1681
+ // regular "not found" response, so this is not an operator-visible failure
1682
+ request.logger.debug({ msg: 'API request failed', err });
1620
1683
  if (Boom.isBoom(err)) {
1621
1684
  throw err;
1622
1685
  }
@@ -39,6 +39,9 @@ module.exports = {
39
39
 
40
40
  SSE_STREAM: 'A long-lived Server-Sent Events stream rather than a normal request and response. The connection stays open until the client closes it.',
41
41
 
42
+ DELETION_SCOPE:
43
+ 'Removes the account, its credentials, its cached data and any messages still queued for delivery. Webhook events generated before the deletion are never delivered afterwards and are discarded once the queue reaches them. Records of deliveries that had already failed permanently are not removed here; they expire on the queue retention window, seven days by default.',
44
+
42
45
  // --- provider differences ----------------------------------------------------------
43
46
  NO_QUOTA_ON_API_ACCOUNTS: 'Quota reporting is not available for Gmail API or MS Graph accounts; the quota field is omitted for those.',
44
47
 
@@ -8,8 +8,8 @@ const getSecret = require('../get-secret');
8
8
  const { lists } = require('../lists');
9
9
  const { failAction } = require('../tools');
10
10
  const { handleError } = require('./route-helpers');
11
- const { accountIdSchema, apiResponses } = require('../schemas');
12
- const { REDIS_PREFIX } = require('../consts');
11
+ const { accountIdSchema, blocklistListIdSchema, apiResponses } = require('../schemas');
12
+ const { IMPACT } = require('./operation-impact');
13
13
 
14
14
  async function init(args) {
15
15
  const { server, call, CORS_CONFIG } = args;
@@ -28,7 +28,7 @@ async function init(args) {
28
28
 
29
29
  options: {
30
30
  description: 'List blocklists',
31
- notes: 'List blocklists with blocked addresses',
31
+ notes: 'List suppression lists (blocklists) with the number of blocked addresses on each',
32
32
  tags: ['api', 'Blocklists'],
33
33
 
34
34
  plugins: {
@@ -98,7 +98,7 @@ async function init(args) {
98
98
 
99
99
  options: {
100
100
  description: 'List blocklist entries',
101
- notes: 'List blocked addresses for a list',
101
+ notes: 'List suppressed addresses for a list',
102
102
  tags: ['api', 'Blocklists'],
103
103
 
104
104
  plugins: {
@@ -122,12 +122,7 @@ async function init(args) {
122
122
  failAction,
123
123
 
124
124
  params: Joi.object({
125
- listId: Joi.string()
126
- .hostname()
127
- .example('test-list')
128
- .description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
129
- .label('ListID')
130
- .required()
125
+ listId: blocklistListIdSchema
131
126
  }).label('BlocklistListRequest'),
132
127
 
133
128
  query: Joi.object({
@@ -162,6 +157,7 @@ async function init(args) {
162
157
  version: ['ipv4', 'ipv6'],
163
158
  cidr: 'optional'
164
159
  })
160
+ .example('198.51.100.24')
165
161
  .description('Which IP address triggered the entry'),
166
162
  userAgent: Joi.string().example('Mozilla/5.0 (Macintosh)').description('Which user agent triggered the entry'),
167
163
  created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was added or updated').required()
@@ -190,21 +186,13 @@ async function init(args) {
190
186
  // throws if account does not exist
191
187
  await accountObject.loadAccountData();
192
188
 
193
- let added = await redis.eeListAdd(
194
- `${REDIS_PREFIX}lists:unsub:lists`,
195
- `${REDIS_PREFIX}lists:unsub:entries:${request.params.listId}`,
196
- request.params.listId,
197
- request.payload.recipient.toLowerCase().trim(),
198
- JSON.stringify({
199
- recipient: request.payload.recipient,
200
- account: request.payload.account,
201
- source: 'api',
202
- reason: request.payload.reason,
203
- remoteAddress: request.app.ip,
204
- userAgent: request.headers['user-agent'],
205
- created: new Date().toISOString()
206
- })
207
- );
189
+ let added = await lists.add(request.params.listId, request.payload.recipient, {
190
+ account: request.payload.account,
191
+ source: 'api',
192
+ reason: request.payload.reason,
193
+ remoteAddress: request.app.ip,
194
+ userAgent: request.headers['user-agent']
195
+ });
208
196
 
209
197
  return {
210
198
  success: true,
@@ -216,7 +204,7 @@ async function init(args) {
216
204
  },
217
205
  options: {
218
206
  description: 'Add to blocklist',
219
- notes: 'Add an email address to a blocklist',
207
+ notes: 'Add an email address to a suppression list. Sending with this listId skips the address',
220
208
  tags: ['api', 'Blocklists'],
221
209
 
222
210
  plugins: {
@@ -240,18 +228,13 @@ async function init(args) {
240
228
  failAction,
241
229
 
242
230
  params: Joi.object({
243
- listId: Joi.string()
244
- .hostname()
245
- .example('test-list')
246
- .description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
247
- .label('ListID')
248
- .required()
231
+ listId: blocklistListIdSchema
249
232
  }).label('BlocklistListRequest'),
250
233
 
251
234
  payload: Joi.object({
252
235
  account: accountIdSchema.required(),
253
236
  recipient: Joi.string().empty('').email().example('user@example.com').description('Email address to add to the list').required(),
254
- reason: Joi.string().empty('').default('block').description('Identifier for the blocking reason')
237
+ reason: Joi.string().empty('').default('block').example('unsubscribe').description('Identifier for the blocking reason')
255
238
  }).label('BlocklistListAddPayload')
256
239
  },
257
240
 
@@ -271,19 +254,14 @@ async function init(args) {
271
254
 
272
255
  async handler(request) {
273
256
  try {
274
- let exists = await redis.hexists(`${REDIS_PREFIX}lists:unsub:lists`, request.params.listId);
257
+ let exists = await lists.exists(request.params.listId);
275
258
  if (!exists) {
276
259
  let message = 'Requested blocklist was not found';
277
260
  let error = Boom.boomify(new Error(message), { statusCode: 404 });
278
261
  throw error;
279
262
  }
280
263
 
281
- let deleted = await redis.eeListRemove(
282
- `${REDIS_PREFIX}lists:unsub:lists`,
283
- `${REDIS_PREFIX}lists:unsub:entries:${request.params.listId}`,
284
- request.params.listId,
285
- request.query.recipient.toLowerCase().trim()
286
- );
264
+ let deleted = await lists.remove(request.params.listId, request.query.recipient);
287
265
 
288
266
  return {
289
267
  deleted: !!deleted
@@ -294,11 +272,12 @@ async function init(args) {
294
272
  },
295
273
  options: {
296
274
  description: 'Remove from blocklist',
297
- notes: 'Delete a blocked email address from a list',
275
+ notes: 'Remove a suppressed email address from a list',
298
276
  tags: ['api', 'Blocklists'],
299
277
 
300
278
  plugins: {
301
279
  openapi: {
280
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
302
281
  responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
303
282
  }
304
283
  },
@@ -318,12 +297,7 @@ async function init(args) {
318
297
  failAction,
319
298
 
320
299
  params: Joi.object({
321
- listId: Joi.string()
322
- .hostname()
323
- .example('test-list')
324
- .description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
325
- .label('ListID')
326
- .required()
300
+ listId: blocklistListIdSchema
327
301
  }).label('BlocklistListRequest'),
328
302
 
329
303
  query: Joi.object({
@@ -6,8 +6,8 @@ const getSecret = require('../get-secret');
6
6
  const Boom = require('@hapi/boom');
7
7
  const Joi = require('joi');
8
8
  const { failAction, getBoolean } = require('../tools');
9
+ const { logApiError } = require('./route-helpers');
9
10
  const settings = require('../settings');
10
- const util = require('util');
11
11
 
12
12
  const LOG_VERBOSE = getBoolean(process.env.EE_OPENAPI_VERBOSE);
13
13
 
@@ -37,7 +37,7 @@ async function init(args) {
37
37
  const { server, call, CORS_CONFIG } = args;
38
38
 
39
39
  async function processChatRequest(opts) {
40
- let { account, question, index, client } = opts;
40
+ let { account, question, index, client, logger } = opts;
41
41
 
42
42
  // throws if account does not exist
43
43
  let accountObject = new Account({ redis, account, call, secret: await getSecret() });
@@ -323,7 +323,7 @@ async function init(args) {
323
323
  }
324
324
 
325
325
  if (LOG_VERBOSE) {
326
- console.error(util.inspect({ searchQuery, searchResult }, false, 8, true));
326
+ logger.trace({ msg: 'Chat search result', searchQuery, searchResult });
327
327
  }
328
328
 
329
329
  if (searchResult && searchResult.hits && searchResult.hits.hits && searchResult.hits.hits.length) {
@@ -378,14 +378,15 @@ async function init(args) {
378
378
  account: request.params.account,
379
379
  question: request.payload.question,
380
380
  index,
381
- client
381
+ client,
382
+ logger: request.logger
382
383
  });
383
384
  } catch (err) {
384
- request.logger.error({ msg: 'API request failed', err });
385
+ let statusCode = logApiError(request, err);
385
386
  if (Boom.isBoom(err)) {
386
387
  throw err;
387
388
  }
388
- let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
389
+ let error = Boom.boomify(err, { statusCode });
389
390
  if (err.code) {
390
391
  error.output.payload.code = err.code;
391
392
  }
@@ -494,14 +495,11 @@ async function init(args) {
494
495
  account: request.payload.account,
495
496
  question: request.payload.question,
496
497
  index,
497
- client
498
+ client,
499
+ logger: request.logger
498
500
  });
499
501
  } catch (err) {
500
- request.logger.error({
501
- msg: 'Failed posting request',
502
- command: 'info',
503
- err
504
- });
502
+ request.logger.error({ msg: 'Failed to run chat test', err });
505
503
  return {
506
504
  success: false,
507
505
  error: err.message
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const Boom = require('@hapi/boom');
4
3
  const Joi = require('joi');
5
4
  const { fetch: fetchCmd } = require('undici');
6
5
  const { redis } = require('../db');
@@ -12,6 +11,8 @@ const { accountIdSchema, apiResponses } = require('../schemas');
12
11
  const { REDIS_PREFIX } = require('../consts');
13
12
  const packageData = require('../../package.json');
14
13
  const BEHAVIOR = require('./behavior-notes');
14
+ const { handleError } = require('./route-helpers');
15
+ const { IMPACT } = require('./operation-impact');
15
16
 
16
17
  async function init(args) {
17
18
  const { server, call, CORS_CONFIG, SMTP_TEST_HOST } = args;
@@ -119,18 +120,7 @@ ${now}`,
119
120
  };
120
121
  }
121
122
  } catch (err) {
122
- request.logger.error({ msg: 'API request failed', err });
123
- if (Boom.isBoom(err)) {
124
- throw err;
125
- }
126
- let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
127
- if (err.code) {
128
- error.output.payload.code = err.code;
129
- }
130
- if (err.details) {
131
- error.output.payload.details = err.details;
132
- }
133
- throw error;
123
+ handleError(request, err);
134
124
  }
135
125
  },
136
126
  options: {
@@ -140,6 +130,7 @@ ${now}`,
140
130
 
141
131
  plugins: {
142
132
  openapi: {
133
+ 'x-ee-impact': IMPACT.SENDS,
143
134
  'x-ee-behavior': [BEHAVIOR.BACKGROUND_JOB],
144
135
  responses: apiResponses(
145
136
  'Returns the ID of the started deliverability test. Poll the check endpoint for the result.',
@@ -203,7 +194,7 @@ ${now}`,
203
194
  path: '/v1/delivery-test/check/{deliveryTest}',
204
195
  async handler(request) {
205
196
  try {
206
- request.logger.info({ msg: 'Requested SMTP delivery test check', deliveryTest: request.params.deliveryTest });
197
+ request.logger.debug({ msg: 'Requested SMTP delivery test check', deliveryTest: request.params.deliveryTest });
207
198
 
208
199
  let deliveryStatus = (await redis.hgetall(`${REDIS_PREFIX}test-send:${request.params.deliveryTest}`)) || {};
209
200
  if (deliveryStatus.success === 'false') {
@@ -278,18 +269,7 @@ ${now}`,
278
269
 
279
270
  return Object.assign({ success }, testResponse || {});
280
271
  } catch (err) {
281
- request.logger.error({ msg: 'API request failed', err });
282
- if (Boom.isBoom(err)) {
283
- throw err;
284
- }
285
- let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
286
- if (err.code) {
287
- error.output.payload.code = err.code;
288
- }
289
- if (err.details) {
290
- error.output.payload.details = err.details;
291
- }
292
- throw error;
272
+ handleError(request, err);
293
273
  }
294
274
  },
295
275
  options: {
@@ -10,6 +10,7 @@ const getSecret = require('../get-secret');
10
10
  const { createDecryptStream } = require('../stream-encrypt');
11
11
  const { handleError } = require('./route-helpers');
12
12
  const BEHAVIOR = require('./behavior-notes');
13
+ const { IMPACT } = require('./operation-impact');
13
14
 
14
15
  async function init(args) {
15
16
  const { server, CORS_CONFIG } = args;
@@ -231,6 +232,7 @@ async function init(args) {
231
232
 
232
233
  plugins: {
233
234
  openapi: {
235
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
234
236
  responses: apiResponses('Returns a deletion marker. Any partially written export file is removed.', 400, 401, 403, 404, 429, 500)
235
237
  }
236
238
  },