@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,323 @@
1
+ import { DEFAULT_CALENDAR_URL_SEGMENT, isResolvableZone, prepareCalendarObject, provisionDefaultCalendar, readCalendarFeed, readSubscriptionUrl, writeCalendarFeed, } from "@remit/calendar-service";
2
+ import { normalizeCalendarUrlSegment } from "@remit/data-ports/id";
3
+ import { CalendarSource } from "@remit/domain-enums";
4
+ import { defaultErrorCode } from "../error.js";
5
+ export const refuseCalendar = (code, message) => ({ ok: false, error: { code, message } });
6
+ /**
7
+ * `CalendarRefusal.code` is this module's and `@remit/calendar-service`'s own
8
+ * routing token, in PascalCase; the API's `code` vocabulary is snake_case
9
+ * (issue #371). Derived rather than mapped by hand, so a refusal added to
10
+ * either producer reaches the wire under its own name instead of silently
11
+ * collapsing into the status-class code.
12
+ */
13
+ const wireCode = (code) => code.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
14
+ /**
15
+ * A 400 keeps the refusal's own code — `unknown_time_zone` and
16
+ * `url_segment_taken` are what a client branches on, and the status class alone
17
+ * would not distinguish them. A 404 and a 412 have nothing to add to their
18
+ * status, so they take the shared token.
19
+ */
20
+ export const badRequest = (error) => ({
21
+ statusCode: 400,
22
+ body: { code: wireCode(error.code), message: error.message },
23
+ });
24
+ export const notFound = (message) => ({
25
+ statusCode: 404,
26
+ body: { code: defaultErrorCode(404), message },
27
+ });
28
+ export const preconditionFailed = (message) => ({
29
+ statusCode: 412,
30
+ body: { code: defaultErrorCode(412), message },
31
+ });
32
+ /** The calendar half of the client, named so a handler takes only what it uses. */
33
+ export const calendarDepsOf = (client) => ({
34
+ calendarCollection: client.calendarCollection,
35
+ calendarObject: client.calendarObject,
36
+ calendarEventIndex: client.calendarEventIndex,
37
+ calendarFeedToken: client.calendarFeedToken,
38
+ calendarStore: client.calendarStore,
39
+ });
40
+ const toCalendarResponse = (item) => ({
41
+ calendarId: item.calendarId,
42
+ accountConfigId: item.accountConfigId,
43
+ urlSegment: item.urlSegment,
44
+ displayName: item.displayName,
45
+ color: item.color,
46
+ componentSet: item.componentSet,
47
+ source: item.source,
48
+ timezone: item.timezone,
49
+ syncSequence: item.syncSequence,
50
+ subscriptionUrl: item.subscriptionUrl,
51
+ subscriptionEnabled: item.subscriptionEnabled,
52
+ subscriptionCheckedAt: item.subscriptionCheckedAt,
53
+ subscriptionFetchedAt: item.subscriptionFetchedAt,
54
+ subscriptionError: item.subscriptionError,
55
+ createdAt: item.createdAt,
56
+ updatedAt: item.updatedAt,
57
+ });
58
+ /**
59
+ * Every collection the account config holds, provisioning the default one when
60
+ * it holds none.
61
+ *
62
+ * Safe to race with itself: `calendarId` is derived from the account config and
63
+ * the URL segment, so two first reads arriving together write the same row
64
+ * rather than two, and the loser's write is a no-op instead of a second
65
+ * calendar nobody asked for.
66
+ */
67
+ export const listCalendarsFor = async (deps, accountConfigId) => {
68
+ const existing = await deps.calendarCollection.listByAccountConfig(accountConfigId);
69
+ if (existing.length > 0)
70
+ return existing;
71
+ await provisionDefaultCalendar(deps.calendarStore, accountConfigId);
72
+ return deps.calendarCollection.listByAccountConfig(accountConfigId);
73
+ };
74
+ /** One of the caller's collections, or a refusal naming the one they asked for. */
75
+ export const findCalendarFor = async (deps, accountConfigId, calendarId) => {
76
+ const collections = await deps.calendarCollection.listByAccountConfig(accountConfigId);
77
+ const found = collections.find((collection) => collection.calendarId === calendarId);
78
+ if (!found) {
79
+ return refuseCalendar("NotFound", `no calendar ${calendarId} on this account`);
80
+ }
81
+ return { ok: true, value: found };
82
+ };
83
+ /**
84
+ * One of the caller's collections that a person may write events into. A
85
+ * subscribed collection holds what its feed holds: an edit made here would be
86
+ * overwritten by the next refresh, so it is refused rather than accepted and
87
+ * silently lost.
88
+ */
89
+ export const findWritableCalendarFor = async (deps, accountConfigId, calendarId) => {
90
+ const found = await findCalendarFor(deps, accountConfigId, calendarId);
91
+ if (!found.ok)
92
+ return found;
93
+ if (found.value.source === CalendarSource.Subscribed) {
94
+ return refuseCalendar("ReadOnlyCalendar", `"${found.value.displayName}" is subscribed to a feed and is read-only — change the event where the feed comes from`);
95
+ }
96
+ return found;
97
+ };
98
+ /**
99
+ * A collection's timezone is what every floating time in it is read in, so a
100
+ * name this server cannot resolve is not a cosmetic setting — it silently moves
101
+ * every all-day and unzoned event in the calendar. A Windows zone name, which
102
+ * is what a client that has not normalised its input sends, is refused here
103
+ * rather than stored and quietly read as UTC.
104
+ */
105
+ export const readCollectionTimezone = (timezone) => {
106
+ if (timezone === undefined || timezone === "")
107
+ return { ok: true, value: "" };
108
+ if (!isResolvableZone(timezone)) {
109
+ return refuseCalendar("UnknownTimeZone", `"${timezone}" is not a time zone this server can resolve — use an IANA name such as "Europe/Amsterdam"`);
110
+ }
111
+ return { ok: true, value: timezone };
112
+ };
113
+ /**
114
+ * Creates a collection subscribed to a feed. The feed is read before anything
115
+ * is written, so an address that cannot be fetched leaves no empty calendar
116
+ * behind; its events then land through the one write path, in the same unit as
117
+ * the collection itself.
118
+ */
119
+ const createSubscribedCalendarFor = async (deps, accountConfigId, input, collection, fetcher, now) => {
120
+ const url = readSubscriptionUrl(input.subscriptionUrl);
121
+ if (!url.ok)
122
+ return url;
123
+ const feed = await readCalendarFeed(url.value, fetcher);
124
+ if (!feed.ok) {
125
+ return refuseCalendar("SubscriptionUnreachable", `the calendar was not created: ${feed.reason}`);
126
+ }
127
+ const { repos } = deps.calendarStore;
128
+ const made = await repos.calendarCollection.createExclusive({
129
+ accountConfigId,
130
+ urlSegment: collection.urlSegment,
131
+ displayName: input.displayName,
132
+ color: input.color,
133
+ timezone: collection.timezone,
134
+ source: CalendarSource.Subscribed,
135
+ subscriptionUrl: url.value,
136
+ subscriptionEnabled: true,
137
+ });
138
+ if (!made) {
139
+ return refuseCalendar("UrlSegmentTaken", `"${collection.urlSegment}" already addresses a calendar on this account — pick another`);
140
+ }
141
+ // A separate step from the create: a collection the feed write never
142
+ // reached is enabled and never checked, so the scheduled refresh takes it
143
+ // on its next pass and fills it from the same feed.
144
+ await writeCalendarFeed(deps.calendarStore, { accountConfigId, calendarId: made.calendarId }, feed.value, now);
145
+ return {
146
+ ok: true,
147
+ value: await repos.calendarCollection.get(accountConfigId, made.calendarId),
148
+ };
149
+ };
150
+ export const createCalendarFor = async (deps, accountConfigId, input, fetcher = fetch, now = Date.now()) => {
151
+ const urlSegment = normalizeCalendarUrlSegment(input.urlSegment);
152
+ if (urlSegment === "") {
153
+ return refuseCalendar("InvalidUrlSegment", "a calendar needs a url segment to be addressed by");
154
+ }
155
+ const timezone = readCollectionTimezone(input.timezone);
156
+ if (!timezone.ok)
157
+ return timezone;
158
+ const { subscriptionUrl } = input;
159
+ if (subscriptionUrl !== undefined) {
160
+ return createSubscribedCalendarFor(deps, accountConfigId, { ...input, subscriptionUrl }, { urlSegment, timezone: timezone.value }, fetcher, now);
161
+ }
162
+ // The write decides, not a prior read: two creates of one segment arriving
163
+ // together would both find it free, and the loser would silently be handed
164
+ // the winner's calendar to write into.
165
+ const created = await deps.calendarStore.repos.calendarCollection.createExclusive({
166
+ accountConfigId,
167
+ urlSegment,
168
+ displayName: input.displayName,
169
+ color: input.color,
170
+ timezone: timezone.value,
171
+ source: CalendarSource.UserCreated,
172
+ });
173
+ if (!created) {
174
+ return refuseCalendar("UrlSegmentTaken", `"${urlSegment}" already addresses a calendar on this account — pick another`);
175
+ }
176
+ return { ok: true, value: created };
177
+ };
178
+ /**
179
+ * Removes a collection with everything in it, in one unit.
180
+ *
181
+ * The default collection stays: it is where an accepted invitation and a first
182
+ * event land, and an account config with no calendar has nowhere to put one.
183
+ */
184
+ export const deleteCalendarFor = async (deps, accountConfigId, calendarId) => {
185
+ const collection = await findCalendarFor(deps, accountConfigId, calendarId);
186
+ if (!collection.ok)
187
+ return collection;
188
+ if (collection.value.source === CalendarSource.Default) {
189
+ return refuseCalendar("DefaultCalendarUndeletable", `"${DEFAULT_CALENDAR_URL_SEGMENT}" is the calendar this account files events into and cannot be removed`);
190
+ }
191
+ await deps.calendarStore.commit([
192
+ { kind: "DeleteCollection", accountConfigId, calendarId },
193
+ ]);
194
+ return { ok: true, value: null };
195
+ };
196
+ /**
197
+ * Reduce a PATCH body to the fields a collection update may set. `urlSegment`
198
+ * is deliberately absent: it is the collection's identity and the path a client
199
+ * has bookmarked, so moving it is making a different calendar.
200
+ */
201
+ export const pickCalendarUpdate = (body) => {
202
+ const patch = {};
203
+ if (Object.hasOwn(body, "displayName"))
204
+ patch.displayName = body.displayName;
205
+ if (Object.hasOwn(body, "color"))
206
+ patch.color = body.color;
207
+ if (Object.hasOwn(body, "timezone"))
208
+ patch.timezone = body.timezone;
209
+ if (Object.hasOwn(body, "subscriptionEnabled")) {
210
+ patch.subscriptionEnabled = body.subscriptionEnabled;
211
+ }
212
+ return patch;
213
+ };
214
+ /**
215
+ * Applies a collection patch, rewriting what the collection's timezone decides.
216
+ *
217
+ * The timezone is not a label. Every floating and all-day time in the
218
+ * collection is read in it, so changing it moves every occurrence row those
219
+ * resources produced — and a row left at the old zone is an event drawn hours
220
+ * from where the calendar now says it is. Each resource is therefore written
221
+ * again from its own stored bytes, which re-projects and re-expands it and
222
+ * bumps the collection's sequence so a syncing client sees the change. The
223
+ * whole set is one unit: a half-converted calendar is worse than either zone.
224
+ */
225
+ export const updateCalendarFor = async (deps, accountConfigId, calendarId, body) => {
226
+ const current = await findCalendarFor(deps, accountConfigId, calendarId);
227
+ if (!current.ok)
228
+ return current;
229
+ const patch = pickCalendarUpdate(body);
230
+ if (patch.subscriptionEnabled !== undefined &&
231
+ current.value.source !== CalendarSource.Subscribed) {
232
+ return refuseCalendar("NotSubscribed", `"${current.value.displayName}" is not subscribed to a feed, so there is no refresh to turn on or off`);
233
+ }
234
+ if (patch.timezone !== undefined) {
235
+ const timezone = readCollectionTimezone(patch.timezone);
236
+ if (!timezone.ok)
237
+ return timezone;
238
+ patch.timezone = timezone.value;
239
+ }
240
+ const rezone = patch.timezone !== undefined && patch.timezone !== current.value.timezone;
241
+ const { repos } = deps.calendarStore;
242
+ const rewrites = [];
243
+ if (rezone) {
244
+ const zone = { timezone: patch.timezone ?? current.value.timezone };
245
+ for (const object of await repos.calendarObject.listByCalendar(calendarId)) {
246
+ const rewritten = await prepareCalendarObject(zone, {
247
+ accountConfigId,
248
+ calendarId,
249
+ resourceName: object.resourceName,
250
+ icalData: object.icalData,
251
+ });
252
+ if (!rewritten.ok) {
253
+ throw new Error(`stored calendar object ${object.calendarObjectId} was refused on re-expansion: ${rewritten.error.code}`);
254
+ }
255
+ rewrites.push({
256
+ ...rewritten.value,
257
+ kind: "ReprojectObject",
258
+ readEtag: object.etag,
259
+ });
260
+ }
261
+ }
262
+ await deps.calendarStore.commit([
263
+ { kind: "UpdateCollection", accountConfigId, calendarId, patch },
264
+ ...rewrites,
265
+ ]);
266
+ return {
267
+ ok: true,
268
+ value: await repos.calendarCollection.get(accountConfigId, calendarId),
269
+ };
270
+ };
271
+ export const CalendarOperations = {
272
+ CalendarOperations_listCalendars: async (_context, ctx) => {
273
+ const accountConfigId = ctx.identity.accountConfigId;
274
+ const deps = calendarDepsOf(ctx.client);
275
+ const items = await listCalendarsFor(deps, accountConfigId);
276
+ return { items: items.map(toCalendarResponse) };
277
+ },
278
+ CalendarOperations_createCalendar: async (context, ctx) => {
279
+ const accountConfigId = ctx.identity.accountConfigId;
280
+ const input = context.request.requestBody;
281
+ const deps = calendarDepsOf(ctx.client);
282
+ const created = await createCalendarFor(deps, accountConfigId, input);
283
+ if (!created.ok)
284
+ return badRequest(created.error);
285
+ return toCalendarResponse(created.value);
286
+ },
287
+ };
288
+ export const CalendarDetailOperations = {
289
+ CalendarDetailOperations_getCalendar: async (context, ctx) => {
290
+ const accountConfigId = ctx.identity.accountConfigId;
291
+ const { calendarId } = context.request.params;
292
+ const deps = calendarDepsOf(ctx.client);
293
+ const found = await findCalendarFor(deps, accountConfigId, calendarId);
294
+ if (!found.ok)
295
+ return notFound(found.error.message);
296
+ return toCalendarResponse(found.value);
297
+ },
298
+ CalendarDetailOperations_updateCalendar: async (context, ctx) => {
299
+ const accountConfigId = ctx.identity.accountConfigId;
300
+ const { calendarId } = context.request.params;
301
+ const body = context.request.requestBody;
302
+ const deps = calendarDepsOf(ctx.client);
303
+ const updated = await updateCalendarFor(deps, accountConfigId, calendarId, body);
304
+ if (!updated.ok) {
305
+ return updated.error.code === "NotFound"
306
+ ? notFound(updated.error.message)
307
+ : badRequest(updated.error);
308
+ }
309
+ return toCalendarResponse(updated.value);
310
+ },
311
+ CalendarDetailOperations_deleteCalendar: async (context, ctx) => {
312
+ const accountConfigId = ctx.identity.accountConfigId;
313
+ const { calendarId } = context.request.params;
314
+ const deps = calendarDepsOf(ctx.client);
315
+ const removed = await deleteCalendarFor(deps, accountConfigId, calendarId);
316
+ if (!removed.ok) {
317
+ return removed.error.code === "NotFound"
318
+ ? notFound(removed.error.message)
319
+ : badRequest(removed.error);
320
+ }
321
+ return { statusCode: 204 };
322
+ },
323
+ };
@@ -0,0 +1,43 @@
1
+ import type { FifoQueueProducer } from "@remit/data-ports";
2
+ import { type StoredCredentialFields } from "@remit/mailbox-service/account-credentials";
3
+ import { type SyncMailboxesEvent } from "../service/trigger-sync.js";
4
+ import type { ConfigOperationIds, OperationHandler } from "../types.js";
5
+ type StructuredLog = (fields: Record<string, unknown>, message: string) => void;
6
+ interface ConfigSyncTriggerDeps {
7
+ queue: FifoQueueProducer<SyncMailboxesEvent>;
8
+ logger: {
9
+ info: StructuredLog;
10
+ error: StructuredLog;
11
+ };
12
+ }
13
+ /**
14
+ * Fire-and-forget sync trigger for the accounts surfaced by GET /config.
15
+ *
16
+ * GET /config is a READ: its response is already computed and does not depend
17
+ * on the trigger succeeding. A failure here (the SQS queue unreachable in
18
+ * smoke/e2e, an IAM/SQS misconfig in prod) must therefore never reach the read
19
+ * response — but it also silently stops ALL sync, so it has to be loud and
20
+ * alertable rather than swallowed.
21
+ *
22
+ * This helper is fully self-contained: it catches every per-account rejection
23
+ * internally and resolves to void, so the caller can `void`-fire it with no
24
+ * chance of an unhandled rejection escaping. The dev/Lambda runtime shares one
25
+ * event loop, so an escaped rejection lands on whatever request is active when
26
+ * the deferred SQS retry finally fails — which is how a `/config` enqueue
27
+ * failure ended up 500-ing unrelated reads like `/outbox` and `/threads`.
28
+ *
29
+ * Each failure is logged as a distinct structured error carrying the SDK error
30
+ * name/code on dedicated fields plus a stable `alert: "sync_trigger_failed"`
31
+ * discriminator a CloudWatch metric filter / alarm can key off.
32
+ *
33
+ * An account storing no credential is not enqueued at all (issue #1120): the
34
+ * import wizard lands accounts without a password by design, and the client
35
+ * polls this read while the user is still typing one. The guard is the stored
36
+ * credential rather than `connectionState`, which stays `credentials_missing`
37
+ * until a connect succeeds — see `hasStoredCredential`.
38
+ */
39
+ export declare const triggerConfigLoadSyncs: (accountConfigId: string, accounts: ReadonlyArray<{
40
+ accountId: string;
41
+ } & StoredCredentialFields>, deps: ConfigSyncTriggerDeps) => Promise<void>;
42
+ export declare const ConfigOperations: Record<ConfigOperationIds, OperationHandler<ConfigOperationIds, "sync">>;
43
+ export {};
@@ -0,0 +1,164 @@
1
+ import { importConfig, pendingImportOf, readConfigForExport, } from "@remit/config-transfer";
2
+ import { ConfigNotEmptyError, NotFoundError } from "@remit/data-ports/errors";
3
+ import { logger } from "@remit/logger";
4
+ import { hasStoredCredential, } from "@remit/mailbox-service/account-credentials";
5
+ import { exportIdentity } from "../service/export-identity.js";
6
+ import { fireAndForget } from "../service/fire-and-forget.js";
7
+ import { triggerAccountSync, } from "../service/trigger-sync.js";
8
+ import { toAccountResponse } from "./account-guards.js";
9
+ import { groupAccountOverrides, } from "./account-overrides.js";
10
+ import { groupSignaturesByAccount, } from "./account-signature.js";
11
+ import { groupFolderAppointmentsByAccount, resolveFolderAppointments, writeFolderRoleAppointment, } from "./folder-role-appointments.js";
12
+ /**
13
+ * Fire-and-forget sync trigger for the accounts surfaced by GET /config.
14
+ *
15
+ * GET /config is a READ: its response is already computed and does not depend
16
+ * on the trigger succeeding. A failure here (the SQS queue unreachable in
17
+ * smoke/e2e, an IAM/SQS misconfig in prod) must therefore never reach the read
18
+ * response — but it also silently stops ALL sync, so it has to be loud and
19
+ * alertable rather than swallowed.
20
+ *
21
+ * This helper is fully self-contained: it catches every per-account rejection
22
+ * internally and resolves to void, so the caller can `void`-fire it with no
23
+ * chance of an unhandled rejection escaping. The dev/Lambda runtime shares one
24
+ * event loop, so an escaped rejection lands on whatever request is active when
25
+ * the deferred SQS retry finally fails — which is how a `/config` enqueue
26
+ * failure ended up 500-ing unrelated reads like `/outbox` and `/threads`.
27
+ *
28
+ * Each failure is logged as a distinct structured error carrying the SDK error
29
+ * name/code on dedicated fields plus a stable `alert: "sync_trigger_failed"`
30
+ * discriminator a CloudWatch metric filter / alarm can key off.
31
+ *
32
+ * An account storing no credential is not enqueued at all (issue #1120): the
33
+ * import wizard lands accounts without a password by design, and the client
34
+ * polls this read while the user is still typing one. The guard is the stored
35
+ * credential rather than `connectionState`, which stays `credentials_missing`
36
+ * until a connect succeeds — see `hasStoredCredential`.
37
+ */
38
+ export const triggerConfigLoadSyncs = async (accountConfigId, accounts, deps) => {
39
+ await Promise.all(accounts.filter(hasStoredCredential).map(({ accountId }) => fireAndForget(async () => {
40
+ const { eventId } = await triggerAccountSync({
41
+ queue: deps.queue,
42
+ accountId,
43
+ });
44
+ deps.logger.info({ accountId, eventId }, "Sync triggered on config load");
45
+ }, {
46
+ source: "config_load",
47
+ message: "Failed to trigger account sync on config load",
48
+ ids: { accountId, accountConfigId },
49
+ logger: deps.logger,
50
+ })));
51
+ };
52
+ const toAccountConfigResponse = (config) => ({
53
+ accountConfigId: config.accountConfigId,
54
+ userId: config.userId,
55
+ name: config.name,
56
+ state: (config.state ??
57
+ "active"),
58
+ createdAt: config.createdAt,
59
+ updatedAt: config.updatedAt,
60
+ });
61
+ /**
62
+ * Returned by GET /config when no AccountConfig row exists yet for this user.
63
+ * GET must never mutate state, so instead of creating a row we synthesize a
64
+ * stable, empty shape the frontend can render as a "no accounts yet" state.
65
+ * The POST account-creation flow will materialize the real row when the user
66
+ * adds their first account.
67
+ */
68
+ const emptyConfigResponse = (accountConfigId, userId, commit) => {
69
+ const now = Date.now();
70
+ return {
71
+ accountConfig: {
72
+ accountConfigId,
73
+ userId,
74
+ state: "active",
75
+ createdAt: now,
76
+ updatedAt: now,
77
+ },
78
+ accounts: [],
79
+ buildCommit: commit,
80
+ };
81
+ };
82
+ export const ConfigOperations = {
83
+ ConfigOperations_getConfig: async (_context, ctx) => {
84
+ const accountConfigId = ctx.identity.accountConfigId;
85
+ const client = ctx.client;
86
+ const description = await client.accountConfig
87
+ .describe(accountConfigId)
88
+ .catch((err) => {
89
+ if (err instanceof NotFoundError)
90
+ return undefined;
91
+ throw err;
92
+ });
93
+ if (!description || description.accountConfig.length === 0) {
94
+ return emptyConfigResponse(accountConfigId, ctx.identity.sub, ctx.config.commit);
95
+ }
96
+ const accountConfig = description.accountConfig[0];
97
+ if (!accountConfig) {
98
+ return emptyConfigResponse(accountConfigId, ctx.identity.sub, ctx.config.commit);
99
+ }
100
+ // Filter out deleted accounts (tombstone pattern)
101
+ const activeAccounts = description.account.filter((acc) => acc.deletedAt === undefined);
102
+ // Signatures and the display-name/mute overrides are stored per-account in
103
+ // AccountSetting rows (RFC 032). Load the whole set for this config once and
104
+ // key both by accountId so the account mapping below surfaces each without
105
+ // an N+1. The per-account folder-role map (RFC 032
106
+ // exclusive-folder-appointment, #976) rides the same settings rows, grouped
107
+ // the same way.
108
+ const allSettings = await client.accountSetting.listByAccountConfig(accountConfigId);
109
+ const signaturesByAccount = groupSignaturesByAccount(allSettings);
110
+ const overridesByAccount = groupAccountOverrides(allSettings);
111
+ const appointmentsByAccount = groupFolderAppointmentsByAccount(allSettings);
112
+ const signatureOf = (accountId) => signaturesByAccount.get(accountId) ?? {};
113
+ const overridesOf = (accountId) => overridesByAccount.get(accountId) ?? {};
114
+ // One mailbox list per account, fetched in parallel: `findFolderForRole`
115
+ // needs each account's folders to fill any role the user hasn't appointed
116
+ // yet (RFC 032: "the map is never empty for a normal provider").
117
+ const mailboxesByAccount = new Map(await Promise.all(activeAccounts.map(async (acc) => [
118
+ acc.accountId,
119
+ await client.mailbox.listAllByAccount(acc.accountId),
120
+ ])));
121
+ // Fire-and-forget: a failed sync enqueue must never fail this read.
122
+ // triggerConfigLoadSyncs swallows nothing — it logs each failure loudly
123
+ // with an alertable structured field — but it also never rejects, so the
124
+ // `void` here cannot leak an unhandled rejection into a later request.
125
+ void triggerConfigLoadSyncs(accountConfigId, activeAccounts, {
126
+ queue: ctx.client.queues.sync,
127
+ logger,
128
+ });
129
+ // An import that named folders IMAP had not produced yet rides the config
130
+ // read rather than a route of its own, so nothing has to poll for it.
131
+ const pendingImport = pendingImportOf(await client.configImport.listByAccountConfig(accountConfigId));
132
+ return {
133
+ accountConfig: toAccountConfigResponse(accountConfig),
134
+ ...(pendingImport ? { pendingImport } : {}),
135
+ buildCommit: ctx.config.commit,
136
+ accounts: activeAccounts.map((acc) => toAccountResponse(acc, signatureOf(acc.accountId), overridesOf(acc.accountId), resolveFolderAppointments(appointmentsByAccount.get(acc.accountId) ?? new Map(), mailboxesByAccount.get(acc.accountId) ?? []))),
137
+ };
138
+ },
139
+ ConfigOperations_exportConfig: async (_context, ctx) => {
140
+ const accountConfigId = ctx.identity.accountConfigId;
141
+ const client = ctx.client;
142
+ const document = await readConfigForExport(client, accountConfigId, exportIdentity(ctx.config));
143
+ return { schemaVersion: document.schemaVersion, document };
144
+ },
145
+ ConfigOperations_importConfig: async (context, ctx) => {
146
+ const accountConfigId = ctx.identity.accountConfigId;
147
+ const body = (context.request.requestBody ?? {});
148
+ const client = ctx.client;
149
+ const outcome = await importConfig({
150
+ repositories: client,
151
+ appointFolderRole: (configId, accountId, role, mailboxId, lastKnownPath) => writeFolderRoleAppointment(client.accountSetting, configId, accountId, role, mailboxId, lastKnownPath),
152
+ }, {
153
+ accountConfigId,
154
+ userId: ctx.identity.sub,
155
+ document: body.document,
156
+ mode: body.mode ?? "validate",
157
+ onExisting: body.onExisting ?? "abort",
158
+ });
159
+ if (outcome.outcome === "conflict") {
160
+ throw new ConfigNotEmptyError(outcome.conflict.message, outcome.conflict.details);
161
+ }
162
+ return outcome.report;
163
+ },
164
+ };
@@ -0,0 +1,9 @@
1
+ import type { IAccountConfigRepository } from "@remit/data-ports";
2
+ /**
3
+ * Ensure an AccountConfig row exists for the given id. A first-time caller
4
+ * coming from Cognito will not yet have one; subsequent calls are idempotent.
5
+ *
6
+ * We attempt a read first to avoid relying on a race on `create()` — the
7
+ * deterministic id (derived from Cognito `sub`) makes both paths safe.
8
+ */
9
+ export declare const ensureAccountConfig: (accountConfig: IAccountConfigRepository, accountConfigId: string) => Promise<void>;
@@ -0,0 +1,27 @@
1
+ import { ConflictError, NotFoundError } from "@remit/data-ports/errors";
2
+ /**
3
+ * Ensure an AccountConfig row exists for the given id. A first-time caller
4
+ * coming from Cognito will not yet have one; subsequent calls are idempotent.
5
+ *
6
+ * We attempt a read first to avoid relying on a race on `create()` — the
7
+ * deterministic id (derived from Cognito `sub`) makes both paths safe.
8
+ */
9
+ export const ensureAccountConfig = async (accountConfig, accountConfigId) => {
10
+ const existing = await accountConfig.get(accountConfigId).catch((err) => {
11
+ if (err instanceof NotFoundError)
12
+ return undefined;
13
+ throw err;
14
+ });
15
+ if (existing)
16
+ return;
17
+ await accountConfig
18
+ .create({
19
+ accountConfigId,
20
+ userId: accountConfigId,
21
+ })
22
+ .catch((err) => {
23
+ if (err instanceof ConflictError)
24
+ return;
25
+ throw err;
26
+ });
27
+ };
@@ -0,0 +1,3 @@
1
+ import type { FilterDetailOperationIds, FilterOperationIds, OperationHandler } from "../types.js";
2
+ export declare const FilterOperations: Record<FilterOperationIds, OperationHandler<FilterOperationIds, "accountFanout">>;
3
+ export declare const FilterDetailOperations: Record<FilterDetailOperationIds, OperationHandler<FilterDetailOperationIds, "accountFanout">>;
@@ -0,0 +1,88 @@
1
+ import { logger } from "@remit/logger";
2
+ import { createFilter, listFilters, ownedAccount, updateFilter, } from "@remit/mailbox-service";
3
+ import { unwrap } from "../service/refusal.js";
4
+ const toFilterResponse = (item) => ({
5
+ filterId: item.filterId,
6
+ accountConfigId: item.accountConfigId,
7
+ name: item.name,
8
+ scope: item.scope,
9
+ expiresAt: item.expiresAt,
10
+ state: item.state,
11
+ disabledReason: item.disabledReason,
12
+ ruleChangedAt: item.ruleChangedAt,
13
+ actionChangedAt: item.actionChangedAt,
14
+ matchOperator: item.matchOperator,
15
+ literalClauses: item.literalClauses,
16
+ actionLabelId: item.actionLabelId,
17
+ actionMailboxId: item.actionMailboxId,
18
+ createdAt: item.createdAt,
19
+ updatedAt: item.updatedAt,
20
+ });
21
+ export const FilterOperations = {
22
+ FilterOperations_listFilters: async (context, ctx) => {
23
+ const accountConfigId = ctx.identity.accountConfigId;
24
+ const { accountId } = context.request.params;
25
+ const { continuationToken } = context.request.query;
26
+ const page = unwrap(await listFilters(ctx.client, accountConfigId, {
27
+ accountId,
28
+ continuationToken,
29
+ }));
30
+ return {
31
+ items: page.items.map(toFilterResponse),
32
+ continuationToken: page.continuationToken,
33
+ };
34
+ },
35
+ FilterOperations_createFilter: async (context, ctx) => {
36
+ const accountConfigId = ctx.identity.accountConfigId;
37
+ const { accountId } = context.request.params;
38
+ const filter = context.request.requestBody;
39
+ const userId = ctx.identity.sub;
40
+ const client = ctx.client;
41
+ const created = unwrap(await createFilter({
42
+ account: client.account,
43
+ mailbox: client.mailbox,
44
+ filter: client.filter,
45
+ organizeJobRequest: client.organizeJobRequest,
46
+ queue: client.queues.accountFanout,
47
+ logger,
48
+ }, { accountConfigId, userId }, { accountId, filter }));
49
+ return {
50
+ ...toFilterResponse(created.filter),
51
+ organizeJobId: created.organizeJob.organizeJobId,
52
+ };
53
+ },
54
+ };
55
+ export const FilterDetailOperations = {
56
+ FilterDetailOperations_getFilter: async (context, ctx) => {
57
+ const accountConfigId = ctx.identity.accountConfigId;
58
+ const { accountId, filterId } = context.request.params;
59
+ const client = ctx.client;
60
+ const account = await client.account.get(accountId);
61
+ unwrap(ownedAccount(account, accountConfigId, "read"));
62
+ const { filter } = client;
63
+ const item = await filter.get(accountConfigId, filterId);
64
+ const refreshed = await filter.refreshExpiry(item);
65
+ return toFilterResponse(refreshed);
66
+ },
67
+ FilterDetailOperations_updateFilter: async (context, ctx) => {
68
+ const accountConfigId = ctx.identity.accountConfigId;
69
+ const { accountId, filterId } = context.request.params;
70
+ const patch = context.request.requestBody;
71
+ const updated = await updateFilter(ctx.client, accountConfigId, {
72
+ accountId,
73
+ filterId,
74
+ patch,
75
+ });
76
+ return toFilterResponse(unwrap(updated));
77
+ },
78
+ FilterDetailOperations_deleteFilter: async (context, ctx) => {
79
+ const accountConfigId = ctx.identity.accountConfigId;
80
+ const { accountId, filterId } = context.request.params;
81
+ const client = ctx.client;
82
+ const account = await client.account.get(accountId);
83
+ unwrap(ownedAccount(account, accountConfigId, "act"));
84
+ const { filter } = client;
85
+ await filter.delete(accountConfigId, filterId);
86
+ return { statusCode: 204 };
87
+ },
88
+ };