@revenexx/integrations-node-devkit 0.6.0 → 0.8.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
@@ -87,6 +87,26 @@ next version bump. To change the host, take a copy that is yours:
87
87
  > `POST`s to `/nodes/{slug}/{version}/config:resolve`, which the mock serves).
88
88
  > The **Workflows** surface is hidden until phase 2, because workflow execution is
89
89
  > not mocked; the Temporal parts (run history, `…/runs/*`) are intentionally absent.
90
+ >
91
+ > Three things a node declares are drawn by the inspector as the product draws
92
+ > them, as of `@revenexx/studio-integrations` 1.3.0: a `showIf` condition hides
93
+ > the setting it is written on until it holds (and the mock's `config:validate`
94
+ > skips that setting too, so the two agree), a `state-ref` setting is a picker
95
+ > rather than a raw JSON box, and a node exported in more than one version can be
96
+ > moved between them from inside the dialog. What each move costs is listed
97
+ > before it happens.
98
+ >
99
+ > From 1.4.0 the Parameters tab draws a node's settings in the order the node
100
+ > declares them, rather than every required one first: four or fewer are all
101
+ > shown, and past the fourth a setting stands when it is required and folds away
102
+ > when it is not. The lever is the manifest — a setting that is central to a node
103
+ > belongs near the top of its `config`, whether or not it is required. A setting
104
+ > inside a repeating row is drawn as what it declares too (its options, its
105
+ > default, its description, its `showIf` resolved against **that** row) instead
106
+ > of as an empty text box, and a new row starts from the declared defaults rather
107
+ > than from an empty string under every key. An option declared with an empty
108
+ > value — "unchanged", "all kinds" — is selectable rather than fatal to the
109
+ > dialog.
90
110
 
91
111
  The mock is checked against the service's own OpenAPI contract — see
92
112
  [docs/architecture.md](docs/architecture.md#staying-in-step-with-the-real-api).
@@ -169,6 +189,22 @@ import {
169
189
  const ctx = createMockContext({ credentials: { 'smtp-1': { host: 'mail' } } });
170
190
  const res = await node.execute(ctx, { credentials: 'smtp-1' });
171
191
 
192
+ // state (PO-374): seed what earlier runs left behind, then assert both branches
193
+ const syncCtx = createMockContext({
194
+ state: {
195
+ mappings: { article: { 'pim:12345': 'erp:A-8891' } },
196
+ cursors: { 'crm.customers': { '': { updatedAfter: '2026-08-01T00:00:00Z' } } },
197
+ },
198
+ });
199
+ await node.execute(syncCtx, { id: '12345' });
200
+ expect(syncCtx.state.mapping.put).not.toHaveBeenCalled(); // it was already known
201
+
202
+ // a cursor and a digest are staged: the run that sets one does not read it back.
203
+ // completeRun() is the run's ending — leave it out to play the run that failed
204
+ await node.execute(syncCtx, { since: 'cursor' });
205
+ syncCtx.completeRun();
206
+ await node.execute(syncCtx, { since: 'cursor' }); // reads what the first run staged
207
+
172
208
  // author-time resolver
173
209
  const authorCtx = createAuthorContext({ category: 'fruits' });
174
210
  const options = await node.loadOptions(authorCtx, 'item');
@@ -201,3 +237,41 @@ This is a faithful **dev** stand-in, not the production service:
201
237
  client-side schema validation is inactive.
202
238
  - `POST /nodes/{slug}/{version}/config:validate` exists only here, not in the real
203
239
  API.
240
+ - **`config:validate` reads a node's settings one level deep.** A setting
241
+ declared inside a repeating row or an object (`items` / `properties`) is
242
+ checked for being an array or an object and no further: its sub-settings are
243
+ not demanded when required, not type-checked, and their own `showIf` is not
244
+ resolved per row. The inspector draws all three from `studio-integrations`
245
+ 1.4.0 on, so on nested settings the preview is now ahead of the validator —
246
+ the mirror image of the gap 1.3.0 closed.
247
+ - **The state store (PO-374) is writable here, and read-only in production.** In
248
+ the real product an author-time test run may read `ctx.state` but not write to
249
+ it: a correlation created by a test click is indistinguishable from one a
250
+ production run made, and the next real run would trust it. Locally there is no
251
+ such stake — the store is a disposable overlay in `.revenexx-dev/` — and
252
+ refusing writes would make it impossible to exercise the very nodes the state
253
+ store exists for. So a node that correlates ids behaves on its second preview
254
+ call like a second run, which it would not do against the real API.
255
+
256
+ What the store *does* enforce is kept: a mapping and a claim take effect at
257
+ once while a cursor and a digest are staged and adopted only when the run
258
+ completes (a preview call that fails leaves them where they were), re-pointing
259
+ either side of an existing correlation is refused, and a `ttlSeconds` outside
260
+ 1…31536000 is refused rather than clamped. A node that passes here should not
261
+ meet the store's rules for the first time in production.
262
+ - **No namespace declaration and no role enforcement.** Any namespace name
263
+ works, where the real engine refuses one the workflow did not declare —
264
+ including the per-node half, where only the namespaces a node's own
265
+ `state-ref` settings name are reachable. Nothing local can enforce that: the
266
+ declarations live in a workflow's blob, and the preview has no workflow.
267
+ - **A `state-ref` picker offers what you declared in it, and only for this
268
+ session.** The picker is real from `studio-integrations` 1.3.0 on — the
269
+ namespaces of the field's `stateRole`, and the offer to declare a new one — but
270
+ in the product its list comes from the workflow being edited. The preview's
271
+ node page owns that list instead: it starts empty, a declaration kept by Save
272
+ joins it, and a browser reload starts over. Nothing is written to the blob,
273
+ because there is none, and the mock does not check a namespace against it
274
+ either — see the bullet above.
275
+ - The state entries are not exposed over the mock API, so the Cockpit's State
276
+ view — and the editor's own State dialog, which edits a workflow's `state`
277
+ block — is inactive in the preview.
@@ -0,0 +1,30 @@
1
+ // src/state-rules.ts
2
+ import { NodeError } from "@revenexx/integrations-node-sdk";
3
+ var DEFAULT_CLAIM_TTL_SECONDS = 604800;
4
+ var MIN_CLAIM_TTL_SECONDS = 1;
5
+ var MAX_CLAIM_TTL_SECONDS = 31536e3;
6
+ function assertTtlInRange(ttlSeconds) {
7
+ if (ttlSeconds === void 0) {
8
+ return;
9
+ }
10
+ if (!Number.isFinite(ttlSeconds) || ttlSeconds < MIN_CLAIM_TTL_SECONDS || ttlSeconds > MAX_CLAIM_TTL_SECONDS) {
11
+ throw new NodeError("INVALID_TTL", `ttlSeconds must be between ${MIN_CLAIM_TTL_SECONDS} and ${MAX_CLAIM_TTL_SECONDS}, got ${String(ttlSeconds)}.`);
12
+ }
13
+ }
14
+ function assertNotRepointed(namespace, pairs, left, right) {
15
+ for (const [existingLeft, existingRight] of pairs) {
16
+ if (existingLeft === left && existingRight !== right) {
17
+ throw new NodeError("MAPPING_CONFLICT", `'${left}' is already correlated with '${existingRight}' in namespace '${namespace}'.`);
18
+ }
19
+ if (existingRight === right && existingLeft !== left) {
20
+ throw new NodeError("MAPPING_CONFLICT", `'${right}' is already correlated with '${existingLeft}' in namespace '${namespace}'.`);
21
+ }
22
+ }
23
+ }
24
+
25
+ export {
26
+ DEFAULT_CLAIM_TTL_SECONDS,
27
+ assertTtlInRange,
28
+ assertNotRepointed
29
+ };
30
+ //# sourceMappingURL=chunk-PME34X7E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state-rules.ts"],"sourcesContent":["import { NodeError } from '@revenexx/integrations-node-sdk';\n\n/**\n * The two rules the tenant state store keeps that neither the mock context nor\n * the local preview would otherwise have any reason to keep — and both of which\n * a node author only finds out about in production if we do not.\n *\n * They live here rather than in either caller because the testing harness and\n * the preview must refuse the same things: a node that passes its unit tests and\n * then trips the store on its first preview run has learnt nothing from either.\n * The rest of what the store promises — that a granted claim really excludes a\n * parallel run, that an undeclared namespace is refused — is the engine's, and\n * `specs/workflow-state.md` in the SDK records it as such.\n */\n\n/** Mirrors the engine's default claim lifetime (7 days). */\nexport const DEFAULT_CLAIM_TTL_SECONDS = 604_800;\n\n/** The window the store accepts: one second to one year. */\nexport const MIN_CLAIM_TTL_SECONDS = 1;\nexport const MAX_CLAIM_TTL_SECONDS = 31_536_000;\n\n/**\n * A `ttlSeconds` outside the accepted window is refused rather than clamped: the\n * figure is the duplicate-suppression window *and* the retry window, so a node\n * quietly given a different one than it asked for would suppress deliveries for\n * a stretch its author never chose.\n */\nexport function assertTtlInRange(ttlSeconds: number | undefined): void {\n if (ttlSeconds === undefined) {\n return;\n }\n if (!Number.isFinite(ttlSeconds) || ttlSeconds < MIN_CLAIM_TTL_SECONDS || ttlSeconds > MAX_CLAIM_TTL_SECONDS) {\n throw new NodeError('INVALID_TTL', `ttlSeconds must be between ${MIN_CLAIM_TTL_SECONDS} and ${MAX_CLAIM_TTL_SECONDS}, got ${String(ttlSeconds)}.`);\n }\n}\n\n/**\n * Re-pointing one side of an existing pair is refused, in both directions: an id\n * correlated two ways is always a bug, and no later sync can untangle it —\n * whichever of the two answers a lookup happens to give, half the records it\n * touches are the wrong ones. Writing the same pair again is not a re-point and\n * is allowed, so a node that puts unconditionally on every run stays green.\n */\nexport function assertNotRepointed(namespace: string, pairs: Iterable<[string, string]>, left: string, right: string): void {\n for (const [existingLeft, existingRight] of pairs) {\n if (existingLeft === left && existingRight !== right) {\n throw new NodeError('MAPPING_CONFLICT', `'${left}' is already correlated with '${existingRight}' in namespace '${namespace}'.`);\n }\n if (existingRight === right && existingLeft !== left) {\n throw new NodeError('MAPPING_CONFLICT', `'${right}' is already correlated with '${existingLeft}' in namespace '${namespace}'.`);\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAgBnB,IAAM,4BAA4B;AAGlC,IAAM,wBAAwB;AAC9B,IAAM,wBAAwB;AAQ9B,SAAS,iBAAiB,YAAsC;AACrE,MAAI,eAAe,QAAW;AAC5B;AAAA,EACF;AACA,MAAI,CAAC,OAAO,SAAS,UAAU,KAAK,aAAa,yBAAyB,aAAa,uBAAuB;AAC5G,UAAM,IAAI,UAAU,eAAe,8BAA8B,qBAAqB,QAAQ,qBAAqB,SAAS,OAAO,UAAU,CAAC,GAAG;AAAA,EACnJ;AACF;AASO,SAAS,mBAAmB,WAAmB,OAAmC,MAAc,OAAqB;AAC1H,aAAW,CAAC,cAAc,aAAa,KAAK,OAAO;AACjD,QAAI,iBAAiB,QAAQ,kBAAkB,OAAO;AACpD,YAAM,IAAI,UAAU,oBAAoB,IAAI,IAAI,iCAAiC,aAAa,mBAAmB,SAAS,IAAI;AAAA,IAChI;AACA,QAAI,kBAAkB,SAAS,iBAAiB,MAAM;AACpD,YAAM,IAAI,UAAU,oBAAoB,IAAI,KAAK,iCAAiC,YAAY,mBAAmB,SAAS,IAAI;AAAA,IAChI;AAAA,EACF;AACF;","names":[]}
@@ -1,3 +1,9 @@
1
+ import {
2
+ DEFAULT_CLAIM_TTL_SECONDS,
3
+ assertNotRepointed,
4
+ assertTtlInRange
5
+ } from "./chunk-PME34X7E.js";
6
+
1
7
  // src/index.ts
2
8
  import { readFileSync as readFileSync3 } from "fs";
3
9
 
@@ -155,10 +161,13 @@ import { randomUUID } from "crypto";
155
161
  var DEV_TENANT_ID = "dev-tenant";
156
162
  var BLOB_DEFINITION_VERSION = "v0-draft";
157
163
  var EXECUTION_MODES = ["async_only", "sync_only", "caller_decides"];
158
- var STORE_SCHEMA_VERSION = 2;
164
+ var STORE_SCHEMA_VERSION = 3;
159
165
  function now() {
160
166
  return (/* @__PURE__ */ new Date()).toISOString();
161
167
  }
168
+ function stateKey(role, namespace, key) {
169
+ return `${role}\0${namespace}\0${key}`;
170
+ }
162
171
  var DevStore = class {
163
172
  /**
164
173
  * @param onChange fired after any mutation so a caller (the CLI) can persist
@@ -172,6 +181,8 @@ var DevStore = class {
172
181
  secrets = /* @__PURE__ */ new Map();
173
182
  workflows = /* @__PURE__ */ new Map();
174
183
  triggers = /* @__PURE__ */ new Map();
184
+ /** Keyed by `${role}\u0000${namespace}\u0000${key}` — a NUL occurs in no part. */
185
+ stateEntries = /* @__PURE__ */ new Map();
175
186
  nextWorkflowId = 1;
176
187
  /** (Re)wire the post-mutation callback — e.g. attach it only after seeding. */
177
188
  setOnMutation(onChange) {
@@ -370,6 +381,21 @@ var DevStore = class {
370
381
  return deleted;
371
382
  }
372
383
  // ------------------------------------------------------------- persistence
384
+ // ------------------------------------------------------------------ state
385
+ /** The stored entry for a role/namespace/key, or undefined when unknown. */
386
+ getStateEntry(role, namespace, key) {
387
+ return this.stateEntries.get(stateKey(role, namespace, key));
388
+ }
389
+ /** Every entry a namespace holds in one role — how a reverse mapping lookup is answered. */
390
+ listStateEntries(role, namespace) {
391
+ return [...this.stateEntries.values()].filter((e) => e.role === role && e.namespace === namespace);
392
+ }
393
+ putStateEntry(entry) {
394
+ const record = { ...entry, updatedAt: now() };
395
+ this.stateEntries.set(stateKey(entry.role, entry.namespace, entry.key), record);
396
+ this.onChange?.();
397
+ return record;
398
+ }
373
399
  toSnapshot() {
374
400
  return {
375
401
  schemaVersion: STORE_SCHEMA_VERSION,
@@ -377,6 +403,7 @@ var DevStore = class {
377
403
  secrets: [...this.secrets.values()],
378
404
  workflows: [...this.workflows.values()],
379
405
  triggers: [...this.triggers.values()],
406
+ stateEntries: [...this.stateEntries.values()],
380
407
  nextWorkflowId: this.nextWorkflowId
381
408
  };
382
409
  }
@@ -385,6 +412,7 @@ var DevStore = class {
385
412
  this.secrets = new Map(snapshot.secrets.map((s) => [s.key, s]));
386
413
  this.workflows = new Map(snapshot.workflows.map((w) => [w.id, w]));
387
414
  this.triggers = new Map(snapshot.triggers.map((t) => [t.id, t]));
415
+ this.stateEntries = new Map((snapshot.stateEntries ?? []).map((e) => [stateKey(e.role, e.namespace, e.key), e]));
388
416
  this.nextWorkflowId = snapshot.nextWorkflowId ?? Math.max(0, ...snapshot.workflows.map((w) => w.id)) + 1;
389
417
  }
390
418
  /**
@@ -406,6 +434,9 @@ var DevStore = class {
406
434
  for (const t of snapshot.triggers) {
407
435
  this.triggers.set(t.id, t);
408
436
  }
437
+ for (const e of snapshot.stateEntries ?? []) {
438
+ this.stateEntries.set(stateKey(e.role, e.namespace, e.key), e);
439
+ }
409
440
  this.nextWorkflowId = Math.max(this.nextWorkflowId, snapshot.nextWorkflowId ?? 0, ...snapshot.workflows.map((w) => w.id + 1));
410
441
  }
411
442
  };
@@ -496,7 +527,8 @@ async function loadSeedsFromDir(dir) {
496
527
 
497
528
  // src/resolve.ts
498
529
  import {
499
- isOAuthAuthorizeCredential
530
+ isOAuthAuthorizeCredential,
531
+ settingApplies
500
532
  } from "@revenexx/integrations-node-sdk";
501
533
  var noopLogger = {
502
534
  info() {
@@ -506,20 +538,66 @@ var noopLogger = {
506
538
  error() {
507
539
  }
508
540
  };
541
+ function parseSemver(version) {
542
+ const [withoutBuild] = version.split("+");
543
+ const dash = withoutBuild.indexOf("-");
544
+ const core = (dash === -1 ? withoutBuild : withoutBuild.slice(0, dash)).split(".").map((n) => Number.parseInt(n, 10) || 0);
545
+ const pre = dash === -1 ? [] : withoutBuild.slice(dash + 1).split(".");
546
+ return { core, pre };
547
+ }
548
+ function comparePrerelease(a, b) {
549
+ if (a.length === 0 || b.length === 0) {
550
+ return (a.length === 0 ? 1 : 0) - (b.length === 0 ? 1 : 0);
551
+ }
552
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
553
+ const ia = a[i];
554
+ const ib = b[i];
555
+ if (ia === void 0 || ib === void 0) {
556
+ return ia === void 0 ? -1 : 1;
557
+ }
558
+ const na = /^\d+$/.test(ia) ? Number(ia) : null;
559
+ const nb = /^\d+$/.test(ib) ? Number(ib) : null;
560
+ if (na !== null && nb !== null) {
561
+ if (na !== nb) {
562
+ return na - nb;
563
+ }
564
+ continue;
565
+ }
566
+ if (na !== null || nb !== null) {
567
+ return na !== null ? -1 : 1;
568
+ }
569
+ if (ia !== ib) {
570
+ return ia < ib ? -1 : 1;
571
+ }
572
+ }
573
+ return 0;
574
+ }
509
575
  function compareSemver(a, b) {
510
- const pa = a.split(".").map((n) => Number.parseInt(n, 10) || 0);
511
- const pb = b.split(".").map((n) => Number.parseInt(n, 10) || 0);
576
+ const pa = parseSemver(a);
577
+ const pb = parseSemver(b);
512
578
  for (let i = 0; i < 3; i++) {
513
- const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
579
+ const diff = (pa.core[i] ?? 0) - (pb.core[i] ?? 0);
514
580
  if (diff !== 0) {
515
581
  return diff;
516
582
  }
517
583
  }
518
- return 0;
584
+ return comparePrerelease(pa.pre, pb.pre);
519
585
  }
520
586
  function nodeVersions(loaded, slug) {
521
587
  return loaded.nodes.filter((n) => n.description.slug === slug).map((n) => n.description.version).sort((a, b) => compareSemver(b, a));
522
588
  }
589
+ function listNodesNewestFirst(nodes) {
590
+ const bySlug = /* @__PURE__ */ new Map();
591
+ for (const node of nodes) {
592
+ const group = bySlug.get(node.slug);
593
+ if (group) {
594
+ group.push(node);
595
+ } else {
596
+ bySlug.set(node.slug, [node]);
597
+ }
598
+ }
599
+ return [...bySlug.values()].flatMap((group) => [...group].sort((a, b) => compareSemver(b.version, a.version)));
600
+ }
523
601
  function findNode(loaded, slug, version) {
524
602
  const matches = loaded.nodes.filter((n) => n.description.slug === slug);
525
603
  if (matches.length === 0) {
@@ -562,6 +640,68 @@ async function resolveCredentialInstance(loaded, store, credentialId) {
562
640
  const ctx = credentialContext(store, credentialId);
563
641
  return cred.resolve(ctx, instance.config, instance.durableCreds);
564
642
  }
643
+ function createRunState(store) {
644
+ const staged = [];
645
+ const stage = (entry) => {
646
+ staged.push(entry);
647
+ };
648
+ const state = {
649
+ mapping: {
650
+ async get(namespace, key, side = "left") {
651
+ if (side === "left") {
652
+ const entry = store.getStateEntry("mapping", namespace, key);
653
+ return entry ? String(entry.value) : null;
654
+ }
655
+ const match = store.listStateEntries("mapping", namespace).find((e) => String(e.value) === key);
656
+ return match ? match.key : null;
657
+ },
658
+ async put(namespace, left, right) {
659
+ assertNotRepointed(
660
+ namespace,
661
+ store.listStateEntries("mapping", namespace).map((e) => [e.key, String(e.value)]),
662
+ left,
663
+ right
664
+ );
665
+ store.putStateEntry({ namespace, role: "mapping", key: left, value: right });
666
+ }
667
+ },
668
+ cursor: {
669
+ async get(namespace, partitionKey = "") {
670
+ return store.getStateEntry("cursor", namespace, partitionKey)?.value;
671
+ },
672
+ async set(namespace, value, partitionKey = "") {
673
+ stage({ namespace, role: "cursor", key: partitionKey, value });
674
+ }
675
+ },
676
+ async claim(namespace, key, opts) {
677
+ assertTtlInRange(opts?.ttlSeconds);
678
+ const held = store.getStateEntry("dedupe", namespace, key);
679
+ if (held && Number(held.value) > Date.now()) {
680
+ return false;
681
+ }
682
+ const ttlSeconds = opts?.ttlSeconds ?? DEFAULT_CLAIM_TTL_SECONDS;
683
+ store.putStateEntry({ namespace, role: "dedupe", key, value: Date.now() + ttlSeconds * 1e3 });
684
+ return true;
685
+ },
686
+ digest: {
687
+ async unchanged(namespace, entityKey, digest) {
688
+ return store.getStateEntry("digest", namespace, entityKey)?.value === digest;
689
+ },
690
+ async set(namespace, entityKey, digest) {
691
+ stage({ namespace, role: "digest", key: entityKey, value: digest });
692
+ }
693
+ }
694
+ };
695
+ return {
696
+ state,
697
+ commit() {
698
+ for (const entry of staged) {
699
+ store.putStateEntry(entry);
700
+ }
701
+ staged.length = 0;
702
+ }
703
+ };
704
+ }
565
705
  function authorContext(loaded, store, config, locale) {
566
706
  return {
567
707
  signal: new AbortController().signal,
@@ -652,6 +792,10 @@ function validateField(field, value, errors) {
652
792
  switch (field.type) {
653
793
  case "string":
654
794
  case "secret-ref":
795
+ // A `state-ref` carries the chosen namespace NAME, so a string is all there
796
+ // is to check here: which names exist is the workflow's declaration, and
797
+ // nothing declares one locally (see the README's fidelity caveats).
798
+ case "state-ref":
655
799
  case "expression":
656
800
  if (typeof value !== "string") {
657
801
  push("Expected a string.");
@@ -735,9 +879,12 @@ async function validateNodeConfig(loaded, store, input) {
735
879
  if (field.type === "dynamic-schema") {
736
880
  continue;
737
881
  }
882
+ if (!settingApplies(field, config)) {
883
+ continue;
884
+ }
738
885
  validateField(field, config[field.key], errors);
739
886
  }
740
- if (fields.some((f) => f.type === "dynamic-schema") && node.resolveConfigSchema) {
887
+ if (fields.some((f) => f.type === "dynamic-schema" && settingApplies(f, config)) && node.resolveConfigSchema) {
741
888
  const ctx = authorContext(loaded, store, config, input.locale);
742
889
  let children;
743
890
  try {
@@ -749,6 +896,9 @@ async function validateNodeConfig(loaded, store, input) {
749
896
  throw new DevApiError(502, `Node resolve failed: ${err.message}`);
750
897
  }
751
898
  for (const child of children) {
899
+ if (!settingApplies(child, config)) {
900
+ continue;
901
+ }
752
902
  validateField(child, config[child.key], errors);
753
903
  }
754
904
  }
@@ -765,6 +915,7 @@ async function executeNodeTest(loaded, store, input) {
765
915
  logs.push(meta === void 0 ? { level, message } : { level, message, meta });
766
916
  };
767
917
  const timeoutMs = Math.max(MIN_TIMEOUT_MS, input.timeoutMs ?? DEFAULT_TIMEOUT_MS);
918
+ const run = createRunState(store);
768
919
  const controller = new AbortController();
769
920
  let timer;
770
921
  const expired = new Promise((_resolve, reject) => {
@@ -789,10 +940,12 @@ async function executeNodeTest(loaded, store, input) {
789
940
  async get(id) {
790
941
  return (await resolveCredentialInstance(loaded, store, id)).credentials;
791
942
  }
792
- }
943
+ },
944
+ state: run.state
793
945
  };
794
946
  try {
795
947
  const result = await Promise.race([node.execute(ctx, { ...input.config, ...input.inputs }), expired]);
948
+ run.commit();
796
949
  return { outputs: result.outputs ?? {}, branch: result.branch ?? null, logs };
797
950
  } catch (err) {
798
951
  if (err instanceof DevApiError) {
@@ -1028,13 +1181,24 @@ function createRequestListener(deps) {
1028
1181
  function createDevServer(deps) {
1029
1182
  return http.createServer(createRequestListener(deps));
1030
1183
  }
1184
+ function requestOrigin(req) {
1185
+ const host = req.headers.host;
1186
+ if (!host) {
1187
+ return "http://localhost";
1188
+ }
1189
+ try {
1190
+ return new URL(`http://${host}`).origin;
1191
+ } catch {
1192
+ return "http://localhost";
1193
+ }
1194
+ }
1031
1195
  async function handle(req, res, deps) {
1032
1196
  const method = (req.method ?? "GET").toUpperCase();
1033
1197
  if (method === "OPTIONS") {
1034
1198
  sendJson(res, 204, {});
1035
1199
  return;
1036
1200
  }
1037
- const url = new URL(req.url ?? "/", "http://localhost");
1201
+ const url = new URL(req.url ?? "/", requestOrigin(req));
1038
1202
  let pathname = url.pathname;
1039
1203
  if (pathname.startsWith("/api/v1")) {
1040
1204
  pathname = pathname.slice("/api/v1".length);
@@ -1095,7 +1259,7 @@ function handleSchemas(res, deps, seg) {
1095
1259
  }
1096
1260
  async function handleNodes(req, res, method, loaded, store, seg) {
1097
1261
  if (seg.length === 1 && method === "GET") {
1098
- return void sendJson(res, 200, { data: loaded.manifest.nodes.map((n) => nodeToApi(n, nodeApiContext(loaded))) });
1262
+ return void sendJson(res, 200, { data: listNodesNewestFirst(loaded.manifest.nodes).map((n) => nodeToApi(n, nodeApiContext(loaded))) });
1099
1263
  }
1100
1264
  const slug = seg[1];
1101
1265
  if (!slug) {
@@ -1160,7 +1324,8 @@ function nodeApiContext(loaded) {
1160
1324
  return { packageInfo: loaded.packageInfo, loadedAt: loaded.loadedAt };
1161
1325
  }
1162
1326
  function findManifestNode(loaded, slug, version) {
1163
- const node = loaded.manifest.nodes.find((n) => n.slug === slug && (version === "latest" || n.version === version));
1327
+ const matches = loaded.manifest.nodes.filter((n) => n.slug === slug);
1328
+ const node = version === "latest" ? listNodesNewestFirst(matches)[0] : matches.find((n) => n.version === version);
1164
1329
  if (!node) {
1165
1330
  throw new DevApiError(404, `Node '${slug}@${version}' not found.`);
1166
1331
  }
@@ -1238,7 +1403,7 @@ async function handleCredentials(req, res, method, loaded, store, seg, url) {
1238
1403
  });
1239
1404
  }
1240
1405
  if (seg[2] === "oauth" && seg[3] === "authorize-url" && method === "POST") {
1241
- const redirectUri = "http://localhost/api/v1/credentials/oauth/callback";
1406
+ const redirectUri = `${url.origin}/api/v1/credentials/oauth/callback`;
1242
1407
  const result = await buildOAuthAuthorizeUrl(loaded, store, id, { redirectUri, state: id });
1243
1408
  return void sendJson(res, 200, { authorize_url: result.authorizeUrl });
1244
1409
  }
@@ -1448,6 +1613,7 @@ export {
1448
1613
  saveState,
1449
1614
  loadSeedsFromDir,
1450
1615
  nodeVersions,
1616
+ listNodesNewestFirst,
1451
1617
  findNode,
1452
1618
  findCredential,
1453
1619
  findCredentialType,
@@ -1462,4 +1628,4 @@ export {
1462
1628
  createDevServer,
1463
1629
  DEVKIT_VERSION
1464
1630
  };
1465
- //# sourceMappingURL=chunk-YXIYTBOZ.js.map
1631
+ //# sourceMappingURL=chunk-YUUW37NC.js.map