@revenexx/integrations-node-devkit 0.1.0 → 0.2.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.
- package/README.md +3 -2
- package/package.json +3 -2
- package/dist/chunk-WPZPKJAS.js +0 -1209
- package/dist/chunk-WPZPKJAS.js.map +0 -1
- package/dist/cli.cjs +0 -1967
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.js +0 -779
- package/dist/cli.js.map +0 -1
- package/dist/index.cjs +0 -1269
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -308
- package/dist/index.d.ts +0 -308
- package/dist/index.js +0 -59
- package/dist/index.js.map +0 -1
- package/dist/testing/index.cjs +0 -215
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -194
- package/dist/testing/index.d.ts +0 -194
- package/dist/testing/index.js +0 -179
- package/dist/testing/index.js.map +0 -1
package/dist/index.cjs
DELETED
|
@@ -1,1269 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
DEVKIT_VERSION: () => DEVKIT_VERSION,
|
|
34
|
-
DEV_TENANT_ID: () => DEV_TENANT_ID,
|
|
35
|
-
DevApiError: () => DevApiError,
|
|
36
|
-
DevStore: () => DevStore,
|
|
37
|
-
STORE_SCHEMA_VERSION: () => STORE_SCHEMA_VERSION,
|
|
38
|
-
applySeeds: () => applySeeds,
|
|
39
|
-
buildOAuthAuthorizeUrl: () => buildOAuthAuthorizeUrl,
|
|
40
|
-
createDevServer: () => createDevServer,
|
|
41
|
-
createRequestListener: () => createRequestListener,
|
|
42
|
-
ensureTsxRegistered: () => ensureTsxRegistered,
|
|
43
|
-
exchangeOAuthCode: () => exchangeOAuthCode,
|
|
44
|
-
findCredential: () => findCredential,
|
|
45
|
-
findCredentialType: () => findCredentialType,
|
|
46
|
-
findNode: () => findNode,
|
|
47
|
-
importFresh: () => importFresh,
|
|
48
|
-
interpolateEnv: () => interpolateEnv,
|
|
49
|
-
loadPackageFromEntry: () => loadPackageFromEntry,
|
|
50
|
-
loadSeedsFromDir: () => loadSeedsFromDir,
|
|
51
|
-
loadState: () => loadState,
|
|
52
|
-
nodeVersions: () => nodeVersions,
|
|
53
|
-
resolveCredentialInstance: () => resolveCredentialInstance,
|
|
54
|
-
resolveExports: () => resolveExports,
|
|
55
|
-
resolveNodeConfig: () => resolveNodeConfig,
|
|
56
|
-
saveState: () => saveState,
|
|
57
|
-
testCredentialConfig: () => testCredentialConfig,
|
|
58
|
-
testCredentialInstance: () => testCredentialInstance,
|
|
59
|
-
validateNodeConfig: () => validateNodeConfig
|
|
60
|
-
});
|
|
61
|
-
module.exports = __toCommonJS(index_exports);
|
|
62
|
-
|
|
63
|
-
// src/errors.ts
|
|
64
|
-
var DevApiError = class extends Error {
|
|
65
|
-
constructor(status, message, errors) {
|
|
66
|
-
super(message);
|
|
67
|
-
this.status = status;
|
|
68
|
-
this.errors = errors;
|
|
69
|
-
this.name = "DevApiError";
|
|
70
|
-
}
|
|
71
|
-
status;
|
|
72
|
-
errors;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// src/loader.ts
|
|
76
|
-
var import_node_url = require("url");
|
|
77
|
-
var import_integrations_node_sdk = require("@revenexx/integrations-node-sdk");
|
|
78
|
-
function resolveExports(mod) {
|
|
79
|
-
if (!Array.isArray(mod.NODES)) {
|
|
80
|
-
throw new Error("Package entry does not export a `NODES` array. Export `NODES: INode[]`.");
|
|
81
|
-
}
|
|
82
|
-
if (mod.CREDENTIALS !== void 0 && !Array.isArray(mod.CREDENTIALS)) {
|
|
83
|
-
throw new Error("Package entry exports `CREDENTIALS` but it is not an array.");
|
|
84
|
-
}
|
|
85
|
-
if (mod.TEMPLATES !== void 0 && !Array.isArray(mod.TEMPLATES)) {
|
|
86
|
-
throw new Error("Package entry exports `TEMPLATES` but it is not an array.");
|
|
87
|
-
}
|
|
88
|
-
const nodes = mod.NODES;
|
|
89
|
-
const credentials = mod.CREDENTIALS ?? [];
|
|
90
|
-
const templates = mod.TEMPLATES ?? [];
|
|
91
|
-
return {
|
|
92
|
-
nodes,
|
|
93
|
-
credentials,
|
|
94
|
-
templates,
|
|
95
|
-
manifest: (0, import_integrations_node_sdk.buildManifest)(nodes, credentials, templates)
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
var tsxRegistered = false;
|
|
99
|
-
async function ensureTsxRegistered() {
|
|
100
|
-
if (tsxRegistered) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const { register } = await import("tsx/esm/api");
|
|
104
|
-
register();
|
|
105
|
-
tsxRegistered = true;
|
|
106
|
-
}
|
|
107
|
-
async function importFresh(entryPath) {
|
|
108
|
-
if (/\.[cm]?tsx?$/.test(entryPath)) {
|
|
109
|
-
await ensureTsxRegistered();
|
|
110
|
-
}
|
|
111
|
-
const href = `${(0, import_node_url.pathToFileURL)(entryPath).href}?t=${Date.now()}`;
|
|
112
|
-
return await import(href);
|
|
113
|
-
}
|
|
114
|
-
async function loadPackageFromEntry(entryPath) {
|
|
115
|
-
return resolveExports(await importFresh(entryPath));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// src/persistence.ts
|
|
119
|
-
var import_node_fs = require("fs");
|
|
120
|
-
var import_node_path = require("path");
|
|
121
|
-
|
|
122
|
-
// src/store.ts
|
|
123
|
-
var import_node_crypto = require("crypto");
|
|
124
|
-
var DEV_TENANT_ID = "dev-tenant";
|
|
125
|
-
var STORE_SCHEMA_VERSION = 1;
|
|
126
|
-
function now() {
|
|
127
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
128
|
-
}
|
|
129
|
-
var DevStore = class {
|
|
130
|
-
/**
|
|
131
|
-
* @param onChange fired after any mutation so a caller (the CLI) can persist
|
|
132
|
-
* the session to `.revenexx-dev/state.json`.
|
|
133
|
-
*/
|
|
134
|
-
constructor(onChange) {
|
|
135
|
-
this.onChange = onChange;
|
|
136
|
-
}
|
|
137
|
-
onChange;
|
|
138
|
-
credentials = /* @__PURE__ */ new Map();
|
|
139
|
-
secrets = /* @__PURE__ */ new Map();
|
|
140
|
-
workflows = /* @__PURE__ */ new Map();
|
|
141
|
-
triggers = /* @__PURE__ */ new Map();
|
|
142
|
-
nextWorkflowId = 1;
|
|
143
|
-
/** (Re)wire the post-mutation callback — e.g. attach it only after seeding. */
|
|
144
|
-
setOnMutation(onChange) {
|
|
145
|
-
this.onChange = onChange;
|
|
146
|
-
}
|
|
147
|
-
touch() {
|
|
148
|
-
this.onChange?.();
|
|
149
|
-
}
|
|
150
|
-
// ------------------------------------------------------------- credentials
|
|
151
|
-
listCredentials(typeSlug) {
|
|
152
|
-
const all = [...this.credentials.values()];
|
|
153
|
-
return typeSlug ? all.filter((c) => c.credentialTypeSlug === typeSlug) : all;
|
|
154
|
-
}
|
|
155
|
-
getCredential(id) {
|
|
156
|
-
return this.credentials.get(id);
|
|
157
|
-
}
|
|
158
|
-
createCredential(input) {
|
|
159
|
-
const ts = now();
|
|
160
|
-
const record = {
|
|
161
|
-
id: input.id ?? (0, import_node_crypto.randomUUID)(),
|
|
162
|
-
tenantId: DEV_TENANT_ID,
|
|
163
|
-
credentialTypeSlug: input.credentialTypeSlug,
|
|
164
|
-
name: input.name,
|
|
165
|
-
status: input.status ?? "active",
|
|
166
|
-
config: input.config,
|
|
167
|
-
durableCreds: input.durableCreds ?? null,
|
|
168
|
-
createdAt: ts,
|
|
169
|
-
updatedAt: ts
|
|
170
|
-
};
|
|
171
|
-
this.credentials.set(record.id, record);
|
|
172
|
-
this.touch();
|
|
173
|
-
return record;
|
|
174
|
-
}
|
|
175
|
-
updateCredential(id, patch) {
|
|
176
|
-
const record = this.credentials.get(id);
|
|
177
|
-
if (!record) {
|
|
178
|
-
return void 0;
|
|
179
|
-
}
|
|
180
|
-
if (patch.name !== void 0) {
|
|
181
|
-
record.name = patch.name;
|
|
182
|
-
}
|
|
183
|
-
if (patch.config !== void 0) {
|
|
184
|
-
record.config = patch.config;
|
|
185
|
-
}
|
|
186
|
-
if (patch.status !== void 0) {
|
|
187
|
-
record.status = patch.status;
|
|
188
|
-
}
|
|
189
|
-
if (patch.durableCreds !== void 0) {
|
|
190
|
-
record.durableCreds = patch.durableCreds;
|
|
191
|
-
}
|
|
192
|
-
record.updatedAt = now();
|
|
193
|
-
this.touch();
|
|
194
|
-
return record;
|
|
195
|
-
}
|
|
196
|
-
deleteCredential(id) {
|
|
197
|
-
const deleted = this.credentials.delete(id);
|
|
198
|
-
if (deleted) {
|
|
199
|
-
this.touch();
|
|
200
|
-
}
|
|
201
|
-
return deleted;
|
|
202
|
-
}
|
|
203
|
-
// ----------------------------------------------------------------- secrets
|
|
204
|
-
listSecrets() {
|
|
205
|
-
return [...this.secrets.values()];
|
|
206
|
-
}
|
|
207
|
-
getSecret(key) {
|
|
208
|
-
return this.secrets.get(key);
|
|
209
|
-
}
|
|
210
|
-
setSecret(key, value) {
|
|
211
|
-
const existing = this.secrets.get(key);
|
|
212
|
-
const ts = now();
|
|
213
|
-
const record = {
|
|
214
|
-
key,
|
|
215
|
-
value,
|
|
216
|
-
createdAt: existing?.createdAt ?? ts,
|
|
217
|
-
updatedAt: ts
|
|
218
|
-
};
|
|
219
|
-
this.secrets.set(key, record);
|
|
220
|
-
this.touch();
|
|
221
|
-
return record;
|
|
222
|
-
}
|
|
223
|
-
deleteSecret(key) {
|
|
224
|
-
const deleted = this.secrets.delete(key);
|
|
225
|
-
if (deleted) {
|
|
226
|
-
this.touch();
|
|
227
|
-
}
|
|
228
|
-
return deleted;
|
|
229
|
-
}
|
|
230
|
-
// --------------------------------------------------------------- workflows
|
|
231
|
-
listWorkflows() {
|
|
232
|
-
return [...this.workflows.values()];
|
|
233
|
-
}
|
|
234
|
-
getWorkflow(id) {
|
|
235
|
-
return this.workflows.get(id);
|
|
236
|
-
}
|
|
237
|
-
createWorkflow(input) {
|
|
238
|
-
const ts = now();
|
|
239
|
-
const record = {
|
|
240
|
-
id: this.nextWorkflowId++,
|
|
241
|
-
name: input.name,
|
|
242
|
-
definition: input.definition,
|
|
243
|
-
buildStatus: "ready",
|
|
244
|
-
createdAt: ts,
|
|
245
|
-
updatedAt: ts
|
|
246
|
-
};
|
|
247
|
-
this.workflows.set(record.id, record);
|
|
248
|
-
this.touch();
|
|
249
|
-
return record;
|
|
250
|
-
}
|
|
251
|
-
updateWorkflow(id, patch) {
|
|
252
|
-
const record = this.workflows.get(id);
|
|
253
|
-
if (!record) {
|
|
254
|
-
return void 0;
|
|
255
|
-
}
|
|
256
|
-
Object.assign(record, patch, { updatedAt: now() });
|
|
257
|
-
this.touch();
|
|
258
|
-
return record;
|
|
259
|
-
}
|
|
260
|
-
deleteWorkflow(id) {
|
|
261
|
-
for (const trigger of this.triggers.values()) {
|
|
262
|
-
if (trigger.workflowId === id) {
|
|
263
|
-
this.triggers.delete(trigger.id);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
const deleted = this.workflows.delete(id);
|
|
267
|
-
if (deleted) {
|
|
268
|
-
this.touch();
|
|
269
|
-
}
|
|
270
|
-
return deleted;
|
|
271
|
-
}
|
|
272
|
-
// ---------------------------------------------------------------- triggers
|
|
273
|
-
listTriggers(workflowId) {
|
|
274
|
-
return [...this.triggers.values()].filter((t) => t.workflowId === workflowId);
|
|
275
|
-
}
|
|
276
|
-
getTrigger(id) {
|
|
277
|
-
return this.triggers.get(id);
|
|
278
|
-
}
|
|
279
|
-
createTrigger(input) {
|
|
280
|
-
const ts = now();
|
|
281
|
-
const record = {
|
|
282
|
-
id: input.id ?? (0, import_node_crypto.randomUUID)(),
|
|
283
|
-
workflowId: input.workflowId,
|
|
284
|
-
type: input.type,
|
|
285
|
-
name: input.name ?? null,
|
|
286
|
-
config: input.config ?? {},
|
|
287
|
-
active: input.active ?? true,
|
|
288
|
-
createdAt: ts,
|
|
289
|
-
updatedAt: ts
|
|
290
|
-
};
|
|
291
|
-
this.triggers.set(record.id, record);
|
|
292
|
-
this.touch();
|
|
293
|
-
return record;
|
|
294
|
-
}
|
|
295
|
-
replaceTrigger(id, input) {
|
|
296
|
-
const record = this.triggers.get(id);
|
|
297
|
-
if (!record) {
|
|
298
|
-
return void 0;
|
|
299
|
-
}
|
|
300
|
-
record.type = input.type;
|
|
301
|
-
record.name = input.name ?? null;
|
|
302
|
-
record.config = input.config ?? {};
|
|
303
|
-
record.active = input.active ?? true;
|
|
304
|
-
record.updatedAt = now();
|
|
305
|
-
this.touch();
|
|
306
|
-
return record;
|
|
307
|
-
}
|
|
308
|
-
deleteTrigger(id) {
|
|
309
|
-
const deleted = this.triggers.delete(id);
|
|
310
|
-
if (deleted) {
|
|
311
|
-
this.touch();
|
|
312
|
-
}
|
|
313
|
-
return deleted;
|
|
314
|
-
}
|
|
315
|
-
// ------------------------------------------------------------- persistence
|
|
316
|
-
toSnapshot() {
|
|
317
|
-
return {
|
|
318
|
-
schemaVersion: STORE_SCHEMA_VERSION,
|
|
319
|
-
credentials: [...this.credentials.values()],
|
|
320
|
-
secrets: [...this.secrets.values()],
|
|
321
|
-
workflows: [...this.workflows.values()],
|
|
322
|
-
triggers: [...this.triggers.values()],
|
|
323
|
-
nextWorkflowId: this.nextWorkflowId
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
loadSnapshot(snapshot) {
|
|
327
|
-
this.credentials = new Map(snapshot.credentials.map((c) => [c.id, c]));
|
|
328
|
-
this.secrets = new Map(snapshot.secrets.map((s) => [s.key, s]));
|
|
329
|
-
this.workflows = new Map(snapshot.workflows.map((w) => [w.id, w]));
|
|
330
|
-
this.triggers = new Map(snapshot.triggers.map((t) => [t.id, t]));
|
|
331
|
-
this.nextWorkflowId = snapshot.nextWorkflowId ?? Math.max(0, ...snapshot.workflows.map((w) => w.id)) + 1;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Overlays a snapshot on top of the current contents (upsert by id/key), used
|
|
335
|
-
* to layer the persisted `.revenexx-dev/state.json` session over the freshly
|
|
336
|
-
* applied committed seeds. State entries win over seed entries with the same
|
|
337
|
-
* id/key; seed-only entries are preserved.
|
|
338
|
-
*/
|
|
339
|
-
mergeSnapshot(snapshot) {
|
|
340
|
-
for (const c of snapshot.credentials) {
|
|
341
|
-
this.credentials.set(c.id, c);
|
|
342
|
-
}
|
|
343
|
-
for (const s of snapshot.secrets) {
|
|
344
|
-
this.secrets.set(s.key, s);
|
|
345
|
-
}
|
|
346
|
-
for (const w of snapshot.workflows) {
|
|
347
|
-
this.workflows.set(w.id, w);
|
|
348
|
-
}
|
|
349
|
-
for (const t of snapshot.triggers) {
|
|
350
|
-
this.triggers.set(t.id, t);
|
|
351
|
-
}
|
|
352
|
-
this.nextWorkflowId = Math.max(this.nextWorkflowId, snapshot.nextWorkflowId ?? 0, ...snapshot.workflows.map((w) => w.id + 1));
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
// src/persistence.ts
|
|
357
|
-
var ENV_REF = /\$\{([A-Z0-9_]+)\}/g;
|
|
358
|
-
function interpolateEnv(value, env = process.env) {
|
|
359
|
-
if (typeof value === "string") {
|
|
360
|
-
return value.replace(ENV_REF, (_match, name) => {
|
|
361
|
-
const resolved = env[name];
|
|
362
|
-
if (resolved === void 0) {
|
|
363
|
-
throw new Error(`Seed references \${${name}} but that environment variable is not set (add it to your .env).`);
|
|
364
|
-
}
|
|
365
|
-
return resolved;
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
if (Array.isArray(value)) {
|
|
369
|
-
return value.map((item) => interpolateEnv(item, env));
|
|
370
|
-
}
|
|
371
|
-
if (value && typeof value === "object") {
|
|
372
|
-
const out = {};
|
|
373
|
-
for (const [key, val] of Object.entries(value)) {
|
|
374
|
-
out[key] = interpolateEnv(val, env);
|
|
375
|
-
}
|
|
376
|
-
return out;
|
|
377
|
-
}
|
|
378
|
-
return value;
|
|
379
|
-
}
|
|
380
|
-
function applySeeds(store, seeds, env = process.env) {
|
|
381
|
-
for (const secret of seeds.secrets ?? []) {
|
|
382
|
-
const { key, value } = interpolateEnv(secret, env);
|
|
383
|
-
store.setSecret(key, value);
|
|
384
|
-
}
|
|
385
|
-
for (const credential of seeds.credentials ?? []) {
|
|
386
|
-
const resolved = interpolateEnv(credential, env);
|
|
387
|
-
store.createCredential({
|
|
388
|
-
credentialTypeSlug: resolved.credentialTypeSlug,
|
|
389
|
-
name: resolved.name,
|
|
390
|
-
config: resolved.config,
|
|
391
|
-
id: resolved.id,
|
|
392
|
-
status: resolved.status,
|
|
393
|
-
durableCreds: resolved.durableCreds ?? null
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
for (const workflow of seeds.workflows ?? []) {
|
|
397
|
-
store.createWorkflow(interpolateEnv(workflow, env));
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function loadState(file, log = console.warn) {
|
|
401
|
-
if (!(0, import_node_fs.existsSync)(file)) {
|
|
402
|
-
return null;
|
|
403
|
-
}
|
|
404
|
-
let parsed;
|
|
405
|
-
try {
|
|
406
|
-
parsed = JSON.parse((0, import_node_fs.readFileSync)(file, "utf-8"));
|
|
407
|
-
} catch {
|
|
408
|
-
log(`Ignoring ${file}: not valid JSON.`);
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
411
|
-
if (parsed.schemaVersion !== STORE_SCHEMA_VERSION) {
|
|
412
|
-
log(`Ignoring ${file}: schemaVersion ${parsed.schemaVersion} != ${STORE_SCHEMA_VERSION} (discarded, seeds are the source of truth).`);
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
return parsed;
|
|
416
|
-
}
|
|
417
|
-
function saveState(file, snapshot) {
|
|
418
|
-
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(file), { recursive: true });
|
|
419
|
-
(0, import_node_fs.writeFileSync)(file, JSON.stringify(snapshot, null, 2), "utf-8");
|
|
420
|
-
}
|
|
421
|
-
var SEED_ENTRY_CANDIDATES = ["index.ts", "index.mjs", "index.js", "seeds.ts", "seeds.js"];
|
|
422
|
-
async function loadSeedsFromDir(dir) {
|
|
423
|
-
for (const candidate of SEED_ENTRY_CANDIDATES) {
|
|
424
|
-
const path = (0, import_node_path.resolve)(dir, candidate);
|
|
425
|
-
if ((0, import_node_fs.existsSync)(path)) {
|
|
426
|
-
const mod = await importFresh(path);
|
|
427
|
-
return mod.default ?? mod.seeds ?? {};
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return {};
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// src/resolve.ts
|
|
434
|
-
var import_integrations_node_sdk2 = require("@revenexx/integrations-node-sdk");
|
|
435
|
-
var noopLogger = {
|
|
436
|
-
info() {
|
|
437
|
-
},
|
|
438
|
-
warn() {
|
|
439
|
-
},
|
|
440
|
-
error() {
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
function compareSemver(a, b) {
|
|
444
|
-
const pa = a.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
445
|
-
const pb = b.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
446
|
-
for (let i = 0; i < 3; i++) {
|
|
447
|
-
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
448
|
-
if (diff !== 0) {
|
|
449
|
-
return diff;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
return 0;
|
|
453
|
-
}
|
|
454
|
-
function nodeVersions(loaded, slug) {
|
|
455
|
-
return loaded.nodes.filter((n) => n.description.slug === slug).map((n) => n.description.version).sort((a, b) => compareSemver(b, a));
|
|
456
|
-
}
|
|
457
|
-
function findNode(loaded, slug, version) {
|
|
458
|
-
const matches = loaded.nodes.filter((n) => n.description.slug === slug);
|
|
459
|
-
if (matches.length === 0) {
|
|
460
|
-
throw new DevApiError(404, `Node '${slug}' not found.`);
|
|
461
|
-
}
|
|
462
|
-
if (!version || version === "latest") {
|
|
463
|
-
return [...matches].sort((a, b) => compareSemver(b.description.version, a.description.version))[0];
|
|
464
|
-
}
|
|
465
|
-
const exact = matches.find((n) => n.description.version === version);
|
|
466
|
-
if (!exact) {
|
|
467
|
-
throw new DevApiError(404, `Node '${slug}' has no version '${version}'.`);
|
|
468
|
-
}
|
|
469
|
-
return exact;
|
|
470
|
-
}
|
|
471
|
-
function findCredential(loaded, slug) {
|
|
472
|
-
const cred = loaded.credentials.find((c) => c.description.slug === slug);
|
|
473
|
-
if (!cred) {
|
|
474
|
-
throw new DevApiError(404, `Credential type '${slug}' not found.`);
|
|
475
|
-
}
|
|
476
|
-
return cred;
|
|
477
|
-
}
|
|
478
|
-
function findCredentialType(loaded, slug) {
|
|
479
|
-
return findCredential(loaded, slug).description;
|
|
480
|
-
}
|
|
481
|
-
function credentialContext(store, credentialId) {
|
|
482
|
-
return {
|
|
483
|
-
signal: new AbortController().signal,
|
|
484
|
-
logger: noopLogger,
|
|
485
|
-
persistDurableCreds: credentialId ? async (durableCreds) => {
|
|
486
|
-
store.updateCredential(credentialId, { durableCreds });
|
|
487
|
-
} : void 0
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
async function resolveCredentialInstance(loaded, store, credentialId) {
|
|
491
|
-
const instance = store.getCredential(credentialId);
|
|
492
|
-
if (!instance) {
|
|
493
|
-
throw new DevApiError(404, `Credential instance '${credentialId}' not found.`);
|
|
494
|
-
}
|
|
495
|
-
const cred = findCredential(loaded, instance.credentialTypeSlug);
|
|
496
|
-
const ctx = credentialContext(store, credentialId);
|
|
497
|
-
return cred.resolve(ctx, instance.config, instance.durableCreds);
|
|
498
|
-
}
|
|
499
|
-
function authorContext(loaded, store, config, locale) {
|
|
500
|
-
return {
|
|
501
|
-
signal: new AbortController().signal,
|
|
502
|
-
logger: noopLogger,
|
|
503
|
-
config,
|
|
504
|
-
secrets: {
|
|
505
|
-
async get(key) {
|
|
506
|
-
const secret = store.getSecret(key);
|
|
507
|
-
if (!secret) {
|
|
508
|
-
throw new DevApiError(404, `Secret '${key}' not found.`);
|
|
509
|
-
}
|
|
510
|
-
return secret.value;
|
|
511
|
-
}
|
|
512
|
-
},
|
|
513
|
-
credentials: {
|
|
514
|
-
async get(id) {
|
|
515
|
-
return (await resolveCredentialInstance(loaded, store, id)).credentials;
|
|
516
|
-
}
|
|
517
|
-
},
|
|
518
|
-
locale
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
async function resolveNodeConfig(loaded, store, input) {
|
|
522
|
-
const node = findNode(loaded, input.slug, input.version);
|
|
523
|
-
const ctx = authorContext(loaded, store, input.config ?? {}, input.locale);
|
|
524
|
-
try {
|
|
525
|
-
if (input.target === "outputs") {
|
|
526
|
-
if (!node.resolveOutputs) {
|
|
527
|
-
return { outputs: [] };
|
|
528
|
-
}
|
|
529
|
-
return { outputs: await node.resolveOutputs(ctx) };
|
|
530
|
-
}
|
|
531
|
-
if (input.target === "*") {
|
|
532
|
-
const result = {};
|
|
533
|
-
if (node.resolveConfigSchema) {
|
|
534
|
-
result.fields = await node.resolveConfigSchema(ctx);
|
|
535
|
-
}
|
|
536
|
-
if (node.resolveOutputs) {
|
|
537
|
-
result.outputs = await node.resolveOutputs(ctx);
|
|
538
|
-
}
|
|
539
|
-
return result;
|
|
540
|
-
}
|
|
541
|
-
const field = node.description.config?.find((f) => f.key === input.target);
|
|
542
|
-
if (field?.type === "dynamic-schema") {
|
|
543
|
-
if (!node.resolveConfigSchema) {
|
|
544
|
-
return { fields: [] };
|
|
545
|
-
}
|
|
546
|
-
return { fields: await node.resolveConfigSchema(ctx) };
|
|
547
|
-
}
|
|
548
|
-
if (!node.loadOptions) {
|
|
549
|
-
return { options: [] };
|
|
550
|
-
}
|
|
551
|
-
return { options: await node.loadOptions(ctx, input.target) };
|
|
552
|
-
} catch (err) {
|
|
553
|
-
if (err instanceof DevApiError) {
|
|
554
|
-
throw err;
|
|
555
|
-
}
|
|
556
|
-
throw new DevApiError(502, `Node resolve failed: ${err.message}`);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
function isProvided(value) {
|
|
560
|
-
if (value === void 0 || value === null) {
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
if (typeof value === "string") {
|
|
564
|
-
return value.trim().length > 0;
|
|
565
|
-
}
|
|
566
|
-
if (Array.isArray(value)) {
|
|
567
|
-
return value.length > 0;
|
|
568
|
-
}
|
|
569
|
-
return true;
|
|
570
|
-
}
|
|
571
|
-
function isExpression(value) {
|
|
572
|
-
return typeof value === "string" && (value.startsWith("=") || value.includes("${{"));
|
|
573
|
-
}
|
|
574
|
-
function validateField(field, value, errors) {
|
|
575
|
-
const push = (msg) => {
|
|
576
|
-
(errors[field.key] ??= []).push(msg);
|
|
577
|
-
};
|
|
578
|
-
const provided = isProvided(value);
|
|
579
|
-
if (field.required && !provided) {
|
|
580
|
-
push("This field is required.");
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
if (!provided || isExpression(value)) {
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
switch (field.type) {
|
|
587
|
-
case "string":
|
|
588
|
-
case "secret-ref":
|
|
589
|
-
case "expression":
|
|
590
|
-
if (typeof value !== "string") {
|
|
591
|
-
push("Expected a string.");
|
|
592
|
-
}
|
|
593
|
-
break;
|
|
594
|
-
case "number":
|
|
595
|
-
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
596
|
-
push("Expected a number.");
|
|
597
|
-
}
|
|
598
|
-
break;
|
|
599
|
-
case "boolean":
|
|
600
|
-
if (typeof value !== "boolean") {
|
|
601
|
-
push("Expected a boolean.");
|
|
602
|
-
}
|
|
603
|
-
break;
|
|
604
|
-
case "select":
|
|
605
|
-
if (!field.dynamic && field.options && !field.options.some((o) => o.value === value)) {
|
|
606
|
-
push("Not one of the allowed options.");
|
|
607
|
-
}
|
|
608
|
-
break;
|
|
609
|
-
case "multiselect":
|
|
610
|
-
if (!Array.isArray(value)) {
|
|
611
|
-
push("Expected an array.");
|
|
612
|
-
} else if (!field.dynamic && field.options) {
|
|
613
|
-
const allowed = new Set(field.options.map((o) => o.value));
|
|
614
|
-
for (const v2 of value) {
|
|
615
|
-
if (!allowed.has(v2)) {
|
|
616
|
-
push(`Value '${String(v2)}' is not an allowed option.`);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
break;
|
|
621
|
-
case "array":
|
|
622
|
-
if (!Array.isArray(value)) {
|
|
623
|
-
push("Expected an array.");
|
|
624
|
-
}
|
|
625
|
-
break;
|
|
626
|
-
case "object":
|
|
627
|
-
if (typeof value !== "object" || Array.isArray(value)) {
|
|
628
|
-
push("Expected an object.");
|
|
629
|
-
}
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
const v = field.validation;
|
|
633
|
-
if (v) {
|
|
634
|
-
if (typeof value === "string") {
|
|
635
|
-
if (v.pattern !== void 0 && !new RegExp(v.pattern).test(value)) {
|
|
636
|
-
push(`Does not match pattern ${v.pattern}.`);
|
|
637
|
-
}
|
|
638
|
-
if (v.minLength !== void 0 && value.length < v.minLength) {
|
|
639
|
-
push(`Must be at least ${v.minLength} characters.`);
|
|
640
|
-
}
|
|
641
|
-
if (v.maxLength !== void 0 && value.length > v.maxLength) {
|
|
642
|
-
push(`Must be at most ${v.maxLength} characters.`);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
if (typeof value === "number") {
|
|
646
|
-
if (v.min !== void 0 && value < v.min) {
|
|
647
|
-
push(`Must be >= ${v.min}.`);
|
|
648
|
-
}
|
|
649
|
-
if (v.max !== void 0 && value > v.max) {
|
|
650
|
-
push(`Must be <= ${v.max}.`);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
if (Array.isArray(value)) {
|
|
654
|
-
if (v.minLength !== void 0 && value.length < v.minLength) {
|
|
655
|
-
push(`Must have at least ${v.minLength} items.`);
|
|
656
|
-
}
|
|
657
|
-
if (v.maxLength !== void 0 && value.length > v.maxLength) {
|
|
658
|
-
push(`Must have at most ${v.maxLength} items.`);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
async function validateNodeConfig(loaded, store, input) {
|
|
664
|
-
const node = findNode(loaded, input.slug, input.version);
|
|
665
|
-
const config = input.config ?? {};
|
|
666
|
-
const errors = {};
|
|
667
|
-
const fields = node.description.config ?? [];
|
|
668
|
-
for (const field of fields) {
|
|
669
|
-
if (field.type === "dynamic-schema") {
|
|
670
|
-
continue;
|
|
671
|
-
}
|
|
672
|
-
validateField(field, config[field.key], errors);
|
|
673
|
-
}
|
|
674
|
-
if (fields.some((f) => f.type === "dynamic-schema") && node.resolveConfigSchema) {
|
|
675
|
-
const ctx = authorContext(loaded, store, config, input.locale);
|
|
676
|
-
let children;
|
|
677
|
-
try {
|
|
678
|
-
children = await node.resolveConfigSchema(ctx);
|
|
679
|
-
} catch (err) {
|
|
680
|
-
if (err instanceof DevApiError) {
|
|
681
|
-
throw err;
|
|
682
|
-
}
|
|
683
|
-
throw new DevApiError(502, `Node resolve failed: ${err.message}`);
|
|
684
|
-
}
|
|
685
|
-
for (const child of children) {
|
|
686
|
-
validateField(child, config[child.key], errors);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return { valid: Object.keys(errors).length === 0, errors };
|
|
690
|
-
}
|
|
691
|
-
async function testCredentialConfig(loaded, store, typeSlug, config) {
|
|
692
|
-
const cred = findCredential(loaded, typeSlug);
|
|
693
|
-
return cred.test(credentialContext(store), config);
|
|
694
|
-
}
|
|
695
|
-
async function testCredentialInstance(loaded, store, credentialId) {
|
|
696
|
-
const instance = store.getCredential(credentialId);
|
|
697
|
-
if (!instance) {
|
|
698
|
-
throw new DevApiError(404, `Credential instance '${credentialId}' not found.`);
|
|
699
|
-
}
|
|
700
|
-
const cred = findCredential(loaded, instance.credentialTypeSlug);
|
|
701
|
-
return cred.test(credentialContext(store, credentialId), instance.config);
|
|
702
|
-
}
|
|
703
|
-
async function buildOAuthAuthorizeUrl(loaded, store, credentialId, params) {
|
|
704
|
-
const instance = store.getCredential(credentialId);
|
|
705
|
-
if (!instance) {
|
|
706
|
-
throw new DevApiError(404, `Credential instance '${credentialId}' not found.`);
|
|
707
|
-
}
|
|
708
|
-
const cred = findCredential(loaded, instance.credentialTypeSlug);
|
|
709
|
-
if (!(0, import_integrations_node_sdk2.isOAuthAuthorizeCredential)(cred)) {
|
|
710
|
-
throw new DevApiError(422, `Credential type '${instance.credentialTypeSlug}' is not a 3-legged OAuth type.`);
|
|
711
|
-
}
|
|
712
|
-
return cred.buildAuthorizeUrl(credentialContext(store, credentialId), instance.config, params);
|
|
713
|
-
}
|
|
714
|
-
async function exchangeOAuthCode(loaded, store, credentialId, params) {
|
|
715
|
-
const instance = store.getCredential(credentialId);
|
|
716
|
-
if (!instance) {
|
|
717
|
-
throw new DevApiError(404, `Credential instance '${credentialId}' not found.`);
|
|
718
|
-
}
|
|
719
|
-
const cred = findCredential(loaded, instance.credentialTypeSlug);
|
|
720
|
-
if (!(0, import_integrations_node_sdk2.isOAuthAuthorizeCredential)(cred)) {
|
|
721
|
-
throw new DevApiError(422, `Credential type '${instance.credentialTypeSlug}' is not a 3-legged OAuth type.`);
|
|
722
|
-
}
|
|
723
|
-
const out = await cred.exchangeCode(credentialContext(store, credentialId), instance.config, params);
|
|
724
|
-
store.updateCredential(credentialId, { durableCreds: out.durableCreds, status: "active" });
|
|
725
|
-
return out;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
// src/server.ts
|
|
729
|
-
var import_node_http = __toESM(require("http"), 1);
|
|
730
|
-
|
|
731
|
-
// src/http.ts
|
|
732
|
-
function sendJson(res, status, body) {
|
|
733
|
-
const payload = JSON.stringify(body);
|
|
734
|
-
res.writeHead(status, {
|
|
735
|
-
"Content-Type": "application/json",
|
|
736
|
-
"Access-Control-Allow-Origin": "*",
|
|
737
|
-
"Access-Control-Allow-Headers": "*",
|
|
738
|
-
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
|
739
|
-
});
|
|
740
|
-
res.end(payload);
|
|
741
|
-
}
|
|
742
|
-
function sendError(res, err) {
|
|
743
|
-
if (err instanceof DevApiError) {
|
|
744
|
-
sendJson(res, err.status, err.errors ? { message: err.message, errors: err.errors } : { message: err.message });
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
sendJson(res, 500, { message: err?.message ?? "Internal error" });
|
|
748
|
-
}
|
|
749
|
-
async function readBody(req) {
|
|
750
|
-
let body = "";
|
|
751
|
-
for await (const chunk of req) {
|
|
752
|
-
body += chunk;
|
|
753
|
-
}
|
|
754
|
-
return body;
|
|
755
|
-
}
|
|
756
|
-
async function readJson(req) {
|
|
757
|
-
const raw = await readBody(req);
|
|
758
|
-
if (raw.trim() === "") {
|
|
759
|
-
return {};
|
|
760
|
-
}
|
|
761
|
-
try {
|
|
762
|
-
return JSON.parse(raw);
|
|
763
|
-
} catch {
|
|
764
|
-
throw new DevApiError(400, "Invalid JSON body.");
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
// src/projections.ts
|
|
769
|
-
var import_integrations_node_sdk3 = require("@revenexx/integrations-node-sdk");
|
|
770
|
-
function hasDynamicOptions(desc) {
|
|
771
|
-
return (desc.config ?? []).some((f) => f.dynamic === true);
|
|
772
|
-
}
|
|
773
|
-
function hasDynamicSchema(desc) {
|
|
774
|
-
return (desc.config ?? []).some((f) => f.type === "dynamic-schema");
|
|
775
|
-
}
|
|
776
|
-
function hasDynamicOutputs(desc) {
|
|
777
|
-
return (desc.outputs ?? []).some((o) => o.resolveOutputs === true);
|
|
778
|
-
}
|
|
779
|
-
function nodeToApi(desc) {
|
|
780
|
-
const [namespace] = desc.slug.split(":");
|
|
781
|
-
return {
|
|
782
|
-
name: desc.name,
|
|
783
|
-
namespace: namespace ?? null,
|
|
784
|
-
slug: desc.slug,
|
|
785
|
-
version: desc.version,
|
|
786
|
-
manifest_version: import_integrations_node_sdk3.MANIFEST_VERSION,
|
|
787
|
-
manifest: desc,
|
|
788
|
-
has_dynamic_options: hasDynamicOptions(desc),
|
|
789
|
-
has_dynamic_schema: hasDynamicSchema(desc),
|
|
790
|
-
has_dynamic_outputs: hasDynamicOutputs(desc),
|
|
791
|
-
created_at: null,
|
|
792
|
-
updated_at: null
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
function credentialTypeToApi(desc) {
|
|
796
|
-
return {
|
|
797
|
-
slug: desc.slug,
|
|
798
|
-
version: desc.version,
|
|
799
|
-
name: desc.name,
|
|
800
|
-
description: desc.description ?? null,
|
|
801
|
-
icon: desc.icon ?? null,
|
|
802
|
-
auth_kind: desc.authKind,
|
|
803
|
-
fields: desc.fields
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
function credentialInstanceToApi(record, type) {
|
|
807
|
-
const secretKeys = new Set((type?.fields ?? []).filter((f) => f.type === "secret").map((f) => f.key));
|
|
808
|
-
const knownKeys = new Set((type?.fields ?? []).map((f) => f.key));
|
|
809
|
-
const publicConfig = {};
|
|
810
|
-
for (const [key, value] of Object.entries(record.config)) {
|
|
811
|
-
if (knownKeys.has(key) && !secretKeys.has(key)) {
|
|
812
|
-
publicConfig[key] = value;
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
return {
|
|
816
|
-
id: record.id,
|
|
817
|
-
tenant_id: record.tenantId,
|
|
818
|
-
credential_type_slug: record.credentialTypeSlug,
|
|
819
|
-
name: record.name,
|
|
820
|
-
status: record.status,
|
|
821
|
-
public_config: publicConfig,
|
|
822
|
-
created_at: record.createdAt,
|
|
823
|
-
updated_at: record.updatedAt
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
function secretToApi(record) {
|
|
827
|
-
return {
|
|
828
|
-
key: record.key,
|
|
829
|
-
created_at: record.createdAt,
|
|
830
|
-
updated_at: record.updatedAt
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
function workflowToApi(record) {
|
|
834
|
-
return {
|
|
835
|
-
id: record.id,
|
|
836
|
-
name: record.name,
|
|
837
|
-
definition: record.definition,
|
|
838
|
-
build_status: record.buildStatus,
|
|
839
|
-
created_at: record.createdAt,
|
|
840
|
-
updated_at: record.updatedAt
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
function triggerToApi(record) {
|
|
844
|
-
return {
|
|
845
|
-
handle: record.id,
|
|
846
|
-
id: record.id,
|
|
847
|
-
workflow_id: record.workflowId,
|
|
848
|
-
type: record.type,
|
|
849
|
-
name: record.name,
|
|
850
|
-
config: record.config,
|
|
851
|
-
active: record.active,
|
|
852
|
-
created_at: record.createdAt,
|
|
853
|
-
updated_at: record.updatedAt
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
function templateSummaryToApi(t) {
|
|
857
|
-
return {
|
|
858
|
-
slug: t.slug,
|
|
859
|
-
version: t.version,
|
|
860
|
-
category: t.category,
|
|
861
|
-
level: t.level,
|
|
862
|
-
name: t.name,
|
|
863
|
-
shortDescription: t.shortDescription ?? null,
|
|
864
|
-
description: t.description ?? null,
|
|
865
|
-
icon: t.icon ?? null,
|
|
866
|
-
industries: t.industries ?? [],
|
|
867
|
-
vendors: t.vendors ?? [],
|
|
868
|
-
triggerTypes: (t.triggers ?? []).map((tr) => tr.type)
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
function templateFullToApi(t) {
|
|
872
|
-
return {
|
|
873
|
-
...templateSummaryToApi(t),
|
|
874
|
-
blobVersion: t.blobVersion,
|
|
875
|
-
definition: t.definition,
|
|
876
|
-
triggers: t.triggers ?? []
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
// src/server.ts
|
|
881
|
-
var SEGMENT = (s) => decodeURIComponent(s ?? "");
|
|
882
|
-
function createRequestListener(deps) {
|
|
883
|
-
return (req, res) => {
|
|
884
|
-
handle(req, res, deps).catch((err) => sendError(res, err));
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
function createDevServer(deps) {
|
|
888
|
-
return import_node_http.default.createServer(createRequestListener(deps));
|
|
889
|
-
}
|
|
890
|
-
async function handle(req, res, deps) {
|
|
891
|
-
const method = (req.method ?? "GET").toUpperCase();
|
|
892
|
-
if (method === "OPTIONS") {
|
|
893
|
-
sendJson(res, 204, {});
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
const url = new URL(req.url ?? "/", "http://localhost");
|
|
897
|
-
let pathname = url.pathname;
|
|
898
|
-
if (pathname.startsWith("/api/v1")) {
|
|
899
|
-
pathname = pathname.slice("/api/v1".length);
|
|
900
|
-
}
|
|
901
|
-
const seg = pathname.split("/").filter(Boolean).map(SEGMENT);
|
|
902
|
-
const loaded = deps.getPackage();
|
|
903
|
-
const store = deps.store;
|
|
904
|
-
switch (seg[0]) {
|
|
905
|
-
case void 0:
|
|
906
|
-
case "health":
|
|
907
|
-
return void sendJson(res, 200, { status: "ok" });
|
|
908
|
-
case "me":
|
|
909
|
-
return void sendJson(res, 200, {
|
|
910
|
-
id: "dev-user",
|
|
911
|
-
name: "Dev User",
|
|
912
|
-
email: "dev@revenexx.test",
|
|
913
|
-
tenant_id: DEV_TENANT_ID
|
|
914
|
-
});
|
|
915
|
-
case "schemas":
|
|
916
|
-
return handleSchemas(res, deps, seg);
|
|
917
|
-
case "nodes":
|
|
918
|
-
return handleNodes(req, res, method, loaded, store, seg);
|
|
919
|
-
case "credential-types":
|
|
920
|
-
return handleCredentialTypes(res, loaded, seg);
|
|
921
|
-
case "credentials":
|
|
922
|
-
return handleCredentials(req, res, method, loaded, store, seg, url);
|
|
923
|
-
case "secrets":
|
|
924
|
-
return handleSecrets(req, res, method, store, seg);
|
|
925
|
-
case "templates":
|
|
926
|
-
return handleTemplates(req, res, method, loaded, store, seg);
|
|
927
|
-
case "workflows":
|
|
928
|
-
return handleWorkflows(req, res, method, store, seg);
|
|
929
|
-
default:
|
|
930
|
-
return void sendJson(res, 404, { message: `No route for /${seg.join("/")}` });
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
function handleSchemas(res, deps, seg) {
|
|
934
|
-
const domain = seg[1];
|
|
935
|
-
const version = seg[2];
|
|
936
|
-
if (!domain) {
|
|
937
|
-
throw new DevApiError(404, "Schema domain required.");
|
|
938
|
-
}
|
|
939
|
-
const schemas = deps.schemas ?? {};
|
|
940
|
-
const schema = version && schemas[`${domain}/${version}`] || schemas[domain];
|
|
941
|
-
if (!schema) {
|
|
942
|
-
throw new DevApiError(404, `No schema for '${domain}${version ? `/${version}` : ""}'. Vendor it into assets/schemas.`);
|
|
943
|
-
}
|
|
944
|
-
sendJson(res, 200, schema);
|
|
945
|
-
}
|
|
946
|
-
async function handleNodes(req, res, method, loaded, store, seg) {
|
|
947
|
-
if (seg.length === 1 && method === "GET") {
|
|
948
|
-
return void sendJson(res, 200, { data: loaded.manifest.nodes.map(nodeToApi) });
|
|
949
|
-
}
|
|
950
|
-
const slug = seg[1];
|
|
951
|
-
if (!slug) {
|
|
952
|
-
throw new DevApiError(404, "Node slug required.");
|
|
953
|
-
}
|
|
954
|
-
if (seg[2] === "versions" && method === "GET") {
|
|
955
|
-
const versions = nodeVersions(loaded, slug);
|
|
956
|
-
if (versions.length === 0) {
|
|
957
|
-
throw new DevApiError(404, `Node '${slug}' not found.`);
|
|
958
|
-
}
|
|
959
|
-
return void sendJson(res, 200, { data: versions });
|
|
960
|
-
}
|
|
961
|
-
const version = seg[2];
|
|
962
|
-
if (!version) {
|
|
963
|
-
throw new DevApiError(404, "Node version required.");
|
|
964
|
-
}
|
|
965
|
-
if (seg[3] === "config:resolve" && method === "POST") {
|
|
966
|
-
const body = await readJson(req);
|
|
967
|
-
if (!body.target) {
|
|
968
|
-
throw new DevApiError(422, "Field `target` is required.", { target: ["The target field is required."] });
|
|
969
|
-
}
|
|
970
|
-
const result = await resolveNodeConfig(loaded, store, {
|
|
971
|
-
slug,
|
|
972
|
-
version,
|
|
973
|
-
target: body.target,
|
|
974
|
-
config: body.config ?? {},
|
|
975
|
-
locale: body.locale
|
|
976
|
-
});
|
|
977
|
-
return void sendJson(res, 200, result);
|
|
978
|
-
}
|
|
979
|
-
if (seg[3] === "config:validate" && method === "POST") {
|
|
980
|
-
const body = await readJson(req);
|
|
981
|
-
const result = await validateNodeConfig(loaded, store, {
|
|
982
|
-
slug,
|
|
983
|
-
version,
|
|
984
|
-
config: body.config ?? {},
|
|
985
|
-
locale: body.locale
|
|
986
|
-
});
|
|
987
|
-
return void sendJson(res, 200, result);
|
|
988
|
-
}
|
|
989
|
-
if (seg.length === 3 && method === "GET") {
|
|
990
|
-
const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
|
|
991
|
-
if (!node) {
|
|
992
|
-
throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
|
|
993
|
-
}
|
|
994
|
-
return void sendJson(res, 200, nodeToApi(node));
|
|
995
|
-
}
|
|
996
|
-
throw new DevApiError(404, `No route for nodes/${seg.slice(1).join("/")}`);
|
|
997
|
-
}
|
|
998
|
-
function handleCredentialTypes(res, loaded, seg) {
|
|
999
|
-
if (seg.length === 1) {
|
|
1000
|
-
return void sendJson(res, 200, {
|
|
1001
|
-
data: (loaded.manifest.credentials ?? []).map(credentialTypeToApi)
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
const slug = seg[1];
|
|
1005
|
-
const type = findCredentialType(loaded, slug);
|
|
1006
|
-
sendJson(res, 200, { data: credentialTypeToApi(type) });
|
|
1007
|
-
}
|
|
1008
|
-
async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
1009
|
-
const typeOf = (slug) => {
|
|
1010
|
-
try {
|
|
1011
|
-
return findCredentialType(loaded, slug);
|
|
1012
|
-
} catch {
|
|
1013
|
-
return void 0;
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
if (seg.length === 1) {
|
|
1017
|
-
if (method === "GET") {
|
|
1018
|
-
const filter = url.searchParams.get("type") ?? void 0;
|
|
1019
|
-
const data = store.listCredentials(filter).map((c) => credentialInstanceToApi(c, typeOf(c.credentialTypeSlug)));
|
|
1020
|
-
return void sendJson(res, 200, { data });
|
|
1021
|
-
}
|
|
1022
|
-
if (method === "POST") {
|
|
1023
|
-
const body = await readJson(req);
|
|
1024
|
-
if (!body.credential_type_slug || !body.name) {
|
|
1025
|
-
throw new DevApiError(422, "Fields `credential_type_slug` and `name` are required.");
|
|
1026
|
-
}
|
|
1027
|
-
findCredential(loaded, body.credential_type_slug);
|
|
1028
|
-
const record = store.createCredential({
|
|
1029
|
-
credentialTypeSlug: body.credential_type_slug,
|
|
1030
|
-
name: body.name,
|
|
1031
|
-
config: body.config ?? {}
|
|
1032
|
-
});
|
|
1033
|
-
return void sendJson(res, 201, credentialInstanceToApi(record, typeOf(record.credentialTypeSlug)));
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
if (seg[1] === "test" && method === "POST") {
|
|
1037
|
-
const body = await readJson(req);
|
|
1038
|
-
if (!body.credential_type_slug) {
|
|
1039
|
-
throw new DevApiError(422, "Field `credential_type_slug` is required.");
|
|
1040
|
-
}
|
|
1041
|
-
const result = await testCredentialConfig(loaded, store, body.credential_type_slug, body.config ?? {});
|
|
1042
|
-
return void sendJson(res, 200, result);
|
|
1043
|
-
}
|
|
1044
|
-
if (seg[1] === "oauth" && seg[2] === "callback" && method === "GET") {
|
|
1045
|
-
const code = url.searchParams.get("code");
|
|
1046
|
-
const state = url.searchParams.get("state");
|
|
1047
|
-
if (!code || !state) {
|
|
1048
|
-
throw new DevApiError(422, "OAuth callback requires `code` and `state`.");
|
|
1049
|
-
}
|
|
1050
|
-
const credentialId = state;
|
|
1051
|
-
const redirectUri = `${url.origin}/api/v1/credentials/oauth/callback`;
|
|
1052
|
-
await exchangeOAuthCode(loaded, store, credentialId, { code, redirectUri });
|
|
1053
|
-
return void sendJson(res, 200, { status: "connected", credential_id: credentialId });
|
|
1054
|
-
}
|
|
1055
|
-
const id = seg[1];
|
|
1056
|
-
if (!id) {
|
|
1057
|
-
throw new DevApiError(404, "Credential id required.");
|
|
1058
|
-
}
|
|
1059
|
-
if (seg[2] === "test" && method === "POST") {
|
|
1060
|
-
const result = await testCredentialInstance(loaded, store, id);
|
|
1061
|
-
return void sendJson(res, 200, result);
|
|
1062
|
-
}
|
|
1063
|
-
if (seg[2] === "oauth" && seg[3] === "authorize-url" && method === "POST") {
|
|
1064
|
-
const redirectUri = "http://localhost/api/v1/credentials/oauth/callback";
|
|
1065
|
-
const result = await buildOAuthAuthorizeUrl(loaded, store, id, { redirectUri, state: id });
|
|
1066
|
-
return void sendJson(res, 200, { authorize_url: result.authorizeUrl });
|
|
1067
|
-
}
|
|
1068
|
-
if (seg.length === 2) {
|
|
1069
|
-
const record = store.getCredential(id);
|
|
1070
|
-
if (method === "GET") {
|
|
1071
|
-
if (!record) {
|
|
1072
|
-
throw new DevApiError(404, `Credential '${id}' not found.`);
|
|
1073
|
-
}
|
|
1074
|
-
return void sendJson(res, 200, credentialInstanceToApi(record, typeOf(record.credentialTypeSlug)));
|
|
1075
|
-
}
|
|
1076
|
-
if (method === "PATCH") {
|
|
1077
|
-
if (!record) {
|
|
1078
|
-
throw new DevApiError(404, `Credential '${id}' not found.`);
|
|
1079
|
-
}
|
|
1080
|
-
const body = await readJson(req);
|
|
1081
|
-
const updated = store.updateCredential(id, { name: body.name, config: body.config });
|
|
1082
|
-
return void sendJson(res, 200, credentialInstanceToApi(updated, typeOf(updated.credentialTypeSlug)));
|
|
1083
|
-
}
|
|
1084
|
-
if (method === "DELETE") {
|
|
1085
|
-
store.deleteCredential(id);
|
|
1086
|
-
return void sendJson(res, 200, { deleted: true });
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
throw new DevApiError(404, `No route for credentials/${seg.slice(1).join("/")}`);
|
|
1090
|
-
}
|
|
1091
|
-
async function handleSecrets(req, res, method, store, seg) {
|
|
1092
|
-
if (seg.length === 1) {
|
|
1093
|
-
if (method === "GET") {
|
|
1094
|
-
return void sendJson(res, 200, { data: store.listSecrets().map(secretToApi) });
|
|
1095
|
-
}
|
|
1096
|
-
if (method === "POST") {
|
|
1097
|
-
const body = await readJson(req);
|
|
1098
|
-
if (!body.key || body.value === void 0) {
|
|
1099
|
-
throw new DevApiError(422, "Fields `key` and `value` are required.");
|
|
1100
|
-
}
|
|
1101
|
-
const record = store.setSecret(body.key, body.value);
|
|
1102
|
-
return void sendJson(res, 201, secretToApi(record));
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
const key = seg[1];
|
|
1106
|
-
if (key) {
|
|
1107
|
-
if (method === "PATCH") {
|
|
1108
|
-
const body = await readJson(req);
|
|
1109
|
-
if (body.value === void 0) {
|
|
1110
|
-
throw new DevApiError(422, "Field `value` is required.");
|
|
1111
|
-
}
|
|
1112
|
-
return void sendJson(res, 200, secretToApi(store.setSecret(key, body.value)));
|
|
1113
|
-
}
|
|
1114
|
-
if (method === "DELETE") {
|
|
1115
|
-
store.deleteSecret(key);
|
|
1116
|
-
return void sendJson(res, 200, { deleted: true });
|
|
1117
|
-
}
|
|
1118
|
-
}
|
|
1119
|
-
throw new DevApiError(404, `No route for secrets/${seg.slice(1).join("/")}`);
|
|
1120
|
-
}
|
|
1121
|
-
async function handleTemplates(req, res, method, loaded, store, seg) {
|
|
1122
|
-
const templates = loaded.manifest.templates ?? [];
|
|
1123
|
-
if (seg.length === 1 && method === "GET") {
|
|
1124
|
-
return void sendJson(res, 200, { data: templates.map(templateSummaryToApi) });
|
|
1125
|
-
}
|
|
1126
|
-
const slug = seg[1];
|
|
1127
|
-
const template = templates.find((t) => t.slug === slug);
|
|
1128
|
-
if (!template) {
|
|
1129
|
-
throw new DevApiError(404, `Template '${slug}' not found.`);
|
|
1130
|
-
}
|
|
1131
|
-
if (seg.length === 2 && method === "GET") {
|
|
1132
|
-
return void sendJson(res, 200, templateFullToApi(template));
|
|
1133
|
-
}
|
|
1134
|
-
if (seg[2] === "requirements" && method === "GET") {
|
|
1135
|
-
return void sendJson(res, 200, { data: { credentials: [], secrets: [] } });
|
|
1136
|
-
}
|
|
1137
|
-
if (seg[2] === "instantiate" && method === "POST") {
|
|
1138
|
-
const body = await readJson(req);
|
|
1139
|
-
const workflow = store.createWorkflow({
|
|
1140
|
-
name: body.name ?? String(template.name),
|
|
1141
|
-
definition: template.definition
|
|
1142
|
-
});
|
|
1143
|
-
for (const trigger of template.triggers ?? []) {
|
|
1144
|
-
store.createTrigger({
|
|
1145
|
-
workflowId: workflow.id,
|
|
1146
|
-
type: trigger.type,
|
|
1147
|
-
name: trigger.name ?? null,
|
|
1148
|
-
config: trigger.config ?? {},
|
|
1149
|
-
active: trigger.active ?? true,
|
|
1150
|
-
id: trigger.handle
|
|
1151
|
-
});
|
|
1152
|
-
}
|
|
1153
|
-
return void sendJson(res, 201, workflowToApi(workflow));
|
|
1154
|
-
}
|
|
1155
|
-
throw new DevApiError(404, `No route for templates/${seg.slice(1).join("/")}`);
|
|
1156
|
-
}
|
|
1157
|
-
async function handleWorkflows(req, res, method, store, seg) {
|
|
1158
|
-
if (seg.length === 1) {
|
|
1159
|
-
if (method === "GET") {
|
|
1160
|
-
return void sendJson(res, 200, { data: store.listWorkflows().map(workflowToApi) });
|
|
1161
|
-
}
|
|
1162
|
-
if (method === "POST") {
|
|
1163
|
-
const body = await readJson(req);
|
|
1164
|
-
const workflow = store.createWorkflow({
|
|
1165
|
-
name: body.name ?? "Untitled workflow",
|
|
1166
|
-
definition: body.definition ?? {}
|
|
1167
|
-
});
|
|
1168
|
-
return void sendJson(res, 201, workflowToApi(workflow));
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
if (seg[1] === "used-credentials" && method === "GET") {
|
|
1172
|
-
return void sendJson(res, 200, { data: [] });
|
|
1173
|
-
}
|
|
1174
|
-
if (seg[1] === "used-credential-types" && method === "GET") {
|
|
1175
|
-
return void sendJson(res, 200, { data: [] });
|
|
1176
|
-
}
|
|
1177
|
-
const id = Number.parseInt(seg[1] ?? "", 10);
|
|
1178
|
-
if (Number.isNaN(id)) {
|
|
1179
|
-
throw new DevApiError(404, `No route for workflows/${seg.slice(1).join("/")}`);
|
|
1180
|
-
}
|
|
1181
|
-
if (seg[2] === "triggers") {
|
|
1182
|
-
if (seg.length === 3 && method === "GET") {
|
|
1183
|
-
return void sendJson(res, 200, { data: store.listTriggers(id).map(triggerToApi) });
|
|
1184
|
-
}
|
|
1185
|
-
if (seg.length === 3 && method === "POST") {
|
|
1186
|
-
const body = await readJson(req);
|
|
1187
|
-
if (!body.type) {
|
|
1188
|
-
throw new DevApiError(422, "Field `type` is required.");
|
|
1189
|
-
}
|
|
1190
|
-
const trigger = store.createTrigger({ workflowId: id, type: body.type, name: body.name, config: body.config, active: body.active });
|
|
1191
|
-
return void sendJson(res, 201, triggerToApi(trigger));
|
|
1192
|
-
}
|
|
1193
|
-
const triggerId = seg[3];
|
|
1194
|
-
if (triggerId && method === "PUT") {
|
|
1195
|
-
const body = await readJson(req);
|
|
1196
|
-
if (!body.type) {
|
|
1197
|
-
throw new DevApiError(422, "Field `type` is required.");
|
|
1198
|
-
}
|
|
1199
|
-
const trigger = store.replaceTrigger(triggerId, { type: body.type, name: body.name, config: body.config, active: body.active });
|
|
1200
|
-
if (!trigger) {
|
|
1201
|
-
throw new DevApiError(404, `Trigger '${triggerId}' not found.`);
|
|
1202
|
-
}
|
|
1203
|
-
return void sendJson(res, 200, triggerToApi(trigger));
|
|
1204
|
-
}
|
|
1205
|
-
if (triggerId && method === "DELETE") {
|
|
1206
|
-
store.deleteTrigger(triggerId);
|
|
1207
|
-
return void sendJson(res, 200, { deleted: true });
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
if (seg.length === 2) {
|
|
1211
|
-
const record = store.getWorkflow(id);
|
|
1212
|
-
if (method === "GET") {
|
|
1213
|
-
if (!record) {
|
|
1214
|
-
throw new DevApiError(404, `Workflow '${id}' not found.`);
|
|
1215
|
-
}
|
|
1216
|
-
return void sendJson(res, 200, workflowToApi(record));
|
|
1217
|
-
}
|
|
1218
|
-
if (method === "PUT") {
|
|
1219
|
-
const body = await readJson(req);
|
|
1220
|
-
const updated = store.updateWorkflow(id, { name: body.name, definition: body.definition });
|
|
1221
|
-
if (!updated) {
|
|
1222
|
-
throw new DevApiError(404, `Workflow '${id}' not found.`);
|
|
1223
|
-
}
|
|
1224
|
-
return void sendJson(res, 200, workflowToApi(updated));
|
|
1225
|
-
}
|
|
1226
|
-
if (method === "DELETE") {
|
|
1227
|
-
store.deleteWorkflow(id);
|
|
1228
|
-
return void sendJson(res, 200, { deleted: true });
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
if ((seg[2] === "credentials" || seg[2] === "credential-types") && method === "GET") {
|
|
1232
|
-
return void sendJson(res, 200, { data: [] });
|
|
1233
|
-
}
|
|
1234
|
-
throw new DevApiError(404, `No route for workflows/${seg.slice(1).join("/")}`);
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
// src/index.ts
|
|
1238
|
-
var DEVKIT_VERSION = "0.1.0";
|
|
1239
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1240
|
-
0 && (module.exports = {
|
|
1241
|
-
DEVKIT_VERSION,
|
|
1242
|
-
DEV_TENANT_ID,
|
|
1243
|
-
DevApiError,
|
|
1244
|
-
DevStore,
|
|
1245
|
-
STORE_SCHEMA_VERSION,
|
|
1246
|
-
applySeeds,
|
|
1247
|
-
buildOAuthAuthorizeUrl,
|
|
1248
|
-
createDevServer,
|
|
1249
|
-
createRequestListener,
|
|
1250
|
-
ensureTsxRegistered,
|
|
1251
|
-
exchangeOAuthCode,
|
|
1252
|
-
findCredential,
|
|
1253
|
-
findCredentialType,
|
|
1254
|
-
findNode,
|
|
1255
|
-
importFresh,
|
|
1256
|
-
interpolateEnv,
|
|
1257
|
-
loadPackageFromEntry,
|
|
1258
|
-
loadSeedsFromDir,
|
|
1259
|
-
loadState,
|
|
1260
|
-
nodeVersions,
|
|
1261
|
-
resolveCredentialInstance,
|
|
1262
|
-
resolveExports,
|
|
1263
|
-
resolveNodeConfig,
|
|
1264
|
-
saveState,
|
|
1265
|
-
testCredentialConfig,
|
|
1266
|
-
testCredentialInstance,
|
|
1267
|
-
validateNodeConfig
|
|
1268
|
-
});
|
|
1269
|
-
//# sourceMappingURL=index.cjs.map
|