@shware/workflow 5.0.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -53
- package/dist/aws/index.cjs +1 -1
- package/dist/aws/index.mjs +1 -1
- package/dist/client.cjs +68 -4
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +39 -3
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.mts +39 -3
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +68 -4
- package/dist/client.mjs.map +1 -1
- package/dist/cloudflare/index.cjs +4 -4
- package/dist/cloudflare/index.mjs +4 -4
- package/dist/cloudflare/runner.cjs +1 -1
- package/dist/cloudflare/runner.d.cts +1 -1
- package/dist/cloudflare/runner.d.mts +1 -1
- package/dist/cloudflare/runner.mjs +1 -1
- package/dist/config.cjs +24 -3
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +15 -9
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +15 -9
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +25 -4
- package/dist/config.mjs.map +1 -1
- package/dist/contract.cjs +11 -0
- package/dist/contract.cjs.map +1 -1
- package/dist/contract.d.cts +28 -7
- package/dist/contract.d.cts.map +1 -1
- package/dist/contract.d.mts +28 -7
- package/dist/contract.d.mts.map +1 -1
- package/dist/contract.mjs +11 -0
- package/dist/contract.mjs.map +1 -1
- package/dist/dsl/bundle.cjs +4 -3
- package/dist/dsl/bundle.cjs.map +1 -1
- package/dist/dsl/bundle.d.cts +5 -1
- package/dist/dsl/bundle.d.cts.map +1 -1
- package/dist/dsl/bundle.d.mts +5 -1
- package/dist/dsl/bundle.d.mts.map +1 -1
- package/dist/dsl/bundle.mjs +4 -3
- package/dist/dsl/bundle.mjs.map +1 -1
- package/dist/dsl/flow.cjs +2 -1
- package/dist/dsl/flow.cjs.map +1 -1
- package/dist/dsl/flow.d.cts +1 -1
- package/dist/dsl/flow.d.cts.map +1 -1
- package/dist/dsl/flow.d.mts +1 -1
- package/dist/dsl/flow.d.mts.map +1 -1
- package/dist/dsl/flow.mjs +2 -1
- package/dist/dsl/flow.mjs.map +1 -1
- package/dist/dsl/workflow.cjs +2 -2
- package/dist/dsl/workflow.mjs +2 -2
- package/dist/email-sender.cjs +3 -2
- package/dist/email-sender.cjs.map +1 -1
- package/dist/email-sender.d.cts +5 -4
- package/dist/email-sender.d.cts.map +1 -1
- package/dist/email-sender.d.mts +5 -4
- package/dist/email-sender.d.mts.map +1 -1
- package/dist/email-sender.mjs +3 -2
- package/dist/email-sender.mjs.map +1 -1
- package/dist/email.cjs +66 -11
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +72 -12
- package/dist/email.d.cts.map +1 -1
- package/dist/email.d.mts +72 -12
- package/dist/email.d.mts.map +1 -1
- package/dist/email.mjs +63 -12
- package/dist/email.mjs.map +1 -1
- package/dist/engine/condition.cjs.map +1 -1
- package/dist/engine/condition.d.cts.map +1 -1
- package/dist/engine/condition.d.mts.map +1 -1
- package/dist/engine/condition.mjs.map +1 -1
- package/dist/engine/index.cjs +1 -1
- package/dist/engine/index.mjs +1 -1
- package/dist/engine/interpreter.cjs +21 -4
- package/dist/engine/interpreter.cjs.map +1 -1
- package/dist/engine/interpreter.mjs +21 -4
- package/dist/engine/interpreter.mjs.map +1 -1
- package/dist/engine/ports.d.cts +14 -2
- package/dist/engine/ports.d.cts.map +1 -1
- package/dist/engine/ports.d.mts +14 -2
- package/dist/engine/ports.d.mts.map +1 -1
- package/dist/host/channels.cjs +1 -1
- package/dist/host/channels.mjs +1 -1
- package/dist/host/execute.cjs +2 -2
- package/dist/host/execute.d.cts +1 -1
- package/dist/host/execute.d.mts +1 -1
- package/dist/host/execute.mjs +2 -2
- package/dist/host/http.cjs +75 -5
- package/dist/host/http.cjs.map +1 -1
- package/dist/host/http.d.cts +2 -2
- package/dist/host/http.d.cts.map +1 -1
- package/dist/host/http.d.mts +2 -2
- package/dist/host/http.d.mts.map +1 -1
- package/dist/host/http.mjs +76 -6
- package/dist/host/http.mjs.map +1 -1
- package/dist/host/ingest.cjs +173 -4
- package/dist/host/ingest.cjs.map +1 -1
- package/dist/host/ingest.d.cts +99 -0
- package/dist/host/ingest.d.cts.map +1 -1
- package/dist/host/ingest.d.mts +99 -0
- package/dist/host/ingest.d.mts.map +1 -1
- package/dist/host/ingest.mjs +167 -5
- package/dist/host/ingest.mjs.map +1 -1
- package/dist/host/journey-host.cjs +10 -8
- package/dist/host/journey-host.cjs.map +1 -1
- package/dist/host/journey-host.mjs +10 -8
- package/dist/host/journey-host.mjs.map +1 -1
- package/dist/index.cjs +8 -2
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +5 -5
- package/dist/ir.cjs +11 -2
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +17 -0
- package/dist/ir.d.cts.map +1 -1
- package/dist/ir.d.mts +17 -0
- package/dist/ir.d.mts.map +1 -1
- package/dist/ir.mjs +11 -3
- package/dist/ir.mjs.map +1 -1
- package/dist/react-email.cjs +6 -5
- package/dist/react-email.cjs.map +1 -1
- package/dist/react-email.d.cts.map +1 -1
- package/dist/react-email.d.mts.map +1 -1
- package/dist/react-email.mjs +6 -5
- package/dist/react-email.mjs.map +1 -1
- package/dist/reporting/observer.cjs +4 -1
- package/dist/reporting/observer.cjs.map +1 -1
- package/dist/reporting/observer.d.cts +2 -1
- package/dist/reporting/observer.d.cts.map +1 -1
- package/dist/reporting/observer.d.mts +2 -1
- package/dist/reporting/observer.d.mts.map +1 -1
- package/dist/reporting/observer.mjs +4 -1
- package/dist/reporting/observer.mjs.map +1 -1
- package/dist/reporting/tracking.cjs +31 -10
- package/dist/reporting/tracking.cjs.map +1 -1
- package/dist/reporting/tracking.d.cts +15 -6
- package/dist/reporting/tracking.d.cts.map +1 -1
- package/dist/reporting/tracking.d.mts +15 -6
- package/dist/reporting/tracking.d.mts.map +1 -1
- package/dist/reporting/tracking.mjs +31 -11
- package/dist/reporting/tracking.mjs.map +1 -1
- package/dist/store/facts.cjs +3 -3
- package/dist/store/facts.cjs.map +1 -1
- package/dist/store/facts.d.cts +2 -2
- package/dist/store/facts.d.cts.map +1 -1
- package/dist/store/facts.d.mts +2 -2
- package/dist/store/facts.d.mts.map +1 -1
- package/dist/store/facts.mjs +3 -3
- package/dist/store/facts.mjs.map +1 -1
- package/dist/store/index.cjs +1 -1
- package/dist/store/index.cjs.map +1 -1
- package/dist/store/index.d.cts +44 -13
- package/dist/store/index.d.cts.map +1 -1
- package/dist/store/index.d.mts +44 -13
- package/dist/store/index.d.mts.map +1 -1
- package/dist/store/index.mjs +1 -1
- package/dist/store/index.mjs.map +1 -1
- package/dist/store/postgres-reporting.cjs +30 -10
- package/dist/store/postgres-reporting.cjs.map +1 -1
- package/dist/store/postgres-reporting.d.cts +4 -2
- package/dist/store/postgres-reporting.d.cts.map +1 -1
- package/dist/store/postgres-reporting.d.mts +4 -2
- package/dist/store/postgres-reporting.d.mts.map +1 -1
- package/dist/store/postgres-reporting.mjs +30 -10
- package/dist/store/postgres-reporting.mjs.map +1 -1
- package/dist/store/postgres.cjs +39 -3
- package/dist/store/postgres.cjs.map +1 -1
- package/dist/store/postgres.d.cts +4 -2
- package/dist/store/postgres.d.cts.map +1 -1
- package/dist/store/postgres.d.mts +4 -2
- package/dist/store/postgres.d.mts.map +1 -1
- package/dist/store/postgres.mjs +40 -4
- package/dist/store/postgres.mjs.map +1 -1
- package/dist/store/tables.cjs +75 -11
- package/dist/store/tables.cjs.map +1 -1
- package/dist/store/tables.d.cts +17 -1
- package/dist/store/tables.d.cts.map +1 -1
- package/dist/store/tables.d.mts +17 -1
- package/dist/store/tables.d.mts.map +1 -1
- package/dist/store/tables.mjs +74 -12
- package/dist/store/tables.mjs.map +1 -1
- package/dist/templates.cjs +60 -7
- package/dist/templates.cjs.map +1 -1
- package/dist/templates.d.cts +101 -13
- package/dist/templates.d.cts.map +1 -1
- package/dist/templates.d.mts +101 -13
- package/dist/templates.d.mts.map +1 -1
- package/dist/templates.mjs +61 -9
- package/dist/templates.mjs.map +1 -1
- package/package.json +1 -1
package/dist/client.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Contract, ContractIssue, ProfilePatch, Topic } from "./contract.cjs";
|
|
1
2
|
import { ProfileProps } from "./store/index.cjs";
|
|
2
|
-
import {
|
|
3
|
-
import { DeployResult, IdentifyResult, IngestResult } from "./host/ingest.cjs";
|
|
3
|
+
import { ChannelSubscriptions, ChannelSubscriptionsPatch, DeployResult, IdentifyResult, IngestResult, MessageOrigin, MessageSubscriptions, SubscriptionChannel, Subscriptions, SubscriptionsPatch } from "./host/ingest.cjs";
|
|
4
4
|
import * as core from "zod/v4/core";
|
|
5
5
|
/**
|
|
6
6
|
* `@shware/workflow/client` — the producer side of the ingest API, for the
|
|
@@ -39,6 +39,8 @@ type EventsOf<C> = C extends Contract<infer E> ? E : never;
|
|
|
39
39
|
export type ClientEventName<C> = [C] extends [undefined] ? string : keyof EventsOf<C> & string;
|
|
40
40
|
type TrackArgs<C, K> = [C] extends [undefined] ? [payload?: Record<string, unknown>, options?: TrackOptions] : K extends keyof EventsOf<C> ? [payload: core.input<EventsOf<C>[K]>, options?: TrackOptions] : never;
|
|
41
41
|
type IdentifyProps<C> = [C] extends [undefined] ? ProfileProps : C extends Contract<Record<string, core.$ZodObject>, infer P> ? ProfilePatch<P> : never;
|
|
42
|
+
/** The topics the client's contract declares; any string without a contract. */
|
|
43
|
+
export type ClientTopic<C> = [C] extends [undefined] ? string : Topic<C>;
|
|
42
44
|
export interface TrackOptions {
|
|
43
45
|
/** The occurrence's identity: a retry with the same id is recorded once. */
|
|
44
46
|
id?: string;
|
|
@@ -99,9 +101,43 @@ export declare class JourneyClient<C extends Contract | undefined = undefined> {
|
|
|
99
101
|
ok: true;
|
|
100
102
|
woke: number;
|
|
101
103
|
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Where the user stands, topic × channel: for `email` and for `push`, `all` (false once they
|
|
106
|
+
* opted out of the whole channel) and each declared topic (false once they opted out of it on
|
|
107
|
+
* that channel) — the engine's record, which a preference page shows as it is. The two are
|
|
108
|
+
* independent flags: a topic answers its own opt-out even while `all` is false, so `all: false`
|
|
109
|
+
* masks every topic however they read (nothing is sent on the channel until it is true again).
|
|
110
|
+
* Rejects with a 410 for an erased user.
|
|
111
|
+
*/
|
|
112
|
+
getSubscriptions(userId: string): Promise<Subscriptions<ClientTopic<C>>>;
|
|
113
|
+
/**
|
|
114
|
+
* Set subscriptions: only what the patch names changes, per channel (`{ email: { topics: {
|
|
115
|
+
* newsletter: false } } }` opts out of one topic's emails, `{ push: { all: false } }` of every
|
|
116
|
+
* push — the in-app opt-out App Store Review Guideline 4.5.4 asks for). `all: true` clears the
|
|
117
|
+
* channel-wide opt-out only: a topic opted out on its own stays off until the patch names it,
|
|
118
|
+
* so a preference page's "subscribe to all" sends `all: true` plus every topic `true`. Answers
|
|
119
|
+
* the subscriptions as they now stand. With a contract, a topic it does not declare is refused
|
|
120
|
+
* here, before the request; the engine refuses it too.
|
|
121
|
+
*/
|
|
122
|
+
setSubscriptions(userId: string, patch: SubscriptionsPatch<ClientTopic<C>>): Promise<Subscriptions<ClientTopic<C>>>;
|
|
123
|
+
/**
|
|
124
|
+
* `getSubscriptions` for the recipient of one copy, by the message id an email's preferences
|
|
125
|
+
* link carries (`email.preferencesUrl?m=<message id>`): how a preference page works without a
|
|
126
|
+
* sign-in. The answer adds `message: { channel, topic }`, the copy the page was opened from,
|
|
127
|
+
* so it can highlight that topic. Rejects with a 404 for an id that names no copy — never
|
|
128
|
+
* sent, or erased with its user — and for a transactional one; the page should show the link
|
|
129
|
+
* as expired. The message id is the capability, so the app proxies this behind its own API
|
|
130
|
+
* and rate-limits it.
|
|
131
|
+
*/
|
|
132
|
+
getSubscriptionsByMessage(messageId: string): Promise<MessageSubscriptions<ClientTopic<C>>>;
|
|
133
|
+
/** `setSubscriptions` for the recipient of one copy; the patch and the answer are those of `getSubscriptionsByMessage`. */
|
|
134
|
+
setSubscriptionsByMessage(messageId: string, patch: SubscriptionsPatch<ClientTopic<C>>): Promise<MessageSubscriptions<ClientTopic<C>>>;
|
|
135
|
+
/** With a contract, the refusal of a patch naming a topic it does not declare; undefined when the patch is fine. */
|
|
136
|
+
private undeclaredTopics;
|
|
102
137
|
/** Deploy a compiled bundle (BundleIR). */
|
|
103
138
|
deploy(bundle: unknown): Promise<DeployResult>;
|
|
104
139
|
private post;
|
|
140
|
+
private request;
|
|
105
141
|
}
|
|
106
|
-
export {};
|
|
142
|
+
export type { ChannelSubscriptions, ChannelSubscriptionsPatch, MessageOrigin, MessageSubscriptions, SubscriptionChannel, Subscriptions, SubscriptionsPatch };
|
|
107
143
|
//# sourceMappingURL=client.d.cts.map
|
package/dist/client.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;iBAoBiB,qBAAqB,UAAU;;;;;EAK9C,WAAW;;EAEX;;EAEA;;EAEA,eAAe;;qBAGJ,2BAA2B;WAE3B;WACA;WACA;EAHX,YACW,cACA,gBACA;;;qBAQA,+BAA+B;WAE/B;WACA;WACA,QAAQ;EAHnB,YACW,cACA,2BACA,QAAQ;;KAWhB,SAAS,KAAK,UAAU,eAAe,KAAK;;YAErC,gBAAgB,MAAM,wCAAwC,SAAS;KAC9E,UAAU,GAAG,MAAM,0BACnB,UAAU,yBAAyB,UAAU,gBAC9C,gBAAgB,SAAS,MACtB,SAAS,KAAK,MAAM,SAAS,GAAG,KAAK,UAAU;KAEjD,cAAc,MAAM,yBACrB,eACA,UAAU,SAAS,eAAe,KAAK,mBAAmB,KACxD,aAAa;;YAIP,YAAY,MAAM,kCAAkC,MAAM;iBAYrD;;EAEf;;EAEA;;qBAGW,cAAc,UAAU;mBACN;EAA7B,YAA6B,SAAS,qBAAqB;;EAG3D,SAAS,gBAAgB,OAAO,cAAc,KAAK,QAAQ;;;;;;;EAgB3D,MAAM,UAAU,gBAAgB,IAC9B,gBACA,OAAO,MACJ,MAAM,UAAU,GAAG,KACrB,QAAQ;;;;;;EAsBX,eACE,gBACA;IAAU;IAAe;IAAqC;MAC7D;IAAU;IAAU;;;;;;EAcvB,cAAc,gBAAgB,oBAAoB;IAAU;IAAU;;;;;;;;EAUtE,WAAW,iBAAiB;IAAU;IAAU;IAAiB;;;EAKjE,aAAa,gBAAgB;IAAU;IAAU;;;EAKjD,aAAa,gBAAgB;IAAU;IAAU;;;;;;;;;;EAYjD,iBAAiB,iBAAiB,QAAQ,cAAc,YAAY;;;;;;;;;;EAapE,iBACE,gBACA,OAAO,mBAAmB,YAAY,MACrC,QAAQ,cAAc,YAAY;;;;;;;;;;EAerC,0BAA0B,oBAAoB,QAAQ,qBAAqB,YAAY;;EAKvF,0BACE,mBACA,OAAO,mBAAmB,YAAY,MACrC,QAAQ,qBAAqB,YAAY;;UAOpC;;EAmBR,OAAO,kBAAkB,QAAQ;UAIzB;UAIM"}
|
package/dist/client.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Contract, ContractIssue, ProfilePatch, Topic } from "./contract.mjs";
|
|
1
2
|
import { ProfileProps } from "./store/index.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { DeployResult, IdentifyResult, IngestResult } from "./host/ingest.mjs";
|
|
3
|
+
import { ChannelSubscriptions, ChannelSubscriptionsPatch, DeployResult, IdentifyResult, IngestResult, MessageOrigin, MessageSubscriptions, SubscriptionChannel, Subscriptions, SubscriptionsPatch } from "./host/ingest.mjs";
|
|
4
4
|
import * as core from "zod/v4/core";
|
|
5
5
|
/**
|
|
6
6
|
* `@shware/workflow/client` — the producer side of the ingest API, for the
|
|
@@ -39,6 +39,8 @@ type EventsOf<C> = C extends Contract<infer E> ? E : never;
|
|
|
39
39
|
export type ClientEventName<C> = [C] extends [undefined] ? string : keyof EventsOf<C> & string;
|
|
40
40
|
type TrackArgs<C, K> = [C] extends [undefined] ? [payload?: Record<string, unknown>, options?: TrackOptions] : K extends keyof EventsOf<C> ? [payload: core.input<EventsOf<C>[K]>, options?: TrackOptions] : never;
|
|
41
41
|
type IdentifyProps<C> = [C] extends [undefined] ? ProfileProps : C extends Contract<Record<string, core.$ZodObject>, infer P> ? ProfilePatch<P> : never;
|
|
42
|
+
/** The topics the client's contract declares; any string without a contract. */
|
|
43
|
+
export type ClientTopic<C> = [C] extends [undefined] ? string : Topic<C>;
|
|
42
44
|
export interface TrackOptions {
|
|
43
45
|
/** The occurrence's identity: a retry with the same id is recorded once. */
|
|
44
46
|
id?: string;
|
|
@@ -99,9 +101,43 @@ export declare class JourneyClient<C extends Contract | undefined = undefined> {
|
|
|
99
101
|
ok: true;
|
|
100
102
|
woke: number;
|
|
101
103
|
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Where the user stands, topic × channel: for `email` and for `push`, `all` (false once they
|
|
106
|
+
* opted out of the whole channel) and each declared topic (false once they opted out of it on
|
|
107
|
+
* that channel) — the engine's record, which a preference page shows as it is. The two are
|
|
108
|
+
* independent flags: a topic answers its own opt-out even while `all` is false, so `all: false`
|
|
109
|
+
* masks every topic however they read (nothing is sent on the channel until it is true again).
|
|
110
|
+
* Rejects with a 410 for an erased user.
|
|
111
|
+
*/
|
|
112
|
+
getSubscriptions(userId: string): Promise<Subscriptions<ClientTopic<C>>>;
|
|
113
|
+
/**
|
|
114
|
+
* Set subscriptions: only what the patch names changes, per channel (`{ email: { topics: {
|
|
115
|
+
* newsletter: false } } }` opts out of one topic's emails, `{ push: { all: false } }` of every
|
|
116
|
+
* push — the in-app opt-out App Store Review Guideline 4.5.4 asks for). `all: true` clears the
|
|
117
|
+
* channel-wide opt-out only: a topic opted out on its own stays off until the patch names it,
|
|
118
|
+
* so a preference page's "subscribe to all" sends `all: true` plus every topic `true`. Answers
|
|
119
|
+
* the subscriptions as they now stand. With a contract, a topic it does not declare is refused
|
|
120
|
+
* here, before the request; the engine refuses it too.
|
|
121
|
+
*/
|
|
122
|
+
setSubscriptions(userId: string, patch: SubscriptionsPatch<ClientTopic<C>>): Promise<Subscriptions<ClientTopic<C>>>;
|
|
123
|
+
/**
|
|
124
|
+
* `getSubscriptions` for the recipient of one copy, by the message id an email's preferences
|
|
125
|
+
* link carries (`email.preferencesUrl?m=<message id>`): how a preference page works without a
|
|
126
|
+
* sign-in. The answer adds `message: { channel, topic }`, the copy the page was opened from,
|
|
127
|
+
* so it can highlight that topic. Rejects with a 404 for an id that names no copy — never
|
|
128
|
+
* sent, or erased with its user — and for a transactional one; the page should show the link
|
|
129
|
+
* as expired. The message id is the capability, so the app proxies this behind its own API
|
|
130
|
+
* and rate-limits it.
|
|
131
|
+
*/
|
|
132
|
+
getSubscriptionsByMessage(messageId: string): Promise<MessageSubscriptions<ClientTopic<C>>>;
|
|
133
|
+
/** `setSubscriptions` for the recipient of one copy; the patch and the answer are those of `getSubscriptionsByMessage`. */
|
|
134
|
+
setSubscriptionsByMessage(messageId: string, patch: SubscriptionsPatch<ClientTopic<C>>): Promise<MessageSubscriptions<ClientTopic<C>>>;
|
|
135
|
+
/** With a contract, the refusal of a patch naming a topic it does not declare; undefined when the patch is fine. */
|
|
136
|
+
private undeclaredTopics;
|
|
102
137
|
/** Deploy a compiled bundle (BundleIR). */
|
|
103
138
|
deploy(bundle: unknown): Promise<DeployResult>;
|
|
104
139
|
private post;
|
|
140
|
+
private request;
|
|
105
141
|
}
|
|
106
|
-
export {};
|
|
142
|
+
export type { ChannelSubscriptions, ChannelSubscriptionsPatch, MessageOrigin, MessageSubscriptions, SubscriptionChannel, Subscriptions, SubscriptionsPatch };
|
|
107
143
|
//# sourceMappingURL=client.d.mts.map
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";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F,0BACE,mBACA,OAAO,mBAAmB,YAAY,MACrC,QAAQ,qBAAqB,YAAY;;UAOpC;;EAmBR,OAAO,kBAAkB,QAAQ;UAIzB;UAIM"}
|
package/dist/client.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SUBSCRIPTION_CHANNELS } from "./host/ingest.mjs";
|
|
1
2
|
// src/client.ts
|
|
2
3
|
var JourneyClientError = class extends Error {
|
|
3
4
|
path;
|
|
@@ -103,22 +104,85 @@ var JourneyClient = class {
|
|
|
103
104
|
removeDevice(token) {
|
|
104
105
|
return this.post("/devices/remove", { token });
|
|
105
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Where the user stands, topic × channel: for `email` and for `push`, `all` (false once they
|
|
109
|
+
* opted out of the whole channel) and each declared topic (false once they opted out of it on
|
|
110
|
+
* that channel) — the engine's record, which a preference page shows as it is. The two are
|
|
111
|
+
* independent flags: a topic answers its own opt-out even while `all` is false, so `all: false`
|
|
112
|
+
* masks every topic however they read (nothing is sent on the channel until it is true again).
|
|
113
|
+
* Rejects with a 410 for an erased user.
|
|
114
|
+
*/
|
|
115
|
+
getSubscriptions(userId) {
|
|
116
|
+
return this.request("GET", subscriptionsPath(userId));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Set subscriptions: only what the patch names changes, per channel (`{ email: { topics: {
|
|
120
|
+
* newsletter: false } } }` opts out of one topic's emails, `{ push: { all: false } }` of every
|
|
121
|
+
* push — the in-app opt-out App Store Review Guideline 4.5.4 asks for). `all: true` clears the
|
|
122
|
+
* channel-wide opt-out only: a topic opted out on its own stays off until the patch names it,
|
|
123
|
+
* so a preference page's "subscribe to all" sends `all: true` plus every topic `true`. Answers
|
|
124
|
+
* the subscriptions as they now stand. With a contract, a topic it does not declare is refused
|
|
125
|
+
* here, before the request; the engine refuses it too.
|
|
126
|
+
*/
|
|
127
|
+
setSubscriptions(userId, patch) {
|
|
128
|
+
const refused = this.undeclaredTopics(patch);
|
|
129
|
+
if (refused !== void 0) return Promise.reject(refused);
|
|
130
|
+
return this.request("PUT", subscriptionsPath(userId), patch);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* `getSubscriptions` for the recipient of one copy, by the message id an email's preferences
|
|
134
|
+
* link carries (`email.preferencesUrl?m=<message id>`): how a preference page works without a
|
|
135
|
+
* sign-in. The answer adds `message: { channel, topic }`, the copy the page was opened from,
|
|
136
|
+
* so it can highlight that topic. Rejects with a 404 for an id that names no copy — never
|
|
137
|
+
* sent, or erased with its user — and for a transactional one; the page should show the link
|
|
138
|
+
* as expired. The message id is the capability, so the app proxies this behind its own API
|
|
139
|
+
* and rate-limits it.
|
|
140
|
+
*/
|
|
141
|
+
getSubscriptionsByMessage(messageId) {
|
|
142
|
+
return this.request("GET", subscriptionsByMessagePath(messageId));
|
|
143
|
+
}
|
|
144
|
+
/** `setSubscriptions` for the recipient of one copy; the patch and the answer are those of `getSubscriptionsByMessage`. */
|
|
145
|
+
setSubscriptionsByMessage(messageId, patch) {
|
|
146
|
+
const refused = this.undeclaredTopics(patch);
|
|
147
|
+
if (refused !== void 0) return Promise.reject(refused);
|
|
148
|
+
return this.request("PUT", subscriptionsByMessagePath(messageId), patch);
|
|
149
|
+
}
|
|
150
|
+
/** With a contract, the refusal of a patch naming a topic it does not declare; undefined when the patch is fine. */
|
|
151
|
+
undeclaredTopics(patch) {
|
|
152
|
+
const contract = this.options.contract;
|
|
153
|
+
if (contract === void 0) return void 0;
|
|
154
|
+
const issues = [];
|
|
155
|
+
for (const channel of SUBSCRIPTION_CHANNELS) for (const topic of Object.keys(patch[channel]?.topics ?? {})) {
|
|
156
|
+
if (contract.topics.includes(topic)) continue;
|
|
157
|
+
issues.push({
|
|
158
|
+
path: `${channel}.topics.${topic}`,
|
|
159
|
+
message: "not a declared topic"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return issues.length > 0 ? new JourneyValidationError("/subscriptions", void 0, issues) : void 0;
|
|
163
|
+
}
|
|
106
164
|
/** Deploy a compiled bundle (BundleIR). */
|
|
107
165
|
deploy(bundle) {
|
|
108
166
|
return this.post("/deploy", bundle);
|
|
109
167
|
}
|
|
110
|
-
|
|
111
|
-
|
|
168
|
+
post(path, body) {
|
|
169
|
+
return this.request("POST", path, body);
|
|
170
|
+
}
|
|
171
|
+
async request(method, path, body) {
|
|
172
|
+
const headers = {};
|
|
173
|
+
if (body !== void 0) headers["content-type"] = "application/json";
|
|
112
174
|
if (this.options.token !== void 0) headers.authorization = `Bearer ${this.options.token}`;
|
|
113
175
|
const response = await (this.options.fetch ?? fetch)(`${this.options.origin.replace(/\/$/, "")}${path}`, {
|
|
114
|
-
method
|
|
176
|
+
method,
|
|
115
177
|
headers,
|
|
116
|
-
body: JSON.stringify(body)
|
|
178
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
117
179
|
});
|
|
118
180
|
if (!response.ok) throw new JourneyClientError(path, response.status, await response.text());
|
|
119
181
|
return await response.json();
|
|
120
182
|
}
|
|
121
183
|
};
|
|
184
|
+
const subscriptionsPath = (userId) => `/subscriptions/${encodeURIComponent(userId)}`;
|
|
185
|
+
const subscriptionsByMessagePath = (messageId) => `/subscriptions/by-message/${encodeURIComponent(messageId)}`;
|
|
122
186
|
export { JourneyClient, JourneyClientError, JourneyValidationError };
|
|
123
187
|
|
|
124
188
|
//# sourceMappingURL=client.mjs.map
|
package/dist/client.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type * as core from 'zod/v4/core';\nimport type { Contract, ContractIssue, ProfilePatch } from './contract';\nimport type { DeployResult, IdentifyResult, IngestResult } from './host/ingest';\nimport type { ProfileProps } from './store';\n\n/**\n * `@shware/workflow/client` — the producer side of the ingest API, for the\n * service that knows what users do (an api server, a webhook handler). Plain\n * fetch, no dependencies; errors carry the status and body so a caller can\n * log them without failing the request that triggered the report.\n */\n\nexport interface JourneyClientOptions<C extends Contract | undefined = undefined> {\n /**\n * The shared `defineContract(...)`: types `track` (the event name picks the\n * payload type) and `identify`, and checks both before anything is sent.\n */\n contract?: C;\n /** The journey Worker's origin, e.g. `https://workflow.example.com`. */\n origin: string;\n /** Its API_TOKEN, sent as a bearer; omit against an open local instance. */\n token?: string;\n /** Fetch implementation (defaults to the global one). */\n fetch?: typeof fetch;\n}\n\nexport class JourneyClientError extends Error {\n constructor(\n readonly path: string,\n readonly status: number,\n readonly body: string\n ) {\n super(`journey ${path} failed: ${status} ${body}`);\n this.name = 'JourneyClientError';\n }\n}\n\n/** A payload or profile patch the contract refuses — raised before the request, with the field paths. */\nexport class JourneyValidationError extends Error {\n constructor(\n readonly path: string,\n readonly event: string | undefined,\n readonly issues: ContractIssue[]\n ) {\n super(\n `journey ${path}${event === undefined ? '' : ` '${event}'`} refused by the contract: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n this.name = 'JourneyValidationError';\n }\n}\n\ntype EventsOf<C> = C extends Contract<infer E> ? E : never;\n/** Event names: the contract's, or any string without one. */\nexport type ClientEventName<C> = [C] extends [undefined] ? string : keyof EventsOf<C> & string;\ntype TrackArgs<C, K> = [C] extends [undefined]\n ? [payload?: Record<string, unknown>, options?: TrackOptions]\n : K extends keyof EventsOf<C>\n ? [payload: core.input<EventsOf<C>[K]>, options?: TrackOptions]\n : never;\ntype IdentifyProps<C> = [C] extends [undefined]\n ? ProfileProps\n : C extends Contract<Record<string, core.$ZodObject>, infer P>\n ? ProfilePatch<P>\n : never;\n\nexport interface TrackOptions {\n /** The occurrence's identity: a retry with the same id is recorded once. */\n id?: string;\n /** When it happened (epoch ms); the Worker's clock when omitted. */\n ts?: number;\n}\n\nexport class JourneyClient<C extends Contract | undefined = undefined> {\n constructor(private readonly options: JourneyClientOptions<C>) {}\n\n /** Merge profile properties (`null` clears one). Every property a journey reads must be identified before the event that starts it. */\n identify(userId: string, props: IdentifyProps<C>): Promise<IdentifyResult> {\n const contract = this.options.contract;\n if (contract !== undefined) {\n const result = contract.parseProfilePatch(props);\n if (!result.ok)\n return Promise.reject(new JourneyValidationError('/identify', undefined, result.issues));\n }\n return this.post<IdentifyResult>('/identify', { userId, props });\n }\n\n /**\n * Record an event; the Worker starts every journey whose trigger matches it\n * and wakes waits on it. A caller that retries should pass the same `id`\n * each time: the Worker stores one occurrence per id, so a retry after a\n * timeout cannot double-count the event. `ts` defaults to the Worker's clock.\n */\n track<K extends ClientEventName<C>>(\n userId: string,\n event: K,\n ...args: TrackArgs<C, K>\n ): Promise<IngestResult> {\n const [payload = {}, options = {}] = args as [Record<string, unknown>?, TrackOptions?];\n const contract = this.options.contract;\n if (contract !== undefined) {\n const result = contract.parseEvent(event, payload);\n if (!result.ok)\n return Promise.reject(new JourneyValidationError('/events', event, result.issues));\n }\n return this.post<IngestResult>('/events', {\n userId,\n event,\n payload,\n ...(options.id === undefined ? {} : { id: options.id }),\n ...(options.ts === undefined ? {} : { ts: options.ts }),\n });\n }\n\n /**\n * A push token the app registered for the user (call it on every registration: a token moves\n * to the latest user). The engine keeps devices itself — pushes go to them, a token APNs / FCM\n * reports as gone is dropped — and journeys waiting on `reachable('push')` wake.\n */\n registerDevice(\n userId: string,\n device: { token: string; platform: 'ios' | 'android' | 'web'; ts?: number }\n ): Promise<{ ok: true; woke: number }> {\n const { token, platform, ts } = device;\n return this.post('/devices', {\n userId,\n token,\n platform,\n ...(ts === undefined ? {} : { ts }),\n });\n }\n\n /**\n * A journey push tapped open: the `message_id` the push carried, reported for the user who\n * tapped it. Recorded as a human open on the copy (an email's opens are tracked by the Worker).\n */\n messageOpened(userId: string, messageId: string): Promise<{ ok: true; recorded: boolean }> {\n return this.post('/messages/opened', { userId, messageId });\n }\n\n /**\n * A deleted account: the engine records the erasure, stops the user's running journeys, then\n * erases everything it keeps about them (profile, devices, events, reporting). Once this\n * resolves the request is durable: `erased: false` means an instance would not stop yet, and\n * the Worker's scheduled sweep finishes the job.\n */\n forgetUser(userId: string): Promise<{ ok: true; erased: boolean; pending: string[] }> {\n return this.post('/users/forget', { userId });\n }\n\n /** The user signed out on that device: the token stays registered, bound to nobody. */\n unbindDevice(token: string): Promise<{ ok: true; woke: number }> {\n return this.post('/devices/unbind', { token });\n }\n\n /** Forget a push token for good (an uninstall the app learned of, a token it replaced). */\n removeDevice(token: string): Promise<{ ok: true; woke: number }> {\n return this.post('/devices/remove', { token });\n }\n\n /** Deploy a compiled bundle (BundleIR). */\n deploy(bundle: unknown): Promise<DeployResult> {\n return this.post<DeployResult>('/deploy', bundle);\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const headers: Record<string, string> = { 'content-type': 'application/json' };\n if (this.options.token !== undefined) headers.authorization = `Bearer ${this.options.token}`;\n const doFetch = this.options.fetch ?? fetch;\n const response = await doFetch(`${this.options.origin.replace(/\\/$/, '')}${path}`, {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n });\n if (!response.ok) throw new JourneyClientError(path, response.status, await response.text());\n return (await response.json()) as T;\n }\n}\n"],"mappings":";AA0BA,IAAa,qBAAb,cAAwC,MAAM;CAEjC;CACA;CACA;CAHX,YACE,MACA,QACA,MACA;EACA,MAAM,WAAW,KAAK,WAAW,OAAO,GAAG,MAAM;EAJxC,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,OAAA;EAGT,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAErC;CACA;CACA;CAHX,YACE,MACA,OACA,QACA;EACA,MACE,WAAW,OAAO,UAAU,KAAA,IAAY,KAAK,KAAK,MAAM,GAAG,4BAA4B,OACpF,KAAK,MAAM,GAAG,EAAE,QAAQ,SAAS,GAAG,EAAE,SAAS,CAAC,CAChD,KAAK,IAAI,GACd;EARS,KAAA,OAAA;EACA,KAAA,QAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACd;AACF;AAuBA,IAAa,gBAAb,MAAuE;CACxC;CAA7B,YAAY,SAAmD;EAAlC,KAAA,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AmB,EAAE,MAAM,CAAC;CAC/C;;CAGA,aAAa,OAAoD;EAC/D,OAAO,KAAK,KAAK,mBAAmB,EAAE,MAAM,CAAC;CAC/C;;CAGA,OAAO,QAAwC;EAC7C,OAAO,KAAK,KAAmB,WAAW,MAAM;CAClD;CAEA,MAAc,KAAQ,MAAc,MAA2B;EAC7D,MAAM,UAAkC,EAAE,gBAAgB,mBAAmB;EAC7E,IAAI,KAAK,QAAQ,UAAU,KAAA,GAAW,QAAQ,gBAAgB,UAAU,KAAK,QAAQ;EAErF,MAAM,WAAW,OADD,KAAK,QAAQ,SAAS,MAAA,CACP,GAAG,KAAK,QAAQ,OAAO,QAAQ,OAAO,EAAE,IAAI,QAAQ;GACjF,QAAQ;GACR;GACA,MAAM,KAAK,UAAU,IAAI;EAC3B,CAAC;EACD,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,mBAAmB,MAAM,SAAS,QAAQ,MAAM,SAAS,KAAK,CAAC;EAC3F,OAAQ,MAAM,SAAS,KAAK;CAC9B;AACF"}
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type * as core from 'zod/v4/core';\nimport type { Contract, ContractIssue, ProfilePatch, Topic } from './contract';\nimport {\n type DeployResult,\n type IdentifyResult,\n type IngestResult,\n type MessageSubscriptions,\n SUBSCRIPTION_CHANNELS,\n type Subscriptions,\n type SubscriptionsPatch,\n} from './host/ingest';\nimport type { ProfileProps } from './store';\n\n/**\n * `@shware/workflow/client` — the producer side of the ingest API, for the\n * service that knows what users do (an api server, a webhook handler). Plain\n * fetch, no dependencies; errors carry the status and body so a caller can\n * log them without failing the request that triggered the report.\n */\n\nexport interface JourneyClientOptions<C extends Contract | undefined = undefined> {\n /**\n * The shared `defineContract(...)`: types `track` (the event name picks the\n * payload type) and `identify`, and checks both before anything is sent.\n */\n contract?: C;\n /** The journey Worker's origin, e.g. `https://workflow.example.com`. */\n origin: string;\n /** Its API_TOKEN, sent as a bearer; omit against an open local instance. */\n token?: string;\n /** Fetch implementation (defaults to the global one). */\n fetch?: typeof fetch;\n}\n\nexport class JourneyClientError extends Error {\n constructor(\n readonly path: string,\n readonly status: number,\n readonly body: string\n ) {\n super(`journey ${path} failed: ${status} ${body}`);\n this.name = 'JourneyClientError';\n }\n}\n\n/** A payload or profile patch the contract refuses — raised before the request, with the field paths. */\nexport class JourneyValidationError extends Error {\n constructor(\n readonly path: string,\n readonly event: string | undefined,\n readonly issues: ContractIssue[]\n ) {\n super(\n `journey ${path}${event === undefined ? '' : ` '${event}'`} refused by the contract: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n this.name = 'JourneyValidationError';\n }\n}\n\ntype EventsOf<C> = C extends Contract<infer E> ? E : never;\n/** Event names: the contract's, or any string without one. */\nexport type ClientEventName<C> = [C] extends [undefined] ? string : keyof EventsOf<C> & string;\ntype TrackArgs<C, K> = [C] extends [undefined]\n ? [payload?: Record<string, unknown>, options?: TrackOptions]\n : K extends keyof EventsOf<C>\n ? [payload: core.input<EventsOf<C>[K]>, options?: TrackOptions]\n : never;\ntype IdentifyProps<C> = [C] extends [undefined]\n ? ProfileProps\n : C extends Contract<Record<string, core.$ZodObject>, infer P>\n ? ProfilePatch<P>\n : never;\n\n/** The topics the client's contract declares; any string without a contract. */\nexport type ClientTopic<C> = [C] extends [undefined] ? string : Topic<C>;\n\nexport type {\n ChannelSubscriptions,\n ChannelSubscriptionsPatch,\n MessageOrigin,\n MessageSubscriptions,\n SubscriptionChannel,\n Subscriptions,\n SubscriptionsPatch,\n} from './host/ingest';\n\nexport interface TrackOptions {\n /** The occurrence's identity: a retry with the same id is recorded once. */\n id?: string;\n /** When it happened (epoch ms); the Worker's clock when omitted. */\n ts?: number;\n}\n\nexport class JourneyClient<C extends Contract | undefined = undefined> {\n constructor(private readonly options: JourneyClientOptions<C>) {}\n\n /** Merge profile properties (`null` clears one). Every property a journey reads must be identified before the event that starts it. */\n identify(userId: string, props: IdentifyProps<C>): Promise<IdentifyResult> {\n const contract = this.options.contract;\n if (contract !== undefined) {\n const result = contract.parseProfilePatch(props);\n if (!result.ok)\n return Promise.reject(new JourneyValidationError('/identify', undefined, result.issues));\n }\n return this.post<IdentifyResult>('/identify', { userId, props });\n }\n\n /**\n * Record an event; the Worker starts every journey whose trigger matches it\n * and wakes waits on it. A caller that retries should pass the same `id`\n * each time: the Worker stores one occurrence per id, so a retry after a\n * timeout cannot double-count the event. `ts` defaults to the Worker's clock.\n */\n track<K extends ClientEventName<C>>(\n userId: string,\n event: K,\n ...args: TrackArgs<C, K>\n ): Promise<IngestResult> {\n const [payload = {}, options = {}] = args as [Record<string, unknown>?, TrackOptions?];\n const contract = this.options.contract;\n if (contract !== undefined) {\n const result = contract.parseEvent(event, payload);\n if (!result.ok)\n return Promise.reject(new JourneyValidationError('/events', event, result.issues));\n }\n return this.post<IngestResult>('/events', {\n userId,\n event,\n payload,\n ...(options.id === undefined ? {} : { id: options.id }),\n ...(options.ts === undefined ? {} : { ts: options.ts }),\n });\n }\n\n /**\n * A push token the app registered for the user (call it on every registration: a token moves\n * to the latest user). The engine keeps devices itself — pushes go to them, a token APNs / FCM\n * reports as gone is dropped — and journeys waiting on `reachable('push')` wake.\n */\n registerDevice(\n userId: string,\n device: { token: string; platform: 'ios' | 'android' | 'web'; ts?: number }\n ): Promise<{ ok: true; woke: number }> {\n const { token, platform, ts } = device;\n return this.post('/devices', {\n userId,\n token,\n platform,\n ...(ts === undefined ? {} : { ts }),\n });\n }\n\n /**\n * A journey push tapped open: the `message_id` the push carried, reported for the user who\n * tapped it. Recorded as a human open on the copy (an email's opens are tracked by the Worker).\n */\n messageOpened(userId: string, messageId: string): Promise<{ ok: true; recorded: boolean }> {\n return this.post('/messages/opened', { userId, messageId });\n }\n\n /**\n * A deleted account: the engine records the erasure, stops the user's running journeys, then\n * erases everything it keeps about them (profile, devices, events, reporting). Once this\n * resolves the request is durable: `erased: false` means an instance would not stop yet, and\n * the Worker's scheduled sweep finishes the job.\n */\n forgetUser(userId: string): Promise<{ ok: true; erased: boolean; pending: string[] }> {\n return this.post('/users/forget', { userId });\n }\n\n /** The user signed out on that device: the token stays registered, bound to nobody. */\n unbindDevice(token: string): Promise<{ ok: true; woke: number }> {\n return this.post('/devices/unbind', { token });\n }\n\n /** Forget a push token for good (an uninstall the app learned of, a token it replaced). */\n removeDevice(token: string): Promise<{ ok: true; woke: number }> {\n return this.post('/devices/remove', { token });\n }\n\n /**\n * Where the user stands, topic × channel: for `email` and for `push`, `all` (false once they\n * opted out of the whole channel) and each declared topic (false once they opted out of it on\n * that channel) — the engine's record, which a preference page shows as it is. The two are\n * independent flags: a topic answers its own opt-out even while `all` is false, so `all: false`\n * masks every topic however they read (nothing is sent on the channel until it is true again).\n * Rejects with a 410 for an erased user.\n */\n getSubscriptions(userId: string): Promise<Subscriptions<ClientTopic<C>>> {\n return this.request('GET', subscriptionsPath(userId));\n }\n\n /**\n * Set subscriptions: only what the patch names changes, per channel (`{ email: { topics: {\n * newsletter: false } } }` opts out of one topic's emails, `{ push: { all: false } }` of every\n * push — the in-app opt-out App Store Review Guideline 4.5.4 asks for). `all: true` clears the\n * channel-wide opt-out only: a topic opted out on its own stays off until the patch names it,\n * so a preference page's \"subscribe to all\" sends `all: true` plus every topic `true`. Answers\n * the subscriptions as they now stand. With a contract, a topic it does not declare is refused\n * here, before the request; the engine refuses it too.\n */\n setSubscriptions(\n userId: string,\n patch: SubscriptionsPatch<ClientTopic<C>>\n ): Promise<Subscriptions<ClientTopic<C>>> {\n const refused = this.undeclaredTopics(patch);\n if (refused !== undefined) return Promise.reject(refused);\n return this.request('PUT', subscriptionsPath(userId), patch);\n }\n\n /**\n * `getSubscriptions` for the recipient of one copy, by the message id an email's preferences\n * link carries (`email.preferencesUrl?m=<message id>`): how a preference page works without a\n * sign-in. The answer adds `message: { channel, topic }`, the copy the page was opened from,\n * so it can highlight that topic. Rejects with a 404 for an id that names no copy — never\n * sent, or erased with its user — and for a transactional one; the page should show the link\n * as expired. The message id is the capability, so the app proxies this behind its own API\n * and rate-limits it.\n */\n getSubscriptionsByMessage(messageId: string): Promise<MessageSubscriptions<ClientTopic<C>>> {\n return this.request('GET', subscriptionsByMessagePath(messageId));\n }\n\n /** `setSubscriptions` for the recipient of one copy; the patch and the answer are those of `getSubscriptionsByMessage`. */\n setSubscriptionsByMessage(\n messageId: string,\n patch: SubscriptionsPatch<ClientTopic<C>>\n ): Promise<MessageSubscriptions<ClientTopic<C>>> {\n const refused = this.undeclaredTopics(patch);\n if (refused !== undefined) return Promise.reject(refused);\n return this.request('PUT', subscriptionsByMessagePath(messageId), patch);\n }\n\n /** With a contract, the refusal of a patch naming a topic it does not declare; undefined when the patch is fine. */\n private undeclaredTopics(\n patch: SubscriptionsPatch<ClientTopic<C>>\n ): JourneyValidationError | undefined {\n const contract = this.options.contract;\n if (contract === undefined) return undefined;\n const issues: ContractIssue[] = [];\n for (const channel of SUBSCRIPTION_CHANNELS) {\n for (const topic of Object.keys(patch[channel]?.topics ?? {})) {\n // `includes`, not the predicate: narrowing `string` by a `topic is string` leaves `never`\n if (contract.topics.includes(topic)) continue;\n issues.push({ path: `${channel}.topics.${topic}`, message: 'not a declared topic' });\n }\n }\n return issues.length > 0\n ? new JourneyValidationError('/subscriptions', undefined, issues)\n : undefined;\n }\n\n /** Deploy a compiled bundle (BundleIR). */\n deploy(bundle: unknown): Promise<DeployResult> {\n return this.post<DeployResult>('/deploy', bundle);\n }\n\n private post<T>(path: string, body: unknown): Promise<T> {\n return this.request<T>('POST', path, body);\n }\n\n private async request<T>(\n method: 'GET' | 'POST' | 'PUT',\n path: string,\n body?: unknown\n ): Promise<T> {\n const headers: Record<string, string> = {};\n if (body !== undefined) headers['content-type'] = 'application/json';\n if (this.options.token !== undefined) headers.authorization = `Bearer ${this.options.token}`;\n const doFetch = this.options.fetch ?? fetch;\n const response = await doFetch(`${this.options.origin.replace(/\\/$/, '')}${path}`, {\n method,\n headers,\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n });\n if (!response.ok) throw new JourneyClientError(path, response.status, await response.text());\n return (await response.json()) as T;\n }\n}\n\nconst subscriptionsPath = (userId: string) => `/subscriptions/${encodeURIComponent(userId)}`;\nconst subscriptionsByMessagePath = (messageId: string) =>\n `/subscriptions/by-message/${encodeURIComponent(messageId)}`;\n"],"mappings":";;AAkCA,IAAa,qBAAb,cAAwC,MAAM;CAEjC;CACA;CACA;CAHX,YACE,MACA,QACA,MACA;EACA,MAAM,WAAW,KAAK,WAAW,OAAO,GAAG,MAAM;EAJxC,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,OAAA;EAGT,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,yBAAb,cAA4C,MAAM;CAErC;CACA;CACA;CAHX,YACE,MACA,OACA,QACA;EACA,MACE,WAAW,OAAO,UAAU,KAAA,IAAY,KAAK,KAAK,MAAM,GAAG,4BAA4B,OACpF,KAAK,MAAM,GAAG,EAAE,QAAQ,SAAS,GAAG,EAAE,SAAS,CAAC,CAChD,KAAK,IAAI,GACd;EARS,KAAA,OAAA;EACA,KAAA,QAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACd;AACF;AAoCA,IAAa,gBAAb,MAAuE;CACxC;CAA7B,YAAY,SAAmD;EAAlC,KAAA,UAAA;CAAmC;;CAGhE,SAAS,QAAgB,OAAkD;EACzE,MAAM,WAAW,KAAK,QAAQ;EAC9B,IAAI,aAAa,KAAA,GAAW;GAC1B,MAAM,SAAS,SAAS,kBAAkB,KAAK;GAC/C,IAAI,CAAC,OAAO,IACV,OAAO,QAAQ,OAAO,IAAI,uBAAuB,aAAa,KAAA,GAAW,OAAO,MAAM,CAAC;EAC3F;EACA,OAAO,KAAK,KAAqB,aAAa;GAAE;GAAQ;EAAM,CAAC;CACjE;;;;;;;CAQA,MACE,QACA,OACA,GAAG,MACoB;EACvB,MAAM,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,KAAK;EACrC,MAAM,WAAW,KAAK,QAA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AI,MAAM,IAAI,mBAAmB,MAAM,SAAS,QAAQ,MAAM,SAAS,KAAK,CAAC;EAC3F,OAAQ,MAAM,SAAS,KAAK;CAC9B;AACF;AAEA,MAAM,qBAAqB,WAAmB,kBAAkB,mBAAmB,MAAM;AACzF,MAAM,8BAA8B,cAClC,6BAA6B,mBAAmB,SAAS"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_reporting_classify = require("../reporting/classify.cjs");
|
|
3
|
+
const require_reporting_tracking = require("../reporting/tracking.cjs");
|
|
4
|
+
const require_store_facts = require("../store/facts.cjs");
|
|
3
5
|
const require_store_erasure = require("../store/erasure.cjs");
|
|
4
6
|
const require_store_postgres_reporting = require("../store/postgres-reporting.cjs");
|
|
5
7
|
const require_store_postgres = require("../store/postgres.cjs");
|
|
6
|
-
const require_store_facts = require("../store/facts.cjs");
|
|
7
8
|
const require_store_index = require("../store/index.cjs");
|
|
8
9
|
const require_host_platform = require("../host/platform.cjs");
|
|
9
10
|
const require_host_ingest = require("../host/ingest.cjs");
|
|
11
|
+
const require_email_sender = require("../email-sender.cjs");
|
|
10
12
|
const require_reporting_observer = require("../reporting/observer.cjs");
|
|
11
13
|
const require_host_senders = require("../host/senders.cjs");
|
|
12
14
|
const require_host_channels = require("../host/channels.cjs");
|
|
13
|
-
const require_reporting_classify = require("../reporting/classify.cjs");
|
|
14
|
-
const require_reporting_tracking = require("../reporting/tracking.cjs");
|
|
15
15
|
const require_host_auth = require("../host/auth.cjs");
|
|
16
16
|
const require_host_http = require("../host/http.cjs");
|
|
17
17
|
const require_host_journey_host = require("../host/journey-host.cjs");
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BURST_WINDOW_MS, DEFAULT_QUICK_MS, classifyClick, classifyOpen } from "../reporting/classify.mjs";
|
|
2
|
+
import { handleTracking, recordPushOpen } from "../reporting/tracking.mjs";
|
|
3
|
+
import { JourneyFactSource } from "../store/facts.mjs";
|
|
2
4
|
import { UserErasedError } from "../store/erasure.mjs";
|
|
3
5
|
import { PostgresReporting } from "../store/postgres-reporting.mjs";
|
|
4
6
|
import { PostgresJourneyStore } from "../store/postgres.mjs";
|
|
5
|
-
import { JourneyFactSource } from "../store/facts.mjs";
|
|
6
7
|
import { SchemaMismatchError } from "../store/index.mjs";
|
|
7
8
|
import { InstanceNotFoundError, WAKE_EVENT_TYPE } from "../host/platform.mjs";
|
|
8
9
|
import { BundleIntegrityError, SWEEP_PAGE_SIZE, deployBundle, forgetUser, identifyUser, ingestEvent, registerDevice, removeDevice, sweepMaintenance, sweepSegments, sweepSegmentsPaged, unbindDevice } from "../host/ingest.mjs";
|
|
10
|
+
import { EmailSender, trackEmail } from "../email-sender.mjs";
|
|
9
11
|
import { reportingObserver } from "../reporting/observer.mjs";
|
|
10
12
|
import { LogMessageSender, WebhookMessageSender, routeByChannel, routeByPlatform } from "../host/senders.mjs";
|
|
11
13
|
import { channelsFromConfig, journeyMode, runtimeFromConfig } from "../host/channels.mjs";
|
|
12
|
-
import { BURST_WINDOW_MS, DEFAULT_QUICK_MS, classifyClick, classifyOpen } from "../reporting/classify.mjs";
|
|
13
|
-
import { handleTracking, recordPushOpen } from "../reporting/tracking.mjs";
|
|
14
14
|
import { authorized, bearerMatches, timingSafeEqual } from "../host/auth.mjs";
|
|
15
15
|
import { handleRequest } from "../host/http.mjs";
|
|
16
16
|
import { EnvValidationError } from "../host/journey-host.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_engine_retry = require("../engine/retry.cjs");
|
|
3
|
-
const require_runtime = require("../runtime.cjs");
|
|
4
3
|
const require_host_platform = require("../host/platform.cjs");
|
|
4
|
+
const require_runtime = require("../runtime.cjs");
|
|
5
5
|
const require_host_execute = require("../host/execute.cjs");
|
|
6
6
|
const require_engine_actions = require("../engine/actions.cjs");
|
|
7
7
|
const require_host_senders = require("../host/senders.cjs");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ActionInvoker, JourneyObserver, JourneyOutcome, MessageSender, MessageValidator } from "../engine/ports.cjs";
|
|
2
2
|
import { RegisteredAction } from "../engine/actions.cjs";
|
|
3
|
-
import { JourneyStore } from "../store/index.cjs";
|
|
4
3
|
import { Contract } from "../contract.cjs";
|
|
4
|
+
import { JourneyStore } from "../store/index.cjs";
|
|
5
5
|
import { JourneyRuntimeOptions } from "../runtime.cjs";
|
|
6
6
|
import { JourneyEnv, JourneyParams } from "../host/platform.cjs";
|
|
7
7
|
import { JourneyRunParts } from "../host/execute.cjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ActionInvoker, JourneyObserver, JourneyOutcome, MessageSender, MessageValidator } from "../engine/ports.mjs";
|
|
2
2
|
import { RegisteredAction } from "../engine/actions.mjs";
|
|
3
|
-
import { JourneyStore } from "../store/index.mjs";
|
|
4
3
|
import { Contract } from "../contract.mjs";
|
|
4
|
+
import { JourneyStore } from "../store/index.mjs";
|
|
5
5
|
import { JourneyRuntimeOptions } from "../runtime.mjs";
|
|
6
6
|
import { JourneyEnv, JourneyParams } from "../host/platform.mjs";
|
|
7
7
|
import { JourneyRunParts } from "../host/execute.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isRetryable } from "../engine/retry.mjs";
|
|
2
|
-
import { resolveRuntime } from "../runtime.mjs";
|
|
3
2
|
import { WAKE_EVENT_TYPE } from "../host/platform.mjs";
|
|
3
|
+
import { resolveRuntime } from "../runtime.mjs";
|
|
4
4
|
import { executeJourney } from "../host/execute.mjs";
|
|
5
5
|
import { RegistryActionInvoker } from "../engine/actions.mjs";
|
|
6
6
|
import { LogMessageSender, WebhookMessageSender } from "../host/senders.mjs";
|
package/dist/config.cjs
CHANGED
|
@@ -31,7 +31,9 @@ var ConfigCompileError = class extends Error {
|
|
|
31
31
|
* by id, not a hand-kept list). The registry is checked first, used or not:
|
|
32
32
|
* every entry is a template of its channel with an id, an id is registered
|
|
33
33
|
* once per channel, and every email template's metadata is valid, as is the
|
|
34
|
-
* config's `email` (which replaced `emails`: a config still carrying it fails)
|
|
34
|
+
* config's `email` (which replaced `emails`: a config still carrying it fails),
|
|
35
|
+
* and every email and push template's `topic` is one the contract declares (a
|
|
36
|
+
* template with a topic under a config whose contract declares none fails too).
|
|
35
37
|
* Then every message node is checked against it — an
|
|
36
38
|
* unregistered or cross-channel template fails with the workflow, node and
|
|
37
39
|
* channel named, and so does a literal prop the template's schema refuses (a
|
|
@@ -45,10 +47,15 @@ function compileConfig(config) {
|
|
|
45
47
|
let index;
|
|
46
48
|
try {
|
|
47
49
|
const email = require_templates.indexTemplates("email", config.templates?.email);
|
|
50
|
+
const push = require_templates.indexTemplates("push", config.templates?.push);
|
|
48
51
|
require_email.assertEmailConfig(config, email.values());
|
|
52
|
+
for (const template of push.values()) require_email.assertTemplateTopic(template, `push template '${template.id}'`, "push", true);
|
|
53
|
+
const declared = config.contract?.topics ?? [];
|
|
54
|
+
assertTopicsDeclared("email", email.values(), declared);
|
|
55
|
+
assertTopicsDeclared("push", push.values(), declared);
|
|
49
56
|
index = {
|
|
50
57
|
email,
|
|
51
|
-
push
|
|
58
|
+
push,
|
|
52
59
|
discord: require_templates.indexTemplates("discord", config.templates?.discord),
|
|
53
60
|
slack: require_templates.indexTemplates("slack", config.templates?.slack)
|
|
54
61
|
};
|
|
@@ -59,7 +66,8 @@ function compileConfig(config) {
|
|
|
59
66
|
workflows: config.workflows,
|
|
60
67
|
...config.segments === void 0 ? {} : { segments: config.segments },
|
|
61
68
|
...config.actions === void 0 ? {} : { actions: config.actions },
|
|
62
|
-
templates: TEMPLATE_CHANNELS.flatMap((channel) => [...index[channel].values()])
|
|
69
|
+
templates: TEMPLATE_CHANNELS.flatMap((channel) => [...index[channel].values()]),
|
|
70
|
+
subscriptions: { topics: config.contract?.topics ?? [] }
|
|
63
71
|
});
|
|
64
72
|
bundle.workflows.forEach((workflow, i) => {
|
|
65
73
|
checkMessages(workflow, workflow.flow, index, config);
|
|
@@ -73,6 +81,19 @@ const TEMPLATE_CHANNELS = [
|
|
|
73
81
|
"discord",
|
|
74
82
|
"slack"
|
|
75
83
|
];
|
|
84
|
+
/**
|
|
85
|
+
* Every topic template names a topic the contract declares: the engine checks opt-outs by topic,
|
|
86
|
+
* so one the producer cannot set (`JourneyClient.setSubscriptions`) would be a topic nobody
|
|
87
|
+
* can opt out of through the app.
|
|
88
|
+
*/
|
|
89
|
+
function assertTopicsDeclared(channel, templates, declared) {
|
|
90
|
+
const known = new Set(declared);
|
|
91
|
+
for (const template of templates) {
|
|
92
|
+
if (template.topic === null || known.has(template.topic)) continue;
|
|
93
|
+
const list = declared.length === 0 ? "the contract declares no topics (defineContract({ subscriptions: { topics: [...] } }))" : `the contract declares ${declared.map((topic) => `'${topic}'`).join(", ")}`;
|
|
94
|
+
throw new TypeError(`${channel} template '${template.id}': topic '${template.topic}' is not declared — ${list}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
76
97
|
/** The channel's templates by id; undefined for a channel templates cannot be declared for. */
|
|
77
98
|
function indexOf(index, channel) {
|
|
78
99
|
return TEMPLATE_CHANNELS.includes(channel) ? index[channel] : void 0;
|
package/dist/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","names":["indexTemplates","compileBundle","templateUses","CHANNEL_OF","z"],"sources":["../src/config.ts"],"sourcesContent":["import * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport type { Contract } from './contract';\nimport { type ActionRef, type SegmentRef, type WorkflowBuilder, compileBundle } from './dsl';\nimport { templateUses } from './dsl/flow';\nimport { type EmailConfig, assertEmailConfig } from './email';\nimport type { BundleIR, ChannelIR, NodeIR, WorkflowIR } from './ir';\nimport type { JourneyMode, JourneyRuntimeConfig } from './runtime';\nimport {\n type AnyTemplate,\n CHANNEL_OF,\n type TemplateChannel,\n type TemplateRegistry,\n indexTemplates,\n} from './templates';\n\n/**\n * `workflow.config.ts` — the project's journey configuration, typed, flat and\n * committed with the code: what it deploys (workflows, segments, actions),\n * the template registries behind them, the contract every inbound event is\n * checked against, what the email templates share, and how the engine runs per\n * environment (time scale, APNs, FCM). The compiler (`compileConfig`), the\n * Worker (`journeyWorker({ config })`) and the Workflow Studio all read this\n * one object, so everything is registered exactly once:\n *\n * export default defineConfig({\n * title: 'Workflow Studio · Acme',\n * contract,\n * workflows, // [onboarding, notificationTest]\n * templates, // { email, push }: the definitions the workflows send\n * email: { unsubscribeUrl: 'https://acme.test/unsubscribe' },\n * runtime: { development: { timeScale: 600, logMessages: true } },\n * apns: { topic: 'io.acme.app', keyId: 'ABC123DEFG', teamId: 'TEAM123456' },\n * });\n *\n * Secrets are the one thing that stay out: a `.p8`, a service account, the\n * ingest bearer. The host reads them from its environment under fixed names\n * (see `JourneyEnv`), so the config says *which* key without carrying it. The\n * config is a source object (schemas, components, functions); only its\n * compiled bundle and preview-safe template data may cross to a browser.\n */\n\n/** Token-based APNs, the `.p8` auth key; the key itself is `APNS_PRIVATE_KEY_BASE64` in the environment. */\nexport interface ApnsConfig {\n /** The app's bundle id (`apns-topic`). */\n topic: string;\n /** The key's 10-character id. */\n keyId: string;\n /** The Apple Developer team id. */\n teamId: string;\n /**\n * Which APNs host each mode's device tokens belong to: `sandbox` for builds\n * signed with `aps-environment: development` (Xcode, the simulator),\n * `production` for App Store and TestFlight builds. Unlisted modes default\n * to `production` for the production mode and `sandbox` for every other.\n */\n environment?: Partial<Record<JourneyMode, 'sandbox' | 'production'>>;\n}\n\n/**\n * Standard Web Push for browsers (VAPID); the key pair is `VAPID_PUBLIC_KEY` /\n * `VAPID_PRIVATE_KEY` in the environment, and the site subscribes with the same public key.\n */\nexport interface WebPushConfig {\n /** Who push services may contact about this sender: `mailto:` or an `https:` URL. */\n subject: string;\n /**\n * The contract event a notification tap the browser reports (`opened_url`) is also recorded\n * as, with `{ message_id }`: the app reports its own taps as an event, and a service worker has\n * no session to do so — without this, browser opens reach the reports but not the conditions\n * (a `performed(e.push_opened)` segment). One event per copy, however often it is tapped.\n */\n openedEvent?: string;\n}\n\n/** FCM HTTP v1 for Android; the service account is `GOOGLE_APPLICATION_CREDENTIALS_BASE64` in the environment. */\nexport interface FcmConfig {\n /** Android notification channel the pushes land in (`android.notification.channel_id`). */\n androidChannelId?: string;\n}\n\n/**\n * The engine's tables live in a Postgres schema of their own, so their short names (`event`,\n * `profile`, `message`, …) never meet the app's. `workflow-ui generate` writes them as one drizzle\n * file on this schema; the host migrates it with its own tooling.\n */\nexport interface DatabaseConfig {\n /** The Postgres schema; `workflow` by default. */\n schema?: string;\n}\n\nexport interface JourneyConfigDefinition {\n /** Studio title (the browser tab names the project). */\n title?: string;\n /** The shared `defineContract(...)` the Worker validates ingest against. */\n contract?: Contract;\n workflows: readonly WorkflowBuilder[];\n segments?: readonly SegmentRef[];\n actions?: readonly ActionRef[];\n /** The template definitions, per channel; each is identified by its own `id`. */\n templates?: TemplateRegistry;\n /** What every email template shares: the default unsubscribe link, how opens and clicks are judged. */\n email?: EmailConfig;\n /** How the engine behaves per mode (`development`, `production`, …): time scale, message logging. */\n runtime?: JourneyRuntimeConfig;\n apns?: ApnsConfig;\n fcm?: FcmConfig;\n webPush?: WebPushConfig;\n /** The schema the store keeps the engine's tables in. */\n database?: DatabaseConfig;\n}\n\nexport interface JourneyConfig extends JourneyConfigDefinition {\n readonly kind: 'journey-config';\n}\n\nexport function defineConfig(definition: JourneyConfigDefinition): JourneyConfig {\n return { kind: 'journey-config', ...definition };\n}\n\nexport function isConfig(value: unknown): value is JourneyConfig {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'journey-config'\n );\n}\n\n/** The APNs environment for `mode`: the configured one, else production only for production. */\nexport function apnsEnvironment(config: ApnsConfig, mode: JourneyMode): 'sandbox' | 'production' {\n return config.environment?.[mode] ?? (mode === 'production' ? 'production' : 'sandbox');\n}\n\n/** A message node the config's registries cannot serve, or whose literal props its template refuses. */\nexport class ConfigCompileError extends Error {\n override readonly name = 'ConfigCompileError';\n}\n\n/**\n * Compile the config: the bundle `compileBundle` would produce, with the\n * template manifest generated from the registry (every registered template,\n * by id, not a hand-kept list). The registry is checked first, used or not:\n * every entry is a template of its channel with an id, an id is registered\n * once per channel, and every email template's metadata is valid, as is the\n * config's `email` (which replaced `emails`: a config still carrying it fails).\n * Then every message node is checked against it — an\n * unregistered or cross-channel template fails with the workflow, node and\n * channel named, and so does a literal prop the template's schema refuses (a\n * missing required prop, an undeclared one, a wrong literal) — and every\n * definition a workflow sends must be the very object registered under its id,\n * not merely one with the same id. User-property references cannot be parsed\n * here (their values exist only at send time) — they are checked by name only,\n * and parsed before sending.\n */\nexport function compileConfig(config: JourneyConfig): BundleIR {\n let index: RegistryIndex;\n try {\n const email = indexTemplates('email', config.templates?.email);\n assertEmailConfig(config, email.values());\n index = {\n email,\n push: indexTemplates('push', config.templates?.push),\n discord: indexTemplates('discord', config.templates?.discord),\n slack: indexTemplates('slack', config.templates?.slack),\n };\n } catch (error) {\n throw new ConfigCompileError((error as Error).message);\n }\n const bundle = compileBundle({\n workflows: config.workflows,\n ...(config.segments === undefined ? {} : { segments: config.segments }),\n ...(config.actions === undefined ? {} : { actions: config.actions }),\n templates: TEMPLATE_CHANNELS.flatMap((channel) => [...index[channel].values()]),\n });\n bundle.workflows.forEach((workflow, i) => {\n checkMessages(workflow, workflow.flow, index, config);\n checkUses(workflow, config.workflows[i], index, config);\n });\n return bundle;\n}\n\nconst TEMPLATE_CHANNELS = ['email', 'push', 'discord', 'slack'] as const;\n\n/** The registry by id, per channel. */\ntype RegistryIndex = Record<TemplateChannel, ReadonlyMap<string, AnyTemplate>>;\n\n/** The channel's templates by id; undefined for a channel templates cannot be declared for. */\nfunction indexOf(\n index: RegistryIndex,\n channel: ChannelIR\n): ReadonlyMap<string, AnyTemplate> | undefined {\n return (TEMPLATE_CHANNELS as readonly ChannelIR[]).includes(channel)\n ? index[channel as TemplateChannel]\n : undefined;\n}\n\n/**\n * The definitions a workflow sends against the registered ones: same id is not enough — a\n * workflow typed by one definition and a registry holding another under that id would render\n * with a schema the call was never checked against.\n */\nfunction checkUses(\n workflow: WorkflowIR,\n builder: WorkflowBuilder,\n index: RegistryIndex,\n config: JourneyConfig\n): void {\n for (const { template, loc } of templateUses(builder)) {\n const channel = CHANNEL_OF[template.kind];\n const registered = index[channel].get(template.id);\n if (registered === template) continue;\n const at = loc === undefined ? '' : ` (${loc.file}:${loc.line})`;\n const where = `workflow '${workflow.id}'${at}: ${channel} template '${template.id}'`;\n if (registered === undefined) throw new ConfigCompileError(`${where} is not registered`);\n const name = Object.entries(config.templates?.[channel] ?? {}).find(\n ([, entry]) => entry === registered\n )?.[0];\n throw new ConfigCompileError(\n `${where} is not the definition registered under that id (templates.${channel}.${name}) — two definitions share the id`\n );\n }\n}\n\n/** A field that may be left out: optional, or with a default the schema fills in. */\nfunction canBeOmitted(schema: core.$ZodType): boolean {\n const type = schema._zod.def.type;\n return type === 'optional' || type === 'default' || type === 'prefault';\n}\n\nfunction checkMessages(\n workflow: WorkflowIR,\n nodes: readonly NodeIR[],\n index: RegistryIndex,\n config: JourneyConfig\n): void {\n for (const node of nodes) {\n switch (node.type) {\n case 'message':\n checkMessage(workflow, node, index, config);\n break;\n case 'send_event':\n checkEmit(workflow, node, config);\n break;\n case 'branch':\n for (const c of node.cases) checkMessages(workflow, c.flow, index, config);\n if (node.otherwise) checkMessages(workflow, node.otherwise, index, config);\n break;\n case 'cohort':\n for (const arm of node.arms) checkMessages(workflow, arm.flow, index, config);\n break;\n case 'wait_until':\n if (Array.isArray(node.onTimeout)) checkMessages(workflow, node.onTimeout, index, config);\n break;\n default:\n break;\n }\n }\n}\n\nfunction checkMessage(\n workflow: WorkflowIR,\n node: Extract<NodeIR, { type: 'message' }>,\n index: RegistryIndex,\n config: JourneyConfig\n): void {\n const where = `workflow '${workflow.id}' node ${node.id}`;\n const registry = indexOf(index, node.channel);\n // Channels without template definitions (sms, …) are rendered by app-supplied senders\n if (registry === undefined) return;\n const entry = registry.get(node.template);\n if (entry === undefined) {\n const other = TEMPLATE_CHANNELS.find(\n (channel) => channel !== node.channel && index[channel].has(node.template)\n );\n const hint = other === undefined ? '' : ` (it is registered as a ${other} template)`;\n throw new ConfigCompileError(\n `${where}: ${node.channel} template '${node.template}' is not registered${hint}`\n );\n }\n const shape = (entry.props._zod.def as core.$ZodObjectDef).shape;\n const problems: string[] = [];\n for (const [field, value] of Object.entries(node.props)) {\n if (!Object.hasOwn(shape, field)) {\n problems.push(`'${field}' is not a prop of the template`);\n continue;\n }\n if (typeof value === 'object' && 'type' in value) {\n // A user ref's value exists only at send time (parsed then); here its name can be checked\n const profile = config.contract?.schemas.profile._zod.def;\n if (\n profile !== undefined &&\n value.path !== 'userId' &&\n !Object.hasOwn(profile.shape, value.path)\n ) {\n problems.push(\n `'${field}' reads u.${value.path}, which the contract's profile does not declare`\n );\n }\n continue;\n }\n const result = z.safeParse(shape[field], value);\n if (!result.success)\n problems.push(`'${field}' = ${JSON.stringify(value)} is refused by the schema`);\n }\n for (const [field, schema] of Object.entries(shape)) {\n const optional = canBeOmitted(schema);\n if (!optional && !Object.hasOwn(node.props, field))\n problems.push(`required prop '${field}' is missing`);\n }\n if (problems.length > 0) {\n throw new ConfigCompileError(\n `${where}: ${node.channel} '${node.template}': ${problems.join('; ')}`\n );\n }\n}\n\n/**\n * Whether an object schema refuses keys it does not declare: `z.strictObject`\n * sets its catchall to `never`; `z.object` strips unknown keys and\n * `z.looseObject` passes them through, and neither refuses.\n */\nfunction refusesUnknownKeys(schema: core.$ZodType): boolean {\n return (schema._zod.def as core.$ZodObjectDef).catchall?._zod.def.type === 'never';\n}\n\n/**\n * An emitted event against the contract, as far as compile time can see: the\n * event is declared, literal payload values parse against their field, no\n * required field is missing, and — when the event's schema is strict — no\n * literal field is undeclared (the Worker would refuse the whole event at\n * emit time, failing the journey where the compile could have failed the\n * build). Values read from the profile are checked when the event is emitted,\n * by the same contract.\n */\nfunction checkEmit(\n workflow: WorkflowIR,\n node: Extract<NodeIR, { type: 'send_event' }>,\n config: JourneyConfig\n): void {\n const contract = config.contract;\n if (contract === undefined) return;\n const where = `workflow '${workflow.id}' node ${node.id}`;\n if (!contract.isEvent(node.event)) {\n throw new ConfigCompileError(\n `${where}: emits '${String(node.event)}', which is not in the contract`\n );\n }\n const schema = contract.schemas.events[node.event];\n const shape = (schema._zod.def as core.$ZodObjectDef).shape;\n const strict = refusesUnknownKeys(schema);\n const problems: string[] = [];\n for (const [field, value] of Object.entries(node.payload)) {\n if (typeof value === 'object' && 'type' in value) continue; // read at emit time\n if (!Object.hasOwn(shape, field)) {\n // A loose or stripping payload may carry extra fields; a strict one refuses them\n if (strict) problems.push(`'${field}' is not a field the contract declares for the event`);\n continue;\n }\n const result = z.safeParse(shape[field], value);\n if (!result.success)\n problems.push(`'${field}' = ${JSON.stringify(value)} is refused by the contract`);\n }\n for (const [field, fieldSchema] of Object.entries(shape)) {\n const optional = canBeOmitted(fieldSchema);\n if (!optional && !Object.hasOwn(node.payload, field))\n problems.push(`required field '${field}' is missing`);\n }\n if (problems.length > 0) {\n throw new ConfigCompileError(`${where}: event '${node.event}': ${problems.join('; ')}`);\n }\n}\n"],"mappings":";;;;;;;;;;AAoHA,SAAgB,aAAa,YAAoD;CAC/E,OAAO;EAAE,MAAM;EAAkB,GAAG;CAAW;AACjD;AAEA,SAAgB,SAAS,OAAwC;CAC/D,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS;AAE3C;;AAGA,SAAgB,gBAAgB,QAAoB,MAA6C;CAC/F,OAAO,OAAO,cAAc,UAAU,SAAS,eAAe,eAAe;AAC/E;;AAGA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,OAAyB;AAC3B;;;;;;;;;;;;;;;;;AAkBA,SAAgB,cAAc,QAAiC;CAC7D,IAAI;CACJ,IAAI;EACF,MAAM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,KAAK,IAAI,SAAS;AAC7E;;;;;;;;;;AAWA,SAAS,UACP,UACA,MACA,QACM;CACN,MAAM,WAAW,OAAO;CACxB,IAAI,aAAa,KAAA,GAAW;CAC5B,MAAM,QAAQ,aAAa,SAAS,GAAG,SAAS,KAAK;CACrD,IAAI,CAAC,SAAS,QAAQ,KAAK,KAAK,GAC9B,MAAM,IAAI,mBACR,GAAG,MAAM,WAAW,OAAO,KAAK,KAAK,EAAE,gCACzC;CAEF,MAAM,SAAS,SAAS,QAAQ,OAAO,KAAK;CAC5C,MAAM,QAAS,OAAO,KAAK,IAA2B;CACtD,MAAM,SAAS,mBAAmB,MAAM;CACxC,MAAM,WAAqB,CAAC;CAC5B,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,OAAO,GAAG;EACzD,IAAI,OAAO,UAAU,YAAY,UAAU,OAAO;EAClD,IAAI,CAAC,OAAO,OAAO,OAAO,KAAK,GAAG;GAEhC,IAAI,QAAQ,SAAS,KAAK,IAAI,MAAM,qDAAqD;GACzF;EACF;EAEA,IAAI,CADWA,SAAE,UAAU,MAAM,QAAQ,KAC/B,CAAC,CAAC,SACV,SAAS,KAAK,IAAI,MAAM,MAAM,KAAK,UAAU,KAAK,EAAE,4BAA4B;CACpF;CACA,KAAK,MAAM,CAAC,OAAO,gBAAgB,OAAO,QAAQ,KAAK,GAErD,IAAI,CADa,aAAa,WAClB,KAAK,CAAC,OAAO,OAAO,KAAK,SAAS,KAAK,GACjD,SAAS,KAAK,mBAAmB,MAAM,aAAa;CAExD,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,mBAAmB,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,SAAS,KAAK,IAAI,GAAG;AAE1F"}
|
|
1
|
+
{"version":3,"file":"config.cjs","names":["indexTemplates","compileBundle","templateUses","CHANNEL_OF","z"],"sources":["../src/config.ts"],"sourcesContent":["import * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport type { Contract, Topic } from './contract';\nimport { type ActionRef, type SegmentRef, type WorkflowBuilder, compileBundle } from './dsl';\nimport { templateUses } from './dsl/flow';\nimport { type EmailConfig, assertEmailConfig, assertTemplateTopic } from './email';\nimport type { BundleIR, ChannelIR, NodeIR, WorkflowIR } from './ir';\nimport type { JourneyMode, JourneyRuntimeConfig } from './runtime';\nimport {\n type AnyTemplate,\n CHANNEL_OF,\n type EmailTemplate,\n type PushTemplate,\n type TemplateChannel,\n type TemplateRegistry,\n indexTemplates,\n} from './templates';\n\n/**\n * `workflow.config.ts` — the project's journey configuration, typed, flat and\n * committed with the code: what it deploys (workflows, segments, actions),\n * the template registries behind them, the contract every inbound event is\n * checked against, what the email templates share, and how the engine runs per\n * environment (time scale, APNs, FCM). The compiler (`compileConfig`), the\n * Worker (`journeyWorker({ config })`) and the Workflow Studio all read this\n * one object, so everything is registered exactly once:\n *\n * export default defineConfig({\n * title: 'Workflow Studio · Acme',\n * contract,\n * workflows, // [onboarding, notificationTest]\n * templates, // { email, push }: the definitions the workflows send\n * email: { unsubscribeUrl: 'https://acme.test/unsubscribe' },\n * runtime: { development: { timeScale: 600, logMessages: true } },\n * apns: { topic: 'io.acme.app', keyId: 'ABC123DEFG', teamId: 'TEAM123456' },\n * });\n *\n * Secrets are the one thing that stay out: a `.p8`, a service account, the\n * ingest bearer. The host reads them from its environment under fixed names\n * (see `JourneyEnv`), so the config says *which* key without carrying it. The\n * config is a source object (schemas, components, functions); only its\n * compiled bundle and preview-safe template data may cross to a browser.\n */\n\n/** Token-based APNs, the `.p8` auth key; the key itself is `APNS_PRIVATE_KEY_BASE64` in the environment. */\nexport interface ApnsConfig {\n /** The app's bundle id (`apns-topic`). */\n topic: string;\n /** The key's 10-character id. */\n keyId: string;\n /** The Apple Developer team id. */\n teamId: string;\n /**\n * Which APNs host each mode's device tokens belong to: `sandbox` for builds\n * signed with `aps-environment: development` (Xcode, the simulator),\n * `production` for App Store and TestFlight builds. Unlisted modes default\n * to `production` for the production mode and `sandbox` for every other.\n */\n environment?: Partial<Record<JourneyMode, 'sandbox' | 'production'>>;\n}\n\n/**\n * Standard Web Push for browsers (VAPID); the key pair is `VAPID_PUBLIC_KEY` /\n * `VAPID_PRIVATE_KEY` in the environment, and the site subscribes with the same public key.\n */\nexport interface WebPushConfig {\n /** Who push services may contact about this sender: `mailto:` or an `https:` URL. */\n subject: string;\n /**\n * The contract event a notification tap the browser reports (`opened_url`) is also recorded\n * as, with `{ message_id }`: the app reports its own taps as an event, and a service worker has\n * no session to do so — without this, browser opens reach the reports but not the conditions\n * (a `performed(e.push_opened)` segment). One event per copy, however often it is tapped.\n */\n openedEvent?: string;\n}\n\n/** FCM HTTP v1 for Android; the service account is `GOOGLE_APPLICATION_CREDENTIALS_BASE64` in the environment. */\nexport interface FcmConfig {\n /** Android notification channel the pushes land in (`android.notification.channel_id`). */\n androidChannelId?: string;\n}\n\n/**\n * The engine's tables live in a Postgres schema of their own, so their short names (`event`,\n * `profile`, `message`, …) never meet the app's. `workflow-ui generate` writes them as one drizzle\n * file on this schema; the host migrates it with its own tooling.\n */\nexport interface DatabaseConfig {\n /** The Postgres schema; `workflow` by default. */\n schema?: string;\n}\n\nexport interface JourneyConfigDefinition<C extends Contract | undefined = Contract | undefined> {\n /** Studio title (the browser tab names the project). */\n title?: string;\n /** The shared `defineContract(...)` the Worker validates ingest against. */\n contract?: C;\n workflows: readonly WorkflowBuilder[];\n segments?: readonly SegmentRef[];\n actions?: readonly ActionRef[];\n /**\n * The template definitions, per channel; each is identified by its own `id`. With a\n * `contract`, an email or push template's `topic` must be one it declares — in the editor\n * here, and at compile for anything the types did not see.\n */\n templates?: TemplateRegistry<Topic<C>>;\n /** What every email template shares: the default unsubscribe link, how opens and clicks are judged. */\n email?: EmailConfig;\n /** How the engine behaves per mode (`development`, `production`, …): time scale, message logging. */\n runtime?: JourneyRuntimeConfig;\n apns?: ApnsConfig;\n fcm?: FcmConfig;\n webPush?: WebPushConfig;\n /** The schema the store keeps the engine's tables in. */\n database?: DatabaseConfig;\n}\n\nexport interface JourneyConfig extends JourneyConfigDefinition {\n readonly kind: 'journey-config';\n}\n\nexport function defineConfig<C extends Contract | undefined = undefined>(\n definition: JourneyConfigDefinition<C>\n): JourneyConfig {\n return { kind: 'journey-config', ...(definition as JourneyConfigDefinition) };\n}\n\nexport function isConfig(value: unknown): value is JourneyConfig {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'journey-config'\n );\n}\n\n/** The APNs environment for `mode`: the configured one, else production only for production. */\nexport function apnsEnvironment(config: ApnsConfig, mode: JourneyMode): 'sandbox' | 'production' {\n return config.environment?.[mode] ?? (mode === 'production' ? 'production' : 'sandbox');\n}\n\n/** A message node the config's registries cannot serve, or whose literal props its template refuses. */\nexport class ConfigCompileError extends Error {\n override readonly name = 'ConfigCompileError';\n}\n\n/**\n * Compile the config: the bundle `compileBundle` would produce, with the\n * template manifest generated from the registry (every registered template,\n * by id, not a hand-kept list). The registry is checked first, used or not:\n * every entry is a template of its channel with an id, an id is registered\n * once per channel, and every email template's metadata is valid, as is the\n * config's `email` (which replaced `emails`: a config still carrying it fails),\n * and every email and push template's `topic` is one the contract declares (a\n * template with a topic under a config whose contract declares none fails too).\n * Then every message node is checked against it — an\n * unregistered or cross-channel template fails with the workflow, node and\n * channel named, and so does a literal prop the template's schema refuses (a\n * missing required prop, an undeclared one, a wrong literal) — and every\n * definition a workflow sends must be the very object registered under its id,\n * not merely one with the same id. User-property references cannot be parsed\n * here (their values exist only at send time) — they are checked by name only,\n * and parsed before sending.\n */\nexport function compileConfig(config: JourneyConfig): BundleIR {\n let index: RegistryIndex;\n try {\n const email = indexTemplates('email', config.templates?.email);\n const push = indexTemplates('push', config.templates?.push);\n assertEmailConfig(config, email.values());\n for (const template of push.values()) {\n assertTemplateTopic(template, `push template '${template.id}'`, 'push', true);\n }\n const declared = config.contract?.topics ?? [];\n assertTopicsDeclared('email', email.values(), declared);\n assertTopicsDeclared('push', push.values(), declared);\n index = {\n email,\n push,\n discord: indexTemplates('discord', config.templates?.discord),\n slack: indexTemplates('slack', config.templates?.slack),\n };\n } catch (error) {\n throw new ConfigCompileError((error as Error).message);\n }\n const bundle = compileBundle({\n workflows: config.workflows,\n ...(config.segments === undefined ? {} : { segments: config.segments }),\n ...(config.actions === undefined ? {} : { actions: config.actions }),\n templates: TEMPLATE_CHANNELS.flatMap((channel) => [...index[channel].values()]),\n subscriptions: { topics: config.contract?.topics ?? [] },\n });\n bundle.workflows.forEach((workflow, i) => {\n checkMessages(workflow, workflow.flow, index, config);\n checkUses(workflow, config.workflows[i], index, config);\n });\n return bundle;\n}\n\nconst TEMPLATE_CHANNELS = ['email', 'push', 'discord', 'slack'] as const;\n\n/**\n * Every topic template names a topic the contract declares: the engine checks opt-outs by topic,\n * so one the producer cannot set (`JourneyClient.setSubscriptions`) would be a topic nobody\n * can opt out of through the app.\n */\nfunction assertTopicsDeclared(\n channel: 'email' | 'push',\n templates: Iterable<EmailTemplate | PushTemplate>,\n declared: readonly string[]\n) {\n const known = new Set(declared);\n for (const template of templates) {\n if (template.topic === null || known.has(template.topic)) continue;\n const list =\n declared.length === 0\n ? 'the contract declares no topics (defineContract({ subscriptions: { topics: [...] } }))'\n : `the contract declares ${declared.map((topic) => `'${topic}'`).join(', ')}`;\n throw new TypeError(\n `${channel} template '${template.id}': topic '${template.topic}' is not declared — ${list}`\n );\n }\n}\n\n/** The registry by id, per channel. */\ntype RegistryIndex = Record<TemplateChannel, ReadonlyMap<string, AnyTemplate>>;\n\n/** The channel's templates by id; undefined for a channel templates cannot be declared for. */\nfunction indexOf(\n index: RegistryIndex,\n channel: ChannelIR\n): ReadonlyMap<string, AnyTemplate> | undefined {\n return (TEMPLATE_CHANNELS as readonly ChannelIR[]).includes(channel)\n ? index[channel as TemplateChannel]\n : undefined;\n}\n\n/**\n * The definitions a workflow sends against the registered ones: same id is not enough — a\n * workflow typed by one definition and a registry holding another under that id would render\n * with a schema the call was never checked against.\n */\nfunction checkUses(\n workflow: WorkflowIR,\n builder: WorkflowBuilder,\n index: RegistryIndex,\n config: JourneyConfig\n): void {\n for (const { template, loc } of templateUses(builder)) {\n const channel = CHANNEL_OF[template.kind];\n const registered = index[channel].get(template.id);\n if (registered === template) continue;\n const at = loc === undefined ? '' : ` (${loc.file}:${loc.line})`;\n const where = `workflow '${workflow.id}'${at}: ${channel} template '${template.id}'`;\n if (registered === undefined) throw new ConfigCompileError(`${where} is not registered`);\n const name = Object.entries(config.templates?.[channel] ?? {}).find(\n ([, entry]) => entry === registered\n )?.[0];\n throw new ConfigCompileError(\n `${where} is not the definition registered under that id (templates.${channel}.${name}) — two definitions share the id`\n );\n }\n}\n\n/** A field that may be left out: optional, or with a default the schema fills in. */\nfunction canBeOmitted(schema: core.$ZodType): boolean {\n const type = schema._zod.def.type;\n return type === 'optional' || type === 'default' || type === 'prefault';\n}\n\nfunction checkMessages(\n workflow: WorkflowIR,\n nodes: readonly NodeIR[],\n index: RegistryIndex,\n config: JourneyConfig\n): void {\n for (const node of nodes) {\n switch (node.type) {\n case 'message':\n checkMessage(workflow, node, index, config);\n break;\n case 'send_event':\n checkEmit(workflow, node, config);\n break;\n case 'branch':\n for (const c of node.cases) checkMessages(workflow, c.flow, index, config);\n if (node.otherwise) checkMessages(workflow, node.otherwise, index, config);\n break;\n case 'cohort':\n for (const arm of node.arms) checkMessages(workflow, arm.flow, index, config);\n break;\n case 'wait_until':\n if (Array.isArray(node.onTimeout)) checkMessages(workflow, node.onTimeout, index, config);\n break;\n default:\n break;\n }\n }\n}\n\nfunction checkMessage(\n workflow: WorkflowIR,\n node: Extract<NodeIR, { type: 'message' }>,\n index: RegistryIndex,\n config: JourneyConfig\n): void {\n const where = `workflow '${workflow.id}' node ${node.id}`;\n const registry = indexOf(index, node.channel);\n // Channels without template definitions (sms, …) are rendered by app-supplied senders\n if (registry === undefined) return;\n const entry = registry.get(node.template);\n if (entry === undefined) {\n const other = TEMPLATE_CHANNELS.find(\n (channel) => channel !== node.channel && index[channel].has(node.template)\n );\n const hint = other === undefined ? '' : ` (it is registered as a ${other} template)`;\n throw new ConfigCompileError(\n `${where}: ${node.channel} template '${node.template}' is not registered${hint}`\n );\n }\n const shape = (entry.props._zod.def as core.$ZodObjectDef).shape;\n const problems: string[] = [];\n for (const [field, value] of Object.entries(node.props)) {\n if (!Object.hasOwn(shape, field)) {\n problems.push(`'${field}' is not a prop of the template`);\n continue;\n }\n if (typeof value === 'object' && 'type' in value) {\n // A user ref's value exists only at send time (parsed then); here its name can be checked\n const profile = config.contract?.schemas.profile._zod.def;\n if (\n profile !== undefined &&\n value.path !== 'userId' &&\n !Object.hasOwn(profile.shape, value.path)\n ) {\n problems.push(\n `'${field}' reads u.${value.path}, which the contract's profile does not declare`\n );\n }\n continue;\n }\n const result = z.safeParse(shape[field], value);\n if (!result.success)\n problems.push(`'${field}' = ${JSON.stringify(value)} is refused by the schema`);\n }\n for (const [field, schema] of Object.entries(shape)) {\n const optional = canBeOmitted(schema);\n if (!optional && !Object.hasOwn(node.props, field))\n problems.push(`required prop '${field}' is missing`);\n }\n if (problems.length > 0) {\n throw new ConfigCompileError(\n `${where}: ${node.channel} '${node.template}': ${problems.join('; ')}`\n );\n }\n}\n\n/**\n * Whether an object schema refuses keys it does not declare: `z.strictObject`\n * sets its catchall to `never`; `z.object` strips unknown keys and\n * `z.looseObject` passes them through, and neither refuses.\n */\nfunction refusesUnknownKeys(schema: core.$ZodType): boolean {\n return (schema._zod.def as core.$ZodObjectDef).catchall?._zod.def.type === 'never';\n}\n\n/**\n * An emitted event against the contract, as far as compile time can see: the\n * event is declared, literal payload values parse against their field, no\n * required field is missing, and — when the event's schema is strict — no\n * literal field is undeclared (the Worker would refuse the whole event at\n * emit time, failing the journey where the compile could have failed the\n * build). Values read from the profile are checked when the event is emitted,\n * by the same contract.\n */\nfunction checkEmit(\n workflow: WorkflowIR,\n node: Extract<NodeIR, { type: 'send_event' }>,\n config: JourneyConfig\n): void {\n const contract = config.contract;\n if (contract === undefined) return;\n const where = `workflow '${workflow.id}' node ${node.id}`;\n if (!contract.isEvent(node.event)) {\n throw new ConfigCompileError(\n `${where}: emits '${String(node.event)}', which is not in the contract`\n );\n }\n const schema = contract.schemas.events[node.event];\n const shape = (schema._zod.def as core.$ZodObjectDef).shape;\n const strict = refusesUnknownKeys(schema);\n const problems: string[] = [];\n for (const [field, value] of Object.entries(node.payload)) {\n if (typeof value === 'object' && 'type' in value) continue; // read at emit time\n if (!Object.hasOwn(shape, field)) {\n // A loose or stripping payload may carry extra fields; a strict one refuses them\n if (strict) problems.push(`'${field}' is not a field the contract declares for the event`);\n continue;\n }\n const result = z.safeParse(shape[field], value);\n if (!result.success)\n problems.push(`'${field}' = ${JSON.stringify(value)} is refused by the contract`);\n }\n for (const [field, fieldSchema] of Object.entries(shape)) {\n const optional = canBeOmitted(fieldSchema);\n if (!optional && !Object.hasOwn(node.payload, field))\n problems.push(`required field '${field}' is missing`);\n }\n if (problems.length > 0) {\n throw new ConfigCompileError(`${where}: event '${node.event}': ${problems.join('; ')}`);\n }\n}\n"],"mappings":";;;;;;;;;;AA0HA,SAAgB,aACd,YACe;CACf,OAAO;EAAE,MAAM;EAAkB,GAAI;CAAuC;AAC9E;AAEA,SAAgB,SAAS,OAAwC;CAC/D,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS;AAE3C;;AAGA,SAAgB,gBAAgB,QAAoB,MAA6C;CAC/F,OAAO,OAAO,cAAc,UAAU,SAAS,eAAe,eAAe;AAC/E;;AAGA,IAAa,qBAAb,cAAwC,MAAM;CAC5C,OAAyB;AAC3B;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,cAAc,QAAiC;CAC7D,IAAI;CACJ,IAAI;EACF,MAAM,QAAQA,kBAAAA,eAAe,SAAS,OAAO,WAAW,KAAK;EAC7D,MAAM,OAAOA,kBAAAA,eAAe,QAAQ,OAAO,WAAW,IAAI;EAC1D,cAAA,kBAAkB,QAAQ,MAAM,OAAO,CAAC;EACxC,KAAK,MAAM,YA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AAS,KAAK,IAAI,MAAM,MAAM,KAAK,UAAU,KAAK,EAAE,4BAA4B;CACpF;CACA,KAAK,MAAM,CAAC,OAAO,gBAAgB,OAAO,QAAQ,KAAK,GAErD,IAAI,CADa,aAAa,WAClB,KAAK,CAAC,OAAO,OAAO,KAAK,SAAS,KAAK,GACjD,SAAS,KAAK,mBAAmB,MAAM,aAAa;CAExD,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,mBAAmB,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,SAAS,KAAK,IAAI,GAAG;AAE1F"}
|
package/dist/config.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BundleIR } from "./ir.cjs";
|
|
2
|
-
import { EmailConfig } from "./email.cjs";
|
|
3
|
-
import { TemplateRegistry } from "./templates.cjs";
|
|
4
2
|
import { ActionRef } from "./dsl/action.cjs";
|
|
5
3
|
import { SegmentRef } from "./dsl/condition.cjs";
|
|
6
4
|
import { WorkflowBuilder } from "./dsl/workflow.cjs";
|
|
7
5
|
import "./dsl/index.cjs";
|
|
8
|
-
import { Contract } from "./contract.cjs";
|
|
6
|
+
import { Contract, Topic } from "./contract.cjs";
|
|
7
|
+
import { EmailConfig } from "./email.cjs";
|
|
8
|
+
import { TemplateRegistry } from "./templates.cjs";
|
|
9
9
|
import { JourneyMode, JourneyRuntimeConfig } from "./runtime.cjs";
|
|
10
10
|
/**
|
|
11
11
|
* `workflow.config.ts` — the project's journey configuration, typed, flat and
|
|
@@ -77,16 +77,20 @@ export interface DatabaseConfig {
|
|
|
77
77
|
/** The Postgres schema; `workflow` by default. */
|
|
78
78
|
schema?: string;
|
|
79
79
|
}
|
|
80
|
-
export interface JourneyConfigDefinition {
|
|
80
|
+
export interface JourneyConfigDefinition<C extends Contract | undefined = Contract | undefined> {
|
|
81
81
|
/** Studio title (the browser tab names the project). */
|
|
82
82
|
title?: string;
|
|
83
83
|
/** The shared `defineContract(...)` the Worker validates ingest against. */
|
|
84
|
-
contract?:
|
|
84
|
+
contract?: C;
|
|
85
85
|
workflows: readonly WorkflowBuilder[];
|
|
86
86
|
segments?: readonly SegmentRef[];
|
|
87
87
|
actions?: readonly ActionRef[];
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* The template definitions, per channel; each is identified by its own `id`. With a
|
|
90
|
+
* `contract`, an email or push template's `topic` must be one it declares — in the editor
|
|
91
|
+
* here, and at compile for anything the types did not see.
|
|
92
|
+
*/
|
|
93
|
+
templates?: TemplateRegistry<Topic<C>>;
|
|
90
94
|
/** What every email template shares: the default unsubscribe link, how opens and clicks are judged. */
|
|
91
95
|
email?: EmailConfig;
|
|
92
96
|
/** How the engine behaves per mode (`development`, `production`, …): time scale, message logging. */
|
|
@@ -100,7 +104,7 @@ export interface JourneyConfigDefinition {
|
|
|
100
104
|
export interface JourneyConfig extends JourneyConfigDefinition {
|
|
101
105
|
readonly kind: 'journey-config';
|
|
102
106
|
}
|
|
103
|
-
export declare function defineConfig(definition: JourneyConfigDefinition): JourneyConfig;
|
|
107
|
+
export declare function defineConfig<C extends Contract | undefined = undefined>(definition: JourneyConfigDefinition<C>): JourneyConfig;
|
|
104
108
|
export declare function isConfig(value: unknown): value is JourneyConfig;
|
|
105
109
|
/** The APNs environment for `mode`: the configured one, else production only for production. */
|
|
106
110
|
export declare function apnsEnvironment(config: ApnsConfig, mode: JourneyMode): 'sandbox' | 'production';
|
|
@@ -114,7 +118,9 @@ export declare class ConfigCompileError extends Error {
|
|
|
114
118
|
* by id, not a hand-kept list). The registry is checked first, used or not:
|
|
115
119
|
* every entry is a template of its channel with an id, an id is registered
|
|
116
120
|
* once per channel, and every email template's metadata is valid, as is the
|
|
117
|
-
* config's `email` (which replaced `emails`: a config still carrying it fails)
|
|
121
|
+
* config's `email` (which replaced `emails`: a config still carrying it fails),
|
|
122
|
+
* and every email and push template's `topic` is one the contract declares (a
|
|
123
|
+
* template with a topic under a config whose contract declares none fails too).
|
|
118
124
|
* Then every message node is checked against it — an
|
|
119
125
|
* unregistered or cross-channel template fails with the workflow, node and
|
|
120
126
|
* channel named, and so does a literal prop the template's schema refuses (a
|