@shware/workflow 3.3.0 → 4.1.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 (350) hide show
  1. package/README.md +230 -40
  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 +50 -6
  19. package/dist/aws/index.cjs.map +1 -1
  20. package/dist/aws/index.d.cts +4 -3
  21. package/dist/aws/index.d.cts.map +1 -1
  22. package/dist/aws/index.d.mts +4 -3
  23. package/dist/aws/index.d.mts.map +1 -1
  24. package/dist/aws/index.mjs +49 -7
  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 +15 -129
  45. package/dist/cloudflare/bindings.d.cts.map +1 -1
  46. package/dist/cloudflare/bindings.d.mts +15 -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 +29 -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/engine/actions.cjs +1 -8
  118. package/dist/engine/actions.cjs.map +1 -1
  119. package/dist/engine/actions.d.cts +1 -12
  120. package/dist/engine/actions.d.cts.map +1 -1
  121. package/dist/engine/actions.d.mts +1 -12
  122. package/dist/engine/actions.d.mts.map +1 -1
  123. package/dist/engine/actions.mjs +1 -8
  124. package/dist/engine/actions.mjs.map +1 -1
  125. package/dist/engine/condition.cjs +25 -5
  126. package/dist/engine/condition.cjs.map +1 -1
  127. package/dist/engine/condition.d.cts +12 -3
  128. package/dist/engine/condition.d.cts.map +1 -1
  129. package/dist/engine/condition.d.mts +12 -3
  130. package/dist/engine/condition.d.mts.map +1 -1
  131. package/dist/engine/condition.mjs +25 -6
  132. package/dist/engine/condition.mjs.map +1 -1
  133. package/dist/engine/index.cjs +3 -0
  134. package/dist/engine/index.d.cts +5 -5
  135. package/dist/engine/index.d.mts +5 -5
  136. package/dist/engine/index.mjs +4 -4
  137. package/dist/engine/interpreter.cjs +27 -20
  138. package/dist/engine/interpreter.cjs.map +1 -1
  139. package/dist/engine/interpreter.d.cts.map +1 -1
  140. package/dist/engine/interpreter.d.mts.map +1 -1
  141. package/dist/engine/interpreter.mjs +27 -20
  142. package/dist/engine/interpreter.mjs.map +1 -1
  143. package/dist/engine/ports.d.cts +15 -6
  144. package/dist/engine/ports.d.cts.map +1 -1
  145. package/dist/engine/ports.d.mts +15 -6
  146. package/dist/engine/ports.d.mts.map +1 -1
  147. package/dist/engine/retry.cjs +13 -0
  148. package/dist/engine/retry.cjs.map +1 -1
  149. package/dist/engine/retry.d.cts +12 -0
  150. package/dist/engine/retry.d.cts.map +1 -1
  151. package/dist/engine/retry.d.mts +12 -0
  152. package/dist/engine/retry.d.mts.map +1 -1
  153. package/dist/engine/retry.mjs +13 -1
  154. package/dist/engine/retry.mjs.map +1 -1
  155. package/dist/engine/time-scale.cjs +90 -15
  156. package/dist/engine/time-scale.cjs.map +1 -1
  157. package/dist/engine/time-scale.d.cts +9 -6
  158. package/dist/engine/time-scale.d.cts.map +1 -1
  159. package/dist/engine/time-scale.d.mts +9 -6
  160. package/dist/engine/time-scale.d.mts.map +1 -1
  161. package/dist/engine/time-scale.mjs +90 -16
  162. package/dist/engine/time-scale.mjs.map +1 -1
  163. package/dist/fcm.cjs +111 -38
  164. package/dist/fcm.cjs.map +1 -1
  165. package/dist/fcm.d.cts +45 -5
  166. package/dist/fcm.d.cts.map +1 -1
  167. package/dist/fcm.d.mts +45 -5
  168. package/dist/fcm.d.mts.map +1 -1
  169. package/dist/fcm.mjs +110 -39
  170. package/dist/fcm.mjs.map +1 -1
  171. package/dist/hash.cjs +6 -6
  172. package/dist/hash.cjs.map +1 -1
  173. package/dist/hash.mjs +6 -6
  174. package/dist/hash.mjs.map +1 -1
  175. package/dist/host/auth.cjs +49 -0
  176. package/dist/host/auth.cjs.map +1 -0
  177. package/dist/host/auth.d.cts +35 -0
  178. package/dist/host/auth.d.cts.map +1 -0
  179. package/dist/host/auth.d.mts +35 -0
  180. package/dist/host/auth.d.mts.map +1 -0
  181. package/dist/host/auth.mjs +46 -0
  182. package/dist/host/auth.mjs.map +1 -0
  183. package/dist/host/channels.cjs +118 -40
  184. package/dist/host/channels.cjs.map +1 -1
  185. package/dist/host/channels.d.cts +27 -1
  186. package/dist/host/channels.d.cts.map +1 -1
  187. package/dist/host/channels.d.mts +27 -1
  188. package/dist/host/channels.d.mts.map +1 -1
  189. package/dist/host/channels.mjs +121 -44
  190. package/dist/host/channels.mjs.map +1 -1
  191. package/dist/host/execute.cjs +14 -2
  192. package/dist/host/execute.cjs.map +1 -1
  193. package/dist/host/execute.d.cts +4 -4
  194. package/dist/host/execute.d.cts.map +1 -1
  195. package/dist/host/execute.d.mts +4 -4
  196. package/dist/host/execute.d.mts.map +1 -1
  197. package/dist/host/execute.mjs +13 -1
  198. package/dist/host/execute.mjs.map +1 -1
  199. package/dist/host/fresh-read.cjs +30 -0
  200. package/dist/host/fresh-read.cjs.map +1 -0
  201. package/dist/host/fresh-read.d.cts +18 -0
  202. package/dist/host/fresh-read.d.cts.map +1 -0
  203. package/dist/host/fresh-read.d.mts +18 -0
  204. package/dist/host/fresh-read.d.mts.map +1 -0
  205. package/dist/host/fresh-read.mjs +29 -0
  206. package/dist/host/fresh-read.mjs.map +1 -0
  207. package/dist/host/http.cjs +340 -0
  208. package/dist/host/http.cjs.map +1 -0
  209. package/dist/host/http.d.cts +58 -0
  210. package/dist/host/http.d.cts.map +1 -0
  211. package/dist/host/http.d.mts +58 -0
  212. package/dist/host/http.d.mts.map +1 -0
  213. package/dist/host/http.mjs +336 -0
  214. package/dist/host/http.mjs.map +1 -0
  215. package/dist/host/{router.cjs → ingest.cjs} +147 -175
  216. package/dist/host/ingest.cjs.map +1 -0
  217. package/dist/host/{router.d.cts → ingest.d.cts} +48 -30
  218. package/dist/host/ingest.d.cts.map +1 -0
  219. package/dist/host/{router.d.mts → ingest.d.mts} +48 -30
  220. package/dist/host/ingest.d.mts.map +1 -0
  221. package/dist/host/{router.mjs → ingest.mjs} +144 -173
  222. package/dist/host/ingest.mjs.map +1 -0
  223. package/dist/host/journey-host.cjs +66 -93
  224. package/dist/host/journey-host.cjs.map +1 -1
  225. package/dist/host/journey-host.d.cts +31 -26
  226. package/dist/host/journey-host.d.cts.map +1 -1
  227. package/dist/host/journey-host.d.mts +31 -26
  228. package/dist/host/journey-host.d.mts.map +1 -1
  229. package/dist/host/journey-host.mjs +66 -93
  230. package/dist/host/journey-host.mjs.map +1 -1
  231. package/dist/host/platform.cjs +21 -0
  232. package/dist/host/platform.cjs.map +1 -0
  233. package/dist/host/platform.d.cts +126 -0
  234. package/dist/host/platform.d.cts.map +1 -0
  235. package/dist/host/platform.d.mts +126 -0
  236. package/dist/host/platform.d.mts.map +1 -0
  237. package/dist/host/platform.mjs +19 -0
  238. package/dist/host/platform.mjs.map +1 -0
  239. package/dist/host/senders.cjs +18 -9
  240. package/dist/host/senders.cjs.map +1 -1
  241. package/dist/host/senders.d.cts +9 -4
  242. package/dist/host/senders.d.cts.map +1 -1
  243. package/dist/host/senders.d.mts +9 -4
  244. package/dist/host/senders.d.mts.map +1 -1
  245. package/dist/host/senders.mjs +18 -9
  246. package/dist/host/senders.mjs.map +1 -1
  247. package/dist/index.cjs +1 -1
  248. package/dist/index.mjs +1 -1
  249. package/dist/ir.cjs +5 -7
  250. package/dist/ir.cjs.map +1 -1
  251. package/dist/ir.d.cts +3 -12
  252. package/dist/ir.d.cts.map +1 -1
  253. package/dist/ir.d.mts +3 -12
  254. package/dist/ir.d.mts.map +1 -1
  255. package/dist/ir.mjs +5 -7
  256. package/dist/ir.mjs.map +1 -1
  257. package/dist/plan.cjs +27 -33
  258. package/dist/plan.cjs.map +1 -1
  259. package/dist/plan.d.cts +1 -1
  260. package/dist/plan.d.cts.map +1 -1
  261. package/dist/plan.d.mts +1 -1
  262. package/dist/plan.d.mts.map +1 -1
  263. package/dist/plan.mjs +27 -33
  264. package/dist/plan.mjs.map +1 -1
  265. package/dist/reporting/tracking.cjs +14 -4
  266. package/dist/reporting/tracking.cjs.map +1 -1
  267. package/dist/reporting/tracking.d.cts +10 -10
  268. package/dist/reporting/tracking.d.cts.map +1 -1
  269. package/dist/reporting/tracking.d.mts +10 -10
  270. package/dist/reporting/tracking.d.mts.map +1 -1
  271. package/dist/reporting/tracking.mjs +14 -4
  272. package/dist/reporting/tracking.mjs.map +1 -1
  273. package/dist/store/d1.cjs +88 -29
  274. package/dist/store/d1.cjs.map +1 -1
  275. package/dist/store/d1.d.cts +29 -11
  276. package/dist/store/d1.d.cts.map +1 -1
  277. package/dist/store/d1.d.mts +29 -11
  278. package/dist/store/d1.d.mts.map +1 -1
  279. package/dist/store/d1.mjs +88 -29
  280. package/dist/store/d1.mjs.map +1 -1
  281. package/dist/store/erasure.cjs +22 -0
  282. package/dist/store/erasure.cjs.map +1 -0
  283. package/dist/store/erasure.d.cts +18 -0
  284. package/dist/store/erasure.d.cts.map +1 -0
  285. package/dist/store/erasure.d.mts +18 -0
  286. package/dist/store/erasure.d.mts.map +1 -0
  287. package/dist/store/erasure.mjs +21 -0
  288. package/dist/store/erasure.mjs.map +1 -0
  289. package/dist/store/index.cjs +2 -0
  290. package/dist/store/index.cjs.map +1 -1
  291. package/dist/store/index.d.cts +67 -13
  292. package/dist/store/index.d.cts.map +1 -1
  293. package/dist/store/index.d.mts +67 -13
  294. package/dist/store/index.d.mts.map +1 -1
  295. package/dist/store/index.mjs +2 -1
  296. package/dist/store/index.mjs.map +1 -1
  297. package/dist/store/postgres-reporting.cjs +125 -62
  298. package/dist/store/postgres-reporting.cjs.map +1 -1
  299. package/dist/store/postgres-reporting.d.cts +30 -2
  300. package/dist/store/postgres-reporting.d.cts.map +1 -1
  301. package/dist/store/postgres-reporting.d.mts +30 -2
  302. package/dist/store/postgres-reporting.d.mts.map +1 -1
  303. package/dist/store/postgres-reporting.mjs +125 -62
  304. package/dist/store/postgres-reporting.mjs.map +1 -1
  305. package/dist/store/postgres.cjs +179 -60
  306. package/dist/store/postgres.cjs.map +1 -1
  307. package/dist/store/postgres.d.cts +44 -7
  308. package/dist/store/postgres.d.cts.map +1 -1
  309. package/dist/store/postgres.d.mts +44 -7
  310. package/dist/store/postgres.d.mts.map +1 -1
  311. package/dist/store/postgres.mjs +179 -60
  312. package/dist/store/postgres.mjs.map +1 -1
  313. package/dist/store/tables.cjs +7 -5
  314. package/dist/store/tables.cjs.map +1 -1
  315. package/dist/store/tables.d.cts.map +1 -1
  316. package/dist/store/tables.d.mts.map +1 -1
  317. package/dist/store/tables.mjs +7 -5
  318. package/dist/store/tables.mjs.map +1 -1
  319. package/dist/store/user-lock.cjs +43 -0
  320. package/dist/store/user-lock.cjs.map +1 -0
  321. package/dist/store/user-lock.d.cts +32 -0
  322. package/dist/store/user-lock.d.cts.map +1 -0
  323. package/dist/store/user-lock.d.mts +32 -0
  324. package/dist/store/user-lock.d.mts.map +1 -0
  325. package/dist/store/user-lock.mjs +40 -0
  326. package/dist/store/user-lock.mjs.map +1 -0
  327. package/dist/transports/cloudflare-email.cjs +1 -1
  328. package/dist/transports/cloudflare-email.mjs +1 -1
  329. package/dist/transports/ses.cjs +47 -6
  330. package/dist/transports/ses.cjs.map +1 -1
  331. package/dist/transports/ses.d.cts +9 -1
  332. package/dist/transports/ses.d.cts.map +1 -1
  333. package/dist/transports/ses.d.mts +9 -1
  334. package/dist/transports/ses.d.mts.map +1 -1
  335. package/dist/transports/ses.mjs +47 -7
  336. package/dist/transports/ses.mjs.map +1 -1
  337. package/dist/webpush.cjs +133 -47
  338. package/dist/webpush.cjs.map +1 -1
  339. package/dist/webpush.d.cts +49 -8
  340. package/dist/webpush.d.cts.map +1 -1
  341. package/dist/webpush.d.mts +49 -8
  342. package/dist/webpush.d.mts.map +1 -1
  343. package/dist/webpush.mjs +130 -47
  344. package/dist/webpush.mjs.map +1 -1
  345. package/package.json +1 -1
  346. package/src/cloudflare/schema.sql +27 -6
  347. package/dist/host/router.cjs.map +0 -1
  348. package/dist/host/router.d.cts.map +0 -1
  349. package/dist/host/router.d.mts.map +0 -1
  350. package/dist/host/router.mjs.map +0 -1
@@ -1,19 +1,7 @@
1
1
  import { TriggerIR } from "../ir.cjs";
2
- import { JourneyEnv } from "../cloudflare/bindings.cjs";
2
+ import { JourneyEnv } from "./platform.cjs";
3
3
  import { BundleVersion, JourneyStore, ProfileProps } from "../store/index.cjs";
4
- import { Contract } from "../contract.cjs";
5
- //#region src/host/router.d.ts
6
- /**
7
- * Ingest router. An incoming event does four things: it is stored, it wakes
8
- * waiting instances, it is matched against event triggers, and it re-evaluates
9
- * segment-trigger membership. Plus /deploy (persist a bundle) and /identify
10
- * (merge a profile — which wakes property-condition waits via
11
- * PROFILE_UPDATED_EVENT and re-evaluates segment triggers too).
12
- *
13
- * Storage goes through a JourneyStore; the `store` argument defaults to the
14
- * D1 + KV store built from the env's bindings, so a Worker that only has those
15
- * calls these functions exactly as before.
16
- */
4
+ //#region src/host/ingest.d.ts
17
5
  export interface IngestInput {
18
6
  userId: string;
19
7
  event: string;
@@ -44,6 +32,12 @@ export interface IngestResult {
44
32
  started: string[];
45
33
  }
46
34
  export declare function ingestEvent(env: JourneyEnv, input: IngestInput, store?: JourneyStore): Promise<IngestResult>;
35
+ /**
36
+ * Wake every instance of the user waiting on any of `events`, once each: an instance subscribed
37
+ * to several of them (a wait on two profile properties, patched together) gets one wake-up, and
38
+ * the payload names the first event it matched.
39
+ */
40
+ export declare function wakeSubscribers(env: JourneyEnv, store: JourneyStore, userId: string, events: readonly string[]): Promise<number>;
47
41
  /**
48
42
  * Segment-entry triggers, maintained lazily: on each ingest/identify for a
49
43
  * user, re-evaluate every trigger-routed segment for that user and act on the
@@ -63,12 +57,43 @@ export interface SweepResult {
63
57
  size: number;
64
58
  }[];
65
59
  }
60
+ /** How many users one sweep page evaluates: a unit of resumable work (AWS checkpoints each). */
61
+ export declare const SWEEP_PAGE_SIZE = 500;
62
+ /**
63
+ * What the sweep does before it looks at any user: the runtime's own upkeep (AWS: unconfirmed
64
+ * starts, executions that ended unseen) and the erasures left unfinished (an instance would not
65
+ * stop). A failure of either is logged, never fatal: the pages still run. Users whose erasure is
66
+ * still pending afterwards are skipped by every page (`sweepSegmentsPaged`).
67
+ */
68
+ export declare function sweepMaintenance(env: JourneyEnv, store: JourneyStore): Promise<void>;
69
+ export interface SweepPage {
70
+ /** Users evaluated on this page (those being erased are listed but skipped). */
71
+ users: number;
72
+ /** Journeys the segments' entries started on this page. */
73
+ started: string[];
74
+ /** The last user id listed, to resume past (`after`); undefined when the page was empty. */
75
+ lastUserId?: string | undefined;
76
+ /** Whether the page was full, so another may follow. */
77
+ more: boolean;
78
+ }
79
+ /**
80
+ * One page of the sweep: the users after `after` (ascending, at most `limit`), every deployed
81
+ * segment evaluated for each. The pages are what makes the sweep resumable — a host whose run
82
+ * can be cut short (a Lambda timeout) checkpoints each one and replays the checkpointed pages
83
+ * instead of starting over; `sweepSegments` is the plain loop over them.
84
+ */
85
+ export declare function sweepSegmentsPaged(env: JourneyEnv, store: JourneyStore, page: {
86
+ after?: string | undefined;
87
+ limit?: number | undefined;
88
+ now?: number | undefined;
89
+ }): Promise<SweepPage>;
66
90
  /**
67
91
  * The scheduled sweep: every deployed segment evaluated for every known user — the evaluator a
68
92
  * journey's conditions run on, so a member is exactly who a journey would see in it. Membership
69
93
  * follows (joiners keep the time they joined, leavers are removed), segment triggers start the
70
94
  * journeys of whoever entered by the clock alone, and the store records each segment's size.
71
- * It walks users one by one: fine for thousands, a large audience wants SQL-side evaluation.
95
+ * It walks users page by page (`sweepSegmentsPaged`): fine for thousands, a large audience wants
96
+ * SQL-side evaluation.
72
97
  */
73
98
  export declare function sweepSegments(env: JourneyEnv, store: JourneyStore, now?: number): Promise<SweepResult>;
74
99
  export interface IdentifyResult {
@@ -99,9 +124,13 @@ export declare function registerDevice(env: JourneyEnv, device: DeviceRegistrati
99
124
  woke: number;
100
125
  }>;
101
126
  /**
102
- * Forget a user (a deleted account): the request is recorded first, then carried out. An
103
- * instance that will not stop leaves it pending — nothing erased yet — and the scheduled sweep
104
- * retries it; `erased: false` says so.
127
+ * Forget a user (a deleted account): the tombstone is committed first, then the erasure carried
128
+ * out. `erased: true` means every admitted runner of theirs was confirmed stopped, the entries
129
+ * never admitted can never run, and the data is deleted — for good, with no time window and no
130
+ * second pass: the tombstone commits under the user's lock, which every write about the user
131
+ * also takes, so nothing of theirs can land after it. An admitted instance that will not stop
132
+ * leaves it pending — nothing erased yet — and the scheduled sweep retries it; `erased: false`
133
+ * says so. A user already erased answers `erased: true` again, with nothing to do.
105
134
  */
106
135
  export declare function forgetUser(env: JourneyEnv, userId: string, store?: JourneyStore, now?: number): Promise<{
107
136
  ok: true;
@@ -157,16 +186,5 @@ export declare class BundleIntegrityError extends Error {
157
186
  * compiled into it; without one it is forced, whatever is live.
158
187
  */
159
188
  export declare function deployBundle(env: JourneyEnv, bundle: unknown, store?: JourneyStore, version?: BundleVersion): Promise<DeployResult>;
160
- /**
161
- * How the ingest API applies a contract: 'enforce' refuses an invalid event or
162
- * patch with a 400 before anything is stored, woken or started; 'report' logs
163
- * the issues (event id, name, field paths — never the payload) and accepts it,
164
- * for checking real producers before turning enforcement on.
165
- */
166
- export interface IngestValidation {
167
- contract?: Contract | undefined;
168
- mode?: 'enforce' | 'report' | undefined;
169
- }
170
- export declare function handleRequest(request: Request, env: JourneyEnv, store?: JourneyStore, validation?: IngestValidation): Promise<Response>;
171
189
  //#endregion
172
- //# sourceMappingURL=router.d.cts.map
190
+ //# sourceMappingURL=ingest.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.d.cts","names":[],"sources":["../../src/host/ingest.ts"],"mappings":";;;;iBA+CiB;EACf;EACA;EACA,UAAU;EACV;;;;;;;;;;;;;;;EAeA;;iBAGe;;EAEf;;EAEA;EACA;EACA;;wBAGoB,YACpB,KAAK,YACL,OAAO,aACP,QAAO,eACN,QAAQ;;;;;;wBAwCW,gBACpB,KAAK,YACL,OAAO,cACP,gBACA,4BACC;;;;;;;;;wBA0EmB,uBACpB,KAAK,YACL,OAAO,cACP,gBACA,aACC;iBA0Fc;EACf;;EAEA;;EAEA;IAAS;IAAiB;;;;qBAIf;;;;;;;wBAQS,iBAAiB,KAAK,YAAY,OAAO,eAAe;iBAkB7D;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;wBASoB,mBACpB,KAAK,YACL,OAAO,cACP;EAAQ;EAA4B;EAA4B;IAC/D,QAAQ;;;;;;;;;wBAsCW,cACpB,KAAK,YACL,OAAO,cACP,eACC,QAAQ;iBAgFM;EACf;EACA,OAAO;EACP;EACA;;;;;;;wBAQoB,aACpB,KAAK,YACL,gBACA,OAAO,cACP,QAAO,eACN,QAAQ;iBAiBM;EACf;EACA;EACA;EACA;;;;;;;wBAQoB,eACpB,KAAK,YACL,QAAQ,oBACR,QAAO,eACN;EAAU;EAAU;;;;;;;;;;;wBA2FD,WACpB,KAAK,YACL,gBACA,QAAO,cACP,eACC;EAAU;EAAU;EAAiB;;;;;;;wBAUlB,aACpB,KAAK,YACL,eACA,QAAO,eACN;EAAU;EAAU;;;wBAQD,aACpB,KAAK,YACL,eACA,QAAO,eACN;EAAU;EAAU;;iBASN;EACf;;;;;;;;EAQA;IAAY;IAAkB,SAAS;;;;;;EAKvC;;;qBAIW,8BAA8B;WACvB;EAClB;;;qBAMW,6BAA6B;EACxC,YAAY;;;;;;;;wBA8CQ,aACpB,KAAK,YACL,iBACA,QAAO,cACP,UAAU,gBACT,QAAQ"}
@@ -1,19 +1,7 @@
1
1
  import { TriggerIR } from "../ir.mjs";
2
- import { JourneyEnv } from "../cloudflare/bindings.mjs";
2
+ import { JourneyEnv } from "./platform.mjs";
3
3
  import { BundleVersion, JourneyStore, ProfileProps } from "../store/index.mjs";
4
- import { Contract } from "../contract.mjs";
5
- //#region src/host/router.d.ts
6
- /**
7
- * Ingest router. An incoming event does four things: it is stored, it wakes
8
- * waiting instances, it is matched against event triggers, and it re-evaluates
9
- * segment-trigger membership. Plus /deploy (persist a bundle) and /identify
10
- * (merge a profile — which wakes property-condition waits via
11
- * PROFILE_UPDATED_EVENT and re-evaluates segment triggers too).
12
- *
13
- * Storage goes through a JourneyStore; the `store` argument defaults to the
14
- * D1 + KV store built from the env's bindings, so a Worker that only has those
15
- * calls these functions exactly as before.
16
- */
4
+ //#region src/host/ingest.d.ts
17
5
  export interface IngestInput {
18
6
  userId: string;
19
7
  event: string;
@@ -44,6 +32,12 @@ export interface IngestResult {
44
32
  started: string[];
45
33
  }
46
34
  export declare function ingestEvent(env: JourneyEnv, input: IngestInput, store?: JourneyStore): Promise<IngestResult>;
35
+ /**
36
+ * Wake every instance of the user waiting on any of `events`, once each: an instance subscribed
37
+ * to several of them (a wait on two profile properties, patched together) gets one wake-up, and
38
+ * the payload names the first event it matched.
39
+ */
40
+ export declare function wakeSubscribers(env: JourneyEnv, store: JourneyStore, userId: string, events: readonly string[]): Promise<number>;
47
41
  /**
48
42
  * Segment-entry triggers, maintained lazily: on each ingest/identify for a
49
43
  * user, re-evaluate every trigger-routed segment for that user and act on the
@@ -63,12 +57,43 @@ export interface SweepResult {
63
57
  size: number;
64
58
  }[];
65
59
  }
60
+ /** How many users one sweep page evaluates: a unit of resumable work (AWS checkpoints each). */
61
+ export declare const SWEEP_PAGE_SIZE = 500;
62
+ /**
63
+ * What the sweep does before it looks at any user: the runtime's own upkeep (AWS: unconfirmed
64
+ * starts, executions that ended unseen) and the erasures left unfinished (an instance would not
65
+ * stop). A failure of either is logged, never fatal: the pages still run. Users whose erasure is
66
+ * still pending afterwards are skipped by every page (`sweepSegmentsPaged`).
67
+ */
68
+ export declare function sweepMaintenance(env: JourneyEnv, store: JourneyStore): Promise<void>;
69
+ export interface SweepPage {
70
+ /** Users evaluated on this page (those being erased are listed but skipped). */
71
+ users: number;
72
+ /** Journeys the segments' entries started on this page. */
73
+ started: string[];
74
+ /** The last user id listed, to resume past (`after`); undefined when the page was empty. */
75
+ lastUserId?: string | undefined;
76
+ /** Whether the page was full, so another may follow. */
77
+ more: boolean;
78
+ }
79
+ /**
80
+ * One page of the sweep: the users after `after` (ascending, at most `limit`), every deployed
81
+ * segment evaluated for each. The pages are what makes the sweep resumable — a host whose run
82
+ * can be cut short (a Lambda timeout) checkpoints each one and replays the checkpointed pages
83
+ * instead of starting over; `sweepSegments` is the plain loop over them.
84
+ */
85
+ export declare function sweepSegmentsPaged(env: JourneyEnv, store: JourneyStore, page: {
86
+ after?: string | undefined;
87
+ limit?: number | undefined;
88
+ now?: number | undefined;
89
+ }): Promise<SweepPage>;
66
90
  /**
67
91
  * The scheduled sweep: every deployed segment evaluated for every known user — the evaluator a
68
92
  * journey's conditions run on, so a member is exactly who a journey would see in it. Membership
69
93
  * follows (joiners keep the time they joined, leavers are removed), segment triggers start the
70
94
  * journeys of whoever entered by the clock alone, and the store records each segment's size.
71
- * It walks users one by one: fine for thousands, a large audience wants SQL-side evaluation.
95
+ * It walks users page by page (`sweepSegmentsPaged`): fine for thousands, a large audience wants
96
+ * SQL-side evaluation.
72
97
  */
73
98
  export declare function sweepSegments(env: JourneyEnv, store: JourneyStore, now?: number): Promise<SweepResult>;
74
99
  export interface IdentifyResult {
@@ -99,9 +124,13 @@ export declare function registerDevice(env: JourneyEnv, device: DeviceRegistrati
99
124
  woke: number;
100
125
  }>;
101
126
  /**
102
- * Forget a user (a deleted account): the request is recorded first, then carried out. An
103
- * instance that will not stop leaves it pending — nothing erased yet — and the scheduled sweep
104
- * retries it; `erased: false` says so.
127
+ * Forget a user (a deleted account): the tombstone is committed first, then the erasure carried
128
+ * out. `erased: true` means every admitted runner of theirs was confirmed stopped, the entries
129
+ * never admitted can never run, and the data is deleted — for good, with no time window and no
130
+ * second pass: the tombstone commits under the user's lock, which every write about the user
131
+ * also takes, so nothing of theirs can land after it. An admitted instance that will not stop
132
+ * leaves it pending — nothing erased yet — and the scheduled sweep retries it; `erased: false`
133
+ * says so. A user already erased answers `erased: true` again, with nothing to do.
105
134
  */
106
135
  export declare function forgetUser(env: JourneyEnv, userId: string, store?: JourneyStore, now?: number): Promise<{
107
136
  ok: true;
@@ -157,16 +186,5 @@ export declare class BundleIntegrityError extends Error {
157
186
  * compiled into it; without one it is forced, whatever is live.
158
187
  */
159
188
  export declare function deployBundle(env: JourneyEnv, bundle: unknown, store?: JourneyStore, version?: BundleVersion): Promise<DeployResult>;
160
- /**
161
- * How the ingest API applies a contract: 'enforce' refuses an invalid event or
162
- * patch with a 400 before anything is stored, woken or started; 'report' logs
163
- * the issues (event id, name, field paths — never the payload) and accepts it,
164
- * for checking real producers before turning enforcement on.
165
- */
166
- export interface IngestValidation {
167
- contract?: Contract | undefined;
168
- mode?: 'enforce' | 'report' | undefined;
169
- }
170
- export declare function handleRequest(request: Request, env: JourneyEnv, store?: JourneyStore, validation?: IngestValidation): Promise<Response>;
171
189
  //#endregion
172
- //# sourceMappingURL=router.d.mts.map
190
+ //# sourceMappingURL=ingest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ingest.d.mts","names":[],"sources":["../../src/host/ingest.ts"],"mappings":";;;;iBA+CiB;EACf;EACA;EACA,UAAU;EACV;;;;;;;;;;;;;;;EAeA;;iBAGe;;EAEf;;EAEA;EACA;EACA;;wBAGoB,YACpB,KAAK,YACL,OAAO,aACP,QAAO,eACN,QAAQ;;;;;;wBAwCW,gBACpB,KAAK,YACL,OAAO,cACP,gBACA,4BACC;;;;;;;;;wBA0EmB,uBACpB,KAAK,YACL,OAAO,cACP,gBACA,aACC;iBA0Fc;EACf;;EAEA;;EAEA;IAAS;IAAiB;;;;qBAIf;;;;;;;wBAQS,iBAAiB,KAAK,YAAY,OAAO,eAAe;iBAkB7D;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;wBASoB,mBACpB,KAAK,YACL,OAAO,cACP;EAAQ;EAA4B;EAA4B;IAC/D,QAAQ;;;;;;;;;wBAsCW,cACpB,KAAK,YACL,OAAO,cACP,eACC,QAAQ;iBAgFM;EACf;EACA,OAAO;EACP;EACA;;;;;;;wBAQoB,aACpB,KAAK,YACL,gBACA,OAAO,cACP,QAAO,eACN,QAAQ;iBAiBM;EACf;EACA;EACA;EACA;;;;;;;wBAQoB,eACpB,KAAK,YACL,QAAQ,oBACR,QAAO,eACN;EAAU;EAAU;;;;;;;;;;;wBA2FD,WACpB,KAAK,YACL,gBACA,QAAO,cACP,eACC;EAAU;EAAU;EAAiB;;;;;;;wBAUlB,aACpB,KAAK,YACL,eACA,QAAO,eACN;EAAU;EAAU;;;wBAQD,aACpB,KAAK,YACL,eACA,QAAO,eACN;EAAU;EAAU;;iBASN;EACf;;;;;;;;EAQA;IAAY;IAAkB,SAAS;;;;;;EAKvC;;;qBAIW,8BAA8B;WACvB;EAClB;;;qBAMW,6BAA6B;EACxC,YAAY;;;;;;;;wBA8CQ,aACpB,KAAK,YACL,iBACA,QAAO,cACP,UAAU,gBACT,QAAQ"}