@remit/imap-worker 0.0.89 → 0.0.91

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 (171) hide show
  1. package/dist/account-check.d.ts +27 -0
  2. package/dist/account-check.js +70 -0
  3. package/dist/body-sync-gate.d.ts +12 -0
  4. package/dist/body-sync-gate.js +53 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +193 -0
  7. package/dist/config-env.d.ts +5 -0
  8. package/dist/config-env.js +37 -0
  9. package/dist/connection-pool.d.ts +22 -0
  10. package/dist/connection-pool.js +97 -0
  11. package/dist/connection-scope.d.ts +8 -0
  12. package/dist/connection-scope.js +10 -0
  13. package/dist/context.d.ts +46 -0
  14. package/dist/context.js +15 -0
  15. package/dist/e2e-processor-shim.d.ts +2 -0
  16. package/dist/e2e-processor-shim.js +181 -0
  17. package/dist/emit.d.ts +15 -0
  18. package/dist/emit.js +76 -0
  19. package/dist/events.d.ts +203 -0
  20. package/dist/events.js +1 -0
  21. package/dist/failure-kind.d.ts +10 -0
  22. package/{src/failure-kind.ts → dist/failure-kind.js} +6 -6
  23. package/dist/handlers/append-sent-message.d.ts +3 -0
  24. package/dist/handlers/append-sent-message.js +152 -0
  25. package/dist/handlers/delete-account-objects.d.ts +3 -0
  26. package/dist/handlers/delete-account-objects.js +35 -0
  27. package/dist/handlers/empty-trash.d.ts +14 -0
  28. package/dist/handlers/empty-trash.js +217 -0
  29. package/dist/handlers/flag-push.d.ts +38 -0
  30. package/dist/handlers/flag-push.js +195 -0
  31. package/dist/handlers/imported-folder.d.ts +4 -0
  32. package/dist/handlers/imported-folder.js +23 -0
  33. package/dist/handlers/mailbox-management.d.ts +6 -0
  34. package/dist/handlers/mailbox-management.js +294 -0
  35. package/dist/handlers/mailbox-sync-order.d.ts +21 -0
  36. package/dist/handlers/mailbox-sync-order.js +50 -0
  37. package/dist/handlers/message-copy.d.ts +40 -0
  38. package/dist/handlers/message-copy.js +371 -0
  39. package/dist/handlers/message-delete-terminal.d.ts +60 -0
  40. package/dist/handlers/message-delete-terminal.js +77 -0
  41. package/dist/handlers/message-delete.d.ts +57 -0
  42. package/dist/handlers/message-delete.js +520 -0
  43. package/{src/handlers/message-move-terminal.ts → dist/handlers/message-move-terminal.d.ts} +18 -105
  44. package/dist/handlers/message-move-terminal.js +94 -0
  45. package/dist/handlers/message-move.d.ts +146 -0
  46. package/dist/handlers/message-move.js +490 -0
  47. package/dist/handlers/placement-move-push.d.ts +62 -0
  48. package/dist/handlers/placement-move-push.js +307 -0
  49. package/dist/handlers/probe-message-id.d.ts +2 -0
  50. package/dist/handlers/probe-message-id.js +6 -0
  51. package/dist/handlers/sync-mailboxes.d.ts +45 -0
  52. package/dist/handlers/sync-mailboxes.js +233 -0
  53. package/dist/handlers/sync-message-body.d.ts +23 -0
  54. package/dist/handlers/sync-message-body.js +182 -0
  55. package/dist/handlers/sync-messages.d.ts +29 -0
  56. package/dist/handlers/sync-messages.js +285 -0
  57. package/dist/index.d.ts +9 -0
  58. package/dist/index.js +67 -0
  59. package/dist/lambda-context.d.ts +8 -0
  60. package/dist/lambda-context.js +33 -0
  61. package/dist/mailbox-row.d.ts +9 -0
  62. package/dist/mailbox-row.js +6 -0
  63. package/dist/poller.d.ts +1 -0
  64. package/dist/poller.js +51 -0
  65. package/dist/process.d.ts +6 -0
  66. package/dist/process.js +3 -0
  67. package/dist/processor.d.ts +3 -0
  68. package/dist/processor.js +44 -0
  69. package/dist/queues.d.ts +10 -0
  70. package/dist/queues.js +1 -0
  71. package/dist/s3-account-objects.d.ts +3 -0
  72. package/dist/s3-account-objects.js +26 -0
  73. package/dist/scheduler/attachment-sweep.d.ts +11 -0
  74. package/dist/scheduler/attachment-sweep.js +23 -0
  75. package/dist/scheduler/calendar-subscriptions.d.ts +26 -0
  76. package/dist/scheduler/calendar-subscriptions.js +35 -0
  77. package/dist/scheduler/config.d.ts +27 -0
  78. package/{src/scheduler/config.ts → dist/scheduler/config.js} +7 -26
  79. package/{src/scheduler/decide-due.ts → dist/scheduler/decide-due.d.ts} +3 -12
  80. package/dist/scheduler/decide-due.js +17 -0
  81. package/dist/scheduler/handler.d.ts +21 -0
  82. package/{src/scheduler/handler.ts → dist/scheduler/handler.js} +24 -36
  83. package/{src/scheduler/loop.ts → dist/scheduler/loop.d.ts} +7 -23
  84. package/dist/scheduler/loop.js +8 -0
  85. package/dist/scheduler/run-tick.d.ts +62 -0
  86. package/dist/scheduler/run-tick.js +164 -0
  87. package/dist/scheduler/runner.d.ts +2 -0
  88. package/{src/scheduler/runner.ts → dist/scheduler/runner.js} +58 -84
  89. package/dist/scheduler/stranded-placement-redrive.d.ts +16 -0
  90. package/dist/scheduler/stranded-placement-redrive.js +172 -0
  91. package/dist/sqs-queues.d.ts +4 -0
  92. package/dist/sqs-queues.js +22 -0
  93. package/dist/with-oauth-lifecycle-deps.d.ts +5 -0
  94. package/dist/with-oauth-lifecycle-deps.js +17 -0
  95. package/dist/with-oauth-lifecycle.d.ts +56 -0
  96. package/dist/with-oauth-lifecycle.js +92 -0
  97. package/{src/worker-version.ts → dist/worker-version.d.ts} +1 -2
  98. package/dist/worker-version.js +12 -0
  99. package/package.json +75 -69
  100. package/src/account-check.test.ts +0 -149
  101. package/src/account-check.ts +0 -101
  102. package/src/body-sync-gate.test.ts +0 -185
  103. package/src/body-sync-gate.ts +0 -86
  104. package/src/cli.ts +0 -224
  105. package/src/connection-scope.test.ts +0 -266
  106. package/src/connection-scope.ts +0 -314
  107. package/src/credential-less-sync-fence.test.ts +0 -152
  108. package/src/e2e-processor-shim.ts +0 -232
  109. package/src/emit.test.ts +0 -127
  110. package/src/emit.ts +0 -117
  111. package/src/events.ts +0 -252
  112. package/src/failure-kind.test.ts +0 -42
  113. package/src/handlers/append-sent-message.sqlite.test.ts +0 -176
  114. package/src/handlers/append-sent-message.ts +0 -264
  115. package/src/handlers/delete-account-objects.test.ts +0 -128
  116. package/src/handlers/delete-account-objects.ts +0 -94
  117. package/src/handlers/empty-trash.sqlite.test.ts +0 -209
  118. package/src/handlers/empty-trash.ts +0 -352
  119. package/src/handlers/flag-push.ts +0 -285
  120. package/src/handlers/imported-folder.test.ts +0 -63
  121. package/src/handlers/imported-folder.ts +0 -38
  122. package/src/handlers/mailbox-management.sqlite.test.ts +0 -265
  123. package/src/handlers/mailbox-management.ts +0 -486
  124. package/src/handlers/mailbox-sync-order.test.ts +0 -93
  125. package/src/handlers/mailbox-sync-order.ts +0 -65
  126. package/src/handlers/message-copy.sqlite.test.ts +0 -298
  127. package/src/handlers/message-copy.ts +0 -566
  128. package/src/handlers/message-delete-terminal.ts +0 -147
  129. package/src/handlers/message-delete.sqlite.test.ts +0 -291
  130. package/src/handlers/message-delete.ts +0 -885
  131. package/src/handlers/message-move.sqlite.test.ts +0 -271
  132. package/src/handlers/message-move.test.ts +0 -216
  133. package/src/handlers/message-move.ts +0 -752
  134. package/src/handlers/placement-move-push.test.ts +0 -137
  135. package/src/handlers/placement-move-push.ts +0 -475
  136. package/src/handlers/placement-push.sqlite.test.ts +0 -298
  137. package/src/handlers/probe-message-id.sqlite.test.ts +0 -192
  138. package/src/handlers/probe-message-id.ts +0 -15
  139. package/src/handlers/sync-mailboxes.test.ts +0 -183
  140. package/src/handlers/sync-mailboxes.ts +0 -421
  141. package/src/handlers/sync-message-body.sqlite.test.ts +0 -314
  142. package/src/handlers/sync-message-body.test.ts +0 -150
  143. package/src/handlers/sync-message-body.ts +0 -365
  144. package/src/handlers/sync-messages.sqlite.test.ts +0 -183
  145. package/src/handlers/sync-messages.ts +0 -525
  146. package/src/index.test.ts +0 -22
  147. package/src/index.ts +0 -86
  148. package/src/mail-sync-selection.sqlite.test.ts +0 -234
  149. package/src/mailbox-row.ts +0 -20
  150. package/src/pending-sync.sqlite.test.ts +0 -166
  151. package/src/poller.ts +0 -55
  152. package/src/processor.ts +0 -60
  153. package/src/queues.ts +0 -49
  154. package/src/scheduler/attachment-sweep.sqlite.test.ts +0 -75
  155. package/src/scheduler/attachment-sweep.ts +0 -46
  156. package/src/scheduler/calendar-subscriptions.sqlite.test.ts +0 -147
  157. package/src/scheduler/calendar-subscriptions.ts +0 -103
  158. package/src/scheduler/config.test.ts +0 -40
  159. package/src/scheduler/decide-due.test.ts +0 -44
  160. package/src/scheduler/half-deleted-accounts.sqlite.test.ts +0 -196
  161. package/src/scheduler/loop.test.ts +0 -143
  162. package/src/scheduler/run-tick.sqlite.test.ts +0 -191
  163. package/src/scheduler/run-tick.ts +0 -281
  164. package/src/scheduler/stranded-placement-redrive.ts +0 -265
  165. package/src/stranded-placement.sqlite.test.ts +0 -794
  166. package/src/test-helpers/test-world.ts +0 -427
  167. package/src/thread-join.sqlite.test.ts +0 -106
  168. package/src/with-oauth-lifecycle-deps.sqlite.test.ts +0 -269
  169. package/src/with-oauth-lifecycle-deps.ts +0 -71
  170. package/src/with-oauth-lifecycle.ts +0 -158
  171. package/tsconfig.json +0 -8
@@ -1,298 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { after, before, describe, it } from "node:test";
3
- import {
4
- MailboxCursorState,
5
- MessageMutation,
6
- MessageStatus,
7
- MessageSyncStatus,
8
- } from "@remit/domain-enums";
9
- import type {
10
- MessageCopyEvent,
11
- MessageDeleteEvent,
12
- MessageMoveEvent,
13
- } from "../events.js";
14
- import { mail, openStore, type World } from "../test-helpers/test-world.js";
15
- import { handleMessageCopy } from "./message-copy.js";
16
- import { handleMessageDelete } from "./message-delete.js";
17
- import { handleMessageMove } from "./message-move.js";
18
-
19
- let store: Awaited<ReturnType<typeof openStore>>;
20
-
21
- before(async () => {
22
- store = await openStore();
23
- });
24
-
25
- after(() => store.close());
26
-
27
- interface Arranged {
28
- w: World;
29
- copyId: string;
30
- sourceMessageId: string;
31
- uid: number;
32
- messageIdHeader: string;
33
- inboxId: string;
34
- projectsId: string;
35
- event: MessageCopyEvent;
36
- }
37
-
38
- /** A message in INBOX, copied to Projects through the service the API calls. */
39
- const arrange = async (
40
- options: { olderCopyInProjects?: boolean } = {},
41
- ): Promise<Arranged> => {
42
- const w = await store.world();
43
- const inbox = await w.folder("INBOX");
44
- const projects = await w.folder("Projects");
45
- const seeded = await w.message(inbox);
46
- if (options.olderCopyInProjects) {
47
- w.imap.deliver("Projects", mail(seeded.messageIdHeader));
48
- }
49
-
50
- const copyId = await w.client.messageMove.copyMessage(
51
- w.account.accountConfigId,
52
- seeded.messageId,
53
- projects.mailboxId,
54
- w.account.accountId,
55
- );
56
- const event = w
57
- .queued()
58
- .find(
59
- (body) => body.type === "MESSAGE_COPY",
60
- ) as unknown as MessageCopyEvent;
61
- assert.ok(event, "the copy enqueued a MESSAGE_COPY");
62
-
63
- return {
64
- w,
65
- copyId,
66
- sourceMessageId: seeded.messageId,
67
- uid: seeded.uid,
68
- messageIdHeader: seeded.messageIdHeader,
69
- inboxId: inbox.mailboxId,
70
- projectsId: projects.mailboxId,
71
- event,
72
- };
73
- };
74
-
75
- const run = (a: Arranged, receiveCount = 1) =>
76
- handleMessageCopy(a.event, a.w.log, receiveCount, a.w.scope);
77
-
78
- describe("a message copy", () => {
79
- it("lands at the destination, leaves the source alone and settles the copy row", async () => {
80
- const a = await arrange();
81
-
82
- await run(a);
83
-
84
- assert.deepEqual(a.w.imap.uids("INBOX"), [a.uid]);
85
- const [copyUid] = a.w.imap.uids("Projects", a.messageIdHeader);
86
- const row = await a.w.row(a.copyId);
87
- assert.equal(row?.mailboxId, a.projectsId);
88
- assert.equal(row?.uid, copyUid);
89
- assert.equal(row?.status, MessageStatus.active);
90
- assert.equal(row?.syncStatus, MessageSyncStatus.synced);
91
- assert.equal((await a.w.row(a.sourceMessageId))?.mailboxId, a.inboxId);
92
- });
93
-
94
- it("settles on the copy this event made when the server sends no COPYUID", async () => {
95
- const a = await arrange({ olderCopyInProjects: true });
96
- a.w.imap.uidplus = false;
97
-
98
- await run(a);
99
-
100
- const copies = a.w.imap.uids("Projects", a.messageIdHeader);
101
- assert.equal(copies.length, 2);
102
- assert.equal((await a.w.row(a.copyId))?.uid, Math.max(...copies));
103
- });
104
-
105
- it("reconciles the copy row away when the destination does not hold the copy", async () => {
106
- const a = await arrange();
107
- a.w.imap.uidplus = false;
108
- a.w.imap.ignoreNext.add("COPY");
109
-
110
- await run(a);
111
-
112
- assert.equal(await a.w.row(a.copyId), undefined);
113
- assert.equal(
114
- a.w.logs.filter(
115
- (line) => line.fields.metric === "message_copy_not_landed",
116
- ).length,
117
- 1,
118
- );
119
- });
120
-
121
- // COPY has no source-side effect, so a second one is a duplicate the user
122
- // then has to find and delete.
123
- it("never copies twice when a redelivery finds the copy already landed", async () => {
124
- const a = await arrange();
125
- a.w.imap.deliver("Projects", mail(a.messageIdHeader));
126
-
127
- await run(a, 2);
128
-
129
- assert.deepEqual(a.w.imap.commands("COPY"), []);
130
- assert.equal(a.w.imap.uids("Projects", a.messageIdHeader).length, 1);
131
- assert.equal((await a.w.row(a.copyId))?.status, MessageStatus.active);
132
- });
133
-
134
- it("issues nothing when a redelivery finds the copy already settled", async () => {
135
- const a = await arrange();
136
- await run(a);
137
- const commands = a.w.imap.log.length;
138
-
139
- await run(a);
140
-
141
- assert.equal(a.w.imap.log.length, commands);
142
- });
143
-
144
- it("creates a destination the server does not have and redelivers", async () => {
145
- const a = await arrange();
146
- a.w.imap.removeFolder("Projects");
147
-
148
- await assert.rejects(run(a), /TRYCREATE/);
149
-
150
- assert.deepEqual(a.w.imap.commands("CREATE"), ["CREATE Projects"]);
151
- });
152
-
153
- it("gives the copy up when the source message is gone on the server", async () => {
154
- const a = await arrange();
155
- a.w.imap.failNext.COPY = new Error("Message not found (NONEXISTENT)");
156
-
157
- await run(a);
158
-
159
- const row = await a.w.row(a.copyId);
160
- assert.equal(row?.status, MessageStatus.deleted);
161
- assert.equal(row?.syncStatus, MessageSyncStatus.abandoned);
162
- assert.equal(row?.abandonedMutation, MessageMutation.copy);
163
- });
164
-
165
- it("marks the copy failed and redelivers when the connection drops", async () => {
166
- const a = await arrange();
167
- a.w.imap.failNext.COPY = new Error("Connection reset");
168
-
169
- await assert.rejects(run(a), /Connection reset/);
170
-
171
- assert.equal(
172
- (await a.w.row(a.copyId))?.syncStatus,
173
- MessageSyncStatus.failed,
174
- );
175
- });
176
-
177
- it("settles on the destination's copy at the ceiling instead of dead-lettering", async () => {
178
- const a = await arrange();
179
- a.w.imap.deliver("Projects", mail(a.messageIdHeader));
180
- a.w.imap.failNext.COPY = new Error("Connection reset");
181
-
182
- await run(a, 3);
183
-
184
- const [copyUid] = a.w.imap.uids("Projects", a.messageIdHeader);
185
- const row = await a.w.row(a.copyId);
186
- assert.equal(row?.uid, copyUid);
187
- assert.equal(row?.status, MessageStatus.active);
188
- });
189
-
190
- it("reconciles the copy row away at the ceiling when nothing reached the destination", async () => {
191
- const a = await arrange();
192
- a.w.imap.failNext.COPY = new Error("Connection reset");
193
-
194
- await run(a, 3);
195
-
196
- assert.equal(await a.w.row(a.copyId), undefined);
197
- });
198
-
199
- it("reconciles the copy row away without connecting when the destination mailbox was deleted", async () => {
200
- const a = await arrange();
201
- await a.w.client.mailbox.delete(a.w.account.accountId, a.projectsId);
202
-
203
- await run(a);
204
-
205
- assert.equal(a.w.imap.connections, 0);
206
- assert.equal(await a.w.row(a.copyId), undefined);
207
- });
208
-
209
- it("reconciles the copy row away without connecting while the source cursor is rebuilding", async () => {
210
- const a = await arrange();
211
- await a.w.client.mailbox.update(a.w.account.accountId, a.inboxId, {
212
- cursorState: MailboxCursorState.rebuilding,
213
- });
214
-
215
- await run(a);
216
-
217
- assert.equal(a.w.imap.connections, 0);
218
- assert.equal(await a.w.row(a.copyId), undefined);
219
- });
220
-
221
- it("copies nothing when the source's UIDVALIDITY changed under it", async () => {
222
- const a = await arrange();
223
- a.w.imap.setUidValidity("INBOX", 2);
224
-
225
- await run(a);
226
-
227
- assert.deepEqual(a.w.imap.commands("COPY"), []);
228
- assert.equal(await a.w.row(a.copyId), undefined);
229
- });
230
-
231
- it("acks without connecting when the source mailbox was deleted", async () => {
232
- const a = await arrange();
233
- await a.w.client.mailbox.delete(a.w.account.accountId, a.inboxId);
234
-
235
- await run(a);
236
-
237
- assert.equal(a.w.imap.connections, 0);
238
- });
239
- });
240
-
241
- describe("a fresh copy acted on before the server confirms it", () => {
242
- const isMove = (
243
- body: Record<string, unknown>,
244
- ): body is Record<string, unknown> & MessageMoveEvent =>
245
- body.type === "MESSAGE_MOVE";
246
- const isDelete = (
247
- body: Record<string, unknown>,
248
- ): body is Record<string, unknown> & MessageDeleteEvent =>
249
- body.type === "MESSAGE_DELETE";
250
-
251
- it("waits for the copy to settle, then moves the copy and leaves the original", async () => {
252
- const a = await arrange();
253
-
254
- const moving = a.w.client.messageMove.moveMessage(
255
- a.w.account.accountConfigId,
256
- a.copyId,
257
- a.inboxId,
258
- a.w.account.accountId,
259
- );
260
- await run(a);
261
- await moving;
262
- const [copyUid] = a.w.imap.uids("Projects", a.messageIdHeader);
263
- const event = a.w.queued().find(isMove);
264
- assert.ok(event, "the move enqueued a MESSAGE_MOVE");
265
- assert.equal(event.uid, copyUid);
266
-
267
- await handleMessageMove(event, a.w.log, 1, a.w.scope);
268
-
269
- assert.deepEqual(a.w.imap.uids("Projects", a.messageIdHeader), []);
270
- assert.equal(a.w.imap.uids("INBOX", a.messageIdHeader).length, 2);
271
- const row = await a.w.row(a.copyId);
272
- assert.equal(row?.mailboxId, a.inboxId);
273
- assert.equal(row?.status, MessageStatus.active);
274
- assert.equal((await a.w.row(a.sourceMessageId))?.uid, a.uid);
275
- });
276
-
277
- it("waits for the copy to settle, then expunges the copy and leaves the original", async () => {
278
- const a = await arrange();
279
-
280
- const deleting = a.w.client.messageMove.deleteMessages(
281
- a.w.account.accountConfigId,
282
- [a.copyId],
283
- a.w.account.accountId,
284
- { permanent: true },
285
- );
286
- await run(a);
287
- assert.deepEqual((await deleting).refusedMessageIds, []);
288
- const event = a.w.queued().find(isDelete);
289
- assert.ok(event, "the delete enqueued a MESSAGE_DELETE");
290
-
291
- await handleMessageDelete(event, a.w.log, 1, a.w.scope);
292
-
293
- assert.deepEqual(a.w.imap.uids("Projects", a.messageIdHeader), []);
294
- assert.deepEqual(a.w.imap.uids("INBOX"), [a.uid]);
295
- assert.equal(await a.w.row(a.copyId), undefined);
296
- assert.equal((await a.w.row(a.sourceMessageId))?.mailboxId, a.inboxId);
297
- });
298
- });