@revenexx/integrations-node-devkit 0.2.2 → 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.
- package/README.md +35 -13
- package/dist/{chunk-2GVOKLIW.js → chunk-PS3HCKE7.js} +237 -52
- package/dist/chunk-PS3HCKE7.js.map +1 -0
- package/dist/cli.cjs +399 -529
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +138 -451
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +233 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -6
- package/dist/index.d.ts +59 -6
- package/dist/index.js +1 -1
- package/package.json +7 -4
- package/preview-host/app.vue +22 -0
- package/preview-host/assets/css/main.css +22 -0
- package/preview-host/composables/devkit-console-stubs.ts +52 -0
- package/preview-host/middleware/hide-workflows.global.ts +13 -0
- package/preview-host/nuxt.config.ts +38 -0
- package/preview-host/package.json +37 -0
- package/preview-host/pages/index.vue +63 -0
- package/preview-host/pages/nodes.vue +208 -0
- package/dist/chunk-2GVOKLIW.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
|
|
|
69
69
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
70
70
|
|
|
71
71
|
// src/index.ts
|
|
72
|
-
var
|
|
72
|
+
var import_node_fs4 = require("fs");
|
|
73
73
|
|
|
74
74
|
// src/env.ts
|
|
75
75
|
var import_node_fs = require("fs");
|
|
@@ -140,9 +140,31 @@ var DevApiError = class extends Error {
|
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
// src/loader.ts
|
|
143
|
+
var import_node_fs2 = require("fs");
|
|
144
|
+
var import_node_path2 = require("path");
|
|
143
145
|
var import_node_url = require("url");
|
|
144
146
|
var import_integrations_node_sdk = require("@revenexx/integrations-node-sdk");
|
|
145
|
-
|
|
147
|
+
var UNKNOWN_PACKAGE = { name: "unknown", version: "0.0.0", label: "Local package" };
|
|
148
|
+
function readPackageInfo(entryPath) {
|
|
149
|
+
let dir = (0, import_node_path2.dirname)(entryPath);
|
|
150
|
+
for (let up = 0; up < 6; up += 1) {
|
|
151
|
+
const candidate = (0, import_node_path2.join)(dir, "package.json");
|
|
152
|
+
if ((0, import_node_fs2.existsSync)(candidate)) {
|
|
153
|
+
try {
|
|
154
|
+
const pkg = JSON.parse((0, import_node_fs2.readFileSync)(candidate, "utf-8"));
|
|
155
|
+
if (pkg.name) {
|
|
156
|
+
return { name: pkg.name, version: pkg.version ?? "0.0.0", label: pkg.name.split("/").pop() ?? pkg.name };
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const parent = (0, import_node_path2.dirname)(dir);
|
|
162
|
+
if (parent === dir) break;
|
|
163
|
+
dir = parent;
|
|
164
|
+
}
|
|
165
|
+
return UNKNOWN_PACKAGE;
|
|
166
|
+
}
|
|
167
|
+
function resolveExports(mod, packageInfo = UNKNOWN_PACKAGE) {
|
|
146
168
|
if (!Array.isArray(mod.NODES)) {
|
|
147
169
|
throw new Error("Package entry does not export a `NODES` array. Export `NODES: INode[]`.");
|
|
148
170
|
}
|
|
@@ -159,7 +181,9 @@ function resolveExports(mod) {
|
|
|
159
181
|
nodes,
|
|
160
182
|
credentials,
|
|
161
183
|
templates,
|
|
162
|
-
manifest: (0, import_integrations_node_sdk.buildManifest)(nodes, credentials, templates)
|
|
184
|
+
manifest: (0, import_integrations_node_sdk.buildManifest)(nodes, credentials, templates),
|
|
185
|
+
packageInfo,
|
|
186
|
+
loadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
163
187
|
};
|
|
164
188
|
}
|
|
165
189
|
var tsxRegistered = false;
|
|
@@ -179,17 +203,19 @@ async function importFresh(entryPath) {
|
|
|
179
203
|
return await import(href);
|
|
180
204
|
}
|
|
181
205
|
async function loadPackageFromEntry(entryPath) {
|
|
182
|
-
return resolveExports(await importFresh(entryPath));
|
|
206
|
+
return resolveExports(await importFresh(entryPath), readPackageInfo(entryPath));
|
|
183
207
|
}
|
|
184
208
|
|
|
185
209
|
// src/persistence.ts
|
|
186
|
-
var
|
|
187
|
-
var
|
|
210
|
+
var import_node_fs3 = require("fs");
|
|
211
|
+
var import_node_path3 = require("path");
|
|
188
212
|
|
|
189
213
|
// src/store.ts
|
|
190
214
|
var import_node_crypto = require("crypto");
|
|
191
215
|
var DEV_TENANT_ID = "dev-tenant";
|
|
192
|
-
var
|
|
216
|
+
var BLOB_DEFINITION_VERSION = "v0-draft";
|
|
217
|
+
var EXECUTION_MODES = ["async_only", "sync_only", "caller_decides"];
|
|
218
|
+
var STORE_SCHEMA_VERSION = 2;
|
|
193
219
|
function now() {
|
|
194
220
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
195
221
|
}
|
|
@@ -232,6 +258,9 @@ var DevStore = class {
|
|
|
232
258
|
status: input.status ?? "active",
|
|
233
259
|
config: input.config,
|
|
234
260
|
durableCreds: input.durableCreds ?? null,
|
|
261
|
+
lastTestAt: null,
|
|
262
|
+
lastTestOk: null,
|
|
263
|
+
lastTestMessage: null,
|
|
235
264
|
createdAt: ts,
|
|
236
265
|
updatedAt: ts
|
|
237
266
|
};
|
|
@@ -260,6 +289,21 @@ var DevStore = class {
|
|
|
260
289
|
this.touch();
|
|
261
290
|
return record;
|
|
262
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Records the outcome of a credential test. The service persists this on the
|
|
294
|
+
* record and reports it back from `POST /credentials/{id}/test`.
|
|
295
|
+
*/
|
|
296
|
+
recordCredentialTest(id, result) {
|
|
297
|
+
const record = this.credentials.get(id);
|
|
298
|
+
if (!record) {
|
|
299
|
+
return void 0;
|
|
300
|
+
}
|
|
301
|
+
record.lastTestAt = now();
|
|
302
|
+
record.lastTestOk = result.ok;
|
|
303
|
+
record.lastTestMessage = result.message ?? null;
|
|
304
|
+
this.touch();
|
|
305
|
+
return record;
|
|
306
|
+
}
|
|
263
307
|
deleteCredential(id) {
|
|
264
308
|
const deleted = this.credentials.delete(id);
|
|
265
309
|
if (deleted) {
|
|
@@ -306,7 +350,12 @@ var DevStore = class {
|
|
|
306
350
|
const record = {
|
|
307
351
|
id: this.nextWorkflowId++,
|
|
308
352
|
name: input.name,
|
|
309
|
-
|
|
353
|
+
description: input.description ?? null,
|
|
354
|
+
blob: input.blob,
|
|
355
|
+
blobDefinitionVersion: input.blobDefinitionVersion ?? BLOB_DEFINITION_VERSION,
|
|
356
|
+
active: input.active ?? true,
|
|
357
|
+
executionMode: input.executionMode ?? EXECUTION_MODES[0],
|
|
358
|
+
revision: 1,
|
|
310
359
|
buildStatus: "ready",
|
|
311
360
|
createdAt: ts,
|
|
312
361
|
updatedAt: ts
|
|
@@ -320,7 +369,8 @@ var DevStore = class {
|
|
|
320
369
|
if (!record) {
|
|
321
370
|
return void 0;
|
|
322
371
|
}
|
|
323
|
-
Object.
|
|
372
|
+
const defined = Object.fromEntries(Object.entries(patch).filter(([, v]) => v !== void 0));
|
|
373
|
+
Object.assign(record, defined, { revision: record.revision + 1, updatedAt: now() });
|
|
324
374
|
this.touch();
|
|
325
375
|
return record;
|
|
326
376
|
}
|
|
@@ -461,16 +511,23 @@ function applySeeds(store, seeds, env = process.env) {
|
|
|
461
511
|
});
|
|
462
512
|
}
|
|
463
513
|
for (const workflow of seeds.workflows ?? []) {
|
|
464
|
-
|
|
514
|
+
const resolved = interpolateEnv(workflow, env);
|
|
515
|
+
store.createWorkflow({
|
|
516
|
+
name: resolved.name,
|
|
517
|
+
blob: resolved.blob ?? resolved.definition ?? {},
|
|
518
|
+
description: resolved.description,
|
|
519
|
+
active: resolved.active,
|
|
520
|
+
executionMode: resolved.executionMode
|
|
521
|
+
});
|
|
465
522
|
}
|
|
466
523
|
}
|
|
467
524
|
function loadState(file, log = console.warn) {
|
|
468
|
-
if (!(0,
|
|
525
|
+
if (!(0, import_node_fs3.existsSync)(file)) {
|
|
469
526
|
return null;
|
|
470
527
|
}
|
|
471
528
|
let parsed;
|
|
472
529
|
try {
|
|
473
|
-
parsed = JSON.parse((0,
|
|
530
|
+
parsed = JSON.parse((0, import_node_fs3.readFileSync)(file, "utf-8"));
|
|
474
531
|
} catch {
|
|
475
532
|
log(`Ignoring ${file}: not valid JSON.`);
|
|
476
533
|
return null;
|
|
@@ -482,14 +539,14 @@ function loadState(file, log = console.warn) {
|
|
|
482
539
|
return parsed;
|
|
483
540
|
}
|
|
484
541
|
function saveState(file, snapshot) {
|
|
485
|
-
(0,
|
|
486
|
-
(0,
|
|
542
|
+
(0, import_node_fs3.mkdirSync)((0, import_node_path3.dirname)(file), { recursive: true });
|
|
543
|
+
(0, import_node_fs3.writeFileSync)(file, JSON.stringify(snapshot, null, 2), "utf-8");
|
|
487
544
|
}
|
|
488
545
|
var SEED_ENTRY_CANDIDATES = ["index.ts", "index.mjs", "index.js", "seeds.ts", "seeds.js"];
|
|
489
546
|
async function loadSeedsFromDir(dir) {
|
|
490
547
|
for (const candidate of SEED_ENTRY_CANDIDATES) {
|
|
491
|
-
const path = (0,
|
|
492
|
-
if ((0,
|
|
548
|
+
const path = (0, import_node_path3.resolve)(dir, candidate);
|
|
549
|
+
if ((0, import_node_fs3.existsSync)(path)) {
|
|
493
550
|
const mod = await importFresh(path);
|
|
494
551
|
return mod.default ?? mod.seeds ?? {};
|
|
495
552
|
}
|
|
@@ -755,6 +812,56 @@ async function validateNodeConfig(loaded, store, input) {
|
|
|
755
812
|
}
|
|
756
813
|
return { valid: Object.keys(errors).length === 0, errors };
|
|
757
814
|
}
|
|
815
|
+
var MIN_TIMEOUT_MS = 1e3;
|
|
816
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
817
|
+
var ExecuteTimeout = class extends Error {
|
|
818
|
+
};
|
|
819
|
+
async function executeNodeTest(loaded, store, input) {
|
|
820
|
+
const node = findNode(loaded, input.slug, input.version);
|
|
821
|
+
const logs = [];
|
|
822
|
+
const record = (level) => (message, meta) => {
|
|
823
|
+
logs.push(meta === void 0 ? { level, message } : { level, message, meta });
|
|
824
|
+
};
|
|
825
|
+
const timeoutMs = Math.max(MIN_TIMEOUT_MS, input.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
826
|
+
const controller = new AbortController();
|
|
827
|
+
let timer;
|
|
828
|
+
const expired = new Promise((_resolve, reject) => {
|
|
829
|
+
timer = setTimeout(() => {
|
|
830
|
+
controller.abort();
|
|
831
|
+
reject(new ExecuteTimeout());
|
|
832
|
+
}, timeoutMs);
|
|
833
|
+
});
|
|
834
|
+
const ctx = {
|
|
835
|
+
signal: controller.signal,
|
|
836
|
+
logger: { info: record("info"), warn: record("warn"), error: record("error") },
|
|
837
|
+
secrets: {
|
|
838
|
+
async get(key) {
|
|
839
|
+
const secret = store.getSecret(key);
|
|
840
|
+
if (!secret) {
|
|
841
|
+
throw new DevApiError(404, `Secret '${key}' not found.`);
|
|
842
|
+
}
|
|
843
|
+
return secret.value;
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
credentials: {
|
|
847
|
+
async get(id) {
|
|
848
|
+
return (await resolveCredentialInstance(loaded, store, id)).credentials;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
try {
|
|
853
|
+
const result = await Promise.race([node.execute(ctx, { ...input.config, ...input.inputs }), expired]);
|
|
854
|
+
return { outputs: result.outputs ?? {}, branch: result.branch ?? null, logs };
|
|
855
|
+
} catch (err) {
|
|
856
|
+
if (err instanceof DevApiError) {
|
|
857
|
+
throw err;
|
|
858
|
+
}
|
|
859
|
+
const reason = err instanceof ExecuteTimeout || controller.signal.aborted ? `timed out after ${timeoutMs} ms` : err.message;
|
|
860
|
+
throw new DevApiError(502, `Node execution failed: ${reason}`, { logs: logs.map((l) => `${l.level}: ${l.message}`) });
|
|
861
|
+
} finally {
|
|
862
|
+
clearTimeout(timer);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
758
865
|
async function testCredentialConfig(loaded, store, typeSlug, config) {
|
|
759
866
|
const cred = findCredential(loaded, typeSlug);
|
|
760
867
|
return cred.test(credentialContext(store), config);
|
|
@@ -796,16 +903,22 @@ async function exchangeOAuthCode(loaded, store, credentialId, params) {
|
|
|
796
903
|
var import_node_http = __toESM(require("http"), 1);
|
|
797
904
|
|
|
798
905
|
// src/http.ts
|
|
906
|
+
var API_VERSION = "1.0.0";
|
|
907
|
+
var BASE_HEADERS = {
|
|
908
|
+
"X-Api-Version": API_VERSION,
|
|
909
|
+
"Access-Control-Allow-Origin": "*",
|
|
910
|
+
"Access-Control-Allow-Headers": "*",
|
|
911
|
+
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
|
912
|
+
};
|
|
799
913
|
function sendJson(res, status, body) {
|
|
800
914
|
const payload = JSON.stringify(body);
|
|
801
|
-
res.writeHead(status, {
|
|
802
|
-
"Content-Type": "application/json",
|
|
803
|
-
"Access-Control-Allow-Origin": "*",
|
|
804
|
-
"Access-Control-Allow-Headers": "*",
|
|
805
|
-
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
|
806
|
-
});
|
|
915
|
+
res.writeHead(status, { "Content-Type": "application/json", ...BASE_HEADERS });
|
|
807
916
|
res.end(payload);
|
|
808
917
|
}
|
|
918
|
+
function sendNoContent(res) {
|
|
919
|
+
res.writeHead(204, BASE_HEADERS);
|
|
920
|
+
res.end();
|
|
921
|
+
}
|
|
809
922
|
function sendError(res, err) {
|
|
810
923
|
if (err instanceof DevApiError) {
|
|
811
924
|
sendJson(res, err.status, err.errors ? { message: err.message, errors: err.errors } : { message: err.message });
|
|
@@ -843,20 +956,24 @@ function hasDynamicSchema(desc) {
|
|
|
843
956
|
function hasDynamicOutputs(desc) {
|
|
844
957
|
return (desc.outputs ?? []).some((o) => o.resolveOutputs === true);
|
|
845
958
|
}
|
|
846
|
-
function nodeToApi(desc) {
|
|
959
|
+
function nodeToApi(desc, ctx) {
|
|
847
960
|
const [namespace] = desc.slug.split(":");
|
|
848
961
|
return {
|
|
849
962
|
name: desc.name,
|
|
850
963
|
namespace: namespace ?? null,
|
|
851
964
|
slug: desc.slug,
|
|
852
965
|
version: desc.version,
|
|
966
|
+
// The contract declares `package` and both timestamps as present. Nodes here
|
|
967
|
+
// come from the developer's working tree, so the package identity is read from
|
|
968
|
+
// their package.json and the timestamps are when the mock loaded the entry.
|
|
969
|
+
package: ctx?.packageInfo ?? null,
|
|
853
970
|
manifest_version: import_integrations_node_sdk3.MANIFEST_VERSION,
|
|
854
971
|
manifest: desc,
|
|
855
972
|
has_dynamic_options: hasDynamicOptions(desc),
|
|
856
973
|
has_dynamic_schema: hasDynamicSchema(desc),
|
|
857
974
|
has_dynamic_outputs: hasDynamicOutputs(desc),
|
|
858
|
-
created_at: null,
|
|
859
|
-
updated_at: null
|
|
975
|
+
created_at: ctx?.loadedAt ?? null,
|
|
976
|
+
updated_at: ctx?.loadedAt ?? null
|
|
860
977
|
};
|
|
861
978
|
}
|
|
862
979
|
function credentialTypeToApi(desc) {
|
|
@@ -866,6 +983,7 @@ function credentialTypeToApi(desc) {
|
|
|
866
983
|
name: desc.name,
|
|
867
984
|
description: desc.description ?? null,
|
|
868
985
|
icon: desc.icon ?? null,
|
|
986
|
+
images: desc.images ?? [],
|
|
869
987
|
auth_kind: desc.authKind,
|
|
870
988
|
fields: desc.fields
|
|
871
989
|
};
|
|
@@ -901,7 +1019,16 @@ function workflowToApi(record) {
|
|
|
901
1019
|
return {
|
|
902
1020
|
id: record.id,
|
|
903
1021
|
name: record.name,
|
|
904
|
-
|
|
1022
|
+
description: record.description,
|
|
1023
|
+
blob_definition_version: record.blobDefinitionVersion,
|
|
1024
|
+
blob: record.blob,
|
|
1025
|
+
active: record.active,
|
|
1026
|
+
execution_mode: record.executionMode,
|
|
1027
|
+
revision: record.revision,
|
|
1028
|
+
// The service reports blob-validation warnings here. The mock's validation is
|
|
1029
|
+
// schema-light (see the fidelity caveats), so it never has any — but the field
|
|
1030
|
+
// is part of the contract and clients may read it.
|
|
1031
|
+
warnings: [],
|
|
905
1032
|
build_status: record.buildStatus,
|
|
906
1033
|
created_at: record.createdAt,
|
|
907
1034
|
updated_at: record.updatedAt
|
|
@@ -930,6 +1057,7 @@ function templateSummaryToApi(t) {
|
|
|
930
1057
|
shortDescription: t.shortDescription ?? null,
|
|
931
1058
|
description: t.description ?? null,
|
|
932
1059
|
icon: t.icon ?? null,
|
|
1060
|
+
images: t.images ?? [],
|
|
933
1061
|
industries: t.industries ?? [],
|
|
934
1062
|
vendors: t.vendors ?? [],
|
|
935
1063
|
triggerTypes: (t.triggers ?? []).map((tr) => tr.type)
|
|
@@ -938,9 +1066,13 @@ function templateSummaryToApi(t) {
|
|
|
938
1066
|
function templateFullToApi(t) {
|
|
939
1067
|
return {
|
|
940
1068
|
...templateSummaryToApi(t),
|
|
941
|
-
|
|
1069
|
+
// snake_case per the contract, even though the surrounding template fields are
|
|
1070
|
+
// camelCase and the SDK's own field is `blobVersion`.
|
|
1071
|
+
blob_version: t.blobVersion,
|
|
942
1072
|
definition: t.definition,
|
|
943
|
-
|
|
1073
|
+
// `config` is optional in the SDK (a manual trigger has none) but declared in
|
|
1074
|
+
// the contract, so normalise it to an object rather than omitting it.
|
|
1075
|
+
triggers: (t.triggers ?? []).map((tr) => ({ ...tr, config: tr.config ?? {} }))
|
|
944
1076
|
};
|
|
945
1077
|
}
|
|
946
1078
|
|
|
@@ -971,13 +1103,15 @@ async function handle(req, res, deps) {
|
|
|
971
1103
|
switch (seg[0]) {
|
|
972
1104
|
case void 0:
|
|
973
1105
|
case "health":
|
|
1106
|
+
// The service's health route is `/up` (Laravel's default); `/health` is kept
|
|
1107
|
+
// because the devkit has always answered there.
|
|
1108
|
+
case "up":
|
|
974
1109
|
return void sendJson(res, 200, { status: "ok" });
|
|
975
1110
|
case "me":
|
|
976
1111
|
return void sendJson(res, 200, {
|
|
977
|
-
id: "dev-user",
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
tenant_id: DEV_TENANT_ID
|
|
1112
|
+
user: { id: 1, zitadel_id: "dev-user", email: "dev@revenexx.test", name: "Dev User" },
|
|
1113
|
+
context: { tenant_id: DEV_TENANT_ID, active_plane: "public", roles: ["admin", "user"] },
|
|
1114
|
+
claims: { iss: "https://id.revenexx.test", sub: "dev-user", aud: ["devkit"] }
|
|
981
1115
|
});
|
|
982
1116
|
case "schemas":
|
|
983
1117
|
return handleSchemas(res, deps, seg);
|
|
@@ -1004,15 +1138,22 @@ function handleSchemas(res, deps, seg) {
|
|
|
1004
1138
|
throw new DevApiError(404, "Schema domain required.");
|
|
1005
1139
|
}
|
|
1006
1140
|
const schemas = deps.schemas ?? {};
|
|
1007
|
-
|
|
1141
|
+
if (!version) {
|
|
1142
|
+
const versions = Object.keys(schemas).filter((key) => key.startsWith(`${domain}/`)).map((key) => key.slice(domain.length + 1)).sort();
|
|
1143
|
+
if (versions.length === 0 && !schemas[domain]) {
|
|
1144
|
+
throw new DevApiError(404, `Unknown schema domain '${domain}'. Vendor it into assets/schemas.`);
|
|
1145
|
+
}
|
|
1146
|
+
return void sendJson(res, 200, { domain, versions });
|
|
1147
|
+
}
|
|
1148
|
+
const schema = schemas[`${domain}/${version}`];
|
|
1008
1149
|
if (!schema) {
|
|
1009
|
-
throw new DevApiError(404, `
|
|
1150
|
+
throw new DevApiError(404, `Unknown schema version '${domain}/${version}'. Vendor it into assets/schemas.`);
|
|
1010
1151
|
}
|
|
1011
|
-
sendJson(res, 200, schema);
|
|
1152
|
+
sendJson(res, 200, { domain, version, schema });
|
|
1012
1153
|
}
|
|
1013
1154
|
async function handleNodes(req, res, method, loaded, store, seg) {
|
|
1014
1155
|
if (seg.length === 1 && method === "GET") {
|
|
1015
|
-
return void sendJson(res, 200, { data: loaded.manifest.nodes.map(nodeToApi) });
|
|
1156
|
+
return void sendJson(res, 200, { data: loaded.manifest.nodes.map((n) => nodeToApi(n, nodeApiContext(loaded))) });
|
|
1016
1157
|
}
|
|
1017
1158
|
const slug = seg[1];
|
|
1018
1159
|
if (!slug) {
|
|
@@ -1053,15 +1194,36 @@ async function handleNodes(req, res, method, loaded, store, seg) {
|
|
|
1053
1194
|
});
|
|
1054
1195
|
return void sendJson(res, 200, result);
|
|
1055
1196
|
}
|
|
1197
|
+
if (seg[3] === "execute:test" && method === "POST") {
|
|
1198
|
+
const body = await readJson(req);
|
|
1199
|
+
const result = await executeNodeTest(loaded, store, {
|
|
1200
|
+
slug,
|
|
1201
|
+
version,
|
|
1202
|
+
config: body.config ?? {},
|
|
1203
|
+
inputs: body.inputs ?? {},
|
|
1204
|
+
timeoutMs: body.timeout_ms
|
|
1205
|
+
});
|
|
1206
|
+
return void sendJson(res, 200, result);
|
|
1207
|
+
}
|
|
1056
1208
|
if (seg.length === 3 && method === "GET") {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
return void
|
|
1209
|
+
return void sendJson(res, 200, nodeToApi(findManifestNode(loaded, slug, version), nodeApiContext(loaded)));
|
|
1210
|
+
}
|
|
1211
|
+
if (seg.length === 3 && method === "DELETE") {
|
|
1212
|
+
findManifestNode(loaded, slug, version);
|
|
1213
|
+
return void sendNoContent(res);
|
|
1062
1214
|
}
|
|
1063
1215
|
throw new DevApiError(404, `No route for nodes/${seg.slice(1).join("/")}`);
|
|
1064
1216
|
}
|
|
1217
|
+
function nodeApiContext(loaded) {
|
|
1218
|
+
return { packageInfo: loaded.packageInfo, loadedAt: loaded.loadedAt };
|
|
1219
|
+
}
|
|
1220
|
+
function findManifestNode(loaded, slug, version) {
|
|
1221
|
+
const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
|
|
1222
|
+
if (!node) {
|
|
1223
|
+
throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
|
|
1224
|
+
}
|
|
1225
|
+
return node;
|
|
1226
|
+
}
|
|
1065
1227
|
function handleCredentialTypes(res, loaded, seg) {
|
|
1066
1228
|
if (seg.length === 1) {
|
|
1067
1229
|
return void sendJson(res, 200, {
|
|
@@ -1125,7 +1287,13 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
|
1125
1287
|
}
|
|
1126
1288
|
if (seg[2] === "test" && method === "POST") {
|
|
1127
1289
|
const result = await testCredentialInstance(loaded, store, id);
|
|
1128
|
-
|
|
1290
|
+
const record = store.recordCredentialTest(id, { ok: result.ok, message: result.message ?? null });
|
|
1291
|
+
return void sendJson(res, 200, {
|
|
1292
|
+
ok: result.ok,
|
|
1293
|
+
message: result.message ?? null,
|
|
1294
|
+
last_test_at: record?.lastTestAt ?? null,
|
|
1295
|
+
last_test_ok: record?.lastTestOk ?? result.ok
|
|
1296
|
+
});
|
|
1129
1297
|
}
|
|
1130
1298
|
if (seg[2] === "oauth" && seg[3] === "authorize-url" && method === "POST") {
|
|
1131
1299
|
const redirectUri = "http://localhost/api/v1/credentials/oauth/callback";
|
|
@@ -1150,7 +1318,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
|
1150
1318
|
}
|
|
1151
1319
|
if (method === "DELETE") {
|
|
1152
1320
|
store.deleteCredential(id);
|
|
1153
|
-
return void
|
|
1321
|
+
return void sendNoContent(res);
|
|
1154
1322
|
}
|
|
1155
1323
|
}
|
|
1156
1324
|
throw new DevApiError(404, `No route for credentials/${seg.slice(1).join("/")}`);
|
|
@@ -1158,7 +1326,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
|
1158
1326
|
async function handleSecrets(req, res, method, store, seg) {
|
|
1159
1327
|
if (seg.length === 1) {
|
|
1160
1328
|
if (method === "GET") {
|
|
1161
|
-
return void sendJson(res, 200, {
|
|
1329
|
+
return void sendJson(res, 200, { keys: store.listSecrets().map((s) => s.key) });
|
|
1162
1330
|
}
|
|
1163
1331
|
if (method === "POST") {
|
|
1164
1332
|
const body = await readJson(req);
|
|
@@ -1180,7 +1348,7 @@ async function handleSecrets(req, res, method, store, seg) {
|
|
|
1180
1348
|
}
|
|
1181
1349
|
if (method === "DELETE") {
|
|
1182
1350
|
store.deleteSecret(key);
|
|
1183
|
-
return void
|
|
1351
|
+
return void sendNoContent(res);
|
|
1184
1352
|
}
|
|
1185
1353
|
}
|
|
1186
1354
|
throw new DevApiError(404, `No route for secrets/${seg.slice(1).join("/")}`);
|
|
@@ -1196,16 +1364,17 @@ async function handleTemplates(req, res, method, loaded, store, seg) {
|
|
|
1196
1364
|
throw new DevApiError(404, `Template '${slug}' not found.`);
|
|
1197
1365
|
}
|
|
1198
1366
|
if (seg.length === 2 && method === "GET") {
|
|
1199
|
-
return void sendJson(res, 200, templateFullToApi(template));
|
|
1367
|
+
return void sendJson(res, 200, { data: templateFullToApi(template) });
|
|
1200
1368
|
}
|
|
1201
1369
|
if (seg[2] === "requirements" && method === "GET") {
|
|
1202
|
-
return void sendJson(res, 200, { data: {
|
|
1370
|
+
return void sendJson(res, 200, { data: { credentialTypes: [], secrets: [] } });
|
|
1203
1371
|
}
|
|
1204
1372
|
if (seg[2] === "instantiate" && method === "POST") {
|
|
1205
1373
|
const body = await readJson(req);
|
|
1206
1374
|
const workflow = store.createWorkflow({
|
|
1207
1375
|
name: body.name ?? String(template.name),
|
|
1208
|
-
|
|
1376
|
+
blob: template.definition,
|
|
1377
|
+
blobDefinitionVersion: template.blobVersion
|
|
1209
1378
|
});
|
|
1210
1379
|
for (const trigger of template.triggers ?? []) {
|
|
1211
1380
|
store.createTrigger({
|
|
@@ -1230,7 +1399,11 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1230
1399
|
const body = await readJson(req);
|
|
1231
1400
|
const workflow = store.createWorkflow({
|
|
1232
1401
|
name: body.name ?? "Untitled workflow",
|
|
1233
|
-
|
|
1402
|
+
blob: body.blob ?? {},
|
|
1403
|
+
blobDefinitionVersion: body.blob_definition_version,
|
|
1404
|
+
description: body.description,
|
|
1405
|
+
active: body.active,
|
|
1406
|
+
executionMode: body.execution_mode
|
|
1234
1407
|
});
|
|
1235
1408
|
return void sendJson(res, 201, workflowToApi(workflow));
|
|
1236
1409
|
}
|
|
@@ -1271,7 +1444,7 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1271
1444
|
}
|
|
1272
1445
|
if (triggerId && method === "DELETE") {
|
|
1273
1446
|
store.deleteTrigger(triggerId);
|
|
1274
|
-
return void
|
|
1447
|
+
return void sendNoContent(res);
|
|
1275
1448
|
}
|
|
1276
1449
|
}
|
|
1277
1450
|
if (seg.length === 2) {
|
|
@@ -1284,7 +1457,14 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1284
1457
|
}
|
|
1285
1458
|
if (method === "PUT") {
|
|
1286
1459
|
const body = await readJson(req);
|
|
1287
|
-
const updated = store.updateWorkflow(id, {
|
|
1460
|
+
const updated = store.updateWorkflow(id, {
|
|
1461
|
+
name: body.name,
|
|
1462
|
+
blob: body.blob,
|
|
1463
|
+
blobDefinitionVersion: body.blob_definition_version,
|
|
1464
|
+
description: body.description,
|
|
1465
|
+
active: body.active,
|
|
1466
|
+
executionMode: body.execution_mode
|
|
1467
|
+
});
|
|
1288
1468
|
if (!updated) {
|
|
1289
1469
|
throw new DevApiError(404, `Workflow '${id}' not found.`);
|
|
1290
1470
|
}
|
|
@@ -1292,7 +1472,7 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1292
1472
|
}
|
|
1293
1473
|
if (method === "DELETE") {
|
|
1294
1474
|
store.deleteWorkflow(id);
|
|
1295
|
-
return void
|
|
1475
|
+
return void sendNoContent(res);
|
|
1296
1476
|
}
|
|
1297
1477
|
}
|
|
1298
1478
|
if ((seg[2] === "credentials" || seg[2] === "credential-types") && method === "GET") {
|
|
@@ -1303,7 +1483,7 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1303
1483
|
|
|
1304
1484
|
// src/index.ts
|
|
1305
1485
|
var manifestUrl = new URL("../package.json", importMetaUrl);
|
|
1306
|
-
var DEVKIT_VERSION = JSON.parse((0,
|
|
1486
|
+
var DEVKIT_VERSION = JSON.parse((0, import_node_fs4.readFileSync)(manifestUrl, "utf8")).version;
|
|
1307
1487
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1308
1488
|
0 && (module.exports = {
|
|
1309
1489
|
DEVKIT_VERSION,
|