@workflow/nest 5.0.0-beta.4 → 5.0.0-beta.6
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/dist/builder.d.ts +7 -0
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +6 -15
- package/dist/builder.js.map +1 -1
- package/dist/workflow.controller.d.ts +0 -1
- package/dist/workflow.controller.d.ts.map +1 -1
- package/dist/workflow.controller.js +2 -15
- package/dist/workflow.controller.js.map +1 -1
- package/package.json +3 -3
package/dist/builder.d.ts
CHANGED
|
@@ -36,6 +36,13 @@ export interface NestBuilderOptions {
|
|
|
36
36
|
* @default 'dist'
|
|
37
37
|
*/
|
|
38
38
|
distDir?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Controls how source maps are emitted for workflow bundles. Accepts the
|
|
41
|
+
* same values as esbuild's `sourcemap` option: `true`/`'inline'` (default),
|
|
42
|
+
* `'linked'`, `'external'`, `'both'`, or `false` to omit source maps.
|
|
43
|
+
* Can also be set via the `WORKFLOW_SOURCEMAP` environment variable.
|
|
44
|
+
*/
|
|
45
|
+
sourcemap?: boolean | 'inline' | 'linked' | 'external' | 'both';
|
|
39
46
|
}
|
|
40
47
|
export declare class NestLocalBuilder extends BaseBuilder {
|
|
41
48
|
#private;
|
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA2B,MAAM,oBAAoB,CAAC;AAI1E,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC;IAChC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAA2B,MAAM,oBAAoB,CAAC;AAI1E,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC;IAChC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;CACjE;AAED,qBAAa,gBAAiB,SAAQ,WAAW;;gBAOnC,OAAO,GAAE,kBAAuB;IAwB5C,IAAI,MAAM,IAAI,MAAM,CAEnB;IAEc,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA8EtC"}
|
package/dist/builder.js
CHANGED
|
@@ -17,6 +17,7 @@ export class NestLocalBuilder extends BaseBuilder {
|
|
|
17
17
|
workingDir,
|
|
18
18
|
watch: options.watch ?? false,
|
|
19
19
|
dirs,
|
|
20
|
+
sourcemap: options.sourcemap,
|
|
20
21
|
}),
|
|
21
22
|
// Use 'standalone' as base target - we handle the specific bundling ourselves
|
|
22
23
|
buildTarget: 'standalone',
|
|
@@ -36,17 +37,13 @@ export class NestLocalBuilder extends BaseBuilder {
|
|
|
36
37
|
async build() {
|
|
37
38
|
const inputFiles = await this.getInputFiles();
|
|
38
39
|
await mkdir(this.#outDir, { recursive: true });
|
|
39
|
-
const { manifest
|
|
40
|
-
outfile: join(this.#outDir, 'workflows.mjs'),
|
|
41
|
-
bundleFinalOutput: false,
|
|
42
|
-
format: 'esm',
|
|
40
|
+
const { manifest } = await this.createCombinedBundle({
|
|
43
41
|
inputFiles,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
outfile: join(this.#outDir, 'steps.mjs'),
|
|
47
|
-
externalizeNonSteps: true,
|
|
42
|
+
stepsOutfile: join(this.#outDir, 'steps.mjs'),
|
|
43
|
+
flowOutfile: join(this.#outDir, 'workflows.mjs'),
|
|
48
44
|
format: 'esm',
|
|
49
|
-
|
|
45
|
+
bundleFinalOutput: false,
|
|
46
|
+
externalizeNonSteps: true,
|
|
50
47
|
});
|
|
51
48
|
// When the NestJS project compiles to CJS via SWC, the ESM steps bundle
|
|
52
49
|
// can't import named exports from CJS files because cjs-module-lexer
|
|
@@ -59,12 +56,6 @@ export class NestLocalBuilder extends BaseBuilder {
|
|
|
59
56
|
outfile: join(this.#outDir, 'webhook.mjs'),
|
|
60
57
|
bundle: false,
|
|
61
58
|
});
|
|
62
|
-
// Merge manifests from both bundles
|
|
63
|
-
const manifest = {
|
|
64
|
-
steps: { ...stepsManifest.steps, ...workflowsManifest.steps },
|
|
65
|
-
workflows: { ...stepsManifest.workflows, ...workflowsManifest.workflows },
|
|
66
|
-
classes: { ...stepsManifest.classes, ...workflowsManifest.classes },
|
|
67
|
-
};
|
|
68
59
|
// Generate manifest
|
|
69
60
|
await this.createManifest({
|
|
70
61
|
workflowBundlePath: join(this.#outDir, 'workflows.mjs'),
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC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O,EAAE,eAAe,CAAC;YACvD,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,QAAQ;SACT,CAAC,CAAC;QAEH,+CAA+C;QAC/C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;YACtC,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,yBAAyB;QAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAExD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,yBAAyB,CAClE,YAAY,EACZ;YACE,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,IAAI,EAAE,IAAI,CAAC,KAAK;SACjB,CACF,CAAC;QAEF,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CACV,sEAAsE;gBACpE,iFAAiF,CACpF,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,WAAW,GAAG;YAClB,yEAAyE;YACzE,2DAA2D;YAC3D,EAAE;SACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,SAAS,CAAC,SAAS,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC;IACtD,CAAC;CACF","sourcesContent":["import { mkdir, writeFile, readFile } from 'node:fs/promises';\nimport { BaseBuilder, createBaseBuilderConfig } from '@workflow/builders';\nimport { join } from 'pathe';\nimport { rewriteTsImportsInContent } from './cjs-rewrite.js';\n\nexport interface NestBuilderOptions {\n /**\n * Working directory for the NestJS application\n * @default process.cwd()\n */\n workingDir?: string;\n /**\n * Directories to scan for workflow files\n * @default ['src']\n */\n dirs?: string[];\n /**\n * Output directory for generated workflow bundles\n * @default '.nestjs/workflow'\n */\n outDir?: string;\n /**\n * Enable watch mode for development\n * @default false\n */\n watch?: boolean;\n /**\n * SWC module compilation type.\n * Set to 'commonjs' if your NestJS project compiles to CJS via SWC.\n * When 'commonjs', the builder rewrites externalized imports in the\n * steps bundle to use require() via createRequire, avoiding ESM/CJS\n * named-export interop issues with SWC's _export() wrapper pattern.\n * @default 'es6'\n */\n moduleType?: 'es6' | 'commonjs';\n /**\n * Directory where NestJS compiles .ts source files to .js (relative to workingDir).\n * Used when moduleType is 'commonjs' to resolve compiled file paths.\n * This should match the `outDir` in your tsconfig.json.\n * @default 'dist'\n */\n distDir?: string;\n /**\n * Controls how source maps are emitted for workflow bundles. Accepts the\n * same values as esbuild's `sourcemap` option: `true`/`'inline'` (default),\n * `'linked'`, `'external'`, `'both'`, or `false` to omit source maps.\n * Can also be set via the `WORKFLOW_SOURCEMAP` environment variable.\n */\n sourcemap?: boolean | 'inline' | 'linked' | 'external' | 'both';\n}\n\nexport class NestLocalBuilder extends BaseBuilder {\n #outDir: string;\n #moduleType: 'es6' | 'commonjs';\n #distDir: string;\n #dirs: string[];\n #workingDir: string;\n\n constructor(options: NestBuilderOptions = {}) {\n const workingDir = options.workingDir ?? process.cwd();\n const outDir = options.outDir ?? join(workingDir, '.nestjs/workflow');\n const dirs = options.dirs ?? ['src'];\n super({\n ...createBaseBuilderConfig({\n workingDir,\n watch: options.watch ?? false,\n dirs,\n sourcemap: options.sourcemap,\n }),\n // Use 'standalone' as base target - we handle the specific bundling ourselves\n buildTarget: 'standalone',\n stepsBundlePath: join(outDir, 'steps.mjs'),\n workflowsBundlePath: join(outDir, 'workflows.mjs'),\n webhookBundlePath: join(outDir, 'webhook.mjs'),\n });\n this.#outDir = outDir;\n this.#moduleType = options.moduleType ?? 'es6';\n this.#distDir = options.distDir ?? 'dist';\n this.#dirs = dirs;\n this.#workingDir = workingDir;\n }\n\n get outDir(): string {\n return this.#outDir;\n }\n\n override async build(): Promise<void> {\n const inputFiles = await this.getInputFiles();\n await mkdir(this.#outDir, { recursive: true });\n\n const { manifest } = await this.createCombinedBundle({\n inputFiles,\n stepsOutfile: join(this.#outDir, 'steps.mjs'),\n flowOutfile: join(this.#outDir, 'workflows.mjs'),\n format: 'esm',\n bundleFinalOutput: false,\n externalizeNonSteps: true,\n });\n\n // When the NestJS project compiles to CJS via SWC, the ESM steps bundle\n // can't import named exports from CJS files because cjs-module-lexer\n // doesn't recognize SWC's _export() wrapper pattern.\n // Rewrite externalized .ts imports to use require() via createRequire.\n if (this.#moduleType === 'commonjs') {\n await this.#rewriteStepsBundleForCjs();\n }\n\n await this.createWebhookBundle({\n outfile: join(this.#outDir, 'webhook.mjs'),\n bundle: false,\n });\n\n // Generate manifest\n await this.createManifest({\n workflowBundlePath: join(this.#outDir, 'workflows.mjs'),\n manifestDir: this.#outDir,\n manifest,\n });\n\n // Create .gitignore to exclude generated files\n if (!process.env.VERCEL_DEPLOYMENT_ID) {\n await writeFile(join(this.#outDir, '.gitignore'), '*\\n');\n }\n }\n\n /**\n * Rewrite externalized .ts/.tsx imports in the steps bundle to use require()\n * for CommonJS compatibility.\n *\n * When NestJS compiles to CJS via SWC, the ESM steps bundle can't import\n * named exports from CJS files because cjs-module-lexer doesn't recognize\n * SWC's _export() wrapper pattern. This rewrites the imports to use\n * createRequire() and points them to the compiled .js files in distDir.\n */\n async #rewriteStepsBundleForCjs(): Promise<void> {\n const stepsPath = join(this.#outDir, 'steps.mjs');\n const stepsContent = await readFile(stepsPath, 'utf-8');\n\n const { content: rewritten, matchCount } = rewriteTsImportsInContent(\n stepsContent,\n {\n outDir: this.#outDir,\n workingDir: this.#workingDir,\n distDir: this.#distDir,\n dirs: this.#dirs,\n }\n );\n\n if (matchCount === 0) {\n console.warn(\n '[@workflow/nest] No .ts/.tsx imports found to rewrite for CommonJS. ' +\n \"If you expected externalized imports, esbuild's output format may have changed.\"\n );\n return;\n }\n\n const requireShim = [\n `import { createRequire as __bundled_createRequire } from 'node:module';`,\n `const require = __bundled_createRequire(import.meta.url);`,\n ``,\n ].join('\\n');\n\n await writeFile(stepsPath, requireShim + rewritten);\n }\n}\n"]}
|
|
@@ -7,7 +7,6 @@ export declare function configureWorkflowController(outDir: string): void;
|
|
|
7
7
|
* Dynamically imports the generated bundles and handles request/response conversion.
|
|
8
8
|
*/
|
|
9
9
|
export declare class WorkflowController {
|
|
10
|
-
handleStep(req: any, res: any): Promise<void>;
|
|
11
10
|
handleFlow(req: any, res: any): Promise<void>;
|
|
12
11
|
handleWebhook(req: any, res: any): Promise<void>;
|
|
13
12
|
handleManifest(res: any): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.controller.d.ts","sourceRoot":"","sources":["../src/workflow.controller.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEhE;AAqED;;;GAGG;AACH,qBACa,kBAAkB;IAEvB,UAAU,CAAQ,GAAG,EAAE,GAAG,EAAS,GAAG,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"workflow.controller.d.ts","sourceRoot":"","sources":["../src/workflow.controller.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEhE;AAqED;;;GAGG;AACH,qBACa,kBAAkB;IAEvB,UAAU,CAAQ,GAAG,EAAE,GAAG,EAAS,GAAG,EAAE,GAAG;IAa3C,aAAa,CAAQ,GAAG,EAAE,GAAG,EAAS,GAAG,EAAE,GAAG;IAW9C,cAAc,CAAQ,GAAG,EAAE,GAAG;CA0BrC"}
|
|
@@ -82,15 +82,10 @@ function getOutDir() {
|
|
|
82
82
|
* Dynamically imports the generated bundles and handles request/response conversion.
|
|
83
83
|
*/
|
|
84
84
|
let WorkflowController = class WorkflowController {
|
|
85
|
-
async handleStep(req, res) {
|
|
86
|
-
const outDir = getOutDir();
|
|
87
|
-
const { POST } = await import(pathToFileURL(join(outDir, 'steps.mjs')).href);
|
|
88
|
-
const webRequest = toWebRequest(req);
|
|
89
|
-
const webResponse = await POST(webRequest);
|
|
90
|
-
await sendWebResponse(res, webResponse);
|
|
91
|
-
}
|
|
92
85
|
async handleFlow(req, res) {
|
|
93
86
|
const outDir = getOutDir();
|
|
87
|
+
// Import step registrations (side effects) before the combined handler
|
|
88
|
+
await import(pathToFileURL(join(outDir, 'steps.mjs')).href);
|
|
94
89
|
const { POST } = await import(pathToFileURL(join(outDir, 'workflows.mjs')).href);
|
|
95
90
|
const webRequest = toWebRequest(req);
|
|
96
91
|
const webResponse = await POST(webRequest);
|
|
@@ -133,14 +128,6 @@ let WorkflowController = class WorkflowController {
|
|
|
133
128
|
await sendWebResponse(res, webResponse);
|
|
134
129
|
}
|
|
135
130
|
};
|
|
136
|
-
__decorate([
|
|
137
|
-
Post('step'),
|
|
138
|
-
__param(0, Req()),
|
|
139
|
-
__param(1, Res()),
|
|
140
|
-
__metadata("design:type", Function),
|
|
141
|
-
__metadata("design:paramtypes", [Object, Object]),
|
|
142
|
-
__metadata("design:returntype", Promise)
|
|
143
|
-
], WorkflowController.prototype, "handleStep", null);
|
|
144
131
|
__decorate([
|
|
145
132
|
Post('flow'),
|
|
146
133
|
__param(0, Req()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.controller.js","sourceRoot":"","sources":["../src/workflow.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE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ToFileURL } from 'node:url';\nimport { All, Controller, Get, Post, Req, Res } from '@nestjs/common';\nimport { join } from 'pathe';\n\n// Module-level state for configuration\nlet configuredOutDir: string | null = null;\n\n/**\n * Configure the workflow controller with the output directory\n */\nexport function configureWorkflowController(outDir: string): void {\n configuredOutDir = outDir;\n}\n\n/**\n * Convert Express/Fastify request to Web API Request\n */\nfunction toWebRequest(req: any): Request {\n // Works for both Express and Fastify\n const protocol =\n req.protocol ?? (req.raw?.socket?.encrypted ? 'https' : 'http');\n const host = req.headers.host ?? req.hostname;\n const url = req.originalUrl ?? req.url;\n const fullUrl = `${protocol}://${host}${url}`;\n\n const headers = req.headers;\n const method = req.method;\n const body = req.body;\n\n return new globalThis.Request(fullUrl, {\n method,\n headers,\n body:\n method !== 'GET' && method !== 'HEAD'\n ? body === undefined\n ? undefined\n : typeof body === 'string'\n ? body\n : JSON.stringify(body)\n : undefined,\n });\n}\n\n/**\n * Send Web API Response back via Express/Fastify response\n */\nasync function sendWebResponse(\n res: any,\n webResponse: globalThis.Response\n): Promise<void> {\n const status = webResponse.status;\n const headers: Record<string, string> = {};\n webResponse.headers.forEach((value, key) => {\n headers[key] = value;\n });\n const body = await webResponse.text();\n\n // Works for both Express and Fastify\n if (typeof res.code === 'function') {\n // Fastify\n res.code(status).headers(headers).send(body);\n } else {\n // Express - use res.end() instead of res.send() to avoid automatic charset addition\n res.status(status);\n for (const [key, value] of Object.entries(headers)) {\n res.setHeader(key, value);\n }\n // Use res.end() to send the body without Express modifying headers\n res.end(body);\n }\n}\n\nfunction getOutDir(): string {\n if (!configuredOutDir) {\n throw new Error(\n 'WorkflowController not configured. Call configureWorkflowController first.'\n );\n }\n return configuredOutDir;\n}\n\n/**\n * Controller that handles the well-known workflow endpoints.\n * Dynamically imports the generated bundles and handles request/response conversion.\n */\n@Controller('.well-known/workflow/v1')\nexport class WorkflowController {\n @Post('flow')\n async handleFlow(@Req() req: any, @Res() res: any) {\n const outDir = getOutDir();\n // Import step registrations (side effects) before the combined handler\n await import(pathToFileURL(join(outDir, 'steps.mjs')).href);\n const { POST } = await import(\n pathToFileURL(join(outDir, 'workflows.mjs')).href\n );\n const webRequest = toWebRequest(req);\n const webResponse = await POST(webRequest);\n await sendWebResponse(res, webResponse);\n }\n\n @All('webhook/:token')\n async handleWebhook(@Req() req: any, @Res() res: any) {\n const outDir = getOutDir();\n const { POST } = await import(\n pathToFileURL(join(outDir, 'webhook.mjs')).href\n );\n const webRequest = toWebRequest(req);\n const webResponse = await POST(webRequest);\n await sendWebResponse(res, webResponse);\n }\n\n @Get('manifest.json')\n async handleManifest(@Res() res: any) {\n if (process.env.WORKFLOW_PUBLIC_MANIFEST !== '1') {\n if (typeof res.code === 'function') {\n res.code(404).send('');\n } else {\n res.status(404).end('');\n }\n return;\n }\n const outDir = getOutDir();\n let manifest: string;\n try {\n manifest = readFileSync(join(outDir, 'manifest.json'), 'utf-8');\n } catch {\n if (typeof res.code === 'function') {\n res.code(404).send('');\n } else {\n res.status(404).end('');\n }\n return;\n }\n const webResponse = new Response(manifest, {\n headers: { 'content-type': 'application/json' },\n });\n await sendWebResponse(res, webResponse);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/nest",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.6",
|
|
4
4
|
"description": "NestJS integration for Workflow SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@swc/core": "1.15.3",
|
|
30
30
|
"pathe": "2.0.3",
|
|
31
|
-
"@workflow/builders": "5.0.0-beta.
|
|
32
|
-
"@workflow/swc-plugin": "5.0.0-beta.
|
|
31
|
+
"@workflow/builders": "5.0.0-beta.6",
|
|
32
|
+
"@workflow/swc-plugin": "5.0.0-beta.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@nestjs/common": ">=10.0.0",
|