@shware/workflow 0.0.0-stage → 0.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 (442) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +154 -2
  3. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  4. package/dist/apns-relay.cjs +105 -0
  5. package/dist/apns-relay.cjs.map +1 -0
  6. package/dist/apns-relay.d.cts +28 -0
  7. package/dist/apns-relay.d.cts.map +1 -0
  8. package/dist/apns-relay.d.mts +28 -0
  9. package/dist/apns-relay.d.mts.map +1 -0
  10. package/dist/apns-relay.mjs +104 -0
  11. package/dist/apns-relay.mjs.map +1 -0
  12. package/dist/apns.cjs +121 -0
  13. package/dist/apns.cjs.map +1 -0
  14. package/dist/apns.d.cts +63 -0
  15. package/dist/apns.d.cts.map +1 -0
  16. package/dist/apns.d.mts +63 -0
  17. package/dist/apns.d.mts.map +1 -0
  18. package/dist/apns.mjs +116 -0
  19. package/dist/apns.mjs.map +1 -0
  20. package/dist/client.cjs +125 -0
  21. package/dist/client.cjs.map +1 -0
  22. package/dist/client.d.cts +108 -0
  23. package/dist/client.d.cts.map +1 -0
  24. package/dist/client.d.mts +108 -0
  25. package/dist/client.d.mts.map +1 -0
  26. package/dist/client.mjs +122 -0
  27. package/dist/client.mjs.map +1 -0
  28. package/dist/cloudflare/bindings.cjs +28 -0
  29. package/dist/cloudflare/bindings.cjs.map +1 -0
  30. package/dist/cloudflare/bindings.d.cts +144 -0
  31. package/dist/cloudflare/bindings.d.cts.map +1 -0
  32. package/dist/cloudflare/bindings.d.mts +144 -0
  33. package/dist/cloudflare/bindings.d.mts.map +1 -0
  34. package/dist/cloudflare/bindings.mjs +25 -0
  35. package/dist/cloudflare/bindings.mjs.map +1 -0
  36. package/dist/cloudflare/channels.cjs +164 -0
  37. package/dist/cloudflare/channels.cjs.map +1 -0
  38. package/dist/cloudflare/channels.d.cts +29 -0
  39. package/dist/cloudflare/channels.d.cts.map +1 -0
  40. package/dist/cloudflare/channels.d.mts +29 -0
  41. package/dist/cloudflare/channels.d.mts.map +1 -0
  42. package/dist/cloudflare/channels.mjs +161 -0
  43. package/dist/cloudflare/channels.mjs.map +1 -0
  44. package/dist/cloudflare/d1-env.cjs +17 -0
  45. package/dist/cloudflare/d1-env.cjs.map +1 -0
  46. package/dist/cloudflare/d1-env.d.cts +12 -0
  47. package/dist/cloudflare/d1-env.d.cts.map +1 -0
  48. package/dist/cloudflare/d1-env.d.mts +12 -0
  49. package/dist/cloudflare/d1-env.d.mts.map +1 -0
  50. package/dist/cloudflare/d1-env.mjs +16 -0
  51. package/dist/cloudflare/d1-env.mjs.map +1 -0
  52. package/dist/cloudflare/index.cjs +54 -0
  53. package/dist/cloudflare/index.d.cts +19 -0
  54. package/dist/cloudflare/index.d.mts +19 -0
  55. package/dist/cloudflare/index.mjs +16 -0
  56. package/dist/cloudflare/router.cjs +516 -0
  57. package/dist/cloudflare/router.cjs.map +1 -0
  58. package/dist/cloudflare/router.d.cts +157 -0
  59. package/dist/cloudflare/router.d.cts.map +1 -0
  60. package/dist/cloudflare/router.d.mts +157 -0
  61. package/dist/cloudflare/router.d.mts.map +1 -0
  62. package/dist/cloudflare/router.mjs +503 -0
  63. package/dist/cloudflare/router.mjs.map +1 -0
  64. package/dist/cloudflare/runner.cjs +225 -0
  65. package/dist/cloudflare/runner.cjs.map +1 -0
  66. package/dist/cloudflare/runner.d.cts +73 -0
  67. package/dist/cloudflare/runner.d.cts.map +1 -0
  68. package/dist/cloudflare/runner.d.mts +73 -0
  69. package/dist/cloudflare/runner.d.mts.map +1 -0
  70. package/dist/cloudflare/runner.mjs +224 -0
  71. package/dist/cloudflare/runner.mjs.map +1 -0
  72. package/dist/cloudflare/schema.sql +127 -0
  73. package/dist/cloudflare/senders.cjs +114 -0
  74. package/dist/cloudflare/senders.cjs.map +1 -0
  75. package/dist/cloudflare/senders.d.cts +68 -0
  76. package/dist/cloudflare/senders.d.cts.map +1 -0
  77. package/dist/cloudflare/senders.d.mts +68 -0
  78. package/dist/cloudflare/senders.d.mts.map +1 -0
  79. package/dist/cloudflare/senders.mjs +108 -0
  80. package/dist/cloudflare/senders.mjs.map +1 -0
  81. package/dist/cloudflare/worker.cjs +228 -0
  82. package/dist/cloudflare/worker.cjs.map +1 -0
  83. package/dist/cloudflare/worker.d.cts +92 -0
  84. package/dist/cloudflare/worker.d.cts.map +1 -0
  85. package/dist/cloudflare/worker.d.mts +92 -0
  86. package/dist/cloudflare/worker.d.mts.map +1 -0
  87. package/dist/cloudflare/worker.mjs +224 -0
  88. package/dist/cloudflare/worker.mjs.map +1 -0
  89. package/dist/cloudflare/workers.d.cjs +0 -0
  90. package/dist/cloudflare/workers.d.cts +44 -0
  91. package/dist/cloudflare/workers.d.cts.map +1 -0
  92. package/dist/cloudflare/workers.d.mts +44 -0
  93. package/dist/cloudflare/workers.d.mts.map +1 -0
  94. package/dist/config.cjs +151 -0
  95. package/dist/config.cjs.map +1 -0
  96. package/dist/config.d.cts +149 -0
  97. package/dist/config.d.cts.map +1 -0
  98. package/dist/config.d.mts +149 -0
  99. package/dist/config.d.mts.map +1 -0
  100. package/dist/config.mjs +143 -0
  101. package/dist/config.mjs.map +1 -0
  102. package/dist/contract.cjs +212 -0
  103. package/dist/contract.cjs.map +1 -0
  104. package/dist/contract.d.cts +90 -0
  105. package/dist/contract.d.cts.map +1 -0
  106. package/dist/contract.d.mts +90 -0
  107. package/dist/contract.d.mts.map +1 -0
  108. package/dist/contract.mjs +206 -0
  109. package/dist/contract.mjs.map +1 -0
  110. package/dist/dsl/action.cjs +29 -0
  111. package/dist/dsl/action.cjs.map +1 -0
  112. package/dist/dsl/action.d.cts +64 -0
  113. package/dist/dsl/action.d.cts.map +1 -0
  114. package/dist/dsl/action.d.mts +64 -0
  115. package/dist/dsl/action.d.mts.map +1 -0
  116. package/dist/dsl/action.mjs +28 -0
  117. package/dist/dsl/action.mjs.map +1 -0
  118. package/dist/dsl/base.cjs +34 -0
  119. package/dist/dsl/base.cjs.map +1 -0
  120. package/dist/dsl/base.d.cts +45 -0
  121. package/dist/dsl/base.d.cts.map +1 -0
  122. package/dist/dsl/base.d.mts +45 -0
  123. package/dist/dsl/base.d.mts.map +1 -0
  124. package/dist/dsl/base.mjs +30 -0
  125. package/dist/dsl/base.mjs.map +1 -0
  126. package/dist/dsl/bundle.cjs +207 -0
  127. package/dist/dsl/bundle.cjs.map +1 -0
  128. package/dist/dsl/bundle.d.cts +19 -0
  129. package/dist/dsl/bundle.d.cts.map +1 -0
  130. package/dist/dsl/bundle.d.mts +19 -0
  131. package/dist/dsl/bundle.d.mts.map +1 -0
  132. package/dist/dsl/bundle.mjs +206 -0
  133. package/dist/dsl/bundle.mjs.map +1 -0
  134. package/dist/dsl/condition.cjs +177 -0
  135. package/dist/dsl/condition.cjs.map +1 -0
  136. package/dist/dsl/condition.d.cts +140 -0
  137. package/dist/dsl/condition.d.cts.map +1 -0
  138. package/dist/dsl/condition.d.mts +140 -0
  139. package/dist/dsl/condition.d.mts.map +1 -0
  140. package/dist/dsl/condition.mjs +156 -0
  141. package/dist/dsl/condition.mjs.map +1 -0
  142. package/dist/dsl/flow.cjs +228 -0
  143. package/dist/dsl/flow.cjs.map +1 -0
  144. package/dist/dsl/flow.d.cts +223 -0
  145. package/dist/dsl/flow.d.cts.map +1 -0
  146. package/dist/dsl/flow.d.mts +223 -0
  147. package/dist/dsl/flow.d.mts.map +1 -0
  148. package/dist/dsl/flow.mjs +226 -0
  149. package/dist/dsl/flow.mjs.map +1 -0
  150. package/dist/dsl/index.cjs +38 -0
  151. package/dist/dsl/index.d.cts +10 -0
  152. package/dist/dsl/index.d.mts +10 -0
  153. package/dist/dsl/index.mjs +9 -0
  154. package/dist/dsl/refs.cjs +59 -0
  155. package/dist/dsl/refs.cjs.map +1 -0
  156. package/dist/dsl/refs.d.cts +88 -0
  157. package/dist/dsl/refs.d.cts.map +1 -0
  158. package/dist/dsl/refs.d.mts +88 -0
  159. package/dist/dsl/refs.d.mts.map +1 -0
  160. package/dist/dsl/refs.mjs +55 -0
  161. package/dist/dsl/refs.mjs.map +1 -0
  162. package/dist/dsl/template.cjs +65 -0
  163. package/dist/dsl/template.cjs.map +1 -0
  164. package/dist/dsl/template.d.cts +75 -0
  165. package/dist/dsl/template.d.cts.map +1 -0
  166. package/dist/dsl/template.d.mts +75 -0
  167. package/dist/dsl/template.d.mts.map +1 -0
  168. package/dist/dsl/template.mjs +63 -0
  169. package/dist/dsl/template.mjs.map +1 -0
  170. package/dist/dsl/trigger.cjs +40 -0
  171. package/dist/dsl/trigger.cjs.map +1 -0
  172. package/dist/dsl/trigger.d.cts +65 -0
  173. package/dist/dsl/trigger.d.cts.map +1 -0
  174. package/dist/dsl/trigger.d.mts +65 -0
  175. package/dist/dsl/trigger.d.mts.map +1 -0
  176. package/dist/dsl/trigger.mjs +39 -0
  177. package/dist/dsl/trigger.mjs.map +1 -0
  178. package/dist/dsl/workflow.cjs +121 -0
  179. package/dist/dsl/workflow.cjs.map +1 -0
  180. package/dist/dsl/workflow.d.cts +59 -0
  181. package/dist/dsl/workflow.d.cts.map +1 -0
  182. package/dist/dsl/workflow.d.mts +59 -0
  183. package/dist/dsl/workflow.d.mts.map +1 -0
  184. package/dist/dsl/workflow.mjs +120 -0
  185. package/dist/dsl/workflow.mjs.map +1 -0
  186. package/dist/engine/actions.cjs +27 -0
  187. package/dist/engine/actions.cjs.map +1 -0
  188. package/dist/engine/actions.d.cts +40 -0
  189. package/dist/engine/actions.d.cts.map +1 -0
  190. package/dist/engine/actions.d.mts +40 -0
  191. package/dist/engine/actions.d.mts.map +1 -0
  192. package/dist/engine/actions.mjs +26 -0
  193. package/dist/engine/actions.mjs.map +1 -0
  194. package/dist/engine/bucket.cjs +72 -0
  195. package/dist/engine/bucket.cjs.map +1 -0
  196. package/dist/engine/bucket.d.cts +32 -0
  197. package/dist/engine/bucket.d.cts.map +1 -0
  198. package/dist/engine/bucket.d.mts +32 -0
  199. package/dist/engine/bucket.d.mts.map +1 -0
  200. package/dist/engine/bucket.mjs +69 -0
  201. package/dist/engine/bucket.mjs.map +1 -0
  202. package/dist/engine/condition.cjs +166 -0
  203. package/dist/engine/condition.cjs.map +1 -0
  204. package/dist/engine/condition.d.cts +52 -0
  205. package/dist/engine/condition.d.cts.map +1 -0
  206. package/dist/engine/condition.d.mts +52 -0
  207. package/dist/engine/condition.d.mts.map +1 -0
  208. package/dist/engine/condition.mjs +161 -0
  209. package/dist/engine/condition.mjs.map +1 -0
  210. package/dist/engine/index.cjs +20 -0
  211. package/dist/engine/index.d.cts +8 -0
  212. package/dist/engine/index.d.mts +8 -0
  213. package/dist/engine/index.mjs +7 -0
  214. package/dist/engine/interpreter.cjs +428 -0
  215. package/dist/engine/interpreter.cjs.map +1 -0
  216. package/dist/engine/interpreter.d.cts +6 -0
  217. package/dist/engine/interpreter.d.cts.map +1 -0
  218. package/dist/engine/interpreter.d.mts +6 -0
  219. package/dist/engine/interpreter.d.mts.map +1 -0
  220. package/dist/engine/interpreter.mjs +427 -0
  221. package/dist/engine/interpreter.mjs.map +1 -0
  222. package/dist/engine/ports.cjs +0 -0
  223. package/dist/engine/ports.d.cts +252 -0
  224. package/dist/engine/ports.d.cts.map +1 -0
  225. package/dist/engine/ports.d.mts +252 -0
  226. package/dist/engine/ports.d.mts.map +1 -0
  227. package/dist/engine/ports.mjs +1 -0
  228. package/dist/engine/recipient.cjs +23 -0
  229. package/dist/engine/recipient.cjs.map +1 -0
  230. package/dist/engine/recipient.d.cts +13 -0
  231. package/dist/engine/recipient.d.cts.map +1 -0
  232. package/dist/engine/recipient.d.mts +13 -0
  233. package/dist/engine/recipient.d.mts.map +1 -0
  234. package/dist/engine/recipient.mjs +22 -0
  235. package/dist/engine/recipient.mjs.map +1 -0
  236. package/dist/engine/time-scale.cjs +54 -0
  237. package/dist/engine/time-scale.cjs.map +1 -0
  238. package/dist/engine/time-scale.d.cts +31 -0
  239. package/dist/engine/time-scale.d.cts.map +1 -0
  240. package/dist/engine/time-scale.d.mts +31 -0
  241. package/dist/engine/time-scale.d.mts.map +1 -0
  242. package/dist/engine/time-scale.mjs +52 -0
  243. package/dist/engine/time-scale.mjs.map +1 -0
  244. package/dist/engine/time-window.cjs +149 -0
  245. package/dist/engine/time-window.cjs.map +1 -0
  246. package/dist/engine/time-window.d.cts +22 -0
  247. package/dist/engine/time-window.d.cts.map +1 -0
  248. package/dist/engine/time-window.d.mts +22 -0
  249. package/dist/engine/time-window.d.mts.map +1 -0
  250. package/dist/engine/time-window.mjs +147 -0
  251. package/dist/engine/time-window.mjs.map +1 -0
  252. package/dist/fcm.cjs +125 -0
  253. package/dist/fcm.cjs.map +1 -0
  254. package/dist/fcm.d.cts +48 -0
  255. package/dist/fcm.d.cts.map +1 -0
  256. package/dist/fcm.d.mts +48 -0
  257. package/dist/fcm.d.mts.map +1 -0
  258. package/dist/fcm.mjs +121 -0
  259. package/dist/fcm.mjs.map +1 -0
  260. package/dist/hash.cjs +245 -0
  261. package/dist/hash.cjs.map +1 -0
  262. package/dist/hash.d.cts +30 -0
  263. package/dist/hash.d.cts.map +1 -0
  264. package/dist/hash.d.mts +30 -0
  265. package/dist/hash.d.mts.map +1 -0
  266. package/dist/hash.mjs +239 -0
  267. package/dist/hash.mjs.map +1 -0
  268. package/dist/index.cjs +100 -0
  269. package/dist/index.d.cts +18 -0
  270. package/dist/index.d.mts +18 -0
  271. package/dist/index.mjs +17 -0
  272. package/dist/ir.cjs +366 -0
  273. package/dist/ir.cjs.map +1 -0
  274. package/dist/ir.d.cts +486 -0
  275. package/dist/ir.d.cts.map +1 -0
  276. package/dist/ir.d.mts +486 -0
  277. package/dist/ir.d.mts.map +1 -0
  278. package/dist/ir.mjs +344 -0
  279. package/dist/ir.mjs.map +1 -0
  280. package/dist/jwt.cjs +22 -0
  281. package/dist/jwt.cjs.map +1 -0
  282. package/dist/jwt.d.cts +9 -0
  283. package/dist/jwt.d.cts.map +1 -0
  284. package/dist/jwt.d.mts +9 -0
  285. package/dist/jwt.d.mts.map +1 -0
  286. package/dist/jwt.mjs +20 -0
  287. package/dist/jwt.mjs.map +1 -0
  288. package/dist/plan.cjs +223 -0
  289. package/dist/plan.cjs.map +1 -0
  290. package/dist/plan.d.cts +68 -0
  291. package/dist/plan.d.cts.map +1 -0
  292. package/dist/plan.d.mts +68 -0
  293. package/dist/plan.d.mts.map +1 -0
  294. package/dist/plan.mjs +221 -0
  295. package/dist/plan.mjs.map +1 -0
  296. package/dist/postgres-js.cjs +42 -0
  297. package/dist/postgres-js.cjs.map +1 -0
  298. package/dist/postgres-js.d.cts +28 -0
  299. package/dist/postgres-js.d.cts.map +1 -0
  300. package/dist/postgres-js.d.mts +28 -0
  301. package/dist/postgres-js.d.mts.map +1 -0
  302. package/dist/postgres-js.mjs +38 -0
  303. package/dist/postgres-js.mjs.map +1 -0
  304. package/dist/provenance.cjs +67 -0
  305. package/dist/provenance.cjs.map +1 -0
  306. package/dist/provenance.d.cts +41 -0
  307. package/dist/provenance.d.cts.map +1 -0
  308. package/dist/provenance.d.mts +41 -0
  309. package/dist/provenance.d.mts.map +1 -0
  310. package/dist/provenance.mjs +65 -0
  311. package/dist/provenance.mjs.map +1 -0
  312. package/dist/push.cjs +14 -0
  313. package/dist/push.cjs.map +1 -0
  314. package/dist/push.d.cts +16 -0
  315. package/dist/push.d.cts.map +1 -0
  316. package/dist/push.d.mts +16 -0
  317. package/dist/push.d.mts.map +1 -0
  318. package/dist/push.mjs +13 -0
  319. package/dist/push.mjs.map +1 -0
  320. package/dist/react-email.cjs +48 -0
  321. package/dist/react-email.cjs.map +1 -0
  322. package/dist/react-email.d.cts +7 -0
  323. package/dist/react-email.d.cts.map +1 -0
  324. package/dist/react-email.d.mts +7 -0
  325. package/dist/react-email.d.mts.map +1 -0
  326. package/dist/react-email.mjs +47 -0
  327. package/dist/react-email.mjs.map +1 -0
  328. package/dist/reporting/classify.cjs +42 -0
  329. package/dist/reporting/classify.cjs.map +1 -0
  330. package/dist/reporting/classify.d.cts +60 -0
  331. package/dist/reporting/classify.d.cts.map +1 -0
  332. package/dist/reporting/classify.d.mts +60 -0
  333. package/dist/reporting/classify.d.mts.map +1 -0
  334. package/dist/reporting/classify.mjs +38 -0
  335. package/dist/reporting/classify.mjs.map +1 -0
  336. package/dist/reporting/observer.cjs +63 -0
  337. package/dist/reporting/observer.cjs.map +1 -0
  338. package/dist/reporting/observer.d.cts +18 -0
  339. package/dist/reporting/observer.d.cts.map +1 -0
  340. package/dist/reporting/observer.d.mts +18 -0
  341. package/dist/reporting/observer.d.mts.map +1 -0
  342. package/dist/reporting/observer.mjs +62 -0
  343. package/dist/reporting/observer.mjs.map +1 -0
  344. package/dist/reporting/tracking.cjs +153 -0
  345. package/dist/reporting/tracking.cjs.map +1 -0
  346. package/dist/reporting/tracking.d.cts +43 -0
  347. package/dist/reporting/tracking.d.cts.map +1 -0
  348. package/dist/reporting/tracking.d.mts +43 -0
  349. package/dist/reporting/tracking.d.mts.map +1 -0
  350. package/dist/reporting/tracking.mjs +151 -0
  351. package/dist/reporting/tracking.mjs.map +1 -0
  352. package/dist/runtime.cjs +19 -0
  353. package/dist/runtime.cjs.map +1 -0
  354. package/dist/runtime.d.cts +30 -0
  355. package/dist/runtime.d.cts.map +1 -0
  356. package/dist/runtime.d.mts +30 -0
  357. package/dist/runtime.d.mts.map +1 -0
  358. package/dist/runtime.mjs +18 -0
  359. package/dist/runtime.mjs.map +1 -0
  360. package/dist/store/d1.cjs +185 -0
  361. package/dist/store/d1.cjs.map +1 -0
  362. package/dist/store/d1.d.cts +55 -0
  363. package/dist/store/d1.d.cts.map +1 -0
  364. package/dist/store/d1.d.mts +55 -0
  365. package/dist/store/d1.d.mts.map +1 -0
  366. package/dist/store/d1.mjs +184 -0
  367. package/dist/store/d1.mjs.map +1 -0
  368. package/dist/store/facts.cjs +60 -0
  369. package/dist/store/facts.cjs.map +1 -0
  370. package/dist/store/facts.d.cts +38 -0
  371. package/dist/store/facts.d.cts.map +1 -0
  372. package/dist/store/facts.d.mts +38 -0
  373. package/dist/store/facts.d.mts.map +1 -0
  374. package/dist/store/facts.mjs +58 -0
  375. package/dist/store/facts.mjs.map +1 -0
  376. package/dist/store/index.cjs +31 -0
  377. package/dist/store/index.cjs.map +1 -0
  378. package/dist/store/index.d.cts +291 -0
  379. package/dist/store/index.d.cts.map +1 -0
  380. package/dist/store/index.d.mts +291 -0
  381. package/dist/store/index.d.mts.map +1 -0
  382. package/dist/store/index.mjs +22 -0
  383. package/dist/store/index.mjs.map +1 -0
  384. package/dist/store/postgres-reporting.cjs +213 -0
  385. package/dist/store/postgres-reporting.cjs.map +1 -0
  386. package/dist/store/postgres-reporting.d.cts +63 -0
  387. package/dist/store/postgres-reporting.d.cts.map +1 -0
  388. package/dist/store/postgres-reporting.d.mts +63 -0
  389. package/dist/store/postgres-reporting.d.mts.map +1 -0
  390. package/dist/store/postgres-reporting.mjs +212 -0
  391. package/dist/store/postgres-reporting.mjs.map +1 -0
  392. package/dist/store/postgres.cjs +309 -0
  393. package/dist/store/postgres.cjs.map +1 -0
  394. package/dist/store/postgres.d.cts +77 -0
  395. package/dist/store/postgres.d.cts.map +1 -0
  396. package/dist/store/postgres.d.mts +77 -0
  397. package/dist/store/postgres.d.mts.map +1 -0
  398. package/dist/store/postgres.mjs +306 -0
  399. package/dist/store/postgres.mjs.map +1 -0
  400. package/dist/store/sql.cjs +24 -0
  401. package/dist/store/sql.cjs.map +1 -0
  402. package/dist/store/sql.d.cts +25 -0
  403. package/dist/store/sql.d.cts.map +1 -0
  404. package/dist/store/sql.d.mts +25 -0
  405. package/dist/store/sql.d.mts.map +1 -0
  406. package/dist/store/sql.mjs +23 -0
  407. package/dist/store/sql.mjs.map +1 -0
  408. package/dist/store/tables.cjs +404 -0
  409. package/dist/store/tables.cjs.map +1 -0
  410. package/dist/store/tables.d.cts +81 -0
  411. package/dist/store/tables.d.cts.map +1 -0
  412. package/dist/store/tables.d.mts +81 -0
  413. package/dist/store/tables.d.mts.map +1 -0
  414. package/dist/store/tables.mjs +399 -0
  415. package/dist/store/tables.mjs.map +1 -0
  416. package/dist/templates.cjs +247 -0
  417. package/dist/templates.cjs.map +1 -0
  418. package/dist/templates.d.cts +187 -0
  419. package/dist/templates.d.cts.map +1 -0
  420. package/dist/templates.d.mts +187 -0
  421. package/dist/templates.d.mts.map +1 -0
  422. package/dist/templates.mjs +230 -0
  423. package/dist/templates.mjs.map +1 -0
  424. package/dist/webhooks.cjs +96 -0
  425. package/dist/webhooks.cjs.map +1 -0
  426. package/dist/webhooks.d.cts +25 -0
  427. package/dist/webhooks.d.cts.map +1 -0
  428. package/dist/webhooks.d.mts +25 -0
  429. package/dist/webhooks.d.mts.map +1 -0
  430. package/dist/webhooks.mjs +94 -0
  431. package/dist/webhooks.mjs.map +1 -0
  432. package/dist/webpush.cjs +180 -0
  433. package/dist/webpush.cjs.map +1 -0
  434. package/dist/webpush.d.cts +53 -0
  435. package/dist/webpush.d.cts.map +1 -0
  436. package/dist/webpush.d.mts +53 -0
  437. package/dist/webpush.d.mts.map +1 -0
  438. package/dist/webpush.mjs +175 -0
  439. package/dist/webpush.mjs.map +1 -0
  440. package/package.json +189 -3
  441. package/src/cloudflare/schema.sql +127 -0
  442. package/src/cloudflare/workers.d.ts +44 -0
@@ -0,0 +1,247 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
+ let zod_mini = require("zod/mini");
4
+ zod_mini = require_runtime.__toESM(zod_mini, 1);
5
+ //#region src/templates.ts
6
+ /** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */
7
+ function discordTemplate(definition) {
8
+ assertSupportedSchema(definition.props, definition.title);
9
+ parsePreview(definition.props, definition.preview, "discord", definition.title);
10
+ return {
11
+ kind: "discord-template",
12
+ version: 1,
13
+ ...definition
14
+ };
15
+ }
16
+ /** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */
17
+ function slackTemplate(definition) {
18
+ assertSupportedSchema(definition.props, definition.title);
19
+ parsePreview(definition.props, definition.preview, "slack", definition.title);
20
+ return {
21
+ kind: "slack-template",
22
+ version: 1,
23
+ ...definition
24
+ };
25
+ }
26
+ /** Declare an email template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
27
+ function emailTemplate(definition) {
28
+ assertSupportedSchema(definition.props, definition.title);
29
+ parsePreview(definition.props, definition.preview, "email", definition.title);
30
+ return {
31
+ kind: "email-template",
32
+ version: 1,
33
+ ...definition
34
+ };
35
+ }
36
+ /** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
37
+ function pushTemplate(definition) {
38
+ assertSupportedSchema(definition.props, definition.title);
39
+ parsePreview(definition.props, definition.preview, "push", definition.title);
40
+ return {
41
+ kind: "push-template",
42
+ version: 1,
43
+ ...definition
44
+ };
45
+ }
46
+ function isEmailTemplate(value) {
47
+ return isMarked(value, "email-template");
48
+ }
49
+ function isPushTemplate(value) {
50
+ return isMarked(value, "push-template");
51
+ }
52
+ function isDiscordTemplate(value) {
53
+ return isMarked(value, "discord-template");
54
+ }
55
+ function isSlackTemplate(value) {
56
+ return isMarked(value, "slack-template");
57
+ }
58
+ const CHANNEL_OF = {
59
+ "email-template": "email",
60
+ "push-template": "push",
61
+ "discord-template": "discord",
62
+ "slack-template": "slack"
63
+ };
64
+ function isMarked(value, kind) {
65
+ return typeof value === "object" && value !== null && value.kind === kind && value.version === 1;
66
+ }
67
+ /**
68
+ * A template refused its input (`phase: 'props'` — the component/content was
69
+ * never called) or its content function returned something that is not a
70
+ * notification (`phase: 'content'` — called, but nothing is sent). Never a
71
+ * provider failure: a sender must not read it as a dead device token.
72
+ */
73
+ var TemplateValidationError = class extends Error {
74
+ channel;
75
+ template;
76
+ phase;
77
+ issues;
78
+ name = "TemplateValidationError";
79
+ constructor(channel, template, phase, issues) {
80
+ super(`${channel} template '${template}' ${phase === "props" ? "rejected its props" : "returned invalid content"}: ${issues.map((i) => `${i.path || "(root)"} ${i.message}`).join("; ")}`);
81
+ this.channel = channel;
82
+ this.template = template;
83
+ this.phase = phase;
84
+ this.issues = issues;
85
+ }
86
+ };
87
+ function issuesOf(error) {
88
+ return error.issues.map((issue) => ({
89
+ path: issue.path.map(String).join("."),
90
+ message: issue.message
91
+ }));
92
+ }
93
+ /**
94
+ * Parse message props against a template's schema and return the parsed value
95
+ * — the only value anything downstream may use. Throws TemplateValidationError.
96
+ */
97
+ function parseTemplateProps(template, key, props) {
98
+ const channel = CHANNEL_OF[template.kind];
99
+ const result = zod_mini.safeParse(template.props, props);
100
+ if (!result.success) throw new TemplateValidationError(channel, key, "props", issuesOf(result.error));
101
+ return result.data;
102
+ }
103
+ const pushContentSchema = zod_mini.strictObject({
104
+ title: zod_mini.string(),
105
+ body: zod_mini.string(),
106
+ image: zod_mini.optional(zod_mini.string()),
107
+ url: zod_mini.optional(zod_mini.string())
108
+ });
109
+ /** Run a push template's content over parsed props and check the notification it returns. */
110
+ function renderPushContent(template, key, props) {
111
+ const parsed = parseTemplateProps(template, key, props);
112
+ const output = template.content(parsed);
113
+ const result = zod_mini.safeParse(pushContentSchema, output);
114
+ if (!result.success) throw new TemplateValidationError("push", key, "content", issuesOf(result.error));
115
+ return result.data;
116
+ }
117
+ /**
118
+ * What a Discord webhook accepts at all: something to show (content, an embed, a poll or
119
+ * components) and content within Discord's 2000 characters. The rest of the body is Discord's to
120
+ * judge; its types come from `discord-api-types`.
121
+ */
122
+ const discordContentSchema = zod_mini.looseObject({
123
+ content: zod_mini.optional(zod_mini.string().check(zod_mini.maxLength(2e3))),
124
+ embeds: zod_mini.optional(zod_mini.array(zod_mini.looseObject({})))
125
+ });
126
+ const slackContentSchema = zod_mini.looseObject({
127
+ text: zod_mini.string().check(zod_mini.minLength(1)),
128
+ blocks: zod_mini.optional(zod_mini.array(zod_mini.looseObject({ type: zod_mini.string() })))
129
+ });
130
+ /** Run a Discord template's content over parsed props and check the message it returns. */
131
+ function renderDiscordContent(template, key, props) {
132
+ const output = template.content(parseTemplateProps(template, key, props));
133
+ const result = zod_mini.safeParse(discordContentSchema, output);
134
+ const empty = result.success && !result.data.content && (result.data.embeds?.length ?? 0) === 0 && output.poll === void 0 && (output.components?.length ?? 0) === 0;
135
+ if (!result.success || empty) throw new TemplateValidationError("discord", key, "content", result.success ? [{
136
+ path: "",
137
+ message: "a Discord message needs content, an embed, a poll or components"
138
+ }] : issuesOf(result.error));
139
+ return output;
140
+ }
141
+ /** Run a Slack template's content over parsed props and check the message it returns. */
142
+ function renderSlackContent(template, key, props) {
143
+ const output = template.content(parseTemplateProps(template, key, props));
144
+ const result = zod_mini.safeParse(slackContentSchema, output);
145
+ if (!result.success) throw new TemplateValidationError("slack", key, "content", issuesOf(result.error));
146
+ return output;
147
+ }
148
+ function parsePreview(schema, preview, channel, title) {
149
+ const result = zod_mini.safeParse(schema, preview);
150
+ if (!result.success) throw new TemplateValidationError(channel, title, "props", issuesOf(result.error).map((i) => Object.assign(i, { message: `preview: ${i.message}` })));
151
+ }
152
+ const SCALAR_TYPES = /* @__PURE__ */ new Set([
153
+ "string",
154
+ "number",
155
+ "boolean",
156
+ "enum"
157
+ ]);
158
+ /** Throws when `schema` is outside the v1 subset (see the header). */
159
+ function assertSupportedSchema(schema, where) {
160
+ const fail = (reason) => {
161
+ throw new TypeError(`template '${where}': unsupported props schema — ${reason}`);
162
+ };
163
+ const def = schema?._zod?.def;
164
+ if (def?.type !== "object") fail("props must be a z.strictObject({...})");
165
+ const object = def;
166
+ if (object.catchall?._zod.def.type !== "never") fail("props must be strict (z.strictObject): unknown fields would be dropped or passed through");
167
+ rejectCustomChecks(object, where, fail);
168
+ for (const [field, value] of Object.entries(object.shape)) {
169
+ let fieldDef = value._zod.def;
170
+ if (fieldDef.type === "optional") {
171
+ rejectCustomChecks(fieldDef, `${where}.${field}`, fail);
172
+ fieldDef = fieldDef.innerType._zod.def;
173
+ }
174
+ if (fieldDef.type === "literal") {
175
+ if (!fieldDef.values.every((v) => [
176
+ "string",
177
+ "number",
178
+ "boolean"
179
+ ].includes(typeof v))) fail(`field '${field}' is a literal of a non-scalar value`);
180
+ } else if (!SCALAR_TYPES.has(fieldDef.type)) fail(`field '${field}' is ${fieldDef.type}; only string, number, boolean, enum and literal fields (optionally .optional()) are supported`);
181
+ if (fieldDef.coerce === true) fail(`field '${field}' coerces its input (z.coerce), which would change what the props mean`);
182
+ rejectCustomChecks(fieldDef, `${where}.${field}`, fail);
183
+ }
184
+ }
185
+ /**
186
+ * Checks the subset refuses: `custom` runs arbitrary code (`.refine()`), and
187
+ * `overwrite` changes the value (`.overwrite()`, `.trim()`, `.toLowerCase()`…)
188
+ * — the props are parsed more than once on the way to a send (the validator,
189
+ * then the renderer), so a value-changing check would apply twice and the
190
+ * email would differ from the preview.
191
+ */
192
+ function rejectCustomChecks(def, where, fail) {
193
+ for (const check of def.checks ?? []) {
194
+ if (check._zod.def.check === "custom") fail(`'${where}' uses a custom refinement, which the template subset does not support`);
195
+ if (check._zod.def.check === "overwrite") fail(`'${where}' changes the value (.overwrite, .trim, .toLowerCase, …), which the template subset does not support`);
196
+ }
197
+ }
198
+ /**
199
+ * The engine's MessageValidator over the template registries: the message's
200
+ * props are parsed by its template (the parsed value is what gets sent); a
201
+ * push's content is also run once and checked, so an invalid notification
202
+ * stops the send before any device; Discord and Slack content likewise. Channels without a
203
+ * registry here (sms, …) pass through to their app-supplied senders.
204
+ */
205
+ function registryValidator(registries) {
206
+ return { validate({ channel, template, props }) {
207
+ if (channel === "email") return parseTemplateProps(lookup(registries.email, "email", template), template, props);
208
+ if (channel === "push") {
209
+ const entry = lookup(registries.push, "push", template);
210
+ renderPushContent(entry, template, props);
211
+ return parseTemplateProps(entry, template, props);
212
+ }
213
+ if (channel === "discord") {
214
+ const entry = lookup(registries.discord, "discord", template);
215
+ renderDiscordContent(entry, template, props);
216
+ return parseTemplateProps(entry, template, props);
217
+ }
218
+ if (channel === "slack") {
219
+ const entry = lookup(registries.slack, "slack", template);
220
+ renderSlackContent(entry, template, props);
221
+ return parseTemplateProps(entry, template, props);
222
+ }
223
+ return props;
224
+ } };
225
+ }
226
+ function lookup(registry, channel, key) {
227
+ if (registry === void 0 || !Object.hasOwn(registry, key)) throw new Error(`${channel} template '${key}' is not registered`);
228
+ return registry[key];
229
+ }
230
+ //#endregion
231
+ exports.TemplateValidationError = TemplateValidationError;
232
+ exports.assertSupportedSchema = assertSupportedSchema;
233
+ exports.discordTemplate = discordTemplate;
234
+ exports.emailTemplate = emailTemplate;
235
+ exports.isDiscordTemplate = isDiscordTemplate;
236
+ exports.isEmailTemplate = isEmailTemplate;
237
+ exports.isPushTemplate = isPushTemplate;
238
+ exports.isSlackTemplate = isSlackTemplate;
239
+ exports.parseTemplateProps = parseTemplateProps;
240
+ exports.pushTemplate = pushTemplate;
241
+ exports.registryValidator = registryValidator;
242
+ exports.renderDiscordContent = renderDiscordContent;
243
+ exports.renderPushContent = renderPushContent;
244
+ exports.renderSlackContent = renderSlackContent;
245
+ exports.slackTemplate = slackTemplate;
246
+
247
+ //# sourceMappingURL=templates.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.cjs","names":["z"],"sources":["../src/templates.ts"],"sourcesContent":["import type { Block, KnownBlock } from '@slack/types';\nimport type { RESTPostAPIWebhookWithTokenJSONBody } from 'discord-api-types/v10';\nimport * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport type { ScalarIR } from './ir';\n\n/**\n * Template definitions — `emailTemplate`, `pushTemplate`, `discordTemplate` and `slackTemplate`. One\n * object per template, and its Zod `props` schema is the only source of the\n * props type: the DSL's `.email()/.push()` arguments, the `preview`, and the\n * `component`/`content` parameter are all derived from it, and every render\n * parses the props against it first (types alone check nothing at run time).\n *\n * Kept free of React and of any renderer: the definitions are plain data plus\n * a function, so the DSL, the Worker and the studio can all import them; the\n * React rendering lives in `@shware/workflow/react-email`.\n *\n * Supported schemas (v1): a strict object (`z.strictObject`) whose fields are\n * string / number / boolean — optionally as enums or literals, optionally\n * `.optional()`, with the built-in checks (min, email, …). That is exactly\n * what IR message props can carry, and it keeps input and output identical, so\n * producer, studio and sender never disagree about a transformed value.\n * Anything else (nested objects, arrays, null, default/transform/coerce,\n * custom refinements) is rejected when the template is declared.\n */\n\n/** A strict Zod object schema of scalar fields — the accepted shape of `props`. */\nexport type PropsSchema = core.$ZodObject;\n\n/** What a push template's `content` returns: the notification itself. */\nexport interface PushContent {\n title: string;\n body: string;\n /** Rich image URL (iOS attachment / Android BigPicture). */\n image?: string;\n /** Where a tap leads: the page a browser push opens (the site's root when absent). */\n url?: string;\n}\n\n/** A Discord webhook message (`discord-api-types`): content, embeds, username, allowed mentions… */\nexport type DiscordContent = RESTPostAPIWebhookWithTokenJSONBody;\n\n/** A Slack incoming-webhook message: the fallback `text` and, usually, Block Kit `blocks`. */\nexport interface SlackContent {\n /** Shown in notifications and wherever blocks cannot be; required even with blocks. */\n text: string;\n blocks?: (KnownBlock | Block)[];\n username?: string;\n icon_emoji?: string;\n icon_url?: string;\n mrkdwn?: boolean;\n unfurl_links?: boolean;\n unfurl_media?: boolean;\n}\n\n/** The channels a template can be declared for. */\nexport type TemplateChannel = 'email' | 'push' | 'discord' | 'slack';\n\ninterface TemplateBase<S extends PropsSchema> {\n /** Display name in the studio (not the email subject, not the notification title). */\n readonly title: string;\n readonly description?: string | undefined;\n readonly props: S;\n /** Sample props for the studio; parsed against `props` when the template is declared. */\n readonly preview: core.input<S>;\n}\n\nexport interface EmailTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {\n readonly kind: 'email-template';\n readonly version: 1;\n readonly subject: string;\n /** The email body: a component over the parsed props (rendered by `@shware/workflow/react-email`). */\n readonly component: (props: Readonly<core.output<S>>) => unknown;\n}\n\nexport interface PushTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {\n readonly kind: 'push-template';\n readonly version: 1;\n /** The notification, from the parsed props. Synchronous and pure; its result is checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => PushContent;\n}\n\n/**\n * A message posted to a team channel through an incoming webhook (Discord, Slack). The webhook\n * URL is a secret, so it lives in the Worker's environment and the template reads it from there\n * at send time: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`, with `Env` the host's\n * zod-validated environment (`journeyWorker({ env: schema })`). The studio never calls it.\n */\ninterface WebhookTemplateBase<S extends PropsSchema, Env> extends TemplateBase<S> {\n readonly version: 1;\n // A method, so a template typed by the host's Env still fits a registry of any Env\n webhook(env: Env): string | undefined;\n}\n\nexport interface DiscordTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'discord-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => DiscordContent;\n}\n\nexport interface SlackTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'slack-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => SlackContent;\n}\n\n/** Strips a Promise return out of the accepted callback types: async content is rejected at the type level. */\ntype Sync<T> = T extends Promise<unknown> ? never : T;\n\nexport interface EmailTemplateDefinition<S extends PropsSchema> {\n title: string;\n description?: string;\n props: S;\n subject: string;\n preview: NoInfer<core.input<S>>;\n component: (props: NoInfer<Readonly<core.output<S>>>) => unknown;\n}\n\nexport interface PushTemplateDefinition<S extends PropsSchema, R> {\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<R> & PushContent;\n}\n\nexport interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n /** The webhook URL, read from the Worker's environment when a message is sent. */\n webhook: (env: Env) => string | undefined;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<C>;\n}\n\n/** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function discordTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, DiscordContent>\n): DiscordTemplate<S, Env> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'discord', definition.title);\n return { kind: 'discord-template', version: 1, ...definition };\n}\n\n/** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function slackTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, SlackContent>\n): SlackTemplate<S, Env> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'slack', definition.title);\n return { kind: 'slack-template', version: 1, ...definition };\n}\n\n/** Declare an email template. Throws when `props` uses an unsupported schema or `preview` does not parse. */\nexport function emailTemplate<S extends PropsSchema>(\n definition: EmailTemplateDefinition<S>\n): EmailTemplate<S> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'email', definition.title);\n return { kind: 'email-template', version: 1, ...definition };\n}\n\n/** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */\nexport function pushTemplate<S extends PropsSchema, R extends PushContent>(\n definition: PushTemplateDefinition<S, R>\n): PushTemplate<S> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'push', definition.title);\n return { kind: 'push-template', version: 1, ...definition } as unknown as PushTemplate<S>;\n}\n\nexport function isEmailTemplate(value: unknown): value is EmailTemplate {\n return isMarked(value, 'email-template');\n}\n\nexport function isPushTemplate(value: unknown): value is PushTemplate {\n return isMarked(value, 'push-template');\n}\n\nexport function isDiscordTemplate(value: unknown): value is DiscordTemplate {\n return isMarked(value, 'discord-template');\n}\n\nexport function isSlackTemplate(value: unknown): value is SlackTemplate {\n return isMarked(value, 'slack-template');\n}\n\n/** Any declared template. */\nexport type AnyTemplate = EmailTemplate | PushTemplate | DiscordTemplate | SlackTemplate;\n\nconst CHANNEL_OF: Record<AnyTemplate['kind'], TemplateChannel> = {\n 'email-template': 'email',\n 'push-template': 'push',\n 'discord-template': 'discord',\n 'slack-template': 'slack',\n};\n\nfunction isMarked(value: unknown, kind: string): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === kind &&\n (value as { version?: unknown }).version === 1\n );\n}\n\n/* ------------------------------- validation -------------------------------- */\n\n/** One failed field, with the dotted path the studio and the logs show. */\nexport interface TemplateIssue {\n path: string;\n message: string;\n}\n\n/**\n * A template refused its input (`phase: 'props'` — the component/content was\n * never called) or its content function returned something that is not a\n * notification (`phase: 'content'` — called, but nothing is sent). Never a\n * provider failure: a sender must not read it as a dead device token.\n */\nexport class TemplateValidationError extends Error {\n override readonly name = 'TemplateValidationError';\n constructor(\n readonly channel: TemplateChannel,\n readonly template: string,\n readonly phase: 'props' | 'content',\n readonly issues: TemplateIssue[]\n ) {\n super(\n `${channel} template '${template}' ${phase === 'props' ? 'rejected its props' : 'returned invalid content'}: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n }\n}\n\nfunction issuesOf(error: core.$ZodError): TemplateIssue[] {\n return error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n}\n\n/**\n * Parse message props against a template's schema and return the parsed value\n * — the only value anything downstream may use. Throws TemplateValidationError.\n */\nexport function parseTemplateProps<S extends PropsSchema>(\n template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>,\n key: string,\n props: Record<string, unknown>\n): core.output<S> {\n const channel = CHANNEL_OF[template.kind];\n const result = z.safeParse(template.props, props);\n if (!result.success) {\n throw new TemplateValidationError(channel, key, 'props', issuesOf(result.error));\n }\n return result.data;\n}\n\nconst pushContentSchema = z.strictObject({\n title: z.string(),\n body: z.string(),\n image: z.optional(z.string()),\n url: z.optional(z.string()),\n});\n\n/** Run a push template's content over parsed props and check the notification it returns. */\nexport function renderPushContent(\n template: PushTemplate,\n key: string,\n props: Record<string, unknown>\n): PushContent {\n const parsed = parseTemplateProps(template, key, props);\n const output: unknown = template.content(parsed);\n // A Promise (async content smuggled past the types) is an object without title/body: refused here\n const result = z.safeParse(pushContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('push', key, 'content', issuesOf(result.error));\n }\n return result.data;\n}\n\n/**\n * What a Discord webhook accepts at all: something to show (content, an embed, a poll or\n * components) and content within Discord's 2000 characters. The rest of the body is Discord's to\n * judge; its types come from `discord-api-types`.\n */\nconst discordContentSchema = z.looseObject({\n content: z.optional(z.string().check(z.maxLength(2000))),\n embeds: z.optional(z.array(z.looseObject({}))),\n});\n\nconst slackContentSchema = z.looseObject({\n text: z.string().check(z.minLength(1)),\n blocks: z.optional(z.array(z.looseObject({ type: z.string() }))),\n});\n\n/** Run a Discord template's content over parsed props and check the message it returns. */\nexport function renderDiscordContent(\n template: DiscordTemplate,\n key: string,\n props: Record<string, unknown>\n): DiscordContent {\n const output: unknown = template.content(parseTemplateProps(template, key, props));\n const result = z.safeParse(discordContentSchema, output);\n const empty =\n result.success &&\n !result.data.content &&\n (result.data.embeds?.length ?? 0) === 0 &&\n (output as { poll?: unknown; components?: unknown[] }).poll === undefined &&\n ((output as { components?: unknown[] }).components?.length ?? 0) === 0;\n if (!result.success || empty) {\n const issues = result.success\n ? [{ path: '', message: 'a Discord message needs content, an embed, a poll or components' }]\n : issuesOf(result.error);\n throw new TemplateValidationError('discord', key, 'content', issues);\n }\n return output as DiscordContent;\n}\n\n/** Run a Slack template's content over parsed props and check the message it returns. */\nexport function renderSlackContent(\n template: SlackTemplate,\n key: string,\n props: Record<string, unknown>\n): SlackContent {\n const output: unknown = template.content(parseTemplateProps(template, key, props));\n const result = z.safeParse(slackContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('slack', key, 'content', issuesOf(result.error));\n }\n return output as SlackContent;\n}\n\nfunction parsePreview(\n schema: PropsSchema,\n preview: unknown,\n channel: TemplateChannel,\n title: string\n) {\n const result = z.safeParse(schema, preview);\n if (!result.success) {\n throw new TemplateValidationError(\n channel,\n title,\n 'props',\n issuesOf(result.error).map((i) => Object.assign(i, { message: `preview: ${i.message}` }))\n );\n }\n}\n\n/* ---------------------------- supported schemas ---------------------------- */\n\nconst SCALAR_TYPES = new Set(['string', 'number', 'boolean', 'enum']);\n\n/** Throws when `schema` is outside the v1 subset (see the header). */\nexport function assertSupportedSchema(schema: unknown, where: string): void {\n const fail = (reason: string): never => {\n throw new TypeError(`template '${where}': unsupported props schema — ${reason}`);\n };\n const def = (schema as core.$ZodType | undefined)?._zod?.def;\n if (def?.type !== 'object') fail('props must be a z.strictObject({...})');\n const object = def as core.$ZodObjectDef;\n if (object.catchall?._zod.def.type !== 'never') {\n fail(\n 'props must be strict (z.strictObject): unknown fields would be dropped or passed through'\n );\n }\n rejectCustomChecks(object, where, fail);\n for (const [field, value] of Object.entries(object.shape)) {\n let fieldDef = value._zod.def;\n if (fieldDef.type === 'optional') {\n // The wrapper carries checks of its own (`.optional().overwrite(...)`): refuse them too\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n fieldDef = (fieldDef as core.$ZodOptionalDef).innerType._zod.def;\n }\n if (fieldDef.type === 'literal') {\n const values = (fieldDef as core.$ZodLiteralDef<core.util.Literal>).values;\n if (!values.every((v) => ['string', 'number', 'boolean'].includes(typeof v))) {\n fail(`field '${field}' is a literal of a non-scalar value`);\n }\n } else if (!SCALAR_TYPES.has(fieldDef.type)) {\n fail(\n `field '${field}' is ${fieldDef.type}; only string, number, boolean, enum and literal fields (optionally .optional()) are supported`\n );\n }\n if ((fieldDef as { coerce?: boolean }).coerce === true) {\n fail(`field '${field}' coerces its input (z.coerce), which would change what the props mean`);\n }\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n }\n}\n\n/**\n * Checks the subset refuses: `custom` runs arbitrary code (`.refine()`), and\n * `overwrite` changes the value (`.overwrite()`, `.trim()`, `.toLowerCase()`…)\n * — the props are parsed more than once on the way to a send (the validator,\n * then the renderer), so a value-changing check would apply twice and the\n * email would differ from the preview.\n */\nfunction rejectCustomChecks(def: core.$ZodTypeDef, where: string, fail: (reason: string) => never) {\n for (const check of def.checks ?? []) {\n if (check._zod.def.check === 'custom') {\n fail(`'${where}' uses a custom refinement, which the template subset does not support`);\n }\n if (check._zod.def.check === 'overwrite') {\n fail(\n `'${where}' changes the value (.overwrite, .trim, .toLowerCase, …), which the template subset does not support`\n );\n }\n }\n}\n\n/** The scalar props a template accepts, as the IR resolves them before parsing. */\nexport type ResolvedProps = Record<string, ScalarIR | undefined>;\n\n/**\n * The engine's MessageValidator over the template registries: the message's\n * props are parsed by its template (the parsed value is what gets sent); a\n * push's content is also run once and checked, so an invalid notification\n * stops the send before any device; Discord and Slack content likewise. Channels without a\n * registry here (sms, …) pass through to their app-supplied senders.\n */\nexport function registryValidator(registries: {\n email?: Record<string, EmailTemplate> | undefined;\n push?: Record<string, PushTemplate> | undefined;\n discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>> | undefined;\n slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>> | undefined;\n}): {\n validate(message: { channel: string; template: string; props: ResolvedProps }): ResolvedProps;\n} {\n return {\n validate({ channel, template, props }) {\n if (channel === 'email') {\n return parseTemplateProps(\n lookup(registries.email, 'email', template),\n template,\n props\n ) as ResolvedProps;\n }\n if (channel === 'push') {\n const entry = lookup(registries.push, 'push', template);\n renderPushContent(entry, template, props);\n return parseTemplateProps(entry, template, props) as ResolvedProps;\n }\n if (channel === 'discord') {\n const entry = lookup(registries.discord, 'discord', template) as DiscordTemplate;\n renderDiscordContent(entry, template, props);\n return parseTemplateProps(entry, template, props) as ResolvedProps;\n }\n if (channel === 'slack') {\n const entry = lookup(registries.slack, 'slack', template) as SlackTemplate;\n renderSlackContent(entry, template, props);\n return parseTemplateProps(entry, template, props) as ResolvedProps;\n }\n return props;\n },\n };\n}\n\nfunction lookup<T>(registry: Record<string, T> | undefined, channel: string, key: string): T {\n if (registry === undefined || !Object.hasOwn(registry, key)) {\n throw new Error(`${channel} template '${key}' is not registered`);\n }\n return registry[key];\n}\n"],"mappings":";;;;;;AA+IA,SAAgB,gBACd,YACyB;CACzB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,WAAW,WAAW,KAAK;CAC9E,OAAO;EAAE,MAAM;EAAoB,SAAS;EAAG,GAAG;CAAW;AAC/D;;AAGA,SAAgB,cACd,YACuB;CACvB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,SAAS,WAAW,KAAK;CAC5E,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAG,GAAG;CAAW;AAC7D;;AAGA,SAAgB,cACd,YACkB;CAClB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,SAAS,WAAW,KAAK;CAC5E,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAG,GAAG;CAAW;AAC7D;;AAGA,SAAgB,aACd,YACiB;CACjB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,QAAQ,WAAW,KAAK;CAC3E,OAAO;EAAE,MAAM;EAAiB,SAAS;EAAG,GAAG;CAAW;AAC5D;AAEA,SAAgB,gBAAgB,OAAwC;CACtE,OAAO,SAAS,OAAO,gBAAgB;AACzC;AAEA,SAAgB,eAAe,OAAuC;CACpE,OAAO,SAAS,OAAO,eAAe;AACxC;AAEA,SAAgB,kBAAkB,OAA0C;CAC1E,OAAO,SAAS,OAAO,kBAAkB;AAC3C;AAEA,SAAgB,gBAAgB,OAAwC;CACtE,OAAO,SAAS,OAAO,gBAAgB;AACzC;AAKA,MAAM,aAA2D;CAC/D,kBAAkB;CAClB,iBAAiB;CACjB,oBAAoB;CACpB,kBAAkB;AACpB;AAEA,SAAS,SAAS,OAAgB,MAAuB;CACvD,OACE,OAAO,UAAU,YACjB,UAAU,QACT,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I,UAAU,CAAC,GAAG;EACpC,IAAI,MAAM,KAAK,IAAI,UAAU,UAC3B,KAAK,IAAI,MAAM,uEAAuE;EAExF,IAAI,MAAM,KAAK,IAAI,UAAU,aAC3B,KACE,IAAI,MAAM,qGACZ;CAEJ;AACF;;;;;;;;AAYA,SAAgB,kBAAkB,YAOhC;CACA,OAAO,EACL,SAAS,EAAE,SAAS,UAAU,SAAS;EACrC,IAAI,YAAY,SACd,OAAO,mBACL,OAAO,WAAW,OAAO,SAAS,QAAQ,GAC1C,UACA,KACF;EAEF,IAAI,YAAY,QAAQ;GACtB,MAAM,QAAQ,OAAO,WAAW,MAAM,QAAQ,QAAQ;GACtD,kBAAkB,OAAO,UAAU,KAAK;GACxC,OAAO,mBAAmB,OAAO,UAAU,KAAK;EAClD;EACA,IAAI,YAAY,WAAW;GACzB,MAAM,QAAQ,OAAO,WAAW,SAAS,WAAW,QAAQ;GAC5D,qBAAqB,OAAO,UAAU,KAAK;GAC3C,OAAO,mBAAmB,OAAO,UAAU,KAAK;EAClD;EACA,IAAI,YAAY,SAAS;GACvB,MAAM,QAAQ,OAAO,WAAW,OAAO,SAAS,QAAQ;GACxD,mBAAmB,OAAO,UAAU,KAAK;GACzC,OAAO,mBAAmB,OAAO,UAAU,KAAK;EAClD;EACA,OAAO;CACT,EACF;AACF;AAEA,SAAS,OAAU,UAAyC,SAAiB,KAAgB;CAC3F,IAAI,aAAa,KAAA,KAAa,CAAC,OAAO,OAAO,UAAU,GAAG,GACxD,MAAM,IAAI,MAAM,GAAG,QAAQ,aAAa,IAAI,oBAAoB;CAElE,OAAO,SAAS;AAClB"}
@@ -0,0 +1,187 @@
1
+ import { ScalarIR } from "./ir.cjs";
2
+ import { Block, KnownBlock } from "@slack/types";
3
+ import { RESTPostAPIWebhookWithTokenJSONBody } from "discord-api-types/v10";
4
+ import * as core from "zod/v4/core";
5
+ //#region src/templates.d.ts
6
+ /**
7
+ * Template definitions — `emailTemplate`, `pushTemplate`, `discordTemplate` and `slackTemplate`. One
8
+ * object per template, and its Zod `props` schema is the only source of the
9
+ * props type: the DSL's `.email()/.push()` arguments, the `preview`, and the
10
+ * `component`/`content` parameter are all derived from it, and every render
11
+ * parses the props against it first (types alone check nothing at run time).
12
+ *
13
+ * Kept free of React and of any renderer: the definitions are plain data plus
14
+ * a function, so the DSL, the Worker and the studio can all import them; the
15
+ * React rendering lives in `@shware/workflow/react-email`.
16
+ *
17
+ * Supported schemas (v1): a strict object (`z.strictObject`) whose fields are
18
+ * string / number / boolean — optionally as enums or literals, optionally
19
+ * `.optional()`, with the built-in checks (min, email, …). That is exactly
20
+ * what IR message props can carry, and it keeps input and output identical, so
21
+ * producer, studio and sender never disagree about a transformed value.
22
+ * Anything else (nested objects, arrays, null, default/transform/coerce,
23
+ * custom refinements) is rejected when the template is declared.
24
+ */
25
+ /** A strict Zod object schema of scalar fields — the accepted shape of `props`. */
26
+ export type PropsSchema = core.$ZodObject;
27
+ /** What a push template's `content` returns: the notification itself. */
28
+ export interface PushContent {
29
+ title: string;
30
+ body: string;
31
+ /** Rich image URL (iOS attachment / Android BigPicture). */
32
+ image?: string;
33
+ /** Where a tap leads: the page a browser push opens (the site's root when absent). */
34
+ url?: string;
35
+ }
36
+ /** A Discord webhook message (`discord-api-types`): content, embeds, username, allowed mentions… */
37
+ export type DiscordContent = RESTPostAPIWebhookWithTokenJSONBody;
38
+ /** A Slack incoming-webhook message: the fallback `text` and, usually, Block Kit `blocks`. */
39
+ export interface SlackContent {
40
+ /** Shown in notifications and wherever blocks cannot be; required even with blocks. */
41
+ text: string;
42
+ blocks?: (KnownBlock | Block)[];
43
+ username?: string;
44
+ icon_emoji?: string;
45
+ icon_url?: string;
46
+ mrkdwn?: boolean;
47
+ unfurl_links?: boolean;
48
+ unfurl_media?: boolean;
49
+ }
50
+ /** The channels a template can be declared for. */
51
+ export type TemplateChannel = 'email' | 'push' | 'discord' | 'slack';
52
+ interface TemplateBase<S extends PropsSchema> {
53
+ /** Display name in the studio (not the email subject, not the notification title). */
54
+ readonly title: string;
55
+ readonly description?: string | undefined;
56
+ readonly props: S;
57
+ /** Sample props for the studio; parsed against `props` when the template is declared. */
58
+ readonly preview: core.input<S>;
59
+ }
60
+ export interface EmailTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {
61
+ readonly kind: 'email-template';
62
+ readonly version: 1;
63
+ readonly subject: string;
64
+ /** The email body: a component over the parsed props (rendered by `@shware/workflow/react-email`). */
65
+ readonly component: (props: Readonly<core.output<S>>) => unknown;
66
+ }
67
+ export interface PushTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {
68
+ readonly kind: 'push-template';
69
+ readonly version: 1;
70
+ /** The notification, from the parsed props. Synchronous and pure; its result is checked before sending. */
71
+ readonly content: (props: Readonly<core.output<S>>) => PushContent;
72
+ }
73
+ /**
74
+ * A message posted to a team channel through an incoming webhook (Discord, Slack). The webhook
75
+ * URL is a secret, so it lives in the Worker's environment and the template reads it from there
76
+ * at send time: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`, with `Env` the host's
77
+ * zod-validated environment (`journeyWorker({ env: schema })`). The studio never calls it.
78
+ */
79
+ interface WebhookTemplateBase<S extends PropsSchema, Env> extends TemplateBase<S> {
80
+ readonly version: 1;
81
+ webhook(env: Env): string | undefined;
82
+ }
83
+ export interface DiscordTemplate<S extends PropsSchema = PropsSchema, Env = Record<string, unknown>> extends WebhookTemplateBase<S, Env> {
84
+ readonly kind: 'discord-template';
85
+ /** The message, from the parsed props. Synchronous and pure; checked before sending. */
86
+ readonly content: (props: Readonly<core.output<S>>) => DiscordContent;
87
+ }
88
+ export interface SlackTemplate<S extends PropsSchema = PropsSchema, Env = Record<string, unknown>> extends WebhookTemplateBase<S, Env> {
89
+ readonly kind: 'slack-template';
90
+ /** The message, from the parsed props. Synchronous and pure; checked before sending. */
91
+ readonly content: (props: Readonly<core.output<S>>) => SlackContent;
92
+ }
93
+ /** Strips a Promise return out of the accepted callback types: async content is rejected at the type level. */
94
+ type Sync<T> = T extends Promise<unknown> ? never : T;
95
+ export interface EmailTemplateDefinition<S extends PropsSchema> {
96
+ title: string;
97
+ description?: string;
98
+ props: S;
99
+ subject: string;
100
+ preview: NoInfer<core.input<S>>;
101
+ component: (props: NoInfer<Readonly<core.output<S>>>) => unknown;
102
+ }
103
+ export interface PushTemplateDefinition<S extends PropsSchema, R> {
104
+ title: string;
105
+ description?: string;
106
+ props: S;
107
+ preview: NoInfer<core.input<S>>;
108
+ content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<R> & PushContent;
109
+ }
110
+ export interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {
111
+ title: string;
112
+ description?: string;
113
+ props: S;
114
+ preview: NoInfer<core.input<S>>;
115
+ /** The webhook URL, read from the Worker's environment when a message is sent. */
116
+ webhook: (env: Env) => string | undefined;
117
+ content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<C>;
118
+ }
119
+ /** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */
120
+ export declare function discordTemplate<S extends PropsSchema, Env = Record<string, unknown>>(definition: WebhookTemplateDefinition<S, Env, DiscordContent>): DiscordTemplate<S, Env>;
121
+ /** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */
122
+ export declare function slackTemplate<S extends PropsSchema, Env = Record<string, unknown>>(definition: WebhookTemplateDefinition<S, Env, SlackContent>): SlackTemplate<S, Env>;
123
+ /** Declare an email template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
124
+ export declare function emailTemplate<S extends PropsSchema>(definition: EmailTemplateDefinition<S>): EmailTemplate<S>;
125
+ /** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
126
+ export declare function pushTemplate<S extends PropsSchema, R extends PushContent>(definition: PushTemplateDefinition<S, R>): PushTemplate<S>;
127
+ export declare function isEmailTemplate(value: unknown): value is EmailTemplate;
128
+ export declare function isPushTemplate(value: unknown): value is PushTemplate;
129
+ export declare function isDiscordTemplate(value: unknown): value is DiscordTemplate;
130
+ export declare function isSlackTemplate(value: unknown): value is SlackTemplate;
131
+ /** Any declared template. */
132
+ export type AnyTemplate = EmailTemplate | PushTemplate | DiscordTemplate | SlackTemplate;
133
+ /** One failed field, with the dotted path the studio and the logs show. */
134
+ export interface TemplateIssue {
135
+ path: string;
136
+ message: string;
137
+ }
138
+ /**
139
+ * A template refused its input (`phase: 'props'` — the component/content was
140
+ * never called) or its content function returned something that is not a
141
+ * notification (`phase: 'content'` — called, but nothing is sent). Never a
142
+ * provider failure: a sender must not read it as a dead device token.
143
+ */
144
+ export declare class TemplateValidationError extends Error {
145
+ readonly channel: TemplateChannel;
146
+ readonly template: string;
147
+ readonly phase: 'props' | 'content';
148
+ readonly issues: TemplateIssue[];
149
+ readonly name = "TemplateValidationError";
150
+ constructor(channel: TemplateChannel, template: string, phase: 'props' | 'content', issues: TemplateIssue[]);
151
+ }
152
+ /**
153
+ * Parse message props against a template's schema and return the parsed value
154
+ * — the only value anything downstream may use. Throws TemplateValidationError.
155
+ */
156
+ export declare function parseTemplateProps<S extends PropsSchema>(template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>, key: string, props: Record<string, unknown>): core.output<S>;
157
+ /** Run a push template's content over parsed props and check the notification it returns. */
158
+ export declare function renderPushContent(template: PushTemplate, key: string, props: Record<string, unknown>): PushContent;
159
+ /** Run a Discord template's content over parsed props and check the message it returns. */
160
+ export declare function renderDiscordContent(template: DiscordTemplate, key: string, props: Record<string, unknown>): DiscordContent;
161
+ /** Run a Slack template's content over parsed props and check the message it returns. */
162
+ export declare function renderSlackContent(template: SlackTemplate, key: string, props: Record<string, unknown>): SlackContent;
163
+ /** Throws when `schema` is outside the v1 subset (see the header). */
164
+ export declare function assertSupportedSchema(schema: unknown, where: string): void;
165
+ /** The scalar props a template accepts, as the IR resolves them before parsing. */
166
+ export type ResolvedProps = Record<string, ScalarIR | undefined>;
167
+ /**
168
+ * The engine's MessageValidator over the template registries: the message's
169
+ * props are parsed by its template (the parsed value is what gets sent); a
170
+ * push's content is also run once and checked, so an invalid notification
171
+ * stops the send before any device; Discord and Slack content likewise. Channels without a
172
+ * registry here (sms, …) pass through to their app-supplied senders.
173
+ */
174
+ export declare function registryValidator(registries: {
175
+ email?: Record<string, EmailTemplate> | undefined;
176
+ push?: Record<string, PushTemplate> | undefined;
177
+ discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>> | undefined;
178
+ slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>> | undefined;
179
+ }): {
180
+ validate(message: {
181
+ channel: string;
182
+ template: string;
183
+ props: ResolvedProps;
184
+ }): ResolvedProps;
185
+ };
186
+ //#endregion
187
+ //# sourceMappingURL=templates.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.cts","names":[],"sources":["../src/templates.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;YA2BY,cAAc,KAAK;;iBAGd;EACf;EACA;;EAEA;;EAEA;;;YAIU,iBAAiB;;iBAGZ;;EAEf;EACA,UAAU,aAAa;EACvB;EACA;EACA;EACA;EACA;EACA;;;YAIU;UAEF,aAAa,UAAU;;WAEtB;WACA;WACA,OAAO;;WAEP,SAAS,KAAK,MAAM;;iBAGd,cAAc,UAAU,cAAc,qBAAqB,aAAa;WAC9E;WACA;WACA;;WAEA,YAAY,OAAO,SAAS,KAAK,OAAO;;iBAGlC,aAAa,UAAU,cAAc,qBAAqB,aAAa;WAC7E;WACA;;WAEA,UAAU,OAAO,SAAS,KAAK,OAAO,QAAQ;;;;;;;;UAS/C,oBAAoB,UAAU,aAAa,aAAa,aAAa;WACpE;EAET,QAAQ,KAAK;;iBAGE,gBACf,UAAU,cAAc,aACxB,MAAM,iCACE,oBAAoB,GAAG;WACtB;;WAEA,UAAU,OAAO,SAAS,KAAK,OAAO,QAAQ;;iBAGxC,cACf,UAAU,cAAc,aACxB,MAAM,iCACE,oBAAoB,GAAG;WACtB;;WAEA,UAAU,OAAO,SAAS,KAAK,OAA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