emailengine-app 2.84.2 → 2.85.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 (86) hide show
  1. package/.ncurc.js +5 -3
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +33 -0
  6. package/Dockerfile +6 -0
  7. package/README.md +1 -1
  8. package/bin/emailengine.js +434 -408
  9. package/copy-static-files.sh +39 -14
  10. package/data/google-crawlers.json +1 -1
  11. package/data/public_suffix_list.dat +16562 -0
  12. package/eslint.config.js +81 -99
  13. package/lib/account.js +36 -5
  14. package/lib/api-reference/format.js +4 -3
  15. package/lib/api-routes/account-routes.js +177 -12
  16. package/lib/api-routes/blocklist-routes.js +23 -2
  17. package/lib/api-routes/delivery-test-routes.js +26 -3
  18. package/lib/api-routes/export-routes.js +28 -2
  19. package/lib/api-routes/gateway-routes.js +28 -2
  20. package/lib/api-routes/mailbox-routes.js +41 -2
  21. package/lib/api-routes/message-routes.js +97 -3
  22. package/lib/api-routes/oauth2-app-routes.js +48 -15
  23. package/lib/api-routes/outbox-routes.js +45 -11
  24. package/lib/api-routes/permission-map.js +12 -1
  25. package/lib/api-routes/settings-routes.js +23 -2
  26. package/lib/api-routes/submit-routes.js +336 -309
  27. package/lib/api-routes/template-routes.js +38 -2
  28. package/lib/api-routes/token-routes.js +142 -96
  29. package/lib/api-routes/webhook-route-routes.js +13 -2
  30. package/lib/bounce-detect.js +397 -205
  31. package/lib/consts.js +5 -4
  32. package/lib/email-client/base-client.js +10 -31
  33. package/lib/email-client/gmail-client.js +9 -11
  34. package/lib/email-client/imap/mailbox.js +3 -19
  35. package/lib/email-client/imap/subconnection.js +1 -1
  36. package/lib/email-client/imap-client.js +1 -1
  37. package/lib/email-client/notification-handler.js +1 -2
  38. package/lib/gateway.js +2 -3
  39. package/lib/hapi-request-logger.js +107 -0
  40. package/lib/imapproxy/imap-core/README.md +6 -5
  41. package/lib/mcp/tools.js +37 -8
  42. package/lib/notify-attachments.js +17 -0
  43. package/lib/oauth/outlook-mailbox.js +35 -0
  44. package/lib/oauth/state.js +24 -0
  45. package/lib/oauth2-apps.js +1 -1
  46. package/lib/pbkdf2-phc.js +1 -1
  47. package/lib/schemas.js +1 -1
  48. package/lib/sso.js +1 -1
  49. package/lib/swagger-options.js +1 -1
  50. package/lib/thread-diagnostics.js +46 -0
  51. package/lib/timezones.js +109 -0
  52. package/lib/token-permission-view.js +3 -3
  53. package/lib/tools.js +40 -10
  54. package/lib/totp.js +2 -5
  55. package/lib/translations.js +1 -2
  56. package/lib/ui-routes/account-routes.js +475 -454
  57. package/lib/ui-routes/account-setup.js +99 -0
  58. package/lib/ui-routes/admin-config-routes.js +88 -10
  59. package/lib/ui-routes/admin-entities-routes.js +91 -7
  60. package/lib/ui-routes/auth-routes.js +90 -38
  61. package/lib/ui-routes/internals-routes.js +5 -0
  62. package/lib/ui-routes/oauth-config-routes.js +124 -82
  63. package/lib/ui-routes/route-helpers.js +19 -3
  64. package/lib/ui-routes/tls-config-routes.js +58 -15
  65. package/lib/utils/back-off.js +82 -0
  66. package/lib/utils/murmurhash3.js +66 -0
  67. package/lib/utils/public-suffix.js +122 -0
  68. package/lib/utils/random-id.js +26 -0
  69. package/lib/utils/version.js +74 -0
  70. package/lib/webhook-routing.js +27 -0
  71. package/lib/webhooks.js +41 -6
  72. package/package.json +27 -29
  73. package/sbom.json +7980 -1
  74. package/server.js +634 -441
  75. package/static/licenses.html +181 -1006
  76. package/translations/messages.pot +62 -63
  77. package/views/config/ai.hbs +1 -1
  78. package/views/config/security.hbs +2 -2
  79. package/views/config/service.hbs +3 -0
  80. package/views/internals/index.hbs +8 -0
  81. package/views/partials/webhook_form.hbs +1 -1
  82. package/views/suppression-lists/index.hbs +1 -1
  83. package/workers/api.js +738 -583
  84. package/workers/export.js +1 -1
  85. package/workers/submit.js +1 -1
  86. package/workers/webhooks.js +16 -32
@@ -14,8 +14,8 @@ const BEHAVIOR = require('./behavior-notes');
14
14
  const { handleError } = require('./route-helpers');
15
15
  const { IMPACT } = require('./operation-impact');
16
16
 
17
- async function init(args) {
18
- const { server, call, CORS_CONFIG, SMTP_TEST_HOST } = args;
17
+ function registerCreateDeliveryTest(server, args) {
18
+ const { call, CORS_CONFIG, SMTP_TEST_HOST } = args;
19
19
 
20
20
  server.route({
21
21
  method: 'POST',
@@ -129,6 +129,18 @@ ${now}`,
129
129
  tags: ['api', 'Delivery Test'],
130
130
 
131
131
  plugins: {
132
+ mcp: {
133
+ name: 'create_delivery_test',
134
+ title: 'Start delivery test',
135
+ description:
136
+ "Send a test message from the account to a probe address of EmailEngine's delivery test service, to see how its mail is received: whether it arrives and its SPF, DKIM and DMARC results. " +
137
+ 'Returns a deliveryTest id; check_delivery_test reads the result from it, which takes a minute or so to be ready. check_delivery_test is a management tool, so a credential with mail access alone can start a test but not read it.',
138
+ // Picking an SMTP gateway is left to the REST API, as it is for send_message.
139
+ // Pinned to none rather than just hidden: the handler reads the field off a
140
+ // payload, so the call has to carry one
141
+ omit: ['gateway'],
142
+ force: { gateway: null }
143
+ },
132
144
  openapi: {
133
145
  'x-ee-impact': IMPACT.SENDS,
134
146
  'x-ee-behavior': [BEHAVIOR.BACKGROUND_JOB],
@@ -188,6 +200,10 @@ ${now}`,
188
200
  }
189
201
  }
190
202
  });
203
+ }
204
+
205
+ function registerCheckDeliveryTest(server, args) {
206
+ const { CORS_CONFIG, SMTP_TEST_HOST } = args;
191
207
 
192
208
  server.route({
193
209
  method: 'GET',
@@ -282,7 +298,7 @@ ${now}`,
282
298
  name: 'check_delivery_test',
283
299
  title: 'Check delivery test',
284
300
  description:
285
- 'Check the result of a delivery test started over the REST API: whether the probe message arrived, and its SPF, DKIM and DMARC results.'
301
+ 'Check the result of a delivery test started by create_delivery_test or over the REST API: whether the probe message arrived, and its SPF, DKIM and DMARC results.'
286
302
  },
287
303
  openapi: {
288
304
  responses: apiResponses(
@@ -347,4 +363,11 @@ ${now}`,
347
363
  });
348
364
  }
349
365
 
366
+ async function init(args) {
367
+ const { server } = args;
368
+
369
+ registerCreateDeliveryTest(server, args);
370
+ registerCheckDeliveryTest(server, args);
371
+ }
372
+
350
373
  module.exports = init;
@@ -9,8 +9,8 @@ const { handleError } = require('./route-helpers');
9
9
  const BEHAVIOR = require('./behavior-notes');
10
10
  const { IMPACT } = require('./operation-impact');
11
11
 
12
- async function init(args) {
13
- const { server, CORS_CONFIG } = args;
12
+ function registerCreateExport(server, args) {
13
+ const { CORS_CONFIG } = args;
14
14
 
15
15
  server.route({
16
16
  method: 'POST',
@@ -74,6 +74,10 @@ async function init(args) {
74
74
  }
75
75
  }
76
76
  });
77
+ }
78
+
79
+ function registerGetExport(server, args) {
80
+ const { CORS_CONFIG } = args;
77
81
 
78
82
  server.route({
79
83
  method: 'GET',
@@ -128,6 +132,10 @@ async function init(args) {
128
132
  }
129
133
  }
130
134
  });
135
+ }
136
+
137
+ function registerDownloadExport(server, args) {
138
+ const { CORS_CONFIG } = args;
131
139
 
132
140
  server.route({
133
141
  method: 'GET',
@@ -188,6 +196,10 @@ async function init(args) {
188
196
  }
189
197
  }
190
198
  });
199
+ }
200
+
201
+ function registerDeleteExport(server, args) {
202
+ const { CORS_CONFIG } = args;
191
203
 
192
204
  server.route({
193
205
  method: 'DELETE',
@@ -245,6 +257,10 @@ async function init(args) {
245
257
  }
246
258
  }
247
259
  });
260
+ }
261
+
262
+ function registerListExports(server, args) {
263
+ const { CORS_CONFIG } = args;
248
264
 
249
265
  server.route({
250
266
  method: 'GET',
@@ -311,4 +327,14 @@ async function init(args) {
311
327
  });
312
328
  }
313
329
 
330
+ async function init(args) {
331
+ const { server } = args;
332
+
333
+ registerCreateExport(server, args);
334
+ registerGetExport(server, args);
335
+ registerDownloadExport(server, args);
336
+ registerDeleteExport(server, args);
337
+ registerListExports(server, args);
338
+ }
339
+
314
340
  module.exports = init;
@@ -35,8 +35,8 @@ const gatewayLastErrorSchema = Joi.object({
35
35
  .description('Information about the last failed delivery attempt using this gateway')
36
36
  .label('GatewayErrorEntry');
37
37
 
38
- async function init(args) {
39
- const { server, call, CORS_CONFIG } = args;
38
+ function registerListGateways(server, args) {
39
+ const { call, CORS_CONFIG } = args;
40
40
 
41
41
  server.route({
42
42
  method: 'GET',
@@ -129,6 +129,10 @@ async function init(args) {
129
129
  }
130
130
  }
131
131
  });
132
+ }
133
+
134
+ function registerGetGateway(server, args) {
135
+ const { call, CORS_CONFIG } = args;
132
136
 
133
137
  server.route({
134
138
  method: 'GET',
@@ -246,6 +250,10 @@ async function init(args) {
246
250
  }
247
251
  }
248
252
  });
253
+ }
254
+
255
+ function registerCreateGateway(server, args) {
256
+ const { call, CORS_CONFIG } = args;
249
257
 
250
258
  server.route({
251
259
  method: 'POST',
@@ -350,6 +358,10 @@ async function init(args) {
350
358
  }
351
359
  }
352
360
  });
361
+ }
362
+
363
+ function registerUpdateGateway(server, args) {
364
+ const { call, CORS_CONFIG } = args;
353
365
 
354
366
  server.route({
355
367
  method: 'PUT',
@@ -435,6 +447,10 @@ async function init(args) {
435
447
  }
436
448
  }
437
449
  });
450
+ }
451
+
452
+ function registerDeleteGateway(server, args) {
453
+ const { CORS_CONFIG } = args;
438
454
 
439
455
  server.route({
440
456
  method: 'DELETE',
@@ -500,4 +516,14 @@ async function init(args) {
500
516
  });
501
517
  }
502
518
 
519
+ async function init(args) {
520
+ const { server } = args;
521
+
522
+ registerListGateways(server, args);
523
+ registerGetGateway(server, args);
524
+ registerCreateGateway(server, args);
525
+ registerUpdateGateway(server, args);
526
+ registerDeleteGateway(server, args);
527
+ }
528
+
503
529
  module.exports = init;
@@ -32,8 +32,8 @@ function throwMailboxError(request, err) {
32
32
  throw error;
33
33
  }
34
34
 
35
- async function init(args) {
36
- const { server, call, CORS_CONFIG, FLAG_SORT_ORDER } = args;
35
+ function registerListMailboxes(server, args) {
36
+ const { call, CORS_CONFIG, FLAG_SORT_ORDER } = args;
37
37
 
38
38
  server.route({
39
39
  method: 'GET',
@@ -130,6 +130,10 @@ async function init(args) {
130
130
  }
131
131
  }
132
132
  });
133
+ }
134
+
135
+ function registerCreateMailbox(server, args) {
136
+ const { call, CORS_CONFIG } = args;
133
137
 
134
138
  server.route({
135
139
  method: 'POST',
@@ -157,6 +161,12 @@ async function init(args) {
157
161
  tags: ['api', 'Mailbox'],
158
162
 
159
163
  plugins: {
164
+ mcp: {
165
+ name: 'create_mailbox',
166
+ title: 'Create mailbox',
167
+ description:
168
+ 'Create a folder. Give the path as a list of names from the top level down (["Projects", "2026"]) so the server joins them with its own separator; a missing parent is created too. The response carries the full path that list_messages and move_message take.'
169
+ },
160
170
  openapi: {
161
171
  responses: apiResponses('Returns the created folder and its path.', 400, 401, 403, 404, 429, 500, 503)
162
172
  }
@@ -201,6 +211,10 @@ async function init(args) {
201
211
  }
202
212
  }
203
213
  });
214
+ }
215
+
216
+ function registerModifyMailbox(server, args) {
217
+ const { call, CORS_CONFIG } = args;
204
218
 
205
219
  server.route({
206
220
  method: 'PUT',
@@ -228,6 +242,12 @@ async function init(args) {
228
242
  tags: ['api', 'Mailbox'],
229
243
 
230
244
  plugins: {
245
+ mcp: {
246
+ name: 'update_mailbox',
247
+ title: 'Rename or update mailbox',
248
+ description:
249
+ 'Rename or move a folder (newPath, as a list of names from the top level down), or change whether it is subscribed. `path` is the current path from list_mailboxes. The messages move with the folder; list them again under the new path for their current ids.'
250
+ },
231
251
  openapi: {
232
252
  responses: apiResponses('Returns the renamed folder with its old and new paths.', 400, 401, 403, 404, 429, 500, 503)
233
253
  }
@@ -284,6 +304,10 @@ async function init(args) {
284
304
  }
285
305
  }
286
306
  });
307
+ }
308
+
309
+ function registerDeleteMailbox(server, args) {
310
+ const { call, CORS_CONFIG } = args;
287
311
 
288
312
  server.route({
289
313
  method: 'DELETE',
@@ -313,6 +337,12 @@ async function init(args) {
313
337
  tags: ['api', 'Mailbox'],
314
338
 
315
339
  plugins: {
340
+ mcp: {
341
+ name: 'delete_mailbox',
342
+ title: 'Delete mailbox',
343
+ description:
344
+ 'Delete a folder by its path from list_mailboxes - confirm with the user before calling this. On an IMAP account the folder goes with every message in it, and nothing is kept in Trash. On a Gmail API account the label is removed and the messages stay in the mailbox under their other labels.'
345
+ },
316
346
  openapi: {
317
347
  'x-ee-impact': IMPACT.DESTRUCTIVE,
318
348
  responses: apiResponses('Returns the deleted folder path.', 400, 401, 403, 404, 429, 500, 503)
@@ -357,4 +387,13 @@ async function init(args) {
357
387
  });
358
388
  }
359
389
 
390
+ async function init(args) {
391
+ const { server } = args;
392
+
393
+ registerListMailboxes(server, args);
394
+ registerCreateMailbox(server, args);
395
+ registerModifyMailbox(server, args);
396
+ registerDeleteMailbox(server, args);
397
+ }
398
+
360
399
  module.exports = init;
@@ -96,8 +96,8 @@ const idMapSchema = Joi.array()
96
96
  .description('An optional map of source and target ID values, if the server provided this info (IMAP accounts only)')
97
97
  .label('IdMapArray');
98
98
 
99
- async function init(args) {
100
- const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
99
+ function registerGetMessageSource(server, args) {
100
+ const { call, CORS_CONFIG } = args;
101
101
 
102
102
  // GET /v1/account/{account}/message/{message}/source - Download raw message
103
103
  server.route({
@@ -153,6 +153,10 @@ async function init(args) {
153
153
  }
154
154
  }
155
155
  });
156
+ }
157
+
158
+ function registerGetMessage(server, args) {
159
+ const { call, CORS_CONFIG } = args;
156
160
 
157
161
  // GET /v1/account/{account}/message/{message} - Get message information
158
162
  server.route({
@@ -284,6 +288,10 @@ async function init(args) {
284
288
  }
285
289
  }
286
290
  });
291
+ }
292
+
293
+ function registerUploadMessage(server, args) {
294
+ const { call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
287
295
 
288
296
  // POST /v1/account/{account}/message - Upload message
289
297
  server.route({
@@ -326,7 +334,7 @@ async function init(args) {
326
334
  description:
327
335
  'Store a new message in a folder, typically a draft in the Drafts folder. Takes structured fields (from, to, subject, text, html). ' +
328
336
  'It takes the same `reference` block as send_message, so a reply or a forward can be drafted for the user to look over first. ' +
329
- 'Nothing is sent - use send_message for that.',
337
+ 'Nothing is sent: once the user has reviewed the draft, send_draft sends it by the id this returns. send_message sends a new message directly.',
330
338
  // An allowlist for the same reason send_message uses one: the composed message
331
339
  // is a small stable set, the route's payload is not, and a field added later
332
340
  // should not join an agent-facing schema by default. Left out are `raw` (which
@@ -481,6 +489,10 @@ async function init(args) {
481
489
  }
482
490
  }
483
491
  });
492
+ }
493
+
494
+ function registerUpdateMessage(server, args) {
495
+ const { call, CORS_CONFIG } = args;
484
496
 
485
497
  // PUT /v1/account/{account}/message/{message} - Update message
486
498
  server.route({
@@ -567,6 +579,10 @@ async function init(args) {
567
579
  }
568
580
  }
569
581
  });
582
+ }
583
+
584
+ function registerUpdateMessages(server, args) {
585
+ const { call, CORS_CONFIG } = args;
570
586
 
571
587
  // PUT /v1/account/{account}/messages - Update multiple messages
572
588
  server.route({
@@ -594,6 +610,14 @@ async function init(args) {
594
610
  tags: ['api', 'Multi Message Actions'],
595
611
 
596
612
  plugins: {
613
+ mcp: {
614
+ name: 'update_messages',
615
+ title: 'Update matching messages',
616
+ description:
617
+ 'Change the flags or labels of every message in one folder that matches a search, in one call - for example mark all unread mail from one sender as read. ' +
618
+ 'Run search_messages with the same folder and criteria first to see which messages match, then pass those criteria here. ' +
619
+ 'For one message, or a few whose ids are known, use update_message instead.'
620
+ },
597
621
  openapi: {
598
622
  'x-ee-behavior': [BEHAVIOR.NO_LABEL_SET_ON_GMAIL],
599
623
  responses: apiResponses('Returns which flag and label changes were applied to the matching messages.', 400, 401, 403, 404, 429, 500, 503)
@@ -649,6 +673,10 @@ async function init(args) {
649
673
  }
650
674
  }
651
675
  });
676
+ }
677
+
678
+ function registerMoveMessage(server, args) {
679
+ const { call, CORS_CONFIG } = args;
652
680
 
653
681
  // PUT /v1/account/{account}/message/{message}/move - Move a message
654
682
  server.route({
@@ -732,6 +760,10 @@ async function init(args) {
732
760
  }
733
761
  }
734
762
  });
763
+ }
764
+
765
+ function registerMoveMessages(server, args) {
766
+ const { call, CORS_CONFIG } = args;
735
767
 
736
768
  // PUT /v1/account/{account}/messages/move - Move multiple messages
737
769
  server.route({
@@ -759,6 +791,18 @@ async function init(args) {
759
791
  tags: ['api', 'Multi Message Actions'],
760
792
 
761
793
  plugins: {
794
+ mcp: {
795
+ name: 'move_messages',
796
+ title: 'Move matching messages',
797
+ description:
798
+ 'Move every message in one folder that matches a search to another folder, in one call. `source` is the folder searched and `path` the folder the messages go to, both paths from list_mailboxes. ' +
799
+ 'Run search_messages on the source folder with the same criteria first to see which messages match, then pass those criteria here. ' +
800
+ 'For one message, or a few whose ids are known, use move_message instead.',
801
+ // The route reads the folder to search from the query and the target from the
802
+ // payload, both as `path`. The target keeps the name move_message gives it, and
803
+ // the folder searched takes the name move_message gives its own source folder.
804
+ rename: { query: { path: 'source' } }
805
+ },
762
806
  openapi: {
763
807
  responses: apiResponses('Returns the number of messages moved.', 400, 401, 403, 404, 429, 500, 503)
764
808
  }
@@ -811,6 +855,10 @@ async function init(args) {
811
855
  }
812
856
  }
813
857
  });
858
+ }
859
+
860
+ function registerDeleteMessage(server, args) {
861
+ const { call, CORS_CONFIG } = args;
814
862
 
815
863
  // DELETE /v1/account/{account}/message/{message} - Delete message
816
864
  server.route({
@@ -900,6 +948,10 @@ async function init(args) {
900
948
  }
901
949
  }
902
950
  });
951
+ }
952
+
953
+ function registerDeleteMessages(server, args) {
954
+ const { call, CORS_CONFIG } = args;
903
955
 
904
956
  // PUT /v1/account/{account}/messages/delete - Delete multiple messages
905
957
  server.route({
@@ -927,6 +979,14 @@ async function init(args) {
927
979
  tags: ['api', 'Multi Message Actions'],
928
980
 
929
981
  plugins: {
982
+ mcp: {
983
+ name: 'delete_messages',
984
+ title: 'Delete matching messages',
985
+ description:
986
+ 'Delete every message in one folder that matches a search, in one call - confirm with the user before calling this. Messages are moved to Trash, and deleted permanently when the folder already is Trash. ' +
987
+ 'Run search_messages with the same folder and criteria first to see which messages match, and pass exactly those criteria here. ' +
988
+ 'For one message, or a few whose ids are known, use delete_message instead.'
989
+ },
930
990
  openapi: {
931
991
  'x-ee-impact': IMPACT.DESTRUCTIVE,
932
992
  'x-ee-behavior': [BEHAVIOR.GMAIL_DELETE_IS_TRASH],
@@ -1000,6 +1060,10 @@ async function init(args) {
1000
1060
  }
1001
1061
  }
1002
1062
  });
1063
+ }
1064
+
1065
+ function registerListMessages(server, args) {
1066
+ const { call, CORS_CONFIG } = args;
1003
1067
 
1004
1068
  // GET /v1/account/{account}/messages - List messages in a folder
1005
1069
  server.route({
@@ -1087,6 +1151,10 @@ async function init(args) {
1087
1151
  }
1088
1152
  }
1089
1153
  });
1154
+ }
1155
+
1156
+ function registerSearchMessages(server, args) {
1157
+ const { call, CORS_CONFIG } = args;
1090
1158
 
1091
1159
  // POST /v1/account/{account}/search - Search for messages
1092
1160
  server.route({
@@ -1209,6 +1277,10 @@ async function init(args) {
1209
1277
  }
1210
1278
  }
1211
1279
  });
1280
+ }
1281
+
1282
+ function registerGetMessageText(server, args) {
1283
+ const { call, CORS_CONFIG, MAX_ATTACHMENT_SIZE } = args;
1212
1284
 
1213
1285
  // GET /v1/account/{account}/text/{text} - Retrieve message text
1214
1286
  server.route({
@@ -1319,6 +1391,10 @@ async function init(args) {
1319
1391
  }
1320
1392
  }
1321
1393
  });
1394
+ }
1395
+
1396
+ function registerGetAttachment(server, args) {
1397
+ const { call, CORS_CONFIG } = args;
1322
1398
 
1323
1399
  // GET /v1/account/{account}/attachment/{attachment} - Download attachment
1324
1400
  server.route({
@@ -1388,4 +1464,22 @@ async function init(args) {
1388
1464
  });
1389
1465
  }
1390
1466
 
1467
+ async function init(args) {
1468
+ const { server } = args;
1469
+
1470
+ registerGetMessageSource(server, args);
1471
+ registerGetMessage(server, args);
1472
+ registerUploadMessage(server, args);
1473
+ registerUpdateMessage(server, args);
1474
+ registerUpdateMessages(server, args);
1475
+ registerMoveMessage(server, args);
1476
+ registerMoveMessages(server, args);
1477
+ registerDeleteMessage(server, args);
1478
+ registerDeleteMessages(server, args);
1479
+ registerListMessages(server, args);
1480
+ registerSearchMessages(server, args);
1481
+ registerGetMessageText(server, args);
1482
+ registerGetAttachment(server, args);
1483
+ }
1484
+
1391
1485
  module.exports = init;
@@ -53,20 +53,8 @@ const oauth2AppExtraFields = {
53
53
  pubSubIamPolicy: Joi.boolean().example(true).description('Whether the IAM policy for the Cloud Pub/Sub topic has been set up')
54
54
  };
55
55
 
56
- async function init(args) {
57
- const { server, call, CORS_CONFIG, OAuth2ProviderSchema } = args;
58
-
59
- // Notify the worker when an app create/update changed Pub/Sub resources, and strip the
60
- // internal marker from the API response
61
- let applyPubSubUpdates = async result => {
62
- if (result && result.pubsubUpdates) {
63
- if (Object.keys(result.pubsubUpdates).length > 0) {
64
- await call({ cmd: 'googlePubSub', app: result.id });
65
- }
66
- delete result.pubsubUpdates;
67
- }
68
- return result;
69
- };
56
+ function registerListOAuth2Apps(server, ctx) {
57
+ const { CORS_CONFIG, OAuth2ProviderSchema } = ctx;
70
58
 
71
59
  server.route({
72
60
  method: 'GET',
@@ -212,6 +200,10 @@ async function init(args) {
212
200
  }
213
201
  }
214
202
  });
203
+ }
204
+
205
+ function registerGetOAuth2App(server, ctx) {
206
+ const { CORS_CONFIG, OAuth2ProviderSchema } = ctx;
215
207
 
216
208
  server.route({
217
209
  method: 'GET',
@@ -338,6 +330,10 @@ async function init(args) {
338
330
  }
339
331
  }
340
332
  });
333
+ }
334
+
335
+ function registerCreateOAuth2App(server, ctx) {
336
+ const { CORS_CONFIG, applyPubSubUpdates } = ctx;
341
337
 
342
338
  server.route({
343
339
  method: 'POST',
@@ -396,6 +392,10 @@ async function init(args) {
396
392
  }
397
393
  }
398
394
  });
395
+ }
396
+
397
+ function registerUpdateOAuth2App(server, ctx) {
398
+ const { CORS_CONFIG, applyPubSubUpdates } = ctx;
399
399
 
400
400
  server.route({
401
401
  method: 'PUT',
@@ -476,7 +476,7 @@ async function init(args) {
476
476
  .trim()
477
477
  .empty('')
478
478
  .max(256)
479
- .example('boT7Q~dUljnfFdVuqpC11g8nGMjO8kpRAv-ZB')
479
+ .example('example-client-secret')
480
480
  .description('Client secret for 3-legged OAuth2 applications'),
481
481
 
482
482
  pubSubApp: Joi.string()
@@ -559,6 +559,10 @@ async function init(args) {
559
559
  }
560
560
  }
561
561
  });
562
+ }
563
+
564
+ function registerDeleteOAuth2App(server, ctx) {
565
+ const { call, CORS_CONFIG } = ctx;
562
566
 
563
567
  server.route({
564
568
  method: 'DELETE',
@@ -626,6 +630,10 @@ async function init(args) {
626
630
  }
627
631
  }
628
632
  });
633
+ }
634
+
635
+ function registerVerifyOAuth2App(server, ctx) {
636
+ const { CORS_CONFIG } = ctx;
629
637
 
630
638
  server.route({
631
639
  method: 'POST',
@@ -716,4 +724,29 @@ async function init(args) {
716
724
  });
717
725
  }
718
726
 
727
+ async function init(args) {
728
+ const { server, call, CORS_CONFIG, OAuth2ProviderSchema } = args;
729
+
730
+ // Notify the worker when an app create/update changed Pub/Sub resources, and strip the
731
+ // internal marker from the API response
732
+ let applyPubSubUpdates = async result => {
733
+ if (result && result.pubsubUpdates) {
734
+ if (Object.keys(result.pubsubUpdates).length > 0) {
735
+ await call({ cmd: 'googlePubSub', app: result.id });
736
+ }
737
+ delete result.pubsubUpdates;
738
+ }
739
+ return result;
740
+ };
741
+
742
+ const ctx = { call, CORS_CONFIG, OAuth2ProviderSchema, applyPubSubUpdates };
743
+
744
+ registerListOAuth2Apps(server, ctx);
745
+ registerGetOAuth2App(server, ctx);
746
+ registerCreateOAuth2App(server, ctx);
747
+ registerUpdateOAuth2App(server, ctx);
748
+ registerDeleteOAuth2App(server, ctx);
749
+ registerVerifyOAuth2App(server, ctx);
750
+ }
751
+
719
752
  module.exports = init;