@remit/backend 0.0.143 → 0.0.145

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 (279) 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 +5 -0
  4. package/dist/src/api.js +73 -0
  5. package/dist/src/auth.d.ts +24 -0
  6. package/dist/src/auth.js +81 -0
  7. package/dist/src/config/api-config.d.ts +20 -0
  8. package/dist/src/config/api-config.js +1 -0
  9. package/dist/src/config/from-env.d.ts +2 -0
  10. package/dist/src/config/from-env.js +65 -0
  11. package/dist/src/config/msoauth-secrets-manager.d.ts +2 -0
  12. package/dist/src/config/msoauth-secrets-manager.js +28 -0
  13. package/dist/src/config/msoauth.d.ts +19 -0
  14. package/dist/src/config/msoauth.js +6 -0
  15. package/{src/derive/autoMoved.ts → dist/src/derive/autoMoved.d.ts} +1 -29
  16. package/dist/src/derive/autoMoved.js +49 -0
  17. package/dist/src/derive/contentSignature.d.ts +40 -0
  18. package/{src/derive/contentSignature.ts → dist/src/derive/contentSignature.js} +23 -77
  19. package/dist/src/derive/contentUrl.d.ts +33 -0
  20. package/dist/src/derive/contentUrl.js +27 -0
  21. package/{src/derive/deriveMuted.ts → dist/src/derive/deriveMuted.d.ts} +1 -3
  22. package/dist/src/derive/deriveMuted.js +7 -0
  23. package/dist/src/derive/enrichThreadRows.d.ts +118 -0
  24. package/dist/src/derive/enrichThreadRows.js +151 -0
  25. package/dist/src/derive/filterThreadCriteria.d.ts +23 -0
  26. package/dist/src/derive/filterThreadCriteria.js +24 -0
  27. package/{src/derive/pendingMoveCounts.ts → dist/src/derive/pendingMoveCounts.d.ts} +5 -53
  28. package/dist/src/derive/pendingMoveCounts.js +53 -0
  29. package/{src/derive/senderTrust.ts → dist/src/derive/senderTrust.d.ts} +1 -9
  30. package/dist/src/derive/senderTrust.js +19 -0
  31. package/dist/src/error.d.ts +21 -0
  32. package/dist/src/error.js +85 -0
  33. package/dist/src/handlers/account-guards.d.ts +36 -0
  34. package/dist/src/handlers/account-guards.js +107 -0
  35. package/dist/src/handlers/account-oauth.d.ts +15 -0
  36. package/dist/src/handlers/account-oauth.js +334 -0
  37. package/dist/src/handlers/account-overrides.d.ts +53 -0
  38. package/dist/src/handlers/account-overrides.js +233 -0
  39. package/dist/src/handlers/account-signature.d.ts +28 -0
  40. package/dist/src/handlers/account-signature.js +85 -0
  41. package/dist/src/handlers/account.d.ts +7 -0
  42. package/dist/src/handlers/account.js +337 -0
  43. package/dist/src/handlers/address.d.ts +35 -0
  44. package/dist/src/handlers/address.js +133 -0
  45. package/dist/src/handlers/calendar-event.d.ts +70 -0
  46. package/dist/src/handlers/calendar-event.js +417 -0
  47. package/dist/src/handlers/calendar-feed.d.ts +47 -0
  48. package/dist/src/handlers/calendar-feed.js +184 -0
  49. package/dist/src/handlers/calendar-suggestion.d.ts +47 -0
  50. package/dist/src/handlers/calendar-suggestion.js +204 -0
  51. package/dist/src/handlers/calendar.d.ts +116 -0
  52. package/dist/src/handlers/calendar.js +323 -0
  53. package/dist/src/handlers/config.d.ts +43 -0
  54. package/dist/src/handlers/config.js +164 -0
  55. package/dist/src/handlers/ensure-account-config.d.ts +9 -0
  56. package/dist/src/handlers/ensure-account-config.js +27 -0
  57. package/dist/src/handlers/filter.d.ts +3 -0
  58. package/dist/src/handlers/filter.js +88 -0
  59. package/dist/src/handlers/folder-role-appointments.d.ts +68 -0
  60. package/dist/src/handlers/folder-role-appointments.js +168 -0
  61. package/dist/src/handlers/folder-role-labels.d.ts +26 -0
  62. package/dist/src/handlers/folder-role-labels.js +40 -0
  63. package/dist/src/handlers/folder-role.d.ts +9 -0
  64. package/dist/src/handlers/folder-role.js +37 -0
  65. package/dist/src/handlers/index.d.ts +88 -0
  66. package/dist/src/handlers/index.js +62 -0
  67. package/dist/src/handlers/label.d.ts +43 -0
  68. package/dist/src/handlers/label.js +107 -0
  69. package/dist/src/handlers/mailbox-bindings.d.ts +41 -0
  70. package/dist/src/handlers/mailbox-bindings.js +61 -0
  71. package/dist/src/handlers/mailbox.d.ts +23 -0
  72. package/dist/src/handlers/mailbox.js +211 -0
  73. package/dist/src/handlers/me.d.ts +2 -0
  74. package/dist/src/handlers/me.js +117 -0
  75. package/dist/src/handlers/message.d.ts +82 -0
  76. package/dist/src/handlers/message.js +595 -0
  77. package/dist/src/handlers/organize.d.ts +10 -0
  78. package/dist/src/handlers/organize.js +103 -0
  79. package/dist/src/handlers/outbox-attachment.d.ts +25 -0
  80. package/dist/src/handlers/outbox-attachment.js +77 -0
  81. package/dist/src/handlers/outbox.d.ts +4 -0
  82. package/dist/src/handlers/outbox.js +136 -0
  83. package/dist/src/handlers/sync-progress.d.ts +46 -0
  84. package/dist/src/handlers/sync-progress.js +63 -0
  85. package/dist/src/handlers/sync.d.ts +28 -0
  86. package/dist/src/handlers/sync.js +73 -0
  87. package/dist/src/handlers/system-update.d.ts +2 -0
  88. package/dist/src/handlers/system-update.js +159 -0
  89. package/dist/src/handlers/thread.d.ts +148 -0
  90. package/dist/src/handlers/thread.js +228 -0
  91. package/dist/src/handlers/unified-threads.d.ts +247 -0
  92. package/dist/src/handlers/unified-threads.js +406 -0
  93. package/{src/handlers/vip-suggestions.ts → dist/src/handlers/vip-suggestions.d.ts} +1 -13
  94. package/dist/src/handlers/vip-suggestions.js +16 -0
  95. package/dist/src/index.d.ts +5 -0
  96. package/dist/src/index.js +53 -0
  97. package/{src/json.ts → dist/src/json.d.ts} +1 -4
  98. package/dist/src/json.js +10 -0
  99. package/dist/src/jwt-auth.d.ts +15 -0
  100. package/dist/src/jwt-auth.js +45 -0
  101. package/dist/src/lambda.d.ts +13 -0
  102. package/dist/src/lambda.js +33 -0
  103. package/dist/src/request.d.ts +9 -0
  104. package/dist/src/request.js +17 -0
  105. package/dist/src/response.d.ts +44 -0
  106. package/dist/src/response.js +80 -0
  107. package/dist/src/serve.d.ts +31 -0
  108. package/dist/src/serve.js +117 -0
  109. package/dist/src/service/account-deletion.d.ts +20 -0
  110. package/dist/src/service/account-deletion.js +33 -0
  111. package/dist/src/service/compose-sqlite.d.ts +3 -0
  112. package/dist/src/service/compose-sqlite.js +13 -0
  113. package/dist/src/service/create-remit-client.d.ts +109 -0
  114. package/dist/src/service/create-remit-client.js +188 -0
  115. package/dist/src/service/data-client.d.ts +12 -0
  116. package/dist/src/service/data-client.js +42 -0
  117. package/dist/src/service/export-identity.d.ts +4 -0
  118. package/dist/src/service/export-identity.js +33 -0
  119. package/dist/src/service/fire-and-forget.d.ts +54 -0
  120. package/dist/src/service/fire-and-forget.js +37 -0
  121. package/dist/src/service/organize.d.ts +181 -0
  122. package/dist/src/service/organize.js +367 -0
  123. package/dist/src/service/queues.d.ts +12 -0
  124. package/dist/src/service/queues.js +1 -0
  125. package/dist/src/service/refusal.d.ts +4 -0
  126. package/dist/src/service/refusal.js +20 -0
  127. package/dist/src/service/sender-category.d.ts +51 -0
  128. package/{src/service/sender-category.ts → dist/src/service/sender-category.js} +40 -81
  129. package/dist/src/service/shared-deps.d.ts +6 -0
  130. package/dist/src/service/shared-deps.js +24 -0
  131. package/dist/src/service/trigger-sync.d.ts +57 -0
  132. package/dist/src/service/trigger-sync.js +31 -0
  133. package/dist/src/types.d.ts +72 -0
  134. package/dist/src/types.js +1 -0
  135. package/package.json +125 -98
  136. package/.env.test +0 -4
  137. package/dev-server/content-auth.test.ts +0 -113
  138. package/dev-server/content-auth.ts +0 -54
  139. package/dev-server/content-handler.test.ts +0 -105
  140. package/dev-server/content-handler.ts +0 -79
  141. package/dev-server/content-path.test.ts +0 -37
  142. package/dev-server/content-path.ts +0 -27
  143. package/dev-server/cors.test.ts +0 -48
  144. package/dev-server/cors.ts +0 -25
  145. package/dev-server/keep-alive.test.ts +0 -24
  146. package/dev-server/lambda-helpers.ts +0 -69
  147. package/dev-server/log-output.test.ts +0 -173
  148. package/dev-server/oauth-callback-route.test.ts +0 -66
  149. package/dev-server/relational-health.test.ts +0 -83
  150. package/dev-server/relational-health.ts +0 -39
  151. package/dev-server/server.ts +0 -384
  152. package/dev-server/sync-age.test.ts +0 -91
  153. package/dev-server/sync-age.ts +0 -55
  154. package/dev-server/upload-handler.ts +0 -132
  155. package/dev-server/upload-route.test.ts +0 -196
  156. package/scripts/backfill-classification.ts +0 -91
  157. package/scripts/backfill-list-id.ts +0 -83
  158. package/scripts/config-save.ts +0 -128
  159. package/src/auth.test.ts +0 -12
  160. package/src/auth.ts +0 -92
  161. package/src/config/msoauth.test.ts +0 -48
  162. package/src/config/msoauth.ts +0 -48
  163. package/src/data-backend.test.ts +0 -23
  164. package/src/data-backend.ts +0 -14
  165. package/src/derive/autoMoved.test.ts +0 -104
  166. package/src/derive/contentSignature.test.ts +0 -161
  167. package/src/derive/contentUrl.test.ts +0 -172
  168. package/src/derive/contentUrl.ts +0 -86
  169. package/src/derive/deriveMuted.test.ts +0 -34
  170. package/src/derive/enrichThreadRows.test.ts +0 -360
  171. package/src/derive/enrichThreadRows.ts +0 -234
  172. package/src/derive/filterThreadCriteria.test.ts +0 -126
  173. package/src/derive/filterThreadCriteria.ts +0 -51
  174. package/src/derive/senderTrust.test.ts +0 -67
  175. package/src/error.test.ts +0 -201
  176. package/src/error.ts +0 -123
  177. package/src/handlers/account-guards.test.ts +0 -67
  178. package/src/handlers/account-guards.ts +0 -169
  179. package/src/handlers/account-oauth-callback.test.ts +0 -155
  180. package/src/handlers/account-oauth-consent.test.ts +0 -336
  181. package/src/handlers/account-oauth-start.test.ts +0 -191
  182. package/src/handlers/account-oauth.test.ts +0 -439
  183. package/src/handlers/account-oauth.ts +0 -635
  184. package/src/handlers/account-overrides.test.ts +0 -88
  185. package/src/handlers/account-overrides.ts +0 -323
  186. package/src/handlers/account-ownership.ts +0 -25
  187. package/src/handlers/account-signature.ts +0 -117
  188. package/src/handlers/account-synced-services.test.ts +0 -245
  189. package/src/handlers/account.ts +0 -552
  190. package/src/handlers/address.test.ts +0 -381
  191. package/src/handlers/address.ts +0 -200
  192. package/src/handlers/calendar-event.test.ts +0 -685
  193. package/src/handlers/calendar-event.ts +0 -738
  194. package/src/handlers/calendar-feed-validators.test.ts +0 -228
  195. package/src/handlers/calendar-feed.test.ts +0 -439
  196. package/src/handlers/calendar-feed.ts +0 -291
  197. package/src/handlers/calendar-sqlite-fixture.ts +0 -36
  198. package/src/handlers/calendar-suggestion.test.ts +0 -1269
  199. package/src/handlers/calendar-suggestion.ts +0 -425
  200. package/src/handlers/calendar.test.ts +0 -1080
  201. package/src/handlers/calendar.ts +0 -517
  202. package/src/handlers/config.test.ts +0 -245
  203. package/src/handlers/config.ts +0 -332
  204. package/src/handlers/ensure-account-config.ts +0 -30
  205. package/src/handlers/filter.test.ts +0 -644
  206. package/src/handlers/filter.ts +0 -518
  207. package/src/handlers/folder-role-appointments.test.ts +0 -438
  208. package/src/handlers/folder-role-appointments.ts +0 -249
  209. package/src/handlers/folder-role-labels.ts +0 -63
  210. package/src/handlers/folder-role.test.ts +0 -209
  211. package/src/handlers/folder-role.ts +0 -80
  212. package/src/handlers/index.ts +0 -83
  213. package/src/handlers/label.test.ts +0 -112
  214. package/src/handlers/label.ts +0 -210
  215. package/src/handlers/mailbox-bindings.ts +0 -111
  216. package/src/handlers/mailbox-rename-refusal.test.ts +0 -247
  217. package/src/handlers/mailbox-settled-target.test.ts +0 -251
  218. package/src/handlers/mailbox.test.ts +0 -280
  219. package/src/handlers/mailbox.ts +0 -581
  220. package/src/handlers/me.test.ts +0 -81
  221. package/src/handlers/me.ts +0 -203
  222. package/src/handlers/message-read-backfill.test.ts +0 -103
  223. package/src/handlers/message.test.ts +0 -131
  224. package/src/handlers/message.ts +0 -1131
  225. package/src/handlers/organize.test.ts +0 -277
  226. package/src/handlers/organize.ts +0 -197
  227. package/src/handlers/outbox-attachment.test.ts +0 -765
  228. package/src/handlers/outbox-attachment.ts +0 -126
  229. package/src/handlers/outbox-list.test.ts +0 -179
  230. package/src/handlers/outbox.test.ts +0 -772
  231. package/src/handlers/outbox.ts +0 -258
  232. package/src/handlers/search.test.ts +0 -161
  233. package/src/handlers/search.ts +0 -105
  234. package/src/handlers/sync-progress.test.ts +0 -205
  235. package/src/handlers/sync-progress.ts +0 -99
  236. package/src/handlers/sync.test.ts +0 -168
  237. package/src/handlers/sync.ts +0 -118
  238. package/src/handlers/system-update.test.ts +0 -497
  239. package/src/handlers/system-update.ts +0 -230
  240. package/src/handlers/thread.test.ts +0 -396
  241. package/src/handlers/thread.ts +0 -427
  242. package/src/handlers/unified-threads-mail-sources.sqlite.test.ts +0 -197
  243. package/src/handlers/unified-threads.test.ts +0 -785
  244. package/src/handlers/unified-threads.ts +0 -669
  245. package/src/index.test.ts +0 -83
  246. package/src/index.ts +0 -228
  247. package/src/jwt-auth.test.ts +0 -152
  248. package/src/jwt-auth.ts +0 -132
  249. package/src/log-redaction.test.ts +0 -144
  250. package/src/openapi-spec.test.ts +0 -118
  251. package/src/request-context.test.ts +0 -61
  252. package/src/request-context.ts +0 -33
  253. package/src/request-pipeline.test.ts +0 -88
  254. package/src/request.ts +0 -10
  255. package/src/response.test.ts +0 -130
  256. package/src/response.ts +0 -144
  257. package/src/service/compose-sqlite.ts +0 -98
  258. package/src/service/config-import.ts +0 -39
  259. package/src/service/create-remit-client.ts +0 -522
  260. package/src/service/data-client.test.ts +0 -97
  261. package/src/service/data-client.ts +0 -58
  262. package/src/service/export-identity.ts +0 -39
  263. package/src/service/filter.ts +0 -40
  264. package/src/service/fire-and-forget.test.ts +0 -126
  265. package/src/service/fire-and-forget.ts +0 -79
  266. package/src/service/localhost-env-config.test.ts +0 -36
  267. package/src/service/organize-queue.ts +0 -98
  268. package/src/service/organize.test.ts +0 -1451
  269. package/src/service/organize.ts +0 -1025
  270. package/src/service/read-path-filter-config.test.ts +0 -243
  271. package/src/service/semantic-capability.test.ts +0 -78
  272. package/src/service/semantic-capability.ts +0 -95
  273. package/src/service/sender-category.test.ts +0 -235
  274. package/src/service/sqs.ts +0 -4
  275. package/src/service/trigger-sync.test.ts +0 -205
  276. package/src/service/trigger-sync.ts +0 -100
  277. package/src/stdout-capture-fixture.ts +0 -40
  278. package/src/types.ts +0 -271
  279. package/tsconfig.json +0 -7
@@ -0,0 +1,68 @@
1
+ import type { FolderAppointment } from "@remit/api-openapi-types";
2
+ import type { AccountSettingItem, IAccountSettingRepository, IMailboxRepository } from "@remit/data-ports";
3
+ import { CANONICAL_ROLES, type CanonicalMailboxRoleValue, type RoleMailboxCandidate } from "@remit/data-ports/folder-role";
4
+ /**
5
+ * RFC 032 exclusive-folder-appointment (#976): a per-account role→mailbox map.
6
+ * Each row is a `FolderRoleAppointment#<accountId>#<role>` AccountSetting (RFC
7
+ * 032 settings tiers), so a role can never be persisted twice for one account —
8
+ * writing it replaces whichever mailbox previously held it. This module owns
9
+ * that persistence; the read side is `resolveRoleForAccount`
10
+ * (`@remit/data-ports/folder-role`), the same rule every special-folder lookup
11
+ * in the backend and the workers goes through.
12
+ *
13
+ * A second row, `FolderRoleAppointmentLabel#<accountId>#<role>`, records the
14
+ * path the appointed mailbox had at the time (#887), so a folder another client
15
+ * later deletes can still be named back to the user. It is display only: it
16
+ * lives beside the appointment rather than inside it precisely so the
17
+ * repository that resolves roles composes one name and cannot reach the other.
18
+ */
19
+ export { CANONICAL_ROLES };
20
+ /** One role's persisted appointment: the choice, plus the path it was made on. */
21
+ export interface PersistedFolderAppointment {
22
+ mailboxId: string;
23
+ lastKnownPath?: string;
24
+ }
25
+ /**
26
+ * Group every persisted folder-role appointment in one config-wide settings
27
+ * read (e.g. GET /config's already-loaded `listByAccountConfig` result) by
28
+ * accountId, then by role. Mirrors `groupAccountOverrides` / `groupMailboxOverrides`.
29
+ */
30
+ export declare const groupFolderAppointmentsByAccount: (settings: AccountSettingItem[]) => Map<string, Map<string, PersistedFolderAppointment>>;
31
+ /**
32
+ * Load one account's persisted appointments by reading each role's row
33
+ * directly (mirrors `loadMailboxOverrides`'s three-get pattern). Used by the
34
+ * create/update account handlers, which only ever need a single account.
35
+ */
36
+ export declare const loadFolderAppointmentsForAccount: (accountSetting: Pick<IAccountSettingRepository, "get">, accountConfigId: string, accountId: string) => Promise<Map<string, PersistedFolderAppointment>>;
37
+ /**
38
+ * Persist (or clear) one role's appointment. `mailboxId: null` deletes the row
39
+ * — the role goes back to unfilled (RFC 032 settings tiers: absence is unset).
40
+ * A value upserts it, replacing whatever mailbox the role pointed at before;
41
+ * there is no second row a duplicate could live in.
42
+ *
43
+ * The label row moves with it, so a path recorded for a previous choice can
44
+ * never be shown against the current one.
45
+ */
46
+ export declare const writeFolderRoleAppointment: (accountSetting: Pick<IAccountSettingRepository, "upsert" | "delete">, accountConfigId: string, accountId: string, role: CanonicalMailboxRoleValue, mailboxId: string | null, lastKnownPath?: string) => Promise<void>;
47
+ /**
48
+ * Resolve the full appointment set for one account, each entry saying where it
49
+ * came from: the user's persisted choice when set, else the server's
50
+ * SPECIAL-USE flag, else the reserved INBOX name, else a name proposal. A
51
+ * choice naming a mailbox the account no longer holds resolves to whatever the
52
+ * account would have had without it, and says so — the user's decision is
53
+ * surfaced as broken rather than quietly discarded. Always one entry per
54
+ * `CANONICAL_ROLES` member (RFC 032 settings tiers: total, never a sparse
55
+ * array).
56
+ */
57
+ export declare const resolveFolderAppointments: (persisted: ReadonlyMap<string, PersistedFolderAppointment>, mailboxes: readonly RoleMailboxCandidate[]) => FolderAppointment[];
58
+ /**
59
+ * End-to-end resolution for one account: load its persisted appointments and
60
+ * its mailboxes, then resolve. The single entry point every handler that
61
+ * builds an AccountResponse calls (create/update account, GET /config's
62
+ * per-account fan-out mirrors this with a pre-loaded settings batch instead —
63
+ * see `groupFolderAppointmentsByAccount` — to avoid an N+1 settings read).
64
+ */
65
+ export declare const resolveAccountFolderAppointments: (client: {
66
+ mailbox: Pick<IMailboxRepository, "listAllByAccount">;
67
+ accountSetting: Pick<IAccountSettingRepository, "get">;
68
+ }, accountConfigId: string, accountId: string) => Promise<FolderAppointment[]>;
@@ -0,0 +1,168 @@
1
+ import { CANONICAL_ROLES, composeFolderRoleAppointmentLabelName, composeFolderRoleAppointmentName, parseFolderRoleAppointmentLabelName, parseFolderRoleAppointmentName, resolveRoleForAccount, } from "@remit/data-ports/folder-role";
2
+ import { FolderAppointmentSource } from "@remit/domain-enums";
3
+ /**
4
+ * RFC 032 exclusive-folder-appointment (#976): a per-account role→mailbox map.
5
+ * Each row is a `FolderRoleAppointment#<accountId>#<role>` AccountSetting (RFC
6
+ * 032 settings tiers), so a role can never be persisted twice for one account —
7
+ * writing it replaces whichever mailbox previously held it. This module owns
8
+ * that persistence; the read side is `resolveRoleForAccount`
9
+ * (`@remit/data-ports/folder-role`), the same rule every special-folder lookup
10
+ * in the backend and the workers goes through.
11
+ *
12
+ * A second row, `FolderRoleAppointmentLabel#<accountId>#<role>`, records the
13
+ * path the appointed mailbox had at the time (#887), so a folder another client
14
+ * later deletes can still be named back to the user. It is display only: it
15
+ * lives beside the appointment rather than inside it precisely so the
16
+ * repository that resolves roles composes one name and cannot reach the other.
17
+ */
18
+ export { CANONICAL_ROLES };
19
+ const stringValueOf = (item) => {
20
+ const { value } = item;
21
+ return value.kind === "String" ? value.value : undefined;
22
+ };
23
+ /**
24
+ * Group every persisted folder-role appointment in one config-wide settings
25
+ * read (e.g. GET /config's already-loaded `listByAccountConfig` result) by
26
+ * accountId, then by role. Mirrors `groupAccountOverrides` / `groupMailboxOverrides`.
27
+ */
28
+ export const groupFolderAppointmentsByAccount = (settings) => {
29
+ const byAccount = new Map();
30
+ for (const setting of settings) {
31
+ const target = parseFolderRoleAppointmentName(setting.name);
32
+ if (!target)
33
+ continue;
34
+ const mailboxId = stringValueOf(setting);
35
+ if (mailboxId === undefined)
36
+ continue;
37
+ const roles = byAccount.get(target.accountId) ??
38
+ new Map();
39
+ roles.set(target.role, { mailboxId });
40
+ byAccount.set(target.accountId, roles);
41
+ }
42
+ for (const setting of settings) {
43
+ const target = parseFolderRoleAppointmentLabelName(setting.name);
44
+ if (!target)
45
+ continue;
46
+ const lastKnownPath = stringValueOf(setting);
47
+ if (lastKnownPath === undefined)
48
+ continue;
49
+ const appointment = byAccount.get(target.accountId)?.get(target.role);
50
+ if (!appointment)
51
+ continue;
52
+ appointment.lastKnownPath = lastKnownPath;
53
+ }
54
+ return byAccount;
55
+ };
56
+ /**
57
+ * Load one account's persisted appointments by reading each role's row
58
+ * directly (mirrors `loadMailboxOverrides`'s three-get pattern). Used by the
59
+ * create/update account handlers, which only ever need a single account.
60
+ */
61
+ export const loadFolderAppointmentsForAccount = async (accountSetting, accountConfigId, accountId) => {
62
+ const entries = await Promise.all(CANONICAL_ROLES.map(async (role) => {
63
+ const appointment = await accountSetting.get(accountConfigId, composeFolderRoleAppointmentName(accountId, role));
64
+ const mailboxId = appointment ? stringValueOf(appointment) : undefined;
65
+ if (mailboxId === undefined)
66
+ return [role, undefined];
67
+ const label = await accountSetting.get(accountConfigId, composeFolderRoleAppointmentLabelName(accountId, role));
68
+ const lastKnownPath = label ? stringValueOf(label) : undefined;
69
+ return [
70
+ role,
71
+ lastKnownPath === undefined
72
+ ? { mailboxId }
73
+ : { mailboxId, lastKnownPath },
74
+ ];
75
+ }));
76
+ const roles = new Map();
77
+ for (const [role, appointment] of entries) {
78
+ if (appointment)
79
+ roles.set(role, appointment);
80
+ }
81
+ return roles;
82
+ };
83
+ /**
84
+ * Persist (or clear) one role's appointment. `mailboxId: null` deletes the row
85
+ * — the role goes back to unfilled (RFC 032 settings tiers: absence is unset).
86
+ * A value upserts it, replacing whatever mailbox the role pointed at before;
87
+ * there is no second row a duplicate could live in.
88
+ *
89
+ * The label row moves with it, so a path recorded for a previous choice can
90
+ * never be shown against the current one.
91
+ */
92
+ export const writeFolderRoleAppointment = async (accountSetting, accountConfigId, accountId, role, mailboxId, lastKnownPath) => {
93
+ const name = composeFolderRoleAppointmentName(accountId, role);
94
+ const labelName = composeFolderRoleAppointmentLabelName(accountId, role);
95
+ if (mailboxId === null) {
96
+ await accountSetting.delete(accountConfigId, name);
97
+ await accountSetting.delete(accountConfigId, labelName);
98
+ return;
99
+ }
100
+ await accountSetting.upsert({
101
+ accountConfigId,
102
+ name,
103
+ value: { kind: "String", value: mailboxId },
104
+ });
105
+ if (lastKnownPath === undefined) {
106
+ await accountSetting.delete(accountConfigId, labelName);
107
+ return;
108
+ }
109
+ await accountSetting.upsert({
110
+ accountConfigId,
111
+ name: labelName,
112
+ value: { kind: "String", value: lastKnownPath },
113
+ });
114
+ };
115
+ const SOURCE_BY_KIND = {
116
+ appointed: FolderAppointmentSource.Appointed,
117
+ flagged: FolderAppointmentSource.Flagged,
118
+ reserved: FolderAppointmentSource.Reserved,
119
+ proposed: FolderAppointmentSource.Proposed,
120
+ };
121
+ const toFolderAppointment = (role, resolution, lastKnownPath) => {
122
+ if (resolution.kind === "appointment_stale") {
123
+ const { fallback } = resolution;
124
+ return {
125
+ role,
126
+ source: FolderAppointmentSource.Stale,
127
+ mailboxId: fallback.kind === "none" ? undefined : fallback.mailbox.mailboxId,
128
+ staleAppointmentMailboxId: resolution.appointedMailboxId,
129
+ staleAppointmentPath: lastKnownPath,
130
+ };
131
+ }
132
+ if (resolution.kind === "none") {
133
+ return { role, source: FolderAppointmentSource.None };
134
+ }
135
+ return {
136
+ role,
137
+ source: SOURCE_BY_KIND[resolution.kind],
138
+ mailboxId: resolution.mailbox.mailboxId,
139
+ };
140
+ };
141
+ /**
142
+ * Resolve the full appointment set for one account, each entry saying where it
143
+ * came from: the user's persisted choice when set, else the server's
144
+ * SPECIAL-USE flag, else the reserved INBOX name, else a name proposal. A
145
+ * choice naming a mailbox the account no longer holds resolves to whatever the
146
+ * account would have had without it, and says so — the user's decision is
147
+ * surfaced as broken rather than quietly discarded. Always one entry per
148
+ * `CANONICAL_ROLES` member (RFC 032 settings tiers: total, never a sparse
149
+ * array).
150
+ */
151
+ export const resolveFolderAppointments = (persisted, mailboxes) => CANONICAL_ROLES.map((role) => {
152
+ const appointment = persisted.get(role);
153
+ return toFolderAppointment(role, resolveRoleForAccount(role, mailboxes, appointment?.mailboxId), appointment?.lastKnownPath);
154
+ });
155
+ /**
156
+ * End-to-end resolution for one account: load its persisted appointments and
157
+ * its mailboxes, then resolve. The single entry point every handler that
158
+ * builds an AccountResponse calls (create/update account, GET /config's
159
+ * per-account fan-out mirrors this with a pre-loaded settings batch instead —
160
+ * see `groupFolderAppointmentsByAccount` — to avoid an N+1 settings read).
161
+ */
162
+ export const resolveAccountFolderAppointments = async (client, accountConfigId, accountId) => {
163
+ const [persisted, mailboxes] = await Promise.all([
164
+ loadFolderAppointmentsForAccount(client.accountSetting, accountConfigId, accountId),
165
+ client.mailbox.listAllByAccount(accountId),
166
+ ]);
167
+ return resolveFolderAppointments(persisted, mailboxes);
168
+ };
@@ -0,0 +1,26 @@
1
+ import type { IAccountSettingRepository } from "@remit/data-ports";
2
+ /**
3
+ * The label row beside each role appointment records the path its folder had at
4
+ * the time (#887), so a folder another client later deletes can still be named
5
+ * back to the user. It is display only, and it lives here rather than beside
6
+ * the appointment writer because that writer is guarded as the only writer of
7
+ * the appointment row itself.
8
+ *
9
+ * A rename keeps every mailboxId, so an appointment survives it — but the path
10
+ * recorded beside it still names where the folder was. Move the labels with the
11
+ * branch, or a later third-party delete names a path the user has not seen
12
+ * since the rename.
13
+ *
14
+ * Driven by the settle, not by the intent: under D2 the row keeps the path the
15
+ * mail server holds until the rename lands, so a label moved when the intent
16
+ * was recorded would name a path that does not exist — permanently, if the
17
+ * rename then fails.
18
+ *
19
+ * The renamed folder is matched by id; its descendants are matched by the path
20
+ * each label already holds.
21
+ */
22
+ export declare const refreshFolderAppointmentLabels: (accountSetting: Pick<IAccountSettingRepository, "get" | "upsert">, accountConfigId: string, accountId: string, renamed: {
23
+ mailboxId: string;
24
+ oldPath: string;
25
+ newPath: string;
26
+ }, delimiter: string) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ import { composeFolderRoleAppointmentLabelName, } from "@remit/data-ports/folder-role";
2
+ import { rebaseMailboxPath } from "@remit/data-ports/mailbox-name";
3
+ import { loadFolderAppointmentsForAccount } from "./folder-role-appointments.js";
4
+ /**
5
+ * The label row beside each role appointment records the path its folder had at
6
+ * the time (#887), so a folder another client later deletes can still be named
7
+ * back to the user. It is display only, and it lives here rather than beside
8
+ * the appointment writer because that writer is guarded as the only writer of
9
+ * the appointment row itself.
10
+ *
11
+ * A rename keeps every mailboxId, so an appointment survives it — but the path
12
+ * recorded beside it still names where the folder was. Move the labels with the
13
+ * branch, or a later third-party delete names a path the user has not seen
14
+ * since the rename.
15
+ *
16
+ * Driven by the settle, not by the intent: under D2 the row keeps the path the
17
+ * mail server holds until the rename lands, so a label moved when the intent
18
+ * was recorded would name a path that does not exist — permanently, if the
19
+ * rename then fails.
20
+ *
21
+ * The renamed folder is matched by id; its descendants are matched by the path
22
+ * each label already holds.
23
+ */
24
+ export const refreshFolderAppointmentLabels = async (accountSetting, accountConfigId, accountId, renamed, delimiter) => {
25
+ const persisted = await loadFolderAppointmentsForAccount(accountSetting, accountConfigId, accountId);
26
+ for (const [role, appointment] of persisted) {
27
+ const moved = appointment.mailboxId === renamed.mailboxId
28
+ ? renamed.newPath
29
+ : appointment.lastKnownPath === undefined
30
+ ? undefined
31
+ : rebaseMailboxPath(appointment.lastKnownPath, renamed.oldPath, renamed.newPath, delimiter);
32
+ if (moved === undefined || moved === appointment.lastKnownPath)
33
+ continue;
34
+ await accountSetting.upsert({
35
+ accountConfigId,
36
+ name: composeFolderRoleAppointmentLabelName(accountId, role),
37
+ value: { kind: "String", value: moved },
38
+ });
39
+ }
40
+ };
@@ -0,0 +1,9 @@
1
+ import type { FolderRoleOperationIds, OperationHandler } from "../types.js";
2
+ /**
3
+ * RFC 032 exclusive-folder-appointment (#976): the single write operation for
4
+ * the per-account role map. `appoint(role, mailboxId)` sets `map[role]` —
5
+ * there is no second place a duplicate appointment could live, so writing a
6
+ * role replaces whichever mailbox previously held it. `mailboxId: null` clears
7
+ * the role back to unfilled.
8
+ */
9
+ export declare const FolderRoleOperations: Record<FolderRoleOperationIds, OperationHandler<FolderRoleOperationIds>>;
@@ -0,0 +1,37 @@
1
+ import { folderInAccount, ownedAccount, settledFolder, } from "@remit/mailbox-service";
2
+ import { unwrap } from "../service/refusal.js";
3
+ import { toAccountResponse } from "./account-guards.js";
4
+ import { loadAccountOverrides } from "./account-overrides.js";
5
+ import { loadSignatureForAccount } from "./account-signature.js";
6
+ import { resolveAccountFolderAppointments, writeFolderRoleAppointment, } from "./folder-role-appointments.js";
7
+ /**
8
+ * RFC 032 exclusive-folder-appointment (#976): the single write operation for
9
+ * the per-account role map. `appoint(role, mailboxId)` sets `map[role]` —
10
+ * there is no second place a duplicate appointment could live, so writing a
11
+ * role replaces whichever mailbox previously held it. `mailboxId: null` clears
12
+ * the role back to unfilled.
13
+ */
14
+ export const FolderRoleOperations = {
15
+ FolderRoleOperations_appointFolderRole: async (context, ctx) => {
16
+ const accountConfigId = ctx.identity.accountConfigId;
17
+ const { accountId, role } = context.request.params;
18
+ const body = context.request.requestBody;
19
+ const { account, accountSetting, mailbox } = ctx.client;
20
+ const existing = await account.get(accountId);
21
+ unwrap(ownedAccount(existing, accountConfigId, "act"));
22
+ let lastKnownPath;
23
+ if (body.mailboxId) {
24
+ const target = await mailbox.get(accountId, body.mailboxId);
25
+ unwrap(folderInAccount(target, accountId, "act"));
26
+ unwrap(settledFolder(target));
27
+ lastKnownPath = target.fullPath;
28
+ }
29
+ await writeFolderRoleAppointment(accountSetting, accountConfigId, accountId, role, body.mailboxId ?? null, lastKnownPath);
30
+ const [signature, overrides, folderAppointments] = await Promise.all([
31
+ loadSignatureForAccount(accountSetting, accountConfigId, accountId),
32
+ loadAccountOverrides(accountSetting, accountConfigId, accountId),
33
+ resolveAccountFolderAppointments({ mailbox, accountSetting }, accountConfigId, accountId),
34
+ ]);
35
+ return toAccountResponse(existing, signature, overrides, folderAppointments);
36
+ },
37
+ };
@@ -0,0 +1,88 @@
1
+ import type { OperationHandler, PublicOperationHandler } from "../types.js";
2
+ export declare const handlers: {
3
+ CalendarSuggestionActionOperations_acceptCalendarSuggestion: OperationHandler<import("../types.js").CalendarSuggestionActionOperationIds>;
4
+ CalendarSuggestionActionOperations_declineCalendarSuggestion: OperationHandler<import("../types.js").CalendarSuggestionActionOperationIds>;
5
+ CalendarSuggestionActionOperations_dismissCalendarSuggestion: OperationHandler<import("../types.js").CalendarSuggestionActionOperationIds>;
6
+ CalendarSuggestionActionOperations_reopenCalendarSuggestion: OperationHandler<import("../types.js").CalendarSuggestionActionOperationIds>;
7
+ MessageCalendarSuggestionOperations_listMessageCalendarSuggestions: OperationHandler<"MessageCalendarSuggestionOperations_listMessageCalendarSuggestions">;
8
+ CalendarSuggestionOperations_listCalendarSuggestions: OperationHandler<"CalendarSuggestionOperations_listCalendarSuggestions">;
9
+ AddressDetailOperations_updateAddress: OperationHandler<"AddressDetailOperations_updateAddress", "accountFanout">;
10
+ AddressOperations_searchAddresses: OperationHandler<"AddressOperations_searchAddresses", "accountFanout">;
11
+ OutboxAttachmentOperations_completeOutboxAttachment: OperationHandler<"OutboxAttachmentOperations_completeOutboxAttachment", "smtp">;
12
+ OutboxDetailOperations_getOutboxMessage: OperationHandler<import("../types.js").OutboxDetailOperationIds, "smtp">;
13
+ OutboxDetailOperations_updateOutboxMessage: OperationHandler<import("../types.js").OutboxDetailOperationIds, "smtp">;
14
+ OutboxDetailOperations_deleteOutboxMessage: OperationHandler<import("../types.js").OutboxDetailOperationIds, "smtp">;
15
+ OutboxDetailOperations_mintOutboxAttachment: OperationHandler<import("../types.js").OutboxDetailOperationIds, "smtp">;
16
+ OutboxDetailOperations_sendOutboxMessage: OperationHandler<import("../types.js").OutboxDetailOperationIds, "smtp">;
17
+ OutboxOperations_createOutboxMessage: OperationHandler<import("../types.js").OutboxOperationIds, "smtp">;
18
+ OutboxOperations_listOutboxMessages: OperationHandler<import("../types.js").OutboxOperationIds, "smtp">;
19
+ MessageBulkOperations_copyMessages: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
20
+ MessageBulkOperations_deleteMessages: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
21
+ MessageBulkOperations_updateFlags: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
22
+ MessageBulkOperations_updateMessageLabels: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
23
+ MessageBulkOperations_moveMessages: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
24
+ MessageBulkOperations_notSpam: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
25
+ MessageBulkOperations_reportSpam: OperationHandler<import("../types.js").MessageBulkOperationIds, "body" | "sync" | "messageManagement">;
26
+ MessageOperations_describeMessage: OperationHandler<import("../types.js").MessageOperationIds, "body" | "sync" | "messageManagement">;
27
+ MessageOperations_updateMessageFlags: OperationHandler<import("../types.js").MessageOperationIds, "body" | "sync" | "messageManagement">;
28
+ MessageOperations_getRawMessage: OperationHandler<import("../types.js").MessageOperationIds, "body" | "sync" | "messageManagement">;
29
+ ThreadOperations_listThreads: OperationHandler<import("../types.js").ThreadOperationIds>;
30
+ ThreadOperations_searchThreads: OperationHandler<import("../types.js").ThreadOperationIds>;
31
+ UnifiedThreadOperations_listAllThreads: OperationHandler<"UnifiedThreadOperations_listAllThreads">;
32
+ ThreadDetailOperations_listThreadMessages: OperationHandler<"ThreadDetailOperations_listThreadMessages">;
33
+ SyncOperations_triggerSync: OperationHandler<import("../types.js").SyncOperationIds, "sync">;
34
+ SyncOperations_getSyncStatus: OperationHandler<import("../types.js").SyncOperationIds, "sync">;
35
+ TrashOperations_emptyTrash: OperationHandler<"TrashOperations_emptyTrash", "sync">;
36
+ CalendarFreeBusyOperations_listCalendarFreeBusy: OperationHandler<"CalendarFreeBusyOperations_listCalendarFreeBusy">;
37
+ CalendarEventDetailOperations_getCalendarEvent: OperationHandler<import("../types.js").CalendarEventDetailOperationIds>;
38
+ CalendarEventDetailOperations_updateCalendarEvent: OperationHandler<import("../types.js").CalendarEventDetailOperationIds>;
39
+ CalendarEventDetailOperations_deleteCalendarEvent: OperationHandler<import("../types.js").CalendarEventDetailOperationIds>;
40
+ CalendarEventOperations_listCalendarEvents: OperationHandler<import("../types.js").CalendarEventOperationIds>;
41
+ CalendarEventOperations_createCalendarEvent: OperationHandler<import("../types.js").CalendarEventOperationIds>;
42
+ CalendarDetailOperations_getCalendarFeed: OperationHandler<import("../types.js").CalendarDetailOperationIds>;
43
+ CalendarDetailOperations_putCalendarFeed: OperationHandler<import("../types.js").CalendarDetailOperationIds>;
44
+ CalendarDetailOperations_revokeCalendarFeed: OperationHandler<import("../types.js").CalendarDetailOperationIds>;
45
+ CalendarDetailOperations_getCalendar: OperationHandler<import("../types.js").CalendarDetailOperationIds>;
46
+ CalendarDetailOperations_updateCalendar: OperationHandler<import("../types.js").CalendarDetailOperationIds>;
47
+ CalendarDetailOperations_deleteCalendar: OperationHandler<import("../types.js").CalendarDetailOperationIds>;
48
+ CalendarOperations_listCalendars: OperationHandler<import("../types.js").CalendarOperationIds>;
49
+ CalendarOperations_createCalendar: OperationHandler<import("../types.js").CalendarOperationIds>;
50
+ OrganizeJobDetailOperations_getOrganizeJob: OperationHandler<"OrganizeJobDetailOperations_getOrganizeJob", "accountFanout">;
51
+ OrganizeOperations_createOrganizeJob: OperationHandler<import("../types.js").OrganizeOperationIds, "accountFanout">;
52
+ OrganizeOperations_previewOrganize: OperationHandler<import("../types.js").OrganizeOperationIds, "accountFanout">;
53
+ LabelDetailOperations_getLabel: OperationHandler<import("../types.js").LabelDetailOperationIds>;
54
+ LabelDetailOperations_updateLabel: OperationHandler<import("../types.js").LabelDetailOperationIds>;
55
+ LabelDetailOperations_deleteLabel: OperationHandler<import("../types.js").LabelDetailOperationIds>;
56
+ LabelOperations_listLabels: OperationHandler<import("../types.js").LabelOperationIds>;
57
+ LabelOperations_createLabel: OperationHandler<import("../types.js").LabelOperationIds>;
58
+ FilterDetailOperations_getFilter: OperationHandler<import("../types.js").FilterDetailOperationIds, "accountFanout">;
59
+ FilterDetailOperations_updateFilter: OperationHandler<import("../types.js").FilterDetailOperationIds, "accountFanout">;
60
+ FilterDetailOperations_deleteFilter: OperationHandler<import("../types.js").FilterDetailOperationIds, "accountFanout">;
61
+ FilterOperations_listFilters: OperationHandler<import("../types.js").FilterOperationIds, "accountFanout">;
62
+ FilterOperations_createFilter: OperationHandler<import("../types.js").FilterOperationIds, "accountFanout">;
63
+ FolderRoleOperations_appointFolderRole: OperationHandler<"FolderRoleOperations_appointFolderRole">;
64
+ MailboxDetailOperations_getMailbox: OperationHandler<import("../types.js").MailboxDetailOperationIds, "sync">;
65
+ MailboxDetailOperations_renameMailbox: OperationHandler<import("../types.js").MailboxDetailOperationIds, "sync">;
66
+ MailboxDetailOperations_deleteMailbox: OperationHandler<import("../types.js").MailboxDetailOperationIds, "sync">;
67
+ MailboxOperations_listMailboxes: OperationHandler<import("../types.js").MailboxOperationIds, "sync">;
68
+ MailboxOperations_createMailbox: OperationHandler<import("../types.js").MailboxOperationIds, "sync">;
69
+ MicrosoftOAuthOperations_microsoftOAuthStart: OperationHandler<import("../types.js").MicrosoftOAuthOperationIds, "sync">;
70
+ AccountDetailOperations_updateAccount: OperationHandler<import("../types.js").AccountDetailOperationIds, "sync" | "accountFanout">;
71
+ AccountDetailOperations_deleteAccount: OperationHandler<import("../types.js").AccountDetailOperationIds, "sync" | "accountFanout">;
72
+ AccountOperations_createAccount: OperationHandler<import("../types.js").AccountOperationIds, "sync" | "accountFanout">;
73
+ AccountOperations_testConnection: OperationHandler<import("../types.js").AccountOperationIds, "sync" | "accountFanout">;
74
+ SystemOperations_getSystemUpdate: OperationHandler<import("../types.js").SystemOperationIds>;
75
+ SystemOperations_applySystemUpdate: OperationHandler<import("../types.js").SystemOperationIds>;
76
+ ConfigOperations_getConfig: OperationHandler<import("../types.js").ConfigOperationIds, "sync">;
77
+ ConfigOperations_exportConfig: OperationHandler<import("../types.js").ConfigOperationIds, "sync">;
78
+ ConfigOperations_importConfig: OperationHandler<import("../types.js").ConfigOperationIds, "sync">;
79
+ MeOperations_deleteMe: OperationHandler<import("../types.js").MeOperationIds, "accountFanout">;
80
+ MeOperations_createExport: OperationHandler<import("../types.js").MeOperationIds, "accountFanout">;
81
+ MeOperations_getExport: OperationHandler<import("../types.js").MeOperationIds, "accountFanout">;
82
+ MeOperations_listQuarantine: OperationHandler<import("../types.js").MeOperationIds, "accountFanout">;
83
+ MeOperations_listVipSuggestions: OperationHandler<import("../types.js").MeOperationIds, "accountFanout">;
84
+ };
85
+ export declare const publicHandlers: {
86
+ MicrosoftOAuthOperations_microsoftOAuthCallback: PublicOperationHandler<"sync">;
87
+ CalendarFeedOperations_getCalendarFeedIcal: PublicOperationHandler;
88
+ };
@@ -0,0 +1,62 @@
1
+ import { AccountDetailOperations, AccountOperations } from "./account.js";
2
+ import { MicrosoftOAuthOperations, microsoftOAuthCallback, } from "./account-oauth.js";
3
+ import { AddressDetailOperations, AddressOperations } from "./address.js";
4
+ import { CalendarDetailOperations, CalendarOperations } from "./calendar.js";
5
+ import { CalendarEventDetailOperations, CalendarEventOperations, CalendarFreeBusyOperations, } from "./calendar-event.js";
6
+ import { CalendarFeedDetailOperations, getCalendarFeedIcal, } from "./calendar-feed.js";
7
+ import { CalendarSuggestionActionOperations, CalendarSuggestionOperations, MessageCalendarSuggestionOperations, } from "./calendar-suggestion.js";
8
+ import { ConfigOperations } from "./config.js";
9
+ import { FilterDetailOperations, FilterOperations } from "./filter.js";
10
+ import { FolderRoleOperations } from "./folder-role.js";
11
+ import { LabelDetailOperations, LabelOperations } from "./label.js";
12
+ import { MailboxDetailOperations, MailboxOperations, TrashOperations, } from "./mailbox.js";
13
+ import { MeOperations } from "./me.js";
14
+ import { MessageBulkOperations, MessageOperations } from "./message.js";
15
+ import { OrganizeJobDetailOperations, OrganizeOperations } from "./organize.js";
16
+ import { OutboxAttachmentOperations, OutboxDetailOperations, OutboxOperations, } from "./outbox.js";
17
+ import { SyncOperations } from "./sync.js";
18
+ import { SystemOperations } from "./system-update.js";
19
+ import { ThreadDetailOperations, ThreadOperations } from "./thread.js";
20
+ import { UnifiedThreadOperations } from "./unified-threads.js";
21
+ export const handlers = {
22
+ ...MeOperations,
23
+ ...ConfigOperations,
24
+ ...SystemOperations,
25
+ ...AccountOperations,
26
+ ...AccountDetailOperations,
27
+ ...MicrosoftOAuthOperations,
28
+ ...MailboxOperations,
29
+ ...MailboxDetailOperations,
30
+ ...FolderRoleOperations,
31
+ ...FilterOperations,
32
+ ...FilterDetailOperations,
33
+ ...LabelOperations,
34
+ ...LabelDetailOperations,
35
+ ...OrganizeOperations,
36
+ ...OrganizeJobDetailOperations,
37
+ ...CalendarOperations,
38
+ ...CalendarDetailOperations,
39
+ ...CalendarFeedDetailOperations,
40
+ ...CalendarEventOperations,
41
+ ...CalendarEventDetailOperations,
42
+ ...CalendarFreeBusyOperations,
43
+ ...TrashOperations,
44
+ ...SyncOperations,
45
+ ...ThreadDetailOperations,
46
+ ...UnifiedThreadOperations,
47
+ ...ThreadOperations,
48
+ ...MessageOperations,
49
+ ...MessageBulkOperations,
50
+ ...OutboxOperations,
51
+ ...OutboxDetailOperations,
52
+ ...OutboxAttachmentOperations,
53
+ ...AddressOperations,
54
+ ...AddressDetailOperations,
55
+ ...CalendarSuggestionOperations,
56
+ ...MessageCalendarSuggestionOperations,
57
+ ...CalendarSuggestionActionOperations,
58
+ };
59
+ export const publicHandlers = {
60
+ MicrosoftOAuthOperations_microsoftOAuthCallback: microsoftOAuthCallback,
61
+ CalendarFeedOperations_getCalendarFeedIcal: getCalendarFeedIcal,
62
+ };
@@ -0,0 +1,43 @@
1
+ import type { CreateLabelInput, FilterItem, LabelItem, UpdateLabelInput } from "@remit/data-ports";
2
+ import type { LabelDetailOperationIds, LabelOperationIds, OperationHandler } from "../types.js";
3
+ /**
4
+ * Minimal label-service surface the CRUD handlers need — declared as a `Pick`
5
+ * so tests can stub it without a live table.
6
+ */
7
+ export interface LabelCrudDeps {
8
+ label: {
9
+ create(input: CreateLabelInput): Promise<LabelItem>;
10
+ get(accountConfigId: string, labelId: string): Promise<LabelItem>;
11
+ update(accountConfigId: string, labelId: string, input: UpdateLabelInput): Promise<LabelItem>;
12
+ delete(accountConfigId: string, labelId: string): Promise<void>;
13
+ listPageByAccountConfig(accountConfigId: string, options?: {
14
+ limit?: number;
15
+ continuationToken?: string;
16
+ }): Promise<{
17
+ items: LabelItem[];
18
+ continuationToken: string | undefined;
19
+ }>;
20
+ };
21
+ filter: {
22
+ listByAccountConfig(accountConfigId: string): Promise<FilterItem[]>;
23
+ delete(accountConfigId: string, filterId: string): Promise<void>;
24
+ };
25
+ messageLabel: {
26
+ removeAllByLabelId(accountConfigId: string, labelId: string): Promise<void>;
27
+ };
28
+ }
29
+ /**
30
+ * Every filter in the account whose action applies this label (issue #26). The
31
+ * count backs `LabelResponse.filterCount`; the list backs the cascade delete.
32
+ */
33
+ export declare const findFiltersForLabel: (deps: Pick<LabelCrudDeps, "filter">, accountConfigId: string, labelId: string) => Promise<FilterItem[]>;
34
+ /**
35
+ * Delete a label and cascade in both directions (issue #26): every filter
36
+ * whose `actionLabelId` is this label is deleted outright — never left
37
+ * dangling, never blocking the delete — and every `MessageLabel` row for it is
38
+ * removed. The label row itself is deleted last so a failure mid-cascade never
39
+ * leaves the label gone while its filters or applied-to-messages still exist.
40
+ */
41
+ export declare const deleteLabelWithCascade: (deps: LabelCrudDeps, accountConfigId: string, labelId: string) => Promise<void>;
42
+ export declare const LabelOperations: Record<LabelOperationIds, OperationHandler<LabelOperationIds>>;
43
+ export declare const LabelDetailOperations: Record<LabelDetailOperationIds, OperationHandler<LabelDetailOperationIds>>;