@shware/workflow-ui 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/workflow-ui",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ShwareHQ/shware-sdk.git"
@@ -38,43 +38,41 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@floating-ui/react": "^0.27.20",
41
- "@react-email/render": "^2.1.0",
42
- "@shware/workflow": "0.3.0",
41
+ "@fontsource-variable/inter": "^5.3.0",
42
+ "@react-email/render": "^2.1.1",
43
+ "@shware/workflow": "1.0.0",
43
44
  "@tailwindcss/vite": "^4.3.3",
44
- "@tanstack/react-query": "^5.104.0",
45
- "@tanstack/react-router": "^1.170.39",
46
- "@vitejs/plugin-react": "^6.1.1",
45
+ "@tanstack/react-query": "^5.104.3",
46
+ "@tanstack/react-router": "^1.170.45",
47
+ "@vitejs/plugin-react": "^6.1.2",
47
48
  "@xyflow/react": "^12.12.0",
48
49
  "clsx": "^2.1.1",
49
- "i18next": "^26.4.2",
50
+ "i18next": "^26.4.7",
50
51
  "i18next-browser-languagedetector": "^8.2.1",
51
- "lucide-react": "^1.48.0",
52
- "react-i18next": "^17.0.15",
52
+ "lucide-react": "^1.59.0",
53
+ "react-i18next": "^17.0.20",
53
54
  "sonner": "^2.0.8",
54
55
  "tailwind-merge": "^3.7.0",
55
56
  "tailwindcss": "^4.3.3",
56
- "vite": "^8.3.1",
57
+ "vite": "^8.3.4",
57
58
  "vite-plugin-svgr": "^5.2.0"
58
59
  },
59
60
  "devDependencies": {
60
- "@fontsource-variable/inter": "^5.3.0",
61
61
  "@repo/typescript-config": "0.0.0",
62
- "@tanstack/react-devtools": "^0.10.13",
63
- "@tanstack/react-query-devtools": "^5.104.0",
64
- "@tanstack/react-router-devtools": "^1.167.2",
62
+ "@tanstack/react-query-devtools": "^5.104.3",
65
63
  "@testing-library/react": "^16.3.3",
66
- "@testing-library/user-event": "^14.6.7",
67
- "@types/node": "^26.6.3",
64
+ "@testing-library/user-event": "^14.6.8",
65
+ "@types/node": "^26.6.5",
68
66
  "@types/react": "^19.3.0",
69
67
  "@types/react-dom": "^19.3.0",
70
68
  "country-flag-icons": "^1.6.20",
71
- "jsdom": "^30.1.1",
69
+ "jsdom": "^30.1.3",
72
70
  "postgres": "^3.4.9",
73
- "react": "^19.3.0",
74
- "react-dom": "^19.3.0",
71
+ "react": "^19.3.1",
72
+ "react-dom": "^19.3.1",
75
73
  "typescript": "^7.0.2",
76
- "vitest": "^5.0.2",
77
- "zod": "^4.6.5"
74
+ "vitest": "^5.0.5",
75
+ "zod": "^4.6.7"
78
76
  },
79
77
  "peerDependencies": {
80
78
  "postgres": ">=3.4.0",
@@ -31,7 +31,7 @@ export function useEmailPreview(mod: EmailTemplate | undefined, key: string, pro
31
31
  queryKey: ['email-preview', key, entryIdentity(mod), props ?? null],
32
32
  queryFn: async (): Promise<EmailPreviewResult> => {
33
33
  if (mod === undefined) throw new Error(`no email registered for '${key}'`);
34
- const prepared = prepareEmail(mod, key, props);
34
+ const prepared = prepareEmail(mod, props);
35
35
  if (!prepared.ok) return { status: 'invalid', failure: prepared.failure };
36
36
  const { component, props: parsed, subject } = prepared.email;
37
37
  try {
@@ -256,9 +256,7 @@ function CanvasTab() {
256
256
  const pushModule =
257
257
  message?.channel === 'push' ? lookup(config.pushes, message.template) : undefined;
258
258
  const push =
259
- message !== undefined && pushModule !== undefined
260
- ? resolvePush(pushModule, message.template)
261
- : undefined;
259
+ message !== undefined && pushModule !== undefined ? resolvePush(pushModule) : undefined;
262
260
 
263
261
  if (ir === undefined) return null;
264
262
 
@@ -293,7 +293,7 @@ export function TemplatesPage({
293
293
  */
294
294
  const pushResolution =
295
295
  active !== undefined && activePush !== undefined
296
- ? resolvePush(activePush, active.key, previewProps)
296
+ ? resolvePush(activePush, previewProps)
297
297
  : undefined;
298
298
  const push =
299
299
  propsFailure === undefined && pushResolution?.ok === true ? pushResolution.push : undefined;
@@ -303,11 +303,11 @@ export function TemplatesPage({
303
303
  /* A chat message, from the same checked content a send posts. */
304
304
  const discordResolution =
305
305
  active !== undefined && activeDiscord !== undefined
306
- ? resolveDiscord(activeDiscord, active.key, previewProps)
306
+ ? resolveDiscord(activeDiscord, previewProps)
307
307
  : undefined;
308
308
  const slackResolution =
309
309
  active !== undefined && activeSlack !== undefined
310
- ? resolveSlack(activeSlack, active.key, previewProps)
310
+ ? resolveSlack(activeSlack, previewProps)
311
311
  : undefined;
312
312
  const chatResolution = discordResolution ?? slackResolution;
313
313
  const chatFailure =
package/src/config.ts CHANGED
@@ -270,13 +270,13 @@ export interface ResolvedStudioConfig {
270
270
  title?: string;
271
271
  /** Compiled workflows, keyed by workflow name (empty when `error` is set). */
272
272
  workflows: Record<string, WorkflowIR>;
273
- /** The project's email registry (empty if none). */
273
+ /** The project's email templates by id (empty if none). */
274
274
  emails: Record<string, EmailTemplate>;
275
- /** The project's push registry (empty if none). */
275
+ /** The project's push templates by id (empty if none). */
276
276
  pushes: Record<string, PushTemplate>;
277
- /** The project's Discord webhook registry (empty if none). */
277
+ /** The project's Discord webhook templates by id (empty if none). */
278
278
  discords: Record<string, DiscordTemplate>;
279
- /** The project's Slack webhook registry (empty if none). */
279
+ /** The project's Slack webhook templates by id (empty if none). */
280
280
  slacks: Record<string, SlackTemplate>;
281
281
  /** Compiled named segments. */
282
282
  segments: SegmentIR[];
@@ -80,8 +80,8 @@ class StudioLoadError extends Error {}
80
80
 
81
81
  /**
82
82
  * The module that exports `registry`, by identity: the registry itself, or
83
- * else an exported `{ email, push }` holding it (`export const registry =
84
- * { email: {...}, push: {...} }` next to `t = templates(registry)`).
83
+ * else an exported `{ email, push }` holding it (`export const templates =
84
+ * { email, push }`).
85
85
  * workflow.config.ts itself is never a candidate: importing it would bring the
86
86
  * whole config (and everything it imports) into the browser. Sorted by path,
87
87
  * so the answer does not depend on load order.
@@ -125,7 +125,7 @@ function locate(
125
125
  throw new StudioLoadError(
126
126
  `templates.${channel} is not exported from a module of its own. Export the registry ` +
127
127
  `(e.g. \`export const ${channel} = {...}\` in src/${channel}/index.ts, or ` +
128
- '`export const registry = { email, push }` in src/templates.ts) ' +
128
+ '`export const templates = { email, push }` in src/templates.ts) ' +
129
129
  'and import it into workflow.config.ts — the studio loads that module, never the config, into the browser.'
130
130
  );
131
131
  }
@@ -232,7 +232,8 @@ export type StatsMethod = (typeof STATS_METHODS)[number];
232
232
 
233
233
  /**
234
234
  * The module the browser imports as `virtual:workflow-config`: the payload as
235
- * a JSON literal, the two registries as imports from their own modules, and
235
+ * a JSON literal, the template registries as imports from their own modules
236
+ * (re-keyed by template id), and
236
237
  * the stats source as calls to the studio's server, one per method
237
238
  * workflow.stats.ts defines — the source itself runs there, next to the
238
239
  * database and the secrets it reads with, never in the browser.
@@ -259,7 +260,7 @@ export function virtualModule(
259
260
  const registries = (Object.keys(CHANNELS) as Channel[]).map((channel) => {
260
261
  const ref = snapshot.registries[channel];
261
262
  const { field } = CHANNELS[channel];
262
- return ` ${field}: ${ref === undefined ? '{}' : importOf(ref, field)},`;
263
+ return ` ${field}: ${ref === undefined ? '{}' : `byId(${importOf(ref, field)})`},`;
263
264
  });
264
265
  const stats =
265
266
  statsMethods === undefined
@@ -281,6 +282,8 @@ const call = (method) => async (...args) => {
281
282
  };`;
282
283
 
283
284
  return `${imports.join('\n')}${call}
285
+ /* The views look a template up by its id, the name messages use, never by the property holding it. */
286
+ const byId = (registry) => Object.fromEntries(Object.values(registry).map((t) => [t.id, t]));
284
287
  const payload = ${JSON.stringify(snapshot.payload)};
285
288
  export default {
286
289
  ...payload,
@@ -120,9 +120,9 @@ export type EmailPreparation =
120
120
  * hand the component the parsed value — or refuse, with the field paths, and
121
121
  * render nothing.
122
122
  */
123
- export function prepareEmail(entry: EmailTemplate, key: string, props?: Props): EmailPreparation {
123
+ export function prepareEmail(entry: EmailTemplate, props?: Props): EmailPreparation {
124
124
  try {
125
- const parsed = parseTemplateProps(entry, key, props ?? previewPropsOf(entry));
125
+ const parsed = parseTemplateProps(entry, props ?? previewPropsOf(entry));
126
126
  return {
127
127
  ok: true,
128
128
  email: {
@@ -152,9 +152,9 @@ export type PushResolution =
152
152
  * over the parsed props, through the SDK (output checked, nothing
153
153
  * placeholder-filled afterwards).
154
154
  */
155
- export function resolvePush(entry: PushTemplate, key: string, props?: Props): PushResolution {
155
+ export function resolvePush(entry: PushTemplate, props?: Props): PushResolution {
156
156
  try {
157
- return { ok: true, push: renderPushContent(entry, key, props ?? previewPropsOf(entry)) };
157
+ return { ok: true, push: renderPushContent(entry, props ?? previewPropsOf(entry)) };
158
158
  } catch (error) {
159
159
  return { ok: false, failure: failureOf(error, 'content') };
160
160
  }
@@ -171,22 +171,18 @@ export type SlackResolution =
171
171
  | { ok: false; failure: TemplateFailure };
172
172
 
173
173
  /** The Discord message a template posts for some props, checked like a send checks it. */
174
- export function resolveDiscord(
175
- entry: DiscordTemplate,
176
- key: string,
177
- props?: Props
178
- ): DiscordResolution {
174
+ export function resolveDiscord(entry: DiscordTemplate, props?: Props): DiscordResolution {
179
175
  try {
180
- return { ok: true, message: renderDiscordContent(entry, key, props ?? previewPropsOf(entry)) };
176
+ return { ok: true, message: renderDiscordContent(entry, props ?? previewPropsOf(entry)) };
181
177
  } catch (error) {
182
178
  return { ok: false, failure: failureOf(error, 'content') };
183
179
  }
184
180
  }
185
181
 
186
182
  /** The Slack message a template posts for some props, checked like a send checks it. */
187
- export function resolveSlack(entry: SlackTemplate, key: string, props?: Props): SlackResolution {
183
+ export function resolveSlack(entry: SlackTemplate, props?: Props): SlackResolution {
188
184
  try {
189
- return { ok: true, message: renderSlackContent(entry, key, props ?? previewPropsOf(entry)) };
185
+ return { ok: true, message: renderSlackContent(entry, props ?? previewPropsOf(entry)) };
190
186
  } catch (error) {
191
187
  return { ok: false, failure: failureOf(error, 'content') };
192
188
  }