emailengine-app 2.76.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 (102) hide show
  1. package/.github/workflows/release.yaml +24 -19
  2. package/.ncurc.js +14 -2
  3. package/.release-please-manifest.json +3 -0
  4. package/CHANGELOG.md +23 -0
  5. package/README.md +1 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/encrypt.js +71 -4
  8. package/lib/address-strategies.js +18 -0
  9. package/lib/api-reference/code-samples.js +194 -0
  10. package/lib/api-reference/format.js +179 -0
  11. package/lib/api-reference/index.js +205 -0
  12. package/lib/api-reference/model.js +336 -0
  13. package/lib/api-reference/schema-tree.js +366 -0
  14. package/lib/api-routes/account-routes.js +117 -37
  15. package/lib/api-routes/behavior-notes.js +54 -0
  16. package/lib/api-routes/blocklist-routes.js +9 -9
  17. package/lib/api-routes/changes-routes.js +6 -4
  18. package/lib/api-routes/chat-routes.js +3 -3
  19. package/lib/api-routes/delivery-test-routes.js +24 -6
  20. package/lib/api-routes/export-routes.js +14 -12
  21. package/lib/api-routes/gateway-routes.js +11 -11
  22. package/lib/api-routes/license-routes.js +7 -7
  23. package/lib/api-routes/mailbox-routes.js +18 -9
  24. package/lib/api-routes/message-routes.js +55 -35
  25. package/lib/api-routes/oauth2-app-routes.js +22 -16
  26. package/lib/api-routes/outbox-routes.js +7 -7
  27. package/lib/api-routes/pubsub-routes.js +3 -3
  28. package/lib/api-routes/settings-routes.js +10 -9
  29. package/lib/api-routes/stats-routes.js +3 -3
  30. package/lib/api-routes/submit-routes.js +58 -8
  31. package/lib/api-routes/template-routes.js +13 -13
  32. package/lib/api-routes/token-routes.js +15 -10
  33. package/lib/api-routes/webhook-route-routes.js +5 -5
  34. package/lib/consts.js +7 -0
  35. package/lib/email-client/base-client.js +66 -12
  36. package/lib/enum-descriptions.js +130 -0
  37. package/lib/imapproxy/imap-server.js +30 -26
  38. package/lib/imapproxy/upstream-client.js +38 -0
  39. package/lib/oauth2-apps.js +9 -3
  40. package/lib/openapi/build-document.js +318 -0
  41. package/lib/openapi/index.js +95 -0
  42. package/lib/openapi/joi-schema.js +523 -0
  43. package/lib/routes-ui.js +5 -1
  44. package/lib/schemas.js +76 -17
  45. package/lib/swagger-options.js +173 -0
  46. package/lib/tokens.js +69 -5
  47. package/lib/ui-routes/admin-entities-routes.js +3 -0
  48. package/lib/ui-routes/dashboard-routes.js +2 -26
  49. package/lib/ui-routes/reference-routes.js +195 -0
  50. package/lib/ui-routes/route-helpers.js +11 -0
  51. package/package.json +9 -11
  52. package/prepare-bundle-deps.sh +28 -0
  53. package/release-please-config.json +11 -0
  54. package/sbom.json +0 -1
  55. package/server.js +10 -2
  56. package/static/css/flyonui.css +1 -1
  57. package/static/css/src/app.tailwind.css +90 -0
  58. package/static/js/ee-client.js +238 -8
  59. package/static/js/reference.js +736 -0
  60. package/static/js/ui.js +61 -33
  61. package/static/licenses.html +4 -4
  62. package/translations/messages.pot +27 -27
  63. package/views/config/ai.hbs +1 -1
  64. package/views/config/document-store/chat.hbs +5 -5
  65. package/views/config/document-store/index.hbs +2 -2
  66. package/views/config/document-store/pre-processing/index.hbs +1 -1
  67. package/views/config/email-processing.hbs +1 -1
  68. package/views/config/imap-proxy.hbs +1 -1
  69. package/views/config/license.hbs +1 -1
  70. package/views/config/oauth/index.hbs +3 -3
  71. package/views/config/security.hbs +1 -1
  72. package/views/config/smtp.hbs +2 -2
  73. package/views/dashboard.hbs +1 -1
  74. package/views/layout/app.hbs +18 -7
  75. package/views/partials/oauth_form.hbs +4 -4
  76. package/views/partials/reference/anchor-link.hbs +20 -0
  77. package/views/partials/reference/disclosure.hbs +37 -0
  78. package/views/partials/reference/nav.hbs +93 -0
  79. package/views/partials/reference/operation.hbs +127 -0
  80. package/views/partials/reference/params.hbs +20 -0
  81. package/views/partials/reference/schema-node.hbs +99 -0
  82. package/views/partials/reference/schema.hbs +19 -0
  83. package/views/partials/reference/section-heading.hbs +16 -0
  84. package/views/partials/reference/token-alert.hbs +24 -0
  85. package/views/partials/reference/try-field.hbs +31 -0
  86. package/views/partials/reference/try-it.hbs +78 -0
  87. package/views/partials/side_menu.hbs +1 -1
  88. package/views/partials/ui/badge.hbs +4 -2
  89. package/views/partials/ui/page-header.hbs +1 -1
  90. package/views/partials/ui/search-input.hbs +31 -0
  91. package/views/partials/ui/setting-ref.hbs +1 -1
  92. package/views/partials/ui/stat-card.hbs +4 -2
  93. package/views/partials/ui/tab.hbs +6 -1
  94. package/views/partials/ui/tabs.hbs +2 -2
  95. package/views/reference/index.hbs +76 -0
  96. package/views/reference/redirect.hbs +49 -0
  97. package/views/reference/tag.hbs +28 -0
  98. package/views/reference/token.hbs +49 -0
  99. package/views/tokens/index.hbs +9 -1
  100. package/views/webhooks/index.hbs +3 -3
  101. package/workers/api.js +37 -215
  102. package/views/swagger/index.hbs +0 -82
@@ -0,0 +1,366 @@
1
+ 'use strict';
2
+
3
+ // Turns an OpenAPI schema into the two things the reference pages render: a nested
4
+ // property tree and a synthesized JSON example.
5
+ //
6
+ // The generated document (lib/openapi/) uses a small corner of OpenAPI: no allOf, no
7
+ // oneOf, no discriminator, no additionalProperties and no recursive schemas. This module
8
+ // deliberately handles exactly that subset plus the guards needed so a future schema
9
+ // that breaks those assumptions degrades into a visible marker instead of hanging the
10
+ // worker.
11
+
12
+ const { formatDescription, constraintList } = require('./format');
13
+ const { SCHEMA_REF_PREFIX } = require('../openapi');
14
+
15
+ // Depth cap for both the property tree and the example. The deepest schema in the
16
+ // current document nests 9 levels, so this only trips on something new.
17
+ const MAX_DEPTH = 14;
18
+
19
+ // Nested property groups render inside a <details>. The first levels start open so the
20
+ // shape of a payload is visible without clicking; deeper ones start collapsed so a
21
+ // large schema (GET /v1/settings carries 104 properties) does not bury the page.
22
+ const OPEN_BY_DEFAULT_DEPTH = 2;
23
+
24
+ // Placeholder values for string formats that have no example of their own, so a
25
+ // synthesized example still shows the expected shape rather than a wall of "string".
26
+ const FORMAT_PLACEHOLDERS = {
27
+ 'date-time': '2026-01-15T09:30:00.000Z',
28
+ date: '2026-01-15',
29
+ email: 'user@example.com',
30
+ uri: 'https://example.com',
31
+ hostname: 'example.com',
32
+ ipv4: '127.0.0.1',
33
+ ipv6: '::1',
34
+ uuid: '00000000-0000-0000-0000-000000000000',
35
+ guid: '00000000-0000-0000-0000-000000000000',
36
+ byte: 'aGVsbG8=',
37
+ binary: '<binary>',
38
+ password: 'secret'
39
+ };
40
+
41
+ // Resolves a local $ref against the document. Every named schema lives in one place, so an
42
+ // unresolvable ref means the document is malformed rather than that another bucket needs
43
+ // looking in - buildNode() surfaces that as a visible marker.
44
+ function lookupRef(spec, ref) {
45
+ if (typeof ref !== 'string' || !ref.startsWith(SCHEMA_REF_PREFIX)) {
46
+ return null;
47
+ }
48
+
49
+ const name = ref.slice(SCHEMA_REF_PREFIX.length);
50
+
51
+ return (spec.components && spec.components.schemas && spec.components.schemas[name]) || null;
52
+ }
53
+
54
+ // Follows a $ref chain to the underlying schema. `refStack` carries the refs already
55
+ // visited on the current branch; revisiting one means the document is recursive, which
56
+ // is reported rather than followed.
57
+ function resolve(spec, schema, refStack) {
58
+ let current = schema;
59
+ let stack = refStack;
60
+
61
+ while (current && typeof current === 'object' && current.$ref) {
62
+ const ref = current.$ref;
63
+ if (stack.includes(ref)) {
64
+ return { schema: null, refStack: stack, circular: true };
65
+ }
66
+
67
+ const target = lookupRef(spec, ref);
68
+ if (!target) {
69
+ return { schema: null, refStack: stack, unresolved: ref };
70
+ }
71
+
72
+ stack = stack.concat(ref);
73
+ current = target;
74
+ }
75
+
76
+ return { schema: current, refStack: stack };
77
+ }
78
+
79
+ // Human-readable type for a schema node. Arrays name their item type so a property row
80
+ // reads "array of object" instead of a bare "array".
81
+ //
82
+ // This lives here rather than in format.js because it has to follow $refs to be correct:
83
+ // 46 array properties in the document have `items: {$ref}`, and an anyOf's branches are
84
+ // refs too. format.js is deliberately spec-free, so a copy there could only ever answer
85
+ // "any" for those - which it did, until buildNode() patched the result afterwards. One
86
+ // ref-aware implementation replaces that and the two overrides it needed.
87
+ function typeLabel(spec, schema, refStack = []) {
88
+ const resolved = resolve(spec, schema, refStack);
89
+ const target = resolved.schema;
90
+
91
+ if (!target || typeof target !== 'object') {
92
+ return 'any';
93
+ }
94
+
95
+ if (Array.isArray(target.anyOf) && target.anyOf.length) {
96
+ return target.anyOf.map(entry => typeLabel(spec, entry, resolved.refStack)).join(' or ');
97
+ }
98
+
99
+ if (target.type === 'array') {
100
+ return `array of ${target.items ? typeLabel(spec, target.items, resolved.refStack) : 'any'}`;
101
+ }
102
+
103
+ if (target.enum && target.enum.length && !target.type) {
104
+ return 'enum';
105
+ }
106
+
107
+ return target.type || 'any';
108
+ }
109
+
110
+ // Enum values with their per-value documentation, when the joi schema carries any.
111
+ // `.meta({ enumDescriptions })` in lib/schemas.js surfaces as `x-meta.enumDescriptions`
112
+ // beside the `enum` array - OpenAPI itself has no field for documenting individual values.
113
+ // Returns null when the schema is not an enum, so callers can assign both fields in one go.
114
+ function enumInfo(schema) {
115
+ if (!Array.isArray(schema.enum) || !schema.enum.length) {
116
+ return null;
117
+ }
118
+
119
+ const documented = (schema['x-meta'] && schema['x-meta'].enumDescriptions) || {};
120
+
121
+ // Object.hasOwn, not a bare lookup: an enum value named `constructor` or `toString`
122
+ // would otherwise pick up an inherited function and render as garbage.
123
+ const values = schema.enum.map(value => {
124
+ const key = typeof value === 'string' ? value : JSON.stringify(value);
125
+ return { value: key, description: Object.hasOwn(documented, key) ? documented[key] : null };
126
+ });
127
+
128
+ return { values, documented: values.some(entry => entry.description) };
129
+ }
130
+
131
+ // Required entries first, declared order preserved within each group (Array#sort is
132
+ // stable). "What do I have to send" is the first question a schema answers, and a
133
+ // payload like SubmitMessage has 33 properties of which 0 to 3 are required - finding
134
+ // them meant reading every row.
135
+ //
136
+ // Exported because operation parameters get the same treatment in model.js: they are
137
+ // deliberately built with the same field names as a tree node so they can render through
138
+ // the same partial, which makes this the right place for the ordering rule too.
139
+ function requiredFirst(nodes) {
140
+ return nodes.sort((a, b) => Number(b.required) - Number(a.required));
141
+ }
142
+
143
+ // The properties to show underneath a node: an object's own properties, or - for an
144
+ // array of objects - the item properties, so an array row expands straight into the
145
+ // item shape instead of an intermediate "items" level.
146
+ function childSource(spec, schema, refStack) {
147
+ if (!schema || typeof schema !== 'object') {
148
+ return null;
149
+ }
150
+
151
+ if (schema.type === 'array' && schema.items) {
152
+ const resolved = resolve(spec, schema.items, refStack);
153
+ if (resolved.schema && resolved.schema.properties) {
154
+ return { schema: resolved.schema, refStack: resolved.refStack };
155
+ }
156
+ return null;
157
+ }
158
+
159
+ if (schema.properties) {
160
+ return { schema, refStack };
161
+ }
162
+
163
+ return null;
164
+ }
165
+
166
+ function buildNode(spec, rawSchema, options) {
167
+ const { name, required, depth, refStack, path } = options;
168
+
169
+ const resolved = resolve(spec, rawSchema, refStack);
170
+
171
+ const node = {
172
+ name: name || null,
173
+ // Anchor id for this property, dotted from the tree root - see buildSchemaTree()
174
+ anchor: path || null,
175
+ required: !!required,
176
+ openByDefault: depth < OPEN_BY_DEFAULT_DEPTH,
177
+ circular: !!resolved.circular,
178
+ unresolved: resolved.unresolved || null,
179
+ truncated: false,
180
+ children: [],
181
+ variants: []
182
+ };
183
+
184
+ const schema = resolved.schema;
185
+ if (!schema || typeof schema !== 'object') {
186
+ node.typeLabel = node.circular ? 'circular reference' : 'any';
187
+ node.descriptionHtml = '';
188
+ node.constraints = [];
189
+ return node;
190
+ }
191
+
192
+ node.typeLabel = typeLabel(spec, schema, resolved.refStack);
193
+
194
+ node.descriptionHtml = formatDescription(schema.description);
195
+ node.constraints = constraintList(schema);
196
+ node.deprecated = !!schema.deprecated;
197
+ node.nullable = !!schema.nullable;
198
+
199
+ const enums = enumInfo(schema);
200
+ if (enums) {
201
+ node.enumValues = enums.values;
202
+ node.enumDocumented = enums.documented;
203
+ }
204
+
205
+ if (typeof schema.default !== 'undefined') {
206
+ node.defaultValue = typeof schema.default === 'string' ? schema.default : JSON.stringify(schema.default);
207
+ }
208
+
209
+ if (depth >= MAX_DEPTH) {
210
+ node.truncated = true;
211
+ return node;
212
+ }
213
+
214
+ if (Array.isArray(schema.anyOf) && schema.anyOf.length) {
215
+ node.variants = schema.anyOf.map((variant, index) =>
216
+ buildNode(spec, variant, {
217
+ name: `option ${index + 1}`,
218
+ required: false,
219
+ depth: depth + 1,
220
+ refStack: resolved.refStack,
221
+ // The index, not the display name: an anchor cannot carry the space in
222
+ // "option 1", and two variants would otherwise share the parent's path
223
+ path: path ? `${path}.option${index + 1}` : null
224
+ })
225
+ );
226
+ return node;
227
+ }
228
+
229
+ const source = childSource(spec, schema, resolved.refStack);
230
+ if (source) {
231
+ const requiredNames = Array.isArray(source.schema.required) ? source.schema.required : [];
232
+ node.children = requiredFirst(
233
+ Object.keys(source.schema.properties).map(propertyName =>
234
+ buildNode(spec, source.schema.properties[propertyName], {
235
+ name: propertyName,
236
+ required: requiredNames.includes(propertyName),
237
+ depth: depth + 1,
238
+ refStack: source.refStack,
239
+ path: path ? `${path}.${propertyName}` : null
240
+ })
241
+ )
242
+ );
243
+
244
+ // Composed here rather than in the template: Handlebars has no inline
245
+ // conditional that can pluralize "property" without a block helper, and the
246
+ // disclosure partial takes its summary as a plain string
247
+ node.childLabel = `${node.children.length} ${node.children.length === 1 ? 'property' : 'properties'}`;
248
+ }
249
+
250
+ return node;
251
+ }
252
+
253
+ // Public entry point: property tree for a schema, or null when there is no schema.
254
+ //
255
+ // `path` is the anchor prefix for the tree, e.g. "accountCreate.body". Every node below
256
+ // it gets a dotted id built from the property names on the way down, which is what makes
257
+ // an individual field linkable ("#accountCreate.body.imap.tls.rejectUnauthorized"). The
258
+ // ids are derived from the schema alone, so they stay stable as long as the field does.
259
+ // Passing no prefix leaves every anchor null and the rows render without a link.
260
+ function buildSchemaTree(spec, schema, path) {
261
+ if (!schema) {
262
+ return null;
263
+ }
264
+
265
+ return buildNode(spec, schema, { name: null, required: false, depth: 0, refStack: [], path: path || null });
266
+ }
267
+
268
+ function scalarExample(schema) {
269
+ if (typeof schema.default !== 'undefined') {
270
+ return schema.default;
271
+ }
272
+
273
+ if (Array.isArray(schema.enum) && schema.enum.length) {
274
+ return schema.enum[0];
275
+ }
276
+
277
+ switch (schema.type) {
278
+ case 'boolean':
279
+ return false;
280
+ case 'integer':
281
+ case 'number':
282
+ if (typeof schema.minimum === 'number') {
283
+ return schema.minimum;
284
+ }
285
+ return 0;
286
+ case 'string': {
287
+ if (schema.format && FORMAT_PLACEHOLDERS[schema.format]) {
288
+ return FORMAT_PLACEHOLDERS[schema.format];
289
+ }
290
+ const xFormat = schema['x-format'];
291
+ if (xFormat && typeof xFormat === 'object') {
292
+ for (const key of Object.keys(xFormat)) {
293
+ if (FORMAT_PLACEHOLDERS[key]) {
294
+ return FORMAT_PLACEHOLDERS[key];
295
+ }
296
+ }
297
+ }
298
+ return 'string';
299
+ }
300
+ default:
301
+ return null;
302
+ }
303
+ }
304
+
305
+ function exampleFor(spec, rawSchema, depth, refStack) {
306
+ const resolved = resolve(spec, rawSchema, refStack);
307
+ const schema = resolved.schema;
308
+
309
+ if (!schema || typeof schema !== 'object') {
310
+ return null;
311
+ }
312
+
313
+ // An explicit example always wins, including on nested objects - those are the
314
+ // curated payloads the joi schemas carry.
315
+ if (typeof schema.example !== 'undefined') {
316
+ return schema.example;
317
+ }
318
+
319
+ if (depth >= MAX_DEPTH) {
320
+ return null;
321
+ }
322
+
323
+ if (Array.isArray(schema.anyOf) && schema.anyOf.length) {
324
+ return exampleFor(spec, schema.anyOf[0], depth + 1, resolved.refStack);
325
+ }
326
+
327
+ if (schema.type === 'array') {
328
+ if (!schema.items) {
329
+ return [];
330
+ }
331
+ return [exampleFor(spec, schema.items, depth + 1, resolved.refStack)];
332
+ }
333
+
334
+ if (schema.properties) {
335
+ const result = {};
336
+ for (const propertyName of Object.keys(schema.properties)) {
337
+ result[propertyName] = exampleFor(spec, schema.properties[propertyName], depth + 1, resolved.refStack);
338
+ }
339
+ return result;
340
+ }
341
+
342
+ if (schema.type === 'object') {
343
+ return {};
344
+ }
345
+
346
+ return scalarExample(schema);
347
+ }
348
+
349
+ // Public entry point: a JSON value illustrating the schema, or undefined when the
350
+ // schema carries nothing to build one from.
351
+ function buildExample(spec, schema) {
352
+ if (!schema) {
353
+ return undefined;
354
+ }
355
+
356
+ const value = exampleFor(spec, schema, 0, []);
357
+ return value === null && !schema.nullable ? undefined : value;
358
+ }
359
+
360
+ module.exports = {
361
+ buildSchemaTree,
362
+ buildExample,
363
+ typeLabel,
364
+ enumInfo,
365
+ requiredFirst
366
+ };
@@ -28,10 +28,12 @@ const {
28
28
  defaultAccountTypeSchema,
29
29
  shortMailboxesSchema,
30
30
  ACCOUNT_DISPLAY_STATES,
31
- errorResponses
31
+ apiResponses,
32
+ ENUM_DESCRIPTIONS
32
33
  } = require('../schemas');
33
34
 
34
35
  const { REDIS_PREFIX, MAX_FORM_TTL, NONCE_BYTES } = require('../consts');
36
+ const BEHAVIOR = require('./behavior-notes');
35
37
 
36
38
  // OAuth2 scope list stored on the account (accountData.oauth2.scope). Reused with a per-route
37
39
  // description/label where the same value is exposed under a different field name
@@ -177,12 +179,21 @@ async function init(args) {
177
179
 
178
180
  options: {
179
181
  description: 'Register new account',
180
- notes: 'Registers new IMAP account to be synced',
182
+ notes: ['Registers new IMAP account to be synced', BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
181
183
  tags: ['api', 'Account'],
182
184
 
183
185
  plugins: {
184
- 'hapi-swagger': {
185
- responses: errorResponses(400, 401, 403, 404, 429, 500)
186
+ openapi: {
187
+ 'x-ee-behavior': [BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
188
+ responses: apiResponses(
189
+ 'Returns the registered account, including the generated account ID when one was not supplied.',
190
+ 400,
191
+ 401,
192
+ 403,
193
+ 404,
194
+ 429,
195
+ 500
196
+ )
186
197
  }
187
198
  },
188
199
 
@@ -329,12 +340,13 @@ async function init(args) {
329
340
  },
330
341
  options: {
331
342
  description: 'Update account info',
332
- notes: 'Updates account information',
343
+ notes: ['Updates account information', BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
333
344
  tags: ['api', 'Account'],
334
345
 
335
346
  plugins: {
336
- 'hapi-swagger': {
337
- responses: errorResponses(400, 401, 403, 404, 429, 500)
347
+ openapi: {
348
+ 'x-ee-behavior': [BEHAVIOR.CREDENTIALS_VERIFIED_LATER],
349
+ responses: apiResponses('Returns the account ID. Changed credentials take effect on the next connection.', 400, 401, 403, 404, 429, 500)
338
350
  }
339
351
  },
340
352
 
@@ -441,12 +453,21 @@ async function init(args) {
441
453
  },
442
454
  options: {
443
455
  description: 'Request reconnect',
444
- notes: 'Requests connection to be reconnected',
456
+ notes: ['Requests connection to be reconnected', BEHAVIOR.SCHEDULED_ON_WORKER],
445
457
  tags: ['api', 'Account'],
446
458
 
447
459
  plugins: {
448
- 'hapi-swagger': {
449
- responses: errorResponses(400, 401, 403, 404, 429, 500)
460
+ openapi: {
461
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
462
+ responses: apiResponses(
463
+ 'Returns an acknowledgement. The reconnect is requested, not completed - watch the account state for the result.',
464
+ 400,
465
+ 401,
466
+ 403,
467
+ 404,
468
+ 429,
469
+ 500
470
+ )
450
471
  }
451
472
  },
452
473
 
@@ -504,12 +525,21 @@ async function init(args) {
504
525
  },
505
526
  options: {
506
527
  description: 'Request syncing',
507
- notes: 'Immediately trigger account syncing for IMAP accounts',
528
+ notes: ['Immediately trigger account syncing for IMAP accounts', BEHAVIOR.SCHEDULED_ON_WORKER],
508
529
  tags: ['api', 'Account'],
509
530
 
510
531
  plugins: {
511
- 'hapi-swagger': {
512
- responses: errorResponses(400, 401, 403, 404, 429, 500)
532
+ openapi: {
533
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
534
+ responses: apiResponses(
535
+ 'Returns an acknowledgement. A full mailbox sync is scheduled and runs in the background.',
536
+ 400,
537
+ 401,
538
+ 403,
539
+ 404,
540
+ 429,
541
+ 500
542
+ )
513
543
  }
514
544
  },
515
545
 
@@ -573,8 +603,16 @@ async function init(args) {
573
603
  tags: ['api', 'Account'],
574
604
 
575
605
  plugins: {
576
- 'hapi-swagger': {
577
- responses: errorResponses(400, 401, 403, 404, 429, 500)
606
+ openapi: {
607
+ responses: apiResponses(
608
+ 'Returns a deletion marker. The account stops syncing immediately; stored data is removed in the background.',
609
+ 400,
610
+ 401,
611
+ 403,
612
+ 404,
613
+ 429,
614
+ 500
615
+ )
578
616
  }
579
617
  },
580
618
 
@@ -640,12 +678,24 @@ async function init(args) {
640
678
  },
641
679
  options: {
642
680
  description: 'Request account flush',
643
- notes: 'Deletes all email indexes from Redis and ElasticSearch and re-creates the index for that account. You can only run a single flush operation at a time, so you must wait until the previous flush has finished before initiating a new one.',
681
+ notes: [
682
+ 'Deletes all email indexes from Redis and ElasticSearch and re-creates the index for that account. You can only run a single flush operation at a time, so you must wait until the previous flush has finished before initiating a new one.',
683
+ BEHAVIOR.SCHEDULED_ON_WORKER
684
+ ],
644
685
  tags: ['api', 'Account'],
645
686
 
646
687
  plugins: {
647
- 'hapi-swagger': {
648
- responses: errorResponses(400, 401, 403, 404, 429, 500)
688
+ openapi: {
689
+ 'x-ee-behavior': [BEHAVIOR.SCHEDULED_ON_WORKER],
690
+ responses: apiResponses(
691
+ 'Returns an acknowledgement. Cached message indexes are cleared and rebuilt in the background.',
692
+ 400,
693
+ 401,
694
+ 403,
695
+ 404,
696
+ 429,
697
+ 500
698
+ )
649
699
  }
650
700
  },
651
701
 
@@ -711,8 +761,8 @@ async function init(args) {
711
761
  tags: ['api', 'Account'],
712
762
 
713
763
  plugins: {
714
- 'hapi-swagger': {
715
- responses: errorResponses(400, 401, 403, 429, 500)
764
+ openapi: {
765
+ responses: apiResponses('Returns a page of accounts with their connection states.', 400, 401, 403, 429, 500)
716
766
  }
717
767
  },
718
768
 
@@ -744,6 +794,7 @@ async function init(args) {
744
794
  .valid(...ACCOUNT_DISPLAY_STATES)
745
795
  .example('connected')
746
796
  .description('Filter accounts by state')
797
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountState })
747
798
  .label('AccountState'),
748
799
  query: Joi.string().example('user@example.com').description('Filter accounts by string match').label('AccountQuery')
749
800
  }).label('AccountsFilter')
@@ -778,6 +829,7 @@ async function init(args) {
778
829
  .valid(...ACCOUNT_DISPLAY_STATES)
779
830
  .example('connected')
780
831
  .description('Account state')
832
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountState })
781
833
  .label('AccountListState'),
782
834
  webhooks: Joi.string()
783
835
  .uri({
@@ -946,12 +998,13 @@ async function init(args) {
946
998
  },
947
999
  options: {
948
1000
  description: 'Get account info',
949
- notes: 'Returns stored information about the account. Passwords are not included.',
1001
+ notes: ['Returns stored information about the account. Passwords are not included.', BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
950
1002
  tags: ['api', 'Account'],
951
1003
 
952
1004
  plugins: {
953
- 'hapi-swagger': {
954
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1005
+ openapi: {
1006
+ 'x-ee-behavior': [BEHAVIOR.NO_QUOTA_ON_API_ACCOUNTS],
1007
+ responses: apiResponses('Returns the account configuration, connection state and sync status.', 400, 401, 403, 404, 429, 500)
955
1008
  }
956
1009
  },
957
1010
 
@@ -1035,6 +1088,7 @@ async function init(args) {
1035
1088
  .valid(...ACCOUNT_DISPLAY_STATES)
1036
1089
  .example('connected')
1037
1090
  .description('Informational account state')
1091
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.accountState })
1038
1092
  .label('AccountInfoState'),
1039
1093
 
1040
1094
  smtpStatus: Joi.object({
@@ -1106,7 +1160,10 @@ async function init(args) {
1106
1160
  id: Joi.string().description('Microsoft Graph subscription ID'),
1107
1161
  expirationDateTime: Joi.date().iso().allow(null).description('When the subscription expires'),
1108
1162
  state: Joi.object({
1109
- state: Joi.string().valid('creating', 'created', 'renewing', 'error').description('Subscription state'),
1163
+ state: Joi.string()
1164
+ .valid('creating', 'created', 'renewing', 'error')
1165
+ .description('Subscription state')
1166
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.pubsubState }),
1110
1167
  time: Joi.number().description('Timestamp of last state change'),
1111
1168
  error: Joi.string().allow(null).description('Error message if state is error, null after a successful renewal'),
1112
1169
  retryCount: Joi.number().integer().description('How many times the subscription renewal has been retried'),
@@ -1183,8 +1240,16 @@ async function init(args) {
1183
1240
  tags: ['api', 'Account'],
1184
1241
 
1185
1242
  plugins: {
1186
- 'hapi-swagger': {
1187
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1243
+ openapi: {
1244
+ responses: apiResponses(
1245
+ 'Returns a valid OAuth2 access token for the account, refreshing it first if it had expired.',
1246
+ 400,
1247
+ 401,
1248
+ 403,
1249
+ 404,
1250
+ 429,
1251
+ 500
1252
+ )
1188
1253
  }
1189
1254
  },
1190
1255
 
@@ -1251,8 +1316,8 @@ async function init(args) {
1251
1316
  tags: ['api', 'Account'],
1252
1317
 
1253
1318
  plugins: {
1254
- 'hapi-swagger': {
1255
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1319
+ openapi: {
1320
+ responses: apiResponses('Returns the signatures configured on the account, as reported by the provider.', 400, 401, 403, 404, 429, 500)
1256
1321
  }
1257
1322
  },
1258
1323
 
@@ -1362,8 +1427,8 @@ async function init(args) {
1362
1427
  tags: ['api', 'Account'],
1363
1428
 
1364
1429
  plugins: {
1365
- 'hapi-swagger': {
1366
- responses: errorResponses(400, 401, 403, 404, 429, 500)
1430
+ openapi: {
1431
+ responses: apiResponses('Returns a single-use URL for the hosted authentication form.', 400, 401, 403, 404, 429, 500)
1367
1432
  }
1368
1433
  },
1369
1434
 
@@ -1448,7 +1513,7 @@ async function init(args) {
1448
1513
  },
1449
1514
  options: {
1450
1515
  description: 'Return IMAP logs for an account',
1451
- notes: 'Output is a downloadable text file',
1516
+ notes: ['Output is a downloadable text file', BEHAVIOR.IMAP_ONLY],
1452
1517
  tags: ['api', 'Logs'],
1453
1518
 
1454
1519
  auth: {
@@ -1458,9 +1523,10 @@ async function init(args) {
1458
1523
  cors: CORS_CONFIG,
1459
1524
 
1460
1525
  plugins: {
1461
- 'hapi-swagger': {
1526
+ openapi: {
1527
+ 'x-ee-behavior': [BEHAVIOR.IMAP_ONLY],
1462
1528
  produces: ['text/plain'],
1463
- responses: errorResponses(400, 401, 403, 429, 500)
1529
+ responses: apiResponses('Returns the account log as a plain text stream.', 400, 401, 403, 429, 500)
1464
1530
  }
1465
1531
  },
1466
1532
 
@@ -1496,8 +1562,15 @@ async function init(args) {
1496
1562
  tags: ['api', 'Account'],
1497
1563
 
1498
1564
  plugins: {
1499
- 'hapi-swagger': {
1500
- responses: errorResponses(400, 401, 403, 429, 500)
1565
+ openapi: {
1566
+ responses: apiResponses(
1567
+ 'Returns the outcome of the IMAP and SMTP connection tests, including per-protocol errors when a test failed.',
1568
+ 400,
1569
+ 401,
1570
+ 403,
1571
+ 429,
1572
+ 500
1573
+ )
1501
1574
  }
1502
1575
  },
1503
1576
 
@@ -1557,8 +1630,15 @@ async function init(args) {
1557
1630
  tags: ['api', 'Settings'],
1558
1631
 
1559
1632
  plugins: {
1560
- 'hapi-swagger': {
1561
- responses: errorResponses(400, 401, 403, 429, 500)
1633
+ openapi: {
1634
+ responses: apiResponses(
1635
+ 'Returns the discovered IMAP and SMTP settings for the address, or empty values when nothing could be resolved.',
1636
+ 400,
1637
+ 401,
1638
+ 403,
1639
+ 429,
1640
+ 500
1641
+ )
1562
1642
  }
1563
1643
  },
1564
1644