emailengine-app 2.84.2 → 2.86.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 (164) hide show
  1. package/.ncurc.js +29 -9
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +107 -0
  6. package/Dockerfile +20 -1
  7. package/ENVIRONMENT.md +139 -0
  8. package/README.md +2 -2
  9. package/bin/emailengine.js +434 -408
  10. package/config/default.toml +2 -0
  11. package/copy-static-files.sh +41 -14
  12. package/data/google-crawlers.json +1 -1
  13. package/data/public_suffix_list.dat +16563 -0
  14. package/eslint.config.js +81 -99
  15. package/lib/account-assignment.js +19 -0
  16. package/lib/account.js +230 -170
  17. package/lib/api-error-codes.js +49 -0
  18. package/lib/api-reference/format.js +4 -3
  19. package/lib/api-reference/model.js +6 -1
  20. package/lib/api-routes/account-routes.js +255 -38
  21. package/lib/api-routes/blocklist-routes.js +91 -4
  22. package/lib/api-routes/delivery-test-routes.js +27 -4
  23. package/lib/api-routes/export-routes.js +28 -2
  24. package/lib/api-routes/gateway-routes.js +110 -12
  25. package/lib/api-routes/index.js +4 -0
  26. package/lib/api-routes/license-routes.js +2 -2
  27. package/lib/api-routes/mailbox-routes.js +44 -5
  28. package/lib/api-routes/message-routes.js +112 -10
  29. package/lib/api-routes/oauth2-app-routes.js +63 -23
  30. package/lib/api-routes/outbox-routes.js +97 -52
  31. package/lib/api-routes/permission-map.js +67 -7
  32. package/lib/api-routes/scoped-routes.js +74 -0
  33. package/lib/api-routes/settings-routes.js +34 -6
  34. package/lib/api-routes/stats-routes.js +5 -1
  35. package/lib/api-routes/submit-routes.js +337 -309
  36. package/lib/api-routes/template-routes.js +45 -8
  37. package/lib/api-routes/token-routes.js +152 -100
  38. package/lib/api-routes/webhook-delivery-routes.js +262 -0
  39. package/lib/api-routes/webhook-route-routes.js +132 -6
  40. package/lib/bounce-detect.js +397 -205
  41. package/lib/calendar-event.js +81 -1
  42. package/lib/consts.js +38 -45
  43. package/lib/db.js +14 -6
  44. package/lib/delivery-error.js +6 -0
  45. package/lib/deprecations.js +270 -0
  46. package/lib/email-client/base-client.js +137 -184
  47. package/lib/email-client/fallback-poll.js +62 -0
  48. package/lib/email-client/gmail-client.js +60 -22
  49. package/lib/email-client/imap/adaptive-idle-store.js +73 -0
  50. package/lib/email-client/imap/adaptive-idle.js +278 -0
  51. package/lib/email-client/imap/connection-errors.js +14 -1
  52. package/lib/email-client/imap/idle-settings.js +31 -5
  53. package/lib/email-client/imap/listing-diff.js +37 -0
  54. package/lib/email-client/imap/mailbox.js +372 -242
  55. package/lib/email-client/imap/subconnection.js +8 -30
  56. package/lib/email-client/imap/sync-operations.js +220 -127
  57. package/lib/email-client/imap-client.js +228 -164
  58. package/lib/email-client/message-builder.js +14 -79
  59. package/lib/email-client/notification-handler.js +1 -2
  60. package/lib/email-client/outlook-client.js +372 -338
  61. package/lib/email-client/smtp-pool-manager.js +16 -13
  62. package/lib/email-client/sync-state-fields.js +19 -0
  63. package/lib/encrypt.js +157 -41
  64. package/lib/enum-descriptions.js +3 -1
  65. package/lib/env-setting-overrides.js +288 -0
  66. package/lib/export-worker.js +751 -0
  67. package/lib/export.js +64 -15
  68. package/lib/gateway.js +19 -4
  69. package/lib/get-raw-email.js +25 -107
  70. package/lib/hapi-request-logger.js +107 -0
  71. package/lib/health.js +75 -0
  72. package/lib/imapproxy/imap-core/README.md +6 -5
  73. package/lib/lock-run.js +119 -0
  74. package/lib/logger-consts.js +48 -0
  75. package/lib/logger.js +1 -1
  76. package/lib/lua/z-head-scores.lua +28 -0
  77. package/lib/mcp/tools.js +37 -8
  78. package/lib/network-errors.js +1 -1
  79. package/lib/node-version.js +24 -0
  80. package/lib/notify-attachments.js +36 -0
  81. package/lib/oauth/outlook-mailbox.js +35 -0
  82. package/lib/oauth/state.js +24 -0
  83. package/lib/oauth2-apps.js +631 -656
  84. package/lib/outbox.js +184 -54
  85. package/lib/parse-message.js +3 -3
  86. package/lib/pbkdf2-phc.js +1 -1
  87. package/lib/privileged-settings.js +2 -2
  88. package/lib/queue-browser/definitions.js +11 -0
  89. package/lib/queue-browser/index.js +68 -19
  90. package/lib/queue-job-actions.js +18 -1
  91. package/lib/queue-retention.js +48 -12
  92. package/lib/queue-stats.js +11 -2
  93. package/lib/read-env-value.js +3 -0
  94. package/lib/redis-memory-warnings.js +99 -0
  95. package/lib/redis-reconnect.js +29 -0
  96. package/lib/request-timing.js +23 -0
  97. package/lib/respawn-backoff.js +35 -0
  98. package/lib/rewrite-text-nodes.js +19 -59
  99. package/lib/schemas.js +164 -40
  100. package/lib/settings.js +6 -2
  101. package/lib/smtp-auth.js +19 -1
  102. package/lib/sso.js +1 -1
  103. package/lib/swagger-options.js +1 -1
  104. package/lib/thread-diagnostics.js +63 -0
  105. package/lib/timezones.js +109 -0
  106. package/lib/tls/provision.js +6 -3
  107. package/lib/token-audit-log.js +19 -20
  108. package/lib/token-permission-view.js +7 -6
  109. package/lib/tools.js +48 -51
  110. package/lib/totp.js +2 -5
  111. package/lib/translations.js +1 -2
  112. package/lib/ui-routes/account-routes.js +475 -454
  113. package/lib/ui-routes/account-setup.js +99 -0
  114. package/lib/ui-routes/admin-config-routes.js +152 -100
  115. package/lib/ui-routes/admin-entities-routes.js +93 -21
  116. package/lib/ui-routes/auth-routes.js +90 -38
  117. package/lib/ui-routes/imap-idle-field.js +1 -1
  118. package/lib/ui-routes/internals-routes.js +5 -0
  119. package/lib/ui-routes/oauth-config-routes.js +124 -82
  120. package/lib/ui-routes/outlook-subscription-view.js +1 -1
  121. package/lib/ui-routes/overridable-fields.js +84 -0
  122. package/lib/ui-routes/queue-routes.js +8 -5
  123. package/lib/ui-routes/route-helpers.js +19 -3
  124. package/lib/ui-routes/settings-page.js +6 -0
  125. package/lib/ui-routes/tls-config-routes.js +58 -15
  126. package/lib/utils/back-off.js +82 -0
  127. package/lib/utils/decode-headers.js +3 -12
  128. package/lib/utils/filter-empty.js +20 -0
  129. package/lib/utils/int-setting.js +48 -0
  130. package/lib/utils/murmurhash3.js +66 -0
  131. package/lib/utils/public-suffix.js +122 -0
  132. package/lib/utils/random-id.js +26 -0
  133. package/lib/utils/tracking-settings.js +35 -0
  134. package/lib/utils/version.js +74 -0
  135. package/lib/web-safe-html.js +18 -105
  136. package/lib/webhook-delivery.js +461 -0
  137. package/lib/webhook-failures.js +132 -0
  138. package/lib/webhook-request.js +29 -1
  139. package/lib/webhook-routing.js +56 -0
  140. package/lib/webhook-test.js +88 -0
  141. package/lib/webhooks.js +93 -45
  142. package/lib/worker-rpc-error.js +2 -1
  143. package/package.json +37 -38
  144. package/sbom.json +7902 -1
  145. package/server.js +784 -518
  146. package/static/js/ace/ace.js +1 -1
  147. package/static/licenses.html +225 -1060
  148. package/translations/messages.pot +62 -63
  149. package/views/config/ai.hbs +1 -1
  150. package/views/config/security.hbs +24 -2
  151. package/views/config/service.hbs +47 -0
  152. package/views/config/webhooks.hbs +36 -0
  153. package/views/internals/index.hbs +8 -0
  154. package/views/partials/queue_retention_note.hbs +12 -8
  155. package/views/partials/ui/env-managed-alert.hbs +16 -7
  156. package/views/partials/webhook_form.hbs +1 -1
  157. package/views/suppression-lists/index.hbs +1 -1
  158. package/workers/api.js +840 -611
  159. package/workers/export.js +17 -632
  160. package/workers/imap.js +13 -0
  161. package/workers/smtp.js +9 -11
  162. package/workers/submit.js +1 -1
  163. package/workers/webhooks.js +18 -448
  164. package/lib/email-client/outlook-fallback-poll.js +0 -30
@@ -8,15 +8,15 @@ const Joi = require('joi');
8
8
  const { failAction } = require('../tools');
9
9
  const { handleError, throwNotFound } = require('./route-helpers');
10
10
 
11
- const { templateSchemas, accountIdSchema, apiResponses, apiBoolean } = require('../schemas');
11
+ const { templateSchemas, accountIdSchema, apiResponses, apiBoolean, listQuerySchema } = require('../schemas');
12
12
  const { IMPACT } = require('./operation-impact');
13
13
  const { MCP_MAX_PAGE_SIZE } = require('../consts');
14
14
 
15
15
  // Template owner field shared by all template response schemas
16
16
  const templateAccountIdSchema = accountIdSchema.required().allow(null).description('Account ID. Null for public templates');
17
17
 
18
- async function init(args) {
19
- const { server, call, CORS_CONFIG } = args;
18
+ function registerCreateTemplate(server, args) {
19
+ const { call, CORS_CONFIG } = args;
20
20
 
21
21
  server.route({
22
22
  method: 'POST',
@@ -126,6 +126,10 @@ async function init(args) {
126
126
  }
127
127
  }
128
128
  });
129
+ }
130
+
131
+ function registerUpdateTemplate(server, args) {
132
+ const { CORS_CONFIG } = args;
129
133
 
130
134
  server.route({
131
135
  method: 'PUT',
@@ -148,7 +152,7 @@ async function init(args) {
148
152
 
149
153
  options: {
150
154
  description: 'Update a template',
151
- notes: 'Update a stored template.',
155
+ notes: 'Changes a stored template. Fields left out of the request keep their stored values.',
152
156
  tags: ['api', 'Templates'],
153
157
 
154
158
  plugins: {
@@ -214,6 +218,10 @@ async function init(args) {
214
218
  }
215
219
  }
216
220
  });
221
+ }
222
+
223
+ function registerListTemplates(server, args) {
224
+ const { call, CORS_CONFIG } = args;
217
225
 
218
226
  server.route({
219
227
  method: 'GET',
@@ -227,7 +235,7 @@ async function init(args) {
227
235
  await accountObject.loadAccountData();
228
236
  }
229
237
 
230
- return await templates.list(request.query.account, request.query.page, request.query.pageSize);
238
+ return await templates.list(request.query.account, request.query.page, request.query.pageSize, request.query.query);
231
239
  } catch (err) {
232
240
  handleError(request, err);
233
241
  }
@@ -235,7 +243,7 @@ async function init(args) {
235
243
 
236
244
  options: {
237
245
  description: 'List account templates',
238
- notes: 'Lists stored templates for the account',
246
+ notes: 'Lists the stored templates, one page at a time: the shared ones, or with `account` set the templates of that account.',
239
247
  tags: ['api', 'Templates'],
240
248
 
241
249
  plugins: {
@@ -275,7 +283,8 @@ async function init(args) {
275
283
  .example(0)
276
284
  .description('Page number (zero indexed, so use 0 for first page)')
277
285
  .label('PageNumber'),
278
- pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize')
286
+ pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize'),
287
+ query: listQuerySchema('ID, name or description', 'TemplatesListQuery')
279
288
  }).label('AccountTemplatesRequest')
280
289
  },
281
290
 
@@ -312,6 +321,10 @@ async function init(args) {
312
321
  }
313
322
  }
314
323
  });
324
+ }
325
+
326
+ function registerGetTemplate(server, args) {
327
+ const { CORS_CONFIG } = args;
315
328
 
316
329
  server.route({
317
330
  method: 'GET',
@@ -335,6 +348,11 @@ async function init(args) {
335
348
  tags: ['api', 'Templates'],
336
349
 
337
350
  plugins: {
351
+ mcp: {
352
+ name: 'get_template',
353
+ title: 'Get template',
354
+ description: 'Get one stored email template with its subject and content (html, text, previewText), by the template id from list_templates.'
355
+ },
338
356
  openapi: {
339
357
  responses: apiResponses('Returns the template, including its content.', 400, 401, 403, 404, 429, 500)
340
358
  }
@@ -387,6 +405,10 @@ async function init(args) {
387
405
  }
388
406
  }
389
407
  });
408
+ }
409
+
410
+ function registerDeleteTemplate(server, args) {
411
+ const { CORS_CONFIG } = args;
390
412
 
391
413
  server.route({
392
414
  method: 'DELETE',
@@ -401,7 +423,7 @@ async function init(args) {
401
423
  },
402
424
  options: {
403
425
  description: 'Remove a template',
404
- notes: 'Delete a stored template',
426
+ notes: 'Deletes a stored template. Messages already queued from it are not affected.',
405
427
  tags: ['api', 'Templates'],
406
428
 
407
429
  plugins: {
@@ -445,6 +467,10 @@ async function init(args) {
445
467
  }
446
468
  }
447
469
  });
470
+ }
471
+
472
+ function registerFlushAccountTemplates(server, args) {
473
+ const { call, CORS_CONFIG } = args;
448
474
 
449
475
  server.route({
450
476
  method: 'DELETE',
@@ -520,4 +546,15 @@ async function init(args) {
520
546
  });
521
547
  }
522
548
 
549
+ async function init(args) {
550
+ const { server } = args;
551
+
552
+ registerCreateTemplate(server, args);
553
+ registerUpdateTemplate(server, args);
554
+ registerListTemplates(server, args);
555
+ registerGetTemplate(server, args);
556
+ registerDeleteTemplate(server, args);
557
+ registerFlushAccountTemplates(server, args);
558
+ }
559
+
523
560
  module.exports = init;
@@ -22,6 +22,7 @@ const {
22
22
  const { IMPACT } = require('./operation-impact');
23
23
  const { mintWidenings } = require('./mint-bounds');
24
24
  const { MCP_MAX_PAGE_SIZE } = require('../consts');
25
+ const { REMOVAL_DATE, TOKEN_ROUTES_DEPRECATED_AT } = require('../deprecations');
25
26
 
26
27
  const tokenAccessSchema = Joi.object({
27
28
  time: Joi.date().iso().allow(null).example('2021-02-17T13:43:18.860Z').description('Last time this token was used. Null if the token has never been used'),
@@ -120,88 +121,83 @@ const tokenListItemFields = {
120
121
  id: tokenIdSchema
121
122
  };
122
123
 
123
- async function init(args) {
124
- const { server, call, CORS_CONFIG } = args;
124
+ // The provision and delete routes are registered twice - the current path and the
125
+ // deprecated pre-2.79 alias at the bottom of this file - so the handlers and the request/
126
+ // response schemas are shared. Sharing the schema INSTANCES matters beyond reuse: the
127
+ // OpenAPI generator names components after joi labels, and two different schema objects
128
+ // carrying the same label would come out numbered (CreateToken1).
129
+ const createTokenPayloadSchema = Joi.object({
130
+ account: accountIdSchema.description('Bind the token to one account. Omit for an instance-wide token, which then has to set `permissions`'),
131
+
132
+ description: Joi.string().empty('').trim().max(1024).required().example('Token description').description('Token description'),
133
+
134
+ scopes: Joi.array()
135
+ .items(
136
+ Joi.string().valid('api', 'smtp', 'imap-proxy', 'mcp', 'mcp-manage').meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenScope }).label('TokenScope')
137
+ )
138
+ .single()
139
+ .default(['api'])
140
+ .required()
141
+ .description(
142
+ 'Token permission scopes: "api" for REST API access, "smtp" for SMTP submission, "imap-proxy" for IMAP proxy authentication, "mcp-manage" for the instance management tools of the MCP endpoint, "mcp" for its mail tools'
143
+ )
144
+ .label('Scopes'),
145
+
146
+ metadata: tokenMetadataSchema,
125
147
 
126
- // The provision and delete routes are registered twice - the current path and the
127
- // deprecated pre-2.79 alias at the bottom of this file - so the handlers and the request/
128
- // response schemas are shared. Sharing the schema INSTANCES matters beyond reuse: the
129
- // OpenAPI generator names components after joi labels, and two different schema objects
130
- // carrying the same label would come out numbered (CreateToken1).
131
- const createTokenPayloadSchema = Joi.object({
132
- account: accountIdSchema.description('Bind the token to one account. Omit for an instance-wide token, which then has to set `permissions`'),
133
-
134
- description: Joi.string().empty('').trim().max(1024).required().example('Token description').description('Token description'),
135
-
136
- scopes: Joi.array()
137
- .items(
138
- Joi.string()
139
- .valid('api', 'smtp', 'imap-proxy', 'mcp', 'mcp-manage')
140
- .meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenScope })
141
- .label('TokenScope')
142
- )
143
- .single()
144
- .default(['api'])
145
- .required()
146
- .description(
147
- 'Token permission scopes: "api" for REST API access, "smtp" for SMTP submission, "imap-proxy" for IMAP proxy authentication, "mcp-manage" for the instance management tools of the MCP endpoint, "mcp" for its mail tools'
148
- )
149
- .label('Scopes'),
150
-
151
- metadata: tokenMetadataSchema,
152
-
153
- restrictions: tokenRestrictionsSchema,
154
-
155
- // An unbound token reaches instance-wide endpoints and every account, so it may
156
- // only be issued narrowed. A bound one is already limited to its account, so the
157
- // narrowing stays optional there.
158
- // `.invalid(null)` matters as much as `.required()`: tokenPermissionsSchema allows
159
- // null so the admin form can post "not narrowed", and joi's required() is a
160
- // presence check that an explicit null satisfies. Without this, sending
161
- // `permissions: null` with no account - which any template rendering an unset
162
- // variable produces - passed the rule and minted a full instance-wide token.
163
- permissions: tokenPermissionsSchema.when('account', {
164
- is: Joi.exist(),
165
- otherwise: tokenPermissionsSchema.required().invalid(null).messages({
166
- 'any.required': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one',
167
- 'any.invalid': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one'
168
- })
169
- }),
170
-
171
- // provision() has always accepted an expiry; the route did not, so until now the
172
- // API could not mint a short-lived token at all. A narrow token that never
173
- // expires is only half of what a per-task credential is for.
174
- expires: Joi.date()
175
- .iso()
176
- .greater('now')
177
- .example('2021-02-17T14:43:18.860Z')
178
- .description('Optional time when this token stops working. Omit for a token that never expires')
179
- // Distinct from the TokenExpires the listing uses: a joi label is a public
180
- // type name in the generated document, so reusing it would collide and the
181
- // generator would number one of them
182
- .label('CreateTokenExpires'),
183
-
184
- ip: ipSchema.description('IP address of the requester').label('TokenIP')
185
- }).label('CreateToken');
186
-
187
- const createTokenResponseSchema = Joi.object({
188
- token: Joi.string()
189
- .length(64)
190
- .hex()
191
- .required()
192
- .example('9a6d24f8f43e01b1f2c4f11a5c5b8e51fe0a4e0eda06e1be5b8d6cc2c66b95dc')
193
- .description('The access token. This is the only time it is returned - store it now'),
194
- id: tokenIdSchema.required().description('Identifier for this token, as reported by the token listings')
195
- }).label('CreateTokenResponse');
196
-
197
- const deleteTokenParamsSchema = Joi.object({
198
- token: tokenReferenceSchema
199
- }).label('DeleteTokenRequest');
200
-
201
- const deleteTokenResponseSchema = Joi.object({
202
- deleted: apiBoolean().default(true).description('Was the token deleted')
203
- }).label('DeleteTokenRequestResponse');
148
+ restrictions: tokenRestrictionsSchema,
204
149
 
150
+ // An unbound token reaches instance-wide endpoints and every account, so it may
151
+ // only be issued narrowed. A bound one is already limited to its account, so the
152
+ // narrowing stays optional there.
153
+ // `.invalid(null)` matters as much as `.required()`: tokenPermissionsSchema allows
154
+ // null so the admin form can post "not narrowed", and joi's required() is a
155
+ // presence check that an explicit null satisfies. Without this, sending
156
+ // `permissions: null` with no account - which any template rendering an unset
157
+ // variable produces - passed the rule and minted a full instance-wide token.
158
+ permissions: tokenPermissionsSchema.when('account', {
159
+ is: Joi.exist(),
160
+ otherwise: tokenPermissionsSchema.required().invalid(null).messages({
161
+ 'any.required': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one',
162
+ 'any.invalid': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one'
163
+ })
164
+ }),
165
+
166
+ // provision() has always accepted an expiry; the route did not, so until now the
167
+ // API could not mint a short-lived token at all. A narrow token that never
168
+ // expires is only half of what a per-task credential is for.
169
+ expires: Joi.date()
170
+ .iso()
171
+ .greater('now')
172
+ .example('2021-02-17T14:43:18.860Z')
173
+ .description('Optional time when this token stops working. Omit for a token that never expires')
174
+ // Distinct from the TokenExpires the listing uses: a joi label is a public
175
+ // type name in the generated document, so reusing it would collide and the
176
+ // generator would number one of them
177
+ .label('CreateTokenExpires'),
178
+
179
+ ip: ipSchema.description('IP address of the requester').label('TokenIP')
180
+ }).label('CreateToken');
181
+
182
+ const createTokenResponseSchema = Joi.object({
183
+ token: Joi.string()
184
+ .length(64)
185
+ .hex()
186
+ .required()
187
+ .example('9a6d24f8f43e01b1f2c4f11a5c5b8e51fe0a4e0eda06e1be5b8d6cc2c66b95dc')
188
+ .description('The access token. This is the only time it is returned - store it now'),
189
+ id: tokenIdSchema.required().description('Identifier for this token, as reported by the token listings')
190
+ }).label('CreateTokenResponse');
191
+
192
+ const deleteTokenParamsSchema = Joi.object({
193
+ token: tokenReferenceSchema
194
+ }).label('DeleteTokenRequest');
195
+
196
+ const deleteTokenResponseSchema = Joi.object({
197
+ deleted: apiBoolean().default(true).description('Was the token deleted')
198
+ }).label('DeleteTokenRequestResponse');
199
+
200
+ function createProvisionTokenHandler(call) {
205
201
  const provisionTokenHandler = async request => {
206
202
  let accountObject = new Account({
207
203
  redis,
@@ -261,13 +257,19 @@ async function init(args) {
261
257
  }
262
258
  };
263
259
 
264
- const deleteTokenHandler = async request => {
265
- try {
266
- return { deleted: await tokens.delete(request.params.token, { remoteAddress: request.app.ip }) };
267
- } catch (err) {
268
- handleError(request, err);
269
- }
270
- };
260
+ return provisionTokenHandler;
261
+ }
262
+
263
+ const deleteTokenHandler = async request => {
264
+ try {
265
+ return { deleted: await tokens.delete(request.params.token, { remoteAddress: request.app.ip }) };
266
+ } catch (err) {
267
+ handleError(request, err);
268
+ }
269
+ };
270
+
271
+ function registerCreateToken(server, ctx) {
272
+ const { CORS_CONFIG, provisionTokenHandler } = ctx;
271
273
 
272
274
  server.route({
273
275
  method: 'POST',
@@ -312,6 +314,10 @@ async function init(args) {
312
314
  }
313
315
  }
314
316
  });
317
+ }
318
+
319
+ function registerDeleteToken(server, ctx) {
320
+ const { CORS_CONFIG } = ctx;
315
321
 
316
322
  server.route({
317
323
  method: 'DELETE',
@@ -320,7 +326,7 @@ async function init(args) {
320
326
  handler: deleteTokenHandler,
321
327
  options: {
322
328
  description: 'Remove a token',
323
- notes: 'Delete an access token',
329
+ notes: 'Revokes an access token. Requests made with it are refused from then on.',
324
330
  tags: ['api', 'Access Tokens'],
325
331
 
326
332
  plugins: {
@@ -359,6 +365,10 @@ async function init(args) {
359
365
  }
360
366
  }
361
367
  });
368
+ }
369
+
370
+ function registerListTokens(server, ctx) {
371
+ const { CORS_CONFIG } = ctx;
362
372
 
363
373
  server.route({
364
374
  method: 'GET',
@@ -456,6 +466,10 @@ async function init(args) {
456
466
  }
457
467
  }
458
468
  });
469
+ }
470
+
471
+ function registerGetToken(server, ctx) {
472
+ const { CORS_CONFIG } = ctx;
459
473
 
460
474
  server.route({
461
475
  method: 'GET',
@@ -542,6 +556,10 @@ async function init(args) {
542
556
  }
543
557
  }
544
558
  });
559
+ }
560
+
561
+ function registerGetTokenLog(server, ctx) {
562
+ const { CORS_CONFIG } = ctx;
545
563
 
546
564
  server.route({
547
565
  method: 'GET',
@@ -667,16 +685,10 @@ async function init(args) {
667
685
  }
668
686
  }
669
687
  });
688
+ }
670
689
 
671
- // --------------------------------------------------------------------------------------------
672
- // Deprecated aliases. v2.79.0 renamed the token endpoints (POST /v1/token -> POST /v1/tokens,
673
- // DELETE /v1/token/{token} -> DELETE /v1/tokens/{token}) and folded the per-account listing
674
- // into GET /v1/tokens?account=..., which handed every pre-2.79 integration that provisions,
675
- // revokes or lists tokens a 404 from a minor upgrade - token-rotation pipelines failing
676
- // first. The old paths stay registered against the same handlers and schema instances, but are
677
- // left OUT of the published document and the API reference (plugins.openapi.deprecated - see
678
- // lib/openapi/build-document.js): they exist for old integrations to keep working, and
679
- // documenting them would steer new ones onto retired paths.
690
+ function registerDeprecatedCreateToken(server, ctx) {
691
+ const { CORS_CONFIG, provisionTokenHandler } = ctx;
680
692
 
681
693
  server.route({
682
694
  method: 'POST',
@@ -686,10 +698,11 @@ async function init(args) {
686
698
 
687
699
  options: {
688
700
  description: 'Provision an access token (deprecated)',
689
- notes: 'Deprecated alias of `POST /v1/tokens`, which behaves identically - use that path instead.',
701
+ notes: `Deprecated alias of \`POST /v1/tokens\`, which behaves identically - use that path instead. Will be removed after ${REMOVAL_DATE}.`,
690
702
  tags: ['api', 'Access Tokens'],
691
703
 
692
704
  plugins: {
705
+ deprecation: { since: TOKEN_ROUTES_DEPRECATED_AT, successor: 'POST /v1/tokens', link: '/v1/tokens' },
693
706
  openapi: {
694
707
  deprecated: true,
695
708
  responses: apiResponses('Returns the new token value. This is the only time it is shown - store it now.', 400, 401, 403, 404, 429, 500)
@@ -719,6 +732,10 @@ async function init(args) {
719
732
  }
720
733
  }
721
734
  });
735
+ }
736
+
737
+ function registerDeprecatedDeleteToken(server, ctx) {
738
+ const { CORS_CONFIG } = ctx;
722
739
 
723
740
  server.route({
724
741
  method: 'DELETE',
@@ -727,10 +744,12 @@ async function init(args) {
727
744
  handler: deleteTokenHandler,
728
745
  options: {
729
746
  description: 'Remove a token (deprecated)',
730
- notes: 'Deprecated alias of `DELETE /v1/tokens/{token}`, which behaves identically - use that path instead.',
747
+ notes: `Deprecated alias of \`DELETE /v1/tokens/{token}\`, which behaves identically - use that path instead. Will be removed after ${REMOVAL_DATE}.`,
731
748
  tags: ['api', 'Access Tokens'],
732
749
 
733
750
  plugins: {
751
+ // no Link: the successor path would have to carry the token
752
+ deprecation: { since: TOKEN_ROUTES_DEPRECATED_AT, successor: 'DELETE /v1/tokens/{token}' },
734
753
  openapi: {
735
754
  deprecated: true,
736
755
  'x-ee-impact': IMPACT.DESTRUCTIVE,
@@ -761,6 +780,10 @@ async function init(args) {
761
780
  }
762
781
  }
763
782
  });
783
+ }
784
+
785
+ function registerDeprecatedListAccountTokens(server, ctx) {
786
+ const { CORS_CONFIG } = ctx;
764
787
 
765
788
  server.route({
766
789
  method: 'GET',
@@ -777,10 +800,11 @@ async function init(args) {
777
800
 
778
801
  options: {
779
802
  description: 'List account tokens (deprecated)',
780
- notes: 'Deprecated alias for listing the access tokens of one account - use `GET /v1/tokens` with the `account` argument instead, which also pages the listing.',
803
+ notes: `Deprecated alias for listing the access tokens of one account - use \`GET /v1/tokens\` with the \`account\` argument instead, which also pages the listing. Will be removed after ${REMOVAL_DATE}.`,
781
804
  tags: ['api', 'Access Tokens'],
782
805
 
783
806
  plugins: {
807
+ deprecation: { since: TOKEN_ROUTES_DEPRECATED_AT, successor: 'GET /v1/tokens?account={account}', link: '/v1/tokens' },
784
808
  openapi: {
785
809
  deprecated: true,
786
810
  responses: apiResponses('Returns the access tokens scoped to the account.', 400, 401, 403, 429, 500)
@@ -822,4 +846,32 @@ async function init(args) {
822
846
  });
823
847
  }
824
848
 
849
+ async function init(args) {
850
+ const { server, call, CORS_CONFIG } = args;
851
+
852
+ const provisionTokenHandler = createProvisionTokenHandler(call);
853
+ const ctx = { CORS_CONFIG, provisionTokenHandler };
854
+
855
+ registerCreateToken(server, ctx);
856
+ registerDeleteToken(server, ctx);
857
+ registerListTokens(server, ctx);
858
+ registerGetToken(server, ctx);
859
+ registerGetTokenLog(server, ctx);
860
+
861
+ // --------------------------------------------------------------------------------------------
862
+ // Deprecated aliases. v2.79.0 renamed the token endpoints (POST /v1/token -> POST /v1/tokens,
863
+ // DELETE /v1/token/{token} -> DELETE /v1/tokens/{token}) and folded the per-account listing
864
+ // into GET /v1/tokens?account=..., which handed every pre-2.79 integration that provisions,
865
+ // revokes or lists tokens a 404 from a minor upgrade - token-rotation pipelines failing
866
+ // first. The old paths stay registered against the same handlers and schema instances, but are
867
+ // left OUT of the published document and the API reference (plugins.openapi.deprecated - see
868
+ // lib/openapi/build-document.js): they exist for old integrations to keep working, and
869
+ // documenting them would steer new ones onto retired paths. They are removed after
870
+ // REMOVAL_DATE (lib/deprecations.js); until then every response says so in its headers.
871
+
872
+ registerDeprecatedCreateToken(server, ctx);
873
+ registerDeprecatedDeleteToken(server, ctx);
874
+ registerDeprecatedListAccountTokens(server, ctx);
875
+ }
876
+
825
877
  module.exports = init;