@remit/imap-worker 0.0.90 → 0.0.92

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 (176) 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 +22 -0
  76. package/dist/scheduler/calendar-subscriptions.js +35 -0
  77. package/dist/scheduler/config.d.ts +29 -0
  78. package/{src/scheduler/config.ts → dist/scheduler/config.js} +9 -28
  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/dist/scheduler/handler.js +50 -0
  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 +66 -0
  86. package/dist/scheduler/run-tick.js +164 -0
  87. package/dist/scheduler/runner.d.ts +2 -0
  88. package/dist/scheduler/runner.js +102 -0
  89. package/dist/scheduler/stranded-placement-redrive.d.ts +16 -0
  90. package/dist/scheduler/stranded-placement-redrive.js +172 -0
  91. package/dist/scheduler/tick.d.ts +5 -0
  92. package/dist/scheduler/tick.js +5 -0
  93. package/dist/sqs-queues.d.ts +4 -0
  94. package/dist/sqs-queues.js +22 -0
  95. package/dist/with-oauth-lifecycle-deps.d.ts +5 -0
  96. package/dist/with-oauth-lifecycle-deps.js +17 -0
  97. package/dist/with-oauth-lifecycle.d.ts +56 -0
  98. package/dist/with-oauth-lifecycle.js +92 -0
  99. package/{src/worker-version.ts → dist/worker-version.d.ts} +1 -2
  100. package/dist/worker-version.js +12 -0
  101. package/package.json +79 -69
  102. package/src/account-check.test.ts +0 -149
  103. package/src/account-check.ts +0 -101
  104. package/src/body-sync-gate.test.ts +0 -185
  105. package/src/body-sync-gate.ts +0 -86
  106. package/src/cli.ts +0 -218
  107. package/src/connection-scope.test.ts +0 -266
  108. package/src/connection-scope.ts +0 -314
  109. package/src/credential-less-sync-fence.test.ts +0 -152
  110. package/src/e2e-processor-shim.ts +0 -232
  111. package/src/emit.test.ts +0 -145
  112. package/src/emit.ts +0 -115
  113. package/src/events.ts +0 -252
  114. package/src/failure-kind.test.ts +0 -42
  115. package/src/handlers/append-sent-message.sqlite.test.ts +0 -176
  116. package/src/handlers/append-sent-message.ts +0 -264
  117. package/src/handlers/delete-account-objects.test.ts +0 -126
  118. package/src/handlers/delete-account-objects.ts +0 -96
  119. package/src/handlers/empty-trash.sqlite.test.ts +0 -209
  120. package/src/handlers/empty-trash.ts +0 -352
  121. package/src/handlers/flag-push.ts +0 -285
  122. package/src/handlers/imported-folder.test.ts +0 -63
  123. package/src/handlers/imported-folder.ts +0 -38
  124. package/src/handlers/mailbox-management.sqlite.test.ts +0 -265
  125. package/src/handlers/mailbox-management.ts +0 -486
  126. package/src/handlers/mailbox-sync-order.test.ts +0 -93
  127. package/src/handlers/mailbox-sync-order.ts +0 -65
  128. package/src/handlers/message-copy.sqlite.test.ts +0 -298
  129. package/src/handlers/message-copy.ts +0 -569
  130. package/src/handlers/message-delete-terminal.ts +0 -147
  131. package/src/handlers/message-delete.sqlite.test.ts +0 -291
  132. package/src/handlers/message-delete.ts +0 -888
  133. package/src/handlers/message-move.sqlite.test.ts +0 -271
  134. package/src/handlers/message-move.test.ts +0 -216
  135. package/src/handlers/message-move.ts +0 -755
  136. package/src/handlers/placement-move-push.test.ts +0 -137
  137. package/src/handlers/placement-move-push.ts +0 -478
  138. package/src/handlers/placement-push.sqlite.test.ts +0 -299
  139. package/src/handlers/probe-message-id.sqlite.test.ts +0 -192
  140. package/src/handlers/probe-message-id.ts +0 -15
  141. package/src/handlers/sync-mailboxes.test.ts +0 -183
  142. package/src/handlers/sync-mailboxes.ts +0 -425
  143. package/src/handlers/sync-message-body.sqlite.test.ts +0 -314
  144. package/src/handlers/sync-message-body.test.ts +0 -150
  145. package/src/handlers/sync-message-body.ts +0 -366
  146. package/src/handlers/sync-messages.sqlite.test.ts +0 -195
  147. package/src/handlers/sync-messages.ts +0 -537
  148. package/src/index.test.ts +0 -22
  149. package/src/index.ts +0 -82
  150. package/src/mail-sync-selection.sqlite.test.ts +0 -227
  151. package/src/mailbox-row.ts +0 -20
  152. package/src/pending-sync.sqlite.test.ts +0 -165
  153. package/src/poller.ts +0 -55
  154. package/src/processor.ts +0 -62
  155. package/src/queues.ts +0 -40
  156. package/src/scheduler/attachment-sweep.sqlite.test.ts +0 -74
  157. package/src/scheduler/attachment-sweep.ts +0 -46
  158. package/src/scheduler/calendar-subscriptions.sqlite.test.ts +0 -147
  159. package/src/scheduler/calendar-subscriptions.ts +0 -103
  160. package/src/scheduler/config.test.ts +0 -40
  161. package/src/scheduler/decide-due.test.ts +0 -44
  162. package/src/scheduler/half-deleted-accounts.sqlite.test.ts +0 -196
  163. package/src/scheduler/handler.ts +0 -69
  164. package/src/scheduler/loop.test.ts +0 -143
  165. package/src/scheduler/run-tick.sqlite.test.ts +0 -191
  166. package/src/scheduler/run-tick.ts +0 -281
  167. package/src/scheduler/runner.ts +0 -125
  168. package/src/scheduler/stranded-placement-redrive.ts +0 -265
  169. package/src/stranded-placement.sqlite.test.ts +0 -799
  170. package/src/test-helpers/test-world.ts +0 -425
  171. package/src/test-helpers/worker-queues.ts +0 -11
  172. package/src/thread-join.sqlite.test.ts +0 -106
  173. package/src/with-oauth-lifecycle-deps.sqlite.test.ts +0 -269
  174. package/src/with-oauth-lifecycle-deps.ts +0 -71
  175. package/src/with-oauth-lifecycle.ts +0 -158
  176. package/tsconfig.json +0 -8
@@ -1,38 +0,0 @@
1
- import type { CreateImportedFolder } from "@remit/config-transfer";
2
- import type { IMailboxRepository } from "@remit/data-ports";
3
- import type { MailboxQueueService } from "@remit/mailbox-service";
4
-
5
- export const createImportedFolder =
6
- (
7
- mailbox: Pick<IMailboxRepository, "findByPath">,
8
- queue: Pick<MailboxQueueService, "createMailbox">,
9
- ): CreateImportedFolder =>
10
- async (accountId, folderPath) => {
11
- const inbox = await mailbox.findByPath(accountId, "INBOX");
12
- if (!inbox) {
13
- throw new Error(
14
- `Account ${accountId} has no INBOX to take a namespace from, so "${folderPath}" cannot be created`,
15
- );
16
- }
17
- return queue.createMailbox(
18
- {
19
- accountId,
20
- namespaceType: inbox.namespaceType,
21
- namespacePrefix: inbox.namespacePrefix,
22
- hierarchyDelimiter: inbox.hierarchyDelimiter,
23
- fullPath: folderPath,
24
- uidValidity: 0,
25
- uidNext: 1,
26
- highestModseq: "0",
27
- messageCount: 0,
28
- unseenCount: 0,
29
- deletedCount: 0,
30
- totalSize: 0,
31
- lastSyncUid: 0,
32
- highWaterMarkUid: 0,
33
- lastMessageSyncAt: 0,
34
- },
35
- accountId,
36
- true,
37
- );
38
- };
@@ -1,265 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { after, before, describe, it } from "node:test";
3
- import type { MailboxItem } from "@remit/data-ports";
4
- import { MailboxSyncStatus } from "@remit/domain-enums";
5
- import { imapError } from "@remit/mailbox-service/test-helpers/fake-imap";
6
- import type { MailboxManagementEvent } from "../events.js";
7
- import { openStore, type World } from "../test-helpers/test-world.js";
8
- import { processMailboxManagement } from "./mailbox-management.js";
9
-
10
- let store: Awaited<ReturnType<typeof openStore>>;
11
-
12
- before(async () => {
13
- store = await openStore();
14
- });
15
-
16
- after(() => store.close());
17
-
18
- const lastEvent = (w: World, type: string): MailboxManagementEvent => {
19
- const event = w
20
- .queued()
21
- .filter((body) => body.type === type)
22
- .at(-1) as unknown as MailboxManagementEvent | undefined;
23
- assert.ok(event, `a ${type} was enqueued`);
24
- return event;
25
- };
26
-
27
- const run = (w: World, event: MailboxManagementEvent) =>
28
- processMailboxManagement(event, w.log, w.scope);
29
-
30
- const mailbox = (
31
- w: World,
32
- mailboxId: string,
33
- ): Promise<MailboxItem | undefined> =>
34
- w.client.mailbox
35
- .listAllByAccount(w.account.accountId)
36
- .then((rows) => rows.find((row) => row.mailboxId === mailboxId));
37
-
38
- /** A folder created through the service the API calls, not yet on the server. */
39
- const requestCreate = async (
40
- w: World,
41
- path: string,
42
- subscribe?: boolean,
43
- ): Promise<{ mailboxId: string; event: MailboxManagementEvent }> => {
44
- const created = await w.client.mailboxQueue.createMailbox(
45
- {
46
- accountId: w.account.accountId,
47
- namespacePrefix: "",
48
- hierarchyDelimiter: "/",
49
- fullPath: path,
50
- uidValidity: 0,
51
- uidNext: 0,
52
- highestModseq: "0",
53
- messageCount: 0,
54
- unseenCount: 0,
55
- deletedCount: 0,
56
- totalSize: 0,
57
- lastSyncUid: 0,
58
- highWaterMarkUid: 0,
59
- lastMessageSyncAt: 0,
60
- },
61
- w.account.accountId,
62
- subscribe,
63
- );
64
- assert.equal(created.outcome, "Created");
65
- if (created.outcome !== "Created") throw new Error("path taken");
66
- return {
67
- mailboxId: created.mailbox.mailboxId,
68
- event: lastEvent(w, "MAILBOX_CREATE"),
69
- };
70
- };
71
-
72
- describe("creating a folder", () => {
73
- it("creates it on the server and settles the row on the server's UIDVALIDITY", async () => {
74
- const w = await store.world();
75
- const { mailboxId, event } = await requestCreate(w, "Receipts");
76
-
77
- await run(w, event);
78
-
79
- assert.ok(w.imap.hasFolder("Receipts"));
80
- const row = await mailbox(w, mailboxId);
81
- assert.equal(row?.syncStatus, MailboxSyncStatus.synced);
82
- assert.equal(row?.uidValidity, w.imap.uidValidityOf("Receipts"));
83
- });
84
-
85
- it("subscribes only when the request asks for it", async () => {
86
- const w = await store.world();
87
- const quiet = await requestCreate(w, "Quiet");
88
- const loud = await requestCreate(w, "Loud", true);
89
-
90
- await run(w, quiet.event);
91
- await run(w, loud.event);
92
-
93
- assert.deepEqual(w.imap.commands("SUBSCRIBE"), ["SUBSCRIBE Loud"]);
94
- });
95
-
96
- it("settles a folder the server already has as created", async () => {
97
- const w = await store.world();
98
- const { mailboxId, event } = await requestCreate(w, "Receipts");
99
- w.imap.addFolder("Receipts", { uidValidity: 7 });
100
-
101
- await run(w, event);
102
-
103
- assert.equal(
104
- (await mailbox(w, mailboxId))?.syncStatus,
105
- MailboxSyncStatus.synced,
106
- );
107
- });
108
-
109
- it("marks the folder failed with the server's reason and acks a refused create", async () => {
110
- const w = await store.world();
111
- const { mailboxId, event } = await requestCreate(w, "Receipts");
112
- w.imap.failNext.CREATE = imapError("NOPERM", "Permission denied");
113
-
114
- await run(w, event);
115
-
116
- const row = await mailbox(w, mailboxId);
117
- assert.equal(row?.syncStatus, MailboxSyncStatus.failed);
118
- assert.equal(row?.syncFailureReason, "Permission denied");
119
- });
120
-
121
- it("marks the folder failed and redelivers when the create fails for another reason", async () => {
122
- const w = await store.world();
123
- const { mailboxId, event } = await requestCreate(w, "Receipts");
124
- w.imap.failNext.CREATE = new Error("Connection reset");
125
-
126
- await assert.rejects(run(w, event), /Connection reset/);
127
-
128
- assert.equal(
129
- (await mailbox(w, mailboxId))?.syncStatus,
130
- MailboxSyncStatus.failed,
131
- );
132
- });
133
-
134
- it("acks when the folder row was deleted before the create ran", async () => {
135
- const w = await store.world();
136
- const { mailboxId, event } = await requestCreate(w, "Receipts");
137
- await w.client.mailbox.delete(w.account.accountId, mailboxId);
138
-
139
- await run(w, event);
140
- });
141
- });
142
-
143
- describe("renaming a folder", () => {
144
- const arrange = async () => {
145
- const w = await store.world();
146
- const work = await w.folder("Work");
147
- const child = await w.folder("Work/Clients");
148
- const message = await w.message(child);
149
- await w.client.mailboxQueue.renameMailbox(
150
- work.mailboxId,
151
- "Projects",
152
- w.account.accountId,
153
- );
154
- return { w, work, child, message, event: lastEvent(w, "MAILBOX_RENAME") };
155
- };
156
-
157
- it("renames on the server and settles the folder and its children onto the new path", async () => {
158
- const { w, work, child, event } = await arrange();
159
-
160
- await run(w, event);
161
-
162
- assert.ok(w.imap.hasFolder("Projects/Clients"));
163
- assert.equal((await mailbox(w, work.mailboxId))?.fullPath, "Projects");
164
- const settledChild = await mailbox(w, child.mailboxId);
165
- assert.equal(settledChild?.fullPath, "Projects/Clients");
166
- assert.equal(settledChild?.syncStatus, MailboxSyncStatus.synced);
167
- });
168
-
169
- it("removes the folder, its children and their mail when the source is gone on the server", async () => {
170
- const { w, work, child, message, event } = await arrange();
171
- w.imap.removeFolder("Work");
172
- w.imap.removeFolder("Work/Clients");
173
-
174
- await run(w, event);
175
-
176
- assert.equal(await mailbox(w, work.mailboxId), undefined);
177
- assert.equal(await mailbox(w, child.mailboxId), undefined);
178
- assert.equal(await w.row(message.messageId), undefined);
179
- });
180
-
181
- it("keeps the confirmed path and acks a refused rename", async () => {
182
- const { w, work, event } = await arrange();
183
- w.imap.failNext.RENAME = imapError("NOPERM", "Permission denied");
184
-
185
- await run(w, event);
186
-
187
- const row = await mailbox(w, work.mailboxId);
188
- assert.equal(row?.fullPath, "Work");
189
- assert.equal(row?.syncStatus, MailboxSyncStatus.failed);
190
- assert.ok(w.imap.hasFolder("Work"));
191
- });
192
-
193
- it("issues no RENAME when a redelivery finds the rename already settled", async () => {
194
- const { w, event } = await arrange();
195
- await run(w, event);
196
-
197
- await run(w, event);
198
-
199
- assert.equal(w.imap.commands("RENAME").length, 1);
200
- });
201
- });
202
-
203
- describe("deleting a folder", () => {
204
- const arrange = async () => {
205
- const w = await store.world();
206
- const old = await w.folder("Old");
207
- const message = await w.message(old);
208
- await w.client.mailboxQueue.deleteMailbox(
209
- old.mailboxId,
210
- w.account.accountId,
211
- );
212
- return { w, old, message, event: lastEvent(w, "MAILBOX_DELETE") };
213
- };
214
-
215
- it("deletes it on the server and removes the folder and its mail", async () => {
216
- const { w, old, message, event } = await arrange();
217
-
218
- await run(w, event);
219
-
220
- assert.equal(w.imap.hasFolder("Old"), false);
221
- assert.equal(await mailbox(w, old.mailboxId), undefined);
222
- assert.equal(await w.row(message.messageId), undefined);
223
- });
224
-
225
- it("removes the folder and its mail when the server no longer has it", async () => {
226
- const { w, old, message, event } = await arrange();
227
- w.imap.removeFolder("Old");
228
-
229
- await run(w, event);
230
-
231
- assert.equal(await mailbox(w, old.mailboxId), undefined);
232
- assert.equal(await w.row(message.messageId), undefined);
233
- });
234
-
235
- it("marks the folder failed, keeps its mail and acks a refused delete", async () => {
236
- const { w, old, message, event } = await arrange();
237
- w.imap.failNext.DELETE = imapError("NOPERM", "Permission denied");
238
-
239
- await run(w, event);
240
-
241
- assert.equal(
242
- (await mailbox(w, old.mailboxId))?.syncStatus,
243
- MailboxSyncStatus.failed,
244
- );
245
- assert.ok(await w.row(message.messageId));
246
- assert.ok(w.imap.hasFolder("Old"));
247
- });
248
-
249
- it("issues no DELETE for a folder that is not being deleted", async () => {
250
- const w = await store.world();
251
- const kept = await w.folder("Kept");
252
-
253
- await run(w, {
254
- type: "MAILBOX_DELETE",
255
- eventId: "evt-stale",
256
- timestamp: Date.now(),
257
- accountId: w.account.accountId,
258
- mailboxId: kept.mailboxId,
259
- path: "Kept",
260
- } as MailboxManagementEvent);
261
-
262
- assert.deepEqual(w.imap.commands("DELETE"), []);
263
- assert.ok(await mailbox(w, kept.mailboxId));
264
- });
265
- });