emailengine-app 2.89.0 → 2.91.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 (120) hide show
  1. package/.ncurc.js +19 -8
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +73 -0
  4. package/Dockerfile +7 -3
  5. package/ENVIRONMENT.md +24 -23
  6. package/README.md +1 -1
  7. package/bin/healthcheck.js +1 -1
  8. package/copy-static-files.sh +0 -8
  9. package/data/google-crawlers.json +1 -1
  10. package/encrypt.js +1 -4
  11. package/lib/account/field-codec.js +396 -0
  12. package/lib/account-assignment.js +26 -9
  13. package/lib/account.js +196 -462
  14. package/lib/api-routes/account-routes.js +49 -6
  15. package/lib/api-routes/route-metadata.js +5 -2
  16. package/lib/api-routes/submit-routes.js +15 -2
  17. package/lib/api-token-auth.js +342 -274
  18. package/lib/arf-detect.js +174 -149
  19. package/lib/attachment-size.js +29 -0
  20. package/lib/autodetect-imap-settings.js +482 -296
  21. package/lib/consts.js +5 -5
  22. package/lib/db.js +1 -4
  23. package/lib/email-client/base-client.js +907 -780
  24. package/lib/email-client/gmail-client.js +557 -450
  25. package/lib/email-client/imap/cid-parts.js +61 -0
  26. package/lib/email-client/imap/mailbox.js +376 -422
  27. package/lib/email-client/imap/sync-operations.js +239 -178
  28. package/lib/email-client/imap-client.js +5 -5
  29. package/lib/email-client/message-builder.js +4 -5
  30. package/lib/email-client/new-message-steps.js +168 -2
  31. package/lib/email-client/outlook/graph-message.js +266 -0
  32. package/lib/email-client/outlook/subscription-expiry.js +30 -0
  33. package/lib/email-client/outlook-client.js +652 -808
  34. package/lib/get-raw-email.js +338 -232
  35. package/lib/get-secret.js +1 -4
  36. package/lib/imapproxy/imap-server.js +5 -5
  37. package/lib/license-subscription.js +60 -0
  38. package/lib/load-env.js +48 -0
  39. package/lib/logger-consts.js +37 -1
  40. package/lib/logger.js +1 -4
  41. package/lib/mail-probe.js +157 -0
  42. package/lib/mcp/tools.js +244 -207
  43. package/lib/metric-values.js +76 -0
  44. package/lib/metrics.js +320 -0
  45. package/lib/oauth/gmail.js +39 -120
  46. package/lib/oauth/http-request.js +195 -0
  47. package/lib/oauth/mail-ru.js +33 -60
  48. package/lib/oauth/outlook.js +37 -137
  49. package/lib/oauth/pubsub/google.js +176 -117
  50. package/lib/oauth2-apps.js +440 -463
  51. package/lib/openapi/build-document.js +10 -10
  52. package/lib/read-env-value.js +31 -7
  53. package/lib/redis-backend-warnings.js +70 -0
  54. package/lib/route-descriptors.js +78 -0
  55. package/lib/schemas.js +10 -1
  56. package/lib/sentry-integrations.js +299 -0
  57. package/lib/sentry.js +75 -27
  58. package/lib/sso-routes.js +249 -0
  59. package/lib/sso.js +29 -6
  60. package/lib/tools.js +17 -28
  61. package/lib/ui-routes/account-edit-form.js +198 -0
  62. package/lib/ui-routes/account-page.js +241 -0
  63. package/lib/ui-routes/account-routes.js +46 -349
  64. package/lib/ui-routes/account-setup.js +1 -1
  65. package/lib/ui-routes/auth-routes.js +10 -10
  66. package/lib/ui-routes/provider-signin.js +187 -0
  67. package/lib/ui-routes/route-helpers.js +1 -1
  68. package/lib/ui-routes/unsubscribe-routes.js +2 -2
  69. package/lib/ui-view-context.js +328 -0
  70. package/lib/utils/public-suffix.js +22 -101
  71. package/lib/web-safe-html.js +20 -7
  72. package/lib/worker-metrics.js +82 -0
  73. package/list-generate.js +2 -5
  74. package/package.json +28 -24
  75. package/sbom.json +360 -1030
  76. package/scripts/refresh-test-tokens.js +1 -1
  77. package/server.js +400 -677
  78. package/static/css/flyonui.css +1 -1
  79. package/static/css/public.css +55 -1
  80. package/static/css/src/app.tailwind.css +18 -0
  81. package/static/js/ee-client.js +2619 -645
  82. package/static/js/ui.js +12 -2
  83. package/static/licenses.html +224 -764
  84. package/translations/de.mo +0 -0
  85. package/translations/de.po +429 -390
  86. package/translations/en.mo +0 -0
  87. package/translations/en.po +342 -257
  88. package/translations/es.mo +0 -0
  89. package/translations/es.po +440 -395
  90. package/translations/et.mo +0 -0
  91. package/translations/et.po +425 -375
  92. package/translations/fr.mo +0 -0
  93. package/translations/fr.po +425 -383
  94. package/translations/it.mo +0 -0
  95. package/translations/it.po +441 -394
  96. package/translations/ja.mo +0 -0
  97. package/translations/ja.po +408 -335
  98. package/translations/messages.pot +188 -130
  99. package/translations/nl.mo +0 -0
  100. package/translations/nl.po +419 -382
  101. package/translations/pl.mo +0 -0
  102. package/translations/pl.po +425 -379
  103. package/translations/sv.mo +0 -0
  104. package/translations/sv.po +440 -388
  105. package/translations/tr.mo +0 -0
  106. package/translations/tr.po +441 -387
  107. package/views/account-identity-error.hbs +1 -1
  108. package/views/account-workspace-error.hbs +2 -2
  109. package/views/accounts/browse.hbs +19 -1
  110. package/views/accounts/register/imap-server.hbs +22 -7
  111. package/views/accounts/register/imap.hbs +3 -0
  112. package/views/accounts/register/index.hbs +1 -27
  113. package/views/accounts/register/provider-signin.hbs +58 -0
  114. package/views/oauth-scope-error.hbs +1 -1
  115. package/views/partials/provider_signin_button.hbs +30 -0
  116. package/views/queues/index.hbs +1 -1
  117. package/views/redirect.hbs +1 -1
  118. package/views/unsubscribe.hbs +6 -6
  119. package/workers/api.js +20 -451
  120. package/data/public_suffix_list.dat +0 -16698
@@ -0,0 +1,396 @@
1
+ 'use strict';
2
+
3
+ // The account hash codec: how Account.serializeAccountData() stores a field in Redis and how
4
+ // Account.unserializeAccountData() reads it back, for every field that is not kept as the plain
5
+ // string it is stored as. Both look the field up here and fall back to the plain string.
6
+ //
7
+ // Every entry is called as (accountObject, key, accountData, result), decoders with skipDecrypt as
8
+ // a fifth argument, and writes into `result` itself, or writes nothing when the field stores or
9
+ // reads as nothing. Writing in place rather than returning a value keeps the output keys in the
10
+ // order of the input keys, which the webhookErrorFlag reset in encodeWebhooks() depends on. An
11
+ // encoder is never called for a field holding undefined: serializeAccountData() skips it.
12
+
13
+ const { encrypt, parseEncryptedData } = require('../encrypt');
14
+
15
+ // Subkeys of the connection objects that hold dates
16
+ const CONNECTION_DATE_KEYS = ['created', 'expires', 'generated'];
17
+
18
+ // Credentials inside a connection object, looked up in its `auth` first (imap, smtp) and then
19
+ // beside it (the OAuth2 tokens)
20
+ const CONNECTION_SECRET_KEYS = ['pass', 'accessToken', 'refreshToken'];
21
+
22
+ function isValidDateObject(value) {
23
+ return value && typeof value === 'object' && typeof value.toISOString === 'function' && value.toString() !== 'Invalid Date';
24
+ }
25
+
26
+ function isStringable(value) {
27
+ return typeof value !== 'undefined' && value !== null && typeof value.toString === 'function';
28
+ }
29
+
30
+ /**
31
+ * Parses a stored JSON value. A value that does not parse is logged and, like a stored `null`,
32
+ * reads as undefined: the field is then left out of the account.
33
+ */
34
+ function parseStoredJson(accountObject, key, stored, ownerAccount) {
35
+ let value;
36
+ try {
37
+ value = JSON.parse(stored);
38
+ } catch (err) {
39
+ accountObject.logUnserializeFailure('Failed to parse input from Redis', key, stored, ownerAccount, err);
40
+ return undefined;
41
+ }
42
+ return value === null ? undefined : value;
43
+ }
44
+
45
+ // Sets the parsed stored JSON value as the field, unless it is null or does not parse. Returns the
46
+ // value, so a decoder can go on to convert parts of it in place
47
+ function setStoredJson(accountObject, key, stored, accountData, result) {
48
+ const value = parseStoredJson(accountObject, key, stored, accountData.account);
49
+ if (value !== undefined) {
50
+ result[key] = value;
51
+ }
52
+ return value;
53
+ }
54
+
55
+ function logStringifyFailure(accountObject, key, err) {
56
+ accountObject.logger.error({ msg: 'Failed to stringify input for Redis', key, account: accountObject.account, err });
57
+ }
58
+
59
+ function decodeDate(accountObject, key, accountData, result) {
60
+ const stored = accountData[key];
61
+ if (!stored) {
62
+ return;
63
+ }
64
+ if (stored === 'null') {
65
+ result[key] = null;
66
+ return;
67
+ }
68
+ const date = new Date(stored);
69
+ if (date.toString() !== 'Invalid Date') {
70
+ result[key] = date;
71
+ }
72
+ }
73
+
74
+ function decodeBool(accountObject, key, accountData, result) {
75
+ const stored = accountData[key];
76
+ if (stored && stored !== 'null') {
77
+ result[key] = stored === 'true';
78
+ }
79
+ }
80
+
81
+ // '' is the cleared marker written by encodeClearable() - report it as unset
82
+ function decodeNonEmpty(accountObject, key, accountData, result) {
83
+ if (accountData[key]) {
84
+ result[key] = accountData[key];
85
+ }
86
+ }
87
+
88
+ function decodePath(accountObject, key, accountData, result) {
89
+ const stored = accountData[key];
90
+ if (!stored || !stored.length) {
91
+ return;
92
+ }
93
+ if (stored.length > 1 && (/^"|"$/.test(stored) || /^\[|\]$/.test(stored))) {
94
+ // seems like JSON array or string
95
+ setStoredJson(accountObject, key, stored, accountData, result);
96
+ } else {
97
+ // regular string
98
+ result[key] = stored;
99
+ }
100
+ }
101
+
102
+ function decodeEncrypted(accountObject, key, accountData, result, skipDecrypt) {
103
+ const value = skipDecrypt ? accountData[key] : accountObject.decryptAccountField(key, accountData[key], accountData.account);
104
+ if (typeof value !== 'undefined') {
105
+ result[key] = value;
106
+ }
107
+ }
108
+
109
+ function decodeCustomHeaders(accountObject, key, accountData, result, skipDecrypt) {
110
+ let stored = accountData[key];
111
+ if (skipDecrypt) {
112
+ if (accountObject.secret && parseEncryptedData(stored).format !== 'cleartext') {
113
+ // not read by any caller that skips decryption
114
+ return;
115
+ }
116
+ } else {
117
+ stored = accountObject.decryptAccountField(key, stored, accountData.account);
118
+ if (typeof stored === 'undefined') {
119
+ return;
120
+ }
121
+ }
122
+ setStoredJson(accountObject, key, stored, accountData, result);
123
+ }
124
+
125
+ function decodeJson(accountObject, key, accountData, result) {
126
+ setStoredJson(accountObject, key, accountData[key], accountData, result);
127
+ }
128
+
129
+ function decodeOutlookSubscription(accountObject, key, accountData, result) {
130
+ const value = setStoredJson(accountObject, key, accountData[key], accountData, result);
131
+ if (value === undefined) {
132
+ return;
133
+ }
134
+ if (value.expirationDateTime) {
135
+ let expirationDateTime = new Date(value.expirationDateTime);
136
+ if (expirationDateTime.toString() === 'Invalid Date') {
137
+ expirationDateTime = null;
138
+ }
139
+ value.expirationDateTime = expirationDateTime;
140
+ }
141
+ }
142
+
143
+ // Connection settings and stored states: date subkeys become Date objects, null subkeys are dropped
144
+ function decodeConnectionJson(accountObject, key, accountData, result) {
145
+ const value = setStoredJson(accountObject, key, accountData[key], accountData, result);
146
+ if (value === undefined) {
147
+ return;
148
+ }
149
+ for (const subKey of CONNECTION_DATE_KEYS) {
150
+ if (value[subKey]) {
151
+ const dateVal = /^[0-9]+$/.test(value[subKey]) ? Number(value[subKey]) : value[subKey];
152
+ const date = new Date(dateVal);
153
+ if (date.toString() !== 'Invalid Date') {
154
+ value[subKey] = date;
155
+ }
156
+ }
157
+ }
158
+ for (const subKey of Object.keys(value)) {
159
+ if (value[subKey] === null) {
160
+ delete value[subKey];
161
+ }
162
+ }
163
+ }
164
+
165
+ function decodeNumber(accountObject, key, accountData, result) {
166
+ result[key] = Number(accountData[key]) || 0;
167
+ }
168
+
169
+ // The fallback for a field with no decoder: the stored string as it is
170
+ function decodePlain(accountObject, key, accountData, result) {
171
+ result[key] = accountData[key];
172
+ }
173
+
174
+ const FIELD_DECODERS = new Map([
175
+ ['notifyFrom', decodeDate],
176
+ ['lastWatch', decodeDate],
177
+ ['copy', decodeBool],
178
+ ['logs', decodeBool],
179
+ ['expectedEmail', decodeNonEmpty],
180
+ ['path', decodePath],
181
+ ['webhooks', decodeEncrypted],
182
+ ['proxy', decodeEncrypted],
183
+ ['webhooksCustomHeaders', decodeCustomHeaders],
184
+ ['subconnections', decodeJson],
185
+ ['watchResponse', decodeJson],
186
+ ['watchFailure', decodeJson],
187
+ ['outlookSubscription', decodeOutlookSubscription],
188
+ ['imap', decodeConnectionJson],
189
+ ['smtp', decodeConnectionJson],
190
+ ['imapServerInfo', decodeConnectionJson],
191
+ ['smtpServerEhlo', decodeConnectionJson],
192
+ ['oauth2', decodeConnectionJson],
193
+ ['lastErrorState', decodeConnectionJson],
194
+ ['syncError', decodeConnectionJson],
195
+ ['smtpStatus', decodeConnectionJson],
196
+ ['webhookErrorFlag', decodeConnectionJson],
197
+ ['connections', decodeNumber],
198
+ ['listRegistry', decodeNumber],
199
+ ['runIndex', decodeNumber]
200
+ ]);
201
+
202
+ function encodeDate(accountObject, key, accountData, result) {
203
+ const value = accountData[key];
204
+ if (value === 'now') {
205
+ result[key] = new Date().toISOString();
206
+ } else if (isValidDateObject(value)) {
207
+ result[key] = value.toISOString();
208
+ } else if (typeof value === 'string') {
209
+ const date = new Date(value);
210
+ if (date.toString() !== 'Invalid Date') {
211
+ result[key] = date.toISOString();
212
+ }
213
+ } else if (value === null) {
214
+ result[key] = 'null';
215
+ }
216
+ }
217
+
218
+ function encodePath(accountObject, key, accountData, result) {
219
+ const value = accountData[key];
220
+ if (value === null || value === '*' || (Array.isArray(value) && (value.length === 0 || (value.length === 1 && value[0] === '*')))) {
221
+ result[key] = '';
222
+ return;
223
+ }
224
+ try {
225
+ result[key] = JSON.stringify(value);
226
+ } catch (err) {
227
+ logStringifyFailure(accountObject, key, err);
228
+ }
229
+ }
230
+
231
+ function encodeCustomHeaders(accountObject, key, accountData, result) {
232
+ try {
233
+ result[key] = accountObject.encryptAccountField(key, JSON.stringify(accountData[key]));
234
+ } catch (err) {
235
+ logStringifyFailure(accountObject, key, err);
236
+ }
237
+ }
238
+
239
+ function encodeProxy(accountObject, key, accountData, result) {
240
+ if (isStringable(accountData[key])) {
241
+ result[key] = accountObject.encryptAccountField(key, accountData[key].toString());
242
+ }
243
+ }
244
+
245
+ function encodeWebhooks(accountObject, key, accountData, result) {
246
+ if (!isStringable(accountData[key])) {
247
+ return;
248
+ }
249
+ const value = accountData[key].toString();
250
+ if (!value) {
251
+ // clear potential error flag
252
+ result.webhookErrorFlag = '{}';
253
+ }
254
+ result[key] = accountObject.encryptAccountField(key, value);
255
+ }
256
+
257
+ function encodeJson(accountObject, key, accountData, result) {
258
+ try {
259
+ result[key] = JSON.stringify(accountData[key]);
260
+ } catch (err) {
261
+ logStringifyFailure(accountObject, key, err);
262
+ }
263
+ }
264
+
265
+ // Stored state the sync clients write as JSON themselves. A string given here is that JSON already
266
+ // and is kept as it is; anything else is encoded, so it reads back as the object it was rather than
267
+ // as '[object Object]'
268
+ function encodeStoredJson(accountObject, key, accountData, result) {
269
+ if (typeof accountData[key] === 'string') {
270
+ result[key] = accountData[key];
271
+ return;
272
+ }
273
+ encodeJson(accountObject, key, accountData, result);
274
+ }
275
+
276
+ function encodeOutlookSubscription(accountObject, key, accountData, result) {
277
+ try {
278
+ const objValue = Object.assign({}, accountData[key]);
279
+
280
+ if (typeof objValue.expirationDateTime === 'number' || typeof objValue.expirationDateTime === 'string') {
281
+ objValue.expirationDateTime = new Date(objValue.expirationDateTime);
282
+ }
283
+
284
+ if (isValidDateObject(objValue.expirationDateTime)) {
285
+ objValue.expirationDateTime = objValue.expirationDateTime.toISOString();
286
+ } else if (objValue.expirationDateTime) {
287
+ objValue.expirationDateTime = null;
288
+ }
289
+
290
+ result[key] = JSON.stringify(objValue);
291
+ } catch (err) {
292
+ logStringifyFailure(accountObject, key, err);
293
+ }
294
+ }
295
+
296
+ // Encrypts the credentials of a connection object copy in place; a value that does not encrypt is
297
+ // logged under its own name and stored as it is
298
+ function encryptConnectionSecrets(accountObject, connectData) {
299
+ for (const field of CONNECTION_SECRET_KEYS) {
300
+ let holder;
301
+ if (field in connectData.auth) {
302
+ holder = connectData.auth;
303
+ } else if (field in connectData) {
304
+ holder = connectData;
305
+ } else {
306
+ continue;
307
+ }
308
+ try {
309
+ holder[field] = encrypt(holder[field], accountObject.secret);
310
+ } catch (err) {
311
+ accountObject.logger.error({ msg: 'Failed to encrypt value', key: field, account: accountObject.account, err });
312
+ }
313
+ }
314
+ }
315
+
316
+ function encodeConnectionJson(accountObject, key, accountData, result) {
317
+ try {
318
+ // make a deep copy for manipulation
319
+ const connectData = JSON.parse(JSON.stringify(accountData[key]));
320
+
321
+ // if possible encrypt passwords
322
+ if (accountObject.secret && connectData.auth) {
323
+ encryptConnectionSecrets(accountObject, connectData);
324
+ }
325
+
326
+ for (const subKey of CONNECTION_DATE_KEYS) {
327
+ const date = accountData[key][subKey];
328
+ if (date && typeof date === 'object' && date.toString() !== 'Invalid Date') {
329
+ connectData[subKey] = date.toISOString();
330
+ }
331
+ }
332
+
333
+ result[key] = JSON.stringify(connectData);
334
+ } catch (err) {
335
+ logStringifyFailure(accountObject, key, err);
336
+ }
337
+ }
338
+
339
+ function encodeBool(accountObject, key, accountData, result) {
340
+ if (typeof accountData[key] === 'boolean') {
341
+ result[key] = accountData[key].toString();
342
+ } else if (accountData[key] === null) {
343
+ result[key] = '';
344
+ }
345
+ }
346
+
347
+ // Clearable, so it cannot ride the plain string fallback: that drops nulls, and hmset only ever
348
+ // adds keys, which would leave an identity pin settable but never removable. Follows the same
349
+ // convention as `copy` - null serializes to the empty marker and decodeNonEmpty() treats it as
350
+ // unset - rather than adding a per-field delete to persistUpdate.
351
+ function encodeClearable(accountObject, key, accountData, result) {
352
+ if (typeof accountData[key] === 'string' || accountData[key] === null) {
353
+ result[key] = accountData[key] || '';
354
+ }
355
+ }
356
+
357
+ const FIELD_ENCODERS = new Map([
358
+ ['notifyFrom', encodeDate],
359
+ ['lastWatch', encodeDate],
360
+ ['path', encodePath],
361
+ ['webhooksCustomHeaders', encodeCustomHeaders],
362
+ ['proxy', encodeProxy],
363
+ ['subconnections', encodeJson],
364
+ ['watchResponse', encodeJson],
365
+ ['watchFailure', encodeJson],
366
+ ['outlookSubscription', encodeOutlookSubscription],
367
+ ['imap', encodeConnectionJson],
368
+ ['smtp', encodeConnectionJson],
369
+ ['oauth2', encodeConnectionJson],
370
+ ['imapServerInfo', encodeStoredJson],
371
+ ['smtpServerEhlo', encodeStoredJson],
372
+ ['lastErrorState', encodeStoredJson],
373
+ ['syncError', encodeStoredJson],
374
+ ['smtpStatus', encodeStoredJson],
375
+ ['webhookErrorFlag', encodeStoredJson],
376
+ ['webhooks', encodeWebhooks],
377
+ ['copy', encodeBool],
378
+ ['logs', encodeBool],
379
+ ['expectedEmail', encodeClearable]
380
+ ]);
381
+
382
+ // The plain string fallback for a field with no encoder: null and undefined are not stored, and
383
+ // neither is an object with no string form of its own, which would be stored as '[object Object]'
384
+ function encodePlain(accountObject, key, accountData, result) {
385
+ const value = accountData[key];
386
+ if (!isStringable(value)) {
387
+ return;
388
+ }
389
+ if (value.toString === Object.prototype.toString) {
390
+ logStringifyFailure(accountObject, key, new TypeError('An object has no plain string form'));
391
+ return;
392
+ }
393
+ result[key] = value.toString();
394
+ }
395
+
396
+ module.exports = { FIELD_DECODERS, FIELD_ENCODERS, decodePlain, encodePlain };
@@ -96,19 +96,17 @@ function forgetAccount({ workerAssigned, assigned, unassigned }, account) {
96
96
  }
97
97
 
98
98
  /**
99
- * Whether an account whose `assign` call failed goes back to unassigned. An account that no longer
100
- * exists fails deterministically on every pass, so it is dropped instead: either the worker said so
101
- * (404), or the account is no longer registered, which also covers a delete that raced the pass.
102
- * A failed membership check keeps the account, a lost retry costs more than a wasted one
103
- * @param {Error} err - The error the assign call failed with
99
+ * Whether an account whose `assign` call failed goes back to unassigned: only while it is still
100
+ * registered. An account that no longer exists fails deterministically on every pass, so it is
101
+ * dropped, which also covers a delete that raced the pass. A 404 from the worker is not proof of
102
+ * that on its own: a delegated account answers 404 when the account it delegates to is missing, and
103
+ * dropping it on that left the account unsynced until a restart even after the other one was
104
+ * added. A failed membership check keeps the account, a lost retry costs more than a wasted one
104
105
  * @param {string} account
105
106
  * @param {Function} isRegistered - async account -> boolean
106
107
  * @returns {Promise<boolean>}
107
108
  */
108
- async function shouldRequeueFailedAssignment(err, account, isRegistered) {
109
- if (err && err.statusCode === 404) {
110
- return false;
111
- }
109
+ async function shouldRequeueFailedAssignment(account, isRegistered) {
112
110
  try {
113
111
  return !!(await isRegistered(account));
114
112
  } catch {
@@ -116,6 +114,24 @@ async function shouldRequeueFailedAssignment(err, account, isRegistered) {
116
114
  }
117
115
  }
118
116
 
117
+ /**
118
+ * Registered accounts the assignment state does not know about: neither assigned to a worker nor
119
+ * waiting for one. A `new` dispatch that never reached the main thread leaves an account like that,
120
+ * and nothing else would pick it up before a restart
121
+ * @param {Iterable<string>} registered - Members of the registered account set
122
+ * @param {Object} state - `assigned` and `unassigned`
123
+ * @returns {string[]}
124
+ */
125
+ function findUntrackedAccounts(registered, { assigned, unassigned }) {
126
+ const untracked = new Set();
127
+ for (const account of registered) {
128
+ if (!assigned.has(account) && !unassigned.has(account)) {
129
+ untracked.add(account);
130
+ }
131
+ }
132
+ return Array.from(untracked);
133
+ }
134
+
119
135
  /**
120
136
  * Picks accounts to move onto a worker that joined after the fleet was already serving them (a
121
137
  * worker that restarted after the failsafe reassignment gave its accounts to the survivors).
@@ -190,5 +206,6 @@ module.exports = {
190
206
  requeueFailedAccounts,
191
207
  forgetAccount,
192
208
  shouldRequeueFailedAssignment,
209
+ findUntrackedAccounts,
193
210
  planRebalance
194
211
  };