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
@@ -7,14 +7,65 @@
7
7
  // base URL used in the code samples) is applied later, in lib/api-reference/index.js.
8
8
 
9
9
  const { formatDescription, slugify, tagUrl, operationUrl, methodVariant, constraintList, stringifyExample } = require('./format');
10
- const { buildSchemaTree, buildExample, typeLabel, enumInfo, requiredFirst } = require('./schema-tree');
10
+ const { buildSchemaTree, buildExample, typeLabel, enumInfo, requiredFirst, rowExample, itemExampleFor } = require('./schema-tree');
11
11
  const { readCodeSamples } = require('./code-samples');
12
12
  const { NOTES_SEPARATOR } = require('../openapi');
13
+ const { IMPACT, resolveImpact } = require('../api-routes/operation-impact');
13
14
 
14
15
  const METHOD_ORDER = ['get', 'post', 'put', 'patch', 'delete', 'options', 'head'];
15
16
 
16
17
  const JSON_CONTENT_TYPE = 'application/json';
17
18
 
19
+ // What the Try it panel says before you press Send, keyed on the operation's resolved impact.
20
+ // The resolution - declared `x-ee-impact` if there is one, otherwise the HTTP method default -
21
+ // belongs to lib/api-routes/operation-impact.js, because the token permission model narrows on
22
+ // the same value. Deriving the method default here as well is how a route ends up classified one
23
+ // way for this banner and another way for access control.
24
+ //
25
+ // Every panel used to carry the same warning - "requests run against this instance with real
26
+ // data" - on all 82 operations, 42 of which only read. A warning that fires on GET /v1/stats
27
+ // is how a reader learns to skim past the one on DELETE /v1/account/{account}, and it
28
+ // described the mechanism (this is a real POST) rather than the consequence. Weight now
29
+ // tracks consequence: nothing on a read, one muted line on an ordinary write, a real warning
30
+ // where the effect cannot be taken back.
31
+ // `warn` picks the rendering in reference/try-it: an alert box when true, one muted line
32
+ // otherwise. A boolean rather than a level string because the template can branch on it with
33
+ // a plain {{#if}}, and this codebase has no comparison helper to test a string against.
34
+ // `confirm` puts a confirmation step in front of Send, on the operations whose effect cannot
35
+ // be taken back. Every field arrives prefilled from the schema example, so
36
+ // DELETE /v1/account/{account} sits one click from a real deletion with nothing in between.
37
+ //
38
+ // Sending is behind the same dialog, and the draft submit is the reason. Its body is
39
+ // entirely optional overrides - the stored draft already carries its own recipients, and
40
+ // lib/api-routes/submit-routes.js says as much - so Send there mails people the reader never
41
+ // typed and cannot see anywhere in the panel. Handing that a lighter treatment than a DELETE
42
+ // would have the guard weakest exactly where the request says least about itself.
43
+ //
44
+ // The dialog shows the resolved request, method and path with the values actually in the
45
+ // form, plus the body when there is one: "delete this account?" is a weaker question than
46
+ // "DELETE /v1/account/user123?".
47
+ const TRY_IMPACT = {
48
+ [IMPACT.DESTRUCTIVE]: { warn: true, confirm: true, text: 'This permanently removes data from this instance. It cannot be undone from here.' },
49
+ [IMPACT.SENDS]: { warn: true, confirm: true, text: 'This sends real email. Messages reach the recipients in the request, not a sandbox.' },
50
+ [IMPACT.READONLY]: null, // reads only, so the panel says nothing at all
51
+ [IMPACT.WRITE]: { warn: false, text: 'Runs against live data on this instance.' }
52
+ };
53
+
54
+ function tryImpact(operation, method) {
55
+ // An unresolvable impact lands on the same `null` as READONLY, which is safe only because a
56
+ // route cannot declare a bad impact and reach a release: test/api-reference-test.js asserts
57
+ // every declaration against DECLARABLE_IMPACTS.
58
+ return TRY_IMPACT[resolveImpact(operation['x-ee-impact'], method)] || null;
59
+ }
60
+
61
+ // A parameter group this long, whose members are all the same type and carry no
62
+ // documentation of their own, is one decision rather than N of them. GET /v1/settings takes
63
+ // 87 boolean query parameters that select which settings come back; rendered a row each they
64
+ // were roughly 260 lines of page at the same visual weight as parameters that carry a real
65
+ // choice, and they pushed the response schema three screens down. Matched on shape rather
66
+ // than on the endpoint, so anything similar added later is covered too.
67
+ const FLAG_GROUP_MIN = 12;
68
+
18
69
  function statusVariant(code) {
19
70
  const numeric = Number(code);
20
71
  if (numeric >= 200 && numeric < 300) {
@@ -48,6 +99,7 @@ function pickContent(content) {
48
99
 
49
100
  function buildParameter(spec, parameter, operationId) {
50
101
  const schema = parameter.schema || {};
102
+ const enums = enumInfo(schema);
51
103
 
52
104
  const view = {
53
105
  name: parameter.name,
@@ -56,17 +108,25 @@ function buildParameter(spec, parameter, operationId) {
56
108
  required: !!parameter.required,
57
109
  typeLabel: typeLabel(spec, schema),
58
110
  descriptionHtml: formatDescription(parameter.description || schema.description),
111
+ usageHtml: formatDescription(schema['x-meta'] && schema['x-meta'].usage),
59
112
  constraints: constraintList(schema),
60
113
  deprecated: !!parameter.deprecated,
114
+ // Shown on the row, under the same rules a schema property gets. A parameter is
115
+ // built with a tree node's field names on purpose - reference/params renders it
116
+ // through reference/schema-node - so the example belongs here too. Nothing
117
+ // inherits: a parameter has no ancestor to inherit from.
118
+ example: rowExample(schema, { itemExample: itemExampleFor(spec, schema, []), enums }),
61
119
  // Booleans and enums render as a select in the try-it form, not a text field
62
120
  isBoolean: schema.type === 'boolean'
63
121
  };
64
122
 
65
- const enums = enumInfo(schema);
66
- if (enums) {
123
+ if (enums && enums.values.length) {
67
124
  view.enumValues = enums.values;
68
125
  view.enumDocumented = enums.documented;
69
126
  }
127
+ if (enums && enums.alsoAccepts.length) {
128
+ view.alsoAccepts = enums.alsoAccepts;
129
+ }
70
130
 
71
131
  if (typeof schema.default !== 'undefined') {
72
132
  view.defaultValue = typeof schema.default === 'string' ? schema.default : JSON.stringify(schema.default);
@@ -88,6 +148,32 @@ function buildParameter(spec, parameter, operationId) {
88
148
  return view;
89
149
  }
90
150
 
151
+ // Names of a parameter group that is a flag list rather than N documented parameters, or
152
+ // null when the group is anything else. See FLAG_GROUP_MIN.
153
+ //
154
+ // The boolean and default-false tests are not incidental: reference/params renders the group
155
+ // under a fixed sentence telling the reader to set the ones they want to `true`. A predicate
156
+ // looser than that sentence would eventually match a group of undocumented strings and
157
+ // describe it wrongly, having also dropped each member's type, default and anchor. Predicate
158
+ // and prose have to mean the same thing.
159
+ function flagNames(parameters) {
160
+ if (parameters.length < FLAG_GROUP_MIN) {
161
+ return null;
162
+ }
163
+
164
+ const uniform = parameters.every(
165
+ parameter =>
166
+ parameter.typeLabel === 'boolean' &&
167
+ parameter.defaultValue === 'false' &&
168
+ !parameter.descriptionHtml &&
169
+ !parameter.required &&
170
+ !parameter.deprecated &&
171
+ !parameter.enumValues
172
+ );
173
+
174
+ return uniform ? parameters.map(parameter => parameter.name) : null;
175
+ }
176
+
91
177
  function buildBody(spec, requestBody, operationId) {
92
178
  if (!requestBody) {
93
179
  return null;
@@ -99,14 +185,39 @@ function buildBody(spec, requestBody, operationId) {
99
185
  }
100
186
 
101
187
  const schema = picked.media.schema;
102
- const exampleValue = typeof picked.media.example !== 'undefined' ? picked.media.example : buildExample(spec, schema);
188
+ // Whether the route declared the whole payload itself, in which case neither view is
189
+ // synthesized and there is nothing to offer a second tab for
190
+ const curated = typeof picked.media.example !== 'undefined';
191
+ const exampleValue = curated ? picked.media.example : buildExample(spec, schema);
192
+ const tree = buildSchemaTree(spec, schema, `${operationId}.body`);
193
+
194
+ // The curated payload answers "what does a normal call look like" and is the right
195
+ // default. It cannot also answer "what else can I send", because an object-level
196
+ // `.example()` stops the descent, so every key its author left out is invisible: 10 of
197
+ // 71 fields on POST /v1/account/{account}/submit, 8 of 62 on PUT /v1/account/{account},
198
+ // 466 of 651 across all request bodies. The complete view fills the rest in from the
199
+ // per-property examples, curated values still winning wherever they exist.
200
+ //
201
+ // Only offered when it actually differs, which is 8 bodies of the document's 34 - on the
202
+ // rest the typical payload already names every field and a second identical tab would be
203
+ // a control that does nothing.
204
+ const completeValue = curated ? undefined : buildExample(spec, schema, { complete: true });
205
+ const exampleJson = stringifyExample(exampleValue);
206
+ const completeJson = stringifyExample(completeValue);
103
207
 
104
208
  return {
105
209
  contentType: picked.contentType,
106
210
  descriptionHtml: formatDescription(requestBody.description),
107
- tree: buildSchemaTree(spec, schema, `${operationId}.body`),
211
+ tree,
212
+ scopeId: `${operationId}-body-schema`,
108
213
  exampleValue,
109
- exampleJson: stringifyExample(exampleValue)
214
+ exampleJson,
215
+ completeJson: completeJson !== exampleJson ? completeJson : '',
216
+ // Panel ids for the two views. Built here for the same reason the response tab ids
217
+ // are: ui/tabs neutralizes its own hash params inside the partial block, which puts
218
+ // the operation id out of reach for composing them there.
219
+ exampleTabId: `${operationId}-body-example`,
220
+ completeTabId: `${operationId}-body-example-full`
110
221
  };
111
222
  }
112
223
 
@@ -125,18 +236,21 @@ function buildResponses(spec, responses, operationId) {
125
236
  const schema = picked && picked.media.schema;
126
237
  const exampleValue = picked && typeof picked.media.example !== 'undefined' ? picked.media.example : buildExample(spec, schema);
127
238
 
239
+ // Property trees are built for success responses only. The document has 474
240
+ // non-2xx responses sharing 8 distinct shapes - all variations on the
241
+ // {statusCode, error, message} envelope - so expanding them per operation
242
+ // added 2,400 of a tag page's 4,400 tree nodes and a quarter of its bytes to
243
+ // restate the same thing. The error envelope is documented once on the
244
+ // landing page, and each response still carries its own example.
245
+ const tree = schema && variant === 'success' ? buildSchemaTree(spec, schema, `${operationId}.resp.${code}`) : null;
246
+
128
247
  return {
129
248
  code,
130
249
  variant,
131
250
  descriptionHtml: formatDescription(response.description),
132
251
  contentType: picked ? picked.contentType : null,
133
- // Property trees are built for success responses only. The document has 474
134
- // non-2xx responses sharing 8 distinct shapes - all variations on the
135
- // {statusCode, error, message} envelope - so expanding them per operation
136
- // added 2,400 of a tag page's 4,400 tree nodes and a quarter of its bytes to
137
- // restate the same thing. The error envelope is documented once on the
138
- // landing page, and each response still carries its own example.
139
- tree: schema && variant === 'success' ? buildSchemaTree(spec, schema, `${operationId}.resp.${code}`) : null,
252
+ tree,
253
+ scopeId: `${operationId}-resp-${code}-schema`,
140
254
  exampleJson: schema ? stringifyExample(exampleValue) : ''
141
255
  };
142
256
  });
@@ -156,6 +270,13 @@ function buildOperation(spec, path, method, operation, tagName) {
156
270
 
157
271
  const parameters = (operation.parameters || []).map(parameter => buildParameter(spec, parameter, id));
158
272
 
273
+ // Path parameters keep their order in the path, which is the only order that makes
274
+ // sense for them. The other two are grouped required-first: GET /v1/settings carries
275
+ // 87 query parameters, and the handful that are mandatory should not be buried.
276
+ const pathParams = parameters.filter(parameter => parameter.in === 'path');
277
+ const queryParams = requiredFirst(parameters.filter(parameter => parameter.in === 'query'));
278
+ const headerParams = requiredFirst(parameters.filter(parameter => parameter.in === 'header'));
279
+
159
280
  const body = buildBody(spec, operation.requestBody, id);
160
281
 
161
282
  // Behavior notes (lib/api-routes/behavior-notes.js): things the schemas cannot express,
@@ -182,18 +303,22 @@ function buildOperation(spec, path, method, operation, tagName) {
182
303
  method: method.toLowerCase(),
183
304
  methodLabel: method.toUpperCase(),
184
305
  methodVariant: methodVariant(method),
306
+ // What the Try it panel warns about, if anything
307
+ tryImpact: tryImpact(operation, method),
185
308
  path,
186
309
  summary: operation.summary || '',
187
310
  descriptionHtml: formatDescription(prose.join('\n\n')),
188
311
  deprecated: !!operation.deprecated,
189
312
  tag: tagName,
190
313
  tagSlug: slugify(tagName),
191
- // Path parameters keep their order in the path, which is the only order that makes
192
- // sense for them. The other two are grouped required-first: GET /v1/settings carries
193
- // 106 query parameters, and the handful that are mandatory should not be buried.
194
- pathParams: parameters.filter(parameter => parameter.in === 'path'),
195
- queryParams: requiredFirst(parameters.filter(parameter => parameter.in === 'query')),
196
- headerParams: requiredFirst(parameters.filter(parameter => parameter.in === 'header')),
314
+ pathParams,
315
+ queryParams,
316
+ headerParams,
317
+ // Set only when the group is really a flag list; reference/params renders those as a
318
+ // chip grid instead of a row each. Query only: flagNames() needs an optional group,
319
+ // and lib/openapi/build-document.js marks every path parameter required, while the
320
+ // largest header group in the document is two entries.
321
+ queryFlags: flagNames(queryParams),
197
322
  body,
198
323
  responses: buildResponses(spec, operation.responses, id)
199
324
  };