emailengine-app 2.78.0 → 2.79.1
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 +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +68 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +112 -36
- package/lib/api-reference/format.js +91 -4
- package/lib/api-reference/model.js +144 -19
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +80 -34
- package/lib/api-routes/blocklist-routes.js +21 -47
- package/lib/api-routes/chat-routes.js +10 -12
- package/lib/api-routes/delivery-test-routes.js +6 -26
- package/lib/api-routes/export-routes.js +2 -0
- package/lib/api-routes/gateway-routes.js +52 -11
- package/lib/api-routes/license-routes.js +2 -0
- package/lib/api-routes/mailbox-routes.js +29 -26
- package/lib/api-routes/message-routes.js +27 -21
- package/lib/api-routes/oauth2-app-routes.js +11 -29
- package/lib/api-routes/operation-impact.js +80 -0
- package/lib/api-routes/outbox-routes.js +15 -5
- package/lib/api-routes/permission-map.js +401 -0
- package/lib/api-routes/route-helpers.js +294 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +66 -38
- package/lib/api-routes/stats-routes.js +2 -2
- package/lib/api-routes/submit-routes.js +53 -31
- package/lib/api-routes/template-routes.js +3 -0
- package/lib/api-routes/token-routes.js +526 -72
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/arf-detect.js +17 -4
- package/lib/auth-token.js +80 -8
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +16 -0
- package/lib/db.js +26 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +23 -17
- package/lib/email-client/imap/mailbox.js +58 -59
- package/lib/email-client/imap/subconnection.js +10 -7
- package/lib/email-client/imap/sync-operations.js +46 -46
- package/lib/email-client/imap-client.js +85 -28
- package/lib/email-client/message-builder.js +3 -3
- package/lib/email-client/notification-handler.js +1 -1
- package/lib/email-client/outlook/graph-api.js +10 -4
- package/lib/email-client/outlook-client.js +56 -64
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +1 -1
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +1 -1
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
- package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
- package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
- package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
- package/lib/imapproxy/imap-server.js +27 -7
- package/lib/license-beacon.js +4 -9
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +5 -5
- package/lib/logger.js +5 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +290 -292
- package/lib/openapi/build-document.js +20 -8
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +85 -17
- package/lib/pre-process.js +8 -8
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +1 -1
- package/lib/reconnection-manager.js +2 -2
- package/lib/rewrite-text-nodes.js +4 -3
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +218 -162
- package/lib/settings.js +98 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +4 -4
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +231 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +247 -66
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +42 -15
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +117 -38
- package/lib/ui-routes/auth-routes.js +30 -24
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +12 -12
- package/lib/ui-routes/reference-routes.js +3 -3
- package/lib/ui-routes/route-helpers.js +78 -2
- package/lib/ui-routes/settings-page.js +1 -1
- package/lib/ui-routes/smtp-test-routes.js +1 -1
- package/lib/ui-routes/suppression-list-routes.js +299 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +84 -0
- package/lib/webhooks.js +48 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +116 -55
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +136 -9
- package/static/js/reference.js +456 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +51 -41
- package/translations/messages.pot +59 -59
- package/views/accounts/account.hbs +75 -13
- package/views/accounts/browse.hbs +19 -36
- package/views/accounts/edit.hbs +2 -2
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/operation.hbs +47 -13
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +110 -52
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/try-it.hbs +84 -11
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/checkbox.hbs +2 -2
- package/views/partials/ui/tabs.hbs +7 -1
- package/views/reference/token.hbs +4 -0
- package/views/suppression-lists/index.hbs +85 -0
- package/views/suppression-lists/list.hbs +87 -0
- package/views/templates/index.hbs +10 -4
- package/views/templates/template.hbs +1 -1
- package/views/tokens/index.hbs +53 -6
- package/views/tokens/new.hbs +334 -5
- package/workers/api.js +185 -102
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +77 -78
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +80 -26
- package/lib/feature-flags.js +0 -48
|
@@ -4,13 +4,13 @@ const crypto = require('crypto');
|
|
|
4
4
|
const { redis } = require('../db');
|
|
5
5
|
const { Account } = require('../account');
|
|
6
6
|
const getSecret = require('../get-secret');
|
|
7
|
-
const { oauth2Apps,
|
|
7
|
+
const { oauth2Apps, SERVICE_ACCOUNT_PROVIDERS } = require('../oauth2-apps');
|
|
8
8
|
const settings = require('../settings');
|
|
9
9
|
const { autodetectImapSettings } = require('../autodetect-imap-settings');
|
|
10
10
|
const Boom = require('@hapi/boom');
|
|
11
11
|
const Joi = require('joi');
|
|
12
12
|
const { failAction, getSignedFormData, getLogs, verifyAccountInfo } = require('../tools');
|
|
13
|
-
const { handleError } = require('./route-helpers');
|
|
13
|
+
const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers');
|
|
14
14
|
|
|
15
15
|
const {
|
|
16
16
|
settingsSchema,
|
|
@@ -34,6 +34,8 @@ const {
|
|
|
34
34
|
|
|
35
35
|
const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES } = require('../consts');
|
|
36
36
|
const BEHAVIOR = require('./behavior-notes');
|
|
37
|
+
const { IMPACT } = require('./operation-impact');
|
|
38
|
+
const { FIELD_USAGE } = require('../field-usage');
|
|
37
39
|
|
|
38
40
|
// OAuth2 scope list stored on the account (accountData.oauth2.scope). Reused with a per-route
|
|
39
41
|
// description/label where the same value is exposed under a different field name
|
|
@@ -218,9 +220,8 @@ async function init(args) {
|
|
|
218
220
|
.max(256)
|
|
219
221
|
.allow(null)
|
|
220
222
|
.example('example')
|
|
221
|
-
.description(
|
|
222
|
-
|
|
223
|
-
)
|
|
223
|
+
.description('Account ID. If set to `null`, a unique ID will be generated automatically')
|
|
224
|
+
.meta({ usage: FIELD_USAGE.accountId })
|
|
224
225
|
.required(),
|
|
225
226
|
|
|
226
227
|
name: Joi.string().max(256).required().example('My Email Account').description('Display name for the account'),
|
|
@@ -256,11 +257,20 @@ async function init(args) {
|
|
|
256
257
|
|
|
257
258
|
imapIndexer: accountSchemas.imapIndexer,
|
|
258
259
|
|
|
259
|
-
imap: Joi.object(imapSchemaArg)
|
|
260
|
+
imap: Joi.object(imapSchemaArg)
|
|
261
|
+
.allow(false)
|
|
262
|
+
.description('IMAP configuration. Set to `false` when there is no IMAP access to configure.')
|
|
263
|
+
.label('ImapConfiguration'),
|
|
260
264
|
|
|
261
|
-
smtp: Joi.object(smtpSchemaArg)
|
|
265
|
+
smtp: Joi.object(smtpSchemaArg)
|
|
266
|
+
.allow(false)
|
|
267
|
+
.description('SMTP configuration. Set to `false` when there is no SMTP access to configure.')
|
|
268
|
+
.label('SmtpConfiguration'),
|
|
262
269
|
|
|
263
|
-
oauth2: Joi.object(oauth2SchemaArg)
|
|
270
|
+
oauth2: Joi.object(oauth2SchemaArg)
|
|
271
|
+
.allow(false)
|
|
272
|
+
.description('OAuth2 configuration. Set to `false` when the account does not authenticate with OAuth2.')
|
|
273
|
+
.label('OAuth2'),
|
|
264
274
|
|
|
265
275
|
webhooksCustomHeaders: settingsSchema.webhooksCustomHeaders.label('AccountWebhooksCustomHeaders'),
|
|
266
276
|
|
|
@@ -299,7 +309,8 @@ async function init(args) {
|
|
|
299
309
|
state: Joi.string()
|
|
300
310
|
.valid('existing', 'new')
|
|
301
311
|
.example('new')
|
|
302
|
-
.description('
|
|
312
|
+
.description('Whether the account was created or updated. Not present when a redirect URL is returned')
|
|
313
|
+
.meta({ enumDescriptions: ENUM_DESCRIPTIONS.entityState })
|
|
303
314
|
.label('CreateAccountState'),
|
|
304
315
|
redirect: Joi.string()
|
|
305
316
|
.uri()
|
|
@@ -402,9 +413,18 @@ async function init(args) {
|
|
|
402
413
|
proxy: settingsSchema.proxyUrl,
|
|
403
414
|
smtpEhloName: settingsSchema.smtpEhloName,
|
|
404
415
|
|
|
405
|
-
imap: Joi.object(imapUpdateSchema)
|
|
406
|
-
|
|
407
|
-
|
|
416
|
+
imap: Joi.object(imapUpdateSchema)
|
|
417
|
+
.allow(false)
|
|
418
|
+
.description('IMAP configuration. Set to `false` to remove the stored IMAP configuration from the account.')
|
|
419
|
+
.label('IMAPUpdate'),
|
|
420
|
+
smtp: Joi.object(smtpUpdateSchema)
|
|
421
|
+
.allow(false)
|
|
422
|
+
.description('SMTP configuration. Set to `false` to remove the stored SMTP configuration from the account.')
|
|
423
|
+
.label('SMTPUpdate'),
|
|
424
|
+
oauth2: Joi.object(oauth2UpdateSchema)
|
|
425
|
+
.allow(false)
|
|
426
|
+
.description('OAuth2 configuration. Set to `false` to remove the stored OAuth2 configuration from the account.')
|
|
427
|
+
.label('OAuth2Update'),
|
|
408
428
|
|
|
409
429
|
webhooksCustomHeaders: settingsSchema.webhooksCustomHeaders.label('AccountWebhooksCustomHeaders'),
|
|
410
430
|
|
|
@@ -611,6 +631,7 @@ async function init(args) {
|
|
|
611
631
|
|
|
612
632
|
plugins: {
|
|
613
633
|
openapi: {
|
|
634
|
+
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
614
635
|
'x-ee-behavior': [BEHAVIOR.DELETION_SCOPE],
|
|
615
636
|
responses: apiResponses(
|
|
616
637
|
'Returns a deletion marker. The account stops syncing immediately; stored data is removed in the background.',
|
|
@@ -647,9 +668,8 @@ async function init(args) {
|
|
|
647
668
|
.truthy('Y', 'true', '1')
|
|
648
669
|
.falsy('N', 'false', 0)
|
|
649
670
|
.default(false)
|
|
650
|
-
.description(
|
|
651
|
-
|
|
652
|
-
)
|
|
671
|
+
.description('Revoke the upstream OAuth2 grant at the provider before deleting the account')
|
|
672
|
+
.meta({ usage: FIELD_USAGE.revokeGrant })
|
|
653
673
|
})
|
|
654
674
|
},
|
|
655
675
|
|
|
@@ -694,6 +714,7 @@ async function init(args) {
|
|
|
694
714
|
|
|
695
715
|
plugins: {
|
|
696
716
|
openapi: {
|
|
717
|
+
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
697
718
|
'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
|
|
698
719
|
responses: apiResponses(
|
|
699
720
|
'Returns an acknowledgement. Cached message indexes are cleared and rebuilt in the background.',
|
|
@@ -757,7 +778,15 @@ async function init(args) {
|
|
|
757
778
|
timeout: request.headers['x-ee-timeout']
|
|
758
779
|
});
|
|
759
780
|
|
|
760
|
-
|
|
781
|
+
const listing = await accountObject.listAccounts(request.query.state, request.query.query, request.query.page, request.query.pageSize);
|
|
782
|
+
|
|
783
|
+
// The proxy and webhook URLs can carry inline credentials, and the listing returns
|
|
784
|
+
// one of each per account
|
|
785
|
+
for (const entry of listing.accounts || []) {
|
|
786
|
+
maskSecrets(entry);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
return listing;
|
|
761
790
|
} catch (err) {
|
|
762
791
|
handleError(request, err);
|
|
763
792
|
}
|
|
@@ -886,7 +915,7 @@ async function init(args) {
|
|
|
886
915
|
if (accountData[type] && accountData[type].auth) {
|
|
887
916
|
for (let key of ['pass', 'accessToken', 'refreshToken']) {
|
|
888
917
|
if (key in accountData[type].auth) {
|
|
889
|
-
accountData[type].auth[key] =
|
|
918
|
+
accountData[type].auth[key] = MASKED;
|
|
890
919
|
}
|
|
891
920
|
}
|
|
892
921
|
}
|
|
@@ -894,12 +923,17 @@ async function init(args) {
|
|
|
894
923
|
if (accountData[type]) {
|
|
895
924
|
for (let key of ['accessToken', 'refreshToken']) {
|
|
896
925
|
if (key in accountData[type]) {
|
|
897
|
-
accountData[type][key] =
|
|
926
|
+
accountData[type][key] = MASKED;
|
|
898
927
|
}
|
|
899
928
|
}
|
|
900
929
|
}
|
|
901
930
|
}
|
|
902
931
|
|
|
932
|
+
// Credentials for systems other than the mail server, which the loop above does not
|
|
933
|
+
// reach: the proxy and webhook URLs, the webhook headers, and the proxy recorded a
|
|
934
|
+
// second time inside smtpStatus.networkRouting by a failed submission.
|
|
935
|
+
maskSecrets(accountData);
|
|
936
|
+
|
|
903
937
|
let result = {};
|
|
904
938
|
|
|
905
939
|
for (let key of [
|
|
@@ -1007,7 +1041,7 @@ async function init(args) {
|
|
|
1007
1041
|
},
|
|
1008
1042
|
options: {
|
|
1009
1043
|
description: 'Get account info',
|
|
1010
|
-
notes: [
|
|
1044
|
+
notes: [`Returns stored information about the account. ${MASK_NOTE}`, BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
|
|
1011
1045
|
tags: ['api', 'Account'],
|
|
1012
1046
|
|
|
1013
1047
|
plugins: {
|
|
@@ -1117,6 +1151,7 @@ async function init(args) {
|
|
|
1117
1151
|
networkRouting: Joi.object()
|
|
1118
1152
|
.unknown()
|
|
1119
1153
|
.allow(null)
|
|
1154
|
+
.example({ localAddress: '198.51.100.24', name: 'relay.example.com' })
|
|
1120
1155
|
.description('Network routing information for the delivery attempt')
|
|
1121
1156
|
.label('SMTPStatusNetworkRouting')
|
|
1122
1157
|
})
|
|
@@ -1168,17 +1203,20 @@ async function init(args) {
|
|
|
1168
1203
|
syncTime: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('Last sync time (IMAP accounts only)'),
|
|
1169
1204
|
|
|
1170
1205
|
outlookSubscription: Joi.object({
|
|
1171
|
-
id: Joi.string().description('Microsoft Graph subscription ID'),
|
|
1172
|
-
expirationDateTime: Joi.date().iso().allow(null).description('When the subscription expires'),
|
|
1206
|
+
id: Joi.string().example('0fc0f6bb-a3e1-4f7a-9d3a-8e2f1f8b9c11').description('Microsoft Graph subscription ID'),
|
|
1207
|
+
expirationDateTime: Joi.date().iso().allow(null).example('2021-07-11T07:06:34.336Z').description('When the subscription expires'),
|
|
1173
1208
|
state: Joi.object({
|
|
1174
1209
|
state: Joi.string()
|
|
1175
1210
|
.valid('creating', 'created', 'renewing', 'error')
|
|
1176
1211
|
.description('Subscription state')
|
|
1177
1212
|
.meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState }),
|
|
1178
|
-
time: Joi.number().description('Timestamp of last state change'),
|
|
1179
|
-
error: Joi.string()
|
|
1180
|
-
|
|
1181
|
-
|
|
1213
|
+
time: Joi.number().example(1625727994336).description('Timestamp of last state change'),
|
|
1214
|
+
error: Joi.string()
|
|
1215
|
+
.allow(null)
|
|
1216
|
+
.example('Subscription renewal was rejected')
|
|
1217
|
+
.description('Error message if state is error, null after a successful renewal'),
|
|
1218
|
+
retryCount: Joi.number().integer().example(0).description('How many times the subscription renewal has been retried'),
|
|
1219
|
+
createRetryCount: Joi.number().integer().example(0).description('How many times the subscription creation has been retried')
|
|
1182
1220
|
})
|
|
1183
1221
|
.unknown()
|
|
1184
1222
|
.description('Current subscription state')
|
|
@@ -1217,9 +1255,9 @@ async function init(args) {
|
|
|
1217
1255
|
const tokenData = await accountObject.getActiveAccessTokenData();
|
|
1218
1256
|
|
|
1219
1257
|
// Account data stores the OAuth2 app ID as the provider value. Resolve it to the
|
|
1220
|
-
// provider name and expose the app ID separately.
|
|
1221
|
-
// their provider name, so
|
|
1222
|
-
if (tokenData.provider
|
|
1258
|
+
// provider name and expose the app ID separately. Migrated legacy app IDs equal
|
|
1259
|
+
// their provider name, so the lookup is a no-op rename for these.
|
|
1260
|
+
if (tokenData.provider) {
|
|
1223
1261
|
let oauth2App = await oauth2Apps.get(tokenData.provider);
|
|
1224
1262
|
if (oauth2App) {
|
|
1225
1263
|
if (oauth2App.id !== oauth2App.provider) {
|
|
@@ -1469,9 +1507,8 @@ async function init(args) {
|
|
|
1469
1507
|
.allow(null)
|
|
1470
1508
|
.example('example')
|
|
1471
1509
|
.default(null)
|
|
1472
|
-
.description(
|
|
1473
|
-
|
|
1474
|
-
),
|
|
1510
|
+
.description('Account ID. If set to `null`, a unique ID will be generated automatically')
|
|
1511
|
+
.meta({ usage: FIELD_USAGE.accountId }),
|
|
1475
1512
|
|
|
1476
1513
|
name: Joi.string().empty('').max(256).example('My Email Account').description('Display name for the account'),
|
|
1477
1514
|
|
|
@@ -1580,6 +1617,7 @@ async function init(args) {
|
|
|
1580
1617
|
|
|
1581
1618
|
plugins: {
|
|
1582
1619
|
openapi: {
|
|
1620
|
+
'x-ee-impact': IMPACT.READONLY,
|
|
1583
1621
|
responses: apiResponses(
|
|
1584
1622
|
'Returns the outcome of the IMAP and SMTP connection tests, including per-protocol errors when a test failed.',
|
|
1585
1623
|
400,
|
|
@@ -1607,8 +1645,14 @@ async function init(args) {
|
|
|
1607
1645
|
|
|
1608
1646
|
payload: Joi.object({
|
|
1609
1647
|
mailboxes: Joi.boolean().example(false).description('Include mailbox listing in response').default(false).label('IncludeMailboxes'),
|
|
1610
|
-
imap: Joi.object(imapSchema)
|
|
1611
|
-
|
|
1648
|
+
imap: Joi.object(imapSchema)
|
|
1649
|
+
.allow(false)
|
|
1650
|
+
.description('IMAP configuration. Set to `false` when there is no IMAP access to configure.')
|
|
1651
|
+
.label('ImapConfiguration'),
|
|
1652
|
+
smtp: Joi.object(smtpSchema)
|
|
1653
|
+
.allow(false)
|
|
1654
|
+
.description('SMTP configuration. Set to `false` when there is no SMTP access to configure.')
|
|
1655
|
+
.label('SmtpConfiguration'),
|
|
1612
1656
|
proxy: settingsSchema.proxyUrl,
|
|
1613
1657
|
smtpEhloName: settingsSchema.smtpEhloName
|
|
1614
1658
|
}).label('VerifyAccount')
|
|
@@ -1633,7 +1677,9 @@ async function init(args) {
|
|
|
1633
1677
|
let serverSettings = await autodetectImapSettings(request.query.email, request.app.gt);
|
|
1634
1678
|
return serverSettings;
|
|
1635
1679
|
} catch (err) {
|
|
1636
|
-
|
|
1680
|
+
// autodiscovery fails routinely for unknown domains and the handler answers with a
|
|
1681
|
+
// regular "not found" response, so this is not an operator-visible failure
|
|
1682
|
+
request.logger.debug({ msg: 'API request failed', err });
|
|
1637
1683
|
if (Boom.isBoom(err)) {
|
|
1638
1684
|
throw err;
|
|
1639
1685
|
}
|
|
@@ -8,8 +8,8 @@ const getSecret = require('../get-secret');
|
|
|
8
8
|
const { lists } = require('../lists');
|
|
9
9
|
const { failAction } = require('../tools');
|
|
10
10
|
const { handleError } = require('./route-helpers');
|
|
11
|
-
const { accountIdSchema, apiResponses } = require('../schemas');
|
|
12
|
-
const {
|
|
11
|
+
const { accountIdSchema, blocklistListIdSchema, apiResponses } = require('../schemas');
|
|
12
|
+
const { IMPACT } = require('./operation-impact');
|
|
13
13
|
|
|
14
14
|
async function init(args) {
|
|
15
15
|
const { server, call, CORS_CONFIG } = args;
|
|
@@ -28,7 +28,7 @@ async function init(args) {
|
|
|
28
28
|
|
|
29
29
|
options: {
|
|
30
30
|
description: 'List blocklists',
|
|
31
|
-
notes: 'List blocklists with blocked addresses',
|
|
31
|
+
notes: 'List suppression lists (blocklists) with the number of blocked addresses on each',
|
|
32
32
|
tags: ['api', 'Blocklists'],
|
|
33
33
|
|
|
34
34
|
plugins: {
|
|
@@ -98,7 +98,7 @@ async function init(args) {
|
|
|
98
98
|
|
|
99
99
|
options: {
|
|
100
100
|
description: 'List blocklist entries',
|
|
101
|
-
notes: 'List
|
|
101
|
+
notes: 'List suppressed addresses for a list',
|
|
102
102
|
tags: ['api', 'Blocklists'],
|
|
103
103
|
|
|
104
104
|
plugins: {
|
|
@@ -122,12 +122,7 @@ async function init(args) {
|
|
|
122
122
|
failAction,
|
|
123
123
|
|
|
124
124
|
params: Joi.object({
|
|
125
|
-
listId:
|
|
126
|
-
.hostname()
|
|
127
|
-
.example('test-list')
|
|
128
|
-
.description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
|
|
129
|
-
.label('ListID')
|
|
130
|
-
.required()
|
|
125
|
+
listId: blocklistListIdSchema
|
|
131
126
|
}).label('BlocklistListRequest'),
|
|
132
127
|
|
|
133
128
|
query: Joi.object({
|
|
@@ -162,6 +157,7 @@ async function init(args) {
|
|
|
162
157
|
version: ['ipv4', 'ipv6'],
|
|
163
158
|
cidr: 'optional'
|
|
164
159
|
})
|
|
160
|
+
.example('198.51.100.24')
|
|
165
161
|
.description('Which IP address triggered the entry'),
|
|
166
162
|
userAgent: Joi.string().example('Mozilla/5.0 (Macintosh)').description('Which user agent triggered the entry'),
|
|
167
163
|
created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was added or updated').required()
|
|
@@ -190,21 +186,13 @@ async function init(args) {
|
|
|
190
186
|
// throws if account does not exist
|
|
191
187
|
await accountObject.loadAccountData();
|
|
192
188
|
|
|
193
|
-
let added = await
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
request.
|
|
197
|
-
request.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
account: request.payload.account,
|
|
201
|
-
source: 'api',
|
|
202
|
-
reason: request.payload.reason,
|
|
203
|
-
remoteAddress: request.app.ip,
|
|
204
|
-
userAgent: request.headers['user-agent'],
|
|
205
|
-
created: new Date().toISOString()
|
|
206
|
-
})
|
|
207
|
-
);
|
|
189
|
+
let added = await lists.add(request.params.listId, request.payload.recipient, {
|
|
190
|
+
account: request.payload.account,
|
|
191
|
+
source: 'api',
|
|
192
|
+
reason: request.payload.reason,
|
|
193
|
+
remoteAddress: request.app.ip,
|
|
194
|
+
userAgent: request.headers['user-agent']
|
|
195
|
+
});
|
|
208
196
|
|
|
209
197
|
return {
|
|
210
198
|
success: true,
|
|
@@ -216,7 +204,7 @@ async function init(args) {
|
|
|
216
204
|
},
|
|
217
205
|
options: {
|
|
218
206
|
description: 'Add to blocklist',
|
|
219
|
-
notes: 'Add an email address to a
|
|
207
|
+
notes: 'Add an email address to a suppression list. Sending with this listId skips the address',
|
|
220
208
|
tags: ['api', 'Blocklists'],
|
|
221
209
|
|
|
222
210
|
plugins: {
|
|
@@ -240,18 +228,13 @@ async function init(args) {
|
|
|
240
228
|
failAction,
|
|
241
229
|
|
|
242
230
|
params: Joi.object({
|
|
243
|
-
listId:
|
|
244
|
-
.hostname()
|
|
245
|
-
.example('test-list')
|
|
246
|
-
.description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
|
|
247
|
-
.label('ListID')
|
|
248
|
-
.required()
|
|
231
|
+
listId: blocklistListIdSchema
|
|
249
232
|
}).label('BlocklistListRequest'),
|
|
250
233
|
|
|
251
234
|
payload: Joi.object({
|
|
252
235
|
account: accountIdSchema.required(),
|
|
253
236
|
recipient: Joi.string().empty('').email().example('user@example.com').description('Email address to add to the list').required(),
|
|
254
|
-
reason: Joi.string().empty('').default('block').description('Identifier for the blocking reason')
|
|
237
|
+
reason: Joi.string().empty('').default('block').example('unsubscribe').description('Identifier for the blocking reason')
|
|
255
238
|
}).label('BlocklistListAddPayload')
|
|
256
239
|
},
|
|
257
240
|
|
|
@@ -271,19 +254,14 @@ async function init(args) {
|
|
|
271
254
|
|
|
272
255
|
async handler(request) {
|
|
273
256
|
try {
|
|
274
|
-
let exists = await
|
|
257
|
+
let exists = await lists.exists(request.params.listId);
|
|
275
258
|
if (!exists) {
|
|
276
259
|
let message = 'Requested blocklist was not found';
|
|
277
260
|
let error = Boom.boomify(new Error(message), { statusCode: 404 });
|
|
278
261
|
throw error;
|
|
279
262
|
}
|
|
280
263
|
|
|
281
|
-
let deleted = await
|
|
282
|
-
`${REDIS_PREFIX}lists:unsub:lists`,
|
|
283
|
-
`${REDIS_PREFIX}lists:unsub:entries:${request.params.listId}`,
|
|
284
|
-
request.params.listId,
|
|
285
|
-
request.query.recipient.toLowerCase().trim()
|
|
286
|
-
);
|
|
264
|
+
let deleted = await lists.remove(request.params.listId, request.query.recipient);
|
|
287
265
|
|
|
288
266
|
return {
|
|
289
267
|
deleted: !!deleted
|
|
@@ -294,11 +272,12 @@ async function init(args) {
|
|
|
294
272
|
},
|
|
295
273
|
options: {
|
|
296
274
|
description: 'Remove from blocklist',
|
|
297
|
-
notes: '
|
|
275
|
+
notes: 'Remove a suppressed email address from a list',
|
|
298
276
|
tags: ['api', 'Blocklists'],
|
|
299
277
|
|
|
300
278
|
plugins: {
|
|
301
279
|
openapi: {
|
|
280
|
+
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
302
281
|
responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
|
|
303
282
|
}
|
|
304
283
|
},
|
|
@@ -318,12 +297,7 @@ async function init(args) {
|
|
|
318
297
|
failAction,
|
|
319
298
|
|
|
320
299
|
params: Joi.object({
|
|
321
|
-
listId:
|
|
322
|
-
.hostname()
|
|
323
|
-
.example('test-list')
|
|
324
|
-
.description('List ID. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
|
|
325
|
-
.label('ListID')
|
|
326
|
-
.required()
|
|
300
|
+
listId: blocklistListIdSchema
|
|
327
301
|
}).label('BlocklistListRequest'),
|
|
328
302
|
|
|
329
303
|
query: Joi.object({
|
|
@@ -6,8 +6,8 @@ const getSecret = require('../get-secret');
|
|
|
6
6
|
const Boom = require('@hapi/boom');
|
|
7
7
|
const Joi = require('joi');
|
|
8
8
|
const { failAction, getBoolean } = require('../tools');
|
|
9
|
+
const { logApiError } = require('./route-helpers');
|
|
9
10
|
const settings = require('../settings');
|
|
10
|
-
const util = require('util');
|
|
11
11
|
|
|
12
12
|
const LOG_VERBOSE = getBoolean(process.env.EE_OPENAPI_VERBOSE);
|
|
13
13
|
|
|
@@ -37,7 +37,7 @@ async function init(args) {
|
|
|
37
37
|
const { server, call, CORS_CONFIG } = args;
|
|
38
38
|
|
|
39
39
|
async function processChatRequest(opts) {
|
|
40
|
-
let { account, question, index, client } = opts;
|
|
40
|
+
let { account, question, index, client, logger } = opts;
|
|
41
41
|
|
|
42
42
|
// throws if account does not exist
|
|
43
43
|
let accountObject = new Account({ redis, account, call, secret: await getSecret() });
|
|
@@ -323,7 +323,7 @@ async function init(args) {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
if (LOG_VERBOSE) {
|
|
326
|
-
|
|
326
|
+
logger.trace({ msg: 'Chat search result', searchQuery, searchResult });
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
if (searchResult && searchResult.hits && searchResult.hits.hits && searchResult.hits.hits.length) {
|
|
@@ -378,14 +378,15 @@ async function init(args) {
|
|
|
378
378
|
account: request.params.account,
|
|
379
379
|
question: request.payload.question,
|
|
380
380
|
index,
|
|
381
|
-
client
|
|
381
|
+
client,
|
|
382
|
+
logger: request.logger
|
|
382
383
|
});
|
|
383
384
|
} catch (err) {
|
|
384
|
-
|
|
385
|
+
let statusCode = logApiError(request, err);
|
|
385
386
|
if (Boom.isBoom(err)) {
|
|
386
387
|
throw err;
|
|
387
388
|
}
|
|
388
|
-
let error = Boom.boomify(err, { statusCode
|
|
389
|
+
let error = Boom.boomify(err, { statusCode });
|
|
389
390
|
if (err.code) {
|
|
390
391
|
error.output.payload.code = err.code;
|
|
391
392
|
}
|
|
@@ -494,14 +495,11 @@ async function init(args) {
|
|
|
494
495
|
account: request.payload.account,
|
|
495
496
|
question: request.payload.question,
|
|
496
497
|
index,
|
|
497
|
-
client
|
|
498
|
+
client,
|
|
499
|
+
logger: request.logger
|
|
498
500
|
});
|
|
499
501
|
} catch (err) {
|
|
500
|
-
request.logger.error({
|
|
501
|
-
msg: 'Failed posting request',
|
|
502
|
-
command: 'info',
|
|
503
|
-
err
|
|
504
|
-
});
|
|
502
|
+
request.logger.error({ msg: 'Failed to run chat test', err });
|
|
505
503
|
return {
|
|
506
504
|
success: false,
|
|
507
505
|
error: err.message
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Boom = require('@hapi/boom');
|
|
4
3
|
const Joi = require('joi');
|
|
5
4
|
const { fetch: fetchCmd } = require('undici');
|
|
6
5
|
const { redis } = require('../db');
|
|
@@ -12,6 +11,8 @@ const { accountIdSchema, apiResponses } = require('../schemas');
|
|
|
12
11
|
const { REDIS_PREFIX } = require('../consts');
|
|
13
12
|
const packageData = require('../../package.json');
|
|
14
13
|
const BEHAVIOR = require('./behavior-notes');
|
|
14
|
+
const { handleError } = require('./route-helpers');
|
|
15
|
+
const { IMPACT } = require('./operation-impact');
|
|
15
16
|
|
|
16
17
|
async function init(args) {
|
|
17
18
|
const { server, call, CORS_CONFIG, SMTP_TEST_HOST } = args;
|
|
@@ -119,18 +120,7 @@ ${now}`,
|
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
} catch (err) {
|
|
122
|
-
|
|
123
|
-
if (Boom.isBoom(err)) {
|
|
124
|
-
throw err;
|
|
125
|
-
}
|
|
126
|
-
let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
|
|
127
|
-
if (err.code) {
|
|
128
|
-
error.output.payload.code = err.code;
|
|
129
|
-
}
|
|
130
|
-
if (err.details) {
|
|
131
|
-
error.output.payload.details = err.details;
|
|
132
|
-
}
|
|
133
|
-
throw error;
|
|
123
|
+
handleError(request, err);
|
|
134
124
|
}
|
|
135
125
|
},
|
|
136
126
|
options: {
|
|
@@ -140,6 +130,7 @@ ${now}`,
|
|
|
140
130
|
|
|
141
131
|
plugins: {
|
|
142
132
|
openapi: {
|
|
133
|
+
'x-ee-impact': IMPACT.SENDS,
|
|
143
134
|
'x-ee-behavior': [BEHAVIOR.BACKGROUND_JOB],
|
|
144
135
|
responses: apiResponses(
|
|
145
136
|
'Returns the ID of the started deliverability test. Poll the check endpoint for the result.',
|
|
@@ -203,7 +194,7 @@ ${now}`,
|
|
|
203
194
|
path: '/v1/delivery-test/check/{deliveryTest}',
|
|
204
195
|
async handler(request) {
|
|
205
196
|
try {
|
|
206
|
-
request.logger.
|
|
197
|
+
request.logger.debug({ msg: 'Requested SMTP delivery test check', deliveryTest: request.params.deliveryTest });
|
|
207
198
|
|
|
208
199
|
let deliveryStatus = (await redis.hgetall(`${REDIS_PREFIX}test-send:${request.params.deliveryTest}`)) || {};
|
|
209
200
|
if (deliveryStatus.success === 'false') {
|
|
@@ -278,18 +269,7 @@ ${now}`,
|
|
|
278
269
|
|
|
279
270
|
return Object.assign({ success }, testResponse || {});
|
|
280
271
|
} catch (err) {
|
|
281
|
-
|
|
282
|
-
if (Boom.isBoom(err)) {
|
|
283
|
-
throw err;
|
|
284
|
-
}
|
|
285
|
-
let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
|
|
286
|
-
if (err.code) {
|
|
287
|
-
error.output.payload.code = err.code;
|
|
288
|
-
}
|
|
289
|
-
if (err.details) {
|
|
290
|
-
error.output.payload.details = err.details;
|
|
291
|
-
}
|
|
292
|
-
throw error;
|
|
272
|
+
handleError(request, err);
|
|
293
273
|
}
|
|
294
274
|
},
|
|
295
275
|
options: {
|
|
@@ -10,6 +10,7 @@ const getSecret = require('../get-secret');
|
|
|
10
10
|
const { createDecryptStream } = require('../stream-encrypt');
|
|
11
11
|
const { handleError } = require('./route-helpers');
|
|
12
12
|
const BEHAVIOR = require('./behavior-notes');
|
|
13
|
+
const { IMPACT } = require('./operation-impact');
|
|
13
14
|
|
|
14
15
|
async function init(args) {
|
|
15
16
|
const { server, CORS_CONFIG } = args;
|
|
@@ -231,6 +232,7 @@ async function init(args) {
|
|
|
231
232
|
|
|
232
233
|
plugins: {
|
|
233
234
|
openapi: {
|
|
235
|
+
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
234
236
|
responses: apiResponses('Returns a deletion marker. Any partially written export file is removed.', 400, 401, 403, 404, 429, 500)
|
|
235
237
|
}
|
|
236
238
|
},
|