next-workflow-builder 0.3.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.
@@ -0,0 +1,29 @@
1
+ import "./chunk-7MUXUHEL.js";
2
+ import "./chunk-D44JFQYX.js";
3
+ import "./chunk-P3DTV3QS.js";
4
+ import "./chunk-5YYA34YV.js";
5
+ import "./chunk-OQHML4II.js";
6
+ import "./chunk-DJ7ANVJ3.js";
7
+ import "./chunk-BNYDOC3I.js";
8
+ import "./chunk-Z3BJJYHM.js";
9
+ import "./chunk-O3I2INCD.js";
10
+ import {
11
+ withStepLogging
12
+ } from "./chunk-3MSAF2TH.js";
13
+
14
+ // src/plugins/condition/condition.ts
15
+ import "server-only";
16
+ function evaluateCondition(input) {
17
+ return { condition: input.condition };
18
+ }
19
+ async function conditionStep(input) {
20
+ "use step";
21
+ return withStepLogging(
22
+ input,
23
+ () => Promise.resolve(evaluateCondition(input))
24
+ );
25
+ }
26
+ conditionStep.maxRetries = 0;
27
+ export {
28
+ conditionStep
29
+ };
@@ -0,0 +1,99 @@
1
+ import {
2
+ fetchCredentials
3
+ } from "./chunk-DJ7ANVJ3.js";
4
+ import "./chunk-BNYDOC3I.js";
5
+ import "./chunk-Z3BJJYHM.js";
6
+ import {
7
+ withStepLogging
8
+ } from "./chunk-3MSAF2TH.js";
9
+
10
+ // src/plugins/database-query/database-query.ts
11
+ import "server-only";
12
+ import { sql } from "drizzle-orm";
13
+ import { drizzle } from "drizzle-orm/postgres-js";
14
+ import postgres from "postgres";
15
+ function validateInput(input) {
16
+ const queryString = input.dbQuery || input.query;
17
+ if (!queryString || queryString.trim() === "") {
18
+ return "SQL query is required";
19
+ }
20
+ return null;
21
+ }
22
+ function createDatabaseClient(databaseUrl) {
23
+ return postgres(databaseUrl, {
24
+ max: 1,
25
+ connect_timeout: 10,
26
+ idle_timeout: 20
27
+ });
28
+ }
29
+ async function executeQuery(client, queryString) {
30
+ const db = drizzle(client);
31
+ return await db.execute(sql.raw(queryString));
32
+ }
33
+ function getDatabaseErrorMessage(error) {
34
+ if (!(error instanceof Error)) {
35
+ return "Unknown database error";
36
+ }
37
+ const errorMessage = error.message;
38
+ if (errorMessage.includes("ECONNREFUSED")) {
39
+ return "Connection refused. Please check your database URL and ensure the database is running.";
40
+ }
41
+ if (errorMessage.includes("ENOTFOUND")) {
42
+ return "Database host not found. Please check your database URL.";
43
+ }
44
+ if (errorMessage.includes("authentication failed")) {
45
+ return "Authentication failed. Please check your database credentials.";
46
+ }
47
+ if (errorMessage.includes("does not exist")) {
48
+ return `Database error: ${errorMessage}`;
49
+ }
50
+ return errorMessage;
51
+ }
52
+ async function cleanupClient(client) {
53
+ if (client) {
54
+ try {
55
+ await client.end();
56
+ } catch {
57
+ }
58
+ }
59
+ }
60
+ async function databaseQuery(input) {
61
+ const validationError = validateInput(input);
62
+ if (validationError) {
63
+ return { success: false, error: validationError };
64
+ }
65
+ const credentials = input.integrationId ? await fetchCredentials(input.integrationId) : {};
66
+ const databaseUrl = credentials.DATABASE_URL;
67
+ if (!databaseUrl) {
68
+ return {
69
+ success: false,
70
+ error: "DATABASE_URL is not configured. Please add it in Project Integrations."
71
+ };
72
+ }
73
+ const queryString = input.dbQuery || input.query;
74
+ let client = null;
75
+ try {
76
+ client = createDatabaseClient(databaseUrl);
77
+ const result = await executeQuery(client, queryString);
78
+ await client.end();
79
+ return {
80
+ success: true,
81
+ rows: result,
82
+ count: Array.isArray(result) ? result.length : 0
83
+ };
84
+ } catch (error) {
85
+ await cleanupClient(client);
86
+ return {
87
+ success: false,
88
+ error: `Database query failed: ${getDatabaseErrorMessage(error)}`
89
+ };
90
+ }
91
+ }
92
+ async function databaseQueryStep(input) {
93
+ "use step";
94
+ return withStepLogging(input, () => databaseQuery(input));
95
+ }
96
+ databaseQueryStep.maxRetries = 0;
97
+ export {
98
+ databaseQueryStep
99
+ };
@@ -0,0 +1,76 @@
1
+ import {
2
+ getErrorMessage
3
+ } from "./chunk-O3I2INCD.js";
4
+ import {
5
+ withStepLogging
6
+ } from "./chunk-3MSAF2TH.js";
7
+
8
+ // src/plugins/http-request/http-request.ts
9
+ import "server-only";
10
+ function parseHeaders(httpHeaders) {
11
+ if (!httpHeaders) {
12
+ return {};
13
+ }
14
+ try {
15
+ return JSON.parse(httpHeaders);
16
+ } catch {
17
+ return {};
18
+ }
19
+ }
20
+ function parseBody(httpMethod, httpBody) {
21
+ if (httpMethod === "GET" || !httpBody) {
22
+ return;
23
+ }
24
+ try {
25
+ const parsedBody = JSON.parse(httpBody);
26
+ return Object.keys(parsedBody).length > 0 ? JSON.stringify(parsedBody) : void 0;
27
+ } catch {
28
+ const trimmed = httpBody.trim();
29
+ return trimmed && trimmed !== "{}" ? httpBody : void 0;
30
+ }
31
+ }
32
+ function parseResponse(response) {
33
+ const contentType = response.headers.get("content-type");
34
+ if (contentType?.includes("application/json")) {
35
+ return response.json();
36
+ }
37
+ return response.text();
38
+ }
39
+ async function httpRequest(input) {
40
+ if (!input.endpoint) {
41
+ return {
42
+ success: false,
43
+ error: "HTTP request failed: URL is required"
44
+ };
45
+ }
46
+ try {
47
+ const response = await fetch(input.endpoint, {
48
+ method: input.httpMethod,
49
+ headers: parseHeaders(input.httpHeaders),
50
+ body: parseBody(input.httpMethod, input.httpBody)
51
+ });
52
+ if (!response.ok) {
53
+ const errorText = await response.text().catch(() => "Unknown error");
54
+ return {
55
+ success: false,
56
+ error: `HTTP request failed with status ${response.status}: ${errorText}`,
57
+ status: response.status
58
+ };
59
+ }
60
+ const data = await parseResponse(response);
61
+ return { success: true, data, status: response.status };
62
+ } catch (error) {
63
+ return {
64
+ success: false,
65
+ error: `HTTP request failed: ${getErrorMessage(error)}`
66
+ };
67
+ }
68
+ }
69
+ async function httpRequestStep(input) {
70
+ "use step";
71
+ return withStepLogging(input, () => httpRequest(input));
72
+ }
73
+ httpRequestStep.maxRetries = 0;
74
+ export {
75
+ httpRequestStep
76
+ };
@@ -0,0 +1,42 @@
1
+ import { NextConfig } from 'next';
2
+ import { z } from 'zod';
3
+
4
+ declare const NextWorkflowBuilderConfigSchema: z.ZodObject<{
5
+ /** Enable debug logging. */
6
+ debug: z.ZodOptional<z.ZodBoolean>;
7
+ /** Set Better Auth options (must be JSON-serializable). */
8
+ authOptions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
9
+ }, z.core.$strict>;
10
+
11
+ /**
12
+ * Configuration options for the Next Workflow Builder plugin.
13
+ * Infer the type from the schema
14
+ */
15
+ type NextWorkflowBuilderConfig = z.infer<typeof NextWorkflowBuilderConfigSchema>;
16
+ /**
17
+ * A function that wraps a Next.js config with Workflow Builder functionality.
18
+ */
19
+ type WithNextWorkflowBuilder = (nextConfig?: NextConfig) => NextConfig;
20
+
21
+ /**
22
+ * Next.js plugin for Workflow Builder.
23
+ *
24
+ * @example
25
+ * ```js
26
+ * // next.config.ts
27
+ * import nextWorkflowBuilder from 'next-workflow-builder'
28
+ *
29
+ * // Set up NextWorkflowBuilder with its configuration
30
+ * const withNextWorkflowBuilder = nextWorkflowBuilder({
31
+ * // ... Add NextWorkflowBuilder-specific options here
32
+ * })
33
+ *
34
+ * // Export the final Next.js config with NextWorkflowBuilder included
35
+ * export default withNextWorkflowBuilder({
36
+ * // ... Add regular Next.js options here
37
+ * })
38
+ * ```
39
+ */
40
+ declare const nextWorkflowBuilder: (config?: NextWorkflowBuilderConfig) => WithNextWorkflowBuilder;
41
+
42
+ export { type NextWorkflowBuilderConfig, type WithNextWorkflowBuilder, nextWorkflowBuilder as default };
@@ -0,0 +1,66 @@
1
+ import {
2
+ discoverPlugins
3
+ } from "../chunk-D44JFQYX.js";
4
+ import "../chunk-OQHML4II.js";
5
+ import "../chunk-Z3BJJYHM.js";
6
+
7
+ // src/next/index.ts
8
+ import { join } from "path";
9
+ import { z as z2 } from "zod";
10
+
11
+ // src/next/schema.ts
12
+ import { z } from "zod";
13
+ var NextWorkflowBuilderConfigSchema = z.strictObject({
14
+ /** Enable debug logging. */
15
+ debug: z.boolean().optional(),
16
+ /** Set Better Auth options (must be JSON-serializable). */
17
+ authOptions: z.record(z.string(), z.unknown()).optional()
18
+ });
19
+
20
+ // src/next/index.ts
21
+ var VIRTUAL_PLUGINS_MODULE = "virtual:workflow-builder-plugins";
22
+ var VIRTUAL_STEP_REGISTRY_MODULE = "virtual:workflow-builder-step-registry";
23
+ var nextWorkflowBuilder = (config = {}) => {
24
+ const { error, data: loaderOptions } = NextWorkflowBuilderConfigSchema.safeParse(config);
25
+ if (error) {
26
+ console.error("Error validating NextWorkflowBuilderConfig");
27
+ throw z2.prettifyError(error);
28
+ }
29
+ if (loaderOptions.authOptions) {
30
+ process.env.__NWB_AUTH_OPTIONS = JSON.stringify(loaderOptions.authOptions);
31
+ }
32
+ discoverPlugins();
33
+ return function withNextWorkflowBuilder(nextConfig = {}) {
34
+ const consumerPluginsRelative = "./plugins/index.ts";
35
+ const consumerPluginsAbsolute = join(process.cwd(), "plugins", "index.ts");
36
+ const consumerStepRegistryRelative = "./lib/step-registry.ts";
37
+ const consumerStepRegistryAbsolute = join(process.cwd(), "lib", "step-registry.ts");
38
+ return {
39
+ ...nextConfig,
40
+ // Turbopack alias (used by `next dev` in Next.js 15+)
41
+ turbopack: {
42
+ ...nextConfig.turbopack,
43
+ resolveAlias: {
44
+ ...nextConfig.turbopack?.resolveAlias,
45
+ [VIRTUAL_PLUGINS_MODULE]: consumerPluginsRelative,
46
+ [VIRTUAL_STEP_REGISTRY_MODULE]: consumerStepRegistryRelative
47
+ }
48
+ },
49
+ // Webpack alias (used by `next build`)
50
+ webpack: (webpackConfig, options) => {
51
+ webpackConfig.resolve = webpackConfig.resolve || {};
52
+ webpackConfig.resolve.alias = webpackConfig.resolve.alias || {};
53
+ webpackConfig.resolve.alias[VIRTUAL_PLUGINS_MODULE] = consumerPluginsAbsolute;
54
+ webpackConfig.resolve.alias[VIRTUAL_STEP_REGISTRY_MODULE] = consumerStepRegistryAbsolute;
55
+ if (typeof nextConfig.webpack === "function") {
56
+ return nextConfig.webpack(webpackConfig, options);
57
+ }
58
+ return webpackConfig;
59
+ }
60
+ };
61
+ };
62
+ };
63
+ var next_default = nextWorkflowBuilder;
64
+ export {
65
+ next_default as default
66
+ };
@@ -0,0 +1,113 @@
1
+ import { I as IntegrationType, A as ActionWithFullId, a as ActionConfigField, b as ActionConfigFieldBase, c as IntegrationPlugin, S as SerializableOutputDisplayConfig, d as ActionConfigFieldGroup } from '../types-BACZx2Ft.js';
2
+ export { P as PluginAction } from '../types-BACZx2Ft.js';
3
+
4
+ /**
5
+ * Register codegen templates (called from consumer's auto-generated codegen-registry.ts)
6
+ */
7
+ declare function registerCodegenTemplates(templates: Record<string, string>): void;
8
+ /**
9
+ * Get a codegen template for an action
10
+ */
11
+ declare function getCodegenTemplate(actionId: string): string | undefined;
12
+ /**
13
+ * Register output display configs (called from consumer's auto-generated output-display-configs.ts)
14
+ */
15
+ declare function registerOutputDisplayConfigs(configs: Record<string, SerializableOutputDisplayConfig>): void;
16
+ /**
17
+ * Get the output display config for an action
18
+ */
19
+ declare function getOutputDisplayConfig(actionId: string): SerializableOutputDisplayConfig | undefined;
20
+ /**
21
+ * Compute full action ID from integration type and action slug
22
+ */
23
+ declare function computeActionId(integrationType: IntegrationType, actionSlug: string): string;
24
+ /**
25
+ * Parse a full action ID into integration type and action slug
26
+ */
27
+ declare function parseActionId(actionId: string | undefined | null): {
28
+ integration: string;
29
+ slug: string;
30
+ } | null;
31
+ /**
32
+ * Register an integration plugin
33
+ */
34
+ declare function registerIntegration(plugin: IntegrationPlugin): void;
35
+ /**
36
+ * Get an integration plugin
37
+ */
38
+ declare function getIntegration(type: IntegrationType): IntegrationPlugin | undefined;
39
+ /**
40
+ * Get all registered integrations
41
+ */
42
+ declare function getAllIntegrations(): IntegrationPlugin[];
43
+ /**
44
+ * Get all integration types
45
+ */
46
+ declare function getIntegrationTypes(): IntegrationType[];
47
+ /**
48
+ * Get all actions across all integrations with full IDs
49
+ */
50
+ declare function getAllActions(): ActionWithFullId[];
51
+ /**
52
+ * Get actions by category
53
+ */
54
+ declare function getActionsByCategory(): Record<string, ActionWithFullId[]>;
55
+ /**
56
+ * Find an action by full ID (e.g., "resend/send-email")
57
+ * Also supports legacy IDs (e.g., "Send Email") for backward compatibility
58
+ */
59
+ declare function findActionById(actionId: string | undefined | null): ActionWithFullId | undefined;
60
+ /**
61
+ * Get integration labels map
62
+ */
63
+ declare function getIntegrationLabels(): Record<IntegrationType, string>;
64
+ /**
65
+ * Get integration descriptions map
66
+ */
67
+ declare function getIntegrationDescriptions(): Record<IntegrationType, string>;
68
+ /**
69
+ * Get sorted integration types for dropdowns
70
+ */
71
+ declare function getSortedIntegrationTypes(): IntegrationType[];
72
+ /**
73
+ * Get all NPM dependencies across all integrations
74
+ */
75
+ declare function getAllDependencies(): Record<string, string>;
76
+ /**
77
+ * Get NPM dependencies for specific action IDs
78
+ */
79
+ declare function getDependenciesForActions(actionIds: string[]): Record<string, string>;
80
+ /**
81
+ * Get environment variables for a single plugin (from formFields)
82
+ */
83
+ declare function getPluginEnvVars(plugin: IntegrationPlugin): Array<{
84
+ name: string;
85
+ description: string;
86
+ }>;
87
+ /**
88
+ * Get all environment variables across all integrations
89
+ */
90
+ declare function getAllEnvVars(): Array<{
91
+ name: string;
92
+ description: string;
93
+ }>;
94
+ /**
95
+ * Get credential mapping for a plugin (auto-generated from formFields)
96
+ */
97
+ declare function getCredentialMapping(plugin: IntegrationPlugin, config: Record<string, unknown>): Record<string, string>;
98
+ /**
99
+ * Type guard to check if a field is a group
100
+ */
101
+ declare function isFieldGroup(field: ActionConfigField): field is ActionConfigFieldGroup;
102
+ /**
103
+ * Flatten config fields, extracting fields from groups
104
+ * Useful for validation and AI prompt generation
105
+ */
106
+ declare function flattenConfigFields(fields: ActionConfigField[]): ActionConfigFieldBase[];
107
+ /**
108
+ * Generate AI prompt section for all available actions
109
+ * This dynamically builds the action types documentation for the AI
110
+ */
111
+ declare function generateAIActionPrompts(): string;
112
+
113
+ export { ActionConfigField, ActionConfigFieldBase, ActionConfigFieldGroup, ActionWithFullId, IntegrationPlugin, computeActionId, findActionById, flattenConfigFields, generateAIActionPrompts, getActionsByCategory, getAllActions, getAllDependencies, getAllEnvVars, getAllIntegrations, getCodegenTemplate, getCredentialMapping, getDependenciesForActions, getIntegration, getIntegrationDescriptions, getIntegrationLabels, getIntegrationTypes, getOutputDisplayConfig, getPluginEnvVars, getSortedIntegrationTypes, isFieldGroup, parseActionId, registerCodegenTemplates, registerIntegration, registerOutputDisplayConfigs };
@@ -0,0 +1,52 @@
1
+ import {
2
+ computeActionId,
3
+ findActionById,
4
+ flattenConfigFields,
5
+ generateAIActionPrompts,
6
+ getActionsByCategory,
7
+ getAllActions,
8
+ getAllDependencies,
9
+ getAllEnvVars,
10
+ getAllIntegrations,
11
+ getCodegenTemplate,
12
+ getCredentialMapping,
13
+ getDependenciesForActions,
14
+ getIntegration,
15
+ getIntegrationDescriptions,
16
+ getIntegrationLabels,
17
+ getIntegrationTypes,
18
+ getOutputDisplayConfig,
19
+ getPluginEnvVars,
20
+ getSortedIntegrationTypes,
21
+ isFieldGroup,
22
+ parseActionId,
23
+ registerCodegenTemplates,
24
+ registerIntegration,
25
+ registerOutputDisplayConfigs
26
+ } from "../chunk-Z3BJJYHM.js";
27
+ export {
28
+ computeActionId,
29
+ findActionById,
30
+ flattenConfigFields,
31
+ generateAIActionPrompts,
32
+ getActionsByCategory,
33
+ getAllActions,
34
+ getAllDependencies,
35
+ getAllEnvVars,
36
+ getAllIntegrations,
37
+ getCodegenTemplate,
38
+ getCredentialMapping,
39
+ getDependenciesForActions,
40
+ getIntegration,
41
+ getIntegrationDescriptions,
42
+ getIntegrationLabels,
43
+ getIntegrationTypes,
44
+ getOutputDisplayConfig,
45
+ getPluginEnvVars,
46
+ getSortedIntegrationTypes,
47
+ isFieldGroup,
48
+ parseActionId,
49
+ registerCodegenTemplates,
50
+ registerIntegration,
51
+ registerOutputDisplayConfigs
52
+ };
@@ -0,0 +1,8 @@
1
+ declare function GET(request: Request): Promise<Response>;
2
+ declare function POST(request: Request): Promise<Response>;
3
+ declare function PUT(request: Request): Promise<Response>;
4
+ declare function PATCH(request: Request): Promise<Response>;
5
+ declare function DELETE(request: Request): Promise<Response>;
6
+ declare function OPTIONS(_request: Request): Promise<Response>;
7
+
8
+ export { DELETE, GET, OPTIONS, PATCH, POST, PUT };