@revenexx/integrations-node-devkit 0.2.1 → 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-UBYGZFB7.js → chunk-PS3HCKE7.js} +263 -68
- package/dist/chunk-PS3HCKE7.js.map +1 -0
- package/dist/cli.cjs +426 -545
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +140 -452
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +258 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -8
- package/dist/index.d.ts +80 -8
- 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-UBYGZFB7.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");
|
|
@@ -83,15 +83,25 @@ function resolveEnvFile(argv, cwd = process.cwd()) {
|
|
|
83
83
|
if (argv.includes("--no-env")) {
|
|
84
84
|
return { path: null, explicit: false };
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
let named = null;
|
|
87
|
+
for (let i = 0; i < argv.length; i++) {
|
|
88
|
+
if (argv[i] !== "--env") {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const value = argv[++i];
|
|
92
|
+
if (!value || value.startsWith("-")) {
|
|
93
|
+
throw new Error("--env requires a path.");
|
|
94
|
+
}
|
|
95
|
+
named = { path: (0, import_node_path.resolve)(cwd, value), explicit: true, raw: value };
|
|
89
96
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
return named ?? { path: (0, import_node_path.resolve)(cwd, ".env"), explicit: false };
|
|
98
|
+
}
|
|
99
|
+
function missingFileMessage(choice, cwd) {
|
|
100
|
+
const raw = choice.raw;
|
|
101
|
+
if (raw && raw === (0, import_node_path.basename)(raw) && (0, import_node_fs.existsSync)((0, import_node_path.resolve)(cwd, `.env.${raw}`))) {
|
|
102
|
+
return `--env: ${choice.path} does not exist. Did you mean --env .env.${raw}? The flag takes a path, not an environment name.`;
|
|
93
103
|
}
|
|
94
|
-
return
|
|
104
|
+
return `--env: ${choice.path} does not exist.`;
|
|
95
105
|
}
|
|
96
106
|
function loadEnvFile(argv, options = {}) {
|
|
97
107
|
const { cwd = process.cwd(), warn = (message) => console.warn(message) } = options;
|
|
@@ -99,22 +109,22 @@ function loadEnvFile(argv, options = {}) {
|
|
|
99
109
|
if (nodeFlag) {
|
|
100
110
|
warn(`Note: ${nodeFlag} is a Node flag and Node has already applied it. The devkit's own flag is --env <path>.`);
|
|
101
111
|
}
|
|
102
|
-
const
|
|
103
|
-
if (!path) {
|
|
112
|
+
const choice = resolveEnvFile(argv, cwd);
|
|
113
|
+
if (!choice.path) {
|
|
104
114
|
return null;
|
|
105
115
|
}
|
|
106
|
-
if (!(0, import_node_fs.existsSync)(path)) {
|
|
107
|
-
if (explicit) {
|
|
108
|
-
throw new Error(
|
|
116
|
+
if (!(0, import_node_fs.existsSync)(choice.path)) {
|
|
117
|
+
if (choice.explicit) {
|
|
118
|
+
throw new Error(missingFileMessage(choice, cwd));
|
|
109
119
|
}
|
|
110
120
|
return null;
|
|
111
121
|
}
|
|
112
122
|
if (typeof process.loadEnvFile !== "function") {
|
|
113
|
-
warn(`Ignoring ${path}: env-file support needs Node >= ${ENV_FILE_MIN_NODE} (running ${process.version}).`);
|
|
123
|
+
warn(`Ignoring ${choice.path}: env-file support needs Node >= ${ENV_FILE_MIN_NODE} (running ${process.version}).`);
|
|
114
124
|
return null;
|
|
115
125
|
}
|
|
116
|
-
process.loadEnvFile(path);
|
|
117
|
-
return path;
|
|
126
|
+
process.loadEnvFile(choice.path);
|
|
127
|
+
return choice.path;
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
// src/errors.ts
|
|
@@ -130,9 +140,31 @@ var DevApiError = class extends Error {
|
|
|
130
140
|
};
|
|
131
141
|
|
|
132
142
|
// src/loader.ts
|
|
143
|
+
var import_node_fs2 = require("fs");
|
|
144
|
+
var import_node_path2 = require("path");
|
|
133
145
|
var import_node_url = require("url");
|
|
134
146
|
var import_integrations_node_sdk = require("@revenexx/integrations-node-sdk");
|
|
135
|
-
|
|
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) {
|
|
136
168
|
if (!Array.isArray(mod.NODES)) {
|
|
137
169
|
throw new Error("Package entry does not export a `NODES` array. Export `NODES: INode[]`.");
|
|
138
170
|
}
|
|
@@ -149,7 +181,9 @@ function resolveExports(mod) {
|
|
|
149
181
|
nodes,
|
|
150
182
|
credentials,
|
|
151
183
|
templates,
|
|
152
|
-
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()
|
|
153
187
|
};
|
|
154
188
|
}
|
|
155
189
|
var tsxRegistered = false;
|
|
@@ -169,17 +203,19 @@ async function importFresh(entryPath) {
|
|
|
169
203
|
return await import(href);
|
|
170
204
|
}
|
|
171
205
|
async function loadPackageFromEntry(entryPath) {
|
|
172
|
-
return resolveExports(await importFresh(entryPath));
|
|
206
|
+
return resolveExports(await importFresh(entryPath), readPackageInfo(entryPath));
|
|
173
207
|
}
|
|
174
208
|
|
|
175
209
|
// src/persistence.ts
|
|
176
|
-
var
|
|
177
|
-
var
|
|
210
|
+
var import_node_fs3 = require("fs");
|
|
211
|
+
var import_node_path3 = require("path");
|
|
178
212
|
|
|
179
213
|
// src/store.ts
|
|
180
214
|
var import_node_crypto = require("crypto");
|
|
181
215
|
var DEV_TENANT_ID = "dev-tenant";
|
|
182
|
-
var
|
|
216
|
+
var BLOB_DEFINITION_VERSION = "v0-draft";
|
|
217
|
+
var EXECUTION_MODES = ["async_only", "sync_only", "caller_decides"];
|
|
218
|
+
var STORE_SCHEMA_VERSION = 2;
|
|
183
219
|
function now() {
|
|
184
220
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
185
221
|
}
|
|
@@ -222,6 +258,9 @@ var DevStore = class {
|
|
|
222
258
|
status: input.status ?? "active",
|
|
223
259
|
config: input.config,
|
|
224
260
|
durableCreds: input.durableCreds ?? null,
|
|
261
|
+
lastTestAt: null,
|
|
262
|
+
lastTestOk: null,
|
|
263
|
+
lastTestMessage: null,
|
|
225
264
|
createdAt: ts,
|
|
226
265
|
updatedAt: ts
|
|
227
266
|
};
|
|
@@ -250,6 +289,21 @@ var DevStore = class {
|
|
|
250
289
|
this.touch();
|
|
251
290
|
return record;
|
|
252
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
|
+
}
|
|
253
307
|
deleteCredential(id) {
|
|
254
308
|
const deleted = this.credentials.delete(id);
|
|
255
309
|
if (deleted) {
|
|
@@ -296,7 +350,12 @@ var DevStore = class {
|
|
|
296
350
|
const record = {
|
|
297
351
|
id: this.nextWorkflowId++,
|
|
298
352
|
name: input.name,
|
|
299
|
-
|
|
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,
|
|
300
359
|
buildStatus: "ready",
|
|
301
360
|
createdAt: ts,
|
|
302
361
|
updatedAt: ts
|
|
@@ -310,7 +369,8 @@ var DevStore = class {
|
|
|
310
369
|
if (!record) {
|
|
311
370
|
return void 0;
|
|
312
371
|
}
|
|
313
|
-
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() });
|
|
314
374
|
this.touch();
|
|
315
375
|
return record;
|
|
316
376
|
}
|
|
@@ -451,16 +511,23 @@ function applySeeds(store, seeds, env = process.env) {
|
|
|
451
511
|
});
|
|
452
512
|
}
|
|
453
513
|
for (const workflow of seeds.workflows ?? []) {
|
|
454
|
-
|
|
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
|
+
});
|
|
455
522
|
}
|
|
456
523
|
}
|
|
457
524
|
function loadState(file, log = console.warn) {
|
|
458
|
-
if (!(0,
|
|
525
|
+
if (!(0, import_node_fs3.existsSync)(file)) {
|
|
459
526
|
return null;
|
|
460
527
|
}
|
|
461
528
|
let parsed;
|
|
462
529
|
try {
|
|
463
|
-
parsed = JSON.parse((0,
|
|
530
|
+
parsed = JSON.parse((0, import_node_fs3.readFileSync)(file, "utf-8"));
|
|
464
531
|
} catch {
|
|
465
532
|
log(`Ignoring ${file}: not valid JSON.`);
|
|
466
533
|
return null;
|
|
@@ -472,14 +539,14 @@ function loadState(file, log = console.warn) {
|
|
|
472
539
|
return parsed;
|
|
473
540
|
}
|
|
474
541
|
function saveState(file, snapshot) {
|
|
475
|
-
(0,
|
|
476
|
-
(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");
|
|
477
544
|
}
|
|
478
545
|
var SEED_ENTRY_CANDIDATES = ["index.ts", "index.mjs", "index.js", "seeds.ts", "seeds.js"];
|
|
479
546
|
async function loadSeedsFromDir(dir) {
|
|
480
547
|
for (const candidate of SEED_ENTRY_CANDIDATES) {
|
|
481
|
-
const path = (0,
|
|
482
|
-
if ((0,
|
|
548
|
+
const path = (0, import_node_path3.resolve)(dir, candidate);
|
|
549
|
+
if ((0, import_node_fs3.existsSync)(path)) {
|
|
483
550
|
const mod = await importFresh(path);
|
|
484
551
|
return mod.default ?? mod.seeds ?? {};
|
|
485
552
|
}
|
|
@@ -745,6 +812,56 @@ async function validateNodeConfig(loaded, store, input) {
|
|
|
745
812
|
}
|
|
746
813
|
return { valid: Object.keys(errors).length === 0, errors };
|
|
747
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
|
+
}
|
|
748
865
|
async function testCredentialConfig(loaded, store, typeSlug, config) {
|
|
749
866
|
const cred = findCredential(loaded, typeSlug);
|
|
750
867
|
return cred.test(credentialContext(store), config);
|
|
@@ -786,16 +903,22 @@ async function exchangeOAuthCode(loaded, store, credentialId, params) {
|
|
|
786
903
|
var import_node_http = __toESM(require("http"), 1);
|
|
787
904
|
|
|
788
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
|
+
};
|
|
789
913
|
function sendJson(res, status, body) {
|
|
790
914
|
const payload = JSON.stringify(body);
|
|
791
|
-
res.writeHead(status, {
|
|
792
|
-
"Content-Type": "application/json",
|
|
793
|
-
"Access-Control-Allow-Origin": "*",
|
|
794
|
-
"Access-Control-Allow-Headers": "*",
|
|
795
|
-
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
|
796
|
-
});
|
|
915
|
+
res.writeHead(status, { "Content-Type": "application/json", ...BASE_HEADERS });
|
|
797
916
|
res.end(payload);
|
|
798
917
|
}
|
|
918
|
+
function sendNoContent(res) {
|
|
919
|
+
res.writeHead(204, BASE_HEADERS);
|
|
920
|
+
res.end();
|
|
921
|
+
}
|
|
799
922
|
function sendError(res, err) {
|
|
800
923
|
if (err instanceof DevApiError) {
|
|
801
924
|
sendJson(res, err.status, err.errors ? { message: err.message, errors: err.errors } : { message: err.message });
|
|
@@ -833,20 +956,24 @@ function hasDynamicSchema(desc) {
|
|
|
833
956
|
function hasDynamicOutputs(desc) {
|
|
834
957
|
return (desc.outputs ?? []).some((o) => o.resolveOutputs === true);
|
|
835
958
|
}
|
|
836
|
-
function nodeToApi(desc) {
|
|
959
|
+
function nodeToApi(desc, ctx) {
|
|
837
960
|
const [namespace] = desc.slug.split(":");
|
|
838
961
|
return {
|
|
839
962
|
name: desc.name,
|
|
840
963
|
namespace: namespace ?? null,
|
|
841
964
|
slug: desc.slug,
|
|
842
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,
|
|
843
970
|
manifest_version: import_integrations_node_sdk3.MANIFEST_VERSION,
|
|
844
971
|
manifest: desc,
|
|
845
972
|
has_dynamic_options: hasDynamicOptions(desc),
|
|
846
973
|
has_dynamic_schema: hasDynamicSchema(desc),
|
|
847
974
|
has_dynamic_outputs: hasDynamicOutputs(desc),
|
|
848
|
-
created_at: null,
|
|
849
|
-
updated_at: null
|
|
975
|
+
created_at: ctx?.loadedAt ?? null,
|
|
976
|
+
updated_at: ctx?.loadedAt ?? null
|
|
850
977
|
};
|
|
851
978
|
}
|
|
852
979
|
function credentialTypeToApi(desc) {
|
|
@@ -856,6 +983,7 @@ function credentialTypeToApi(desc) {
|
|
|
856
983
|
name: desc.name,
|
|
857
984
|
description: desc.description ?? null,
|
|
858
985
|
icon: desc.icon ?? null,
|
|
986
|
+
images: desc.images ?? [],
|
|
859
987
|
auth_kind: desc.authKind,
|
|
860
988
|
fields: desc.fields
|
|
861
989
|
};
|
|
@@ -891,7 +1019,16 @@ function workflowToApi(record) {
|
|
|
891
1019
|
return {
|
|
892
1020
|
id: record.id,
|
|
893
1021
|
name: record.name,
|
|
894
|
-
|
|
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: [],
|
|
895
1032
|
build_status: record.buildStatus,
|
|
896
1033
|
created_at: record.createdAt,
|
|
897
1034
|
updated_at: record.updatedAt
|
|
@@ -920,6 +1057,7 @@ function templateSummaryToApi(t) {
|
|
|
920
1057
|
shortDescription: t.shortDescription ?? null,
|
|
921
1058
|
description: t.description ?? null,
|
|
922
1059
|
icon: t.icon ?? null,
|
|
1060
|
+
images: t.images ?? [],
|
|
923
1061
|
industries: t.industries ?? [],
|
|
924
1062
|
vendors: t.vendors ?? [],
|
|
925
1063
|
triggerTypes: (t.triggers ?? []).map((tr) => tr.type)
|
|
@@ -928,9 +1066,13 @@ function templateSummaryToApi(t) {
|
|
|
928
1066
|
function templateFullToApi(t) {
|
|
929
1067
|
return {
|
|
930
1068
|
...templateSummaryToApi(t),
|
|
931
|
-
|
|
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,
|
|
932
1072
|
definition: t.definition,
|
|
933
|
-
|
|
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 ?? {} }))
|
|
934
1076
|
};
|
|
935
1077
|
}
|
|
936
1078
|
|
|
@@ -961,13 +1103,15 @@ async function handle(req, res, deps) {
|
|
|
961
1103
|
switch (seg[0]) {
|
|
962
1104
|
case void 0:
|
|
963
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":
|
|
964
1109
|
return void sendJson(res, 200, { status: "ok" });
|
|
965
1110
|
case "me":
|
|
966
1111
|
return void sendJson(res, 200, {
|
|
967
|
-
id: "dev-user",
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
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"] }
|
|
971
1115
|
});
|
|
972
1116
|
case "schemas":
|
|
973
1117
|
return handleSchemas(res, deps, seg);
|
|
@@ -994,15 +1138,22 @@ function handleSchemas(res, deps, seg) {
|
|
|
994
1138
|
throw new DevApiError(404, "Schema domain required.");
|
|
995
1139
|
}
|
|
996
1140
|
const schemas = deps.schemas ?? {};
|
|
997
|
-
|
|
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}`];
|
|
998
1149
|
if (!schema) {
|
|
999
|
-
throw new DevApiError(404, `
|
|
1150
|
+
throw new DevApiError(404, `Unknown schema version '${domain}/${version}'. Vendor it into assets/schemas.`);
|
|
1000
1151
|
}
|
|
1001
|
-
sendJson(res, 200, schema);
|
|
1152
|
+
sendJson(res, 200, { domain, version, schema });
|
|
1002
1153
|
}
|
|
1003
1154
|
async function handleNodes(req, res, method, loaded, store, seg) {
|
|
1004
1155
|
if (seg.length === 1 && method === "GET") {
|
|
1005
|
-
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))) });
|
|
1006
1157
|
}
|
|
1007
1158
|
const slug = seg[1];
|
|
1008
1159
|
if (!slug) {
|
|
@@ -1043,15 +1194,36 @@ async function handleNodes(req, res, method, loaded, store, seg) {
|
|
|
1043
1194
|
});
|
|
1044
1195
|
return void sendJson(res, 200, result);
|
|
1045
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
|
+
}
|
|
1046
1208
|
if (seg.length === 3 && method === "GET") {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
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);
|
|
1052
1214
|
}
|
|
1053
1215
|
throw new DevApiError(404, `No route for nodes/${seg.slice(1).join("/")}`);
|
|
1054
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
|
+
}
|
|
1055
1227
|
function handleCredentialTypes(res, loaded, seg) {
|
|
1056
1228
|
if (seg.length === 1) {
|
|
1057
1229
|
return void sendJson(res, 200, {
|
|
@@ -1115,7 +1287,13 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
|
1115
1287
|
}
|
|
1116
1288
|
if (seg[2] === "test" && method === "POST") {
|
|
1117
1289
|
const result = await testCredentialInstance(loaded, store, id);
|
|
1118
|
-
|
|
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
|
+
});
|
|
1119
1297
|
}
|
|
1120
1298
|
if (seg[2] === "oauth" && seg[3] === "authorize-url" && method === "POST") {
|
|
1121
1299
|
const redirectUri = "http://localhost/api/v1/credentials/oauth/callback";
|
|
@@ -1140,7 +1318,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
|
1140
1318
|
}
|
|
1141
1319
|
if (method === "DELETE") {
|
|
1142
1320
|
store.deleteCredential(id);
|
|
1143
|
-
return void
|
|
1321
|
+
return void sendNoContent(res);
|
|
1144
1322
|
}
|
|
1145
1323
|
}
|
|
1146
1324
|
throw new DevApiError(404, `No route for credentials/${seg.slice(1).join("/")}`);
|
|
@@ -1148,7 +1326,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
|
|
|
1148
1326
|
async function handleSecrets(req, res, method, store, seg) {
|
|
1149
1327
|
if (seg.length === 1) {
|
|
1150
1328
|
if (method === "GET") {
|
|
1151
|
-
return void sendJson(res, 200, {
|
|
1329
|
+
return void sendJson(res, 200, { keys: store.listSecrets().map((s) => s.key) });
|
|
1152
1330
|
}
|
|
1153
1331
|
if (method === "POST") {
|
|
1154
1332
|
const body = await readJson(req);
|
|
@@ -1170,7 +1348,7 @@ async function handleSecrets(req, res, method, store, seg) {
|
|
|
1170
1348
|
}
|
|
1171
1349
|
if (method === "DELETE") {
|
|
1172
1350
|
store.deleteSecret(key);
|
|
1173
|
-
return void
|
|
1351
|
+
return void sendNoContent(res);
|
|
1174
1352
|
}
|
|
1175
1353
|
}
|
|
1176
1354
|
throw new DevApiError(404, `No route for secrets/${seg.slice(1).join("/")}`);
|
|
@@ -1186,16 +1364,17 @@ async function handleTemplates(req, res, method, loaded, store, seg) {
|
|
|
1186
1364
|
throw new DevApiError(404, `Template '${slug}' not found.`);
|
|
1187
1365
|
}
|
|
1188
1366
|
if (seg.length === 2 && method === "GET") {
|
|
1189
|
-
return void sendJson(res, 200, templateFullToApi(template));
|
|
1367
|
+
return void sendJson(res, 200, { data: templateFullToApi(template) });
|
|
1190
1368
|
}
|
|
1191
1369
|
if (seg[2] === "requirements" && method === "GET") {
|
|
1192
|
-
return void sendJson(res, 200, { data: {
|
|
1370
|
+
return void sendJson(res, 200, { data: { credentialTypes: [], secrets: [] } });
|
|
1193
1371
|
}
|
|
1194
1372
|
if (seg[2] === "instantiate" && method === "POST") {
|
|
1195
1373
|
const body = await readJson(req);
|
|
1196
1374
|
const workflow = store.createWorkflow({
|
|
1197
1375
|
name: body.name ?? String(template.name),
|
|
1198
|
-
|
|
1376
|
+
blob: template.definition,
|
|
1377
|
+
blobDefinitionVersion: template.blobVersion
|
|
1199
1378
|
});
|
|
1200
1379
|
for (const trigger of template.triggers ?? []) {
|
|
1201
1380
|
store.createTrigger({
|
|
@@ -1220,7 +1399,11 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1220
1399
|
const body = await readJson(req);
|
|
1221
1400
|
const workflow = store.createWorkflow({
|
|
1222
1401
|
name: body.name ?? "Untitled workflow",
|
|
1223
|
-
|
|
1402
|
+
blob: body.blob ?? {},
|
|
1403
|
+
blobDefinitionVersion: body.blob_definition_version,
|
|
1404
|
+
description: body.description,
|
|
1405
|
+
active: body.active,
|
|
1406
|
+
executionMode: body.execution_mode
|
|
1224
1407
|
});
|
|
1225
1408
|
return void sendJson(res, 201, workflowToApi(workflow));
|
|
1226
1409
|
}
|
|
@@ -1261,7 +1444,7 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1261
1444
|
}
|
|
1262
1445
|
if (triggerId && method === "DELETE") {
|
|
1263
1446
|
store.deleteTrigger(triggerId);
|
|
1264
|
-
return void
|
|
1447
|
+
return void sendNoContent(res);
|
|
1265
1448
|
}
|
|
1266
1449
|
}
|
|
1267
1450
|
if (seg.length === 2) {
|
|
@@ -1274,7 +1457,14 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1274
1457
|
}
|
|
1275
1458
|
if (method === "PUT") {
|
|
1276
1459
|
const body = await readJson(req);
|
|
1277
|
-
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
|
+
});
|
|
1278
1468
|
if (!updated) {
|
|
1279
1469
|
throw new DevApiError(404, `Workflow '${id}' not found.`);
|
|
1280
1470
|
}
|
|
@@ -1282,7 +1472,7 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1282
1472
|
}
|
|
1283
1473
|
if (method === "DELETE") {
|
|
1284
1474
|
store.deleteWorkflow(id);
|
|
1285
|
-
return void
|
|
1475
|
+
return void sendNoContent(res);
|
|
1286
1476
|
}
|
|
1287
1477
|
}
|
|
1288
1478
|
if ((seg[2] === "credentials" || seg[2] === "credential-types") && method === "GET") {
|
|
@@ -1293,7 +1483,7 @@ async function handleWorkflows(req, res, method, store, seg) {
|
|
|
1293
1483
|
|
|
1294
1484
|
// src/index.ts
|
|
1295
1485
|
var manifestUrl = new URL("../package.json", importMetaUrl);
|
|
1296
|
-
var DEVKIT_VERSION = JSON.parse((0,
|
|
1486
|
+
var DEVKIT_VERSION = JSON.parse((0, import_node_fs4.readFileSync)(manifestUrl, "utf8")).version;
|
|
1297
1487
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1298
1488
|
0 && (module.exports = {
|
|
1299
1489
|
DEVKIT_VERSION,
|