@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
@@ -1,291 +0,0 @@
1
- import type {
2
- CalendarFeedResponse,
3
- CalendarFeedStateResponse,
4
- } from "@remit/api-openapi-types";
5
- import {
6
- buildCalendarFeed,
7
- calendarFeedIsUnchanged,
8
- calendarFeedIsUnmodifiedSince,
9
- hashCalendarFeedToken,
10
- isCalendarFeedToken,
11
- mintCalendarFeedToken,
12
- readCalendarFeedToken,
13
- } from "@remit/calendar-service";
14
- import type { CalendarFeedTokenItem } from "@remit/data-ports";
15
- import { NotFoundError } from "@remit/data-ports/errors";
16
- import type { APIGatewayProxyEvent } from "aws-lambda";
17
- import { getAccountConfigIdFromEvent } from "../auth.js";
18
- import { type RawApiResponse, rawApiResponse } from "../response.js";
19
- import { getClient } from "../service/data-client.js";
20
- import type {
21
- CalendarDetailOperationIds,
22
- CalendarFeedDetailOperationIds,
23
- CalendarFeedOperationIds,
24
- OperationHandler,
25
- } from "../types.js";
26
- import {
27
- type CalendarDeps,
28
- type CalendarOutcome,
29
- calendarDepsOf,
30
- findCalendarFor,
31
- notFound,
32
- refuseCalendar,
33
- } from "./calendar.js";
34
-
35
- const toFeedState = (
36
- token: CalendarFeedTokenItem,
37
- ): CalendarFeedStateResponse => ({
38
- calendarId: token.calendarId,
39
- createdAt: token.createdAt,
40
- rotatedAt: token.rotatedAt,
41
- });
42
-
43
- /**
44
- * Mints the calendar's feed address, or replaces the one it has.
45
- *
46
- * The plaintext exists here and nowhere else: the store keeps a digest, so this
47
- * return value is the only chance anybody has to read the token. Ownership is
48
- * settled before the mint — a calendar the caller does not hold is absent, not
49
- * forbidden, which is the same answer `getCalendar` gives it.
50
- */
51
- export const putCalendarFeedFor = async (
52
- deps: CalendarDeps,
53
- accountConfigId: string,
54
- calendarId: string,
55
- ): Promise<CalendarOutcome<CalendarFeedResponse>> => {
56
- const calendar = await findCalendarFor(deps, accountConfigId, calendarId);
57
- if (!calendar.ok) return calendar;
58
-
59
- const secret = mintCalendarFeedToken();
60
- const stored = await deps.calendarFeedToken.put({
61
- accountConfigId,
62
- calendarId,
63
- tokenHash: secret.tokenHash,
64
- });
65
-
66
- return {
67
- ok: true,
68
- value: {
69
- calendarId: stored.calendarId,
70
- feedToken: secret.token,
71
- createdAt: stored.createdAt,
72
- rotatedAt: stored.rotatedAt,
73
- },
74
- };
75
- };
76
-
77
- /** Whether the calendar has a feed address, and how old it is. */
78
- export const findCalendarFeedFor = async (
79
- deps: CalendarDeps,
80
- accountConfigId: string,
81
- calendarId: string,
82
- ): Promise<CalendarOutcome<CalendarFeedStateResponse>> => {
83
- const calendar = await findCalendarFor(deps, accountConfigId, calendarId);
84
- if (!calendar.ok) return calendar;
85
-
86
- const stored = await deps.calendarFeedToken.findByCalendar(
87
- accountConfigId,
88
- calendarId,
89
- );
90
- if (!stored) {
91
- return refuseCalendar("NotFound", `no feed on calendar ${calendarId}`);
92
- }
93
- return { ok: true, value: toFeedState(stored) };
94
- };
95
-
96
- /**
97
- * Revokes the calendar's feed address.
98
- *
99
- * A calendar with no feed is refused rather than answered 204: the caller asked
100
- * for a subscription to stop working, and reporting success for one that was
101
- * never there reads as confirmation that it has.
102
- */
103
- export const revokeCalendarFeedFor = async (
104
- deps: CalendarDeps,
105
- accountConfigId: string,
106
- calendarId: string,
107
- ): Promise<CalendarOutcome<null>> => {
108
- const calendar = await findCalendarFor(deps, accountConfigId, calendarId);
109
- if (!calendar.ok) return calendar;
110
-
111
- const stored = await deps.calendarFeedToken.findByCalendar(
112
- accountConfigId,
113
- calendarId,
114
- );
115
- if (!stored) {
116
- return refuseCalendar("NotFound", `no feed on calendar ${calendarId}`);
117
- }
118
-
119
- await deps.calendarFeedToken.delete(accountConfigId, calendarId);
120
- return { ok: true, value: null };
121
- };
122
-
123
- /**
124
- * No feed answers to this address.
125
- *
126
- * One answer for an unknown token, a revoked one and a malformed one, with a
127
- * body that says the same thing to all three: a caller probing addresses learns
128
- * only whether the one it sent works, which is what it was going to find out
129
- * anyway.
130
- */
131
- const feedNotFound = (): RawApiResponse =>
132
- rawApiResponse({
133
- statusCode: 404,
134
- headers: { "Content-Type": "text/plain; charset=utf-8" },
135
- body: "no calendar feed at this address\n",
136
- });
137
-
138
- /**
139
- * Serves a calendar to whoever holds its secret address.
140
- *
141
- * The token is the whole credential, so a value that cannot be one is refused
142
- * before anything is hashed, and the digest of what arrived is what the store is
143
- * asked about — the plaintext is never compared against a stored one because
144
- * none is stored.
145
- *
146
- * `Last-Modified` is the collection's own timestamp, not the newest event in
147
- * it: an event deleted from a calendar leaves every survivor older than the
148
- * change, and a validator that moves backwards tells a subscriber its cached
149
- * copy is still good. The collection is stamped by the same sequence bump every
150
- * write and every delete goes through, so it only ever moves forward.
151
- *
152
- * A row whose collection is gone is the same 404. It should not exist — a
153
- * calendar's delete takes its token with it, in one transaction — and serving a
154
- * blank calendar for one would be worse than saying nothing.
155
- */
156
- export const serveCalendarFeed = async (
157
- deps: CalendarDeps,
158
- feedToken: string,
159
- conditions: {
160
- ifNoneMatch: string | undefined;
161
- ifModifiedSince: string | undefined;
162
- },
163
- ): Promise<RawApiResponse> => {
164
- if (!isCalendarFeedToken(feedToken)) return feedNotFound();
165
-
166
- const stored = await deps.calendarFeedToken.findByTokenHash(
167
- hashCalendarFeedToken(feedToken),
168
- );
169
- if (!stored) return feedNotFound();
170
-
171
- const collection = await deps.calendarCollection
172
- .get(stored.accountConfigId, stored.calendarId)
173
- .catch((error: unknown) => {
174
- if (error instanceof NotFoundError) return null;
175
- throw error;
176
- });
177
- if (!collection) return feedNotFound();
178
-
179
- const objects = await deps.calendarObject.listByCalendar(stored.calendarId);
180
- const feed = buildCalendarFeed(collection, objects);
181
- const etag = `"${feed.etag}"`;
182
- const lastModified = new Date(collection.updatedAt).toUTCString();
183
-
184
- // `If-None-Match` wins outright when both arrive (RFC 9110 13.2.2): the tag
185
- // is exact where the date is truncated to the second, so honouring the date
186
- // as well could only turn a 200 the tag asked for into a 304.
187
- const unchanged =
188
- conditions.ifNoneMatch === undefined
189
- ? calendarFeedIsUnmodifiedSince(
190
- conditions.ifModifiedSince,
191
- collection.updatedAt,
192
- )
193
- : calendarFeedIsUnchanged(conditions.ifNoneMatch, feed.etag);
194
-
195
- if (unchanged) {
196
- return rawApiResponse({
197
- statusCode: 304,
198
- headers: { ETag: etag, "Last-Modified": lastModified },
199
- body: "",
200
- });
201
- }
202
-
203
- return rawApiResponse({
204
- statusCode: 200,
205
- headers: {
206
- "Content-Type": "text/calendar; charset=utf-8",
207
- ETag: etag,
208
- "Last-Modified": lastModified,
209
- },
210
- body: feed.icalData,
211
- });
212
- };
213
-
214
- export const CalendarFeedDetailOperations: Record<
215
- CalendarFeedDetailOperationIds,
216
- OperationHandler<CalendarDetailOperationIds>
217
- > = {
218
- CalendarDetailOperations_getCalendarFeed: async (
219
- context,
220
- ...args: unknown[]
221
- ) => {
222
- const event = args[0] as APIGatewayProxyEvent;
223
- const accountConfigId = getAccountConfigIdFromEvent(event);
224
- const { calendarId } = context.request.params as { calendarId: string };
225
- const deps = calendarDepsOf(await getClient());
226
-
227
- const found = await findCalendarFeedFor(deps, accountConfigId, calendarId);
228
- if (!found.ok) return notFound(found.error.message);
229
- return found.value;
230
- },
231
-
232
- CalendarDetailOperations_putCalendarFeed: async (
233
- context,
234
- ...args: unknown[]
235
- ) => {
236
- const event = args[0] as APIGatewayProxyEvent;
237
- const accountConfigId = getAccountConfigIdFromEvent(event);
238
- const { calendarId } = context.request.params as { calendarId: string };
239
- const deps = calendarDepsOf(await getClient());
240
-
241
- const minted = await putCalendarFeedFor(deps, accountConfigId, calendarId);
242
- if (!minted.ok) return notFound(minted.error.message);
243
- return minted.value;
244
- },
245
-
246
- CalendarDetailOperations_revokeCalendarFeed: async (
247
- context,
248
- ...args: unknown[]
249
- ) => {
250
- const event = args[0] as APIGatewayProxyEvent;
251
- const accountConfigId = getAccountConfigIdFromEvent(event);
252
- const { calendarId } = context.request.params as { calendarId: string };
253
- const deps = calendarDepsOf(await getClient());
254
-
255
- const revoked = await revokeCalendarFeedFor(
256
- deps,
257
- accountConfigId,
258
- calendarId,
259
- );
260
- if (!revoked.ok) return notFound(revoked.error.message);
261
- return { statusCode: 204 };
262
- },
263
- };
264
-
265
- export const CalendarFeedOperations: Record<
266
- CalendarFeedOperationIds,
267
- OperationHandler<CalendarFeedOperationIds>
268
- > = {
269
- CalendarFeedOperations_getCalendarFeedIcal: async (
270
- context,
271
- ...args: unknown[]
272
- ) => {
273
- // From the raw path, not from the router's captured parameter: the matcher
274
- // substitutes the parameter into the literal path and leaves the dot of
275
- // ".ics" as a regex dot, so /feeds/calendar/<token>Xics routes here too —
276
- // and answering it would serve the feed at an address nobody was handed.
277
- const event = args[0] as APIGatewayProxyEvent;
278
- const feedToken = readCalendarFeedToken(event.path);
279
- if (feedToken === null) return feedNotFound();
280
-
281
- const ifNoneMatch = context.request.headers["if-none-match"];
282
- const ifModifiedSince = context.request.headers["if-modified-since"];
283
- const deps = calendarDepsOf(await getClient());
284
-
285
- return serveCalendarFeed(deps, feedToken, {
286
- ifNoneMatch: typeof ifNoneMatch === "string" ? ifNoneMatch : undefined,
287
- ifModifiedSince:
288
- typeof ifModifiedSince === "string" ? ifModifiedSince : undefined,
289
- });
290
- },
291
- };
@@ -1,36 +0,0 @@
1
- import { mkdtempSync, rmSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { applyShippedMigrations } from "@remit/drizzle-service/test-sqlite";
5
- import Database from "better-sqlite3";
6
- import { buildSqliteClient } from "../service/compose-sqlite.js";
7
- import type { RemitClient } from "../service/data-client.js";
8
-
9
- /**
10
- * A handler test's store: the backend's own SQLite composition, over the DDL a
11
- * self-host deployment actually runs.
12
- *
13
- * The migrations are applied rather than pushed from the drizzle table objects,
14
- * so a handler test exercises the shipped column shapes. The client is built by
15
- * `compose-sqlite.ts`, the composition root a self-host process boots, so
16
- * nothing here is a second wiring that could drift from the one that ships.
17
- *
18
- * One per test file: every row is scoped by account config, so a test that
19
- * mints its own account config sees only what it wrote.
20
- */
21
- export const createCalendarSqliteClient = async (): Promise<{
22
- client: RemitClient;
23
- cleanup: () => void;
24
- }> => {
25
- const directory = mkdtempSync(join(tmpdir(), "remit-calendar-handlers-"));
26
- const path = join(directory, "remit.db");
27
- const sqlite = new Database(path);
28
- applyShippedMigrations(sqlite);
29
- sqlite.close();
30
-
31
- process.env.SQLITE_DB_PATH = path;
32
- return {
33
- client: await buildSqliteClient(),
34
- cleanup: () => rmSync(directory, { recursive: true, force: true }),
35
- };
36
- };