@shware/workflow 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -29
- package/dist/apns.cjs +113 -26
- package/dist/apns.cjs.map +1 -1
- package/dist/apns.d.cts +52 -6
- package/dist/apns.d.cts.map +1 -1
- package/dist/apns.d.mts +52 -6
- package/dist/apns.d.mts.map +1 -1
- package/dist/apns.mjs +111 -27
- package/dist/apns.mjs.map +1 -1
- package/dist/aws/engine-step.cjs +5 -5
- package/dist/aws/engine-step.cjs.map +1 -1
- package/dist/aws/engine-step.d.cts +8 -2
- package/dist/aws/engine-step.d.cts.map +1 -1
- package/dist/aws/engine-step.d.mts +8 -2
- package/dist/aws/engine-step.d.mts.map +1 -1
- package/dist/aws/engine-step.mjs +5 -5
- package/dist/aws/engine-step.mjs.map +1 -1
- package/dist/aws/index.cjs +47 -6
- package/dist/aws/index.cjs.map +1 -1
- package/dist/aws/index.d.cts +2 -2
- package/dist/aws/index.d.cts.map +1 -1
- package/dist/aws/index.d.mts +2 -2
- package/dist/aws/index.d.mts.map +1 -1
- package/dist/aws/index.mjs +47 -6
- package/dist/aws/index.mjs.map +1 -1
- package/dist/aws/instances.cjs +29 -6
- package/dist/aws/instances.cjs.map +1 -1
- package/dist/aws/instances.d.cts +11 -1
- package/dist/aws/instances.d.cts.map +1 -1
- package/dist/aws/instances.d.mts +11 -1
- package/dist/aws/instances.d.mts.map +1 -1
- package/dist/aws/instances.mjs +27 -4
- package/dist/aws/instances.mjs.map +1 -1
- package/dist/client.cjs +4 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -2
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.mts +2 -2
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +4 -1
- package/dist/client.mjs.map +1 -1
- package/dist/cloudflare/bindings.cjs +28 -25
- package/dist/cloudflare/bindings.cjs.map +1 -1
- package/dist/cloudflare/bindings.d.cts +17 -129
- package/dist/cloudflare/bindings.d.cts.map +1 -1
- package/dist/cloudflare/bindings.d.mts +17 -129
- package/dist/cloudflare/bindings.d.mts.map +1 -1
- package/dist/cloudflare/bindings.mjs +28 -23
- package/dist/cloudflare/bindings.mjs.map +1 -1
- package/dist/cloudflare/d1-env.cjs +6 -6
- package/dist/cloudflare/d1-env.cjs.map +1 -1
- package/dist/cloudflare/d1-env.d.cts +5 -5
- package/dist/cloudflare/d1-env.d.mts +5 -5
- package/dist/cloudflare/d1-env.mjs +6 -6
- package/dist/cloudflare/d1-env.mjs.map +1 -1
- package/dist/cloudflare/index.cjs +28 -18
- package/dist/cloudflare/index.d.cts +8 -4
- package/dist/cloudflare/index.d.mts +8 -4
- package/dist/cloudflare/index.mjs +9 -5
- package/dist/cloudflare/runner.cjs +29 -14
- package/dist/cloudflare/runner.cjs.map +1 -1
- package/dist/cloudflare/runner.d.cts +9 -2
- package/dist/cloudflare/runner.d.cts.map +1 -1
- package/dist/cloudflare/runner.d.mts +9 -2
- package/dist/cloudflare/runner.d.mts.map +1 -1
- package/dist/cloudflare/runner.mjs +28 -13
- package/dist/cloudflare/runner.mjs.map +1 -1
- package/dist/cloudflare/schema.sql +27 -6
- package/dist/cloudflare/worker.cjs +19 -9
- package/dist/cloudflare/worker.cjs.map +1 -1
- package/dist/cloudflare/worker.d.cts +2 -2
- package/dist/cloudflare/worker.d.cts.map +1 -1
- package/dist/cloudflare/worker.d.mts +2 -2
- package/dist/cloudflare/worker.d.mts.map +1 -1
- package/dist/cloudflare/worker.mjs +19 -9
- package/dist/cloudflare/worker.mjs.map +1 -1
- package/dist/config.cjs +21 -5
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs +21 -5
- package/dist/config.mjs.map +1 -1
- package/dist/dsl/action.cjs +3 -6
- package/dist/dsl/action.cjs.map +1 -1
- package/dist/dsl/action.d.cts +12 -11
- package/dist/dsl/action.d.cts.map +1 -1
- package/dist/dsl/action.d.mts +12 -11
- package/dist/dsl/action.d.mts.map +1 -1
- package/dist/dsl/action.mjs +3 -6
- package/dist/dsl/action.mjs.map +1 -1
- package/dist/dsl/bundle.cjs +35 -31
- package/dist/dsl/bundle.cjs.map +1 -1
- package/dist/dsl/bundle.d.cts.map +1 -1
- package/dist/dsl/bundle.d.mts.map +1 -1
- package/dist/dsl/bundle.mjs +35 -31
- package/dist/dsl/bundle.mjs.map +1 -1
- package/dist/dsl/condition.cjs +13 -1
- package/dist/dsl/condition.cjs.map +1 -1
- package/dist/dsl/condition.d.cts +9 -1
- package/dist/dsl/condition.d.cts.map +1 -1
- package/dist/dsl/condition.d.mts +9 -1
- package/dist/dsl/condition.d.mts.map +1 -1
- package/dist/dsl/condition.mjs +13 -2
- package/dist/dsl/condition.mjs.map +1 -1
- package/dist/dsl/flow.cjs +33 -11
- package/dist/dsl/flow.cjs.map +1 -1
- package/dist/dsl/flow.d.cts +9 -1
- package/dist/dsl/flow.d.cts.map +1 -1
- package/dist/dsl/flow.d.mts +9 -1
- package/dist/dsl/flow.d.mts.map +1 -1
- package/dist/dsl/flow.mjs +34 -13
- package/dist/dsl/flow.mjs.map +1 -1
- package/dist/dsl/workflow.cjs +2 -3
- package/dist/dsl/workflow.cjs.map +1 -1
- package/dist/dsl/workflow.d.cts.map +1 -1
- package/dist/dsl/workflow.d.mts.map +1 -1
- package/dist/dsl/workflow.mjs +3 -4
- package/dist/dsl/workflow.mjs.map +1 -1
- package/dist/email-sender.cjs +24 -0
- package/dist/email-sender.cjs.map +1 -1
- package/dist/email-sender.d.cts +18 -0
- package/dist/email-sender.d.cts.map +1 -1
- package/dist/email-sender.d.mts +18 -0
- package/dist/email-sender.d.mts.map +1 -1
- package/dist/email-sender.mjs +24 -1
- package/dist/email-sender.mjs.map +1 -1
- package/dist/engine/actions.cjs +1 -8
- package/dist/engine/actions.cjs.map +1 -1
- package/dist/engine/actions.d.cts +1 -12
- package/dist/engine/actions.d.cts.map +1 -1
- package/dist/engine/actions.d.mts +1 -12
- package/dist/engine/actions.d.mts.map +1 -1
- package/dist/engine/actions.mjs +1 -8
- package/dist/engine/actions.mjs.map +1 -1
- package/dist/engine/condition.cjs +25 -5
- package/dist/engine/condition.cjs.map +1 -1
- package/dist/engine/condition.d.cts +12 -3
- package/dist/engine/condition.d.cts.map +1 -1
- package/dist/engine/condition.d.mts +12 -3
- package/dist/engine/condition.d.mts.map +1 -1
- package/dist/engine/condition.mjs +25 -6
- package/dist/engine/condition.mjs.map +1 -1
- package/dist/engine/index.cjs +3 -0
- package/dist/engine/index.d.cts +5 -5
- package/dist/engine/index.d.mts +5 -5
- package/dist/engine/index.mjs +4 -4
- package/dist/engine/interpreter.cjs +27 -20
- package/dist/engine/interpreter.cjs.map +1 -1
- package/dist/engine/interpreter.d.cts.map +1 -1
- package/dist/engine/interpreter.d.mts.map +1 -1
- package/dist/engine/interpreter.mjs +27 -20
- package/dist/engine/interpreter.mjs.map +1 -1
- package/dist/engine/ports.d.cts +21 -6
- package/dist/engine/ports.d.cts.map +1 -1
- package/dist/engine/ports.d.mts +21 -6
- package/dist/engine/ports.d.mts.map +1 -1
- package/dist/engine/retry.cjs +13 -0
- package/dist/engine/retry.cjs.map +1 -1
- package/dist/engine/retry.d.cts +12 -0
- package/dist/engine/retry.d.cts.map +1 -1
- package/dist/engine/retry.d.mts +12 -0
- package/dist/engine/retry.d.mts.map +1 -1
- package/dist/engine/retry.mjs +13 -1
- package/dist/engine/retry.mjs.map +1 -1
- package/dist/engine/time-scale.cjs +90 -15
- package/dist/engine/time-scale.cjs.map +1 -1
- package/dist/engine/time-scale.d.cts +9 -6
- package/dist/engine/time-scale.d.cts.map +1 -1
- package/dist/engine/time-scale.d.mts +9 -6
- package/dist/engine/time-scale.d.mts.map +1 -1
- package/dist/engine/time-scale.mjs +90 -16
- package/dist/engine/time-scale.mjs.map +1 -1
- package/dist/fcm.cjs +111 -38
- package/dist/fcm.cjs.map +1 -1
- package/dist/fcm.d.cts +45 -5
- package/dist/fcm.d.cts.map +1 -1
- package/dist/fcm.d.mts +45 -5
- package/dist/fcm.d.mts.map +1 -1
- package/dist/fcm.mjs +110 -39
- package/dist/fcm.mjs.map +1 -1
- package/dist/hash.cjs +6 -6
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.mjs +6 -6
- package/dist/hash.mjs.map +1 -1
- package/dist/host/auth.cjs +49 -0
- package/dist/host/auth.cjs.map +1 -0
- package/dist/host/auth.d.cts +21 -0
- package/dist/host/auth.d.cts.map +1 -0
- package/dist/host/auth.d.mts +21 -0
- package/dist/host/auth.d.mts.map +1 -0
- package/dist/host/auth.mjs +47 -0
- package/dist/host/auth.mjs.map +1 -0
- package/dist/host/channels.cjs +118 -40
- package/dist/host/channels.cjs.map +1 -1
- package/dist/host/channels.d.cts +27 -1
- package/dist/host/channels.d.cts.map +1 -1
- package/dist/host/channels.d.mts +27 -1
- package/dist/host/channels.d.mts.map +1 -1
- package/dist/host/channels.mjs +121 -44
- package/dist/host/channels.mjs.map +1 -1
- package/dist/host/execute.cjs +14 -2
- package/dist/host/execute.cjs.map +1 -1
- package/dist/host/execute.d.cts +4 -4
- package/dist/host/execute.d.cts.map +1 -1
- package/dist/host/execute.d.mts +4 -4
- package/dist/host/execute.d.mts.map +1 -1
- package/dist/host/execute.mjs +13 -1
- package/dist/host/execute.mjs.map +1 -1
- package/dist/host/fresh-read.cjs +30 -0
- package/dist/host/fresh-read.cjs.map +1 -0
- package/dist/host/fresh-read.d.cts +18 -0
- package/dist/host/fresh-read.d.cts.map +1 -0
- package/dist/host/fresh-read.d.mts +18 -0
- package/dist/host/fresh-read.d.mts.map +1 -0
- package/dist/host/fresh-read.mjs +29 -0
- package/dist/host/fresh-read.mjs.map +1 -0
- package/dist/host/http.cjs +321 -0
- package/dist/host/http.cjs.map +1 -0
- package/dist/host/http.d.cts +54 -0
- package/dist/host/http.d.cts.map +1 -0
- package/dist/host/http.d.mts +54 -0
- package/dist/host/http.d.mts.map +1 -0
- package/dist/host/http.mjs +317 -0
- package/dist/host/http.mjs.map +1 -0
- package/dist/host/{router.cjs → ingest.cjs} +147 -175
- package/dist/host/ingest.cjs.map +1 -0
- package/dist/host/{router.d.cts → ingest.d.cts} +48 -30
- package/dist/host/ingest.d.cts.map +1 -0
- package/dist/host/{router.d.mts → ingest.d.mts} +48 -30
- package/dist/host/ingest.d.mts.map +1 -0
- package/dist/host/{router.mjs → ingest.mjs} +144 -173
- package/dist/host/ingest.mjs.map +1 -0
- package/dist/host/journey-host.cjs +65 -93
- package/dist/host/journey-host.cjs.map +1 -1
- package/dist/host/journey-host.d.cts +19 -26
- package/dist/host/journey-host.d.cts.map +1 -1
- package/dist/host/journey-host.d.mts +19 -26
- package/dist/host/journey-host.d.mts.map +1 -1
- package/dist/host/journey-host.mjs +65 -93
- package/dist/host/journey-host.mjs.map +1 -1
- package/dist/host/platform.cjs +21 -0
- package/dist/host/platform.cjs.map +1 -0
- package/dist/host/platform.d.cts +126 -0
- package/dist/host/platform.d.cts.map +1 -0
- package/dist/host/platform.d.mts +126 -0
- package/dist/host/platform.d.mts.map +1 -0
- package/dist/host/platform.mjs +19 -0
- package/dist/host/platform.mjs.map +1 -0
- package/dist/host/senders.cjs +18 -9
- package/dist/host/senders.cjs.map +1 -1
- package/dist/host/senders.d.cts +9 -4
- package/dist/host/senders.d.cts.map +1 -1
- package/dist/host/senders.d.mts +9 -4
- package/dist/host/senders.d.mts.map +1 -1
- package/dist/host/senders.mjs +18 -9
- package/dist/host/senders.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/ir.cjs +5 -7
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +3 -12
- package/dist/ir.d.cts.map +1 -1
- package/dist/ir.d.mts +3 -12
- package/dist/ir.d.mts.map +1 -1
- package/dist/ir.mjs +5 -7
- package/dist/ir.mjs.map +1 -1
- package/dist/plan.cjs +27 -33
- package/dist/plan.cjs.map +1 -1
- package/dist/plan.d.cts +1 -1
- package/dist/plan.d.cts.map +1 -1
- package/dist/plan.d.mts +1 -1
- package/dist/plan.d.mts.map +1 -1
- package/dist/plan.mjs +27 -33
- package/dist/plan.mjs.map +1 -1
- package/dist/reporting/observer.cjs +1 -0
- package/dist/reporting/observer.cjs.map +1 -1
- package/dist/reporting/observer.mjs +1 -0
- package/dist/reporting/observer.mjs.map +1 -1
- package/dist/reporting/tracking.cjs +19 -4
- package/dist/reporting/tracking.cjs.map +1 -1
- package/dist/reporting/tracking.d.cts +13 -11
- package/dist/reporting/tracking.d.cts.map +1 -1
- package/dist/reporting/tracking.d.mts +13 -11
- package/dist/reporting/tracking.d.mts.map +1 -1
- package/dist/reporting/tracking.mjs +19 -4
- package/dist/reporting/tracking.mjs.map +1 -1
- package/dist/store/d1.cjs +88 -29
- package/dist/store/d1.cjs.map +1 -1
- package/dist/store/d1.d.cts +29 -11
- package/dist/store/d1.d.cts.map +1 -1
- package/dist/store/d1.d.mts +29 -11
- package/dist/store/d1.d.mts.map +1 -1
- package/dist/store/d1.mjs +88 -29
- package/dist/store/d1.mjs.map +1 -1
- package/dist/store/erasure.cjs +22 -0
- package/dist/store/erasure.cjs.map +1 -0
- package/dist/store/erasure.d.cts +18 -0
- package/dist/store/erasure.d.cts.map +1 -0
- package/dist/store/erasure.d.mts +18 -0
- package/dist/store/erasure.d.mts.map +1 -0
- package/dist/store/erasure.mjs +21 -0
- package/dist/store/erasure.mjs.map +1 -0
- package/dist/store/index.cjs +2 -0
- package/dist/store/index.cjs.map +1 -1
- package/dist/store/index.d.cts +67 -13
- package/dist/store/index.d.cts.map +1 -1
- package/dist/store/index.d.mts +67 -13
- package/dist/store/index.d.mts.map +1 -1
- package/dist/store/index.mjs +2 -1
- package/dist/store/index.mjs.map +1 -1
- package/dist/store/postgres-reporting.cjs +125 -62
- package/dist/store/postgres-reporting.cjs.map +1 -1
- package/dist/store/postgres-reporting.d.cts +30 -2
- package/dist/store/postgres-reporting.d.cts.map +1 -1
- package/dist/store/postgres-reporting.d.mts +30 -2
- package/dist/store/postgres-reporting.d.mts.map +1 -1
- package/dist/store/postgres-reporting.mjs +125 -62
- package/dist/store/postgres-reporting.mjs.map +1 -1
- package/dist/store/postgres.cjs +179 -60
- package/dist/store/postgres.cjs.map +1 -1
- package/dist/store/postgres.d.cts +44 -7
- package/dist/store/postgres.d.cts.map +1 -1
- package/dist/store/postgres.d.mts +44 -7
- package/dist/store/postgres.d.mts.map +1 -1
- package/dist/store/postgres.mjs +179 -60
- package/dist/store/postgres.mjs.map +1 -1
- package/dist/store/tables.cjs +7 -5
- package/dist/store/tables.cjs.map +1 -1
- package/dist/store/tables.d.cts.map +1 -1
- package/dist/store/tables.d.mts.map +1 -1
- package/dist/store/tables.mjs +7 -5
- package/dist/store/tables.mjs.map +1 -1
- package/dist/store/user-lock.cjs +43 -0
- package/dist/store/user-lock.cjs.map +1 -0
- package/dist/store/user-lock.d.cts +32 -0
- package/dist/store/user-lock.d.cts.map +1 -0
- package/dist/store/user-lock.d.mts +32 -0
- package/dist/store/user-lock.d.mts.map +1 -0
- package/dist/store/user-lock.mjs +40 -0
- package/dist/store/user-lock.mjs.map +1 -0
- package/dist/transports/cloudflare-email.cjs +3 -2
- package/dist/transports/cloudflare-email.cjs.map +1 -1
- package/dist/transports/cloudflare-email.mjs +3 -2
- package/dist/transports/cloudflare-email.mjs.map +1 -1
- package/dist/transports/ses.cjs +52 -7
- package/dist/transports/ses.cjs.map +1 -1
- package/dist/transports/ses.d.cts +9 -1
- package/dist/transports/ses.d.cts.map +1 -1
- package/dist/transports/ses.d.mts +9 -1
- package/dist/transports/ses.d.mts.map +1 -1
- package/dist/transports/ses.mjs +52 -8
- package/dist/transports/ses.mjs.map +1 -1
- package/dist/webpush.cjs +133 -47
- package/dist/webpush.cjs.map +1 -1
- package/dist/webpush.d.cts +49 -8
- package/dist/webpush.d.cts.map +1 -1
- package/dist/webpush.d.mts +49 -8
- package/dist/webpush.d.mts.map +1 -1
- package/dist/webpush.mjs +130 -47
- package/dist/webpush.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cloudflare/schema.sql +27 -6
- package/dist/host/router.cjs.map +0 -1
- package/dist/host/router.d.cts.map +0 -1
- package/dist/host/router.d.mts.map +0 -1
- package/dist/host/router.mjs.map +0 -1
package/dist/host/execute.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ActionInvoker, EngineStep, JourneyObserver, JourneyOutcome, MessageSender, MessageValidator } from "../engine/ports.mjs";
|
|
2
|
-
import { JourneyEnv, JourneyParams } from "
|
|
2
|
+
import { JourneyEnv, JourneyParams } from "./platform.mjs";
|
|
3
3
|
import { JourneyStore } from "../store/index.mjs";
|
|
4
4
|
import { Contract } from "../contract.mjs";
|
|
5
5
|
import { JourneyRuntimeOptions } from "../runtime.mjs";
|
|
6
6
|
//#region src/host/execute.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* One journey instance run to its end, on whatever durable runtime supplies the `EngineStep`:
|
|
9
|
-
* the
|
|
10
|
-
*
|
|
11
|
-
* their EngineStep differs.
|
|
9
|
+
* the runner admitted against the user's erasure tombstone, the IR loaded by the hash pinned at
|
|
10
|
+
* entry, the outlets wired, the interpreter run, and the ledger finalized. Cloudflare's runner
|
|
11
|
+
* and the Lambda handler both come through here; only their EngineStep differs.
|
|
12
12
|
*/
|
|
13
13
|
/** Everything a run is wired to, assembled by the host. */
|
|
14
14
|
export interface JourneyRunParts {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.mts","names":[],"sources":["../../src/host/execute.ts"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"execute.d.mts","names":[],"sources":["../../src/host/execute.ts"],"mappings":";;;;;;;;;;;;;iBA2BiB;EACf,OAAO;;;;;EAKP,KAAK;EACL,SAAS;EACT,UAAU;EACV,SAAS;EACT,WAAW;EACX,YAAY;EACZ,WAAW;;iBAGI;EACf;EACA,QAAQ;;EAER;EACA,MAAM;;wBAec,eACpB,OAAO,iBACP,OAAO,kBACN,QAAQ"}
|
package/dist/host/execute.mjs
CHANGED
|
@@ -3,7 +3,8 @@ import { resolveRuntime } from "../runtime.mjs";
|
|
|
3
3
|
import { runJourney } from "../engine/interpreter.mjs";
|
|
4
4
|
import { scaleDurations } from "../engine/time-scale.mjs";
|
|
5
5
|
import { JourneyFactSource } from "../store/facts.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { readWithRetry } from "./fresh-read.mjs";
|
|
7
|
+
import { ingestEvent } from "./ingest.mjs";
|
|
7
8
|
//#region src/host/execute.ts
|
|
8
9
|
/** Development aid: echo each outbound message before handing it to the real sender. */
|
|
9
10
|
function logging(sender) {
|
|
@@ -40,6 +41,16 @@ async function executeJourney(input, parts) {
|
|
|
40
41
|
payload: accepted
|
|
41
42
|
}, store);
|
|
42
43
|
} };
|
|
44
|
+
if (!await readWithRetry(() => store.admitInstance(instanceId, userId), {
|
|
45
|
+
what: "admission",
|
|
46
|
+
instanceId
|
|
47
|
+
})) {
|
|
48
|
+
console.warn(`[workflow] instance ${instanceId} of ${userId} refused admission: not running`);
|
|
49
|
+
return {
|
|
50
|
+
status: "exited",
|
|
51
|
+
reason: "erased"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
43
54
|
let outcome;
|
|
44
55
|
try {
|
|
45
56
|
const stored = await step.do("$workflow:ir", async () => {
|
|
@@ -63,6 +74,7 @@ async function executeJourney(input, parts) {
|
|
|
63
74
|
} catch (error) {
|
|
64
75
|
await step.do("finalize:failed", async () => {
|
|
65
76
|
await store.setEntryStatus(instanceId, "failed");
|
|
77
|
+
await store.unsubscribe(instanceId);
|
|
66
78
|
await finished("failed");
|
|
67
79
|
});
|
|
68
80
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.mjs","names":[],"sources":["../../src/host/execute.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"execute.mjs","names":[],"sources":["../../src/host/execute.ts"],"sourcesContent":["import { type Contract, ContractValidationError, checkEvent } from '../contract';\nimport { runJourney } from '../engine/interpreter';\nimport type {\n ActionInvoker,\n EngineStep,\n EventSink,\n JourneyObserver,\n JourneyOutcome,\n MessageSender,\n MessageValidator,\n} from '../engine/ports';\nimport { scaleDurations } from '../engine/time-scale';\nimport { type JourneyRuntimeOptions, resolveRuntime } from '../runtime';\nimport { JourneyFactSource } from '../store/facts';\nimport type { JourneyStore } from '../store/index';\nimport { readWithRetry } from './fresh-read';\nimport { ingestEvent } from './ingest';\nimport type { JourneyEnv, JourneyParams } from './platform';\n\n/**\n * One journey instance run to its end, on whatever durable runtime supplies the `EngineStep`:\n * the runner admitted against the user's erasure tombstone, the IR loaded by the hash pinned at\n * entry, the outlets wired, the interpreter run, and the ledger finalized. Cloudflare's runner\n * and the Lambda handler both come through here; only their EngineStep differs.\n */\n\n/** Everything a run is wired to, assembled by the host. */\nexport interface JourneyRunParts {\n store: JourneyStore;\n /**\n * The env the emitted events are ingested with: its `JOURNEY` starts and wakes instances on\n * this runtime.\n */\n env: JourneyEnv;\n runtime: JourneyRuntimeOptions;\n messages: MessageSender;\n actions: ActionInvoker;\n contract?: Contract | undefined;\n validator?: MessageValidator | undefined;\n observer?: JourneyObserver | undefined;\n}\n\nexport interface JourneyRunInput {\n instanceId: string;\n params: JourneyParams;\n /** When the trigger happened: replay-stable, never Date.now() at run time. */\n enteredAtMs: number;\n step: EngineStep;\n}\n\n/** Development aid: echo each outbound message before handing it to the real sender. */\nfunction logging(sender: MessageSender): MessageSender {\n return {\n async send(message) {\n console.log(\n `[journey] ${message.channel} ${message.template} → ${message.recipient ?? message.userId} ${JSON.stringify(message.props)}`\n );\n return sender.send(message);\n },\n };\n}\n\nexport async function executeJourney(\n input: JourneyRunInput,\n parts: JourneyRunParts\n): Promise<JourneyOutcome> {\n const { instanceId, params, step } = input;\n const { workflowId, contentHash, userId } = params;\n const { store, env, observer, contract } = parts;\n\n const runtime = resolveRuntime({ current: parts.runtime }, 'current');\n\n const finished = (status: JourneyOutcome['status'] | 'failed', convertedAt?: number) =>\n observer?.finished?.({\n workflow: workflowId,\n instanceId,\n userId,\n status,\n at: Date.now(),\n ...(convertedAt === undefined ? {} : { convertedAt }),\n });\n\n const messages = runtime.logMessages ? logging(parts.messages) : parts.messages;\n\n // send_event feeds straight back into the router logic — an in-process call\n // forming the event edge between workflows. The step's identity travels as\n // the event id, so a retried emit records the occurrence once.\n // An emitted event passes the same contract check as one arriving over HTTP.\n const events: EventSink = {\n emit: async (name, payload, id) => {\n let accepted: Record<string, unknown> = payload;\n if (contract !== undefined) {\n const verdict = checkEvent(contract, name, payload);\n if (!verdict.ok) throw new ContractValidationError(name, verdict.issues);\n accepted = verdict.data;\n }\n await ingestEvent(env, { id, userId, event: name, payload: accepted }, store);\n },\n };\n\n /*\n * Admission: the ledger entry was committed before the runtime was asked to create this\n * instance, so an erasure can land in between (the entry is not found by `get`, the erase\n * goes through, and then the create lands). The runner is the only one who can refuse that\n * late run, and it must do so before its first observable effect — `observer.started`, the\n * IR read, any action or send.\n *\n * Outside any durable step, on purpose: a step would checkpoint the first invocation's\n * \"admitted\" and replay it on every wake and every rebuild after an eviction, which is\n * exactly when the tombstone may have arrived since. `admitInstance` is idempotent — the\n * entry's `admitted_at` keeps its first value — so a replay re-admits the same instance, and\n * the store makes the admission mutually exclusive with the erasure: either the entry is\n * admitted first and the erasure finds it and stops it, or the tombstone commits first and\n * this read answers false. Only the read itself is retried, briefly, when the database\n * stumbled; one that keeps failing throws, so the instance errors without running anything,\n * its entry stays, and the erasure protocol (or a later wake) decides what becomes of it.\n */\n const admitted = await readWithRetry(() => store.admitInstance(instanceId, userId), {\n what: 'admission',\n instanceId,\n });\n if (!admitted) {\n /*\n * No finalize either way: the entry is gone (erased, or never ours to run) or is being\n * erased, and the finalize steps would write it back — a status on an entry the erasure\n * deletes, a `finished` the reporting records as a new row of an erased user. The\n * subscriptions, if any, go with the user's data.\n */\n console.warn(`[workflow] instance ${instanceId} of ${userId} refused admission: not running`);\n return { status: 'exited', reason: 'erased' };\n }\n\n let outcome: JourneyOutcome;\n try {\n // In a step: a read that fails is retried like any other, and one that keeps failing ends\n // the instance through the failure path below rather than leaving its entry 'running'.\n // Content addressing makes the IR immutable, so the checkpointed copy is the one to replay\n const stored = await step.do('$workflow:ir', async () => {\n const found = await store.getWorkflowIR(contentHash);\n if (found === undefined)\n throw new Error(`WorkflowIR not found: ${workflowId}@${contentHash}`);\n return found;\n });\n // Development runs the journey in fast-forward; the pinned hash still names the version.\n const ir = scaleDurations(stored, runtime.timeScale);\n outcome = await runJourney(ir, {\n userId,\n instanceId,\n enteredAtMs: input.enteredAtMs,\n step,\n facts: new JourneyFactSource(store, userId),\n messages,\n events,\n actions: parts.actions,\n validator: parts.validator,\n observer,\n });\n } catch (error) {\n /*\n * An error escaping run() ends the instance, and the ledger is the only\n * place anyone looks afterwards: leaving it at 'running' meant a dead\n * journey stayed indistinguishable from a waiting one, in the dashboard\n * and in the once-policy, forever.\n *\n * Subscriptions go too, as on every ordinary ending: left behind, the\n * rows would only make every later event of the user poke a dead\n * instance (one wake call to the runtime each, refused every time).\n *\n * A paused instance never gets here: a durable wait suspends the run\n * without throwing through it.\n */\n await step.do('finalize:failed', async () => {\n await store.setEntryStatus(instanceId, 'failed');\n await store.unsubscribe(instanceId);\n await finished('failed');\n });\n throw error;\n }\n\n await step.do('finalize', async () => {\n await store.setEntryStatus(instanceId, outcome.status);\n await store.unsubscribe(instanceId);\n await finished(outcome.status, outcome.convertedAt);\n });\n\n return outcome;\n}\n"],"mappings":";;;;;;;;;AAmDA,SAAS,QAAQ,QAAsC;CACrD,OAAO,EACL,MAAM,KAAK,SAAS;EAClB,QAAQ,IACN,aAAa,QAAQ,QAAQ,GAAG,QAAQ,SAAS,KAAK,QAAQ,aAAa,QAAQ,OAAO,GAAG,KAAK,UAAU,QAAQ,KAAK,GAC3H;EACA,OAAO,OAAO,KAAK,OAAO;CAC5B,EACF;AACF;AAEA,eAAsB,eACpB,OACA,OACyB;CACzB,MAAM,EAAE,YAAY,QAAQ,SAAS;CACrC,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OAAO,IAAI,kBAAkB,OAAO,MAAM;GAC1C;GACA;GACA,SAAS,MAAM;GACf,WAAW,MAAM;GACjB;EACF,CAAC;CACH,SAAS,OAAO;EAcd,MAAM,KAAK,GAAG,mBAAmB,YAAY;GAC3C,MAAM,MAAM,eAAe,YAAY,QAAQ;GAC/C,MAAM,MAAM,YAAY,UAAU;GAClC,MAAM,SAAS,QAAQ;EACzB,CAAC;EACD,MAAM;CACR;CAEA,MAAM,KAAK,GAAG,YAAY,YAAY;EACpC,MAAM,MAAM,eAAe,YAAY,QAAQ,MAAM;EACrD,MAAM,MAAM,YAAY,UAAU;EAClC,MAAM,SAAS,QAAQ,QAAQ,QAAQ,WAAW;CACpD,CAAC;CAED,OAAO;AACT"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_engine_retry = require("../engine/retry.cjs");
|
|
3
|
+
//#region src/host/fresh-read.ts
|
|
4
|
+
/**
|
|
5
|
+
* A read that runs outside any durable step — a runner's admission at its entry, the registry
|
|
6
|
+
* check on AWS — which must see the record as it is now (an erasure since the last checkpoint)
|
|
7
|
+
* and so cannot be checkpointed: a step would replay the first invocation's verdict on every
|
|
8
|
+
* wake. Only the read itself is retried, a bounded number of times, on a transient failure (a
|
|
9
|
+
* dropped connection, a timeout); what it returns is never retried — a refusal is the caller's
|
|
10
|
+
* — and a `PermanentError` (or any error that says `retryable: false`) ends it at once.
|
|
11
|
+
*/
|
|
12
|
+
async function readWithRetry(fn, about, budget = {
|
|
13
|
+
attempts: 3,
|
|
14
|
+
delaysMs: [100, 300]
|
|
15
|
+
}) {
|
|
16
|
+
for (let attempt = 1;; attempt++) try {
|
|
17
|
+
return await fn();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (attempt >= budget.attempts || !require_engine_retry.isRetryable(error)) throw error;
|
|
20
|
+
const delayMs = budget.delaysMs[Math.min(attempt, budget.delaysMs.length) - 1] ?? 0;
|
|
21
|
+
console.warn(`[workflow] ${about.what}: read failed for instance ${about.instanceId} (attempt ${attempt} of ${budget.attempts}), retrying in ${delayMs} ms`, error);
|
|
22
|
+
await new Promise((resolve) => {
|
|
23
|
+
setTimeout(resolve, delayMs);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.readWithRetry = readWithRetry;
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=fresh-read.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fresh-read.cjs","names":["isRetryable"],"sources":["../../src/host/fresh-read.ts"],"sourcesContent":["import { isRetryable } from '../engine/retry';\n\n/**\n * A read that runs outside any durable step — a runner's admission at its entry, the registry\n * check on AWS — which must see the record as it is now (an erasure since the last checkpoint)\n * and so cannot be checkpointed: a step would replay the first invocation's verdict on every\n * wake. Only the read itself is retried, a bounded number of times, on a transient failure (a\n * dropped connection, a timeout); what it returns is never retried — a refusal is the caller's\n * — and a `PermanentError` (or any error that says `retryable: false`) ends it at once.\n */\nexport async function readWithRetry<T>(\n fn: () => Promise<T>,\n about: { what: string; instanceId: string },\n budget: { attempts: number; delaysMs: readonly number[] } = { attempts: 3, delaysMs: [100, 300] }\n): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n return await fn();\n } catch (error) {\n if (attempt >= budget.attempts || !isRetryable(error)) throw error;\n const delayMs = budget.delaysMs[Math.min(attempt, budget.delaysMs.length) - 1] ?? 0;\n console.warn(\n `[workflow] ${about.what}: read failed for instance ${about.instanceId} (attempt ${attempt} of ${budget.attempts}), retrying in ${delayMs} ms`,\n error\n );\n await new Promise<void>((resolve) => {\n setTimeout(resolve, delayMs);\n });\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAUA,eAAsB,cACpB,IACA,OACA,SAA4D;CAAE,UAAU;CAAG,UAAU,CAAC,KAAK,GAAG;AAAE,GACpF;CACZ,KAAK,IAAI,UAAU,IAAK,WACtB,IAAI;EACF,OAAO,MAAM,GAAG;CAClB,SAAS,OAAO;EACd,IAAI,WAAW,OAAO,YAAY,CAACA,qBAAAA,YAAY,KAAK,GAAG,MAAM;EAC7D,MAAM,UAAU,OAAO,SAAS,KAAK,IAAI,SAAS,OAAO,SAAS,MAAM,IAAI,MAAM;EAClF,QAAQ,KACN,cAAc,MAAM,KAAK,6BAA6B,MAAM,WAAW,YAAY,QAAQ,MAAM,OAAO,SAAS,iBAAiB,QAAQ,MAC1I,KACF;EACA,MAAM,IAAI,SAAe,YAAY;GACnC,WAAW,SAAS,OAAO;EAC7B,CAAC;CACH;AAEJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/host/fresh-read.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A read that runs outside any durable step — a runner's admission at its entry, the registry
|
|
4
|
+
* check on AWS — which must see the record as it is now (an erasure since the last checkpoint)
|
|
5
|
+
* and so cannot be checkpointed: a step would replay the first invocation's verdict on every
|
|
6
|
+
* wake. Only the read itself is retried, a bounded number of times, on a transient failure (a
|
|
7
|
+
* dropped connection, a timeout); what it returns is never retried — a refusal is the caller's
|
|
8
|
+
* — and a `PermanentError` (or any error that says `retryable: false`) ends it at once.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readWithRetry<T>(fn: () => Promise<T>, about: {
|
|
11
|
+
what: string;
|
|
12
|
+
instanceId: string;
|
|
13
|
+
}, budget?: {
|
|
14
|
+
attempts: number;
|
|
15
|
+
delaysMs: readonly number[];
|
|
16
|
+
}): Promise<T>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=fresh-read.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fresh-read.d.cts","names":[],"sources":["../../src/host/fresh-read.ts"],"mappings":";;;;;;;;;wBAUsB,cAAc,GAClC,UAAU,QAAQ,IAClB;EAAS;EAAc;GACvB;EAAU;EAAkB;IAC3B,QAAQ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/host/fresh-read.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A read that runs outside any durable step — a runner's admission at its entry, the registry
|
|
4
|
+
* check on AWS — which must see the record as it is now (an erasure since the last checkpoint)
|
|
5
|
+
* and so cannot be checkpointed: a step would replay the first invocation's verdict on every
|
|
6
|
+
* wake. Only the read itself is retried, a bounded number of times, on a transient failure (a
|
|
7
|
+
* dropped connection, a timeout); what it returns is never retried — a refusal is the caller's
|
|
8
|
+
* — and a `PermanentError` (or any error that says `retryable: false`) ends it at once.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readWithRetry<T>(fn: () => Promise<T>, about: {
|
|
11
|
+
what: string;
|
|
12
|
+
instanceId: string;
|
|
13
|
+
}, budget?: {
|
|
14
|
+
attempts: number;
|
|
15
|
+
delaysMs: readonly number[];
|
|
16
|
+
}): Promise<T>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=fresh-read.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fresh-read.d.mts","names":[],"sources":["../../src/host/fresh-read.ts"],"mappings":";;;;;;;;;wBAUsB,cAAc,GAClC,UAAU,QAAQ,IAClB;EAAS;EAAc;GACvB;EAAU;EAAkB;IAC3B,QAAQ"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isRetryable } from "../engine/retry.mjs";
|
|
2
|
+
//#region src/host/fresh-read.ts
|
|
3
|
+
/**
|
|
4
|
+
* A read that runs outside any durable step — a runner's admission at its entry, the registry
|
|
5
|
+
* check on AWS — which must see the record as it is now (an erasure since the last checkpoint)
|
|
6
|
+
* and so cannot be checkpointed: a step would replay the first invocation's verdict on every
|
|
7
|
+
* wake. Only the read itself is retried, a bounded number of times, on a transient failure (a
|
|
8
|
+
* dropped connection, a timeout); what it returns is never retried — a refusal is the caller's
|
|
9
|
+
* — and a `PermanentError` (or any error that says `retryable: false`) ends it at once.
|
|
10
|
+
*/
|
|
11
|
+
async function readWithRetry(fn, about, budget = {
|
|
12
|
+
attempts: 3,
|
|
13
|
+
delaysMs: [100, 300]
|
|
14
|
+
}) {
|
|
15
|
+
for (let attempt = 1;; attempt++) try {
|
|
16
|
+
return await fn();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (attempt >= budget.attempts || !isRetryable(error)) throw error;
|
|
19
|
+
const delayMs = budget.delaysMs[Math.min(attempt, budget.delaysMs.length) - 1] ?? 0;
|
|
20
|
+
console.warn(`[workflow] ${about.what}: read failed for instance ${about.instanceId} (attempt ${attempt} of ${budget.attempts}), retrying in ${delayMs} ms`, error);
|
|
21
|
+
await new Promise((resolve) => {
|
|
22
|
+
setTimeout(resolve, delayMs);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { readWithRetry };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=fresh-read.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fresh-read.mjs","names":[],"sources":["../../src/host/fresh-read.ts"],"sourcesContent":["import { isRetryable } from '../engine/retry';\n\n/**\n * A read that runs outside any durable step — a runner's admission at its entry, the registry\n * check on AWS — which must see the record as it is now (an erasure since the last checkpoint)\n * and so cannot be checkpointed: a step would replay the first invocation's verdict on every\n * wake. Only the read itself is retried, a bounded number of times, on a transient failure (a\n * dropped connection, a timeout); what it returns is never retried — a refusal is the caller's\n * — and a `PermanentError` (or any error that says `retryable: false`) ends it at once.\n */\nexport async function readWithRetry<T>(\n fn: () => Promise<T>,\n about: { what: string; instanceId: string },\n budget: { attempts: number; delaysMs: readonly number[] } = { attempts: 3, delaysMs: [100, 300] }\n): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n return await fn();\n } catch (error) {\n if (attempt >= budget.attempts || !isRetryable(error)) throw error;\n const delayMs = budget.delaysMs[Math.min(attempt, budget.delaysMs.length) - 1] ?? 0;\n console.warn(\n `[workflow] ${about.what}: read failed for instance ${about.instanceId} (attempt ${attempt} of ${budget.attempts}), retrying in ${delayMs} ms`,\n error\n );\n await new Promise<void>((resolve) => {\n setTimeout(resolve, delayMs);\n });\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,eAAsB,cACpB,IACA,OACA,SAA4D;CAAE,UAAU;CAAG,UAAU,CAAC,KAAK,GAAG;AAAE,GACpF;CACZ,KAAK,IAAI,UAAU,IAAK,WACtB,IAAI;EACF,OAAO,MAAM,GAAG;CAClB,SAAS,OAAO;EACd,IAAI,WAAW,OAAO,YAAY,CAAC,YAAY,KAAK,GAAG,MAAM;EAC7D,MAAM,UAAU,OAAO,SAAS,KAAK,IAAI,SAAS,OAAO,SAAS,MAAM,IAAI,MAAM;EAClF,QAAQ,KACN,cAAc,MAAM,KAAK,6BAA6B,MAAM,WAAW,YAAY,QAAQ,MAAM,OAAO,SAAS,iBAAiB,QAAQ,MAC1I,KACF;EACA,MAAM,IAAI,SAAe,YAAY;GACnC,WAAW,SAAS,OAAO;EAC7B,CAAC;CACH;AAEJ"}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_templates = require("../templates.cjs");
|
|
4
|
+
const require_contract = require("../contract.cjs");
|
|
5
|
+
const require_store_erasure = require("../store/erasure.cjs");
|
|
6
|
+
const require_cloudflare_d1_env = require("../cloudflare/d1-env.cjs");
|
|
7
|
+
const require_store_index = require("../store/index.cjs");
|
|
8
|
+
const require_host_ingest = require("./ingest.cjs");
|
|
9
|
+
const require_host_channels = require("./channels.cjs");
|
|
10
|
+
const require_reporting_tracking = require("../reporting/tracking.cjs");
|
|
11
|
+
const require_host_auth = require("./auth.cjs");
|
|
12
|
+
let zod_mini = require("zod/mini");
|
|
13
|
+
zod_mini = require_runtime.__toESM(zod_mini, 1);
|
|
14
|
+
//#region src/host/http.ts
|
|
15
|
+
const json = (body, status = 200) => new Response(JSON.stringify(body), {
|
|
16
|
+
status,
|
|
17
|
+
headers: { "content-type": "application/json" }
|
|
18
|
+
});
|
|
19
|
+
const notFound = () => json({ error: "not found" }, 404);
|
|
20
|
+
/** The request body is not JSON: the caller's to fix (a 400), not a server fault. */
|
|
21
|
+
var InvalidJsonError = class extends Error {
|
|
22
|
+
name = "InvalidJsonError";
|
|
23
|
+
};
|
|
24
|
+
async function readJson(request) {
|
|
25
|
+
try {
|
|
26
|
+
return await request.json();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new InvalidJsonError("invalid JSON body", { cause: error });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Request bodies are untrusted JSON. They are read as unknown fields and
|
|
33
|
+
* checked, never cast into the shape they are supposed to have: a cast only
|
|
34
|
+
* silences the compiler, and what arrives here reaches SQL parameters.
|
|
35
|
+
*/
|
|
36
|
+
async function readBody(request) {
|
|
37
|
+
const body = await readJson(request);
|
|
38
|
+
return isPlainObject(body) ? body : {};
|
|
39
|
+
}
|
|
40
|
+
function isPlainObject(value) {
|
|
41
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
function isNonEmptyString(value) {
|
|
44
|
+
return typeof value === "string" && value.length > 0;
|
|
45
|
+
}
|
|
46
|
+
/** A profile value: a scalar or null (which removes the property). Nested values are not profile data. */
|
|
47
|
+
function isScalarOrNull(value) {
|
|
48
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
49
|
+
}
|
|
50
|
+
/** How far ahead of the server's clock an event or device `ts` may be: clock skew, not the future. */
|
|
51
|
+
const TS_FUTURE_TOLERANCE_MS = 3e5;
|
|
52
|
+
const TS_ERROR = "ts must be a non-negative integer no later than 5 minutes in the future";
|
|
53
|
+
/**
|
|
54
|
+
* A caller's timestamp: epoch milliseconds, whole, not negative, and not past the skew tolerance.
|
|
55
|
+
* A far-future ts would put the event ahead of everything a window condition reads, and a
|
|
56
|
+
* fractional or unsafe one does not survive the store.
|
|
57
|
+
*/
|
|
58
|
+
function isValidTs(ts) {
|
|
59
|
+
return typeof ts === "number" && Number.isSafeInteger(ts) && ts >= 0 && ts <= Date.now() + TS_FUTURE_TOLERANCE_MS;
|
|
60
|
+
}
|
|
61
|
+
/** The contract's verdict: the value to use, or the response refusing the request. */
|
|
62
|
+
function checked(validation, result, original, what) {
|
|
63
|
+
if (result.ok) return { value: result.data };
|
|
64
|
+
const issues = result.issues.map((i) => `${i.path || "(root)"}: ${i.message}`);
|
|
65
|
+
if (validation.mode === "report") {
|
|
66
|
+
console.warn(`[workflow http] contract would refuse ${what}: ${issues.join("; ")}`);
|
|
67
|
+
return { value: original };
|
|
68
|
+
}
|
|
69
|
+
return { refused: json({
|
|
70
|
+
error: `${what} refused by the contract`,
|
|
71
|
+
issues: result.issues
|
|
72
|
+
}, 400) };
|
|
73
|
+
}
|
|
74
|
+
const routes = [
|
|
75
|
+
{
|
|
76
|
+
method: "GET",
|
|
77
|
+
path: "/health",
|
|
78
|
+
auth: "none",
|
|
79
|
+
handle: async () => json({ ok: true })
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
method: "*",
|
|
83
|
+
path: /^\/t\//,
|
|
84
|
+
auth: "none",
|
|
85
|
+
async handle({ request, store, host }) {
|
|
86
|
+
if (host.tracking === void 0 || store.reporting === void 0) return notFound();
|
|
87
|
+
return await require_reporting_tracking.handleTracking(request, store.reporting, host.tracking) ?? notFound();
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
method: "POST",
|
|
92
|
+
path: "/events",
|
|
93
|
+
auth: "bearer",
|
|
94
|
+
async handle({ request, env, store, validation }) {
|
|
95
|
+
const { id, userId, event, payload, ts } = await readBody(request);
|
|
96
|
+
if (!isNonEmptyString(userId) || !isNonEmptyString(event)) return json({ error: "userId and event required" }, 400);
|
|
97
|
+
if (event.startsWith("$")) return json({ error: "event names starting with $ are reserved" }, 400);
|
|
98
|
+
if (id !== void 0 && !isNonEmptyString(id)) return json({ error: "id must be a non-empty string" }, 400);
|
|
99
|
+
if (ts !== void 0 && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);
|
|
100
|
+
if (payload !== void 0 && !isPlainObject(payload)) return json({ error: "payload must be an object" }, 400);
|
|
101
|
+
let accepted = payload;
|
|
102
|
+
if (validation.contract !== void 0) {
|
|
103
|
+
const verdict = checked(validation, require_contract.checkEvent(validation.contract, event, payload ?? {}), accepted ?? {}, `event '${event}'${typeof id === "string" ? ` (${id})` : ""}`);
|
|
104
|
+
if ("refused" in verdict) return verdict.refused;
|
|
105
|
+
accepted = verdict.value;
|
|
106
|
+
}
|
|
107
|
+
return json(await require_host_ingest.ingestEvent(env, {
|
|
108
|
+
id,
|
|
109
|
+
userId,
|
|
110
|
+
event,
|
|
111
|
+
payload: accepted,
|
|
112
|
+
ts
|
|
113
|
+
}, store));
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
method: "POST",
|
|
118
|
+
path: "/identify",
|
|
119
|
+
auth: "bearer",
|
|
120
|
+
async handle({ request, env, store, validation }) {
|
|
121
|
+
const { userId, props } = await readBody(request);
|
|
122
|
+
if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
|
|
123
|
+
if (!isPlainObject(props)) return json({ error: "props must be an object" }, 400);
|
|
124
|
+
if (!Object.values(props).every(isScalarOrNull)) return json({ error: "props values must be scalars (string, number, boolean) or null" }, 400);
|
|
125
|
+
let patch = props;
|
|
126
|
+
if (validation.contract !== void 0) {
|
|
127
|
+
const verdict = checked(validation, validation.contract.parseProfilePatch(props), patch, "identify");
|
|
128
|
+
if ("refused" in verdict) return verdict.refused;
|
|
129
|
+
patch = verdict.value;
|
|
130
|
+
}
|
|
131
|
+
return json(await require_host_ingest.identifyUser(env, userId, patch, store));
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
method: "POST",
|
|
136
|
+
path: "/devices",
|
|
137
|
+
auth: "bearer",
|
|
138
|
+
async handle({ request, env, store }) {
|
|
139
|
+
const { userId, token, platform, ts } = await readBody(request);
|
|
140
|
+
if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
|
|
141
|
+
if (!isNonEmptyString(token)) return json({ error: "token required" }, 400);
|
|
142
|
+
if (platform !== "ios" && platform !== "android" && platform !== "web") return json({ error: "platform must be 'ios', 'android' or 'web'" }, 400);
|
|
143
|
+
if (ts !== void 0 && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);
|
|
144
|
+
const device = {
|
|
145
|
+
userId,
|
|
146
|
+
token,
|
|
147
|
+
platform,
|
|
148
|
+
...ts === void 0 ? {} : { ts }
|
|
149
|
+
};
|
|
150
|
+
return json(await require_host_ingest.registerDevice(env, device, store));
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
method: "POST",
|
|
155
|
+
path: "/devices/unbind",
|
|
156
|
+
auth: "bearer",
|
|
157
|
+
async handle({ request, env, store }) {
|
|
158
|
+
const { token } = await readBody(request);
|
|
159
|
+
if (!isNonEmptyString(token)) return json({ error: "token required" }, 400);
|
|
160
|
+
return json(await require_host_ingest.unbindDevice(env, token, store));
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
method: "POST",
|
|
165
|
+
path: "/devices/remove",
|
|
166
|
+
auth: "bearer",
|
|
167
|
+
async handle({ request, env, store }) {
|
|
168
|
+
const { token } = await readBody(request);
|
|
169
|
+
if (!isNonEmptyString(token)) return json({ error: "token required" }, 400);
|
|
170
|
+
return json(await require_host_ingest.removeDevice(env, token, store));
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
method: "POST",
|
|
175
|
+
path: "/messages/opened",
|
|
176
|
+
auth: "bearer",
|
|
177
|
+
async handle({ request, store }) {
|
|
178
|
+
const { userId, messageId } = await readBody(request);
|
|
179
|
+
if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
|
|
180
|
+
if (!isNonEmptyString(messageId)) return json({ error: "messageId required" }, 400);
|
|
181
|
+
const recorded = store.reporting !== void 0 && await require_reporting_tracking.recordPushOpen(store.reporting, userId, messageId);
|
|
182
|
+
return json({
|
|
183
|
+
ok: true,
|
|
184
|
+
recorded
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
method: "POST",
|
|
190
|
+
path: "/users/forget",
|
|
191
|
+
auth: "bearer",
|
|
192
|
+
async handle({ request, env, store }) {
|
|
193
|
+
const { userId } = await readBody(request);
|
|
194
|
+
if (!isNonEmptyString(userId)) return json({ error: "userId required" }, 400);
|
|
195
|
+
return json(await require_host_ingest.forgetUser(env, userId, store));
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
method: "POST",
|
|
200
|
+
path: "/deploy",
|
|
201
|
+
auth: "bearer",
|
|
202
|
+
async handle({ request, env, store }) {
|
|
203
|
+
return json(await require_host_ingest.deployBundle(env, await readJson(request), store));
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
method: "GET",
|
|
208
|
+
path: "/bundle",
|
|
209
|
+
auth: "bearer",
|
|
210
|
+
async handle({ host }) {
|
|
211
|
+
return host.bundle === void 0 ? notFound() : json(host.bundle());
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
method: "POST",
|
|
216
|
+
path: "/bundle/deploy",
|
|
217
|
+
auth: "bearer",
|
|
218
|
+
async handle({ env, store, host }) {
|
|
219
|
+
if (host.bundle === void 0) return notFound();
|
|
220
|
+
return json(await require_host_ingest.deployBundle(env, host.bundle(), store));
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
method: "POST",
|
|
225
|
+
path: "/segments/sweep",
|
|
226
|
+
auth: "bearer",
|
|
227
|
+
async handle({ host }) {
|
|
228
|
+
return host.sweep === void 0 ? notFound() : json(await host.sweep());
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
method: "GET",
|
|
233
|
+
path: /^\/preview\//,
|
|
234
|
+
auth: "bearer",
|
|
235
|
+
async handle({ url, host }) {
|
|
236
|
+
const { preview } = host;
|
|
237
|
+
if (preview === void 0) return notFound();
|
|
238
|
+
const key = url.pathname.slice(9);
|
|
239
|
+
if (!preview.has(key)) return json({ error: `unknown email template: ${key}` }, 404);
|
|
240
|
+
let props;
|
|
241
|
+
try {
|
|
242
|
+
props = JSON.parse(url.searchParams.get("props") ?? "{}");
|
|
243
|
+
} catch {
|
|
244
|
+
return json({ error: "props must be a JSON object" }, 400);
|
|
245
|
+
}
|
|
246
|
+
if (!isPlainObject(props)) return json({ error: "props must be a JSON object" }, 400);
|
|
247
|
+
const { subject, html } = await preview.render(key, props);
|
|
248
|
+
return new Response(html, { headers: {
|
|
249
|
+
"content-type": "text/html; charset=utf-8",
|
|
250
|
+
"x-subject": encodeURIComponent(subject)
|
|
251
|
+
} });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
];
|
|
255
|
+
function matches(path, pathname) {
|
|
256
|
+
if (typeof path === "string") return path === pathname;
|
|
257
|
+
if (path instanceof RegExp) return path.test(pathname);
|
|
258
|
+
return path(pathname);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Production without a bearer token is not an open instance, it is a mistake: anyone could
|
|
262
|
+
* ingest, identify and deploy. Only what recipients open (`/t/*`) and the health check stay up.
|
|
263
|
+
*/
|
|
264
|
+
function refusesOpen(request, env, pathname) {
|
|
265
|
+
return env.API_TOKEN === void 0 && require_host_channels.journeyMode(env) === "production" && !pathname.startsWith("/t/") && !(request.method === "GET" && pathname === "/health");
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* What a failed request answers. Validation problems are the caller's to fix (a 400, saying
|
|
269
|
+
* what); anything else stays out of the response body (internals are logged, not leaked).
|
|
270
|
+
*/
|
|
271
|
+
function failure(error) {
|
|
272
|
+
if (error instanceof InvalidJsonError) return json({ error: "invalid JSON body" }, 400);
|
|
273
|
+
if (error instanceof zod_mini.core.$ZodError) return json({ error: `invalid payload: ${error.message}` }, 400);
|
|
274
|
+
if (error instanceof require_host_ingest.BundleIntegrityError) return json({ error: error.message }, 400);
|
|
275
|
+
if (error instanceof require_templates.TemplateValidationError) return json({
|
|
276
|
+
error: error.message,
|
|
277
|
+
issues: error.issues
|
|
278
|
+
}, 400);
|
|
279
|
+
if (error instanceof require_store_erasure.UserErasedError) return json({ error: "user is erased" }, 410);
|
|
280
|
+
if (error instanceof require_store_index.SchemaMismatchError) return json({
|
|
281
|
+
error: error.message,
|
|
282
|
+
problems: error.problems
|
|
283
|
+
}, 503);
|
|
284
|
+
console.error("[workflow http]", error);
|
|
285
|
+
return json({ error: "internal error" }, 500);
|
|
286
|
+
}
|
|
287
|
+
/** One request through the table: the production gate, the bearer, the route, the error mapping. */
|
|
288
|
+
async function serve(request, ctx) {
|
|
289
|
+
const url = new URL(request.url);
|
|
290
|
+
if (ctx.host !== void 0 && refusesOpen(request, ctx.env, url.pathname)) return json({ error: "API_TOKEN is not set: production refuses to serve without it (set ENVIRONMENT=development to run open)" }, 503);
|
|
291
|
+
const candidates = routes.filter((route) => matches(route.path, url.pathname));
|
|
292
|
+
if (candidates.length === 0) return notFound();
|
|
293
|
+
if (candidates.some((route) => route.auth === "bearer") && !require_host_auth.authorized(request, ctx.env)) return json({ error: "unauthorized" }, 401);
|
|
294
|
+
const route = candidates.find((r) => r.method === "*" || r.method === request.method);
|
|
295
|
+
if (route === void 0) return json({ error: "method not allowed" }, 405);
|
|
296
|
+
try {
|
|
297
|
+
return await route.handle({
|
|
298
|
+
request,
|
|
299
|
+
url,
|
|
300
|
+
env: ctx.env,
|
|
301
|
+
store: ctx.store,
|
|
302
|
+
validation: ctx.validation ?? {},
|
|
303
|
+
host: ctx.host ?? {}
|
|
304
|
+
});
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return failure(error);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** The bare ingest API over one store: `/health`, `/events`, `/identify`, `/devices*`, `/messages/opened`, `/users/forget`, `/deploy`. */
|
|
310
|
+
function handleRequest(request, env, store = require_cloudflare_d1_env.d1Store(env), validation = {}) {
|
|
311
|
+
return serve(request, {
|
|
312
|
+
env,
|
|
313
|
+
store,
|
|
314
|
+
validation
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
exports.handleRequest = handleRequest;
|
|
319
|
+
exports.serve = serve;
|
|
320
|
+
|
|
321
|
+
//# sourceMappingURL=http.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.cjs","names":["handleTracking","checkEvent","ingestEvent","identifyUser","registerDevice","unbindDevice","removeDevice","recordPushOpen","forgetUser","deployBundle","journeyMode","z","BundleIntegrityError","TemplateValidationError","UserErasedError","SchemaMismatchError","authorized","d1Store"],"sources":["../../src/host/http.ts"],"sourcesContent":["import * as z from 'zod/mini';\nimport { d1Store } from '../cloudflare/d1-env';\nimport { type Contract, type ContractResult, checkEvent } from '../contract';\nimport type { EmailRenderer } from '../email-sender';\nimport type { BundleIR, ScalarIR } from '../ir';\nimport { type TrackingOptions, handleTracking, recordPushOpen } from '../reporting/tracking';\nimport {\n type JourneyStore,\n type ProfileProps,\n SchemaMismatchError,\n UserErasedError,\n} from '../store/index';\nimport { TemplateValidationError } from '../templates';\nimport { authorized } from './auth';\nimport { journeyMode } from './channels';\nimport {\n BundleIntegrityError,\n type SweepResult,\n deployBundle,\n forgetUser,\n identifyUser,\n ingestEvent,\n registerDevice,\n removeDevice,\n unbindDevice,\n} from './ingest';\nimport type { JourneyEnv } from './platform';\n\n/**\n * The HTTP surface, as one route table: the bare ingest API (`handleRequest`) and the routes\n * the full host adds (`serve` with its parts — the bundle, previews, tracking, the sweep). A\n * route whose part is absent answers 404, so the two share the table, the bearer check, the\n * body validation and the error mapping.\n */\n\n/**\n * How the ingest API applies a contract: 'enforce' refuses an invalid event or\n * patch with a 400 before anything is stored, woken or started; 'report' logs\n * the issues (event id, name, field paths — never the payload) and accepts it,\n * for checking real producers before turning enforcement on.\n */\nexport interface IngestValidation {\n contract?: Contract | undefined;\n mode?: 'enforce' | 'report' | undefined;\n}\n\n/** What the full host serves beyond the ingest API. A route whose part is absent answers 404. */\nexport interface HostParts {\n /** The bundle compiled into the code: `GET /bundle` shows it, `POST /bundle/deploy` makes it live. */\n bundle?: (() => BundleIR) | undefined;\n /** `GET /preview/:id?props=<JSON>`: the email templates, rendered. */\n preview?: { has(id: string): boolean; render: EmailRenderer } | undefined;\n /** `/t/*`, what recipients open (no bearer): served on a store that keeps reporting. */\n tracking?: TrackingOptions | undefined;\n /** `POST /segments/sweep`. */\n sweep?: (() => Promise<SweepResult>) | undefined;\n}\n\nexport interface ServeContext {\n env: JourneyEnv;\n store: JourneyStore;\n validation?: IngestValidation | undefined;\n /**\n * The host's parts. Their presence is what makes this a deployed host rather than the bare\n * API: production then refuses to serve without `API_TOKEN`.\n */\n host?: HostParts | undefined;\n}\n\ninterface RouteContext {\n request: Request;\n url: URL;\n env: JourneyEnv;\n store: JourneyStore;\n validation: IngestValidation;\n host: HostParts;\n}\n\ninterface Route {\n /** '*' takes every method (the tracking routes answer GET, HEAD and POST themselves). */\n method: 'GET' | 'POST' | '*';\n path: string | RegExp | ((pathname: string) => boolean);\n auth: 'none' | 'bearer';\n handle(ctx: RouteContext): Promise<Response>;\n}\n\nconst json = (body: unknown, status = 200): Response =>\n new Response(JSON.stringify(body), {\n status,\n headers: { 'content-type': 'application/json' },\n });\n\nconst notFound = () => json({ error: 'not found' }, 404);\n\n/* --------------------------------- bodies ---------------------------------- */\n\n/** The request body is not JSON: the caller's to fix (a 400), not a server fault. */\nclass InvalidJsonError extends Error {\n override readonly name = 'InvalidJsonError';\n}\n\nasync function readJson(request: Request): Promise<unknown> {\n try {\n return await request.json();\n } catch (error) {\n throw new InvalidJsonError('invalid JSON body', { cause: error });\n }\n}\n\n/**\n * Request bodies are untrusted JSON. They are read as unknown fields and\n * checked, never cast into the shape they are supposed to have: a cast only\n * silences the compiler, and what arrives here reaches SQL parameters.\n */\nasync function readBody(request: Request): Promise<Record<string, unknown>> {\n const body = await readJson(request);\n return isPlainObject(body) ? body : {};\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\n/** A profile value: a scalar or null (which removes the property). Nested values are not profile data. */\nfunction isScalarOrNull(value: unknown): value is string | number | boolean | null {\n return (\n value === null ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n );\n}\n\n/** How far ahead of the server's clock an event or device `ts` may be: clock skew, not the future. */\nconst TS_FUTURE_TOLERANCE_MS = 5 * 60_000;\nconst TS_ERROR = 'ts must be a non-negative integer no later than 5 minutes in the future';\n\n/**\n * A caller's timestamp: epoch milliseconds, whole, not negative, and not past the skew tolerance.\n * A far-future ts would put the event ahead of everything a window condition reads, and a\n * fractional or unsafe one does not survive the store.\n */\nfunction isValidTs(ts: unknown): ts is number {\n return (\n typeof ts === 'number' &&\n Number.isSafeInteger(ts) &&\n ts >= 0 &&\n ts <= Date.now() + TS_FUTURE_TOLERANCE_MS\n );\n}\n\n/** The contract's verdict: the value to use, or the response refusing the request. */\nfunction checked<T>(\n validation: IngestValidation,\n result: ContractResult<T>,\n original: T,\n what: string\n): { value: T } | { refused: Response } {\n if (result.ok) return { value: result.data };\n const issues = result.issues.map((i) => `${i.path || '(root)'}: ${i.message}`);\n if (validation.mode === 'report') {\n console.warn(`[workflow http] contract would refuse ${what}: ${issues.join('; ')}`);\n return { value: original };\n }\n return {\n refused: json({ error: `${what} refused by the contract`, issues: result.issues }, 400),\n };\n}\n\n/* --------------------------------- routes ---------------------------------- */\n\nconst routes: readonly Route[] = [\n { method: 'GET', path: '/health', auth: 'none', handle: async () => json({ ok: true }) },\n {\n // Opened by recipients, so no bearer: the routes only record, and redirect to recorded URLs\n method: '*',\n path: /^\\/t\\//,\n auth: 'none',\n async handle({ request, store, host }) {\n if (host.tracking === undefined || store.reporting === undefined) return notFound();\n return (await handleTracking(request, store.reporting, host.tracking)) ?? notFound();\n },\n },\n {\n method: 'POST',\n path: '/events',\n auth: 'bearer',\n async handle({ request, env, store, validation }) {\n const { id, userId, event, payload, ts } = await readBody(request);\n if (!isNonEmptyString(userId) || !isNonEmptyString(event)) {\n return json({ error: 'userId and event required' }, 400);\n }\n if (event.startsWith('$')) {\n return json({ error: 'event names starting with $ are reserved' }, 400);\n }\n // An empty id is rejected rather than treated as absent: a caller that\n // sent one meant to identify the occurrence, and silently minting a\n // different one would turn their retry into a duplicate.\n if (id !== undefined && !isNonEmptyString(id)) {\n return json({ error: 'id must be a non-empty string' }, 400);\n }\n if (ts !== undefined && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);\n if (payload !== undefined && !isPlainObject(payload)) {\n return json({ error: 'payload must be an object' }, 400);\n }\n let accepted = payload;\n if (validation.contract !== undefined) {\n const verdict = checked(\n validation,\n checkEvent(validation.contract, event, payload ?? {}),\n accepted ?? {},\n `event '${event}'${typeof id === 'string' ? ` (${id})` : ''}`\n );\n if ('refused' in verdict) return verdict.refused;\n accepted = verdict.value;\n }\n return json(await ingestEvent(env, { id, userId, event, payload: accepted, ts }, store));\n },\n },\n {\n method: 'POST',\n path: '/identify',\n auth: 'bearer',\n async handle({ request, env, store, validation }) {\n const { userId, props } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n if (!isPlainObject(props)) return json({ error: 'props must be an object' }, 400);\n // Profiles hold scalars only (both stores merge at the top level; a nested object would\n // be merged differently by each): refused here, contract or not\n if (!Object.values(props).every(isScalarOrNull)) {\n return json(\n { error: 'props values must be scalars (string, number, boolean) or null' },\n 400\n );\n }\n let patch = props as ProfileProps;\n if (validation.contract !== undefined) {\n const verdict = checked(\n validation,\n validation.contract.parseProfilePatch(props),\n patch,\n 'identify'\n );\n if ('refused' in verdict) return verdict.refused;\n patch = verdict.value as ProfileProps;\n }\n return json(await identifyUser(env, userId, patch, store));\n },\n },\n {\n method: 'POST',\n path: '/devices',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { userId, token, platform, ts } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n if (!isNonEmptyString(token)) return json({ error: 'token required' }, 400);\n if (platform !== 'ios' && platform !== 'android' && platform !== 'web') {\n return json({ error: \"platform must be 'ios', 'android' or 'web'\" }, 400);\n }\n if (ts !== undefined && !isValidTs(ts)) return json({ error: TS_ERROR }, 400);\n const device = { userId, token, platform, ...(ts === undefined ? {} : { ts }) };\n return json(await registerDevice(env, device, store));\n },\n },\n {\n method: 'POST',\n path: '/devices/unbind',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { token } = await readBody(request);\n if (!isNonEmptyString(token)) return json({ error: 'token required' }, 400);\n return json(await unbindDevice(env, token, store));\n },\n },\n {\n method: 'POST',\n path: '/devices/remove',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { token } = await readBody(request);\n if (!isNonEmptyString(token)) return json({ error: 'token required' }, 400);\n return json(await removeDevice(env, token, store));\n },\n },\n {\n method: 'POST',\n path: '/messages/opened',\n auth: 'bearer',\n async handle({ request, store }) {\n const { userId, messageId } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n if (!isNonEmptyString(messageId)) return json({ error: 'messageId required' }, 400);\n const recorded =\n store.reporting !== undefined && (await recordPushOpen(store.reporting, userId, messageId));\n return json({ ok: true, recorded });\n },\n },\n {\n method: 'POST',\n path: '/users/forget',\n auth: 'bearer',\n async handle({ request, env, store }) {\n const { userId } = await readBody(request);\n if (!isNonEmptyString(userId)) return json({ error: 'userId required' }, 400);\n return json(await forgetUser(env, userId, store));\n },\n },\n {\n method: 'POST',\n path: '/deploy',\n auth: 'bearer',\n async handle({ request, env, store }) {\n return json(await deployBundle(env, await readJson(request), store));\n },\n },\n {\n method: 'GET',\n path: '/bundle',\n auth: 'bearer',\n async handle({ host }) {\n return host.bundle === undefined ? notFound() : json(host.bundle());\n },\n },\n {\n method: 'POST',\n path: '/bundle/deploy',\n auth: 'bearer',\n async handle({ env, store, host }) {\n if (host.bundle === undefined) return notFound();\n return json(await deployBundle(env, host.bundle(), store));\n },\n },\n {\n method: 'POST',\n path: '/segments/sweep',\n auth: 'bearer',\n async handle({ host }) {\n return host.sweep === undefined ? notFound() : json(await host.sweep());\n },\n },\n {\n method: 'GET',\n path: /^\\/preview\\//,\n auth: 'bearer',\n async handle({ url, host }) {\n const { preview } = host;\n if (preview === undefined) return notFound();\n const key = url.pathname.slice('/preview/'.length);\n if (!preview.has(key)) return json({ error: `unknown email template: ${key}` }, 404);\n // `?props=<JSON object>`: JSON keeps numbers and booleans typed, which query strings cannot\n let props: unknown;\n try {\n props = JSON.parse(url.searchParams.get('props') ?? '{}');\n } catch {\n return json({ error: 'props must be a JSON object' }, 400);\n }\n if (!isPlainObject(props)) return json({ error: 'props must be a JSON object' }, 400);\n const { subject, html } = await preview.render(key, props as Record<string, ScalarIR>);\n // A header holds bytes, not text: a subject with a non-Latin-1 character would throw\n // here, so it travels percent-encoded (the reader `decodeURIComponent`s it)\n return new Response(html, {\n headers: {\n 'content-type': 'text/html; charset=utf-8',\n 'x-subject': encodeURIComponent(subject),\n },\n });\n },\n },\n];\n\nfunction matches(path: Route['path'], pathname: string): boolean {\n if (typeof path === 'string') return path === pathname;\n if (path instanceof RegExp) return path.test(pathname);\n return path(pathname);\n}\n\n/**\n * Production without a bearer token is not an open instance, it is a mistake: anyone could\n * ingest, identify and deploy. Only what recipients open (`/t/*`) and the health check stay up.\n */\nfunction refusesOpen(request: Request, env: JourneyEnv, pathname: string): boolean {\n return (\n env.API_TOKEN === undefined &&\n journeyMode(env) === 'production' &&\n !pathname.startsWith('/t/') &&\n !(request.method === 'GET' && pathname === '/health')\n );\n}\n\n/**\n * What a failed request answers. Validation problems are the caller's to fix (a 400, saying\n * what); anything else stays out of the response body (internals are logged, not leaked).\n */\nfunction failure(error: unknown): Response {\n if (error instanceof InvalidJsonError) return json({ error: 'invalid JSON body' }, 400);\n if (error instanceof z.core.$ZodError) {\n return json({ error: `invalid payload: ${error.message}` }, 400);\n }\n // The caller sent a self-inconsistent bundle: their problem to fix, so say what is wrong\n if (error instanceof BundleIntegrityError) return json({ error: error.message }, 400);\n // The query string is the props: a refusal is the caller's to fix, with the field paths\n if (error instanceof TemplateValidationError) {\n return json({ error: error.message, issues: error.issues }, 400);\n }\n // The user has an erasure tombstone: gone, and nothing about them is taken, now or later\n if (error instanceof UserErasedError) return json({ error: 'user is erased' }, 410);\n // The operator's to fix (run the migrations), so the response says what is missing\n if (error instanceof SchemaMismatchError) {\n return json({ error: error.message, problems: error.problems }, 503);\n }\n console.error('[workflow http]', error);\n return json({ error: 'internal error' }, 500);\n}\n\n/** One request through the table: the production gate, the bearer, the route, the error mapping. */\nexport async function serve(request: Request, ctx: ServeContext): Promise<Response> {\n const url = new URL(request.url);\n if (ctx.host !== undefined && refusesOpen(request, ctx.env, url.pathname)) {\n return json(\n {\n error:\n 'API_TOKEN is not set: production refuses to serve without it (set ENVIRONMENT=development to run open)',\n },\n 503\n );\n }\n const candidates = routes.filter((route) => matches(route.path, url.pathname));\n if (candidates.length === 0) return notFound();\n // Bearer auth on everything but the health check and the recipients' routes. An unset token\n // means an open dev instance (see JourneyEnv.API_TOKEN); production refuses to run that way\n if (candidates.some((route) => route.auth === 'bearer') && !authorized(request, ctx.env)) {\n return json({ error: 'unauthorized' }, 401);\n }\n const route = candidates.find((r) => r.method === '*' || r.method === request.method);\n if (route === undefined) return json({ error: 'method not allowed' }, 405);\n try {\n return await route.handle({\n request,\n url,\n env: ctx.env,\n store: ctx.store,\n validation: ctx.validation ?? {},\n host: ctx.host ?? {},\n });\n } catch (error) {\n return failure(error);\n }\n}\n\n/** The bare ingest API over one store: `/health`, `/events`, `/identify`, `/devices*`, `/messages/opened`, `/users/forget`, `/deploy`. */\nexport function handleRequest(\n request: Request,\n env: JourneyEnv,\n store: JourneyStore = d1Store(env),\n validation: IngestValidation = {}\n): Promise<Response> {\n return serve(request, { env, store, validation });\n}\n"],"mappings":";;;;;;;;;;;;;;AAsFA,MAAM,QAAQ,MAAe,SAAS,QACpC,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;CACjC;CACA,SAAS,EAAE,gBAAgB,mBAAmB;AAChD,CAAC;AAEH,MAAM,iBAAiB,KAAK,EAAE,OAAO,YAAY,GAAG,GAAG;;AAKvD,IAAM,mBAAN,cAA+B,MAAM;CACnC,OAAyB;AAC3B;AAEA,eAAe,SAAS,SAAoC;CAC1D,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK;CAC5B,SAAS,OAAO;EACd,MAAM,IAAI,iBAAiB,qBAAqB,EAAE,OAAO,MAAM,CAAC;CAClE;AACF;;;;;;AAOA,eAAe,SAAS,SAAoD;CAC1E,MAAM,OAAO,MAAM,SAAS,OAAO;CACnC,OAAO,cAAc,IAAI,IAAI,OAAO,CAAC;AACvC;AAEA,SAAS,cAAc,OAAkD;CACvE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,iBAAiB,OAAiC;CACzD,OAAO,OAAO,UAAU,YAAY,MAAM,SAAS;AACrD;;AAGA,SAAS,eAAe,OAA2D;CACjF,OACE,UAAU,QACV,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU;AAErB;;AAGA,MAAM,yBAAyB;AAC/B,MAAM,WAAW;;;;;;AAOjB,SAAS,UAAU,IAA2B;CAC5C,OACE,OAAO,OAAO,YACd,OAAO,cAAc,EAAE,KACvB,MAAM,KACN,MAAM,KAAK,IAAI,IAAI;AAEvB;;AAGA,SAAS,QACP,YACA,QACA,UACA,MACsC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