@uipath/maestro-builder-sdk 6.122.7 → 6.122.8

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/check-cli.js CHANGED
@@ -22,7 +22,7 @@ import { readCliResources } from './registry/prepare/resources.js';
22
22
  import { resolveFlowFile, loadBuiltFlow } from './load.js';
23
23
  import { check, checkCompiled, scopeToEdit } from './check.js';
24
24
  import { flowCheckOpts } from './cli-library.js';
25
- import { readNodeCatalog } from './node-catalog-files.js';
25
+ import { currentNodeCatalog, NODE_CACHE_SCOPE_ENV, readNodeCatalog } from './node-catalog-files.js';
26
26
  import { withFetchedDefinitions } from './registry/fetch/with-fetched-definitions.js';
27
27
  import { Bindings } from './bindings.js';
28
28
  import { flagValue, flagValues, runWhenInvokedDirectly } from './cli-run.js';
@@ -57,8 +57,18 @@ function checkOpts(argv, library, solution) {
57
57
  // as still owed — telling the author to re-run a `prepare` they already ran.
58
58
  // The resource ledger `prepare` writes, the default found as bindings.json is.
59
59
  const resources = readCliResources(argv, defaultResourcesFile());
60
- // The node registry cache a manifest-less `rawNode` resolves from (#1981), read on first use.
61
- return { ...flowCheckOpts(library, bindings), ...(resources ? { resources } : {}), nodeCatalog: readNodeCatalog(), ...(solution ? { solution } : {}), scriptTypes: true };
60
+ // The node registry cache a manifest-less `rawNode` resolves from (#1981), read on first use;
61
+ // and, only when `uip` names the tenant the cache belongs to, the current manifests
62
+ // HANDLE_NOT_IN_CURRENT_MANIFEST checks edges against.
63
+ const current = currentNodeCatalog(process.env[NODE_CACHE_SCOPE_ENV]);
64
+ // Say when the tenant handle check did not run, so a clean result is not read as a pass on it.
65
+ if ('skipped' in current)
66
+ console.error(`check: HANDLE_NOT_IN_CURRENT_MANIFEST did not run: ${current.skipped}.`);
67
+ const tenantCatalog = 'catalog' in current ? current.catalog : undefined;
68
+ return {
69
+ ...flowCheckOpts(library, bindings), ...(resources ? { resources } : {}), nodeCatalog: readNodeCatalog(),
70
+ ...(tenantCatalog ? { currentNodeCatalog: tenantCatalog } : {}), ...(solution ? { solution } : {}), scriptTypes: true,
71
+ };
62
72
  }
63
73
  export async function run(argv) {
64
74
  const arg = argv.find((a, i) => !a.startsWith('--') && !VALUE_FLAGS.has(argv[i - 1])) ?? argv[0];
package/dist/check.d.ts CHANGED
@@ -94,6 +94,15 @@ export interface CheckOpts extends ConnectorCheckOpts, EventCheckOpts {
94
94
  * a step is `RAW_NODE_MANIFEST_NOT_CACHED`, as `compile` would say.
95
95
  */
96
96
  nodeCatalog?: NodeCatalog;
97
+ /**
98
+ * The node catalog verified to be the current tenant's manifests, which
99
+ * HANDLE_NOT_IN_CURRENT_MANIFEST judges edges against. Separate from
100
+ * `nodeCatalog`: a cache from another tenant still resolves a `rawNode`'s
101
+ * manifest, but must not reject a valid edge. The CLI passes one only when
102
+ * `uip` names the logged-in tenant and the cache provably belongs to it
103
+ * (`readCurrentNodeCatalog`). Without one the rule is silent.
104
+ */
105
+ currentNodeCatalog?: NodeCatalog;
97
106
  /** `false` skips the serializer pass, for a caller that compiles the flow itself (`merge`). */
98
107
  serializer?: false;
99
108
  /**
package/dist/check.js CHANGED
@@ -33,6 +33,7 @@ import { refusalClass } from './core/refusals.js';
33
33
  import { classifyDrafts, placeDiagnostics } from './edit-scope.js';
34
34
  import { preExistingFindings, scopeFindings } from './core/baseline-scope.js';
35
35
  import { lookupConnectionIndex } from './core/lookup-connection.js';
36
+ import { staleHandles } from './core/current-manifest-handles.js';
36
37
  export function check(built, opts = {}) {
37
38
  return checkCompiled(built, opts).diagnostics;
38
39
  }
@@ -65,6 +66,7 @@ export function checkCompiled(built, opts = {}) {
65
66
  diags.push(...serialized.diagnostics);
66
67
  if (serialized.flow !== undefined)
67
68
  diags.push(...mergeNeverCompletes(serialized.flow, serialized.scopes ?? []));
69
+ diags.push(...staleHandleDiagnostics(serialized.flow, opts.currentNodeCatalog));
68
70
  const placed = serialized.flow !== undefined ? placeDiagnostics(diags, serialized.flow) : undefined;
69
71
  const diagnostics = diags.map((d, i) => {
70
72
  const nodeId = d.nodeId ?? (placed?.[i].nodeId || undefined);
@@ -73,6 +75,22 @@ export function checkCompiled(built, opts = {}) {
73
75
  });
74
76
  return { diagnostics, flow: serialized.flow, ...(serialized.stoppedAt ? { stoppedAt: serialized.stoppedAt } : {}) };
75
77
  }
78
+ /**
79
+ * HANDLE_NOT_IN_CURRENT_MANIFEST: an edge of the compiled flow on a handle the
80
+ * current tenant's manifest for its node does not declare
81
+ * (`core/current-manifest-handles.ts`). Silent without a verified catalog.
82
+ */
83
+ function staleHandleDiagnostics(compiled, catalog) {
84
+ return staleHandles(compiled, catalog).map((s) => ({
85
+ level: 'error', code: 'HANDLE_NOT_IN_CURRENT_MANIFEST', nodeId: s.nodeId,
86
+ message: `Edge "${s.edgeId}"${s.subflow !== undefined ? ` in subflow "${s.subflow}"` : ''} uses ${s.side} handle "${s.port}" on node "${s.nodeId}", `
87
+ + `but the tenant's current manifest for ${s.nodeType}@${s.version} (${catalog?.source ?? 'the node registry cache'}) does not declare it. `
88
+ + `The SDK's bundled definition still has it, so the .flow is consistent with itself, but Studio Web renders the node from the tenant's manifest `
89
+ + `and draws this edge as missing; \`uip maestro flow validate\` fails it. Declared ${s.side} handles: ${s.available}.`,
90
+ suggestion: `Remove what wires the "${s.port}" handle, or author against a version the tenant serves with it `
91
+ + `(\`uip maestro flow registry get ${s.nodeType}\`). If the cache is old, refresh it with \`uip maestro flow registry pull --force\`.`,
92
+ }));
93
+ }
76
94
  /**
77
95
  * The canvas's script type complaints on the script bodies of one flow level (the code
78
96
  * sites its node types declare), one warning each (`script-type-check.ts`).
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Edges on a handle the current tenant's manifest does not declare
3
+ * (`HANDLE_NOT_IN_CURRENT_MANIFEST`). A `.flow` embeds each node's definition
4
+ * when it is compiled, but Studio Web renders the node from the tenant's
5
+ * manifest, which can declare different handles at the same version; an edge
6
+ * on a handle it lacks is drawn as missing. `uip maestro flow validate` runs
7
+ * the same rule (`validateEdgeHandlesAgainstCurrentManifests`), so this
8
+ * matches it:
9
+ *
10
+ * - Only nodes whose `typeVersion` the catalog holds are checked, comparing
11
+ * versions with trailing `.0`s dropped (`1.0.0` is `1.0`).
12
+ * - A side is enforced only when the manifest declares a handle on it.
13
+ * - `repeat` handles expand over the node's inputs; one that cannot expand
14
+ * matches as a pattern.
15
+ * - `supportsErrorHandling: true` adds the implicit `error` source port.
16
+ * - `handleCustomization` replaces source handles group by group, by position.
17
+ *
18
+ * Pure (FB015): the catalog is passed in, and without one nothing is checked.
19
+ */
20
+ import type { NodeCatalog } from './node-catalog.js';
21
+ /** One edge on a handle the current manifest does not declare. */
22
+ export interface StaleHandle {
23
+ edgeId: string;
24
+ /** The node whose manifest lacks the handle (the edge's source or target node). */
25
+ nodeId: string;
26
+ nodeType: string;
27
+ version: string;
28
+ side: 'source' | 'target';
29
+ port: string;
30
+ /** The handles the manifest does declare on that side, as `a, b, case-{item.id}`. */
31
+ available: string;
32
+ /** Which subflow the edge is in; absent for the root graph. */
33
+ subflow?: string;
34
+ }
35
+ /**
36
+ * Every edge of `flow` (root graph and each subflow) on a handle the catalog's
37
+ * manifest for its node does not declare. Empty without a catalog.
38
+ *
39
+ * ```ts
40
+ * staleHandles(compiled, catalog)
41
+ * // → [{ edgeId: 'ask-memory', nodeId: 'ask', nodeType: 'uipath.agent.autonomous', version: '1.4',
42
+ * // side: 'source', port: 'memory', available: 'success, error, tool, context, escalation' }]
43
+ * ```
44
+ */
45
+ export declare function staleHandles(flow: unknown, catalog: NodeCatalog | undefined): StaleHandle[];
46
+ /** `1.0.0` → `1.0`, `1.4` → `1.4`: trailing `.0`s past the minor dropped, as validate compares versions. */
47
+ export declare function normalizeNodeVersion(version: string): string;
48
+ /**
49
+ * `port` against a templated id: each `{…}` stands for one or more characters
50
+ * other than a line break, and the rest matches literally.
51
+ *
52
+ * ```ts
53
+ * portMatchesTemplate('case-q1', 'case-{item.id}'); // → true
54
+ * portMatchesTemplate('case-', 'case-{item.id}'); // → false
55
+ * ```
56
+ */
57
+ export declare function portMatchesTemplate(port: string, template: string): boolean;
@@ -0,0 +1,215 @@
1
+ import { isRecord } from './node-envelope.js';
2
+ /**
3
+ * Every edge of `flow` (root graph and each subflow) on a handle the catalog's
4
+ * manifest for its node does not declare. Empty without a catalog.
5
+ *
6
+ * ```ts
7
+ * staleHandles(compiled, catalog)
8
+ * // → [{ edgeId: 'ask-memory', nodeId: 'ask', nodeType: 'uipath.agent.autonomous', version: '1.4',
9
+ * // side: 'source', port: 'memory', available: 'success, error, tool, context, escalation' }]
10
+ * ```
11
+ */
12
+ export function staleHandles(flow, catalog) {
13
+ if (catalog === undefined || !isRecord(flow))
14
+ return [];
15
+ const out = [];
16
+ const graphs = [[undefined, asGraph(flow)]];
17
+ if (isRecord(flow.subflows)) {
18
+ for (const [id, sub] of Object.entries(flow.subflows))
19
+ graphs.push([id, asGraph(sub)]);
20
+ }
21
+ for (const [subflow, graph] of graphs)
22
+ out.push(...graphStaleHandles(graph, catalog, subflow));
23
+ return out;
24
+ }
25
+ function asGraph(v) {
26
+ const g = isRecord(v) ? v : {};
27
+ return { nodes: Array.isArray(g.nodes) ? g.nodes : [], edges: Array.isArray(g.edges) ? g.edges : [] };
28
+ }
29
+ function graphStaleHandles(graph, catalog, subflow) {
30
+ const nodes = new Map();
31
+ for (const node of graph.nodes) {
32
+ if (!isRecord(node) || typeof node.id !== 'string' || typeof node.type !== 'string')
33
+ continue;
34
+ const version = typeof node.typeVersion === 'string' ? node.typeVersion : '1.0.0';
35
+ const manifest = currentManifest(catalog, node.type, version);
36
+ if (manifest === undefined)
37
+ continue;
38
+ nodes.set(node.id, { type: node.type, version, handles: manifestHandles(manifest, node) });
39
+ }
40
+ const out = [];
41
+ for (const edge of graph.edges) {
42
+ if (!isRecord(edge) || typeof edge.id !== 'string')
43
+ continue;
44
+ for (const side of ['source', 'target']) {
45
+ const nodeId = edge[`${side}NodeId`];
46
+ const port = edge[`${side}Port`];
47
+ if (typeof nodeId !== 'string' || typeof port !== 'string')
48
+ continue;
49
+ const node = nodes.get(nodeId);
50
+ if (node === undefined || !enforced(node.handles, side) || declares(node.handles, side, port))
51
+ continue;
52
+ out.push({
53
+ edgeId: edge.id, nodeId, nodeType: node.type, version: node.version, side, port,
54
+ available: availableHandles(node.handles, side),
55
+ ...(subflow !== undefined ? { subflow } : {}),
56
+ });
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+ /** `1.0.0` → `1.0`, `1.4` → `1.4`: trailing `.0`s past the minor dropped, as validate compares versions. */
62
+ export function normalizeNodeVersion(version) {
63
+ const parts = version.split('.');
64
+ if (!parts.every((p) => /^\d+$/.test(p)))
65
+ return version;
66
+ while (parts.length > 2 && parts[parts.length - 1] === '0')
67
+ parts.pop();
68
+ return parts.join('.');
69
+ }
70
+ /** The catalog's manifest for `nodeType` at `version`, matching versions as {@link normalizeNodeVersion} does. */
71
+ function currentManifest(catalog, nodeType, version) {
72
+ const want = normalizeNodeVersion(version);
73
+ const held = catalog.versions(nodeType).find((v) => normalizeNodeVersion(v) === want);
74
+ const manifest = held !== undefined ? catalog.definition(nodeType, held) : undefined;
75
+ return isRecord(manifest) ? manifest : undefined;
76
+ }
77
+ function manifestHandles(manifest, node) {
78
+ const h = { source: new Map(), target: new Map(), sourceTemplates: [], targetTemplates: [], sourceDeclared: false };
79
+ const groups = Array.isArray(manifest.handleConfiguration) ? manifest.handleConfiguration : [];
80
+ for (const group of groups) {
81
+ if (!isRecord(group) || !Array.isArray(group.handles))
82
+ continue;
83
+ const position = typeof group.position === 'string' ? group.position : undefined;
84
+ for (const handle of group.handles) {
85
+ if (!isRecord(handle) || typeof handle.id !== 'string')
86
+ continue;
87
+ if (handle.type !== 'source' && handle.type !== 'target')
88
+ continue;
89
+ for (const id of expandHandleIds(handle.id, handle.repeat, node)) {
90
+ if (id.includes('{'))
91
+ (handle.type === 'source' ? h.sourceTemplates : h.targetTemplates).push({ id, position });
92
+ else
93
+ (handle.type === 'source' ? h.source : h.target).set(id, position);
94
+ }
95
+ }
96
+ }
97
+ // As validate counts it: a handle from a positioned group, or any template.
98
+ h.sourceDeclared = [...h.source.values()].some((p) => p !== undefined) || h.sourceTemplates.length > 0;
99
+ if (manifest.supportsErrorHandling === true && !h.source.has('error'))
100
+ h.source.set('error', undefined);
101
+ if (h.sourceDeclared)
102
+ applyHandleCustomization(h, node);
103
+ return h;
104
+ }
105
+ /**
106
+ * `id` once per item of the array at `repeat` (a path from the node, such as
107
+ * `inputs.cases`), each `{item.<key>}` replaced by the item's value. The bare
108
+ * template when `repeat` does not name an array (an expression): it then
109
+ * matches as a pattern ({@link portMatchesTemplate}).
110
+ */
111
+ function expandHandleIds(id, repeat, node) {
112
+ if (typeof repeat !== 'string' || repeat === '')
113
+ return [id];
114
+ let items = node;
115
+ for (const seg of repeat.split('.'))
116
+ items = isRecord(items) ? items[seg] : undefined;
117
+ if (!Array.isArray(items))
118
+ return [id];
119
+ return items.filter(isRecord).map((item) => id.replace(/\{item\.(\w+)\}/g, (_m, key) => String(item[key] ?? '')));
120
+ }
121
+ /**
122
+ * The node's `handleCustomization` (`{ groups: [{ position, handles }] }`)
123
+ * replaces the manifest's source handles in each group it names by position;
124
+ * groups at other positions, and ports with no position (`error`), stay. A
125
+ * customization with no source handle replaces nothing.
126
+ */
127
+ function applyHandleCustomization(h, node) {
128
+ const custom = node.handleCustomization;
129
+ if (!isRecord(custom) || !Array.isArray(custom.groups))
130
+ return;
131
+ const positions = new Set();
132
+ const ids = [];
133
+ for (const group of custom.groups) {
134
+ if (!isRecord(group))
135
+ continue;
136
+ if (typeof group.position === 'string')
137
+ positions.add(group.position);
138
+ for (const handle of Array.isArray(group.handles) ? group.handles : []) {
139
+ if (isRecord(handle) && handle.type === 'source' && typeof handle.id === 'string')
140
+ ids.push(handle.id);
141
+ }
142
+ }
143
+ if (ids.length === 0)
144
+ return;
145
+ const replaced = (position) => position !== undefined && positions.has(position);
146
+ for (const [id, position] of [...h.source])
147
+ if (replaced(position))
148
+ h.source.delete(id);
149
+ h.sourceTemplates = h.sourceTemplates.filter((t) => !replaced(t.position));
150
+ for (const id of ids)
151
+ h.source.set(id, undefined);
152
+ }
153
+ function enforced(h, side) {
154
+ return side === 'source' ? h.sourceDeclared : h.target.size + h.targetTemplates.length > 0;
155
+ }
156
+ function declares(h, side, port) {
157
+ if ((side === 'source' ? h.source : h.target).has(port))
158
+ return true;
159
+ return (side === 'source' ? h.sourceTemplates : h.targetTemplates).some((t) => portMatchesTemplate(port, t.id));
160
+ }
161
+ function availableHandles(h, side) {
162
+ const ids = [...(side === 'source' ? h.source : h.target).keys(), ...(side === 'source' ? h.sourceTemplates : h.targetTemplates).map((t) => t.id)];
163
+ return ids.length > 0 ? ids.join(', ') : '(none)';
164
+ }
165
+ /**
166
+ * `port` against a templated id: each `{…}` stands for one or more characters
167
+ * other than a line break, and the rest matches literally.
168
+ *
169
+ * ```ts
170
+ * portMatchesTemplate('case-q1', 'case-{item.id}'); // → true
171
+ * portMatchesTemplate('case-', 'case-{item.id}'); // → false
172
+ * ```
173
+ */
174
+ export function portMatchesTemplate(port, template) {
175
+ if (!template.includes('{'))
176
+ return port === template;
177
+ const parts = templateLiterals(template);
178
+ const first = parts[0];
179
+ const last = parts[parts.length - 1];
180
+ if (parts.length === 1)
181
+ return port === first;
182
+ if (!port.startsWith(first) || !port.endsWith(last))
183
+ return false;
184
+ // Each literal at its leftmost fit leaves the most room for the rest, so one
185
+ // forward pass decides the match (linear in the port; no regex backtracking).
186
+ const lastStart = port.length - last.length;
187
+ let gapStart = first.length;
188
+ for (const lit of parts.slice(1, -1)) {
189
+ const at = port.indexOf(lit, gapStart + 1);
190
+ if (at === -1 || hasLineBreak(port, gapStart, at))
191
+ return false;
192
+ gapStart = at + lit.length;
193
+ }
194
+ return gapStart < lastStart && !hasLineBreak(port, gapStart, lastStart);
195
+ }
196
+ /** The literal segments between a template's `{…}` placeholders; an unclosed `{` is literal. */
197
+ function templateLiterals(template) {
198
+ const parts = [];
199
+ let start = 0;
200
+ for (let open = template.indexOf('{'); open !== -1; open = template.indexOf('{', start)) {
201
+ const close = template.indexOf('}', open + 1);
202
+ if (close === -1)
203
+ break;
204
+ parts.push(template.slice(start, open));
205
+ start = close + 1;
206
+ }
207
+ parts.push(template.slice(start));
208
+ return parts;
209
+ }
210
+ function hasLineBreak(s, from, to) {
211
+ for (let i = from; i < to; i++)
212
+ if ('\n\r\u2028\u2029'.includes(s[i]))
213
+ return true;
214
+ return false;
215
+ }
@@ -17,6 +17,18 @@ export interface NodeCatalog {
17
17
  /** Where the catalog was read from, for messages (`~/.uipath/nodes/index.json`). */
18
18
  readonly source?: string;
19
19
  }
20
+ /**
21
+ * A catalog over `nodes`, the manifests `registry pull` caches: one array, each
22
+ * as `registry get` prints it. `nodes` may be a function, called on the first
23
+ * lookup, so a caller that never looks a node up never reads the cache. A few
24
+ * connector types are listed twice at one version; the first one listed wins.
25
+ *
26
+ * ```ts
27
+ * const catalog = nodeCatalogOf([{ nodeType: 'core.logic.decision', version: '1.4', handleConfiguration: [] }]);
28
+ * catalog.versions('core.logic.decision'); // → ['1.4']
29
+ * ```
30
+ */
31
+ export declare function nodeCatalogOf(nodes: readonly unknown[] | (() => readonly unknown[]), source?: string): NodeCatalog;
20
32
  /** What a `rawNode` with no `manifest` resolves to: the manifest, or why there is none. */
21
33
  export type CatalogLookup = {
22
34
  manifest: unknown;
@@ -8,6 +8,41 @@
8
8
  * `node:` builtin (FB015), so the CLI loads it (`node-catalog-files.ts`) and
9
9
  * passes it in as `SerializeOpts.nodeCatalog` / `CheckOpts.nodeCatalog`.
10
10
  */
11
+ import { isRecord } from './node-envelope.js';
12
+ /**
13
+ * A catalog over `nodes`, the manifests `registry pull` caches: one array, each
14
+ * as `registry get` prints it. `nodes` may be a function, called on the first
15
+ * lookup, so a caller that never looks a node up never reads the cache. A few
16
+ * connector types are listed twice at one version; the first one listed wins.
17
+ *
18
+ * ```ts
19
+ * const catalog = nodeCatalogOf([{ nodeType: 'core.logic.decision', version: '1.4', handleConfiguration: [] }]);
20
+ * catalog.versions('core.logic.decision'); // → ['1.4']
21
+ * ```
22
+ */
23
+ export function nodeCatalogOf(nodes, source) {
24
+ let byType;
25
+ const index = () => {
26
+ if (byType !== undefined)
27
+ return byType;
28
+ byType = new Map();
29
+ for (const node of typeof nodes === 'function' ? nodes() : nodes) {
30
+ if (!isRecord(node) || typeof node.nodeType !== 'string' || typeof node.version !== 'string')
31
+ continue;
32
+ let versions = byType.get(node.nodeType);
33
+ if (versions === undefined)
34
+ byType.set(node.nodeType, versions = new Map());
35
+ if (!versions.has(node.version))
36
+ versions.set(node.version, node);
37
+ }
38
+ return byType;
39
+ };
40
+ return {
41
+ ...(source !== undefined ? { source } : {}),
42
+ definition: (nodeType, version) => index().get(nodeType)?.get(version),
43
+ versions: (nodeType) => [...(index().get(nodeType)?.keys() ?? [])],
44
+ };
45
+ }
11
46
  /**
12
47
  * Look `nodeType@version` up in `catalog`, wording the miss so the author
13
48
  * knows the command that fills the cache (`uip maestro flow registry pull`)
@@ -417,6 +417,7 @@ export declare const REFUSALS: {
417
417
  readonly GUARDRAIL_NO_SCOPE: "lint";
418
418
  readonly GUARDRAIL_NO_VALIDATOR: "lint";
419
419
  readonly GUARDRAIL_TYPE_UNKNOWN: "lint";
420
+ readonly HANDLE_NOT_IN_CURRENT_MANIFEST: "lint";
420
421
  readonly HITL_APP_INCOMPLETE: "lowering";
421
422
  readonly HITL_APP_INPUT_REQUIRED: "lint";
422
423
  readonly HITL_APP_INPUT_UNKNOWN: "lint";
@@ -493,6 +493,9 @@ export const REFUSALS = {
493
493
  GUARDRAIL_NO_SCOPE: 'lint',
494
494
  GUARDRAIL_NO_VALIDATOR: 'lint',
495
495
  GUARDRAIL_TYPE_UNKNOWN: 'lint',
496
+ // An edge on a handle the tenant's current manifest drops (core/current-manifest-handles.ts):
497
+ // compile writes the edge the source asks for; only check, given the node catalog, sees the tenant disagree.
498
+ HANDLE_NOT_IN_CURRENT_MANIFEST: 'lint',
496
499
  HITL_APP_INCOMPLETE: 'lowering',
497
500
  HITL_APP_INPUT_REQUIRED: 'lint',
498
501
  HITL_APP_INPUT_UNKNOWN: 'lint',
@@ -1,4 +1,4 @@
1
- import type { NodeCatalog } from './core/node-catalog.js';
1
+ import { type NodeCatalog } from './core/node-catalog.js';
2
2
  /** The cache `uip maestro flow registry pull` writes. */
3
3
  export declare function defaultNodeCatalogFile(): string;
4
4
  /**
@@ -7,3 +7,37 @@ export declare function defaultNodeCatalogFile(): string;
7
7
  * reports the miss and names `registry pull`.
8
8
  */
9
9
  export declare function readNodeCatalog(file?: string): NodeCatalog;
10
+ /**
11
+ * The environment variable `uip maestro flow check` sets to the node-cache
12
+ * scope of the tenant it is logged in to (`<base URL>|<org id>|<tenant id>`,
13
+ * lower-cased, as `index.meta.json` records it).
14
+ */
15
+ export declare const NODE_CACHE_SCOPE_ENV = "FLOW_SDK_NODE_CACHE_SCOPE";
16
+ /** How long a node cache counts as current: the TTL `uip maestro flow registry get/search` use. */
17
+ export declare const CURRENT_NODE_CACHE_TTL_MS: number;
18
+ /**
19
+ * The node catalog in `file` when it provably holds the current tenant's
20
+ * manifests, or why not. It has to:
21
+ *
22
+ * - be named: `scope` is the logged-in tenant's scope, which only `uip` knows;
23
+ * - be that tenant's: the sibling `index.meta.json` records the same scope,
24
+ * so a cache pulled on another tenant or environment is never "current";
25
+ * - be complete: the metadata's `hash` is the sha256 of `index.json`, so an
26
+ * index another login replaced after the metadata was read does not pass;
27
+ * - be fresh: pulled within {@link CURRENT_NODE_CACHE_TTL_MS}, so an old
28
+ * snapshot cannot reject a handle the tenant serves today. Nothing here
29
+ * refetches; the next `registry pull` makes it current again.
30
+ *
31
+ * `HANDLE_NOT_IN_CURRENT_MANIFEST` runs only on such a catalog. A `rawNode`
32
+ * still resolves from {@link readNodeCatalog}, which needs no tenant.
33
+ *
34
+ * @example
35
+ * currentNodeCatalog(undefined); // { skipped: 'uip named no logged-in tenant …' }
36
+ */
37
+ export declare function currentNodeCatalog(scope: string | undefined, file?: string, now?: number): {
38
+ catalog: NodeCatalog;
39
+ } | {
40
+ skipped: string;
41
+ };
42
+ /** {@link currentNodeCatalog}'s catalog, or `undefined` when it was skipped. */
43
+ export declare function readCurrentNodeCatalog(scope: string | undefined, file?: string, now?: number): NodeCatalog | undefined;
@@ -11,9 +11,11 @@
11
11
  * read on the first lookup, not when the catalog is opened: a flow with no
12
12
  * manifest-less `rawNode` never reads it.
13
13
  */
14
+ import { createHash } from 'node:crypto';
14
15
  import { readFileSync } from 'node:fs';
15
16
  import { homedir } from 'node:os';
16
- import { join } from 'node:path';
17
+ import { dirname, join } from 'node:path';
18
+ import { nodeCatalogOf } from './core/node-catalog.js';
17
19
  import { isRecord } from './core/node-envelope.js';
18
20
  /** The cache `uip maestro flow registry pull` writes. */
19
21
  export function defaultNodeCatalogFile() {
@@ -25,28 +27,80 @@ export function defaultNodeCatalogFile() {
25
27
  * reports the miss and names `registry pull`.
26
28
  */
27
29
  export function readNodeCatalog(file = defaultNodeCatalogFile()) {
28
- let byType;
29
- const index = () => {
30
- if (byType !== undefined)
31
- return byType;
32
- byType = new Map();
33
- for (const node of cachedNodes(file)) {
34
- if (!isRecord(node) || typeof node.nodeType !== 'string' || typeof node.version !== 'string')
35
- continue;
36
- let versions = byType.get(node.nodeType);
37
- if (versions === undefined)
38
- byType.set(node.nodeType, versions = new Map());
39
- // A few connector types are listed twice at one version (a rawNode refuses those anyway); keep the first.
40
- if (!versions.has(node.version))
41
- versions.set(node.version, node);
42
- }
43
- return byType;
44
- };
45
- return {
46
- source: file.startsWith(homedir()) ? `~${file.slice(homedir().length)}` : file,
47
- definition: (nodeType, version) => index().get(nodeType)?.get(version),
48
- versions: (nodeType) => [...(index().get(nodeType)?.keys() ?? [])],
49
- };
30
+ // Read on the first lookup, not here: a flow with no lookup never pays for the ~20 MB file.
31
+ return nodeCatalogOf(() => cachedNodes(file), file.startsWith(homedir()) ? `~${file.slice(homedir().length)}` : file);
32
+ }
33
+ /**
34
+ * The environment variable `uip maestro flow check` sets to the node-cache
35
+ * scope of the tenant it is logged in to (`<base URL>|<org id>|<tenant id>`,
36
+ * lower-cased, as `index.meta.json` records it).
37
+ */
38
+ export const NODE_CACHE_SCOPE_ENV = 'FLOW_SDK_NODE_CACHE_SCOPE';
39
+ /** How long a node cache counts as current: the TTL `uip maestro flow registry get/search` use. */
40
+ export const CURRENT_NODE_CACHE_TTL_MS = 30 * 60 * 1000;
41
+ /**
42
+ * The node catalog in `file` when it provably holds the current tenant's
43
+ * manifests, or why not. It has to:
44
+ *
45
+ * - be named: `scope` is the logged-in tenant's scope, which only `uip` knows;
46
+ * - be that tenant's: the sibling `index.meta.json` records the same scope,
47
+ * so a cache pulled on another tenant or environment is never "current";
48
+ * - be complete: the metadata's `hash` is the sha256 of `index.json`, so an
49
+ * index another login replaced after the metadata was read does not pass;
50
+ * - be fresh: pulled within {@link CURRENT_NODE_CACHE_TTL_MS}, so an old
51
+ * snapshot cannot reject a handle the tenant serves today. Nothing here
52
+ * refetches; the next `registry pull` makes it current again.
53
+ *
54
+ * `HANDLE_NOT_IN_CURRENT_MANIFEST` runs only on such a catalog. A `rawNode`
55
+ * still resolves from {@link readNodeCatalog}, which needs no tenant.
56
+ *
57
+ * @example
58
+ * currentNodeCatalog(undefined); // { skipped: 'uip named no logged-in tenant …' }
59
+ */
60
+ export function currentNodeCatalog(scope, file = defaultNodeCatalogFile(), now = Date.now()) {
61
+ if (scope === undefined || scope.trim() === '') {
62
+ return { skipped: 'uip named no logged-in tenant (run it through `uip maestro flow check` while logged in)' };
63
+ }
64
+ let meta;
65
+ let content;
66
+ try {
67
+ meta = JSON.parse(readFileSync(join(dirname(file), 'index.meta.json'), 'utf8'));
68
+ content = readFileSync(file, 'utf8');
69
+ }
70
+ catch {
71
+ return { skipped: 'there is no node cache (run `uip maestro flow registry pull`)' };
72
+ }
73
+ if (!isRecord(meta) || typeof meta.scope !== 'string' || typeof meta.hash !== 'string') {
74
+ return { skipped: 'the node cache has no tenant metadata (run `uip maestro flow registry pull`)' };
75
+ }
76
+ if (meta.scope.toLowerCase() !== scope.trim().toLowerCase()) {
77
+ return { skipped: 'the node cache was pulled for another tenant (run `uip maestro flow registry pull`)' };
78
+ }
79
+ // The age must be known: a finite time, not in the future (a clock moved back), under the TTL.
80
+ const age = typeof meta.lastSync === 'number' && Number.isFinite(meta.lastSync) ? now - meta.lastSync : Number.NaN;
81
+ if (!Number.isFinite(age) || age < 0) {
82
+ return { skipped: "the node cache's pull time is missing, invalid or in the future (run `uip maestro flow registry pull --force`)" };
83
+ }
84
+ if (age >= CURRENT_NODE_CACHE_TTL_MS) {
85
+ return { skipped: 'the node cache is more than 30 minutes old (run `uip maestro flow registry pull`)' };
86
+ }
87
+ if (createHash('sha256').update(content).digest('hex') !== meta.hash) {
88
+ return { skipped: 'the node cache does not match its metadata (a pull may be in progress: run check again; if it persists, run `uip maestro flow registry pull --force`)' };
89
+ }
90
+ let parsed;
91
+ try {
92
+ parsed = JSON.parse(content);
93
+ }
94
+ catch {
95
+ return { skipped: 'the node cache is not valid JSON (run `uip maestro flow registry pull --force`)' };
96
+ }
97
+ const nodes = Array.isArray(parsed) ? parsed : isRecord(parsed) && Array.isArray(parsed.nodes) ? parsed.nodes : [];
98
+ return { catalog: nodeCatalogOf(nodes, file.startsWith(homedir()) ? `~${file.slice(homedir().length)}` : file) };
99
+ }
100
+ /** {@link currentNodeCatalog}'s catalog, or `undefined` when it was skipped. */
101
+ export function readCurrentNodeCatalog(scope, file = defaultNodeCatalogFile(), now = Date.now()) {
102
+ const current = currentNodeCatalog(scope, file, now);
103
+ return 'catalog' in current ? current.catalog : undefined;
50
104
  }
51
105
  /** The manifests in the cache file: an array, or `{ nodes: [...] }`; nothing when absent or unparseable. */
52
106
  function cachedNodes(file) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.122.7",
3
+ "version": "6.122.8",
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",
@@ -126,5 +126,5 @@
126
126
  "@types/node": "^22.7.0",
127
127
  "esbuild": "^0.28.1"
128
128
  },
129
- "gitref": "830b4a8b5f25eb5f2ed3667f2283ab81b423b3c6"
129
+ "gitref": "a368d51e857af55e2abf26df247744a12bfcd983"
130
130
  }