@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.
@@ -1,9 +1,9 @@
1
1
  // src/index.ts
2
- import { readFileSync as readFileSync2 } from "fs";
2
+ import { readFileSync as readFileSync3 } from "fs";
3
3
 
4
4
  // src/env.ts
5
5
  import { existsSync } from "fs";
6
- import { resolve } from "path";
6
+ import { basename, resolve } from "path";
7
7
  var ENV_FILE_MIN_NODE = "20.12";
8
8
  var NODE_OWNED_FLAGS = ["--env-file", "--env-file-if-exists"];
9
9
  function nodeOwnedEnvFlag(argv) {
@@ -13,15 +13,25 @@ function resolveEnvFile(argv, cwd = process.cwd()) {
13
13
  if (argv.includes("--no-env")) {
14
14
  return { path: null, explicit: false };
15
15
  }
16
- const flag = argv.indexOf("--env");
17
- if (flag === -1) {
18
- return { path: resolve(cwd, ".env"), explicit: false };
16
+ let named = null;
17
+ for (let i = 0; i < argv.length; i++) {
18
+ if (argv[i] !== "--env") {
19
+ continue;
20
+ }
21
+ const value = argv[++i];
22
+ if (!value || value.startsWith("-")) {
23
+ throw new Error("--env requires a path.");
24
+ }
25
+ named = { path: resolve(cwd, value), explicit: true, raw: value };
19
26
  }
20
- const value = argv[flag + 1];
21
- if (!value || value.startsWith("-")) {
22
- throw new Error("--env requires a path.");
27
+ return named ?? { path: resolve(cwd, ".env"), explicit: false };
28
+ }
29
+ function missingFileMessage(choice, cwd) {
30
+ const raw = choice.raw;
31
+ if (raw && raw === basename(raw) && existsSync(resolve(cwd, `.env.${raw}`))) {
32
+ return `--env: ${choice.path} does not exist. Did you mean --env .env.${raw}? The flag takes a path, not an environment name.`;
23
33
  }
24
- return { path: resolve(cwd, value), explicit: true };
34
+ return `--env: ${choice.path} does not exist.`;
25
35
  }
26
36
  function loadEnvFile(argv, options = {}) {
27
37
  const { cwd = process.cwd(), warn = (message) => console.warn(message) } = options;
@@ -29,22 +39,22 @@ function loadEnvFile(argv, options = {}) {
29
39
  if (nodeFlag) {
30
40
  warn(`Note: ${nodeFlag} is a Node flag and Node has already applied it. The devkit's own flag is --env <path>.`);
31
41
  }
32
- const { path, explicit } = resolveEnvFile(argv, cwd);
33
- if (!path) {
42
+ const choice = resolveEnvFile(argv, cwd);
43
+ if (!choice.path) {
34
44
  return null;
35
45
  }
36
- if (!existsSync(path)) {
37
- if (explicit) {
38
- throw new Error(`--env: ${path} does not exist.`);
46
+ if (!existsSync(choice.path)) {
47
+ if (choice.explicit) {
48
+ throw new Error(missingFileMessage(choice, cwd));
39
49
  }
40
50
  return null;
41
51
  }
42
52
  if (typeof process.loadEnvFile !== "function") {
43
- warn(`Ignoring ${path}: env-file support needs Node >= ${ENV_FILE_MIN_NODE} (running ${process.version}).`);
53
+ warn(`Ignoring ${choice.path}: env-file support needs Node >= ${ENV_FILE_MIN_NODE} (running ${process.version}).`);
44
54
  return null;
45
55
  }
46
- process.loadEnvFile(path);
47
- return path;
56
+ process.loadEnvFile(choice.path);
57
+ return choice.path;
48
58
  }
49
59
 
50
60
  // src/errors.ts
@@ -60,9 +70,31 @@ var DevApiError = class extends Error {
60
70
  };
61
71
 
62
72
  // src/loader.ts
73
+ import { existsSync as existsSync2, readFileSync } from "fs";
74
+ import { dirname, join } from "path";
63
75
  import { pathToFileURL } from "url";
64
76
  import { buildManifest } from "@revenexx/integrations-node-sdk";
65
- function resolveExports(mod) {
77
+ var UNKNOWN_PACKAGE = { name: "unknown", version: "0.0.0", label: "Local package" };
78
+ function readPackageInfo(entryPath) {
79
+ let dir = dirname(entryPath);
80
+ for (let up = 0; up < 6; up += 1) {
81
+ const candidate = join(dir, "package.json");
82
+ if (existsSync2(candidate)) {
83
+ try {
84
+ const pkg = JSON.parse(readFileSync(candidate, "utf-8"));
85
+ if (pkg.name) {
86
+ return { name: pkg.name, version: pkg.version ?? "0.0.0", label: pkg.name.split("/").pop() ?? pkg.name };
87
+ }
88
+ } catch {
89
+ }
90
+ }
91
+ const parent = dirname(dir);
92
+ if (parent === dir) break;
93
+ dir = parent;
94
+ }
95
+ return UNKNOWN_PACKAGE;
96
+ }
97
+ function resolveExports(mod, packageInfo = UNKNOWN_PACKAGE) {
66
98
  if (!Array.isArray(mod.NODES)) {
67
99
  throw new Error("Package entry does not export a `NODES` array. Export `NODES: INode[]`.");
68
100
  }
@@ -79,7 +111,9 @@ function resolveExports(mod) {
79
111
  nodes,
80
112
  credentials,
81
113
  templates,
82
- manifest: buildManifest(nodes, credentials, templates)
114
+ manifest: buildManifest(nodes, credentials, templates),
115
+ packageInfo,
116
+ loadedAt: (/* @__PURE__ */ new Date()).toISOString()
83
117
  };
84
118
  }
85
119
  var tsxRegistered = false;
@@ -91,6 +125,10 @@ async function ensureTsxRegistered() {
91
125
  register();
92
126
  tsxRegistered = true;
93
127
  }
128
+ var RELOADABLE_SOURCE = /\.(?:[cm]?[jt]sx?|json)$/;
129
+ function isReloadableSource(file) {
130
+ return RELOADABLE_SOURCE.test(file);
131
+ }
94
132
  async function importFresh(entryPath) {
95
133
  if (/\.[cm]?tsx?$/.test(entryPath)) {
96
134
  await ensureTsxRegistered();
@@ -99,17 +137,19 @@ async function importFresh(entryPath) {
99
137
  return await import(href);
100
138
  }
101
139
  async function loadPackageFromEntry(entryPath) {
102
- return resolveExports(await importFresh(entryPath));
140
+ return resolveExports(await importFresh(entryPath), readPackageInfo(entryPath));
103
141
  }
104
142
 
105
143
  // src/persistence.ts
106
- import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
107
- import { dirname, resolve as resolve2 } from "path";
144
+ import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
145
+ import { dirname as dirname2, resolve as resolve2 } from "path";
108
146
 
109
147
  // src/store.ts
110
148
  import { randomUUID } from "crypto";
111
149
  var DEV_TENANT_ID = "dev-tenant";
112
- var STORE_SCHEMA_VERSION = 1;
150
+ var BLOB_DEFINITION_VERSION = "v0-draft";
151
+ var EXECUTION_MODES = ["async_only", "sync_only", "caller_decides"];
152
+ var STORE_SCHEMA_VERSION = 2;
113
153
  function now() {
114
154
  return (/* @__PURE__ */ new Date()).toISOString();
115
155
  }
@@ -152,6 +192,9 @@ var DevStore = class {
152
192
  status: input.status ?? "active",
153
193
  config: input.config,
154
194
  durableCreds: input.durableCreds ?? null,
195
+ lastTestAt: null,
196
+ lastTestOk: null,
197
+ lastTestMessage: null,
155
198
  createdAt: ts,
156
199
  updatedAt: ts
157
200
  };
@@ -180,6 +223,21 @@ var DevStore = class {
180
223
  this.touch();
181
224
  return record;
182
225
  }
226
+ /**
227
+ * Records the outcome of a credential test. The service persists this on the
228
+ * record and reports it back from `POST /credentials/{id}/test`.
229
+ */
230
+ recordCredentialTest(id, result) {
231
+ const record = this.credentials.get(id);
232
+ if (!record) {
233
+ return void 0;
234
+ }
235
+ record.lastTestAt = now();
236
+ record.lastTestOk = result.ok;
237
+ record.lastTestMessage = result.message ?? null;
238
+ this.touch();
239
+ return record;
240
+ }
183
241
  deleteCredential(id) {
184
242
  const deleted = this.credentials.delete(id);
185
243
  if (deleted) {
@@ -226,7 +284,12 @@ var DevStore = class {
226
284
  const record = {
227
285
  id: this.nextWorkflowId++,
228
286
  name: input.name,
229
- definition: input.definition,
287
+ description: input.description ?? null,
288
+ blob: input.blob,
289
+ blobDefinitionVersion: input.blobDefinitionVersion ?? BLOB_DEFINITION_VERSION,
290
+ active: input.active ?? true,
291
+ executionMode: input.executionMode ?? EXECUTION_MODES[0],
292
+ revision: 1,
230
293
  buildStatus: "ready",
231
294
  createdAt: ts,
232
295
  updatedAt: ts
@@ -240,7 +303,8 @@ var DevStore = class {
240
303
  if (!record) {
241
304
  return void 0;
242
305
  }
243
- Object.assign(record, patch, { updatedAt: now() });
306
+ const defined = Object.fromEntries(Object.entries(patch).filter(([, v]) => v !== void 0));
307
+ Object.assign(record, defined, { revision: record.revision + 1, updatedAt: now() });
244
308
  this.touch();
245
309
  return record;
246
310
  }
@@ -381,16 +445,23 @@ function applySeeds(store, seeds, env = process.env) {
381
445
  });
382
446
  }
383
447
  for (const workflow of seeds.workflows ?? []) {
384
- store.createWorkflow(interpolateEnv(workflow, env));
448
+ const resolved = interpolateEnv(workflow, env);
449
+ store.createWorkflow({
450
+ name: resolved.name,
451
+ blob: resolved.blob ?? resolved.definition ?? {},
452
+ description: resolved.description,
453
+ active: resolved.active,
454
+ executionMode: resolved.executionMode
455
+ });
385
456
  }
386
457
  }
387
458
  function loadState(file, log = console.warn) {
388
- if (!existsSync2(file)) {
459
+ if (!existsSync3(file)) {
389
460
  return null;
390
461
  }
391
462
  let parsed;
392
463
  try {
393
- parsed = JSON.parse(readFileSync(file, "utf-8"));
464
+ parsed = JSON.parse(readFileSync2(file, "utf-8"));
394
465
  } catch {
395
466
  log(`Ignoring ${file}: not valid JSON.`);
396
467
  return null;
@@ -402,14 +473,14 @@ function loadState(file, log = console.warn) {
402
473
  return parsed;
403
474
  }
404
475
  function saveState(file, snapshot) {
405
- mkdirSync(dirname(file), { recursive: true });
476
+ mkdirSync(dirname2(file), { recursive: true });
406
477
  writeFileSync(file, JSON.stringify(snapshot, null, 2), "utf-8");
407
478
  }
408
479
  var SEED_ENTRY_CANDIDATES = ["index.ts", "index.mjs", "index.js", "seeds.ts", "seeds.js"];
409
480
  async function loadSeedsFromDir(dir) {
410
481
  for (const candidate of SEED_ENTRY_CANDIDATES) {
411
482
  const path = resolve2(dir, candidate);
412
- if (existsSync2(path)) {
483
+ if (existsSync3(path)) {
413
484
  const mod = await importFresh(path);
414
485
  return mod.default ?? mod.seeds ?? {};
415
486
  }
@@ -677,6 +748,56 @@ async function validateNodeConfig(loaded, store, input) {
677
748
  }
678
749
  return { valid: Object.keys(errors).length === 0, errors };
679
750
  }
751
+ var MIN_TIMEOUT_MS = 1e3;
752
+ var DEFAULT_TIMEOUT_MS = 3e4;
753
+ var ExecuteTimeout = class extends Error {
754
+ };
755
+ async function executeNodeTest(loaded, store, input) {
756
+ const node = findNode(loaded, input.slug, input.version);
757
+ const logs = [];
758
+ const record = (level) => (message, meta) => {
759
+ logs.push(meta === void 0 ? { level, message } : { level, message, meta });
760
+ };
761
+ const timeoutMs = Math.max(MIN_TIMEOUT_MS, input.timeoutMs ?? DEFAULT_TIMEOUT_MS);
762
+ const controller = new AbortController();
763
+ let timer;
764
+ const expired = new Promise((_resolve, reject) => {
765
+ timer = setTimeout(() => {
766
+ controller.abort();
767
+ reject(new ExecuteTimeout());
768
+ }, timeoutMs);
769
+ });
770
+ const ctx = {
771
+ signal: controller.signal,
772
+ logger: { info: record("info"), warn: record("warn"), error: record("error") },
773
+ secrets: {
774
+ async get(key) {
775
+ const secret = store.getSecret(key);
776
+ if (!secret) {
777
+ throw new DevApiError(404, `Secret '${key}' not found.`);
778
+ }
779
+ return secret.value;
780
+ }
781
+ },
782
+ credentials: {
783
+ async get(id) {
784
+ return (await resolveCredentialInstance(loaded, store, id)).credentials;
785
+ }
786
+ }
787
+ };
788
+ try {
789
+ const result = await Promise.race([node.execute(ctx, { ...input.config, ...input.inputs }), expired]);
790
+ return { outputs: result.outputs ?? {}, branch: result.branch ?? null, logs };
791
+ } catch (err) {
792
+ if (err instanceof DevApiError) {
793
+ throw err;
794
+ }
795
+ const reason = err instanceof ExecuteTimeout || controller.signal.aborted ? `timed out after ${timeoutMs} ms` : err.message;
796
+ throw new DevApiError(502, `Node execution failed: ${reason}`, { logs: logs.map((l) => `${l.level}: ${l.message}`) });
797
+ } finally {
798
+ clearTimeout(timer);
799
+ }
800
+ }
680
801
  async function testCredentialConfig(loaded, store, typeSlug, config) {
681
802
  const cred = findCredential(loaded, typeSlug);
682
803
  return cred.test(credentialContext(store), config);
@@ -718,16 +839,22 @@ async function exchangeOAuthCode(loaded, store, credentialId, params) {
718
839
  import http from "http";
719
840
 
720
841
  // src/http.ts
842
+ var API_VERSION = "1.0.0";
843
+ var BASE_HEADERS = {
844
+ "X-Api-Version": API_VERSION,
845
+ "Access-Control-Allow-Origin": "*",
846
+ "Access-Control-Allow-Headers": "*",
847
+ "Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
848
+ };
721
849
  function sendJson(res, status, body) {
722
850
  const payload = JSON.stringify(body);
723
- res.writeHead(status, {
724
- "Content-Type": "application/json",
725
- "Access-Control-Allow-Origin": "*",
726
- "Access-Control-Allow-Headers": "*",
727
- "Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
728
- });
851
+ res.writeHead(status, { "Content-Type": "application/json", ...BASE_HEADERS });
729
852
  res.end(payload);
730
853
  }
854
+ function sendNoContent(res) {
855
+ res.writeHead(204, BASE_HEADERS);
856
+ res.end();
857
+ }
731
858
  function sendError(res, err) {
732
859
  if (err instanceof DevApiError) {
733
860
  sendJson(res, err.status, err.errors ? { message: err.message, errors: err.errors } : { message: err.message });
@@ -765,20 +892,24 @@ function hasDynamicSchema(desc) {
765
892
  function hasDynamicOutputs(desc) {
766
893
  return (desc.outputs ?? []).some((o) => o.resolveOutputs === true);
767
894
  }
768
- function nodeToApi(desc) {
895
+ function nodeToApi(desc, ctx) {
769
896
  const [namespace] = desc.slug.split(":");
770
897
  return {
771
898
  name: desc.name,
772
899
  namespace: namespace ?? null,
773
900
  slug: desc.slug,
774
901
  version: desc.version,
902
+ // The contract declares `package` and both timestamps as present. Nodes here
903
+ // come from the developer's working tree, so the package identity is read from
904
+ // their package.json and the timestamps are when the mock loaded the entry.
905
+ package: ctx?.packageInfo ?? null,
775
906
  manifest_version: MANIFEST_VERSION,
776
907
  manifest: desc,
777
908
  has_dynamic_options: hasDynamicOptions(desc),
778
909
  has_dynamic_schema: hasDynamicSchema(desc),
779
910
  has_dynamic_outputs: hasDynamicOutputs(desc),
780
- created_at: null,
781
- updated_at: null
911
+ created_at: ctx?.loadedAt ?? null,
912
+ updated_at: ctx?.loadedAt ?? null
782
913
  };
783
914
  }
784
915
  function credentialTypeToApi(desc) {
@@ -788,6 +919,7 @@ function credentialTypeToApi(desc) {
788
919
  name: desc.name,
789
920
  description: desc.description ?? null,
790
921
  icon: desc.icon ?? null,
922
+ images: desc.images ?? [],
791
923
  auth_kind: desc.authKind,
792
924
  fields: desc.fields
793
925
  };
@@ -823,7 +955,16 @@ function workflowToApi(record) {
823
955
  return {
824
956
  id: record.id,
825
957
  name: record.name,
826
- definition: record.definition,
958
+ description: record.description,
959
+ blob_definition_version: record.blobDefinitionVersion,
960
+ blob: record.blob,
961
+ active: record.active,
962
+ execution_mode: record.executionMode,
963
+ revision: record.revision,
964
+ // The service reports blob-validation warnings here. The mock's validation is
965
+ // schema-light (see the fidelity caveats), so it never has any — but the field
966
+ // is part of the contract and clients may read it.
967
+ warnings: [],
827
968
  build_status: record.buildStatus,
828
969
  created_at: record.createdAt,
829
970
  updated_at: record.updatedAt
@@ -852,6 +993,7 @@ function templateSummaryToApi(t) {
852
993
  shortDescription: t.shortDescription ?? null,
853
994
  description: t.description ?? null,
854
995
  icon: t.icon ?? null,
996
+ images: t.images ?? [],
855
997
  industries: t.industries ?? [],
856
998
  vendors: t.vendors ?? [],
857
999
  triggerTypes: (t.triggers ?? []).map((tr) => tr.type)
@@ -860,9 +1002,13 @@ function templateSummaryToApi(t) {
860
1002
  function templateFullToApi(t) {
861
1003
  return {
862
1004
  ...templateSummaryToApi(t),
863
- blobVersion: t.blobVersion,
1005
+ // snake_case per the contract, even though the surrounding template fields are
1006
+ // camelCase and the SDK's own field is `blobVersion`.
1007
+ blob_version: t.blobVersion,
864
1008
  definition: t.definition,
865
- triggers: t.triggers ?? []
1009
+ // `config` is optional in the SDK (a manual trigger has none) but declared in
1010
+ // the contract, so normalise it to an object rather than omitting it.
1011
+ triggers: (t.triggers ?? []).map((tr) => ({ ...tr, config: tr.config ?? {} }))
866
1012
  };
867
1013
  }
868
1014
 
@@ -893,13 +1039,15 @@ async function handle(req, res, deps) {
893
1039
  switch (seg[0]) {
894
1040
  case void 0:
895
1041
  case "health":
1042
+ // The service's health route is `/up` (Laravel's default); `/health` is kept
1043
+ // because the devkit has always answered there.
1044
+ case "up":
896
1045
  return void sendJson(res, 200, { status: "ok" });
897
1046
  case "me":
898
1047
  return void sendJson(res, 200, {
899
- id: "dev-user",
900
- name: "Dev User",
901
- email: "dev@revenexx.test",
902
- tenant_id: DEV_TENANT_ID
1048
+ user: { id: 1, zitadel_id: "dev-user", email: "dev@revenexx.test", name: "Dev User" },
1049
+ context: { tenant_id: DEV_TENANT_ID, active_plane: "public", roles: ["admin", "user"] },
1050
+ claims: { iss: "https://id.revenexx.test", sub: "dev-user", aud: ["devkit"] }
903
1051
  });
904
1052
  case "schemas":
905
1053
  return handleSchemas(res, deps, seg);
@@ -926,15 +1074,22 @@ function handleSchemas(res, deps, seg) {
926
1074
  throw new DevApiError(404, "Schema domain required.");
927
1075
  }
928
1076
  const schemas = deps.schemas ?? {};
929
- const schema = version && schemas[`${domain}/${version}`] || schemas[domain];
1077
+ if (!version) {
1078
+ const versions = Object.keys(schemas).filter((key) => key.startsWith(`${domain}/`)).map((key) => key.slice(domain.length + 1)).sort();
1079
+ if (versions.length === 0 && !schemas[domain]) {
1080
+ throw new DevApiError(404, `Unknown schema domain '${domain}'. Vendor it into assets/schemas.`);
1081
+ }
1082
+ return void sendJson(res, 200, { domain, versions });
1083
+ }
1084
+ const schema = schemas[`${domain}/${version}`];
930
1085
  if (!schema) {
931
- throw new DevApiError(404, `No schema for '${domain}${version ? `/${version}` : ""}'. Vendor it into assets/schemas.`);
1086
+ throw new DevApiError(404, `Unknown schema version '${domain}/${version}'. Vendor it into assets/schemas.`);
932
1087
  }
933
- sendJson(res, 200, schema);
1088
+ sendJson(res, 200, { domain, version, schema });
934
1089
  }
935
1090
  async function handleNodes(req, res, method, loaded, store, seg) {
936
1091
  if (seg.length === 1 && method === "GET") {
937
- return void sendJson(res, 200, { data: loaded.manifest.nodes.map(nodeToApi) });
1092
+ return void sendJson(res, 200, { data: loaded.manifest.nodes.map((n) => nodeToApi(n, nodeApiContext(loaded))) });
938
1093
  }
939
1094
  const slug = seg[1];
940
1095
  if (!slug) {
@@ -975,15 +1130,36 @@ async function handleNodes(req, res, method, loaded, store, seg) {
975
1130
  });
976
1131
  return void sendJson(res, 200, result);
977
1132
  }
1133
+ if (seg[3] === "execute:test" && method === "POST") {
1134
+ const body = await readJson(req);
1135
+ const result = await executeNodeTest(loaded, store, {
1136
+ slug,
1137
+ version,
1138
+ config: body.config ?? {},
1139
+ inputs: body.inputs ?? {},
1140
+ timeoutMs: body.timeout_ms
1141
+ });
1142
+ return void sendJson(res, 200, result);
1143
+ }
978
1144
  if (seg.length === 3 && method === "GET") {
979
- const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
980
- if (!node) {
981
- throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
982
- }
983
- return void sendJson(res, 200, nodeToApi(node));
1145
+ return void sendJson(res, 200, nodeToApi(findManifestNode(loaded, slug, version), nodeApiContext(loaded)));
1146
+ }
1147
+ if (seg.length === 3 && method === "DELETE") {
1148
+ findManifestNode(loaded, slug, version);
1149
+ return void sendNoContent(res);
984
1150
  }
985
1151
  throw new DevApiError(404, `No route for nodes/${seg.slice(1).join("/")}`);
986
1152
  }
1153
+ function nodeApiContext(loaded) {
1154
+ return { packageInfo: loaded.packageInfo, loadedAt: loaded.loadedAt };
1155
+ }
1156
+ function findManifestNode(loaded, slug, version) {
1157
+ const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
1158
+ if (!node) {
1159
+ throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
1160
+ }
1161
+ return node;
1162
+ }
987
1163
  function handleCredentialTypes(res, loaded, seg) {
988
1164
  if (seg.length === 1) {
989
1165
  return void sendJson(res, 200, {
@@ -1047,7 +1223,13 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1047
1223
  }
1048
1224
  if (seg[2] === "test" && method === "POST") {
1049
1225
  const result = await testCredentialInstance(loaded, store, id);
1050
- return void sendJson(res, 200, result);
1226
+ const record = store.recordCredentialTest(id, { ok: result.ok, message: result.message ?? null });
1227
+ return void sendJson(res, 200, {
1228
+ ok: result.ok,
1229
+ message: result.message ?? null,
1230
+ last_test_at: record?.lastTestAt ?? null,
1231
+ last_test_ok: record?.lastTestOk ?? result.ok
1232
+ });
1051
1233
  }
1052
1234
  if (seg[2] === "oauth" && seg[3] === "authorize-url" && method === "POST") {
1053
1235
  const redirectUri = "http://localhost/api/v1/credentials/oauth/callback";
@@ -1072,7 +1254,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1072
1254
  }
1073
1255
  if (method === "DELETE") {
1074
1256
  store.deleteCredential(id);
1075
- return void sendJson(res, 200, { deleted: true });
1257
+ return void sendNoContent(res);
1076
1258
  }
1077
1259
  }
1078
1260
  throw new DevApiError(404, `No route for credentials/${seg.slice(1).join("/")}`);
@@ -1080,7 +1262,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1080
1262
  async function handleSecrets(req, res, method, store, seg) {
1081
1263
  if (seg.length === 1) {
1082
1264
  if (method === "GET") {
1083
- return void sendJson(res, 200, { data: store.listSecrets().map(secretToApi) });
1265
+ return void sendJson(res, 200, { keys: store.listSecrets().map((s) => s.key) });
1084
1266
  }
1085
1267
  if (method === "POST") {
1086
1268
  const body = await readJson(req);
@@ -1102,7 +1284,7 @@ async function handleSecrets(req, res, method, store, seg) {
1102
1284
  }
1103
1285
  if (method === "DELETE") {
1104
1286
  store.deleteSecret(key);
1105
- return void sendJson(res, 200, { deleted: true });
1287
+ return void sendNoContent(res);
1106
1288
  }
1107
1289
  }
1108
1290
  throw new DevApiError(404, `No route for secrets/${seg.slice(1).join("/")}`);
@@ -1118,16 +1300,17 @@ async function handleTemplates(req, res, method, loaded, store, seg) {
1118
1300
  throw new DevApiError(404, `Template '${slug}' not found.`);
1119
1301
  }
1120
1302
  if (seg.length === 2 && method === "GET") {
1121
- return void sendJson(res, 200, templateFullToApi(template));
1303
+ return void sendJson(res, 200, { data: templateFullToApi(template) });
1122
1304
  }
1123
1305
  if (seg[2] === "requirements" && method === "GET") {
1124
- return void sendJson(res, 200, { data: { credentials: [], secrets: [] } });
1306
+ return void sendJson(res, 200, { data: { credentialTypes: [], secrets: [] } });
1125
1307
  }
1126
1308
  if (seg[2] === "instantiate" && method === "POST") {
1127
1309
  const body = await readJson(req);
1128
1310
  const workflow = store.createWorkflow({
1129
1311
  name: body.name ?? String(template.name),
1130
- definition: template.definition
1312
+ blob: template.definition,
1313
+ blobDefinitionVersion: template.blobVersion
1131
1314
  });
1132
1315
  for (const trigger of template.triggers ?? []) {
1133
1316
  store.createTrigger({
@@ -1152,7 +1335,11 @@ async function handleWorkflows(req, res, method, store, seg) {
1152
1335
  const body = await readJson(req);
1153
1336
  const workflow = store.createWorkflow({
1154
1337
  name: body.name ?? "Untitled workflow",
1155
- definition: body.definition ?? {}
1338
+ blob: body.blob ?? {},
1339
+ blobDefinitionVersion: body.blob_definition_version,
1340
+ description: body.description,
1341
+ active: body.active,
1342
+ executionMode: body.execution_mode
1156
1343
  });
1157
1344
  return void sendJson(res, 201, workflowToApi(workflow));
1158
1345
  }
@@ -1193,7 +1380,7 @@ async function handleWorkflows(req, res, method, store, seg) {
1193
1380
  }
1194
1381
  if (triggerId && method === "DELETE") {
1195
1382
  store.deleteTrigger(triggerId);
1196
- return void sendJson(res, 200, { deleted: true });
1383
+ return void sendNoContent(res);
1197
1384
  }
1198
1385
  }
1199
1386
  if (seg.length === 2) {
@@ -1206,7 +1393,14 @@ async function handleWorkflows(req, res, method, store, seg) {
1206
1393
  }
1207
1394
  if (method === "PUT") {
1208
1395
  const body = await readJson(req);
1209
- const updated = store.updateWorkflow(id, { name: body.name, definition: body.definition });
1396
+ const updated = store.updateWorkflow(id, {
1397
+ name: body.name,
1398
+ blob: body.blob,
1399
+ blobDefinitionVersion: body.blob_definition_version,
1400
+ description: body.description,
1401
+ active: body.active,
1402
+ executionMode: body.execution_mode
1403
+ });
1210
1404
  if (!updated) {
1211
1405
  throw new DevApiError(404, `Workflow '${id}' not found.`);
1212
1406
  }
@@ -1214,7 +1408,7 @@ async function handleWorkflows(req, res, method, store, seg) {
1214
1408
  }
1215
1409
  if (method === "DELETE") {
1216
1410
  store.deleteWorkflow(id);
1217
- return void sendJson(res, 200, { deleted: true });
1411
+ return void sendNoContent(res);
1218
1412
  }
1219
1413
  }
1220
1414
  if ((seg[2] === "credentials" || seg[2] === "credential-types") && method === "GET") {
@@ -1225,7 +1419,7 @@ async function handleWorkflows(req, res, method, store, seg) {
1225
1419
 
1226
1420
  // src/index.ts
1227
1421
  var manifestUrl = new URL("../package.json", import.meta.url);
1228
- var DEVKIT_VERSION = JSON.parse(readFileSync2(manifestUrl, "utf8")).version;
1422
+ var DEVKIT_VERSION = JSON.parse(readFileSync3(manifestUrl, "utf8")).version;
1229
1423
 
1230
1424
  export {
1231
1425
  ENV_FILE_MIN_NODE,
@@ -1235,6 +1429,7 @@ export {
1235
1429
  DevApiError,
1236
1430
  resolveExports,
1237
1431
  ensureTsxRegistered,
1432
+ isReloadableSource,
1238
1433
  importFresh,
1239
1434
  loadPackageFromEntry,
1240
1435
  DEV_TENANT_ID,
@@ -1260,4 +1455,4 @@ export {
1260
1455
  createDevServer,
1261
1456
  DEVKIT_VERSION
1262
1457
  };
1263
- //# sourceMappingURL=chunk-UBYGZFB7.js.map
1458
+ //# sourceMappingURL=chunk-PS3HCKE7.js.map