@remit/mailbox-service 0.0.111 → 0.0.113
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.
- package/dist/account-credentials.d.ts +83 -0
- package/dist/account-credentials.js +104 -0
- package/dist/attribute-mapper.d.ts +36 -0
- package/dist/attribute-mapper.js +119 -0
- package/dist/body-parse.d.ts +28 -0
- package/{src/body-parse.ts → dist/body-parse.js} +18 -26
- package/dist/body-part-mapper.d.ts +92 -0
- package/dist/body-part-mapper.js +301 -0
- package/dist/body-sync-queue.d.ts +59 -0
- package/dist/body-sync-queue.js +56 -0
- package/dist/body-sync-terminal.d.ts +58 -0
- package/dist/body-sync-terminal.js +95 -0
- package/dist/body-sync.d.ts +351 -0
- package/dist/body-sync.js +1204 -0
- package/dist/calendar-parts.d.ts +23 -0
- package/dist/calendar-parts.js +18 -0
- package/dist/classification-backfill.d.ts +91 -0
- package/dist/classification-backfill.js +180 -0
- package/dist/classify-message.d.ts +31 -0
- package/dist/classify-message.js +89 -0
- package/dist/connection-factory.d.ts +54 -0
- package/dist/connection-factory.js +54 -0
- package/dist/connection-test.d.ts +41 -0
- package/dist/connection-test.js +152 -0
- package/dist/external-move.d.ts +94 -0
- package/dist/external-move.js +173 -0
- package/dist/filter-operations.d.ts +42 -0
- package/dist/filter-operations.js +211 -0
- package/dist/filters/filter-config.d.ts +14 -0
- package/dist/filters/filter-config.js +10 -0
- package/{src/filters/list-id.ts → dist/filters/list-id.d.ts} +2 -16
- package/dist/filters/list-id.js +26 -0
- package/dist/filters/match.d.ts +69 -0
- package/dist/filters/match.js +165 -0
- package/dist/filters/pipeline.d.ts +64 -0
- package/dist/filters/pipeline.js +100 -0
- package/{src/flag-push-terminal.ts → dist/flag-push-terminal.d.ts} +19 -77
- package/dist/flag-push-terminal.js +63 -0
- package/dist/flag-push.d.ts +69 -0
- package/dist/flag-push.js +111 -0
- package/dist/flag-queue.d.ts +175 -0
- package/dist/flag-queue.js +291 -0
- package/dist/folder-operations.d.ts +39 -0
- package/dist/folder-operations.js +112 -0
- package/dist/folder-placement.d.ts +13 -0
- package/dist/folder-placement.js +23 -0
- package/dist/heuristics/authenticationResults.d.ts +10 -0
- package/dist/heuristics/authenticationResults.js +187 -0
- package/dist/heuristics/classifyByHeaders.d.ts +82 -0
- package/dist/heuristics/classifyByHeaders.js +365 -0
- package/dist/heuristics/classifyPlacement.d.ts +67 -0
- package/dist/heuristics/classifyPlacement.js +153 -0
- package/dist/heuristics/machineSenders.d.ts +21 -0
- package/{src/heuristics/machineSenders.ts → dist/heuristics/machineSenders.js} +34 -40
- package/dist/heuristics/senderMismatch.d.ts +81 -0
- package/dist/heuristics/senderMismatch.js +192 -0
- package/dist/heuristics/socialDomains.d.ts +14 -0
- package/{src/heuristics/socialDomains.ts → dist/heuristics/socialDomains.js} +9 -9
- package/dist/heuristics/transactionalDomains.d.ts +18 -0
- package/{src/heuristics/transactionalDomains.ts → dist/heuristics/transactionalDomains.js} +8 -8
- package/dist/imapflow-connection.d.ts +377 -0
- package/dist/imapflow-connection.js +1147 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +65 -0
- package/dist/list-id-backfill.d.ts +83 -0
- package/dist/list-id-backfill.js +132 -0
- package/dist/mailbox-cursor-rebuild.d.ts +74 -0
- package/dist/mailbox-cursor-rebuild.js +71 -0
- package/{src/mailbox-cursor.ts → dist/mailbox-cursor.d.ts} +20 -98
- package/dist/mailbox-cursor.js +102 -0
- package/dist/mailbox-intent.d.ts +41 -0
- package/{src/mailbox-intent.ts → dist/mailbox-intent.js} +39 -63
- package/dist/mailbox-management.d.ts +240 -0
- package/dist/mailbox-management.js +576 -0
- package/dist/mailbox-presence.d.ts +52 -0
- package/{src/mailbox-presence.ts → dist/mailbox-presence.js} +19 -30
- package/dist/mailbox-queue.d.ts +126 -0
- package/dist/mailbox-queue.js +214 -0
- package/dist/mailbox-sync.d.ts +93 -0
- package/dist/mailbox-sync.js +490 -0
- package/dist/mailbox-upstream.d.ts +38 -0
- package/{src/mailbox-upstream.ts → dist/mailbox-upstream.js} +37 -47
- package/dist/message-category.d.ts +51 -0
- package/{src/message-category.ts → dist/message-category.js} +28 -71
- package/dist/message-move.d.ts +285 -0
- package/dist/message-move.js +858 -0
- package/dist/message-parser.d.ts +14 -0
- package/dist/message-parser.js +17 -0
- package/{src/message-presence.ts → dist/message-presence.d.ts} +1 -13
- package/dist/message-presence.js +29 -0
- package/dist/message-read.d.ts +51 -0
- package/dist/message-read.js +31 -0
- package/dist/message-sync.d.ts +345 -0
- package/dist/message-sync.js +1358 -0
- package/dist/mime-walker.d.ts +102 -0
- package/dist/mime-walker.js +198 -0
- package/dist/organize-job.d.ts +20 -0
- package/dist/organize-job.js +37 -0
- package/dist/outbox-attachment-content.d.ts +37 -0
- package/dist/outbox-attachment-content.js +50 -0
- package/dist/outbox-attachment-filename.d.ts +19 -0
- package/dist/outbox-attachment-filename.js +64 -0
- package/dist/outbox-attachment.d.ts +148 -0
- package/dist/outbox-attachment.js +273 -0
- package/dist/outbox-queue.d.ts +73 -0
- package/dist/outbox-queue.js +284 -0
- package/{src/outbox-status.ts → dist/outbox-status.d.ts} +1 -6
- package/dist/outbox-status.js +18 -0
- package/dist/ownership.d.ts +24 -0
- package/dist/ownership.js +83 -0
- package/dist/placement-move-terminal.d.ts +67 -0
- package/dist/placement-move-terminal.js +88 -0
- package/dist/placement-move.d.ts +83 -0
- package/dist/placement-move.js +216 -0
- package/{src/placement-settled.ts → dist/placement-settled.d.ts} +19 -50
- package/dist/placement-settled.js +75 -0
- package/dist/quarantine.d.ts +95 -0
- package/dist/quarantine.js +131 -0
- package/dist/refusal.d.ts +31 -0
- package/dist/refusal.js +3 -0
- package/{src/restore-source-placement.ts → dist/restore-source-placement.d.ts} +29 -101
- package/dist/restore-source-placement.js +79 -0
- package/dist/search-text-backfill.d.ts +15 -0
- package/dist/search-text-backfill.js +33 -0
- package/dist/snippet.d.ts +61 -0
- package/dist/snippet.js +129 -0
- package/dist/spam-report.d.ts +86 -0
- package/dist/spam-report.js +241 -0
- package/dist/sync-warning.d.ts +21 -0
- package/dist/sync-warning.js +26 -0
- package/dist/sync-watermarks.d.ts +138 -0
- package/dist/sync-watermarks.js +205 -0
- package/dist/test-helpers/fake-imap.d.ts +151 -0
- package/dist/test-helpers/fake-imap.js +508 -0
- package/dist/test-helpers/folder-roles.d.ts +34 -0
- package/dist/test-helpers/folder-roles.js +47 -0
- package/dist/test-helpers/mime-tree-generator.d.ts +82 -0
- package/dist/test-helpers/mime-tree-generator.js +329 -0
- package/dist/test-helpers/test-store.d.ts +69 -0
- package/dist/test-helpers/test-store.js +193 -0
- package/dist/text/normalizer.d.ts +20 -0
- package/dist/text/normalizer.js +102 -0
- package/dist/thread-message-rows.d.ts +69 -0
- package/dist/thread-message-rows.js +40 -0
- package/dist/thread-root.d.ts +7 -0
- package/dist/thread-root.js +25 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +19 -0
- package/package.json +86 -73
- package/src/account-credentials.ts +0 -210
- package/src/adversarial-mime.e2e.test.ts +0 -307
- package/src/attribute-mapper.test.ts +0 -104
- package/src/attribute-mapper.ts +0 -148
- package/src/body-parse.test.ts +0 -55
- package/src/body-part-mapper.property.test.ts +0 -354
- package/src/body-part-mapper.ts +0 -360
- package/src/body-sync-auto-read-writeonce.test.ts +0 -219
- package/src/body-sync-calendar-suggestion.test.ts +0 -433
- package/src/body-sync-category-denormalize.test.ts +0 -352
- package/src/body-sync-category-override.test.ts +0 -501
- package/src/body-sync-category-writeonce.test.ts +0 -234
- package/src/body-sync-filter.test.ts +0 -237
- package/src/body-sync-message-gone.test.ts +0 -139
- package/src/body-sync-placement-flags.test.ts +0 -347
- package/src/body-sync-placement-writeonce.test.ts +0 -337
- package/src/body-sync-quarantine.test.ts +0 -276
- package/src/body-sync-queue.test.ts +0 -124
- package/src/body-sync-queue.ts +0 -131
- package/src/body-sync-resync.test.ts +0 -605
- package/src/body-sync-terminal.test.ts +0 -310
- package/src/body-sync-terminal.ts +0 -176
- package/src/body-sync-unclassifiable-once.test.ts +0 -260
- package/src/body-sync-unsubscribed-auto-read.test.ts +0 -176
- package/src/body-sync.ts +0 -1970
- package/src/calendar-parts.ts +0 -41
- package/src/classification-backfill.test.ts +0 -615
- package/src/classification-backfill.ts +0 -363
- package/src/classify-message.test.ts +0 -205
- package/src/classify-message.ts +0 -116
- package/src/connection-factory.ts +0 -102
- package/src/connection-test.ts +0 -208
- package/src/credentials.test.ts +0 -181
- package/src/external-move.test.ts +0 -369
- package/src/external-move.ts +0 -272
- package/src/filters/anchor-drift.ts +0 -55
- package/src/filters/filter-config.test.ts +0 -229
- package/src/filters/filter-config.ts +0 -69
- package/src/filters/list-id.test.ts +0 -50
- package/src/filters/match.test.ts +0 -429
- package/src/filters/match.ts +0 -274
- package/src/filters/message-embedder.test.ts +0 -39
- package/src/filters/message-embedder.ts +0 -33
- package/src/filters/pipeline.test.ts +0 -330
- package/src/filters/pipeline.ts +0 -284
- package/src/flag-push-terminal.test.ts +0 -209
- package/src/flag-push.test.ts +0 -408
- package/src/flag-push.ts +0 -198
- package/src/flag-queue-stars.test.ts +0 -171
- package/src/flag-queue.ts +0 -509
- package/src/folder-placement.ts +0 -56
- package/src/heuristics/authenticationResults.test.ts +0 -189
- package/src/heuristics/authenticationResults.ts +0 -212
- package/src/heuristics/classifyByHeaders.test.ts +0 -889
- package/src/heuristics/classifyByHeaders.ts +0 -467
- package/src/heuristics/classifyPlacement.test.ts +0 -366
- package/src/heuristics/classifyPlacement.ts +0 -211
- package/src/heuristics/classifyRealMail.test.ts +0 -242
- package/src/heuristics/machineSenders.test.ts +0 -101
- package/src/heuristics/senderMismatch.test.ts +0 -346
- package/src/heuristics/senderMismatch.ts +0 -259
- package/src/imapflow-connect-retry.test.ts +0 -134
- package/src/imapflow-connection.e2e.test.ts +0 -335
- package/src/imapflow-connection.integ.test.ts +0 -316
- package/src/imapflow-connection.test.ts +0 -469
- package/src/imapflow-connection.ts +0 -1475
- package/src/index.ts +0 -350
- package/src/list-id-backfill.test.ts +0 -573
- package/src/list-id-backfill.ts +0 -274
- package/src/mailbox-cursor-rebuild.test.ts +0 -171
- package/src/mailbox-cursor-rebuild.ts +0 -146
- package/src/mailbox-cursor.test.ts +0 -249
- package/src/mailbox-delete-intent.test.ts +0 -246
- package/src/mailbox-management.test.ts +0 -356
- package/src/mailbox-management.ts +0 -839
- package/src/mailbox-presence.test.ts +0 -72
- package/src/mailbox-queue.ts +0 -415
- package/src/mailbox-rename-intent.test.ts +0 -389
- package/src/mailbox-rename-subtree.test.ts +0 -664
- package/src/mailbox-sync.test.ts +0 -848
- package/src/mailbox-sync.ts +0 -724
- package/src/message-delete-junk-reconcile.test.ts +0 -117
- package/src/message-delete-no-trash.test.ts +0 -245
- package/src/message-delete-unsettled-placement.test.ts +0 -396
- package/src/message-move-copy.test.ts +0 -562
- package/src/message-move-empty-trash.test.ts +0 -326
- package/src/message-move-same-mailbox.test.ts +0 -139
- package/src/message-move-unsettled-placement.test.ts +0 -378
- package/src/message-move.ts +0 -1348
- package/src/message-parser.ts +0 -26
- package/src/message-presence.test.ts +0 -50
- package/src/message-sync-address-spoof.test.ts +0 -293
- package/src/message-sync-category.test.ts +0 -142
- package/src/message-sync-changedsince.test.ts +0 -840
- package/src/message-sync-flags.test.ts +0 -158
- package/src/message-sync-junk-harvest.test.ts +0 -244
- package/src/message-sync-quarantine.test.ts +0 -416
- package/src/message-sync-repoint.test.ts +0 -419
- package/src/message-sync.ts +0 -1963
- package/src/mime-walker.test.ts +0 -311
- package/src/mime-walker.ts +0 -305
- package/src/outbox-attachment-content.test.ts +0 -153
- package/src/outbox-attachment-content.ts +0 -104
- package/src/outbox-attachment-filename.test.ts +0 -132
- package/src/outbox-attachment-filename.ts +0 -76
- package/src/outbox-attachment.test.ts +0 -738
- package/src/outbox-attachment.ts +0 -536
- package/src/outbox-failed-recovery.test.ts +0 -370
- package/src/outbox-queue-settled-row.test.ts +0 -140
- package/src/outbox-queue.test.ts +0 -291
- package/src/outbox-queue.ts +0 -508
- package/src/pass-through-unit-of-work.ts +0 -17
- package/src/placement-move-terminal.test.ts +0 -300
- package/src/placement-move-terminal.ts +0 -148
- package/src/placement-move-unsettled.test.ts +0 -275
- package/src/placement-move.ts +0 -336
- package/src/placement-settled.test.ts +0 -147
- package/src/placement-transition-race.test.ts +0 -482
- package/src/quarantine.test.ts +0 -191
- package/src/quarantine.ts +0 -228
- package/src/snippet.test.ts +0 -213
- package/src/snippet.ts +0 -152
- package/src/spam-report.test.ts +0 -801
- package/src/spam-report.ts +0 -357
- package/src/stale-message-reconcile.test.ts +0 -82
- package/src/stale-message-reconcile.ts +0 -55
- package/src/sync-watermarks.test.ts +0 -409
- package/src/sync-watermarks.ts +0 -319
- package/src/system-flag-wire-format.test.ts +0 -77
- package/src/test-helpers/folder-roles.ts +0 -66
- package/src/test-helpers/isolated-mailbox.ts +0 -44
- package/src/test-helpers/mailfuzz-connection.ts +0 -27
- package/src/test-helpers/mime-tree-generator.ts +0 -461
- package/src/text/normalizer.test.ts +0 -223
- package/src/text/normalizer.ts +0 -140
- package/src/thread-message-rows.ts +0 -77
- package/src/types/mailparser-augment.d.ts +0 -15
- package/src/types/natural-porter-stemmer.d.ts +0 -50
- package/src/types/stopword.d.ts +0 -69
- package/src/types.ts +0 -371
- package/test/fixtures/mime-adversarial-e2e/01-octet-stream-pdf.eml +0 -21
- package/test/fixtures/mime-adversarial-e2e/02-nested-related-cid-image.eml +0 -31
- package/test/fixtures/mime-adversarial-e2e/03-calendar-invite.eml +0 -33
- package/test/fixtures/mime-adversarial-e2e/04-forwarded-rfc822-with-attachments.eml +0 -42
- package/test/fixtures/mime-adversarial-e2e/05-tnef-winmail.eml +0 -25
- package/test/fixtures/mime-adversarial-e2e/06-8bit-non-ascii.eml +0 -15
- package/test/fixtures/mime-adversarial-e2e/07-quoted-printable-soft-breaks.eml +0 -17
- package/test/fixtures/mime-adversarial-e2e/08-alternative-empty-text.eml +0 -18
- package/tsconfig.json +0 -8
|
@@ -1,573 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ListId is only written at body-sync time, going forward (issue #263). A row
|
|
3
|
-
* synced before header extraction shipped keeps `listId` unset forever, so a
|
|
4
|
-
* `ListId` filter clause silently under-matches the back catalogue.
|
|
5
|
-
*
|
|
6
|
-
* These tests pin the one-time, resumable pass that closes that gap: it reads
|
|
7
|
-
* each candidate's already-stored raw source (never IMAP), extracts
|
|
8
|
-
* `List-Id`, and writes only that field.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import assert from "node:assert/strict";
|
|
12
|
-
import { describe, it } from "node:test";
|
|
13
|
-
import type {
|
|
14
|
-
AccountConfigItem,
|
|
15
|
-
IAccountConfigRepository,
|
|
16
|
-
IMessageRepository,
|
|
17
|
-
IThreadMessageRepository,
|
|
18
|
-
MessageItem,
|
|
19
|
-
ResultList,
|
|
20
|
-
ThreadMessageItem,
|
|
21
|
-
UpdateThreadMessageInput,
|
|
22
|
-
} from "@remit/data-ports";
|
|
23
|
-
import type { StorageService } from "@remit/storage-service";
|
|
24
|
-
import {
|
|
25
|
-
backfillListIds,
|
|
26
|
-
type ListIdBackfillCheckpoint,
|
|
27
|
-
type ListIdBackfillCheckpointStore,
|
|
28
|
-
type ListIdBackfillProgress,
|
|
29
|
-
} from "./list-id-backfill.js";
|
|
30
|
-
|
|
31
|
-
const LIST_EML = Buffer.from(
|
|
32
|
-
[
|
|
33
|
-
"From: Weekly News <news@example.com>",
|
|
34
|
-
"To: me@example.com",
|
|
35
|
-
"Subject: This week",
|
|
36
|
-
"List-Id: Weekly News <weekly.news.example.com>",
|
|
37
|
-
"Content-Type: text/plain",
|
|
38
|
-
"",
|
|
39
|
-
"news",
|
|
40
|
-
].join("\r\n"),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
const PLAIN_EML = Buffer.from(
|
|
44
|
-
[
|
|
45
|
-
"From: Alice <alice@example.com>",
|
|
46
|
-
"To: me@example.com",
|
|
47
|
-
"Subject: Hi",
|
|
48
|
-
"Content-Type: text/plain",
|
|
49
|
-
"",
|
|
50
|
-
"hi",
|
|
51
|
-
].join("\r\n"),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const MALFORMED_LIST_ID_EML = Buffer.from(
|
|
55
|
-
[
|
|
56
|
-
"From: Weird <weird@example.com>",
|
|
57
|
-
"To: me@example.com",
|
|
58
|
-
"Subject: Odd header",
|
|
59
|
-
"List-Id:",
|
|
60
|
-
"Content-Type: text/plain",
|
|
61
|
-
"",
|
|
62
|
-
"body",
|
|
63
|
-
].join("\r\n"),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const row = (overrides: Partial<ThreadMessageItem>): ThreadMessageItem =>
|
|
67
|
-
({
|
|
68
|
-
threadMessageId: "tm-1",
|
|
69
|
-
accountConfigId: "acc-1",
|
|
70
|
-
threadId: "thread-1",
|
|
71
|
-
messageId: "m-1",
|
|
72
|
-
mailboxId: "mb-1",
|
|
73
|
-
uid: 1,
|
|
74
|
-
referenceOrder: 0,
|
|
75
|
-
internalDate: 1,
|
|
76
|
-
sentDate: 1,
|
|
77
|
-
isRead: false,
|
|
78
|
-
hasAttachment: false,
|
|
79
|
-
star: "none",
|
|
80
|
-
hasStars: false,
|
|
81
|
-
isDeleted: false,
|
|
82
|
-
category: "uncategorized",
|
|
83
|
-
createdAt: 1,
|
|
84
|
-
updatedAt: 1,
|
|
85
|
-
...overrides,
|
|
86
|
-
}) as unknown as ThreadMessageItem;
|
|
87
|
-
|
|
88
|
-
const message = (overrides: Partial<MessageItem>): MessageItem =>
|
|
89
|
-
({
|
|
90
|
-
messageId: "m-1",
|
|
91
|
-
mailboxId: "mb-1",
|
|
92
|
-
uid: 1,
|
|
93
|
-
status: "active",
|
|
94
|
-
syncStatus: "synced",
|
|
95
|
-
category: "uncategorized",
|
|
96
|
-
hasListUnsubscribe: false,
|
|
97
|
-
movedByRemit: false,
|
|
98
|
-
createdAt: 1,
|
|
99
|
-
updatedAt: 1,
|
|
100
|
-
...overrides,
|
|
101
|
-
}) as unknown as MessageItem;
|
|
102
|
-
|
|
103
|
-
const asAccount = (accountConfigId: string): AccountConfigItem =>
|
|
104
|
-
({ accountConfigId }) as unknown as AccountConfigItem;
|
|
105
|
-
|
|
106
|
-
const inMemoryCheckpointStore = (): ListIdBackfillCheckpointStore => {
|
|
107
|
-
let checkpoint: ListIdBackfillCheckpoint | undefined;
|
|
108
|
-
return {
|
|
109
|
-
load: async () => checkpoint,
|
|
110
|
-
save: async (next) => {
|
|
111
|
-
checkpoint = next;
|
|
112
|
-
},
|
|
113
|
-
clear: async () => {
|
|
114
|
-
checkpoint = undefined;
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
interface Harness {
|
|
120
|
-
accountConfigService: Pick<IAccountConfigRepository, "listAll">;
|
|
121
|
-
threadMessageService: Pick<
|
|
122
|
-
IThreadMessageRepository,
|
|
123
|
-
"listByAccount" | "update"
|
|
124
|
-
>;
|
|
125
|
-
messageService: Pick<IMessageRepository, "get">;
|
|
126
|
-
storageService: Pick<StorageService, "retrieve">;
|
|
127
|
-
updates: Array<{ threadMessageId: string; input: UpdateThreadMessageInput }>;
|
|
128
|
-
retrieved: string[];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const buildHarness = (options: {
|
|
132
|
-
accounts?: AccountConfigItem[];
|
|
133
|
-
rows: ThreadMessageItem[];
|
|
134
|
-
messages: MessageItem[];
|
|
135
|
-
retrieve?: (key: string) => Promise<Buffer>;
|
|
136
|
-
pageSize?: number;
|
|
137
|
-
}): Harness => {
|
|
138
|
-
const accounts = options.accounts ?? [
|
|
139
|
-
{ accountConfigId: "acc-1" } as unknown as AccountConfigItem,
|
|
140
|
-
];
|
|
141
|
-
const messagesById = new Map(options.messages.map((m) => [m.messageId, m]));
|
|
142
|
-
const updates: Array<{
|
|
143
|
-
threadMessageId: string;
|
|
144
|
-
input: UpdateThreadMessageInput;
|
|
145
|
-
}> = [];
|
|
146
|
-
const retrieved: string[] = [];
|
|
147
|
-
const pageSize = options.pageSize ?? 200;
|
|
148
|
-
|
|
149
|
-
const accountConfigService: Pick<IAccountConfigRepository, "listAll"> = {
|
|
150
|
-
listAll: async () => accounts,
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const threadMessageService: Pick<
|
|
154
|
-
IThreadMessageRepository,
|
|
155
|
-
"listByAccount" | "update"
|
|
156
|
-
> = {
|
|
157
|
-
listByAccount: async (
|
|
158
|
-
accountConfigId: string,
|
|
159
|
-
opts?: { limit?: number; continuationToken?: string },
|
|
160
|
-
): Promise<ResultList<ThreadMessageItem>> => {
|
|
161
|
-
const scoped = options.rows.filter(
|
|
162
|
-
(r) => r.accountConfigId === accountConfigId,
|
|
163
|
-
);
|
|
164
|
-
const start = opts?.continuationToken
|
|
165
|
-
? Number(opts.continuationToken)
|
|
166
|
-
: 0;
|
|
167
|
-
const limit = opts?.limit ?? pageSize;
|
|
168
|
-
const page = scoped.slice(start, start + limit);
|
|
169
|
-
const nextStart = start + page.length;
|
|
170
|
-
return {
|
|
171
|
-
items: page,
|
|
172
|
-
continuationToken:
|
|
173
|
-
nextStart < scoped.length ? String(nextStart) : undefined,
|
|
174
|
-
};
|
|
175
|
-
},
|
|
176
|
-
update: async (
|
|
177
|
-
_accountConfigId: string,
|
|
178
|
-
threadMessageId: string,
|
|
179
|
-
input: UpdateThreadMessageInput,
|
|
180
|
-
) => {
|
|
181
|
-
updates.push({ threadMessageId, input });
|
|
182
|
-
return row({ threadMessageId, ...input });
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const messageService: Pick<IMessageRepository, "get"> = {
|
|
187
|
-
get: (async (messageIds: string | string[]) => {
|
|
188
|
-
if (Array.isArray(messageIds)) {
|
|
189
|
-
return messageIds
|
|
190
|
-
.map((id) => messagesById.get(id))
|
|
191
|
-
.filter((m): m is MessageItem => m !== undefined);
|
|
192
|
-
}
|
|
193
|
-
const found = messagesById.get(messageIds);
|
|
194
|
-
if (!found) throw new Error(`no fixture for ${messageIds}`);
|
|
195
|
-
return found;
|
|
196
|
-
}) as IMessageRepository["get"],
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const storageService: Pick<StorageService, "retrieve"> = {
|
|
200
|
-
retrieve: async (key: string) => {
|
|
201
|
-
retrieved.push(key);
|
|
202
|
-
return options.retrieve ? options.retrieve(key) : LIST_EML;
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
return {
|
|
207
|
-
accountConfigService,
|
|
208
|
-
threadMessageService,
|
|
209
|
-
messageService,
|
|
210
|
-
storageService,
|
|
211
|
-
updates,
|
|
212
|
-
retrieved,
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
describe("backfillListIds", () => {
|
|
217
|
-
it("writes the extracted List-Id for a candidate row", async () => {
|
|
218
|
-
const harness = buildHarness({
|
|
219
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
220
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: "s3://m-1" })],
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
const result = await backfillListIds(harness);
|
|
224
|
-
|
|
225
|
-
assert.equal(result.backfilled, 1);
|
|
226
|
-
assert.equal(result.failed, 0);
|
|
227
|
-
assert.equal(harness.updates.length, 1);
|
|
228
|
-
assert.equal(harness.updates[0].input.listId, "weekly.news.example.com");
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("leaves listId empty, without error, when the message has no List-Id header", async () => {
|
|
232
|
-
const harness = buildHarness({
|
|
233
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
234
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: "s3://m-1" })],
|
|
235
|
-
retrieve: async () => PLAIN_EML,
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const result = await backfillListIds(harness);
|
|
239
|
-
|
|
240
|
-
assert.equal(result.noListId, 1);
|
|
241
|
-
assert.equal(result.failed, 0);
|
|
242
|
-
assert.deepEqual(harness.updates, []);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it("does not error on a malformed List-Id header", async () => {
|
|
246
|
-
const harness = buildHarness({
|
|
247
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
248
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: "s3://m-1" })],
|
|
249
|
-
retrieve: async () => MALFORMED_LIST_ID_EML,
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const result = await backfillListIds(harness);
|
|
253
|
-
|
|
254
|
-
assert.equal(result.failed, 0);
|
|
255
|
-
assert.equal(result.noListId, 1);
|
|
256
|
-
assert.deepEqual(harness.updates, []);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it("skips a row whose listId is already set, without reading storage", async () => {
|
|
260
|
-
const harness = buildHarness({
|
|
261
|
-
rows: [
|
|
262
|
-
row({
|
|
263
|
-
threadMessageId: "tm-1",
|
|
264
|
-
messageId: "m-1",
|
|
265
|
-
listId: "already.set",
|
|
266
|
-
}),
|
|
267
|
-
],
|
|
268
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: "s3://m-1" })],
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const result = await backfillListIds(harness);
|
|
272
|
-
|
|
273
|
-
assert.equal(result.alreadySet, 1);
|
|
274
|
-
assert.equal(result.backfilled, 0);
|
|
275
|
-
assert.deepEqual(harness.retrieved, []);
|
|
276
|
-
assert.deepEqual(harness.updates, []);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("skips a candidate whose body was never synced, without reading storage", async () => {
|
|
280
|
-
const harness = buildHarness({
|
|
281
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
282
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: undefined })],
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
const result = await backfillListIds(harness);
|
|
286
|
-
|
|
287
|
-
assert.equal(result.skippedNoBody, 1);
|
|
288
|
-
assert.deepEqual(harness.retrieved, []);
|
|
289
|
-
assert.deepEqual(harness.updates, []);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it("contains a storage failure to the one message and keeps going", async () => {
|
|
293
|
-
const harness = buildHarness({
|
|
294
|
-
rows: [
|
|
295
|
-
row({ threadMessageId: "tm-bad", messageId: "m-bad" }),
|
|
296
|
-
row({ threadMessageId: "tm-good", messageId: "m-good" }),
|
|
297
|
-
],
|
|
298
|
-
messages: [
|
|
299
|
-
message({ messageId: "m-bad", bodyStorageKey: "s3://m-bad" }),
|
|
300
|
-
message({ messageId: "m-good", bodyStorageKey: "s3://m-good" }),
|
|
301
|
-
],
|
|
302
|
-
retrieve: async (key) => {
|
|
303
|
-
if (key === "s3://m-bad") throw new Error("AccessDenied");
|
|
304
|
-
return LIST_EML;
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
const result = await backfillListIds(harness);
|
|
309
|
-
|
|
310
|
-
assert.equal(result.failed, 1);
|
|
311
|
-
assert.deepEqual(result.failedThreadMessageIds, ["tm-bad"]);
|
|
312
|
-
assert.equal(result.backfilled, 1);
|
|
313
|
-
assert.equal(harness.updates.length, 1);
|
|
314
|
-
assert.equal(harness.updates[0].threadMessageId, "tm-good");
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it("reports progress as pages are processed", async () => {
|
|
318
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
319
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
320
|
-
);
|
|
321
|
-
const messages = rows.map((r) =>
|
|
322
|
-
message({
|
|
323
|
-
messageId: r.messageId,
|
|
324
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
325
|
-
}),
|
|
326
|
-
);
|
|
327
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
328
|
-
const progress: ListIdBackfillProgress[] = [];
|
|
329
|
-
|
|
330
|
-
const result = await backfillListIds(harness, {
|
|
331
|
-
batchSize: 2,
|
|
332
|
-
onProgress: (p) => progress.push({ ...p }),
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
assert.equal(result.backfilled, 3);
|
|
336
|
-
assert.equal(progress.length, 2);
|
|
337
|
-
assert.equal(progress[0].scanned, 2);
|
|
338
|
-
assert.equal(progress[1].scanned, 3);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("scans every account returned by listAll", async () => {
|
|
342
|
-
const harness = buildHarness({
|
|
343
|
-
accounts: [
|
|
344
|
-
{ accountConfigId: "acc-1" } as unknown as AccountConfigItem,
|
|
345
|
-
{ accountConfigId: "acc-2" } as unknown as AccountConfigItem,
|
|
346
|
-
],
|
|
347
|
-
rows: [
|
|
348
|
-
row({
|
|
349
|
-
threadMessageId: "tm-1",
|
|
350
|
-
messageId: "m-1",
|
|
351
|
-
accountConfigId: "acc-1",
|
|
352
|
-
}),
|
|
353
|
-
row({
|
|
354
|
-
threadMessageId: "tm-2",
|
|
355
|
-
messageId: "m-2",
|
|
356
|
-
accountConfigId: "acc-2",
|
|
357
|
-
}),
|
|
358
|
-
],
|
|
359
|
-
messages: [
|
|
360
|
-
message({ messageId: "m-1", bodyStorageKey: "s3://m-1" }),
|
|
361
|
-
message({ messageId: "m-2", bodyStorageKey: "s3://m-2" }),
|
|
362
|
-
],
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
const result = await backfillListIds(harness);
|
|
366
|
-
|
|
367
|
-
assert.equal(result.backfilled, 2);
|
|
368
|
-
assert.equal(harness.updates.length, 2);
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it("scans accounts in account-id order, whatever order listAll returns", async () => {
|
|
372
|
-
const accountIds = ["acc-1", "acc-2", "acc-3"];
|
|
373
|
-
const rows = accountIds.map((accountConfigId) =>
|
|
374
|
-
row({
|
|
375
|
-
threadMessageId: `tm-${accountConfigId}`,
|
|
376
|
-
messageId: `m-${accountConfigId}`,
|
|
377
|
-
accountConfigId,
|
|
378
|
-
}),
|
|
379
|
-
);
|
|
380
|
-
const harness = buildHarness({
|
|
381
|
-
accounts: ["acc-3", "acc-1", "acc-2"].map(asAccount),
|
|
382
|
-
rows,
|
|
383
|
-
messages: rows.map((r) =>
|
|
384
|
-
message({
|
|
385
|
-
messageId: r.messageId,
|
|
386
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
387
|
-
}),
|
|
388
|
-
),
|
|
389
|
-
});
|
|
390
|
-
const progress: ListIdBackfillProgress[] = [];
|
|
391
|
-
|
|
392
|
-
await backfillListIds(harness, {
|
|
393
|
-
onProgress: (p) => progress.push({ ...p }),
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
assert.deepEqual(
|
|
397
|
-
progress.map((p) => p.accountConfigId),
|
|
398
|
-
accountIds,
|
|
399
|
-
);
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it("checkpoints after each page and clears it on completion", async () => {
|
|
403
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
404
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
405
|
-
);
|
|
406
|
-
const messages = rows.map((r) =>
|
|
407
|
-
message({
|
|
408
|
-
messageId: r.messageId,
|
|
409
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
410
|
-
}),
|
|
411
|
-
);
|
|
412
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
413
|
-
|
|
414
|
-
const saved: ListIdBackfillCheckpoint[] = [];
|
|
415
|
-
let cleared = false;
|
|
416
|
-
|
|
417
|
-
await backfillListIds(harness, {
|
|
418
|
-
batchSize: 2,
|
|
419
|
-
checkpointStore: {
|
|
420
|
-
load: async () => undefined,
|
|
421
|
-
save: async (checkpoint) => {
|
|
422
|
-
saved.push(checkpoint);
|
|
423
|
-
},
|
|
424
|
-
clear: async () => {
|
|
425
|
-
cleared = true;
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
assert.equal(saved.length, 2);
|
|
431
|
-
assert.equal(saved[0].accountConfigId, "acc-1");
|
|
432
|
-
assert.equal(saved[0].continuationToken, "2");
|
|
433
|
-
assert.equal(saved[1].continuationToken, undefined);
|
|
434
|
-
assert.equal(cleared, true);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
it("resumes from a saved checkpoint instead of rescanning from the start", async () => {
|
|
438
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
439
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
440
|
-
);
|
|
441
|
-
const messages = rows.map((r) =>
|
|
442
|
-
message({
|
|
443
|
-
messageId: r.messageId,
|
|
444
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
445
|
-
}),
|
|
446
|
-
);
|
|
447
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
448
|
-
|
|
449
|
-
const result = await backfillListIds(harness, {
|
|
450
|
-
batchSize: 2,
|
|
451
|
-
checkpointStore: {
|
|
452
|
-
load: async () => ({
|
|
453
|
-
accountConfigId: "acc-1",
|
|
454
|
-
continuationToken: "2",
|
|
455
|
-
}),
|
|
456
|
-
save: async () => {},
|
|
457
|
-
clear: async () => {},
|
|
458
|
-
},
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
assert.equal(result.scanned, 1);
|
|
462
|
-
assert.equal(result.backfilled, 1);
|
|
463
|
-
assert.deepEqual(
|
|
464
|
-
harness.updates.map((u) => u.threadMessageId),
|
|
465
|
-
["tm-2"],
|
|
466
|
-
);
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it("resumes the account it was working through after an earlier account is removed", async () => {
|
|
470
|
-
const accountIds = ["acc-1", "acc-2", "acc-3"];
|
|
471
|
-
const rows = [
|
|
472
|
-
row({
|
|
473
|
-
threadMessageId: "tm-1",
|
|
474
|
-
messageId: "m-1",
|
|
475
|
-
accountConfigId: "acc-1",
|
|
476
|
-
}),
|
|
477
|
-
row({
|
|
478
|
-
threadMessageId: "tm-2a",
|
|
479
|
-
messageId: "m-2a",
|
|
480
|
-
accountConfigId: "acc-2",
|
|
481
|
-
}),
|
|
482
|
-
row({
|
|
483
|
-
threadMessageId: "tm-2b",
|
|
484
|
-
messageId: "m-2b",
|
|
485
|
-
accountConfigId: "acc-2",
|
|
486
|
-
}),
|
|
487
|
-
row({
|
|
488
|
-
threadMessageId: "tm-3",
|
|
489
|
-
messageId: "m-3",
|
|
490
|
-
accountConfigId: "acc-3",
|
|
491
|
-
}),
|
|
492
|
-
];
|
|
493
|
-
const messages = rows.map((r) =>
|
|
494
|
-
message({
|
|
495
|
-
messageId: r.messageId,
|
|
496
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
497
|
-
}),
|
|
498
|
-
);
|
|
499
|
-
|
|
500
|
-
const store = inMemoryCheckpointStore();
|
|
501
|
-
|
|
502
|
-
const interrupted = buildHarness({
|
|
503
|
-
accounts: accountIds.map(asAccount),
|
|
504
|
-
rows,
|
|
505
|
-
messages,
|
|
506
|
-
pageSize: 1,
|
|
507
|
-
});
|
|
508
|
-
const listByAccount = interrupted.threadMessageService.listByAccount;
|
|
509
|
-
interrupted.threadMessageService.listByAccount = async (
|
|
510
|
-
accountConfigId,
|
|
511
|
-
opts,
|
|
512
|
-
) => {
|
|
513
|
-
if (accountConfigId === "acc-2" && opts?.continuationToken) {
|
|
514
|
-
throw new Error("interrupted");
|
|
515
|
-
}
|
|
516
|
-
return listByAccount(accountConfigId, opts);
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
await assert.rejects(
|
|
520
|
-
backfillListIds(interrupted, { batchSize: 1, checkpointStore: store }),
|
|
521
|
-
/interrupted/,
|
|
522
|
-
);
|
|
523
|
-
|
|
524
|
-
const resumed = buildHarness({
|
|
525
|
-
accounts: ["acc-2", "acc-3"].map(asAccount),
|
|
526
|
-
rows,
|
|
527
|
-
messages,
|
|
528
|
-
pageSize: 1,
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
const result = await backfillListIds(resumed, {
|
|
532
|
-
batchSize: 1,
|
|
533
|
-
checkpointStore: store,
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
assert.deepEqual(
|
|
537
|
-
resumed.updates.map((u) => u.threadMessageId),
|
|
538
|
-
["tm-2b", "tm-3"],
|
|
539
|
-
);
|
|
540
|
-
assert.equal(result.backfilled, 2);
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
it("restarts the pass when the checkpointed account no longer exists", async () => {
|
|
544
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
545
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
546
|
-
);
|
|
547
|
-
const messages = rows.map((r) =>
|
|
548
|
-
message({
|
|
549
|
-
messageId: r.messageId,
|
|
550
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
551
|
-
}),
|
|
552
|
-
);
|
|
553
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
554
|
-
|
|
555
|
-
const result = await backfillListIds(harness, {
|
|
556
|
-
batchSize: 2,
|
|
557
|
-
checkpointStore: {
|
|
558
|
-
load: async () => ({
|
|
559
|
-
accountConfigId: "acc-removed",
|
|
560
|
-
continuationToken: "2",
|
|
561
|
-
}),
|
|
562
|
-
save: async () => {},
|
|
563
|
-
clear: async () => {},
|
|
564
|
-
},
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
assert.equal(result.scanned, 3);
|
|
568
|
-
assert.deepEqual(
|
|
569
|
-
harness.updates.map((u) => u.threadMessageId),
|
|
570
|
-
["tm-0", "tm-1", "tm-2"],
|
|
571
|
-
);
|
|
572
|
-
});
|
|
573
|
-
});
|