next-workflow-builder 0.5.0 → 0.7.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/README.md +1 -1
  3. package/dist/chunk-5J6TNMJG.js +1 -0
  4. package/dist/chunk-6UXAINJQ.js +1 -0
  5. package/dist/chunk-7WFHHPX4.js +1 -0
  6. package/dist/chunk-BNX2SV7E.js +1 -0
  7. package/dist/chunk-CYVALTSI.js +218 -0
  8. package/dist/chunk-DMHGXYVW.js +14 -0
  9. package/dist/chunk-HB2H2PVI.js +42 -0
  10. package/dist/chunk-IEOZJAW2.js +1 -0
  11. package/dist/chunk-KFTXS23Q.js +1 -0
  12. package/dist/chunk-NI6U7PHC.js +76 -0
  13. package/dist/chunk-PRVESNIO.js +1 -0
  14. package/dist/chunk-QRG4O4PE.js +2 -0
  15. package/dist/chunk-R5GS6TJS.js +1 -0
  16. package/dist/client/index.js +160 -13725
  17. package/dist/condition-CFAA7UDI.js +1 -0
  18. package/dist/database-query-OHFQUPLV.js +1 -0
  19. package/dist/handler-NWAMWKXW.js +1 -0
  20. package/dist/http-request-EHJHOTNA.js +1 -0
  21. package/dist/loop-5LPVY452.js +1 -0
  22. package/dist/merge-HYBHX22D.js +1 -0
  23. package/dist/next/index.d.ts +9 -0
  24. package/dist/next/index.js +1 -84
  25. package/dist/plugins/index.js +1 -54
  26. package/dist/server/api/index.d.ts +30 -1
  27. package/dist/server/api/index.js +18 -2360
  28. package/dist/server/index.js +1 -60
  29. package/dist/switch-ZPVREROE.js +1 -0
  30. package/drizzle.config.ts +9 -0
  31. package/package.json +27 -2
  32. package/src/plugins/types.ts +31 -0
  33. package/src/server/db/schema.ts +228 -0
  34. package/src/server/lib/utils/id.ts +26 -0
  35. package/dist/chunk-3XFDIK7H.js +0 -251
  36. package/dist/chunk-5H76TY4T.js +0 -51
  37. package/dist/chunk-5YYA34YV.js +0 -96
  38. package/dist/chunk-C7GDB4KC.js +0 -550
  39. package/dist/chunk-CKE7ETZL.js +0 -169
  40. package/dist/chunk-EMCA7GLF.js +0 -1305
  41. package/dist/chunk-J72T2LRL.js +0 -66
  42. package/dist/chunk-JUV5RBYM.js +0 -105
  43. package/dist/chunk-O3I2INCD.js +0 -71
  44. package/dist/chunk-OQHML4II.js +0 -36
  45. package/dist/chunk-PEVVELQ6.js +0 -438
  46. package/dist/condition-VHC4KYLI.js +0 -29
  47. package/dist/database-query-BYPF5CDB.js +0 -99
  48. package/dist/http-request-4OT32ZXA.js +0 -76
  49. package/dist/loop-S5H7DSCB.js +0 -47
  50. package/dist/merge-X5JAIZSZ.js +0 -107
  51. package/dist/style-prefixed.css +0 -5167
  52. package/dist/switch-WZBVDWWR.js +0 -68
@@ -1,169 +0,0 @@
1
- import {
2
- db,
3
- integrations
4
- } from "./chunk-PEVVELQ6.js";
5
-
6
- // src/server/db/integrations.ts
7
- import "server-only";
8
- import { and, eq, inArray } from "drizzle-orm";
9
- import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
10
- var ALGORITHM = "aes-256-gcm";
11
- var IV_LENGTH = 16;
12
- var ENCRYPTION_KEY_ENV = "INTEGRATION_ENCRYPTION_KEY";
13
- function getEncryptionKey() {
14
- const keyHex = process.env[ENCRYPTION_KEY_ENV];
15
- if (!keyHex) {
16
- throw new Error(
17
- `${ENCRYPTION_KEY_ENV} environment variable is required for encrypting integration credentials`
18
- );
19
- }
20
- if (keyHex.length !== 64) {
21
- throw new Error(
22
- `${ENCRYPTION_KEY_ENV} must be a 64-character hex string (32 bytes)`
23
- );
24
- }
25
- return Buffer.from(keyHex, "hex");
26
- }
27
- function encrypt(plaintext) {
28
- const key = getEncryptionKey();
29
- const iv = randomBytes(IV_LENGTH);
30
- const cipher = createCipheriv(ALGORITHM, key, iv);
31
- let encrypted = cipher.update(plaintext, "utf8", "hex");
32
- encrypted += cipher.final("hex");
33
- const authTag = cipher.getAuthTag();
34
- return `${iv.toString("hex")}:${authTag.toString("hex")}:${encrypted}`;
35
- }
36
- function decrypt(ciphertext) {
37
- const key = getEncryptionKey();
38
- const parts = ciphertext.split(":");
39
- if (parts.length !== 3) {
40
- throw new Error("Invalid encrypted data format");
41
- }
42
- const iv = Buffer.from(parts[0], "hex");
43
- const authTag = Buffer.from(parts[1], "hex");
44
- const encrypted = parts[2];
45
- const decipher = createDecipheriv(ALGORITHM, key, iv);
46
- decipher.setAuthTag(authTag);
47
- let decrypted = decipher.update(encrypted, "hex", "utf8");
48
- decrypted += decipher.final("utf8");
49
- return decrypted;
50
- }
51
- function encryptConfig(config) {
52
- return encrypt(JSON.stringify(config));
53
- }
54
- function decryptConfig(encryptedConfig) {
55
- try {
56
- const decrypted = decrypt(encryptedConfig);
57
- return JSON.parse(decrypted);
58
- } catch (error) {
59
- console.error("Failed to decrypt integration config:", error);
60
- return {};
61
- }
62
- }
63
- async function getIntegrations(userId, type) {
64
- const conditions = [eq(integrations.userId, userId)];
65
- if (type) {
66
- conditions.push(eq(integrations.type, type));
67
- }
68
- const results = await db.select().from(integrations).where(and(...conditions));
69
- return results.map((integration) => ({
70
- ...integration,
71
- config: decryptConfig(integration.config)
72
- }));
73
- }
74
- async function getIntegration(integrationId, userId) {
75
- const result = await db.select().from(integrations).where(
76
- and(eq(integrations.id, integrationId), eq(integrations.userId, userId))
77
- ).limit(1);
78
- if (result.length === 0) {
79
- return null;
80
- }
81
- return {
82
- ...result[0],
83
- config: decryptConfig(result[0].config)
84
- };
85
- }
86
- async function getIntegrationById(integrationId) {
87
- const result = await db.select().from(integrations).where(eq(integrations.id, integrationId)).limit(1);
88
- if (result.length === 0) {
89
- return null;
90
- }
91
- return {
92
- ...result[0],
93
- config: decryptConfig(result[0].config)
94
- };
95
- }
96
- async function createIntegration(userId, name, type, config) {
97
- const encryptedConfig = encryptConfig(config);
98
- const [result] = await db.insert(integrations).values({
99
- userId,
100
- name,
101
- type,
102
- config: encryptedConfig
103
- }).returning();
104
- return {
105
- ...result,
106
- config
107
- };
108
- }
109
- async function updateIntegration(integrationId, userId, updates) {
110
- const updateData = {
111
- updatedAt: /* @__PURE__ */ new Date()
112
- };
113
- if (updates.name !== void 0) {
114
- updateData.name = updates.name;
115
- }
116
- if (updates.config !== void 0) {
117
- updateData.config = encryptConfig(updates.config);
118
- }
119
- const [result] = await db.update(integrations).set(updateData).where(
120
- and(eq(integrations.id, integrationId), eq(integrations.userId, userId))
121
- ).returning();
122
- if (!result) {
123
- return null;
124
- }
125
- return {
126
- ...result,
127
- config: decryptConfig(result.config)
128
- };
129
- }
130
- async function deleteIntegration(integrationId, userId) {
131
- const result = await db.delete(integrations).where(
132
- and(eq(integrations.id, integrationId), eq(integrations.userId, userId))
133
- ).returning();
134
- return result.length > 0;
135
- }
136
- function extractIntegrationIds(nodes) {
137
- const integrationIds = [];
138
- for (const node of nodes) {
139
- const integrationId = node.data?.config?.integrationId;
140
- if (integrationId && typeof integrationId === "string") {
141
- integrationIds.push(integrationId);
142
- }
143
- }
144
- return [...new Set(integrationIds)];
145
- }
146
- async function validateWorkflowIntegrations(nodes, userId) {
147
- const integrationIds = extractIntegrationIds(nodes);
148
- if (integrationIds.length === 0) {
149
- return { valid: true };
150
- }
151
- const existingIntegrations = await db.select({ id: integrations.id, userId: integrations.userId }).from(integrations).where(inArray(integrations.id, integrationIds));
152
- const invalidIds = existingIntegrations.filter((i) => i.userId !== userId).map((i) => i.id);
153
- if (invalidIds.length > 0) {
154
- return { valid: false, invalidIds };
155
- }
156
- return { valid: true };
157
- }
158
-
159
- export {
160
- encrypt,
161
- decrypt,
162
- getIntegrations,
163
- getIntegration,
164
- getIntegrationById,
165
- createIntegration,
166
- updateIntegration,
167
- deleteIntegration,
168
- validateWorkflowIntegrations
169
- };