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
@@ -0,0 +1,179 @@
1
+ 'use strict';
2
+
3
+ // Text and value formatting helpers for the server-rendered API reference.
4
+ //
5
+ // Everything here is pure and spec-free, so it can be unit tested in isolation. Anything
6
+ // that has to follow a $ref (type labels) lives in schema-tree.js, which owns resolution.
7
+ //
8
+ // SECURITY: this module is the single place where reference text becomes HTML. The
9
+ // OpenAPI document is generated from our own joi schemas, so the strings are not
10
+ // attacker controlled, but three descriptions legitimately contain angle brackets
11
+ // (`templateHtmlHead` documents injecting into the `<head>` section) and must render
12
+ // as literal text. formatDescription() therefore escapes first and only then adds a
13
+ // fixed, closed set of tags back. Never reverse that order and never widen the tag
14
+ // set to pass markup through.
15
+ //
16
+ // Note on `marked`: the repo already renders markdown with it (the EULA page), but it
17
+ // is deliberately not used here - the escape-first ordering is the security property,
18
+ // and marked would need separate sanitization to give the same guarantee.
19
+
20
+ const he = require('he');
21
+
22
+ // Only http(s) targets become links. The input is already HTML-escaped when this runs,
23
+ // but escaping does not neutralize a `javascript:` scheme in an href, so the scheme is
24
+ // checked explicitly rather than relying on the escape pass.
25
+ function isSafeUrl(url) {
26
+ return /^https?:\/\//i.test(url);
27
+ }
28
+
29
+ // Minimal inline formatter for schema and operation descriptions. Handles the small
30
+ // subset of markdown our joi `.description()` strings actually use: backtick code
31
+ // spans, `[label](url)` links, bare URLs, and paragraph breaks. Input is escaped
32
+ // first, so the only tags in the output are the ones added here.
33
+ function formatDescription(text) {
34
+ if (!text) {
35
+ return '';
36
+ }
37
+
38
+ let html = he.escape(String(text));
39
+
40
+ // he.escape() escapes the backtick too (to `&#x60;`, for an old IE attribute quirk),
41
+ // so the code-span pass has to match the escaped form - it runs after escaping by
42
+ // design and there are no literal backticks left to find.
43
+ html = html.replace(/&#x60;([\s\S]+?)&#x60;/g, (match, code) => `<code class="ee-code">${code}</code>`);
44
+
45
+ html = html.replace(/\[([^\]]+)\]\(([^\s)]+)\)/g, (match, label, url) => {
46
+ if (!isSafeUrl(url)) {
47
+ return match;
48
+ }
49
+ return `<a href="${url}" target="_blank" rel="noopener noreferrer" class="link link-primary">${label}</a>`;
50
+ });
51
+
52
+ // Bare URLs, skipping ones already inside an href="..." emitted above
53
+ html = html.replace(/(^|[\s(])(https?:\/\/[^\s<>"')]+)/g, (match, prefix, url) => {
54
+ return `${prefix}<a href="${url}" target="_blank" rel="noopener noreferrer" class="link link-primary">${url}</a>`;
55
+ });
56
+
57
+ return html
58
+ .split(/\n{2,}/)
59
+ .map(paragraph => paragraph.replace(/\n/g, '<br>'))
60
+ .join('</p><p class="mt-2">');
61
+ }
62
+
63
+ // URL segment for a tag name: "Export (Beta)" -> "export-beta"
64
+ function slugify(value) {
65
+ return String(value || '')
66
+ .toLowerCase()
67
+ .replace(/[^a-z0-9]+/g, '-')
68
+ .replace(/^-+|-+$/g, '');
69
+ }
70
+
71
+ const METHOD_VARIANTS = {
72
+ get: 'info',
73
+ post: 'success',
74
+ put: 'warning',
75
+ patch: 'warning',
76
+ delete: 'error'
77
+ };
78
+
79
+ function methodVariant(method) {
80
+ return METHOD_VARIANTS[String(method || '').toLowerCase()] || 'neutral';
81
+ }
82
+
83
+ // "1 to 10 items" / "min 1 item" / "max 10 items", or null when neither bound is set.
84
+ function rangeChip(min, max, unit) {
85
+ const suffix = unit ? ` ${unit}` : '';
86
+
87
+ if (typeof min === 'number' && typeof max === 'number') {
88
+ return `${min} to ${max}${suffix}`;
89
+ }
90
+ if (typeof min === 'number') {
91
+ return `min ${min}${suffix}`;
92
+ }
93
+ if (typeof max === 'number') {
94
+ return `max ${max}${suffix}`;
95
+ }
96
+ return null;
97
+ }
98
+
99
+ // Short constraint chips shown next to a property. Covers both the standard OpenAPI
100
+ // keywords and the `x-*` extensions the generator emits for joi rules OpenAPI has no
101
+ // keyword for (accepted URI schemes, email format, value coercion) - real validation
102
+ // rules that generic documentation tools drop on the floor.
103
+ function constraintList(schema) {
104
+ if (!schema || typeof schema !== 'object') {
105
+ return [];
106
+ }
107
+
108
+ const chips = [];
109
+
110
+ if (schema.format) {
111
+ chips.push(schema.format);
112
+ }
113
+
114
+ for (const chip of [
115
+ rangeChip(schema.minimum, schema.maximum, ''),
116
+ rangeChip(schema.minLength, schema.maxLength, 'chars'),
117
+ rangeChip(schema.minItems, schema.maxItems, 'items')
118
+ ]) {
119
+ if (chip) {
120
+ chips.push(chip);
121
+ }
122
+ }
123
+
124
+ if (schema.pattern) {
125
+ chips.push(`pattern ${schema.pattern}`);
126
+ }
127
+
128
+ const xFormat = schema['x-format'];
129
+ if (xFormat && typeof xFormat === 'object') {
130
+ for (const key of Object.keys(xFormat)) {
131
+ const value = xFormat[key];
132
+ if (key === 'uri' && value && Array.isArray(value.scheme) && value.scheme.length) {
133
+ chips.push(`URI (${value.scheme.join(', ')})`);
134
+ } else {
135
+ chips.push(key);
136
+ }
137
+ }
138
+ }
139
+
140
+ const xConvert = schema['x-convert'];
141
+ if (xConvert && typeof xConvert === 'object') {
142
+ if (xConvert.trim) {
143
+ chips.push('trimmed');
144
+ }
145
+ if (xConvert.case === 'lower') {
146
+ chips.push('lowercased');
147
+ }
148
+ if (xConvert.case === 'upper') {
149
+ chips.push('uppercased');
150
+ }
151
+ }
152
+
153
+ if (schema['x-constraint'] && schema['x-constraint'].single) {
154
+ chips.push('single value allowed');
155
+ }
156
+
157
+ return chips;
158
+ }
159
+
160
+ // JSON rendered for the example panels. Kept here so the pretty-printing is identical
161
+ // everywhere (page body, code samples, try-it request editor).
162
+ function stringifyExample(value) {
163
+ if (typeof value === 'undefined') {
164
+ return '';
165
+ }
166
+ try {
167
+ return JSON.stringify(value, null, 2);
168
+ } catch (err) {
169
+ return '';
170
+ }
171
+ }
172
+
173
+ module.exports = {
174
+ formatDescription,
175
+ slugify,
176
+ methodVariant,
177
+ constraintList,
178
+ stringifyExample
179
+ };
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+
3
+ // Server-rendered API reference.
4
+ //
5
+ // The OpenAPI document is generated from the route joi schemas by lib/openapi/ - this
6
+ // module only reads it back (over server.inject, so there is no second source of truth)
7
+ // and turns it into a render model. The old /admin/swagger page shipped the same document
8
+ // to the browser and let swagger-ui build the DOM; here the whole page is HTML by the time
9
+ // it leaves the worker.
10
+ //
11
+ // The model is derived purely from the spec, so it is built once per API worker and
12
+ // shared. Only the code samples depend on the request, and those are applied per render.
13
+
14
+ const settings = require('../settings');
15
+ const { buildModel } = require('./model');
16
+ const { buildCodeSamples } = require('./code-samples');
17
+
18
+ const SPEC_URL = '/swagger.json';
19
+
20
+ const FALLBACK_BASE_URL = 'https://your-emailengine-host';
21
+
22
+ // The in-flight or resolved model. Caching the promise itself means concurrent first
23
+ // requests share one load; a failed load clears the slot so the next request retries.
24
+ let modelPromise = null;
25
+
26
+ async function fetchSpec(server) {
27
+ const res = await server.inject({ method: 'get', url: SPEC_URL });
28
+
29
+ if (res.statusCode !== 200) {
30
+ throw new Error(`Failed to load the API specification (HTTP ${res.statusCode})`);
31
+ }
32
+
33
+ // hapi returns the handler's own object for an in-process inject, so the JSON parse
34
+ // is only the fallback for a serialized payload
35
+ if (res.result && typeof res.result === 'object') {
36
+ return res.result;
37
+ }
38
+
39
+ return JSON.parse(res.payload);
40
+ }
41
+
42
+ function getModel(server) {
43
+ if (!modelPromise) {
44
+ modelPromise = fetchSpec(server)
45
+ .then(buildModel)
46
+ .catch(err => {
47
+ modelPromise = null;
48
+ throw err;
49
+ });
50
+ }
51
+
52
+ return modelPromise;
53
+ }
54
+
55
+ // Base address used in the generated samples. The configured public URL wins, because
56
+ // that is the address callers actually use; otherwise the request's own origin is used,
57
+ // normalized through the URL parser so a malformed Host header cannot smuggle anything
58
+ // into the rendered snippet.
59
+ //
60
+ // serviceUrl is memoized because the shared view context already reads it for every
61
+ // admin page render, so an unmemoized read here would be a second Redis round trip for
62
+ // the same value. The worker's existing settings broadcast clears it.
63
+ let cachedServiceUrl;
64
+
65
+ function clearServiceUrlCache() {
66
+ cachedServiceUrl = undefined;
67
+ }
68
+
69
+ async function resolveBaseUrl(request) {
70
+ if (typeof cachedServiceUrl === 'undefined') {
71
+ cachedServiceUrl = (await settings.get('serviceUrl')) || null;
72
+ }
73
+
74
+ const serviceUrl = cachedServiceUrl;
75
+ if (serviceUrl) {
76
+ try {
77
+ return new URL(serviceUrl).origin;
78
+ } catch (err) {
79
+ // fall through to the request origin
80
+ }
81
+ }
82
+
83
+ try {
84
+ return new URL(`${request.server.info.protocol}://${request.info.host}`).origin;
85
+ } catch (err) {
86
+ return FALLBACK_BASE_URL;
87
+ }
88
+ }
89
+
90
+ // Per-request copy of an operation carrying its code samples. The cached model is never
91
+ // mutated - samples embed the base URL, which differs between callers.
92
+ function withSamples(operation, baseUrl) {
93
+ return Object.assign({}, operation, {
94
+ samples: buildCodeSamples(operation, baseUrl, operation.body && operation.body.exampleValue, operation.body && operation.body.exampleJson)
95
+ });
96
+ }
97
+
98
+ // Navigation model shared by every reference page: all tags, with the active one marked.
99
+ // activeSlug is null on the overview page, which the nav marks instead.
100
+ function buildNav(model, activeSlug) {
101
+ return model.tags.map(tag => ({
102
+ name: tag.name,
103
+ slug: tag.slug,
104
+ operationCount: tag.operationCount,
105
+ active: tag.slug === activeSlug,
106
+ operations: tag.slug === activeSlug ? tag.operations.map(operation => ({ id: operation.id, summary: operation.summary || operation.path })) : []
107
+ }));
108
+ }
109
+
110
+ // Serializes a value for embedding in a <script> element. JSON.stringify escapes quotes but
111
+ // NOT `<`, so a string containing `</script` would close the element and everything after it
112
+ // would be parsed as HTML. Nothing in this map can contain one today - operation ids are
113
+ // [A-Za-z0-9_] and slugs are [a-z0-9-] - but that is a property of the inputs, and this makes
114
+ // it a property of the sink instead. U+2028/2029 are escaped too: legal in JSON, but line
115
+ // terminators in JavaScript source.
116
+ function jsonForScript(value) {
117
+ return JSON.stringify(value)
118
+ .replace(/</g, '\\u003c')
119
+ .replace(/\u2028/g, '\\u2028')
120
+ .replace(/\u2029/g, '\\u2029');
121
+ }
122
+
123
+ // Lookup tables for the /admin/swagger compatibility redirect. The old swagger-ui page deep
124
+ // linked as `#/Tag/operationId`, and a fragment never reaches the server, so the mapping has
125
+ // to be done in the browser.
126
+ //
127
+ // Operations map to their tag SLUG rather than a full URL: the shim composes the URL, which
128
+ // halves the payload since the operation id is already the key.
129
+ //
130
+ // The lookup is keyed on the operation id alone, deliberately ignoring the tag in the old
131
+ // hash - tags get renamed (the Chat endpoints now sit under "Deprecated endpoints (Document
132
+ // Store)"), which would strand every link that named the old one. The tag table is only a
133
+ // second chance for a link whose operation no longer exists but whose group still does.
134
+ let redirectMapJson;
135
+
136
+ async function getRedirectView(request) {
137
+ const model = await getModel(request.server);
138
+
139
+ if (!redirectMapJson) {
140
+ redirectMapJson = jsonForScript({
141
+ operations: Object.fromEntries(model.searchIndex.map(entry => [entry.id, entry.url.split('#')[0].split('/').pop()])),
142
+ tags: Object.fromEntries(model.tags.map(tag => [tag.name.toLowerCase(), tag.slug]))
143
+ });
144
+ }
145
+
146
+ return { redirectMap: redirectMapJson };
147
+ }
148
+
149
+ // Just the sidebar, for the reference pages that render no operations of their own
150
+ // (the access-token page).
151
+ async function getNavView(request) {
152
+ const model = await getModel(request.server);
153
+
154
+ return {
155
+ nav: buildNav(model, null),
156
+ // marks the nav's "Access token" entry as current
157
+ tokenActive: true,
158
+ searchIndex: model.searchIndex
159
+ };
160
+ }
161
+
162
+ // Landing page: the tag directory plus the counts shown on it.
163
+ async function getIndexView(request) {
164
+ const model = await getModel(request.server);
165
+
166
+ return {
167
+ version: model.version,
168
+ descriptionHtml: model.descriptionHtml,
169
+ operationCount: model.operationCount,
170
+ tags: model.tags,
171
+ nav: buildNav(model, null),
172
+ // marks the nav's "Overview" entry as current
173
+ overviewActive: true,
174
+ baseUrl: await resolveBaseUrl(request),
175
+ searchIndex: model.searchIndex
176
+ };
177
+ }
178
+
179
+ // Per-tag page. Returns null when the slug does not match a tag, so the route can 404.
180
+ async function getTagView(request, slug) {
181
+ const model = await getModel(request.server);
182
+
183
+ const tag = model.tagsBySlug.get(slug);
184
+ if (!tag) {
185
+ return null;
186
+ }
187
+
188
+ const baseUrl = await resolveBaseUrl(request);
189
+
190
+ return {
191
+ tag,
192
+ operations: tag.operations.map(operation => withSamples(operation, baseUrl)),
193
+ nav: buildNav(model, slug),
194
+ searchIndex: model.searchIndex
195
+ };
196
+ }
197
+
198
+ module.exports = {
199
+ getModel,
200
+ getRedirectView,
201
+ getNavView,
202
+ getIndexView,
203
+ getTagView,
204
+ clearServiceUrlCache
205
+ };