emailengine-app 2.75.0 → 2.77.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 (113) hide show
  1. package/.github/workflows/release.yaml +24 -19
  2. package/.github/workflows/test.yml +0 -10
  3. package/.ncurc.js +14 -2
  4. package/.release-please-manifest.json +3 -0
  5. package/CHANGELOG.md +38 -0
  6. package/README.md +1 -1
  7. package/config/e2e.toml +1 -1
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +71 -4
  10. package/lib/address-strategies.js +18 -0
  11. package/lib/api-reference/code-samples.js +194 -0
  12. package/lib/api-reference/format.js +179 -0
  13. package/lib/api-reference/index.js +205 -0
  14. package/lib/api-reference/model.js +336 -0
  15. package/lib/api-reference/schema-tree.js +366 -0
  16. package/lib/api-routes/account-routes.js +117 -37
  17. package/lib/api-routes/behavior-notes.js +54 -0
  18. package/lib/api-routes/blocklist-routes.js +9 -9
  19. package/lib/api-routes/changes-routes.js +6 -4
  20. package/lib/api-routes/chat-routes.js +3 -3
  21. package/lib/api-routes/delivery-test-routes.js +24 -6
  22. package/lib/api-routes/export-routes.js +14 -12
  23. package/lib/api-routes/gateway-routes.js +11 -11
  24. package/lib/api-routes/license-routes.js +7 -7
  25. package/lib/api-routes/mailbox-routes.js +18 -9
  26. package/lib/api-routes/message-routes.js +55 -35
  27. package/lib/api-routes/oauth2-app-routes.js +22 -16
  28. package/lib/api-routes/outbox-routes.js +7 -7
  29. package/lib/api-routes/pubsub-routes.js +3 -3
  30. package/lib/api-routes/route-helpers.js +3 -0
  31. package/lib/api-routes/settings-routes.js +10 -9
  32. package/lib/api-routes/stats-routes.js +3 -3
  33. package/lib/api-routes/submit-routes.js +213 -56
  34. package/lib/api-routes/template-routes.js +13 -13
  35. package/lib/api-routes/token-routes.js +15 -10
  36. package/lib/api-routes/webhook-route-routes.js +5 -5
  37. package/lib/consts.js +7 -0
  38. package/lib/email-client/base-client.js +230 -31
  39. package/lib/email-client/gmail/send-request.js +16 -1
  40. package/lib/email-client/gmail-client.js +89 -5
  41. package/lib/email-client/imap-client.js +103 -1
  42. package/lib/email-client/message-builder.js +24 -7
  43. package/lib/email-client/outlook/send-request.js +18 -1
  44. package/lib/email-client/outlook-client.js +79 -4
  45. package/lib/enum-descriptions.js +130 -0
  46. package/lib/imapproxy/imap-server.js +30 -26
  47. package/lib/imapproxy/upstream-client.js +38 -0
  48. package/lib/oauth2-apps.js +9 -3
  49. package/lib/openapi/build-document.js +318 -0
  50. package/lib/openapi/index.js +95 -0
  51. package/lib/openapi/joi-schema.js +523 -0
  52. package/lib/routes-ui.js +5 -1
  53. package/lib/schemas.js +76 -17
  54. package/lib/swagger-options.js +173 -0
  55. package/lib/tokens.js +69 -5
  56. package/lib/ui-routes/admin-entities-routes.js +3 -0
  57. package/lib/ui-routes/dashboard-routes.js +2 -26
  58. package/lib/ui-routes/reference-routes.js +195 -0
  59. package/lib/ui-routes/route-helpers.js +11 -0
  60. package/package.json +19 -26
  61. package/playwright.config.js +1 -1
  62. package/prepare-bundle-deps.sh +28 -0
  63. package/release-please-config.json +11 -0
  64. package/sbom.json +0 -1
  65. package/server.js +22 -2
  66. package/static/css/flyonui.css +1 -1
  67. package/static/css/src/app.tailwind.css +90 -0
  68. package/static/js/ee-client.js +238 -8
  69. package/static/js/reference.js +736 -0
  70. package/static/js/ui.js +61 -33
  71. package/static/licenses.html +16 -16
  72. package/translations/messages.pot +13 -13
  73. package/views/config/ai.hbs +1 -1
  74. package/views/config/document-store/chat.hbs +5 -5
  75. package/views/config/document-store/index.hbs +2 -2
  76. package/views/config/document-store/pre-processing/index.hbs +1 -1
  77. package/views/config/email-processing.hbs +1 -1
  78. package/views/config/imap-proxy.hbs +1 -1
  79. package/views/config/license.hbs +1 -1
  80. package/views/config/oauth/index.hbs +3 -3
  81. package/views/config/security.hbs +1 -1
  82. package/views/config/smtp.hbs +2 -2
  83. package/views/dashboard.hbs +1 -1
  84. package/views/layout/app.hbs +18 -7
  85. package/views/partials/oauth_form.hbs +4 -4
  86. package/views/partials/reference/anchor-link.hbs +20 -0
  87. package/views/partials/reference/disclosure.hbs +37 -0
  88. package/views/partials/reference/nav.hbs +93 -0
  89. package/views/partials/reference/operation.hbs +127 -0
  90. package/views/partials/reference/params.hbs +20 -0
  91. package/views/partials/reference/schema-node.hbs +99 -0
  92. package/views/partials/reference/schema.hbs +19 -0
  93. package/views/partials/reference/section-heading.hbs +16 -0
  94. package/views/partials/reference/token-alert.hbs +24 -0
  95. package/views/partials/reference/try-field.hbs +31 -0
  96. package/views/partials/reference/try-it.hbs +78 -0
  97. package/views/partials/side_menu.hbs +1 -1
  98. package/views/partials/ui/badge.hbs +4 -2
  99. package/views/partials/ui/page-header.hbs +1 -1
  100. package/views/partials/ui/search-input.hbs +31 -0
  101. package/views/partials/ui/setting-ref.hbs +1 -1
  102. package/views/partials/ui/stat-card.hbs +4 -2
  103. package/views/partials/ui/tab.hbs +6 -1
  104. package/views/partials/ui/tabs.hbs +2 -2
  105. package/views/reference/index.hbs +76 -0
  106. package/views/reference/redirect.hbs +49 -0
  107. package/views/reference/tag.hbs +28 -0
  108. package/views/reference/token.hbs +49 -0
  109. package/views/tokens/index.hbs +9 -1
  110. package/views/webhooks/index.hbs +3 -3
  111. package/workers/api.js +37 -215
  112. package/Gruntfile.js +0 -58
  113. package/views/swagger/index.hbs +0 -82
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const Boom = require('@hapi/boom');
4
3
  const Joi = require('joi');
5
4
  const { redis } = require('../db');
6
5
  const { Account } = require('../account');
7
6
  const getSecret = require('../get-secret');
8
7
  const { failAction } = require('../tools');
8
+ const { handleError } = require('./route-helpers');
9
+ const BEHAVIOR = require('./behavior-notes');
9
10
  const {
10
11
  messageReferenceSchema,
11
12
  fromAddressSchema,
@@ -17,9 +18,54 @@ const {
17
18
  settingsSchema,
18
19
  ipSchema,
19
20
  threadIdSchema,
20
- errorResponses
21
+ apiResponses,
22
+ ENUM_DESCRIPTIONS
21
23
  } = require('../schemas');
22
24
 
25
+ // Schema fragments shared between the message submit and the draft submit routes. Joi schemas
26
+ // are immutable, so per-route variants are derived with .description()/.label() where needed.
27
+ const submitHeadersSchema = Joi.object({
28
+ 'x-ee-timeout': headerTimeoutSchema,
29
+ 'idempotency-key': idempotencyKeySchema
30
+ }).unknown();
31
+
32
+ const sendAtSchema = Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Send message at specified time');
33
+
34
+ const deliveryAttemptsSchema = Joi.number().integer().example(10).description('How many delivery attempts to make until message is considered as failed');
35
+
36
+ const gatewaySchema = Joi.string().max(256).example('example').description('Optional SMTP gateway ID for message routing').label('MessageGateway');
37
+
38
+ const dsnSchema = Joi.object({
39
+ id: Joi.string().trim().empty('').max(256).description('The envelope identifier that would be included in the response (ENVID)'),
40
+ return: Joi.string()
41
+ .trim()
42
+ .empty('')
43
+ .valid('headers', 'full')
44
+ .required()
45
+ .description('Specifies if only headers or the entire body of the message should be included in the response (RET)')
46
+ .label('DsnReturn'),
47
+ notify: Joi.array()
48
+ .single()
49
+ .items(Joi.string().valid('never', 'success', 'failure', 'delay').meta({ enumDescriptions: ENUM_DESCRIPTIONS.dsnNotify }).label('NotifyEntry'))
50
+ .description('Defines the conditions under which a DSN response should be sent')
51
+ .label('DsnNotify'),
52
+ recipient: Joi.string().trim().empty('').email().description('The email address the DSN should be sent (ORCPT)')
53
+ }).description('Request DSN notifications');
54
+
55
+ const proxySchema = settingsSchema.proxyUrl.description('Optional proxy URL to use when connecting to the SMTP server');
56
+
57
+ const localAddressSchema = ipSchema.description('Optional local IP address to bind to when connecting to the SMTP server');
58
+
59
+ const idempotencyResponseSchema = Joi.object({
60
+ key: idempotencyKeySchema.example('submit-12345').description('Idempotency key from the request').label('ResponseIdempotencyKey'),
61
+ status: Joi.string()
62
+ .valid('MISS', 'HIT')
63
+ .example('MISS')
64
+ .description('Whether the response was generated now (MISS) or returned from the idempotency cache (HIT)')
65
+ })
66
+ .description('Idempotency info, present when an Idempotency-Key header was used')
67
+ .label('ResponseIdempotency');
68
+
23
69
  async function init(args) {
24
70
  const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
25
71
 
@@ -43,18 +89,7 @@ async function init(args) {
43
89
  useStructuredFormat: request.query.useStructuredFormat
44
90
  });
45
91
  } catch (err) {
46
- request.logger.error({ msg: 'API request failed', err });
47
- if (Boom.isBoom(err)) {
48
- throw err;
49
- }
50
- let error = Boom.boomify(err, { statusCode: err.statusCode || 500 });
51
- if (err.code) {
52
- error.output.payload.code = err.code;
53
- }
54
- if (err.info) {
55
- error.output.payload.info = err.info;
56
- }
57
- throw error;
92
+ handleError(request, err);
58
93
  }
59
94
  },
60
95
  options: {
@@ -64,12 +99,26 @@ async function init(args) {
64
99
  },
65
100
 
66
101
  description: 'Submit message for delivery',
67
- notes: 'Submit message for delivery. If reference message ID is provided then EmailEngine adds all headers and flags required for a reply/forward automatically.',
102
+ notes: [
103
+ 'Submit message for delivery. If reference message ID is provided then EmailEngine adds all headers and flags required for a reply/forward automatically.',
104
+ BEHAVIOR.QUEUED_DELIVERY,
105
+ BEHAVIOR.SENT_FOLDER_UPLOAD
106
+ ],
68
107
  tags: ['api', 'Submit'],
69
108
 
70
109
  plugins: {
71
- 'hapi-swagger': {
72
- responses: errorResponses(400, 401, 403, 404, 429, 500, 503)
110
+ openapi: {
111
+ 'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
112
+ responses: apiResponses(
113
+ 'Returns the queue ID the message was accepted under. Delivery happens asynchronously - a 200 means queued, not sent.',
114
+ 400,
115
+ 401,
116
+ 403,
117
+ 404,
118
+ 429,
119
+ 500,
120
+ 503
121
+ )
73
122
  }
74
123
  },
75
124
 
@@ -106,10 +155,7 @@ async function init(args) {
106
155
  )
107
156
  }).label('SubmitQuery'),
108
157
 
109
- headers: Joi.object({
110
- 'x-ee-timeout': headerTimeoutSchema,
111
- 'idempotency-key': idempotencyKeySchema
112
- }).unknown(),
158
+ headers: submitHeadersSchema,
113
159
 
114
160
  payload: Joi.object({
115
161
  reference: messageReferenceSchema,
@@ -285,12 +331,9 @@ async function init(args) {
285
331
  locale: Joi.string().empty('').max(100).example('fr').description('Optional locale').label('MessageLocale'),
286
332
  tz: Joi.string().empty('').max(100).example('Europe/Tallinn').description('Optional timezone'),
287
333
 
288
- sendAt: Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Send message at specified time'),
289
- deliveryAttempts: Joi.number()
290
- .integer()
291
- .example(10)
292
- .description('How many delivery attempts to make until message is considered as failed'),
293
- gateway: Joi.string().max(256).example('example').description('Optional SMTP gateway ID for message routing').label('MessageGateway'),
334
+ sendAt: sendAtSchema,
335
+ deliveryAttempts: deliveryAttemptsSchema,
336
+ gateway: gatewaySchema,
294
337
 
295
338
  listId: Joi.string()
296
339
  .hostname()
@@ -305,24 +348,7 @@ async function init(args) {
305
348
  otherwise: Joi.forbidden()
306
349
  }),
307
350
 
308
- dsn: Joi.object({
309
- id: Joi.string().trim().empty('').max(256).description('The envelope identifier that would be included in the response (ENVID)'),
310
- return: Joi.string()
311
- .trim()
312
- .empty('')
313
- .valid('headers', 'full')
314
- .required()
315
- .description('Specifies if only headers or the entire body of the message should be included in the response (RET)')
316
- .label('DsnReturn'),
317
- notify: Joi.array()
318
- .single()
319
- .items(Joi.string().valid('never', 'success', 'failure', 'delay').label('NotifyEntry'))
320
- .description('Defines the conditions under which a DSN response should be sent')
321
- .label('DsnNotify'),
322
- recipient: Joi.string().trim().empty('').email().description('The email address the DSN should be sent (ORCPT)')
323
- })
324
- .description('Request DSN notifications')
325
- .label('DSN'),
351
+ dsn: dsnSchema.label('DSN'),
326
352
 
327
353
  baseUrl: Joi.string()
328
354
  .trim()
@@ -334,8 +360,8 @@ async function init(args) {
334
360
  .example('https://customer123.myservice.com')
335
361
  .description('Optional base URL for trackers. This URL must point to your EmailEngine instance.'),
336
362
 
337
- proxy: settingsSchema.proxyUrl.description('Optional proxy URL to use when connecting to the SMTP server'),
338
- localAddress: ipSchema.description('Optional local IP address to bind to when connecting to the SMTP server'),
363
+ proxy: proxySchema,
364
+ localAddress: localAddressSchema,
339
365
 
340
366
  dryRun: Joi.boolean()
341
367
  .truthy('Y', 'true', '1')
@@ -404,15 +430,7 @@ async function init(args) {
404
430
  .description('Base64 encoded RFC822 email if a preview was requested. Not returned for mail-merge submissions.')
405
431
  .label('ResponsePreview'),
406
432
 
407
- idempotency: Joi.object({
408
- key: idempotencyKeySchema.example('submit-12345').description('Idempotency key from the request').label('ResponseIdempotencyKey'),
409
- status: Joi.string()
410
- .valid('MISS', 'HIT')
411
- .example('MISS')
412
- .description('Whether the response was generated now (MISS) or returned from the idempotency cache (HIT)')
413
- })
414
- .description('Idempotency info, present when an Idempotency-Key header was used')
415
- .label('ResponseIdempotency'),
433
+ idempotency: idempotencyResponseSchema,
416
434
 
417
435
  mailMerge: Joi.array()
418
436
  .items(
@@ -456,6 +474,145 @@ async function init(args) {
456
474
  }
457
475
  }
458
476
  });
477
+
478
+ server.route({
479
+ method: 'POST',
480
+ path: '/v1/account/{account}/message/{message}/submit',
481
+
482
+ async handler(request) {
483
+ let accountObject = new Account({
484
+ redis,
485
+ account: request.params.account,
486
+ call,
487
+ secret: await getSecret(),
488
+ timeout: request.headers['x-ee-timeout']
489
+ });
490
+
491
+ try {
492
+ return await accountObject.queueMessage(request.payload || {}, {
493
+ source: 'api',
494
+ idempotencyKey: request.headers['idempotency-key'],
495
+ draft: { message: request.params.message }
496
+ });
497
+ } catch (err) {
498
+ handleError(request, err);
499
+ }
500
+ },
501
+ options: {
502
+ description: 'Submit a stored draft for delivery',
503
+ notes: [
504
+ 'Sends an existing draft message. The message must be a draft: stored in the Drafts folder or flagged as a draft (IMAP), carrying the DRAFT label (Gmail), or a draft message (MS Graph). Gmail and MS Graph accounts use the native draft-send call of the provider, which also files the message into the Sent Mail folder and removes the draft. For IMAP accounts the draft is downloaded, sent over SMTP, copied to the Sent Mail folder (unless disabled), and then removed from the Drafts folder.',
505
+ BEHAVIOR.QUEUED_DELIVERY,
506
+ BEHAVIOR.SENT_FOLDER_UPLOAD
507
+ ],
508
+ tags: ['api', 'Submit'],
509
+
510
+ plugins: {
511
+ openapi: {
512
+ 'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
513
+
514
+ // Every property of this payload is an optional override, so a snippet
515
+ // synthesized from the schema shows an envelope, a DSN block and a proxy
516
+ // as if they were the request. The draft already carries its recipients
517
+ // and content; the call that matters is the empty one. Hand-written
518
+ // samples lead the tab strip on the reference page and reach every other
519
+ // consumer of /swagger.json through the standard extension.
520
+ 'x-codeSamples': [
521
+ {
522
+ lang: 'bash',
523
+ label: 'Minimal',
524
+ source: [
525
+ `curl -X POST "$EMAILENGINE_URL/v1/account/example/message/AAAAAQAACnA/submit" \\`,
526
+ ` -H "Authorization: Bearer $EMAILENGINE_TOKEN" \\`,
527
+ ` -H "Content-Type: application/json" \\`,
528
+ ` -d '{}'`
529
+ ].join('\n')
530
+ }
531
+ ],
532
+
533
+ responses: apiResponses(
534
+ 'Returns the queue ID the stored draft was accepted under. Delivery happens asynchronously - a 200 means queued, not sent.',
535
+ 400,
536
+ 401,
537
+ 403,
538
+ 404,
539
+ 429,
540
+ 500,
541
+ 503
542
+ )
543
+ }
544
+ },
545
+
546
+ auth: {
547
+ strategy: 'api-token',
548
+ mode: 'required'
549
+ },
550
+ cors: CORS_CONFIG,
551
+
552
+ validate: {
553
+ options: {
554
+ stripUnknown: false,
555
+ abortEarly: false,
556
+ convert: true
557
+ },
558
+ failAction,
559
+
560
+ params: Joi.object({
561
+ account: accountIdSchema.required(),
562
+ message: Joi.string().max(256).required().example('AAAAAQAACnA').description('Message ID of the draft')
563
+ }),
564
+
565
+ headers: submitHeadersSchema,
566
+
567
+ payload: Joi.object({
568
+ envelope: Joi.object({
569
+ from: Joi.string().email().allow('').example('sender@example.com'),
570
+ to: Joi.array().items(Joi.string().email().required().example('recipient@example.com')).single().label('DraftSmtpEnvelopeTo')
571
+ })
572
+ .description(
573
+ "An optional object specifying the SMTP envelope used during email transmission. If not provided, the envelope is derived from the draft's message headers. Only used when the message is delivered over SMTP."
574
+ )
575
+ .label('DraftSMTPEnvelope'),
576
+
577
+ copy: Joi.boolean()
578
+ .allow(null)
579
+ .example(null)
580
+ .description(
581
+ "If set then either copies the message to the Sent Mail folder or not. If not set then uses the account's default setting. Only applies to SMTP deliveries - Gmail and MS Graph file sent drafts into the Sent Mail folder themselves."
582
+ ),
583
+
584
+ sentMailPath: Joi.string()
585
+ .empty('')
586
+ .max(1024)
587
+ .example('Sent Mail')
588
+ .description("Upload sent message to this folder. By default the account's Sent Mail folder is used. Only applies to SMTP deliveries."),
589
+
590
+ sendAt: sendAtSchema,
591
+ deliveryAttempts: deliveryAttemptsSchema,
592
+ gateway: gatewaySchema,
593
+
594
+ dsn: dsnSchema.description('Request DSN notifications. Only used when the message is delivered over SMTP.').label('DraftDSN'),
595
+
596
+ proxy: proxySchema,
597
+ localAddress: localAddressSchema
598
+ })
599
+ .allow(null)
600
+ .label('SubmitDraft')
601
+ },
602
+
603
+ response: {
604
+ schema: Joi.object({
605
+ response: Joi.string().example('Queued for delivery'),
606
+ messageId: Joi.string().example('<a2184d08-a470-fec6-a493-fa211a3756e9@example.com>').description('Message-ID header value'),
607
+ queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for scheduled email'),
608
+ sendAt: Joi.date().example('2021-07-08T07:06:34.336Z').description('Scheduled send time'),
609
+
610
+ idempotency: idempotencyResponseSchema
611
+ }).label('SubmitDraftResponse'),
612
+ failAction: 'log'
613
+ }
614
+ }
615
+ });
459
616
  }
460
617
 
461
618
  module.exports = init;
@@ -8,7 +8,7 @@ const Joi = require('joi');
8
8
  const { failAction } = require('../tools');
9
9
  const { handleError, throwNotFound } = require('./route-helpers');
10
10
 
11
- const { templateSchemas, accountIdSchema, errorResponses } = require('../schemas');
11
+ const { templateSchemas, accountIdSchema, apiResponses } = require('../schemas');
12
12
 
13
13
  // Template owner field shared by all template response schemas
14
14
  const templateAccountIdSchema = accountIdSchema.required().allow(null).description('Account ID. Null for public templates');
@@ -56,8 +56,8 @@ async function init(args) {
56
56
  tags: ['api', 'Templates'],
57
57
 
58
58
  plugins: {
59
- 'hapi-swagger': {
60
- responses: errorResponses(400, 401, 403, 404, 429, 500)
59
+ openapi: {
60
+ responses: apiResponses('Returns the created template.', 400, 401, 403, 404, 429, 500)
61
61
  }
62
62
  },
63
63
 
@@ -144,8 +144,8 @@ async function init(args) {
144
144
  tags: ['api', 'Templates'],
145
145
 
146
146
  plugins: {
147
- 'hapi-swagger': {
148
- responses: errorResponses(400, 401, 403, 404, 429, 500)
147
+ openapi: {
148
+ responses: apiResponses('Returns the updated template.', 400, 401, 403, 404, 429, 500)
149
149
  }
150
150
  },
151
151
 
@@ -225,8 +225,8 @@ async function init(args) {
225
225
  tags: ['api', 'Templates'],
226
226
 
227
227
  plugins: {
228
- 'hapi-swagger': {
229
- responses: errorResponses(400, 401, 403, 404, 429, 500)
228
+ openapi: {
229
+ responses: apiResponses('Returns a page of stored templates for the account.', 400, 401, 403, 404, 429, 500)
230
230
  }
231
231
  },
232
232
 
@@ -315,8 +315,8 @@ async function init(args) {
315
315
  tags: ['api', 'Templates'],
316
316
 
317
317
  plugins: {
318
- 'hapi-swagger': {
319
- responses: errorResponses(400, 401, 403, 404, 429, 500)
318
+ openapi: {
319
+ responses: apiResponses('Returns the template, including its content.', 400, 401, 403, 404, 429, 500)
320
320
  }
321
321
  },
322
322
 
@@ -385,8 +385,8 @@ async function init(args) {
385
385
  tags: ['api', 'Templates'],
386
386
 
387
387
  plugins: {
388
- 'hapi-swagger': {
389
- responses: errorResponses(400, 401, 403, 429, 500)
388
+ openapi: {
389
+ responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 429, 500)
390
390
  }
391
391
  },
392
392
 
@@ -449,8 +449,8 @@ async function init(args) {
449
449
  tags: ['api', 'Templates'],
450
450
 
451
451
  plugins: {
452
- 'hapi-swagger': {
453
- responses: errorResponses(400, 401, 403, 404, 429, 500)
452
+ openapi: {
453
+ responses: apiResponses('Returns the number of templates removed.', 400, 401, 403, 404, 429, 500)
454
454
  }
455
455
  },
456
456
 
@@ -8,7 +8,7 @@ const getSecret = require('../get-secret');
8
8
  const tokens = require('../tokens');
9
9
  const { failAction } = require('../tools');
10
10
  const { handleError } = require('./route-helpers');
11
- const { accountIdSchema, tokenRestrictionsSchema, ipSchema, tokenIdSchema, errorResponses } = require('../schemas');
11
+ const { accountIdSchema, tokenRestrictionsSchema, ipSchema, tokenIdSchema, apiResponses, ENUM_DESCRIPTIONS } = require('../schemas');
12
12
 
13
13
  const tokenAccessSchema = Joi.object({
14
14
  time: Joi.date().iso().allow(null).example('2021-02-17T13:43:18.860Z').description('Last time this token was used. Null if the token has never been used'),
@@ -49,6 +49,11 @@ const tokenListItemFields = {
49
49
  scopes: tokenScopesSchema,
50
50
  restrictions: tokenRestrictionsSchema,
51
51
  created: Joi.date().iso().example('2021-02-17T13:43:18.860Z').description('The time this token was created'),
52
+ expires: Joi.date()
53
+ .iso()
54
+ .example('2021-02-17T14:43:18.860Z')
55
+ .description('The time this token stops working. Absent for tokens that never expire')
56
+ .label('TokenExpires'),
52
57
  access: tokenAccessSchema,
53
58
  id: tokenIdSchema
54
59
  };
@@ -99,8 +104,8 @@ async function init(args) {
99
104
  tags: ['api', 'Access Tokens'],
100
105
 
101
106
  plugins: {
102
- 'hapi-swagger': {
103
- responses: errorResponses(400, 401, 403, 404, 429, 500)
107
+ openapi: {
108
+ responses: apiResponses('Returns the new token value. This is the only time it is shown - store it now.', 400, 401, 403, 404, 429, 500)
104
109
  }
105
110
  },
106
111
 
@@ -124,7 +129,7 @@ async function init(args) {
124
129
  description: Joi.string().empty('').trim().max(1024).required().example('Token description').description('Token description'),
125
130
 
126
131
  scopes: Joi.array()
127
- .items(Joi.string().valid('api', 'smtp', 'imap-proxy').label('TokenScope'))
132
+ .items(Joi.string().valid('api', 'smtp', 'imap-proxy').meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenScope }).label('TokenScope'))
128
133
  .single()
129
134
  .default(['api'])
130
135
  .required()
@@ -167,8 +172,8 @@ async function init(args) {
167
172
  tags: ['api', 'Access Tokens'],
168
173
 
169
174
  plugins: {
170
- 'hapi-swagger': {
171
- responses: errorResponses(400, 401, 403, 429, 500)
175
+ openapi: {
176
+ responses: apiResponses('Returns a deletion marker. The token stops working immediately.', 400, 401, 403, 429, 500)
172
177
  }
173
178
  },
174
179
 
@@ -219,8 +224,8 @@ async function init(args) {
219
224
  tags: ['api', 'Access Tokens'],
220
225
 
221
226
  plugins: {
222
- 'hapi-swagger': {
223
- responses: errorResponses(401, 403, 429, 500)
227
+ openapi: {
228
+ responses: apiResponses('Returns the root access tokens. Token values are never returned after creation.', 401, 403, 429, 500)
224
229
  }
225
230
  },
226
231
 
@@ -267,8 +272,8 @@ async function init(args) {
267
272
  tags: ['api', 'Access Tokens'],
268
273
 
269
274
  plugins: {
270
- 'hapi-swagger': {
271
- responses: errorResponses(400, 401, 403, 429, 500)
275
+ openapi: {
276
+ responses: apiResponses('Returns the access tokens scoped to the account.', 400, 401, 403, 429, 500)
272
277
  }
273
278
  },
274
279
 
@@ -4,7 +4,7 @@ const Joi = require('joi');
4
4
  const { webhooks: Webhooks } = require('../webhooks');
5
5
  const { failAction } = require('../tools');
6
6
  const { handleError, throwNotFound } = require('./route-helpers');
7
- const { settingsSchema, errorResponses } = require('../schemas');
7
+ const { settingsSchema, apiResponses } = require('../schemas');
8
8
 
9
9
  const webhookErrorFlagSchema = Joi.object({
10
10
  message: Joi.string().example('Request failed with status 500').description('Error message from the last failed delivery')
@@ -39,8 +39,8 @@ async function init(args) {
39
39
  tags: ['api', 'Webhooks'],
40
40
 
41
41
  plugins: {
42
- 'hapi-swagger': {
43
- responses: errorResponses(400, 401, 403, 429, 500)
42
+ openapi: {
43
+ responses: apiResponses('Returns a page of custom webhook routes.', 400, 401, 403, 429, 500)
44
44
  }
45
45
  },
46
46
 
@@ -126,8 +126,8 @@ async function init(args) {
126
126
  tags: ['api', 'Webhooks'],
127
127
 
128
128
  plugins: {
129
- 'hapi-swagger': {
130
- responses: errorResponses(400, 401, 403, 404, 429, 500)
129
+ openapi: {
130
+ responses: apiResponses('Returns the webhook route, including its filter and transform functions.', 400, 401, 403, 404, 429, 500)
131
131
  }
132
132
  },
133
133
 
package/lib/consts.js CHANGED
@@ -104,6 +104,13 @@ module.exports = {
104
104
  // is a write-only credential, it can only be used to submit events.
105
105
  COMMUNITY_SENTRY_DSN: 'https://bdd958f3e813a488904b0f254e0bb8a8@sentry.emailengine.dev/3',
106
106
 
107
+ // OAuth2 application fields that are encrypted at rest and redacted in API responses. Every
108
+ // consumer must agree on the list: the writer (lib/oauth2-apps.js), the `emailengine encrypt`
109
+ // rotation tool (a field it skips stays readable only with the old secret) and the API
110
+ // read routes (a field they skip is returned as-is, which is cleartext on an instance with
111
+ // no service secret).
112
+ ENCRYPTED_APP_KEYS: ['clientSecret', 'serviceKey', 'accessToken', 'externalAccount'],
113
+
107
114
  PDKDF2_ITERATIONS: 600000,
108
115
  PDKDF2_SALT_SIZE: 16,
109
116
  PDKDF2_DIGEST: 'sha256', // 'sha512', 'sha256' or 'sha1'