@revenexx/integrations-node-devkit 0.2.2 → 0.4.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 CHANGED
@@ -57,10 +57,17 @@ host app. The devkit scaffolds and runs that host for you:
57
57
  npm run preview
58
58
  ```
59
59
 
60
- This (1) scaffolds a minimal Nuxt host into `.revenexx-dev/preview/` (gitignored)
61
- on first run, (2) `npm install`s it (heavy first time — pulls Nuxt + the studio
62
- packages), (3) starts the mock API, and (4) runs `nuxt dev` wired to the mock.
63
- Open **http://localhost:3000/integrations**.
60
+ This (1) copies the host into a shared cache directory, (2) `npm install`s it there
61
+ (heavy the first time — pulls Nuxt + the studio packages), (3) starts the mock API,
62
+ and (4) runs `nuxt dev` wired to the mock. Open
63
+ **http://localhost:3000/integrations**.
64
+
65
+ **The host does not go into your repo.** It is copied to
66
+ `${XDG_CACHE_HOME:-~/.cache}/revenexx/devkit-preview/<devkit-version>/`, so every
67
+ one of your node packages shares a single dependency install, and a devkit upgrade
68
+ can never leave you running a stale host. Your repo only gets
69
+ `.revenexx-dev/state.json`. If you still have a `.revenexx-dev/preview/` from an
70
+ older devkit, it is unused and can be deleted.
64
71
 
65
72
  No auth shim is needed: `@revenexx/studio-shared`'s standalone
66
73
  `usePlatformAuth`/`usePlatformTenant` read a dev token/tenant from
@@ -68,15 +75,24 @@ No auth shim is needed: `@revenexx/studio-shared`'s standalone
68
75
  mock ignores the values). `runtimeConfig.public.integrationsApi` is pointed at
69
76
  the mock automatically.
70
77
 
71
- - `integrations-devkit init-preview` — only scaffold the host (then edit it; it's yours).
72
- - `integrations-devkit preview --dir <path> --force` — custom dir / re-scaffold.
78
+ The managed copy is a disposable artifact — don't edit it, it is replaced on the
79
+ next version bump. To change the host, take a copy that is yours:
80
+
81
+ - `integrations-devkit init-preview --dir ./my-preview` — an **unmanaged** copy,
82
+ never touched by devkit upgrades.
83
+ - `integrations-devkit preview --dir ./my-preview` — run that copy instead.
73
84
 
74
85
  > **Scope:** the preview targets the **slimmed** studio build — node listing +
75
- > credential/template management + **config-field resolving**. `studio-integrations`
76
- > 0.1.4 still ships the workflow editor and renders `field.options` statically;
77
- > config-field resolving needs the UI to `POST /nodes/{slug}/{version}/config:resolve`
78
- > (the mock already serves it). The Temporal parts (run history, `…/runs/*`) are
79
- > intentionally not mocked.
86
+ > credential/template management + **config-field resolving** (the UI
87
+ > `POST`s to `/nodes/{slug}/{version}/config:resolve`, which the mock serves).
88
+ > The **Workflows** surface is hidden until phase 2, because workflow execution is
89
+ > not mocked; the Temporal parts (run history, `…/runs/*`) are intentionally absent.
90
+
91
+ The mock is checked against the service's own OpenAPI contract — see
92
+ [docs/architecture.md](docs/architecture.md#staying-in-step-with-the-real-api).
93
+ One caveat to know up front: `POST /nodes/{slug}/{version}/config:validate` is a
94
+ **devkit-only** endpoint used by the preview's node page. It does not exist in the
95
+ real API.
80
96
 
81
97
  Pass `--ui <dir>` to `integrations-devkit` if you instead have a prebuilt static SPA.
82
98
 
@@ -88,10 +104,13 @@ Pass `--ui <dir>` to `integrations-devkit` if you instead have a prebuilt static
88
104
  | `--seed <dir>` | `dev/seeds` | Committed seed directory |
89
105
  | `--state <file>` | `.revenexx-dev/state.json` | Session overlay file |
90
106
  | `--no-persist` | off | In-memory only; don't write the overlay |
91
- | `--port <n>` | `$PORT` or `3555` | Listen port |
107
+ | `--port <n>` | `$PORT` or `3555` | Listen port. The default relocates when taken; an explicit one is reported as a conflict |
92
108
  | `--ui <dir>` | resolve UI package | Static UI build to serve |
93
109
  | `--no-ui` | off | Run API-only |
94
110
  | `--open` | off | Open the preview in a browser |
111
+ | `--dir <path>` | managed cache | Use this preview-host dir instead (unmanaged) |
112
+ | `--force` | off | Re-copy the host even if the target looks complete |
113
+ | `--parallel` | off | Run a second `preview` alongside one already running |
95
114
  | `reset` (subcommand) | | Delete the session overlay |
96
115
 
97
116
  ## Seeds + persistence (layered)
@@ -176,5 +195,9 @@ This is a faithful **dev** stand-in, not the production service:
176
195
  reproduced.
177
196
  - Workflow-blob validation is light and schema-based; the production service
178
197
  does deeper cross-validation on save.
179
- - Workflow **run execution** is not included (v1).
180
- # devkit
198
+ - Workflow **run execution** is not included (v1), so the Workflows surface is
199
+ hidden in the preview.
200
+ - `assets/schemas/` is still empty, so `GET /schemas/{domain}` 404s and the UI's
201
+ client-side schema validation is inactive.
202
+ - `POST /nodes/{slug}/{version}/config:validate` exists only here, not in the real
203
+ API.
@@ -1,5 +1,5 @@
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";
@@ -68,11 +68,39 @@ var DevApiError = class extends Error {
68
68
  status;
69
69
  errors;
70
70
  };
71
+ var CliError = class extends Error {
72
+ constructor(message) {
73
+ super(message);
74
+ this.name = "CliError";
75
+ }
76
+ };
71
77
 
72
78
  // src/loader.ts
79
+ import { existsSync as existsSync2, readFileSync } from "fs";
80
+ import { dirname, join } from "path";
73
81
  import { pathToFileURL } from "url";
74
82
  import { buildManifest } from "@revenexx/integrations-node-sdk";
75
- function resolveExports(mod) {
83
+ var UNKNOWN_PACKAGE = { name: "unknown", version: "0.0.0", label: "Local package" };
84
+ function readPackageInfo(entryPath) {
85
+ let dir = dirname(entryPath);
86
+ for (let up = 0; up < 6; up += 1) {
87
+ const candidate = join(dir, "package.json");
88
+ if (existsSync2(candidate)) {
89
+ try {
90
+ const pkg = JSON.parse(readFileSync(candidate, "utf-8"));
91
+ if (pkg.name) {
92
+ return { name: pkg.name, version: pkg.version ?? "0.0.0", label: pkg.name.split("/").pop() ?? pkg.name };
93
+ }
94
+ } catch {
95
+ }
96
+ }
97
+ const parent = dirname(dir);
98
+ if (parent === dir) break;
99
+ dir = parent;
100
+ }
101
+ return UNKNOWN_PACKAGE;
102
+ }
103
+ function resolveExports(mod, packageInfo = UNKNOWN_PACKAGE) {
76
104
  if (!Array.isArray(mod.NODES)) {
77
105
  throw new Error("Package entry does not export a `NODES` array. Export `NODES: INode[]`.");
78
106
  }
@@ -89,7 +117,9 @@ function resolveExports(mod) {
89
117
  nodes,
90
118
  credentials,
91
119
  templates,
92
- manifest: buildManifest(nodes, credentials, templates)
120
+ manifest: buildManifest(nodes, credentials, templates),
121
+ packageInfo,
122
+ loadedAt: (/* @__PURE__ */ new Date()).toISOString()
93
123
  };
94
124
  }
95
125
  var tsxRegistered = false;
@@ -101,6 +131,10 @@ async function ensureTsxRegistered() {
101
131
  register();
102
132
  tsxRegistered = true;
103
133
  }
134
+ var RELOADABLE_SOURCE = /\.(?:[cm]?[jt]sx?|json)$/;
135
+ function isReloadableSource(file) {
136
+ return RELOADABLE_SOURCE.test(file);
137
+ }
104
138
  async function importFresh(entryPath) {
105
139
  if (/\.[cm]?tsx?$/.test(entryPath)) {
106
140
  await ensureTsxRegistered();
@@ -109,17 +143,19 @@ async function importFresh(entryPath) {
109
143
  return await import(href);
110
144
  }
111
145
  async function loadPackageFromEntry(entryPath) {
112
- return resolveExports(await importFresh(entryPath));
146
+ return resolveExports(await importFresh(entryPath), readPackageInfo(entryPath));
113
147
  }
114
148
 
115
149
  // src/persistence.ts
116
- import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
117
- import { dirname, resolve as resolve2 } from "path";
150
+ import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
151
+ import { dirname as dirname2, resolve as resolve2 } from "path";
118
152
 
119
153
  // src/store.ts
120
154
  import { randomUUID } from "crypto";
121
155
  var DEV_TENANT_ID = "dev-tenant";
122
- var STORE_SCHEMA_VERSION = 1;
156
+ var BLOB_DEFINITION_VERSION = "v0-draft";
157
+ var EXECUTION_MODES = ["async_only", "sync_only", "caller_decides"];
158
+ var STORE_SCHEMA_VERSION = 2;
123
159
  function now() {
124
160
  return (/* @__PURE__ */ new Date()).toISOString();
125
161
  }
@@ -162,6 +198,9 @@ var DevStore = class {
162
198
  status: input.status ?? "active",
163
199
  config: input.config,
164
200
  durableCreds: input.durableCreds ?? null,
201
+ lastTestAt: null,
202
+ lastTestOk: null,
203
+ lastTestMessage: null,
165
204
  createdAt: ts,
166
205
  updatedAt: ts
167
206
  };
@@ -190,6 +229,21 @@ var DevStore = class {
190
229
  this.touch();
191
230
  return record;
192
231
  }
232
+ /**
233
+ * Records the outcome of a credential test. The service persists this on the
234
+ * record and reports it back from `POST /credentials/{id}/test`.
235
+ */
236
+ recordCredentialTest(id, result) {
237
+ const record = this.credentials.get(id);
238
+ if (!record) {
239
+ return void 0;
240
+ }
241
+ record.lastTestAt = now();
242
+ record.lastTestOk = result.ok;
243
+ record.lastTestMessage = result.message ?? null;
244
+ this.touch();
245
+ return record;
246
+ }
193
247
  deleteCredential(id) {
194
248
  const deleted = this.credentials.delete(id);
195
249
  if (deleted) {
@@ -236,7 +290,12 @@ var DevStore = class {
236
290
  const record = {
237
291
  id: this.nextWorkflowId++,
238
292
  name: input.name,
239
- definition: input.definition,
293
+ description: input.description ?? null,
294
+ blob: input.blob,
295
+ blobDefinitionVersion: input.blobDefinitionVersion ?? BLOB_DEFINITION_VERSION,
296
+ active: input.active ?? true,
297
+ executionMode: input.executionMode ?? EXECUTION_MODES[0],
298
+ revision: 1,
240
299
  buildStatus: "ready",
241
300
  createdAt: ts,
242
301
  updatedAt: ts
@@ -250,7 +309,8 @@ var DevStore = class {
250
309
  if (!record) {
251
310
  return void 0;
252
311
  }
253
- Object.assign(record, patch, { updatedAt: now() });
312
+ const defined = Object.fromEntries(Object.entries(patch).filter(([, v]) => v !== void 0));
313
+ Object.assign(record, defined, { revision: record.revision + 1, updatedAt: now() });
254
314
  this.touch();
255
315
  return record;
256
316
  }
@@ -391,16 +451,23 @@ function applySeeds(store, seeds, env = process.env) {
391
451
  });
392
452
  }
393
453
  for (const workflow of seeds.workflows ?? []) {
394
- store.createWorkflow(interpolateEnv(workflow, env));
454
+ const resolved = interpolateEnv(workflow, env);
455
+ store.createWorkflow({
456
+ name: resolved.name,
457
+ blob: resolved.blob ?? resolved.definition ?? {},
458
+ description: resolved.description,
459
+ active: resolved.active,
460
+ executionMode: resolved.executionMode
461
+ });
395
462
  }
396
463
  }
397
464
  function loadState(file, log = console.warn) {
398
- if (!existsSync2(file)) {
465
+ if (!existsSync3(file)) {
399
466
  return null;
400
467
  }
401
468
  let parsed;
402
469
  try {
403
- parsed = JSON.parse(readFileSync(file, "utf-8"));
470
+ parsed = JSON.parse(readFileSync2(file, "utf-8"));
404
471
  } catch {
405
472
  log(`Ignoring ${file}: not valid JSON.`);
406
473
  return null;
@@ -412,14 +479,14 @@ function loadState(file, log = console.warn) {
412
479
  return parsed;
413
480
  }
414
481
  function saveState(file, snapshot) {
415
- mkdirSync(dirname(file), { recursive: true });
482
+ mkdirSync(dirname2(file), { recursive: true });
416
483
  writeFileSync(file, JSON.stringify(snapshot, null, 2), "utf-8");
417
484
  }
418
485
  var SEED_ENTRY_CANDIDATES = ["index.ts", "index.mjs", "index.js", "seeds.ts", "seeds.js"];
419
486
  async function loadSeedsFromDir(dir) {
420
487
  for (const candidate of SEED_ENTRY_CANDIDATES) {
421
488
  const path = resolve2(dir, candidate);
422
- if (existsSync2(path)) {
489
+ if (existsSync3(path)) {
423
490
  const mod = await importFresh(path);
424
491
  return mod.default ?? mod.seeds ?? {};
425
492
  }
@@ -687,6 +754,56 @@ async function validateNodeConfig(loaded, store, input) {
687
754
  }
688
755
  return { valid: Object.keys(errors).length === 0, errors };
689
756
  }
757
+ var MIN_TIMEOUT_MS = 1e3;
758
+ var DEFAULT_TIMEOUT_MS = 3e4;
759
+ var ExecuteTimeout = class extends Error {
760
+ };
761
+ async function executeNodeTest(loaded, store, input) {
762
+ const node = findNode(loaded, input.slug, input.version);
763
+ const logs = [];
764
+ const record = (level) => (message, meta) => {
765
+ logs.push(meta === void 0 ? { level, message } : { level, message, meta });
766
+ };
767
+ const timeoutMs = Math.max(MIN_TIMEOUT_MS, input.timeoutMs ?? DEFAULT_TIMEOUT_MS);
768
+ const controller = new AbortController();
769
+ let timer;
770
+ const expired = new Promise((_resolve, reject) => {
771
+ timer = setTimeout(() => {
772
+ controller.abort();
773
+ reject(new ExecuteTimeout());
774
+ }, timeoutMs);
775
+ });
776
+ const ctx = {
777
+ signal: controller.signal,
778
+ logger: { info: record("info"), warn: record("warn"), error: record("error") },
779
+ secrets: {
780
+ async get(key) {
781
+ const secret = store.getSecret(key);
782
+ if (!secret) {
783
+ throw new DevApiError(404, `Secret '${key}' not found.`);
784
+ }
785
+ return secret.value;
786
+ }
787
+ },
788
+ credentials: {
789
+ async get(id) {
790
+ return (await resolveCredentialInstance(loaded, store, id)).credentials;
791
+ }
792
+ }
793
+ };
794
+ try {
795
+ const result = await Promise.race([node.execute(ctx, { ...input.config, ...input.inputs }), expired]);
796
+ return { outputs: result.outputs ?? {}, branch: result.branch ?? null, logs };
797
+ } catch (err) {
798
+ if (err instanceof DevApiError) {
799
+ throw err;
800
+ }
801
+ const reason = err instanceof ExecuteTimeout || controller.signal.aborted ? `timed out after ${timeoutMs} ms` : err.message;
802
+ throw new DevApiError(502, `Node execution failed: ${reason}`, { logs: logs.map((l) => `${l.level}: ${l.message}`) });
803
+ } finally {
804
+ clearTimeout(timer);
805
+ }
806
+ }
690
807
  async function testCredentialConfig(loaded, store, typeSlug, config) {
691
808
  const cred = findCredential(loaded, typeSlug);
692
809
  return cred.test(credentialContext(store), config);
@@ -728,16 +845,22 @@ async function exchangeOAuthCode(loaded, store, credentialId, params) {
728
845
  import http from "http";
729
846
 
730
847
  // src/http.ts
848
+ var API_VERSION = "1.0.0";
849
+ var BASE_HEADERS = {
850
+ "X-Api-Version": API_VERSION,
851
+ "Access-Control-Allow-Origin": "*",
852
+ "Access-Control-Allow-Headers": "*",
853
+ "Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
854
+ };
731
855
  function sendJson(res, status, body) {
732
856
  const payload = JSON.stringify(body);
733
- res.writeHead(status, {
734
- "Content-Type": "application/json",
735
- "Access-Control-Allow-Origin": "*",
736
- "Access-Control-Allow-Headers": "*",
737
- "Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS"
738
- });
857
+ res.writeHead(status, { "Content-Type": "application/json", ...BASE_HEADERS });
739
858
  res.end(payload);
740
859
  }
860
+ function sendNoContent(res) {
861
+ res.writeHead(204, BASE_HEADERS);
862
+ res.end();
863
+ }
741
864
  function sendError(res, err) {
742
865
  if (err instanceof DevApiError) {
743
866
  sendJson(res, err.status, err.errors ? { message: err.message, errors: err.errors } : { message: err.message });
@@ -775,20 +898,24 @@ function hasDynamicSchema(desc) {
775
898
  function hasDynamicOutputs(desc) {
776
899
  return (desc.outputs ?? []).some((o) => o.resolveOutputs === true);
777
900
  }
778
- function nodeToApi(desc) {
901
+ function nodeToApi(desc, ctx) {
779
902
  const [namespace] = desc.slug.split(":");
780
903
  return {
781
904
  name: desc.name,
782
905
  namespace: namespace ?? null,
783
906
  slug: desc.slug,
784
907
  version: desc.version,
908
+ // The contract declares `package` and both timestamps as present. Nodes here
909
+ // come from the developer's working tree, so the package identity is read from
910
+ // their package.json and the timestamps are when the mock loaded the entry.
911
+ package: ctx?.packageInfo ?? null,
785
912
  manifest_version: MANIFEST_VERSION,
786
913
  manifest: desc,
787
914
  has_dynamic_options: hasDynamicOptions(desc),
788
915
  has_dynamic_schema: hasDynamicSchema(desc),
789
916
  has_dynamic_outputs: hasDynamicOutputs(desc),
790
- created_at: null,
791
- updated_at: null
917
+ created_at: ctx?.loadedAt ?? null,
918
+ updated_at: ctx?.loadedAt ?? null
792
919
  };
793
920
  }
794
921
  function credentialTypeToApi(desc) {
@@ -798,6 +925,7 @@ function credentialTypeToApi(desc) {
798
925
  name: desc.name,
799
926
  description: desc.description ?? null,
800
927
  icon: desc.icon ?? null,
928
+ images: desc.images ?? [],
801
929
  auth_kind: desc.authKind,
802
930
  fields: desc.fields
803
931
  };
@@ -833,7 +961,16 @@ function workflowToApi(record) {
833
961
  return {
834
962
  id: record.id,
835
963
  name: record.name,
836
- definition: record.definition,
964
+ description: record.description,
965
+ blob_definition_version: record.blobDefinitionVersion,
966
+ blob: record.blob,
967
+ active: record.active,
968
+ execution_mode: record.executionMode,
969
+ revision: record.revision,
970
+ // The service reports blob-validation warnings here. The mock's validation is
971
+ // schema-light (see the fidelity caveats), so it never has any — but the field
972
+ // is part of the contract and clients may read it.
973
+ warnings: [],
837
974
  build_status: record.buildStatus,
838
975
  created_at: record.createdAt,
839
976
  updated_at: record.updatedAt
@@ -862,6 +999,7 @@ function templateSummaryToApi(t) {
862
999
  shortDescription: t.shortDescription ?? null,
863
1000
  description: t.description ?? null,
864
1001
  icon: t.icon ?? null,
1002
+ images: t.images ?? [],
865
1003
  industries: t.industries ?? [],
866
1004
  vendors: t.vendors ?? [],
867
1005
  triggerTypes: (t.triggers ?? []).map((tr) => tr.type)
@@ -870,9 +1008,13 @@ function templateSummaryToApi(t) {
870
1008
  function templateFullToApi(t) {
871
1009
  return {
872
1010
  ...templateSummaryToApi(t),
873
- blobVersion: t.blobVersion,
1011
+ // snake_case per the contract, even though the surrounding template fields are
1012
+ // camelCase and the SDK's own field is `blobVersion`.
1013
+ blob_version: t.blobVersion,
874
1014
  definition: t.definition,
875
- triggers: t.triggers ?? []
1015
+ // `config` is optional in the SDK (a manual trigger has none) but declared in
1016
+ // the contract, so normalise it to an object rather than omitting it.
1017
+ triggers: (t.triggers ?? []).map((tr) => ({ ...tr, config: tr.config ?? {} }))
876
1018
  };
877
1019
  }
878
1020
 
@@ -903,13 +1045,15 @@ async function handle(req, res, deps) {
903
1045
  switch (seg[0]) {
904
1046
  case void 0:
905
1047
  case "health":
1048
+ // The service's health route is `/up` (Laravel's default); `/health` is kept
1049
+ // because the devkit has always answered there.
1050
+ case "up":
906
1051
  return void sendJson(res, 200, { status: "ok" });
907
1052
  case "me":
908
1053
  return void sendJson(res, 200, {
909
- id: "dev-user",
910
- name: "Dev User",
911
- email: "dev@revenexx.test",
912
- tenant_id: DEV_TENANT_ID
1054
+ user: { id: 1, zitadel_id: "dev-user", email: "dev@revenexx.test", name: "Dev User" },
1055
+ context: { tenant_id: DEV_TENANT_ID, active_plane: "public", roles: ["admin", "user"] },
1056
+ claims: { iss: "https://id.revenexx.test", sub: "dev-user", aud: ["devkit"] }
913
1057
  });
914
1058
  case "schemas":
915
1059
  return handleSchemas(res, deps, seg);
@@ -936,15 +1080,22 @@ function handleSchemas(res, deps, seg) {
936
1080
  throw new DevApiError(404, "Schema domain required.");
937
1081
  }
938
1082
  const schemas = deps.schemas ?? {};
939
- const schema = version && schemas[`${domain}/${version}`] || schemas[domain];
1083
+ if (!version) {
1084
+ const versions = Object.keys(schemas).filter((key) => key.startsWith(`${domain}/`)).map((key) => key.slice(domain.length + 1)).sort();
1085
+ if (versions.length === 0 && !schemas[domain]) {
1086
+ throw new DevApiError(404, `Unknown schema domain '${domain}'. Vendor it into assets/schemas.`);
1087
+ }
1088
+ return void sendJson(res, 200, { domain, versions });
1089
+ }
1090
+ const schema = schemas[`${domain}/${version}`];
940
1091
  if (!schema) {
941
- throw new DevApiError(404, `No schema for '${domain}${version ? `/${version}` : ""}'. Vendor it into assets/schemas.`);
1092
+ throw new DevApiError(404, `Unknown schema version '${domain}/${version}'. Vendor it into assets/schemas.`);
942
1093
  }
943
- sendJson(res, 200, schema);
1094
+ sendJson(res, 200, { domain, version, schema });
944
1095
  }
945
1096
  async function handleNodes(req, res, method, loaded, store, seg) {
946
1097
  if (seg.length === 1 && method === "GET") {
947
- return void sendJson(res, 200, { data: loaded.manifest.nodes.map(nodeToApi) });
1098
+ return void sendJson(res, 200, { data: loaded.manifest.nodes.map((n) => nodeToApi(n, nodeApiContext(loaded))) });
948
1099
  }
949
1100
  const slug = seg[1];
950
1101
  if (!slug) {
@@ -985,15 +1136,36 @@ async function handleNodes(req, res, method, loaded, store, seg) {
985
1136
  });
986
1137
  return void sendJson(res, 200, result);
987
1138
  }
1139
+ if (seg[3] === "execute:test" && method === "POST") {
1140
+ const body = await readJson(req);
1141
+ const result = await executeNodeTest(loaded, store, {
1142
+ slug,
1143
+ version,
1144
+ config: body.config ?? {},
1145
+ inputs: body.inputs ?? {},
1146
+ timeoutMs: body.timeout_ms
1147
+ });
1148
+ return void sendJson(res, 200, result);
1149
+ }
988
1150
  if (seg.length === 3 && method === "GET") {
989
- const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
990
- if (!node) {
991
- throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
992
- }
993
- return void sendJson(res, 200, nodeToApi(node));
1151
+ return void sendJson(res, 200, nodeToApi(findManifestNode(loaded, slug, version), nodeApiContext(loaded)));
1152
+ }
1153
+ if (seg.length === 3 && method === "DELETE") {
1154
+ findManifestNode(loaded, slug, version);
1155
+ return void sendNoContent(res);
994
1156
  }
995
1157
  throw new DevApiError(404, `No route for nodes/${seg.slice(1).join("/")}`);
996
1158
  }
1159
+ function nodeApiContext(loaded) {
1160
+ return { packageInfo: loaded.packageInfo, loadedAt: loaded.loadedAt };
1161
+ }
1162
+ function findManifestNode(loaded, slug, version) {
1163
+ const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
1164
+ if (!node) {
1165
+ throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
1166
+ }
1167
+ return node;
1168
+ }
997
1169
  function handleCredentialTypes(res, loaded, seg) {
998
1170
  if (seg.length === 1) {
999
1171
  return void sendJson(res, 200, {
@@ -1057,7 +1229,13 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1057
1229
  }
1058
1230
  if (seg[2] === "test" && method === "POST") {
1059
1231
  const result = await testCredentialInstance(loaded, store, id);
1060
- return void sendJson(res, 200, result);
1232
+ const record = store.recordCredentialTest(id, { ok: result.ok, message: result.message ?? null });
1233
+ return void sendJson(res, 200, {
1234
+ ok: result.ok,
1235
+ message: result.message ?? null,
1236
+ last_test_at: record?.lastTestAt ?? null,
1237
+ last_test_ok: record?.lastTestOk ?? result.ok
1238
+ });
1061
1239
  }
1062
1240
  if (seg[2] === "oauth" && seg[3] === "authorize-url" && method === "POST") {
1063
1241
  const redirectUri = "http://localhost/api/v1/credentials/oauth/callback";
@@ -1082,7 +1260,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1082
1260
  }
1083
1261
  if (method === "DELETE") {
1084
1262
  store.deleteCredential(id);
1085
- return void sendJson(res, 200, { deleted: true });
1263
+ return void sendNoContent(res);
1086
1264
  }
1087
1265
  }
1088
1266
  throw new DevApiError(404, `No route for credentials/${seg.slice(1).join("/")}`);
@@ -1090,7 +1268,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1090
1268
  async function handleSecrets(req, res, method, store, seg) {
1091
1269
  if (seg.length === 1) {
1092
1270
  if (method === "GET") {
1093
- return void sendJson(res, 200, { data: store.listSecrets().map(secretToApi) });
1271
+ return void sendJson(res, 200, { keys: store.listSecrets().map((s) => s.key) });
1094
1272
  }
1095
1273
  if (method === "POST") {
1096
1274
  const body = await readJson(req);
@@ -1112,7 +1290,7 @@ async function handleSecrets(req, res, method, store, seg) {
1112
1290
  }
1113
1291
  if (method === "DELETE") {
1114
1292
  store.deleteSecret(key);
1115
- return void sendJson(res, 200, { deleted: true });
1293
+ return void sendNoContent(res);
1116
1294
  }
1117
1295
  }
1118
1296
  throw new DevApiError(404, `No route for secrets/${seg.slice(1).join("/")}`);
@@ -1128,16 +1306,17 @@ async function handleTemplates(req, res, method, loaded, store, seg) {
1128
1306
  throw new DevApiError(404, `Template '${slug}' not found.`);
1129
1307
  }
1130
1308
  if (seg.length === 2 && method === "GET") {
1131
- return void sendJson(res, 200, templateFullToApi(template));
1309
+ return void sendJson(res, 200, { data: templateFullToApi(template) });
1132
1310
  }
1133
1311
  if (seg[2] === "requirements" && method === "GET") {
1134
- return void sendJson(res, 200, { data: { credentials: [], secrets: [] } });
1312
+ return void sendJson(res, 200, { data: { credentialTypes: [], secrets: [] } });
1135
1313
  }
1136
1314
  if (seg[2] === "instantiate" && method === "POST") {
1137
1315
  const body = await readJson(req);
1138
1316
  const workflow = store.createWorkflow({
1139
1317
  name: body.name ?? String(template.name),
1140
- definition: template.definition
1318
+ blob: template.definition,
1319
+ blobDefinitionVersion: template.blobVersion
1141
1320
  });
1142
1321
  for (const trigger of template.triggers ?? []) {
1143
1322
  store.createTrigger({
@@ -1162,7 +1341,11 @@ async function handleWorkflows(req, res, method, store, seg) {
1162
1341
  const body = await readJson(req);
1163
1342
  const workflow = store.createWorkflow({
1164
1343
  name: body.name ?? "Untitled workflow",
1165
- definition: body.definition ?? {}
1344
+ blob: body.blob ?? {},
1345
+ blobDefinitionVersion: body.blob_definition_version,
1346
+ description: body.description,
1347
+ active: body.active,
1348
+ executionMode: body.execution_mode
1166
1349
  });
1167
1350
  return void sendJson(res, 201, workflowToApi(workflow));
1168
1351
  }
@@ -1203,7 +1386,7 @@ async function handleWorkflows(req, res, method, store, seg) {
1203
1386
  }
1204
1387
  if (triggerId && method === "DELETE") {
1205
1388
  store.deleteTrigger(triggerId);
1206
- return void sendJson(res, 200, { deleted: true });
1389
+ return void sendNoContent(res);
1207
1390
  }
1208
1391
  }
1209
1392
  if (seg.length === 2) {
@@ -1216,7 +1399,14 @@ async function handleWorkflows(req, res, method, store, seg) {
1216
1399
  }
1217
1400
  if (method === "PUT") {
1218
1401
  const body = await readJson(req);
1219
- const updated = store.updateWorkflow(id, { name: body.name, definition: body.definition });
1402
+ const updated = store.updateWorkflow(id, {
1403
+ name: body.name,
1404
+ blob: body.blob,
1405
+ blobDefinitionVersion: body.blob_definition_version,
1406
+ description: body.description,
1407
+ active: body.active,
1408
+ executionMode: body.execution_mode
1409
+ });
1220
1410
  if (!updated) {
1221
1411
  throw new DevApiError(404, `Workflow '${id}' not found.`);
1222
1412
  }
@@ -1224,7 +1414,7 @@ async function handleWorkflows(req, res, method, store, seg) {
1224
1414
  }
1225
1415
  if (method === "DELETE") {
1226
1416
  store.deleteWorkflow(id);
1227
- return void sendJson(res, 200, { deleted: true });
1417
+ return void sendNoContent(res);
1228
1418
  }
1229
1419
  }
1230
1420
  if ((seg[2] === "credentials" || seg[2] === "credential-types") && method === "GET") {
@@ -1235,16 +1425,18 @@ async function handleWorkflows(req, res, method, store, seg) {
1235
1425
 
1236
1426
  // src/index.ts
1237
1427
  var manifestUrl = new URL("../package.json", import.meta.url);
1238
- var DEVKIT_VERSION = JSON.parse(readFileSync2(manifestUrl, "utf8")).version;
1428
+ var DEVKIT_VERSION = JSON.parse(readFileSync3(manifestUrl, "utf8")).version;
1239
1429
 
1240
1430
  export {
1431
+ DevApiError,
1432
+ CliError,
1241
1433
  ENV_FILE_MIN_NODE,
1242
1434
  nodeOwnedEnvFlag,
1243
1435
  resolveEnvFile,
1244
1436
  loadEnvFile,
1245
- DevApiError,
1246
1437
  resolveExports,
1247
1438
  ensureTsxRegistered,
1439
+ isReloadableSource,
1248
1440
  importFresh,
1249
1441
  loadPackageFromEntry,
1250
1442
  DEV_TENANT_ID,
@@ -1270,4 +1462,4 @@ export {
1270
1462
  createDevServer,
1271
1463
  DEVKIT_VERSION
1272
1464
  };
1273
- //# sourceMappingURL=chunk-2GVOKLIW.js.map
1465
+ //# sourceMappingURL=chunk-YXIYTBOZ.js.map