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
package/lib/schemas.js CHANGED
@@ -5,7 +5,7 @@ const config = require('@zone-eu/wild-config');
5
5
  const { getByteSize } = require('./tools');
6
6
  const { COLLAPSE_CLASS } = require('./consts');
7
7
  const { locales } = require('./translations');
8
- const { LEGACY_KEYS, OAUTH_PROVIDERS } = require('./oauth2-apps');
8
+ const { OAUTH_PROVIDERS } = require('./oauth2-apps');
9
9
  const { ACCOUNT_STATES } = require('./account/account-state');
10
10
  const { validateConfig: validateExternalAccountConfig } = require('./oauth/external-account-config');
11
11
 
@@ -43,6 +43,15 @@ const MAX_ATTACHMENT_SIZE = getByteSize(process.env.EENGINE_MAX_SIZE || config.a
43
43
 
44
44
  const accountIdSchema = Joi.string().empty('').trim().max(256).example('user123').description('Unique identifier for the email account');
45
45
 
46
+ // Suppression list identifier, shared by the Blocklists API and the suppression-list admin UI
47
+ // so the two surfaces cannot drift on what a valid list ID is
48
+ const blocklistListIdSchema = Joi.string()
49
+ .hostname()
50
+ .example('test-list')
51
+ .description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
52
+ .label('ListID')
53
+ .required();
54
+
46
55
  // The service-secret-signed blob (base64url `data` + its HMAC `sig`) carried by every hosted
47
56
  // authentication-form page. Defined once so the security-relevant field definitions cannot drift across
48
57
  // the auth:false hosted-form endpoints. Both fields required: every issuer signs unconditionally and every
@@ -62,6 +71,8 @@ const ACCOUNT_DISPLAY_STATES = [...Object.values(ACCOUNT_STATES), 'disconnected'
62
71
 
63
72
  const { ADDRESS_STRATEGIES } = require('./address-strategies');
64
73
  const { ENUM_DESCRIPTIONS } = require('./enum-descriptions');
74
+ const { ACTION, GRANTABLE_GROUPS } = require('./api-routes/permission-map');
75
+ const { FIELD_USAGE } = require('./field-usage');
65
76
 
66
77
  // Account identity as the API describes it. These live here rather than next to the routes that use
67
78
  // them because they are derived from the OAuth2 provider list, and a copy in a test fixture would
@@ -76,9 +87,8 @@ const oauth2ProviderSchema = Joi.string()
76
87
  const accountTypeSchema = Joi.string()
77
88
  .valid(...['imap'].concat(Object.keys(OAUTH_PROVIDERS)).concat(['oauth2', 'delegated', 'sending', 'invalid']))
78
89
  .example('outlook')
79
- .description(
80
- 'Account type: "imap" for IMAP accounts, an OAuth2 provider name for OAuth2 accounts, "oauth2" when the OAuth2 application is missing, "delegated" for delegated accounts, "sending" for send-only accounts, "invalid" when delegation cannot be resolved'
81
- )
90
+ .description('How the account connects to its mailbox')
91
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountType })
82
92
  .required()
83
93
  .label('AccountType');
84
94
 
@@ -160,7 +170,8 @@ const settingsSchema = {
160
170
  .trim()
161
171
  .valid('full', 'fast')
162
172
  .example('full')
163
- .description('IMAP indexing strategy:\n * full - Detect new, changed, and deleted messages (slower but complete)\n * fast - Detect only new messages')
173
+ .description('How much of a mailbox EmailEngine tracks on each sync')
174
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.imapIndexer, usage: FIELD_USAGE.imapIndexer })
164
175
  .label('ImapIndexer'),
165
176
 
166
177
  resolveGmailCategories: Joi.boolean()
@@ -193,9 +204,8 @@ const settingsSchema = {
193
204
  .uri({ scheme: ['http', 'https'], allowRelative: false })
194
205
  .allow('')
195
206
  .example('https://api.openai.com')
196
- .description(
197
- 'Base URL for the OpenAI API. Set for OpenAI-compatible services, including any URL path the service mounts the API under - for Azure OpenAI, use https://<your-resource>.openai.azure.com/openai/v1'
198
- )
207
+ .description('Base URL for the OpenAI API')
208
+ .meta({ usage: FIELD_USAGE.openAiAPIUrl })
199
209
  .label('OpenAiAPIUrl'),
200
210
 
201
211
  documentStoreChatModel: Joi.string()
@@ -262,6 +272,16 @@ const settingsSchema = {
262
272
  .description('External authentication service URL for retrieving mailbox credentials dynamically')
263
273
  .label('AuthServer'),
264
274
 
275
+ // Off by default: it adds a write to the hot path of every authenticated request, and most
276
+ // instances will never read the result
277
+ tokenAuditLog: Joi.boolean()
278
+ .truthy('Y', 'true', '1', 'on')
279
+ .falsy('N', 'false', 0, '')
280
+ .example(false)
281
+ .description(
282
+ 'Record which requests each access token makes, readable at GET /v1/tokens/{token}/log. Disabled by default, and entries only exist from the point it is enabled'
283
+ ),
284
+
265
285
  /* ────────────── Proxy ────────────── */
266
286
 
267
287
  proxyEnabled: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Route outbound connections through a proxy server'),
@@ -302,92 +322,14 @@ const settingsSchema = {
302
322
  .description(
303
323
  'Sanitize HTML content to remove potentially dangerous elements before including in webhooks, and fold quoted thread history into a collapsed block'
304
324
  ),
305
- notifyTextSize: Joi.number().integer().min(0).description('Maximum size (in bytes) of text content to include in webhook payloads'),
325
+ notifyTextSize: Joi.number().integer().min(0).example(1048576).description('Maximum size (in bytes) of text content to include in webhook payloads'),
306
326
  notifyAttachments: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Include attachment data in webhook payloads'),
307
- notifyAttachmentSize: Joi.number().integer().min(0).description('Maximum size (in bytes) per attachment to include in webhook payloads'),
327
+ notifyAttachmentSize: Joi.number().integer().min(0).example(5242880).description('Maximum size (in bytes) per attachment to include in webhook payloads'),
308
328
  notifyCalendarEvents: Joi.boolean()
309
329
  .truthy('Y', 'true', '1', 'on')
310
330
  .falsy('N', 'false', 0, '')
311
331
  .description('Include parsed calendar event data in webhook payloads'),
312
332
 
313
- /* ────────────── OAuth - Gmail (Deprecated) ────────────── */
314
-
315
- gmailEnabled: Joi.boolean()
316
- .truthy('Y', 'true', '1')
317
- .falsy('N', 'false', 0)
318
- .description('Deprecated - Controls visibility of Gmail account type')
319
- .meta({ swaggerHidden: true }),
320
-
321
- gmailClientId: Joi.string().allow('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
322
- gmailClientSecret: Joi.string().empty('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
323
- gmailRedirectUrl: Joi.string()
324
- .allow('')
325
- .uri({ scheme: ['http', 'https'], allowRelative: false })
326
- .description('Deprecated - Use OAuth2 Applications instead')
327
- .meta({ swaggerHidden: true }),
328
- gmailExtraScopes: Joi.array()
329
- .items(Joi.string().empty('').trim().max(256).example('https://mail.google.com/'))
330
- .description('Deprecated - Use OAuth2 Applications instead')
331
- .meta({ swaggerHidden: true }),
332
-
333
- /* ────────────── OAuth - Outlook (Deprecated) ────────────── */
334
-
335
- outlookEnabled: Joi.boolean()
336
- .truthy('Y', 'true', '1')
337
- .falsy('N', 'false', 0)
338
- .description('Deprecated - Controls visibility of Outlook account type')
339
- .meta({ swaggerHidden: true }),
340
- outlookClientId: Joi.string().allow('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
341
- outlookClientSecret: Joi.string().empty('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
342
- outlookRedirectUrl: Joi.string()
343
- .allow('')
344
- .uri({ scheme: ['http', 'https'], allowRelative: false })
345
- .description('Deprecated - Use OAuth2 Applications instead')
346
- .meta({ swaggerHidden: true }),
347
- outlookAuthority: Joi.string()
348
- .empty('')
349
- .allow('consumers', 'organizations', 'common')
350
- .example('consumers')
351
- .description('Deprecated - Use OAuth2 Applications instead')
352
- .meta({ swaggerHidden: true }),
353
- outlookExtraScopes: Joi.array()
354
- .items(Joi.string().empty('').trim().max(256).example('offline_access'))
355
- .description('Deprecated - Use OAuth2 Applications instead')
356
- .meta({ swaggerHidden: true }),
357
-
358
- /* ────────────── OAuth - Mail.ru (Deprecated) ────────────── */
359
-
360
- mailRuEnabled: Joi.boolean()
361
- .truthy('Y', 'true', '1')
362
- .falsy('N', 'false', 0)
363
- .description('Deprecated - Controls visibility of Mail.ru account type')
364
- .meta({ swaggerHidden: true }),
365
- mailRuClientId: Joi.string().allow('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
366
- mailRuClientSecret: Joi.string().empty('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
367
- mailRuRedirectUrl: Joi.string()
368
- .allow('')
369
- .uri({ scheme: ['http', 'https'], allowRelative: false })
370
- .description('Deprecated - Use OAuth2 Applications instead')
371
- .meta({ swaggerHidden: true }),
372
- mailRuExtraScopes: Joi.array()
373
- .items(Joi.string().empty('').trim().max(256).example('offline_access'))
374
- .description('Deprecated - Use OAuth2 Applications instead')
375
- .meta({ swaggerHidden: true }),
376
-
377
- /* ────────────── Generic OAuth2 Service (Deprecated) ────────────── */
378
-
379
- serviceClient: Joi.string().trim().allow('').max(256).description('Deprecated - Use OAuth2 Applications instead').meta({ swaggerHidden: true }),
380
- serviceKey: Joi.string()
381
- .trim()
382
- .empty('')
383
- .max(100 * 1024)
384
- .description('Deprecated - Use OAuth2 Applications instead')
385
- .meta({ swaggerHidden: true }),
386
- serviceExtraScopes: Joi.array()
387
- .items(Joi.string().empty('').trim().max(256).example('https://mail.google.com/'))
388
- .description('Deprecated - Use OAuth2 Applications instead')
389
- .meta({ swaggerHidden: true }),
390
-
391
333
  /* ────────────── Document Store (Deprecated) ────────────── */
392
334
 
393
335
  documentStoreEnabled: Joi.boolean()
@@ -436,7 +378,7 @@ const settingsSchema = {
436
378
  .default(false)
437
379
  .example(false)
438
380
  .description('Enable detailed logging for all email accounts'),
439
- maxLogLines: Joi.number().integer().min(0).max(1000000).default(10000).description('Maximum number of log entries to retain per account')
381
+ maxLogLines: Joi.number().integer().min(0).max(1000000).default(10000).example(10000).description('Maximum number of log entries to retain per account')
440
382
  }).label('LogSettings'),
441
383
 
442
384
  /* ────────────── Error Reporting ────────────── */
@@ -476,6 +418,7 @@ const settingsSchema = {
476
418
  .items(
477
419
  Joi.string()
478
420
  .ip({ version: ['ipv4', 'ipv6'], cidr: 'forbidden' })
421
+ .example('198.51.100.24')
479
422
  .label('LocalAddressEntry')
480
423
  )
481
424
  .single()
@@ -488,17 +431,23 @@ const settingsSchema = {
488
431
  .truthy('Y', 'true', '1', 'on')
489
432
  .falsy('N', 'false', 0, '')
490
433
  .description('Enable the built-in SMTP server for receiving emails'),
491
- smtpServerPort: Joi.number().integer().min(0).max(65535).empty('').description('Port number for the built-in SMTP server'),
434
+ smtpServerPort: Joi.number().integer().min(0).max(65535).empty('').example(2525).description('Port number for the built-in SMTP server'),
492
435
  smtpServerHost: Joi.string()
493
436
  .ip({ version: ['ipv4', 'ipv6'], cidr: 'forbidden' })
494
437
  .empty('')
438
+ .example('0.0.0.0')
495
439
  .description('IP address to bind the SMTP server to (empty = all interfaces)'),
496
440
  smtpServerProxy: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Enable PROXY protocol support for the SMTP server'),
497
441
  smtpServerAuthEnabled: Joi.boolean()
498
442
  .truthy('Y', 'true', '1', 'on')
499
443
  .falsy('N', 'false', 0, '')
500
444
  .description('Require SMTP authentication for incoming connections'),
501
- smtpServerPassword: Joi.string().empty('').allow(null).max(1024).description('Password for SMTP authentication (null = disable authentication)'),
445
+ smtpServerPassword: Joi.string()
446
+ .empty('')
447
+ .allow(null)
448
+ .max(1024)
449
+ .example('verysecret')
450
+ .description('Password for SMTP authentication (null = disable authentication)'),
502
451
  smtpServerTLSEnabled: Joi.boolean()
503
452
  .truthy('Y', 'true', '1', 'on')
504
453
  .falsy('N', 'false', 0, '')
@@ -507,28 +456,41 @@ const settingsSchema = {
507
456
  /* ────────────── IMAP Proxy ────────────── */
508
457
 
509
458
  imapProxyServerEnabled: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Enable the IMAP proxy server'),
510
- imapProxyServerPort: Joi.number().integer().min(0).max(65535).empty('').description('Port number for the IMAP proxy server'),
459
+ imapProxyServerPort: Joi.number().integer().min(0).max(65535).empty('').example(9993).description('Port number for the IMAP proxy server'),
511
460
  imapProxyServerHost: Joi.string()
512
461
  .ip({ version: ['ipv4', 'ipv6'], cidr: 'forbidden' })
513
462
  .empty('')
463
+ .example('0.0.0.0')
514
464
  .description('IP address to bind the IMAP proxy to (empty = all interfaces)'),
515
465
  imapProxyServerProxy: Joi.boolean()
516
466
  .truthy('Y', 'true', '1', 'on')
517
467
  .falsy('N', 'false', 0, '')
518
468
  .description('Enable PROXY protocol support for the IMAP proxy'),
519
- imapProxyServerPassword: Joi.string().empty('').allow(null).max(1024).description('Password for IMAP proxy authentication (null = disable authentication)'),
469
+ imapProxyServerPassword: Joi.string()
470
+ .empty('')
471
+ .allow(null)
472
+ .max(1024)
473
+ .example('verysecret')
474
+ .description('Password for IMAP proxy authentication (null = disable authentication)'),
520
475
  imapProxyServerTLSEnabled: Joi.boolean().truthy('Y', 'true', '1', 'on').falsy('N', 'false', 0, '').description('Enable TLS support for the IMAP proxy'),
521
476
 
522
477
  /* ────────────── Queue & Delivery ────────────── */
523
478
 
524
- queueKeep: Joi.number().integer().empty('').min(0).description('Number of completed and failed queue entries to retain for debugging'),
525
- deliveryAttempts: Joi.number().integer().empty('').min(0).description('Maximum number of delivery attempts before marking a message as permanently failed'),
479
+ queueKeep: Joi.number().integer().empty('').min(0).example(50).description('Number of completed and failed queue entries to retain for debugging'),
480
+
481
+ deliveryAttempts: Joi.number()
482
+ .integer()
483
+ .empty('')
484
+ .min(0)
485
+ .example(10)
486
+ .description('Maximum number of delivery attempts before marking a message as permanently failed'),
526
487
 
527
488
  gmailSubscriptionTtl: Joi.number()
528
489
  .integer()
529
490
  .empty('')
530
491
  .min(0)
531
492
  .max(365)
493
+ .example(31)
532
494
  .description('Gmail Pub/Sub subscription inactivity expiration in days. Empty for Google default (31 days), 0 for no expiration.')
533
495
  .label('GmailSubscriptionTTL'),
534
496
 
@@ -538,11 +500,13 @@ const settingsSchema = {
538
500
  .empty('')
539
501
  .trim()
540
502
  .max(1024 * 1024)
503
+ .example('<div class="brand-bar">Acme Mail</div>')
541
504
  .description('Custom HTML to inject at the top of hosted pages (e.g., for branding)'),
542
505
  templateHtmlHead: Joi.string()
543
506
  .empty('')
544
507
  .trim()
545
508
  .max(1024 * 1024)
509
+ .example('<link rel="stylesheet" href="https://example.com/brand.css">')
546
510
  .description('Custom HTML to inject into the <head> section of hosted pages (e.g., for analytics)'),
547
511
 
548
512
  /* ────────────── Pre-processing ────────────── */
@@ -668,9 +632,13 @@ const imapSchema = {
668
632
  otherwise: Joi.optional()
669
633
  })
670
634
  .description('Authentication credentials for the IMAP server')
635
+ .meta({ usage: FIELD_USAGE.imapAuth })
671
636
  .label('ImapAuthentication'),
672
637
 
673
- useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
638
+ useAuthServer: Joi.boolean()
639
+ .example(false)
640
+ .description('Use external authentication server to retrieve credentials dynamically')
641
+ .meta({ usage: FIELD_USAGE.useAuthServer }),
674
642
 
675
643
  host: Joi.string()
676
644
  .hostname()
@@ -704,9 +672,8 @@ const imapSchema = {
704
672
  // imap object is merged verbatim into the ImapFlow connection config
705
673
  disableIMAP4rev2: Joi.boolean()
706
674
  .example(false)
707
- .description(
708
- 'Do not use IMAP4rev2 even if the server supports it. Set this for servers with a broken IMAP4rev2 implementation. Only applies to accounts using regular password authentication.'
709
- ),
675
+ .description('Do not use IMAP4rev2 even if the server supports it')
676
+ .meta({ usage: FIELD_USAGE.disableIMAP4rev2 }),
710
677
  resyncDelay: Joi.number().integer().example(RESYNC_DELAY).description('Delay in seconds between full mailbox resynchronizations').default(RESYNC_DELAY),
711
678
  disabled: Joi.boolean().example(false).description('Temporarily disable IMAP operations for this account'),
712
679
 
@@ -763,9 +730,13 @@ const smtpSchema = {
763
730
  otherwise: Joi.optional()
764
731
  })
765
732
  .description('Authentication credentials for the SMTP server')
733
+ .meta({ usage: FIELD_USAGE.smtpAuth })
766
734
  .label('SmtpAuthentication'),
767
735
 
768
- useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
736
+ useAuthServer: Joi.boolean()
737
+ .example(false)
738
+ .description('Use external authentication server to retrieve credentials dynamically')
739
+ .meta({ usage: FIELD_USAGE.useAuthServer }),
769
740
 
770
741
  host: Joi.string().hostname().required().example('smtp.gmail.com').description('SMTP server hostname'),
771
742
  port: Joi.number()
@@ -826,7 +797,10 @@ const oauth2Schema = {
826
797
 
827
798
  auth: oauth2AuthSchema,
828
799
 
829
- useAuthServer: Joi.boolean().example(false).description('Use external authentication server for token management instead of EmailEngine'),
800
+ useAuthServer: Joi.boolean()
801
+ .example(false)
802
+ .description('Use external authentication server for token management instead of EmailEngine')
803
+ .meta({ usage: FIELD_USAGE.useAuthServer }),
830
804
 
831
805
  accessToken: Joi.string()
832
806
  .max(4 * 4096)
@@ -850,7 +824,11 @@ const oauth2Schema = {
850
824
  expires: Joi.date().iso().example('2021-03-22T13:13:31.000Z').description('Access token expiration timestamp')
851
825
  };
852
826
 
853
- const partialSchema = Joi.boolean().example(false).description('Update only the provided fields instead of replacing the entire configuration').default(false);
827
+ const partialSchema = Joi.boolean()
828
+ .example(false)
829
+ .description('Update only the provided fields instead of replacing the entire configuration')
830
+ .meta({ usage: FIELD_USAGE.partialUpdate })
831
+ .default(false);
854
832
 
855
833
  const imapUpdateSchema = {
856
834
  partial: partialSchema,
@@ -880,9 +858,13 @@ const imapUpdateSchema = {
880
858
  otherwise: Joi.optional()
881
859
  })
882
860
  .description('Authentication credentials for the IMAP server')
861
+ .meta({ usage: FIELD_USAGE.imapAuth })
883
862
  .label('ImapUpdateAuthentication'),
884
863
 
885
- useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
864
+ useAuthServer: Joi.boolean()
865
+ .example(false)
866
+ .description('Use external authentication server to retrieve credentials dynamically')
867
+ .meta({ usage: FIELD_USAGE.useAuthServer }),
886
868
 
887
869
  host: Joi.string().hostname().example('imap.gmail.com').description('IMAP server hostname'),
888
870
  port: Joi.number().integer().min(1).max(65535).example(993).description('IMAP server port'),
@@ -896,9 +878,8 @@ const imapUpdateSchema = {
896
878
  .label('ImapUpdateTlsOptions'),
897
879
  disableIMAP4rev2: Joi.boolean()
898
880
  .example(false)
899
- .description(
900
- 'Do not use IMAP4rev2 even if the server supports it. Set this for servers with a broken IMAP4rev2 implementation. Only applies to accounts using regular password authentication.'
901
- ),
881
+ .description('Do not use IMAP4rev2 even if the server supports it')
882
+ .meta({ usage: FIELD_USAGE.disableIMAP4rev2 }),
902
883
  resyncDelay: Joi.number().integer().example(RESYNC_DELAY).description('Delay in seconds between full mailbox resynchronizations'),
903
884
 
904
885
  disabled: Joi.boolean().example(false).description('Temporarily disable IMAP operations for this account'),
@@ -937,9 +918,13 @@ const smtpUpdateSchema = {
937
918
  otherwise: Joi.optional()
938
919
  })
939
920
  .description('Authentication credentials for the SMTP server')
921
+ .meta({ usage: FIELD_USAGE.smtpAuth })
940
922
  .label('SmtpUpdateAuthentication'),
941
923
 
942
- useAuthServer: Joi.boolean().example(false).description('Use external authentication server to retrieve credentials dynamically'),
924
+ useAuthServer: Joi.boolean()
925
+ .example(false)
926
+ .description('Use external authentication server to retrieve credentials dynamically')
927
+ .meta({ usage: FIELD_USAGE.useAuthServer }),
943
928
 
944
929
  host: Joi.string().hostname().example('smtp.gmail.com').description('SMTP server hostname'),
945
930
  port: Joi.number().integer().min(1).max(65535).example(587).description('SMTP server port'),
@@ -961,7 +946,10 @@ const oauth2UpdateSchema = {
961
946
 
962
947
  auth: oauth2AuthSchema,
963
948
 
964
- useAuthServer: Joi.boolean().example(false).description('Use external authentication server for token management instead of EmailEngine'),
949
+ useAuthServer: Joi.boolean()
950
+ .example(false)
951
+ .description('Use external authentication server for token management instead of EmailEngine')
952
+ .meta({ usage: FIELD_USAGE.useAuthServer }),
965
953
 
966
954
  accessToken: Joi.string()
967
955
  .max(4 * 4096)
@@ -1104,7 +1092,7 @@ const messageEntrySchema = Joi.object({
1104
1092
  .label('TextEncodedSize')
1105
1093
  }).label('TextInfo'),
1106
1094
 
1107
- preview: Joi.string().description('Short preview of the message content'),
1095
+ preview: Joi.string().example('Hello, here is the report you asked for').description('Short preview of the message content'),
1108
1096
 
1109
1097
  category: messageCategorySchema,
1110
1098
  messageSpecialUse: messageSpecialUseSchema,
@@ -1176,7 +1164,9 @@ const messageDetailsSchema = Joi.object({
1176
1164
 
1177
1165
  isAutoReply: Joi.boolean().example(false).description('Whether this message appears to be an automatic reply (out of office, vacation responder, etc.)'),
1178
1166
 
1179
- preview: Joi.string().description('Short preview of the message content (Gmail API and MS Graph API accounts only)'),
1167
+ preview: Joi.string()
1168
+ .example('Hello, here is the report you asked for')
1169
+ .description('Short preview of the message content (Gmail API and MS Graph API accounts only)'),
1180
1170
  category: messageCategorySchema,
1181
1171
 
1182
1172
  specialUse: Joi.string()
@@ -1245,7 +1235,8 @@ const mailboxBaseFields = {
1245
1235
  specialUseSource: Joi.string()
1246
1236
  .example('extension')
1247
1237
  .valid('user', 'extension', 'name')
1248
- .description('How the special use was determined: "user" (set via API), "extension" (server-provided), or "name" (guessed from folder name)')
1238
+ .description('How the special-use flag was determined')
1239
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.specialUseSource })
1249
1240
  .label('MailboxSpecialUseSource'),
1250
1241
  noInferiors: Joi.boolean().example(false).description('Whether this mailbox can contain child mailboxes').label('MailboxNoInferiors')
1251
1242
  };
@@ -1285,7 +1276,10 @@ const mailboxesSchema = Joi.array()
1285
1276
  status: Joi.object({
1286
1277
  messages: Joi.number().integer().example(120).description('Message count from STATUS command').label('StatusMessages'),
1287
1278
  unseen: Joi.number().integer().example(120).description('Unread message count from STATUS command').label('StatusUnseenMessages'),
1288
- error: Joi.string().description('Error message if the STATUS command failed for this mailbox').label('StatusError')
1279
+ error: Joi.string()
1280
+ .example('Mailbox does not exist')
1281
+ .description('Error message if the STATUS command failed for this mailbox')
1282
+ .label('StatusError')
1289
1283
  })
1290
1284
  .unknown()
1291
1285
  .description('Additional mailbox statistics')
@@ -1310,6 +1304,7 @@ const licenseSchema = Joi.object({
1310
1304
  expires: Joi.date().iso().example('2026-01-01T00:00:00.000Z').description('License expiration time, if the license is time-limited')
1311
1305
  })
1312
1306
  .allow(false)
1307
+ .description('Details of the registered license. False when no license is registered.')
1313
1308
  .label('LicenseDetails'),
1314
1309
  suspended: Joi.boolean().example(false).description('Whether email operations are suspended due to license issues')
1315
1310
  }).label('LicenseInfo');
@@ -1418,9 +1413,15 @@ const documentStoreSchema = Joi.boolean()
1418
1413
  .label('UseDocumentStore')
1419
1414
  .meta({ swaggerHidden: true });
1420
1415
 
1416
+ // Every field carries its own `.example()`. The search object is embedded by five
1417
+ // operations and only one of them - POST /v1/account/{account}/search - wraps it in a
1418
+ // curated payload, so on the other four the API reference had nothing to show for any of
1419
+ // these. Where the curated payload does set a value, the example here is the same value, so
1420
+ // the property row and the payload above it never state two different things.
1421
1421
  const searchSchema = Joi.object({
1422
1422
  seq: Joi.string()
1423
1423
  .max(8 * 1024)
1424
+ .example('1:10')
1424
1425
  .description('Sequence number range (e.g., "1:10" or "1,3,5"). Only supported for IMAP.'),
1425
1426
 
1426
1427
  answered: Joi.boolean()
@@ -1438,12 +1439,12 @@ const searchSchema = Joi.object({
1438
1439
  flagged: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).description('Filter for flagged/starred messages').label('Flagged'),
1439
1440
  seen: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).description('Filter for read messages').label('SeenFlag'),
1440
1441
 
1441
- from: Joi.string().max(256).description('Search in From addresses').label('From'),
1442
- to: Joi.string().max(256).description('Search in To addresses. Not supported for MS Graph API.').label('To'),
1443
- cc: Joi.string().max(256).description('Search in Cc addresses. Not supported for MS Graph API.').label('Cc'),
1444
- bcc: Joi.string().max(256).description('Search in Bcc addresses. Not supported for MS Graph API.').label('Bcc'),
1442
+ from: Joi.string().max(256).example('nyan.cat@example.com').description('Search in From addresses').label('From'),
1443
+ to: Joi.string().max(256).example('support@example.com').description('Search in To addresses. Not supported for MS Graph API.').label('To'),
1444
+ cc: Joi.string().max(256).example('billing@example.com').description('Search in Cc addresses. Not supported for MS Graph API.').label('Cc'),
1445
+ bcc: Joi.string().max(256).example('archive@example.com').description('Search in Bcc addresses. Not supported for MS Graph API.').label('Bcc'),
1445
1446
 
1446
- body: Joi.string().max(256).description('Search in message body content').label('MessageBody'),
1447
+ body: Joi.string().max(256).example('Hello world').description('Search in message body content').label('MessageBody'),
1447
1448
  subject: Joi.string()
1448
1449
  .allow('')
1449
1450
  .max(10 * 256)
@@ -1455,6 +1456,7 @@ const searchSchema = Joi.object({
1455
1456
  .integer()
1456
1457
  .min(0)
1457
1458
  .max(1024 * 1024 * 1024)
1459
+ .example(1048576)
1458
1460
  .description('Find messages larger than specified size in bytes. Not supported for MS Graph API.')
1459
1461
  .label('MessageLarger'),
1460
1462
 
@@ -1462,25 +1464,28 @@ const searchSchema = Joi.object({
1462
1464
  .integer()
1463
1465
  .min(0)
1464
1466
  .max(1024 * 1024 * 1024)
1467
+ .example(102400)
1465
1468
  .description('Find messages smaller than specified size in bytes. Not supported for MS Graph API.')
1466
1469
  .label('MessageSmaller'),
1467
1470
 
1468
1471
  uid: Joi.string()
1469
1472
  .max(8 * 1024)
1473
+ .example('100:200')
1470
1474
  .description('UID range (e.g., "100:200" or "150,200,250"). Only supported for IMAP.')
1471
1475
  .label('UIDRange'),
1472
1476
 
1473
1477
  modseq: Joi.number()
1474
1478
  .integer()
1475
1479
  .min(0)
1480
+ .example(12345)
1476
1481
  .description('Find messages with modification sequence higher than specified value. Only supported for IMAP with CONDSTORE.')
1477
1482
  .label('ModseqLarger'),
1478
1483
 
1479
- before: Joi.date().description('Find messages received before this date').label('EnvelopeBefore'),
1480
- since: Joi.date().description('Find messages received after this date').label('EnvelopeSince'),
1484
+ before: Joi.date().example('2024-08-09').description('Find messages received before this date').label('EnvelopeBefore'),
1485
+ since: Joi.date().example('2022-08-09').description('Find messages received after this date').label('EnvelopeSince'),
1481
1486
 
1482
- sentBefore: Joi.date().description('Find messages sent before this date').label('HeaderBefore'),
1483
- sentSince: Joi.date().description('Find messages sent after this date').label('HeaderSince'),
1487
+ sentBefore: Joi.date().example('2024-08-09').description('Find messages sent before this date').label('HeaderBefore'),
1488
+ sentSince: Joi.date().example('2022-08-09').description('Find messages sent after this date').label('HeaderSince'),
1484
1489
 
1485
1490
  emailId: emailIdSchema,
1486
1491
  threadId: threadIdSchema,
@@ -1509,7 +1514,8 @@ const searchSchema = Joi.object({
1509
1514
  emailIds: Joi.array()
1510
1515
  .items(emailIdSchema)
1511
1516
  .single()
1512
- .description('List of specific email IDs to fetch. When provided, other search criteria are ignored. Useful for bulk operations on known messages.')
1517
+ .description('List of specific email IDs to fetch')
1518
+ .meta({ usage: FIELD_USAGE.searchEmailIds })
1513
1519
  .example(['1278455344230334865'])
1514
1520
  .label('EmailIds')
1515
1521
  })
@@ -1563,6 +1569,18 @@ const messageUpdateSchema = Joi.object({
1563
1569
  }
1564
1570
  });
1565
1571
 
1572
+ // The update variant below is derived from this one, so the two cannot drift apart in the published API
1573
+ // document - only the "how to clear it" sentence differs. The five sentences of caveats that
1574
+ // used to live here are now the usage note, which the API reference renders collapsed.
1575
+ const EXPECTED_EMAIL_DESCRIPTION = 'Pins the account to an email address';
1576
+
1577
+ const expectedEmailSchema = Joi.string()
1578
+ .empty('')
1579
+ .email()
1580
+ .example('user@example.com')
1581
+ .description(EXPECTED_EMAIL_DESCRIPTION)
1582
+ .meta({ usage: FIELD_USAGE.expectedEmail });
1583
+
1566
1584
  const accountSchemas = {
1567
1585
  syncFrom: Joi.date()
1568
1586
  .iso()
@@ -1586,15 +1604,19 @@ const accountSchemas = {
1586
1604
  )
1587
1605
  .label('SubconnectionPaths'),
1588
1606
 
1607
+ expectedEmail: expectedEmailSchema,
1608
+
1609
+ // Same field on the update endpoint, where null clears the constraint.
1610
+ expectedEmailUpdate: expectedEmailSchema.allow(null).description(`${EXPECTED_EMAIL_DESCRIPTION}. Set to \`null\` to remove the constraint`),
1611
+
1589
1612
  imapIndexer: Joi.string()
1590
1613
  .empty('')
1591
1614
  .trim()
1592
1615
  .allow(null)
1593
1616
  .valid('full', 'fast')
1594
1617
  .example('full')
1595
- .description(
1596
- 'Override global IMAP indexing strategy for this account. "full" tracks all changes including deletions, "fast" only detects new messages.'
1597
- )
1618
+ .description('Override the global IMAP indexing strategy for this account')
1619
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.imapIndexer, usage: FIELD_USAGE.imapIndexer })
1598
1620
  .label('AccountImapIndexer')
1599
1621
  };
1600
1622
 
@@ -1774,7 +1796,8 @@ const oauthCreateSchema = {
1774
1796
  otherwise: Joi.optional().valid(false, null)
1775
1797
  })
1776
1798
  .example('externalAccount')
1777
- .description('Authentication method for Gmail service account ("serviceKey" or "externalAccount")'),
1799
+ .description('How token requests for the Gmail service account are signed')
1800
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.gmailAuthMethod }),
1778
1801
 
1779
1802
  externalAccount: Joi.string()
1780
1803
  .trim()
@@ -1866,17 +1889,7 @@ const oauthUpdateSchema = {
1866
1889
  .required()
1867
1890
  .description('OAuth2 provider'),
1868
1891
 
1869
- name: Joi.string()
1870
- .trim()
1871
- .empty('')
1872
- .max(256)
1873
- .example('My Gmail App')
1874
- .description('Application name')
1875
- .when('app', {
1876
- not: Joi.string().valid(...LEGACY_KEYS),
1877
- then: Joi.required(),
1878
- otherwise: Joi.optional().valid(false, null)
1879
- }),
1892
+ name: Joi.string().trim().empty('').max(256).example('My Gmail App').description('Application name').required(),
1880
1893
  description: Joi.string().trim().allow('').max(1024).example('My cool app').description('Application description'),
1881
1894
 
1882
1895
  title: Joi.string().allow('').trim().max(256).example('App title').description('Title for the application button'),
@@ -1972,7 +1985,8 @@ const oauthUpdateSchema = {
1972
1985
  then: Joi.optional().default('serviceKey'),
1973
1986
  otherwise: Joi.forbidden()
1974
1987
  })
1975
- .description('Authentication method for Gmail service account ("serviceKey" or "externalAccount")'),
1988
+ .description('How token requests for the Gmail service account are signed')
1989
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.gmailAuthMethod }),
1976
1990
 
1977
1991
  externalAccount: Joi.string()
1978
1992
  .trim()
@@ -2069,6 +2083,57 @@ const tokenRestrictionsSchema = Joi.object({
2069
2083
  .label('TokenRestrictions')
2070
2084
  .description('Security restrictions for API token usage');
2071
2085
 
2086
+ // Narrowing below what the token's scope and account binding already allow. Both axes are optional
2087
+ // and both only SUBTRACT - there is no value here that grants anything, so a token can be handed
2088
+ // out for one job without widening what the holder can reach.
2089
+ //
2090
+ // `.min(1)` on the object refuses `{}`, ambiguous between "no narrowing" and "grant nothing"; the
2091
+ // same on each array refuses an axis that lists nothing, which would mint a token that authenticates
2092
+ // and then refuses every request. lib/token-permissions.js still treats an empty array as a denial,
2093
+ // because tokens.setRawData() can write one without ever passing this schema.
2094
+ // Refusing it at the schema keeps that ambiguity out of the record entirely; lib/token-permissions.js
2095
+ // treats one that arrives by another path as a denial.
2096
+ //
2097
+ // The groups list omits `admin` on purpose, so the API refuses to ISSUE a token naming it rather
2098
+ // than accepting one and denying every request it makes. The request-time deny in
2099
+ // lib/token-permissions.js stays regardless - it has to, because tokens.setRawData() writes a record
2100
+ // with no schema at all.
2101
+ const tokenPermissionsSchema = Joi.object({
2102
+ actions: Joi.array()
2103
+ .items(
2104
+ Joi.string()
2105
+ .valid(...Object.values(ACTION))
2106
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenAction })
2107
+ .label('TokenAction')
2108
+ )
2109
+ .single()
2110
+ .min(1)
2111
+ .example(['read', 'write'])
2112
+ .description('Which kinds of operation this token may perform. Omit to allow all of them')
2113
+ .label('TokenActions'),
2114
+
2115
+ groups: Joi.array()
2116
+ .items(
2117
+ Joi.string()
2118
+ .valid(...GRANTABLE_GROUPS)
2119
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenGroup })
2120
+ .label('TokenGroup')
2121
+ )
2122
+ .single()
2123
+ .min(1)
2124
+ .example(['message', 'mailbox'])
2125
+ .description('Which parts of the API this token may reach. Omit to allow all of them')
2126
+ .label('TokenGroups')
2127
+ })
2128
+ .min(1)
2129
+ .empty(Joi.valid('', false))
2130
+ .allow(null)
2131
+ .example({ actions: ['read'], groups: ['message', 'mailbox'] })
2132
+ .label('TokenPermissions')
2133
+ .description(
2134
+ 'Restricts a token below its scope. Each axis is an allowlist that only narrows, and both apply together, so an operation must match the actions AND the groups. Endpoints that hand out credentials or change instance configuration can never be reached by a token that sets this field, whatever it lists'
2135
+ );
2136
+
2072
2137
  const ipSchema = Joi.string()
2073
2138
  .empty('')
2074
2139
  .trim()
@@ -2100,9 +2165,8 @@ const accountPathSchema = Joi.array()
2100
2165
  .items(pathSchema)
2101
2166
  .single()
2102
2167
  .allow(null)
2103
- .description(
2104
- 'Mailbox folders to monitor for changes (IMAP only). Use "*" to monitor all folders (default). While you can still access unmonitored folders via API, you won\'t receive webhooks for changes in those folders.'
2105
- );
2168
+ .description('Mailbox folders to monitor for changes (IMAP only). Use "*" to monitor all folders (default)')
2169
+ .meta({ usage: FIELD_USAGE.imapPath });
2106
2170
 
2107
2171
  const defaultAccountTypeSchema = Joi.string()
2108
2172
  .empty('')
@@ -2136,10 +2200,10 @@ const outboxEntrySchema = Joi.object({
2136
2200
  .example('What a wonderful message')
2137
2201
  .description('Email subject line'),
2138
2202
 
2139
- gateway: Joi.string().allow(null).max(256).example(null).description('Gateway ID used for delivery, or null when no gateway is set'),
2140
- proxy: Joi.string().allow(null).example(null).description('Proxy URL used for delivery, or null when no proxy is set'),
2141
- localAddress: Joi.string().allow(null).example(null).description('Local IP address used for delivery, or null when not set'),
2142
- idempotencyKey: Joi.string().allow(null).max(1024).description('Idempotency key provided when the message was submitted'),
2203
+ gateway: Joi.string().allow(null).max(256).example('example').description('Gateway ID used for delivery, or null when no gateway is set'),
2204
+ proxy: Joi.string().allow(null).example('socks5://proxy.example.com:1080').description('Proxy URL used for delivery, or null when no proxy is set'),
2205
+ localAddress: Joi.string().allow(null).example('198.51.100.24').description('Local IP address used for delivery, or null when not set'),
2206
+ idempotencyKey: Joi.string().allow(null).max(1024).example('submit-12345').description('Idempotency key provided when the message was submitted'),
2143
2207
  useStructuredFormat: Joi.boolean().description('Whether delivery errors for this message are reported in a structured format'),
2144
2208
 
2145
2209
  created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('When this message was added to the queue'),
@@ -2174,6 +2238,7 @@ const outboxEntrySchema = Joi.object({
2174
2238
  networkRouting: Joi.object()
2175
2239
  .unknown()
2176
2240
  .allow(null)
2241
+ .example({ localAddress: '198.51.100.24', name: 'relay.example.com' })
2177
2242
  .description('Network routing information for the failed delivery attempt')
2178
2243
  .label('OutboxErrorNetworkRouting')
2179
2244
  })
@@ -2194,7 +2259,8 @@ const messageReferenceSchema = Joi.object({
2194
2259
  .valid('forward', 'reply', 'reply-all')
2195
2260
  .example('reply')
2196
2261
  .default('reply')
2197
- .description('Action type: "reply" (reply to sender), "reply-all" (reply to all recipients), or "forward" (forward to new recipients)')
2262
+ .description('What to do with the referenced message')
2263
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.messageAction })
2198
2264
  .label('MessageAction'),
2199
2265
 
2200
2266
  inline: Joi.boolean()
@@ -2228,9 +2294,7 @@ const messageReferenceSchema = Joi.object({
2228
2294
  .example('<test123@example.com>')
2229
2295
  .description('Verify the Message-ID of the referenced email matches this value before proceeding'),
2230
2296
 
2231
- threadId: threadIdSchema.description(
2232
- 'Gmail thread ID to attach the outgoing message to. Used only by Gmail-API accounts; ignored for IMAP and Microsoft Graph backends, which derive threading from RFC In-Reply-To/References headers. When both "message" and "threadId" are provided, the caller-supplied "threadId" takes precedence over the value derived from the referenced message.'
2233
- ),
2297
+ threadId: threadIdSchema.description('Gmail thread ID to attach the outgoing message to').meta({ usage: FIELD_USAGE.referenceThreadId }),
2234
2298
 
2235
2299
  documentStore: documentStoreSchema.default(false).meta({ swaggerHidden: true })
2236
2300
  })
@@ -2246,6 +2310,7 @@ const idempotencyKeySchema = Joi.string()
2246
2310
  .optional()
2247
2311
  .replace(/^\s*"\s*|\s*"\s*$|/g, '')
2248
2312
  .replace(/\\([\\"])/g, '$1')
2313
+ .example('submit-12345')
2249
2314
  .description('Unique key to prevent duplicate processing of the same request')
2250
2315
  .label('Idempotency-Key');
2251
2316
 
@@ -2254,6 +2319,7 @@ const headerTimeoutSchema = Joi.number()
2254
2319
  .min(0)
2255
2320
  .max(2 * 3600 * 1000)
2256
2321
  .optional()
2322
+ .example(30000)
2257
2323
  .description('Request timeout in milliseconds (overrides EENGINE_TIMEOUT environment variable)')
2258
2324
  .label('X-EE-Timeout');
2259
2325
 
@@ -2270,9 +2336,8 @@ const exportRequestSchema = Joi.object({
2270
2336
  folders: Joi.array()
2271
2337
  .items(Joi.string().max(1024).example('INBOX'))
2272
2338
  .single()
2273
- .description(
2274
- 'Folder paths or special-use flags (e.g., \\Inbox, \\Sent, \\All) to export from. If empty/omitted, Gmail/Outlook API accounts export from All Mail folder; other accounts export all folders except Junk and Trash.'
2275
- )
2339
+ .description('Folder paths or special-use flags (e.g., \\Inbox, \\Sent, \\All) to export from')
2340
+ .meta({ usage: FIELD_USAGE.exportFolders })
2276
2341
  .label('ExportFolders'),
2277
2342
  startDate: Joi.date().iso().required().example('2024-01-01T00:00:00Z').description('Export messages from this date'),
2278
2343
  endDate: Joi.date().iso().required().example('2024-12-31T23:59:59Z').description('Export messages until this date'),
@@ -2280,7 +2345,8 @@ const exportRequestSchema = Joi.object({
2280
2345
  .valid('plain', 'html', '*')
2281
2346
  .default('*')
2282
2347
  .example('*')
2283
- .description('Text content to include: "plain", "html", or "*" (both)')
2348
+ .description('Which message bodies to include in the export')
2349
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.exportTextType })
2284
2350
  .label('ExportTextType'),
2285
2351
  maxBytes: Joi.number()
2286
2352
  .integer()
@@ -2325,7 +2391,7 @@ const exportStatusSchema = Joi.object({
2325
2391
  .description('Current export phase')
2326
2392
  .meta({ enumDescriptions: ENUM_DESCRIPTIONS.exportPhase })
2327
2393
  .label('ExportPhase'),
2328
- folders: Joi.array().items(Joi.string().label('ExportFolderItem')).description('Folders being exported').label('ExportStatusFolders'),
2394
+ folders: Joi.array().items(Joi.string().example('INBOX').label('ExportFolderItem')).description('Folders being exported').label('ExportStatusFolders'),
2329
2395
  startDate: Joi.date().iso().example('2024-01-01T00:00:00Z').description('Export start date filter'),
2330
2396
  endDate: Joi.date().iso().example('2024-12-31T23:59:59Z').description('Export end date filter'),
2331
2397
  isEncrypted: Joi.boolean().example(false).description('Whether the export file is encrypted'),
@@ -2335,7 +2401,7 @@ const exportStatusSchema = Joi.object({
2335
2401
  truncated: Joi.boolean()
2336
2402
  .example(true)
2337
2403
  .description('Whether the export was truncated due to message count or size limits. Only present (as true) for truncated exports'),
2338
- error: Joi.string().allow(null).description('Error message if export failed')
2404
+ error: Joi.string().allow(null).example('Mailbox listing failed').description('Error message if export failed')
2339
2405
  }).label('ExportStatus');
2340
2406
 
2341
2407
  const exportListEntrySchema = Joi.object({
@@ -2543,7 +2609,9 @@ module.exports = {
2543
2609
  oauthCreateSchema,
2544
2610
  oauthUpdateSchema,
2545
2611
  tokenRestrictionsSchema,
2612
+ tokenPermissionsSchema,
2546
2613
  accountIdSchema,
2614
+ blocklistListIdSchema,
2547
2615
  oauth2ProviderSchema,
2548
2616
  accountTypeSchema,
2549
2617
  apiHeadersSchema,