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.
- package/.ncurc.js +29 -9
- package/.prettierignore +5 -1
- package/.prettierrc.js +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +107 -0
- package/Dockerfile +20 -1
- package/ENVIRONMENT.md +139 -0
- package/README.md +2 -2
- package/bin/emailengine.js +434 -408
- package/config/default.toml +2 -0
- package/copy-static-files.sh +41 -14
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +16563 -0
- package/eslint.config.js +81 -99
- package/lib/account-assignment.js +19 -0
- package/lib/account.js +230 -170
- package/lib/api-error-codes.js +49 -0
- package/lib/api-reference/format.js +4 -3
- package/lib/api-reference/model.js +6 -1
- package/lib/api-routes/account-routes.js +255 -38
- package/lib/api-routes/blocklist-routes.js +91 -4
- package/lib/api-routes/delivery-test-routes.js +27 -4
- package/lib/api-routes/export-routes.js +28 -2
- package/lib/api-routes/gateway-routes.js +110 -12
- package/lib/api-routes/index.js +4 -0
- package/lib/api-routes/license-routes.js +2 -2
- package/lib/api-routes/mailbox-routes.js +44 -5
- package/lib/api-routes/message-routes.js +112 -10
- package/lib/api-routes/oauth2-app-routes.js +63 -23
- package/lib/api-routes/outbox-routes.js +97 -52
- package/lib/api-routes/permission-map.js +67 -7
- package/lib/api-routes/scoped-routes.js +74 -0
- package/lib/api-routes/settings-routes.js +34 -6
- package/lib/api-routes/stats-routes.js +5 -1
- package/lib/api-routes/submit-routes.js +337 -309
- package/lib/api-routes/template-routes.js +45 -8
- package/lib/api-routes/token-routes.js +152 -100
- package/lib/api-routes/webhook-delivery-routes.js +262 -0
- package/lib/api-routes/webhook-route-routes.js +132 -6
- package/lib/bounce-detect.js +397 -205
- package/lib/calendar-event.js +81 -1
- package/lib/consts.js +38 -45
- package/lib/db.js +14 -6
- package/lib/delivery-error.js +6 -0
- package/lib/deprecations.js +270 -0
- package/lib/email-client/base-client.js +137 -184
- package/lib/email-client/fallback-poll.js +62 -0
- package/lib/email-client/gmail-client.js +60 -22
- package/lib/email-client/imap/adaptive-idle-store.js +73 -0
- package/lib/email-client/imap/adaptive-idle.js +278 -0
- package/lib/email-client/imap/connection-errors.js +14 -1
- package/lib/email-client/imap/idle-settings.js +31 -5
- package/lib/email-client/imap/listing-diff.js +37 -0
- package/lib/email-client/imap/mailbox.js +372 -242
- package/lib/email-client/imap/subconnection.js +8 -30
- package/lib/email-client/imap/sync-operations.js +220 -127
- package/lib/email-client/imap-client.js +228 -164
- package/lib/email-client/message-builder.js +14 -79
- package/lib/email-client/notification-handler.js +1 -2
- package/lib/email-client/outlook-client.js +372 -338
- package/lib/email-client/smtp-pool-manager.js +16 -13
- package/lib/email-client/sync-state-fields.js +19 -0
- package/lib/encrypt.js +157 -41
- package/lib/enum-descriptions.js +3 -1
- package/lib/env-setting-overrides.js +288 -0
- package/lib/export-worker.js +751 -0
- package/lib/export.js +64 -15
- package/lib/gateway.js +19 -4
- package/lib/get-raw-email.js +25 -107
- package/lib/hapi-request-logger.js +107 -0
- package/lib/health.js +75 -0
- package/lib/imapproxy/imap-core/README.md +6 -5
- package/lib/lock-run.js +119 -0
- package/lib/logger-consts.js +48 -0
- package/lib/logger.js +1 -1
- package/lib/lua/z-head-scores.lua +28 -0
- package/lib/mcp/tools.js +37 -8
- package/lib/network-errors.js +1 -1
- package/lib/node-version.js +24 -0
- package/lib/notify-attachments.js +36 -0
- package/lib/oauth/outlook-mailbox.js +35 -0
- package/lib/oauth/state.js +24 -0
- package/lib/oauth2-apps.js +631 -656
- package/lib/outbox.js +184 -54
- package/lib/parse-message.js +3 -3
- package/lib/pbkdf2-phc.js +1 -1
- package/lib/privileged-settings.js +2 -2
- package/lib/queue-browser/definitions.js +11 -0
- package/lib/queue-browser/index.js +68 -19
- package/lib/queue-job-actions.js +18 -1
- package/lib/queue-retention.js +48 -12
- package/lib/queue-stats.js +11 -2
- package/lib/read-env-value.js +3 -0
- package/lib/redis-memory-warnings.js +99 -0
- package/lib/redis-reconnect.js +29 -0
- package/lib/request-timing.js +23 -0
- package/lib/respawn-backoff.js +35 -0
- package/lib/rewrite-text-nodes.js +19 -59
- package/lib/schemas.js +164 -40
- package/lib/settings.js +6 -2
- package/lib/smtp-auth.js +19 -1
- package/lib/sso.js +1 -1
- package/lib/swagger-options.js +1 -1
- package/lib/thread-diagnostics.js +63 -0
- package/lib/timezones.js +109 -0
- package/lib/tls/provision.js +6 -3
- package/lib/token-audit-log.js +19 -20
- package/lib/token-permission-view.js +7 -6
- package/lib/tools.js +48 -51
- package/lib/totp.js +2 -5
- package/lib/translations.js +1 -2
- package/lib/ui-routes/account-routes.js +475 -454
- package/lib/ui-routes/account-setup.js +99 -0
- package/lib/ui-routes/admin-config-routes.js +152 -100
- package/lib/ui-routes/admin-entities-routes.js +93 -21
- package/lib/ui-routes/auth-routes.js +90 -38
- package/lib/ui-routes/imap-idle-field.js +1 -1
- package/lib/ui-routes/internals-routes.js +5 -0
- package/lib/ui-routes/oauth-config-routes.js +124 -82
- package/lib/ui-routes/outlook-subscription-view.js +1 -1
- package/lib/ui-routes/overridable-fields.js +84 -0
- package/lib/ui-routes/queue-routes.js +8 -5
- package/lib/ui-routes/route-helpers.js +19 -3
- package/lib/ui-routes/settings-page.js +6 -0
- package/lib/ui-routes/tls-config-routes.js +58 -15
- package/lib/utils/back-off.js +82 -0
- package/lib/utils/decode-headers.js +3 -12
- package/lib/utils/filter-empty.js +20 -0
- package/lib/utils/int-setting.js +48 -0
- package/lib/utils/murmurhash3.js +66 -0
- package/lib/utils/public-suffix.js +122 -0
- package/lib/utils/random-id.js +26 -0
- package/lib/utils/tracking-settings.js +35 -0
- package/lib/utils/version.js +74 -0
- package/lib/web-safe-html.js +18 -105
- package/lib/webhook-delivery.js +461 -0
- package/lib/webhook-failures.js +132 -0
- package/lib/webhook-request.js +29 -1
- package/lib/webhook-routing.js +56 -0
- package/lib/webhook-test.js +88 -0
- package/lib/webhooks.js +93 -45
- package/lib/worker-rpc-error.js +2 -1
- package/package.json +37 -38
- package/sbom.json +7902 -1
- package/server.js +784 -518
- package/static/js/ace/ace.js +1 -1
- package/static/licenses.html +225 -1060
- package/translations/messages.pot +62 -63
- package/views/config/ai.hbs +1 -1
- package/views/config/security.hbs +24 -2
- package/views/config/service.hbs +47 -0
- package/views/config/webhooks.hbs +36 -0
- package/views/internals/index.hbs +8 -0
- package/views/partials/queue_retention_note.hbs +12 -8
- package/views/partials/ui/env-managed-alert.hbs +16 -7
- package/views/partials/webhook_form.hbs +1 -1
- package/views/suppression-lists/index.hbs +1 -1
- package/workers/api.js +840 -611
- package/workers/export.js +17 -632
- package/workers/imap.js +13 -0
- package/workers/smtp.js +9 -11
- package/workers/submit.js +1 -1
- package/workers/webhooks.js +18 -448
- 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
|
-
|
|
19
|
-
const {
|
|
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: '
|
|
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
|
|
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: '
|
|
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
|
-
|
|
124
|
-
|
|
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
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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: '
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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;
|