@lovable.dev/workflows-sdk 0.0.0-dev.6 → 0.0.0-dev.7
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 +40 -13
- package/dist/vite.d.ts +2 -4
- package/dist/vite.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -300,32 +300,60 @@ partial graph. A handler with no steps can have an empty graph.
|
|
|
300
300
|
|
|
301
301
|
## Run endpoint (TanStack Start)
|
|
302
302
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
303
|
+
The same `workflowsPlugin` that writes the manifests also emits one dynamic
|
|
304
|
+
route, `src/routes/api/workflows/$workflowId.ts`, serving every registered
|
|
305
|
+
workflow. There is no opt-in: a declared workflow with no endpoint cannot run.
|
|
306
|
+
One plugin and one `entry` cover both, so a manifest can never describe a
|
|
307
|
+
collection the route does not serve:
|
|
307
308
|
|
|
308
309
|
```ts
|
|
309
310
|
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
|
310
311
|
import { workflowsPlugin } from "@lovable.dev/workflows-sdk/vite";
|
|
311
312
|
|
|
312
313
|
export default defineConfig({
|
|
313
|
-
plugins: [workflowsPlugin(
|
|
314
|
+
plugins: [workflowsPlugin(), tanstackStart()],
|
|
314
315
|
});
|
|
315
316
|
```
|
|
316
317
|
|
|
317
|
-
`
|
|
318
|
-
|
|
319
|
-
|
|
318
|
+
A missing `entry` file is the only thing that suppresses the route: an app with
|
|
319
|
+
no collection gets no endpoint.
|
|
320
|
+
|
|
321
|
+
### The route is unauthenticated
|
|
322
|
+
|
|
323
|
+
**Any caller who reaches the route can run any declared workflow.** The SDK
|
|
324
|
+
ships no request authentication today; signed invocation is the next piece of
|
|
325
|
+
work on this endpoint. Until it lands, treat the endpoint as public and keep
|
|
326
|
+
anything a stranger must not trigger — spend, mutation of another user's data,
|
|
327
|
+
outbound mail — out of a declared workflow, or guard it inside the handler.
|
|
328
|
+
|
|
329
|
+
Reachability is the lever an app has in the meantime. Public apps expose the
|
|
330
|
+
route to the internet. Workspace and private apps are gated by the Lovable host,
|
|
331
|
+
which is why `path` matters (below).
|
|
332
|
+
|
|
333
|
+
### Relocating the route with `path`
|
|
334
|
+
|
|
335
|
+
`path` sets the URL prefix; the workflow ID is appended as a dynamic segment,
|
|
336
|
+
and the emitted file name follows the path. Workspace and private apps reach
|
|
337
|
+
anonymous traffic only under an `/api/public` prefix — everything else is
|
|
338
|
+
blocked by the host before it reaches the app — so those projects must move the
|
|
339
|
+
route there for it to be reachable at all:
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
workflowsPlugin({ path: "/api/public/workflows" });
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
That emits `src/routes/api/public/workflows/$workflowId.ts` and serves
|
|
346
|
+
`POST /api/public/workflows/{workflow-id}`. The trade is explicit: the prefix
|
|
347
|
+
that makes the route reachable also makes it anonymously reachable.
|
|
320
348
|
|
|
321
349
|
The emitted file is thin — it imports the collection and mounts
|
|
322
350
|
`createTanStackWorkflowHandler` from `@lovable.dev/workflows-sdk/stacks/tanstack`
|
|
323
351
|
as the route's `POST` handler. All runtime logic stays in the package. The file
|
|
324
352
|
carries a generated banner, which is the plugin's ownership token: it rewrites
|
|
325
|
-
and deletes only files that have it, and deletes its own orphans when `path
|
|
326
|
-
`workflowIdParam
|
|
327
|
-
|
|
328
|
-
|
|
353
|
+
and deletes only files that have it, and deletes its own orphans when `path` or
|
|
354
|
+
`workflowIdParam` changes. Delete the banner line to take the route over — the
|
|
355
|
+
plugin then leaves that file alone, and the build keeps working. That is also
|
|
356
|
+
the supported way to add a check of your own in front of the handler.
|
|
329
357
|
|
|
330
358
|
| Option | Default | Meaning |
|
|
331
359
|
| --- | --- | --- |
|
|
@@ -333,7 +361,6 @@ working.
|
|
|
333
361
|
| `routesDir` | `src/routes` | Where the route file is written |
|
|
334
362
|
| `path` | `/api/workflows` | URL prefix; the workflow ID is the next segment |
|
|
335
363
|
| `workflowIdParam` | `workflowId` | Route parameter, and the emitted file name |
|
|
336
|
-
| `runRoute` | `false` | Emit the route at all |
|
|
337
364
|
|
|
338
365
|
### Calling it
|
|
339
366
|
|
package/dist/vite.d.ts
CHANGED
|
@@ -10,12 +10,10 @@ interface WorkflowsPluginOptions {
|
|
|
10
10
|
path?: string;
|
|
11
11
|
/** Route parameter carrying the workflow ID. @default "workflowId" */
|
|
12
12
|
workflowIdParam?: string;
|
|
13
|
-
/** @default false */
|
|
14
|
-
runRoute?: boolean;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
|
-
* Build the collection's manifests and
|
|
18
|
-
*
|
|
15
|
+
* Build the collection's manifests and emit the route serving them; one `entry`
|
|
16
|
+
* feeds both, so the two can never describe different sets.
|
|
19
17
|
*/
|
|
20
18
|
declare function workflowsPlugin(options?: WorkflowsPluginOptions): Plugin;
|
|
21
19
|
//#endregion
|
package/dist/vite.js
CHANGED
|
@@ -65,7 +65,8 @@ function buildRouteSource(routeFile, routeLiteral, param, entry, root) {
|
|
|
65
65
|
return `${GENERATED_BANNER}
|
|
66
66
|
// route: ${routeLiteral}
|
|
67
67
|
// emitted to: ${normalizePath(relative(root, routeFile))}
|
|
68
|
-
// This route is unauthenticated: any caller can run any declared
|
|
68
|
+
// This route is unauthenticated: any caller who reaches it can run any declared
|
|
69
|
+
// workflow. Signed invocation is not available yet.
|
|
69
70
|
|
|
70
71
|
import { createFileRoute } from "@tanstack/react-router";
|
|
71
72
|
|
|
@@ -155,7 +156,7 @@ function createRouteEmitter(options) {
|
|
|
155
156
|
entryExists = false;
|
|
156
157
|
}
|
|
157
158
|
const expected = /* @__PURE__ */ new Set();
|
|
158
|
-
if (entryExists
|
|
159
|
+
if (entryExists) {
|
|
159
160
|
expected.add(routeFile);
|
|
160
161
|
writeIfChanged(routeFile, buildRouteSource(routeFile, routeLiteral, param, entry, root));
|
|
161
162
|
}
|
|
@@ -173,8 +174,8 @@ function createRouteEmitter(options) {
|
|
|
173
174
|
//#endregion
|
|
174
175
|
//#region src/vite/plugin.ts
|
|
175
176
|
/**
|
|
176
|
-
* Build the collection's manifests and
|
|
177
|
-
*
|
|
177
|
+
* Build the collection's manifests and emit the route serving them; one `entry`
|
|
178
|
+
* feeds both, so the two can never describe different sets.
|
|
178
179
|
*/
|
|
179
180
|
function workflowsPlugin(options = {}) {
|
|
180
181
|
const entry = options.entry ?? "src/lib/workflows/index.ts";
|
|
@@ -182,8 +183,7 @@ function workflowsPlugin(options = {}) {
|
|
|
182
183
|
entry,
|
|
183
184
|
routesDir: options.routesDir ?? "src/routes",
|
|
184
185
|
path: options.path ?? "/api/workflows",
|
|
185
|
-
workflowIdParam: options.workflowIdParam ?? "workflowId"
|
|
186
|
-
runRoute: options.runRoute === true
|
|
186
|
+
workflowIdParam: options.workflowIdParam ?? "workflowId"
|
|
187
187
|
});
|
|
188
188
|
let config;
|
|
189
189
|
return {
|