emailengine-app 2.78.0 → 2.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/.ncurc.js +23 -13
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +29 -0
  4. package/config/e2e.toml +2 -1
  5. package/config/test.toml +2 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/lib/account.js +70 -35
  8. package/lib/api-reference/format.js +91 -4
  9. package/lib/api-reference/model.js +144 -19
  10. package/lib/api-reference/schema-tree.js +282 -28
  11. package/lib/api-routes/account-routes.js +80 -34
  12. package/lib/api-routes/blocklist-routes.js +21 -47
  13. package/lib/api-routes/chat-routes.js +10 -12
  14. package/lib/api-routes/delivery-test-routes.js +6 -26
  15. package/lib/api-routes/export-routes.js +2 -0
  16. package/lib/api-routes/gateway-routes.js +52 -11
  17. package/lib/api-routes/license-routes.js +2 -0
  18. package/lib/api-routes/mailbox-routes.js +29 -26
  19. package/lib/api-routes/message-routes.js +27 -21
  20. package/lib/api-routes/oauth2-app-routes.js +11 -29
  21. package/lib/api-routes/operation-impact.js +80 -0
  22. package/lib/api-routes/outbox-routes.js +15 -5
  23. package/lib/api-routes/permission-map.js +397 -0
  24. package/lib/api-routes/route-helpers.js +223 -9
  25. package/lib/api-routes/route-metadata.js +28 -0
  26. package/lib/api-routes/settings-routes.js +30 -25
  27. package/lib/api-routes/stats-routes.js +2 -2
  28. package/lib/api-routes/submit-routes.js +53 -31
  29. package/lib/api-routes/template-routes.js +3 -0
  30. package/lib/api-routes/token-routes.js +319 -33
  31. package/lib/api-routes/webhook-route-routes.js +14 -4
  32. package/lib/auth-token.js +80 -8
  33. package/lib/consts.js +10 -0
  34. package/lib/db.js +20 -2
  35. package/lib/delivery-error.js +30 -1
  36. package/lib/email-client/base-client.js +27 -41
  37. package/lib/email-client/gmail-client.js +19 -10
  38. package/lib/email-client/imap/mailbox.js +23 -24
  39. package/lib/email-client/imap/subconnection.js +10 -7
  40. package/lib/email-client/imap/sync-operations.js +46 -46
  41. package/lib/email-client/imap-client.js +36 -26
  42. package/lib/email-client/message-builder.js +3 -3
  43. package/lib/email-client/notification-handler.js +1 -1
  44. package/lib/email-client/outlook/graph-api.js +10 -4
  45. package/lib/email-client/outlook-client.js +53 -54
  46. package/lib/email-client/smtp-pool-manager.js +1 -1
  47. package/lib/enum-descriptions.js +92 -2
  48. package/lib/export.js +1 -1
  49. package/lib/field-usage.js +133 -0
  50. package/lib/gateway.js +1 -1
  51. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  52. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  53. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  54. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  55. package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
  56. package/lib/imapproxy/imap-server.js +27 -7
  57. package/lib/license-beacon.js +4 -9
  58. package/lib/lists.js +49 -1
  59. package/lib/llm-pre-process.js +5 -5
  60. package/lib/logger.js +5 -1
  61. package/lib/metrics-collector.js +2 -2
  62. package/lib/oauth/gmail.js +9 -12
  63. package/lib/oauth/mail-ru.js +5 -7
  64. package/lib/oauth/outlook.js +9 -9
  65. package/lib/oauth/pubsub/google.js +25 -10
  66. package/lib/oauth/scope-checker.js +1 -1
  67. package/lib/oauth2-apps.js +223 -294
  68. package/lib/openapi/build-document.js +15 -7
  69. package/lib/openapi/joi-schema.js +20 -0
  70. package/lib/outbox.js +85 -17
  71. package/lib/pre-process.js +8 -8
  72. package/lib/queue-stats.js +49 -0
  73. package/lib/read-env-value.js +1 -1
  74. package/lib/reconnection-manager.js +2 -2
  75. package/lib/rewrite-text-nodes.js +4 -3
  76. package/lib/routes-ui.js +4 -0
  77. package/lib/schemas.js +216 -160
  78. package/lib/settings.js +84 -5
  79. package/lib/sub-script.js +2 -1
  80. package/lib/swagger-options.js +2 -1
  81. package/lib/templates.js +4 -4
  82. package/lib/threads.js +2 -2
  83. package/lib/token-audit-log.js +208 -0
  84. package/lib/token-permission-view.js +219 -0
  85. package/lib/token-permissions.js +172 -0
  86. package/lib/tokens.js +99 -15
  87. package/lib/tools.js +142 -37
  88. package/lib/ui-routes/account-routes.js +31 -11
  89. package/lib/ui-routes/admin-config-routes.js +18 -10
  90. package/lib/ui-routes/admin-entities-routes.js +66 -22
  91. package/lib/ui-routes/auth-routes.js +30 -24
  92. package/lib/ui-routes/export-routes.js +10 -4
  93. package/lib/ui-routes/oauth-config-routes.js +5 -5
  94. package/lib/ui-routes/reference-routes.js +3 -3
  95. package/lib/ui-routes/route-helpers.js +51 -2
  96. package/lib/ui-routes/settings-page.js +1 -1
  97. package/lib/ui-routes/smtp-test-routes.js +1 -1
  98. package/lib/ui-routes/suppression-list-routes.js +294 -0
  99. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  100. package/lib/utils/network.js +2 -2
  101. package/lib/web-safe-html.js +1 -1
  102. package/lib/webhook-routing.js +80 -0
  103. package/lib/webhooks.js +20 -14
  104. package/package.json +11 -10
  105. package/sbom.json +1 -1
  106. package/server.js +80 -41
  107. package/static/css/flyonui.css +1 -1
  108. package/static/css/src/app.tailwind.css +136 -9
  109. package/static/js/reference.js +456 -10
  110. package/static/js/ui.js +43 -0
  111. package/static/licenses.html +51 -41
  112. package/translations/messages.pot +59 -59
  113. package/views/accounts/account.hbs +69 -7
  114. package/views/accounts/browse.hbs +18 -35
  115. package/views/config/logging.hbs +6 -0
  116. package/views/config/oauth/app.hbs +0 -2
  117. package/views/config/security.hbs +13 -0
  118. package/views/partials/oauth_form.hbs +0 -15
  119. package/views/partials/reference/disclosure.hbs +8 -2
  120. package/views/partials/reference/operation.hbs +47 -13
  121. package/views/partials/reference/params.hbs +17 -1
  122. package/views/partials/reference/schema-node.hbs +110 -52
  123. package/views/partials/reference/schema-tools.hbs +25 -0
  124. package/views/partials/reference/try-it.hbs +84 -11
  125. package/views/partials/side_menu.hbs +1 -0
  126. package/views/partials/ui/checkbox.hbs +2 -2
  127. package/views/partials/ui/tabs.hbs +7 -1
  128. package/views/reference/token.hbs +4 -0
  129. package/views/suppression-lists/index.hbs +85 -0
  130. package/views/suppression-lists/list.hbs +87 -0
  131. package/views/templates/index.hbs +8 -2
  132. package/views/tokens/index.hbs +31 -4
  133. package/views/tokens/new.hbs +324 -2
  134. package/workers/api.js +146 -57
  135. package/workers/documents.js +46 -26
  136. package/workers/export.js +20 -8
  137. package/workers/imap-proxy.js +2 -2
  138. package/workers/imap.js +12 -6
  139. package/workers/smtp.js +13 -7
  140. package/workers/submit.js +40 -30
  141. package/workers/webhooks.js +59 -25
  142. package/lib/feature-flags.js +0 -48
@@ -5,8 +5,10 @@ const { redis } = require('../db');
5
5
  const { Gateway } = require('../gateway');
6
6
  const getSecret = require('../get-secret');
7
7
  const { failAction } = require('../tools');
8
- const { handleError } = require('./route-helpers');
8
+ const { handleError, maskSecrets, MASKED, MASK_NOTE } = require('./route-helpers');
9
9
  const { apiResponses } = require('../schemas');
10
+ const { ENUM_DESCRIPTIONS } = require('../enum-descriptions');
11
+ const { IMPACT } = require('./operation-impact');
10
12
 
11
13
  // Gateways store SMTP delivery errors, not OAuth2 errors, so the error shape differs from the
12
14
  // account-level lastErrorSchema
@@ -18,7 +20,12 @@ const gatewayLastErrorSchema = Joi.object({
18
20
  code: Joi.string().example('EAUTH').description('Error type identifier'),
19
21
  command: Joi.string().example('AUTH PLAIN').description('SMTP command that failed'),
20
22
  description: Joi.string().example('Authentication failed').description('Error description'),
21
- networkRouting: Joi.object().unknown().allow(null).description('Network routing information for the delivery attempt').label('GatewayErrorNetworkRouting')
23
+ networkRouting: Joi.object()
24
+ .unknown()
25
+ .allow(null)
26
+ .example({ localAddress: '198.51.100.24', name: 'relay.example.com' })
27
+ .description('Network routing information for the delivery attempt')
28
+ .label('GatewayErrorNetworkRouting')
22
29
  })
23
30
  .unknown()
24
31
  .description('Information about the last failed delivery attempt using this gateway')
@@ -35,7 +42,13 @@ async function init(args) {
35
42
  try {
36
43
  let gatewayObject = new Gateway({ redis, gateway: request.params.gateway, call, secret: await getSecret() });
37
44
 
38
- return await gatewayObject.listGateways(request.query.page, request.query.pageSize);
45
+ const listing = await gatewayObject.listGateways(request.query.page, request.query.pageSize);
46
+
47
+ for (const entry of listing.gateways || []) {
48
+ maskSecrets(entry);
49
+ }
50
+
51
+ return listing;
39
52
  } catch (err) {
40
53
  handleError(request, err);
41
54
  }
@@ -117,9 +130,13 @@ async function init(args) {
117
130
 
118
131
  // remove secrets
119
132
  if (gatewayData.pass) {
120
- gatewayData.pass = '******';
133
+ gatewayData.pass = MASKED;
121
134
  }
122
135
 
136
+ // A failed delivery records the proxy it used under lastError.networkRouting, which
137
+ // is projected below - the password beside it was already masked
138
+ maskSecrets(gatewayData);
139
+
123
140
  let result = {};
124
141
 
125
142
  for (let key of ['gateway', 'name', 'host', 'port', 'user', 'pass', 'secure', 'deliveries', 'lastUse', 'lastError']) {
@@ -135,7 +152,7 @@ async function init(args) {
135
152
  },
136
153
  options: {
137
154
  description: 'Get gateway info',
138
- notes: 'Returns stored information about the gateway. Passwords are not included.',
155
+ notes: `Returns stored information about the gateway. ${MASK_NOTE}`,
139
156
  tags: ['api', 'SMTP Gateway'],
140
157
 
141
158
  plugins: {
@@ -175,10 +192,18 @@ async function init(args) {
175
192
  .example('2021-02-17T13:43:18.860Z')
176
193
  .description('Last delivery time. Null for gateways that have not been used yet'),
177
194
 
178
- user: Joi.string().empty('').trim().allow(null).max(1024).description('SMTP authentication username').label('UserName'),
195
+ user: Joi.string()
196
+ .empty('')
197
+ .trim()
198
+ .allow(null)
199
+ .max(1024)
200
+ .example('smtp-user')
201
+ .description('SMTP authentication username')
202
+ .label('UserName'),
179
203
  pass: Joi.string()
180
204
  .empty('')
181
205
  .max(1024)
206
+ .example('******')
182
207
  .description('SMTP authentication password. Always returned as the masked value "******" when a password is set')
183
208
  .label('Password'),
184
209
 
@@ -252,8 +277,15 @@ async function init(args) {
252
277
 
253
278
  name: Joi.string().empty('').max(256).example('John Smith').description('Account Name').label('Gateway Name').required(),
254
279
 
255
- user: Joi.string().empty('').trim().default(null).max(1024).description('SMTP authentication username').label('UserName'),
256
- pass: Joi.string().empty('').max(1024).default(null).description('SMTP authentication password').label('Password'),
280
+ user: Joi.string()
281
+ .empty('')
282
+ .trim()
283
+ .default(null)
284
+ .max(1024)
285
+ .example('smtp-user')
286
+ .description('SMTP authentication username')
287
+ .label('UserName'),
288
+ pass: Joi.string().empty('').max(1024).default(null).example('verysecret').description('SMTP authentication password').label('Password'),
257
289
 
258
290
  host: Joi.string().hostname().example('smtp.gmail.com').description('Hostname to connect to').label('Hostname').required(),
259
291
  port: Joi.number()
@@ -282,7 +314,8 @@ async function init(args) {
282
314
  .required()
283
315
  .valid('existing', 'new')
284
316
  .example('new')
285
- .description('Is the gateway new or updated existing')
317
+ .description('Whether the gateway was created or updated')
318
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.entityState })
286
319
  .label('CreateGatewayState')
287
320
  }).label('CreateGatewayResponse'),
288
321
  failAction: 'log'
@@ -335,8 +368,15 @@ async function init(args) {
335
368
  payload: Joi.object({
336
369
  name: Joi.string().empty('').max(256).example('John Smith').description('Account Name').label('Gateway Name'),
337
370
 
338
- user: Joi.string().empty('').trim().max(1024).allow(null).description('SMTP authentication username').label('UserName'),
339
- pass: Joi.string().empty('').max(1024).allow(null).description('SMTP authentication password').label('Password'),
371
+ user: Joi.string()
372
+ .empty('')
373
+ .trim()
374
+ .max(1024)
375
+ .allow(null)
376
+ .example('smtp-user')
377
+ .description('SMTP authentication username')
378
+ .label('UserName'),
379
+ pass: Joi.string().empty('').max(1024).allow(null).example('verysecret').description('SMTP authentication password').label('Password'),
340
380
 
341
381
  host: Joi.string().hostname().empty('').example('smtp.gmail.com').description('Hostname to connect to').label('Hostname'),
342
382
  port: Joi.number()
@@ -390,6 +430,7 @@ async function init(args) {
390
430
 
391
431
  plugins: {
392
432
  openapi: {
433
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
393
434
  responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
394
435
  }
395
436
  },
@@ -4,6 +4,7 @@ const Joi = require('joi');
4
4
  const { failAction } = require('../tools');
5
5
  const { handleError } = require('./route-helpers');
6
6
  const { licenseSchema, apiResponses } = require('../schemas');
7
+ const { IMPACT } = require('./operation-impact');
7
8
 
8
9
  async function init(args) {
9
10
  const { server, call, CORS_CONFIG } = args;
@@ -73,6 +74,7 @@ async function init(args) {
73
74
 
74
75
  plugins: {
75
76
  openapi: {
77
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
76
78
  responses: apiResponses('Returns an empty license object. EmailEngine drops to limited mode.', 401, 403, 429, 500)
77
79
  }
78
80
  },
@@ -6,8 +6,31 @@ const { redis } = require('../db');
6
6
  const { Account } = require('../account');
7
7
  const getSecret = require('../get-secret');
8
8
  const { failAction } = require('../tools');
9
- const { handleError } = require('./route-helpers');
9
+ const { handleError, logApiError } = require('./route-helpers');
10
10
  const { accountIdSchema, mailboxesSchema, apiResponses } = require('../schemas');
11
+ const { IMPACT } = require('./operation-impact');
12
+ const { FIELD_USAGE } = require('../field-usage');
13
+
14
+ // The create and modify routes publish err.info as `details`, which is the field their documented
15
+ // error schema declares, while the shared handleError publishes it as `info`. They keep their own
16
+ // envelope rather than fork the logging policy, so routing them through handleError would silently
17
+ // rename a published response field. Always throws, like handleError.
18
+ function throwMailboxError(request, err) {
19
+ let statusCode = logApiError(request, err);
20
+
21
+ if (Boom.isBoom(err)) {
22
+ throw err;
23
+ }
24
+
25
+ let error = Boom.boomify(err, { statusCode });
26
+ if (err.code) {
27
+ error.output.payload.code = err.code;
28
+ }
29
+ if (err.info) {
30
+ error.output.payload.details = err.info;
31
+ }
32
+ throw error;
33
+ }
11
34
 
12
35
  async function init(args) {
13
36
  const { server, call, CORS_CONFIG, FLAG_SORT_ORDER } = args;
@@ -123,18 +146,7 @@ async function init(args) {
123
146
  try {
124
147
  return await accountObject.createMailbox(request.payload.path);
125
148
  } catch (err) {
126
- request.logger.error({ msg: 'API request failed', err });
127
- if (Boom.isBoom(err)) {
128
- throw err;
129
- }
130
- let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
131
- if (err.code) {
132
- error.output.payload.code = err.code;
133
- }
134
- if (err.info) {
135
- error.output.payload.details = err.info;
136
- }
137
- throw error;
149
+ throwMailboxError(request, err);
138
150
  }
139
151
  },
140
152
 
@@ -204,18 +216,7 @@ async function init(args) {
204
216
  try {
205
217
  return await accountObject.modifyMailbox(request.payload.path, request.payload.newPath, request.payload.subscribed);
206
218
  } catch (err) {
207
- request.logger.error({ msg: 'API request failed', err });
208
- if (Boom.isBoom(err)) {
209
- throw err;
210
- }
211
- let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
212
- if (err.code) {
213
- error.output.payload.code = err.code;
214
- }
215
- if (err.info) {
216
- error.output.payload.details = err.info;
217
- }
218
- throw error;
219
+ throwMailboxError(request, err);
219
220
  }
220
221
  },
221
222
 
@@ -258,7 +259,8 @@ async function init(args) {
258
259
  .label('TargetMailboxPath'),
259
260
  subscribed: Joi.boolean()
260
261
  .example(true)
261
- .description('Change mailbox subscription status. Only applies to IMAP accounts, ignored for Gmail and Outlook.')
262
+ .description('Change mailbox subscription status')
263
+ .meta({ usage: FIELD_USAGE.mailboxSubscribed })
262
264
  .label('SubscriptionStatus')
263
265
  })
264
266
  .or('newPath', 'subscribed')
@@ -308,6 +310,7 @@ async function init(args) {
308
310
 
309
311
  plugins: {
310
312
  openapi: {
313
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
311
314
  responses: apiResponses('Returns the deleted folder path.', 400, 401, 403, 404, 429, 500, 503)
312
315
  }
313
316
  },
@@ -6,9 +6,10 @@ const getSecret = require('../get-secret');
6
6
  const settings = require('../settings');
7
7
  const Joi = require('joi');
8
8
  const { failAction } = require('../tools');
9
- const { COLLAPSE_CLASS } = require('../consts');
10
9
  const { handleError } = require('./route-helpers');
11
10
  const BEHAVIOR = require('./behavior-notes');
11
+ const { IMPACT } = require('./operation-impact');
12
+ const { FIELD_USAGE } = require('../field-usage');
12
13
 
13
14
  const {
14
15
  accountIdSchema,
@@ -31,11 +32,19 @@ const {
31
32
  const listMessageFolderPathDescription =
32
33
  'Mailbox folder path. Can use special use labels like "\\Sent". Special value "\\All" is available for Gmail IMAP, Gmail API, MS Graph API accounts.';
33
34
 
35
+ // One entry of the array branch below. The operation's own example is a boolean for flags,
36
+ // so the array branch has nothing to inherit from and its entries used to document
37
+ // themselves as "string" - see the example coverage assertion in test/api-reference-test.js.
38
+ const UPDATE_OP_ENTRY_EXAMPLE = {
39
+ flags: '\\Seen',
40
+ labels: 'Label_971539351003152516'
41
+ };
42
+
34
43
  // Response field for a flag or label update operation. IMAP accounts return a boolean (whether
35
44
  // the operation succeeded), API-based accounts echo the requested values as an array.
36
45
  const updateOpResultSchema = (op, noun, entryLabel, example, label) =>
37
46
  Joi.alternatives()
38
- .try(Joi.boolean(), Joi.array().items(Joi.string().label(entryLabel)))
47
+ .try(Joi.boolean(), Joi.array().items(Joi.string().label(entryLabel).example(UPDATE_OP_ENTRY_EXAMPLE[noun])))
39
48
  .example(example)
40
49
  .description(`Did the ${op} operation succeed (boolean, IMAP accounts) or the requested ${noun} (array, API-based accounts)`)
41
50
  .label(label);
@@ -179,10 +188,8 @@ async function init(args) {
179
188
  .truthy('Y', 'true', '1')
180
189
  .falsy('N', 'false', 0)
181
190
  .default(false)
182
- .description(
183
- 'Shorthand option to fetch and preprocess HTML and inline images. Overrides `textType`, `preProcessHtml`, and `embedAttachedImages` options. ' +
184
- `Quoted thread history is folded into a single collapsed <details class="${COLLAPSE_CLASS}"> element.`
185
- )
191
+ .description('Shorthand option to fetch and preprocess HTML and inline images')
192
+ .meta({ usage: FIELD_USAGE.webSafeHtml })
186
193
  .label('WebSafeHtml'),
187
194
 
188
195
  embedAttachedImages: Joi.boolean()
@@ -289,9 +296,8 @@ async function init(args) {
289
296
  .base64()
290
297
  .max(MAX_ATTACHMENT_SIZE)
291
298
  .example('TUlNRS1WZXJzaW9uOiAxLjANClN1YmplY3Q6IGhlbGxvIHdvcmxkDQoNCkhlbGxvIQ0K')
292
- .description(
293
- 'A Base64-encoded email message in RFC 822 format. If you provide other fields along with raw, those fields will override the corresponding values in the raw message.'
294
- )
299
+ .description('A Base64-encoded email message in RFC 822 format')
300
+ .meta({ usage: FIELD_USAGE.messageRaw })
295
301
  .label('RFC822Raw'),
296
302
 
297
303
  from: fromAddressSchema,
@@ -347,9 +353,8 @@ async function init(args) {
347
353
  .max(256)
348
354
  .allow(false, null)
349
355
  .example('AAAAAQAACnAcde')
350
- .description(
351
- 'References an existing attachment by its ID instead of providing new attachment content. If this field is set, the `content` field must not be included. If not set, the `content` field is required.'
352
- )
356
+ .description('References an existing attachment by its ID instead of providing new attachment content')
357
+ .meta({ usage: FIELD_USAGE.attachmentReference })
353
358
  .label('MsgUploadReference')
354
359
  }).label('UploadAttachment')
355
360
  )
@@ -747,6 +752,7 @@ async function init(args) {
747
752
 
748
753
  plugins: {
749
754
  openapi: {
755
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
750
756
  'x-ee-behavior': [BEHAVIOR.GMAIL_DELETE_IS_TRASH],
751
757
  responses: apiResponses('Returns whether the message was moved to Trash or permanently deleted.', 400, 401, 403, 404, 429, 500, 503)
752
758
  }
@@ -832,6 +838,7 @@ async function init(args) {
832
838
 
833
839
  plugins: {
834
840
  openapi: {
841
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
835
842
  'x-ee-behavior': [BEHAVIOR.GMAIL_DELETE_IS_TRASH],
836
843
  responses: apiResponses('Returns the number of messages deleted.', 400, 401, 403, 404, 429, 500, 503)
837
844
  }
@@ -971,9 +978,8 @@ async function init(args) {
971
978
  .max(1024 * 1024)
972
979
  .default(0)
973
980
  .example(0)
974
- .description(
975
- 'Page number (zero-indexed, so use 0 for the first page). Only supported for IMAP accounts. Deprecated; use the paging cursor instead. If the page cursor value is provided, then the page number value is ignored.'
976
- )
981
+ .description('Page number (zero-indexed, so use 0 for the first page). Only supported for IMAP accounts')
982
+ .meta({ usage: FIELD_USAGE.messagePage })
977
983
  .label('PageNumber'),
978
984
 
979
985
  pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page').label('PageSize'),
@@ -1038,6 +1044,7 @@ async function init(args) {
1038
1044
 
1039
1045
  plugins: {
1040
1046
  openapi: {
1047
+ 'x-ee-impact': IMPACT.READONLY,
1041
1048
  responses: apiResponses('Returns a page of matching messages, newest first.', 400, 401, 403, 404, 422, 429, 500, 503)
1042
1049
  }
1043
1050
  },
@@ -1084,9 +1091,8 @@ async function init(args) {
1084
1091
  .max(1024 * 1024)
1085
1092
  .default(0)
1086
1093
  .example(0)
1087
- .description(
1088
- 'Page number (zero-indexed, so use 0 for the first page). Only supported for IMAP accounts. Deprecated; use the paging cursor instead. If the page cursor value is provided, then the page number value is ignored.'
1089
- )
1094
+ .description('Page number (zero-indexed, so use 0 for the first page). Only supported for IMAP accounts')
1095
+ .meta({ usage: FIELD_USAGE.messagePage })
1090
1096
  .label('PageNumber'),
1091
1097
 
1092
1098
  pageSize: Joi.number().integer().min(1).max(1000).default(20).example(20).description('How many entries per page'),
@@ -1094,9 +1100,8 @@ async function init(args) {
1094
1100
  useOutlookSearch: Joi.boolean()
1095
1101
  .truthy('Y', 'true', '1')
1096
1102
  .falsy('N', 'false', 0)
1097
- .description(
1098
- 'MS Graph only. If enabled, uses the $search parameter for MS Graph search queries instead of $filter. This allows searching the "to", "cc", "bcc", "larger", "smaller", "body", "before", "sentBefore", "since", and the "sentSince" fields. Note that $search returns up to 1,000 results, does not indicate the total number of matching results or pages, and returns results sorted by relevance rather than date. The "labels" filter is not available in this mode - leave this option disabled to filter by category.'
1099
- )
1103
+ .description('MS Graph only. Use the $search parameter for search queries instead of $filter')
1104
+ .meta({ usage: FIELD_USAGE.useOutlookSearch })
1100
1105
  .label('useOutlookSearch')
1101
1106
  .optional(),
1102
1107
 
@@ -1205,6 +1210,7 @@ async function init(args) {
1205
1210
 
1206
1211
  plugins: {
1207
1212
  openapi: {
1213
+ 'x-ee-impact': IMPACT.READONLY,
1208
1214
  responses: apiResponses('Returns matching messages across all indexed accounts.', 400, 401, 403, 429, 500)
1209
1215
  }
1210
1216
  },
@@ -15,8 +15,9 @@ const {
15
15
  apiResponses,
16
16
  ENUM_DESCRIPTIONS
17
17
  } = require('../schemas');
18
- const { handleError, throwNotFound, flattenOAuthAppMeta } = require('./route-helpers');
18
+ const { handleError, throwNotFound, flattenOAuthAppMeta, MASKED } = require('./route-helpers');
19
19
  const { ENCRYPTED_APP_KEYS } = require('../consts');
20
+ const { IMPACT } = require('./operation-impact');
20
21
 
21
22
  // Stored fields that are returned on OAuth2 application objects in addition to the basic fields
22
23
  const oauth2AppExtraFields = {
@@ -73,7 +74,7 @@ async function init(args) {
73
74
  for (let app of response.apps) {
74
75
  for (let secretKey of ENCRYPTED_APP_KEYS) {
75
76
  if (app[secretKey]) {
76
- app[secretKey] = '******';
77
+ app[secretKey] = MASKED;
77
78
  }
78
79
  }
79
80
 
@@ -152,15 +153,7 @@ async function init(args) {
152
153
  .example(true)
153
154
  .description('Is the application enabled')
154
155
  .label('AppEnabled'),
155
- legacy: Joi.boolean()
156
- .truthy('Y', 'true', '1', 'on')
157
- .falsy('N', 'false', 0, '')
158
- .example(true)
159
- .description('`true` for older OAuth2 apps set via the settings endpoint'),
160
- created: Joi.date()
161
- .iso()
162
- .example('2021-02-17T13:43:18.860Z')
163
- .description('The time this entry was added. Not present for legacy apps'),
156
+ created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was added'),
164
157
  updated: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was updated'),
165
158
  includeInListing: Joi.boolean()
166
159
  .truthy('Y', 'true', '1', 'on')
@@ -231,7 +224,7 @@ async function init(args) {
231
224
  // remove secrets
232
225
  for (let secretKey of ENCRYPTED_APP_KEYS) {
233
226
  if (app[secretKey]) {
234
- app[secretKey] = '******';
227
+ app[secretKey] = MASKED;
235
228
  }
236
229
  }
237
230
 
@@ -293,12 +286,7 @@ async function init(args) {
293
286
  .example(true)
294
287
  .description('Is the application enabled')
295
288
  .label('AppEnabled'),
296
- legacy: Joi.boolean()
297
- .truthy('Y', 'true', '1', 'on')
298
- .falsy('N', 'false', 0, '')
299
- .example(true)
300
- .description('`true` for older OAuth2 apps set via the settings endpoint'),
301
- created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was added. Not present for legacy apps'),
289
+ created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was added'),
302
290
  updated: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this entry was updated'),
303
291
  includeInListing: Joi.boolean()
304
292
  .truthy('Y', 'true', '1', 'on')
@@ -340,10 +328,7 @@ async function init(args) {
340
328
  .example('******')
341
329
  .description('PEM formatted service secret for 2-legged OAuth2 applications. Actual value is not revealed.'),
342
330
 
343
- accounts: Joi.number()
344
- .integer()
345
- .example(12)
346
- .description('The number of accounts registered with this application. Not available for legacy apps.'),
331
+ accounts: Joi.number().integer().example(12).description('The number of accounts registered with this application'),
347
332
 
348
333
  ...oauth2AppExtraFields,
349
334
 
@@ -543,8 +528,7 @@ async function init(args) {
543
528
  response: {
544
529
  schema: Joi.object({
545
530
  id: Joi.string().max(256).required().example('example').description('OAuth2 app ID'),
546
- updated: Joi.boolean().example(true).description('Was the application updated'),
547
- legacy: Joi.boolean().example(false).description('`true` for older OAuth2 apps set via the settings endpoint')
531
+ updated: Joi.boolean().example(true).description('Was the application updated')
548
532
  }).label('UpdateOAuthAppResponse'),
549
533
  failAction: 'log'
550
534
  }
@@ -577,6 +561,7 @@ async function init(args) {
577
561
 
578
562
  plugins: {
579
563
  openapi: {
564
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
580
565
  responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
581
566
  }
582
567
  },
@@ -604,11 +589,7 @@ async function init(args) {
604
589
  schema: Joi.object({
605
590
  id: Joi.string().max(256).required().example('AAABhaBPHscAAAAH').description('OAuth2 application ID'),
606
591
  deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the OAuth2 application deleted'),
607
- legacy: Joi.boolean().example(false).description('`true` for older OAuth2 apps set via the settings endpoint'),
608
- accounts: Joi.number()
609
- .integer()
610
- .example(12)
611
- .description('The number of accounts registered with this application. Not available for legacy apps.')
592
+ accounts: Joi.number().integer().example(12).description('The number of accounts registered with this application')
612
593
  }).label('DeleteAppRequestResponse'),
613
594
  failAction: 'log'
614
595
  }
@@ -636,6 +617,7 @@ async function init(args) {
636
617
 
637
618
  plugins: {
638
619
  openapi: {
620
+ 'x-ee-impact': IMPACT.READONLY,
639
621
  responses: apiResponses('Returns the outcome of the credential check against the provider.', 400, 401, 403, 404, 429, 500)
640
622
  }
641
623
  },
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ // What running an operation actually does to the instance. Declared per route under
4
+ // `plugins.openapi['x-ee-impact']`, which the generator publishes verbatim (see
5
+ // assignVendorExtensions in lib/openapi/build-document.js), so the classification reaches every
6
+ // consumer of /swagger.json and not just the admin UI.
7
+ //
8
+ // It exists because the Try it panel used to carry the same warning on all 82 operations -
9
+ // including 42 that only read - which is how a warning teaches readers to skim past it. The
10
+ // weight of the warning now tracks the consequence: nothing on a read, a muted line on an
11
+ // ordinary write, and a real warning on the operations that destroy data or send mail.
12
+ //
13
+ // Only the exceptions are declared. resolveImpact() derives the default from the HTTP method, so
14
+ // a plain GET needs nothing and a POST that writes needs nothing. Declare an impact when the
15
+ // method is a bad proxy for the effect, which is both directions here:
16
+ // `POST /v1/unified/search` only reads, and `PUT /v1/account/{account}/messages/delete`
17
+ // deletes in bulk.
18
+ //
19
+ // The derivation lives here rather than in the one place that reads it today because it is about
20
+ // to have a second reader. lib/api-reference/model.js weights the Try it warning by it; the token
21
+ // permission model narrows on the same value. A route classified one way for the warning banner
22
+ // and another way for access control is a divergence nothing would catch, so both call this.
23
+ const IMPACT = {
24
+ // Removes data, or discards state that cannot be recovered from EmailEngine
25
+ DESTRUCTIVE: 'destructive',
26
+
27
+ // Hands a message to a mail server. Whatever else happens, mail leaves the instance and
28
+ // reaches real recipients - the one Try it consequence that is not undoable from here.
29
+ SENDS: 'sends',
30
+
31
+ // Reads only, despite not being a GET
32
+ READONLY: 'readonly',
33
+
34
+ // What an undeclared non-GET resolves to. Derived rather than declared, so it is absent from
35
+ // DECLARABLE below, but the consumers that switch on an impact still need a name for it.
36
+ WRITE: 'write'
37
+ };
38
+
39
+ // What a route may put in `x-ee-impact`. WRITE is deliberately excluded: it is the default, so
40
+ // declaring it says nothing, and treating it as valid input would mean two spellings of the same
41
+ // classification. Exported because test/api-reference-test.js asserts what the routes declare and
42
+ // has no business keeping its own copy of the vocabulary.
43
+ const DECLARABLE_IMPACTS = new Set([IMPACT.DESTRUCTIVE, IMPACT.SENDS, IMPACT.READONLY]);
44
+
45
+ /**
46
+ * Resolves an operation's impact from what it declares plus its HTTP method.
47
+ *
48
+ * Returns null when `declared` is not a declarable impact. That is a typo in a route definition
49
+ * rather than a fourth kind of impact, and guessing would hide it: a route meaning `destructive`
50
+ * but spelling it `deletes` would silently resolve to the method default and lose its warning.
51
+ * Callers decide what null means for them - the reference page renders no warning, which is what
52
+ * it did before this function existed.
53
+ *
54
+ * @param {String} [declared] - the route's `x-ee-impact`, if it sets one
55
+ * @param {String} method - HTTP method, in any case
56
+ * @returns {String|null} one of IMPACT, or null when `declared` is not declarable
57
+ */
58
+ function resolveImpact(declared, method) {
59
+ if (declared) {
60
+ return DECLARABLE_IMPACTS.has(declared) ? declared : null;
61
+ }
62
+
63
+ switch (String(method).toLowerCase()) {
64
+ case 'get':
65
+ return IMPACT.READONLY;
66
+
67
+ // A DELETE removes something. Defaulting it to WRITE made `destructive` opt-in, which is
68
+ // fail-open now that a token can be narrowed to "write but not destructive": a new DELETE
69
+ // that forgot its declaration would resolve to WRITE and be callable by a token explicitly
70
+ // issued without destructive rights. Every DELETE today declares IMPACT.DESTRUCTIVE, so
71
+ // this changes no current classification - it removes the way the next one could go wrong.
72
+ case 'delete':
73
+ return IMPACT.DESTRUCTIVE;
74
+
75
+ default:
76
+ return IMPACT.WRITE;
77
+ }
78
+ }
79
+
80
+ module.exports = { IMPACT, DECLARABLE_IMPACTS, resolveImpact };
@@ -5,8 +5,9 @@ const Joi = require('joi');
5
5
  const logger = require('../logger');
6
6
  const outbox = require('../outbox');
7
7
  const { failAction } = require('../tools');
8
- const { handleError } = require('./route-helpers');
8
+ const { handleError, maskSecrets, MASK_NOTE } = require('./route-helpers');
9
9
  const { outboxEntrySchema, apiResponses } = require('../schemas');
10
+ const { IMPACT } = require('./operation-impact');
10
11
 
11
12
  async function init(args) {
12
13
  const { server, CORS_CONFIG } = args;
@@ -17,7 +18,15 @@ async function init(args) {
17
18
 
18
19
  async handler(request) {
19
20
  try {
20
- return await outbox.list(Object.assign({ logger }, request.query));
21
+ const listing = await outbox.list(Object.assign({ logger }, request.query));
22
+
23
+ // A queue entry carries the proxy the submission was told to use, and a failed one
24
+ // also records the route it took under progress.error.networkRouting
25
+ for (const entry of listing.messages || []) {
26
+ maskSecrets(entry);
27
+ }
28
+
29
+ return listing;
21
30
  } catch (err) {
22
31
  handleError(request, err);
23
32
  }
@@ -25,7 +34,7 @@ async function init(args) {
25
34
 
26
35
  options: {
27
36
  description: 'List queued messages',
28
- notes: 'Lists messages in the Outbox',
37
+ notes: `Lists messages in the Outbox. ${MASK_NOTE}`,
29
38
  tags: ['api', 'Outbox'],
30
39
 
31
40
  plugins: {
@@ -86,7 +95,7 @@ async function init(args) {
86
95
  let error = Boom.boomify(new Error(message), { statusCode: 404 });
87
96
  throw error;
88
97
  }
89
- return outboxEntry;
98
+ return maskSecrets(outboxEntry);
90
99
  } catch (err) {
91
100
  handleError(request, err);
92
101
  }
@@ -94,7 +103,7 @@ async function init(args) {
94
103
 
95
104
  options: {
96
105
  description: 'Get queued message',
97
- notes: 'Gets a queued message in the Outbox',
106
+ notes: `Gets a queued message in the Outbox. ${MASK_NOTE}`,
98
107
  tags: ['api', 'Outbox'],
99
108
 
100
109
  plugins: {
@@ -149,6 +158,7 @@ async function init(args) {
149
158
 
150
159
  plugins: {
151
160
  openapi: {
161
+ 'x-ee-impact': IMPACT.DESTRUCTIVE,
152
162
  responses: apiResponses('Returns a deletion marker. A message already being delivered cannot be removed.', 400, 401, 403, 429, 500)
153
163
  }
154
164
  },