@shware/workflow 0.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +90 -49
  2. package/dist/client.d.cts +1 -1
  3. package/dist/client.d.mts +1 -1
  4. package/dist/cloudflare/bindings.cjs.map +1 -1
  5. package/dist/cloudflare/bindings.d.cts +1 -1
  6. package/dist/cloudflare/bindings.d.mts +1 -1
  7. package/dist/cloudflare/bindings.mjs.map +1 -1
  8. package/dist/cloudflare/channels.cjs +13 -18
  9. package/dist/cloudflare/channels.cjs.map +1 -1
  10. package/dist/cloudflare/channels.d.cts +3 -3
  11. package/dist/cloudflare/channels.d.cts.map +1 -1
  12. package/dist/cloudflare/channels.d.mts +3 -3
  13. package/dist/cloudflare/channels.d.mts.map +1 -1
  14. package/dist/cloudflare/channels.mjs +14 -19
  15. package/dist/cloudflare/channels.mjs.map +1 -1
  16. package/dist/cloudflare/index.d.cts +4 -4
  17. package/dist/cloudflare/index.d.mts +4 -4
  18. package/dist/cloudflare/router.d.cts +1 -1
  19. package/dist/cloudflare/router.d.mts +1 -1
  20. package/dist/cloudflare/runner.d.cts +2 -2
  21. package/dist/cloudflare/runner.d.mts +2 -2
  22. package/dist/cloudflare/senders.cjs +15 -8
  23. package/dist/cloudflare/senders.cjs.map +1 -1
  24. package/dist/cloudflare/senders.d.cts +15 -11
  25. package/dist/cloudflare/senders.d.cts.map +1 -1
  26. package/dist/cloudflare/senders.d.mts +15 -11
  27. package/dist/cloudflare/senders.d.mts.map +1 -1
  28. package/dist/cloudflare/senders.mjs +15 -8
  29. package/dist/cloudflare/senders.mjs.map +1 -1
  30. package/dist/cloudflare/worker.cjs +7 -4
  31. package/dist/cloudflare/worker.cjs.map +1 -1
  32. package/dist/cloudflare/worker.d.cts +2 -2
  33. package/dist/cloudflare/worker.d.cts.map +1 -1
  34. package/dist/cloudflare/worker.d.mts +2 -2
  35. package/dist/cloudflare/worker.d.mts.map +1 -1
  36. package/dist/cloudflare/worker.mjs +8 -5
  37. package/dist/cloudflare/worker.mjs.map +1 -1
  38. package/dist/config.cjs +66 -42
  39. package/dist/config.cjs.map +1 -1
  40. package/dist/config.d.cts +26 -45
  41. package/dist/config.d.cts.map +1 -1
  42. package/dist/config.d.mts +26 -45
  43. package/dist/config.d.mts.map +1 -1
  44. package/dist/config.mjs +67 -42
  45. package/dist/config.mjs.map +1 -1
  46. package/dist/dsl/action.cjs +1 -1
  47. package/dist/dsl/action.cjs.map +1 -1
  48. package/dist/dsl/action.d.cts +1 -1
  49. package/dist/dsl/action.d.mts +1 -1
  50. package/dist/dsl/action.mjs +1 -1
  51. package/dist/dsl/action.mjs.map +1 -1
  52. package/dist/dsl/bundle.cjs +3 -2
  53. package/dist/dsl/bundle.cjs.map +1 -1
  54. package/dist/dsl/bundle.d.cts +3 -2
  55. package/dist/dsl/bundle.d.cts.map +1 -1
  56. package/dist/dsl/bundle.d.mts +3 -2
  57. package/dist/dsl/bundle.d.mts.map +1 -1
  58. package/dist/dsl/bundle.mjs +3 -2
  59. package/dist/dsl/bundle.mjs.map +1 -1
  60. package/dist/dsl/condition.cjs +1 -1
  61. package/dist/dsl/condition.cjs.map +1 -1
  62. package/dist/dsl/condition.d.cts +1 -1
  63. package/dist/dsl/condition.d.mts +1 -1
  64. package/dist/dsl/condition.mjs +1 -1
  65. package/dist/dsl/condition.mjs.map +1 -1
  66. package/dist/dsl/flow.cjs +45 -17
  67. package/dist/dsl/flow.cjs.map +1 -1
  68. package/dist/dsl/flow.d.cts +30 -17
  69. package/dist/dsl/flow.d.cts.map +1 -1
  70. package/dist/dsl/flow.d.mts +30 -17
  71. package/dist/dsl/flow.d.mts.map +1 -1
  72. package/dist/dsl/flow.mjs +45 -18
  73. package/dist/dsl/flow.mjs.map +1 -1
  74. package/dist/dsl/index.cjs +0 -1
  75. package/dist/dsl/index.d.cts +2 -2
  76. package/dist/dsl/index.d.mts +2 -2
  77. package/dist/dsl/index.mjs +2 -2
  78. package/dist/dsl/template.cjs +2 -47
  79. package/dist/dsl/template.cjs.map +1 -1
  80. package/dist/dsl/template.d.cts +4 -54
  81. package/dist/dsl/template.d.cts.map +1 -1
  82. package/dist/dsl/template.d.mts +4 -54
  83. package/dist/dsl/template.d.mts.map +1 -1
  84. package/dist/dsl/template.mjs +3 -47
  85. package/dist/dsl/template.mjs.map +1 -1
  86. package/dist/dsl/workflow.cjs +1 -1
  87. package/dist/dsl/workflow.cjs.map +1 -1
  88. package/dist/dsl/workflow.d.cts +1 -1
  89. package/dist/dsl/workflow.d.mts +1 -1
  90. package/dist/dsl/workflow.mjs +1 -1
  91. package/dist/dsl/workflow.mjs.map +1 -1
  92. package/dist/email-context.cjs +29 -0
  93. package/dist/email-context.cjs.map +1 -0
  94. package/dist/email-context.d.cts +11 -0
  95. package/dist/email-context.d.cts.map +1 -0
  96. package/dist/email-context.d.mts +11 -0
  97. package/dist/email-context.d.mts.map +1 -0
  98. package/dist/email-context.mjs +27 -0
  99. package/dist/email-context.mjs.map +1 -0
  100. package/dist/email.cjs +72 -0
  101. package/dist/email.cjs.map +1 -0
  102. package/dist/email.d.cts +63 -0
  103. package/dist/email.d.cts.map +1 -0
  104. package/dist/email.d.mts +63 -0
  105. package/dist/email.d.mts.map +1 -0
  106. package/dist/email.mjs +65 -0
  107. package/dist/email.mjs.map +1 -0
  108. package/dist/engine/index.d.cts +2 -2
  109. package/dist/engine/index.d.mts +2 -2
  110. package/dist/engine/ports.d.cts +7 -2
  111. package/dist/engine/ports.d.cts.map +1 -1
  112. package/dist/engine/ports.d.mts +7 -2
  113. package/dist/engine/ports.d.mts.map +1 -1
  114. package/dist/index.cjs +13 -3
  115. package/dist/index.d.cts +5 -4
  116. package/dist/index.d.mts +5 -4
  117. package/dist/index.mjs +5 -4
  118. package/dist/push.cjs +3 -5
  119. package/dist/push.cjs.map +1 -1
  120. package/dist/push.d.cts +2 -2
  121. package/dist/push.d.cts.map +1 -1
  122. package/dist/push.d.mts +2 -2
  123. package/dist/push.d.mts.map +1 -1
  124. package/dist/push.mjs +4 -6
  125. package/dist/push.mjs.map +1 -1
  126. package/dist/react-email.cjs +16 -8
  127. package/dist/react-email.cjs.map +1 -1
  128. package/dist/react-email.d.cts +2 -1
  129. package/dist/react-email.d.cts.map +1 -1
  130. package/dist/react-email.d.mts +2 -1
  131. package/dist/react-email.d.mts.map +1 -1
  132. package/dist/react-email.mjs +17 -9
  133. package/dist/react-email.mjs.map +1 -1
  134. package/dist/reporting/classify.cjs.map +1 -1
  135. package/dist/reporting/classify.d.cts +1 -1
  136. package/dist/reporting/classify.d.mts +1 -1
  137. package/dist/reporting/classify.mjs.map +1 -1
  138. package/dist/reporting/observer.cjs +5 -4
  139. package/dist/reporting/observer.cjs.map +1 -1
  140. package/dist/reporting/observer.d.cts +3 -2
  141. package/dist/reporting/observer.d.cts.map +1 -1
  142. package/dist/reporting/observer.d.mts +3 -2
  143. package/dist/reporting/observer.d.mts.map +1 -1
  144. package/dist/reporting/observer.mjs +5 -4
  145. package/dist/reporting/observer.mjs.map +1 -1
  146. package/dist/reporting/tracking.cjs +3 -12
  147. package/dist/reporting/tracking.cjs.map +1 -1
  148. package/dist/reporting/tracking.d.cts +18 -7
  149. package/dist/reporting/tracking.d.cts.map +1 -1
  150. package/dist/reporting/tracking.d.mts +18 -7
  151. package/dist/reporting/tracking.d.mts.map +1 -1
  152. package/dist/reporting/tracking.mjs +3 -12
  153. package/dist/reporting/tracking.mjs.map +1 -1
  154. package/dist/templates.cjs +90 -30
  155. package/dist/templates.cjs.map +1 -1
  156. package/dist/templates.d.cts +70 -13
  157. package/dist/templates.d.cts.map +1 -1
  158. package/dist/templates.d.mts +70 -13
  159. package/dist/templates.d.mts.map +1 -1
  160. package/dist/templates.mjs +87 -31
  161. package/dist/templates.mjs.map +1 -1
  162. package/package.json +11 -1
@@ -1,11 +1,14 @@
1
1
  import { ScalarIR } from "./ir.mjs";
2
+ import { EmailAddress } from "./email.mjs";
2
3
  import { Block, KnownBlock } from "@slack/types";
3
4
  import { RESTPostAPIWebhookWithTokenJSONBody } from "discord-api-types/v10";
4
5
  import * as core from "zod/v4/core";
5
6
  //#region src/templates.d.ts
6
7
  /**
7
8
  * Template definitions — `emailTemplate`, `pushTemplate`, `discordTemplate` and `slackTemplate`. One
8
- * object per template, and its Zod `props` schema is the only source of the
9
+ * object per template, identified by its own `id` (unique per channel): workflows take the
10
+ * definition itself (`.email(welcome, props)`), the config registers it, and the IR, the manifest,
11
+ * the senders and the studio all find it by that id. Its Zod `props` schema is the only source of the
9
12
  * props type: the DSL's `.email()/.push()` arguments, the `preview`, and the
10
13
  * `component`/`content` parameter are all derived from it, and every render
11
14
  * parses the props against it first (types alone check nothing at run time).
@@ -50,6 +53,12 @@ export interface SlackContent {
50
53
  /** The channels a template can be declared for. */
51
54
  export type TemplateChannel = 'email' | 'push' | 'discord' | 'slack';
52
55
  interface TemplateBase<S extends PropsSchema> {
56
+ /**
57
+ * Wire identity, unique per channel: message nodes, the template manifest, every send and the
58
+ * studio's preview links name the template by it. Not something to rename for readability —
59
+ * `title` is; the property a registry holds it under is only a JavaScript name.
60
+ */
61
+ readonly id: string;
53
62
  /** Display name in the studio (not the email subject, not the notification title). */
54
63
  readonly title: string;
55
64
  readonly description?: string | undefined;
@@ -57,7 +66,19 @@ interface TemplateBase<S extends PropsSchema> {
57
66
  /** Sample props for the studio; parsed against `props` when the template is declared. */
58
67
  readonly preview: core.input<S>;
59
68
  }
60
- export interface EmailTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {
69
+ /**
70
+ * Who an email comes from and where it leads: declared on each template, never inherited from a
71
+ * global sender. Metadata, not props — the component never receives it; its layout reads the
72
+ * resolved unsubscribe link with `useEmailContext()` (`@shware/workflow/email-context`).
73
+ */
74
+ export interface EmailMetadata {
75
+ readonly from: EmailAddress;
76
+ /** Where replies go; left out, the email has no Reply-To (it is not `from`, and not inherited). */
77
+ readonly replyTo?: EmailAddress | undefined;
78
+ /** This template's unsubscribe link; left out, the config's `email.unsubscribeUrl` (if any). */
79
+ readonly unsubscribeUrl?: string | undefined;
80
+ }
81
+ export interface EmailTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S>, EmailMetadata {
61
82
  readonly kind: 'email-template';
62
83
  readonly version: 1;
63
84
  readonly subject: string;
@@ -93,14 +114,19 @@ export interface SlackTemplate<S extends PropsSchema = PropsSchema, Env = Record
93
114
  /** Strips a Promise return out of the accepted callback types: async content is rejected at the type level. */
94
115
  type Sync<T> = T extends Promise<unknown> ? never : T;
95
116
  export interface EmailTemplateDefinition<S extends PropsSchema> {
117
+ id: string;
96
118
  title: string;
97
119
  description?: string;
120
+ from: EmailAddress;
121
+ replyTo?: EmailAddress;
122
+ unsubscribeUrl?: string;
98
123
  props: S;
99
124
  subject: string;
100
125
  preview: NoInfer<core.input<S>>;
101
126
  component: (props: NoInfer<Readonly<core.output<S>>>) => unknown;
102
127
  }
103
128
  export interface PushTemplateDefinition<S extends PropsSchema, R> {
129
+ id: string;
104
130
  title: string;
105
131
  description?: string;
106
132
  props: S;
@@ -108,6 +134,7 @@ export interface PushTemplateDefinition<S extends PropsSchema, R> {
108
134
  content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<R> & PushContent;
109
135
  }
110
136
  export interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {
137
+ id: string;
111
138
  title: string;
112
139
  description?: string;
113
140
  props: S;
@@ -120,7 +147,10 @@ export interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {
120
147
  export declare function discordTemplate<S extends PropsSchema, Env = Record<string, unknown>>(definition: WebhookTemplateDefinition<S, Env, DiscordContent>): DiscordTemplate<S, Env>;
121
148
  /** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */
122
149
  export declare function slackTemplate<S extends PropsSchema, Env = Record<string, unknown>>(definition: WebhookTemplateDefinition<S, Env, SlackContent>): SlackTemplate<S, Env>;
123
- /** Declare an email template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
150
+ /**
151
+ * Declare an email template. Throws when `from` is missing or invalid, `replyTo` or `unsubscribeUrl`
152
+ * is invalid, `props` uses an unsupported schema or `preview` does not parse.
153
+ */
124
154
  export declare function emailTemplate<S extends PropsSchema>(definition: EmailTemplateDefinition<S>): EmailTemplate<S>;
125
155
  /** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
126
156
  export declare function pushTemplate<S extends PropsSchema, R extends PushContent>(definition: PushTemplateDefinition<S, R>): PushTemplate<S>;
@@ -130,6 +160,38 @@ export declare function isDiscordTemplate(value: unknown): value is DiscordTempl
130
160
  export declare function isSlackTemplate(value: unknown): value is SlackTemplate;
131
161
  /** Any declared template. */
132
162
  export type AnyTemplate = EmailTemplate | PushTemplate | DiscordTemplate | SlackTemplate;
163
+ export declare const CHANNEL_OF: Record<AnyTemplate['kind'], TemplateChannel>;
164
+ /** Any template definition, whatever its channel. */
165
+ export declare function isTemplate(value: unknown): value is AnyTemplate;
166
+ /**
167
+ * The template registry: per channel, the definitions the project registers. Each channel is a
168
+ * plain object whose property names are JavaScript names only — a template is identified by its
169
+ * own `id` (`indexTemplates`).
170
+ */
171
+ export interface TemplateRegistry {
172
+ readonly email?: Readonly<Record<string, EmailTemplate>>;
173
+ readonly push?: Readonly<Record<string, PushTemplate>>;
174
+ /** Discord webhook templates, each typed by the host's Env its `webhook` reads. */
175
+ readonly discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>>;
176
+ readonly slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>>;
177
+ }
178
+ /** The template a channel's registry holds. */
179
+ export interface ChannelTemplate {
180
+ email: EmailTemplate;
181
+ push: PushTemplate;
182
+ discord: DiscordTemplate;
183
+ slack: SlackTemplate;
184
+ }
185
+ /**
186
+ * A channel's registry by template id — how everything that turns an id back into a definition
187
+ * (the compiler, the validator, the renderers, the senders, the studio) looks it up. Throws when
188
+ * an entry is not a template of the channel, has no id, or shares its id with another entry: an id
189
+ * is registered once per channel, so two registrations (even of the same object) are an error,
190
+ * not a silent last-wins. Insertion order is the registry's.
191
+ */
192
+ export declare function indexTemplates<C extends TemplateChannel>(channel: C, registry: Readonly<Record<string, unknown>> | undefined): ReadonlyMap<string, ChannelTemplate[C]>;
193
+ /** A registered template by id; throws naming the channel and id when there is none. */
194
+ export declare function lookupTemplate<T>(index: ReadonlyMap<string, T>, channel: string, id: string): T;
133
195
  /** One failed field, with the dotted path the studio and the logs show. */
134
196
  export interface TemplateIssue {
135
197
  path: string;
@@ -153,13 +215,13 @@ export declare class TemplateValidationError extends Error {
153
215
  * Parse message props against a template's schema and return the parsed value
154
216
  * — the only value anything downstream may use. Throws TemplateValidationError.
155
217
  */
156
- export declare function parseTemplateProps<S extends PropsSchema>(template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>, key: string, props: Record<string, unknown>): core.output<S>;
218
+ export declare function parseTemplateProps<S extends PropsSchema>(template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>, props: Record<string, unknown>): core.output<S>;
157
219
  /** Run a push template's content over parsed props and check the notification it returns. */
158
- export declare function renderPushContent(template: PushTemplate, key: string, props: Record<string, unknown>): PushContent;
220
+ export declare function renderPushContent(template: PushTemplate, props: Record<string, unknown>): PushContent;
159
221
  /** Run a Discord template's content over parsed props and check the message it returns. */
160
- export declare function renderDiscordContent(template: DiscordTemplate, key: string, props: Record<string, unknown>): DiscordContent;
222
+ export declare function renderDiscordContent(template: DiscordTemplate, props: Record<string, unknown>): DiscordContent;
161
223
  /** Run a Slack template's content over parsed props and check the message it returns. */
162
- export declare function renderSlackContent(template: SlackTemplate, key: string, props: Record<string, unknown>): SlackContent;
224
+ export declare function renderSlackContent(template: SlackTemplate, props: Record<string, unknown>): SlackContent;
163
225
  /** Throws when `schema` is outside the v1 subset (see the header). */
164
226
  export declare function assertSupportedSchema(schema: unknown, where: string): void;
165
227
  /** The scalar props a template accepts, as the IR resolves them before parsing. */
@@ -171,12 +233,7 @@ export type ResolvedProps = Record<string, ScalarIR | undefined>;
171
233
  * stops the send before any device; Discord and Slack content likewise. Channels without a
172
234
  * registry here (sms, …) pass through to their app-supplied senders.
173
235
  */
174
- export declare function registryValidator(registries: {
175
- email?: Record<string, EmailTemplate> | undefined;
176
- push?: Record<string, PushTemplate> | undefined;
177
- discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>> | undefined;
178
- slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>> | undefined;
179
- }): {
236
+ export declare function registryValidator(registry: TemplateRegistry): {
180
237
  validate(message: {
181
238
  channel: string;
182
239
  template: string;
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.mts","names":[],"sources":["../src/templates.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;YA2BY,cAAc,KAAK;;iBAGd;EACf;EACA;;EAEA;;EAEA;;;YAIU,iBAAiB;;iBAGZ;;EAEf;EACA,UAAU,aAAa;EACvB;EACA;EACA;EACA;EACA;EACA;;;YAIU;UAEF,aAAa,UAAU;;WAEtB;WACA;WACA,OAAO;;WAEP,SAAS,KAAK,MAAM;;iBAGd,cAAc,UAAU,cAAc,qBAAqB,aAAa;WAC9E;WACA;WACA;;WAEA,YAAY,OAAO,SAAS,KAAK,OAAO;;iBAGlC,aAAa,UAAU,cAAc,qBAAqB,aAAa;WAC7E;WACA;;WAEA,UAAU,OAAO,SAAS,KAAK,OAAO,QAAQ;;;;;;;;UAS/C,oBAAoB,UAAU,aAAa,aAAa,aAAa;WACpE;EAET,QAAQ,KAAK;;iBAGE,gBACf,UAAU,cAAc,aACxB,MAAM,iCACE,oBAAoB,GAAG;WACtB;;WAEA,UAAU,OAAO,SAAS,KAAK,OAAO,QAAQ;;iBAGxC,cACf,UAAU,cAAc,aACxB,MAAM,iCACE,oBAAoB,GAAG;WACtB;;WAEA,UAAU,OAAO,SAAS,KAAK,OAAO,QAAQ;;;KAIpD,KAAK,KAAK,UAAU,2BAA2B;iBAEnC,wBAAwB,UAA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iBAS9E;EACf;EACA;;;;;;;;qBASW,gCAAgC;WAGhC,SAAS;WACT;WACA;WACA,QAAQ;WALD;EAClB,YACW,SAAS,iBACT,kBACA,4BACA,QAAQ;;;;;;wBAqBL,mBAAmB,UAAU,aAC3C,UAAU,cAAc,KAAK,aAAa,KAAK,gBAAgB,KAAK,cAAc,IAClF,OAAO,0BACN,KAAK,OAAO;;wBAiBC,kBACd,UAAU,cACV,OAAO,0BACN;;wBA2Ba,qBACd,UAAU,iBACV,OAAO,0BACN;;wBAmBa,mBACd,UAAU,eACV,OAAO,0BACN;;wBA+Ba,sBAAsB,iBAAiB;;YA0D3C,gBAAgB,eAAe;;;;;;;;wBAS3B,kBAAkB,UAAU;EAC1C,SAAS;IAAW;IAAiB;IAAkB,OAAO;MAAkB"}
@@ -1,7 +1,9 @@
1
+ import { assertEmailMetadata } from "./email.mjs";
1
2
  import * as z from "zod/mini";
2
3
  //#region src/templates.ts
3
4
  /** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */
4
5
  function discordTemplate(definition) {
6
+ assertTemplateId(definition.id, "discordTemplate");
5
7
  assertSupportedSchema(definition.props, definition.title);
6
8
  parsePreview(definition.props, definition.preview, "discord", definition.title);
7
9
  return {
@@ -12,6 +14,7 @@ function discordTemplate(definition) {
12
14
  }
13
15
  /** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */
14
16
  function slackTemplate(definition) {
17
+ assertTemplateId(definition.id, "slackTemplate");
15
18
  assertSupportedSchema(definition.props, definition.title);
16
19
  parsePreview(definition.props, definition.preview, "slack", definition.title);
17
20
  return {
@@ -20,8 +23,13 @@ function slackTemplate(definition) {
20
23
  ...definition
21
24
  };
22
25
  }
23
- /** Declare an email template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
26
+ /**
27
+ * Declare an email template. Throws when `from` is missing or invalid, `replyTo` or `unsubscribeUrl`
28
+ * is invalid, `props` uses an unsupported schema or `preview` does not parse.
29
+ */
24
30
  function emailTemplate(definition) {
31
+ assertTemplateId(definition.id, "emailTemplate");
32
+ assertEmailMetadata(definition, `emailTemplate('${definition.id}')`);
25
33
  assertSupportedSchema(definition.props, definition.title);
26
34
  parsePreview(definition.props, definition.preview, "email", definition.title);
27
35
  return {
@@ -32,6 +40,7 @@ function emailTemplate(definition) {
32
40
  }
33
41
  /** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */
34
42
  function pushTemplate(definition) {
43
+ assertTemplateId(definition.id, "pushTemplate");
35
44
  assertSupportedSchema(definition.props, definition.title);
36
45
  parsePreview(definition.props, definition.preview, "push", definition.title);
37
46
  return {
@@ -40,6 +49,12 @@ function pushTemplate(definition) {
40
49
  ...definition
41
50
  };
42
51
  }
52
+ function assertTemplateId(id, factory) {
53
+ if (!isTemplateId(id)) throw new TypeError(`${factory}(): 'id' must be a non-empty string`);
54
+ }
55
+ function isTemplateId(id) {
56
+ return typeof id === "string" && id.trim() !== "";
57
+ }
43
58
  function isEmailTemplate(value) {
44
59
  return isMarked(value, "email-template");
45
60
  }
@@ -61,6 +76,44 @@ const CHANNEL_OF = {
61
76
  function isMarked(value, kind) {
62
77
  return typeof value === "object" && value !== null && value.kind === kind && value.version === 1;
63
78
  }
79
+ /** Any template definition, whatever its channel. */
80
+ function isTemplate(value) {
81
+ return typeof value === "object" && value !== null && Object.hasOwn(CHANNEL_OF, value.kind) && value.version === 1;
82
+ }
83
+ const IS_TEMPLATE = {
84
+ email: isEmailTemplate,
85
+ push: isPushTemplate,
86
+ discord: isDiscordTemplate,
87
+ slack: isSlackTemplate
88
+ };
89
+ /**
90
+ * A channel's registry by template id — how everything that turns an id back into a definition
91
+ * (the compiler, the validator, the renderers, the senders, the studio) looks it up. Throws when
92
+ * an entry is not a template of the channel, has no id, or shares its id with another entry: an id
93
+ * is registered once per channel, so two registrations (even of the same object) are an error,
94
+ * not a silent last-wins. Insertion order is the registry's.
95
+ */
96
+ function indexTemplates(channel, registry) {
97
+ const index = /* @__PURE__ */ new Map();
98
+ const paths = /* @__PURE__ */ new Map();
99
+ for (const [name, entry] of Object.entries(registry ?? {})) {
100
+ const path = `templates.${channel}.${name}`;
101
+ if (!IS_TEMPLATE[channel](entry)) throw new TypeError(`${path} is not a ${channel} template`);
102
+ const id = entry.id;
103
+ if (!isTemplateId(id)) throw new TypeError(`${path} has no id`);
104
+ const previous = paths.get(id);
105
+ if (previous !== void 0) throw new TypeError(`${channel} template id '${id}' is registered twice: ${previous} and ${path}`);
106
+ paths.set(id, path);
107
+ index.set(id, entry);
108
+ }
109
+ return index;
110
+ }
111
+ /** A registered template by id; throws naming the channel and id when there is none. */
112
+ function lookupTemplate(index, channel, id) {
113
+ const template = index.get(id);
114
+ if (template === void 0) throw new Error(`${channel} template '${id}' is not registered`);
115
+ return template;
116
+ }
64
117
  /**
65
118
  * A template refused its input (`phase: 'props'` — the component/content was
66
119
  * never called) or its content function returned something that is not a
@@ -91,10 +144,10 @@ function issuesOf(error) {
91
144
  * Parse message props against a template's schema and return the parsed value
92
145
  * — the only value anything downstream may use. Throws TemplateValidationError.
93
146
  */
94
- function parseTemplateProps(template, key, props) {
147
+ function parseTemplateProps(template, props) {
95
148
  const channel = CHANNEL_OF[template.kind];
96
149
  const result = z.safeParse(template.props, props);
97
- if (!result.success) throw new TemplateValidationError(channel, key, "props", issuesOf(result.error));
150
+ if (!result.success) throw new TemplateValidationError(channel, template.id, "props", issuesOf(result.error));
98
151
  return result.data;
99
152
  }
100
153
  const pushContentSchema = z.strictObject({
@@ -104,11 +157,11 @@ const pushContentSchema = z.strictObject({
104
157
  url: z.optional(z.string())
105
158
  });
106
159
  /** Run a push template's content over parsed props and check the notification it returns. */
107
- function renderPushContent(template, key, props) {
108
- const parsed = parseTemplateProps(template, key, props);
160
+ function renderPushContent(template, props) {
161
+ const parsed = parseTemplateProps(template, props);
109
162
  const output = template.content(parsed);
110
163
  const result = z.safeParse(pushContentSchema, output);
111
- if (!result.success) throw new TemplateValidationError("push", key, "content", issuesOf(result.error));
164
+ if (!result.success) throw new TemplateValidationError("push", template.id, "content", issuesOf(result.error));
112
165
  return result.data;
113
166
  }
114
167
  /**
@@ -125,21 +178,24 @@ const slackContentSchema = z.looseObject({
125
178
  blocks: z.optional(z.array(z.looseObject({ type: z.string() })))
126
179
  });
127
180
  /** Run a Discord template's content over parsed props and check the message it returns. */
128
- function renderDiscordContent(template, key, props) {
129
- const output = template.content(parseTemplateProps(template, key, props));
181
+ function renderDiscordContent(template, props) {
182
+ const output = template.content(parseTemplateProps(template, props));
130
183
  const result = z.safeParse(discordContentSchema, output);
131
184
  const empty = result.success && !result.data.content && (result.data.embeds?.length ?? 0) === 0 && output.poll === void 0 && (output.components?.length ?? 0) === 0;
132
- if (!result.success || empty) throw new TemplateValidationError("discord", key, "content", result.success ? [{
133
- path: "",
134
- message: "a Discord message needs content, an embed, a poll or components"
135
- }] : issuesOf(result.error));
185
+ if (!result.success || empty) {
186
+ const issues = result.success ? [{
187
+ path: "",
188
+ message: "a Discord message needs content, an embed, a poll or components"
189
+ }] : issuesOf(result.error);
190
+ throw new TemplateValidationError("discord", template.id, "content", issues);
191
+ }
136
192
  return output;
137
193
  }
138
194
  /** Run a Slack template's content over parsed props and check the message it returns. */
139
- function renderSlackContent(template, key, props) {
140
- const output = template.content(parseTemplateProps(template, key, props));
195
+ function renderSlackContent(template, props) {
196
+ const output = template.content(parseTemplateProps(template, props));
141
197
  const result = z.safeParse(slackContentSchema, output);
142
- if (!result.success) throw new TemplateValidationError("slack", key, "content", issuesOf(result.error));
198
+ if (!result.success) throw new TemplateValidationError("slack", template.id, "content", issuesOf(result.error));
143
199
  return output;
144
200
  }
145
201
  function parsePreview(schema, preview, channel, title) {
@@ -199,32 +255,32 @@ function rejectCustomChecks(def, where, fail) {
199
255
  * stops the send before any device; Discord and Slack content likewise. Channels without a
200
256
  * registry here (sms, …) pass through to their app-supplied senders.
201
257
  */
202
- function registryValidator(registries) {
258
+ function registryValidator(registry) {
259
+ const email = indexTemplates("email", registry.email);
260
+ const push = indexTemplates("push", registry.push);
261
+ const discord = indexTemplates("discord", registry.discord);
262
+ const slack = indexTemplates("slack", registry.slack);
203
263
  return { validate({ channel, template, props }) {
204
- if (channel === "email") return parseTemplateProps(lookup(registries.email, "email", template), template, props);
264
+ if (channel === "email") return parseTemplateProps(lookupTemplate(email, "email", template), props);
205
265
  if (channel === "push") {
206
- const entry = lookup(registries.push, "push", template);
207
- renderPushContent(entry, template, props);
208
- return parseTemplateProps(entry, template, props);
266
+ const entry = lookupTemplate(push, "push", template);
267
+ renderPushContent(entry, props);
268
+ return parseTemplateProps(entry, props);
209
269
  }
210
270
  if (channel === "discord") {
211
- const entry = lookup(registries.discord, "discord", template);
212
- renderDiscordContent(entry, template, props);
213
- return parseTemplateProps(entry, template, props);
271
+ const entry = lookupTemplate(discord, "discord", template);
272
+ renderDiscordContent(entry, props);
273
+ return parseTemplateProps(entry, props);
214
274
  }
215
275
  if (channel === "slack") {
216
- const entry = lookup(registries.slack, "slack", template);
217
- renderSlackContent(entry, template, props);
218
- return parseTemplateProps(entry, template, props);
276
+ const entry = lookupTemplate(slack, "slack", template);
277
+ renderSlackContent(entry, props);
278
+ return parseTemplateProps(entry, props);
219
279
  }
220
280
  return props;
221
281
  } };
222
282
  }
223
- function lookup(registry, channel, key) {
224
- if (registry === void 0 || !Object.hasOwn(registry, key)) throw new Error(`${channel} template '${key}' is not registered`);
225
- return registry[key];
226
- }
227
283
  //#endregion
228
- export { TemplateValidationError, assertSupportedSchema, discordTemplate, emailTemplate, isDiscordTemplate, isEmailTemplate, isPushTemplate, isSlackTemplate, parseTemplateProps, pushTemplate, registryValidator, renderDiscordContent, renderPushContent, renderSlackContent, slackTemplate };
284
+ export { CHANNEL_OF, TemplateValidationError, assertSupportedSchema, discordTemplate, emailTemplate, indexTemplates, isDiscordTemplate, isEmailTemplate, isPushTemplate, isSlackTemplate, isTemplate, lookupTemplate, parseTemplateProps, pushTemplate, registryValidator, renderDiscordContent, renderPushContent, renderSlackContent, slackTemplate };
229
285
 
230
286
  //# sourceMappingURL=templates.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"templates.mjs","names":[],"sources":["../src/templates.ts"],"sourcesContent":["import type { Block, KnownBlock } from '@slack/types';\nimport type { RESTPostAPIWebhookWithTokenJSONBody } from 'discord-api-types/v10';\nimport * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport type { ScalarIR } from './ir';\n\n/**\n * Template definitions — `emailTemplate`, `pushTemplate`, `discordTemplate` and `slackTemplate`. One\n * object per template, and its Zod `props` schema is the only source of the\n * props type: the DSL's `.email()/.push()` arguments, the `preview`, and the\n * `component`/`content` parameter are all derived from it, and every render\n * parses the props against it first (types alone check nothing at run time).\n *\n * Kept free of React and of any renderer: the definitions are plain data plus\n * a function, so the DSL, the Worker and the studio can all import them; the\n * React rendering lives in `@shware/workflow/react-email`.\n *\n * Supported schemas (v1): a strict object (`z.strictObject`) whose fields are\n * string / number / boolean — optionally as enums or literals, optionally\n * `.optional()`, with the built-in checks (min, email, …). That is exactly\n * what IR message props can carry, and it keeps input and output identical, so\n * producer, studio and sender never disagree about a transformed value.\n * Anything else (nested objects, arrays, null, default/transform/coerce,\n * custom refinements) is rejected when the template is declared.\n */\n\n/** A strict Zod object schema of scalar fields — the accepted shape of `props`. */\nexport type PropsSchema = core.$ZodObject;\n\n/** What a push template's `content` returns: the notification itself. */\nexport interface PushContent {\n title: string;\n body: string;\n /** Rich image URL (iOS attachment / Android BigPicture). */\n image?: string;\n /** Where a tap leads: the page a browser push opens (the site's root when absent). */\n url?: string;\n}\n\n/** A Discord webhook message (`discord-api-types`): content, embeds, username, allowed mentions… */\nexport type DiscordContent = RESTPostAPIWebhookWithTokenJSONBody;\n\n/** A Slack incoming-webhook message: the fallback `text` and, usually, Block Kit `blocks`. */\nexport interface SlackContent {\n /** Shown in notifications and wherever blocks cannot be; required even with blocks. */\n text: string;\n blocks?: (KnownBlock | Block)[];\n username?: string;\n icon_emoji?: string;\n icon_url?: string;\n mrkdwn?: boolean;\n unfurl_links?: boolean;\n unfurl_media?: boolean;\n}\n\n/** The channels a template can be declared for. */\nexport type TemplateChannel = 'email' | 'push' | 'discord' | 'slack';\n\ninterface TemplateBase<S extends PropsSchema> {\n /** Display name in the studio (not the email subject, not the notification title). */\n readonly title: string;\n readonly description?: string | undefined;\n readonly props: S;\n /** Sample props for the studio; parsed against `props` when the template is declared. */\n readonly preview: core.input<S>;\n}\n\nexport interface EmailTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {\n readonly kind: 'email-template';\n readonly version: 1;\n readonly subject: string;\n /** The email body: a component over the parsed props (rendered by `@shware/workflow/react-email`). */\n readonly component: (props: Readonly<core.output<S>>) => unknown;\n}\n\nexport interface PushTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {\n readonly kind: 'push-template';\n readonly version: 1;\n /** The notification, from the parsed props. Synchronous and pure; its result is checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => PushContent;\n}\n\n/**\n * A message posted to a team channel through an incoming webhook (Discord, Slack). The webhook\n * URL is a secret, so it lives in the Worker's environment and the template reads it from there\n * at send time: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`, with `Env` the host's\n * zod-validated environment (`journeyWorker({ env: schema })`). The studio never calls it.\n */\ninterface WebhookTemplateBase<S extends PropsSchema, Env> extends TemplateBase<S> {\n readonly version: 1;\n // A method, so a template typed by the host's Env still fits a registry of any Env\n webhook(env: Env): string | undefined;\n}\n\nexport interface DiscordTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'discord-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => DiscordContent;\n}\n\nexport interface SlackTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'slack-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => SlackContent;\n}\n\n/** Strips a Promise return out of the accepted callback types: async content is rejected at the type level. */\ntype Sync<T> = T extends Promise<unknown> ? never : T;\n\nexport interface EmailTemplateDefinition<S extends PropsSchema> {\n title: string;\n description?: string;\n props: S;\n subject: string;\n preview: NoInfer<core.input<S>>;\n component: (props: NoInfer<Readonly<core.output<S>>>) => unknown;\n}\n\nexport interface PushTemplateDefinition<S extends PropsSchema, R> {\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<R> & PushContent;\n}\n\nexport interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n /** The webhook URL, read from the Worker's environment when a message is sent. */\n webhook: (env: Env) => string | undefined;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<C>;\n}\n\n/** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function discordTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, DiscordContent>\n): DiscordTemplate<S, Env> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'discord', definition.title);\n return { kind: 'discord-template', version: 1, ...definition };\n}\n\n/** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function slackTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, SlackContent>\n): SlackTemplate<S, Env> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'slack', definition.title);\n return { kind: 'slack-template', version: 1, ...definition };\n}\n\n/** Declare an email template. Throws when `props` uses an unsupported schema or `preview` does not parse. */\nexport function emailTemplate<S extends PropsSchema>(\n definition: EmailTemplateDefinition<S>\n): EmailTemplate<S> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'email', definition.title);\n return { kind: 'email-template', version: 1, ...definition };\n}\n\n/** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */\nexport function pushTemplate<S extends PropsSchema, R extends PushContent>(\n definition: PushTemplateDefinition<S, R>\n): PushTemplate<S> {\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'push', definition.title);\n return { kind: 'push-template', version: 1, ...definition } as unknown as PushTemplate<S>;\n}\n\nexport function isEmailTemplate(value: unknown): value is EmailTemplate {\n return isMarked(value, 'email-template');\n}\n\nexport function isPushTemplate(value: unknown): value is PushTemplate {\n return isMarked(value, 'push-template');\n}\n\nexport function isDiscordTemplate(value: unknown): value is DiscordTemplate {\n return isMarked(value, 'discord-template');\n}\n\nexport function isSlackTemplate(value: unknown): value is SlackTemplate {\n return isMarked(value, 'slack-template');\n}\n\n/** Any declared template. */\nexport type AnyTemplate = EmailTemplate | PushTemplate | DiscordTemplate | SlackTemplate;\n\nconst CHANNEL_OF: Record<AnyTemplate['kind'], TemplateChannel> = {\n 'email-template': 'email',\n 'push-template': 'push',\n 'discord-template': 'discord',\n 'slack-template': 'slack',\n};\n\nfunction isMarked(value: unknown, kind: string): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === kind &&\n (value as { version?: unknown }).version === 1\n );\n}\n\n/* ------------------------------- validation -------------------------------- */\n\n/** One failed field, with the dotted path the studio and the logs show. */\nexport interface TemplateIssue {\n path: string;\n message: string;\n}\n\n/**\n * A template refused its input (`phase: 'props'` — the component/content was\n * never called) or its content function returned something that is not a\n * notification (`phase: 'content'` — called, but nothing is sent). Never a\n * provider failure: a sender must not read it as a dead device token.\n */\nexport class TemplateValidationError extends Error {\n override readonly name = 'TemplateValidationError';\n constructor(\n readonly channel: TemplateChannel,\n readonly template: string,\n readonly phase: 'props' | 'content',\n readonly issues: TemplateIssue[]\n ) {\n super(\n `${channel} template '${template}' ${phase === 'props' ? 'rejected its props' : 'returned invalid content'}: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n }\n}\n\nfunction issuesOf(error: core.$ZodError): TemplateIssue[] {\n return error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n}\n\n/**\n * Parse message props against a template's schema and return the parsed value\n * — the only value anything downstream may use. Throws TemplateValidationError.\n */\nexport function parseTemplateProps<S extends PropsSchema>(\n template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>,\n key: string,\n props: Record<string, unknown>\n): core.output<S> {\n const channel = CHANNEL_OF[template.kind];\n const result = z.safeParse(template.props, props);\n if (!result.success) {\n throw new TemplateValidationError(channel, key, 'props', issuesOf(result.error));\n }\n return result.data;\n}\n\nconst pushContentSchema = z.strictObject({\n title: z.string(),\n body: z.string(),\n image: z.optional(z.string()),\n url: z.optional(z.string()),\n});\n\n/** Run a push template's content over parsed props and check the notification it returns. */\nexport function renderPushContent(\n template: PushTemplate,\n key: string,\n props: Record<string, unknown>\n): PushContent {\n const parsed = parseTemplateProps(template, key, props);\n const output: unknown = template.content(parsed);\n // A Promise (async content smuggled past the types) is an object without title/body: refused here\n const result = z.safeParse(pushContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('push', key, 'content', issuesOf(result.error));\n }\n return result.data;\n}\n\n/**\n * What a Discord webhook accepts at all: something to show (content, an embed, a poll or\n * components) and content within Discord's 2000 characters. The rest of the body is Discord's to\n * judge; its types come from `discord-api-types`.\n */\nconst discordContentSchema = z.looseObject({\n content: z.optional(z.string().check(z.maxLength(2000))),\n embeds: z.optional(z.array(z.looseObject({}))),\n});\n\nconst slackContentSchema = z.looseObject({\n text: z.string().check(z.minLength(1)),\n blocks: z.optional(z.array(z.looseObject({ type: z.string() }))),\n});\n\n/** Run a Discord template's content over parsed props and check the message it returns. */\nexport function renderDiscordContent(\n template: DiscordTemplate,\n key: string,\n props: Record<string, unknown>\n): DiscordContent {\n const output: unknown = template.content(parseTemplateProps(template, key, props));\n const result = z.safeParse(discordContentSchema, output);\n const empty =\n result.success &&\n !result.data.content &&\n (result.data.embeds?.length ?? 0) === 0 &&\n (output as { poll?: unknown; components?: unknown[] }).poll === undefined &&\n ((output as { components?: unknown[] }).components?.length ?? 0) === 0;\n if (!result.success || empty) {\n const issues = result.success\n ? [{ path: '', message: 'a Discord message needs content, an embed, a poll or components' }]\n : issuesOf(result.error);\n throw new TemplateValidationError('discord', key, 'content', issues);\n }\n return output as DiscordContent;\n}\n\n/** Run a Slack template's content over parsed props and check the message it returns. */\nexport function renderSlackContent(\n template: SlackTemplate,\n key: string,\n props: Record<string, unknown>\n): SlackContent {\n const output: unknown = template.content(parseTemplateProps(template, key, props));\n const result = z.safeParse(slackContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('slack', key, 'content', issuesOf(result.error));\n }\n return output as SlackContent;\n}\n\nfunction parsePreview(\n schema: PropsSchema,\n preview: unknown,\n channel: TemplateChannel,\n title: string\n) {\n const result = z.safeParse(schema, preview);\n if (!result.success) {\n throw new TemplateValidationError(\n channel,\n title,\n 'props',\n issuesOf(result.error).map((i) => Object.assign(i, { message: `preview: ${i.message}` }))\n );\n }\n}\n\n/* ---------------------------- supported schemas ---------------------------- */\n\nconst SCALAR_TYPES = new Set(['string', 'number', 'boolean', 'enum']);\n\n/** Throws when `schema` is outside the v1 subset (see the header). */\nexport function assertSupportedSchema(schema: unknown, where: string): void {\n const fail = (reason: string): never => {\n throw new TypeError(`template '${where}': unsupported props schema — ${reason}`);\n };\n const def = (schema as core.$ZodType | undefined)?._zod?.def;\n if (def?.type !== 'object') fail('props must be a z.strictObject({...})');\n const object = def as core.$ZodObjectDef;\n if (object.catchall?._zod.def.type !== 'never') {\n fail(\n 'props must be strict (z.strictObject): unknown fields would be dropped or passed through'\n );\n }\n rejectCustomChecks(object, where, fail);\n for (const [field, value] of Object.entries(object.shape)) {\n let fieldDef = value._zod.def;\n if (fieldDef.type === 'optional') {\n // The wrapper carries checks of its own (`.optional().overwrite(...)`): refuse them too\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n fieldDef = (fieldDef as core.$ZodOptionalDef).innerType._zod.def;\n }\n if (fieldDef.type === 'literal') {\n const values = (fieldDef as core.$ZodLiteralDef<core.util.Literal>).values;\n if (!values.every((v) => ['string', 'number', 'boolean'].includes(typeof v))) {\n fail(`field '${field}' is a literal of a non-scalar value`);\n }\n } else if (!SCALAR_TYPES.has(fieldDef.type)) {\n fail(\n `field '${field}' is ${fieldDef.type}; only string, number, boolean, enum and literal fields (optionally .optional()) are supported`\n );\n }\n if ((fieldDef as { coerce?: boolean }).coerce === true) {\n fail(`field '${field}' coerces its input (z.coerce), which would change what the props mean`);\n }\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n }\n}\n\n/**\n * Checks the subset refuses: `custom` runs arbitrary code (`.refine()`), and\n * `overwrite` changes the value (`.overwrite()`, `.trim()`, `.toLowerCase()`…)\n * — the props are parsed more than once on the way to a send (the validator,\n * then the renderer), so a value-changing check would apply twice and the\n * email would differ from the preview.\n */\nfunction rejectCustomChecks(def: core.$ZodTypeDef, where: string, fail: (reason: string) => never) {\n for (const check of def.checks ?? []) {\n if (check._zod.def.check === 'custom') {\n fail(`'${where}' uses a custom refinement, which the template subset does not support`);\n }\n if (check._zod.def.check === 'overwrite') {\n fail(\n `'${where}' changes the value (.overwrite, .trim, .toLowerCase, …), which the template subset does not support`\n );\n }\n }\n}\n\n/** The scalar props a template accepts, as the IR resolves them before parsing. */\nexport type ResolvedProps = Record<string, ScalarIR | undefined>;\n\n/**\n * The engine's MessageValidator over the template registries: the message's\n * props are parsed by its template (the parsed value is what gets sent); a\n * push's content is also run once and checked, so an invalid notification\n * stops the send before any device; Discord and Slack content likewise. Channels without a\n * registry here (sms, …) pass through to their app-supplied senders.\n */\nexport function registryValidator(registries: {\n email?: Record<string, EmailTemplate> | undefined;\n push?: Record<string, PushTemplate> | undefined;\n discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>> | undefined;\n slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>> | undefined;\n}): {\n validate(message: { channel: string; template: string; props: ResolvedProps }): ResolvedProps;\n} {\n return {\n validate({ channel, template, props }) {\n if (channel === 'email') {\n return parseTemplateProps(\n lookup(registries.email, 'email', template),\n template,\n props\n ) as ResolvedProps;\n }\n if (channel === 'push') {\n const entry = lookup(registries.push, 'push', template);\n renderPushContent(entry, template, props);\n return parseTemplateProps(entry, template, props) as ResolvedProps;\n }\n if (channel === 'discord') {\n const entry = lookup(registries.discord, 'discord', template) as DiscordTemplate;\n renderDiscordContent(entry, template, props);\n return parseTemplateProps(entry, template, props) as ResolvedProps;\n }\n if (channel === 'slack') {\n const entry = lookup(registries.slack, 'slack', template) as SlackTemplate;\n renderSlackContent(entry, template, props);\n return parseTemplateProps(entry, template, props) as ResolvedProps;\n }\n return props;\n },\n };\n}\n\nfunction lookup<T>(registry: Record<string, T> | undefined, channel: string, key: string): T {\n if (registry === undefined || !Object.hasOwn(registry, key)) {\n throw new Error(`${channel} template '${key}' is not registered`);\n }\n return registry[key];\n}\n"],"mappings":";;;AA+IA,SAAgB,gBACd,YACyB;CACzB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,WAAW,WAAW,KAAK;CAC9E,OAAO;EAAE,MAAM;EAAoB,SAAS;EAAG,GAAG;CAAW;AAC/D;;AAGA,SAAgB,cACd,YACuB;CACvB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,SAAS,WAAW,KAAK;CAC5E,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAG,GAAG;CAAW;AAC7D;;AAGA,SAAgB,cACd,YACkB;CAClB,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,SAAS,WAAW,KAAK;CAC5E,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAG,GAAG;CAAW;AAC7D;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;EACA,IAAI,YAAY,SAAS;GACvB,MAAM,QAAQ,OAAO,WAAW,OAAO,SAAS,QAAQ;GACxD,mBAAmB,OAAO,UAAU,KAAK;GACzC,OAAO,mBAAmB,OAAO,UAAU,KAAK;EAClD;EACA,OAAO;CACT,EACF;AACF;AAEA,SAAS,OAAU,UAAyC,SAAiB,KAAgB;CAC3F,IAAI,aAAa,KAAA,KAAa,CAAC,OAAO,OAAO,UAAU,GAAG,GACxD,MAAM,IAAI,MAAM,GAAG,QAAQ,aAAa,IAAI,oBAAoB;CAElE,OAAO,SAAS;AAClB"}
1
+ {"version":3,"file":"templates.mjs","names":[],"sources":["../src/templates.ts"],"sourcesContent":["import type { Block, KnownBlock } from '@slack/types';\nimport type { RESTPostAPIWebhookWithTokenJSONBody } from 'discord-api-types/v10';\nimport * as z from 'zod/mini';\nimport type * as core from 'zod/v4/core';\nimport { type EmailAddress, assertEmailMetadata } from './email';\nimport type { ScalarIR } from './ir';\n\n/**\n * Template definitions — `emailTemplate`, `pushTemplate`, `discordTemplate` and `slackTemplate`. One\n * object per template, identified by its own `id` (unique per channel): workflows take the\n * definition itself (`.email(welcome, props)`), the config registers it, and the IR, the manifest,\n * the senders and the studio all find it by that id. Its Zod `props` schema is the only source of the\n * props type: the DSL's `.email()/.push()` arguments, the `preview`, and the\n * `component`/`content` parameter are all derived from it, and every render\n * parses the props against it first (types alone check nothing at run time).\n *\n * Kept free of React and of any renderer: the definitions are plain data plus\n * a function, so the DSL, the Worker and the studio can all import them; the\n * React rendering lives in `@shware/workflow/react-email`.\n *\n * Supported schemas (v1): a strict object (`z.strictObject`) whose fields are\n * string / number / boolean — optionally as enums or literals, optionally\n * `.optional()`, with the built-in checks (min, email, …). That is exactly\n * what IR message props can carry, and it keeps input and output identical, so\n * producer, studio and sender never disagree about a transformed value.\n * Anything else (nested objects, arrays, null, default/transform/coerce,\n * custom refinements) is rejected when the template is declared.\n */\n\n/** A strict Zod object schema of scalar fields — the accepted shape of `props`. */\nexport type PropsSchema = core.$ZodObject;\n\n/** What a push template's `content` returns: the notification itself. */\nexport interface PushContent {\n title: string;\n body: string;\n /** Rich image URL (iOS attachment / Android BigPicture). */\n image?: string;\n /** Where a tap leads: the page a browser push opens (the site's root when absent). */\n url?: string;\n}\n\n/** A Discord webhook message (`discord-api-types`): content, embeds, username, allowed mentions… */\nexport type DiscordContent = RESTPostAPIWebhookWithTokenJSONBody;\n\n/** A Slack incoming-webhook message: the fallback `text` and, usually, Block Kit `blocks`. */\nexport interface SlackContent {\n /** Shown in notifications and wherever blocks cannot be; required even with blocks. */\n text: string;\n blocks?: (KnownBlock | Block)[];\n username?: string;\n icon_emoji?: string;\n icon_url?: string;\n mrkdwn?: boolean;\n unfurl_links?: boolean;\n unfurl_media?: boolean;\n}\n\n/** The channels a template can be declared for. */\nexport type TemplateChannel = 'email' | 'push' | 'discord' | 'slack';\n\ninterface TemplateBase<S extends PropsSchema> {\n /**\n * Wire identity, unique per channel: message nodes, the template manifest, every send and the\n * studio's preview links name the template by it. Not something to rename for readability —\n * `title` is; the property a registry holds it under is only a JavaScript name.\n */\n readonly id: string;\n /** Display name in the studio (not the email subject, not the notification title). */\n readonly title: string;\n readonly description?: string | undefined;\n readonly props: S;\n /** Sample props for the studio; parsed against `props` when the template is declared. */\n readonly preview: core.input<S>;\n}\n\n/**\n * Who an email comes from and where it leads: declared on each template, never inherited from a\n * global sender. Metadata, not props — the component never receives it; its layout reads the\n * resolved unsubscribe link with `useEmailContext()` (`@shware/workflow/email-context`).\n */\nexport interface EmailMetadata {\n readonly from: EmailAddress;\n /** Where replies go; left out, the email has no Reply-To (it is not `from`, and not inherited). */\n readonly replyTo?: EmailAddress | undefined;\n /** This template's unsubscribe link; left out, the config's `email.unsubscribeUrl` (if any). */\n readonly unsubscribeUrl?: string | undefined;\n}\n\nexport interface EmailTemplate<S extends PropsSchema = PropsSchema>\n extends TemplateBase<S>, EmailMetadata {\n readonly kind: 'email-template';\n readonly version: 1;\n readonly subject: string;\n /** The email body: a component over the parsed props (rendered by `@shware/workflow/react-email`). */\n readonly component: (props: Readonly<core.output<S>>) => unknown;\n}\n\nexport interface PushTemplate<S extends PropsSchema = PropsSchema> extends TemplateBase<S> {\n readonly kind: 'push-template';\n readonly version: 1;\n /** The notification, from the parsed props. Synchronous and pure; its result is checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => PushContent;\n}\n\n/**\n * A message posted to a team channel through an incoming webhook (Discord, Slack). The webhook\n * URL is a secret, so it lives in the Worker's environment and the template reads it from there\n * at send time: `webhook: (env: Env) => env.WEBHOOK_DISCORD_ALERTS`, with `Env` the host's\n * zod-validated environment (`journeyWorker({ env: schema })`). The studio never calls it.\n */\ninterface WebhookTemplateBase<S extends PropsSchema, Env> extends TemplateBase<S> {\n readonly version: 1;\n // A method, so a template typed by the host's Env still fits a registry of any Env\n webhook(env: Env): string | undefined;\n}\n\nexport interface DiscordTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'discord-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => DiscordContent;\n}\n\nexport interface SlackTemplate<\n S extends PropsSchema = PropsSchema,\n Env = Record<string, unknown>,\n> extends WebhookTemplateBase<S, Env> {\n readonly kind: 'slack-template';\n /** The message, from the parsed props. Synchronous and pure; checked before sending. */\n readonly content: (props: Readonly<core.output<S>>) => SlackContent;\n}\n\n/** Strips a Promise return out of the accepted callback types: async content is rejected at the type level. */\ntype Sync<T> = T extends Promise<unknown> ? never : T;\n\nexport interface EmailTemplateDefinition<S extends PropsSchema> {\n id: string;\n title: string;\n description?: string;\n from: EmailAddress;\n replyTo?: EmailAddress;\n unsubscribeUrl?: string;\n props: S;\n subject: string;\n preview: NoInfer<core.input<S>>;\n component: (props: NoInfer<Readonly<core.output<S>>>) => unknown;\n}\n\nexport interface PushTemplateDefinition<S extends PropsSchema, R> {\n id: string;\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<R> & PushContent;\n}\n\nexport interface WebhookTemplateDefinition<S extends PropsSchema, Env, C> {\n id: string;\n title: string;\n description?: string;\n props: S;\n preview: NoInfer<core.input<S>>;\n /** The webhook URL, read from the Worker's environment when a message is sent. */\n webhook: (env: Env) => string | undefined;\n content: (props: NoInfer<Readonly<core.output<S>>>) => Sync<C>;\n}\n\n/** Declare a Discord webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function discordTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, DiscordContent>\n): DiscordTemplate<S, Env> {\n assertTemplateId(definition.id, 'discordTemplate');\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'discord', definition.title);\n return { kind: 'discord-template', version: 1, ...definition };\n}\n\n/** Declare a Slack webhook template. Throws when `props` is unsupported or `preview` does not parse. */\nexport function slackTemplate<S extends PropsSchema, Env = Record<string, unknown>>(\n definition: WebhookTemplateDefinition<S, Env, SlackContent>\n): SlackTemplate<S, Env> {\n assertTemplateId(definition.id, 'slackTemplate');\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'slack', definition.title);\n return { kind: 'slack-template', version: 1, ...definition };\n}\n\n/**\n * Declare an email template. Throws when `from` is missing or invalid, `replyTo` or `unsubscribeUrl`\n * is invalid, `props` uses an unsupported schema or `preview` does not parse.\n */\nexport function emailTemplate<S extends PropsSchema>(\n definition: EmailTemplateDefinition<S>\n): EmailTemplate<S> {\n assertTemplateId(definition.id, 'emailTemplate');\n assertEmailMetadata(definition, `emailTemplate('${definition.id}')`);\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'email', definition.title);\n return { kind: 'email-template', version: 1, ...definition };\n}\n\n/** Declare a push template. Throws when `props` uses an unsupported schema or `preview` does not parse. */\nexport function pushTemplate<S extends PropsSchema, R extends PushContent>(\n definition: PushTemplateDefinition<S, R>\n): PushTemplate<S> {\n assertTemplateId(definition.id, 'pushTemplate');\n assertSupportedSchema(definition.props, definition.title);\n parsePreview(definition.props, definition.preview, 'push', definition.title);\n return { kind: 'push-template', version: 1, ...definition } as unknown as PushTemplate<S>;\n}\n\nfunction assertTemplateId(id: unknown, factory: string): void {\n if (!isTemplateId(id)) {\n throw new TypeError(`${factory}(): 'id' must be a non-empty string`);\n }\n}\n\nfunction isTemplateId(id: unknown): id is string {\n return typeof id === 'string' && id.trim() !== '';\n}\n\nexport function isEmailTemplate(value: unknown): value is EmailTemplate {\n return isMarked(value, 'email-template');\n}\n\nexport function isPushTemplate(value: unknown): value is PushTemplate {\n return isMarked(value, 'push-template');\n}\n\nexport function isDiscordTemplate(value: unknown): value is DiscordTemplate {\n return isMarked(value, 'discord-template');\n}\n\nexport function isSlackTemplate(value: unknown): value is SlackTemplate {\n return isMarked(value, 'slack-template');\n}\n\n/** Any declared template. */\nexport type AnyTemplate = EmailTemplate | PushTemplate | DiscordTemplate | SlackTemplate;\n\nexport const CHANNEL_OF: Record<AnyTemplate['kind'], TemplateChannel> = {\n 'email-template': 'email',\n 'push-template': 'push',\n 'discord-template': 'discord',\n 'slack-template': 'slack',\n};\n\nfunction isMarked(value: unknown, kind: string): boolean {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === kind &&\n (value as { version?: unknown }).version === 1\n );\n}\n\n/** Any template definition, whatever its channel. */\nexport function isTemplate(value: unknown): value is AnyTemplate {\n return (\n typeof value === 'object' &&\n value !== null &&\n Object.hasOwn(CHANNEL_OF, (value as { kind?: unknown }).kind as string) &&\n (value as { version?: unknown }).version === 1\n );\n}\n\n/* --------------------------------- registry -------------------------------- */\n\n/**\n * The template registry: per channel, the definitions the project registers. Each channel is a\n * plain object whose property names are JavaScript names only — a template is identified by its\n * own `id` (`indexTemplates`).\n */\nexport interface TemplateRegistry {\n readonly email?: Readonly<Record<string, EmailTemplate>>;\n readonly push?: Readonly<Record<string, PushTemplate>>;\n /** Discord webhook templates, each typed by the host's Env its `webhook` reads. */\n readonly discord?: Readonly<Record<string, DiscordTemplate<PropsSchema, never>>>;\n readonly slack?: Readonly<Record<string, SlackTemplate<PropsSchema, never>>>;\n}\n\n/** The template a channel's registry holds. */\nexport interface ChannelTemplate {\n email: EmailTemplate;\n push: PushTemplate;\n discord: DiscordTemplate;\n slack: SlackTemplate;\n}\n\nconst IS_TEMPLATE: Record<TemplateChannel, (value: unknown) => boolean> = {\n email: isEmailTemplate,\n push: isPushTemplate,\n discord: isDiscordTemplate,\n slack: isSlackTemplate,\n};\n\n/**\n * A channel's registry by template id — how everything that turns an id back into a definition\n * (the compiler, the validator, the renderers, the senders, the studio) looks it up. Throws when\n * an entry is not a template of the channel, has no id, or shares its id with another entry: an id\n * is registered once per channel, so two registrations (even of the same object) are an error,\n * not a silent last-wins. Insertion order is the registry's.\n */\nexport function indexTemplates<C extends TemplateChannel>(\n channel: C,\n registry: Readonly<Record<string, unknown>> | undefined\n): ReadonlyMap<string, ChannelTemplate[C]> {\n const index = new Map<string, ChannelTemplate[C]>();\n const paths = new Map<string, string>();\n for (const [name, entry] of Object.entries(registry ?? {})) {\n const path = `templates.${channel}.${name}`;\n if (!IS_TEMPLATE[channel](entry)) {\n throw new TypeError(`${path} is not a ${channel} template`);\n }\n const id = (entry as AnyTemplate).id;\n if (!isTemplateId(id)) throw new TypeError(`${path} has no id`);\n const previous = paths.get(id);\n if (previous !== undefined) {\n throw new TypeError(\n `${channel} template id '${id}' is registered twice: ${previous} and ${path}`\n );\n }\n paths.set(id, path);\n index.set(id, entry as ChannelTemplate[C]);\n }\n return index;\n}\n\n/** A registered template by id; throws naming the channel and id when there is none. */\nexport function lookupTemplate<T>(index: ReadonlyMap<string, T>, channel: string, id: string): T {\n const template = index.get(id);\n if (template === undefined) throw new Error(`${channel} template '${id}' is not registered`);\n return template;\n}\n\n/* ------------------------------- validation -------------------------------- */\n\n/** One failed field, with the dotted path the studio and the logs show. */\nexport interface TemplateIssue {\n path: string;\n message: string;\n}\n\n/**\n * A template refused its input (`phase: 'props'` — the component/content was\n * never called) or its content function returned something that is not a\n * notification (`phase: 'content'` — called, but nothing is sent). Never a\n * provider failure: a sender must not read it as a dead device token.\n */\nexport class TemplateValidationError extends Error {\n override readonly name = 'TemplateValidationError';\n constructor(\n readonly channel: TemplateChannel,\n readonly template: string,\n readonly phase: 'props' | 'content',\n readonly issues: TemplateIssue[]\n ) {\n super(\n `${channel} template '${template}' ${phase === 'props' ? 'rejected its props' : 'returned invalid content'}: ${issues\n .map((i) => `${i.path || '(root)'} ${i.message}`)\n .join('; ')}`\n );\n }\n}\n\nfunction issuesOf(error: core.$ZodError): TemplateIssue[] {\n return error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n}\n\n/**\n * Parse message props against a template's schema and return the parsed value\n * — the only value anything downstream may use. Throws TemplateValidationError.\n */\nexport function parseTemplateProps<S extends PropsSchema>(\n template: EmailTemplate<S> | PushTemplate<S> | DiscordTemplate<S> | SlackTemplate<S>,\n props: Record<string, unknown>\n): core.output<S> {\n const channel = CHANNEL_OF[template.kind];\n const result = z.safeParse(template.props, props);\n if (!result.success) {\n throw new TemplateValidationError(channel, template.id, 'props', issuesOf(result.error));\n }\n return result.data;\n}\n\nconst pushContentSchema = z.strictObject({\n title: z.string(),\n body: z.string(),\n image: z.optional(z.string()),\n url: z.optional(z.string()),\n});\n\n/** Run a push template's content over parsed props and check the notification it returns. */\nexport function renderPushContent(\n template: PushTemplate,\n props: Record<string, unknown>\n): PushContent {\n const parsed = parseTemplateProps(template, props);\n const output: unknown = template.content(parsed);\n // A Promise (async content smuggled past the types) is an object without title/body: refused here\n const result = z.safeParse(pushContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('push', template.id, 'content', issuesOf(result.error));\n }\n return result.data;\n}\n\n/**\n * What a Discord webhook accepts at all: something to show (content, an embed, a poll or\n * components) and content within Discord's 2000 characters. The rest of the body is Discord's to\n * judge; its types come from `discord-api-types`.\n */\nconst discordContentSchema = z.looseObject({\n content: z.optional(z.string().check(z.maxLength(2000))),\n embeds: z.optional(z.array(z.looseObject({}))),\n});\n\nconst slackContentSchema = z.looseObject({\n text: z.string().check(z.minLength(1)),\n blocks: z.optional(z.array(z.looseObject({ type: z.string() }))),\n});\n\n/** Run a Discord template's content over parsed props and check the message it returns. */\nexport function renderDiscordContent(\n template: DiscordTemplate,\n props: Record<string, unknown>\n): DiscordContent {\n const output: unknown = template.content(parseTemplateProps(template, props));\n const result = z.safeParse(discordContentSchema, output);\n const empty =\n result.success &&\n !result.data.content &&\n (result.data.embeds?.length ?? 0) === 0 &&\n (output as { poll?: unknown; components?: unknown[] }).poll === undefined &&\n ((output as { components?: unknown[] }).components?.length ?? 0) === 0;\n if (!result.success || empty) {\n const issues = result.success\n ? [{ path: '', message: 'a Discord message needs content, an embed, a poll or components' }]\n : issuesOf(result.error);\n throw new TemplateValidationError('discord', template.id, 'content', issues);\n }\n return output as DiscordContent;\n}\n\n/** Run a Slack template's content over parsed props and check the message it returns. */\nexport function renderSlackContent(\n template: SlackTemplate,\n props: Record<string, unknown>\n): SlackContent {\n const output: unknown = template.content(parseTemplateProps(template, props));\n const result = z.safeParse(slackContentSchema, output);\n if (!result.success) {\n throw new TemplateValidationError('slack', template.id, 'content', issuesOf(result.error));\n }\n return output as SlackContent;\n}\n\nfunction parsePreview(\n schema: PropsSchema,\n preview: unknown,\n channel: TemplateChannel,\n title: string\n) {\n const result = z.safeParse(schema, preview);\n if (!result.success) {\n throw new TemplateValidationError(\n channel,\n title,\n 'props',\n issuesOf(result.error).map((i) => Object.assign(i, { message: `preview: ${i.message}` }))\n );\n }\n}\n\n/* ---------------------------- supported schemas ---------------------------- */\n\nconst SCALAR_TYPES = new Set(['string', 'number', 'boolean', 'enum']);\n\n/** Throws when `schema` is outside the v1 subset (see the header). */\nexport function assertSupportedSchema(schema: unknown, where: string): void {\n const fail = (reason: string): never => {\n throw new TypeError(`template '${where}': unsupported props schema — ${reason}`);\n };\n const def = (schema as core.$ZodType | undefined)?._zod?.def;\n if (def?.type !== 'object') fail('props must be a z.strictObject({...})');\n const object = def as core.$ZodObjectDef;\n if (object.catchall?._zod.def.type !== 'never') {\n fail(\n 'props must be strict (z.strictObject): unknown fields would be dropped or passed through'\n );\n }\n rejectCustomChecks(object, where, fail);\n for (const [field, value] of Object.entries(object.shape)) {\n let fieldDef = value._zod.def;\n if (fieldDef.type === 'optional') {\n // The wrapper carries checks of its own (`.optional().overwrite(...)`): refuse them too\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n fieldDef = (fieldDef as core.$ZodOptionalDef).innerType._zod.def;\n }\n if (fieldDef.type === 'literal') {\n const values = (fieldDef as core.$ZodLiteralDef<core.util.Literal>).values;\n if (!values.every((v) => ['string', 'number', 'boolean'].includes(typeof v))) {\n fail(`field '${field}' is a literal of a non-scalar value`);\n }\n } else if (!SCALAR_TYPES.has(fieldDef.type)) {\n fail(\n `field '${field}' is ${fieldDef.type}; only string, number, boolean, enum and literal fields (optionally .optional()) are supported`\n );\n }\n if ((fieldDef as { coerce?: boolean }).coerce === true) {\n fail(`field '${field}' coerces its input (z.coerce), which would change what the props mean`);\n }\n rejectCustomChecks(fieldDef, `${where}.${field}`, fail);\n }\n}\n\n/**\n * Checks the subset refuses: `custom` runs arbitrary code (`.refine()`), and\n * `overwrite` changes the value (`.overwrite()`, `.trim()`, `.toLowerCase()`…)\n * — the props are parsed more than once on the way to a send (the validator,\n * then the renderer), so a value-changing check would apply twice and the\n * email would differ from the preview.\n */\nfunction rejectCustomChecks(def: core.$ZodTypeDef, where: string, fail: (reason: string) => never) {\n for (const check of def.checks ?? []) {\n if (check._zod.def.check === 'custom') {\n fail(`'${where}' uses a custom refinement, which the template subset does not support`);\n }\n if (check._zod.def.check === 'overwrite') {\n fail(\n `'${where}' changes the value (.overwrite, .trim, .toLowerCase, …), which the template subset does not support`\n );\n }\n }\n}\n\n/** The scalar props a template accepts, as the IR resolves them before parsing. */\nexport type ResolvedProps = Record<string, ScalarIR | undefined>;\n\n/**\n * The engine's MessageValidator over the template registries: the message's\n * props are parsed by its template (the parsed value is what gets sent); a\n * push's content is also run once and checked, so an invalid notification\n * stops the send before any device; Discord and Slack content likewise. Channels without a\n * registry here (sms, …) pass through to their app-supplied senders.\n */\nexport function registryValidator(registry: TemplateRegistry): {\n validate(message: { channel: string; template: string; props: ResolvedProps }): ResolvedProps;\n} {\n const email = indexTemplates('email', registry.email);\n const push = indexTemplates('push', registry.push);\n const discord = indexTemplates('discord', registry.discord);\n const slack = indexTemplates('slack', registry.slack);\n return {\n validate({ channel, template, props }) {\n if (channel === 'email') {\n const entry = lookupTemplate(email, 'email', template);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n if (channel === 'push') {\n const entry = lookupTemplate(push, 'push', template);\n renderPushContent(entry, props);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n if (channel === 'discord') {\n const entry = lookupTemplate(discord, 'discord', template);\n renderDiscordContent(entry, props);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n if (channel === 'slack') {\n const entry = lookupTemplate(slack, 'slack', template);\n renderSlackContent(entry, props);\n return parseTemplateProps(entry, props) as ResolvedProps;\n }\n return props;\n },\n };\n}\n"],"mappings":";;;;AA4KA,SAAgB,gBACd,YACyB;CACzB,iBAAiB,WAAW,IAAI,iBAAiB;CACjD,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,WAAW,WAAW,KAAK;CAC9E,OAAO;EAAE,MAAM;EAAoB,SAAS;EAAG,GAAG;CAAW;AAC/D;;AAGA,SAAgB,cACd,YACuB;CACvB,iBAAiB,WAAW,IAAI,eAAe;CAC/C,sBAAsB,WAAW,OAAO,WAAW,KAAK;CACxD,aAAa,WAAW,OAAO,WAAW,SAAS,SAAS,WAAW,KAAK;CAC5E,OAAO;EAAE,MAAM;EAAkB,SAAS;EAAG,G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,OAAO;CAC1D,MAAM,QAAQ,eAAe,SAAS,SAAS,KAAK;CACpD,OAAO,EACL,SAAS,EAAE,SAAS,UAAU,SAAS;EACrC,IAAI,YAAY,SAEd,OAAO,mBADO,eAAe,OAAO,SAAS,QACf,GAAG,KAAK;EAExC,IAAI,YAAY,QAAQ;GACtB,MAAM,QAAQ,eAAe,MAAM,QAAQ,QAAQ;GACnD,kBAAkB,OAAO,KAAK;GAC9B,OAAO,mBAAmB,OAAO,KAAK;EACxC;EACA,IAAI,YAAY,WAAW;GACzB,MAAM,QAAQ,eAAe,SAAS,WAAW,QAAQ;GACzD,qBAAqB,OAAO,KAAK;GACjC,OAAO,mBAAmB,OAAO,KAAK;EACxC;EACA,IAAI,YAAY,SAAS;GACvB,MAAM,QAAQ,eAAe,OAAO,SAAS,QAAQ;GACrD,mBAAmB,OAAO,KAAK;GAC/B,OAAO,mBAAmB,OAAO,KAAK;EACxC;EACA,OAAO;CACT,EACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/workflow",
3
- "version": "0.4.0",
3
+ "version": "2.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ShwareHQ/shware-sdk.git"
@@ -83,6 +83,16 @@
83
83
  "default": "./dist/react-email.cjs"
84
84
  }
85
85
  },
86
+ "./email-context": {
87
+ "import": {
88
+ "types": "./dist/email-context.d.mts",
89
+ "default": "./dist/email-context.mjs"
90
+ },
91
+ "require": {
92
+ "types": "./dist/email-context.d.cts",
93
+ "default": "./dist/email-context.cjs"
94
+ }
95
+ },
86
96
  "./push": {
87
97
  "import": {
88
98
  "types": "./dist/push.d.mts",