sendwend 0.0.0-stage → 12.7.3

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 (680) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2082 -2
  3. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  4. package/dist/apns-relay.cjs +91 -0
  5. package/dist/apns-relay.cjs.map +1 -0
  6. package/dist/apns-relay.d.cts +26 -0
  7. package/dist/apns-relay.d.cts.map +1 -0
  8. package/dist/apns-relay.d.mts +26 -0
  9. package/dist/apns-relay.d.mts.map +1 -0
  10. package/dist/apns-relay.mjs +90 -0
  11. package/dist/apns-relay.mjs.map +1 -0
  12. package/dist/apns.cjs +215 -0
  13. package/dist/apns.cjs.map +1 -0
  14. package/dist/apns.d.cts +110 -0
  15. package/dist/apns.d.cts.map +1 -0
  16. package/dist/apns.d.mts +110 -0
  17. package/dist/apns.d.mts.map +1 -0
  18. package/dist/apns.mjs +207 -0
  19. package/dist/apns.mjs.map +1 -0
  20. package/dist/aws/engine-step.cjs +105 -0
  21. package/dist/aws/engine-step.cjs.map +1 -0
  22. package/dist/aws/engine-step.d.cts +42 -0
  23. package/dist/aws/engine-step.d.cts.map +1 -0
  24. package/dist/aws/engine-step.d.mts +42 -0
  25. package/dist/aws/engine-step.d.mts.map +1 -0
  26. package/dist/aws/engine-step.mjs +103 -0
  27. package/dist/aws/engine-step.mjs.map +1 -0
  28. package/dist/aws/function-url.cjs +53 -0
  29. package/dist/aws/function-url.cjs.map +1 -0
  30. package/dist/aws/function-url.d.cts +36 -0
  31. package/dist/aws/function-url.d.cts.map +1 -0
  32. package/dist/aws/function-url.d.mts +36 -0
  33. package/dist/aws/function-url.d.mts.map +1 -0
  34. package/dist/aws/function-url.mjs +50 -0
  35. package/dist/aws/function-url.mjs.map +1 -0
  36. package/dist/aws/index.cjs +232 -0
  37. package/dist/aws/index.cjs.map +1 -0
  38. package/dist/aws/index.d.cts +73 -0
  39. package/dist/aws/index.d.cts.map +1 -0
  40. package/dist/aws/index.d.mts +73 -0
  41. package/dist/aws/index.d.mts.map +1 -0
  42. package/dist/aws/index.mjs +218 -0
  43. package/dist/aws/index.mjs.map +1 -0
  44. package/dist/aws/instances.cjs +218 -0
  45. package/dist/aws/instances.cjs.map +1 -0
  46. package/dist/aws/instances.d.cts +102 -0
  47. package/dist/aws/instances.d.cts.map +1 -0
  48. package/dist/aws/instances.d.mts +102 -0
  49. package/dist/aws/instances.d.mts.map +1 -0
  50. package/dist/aws/instances.mjs +214 -0
  51. package/dist/aws/instances.mjs.map +1 -0
  52. package/dist/aws/lambda-api.cjs +86 -0
  53. package/dist/aws/lambda-api.cjs.map +1 -0
  54. package/dist/aws/lambda-api.d.cts +41 -0
  55. package/dist/aws/lambda-api.d.cts.map +1 -0
  56. package/dist/aws/lambda-api.d.mts +41 -0
  57. package/dist/aws/lambda-api.d.mts.map +1 -0
  58. package/dist/aws/lambda-api.mjs +85 -0
  59. package/dist/aws/lambda-api.mjs.map +1 -0
  60. package/dist/client.cjs +216 -0
  61. package/dist/client.cjs.map +1 -0
  62. package/dist/client.d.cts +193 -0
  63. package/dist/client.d.cts.map +1 -0
  64. package/dist/client.d.mts +193 -0
  65. package/dist/client.d.mts.map +1 -0
  66. package/dist/client.mjs +212 -0
  67. package/dist/client.mjs.map +1 -0
  68. package/dist/cloudflare/bindings.cjs +49 -0
  69. package/dist/cloudflare/bindings.cjs.map +1 -0
  70. package/dist/cloudflare/bindings.d.cts +31 -0
  71. package/dist/cloudflare/bindings.d.cts.map +1 -0
  72. package/dist/cloudflare/bindings.d.mts +31 -0
  73. package/dist/cloudflare/bindings.d.mts.map +1 -0
  74. package/dist/cloudflare/bindings.mjs +46 -0
  75. package/dist/cloudflare/bindings.mjs.map +1 -0
  76. package/dist/cloudflare/index.cjs +73 -0
  77. package/dist/cloudflare/index.d.cts +25 -0
  78. package/dist/cloudflare/index.d.mts +25 -0
  79. package/dist/cloudflare/index.mjs +20 -0
  80. package/dist/cloudflare/runner.cjs +200 -0
  81. package/dist/cloudflare/runner.cjs.map +1 -0
  82. package/dist/cloudflare/runner.d.cts +83 -0
  83. package/dist/cloudflare/runner.d.cts.map +1 -0
  84. package/dist/cloudflare/runner.d.mts +83 -0
  85. package/dist/cloudflare/runner.d.mts.map +1 -0
  86. package/dist/cloudflare/runner.mjs +199 -0
  87. package/dist/cloudflare/runner.mjs.map +1 -0
  88. package/dist/cloudflare/worker.cjs +106 -0
  89. package/dist/cloudflare/worker.cjs.map +1 -0
  90. package/dist/cloudflare/worker.d.cts +52 -0
  91. package/dist/cloudflare/worker.d.cts.map +1 -0
  92. package/dist/cloudflare/worker.d.mts +52 -0
  93. package/dist/cloudflare/worker.d.mts.map +1 -0
  94. package/dist/cloudflare/worker.mjs +104 -0
  95. package/dist/cloudflare/worker.mjs.map +1 -0
  96. package/dist/cloudflare/workers.d.cjs +0 -0
  97. package/dist/cloudflare/workers.d.cts +42 -0
  98. package/dist/cloudflare/workers.d.cts.map +1 -0
  99. package/dist/cloudflare/workers.d.mts +42 -0
  100. package/dist/cloudflare/workers.d.mts.map +1 -0
  101. package/dist/config.cjs +257 -0
  102. package/dist/config.cjs.map +1 -0
  103. package/dist/config.d.cts +184 -0
  104. package/dist/config.d.cts.map +1 -0
  105. package/dist/config.d.mts +184 -0
  106. package/dist/config.d.mts.map +1 -0
  107. package/dist/config.mjs +246 -0
  108. package/dist/config.mjs.map +1 -0
  109. package/dist/contract.cjs +222 -0
  110. package/dist/contract.cjs.map +1 -0
  111. package/dist/contract.d.cts +110 -0
  112. package/dist/contract.d.cts.map +1 -0
  113. package/dist/contract.d.mts +110 -0
  114. package/dist/contract.d.mts.map +1 -0
  115. package/dist/contract.mjs +216 -0
  116. package/dist/contract.mjs.map +1 -0
  117. package/dist/date-time.cjs +22 -0
  118. package/dist/date-time.cjs.map +1 -0
  119. package/dist/date-time.d.cts +10 -0
  120. package/dist/date-time.d.cts.map +1 -0
  121. package/dist/date-time.d.mts +10 -0
  122. package/dist/date-time.d.mts.map +1 -0
  123. package/dist/date-time.mjs +21 -0
  124. package/dist/date-time.mjs.map +1 -0
  125. package/dist/dsl/action.cjs +25 -0
  126. package/dist/dsl/action.cjs.map +1 -0
  127. package/dist/dsl/action.d.cts +63 -0
  128. package/dist/dsl/action.d.cts.map +1 -0
  129. package/dist/dsl/action.d.mts +63 -0
  130. package/dist/dsl/action.d.mts.map +1 -0
  131. package/dist/dsl/action.mjs +24 -0
  132. package/dist/dsl/action.mjs.map +1 -0
  133. package/dist/dsl/base.cjs +33 -0
  134. package/dist/dsl/base.cjs.map +1 -0
  135. package/dist/dsl/base.d.cts +43 -0
  136. package/dist/dsl/base.d.cts.map +1 -0
  137. package/dist/dsl/base.d.mts +43 -0
  138. package/dist/dsl/base.d.mts.map +1 -0
  139. package/dist/dsl/base.mjs +29 -0
  140. package/dist/dsl/base.mjs.map +1 -0
  141. package/dist/dsl/bundle.cjs +287 -0
  142. package/dist/dsl/bundle.cjs.map +1 -0
  143. package/dist/dsl/bundle.d.cts +33 -0
  144. package/dist/dsl/bundle.d.cts.map +1 -0
  145. package/dist/dsl/bundle.d.mts +33 -0
  146. package/dist/dsl/bundle.d.mts.map +1 -0
  147. package/dist/dsl/bundle.mjs +284 -0
  148. package/dist/dsl/bundle.mjs.map +1 -0
  149. package/dist/dsl/condition.cjs +200 -0
  150. package/dist/dsl/condition.cjs.map +1 -0
  151. package/dist/dsl/condition.d.cts +151 -0
  152. package/dist/dsl/condition.d.cts.map +1 -0
  153. package/dist/dsl/condition.d.mts +151 -0
  154. package/dist/dsl/condition.d.mts.map +1 -0
  155. package/dist/dsl/condition.mjs +178 -0
  156. package/dist/dsl/condition.mjs.map +1 -0
  157. package/dist/dsl/flow.cjs +335 -0
  158. package/dist/dsl/flow.cjs.map +1 -0
  159. package/dist/dsl/flow.d.cts +278 -0
  160. package/dist/dsl/flow.d.cts.map +1 -0
  161. package/dist/dsl/flow.d.mts +278 -0
  162. package/dist/dsl/flow.d.mts.map +1 -0
  163. package/dist/dsl/flow.mjs +331 -0
  164. package/dist/dsl/flow.mjs.map +1 -0
  165. package/dist/dsl/index.cjs +37 -0
  166. package/dist/dsl/index.d.cts +34 -0
  167. package/dist/dsl/index.d.mts +34 -0
  168. package/dist/dsl/index.mjs +9 -0
  169. package/dist/dsl/refs.cjs +101 -0
  170. package/dist/dsl/refs.cjs.map +1 -0
  171. package/dist/dsl/refs.d.cts +127 -0
  172. package/dist/dsl/refs.d.cts.map +1 -0
  173. package/dist/dsl/refs.d.mts +127 -0
  174. package/dist/dsl/refs.d.mts.map +1 -0
  175. package/dist/dsl/refs.mjs +93 -0
  176. package/dist/dsl/refs.mjs.map +1 -0
  177. package/dist/dsl/template.cjs +19 -0
  178. package/dist/dsl/template.cjs.map +1 -0
  179. package/dist/dsl/template.d.cts +30 -0
  180. package/dist/dsl/template.d.cts.map +1 -0
  181. package/dist/dsl/template.d.mts +30 -0
  182. package/dist/dsl/template.d.mts.map +1 -0
  183. package/dist/dsl/template.mjs +18 -0
  184. package/dist/dsl/template.mjs.map +1 -0
  185. package/dist/dsl/trigger.cjs +53 -0
  186. package/dist/dsl/trigger.cjs.map +1 -0
  187. package/dist/dsl/trigger.d.cts +112 -0
  188. package/dist/dsl/trigger.d.cts.map +1 -0
  189. package/dist/dsl/trigger.d.mts +112 -0
  190. package/dist/dsl/trigger.d.mts.map +1 -0
  191. package/dist/dsl/trigger.mjs +52 -0
  192. package/dist/dsl/trigger.mjs.map +1 -0
  193. package/dist/dsl/workflow.cjs +143 -0
  194. package/dist/dsl/workflow.cjs.map +1 -0
  195. package/dist/dsl/workflow.d.cts +88 -0
  196. package/dist/dsl/workflow.d.cts.map +1 -0
  197. package/dist/dsl/workflow.d.mts +88 -0
  198. package/dist/dsl/workflow.d.mts.map +1 -0
  199. package/dist/dsl/workflow.mjs +142 -0
  200. package/dist/dsl/workflow.mjs.map +1 -0
  201. package/dist/email-context.cjs +28 -0
  202. package/dist/email-context.cjs.map +1 -0
  203. package/dist/email-context.d.cts +9 -0
  204. package/dist/email-context.d.cts.map +1 -0
  205. package/dist/email-context.d.mts +9 -0
  206. package/dist/email-context.d.mts.map +1 -0
  207. package/dist/email-context.mjs +26 -0
  208. package/dist/email-context.mjs.map +1 -0
  209. package/dist/email-sender.cjs +93 -0
  210. package/dist/email-sender.cjs.map +1 -0
  211. package/dist/email-sender.d.cts +88 -0
  212. package/dist/email-sender.d.cts.map +1 -0
  213. package/dist/email-sender.d.mts +88 -0
  214. package/dist/email-sender.d.mts.map +1 -0
  215. package/dist/email-sender.mjs +90 -0
  216. package/dist/email-sender.mjs.map +1 -0
  217. package/dist/email.cjs +73 -0
  218. package/dist/email.cjs.map +1 -0
  219. package/dist/email.d.cts +59 -0
  220. package/dist/email.d.cts.map +1 -0
  221. package/dist/email.d.mts +59 -0
  222. package/dist/email.d.mts.map +1 -0
  223. package/dist/email.mjs +68 -0
  224. package/dist/email.mjs.map +1 -0
  225. package/dist/engine/actions.cjs +19 -0
  226. package/dist/engine/actions.cjs.map +1 -0
  227. package/dist/engine/actions.d.cts +27 -0
  228. package/dist/engine/actions.d.cts.map +1 -0
  229. package/dist/engine/actions.d.mts +27 -0
  230. package/dist/engine/actions.d.mts.map +1 -0
  231. package/dist/engine/actions.mjs +18 -0
  232. package/dist/engine/actions.mjs.map +1 -0
  233. package/dist/engine/bucket.cjs +71 -0
  234. package/dist/engine/bucket.cjs.map +1 -0
  235. package/dist/engine/bucket.d.cts +30 -0
  236. package/dist/engine/bucket.d.cts.map +1 -0
  237. package/dist/engine/bucket.d.mts +30 -0
  238. package/dist/engine/bucket.d.mts.map +1 -0
  239. package/dist/engine/bucket.mjs +68 -0
  240. package/dist/engine/bucket.mjs.map +1 -0
  241. package/dist/engine/condition.cjs +199 -0
  242. package/dist/engine/condition.cjs.map +1 -0
  243. package/dist/engine/condition.d.cts +76 -0
  244. package/dist/engine/condition.d.cts.map +1 -0
  245. package/dist/engine/condition.d.mts +76 -0
  246. package/dist/engine/condition.d.mts.map +1 -0
  247. package/dist/engine/condition.mjs +192 -0
  248. package/dist/engine/condition.mjs.map +1 -0
  249. package/dist/engine/duration.cjs +33 -0
  250. package/dist/engine/duration.cjs.map +1 -0
  251. package/dist/engine/duration.d.cts +3 -0
  252. package/dist/engine/duration.d.cts.map +1 -0
  253. package/dist/engine/duration.d.mts +3 -0
  254. package/dist/engine/duration.d.mts.map +1 -0
  255. package/dist/engine/duration.mjs +32 -0
  256. package/dist/engine/duration.mjs.map +1 -0
  257. package/dist/engine/index.cjs +33 -0
  258. package/dist/engine/index.d.cts +10 -0
  259. package/dist/engine/index.d.mts +10 -0
  260. package/dist/engine/index.mjs +9 -0
  261. package/dist/engine/interpreter.cjs +613 -0
  262. package/dist/engine/interpreter.cjs.map +1 -0
  263. package/dist/engine/interpreter.d.cts +4 -0
  264. package/dist/engine/interpreter.d.cts.map +1 -0
  265. package/dist/engine/interpreter.d.mts +4 -0
  266. package/dist/engine/interpreter.d.mts.map +1 -0
  267. package/dist/engine/interpreter.mjs +612 -0
  268. package/dist/engine/interpreter.mjs.map +1 -0
  269. package/dist/engine/ports.cjs +0 -0
  270. package/dist/engine/ports.d.cts +373 -0
  271. package/dist/engine/ports.d.cts.map +1 -0
  272. package/dist/engine/ports.d.mts +373 -0
  273. package/dist/engine/ports.d.mts.map +1 -0
  274. package/dist/engine/ports.mjs +1 -0
  275. package/dist/engine/recipient.cjs +22 -0
  276. package/dist/engine/recipient.cjs.map +1 -0
  277. package/dist/engine/recipient.d.cts +11 -0
  278. package/dist/engine/recipient.d.cts.map +1 -0
  279. package/dist/engine/recipient.d.mts +11 -0
  280. package/dist/engine/recipient.d.mts.map +1 -0
  281. package/dist/engine/recipient.mjs +21 -0
  282. package/dist/engine/recipient.mjs.map +1 -0
  283. package/dist/engine/retry.cjs +106 -0
  284. package/dist/engine/retry.cjs.map +1 -0
  285. package/dist/engine/retry.d.cts +73 -0
  286. package/dist/engine/retry.d.cts.map +1 -0
  287. package/dist/engine/retry.d.mts +73 -0
  288. package/dist/engine/retry.d.mts.map +1 -0
  289. package/dist/engine/retry.mjs +98 -0
  290. package/dist/engine/retry.mjs.map +1 -0
  291. package/dist/engine/time-scale.cjs +153 -0
  292. package/dist/engine/time-scale.cjs.map +1 -0
  293. package/dist/engine/time-scale.d.cts +41 -0
  294. package/dist/engine/time-scale.d.cts.map +1 -0
  295. package/dist/engine/time-scale.d.mts +41 -0
  296. package/dist/engine/time-scale.d.mts.map +1 -0
  297. package/dist/engine/time-scale.mjs +150 -0
  298. package/dist/engine/time-scale.mjs.map +1 -0
  299. package/dist/engine/time-window.cjs +148 -0
  300. package/dist/engine/time-window.cjs.map +1 -0
  301. package/dist/engine/time-window.d.cts +20 -0
  302. package/dist/engine/time-window.d.cts.map +1 -0
  303. package/dist/engine/time-window.d.mts +20 -0
  304. package/dist/engine/time-window.d.mts.map +1 -0
  305. package/dist/engine/time-window.mjs +146 -0
  306. package/dist/engine/time-window.mjs.map +1 -0
  307. package/dist/fcm.cjs +208 -0
  308. package/dist/fcm.cjs.map +1 -0
  309. package/dist/fcm.d.cts +89 -0
  310. package/dist/fcm.d.cts.map +1 -0
  311. package/dist/fcm.d.mts +89 -0
  312. package/dist/fcm.d.mts.map +1 -0
  313. package/dist/fcm.mjs +202 -0
  314. package/dist/fcm.mjs.map +1 -0
  315. package/dist/hash.cjs +244 -0
  316. package/dist/hash.cjs.map +1 -0
  317. package/dist/hash.d.cts +28 -0
  318. package/dist/hash.d.cts.map +1 -0
  319. package/dist/hash.d.mts +28 -0
  320. package/dist/hash.d.mts.map +1 -0
  321. package/dist/hash.mjs +238 -0
  322. package/dist/hash.mjs.map +1 -0
  323. package/dist/host/auth.cjs +48 -0
  324. package/dist/host/auth.cjs.map +1 -0
  325. package/dist/host/auth.d.cts +33 -0
  326. package/dist/host/auth.d.cts.map +1 -0
  327. package/dist/host/auth.d.mts +33 -0
  328. package/dist/host/auth.d.mts.map +1 -0
  329. package/dist/host/auth.mjs +45 -0
  330. package/dist/host/auth.mjs.map +1 -0
  331. package/dist/host/batch.cjs +178 -0
  332. package/dist/host/batch.cjs.map +1 -0
  333. package/dist/host/batch.d.cts +92 -0
  334. package/dist/host/batch.d.cts.map +1 -0
  335. package/dist/host/batch.d.mts +92 -0
  336. package/dist/host/batch.d.mts.map +1 -0
  337. package/dist/host/batch.mjs +169 -0
  338. package/dist/host/batch.mjs.map +1 -0
  339. package/dist/host/channels.cjs +256 -0
  340. package/dist/host/channels.cjs.map +1 -0
  341. package/dist/host/channels.d.cts +66 -0
  342. package/dist/host/channels.d.cts.map +1 -0
  343. package/dist/host/channels.d.mts +66 -0
  344. package/dist/host/channels.d.mts.map +1 -0
  345. package/dist/host/channels.mjs +252 -0
  346. package/dist/host/channels.mjs.map +1 -0
  347. package/dist/host/execute.cjs +102 -0
  348. package/dist/host/execute.cjs.map +1 -0
  349. package/dist/host/execute.d.cts +38 -0
  350. package/dist/host/execute.d.cts.map +1 -0
  351. package/dist/host/execute.d.mts +38 -0
  352. package/dist/host/execute.d.mts.map +1 -0
  353. package/dist/host/execute.mjs +101 -0
  354. package/dist/host/execute.mjs.map +1 -0
  355. package/dist/host/fresh-read.cjs +29 -0
  356. package/dist/host/fresh-read.cjs.map +1 -0
  357. package/dist/host/fresh-read.d.cts +16 -0
  358. package/dist/host/fresh-read.d.cts.map +1 -0
  359. package/dist/host/fresh-read.d.mts +16 -0
  360. package/dist/host/fresh-read.d.mts.map +1 -0
  361. package/dist/host/fresh-read.mjs +28 -0
  362. package/dist/host/fresh-read.mjs.map +1 -0
  363. package/dist/host/http.cjs +393 -0
  364. package/dist/host/http.cjs.map +1 -0
  365. package/dist/host/http.d.cts +61 -0
  366. package/dist/host/http.d.cts.map +1 -0
  367. package/dist/host/http.d.mts +61 -0
  368. package/dist/host/http.d.mts.map +1 -0
  369. package/dist/host/http.mjs +389 -0
  370. package/dist/host/http.mjs.map +1 -0
  371. package/dist/host/ingest.cjs +1210 -0
  372. package/dist/host/ingest.cjs.map +1 -0
  373. package/dist/host/ingest.d.cts +497 -0
  374. package/dist/host/ingest.d.cts.map +1 -0
  375. package/dist/host/ingest.d.mts +497 -0
  376. package/dist/host/ingest.d.mts.map +1 -0
  377. package/dist/host/ingest.mjs +1172 -0
  378. package/dist/host/ingest.mjs.map +1 -0
  379. package/dist/host/journey-host.cjs +223 -0
  380. package/dist/host/journey-host.cjs.map +1 -0
  381. package/dist/host/journey-host.d.cts +118 -0
  382. package/dist/host/journey-host.d.cts.map +1 -0
  383. package/dist/host/journey-host.d.mts +118 -0
  384. package/dist/host/journey-host.d.mts.map +1 -0
  385. package/dist/host/journey-host.mjs +219 -0
  386. package/dist/host/journey-host.mjs.map +1 -0
  387. package/dist/host/platform.cjs +20 -0
  388. package/dist/host/platform.cjs.map +1 -0
  389. package/dist/host/platform.d.cts +120 -0
  390. package/dist/host/platform.d.cts.map +1 -0
  391. package/dist/host/platform.d.mts +120 -0
  392. package/dist/host/platform.d.mts.map +1 -0
  393. package/dist/host/platform.mjs +18 -0
  394. package/dist/host/platform.mjs.map +1 -0
  395. package/dist/host/senders.cjs +71 -0
  396. package/dist/host/senders.cjs.map +1 -0
  397. package/dist/host/senders.d.cts +34 -0
  398. package/dist/host/senders.d.cts.map +1 -0
  399. package/dist/host/senders.d.mts +34 -0
  400. package/dist/host/senders.d.mts.map +1 -0
  401. package/dist/host/senders.mjs +67 -0
  402. package/dist/host/senders.mjs.map +1 -0
  403. package/dist/host/workflow-cache.cjs +47 -0
  404. package/dist/host/workflow-cache.cjs.map +1 -0
  405. package/dist/host/workflow-cache.d.cts +21 -0
  406. package/dist/host/workflow-cache.d.cts.map +1 -0
  407. package/dist/host/workflow-cache.d.mts +21 -0
  408. package/dist/host/workflow-cache.d.mts.map +1 -0
  409. package/dist/host/workflow-cache.mjs +46 -0
  410. package/dist/host/workflow-cache.mjs.map +1 -0
  411. package/dist/http2-client.cjs +89 -0
  412. package/dist/http2-client.cjs.map +1 -0
  413. package/dist/http2-client.d.cts +45 -0
  414. package/dist/http2-client.d.cts.map +1 -0
  415. package/dist/http2-client.d.mts +45 -0
  416. package/dist/http2-client.d.mts.map +1 -0
  417. package/dist/http2-client.mjs +87 -0
  418. package/dist/http2-client.mjs.map +1 -0
  419. package/dist/index.cjs +130 -0
  420. package/dist/index.d.cts +21 -0
  421. package/dist/index.d.mts +21 -0
  422. package/dist/index.mjs +20 -0
  423. package/dist/inflight.cjs +116 -0
  424. package/dist/inflight.cjs.map +1 -0
  425. package/dist/inflight.d.cts +49 -0
  426. package/dist/inflight.d.cts.map +1 -0
  427. package/dist/inflight.d.mts +49 -0
  428. package/dist/inflight.d.mts.map +1 -0
  429. package/dist/inflight.mjs +113 -0
  430. package/dist/inflight.mjs.map +1 -0
  431. package/dist/ir.cjs +429 -0
  432. package/dist/ir.cjs.map +1 -0
  433. package/dist/ir.d.cts +593 -0
  434. package/dist/ir.d.cts.map +1 -0
  435. package/dist/ir.d.mts +593 -0
  436. package/dist/ir.d.mts.map +1 -0
  437. package/dist/ir.mjs +404 -0
  438. package/dist/ir.mjs.map +1 -0
  439. package/dist/jwt.cjs +17 -0
  440. package/dist/jwt.cjs.map +1 -0
  441. package/dist/jwt.d.cts +7 -0
  442. package/dist/jwt.d.cts.map +1 -0
  443. package/dist/jwt.d.mts +7 -0
  444. package/dist/jwt.d.mts.map +1 -0
  445. package/dist/jwt.mjs +15 -0
  446. package/dist/jwt.mjs.map +1 -0
  447. package/dist/node/index.cjs +231 -0
  448. package/dist/node/index.cjs.map +1 -0
  449. package/dist/node/index.d.cts +59 -0
  450. package/dist/node/index.d.cts.map +1 -0
  451. package/dist/node/index.d.mts +59 -0
  452. package/dist/node/index.d.mts.map +1 -0
  453. package/dist/node/index.mjs +225 -0
  454. package/dist/node/index.mjs.map +1 -0
  455. package/dist/node/runs.cjs +222 -0
  456. package/dist/node/runs.cjs.map +1 -0
  457. package/dist/node/runs.d.cts +93 -0
  458. package/dist/node/runs.d.cts.map +1 -0
  459. package/dist/node/runs.d.mts +93 -0
  460. package/dist/node/runs.d.mts.map +1 -0
  461. package/dist/node/runs.mjs +221 -0
  462. package/dist/node/runs.mjs.map +1 -0
  463. package/dist/node/runtime.cjs +351 -0
  464. package/dist/node/runtime.cjs.map +1 -0
  465. package/dist/node/runtime.d.cts +96 -0
  466. package/dist/node/runtime.d.cts.map +1 -0
  467. package/dist/node/runtime.d.mts +96 -0
  468. package/dist/node/runtime.d.mts.map +1 -0
  469. package/dist/node/runtime.mjs +348 -0
  470. package/dist/node/runtime.mjs.map +1 -0
  471. package/dist/plan.cjs +221 -0
  472. package/dist/plan.cjs.map +1 -0
  473. package/dist/plan.d.cts +68 -0
  474. package/dist/plan.d.cts.map +1 -0
  475. package/dist/plan.d.mts +68 -0
  476. package/dist/plan.d.mts.map +1 -0
  477. package/dist/plan.mjs +218 -0
  478. package/dist/plan.mjs.map +1 -0
  479. package/dist/postgres-js.cjs +51 -0
  480. package/dist/postgres-js.cjs.map +1 -0
  481. package/dist/postgres-js.d.cts +32 -0
  482. package/dist/postgres-js.d.cts.map +1 -0
  483. package/dist/postgres-js.d.mts +32 -0
  484. package/dist/postgres-js.d.mts.map +1 -0
  485. package/dist/postgres-js.mjs +46 -0
  486. package/dist/postgres-js.mjs.map +1 -0
  487. package/dist/provenance.cjs +66 -0
  488. package/dist/provenance.cjs.map +1 -0
  489. package/dist/provenance.d.cts +40 -0
  490. package/dist/provenance.d.cts.map +1 -0
  491. package/dist/provenance.d.mts +40 -0
  492. package/dist/provenance.d.mts.map +1 -0
  493. package/dist/provenance.mjs +64 -0
  494. package/dist/provenance.mjs.map +1 -0
  495. package/dist/push.cjs +11 -0
  496. package/dist/push.cjs.map +1 -0
  497. package/dist/push.d.cts +14 -0
  498. package/dist/push.d.cts.map +1 -0
  499. package/dist/push.d.mts +14 -0
  500. package/dist/push.d.mts.map +1 -0
  501. package/dist/push.mjs +10 -0
  502. package/dist/push.mjs.map +1 -0
  503. package/dist/react-email.cjs +56 -0
  504. package/dist/react-email.cjs.map +1 -0
  505. package/dist/react-email.d.cts +5 -0
  506. package/dist/react-email.d.cts.map +1 -0
  507. package/dist/react-email.d.mts +5 -0
  508. package/dist/react-email.d.mts.map +1 -0
  509. package/dist/react-email.mjs +55 -0
  510. package/dist/react-email.mjs.map +1 -0
  511. package/dist/reporting/classify.cjs +46 -0
  512. package/dist/reporting/classify.cjs.map +1 -0
  513. package/dist/reporting/classify.d.cts +65 -0
  514. package/dist/reporting/classify.d.cts.map +1 -0
  515. package/dist/reporting/classify.d.mts +65 -0
  516. package/dist/reporting/classify.d.mts.map +1 -0
  517. package/dist/reporting/classify.mjs +42 -0
  518. package/dist/reporting/classify.mjs.map +1 -0
  519. package/dist/reporting/observer.cjs +137 -0
  520. package/dist/reporting/observer.cjs.map +1 -0
  521. package/dist/reporting/observer.d.cts +31 -0
  522. package/dist/reporting/observer.d.cts.map +1 -0
  523. package/dist/reporting/observer.d.mts +31 -0
  524. package/dist/reporting/observer.d.mts.map +1 -0
  525. package/dist/reporting/observer.mjs +134 -0
  526. package/dist/reporting/observer.mjs.map +1 -0
  527. package/dist/reporting/tracking.cjs +185 -0
  528. package/dist/reporting/tracking.cjs.map +1 -0
  529. package/dist/reporting/tracking.d.cts +63 -0
  530. package/dist/reporting/tracking.d.cts.map +1 -0
  531. package/dist/reporting/tracking.d.mts +63 -0
  532. package/dist/reporting/tracking.d.mts.map +1 -0
  533. package/dist/reporting/tracking.mjs +182 -0
  534. package/dist/reporting/tracking.mjs.map +1 -0
  535. package/dist/runtime.cjs +18 -0
  536. package/dist/runtime.cjs.map +1 -0
  537. package/dist/runtime.d.cts +44 -0
  538. package/dist/runtime.d.cts.map +1 -0
  539. package/dist/runtime.d.mts +44 -0
  540. package/dist/runtime.d.mts.map +1 -0
  541. package/dist/runtime.mjs +17 -0
  542. package/dist/runtime.mjs.map +1 -0
  543. package/dist/store/condition-sql.cjs +145 -0
  544. package/dist/store/condition-sql.cjs.map +1 -0
  545. package/dist/store/condition-sql.d.cts +38 -0
  546. package/dist/store/condition-sql.d.cts.map +1 -0
  547. package/dist/store/condition-sql.d.mts +38 -0
  548. package/dist/store/condition-sql.d.mts.map +1 -0
  549. package/dist/store/condition-sql.mjs +144 -0
  550. package/dist/store/condition-sql.mjs.map +1 -0
  551. package/dist/store/erasure.cjs +21 -0
  552. package/dist/store/erasure.cjs.map +1 -0
  553. package/dist/store/erasure.d.cts +16 -0
  554. package/dist/store/erasure.d.cts.map +1 -0
  555. package/dist/store/erasure.d.mts +16 -0
  556. package/dist/store/erasure.d.mts.map +1 -0
  557. package/dist/store/erasure.mjs +20 -0
  558. package/dist/store/erasure.mjs.map +1 -0
  559. package/dist/store/facts.cjs +79 -0
  560. package/dist/store/facts.cjs.map +1 -0
  561. package/dist/store/facts.d.cts +41 -0
  562. package/dist/store/facts.d.cts.map +1 -0
  563. package/dist/store/facts.d.mts +41 -0
  564. package/dist/store/facts.d.mts.map +1 -0
  565. package/dist/store/facts.mjs +77 -0
  566. package/dist/store/facts.mjs.map +1 -0
  567. package/dist/store/identity.cjs +34 -0
  568. package/dist/store/identity.cjs.map +1 -0
  569. package/dist/store/identity.d.cts +13 -0
  570. package/dist/store/identity.d.cts.map +1 -0
  571. package/dist/store/identity.d.mts +13 -0
  572. package/dist/store/identity.d.mts.map +1 -0
  573. package/dist/store/identity.mjs +30 -0
  574. package/dist/store/identity.mjs.map +1 -0
  575. package/dist/store/index.cjs +35 -0
  576. package/dist/store/index.cjs.map +1 -0
  577. package/dist/store/index.d.cts +766 -0
  578. package/dist/store/index.d.cts.map +1 -0
  579. package/dist/store/index.d.mts +766 -0
  580. package/dist/store/index.d.mts.map +1 -0
  581. package/dist/store/index.mjs +22 -0
  582. package/dist/store/index.mjs.map +1 -0
  583. package/dist/store/postgres-reporting.cjs +327 -0
  584. package/dist/store/postgres-reporting.cjs.map +1 -0
  585. package/dist/store/postgres-reporting.d.cts +95 -0
  586. package/dist/store/postgres-reporting.d.cts.map +1 -0
  587. package/dist/store/postgres-reporting.d.mts +95 -0
  588. package/dist/store/postgres-reporting.d.mts.map +1 -0
  589. package/dist/store/postgres-reporting.mjs +326 -0
  590. package/dist/store/postgres-reporting.mjs.map +1 -0
  591. package/dist/store/postgres.cjs +1173 -0
  592. package/dist/store/postgres.cjs.map +1 -0
  593. package/dist/store/postgres.d.cts +199 -0
  594. package/dist/store/postgres.d.cts.map +1 -0
  595. package/dist/store/postgres.d.mts +199 -0
  596. package/dist/store/postgres.d.mts.map +1 -0
  597. package/dist/store/postgres.mjs +1170 -0
  598. package/dist/store/postgres.mjs.map +1 -0
  599. package/dist/store/sql.cjs +24 -0
  600. package/dist/store/sql.cjs.map +1 -0
  601. package/dist/store/sql.d.cts +26 -0
  602. package/dist/store/sql.d.cts.map +1 -0
  603. package/dist/store/sql.d.mts +26 -0
  604. package/dist/store/sql.d.mts.map +1 -0
  605. package/dist/store/sql.mjs +23 -0
  606. package/dist/store/sql.mjs.map +1 -0
  607. package/dist/store/tables.cjs +660 -0
  608. package/dist/store/tables.cjs.map +1 -0
  609. package/dist/store/tables.d.cts +103 -0
  610. package/dist/store/tables.d.cts.map +1 -0
  611. package/dist/store/tables.d.mts +103 -0
  612. package/dist/store/tables.d.mts.map +1 -0
  613. package/dist/store/tables.mjs +653 -0
  614. package/dist/store/tables.mjs.map +1 -0
  615. package/dist/store/user-lock.cjs +42 -0
  616. package/dist/store/user-lock.cjs.map +1 -0
  617. package/dist/store/user-lock.d.cts +30 -0
  618. package/dist/store/user-lock.d.cts.map +1 -0
  619. package/dist/store/user-lock.d.mts +30 -0
  620. package/dist/store/user-lock.d.mts.map +1 -0
  621. package/dist/store/user-lock.mjs +39 -0
  622. package/dist/store/user-lock.mjs.map +1 -0
  623. package/dist/template-rules.cjs +94 -0
  624. package/dist/template-rules.cjs.map +1 -0
  625. package/dist/template-rules.d.cts +80 -0
  626. package/dist/template-rules.d.cts.map +1 -0
  627. package/dist/template-rules.d.mts +80 -0
  628. package/dist/template-rules.d.mts.map +1 -0
  629. package/dist/template-rules.mjs +86 -0
  630. package/dist/template-rules.mjs.map +1 -0
  631. package/dist/templates.cjs +375 -0
  632. package/dist/templates.cjs.map +1 -0
  633. package/dist/templates.d.cts +358 -0
  634. package/dist/templates.d.cts.map +1 -0
  635. package/dist/templates.d.mts +358 -0
  636. package/dist/templates.d.mts.map +1 -0
  637. package/dist/templates.mjs +353 -0
  638. package/dist/templates.mjs.map +1 -0
  639. package/dist/transports/cloudflare-email.cjs +69 -0
  640. package/dist/transports/cloudflare-email.cjs.map +1 -0
  641. package/dist/transports/cloudflare-email.d.cts +63 -0
  642. package/dist/transports/cloudflare-email.d.cts.map +1 -0
  643. package/dist/transports/cloudflare-email.d.mts +63 -0
  644. package/dist/transports/cloudflare-email.d.mts.map +1 -0
  645. package/dist/transports/cloudflare-email.mjs +67 -0
  646. package/dist/transports/cloudflare-email.mjs.map +1 -0
  647. package/dist/transports/ses.cjs +142 -0
  648. package/dist/transports/ses.cjs.map +1 -0
  649. package/dist/transports/ses.d.cts +49 -0
  650. package/dist/transports/ses.d.cts.map +1 -0
  651. package/dist/transports/ses.d.mts +49 -0
  652. package/dist/transports/ses.d.mts.map +1 -0
  653. package/dist/transports/ses.mjs +139 -0
  654. package/dist/transports/ses.mjs.map +1 -0
  655. package/dist/transports/sigv4.cjs +86 -0
  656. package/dist/transports/sigv4.cjs.map +1 -0
  657. package/dist/transports/sigv4.d.cts +25 -0
  658. package/dist/transports/sigv4.d.cts.map +1 -0
  659. package/dist/transports/sigv4.d.mts +25 -0
  660. package/dist/transports/sigv4.d.mts.map +1 -0
  661. package/dist/transports/sigv4.mjs +85 -0
  662. package/dist/transports/sigv4.mjs.map +1 -0
  663. package/dist/webhooks.cjs +97 -0
  664. package/dist/webhooks.cjs.map +1 -0
  665. package/dist/webhooks.d.cts +23 -0
  666. package/dist/webhooks.d.cts.map +1 -0
  667. package/dist/webhooks.d.mts +23 -0
  668. package/dist/webhooks.d.mts.map +1 -0
  669. package/dist/webhooks.mjs +95 -0
  670. package/dist/webhooks.mjs.map +1 -0
  671. package/dist/webpush.cjs +361 -0
  672. package/dist/webpush.cjs.map +1 -0
  673. package/dist/webpush.d.cts +135 -0
  674. package/dist/webpush.d.cts.map +1 -0
  675. package/dist/webpush.d.mts +135 -0
  676. package/dist/webpush.d.mts.map +1 -0
  677. package/dist/webpush.mjs +350 -0
  678. package/dist/webpush.mjs.map +1 -0
  679. package/package.json +279 -3
  680. package/src/cloudflare/workers.d.ts +44 -0
@@ -0,0 +1,612 @@
1
+ import { hashToBucket } from "./bucket.mjs";
2
+ import { evaluateCondition, payloadScalar, relevantEvents } from "./condition.mjs";
3
+ import { RECIPIENT_PROPERTY } from "./recipient.mjs";
4
+ import { isRefusedSend, isUnanswered, refusalReason } from "./retry.mjs";
5
+ import { nextWindowStart } from "./time-window.mjs";
6
+ // src/engine/interpreter.ts
7
+ /**
8
+ * IR interpreter: the execution core for one user's journey instance.
9
+ *
10
+ * Pure logic — it imports nothing platform-specific; every external effect
11
+ * arrives through the JourneyContext ports, and durable semantics
12
+ * (checkpoint/replay) are the EngineStep adapter's job.
13
+ *
14
+ * Step naming: an IR node id *is* the step name (derived from the structural
15
+ * path, so it is deterministic and unique). When one node needs several steps,
16
+ * a suffix is appended (`${id}:guard`, `${id}:check:${n}`).
17
+ *
18
+ * Guard semantics: goal / exitWhen are checked at journey entry and after
19
+ * every suspension point (delay / random_delay / time_window / wait_until) —
20
+ * the moments where wall-clock time passed and the user's state may have
21
+ * moved. Between two synchronous nodes no meaningful time passes, so checking
22
+ * there would only burn step budget (each checkpoint costs a state write).
23
+ */
24
+ /**
25
+ * Cap on wait_until re-evaluations, so a wake-up storm cannot exhaust the platform's step
26
+ * budget. Each loop iteration costs a handful of steps, so 64 checks stay well inside the
27
+ * platform step budgets while absorbing far more wake churn than 16 did. Past the cap the wait
28
+ * is not given up: it sleeps to its deadline and checks once more there (see waitLoop) — the
29
+ * answer is still right at the deadline, it just stops being event-driven in between.
30
+ */
31
+ const MAX_WAIT_CHECKS = 64;
32
+ /**
33
+ * The user property holding an IANA zone id, read when a time_window says tz: 'user'. Snake case,
34
+ * like the analytics `time_zone` tag a host fills it from. Same convention-table status as
35
+ * RECIPIENT_PROPERTY.
36
+ */
37
+ const TIMEZONE_PROPERTY = "time_zone";
38
+ const FALL_THROUGH = { kind: "fall_through" };
39
+ /** Who a message or report is about now: a journey started by a visitor moves when they sign in. */
40
+ function ownerOf(ctx) {
41
+ return ctx.currentUserId?.() ?? Promise.resolve(ctx.userId);
42
+ }
43
+ const goalStates = /* @__PURE__ */ new WeakMap();
44
+ function goalState(ctx) {
45
+ let state = goalStates.get(ctx);
46
+ if (state === void 0) {
47
+ state = {};
48
+ goalStates.set(ctx, state);
49
+ }
50
+ return state;
51
+ }
52
+ /** When the goal's attribution window closes, measured from entry; none without `within`. */
53
+ function goalDeadline(ir, ctx) {
54
+ return ir.goal?.within === void 0 ? void 0 : ctx.enteredAtMs + ir.goal.within.ms;
55
+ }
56
+ /**
57
+ * Whether the goal holds for events inside its window: after entry, and not after the window
58
+ * closed — an instance resumed past the deadline must not count a purchase made after it. The
59
+ * conversion time is when the check saw it, capped at the deadline.
60
+ */
61
+ async function goalReached(ir, ctx, now) {
62
+ const goal = ir.goal;
63
+ if (goal === void 0) return null;
64
+ const deadline = goalDeadline(ir, ctx);
65
+ return await holds(goal.condition, ctx, now, {
66
+ anchorMs: ctx.enteredAtMs,
67
+ ...ctx.trigger === void 0 ? {} : { after: {
68
+ event: ctx.trigger.event,
69
+ ms: ctx.trigger.ts
70
+ } },
71
+ ...deadline === void 0 ? {} : { untilMs: deadline }
72
+ }) ? { at: deadline === void 0 ? now : Math.min(now, deadline) } : null;
73
+ }
74
+ async function runJourney(ir, ctx) {
75
+ await started(ir, ctx);
76
+ let signal = await checkGuards("entry", ir, ctx) ?? await runFlow(ir.flow, ir, ctx);
77
+ if (signal.kind === "fall_through") signal = await awaitTail(ir, ctx) ?? FALL_THROUGH;
78
+ const { convertedAt } = goalState(ctx);
79
+ const converted = convertedAt === void 0 ? {} : { convertedAt };
80
+ switch (signal.kind) {
81
+ case "fall_through": return {
82
+ status: "completed",
83
+ ...converted
84
+ };
85
+ case "exit": return signal.reason !== void 0 ? {
86
+ status: "exited",
87
+ reason: signal.reason,
88
+ ...converted
89
+ } : {
90
+ status: "exited",
91
+ ...converted
92
+ };
93
+ case "goal": return {
94
+ status: "goal",
95
+ ...converted
96
+ };
97
+ case "exit_when": return {
98
+ status: "exit_when",
99
+ ...converted
100
+ };
101
+ }
102
+ }
103
+ async function runFlow(nodes, ir, ctx) {
104
+ for (const node of nodes) {
105
+ await reached(node, ir, ctx);
106
+ const signal = await runNode(node, ir, ctx);
107
+ if (signal.kind !== "fall_through") return signal;
108
+ }
109
+ return FALL_THROUGH;
110
+ }
111
+ /** The engine's own reports: the same over again, and nothing the journey's path depends on. */
112
+ const BOOKKEEPING = { idempotent: true };
113
+ /**
114
+ * Tell the observer the instance entered — before the entry guards, which can end it before the
115
+ * first node: an instance is counted from its entry, not from its first node.
116
+ */
117
+ async function started(ir, ctx) {
118
+ const observer = ctx.observer;
119
+ if (observer?.started === void 0) return;
120
+ await ctx.step.do("entry:started", async () => {
121
+ await observer.started?.({
122
+ workflow: ir.id,
123
+ instanceId: ctx.instanceId,
124
+ userId: await ownerOf(ctx),
125
+ at: ctx.enteredAtMs
126
+ });
127
+ }, BOOKKEEPING);
128
+ }
129
+ /**
130
+ * Tell the observer the instance is at `node`. A step of its own, so a replay does not report
131
+ * the nodes it passes on the way back again, and the arrival time stays the first one.
132
+ */
133
+ async function reached(node, ir, ctx) {
134
+ const observer = ctx.observer;
135
+ if (observer?.nodeReached === void 0) return;
136
+ await ctx.step.do(`${node.id}:reached`, async () => {
137
+ await observer.nodeReached?.({
138
+ workflow: ir.id,
139
+ instanceId: ctx.instanceId,
140
+ userId: await ownerOf(ctx),
141
+ nodeId: node.id,
142
+ at: Date.now()
143
+ });
144
+ }, BOOKKEEPING);
145
+ }
146
+ /**
147
+ * One copy out through the host's sender, with the observer around it: settled? → prepared
148
+ * (the row, the tracking) → claimed (handed to the transport, committed before the send) →
149
+ * send → sent.
150
+ *
151
+ * Delivery is at most once. A send that throws is a definite failure — the provider answered
152
+ * with a refusal, or the sender never got as far as asking. What happens next depends on whether
153
+ * another attempt could go differently:
154
+ *
155
+ * - it could (a 429, a 5xx, a token that expired): the claim is released, the step retries, and
156
+ * the copy is reported when it settles. So it is for the engine's own refusals raised inside a
157
+ * sender (a template refusing its props or content, an erased user), which no retry fixes: the
158
+ * claim is released and the step fails, because that is the workflow, not the recipient;
159
+ * - it could not (`isRefusedSend`: a `PermanentError`, a transport's `retryable: false` — the
160
+ * provider refused this token, this address or this payload, or the channel is not
161
+ * configured): the copy settles
162
+ * undelivered under the refusal's reason and the journey goes on. One device, one address or
163
+ * one misconfigured channel does not end the journey for the user — the copies to their other
164
+ * devices and the steps after this one still run, and the report counts the refusals.
165
+ *
166
+ * Two cases are uncertain, and in neither is the copy sent again:
167
+ *
168
+ * - the provider never answered (`UnansweredSendError`: the connection dropped, the fetch timed
169
+ * out) — it may have taken the message, so the claim is kept and the copy settles undelivered
170
+ * as `no_answer`, and the journey goes on;
171
+ * - the copy was claimed and never settled — the earlier run died between the transport taking
172
+ * it and the report (or the step's checkpoint) — and a replay settles it as `unconfirmed`.
173
+ *
174
+ * Both are in the report under those reasons: what at-most-once cost is countable. The templates
175
+ * that must arrive opt out per template (`redelivery: 'resend'`), and are sent again as the step
176
+ * retries. A report that fails after the send is logged, never thrown: the step would retry,
177
+ * and the copy — now claimed — would be skipped.
178
+ *
179
+ * Why at most once (decided 2026-11-10, after reviewing the alternatives): exactly-once is out of
180
+ * reach — Cloudflare Email Service (the `send_email` binding and the REST endpoint alike) and SES
181
+ * accept no idempotency key or client message id, FCM does not de-duplicate, only APNs and Web
182
+ * Push collapse a repeat on the device. Between the two remaining options, a duplicate marketing
183
+ * email costs spam complaints, unsubscribes and sender reputation, while a lost nudge is invisible
184
+ * to the user and a journey has later steps; this is how Customer.io and Braze behave (the
185
+ * delivery record is the source of truth, no resend on uncertainty). Do not "fix" this back to
186
+ * at-least-once: set `redelivery: 'resend'` on the templates that need it instead.
187
+ */
188
+ async function deliver(message, ctx) {
189
+ const observer = ctx.observer;
190
+ if (await observer?.messageSettled?.(message)) return;
191
+ const tracking = await observer?.messagePrepared?.(message);
192
+ const copy = tracking === void 0 ? message : {
193
+ ...message,
194
+ tracking
195
+ };
196
+ if (!(await observer?.messageClaimed?.(copy) ?? true) && copy.redelivery !== "resend") {
197
+ console.warn(`[workflow] ${copy.idempotencyKey} was handed to the transport by an earlier run and never settled: not sent again (redelivery: 'skip')`);
198
+ await settleUncertain(copy, "unconfirmed", ctx);
199
+ return;
200
+ }
201
+ let result;
202
+ try {
203
+ result = await ctx.messages.send(copy);
204
+ } catch (error) {
205
+ if (isUnanswered(error) && copy.redelivery !== "resend") {
206
+ console.warn(`[workflow] ${copy.idempotencyKey} got no answer from the provider: not sent again (redelivery: 'skip')`, error);
207
+ await settleUncertain(copy, "no_answer", ctx);
208
+ return;
209
+ }
210
+ if (isRefusedSend(error)) {
211
+ const reason = refusalReason(error);
212
+ console.error(`[workflow] ${copy.idempotencyKey} (${copy.channel} '${copy.template}') was refused, settled as undelivered (${reason}) and the journey goes on`, error);
213
+ try {
214
+ await observer?.messageSent?.(copy, {
215
+ delivered: false,
216
+ reason
217
+ });
218
+ } catch (reportError) {
219
+ console.error(`[workflow] reporting ${copy.idempotencyKey} as refused failed`, reportError);
220
+ }
221
+ return;
222
+ }
223
+ try {
224
+ await observer?.messageReleased?.(copy);
225
+ } catch (releaseError) {
226
+ console.error(`[workflow] releasing ${copy.idempotencyKey} after a failed send failed`, releaseError);
227
+ }
228
+ throw error;
229
+ }
230
+ try {
231
+ await observer?.messageSent?.(copy, result ?? { delivered: true });
232
+ } catch (error) {
233
+ console.error(`[workflow] reporting ${copy.idempotencyKey} as sent failed`, error);
234
+ }
235
+ }
236
+ /**
237
+ * A copy that may or may not have reached the user, settled as undelivered under the reason that
238
+ * says which uncertainty it was. Logged, never thrown, like every report after a send.
239
+ */
240
+ async function settleUncertain(copy, reason, ctx) {
241
+ try {
242
+ await ctx.observer?.messageSent?.(copy, {
243
+ delivered: false,
244
+ reason
245
+ });
246
+ } catch (error) {
247
+ console.error(`[workflow] reporting ${copy.idempotencyKey} as ${reason} failed`, error);
248
+ }
249
+ }
250
+ /**
251
+ * Goal / exitWhen guards (see the header for when they run).
252
+ *
253
+ * The goal condition is anchored at workflow entry: a `performed` inside it
254
+ * only counts events after the user entered, so pre-existing history cannot
255
+ * register as a conversion. exitWhen is deliberately unanchored — "user
256
+ * unsubscribed" should exit no matter when it happened.
257
+ */
258
+ async function checkGuards(stepId, ir, ctx) {
259
+ const goal = ir.goal;
260
+ const exitWhen = ir.exitWhen;
261
+ if (goal === void 0 && exitWhen === void 0) return null;
262
+ const state = goalState(ctx);
263
+ const result = await ctx.step.do(`${stepId}:guard`, async () => {
264
+ const now = Date.now();
265
+ const goalHit = goal !== void 0 && state.convertedAt === void 0 ? await goalReached(ir, ctx, now) : null;
266
+ const exitMet = exitWhen !== void 0 && await holds(exitWhen, ctx, now);
267
+ return {
268
+ goalAt: goalHit?.at ?? null,
269
+ exitMet
270
+ };
271
+ });
272
+ if (result.goalAt !== null) {
273
+ state.convertedAt ??= result.goalAt;
274
+ if (goal?.exitOnMatch ?? true) return { kind: "goal" };
275
+ }
276
+ if (result.exitMet) return { kind: "exit_when" };
277
+ return null;
278
+ }
279
+ /**
280
+ * The host's template check, with the instance and node added to the message:
281
+ * a refused message must point at the journey that produced it. The error
282
+ * keeps its class (and `name`), so adapters can stop retrying it.
283
+ */
284
+ function validate(node, props, ctx) {
285
+ if (ctx.validator === void 0) return props;
286
+ try {
287
+ return ctx.validator.validate({
288
+ channel: node.channel,
289
+ template: node.template,
290
+ props
291
+ });
292
+ } catch (error) {
293
+ if (error instanceof Error) error.message = `[${ctx.instanceId} ${node.id}] ${error.message}${missingRefs(node, props)}`;
294
+ throw error;
295
+ }
296
+ }
297
+ /**
298
+ * What a refused message most often lacks: a prop written as a reference (`{ name: u.name }`)
299
+ * that this user has no value for. A profile field the contract declares as required is still
300
+ * absent until someone writes it — the contract checks what is written, not that it was — so
301
+ * the refusal says which field, and the author knows whether to write the data or to declare
302
+ * the field (and the template's prop) optional.
303
+ */
304
+ function missingRefs(node, props) {
305
+ const missing = [];
306
+ for (const [key, value] of Object.entries(node.props)) {
307
+ if (typeof value !== "object" || props[key] !== void 0) continue;
308
+ const source = value.type === "trigger_payload" ? `trigger payload field '${value.path}'` : `profile field '${value.path}'`;
309
+ missing.push(`props.${key} reads ${source}, which this user has no value for`);
310
+ }
311
+ return missing.length > 0 ? ` (${missing.join("; ")})` : "";
312
+ }
313
+ /**
314
+ * The message's opt-out topic and redelivery policy at the moment of the send. The template is
315
+ * resolved when it is used — the latest content goes out — and so is what it says about itself:
316
+ * a template moved to another topic, or from transactional to a topic, since this journey's
317
+ * workflow was compiled is sent under what it declares today. The node's own values (the
318
+ * compile-time snapshot) stand only where no registry answers: a host without a validator, a
319
+ * channel without templates. Called inside the send's step, so a replay reads the checkpoint.
320
+ */
321
+ function policyOf(node, ctx) {
322
+ const live = ctx.validator?.describe?.({
323
+ channel: node.channel,
324
+ template: node.template
325
+ });
326
+ if (live !== void 0) return live;
327
+ return {
328
+ ...node.topic !== void 0 ? { topic: node.topic } : {},
329
+ ...node.redelivery === "resend" ? { redelivery: "resend" } : {}
330
+ };
331
+ }
332
+ /**
333
+ * The policy as the copy carries it: what the observer records and the senders may read. An
334
+ * email or a push always says its topic — one with none known (a node compiled before topics
335
+ * existed) is recorded as transactional, as it always was.
336
+ */
337
+ function carried(node, policy) {
338
+ return {
339
+ ...node.channel === "email" || node.channel === "push" ? { topic: policy.topic ?? null } : {},
340
+ ...policy.redelivery === "resend" ? { redelivery: "resend" } : {}
341
+ };
342
+ }
343
+ /**
344
+ * Whether the user opted out of what this step sends. An email or push step checks its topic —
345
+ * an opt-out of the topic on that channel or of the whole channel skips it — and a transactional
346
+ * message (`topic: null`) is never skipped: a receipt or a code goes out whatever the user opted
347
+ * out of. With no topic known (a node compiled before topics existed, on a host whose registry
348
+ * does not answer for it) the channel-wide opt-out alone is checked, as it always was. Other
349
+ * channels check the channel.
350
+ */
351
+ async function suppressed(node, policy, ctx) {
352
+ if (policy.topic === null) return false;
353
+ return await ctx.facts.isSuppressed?.(node.channel, policy.topic) === true;
354
+ }
355
+ /**
356
+ * A push goes to devices, not to a profile address: one copy per device the
357
+ * host's directory lists (or only the most recent, `devices: 'latest'`). Each
358
+ * copy's idempotency key carries its token, so a retried step that already
359
+ * reached some devices re-sends to the rest and skips the ones it reached —
360
+ * keyed by token rather than position, because the list can change between
361
+ * attempts. A user with no device is skipped, not failed: being unreachable is
362
+ * a state of the user, and `reachable('push')` is how a journey branches on it.
363
+ */
364
+ /**
365
+ * A push: one step settles what goes out and to which devices, then each device gets a step of
366
+ * its own — a failure on one device retries that device alone, and the copies already delivered
367
+ * or claimed are not sent again (see `deliver`; APNs collapses a repeat on the device, FCM does
368
+ * not de-duplicate at all).
369
+ */
370
+ async function sendPush(node, ir, ctx) {
371
+ const plan = await ctx.step.do(`${node.id}:send`, async () => {
372
+ const props = validate(node, await resolveValues(node.props, ctx), ctx);
373
+ const policy = policyOf(node, ctx);
374
+ if (await suppressed(node, policy, ctx)) return null;
375
+ const listed = await ctx.facts.listDevices();
376
+ return {
377
+ props,
378
+ devices: node.devices === "latest" ? listed.slice(0, 1) : listed,
379
+ policy
380
+ };
381
+ });
382
+ if (plan === null) return;
383
+ if (plan.devices.length === 0) {
384
+ console.log(`[journey] push ${node.template} skipped: no device for user ${ctx.userId}`);
385
+ return;
386
+ }
387
+ const policy = plan.policy ?? policyOf(node, ctx);
388
+ for (const [index, device] of plan.devices.entries()) await ctx.step.do(`${node.id}:send:${index}`, async () => {
389
+ await deliver({
390
+ workflow: ir.id,
391
+ instanceId: ctx.instanceId,
392
+ nodeId: node.id,
393
+ channel: "push",
394
+ template: node.template,
395
+ props: plan.props,
396
+ userId: await ownerOf(ctx),
397
+ recipient: device.token,
398
+ device,
399
+ idempotencyKey: `${ctx.instanceId}:${node.id}:${device.token}`,
400
+ ...carried(node, policy)
401
+ }, ctx);
402
+ });
403
+ }
404
+ async function runNode(node, ir, ctx) {
405
+ switch (node.type) {
406
+ case "message":
407
+ if (node.channel === "push") {
408
+ await sendPush(node, ir, ctx);
409
+ return FALL_THROUGH;
410
+ }
411
+ await ctx.step.do(`${node.id}:send`, async () => {
412
+ const props = validate(node, await resolveValues(node.props, ctx), ctx);
413
+ const policy = policyOf(node, ctx);
414
+ if (await suppressed(node, policy, ctx)) return;
415
+ const recipientPath = RECIPIENT_PROPERTY[node.channel];
416
+ const recipient = recipientPath === void 0 ? void 0 : await ctx.facts.getProperty(recipientPath);
417
+ await deliver({
418
+ workflow: ir.id,
419
+ instanceId: ctx.instanceId,
420
+ nodeId: node.id,
421
+ channel: node.channel,
422
+ template: node.template,
423
+ props,
424
+ userId: await ownerOf(ctx),
425
+ recipient: recipient === void 0 ? void 0 : String(recipient),
426
+ idempotencyKey: `${ctx.instanceId}:${node.id}`,
427
+ ...carried(node, policy)
428
+ }, ctx);
429
+ });
430
+ return FALL_THROUGH;
431
+ case "delay":
432
+ await ctx.step.sleep(node.id, node.duration.ms);
433
+ return await checkGuards(node.id, ir, ctx) ?? FALL_THROUGH;
434
+ case "random_delay": {
435
+ const ms = await ctx.step.do(`${node.id}:roll`, async () => {
436
+ const span = node.max.ms - node.min.ms;
437
+ return node.min.ms + Math.floor(Math.random() * Math.max(span, 0));
438
+ });
439
+ await ctx.step.sleep(`${node.id}:sleep`, ms);
440
+ return await checkGuards(node.id, ir, ctx) ?? FALL_THROUGH;
441
+ }
442
+ case "time_window": {
443
+ const target = await ctx.step.do(`${node.id}:target`, async () => {
444
+ const tz = node.tz === "user" ? String(await ctx.facts.getProperty(TIMEZONE_PROPERTY) ?? "UTC") : node.tz;
445
+ return nextWindowStart(Date.now(), node.days, node.between, tz);
446
+ });
447
+ if (target === null) return FALL_THROUGH;
448
+ const ms = await ctx.step.do(`${node.id}:remaining`, async () => target - Date.now());
449
+ if (ms > 0) await ctx.step.sleep(`${node.id}:sleep`, ms);
450
+ return await checkGuards(node.id, ir, ctx) ?? FALL_THROUGH;
451
+ }
452
+ case "wait_until": {
453
+ const met = await waitUntil(node, ctx);
454
+ const guard = await checkGuards(node.id, ir, ctx);
455
+ if (guard) return guard;
456
+ if (met) return FALL_THROUGH;
457
+ const onTimeout = node.onTimeout;
458
+ if (onTimeout === "continue") return FALL_THROUGH;
459
+ if (onTimeout === "exit") return {
460
+ kind: "exit",
461
+ reason: `${node.id}:timeout`
462
+ };
463
+ return runFlow(onTimeout, ir, ctx);
464
+ }
465
+ case "branch": {
466
+ const matched = await ctx.step.do(`${node.id}:eval`, async () => {
467
+ const now = Date.now();
468
+ for (const [i, branchCase] of node.cases.entries()) if (await holds(branchCase.condition, ctx, now)) return i;
469
+ return -1;
470
+ });
471
+ const flow = matched >= 0 ? node.cases[matched]?.flow : node.otherwise;
472
+ if (flow === void 0) return FALL_THROUGH;
473
+ return await runFlow(flow, ir, ctx);
474
+ }
475
+ case "filter": return await ctx.step.do(`${node.id}:eval`, async () => holds(node.condition, ctx, Date.now())) ? FALL_THROUGH : {
476
+ kind: "exit",
477
+ reason: node.reason ?? `${node.id}:filtered`
478
+ };
479
+ case "cohort": {
480
+ const bucket = hashToBucket(`${ctx.userId}:${node.key ?? `${ir.id}:${node.id}`}`);
481
+ let cumulative = 0;
482
+ for (const arm of node.arms) {
483
+ cumulative += Math.round(arm.weight * 100);
484
+ if (bucket < cumulative) return runFlow(arm.flow, ir, ctx);
485
+ }
486
+ return FALL_THROUGH;
487
+ }
488
+ case "exit": return node.reason !== void 0 ? {
489
+ kind: "exit",
490
+ reason: node.reason
491
+ } : { kind: "exit" };
492
+ case "send_event":
493
+ await ctx.step.do(`${node.id}:emit`, async () => {
494
+ const payload = await resolveValues(node.payload, ctx);
495
+ try {
496
+ await ctx.events.emit(node.event, payload, `${ctx.instanceId}:${node.id}`);
497
+ } catch (error) {
498
+ if (error instanceof Error) error.message = `[${ctx.instanceId} ${node.id}] ${error.message}`;
499
+ throw error;
500
+ }
501
+ });
502
+ return FALL_THROUGH;
503
+ case "action": {
504
+ const invoker = ctx.actions;
505
+ if (invoker === void 0) throw new Error(`action '${node.action}': this runtime has no ActionInvoker configured — register the action on the adapter (see engine/actions.ts)`);
506
+ await ctx.step.do(`${node.id}:run`, async () => {
507
+ const args = await resolveValues(node.args, ctx);
508
+ await invoker.invoke({
509
+ action: node.action,
510
+ args,
511
+ userId: await ownerOf(ctx),
512
+ idempotencyKey: `${ctx.instanceId}:${node.id}`
513
+ });
514
+ });
515
+ return FALL_THROUGH;
516
+ }
517
+ }
518
+ }
519
+ async function waitUntil(node, ctx) {
520
+ const deadline = await ctx.step.do(`${node.id}:deadline`, async () => Date.now() + node.timeout.ms);
521
+ const events = await ctx.step.do(`${node.id}:events`, async () => relevantEvents(node.condition, ctx.facts));
522
+ const anchorMs = deadline - node.timeout.ms;
523
+ const met = await waitLoop(node.id, ctx, deadline, events, async (now) => await holds(node.condition, ctx, now, {
524
+ anchorMs,
525
+ untilMs: deadline
526
+ }) ? true : null);
527
+ await ctx.step.unsubscribe(`${node.id}:unsubscribe`);
528
+ return met === true;
529
+ }
530
+ /**
531
+ * The conversion window outlives the flow: a journey whose steps are done while its goal's
532
+ * `within` is still open keeps watching until the window closes — the purchase that follows the
533
+ * last offer email is that email's conversion, and ending the instance at the email would report
534
+ * it as a plain completion. `exitWhen` still applies while it waits. Nothing to wait for without
535
+ * a window, or once the instance has converted.
536
+ */
537
+ async function awaitTail(ir, ctx) {
538
+ const deadline = goalDeadline(ir, ctx);
539
+ const goal = ir.goal;
540
+ if (goal === void 0 || deadline === void 0) return null;
541
+ const state = goalState(ctx);
542
+ if (state.convertedAt !== void 0) return null;
543
+ if (!await ctx.step.do("goal:open", async () => deadline > Date.now())) return null;
544
+ const exitWhen = ir.exitWhen;
545
+ const hit = await waitLoop("goal", ctx, deadline, await ctx.step.do("goal:events", async () => [.../* @__PURE__ */ new Set([...await relevantEvents(goal.condition, ctx.facts), ...exitWhen === void 0 ? [] : await relevantEvents(exitWhen, ctx.facts)])]), async (now) => {
546
+ const reached = await goalReached(ir, ctx, now);
547
+ if (reached !== null) return {
548
+ kind: "goal",
549
+ at: reached.at
550
+ };
551
+ if (exitWhen !== void 0 && await holds(exitWhen, ctx, now)) return {
552
+ kind: "exit_when",
553
+ at: now
554
+ };
555
+ return null;
556
+ });
557
+ await ctx.step.unsubscribe("goal:unsubscribe");
558
+ if (hit === null) return null;
559
+ if (hit.kind === "goal") {
560
+ state.convertedAt ??= hit.at;
561
+ return { kind: "goal" };
562
+ }
563
+ return { kind: "exit_when" };
564
+ }
565
+ /**
566
+ * Wait until `check` finds something or the deadline passes: subscribe, check, sleep until a
567
+ * relevant event wakes the instance or time runs out. `check` runs inside a step, so its result
568
+ * must be serializable; null means "not yet". Null from here means the deadline passed with
569
+ * nothing found — never a failure, and never a wait given up on early.
570
+ */
571
+ async function waitLoop(id, ctx, deadline, events, check) {
572
+ for (let attempt = 0; attempt < MAX_WAIT_CHECKS; attempt++) {
573
+ await ctx.step.subscribe(`${id}:subscribe:${attempt}`, events, { deadlineMs: deadline });
574
+ const met = await ctx.step.do(`${id}:check:${attempt}`, async () => check(Date.now()));
575
+ if (met !== null) return met;
576
+ const remaining = await ctx.step.do(`${id}:remaining:${attempt}`, async () => deadline - Date.now());
577
+ if (remaining <= 0) return null;
578
+ if (await ctx.step.waitForWake(`${id}:wait:${attempt}`, {
579
+ timeoutMs: remaining,
580
+ deadlineMs: deadline
581
+ }) === "timeout") return finalCheck(id, ctx, check);
582
+ }
583
+ console.warn(`[journey] ${ctx.instanceId} ${id}: ${MAX_WAIT_CHECKS} wake-ups without the condition holding — sleeping to the deadline`);
584
+ const budgetRemaining = await ctx.step.do(`${id}:budget:remaining`, async () => deadline - Date.now());
585
+ if (budgetRemaining > 0) await ctx.step.sleep(`${id}:budget:sleep`, budgetRemaining);
586
+ return finalCheck(id, ctx, check);
587
+ }
588
+ /** The check once the deadline is reached — one step for all the ways of getting there. */
589
+ async function finalCheck(id, ctx, check) {
590
+ return ctx.step.do(`${id}:final`, async () => check(Date.now()));
591
+ }
592
+ /**
593
+ * A journey's condition: the facts are the user's, and the trigger payload is the instance's
594
+ * own. An instance started with none (a segment or webhook trigger) reads an empty payload —
595
+ * the compiler refuses trigger references in such a workflow, so only hand-built IR gets here.
596
+ */
597
+ function holds(condition, ctx, nowMs, opts) {
598
+ return evaluateCondition(condition, ctx.facts, nowMs, {
599
+ ...opts,
600
+ triggerPayload: ctx.triggerPayload ?? {}
601
+ });
602
+ }
603
+ async function resolveValues(values, ctx) {
604
+ const resolved = {};
605
+ for (const [key, value] of Object.entries(values)) if (typeof value !== "object") resolved[key] = value;
606
+ else if (value.type === "trigger_payload") resolved[key] = payloadScalar(ctx.triggerPayload, value.path);
607
+ else resolved[key] = await ctx.facts.getProperty(value.path);
608
+ return resolved;
609
+ }
610
+ export { runJourney };
611
+
612
+ //# sourceMappingURL=interpreter.mjs.map