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,222 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_dsl_refs = require("./dsl/refs.cjs");
|
|
4
|
+
let zod_mini = require("zod/mini");
|
|
5
|
+
require("./dsl/index.cjs");
|
|
6
|
+
zod_mini = require_runtime.__toESM(zod_mini, 1);
|
|
7
|
+
// src/contract.ts
|
|
8
|
+
/** A topic id: what goes in a URL, a JSON key and a database column, so no spaces or specials. */
|
|
9
|
+
const TOPIC_ID = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
10
|
+
function defineContract(definition) {
|
|
11
|
+
const topics = [...definition.subscriptions?.topics ?? []];
|
|
12
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const topic of topics) {
|
|
14
|
+
if (typeof topic !== "string" || !TOPIC_ID.test(topic)) throw new TypeError(`contract subscriptions.topics: '${topic}' is not a topic id (letters, digits, '_', '-' and '.', starting with a letter or digit)`);
|
|
15
|
+
if (seen.has(topic)) throw new TypeError(`contract subscriptions.topics lists '${topic}' twice`);
|
|
16
|
+
seen.add(topic);
|
|
17
|
+
}
|
|
18
|
+
for (const [name, schema] of Object.entries(definition.events)) {
|
|
19
|
+
if (name.startsWith("$")) throw new TypeError(`contract event '${name}': names starting with $ are reserved`);
|
|
20
|
+
assertJsonSchema(schema, `event '${name}'`, true);
|
|
21
|
+
}
|
|
22
|
+
assertJsonSchema(definition.profile, "profile", true);
|
|
23
|
+
const profileShape = definition.profile._zod.def.shape;
|
|
24
|
+
for (const [field, schema] of Object.entries(profileShape)) assertFlatScalar(schema, `profile.${field}`);
|
|
25
|
+
const strictProfile = definition.profile._zod.def.catchall?._zod.def.type === "never";
|
|
26
|
+
const names = Object.keys(definition.events);
|
|
27
|
+
return {
|
|
28
|
+
kind: "journey-contract",
|
|
29
|
+
events: require_dsl_refs.event(),
|
|
30
|
+
user: require_dsl_refs.user(),
|
|
31
|
+
schemas: {
|
|
32
|
+
events: definition.events,
|
|
33
|
+
profile: definition.profile
|
|
34
|
+
},
|
|
35
|
+
eventNames: names,
|
|
36
|
+
topics,
|
|
37
|
+
isTopic: (topic) => seen.has(topic),
|
|
38
|
+
isEvent: (name) => Object.hasOwn(definition.events, name),
|
|
39
|
+
parseEvent(name, payload) {
|
|
40
|
+
if (!Object.hasOwn(definition.events, name)) return {
|
|
41
|
+
ok: false,
|
|
42
|
+
issues: [{
|
|
43
|
+
path: "",
|
|
44
|
+
message: `unknown event '${name}'`
|
|
45
|
+
}]
|
|
46
|
+
};
|
|
47
|
+
return toResult(zod_mini.safeParse(definition.events[name], payload));
|
|
48
|
+
},
|
|
49
|
+
parseProfilePatch(patch) {
|
|
50
|
+
if (typeof patch !== "object" || patch === null || Array.isArray(patch)) return {
|
|
51
|
+
ok: false,
|
|
52
|
+
issues: [{
|
|
53
|
+
path: "",
|
|
54
|
+
message: "props must be an object"
|
|
55
|
+
}]
|
|
56
|
+
};
|
|
57
|
+
const issues = [];
|
|
58
|
+
const data = {};
|
|
59
|
+
for (const [field, value] of Object.entries(patch)) {
|
|
60
|
+
if (!Object.hasOwn(profileShape, field)) {
|
|
61
|
+
if (strictProfile || field === "userId") issues.push({
|
|
62
|
+
path: field,
|
|
63
|
+
message: "not a declared profile field"
|
|
64
|
+
});
|
|
65
|
+
else data[field] = value;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (value === null) {
|
|
69
|
+
data[field] = null;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const result = zod_mini.safeParse(profileShape[field], value);
|
|
73
|
+
if (result.success) data[field] = result.data;
|
|
74
|
+
else issues.push(...prefixed(field, result.error));
|
|
75
|
+
}
|
|
76
|
+
return issues.length > 0 ? {
|
|
77
|
+
ok: false,
|
|
78
|
+
issues
|
|
79
|
+
} : {
|
|
80
|
+
ok: true,
|
|
81
|
+
data
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* An event the contract refuses — raised for events a journey emits itself
|
|
88
|
+
* (`.sendEvent()`), which never pass the HTTP ingest: they go through the same
|
|
89
|
+
* check, and a refusal is deterministic, so it is not retried.
|
|
90
|
+
*/
|
|
91
|
+
var ContractValidationError = class extends Error {
|
|
92
|
+
event;
|
|
93
|
+
issues;
|
|
94
|
+
name = "ContractValidationError";
|
|
95
|
+
constructor(event, issues) {
|
|
96
|
+
super(`event '${event}' refused by the contract: ${issues.map((i) => `${i.path || "(root)"} ${i.message}`).join("; ")}`);
|
|
97
|
+
this.event = event;
|
|
98
|
+
this.issues = issues;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/** The one check every event passes, from HTTP or from a journey: declared, and its payload parses. */
|
|
102
|
+
function checkEvent(contract, name, payload) {
|
|
103
|
+
if (!contract.isEvent(name)) return {
|
|
104
|
+
ok: false,
|
|
105
|
+
issues: [{
|
|
106
|
+
path: "",
|
|
107
|
+
message: `'${String(name)}' is not in the contract`
|
|
108
|
+
}]
|
|
109
|
+
};
|
|
110
|
+
return contract.parseEvent(name, payload);
|
|
111
|
+
}
|
|
112
|
+
function isContract(value) {
|
|
113
|
+
return typeof value === "object" && value !== null && value.kind === "journey-contract";
|
|
114
|
+
}
|
|
115
|
+
function toResult(result) {
|
|
116
|
+
return result.success ? {
|
|
117
|
+
ok: true,
|
|
118
|
+
data: result.data
|
|
119
|
+
} : {
|
|
120
|
+
ok: false,
|
|
121
|
+
issues: prefixed("", result.error)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function prefixed(prefix, error) {
|
|
125
|
+
return error.issues.map((issue) => ({
|
|
126
|
+
path: [prefix, ...issue.path.map(String)].filter((p) => p !== "").join("."),
|
|
127
|
+
message: issue.message
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The schema types a contract may use — JSON shapes that parse synchronously
|
|
132
|
+
* and mean the same before and after parsing. Anything not listed (default,
|
|
133
|
+
* transform, pipe, lazy, promise, custom, date, bigint, …) is refused, and
|
|
134
|
+
* every container is walked so nothing unsupported hides inside one.
|
|
135
|
+
*/
|
|
136
|
+
const ALLOWED = /* @__PURE__ */ new Set([
|
|
137
|
+
"object",
|
|
138
|
+
"array",
|
|
139
|
+
"tuple",
|
|
140
|
+
"union",
|
|
141
|
+
"intersection",
|
|
142
|
+
"record",
|
|
143
|
+
"optional",
|
|
144
|
+
"nullable",
|
|
145
|
+
"readonly",
|
|
146
|
+
"nonoptional",
|
|
147
|
+
"string",
|
|
148
|
+
"number",
|
|
149
|
+
"boolean",
|
|
150
|
+
"null",
|
|
151
|
+
"enum",
|
|
152
|
+
"literal",
|
|
153
|
+
"unknown",
|
|
154
|
+
"any",
|
|
155
|
+
"never"
|
|
156
|
+
]);
|
|
157
|
+
/** Checks that change the value (`overwrite`: `.trim()`, `.toLowerCase()`, …) or run arbitrary code (`custom`: `.refine()`, async or not). */
|
|
158
|
+
const REFUSED_CHECKS = /* @__PURE__ */ new Set(["custom", "overwrite"]);
|
|
159
|
+
function assertJsonSchema(schema, where, top = false) {
|
|
160
|
+
const def = schema?._zod?.def;
|
|
161
|
+
if (def === void 0) throw new TypeError(`contract ${where}: not a Zod schema`);
|
|
162
|
+
if (top && def.type !== "object") throw new TypeError(`contract ${where}: must be an object schema (z.looseObject / z.strictObject)`);
|
|
163
|
+
if (!ALLOWED.has(def.type)) throw new TypeError(`contract ${where}: ${def.type} schemas are not supported (input and output must mean the same JSON, parsed synchronously)`);
|
|
164
|
+
if (def.coerce === true) throw new TypeError(`contract ${where}: coercion (z.coerce) is not supported`);
|
|
165
|
+
for (const check of def.checks ?? []) if (REFUSED_CHECKS.has(check._zod.def.check)) throw new TypeError(`contract ${where}: ${check._zod.def.check === "overwrite" ? "value-changing checks (.overwrite, .trim, …)" : "custom refinements"} are not supported`);
|
|
166
|
+
const children = [];
|
|
167
|
+
switch (def.type) {
|
|
168
|
+
case "object": {
|
|
169
|
+
const object = def;
|
|
170
|
+
for (const [k, v] of Object.entries(object.shape)) children.push([`${where}.${k}`, v]);
|
|
171
|
+
if (object.catchall !== void 0) children.push([`${where}.*`, object.catchall]);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case "optional":
|
|
175
|
+
case "nullable":
|
|
176
|
+
case "readonly":
|
|
177
|
+
case "nonoptional":
|
|
178
|
+
children.push([where, def.innerType]);
|
|
179
|
+
break;
|
|
180
|
+
case "array":
|
|
181
|
+
children.push([`${where}[]`, def.element]);
|
|
182
|
+
break;
|
|
183
|
+
case "tuple": {
|
|
184
|
+
const tuple = def;
|
|
185
|
+
tuple.items.forEach((item, index) => children.push([`${where}[${index}]`, item]));
|
|
186
|
+
if (tuple.rest !== null) children.push([`${where}[…]`, tuple.rest]);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case "union":
|
|
190
|
+
for (const option of def.options) children.push([where, option]);
|
|
191
|
+
break;
|
|
192
|
+
case "intersection": {
|
|
193
|
+
const intersection = def;
|
|
194
|
+
children.push([where, intersection.left], [where, intersection.right]);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "record": {
|
|
198
|
+
const record = def;
|
|
199
|
+
children.push([`${where}{key}`, record.keyType], [`${where}{}`, record.valueType]);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const [path, child] of children) assertJsonSchema(child, path);
|
|
204
|
+
}
|
|
205
|
+
const SCALARS = /* @__PURE__ */ new Set([
|
|
206
|
+
"string",
|
|
207
|
+
"number",
|
|
208
|
+
"boolean",
|
|
209
|
+
"enum",
|
|
210
|
+
"literal"
|
|
211
|
+
]);
|
|
212
|
+
function assertFlatScalar(schema, where) {
|
|
213
|
+
let def = schema._zod.def;
|
|
214
|
+
if (def.type === "optional") def = def.innerType._zod.def;
|
|
215
|
+
if (!SCALARS.has(def.type)) throw new TypeError(`contract ${where}: profile fields must be flat scalars (string, number, boolean, enum, literal), got ${def.type}`);
|
|
216
|
+
}
|
|
217
|
+
exports.ContractValidationError = ContractValidationError;
|
|
218
|
+
exports.checkEvent = checkEvent;
|
|
219
|
+
exports.defineContract = defineContract;
|
|
220
|
+
exports.isContract = isContract;
|
|
221
|
+
|
|
222
|
+
//# sourceMappingURL=contract.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.cjs","names":["event","user","z"],"sources":["../src/contract.ts"],"sourcesContent":["import * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport { type EventRefs, type UserRefs, event, user } from './dsl';\n\n/**\n * `defineContract({ events, profile, subscriptions? })` — the producer/engine contract as Zod\n * schemas, written once in a package both sides import. From it:\n *\n * - `contract.events` / `contract.user` are the DSL's typed reference tables\n * (what `event<E>()` / `user<U>()` used to be, now derived from the schemas);\n * - `contract.topics` are the subscription topics: every email and push template names one (or\n * is transactional), a user opts out of one at a time per channel, and the compile refuses a\n * topic the contract does not declare;\n * - `JourneyClient({ contract })` types `track` / `identify` by event name and\n * checks payloads before sending, and `getSubscriptions` / `setSubscriptions` by topic;\n * - `journeyWorker({ contract })` re-validates every inbound `/ingest`\n * and `/subscriptions` — never trusting the caller used the SDK — and refuses a bad\n * one with a 4xx before anything is stored, woken or started.\n *\n * Supported schemas (v1), synchronous and JSON-shaped: event payloads are\n * object schemas (`z.looseObject` keeps a producer's extra analytics fields,\n * `z.strictObject` refuses them) and may nest objects and arrays; the profile\n * is a flat object of string / number / boolean / enum / literal fields. Input\n * and output must mean the same thing, so defaults, transforms, coercion,\n * custom refinements and async checks are refused when the contract is\n * defined. The Zod instances stay in the host; nothing here changes the IR.\n */\n\ntype ObjectSchema = core.$ZodObject;\n\n/** The declared fields of an object schema — without a loose object's `[key: string]: unknown`, so the DSL only offers fields that were written down. */\nexport type DeclaredOutput<S> =\n S extends core.$ZodObject<infer Shape>\n ? core.$InferObjectOutput<Shape, core.$strict['out']>\n : never;\n\n/**\n * The subscription topics a producer and the engine agree on: content categories ('offers',\n * 'tips'), not channels — an email or push template declares one (`emailTemplate({ topic })`,\n * `pushTemplate({ topic })`), and a user opts out of a topic per channel (the preference page is\n * topic × channel). Ids only — display names belong to the app's i18n. A plain array literal\n * is enough: `defineContract` keeps the literals (no `as const` needed), and the union they form\n * types the templates, the config and `JourneyClient.setSubscriptions`.\n */\nexport interface SubscriptionsDefinition<T extends string> {\n topics: readonly T[];\n}\n\nexport interface ContractDefinition<\n E extends Record<string, ObjectSchema>,\n P extends ObjectSchema,\n T extends string = never,\n> {\n events: E;\n profile: P;\n /** The topics, e.g. `{ topics: ['promotions', 'newsletter'] }`; none without it (transactional email and push only). */\n subscriptions?: SubscriptionsDefinition<T>;\n}\n\n/** One rejected field, with the dotted path the producer can fix. */\nexport interface ContractIssue {\n path: string;\n message: string;\n}\n\nexport type ContractResult<T> = { ok: true; data: T } | { ok: false; issues: ContractIssue[] };\n\nexport interface Contract<\n E extends Record<string, ObjectSchema> = Record<string, ObjectSchema>,\n P extends ObjectSchema = ObjectSchema,\n T extends string = string,\n> {\n readonly kind: 'journey-contract';\n /** The declared subscription topics (`subscriptions.topics`), empty when none were declared. */\n readonly topics: readonly T[];\n isTopic(topic: string): topic is T;\n /** The DSL's event reference table: `e.purchase` — payload refs from the declared fields only. */\n readonly events: EventRefs<{ [K in keyof E]: DeclaredOutput<E[K]> }>;\n /** The DSL's user-property reference table: `u.name`, plus the system `u.userId`. */\n readonly user: UserRefs<DeclaredOutput<P> & { userId: string }>;\n /** The raw schemas, for hosts that need them (validation, docs). */\n readonly schemas: { readonly events: E; readonly profile: P };\n /** Every event name the contract declares — what a producer forwards. */\n readonly eventNames: readonly (keyof E & string)[];\n isEvent(name: string): name is keyof E & string;\n /** Validate one event's payload; the parsed value is what may be stored. */\n parseEvent<K extends keyof E & string>(\n name: K,\n payload: unknown\n ): ContractResult<core.output<E[K]>>;\n /**\n * Validate a profile merge patch: omitted fields stay as they are,\n * `null` removes a field, every provided value is checked against its field\n * schema, and an undeclared field is refused — a patch, never a full parse\n * that would fill defaults over fields the caller did not send.\n */\n parseProfilePatch(patch: unknown): ContractResult<ProfilePatch<P>>;\n}\n\n/** A patch over the profile: any subset of fields, `null` to remove one. */\nexport type ProfilePatch<P> = { [K in keyof DeclaredOutput<P>]?: DeclaredOutput<P>[K] | null };\n\n/** Payload type of one event, for producers: `EventPayload<typeof contract, 'purchase'>`. */\nexport type EventPayload<C, K extends string> =\n C extends Contract<infer E> ? (K extends keyof E ? core.input<E[K]> : never) : never;\n\n/** The topics a contract declares, as a union: `Topic<typeof contract>`; `never` without any. */\nexport type Topic<C> =\n C extends Contract<Record<string, ObjectSchema>, ObjectSchema, infer T> ? T : never;\n\n/** A topic id: what goes in a URL, a JSON key and a database column, so no spaces or specials. */\nconst TOPIC_ID = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;\n\nexport function defineContract<\n E extends Record<string, ObjectSchema>,\n P extends ObjectSchema,\n const T extends string = never,\n>(definition: ContractDefinition<E, P, T>): Contract<E, P, T> {\n const topics = [...(definition.subscriptions?.topics ?? [])];\n const seen = new Set<string>();\n for (const topic of topics) {\n if (typeof topic !== 'string' || !TOPIC_ID.test(topic)) {\n throw new TypeError(\n `contract subscriptions.topics: '${topic as string}' is not a topic id (letters, digits, '_', '-' and '.', starting with a letter or digit)`\n );\n }\n if (seen.has(topic))\n throw new TypeError(`contract subscriptions.topics lists '${topic}' twice`);\n seen.add(topic);\n }\n for (const [name, schema] of Object.entries(definition.events)) {\n if (name.startsWith('$')) {\n throw new TypeError(`contract event '${name}': names starting with $ are reserved`);\n }\n assertJsonSchema(schema, `event '${name}'`, true);\n }\n assertJsonSchema(definition.profile, 'profile', true);\n const profileShape = (definition.profile._zod.def as core.$ZodObjectDef).shape;\n for (const [field, schema] of Object.entries(profileShape)) {\n assertFlatScalar(schema, `profile.${field}`);\n }\n const strictProfile = definition.profile._zod.def.catchall?._zod.def.type === 'never';\n\n const names = Object.keys(definition.events) as (keyof E & string)[];\n return {\n kind: 'journey-contract',\n events: event() as never,\n user: user() as never,\n schemas: { events: definition.events, profile: definition.profile },\n eventNames: names,\n topics,\n isTopic: (topic): topic is T => seen.has(topic),\n isEvent: (name): name is keyof E & string => Object.hasOwn(definition.events, name),\n parseEvent(name, payload) {\n if (!Object.hasOwn(definition.events, name)) {\n return { ok: false, issues: [{ path: '', message: `unknown event '${name}'` }] };\n }\n return toResult(z.safeParse(definition.events[name], payload));\n },\n parseProfilePatch(patch) {\n if (typeof patch !== 'object' || patch === null || Array.isArray(patch)) {\n return { ok: false, issues: [{ path: '', message: 'props must be an object' }] };\n }\n const issues: ContractIssue[] = [];\n const data: Record<string, unknown> = {};\n for (const [field, value] of Object.entries(patch)) {\n if (!Object.hasOwn(profileShape, field)) {\n // userId is the request's identity, not a profile field\n if (strictProfile || field === 'userId') {\n issues.push({ path: field, message: 'not a declared profile field' });\n } else {\n data[field] = value;\n }\n continue;\n }\n if (value === null) {\n data[field] = null;\n continue;\n }\n const result = z.safeParse(profileShape[field], value);\n if (result.success) data[field] = result.data;\n else issues.push(...prefixed(field, result.error));\n }\n return issues.length > 0 ? { ok: false, issues } : { ok: true, data: data as never };\n },\n };\n}\n\n/**\n * An event the contract refuses — raised for events a journey emits itself\n * (`.sendEvent()`), which never pass the HTTP ingest: they go through the same\n * check, and a refusal is deterministic, so it is not retried.\n */\nexport class ContractValidationError extends Error {\n override readonly name = 'ContractValidationError';\n constructor(\n readonly event: string,\n readonly issues: ContractIssue[]\n ) {\n super(\n `event '${event}' refused by the contract: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n }\n}\n\n/** The one check every event passes, from HTTP or from a journey: declared, and its payload parses. */\nexport function checkEvent(\n contract: Contract,\n name: string,\n payload: unknown\n): ContractResult<Record<string, unknown>> {\n if (!contract.isEvent(name)) {\n return {\n ok: false,\n issues: [{ path: '', message: `'${String(name)}' is not in the contract` }],\n };\n }\n return contract.parseEvent(name, payload);\n}\n\nexport function isContract(value: unknown): value is Contract {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'journey-contract'\n );\n}\n\nfunction toResult<T>(result: core.util.SafeParseResult<T>): ContractResult<T> {\n return result.success\n ? { ok: true, data: result.data }\n : { ok: false, issues: prefixed('', result.error) };\n}\n\nfunction prefixed(prefix: string, error: core.$ZodError): ContractIssue[] {\n return error.issues.map((issue) => ({\n path: [prefix, ...issue.path.map(String)].filter((p) => p !== '').join('.'),\n message: issue.message,\n }));\n}\n\n/* ---------------------------- supported schemas ---------------------------- */\n\n/**\n * The schema types a contract may use — JSON shapes that parse synchronously\n * and mean the same before and after parsing. Anything not listed (default,\n * transform, pipe, lazy, promise, custom, date, bigint, …) is refused, and\n * every container is walked so nothing unsupported hides inside one.\n */\nconst ALLOWED = new Set([\n 'object',\n 'array',\n 'tuple',\n 'union',\n 'intersection',\n 'record',\n 'optional',\n 'nullable',\n 'readonly',\n 'nonoptional',\n 'string',\n 'number',\n 'boolean',\n 'null',\n 'enum',\n 'literal',\n 'unknown',\n 'any',\n 'never',\n]);\n\n/** Checks that change the value (`overwrite`: `.trim()`, `.toLowerCase()`, …) or run arbitrary code (`custom`: `.refine()`, async or not). */\nconst REFUSED_CHECKS = new Set(['custom', 'overwrite']);\n\nfunction assertJsonSchema(schema: unknown, where: string, top = false): void {\n const def = (schema as { _zod?: { def?: core.$ZodTypeDef } } | null | undefined)?._zod?.def;\n if (def === undefined) throw new TypeError(`contract ${where}: not a Zod schema`);\n if (top && def.type !== 'object') {\n throw new TypeError(\n `contract ${where}: must be an object schema (z.looseObject / z.strictObject)`\n );\n }\n if (!ALLOWED.has(def.type)) {\n throw new TypeError(\n `contract ${where}: ${def.type} schemas are not supported (input and output must mean the same JSON, parsed synchronously)`\n );\n }\n if ((def as { coerce?: boolean }).coerce === true) {\n throw new TypeError(`contract ${where}: coercion (z.coerce) is not supported`);\n }\n for (const check of def.checks ?? []) {\n if (REFUSED_CHECKS.has(check._zod.def.check)) {\n throw new TypeError(\n `contract ${where}: ${check._zod.def.check === 'overwrite' ? 'value-changing checks (.overwrite, .trim, …)' : 'custom refinements'} are not supported`\n );\n }\n }\n const children: [string, unknown][] = [];\n switch (def.type) {\n case 'object': {\n const object = def as core.$ZodObjectDef;\n for (const [k, v] of Object.entries(object.shape)) children.push([`${where}.${k}`, v]);\n if (object.catchall !== undefined) children.push([`${where}.*`, object.catchall]);\n break;\n }\n case 'optional':\n case 'nullable':\n case 'readonly':\n case 'nonoptional':\n children.push([where, (def as unknown as { innerType: unknown }).innerType]);\n break;\n case 'array':\n children.push([`${where}[]`, (def as core.$ZodArrayDef).element]);\n break;\n case 'tuple': {\n const tuple = def as core.$ZodTupleDef;\n tuple.items.forEach((item, index) => children.push([`${where}[${index}]`, item]));\n if (tuple.rest !== null) children.push([`${where}[…]`, tuple.rest]);\n break;\n }\n case 'union':\n for (const option of (def as core.$ZodUnionDef).options) children.push([where, option]);\n break;\n case 'intersection': {\n const intersection = def as core.$ZodIntersectionDef;\n children.push([where, intersection.left], [where, intersection.right]);\n break;\n }\n case 'record': {\n const record = def as core.$ZodRecordDef;\n children.push([`${where}{key}`, record.keyType], [`${where}{}`, record.valueType]);\n break;\n }\n default:\n break;\n }\n for (const [path, child] of children) assertJsonSchema(child, path);\n}\n\nconst SCALARS = new Set(['string', 'number', 'boolean', 'enum', 'literal']);\n\nfunction assertFlatScalar(schema: unknown, where: string): void {\n let def = (schema as core.$ZodType)._zod.def;\n if (def.type === 'optional') def = (def as core.$ZodOptionalDef).innerType._zod.def;\n if (!SCALARS.has(def.type)) {\n throw new TypeError(\n `contract ${where}: profile fields must be flat scalars (string, number, boolean, enum, literal), got ${def.type}`\n );\n }\n}\n"],"mappings":";;;;;;;;AA+GA,MAAM,WAAW;AAEjB,SAAgB,eAId,YAA4D;CAC5D,MAAM,SAAS,CAAC,GAAI,WAAW,eAAe,UAAU,CAAC,CAAE;CAC3D,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,SAAS,QAAQ;EAC1B,IAAI,OAAO,UAAU,YAAY,CAAC,SAAS,KAAK,KAAK,GACnD,MAAM,IAAI,UACR,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IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,GACvB,MAAM,IAAI,UACR,YAAY,MAAM,sFAAsF,IAAI,MAC9G;AAEJ"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { EventRefs, UserRefs } from "./dsl/refs.cjs";
|
|
2
|
+
import * as core from "zod/v4/core";
|
|
3
|
+
import "./dsl/index.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* `defineContract({ events, profile, subscriptions? })` — the producer/engine contract as Zod
|
|
6
|
+
* schemas, written once in a package both sides import. From it:
|
|
7
|
+
*
|
|
8
|
+
* - `contract.events` / `contract.user` are the DSL's typed reference tables
|
|
9
|
+
* (what `event<E>()` / `user<U>()` used to be, now derived from the schemas);
|
|
10
|
+
* - `contract.topics` are the subscription topics: every email and push template names one (or
|
|
11
|
+
* is transactional), a user opts out of one at a time per channel, and the compile refuses a
|
|
12
|
+
* topic the contract does not declare;
|
|
13
|
+
* - `JourneyClient({ contract })` types `track` / `identify` by event name and
|
|
14
|
+
* checks payloads before sending, and `getSubscriptions` / `setSubscriptions` by topic;
|
|
15
|
+
* - `journeyWorker({ contract })` re-validates every inbound `/ingest`
|
|
16
|
+
* and `/subscriptions` — never trusting the caller used the SDK — and refuses a bad
|
|
17
|
+
* one with a 4xx before anything is stored, woken or started.
|
|
18
|
+
*
|
|
19
|
+
* Supported schemas (v1), synchronous and JSON-shaped: event payloads are
|
|
20
|
+
* object schemas (`z.looseObject` keeps a producer's extra analytics fields,
|
|
21
|
+
* `z.strictObject` refuses them) and may nest objects and arrays; the profile
|
|
22
|
+
* is a flat object of string / number / boolean / enum / literal fields. Input
|
|
23
|
+
* and output must mean the same thing, so defaults, transforms, coercion,
|
|
24
|
+
* custom refinements and async checks are refused when the contract is
|
|
25
|
+
* defined. The Zod instances stay in the host; nothing here changes the IR.
|
|
26
|
+
*/
|
|
27
|
+
type ObjectSchema = core.$ZodObject;
|
|
28
|
+
/** The declared fields of an object schema — without a loose object's `[key: string]: unknown`, so the DSL only offers fields that were written down. */
|
|
29
|
+
export type DeclaredOutput<S> = S extends core.$ZodObject<infer Shape> ? core.$InferObjectOutput<Shape, core.$strict['out']> : never;
|
|
30
|
+
/**
|
|
31
|
+
* The subscription topics a producer and the engine agree on: content categories ('offers',
|
|
32
|
+
* 'tips'), not channels — an email or push template declares one (`emailTemplate({ topic })`,
|
|
33
|
+
* `pushTemplate({ topic })`), and a user opts out of a topic per channel (the preference page is
|
|
34
|
+
* topic × channel). Ids only — display names belong to the app's i18n. A plain array literal
|
|
35
|
+
* is enough: `defineContract` keeps the literals (no `as const` needed), and the union they form
|
|
36
|
+
* types the templates, the config and `JourneyClient.setSubscriptions`.
|
|
37
|
+
*/
|
|
38
|
+
export interface SubscriptionsDefinition<T extends string> {
|
|
39
|
+
topics: readonly T[];
|
|
40
|
+
}
|
|
41
|
+
export interface ContractDefinition<E extends Record<string, ObjectSchema>, P extends ObjectSchema, T extends string = never> {
|
|
42
|
+
events: E;
|
|
43
|
+
profile: P;
|
|
44
|
+
/** The topics, e.g. `{ topics: ['promotions', 'newsletter'] }`; none without it (transactional email and push only). */
|
|
45
|
+
subscriptions?: SubscriptionsDefinition<T>;
|
|
46
|
+
}
|
|
47
|
+
/** One rejected field, with the dotted path the producer can fix. */
|
|
48
|
+
export interface ContractIssue {
|
|
49
|
+
path: string;
|
|
50
|
+
message: string;
|
|
51
|
+
}
|
|
52
|
+
export type ContractResult<T> = {
|
|
53
|
+
ok: true;
|
|
54
|
+
data: T;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
issues: ContractIssue[];
|
|
58
|
+
};
|
|
59
|
+
export interface Contract<E extends Record<string, ObjectSchema> = Record<string, ObjectSchema>, P extends ObjectSchema = ObjectSchema, T extends string = string> {
|
|
60
|
+
readonly kind: 'journey-contract';
|
|
61
|
+
/** The declared subscription topics (`subscriptions.topics`), empty when none were declared. */
|
|
62
|
+
readonly topics: readonly T[];
|
|
63
|
+
isTopic(topic: string): topic is T;
|
|
64
|
+
/** The DSL's event reference table: `e.purchase` — payload refs from the declared fields only. */
|
|
65
|
+
readonly events: EventRefs<{ [K in keyof E]: DeclaredOutput<E[K]>; }>;
|
|
66
|
+
/** The DSL's user-property reference table: `u.name`, plus the system `u.userId`. */
|
|
67
|
+
readonly user: UserRefs<DeclaredOutput<P> & {
|
|
68
|
+
userId: string;
|
|
69
|
+
}>;
|
|
70
|
+
/** The raw schemas, for hosts that need them (validation, docs). */
|
|
71
|
+
readonly schemas: {
|
|
72
|
+
readonly events: E;
|
|
73
|
+
readonly profile: P;
|
|
74
|
+
};
|
|
75
|
+
/** Every event name the contract declares — what a producer forwards. */
|
|
76
|
+
readonly eventNames: readonly (keyof E & string)[];
|
|
77
|
+
isEvent(name: string): name is keyof E & string;
|
|
78
|
+
/** Validate one event's payload; the parsed value is what may be stored. */
|
|
79
|
+
parseEvent<K extends keyof E & string>(name: K, payload: unknown): ContractResult<core.output<E[K]>>;
|
|
80
|
+
/**
|
|
81
|
+
* Validate a profile merge patch: omitted fields stay as they are,
|
|
82
|
+
* `null` removes a field, every provided value is checked against its field
|
|
83
|
+
* schema, and an undeclared field is refused — a patch, never a full parse
|
|
84
|
+
* that would fill defaults over fields the caller did not send.
|
|
85
|
+
*/
|
|
86
|
+
parseProfilePatch(patch: unknown): ContractResult<ProfilePatch<P>>;
|
|
87
|
+
}
|
|
88
|
+
/** A patch over the profile: any subset of fields, `null` to remove one. */
|
|
89
|
+
export type ProfilePatch<P> = { [K in keyof DeclaredOutput<P>]?: DeclaredOutput<P>[K] | null; };
|
|
90
|
+
/** Payload type of one event, for producers: `EventPayload<typeof contract, 'purchase'>`. */
|
|
91
|
+
export type EventPayload<C, K extends string> = C extends Contract<infer E> ? (K extends keyof E ? core.input<E[K]> : never) : never;
|
|
92
|
+
/** The topics a contract declares, as a union: `Topic<typeof contract>`; `never` without any. */
|
|
93
|
+
export type Topic<C> = C extends Contract<Record<string, ObjectSchema>, ObjectSchema, infer T> ? T : never;
|
|
94
|
+
export declare function defineContract<E extends Record<string, ObjectSchema>, P extends ObjectSchema, const T extends string = never>(definition: ContractDefinition<E, P, T>): Contract<E, P, T>;
|
|
95
|
+
/**
|
|
96
|
+
* An event the contract refuses — raised for events a journey emits itself
|
|
97
|
+
* (`.sendEvent()`), which never pass the HTTP ingest: they go through the same
|
|
98
|
+
* check, and a refusal is deterministic, so it is not retried.
|
|
99
|
+
*/
|
|
100
|
+
export declare class ContractValidationError extends Error {
|
|
101
|
+
readonly event: string;
|
|
102
|
+
readonly issues: ContractIssue[];
|
|
103
|
+
readonly name = "ContractValidationError";
|
|
104
|
+
constructor(event: string, issues: ContractIssue[]);
|
|
105
|
+
}
|
|
106
|
+
/** The one check every event passes, from HTTP or from a journey: declared, and its payload parses. */
|
|
107
|
+
export declare function checkEvent(contract: Contract, name: string, payload: unknown): ContractResult<Record<string, unknown>>;
|
|
108
|
+
export declare function isContract(value: unknown): value is Contract;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=contract.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.cts","names":[],"sources":["../src/contract.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;KA4BK,eAAe,KAAK;;YAGb,eAAe,KACzB,UAAU,KAAK,iBAAiB,SAC5B,KAAK,mBAAmB,OAAO,KAAK;;;;;;;;;iBAWzB,wBAAwB;EACvC,iBAAiB;;iBAGF,mBACf,UAAU,eAAe,eACzB,UAAU,cACV;EAEA,QAAQ;EACR,SAAS;;EAET,gBAAgB,wBAAwB;;;iBAIzB;EACf;EACA;;YAGU,eAAe;EAAO;EAAU,MAAM;;EAAQ;EAAW,QAAQ;;iBAE5D,SACf,UAAU,eAAe,gBAAgB,eAAe,eACxD,UAAU,eAAe,cACzB;WAES;;WAEA,iBAAiB;EAC1B,QAAQ,gBAAgB,SAAS;;WAExB,QAAQ,aAAa,WAAW,IAAI,eAAe,EAAE;;WAErD,MAAM,SAAS,eAAe;IAAO;;;WAErC;aAAoB,QAAQ;aAAY,SAAS;;;WAEjD,4BAA4B;EACrC,QAAQ,eAAe,cAAc;;EAErC,WAAW,gBAAgB,YACzB,MAAM,GACN,mBACC,eAAe,KAAK,OAAO,EAAE;;;;;;;EAOhC,kBAAkB,iBAAiB,eAAe,aAAa;;;YAIrD,aAAa,QAAQ,WAAW,eAAe,MAAM,eAAe,GAAG;;YAGvE,aAAa,GAAG,oBAC1B,UAAU,eAAe,MAAM,gBAAgB,IAAI,KAAK,MAAM,EAAE;;YAGtD,MAAM,KAChB,UAAU,SAAS,eAAe,eAAe,oBAAoB,KAAK;wBAK5D,eACd,UAAU,eAAe,eACzB,UAAU,oBACJ,0BACN,YAAY,mBAAmB,GAAG,GAAG,KAAK,SAAS,GAAG,GAAG;;;;;;qBA4E9C,gCAAgC;WAGhC;WACA,QAAQ;WAHD;EAClB,YACW,eACA,QAAQ;;;wBAWL,WACd,UAAU,UACV,cACA,mBACC,eAAe;wBAUF,WAAW,iBAAiB,SAAS"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { EventRefs, UserRefs } from "./dsl/refs.mjs";
|
|
2
|
+
import * as core from "zod/v4/core";
|
|
3
|
+
import "./dsl/index.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* `defineContract({ events, profile, subscriptions? })` — the producer/engine contract as Zod
|
|
6
|
+
* schemas, written once in a package both sides import. From it:
|
|
7
|
+
*
|
|
8
|
+
* - `contract.events` / `contract.user` are the DSL's typed reference tables
|
|
9
|
+
* (what `event<E>()` / `user<U>()` used to be, now derived from the schemas);
|
|
10
|
+
* - `contract.topics` are the subscription topics: every email and push template names one (or
|
|
11
|
+
* is transactional), a user opts out of one at a time per channel, and the compile refuses a
|
|
12
|
+
* topic the contract does not declare;
|
|
13
|
+
* - `JourneyClient({ contract })` types `track` / `identify` by event name and
|
|
14
|
+
* checks payloads before sending, and `getSubscriptions` / `setSubscriptions` by topic;
|
|
15
|
+
* - `journeyWorker({ contract })` re-validates every inbound `/ingest`
|
|
16
|
+
* and `/subscriptions` — never trusting the caller used the SDK — and refuses a bad
|
|
17
|
+
* one with a 4xx before anything is stored, woken or started.
|
|
18
|
+
*
|
|
19
|
+
* Supported schemas (v1), synchronous and JSON-shaped: event payloads are
|
|
20
|
+
* object schemas (`z.looseObject` keeps a producer's extra analytics fields,
|
|
21
|
+
* `z.strictObject` refuses them) and may nest objects and arrays; the profile
|
|
22
|
+
* is a flat object of string / number / boolean / enum / literal fields. Input
|
|
23
|
+
* and output must mean the same thing, so defaults, transforms, coercion,
|
|
24
|
+
* custom refinements and async checks are refused when the contract is
|
|
25
|
+
* defined. The Zod instances stay in the host; nothing here changes the IR.
|
|
26
|
+
*/
|
|
27
|
+
type ObjectSchema = core.$ZodObject;
|
|
28
|
+
/** The declared fields of an object schema — without a loose object's `[key: string]: unknown`, so the DSL only offers fields that were written down. */
|
|
29
|
+
export type DeclaredOutput<S> = S extends core.$ZodObject<infer Shape> ? core.$InferObjectOutput<Shape, core.$strict['out']> : never;
|
|
30
|
+
/**
|
|
31
|
+
* The subscription topics a producer and the engine agree on: content categories ('offers',
|
|
32
|
+
* 'tips'), not channels — an email or push template declares one (`emailTemplate({ topic })`,
|
|
33
|
+
* `pushTemplate({ topic })`), and a user opts out of a topic per channel (the preference page is
|
|
34
|
+
* topic × channel). Ids only — display names belong to the app's i18n. A plain array literal
|
|
35
|
+
* is enough: `defineContract` keeps the literals (no `as const` needed), and the union they form
|
|
36
|
+
* types the templates, the config and `JourneyClient.setSubscriptions`.
|
|
37
|
+
*/
|
|
38
|
+
export interface SubscriptionsDefinition<T extends string> {
|
|
39
|
+
topics: readonly T[];
|
|
40
|
+
}
|
|
41
|
+
export interface ContractDefinition<E extends Record<string, ObjectSchema>, P extends ObjectSchema, T extends string = never> {
|
|
42
|
+
events: E;
|
|
43
|
+
profile: P;
|
|
44
|
+
/** The topics, e.g. `{ topics: ['promotions', 'newsletter'] }`; none without it (transactional email and push only). */
|
|
45
|
+
subscriptions?: SubscriptionsDefinition<T>;
|
|
46
|
+
}
|
|
47
|
+
/** One rejected field, with the dotted path the producer can fix. */
|
|
48
|
+
export interface ContractIssue {
|
|
49
|
+
path: string;
|
|
50
|
+
message: string;
|
|
51
|
+
}
|
|
52
|
+
export type ContractResult<T> = {
|
|
53
|
+
ok: true;
|
|
54
|
+
data: T;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
issues: ContractIssue[];
|
|
58
|
+
};
|
|
59
|
+
export interface Contract<E extends Record<string, ObjectSchema> = Record<string, ObjectSchema>, P extends ObjectSchema = ObjectSchema, T extends string = string> {
|
|
60
|
+
readonly kind: 'journey-contract';
|
|
61
|
+
/** The declared subscription topics (`subscriptions.topics`), empty when none were declared. */
|
|
62
|
+
readonly topics: readonly T[];
|
|
63
|
+
isTopic(topic: string): topic is T;
|
|
64
|
+
/** The DSL's event reference table: `e.purchase` — payload refs from the declared fields only. */
|
|
65
|
+
readonly events: EventRefs<{ [K in keyof E]: DeclaredOutput<E[K]>; }>;
|
|
66
|
+
/** The DSL's user-property reference table: `u.name`, plus the system `u.userId`. */
|
|
67
|
+
readonly user: UserRefs<DeclaredOutput<P> & {
|
|
68
|
+
userId: string;
|
|
69
|
+
}>;
|
|
70
|
+
/** The raw schemas, for hosts that need them (validation, docs). */
|
|
71
|
+
readonly schemas: {
|
|
72
|
+
readonly events: E;
|
|
73
|
+
readonly profile: P;
|
|
74
|
+
};
|
|
75
|
+
/** Every event name the contract declares — what a producer forwards. */
|
|
76
|
+
readonly eventNames: readonly (keyof E & string)[];
|
|
77
|
+
isEvent(name: string): name is keyof E & string;
|
|
78
|
+
/** Validate one event's payload; the parsed value is what may be stored. */
|
|
79
|
+
parseEvent<K extends keyof E & string>(name: K, payload: unknown): ContractResult<core.output<E[K]>>;
|
|
80
|
+
/**
|
|
81
|
+
* Validate a profile merge patch: omitted fields stay as they are,
|
|
82
|
+
* `null` removes a field, every provided value is checked against its field
|
|
83
|
+
* schema, and an undeclared field is refused — a patch, never a full parse
|
|
84
|
+
* that would fill defaults over fields the caller did not send.
|
|
85
|
+
*/
|
|
86
|
+
parseProfilePatch(patch: unknown): ContractResult<ProfilePatch<P>>;
|
|
87
|
+
}
|
|
88
|
+
/** A patch over the profile: any subset of fields, `null` to remove one. */
|
|
89
|
+
export type ProfilePatch<P> = { [K in keyof DeclaredOutput<P>]?: DeclaredOutput<P>[K] | null; };
|
|
90
|
+
/** Payload type of one event, for producers: `EventPayload<typeof contract, 'purchase'>`. */
|
|
91
|
+
export type EventPayload<C, K extends string> = C extends Contract<infer E> ? (K extends keyof E ? core.input<E[K]> : never) : never;
|
|
92
|
+
/** The topics a contract declares, as a union: `Topic<typeof contract>`; `never` without any. */
|
|
93
|
+
export type Topic<C> = C extends Contract<Record<string, ObjectSchema>, ObjectSchema, infer T> ? T : never;
|
|
94
|
+
export declare function defineContract<E extends Record<string, ObjectSchema>, P extends ObjectSchema, const T extends string = never>(definition: ContractDefinition<E, P, T>): Contract<E, P, T>;
|
|
95
|
+
/**
|
|
96
|
+
* An event the contract refuses — raised for events a journey emits itself
|
|
97
|
+
* (`.sendEvent()`), which never pass the HTTP ingest: they go through the same
|
|
98
|
+
* check, and a refusal is deterministic, so it is not retried.
|
|
99
|
+
*/
|
|
100
|
+
export declare class ContractValidationError extends Error {
|
|
101
|
+
readonly event: string;
|
|
102
|
+
readonly issues: ContractIssue[];
|
|
103
|
+
readonly name = "ContractValidationError";
|
|
104
|
+
constructor(event: string, issues: ContractIssue[]);
|
|
105
|
+
}
|
|
106
|
+
/** The one check every event passes, from HTTP or from a journey: declared, and its payload parses. */
|
|
107
|
+
export declare function checkEvent(contract: Contract, name: string, payload: unknown): ContractResult<Record<string, unknown>>;
|
|
108
|
+
export declare function isContract(value: unknown): value is Contract;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.mts","names":[],"sources":["../src/contract.ts"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