next-workflow-builder 0.3.1 → 0.4.1

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 CHANGED
@@ -160,6 +160,10 @@ For full documentation including configuration, authentication, database setup,
160
160
  - [Database](https://next-workflow-builder.vercel.app/docs/database)
161
161
  - [Deployment](https://next-workflow-builder.vercel.app/docs/deployment)
162
162
 
163
+ ## Changelog
164
+
165
+ Full [Changelog](./CHANGELOG.md) file
166
+
163
167
  ## License
164
168
 
165
169
  Apache-2.0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getIntegrationById
3
- } from "./chunk-BNYDOC3I.js";
3
+ } from "./chunk-BL6QJDNB.js";
4
4
  import {
5
5
  getCredentialMapping,
6
6
  getIntegration
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  db,
3
3
  integrations
4
- } from "./chunk-3MSAF2TH.js";
4
+ } from "./chunk-PGG52OSJ.js";
5
5
 
6
6
  // src/server/db/integrations.ts
7
7
  import "server-only";
@@ -9,7 +9,7 @@ import {
9
9
  workflowExecutions,
10
10
  workflowExecutionsRelations,
11
11
  workflows
12
- } from "./chunk-3MSAF2TH.js";
12
+ } from "./chunk-PGG52OSJ.js";
13
13
 
14
14
  // src/server/auth/index.ts
15
15
  import { betterAuth } from "better-auth";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  db,
3
3
  workflows
4
- } from "./chunk-3MSAF2TH.js";
4
+ } from "./chunk-PGG52OSJ.js";
5
5
 
6
6
  // src/server/lib/metadata.ts
7
7
  import { eq } from "drizzle-orm";
@@ -162,7 +162,7 @@ var schema = {
162
162
  apiKeys,
163
163
  integrations
164
164
  };
165
- var connectionString = process.env.DATABASE_URL || "postgres://localhost:5432/workflow";
165
+ var connectionString = process.env.__NWB_DATABASE_URL || process.env.DATABASE_URL || "postgres://localhost:5432/workflow";
166
166
  var migrationClient = postgres(connectionString, { max: 1 });
167
167
  var globalForDb = globalThis;
168
168
  var queryClient = globalForDb.queryClient ?? postgres(connectionString, { max: 10 });
@@ -12634,7 +12634,9 @@ var SYSTEM_ACTION_LABELS = {
12634
12634
  "Database Query": "Database",
12635
12635
  Condition: "Condition",
12636
12636
  "Execute Code": "System",
12637
- Loop: "Loop"
12637
+ Loop: "Loop",
12638
+ Switch: "Switch",
12639
+ Merge: "Merge"
12638
12640
  };
12639
12641
  var getIntegrationFromActionType = (actionType) => {
12640
12642
  if (SYSTEM_ACTION_LABELS[actionType]) {
@@ -1,15 +1,15 @@
1
- import "./chunk-7MUXUHEL.js";
1
+ import "./chunk-KZNRU3LB.js";
2
2
  import "./chunk-TFNZVQEH.js";
3
- import "./chunk-P3DTV3QS.js";
3
+ import "./chunk-F6HAK4HT.js";
4
4
  import "./chunk-5YYA34YV.js";
5
5
  import "./chunk-OQHML4II.js";
6
- import "./chunk-DJ7ANVJ3.js";
7
- import "./chunk-BNYDOC3I.js";
6
+ import "./chunk-2IJUDWUK.js";
7
+ import "./chunk-BL6QJDNB.js";
8
8
  import "./chunk-Z3BJJYHM.js";
9
9
  import "./chunk-O3I2INCD.js";
10
10
  import {
11
11
  withStepLogging
12
- } from "./chunk-3MSAF2TH.js";
12
+ } from "./chunk-PGG52OSJ.js";
13
13
 
14
14
  // src/plugins/condition/condition.ts
15
15
  import "server-only";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  fetchCredentials
3
- } from "./chunk-DJ7ANVJ3.js";
4
- import "./chunk-BNYDOC3I.js";
3
+ } from "./chunk-2IJUDWUK.js";
4
+ import "./chunk-BL6QJDNB.js";
5
5
  import "./chunk-Z3BJJYHM.js";
6
6
  import {
7
7
  withStepLogging
8
- } from "./chunk-3MSAF2TH.js";
8
+ } from "./chunk-PGG52OSJ.js";
9
9
 
10
10
  // src/plugins/database-query/database-query.ts
11
11
  import "server-only";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-O3I2INCD.js";
4
4
  import {
5
5
  withStepLogging
6
- } from "./chunk-3MSAF2TH.js";
6
+ } from "./chunk-PGG52OSJ.js";
7
7
 
8
8
  // src/plugins/http-request/http-request.ts
9
9
  import "server-only";
@@ -0,0 +1,37 @@
1
+ import {
2
+ withStepLogging
3
+ } from "./chunk-PGG52OSJ.js";
4
+
5
+ // src/plugins/loop/loop.ts
6
+ import "server-only";
7
+ function evaluateLoop(input) {
8
+ const items = Array.isArray(input.items) ? input.items : [];
9
+ const batchSize = Math.max(1, input.batchSize || 1);
10
+ const currentBatchIndex = input.currentBatchIndex ?? 0;
11
+ const totalItems = items.length;
12
+ const totalBatches = Math.ceil(totalItems / batchSize);
13
+ const startIndex = currentBatchIndex * batchSize;
14
+ const endIndex = Math.min(startIndex + batchSize, totalItems);
15
+ const currentBatch = items.slice(startIndex, endIndex);
16
+ const currentItem = currentBatch[0];
17
+ const hasMore = currentBatchIndex < totalBatches - 1;
18
+ return {
19
+ hasMore,
20
+ currentBatchIndex,
21
+ currentBatch,
22
+ currentItem,
23
+ currentIndex: startIndex,
24
+ totalItems,
25
+ totalBatches,
26
+ items,
27
+ batchSize
28
+ };
29
+ }
30
+ async function loopStep(input) {
31
+ "use step";
32
+ return withStepLogging(input, () => Promise.resolve(evaluateLoop(input)));
33
+ }
34
+ loopStep.maxRetries = 0;
35
+ export {
36
+ loopStep
37
+ };
@@ -0,0 +1,107 @@
1
+ import "./chunk-KZNRU3LB.js";
2
+ import "./chunk-TFNZVQEH.js";
3
+ import "./chunk-F6HAK4HT.js";
4
+ import "./chunk-5YYA34YV.js";
5
+ import "./chunk-OQHML4II.js";
6
+ import "./chunk-2IJUDWUK.js";
7
+ import "./chunk-BL6QJDNB.js";
8
+ import "./chunk-Z3BJJYHM.js";
9
+ import "./chunk-O3I2INCD.js";
10
+ import {
11
+ withStepLogging
12
+ } from "./chunk-PGG52OSJ.js";
13
+
14
+ // src/plugins/merge/merge.ts
15
+ import "server-only";
16
+ function getField(item, field) {
17
+ if (item && typeof item === "object") {
18
+ return item[field];
19
+ }
20
+ return void 0;
21
+ }
22
+ function mergeAppend(items1, items2) {
23
+ const merged = [...items1, ...items2];
24
+ return { merged, totalItems: merged.length };
25
+ }
26
+ function mergeByPosition(items1, items2, unmatchedHandling) {
27
+ const maxLength = Math.max(items1.length, items2.length);
28
+ const useNull = unmatchedHandling !== "discard";
29
+ const merged = [];
30
+ for (let i = 0; i < maxLength; i++) {
31
+ const item1 = items1[i];
32
+ const item2 = items2[i];
33
+ if (!useNull && (item1 === void 0 || item2 === void 0)) {
34
+ continue;
35
+ }
36
+ merged.push({
37
+ ...item1 && typeof item1 === "object" ? item1 : { input1: item1 ?? null },
38
+ ...item2 && typeof item2 === "object" ? item2 : { input2: item2 ?? null }
39
+ });
40
+ }
41
+ return { merged, totalItems: merged.length };
42
+ }
43
+ function mergeByFields(items1, items2, field1, field2, joinType) {
44
+ const map2 = /* @__PURE__ */ new Map();
45
+ for (const item of items2) {
46
+ const key = getField(item, field2);
47
+ if (!map2.has(key)) {
48
+ map2.set(key, []);
49
+ }
50
+ map2.get(key).push(item);
51
+ }
52
+ const merged = [];
53
+ const matchedKeys2 = /* @__PURE__ */ new Set();
54
+ for (const item1 of items1) {
55
+ const key = getField(item1, field1);
56
+ const matches = map2.get(key);
57
+ if (matches && matches.length > 0) {
58
+ matchedKeys2.add(key);
59
+ for (const item2 of matches) {
60
+ merged.push({
61
+ ...typeof item1 === "object" ? item1 : {},
62
+ ...typeof item2 === "object" ? item2 : {}
63
+ });
64
+ }
65
+ } else if (joinType === "leftOuter" || joinType === "fullOuter") {
66
+ merged.push({ ...typeof item1 === "object" ? item1 : {} });
67
+ }
68
+ }
69
+ if (joinType === "rightOuter" || joinType === "fullOuter") {
70
+ for (const item2 of items2) {
71
+ const key = getField(item2, field2);
72
+ if (!matchedKeys2.has(key)) {
73
+ merged.push({ ...typeof item2 === "object" ? item2 : {} });
74
+ }
75
+ }
76
+ }
77
+ return { merged, totalItems: merged.length };
78
+ }
79
+ function evaluateMerge(input) {
80
+ const items1 = Array.isArray(input.input1) ? input.input1 : [];
81
+ const items2 = Array.isArray(input.input2) ? input.input2 : [];
82
+ const mode = input.mode || "append";
83
+ switch (mode) {
84
+ case "append":
85
+ return mergeAppend(items1, items2);
86
+ case "combineByPosition":
87
+ return mergeByPosition(items1, items2, input.unmatchedHandling || "useNull");
88
+ case "combineByFields":
89
+ return mergeByFields(
90
+ items1,
91
+ items2,
92
+ input.matchField1 || "id",
93
+ input.matchField2 || "id",
94
+ input.joinType || "inner"
95
+ );
96
+ default:
97
+ return mergeAppend(items1, items2);
98
+ }
99
+ }
100
+ async function mergeStep(input) {
101
+ "use step";
102
+ return withStepLogging(input, () => Promise.resolve(evaluateMerge(input)));
103
+ }
104
+ mergeStep.maxRetries = 0;
105
+ export {
106
+ mergeStep
107
+ };
@@ -6,6 +6,8 @@ declare const NextWorkflowBuilderConfigSchema: z.ZodObject<{
6
6
  debug: z.ZodOptional<z.ZodBoolean>;
7
7
  /** Set Better Auth options (must be JSON-serializable). */
8
8
  authOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
9
+ /** Override the database connection URL. Defaults to process.env.DATABASE_URL. */
10
+ databaseUrl: z.ZodOptional<z.ZodString>;
9
11
  }, z.core.$strict>;
10
12
 
11
13
  /**
@@ -14,7 +14,9 @@ var NextWorkflowBuilderConfigSchema = z.strictObject({
14
14
  /** Enable debug logging. */
15
15
  debug: z.boolean().optional(),
16
16
  /** Set Better Auth options (must be JSON-serializable). */
17
- authOptions: z.record(z.string(), z.unknown()).optional()
17
+ authOptions: z.record(z.string(), z.unknown()).optional(),
18
+ /** Override the database connection URL. Defaults to process.env.DATABASE_URL. */
19
+ databaseUrl: z.string().optional()
18
20
  });
19
21
 
20
22
  // src/next/index.ts
@@ -29,6 +31,9 @@ var nextWorkflowBuilder = (config = {}) => {
29
31
  if (loaderOptions.authOptions) {
30
32
  process.env.__NWB_AUTH_OPTIONS = JSON.stringify(loaderOptions.authOptions);
31
33
  }
34
+ if (loaderOptions.databaseUrl) {
35
+ process.env.__NWB_DATABASE_URL = loaderOptions.databaseUrl;
36
+ }
32
37
  discoverPlugins();
33
38
  return function withNextWorkflowBuilder(nextConfig = {}) {
34
39
  const consumerPluginsRelative = "./plugins/index.ts";
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  auth,
17
17
  getAuthConfig
18
- } from "../../chunk-P3DTV3QS.js";
18
+ } from "../../chunk-F6HAK4HT.js";
19
19
  import {
20
20
  getErrorMessageAsync
21
21
  } from "../../chunk-5YYA34YV.js";
@@ -33,7 +33,7 @@ import {
33
33
  getIntegrations,
34
34
  updateIntegration,
35
35
  validateWorkflowIntegrations
36
- } from "../../chunk-BNYDOC3I.js";
36
+ } from "../../chunk-BL6QJDNB.js";
37
37
  import {
38
38
  findActionById,
39
39
  getAllEnvVars,
@@ -50,7 +50,7 @@ import {
50
50
  workflowExecutionLogs,
51
51
  workflowExecutions,
52
52
  workflows
53
- } from "../../chunk-3MSAF2TH.js";
53
+ } from "../../chunk-PGG52OSJ.js";
54
54
 
55
55
  // src/server/api/index.ts
56
56
  import { NextResponse as NextResponse5 } from "next/server";
@@ -416,18 +416,33 @@ triggerStep.maxRetries = 0;
416
416
  var SYSTEM_ACTIONS = {
417
417
  "Database Query": {
418
418
  // biome-ignore lint/suspicious/noExplicitAny: Dynamic module import
419
- importer: () => import("../../database-query-GRWP3S3M.js"),
419
+ importer: () => import("../../database-query-Q2JDUQ3N.js"),
420
420
  stepFunction: "databaseQueryStep"
421
421
  },
422
422
  "HTTP Request": {
423
423
  // biome-ignore lint/suspicious/noExplicitAny: Dynamic module import
424
- importer: () => import("../../http-request-2HVCXQHK.js"),
424
+ importer: () => import("../../http-request-T2UP7JLH.js"),
425
425
  stepFunction: "httpRequestStep"
426
426
  },
427
427
  Condition: {
428
428
  // biome-ignore lint/suspicious/noExplicitAny: Dynamic module import
429
- importer: () => import("../../condition-JZJH7YSJ.js"),
429
+ importer: () => import("../../condition-YFHUXD7D.js"),
430
430
  stepFunction: "conditionStep"
431
+ },
432
+ Loop: {
433
+ // biome-ignore lint/suspicious/noExplicitAny: Dynamic module import
434
+ importer: () => import("../../loop-EIU3JQIY.js"),
435
+ stepFunction: "loopStep"
436
+ },
437
+ Switch: {
438
+ // biome-ignore lint/suspicious/noExplicitAny: Dynamic module import
439
+ importer: () => import("../../switch-SG2SNUUJ.js"),
440
+ stepFunction: "switchStep"
441
+ },
442
+ Merge: {
443
+ // biome-ignore lint/suspicious/noExplicitAny: Dynamic module import
444
+ importer: () => import("../../merge-2GBB4W2S.js"),
445
+ stepFunction: "mergeStep"
431
446
  }
432
447
  };
433
448
  function replaceTemplateVariable(match, nodeId, rest, outputs, evalContext, varCounter) {
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  generateWorkflowMetadata
3
- } from "../chunk-7MUXUHEL.js";
3
+ } from "../chunk-KZNRU3LB.js";
4
4
  import {
5
5
  discoverPlugins
6
6
  } from "../chunk-TFNZVQEH.js";
7
7
  import {
8
8
  auth
9
- } from "../chunk-P3DTV3QS.js";
9
+ } from "../chunk-F6HAK4HT.js";
10
10
  import {
11
11
  getErrorMessageAsync
12
12
  } from "../chunk-5YYA34YV.js";
13
13
  import "../chunk-OQHML4II.js";
14
14
  import {
15
15
  fetchCredentials
16
- } from "../chunk-DJ7ANVJ3.js";
16
+ } from "../chunk-2IJUDWUK.js";
17
17
  import {
18
18
  decrypt,
19
19
  encrypt
20
- } from "../chunk-BNYDOC3I.js";
20
+ } from "../chunk-BL6QJDNB.js";
21
21
  import "../chunk-Z3BJJYHM.js";
22
22
  import {
23
23
  getErrorMessage
@@ -35,7 +35,7 @@ import {
35
35
  workflowExecutionLogs,
36
36
  workflowExecutions,
37
37
  workflowExecutionsRelations
38
- } from "../chunk-3MSAF2TH.js";
38
+ } from "../chunk-PGG52OSJ.js";
39
39
  export {
40
40
  accounts,
41
41
  apiKeys,
@@ -0,0 +1,68 @@
1
+ import "./chunk-KZNRU3LB.js";
2
+ import "./chunk-TFNZVQEH.js";
3
+ import "./chunk-F6HAK4HT.js";
4
+ import "./chunk-5YYA34YV.js";
5
+ import "./chunk-OQHML4II.js";
6
+ import "./chunk-2IJUDWUK.js";
7
+ import "./chunk-BL6QJDNB.js";
8
+ import "./chunk-Z3BJJYHM.js";
9
+ import "./chunk-O3I2INCD.js";
10
+ import {
11
+ withStepLogging
12
+ } from "./chunk-PGG52OSJ.js";
13
+
14
+ // src/plugins/switch/switch.ts
15
+ import "server-only";
16
+ function buildRoutes(input) {
17
+ const routes = [];
18
+ for (let i = 0; i < 4; i++) {
19
+ const name = input[`routeName${i}`];
20
+ const condition = input[`routeCondition${i}`];
21
+ const caseValue = input[`routeCaseValue${i}`];
22
+ routes.push({
23
+ name: name || `Route ${i + 1}`,
24
+ condition,
25
+ caseValue
26
+ });
27
+ }
28
+ return routes;
29
+ }
30
+ function evaluateSwitch(input) {
31
+ const mode = input.mode || "rules";
32
+ const routes = buildRoutes(input);
33
+ if (mode === "rules") {
34
+ for (let i = 0; i < routes.length; i++) {
35
+ if (routes[i].condition === true) {
36
+ return {
37
+ matchedRouteIndex: i,
38
+ matchedRouteName: routes[i].name,
39
+ isDefault: false
40
+ };
41
+ }
42
+ }
43
+ } else {
44
+ const switchValue = String(input.switchValue ?? "");
45
+ for (let i = 0; i < routes.length; i++) {
46
+ if (routes[i].caseValue !== void 0 && String(routes[i].caseValue) === switchValue) {
47
+ return {
48
+ matchedRouteIndex: i,
49
+ matchedRouteName: routes[i].name,
50
+ isDefault: false
51
+ };
52
+ }
53
+ }
54
+ }
55
+ return {
56
+ matchedRouteIndex: -1,
57
+ matchedRouteName: "Default",
58
+ isDefault: true
59
+ };
60
+ }
61
+ async function switchStep(input) {
62
+ "use step";
63
+ return withStepLogging(input, () => Promise.resolve(evaluateSwitch(input)));
64
+ }
65
+ switchStep.maxRetries = 0;
66
+ export {
67
+ switchStep
68
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-workflow-builder",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "Next.js plugin for Workflow Builder",
6
6
  "repository": "https://github.com/emulienfou/next-workflow-builder",