@shware/workflow 3.2.0 → 4.0.0

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 (364) hide show
  1. package/README.md +100 -29
  2. package/dist/apns.cjs +113 -26
  3. package/dist/apns.cjs.map +1 -1
  4. package/dist/apns.d.cts +52 -6
  5. package/dist/apns.d.cts.map +1 -1
  6. package/dist/apns.d.mts +52 -6
  7. package/dist/apns.d.mts.map +1 -1
  8. package/dist/apns.mjs +111 -27
  9. package/dist/apns.mjs.map +1 -1
  10. package/dist/aws/engine-step.cjs +5 -5
  11. package/dist/aws/engine-step.cjs.map +1 -1
  12. package/dist/aws/engine-step.d.cts +8 -2
  13. package/dist/aws/engine-step.d.cts.map +1 -1
  14. package/dist/aws/engine-step.d.mts +8 -2
  15. package/dist/aws/engine-step.d.mts.map +1 -1
  16. package/dist/aws/engine-step.mjs +5 -5
  17. package/dist/aws/engine-step.mjs.map +1 -1
  18. package/dist/aws/index.cjs +47 -6
  19. package/dist/aws/index.cjs.map +1 -1
  20. package/dist/aws/index.d.cts +2 -2
  21. package/dist/aws/index.d.cts.map +1 -1
  22. package/dist/aws/index.d.mts +2 -2
  23. package/dist/aws/index.d.mts.map +1 -1
  24. package/dist/aws/index.mjs +47 -6
  25. package/dist/aws/index.mjs.map +1 -1
  26. package/dist/aws/instances.cjs +29 -6
  27. package/dist/aws/instances.cjs.map +1 -1
  28. package/dist/aws/instances.d.cts +11 -1
  29. package/dist/aws/instances.d.cts.map +1 -1
  30. package/dist/aws/instances.d.mts +11 -1
  31. package/dist/aws/instances.d.mts.map +1 -1
  32. package/dist/aws/instances.mjs +27 -4
  33. package/dist/aws/instances.mjs.map +1 -1
  34. package/dist/client.cjs +4 -1
  35. package/dist/client.cjs.map +1 -1
  36. package/dist/client.d.cts +2 -2
  37. package/dist/client.d.cts.map +1 -1
  38. package/dist/client.d.mts +2 -2
  39. package/dist/client.d.mts.map +1 -1
  40. package/dist/client.mjs +4 -1
  41. package/dist/client.mjs.map +1 -1
  42. package/dist/cloudflare/bindings.cjs +28 -25
  43. package/dist/cloudflare/bindings.cjs.map +1 -1
  44. package/dist/cloudflare/bindings.d.cts +17 -129
  45. package/dist/cloudflare/bindings.d.cts.map +1 -1
  46. package/dist/cloudflare/bindings.d.mts +17 -129
  47. package/dist/cloudflare/bindings.d.mts.map +1 -1
  48. package/dist/cloudflare/bindings.mjs +28 -23
  49. package/dist/cloudflare/bindings.mjs.map +1 -1
  50. package/dist/cloudflare/d1-env.cjs +6 -6
  51. package/dist/cloudflare/d1-env.cjs.map +1 -1
  52. package/dist/cloudflare/d1-env.d.cts +5 -5
  53. package/dist/cloudflare/d1-env.d.mts +5 -5
  54. package/dist/cloudflare/d1-env.mjs +6 -6
  55. package/dist/cloudflare/d1-env.mjs.map +1 -1
  56. package/dist/cloudflare/index.cjs +28 -18
  57. package/dist/cloudflare/index.d.cts +8 -4
  58. package/dist/cloudflare/index.d.mts +8 -4
  59. package/dist/cloudflare/index.mjs +9 -5
  60. package/dist/cloudflare/runner.cjs +29 -14
  61. package/dist/cloudflare/runner.cjs.map +1 -1
  62. package/dist/cloudflare/runner.d.cts +9 -2
  63. package/dist/cloudflare/runner.d.cts.map +1 -1
  64. package/dist/cloudflare/runner.d.mts +9 -2
  65. package/dist/cloudflare/runner.d.mts.map +1 -1
  66. package/dist/cloudflare/runner.mjs +28 -13
  67. package/dist/cloudflare/runner.mjs.map +1 -1
  68. package/dist/cloudflare/schema.sql +27 -6
  69. package/dist/cloudflare/worker.cjs +19 -9
  70. package/dist/cloudflare/worker.cjs.map +1 -1
  71. package/dist/cloudflare/worker.d.cts +2 -2
  72. package/dist/cloudflare/worker.d.cts.map +1 -1
  73. package/dist/cloudflare/worker.d.mts +2 -2
  74. package/dist/cloudflare/worker.d.mts.map +1 -1
  75. package/dist/cloudflare/worker.mjs +19 -9
  76. package/dist/cloudflare/worker.mjs.map +1 -1
  77. package/dist/config.cjs +21 -5
  78. package/dist/config.cjs.map +1 -1
  79. package/dist/config.mjs +21 -5
  80. package/dist/config.mjs.map +1 -1
  81. package/dist/dsl/action.cjs +3 -6
  82. package/dist/dsl/action.cjs.map +1 -1
  83. package/dist/dsl/action.d.cts +12 -11
  84. package/dist/dsl/action.d.cts.map +1 -1
  85. package/dist/dsl/action.d.mts +12 -11
  86. package/dist/dsl/action.d.mts.map +1 -1
  87. package/dist/dsl/action.mjs +3 -6
  88. package/dist/dsl/action.mjs.map +1 -1
  89. package/dist/dsl/bundle.cjs +35 -31
  90. package/dist/dsl/bundle.cjs.map +1 -1
  91. package/dist/dsl/bundle.d.cts.map +1 -1
  92. package/dist/dsl/bundle.d.mts.map +1 -1
  93. package/dist/dsl/bundle.mjs +35 -31
  94. package/dist/dsl/bundle.mjs.map +1 -1
  95. package/dist/dsl/condition.cjs +13 -1
  96. package/dist/dsl/condition.cjs.map +1 -1
  97. package/dist/dsl/condition.d.cts +9 -1
  98. package/dist/dsl/condition.d.cts.map +1 -1
  99. package/dist/dsl/condition.d.mts +9 -1
  100. package/dist/dsl/condition.d.mts.map +1 -1
  101. package/dist/dsl/condition.mjs +13 -2
  102. package/dist/dsl/condition.mjs.map +1 -1
  103. package/dist/dsl/flow.cjs +33 -11
  104. package/dist/dsl/flow.cjs.map +1 -1
  105. package/dist/dsl/flow.d.cts +9 -1
  106. package/dist/dsl/flow.d.cts.map +1 -1
  107. package/dist/dsl/flow.d.mts +9 -1
  108. package/dist/dsl/flow.d.mts.map +1 -1
  109. package/dist/dsl/flow.mjs +34 -13
  110. package/dist/dsl/flow.mjs.map +1 -1
  111. package/dist/dsl/workflow.cjs +2 -3
  112. package/dist/dsl/workflow.cjs.map +1 -1
  113. package/dist/dsl/workflow.d.cts.map +1 -1
  114. package/dist/dsl/workflow.d.mts.map +1 -1
  115. package/dist/dsl/workflow.mjs +3 -4
  116. package/dist/dsl/workflow.mjs.map +1 -1
  117. package/dist/email-sender.cjs +24 -0
  118. package/dist/email-sender.cjs.map +1 -1
  119. package/dist/email-sender.d.cts +18 -0
  120. package/dist/email-sender.d.cts.map +1 -1
  121. package/dist/email-sender.d.mts +18 -0
  122. package/dist/email-sender.d.mts.map +1 -1
  123. package/dist/email-sender.mjs +24 -1
  124. package/dist/email-sender.mjs.map +1 -1
  125. package/dist/engine/actions.cjs +1 -8
  126. package/dist/engine/actions.cjs.map +1 -1
  127. package/dist/engine/actions.d.cts +1 -12
  128. package/dist/engine/actions.d.cts.map +1 -1
  129. package/dist/engine/actions.d.mts +1 -12
  130. package/dist/engine/actions.d.mts.map +1 -1
  131. package/dist/engine/actions.mjs +1 -8
  132. package/dist/engine/actions.mjs.map +1 -1
  133. package/dist/engine/condition.cjs +25 -5
  134. package/dist/engine/condition.cjs.map +1 -1
  135. package/dist/engine/condition.d.cts +12 -3
  136. package/dist/engine/condition.d.cts.map +1 -1
  137. package/dist/engine/condition.d.mts +12 -3
  138. package/dist/engine/condition.d.mts.map +1 -1
  139. package/dist/engine/condition.mjs +25 -6
  140. package/dist/engine/condition.mjs.map +1 -1
  141. package/dist/engine/index.cjs +3 -0
  142. package/dist/engine/index.d.cts +5 -5
  143. package/dist/engine/index.d.mts +5 -5
  144. package/dist/engine/index.mjs +4 -4
  145. package/dist/engine/interpreter.cjs +27 -20
  146. package/dist/engine/interpreter.cjs.map +1 -1
  147. package/dist/engine/interpreter.d.cts.map +1 -1
  148. package/dist/engine/interpreter.d.mts.map +1 -1
  149. package/dist/engine/interpreter.mjs +27 -20
  150. package/dist/engine/interpreter.mjs.map +1 -1
  151. package/dist/engine/ports.d.cts +21 -6
  152. package/dist/engine/ports.d.cts.map +1 -1
  153. package/dist/engine/ports.d.mts +21 -6
  154. package/dist/engine/ports.d.mts.map +1 -1
  155. package/dist/engine/retry.cjs +13 -0
  156. package/dist/engine/retry.cjs.map +1 -1
  157. package/dist/engine/retry.d.cts +12 -0
  158. package/dist/engine/retry.d.cts.map +1 -1
  159. package/dist/engine/retry.d.mts +12 -0
  160. package/dist/engine/retry.d.mts.map +1 -1
  161. package/dist/engine/retry.mjs +13 -1
  162. package/dist/engine/retry.mjs.map +1 -1
  163. package/dist/engine/time-scale.cjs +90 -15
  164. package/dist/engine/time-scale.cjs.map +1 -1
  165. package/dist/engine/time-scale.d.cts +9 -6
  166. package/dist/engine/time-scale.d.cts.map +1 -1
  167. package/dist/engine/time-scale.d.mts +9 -6
  168. package/dist/engine/time-scale.d.mts.map +1 -1
  169. package/dist/engine/time-scale.mjs +90 -16
  170. package/dist/engine/time-scale.mjs.map +1 -1
  171. package/dist/fcm.cjs +111 -38
  172. package/dist/fcm.cjs.map +1 -1
  173. package/dist/fcm.d.cts +45 -5
  174. package/dist/fcm.d.cts.map +1 -1
  175. package/dist/fcm.d.mts +45 -5
  176. package/dist/fcm.d.mts.map +1 -1
  177. package/dist/fcm.mjs +110 -39
  178. package/dist/fcm.mjs.map +1 -1
  179. package/dist/hash.cjs +6 -6
  180. package/dist/hash.cjs.map +1 -1
  181. package/dist/hash.mjs +6 -6
  182. package/dist/hash.mjs.map +1 -1
  183. package/dist/host/auth.cjs +49 -0
  184. package/dist/host/auth.cjs.map +1 -0
  185. package/dist/host/auth.d.cts +21 -0
  186. package/dist/host/auth.d.cts.map +1 -0
  187. package/dist/host/auth.d.mts +21 -0
  188. package/dist/host/auth.d.mts.map +1 -0
  189. package/dist/host/auth.mjs +47 -0
  190. package/dist/host/auth.mjs.map +1 -0
  191. package/dist/host/channels.cjs +118 -40
  192. package/dist/host/channels.cjs.map +1 -1
  193. package/dist/host/channels.d.cts +27 -1
  194. package/dist/host/channels.d.cts.map +1 -1
  195. package/dist/host/channels.d.mts +27 -1
  196. package/dist/host/channels.d.mts.map +1 -1
  197. package/dist/host/channels.mjs +121 -44
  198. package/dist/host/channels.mjs.map +1 -1
  199. package/dist/host/execute.cjs +14 -2
  200. package/dist/host/execute.cjs.map +1 -1
  201. package/dist/host/execute.d.cts +4 -4
  202. package/dist/host/execute.d.cts.map +1 -1
  203. package/dist/host/execute.d.mts +4 -4
  204. package/dist/host/execute.d.mts.map +1 -1
  205. package/dist/host/execute.mjs +13 -1
  206. package/dist/host/execute.mjs.map +1 -1
  207. package/dist/host/fresh-read.cjs +30 -0
  208. package/dist/host/fresh-read.cjs.map +1 -0
  209. package/dist/host/fresh-read.d.cts +18 -0
  210. package/dist/host/fresh-read.d.cts.map +1 -0
  211. package/dist/host/fresh-read.d.mts +18 -0
  212. package/dist/host/fresh-read.d.mts.map +1 -0
  213. package/dist/host/fresh-read.mjs +29 -0
  214. package/dist/host/fresh-read.mjs.map +1 -0
  215. package/dist/host/http.cjs +321 -0
  216. package/dist/host/http.cjs.map +1 -0
  217. package/dist/host/http.d.cts +54 -0
  218. package/dist/host/http.d.cts.map +1 -0
  219. package/dist/host/http.d.mts +54 -0
  220. package/dist/host/http.d.mts.map +1 -0
  221. package/dist/host/http.mjs +317 -0
  222. package/dist/host/http.mjs.map +1 -0
  223. package/dist/host/{router.cjs → ingest.cjs} +147 -175
  224. package/dist/host/ingest.cjs.map +1 -0
  225. package/dist/host/{router.d.cts → ingest.d.cts} +48 -30
  226. package/dist/host/ingest.d.cts.map +1 -0
  227. package/dist/host/{router.d.mts → ingest.d.mts} +48 -30
  228. package/dist/host/ingest.d.mts.map +1 -0
  229. package/dist/host/{router.mjs → ingest.mjs} +144 -173
  230. package/dist/host/ingest.mjs.map +1 -0
  231. package/dist/host/journey-host.cjs +65 -93
  232. package/dist/host/journey-host.cjs.map +1 -1
  233. package/dist/host/journey-host.d.cts +19 -26
  234. package/dist/host/journey-host.d.cts.map +1 -1
  235. package/dist/host/journey-host.d.mts +19 -26
  236. package/dist/host/journey-host.d.mts.map +1 -1
  237. package/dist/host/journey-host.mjs +65 -93
  238. package/dist/host/journey-host.mjs.map +1 -1
  239. package/dist/host/platform.cjs +21 -0
  240. package/dist/host/platform.cjs.map +1 -0
  241. package/dist/host/platform.d.cts +126 -0
  242. package/dist/host/platform.d.cts.map +1 -0
  243. package/dist/host/platform.d.mts +126 -0
  244. package/dist/host/platform.d.mts.map +1 -0
  245. package/dist/host/platform.mjs +19 -0
  246. package/dist/host/platform.mjs.map +1 -0
  247. package/dist/host/senders.cjs +18 -9
  248. package/dist/host/senders.cjs.map +1 -1
  249. package/dist/host/senders.d.cts +9 -4
  250. package/dist/host/senders.d.cts.map +1 -1
  251. package/dist/host/senders.d.mts +9 -4
  252. package/dist/host/senders.d.mts.map +1 -1
  253. package/dist/host/senders.mjs +18 -9
  254. package/dist/host/senders.mjs.map +1 -1
  255. package/dist/index.cjs +1 -1
  256. package/dist/index.mjs +1 -1
  257. package/dist/ir.cjs +5 -7
  258. package/dist/ir.cjs.map +1 -1
  259. package/dist/ir.d.cts +3 -12
  260. package/dist/ir.d.cts.map +1 -1
  261. package/dist/ir.d.mts +3 -12
  262. package/dist/ir.d.mts.map +1 -1
  263. package/dist/ir.mjs +5 -7
  264. package/dist/ir.mjs.map +1 -1
  265. package/dist/plan.cjs +27 -33
  266. package/dist/plan.cjs.map +1 -1
  267. package/dist/plan.d.cts +1 -1
  268. package/dist/plan.d.cts.map +1 -1
  269. package/dist/plan.d.mts +1 -1
  270. package/dist/plan.d.mts.map +1 -1
  271. package/dist/plan.mjs +27 -33
  272. package/dist/plan.mjs.map +1 -1
  273. package/dist/reporting/observer.cjs +1 -0
  274. package/dist/reporting/observer.cjs.map +1 -1
  275. package/dist/reporting/observer.mjs +1 -0
  276. package/dist/reporting/observer.mjs.map +1 -1
  277. package/dist/reporting/tracking.cjs +19 -4
  278. package/dist/reporting/tracking.cjs.map +1 -1
  279. package/dist/reporting/tracking.d.cts +13 -11
  280. package/dist/reporting/tracking.d.cts.map +1 -1
  281. package/dist/reporting/tracking.d.mts +13 -11
  282. package/dist/reporting/tracking.d.mts.map +1 -1
  283. package/dist/reporting/tracking.mjs +19 -4
  284. package/dist/reporting/tracking.mjs.map +1 -1
  285. package/dist/store/d1.cjs +88 -29
  286. package/dist/store/d1.cjs.map +1 -1
  287. package/dist/store/d1.d.cts +29 -11
  288. package/dist/store/d1.d.cts.map +1 -1
  289. package/dist/store/d1.d.mts +29 -11
  290. package/dist/store/d1.d.mts.map +1 -1
  291. package/dist/store/d1.mjs +88 -29
  292. package/dist/store/d1.mjs.map +1 -1
  293. package/dist/store/erasure.cjs +22 -0
  294. package/dist/store/erasure.cjs.map +1 -0
  295. package/dist/store/erasure.d.cts +18 -0
  296. package/dist/store/erasure.d.cts.map +1 -0
  297. package/dist/store/erasure.d.mts +18 -0
  298. package/dist/store/erasure.d.mts.map +1 -0
  299. package/dist/store/erasure.mjs +21 -0
  300. package/dist/store/erasure.mjs.map +1 -0
  301. package/dist/store/index.cjs +2 -0
  302. package/dist/store/index.cjs.map +1 -1
  303. package/dist/store/index.d.cts +67 -13
  304. package/dist/store/index.d.cts.map +1 -1
  305. package/dist/store/index.d.mts +67 -13
  306. package/dist/store/index.d.mts.map +1 -1
  307. package/dist/store/index.mjs +2 -1
  308. package/dist/store/index.mjs.map +1 -1
  309. package/dist/store/postgres-reporting.cjs +125 -62
  310. package/dist/store/postgres-reporting.cjs.map +1 -1
  311. package/dist/store/postgres-reporting.d.cts +30 -2
  312. package/dist/store/postgres-reporting.d.cts.map +1 -1
  313. package/dist/store/postgres-reporting.d.mts +30 -2
  314. package/dist/store/postgres-reporting.d.mts.map +1 -1
  315. package/dist/store/postgres-reporting.mjs +125 -62
  316. package/dist/store/postgres-reporting.mjs.map +1 -1
  317. package/dist/store/postgres.cjs +179 -60
  318. package/dist/store/postgres.cjs.map +1 -1
  319. package/dist/store/postgres.d.cts +44 -7
  320. package/dist/store/postgres.d.cts.map +1 -1
  321. package/dist/store/postgres.d.mts +44 -7
  322. package/dist/store/postgres.d.mts.map +1 -1
  323. package/dist/store/postgres.mjs +179 -60
  324. package/dist/store/postgres.mjs.map +1 -1
  325. package/dist/store/tables.cjs +7 -5
  326. package/dist/store/tables.cjs.map +1 -1
  327. package/dist/store/tables.d.cts.map +1 -1
  328. package/dist/store/tables.d.mts.map +1 -1
  329. package/dist/store/tables.mjs +7 -5
  330. package/dist/store/tables.mjs.map +1 -1
  331. package/dist/store/user-lock.cjs +43 -0
  332. package/dist/store/user-lock.cjs.map +1 -0
  333. package/dist/store/user-lock.d.cts +32 -0
  334. package/dist/store/user-lock.d.cts.map +1 -0
  335. package/dist/store/user-lock.d.mts +32 -0
  336. package/dist/store/user-lock.d.mts.map +1 -0
  337. package/dist/store/user-lock.mjs +40 -0
  338. package/dist/store/user-lock.mjs.map +1 -0
  339. package/dist/transports/cloudflare-email.cjs +3 -2
  340. package/dist/transports/cloudflare-email.cjs.map +1 -1
  341. package/dist/transports/cloudflare-email.mjs +3 -2
  342. package/dist/transports/cloudflare-email.mjs.map +1 -1
  343. package/dist/transports/ses.cjs +52 -7
  344. package/dist/transports/ses.cjs.map +1 -1
  345. package/dist/transports/ses.d.cts +9 -1
  346. package/dist/transports/ses.d.cts.map +1 -1
  347. package/dist/transports/ses.d.mts +9 -1
  348. package/dist/transports/ses.d.mts.map +1 -1
  349. package/dist/transports/ses.mjs +52 -8
  350. package/dist/transports/ses.mjs.map +1 -1
  351. package/dist/webpush.cjs +133 -47
  352. package/dist/webpush.cjs.map +1 -1
  353. package/dist/webpush.d.cts +49 -8
  354. package/dist/webpush.d.cts.map +1 -1
  355. package/dist/webpush.d.mts +49 -8
  356. package/dist/webpush.d.mts.map +1 -1
  357. package/dist/webpush.mjs +130 -47
  358. package/dist/webpush.mjs.map +1 -1
  359. package/package.json +1 -1
  360. package/src/cloudflare/schema.sql +27 -6
  361. package/dist/host/router.cjs.map +0 -1
  362. package/dist/host/router.d.cts.map +0 -1
  363. package/dist/host/router.d.mts.map +0 -1
  364. package/dist/host/router.mjs.map +0 -1
@@ -0,0 +1,54 @@
1
+ import { BundleIR } from "../ir.cjs";
2
+ import { JourneyEnv } from "./platform.cjs";
3
+ import { JourneyStore } from "../store/index.cjs";
4
+ import { Contract } from "../contract.cjs";
5
+ import { EmailRenderer } from "../email-sender.cjs";
6
+ import { SweepResult } from "./ingest.cjs";
7
+ import { TrackingOptions } from "../reporting/tracking.cjs";
8
+ //#region src/host/http.d.ts
9
+ /**
10
+ * The HTTP surface, as one route table: the bare ingest API (`handleRequest`) and the routes
11
+ * the full host adds (`serve` with its parts — the bundle, previews, tracking, the sweep). A
12
+ * route whose part is absent answers 404, so the two share the table, the bearer check, the
13
+ * body validation and the error mapping.
14
+ */
15
+ /**
16
+ * How the ingest API applies a contract: 'enforce' refuses an invalid event or
17
+ * patch with a 400 before anything is stored, woken or started; 'report' logs
18
+ * the issues (event id, name, field paths — never the payload) and accepts it,
19
+ * for checking real producers before turning enforcement on.
20
+ */
21
+ export interface IngestValidation {
22
+ contract?: Contract | undefined;
23
+ mode?: 'enforce' | 'report' | undefined;
24
+ }
25
+ /** What the full host serves beyond the ingest API. A route whose part is absent answers 404. */
26
+ export interface HostParts {
27
+ /** The bundle compiled into the code: `GET /bundle` shows it, `POST /bundle/deploy` makes it live. */
28
+ bundle?: (() => BundleIR) | undefined;
29
+ /** `GET /preview/:id?props=<JSON>`: the email templates, rendered. */
30
+ preview?: {
31
+ has(id: string): boolean;
32
+ render: EmailRenderer;
33
+ } | undefined;
34
+ /** `/t/*`, what recipients open (no bearer): served on a store that keeps reporting. */
35
+ tracking?: TrackingOptions | undefined;
36
+ /** `POST /segments/sweep`. */
37
+ sweep?: (() => Promise<SweepResult>) | undefined;
38
+ }
39
+ export interface ServeContext {
40
+ env: JourneyEnv;
41
+ store: JourneyStore;
42
+ validation?: IngestValidation | undefined;
43
+ /**
44
+ * The host's parts. Their presence is what makes this a deployed host rather than the bare
45
+ * API: production then refuses to serve without `API_TOKEN`.
46
+ */
47
+ host?: HostParts | undefined;
48
+ }
49
+ /** One request through the table: the production gate, the bearer, the route, the error mapping. */
50
+ export declare function serve(request: Request, ctx: ServeContext): Promise<Response>;
51
+ /** The bare ingest API over one store: `/health`, `/events`, `/identify`, `/devices*`, `/messages/opened`, `/users/forget`, `/deploy`. */
52
+ export declare function handleRequest(request: Request, env: JourneyEnv, store?: JourneyStore, validation?: IngestValidation): Promise<Response>;
53
+ //#endregion
54
+ //# sourceMappingURL=http.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.cts","names":[],"sources":["../../src/host/http.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAyCiB;EACf,WAAW;EACX;;;iBAIe;;EAEf,gBAAgB;;EAEhB;IAAY,IAAI;IAAsB,QAAQ;;;EAE9C,WAAW;;EAEX,eAAe,QAAQ;;iBAGR;EACf,KAAK;EACL,OAAO;EACP,aAAa;;;;;EAKb,OAAO;;;wBAkWa,MAAM,SAAS,SAAS,KAAK,eAAe,QAAQ;;wBAmC1D,cACd,SAAS,SACT,KAAK,YACL,QAAO,cACP,aAAY,mBACX,QAAQ"}
@@ -0,0 +1,54 @@
1
+ import { BundleIR } from "../ir.mjs";
2
+ import { JourneyEnv } from "./platform.mjs";
3
+ import { JourneyStore } from "../store/index.mjs";
4
+ import { Contract } from "../contract.mjs";
5
+ import { EmailRenderer } from "../email-sender.mjs";
6
+ import { SweepResult } from "./ingest.mjs";
7
+ import { TrackingOptions } from "../reporting/tracking.mjs";
8
+ //#region src/host/http.d.ts
9
+ /**
10
+ * The HTTP surface, as one route table: the bare ingest API (`handleRequest`) and the routes
11
+ * the full host adds (`serve` with its parts — the bundle, previews, tracking, the sweep). A
12
+ * route whose part is absent answers 404, so the two share the table, the bearer check, the
13
+ * body validation and the error mapping.
14
+ */
15
+ /**
16
+ * How the ingest API applies a contract: 'enforce' refuses an invalid event or
17
+ * patch with a 400 before anything is stored, woken or started; 'report' logs
18
+ * the issues (event id, name, field paths — never the payload) and accepts it,
19
+ * for checking real producers before turning enforcement on.
20
+ */
21
+ export interface IngestValidation {
22
+ contract?: Contract | undefined;
23
+ mode?: 'enforce' | 'report' | undefined;
24
+ }
25
+ /** What the full host serves beyond the ingest API. A route whose part is absent answers 404. */
26
+ export interface HostParts {
27
+ /** The bundle compiled into the code: `GET /bundle` shows it, `POST /bundle/deploy` makes it live. */
28
+ bundle?: (() => BundleIR) | undefined;
29
+ /** `GET /preview/:id?props=<JSON>`: the email templates, rendered. */
30
+ preview?: {
31
+ has(id: string): boolean;
32
+ render: EmailRenderer;
33
+ } | undefined;
34
+ /** `/t/*`, what recipients open (no bearer): served on a store that keeps reporting. */
35
+ tracking?: TrackingOptions | undefined;
36
+ /** `POST /segments/sweep`. */
37
+ sweep?: (() => Promise<SweepResult>) | undefined;
38
+ }
39
+ export interface ServeContext {
40
+ env: JourneyEnv;
41
+ store: JourneyStore;
42
+ validation?: IngestValidation | undefined;
43
+ /**
44
+ * The host's parts. Their presence is what makes this a deployed host rather than the bare
45
+ * API: production then refuses to serve without `API_TOKEN`.
46
+ */
47
+ host?: HostParts | undefined;
48
+ }
49
+ /** One request through the table: the production gate, the bearer, the route, the error mapping. */
50
+ export declare function serve(request: Request, ctx: ServeContext): Promise<Response>;
51
+ /** The bare ingest API over one store: `/health`, `/events`, `/identify`, `/devices*`, `/messages/opened`, `/users/forget`, `/deploy`. */
52
+ export declare function handleRequest(request: Request, env: JourneyEnv, store?: JourneyStore, validation?: IngestValidation): Promise<Response>;
53
+ //#endregion
54
+ //# sourceMappingURL=http.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.mts","names":[],"sources":["../../src/host/http.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAyCiB;EACf,WAAW;EACX;;;iBAIe;;EAEf,gBAAgB;;EAEhB;IAAY,IAAI;IAAsB,QAAQ;;;EAE9C,WAAW;;EAEX,eAAe,QAAQ;;iBAGR;EACf,KAAK;EACL,OAAO;EACP,aAAa;;;;;EAKb,OAAO;;;wBAkWa,MAAM,SAAS,SAAS,KAAK,eAAe,QAAQ;;wBAmC1D,cACd,SAAS,SACT,KAAK,YACL,QAAO,cACP,aAAY,mBACX,QAAQ"}
@@ -0,0 +1,317 @@
1
+ import { TemplateValidationError } from "../templates.mjs";
2
+ import { checkEvent } from "../contract.mjs";
3
+ import { UserErasedError } from "../store/erasure.mjs";
4
+ import { d1Store } from "../cloudflare/d1-env.mjs";
5
+ import { SchemaMismatchError } from "../store/index.mjs";
6
+ import { BundleIntegrityError, deployBundle, forgetUser, identifyUser, ingestEvent, registerDevice, removeDevice, unbindDevice } from "./ingest.mjs";
7
+ import { journeyMode } from "./channels.mjs";
8
+ import { handleTracking, recordPushOpen } from "../reporting/tracking.mjs";
9
+ import { authorized } from "./auth.mjs";
10
+ import * as z from "zod/mini";
11
+ //#region src/host/http.ts
12
+ const json = (body, status = 200) => new Response(JSON.stringify(body), {
13
+ status,
14
+ headers: { "content-type": "application/json" }
15
+ });
16
+ const notFound = () => json({ error: "not found" }, 404);
17
+ /** The request body is not JSON: the caller's to fix (a 400), not a server fault. */
18
+ var InvalidJsonError = class extends Error {
19
+ name = "InvalidJsonError";
20
+ };
21
+ async function readJson(request) {
22
+ try {
23
+ return await request.json();
24
+ } catch (error) {
25
+ throw new InvalidJsonError("invalid JSON body", { cause: error });
26
+ }
27
+ }
28
+ /**
29
+ * Request bodies are untrusted JSON. They are read as unknown fields and
30
+ * checked, never cast into the shape they are supposed to have: a cast only
31
+ * silences the compiler, and what arrives here reaches SQL parameters.
32
+ */
33
+ async function readBody(request) {
34
+ const body = await readJson(request);
35
+ return isPlainObject(body) ? body : {};
36
+ }
37
+ function isPlainObject(value) {
38
+ return typeof value === "object" && value !== null && !Array.isArray(value);
39
+ }
40
+ function isNonEmptyString(value) {
41
+ return typeof value === "string" && value.length > 0;
42
+ }
43
+ /** A profile value: a scalar or null (which removes the property). Nested values are not profile data. */
44
+ function isScalarOrNull(value) {
45
+ return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
46
+ }
47
+ /** How far ahead of the server's clock an event or device `ts` may be: clock skew, not the future. */
48
+ const TS_FUTURE_TOLERANCE_MS = 3e5;
49
+ const TS_ERROR = "ts must be a non-negative integer no later than 5 minutes in the future";
50
+ /**
51
+ * A caller's timestamp: epoch milliseconds, whole, not negative, and not past the skew tolerance.
52
+ * A far-future ts would put the event ahead of everything a window condition reads, and a
53
+ * fractional or unsafe one does not survive the store.
54
+ */
55
+ function isValidTs(ts) {
56
+ return typeof ts === "number" && Number.isSafeInteger(ts) && ts >= 0 && ts <= Date.now() + TS_FUTURE_TOLERANCE_MS;
57
+ }
58
+ /** The contract's verdict: the value to use, or the response refusing the request. */
59
+ function checked(validation, result, original, what) {
60
+ if (result.ok) return { value: result.data };
61
+ const issues = result.issues.map((i) => `${i.path || "(root)"}: ${i.message}`);
62
+ if (validation.mode === "report") {
63
+ console.warn(`[workflow http] contract would refuse ${what}: ${issues.join("; ")}`);
64
+ return { value: original };
65
+ }
66
+ return { refused: json({
67
+ error: `${what} refused by the contract`,
68
+ issues: result.issues
69
+ }, 400) };
70
+ }
71
+ const routes = [
72
+ {
73
+ method: "GET",
74
+ path: "/health",
75
+ auth: "none",
76
+ handle: async () => json({ ok: true })
77
+ },
78
+ {
79
+ method: "*",
80
+ path: /^\/t\//,
81
+ auth: "none",
82
+ async handle({ request, store, host }) {
83
+ if (host.tracking === void 0 || store.reporting === void 0) return notFound();
84
+ return await handleTracking(request, store.reporting, host.tracking) ?? notFound();
85
+ }
86
+ },
87
+ {
88
+ method: "POST",
89
+ path: "/events",
90
+ auth: "bearer",
91
+ async handle({ request, env, store, validation }) {
92
+ const { id, userId, event, payload, ts } = await readBody(request);
93
+ if (!isNonEmptyString(userId) || !isNonEmptyString(event)) return json({ error: "userId and event required" }, 400);
94
+ if (event.startsWith("$")) return json({ error: "event names starting with $ are reserved" }, 400);
95
+ if (id !== void 0 && !isNonEmptyString(id)) return json({ error: "id must be a non-empty string" }, 400);
96
+ if (ts !== void 0 && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);
97
+ if (payload !== void 0 && !isPlainObject(payload)) return json({ error: "payload must be an object" }, 400);
98
+ let accepted = payload;
99
+ if (validation.contract !== void 0) {
100
+ const verdict = checked(validation, checkEvent(validation.contract, event, payload ?? {}), accepted ?? {}, `event '${event}'${typeof id === "string" ? ` (${id})` : ""}`);
101
+ if ("refused" in verdict) return verdict.refused;
102
+ accepted = verdict.value;
103
+ }
104
+ return json(await ingestEvent(env, {
105
+ id,
106
+ userId,
107
+ event,
108
+ payload: accepted,
109
+ ts
110
+ }, store));
111
+ }
112
+ },
113
+ {
114
+ method: "POST",
115
+ path: "/identify",
116
+ auth: "bearer",
117
+ async handle({ request, env, store, validation }) {
118
+ const { userId, props } = await readBody(request);
119
+ if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
120
+ if (!isPlainObject(props)) return json({ error: "props must be an object" }, 400);
121
+ if (!Object.values(props).every(isScalarOrNull)) return json({ error: "props values must be scalars (string, number, boolean) or null" }, 400);
122
+ let patch = props;
123
+ if (validation.contract !== void 0) {
124
+ const verdict = checked(validation, validation.contract.parseProfilePatch(props), patch, "identify");
125
+ if ("refused" in verdict) return verdict.refused;
126
+ patch = verdict.value;
127
+ }
128
+ return json(await identifyUser(env, userId, patch, store));
129
+ }
130
+ },
131
+ {
132
+ method: "POST",
133
+ path: "/devices",
134
+ auth: "bearer",
135
+ async handle({ request, env, store }) {
136
+ const { userId, token, platform, ts } = await readBody(request);
137
+ if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
138
+ if (!isNonEmptyString(token)) return json({ error: "token required" }, 400);
139
+ if (platform !== "ios" && platform !== "android" && platform !== "web") return json({ error: "platform must be 'ios', 'android' or 'web'" }, 400);
140
+ if (ts !== void 0 && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);
141
+ const device = {
142
+ userId,
143
+ token,
144
+ platform,
145
+ ...ts === void 0 ? {} : { ts }
146
+ };
147
+ return json(await registerDevice(env, device, store));
148
+ }
149
+ },
150
+ {
151
+ method: "POST",
152
+ path: "/devices/unbind",
153
+ auth: "bearer",
154
+ async handle({ request, env, store }) {
155
+ const { token } = await readBody(request);
156
+ if (!isNonEmptyString(token)) return json({ error: "token required" }, 400);
157
+ return json(await unbindDevice(env, token, store));
158
+ }
159
+ },
160
+ {
161
+ method: "POST",
162
+ path: "/devices/remove",
163
+ auth: "bearer",
164
+ async handle({ request, env, store }) {
165
+ const { token } = await readBody(request);
166
+ if (!isNonEmptyString(token)) return json({ error: "token required" }, 400);
167
+ return json(await removeDevice(env, token, store));
168
+ }
169
+ },
170
+ {
171
+ method: "POST",
172
+ path: "/messages/opened",
173
+ auth: "bearer",
174
+ async handle({ request, store }) {
175
+ const { userId, messageId } = await readBody(request);
176
+ if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
177
+ if (!isNonEmptyString(messageId)) return json({ error: "messageId required" }, 400);
178
+ const recorded = store.reporting !== void 0 && await recordPushOpen(store.reporting, userId, messageId);
179
+ return json({
180
+ ok: true,
181
+ recorded
182
+ });
183
+ }
184
+ },
185
+ {
186
+ method: "POST",
187
+ path: "/users/forget",
188
+ auth: "bearer",
189
+ async handle({ request, env, store }) {
190
+ const { userId } = await readBody(request);
191
+ if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
192
+ return json(await forgetUser(env, userId, store));
193
+ }
194
+ },
195
+ {
196
+ method: "POST",
197
+ path: "/deploy",
198
+ auth: "bearer",
199
+ async handle({ request, env, store }) {
200
+ return json(await deployBundle(env, await readJson(request), store));
201
+ }
202
+ },
203
+ {
204
+ method: "GET",
205
+ path: "/bundle",
206
+ auth: "bearer",
207
+ async handle({ host }) {
208
+ return host.bundle === void 0 ? notFound() : json(host.bundle());
209
+ }
210
+ },
211
+ {
212
+ method: "POST",
213
+ path: "/bundle/deploy",
214
+ auth: "bearer",
215
+ async handle({ env, store, host }) {
216
+ if (host.bundle === void 0) return notFound();
217
+ return json(await deployBundle(env, host.bundle(), store));
218
+ }
219
+ },
220
+ {
221
+ method: "POST",
222
+ path: "/segments/sweep",
223
+ auth: "bearer",
224
+ async handle({ host }) {
225
+ return host.sweep === void 0 ? notFound() : json(await host.sweep());
226
+ }
227
+ },
228
+ {
229
+ method: "GET",
230
+ path: /^\/preview\//,
231
+ auth: "bearer",
232
+ async handle({ url, host }) {
233
+ const { preview } = host;
234
+ if (preview === void 0) return notFound();
235
+ const key = url.pathname.slice(9);
236
+ if (!preview.has(key)) return json({ error: `unknown email template: ${key}` }, 404);
237
+ let props;
238
+ try {
239
+ props = JSON.parse(url.searchParams.get("props") ?? "{}");
240
+ } catch {
241
+ return json({ error: "props must be a JSON object" }, 400);
242
+ }
243
+ if (!isPlainObject(props)) return json({ error: "props must be a JSON object" }, 400);
244
+ const { subject, html } = await preview.render(key, props);
245
+ return new Response(html, { headers: {
246
+ "content-type": "text/html; charset=utf-8",
247
+ "x-subject": encodeURIComponent(subject)
248
+ } });
249
+ }
250
+ }
251
+ ];
252
+ function matches(path, pathname) {
253
+ if (typeof path === "string") return path === pathname;
254
+ if (path instanceof RegExp) return path.test(pathname);
255
+ return path(pathname);
256
+ }
257
+ /**
258
+ * Production without a bearer token is not an open instance, it is a mistake: anyone could
259
+ * ingest, identify and deploy. Only what recipients open (`/t/*`) and the health check stay up.
260
+ */
261
+ function refusesOpen(request, env, pathname) {
262
+ return env.API_TOKEN === void 0 && journeyMode(env) === "production" && !pathname.startsWith("/t/") && !(request.method === "GET" && pathname === "/health");
263
+ }
264
+ /**
265
+ * What a failed request answers. Validation problems are the caller's to fix (a 400, saying
266
+ * what); anything else stays out of the response body (internals are logged, not leaked).
267
+ */
268
+ function failure(error) {
269
+ if (error instanceof InvalidJsonError) return json({ error: "invalid JSON body" }, 400);
270
+ if (error instanceof z.core.$ZodError) return json({ error: `invalid payload: ${error.message}` }, 400);
271
+ if (error instanceof BundleIntegrityError) return json({ error: error.message }, 400);
272
+ if (error instanceof TemplateValidationError) return json({
273
+ error: error.message,
274
+ issues: error.issues
275
+ }, 400);
276
+ if (error instanceof UserErasedError) return json({ error: "user is erased" }, 410);
277
+ if (error instanceof SchemaMismatchError) return json({
278
+ error: error.message,
279
+ problems: error.problems
280
+ }, 503);
281
+ console.error("[workflow http]", error);
282
+ return json({ error: "internal error" }, 500);
283
+ }
284
+ /** One request through the table: the production gate, the bearer, the route, the error mapping. */
285
+ async function serve(request, ctx) {
286
+ const url = new URL(request.url);
287
+ if (ctx.host !== void 0 && refusesOpen(request, ctx.env, url.pathname)) return json({ error: "API_TOKEN is not set: production refuses to serve without it (set ENVIRONMENT=development to run open)" }, 503);
288
+ const candidates = routes.filter((route) => matches(route.path, url.pathname));
289
+ if (candidates.length === 0) return notFound();
290
+ if (candidates.some((route) => route.auth === "bearer") && !authorized(request, ctx.env)) return json({ error: "unauthorized" }, 401);
291
+ const route = candidates.find((r) => r.method === "*" || r.method === request.method);
292
+ if (route === void 0) return json({ error: "method not allowed" }, 405);
293
+ try {
294
+ return await route.handle({
295
+ request,
296
+ url,
297
+ env: ctx.env,
298
+ store: ctx.store,
299
+ validation: ctx.validation ?? {},
300
+ host: ctx.host ?? {}
301
+ });
302
+ } catch (error) {
303
+ return failure(error);
304
+ }
305
+ }
306
+ /** The bare ingest API over one store: `/health`, `/events`, `/identify`, `/devices*`, `/messages/opened`, `/users/forget`, `/deploy`. */
307
+ function handleRequest(request, env, store = d1Store(env), validation = {}) {
308
+ return serve(request, {
309
+ env,
310
+ store,
311
+ validation
312
+ });
313
+ }
314
+ //#endregion
315
+ export { handleRequest, serve };
316
+
317
+ //# sourceMappingURL=http.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.mjs","names":[],"sources":["../../src/host/http.ts"],"sourcesContent":["import * as z from 'zod/mini';\nimport { d1Store } from '../cloudflare/d1-env';\nimport { type Contract, type ContractResult, checkEvent } from '../contract';\nimport type { EmailRenderer } from '../email-sender';\nimport type { BundleIR, ScalarIR } from '../ir';\nimport { type TrackingOptions, handleTracking, recordPushOpen } from '../reporting/tracking';\nimport {\n type JourneyStore,\n type ProfileProps,\n SchemaMismatchError,\n UserErasedError,\n} from '../store/index';\nimport { TemplateValidationError } from '../templates';\nimport { authorized } from './auth';\nimport { journeyMode } from './channels';\nimport {\n BundleIntegrityError,\n type SweepResult,\n deployBundle,\n forgetUser,\n identifyUser,\n ingestEvent,\n registerDevice,\n removeDevice,\n unbindDevice,\n} from './ingest';\nimport type { JourneyEnv } from './platform';\n\n/**\n * The HTTP surface, as one route table: the bare ingest API (`handleRequest`) and the routes\n * the full host adds (`serve` with its parts — the bundle, previews, tracking, the sweep). A\n * route whose part is absent answers 404, so the two share the table, the bearer check, the\n * body validation and the error mapping.\n */\n\n/**\n * How the ingest API applies a contract: 'enforce' refuses an invalid event or\n * patch with a 400 before anything is stored, woken or started; 'report' logs\n * the issues (event id, name, field paths — never the payload) and accepts it,\n * for checking real producers before turning enforcement on.\n */\nexport interface IngestValidation {\n contract?: Contract | undefined;\n mode?: 'enforce' | 'report' | undefined;\n}\n\n/** What the full host serves beyond the ingest API. A route whose part is absent answers 404. */\nexport interface HostParts {\n /** The bundle compiled into the code: `GET /bundle` shows it, `POST /bundle/deploy` makes it live. */\n bundle?: (() => BundleIR) | undefined;\n /** `GET /preview/:id?props=<JSON>`: the email templates, rendered. */\n preview?: { has(id: string): boolean; render: EmailRenderer } | undefined;\n /** `/t/*`, what recipients open (no bearer): served on a store that keeps reporting. */\n tracking?: TrackingOptions | undefined;\n /** `POST /segments/sweep`. */\n sweep?: (() => Promise<SweepResult>) | undefined;\n}\n\nexport interface ServeContext {\n env: JourneyEnv;\n store: JourneyStore;\n validation?: IngestValidation | undefined;\n /**\n * The host's parts. Their presence is what makes this a deployed host rather than the bare\n * API: production then refuses to serve without `API_TOKEN`.\n */\n host?: HostParts | undefined;\n}\n\ninterface RouteContext {\n request: Request;\n url: URL;\n env: JourneyEnv;\n store: JourneyStore;\n validation: IngestValidation;\n host: HostParts;\n}\n\ninterface Route {\n /** '*' takes every method (the tracking routes answer GET, HEAD and POST themselves). */\n method: 'GET' | 'POST' | '*';\n path: string | RegExp | ((pathname: string) => boolean);\n auth: 'none' | 'bearer';\n handle(ctx: RouteContext): Promise<Response>;\n}\n\nconst json = (body: unknown, status = 200): Response =>\n new Response(JSON.stringify(body), {\n status,\n headers: { 'content-type': 'application/json' },\n });\n\nconst notFound = () => json({ error: 'not found' }, 404);\n\n/* --------------------------------- bodies ---------------------------------- */\n\n/** The request body is not JSON: the caller's to fix (a 400), not a server fault. */\nclass InvalidJsonError extends Error {\n override readonly name = 'InvalidJsonError';\n}\n\nasync function readJson(request: Request): Promise<unknown> {\n try {\n return await request.json();\n } catch (error) {\n throw new InvalidJsonError('invalid JSON body', { cause: error });\n }\n}\n\n/**\n * Request bodies are untrusted JSON. They are read as unknown fields and\n * checked, never cast into the shape they are supposed to have: a cast only\n * silences the compiler, and what arrives here reaches SQL parameters.\n */\nasync function readBody(request: Request): Promise<Record<string, unknown>> {\n const body = await readJson(request);\n return isPlainObject(body) ? body : {};\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\n/** A profile value: a scalar or null (which removes the property). Nested values are not profile data. */\nfunction isScalarOrNull(value: unknown): value is string | number | boolean | null {\n return (\n value === null ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n );\n}\n\n/** How far ahead of the server's clock an event or device `ts` may be: clock skew, not the future. */\nconst TS_FUTURE_TOLERANCE_MS = 5 * 60_000;\nconst TS_ERROR = 'ts must be a non-negative integer no later than 5 minutes in the future';\n\n/**\n * A caller's timestamp: epoch milliseconds, whole, not negative, and not past the skew tolerance.\n * A far-future ts would put the event ahead of everything a window condition reads, and a\n * fractional or unsafe one does not survive the store.\n */\nfunction isValidTs(ts: unknown): ts is number {\n return (\n typeof ts === 'number' &&\n Number.isSafeInteger(ts) &&\n ts >= 0 &&\n ts <= Date.now() + TS_FUTURE_TOLERANCE_MS\n );\n}\n\n/** The contract's verdict: the value to use, or the response refusing the request. */\nfunction checked<T>(\n validation: IngestValidation,\n result: ContractResult<T>,\n original: T,\n what: string\n): { value: T } | { refused: Response } {\n if (result.ok) return { value: result.data };\n const issues = result.issues.map((i) => `${i.path || '(root)'}: ${i.message}`);\n if (validation.mode === 'report') {\n console.warn(`[workflow http] contract would refuse ${what}: ${issues.join('; ')}`);\n return { value: original };\n }\n return {\n refused: json({ error: `${what} refused by the contract`, issues: result.issues }, 400),\n };\n}\n\n/* --------------------------------- routes ---------------------------------- */\n\nconst routes: readonly Route[] = [\n { method: 'GET', path: '/health', auth: 'none', handle: async () => json({ ok: true }) },\n {\n // Opened by recipients, so no bearer: the routes only record, and redirect to recorded URLs\n method: '*',\n path: /^\\/t\\//,\n auth: 'none',\n async handle({ request, store, host }) {\n if (host.tracking === undefined || store.reporting === undefined) return notFound();\n return (await handleTracking(request, store.reporting, host.tracking)) ?? notFound();\n },\n },\n {\n method: 'POST',\n path: '/events',\n auth: 'bearer',\n async handle({ request, env, store, validation }) {\n const { id, userId, event, payload, ts } = await readBody(request);\n if (!isNonEmptyString(userId) || !isNonEmptyString(event)) {\n return json({ error: 'userId and event required' }, 400);\n }\n if (event.startsWith('$')) {\n return json({ error: 'event names starting with $ are reserved' }, 400);\n }\n // An empty id is rejected rather than treated as absent: a caller that\n // sent one meant to identify the occurrence, and silently minting a\n // different one would turn their retry into a duplicate.\n if (id !== undefined && !isNonEmptyString(id)) {\n return json({ error: 'id must be a non-empty string' }, 400);\n }\n if (ts !== undefined && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);\n if (payload !== undefined && !isPlainObject(payload)) {\n return json({ error: 'payload must be an object' }, 400);\n }\n let accepted = payload;\n if (validation.contract !== undefined) {\n const verdict = checked(\n validation,\n checkEvent(validation.contract, event, payload ?? {}),\n accepted ?? {},\n `event '${event}'${typeof id === 'string' ? ` (${id})` : ''}`\n );\n if ('refused' in verdict) return verdict.refused;\n accepted = verdict.value;\n }\n return json(await ingestEvent(env, { id, userId, event, payload: accepted, ts }, store));\n },\n },\n {\n method: 'POST',\n path: '/identify',\n auth: 'bearer',\n async handle({ request, env, store, validation }) {\n const { userId, props } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n if (!isPlainObject(props)) return json({ error: 'props must be an object' }, 400);\n // Profiles hold scalars only (both stores merge at the top level; a nested object would\n // be merged differently by each): refused here, contract or not\n if (!Object.values(props).every(isScalarOrNull)) {\n return json(\n { error: 'props values must be scalars (string, number, boolean) or null' },\n 400\n );\n }\n let patch = props as ProfileProps;\n if (validation.contract !== undefined) {\n const verdict = checked(\n validation,\n validation.contract.parseProfilePatch(props),\n patch,\n 'identify'\n );\n if ('refused' in verdict) return verdict.refused;\n patch = verdict.value as ProfileProps;\n }\n return json(await identifyUser(env, userId, patch, store));\n },\n },\n {\n method: 'POST',\n path: '/devices',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { userId, token, platform, ts } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n if (!isNonEmptyString(token)) return json({ error: 'token required' }, 400);\n if (platform !== 'ios' && platform !== 'android' && platform !== 'web') {\n return json({ error: \"platform must be 'ios', 'android' or 'web'\" }, 400);\n }\n if (ts !== undefined && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);\n const device = { userId, token, platform, ...(ts === undefined ? {} : { ts }) };\n return json(await registerDevice(env, device, store));\n },\n },\n {\n method: 'POST',\n path: '/devices/unbind',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { token } = await readBody(request);\n if (!isNonEmptyString(token)) return json({ error: 'token required' }, 400);\n return json(await unbindDevice(env, token, store));\n },\n },\n {\n method: 'POST',\n path: '/devices/remove',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { token } = await readBody(request);\n if (!isNonEmptyString(token)) return json({ error: 'token required' }, 400);\n return json(await removeDevice(env, token, store));\n },\n },\n {\n method: 'POST',\n path: '/messages/opened',\n auth: 'bearer',\n async handle({ request, store }) {\n const { userId, messageId } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n if (!isNonEmptyString(messageId)) return json({ error: 'messageId required' }, 400);\n const recorded =\n store.reporting !== undefined && (await recordPushOpen(store.reporting, userId, messageId));\n return json({ ok: true, recorded });\n },\n },\n {\n method: 'POST',\n path: '/users/forget',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { userId } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n return json(await forgetUser(env, userId, store));\n },\n },\n {\n method: 'POST',\n path: '/deploy',\n auth: 'bearer',\n async handle({ request, env, store }) {\n return json(await deployBundle(env, await readJson(request), store));\n },\n },\n {\n method: 'GET',\n path: '/bundle',\n auth: 'bearer',\n async handle({ host }) {\n return host.bundle === undefined ? notFound() : json(host.bundle());\n },\n },\n {\n method: 'POST',\n path: '/bundle/deploy',\n auth: 'bearer',\n async handle({ env, store, host }) {\n if (host.bundle === undefined) return notFound();\n return json(await deployBundle(env, host.bundle(), store));\n },\n },\n {\n method: 'POST',\n path: '/segments/sweep',\n auth: 'bearer',\n async handle({ host }) {\n return host.sweep === undefined ? notFound() : json(await host.sweep());\n },\n },\n {\n method: 'GET',\n path: /^\\/preview\\//,\n auth: 'bearer',\n async handle({ url, host }) {\n const { preview } = host;\n if (preview === undefined) return notFound();\n const key = url.pathname.slice('/preview/'.length);\n if (!preview.has(key)) return json({ error: `unknown email template: ${key}` }, 404);\n // `?props=<JSON object>`: JSON keeps numbers and booleans typed, which query strings cannot\n let props: unknown;\n try {\n props = JSON.parse(url.searchParams.get('props') ?? '{}');\n } catch {\n return json({ error: 'props must be a JSON object' }, 400);\n }\n if (!isPlainObject(props)) return json({ error: 'props must be a JSON object' }, 400);\n const { subject, html } = await preview.render(key, props as Record<string, ScalarIR>);\n // A header holds bytes, not text: a subject with a non-Latin-1 character would throw\n // here, so it travels percent-encoded (the reader `decodeURIComponent`s it)\n return new Response(html, {\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n 'x-subject': encodeURIComponent(subject),\n },\n });\n },\n },\n];\n\nfunction matches(path: Route['path'], pathname: string): boolean {\n if (typeof path === 'string') return path === pathname;\n if (path instanceof RegExp) return path.test(pathname);\n return path(pathname);\n}\n\n/**\n * Production without a bearer token is not an open instance, it is a mistake: anyone could\n * ingest, identify and deploy. Only what recipients open (`/t/*`) and the health check stay up.\n */\nfunction refusesOpen(request: Request, env: JourneyEnv, pathname: string): boolean {\n return (\n env.API_TOKEN === undefined &&\n journeyMode(env) === 'production' &&\n !pathname.startsWith('/t/') &&\n !(request.method === 'GET' && pathname === '/health')\n );\n}\n\n/**\n * What a failed request answers. Validation problems are the caller's to fix (a 400, saying\n * what); anything else stays out of the response body (internals are logged, not leaked).\n */\nfunction failure(error: unknown): Response {\n if (error instanceof InvalidJsonError) return json({ error: 'invalid JSON body' }, 400);\n if (error instanceof z.core.$ZodError) {\n return json({ error: `invalid payload: ${error.message}` }, 400);\n }\n // The caller sent a self-inconsistent bundle: their problem to fix, so say what is wrong\n if (error instanceof BundleIntegrityError) return json({ error: error.message }, 400);\n // The query string is the props: a refusal is the caller's to fix, with the field paths\n if (error instanceof TemplateValidationError) {\n return json({ error: error.message, issues: error.issues }, 400);\n }\n // The user has an erasure tombstone: gone, and nothing about them is taken, now or later\n if (error instanceof UserErasedError) return json({ error: 'user is erased' }, 410);\n // The operator's to fix (run the migrations), so the response says what is missing\n if (error instanceof SchemaMismatchError) {\n return json({ error: error.message, problems: error.problems }, 503);\n }\n console.error('[workflow http]', error);\n return json({ error: 'internal error' }, 500);\n}\n\n/** One request through the table: the production gate, the bearer, the route, the error mapping. */\nexport async function serve(request: Request, ctx: ServeContext): Promise<Response> {\n const url = new URL(request.url);\n if (ctx.host !== undefined && refusesOpen(request, ctx.env, url.pathname)) {\n return json(\n {\n error:\n 'API_TOKEN is not set: production refuses to serve without it (set ENVIRONMENT=development to run open)',\n },\n 503\n );\n }\n const candidates = routes.filter((route) => matches(route.path, url.pathname));\n if (candidates.length === 0) return notFound();\n // Bearer auth on everything but the health check and the recipients' routes. An unset token\n // means an open dev instance (see JourneyEnv.API_TOKEN); production refuses to run that way\n if (candidates.some((route) => route.auth === 'bearer') && !authorized(request, ctx.env)) {\n return json({ error: 'unauthorized' }, 401);\n }\n const route = candidates.find((r) => r.method === '*' || r.method === request.method);\n if (route === undefined) return json({ error: 'method not allowed' }, 405);\n try {\n return await route.handle({\n request,\n url,\n env: ctx.env,\n store: ctx.store,\n validation: ctx.validation ?? {},\n host: ctx.host ?? {},\n });\n } catch (error) {\n return failure(error);\n }\n}\n\n/** The bare ingest API over one store: `/health`, `/events`, `/identify`, `/devices*`, `/messages/opened`, `/users/forget`, `/deploy`. */\nexport function handleRequest(\n request: Request,\n env: JourneyEnv,\n store: JourneyStore = d1Store(env),\n validation: IngestValidation = {}\n): Promise<Response> {\n return serve(request, { env, store, validation });\n}\n"],"mappings":";;;;;;;;;;;AAsFA,MAAM,QAAQ,MAAe,SAAS,QACpC,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;CACjC;CACA,SAAS,EAAE,gBAAgB,mBAAmB;AAChD,CAAC;AAEH,MAAM,iBAAiB,KAAK,EAAE,OAAO,YAAY,GAAG,GAAG;;AAKvD,IAAM,mBAAN,cAA+B,MAAM;CACnC,OAAyB;AAC3B;AAEA,eAAe,SAAS,SAAoC;CAC1D,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK;CAC5B,SAAS,OAAO;EACd,MAAM,IAAI,iBAAiB,qBAAqB,EAAE,OAAO,MAAM,CAAC;CAClE;AACF;;;;;;AAOA,eAAe,SAAS,SAAoD;CAC1E,MAAM,OAAO,MAAM,SAAS,OAAO;CACnC,OAAO,cAAc,IAAI,IAAI,OAAO,CAAC;AACvC;AAEA,SAAS,cAAc,OAAkD;CACvE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,iBAAiB,OAAiC;CACzD,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS;AACrD;;AAGA,SAAS,eAAe,OAA2D;CACjF,OACE,UAAU,QACV,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAErB;;AAGA,MAAM,yBAAyB;AA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