emailengine-app 2.88.0 → 2.90.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 (79) hide show
  1. package/.ncurc.js +36 -45
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +58 -0
  4. package/Dockerfile +5 -1
  5. package/bin/healthcheck.js +1 -1
  6. package/copy-static-files.sh +0 -8
  7. package/data/google-crawlers.json +1 -1
  8. package/encrypt.js +1 -4
  9. package/lib/account/field-codec.js +396 -0
  10. package/lib/account.js +158 -453
  11. package/lib/api-routes/account-routes.js +42 -6
  12. package/lib/api-routes/route-metadata.js +5 -2
  13. package/lib/api-routes/submit-routes.js +15 -2
  14. package/lib/api-token-auth.js +342 -274
  15. package/lib/arf-detect.js +174 -149
  16. package/lib/attachment-size.js +29 -0
  17. package/lib/autodetect-imap-settings.js +83 -234
  18. package/lib/consts.js +1 -5
  19. package/lib/db.js +1 -4
  20. package/lib/email-client/base-client.js +907 -780
  21. package/lib/email-client/gmail-client.js +557 -450
  22. package/lib/email-client/imap/cid-parts.js +61 -0
  23. package/lib/email-client/imap/mailbox.js +376 -422
  24. package/lib/email-client/imap/sync-operations.js +239 -178
  25. package/lib/email-client/new-message-steps.js +168 -2
  26. package/lib/email-client/outlook/graph-message.js +266 -0
  27. package/lib/email-client/outlook/subscription-expiry.js +30 -0
  28. package/lib/email-client/outlook-client.js +652 -808
  29. package/lib/get-raw-email.js +338 -232
  30. package/lib/get-secret.js +1 -4
  31. package/lib/license-subscription.js +77 -11
  32. package/lib/load-env.js +48 -0
  33. package/lib/logger.js +1 -4
  34. package/lib/mcp/tools.js +244 -207
  35. package/lib/metric-values.js +76 -0
  36. package/lib/metrics.js +320 -0
  37. package/lib/node-version.js +99 -12
  38. package/lib/oauth/gmail.js +39 -120
  39. package/lib/oauth/http-request.js +195 -0
  40. package/lib/oauth/mail-ru.js +24 -58
  41. package/lib/oauth/outlook.js +37 -137
  42. package/lib/oauth/pubsub/google.js +176 -117
  43. package/lib/oauth2-apps.js +440 -463
  44. package/lib/openapi/build-document.js +10 -10
  45. package/lib/read-env-value.js +1 -1
  46. package/lib/route-descriptors.js +78 -0
  47. package/lib/schemas.js +10 -1
  48. package/lib/sentry-integrations.js +299 -0
  49. package/lib/sentry.js +75 -27
  50. package/lib/settings.js +4 -1
  51. package/lib/sso-routes.js +249 -0
  52. package/lib/sso.js +29 -6
  53. package/lib/tools.js +5 -4
  54. package/lib/ui-routes/account-edit-form.js +198 -0
  55. package/lib/ui-routes/account-page.js +241 -0
  56. package/lib/ui-routes/account-routes.js +12 -318
  57. package/lib/ui-routes/auth-routes.js +10 -10
  58. package/lib/ui-routes/dashboard-routes.js +4 -0
  59. package/lib/ui-view-context.js +328 -0
  60. package/lib/utils/public-suffix.js +22 -101
  61. package/lib/web-safe-html.js +70 -13
  62. package/lib/worker-metrics.js +82 -0
  63. package/list-generate.js +57 -23
  64. package/package.json +34 -33
  65. package/sbom.json +380 -1612
  66. package/scripts/refresh-test-tokens.js +1 -1
  67. package/server.js +351 -707
  68. package/static/css/flyonui.css +1 -1
  69. package/static/css/src/app.tailwind.css +18 -0
  70. package/static/js/ee-client.js +2619 -645
  71. package/static/js/ui.js +12 -2
  72. package/static/licenses.html +1055 -969
  73. package/translations/messages.pot +71 -60
  74. package/views/accounts/browse.hbs +19 -1
  75. package/views/dashboard.hbs +9 -0
  76. package/views/upgrade.hbs +25 -0
  77. package/workers/api.js +20 -451
  78. package/data/public_suffix_list.dat +0 -16597
  79. package/lib/net-tos-guard.js +0 -42
@@ -16,6 +16,8 @@
16
16
  * removed when they run out, which is how every earlier release behaved.
17
17
  */
18
18
 
19
+ const { compareVersions, parseVersion } = require('./utils/version');
20
+
19
21
  const HOUR = 60 * 60 * 1000;
20
22
  const DAY = 24 * HOUR;
21
23
 
@@ -82,17 +84,24 @@ const checkInterval = state => (state && (toTime(state.subexp) || state.subsusp)
82
84
  * to store; suspend is the subsusp record to store; removeLicense is the legacy outcome; nextCheck is
83
85
  * when the next online check is due (ms), or null to leave it
84
86
  */
87
+ // A server-provided time as an ISO string, or null when it does not parse
88
+ const isoOrNull = value => {
89
+ const time = toTime(value);
90
+ return time ? new Date(time).toISOString() : null;
91
+ };
92
+
93
+ // What decide() returns when nothing changes; each branch states only what differs
94
+ const NO_CHANGE = Object.freeze({ clear: false, resume: false, subexp: null, suspend: null, removeLicense: false, nextCheck: null });
95
+
85
96
  function decide({ ok, data, now, subexp }) {
86
97
  data = data || {};
87
98
 
88
99
  if (ok) {
89
100
  const validatedUntil = toTime(data.validatedUntil);
90
101
  return {
102
+ ...NO_CHANGE,
91
103
  clear: true,
92
104
  resume: true,
93
- subexp: null,
94
- suspend: null,
95
- removeLicense: false,
96
105
  nextCheck: validatedUntil ? Math.min(now + MAX_LICENSE_CHECK_DELAY, validatedUntil) : null
97
106
  };
98
107
  }
@@ -100,7 +109,7 @@ function decide({ ok, data, now, subexp }) {
100
109
  // A refusal without invalidate is not about the subscription (bad input, a server error):
101
110
  // nothing changes, EmailEngine never stops over the license server's own trouble
102
111
  if (!data.invalidate) {
103
- return { clear: false, resume: false, subexp: null, suspend: null, removeLicense: false, nextCheck: null };
112
+ return { ...NO_CHANGE };
104
113
  }
105
114
 
106
115
  const stored = toTime(subexp);
@@ -109,25 +118,23 @@ function decide({ ok, data, now, subexp }) {
109
118
  if (deadline > now) {
110
119
  // inside the window: working, even if a stored suspension said otherwise (the server's
111
120
  // deadline is the one that counts, and it can move later)
112
- return { clear: false, resume: true, subexp: deadline, suspend: null, removeLicense: false, nextCheck: now + OVERDUE_CHECK_INTERVAL };
121
+ return { ...NO_CHANGE, resume: true, subexp: deadline, nextCheck: now + OVERDUE_CHECK_INTERVAL };
113
122
  }
114
123
 
115
124
  if (!data.keepLicense) {
116
- return { clear: false, resume: false, subexp: null, suspend: null, removeLicense: true, nextCheck: null };
125
+ return { ...NO_CHANGE, removeLicense: true };
117
126
  }
118
127
 
119
128
  return {
120
- clear: false,
121
- resume: false,
129
+ ...NO_CHANGE,
122
130
  subexp: deadline,
123
131
  suspend: {
124
132
  code: typeof data.code === 'string' ? data.code.slice(0, 64) : 'SubscriptionInactive',
125
133
  error: typeof data.error === 'string' ? data.error.slice(0, 256) : 'Subscription inactive',
126
134
  since: new Date(deadline).toISOString(),
127
- overdueSince: toTime(data.overdueSince) ? new Date(toTime(data.overdueSince)).toISOString() : null,
128
- endedAt: toTime(data.endedAt) ? new Date(toTime(data.endedAt)).toISOString() : null
135
+ overdueSince: isoOrNull(data.overdueSince),
136
+ endedAt: isoOrNull(data.endedAt)
129
137
  },
130
- removeLicense: false,
131
138
  nextCheck: now + OVERDUE_CHECK_INTERVAL
132
139
  };
133
140
  }
@@ -149,6 +156,61 @@ function expiredSuspension(subexp, subsusp, now) {
149
156
  return { code: 'SubscriptionInactive', error: 'Subscription inactive', since: new Date(deadline).toISOString() };
150
157
  }
151
158
 
159
+ /**
160
+ * Whether the record of the last successful validation no longer covers this instance, so the
161
+ * scheduled online check is allowed to run. It is covered while the version that validated (kv,
162
+ * hex) is this release or a later one and the record's own expiry (ks, hex ms) has not passed;
163
+ * an unreadable or missing record means checking again, which also rewrites it
164
+ * @param {Object} input
165
+ * @param {string|null} input.kv - the stored validated version
166
+ * @param {string|null} input.ks - the stored record expiry
167
+ * @param {string} input.version - the running version
168
+ * @param {number} input.now
169
+ * @returns {boolean}
170
+ */
171
+ function needsVersionRecheck({ kv, ks, version, now }) {
172
+ if (!ks || typeof ks !== 'string' || new Date(parseInt(ks, 16)) < now) {
173
+ return true;
174
+ }
175
+ let validatedVersion = kv && typeof kv === 'string' ? Buffer.from(kv, 'hex').toString() : null;
176
+ return !(parseVersion(validatedVersion) && compareVersions(version, validatedVersion) <= 0);
177
+ }
178
+
179
+ /**
180
+ * Which license the periodic check concerns, and whether a passed deadline suspends it before
181
+ * the license server is asked
182
+ * @param {Object} licenseInfo - the running license state (`active`, `suspension`, `details`)
183
+ * @param {Object} input
184
+ * @param {number|string|null} input.subexp - the stored deadline
185
+ * @param {string|null} input.subsusp - the stored suspension
186
+ * @param {number} input.now
187
+ * @returns {{subscriptionLicense: boolean, localSuspension: (Object|null)}} subscriptionLicense says
188
+ * the online check applies (a suspended license is still registered and still checked, which is
189
+ * how it resumes); localSuspension is the suspension record to apply now, or null
190
+ */
191
+ function subscriptionCheckState(licenseInfo, { subexp, subsusp, now }) {
192
+ let subscriptionLicense = (licenseInfo.active || !!licenseInfo.suspension) && isSubscriptionLicense(licenseInfo.details);
193
+ let localSuspension = subscriptionLicense && !licenseInfo.suspension ? expiredSuspension(subexp, subsusp, now) : null;
194
+ return { subscriptionLicense, localSuspension };
195
+ }
196
+
197
+ /**
198
+ * What a license check does to the licensed workers
199
+ * @param {boolean} licenseActive
200
+ * @param {number} suspendedTypes - how many worker types are suspended now
201
+ * @returns {'suspend'|'resume'|null} suspend every licensed worker type, respawn the suspended
202
+ * ones, or leave them as they are
203
+ */
204
+ function workerSuspensionChange(licenseActive, suspendedTypes) {
205
+ if (!licenseActive && !suspendedTypes) {
206
+ return 'suspend';
207
+ }
208
+ if (licenseActive && suspendedTypes) {
209
+ return 'resume';
210
+ }
211
+ return null;
212
+ }
213
+
152
214
  /**
153
215
  * What a start of EmailEngine does before any worker runs
154
216
  * @param {Object} input
@@ -225,12 +287,16 @@ module.exports = {
225
287
  decide,
226
288
  startupPlan,
227
289
  expiredSuspension,
290
+ needsVersionRecheck,
291
+ subscriptionCheckState,
292
+ workerSuspensionChange,
228
293
  checkInterval,
229
294
  subscriptionView,
230
295
  isSuspended,
231
296
  parseSuspension,
232
297
  isSubscriptionLicense,
233
298
  keepsSubscriptionState,
299
+ toTime,
234
300
  LEGACY_GRACE,
235
301
  CHECK_INTERVAL,
236
302
  OVERDUE_CHECK_INTERVAL,
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // Loads `.env` from the working directory into process.env with Node's own parser
4
+ // (process.loadEnvFile, Node 21.7+), which replaced the dotenv package. Variables that are
5
+ // already set are never overwritten, the same as dotenv did.
6
+ //
7
+ // Dependency-free on purpose: server.js loads it before it checks the Node.js version, so it has
8
+ // to load on any release. On a release without process.loadEnvFile it does nothing, and the
9
+ // version check that follows tells the operator to upgrade.
10
+
11
+ /**
12
+ * Loads an env file, if there is one.
13
+ *
14
+ * A missing file is the normal case and is silent. A file that exists but cannot be read is
15
+ * reported on stderr and otherwise ignored, as dotenv ignored it: the instance then starts with
16
+ * the environment it was given rather than not at all.
17
+ *
18
+ * @param {string} [path='.env'] Resolved against the working directory
19
+ * @returns {boolean} Whether a file was loaded
20
+ */
21
+ function loadEnvFile(path = '.env') {
22
+ if (typeof process.loadEnvFile !== 'function') {
23
+ return false;
24
+ }
25
+ try {
26
+ process.loadEnvFile(path);
27
+ return true;
28
+ } catch (err) {
29
+ if (err.code !== 'ENOENT') {
30
+ process.stderr.write(`Could not load ${path}: ${err.message}\n`);
31
+ }
32
+ return false;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Loads `.env` once per process, however many modules ask. A worker thread starts with a copy of
38
+ * the main thread's process.env, marker included, so it does not load the file again; the tests set
39
+ * the marker themselves to keep a developer's own .env out of a child process.
40
+ */
41
+ function loadEnvOnce() {
42
+ if (!process.env.EE_ENV_LOADED) {
43
+ loadEnvFile();
44
+ process.env.EE_ENV_LOADED = 'true';
45
+ }
46
+ }
47
+
48
+ module.exports = { loadEnvFile, loadEnvOnce };
package/lib/logger.js CHANGED
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- if (!process.env.EE_ENV_LOADED) {
4
- require('dotenv').config({ quiet: true });
5
- process.env.EE_ENV_LOADED = 'true';
6
- }
3
+ require('./load-env').loadEnvOnce();
7
4
 
8
5
  const config = require('@zone-eu/wild-config');
9
6
  const pino = require('pino');