@uipath/maestro-builder-sdk 6.93.6 → 6.93.7

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.
@@ -964,6 +964,9 @@ export interface ScriptTaskOpts extends ActivityOpts {
964
964
  * PO.BpmnEngine returns `{ "response": <whatever the script returned> }` when
965
965
  * `IsVersionAtLeast(version, 2)`. So the script may return any JSON value and
966
966
  * `=result.response` is that value; `=result.Error` is its error slot.
967
+ * `check` reports a row on a v2-or-later task that reads `result` any other way
968
+ * (`=result.severity`, `=result`) as `SCRIPT_RESULT_NOT_RESPONSE`, with the
969
+ * corrected expression (`=result.response.severity`).
967
970
  *
968
971
  * Only a v1 script task spreads the return object's fields, and it must return an
969
972
  * object or the activity throws. This SDK does not emit v1.
@@ -3489,7 +3492,7 @@ export declare class PathBuilder extends ScopeBuilder {
3489
3492
  * bpmn('retrying')
3490
3493
  * .var('ok', 'boolean')
3491
3494
  * .startEvent('start')
3492
- * .scriptTask('attempt', { script: 'return { ok: true };', outputs: { ok: '=result.ok' } })
3495
+ * .scriptTask('attempt', { script: 'return { ok: true };', outputs: { ok: '=result.response.ok' } })
3493
3496
  * .choose('worked', [
3494
3497
  * { when: '=vars.ok == true', body: (b) => b.endEvent('done') },
3495
3498
  * { otherwise: true, body: (b) => b.goto('attempt') },
@@ -2609,7 +2609,7 @@ export class PathBuilder extends ScopeBuilder {
2609
2609
  * bpmn('retrying')
2610
2610
  * .var('ok', 'boolean')
2611
2611
  * .startEvent('start')
2612
- * .scriptTask('attempt', { script: 'return { ok: true };', outputs: { ok: '=result.ok' } })
2612
+ * .scriptTask('attempt', { script: 'return { ok: true };', outputs: { ok: '=result.response.ok' } })
2613
2613
  * .choose('worked', [
2614
2614
  * { when: '=vars.ok == true', body: (b) => b.endEvent('done') },
2615
2615
  * { otherwise: true, body: (b) => b.goto('attempt') },
@@ -1,20 +1,3 @@
1
- /**
2
- * bpmn/check — fast static validation of a BuiltBpmn before serialization.
3
- *
4
- * Surfaces the common Maestro canvas-rule failures early (dangling flow refs,
5
- * duplicate ids, a gateway branch with no condition, a superfluous gateway, an
6
- * implicit join, a missing start event, a boundary event attached to nothing, an
7
- * empty timer) so authoring gets instant feedback. The authoritative gate is
8
- * still `uip maestro bpmn validate` (`validateBpmnCanvas`) on the emitted
9
- * `.bpmn`.
10
- *
11
- * **An `error` here must mirror a real platform rule.** Being stricter than
12
- * `validate` is worse than being looser: it refuses processes that deploy and run
13
- * correctly, and the author has no way to appeal. Where this file is deliberately
14
- * stricter than the platform — an unconditioned inclusive-gateway branch, an
15
- * implicit join — the diagnostic is a `warning`, and its comment says which
16
- * platform rule it corresponds to and how the two differ.
17
- */
18
1
  import type { BuiltBpmn } from './bpmn-sdk.js';
19
2
  import type { Library } from '../core/library.js';
20
3
  import type { ResourceResolutions } from '../core/resource-resolution.js';
@@ -1,3 +1,21 @@
1
+ /**
2
+ * bpmn/check — fast static validation of a BuiltBpmn before serialization.
3
+ *
4
+ * Surfaces the common Maestro canvas-rule failures early (dangling flow refs,
5
+ * duplicate ids, a gateway branch with no condition, a superfluous gateway, an
6
+ * implicit join, a missing start event, a boundary event attached to nothing, an
7
+ * empty timer) so authoring gets instant feedback. The authoritative gate is
8
+ * still `uip maestro bpmn validate` (`validateBpmnCanvas`) on the emitted
9
+ * `.bpmn`.
10
+ *
11
+ * **An `error` here must mirror a real platform rule.** Being stricter than
12
+ * `validate` is worse than being looser: it refuses processes that deploy and run
13
+ * correctly, and the author has no way to appeal. Where this file is deliberately
14
+ * stricter than the platform — an unconditioned inclusive-gateway branch, an
15
+ * implicit join — the diagnostic is a `warning`, and its comment says which
16
+ * platform rule it corresponds to and how the two differ.
17
+ */
18
+ import { parse } from 'acorn';
1
19
  import { checkBpmnExpressions } from './bpmn-expr-check.js';
2
20
  import { allNodes, collectSerializerModel, folderCompanionKeys, implicitNodeVars, processId } from './serialize.js';
3
21
  import { refreshConnectionDiagnostics } from './refresh-connections.js';
@@ -1072,8 +1090,210 @@ function readsBareIdentifier(script, name) {
1072
1090
  const re = new RegExp(`(?<![\\w$.])${name.replace(/\$/g, '\\$')}(?![\\w$])(?!\\s*:)`);
1073
1091
  return re.test(stripped);
1074
1092
  }
1093
+ /** The `result` members a v2+ output may read directly: the wrapper, and the error slot. */
1094
+ const RESULT_MEMBERS = new Set(['response', 'Error']);
1095
+ const isJsNode = (v) => typeof v === 'object' && v !== null && typeof v.type === 'string';
1096
+ /** The child nodes of `node`, in source order. */
1097
+ function jsChildren(node) {
1098
+ const out = [];
1099
+ for (const [field, v] of Object.entries(node)) {
1100
+ if (field === 'type' || field === 'start' || field === 'end')
1101
+ continue;
1102
+ if (Array.isArray(v))
1103
+ for (const item of v) {
1104
+ if (isJsNode(item))
1105
+ out.push(item);
1106
+ }
1107
+ else if (isJsNode(v))
1108
+ out.push(v);
1109
+ }
1110
+ return out;
1111
+ }
1112
+ /** Whether a binding pattern (`result`, `{ a: result }`, `[result = 1]`, `...result`) declares `name`. */
1113
+ function patternBinds(p, name) {
1114
+ switch (p.type) {
1115
+ case 'Identifier': return p.name === name;
1116
+ case 'AssignmentPattern': return patternBinds(p.left, name);
1117
+ case 'RestElement': return patternBinds(p.argument, name);
1118
+ case 'ArrayPattern': return p.elements.some((e) => e !== null && patternBinds(e, name));
1119
+ // A pattern's computed key or default value is an expression, not a binding.
1120
+ case 'ObjectPattern': return p.properties.some((pr) => patternBinds(pr.type === 'RestElement' ? pr : pr.value, name));
1121
+ default: return false;
1122
+ }
1123
+ }
1124
+ const isFunction = (n) => /Function/.test(n.type);
1125
+ /** Whether a `let`/`const`/`var` declaration of the given kinds declares `name`. */
1126
+ function declarationBinds(n, name, kinds) {
1127
+ return isJsNode(n) && n.type === 'VariableDeclaration' && kinds(n.kind)
1128
+ && n.declarations.some((d) => patternBinds(d.id, name));
1129
+ }
1130
+ /** Whether these statements, at the top of one block, declare `name` block-scoped: `let`, `const`, `class` or a function declaration. */
1131
+ function lexicallyBinds(statements, name) {
1132
+ return statements.some((s) => declarationBinds(s, name, (k) => k !== 'var')
1133
+ || ((s.type === 'ClassDeclaration' || s.type === 'FunctionDeclaration') && isJsNode(s.id) && s.id.name === name));
1134
+ }
1135
+ /** Whether a `var` under `node` declares `name` in the function `node` belongs to: nested functions and static blocks are their own `var` scope and are not walked. */
1136
+ function varBinds(node, name) {
1137
+ if (declarationBinds(node, name, (k) => k === 'var'))
1138
+ return true;
1139
+ return jsChildren(node).some((c) => !isFunction(c) && c.type !== 'StaticBlock' && varBinds(c, name));
1140
+ }
1141
+ /**
1142
+ * Whether `node` opens a scope that declares `name`, so every `name` inside it is that
1143
+ * binding, not the outer one. A function: its own name (an expression's), a parameter,
1144
+ * a `var` anywhere in its body outside a nested function, or a block-scoped declaration
1145
+ * at the top of its body. A block, a `switch`, a `for` head or a `catch` parameter: the
1146
+ * declarations scoped to it. A declaration in a nested function shadows only inside that
1147
+ * function, so it is found when the walk reaches that function, never from outside.
1148
+ */
1149
+ function scopeBinds(node, name) {
1150
+ if (isFunction(node)) {
1151
+ if (node.type === 'FunctionExpression' && isJsNode(node.id) && node.id.name === name)
1152
+ return true;
1153
+ if (node.params.some((p) => patternBinds(p, name)))
1154
+ return true;
1155
+ const body = node.body;
1156
+ return body.type === 'BlockStatement' && (varBinds(body, name) || lexicallyBinds(body.body, name));
1157
+ }
1158
+ switch (node.type) {
1159
+ case 'BlockStatement': return lexicallyBinds(node.body, name);
1160
+ case 'StaticBlock': return varBinds(node, name) || lexicallyBinds(node.body, name);
1161
+ case 'SwitchStatement': return lexicallyBinds(node.cases.flatMap((c) => c.consequent), name);
1162
+ case 'CatchClause': return isJsNode(node.param) && patternBinds(node.param, name);
1163
+ case 'ForStatement': return declarationBinds(node.init, name, (k) => k !== 'var');
1164
+ case 'ForInStatement':
1165
+ case 'ForOfStatement': return declarationBinds(node.left, name, (k) => k !== 'var');
1166
+ case 'ClassExpression':
1167
+ case 'ClassDeclaration': return isJsNode(node.id) && node.id.name === name;
1168
+ default: return false;
1169
+ }
1170
+ }
1171
+ /** The string a member selector names: `.response`, `['response']`, `` [`response`] ``; `undefined` for any other. */
1172
+ function memberName(member) {
1173
+ const prop = member.property;
1174
+ if (!member.computed)
1175
+ return prop.type === 'Identifier' ? prop.name : undefined;
1176
+ if (prop.type === 'Literal')
1177
+ return typeof prop.value === 'string' ? prop.value : undefined;
1178
+ const quasis = prop.quasis;
1179
+ return prop.type === 'TemplateLiteral' && quasis?.length === 1 ? quasis[0].value.cooked : undefined;
1180
+ }
1181
+ /**
1182
+ * Where `code` reads the variable `result` other than through `result.response` or
1183
+ * `result.Error`: the span of each such identifier, in source order, and whether it is an object
1184
+ * shorthand (`{ result }`, which needs its key spelled out to be rewritten).
1185
+ *
1186
+ * `code` is parsed (acorn, as the Case checks parse JavaScript), so only real
1187
+ * references count: a property name (`foo.result`), an object key
1188
+ * (`{ result: … }`), a string, template text, regex or comment is none, while a
1189
+ * template's `${…}` hole is code. Optional chaining (`result?.response`,
1190
+ * `result?.['response']`) is the same member read. A scope that declares its own
1191
+ * `result` (a parameter, `var`, `let`, `const`, `class`, function or `catch` binding) is
1192
+ * not looked into, and only that scope: a nested function's declaration does not hide
1193
+ * an outer read. `undefined` when `code` is not one expression.
1194
+ */
1195
+ function resultReads(code) {
1196
+ let program;
1197
+ try {
1198
+ // Parenthesized so `{ … }` is an object, closed on a new line so a trailing `// comment` ends first.
1199
+ program = parse(`(${code}\n)`, { ecmaVersion: 'latest', sourceType: 'script' });
1200
+ }
1201
+ catch {
1202
+ return undefined;
1203
+ }
1204
+ const reads = [];
1205
+ const visit = (node, parent) => {
1206
+ if (node.type === 'Identifier') {
1207
+ if (node.name !== 'result')
1208
+ return;
1209
+ if (parent?.type === 'MemberExpression' && parent.object === node && RESULT_MEMBERS.has(memberName(parent) ?? ''))
1210
+ return;
1211
+ reads.push({ start: node.start - 1, end: node.end - 1, shorthand: parent?.type === 'Property' && parent.shorthand === true });
1212
+ return;
1213
+ }
1214
+ if (scopeBinds(node, 'result'))
1215
+ return;
1216
+ for (const child of jsChildren(node)) {
1217
+ // A name in a property position is not a reference: `a.result`, `{ result: … }`, a
1218
+ // member's name, a label. A shorthand `{ result }` is one too, read through its value.
1219
+ const isName = child === node.key || child === node.property || child === node.label || child === node.meta;
1220
+ if (isName && !node.computed)
1221
+ continue;
1222
+ visit(child, node);
1223
+ }
1224
+ };
1225
+ visit(program, undefined);
1226
+ // The fix splices these left to right, and a node's fields are not guaranteed to come in span order.
1227
+ return reads.sort((a, b) => a.start - b.start);
1228
+ }
1229
+ /**
1230
+ * `source` with every `result` read that skips the v2+ wrapper sent through it
1231
+ * (`=result.severity` → `=result.response.severity`), or `undefined` when there is none
1232
+ * (or the expression does not parse, which is not this check's to report).
1233
+ */
1234
+ function scriptResultThroughResponse(source) {
1235
+ const prefix = /^=(?:js:)?/.exec(source)?.[0];
1236
+ if (prefix === undefined || !/\bresult\b/.test(source))
1237
+ return undefined;
1238
+ const code = source.slice(prefix.length);
1239
+ const reads = resultReads(code);
1240
+ if (!reads?.length)
1241
+ return undefined;
1242
+ let fixed = '';
1243
+ let at = 0;
1244
+ for (const r of reads) {
1245
+ fixed += code.slice(at, r.start) + (r.shorthand ? 'result: result.response' : 'result.response');
1246
+ at = r.end;
1247
+ }
1248
+ return prefix + fixed + code.slice(at);
1249
+ }
1250
+ /** Whether a `uipath:scriptVersion` value is `v2` or later — the versions that wrap the return value. */
1251
+ function wrapsScriptResult(version) {
1252
+ const m = /^v(\d+)$/i.exec(version.trim());
1253
+ return m !== null && Number(m[1]) >= 2;
1254
+ }
1255
+ /**
1256
+ * A script task at `uipath:scriptVersion` v2 or later whose output row reads `result`
1257
+ * other than through `result.response`.
1258
+ *
1259
+ * The runtime wraps a v2-or-later script's return value: `ScriptActivities.DoInvokeScriptTaskAsync`
1260
+ * in PO.BpmnEngine returns `{ "response": <what the script returned> }` when
1261
+ * `IsVersionAtLeast(version, 2)`, so `=result.severity` reads a field the result does not
1262
+ * have and the variable comes back empty. Nothing else notices: `compile` writes the row,
1263
+ * `validate` accepts it and the run completes. Measured in R15 (#1872): two e2e tasks
1264
+ * finished their live runs with empty public outputs from exactly this.
1265
+ *
1266
+ * Only v1 spreads the returned object's fields, so a v1 task (what an absent
1267
+ * `uipath:scriptVersion` means; decompile spells it `'v1'`) is exempt, and a version
1268
+ * this file cannot read is left alone. All 29 script tasks in the real Studio Web
1269
+ * exports (`research/bpmn-roundtrip/FINDINGS.md`, G2) are v3, so an import carrying
1270
+ * this shape was already broken on the platform.
1271
+ */
1272
+ function checkScriptResultReads(n, diags) {
1273
+ if (!wrapsScriptResult(n.scriptVersion))
1274
+ return;
1275
+ const rows = n.outputRows
1276
+ ? n.outputRows.flatMap((r) => (typeof r.source === 'string' ? [{ name: r.name, source: r.source, spelled: 'outputRows' }] : []))
1277
+ : Object.entries(n.outputs).flatMap(([name, source]) => (typeof source === 'string' ? [{ name, source, spelled: 'outputs' }] : []));
1278
+ for (const row of rows) {
1279
+ const fixed = scriptResultThroughResponse(row.source);
1280
+ if (fixed === undefined)
1281
+ continue;
1282
+ diags.push({
1283
+ level: 'error',
1284
+ code: 'SCRIPT_RESULT_NOT_RESPONSE',
1285
+ message: `Script task "${n.id}" output "${row.name}" reads \`${row.source}\`, but a ${n.scriptVersion} script task's ` +
1286
+ `return value arrives wrapped as \`result.response\`, so this reads nothing and the variable comes back empty. ` +
1287
+ `Write \`${fixed}\`.`,
1288
+ where: n.id,
1289
+ suggestion: `In \`${row.spelled}\`, change "${row.name}" to \`${fixed}\`.`,
1290
+ });
1291
+ }
1292
+ }
1075
1293
  /** Retry and loop options, checked per activity. */
1076
1294
  function checkActivityFields(n, diags) {
1295
+ if (n.kind === 'scriptTask')
1296
+ checkScriptResultReads(n, diags);
1077
1297
  // A script task whose body is missing or blank. The wire form of a script task IS its
1078
1298
  // `<bpmn:script>` body, so without one the emitter writes an activity that parses,
1079
1299
  // validates and runs — and does nothing. Every gate stays green: `check` passed, the
@@ -666,6 +666,7 @@ export declare const REFUSALS: {
666
666
  readonly SCRIPT_EMPTY_RETURNS: "lint";
667
667
  readonly SCRIPT_FUNCTION_SCOPE: "lowering";
668
668
  readonly SCRIPT_FUNCTION_UNLOWERABLE: "lowering";
669
+ readonly SCRIPT_RESULT_NOT_RESPONSE: "lint";
669
670
  readonly SCRIPT_RETURNS_UNKNOWN_TYPE: "lint";
670
671
  readonly SCRIPT_TASK_NO_BODY: "lint";
671
672
  readonly SDK_RESOLVE_HOOK_MISSING: "lowering";
@@ -740,6 +740,7 @@ export const REFUSALS = {
740
740
  SCRIPT_EMPTY_RETURNS: 'lint',
741
741
  SCRIPT_FUNCTION_SCOPE: 'lowering',
742
742
  SCRIPT_FUNCTION_UNLOWERABLE: 'lowering',
743
+ SCRIPT_RESULT_NOT_RESPONSE: 'lint',
743
744
  SCRIPT_RETURNS_UNKNOWN_TYPE: 'lint',
744
745
  SCRIPT_TASK_NO_BODY: 'lint',
745
746
  SDK_RESOLVE_HOOK_MISSING: 'lowering',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.93.6",
3
+ "version": "6.93.7",
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",
@@ -111,5 +111,5 @@
111
111
  "@types/node": "^22.7.0",
112
112
  "esbuild": "^0.28.1"
113
113
  },
114
- "gitref": "8d5d725341a2885abea7c13d6e0657d809d4b801"
114
+ "gitref": "9049e7872b34bee80a23919e5a9b3bcf9000fca2"
115
115
  }