emailengine-app 2.81.2 → 2.82.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 +12 -11
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +27 -0
- package/Dockerfile +2 -0
- package/bin/emailengine.js +28 -18
- package/config/default.toml +0 -5
- package/config/test.toml +0 -5
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +70 -42
- package/getswagger.sh +0 -4
- package/lib/account/account-state.js +2 -110
- package/lib/account/expected-identity.js +1 -1
- package/lib/account-assignment.js +138 -1
- package/lib/account.js +254 -859
- package/lib/api-reference/index.js +2 -3
- package/lib/api-reference/schema-tree.js +53 -3
- package/lib/api-routes/account-routes.js +18 -29
- package/lib/api-routes/blocklist-routes.js +2 -2
- package/lib/api-routes/bull-board-routes.js +1 -6
- package/lib/api-routes/export-routes.js +2 -22
- package/lib/api-routes/gateway-routes.js +5 -14
- package/lib/api-routes/index.js +1 -13
- package/lib/api-routes/mailbox-routes.js +2 -7
- package/lib/api-routes/mcp-oauth-routes.js +2 -1
- package/lib/api-routes/mcp-routes.js +7 -7
- package/lib/api-routes/message-routes.js +40 -235
- package/lib/api-routes/mint-bounds.js +110 -0
- package/lib/api-routes/oauth2-app-routes.js +23 -32
- package/lib/api-routes/operation-impact.js +1 -1
- package/lib/api-routes/outbox-routes.js +2 -2
- package/lib/api-routes/permission-map.js +1 -7
- package/lib/api-routes/route-helpers.js +11 -5
- package/lib/api-routes/settings-routes.js +19 -19
- package/lib/api-routes/stats-routes.js +1 -1
- package/lib/api-routes/submit-routes.js +17 -18
- package/lib/api-routes/template-routes.js +4 -9
- package/lib/api-routes/token-routes.js +27 -5
- package/lib/api-token-scheme.js +71 -0
- package/lib/arf-detect.js +33 -6
- package/lib/auth-token.js +44 -24
- package/lib/autodetect-imap-settings.js +163 -123
- package/lib/bounce-detect.js +25 -16
- package/lib/calendar-event.js +78 -0
- package/lib/consts.js +42 -5
- package/lib/create-imap-client.js +24 -0
- package/lib/db.js +76 -11
- package/lib/delivery-error.js +2 -1
- package/lib/egress-fetch.js +54 -3
- package/lib/egress-filter.js +11 -0
- package/lib/email-client/api-retry.js +147 -0
- package/lib/email-client/base-client.js +377 -523
- package/lib/email-client/gmail/gmail-api.js +38 -125
- package/lib/email-client/gmail/send-request.js +1 -1
- package/lib/email-client/gmail-client.js +76 -50
- package/lib/email-client/imap/mailbox.js +158 -324
- package/lib/email-client/imap/stale-view.js +109 -0
- package/lib/email-client/imap/subconnection.js +46 -9
- package/lib/email-client/imap/sync-operations.js +5 -37
- package/lib/email-client/imap-client.js +188 -64
- package/lib/email-client/message-builder.js +9 -14
- package/lib/email-client/notification-handler.js +5 -219
- package/lib/email-client/outlook/graph-api.js +147 -126
- package/lib/email-client/outlook/send-request.js +10 -4
- package/lib/email-client/outlook-client.js +194 -397
- package/lib/email-client/smtp-pool-manager.js +3 -2
- package/lib/encrypt.js +184 -19
- package/lib/enum-descriptions.js +1 -2
- package/lib/export.js +133 -39
- package/lib/gateway.js +20 -6
- package/lib/get-raw-email.js +26 -44
- package/lib/handlebars-helpers.js +31 -10
- package/lib/imap-proxy-auth.js +13 -29
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
- package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
- package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
- package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
- package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
- package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
- package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
- package/lib/imapproxy/imap-server.js +17 -177
- package/lib/imapproxy/proxy-handoff.js +235 -0
- package/lib/imapproxy/response-error.js +33 -0
- package/lib/imapproxy/upstream-client.js +2 -2
- package/lib/license-beacon.js +3 -9
- package/lib/llm-pre-process.js +182 -43
- package/lib/logger.js +1 -1
- package/lib/lua/ee-export-queue-add.lua +39 -0
- package/lib/lua/ee-get-idempotency.lua +15 -3
- package/lib/lua/ee-release-attempts.lua +23 -0
- package/lib/lua/ee-reserve-attempts.lua +42 -0
- package/lib/lua/h-set-bigger.lua +12 -2
- package/lib/lua/s-list-accounts.lua +6 -3
- package/lib/mcp/index.js +1 -2
- package/lib/mcp/listen.js +221 -18
- package/lib/mcp/oauth.js +44 -5
- package/lib/mcp/resources.js +8 -2
- package/lib/mcp/tools.js +13 -0
- package/lib/message-port-stream.js +64 -6
- package/lib/oauth/external-account-signer.js +16 -13
- package/lib/oauth/gmail.js +22 -20
- package/lib/oauth/outlook.js +19 -16
- package/lib/oauth/pubsub/google.js +38 -2
- package/lib/oauth/scope-checker.js +4 -7
- package/lib/oauth/verify-app.js +2 -2
- package/lib/oauth2-apps.js +139 -44
- package/lib/openapi/build-document.js +1 -1
- package/lib/openapi/joi-schema.js +78 -9
- package/lib/parse-message.js +21 -0
- package/lib/payload-examples-webhooks.json +4 -7
- package/lib/pbkdf2-phc.js +101 -0
- package/lib/privileged-settings.js +0 -14
- package/lib/rate-limit.js +54 -15
- package/lib/redis-scan-delete.js +56 -29
- package/lib/redis-url.js +3 -1
- package/lib/respawn-backoff.js +5 -4
- package/lib/response-stream.js +25 -4
- package/lib/rewrite-text-nodes.js +27 -40
- package/lib/routes-ui.js +0 -5
- package/lib/schemas.js +122 -242
- package/lib/sentry.js +21 -5
- package/lib/settings.js +58 -59
- package/lib/smtp-auth.js +6 -2
- package/lib/smtp-message-processor.js +28 -7
- package/lib/sso.js +7 -3
- package/lib/stream-encrypt.js +14 -13
- package/lib/swagger-options.js +3 -1
- package/lib/tls/provision.js +69 -3
- package/lib/tls/store.js +14 -1
- package/lib/tools.js +113 -52
- package/lib/totp.js +16 -1
- package/lib/ui-routes/account-routes.js +27 -63
- package/lib/ui-routes/admin-config-routes.js +111 -134
- package/lib/ui-routes/admin-entities-routes.js +101 -191
- package/lib/ui-routes/ai-options.js +104 -0
- package/lib/ui-routes/auth-routes.js +98 -18
- package/lib/ui-routes/export-routes.js +3 -23
- package/lib/ui-routes/internals-routes.js +12 -9
- package/lib/ui-routes/network-config-routes.js +8 -18
- package/lib/ui-routes/oauth-config-routes.js +80 -214
- package/lib/ui-routes/route-helpers.js +40 -44
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/utils/decode-headers.js +32 -5
- package/lib/utils/header-map.js +62 -1
- package/lib/utils/network.js +2 -0
- package/lib/web-safe-html.js +77 -4
- package/lib/webhook-request.js +9 -1
- package/lib/webhook-routing.js +27 -1
- package/lib/webhooks.js +120 -43
- package/lib/worker-rpc-error.js +43 -2
- package/list-generate.js +13 -2
- package/package.json +33 -41
- package/sbom.json +1 -1
- package/scripts/refresh-test-tokens.js +42 -14
- package/server.js +317 -289
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +7 -8
- package/static/js/ee-client.js +145 -70
- package/static/js/ui.js +350 -154
- package/static/licenses.html +434 -1835
- package/translations/messages.pot +97 -97
- package/views/accounts/browse.hbs +10 -4
- package/views/config/ai.hbs +49 -41
- package/views/config/oauth/app.hbs +2 -1
- package/views/dashboard.hbs +18 -16
- package/views/layout/app.hbs +0 -22
- package/views/layout/login.hbs +2 -1
- package/views/partials/filter_editor_js.hbs +4 -3
- package/views/partials/side_menu.hbs +0 -4
- package/views/partials/ui/account-picker.hbs +6 -32
- package/views/partials/ui/model-picker.hbs +31 -0
- package/views/partials/ui/pagination.hbs +6 -1
- package/views/partials/ui/picker.hbs +47 -0
- package/views/unsubscribe.hbs +1 -1
- package/workers/api.js +20 -20
- package/workers/export.js +55 -60
- package/workers/imap.js +126 -46
- package/workers/submit.js +3 -1
- package/workers/webhooks.js +46 -27
- package/.githooks/pre-commit +0 -80
- package/.github/CODE_OF_CONDUCT.md +0 -76
- package/.github/contributing.md +0 -17
- package/.github/dependabot.yml +0 -22
- package/.github/docker-smoke-test.sh +0 -61
- package/.github/workflows/deploy.yml +0 -215
- package/.github/workflows/e2e.yml +0 -55
- package/.github/workflows/release.yaml +0 -217
- package/.github/workflows/test.yml +0 -307
- package/lib/api-routes/chat-routes.js +0 -535
- package/lib/document-store.js +0 -75
- package/lib/es.js +0 -757
- package/lib/generate-text-preview.js +0 -61
- package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
- package/lib/pre-process.js +0 -196
- package/lib/threads.js +0 -155
- package/lib/ui-routes/document-store-routes.js +0 -806
- package/playwright.config.js +0 -47
- package/views/config/document-store/chat.hbs +0 -286
- package/views/config/document-store/index.hbs +0 -146
- package/views/config/document-store/mappings/index.hbs +0 -108
- package/views/config/document-store/mappings/new.hbs +0 -68
- package/views/config/document-store/pre-processing/index.hbs +0 -103
- package/views/partials/document_store_header.hbs +0 -30
- package/workers/documents.js +0 -1128
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const { redis } = require('../db');
|
|
4
4
|
const { Account } = require('../account');
|
|
5
5
|
const getSecret = require('../get-secret');
|
|
6
|
-
const settings = require('../settings');
|
|
7
6
|
const Joi = require('joi');
|
|
8
7
|
const { failAction } = require('../tools');
|
|
9
8
|
const { handleError } = require('./route-helpers');
|
|
@@ -42,9 +41,7 @@ const {
|
|
|
42
41
|
messageIdSchema,
|
|
43
42
|
messageDetailsSchema,
|
|
44
43
|
messageListSchema,
|
|
45
|
-
messageEntrySchema,
|
|
46
44
|
documentStoreSchema,
|
|
47
|
-
documentStoreQuerySchema,
|
|
48
45
|
searchSchema,
|
|
49
46
|
messageUpdateSchema,
|
|
50
47
|
addressSchema,
|
|
@@ -53,7 +50,9 @@ const {
|
|
|
53
50
|
emailIdSchema,
|
|
54
51
|
threadIdSchema,
|
|
55
52
|
apiResponses,
|
|
56
|
-
ENUM_DESCRIPTIONS
|
|
53
|
+
ENUM_DESCRIPTIONS,
|
|
54
|
+
MAX_MESSAGE_ATTACHMENTS,
|
|
55
|
+
apiBoolean
|
|
57
56
|
} = require('../schemas');
|
|
58
57
|
|
|
59
58
|
const listMessageFolderPathDescription =
|
|
@@ -69,6 +68,18 @@ const UPDATE_OP_ENTRY_EXAMPLE = {
|
|
|
69
68
|
|
|
70
69
|
// Response field for a flag or label update operation. IMAP accounts return a boolean (whether
|
|
71
70
|
// the operation succeeded), API-based accounts echo the requested values as an array.
|
|
71
|
+
// The `failed` member of a bulk response: the messages the server refused after retries. The
|
|
72
|
+
// labels are public type names in the OpenAPI document, so the prefix is the operation's.
|
|
73
|
+
const bulkFailedSchema = prefix =>
|
|
74
|
+
Joi.object({
|
|
75
|
+
emailIds: Joi.array()
|
|
76
|
+
.items(emailIdSchema)
|
|
77
|
+
.description('List of emailId values the server refused after retries (MS Graph API accounts only)')
|
|
78
|
+
.label(`${prefix}FailedEmailIds`)
|
|
79
|
+
})
|
|
80
|
+
.label(`${prefix}Failed`)
|
|
81
|
+
.description('Present when some messages could not be processed (MS Graph API accounts only)');
|
|
82
|
+
|
|
72
83
|
const updateOpResultSchema = (op, noun, entryLabel, example, label) =>
|
|
73
84
|
Joi.alternatives()
|
|
74
85
|
.try(Joi.boolean(), Joi.array().items(Joi.string().label(entryLabel).example(UPDATE_OP_ENTRY_EXAMPLE[noun])))
|
|
@@ -85,7 +96,7 @@ const idMapSchema = Joi.array()
|
|
|
85
96
|
.label('IdMapArray');
|
|
86
97
|
|
|
87
98
|
async function init(args) {
|
|
88
|
-
const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT
|
|
99
|
+
const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
|
|
89
100
|
|
|
90
101
|
// GET /v1/account/{account}/message/{message}/source - Download raw message
|
|
91
102
|
server.route({
|
|
@@ -147,13 +158,12 @@ async function init(args) {
|
|
|
147
158
|
method: 'GET',
|
|
148
159
|
path: '/v1/account/{account}/message/{message}',
|
|
149
160
|
|
|
150
|
-
async handler(request
|
|
161
|
+
async handler(request) {
|
|
151
162
|
let accountObject = new Account({
|
|
152
163
|
redis,
|
|
153
164
|
account: request.params.account,
|
|
154
165
|
call,
|
|
155
166
|
secret: await getSecret(),
|
|
156
|
-
esClient: await h.getESClient(request.logger),
|
|
157
167
|
timeout: request.headers['x-ee-timeout']
|
|
158
168
|
});
|
|
159
169
|
|
|
@@ -231,9 +241,7 @@ async function init(args) {
|
|
|
231
241
|
.description('Which text content to return, use * for all. By default text content is not returned.')
|
|
232
242
|
.label('MessageTextType'),
|
|
233
243
|
|
|
234
|
-
webSafeHtml:
|
|
235
|
-
.truthy('Y', 'true', '1')
|
|
236
|
-
.falsy('N', 'false', 0)
|
|
244
|
+
webSafeHtml: apiBoolean()
|
|
237
245
|
.default(false)
|
|
238
246
|
.description('Shorthand option to fetch and preprocess HTML and inline images')
|
|
239
247
|
.meta({ usage: FIELD_USAGE.webSafeHtml })
|
|
@@ -243,28 +251,19 @@ async function init(args) {
|
|
|
243
251
|
// for" from an explicit false, because an explicit false is what overrides
|
|
244
252
|
// the webSafeHtml shorthand. It resolves the tri-state to a boolean, so no
|
|
245
253
|
// consumer downstream sees the undefined.
|
|
246
|
-
embedAttachedImages:
|
|
247
|
-
.truthy('Y', 'true', '1')
|
|
248
|
-
.falsy('N', 'false', 0)
|
|
254
|
+
embedAttachedImages: apiBoolean()
|
|
249
255
|
.description('If true, then fetches attached images and embeds these in the HTML as data URIs. Not set means false')
|
|
250
256
|
.meta({ usage: FIELD_USAGE.embedAttachedImages })
|
|
251
257
|
.label('EmbedImages'),
|
|
252
258
|
|
|
253
|
-
preProcessHtml:
|
|
254
|
-
.truthy('Y', 'true', '1')
|
|
255
|
-
.falsy('N', 'false', 0)
|
|
256
|
-
.default(false)
|
|
257
|
-
.description('If true, then pre-processes HTML for compatibility')
|
|
258
|
-
.label('PreProcess'),
|
|
259
|
+
preProcessHtml: apiBoolean().default(false).description('If true, then pre-processes HTML for compatibility').label('PreProcess'),
|
|
259
260
|
|
|
260
|
-
markAsSeen:
|
|
261
|
-
.truthy('Y', 'true', '1')
|
|
262
|
-
.falsy('N', 'false', 0)
|
|
261
|
+
markAsSeen: apiBoolean()
|
|
263
262
|
.default(false)
|
|
264
263
|
.description('If true, then marks unseen email as seen while returning the message')
|
|
265
264
|
.label('MarkAsSeen'),
|
|
266
265
|
|
|
267
|
-
documentStore: documentStoreSchema
|
|
266
|
+
documentStore: documentStoreSchema
|
|
268
267
|
}),
|
|
269
268
|
|
|
270
269
|
params: Joi.object({
|
|
@@ -424,6 +423,7 @@ async function init(args) {
|
|
|
424
423
|
.label('MsgUploadReference')
|
|
425
424
|
}).label('UploadAttachment')
|
|
426
425
|
)
|
|
426
|
+
.max(MAX_MESSAGE_ATTACHMENTS)
|
|
427
427
|
.description('List of attachments')
|
|
428
428
|
.label('UploadAttachmentList'),
|
|
429
429
|
|
|
@@ -462,7 +462,6 @@ async function init(args) {
|
|
|
462
462
|
.description('Referenced message ID. Not present when only a thread ID was referenced'),
|
|
463
463
|
threadId: threadIdSchema.description('Referenced thread ID (Gmail API accounts only)').label('ResponseReferenceThreadId'),
|
|
464
464
|
success: Joi.boolean().example(true).description('Was the referenced message processed').label('ResponseReferenceSuccess'),
|
|
465
|
-
documentStore: documentStoreSchema.default(false),
|
|
466
465
|
error: Joi.string().example('Referenced message was not found').description('An error message if referenced message processing failed')
|
|
467
466
|
})
|
|
468
467
|
.description('Reference info if referencing was requested')
|
|
@@ -630,6 +629,7 @@ async function init(args) {
|
|
|
630
629
|
delete: updateOpResultSchema('delete', 'labels', 'BulkLabelEntry', ['Label3'], 'BulkLabelDeleteResult'),
|
|
631
630
|
set: updateOpResultSchema('set', 'labels', 'BulkLabelEntry', ['Label1'], 'BulkLabelSetResult')
|
|
632
631
|
}).label('BulkLabelUpdateResponse'),
|
|
632
|
+
failed: bulkFailedSchema('BulkUpdate'),
|
|
633
633
|
emailIds: Joi.array()
|
|
634
634
|
.items(emailIdSchema)
|
|
635
635
|
.description('List of updated email IDs (Gmail API and MS Graph API accounts only)')
|
|
@@ -794,7 +794,8 @@ async function init(args) {
|
|
|
794
794
|
.description(
|
|
795
795
|
'An optional list of emailId values, if the server supports unique email IDs (Gmail API and MS Graph API accounts only). Null when no messages matched the search (Gmail API)'
|
|
796
796
|
)
|
|
797
|
-
.label('MovedEmailIdsArray')
|
|
797
|
+
.label('MovedEmailIdsArray'),
|
|
798
|
+
failed: bulkFailedSchema('BulkMove')
|
|
798
799
|
}).label('MessagesMoveResponse'),
|
|
799
800
|
failAction: 'log'
|
|
800
801
|
}
|
|
@@ -854,9 +855,7 @@ async function init(args) {
|
|
|
854
855
|
failAction,
|
|
855
856
|
|
|
856
857
|
query: Joi.object({
|
|
857
|
-
force:
|
|
858
|
-
.truthy('Y', 'true', '1')
|
|
859
|
-
.falsy('N', 'false', 0)
|
|
858
|
+
force: apiBoolean()
|
|
860
859
|
.default(false)
|
|
861
860
|
.description('Delete message even if not in Trash. Not supported for Gmail API accounts.')
|
|
862
861
|
.label('ForceDelete')
|
|
@@ -945,9 +944,7 @@ async function init(args) {
|
|
|
945
944
|
|
|
946
945
|
query: Joi.object({
|
|
947
946
|
path: Joi.string().empty('').required().example('INBOX').description(listMessageFolderPathDescription),
|
|
948
|
-
force:
|
|
949
|
-
.truthy('Y', 'true', '1')
|
|
950
|
-
.falsy('N', 'false', 0)
|
|
947
|
+
force: apiBoolean()
|
|
951
948
|
.default(false)
|
|
952
949
|
.description('Delete messages even if not in Trash. Not supported for Gmail API accounts (messages are always moved to Trash)')
|
|
953
950
|
.label('ForceDelete')
|
|
@@ -986,7 +983,8 @@ async function init(args) {
|
|
|
986
983
|
.label('DeletedEmailIdsArray')
|
|
987
984
|
})
|
|
988
985
|
.label('MessagesDeleted')
|
|
989
|
-
.description('Value is present if messages were deleted permanently (MS Graph API accounts only)')
|
|
986
|
+
.description('Value is present if messages were deleted permanently (MS Graph API accounts only)'),
|
|
987
|
+
failed: bulkFailedSchema('BulkDelete')
|
|
990
988
|
}).label('MessagesDeleteResponse'),
|
|
991
989
|
failAction: 'log'
|
|
992
990
|
}
|
|
@@ -998,13 +996,12 @@ async function init(args) {
|
|
|
998
996
|
method: 'GET',
|
|
999
997
|
path: '/v1/account/{account}/messages',
|
|
1000
998
|
|
|
1001
|
-
async handler(request
|
|
999
|
+
async handler(request) {
|
|
1002
1000
|
let accountObject = new Account({
|
|
1003
1001
|
redis,
|
|
1004
1002
|
account: request.params.account,
|
|
1005
1003
|
call,
|
|
1006
1004
|
secret: await getSecret(),
|
|
1007
|
-
esClient: await h.getESClient(request.logger),
|
|
1008
1005
|
timeout: request.headers['x-ee-timeout']
|
|
1009
1006
|
});
|
|
1010
1007
|
|
|
@@ -1070,7 +1067,7 @@ async function init(args) {
|
|
|
1070
1067
|
.label('PageNumber'),
|
|
1071
1068
|
|
|
1072
1069
|
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize'),
|
|
1073
|
-
documentStore: documentStoreSchema
|
|
1070
|
+
documentStore: documentStoreSchema
|
|
1074
1071
|
}).label('MessageQuery')
|
|
1075
1072
|
},
|
|
1076
1073
|
|
|
@@ -1086,38 +1083,15 @@ async function init(args) {
|
|
|
1086
1083
|
method: 'POST',
|
|
1087
1084
|
path: '/v1/account/{account}/search',
|
|
1088
1085
|
|
|
1089
|
-
async handler(request
|
|
1086
|
+
async handler(request) {
|
|
1090
1087
|
let accountObject = new Account({
|
|
1091
1088
|
redis,
|
|
1092
1089
|
account: request.params.account,
|
|
1093
1090
|
call,
|
|
1094
1091
|
secret: await getSecret(),
|
|
1095
|
-
esClient: await h.getESClient(request.logger),
|
|
1096
1092
|
timeout: request.headers['x-ee-timeout']
|
|
1097
1093
|
});
|
|
1098
1094
|
|
|
1099
|
-
let extraValidationErrors = [];
|
|
1100
|
-
|
|
1101
|
-
if (request.query.documentStore) {
|
|
1102
|
-
for (let key of ['seq', 'modseq']) {
|
|
1103
|
-
if (request.payload.search && key in request.payload.search) {
|
|
1104
|
-
extraValidationErrors.push({ message: 'Not available when using Document Store', context: { key } });
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
} else {
|
|
1108
|
-
for (let key of ['documentQuery']) {
|
|
1109
|
-
if (key in request.payload) {
|
|
1110
|
-
extraValidationErrors.push({ message: 'Requires Document Store to be enabled', context: { key } });
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
if (extraValidationErrors.length) {
|
|
1116
|
-
let error = new Error('Input validation failed');
|
|
1117
|
-
error.details = extraValidationErrors;
|
|
1118
|
-
return failAction(request, h, error);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
1095
|
try {
|
|
1122
1096
|
return await accountObject.searchMessages(Object.assign(request.query, request.payload));
|
|
1123
1097
|
} catch (err) {
|
|
@@ -1162,15 +1136,7 @@ async function init(args) {
|
|
|
1162
1136
|
}),
|
|
1163
1137
|
|
|
1164
1138
|
query: Joi.object({
|
|
1165
|
-
path: Joi.string()
|
|
1166
|
-
.when('documentStore', {
|
|
1167
|
-
is: true,
|
|
1168
|
-
then: Joi.optional(),
|
|
1169
|
-
otherwise: Joi.required()
|
|
1170
|
-
})
|
|
1171
|
-
.example('INBOX')
|
|
1172
|
-
.description(listMessageFolderPathDescription)
|
|
1173
|
-
.label('Path'),
|
|
1139
|
+
path: Joi.string().required().example('INBOX').description(listMessageFolderPathDescription).label('Path'),
|
|
1174
1140
|
|
|
1175
1141
|
cursor: Joi.string()
|
|
1176
1142
|
.trim()
|
|
@@ -1191,36 +1157,17 @@ async function init(args) {
|
|
|
1191
1157
|
|
|
1192
1158
|
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page'),
|
|
1193
1159
|
|
|
1194
|
-
useOutlookSearch:
|
|
1195
|
-
.truthy('Y', 'true', '1')
|
|
1196
|
-
.falsy('N', 'false', 0)
|
|
1160
|
+
useOutlookSearch: apiBoolean()
|
|
1197
1161
|
.description('MS Graph only. Use the $search parameter for search queries instead of $filter')
|
|
1198
1162
|
.meta({ usage: FIELD_USAGE.useOutlookSearch })
|
|
1199
1163
|
.label('useOutlookSearch')
|
|
1200
1164
|
.optional(),
|
|
1201
1165
|
|
|
1202
|
-
documentStore: documentStoreSchema
|
|
1203
|
-
exposeQuery: Joi.boolean()
|
|
1204
|
-
.truthy('Y', 'true', '1')
|
|
1205
|
-
.falsy('N', 'false', 0)
|
|
1206
|
-
.description('If enabled then includes the combined query (as the documentStoreQuery field) in the response for debugging')
|
|
1207
|
-
.label('exposeQuery')
|
|
1208
|
-
.when('documentStore', {
|
|
1209
|
-
is: true,
|
|
1210
|
-
then: Joi.optional(),
|
|
1211
|
-
otherwise: Joi.forbidden()
|
|
1212
|
-
})
|
|
1213
|
-
.meta({ swaggerHidden: true })
|
|
1166
|
+
documentStore: documentStoreSchema
|
|
1214
1167
|
}),
|
|
1215
1168
|
|
|
1216
1169
|
payload: Joi.object({
|
|
1217
|
-
search: searchSchema
|
|
1218
|
-
documentQuery: Joi.object()
|
|
1219
|
-
.min(1)
|
|
1220
|
-
.description('Document Store query. Only allowed with `documentStore`.')
|
|
1221
|
-
.label('DocumentQuery')
|
|
1222
|
-
.unknown()
|
|
1223
|
-
.meta({ swaggerHidden: true })
|
|
1170
|
+
search: searchSchema
|
|
1224
1171
|
})
|
|
1225
1172
|
.label('MessageSearchPayload')
|
|
1226
1173
|
.example({
|
|
@@ -1253,157 +1200,17 @@ async function init(args) {
|
|
|
1253
1200
|
}
|
|
1254
1201
|
});
|
|
1255
1202
|
|
|
1256
|
-
// POST /v1/unified/search - Unified search for messages
|
|
1257
|
-
// Deprecated Document Store feature: only register this endpoint when the feature is enabled,
|
|
1258
|
-
// otherwise it behaves like a regular 404.
|
|
1259
|
-
if (documentStoreFeatureEnabled) {
|
|
1260
|
-
server.route({
|
|
1261
|
-
method: 'POST',
|
|
1262
|
-
path: '/v1/unified/search',
|
|
1263
|
-
|
|
1264
|
-
async handler(request, h) {
|
|
1265
|
-
let accountObject = new Account({
|
|
1266
|
-
redis,
|
|
1267
|
-
call,
|
|
1268
|
-
secret: await getSecret(),
|
|
1269
|
-
esClient: await h.getESClient(request.logger),
|
|
1270
|
-
timeout: request.headers['x-ee-timeout']
|
|
1271
|
-
});
|
|
1272
|
-
|
|
1273
|
-
let extraValidationErrors = [];
|
|
1274
|
-
|
|
1275
|
-
for (let key of ['seq', 'modseq']) {
|
|
1276
|
-
if (request.payload.search && key in request.payload.search) {
|
|
1277
|
-
extraValidationErrors.push({ message: 'Not available when using Document Store', context: { key } });
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
if (extraValidationErrors.length) {
|
|
1282
|
-
let error = new Error('Input validation failed');
|
|
1283
|
-
error.details = extraValidationErrors;
|
|
1284
|
-
return failAction(request, h, error);
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
let documentStoreEnabled = await settings.get('documentStoreEnabled');
|
|
1288
|
-
if (!documentStoreEnabled) {
|
|
1289
|
-
let error = new Error('Document store not enabled');
|
|
1290
|
-
error.details = extraValidationErrors;
|
|
1291
|
-
return failAction(request, h, error);
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
try {
|
|
1295
|
-
return await accountObject.searchMessages(Object.assign({ documentStore: true }, request.query, request.payload), { unified: true });
|
|
1296
|
-
} catch (err) {
|
|
1297
|
-
handleError(request, err);
|
|
1298
|
-
}
|
|
1299
|
-
},
|
|
1300
|
-
options: {
|
|
1301
|
-
description: 'Unified search for messages',
|
|
1302
|
-
notes: 'Filter messages from the Document Store for multiple accounts or paths. Document Store must be enabled for the unified search to work.',
|
|
1303
|
-
tags: ['api', 'Deprecated endpoints (Document Store)'],
|
|
1304
|
-
|
|
1305
|
-
plugins: {
|
|
1306
|
-
openapi: {
|
|
1307
|
-
'x-ee-impact': IMPACT.READONLY,
|
|
1308
|
-
responses: apiResponses('Returns matching messages across all indexed accounts.', 400, 401, 403, 429, 500)
|
|
1309
|
-
}
|
|
1310
|
-
},
|
|
1311
|
-
|
|
1312
|
-
auth: {
|
|
1313
|
-
strategy: 'api-token',
|
|
1314
|
-
mode: 'required'
|
|
1315
|
-
},
|
|
1316
|
-
cors: CORS_CONFIG,
|
|
1317
|
-
|
|
1318
|
-
validate: {
|
|
1319
|
-
options: {
|
|
1320
|
-
stripUnknown: false,
|
|
1321
|
-
abortEarly: false,
|
|
1322
|
-
convert: true
|
|
1323
|
-
},
|
|
1324
|
-
failAction,
|
|
1325
|
-
|
|
1326
|
-
query: Joi.object({
|
|
1327
|
-
page: Joi.number()
|
|
1328
|
-
.integer()
|
|
1329
|
-
.min(0)
|
|
1330
|
-
.max(1024 * 1024)
|
|
1331
|
-
.default(0)
|
|
1332
|
-
.example(0)
|
|
1333
|
-
.description('Page number (zero indexed, so use 0 for first page)'),
|
|
1334
|
-
pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page'),
|
|
1335
|
-
exposeQuery: Joi.boolean()
|
|
1336
|
-
.truthy('Y', 'true', '1')
|
|
1337
|
-
.falsy('N', 'false', 0)
|
|
1338
|
-
.description('If enabled then includes the combined query (as the documentStoreQuery field) in the response for debugging')
|
|
1339
|
-
.label('exposeQuery')
|
|
1340
|
-
.optional()
|
|
1341
|
-
.meta({ swaggerHidden: true })
|
|
1342
|
-
}),
|
|
1343
|
-
|
|
1344
|
-
payload: Joi.object({
|
|
1345
|
-
accounts: Joi.array()
|
|
1346
|
-
.items(Joi.string().empty('').trim().max(256).example('example'))
|
|
1347
|
-
.single()
|
|
1348
|
-
.description('Optional list of account ID values')
|
|
1349
|
-
.label('UnifiedSearchAccounts'),
|
|
1350
|
-
paths: Joi.array()
|
|
1351
|
-
.items(Joi.string().optional().example('INBOX'))
|
|
1352
|
-
.single()
|
|
1353
|
-
.description('Optional list of mailbox folder paths or specialUse flags')
|
|
1354
|
-
.label('UnifiedSearchPaths'),
|
|
1355
|
-
search: searchSchema,
|
|
1356
|
-
documentQuery: Joi.object().min(1).description('Document Store query').label('DocumentQuery').unknown().meta({ swaggerHidden: true })
|
|
1357
|
-
}).label('UnifiedSearchQuery')
|
|
1358
|
-
},
|
|
1359
|
-
|
|
1360
|
-
response: {
|
|
1361
|
-
schema: Joi.object({
|
|
1362
|
-
total: Joi.number()
|
|
1363
|
-
.integer()
|
|
1364
|
-
.example(120)
|
|
1365
|
-
.description('Total number of matching messages (capped at 10000 by the Document Store)')
|
|
1366
|
-
.label('UnifiedTotalNumber'),
|
|
1367
|
-
page: Joi.number().integer().example(0).description('Current page number (zero-based)').label('UnifiedPageNumber'),
|
|
1368
|
-
pages: Joi.number().integer().example(24).description('Total number of pages available').label('UnifiedPagesNumber'),
|
|
1369
|
-
accounts: Joi.array()
|
|
1370
|
-
.items(Joi.string().example('example'))
|
|
1371
|
-
.description('Account filter used for the search, if provided')
|
|
1372
|
-
.label('UnifiedSearchAccountsEcho'),
|
|
1373
|
-
paths: Joi.array()
|
|
1374
|
-
.items(Joi.string().example('INBOX'))
|
|
1375
|
-
.description('Path filter used for the search, if provided')
|
|
1376
|
-
.label('UnifiedSearchPathsEcho'),
|
|
1377
|
-
messages: Joi.array()
|
|
1378
|
-
.items(
|
|
1379
|
-
messageEntrySchema
|
|
1380
|
-
.keys({
|
|
1381
|
-
account: accountIdSchema.description('Account ID this message belongs to')
|
|
1382
|
-
})
|
|
1383
|
-
.unknown()
|
|
1384
|
-
.label('UnifiedMessageListEntry')
|
|
1385
|
-
)
|
|
1386
|
-
.label('UnifiedPageMessages'),
|
|
1387
|
-
documentStoreQuery: documentStoreQuerySchema
|
|
1388
|
-
}).label('UnifiedSearchResponse'),
|
|
1389
|
-
failAction: 'log'
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
1203
|
// GET /v1/account/{account}/text/{text} - Retrieve message text
|
|
1396
1204
|
server.route({
|
|
1397
1205
|
method: 'GET',
|
|
1398
1206
|
path: '/v1/account/{account}/text/{text}',
|
|
1399
1207
|
|
|
1400
|
-
async handler(request
|
|
1208
|
+
async handler(request) {
|
|
1401
1209
|
let accountObject = new Account({
|
|
1402
1210
|
redis,
|
|
1403
1211
|
account: request.params.account,
|
|
1404
1212
|
call,
|
|
1405
1213
|
secret: await getSecret(),
|
|
1406
|
-
esClient: await h.getESClient(request.logger),
|
|
1407
1214
|
timeout: request.headers['x-ee-timeout']
|
|
1408
1215
|
});
|
|
1409
1216
|
|
|
@@ -1464,15 +1271,13 @@ async function init(args) {
|
|
|
1464
1271
|
.description('Which text content to return, use * for all. By default all contents are returned.')
|
|
1465
1272
|
.label('TextSearchTextType'),
|
|
1466
1273
|
|
|
1467
|
-
webSafeHtml:
|
|
1468
|
-
.truthy('Y', 'true', '1')
|
|
1469
|
-
.falsy('N', 'false', 0)
|
|
1274
|
+
webSafeHtml: apiBoolean()
|
|
1470
1275
|
.default(false)
|
|
1471
1276
|
.description('If true, then returns a single sanitized HTML rendering of the body instead of the raw text parts')
|
|
1472
1277
|
.meta({ usage: FIELD_USAGE.webSafeText })
|
|
1473
1278
|
.label('WebSafeText'),
|
|
1474
1279
|
|
|
1475
|
-
documentStore: documentStoreSchema
|
|
1280
|
+
documentStore: documentStoreSchema
|
|
1476
1281
|
}),
|
|
1477
1282
|
|
|
1478
1283
|
params: Joi.object({
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { matchIp, parseComparableIp, parseComparableCidr } = require('../utils/network');
|
|
4
|
+
|
|
5
|
+
// POST /v1/tokens is only reachable by a full-privilege root token, so the new token can never
|
|
6
|
+
// hold a wider grant than its creator. The creator's restrictions and lifetime are a different
|
|
7
|
+
// axis, though: a root token limited to one address, one referrer, a rate limit or a one hour
|
|
8
|
+
// lifetime could otherwise mint a successor with none of those and walk out of every limit it
|
|
9
|
+
// was issued with. Rather than silently narrowing what the caller asked for (which would hand
|
|
10
|
+
// back a token that behaves differently from the request), the mint is refused unless the
|
|
11
|
+
// payload repeats each of the creator's limits at least as narrowly.
|
|
12
|
+
|
|
13
|
+
// Parses a single allowlist entry into [address, bits] with the same parsers matchIp() uses, so
|
|
14
|
+
// the containment check unwraps the IPv4-mapped IPv6 form exactly as the strategy does
|
|
15
|
+
function parseEntry(entry) {
|
|
16
|
+
if (/\/\d+$/.test(entry)) {
|
|
17
|
+
return parseComparableCidr(entry);
|
|
18
|
+
}
|
|
19
|
+
const addr = parseComparableIp(entry);
|
|
20
|
+
return [addr, addr.kind() === 'ipv6' ? 128 : 32];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// True when every address the entry describes is also allowed by the creator's list
|
|
24
|
+
function entryCovered(entry, allowed) {
|
|
25
|
+
let addr;
|
|
26
|
+
let bits;
|
|
27
|
+
try {
|
|
28
|
+
[addr, bits] = parseEntry(entry);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A single address only needs to match; matchIp() already handles the forms the strategy uses
|
|
34
|
+
if (bits === (addr.kind() === 'ipv6' ? 128 : 32)) {
|
|
35
|
+
return matchIp(addr.toString(), allowed);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// A range is covered when it sits entirely inside one allowed range: same family, a prefix at
|
|
39
|
+
// least as long, and its network address inside that range
|
|
40
|
+
for (let candidate of allowed) {
|
|
41
|
+
try {
|
|
42
|
+
let [range, rangeBits] = parseEntry(candidate);
|
|
43
|
+
if (range.kind() === addr.kind() && bits >= rangeBits && addr.match(range, rangeBits)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// an unparseable allowlist entry covers nothing
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lists the ways a requested token would be less restricted than the token minting it.
|
|
55
|
+
*
|
|
56
|
+
* @param {Object} creator - the minting token's record (request.auth.artifacts)
|
|
57
|
+
* @param {Object} payload - the validated mint payload
|
|
58
|
+
* @returns {string[]} human readable reasons, empty when the new token is at least as narrow
|
|
59
|
+
*/
|
|
60
|
+
function mintWidenings(creator, payload) {
|
|
61
|
+
const reasons = [];
|
|
62
|
+
if (!creator || typeof creator !== 'object') {
|
|
63
|
+
return reasons;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const own = creator.restrictions || {};
|
|
67
|
+
const requested = (payload && payload.restrictions) || {};
|
|
68
|
+
|
|
69
|
+
if (Array.isArray(own.addresses) && own.addresses.length) {
|
|
70
|
+
const list = Array.isArray(requested.addresses) ? requested.addresses : [];
|
|
71
|
+
if (!list.length || !list.every(entry => entryCovered(entry, own.addresses))) {
|
|
72
|
+
reasons.push("restrictions.addresses must be set to addresses within the creating token's own address allowlist");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(own.referrers) && own.referrers.length) {
|
|
77
|
+
// Referrer entries are wildcard patterns, and deciding whether one pattern is contained in
|
|
78
|
+
// another is not worth the risk of getting it wrong, so each has to be repeated verbatim
|
|
79
|
+
const list = Array.isArray(requested.referrers) ? requested.referrers : [];
|
|
80
|
+
if (!list.length || !list.every(entry => own.referrers.includes(entry))) {
|
|
81
|
+
reasons.push("restrictions.referrers must be set to a subset of the creating token's own referrer allowlist");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (own.rateLimit && own.rateLimit.maxRequests && own.rateLimit.timeWindow) {
|
|
86
|
+
const limit = requested.rateLimit;
|
|
87
|
+
// Both the burst and the sustained rate have to stay within the creator's limit
|
|
88
|
+
const narrow =
|
|
89
|
+
limit &&
|
|
90
|
+
limit.maxRequests &&
|
|
91
|
+
limit.timeWindow &&
|
|
92
|
+
limit.maxRequests <= own.rateLimit.maxRequests &&
|
|
93
|
+
limit.maxRequests * own.rateLimit.timeWindow <= own.rateLimit.maxRequests * limit.timeWindow;
|
|
94
|
+
if (!narrow) {
|
|
95
|
+
reasons.push("restrictions.rateLimit must be set no higher than the creating token's own rate limit");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (creator.expires) {
|
|
100
|
+
const ownExpires = new Date(creator.expires).getTime();
|
|
101
|
+
const requestedExpires = payload && payload.expires ? new Date(payload.expires).getTime() : NaN;
|
|
102
|
+
if (!Number.isFinite(requestedExpires) || !(requestedExpires <= ownExpires)) {
|
|
103
|
+
reasons.push("expires must be set no later than the creating token's own expiry");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return reasons;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = { mintWidenings };
|