emailengine-app 2.76.0 → 2.78.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 (165) hide show
  1. package/.github/workflows/release.yaml +24 -19
  2. package/.github/workflows/test.yml +80 -0
  3. package/.ncurc.js +14 -2
  4. package/.release-please-manifest.json +3 -0
  5. package/CHANGELOG.md +54 -0
  6. package/README.md +1 -1
  7. package/bin/emailengine.js +1 -1
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +72 -5
  10. package/lib/account/expected-identity.js +88 -0
  11. package/lib/account.js +75 -26
  12. package/lib/address-strategies.js +18 -0
  13. package/lib/api-reference/code-samples.js +194 -0
  14. package/lib/api-reference/format.js +193 -0
  15. package/lib/api-reference/index.js +222 -0
  16. package/lib/api-reference/model.js +338 -0
  17. package/lib/api-reference/schema-tree.js +366 -0
  18. package/lib/api-routes/account-routes.js +136 -39
  19. package/lib/api-routes/behavior-notes.js +57 -0
  20. package/lib/api-routes/blocklist-routes.js +9 -9
  21. package/lib/api-routes/changes-routes.js +6 -4
  22. package/lib/api-routes/chat-routes.js +3 -3
  23. package/lib/api-routes/delivery-test-routes.js +24 -6
  24. package/lib/api-routes/export-routes.js +14 -12
  25. package/lib/api-routes/gateway-routes.js +11 -11
  26. package/lib/api-routes/license-routes.js +7 -7
  27. package/lib/api-routes/mailbox-routes.js +18 -9
  28. package/lib/api-routes/message-routes.js +55 -35
  29. package/lib/api-routes/oauth2-app-routes.js +22 -16
  30. package/lib/api-routes/outbox-routes.js +7 -7
  31. package/lib/api-routes/pubsub-routes.js +3 -3
  32. package/lib/api-routes/settings-routes.js +10 -9
  33. package/lib/api-routes/stats-routes.js +3 -3
  34. package/lib/api-routes/submit-routes.js +58 -8
  35. package/lib/api-routes/template-routes.js +13 -13
  36. package/lib/api-routes/token-routes.js +15 -10
  37. package/lib/api-routes/webhook-route-routes.js +5 -5
  38. package/lib/append-list.js +3 -14
  39. package/lib/arf-detect.js +23 -1
  40. package/lib/autodetect-imap-settings.js +40 -16
  41. package/lib/base32.js +30 -0
  42. package/lib/bounce-detect.js +182 -62
  43. package/lib/consts.js +7 -0
  44. package/lib/egress-filter.js +89 -8
  45. package/lib/email-client/base-client.js +72 -82
  46. package/lib/email-client/gmail-client.js +3 -3
  47. package/lib/email-client/imap/listing-diff.js +3 -3
  48. package/lib/email-client/imap/mailbox.js +5 -69
  49. package/lib/email-client/imap-client.js +3 -2
  50. package/lib/email-client/message-builder.js +13 -13
  51. package/lib/email-client/outlook-client.js +1 -1
  52. package/lib/enum-descriptions.js +130 -0
  53. package/lib/export.js +1 -1
  54. package/lib/gateway.js +1 -1
  55. package/lib/get-raw-email.js +1 -1
  56. package/lib/imapproxy/imap-core/lib/imap-connection.js +2 -2
  57. package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
  58. package/lib/imapproxy/imap-server.js +42 -28
  59. package/lib/imapproxy/upstream-client.js +38 -0
  60. package/lib/license-beacon.js +1 -1
  61. package/lib/llm-pre-process.js +1 -1
  62. package/lib/msgpack.js +62 -0
  63. package/lib/oauth/decode-jwt-payload.js +39 -0
  64. package/lib/oauth/outlook-identity.js +61 -0
  65. package/lib/oauth/retry-setup.js +38 -0
  66. package/lib/oauth2-apps.js +10 -4
  67. package/lib/openapi/build-document.js +318 -0
  68. package/lib/openapi/index.js +95 -0
  69. package/lib/openapi/joi-schema.js +523 -0
  70. package/lib/outbox.js +66 -3
  71. package/lib/pre-process.js +1 -1
  72. package/lib/read-env-value.js +37 -0
  73. package/lib/routes-ui.js +5 -1
  74. package/lib/schemas.js +88 -17
  75. package/lib/swagger-options.js +173 -0
  76. package/lib/templates.js +1 -1
  77. package/lib/tokens.js +70 -6
  78. package/lib/tools.js +117 -48
  79. package/lib/totp.js +67 -0
  80. package/lib/ui-routes/account-routes.js +91 -15
  81. package/lib/ui-routes/admin-config-routes.js +2 -7
  82. package/lib/ui-routes/admin-entities-routes.js +3 -0
  83. package/lib/ui-routes/auth-routes.js +6 -24
  84. package/lib/ui-routes/dashboard-routes.js +2 -26
  85. package/lib/ui-routes/reference-routes.js +198 -0
  86. package/lib/ui-routes/route-helpers.js +39 -0
  87. package/lib/utils/is-email.js +34 -0
  88. package/lib/utils/to-camel-case.js +17 -0
  89. package/lib/webhook-egress.js +37 -0
  90. package/lib/webhooks.js +1 -1
  91. package/package.json +27 -31
  92. package/prepare-bundle-deps.sh +28 -0
  93. package/release-please-config.json +11 -0
  94. package/sbom.json +1 -1
  95. package/server.js +11 -3
  96. package/static/css/flyonui.css +1 -1
  97. package/static/css/public.css +3 -0
  98. package/static/css/src/app.tailwind.css +113 -0
  99. package/static/js/app.js +69 -0
  100. package/static/js/ee-client.js +238 -8
  101. package/static/js/reference.js +1021 -0
  102. package/static/js/ui.js +61 -33
  103. package/static/licenses.html +658 -1560
  104. package/translations/README.md +64 -0
  105. package/translations/de.mo +0 -0
  106. package/translations/de.po +164 -120
  107. package/translations/en.po +200 -161
  108. package/translations/et.mo +0 -0
  109. package/translations/et.po +163 -120
  110. package/translations/fr.mo +0 -0
  111. package/translations/fr.po +163 -120
  112. package/translations/ja.mo +0 -0
  113. package/translations/ja.po +163 -120
  114. package/translations/messages.pot +84 -54
  115. package/translations/nl.mo +0 -0
  116. package/translations/nl.po +164 -120
  117. package/translations/pl.mo +0 -0
  118. package/translations/pl.po +163 -120
  119. package/views/account-identity-error.hbs +34 -0
  120. package/views/accounts/edit.hbs +1 -0
  121. package/views/accounts/register/imap.hbs +12 -2
  122. package/views/config/ai.hbs +1 -1
  123. package/views/config/document-store/chat.hbs +5 -5
  124. package/views/config/document-store/index.hbs +2 -2
  125. package/views/config/document-store/pre-processing/index.hbs +1 -1
  126. package/views/config/email-processing.hbs +1 -1
  127. package/views/config/imap-proxy.hbs +1 -1
  128. package/views/config/license.hbs +1 -1
  129. package/views/config/oauth/index.hbs +3 -3
  130. package/views/config/security.hbs +1 -1
  131. package/views/config/smtp.hbs +2 -2
  132. package/views/dashboard.hbs +1 -1
  133. package/views/layout/app.hbs +43 -8
  134. package/views/oauth-scope-error.hbs +1 -1
  135. package/views/partials/oauth_form.hbs +4 -4
  136. package/views/partials/reference/anchor-link.hbs +20 -0
  137. package/views/partials/reference/disclosure.hbs +37 -0
  138. package/views/partials/reference/nav.hbs +120 -0
  139. package/views/partials/reference/operation.hbs +127 -0
  140. package/views/partials/reference/params.hbs +20 -0
  141. package/views/partials/reference/schema-node.hbs +99 -0
  142. package/views/partials/reference/schema.hbs +19 -0
  143. package/views/partials/reference/section-heading.hbs +16 -0
  144. package/views/partials/reference/token-alert.hbs +49 -0
  145. package/views/partials/reference/try-field.hbs +31 -0
  146. package/views/partials/reference/try-it.hbs +78 -0
  147. package/views/partials/side_menu.hbs +1 -1
  148. package/views/partials/ui/badge.hbs +4 -2
  149. package/views/partials/ui/page-header.hbs +1 -1
  150. package/views/partials/ui/search-input.hbs +31 -0
  151. package/views/partials/ui/setting-ref.hbs +1 -1
  152. package/views/partials/ui/stat-card.hbs +4 -2
  153. package/views/partials/ui/tab.hbs +6 -1
  154. package/views/partials/ui/tabs.hbs +2 -2
  155. package/views/reference/index.hbs +76 -0
  156. package/views/reference/redirect.hbs +49 -0
  157. package/views/reference/tag.hbs +28 -0
  158. package/views/reference/token.hbs +49 -0
  159. package/views/tokens/index.hbs +9 -1
  160. package/views/webhooks/index.hbs +3 -3
  161. package/workers/api.js +194 -302
  162. package/workers/imap.js +1 -1
  163. package/workers/submit.js +1 -1
  164. package/workers/webhooks.js +2 -13
  165. package/views/swagger/index.hbs +0 -82
@@ -28,10 +28,12 @@ const {
28
28
  defaultAccountTypeSchema,
29
29
  shortMailboxesSchema,
30
30
  ACCOUNT_DISPLAY_STATES,
31
- errorResponses
31
+ apiResponses,
32
+ ENUM_DESCRIPTIONS
32
33
  } = require('../schemas');
33
34
 
34
35
  const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES } = require('../consts');
36
+ const BEHAVIOR = require('./behavior-notes');
35
37
 
36
38
  // OAuth2 scope list stored on the account (accountData.oauth2.scope). Reused with a per-route
37
39
  // description/label where the same value is exposed under a different field name
@@ -177,12 +179,21 @@ async function init(args) {
177
179
 
178
180
  options: {
179
181
  description: 'Register new account',
180
- notes: 'Registers new IMAP account to be synced',
182
+ notes: ['Registers new IMAP account to be synced', BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
181
183
  tags: ['api', 'Account'],
182
184
 
183
185
  plugins: {
184
- 'hapi-swagger': {
185
- responses: errorResponses(400, 401, 403, 404, 429, 500)
186
+ openapi: {
187
+ 'x-ee-behavior': [BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
188
+ responses: apiResponses(
189
+ 'Returns the registered account, including the generated account ID when one was not supplied.',
190
+ 400,
191
+ 401,
192
+ 403,
193
+ 404,
194
+ 429,
195
+ 500
196
+ )
186
197
  }
187
198
  },
188
199
 
@@ -215,6 +226,8 @@ async function init(args) {
215
226
  name: Joi.string().max(256).required().example('My Email Account').description('Display name for the account'),
216
227
  email: Joi.string().empty('').email().example('user@example.com').description('Default email address of the account'),
217
228
 
229
+ expectedEmail: accountSchemas.expectedEmail,
230
+
218
231
  path: accountPathSchema.example(['*']).label('AccountPath'),
219
232
 
220
233
  subconnections: accountSchemas.subconnections,
@@ -329,12 +342,13 @@ async function init(args) {
329
342
  },
330
343
  options: {
331
344
  description: 'Update account info',
332
- notes: 'Updates account information',
345
+ notes: ['Updates account information', BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
333
346
  tags: ['api', 'Account'],
334
347
 
335
348
  plugins: {
336
- 'hapi-swagger': {
337
- responses: errorResponses(400, 401, 403, 404, 429, 500)
349
+ openapi: {
350
+ 'x-ee-behavior': [BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
351
+ responses: apiResponses('Returns the account ID. Changed credentials take effect on the next connection.', 400, 401, 403, 404, 429, 500)
338
352
  }
339
353
  },
340
354
 
@@ -360,6 +374,8 @@ async function init(args) {
360
374
  name: Joi.string().max(256).example('My Email Account').description('Display name for the account'),
361
375
  email: Joi.string().empty('').email().example('user@example.com').description('Default email address of the account'),
362
376
 
377
+ expectedEmail: accountSchemas.expectedEmailUpdate,
378
+
363
379
  path: accountPathSchema.example(['*']).label('AccountPath'),
364
380
 
365
381
  subconnections: accountSchemas.subconnections,
@@ -441,12 +457,21 @@ async function init(args) {
441
457
  },
442
458
  options: {
443
459
  description: 'Request reconnect',
444
- notes: 'Requests connection to be reconnected',
460
+ notes: ['Requests connection to be reconnected', BEHAVIOR.SCHEDULED_ON_WORKER],
445
461
  tags: ['api', 'Account'],
446
462
 
447
463
  plugins: {
448
- 'hapi-swagger': {
449
- responses: errorResponses(400, 401, 403, 404, 429, 500)
464
+ openapi: {
465
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
466
+ responses: apiResponses(
467
+ 'Returns an acknowledgement. The reconnect is requested, not completed - watch the account state for the result.',
468
+ 400,
469
+ 401,
470
+ 403,
471
+ 404,
472
+ 429,
473
+ 500
474
+ )
450
475
  }
451
476
  },
452
477
 
@@ -504,12 +529,21 @@ async function init(args) {
504
529
  },
505
530
  options: {
506
531
  description: 'Request syncing',
507
- notes: 'Immediately trigger account syncing for IMAP accounts',
532
+ notes: ['Immediately trigger account syncing for IMAP accounts', BEHAVIOR.SCHEDULED_ON_WORKER],
508
533
  tags: ['api', 'Account'],
509
534
 
510
535
  plugins: {
511
- 'hapi-swagger': {
512
- responses: errorResponses(400, 401, 403, 404, 429, 500)
536
+ openapi: {
537
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
538
+ responses: apiResponses(
539
+ 'Returns an acknowledgement. A full mailbox sync is scheduled and runs in the background.',
540
+ 400,
541
+ 401,
542
+ 403,
543
+ 404,
544
+ 429,
545
+ 500
546
+ )
513
547
  }
514
548
  },
515
549
 
@@ -568,13 +602,25 @@ async function init(args) {
568
602
  },
569
603
  options: {
570
604
  description: 'Remove account',
571
- 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.",
605
+ notes: [
606
+ "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.",
607
+ BEHAVIOR.DELETION_SCOPE
608
+ ],
572
609
 
573
610
  tags: ['api', 'Account'],
574
611
 
575
612
  plugins: {
576
- 'hapi-swagger': {
577
- responses: errorResponses(400, 401, 403, 404, 429, 500)
613
+ openapi: {
614
+ 'x-ee-behavior': [BEHAVIOR.DELETION_SCOPE],
615
+ responses: apiResponses(
616
+ 'Returns a deletion marker. The account stops syncing immediately; stored data is removed in the background.',
617
+ 400,
618
+ 401,
619
+ 403,
620
+ 404,
621
+ 429,
622
+ 500
623
+ )
578
624
  }
579
625
  },
580
626
 
@@ -640,12 +686,24 @@ async function init(args) {
640
686
  },
641
687
  options: {
642
688
  description: 'Request account flush',
643
- notes: 'Deletes all email indexes from Redis and ElasticSearch and re-creates the index for that account. You can only run a single flush operation at a time, so you must wait until the previous flush has finished before initiating a new one.',
689
+ notes: [
690
+ 'Deletes all email indexes from Redis and ElasticSearch and re-creates the index for that account. You can only run a single flush operation at a time, so you must wait until the previous flush has finished before initiating a new one.',
691
+ BEHAVIOR.SCHEDULED_ON_WORKER
692
+ ],
644
693
  tags: ['api', 'Account'],
645
694
 
646
695
  plugins: {
647
- 'hapi-swagger': {
648
- responses: errorResponses(400, 401, 403, 404, 429, 500)
696
+ openapi: {
697
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
698
+ responses: apiResponses(
699
+ 'Returns an acknowledgement. Cached message indexes are cleared and rebuilt in the background.',
700
+ 400,
701
+ 401,
702
+ 403,
703
+ 404,
704
+ 429,
705
+ 500
706
+ )
649
707
  }
650
708
  },
651
709
 
@@ -711,8 +769,8 @@ async function init(args) {
711
769
  tags: ['api', 'Account'],
712
770
 
713
771
  plugins: {
714
- 'hapi-swagger': {
715
- responses: errorResponses(400, 401, 403, 429, 500)
772
+ openapi: {
773
+ responses: apiResponses('Returns a page of accounts with their connection states.', 400, 401, 403, 429, 500)
716
774
  }
717
775
  },
718
776
 
@@ -744,6 +802,7 @@ async function init(args) {
744
802
  .valid(...ACCOUNT_DISPLAY_STATES)
745
803
  .example('connected')
746
804
  .description('Filter accounts by state')
805
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountState })
747
806
  .label('AccountState'),
748
807
  query: Joi.string().example('user@example.com').description('Filter accounts by string match').label('AccountQuery')
749
808
  }).label('AccountsFilter')
@@ -778,6 +837,7 @@ async function init(args) {
778
837
  .valid(...ACCOUNT_DISPLAY_STATES)
779
838
  .example('connected')
780
839
  .description('Account state')
840
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountState })
781
841
  .label('AccountListState'),
782
842
  webhooks: Joi.string()
783
843
  .uri({
@@ -846,6 +906,7 @@ async function init(args) {
846
906
  'account',
847
907
  'name',
848
908
  'email',
909
+ 'expectedEmail',
849
910
  'copy',
850
911
  'logs',
851
912
  'notifyFrom',
@@ -946,12 +1007,13 @@ async function init(args) {
946
1007
  },
947
1008
  options: {
948
1009
  description: 'Get account info',
949
- notes: 'Returns stored information about the account. Passwords are not included.',
1010
+ notes: ['Returns stored information about the account. Passwords are not included.', BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
950
1011
  tags: ['api', 'Account'],
951
1012
 
952
1013
  plugins: {
953
- 'hapi-swagger': {
954
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1014
+ openapi: {
1015
+ 'x-ee-behavior': [BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
1016
+ responses: apiResponses('Returns the account configuration, connection state and sync status.', 400, 401, 403, 404, 429, 500)
955
1017
  }
956
1018
  },
957
1019
 
@@ -990,6 +1052,8 @@ async function init(args) {
990
1052
  name: Joi.string().allow('').max(256).example('My Email Account').description('Display name for the account'),
991
1053
  email: Joi.string().empty('').email().example('user@example.com').description('Default email address of the account'),
992
1054
 
1055
+ expectedEmail: accountSchemas.expectedEmail,
1056
+
993
1057
  copy: Joi.boolean().example(true).description('Copy submitted messages to Sent folder'),
994
1058
  logs: Joi.boolean().example(false).description('Store recent logs'),
995
1059
 
@@ -1035,6 +1099,7 @@ async function init(args) {
1035
1099
  .valid(...ACCOUNT_DISPLAY_STATES)
1036
1100
  .example('connected')
1037
1101
  .description('Informational account state')
1102
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountState })
1038
1103
  .label('AccountInfoState'),
1039
1104
 
1040
1105
  smtpStatus: Joi.object({
@@ -1106,7 +1171,10 @@ async function init(args) {
1106
1171
  id: Joi.string().description('Microsoft Graph subscription ID'),
1107
1172
  expirationDateTime: Joi.date().iso().allow(null).description('When the subscription expires'),
1108
1173
  state: Joi.object({
1109
- state: Joi.string().valid('creating', 'created', 'renewing', 'error').description('Subscription state'),
1174
+ state: Joi.string()
1175
+ .valid('creating', 'created', 'renewing', 'error')
1176
+ .description('Subscription state')
1177
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState }),
1110
1178
  time: Joi.number().description('Timestamp of last state change'),
1111
1179
  error: Joi.string().allow(null).description('Error message if state is error, null after a successful renewal'),
1112
1180
  retryCount: Joi.number().integer().description('How many times the subscription renewal has been retried'),
@@ -1183,8 +1251,16 @@ async function init(args) {
1183
1251
  tags: ['api', 'Account'],
1184
1252
 
1185
1253
  plugins: {
1186
- 'hapi-swagger': {
1187
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1254
+ openapi: {
1255
+ responses: apiResponses(
1256
+ 'Returns a valid OAuth2 access token for the account, refreshing it first if it had expired.',
1257
+ 400,
1258
+ 401,
1259
+ 403,
1260
+ 404,
1261
+ 429,
1262
+ 500
1263
+ )
1188
1264
  }
1189
1265
  },
1190
1266
 
@@ -1251,8 +1327,8 @@ async function init(args) {
1251
1327
  tags: ['api', 'Account'],
1252
1328
 
1253
1329
  plugins: {
1254
- 'hapi-swagger': {
1255
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1330
+ openapi: {
1331
+ responses: apiResponses('Returns the signatures configured on the account, as reported by the provider.', 400, 401, 403, 404, 429, 500)
1256
1332
  }
1257
1333
  },
1258
1334
 
@@ -1303,6 +1379,7 @@ async function init(args) {
1303
1379
  account: request.payload.account,
1304
1380
  name: request.payload.name,
1305
1381
  email: request.payload.email,
1382
+ expectedEmail: request.payload.expectedEmail,
1306
1383
  syncFrom: request.payload.syncFrom,
1307
1384
  notifyFrom: request.payload.notifyFrom,
1308
1385
  subconnections: request.payload.subconnections,
@@ -1358,12 +1435,15 @@ async function init(args) {
1358
1435
 
1359
1436
  options: {
1360
1437
  description: 'Generate authentication link',
1361
- notes: 'Generates a redirect link to the hosted authentication form',
1438
+ notes: [
1439
+ 'Generates a redirect link to the hosted authentication form',
1440
+ '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`.'
1441
+ ],
1362
1442
  tags: ['api', 'Account'],
1363
1443
 
1364
1444
  plugins: {
1365
- 'hapi-swagger': {
1366
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1445
+ openapi: {
1446
+ responses: apiResponses('Returns a single-use URL for the hosted authentication form.', 400, 401, 403, 404, 429, 500)
1367
1447
  }
1368
1448
  },
1369
1449
 
@@ -1401,6 +1481,8 @@ async function init(args) {
1401
1481
  .example('user@example.com')
1402
1482
  .description('Specifies the default email address for this account. Users can change it if needed.'),
1403
1483
 
1484
+ expectedEmail: accountSchemas.expectedEmail,
1485
+
1404
1486
  delegated: Joi.boolean()
1405
1487
  .empty('')
1406
1488
  .truthy('Y', 'true', '1')
@@ -1448,7 +1530,7 @@ async function init(args) {
1448
1530
  },
1449
1531
  options: {
1450
1532
  description: 'Return IMAP logs for an account',
1451
- notes: 'Output is a downloadable text file',
1533
+ notes: ['Output is a downloadable text file', BEHAVIOR.IMAP_ONLY],
1452
1534
  tags: ['api', 'Logs'],
1453
1535
 
1454
1536
  auth: {
@@ -1458,9 +1540,10 @@ async function init(args) {
1458
1540
  cors: CORS_CONFIG,
1459
1541
 
1460
1542
  plugins: {
1461
- 'hapi-swagger': {
1543
+ openapi: {
1544
+ 'x-ee-behavior': [BEHAVIOR.IMAP_ONLY],
1462
1545
  produces: ['text/plain'],
1463
- responses: errorResponses(400, 401, 403, 429, 500)
1546
+ responses: apiResponses('Returns the account log as a plain text stream.', 400, 401, 403, 429, 500)
1464
1547
  }
1465
1548
  },
1466
1549
 
@@ -1496,8 +1579,15 @@ async function init(args) {
1496
1579
  tags: ['api', 'Account'],
1497
1580
 
1498
1581
  plugins: {
1499
- 'hapi-swagger': {
1500
- responses: errorResponses(400, 401, 403, 429, 500)
1582
+ openapi: {
1583
+ responses: apiResponses(
1584
+ 'Returns the outcome of the IMAP and SMTP connection tests, including per-protocol errors when a test failed.',
1585
+ 400,
1586
+ 401,
1587
+ 403,
1588
+ 429,
1589
+ 500
1590
+ )
1501
1591
  }
1502
1592
  },
1503
1593
 
@@ -1557,8 +1647,15 @@ async function init(args) {
1557
1647
  tags: ['api', 'Settings'],
1558
1648
 
1559
1649
  plugins: {
1560
- 'hapi-swagger': {
1561
- responses: errorResponses(400, 401, 403, 429, 500)
1650
+ openapi: {
1651
+ responses: apiResponses(
1652
+ 'Returns the discovered IMAP and SMTP settings for the address, or empty values when nothing could be resolved.',
1653
+ 400,
1654
+ 401,
1655
+ 403,
1656
+ 429,
1657
+ 500
1658
+ )
1562
1659
  }
1563
1660
  },
1564
1661
 
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ // Per-operation behavior notes: the things a caller has to know that the request and
4
+ // response schemas cannot express - whether the work is asynchronous, what a 200 actually
5
+ // promises, and where a provider's API behaves differently from IMAP.
6
+ //
7
+ // Routes declare each note TWICE, on purpose:
8
+ // - appended to the route's `notes` array, which the generator joins into the standard
9
+ // `description` field, so every consumer of /swagger.json sees it;
10
+ // - listed under `plugins.openapi['x-ee-behavior']`, so the API reference can tell
11
+ // these apart from the operation's own prose and render them as a callout.
12
+ // A vendor extension alone would be invisible to Postman, Redoc and code generators, which
13
+ // is exactly the audience that would otherwise ship "a 2xx means sent". A test asserts the
14
+ // two declarations stay in step.
15
+ //
16
+ // The provider notes are transcribed by hand from the transports, and nothing enforces the
17
+ // copy. When changing one, check the code that actually implements the limit - not the
18
+ // ASCII capability matrices at the top of those files, which are comments too:
19
+ // NO_LABEL_SET_ON_GMAIL lib/email-client/gmail-client.js, prepareLabelUpdate throw
20
+ // GMAIL_DELETE_IS_TRASH lib/email-client/gmail-client.js, deleteMessage
21
+ // UPLOAD_DRAFTS_ONLY_GRAPH lib/email-client/outlook-client.js, uploadMessage
22
+ // NO_QUOTA_ON_API_ACCOUNTS getQuota on both clients
23
+
24
+ module.exports = {
25
+ // --- asynchronous work -------------------------------------------------------------
26
+ QUEUED_DELIVERY:
27
+ 'Delivery is asynchronous. A 2xx means the message was queued, not that it was sent. Failed attempts are retried with exponential backoff up to the configured deliveryAttempts; follow the outcome through the Outbox endpoints or the messageSent, messageDeliveryError and messageFailed webhooks.',
28
+
29
+ SENT_FOLDER_UPLOAD:
30
+ 'For SMTP accounts EmailEngine uploads the sent message to the Sent Mail folder after delivery. Gmail API and MS Graph accounts file sent messages themselves, so no upload is performed.',
31
+
32
+ SCHEDULED_ON_WORKER:
33
+ 'The request only schedules the work and returns before it finishes. Watch the account state, or the accountInitialized and authenticationError webhooks, for the result.',
34
+
35
+ BACKGROUND_JOB: 'Runs as a background job. Follow it either by polling the status endpoint or by waiting for the completion webhook.',
36
+
37
+ CREDENTIALS_VERIFIED_LATER:
38
+ 'Credentials are not verified while handling this request. The account connects afterwards, and an authentication failure surfaces as an authenticationError state rather than an error here. Use the account verification endpoint to test credentials up front.',
39
+
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
+
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
+
45
+ // --- provider differences ----------------------------------------------------------
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.',
47
+
48
+ UPLOAD_DRAFTS_ONLY_GRAPH: 'For MS Graph accounts only drafts can be uploaded, and the draft flag cannot be changed afterwards.',
49
+
50
+ NO_LABEL_SET_ON_GMAIL:
51
+ 'For Gmail API accounts the entire label set cannot be replaced in one call. Add and remove labels individually instead of using the set operation.',
52
+
53
+ GMAIL_DELETE_IS_TRASH:
54
+ 'For Gmail API accounts the message is always moved to Trash. The force option, which permanently deletes on IMAP accounts, has no effect.',
55
+
56
+ IMAP_ONLY: 'Only available for IMAP accounts. Gmail API and MS Graph accounts have no equivalent.'
57
+ };
@@ -8,7 +8,7 @@ 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, errorResponses } = require('../schemas');
11
+ const { accountIdSchema, apiResponses } = require('../schemas');
12
12
  const { REDIS_PREFIX } = require('../consts');
13
13
 
14
14
  async function init(args) {
@@ -32,8 +32,8 @@ async function init(args) {
32
32
  tags: ['api', 'Blocklists'],
33
33
 
34
34
  plugins: {
35
- 'hapi-swagger': {
36
- responses: errorResponses(400, 401, 403, 429, 500)
35
+ openapi: {
36
+ responses: apiResponses('Returns every blocklist with its entry count.', 400, 401, 403, 429, 500)
37
37
  }
38
38
  },
39
39
 
@@ -102,8 +102,8 @@ async function init(args) {
102
102
  tags: ['api', 'Blocklists'],
103
103
 
104
104
  plugins: {
105
- 'hapi-swagger': {
106
- responses: errorResponses(400, 401, 403, 404, 429, 500)
105
+ openapi: {
106
+ responses: apiResponses('Returns a page of entries on the blocklist.', 400, 401, 403, 404, 429, 500)
107
107
  }
108
108
  },
109
109
 
@@ -220,8 +220,8 @@ async function init(args) {
220
220
  tags: ['api', 'Blocklists'],
221
221
 
222
222
  plugins: {
223
- 'hapi-swagger': {
224
- responses: errorResponses(400, 401, 403, 404, 429, 500)
223
+ openapi: {
224
+ responses: apiResponses('Returns whether the address was added or was already listed.', 400, 401, 403, 404, 429, 500)
225
225
  }
226
226
  },
227
227
 
@@ -298,8 +298,8 @@ async function init(args) {
298
298
  tags: ['api', 'Blocklists'],
299
299
 
300
300
  plugins: {
301
- 'hapi-swagger': {
302
- responses: errorResponses(400, 401, 403, 404, 429, 500)
301
+ openapi: {
302
+ responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
303
303
  }
304
304
  },
305
305
 
@@ -8,7 +8,8 @@
8
8
  // on it would have been invisible.
9
9
 
10
10
  const { openChangeStream } = require('../response-stream');
11
- const { errorResponses } = require('../schemas');
11
+ const { apiResponses } = require('../schemas');
12
+ const BEHAVIOR = require('./behavior-notes');
12
13
 
13
14
  /**
14
15
  * Registers the change-stream route.
@@ -29,13 +30,14 @@ async function init(args) {
29
30
 
30
31
  options: {
31
32
  description: 'Stream state changes',
32
- notes: 'Stream account state changes as an EventSource',
33
+ notes: ['Stream account state changes as an EventSource', BEHAVIOR.SSE_STREAM],
33
34
  tags: ['api', 'Account'],
34
35
 
35
36
  plugins: {
36
- 'hapi-swagger': {
37
+ openapi: {
38
+ 'x-ee-behavior': [BEHAVIOR.SSE_STREAM],
37
39
  produces: ['text/event-stream'],
38
- responses: errorResponses(401, 403, 429, 500)
40
+ responses: apiResponses('Returns an open EventSource stream of account state changes.', 401, 403, 429, 500)
39
41
  }
40
42
  },
41
43
 
@@ -11,7 +11,7 @@ const util = require('util');
11
11
 
12
12
  const LOG_VERBOSE = getBoolean(process.env.EE_OPENAPI_VERBOSE);
13
13
 
14
- const { accountIdSchema, messageSpecialUseSchema, responseAddressSchema, responseFromAddressSchema, errorResponses } = require('../schemas');
14
+ const { accountIdSchema, messageSpecialUseSchema, responseAddressSchema, responseFromAddressSchema, apiResponses } = require('../schemas');
15
15
 
16
16
  function getDateValue(str) {
17
17
  try {
@@ -402,8 +402,8 @@ async function init(args) {
402
402
  tags: ['api', 'Deprecated endpoints (Document Store)'],
403
403
 
404
404
  plugins: {
405
- 'hapi-swagger': {
406
- responses: errorResponses(400, 401, 403, 404, 429, 500)
405
+ openapi: {
406
+ responses: apiResponses('Returns the generated answer and the messages it was drawn from.', 400, 401, 403, 404, 429, 500)
407
407
  }
408
408
  },
409
409
 
@@ -8,9 +8,10 @@ const { Account } = require('../account');
8
8
  const { Gateway } = require('../gateway');
9
9
  const getSecret = require('../get-secret');
10
10
  const { failAction, httpAgent } = require('../tools');
11
- const { accountIdSchema, errorResponses } = require('../schemas');
11
+ const { accountIdSchema, apiResponses } = require('../schemas');
12
12
  const { REDIS_PREFIX } = require('../consts');
13
13
  const packageData = require('../../package.json');
14
+ const BEHAVIOR = require('./behavior-notes');
14
15
 
15
16
  async function init(args) {
16
17
  const { server, call, CORS_CONFIG, SMTP_TEST_HOST } = args;
@@ -134,12 +135,21 @@ ${now}`,
134
135
  },
135
136
  options: {
136
137
  description: 'Create delivery test',
137
- notes: 'Initiate a delivery test',
138
+ notes: ['Initiate a delivery test', BEHAVIOR.BACKGROUND_JOB],
138
139
  tags: ['api', 'Delivery Test'],
139
140
 
140
141
  plugins: {
141
- 'hapi-swagger': {
142
- responses: errorResponses(400, 401, 403, 404, 429, 500)
142
+ openapi: {
143
+ 'x-ee-behavior': [BEHAVIOR.BACKGROUND_JOB],
144
+ responses: apiResponses(
145
+ 'Returns the ID of the started deliverability test. Poll the check endpoint for the result.',
146
+ 400,
147
+ 401,
148
+ 403,
149
+ 404,
150
+ 429,
151
+ 500
152
+ )
143
153
  }
144
154
  },
145
155
 
@@ -288,8 +298,16 @@ ${now}`,
288
298
  tags: ['api', 'Delivery Test'],
289
299
 
290
300
  plugins: {
291
- 'hapi-swagger': {
292
- responses: errorResponses(400, 401, 403, 404, 429, 500)
301
+ openapi: {
302
+ responses: apiResponses(
303
+ 'Returns the test result once it has completed, including SPF, DKIM and DMARC outcomes.',
304
+ 400,
305
+ 401,
306
+ 403,
307
+ 404,
308
+ 429,
309
+ 500
310
+ )
293
311
  }
294
312
  },
295
313