@shware/workflow 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (487) hide show
  1. package/README.md +165 -42
  2. package/dist/_virtual/_rolldown/runtime.cjs +1 -2
  3. package/dist/apns-relay.cjs +1 -2
  4. package/dist/apns-relay.d.cts +0 -2
  5. package/dist/apns-relay.d.cts.map +1 -1
  6. package/dist/apns-relay.d.mts +0 -2
  7. package/dist/apns-relay.d.mts.map +1 -1
  8. package/dist/apns-relay.mjs +1 -2
  9. package/dist/apns.cjs +1 -2
  10. package/dist/apns.d.cts +0 -2
  11. package/dist/apns.d.cts.map +1 -1
  12. package/dist/apns.d.mts +0 -2
  13. package/dist/apns.d.mts.map +1 -1
  14. package/dist/apns.mjs +1 -2
  15. package/dist/aws/engine-step.cjs +1 -2
  16. package/dist/aws/engine-step.d.cts +0 -2
  17. package/dist/aws/engine-step.d.cts.map +1 -1
  18. package/dist/aws/engine-step.d.mts +0 -2
  19. package/dist/aws/engine-step.d.mts.map +1 -1
  20. package/dist/aws/engine-step.mjs +1 -2
  21. package/dist/aws/function-url.cjs +1 -2
  22. package/dist/aws/function-url.d.cts +0 -2
  23. package/dist/aws/function-url.d.cts.map +1 -1
  24. package/dist/aws/function-url.d.mts +0 -2
  25. package/dist/aws/function-url.d.mts.map +1 -1
  26. package/dist/aws/function-url.mjs +1 -2
  27. package/dist/aws/index.cjs +2 -3
  28. package/dist/aws/index.d.cts +0 -2
  29. package/dist/aws/index.d.cts.map +1 -1
  30. package/dist/aws/index.d.mts +0 -2
  31. package/dist/aws/index.d.mts.map +1 -1
  32. package/dist/aws/index.mjs +2 -3
  33. package/dist/aws/instances.cjs +1 -2
  34. package/dist/aws/instances.d.cts +0 -2
  35. package/dist/aws/instances.d.cts.map +1 -1
  36. package/dist/aws/instances.d.mts +0 -2
  37. package/dist/aws/instances.d.mts.map +1 -1
  38. package/dist/aws/instances.mjs +1 -2
  39. package/dist/aws/lambda-api.cjs +1 -2
  40. package/dist/aws/lambda-api.d.cts +0 -2
  41. package/dist/aws/lambda-api.d.cts.map +1 -1
  42. package/dist/aws/lambda-api.d.mts +0 -2
  43. package/dist/aws/lambda-api.d.mts.map +1 -1
  44. package/dist/aws/lambda-api.mjs +1 -2
  45. package/dist/client.cjs +46 -6
  46. package/dist/client.cjs.map +1 -1
  47. package/dist/client.d.cts +25 -5
  48. package/dist/client.d.cts.map +1 -1
  49. package/dist/client.d.mts +25 -5
  50. package/dist/client.d.mts.map +1 -1
  51. package/dist/client.mjs +46 -6
  52. package/dist/client.mjs.map +1 -1
  53. package/dist/cloudflare/bindings.cjs +1 -2
  54. package/dist/cloudflare/bindings.d.cts +0 -2
  55. package/dist/cloudflare/bindings.d.cts.map +1 -1
  56. package/dist/cloudflare/bindings.d.mts +0 -2
  57. package/dist/cloudflare/bindings.d.mts.map +1 -1
  58. package/dist/cloudflare/bindings.mjs +1 -2
  59. package/dist/cloudflare/index.cjs +2 -2
  60. package/dist/cloudflare/index.mjs +2 -2
  61. package/dist/cloudflare/runner.cjs +2 -3
  62. package/dist/cloudflare/runner.d.cts +1 -3
  63. package/dist/cloudflare/runner.d.cts.map +1 -1
  64. package/dist/cloudflare/runner.d.mts +1 -3
  65. package/dist/cloudflare/runner.d.mts.map +1 -1
  66. package/dist/cloudflare/runner.mjs +2 -3
  67. package/dist/cloudflare/worker.cjs +1 -2
  68. package/dist/cloudflare/worker.d.cts +0 -2
  69. package/dist/cloudflare/worker.d.cts.map +1 -1
  70. package/dist/cloudflare/worker.d.mts +0 -2
  71. package/dist/cloudflare/worker.d.mts.map +1 -1
  72. package/dist/cloudflare/worker.mjs +1 -2
  73. package/dist/cloudflare/workers.d.cts +0 -2
  74. package/dist/cloudflare/workers.d.cts.map +1 -1
  75. package/dist/cloudflare/workers.d.mts +0 -2
  76. package/dist/cloudflare/workers.d.mts.map +1 -1
  77. package/dist/config.cjs +25 -5
  78. package/dist/config.cjs.map +1 -1
  79. package/dist/config.d.cts +15 -11
  80. package/dist/config.d.cts.map +1 -1
  81. package/dist/config.d.mts +15 -11
  82. package/dist/config.d.mts.map +1 -1
  83. package/dist/config.mjs +26 -6
  84. package/dist/config.mjs.map +1 -1
  85. package/dist/contract.cjs +12 -2
  86. package/dist/contract.cjs.map +1 -1
  87. package/dist/contract.d.cts +28 -9
  88. package/dist/contract.d.cts.map +1 -1
  89. package/dist/contract.d.mts +28 -9
  90. package/dist/contract.d.mts.map +1 -1
  91. package/dist/contract.mjs +12 -2
  92. package/dist/contract.mjs.map +1 -1
  93. package/dist/dsl/action.cjs +1 -2
  94. package/dist/dsl/action.d.cts +0 -2
  95. package/dist/dsl/action.d.cts.map +1 -1
  96. package/dist/dsl/action.d.mts +0 -2
  97. package/dist/dsl/action.d.mts.map +1 -1
  98. package/dist/dsl/action.mjs +1 -2
  99. package/dist/dsl/base.cjs +1 -2
  100. package/dist/dsl/base.d.cts +0 -2
  101. package/dist/dsl/base.d.cts.map +1 -1
  102. package/dist/dsl/base.d.mts +0 -2
  103. package/dist/dsl/base.d.mts.map +1 -1
  104. package/dist/dsl/base.mjs +1 -2
  105. package/dist/dsl/bundle.cjs +5 -5
  106. package/dist/dsl/bundle.cjs.map +1 -1
  107. package/dist/dsl/bundle.d.cts +5 -3
  108. package/dist/dsl/bundle.d.cts.map +1 -1
  109. package/dist/dsl/bundle.d.mts +5 -3
  110. package/dist/dsl/bundle.d.mts.map +1 -1
  111. package/dist/dsl/bundle.mjs +5 -5
  112. package/dist/dsl/bundle.mjs.map +1 -1
  113. package/dist/dsl/condition.cjs +1 -2
  114. package/dist/dsl/condition.d.cts +0 -2
  115. package/dist/dsl/condition.d.cts.map +1 -1
  116. package/dist/dsl/condition.d.mts +0 -2
  117. package/dist/dsl/condition.d.mts.map +1 -1
  118. package/dist/dsl/condition.mjs +1 -2
  119. package/dist/dsl/flow.cjs +3 -3
  120. package/dist/dsl/flow.cjs.map +1 -1
  121. package/dist/dsl/flow.d.cts +1 -3
  122. package/dist/dsl/flow.d.cts.map +1 -1
  123. package/dist/dsl/flow.d.mts +1 -3
  124. package/dist/dsl/flow.d.mts.map +1 -1
  125. package/dist/dsl/flow.mjs +3 -3
  126. package/dist/dsl/flow.mjs.map +1 -1
  127. package/dist/dsl/refs.cjs +1 -2
  128. package/dist/dsl/refs.d.cts +0 -2
  129. package/dist/dsl/refs.d.cts.map +1 -1
  130. package/dist/dsl/refs.d.mts +0 -2
  131. package/dist/dsl/refs.d.mts.map +1 -1
  132. package/dist/dsl/refs.mjs +1 -2
  133. package/dist/dsl/template.cjs +1 -2
  134. package/dist/dsl/template.d.cts +0 -2
  135. package/dist/dsl/template.d.cts.map +1 -1
  136. package/dist/dsl/template.d.mts +0 -2
  137. package/dist/dsl/template.d.mts.map +1 -1
  138. package/dist/dsl/template.mjs +1 -2
  139. package/dist/dsl/trigger.cjs +1 -2
  140. package/dist/dsl/trigger.d.cts +0 -2
  141. package/dist/dsl/trigger.d.cts.map +1 -1
  142. package/dist/dsl/trigger.d.mts +0 -2
  143. package/dist/dsl/trigger.d.mts.map +1 -1
  144. package/dist/dsl/trigger.mjs +1 -2
  145. package/dist/dsl/workflow.cjs +3 -4
  146. package/dist/dsl/workflow.d.cts +0 -2
  147. package/dist/dsl/workflow.d.cts.map +1 -1
  148. package/dist/dsl/workflow.d.mts +0 -2
  149. package/dist/dsl/workflow.d.mts.map +1 -1
  150. package/dist/dsl/workflow.mjs +3 -4
  151. package/dist/email-context.cjs +1 -2
  152. package/dist/email-context.d.cts +0 -2
  153. package/dist/email-context.d.cts.map +1 -1
  154. package/dist/email-context.d.mts +0 -2
  155. package/dist/email-context.d.mts.map +1 -1
  156. package/dist/email-context.mjs +1 -2
  157. package/dist/email-sender.cjs +2 -3
  158. package/dist/email-sender.cjs.map +1 -1
  159. package/dist/email-sender.d.cts +1 -3
  160. package/dist/email-sender.d.cts.map +1 -1
  161. package/dist/email-sender.d.mts +1 -3
  162. package/dist/email-sender.d.mts.map +1 -1
  163. package/dist/email-sender.mjs +2 -3
  164. package/dist/email-sender.mjs.map +1 -1
  165. package/dist/email.cjs +33 -7
  166. package/dist/email.cjs.map +1 -1
  167. package/dist/email.d.cts +38 -11
  168. package/dist/email.d.cts.map +1 -1
  169. package/dist/email.d.mts +38 -11
  170. package/dist/email.d.mts.map +1 -1
  171. package/dist/email.mjs +33 -8
  172. package/dist/email.mjs.map +1 -1
  173. package/dist/engine/actions.cjs +1 -2
  174. package/dist/engine/actions.d.cts +0 -2
  175. package/dist/engine/actions.d.cts.map +1 -1
  176. package/dist/engine/actions.d.mts +0 -2
  177. package/dist/engine/actions.d.mts.map +1 -1
  178. package/dist/engine/actions.mjs +1 -2
  179. package/dist/engine/bucket.cjs +1 -2
  180. package/dist/engine/bucket.d.cts +0 -2
  181. package/dist/engine/bucket.d.cts.map +1 -1
  182. package/dist/engine/bucket.d.mts +0 -2
  183. package/dist/engine/bucket.d.mts.map +1 -1
  184. package/dist/engine/bucket.mjs +1 -2
  185. package/dist/engine/condition.cjs +1 -2
  186. package/dist/engine/condition.cjs.map +1 -1
  187. package/dist/engine/condition.d.cts +0 -2
  188. package/dist/engine/condition.d.cts.map +1 -1
  189. package/dist/engine/condition.d.mts +0 -2
  190. package/dist/engine/condition.d.mts.map +1 -1
  191. package/dist/engine/condition.mjs +1 -2
  192. package/dist/engine/condition.mjs.map +1 -1
  193. package/dist/engine/duration.cjs +1 -2
  194. package/dist/engine/duration.d.cts +0 -2
  195. package/dist/engine/duration.d.cts.map +1 -1
  196. package/dist/engine/duration.d.mts +0 -2
  197. package/dist/engine/duration.d.mts.map +1 -1
  198. package/dist/engine/duration.mjs +1 -2
  199. package/dist/engine/index.cjs +1 -1
  200. package/dist/engine/index.mjs +1 -1
  201. package/dist/engine/interpreter.cjs +22 -6
  202. package/dist/engine/interpreter.cjs.map +1 -1
  203. package/dist/engine/interpreter.d.cts +0 -2
  204. package/dist/engine/interpreter.d.cts.map +1 -1
  205. package/dist/engine/interpreter.d.mts +0 -2
  206. package/dist/engine/interpreter.d.mts.map +1 -1
  207. package/dist/engine/interpreter.mjs +22 -6
  208. package/dist/engine/interpreter.mjs.map +1 -1
  209. package/dist/engine/ports.d.cts +8 -4
  210. package/dist/engine/ports.d.cts.map +1 -1
  211. package/dist/engine/ports.d.mts +8 -4
  212. package/dist/engine/ports.d.mts.map +1 -1
  213. package/dist/engine/recipient.cjs +1 -2
  214. package/dist/engine/recipient.d.cts +0 -2
  215. package/dist/engine/recipient.d.cts.map +1 -1
  216. package/dist/engine/recipient.d.mts +0 -2
  217. package/dist/engine/recipient.d.mts.map +1 -1
  218. package/dist/engine/recipient.mjs +1 -2
  219. package/dist/engine/retry.cjs +1 -2
  220. package/dist/engine/retry.d.cts +0 -2
  221. package/dist/engine/retry.d.cts.map +1 -1
  222. package/dist/engine/retry.d.mts +0 -2
  223. package/dist/engine/retry.d.mts.map +1 -1
  224. package/dist/engine/retry.mjs +1 -2
  225. package/dist/engine/time-scale.cjs +1 -2
  226. package/dist/engine/time-scale.d.cts +0 -2
  227. package/dist/engine/time-scale.d.cts.map +1 -1
  228. package/dist/engine/time-scale.d.mts +0 -2
  229. package/dist/engine/time-scale.d.mts.map +1 -1
  230. package/dist/engine/time-scale.mjs +1 -2
  231. package/dist/engine/time-window.cjs +1 -2
  232. package/dist/engine/time-window.d.cts +0 -2
  233. package/dist/engine/time-window.d.cts.map +1 -1
  234. package/dist/engine/time-window.d.mts +0 -2
  235. package/dist/engine/time-window.d.mts.map +1 -1
  236. package/dist/engine/time-window.mjs +1 -2
  237. package/dist/fcm.cjs +1 -2
  238. package/dist/fcm.d.cts +0 -2
  239. package/dist/fcm.d.cts.map +1 -1
  240. package/dist/fcm.d.mts +0 -2
  241. package/dist/fcm.d.mts.map +1 -1
  242. package/dist/fcm.mjs +1 -2
  243. package/dist/hash.cjs +1 -2
  244. package/dist/hash.d.cts +0 -2
  245. package/dist/hash.d.cts.map +1 -1
  246. package/dist/hash.d.mts +0 -2
  247. package/dist/hash.d.mts.map +1 -1
  248. package/dist/hash.mjs +1 -2
  249. package/dist/host/auth.cjs +1 -2
  250. package/dist/host/auth.d.cts +0 -2
  251. package/dist/host/auth.d.cts.map +1 -1
  252. package/dist/host/auth.d.mts +0 -2
  253. package/dist/host/auth.d.mts.map +1 -1
  254. package/dist/host/auth.mjs +1 -2
  255. package/dist/host/channels.cjs +2 -3
  256. package/dist/host/channels.d.cts +0 -2
  257. package/dist/host/channels.d.cts.map +1 -1
  258. package/dist/host/channels.d.mts +0 -2
  259. package/dist/host/channels.d.mts.map +1 -1
  260. package/dist/host/channels.mjs +2 -3
  261. package/dist/host/execute.cjs +3 -4
  262. package/dist/host/execute.d.cts +1 -3
  263. package/dist/host/execute.d.cts.map +1 -1
  264. package/dist/host/execute.d.mts +1 -3
  265. package/dist/host/execute.d.mts.map +1 -1
  266. package/dist/host/execute.mjs +3 -4
  267. package/dist/host/fresh-read.cjs +1 -2
  268. package/dist/host/fresh-read.d.cts +0 -2
  269. package/dist/host/fresh-read.d.cts.map +1 -1
  270. package/dist/host/fresh-read.d.mts +0 -2
  271. package/dist/host/fresh-read.d.mts.map +1 -1
  272. package/dist/host/fresh-read.mjs +1 -2
  273. package/dist/host/http.cjs +39 -5
  274. package/dist/host/http.cjs.map +1 -1
  275. package/dist/host/http.d.cts +2 -4
  276. package/dist/host/http.d.cts.map +1 -1
  277. package/dist/host/http.d.mts +2 -4
  278. package/dist/host/http.d.mts.map +1 -1
  279. package/dist/host/http.mjs +40 -6
  280. package/dist/host/http.mjs.map +1 -1
  281. package/dist/host/ingest.cjs +129 -6
  282. package/dist/host/ingest.cjs.map +1 -1
  283. package/dist/host/ingest.d.cts +71 -2
  284. package/dist/host/ingest.d.cts.map +1 -1
  285. package/dist/host/ingest.d.mts +71 -2
  286. package/dist/host/ingest.d.mts.map +1 -1
  287. package/dist/host/ingest.mjs +126 -7
  288. package/dist/host/ingest.mjs.map +1 -1
  289. package/dist/host/journey-host.cjs +11 -10
  290. package/dist/host/journey-host.cjs.map +1 -1
  291. package/dist/host/journey-host.d.cts +0 -2
  292. package/dist/host/journey-host.d.cts.map +1 -1
  293. package/dist/host/journey-host.d.mts +0 -2
  294. package/dist/host/journey-host.d.mts.map +1 -1
  295. package/dist/host/journey-host.mjs +11 -10
  296. package/dist/host/journey-host.mjs.map +1 -1
  297. package/dist/host/platform.cjs +1 -2
  298. package/dist/host/platform.d.cts +0 -2
  299. package/dist/host/platform.d.cts.map +1 -1
  300. package/dist/host/platform.d.mts +0 -2
  301. package/dist/host/platform.d.mts.map +1 -1
  302. package/dist/host/platform.mjs +1 -2
  303. package/dist/host/senders.cjs +1 -2
  304. package/dist/host/senders.d.cts +0 -2
  305. package/dist/host/senders.d.cts.map +1 -1
  306. package/dist/host/senders.d.mts +0 -2
  307. package/dist/host/senders.d.mts.map +1 -1
  308. package/dist/host/senders.mjs +1 -2
  309. package/dist/http2-client.cjs +1 -2
  310. package/dist/http2-client.d.cts +0 -2
  311. package/dist/http2-client.d.cts.map +1 -1
  312. package/dist/http2-client.d.mts +0 -2
  313. package/dist/http2-client.d.mts.map +1 -1
  314. package/dist/http2-client.mjs +1 -2
  315. package/dist/index.cjs +5 -2
  316. package/dist/index.d.cts +5 -5
  317. package/dist/index.d.mts +5 -5
  318. package/dist/index.mjs +5 -5
  319. package/dist/ir.cjs +12 -4
  320. package/dist/ir.cjs.map +1 -1
  321. package/dist/ir.d.cts +17 -2
  322. package/dist/ir.d.cts.map +1 -1
  323. package/dist/ir.d.mts +17 -2
  324. package/dist/ir.d.mts.map +1 -1
  325. package/dist/ir.mjs +12 -5
  326. package/dist/ir.mjs.map +1 -1
  327. package/dist/jwt.cjs +1 -2
  328. package/dist/jwt.d.cts +0 -2
  329. package/dist/jwt.d.cts.map +1 -1
  330. package/dist/jwt.d.mts +0 -2
  331. package/dist/jwt.d.mts.map +1 -1
  332. package/dist/jwt.mjs +1 -2
  333. package/dist/plan.cjs +1 -2
  334. package/dist/plan.d.cts +0 -2
  335. package/dist/plan.d.cts.map +1 -1
  336. package/dist/plan.d.mts +0 -2
  337. package/dist/plan.d.mts.map +1 -1
  338. package/dist/plan.mjs +1 -2
  339. package/dist/postgres-js.cjs +1 -2
  340. package/dist/postgres-js.d.cts +0 -2
  341. package/dist/postgres-js.d.cts.map +1 -1
  342. package/dist/postgres-js.d.mts +0 -2
  343. package/dist/postgres-js.d.mts.map +1 -1
  344. package/dist/postgres-js.mjs +1 -2
  345. package/dist/provenance.cjs +1 -2
  346. package/dist/provenance.d.cts +0 -2
  347. package/dist/provenance.d.cts.map +1 -1
  348. package/dist/provenance.d.mts +0 -2
  349. package/dist/provenance.d.mts.map +1 -1
  350. package/dist/provenance.mjs +1 -2
  351. package/dist/push.cjs +1 -2
  352. package/dist/push.d.cts +0 -2
  353. package/dist/push.d.cts.map +1 -1
  354. package/dist/push.d.mts +0 -2
  355. package/dist/push.d.mts.map +1 -1
  356. package/dist/push.mjs +1 -2
  357. package/dist/react-email.cjs +1 -2
  358. package/dist/react-email.d.cts +0 -2
  359. package/dist/react-email.d.cts.map +1 -1
  360. package/dist/react-email.d.mts +0 -2
  361. package/dist/react-email.d.mts.map +1 -1
  362. package/dist/react-email.mjs +1 -2
  363. package/dist/reporting/classify.cjs +1 -2
  364. package/dist/reporting/classify.d.cts +0 -2
  365. package/dist/reporting/classify.d.cts.map +1 -1
  366. package/dist/reporting/classify.d.mts +0 -2
  367. package/dist/reporting/classify.d.mts.map +1 -1
  368. package/dist/reporting/classify.mjs +1 -2
  369. package/dist/reporting/observer.cjs +2 -2
  370. package/dist/reporting/observer.cjs.map +1 -1
  371. package/dist/reporting/observer.d.cts +0 -2
  372. package/dist/reporting/observer.d.cts.map +1 -1
  373. package/dist/reporting/observer.d.mts +0 -2
  374. package/dist/reporting/observer.d.mts.map +1 -1
  375. package/dist/reporting/observer.mjs +2 -2
  376. package/dist/reporting/observer.mjs.map +1 -1
  377. package/dist/reporting/tracking.cjs +29 -12
  378. package/dist/reporting/tracking.cjs.map +1 -1
  379. package/dist/reporting/tracking.d.cts +13 -8
  380. package/dist/reporting/tracking.d.cts.map +1 -1
  381. package/dist/reporting/tracking.d.mts +13 -8
  382. package/dist/reporting/tracking.d.mts.map +1 -1
  383. package/dist/reporting/tracking.mjs +29 -12
  384. package/dist/reporting/tracking.mjs.map +1 -1
  385. package/dist/runtime.cjs +1 -2
  386. package/dist/runtime.d.cts +0 -2
  387. package/dist/runtime.d.cts.map +1 -1
  388. package/dist/runtime.d.mts +0 -2
  389. package/dist/runtime.d.mts.map +1 -1
  390. package/dist/runtime.mjs +1 -2
  391. package/dist/store/erasure.cjs +1 -2
  392. package/dist/store/erasure.d.cts +0 -2
  393. package/dist/store/erasure.d.cts.map +1 -1
  394. package/dist/store/erasure.d.mts +0 -2
  395. package/dist/store/erasure.d.mts.map +1 -1
  396. package/dist/store/erasure.mjs +1 -2
  397. package/dist/store/facts.cjs +4 -5
  398. package/dist/store/facts.cjs.map +1 -1
  399. package/dist/store/facts.d.cts +2 -4
  400. package/dist/store/facts.d.cts.map +1 -1
  401. package/dist/store/facts.d.mts +2 -4
  402. package/dist/store/facts.d.mts.map +1 -1
  403. package/dist/store/facts.mjs +4 -5
  404. package/dist/store/facts.mjs.map +1 -1
  405. package/dist/store/index.cjs +2 -3
  406. package/dist/store/index.cjs.map +1 -1
  407. package/dist/store/index.d.cts +44 -15
  408. package/dist/store/index.d.cts.map +1 -1
  409. package/dist/store/index.d.mts +44 -15
  410. package/dist/store/index.d.mts.map +1 -1
  411. package/dist/store/index.mjs +2 -3
  412. package/dist/store/index.mjs.map +1 -1
  413. package/dist/store/postgres-reporting.cjs +31 -12
  414. package/dist/store/postgres-reporting.cjs.map +1 -1
  415. package/dist/store/postgres-reporting.d.cts +4 -4
  416. package/dist/store/postgres-reporting.d.cts.map +1 -1
  417. package/dist/store/postgres-reporting.d.mts +4 -4
  418. package/dist/store/postgres-reporting.d.mts.map +1 -1
  419. package/dist/store/postgres-reporting.mjs +31 -12
  420. package/dist/store/postgres-reporting.mjs.map +1 -1
  421. package/dist/store/postgres.cjs +40 -5
  422. package/dist/store/postgres.cjs.map +1 -1
  423. package/dist/store/postgres.d.cts +4 -4
  424. package/dist/store/postgres.d.cts.map +1 -1
  425. package/dist/store/postgres.d.mts +4 -4
  426. package/dist/store/postgres.d.mts.map +1 -1
  427. package/dist/store/postgres.mjs +41 -6
  428. package/dist/store/postgres.mjs.map +1 -1
  429. package/dist/store/sql.cjs +1 -2
  430. package/dist/store/sql.d.cts +0 -2
  431. package/dist/store/sql.d.cts.map +1 -1
  432. package/dist/store/sql.d.mts +0 -2
  433. package/dist/store/sql.d.mts.map +1 -1
  434. package/dist/store/sql.mjs +1 -2
  435. package/dist/store/tables.cjs +76 -13
  436. package/dist/store/tables.cjs.map +1 -1
  437. package/dist/store/tables.d.cts +17 -3
  438. package/dist/store/tables.d.cts.map +1 -1
  439. package/dist/store/tables.d.mts +17 -3
  440. package/dist/store/tables.d.mts.map +1 -1
  441. package/dist/store/tables.mjs +75 -14
  442. package/dist/store/tables.mjs.map +1 -1
  443. package/dist/store/user-lock.cjs +1 -2
  444. package/dist/store/user-lock.d.cts +0 -2
  445. package/dist/store/user-lock.d.cts.map +1 -1
  446. package/dist/store/user-lock.d.mts +0 -2
  447. package/dist/store/user-lock.d.mts.map +1 -1
  448. package/dist/store/user-lock.mjs +1 -2
  449. package/dist/templates.cjs +61 -9
  450. package/dist/templates.cjs.map +1 -1
  451. package/dist/templates.d.cts +101 -15
  452. package/dist/templates.d.cts.map +1 -1
  453. package/dist/templates.d.mts +101 -15
  454. package/dist/templates.d.mts.map +1 -1
  455. package/dist/templates.mjs +62 -11
  456. package/dist/templates.mjs.map +1 -1
  457. package/dist/transports/cloudflare-email.cjs +1 -2
  458. package/dist/transports/cloudflare-email.d.cts +0 -2
  459. package/dist/transports/cloudflare-email.d.cts.map +1 -1
  460. package/dist/transports/cloudflare-email.d.mts +0 -2
  461. package/dist/transports/cloudflare-email.d.mts.map +1 -1
  462. package/dist/transports/cloudflare-email.mjs +1 -2
  463. package/dist/transports/ses.cjs +1 -2
  464. package/dist/transports/ses.d.cts +0 -2
  465. package/dist/transports/ses.d.cts.map +1 -1
  466. package/dist/transports/ses.d.mts +0 -2
  467. package/dist/transports/ses.d.mts.map +1 -1
  468. package/dist/transports/ses.mjs +1 -2
  469. package/dist/transports/sigv4.cjs +1 -2
  470. package/dist/transports/sigv4.d.cts +0 -2
  471. package/dist/transports/sigv4.d.cts.map +1 -1
  472. package/dist/transports/sigv4.d.mts +0 -2
  473. package/dist/transports/sigv4.d.mts.map +1 -1
  474. package/dist/transports/sigv4.mjs +1 -2
  475. package/dist/webhooks.cjs +1 -2
  476. package/dist/webhooks.d.cts +0 -2
  477. package/dist/webhooks.d.cts.map +1 -1
  478. package/dist/webhooks.d.mts +0 -2
  479. package/dist/webhooks.d.mts.map +1 -1
  480. package/dist/webhooks.mjs +1 -2
  481. package/dist/webpush.cjs +1 -2
  482. package/dist/webpush.d.cts +0 -2
  483. package/dist/webpush.d.cts.map +1 -1
  484. package/dist/webpush.d.mts +0 -2
  485. package/dist/webpush.d.mts.map +1 -1
  486. package/dist/webpush.mjs +1 -2
  487. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.mjs","names":["BundleIRSchema"],"sources":["../../src/dsl/bundle.ts"],"sourcesContent":["import { semanticHash } from '../hash';\nimport {\n type BundleIR,\n BundleIR as BundleIRSchema,\n type ConditionIR,\n IR_VERSION,\n type NodeIR,\n type SegmentIR,\n type WorkflowIR,\n} from '../ir';\nimport { type AnyTemplate, CHANNEL_OF } from '../templates';\nimport type { ActionRef } from './action';\nimport type { SegmentInternal, SegmentRef } from './condition';\nimport { actionUses } from './flow';\nimport type { WorkflowBuilder } from './workflow';\n\n/**\n * The deployment unit — compileBundle gathers workflows, segments and the\n * template manifest into one BundleIR snapshot (terraform-apply mental model);\n * the server diffs each definition by contentHash (see plan.ts).\n */\nexport function compileBundle(input: {\n workflows: readonly WorkflowBuilder[];\n segments?: readonly SegmentRef[];\n /** The template manifest: these definitions, by channel and id. */\n templates?: readonly AnyTemplate[];\n actions?: readonly ActionRef[];\n}): BundleIR {\n const segments = (input.segments ?? []).map((segment) => {\n const { id, definition, loc, meta } = segment as SegmentInternal;\n const compiled: SegmentIR = {\n irVersion: IR_VERSION,\n id,\n // Labels and provenance both live in meta, which stripMeta drops before hashing\n contentHash: semanticHash(definition),\n condition: definition,\n };\n const merged = {\n ...(meta?.name !== undefined ? { name: meta.name } : {}),\n ...(meta?.description !== undefined ? { description: meta.description } : {}),\n ...(loc !== undefined ? { loc } : {}),\n };\n if (Object.keys(merged).length > 0) compiled.meta = merged;\n return compiled;\n });\n\n const templates = (input.templates ?? []).map((template) => ({\n irVersion: IR_VERSION,\n key: template.id,\n channel: CHANNEL_OF[template.kind],\n }));\n\n // Manifest only — names; the implementation ships in the Worker bundle, never in IR\n const actions = (input.actions ?? []).map((a) => ({ irVersion: IR_VERSION, name: a.name }));\n\n const workflows = input.workflows.map((builder) => builder.toIR());\n\n // Names are wire identity (routing tables, entry ledger, by-name refs):\n // duplicates would silently last-write-win on deploy, so fail the compile.\n assertUniqueNames(\n workflows.map((w) => w.id),\n 'workflow'\n );\n assertUniqueNames(\n segments.map((s) => s.id),\n 'segment'\n );\n // A message node names its template by channel and key, so the key is unique per channel:\n // an email and a push of one nudge may share it\n assertUniqueNames(\n templates.map((t) => `${t.channel}:${t.key}`),\n 'template'\n );\n assertUniqueNames(\n actions.map((a) => a.name),\n 'action'\n );\n\n // Deploy replaces the whole segment table, so every by-name reference must\n // resolve inside this bundle — catching it here turns a runtime \"Unknown\n // segment\" in some user's journey into a compile error.\n assertSegmentRefsResolve(workflows, segments);\n\n // A segment is evaluated by evaluating the segments it names; a cycle among\n // them has no evaluation order and would recurse until the stack ran out —\n // at run time, in some user's journey. Caught here, with the cycle spelled out.\n assertNoSegmentCycles(segments);\n\n // Payload predicates and profile predicates share the Condition type, so\n // placement is checked here: payload only inside where-trees, and where-trees\n // contain nothing but payload predicates and combinators.\n assertConditionPlacement(workflows, segments);\n\n // Same rationale as segments: the runtime registry is looked up by name, so\n // an action a workflow runs must be in the bundle — and it must be the very\n // definition listed there, or two same-named definitions are competing for\n // one identity (the IR names it; only the compile can tell them apart).\n assertActionRefsResolve(workflows, input.workflows, input.actions ?? []);\n\n return BundleIRSchema.parse({ irVersion: IR_VERSION, workflows, segments, templates, actions });\n}\n\nfunction assertUniqueNames(names: readonly string[], kind: string): void {\n const seen = new Set<string>();\n for (const name of names) {\n if (seen.has(name)) throw new Error(`compileBundle: duplicate ${kind} name '${name}'`);\n seen.add(name);\n }\n}\n\nfunction assertSegmentRefsResolve(\n workflows: readonly WorkflowIR[],\n segments: readonly SegmentIR[]\n): void {\n const defined = new Set(segments.map((s) => s.id));\n const check = (refs: ReadonlySet<string>, owner: string): void => {\n for (const ref of refs) {\n if (!defined.has(ref)) {\n throw new Error(\n `compileBundle: ${owner} references segment '${ref}' that is not in the bundle — pass it in 'segments'`\n );\n }\n }\n };\n for (const workflow of workflows) {\n check(referencedSegments(workflow), `workflow '${workflow.id}'`);\n }\n // Segments may reference other segments; those must resolve too\n for (const segment of segments) {\n const refs = new Set<string>();\n collectConditionRefs(segment.condition, refs);\n check(refs, `segment '${segment.id}'`);\n }\n}\n\nfunction referencedSegments(workflow: WorkflowIR): Set<string> {\n const refs = new Set<string>();\n if (workflow.trigger.type === 'segment') refs.add(workflow.trigger.segment);\n if (workflow.trigger.type === 'event' && workflow.trigger.filter !== undefined) {\n collectConditionRefs(workflow.trigger.filter, refs);\n }\n if (workflow.goal !== undefined) collectConditionRefs(workflow.goal.condition, refs);\n if (workflow.exitWhen !== undefined) collectConditionRefs(workflow.exitWhen, refs);\n collectNodeRefs(workflow.flow, refs);\n return refs;\n}\n\nfunction collectConditionRefs(condition: ConditionIR, into: Set<string>): void {\n switch (condition.type) {\n case 'and':\n case 'or':\n for (const child of condition.conditions) collectConditionRefs(child, into);\n break;\n case 'not':\n collectConditionRefs(condition.condition, into);\n break;\n case 'segment':\n into.add(condition.segment);\n break;\n default:\n break;\n }\n}\n\nfunction collectNodeRefs(nodes: readonly NodeIR[], into: Set<string>): void {\n for (const node of nodes) {\n switch (node.type) {\n case 'wait_until':\n collectConditionRefs(node.condition, into);\n if (Array.isArray(node.onTimeout)) collectNodeRefs(node.onTimeout, into);\n break;\n case 'branch':\n for (const branchCase of node.cases) {\n collectConditionRefs(branchCase.condition, into);\n collectNodeRefs(branchCase.flow, into);\n }\n if (node.otherwise) collectNodeRefs(node.otherwise, into);\n break;\n case 'filter':\n collectConditionRefs(node.condition, into);\n break;\n case 'cohort':\n for (const arm of node.arms) collectNodeRefs(arm.flow, into);\n break;\n default:\n break;\n }\n }\n}\n\nfunction assertActionRefsResolve(\n workflows: readonly WorkflowIR[],\n builders: readonly WorkflowBuilder[],\n actions: readonly ActionRef[]\n): void {\n const listed = new Map(actions.map((a) => [a.name, a]));\n workflows.forEach((workflow, i) => {\n for (const used of actionUses(builders[i])) {\n const manifest = listed.get(used.name);\n if (manifest === undefined) {\n throw new Error(\n `compileBundle: workflow '${workflow.id}' runs action '${used.name}' that is not in the bundle — pass it in 'actions'`\n );\n }\n // Identity, not source text: the printed handler depends on the bundler.\n // Every use is checked, not one per name — with two definitions under one\n // name, whichever is listed, the *other* node would run the wrong code.\n if (manifest !== used && manifest.handler !== used.handler) {\n throw new Error(\n `compileBundle: workflow '${workflow.id}' runs action '${used.name}' that is not the definition listed in 'actions' — two definitions are sharing that name`\n );\n }\n }\n });\n}\n\n/** Walk segment → segment references depth-first; the first back edge is reported as the cycle path. */\nfunction assertNoSegmentCycles(segments: readonly SegmentIR[]): void {\n const refsOf = new Map<string, Set<string>>();\n for (const segment of segments) {\n const refs = new Set<string>();\n collectConditionRefs(segment.condition, refs);\n refsOf.set(segment.id, refs);\n }\n const done = new Set<string>();\n const path: string[] = [];\n const visit = (id: string): void => {\n const at = path.indexOf(id);\n if (at !== -1) {\n const cycle = [...path.slice(at), id].join(' → ');\n throw new Error(`compileBundle: segments reference each other in a cycle: ${cycle}`);\n }\n if (done.has(id)) return;\n path.push(id);\n for (const ref of refsOf.get(id) ?? []) visit(ref);\n path.pop();\n done.add(id);\n };\n for (const id of refsOf.keys()) visit(id);\n}\n\n/* --------------------- payload / profile placement checks --------------------- */\n\nfunction assertConditionPlacement(\n workflows: readonly WorkflowIR[],\n segments: readonly SegmentIR[]\n): void {\n for (const workflow of workflows) {\n if (workflow.trigger.type === 'event') {\n if (workflow.trigger.where !== undefined) {\n assertWhereTree(workflow.trigger.where, `workflow '${workflow.id}' trigger where`);\n }\n if (workflow.trigger.filter !== undefined) {\n assertProfileTree(workflow.trigger.filter, `workflow '${workflow.id}' trigger filter`);\n }\n }\n if (workflow.goal !== undefined) {\n assertProfileTree(workflow.goal.condition, `workflow '${workflow.id}' goal`);\n }\n if (workflow.exitWhen !== undefined) {\n assertProfileTree(workflow.exitWhen, `workflow '${workflow.id}' exitWhen`);\n }\n assertNodeTrees(workflow.flow, `workflow '${workflow.id}'`);\n }\n for (const segment of segments) {\n assertProfileTree(segment.condition, `segment '${segment.id}'`);\n }\n}\n\n/** A profile-context tree: payload predicates may appear only under a performed.where. */\nfunction assertProfileTree(condition: ConditionIR, owner: string): void {\n switch (condition.type) {\n case 'and':\n case 'or':\n for (const child of condition.conditions) assertProfileTree(child, owner);\n break;\n case 'not':\n assertProfileTree(condition.condition, owner);\n break;\n case 'performed':\n if (condition.where !== undefined) assertWhereTree(condition.where, owner);\n break;\n case 'payload':\n throw new Error(\n `compileBundle: ${owner} uses a payload predicate outside a where clause — payload refs are only valid inside performed({ where }) or trigger.event({ where })`\n );\n default:\n break; // property / segment\n }\n}\n\n/** A where tree: payload predicates and combinators only — no profile facts in event scope. */\nfunction assertWhereTree(condition: ConditionIR, owner: string): void {\n switch (condition.type) {\n case 'and':\n case 'or':\n for (const child of condition.conditions) assertWhereTree(child, owner);\n break;\n case 'not':\n assertWhereTree(condition.condition, owner);\n break;\n case 'payload':\n break;\n default:\n throw new Error(\n `compileBundle: ${owner} where clause may only contain payload predicates and and/or/not, found '${condition.type}'`\n );\n }\n}\n\nfunction assertNodeTrees(nodes: readonly NodeIR[], owner: string): void {\n for (const node of nodes) {\n switch (node.type) {\n case 'wait_until':\n assertProfileTree(node.condition, owner);\n if (Array.isArray(node.onTimeout)) assertNodeTrees(node.onTimeout, owner);\n break;\n case 'branch':\n for (const branchCase of node.cases) {\n assertProfileTree(branchCase.condition, owner);\n assertNodeTrees(branchCase.flow, owner);\n }\n if (node.otherwise) assertNodeTrees(node.otherwise, owner);\n break;\n case 'filter':\n assertProfileTree(node.condition, owner);\n break;\n case 'cohort':\n for (const arm of node.arms) assertNodeTrees(arm.flow, owner);\n break;\n default:\n break;\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAqBA,SAAgB,cAAc,OAMjB;CACX,MAAM,YAAY,MAAM,YAAY,CAAC,EAAA,CAAG,KAAK,YAAY;EACvD,MAAM,EAAE,IAAI,YAAY,KAAK,SAAS;EACtC,MAAM,WAAsB;GAC1B,WAAA;GACA;GAEA,aAAa,aAAa,UAAU;GACpC,WAAW;EACb;EACA,MAAM,SAAS;GACb,GAAI,MAAM,SAAS,KAAA,IAAY,EAAE,MAAM,KAAK,KAAK,IAAI,CAAC;GACtD,GAAI,MAAM,gBAAgB,KAAA,IAAY,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;GAC3E,GAAI,QAAQ,KAAA,IAAY,EAAE,IAAI,IAAI,CAAC;EACrC;EACA,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAAG,SAAS,OAAO;EACpD,OAAO;CACT,CAAC;CAED,MAAM,aAAa,MAAM,aAAa,CAAC,EAAA,CAAG,KAAK,cAAc;EAC3D,WAAA;EACA,KAAK,SAAS;EACd,SAAS,WAAW,SAAS;CAC/B,EAAE;CAGF,MAAM,WAAW,MAAM,WAAW,CAAC,EAAA,CAAG,KAAK,OAAO;EAAE,WAAA;EAAuB,MAAM,EAAE;CAAK,EAAE;CAE1F,MAAM,YAAY,MAAM,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;GACvC,IAAI,MAAM,QAAQ,KAAK,SAAS,GAAG,gBAAgB,KAAK,WAAW,KAAK;GACxE;EACF,KAAK;GACH,KAAK,MAAM,cAAc,KAAK,OAAO;IACnC,kBAAkB,WAAW,WAAW,KAAK;IAC7C,gBAAgB,WAAW,MAAM,KAAK;GACxC;GACA,IAAI,KAAK,WAAW,gBAAgB,KAAK,WAAW,KAAK;GACzD;EACF,KAAK;GACH,kBAAkB,KAAK,WAAW,KAAK;GACvC;EACF,KAAK,UACH,KAAK,MAAM,OAAO,KAAK,MAAM,gBAAgB,IAAI,MAAM,KAAK;CAIhE;AAEJ"}
1
+ {"version":3,"file":"bundle.mjs","names":["BundleIRSchema"],"sources":["../../src/dsl/bundle.ts"],"sourcesContent":["import { semanticHash } from '../hash';\nimport {\n type BundleIR,\n BundleIR as BundleIRSchema,\n type ConditionIR,\n IR_VERSION,\n type NodeIR,\n type SegmentIR,\n type WorkflowIR,\n} from '../ir';\nimport { type AnyTemplate, CHANNEL_OF } from '../templates';\nimport type { ActionRef } from './action';\nimport type { SegmentInternal, SegmentRef } from './condition';\nimport { actionUses } from './flow';\nimport type { WorkflowBuilder } from './workflow';\n\n/**\n * The deployment unit — compileBundle gathers workflows, segments and the\n * template manifest into one BundleIR snapshot (terraform-apply mental model);\n * the server diffs each definition by contentHash (see plan.ts).\n */\nexport function compileBundle(input: {\n workflows: readonly WorkflowBuilder[];\n segments?: readonly SegmentRef[];\n /** The template manifest: these definitions, by channel and id. */\n templates?: readonly AnyTemplate[];\n actions?: readonly ActionRef[];\n /** The contract's subscription topics, carried for the engine (`compileConfig` passes them). */\n subscriptions?: { topics: readonly string[] };\n}): BundleIR {\n const segments = (input.segments ?? []).map((segment) => {\n const { id, definition, loc, meta } = segment as SegmentInternal;\n const compiled: SegmentIR = {\n irVersion: IR_VERSION,\n id,\n // Labels and provenance both live in meta, which stripMeta drops before hashing\n contentHash: semanticHash(definition),\n condition: definition,\n };\n const merged = {\n ...(meta?.name !== undefined ? { name: meta.name } : {}),\n ...(meta?.description !== undefined ? { description: meta.description } : {}),\n ...(loc !== undefined ? { loc } : {}),\n };\n if (Object.keys(merged).length > 0) compiled.meta = merged;\n return compiled;\n });\n\n const templates = (input.templates ?? []).map((template) => ({\n irVersion: IR_VERSION,\n key: template.id,\n channel: CHANNEL_OF[template.kind],\n }));\n\n // Manifest only — names; the implementation ships in the Worker bundle, never in IR\n const actions = (input.actions ?? []).map((a) => ({ irVersion: IR_VERSION, name: a.name }));\n\n const workflows = input.workflows.map((builder) => builder.toIR());\n\n // Names are wire identity (routing tables, entry ledger, by-name refs):\n // duplicates would silently last-write-win on deploy, so fail the compile.\n assertUniqueNames(\n workflows.map((w) => w.id),\n 'workflow'\n );\n assertUniqueNames(\n segments.map((s) => s.id),\n 'segment'\n );\n // A message node names its template by channel and key, so the key is unique per channel:\n // an email and a push of one nudge may share it\n assertUniqueNames(\n templates.map((t) => `${t.channel}:${t.key}`),\n 'template'\n );\n assertUniqueNames(\n actions.map((a) => a.name),\n 'action'\n );\n\n // Deploy replaces the whole segment table, so every by-name reference must\n // resolve inside this bundle — catching it here turns a runtime \"Unknown\n // segment\" in some user's journey into a compile error.\n assertSegmentRefsResolve(workflows, segments);\n\n // A segment is evaluated by evaluating the segments it names; a cycle among\n // them has no evaluation order and would recurse until the stack ran out —\n // at run time, in some user's journey. Caught here, with the cycle spelled out.\n assertNoSegmentCycles(segments);\n\n // Payload predicates and profile predicates share the Condition type, so\n // placement is checked here: payload only inside where-trees, and where-trees\n // contain nothing but payload predicates and combinators.\n assertConditionPlacement(workflows, segments);\n\n // Same rationale as segments: the runtime registry is looked up by name, so\n // an action a workflow runs must be in the bundle — and it must be the very\n // definition listed there, or two same-named definitions are competing for\n // one identity (the IR names it; only the compile can tell them apart).\n assertActionRefsResolve(workflows, input.workflows, input.actions ?? []);\n\n return BundleIRSchema.parse({\n irVersion: IR_VERSION,\n workflows,\n segments,\n templates,\n actions,\n subscriptions: { topics: [...(input.subscriptions?.topics ?? [])] },\n });\n}\n\nfunction assertUniqueNames(names: readonly string[], kind: string): void {\n const seen = new Set<string>();\n for (const name of names) {\n if (seen.has(name)) throw new Error(`compileBundle: duplicate ${kind} name '${name}'`);\n seen.add(name);\n }\n}\n\nfunction assertSegmentRefsResolve(\n workflows: readonly WorkflowIR[],\n segments: readonly SegmentIR[]\n): void {\n const defined = new Set(segments.map((s) => s.id));\n const check = (refs: ReadonlySet<string>, owner: string): void => {\n for (const ref of refs) {\n if (!defined.has(ref)) {\n throw new Error(\n `compileBundle: ${owner} references segment '${ref}' that is not in the bundle — pass it in 'segments'`\n );\n }\n }\n };\n for (const workflow of workflows) {\n check(referencedSegments(workflow), `workflow '${workflow.id}'`);\n }\n // Segments may reference other segments; those must resolve too\n for (const segment of segments) {\n const refs = new Set<string>();\n collectConditionRefs(segment.condition, refs);\n check(refs, `segment '${segment.id}'`);\n }\n}\n\nfunction referencedSegments(workflow: WorkflowIR): Set<string> {\n const refs = new Set<string>();\n if (workflow.trigger.type === 'segment') refs.add(workflow.trigger.segment);\n if (workflow.trigger.type === 'event' && workflow.trigger.filter !== undefined) {\n collectConditionRefs(workflow.trigger.filter, refs);\n }\n if (workflow.goal !== undefined) collectConditionRefs(workflow.goal.condition, refs);\n if (workflow.exitWhen !== undefined) collectConditionRefs(workflow.exitWhen, refs);\n collectNodeRefs(workflow.flow, refs);\n return refs;\n}\n\nfunction collectConditionRefs(condition: ConditionIR, into: Set<string>): void {\n switch (condition.type) {\n case 'and':\n case 'or':\n for (const child of condition.conditions) collectConditionRefs(child, into);\n break;\n case 'not':\n collectConditionRefs(condition.condition, into);\n break;\n case 'segment':\n into.add(condition.segment);\n break;\n default:\n break;\n }\n}\n\nfunction collectNodeRefs(nodes: readonly NodeIR[], into: Set<string>): void {\n for (const node of nodes) {\n switch (node.type) {\n case 'wait_until':\n collectConditionRefs(node.condition, into);\n if (Array.isArray(node.onTimeout)) collectNodeRefs(node.onTimeout, into);\n break;\n case 'branch':\n for (const branchCase of node.cases) {\n collectConditionRefs(branchCase.condition, into);\n collectNodeRefs(branchCase.flow, into);\n }\n if (node.otherwise) collectNodeRefs(node.otherwise, into);\n break;\n case 'filter':\n collectConditionRefs(node.condition, into);\n break;\n case 'cohort':\n for (const arm of node.arms) collectNodeRefs(arm.flow, into);\n break;\n default:\n break;\n }\n }\n}\n\nfunction assertActionRefsResolve(\n workflows: readonly WorkflowIR[],\n builders: readonly WorkflowBuilder[],\n actions: readonly ActionRef[]\n): void {\n const listed = new Map(actions.map((a) => [a.name, a]));\n workflows.forEach((workflow, i) => {\n for (const used of actionUses(builders[i])) {\n const manifest = listed.get(used.name);\n if (manifest === undefined) {\n throw new Error(\n `compileBundle: workflow '${workflow.id}' runs action '${used.name}' that is not in the bundle — pass it in 'actions'`\n );\n }\n // Identity, not source text: the printed handler depends on the bundler.\n // Every use is checked, not one per name — with two definitions under one\n // name, whichever is listed, the *other* node would run the wrong code.\n if (manifest !== used && manifest.handler !== used.handler) {\n throw new Error(\n `compileBundle: workflow '${workflow.id}' runs action '${used.name}' that is not the definition listed in 'actions' — two definitions are sharing that name`\n );\n }\n }\n });\n}\n\n/** Walk segment → segment references depth-first; the first back edge is reported as the cycle path. */\nfunction assertNoSegmentCycles(segments: readonly SegmentIR[]): void {\n const refsOf = new Map<string, Set<string>>();\n for (const segment of segments) {\n const refs = new Set<string>();\n collectConditionRefs(segment.condition, refs);\n refsOf.set(segment.id, refs);\n }\n const done = new Set<string>();\n const path: string[] = [];\n const visit = (id: string): void => {\n const at = path.indexOf(id);\n if (at !== -1) {\n const cycle = [...path.slice(at), id].join(' → ');\n throw new Error(`compileBundle: segments reference each other in a cycle: ${cycle}`);\n }\n if (done.has(id)) return;\n path.push(id);\n for (const ref of refsOf.get(id) ?? []) visit(ref);\n path.pop();\n done.add(id);\n };\n for (const id of refsOf.keys()) visit(id);\n}\n\n/* --------------------- payload / profile placement checks --------------------- */\n\nfunction assertConditionPlacement(\n workflows: readonly WorkflowIR[],\n segments: readonly SegmentIR[]\n): void {\n for (const workflow of workflows) {\n if (workflow.trigger.type === 'event') {\n if (workflow.trigger.where !== undefined) {\n assertWhereTree(workflow.trigger.where, `workflow '${workflow.id}' trigger where`);\n }\n if (workflow.trigger.filter !== undefined) {\n assertProfileTree(workflow.trigger.filter, `workflow '${workflow.id}' trigger filter`);\n }\n }\n if (workflow.goal !== undefined) {\n assertProfileTree(workflow.goal.condition, `workflow '${workflow.id}' goal`);\n }\n if (workflow.exitWhen !== undefined) {\n assertProfileTree(workflow.exitWhen, `workflow '${workflow.id}' exitWhen`);\n }\n assertNodeTrees(workflow.flow, `workflow '${workflow.id}'`);\n }\n for (const segment of segments) {\n assertProfileTree(segment.condition, `segment '${segment.id}'`);\n }\n}\n\n/** A profile-context tree: payload predicates may appear only under a performed.where. */\nfunction assertProfileTree(condition: ConditionIR, owner: string): void {\n switch (condition.type) {\n case 'and':\n case 'or':\n for (const child of condition.conditions) assertProfileTree(child, owner);\n break;\n case 'not':\n assertProfileTree(condition.condition, owner);\n break;\n case 'performed':\n if (condition.where !== undefined) assertWhereTree(condition.where, owner);\n break;\n case 'payload':\n throw new Error(\n `compileBundle: ${owner} uses a payload predicate outside a where clause — payload refs are only valid inside performed({ where }) or trigger.event({ where })`\n );\n default:\n break; // property / segment\n }\n}\n\n/** A where tree: payload predicates and combinators only — no profile facts in event scope. */\nfunction assertWhereTree(condition: ConditionIR, owner: string): void {\n switch (condition.type) {\n case 'and':\n case 'or':\n for (const child of condition.conditions) assertWhereTree(child, owner);\n break;\n case 'not':\n assertWhereTree(condition.condition, owner);\n break;\n case 'payload':\n break;\n default:\n throw new Error(\n `compileBundle: ${owner} where clause may only contain payload predicates and and/or/not, found '${condition.type}'`\n );\n }\n}\n\nfunction assertNodeTrees(nodes: readonly NodeIR[], owner: string): void {\n for (const node of nodes) {\n switch (node.type) {\n case 'wait_until':\n assertProfileTree(node.condition, owner);\n if (Array.isArray(node.onTimeout)) assertNodeTrees(node.onTimeout, owner);\n break;\n case 'branch':\n for (const branchCase of node.cases) {\n assertProfileTree(branchCase.condition, owner);\n assertNodeTrees(branchCase.flow, owner);\n }\n if (node.otherwise) assertNodeTrees(node.otherwise, owner);\n break;\n case 'filter':\n assertProfileTree(node.condition, owner);\n break;\n case 'cohort':\n for (const arm of node.arms) assertNodeTrees(arm.flow, owner);\n break;\n default:\n break;\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAqBA,SAAgB,cAAc,OAQjB;CACX,MAAM,YAAY,MAAM,YAAY,CAAC,EAAA,CAAG,KAAK,YAAY;EACvD,MAAM,EAAE,IAAI,YAAY,KAAK,SAAS;EACtC,MAAM,WAAsB;GAC1B,WAAA;GACA;GAEA,aAAa,aAAa,UAAU;GACpC,WAAW;EACb;EACA,MAAM,SAAS;GACb,GAAI,MAAM,SAAS,KAAA,IAAY,EAAE,MAAM,KAAK,KAAK,IAAI,CAAC;GACtD,GAAI,MAAM,gBAAgB,KAAA,IAAY,EAAE,aAAa,KAAK,YAAY,IAAI,CAAC;GAC3E,GAAI,QAAQ,KAAA,IAAY,EAAE,IAAI,IAAI,CAAC;EACrC;EACA,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAAG,SAAS,OAAO;EACpD,OAAO;CACT,CAAC;CAED,MAAM,aAAa,MAAM,aAAa,CAAC,EAAA,CAAG,KAAK,cAAc;EAC3D,WAAA;EACA,KAAK,SAAS;EACd,SAAS,WAAW,SAAS;CAC/B,EAAE;CAGF,MAAM,WAAW,MAAM,WAAW,CAAC,EAAA,CAAG,KAAK,OAAO;EAAE,WAAA;EAAuB,MAAM,EAAE;CAAK,EAAE;CAE1F,MAAM,YAAY,MAAM,UAAU,KAAK,YAAY,QAAQ,KAAK,CAAC;CAIjE,kBACE,UAAU,KAAK,MAAM,EAAE,EAAE,GACzB,UACF;CACA,kBACE,SAAS,KAAK,MAAM,EAAE,EAAE,GACxB,SACF;CAGA,kBACE,UAAU,KAAK,MAAM,GAAG,EAAE,QAAQ,GAAG,EAAE,KAAK,GAC5C,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K;IAC7C,gBAAgB,WAAW,MAAM,KAAK;GACxC;GACA,IAAI,KAAK,WAAW,gBAAgB,KAAK,WAAW,KAAK;GACzD;EACF,KAAK;GACH,kBAAkB,KAAK,WAAW,KAAK;GACvC;EACF,KAAK,UACH,KAAK,MAAM,OAAO,KAAK,MAAM,gBAAgB,IAAI,MAAM,KAAK;CAIhE;AAEJ"}
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_dsl_refs = require("./refs.cjs");
3
3
  const require_provenance = require("../provenance.cjs");
4
4
  const require_dsl_base = require("./base.cjs");
5
- //#region src/dsl/condition.ts
5
+ // src/dsl/condition.ts
6
6
  const cond = (ir, loc) => {
7
7
  return {
8
8
  __condition: true,
@@ -164,7 +164,6 @@ function segment({ id, condition, name, description }) {
164
164
  meta: Object.keys(meta).length === 0 ? void 0 : meta
165
165
  };
166
166
  }
167
- //#endregion
168
167
  exports.and = and;
169
168
  exports.between = between;
170
169
  exports.condIR = condIR;
@@ -2,7 +2,6 @@ import { ConditionIR, DurationIR, SourceLocIR } from "../ir.cjs";
2
2
  import { Duration } from "./base.cjs";
3
3
  import { EventRef, PayloadRef, PayloadRefs, UserPropertyRef } from "./refs.cjs";
4
4
  import { Channel } from "./template.cjs";
5
- //#region src/dsl/condition.d.ts
6
5
  /**
7
6
  * Conditions — drizzle-style predicate expressions: free functions (eq/gt/…)
8
7
  * composed with and/or/not, plus `segment` for naming an expression as a
@@ -146,6 +145,5 @@ export interface SegmentDefinition extends SegmentMeta {
146
145
  * });
147
146
  */
148
147
  export declare function segment({ id, condition, name, description }: SegmentDefinition): SegmentRef;
149
- //#endregion
150
148
  export {};
151
149
  //# sourceMappingURL=condition.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"condition.d.cts","names":[],"sources":["../../src/dsl/condition.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBA6BiB;WACN;;;qBAgBE,SAAM,GAAO,cAAY;;;;;;KAoBjC,Q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AQc,mBAAmB,OAAO,UAAU,eAAe;;YAOvD,aAAa,MAAM,GAAG,YAAY,OAAO;;;;;;;;;;;;;;;;;;;;;;wBAuBrC,UAAU,GAAG,OAAO,SAAS,IAAI,OAAO,mBAAmB;wBAC3D,UAAU,GACxB,OAAO,SAAS,IAChB,OAAO,aAAa,IACpB,OAAO,mBACN;;;;;;;;;;;;;wBAsCa,UAAU,SAAS,UAAU;;wBAK7B,OAAO,qBAAqB,cAAc;wBAG1C,MAAM,qBAAqB,cAAc;wBAGzC,IAAI,WAAW,YAAY;;;;;;;;;;iBAa1B,mBAAmB;WACzB;;WAEA;;;iBAIM,wBAAwB;WAC9B,IAAI;;WAEJ,MAAM;;WAEN,YAAY;;WAEZ,KAAK;;;iBAIC;EACf;EACA;;iBAGe,0BAA0B;;;;;EAKzC;;EAEA,WAAW;;;;;;;;;;;;wBAaG,UAAU,IAAI,WAAW,MAAM,eAAe,oBAAoB"}
@@ -2,7 +2,6 @@ import { ConditionIR, DurationIR, SourceLocIR } from "../ir.mjs";
2
2
  import { Duration } from "./base.mjs";
3
3
  import { EventRef, PayloadRef, PayloadRefs, UserPropertyRef } from "./refs.mjs";
4
4
  import { Channel } from "./template.mjs";
5
- //#region src/dsl/condition.d.ts
6
5
  /**
7
6
  * Conditions — drizzle-style predicate expressions: free functions (eq/gt/…)
8
7
  * composed with and/or/not, plus `segment` for naming an expression as a
@@ -146,6 +145,5 @@ export interface SegmentDefinition extends SegmentMeta {
146
145
  * });
147
146
  */
148
147
  export declare function segment({ id, condition, name, description }: SegmentDefinition): SegmentRef;
149
- //#endregion
150
148
  export {};
151
149
  //# sourceMappingURL=condition.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"condition.d.mts","names":[],"sources":["../../src/dsl/condition.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBA6BiB;WACN;;;qBAgBE,SAAM,GAAO,cAAY;;;;;;KAoBjC,QAAQ,KAAK,gBAAgB,KAAK,WAAW;wBA6ClC,GAAG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AAM,GAAG,YAAY,OAAO;;;;;;;;;;;;;;;;;;;;;;wBAuBrC,UAAU,GAAG,OAAO,SAAS,IAAI,OAAO,mBAAmB;wBAC3D,UAAU,GACxB,OAAO,SAAS,IAChB,OAAO,aAAa,IACpB,OAAO,mBACN;;;;;;;;;;;;;wBAsCa,UAAU,SAAS,UAAU;;wBAK7B,OAAO,qBAAqB,cAAc;wBAG1C,MAAM,qBAAqB,cAAc;wBAGzC,IAAI,WAAW,YAAY;;;;;;;;;;iBAa1B,mBAAmB;WACzB;;WAEA;;;iBAIM,wBAAwB;WAC9B,IAAI;;WAEJ,MAAM;;WAEN,YAAY;;WAEZ,KAAK;;;iBAIC;EACf;EACA;;iBAGe,0BAA0B;;;;;EAKzC;;EAEA,WAAW;;;;;;;;;;;;wBAaG,UAAU,IAAI,WAAW,MAAM,eAAe,oBAAoB"}
@@ -1,7 +1,7 @@
1
1
  import { PAYLOAD_PATH, payloadRefs } from "./refs.mjs";
2
2
  import { captureLoc } from "../provenance.mjs";
3
3
  import { durationIR } from "./base.mjs";
4
- //#region src/dsl/condition.ts
4
+ // src/dsl/condition.ts
5
5
  const cond = (ir, loc) => {
6
6
  return {
7
7
  __condition: true,
@@ -163,7 +163,6 @@ function segment({ id, condition, name, description }) {
163
163
  meta: Object.keys(meta).length === 0 ? void 0 : meta
164
164
  };
165
165
  }
166
- //#endregion
167
166
  export { and, between, condIR, contains, eq, exists, gt, gte, inArray, lt, lte, ne, not, notBetween, notContains, notExists, notInArray, or, performed, positiveDurationIR, reachable, segment };
168
167
 
169
168
  //# sourceMappingURL=condition.mjs.map
package/dist/dsl/flow.cjs CHANGED
@@ -3,7 +3,7 @@ const require_provenance = require("../provenance.cjs");
3
3
  const require_dsl_base = require("./base.cjs");
4
4
  const require_dsl_condition = require("./condition.cjs");
5
5
  const require_templates = require("../templates.cjs");
6
- //#region src/dsl/flow.ts
6
+ // src/dsl/flow.ts
7
7
  /** prefer() is typed strictly, but a JS caller (or an `any`) reaches it unchecked — fail at the call, not at send time. */
8
8
  function checkPreferArgs(candidates, props, options) {
9
9
  if (!Array.isArray(candidates) || candidates.length !== 2) throw new TypeError("prefer(): candidates must be exactly two templates — one push, one email");
@@ -68,7 +68,8 @@ function messageNode(channel, tpl, props, devices) {
68
68
  channel,
69
69
  template: templateKey(channel, tpl),
70
70
  props: props ?? {},
71
- ...devices !== void 0 ? { devices } : {}
71
+ ...devices !== void 0 ? { devices } : {},
72
+ ...channel === "email" || channel === "push" ? { topic: tpl.topic ?? null } : {}
72
73
  };
73
74
  }
74
75
  /** @internal extended by WorkflowBuilderImpl; not part of the public API */
@@ -313,7 +314,6 @@ function flow(build) {
313
314
  actions: builder.actions
314
315
  };
315
316
  }
316
- //#endregion
317
317
  exports.FlowBuilderImpl = FlowBuilderImpl;
318
318
  exports.actionUses = actionUses;
319
319
  exports.flow = flow;
@@ -1 +1 @@
1
- {"version":3,"file":"flow.cjs","names":["isTemplate","CHANNEL_OF","captureLoc","durationIR","timeOfDayMinutes","condIR","positiveDurationIR"],"sources":["../../src/dsl/flow.ts"],"sourcesContent":["import type { ChannelIR, ConditionIR, NodeIR, PropValueIR, SourceLocIR } from '../ir';\nimport { captureLoc } from '../provenance';\nimport {\n type AnyTemplate,\n CHANNEL_OF,\n type DiscordTemplate,\n type EmailTemplate,\n type PropsSchema,\n type PushTemplate,\n type SlackTemplate,\n isTemplate,\n} from '../templates';\nimport type { ActionRef } from './action';\nimport { type Duration, type TimeOfDay, type Weekday, durationIR, timeOfDayMinutes } from './base';\nimport { type Condition, condIR, positiveDurationIR } from './condition';\nimport type { EventRef, MessageArgs, PropInput, PropsInput } from './refs';\nimport type { PropsOf, TemplateRef } from './template';\n\n/**\n * The flow chain — FlowBuilder is the DSL's step surface (messages, delays,\n * flow control, data), and its implementation is the compiler front half: each\n * chained call executes no logic, it just collects one IR node (ids are\n * assigned later, in workflow.toIR()). Sub-flow callbacks run exactly once at\n * construction — builder in, builder out — so the output is always a static\n * tree.\n *\n * Every public method also captures its callsite (provenance): the loc lands\n * in the node's hash-excluded meta and is the anchor for future in-place\n * editing from the studio.\n */\n\ntype Scalar = string | number | boolean;\n\n/** An emitted field: a scalar (or a profile ref to one); a nested field cannot be sent. */\ntype EmitValue<T> = [NonNullable<T>] extends [Scalar] ? PropInput<T> : never;\n\n/** The payload `sendEvent` accepts for an event: its fields, scalar ones only. */\nexport type EmitPayload<P> = { [K in keyof P]: EmitValue<P[K]> };\n\n/** Payload may be omitted when the event declares no required field. */\nexport type EmitArgs<P> =\n Record<string, never> extends P ? [payload?: EmitPayload<P>] : [payload: EmitPayload<P>];\n\n/** Per-node push options. */\nexport interface PushOptions {\n /** Which devices get a copy: 'all' (the default) or only the most recently registered. */\n devices?: 'all' | 'latest';\n}\n\n/** `prefer()` options. */\nexport interface PreferOptions {\n /** The generated branch's name in IR (UI title / observability handle), as `branch(label, …)`. */\n label?: string;\n}\n\n/** The candidates `prefer()` takes: one push and one email template, in priority order. */\ntype PreferPair = readonly [PushTemplate, EmailTemplate] | readonly [EmailTemplate, PushTemplate];\n\ntype NormalizeProps<P> = { -readonly [K in keyof P]: P[K] };\ntype Equal<A, B> =\n (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;\n\n/** Both candidates render the one props object, so they must declare the same props type — not merely overlap. */\ntype SameProps<T extends PreferPair> =\n Equal<NormalizeProps<PropsOf<T[0]>>, NormalizeProps<PropsOf<T[1]>>> extends true\n ? unknown\n : { readonly __prefer_error__: 'Both templates must declare the same props type' };\n\n/** Distributes, so a field only one member of a union variable has still counts as extra. */\ntype KeysOfUnion<A> = A extends unknown ? keyof A : never;\n/** Rejects known extra fields, which `{}` (an empty props schema) would otherwise accept. */\ntype NoExtra<A, P> = Record<Exclude<KeysOfUnion<A>, keyof P>, never>;\n\n/** prefer() is typed strictly, but a JS caller (or an `any`) reaches it unchecked — fail at the call, not at send time. */\nfunction checkPreferArgs(candidates: unknown, props: unknown, options: unknown): void {\n if (!Array.isArray(candidates) || candidates.length !== 2) {\n throw new TypeError('prefer(): candidates must be exactly two templates — one push, one email');\n }\n const channels = (candidates as unknown[]).map((candidate) =>\n isTemplate(candidate) ? CHANNEL_OF[candidate.kind] : undefined\n );\n if (!channels.every((channel) => channel === 'push' || channel === 'email')) {\n throw new TypeError('prefer(): each candidate must be a pushTemplate or an emailTemplate');\n }\n if (channels[0] === channels[1]) {\n throw new TypeError('prefer(): candidates must be one push and one email template');\n }\n if (typeof props !== 'object' || props === null || Array.isArray(props)) {\n throw new TypeError(\n 'prefer(): props must be an object — pass {} when the templates declare none'\n );\n }\n if (options === undefined) return;\n if (typeof options !== 'object' || options === null || Array.isArray(options)) {\n throw new TypeError('prefer(): options must be an object');\n }\n for (const [name, value] of Object.entries(options)) {\n if (name !== 'label') {\n throw new TypeError(\n `prefer(): unknown option '${name}' — props go in the second argument, options take only 'label'`\n );\n }\n if (typeof value !== 'string') throw new TypeError(\"prefer(): 'label' must be a string\");\n }\n}\n\n/** A reusable flow fragment (what `flow(...)` returns), referenced directly by branch arms. */\nexport interface Flow {\n readonly __flow: true;\n}\n\ninterface FlowInternal extends Flow {\n readonly nodes: NodeIR[];\n readonly uses: readonly TemplateUse[];\n readonly actions: readonly ActionRef[];\n}\n\n/**\n * @internal A template definition a flow sends, kept beside the IR (which names it by id only):\n * compileConfig checks that the registered definition under that id is this very object, so the\n * schema that typed the call is the one that renders it. Never part of the IR or its hash.\n */\nexport interface TemplateUse {\n readonly template: AnyTemplate;\n readonly loc: SourceLocIR | undefined;\n}\n\n/** @internal The template definitions a workflow sends, sub-flows and fragments included. */\nexport function templateUses(builder: FlowBuilder): readonly TemplateUse[] {\n return builder instanceof FlowBuilderImpl ? builder.uses : [];\n}\n\n/**\n * @internal The action definitions a workflow runs, sub-flows and fragments included. The IR\n * names an action only; compileBundle checks that each ref is the very object listed in\n * `actions`, which is what keeps two definitions from sharing one name. Never part of the IR.\n */\nexport function actionUses(builder: FlowBuilder): readonly ActionRef[] {\n return builder instanceof FlowBuilderImpl ? builder.actions : [];\n}\n\n/** Sub-flow: a named fragment, or an inline callback (runs once at construction — builder in, builder out). */\nexport type SubFlow = Flow | ((w: FlowBuilder) => FlowBuilder);\n\n/** A branch arm: the [condition, sub-flow] tuple — an [if, then] ordering convention. */\nexport type BranchCase = readonly [condition: Condition, flow: SubFlow];\n\n/**\n * A branch argument: either a tuple arm, or a bare sub-flow meaning the default\n * arm. The bare form may appear once, and must come last (checked at runtime).\n */\nexport type BranchArm = BranchCase | SubFlow;\n\n/**\n * A cohort arm name has two jobs, and both constrain its spelling:\n * - it is interpolated into the node ids of the arm's flow ('{id}.{name}.{j}'),\n * and an id is a durable step name — a dot would fake a nesting level and can\n * collide with a real one, an empty name gives '{id}..{j}';\n * - it is an object key, and JavaScript lists integer-like keys first in\n * ascending numeric order however the author wrote them. The arms array is\n * documented (and interpreted) as authoring order, and the bucketing walk\n * accumulates weights along it, so an arm named '0' added to a live\n * experiment would prepend itself and re-bucket everyone already in it.\n */\nconst ARM_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;\n\n/** A sub-flow's nodes; the template definitions it sends and the actions it runs are added to `uses` / `actions`. */\nfunction resolveSubFlow(sub: SubFlow, uses: TemplateUse[], actions: ActionRef[]): NodeIR[] {\n if (typeof sub === 'function') {\n const builder = new FlowBuilderImpl();\n const returned: unknown = sub(builder);\n // An async callback would add its nodes after construction is over — after ids were assigned\n if (typeof (returned as { then?: unknown } | undefined)?.then === 'function') {\n throw new TypeError(\n 'sub-flow callbacks must be synchronous: they run once, while the workflow is defined'\n );\n }\n uses.push(...builder.uses);\n actions.push(...builder.actions);\n return builder.nodes;\n }\n uses.push(...(sub as FlowInternal).uses);\n actions.push(...(sub as FlowInternal).actions);\n /*\n * A named fragment is a value, and the convention is to reuse it — two branch\n * arms may hold the same one. Handing out its own nodes aliases them into\n * both places, and assignIds writes ids *in place*: the second prefix\n * overwrites the first, so the two placements end up as one object under one\n * id — one durable step name, one message idempotency key, one bucket seed.\n * A copy per placement is what makes a fragment behave like a value.\n */\n return structuredClone((sub as FlowInternal).nodes);\n}\n\nexport interface FlowBuilder {\n /* ---- Messages: every channel is one message node; separate methods buy channel-level typing ---- */\n email<T extends EmailTemplate>(template: T, ...props: MessageArgs<PropsOf<T>>): this;\n sms<P extends object>(template: TemplateRef<'sms', P>, ...props: MessageArgs<P>): this;\n /**\n * Push to the user's devices — every device the host's directory lists, or\n * only the most recently registered with `{ devices: 'latest' }`. A user with\n * no device is skipped (`prefer([pushTpl, emailTpl], props)` falls back to email).\n */\n push<T extends PushTemplate>(\n template: T,\n ...args: [...props: MessageArgs<PropsOf<T>>, options?: PushOptions]\n ): this;\n inApp<P extends object>(template: TemplateRef<'in_app', P>, ...props: MessageArgs<P>): this;\n slack<T extends SlackTemplate<PropsSchema, never>>(\n template: T,\n ...props: MessageArgs<PropsOf<T>>\n ): this;\n discord<T extends DiscordTemplate<PropsSchema, never>>(\n template: T,\n ...props: MessageArgs<PropsOf<T>>\n ): this;\n survey<P extends object>(template: TemplateRef<'survey', P>, ...props: MessageArgs<P>): this;\n\n /**\n * Send one message on the first channel the user can be reached on: one push\n * and one email template, in priority order, rendered with the same props.\n * Sugar for the branch it compiles to — same IR, ids and hash as writing\n *\n * .branch(label, [reachable(first.channel), (b) => b.<first>(first, props)], (b) => b.<second>(second, props))\n *\n * so the choice is made once, when the step is reached, and a first choice\n * that fails to send retries as itself — it never falls through to the\n * second. Props are always passed (`{}` for templates that declare none),\n * and both templates must declare the same props type; for differing props\n * or other channels, write the branch.\n *\n * .prefer([push.tip, email.tip], { name: u.name }, { label: 'tip by channel' })\n */\n prefer<const T extends PreferPair, const A extends PropsInput<NoInfer<PropsOf<T[0]>>>>(\n candidates: T & SameProps<NoInfer<T>>,\n props: A & NoInfer<NoExtra<A, PropsOf<T[0]>>>,\n options?: PreferOptions\n ): this;\n\n /* --------------------------------- Delays --------------------------------- */\n /** Time Delay; passing { min, max } makes it a Randomized Delay. */\n delay(duration: Duration): this;\n delay(range: { min: Duration; max: Duration }): this;\n\n /** Time Window: hold until inside the window (e.g. weekdays 09:00–17:00). tz: 'user' uses the user's timezone. */\n timeWindow(opts: {\n days?: readonly Weekday[];\n between: readonly [TimeOfDay, TimeOfDay];\n tz?: 'user' | (string & {});\n }): this;\n\n /**\n * Wait Until: continue on the main line once the condition holds, or take\n * onTimeout when it expires (default 'continue'). On the engine side this is\n * \"await event racing a timer\" — a native primitive of durable runtimes.\n */\n waitUntil(\n condition: Condition,\n opts: { timeout: Duration; onTimeout?: 'continue' | 'exit' | SubFlow }\n ): this;\n\n /**\n * Splice a fragment in place: a named `flow(...)` or a callback, expanded\n * once while the workflow is defined — a composition step before compiling,\n * not a node (the IR has no trace of it, and ids are assigned over the whole\n * workflow as if the steps were written inline). Each use gets its own copy,\n * so one fragment can be used in several places and workflows.\n *\n * const officeHours = flow((w) => w.timeWindow({ days: ['mon', 'tue', 'wed', 'thu', 'fri'], between: ['09:00', '17:00'] }));\n * workflow({ id: 'onboarding', ... }).delay('1 day').use(officeHours).email(email.tip, { name: u.name })\n */\n use(fragment: SubFlow): this;\n\n /* ------------------------------ Flow Control ------------------------------ */\n /**\n * Conditional branch: ordered first-match (same semantics as Step Functions\n * Choice / Knock branch). This one primitive covers both the UI's True/False\n * Branch (two arms) and Multi-Split Branch (N arms). Arms are\n * [condition, sub-flow] tuples; a bare sub-flow in tail position is the\n * default arm. With no match and no default, execution simply continues.\n * Rejoin is structural: after the matching arm finishes, execution resumes\n * at the node following the branch — to opt out, call .exit() inside the arm.\n *\n * .branch([activeSubscriber, upgradeFlow], firstTimeFlow) // True/False\n * .branch([vip, vipFlow], [trial, trialFlow], defaultFlow) // Multi-Split\n * .branch([not(usedStaging), eduFlow]) // single arm: no match continues\n *\n * The optional first argument `label` becomes the node's name in IR (UI title\n * / observability handle). It is not a jump target — there is no goto here;\n * looping is a future re-entry-policy topic (see sendEvent). Arm labels in\n * the UI are derived from the condition.\n */\n branch(...arms: readonly BranchArm[]): this;\n branch(label: string, ...arms: readonly BranchArm[]): this;\n\n /**\n * Gate: exit unless the condition holds, otherwise continue. A first-class\n * node rather than sugar over branch — same semantics as Zapier's \"only\n * continue if\" / Iterable's Filter tile, and rendered on its own in the UI.\n * `reason` is the audit-log line — metadata, so rewording it is free\n * (excluded from contentHash, see hash.ts).\n */\n filter(condition: Condition, opts?: { reason?: string }): this;\n\n /**\n * Random Cohort Branch (A/B): weights must sum to 100 (checked at runtime).\n * `key` names the experiment: bucketing hashes `userId:key` instead of the\n * structural node id, so assignments survive node insertion/moves and the\n * experiment keeps one identity across workflow versions — set it for any\n * A/B whose results you intend to read.\n *\n * Arm names become node id segments and are read back in authoring order, so\n * they are restricted to letters, digits, '_' and '-', never starting with a\n * digit (checked at runtime).\n */\n cohort(arms: Record<string, { weight: number; flow?: SubFlow }>, opts?: { key?: string }): this;\n\n /**\n * Exit: end the whole workflow immediately (the UI's Exit node); `reason`\n * goes into the audit log and is metadata, so rewording it neither repins\n * in-flight journeys nor shows up in plan. Inside a branch arm this means\n * \"terminate, do not rejoin\" — it stops here instead of falling through,\n * while an arm without exit rejoins naturally.\n */\n exit(reason?: string): this;\n\n /* ---------------------------------- Data ---------------------------------- */\n /**\n * Emit a typed event (customer.io's Send Event). The event comes from an\n * e.xxx reference, so payload types flow in the same way trigger.event works.\n * This is how workflows compose: an event can trigger another workflow, and\n * the resulting call graph is statically analyzable. Payload values may\n * reference u.xxx. Only scalar fields can be sent (IR carries literals and\n * profile refs, not nested JSON): an event whose payload requires a nested\n * field cannot be emitted from a journey, and the types say so.\n *\n * Note on loops: a trailing self-triggering sendEvent will become the\n * official periodic-flow shape *once a re-entry policy exists* — today the\n * entry policy is once-per-user, so a self-trigger cannot re-enter and does\n * not loop.\n * TODO: the rest of the Data category — outbound webhook / profile update /\n * journey attributes.\n */\n sendEvent<P extends object>(event: EventRef<P>, ...payload: EmitArgs<P>): this;\n\n /**\n * Run a custom action (see dsl/action.ts for the model). The chain records\n * identity only — name and args — never the code: the implementation\n * ships inside the deployed Worker bundle and is resolved by name from the\n * runtime registry. Args are typed by the ActionRef and may reference u.xxx,\n * resolved at run time exactly like message props. Executed inside a durable\n * step: retried on throw, checkpointed on success.\n */\n run<A extends object>(action: ActionRef<A>, ...args: MessageArgs<A>): this;\n}\n\nconst DEFINED_CHANNELS: ReadonlySet<ChannelIR> = new Set(Object.values(CHANNEL_OF));\n\n/** A message's template: a definition of the channel (named by its id), or a reference by key. */\ntype MessageTemplate = AnyTemplate | TemplateRef;\n\nfunction templateKey(channel: ChannelIR, tpl: MessageTemplate): string {\n if (!DEFINED_CHANNELS.has(channel)) return (tpl as TemplateRef).key;\n // Typed, but a JS caller (or an `any`) reaches it unchecked: fail where the workflow is written\n if (!isTemplate(tpl) || CHANNEL_OF[tpl.kind] !== channel) {\n throw new TypeError(`${channel}(): expects a ${channel} template definition`);\n }\n return tpl.id;\n}\n\nfunction messageNode(\n channel: ChannelIR,\n tpl: MessageTemplate,\n props: object | undefined,\n devices?: 'latest'\n): NodeIR {\n return {\n id: '',\n type: 'message',\n channel,\n template: templateKey(channel, tpl),\n props: (props ?? {}) as Record<string, PropValueIR>,\n // Absent for 'all', so adding the option left every existing push's hash as it was\n ...(devices !== undefined ? { devices } : {}),\n };\n}\n\n/* oxlint-disable typescript/unbound-method --\n * `captureLoc(this.xxx)` passes the method by identity as the stack-trace\n * boundary for Error.captureStackTrace; it is never invoked, so `this`\n * scoping cannot go wrong. */\n/** @internal extended by WorkflowBuilderImpl; not part of the public API */\nexport class FlowBuilderImpl implements FlowBuilder {\n /** Nodes as collected; ids are assigned in one pass inside toIR, so '' is a placeholder here. */\n readonly nodes: NodeIR[] = [];\n /** The template definitions sent, with where: compile-time only, never in the IR. */\n readonly uses: TemplateUse[] = [];\n /** The action definitions run: compile-time identity only, never in the IR. */\n readonly actions: ActionRef[] = [];\n\n /** Provenance: the callsite (captured in the public method) lands in meta.loc, outside the hash. */\n private pushNode(node: NodeIR, loc: SourceLocIR | undefined): this {\n this.nodes.push({ ...node, ...(loc !== undefined ? { meta: { loc } } : {}) });\n return this;\n }\n\n private message(\n channel: ChannelIR,\n tpl: MessageTemplate,\n props: object | undefined,\n loc: SourceLocIR | undefined,\n devices?: 'latest'\n ): this {\n this.pushNode(messageNode(channel, tpl, props, devices), loc);\n if (isTemplate(tpl)) this.uses.push({ template: tpl, loc });\n return this;\n }\n\n email<T extends EmailTemplate>(t: T, ...args: MessageArgs<PropsOf<T>>): this {\n return this.message('email', t, args[0], captureLoc(this.email));\n }\n sms<P extends object>(t: TemplateRef<'sms', P>, ...args: MessageArgs<P>): this {\n return this.message('sms', t, args[0], captureLoc(this.sms));\n }\n push<T extends PushTemplate>(\n t: T,\n ...args: [...props: MessageArgs<PropsOf<T>>, options?: PushOptions]\n ): this {\n const [props, options] = args as unknown as [object | undefined, PushOptions | undefined];\n const devices = options?.devices === 'latest' ? 'latest' : undefined;\n return this.message('push', t, props, captureLoc(this.push), devices);\n }\n inApp<P extends object>(t: TemplateRef<'in_app', P>, ...args: MessageArgs<P>): this {\n return this.message('in_app', t, args[0], captureLoc(this.inApp));\n }\n slack<T extends SlackTemplate<PropsSchema, never>>(t: T, ...args: MessageArgs<PropsOf<T>>): this {\n return this.message('slack', t, args[0], captureLoc(this.slack));\n }\n discord<T extends DiscordTemplate<PropsSchema, never>>(\n t: T,\n ...args: MessageArgs<PropsOf<T>>\n ): this {\n return this.message('discord', t, args[0], captureLoc(this.discord));\n }\n survey<P extends object>(t: TemplateRef<'survey', P>, ...args: MessageArgs<P>): this {\n return this.message('survey', t, args[0], captureLoc(this.survey));\n }\n\n prefer<const T extends PreferPair, const A extends PropsInput<NoInfer<PropsOf<T[0]>>>>(\n candidates: T & SameProps<NoInfer<T>>,\n props: A & NoInfer<NoExtra<A, PropsOf<T[0]>>>,\n options?: PreferOptions\n ): this {\n checkPreferArgs(candidates, props, options);\n // Every generated node points at the author's prefer() call, not at this method's body\n const loc = captureLoc(this.prefer);\n const meta = loc !== undefined ? { meta: { loc } } : {};\n const [first, second] = candidates as readonly (EmailTemplate | PushTemplate)[];\n const channel = (tpl: EmailTemplate | PushTemplate) => CHANNEL_OF[tpl.kind] as 'email' | 'push';\n // Both are sent from here as far as the registry check goes, the fallback included\n this.uses.push({ template: first, loc }, { template: second, loc });\n // A copy per message, as two separately written calls would hold\n const arm = (tpl: EmailTemplate | PushTemplate): NodeIR[] => [\n { ...messageNode(channel(tpl), tpl, { ...props }), ...meta },\n ];\n return this.pushNode(\n {\n id: '',\n type: 'branch',\n ...(options?.label !== undefined ? { label: options.label } : {}),\n cases: [\n { condition: { type: 'reachable', channel: channel(first), ...meta }, flow: arm(first) },\n ],\n otherwise: arm(second),\n },\n loc\n );\n }\n\n delay(duration: Duration): this;\n delay(range: { min: Duration; max: Duration }): this;\n delay(d: Duration | { min: Duration; max: Duration }): this {\n const loc = captureLoc(this.delay);\n if (typeof d === 'string') {\n return this.pushNode({ id: '', type: 'delay', duration: durationIR(d) }, loc);\n }\n const min = durationIR(d.min);\n const max = durationIR(d.max);\n /*\n * The interpreter draws `min + random(max - min)` with the span clamped at\n * zero, so a backwards range does not fail — it quietly collapses into a\n * fixed `min` sleep. Reject it here, where the author can still see it.\n */\n if (max.ms < min.ms) {\n throw new Error(\n `delay(): 'max' must not be shorter than 'min', got { min: '${d.min}', max: '${d.max}' }`\n );\n }\n return this.pushNode({ id: '', type: 'random_delay', min, max }, loc);\n }\n\n timeWindow(opts: {\n days?: readonly Weekday[];\n between: readonly [TimeOfDay, TimeOfDay];\n tz?: 'user' | (string & {});\n }): this {\n const loc = captureLoc(this.timeWindow);\n if (opts.days !== undefined) {\n // An empty list is a window that never opens: the node would hold the user forever\n if (opts.days.length === 0) {\n throw new Error(\"timeWindow(): 'days' must name at least one day\");\n }\n const seen = new Set<Weekday>();\n for (const day of opts.days) {\n if (seen.has(day)) throw new Error(`timeWindow(): 'days' lists '${day}' twice`);\n seen.add(day);\n }\n }\n const start = timeOfDayMinutes(opts.between[0]);\n const end = timeOfDayMinutes(opts.between[1]);\n if (end <= start) {\n throw new Error(\n `timeWindow(): 'between' must open before it closes within one day, got [${opts.between[0]}, ${opts.between[1]}] (overnight windows are not supported yet)`\n );\n }\n return this.pushNode(\n {\n id: '',\n type: 'time_window',\n days: [...(opts.days ?? (['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as const))],\n between: [opts.between[0], opts.between[1]],\n tz: opts.tz ?? 'user',\n },\n loc\n );\n }\n\n waitUntil(\n condition: Condition,\n opts: { timeout: Duration; onTimeout?: 'continue' | 'exit' | SubFlow }\n ): this {\n const loc = captureLoc(this.waitUntil);\n const onTimeout = opts.onTimeout ?? 'continue';\n return this.pushNode(\n {\n id: '',\n type: 'wait_until',\n condition: condIR(condition),\n timeout: positiveDurationIR(opts.timeout, 'waitUntil(): timeout'),\n onTimeout:\n onTimeout === 'continue' || onTimeout === 'exit'\n ? onTimeout\n : resolveSubFlow(onTimeout, this.uses, this.actions),\n },\n loc\n );\n }\n\n use(fragment: SubFlow): this {\n // The fragment's nodes carry their own provenance (where the fragment was written)\n this.nodes.push(...resolveSubFlow(fragment, this.uses, this.actions));\n return this;\n }\n\n branch(...arms: readonly BranchArm[]): this;\n branch(label: string, ...arms: readonly BranchArm[]): this;\n branch(...args: readonly (string | BranchArm)[]): this {\n const loc = captureLoc(this.branch);\n const label = typeof args[0] === 'string' ? args[0] : undefined;\n const arms = (label === undefined ? args : args.slice(1)) as readonly BranchArm[];\n\n const cases: { condition: ConditionIR; flow: NodeIR[] }[] = [];\n let otherwise: NodeIR[] | undefined;\n arms.forEach((arm, i) => {\n if (Array.isArray(arm)) {\n if (otherwise !== undefined) {\n throw new Error('branch(): default arm (bare sub-flow) must be the last argument');\n }\n const [condition, sub] = arm as BranchCase;\n cases.push({\n condition: condIR(condition),\n flow: resolveSubFlow(sub, this.uses, this.actions),\n });\n } else {\n if (otherwise !== undefined) {\n throw new Error('branch(): only one default arm (bare sub-flow) is allowed');\n }\n if (i !== arms.length - 1) {\n throw new Error('branch(): default arm (bare sub-flow) must be the last argument');\n }\n otherwise = resolveSubFlow(arm as SubFlow, this.uses, this.actions);\n }\n });\n\n return this.pushNode(\n {\n id: '',\n type: 'branch',\n ...(label !== undefined ? { label } : {}),\n cases,\n ...(otherwise !== undefined ? { otherwise } : {}),\n },\n loc\n );\n }\n\n filter(condition: Condition, opts?: { reason?: string }): this {\n return this.pushNode(\n {\n id: '',\n type: 'filter',\n condition: condIR(condition),\n ...(opts?.reason !== undefined ? { reason: opts.reason } : {}),\n },\n captureLoc(this.filter)\n );\n }\n\n cohort(arms: Record<string, { weight: number; flow?: SubFlow }>, opts?: { key?: string }): this {\n const loc = captureLoc(this.cohort);\n const entries = Object.entries(arms);\n /*\n * Weights live on a 0.01% grid: the runtime buckets into 10,000 slots\n * (basis points), so anything finer would be silently quantized — reject\n * it here instead. Converting to integer basis points also makes the\n * sum check exact; no epsilon needed.\n */\n const basisPoints = entries.map(([name, a]) => {\n if (!ARM_NAME.test(name)) {\n throw new Error(\n `cohort(): arm name '${name}' must start with a letter or '_' and contain only letters, digits, '_' or '-' — arm names become node id segments, and integer-like names would silently reorder the arms`\n );\n }\n const bp = a.weight * 100;\n if (Math.abs(bp - Math.round(bp)) > 1e-6) {\n throw new Error(\n `cohort(): arm '${name}' weight ${a.weight} is finer than the 0.01% bucketing grid — use at most two decimal places`\n );\n }\n /*\n * The sum check alone accepts -50 / 150: the runtime walks the arms\n * accumulating basis points and takes the first whose cumulative total\n * clears the bucket, so a negative weight hands 100% of users to its\n * neighbour instead of splitting anything.\n */\n if (bp < 0) {\n throw new Error(`cohort(): arm '${name}' weight ${a.weight} must not be negative`);\n }\n return Math.round(bp);\n });\n const total = basisPoints.reduce((sum, bp) => sum + bp, 0);\n if (total !== 10_000) {\n throw new Error(`cohort(): weights must sum to 100, got ${total / 100}`);\n }\n return this.pushNode(\n {\n id: '',\n type: 'cohort',\n ...(opts?.key !== undefined ? { key: opts.key } : {}),\n arms: entries.map(([name, a]) => ({\n name,\n weight: a.weight,\n flow: a.flow ? resolveSubFlow(a.flow, this.uses, this.actions) : [],\n })),\n },\n loc\n );\n }\n\n exit(reason?: string): this {\n return this.pushNode(\n { id: '', type: 'exit', ...(reason !== undefined ? { reason } : {}) },\n captureLoc(this.exit)\n );\n }\n\n sendEvent<P extends object>(ev: EventRef<P>, ...payload: EmitArgs<P>): this {\n const values = (payload[0] ?? {}) as Record<string, unknown>;\n for (const [field, value] of Object.entries(values)) {\n const ref =\n typeof value === 'object' &&\n value !== null &&\n (value as { type?: unknown }).type === 'user_property';\n if (!ref && !['string', 'number', 'boolean'].includes(typeof value)) {\n throw new TypeError(\n `sendEvent('${ev.name}'): '${field}' is not a scalar or a u.xxx reference — an emitted payload carries scalar fields only`\n );\n }\n }\n return this.pushNode(\n {\n id: '',\n type: 'send_event',\n event: ev.name,\n payload: values as Record<string, PropValueIR>,\n },\n captureLoc(this.sendEvent)\n );\n }\n\n run<A extends object>(a: ActionRef<A>, ...args: MessageArgs<A>): this {\n this.actions.push(a);\n return this.pushNode(\n {\n id: '',\n type: 'action',\n action: a.name,\n args: (args[0] ?? {}) as Record<string, PropValueIR>,\n },\n captureLoc(this.run)\n );\n }\n}\n/* oxlint-enable typescript/unbound-method */\n\n/**\n * A reusable flow fragment: a free function. Once personalization goes through\n * u.xxx and events through e.xxx, the flow layer carries no schema generics.\n */\nexport function flow(build: (w: FlowBuilder) => FlowBuilder): Flow {\n const builder = new FlowBuilderImpl();\n build(builder);\n const impl: FlowInternal = {\n __flow: true,\n nodes: builder.nodes,\n uses: builder.uses,\n actions: builder.actions,\n };\n return impl;\n}\n"],"mappings":";;;;;;;AA0EA,SAAS,gBAAgB,YAAqB,OAAgB,SAAwB;CACpF,IAAI,CAAC,MAAM,QAAQ,UAAU,KAAK,WAAW,WAAW,GACtD,MAAM,IAAI,UAAU,0EAA0E;CAEhG,MAAM,WAAY,WAAyB,KAAK,cAC9CA,kBAAAA,WAAW,SAAS,IAAIC,kBAAAA,WAAW,UAAU,QAAQ,KAAA,CACvD;CACA,IAA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IAChC;IACA,QAAQ,EAAE;IACV,MAAM,EAAE,OAAO,eAAe,EAAE,MAAM,KAAK,MAAM,KAAK,OAAO,IAAI,CAAC;GACpE,EAAE;EACJ,GACA,GACF;CACF;CAEA,KAAK,QAAuB;EAC1B,OAAO,KAAK,SACV;GAAE,IAAI;GAAI,MAAM;GAAQ,GAAI,WAAW,KAAA,IAAY,EAAE,OAAO,IAAI,CAAC;EAAG,GACpEA,mBAAAA,WAAW,KAAK,IAAI,CACtB;CACF;CAEA,UAA4B,IAAiB,GAAG,SAA4B;EAC1E,MAAM,SAAU,QAAQ,MAAM,CAAC;EAC/B,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,MAAM,GAKhD,IAAI,EAHF,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS,oBAC7B,CAAC;GAAC;GAAU;GAAU;EAAS,CAAC,CAAC,SAAS,OAAO,KAAK,GAChE,MAAM,IAAI,UACR,cAAc,GAAG,KAAK,OAAO,MAAM,uFACrC;EAGJ,OAAO,KAAK,SACV;GACE,IAAI;GACJ,MAAM;GACN,OAAO,GAAG;GACV,SAAS;EACX,GACAA,mBAAAA,WAAW,KAAK,SAAS,CAC3B;CACF;CAEA,IAAsB,GAAiB,GAAG,MAA4B;EACpE,KAAK,QAAQ,KAAK,CAAC;EACnB,OAAO,KAAK,SACV;GACE,IAAI;GACJ,MAAM;GACN,QAAQ,EAAE;GACV,MAAO,KAAK,MAAM,CAAC;EACrB,GACAA,mBAAAA,WAAW,KAAK,GAAG,CACrB;CACF;AACF;;;;;AAOA,SAAgB,KAAK,OAA8C;CACjE,MAAM,UAAU,IAAI,gBAAgB;CACpC,MAAM,OAAO;CAOb,OAAO;EALL,QAAQ;EACR,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,SAAS,QAAQ;CAET;AACZ"}
1
+ {"version":3,"file":"flow.cjs","names":["isTemplate","CHANNEL_OF","captureLoc","durationIR","timeOfDayMinutes","condIR","positiveDurationIR"],"sources":["../../src/dsl/flow.ts"],"sourcesContent":["import type { ChannelIR, ConditionIR, NodeIR, PropValueIR, SourceLocIR } from '../ir';\nimport { captureLoc } from '../provenance';\nimport {\n type AnyTemplate,\n CHANNEL_OF,\n type DiscordTemplate,\n type EmailTemplate,\n type PropsSchema,\n type PushTemplate,\n type SlackTemplate,\n isTemplate,\n} from '../templates';\nimport type { ActionRef } from './action';\nimport { type Duration, type TimeOfDay, type Weekday, durationIR, timeOfDayMinutes } from './base';\nimport { type Condition, condIR, positiveDurationIR } from './condition';\nimport type { EventRef, MessageArgs, PropInput, PropsInput } from './refs';\nimport type { PropsOf, TemplateRef } from './template';\n\n/**\n * The flow chain — FlowBuilder is the DSL's step surface (messages, delays,\n * flow control, data), and its implementation is the compiler front half: each\n * chained call executes no logic, it just collects one IR node (ids are\n * assigned later, in workflow.toIR()). Sub-flow callbacks run exactly once at\n * construction — builder in, builder out — so the output is always a static\n * tree.\n *\n * Every public method also captures its callsite (provenance): the loc lands\n * in the node's hash-excluded meta and is the anchor for future in-place\n * editing from the studio.\n */\n\ntype Scalar = string | number | boolean;\n\n/** An emitted field: a scalar (or a profile ref to one); a nested field cannot be sent. */\ntype EmitValue<T> = [NonNullable<T>] extends [Scalar] ? PropInput<T> : never;\n\n/** The payload `sendEvent` accepts for an event: its fields, scalar ones only. */\nexport type EmitPayload<P> = { [K in keyof P]: EmitValue<P[K]> };\n\n/** Payload may be omitted when the event declares no required field. */\nexport type EmitArgs<P> =\n Record<string, never> extends P ? [payload?: EmitPayload<P>] : [payload: EmitPayload<P>];\n\n/** Per-node push options. */\nexport interface PushOptions {\n /** Which devices get a copy: 'all' (the default) or only the most recently registered. */\n devices?: 'all' | 'latest';\n}\n\n/** `prefer()` options. */\nexport interface PreferOptions {\n /** The generated branch's name in IR (UI title / observability handle), as `branch(label, …)`. */\n label?: string;\n}\n\n/** The candidates `prefer()` takes: one push and one email template, in priority order. */\ntype PreferPair = readonly [PushTemplate, EmailTemplate] | readonly [EmailTemplate, PushTemplate];\n\ntype NormalizeProps<P> = { -readonly [K in keyof P]: P[K] };\ntype Equal<A, B> =\n (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;\n\n/** Both candidates render the one props object, so they must declare the same props type — not merely overlap. */\ntype SameProps<T extends PreferPair> =\n Equal<NormalizeProps<PropsOf<T[0]>>, NormalizeProps<PropsOf<T[1]>>> extends true\n ? unknown\n : { readonly __prefer_error__: 'Both templates must declare the same props type' };\n\n/** Distributes, so a field only one member of a union variable has still counts as extra. */\ntype KeysOfUnion<A> = A extends unknown ? keyof A : never;\n/** Rejects known extra fields, which `{}` (an empty props schema) would otherwise accept. */\ntype NoExtra<A, P> = Record<Exclude<KeysOfUnion<A>, keyof P>, never>;\n\n/** prefer() is typed strictly, but a JS caller (or an `any`) reaches it unchecked — fail at the call, not at send time. */\nfunction checkPreferArgs(candidates: unknown, props: unknown, options: unknown): void {\n if (!Array.isArray(candidates) || candidates.length !== 2) {\n throw new TypeError('prefer(): candidates must be exactly two templates — one push, one email');\n }\n const channels = (candidates as unknown[]).map((candidate) =>\n isTemplate(candidate) ? CHANNEL_OF[candidate.kind] : undefined\n );\n if (!channels.every((channel) => channel === 'push' || channel === 'email')) {\n throw new TypeError('prefer(): each candidate must be a pushTemplate or an emailTemplate');\n }\n if (channels[0] === channels[1]) {\n throw new TypeError('prefer(): candidates must be one push and one email template');\n }\n if (typeof props !== 'object' || props === null || Array.isArray(props)) {\n throw new TypeError(\n 'prefer(): props must be an object — pass {} when the templates declare none'\n );\n }\n if (options === undefined) return;\n if (typeof options !== 'object' || options === null || Array.isArray(options)) {\n throw new TypeError('prefer(): options must be an object');\n }\n for (const [name, value] of Object.entries(options)) {\n if (name !== 'label') {\n throw new TypeError(\n `prefer(): unknown option '${name}' — props go in the second argument, options take only 'label'`\n );\n }\n if (typeof value !== 'string') throw new TypeError(\"prefer(): 'label' must be a string\");\n }\n}\n\n/** A reusable flow fragment (what `flow(...)` returns), referenced directly by branch arms. */\nexport interface Flow {\n readonly __flow: true;\n}\n\ninterface FlowInternal extends Flow {\n readonly nodes: NodeIR[];\n readonly uses: readonly TemplateUse[];\n readonly actions: readonly ActionRef[];\n}\n\n/**\n * @internal A template definition a flow sends, kept beside the IR (which names it by id only):\n * compileConfig checks that the registered definition under that id is this very object, so the\n * schema that typed the call is the one that renders it. Never part of the IR or its hash.\n */\nexport interface TemplateUse {\n readonly template: AnyTemplate;\n readonly loc: SourceLocIR | undefined;\n}\n\n/** @internal The template definitions a workflow sends, sub-flows and fragments included. */\nexport function templateUses(builder: FlowBuilder): readonly TemplateUse[] {\n return builder instanceof FlowBuilderImpl ? builder.uses : [];\n}\n\n/**\n * @internal The action definitions a workflow runs, sub-flows and fragments included. The IR\n * names an action only; compileBundle checks that each ref is the very object listed in\n * `actions`, which is what keeps two definitions from sharing one name. Never part of the IR.\n */\nexport function actionUses(builder: FlowBuilder): readonly ActionRef[] {\n return builder instanceof FlowBuilderImpl ? builder.actions : [];\n}\n\n/** Sub-flow: a named fragment, or an inline callback (runs once at construction — builder in, builder out). */\nexport type SubFlow = Flow | ((w: FlowBuilder) => FlowBuilder);\n\n/** A branch arm: the [condition, sub-flow] tuple — an [if, then] ordering convention. */\nexport type BranchCase = readonly [condition: Condition, flow: SubFlow];\n\n/**\n * A branch argument: either a tuple arm, or a bare sub-flow meaning the default\n * arm. The bare form may appear once, and must come last (checked at runtime).\n */\nexport type BranchArm = BranchCase | SubFlow;\n\n/**\n * A cohort arm name has two jobs, and both constrain its spelling:\n * - it is interpolated into the node ids of the arm's flow ('{id}.{name}.{j}'),\n * and an id is a durable step name — a dot would fake a nesting level and can\n * collide with a real one, an empty name gives '{id}..{j}';\n * - it is an object key, and JavaScript lists integer-like keys first in\n * ascending numeric order however the author wrote them. The arms array is\n * documented (and interpreted) as authoring order, and the bucketing walk\n * accumulates weights along it, so an arm named '0' added to a live\n * experiment would prepend itself and re-bucket everyone already in it.\n */\nconst ARM_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;\n\n/** A sub-flow's nodes; the template definitions it sends and the actions it runs are added to `uses` / `actions`. */\nfunction resolveSubFlow(sub: SubFlow, uses: TemplateUse[], actions: ActionRef[]): NodeIR[] {\n if (typeof sub === 'function') {\n const builder = new FlowBuilderImpl();\n const returned: unknown = sub(builder);\n // An async callback would add its nodes after construction is over — after ids were assigned\n if (typeof (returned as { then?: unknown } | undefined)?.then === 'function') {\n throw new TypeError(\n 'sub-flow callbacks must be synchronous: they run once, while the workflow is defined'\n );\n }\n uses.push(...builder.uses);\n actions.push(...builder.actions);\n return builder.nodes;\n }\n uses.push(...(sub as FlowInternal).uses);\n actions.push(...(sub as FlowInternal).actions);\n /*\n * A named fragment is a value, and the convention is to reuse it — two branch\n * arms may hold the same one. Handing out its own nodes aliases them into\n * both places, and assignIds writes ids *in place*: the second prefix\n * overwrites the first, so the two placements end up as one object under one\n * id — one durable step name, one message idempotency key, one bucket seed.\n * A copy per placement is what makes a fragment behave like a value.\n */\n return structuredClone((sub as FlowInternal).nodes);\n}\n\nexport interface FlowBuilder {\n /* ---- Messages: every channel is one message node; separate methods buy channel-level typing ---- */\n email<T extends EmailTemplate>(template: T, ...props: MessageArgs<PropsOf<T>>): this;\n sms<P extends object>(template: TemplateRef<'sms', P>, ...props: MessageArgs<P>): this;\n /**\n * Push to the user's devices — every device the host's directory lists, or\n * only the most recently registered with `{ devices: 'latest' }`. A user with\n * no device is skipped (`prefer([pushTpl, emailTpl], props)` falls back to email).\n */\n push<T extends PushTemplate>(\n template: T,\n ...args: [...props: MessageArgs<PropsOf<T>>, options?: PushOptions]\n ): this;\n inApp<P extends object>(template: TemplateRef<'in_app', P>, ...props: MessageArgs<P>): this;\n slack<T extends SlackTemplate<PropsSchema, never>>(\n template: T,\n ...props: MessageArgs<PropsOf<T>>\n ): this;\n discord<T extends DiscordTemplate<PropsSchema, never>>(\n template: T,\n ...props: MessageArgs<PropsOf<T>>\n ): this;\n survey<P extends object>(template: TemplateRef<'survey', P>, ...props: MessageArgs<P>): this;\n\n /**\n * Send one message on the first channel the user can be reached on: one push\n * and one email template, in priority order, rendered with the same props.\n * Sugar for the branch it compiles to — same IR, ids and hash as writing\n *\n * .branch(label, [reachable(first.channel), (b) => b.<first>(first, props)], (b) => b.<second>(second, props))\n *\n * so the choice is made once, when the step is reached, and a first choice\n * that fails to send retries as itself — it never falls through to the\n * second. Props are always passed (`{}` for templates that declare none),\n * and both templates must declare the same props type; for differing props\n * or other channels, write the branch.\n *\n * .prefer([push.tip, email.tip], { name: u.name }, { label: 'tip by channel' })\n */\n prefer<const T extends PreferPair, const A extends PropsInput<NoInfer<PropsOf<T[0]>>>>(\n candidates: T & SameProps<NoInfer<T>>,\n props: A & NoInfer<NoExtra<A, PropsOf<T[0]>>>,\n options?: PreferOptions\n ): this;\n\n /* --------------------------------- Delays --------------------------------- */\n /** Time Delay; passing { min, max } makes it a Randomized Delay. */\n delay(duration: Duration): this;\n delay(range: { min: Duration; max: Duration }): this;\n\n /** Time Window: hold until inside the window (e.g. weekdays 09:00–17:00). tz: 'user' uses the user's timezone. */\n timeWindow(opts: {\n days?: readonly Weekday[];\n between: readonly [TimeOfDay, TimeOfDay];\n tz?: 'user' | (string & {});\n }): this;\n\n /**\n * Wait Until: continue on the main line once the condition holds, or take\n * onTimeout when it expires (default 'continue'). On the engine side this is\n * \"await event racing a timer\" — a native primitive of durable runtimes.\n */\n waitUntil(\n condition: Condition,\n opts: { timeout: Duration; onTimeout?: 'continue' | 'exit' | SubFlow }\n ): this;\n\n /**\n * Splice a fragment in place: a named `flow(...)` or a callback, expanded\n * once while the workflow is defined — a composition step before compiling,\n * not a node (the IR has no trace of it, and ids are assigned over the whole\n * workflow as if the steps were written inline). Each use gets its own copy,\n * so one fragment can be used in several places and workflows.\n *\n * const officeHours = flow((w) => w.timeWindow({ days: ['mon', 'tue', 'wed', 'thu', 'fri'], between: ['09:00', '17:00'] }));\n * workflow({ id: 'onboarding', ... }).delay('1 day').use(officeHours).email(email.tip, { name: u.name })\n */\n use(fragment: SubFlow): this;\n\n /* ------------------------------ Flow Control ------------------------------ */\n /**\n * Conditional branch: ordered first-match (same semantics as Step Functions\n * Choice / Knock branch). This one primitive covers both the UI's True/False\n * Branch (two arms) and Multi-Split Branch (N arms). Arms are\n * [condition, sub-flow] tuples; a bare sub-flow in tail position is the\n * default arm. With no match and no default, execution simply continues.\n * Rejoin is structural: after the matching arm finishes, execution resumes\n * at the node following the branch — to opt out, call .exit() inside the arm.\n *\n * .branch([activeSubscriber, upgradeFlow], firstTimeFlow) // True/False\n * .branch([vip, vipFlow], [trial, trialFlow], defaultFlow) // Multi-Split\n * .branch([not(usedStaging), eduFlow]) // single arm: no match continues\n *\n * The optional first argument `label` becomes the node's name in IR (UI title\n * / observability handle). It is not a jump target — there is no goto here;\n * looping is a future re-entry-policy topic (see sendEvent). Arm labels in\n * the UI are derived from the condition.\n */\n branch(...arms: readonly BranchArm[]): this;\n branch(label: string, ...arms: readonly BranchArm[]): this;\n\n /**\n * Gate: exit unless the condition holds, otherwise continue. A first-class\n * node rather than sugar over branch — same semantics as Zapier's \"only\n * continue if\" / Iterable's Filter tile, and rendered on its own in the UI.\n * `reason` is the audit-log line — metadata, so rewording it is free\n * (excluded from contentHash, see hash.ts).\n */\n filter(condition: Condition, opts?: { reason?: string }): this;\n\n /**\n * Random Cohort Branch (A/B): weights must sum to 100 (checked at runtime).\n * `key` names the experiment: bucketing hashes `userId:key` instead of the\n * structural node id, so assignments survive node insertion/moves and the\n * experiment keeps one identity across workflow versions — set it for any\n * A/B whose results you intend to read.\n *\n * Arm names become node id segments and are read back in authoring order, so\n * they are restricted to letters, digits, '_' and '-', never starting with a\n * digit (checked at runtime).\n */\n cohort(arms: Record<string, { weight: number; flow?: SubFlow }>, opts?: { key?: string }): this;\n\n /**\n * Exit: end the whole workflow immediately (the UI's Exit node); `reason`\n * goes into the audit log and is metadata, so rewording it neither repins\n * in-flight journeys nor shows up in plan. Inside a branch arm this means\n * \"terminate, do not rejoin\" — it stops here instead of falling through,\n * while an arm without exit rejoins naturally.\n */\n exit(reason?: string): this;\n\n /* ---------------------------------- Data ---------------------------------- */\n /**\n * Emit a typed event (customer.io's Send Event). The event comes from an\n * e.xxx reference, so payload types flow in the same way trigger.event works.\n * This is how workflows compose: an event can trigger another workflow, and\n * the resulting call graph is statically analyzable. Payload values may\n * reference u.xxx. Only scalar fields can be sent (IR carries literals and\n * profile refs, not nested JSON): an event whose payload requires a nested\n * field cannot be emitted from a journey, and the types say so.\n *\n * Note on loops: a trailing self-triggering sendEvent will become the\n * official periodic-flow shape *once a re-entry policy exists* — today the\n * entry policy is once-per-user, so a self-trigger cannot re-enter and does\n * not loop.\n * TODO: the rest of the Data category — outbound webhook / profile update /\n * journey attributes.\n */\n sendEvent<P extends object>(event: EventRef<P>, ...payload: EmitArgs<P>): this;\n\n /**\n * Run a custom action (see dsl/action.ts for the model). The chain records\n * identity only — name and args — never the code: the implementation\n * ships inside the deployed Worker bundle and is resolved by name from the\n * runtime registry. Args are typed by the ActionRef and may reference u.xxx,\n * resolved at run time exactly like message props. Executed inside a durable\n * step: retried on throw, checkpointed on success.\n */\n run<A extends object>(action: ActionRef<A>, ...args: MessageArgs<A>): this;\n}\n\nconst DEFINED_CHANNELS: ReadonlySet<ChannelIR> = new Set(Object.values(CHANNEL_OF));\n\n/** A message's template: a definition of the channel (named by its id), or a reference by key. */\ntype MessageTemplate = AnyTemplate | TemplateRef;\n\nfunction templateKey(channel: ChannelIR, tpl: MessageTemplate): string {\n if (!DEFINED_CHANNELS.has(channel)) return (tpl as TemplateRef).key;\n // Typed, but a JS caller (or an `any`) reaches it unchecked: fail where the workflow is written\n if (!isTemplate(tpl) || CHANNEL_OF[tpl.kind] !== channel) {\n throw new TypeError(`${channel}(): expects a ${channel} template definition`);\n }\n return tpl.id;\n}\n\nfunction messageNode(\n channel: ChannelIR,\n tpl: MessageTemplate,\n props: object | undefined,\n devices?: 'latest'\n): NodeIR {\n return {\n id: '',\n type: 'message',\n channel,\n template: templateKey(channel, tpl),\n props: (props ?? {}) as Record<string, PropValueIR>,\n // Absent for 'all', so adding the option left every existing push's hash as it was\n ...(devices !== undefined ? { devices } : {}),\n // An email's or push's topic (null: transactional) is what the engine checks the opt-outs against\n ...(channel === 'email' || channel === 'push'\n ? { topic: (tpl as EmailTemplate | PushTemplate).topic ?? null }\n : {}),\n };\n}\n\n/* oxlint-disable typescript/unbound-method --\n * `captureLoc(this.xxx)` passes the method by identity as the stack-trace\n * boundary for Error.captureStackTrace; it is never invoked, so `this`\n * scoping cannot go wrong. */\n/** @internal extended by WorkflowBuilderImpl; not part of the public API */\nexport class FlowBuilderImpl implements FlowBuilder {\n /** Nodes as collected; ids are assigned in one pass inside toIR, so '' is a placeholder here. */\n readonly nodes: NodeIR[] = [];\n /** The template definitions sent, with where: compile-time only, never in the IR. */\n readonly uses: TemplateUse[] = [];\n /** The action definitions run: compile-time identity only, never in the IR. */\n readonly actions: ActionRef[] = [];\n\n /** Provenance: the callsite (captured in the public method) lands in meta.loc, outside the hash. */\n private pushNode(node: NodeIR, loc: SourceLocIR | undefined): this {\n this.nodes.push({ ...node, ...(loc !== undefined ? { meta: { loc } } : {}) });\n return this;\n }\n\n private message(\n channel: ChannelIR,\n tpl: MessageTemplate,\n props: object | undefined,\n loc: SourceLocIR | undefined,\n devices?: 'latest'\n ): this {\n this.pushNode(messageNode(channel, tpl, props, devices), loc);\n if (isTemplate(tpl)) this.uses.push({ template: tpl, loc });\n return this;\n }\n\n email<T extends EmailTemplate>(t: T, ...args: MessageArgs<PropsOf<T>>): this {\n return this.message('email', t, args[0], captureLoc(this.email));\n }\n sms<P extends object>(t: TemplateRef<'sms', P>, ...args: MessageArgs<P>): this {\n return this.message('sms', t, args[0], captureLoc(this.sms));\n }\n push<T extends PushTemplate>(\n t: T,\n ...args: [...props: MessageArgs<PropsOf<T>>, options?: PushOptions]\n ): this {\n const [props, options] = args as unknown as [object | undefined, PushOptions | undefined];\n const devices = options?.devices === 'latest' ? 'latest' : undefined;\n return this.message('push', t, props, captureLoc(this.push), devices);\n }\n inApp<P extends object>(t: TemplateRef<'in_app', P>, ...args: MessageArgs<P>): this {\n return this.message('in_app', t, args[0], captureLoc(this.inApp));\n }\n slack<T extends SlackTemplate<PropsSchema, never>>(t: T, ...args: MessageArgs<PropsOf<T>>): this {\n return this.message('slack', t, args[0], captureLoc(this.slack));\n }\n discord<T extends DiscordTemplate<PropsSchema, never>>(\n t: T,\n ...args: MessageArgs<PropsOf<T>>\n ): this {\n return this.message('discord', t, args[0], captureLoc(this.discord));\n }\n survey<P extends object>(t: TemplateRef<'survey', P>, ...args: MessageArgs<P>): this {\n return this.message('survey', t, args[0], captureLoc(this.survey));\n }\n\n prefer<const T extends PreferPair, const A extends PropsInput<NoInfer<PropsOf<T[0]>>>>(\n candidates: T & SameProps<NoInfer<T>>,\n props: A & NoInfer<NoExtra<A, PropsOf<T[0]>>>,\n options?: PreferOptions\n ): this {\n checkPreferArgs(candidates, props, options);\n // Every generated node points at the author's prefer() call, not at this method's body\n const loc = captureLoc(this.prefer);\n const meta = loc !== undefined ? { meta: { loc } } : {};\n const [first, second] = candidates as readonly (EmailTemplate | PushTemplate)[];\n const channel = (tpl: EmailTemplate | PushTemplate) => CHANNEL_OF[tpl.kind] as 'email' | 'push';\n // Both are sent from here as far as the registry check goes, the fallback included\n this.uses.push({ template: first, loc }, { template: second, loc });\n // A copy per message, as two separately written calls would hold\n const arm = (tpl: EmailTemplate | PushTemplate): NodeIR[] => [\n { ...messageNode(channel(tpl), tpl, { ...props }), ...meta },\n ];\n return this.pushNode(\n {\n id: '',\n type: 'branch',\n ...(options?.label !== undefined ? { label: options.label } : {}),\n cases: [\n { condition: { type: 'reachable', channel: channel(first), ...meta }, flow: arm(first) },\n ],\n otherwise: arm(second),\n },\n loc\n );\n }\n\n delay(duration: Duration): this;\n delay(range: { min: Duration; max: Duration }): this;\n delay(d: Duration | { min: Duration; max: Duration }): this {\n const loc = captureLoc(this.delay);\n if (typeof d === 'string') {\n return this.pushNode({ id: '', type: 'delay', duration: durationIR(d) }, loc);\n }\n const min = durationIR(d.min);\n const max = durationIR(d.max);\n /*\n * The interpreter draws `min + random(max - min)` with the span clamped at\n * zero, so a backwards range does not fail — it quietly collapses into a\n * fixed `min` sleep. Reject it here, where the author can still see it.\n */\n if (max.ms < min.ms) {\n throw new Error(\n `delay(): 'max' must not be shorter than 'min', got { min: '${d.min}', max: '${d.max}' }`\n );\n }\n return this.pushNode({ id: '', type: 'random_delay', min, max }, loc);\n }\n\n timeWindow(opts: {\n days?: readonly Weekday[];\n between: readonly [TimeOfDay, TimeOfDay];\n tz?: 'user' | (string & {});\n }): this {\n const loc = captureLoc(this.timeWindow);\n if (opts.days !== undefined) {\n // An empty list is a window that never opens: the node would hold the user forever\n if (opts.days.length === 0) {\n throw new Error(\"timeWindow(): 'days' must name at least one day\");\n }\n const seen = new Set<Weekday>();\n for (const day of opts.days) {\n if (seen.has(day)) throw new Error(`timeWindow(): 'days' lists '${day}' twice`);\n seen.add(day);\n }\n }\n const start = timeOfDayMinutes(opts.between[0]);\n const end = timeOfDayMinutes(opts.between[1]);\n if (end <= start) {\n throw new Error(\n `timeWindow(): 'between' must open before it closes within one day, got [${opts.between[0]}, ${opts.between[1]}] (overnight windows are not supported yet)`\n );\n }\n return this.pushNode(\n {\n id: '',\n type: 'time_window',\n days: [...(opts.days ?? (['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] as const))],\n between: [opts.between[0], opts.between[1]],\n tz: opts.tz ?? 'user',\n },\n loc\n );\n }\n\n waitUntil(\n condition: Condition,\n opts: { timeout: Duration; onTimeout?: 'continue' | 'exit' | SubFlow }\n ): this {\n const loc = captureLoc(this.waitUntil);\n const onTimeout = opts.onTimeout ?? 'continue';\n return this.pushNode(\n {\n id: '',\n type: 'wait_until',\n condition: condIR(condition),\n timeout: positiveDurationIR(opts.timeout, 'waitUntil(): timeout'),\n onTimeout:\n onTimeout === 'continue' || onTimeout === 'exit'\n ? onTimeout\n : resolveSubFlow(onTimeout, this.uses, this.actions),\n },\n loc\n );\n }\n\n use(fragment: SubFlow): this {\n // The fragment's nodes carry their own provenance (where the fragment was written)\n this.nodes.push(...resolveSubFlow(fragment, this.uses, this.actions));\n return this;\n }\n\n branch(...arms: readonly BranchArm[]): this;\n branch(label: string, ...arms: readonly BranchArm[]): this;\n branch(...args: readonly (string | BranchArm)[]): this {\n const loc = captureLoc(this.branch);\n const label = typeof args[0] === 'string' ? args[0] : undefined;\n const arms = (label === undefined ? args : args.slice(1)) as readonly BranchArm[];\n\n const cases: { condition: ConditionIR; flow: NodeIR[] }[] = [];\n let otherwise: NodeIR[] | undefined;\n arms.forEach((arm, i) => {\n if (Array.isArray(arm)) {\n if (otherwise !== undefined) {\n throw new Error('branch(): default arm (bare sub-flow) must be the last argument');\n }\n const [condition, sub] = arm as BranchCase;\n cases.push({\n condition: condIR(condition),\n flow: resolveSubFlow(sub, this.uses, this.actions),\n });\n } else {\n if (otherwise !== undefined) {\n throw new Error('branch(): only one default arm (bare sub-flow) is allowed');\n }\n if (i !== arms.length - 1) {\n throw new Error('branch(): default arm (bare sub-flow) must be the last argument');\n }\n otherwise = resolveSubFlow(arm as SubFlow, this.uses, this.actions);\n }\n });\n\n return this.pushNode(\n {\n id: '',\n type: 'branch',\n ...(label !== undefined ? { label } : {}),\n cases,\n ...(otherwise !== undefined ? { otherwise } : {}),\n },\n loc\n );\n }\n\n filter(condition: Condition, opts?: { reason?: string }): this {\n return this.pushNode(\n {\n id: '',\n type: 'filter',\n condition: condIR(condition),\n ...(opts?.reason !== undefined ? { reason: opts.reason } : {}),\n },\n captureLoc(this.filter)\n );\n }\n\n cohort(arms: Record<string, { weight: number; flow?: SubFlow }>, opts?: { key?: string }): this {\n const loc = captureLoc(this.cohort);\n const entries = Object.entries(arms);\n /*\n * Weights live on a 0.01% grid: the runtime buckets into 10,000 slots\n * (basis points), so anything finer would be silently quantized — reject\n * it here instead. Converting to integer basis points also makes the\n * sum check exact; no epsilon needed.\n */\n const basisPoints = entries.map(([name, a]) => {\n if (!ARM_NAME.test(name)) {\n throw new Error(\n `cohort(): arm name '${name}' must start with a letter or '_' and contain only letters, digits, '_' or '-' — arm names become node id segments, and integer-like names would silently reorder the arms`\n );\n }\n const bp = a.weight * 100;\n if (Math.abs(bp - Math.round(bp)) > 1e-6) {\n throw new Error(\n `cohort(): arm '${name}' weight ${a.weight} is finer than the 0.01% bucketing grid — use at most two decimal places`\n );\n }\n /*\n * The sum check alone accepts -50 / 150: the runtime walks the arms\n * accumulating basis points and takes the first whose cumulative total\n * clears the bucket, so a negative weight hands 100% of users to its\n * neighbour instead of splitting anything.\n */\n if (bp < 0) {\n throw new Error(`cohort(): arm '${name}' weight ${a.weight} must not be negative`);\n }\n return Math.round(bp);\n });\n const total = basisPoints.reduce((sum, bp) => sum + bp, 0);\n if (total !== 10_000) {\n throw new Error(`cohort(): weights must sum to 100, got ${total / 100}`);\n }\n return this.pushNode(\n {\n id: '',\n type: 'cohort',\n ...(opts?.key !== undefined ? { key: opts.key } : {}),\n arms: entries.map(([name, a]) => ({\n name,\n weight: a.weight,\n flow: a.flow ? resolveSubFlow(a.flow, this.uses, this.actions) : [],\n })),\n },\n loc\n );\n }\n\n exit(reason?: string): this {\n return this.pushNode(\n { id: '', type: 'exit', ...(reason !== undefined ? { reason } : {}) },\n captureLoc(this.exit)\n );\n }\n\n sendEvent<P extends object>(ev: EventRef<P>, ...payload: EmitArgs<P>): this {\n const values = (payload[0] ?? {}) as Record<string, unknown>;\n for (const [field, value] of Object.entries(values)) {\n const ref =\n typeof value === 'object' &&\n value !== null &&\n (value as { type?: unknown }).type === 'user_property';\n if (!ref && !['string', 'number', 'boolean'].includes(typeof value)) {\n throw new TypeError(\n `sendEvent('${ev.name}'): '${field}' is not a scalar or a u.xxx reference — an emitted payload carries scalar fields only`\n );\n }\n }\n return this.pushNode(\n {\n id: '',\n type: 'send_event',\n event: ev.name,\n payload: values as Record<string, PropValueIR>,\n },\n captureLoc(this.sendEvent)\n );\n }\n\n run<A extends object>(a: ActionRef<A>, ...args: MessageArgs<A>): this {\n this.actions.push(a);\n return this.pushNode(\n {\n id: '',\n type: 'action',\n action: a.name,\n args: (args[0] ?? {}) as Record<string, PropValueIR>,\n },\n captureLoc(this.run)\n );\n }\n}\n/* oxlint-enable typescript/unbound-method */\n\n/**\n * A reusable flow fragment: a free function. Once personalization goes through\n * u.xxx and events through e.xxx, the flow layer carries no schema generics.\n */\nexport function flow(build: (w: FlowBuilder) => FlowBuilder): Flow {\n const builder = new FlowBuilderImpl();\n build(builder);\n const impl: FlowInternal = {\n __flow: true,\n nodes: builder.nodes,\n uses: builder.uses,\n actions: builder.actions,\n };\n return impl;\n}\n"],"mappings":";;;;;;;AA0EA,SAAS,gBAAgB,YAAqB,OAAgB,SAAwB;CACpF,IAAI,CAAC,MAAM,QAAQ,UAAU,KAAK,WAAW,WAAW,GACtD,MAAM,IAAI,UAAU,0EAA0E;CAEhG,MAAM,WAAY,WAAyB,KAAK,cAC9CA,kBAAAA,WAAW,SAAS,IAAIC,kBAAAA,WAAW,UAAU,QAAQ,KAAA,CACvD;CACA,IAAI,CAAC,SAAS,OAAO,YAAY,YAAY,UAAU,YAAY,OAAO,GACxE,MAAM,IAAI,UAAU,qEAAqE;CAE3F,IAAI,SAAS,OAAO,SAAS,IAC3B,MAAM,IAAI,UAAU,8DAA8D;CAEpF,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GACpE,MAAM,IAAI,UACR,6EACF;CAEF,IAAI,YAAY,KAAA,GAAW;CAC3B,IAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,MAAM,QAAQ,OAAO,GAC1E,MAAM,IAAI,UAAU,qCAAqC;CAE3D,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,OAAO,GAAG;EACnD,IAAI,SAAS,SACX,MAAM,IAAI,UACR,6BAA6B,KAAK,+DACpC;EAEF,IAAI,OAAO,UAAU,UAAU,MAAM,I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EAHF,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS,oBAC7B,CAAC;GAAC;GAAU;GAAU;EAAS,CAAC,CAAC,SAAS,OAAO,KAAK,GAChE,MAAM,IAAI,UACR,cAAc,GAAG,KAAK,OAAO,MAAM,uFACrC;EAGJ,OAAO,KAAK,SACV;GACE,IAAI;GACJ,MAAM;GACN,OAAO,GAAG;GACV,SAAS;EACX,GACAA,mBAAAA,WAAW,KAAK,SAAS,CAC3B;CACF;CAEA,IAAsB,GAAiB,GAAG,MAA4B;EACpE,KAAK,QAAQ,KAAK,CAAC;EACnB,OAAO,KAAK,SACV;GACE,IAAI;GACJ,MAAM;GACN,QAAQ,EAAE;GACV,MAAO,KAAK,MAAM,CAAC;EACrB,GACAA,mBAAAA,WAAW,KAAK,GAAG,CACrB;CACF;AACF;;;;;AAOA,SAAgB,KAAK,OAA8C;CACjE,MAAM,UAAU,IAAI,gBAAgB;CACpC,MAAM,OAAO;CAOb,OAAO;EALL,QAAQ;EACR,OAAO,QAAQ;EACf,MAAM,QAAQ;EACd,SAAS,QAAQ;CAET;AACZ"}
@@ -1,11 +1,10 @@
1
1
  import { NodeIR, SourceLocIR } from "../ir.cjs";
2
- import { AnyTemplate, DiscordTemplate, EmailTemplate, PropsSchema, PushTemplate, SlackTemplate } from "../templates.cjs";
3
2
  import { ActionRef } from "./action.cjs";
4
3
  import { Duration, TimeOfDay, Weekday } from "./base.cjs";
5
4
  import { EventRef, MessageArgs, PropInput, PropsInput } from "./refs.cjs";
6
5
  import { PropsOf, TemplateRef } from "./template.cjs";
7
6
  import { Condition } from "./condition.cjs";
8
- //#region src/dsl/flow.d.ts
7
+ import { AnyTemplate, DiscordTemplate, EmailTemplate, PropsSchema, PushTemplate, SlackTemplate } from "../templates.cjs";
9
8
  /**
10
9
  * The flow chain — FlowBuilder is the DSL's step surface (messages, delays,
11
10
  * flow control, data), and its implementation is the compiler front half: each
@@ -274,6 +273,5 @@ export declare class FlowBuilderImpl implements FlowBuilder {
274
273
  * u.xxx and events through e.xxx, the flow layer carries no schema generics.
275
274
  */
276
275
  export declare function flow(build: (w: FlowBuilder) => FlowBuilder): Flow;
277
- //#endregion
278
276
  export {};
279
277
  //# sourceMappingURL=flow.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flow.d.cts","names":[],"sources":["../../src/dsl/flow.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;KA+BK;;KAGA,UAAU,MAAM,YAAY,aAAa,UAAU,UAAU;;YAGtD,YAAY,QAAQ,WAAW,IAAI,UAAU,EAAE;;YAG/C,SAAS,KACnB,8BAA8B,KAAK,UAAU,YAAY,OAAO,SAAS,YAAY;;iBAGtE;;EAEf;;;iBAIe;;EAEf;;;KAIG,uBAAuB,cAAc,2BAA2B,eAAe;KAE/E,eAAe,kBAAkB,WAAW,IAAI,EAAE;KAClD,MAAM,GAAG,OACV,QAAQ,UAAU,qBAAoB,SAAQ,UAAU;;KAGvD,UAAU,UAAU,cACvB,MAAM,eAAe,QAAQ,QAAQ,eAAe,QAAQ;WAE7C;;;KAGZ,YAAY,KAAK,0BAA0B;;KAE3C,QAAQ,GAAG,KAAK,OAAO,QAAQ,YAAY,UAAU;;iBAoCzC;WACN;;;;;;;iBAcM;WACN,UAAU;WACV,KAAK;;;wBAIA,aAAa,SAAS,uBAAuB;;;;;;wBAS7C,WAAW,SAAS,uBAAuB;;YAK/C,UAAU,SAAS,GAAG,gBAAgB;;YAGtC,uBAAuB,WAAW,WAAW,MAAM;;;;;YAMnD,YAAY,aAAa;iBA2CpB;EAEf,MAAM,UAAU,eAAe,UAAU,MAAM,OAAO,YAAY,QAAQ;EAC1E,IAAI,kBAAkB,UAAU,mBAAmB,OAAO,OAAO,YAAY;;;;;;EAM7E,KAAK,UAAU,cACb,UAAU,MACP,UAAU,OAAO,YAAY,QAAQ,KAAK,UAAU;EAEzD,MAAM,kBAAkB,UAAU,sBAAsB,OAAO,OAAO,YAAY;EAClF,MAAM,UAAU,cAAc,qBAC5B,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G,UAAU,OAAO,MAAM,YAAY;;;;;;wBAmB9C,KAAK,QAAQ,GAAG,gBAAgB,cAAc"}
@@ -1,11 +1,10 @@
1
1
  import { NodeIR, SourceLocIR } from "../ir.mjs";
2
- import { AnyTemplate, DiscordTemplate, EmailTemplate, PropsSchema, PushTemplate, SlackTemplate } from "../templates.mjs";
3
2
  import { ActionRef } from "./action.mjs";
4
3
  import { Duration, TimeOfDay, Weekday } from "./base.mjs";
5
4
  import { EventRef, MessageArgs, PropInput, PropsInput } from "./refs.mjs";
6
5
  import { PropsOf, TemplateRef } from "./template.mjs";
7
6
  import { Condition } from "./condition.mjs";
8
- //#region src/dsl/flow.d.ts
7
+ import { AnyTemplate, DiscordTemplate, EmailTemplate, PropsSchema, PushTemplate, SlackTemplate } from "../templates.mjs";
9
8
  /**
10
9
  * The flow chain — FlowBuilder is the DSL's step surface (messages, delays,
11
10
  * flow control, data), and its implementation is the compiler front half: each
@@ -274,6 +273,5 @@ export declare class FlowBuilderImpl implements FlowBuilder {
274
273
  * u.xxx and events through e.xxx, the flow layer carries no schema generics.
275
274
  */
276
275
  export declare function flow(build: (w: FlowBuilder) => FlowBuilder): Flow;
277
- //#endregion
278
276
  export {};
279
277
  //# sourceMappingURL=flow.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flow.d.mts","names":[],"sources":["../../src/dsl/flow.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;KA+BK;;KAGA,UAAU,MAAM,YAAY,aAAa,UAAU,UAAU;;YAGtD,YAAY,QAAQ,WAAW,IAAI,UAAU,EAAE;;YAG/C,SAAS,KACnB,8BAA8B,KAAK,UAAU,YAAY,OAAO,SAAS,YAAY;;iBAGtE;;EAEf;;;iBAIe;;EAEf;;;KAIG,uBAAuB,cAAc,2BAA2B,eAAe;KAE/E,eAAe,kBAAkB,WAAW,IAAI,EAAE;KAClD,MAAM,GAAG,OACV,QAAQ,UAAU,qBAAoB,SAAQ,UAAU;;KAGvD,UAAU,UAAU,cACvB,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AM,YAAY,QAAQ;EAI/B,OAAO,kBAAkB,GAAG,sBAAsB,OAAO,MAAM,YAAY;EAI3E,aAAa,UAAU,kBAAkB,UAAU,WAAW,QAAQ,QAAQ,SAC5E,YAAY,IAAI,UAAU,QAAQ,KAClC,OAAO,IAAI,QAAQ,QAAQ,GAAG,QAAQ,SACtC,UAAU;EA4BZ,MAAM,UAAU;EAChB,MAAM;IAAS,KAAK;IAAU,KAAK;;EAqBnC,WAAW;IACT,gBAAgB;IAChB,mBAAmB,WAAW;IAC9B;;EAiCF,UACE,WAAW,WACX;IAAQ,SAAS;IAAU,kCAAkC;;EAmB/D,IAAI,UAAU;EAMd,UAAU,eAAe;EACzB,OAAO,kBAAkB,eAAe;EAyCxC,OAAO,WAAW,WAAW;IAAS;;EAYtC,OAAO,MAAM;IAAiB;IAAgB,OAAO;MAAY;IAAS;;EAmD1E,KAAK;EAOL,UAAU,kBAAkB,IAAI,SAAS,OAAO,SAAS,SAAS;EAwBlE,IAAI,kBAAkB,GAAG,UAAU,OAAO,MAAM,YAAY;;;;;;wBAmB9C,KAAK,QAAQ,GAAG,gBAAgB,cAAc"}
package/dist/dsl/flow.mjs CHANGED
@@ -2,7 +2,7 @@ import { captureLoc } from "../provenance.mjs";
2
2
  import { durationIR, timeOfDayMinutes } from "./base.mjs";
3
3
  import { condIR, positiveDurationIR } from "./condition.mjs";
4
4
  import { CHANNEL_OF, isTemplate } from "../templates.mjs";
5
- //#region src/dsl/flow.ts
5
+ // src/dsl/flow.ts
6
6
  /** prefer() is typed strictly, but a JS caller (or an `any`) reaches it unchecked — fail at the call, not at send time. */
7
7
  function checkPreferArgs(candidates, props, options) {
8
8
  if (!Array.isArray(candidates) || candidates.length !== 2) throw new TypeError("prefer(): candidates must be exactly two templates — one push, one email");
@@ -67,7 +67,8 @@ function messageNode(channel, tpl, props, devices) {
67
67
  channel,
68
68
  template: templateKey(channel, tpl),
69
69
  props: props ?? {},
70
- ...devices !== void 0 ? { devices } : {}
70
+ ...devices !== void 0 ? { devices } : {},
71
+ ...channel === "email" || channel === "push" ? { topic: tpl.topic ?? null } : {}
71
72
  };
72
73
  }
73
74
  /** @internal extended by WorkflowBuilderImpl; not part of the public API */
@@ -312,7 +313,6 @@ function flow(build) {
312
313
  actions: builder.actions
313
314
  };
314
315
  }
315
- //#endregion
316
316
  export { FlowBuilderImpl, actionUses, flow, templateUses };
317
317
 
318
318
  //# sourceMappingURL=flow.mjs.map