sendwend 0.0.1 → 12.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +2065 -22
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/apns-relay.cjs +91 -0
- package/dist/apns-relay.cjs.map +1 -0
- package/dist/apns-relay.d.cts +26 -0
- package/dist/apns-relay.d.cts.map +1 -0
- package/dist/apns-relay.d.mts +26 -0
- package/dist/apns-relay.d.mts.map +1 -0
- package/dist/apns-relay.mjs +90 -0
- package/dist/apns-relay.mjs.map +1 -0
- package/dist/apns.cjs +215 -0
- package/dist/apns.cjs.map +1 -0
- package/dist/apns.d.cts +110 -0
- package/dist/apns.d.cts.map +1 -0
- package/dist/apns.d.mts +110 -0
- package/dist/apns.d.mts.map +1 -0
- package/dist/apns.mjs +207 -0
- package/dist/apns.mjs.map +1 -0
- package/dist/aws/engine-step.cjs +105 -0
- package/dist/aws/engine-step.cjs.map +1 -0
- package/dist/aws/engine-step.d.cts +42 -0
- package/dist/aws/engine-step.d.cts.map +1 -0
- package/dist/aws/engine-step.d.mts +42 -0
- package/dist/aws/engine-step.d.mts.map +1 -0
- package/dist/aws/engine-step.mjs +103 -0
- package/dist/aws/engine-step.mjs.map +1 -0
- package/dist/aws/function-url.cjs +53 -0
- package/dist/aws/function-url.cjs.map +1 -0
- package/dist/aws/function-url.d.cts +36 -0
- package/dist/aws/function-url.d.cts.map +1 -0
- package/dist/aws/function-url.d.mts +36 -0
- package/dist/aws/function-url.d.mts.map +1 -0
- package/dist/aws/function-url.mjs +50 -0
- package/dist/aws/function-url.mjs.map +1 -0
- package/dist/aws/index.cjs +232 -0
- package/dist/aws/index.cjs.map +1 -0
- package/dist/aws/index.d.cts +73 -0
- package/dist/aws/index.d.cts.map +1 -0
- package/dist/aws/index.d.mts +73 -0
- package/dist/aws/index.d.mts.map +1 -0
- package/dist/aws/index.mjs +218 -0
- package/dist/aws/index.mjs.map +1 -0
- package/dist/aws/instances.cjs +218 -0
- package/dist/aws/instances.cjs.map +1 -0
- package/dist/aws/instances.d.cts +102 -0
- package/dist/aws/instances.d.cts.map +1 -0
- package/dist/aws/instances.d.mts +102 -0
- package/dist/aws/instances.d.mts.map +1 -0
- package/dist/aws/instances.mjs +214 -0
- package/dist/aws/instances.mjs.map +1 -0
- package/dist/aws/lambda-api.cjs +86 -0
- package/dist/aws/lambda-api.cjs.map +1 -0
- package/dist/aws/lambda-api.d.cts +41 -0
- package/dist/aws/lambda-api.d.cts.map +1 -0
- package/dist/aws/lambda-api.d.mts +41 -0
- package/dist/aws/lambda-api.d.mts.map +1 -0
- package/dist/aws/lambda-api.mjs +85 -0
- package/dist/aws/lambda-api.mjs.map +1 -0
- package/dist/client.cjs +216 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +193 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.mts +193 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +212 -0
- package/dist/client.mjs.map +1 -0
- package/dist/cloudflare/bindings.cjs +49 -0
- package/dist/cloudflare/bindings.cjs.map +1 -0
- package/dist/cloudflare/bindings.d.cts +31 -0
- package/dist/cloudflare/bindings.d.cts.map +1 -0
- package/dist/cloudflare/bindings.d.mts +31 -0
- package/dist/cloudflare/bindings.d.mts.map +1 -0
- package/dist/cloudflare/bindings.mjs +46 -0
- package/dist/cloudflare/bindings.mjs.map +1 -0
- package/dist/cloudflare/index.cjs +73 -0
- package/dist/cloudflare/index.d.cts +25 -0
- package/dist/cloudflare/index.d.mts +25 -0
- package/dist/cloudflare/index.mjs +20 -0
- package/dist/cloudflare/runner.cjs +200 -0
- package/dist/cloudflare/runner.cjs.map +1 -0
- package/dist/cloudflare/runner.d.cts +83 -0
- package/dist/cloudflare/runner.d.cts.map +1 -0
- package/dist/cloudflare/runner.d.mts +83 -0
- package/dist/cloudflare/runner.d.mts.map +1 -0
- package/dist/cloudflare/runner.mjs +199 -0
- package/dist/cloudflare/runner.mjs.map +1 -0
- package/dist/cloudflare/worker.cjs +106 -0
- package/dist/cloudflare/worker.cjs.map +1 -0
- package/dist/cloudflare/worker.d.cts +52 -0
- package/dist/cloudflare/worker.d.cts.map +1 -0
- package/dist/cloudflare/worker.d.mts +52 -0
- package/dist/cloudflare/worker.d.mts.map +1 -0
- package/dist/cloudflare/worker.mjs +104 -0
- package/dist/cloudflare/worker.mjs.map +1 -0
- package/dist/cloudflare/workers.d.cjs +0 -0
- package/dist/cloudflare/workers.d.cts +42 -0
- package/dist/cloudflare/workers.d.cts.map +1 -0
- package/dist/cloudflare/workers.d.mts +42 -0
- package/dist/cloudflare/workers.d.mts.map +1 -0
- package/dist/config.cjs +257 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +184 -0
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +184 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +246 -0
- package/dist/config.mjs.map +1 -0
- package/dist/contract.cjs +222 -0
- package/dist/contract.cjs.map +1 -0
- package/dist/contract.d.cts +110 -0
- package/dist/contract.d.cts.map +1 -0
- package/dist/contract.d.mts +110 -0
- package/dist/contract.d.mts.map +1 -0
- package/dist/contract.mjs +216 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/date-time.cjs +22 -0
- package/dist/date-time.cjs.map +1 -0
- package/dist/date-time.d.cts +10 -0
- package/dist/date-time.d.cts.map +1 -0
- package/dist/date-time.d.mts +10 -0
- package/dist/date-time.d.mts.map +1 -0
- package/dist/date-time.mjs +21 -0
- package/dist/date-time.mjs.map +1 -0
- package/dist/dsl/action.cjs +25 -0
- package/dist/dsl/action.cjs.map +1 -0
- package/dist/dsl/action.d.cts +63 -0
- package/dist/dsl/action.d.cts.map +1 -0
- package/dist/dsl/action.d.mts +63 -0
- package/dist/dsl/action.d.mts.map +1 -0
- package/dist/dsl/action.mjs +24 -0
- package/dist/dsl/action.mjs.map +1 -0
- package/dist/dsl/base.cjs +33 -0
- package/dist/dsl/base.cjs.map +1 -0
- package/dist/dsl/base.d.cts +43 -0
- package/dist/dsl/base.d.cts.map +1 -0
- package/dist/dsl/base.d.mts +43 -0
- package/dist/dsl/base.d.mts.map +1 -0
- package/dist/dsl/base.mjs +29 -0
- package/dist/dsl/base.mjs.map +1 -0
- package/dist/dsl/bundle.cjs +287 -0
- package/dist/dsl/bundle.cjs.map +1 -0
- package/dist/dsl/bundle.d.cts +33 -0
- package/dist/dsl/bundle.d.cts.map +1 -0
- package/dist/dsl/bundle.d.mts +33 -0
- package/dist/dsl/bundle.d.mts.map +1 -0
- package/dist/dsl/bundle.mjs +284 -0
- package/dist/dsl/bundle.mjs.map +1 -0
- package/dist/dsl/condition.cjs +200 -0
- package/dist/dsl/condition.cjs.map +1 -0
- package/dist/dsl/condition.d.cts +151 -0
- package/dist/dsl/condition.d.cts.map +1 -0
- package/dist/dsl/condition.d.mts +151 -0
- package/dist/dsl/condition.d.mts.map +1 -0
- package/dist/dsl/condition.mjs +178 -0
- package/dist/dsl/condition.mjs.map +1 -0
- package/dist/dsl/flow.cjs +335 -0
- package/dist/dsl/flow.cjs.map +1 -0
- package/dist/dsl/flow.d.cts +278 -0
- package/dist/dsl/flow.d.cts.map +1 -0
- package/dist/dsl/flow.d.mts +278 -0
- package/dist/dsl/flow.d.mts.map +1 -0
- package/dist/dsl/flow.mjs +331 -0
- package/dist/dsl/flow.mjs.map +1 -0
- package/dist/dsl/index.cjs +37 -0
- package/dist/dsl/index.d.cts +34 -0
- package/dist/dsl/index.d.mts +34 -0
- package/dist/dsl/index.mjs +9 -0
- package/dist/dsl/refs.cjs +101 -0
- package/dist/dsl/refs.cjs.map +1 -0
- package/dist/dsl/refs.d.cts +127 -0
- package/dist/dsl/refs.d.cts.map +1 -0
- package/dist/dsl/refs.d.mts +127 -0
- package/dist/dsl/refs.d.mts.map +1 -0
- package/dist/dsl/refs.mjs +93 -0
- package/dist/dsl/refs.mjs.map +1 -0
- package/dist/dsl/template.cjs +19 -0
- package/dist/dsl/template.cjs.map +1 -0
- package/dist/dsl/template.d.cts +30 -0
- package/dist/dsl/template.d.cts.map +1 -0
- package/dist/dsl/template.d.mts +30 -0
- package/dist/dsl/template.d.mts.map +1 -0
- package/dist/dsl/template.mjs +18 -0
- package/dist/dsl/template.mjs.map +1 -0
- package/dist/dsl/trigger.cjs +53 -0
- package/dist/dsl/trigger.cjs.map +1 -0
- package/dist/dsl/trigger.d.cts +112 -0
- package/dist/dsl/trigger.d.cts.map +1 -0
- package/dist/dsl/trigger.d.mts +112 -0
- package/dist/dsl/trigger.d.mts.map +1 -0
- package/dist/dsl/trigger.mjs +52 -0
- package/dist/dsl/trigger.mjs.map +1 -0
- package/dist/dsl/workflow.cjs +143 -0
- package/dist/dsl/workflow.cjs.map +1 -0
- package/dist/dsl/workflow.d.cts +88 -0
- package/dist/dsl/workflow.d.cts.map +1 -0
- package/dist/dsl/workflow.d.mts +88 -0
- package/dist/dsl/workflow.d.mts.map +1 -0
- package/dist/dsl/workflow.mjs +142 -0
- package/dist/dsl/workflow.mjs.map +1 -0
- package/dist/email-context.cjs +28 -0
- package/dist/email-context.cjs.map +1 -0
- package/dist/email-context.d.cts +9 -0
- package/dist/email-context.d.cts.map +1 -0
- package/dist/email-context.d.mts +9 -0
- package/dist/email-context.d.mts.map +1 -0
- package/dist/email-context.mjs +26 -0
- package/dist/email-context.mjs.map +1 -0
- package/dist/email-sender.cjs +93 -0
- package/dist/email-sender.cjs.map +1 -0
- package/dist/email-sender.d.cts +88 -0
- package/dist/email-sender.d.cts.map +1 -0
- package/dist/email-sender.d.mts +88 -0
- package/dist/email-sender.d.mts.map +1 -0
- package/dist/email-sender.mjs +90 -0
- package/dist/email-sender.mjs.map +1 -0
- package/dist/email.cjs +73 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +59 -0
- package/dist/email.d.cts.map +1 -0
- package/dist/email.d.mts +59 -0
- package/dist/email.d.mts.map +1 -0
- package/dist/email.mjs +68 -0
- package/dist/email.mjs.map +1 -0
- package/dist/engine/actions.cjs +19 -0
- package/dist/engine/actions.cjs.map +1 -0
- package/dist/engine/actions.d.cts +27 -0
- package/dist/engine/actions.d.cts.map +1 -0
- package/dist/engine/actions.d.mts +27 -0
- package/dist/engine/actions.d.mts.map +1 -0
- package/dist/engine/actions.mjs +18 -0
- package/dist/engine/actions.mjs.map +1 -0
- package/dist/engine/bucket.cjs +71 -0
- package/dist/engine/bucket.cjs.map +1 -0
- package/dist/engine/bucket.d.cts +30 -0
- package/dist/engine/bucket.d.cts.map +1 -0
- package/dist/engine/bucket.d.mts +30 -0
- package/dist/engine/bucket.d.mts.map +1 -0
- package/dist/engine/bucket.mjs +68 -0
- package/dist/engine/bucket.mjs.map +1 -0
- package/dist/engine/condition.cjs +199 -0
- package/dist/engine/condition.cjs.map +1 -0
- package/dist/engine/condition.d.cts +76 -0
- package/dist/engine/condition.d.cts.map +1 -0
- package/dist/engine/condition.d.mts +76 -0
- package/dist/engine/condition.d.mts.map +1 -0
- package/dist/engine/condition.mjs +192 -0
- package/dist/engine/condition.mjs.map +1 -0
- package/dist/engine/duration.cjs +33 -0
- package/dist/engine/duration.cjs.map +1 -0
- package/dist/engine/duration.d.cts +3 -0
- package/dist/engine/duration.d.cts.map +1 -0
- package/dist/engine/duration.d.mts +3 -0
- package/dist/engine/duration.d.mts.map +1 -0
- package/dist/engine/duration.mjs +32 -0
- package/dist/engine/duration.mjs.map +1 -0
- package/dist/engine/index.cjs +33 -0
- package/dist/engine/index.d.cts +10 -0
- package/dist/engine/index.d.mts +10 -0
- package/dist/engine/index.mjs +9 -0
- package/dist/engine/interpreter.cjs +613 -0
- package/dist/engine/interpreter.cjs.map +1 -0
- package/dist/engine/interpreter.d.cts +4 -0
- package/dist/engine/interpreter.d.cts.map +1 -0
- package/dist/engine/interpreter.d.mts +4 -0
- package/dist/engine/interpreter.d.mts.map +1 -0
- package/dist/engine/interpreter.mjs +612 -0
- package/dist/engine/interpreter.mjs.map +1 -0
- package/dist/engine/ports.cjs +0 -0
- package/dist/engine/ports.d.cts +373 -0
- package/dist/engine/ports.d.cts.map +1 -0
- package/dist/engine/ports.d.mts +373 -0
- package/dist/engine/ports.d.mts.map +1 -0
- package/dist/engine/ports.mjs +1 -0
- package/dist/engine/recipient.cjs +22 -0
- package/dist/engine/recipient.cjs.map +1 -0
- package/dist/engine/recipient.d.cts +11 -0
- package/dist/engine/recipient.d.cts.map +1 -0
- package/dist/engine/recipient.d.mts +11 -0
- package/dist/engine/recipient.d.mts.map +1 -0
- package/dist/engine/recipient.mjs +21 -0
- package/dist/engine/recipient.mjs.map +1 -0
- package/dist/engine/retry.cjs +106 -0
- package/dist/engine/retry.cjs.map +1 -0
- package/dist/engine/retry.d.cts +73 -0
- package/dist/engine/retry.d.cts.map +1 -0
- package/dist/engine/retry.d.mts +73 -0
- package/dist/engine/retry.d.mts.map +1 -0
- package/dist/engine/retry.mjs +98 -0
- package/dist/engine/retry.mjs.map +1 -0
- package/dist/engine/time-scale.cjs +153 -0
- package/dist/engine/time-scale.cjs.map +1 -0
- package/dist/engine/time-scale.d.cts +41 -0
- package/dist/engine/time-scale.d.cts.map +1 -0
- package/dist/engine/time-scale.d.mts +41 -0
- package/dist/engine/time-scale.d.mts.map +1 -0
- package/dist/engine/time-scale.mjs +150 -0
- package/dist/engine/time-scale.mjs.map +1 -0
- package/dist/engine/time-window.cjs +148 -0
- package/dist/engine/time-window.cjs.map +1 -0
- package/dist/engine/time-window.d.cts +20 -0
- package/dist/engine/time-window.d.cts.map +1 -0
- package/dist/engine/time-window.d.mts +20 -0
- package/dist/engine/time-window.d.mts.map +1 -0
- package/dist/engine/time-window.mjs +146 -0
- package/dist/engine/time-window.mjs.map +1 -0
- package/dist/fcm.cjs +208 -0
- package/dist/fcm.cjs.map +1 -0
- package/dist/fcm.d.cts +89 -0
- package/dist/fcm.d.cts.map +1 -0
- package/dist/fcm.d.mts +89 -0
- package/dist/fcm.d.mts.map +1 -0
- package/dist/fcm.mjs +202 -0
- package/dist/fcm.mjs.map +1 -0
- package/dist/hash.cjs +244 -0
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.d.cts +28 -0
- package/dist/hash.d.cts.map +1 -0
- package/dist/hash.d.mts +28 -0
- package/dist/hash.d.mts.map +1 -0
- package/dist/hash.mjs +238 -0
- package/dist/hash.mjs.map +1 -0
- package/dist/host/auth.cjs +48 -0
- package/dist/host/auth.cjs.map +1 -0
- package/dist/host/auth.d.cts +33 -0
- package/dist/host/auth.d.cts.map +1 -0
- package/dist/host/auth.d.mts +33 -0
- package/dist/host/auth.d.mts.map +1 -0
- package/dist/host/auth.mjs +45 -0
- package/dist/host/auth.mjs.map +1 -0
- package/dist/host/batch.cjs +178 -0
- package/dist/host/batch.cjs.map +1 -0
- package/dist/host/batch.d.cts +92 -0
- package/dist/host/batch.d.cts.map +1 -0
- package/dist/host/batch.d.mts +92 -0
- package/dist/host/batch.d.mts.map +1 -0
- package/dist/host/batch.mjs +169 -0
- package/dist/host/batch.mjs.map +1 -0
- package/dist/host/channels.cjs +256 -0
- package/dist/host/channels.cjs.map +1 -0
- package/dist/host/channels.d.cts +66 -0
- package/dist/host/channels.d.cts.map +1 -0
- package/dist/host/channels.d.mts +66 -0
- package/dist/host/channels.d.mts.map +1 -0
- package/dist/host/channels.mjs +252 -0
- package/dist/host/channels.mjs.map +1 -0
- package/dist/host/execute.cjs +102 -0
- package/dist/host/execute.cjs.map +1 -0
- package/dist/host/execute.d.cts +38 -0
- package/dist/host/execute.d.cts.map +1 -0
- package/dist/host/execute.d.mts +38 -0
- package/dist/host/execute.d.mts.map +1 -0
- package/dist/host/execute.mjs +101 -0
- package/dist/host/execute.mjs.map +1 -0
- package/dist/host/fresh-read.cjs +29 -0
- package/dist/host/fresh-read.cjs.map +1 -0
- package/dist/host/fresh-read.d.cts +16 -0
- package/dist/host/fresh-read.d.cts.map +1 -0
- package/dist/host/fresh-read.d.mts +16 -0
- package/dist/host/fresh-read.d.mts.map +1 -0
- package/dist/host/fresh-read.mjs +28 -0
- package/dist/host/fresh-read.mjs.map +1 -0
- package/dist/host/http.cjs +393 -0
- package/dist/host/http.cjs.map +1 -0
- package/dist/host/http.d.cts +61 -0
- package/dist/host/http.d.cts.map +1 -0
- package/dist/host/http.d.mts +61 -0
- package/dist/host/http.d.mts.map +1 -0
- package/dist/host/http.mjs +389 -0
- package/dist/host/http.mjs.map +1 -0
- package/dist/host/ingest.cjs +1210 -0
- package/dist/host/ingest.cjs.map +1 -0
- package/dist/host/ingest.d.cts +497 -0
- package/dist/host/ingest.d.cts.map +1 -0
- package/dist/host/ingest.d.mts +497 -0
- package/dist/host/ingest.d.mts.map +1 -0
- package/dist/host/ingest.mjs +1172 -0
- package/dist/host/ingest.mjs.map +1 -0
- package/dist/host/journey-host.cjs +223 -0
- package/dist/host/journey-host.cjs.map +1 -0
- package/dist/host/journey-host.d.cts +118 -0
- package/dist/host/journey-host.d.cts.map +1 -0
- package/dist/host/journey-host.d.mts +118 -0
- package/dist/host/journey-host.d.mts.map +1 -0
- package/dist/host/journey-host.mjs +219 -0
- package/dist/host/journey-host.mjs.map +1 -0
- package/dist/host/platform.cjs +20 -0
- package/dist/host/platform.cjs.map +1 -0
- package/dist/host/platform.d.cts +120 -0
- package/dist/host/platform.d.cts.map +1 -0
- package/dist/host/platform.d.mts +120 -0
- package/dist/host/platform.d.mts.map +1 -0
- package/dist/host/platform.mjs +18 -0
- package/dist/host/platform.mjs.map +1 -0
- package/dist/host/senders.cjs +71 -0
- package/dist/host/senders.cjs.map +1 -0
- package/dist/host/senders.d.cts +34 -0
- package/dist/host/senders.d.cts.map +1 -0
- package/dist/host/senders.d.mts +34 -0
- package/dist/host/senders.d.mts.map +1 -0
- package/dist/host/senders.mjs +67 -0
- package/dist/host/senders.mjs.map +1 -0
- package/dist/host/workflow-cache.cjs +47 -0
- package/dist/host/workflow-cache.cjs.map +1 -0
- package/dist/host/workflow-cache.d.cts +21 -0
- package/dist/host/workflow-cache.d.cts.map +1 -0
- package/dist/host/workflow-cache.d.mts +21 -0
- package/dist/host/workflow-cache.d.mts.map +1 -0
- package/dist/host/workflow-cache.mjs +46 -0
- package/dist/host/workflow-cache.mjs.map +1 -0
- package/dist/http2-client.cjs +89 -0
- package/dist/http2-client.cjs.map +1 -0
- package/dist/http2-client.d.cts +45 -0
- package/dist/http2-client.d.cts.map +1 -0
- package/dist/http2-client.d.mts +45 -0
- package/dist/http2-client.d.mts.map +1 -0
- package/dist/http2-client.mjs +87 -0
- package/dist/http2-client.mjs.map +1 -0
- package/dist/index.cjs +130 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.mjs +20 -0
- package/dist/inflight.cjs +116 -0
- package/dist/inflight.cjs.map +1 -0
- package/dist/inflight.d.cts +49 -0
- package/dist/inflight.d.cts.map +1 -0
- package/dist/inflight.d.mts +49 -0
- package/dist/inflight.d.mts.map +1 -0
- package/dist/inflight.mjs +113 -0
- package/dist/inflight.mjs.map +1 -0
- package/dist/ir.cjs +429 -0
- package/dist/ir.cjs.map +1 -0
- package/dist/ir.d.cts +593 -0
- package/dist/ir.d.cts.map +1 -0
- package/dist/ir.d.mts +593 -0
- package/dist/ir.d.mts.map +1 -0
- package/dist/ir.mjs +404 -0
- package/dist/ir.mjs.map +1 -0
- package/dist/jwt.cjs +17 -0
- package/dist/jwt.cjs.map +1 -0
- package/dist/jwt.d.cts +7 -0
- package/dist/jwt.d.cts.map +1 -0
- package/dist/jwt.d.mts +7 -0
- package/dist/jwt.d.mts.map +1 -0
- package/dist/jwt.mjs +15 -0
- package/dist/jwt.mjs.map +1 -0
- package/dist/node/index.cjs +231 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +59 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts +59 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.mjs +225 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/node/runs.cjs +222 -0
- package/dist/node/runs.cjs.map +1 -0
- package/dist/node/runs.d.cts +93 -0
- package/dist/node/runs.d.cts.map +1 -0
- package/dist/node/runs.d.mts +93 -0
- package/dist/node/runs.d.mts.map +1 -0
- package/dist/node/runs.mjs +221 -0
- package/dist/node/runs.mjs.map +1 -0
- package/dist/node/runtime.cjs +351 -0
- package/dist/node/runtime.cjs.map +1 -0
- package/dist/node/runtime.d.cts +96 -0
- package/dist/node/runtime.d.cts.map +1 -0
- package/dist/node/runtime.d.mts +96 -0
- package/dist/node/runtime.d.mts.map +1 -0
- package/dist/node/runtime.mjs +348 -0
- package/dist/node/runtime.mjs.map +1 -0
- package/dist/plan.cjs +221 -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 +218 -0
- package/dist/plan.mjs.map +1 -0
- package/dist/postgres-js.cjs +51 -0
- package/dist/postgres-js.cjs.map +1 -0
- package/dist/postgres-js.d.cts +32 -0
- package/dist/postgres-js.d.cts.map +1 -0
- package/dist/postgres-js.d.mts +32 -0
- package/dist/postgres-js.d.mts.map +1 -0
- package/dist/postgres-js.mjs +46 -0
- package/dist/postgres-js.mjs.map +1 -0
- package/dist/provenance.cjs +66 -0
- package/dist/provenance.cjs.map +1 -0
- package/dist/provenance.d.cts +40 -0
- package/dist/provenance.d.cts.map +1 -0
- package/dist/provenance.d.mts +40 -0
- package/dist/provenance.d.mts.map +1 -0
- package/dist/provenance.mjs +64 -0
- package/dist/provenance.mjs.map +1 -0
- package/dist/push.cjs +11 -0
- package/dist/push.cjs.map +1 -0
- package/dist/push.d.cts +14 -0
- package/dist/push.d.cts.map +1 -0
- package/dist/push.d.mts +14 -0
- package/dist/push.d.mts.map +1 -0
- package/dist/push.mjs +10 -0
- package/dist/push.mjs.map +1 -0
- package/dist/react-email.cjs +56 -0
- package/dist/react-email.cjs.map +1 -0
- package/dist/react-email.d.cts +5 -0
- package/dist/react-email.d.cts.map +1 -0
- package/dist/react-email.d.mts +5 -0
- package/dist/react-email.d.mts.map +1 -0
- package/dist/react-email.mjs +55 -0
- package/dist/react-email.mjs.map +1 -0
- package/dist/reporting/classify.cjs +46 -0
- package/dist/reporting/classify.cjs.map +1 -0
- package/dist/reporting/classify.d.cts +65 -0
- package/dist/reporting/classify.d.cts.map +1 -0
- package/dist/reporting/classify.d.mts +65 -0
- package/dist/reporting/classify.d.mts.map +1 -0
- package/dist/reporting/classify.mjs +42 -0
- package/dist/reporting/classify.mjs.map +1 -0
- package/dist/reporting/observer.cjs +137 -0
- package/dist/reporting/observer.cjs.map +1 -0
- package/dist/reporting/observer.d.cts +31 -0
- package/dist/reporting/observer.d.cts.map +1 -0
- package/dist/reporting/observer.d.mts +31 -0
- package/dist/reporting/observer.d.mts.map +1 -0
- package/dist/reporting/observer.mjs +134 -0
- package/dist/reporting/observer.mjs.map +1 -0
- package/dist/reporting/tracking.cjs +185 -0
- package/dist/reporting/tracking.cjs.map +1 -0
- package/dist/reporting/tracking.d.cts +63 -0
- package/dist/reporting/tracking.d.cts.map +1 -0
- package/dist/reporting/tracking.d.mts +63 -0
- package/dist/reporting/tracking.d.mts.map +1 -0
- package/dist/reporting/tracking.mjs +182 -0
- package/dist/reporting/tracking.mjs.map +1 -0
- package/dist/runtime.cjs +18 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +44 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.mts +44 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +17 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/store/condition-sql.cjs +145 -0
- package/dist/store/condition-sql.cjs.map +1 -0
- package/dist/store/condition-sql.d.cts +38 -0
- package/dist/store/condition-sql.d.cts.map +1 -0
- package/dist/store/condition-sql.d.mts +38 -0
- package/dist/store/condition-sql.d.mts.map +1 -0
- package/dist/store/condition-sql.mjs +144 -0
- package/dist/store/condition-sql.mjs.map +1 -0
- package/dist/store/erasure.cjs +21 -0
- package/dist/store/erasure.cjs.map +1 -0
- package/dist/store/erasure.d.cts +16 -0
- package/dist/store/erasure.d.cts.map +1 -0
- package/dist/store/erasure.d.mts +16 -0
- package/dist/store/erasure.d.mts.map +1 -0
- package/dist/store/erasure.mjs +20 -0
- package/dist/store/erasure.mjs.map +1 -0
- package/dist/store/facts.cjs +79 -0
- package/dist/store/facts.cjs.map +1 -0
- package/dist/store/facts.d.cts +41 -0
- package/dist/store/facts.d.cts.map +1 -0
- package/dist/store/facts.d.mts +41 -0
- package/dist/store/facts.d.mts.map +1 -0
- package/dist/store/facts.mjs +77 -0
- package/dist/store/facts.mjs.map +1 -0
- package/dist/store/identity.cjs +34 -0
- package/dist/store/identity.cjs.map +1 -0
- package/dist/store/identity.d.cts +13 -0
- package/dist/store/identity.d.cts.map +1 -0
- package/dist/store/identity.d.mts +13 -0
- package/dist/store/identity.d.mts.map +1 -0
- package/dist/store/identity.mjs +30 -0
- package/dist/store/identity.mjs.map +1 -0
- package/dist/store/index.cjs +35 -0
- package/dist/store/index.cjs.map +1 -0
- package/dist/store/index.d.cts +766 -0
- package/dist/store/index.d.cts.map +1 -0
- package/dist/store/index.d.mts +766 -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 +327 -0
- package/dist/store/postgres-reporting.cjs.map +1 -0
- package/dist/store/postgres-reporting.d.cts +95 -0
- package/dist/store/postgres-reporting.d.cts.map +1 -0
- package/dist/store/postgres-reporting.d.mts +95 -0
- package/dist/store/postgres-reporting.d.mts.map +1 -0
- package/dist/store/postgres-reporting.mjs +326 -0
- package/dist/store/postgres-reporting.mjs.map +1 -0
- package/dist/store/postgres.cjs +1173 -0
- package/dist/store/postgres.cjs.map +1 -0
- package/dist/store/postgres.d.cts +199 -0
- package/dist/store/postgres.d.cts.map +1 -0
- package/dist/store/postgres.d.mts +199 -0
- package/dist/store/postgres.d.mts.map +1 -0
- package/dist/store/postgres.mjs +1170 -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 +26 -0
- package/dist/store/sql.d.cts.map +1 -0
- package/dist/store/sql.d.mts +26 -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 +660 -0
- package/dist/store/tables.cjs.map +1 -0
- package/dist/store/tables.d.cts +103 -0
- package/dist/store/tables.d.cts.map +1 -0
- package/dist/store/tables.d.mts +103 -0
- package/dist/store/tables.d.mts.map +1 -0
- package/dist/store/tables.mjs +653 -0
- package/dist/store/tables.mjs.map +1 -0
- package/dist/store/user-lock.cjs +42 -0
- package/dist/store/user-lock.cjs.map +1 -0
- package/dist/store/user-lock.d.cts +30 -0
- package/dist/store/user-lock.d.cts.map +1 -0
- package/dist/store/user-lock.d.mts +30 -0
- package/dist/store/user-lock.d.mts.map +1 -0
- package/dist/store/user-lock.mjs +39 -0
- package/dist/store/user-lock.mjs.map +1 -0
- package/dist/template-rules.cjs +94 -0
- package/dist/template-rules.cjs.map +1 -0
- package/dist/template-rules.d.cts +80 -0
- package/dist/template-rules.d.cts.map +1 -0
- package/dist/template-rules.d.mts +80 -0
- package/dist/template-rules.d.mts.map +1 -0
- package/dist/template-rules.mjs +86 -0
- package/dist/template-rules.mjs.map +1 -0
- package/dist/templates.cjs +375 -0
- package/dist/templates.cjs.map +1 -0
- package/dist/templates.d.cts +358 -0
- package/dist/templates.d.cts.map +1 -0
- package/dist/templates.d.mts +358 -0
- package/dist/templates.d.mts.map +1 -0
- package/dist/templates.mjs +353 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/transports/cloudflare-email.cjs +69 -0
- package/dist/transports/cloudflare-email.cjs.map +1 -0
- package/dist/transports/cloudflare-email.d.cts +63 -0
- package/dist/transports/cloudflare-email.d.cts.map +1 -0
- package/dist/transports/cloudflare-email.d.mts +63 -0
- package/dist/transports/cloudflare-email.d.mts.map +1 -0
- package/dist/transports/cloudflare-email.mjs +67 -0
- package/dist/transports/cloudflare-email.mjs.map +1 -0
- package/dist/transports/ses.cjs +142 -0
- package/dist/transports/ses.cjs.map +1 -0
- package/dist/transports/ses.d.cts +49 -0
- package/dist/transports/ses.d.cts.map +1 -0
- package/dist/transports/ses.d.mts +49 -0
- package/dist/transports/ses.d.mts.map +1 -0
- package/dist/transports/ses.mjs +139 -0
- package/dist/transports/ses.mjs.map +1 -0
- package/dist/transports/sigv4.cjs +86 -0
- package/dist/transports/sigv4.cjs.map +1 -0
- package/dist/transports/sigv4.d.cts +25 -0
- package/dist/transports/sigv4.d.cts.map +1 -0
- package/dist/transports/sigv4.d.mts +25 -0
- package/dist/transports/sigv4.d.mts.map +1 -0
- package/dist/transports/sigv4.mjs +85 -0
- package/dist/transports/sigv4.mjs.map +1 -0
- package/dist/webhooks.cjs +97 -0
- package/dist/webhooks.cjs.map +1 -0
- package/dist/webhooks.d.cts +23 -0
- package/dist/webhooks.d.cts.map +1 -0
- package/dist/webhooks.d.mts +23 -0
- package/dist/webhooks.d.mts.map +1 -0
- package/dist/webhooks.mjs +95 -0
- package/dist/webhooks.mjs.map +1 -0
- package/dist/webpush.cjs +361 -0
- package/dist/webpush.cjs.map +1 -0
- package/dist/webpush.d.cts +135 -0
- package/dist/webpush.d.cts.map +1 -0
- package/dist/webpush.d.mts +135 -0
- package/dist/webpush.d.mts.map +1 -0
- package/dist/webpush.mjs +350 -0
- package/dist/webpush.mjs.map +1 -0
- package/package.json +270 -31
- package/src/cloudflare/workers.d.ts +44 -0
- package/index.cjs +0 -18
- package/index.d.cts +0 -4
- package/index.d.mts +0 -4
- package/index.mjs +0 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { BURST_WINDOW_MS, classifyClick, classifyOpen } from "./classify.mjs";
|
|
2
|
+
// src/reporting/tracking.ts
|
|
3
|
+
const GIF = Uint8Array.from(atob("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"), (char) => char.charCodeAt(0));
|
|
4
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5
|
+
/** Whether `id` has the shape of a message id (a UUID); anything else names no copy. */
|
|
6
|
+
const isMessageId = (id) => UUID.test(id);
|
|
7
|
+
function requester(request) {
|
|
8
|
+
const cf = request.cf;
|
|
9
|
+
return {
|
|
10
|
+
method: request.method,
|
|
11
|
+
userAgent: request.headers.get("user-agent"),
|
|
12
|
+
asn: cf?.asn ?? null,
|
|
13
|
+
organization: cf?.asOrganization ?? null,
|
|
14
|
+
country: cf?.country ?? null
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** A `/t/...` request's response, or undefined when the path is not a tracking route. */
|
|
18
|
+
async function handleTracking(request, reporting, options = {}) {
|
|
19
|
+
const url = new URL(request.url);
|
|
20
|
+
const path = url.pathname.split("/");
|
|
21
|
+
const root = path.at(1);
|
|
22
|
+
const kind = path.at(2);
|
|
23
|
+
const id = path.at(3);
|
|
24
|
+
const position = path.at(4);
|
|
25
|
+
if (root !== "t" || id === void 0 || !UUID.test(id)) return void 0;
|
|
26
|
+
const who = requester(request);
|
|
27
|
+
const read = who.method === "GET" || who.method === "HEAD";
|
|
28
|
+
if (kind === "o" && read) {
|
|
29
|
+
await recordOpen(reporting, id, who, options);
|
|
30
|
+
return new Response(who.method === "HEAD" ? null : GIF, { headers: {
|
|
31
|
+
"content-type": "image/gif",
|
|
32
|
+
"cache-control": "no-store, max-age=0"
|
|
33
|
+
} });
|
|
34
|
+
}
|
|
35
|
+
if ((kind === "l" || kind === "u") && position !== void 0 && read) {
|
|
36
|
+
const target = await recordClick(reporting, id, Number(position), who, options);
|
|
37
|
+
if (target === void 0) return page(options, "This link has expired.", 404);
|
|
38
|
+
if (kind === "u") return confirmUnsubscribe(reporting, options, id);
|
|
39
|
+
return Response.redirect(target, 302);
|
|
40
|
+
}
|
|
41
|
+
if (kind === "u" && position === void 0 && read) return confirmUnsubscribe(reporting, options, id);
|
|
42
|
+
if (kind === "d" && who.method === "POST") {
|
|
43
|
+
const known = await reporting.recordDeviceDelivered(id, Date.now());
|
|
44
|
+
return new Response(null, { status: known ? 204 : 404 });
|
|
45
|
+
}
|
|
46
|
+
if (kind === "p" && who.method === "POST") {
|
|
47
|
+
const at = Date.now();
|
|
48
|
+
let userId;
|
|
49
|
+
const known = await reporting.recordOpen(id, (message) => {
|
|
50
|
+
if (!message.channel.startsWith("push")) return void 0;
|
|
51
|
+
userId = message.userId;
|
|
52
|
+
return {
|
|
53
|
+
at,
|
|
54
|
+
machine: false,
|
|
55
|
+
reason: null,
|
|
56
|
+
...network(who)
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
if (known && userId === void 0) return new Response(null, { status: 404 });
|
|
60
|
+
if (known && userId !== void 0 && options.pushOpened !== void 0) try {
|
|
61
|
+
await options.pushOpened({
|
|
62
|
+
messageId: id,
|
|
63
|
+
userId,
|
|
64
|
+
at
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(`[workflow] recording push open ${id} as an event failed`, error);
|
|
68
|
+
}
|
|
69
|
+
return new Response(null, { status: known ? 204 : 404 });
|
|
70
|
+
}
|
|
71
|
+
if (kind === "u" && who.method === "POST") {
|
|
72
|
+
const at = Date.now();
|
|
73
|
+
const all = url.searchParams.get("scope") === "all";
|
|
74
|
+
const unsubscribed = await reporting.recordUnsubscribe(id, at, all ? "all" : "topic");
|
|
75
|
+
if (unsubscribed === void 0) return page(options, "You won't get these emails anymore.");
|
|
76
|
+
if (unsubscribed.topic === null) return page(options, "This link has expired.", 404);
|
|
77
|
+
if (options.onUnsubscribed !== void 0) try {
|
|
78
|
+
await options.onUnsubscribed({
|
|
79
|
+
messageId: id,
|
|
80
|
+
userId: unsubscribed.userId,
|
|
81
|
+
at,
|
|
82
|
+
topic: unsubscribed.topic,
|
|
83
|
+
all
|
|
84
|
+
});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(`[workflow] acting on the unsubscribe of ${id} failed`, error);
|
|
87
|
+
}
|
|
88
|
+
const from = options.product === void 0 ? "" : ` from ${escape(options.product)}`;
|
|
89
|
+
return page(options, all ? `You won't get emails${from} anymore.` : `You won't get ${escape(topicName(unsubscribed.topic))} emails${from} anymore.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** A topic id as the page shows it: `product_updates` reads as "product updates". */
|
|
93
|
+
function topicName(topic) {
|
|
94
|
+
return topic.replace(/[_-]+/g, " ");
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The question an unsubscribe link, or the List-Unsubscribe URL opened in a browser, asks: the
|
|
98
|
+
* email's topic (the default), or every email. A copy nobody knows, or a transactional one (the
|
|
99
|
+
* link was never in it), is an expired link.
|
|
100
|
+
*/
|
|
101
|
+
async function confirmUnsubscribe(reporting, options, id) {
|
|
102
|
+
const message = await reporting.lookupMessage(id);
|
|
103
|
+
if (message?.channel !== "email" || message.topic === null) return page(options, "This link has expired.", 404);
|
|
104
|
+
const product = options.product === void 0 ? "" : ` from ${escape(options.product)}`;
|
|
105
|
+
const topic = escape(topicName(message.topic));
|
|
106
|
+
return page(options, `Unsubscribe from ${topic} emails${product}?`, 200, `<form method="post" action="/t/u/${id}"><button type="submit">Unsubscribe from ${topic}</button></form><form method="post" action="/t/u/${id}?scope=all"><button type="submit" class="secondary">Unsubscribe from all emails</button></form>`);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A journey push tapped open, as the app reports it (`JourneyClient.messageOpened`): an open on
|
|
110
|
+
* the copy — only the recipient's own, and never a machine, since no proxy or scanner taps a
|
|
111
|
+
* notification. False when the message is unknown or not the user's.
|
|
112
|
+
*/
|
|
113
|
+
async function recordPushOpen(reporting, userId, messageId, at = Date.now()) {
|
|
114
|
+
if (!UUID.test(messageId)) return false;
|
|
115
|
+
let recorded = false;
|
|
116
|
+
await reporting.recordOpen(messageId, (message) => {
|
|
117
|
+
if (message.userId !== userId) return void 0;
|
|
118
|
+
recorded = true;
|
|
119
|
+
return {
|
|
120
|
+
at,
|
|
121
|
+
machine: false,
|
|
122
|
+
reason: null,
|
|
123
|
+
userAgent: null,
|
|
124
|
+
asn: null,
|
|
125
|
+
organization: null,
|
|
126
|
+
country: null
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
return recorded;
|
|
130
|
+
}
|
|
131
|
+
async function recordOpen(reporting, id, who, options) {
|
|
132
|
+
const at = Date.now();
|
|
133
|
+
await reporting.recordOpen(id, (message) => ({
|
|
134
|
+
at,
|
|
135
|
+
...classifyOpen({
|
|
136
|
+
...who,
|
|
137
|
+
sinceDeliveredMs: at - message.deliveredAt
|
|
138
|
+
}, { quickMs: options.quickMs }),
|
|
139
|
+
...network(who)
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
const network = (who) => ({
|
|
143
|
+
userAgent: who.userAgent,
|
|
144
|
+
asn: who.asn,
|
|
145
|
+
organization: who.organization,
|
|
146
|
+
country: who.country
|
|
147
|
+
});
|
|
148
|
+
/** Records the click and answers the URL to send the visitor to, or undefined for an unknown link. */
|
|
149
|
+
async function recordClick(reporting, id, position, who, options) {
|
|
150
|
+
if (!Number.isInteger(position) || position < 0) return void 0;
|
|
151
|
+
const at = Date.now();
|
|
152
|
+
return (await reporting.recordClick(id, position, at, BURST_WINDOW_MS, (link) => {
|
|
153
|
+
const linksInBurst = (/* @__PURE__ */ new Set([position, ...link.recent.map((click) => click.position)])).size;
|
|
154
|
+
const verdict = classifyClick({
|
|
155
|
+
...who,
|
|
156
|
+
sinceDeliveredMs: at - link.deliveredAt,
|
|
157
|
+
linksInBurst,
|
|
158
|
+
linkCount: link.linkCount
|
|
159
|
+
}, { quickMs: options.quickMs });
|
|
160
|
+
return {
|
|
161
|
+
engagement: {
|
|
162
|
+
at,
|
|
163
|
+
...verdict,
|
|
164
|
+
...network(who)
|
|
165
|
+
},
|
|
166
|
+
backdate: verdict.reason === "link_burst" || (verdict.reason ?? "").endsWith("link_pair")
|
|
167
|
+
};
|
|
168
|
+
}))?.url;
|
|
169
|
+
}
|
|
170
|
+
function escape(text) {
|
|
171
|
+
return text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
172
|
+
}
|
|
173
|
+
function page(options, message, status = 200, extra = "") {
|
|
174
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escape(options.product ?? "Email")}</title><style>body{font:16px system-ui;margin:0;display:grid;place-items:center;min-height:100vh;background:#fafafa;color:#18181b}main{text-align:center;padding:24px}form{margin:12px 0}button{font:inherit;padding:10px 20px;border-radius:9999px;border:0;background:#18181b;color:#fff;cursor:pointer}button.secondary{background:#e4e4e7;color:#18181b}</style></head><body><main><p>${message}</p>${extra}</main></body></html>`;
|
|
175
|
+
return new Response(html, {
|
|
176
|
+
status,
|
|
177
|
+
headers: { "content-type": "text/html; charset=utf-8" }
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
export { handleTracking, isMessageId, recordPushOpen };
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=tracking.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracking.mjs","names":[],"sources":["../../src/reporting/tracking.ts"],"sourcesContent":["import type { JourneyReporting } from '../store';\nimport { BURST_WINDOW_MS, classifyClick, classifyOpen } from './classify';\n\n/**\n * The endpoints a journey email's tracking points at (see ./observer.ts), served by journeyWorker\n * without a bearer — recipients open them:\n *\n * GET /t/o/<message> the open pixel: records the open, answers a 1×1 GIF\n * GET /t/l/<message>/<position> a link: records the click, redirects to the recorded URL\n * GET /t/u/<message>/<position> the unsubscribe link: records the click, asks to confirm\n * GET /t/u/<message> the List-Unsubscribe header's URL, opened: asks to confirm\n * POST /t/u/<message> the unsubscribe confirmation, and the header's one-click\n * unsubscribe (RFC 8058: a mail client's button posts here):\n * opts out of the email's topic; `?scope=all` (the page's\n * second button) of every email\n * POST /t/d/<message> a push the device received (iOS's notification service\n * extension, a browser's service worker)\n * POST /t/p/<message> a push opened, reported by a browser's service worker\n *\n * Every open and click is recorded with its verdict (./classify.ts), and the message keeps its\n * first open and click of each kind. The redirect goes only to the URL recorded for that position,\n * never to one the request carries, so the endpoint cannot bounce visitors anywhere else. An\n * email's unsubscribe link is a tracked link too, and which link it is was fixed when the email was\n * sent (its route): following it shows a confirmation page, and only the confirmation — a POST,\n * which no link scanner sends — counts. The page offers the email's topic (the default, and what\n * a mail client's one-click POST does) and every email. Changing a template's or the config's\n * unsubscribe URL, or removing the template, changes nothing for emails already sent. A\n * transactional email (no topic) never carried the link: every `/t/u` variant answers 404 for it.\n */\n\nexport interface TrackingOptions {\n /** The name the confirmation pages show (the config's `title`). */\n product?: string | undefined;\n /** `email.tracking.quickClickMs`: how soon after delivery an open or click is a weak machine signal. */\n quickMs?: number | undefined;\n /** A browser reported a push tapped (`/t/p`): the host records it as an event too (`webPush.openedEvent`). */\n pushOpened?:\n | ((open: { messageId: string; userId: string; at: number }) => Promise<void>)\n | undefined;\n /**\n * An unsubscribe was recorded (`POST /t/u`): from the email's `topic`, or with `all` from every\n * email — then the host wakes the user's waits that read email reachability, so an\n * `exitWhen: not(reachable('email'))` takes effect at once. Its failure is logged, never a\n * reason to fail the unsubscribe.\n */\n onUnsubscribed?:\n | ((unsubscribe: {\n messageId: string;\n userId: string;\n at: number;\n topic: string;\n all: boolean;\n }) => Promise<void>)\n | undefined;\n}\n\nconst GIF = Uint8Array.from(\n atob('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'),\n (char) => char.charCodeAt(0)\n);\nconst UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/** Whether `id` has the shape of a message id (a UUID); anything else names no copy. */\nexport const isMessageId = (id: string): boolean => UUID.test(id);\n\ninterface Requester {\n method: string;\n userAgent: string | null;\n asn: number | null;\n organization: string | null;\n country: string | null;\n}\n\nfunction requester(request: Request): Requester {\n const cf = (\n request as Request & { cf?: { asn?: number; asOrganization?: string; country?: string } }\n ).cf;\n return {\n method: request.method,\n userAgent: request.headers.get('user-agent'),\n asn: cf?.asn ?? null,\n organization: cf?.asOrganization ?? null,\n country: cf?.country ?? null,\n };\n}\n\n/** A `/t/...` request's response, or undefined when the path is not a tracking route. */\nexport async function handleTracking(\n request: Request,\n reporting: JourneyReporting,\n options: TrackingOptions = {}\n): Promise<Response | undefined> {\n const url = new URL(request.url);\n const path = url.pathname.split('/');\n const root = path.at(1);\n const kind = path.at(2);\n const id = path.at(3);\n const position = path.at(4);\n if (root !== 't' || id === undefined || !UUID.test(id)) return undefined;\n const who = requester(request);\n const read = who.method === 'GET' || who.method === 'HEAD';\n if (kind === 'o' && read) {\n await recordOpen(reporting, id, who, options);\n return new Response(who.method === 'HEAD' ? null : GIF, {\n headers: { 'content-type': 'image/gif', 'cache-control': 'no-store, max-age=0' },\n });\n }\n if ((kind === 'l' || kind === 'u') && position !== undefined && read) {\n const target = await recordClick(reporting, id, Number(position), who, options);\n if (target === undefined) return page(options, 'This link has expired.', 404);\n if (kind === 'u') return confirmUnsubscribe(reporting, options, id);\n return Response.redirect(target, 302);\n }\n // The List-Unsubscribe URL opened in a browser (a client without one-click): the same question\n if (kind === 'u' && position === undefined && read)\n return confirmUnsubscribe(reporting, options, id);\n if (kind === 'd' && who.method === 'POST') {\n const known = await reporting.recordDeviceDelivered(id, Date.now());\n return new Response(null, { status: known ? 204 : 404 });\n }\n if (kind === 'p' && who.method === 'POST') {\n // A notification tap: a person, as the message id is what proves it is theirs. Only a push\n // copy's id proves that: an email's id is in every link of the email (forwarded, scanned,\n // logged by proxies), and taking it here would let anyone holding one forge a human open and\n // have the host ingest an event as the recipient\n const at = Date.now();\n let userId: string | undefined;\n const known = await reporting.recordOpen(id, (message) => {\n // A push copy is recorded per platform (`push_ios`, `push_web`, ...)\n if (!message.channel.startsWith('push')) return undefined;\n userId = message.userId;\n return { at, machine: false, reason: null, ...network(who) };\n });\n if (known && userId === undefined) return new Response(null, { status: 404 });\n if (known && userId !== undefined && options.pushOpened !== undefined) {\n try {\n await options.pushOpened({ messageId: id, userId, at });\n } catch (error) {\n // The open is recorded; the event is the host's extra, never a reason to fail the beacon\n console.error(`[workflow] recording push open ${id} as an event failed`, error);\n }\n }\n return new Response(null, { status: known ? 204 : 404 });\n }\n if (kind === 'u' && who.method === 'POST') {\n const at = Date.now();\n // The page's \"all emails\" button; a mail client's one-click POST carries no scope\n const all = url.searchParams.get('scope') === 'all';\n const unsubscribed = await reporting.recordUnsubscribe(id, at, all ? 'all' : 'topic');\n // A mail client's one-click POST must succeed: for a copy no longer on record (its user\n // erased) there is nothing left to send to, so the answer is the same\n if (unsubscribed === undefined) return page(options, \"You won't get these emails anymore.\");\n // A transactional email never carried the link\n if (unsubscribed.topic === null) return page(options, 'This link has expired.', 404);\n if (options.onUnsubscribed !== undefined) {\n try {\n await options.onUnsubscribed({\n messageId: id,\n userId: unsubscribed.userId,\n at,\n topic: unsubscribed.topic,\n all,\n });\n } catch (error) {\n console.error(`[workflow] acting on the unsubscribe of ${id} failed`, error);\n }\n }\n const from = options.product === undefined ? '' : ` from ${escape(options.product)}`;\n return page(\n options,\n all\n ? `You won't get emails${from} anymore.`\n : `You won't get ${escape(topicName(unsubscribed.topic))} emails${from} anymore.`\n );\n }\n return undefined;\n}\n\n/** A topic id as the page shows it: `product_updates` reads as \"product updates\". */\nfunction topicName(topic: string): string {\n return topic.replace(/[_-]+/g, ' ');\n}\n\n/**\n * The question an unsubscribe link, or the List-Unsubscribe URL opened in a browser, asks: the\n * email's topic (the default), or every email. A copy nobody knows, or a transactional one (the\n * link was never in it), is an expired link.\n */\nasync function confirmUnsubscribe(\n reporting: JourneyReporting,\n options: TrackingOptions,\n id: string\n): Promise<Response> {\n const message = await reporting.lookupMessage(id);\n if (message?.channel !== 'email' || message.topic === null) {\n return page(options, 'This link has expired.', 404);\n }\n const product = options.product === undefined ? '' : ` from ${escape(options.product)}`;\n const topic = escape(topicName(message.topic));\n return page(\n options,\n `Unsubscribe from ${topic} emails${product}?`,\n 200,\n `<form method=\"post\" action=\"/t/u/${id}\"><button type=\"submit\">Unsubscribe from ${topic}</button></form>` +\n `<form method=\"post\" action=\"/t/u/${id}?scope=all\"><button type=\"submit\" class=\"secondary\">Unsubscribe from all emails</button></form>`\n );\n}\n\n/**\n * A journey push tapped open, as the app reports it (`JourneyClient.messageOpened`): an open on\n * the copy — only the recipient's own, and never a machine, since no proxy or scanner taps a\n * notification. False when the message is unknown or not the user's.\n */\nexport async function recordPushOpen(\n reporting: JourneyReporting,\n userId: string,\n messageId: string,\n at = Date.now()\n): Promise<boolean> {\n if (!UUID.test(messageId)) return false;\n let recorded = false;\n await reporting.recordOpen(messageId, (message) => {\n if (message.userId !== userId) return undefined;\n recorded = true;\n return {\n at,\n machine: false,\n reason: null,\n userAgent: null,\n asn: null,\n organization: null,\n country: null,\n };\n });\n return recorded;\n}\n\nasync function recordOpen(\n reporting: JourneyReporting,\n id: string,\n who: Requester,\n options: TrackingOptions\n) {\n const at = Date.now();\n await reporting.recordOpen(id, (message) => ({\n at,\n ...classifyOpen(\n { ...who, sinceDeliveredMs: at - message.deliveredAt },\n { quickMs: options.quickMs }\n ),\n ...network(who),\n }));\n}\n\nconst network = (who: Requester) => ({\n userAgent: who.userAgent,\n asn: who.asn,\n organization: who.organization,\n country: who.country,\n});\n\n/** Records the click and answers the URL to send the visitor to, or undefined for an unknown link. */\nasync function recordClick(\n reporting: JourneyReporting,\n id: string,\n position: number,\n who: Requester,\n options: TrackingOptions\n): Promise<string | undefined> {\n if (!Number.isInteger(position) || position < 0) return undefined;\n const at = Date.now();\n const recorded = await reporting.recordClick(id, position, at, BURST_WINDOW_MS, (link) => {\n const linksInBurst = new Set([position, ...link.recent.map((click) => click.position)]).size;\n const verdict = classifyClick(\n { ...who, sinceDeliveredMs: at - link.deliveredAt, linksInBurst, linkCount: link.linkCount },\n { quickMs: options.quickMs }\n );\n return {\n engagement: { at, ...verdict, ...network(who) },\n // The earlier click of a pair was judged before its other half arrived\n backdate: verdict.reason === 'link_burst' || (verdict.reason ?? '').endsWith('link_pair'),\n };\n });\n return recorded?.url;\n}\n\nfunction escape(text: string): string {\n return text.replace(/[&<>\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n}\n\nfunction page(options: TrackingOptions, message: string, status = 200, extra = ''): Response {\n const title = escape(options.product ?? 'Email');\n const html = `<!doctype html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>${title}</title><style>body{font:16px system-ui;margin:0;display:grid;place-items:center;min-height:100vh;background:#fafafa;color:#18181b}main{text-align:center;padding:24px}form{margin:12px 0}button{font:inherit;padding:10px 20px;border-radius:9999px;border:0;background:#18181b;color:#fff;cursor:pointer}button.secondary{background:#e4e4e7;color:#18181b}</style></head><body><main><p>${message}</p>${extra}</main></body></html>`;\n return new Response(html, { status, headers: { 'content-type': 'text/html; charset=utf-8' } });\n}\n"],"mappings":";;AAwDA,MAAM,MAAM,WAAW,KACrB,KAAK,0DAA0D,IAC9D,SAAS,KAAK,WAAW,CAAC,CAC7B;AACA,MAAM,OAAO;;AAGb,MAAa,eAAe,OAAwB,KAAK,KAAK,EAAE;AAUhE,SAAS,UAAU,SAA6B;CAC9C,MAAM,KACJ,QACA;CACF,OAAO;EACL,QAAQ,QAAQ;EAChB,WAAW,QAAQ,QAAQ,IAAI,YAAY;EAC3C,KAAK,IAAI,OAAO;EAChB,cAAc,IAAI,kBAAkB;EACpC,SAAS,IAAI,WAAW;CAC1B;AACF;;AAGA,eAAsB,eACpB,SACA,WACA,UAA2B,CAAC,GACG;CAC/B,MAAM,MAAM,IAAI,IAAI,QAAQ,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ACA,KACA,SAC6B;CAC7B,IAAI,CAAC,OAAO,UAAU,QAAQ,KAAK,WAAW,GAAG,OAAO,KAAA;CACxD,MAAM,KAAK,KAAK,IAAI;CAapB,QAAO,MAZgB,UAAU,YAAY,IAAI,UAAU,IAAI,kBAAkB,SAAS;EACxF,MAAM,gCAAe,IAAI,IAAI,CAAC,UAAU,GAAG,KAAK,OAAO,KAAK,UAAU,MAAM,QAAQ,CAAC,CAAC,EAAA,CAAE;EACxF,MAAM,UAAU,cACd;GAAE,GAAG;GAAK,kBAAkB,KAAK,KAAK;GAAa;GAAc,WAAW,KAAK;EAAU,GAC3F,EAAE,SAAS,QAAQ,QAAQ,CAC7B;EACA,OAAO;GACL,YAAY;IAAE;IAAI,GAAG;IAAS,GAAG,QAAQ,GAAG;GAAE;GAE9C,UAAU,QAAQ,WAAW,iBAAiB,QAAQ,UAAU,GAAA,CAAI,SAAS,WAAW;EAC1F;CACF,CAAC,EAAA,EACgB;AACnB;AAEA,SAAS,OAAO,MAAsB;CACpC,OAAO,KAAK,QAAQ,aAAa,MAAM,KAAK,EAAE,WAAW,CAAC,EAAE,EAAE;AAChE;AAEA,SAAS,KAAK,SAA0B,SAAiB,SAAS,KAAK,QAAQ,IAAc;CAE3F,MAAM,OAAO,8HADC,OAAO,QAAQ,WAAW,OACuG,EAAE,6XAA6X,QAAQ,MAAM,MAAM;CACliB,OAAO,IAAI,SAAS,MAAM;EAAE;EAAQ,SAAS,EAAE,gBAAgB,2BAA2B;CAAE,CAAC;AAC/F"}
|
package/dist/runtime.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// src/runtime.ts
|
|
3
|
+
const DEFAULTS = {
|
|
4
|
+
timeScale: 1,
|
|
5
|
+
logMessages: false
|
|
6
|
+
};
|
|
7
|
+
/** The options for `mode`, defaults filled in; `config` may be absent altogether. */
|
|
8
|
+
function resolveRuntime(config, mode) {
|
|
9
|
+
const entry = config?.[mode] ?? {};
|
|
10
|
+
const timeScale = entry.timeScale ?? DEFAULTS.timeScale;
|
|
11
|
+
return {
|
|
12
|
+
timeScale: Number.isFinite(timeScale) && timeScale > 0 ? timeScale : DEFAULTS.timeScale,
|
|
13
|
+
logMessages: entry.logMessages ?? DEFAULTS.logMessages
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.resolveRuntime = resolveRuntime;
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=runtime.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["/**\n * Runtime options — how the engine should behave in a given environment, as\n * typed configuration rather than loose environment variables. A project keeps\n * one `JourneyRuntimeConfig` (typically in its `workflow.config.ts`, next to the\n * studio settings) with one entry per mode; the host resolves the entry for\n * the environment it is running in and hands it to the runner.\n *\n * The only thing that should come from the environment is the mode itself —\n * which entry applies — never the values.\n */\n\nexport interface JourneyRuntimeOptions {\n /**\n * Fast-forward factor for every duration in a journey — delays, random\n * delays, wait timeouts, goal and `performed(within)` windows scale\n * together (see engine/time-scale.ts). 3600 turns \"2 days\" into 48 s.\n * 1 (the default) is real time; anything else belongs to development only:\n * the `production` entry's type admits no other value (`ProductionRuntimeOptions`).\n */\n timeScale?: number;\n /** Log every outbound message (channel, template, recipient, resolved props) as it is sent. */\n logMessages?: boolean;\n}\n\n/**\n * The `production` entry: real time, in the type. A fast-forwarded production (every delay,\n * goal window and segment window of every user compressed alike, a week of journey mail in\n * minutes) has only ever been a slip — a `development` entry pasted under the wrong key, a\n * factor left in after a rehearsal — so `timeScale` here is `1` or absent, and the slip is a\n * compile error where it is written rather than a flood of messages where it runs. A deploy that\n * is meant to run fast is not production: give it a mode of its own (`ENVIRONMENT=rehearsal`),\n * which is as free as `development`.\n */\nexport type ProductionRuntimeOptions = Omit<JourneyRuntimeOptions, 'timeScale'> & { timeScale?: 1 };\n\n/** Environments a project distinguishes; any string works, these two are the conventional ones. */\nexport type JourneyMode = 'development' | 'production' | (string & {});\n\n/**\n * One options entry per mode. Missing modes run with the defaults (real time, quiet). Only\n * `production` is held to real time; a mode under any other name is as free as `development`.\n */\nexport type JourneyRuntimeConfig = {\n [mode in JourneyMode]?: mode extends 'production'\n ? ProductionRuntimeOptions\n : JourneyRuntimeOptions;\n};\n\nconst DEFAULTS: Required<JourneyRuntimeOptions> = { timeScale: 1, logMessages: false };\n\n/** The options for `mode`, defaults filled in; `config` may be absent altogether. */\nexport function resolveRuntime(\n config: JourneyRuntimeConfig | undefined,\n mode: JourneyMode\n): Required<JourneyRuntimeOptions> {\n const entry = config?.[mode] ?? {};\n const timeScale = entry.timeScale ?? DEFAULTS.timeScale;\n return {\n timeScale: Number.isFinite(timeScale) && timeScale > 0 ? timeScale : DEFAULTS.timeScale,\n logMessages: entry.logMessages ?? DEFAULTS.logMessages,\n };\n}\n"],"mappings":";;AAgDA,MAAM,WAA4C;CAAE,WAAW;CAAG,aAAa;AAAM;;AAGrF,SAAgB,eACd,QACA,MACiC;CACjC,MAAM,QAAQ,SAAS,SAAS,CAAC;CACjC,MAAM,YAAY,MAAM,aAAa,SAAS;CAC9C,OAAO;EACL,WAAW,OAAO,SAAS,SAAS,KAAK,YAAY,IAAI,YAAY,SAAS;EAC9E,aAAa,MAAM,eAAe,SAAS;CAC7C;AACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime options — how the engine should behave in a given environment, as
|
|
3
|
+
* typed configuration rather than loose environment variables. A project keeps
|
|
4
|
+
* one `JourneyRuntimeConfig` (typically in its `workflow.config.ts`, next to the
|
|
5
|
+
* studio settings) with one entry per mode; the host resolves the entry for
|
|
6
|
+
* the environment it is running in and hands it to the runner.
|
|
7
|
+
*
|
|
8
|
+
* The only thing that should come from the environment is the mode itself —
|
|
9
|
+
* which entry applies — never the values.
|
|
10
|
+
*/
|
|
11
|
+
export interface JourneyRuntimeOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Fast-forward factor for every duration in a journey — delays, random
|
|
14
|
+
* delays, wait timeouts, goal and `performed(within)` windows scale
|
|
15
|
+
* together (see engine/time-scale.ts). 3600 turns "2 days" into 48 s.
|
|
16
|
+
* 1 (the default) is real time; anything else belongs to development only:
|
|
17
|
+
* the `production` entry's type admits no other value (`ProductionRuntimeOptions`).
|
|
18
|
+
*/
|
|
19
|
+
timeScale?: number;
|
|
20
|
+
/** Log every outbound message (channel, template, recipient, resolved props) as it is sent. */
|
|
21
|
+
logMessages?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The `production` entry: real time, in the type. A fast-forwarded production (every delay,
|
|
25
|
+
* goal window and segment window of every user compressed alike, a week of journey mail in
|
|
26
|
+
* minutes) has only ever been a slip — a `development` entry pasted under the wrong key, a
|
|
27
|
+
* factor left in after a rehearsal — so `timeScale` here is `1` or absent, and the slip is a
|
|
28
|
+
* compile error where it is written rather than a flood of messages where it runs. A deploy that
|
|
29
|
+
* is meant to run fast is not production: give it a mode of its own (`ENVIRONMENT=rehearsal`),
|
|
30
|
+
* which is as free as `development`.
|
|
31
|
+
*/
|
|
32
|
+
export type ProductionRuntimeOptions = Omit<JourneyRuntimeOptions, 'timeScale'> & {
|
|
33
|
+
timeScale?: 1;
|
|
34
|
+
};
|
|
35
|
+
/** Environments a project distinguishes; any string works, these two are the conventional ones. */
|
|
36
|
+
export type JourneyMode = 'development' | 'production' | (string & {});
|
|
37
|
+
/**
|
|
38
|
+
* One options entry per mode. Missing modes run with the defaults (real time, quiet). Only
|
|
39
|
+
* `production` is held to real time; a mode under any other name is as free as `development`.
|
|
40
|
+
*/
|
|
41
|
+
export type JourneyRuntimeConfig = { [mode in JourneyMode]?: mode extends 'production' ? ProductionRuntimeOptions : JourneyRuntimeOptions; };
|
|
42
|
+
/** The options for `mode`, defaults filled in; `config` may be absent altogether. */
|
|
43
|
+
export declare function resolveRuntime(config: JourneyRuntimeConfig | undefined, mode: JourneyMode): Required<JourneyRuntimeOptions>;
|
|
44
|
+
//# sourceMappingURL=runtime.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.cts","names":[],"sources":["../src/runtime.ts"],"mappings":";;;;;;;;;;iBAWiB;;;;;;;;EAQf;;EAEA;;;;;;;;;;;YAYU,2BAA2B,KAAK;EAAwC;;;YAGxE;;;;;YAMA,0BACT,QAAQ,eAAe,4BACpB,2BACA;;wBAMU,eACd,QAAQ,kCACR,MAAM,cACL,SAAS"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime options — how the engine should behave in a given environment, as
|
|
3
|
+
* typed configuration rather than loose environment variables. A project keeps
|
|
4
|
+
* one `JourneyRuntimeConfig` (typically in its `workflow.config.ts`, next to the
|
|
5
|
+
* studio settings) with one entry per mode; the host resolves the entry for
|
|
6
|
+
* the environment it is running in and hands it to the runner.
|
|
7
|
+
*
|
|
8
|
+
* The only thing that should come from the environment is the mode itself —
|
|
9
|
+
* which entry applies — never the values.
|
|
10
|
+
*/
|
|
11
|
+
export interface JourneyRuntimeOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Fast-forward factor for every duration in a journey — delays, random
|
|
14
|
+
* delays, wait timeouts, goal and `performed(within)` windows scale
|
|
15
|
+
* together (see engine/time-scale.ts). 3600 turns "2 days" into 48 s.
|
|
16
|
+
* 1 (the default) is real time; anything else belongs to development only:
|
|
17
|
+
* the `production` entry's type admits no other value (`ProductionRuntimeOptions`).
|
|
18
|
+
*/
|
|
19
|
+
timeScale?: number;
|
|
20
|
+
/** Log every outbound message (channel, template, recipient, resolved props) as it is sent. */
|
|
21
|
+
logMessages?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The `production` entry: real time, in the type. A fast-forwarded production (every delay,
|
|
25
|
+
* goal window and segment window of every user compressed alike, a week of journey mail in
|
|
26
|
+
* minutes) has only ever been a slip — a `development` entry pasted under the wrong key, a
|
|
27
|
+
* factor left in after a rehearsal — so `timeScale` here is `1` or absent, and the slip is a
|
|
28
|
+
* compile error where it is written rather than a flood of messages where it runs. A deploy that
|
|
29
|
+
* is meant to run fast is not production: give it a mode of its own (`ENVIRONMENT=rehearsal`),
|
|
30
|
+
* which is as free as `development`.
|
|
31
|
+
*/
|
|
32
|
+
export type ProductionRuntimeOptions = Omit<JourneyRuntimeOptions, 'timeScale'> & {
|
|
33
|
+
timeScale?: 1;
|
|
34
|
+
};
|
|
35
|
+
/** Environments a project distinguishes; any string works, these two are the conventional ones. */
|
|
36
|
+
export type JourneyMode = 'development' | 'production' | (string & {});
|
|
37
|
+
/**
|
|
38
|
+
* One options entry per mode. Missing modes run with the defaults (real time, quiet). Only
|
|
39
|
+
* `production` is held to real time; a mode under any other name is as free as `development`.
|
|
40
|
+
*/
|
|
41
|
+
export type JourneyRuntimeConfig = { [mode in JourneyMode]?: mode extends 'production' ? ProductionRuntimeOptions : JourneyRuntimeOptions; };
|
|
42
|
+
/** The options for `mode`, defaults filled in; `config` may be absent altogether. */
|
|
43
|
+
export declare function resolveRuntime(config: JourneyRuntimeConfig | undefined, mode: JourneyMode): Required<JourneyRuntimeOptions>;
|
|
44
|
+
//# sourceMappingURL=runtime.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/runtime.ts"],"mappings":";;;;;;;;;;iBAWiB;;;;;;;;EAQf;;EAEA;;;;;;;;;;;YAYU,2BAA2B,KAAK;EAAwC;;;YAGxE;;;;;YAMA,0BACT,QAAQ,eAAe,4BACpB,2BACA;;wBAMU,eACd,QAAQ,kCACR,MAAM,cACL,SAAS"}
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/runtime.ts
|
|
2
|
+
const DEFAULTS = {
|
|
3
|
+
timeScale: 1,
|
|
4
|
+
logMessages: false
|
|
5
|
+
};
|
|
6
|
+
/** The options for `mode`, defaults filled in; `config` may be absent altogether. */
|
|
7
|
+
function resolveRuntime(config, mode) {
|
|
8
|
+
const entry = config?.[mode] ?? {};
|
|
9
|
+
const timeScale = entry.timeScale ?? DEFAULTS.timeScale;
|
|
10
|
+
return {
|
|
11
|
+
timeScale: Number.isFinite(timeScale) && timeScale > 0 ? timeScale : DEFAULTS.timeScale,
|
|
12
|
+
logMessages: entry.logMessages ?? DEFAULTS.logMessages
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export { resolveRuntime };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["/**\n * Runtime options — how the engine should behave in a given environment, as\n * typed configuration rather than loose environment variables. A project keeps\n * one `JourneyRuntimeConfig` (typically in its `workflow.config.ts`, next to the\n * studio settings) with one entry per mode; the host resolves the entry for\n * the environment it is running in and hands it to the runner.\n *\n * The only thing that should come from the environment is the mode itself —\n * which entry applies — never the values.\n */\n\nexport interface JourneyRuntimeOptions {\n /**\n * Fast-forward factor for every duration in a journey — delays, random\n * delays, wait timeouts, goal and `performed(within)` windows scale\n * together (see engine/time-scale.ts). 3600 turns \"2 days\" into 48 s.\n * 1 (the default) is real time; anything else belongs to development only:\n * the `production` entry's type admits no other value (`ProductionRuntimeOptions`).\n */\n timeScale?: number;\n /** Log every outbound message (channel, template, recipient, resolved props) as it is sent. */\n logMessages?: boolean;\n}\n\n/**\n * The `production` entry: real time, in the type. A fast-forwarded production (every delay,\n * goal window and segment window of every user compressed alike, a week of journey mail in\n * minutes) has only ever been a slip — a `development` entry pasted under the wrong key, a\n * factor left in after a rehearsal — so `timeScale` here is `1` or absent, and the slip is a\n * compile error where it is written rather than a flood of messages where it runs. A deploy that\n * is meant to run fast is not production: give it a mode of its own (`ENVIRONMENT=rehearsal`),\n * which is as free as `development`.\n */\nexport type ProductionRuntimeOptions = Omit<JourneyRuntimeOptions, 'timeScale'> & { timeScale?: 1 };\n\n/** Environments a project distinguishes; any string works, these two are the conventional ones. */\nexport type JourneyMode = 'development' | 'production' | (string & {});\n\n/**\n * One options entry per mode. Missing modes run with the defaults (real time, quiet). Only\n * `production` is held to real time; a mode under any other name is as free as `development`.\n */\nexport type JourneyRuntimeConfig = {\n [mode in JourneyMode]?: mode extends 'production'\n ? ProductionRuntimeOptions\n : JourneyRuntimeOptions;\n};\n\nconst DEFAULTS: Required<JourneyRuntimeOptions> = { timeScale: 1, logMessages: false };\n\n/** The options for `mode`, defaults filled in; `config` may be absent altogether. */\nexport function resolveRuntime(\n config: JourneyRuntimeConfig | undefined,\n mode: JourneyMode\n): Required<JourneyRuntimeOptions> {\n const entry = config?.[mode] ?? {};\n const timeScale = entry.timeScale ?? DEFAULTS.timeScale;\n return {\n timeScale: Number.isFinite(timeScale) && timeScale > 0 ? timeScale : DEFAULTS.timeScale,\n logMessages: entry.logMessages ?? DEFAULTS.logMessages,\n };\n}\n"],"mappings":";AAgDA,MAAM,WAA4C;CAAE,WAAW;CAAG,aAAa;AAAM;;AAGrF,SAAgB,eACd,QACA,MACiC;CACjC,MAAM,QAAQ,SAAS,SAAS,CAAC;CACjC,MAAM,YAAY,MAAM,aAAa,SAAS;CAC9C,OAAO;EACL,WAAW,OAAO,SAAS,SAAS,KAAK,YAAY,IAAI,YAAY,SAAS;EAC9E,aAAa,MAAM,eAAe,SAAS;CAC7C;AACF"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_engine_recipient = require("../engine/recipient.cjs");
|
|
3
|
+
require("./facts.cjs");
|
|
4
|
+
// src/store/condition-sql.ts
|
|
5
|
+
const UNKNOWN = "NULL::boolean";
|
|
6
|
+
/** `to_timestamp`, as every other read of `ts` in the store writes it. */
|
|
7
|
+
const timestamp = (param) => `to_timestamp(${param}::double precision / 1000)`;
|
|
8
|
+
function conditionToSql(condition, context) {
|
|
9
|
+
if (JSON.stringify(condition).includes("\\u0000")) return UNKNOWN;
|
|
10
|
+
return compile(condition, context, []);
|
|
11
|
+
}
|
|
12
|
+
function compile(condition, context, enclosing) {
|
|
13
|
+
switch (condition.type) {
|
|
14
|
+
case "and": return join(condition.conditions.map((child) => compile(child, context, enclosing)), "AND", "TRUE");
|
|
15
|
+
case "or": return join(condition.conditions.map((child) => compile(child, context, enclosing)), "OR", "FALSE");
|
|
16
|
+
case "not": return `(NOT ${compile(condition.condition, context, enclosing)})`;
|
|
17
|
+
case "segment": {
|
|
18
|
+
const definition = context.segments.get(condition.segment);
|
|
19
|
+
if (definition === void 0 || enclosing.includes(condition.segment)) return UNKNOWN;
|
|
20
|
+
return compile(definition, context, [...enclosing, condition.segment]);
|
|
21
|
+
}
|
|
22
|
+
case "performed": return performed(condition, context);
|
|
23
|
+
case "property": return compare(condition, once(() => profileScalar(condition.path, context)), context);
|
|
24
|
+
case "reachable": return reachable(condition.channel, context);
|
|
25
|
+
case "payload":
|
|
26
|
+
case "trigger_payload": return UNKNOWN;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function once(make) {
|
|
30
|
+
let made;
|
|
31
|
+
return () => made ??= make();
|
|
32
|
+
}
|
|
33
|
+
function join(parts, operator, empty) {
|
|
34
|
+
return parts.length === 0 ? empty : `(${parts.join(` ${operator} `)})`;
|
|
35
|
+
}
|
|
36
|
+
/** Mirrors `JourneyFactSource.countEvents`: the window's bounds are inclusive at both ends. */
|
|
37
|
+
function performed(condition, context) {
|
|
38
|
+
const atLeast = Math.ceil(condition.count ?? 1);
|
|
39
|
+
if (!Number.isSafeInteger(atLeast)) return UNKNOWN;
|
|
40
|
+
if (atLeast <= 0) return "TRUE";
|
|
41
|
+
const since = condition.within === void 0 ? void 0 : context.nowMs - condition.within.ms;
|
|
42
|
+
if (since !== void 0 && !Number.isFinite(since)) return UNKNOWN;
|
|
43
|
+
let events = `SELECT 1 FROM ${context.tables.event} ev WHERE ev.user_id = ${context.user} AND ev.name = ${context.bind(condition.event)}::text`;
|
|
44
|
+
if (since !== void 0) events += ` AND ev.ts >= ${timestamp(context.bind(since))}`;
|
|
45
|
+
if (condition.where === void 0) return reaches(events, atLeast);
|
|
46
|
+
const where = whereToSql(condition.where, context);
|
|
47
|
+
return `(CASE WHEN ${reaches(`${events} AND (${where}) IS TRUE`, atLeast)} THEN TRUE WHEN ${reaches(`${events} AND (${where}) IS NOT FALSE`, atLeast)} THEN ${UNKNOWN} ELSE FALSE END)`;
|
|
48
|
+
}
|
|
49
|
+
/** Whether a query yields `atLeast` rows, stopping there: the (user_id, name, ts) index serves it. */
|
|
50
|
+
function reaches(query, atLeast) {
|
|
51
|
+
return atLeast === 1 ? `EXISTS (${query})` : `((SELECT count(*) FROM (${query} LIMIT ${String(atLeast)}) capped) >= ${String(atLeast)})`;
|
|
52
|
+
}
|
|
53
|
+
/** Mirrors `matchesWhere`, over the event row `ev`. */
|
|
54
|
+
function whereToSql(where, context) {
|
|
55
|
+
switch (where.type) {
|
|
56
|
+
case "and": return join(where.conditions.map((child) => whereToSql(child, context)), "AND", "TRUE");
|
|
57
|
+
case "or": return join(where.conditions.map((child) => whereToSql(child, context)), "OR", "FALSE");
|
|
58
|
+
case "not": return `(NOT ${whereToSql(where.condition, context)})`;
|
|
59
|
+
case "payload": {
|
|
60
|
+
const keys = where.path.split(".");
|
|
61
|
+
if (!keys.every(isPlainKey)) return UNKNOWN;
|
|
62
|
+
const raw = once(() => keys.reduce((json, key) => `${json} -> ${context.bind(key)}::text`, "ev.payload"));
|
|
63
|
+
const present = () => `(jsonb_typeof(${raw()}) IS DISTINCT FROM 'null' AND ${raw()} IS NOT NULL)`;
|
|
64
|
+
if (where.op === "exists") return present();
|
|
65
|
+
if (where.op === "not_exists") return `(NOT ${present()})`;
|
|
66
|
+
return compare(where, once(() => scalarOf(raw())), context);
|
|
67
|
+
}
|
|
68
|
+
default: return UNKNOWN;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A key `valueAtPath` finds in plain JSON objects only. It indexes with `current[key]`, so a
|
|
73
|
+
* number reaches into an array, `length` reads an array's size and `toString` finds the prototype,
|
|
74
|
+
* none of which `->` does.
|
|
75
|
+
*/
|
|
76
|
+
function isPlainKey(key) {
|
|
77
|
+
return !/^\d+$/.test(key) && key !== "length" && !(key in Object.prototype);
|
|
78
|
+
}
|
|
79
|
+
/** The value if it is a JSON scalar, SQL NULL otherwise: a non-scalar reads as absent. */
|
|
80
|
+
function scalarOf(json) {
|
|
81
|
+
return `(CASE WHEN jsonb_typeof(${json}) IN ('string', 'number', 'boolean') THEN ${json} END)`;
|
|
82
|
+
}
|
|
83
|
+
/** Mirrors `JourneyFactSource.getProperty`. */
|
|
84
|
+
function profileScalar(path, context) {
|
|
85
|
+
if (path === "userId") return `to_jsonb(${context.user})`;
|
|
86
|
+
return scalarOf(`${context.props} -> ${context.bind(path)}::text`);
|
|
87
|
+
}
|
|
88
|
+
function reachable(channel, context) {
|
|
89
|
+
const suppressed = `EXISTS (SELECT 1 FROM ${context.tables.suppression} s WHERE s.user_id = ${context.user} AND s.channel = ${context.bind(channel)}::text AND s.topic IS NULL)`;
|
|
90
|
+
let address;
|
|
91
|
+
if (channel === "push") address = `EXISTS (SELECT 1 FROM ${context.tables.device} d WHERE d.user_id = ${context.user})`;
|
|
92
|
+
else {
|
|
93
|
+
const path = require_engine_recipient.RECIPIENT_PROPERTY[channel];
|
|
94
|
+
address = path === void 0 ? "TRUE" : `${profileScalar(path, context)} IS NOT NULL`;
|
|
95
|
+
}
|
|
96
|
+
return `(NOT ${suppressed} AND ${address})`;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Mirrors `compareProperty`. `actual` yields a jsonb scalar, or SQL NULL for "undefined". It is
|
|
100
|
+
* asked for only by a branch that uses it: Postgres cannot type a parameter no statement mentions,
|
|
101
|
+
* so an operator that needs no value (`between` without a range) must not bind one.
|
|
102
|
+
*/
|
|
103
|
+
function compare(condition, actual, context) {
|
|
104
|
+
const { value, values } = condition;
|
|
105
|
+
const json = (scalar) => `${context.bind(JSON.stringify(scalar))}::text::jsonb`;
|
|
106
|
+
const isIn = () => (values ?? []).length === 0 ? "FALSE" : `COALESCE(${actual()} IN (${(values ?? []).map(json).join(", ")}), FALSE)`;
|
|
107
|
+
const isBetween = () => {
|
|
108
|
+
if (values === void 0 || values.length < 2) return "FALSE";
|
|
109
|
+
const [min, max] = values;
|
|
110
|
+
return `(${order(actual, ">=", min, context)} AND ${order(actual, "<=", max, context)})`;
|
|
111
|
+
};
|
|
112
|
+
const contains = () => typeof value === "string" ? `COALESCE(jsonb_typeof(${actual()}) = 'string' AND strpos(${actual()} #>> '{}', ${context.bind(value)}::text) > 0, FALSE)` : "FALSE";
|
|
113
|
+
switch (condition.op) {
|
|
114
|
+
case "exists": return `(${actual()} IS NOT NULL)`;
|
|
115
|
+
case "not_exists": return `(${actual()} IS NULL)`;
|
|
116
|
+
case "eq": return value === void 0 ? `(${actual()} IS NULL)` : `COALESCE(${actual()} = ${json(value)}, FALSE)`;
|
|
117
|
+
case "ne": return value === void 0 ? `(${actual()} IS NOT NULL)` : `(${actual()} IS DISTINCT FROM ${json(value)})`;
|
|
118
|
+
case "gt": return order(actual, ">", value, context);
|
|
119
|
+
case "gte": return order(actual, ">=", value, context);
|
|
120
|
+
case "lt": return order(actual, "<", value, context);
|
|
121
|
+
case "lte": return order(actual, "<=", value, context);
|
|
122
|
+
case "between": return isBetween();
|
|
123
|
+
case "not_between": return `(NOT ${isBetween()})`;
|
|
124
|
+
case "in_array": return isIn();
|
|
125
|
+
case "not_in_array": return `(NOT ${isIn()})`;
|
|
126
|
+
case "contains": return contains();
|
|
127
|
+
case "not_contains": return `(NOT ${contains()})`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* An ordering of two values of one type; across types JavaScript coerces, so that is the
|
|
132
|
+
* evaluator's to answer. Strings compare by code point, what `COLLATE "C"` does on UTF-8: JavaScript
|
|
133
|
+
* compares UTF-16 units, which differs only between an astral character and U+E000 to U+FFFF.
|
|
134
|
+
*/
|
|
135
|
+
function order(scalar, operator, value, context) {
|
|
136
|
+
if (value === void 0) return "FALSE";
|
|
137
|
+
const actual = scalar();
|
|
138
|
+
let same = UNKNOWN;
|
|
139
|
+
if (typeof value === "number" && Number.isFinite(value)) same = `(CASE WHEN jsonb_typeof(${actual}) = 'number' THEN (${actual})::numeric ${operator} ${`${context.bind(String(value))}::text::numeric`} END)`;
|
|
140
|
+
else if (typeof value === "string") same = `(CASE WHEN jsonb_typeof(${actual}) = 'string' THEN (${actual} #>> '{}') COLLATE "C" ${operator} ${`${context.bind(value)}::text`} END)`;
|
|
141
|
+
return `(CASE WHEN ${actual} IS NULL THEN FALSE ELSE ${same} END)`;
|
|
142
|
+
}
|
|
143
|
+
exports.conditionToSql = conditionToSql;
|
|
144
|
+
|
|
145
|
+
//# sourceMappingURL=condition-sql.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-sql.cjs","names":["RECIPIENT_PROPERTY"],"sources":["../../src/store/condition-sql.ts"],"sourcesContent":["import { RECIPIENT_PROPERTY } from '../engine/recipient';\nimport type { ConditionIR, PropertyOperatorIR, ScalarIR } from '../ir';\nimport { USER_ID_PROPERTY } from './facts';\n\n/**\n * A condition as one SQL boolean over a whole set of users, for the segment sweep: where\n * `engine/condition.ts` asks about one user in several round trips, this asks about all of them\n * in one statement.\n *\n * `engine/condition.ts` stays the authority, and this only narrows down who it has to look at.\n * So the result is three-valued: TRUE and FALSE state what the evaluator would answer, and NULL\n * means \"ask the evaluator\". SQL's AND, OR and NOT carry a NULL exactly as far as it can affect\n * the outcome, so a leaf that cannot match JavaScript's semantics returns NULL and nothing above\n * it has to know. That covers what SQL has no clean form for: a comparison across types (`'5' > 3`\n * coerces in JavaScript), a segment that is unknown or reaches itself (the evaluator throws, and\n * its error is the one to report), hand-built IR.\n *\n * Injection: nothing from the condition is ever written into the statement. Every name, path and\n * value goes through `bind`, as does the clock; the only other text is this file's own SQL, the\n * store's table names and a count checked to be an integer. Keep it that way: a segment id or a\n * property path is data, however trusted the bundle that carries it.\n */\n\nexport interface ConditionSqlContext {\n /** The qualified tables the condition reads. */\n tables: { event: string; suppression: string; device: string };\n /** The column holding the user id. */\n user: string;\n /** The column holding the user's profile props, NULL when there is no profile. */\n props: string;\n nowMs: number;\n /** Every deployed segment, for `segment(...)` references. */\n segments: ReadonlyMap<string, ConditionIR>;\n /** Registers a parameter and returns its placeholder (`$3`). */\n bind(value: unknown): string;\n}\n\nconst UNKNOWN = 'NULL::boolean';\n\n/** `to_timestamp`, as every other read of `ts` in the store writes it. */\nconst timestamp = (param: string) => `to_timestamp(${param}::double precision / 1000)`;\n\nexport function conditionToSql(condition: ConditionIR, context: ConditionSqlContext): string {\n // Postgres refuses NUL in text and jsonb, and one bad parameter would fail the statement for\n // every segment on the page. JSON escapes it, so this sees it wherever the tree holds it.\n if (JSON.stringify(condition).includes('\\\\u0000')) return UNKNOWN;\n return compile(condition, context, []);\n}\n\nfunction compile(\n condition: ConditionIR,\n context: ConditionSqlContext,\n enclosing: readonly string[]\n): string {\n switch (condition.type) {\n case 'and':\n return join(\n condition.conditions.map((child) => compile(child, context, enclosing)),\n 'AND',\n 'TRUE'\n );\n case 'or':\n return join(\n condition.conditions.map((child) => compile(child, context, enclosing)),\n 'OR',\n 'FALSE'\n );\n case 'not':\n return `(NOT ${compile(condition.condition, context, enclosing)})`;\n case 'segment': {\n const definition = context.segments.get(condition.segment);\n if (definition === undefined || enclosing.includes(condition.segment)) return UNKNOWN;\n return compile(definition, context, [...enclosing, condition.segment]);\n }\n case 'performed':\n return performed(condition, context);\n case 'property':\n return compare(\n condition,\n once(() => profileScalar(condition.path, context)),\n context\n );\n case 'reachable':\n return reachable(condition.channel, context);\n case 'payload':\n case 'trigger_payload':\n // The evaluator rejects both here: a payload condition outside a where clause, and a\n // trigger payload condition where there is no journey\n return UNKNOWN;\n }\n}\n\nfunction once(make: () => string): () => string {\n let made: string | undefined;\n return () => (made ??= make());\n}\n\nfunction join(parts: string[], operator: 'AND' | 'OR', empty: string): string {\n return parts.length === 0 ? empty : `(${parts.join(` ${operator} `)})`;\n}\n\n/** Mirrors `JourneyFactSource.countEvents`: the window's bounds are inclusive at both ends. */\nfunction performed(\n condition: Extract<ConditionIR, { type: 'performed' }>,\n context: ConditionSqlContext\n): string {\n const atLeast = Math.ceil(condition.count ?? 1);\n if (!Number.isSafeInteger(atLeast)) return UNKNOWN;\n if (atLeast <= 0) return 'TRUE'; // Every count is at least zero\n const since = condition.within === undefined ? undefined : context.nowMs - condition.within.ms;\n // Before anything is bound: to_timestamp would fail the whole statement on it\n if (since !== undefined && !Number.isFinite(since)) return UNKNOWN;\n let events =\n `SELECT 1 FROM ${context.tables.event} ev ` +\n `WHERE ev.user_id = ${context.user} AND ev.name = ${context.bind(condition.event)}::text`;\n if (since !== undefined) events += ` AND ev.ts >= ${timestamp(context.bind(since))}`;\n if (condition.where === undefined) return reaches(events, atLeast);\n const where = whereToSql(condition.where, context);\n // An event the where clause cannot decide may or may not count\n const certain = reaches(`${events} AND (${where}) IS TRUE`, atLeast);\n const possible = reaches(`${events} AND (${where}) IS NOT FALSE`, atLeast);\n return `(CASE WHEN ${certain} THEN TRUE WHEN ${possible} THEN ${UNKNOWN} ELSE FALSE END)`;\n}\n\n/** Whether a query yields `atLeast` rows, stopping there: the (user_id, name, ts) index serves it. */\nfunction reaches(query: string, atLeast: number): string {\n return atLeast === 1\n ? `EXISTS (${query})`\n : `((SELECT count(*) FROM (${query} LIMIT ${String(atLeast)}) capped) >= ${String(atLeast)})`;\n}\n\n/** Mirrors `matchesWhere`, over the event row `ev`. */\nfunction whereToSql(where: ConditionIR, context: ConditionSqlContext): string {\n switch (where.type) {\n case 'and':\n return join(\n where.conditions.map((child) => whereToSql(child, context)),\n 'AND',\n 'TRUE'\n );\n case 'or':\n return join(\n where.conditions.map((child) => whereToSql(child, context)),\n 'OR',\n 'FALSE'\n );\n case 'not':\n return `(NOT ${whereToSql(where.condition, context)})`;\n case 'payload': {\n const keys = where.path.split('.');\n if (!keys.every(isPlainKey)) return UNKNOWN;\n const raw = once(() =>\n keys.reduce((json, key) => `${json} -> ${context.bind(key)}::text`, 'ev.payload')\n );\n // Unlike a comparison, exists sees objects and arrays too; only JSON null reads as missing\n const present = () =>\n `(jsonb_typeof(${raw()}) IS DISTINCT FROM 'null' AND ${raw()} IS NOT NULL)`;\n if (where.op === 'exists') return present();\n if (where.op === 'not_exists') return `(NOT ${present()})`;\n return compare(\n where,\n once(() => scalarOf(raw())),\n context\n );\n }\n default:\n // Compile rejects these, and the evaluator throws on hand-built IR\n return UNKNOWN;\n }\n}\n\n/**\n * A key `valueAtPath` finds in plain JSON objects only. It indexes with `current[key]`, so a\n * number reaches into an array, `length` reads an array's size and `toString` finds the prototype,\n * none of which `->` does.\n */\nfunction isPlainKey(key: string): boolean {\n return !/^\\d+$/.test(key) && key !== 'length' && !(key in Object.prototype);\n}\n\n/** The value if it is a JSON scalar, SQL NULL otherwise: a non-scalar reads as absent. */\nfunction scalarOf(json: string): string {\n return `(CASE WHEN jsonb_typeof(${json}) IN ('string', 'number', 'boolean') THEN ${json} END)`;\n}\n\n/** Mirrors `JourneyFactSource.getProperty`. */\nfunction profileScalar(path: string, context: ConditionSqlContext): string {\n if (path === USER_ID_PROPERTY) return `to_jsonb(${context.user})`;\n return scalarOf(`${context.props} -> ${context.bind(path)}::text`);\n}\n\nfunction reachable(\n channel: Extract<ConditionIR, { type: 'reachable' }>['channel'],\n context: ConditionSqlContext\n): string {\n // The channel-wide opt-out only, as in the evaluator: its row has no topic\n const suppressed =\n `EXISTS (SELECT 1 FROM ${context.tables.suppression} s ` +\n `WHERE s.user_id = ${context.user} AND s.channel = ${context.bind(channel)}::text AND s.topic IS NULL)`;\n let address: string;\n if (channel === 'push') {\n address = `EXISTS (SELECT 1 FROM ${context.tables.device} d WHERE d.user_id = ${context.user})`;\n } else {\n const path = RECIPIENT_PROPERTY[channel];\n address = path === undefined ? 'TRUE' : `${profileScalar(path, context)} IS NOT NULL`;\n }\n return `(NOT ${suppressed} AND ${address})`;\n}\n\n/**\n * Mirrors `compareProperty`. `actual` yields a jsonb scalar, or SQL NULL for \"undefined\". It is\n * asked for only by a branch that uses it: Postgres cannot type a parameter no statement mentions,\n * so an operator that needs no value (`between` without a range) must not bind one.\n */\nfunction compare(\n condition: {\n op: PropertyOperatorIR;\n value?: ScalarIR | undefined;\n values?: ScalarIR[] | undefined;\n },\n actual: () => string,\n context: ConditionSqlContext\n): string {\n const { value, values } = condition;\n const json = (scalar: ScalarIR) => `${context.bind(JSON.stringify(scalar))}::text::jsonb`;\n const isIn = () =>\n (values ?? []).length === 0\n ? 'FALSE'\n : `COALESCE(${actual()} IN (${(values ?? []).map(json).join(', ')}), FALSE)`;\n const isBetween = () => {\n if (values === undefined || values.length < 2) return 'FALSE';\n const [min, max] = values as [ScalarIR, ScalarIR, ...ScalarIR[]];\n return `(${order(actual, '>=', min, context)} AND ${order(actual, '<=', max, context)})`;\n };\n const contains = () =>\n typeof value === 'string'\n ? `COALESCE(jsonb_typeof(${actual()}) = 'string' AND strpos(${actual()} #>> '{}', ${context.bind(value)}::text) > 0, FALSE)`\n : 'FALSE';\n switch (condition.op) {\n case 'exists':\n return `(${actual()} IS NOT NULL)`;\n case 'not_exists':\n return `(${actual()} IS NULL)`;\n case 'eq':\n return value === undefined\n ? `(${actual()} IS NULL)`\n : `COALESCE(${actual()} = ${json(value)}, FALSE)`;\n case 'ne':\n return value === undefined\n ? `(${actual()} IS NOT NULL)`\n : `(${actual()} IS DISTINCT FROM ${json(value)})`;\n case 'gt':\n return order(actual, '>', value, context);\n case 'gte':\n return order(actual, '>=', value, context);\n case 'lt':\n return order(actual, '<', value, context);\n case 'lte':\n return order(actual, '<=', value, context);\n case 'between':\n return isBetween();\n case 'not_between':\n return `(NOT ${isBetween()})`;\n case 'in_array':\n return isIn();\n case 'not_in_array':\n return `(NOT ${isIn()})`;\n case 'contains':\n return contains();\n case 'not_contains':\n return `(NOT ${contains()})`;\n }\n}\n\n/**\n * An ordering of two values of one type; across types JavaScript coerces, so that is the\n * evaluator's to answer. Strings compare by code point, what `COLLATE \"C\"` does on UTF-8: JavaScript\n * compares UTF-16 units, which differs only between an astral character and U+E000 to U+FFFF.\n */\nfunction order(\n scalar: () => string,\n operator: '>' | '>=' | '<' | '<=',\n value: ScalarIR | undefined,\n context: ConditionSqlContext\n): string {\n if (value === undefined) return 'FALSE';\n const actual = scalar();\n let same = UNKNOWN;\n if (typeof value === 'number' && Number.isFinite(value)) {\n const bound = `${context.bind(String(value))}::text::numeric`;\n same = `(CASE WHEN jsonb_typeof(${actual}) = 'number' THEN (${actual})::numeric ${operator} ${bound} END)`;\n } else if (typeof value === 'string') {\n const bound = `${context.bind(value)}::text`;\n same = `(CASE WHEN jsonb_typeof(${actual}) = 'string' THEN (${actual} #>> '{}') COLLATE \"C\" ${operator} ${bound} END)`;\n }\n return `(CASE WHEN ${actual} IS NULL THEN FALSE ELSE ${same} END)`;\n}\n"],"mappings":";;;;AAqCA,MAAM,UAAU;;AAGhB,MAAM,aAAa,UAAkB,gBAAgB,MAAM;AAE3D,SAAgB,eAAe,WAAwB,SAAsC;CAG3F,IAAI,KAAK,UAAU,SAAS,CAAC,CAAC,SAAS,SAAS,GAAG,OAAO;CAC1D,OAAO,QAAQ,WAAW,SAAS,CAAC,CAAC;AACvC;AAEA,SAAS,QACP,WACA,SACA,WACQ;CACR,QAAQ,UAAU,MAAlB;EACE,KAAK,OACH,OAAO,KACL,UAAU,WAAW,KAAK,UAAU,QAAQ,OAAO,SAAS,SAAS,CAAC,GACtE,OACA,MACF;EACF,KAAK,MACH,OAAO,KACL,UAAU,WAAW,KAAK,UAAU,QAAQ,OAAO,SAAS,SAAS,CAAC,GACtE,MACA,OACF;EACF,KAAK,OACH,OAAO,QAAQ,QAAQ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ConditionIR } from "../ir.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* A condition as one SQL boolean over a whole set of users, for the segment sweep: where
|
|
4
|
+
* `engine/condition.ts` asks about one user in several round trips, this asks about all of them
|
|
5
|
+
* in one statement.
|
|
6
|
+
*
|
|
7
|
+
* `engine/condition.ts` stays the authority, and this only narrows down who it has to look at.
|
|
8
|
+
* So the result is three-valued: TRUE and FALSE state what the evaluator would answer, and NULL
|
|
9
|
+
* means "ask the evaluator". SQL's AND, OR and NOT carry a NULL exactly as far as it can affect
|
|
10
|
+
* the outcome, so a leaf that cannot match JavaScript's semantics returns NULL and nothing above
|
|
11
|
+
* it has to know. That covers what SQL has no clean form for: a comparison across types (`'5' > 3`
|
|
12
|
+
* coerces in JavaScript), a segment that is unknown or reaches itself (the evaluator throws, and
|
|
13
|
+
* its error is the one to report), hand-built IR.
|
|
14
|
+
*
|
|
15
|
+
* Injection: nothing from the condition is ever written into the statement. Every name, path and
|
|
16
|
+
* value goes through `bind`, as does the clock; the only other text is this file's own SQL, the
|
|
17
|
+
* store's table names and a count checked to be an integer. Keep it that way: a segment id or a
|
|
18
|
+
* property path is data, however trusted the bundle that carries it.
|
|
19
|
+
*/
|
|
20
|
+
export interface ConditionSqlContext {
|
|
21
|
+
/** The qualified tables the condition reads. */
|
|
22
|
+
tables: {
|
|
23
|
+
event: string;
|
|
24
|
+
suppression: string;
|
|
25
|
+
device: string;
|
|
26
|
+
};
|
|
27
|
+
/** The column holding the user id. */
|
|
28
|
+
user: string;
|
|
29
|
+
/** The column holding the user's profile props, NULL when there is no profile. */
|
|
30
|
+
props: string;
|
|
31
|
+
nowMs: number;
|
|
32
|
+
/** Every deployed segment, for `segment(...)` references. */
|
|
33
|
+
segments: ReadonlyMap<string, ConditionIR>;
|
|
34
|
+
/** Registers a parameter and returns its placeholder (`$3`). */
|
|
35
|
+
bind(value: unknown): string;
|
|
36
|
+
}
|
|
37
|
+
export declare function conditionToSql(condition: ConditionIR, context: ConditionSqlContext): string;
|
|
38
|
+
//# sourceMappingURL=condition-sql.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-sql.d.cts","names":[],"sources":["../../src/store/condition-sql.ts"],"mappings":";;;;;;;;;;;;;;;;;;;iBAuBiB;;EAEf;IAAU;IAAe;IAAqB;;;EAE9C;;EAEA;EACA;;EAEA,UAAU,oBAAoB;;EAE9B,KAAK;;wBAQS,eAAe,WAAW,aAAa,SAAS"}
|