@workflow/next 5.0.8 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -104,6 +104,7 @@ export default withWorkflow(nextConfig, {
104
104
  | --- | --- | --- | --- |
105
105
  | `workflows.local.port` | `number` | — | Overrides the `PORT` environment variable for local development. Has no effect when deployed to Vercel. |
106
106
  | `workflows.sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. See [Source maps](#source-maps) below. |
107
+ | `workflows.experimentalRoutePrefix` | `string` | — | Serves the generated workflow routes below a route segment this app owns, such as `/dashboard`. See [Workflow route prefix](#workflow-route-prefix) below. |
107
108
 
108
109
  ### Source maps
109
110
 
@@ -129,6 +130,62 @@ The option can also be set via the `WORKFLOW_SOURCEMAP` environment variable, wh
129
130
  The `workflows.local` options only affect local development. When deployed to Vercel, the runtime ignores `local` settings and uses the Vercel world automatically.
130
131
  </Callout>
131
132
 
133
+ ### Workflow route prefix
134
+
135
+ By default the integration generates its routes at the root of your app, so the flow route answers at `/.well-known/workflow/v1/flow`. Some deployments cannot own those paths. In a [Microfrontends](https://vercel.com/docs/microfrontends) setup, for example, a child app is routed a path such as `/dashboard/*` while requests for `/.well-known/*` go to the default app, so queue deliveries and webhooks aimed at the root never reach the child.
136
+
137
+ `workflows.experimentalRoutePrefix` moves the generated workflow routes below a segment the app does own:
138
+
139
+ ```typescript title="next.config.ts" lineNumbers
140
+ import type { NextConfig } from "next";
141
+ import { withWorkflow } from "workflow/next";
142
+
143
+ const nextConfig: NextConfig = {};
144
+
145
+ export default withWorkflow(nextConfig, {
146
+ workflows: {
147
+ experimentalRoutePrefix: "/dashboard", // [!code highlight]
148
+ },
149
+ });
150
+ ```
151
+
152
+ With that prefix, the build emits:
153
+
154
+ | Artifact | Path |
155
+ | --- | --- |
156
+ | Flow route | `app/dashboard/.well-known/workflow/v1/flow/route.js` |
157
+ | Webhook route | `app/dashboard/.well-known/workflow/v1/webhook/[token]/route.js` |
158
+ | Vercel function config | `app/dashboard/.well-known/workflow/v1/config.json` |
159
+ | Manifest | `app/dashboard/.well-known/workflow/v1/manifest.json` |
160
+
161
+ The queue trigger that makes the flow route a queue consumer is written next to the prefixed route, so deliveries reach it without any additional routing configuration. Webhook URLs, health checks, and the local and Postgres queue targets are all built from the prefix, so `createWebhook()` returns a URL under `/dashboard/.well-known/workflow/v1/webhook/:token`. `getWorkflowMetadata().url` includes the prefix too (for example `https://example.com/dashboard`), so don't build URLs to the rest of your app from it.
162
+
163
+ The prefix is a plain path of one or more segments. Leading and trailing slashes are optional. Anything Next.js would not serve at a fixed path is rejected when the config is created: dynamic segments such as `/[team]`, route groups such as `/(group)`, and `_`-prefixed segments, which Next.js excludes from routing entirely. Segments starting with `.` are rejected too, because the build could not clean up routes generated below them after the prefix changes.
164
+
165
+ <Callout type="warn">
166
+ If you cache your build with Turborepo, update the `outputs` globs to the prefixed paths. `app/.well-known/workflow/**` no longer matches `app/dashboard/.well-known/workflow/**`, and a cache hit would restore a build with no workflow routes in it.
167
+ </Callout>
168
+
169
+ <Callout type="warn">
170
+ If the app has `proxy.ts` or middleware, its matcher must exclude the prefixed path. A pattern such as `/((?!.well-known/workflow/).*)` only matches from the start of the path, so it no longer skips `/dashboard/.well-known/workflow/v1/flow`; exclude `dashboard/.well-known/workflow/` instead.
171
+ </Callout>
172
+
173
+ <Callout type="warn">
174
+ Your routing layer must send the prefixed paths to this app. With Microfrontends, that means choosing a prefix the child app is already routed in the group's [routing configuration](https://vercel.com/docs/microfrontends/routing).
175
+ </Callout>
176
+
177
+ This option is experimental and its name may change.
178
+
179
+ #### Compared with `basePath`
180
+
181
+ The integration already honors Next.js' [`basePath`](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath): Next.js serves every route, including the generated workflow routes, below it, and `withWorkflow` passes it to the runtime so webhook and queue URLs include it. That only helps when the whole app can move under one path. A Microfrontends child app usually can't: its pages already live at `app/dashboard/...`, so `basePath: "/dashboard"` would serve them at `/dashboard/dashboard/...`.
182
+
183
+ `experimentalRoutePrefix` moves only the generated workflow routes and their function config into the app tree; the rest of your routes keep their paths. The two compose: with `basePath: "/v2"` and `experimentalRoutePrefix: "/dashboard"`, the flow route answers at `/v2/dashboard/.well-known/workflow/v1/flow`.
184
+
185
+ <Callout type="info">
186
+ The local CLI and web UI find a prefixed manifest such as `app/dashboard/.well-known/workflow/v1/manifest.json` on their own; set [`WORKFLOW_MANIFEST_PATH`](/docs/configuration/cli-and-web-ui#workflow_manifest_path) to pick another. Pass the base path to [`workflow health`](/docs/configuration/cli-and-web-ui#--base-path), for example `workflow health --base-path /dashboard`.
187
+ </Callout>
188
+
132
189
  ## Exporting a function
133
190
 
134
191
 
package/docs/next.mdx CHANGED
@@ -308,6 +308,8 @@ Add the following to your `turbo.json`:
308
308
 
309
309
  Without this configuration, you may experience intermittent issues where workflows fail to register properly on cache hits, while working correctly on cache misses.
310
310
 
311
+ If you set [`workflows.experimentalRoutePrefix`](/docs/api-reference/workflow-next/with-workflow#workflow-route-prefix), include the prefix in these globs (for example `app/dashboard/.well-known/workflow/**`).
312
+
311
313
  ### `start()` says it received an invalid workflow function
312
314
 
313
315
  If you see this error:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/next",
3
- "version": "5.0.8",
3
+ "version": "5.1.0",
4
4
  "description": "Next.js integration for Workflow SDK",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -27,20 +27,20 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@swc/core": "1.15.3",
30
- "@workflow/builders": "5.0.8",
31
- "@workflow/core": "5.4.0",
30
+ "@workflow/builders": "5.1.0",
31
+ "@workflow/core": "5.5.0",
32
32
  "@workflow/swc-plugin": "5.0.1",
33
- "ignore": "7.0.5",
34
- "semver": "7.7.4",
35
- "watchpack": "2.5.1"
33
+ "ignore": "7.0.14",
34
+ "semver": "7.8.6",
35
+ "watchpack": "2.6.4"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "22.19.0",
39
- "@types/semver": "7.7.1",
38
+ "@types/node": "22.19.21",
39
+ "@types/semver": "7.8.0",
40
40
  "@workflow/tsconfig": "5.0.0",
41
- "next": "16.3.8",
41
+ "next": "16.4.5",
42
42
  "typescript": "^6.0.3",
43
- "vitest": "^4.1.10"
43
+ "vitest": "^5.1.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "next": ">13"
@@ -53,7 +53,7 @@
53
53
  "scripts": {
54
54
  "build": "tsc",
55
55
  "dev": "tsc --watch",
56
- "test": "vitest run src",
56
+ "test": "vitest run --config=../../vitest.config.ts src",
57
57
  "clean": "tsc --build --clean && rm -rf dist docs"
58
58
  }
59
59
  }