@remit/backend 0.0.142 → 0.0.144

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 (269) hide show
  1. package/dist/dev-server/content-handler.d.ts +38 -0
  2. package/dist/dev-server/content-handler.js +46 -0
  3. package/dist/src/api.d.ts +7 -0
  4. package/dist/src/api.js +144 -0
  5. package/dist/src/auth.d.ts +30 -0
  6. package/dist/src/auth.js +73 -0
  7. package/dist/src/config/msoauth.d.ts +30 -0
  8. package/dist/src/config/msoauth.js +30 -0
  9. package/{src/data-backend.ts → dist/src/data-backend.d.ts} +2 -4
  10. package/dist/src/data-backend.js +12 -0
  11. package/{src/derive/autoMoved.ts → dist/src/derive/autoMoved.d.ts} +1 -29
  12. package/dist/src/derive/autoMoved.js +49 -0
  13. package/dist/src/derive/contentSignature.d.ts +41 -0
  14. package/{src/derive/contentSignature.ts → dist/src/derive/contentSignature.js} +27 -72
  15. package/dist/src/derive/contentUrl.d.ts +46 -0
  16. package/dist/src/derive/contentUrl.js +46 -0
  17. package/{src/derive/deriveMuted.ts → dist/src/derive/deriveMuted.d.ts} +1 -3
  18. package/dist/src/derive/deriveMuted.js +7 -0
  19. package/dist/src/derive/enrichThreadRows.d.ts +118 -0
  20. package/dist/src/derive/enrichThreadRows.js +151 -0
  21. package/dist/src/derive/filterThreadCriteria.d.ts +23 -0
  22. package/dist/src/derive/filterThreadCriteria.js +24 -0
  23. package/{src/derive/pendingMoveCounts.ts → dist/src/derive/pendingMoveCounts.d.ts} +5 -53
  24. package/dist/src/derive/pendingMoveCounts.js +53 -0
  25. package/{src/derive/senderTrust.ts → dist/src/derive/senderTrust.d.ts} +1 -9
  26. package/dist/src/derive/senderTrust.js +19 -0
  27. package/dist/src/error.d.ts +21 -0
  28. package/dist/src/error.js +85 -0
  29. package/dist/src/handlers/account-guards.d.ts +36 -0
  30. package/dist/src/handlers/account-guards.js +107 -0
  31. package/dist/src/handlers/account-oauth.d.ts +14 -0
  32. package/dist/src/handlers/account-oauth.js +387 -0
  33. package/dist/src/handlers/account-overrides.d.ts +53 -0
  34. package/dist/src/handlers/account-overrides.js +233 -0
  35. package/dist/src/handlers/account-signature.d.ts +28 -0
  36. package/dist/src/handlers/account-signature.js +85 -0
  37. package/dist/src/handlers/account.d.ts +6 -0
  38. package/dist/src/handlers/account.js +350 -0
  39. package/dist/src/handlers/address.d.ts +35 -0
  40. package/dist/src/handlers/address.js +141 -0
  41. package/dist/src/handlers/calendar-event.d.ts +70 -0
  42. package/dist/src/handlers/calendar-event.js +425 -0
  43. package/dist/src/handlers/calendar-feed.d.ts +47 -0
  44. package/dist/src/handlers/calendar-feed.js +192 -0
  45. package/dist/src/handlers/calendar-suggestion.d.ts +47 -0
  46. package/dist/src/handlers/calendar-suggestion.js +212 -0
  47. package/dist/src/handlers/calendar.d.ts +116 -0
  48. package/dist/src/handlers/calendar.js +330 -0
  49. package/dist/src/handlers/config.d.ts +43 -0
  50. package/dist/src/handlers/config.js +176 -0
  51. package/dist/src/handlers/ensure-account-config.d.ts +9 -0
  52. package/dist/src/handlers/ensure-account-config.js +27 -0
  53. package/dist/src/handlers/filter.d.ts +3 -0
  54. package/dist/src/handlers/filter.js +103 -0
  55. package/dist/src/handlers/folder-role-appointments.d.ts +68 -0
  56. package/dist/src/handlers/folder-role-appointments.js +168 -0
  57. package/dist/src/handlers/folder-role-labels.d.ts +26 -0
  58. package/dist/src/handlers/folder-role-labels.js +40 -0
  59. package/dist/src/handlers/folder-role.d.ts +9 -0
  60. package/dist/src/handlers/folder-role.js +40 -0
  61. package/dist/src/handlers/index.d.ts +2 -0
  62. package/dist/src/handlers/index.js +60 -0
  63. package/dist/src/handlers/label.d.ts +43 -0
  64. package/dist/src/handlers/label.js +114 -0
  65. package/dist/src/handlers/mailbox-bindings.d.ts +41 -0
  66. package/dist/src/handlers/mailbox-bindings.js +61 -0
  67. package/dist/src/handlers/mailbox.d.ts +23 -0
  68. package/dist/src/handlers/mailbox.js +219 -0
  69. package/dist/src/handlers/me.d.ts +2 -0
  70. package/dist/src/handlers/me.js +138 -0
  71. package/dist/src/handlers/message.d.ts +84 -0
  72. package/dist/src/handlers/message.js +607 -0
  73. package/dist/src/handlers/organize.d.ts +10 -0
  74. package/dist/src/handlers/organize.js +112 -0
  75. package/dist/src/handlers/outbox-attachment.d.ts +23 -0
  76. package/dist/src/handlers/outbox-attachment.js +81 -0
  77. package/dist/src/handlers/outbox.d.ts +4 -0
  78. package/dist/src/handlers/outbox.js +144 -0
  79. package/dist/src/handlers/sync-progress.d.ts +46 -0
  80. package/dist/src/handlers/sync-progress.js +63 -0
  81. package/dist/src/handlers/sync.d.ts +28 -0
  82. package/dist/src/handlers/sync.js +82 -0
  83. package/dist/src/handlers/system-update.d.ts +2 -0
  84. package/dist/src/handlers/system-update.js +172 -0
  85. package/dist/src/handlers/thread.d.ts +148 -0
  86. package/dist/src/handlers/thread.js +233 -0
  87. package/dist/src/handlers/unified-threads.d.ts +247 -0
  88. package/dist/src/handlers/unified-threads.js +409 -0
  89. package/{src/handlers/vip-suggestions.ts → dist/src/handlers/vip-suggestions.d.ts} +1 -13
  90. package/dist/src/handlers/vip-suggestions.js +16 -0
  91. package/dist/src/index.d.ts +2 -0
  92. package/dist/src/index.js +37 -0
  93. package/{src/json.ts → dist/src/json.d.ts} +1 -4
  94. package/dist/src/json.js +10 -0
  95. package/dist/src/jwt-auth.d.ts +18 -0
  96. package/dist/src/jwt-auth.js +97 -0
  97. package/dist/src/request-context.d.ts +9 -0
  98. package/dist/src/request-context.js +22 -0
  99. package/dist/src/request.d.ts +3 -0
  100. package/dist/src/request.js +7 -0
  101. package/dist/src/response.d.ts +27 -0
  102. package/dist/src/response.js +87 -0
  103. package/dist/src/service/account-deletion.d.ts +22 -0
  104. package/dist/src/service/account-deletion.js +39 -0
  105. package/dist/src/service/compose-sqlite.d.ts +2 -0
  106. package/dist/src/service/compose-sqlite.js +11 -0
  107. package/dist/src/service/create-remit-client.d.ts +95 -0
  108. package/dist/src/service/create-remit-client.js +207 -0
  109. package/dist/src/service/data-client.d.ts +12 -0
  110. package/dist/src/service/data-client.js +44 -0
  111. package/dist/src/service/export-identity.d.ts +3 -0
  112. package/dist/src/service/export-identity.js +35 -0
  113. package/dist/src/service/fire-and-forget.d.ts +54 -0
  114. package/dist/src/service/fire-and-forget.js +38 -0
  115. package/dist/src/service/organize.d.ts +184 -0
  116. package/dist/src/service/organize.js +384 -0
  117. package/dist/src/service/refusal.d.ts +4 -0
  118. package/dist/src/service/refusal.js +20 -0
  119. package/dist/src/service/sender-category.d.ts +51 -0
  120. package/{src/service/sender-category.ts → dist/src/service/sender-category.js} +40 -81
  121. package/dist/src/service/sqs.d.ts +1 -0
  122. package/{src/service/sqs.ts → dist/src/service/sqs.js} +0 -1
  123. package/dist/src/service/trigger-sync.d.ts +51 -0
  124. package/dist/src/service/trigger-sync.js +39 -0
  125. package/dist/src/types.d.ts +49 -0
  126. package/dist/src/types.js +1 -0
  127. package/package.json +113 -98
  128. package/.env.test +0 -4
  129. package/dev-server/content-auth.test.ts +0 -113
  130. package/dev-server/content-auth.ts +0 -54
  131. package/dev-server/content-handler.test.ts +0 -105
  132. package/dev-server/content-handler.ts +0 -79
  133. package/dev-server/content-path.test.ts +0 -37
  134. package/dev-server/content-path.ts +0 -27
  135. package/dev-server/cors.test.ts +0 -48
  136. package/dev-server/cors.ts +0 -25
  137. package/dev-server/keep-alive.test.ts +0 -24
  138. package/dev-server/lambda-helpers.ts +0 -69
  139. package/dev-server/log-output.test.ts +0 -173
  140. package/dev-server/oauth-callback-route.test.ts +0 -66
  141. package/dev-server/relational-health.test.ts +0 -83
  142. package/dev-server/relational-health.ts +0 -39
  143. package/dev-server/server.ts +0 -384
  144. package/dev-server/sync-age.test.ts +0 -91
  145. package/dev-server/sync-age.ts +0 -55
  146. package/dev-server/upload-handler.ts +0 -132
  147. package/dev-server/upload-route.test.ts +0 -196
  148. package/scripts/backfill-classification.ts +0 -91
  149. package/scripts/backfill-list-id.ts +0 -83
  150. package/scripts/config-save.ts +0 -128
  151. package/src/auth.test.ts +0 -12
  152. package/src/auth.ts +0 -92
  153. package/src/config/msoauth.test.ts +0 -48
  154. package/src/config/msoauth.ts +0 -48
  155. package/src/data-backend.test.ts +0 -23
  156. package/src/derive/autoMoved.test.ts +0 -104
  157. package/src/derive/contentSignature.test.ts +0 -161
  158. package/src/derive/contentUrl.test.ts +0 -172
  159. package/src/derive/contentUrl.ts +0 -86
  160. package/src/derive/deriveMuted.test.ts +0 -34
  161. package/src/derive/enrichThreadRows.test.ts +0 -360
  162. package/src/derive/enrichThreadRows.ts +0 -234
  163. package/src/derive/filterThreadCriteria.test.ts +0 -126
  164. package/src/derive/filterThreadCriteria.ts +0 -51
  165. package/src/derive/senderTrust.test.ts +0 -67
  166. package/src/error.test.ts +0 -201
  167. package/src/error.ts +0 -123
  168. package/src/handlers/account-guards.test.ts +0 -67
  169. package/src/handlers/account-guards.ts +0 -169
  170. package/src/handlers/account-oauth-callback.test.ts +0 -155
  171. package/src/handlers/account-oauth-consent.test.ts +0 -336
  172. package/src/handlers/account-oauth-start.test.ts +0 -191
  173. package/src/handlers/account-oauth.test.ts +0 -439
  174. package/src/handlers/account-oauth.ts +0 -635
  175. package/src/handlers/account-overrides.test.ts +0 -88
  176. package/src/handlers/account-overrides.ts +0 -323
  177. package/src/handlers/account-ownership.ts +0 -25
  178. package/src/handlers/account-signature.ts +0 -117
  179. package/src/handlers/account-synced-services.test.ts +0 -245
  180. package/src/handlers/account.ts +0 -552
  181. package/src/handlers/address.test.ts +0 -381
  182. package/src/handlers/address.ts +0 -200
  183. package/src/handlers/calendar-event.test.ts +0 -685
  184. package/src/handlers/calendar-event.ts +0 -738
  185. package/src/handlers/calendar-feed-validators.test.ts +0 -228
  186. package/src/handlers/calendar-feed.test.ts +0 -439
  187. package/src/handlers/calendar-feed.ts +0 -291
  188. package/src/handlers/calendar-sqlite-fixture.ts +0 -36
  189. package/src/handlers/calendar-suggestion.test.ts +0 -1269
  190. package/src/handlers/calendar-suggestion.ts +0 -425
  191. package/src/handlers/calendar.test.ts +0 -1080
  192. package/src/handlers/calendar.ts +0 -517
  193. package/src/handlers/config.test.ts +0 -245
  194. package/src/handlers/config.ts +0 -332
  195. package/src/handlers/ensure-account-config.ts +0 -30
  196. package/src/handlers/filter.test.ts +0 -644
  197. package/src/handlers/filter.ts +0 -518
  198. package/src/handlers/folder-role-appointments.test.ts +0 -438
  199. package/src/handlers/folder-role-appointments.ts +0 -249
  200. package/src/handlers/folder-role-labels.ts +0 -63
  201. package/src/handlers/folder-role.test.ts +0 -209
  202. package/src/handlers/folder-role.ts +0 -80
  203. package/src/handlers/index.ts +0 -83
  204. package/src/handlers/label.test.ts +0 -112
  205. package/src/handlers/label.ts +0 -210
  206. package/src/handlers/mailbox-bindings.ts +0 -111
  207. package/src/handlers/mailbox-rename-refusal.test.ts +0 -247
  208. package/src/handlers/mailbox-settled-target.test.ts +0 -251
  209. package/src/handlers/mailbox.test.ts +0 -280
  210. package/src/handlers/mailbox.ts +0 -581
  211. package/src/handlers/me.test.ts +0 -81
  212. package/src/handlers/me.ts +0 -203
  213. package/src/handlers/message-read-backfill.test.ts +0 -103
  214. package/src/handlers/message.test.ts +0 -131
  215. package/src/handlers/message.ts +0 -1131
  216. package/src/handlers/organize.test.ts +0 -277
  217. package/src/handlers/organize.ts +0 -197
  218. package/src/handlers/outbox-attachment.test.ts +0 -765
  219. package/src/handlers/outbox-attachment.ts +0 -126
  220. package/src/handlers/outbox-list.test.ts +0 -179
  221. package/src/handlers/outbox.test.ts +0 -772
  222. package/src/handlers/outbox.ts +0 -258
  223. package/src/handlers/search.test.ts +0 -161
  224. package/src/handlers/search.ts +0 -105
  225. package/src/handlers/sync-progress.test.ts +0 -205
  226. package/src/handlers/sync-progress.ts +0 -99
  227. package/src/handlers/sync.test.ts +0 -168
  228. package/src/handlers/sync.ts +0 -118
  229. package/src/handlers/system-update.test.ts +0 -497
  230. package/src/handlers/system-update.ts +0 -230
  231. package/src/handlers/thread.test.ts +0 -396
  232. package/src/handlers/thread.ts +0 -427
  233. package/src/handlers/unified-threads-mail-sources.sqlite.test.ts +0 -197
  234. package/src/handlers/unified-threads.test.ts +0 -785
  235. package/src/handlers/unified-threads.ts +0 -669
  236. package/src/index.test.ts +0 -83
  237. package/src/index.ts +0 -228
  238. package/src/jwt-auth.test.ts +0 -152
  239. package/src/jwt-auth.ts +0 -132
  240. package/src/log-redaction.test.ts +0 -144
  241. package/src/openapi-spec.test.ts +0 -118
  242. package/src/request-context.test.ts +0 -61
  243. package/src/request-context.ts +0 -33
  244. package/src/request-pipeline.test.ts +0 -88
  245. package/src/request.ts +0 -10
  246. package/src/response.test.ts +0 -130
  247. package/src/response.ts +0 -144
  248. package/src/service/compose-sqlite.ts +0 -98
  249. package/src/service/config-import.ts +0 -39
  250. package/src/service/create-remit-client.ts +0 -521
  251. package/src/service/data-client.test.ts +0 -97
  252. package/src/service/data-client.ts +0 -58
  253. package/src/service/export-identity.ts +0 -39
  254. package/src/service/filter.ts +0 -40
  255. package/src/service/fire-and-forget.test.ts +0 -126
  256. package/src/service/fire-and-forget.ts +0 -79
  257. package/src/service/localhost-env-config.test.ts +0 -36
  258. package/src/service/organize-queue.ts +0 -98
  259. package/src/service/organize.test.ts +0 -1451
  260. package/src/service/organize.ts +0 -1025
  261. package/src/service/read-path-filter-config.test.ts +0 -243
  262. package/src/service/semantic-capability.test.ts +0 -78
  263. package/src/service/semantic-capability.ts +0 -95
  264. package/src/service/sender-category.test.ts +0 -235
  265. package/src/service/trigger-sync.test.ts +0 -205
  266. package/src/service/trigger-sync.ts +0 -100
  267. package/src/stdout-capture-fixture.ts +0 -40
  268. package/src/types.ts +0 -271
  269. package/tsconfig.json +0 -7
@@ -1,251 +0,0 @@
1
- /**
2
- * Every API write that binds a durable reference to a folder requires that
3
- * folder to be settled (D12, first row; imap-mutations R2: wait). Driven
4
- * through the real handlers rather than the helper, because the claim is that
5
- * each call site is wired to it — a helper that nothing calls refuses nothing.
6
- *
7
- * The other half of the same invariant is the delete refusal (D16), in
8
- * `mailbox.test.ts`: a binding is only created against a settled folder and
9
- * only removed by the user, so a `mailboxId` that names nothing never exists.
10
- */
11
- import assert from "node:assert/strict";
12
- import { afterEach, describe, it, mock } from "node:test";
13
- import type { MailboxItem } from "@remit/data-ports";
14
- import { CanonicalMailboxRole, MailboxSyncStatus } from "@remit/domain-enums";
15
- import type { APIGatewayProxyEvent } from "aws-lambda";
16
- import type { Context } from "openapi-backend";
17
- import { deriveAccountConfigId } from "../auth.js";
18
- import {
19
- _resetForTest,
20
- type RemitClient,
21
- setClient,
22
- } from "../service/data-client.js";
23
- import { sqsClient } from "../service/sqs.js";
24
- import { FilterDetailOperations, FilterOperations } from "./filter.js";
25
- import { FolderRoleOperations } from "./folder-role.js";
26
- import { MessageBulkOperations } from "./message.js";
27
-
28
- const SUB = "cognito-sub-365";
29
- const ACCOUNT_ID = "acc-365";
30
- const CONFIG_ID = deriveAccountConfigId(SUB);
31
- const TARGET = "mbx-target";
32
-
33
- const target = (syncStatus: MailboxItem["syncStatus"]): MailboxItem =>
34
- ({
35
- mailboxId: TARGET,
36
- accountId: ACCOUNT_ID,
37
- fullPath: "Receipts",
38
- hierarchyDelimiter: "/",
39
- syncStatus,
40
- }) as MailboxItem;
41
-
42
- interface Writes {
43
- filters: unknown[];
44
- filterPatches: unknown[];
45
- appointments: unknown[];
46
- moves: unknown[];
47
- copies: unknown[];
48
- }
49
-
50
- const world = (syncStatus: MailboxItem["syncStatus"]): Writes => {
51
- const writes: Writes = {
52
- filters: [],
53
- filterPatches: [],
54
- appointments: [],
55
- moves: [],
56
- copies: [],
57
- };
58
- const row = target(syncStatus);
59
- process.env.SQS_QUEUE_URL_ACCOUNT_FANOUT =
60
- "http://localhost:9324/queue/account-fanout-test";
61
- mock.method(sqsClient, "send", async () => ({}));
62
-
63
- setClient({
64
- account: {
65
- get: async () => ({ accountId: ACCOUNT_ID, accountConfigId: CONFIG_ID }),
66
- listAllByAccountConfig: async () => [{ accountId: ACCOUNT_ID }],
67
- },
68
- mailbox: {
69
- get: async (_accountId: string, mailboxId: string | string[]) =>
70
- Array.isArray(mailboxId)
71
- ? mailboxId.map((id) => ({ mailboxId: id, accountId: ACCOUNT_ID }))
72
- : row,
73
- listAllByAccount: async () => [row],
74
- },
75
- message: {
76
- get: async () => ({ mailboxId: "mbx-source" }),
77
- },
78
- filter: {
79
- get: async () => ({ filterId: "flt-1", scope: "Standing" }),
80
- update: async (...args: unknown[]) => {
81
- writes.filterPatches.push(args);
82
- return { filterId: "flt-1" };
83
- },
84
- listByAccountConfig: async () => [],
85
- },
86
- filterAnchorTransaction: {
87
- createWithAnchor: async (input: unknown) => {
88
- writes.filters.push(input);
89
- return { filterId: "flt-1" };
90
- },
91
- },
92
- organizeJobRequest: {
93
- create: async (input: Record<string, unknown>) => ({
94
- ...input,
95
- organizeJobId: "job-1",
96
- state: "Pending",
97
- }),
98
- },
99
- accountSetting: {
100
- get: async () => null,
101
- upsert: async (item: unknown) => {
102
- writes.appointments.push(item);
103
- return item;
104
- },
105
- delete: async () => undefined,
106
- },
107
- messageMove: {
108
- moveMessages: async (...args: unknown[]) => {
109
- writes.moves.push(args);
110
- },
111
- copyMessages: async (...args: unknown[]) => {
112
- writes.copies.push(args);
113
- },
114
- },
115
- } as unknown as RemitClient);
116
-
117
- return writes;
118
- };
119
-
120
- const event = {
121
- requestContext: { authorizer: { claims: { sub: SUB } } },
122
- } as unknown as APIGatewayProxyEvent;
123
-
124
- const call = <T>(
125
- handler: unknown,
126
- request: Record<string, unknown>,
127
- ): Promise<T> =>
128
- (handler as (context: Context, event: APIGatewayProxyEvent) => Promise<T>)(
129
- { request } as unknown as Context,
130
- event,
131
- );
132
-
133
- const appoint = () =>
134
- call(FolderRoleOperations.FolderRoleOperations_appointFolderRole, {
135
- params: { accountId: ACCOUNT_ID, role: CanonicalMailboxRole.Archive },
136
- requestBody: { mailboxId: TARGET },
137
- });
138
-
139
- const createFilter = () =>
140
- call(FilterOperations.FilterOperations_createFilter, {
141
- params: { accountId: ACCOUNT_ID },
142
- requestBody: {
143
- name: "Invoices",
144
- scope: "Standing",
145
- actionMailboxId: TARGET,
146
- },
147
- });
148
-
149
- const updateFilter = () =>
150
- call(FilterDetailOperations.FilterDetailOperations_updateFilter, {
151
- params: { accountId: ACCOUNT_ID, filterId: "flt-1" },
152
- requestBody: { actionMailboxId: TARGET },
153
- });
154
-
155
- const moveMessages = () =>
156
- call(MessageBulkOperations.MessageBulkOperations_moveMessages, {
157
- params: {},
158
- requestBody: { messageIds: ["msg-1"], destinationMailboxId: TARGET },
159
- });
160
-
161
- const copyMessages = () =>
162
- call(MessageBulkOperations.MessageBulkOperations_copyMessages, {
163
- params: {},
164
- requestBody: { messageIds: ["msg-1"], destinationMailboxId: TARGET },
165
- });
166
-
167
- const unready = (error: unknown): boolean =>
168
- (error as { statusCode?: number }).statusCode === 422 &&
169
- (error as { publicApiError?: { code?: string } }).publicApiError?.code ===
170
- "mailbox_not_settled";
171
-
172
- const SITES = [
173
- ["appointing a role", appoint, (w: Writes) => w.appointments],
174
- ["creating a filter", createFilter, (w: Writes) => w.filters],
175
- ["updating a filter", updateFilter, (w: Writes) => w.filterPatches],
176
- ["moving messages", moveMessages, (w: Writes) => w.moves],
177
- ["copying messages", copyMessages, (w: Writes) => w.copies],
178
- ] as const;
179
-
180
- describe("a write that binds to a folder requires a settled folder", () => {
181
- afterEach(() => {
182
- mock.restoreAll();
183
- _resetForTest();
184
- });
185
-
186
- for (const [what, run, written] of SITES) {
187
- for (const state of [
188
- MailboxSyncStatus.pending,
189
- MailboxSyncStatus.deleting,
190
- MailboxSyncStatus.failed,
191
- ]) {
192
- it(`refuses ${what} against a ${state} folder, writing nothing`, async () => {
193
- const writes = world(state);
194
-
195
- await assert.rejects(run(), unready);
196
- assert.deepEqual(written(writes), []);
197
- });
198
- }
199
-
200
- it(`accepts ${what} against a settled folder`, async () => {
201
- const writes = world(MailboxSyncStatus.synced);
202
-
203
- await run();
204
- assert.equal(written(writes).length > 0, true);
205
- });
206
- }
207
-
208
- it("never answers 409 from these paths", async () => {
209
- // 409 belongs to the folder's own mutation losing a compare-and-set
210
- // (#362, #363). Reusing it here would make "somebody else is changing this
211
- // folder" and "the folder you are pointing at is not ready" the same
212
- // answer, with different copy and different remedies behind it.
213
- world(MailboxSyncStatus.pending);
214
-
215
- await assert.rejects(
216
- appoint(),
217
- (error: unknown) => (error as { statusCode?: number }).statusCode !== 409,
218
- );
219
- });
220
-
221
- it("does not gate clearing a role whose folder is on its way out", async () => {
222
- const writes = world(MailboxSyncStatus.deleting);
223
-
224
- await call(FolderRoleOperations.FolderRoleOperations_appointFolderRole, {
225
- params: { accountId: ACCOUNT_ID, role: CanonicalMailboxRole.Archive },
226
- requestBody: { mailboxId: null },
227
- });
228
-
229
- assert.deepEqual(
230
- writes.appointments,
231
- [],
232
- "the row is deleted, not upserted",
233
- );
234
- });
235
-
236
- it("does not gate a filter that applies no move action", async () => {
237
- // `None` is the sentinel for "no move action", so it binds to nothing.
238
- const writes = world(MailboxSyncStatus.deleting);
239
-
240
- await call(FilterOperations.FilterOperations_createFilter, {
241
- params: { accountId: ACCOUNT_ID },
242
- requestBody: {
243
- name: "Just a label",
244
- scope: "Standing",
245
- actionMailboxId: "None",
246
- },
247
- });
248
-
249
- assert.equal(writes.filters.length, 1);
250
- });
251
- });
@@ -1,280 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { afterEach, describe, it } from "node:test";
3
- import type { MailboxItem } from "@remit/data-ports";
4
- import { BadRequestError } from "@remit/data-ports/errors";
5
- import { MailboxSyncStatus } from "@remit/domain-enums";
6
- import { UnconfirmedTrashMailboxError } from "@remit/mailbox-service";
7
- import type { APIGatewayProxyEvent } from "aws-lambda";
8
- import type { Context } from "openapi-backend";
9
- import { deriveAccountConfigId } from "../auth.js";
10
- import {
11
- _resetForTest,
12
- type RemitClient,
13
- setClient,
14
- } from "../service/data-client.js";
15
- import {
16
- MailboxDetailOperations,
17
- MailboxOperations,
18
- TrashOperations,
19
- } from "./mailbox.js";
20
-
21
- const SUB = "cognito-sub-887";
22
- const ACCOUNT_ID = "acc-887";
23
-
24
- const emptyTrash = TrashOperations.TrashOperations_emptyTrash as unknown as (
25
- context: Context,
26
- event: APIGatewayProxyEvent,
27
- ) => Promise<{ deletedCount: number }>;
28
-
29
- const callEmptyTrash = (
30
- serviceEmptyTrash: () => Promise<{ deletedCount: number }>,
31
- ): Promise<{ deletedCount: number }> => {
32
- setClient({
33
- account: {
34
- get: async () => ({
35
- accountId: ACCOUNT_ID,
36
- accountConfigId: deriveAccountConfigId(SUB),
37
- }),
38
- },
39
- messageMove: { emptyTrash: serviceEmptyTrash },
40
- } as unknown as RemitClient);
41
-
42
- return emptyTrash(
43
- { request: { params: { accountId: ACCOUNT_ID } } } as unknown as Context,
44
- {
45
- requestContext: { authorizer: { claims: { sub: SUB } } },
46
- } as unknown as APIGatewayProxyEvent,
47
- );
48
- };
49
-
50
- describe("TrashOperations_emptyTrash", () => {
51
- afterEach(() => {
52
- _resetForTest();
53
- });
54
-
55
- it("reports the service's count rather than one of its own", async () => {
56
- // The handler resolves no folder and counts no rows: a second read would
57
- // be free to disagree with the one that actually marked them.
58
- const response = await callEmptyTrash(async () => ({ deletedCount: 7 }));
59
-
60
- assert.deepEqual(response, { deletedCount: 7 });
61
- });
62
-
63
- it("lets the service's coded refusal through untouched", async () => {
64
- await assert.rejects(
65
- callEmptyTrash(async () => {
66
- throw new UnconfirmedTrashMailboxError(ACCOUNT_ID);
67
- }),
68
- (error: unknown) =>
69
- error instanceof UnconfirmedTrashMailboxError &&
70
- error.statusCode === 409 &&
71
- error.publicApiError?.details?.reason === "unconfirmed",
72
- );
73
- });
74
- });
75
-
76
- const deleteMailbox =
77
- MailboxDetailOperations.MailboxDetailOperations_deleteMailbox as unknown as (
78
- context: Context,
79
- event: APIGatewayProxyEvent,
80
- ) => Promise<{ statusCode: number }>;
81
-
82
- const folder = (over: Partial<MailboxItem> = {}): MailboxItem =>
83
- ({
84
- mailboxId: "mbx-1",
85
- accountId: ACCOUNT_ID,
86
- fullPath: "Receipts",
87
- hierarchyDelimiter: "/",
88
- syncStatus: MailboxSyncStatus.synced,
89
- ...over,
90
- }) as MailboxItem;
91
-
92
- interface DeleteWorld {
93
- mailbox?: MailboxItem;
94
- children?: MailboxItem[];
95
- filters?: { name: string; actionMailboxId: string }[];
96
- appointments?: Record<string, string>;
97
- }
98
-
99
- const callDelete = (
100
- world: DeleteWorld,
101
- ): { run: () => Promise<{ statusCode: number }>; deleted: string[] } => {
102
- const deleted: string[] = [];
103
- setClient({
104
- account: {
105
- get: async () => ({
106
- accountId: ACCOUNT_ID,
107
- accountConfigId: deriveAccountConfigId(SUB),
108
- }),
109
- },
110
- mailbox: {
111
- get: async () => world.mailbox ?? folder(),
112
- findByPathPrefix: async () => world.children ?? [],
113
- },
114
- filter: {
115
- listByAccountConfig: async () => world.filters ?? [],
116
- },
117
- accountSetting: {
118
- get: async (_configId: string, name: string) => {
119
- for (const [role, mailboxId] of Object.entries(
120
- world.appointments ?? {},
121
- )) {
122
- if (name === `FolderRoleAppointment#${ACCOUNT_ID}#${role}`) {
123
- return { value: { kind: "String", value: mailboxId } };
124
- }
125
- }
126
- return null;
127
- },
128
- },
129
- mailboxQueue: {
130
- deleteMailbox: async (mailboxId: string) => {
131
- deleted.push(mailboxId);
132
- },
133
- },
134
- } as unknown as RemitClient);
135
-
136
- return {
137
- deleted,
138
- run: () =>
139
- deleteMailbox(
140
- {
141
- request: { params: { accountId: ACCOUNT_ID, mailboxId: "mbx-1" } },
142
- } as unknown as Context,
143
- {
144
- requestContext: { authorizer: { claims: { sub: SUB } } },
145
- } as unknown as APIGatewayProxyEvent,
146
- ),
147
- };
148
- };
149
-
150
- const refusal = (match: RegExp) => (error: unknown) =>
151
- (error as { statusCode?: number }).statusCode === 400 &&
152
- match.test((error as Error).message);
153
-
154
- describe("MailboxDetailOperations_deleteMailbox — what it refuses (D4, D16)", () => {
155
- afterEach(() => {
156
- _resetForTest();
157
- });
158
-
159
- it("refuses the inbox", async () => {
160
- const { run, deleted } = callDelete({
161
- mailbox: folder({ fullPath: "INBOX" }),
162
- });
163
-
164
- await assert.rejects(run(), refusal(/inbox can't be deleted/));
165
- assert.deepEqual(deleted, []);
166
- });
167
-
168
- it("refuses a folder that has folders inside it", async () => {
169
- // The server would keep the parent's name as a placeholder and leave the
170
- // children untouched — an outcome no local row describes.
171
- const { run, deleted } = callDelete({
172
- children: [folder({ mailboxId: "mbx-2", fullPath: "Receipts/2026" })],
173
- });
174
-
175
- await assert.rejects(run(), refusal(/has folders inside it/));
176
- assert.deepEqual(deleted, []);
177
- });
178
-
179
- /**
180
- * D16. Refusing is what makes the settled-target rule total: a binding is
181
- * only created against a settled folder and only removed by the user, so a
182
- * mailboxId that names nothing never exists and no reader needs a
183
- * missing-target branch.
184
- */
185
- it("refuses a folder a filter moves mail into, naming the filter", async () => {
186
- const { run, deleted } = callDelete({
187
- filters: [{ name: "Invoices → Receipts", actionMailboxId: "mbx-1" }],
188
- });
189
-
190
- await assert.rejects(run(), refusal(/the filter “Invoices → Receipts”/));
191
- assert.deepEqual(deleted, []);
192
- });
193
-
194
- it("refuses a folder appointed to a role, naming the role", async () => {
195
- const { run, deleted } = callDelete({ appointments: { Archive: "mbx-1" } });
196
-
197
- await assert.rejects(run(), refusal(/the Archive role/));
198
- assert.deepEqual(deleted, []);
199
- });
200
-
201
- it("names both when both are bound", async () => {
202
- const { run } = callDelete({
203
- filters: [{ name: "Invoices", actionMailboxId: "mbx-1" }],
204
- appointments: { Archive: "mbx-1" },
205
- });
206
-
207
- await assert.rejects(
208
- run(),
209
- refusal(/the filter “Invoices” and the Archive role/),
210
- );
211
- });
212
-
213
- it("ignores a filter that moves mail into a different folder", async () => {
214
- const { run, deleted } = callDelete({
215
- filters: [{ name: "Elsewhere", actionMailboxId: "mbx-9" }],
216
- });
217
-
218
- assert.deepEqual(await run(), { statusCode: 204 });
219
- assert.deepEqual(deleted, ["mbx-1"]);
220
- });
221
-
222
- it("ignores a filter with no move action at all", async () => {
223
- const { run, deleted } = callDelete({
224
- filters: [{ name: "Just a label", actionMailboxId: "None" }],
225
- });
226
-
227
- assert.deepEqual(await run(), { statusCode: 204 });
228
- assert.deepEqual(deleted, ["mbx-1"]);
229
- });
230
-
231
- it("records the intent for an ordinary folder", async () => {
232
- const { run, deleted } = callDelete({});
233
-
234
- assert.deepEqual(await run(), { statusCode: 204 });
235
- assert.deepEqual(deleted, ["mbx-1"]);
236
- });
237
- });
238
-
239
- const createMailbox =
240
- MailboxOperations.MailboxOperations_createMailbox as unknown as (
241
- context: Context,
242
- event: APIGatewayProxyEvent,
243
- ) => Promise<unknown>;
244
-
245
- describe("MailboxOperations_createMailbox", () => {
246
- afterEach(() => {
247
- _resetForTest();
248
- });
249
-
250
- it("refuses a path the account already has a folder at", async () => {
251
- setClient({
252
- account: {
253
- get: async () => ({
254
- accountId: ACCOUNT_ID,
255
- accountConfigId: deriveAccountConfigId(SUB),
256
- }),
257
- },
258
- mailboxQueue: {
259
- createMailbox: async () => ({ outcome: "PathTaken" }),
260
- },
261
- } as unknown as RemitClient);
262
-
263
- await assert.rejects(
264
- createMailbox(
265
- {
266
- request: {
267
- params: { accountId: ACCOUNT_ID },
268
- requestBody: { namespaceType: "personal", fullPath: "Receipts" },
269
- },
270
- } as unknown as Context,
271
- {
272
- requestContext: { authorizer: { claims: { sub: SUB } } },
273
- } as unknown as APIGatewayProxyEvent,
274
- ),
275
- (error: unknown) =>
276
- error instanceof BadRequestError &&
277
- error.message === "A folder named “Receipts” is already there.",
278
- );
279
- });
280
- });