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,195 @@
1
+ 'use strict';
2
+
3
+ // Admin UI routes for the server-rendered API reference.
4
+ //
5
+ // This replaced the bundled swagger-ui page, which shipped the OpenAPI document to the
6
+ // browser and let swagger-ui build the DOM. Here the whole page is HTML by the time it
7
+ // leaves the worker - see lib/api-reference/ for the model.
8
+ //
9
+ // This is the "API Reference" entry in the side menu. /admin/swagger is kept only as a
10
+ // redirect for deep links written against the old page.
11
+
12
+ const Joi = require('joi');
13
+ const Boom = require('@hapi/boom');
14
+
15
+ const { failAction } = require('../tools');
16
+ const { jsonErrorPayload } = require('./route-helpers');
17
+ const tokens = require('../tokens');
18
+ const { getIndexView, getTagView, getNavView, getRedirectView } = require('../api-reference');
19
+
20
+ // Lifetime of the throwaway tokens the reference page mints for its try-it panels. Long
21
+ // enough to read through the docs, short enough that a token left in a browser tab is
22
+ // not a lasting credential.
23
+ const TEMP_TOKEN_TTL = 60 * 60 * 1000;
24
+
25
+ // Only tokens carrying this description are revocable through the reference page. It is
26
+ // what the mint route sets, so a pasted token - which the user owns and may still need -
27
+ // can never be deleted by clearing the field.
28
+ const TEMP_TOKEN_DESCRIPTION = 'Temporary token for the API reference';
29
+
30
+ function init(args) {
31
+ const { server } = args;
32
+
33
+ server.route({
34
+ method: 'GET',
35
+ path: '/admin/reference',
36
+ async handler(request, h) {
37
+ const view = await getIndexView(request);
38
+
39
+ // secondaryNav opts this page into the layout's second navigation column,
40
+ // rendered flush against the main sidebar (views/layout/app.hbs)
41
+ return h.view('reference/index', Object.assign({ pageTitle: 'API Reference', menuReference: true, secondaryNav: 'reference/nav' }, view), {
42
+ layout: 'app'
43
+ });
44
+ }
45
+ });
46
+
47
+ // Access-token page. A literal segment, so hapi routes it ahead of /{tag} below - no
48
+ // tag slug may be `token` or it would be shadowed, which test/api-reference-test.js
49
+ // asserts against RESERVED_SLUGS.
50
+ server.route({
51
+ method: 'GET',
52
+ path: '/admin/reference/token',
53
+ async handler(request, h) {
54
+ const view = await getNavView(request);
55
+
56
+ return h.view('reference/token', Object.assign({ pageTitle: 'Access token', menuReference: true, secondaryNav: 'reference/nav' }, view), {
57
+ layout: 'app'
58
+ });
59
+ }
60
+ });
61
+
62
+ server.route({
63
+ method: 'GET',
64
+ path: '/admin/reference/{tag}',
65
+ async handler(request, h) {
66
+ const view = await getTagView(request, request.params.tag);
67
+
68
+ if (!view) {
69
+ throw Boom.notFound('Unknown endpoint group');
70
+ }
71
+
72
+ return h.view('reference/tag', Object.assign({ pageTitle: `${view.tag.name} API`, menuReference: true, secondaryNav: 'reference/nav' }, view), {
73
+ layout: 'app'
74
+ });
75
+ },
76
+
77
+ options: {
78
+ validate: {
79
+ options: {
80
+ stripUnknown: true,
81
+ abortEarly: false,
82
+ convert: true
83
+ },
84
+ failAction,
85
+ params: Joi.object({
86
+ // Slugs are generated by slugify() in lib/api-reference/format.js;
87
+ // anything else cannot match a tag and is rejected before the lookup
88
+ tag: Joi.string()
89
+ .max(64)
90
+ .pattern(/^[a-z0-9-]+$/)
91
+ .required()
92
+ })
93
+ }
94
+ }
95
+ });
96
+
97
+ // Compatibility shim for the retired swagger-ui page. Old versions of EmailEngine, and
98
+ // any bookmark, link here as /admin/swagger#/Tag/operationId; a fragment never reaches
99
+ // the server, so the page maps it in the browser. Links inside this version point at
100
+ // /admin/reference directly.
101
+ server.route({
102
+ method: 'GET',
103
+ path: '/admin/swagger',
104
+ async handler(request, h) {
105
+ const view = await getRedirectView(request);
106
+
107
+ return h.view('reference/redirect', Object.assign({ pageTitle: 'API Reference', menuReference: true }, view), { layout: 'app' });
108
+ }
109
+ });
110
+
111
+ // Mints a short-lived, api-scoped token for the try-it panels, so trying an endpoint
112
+ // does not mean creating a permanent credential and remembering to delete it.
113
+ server.route({
114
+ method: 'POST',
115
+ path: '/admin/reference/token',
116
+
117
+ async handler(request) {
118
+ try {
119
+ // Same gate as POST /admin/tokens/new, for the same reason: a token is
120
+ // never invalidated once minted, so an unauthenticated caller must not be
121
+ // able to obtain one. `server.auth.default('session')` is applied
122
+ // conditionally and only in the worker that observed the password being
123
+ // set, so this keys on whether THIS request carries an admin session
124
+ // rather than on the global secured-state.
125
+ if (!request.auth.isAuthenticated) {
126
+ throw Boom.forbidden('Can not provision an access token without an authenticated admin session');
127
+ }
128
+
129
+ const expires = Date.now() + TEMP_TOKEN_TTL;
130
+
131
+ const token = await tokens.provision({
132
+ ip: request.app.ip,
133
+ remoteAddress: request.app.ip,
134
+ description: TEMP_TOKEN_DESCRIPTION,
135
+ scopes: ['api'],
136
+ expires
137
+ });
138
+
139
+ return { success: true, token, expires };
140
+ } catch (err) {
141
+ request.logger.error({ msg: 'Failed to mint a temporary reference token', err, remoteAddress: request.app.ip });
142
+ return jsonErrorPayload(err);
143
+ }
144
+ }
145
+ });
146
+
147
+ // Revokes a token minted above, so clearing it in the UI actually removes it rather
148
+ // than leaving a working credential in Redis until it expires on its own.
149
+ server.route({
150
+ method: 'POST',
151
+ path: '/admin/reference/token/revoke',
152
+
153
+ async handler(request) {
154
+ try {
155
+ if (!request.auth.isAuthenticated) {
156
+ throw Boom.forbidden('Can not revoke an access token without an authenticated admin session');
157
+ }
158
+
159
+ // Refuse anything this page did not mint. An admin can delete any token
160
+ // from the Access Tokens page anyway, so this is not a privilege boundary -
161
+ // it stops the reference page from destroying a token the user pasted in.
162
+ let tokenData;
163
+ try {
164
+ tokenData = await tokens.get(request.payload.token, false, { allowExpired: true });
165
+ } catch (err) {
166
+ // already gone, or never existed - nothing left to revoke
167
+ return { success: true, deleted: false };
168
+ }
169
+
170
+ if (tokenData.description !== TEMP_TOKEN_DESCRIPTION) {
171
+ throw Boom.forbidden('Only tokens minted by the API reference can be revoked here');
172
+ }
173
+
174
+ await tokens.delete(request.payload.token, { remoteAddress: request.app.ip });
175
+
176
+ return { success: true, deleted: true };
177
+ } catch (err) {
178
+ request.logger.error({ msg: 'Failed to revoke a temporary reference token', err, remoteAddress: request.app.ip });
179
+ return jsonErrorPayload(err);
180
+ }
181
+ },
182
+
183
+ options: {
184
+ validate: {
185
+ options: { stripUnknown: true, abortEarly: false, convert: true },
186
+ failAction,
187
+ payload: Joi.object({
188
+ token: Joi.string().length(64).hex().required().description('The token to revoke')
189
+ })
190
+ }
191
+ }
192
+ });
193
+ }
194
+
195
+ module.exports = init;
@@ -326,7 +326,18 @@ function throwAsBoom(err) {
326
326
  throw error;
327
327
  }
328
328
 
329
+ // Shapes an error for the admin UI's JSON endpoints, which answer 200 with `success: false`
330
+ // rather than an HTTP error - the client branches on the body. Boom errors keep their status
331
+ // and message; anything else degrades to its code.
332
+ function jsonErrorPayload(err) {
333
+ if (Boom.isBoom(err)) {
334
+ return Object.assign({ success: false }, err.output.payload);
335
+ }
336
+ return { success: false, error: err.code || 'Error', message: err.message };
337
+ }
338
+
329
339
  module.exports = {
340
+ jsonErrorPayload,
330
341
  OPEN_AI_MODELS,
331
342
  cachedTemplates,
332
343
  getOpenAiModels,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.76.0",
3
+ "version": "2.77.0",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -21,7 +21,7 @@
21
21
  "lint:src": "npx eslint 'lib/**/*.js' 'workers/**/*.js' server.js",
22
22
  "swagger": "./getswagger.sh",
23
23
  "build:css": "tailwindcss -i static/css/src/app.tailwind.css -o static/css/flyonui.css --minify",
24
- "build-source": "rm -rf node_modules && npm install && rm -rf node_modules && npm ci --omit=dev && rm -rf node_modules/ace-builds node_modules/@postalsys/ee-client && ./update-info.sh",
24
+ "build-source": "rm -rf node_modules && npm install && rm -rf node_modules && npm ci --omit=dev && rm -rf node_modules/ace-builds node_modules/@postalsys/ee-client && ./prepare-bundle-deps.sh && ./update-info.sh",
25
25
  "build-dist": "pkg --compress Brotli package.json && npm install && node winconf.js",
26
26
  "build-dist-fast": "pkg --debug package.json && npm install && node winconf.js",
27
27
  "licenses": "node list-generate.js",
@@ -50,8 +50,8 @@
50
50
  },
51
51
  "homepage": "https://emailengine.app/",
52
52
  "dependencies": {
53
- "@bull-board/api": "8.4.0",
54
- "@bull-board/hapi": "8.4.0",
53
+ "@bull-board/api": "8.5.0",
54
+ "@bull-board/hapi": "8.5.0",
55
55
  "@elastic/elasticsearch": "8.15.3",
56
56
  "@hapi/accept": "6.0.3",
57
57
  "@hapi/bell": "13.1.0",
@@ -64,7 +64,7 @@
64
64
  "@phc/pbkdf2": "1.1.14",
65
65
  "@postalsys/bounce-classifier": "3.0.0",
66
66
  "@postalsys/certs": "1.0.16",
67
- "@postalsys/ee-client": "1.6.0",
67
+ "@postalsys/ee-client": "1.7.0",
68
68
  "@postalsys/email-ai-tools": "1.13.15",
69
69
  "@postalsys/email-content": "0.1.2",
70
70
  "@postalsys/email-text-tools": "2.4.11",
@@ -78,7 +78,7 @@
78
78
  "@zone-eu/wild-config": "1.7.6",
79
79
  "ace-builds": "1.44.0",
80
80
  "base32.js": "0.1.0",
81
- "bullmq": "5.81.2",
81
+ "bullmq": "5.81.3",
82
82
  "compare-versions": "6.1.1",
83
83
  "dotenv": "17.4.2",
84
84
  "encoding-japanese": "2.2.0",
@@ -87,7 +87,6 @@
87
87
  "handlebars": "4.7.9",
88
88
  "hapi-auth-bearer-token": "8.0.0",
89
89
  "hapi-pino": "13.0.0",
90
- "hapi-swagger": "17.3.2",
91
90
  "he": "1.2.0",
92
91
  "html-to-text": "10.0.0",
93
92
  "ical.js": "1.5.0",
@@ -96,7 +95,7 @@
96
95
  "ioredfour": "1.4.2",
97
96
  "ioredis": "5.11.1",
98
97
  "ipaddr.js": "2.4.0",
99
- "joi": "17.13.4",
98
+ "joi": "18.2.3",
100
99
  "libbase64": "1.3.0",
101
100
  "libmime": "5.4.1",
102
101
  "libqp": "2.1.1",
@@ -105,7 +104,7 @@
105
104
  "minimist": "1.2.8",
106
105
  "msgpack5": "6.0.2",
107
106
  "murmurhash": "2.0.1",
108
- "nanoid": "3.3.16",
107
+ "nanoid": "3.3.17",
109
108
  "nodemailer": "9.0.3",
110
109
  "pino": "10.3.1",
111
110
  "prom-client": "15.1.3",
@@ -124,7 +123,7 @@
124
123
  "@eslint/js": "10.0.1",
125
124
  "@iconify-json/tabler": "1.2.38",
126
125
  "@iconify/tailwind4": "1.2.3",
127
- "@playwright/test": "1.62.0",
126
+ "@playwright/test": "1.62.1",
128
127
  "@tailwindcss/cli": "4.3.3",
129
128
  "acorn": "8.18.0",
130
129
  "acorn-walk": "8.3.5",
@@ -159,7 +158,6 @@
159
158
  "views/**/*",
160
159
  "lib/lua/**/*",
161
160
  "node_modules/bull/lib/commands/**/*",
162
- "node_modules/swagger-ui-dist/**/*",
163
161
  "translations/**/*",
164
162
  "node_modules/@postalsys/joi-messages/translations/*",
165
163
  "node_modules/@postalsys/bounce-classifier/model/**/*",
@@ -0,0 +1,28 @@
1
+ #!/bin/sh
2
+
3
+ # Fixups applied to the production node_modules tree before pkg bundles it.
4
+ #
5
+ # pkg walks every file a package's `exports` map points at and runs it through esbuild.
6
+ # A file esbuild transforms to nothing leaves pkg dereferencing an undefined result, and
7
+ # it dies with "Cannot read properties of undefined (reading 'tokens')" naming whichever
8
+ # of our own files happened to pull the package in - which points at the wrong place
9
+ # entirely. Fixed upstream in neither pkg 6.21 nor 6.22.
10
+ #
11
+ # Run from npm run build-source, after `npm ci --omit=dev` has produced the tree that
12
+ # actually gets bundled.
13
+
14
+ set -e
15
+
16
+ # @standard-schema/spec (joi >=18) is a types-only package: its runtime export is
17
+ # literally `{}` (see dist/index.cjs) and joi names it only in an `import type` inside
18
+ # lib/index.d.ts, which TypeScript erases. Its ESM entry point dist/index.js is therefore
19
+ # a 0-byte file, which is the one pkg cannot swallow.
20
+ #
21
+ # The file is restored to what an empty ES module should look like rather than deleted:
22
+ # the package stays resolvable, so a future joi that does require it at runtime keeps
23
+ # working instead of failing inside a shipped binary.
24
+ EMPTY_ESM="node_modules/@standard-schema/spec/dist/index.js"
25
+ if [ -f "$EMPTY_ESM" ] && [ ! -s "$EMPTY_ESM" ]; then
26
+ echo "export {};" >"$EMPTY_ESM"
27
+ echo "patched empty ESM entry point: $EMPTY_ESM"
28
+ fi
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3
+ "packages": {
4
+ ".": {
5
+ "release-type": "node",
6
+ "draft": true,
7
+ "force-tag-creation": true,
8
+ "include-component-in-tag": false
9
+ }
10
+ }
11
+ }