@uipath/maestro-builder-sdk 6.26.0 → 6.27.1

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/dist/flow-sdk.js CHANGED
@@ -612,11 +612,23 @@ class StepList {
612
612
  * ], (other) => other.step('unknown', script({ code: 'return "Unknown";' })))
613
613
  * ```
614
614
  *
615
+ * @example
616
+ * **Cases with their own conditions** (`on` is `undefined`)
617
+ * ```ts
618
+ * .switch('route', undefined, [
619
+ * { when: js`$vars.start.output.amount > 100`, label: 'High', body: (b) => b.step('review', script({ code: 'return 1;' })) },
620
+ * { when: js`$vars.start.output.amount <= 100`, label: 'Low', body: (b) => b.step('auto', script({ code: 'return 2;' })) },
621
+ * ])
622
+ * ```
623
+ *
615
624
  * @param name - The switch node's id.
616
- * @param on - The value to compare each case against.
617
- * @param cases - One entry per arm, evaluated top to bottom; the first strict
618
- * match wins. `label` names the arm's outgoing edge. `id` keeps a case's wire
619
- * id (`inputs.cases[].id`, port `case-<id>`); omitted, it is `case_<n>`.
625
+ * @param on - The value to compare each `value` case against; `undefined`
626
+ * when every case carries its own `when` condition.
627
+ * @param cases - One entry per arm, evaluated top to bottom; the first match
628
+ * wins. A case is `{ value }` (strict `on === value`) or `{ when }` (its own
629
+ * boolean expression). `label` names the arm's outgoing edge. `id` keeps a
630
+ * case's wire id (`inputs.cases[].id`, port `case-<id>`); omitted, it is
631
+ * `case_<n>`.
620
632
  * @param defaultFn - Receives a sub-builder for the arm taken when nothing
621
633
  * matches. Omit it and an unmatched value simply continues.
622
634
  * @param options - Node options; `version` selects the exact definition
@@ -634,7 +646,14 @@ class StepList {
634
646
  // An arm's own `.label(...)` wins over the case config's `label`; either
635
647
  // overrides the serializer's derived `Case "<value>"`.
636
648
  const label = arm.armLabel ?? c.label;
637
- return { value: c.value, ...(label !== undefined ? { label } : {}), ...(c.id !== undefined ? { id: c.id } : {}), body: arm.steps };
649
+ return {
650
+ // Both kept as given, so check can refuse a case with both or neither.
651
+ ...(c.value !== undefined ? { value: c.value } : {}),
652
+ ...(c.when !== undefined ? { when: toExpr(c.when) } : {}),
653
+ ...(label !== undefined ? { label } : {}),
654
+ ...(c.id !== undefined ? { id: c.id } : {}),
655
+ body: arm.steps,
656
+ };
638
657
  });
639
658
  let dflt;
640
659
  if (defaultFn) {
@@ -649,7 +668,7 @@ class StepList {
649
668
  this.steps.push({
650
669
  kind: 'switch',
651
670
  name,
652
- on: toExpr(on),
671
+ ...(on !== undefined ? { on: toExpr(on) } : {}),
653
672
  cases: arms,
654
673
  ...(dflt !== undefined ? { default: dflt } : {}),
655
674
  ...(options ? { options } : {}),
@@ -4,8 +4,10 @@
4
4
  * `sdk-resolve-hook.ts` for why. Idempotent; call it before importing authored
5
5
  * source.
6
6
  *
7
- * Does nothing when the compiled hook is absent, which is the case only when
8
- * the SDK runs from its TypeScript source under the test runner. The runner
9
- * resolves imports itself, so no hook is needed there.
7
+ * Does nothing when the SDK runs from its TypeScript source under the test
8
+ * runner, which resolves imports itself. Anywhere else a missing hook means the
9
+ * SDK was bundled: authored source would then load a second copy of the
10
+ * package, its expressions would fail this copy's `instanceof` checks, and the
11
+ * `.flow` would come out wrong with no error. That throws instead.
10
12
  */
11
13
  export declare function useThisSdkForAuthoredSource(): void;
@@ -2,6 +2,7 @@
2
2
  import { existsSync } from 'node:fs';
3
3
  import { register } from 'node:module';
4
4
  import { fileURLToPath } from 'node:url';
5
+ import { PACKAGE_NAME } from './package-name.js';
5
6
  let registered = false;
6
7
  /**
7
8
  * Make `import … from '@uipath/maestro-builder-sdk'` in authored source resolve
@@ -9,16 +10,24 @@ let registered = false;
9
10
  * `sdk-resolve-hook.ts` for why. Idempotent; call it before importing authored
10
11
  * source.
11
12
  *
12
- * Does nothing when the compiled hook is absent, which is the case only when
13
- * the SDK runs from its TypeScript source under the test runner. The runner
14
- * resolves imports itself, so no hook is needed there.
13
+ * Does nothing when the SDK runs from its TypeScript source under the test
14
+ * runner, which resolves imports itself. Anywhere else a missing hook means the
15
+ * SDK was bundled: authored source would then load a second copy of the
16
+ * package, its expressions would fail this copy's `instanceof` checks, and the
17
+ * `.flow` would come out wrong with no error. That throws instead.
15
18
  */
16
19
  export function useThisSdkForAuthoredSource() {
17
20
  if (registered)
18
21
  return;
19
- registered = true;
20
22
  const hook = new URL('./sdk-resolve-hook.js', import.meta.url);
21
- if (!existsSync(fileURLToPath(hook)))
22
- return;
23
+ if (!existsSync(fileURLToPath(hook))) {
24
+ if (import.meta.url.endsWith('.ts')) {
25
+ registered = true;
26
+ return;
27
+ }
28
+ throw new Error(`cannot point authored source at this copy of ${PACKAGE_NAME}: ${fileURLToPath(hook)} is missing, as in a bundle, `
29
+ + 'so its imports would load a second copy and serialize wrong. Run the installed package, or load authored source yourself.');
30
+ }
23
31
  register(hook);
32
+ registered = true;
24
33
  }
package/dist/serialize.js CHANGED
@@ -6,9 +6,7 @@
6
6
  * resolved from the connector library (entry + v1def sidecar), matching what
7
7
  * the platform emits, so the result passes `uip maestro flow validate`.
8
8
  */
9
- import { readFileSync } from 'node:fs';
10
- import { fileURLToPath } from 'node:url';
11
- import { dirname, join } from 'node:path';
9
+ import ixpDefinition from './ixp-definition.json' with { type: 'json' };
12
10
  import { BUNDLED_DEFINITIONS, bundledVersions } from './flow-definitions.js';
13
11
  import { Expr, toExpr, SCHEDULE_PRESETS, parseIxpProjectType, flatNameOf, flatNameSegmentsOf } from './flow-sdk.js';
14
12
  import { FlowAction, FlowTrigger } from './core/node-classes.js';
@@ -65,7 +63,6 @@ import { types } from './core/expr.js';
65
63
  import { SUBFLOW_START_LABEL } from './core/subflow-start.js';
66
64
  import { ownEntry } from './core/own-entry.js';
67
65
  import { jsonClone } from './core/json-file.js';
68
- const HERE = dirname(fileURLToPath(import.meta.url));
69
66
  // core-definitions.json is an object keyed by "<nodeType>@<version>".
70
67
  const DEFS = BUNDLED_DEFINITIONS;
71
68
  // FIRST occurrence wins: with multiple bundled versions of one family (HITL
@@ -2592,7 +2589,7 @@ function promptTokens(content) {
2592
2589
  * ["fileRef"]` (the pre-pull answer) instead of the three the platform's
2593
2590
  * `ixp-node` validator actually enforces.
2594
2591
  */
2595
- const IXP_DEF = JSON.parse(readFileSync(join(HERE, 'ixp-definition.json'), 'utf8'));
2592
+ const IXP_DEF = ixpDefinition;
2596
2593
  /**
2597
2594
  * Build the definition for one published IxP project.
2598
2595
  *
@@ -6171,8 +6168,12 @@ export function serialize(built, opts = {}) {
6171
6168
  // must leave from ITS handles), else positional (#1130).
6172
6169
  const cases = step.cases.map((c, i) => ({
6173
6170
  id: c.id ?? `case_${i + 1}`,
6174
- label: c.label ?? `Case ${caseLiteral(c.value)}`,
6175
- expression: `${renameRefs(step.on.js, scope.rename)} === ${caseLiteral(c.value)}`,
6171
+ // A `when` case writes its own condition — the product's per-case form,
6172
+ // first truthy case wins (#1131). A `value` case compares with `on`.
6173
+ label: c.label ?? (c.when !== undefined ? `Case ${i + 1}` : `Case ${caseLiteral(c.value)}`),
6174
+ expression: c.when !== undefined
6175
+ ? renameRefs(c.when.js, scope.rename)
6176
+ : `${renameRefs(step.on?.js ?? 'undefined', scope.rename)} === ${caseLiteral(c.value)}`,
6176
6177
  }));
6177
6178
  node.inputs = { cases, hasDefault: step.default !== undefined };
6178
6179
  scope.nodes.push(node);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.26.0",
3
+ "version": "6.27.1",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -92,5 +92,5 @@
92
92
  "@types/node": "^22.7.0",
93
93
  "esbuild": "^0.28.1"
94
94
  },
95
- "gitref": "6f62b8136efeafdce6dde0429c7d98a59a4661d2"
95
+ "gitref": "c635f8993b10e795715c85109080ec8e2e2f28d2"
96
96
  }