@shware/workflow 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +154 -2
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/apns-relay.cjs +105 -0
- package/dist/apns-relay.cjs.map +1 -0
- package/dist/apns-relay.d.cts +28 -0
- package/dist/apns-relay.d.cts.map +1 -0
- package/dist/apns-relay.d.mts +28 -0
- package/dist/apns-relay.d.mts.map +1 -0
- package/dist/apns-relay.mjs +104 -0
- package/dist/apns-relay.mjs.map +1 -0
- package/dist/apns.cjs +121 -0
- package/dist/apns.cjs.map +1 -0
- package/dist/apns.d.cts +63 -0
- package/dist/apns.d.cts.map +1 -0
- package/dist/apns.d.mts +63 -0
- package/dist/apns.d.mts.map +1 -0
- package/dist/apns.mjs +116 -0
- package/dist/apns.mjs.map +1 -0
- package/dist/client.cjs +125 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +108 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.mts +108 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +122 -0
- package/dist/client.mjs.map +1 -0
- package/dist/cloudflare/bindings.cjs +28 -0
- package/dist/cloudflare/bindings.cjs.map +1 -0
- package/dist/cloudflare/bindings.d.cts +144 -0
- package/dist/cloudflare/bindings.d.cts.map +1 -0
- package/dist/cloudflare/bindings.d.mts +144 -0
- package/dist/cloudflare/bindings.d.mts.map +1 -0
- package/dist/cloudflare/bindings.mjs +25 -0
- package/dist/cloudflare/bindings.mjs.map +1 -0
- package/dist/cloudflare/channels.cjs +164 -0
- package/dist/cloudflare/channels.cjs.map +1 -0
- package/dist/cloudflare/channels.d.cts +29 -0
- package/dist/cloudflare/channels.d.cts.map +1 -0
- package/dist/cloudflare/channels.d.mts +29 -0
- package/dist/cloudflare/channels.d.mts.map +1 -0
- package/dist/cloudflare/channels.mjs +161 -0
- package/dist/cloudflare/channels.mjs.map +1 -0
- package/dist/cloudflare/d1-env.cjs +17 -0
- package/dist/cloudflare/d1-env.cjs.map +1 -0
- package/dist/cloudflare/d1-env.d.cts +12 -0
- package/dist/cloudflare/d1-env.d.cts.map +1 -0
- package/dist/cloudflare/d1-env.d.mts +12 -0
- package/dist/cloudflare/d1-env.d.mts.map +1 -0
- package/dist/cloudflare/d1-env.mjs +16 -0
- package/dist/cloudflare/d1-env.mjs.map +1 -0
- package/dist/cloudflare/index.cjs +54 -0
- package/dist/cloudflare/index.d.cts +19 -0
- package/dist/cloudflare/index.d.mts +19 -0
- package/dist/cloudflare/index.mjs +16 -0
- package/dist/cloudflare/router.cjs +516 -0
- package/dist/cloudflare/router.cjs.map +1 -0
- package/dist/cloudflare/router.d.cts +157 -0
- package/dist/cloudflare/router.d.cts.map +1 -0
- package/dist/cloudflare/router.d.mts +157 -0
- package/dist/cloudflare/router.d.mts.map +1 -0
- package/dist/cloudflare/router.mjs +503 -0
- package/dist/cloudflare/router.mjs.map +1 -0
- package/dist/cloudflare/runner.cjs +225 -0
- package/dist/cloudflare/runner.cjs.map +1 -0
- package/dist/cloudflare/runner.d.cts +73 -0
- package/dist/cloudflare/runner.d.cts.map +1 -0
- package/dist/cloudflare/runner.d.mts +73 -0
- package/dist/cloudflare/runner.d.mts.map +1 -0
- package/dist/cloudflare/runner.mjs +224 -0
- package/dist/cloudflare/runner.mjs.map +1 -0
- package/dist/cloudflare/schema.sql +127 -0
- package/dist/cloudflare/senders.cjs +114 -0
- package/dist/cloudflare/senders.cjs.map +1 -0
- package/dist/cloudflare/senders.d.cts +68 -0
- package/dist/cloudflare/senders.d.cts.map +1 -0
- package/dist/cloudflare/senders.d.mts +68 -0
- package/dist/cloudflare/senders.d.mts.map +1 -0
- package/dist/cloudflare/senders.mjs +108 -0
- package/dist/cloudflare/senders.mjs.map +1 -0
- package/dist/cloudflare/worker.cjs +228 -0
- package/dist/cloudflare/worker.cjs.map +1 -0
- package/dist/cloudflare/worker.d.cts +92 -0
- package/dist/cloudflare/worker.d.cts.map +1 -0
- package/dist/cloudflare/worker.d.mts +92 -0
- package/dist/cloudflare/worker.d.mts.map +1 -0
- package/dist/cloudflare/worker.mjs +224 -0
- package/dist/cloudflare/worker.mjs.map +1 -0
- package/dist/cloudflare/workers.d.cjs +0 -0
- package/dist/cloudflare/workers.d.cts +44 -0
- package/dist/cloudflare/workers.d.cts.map +1 -0
- package/dist/cloudflare/workers.d.mts +44 -0
- package/dist/cloudflare/workers.d.mts.map +1 -0
- package/dist/config.cjs +151 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +149 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +149 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +143 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract.cjs +212 -0
- package/dist/contract.cjs.map +1 -0
- package/dist/contract.d.cts +90 -0
- package/dist/contract.d.cts.map +1 -0
- package/dist/contract.d.mts +90 -0
- package/dist/contract.d.mts.map +1 -0
- package/dist/contract.mjs +206 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/dsl/action.cjs +29 -0
- package/dist/dsl/action.cjs.map +1 -0
- package/dist/dsl/action.d.cts +64 -0
- package/dist/dsl/action.d.cts.map +1 -0
- package/dist/dsl/action.d.mts +64 -0
- package/dist/dsl/action.d.mts.map +1 -0
- package/dist/dsl/action.mjs +28 -0
- package/dist/dsl/action.mjs.map +1 -0
- package/dist/dsl/base.cjs +34 -0
- package/dist/dsl/base.cjs.map +1 -0
- package/dist/dsl/base.d.cts +45 -0
- package/dist/dsl/base.d.cts.map +1 -0
- package/dist/dsl/base.d.mts +45 -0
- package/dist/dsl/base.d.mts.map +1 -0
- package/dist/dsl/base.mjs +30 -0
- package/dist/dsl/base.mjs.map +1 -0
- package/dist/dsl/bundle.cjs +207 -0
- package/dist/dsl/bundle.cjs.map +1 -0
- package/dist/dsl/bundle.d.cts +19 -0
- package/dist/dsl/bundle.d.cts.map +1 -0
- package/dist/dsl/bundle.d.mts +19 -0
- package/dist/dsl/bundle.d.mts.map +1 -0
- package/dist/dsl/bundle.mjs +206 -0
- package/dist/dsl/bundle.mjs.map +1 -0
- package/dist/dsl/condition.cjs +177 -0
- package/dist/dsl/condition.cjs.map +1 -0
- package/dist/dsl/condition.d.cts +140 -0
- package/dist/dsl/condition.d.cts.map +1 -0
- package/dist/dsl/condition.d.mts +140 -0
- package/dist/dsl/condition.d.mts.map +1 -0
- package/dist/dsl/condition.mjs +156 -0
- package/dist/dsl/condition.mjs.map +1 -0
- package/dist/dsl/flow.cjs +228 -0
- package/dist/dsl/flow.cjs.map +1 -0
- package/dist/dsl/flow.d.cts +223 -0
- package/dist/dsl/flow.d.cts.map +1 -0
- package/dist/dsl/flow.d.mts +223 -0
- package/dist/dsl/flow.d.mts.map +1 -0
- package/dist/dsl/flow.mjs +226 -0
- package/dist/dsl/flow.mjs.map +1 -0
- package/dist/dsl/index.cjs +38 -0
- package/dist/dsl/index.d.cts +10 -0
- package/dist/dsl/index.d.mts +10 -0
- package/dist/dsl/index.mjs +9 -0
- package/dist/dsl/refs.cjs +59 -0
- package/dist/dsl/refs.cjs.map +1 -0
- package/dist/dsl/refs.d.cts +88 -0
- package/dist/dsl/refs.d.cts.map +1 -0
- package/dist/dsl/refs.d.mts +88 -0
- package/dist/dsl/refs.d.mts.map +1 -0
- package/dist/dsl/refs.mjs +55 -0
- package/dist/dsl/refs.mjs.map +1 -0
- package/dist/dsl/template.cjs +65 -0
- package/dist/dsl/template.cjs.map +1 -0
- package/dist/dsl/template.d.cts +75 -0
- package/dist/dsl/template.d.cts.map +1 -0
- package/dist/dsl/template.d.mts +75 -0
- package/dist/dsl/template.d.mts.map +1 -0
- package/dist/dsl/template.mjs +63 -0
- package/dist/dsl/template.mjs.map +1 -0
- package/dist/dsl/trigger.cjs +40 -0
- package/dist/dsl/trigger.cjs.map +1 -0
- package/dist/dsl/trigger.d.cts +65 -0
- package/dist/dsl/trigger.d.cts.map +1 -0
- package/dist/dsl/trigger.d.mts +65 -0
- package/dist/dsl/trigger.d.mts.map +1 -0
- package/dist/dsl/trigger.mjs +39 -0
- package/dist/dsl/trigger.mjs.map +1 -0
- package/dist/dsl/workflow.cjs +121 -0
- package/dist/dsl/workflow.cjs.map +1 -0
- package/dist/dsl/workflow.d.cts +59 -0
- package/dist/dsl/workflow.d.cts.map +1 -0
- package/dist/dsl/workflow.d.mts +59 -0
- package/dist/dsl/workflow.d.mts.map +1 -0
- package/dist/dsl/workflow.mjs +120 -0
- package/dist/dsl/workflow.mjs.map +1 -0
- package/dist/engine/actions.cjs +27 -0
- package/dist/engine/actions.cjs.map +1 -0
- package/dist/engine/actions.d.cts +40 -0
- package/dist/engine/actions.d.cts.map +1 -0
- package/dist/engine/actions.d.mts +40 -0
- package/dist/engine/actions.d.mts.map +1 -0
- package/dist/engine/actions.mjs +26 -0
- package/dist/engine/actions.mjs.map +1 -0
- package/dist/engine/bucket.cjs +72 -0
- package/dist/engine/bucket.cjs.map +1 -0
- package/dist/engine/bucket.d.cts +32 -0
- package/dist/engine/bucket.d.cts.map +1 -0
- package/dist/engine/bucket.d.mts +32 -0
- package/dist/engine/bucket.d.mts.map +1 -0
- package/dist/engine/bucket.mjs +69 -0
- package/dist/engine/bucket.mjs.map +1 -0
- package/dist/engine/condition.cjs +166 -0
- package/dist/engine/condition.cjs.map +1 -0
- package/dist/engine/condition.d.cts +52 -0
- package/dist/engine/condition.d.cts.map +1 -0
- package/dist/engine/condition.d.mts +52 -0
- package/dist/engine/condition.d.mts.map +1 -0
- package/dist/engine/condition.mjs +161 -0
- package/dist/engine/condition.mjs.map +1 -0
- package/dist/engine/index.cjs +20 -0
- package/dist/engine/index.d.cts +8 -0
- package/dist/engine/index.d.mts +8 -0
- package/dist/engine/index.mjs +7 -0
- package/dist/engine/interpreter.cjs +428 -0
- package/dist/engine/interpreter.cjs.map +1 -0
- package/dist/engine/interpreter.d.cts +6 -0
- package/dist/engine/interpreter.d.cts.map +1 -0
- package/dist/engine/interpreter.d.mts +6 -0
- package/dist/engine/interpreter.d.mts.map +1 -0
- package/dist/engine/interpreter.mjs +427 -0
- package/dist/engine/interpreter.mjs.map +1 -0
- package/dist/engine/ports.cjs +0 -0
- package/dist/engine/ports.d.cts +252 -0
- package/dist/engine/ports.d.cts.map +1 -0
- package/dist/engine/ports.d.mts +252 -0
- package/dist/engine/ports.d.mts.map +1 -0
- package/dist/engine/ports.mjs +1 -0
- package/dist/engine/recipient.cjs +23 -0
- package/dist/engine/recipient.cjs.map +1 -0
- package/dist/engine/recipient.d.cts +13 -0
- package/dist/engine/recipient.d.cts.map +1 -0
- package/dist/engine/recipient.d.mts +13 -0
- package/dist/engine/recipient.d.mts.map +1 -0
- package/dist/engine/recipient.mjs +22 -0
- package/dist/engine/recipient.mjs.map +1 -0
- package/dist/engine/time-scale.cjs +54 -0
- package/dist/engine/time-scale.cjs.map +1 -0
- package/dist/engine/time-scale.d.cts +31 -0
- package/dist/engine/time-scale.d.cts.map +1 -0
- package/dist/engine/time-scale.d.mts +31 -0
- package/dist/engine/time-scale.d.mts.map +1 -0
- package/dist/engine/time-scale.mjs +52 -0
- package/dist/engine/time-scale.mjs.map +1 -0
- package/dist/engine/time-window.cjs +149 -0
- package/dist/engine/time-window.cjs.map +1 -0
- package/dist/engine/time-window.d.cts +22 -0
- package/dist/engine/time-window.d.cts.map +1 -0
- package/dist/engine/time-window.d.mts +22 -0
- package/dist/engine/time-window.d.mts.map +1 -0
- package/dist/engine/time-window.mjs +147 -0
- package/dist/engine/time-window.mjs.map +1 -0
- package/dist/fcm.cjs +125 -0
- package/dist/fcm.cjs.map +1 -0
- package/dist/fcm.d.cts +48 -0
- package/dist/fcm.d.cts.map +1 -0
- package/dist/fcm.d.mts +48 -0
- package/dist/fcm.d.mts.map +1 -0
- package/dist/fcm.mjs +121 -0
- package/dist/fcm.mjs.map +1 -0
- package/dist/hash.cjs +245 -0
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.d.cts +30 -0
- package/dist/hash.d.cts.map +1 -0
- package/dist/hash.d.mts +30 -0
- package/dist/hash.d.mts.map +1 -0
- package/dist/hash.mjs +239 -0
- package/dist/hash.mjs.map +1 -0
- package/dist/index.cjs +100 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +17 -0
- package/dist/ir.cjs +366 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +486 -0
- package/dist/ir.d.cts.map +1 -0
- package/dist/ir.d.mts +486 -0
- package/dist/ir.d.mts.map +1 -0
- package/dist/ir.mjs +344 -0
- package/dist/ir.mjs.map +1 -0
- package/dist/jwt.cjs +22 -0
- package/dist/jwt.cjs.map +1 -0
- package/dist/jwt.d.cts +9 -0
- package/dist/jwt.d.cts.map +1 -0
- package/dist/jwt.d.mts +9 -0
- package/dist/jwt.d.mts.map +1 -0
- package/dist/jwt.mjs +20 -0
- package/dist/jwt.mjs.map +1 -0
- package/dist/plan.cjs +223 -0
- package/dist/plan.cjs.map +1 -0
- package/dist/plan.d.cts +68 -0
- package/dist/plan.d.cts.map +1 -0
- package/dist/plan.d.mts +68 -0
- package/dist/plan.d.mts.map +1 -0
- package/dist/plan.mjs +221 -0
- package/dist/plan.mjs.map +1 -0
- package/dist/postgres-js.cjs +42 -0
- package/dist/postgres-js.cjs.map +1 -0
- package/dist/postgres-js.d.cts +28 -0
- package/dist/postgres-js.d.cts.map +1 -0
- package/dist/postgres-js.d.mts +28 -0
- package/dist/postgres-js.d.mts.map +1 -0
- package/dist/postgres-js.mjs +38 -0
- package/dist/postgres-js.mjs.map +1 -0
- package/dist/provenance.cjs +67 -0
- package/dist/provenance.cjs.map +1 -0
- package/dist/provenance.d.cts +41 -0
- package/dist/provenance.d.cts.map +1 -0
- package/dist/provenance.d.mts +41 -0
- package/dist/provenance.d.mts.map +1 -0
- package/dist/provenance.mjs +65 -0
- package/dist/provenance.mjs.map +1 -0
- package/dist/push.cjs +14 -0
- package/dist/push.cjs.map +1 -0
- package/dist/push.d.cts +16 -0
- package/dist/push.d.cts.map +1 -0
- package/dist/push.d.mts +16 -0
- package/dist/push.d.mts.map +1 -0
- package/dist/push.mjs +13 -0
- package/dist/push.mjs.map +1 -0
- package/dist/react-email.cjs +48 -0
- package/dist/react-email.cjs.map +1 -0
- package/dist/react-email.d.cts +7 -0
- package/dist/react-email.d.cts.map +1 -0
- package/dist/react-email.d.mts +7 -0
- package/dist/react-email.d.mts.map +1 -0
- package/dist/react-email.mjs +47 -0
- package/dist/react-email.mjs.map +1 -0
- package/dist/reporting/classify.cjs +42 -0
- package/dist/reporting/classify.cjs.map +1 -0
- package/dist/reporting/classify.d.cts +60 -0
- package/dist/reporting/classify.d.cts.map +1 -0
- package/dist/reporting/classify.d.mts +60 -0
- package/dist/reporting/classify.d.mts.map +1 -0
- package/dist/reporting/classify.mjs +38 -0
- package/dist/reporting/classify.mjs.map +1 -0
- package/dist/reporting/observer.cjs +63 -0
- package/dist/reporting/observer.cjs.map +1 -0
- package/dist/reporting/observer.d.cts +18 -0
- package/dist/reporting/observer.d.cts.map +1 -0
- package/dist/reporting/observer.d.mts +18 -0
- package/dist/reporting/observer.d.mts.map +1 -0
- package/dist/reporting/observer.mjs +62 -0
- package/dist/reporting/observer.mjs.map +1 -0
- package/dist/reporting/tracking.cjs +153 -0
- package/dist/reporting/tracking.cjs.map +1 -0
- package/dist/reporting/tracking.d.cts +43 -0
- package/dist/reporting/tracking.d.cts.map +1 -0
- package/dist/reporting/tracking.d.mts +43 -0
- package/dist/reporting/tracking.d.mts.map +1 -0
- package/dist/reporting/tracking.mjs +151 -0
- package/dist/reporting/tracking.mjs.map +1 -0
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +30 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.mts +30 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +18 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/store/d1.cjs +185 -0
- package/dist/store/d1.cjs.map +1 -0
- package/dist/store/d1.d.cts +55 -0
- package/dist/store/d1.d.cts.map +1 -0
- package/dist/store/d1.d.mts +55 -0
- package/dist/store/d1.d.mts.map +1 -0
- package/dist/store/d1.mjs +184 -0
- package/dist/store/d1.mjs.map +1 -0
- package/dist/store/facts.cjs +60 -0
- package/dist/store/facts.cjs.map +1 -0
- package/dist/store/facts.d.cts +38 -0
- package/dist/store/facts.d.cts.map +1 -0
- package/dist/store/facts.d.mts +38 -0
- package/dist/store/facts.d.mts.map +1 -0
- package/dist/store/facts.mjs +58 -0
- package/dist/store/facts.mjs.map +1 -0
- package/dist/store/index.cjs +31 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.cts +291 -0
- package/dist/store/index.d.cts.map +1 -0
- package/dist/store/index.d.mts +291 -0
- package/dist/store/index.d.mts.map +1 -0
- package/dist/store/index.mjs +22 -0
- package/dist/store/index.mjs.map +1 -0
- package/dist/store/postgres-reporting.cjs +213 -0
- package/dist/store/postgres-reporting.cjs.map +1 -0
- package/dist/store/postgres-reporting.d.cts +63 -0
- package/dist/store/postgres-reporting.d.cts.map +1 -0
- package/dist/store/postgres-reporting.d.mts +63 -0
- package/dist/store/postgres-reporting.d.mts.map +1 -0
- package/dist/store/postgres-reporting.mjs +212 -0
- package/dist/store/postgres-reporting.mjs.map +1 -0
- package/dist/store/postgres.cjs +309 -0
- package/dist/store/postgres.cjs.map +1 -0
- package/dist/store/postgres.d.cts +77 -0
- package/dist/store/postgres.d.cts.map +1 -0
- package/dist/store/postgres.d.mts +77 -0
- package/dist/store/postgres.d.mts.map +1 -0
- package/dist/store/postgres.mjs +306 -0
- package/dist/store/postgres.mjs.map +1 -0
- package/dist/store/sql.cjs +24 -0
- package/dist/store/sql.cjs.map +1 -0
- package/dist/store/sql.d.cts +25 -0
- package/dist/store/sql.d.cts.map +1 -0
- package/dist/store/sql.d.mts +25 -0
- package/dist/store/sql.d.mts.map +1 -0
- package/dist/store/sql.mjs +23 -0
- package/dist/store/sql.mjs.map +1 -0
- package/dist/store/tables.cjs +404 -0
- package/dist/store/tables.cjs.map +1 -0
- package/dist/store/tables.d.cts +81 -0
- package/dist/store/tables.d.cts.map +1 -0
- package/dist/store/tables.d.mts +81 -0
- package/dist/store/tables.d.mts.map +1 -0
- package/dist/store/tables.mjs +399 -0
- package/dist/store/tables.mjs.map +1 -0
- package/dist/templates.cjs +247 -0
- package/dist/templates.cjs.map +1 -0
- package/dist/templates.d.cts +187 -0
- package/dist/templates.d.cts.map +1 -0
- package/dist/templates.d.mts +187 -0
- package/dist/templates.d.mts.map +1 -0
- package/dist/templates.mjs +230 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/webhooks.cjs +96 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +25 -0
- package/dist/webhooks.d.cts.map +1 -0
- package/dist/webhooks.d.mts +25 -0
- package/dist/webhooks.d.mts.map +1 -0
- package/dist/webhooks.mjs +94 -0
- package/dist/webhooks.mjs.map +1 -0
- package/dist/webpush.cjs +180 -0
- package/dist/webpush.cjs.map +1 -0
- package/dist/webpush.d.cts +53 -0
- package/dist/webpush.d.cts.map +1 -0
- package/dist/webpush.d.mts +53 -0
- package/dist/webpush.d.mts.map +1 -0
- package/dist/webpush.mjs +175 -0
- package/dist/webpush.mjs.map +1 -0
- package/package.json +189 -3
- package/src/cloudflare/schema.sql +127 -0
- package/src/cloudflare/workers.d.ts +44 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_templates = require("../templates.cjs");
|
|
4
|
+
const require_config = require("../config.cjs");
|
|
5
|
+
const require_contract = require("../contract.cjs");
|
|
6
|
+
require("../store/tables.cjs");
|
|
7
|
+
const require_react_email = require("../react-email.cjs");
|
|
8
|
+
const require_reporting_tracking = require("../reporting/tracking.cjs");
|
|
9
|
+
const require_store_index = require("../store/index.cjs");
|
|
10
|
+
const require_cloudflare_d1_env = require("./d1-env.cjs");
|
|
11
|
+
const require_cloudflare_router = require("./router.cjs");
|
|
12
|
+
const require_cloudflare_channels = require("./channels.cjs");
|
|
13
|
+
const require_engine_time_scale = require("../engine/time-scale.cjs");
|
|
14
|
+
const require_cloudflare_runner = require("./runner.cjs");
|
|
15
|
+
const require_reporting_observer = require("../reporting/observer.cjs");
|
|
16
|
+
let zod_mini = require("zod/mini");
|
|
17
|
+
zod_mini = require_runtime.__toESM(zod_mini, 1);
|
|
18
|
+
//#region src/cloudflare/worker.ts
|
|
19
|
+
/**
|
|
20
|
+
* A complete journey host in one call: the runner class with the app's store,
|
|
21
|
+
* outlets and runtime plugged in, and the fetch handler that serves the ingest
|
|
22
|
+
* API around them.
|
|
23
|
+
*
|
|
24
|
+
* const journeys = journeyWorker<Env>({
|
|
25
|
+
* config, // workflow.config.ts (defineConfig)
|
|
26
|
+
* store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database),
|
|
27
|
+
* });
|
|
28
|
+
* export const MyRunner = journeys.Runner;
|
|
29
|
+
* export default { fetch: journeys.fetch };
|
|
30
|
+
*/
|
|
31
|
+
/** The Worker's environment failed its schema (`journeyWorker({ env })`). */
|
|
32
|
+
var EnvValidationError = class extends Error {
|
|
33
|
+
issues;
|
|
34
|
+
name = "EnvValidationError";
|
|
35
|
+
constructor(issues) {
|
|
36
|
+
super(`the Worker's environment is invalid:\n ${issues.join("\n ")}`);
|
|
37
|
+
this.issues = issues;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function journeyWorker(options) {
|
|
41
|
+
const { config } = options;
|
|
42
|
+
const checked = /* @__PURE__ */ new WeakMap();
|
|
43
|
+
const checkEnv = (env) => {
|
|
44
|
+
if (options.env === void 0) return env;
|
|
45
|
+
const cached = checked.get(env);
|
|
46
|
+
if (cached !== void 0) return cached;
|
|
47
|
+
const result = zod_mini.safeParse(options.env, env);
|
|
48
|
+
if (!result.success) throw new EnvValidationError(result.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`));
|
|
49
|
+
const merged = {
|
|
50
|
+
...env,
|
|
51
|
+
...result.data
|
|
52
|
+
};
|
|
53
|
+
checked.set(env, merged);
|
|
54
|
+
return merged;
|
|
55
|
+
};
|
|
56
|
+
const bundle = () => require_config.compileConfig(config);
|
|
57
|
+
const emails = config.templates?.email;
|
|
58
|
+
const database = { schema: config.database?.schema ?? "workflow" };
|
|
59
|
+
const lease = (env) => {
|
|
60
|
+
const opened = options.store === void 0 ? require_cloudflare_d1_env.d1Store(env) : options.store(env, database);
|
|
61
|
+
const noop = async () => {};
|
|
62
|
+
const factor = require_cloudflare_channels.runtimeFromConfig(config, env).timeScale;
|
|
63
|
+
return "store" in opened ? {
|
|
64
|
+
store: require_engine_time_scale.scaleSegmentWindows(opened.store, factor),
|
|
65
|
+
close: opened.close ?? noop
|
|
66
|
+
} : {
|
|
67
|
+
store: require_engine_time_scale.scaleSegmentWindows(opened, factor),
|
|
68
|
+
close: noop
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
class Runner extends require_cloudflare_runner.JourneyRunner {
|
|
72
|
+
leases = /* @__PURE__ */ new WeakMap();
|
|
73
|
+
current;
|
|
74
|
+
createStore() {
|
|
75
|
+
const { store, close } = lease(checkEnv(this.env));
|
|
76
|
+
this.leases.set(store, close);
|
|
77
|
+
this.current = store;
|
|
78
|
+
return store;
|
|
79
|
+
}
|
|
80
|
+
async closeStore(store) {
|
|
81
|
+
await this.leases.get(store)?.();
|
|
82
|
+
}
|
|
83
|
+
contract() {
|
|
84
|
+
return config.contract;
|
|
85
|
+
}
|
|
86
|
+
createMessageValidator() {
|
|
87
|
+
return require_templates.registryValidator(config.templates ?? {});
|
|
88
|
+
}
|
|
89
|
+
createMessageSender() {
|
|
90
|
+
if (this.current === void 0) return super.createMessageSender();
|
|
91
|
+
if (options.messages !== void 0) return options.messages(checkEnv(this.env), this.current);
|
|
92
|
+
return require_cloudflare_channels.channelsFromConfig(config, checkEnv(this.env), { store: this.current });
|
|
93
|
+
}
|
|
94
|
+
createObserver(store) {
|
|
95
|
+
if (options.observer !== void 0) return options.observer(checkEnv(this.env), store);
|
|
96
|
+
return store.reporting === void 0 ? void 0 : require_reporting_observer.reportingObserver(store.reporting, checkEnv(this.env).WORKFLOW_ORIGIN);
|
|
97
|
+
}
|
|
98
|
+
runtime(params) {
|
|
99
|
+
const env = checkEnv(this.env);
|
|
100
|
+
if (options.runtime !== void 0) return options.runtime(env, params);
|
|
101
|
+
return require_cloudflare_channels.runtimeFromConfig(config, env);
|
|
102
|
+
}
|
|
103
|
+
actions() {
|
|
104
|
+
return config.actions ?? [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const json = (body, status = 200) => new Response(JSON.stringify(body), {
|
|
108
|
+
status,
|
|
109
|
+
headers: { "content-type": "application/json" }
|
|
110
|
+
});
|
|
111
|
+
const authorized = (request, env) => env.API_TOKEN === void 0 || request.headers.get("authorization") === `Bearer ${env.API_TOKEN}`;
|
|
112
|
+
const preview = emails === void 0 ? void 0 : require_react_email.registryRenderer(emails);
|
|
113
|
+
const fetch = async (request, rawEnv, ctx) => {
|
|
114
|
+
let env;
|
|
115
|
+
try {
|
|
116
|
+
env = checkEnv(rawEnv);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (!(error instanceof EnvValidationError)) throw error;
|
|
119
|
+
console.error(`[workflow] ${error.message}`);
|
|
120
|
+
return json({ error: error.message }, 500);
|
|
121
|
+
}
|
|
122
|
+
const url = new URL(request.url);
|
|
123
|
+
const { store, close } = lease(env);
|
|
124
|
+
try {
|
|
125
|
+
if (url.pathname.startsWith("/t/") && store.reporting !== void 0) {
|
|
126
|
+
const openedEvent = config.webPush?.openedEvent;
|
|
127
|
+
const tracked = await require_reporting_tracking.handleTracking(request, store.reporting, {
|
|
128
|
+
unsubscribe: config.emails?.unsubscribe,
|
|
129
|
+
product: config.title,
|
|
130
|
+
quickMs: config.emails?.tracking?.quickClickMs,
|
|
131
|
+
pushOpened: openedEvent === void 0 ? void 0 : async ({ messageId, userId, at }) => {
|
|
132
|
+
const payload = { message_id: messageId };
|
|
133
|
+
const contract = config.contract;
|
|
134
|
+
const verdict = contract === void 0 ? void 0 : require_contract.checkEvent(contract, openedEvent, payload);
|
|
135
|
+
if (verdict !== void 0 && !verdict.ok) throw new require_contract.ContractValidationError(openedEvent, verdict.issues);
|
|
136
|
+
await require_cloudflare_router.ingestEvent(env, {
|
|
137
|
+
id: `${openedEvent}:${messageId}`,
|
|
138
|
+
userId,
|
|
139
|
+
event: openedEvent,
|
|
140
|
+
payload: verdict?.data ?? payload,
|
|
141
|
+
ts: at
|
|
142
|
+
}, store);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (tracked !== void 0) return tracked;
|
|
146
|
+
}
|
|
147
|
+
if (url.pathname === "/segments/sweep") {
|
|
148
|
+
if (!authorized(request, env)) return json({ error: "unauthorized" }, 401);
|
|
149
|
+
if (request.method !== "POST") return json({ error: "method not allowed" }, 405);
|
|
150
|
+
return json(await require_cloudflare_router.sweepSegments(env, store));
|
|
151
|
+
}
|
|
152
|
+
if (url.pathname === "/bundle") {
|
|
153
|
+
if (!authorized(request, env)) return json({ error: "unauthorized" }, 401);
|
|
154
|
+
if (request.method !== "GET") return json({ error: "method not allowed" }, 405);
|
|
155
|
+
return json(bundle());
|
|
156
|
+
}
|
|
157
|
+
if (url.pathname === "/bundle/deploy") {
|
|
158
|
+
if (!authorized(request, env)) return json({ error: "unauthorized" }, 401);
|
|
159
|
+
if (request.method !== "POST") return json({ error: "method not allowed" }, 405);
|
|
160
|
+
try {
|
|
161
|
+
return json(await require_cloudflare_router.deployBundle(env, bundle(), store));
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (!(error instanceof require_store_index.SchemaMismatchError)) throw error;
|
|
164
|
+
return json({
|
|
165
|
+
error: error.message,
|
|
166
|
+
problems: error.problems
|
|
167
|
+
}, 503);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (emails !== void 0 && preview !== void 0 && url.pathname.startsWith("/preview/")) {
|
|
171
|
+
if (!authorized(request, env)) return json({ error: "unauthorized" }, 401);
|
|
172
|
+
if (request.method !== "GET") return json({ error: "method not allowed" }, 405);
|
|
173
|
+
const key = url.pathname.slice(9);
|
|
174
|
+
if (!Object.hasOwn(emails, key)) return json({ error: `unknown email template: ${key}` }, 404);
|
|
175
|
+
let props = {};
|
|
176
|
+
try {
|
|
177
|
+
props = JSON.parse(url.searchParams.get("props") ?? "{}");
|
|
178
|
+
} catch {
|
|
179
|
+
return json({ error: "props must be a JSON object" }, 400);
|
|
180
|
+
}
|
|
181
|
+
if (typeof props !== "object" || props === null || Array.isArray(props)) return json({ error: "props must be a JSON object" }, 400);
|
|
182
|
+
try {
|
|
183
|
+
const { subject, html } = await preview(key, props);
|
|
184
|
+
return new Response(html, { headers: {
|
|
185
|
+
"content-type": "text/html; charset=utf-8",
|
|
186
|
+
"x-subject": subject
|
|
187
|
+
} });
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error instanceof require_templates.TemplateValidationError) return json({
|
|
190
|
+
error: error.message,
|
|
191
|
+
issues: error.issues
|
|
192
|
+
}, 400);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return await require_cloudflare_router.handleRequest(request, env, store, {
|
|
197
|
+
contract: config.contract,
|
|
198
|
+
mode: options.contractMode
|
|
199
|
+
});
|
|
200
|
+
} finally {
|
|
201
|
+
if (ctx === void 0) await close();
|
|
202
|
+
else ctx.waitUntil(close());
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const sweep = async (rawEnv) => {
|
|
206
|
+
const env = checkEnv(rawEnv);
|
|
207
|
+
const { store, close } = lease(env);
|
|
208
|
+
try {
|
|
209
|
+
return await require_cloudflare_router.sweepSegments(env, store);
|
|
210
|
+
} finally {
|
|
211
|
+
await close();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const scheduled = async (_controller, env, ctx) => {
|
|
215
|
+
ctx.waitUntil(sweep(env));
|
|
216
|
+
};
|
|
217
|
+
return {
|
|
218
|
+
Runner,
|
|
219
|
+
fetch,
|
|
220
|
+
sweep,
|
|
221
|
+
scheduled
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
exports.EnvValidationError = EnvValidationError;
|
|
226
|
+
exports.journeyWorker = journeyWorker;
|
|
227
|
+
|
|
228
|
+
//# sourceMappingURL=worker.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.cjs","names":["z","compileConfig","d1Store","runtimeFromConfig","scaleSegmentWindows","JourneyRunner","registryValidator","channelsFromConfig","reportingObserver","registryRenderer","handleTracking","checkEvent","ContractValidationError","ingestEvent","sweepSegments","deployBundle","SchemaMismatchError","TemplateValidationError","handleRequest"],"sources":["../../src/cloudflare/worker.ts"],"sourcesContent":["import * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport { type JourneyConfig, compileConfig } from '../config';\nimport { type Contract, ContractValidationError, checkEvent } from '../contract';\nimport type { RegisteredAction } from '../engine/actions';\nimport type { JourneyObserver, MessageSender, MessageValidator } from '../engine/ports';\nimport { scaleSegmentWindows } from '../engine/time-scale';\nimport type { ScalarIR } from '../ir';\nimport { registryRenderer } from '../react-email';\nimport { reportingObserver } from '../reporting/observer';\nimport { handleTracking } from '../reporting/tracking';\nimport type { JourneyRuntimeOptions } from '../runtime';\nimport { type JourneyStore, SchemaMismatchError, type StoreLease } from '../store/index';\nimport { DEFAULT_SCHEMA } from '../store/tables';\nimport { TemplateValidationError, registryValidator } from '../templates';\nimport type { JourneyEnv, JourneyParams } from './bindings';\nimport { channelsFromConfig, runtimeFromConfig } from './channels';\nimport { d1Store } from './d1-env';\nimport {\n type SweepResult,\n deployBundle,\n handleRequest,\n ingestEvent,\n sweepSegments,\n} from './router';\nimport { JourneyRunner } from './runner';\n\n/** The fetch handler's execution context (the subset used). */\nexport interface ExecutionContextLike {\n waitUntil(promise: Promise<unknown>): void;\n}\n\nexport interface JourneyWorkerOptions<Env extends JourneyEnv> {\n /**\n * The project's `workflow.config.ts` (`defineConfig`): what the Worker\n * deploys (`GET /bundle`, `POST /bundle/deploy` serve `compileConfig`), the\n * template registries the senders, the validator and `/preview` render from,\n * the contract every `/events` and `/identify` is checked against, the email\n * envelope, actions, and the runtime / APNs / FCM settings. Secrets come\n * from the env under the names `JourneyEnv` documents.\n */\n config: JourneyConfig;\n /**\n * The data plane, opened per request and per workflow run. Return a\n * `StoreLease` when the client must be released afterwards (a Postgres\n * connection); defaults to D1 + KV from the env's bindings. `database` is\n * the config's (`schema` defaulting to `workflow`), for a Postgres store:\n *\n * store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database)\n */\n store?: (env: Env, database: { schema: string }) => JourneyStore | StoreLease;\n /**\n * Reporting hooks: node arrivals, every copy sent (with the tracking it should carry — click\n * links and an open pixel for email, payload data for a push), and how each instance ended.\n * By default a store that keeps reporting (Postgres) records them itself, and the Worker\n * serves the email tracking routes (`/t/...`, on `WORKFLOW_ORIGIN`); override to report\n * elsewhere.\n */\n observer?: (env: Env, store: JourneyStore) => JourneyObserver;\n /** Message outlet override (tests, a custom gateway); by default the channels the config describes. */\n messages?: (env: Env, store: JourneyStore) => MessageSender;\n /** Per-instance runtime options override (a tester in fast-forward); by default `config.runtime` for `ENVIRONMENT`. */\n runtime?: (env: Env, params: JourneyParams) => JourneyRuntimeOptions;\n /**\n * The host's environment, as a zod schema over its vars and secrets (bindings pass through\n * untouched): checked the first time the Worker runs, so a missing or malformed variable fails\n * there — every problem listed — not at the send that needs it. Webhook templates read their\n * URL from the parsed values: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`.\n */\n env?: core.$ZodType<object>;\n /** 'enforce' (default) answers an event or patch the contract refuses with a 400; 'report' only logs it. */\n contractMode?: 'enforce' | 'report';\n}\n\nexport interface JourneyWorker<Env extends JourneyEnv> {\n /** Export this under the `class_name` of the wrangler `workflows` binding. */\n Runner: new (...args: never[]) => JourneyRunner;\n /** The Worker's fetch handler: `/health`, `/events`, `/identify`, `/devices`, `/messages/opened`, `/segments/sweep`, `/t/*` (email tracking), `/deploy`, `/bundle`, `/bundle/deploy` and `/preview/*`. */\n fetch: (request: Request, env: Env, ctx?: ExecutionContextLike) => Promise<Response>;\n /**\n * The segment sweep (`sweepSegments`): membership of every deployed segment for every known\n * user, the journeys of segments entered by the clock alone (`not(performed(e.login, { within:\n * '7 days' }))` has no event to ride on), and each segment's size. Also served as\n * `POST /segments/sweep`.\n */\n sweep: (env: Env) => Promise<SweepResult>;\n /** The cron trigger's handler: runs the sweep. Export it beside `fetch` with a `triggers.crons` entry. */\n scheduled: (controller: unknown, env: Env, ctx: ExecutionContextLike) => Promise<void>;\n}\n\n/**\n * A complete journey host in one call: the runner class with the app's store,\n * outlets and runtime plugged in, and the fetch handler that serves the ingest\n * API around them.\n *\n * const journeys = journeyWorker<Env>({\n * config, // workflow.config.ts (defineConfig)\n * store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database),\n * });\n * export const MyRunner = journeys.Runner;\n * export default { fetch: journeys.fetch };\n */\n/** The Worker's environment failed its schema (`journeyWorker({ env })`). */\nexport class EnvValidationError extends Error {\n override readonly name = 'EnvValidationError';\n constructor(readonly issues: readonly string[]) {\n super(`the Worker's environment is invalid:\\n ${issues.join('\\n ')}`);\n }\n}\n\nexport function journeyWorker<Env extends JourneyEnv>(\n options: JourneyWorkerOptions<Env>\n): JourneyWorker<Env> {\n const { config } = options;\n // Parsed once per env object: the runtime hands the same one to every request of an isolate\n const checked = new WeakMap<object, Env>();\n const checkEnv = (env: Env): Env => {\n if (options.env === undefined) return env;\n const cached = checked.get(env);\n if (cached !== undefined) return cached;\n const result = z.safeParse(options.env, env);\n if (!result.success) {\n // Names and reasons only: the values are secrets\n throw new EnvValidationError(\n result.error.issues.map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`)\n );\n }\n const merged: Env = { ...env, ...result.data };\n checked.set(env, merged);\n return merged;\n };\n const bundle = () => compileConfig(config);\n const emails = config.templates?.email;\n const database = { schema: config.database?.schema ?? DEFAULT_SCHEMA };\n // In fast-forward, segment windows scale with the journeys reading them (time-scale.ts)\n const lease = (env: Env): Required<StoreLease> => {\n const opened = options.store === undefined ? d1Store(env) : options.store(env, database);\n const noop = async () => {};\n const factor = runtimeFromConfig(config, env).timeScale;\n return 'store' in opened\n ? { store: scaleSegmentWindows(opened.store, factor), close: opened.close ?? noop }\n : { store: scaleSegmentWindows(opened, factor), close: noop };\n };\n\n class Runner extends JourneyRunner {\n private readonly leases = new WeakMap<JourneyStore, () => Promise<void>>();\n private current: JourneyStore | undefined;\n\n protected override createStore(): JourneyStore {\n // A run fails at its start on an invalid environment, not at the send that needs it\n const { store, close } = lease(checkEnv(this.env as Env));\n this.leases.set(store, close);\n this.current = store;\n return store;\n }\n\n protected override async closeStore(store: JourneyStore): Promise<void> {\n await this.leases.get(store)?.();\n }\n\n protected override contract(): Contract | undefined {\n return config.contract;\n }\n\n protected override createMessageValidator(): MessageValidator {\n return registryValidator(config.templates ?? {});\n }\n\n protected override createMessageSender(): MessageSender {\n if (this.current === undefined) return super.createMessageSender();\n if (options.messages !== undefined) {\n return options.messages(checkEnv(this.env as Env), this.current);\n }\n return channelsFromConfig(config, checkEnv(this.env as Env), { store: this.current });\n }\n\n protected override createObserver(store: JourneyStore): JourneyObserver | undefined {\n if (options.observer !== undefined) return options.observer(checkEnv(this.env as Env), store);\n return store.reporting === undefined\n ? undefined\n : reportingObserver(store.reporting, checkEnv(this.env as Env).WORKFLOW_ORIGIN);\n }\n\n protected override runtime(params: JourneyParams): JourneyRuntimeOptions {\n const env = checkEnv(this.env as Env);\n if (options.runtime !== undefined) return options.runtime(env, params);\n return runtimeFromConfig(config, env);\n }\n\n protected override actions(): readonly RegisteredAction[] {\n // An action ref is a registered action structurally: the same object carries name, code and hash\n return config.actions ?? [];\n }\n }\n\n const json = (body: unknown, status = 200): Response =>\n new Response(JSON.stringify(body), {\n status,\n headers: { 'content-type': 'application/json' },\n });\n\n const authorized = (request: Request, env: Env): boolean =>\n env.API_TOKEN === undefined ||\n request.headers.get('authorization') === `Bearer ${env.API_TOKEN}`;\n\n const preview = emails === undefined ? undefined : registryRenderer(emails);\n\n const fetch = async (request: Request, rawEnv: Env, ctx?: ExecutionContextLike) => {\n // Everything below reads the validated environment (the schema's defaults applied)\n let env: Env;\n try {\n env = checkEnv(rawEnv);\n } catch (error) {\n if (!(error instanceof EnvValidationError)) throw error;\n console.error(`[workflow] ${error.message}`);\n return json({ error: error.message }, 500);\n }\n const url = new URL(request.url);\n const { store, close } = lease(env);\n try {\n // Opened by recipients, so no bearer: the routes only record, and redirect to recorded URLs\n if (url.pathname.startsWith('/t/') && store.reporting !== undefined) {\n const openedEvent = config.webPush?.openedEvent;\n const tracked = await handleTracking(request, store.reporting, {\n unsubscribe: config.emails?.unsubscribe,\n product: config.title,\n quickMs: config.emails?.tracking?.quickClickMs,\n pushOpened:\n openedEvent === undefined\n ? undefined\n : async ({ messageId, userId, at }) => {\n const payload: Record<string, unknown> = { message_id: messageId };\n const contract = config.contract;\n const verdict =\n contract === undefined ? undefined : checkEvent(contract, openedEvent, payload);\n if (verdict !== undefined && !verdict.ok) {\n throw new ContractValidationError(openedEvent, verdict.issues);\n }\n // Keyed by the copy: a second tap of the same notification is the same event\n await ingestEvent(\n env,\n {\n id: `${openedEvent}:${messageId}`,\n userId,\n event: openedEvent,\n payload: verdict?.data ?? payload,\n ts: at,\n },\n store\n );\n },\n });\n if (tracked !== undefined) return tracked;\n }\n if (url.pathname === '/segments/sweep') {\n if (!authorized(request, env)) return json({ error: 'unauthorized' }, 401);\n if (request.method !== 'POST') return json({ error: 'method not allowed' }, 405);\n return json(await sweepSegments(env, store));\n }\n if (url.pathname === '/bundle') {\n if (!authorized(request, env)) return json({ error: 'unauthorized' }, 401);\n if (request.method !== 'GET') return json({ error: 'method not allowed' }, 405);\n return json(bundle());\n }\n if (url.pathname === '/bundle/deploy') {\n if (!authorized(request, env)) return json({ error: 'unauthorized' }, 401);\n if (request.method !== 'POST') return json({ error: 'method not allowed' }, 405);\n try {\n return json(await deployBundle(env, bundle(), store));\n } catch (error) {\n if (!(error instanceof SchemaMismatchError)) throw error;\n return json({ error: error.message, problems: error.problems }, 503);\n }\n }\n if (emails !== undefined && preview !== undefined && url.pathname.startsWith('/preview/')) {\n if (!authorized(request, env)) return json({ error: 'unauthorized' }, 401);\n if (request.method !== 'GET') return json({ error: 'method not allowed' }, 405);\n const key = url.pathname.slice('/preview/'.length);\n if (!Object.hasOwn(emails, key))\n return json({ error: `unknown email template: ${key}` }, 404);\n // `?props=<JSON object>`: JSON keeps numbers and booleans typed, which query strings cannot\n let props: unknown = {};\n try {\n props = JSON.parse(url.searchParams.get('props') ?? '{}');\n } catch {\n return json({ error: 'props must be a JSON object' }, 400);\n }\n if (typeof props !== 'object' || props === null || Array.isArray(props)) {\n return json({ error: 'props must be a JSON object' }, 400);\n }\n try {\n const { subject, html } = await preview(key, props as Record<string, ScalarIR>);\n return new Response(html, {\n headers: { 'content-type': 'text/html; charset=utf-8', 'x-subject': subject },\n });\n } catch (error) {\n // The query string is the props: a refusal is the caller's to fix, with the field paths\n if (error instanceof TemplateValidationError) {\n return json({ error: error.message, issues: error.issues }, 400);\n }\n throw error;\n }\n }\n return await handleRequest(request, env, store, {\n contract: config.contract,\n mode: options.contractMode,\n });\n } finally {\n // After the response when the runtime offers waitUntil, inline otherwise (tests).\n if (ctx === undefined) await close();\n else ctx.waitUntil(close());\n }\n };\n\n const sweep = async (rawEnv: Env) => {\n const env = checkEnv(rawEnv);\n const { store, close } = lease(env);\n try {\n return await sweepSegments(env, store);\n } finally {\n await close();\n }\n };\n\n const scheduled = async (_controller: unknown, env: Env, ctx: ExecutionContextLike) => {\n ctx.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C1B;CAEA,OAAO;EAAE;EAAQ;EAAO;EAAO;CAAU;AAC3C"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { JourneyObserver, MessageSender } from "../engine/ports.cjs";
|
|
2
|
+
import { JourneyRuntimeOptions } from "../runtime.cjs";
|
|
3
|
+
import { JourneyConfig } from "../config.cjs";
|
|
4
|
+
import { JourneyEnv, JourneyParams } from "./bindings.cjs";
|
|
5
|
+
import { JourneyStore, StoreLease } from "../store/index.cjs";
|
|
6
|
+
import { SweepResult } from "./router.cjs";
|
|
7
|
+
import { JourneyRunner } from "./runner.cjs";
|
|
8
|
+
import * as core from "zod/v4/core";
|
|
9
|
+
//#region src/cloudflare/worker.d.ts
|
|
10
|
+
/** The fetch handler's execution context (the subset used). */
|
|
11
|
+
export interface ExecutionContextLike {
|
|
12
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
13
|
+
}
|
|
14
|
+
export interface JourneyWorkerOptions<Env extends JourneyEnv> {
|
|
15
|
+
/**
|
|
16
|
+
* The project's `workflow.config.ts` (`defineConfig`): what the Worker
|
|
17
|
+
* deploys (`GET /bundle`, `POST /bundle/deploy` serve `compileConfig`), the
|
|
18
|
+
* template registries the senders, the validator and `/preview` render from,
|
|
19
|
+
* the contract every `/events` and `/identify` is checked against, the email
|
|
20
|
+
* envelope, actions, and the runtime / APNs / FCM settings. Secrets come
|
|
21
|
+
* from the env under the names `JourneyEnv` documents.
|
|
22
|
+
*/
|
|
23
|
+
config: JourneyConfig;
|
|
24
|
+
/**
|
|
25
|
+
* The data plane, opened per request and per workflow run. Return a
|
|
26
|
+
* `StoreLease` when the client must be released afterwards (a Postgres
|
|
27
|
+
* connection); defaults to D1 + KV from the env's bindings. `database` is
|
|
28
|
+
* the config's (`schema` defaulting to `workflow`), for a Postgres store:
|
|
29
|
+
*
|
|
30
|
+
* store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database)
|
|
31
|
+
*/
|
|
32
|
+
store?: (env: Env, database: {
|
|
33
|
+
schema: string;
|
|
34
|
+
}) => JourneyStore | StoreLease;
|
|
35
|
+
/**
|
|
36
|
+
* Reporting hooks: node arrivals, every copy sent (with the tracking it should carry — click
|
|
37
|
+
* links and an open pixel for email, payload data for a push), and how each instance ended.
|
|
38
|
+
* By default a store that keeps reporting (Postgres) records them itself, and the Worker
|
|
39
|
+
* serves the email tracking routes (`/t/...`, on `WORKFLOW_ORIGIN`); override to report
|
|
40
|
+
* elsewhere.
|
|
41
|
+
*/
|
|
42
|
+
observer?: (env: Env, store: JourneyStore) => JourneyObserver;
|
|
43
|
+
/** Message outlet override (tests, a custom gateway); by default the channels the config describes. */
|
|
44
|
+
messages?: (env: Env, store: JourneyStore) => MessageSender;
|
|
45
|
+
/** Per-instance runtime options override (a tester in fast-forward); by default `config.runtime` for `ENVIRONMENT`. */
|
|
46
|
+
runtime?: (env: Env, params: JourneyParams) => JourneyRuntimeOptions;
|
|
47
|
+
/**
|
|
48
|
+
* The host's environment, as a zod schema over its vars and secrets (bindings pass through
|
|
49
|
+
* untouched): checked the first time the Worker runs, so a missing or malformed variable fails
|
|
50
|
+
* there — every problem listed — not at the send that needs it. Webhook templates read their
|
|
51
|
+
* URL from the parsed values: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`.
|
|
52
|
+
*/
|
|
53
|
+
env?: core.$ZodType<object>;
|
|
54
|
+
/** 'enforce' (default) answers an event or patch the contract refuses with a 400; 'report' only logs it. */
|
|
55
|
+
contractMode?: 'enforce' | 'report';
|
|
56
|
+
}
|
|
57
|
+
export interface JourneyWorker<Env extends JourneyEnv> {
|
|
58
|
+
/** Export this under the `class_name` of the wrangler `workflows` binding. */
|
|
59
|
+
Runner: new (...args: never[]) => JourneyRunner;
|
|
60
|
+
/** The Worker's fetch handler: `/health`, `/events`, `/identify`, `/devices`, `/messages/opened`, `/segments/sweep`, `/t/*` (email tracking), `/deploy`, `/bundle`, `/bundle/deploy` and `/preview/*`. */
|
|
61
|
+
fetch: (request: Request, env: Env, ctx?: ExecutionContextLike) => Promise<Response>;
|
|
62
|
+
/**
|
|
63
|
+
* The segment sweep (`sweepSegments`): membership of every deployed segment for every known
|
|
64
|
+
* user, the journeys of segments entered by the clock alone (`not(performed(e.login, { within:
|
|
65
|
+
* '7 days' }))` has no event to ride on), and each segment's size. Also served as
|
|
66
|
+
* `POST /segments/sweep`.
|
|
67
|
+
*/
|
|
68
|
+
sweep: (env: Env) => Promise<SweepResult>;
|
|
69
|
+
/** The cron trigger's handler: runs the sweep. Export it beside `fetch` with a `triggers.crons` entry. */
|
|
70
|
+
scheduled: (controller: unknown, env: Env, ctx: ExecutionContextLike) => Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A complete journey host in one call: the runner class with the app's store,
|
|
74
|
+
* outlets and runtime plugged in, and the fetch handler that serves the ingest
|
|
75
|
+
* API around them.
|
|
76
|
+
*
|
|
77
|
+
* const journeys = journeyWorker<Env>({
|
|
78
|
+
* config, // workflow.config.ts (defineConfig)
|
|
79
|
+
* store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database),
|
|
80
|
+
* });
|
|
81
|
+
* export const MyRunner = journeys.Runner;
|
|
82
|
+
* export default { fetch: journeys.fetch };
|
|
83
|
+
*/
|
|
84
|
+
/** The Worker's environment failed its schema (`journeyWorker({ env })`). */
|
|
85
|
+
export declare class EnvValidationError extends Error {
|
|
86
|
+
readonly issues: readonly string[];
|
|
87
|
+
readonly name = "EnvValidationError";
|
|
88
|
+
constructor(issues: readonly string[]);
|
|
89
|
+
}
|
|
90
|
+
export declare function journeyWorker<Env extends JourneyEnv>(options: JourneyWorkerOptions<Env>): JourneyWorker<Env>;
|
|
91
|
+
//#endregion
|
|
92
|
+
//# sourceMappingURL=worker.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.cts","names":[],"sources":["../../src/cloudflare/worker.ts"],"mappings":";;;;;;;;;;iBA4BiB;EACf,UAAU,SAAS;;iBAGJ,qBAAqB,YAAY;;;;;;;;;EAShD,QAAQ;;;;;;;;;EASR,SAAS,KAAK,KAAK;IAAY;QAAqB,eAAe;;;;;;;;EAQnE,YAAY,KAAK,KAAK,OAAO,iBAAiB;;EAE9C,YAAY,KAAK,KAAK,OAAO,iBAAiB;;EAE9C,WAAW,KAAK,KAAK,QAAQ,kBAAkB;;;;;;;EAO/C,MAAM,KAAK;;EAEX;;iBAGe,cAAc,YAAY;;EAEzC,gBAAgB,kBAAkB;;EAElC,QAAQ,SAAS,SAAS,KAAK,KAAK,MAAM,yBAAyB,QAAQ;;;;;;;EAO3E,QAAQ,KAAK,QAAQ,QAAQ;;EAE7B,YAAY,qBAAqB,KAAK,KAAK,KAAK,yBAAyB;;;;;;;;;;;;;;;qBAgB9D,2BAA2B;WAEjB;WADH;EAClB,YAAqB;;wBAKP,cAAc,YAAY,YACxC,SAAS,qBAAqB,OAC7B,cAAc"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { JourneyObserver, MessageSender } from "../engine/ports.mjs";
|
|
2
|
+
import { JourneyRuntimeOptions } from "../runtime.mjs";
|
|
3
|
+
import { JourneyConfig } from "../config.mjs";
|
|
4
|
+
import { JourneyEnv, JourneyParams } from "./bindings.mjs";
|
|
5
|
+
import { JourneyStore, StoreLease } from "../store/index.mjs";
|
|
6
|
+
import { SweepResult } from "./router.mjs";
|
|
7
|
+
import { JourneyRunner } from "./runner.mjs";
|
|
8
|
+
import * as core from "zod/v4/core";
|
|
9
|
+
//#region src/cloudflare/worker.d.ts
|
|
10
|
+
/** The fetch handler's execution context (the subset used). */
|
|
11
|
+
export interface ExecutionContextLike {
|
|
12
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
13
|
+
}
|
|
14
|
+
export interface JourneyWorkerOptions<Env extends JourneyEnv> {
|
|
15
|
+
/**
|
|
16
|
+
* The project's `workflow.config.ts` (`defineConfig`): what the Worker
|
|
17
|
+
* deploys (`GET /bundle`, `POST /bundle/deploy` serve `compileConfig`), the
|
|
18
|
+
* template registries the senders, the validator and `/preview` render from,
|
|
19
|
+
* the contract every `/events` and `/identify` is checked against, the email
|
|
20
|
+
* envelope, actions, and the runtime / APNs / FCM settings. Secrets come
|
|
21
|
+
* from the env under the names `JourneyEnv` documents.
|
|
22
|
+
*/
|
|
23
|
+
config: JourneyConfig;
|
|
24
|
+
/**
|
|
25
|
+
* The data plane, opened per request and per workflow run. Return a
|
|
26
|
+
* `StoreLease` when the client must be released afterwards (a Postgres
|
|
27
|
+
* connection); defaults to D1 + KV from the env's bindings. `database` is
|
|
28
|
+
* the config's (`schema` defaulting to `workflow`), for a Postgres store:
|
|
29
|
+
*
|
|
30
|
+
* store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database)
|
|
31
|
+
*/
|
|
32
|
+
store?: (env: Env, database: {
|
|
33
|
+
schema: string;
|
|
34
|
+
}) => JourneyStore | StoreLease;
|
|
35
|
+
/**
|
|
36
|
+
* Reporting hooks: node arrivals, every copy sent (with the tracking it should carry — click
|
|
37
|
+
* links and an open pixel for email, payload data for a push), and how each instance ended.
|
|
38
|
+
* By default a store that keeps reporting (Postgres) records them itself, and the Worker
|
|
39
|
+
* serves the email tracking routes (`/t/...`, on `WORKFLOW_ORIGIN`); override to report
|
|
40
|
+
* elsewhere.
|
|
41
|
+
*/
|
|
42
|
+
observer?: (env: Env, store: JourneyStore) => JourneyObserver;
|
|
43
|
+
/** Message outlet override (tests, a custom gateway); by default the channels the config describes. */
|
|
44
|
+
messages?: (env: Env, store: JourneyStore) => MessageSender;
|
|
45
|
+
/** Per-instance runtime options override (a tester in fast-forward); by default `config.runtime` for `ENVIRONMENT`. */
|
|
46
|
+
runtime?: (env: Env, params: JourneyParams) => JourneyRuntimeOptions;
|
|
47
|
+
/**
|
|
48
|
+
* The host's environment, as a zod schema over its vars and secrets (bindings pass through
|
|
49
|
+
* untouched): checked the first time the Worker runs, so a missing or malformed variable fails
|
|
50
|
+
* there — every problem listed — not at the send that needs it. Webhook templates read their
|
|
51
|
+
* URL from the parsed values: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`.
|
|
52
|
+
*/
|
|
53
|
+
env?: core.$ZodType<object>;
|
|
54
|
+
/** 'enforce' (default) answers an event or patch the contract refuses with a 400; 'report' only logs it. */
|
|
55
|
+
contractMode?: 'enforce' | 'report';
|
|
56
|
+
}
|
|
57
|
+
export interface JourneyWorker<Env extends JourneyEnv> {
|
|
58
|
+
/** Export this under the `class_name` of the wrangler `workflows` binding. */
|
|
59
|
+
Runner: new (...args: never[]) => JourneyRunner;
|
|
60
|
+
/** The Worker's fetch handler: `/health`, `/events`, `/identify`, `/devices`, `/messages/opened`, `/segments/sweep`, `/t/*` (email tracking), `/deploy`, `/bundle`, `/bundle/deploy` and `/preview/*`. */
|
|
61
|
+
fetch: (request: Request, env: Env, ctx?: ExecutionContextLike) => Promise<Response>;
|
|
62
|
+
/**
|
|
63
|
+
* The segment sweep (`sweepSegments`): membership of every deployed segment for every known
|
|
64
|
+
* user, the journeys of segments entered by the clock alone (`not(performed(e.login, { within:
|
|
65
|
+
* '7 days' }))` has no event to ride on), and each segment's size. Also served as
|
|
66
|
+
* `POST /segments/sweep`.
|
|
67
|
+
*/
|
|
68
|
+
sweep: (env: Env) => Promise<SweepResult>;
|
|
69
|
+
/** The cron trigger's handler: runs the sweep. Export it beside `fetch` with a `triggers.crons` entry. */
|
|
70
|
+
scheduled: (controller: unknown, env: Env, ctx: ExecutionContextLike) => Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A complete journey host in one call: the runner class with the app's store,
|
|
74
|
+
* outlets and runtime plugged in, and the fetch handler that serves the ingest
|
|
75
|
+
* API around them.
|
|
76
|
+
*
|
|
77
|
+
* const journeys = journeyWorker<Env>({
|
|
78
|
+
* config, // workflow.config.ts (defineConfig)
|
|
79
|
+
* store: (env, database) => postgresJsStore(env.HYPERDRIVE.connectionString, database),
|
|
80
|
+
* });
|
|
81
|
+
* export const MyRunner = journeys.Runner;
|
|
82
|
+
* export default { fetch: journeys.fetch };
|
|
83
|
+
*/
|
|
84
|
+
/** The Worker's environment failed its schema (`journeyWorker({ env })`). */
|
|
85
|
+
export declare class EnvValidationError extends Error {
|
|
86
|
+
readonly issues: readonly string[];
|
|
87
|
+
readonly name = "EnvValidationError";
|
|
88
|
+
constructor(issues: readonly string[]);
|
|
89
|
+
}
|
|
90
|
+
export declare function journeyWorker<Env extends JourneyEnv>(options: JourneyWorkerOptions<Env>): JourneyWorker<Env>;
|
|
91
|
+
//#endregion
|
|
92
|
+
//# sourceMappingURL=worker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.mts","names":[],"sources":["../../src/cloudflare/worker.ts"],"mappings":";;;;;;;;;;iBA4BiB;EACf,UAAU,SAAS;;iBAGJ,qBAAqB,YAAY;;;;;;;;;EAShD,QAAQ;;;;;;;;;EASR,SAAS,KAAK,KAAK;IAAY;QAAqB,eAAe;;;;;;;;EAQnE,YAAY,KAAK,KAAK,OAAO,iBAAiB;;EAE9C,YAAY,KAAK,KAAK,OAAO,iBAAiB;;EAE9C,WAAW,KAAK,KAAK,QAAQ,kBAAkB;;;;;;;EAO/C,MAAM,KAAK;;EAEX;;iBAGe,cAAc,YAAY;;EAEzC,gBAAgB,kBAAkB;;EAElC,QAAQ,SAAS,SAAS,KAAK,KAAK,MAAM,yBAAyB,QAAQ;;;;;;;EAO3E,QAAQ,KAAK,QAAQ,QAAQ;;EAE7B,YAAY,qBAAqB,KAAK,KAAK,KAAK,yBAAyB;;;;;;;;;;;;;;;qBAgB9D,2BAA2B;WAEjB;WADH;EAClB,YAAqB;;wBAKP,cAAc,YAAY,YACxC,SAAS,qBAAqB,OAC7B,cAAc"}
|