@shware/workflow-ui 0.1.3 → 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/README.md +6 -8
- package/dist/cli.mjs +8 -5
- package/dist/cli.mjs.map +1 -1
- package/dist/config.d.mts +4 -4
- package/dist/config.mjs.map +1 -1
- package/dist/index.mjs +9 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/app/email-preview.ts +1 -1
- package/src/app/routes/workflows.tsx +1 -3
- package/src/components/templates-page.tsx +3 -3
- package/src/config.ts +4 -4
- package/src/server/project.ts +8 -5
- package/src/utils/template-content.ts +8 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shware/workflow-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ShwareHQ/shware-sdk.git"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@floating-ui/react": "^0.27.20",
|
|
41
41
|
"@fontsource-variable/inter": "^5.3.0",
|
|
42
42
|
"@react-email/render": "^2.1.1",
|
|
43
|
-
"@shware/workflow": "0.
|
|
43
|
+
"@shware/workflow": "1.0.0",
|
|
44
44
|
"@tailwindcss/vite": "^4.3.3",
|
|
45
45
|
"@tanstack/react-query": "^5.104.3",
|
|
46
46
|
"@tanstack/react-router": "^1.170.45",
|
package/src/app/email-preview.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
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,
|
|
306
|
+
? resolveDiscord(activeDiscord, previewProps)
|
|
307
307
|
: undefined;
|
|
308
308
|
const slackResolution =
|
|
309
309
|
active !== undefined && activeSlack !== undefined
|
|
310
|
-
? resolveSlack(activeSlack,
|
|
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
|
|
273
|
+
/** The project's email templates by id (empty if none). */
|
|
274
274
|
emails: Record<string, EmailTemplate>;
|
|
275
|
-
/** The project's push
|
|
275
|
+
/** The project's push templates by id (empty if none). */
|
|
276
276
|
pushes: Record<string, PushTemplate>;
|
|
277
|
-
/** The project's Discord webhook
|
|
277
|
+
/** The project's Discord webhook templates by id (empty if none). */
|
|
278
278
|
discords: Record<string, DiscordTemplate>;
|
|
279
|
-
/** The project's Slack webhook
|
|
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[];
|
package/src/server/project.ts
CHANGED
|
@@ -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
|
|
84
|
-
* { email
|
|
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
|
|
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
|
|
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,
|
|
123
|
+
export function prepareEmail(entry: EmailTemplate, props?: Props): EmailPreparation {
|
|
124
124
|
try {
|
|
125
|
-
const parsed = parseTemplateProps(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,
|
|
155
|
+
export function resolvePush(entry: PushTemplate, props?: Props): PushResolution {
|
|
156
156
|
try {
|
|
157
|
-
return { ok: true, push: renderPushContent(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,
|
|
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,
|
|
183
|
+
export function resolveSlack(entry: SlackTemplate, props?: Props): SlackResolution {
|
|
188
184
|
try {
|
|
189
|
-
return { ok: true, message: renderSlackContent(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
|
}
|