@uipath/maestro-builder-sdk 6.120.2 → 6.120.4

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.
@@ -17,6 +17,12 @@ export declare function caseConnectorOwners(plan: Record<string, any>): Array<{
17
17
  key: string;
18
18
  bag: Record<string, any>;
19
19
  }>;
20
+ /**
21
+ * Whether a context row named `name` counts when comparing the element
22
+ * compile built (`bag`) with a saved one: always, except a row in
23
+ * {@link ACTIVITY_SAVED_ONLY_ROWS} on an activity whose built context lacks it.
24
+ */
25
+ export declare function comparesContextRow(bag: Record<string, any>, name: string): boolean;
20
26
  /**
21
27
  * The saved context of a connector element, when it has a `metadata` row with
22
28
  * an object body (the Designer's state) that compile could not have written
@@ -81,6 +81,34 @@ function isEmptyInput(value) {
81
81
  || (Array.isArray(value) && value.length === 0) || (isObject(value) && Object.keys(value).length === 0);
82
82
  }
83
83
  const EVENT_SERVICE_TYPES = new Set(['Intsvc.EventTrigger', 'Intsvc.WaitForEvent']);
84
+ /**
85
+ * Context rows an older Case Designer saves on an `execute-connector-activity`
86
+ * task that compile never writes there (`connectorTaskData` in serialize.ts):
87
+ * `operation` (`list`, `create`, `replace`, `SendEmailV2`, ...), the name of
88
+ * the action the task calls. On an activity it repeats what `objectName`,
89
+ * `method`, `path` and the metadata's activity type id already say, and no
90
+ * source edit can set it, so a saved row that compile's side lacks is no sign
91
+ * of an edit. The saved copy is then the only thing that keeps it.
92
+ *
93
+ * An event element's `operation` is different: compile writes it from the
94
+ * event the source names, so it is compared there as any other row.
95
+ *
96
+ * For instance, a task saved with `objectName: query`, `method: POST`,
97
+ * `path: /hubs/datawarehouse/query` and `operation: list` is the same element
98
+ * as the one compile builds with the first three rows and no `operation`.
99
+ */
100
+ const ACTIVITY_SAVED_ONLY_ROWS = new Set(['operation']);
101
+ /**
102
+ * Whether a context row named `name` counts when comparing the element
103
+ * compile built (`bag`) with a saved one: always, except a row in
104
+ * {@link ACTIVITY_SAVED_ONLY_ROWS} on an activity whose built context lacks it.
105
+ */
106
+ export function comparesContextRow(bag, name) {
107
+ if (!ACTIVITY_SAVED_ONLY_ROWS.has(name) || EVENT_SERVICE_TYPES.has(bag?.serviceType))
108
+ return true;
109
+ const built = Array.isArray(bag?.context) ? bag.context : [];
110
+ return built.some((row) => isObject(row) && row.name === name);
111
+ }
84
112
  const JSON_STRING = '=jsonString:';
85
113
  /** The context row a flagged-V2 plan's connector elements carry (`stampConnectorConfigVersion`). */
86
114
  const V2_CONFIG_ROW = 'activityConfigurationVersion';
@@ -193,7 +221,9 @@ function actionIdentity(context) {
193
221
  * one side only reading as no value. So adding or removing a `folderKey`
194
222
  * row (an edit that adds or drops `folder:`) gets compile's context, while
195
223
  * a Designer row compile never writes and that holds no value (a bare
196
- * `method`) still compares equal. `connectorKey` must be on both sides;
224
+ * `method`) still compares equal, and so does an activity's saved
225
+ * `operation` row, which compile never writes there
226
+ * ({@link comparesContextRow}). `connectorKey` must be on both sides;
197
227
  * - the action is the same: the activity type id agrees, and the wire
198
228
  * activity type is curated on both sides or generic on both, wherever both
199
229
  * sides carry them ({@link actionIdentity}), so switching to an action's
@@ -208,7 +238,7 @@ function unchanged(bag, entry, v2) {
208
238
  if (!builtRows.has('connectorKey') || !saved.has('connectorKey'))
209
239
  return false;
210
240
  for (const name of new Set([...builtRows.keys(), ...saved.keys()])) {
211
- if (name === 'metadata')
241
+ if (name === 'metadata' || (typeof name === 'string' && !comparesContextRow(bag, name)))
212
242
  continue;
213
243
  // On a flagged-V2 plan `activityConfigurationVersion: v2` is compile's
214
244
  // repair: it is written on connection-bound contexts, on a trigger or task
@@ -5,6 +5,17 @@ export interface PreservedConnectorRowSet {
5
5
  /** The element was saved with no such field at all. */
6
6
  absent?: true;
7
7
  }
8
+ /** How one saved extract row differs from the row compile writes for it. */
9
+ export interface PreservedExtractShape {
10
+ /** The `source` the row reads (`=response.CreatedBy.Id`). */
11
+ source: string;
12
+ /** The variable the row writes. */
13
+ var: string;
14
+ /** Saved fields compile does not write (`displayName`), verbatim. */
15
+ fields?: Record<string, unknown>;
16
+ /** The row was saved with no `target`. */
17
+ omit?: ['target'];
18
+ }
8
19
  /** One saved connector element's own rows, as `preserveCaseJson` carries them. */
9
20
  export interface PreservedConnectorRows {
10
21
  /** `trigger:<node id>`, `task:<task id>` or `rule:<stage id>:<rule id>`. */
@@ -13,6 +24,8 @@ export interface PreservedConnectorRows {
13
24
  operation: Record<string, string>;
14
25
  inputs?: PreservedConnectorRowSet;
15
26
  outputs?: PreservedConnectorRowSet;
27
+ /** The Designer's spelling of the author's extract rows. */
28
+ extracts?: PreservedExtractShape[];
16
29
  }
17
30
  /**
18
31
  * Every connector element and the bag that holds its rows: event triggers,
@@ -44,7 +44,17 @@
44
44
  *
45
45
  * An element whose rows are what compile writes anyway (an SDK-authored
46
46
  * plan's) records nothing for that half, so its source carries no copy.
47
+ *
48
+ * The author's extracts (`.outputs({ createdById: '=response.CreatedBy.Id' })`)
49
+ * are compile's to write, but the Designer saves them with a field compile
50
+ * does not write (`displayName: 'CreatedBy.Id'`) and without one it does
51
+ * (`target`). `extracts` records that difference per extract, keyed by the
52
+ * `source` it reads and the `var` it writes, and compile puts it back on the
53
+ * row that still reads that source into that variable, while the element calls
54
+ * the same operation. An extract the author edits (another source or
55
+ * variable) gets compile's row.
47
56
  */
57
+ import { comparesContextRow } from './connector-saved-context.js';
48
58
  import { caseSubscriptionOwners } from './subscription.js';
49
59
  const CONNECTOR_ACTIVITY_TYPE = 'execute-connector-activity';
50
60
  /** The context rows that name the operation an element calls. */
@@ -196,14 +206,69 @@ export function savedConnectorRows(owner, bag) {
196
206
  const activity = bag.serviceType !== 'Intsvc.EventTrigger' && bag.serviceType !== 'Intsvc.WaitForEvent';
197
207
  const outputs = savedOutputs(bag);
198
208
  const inputs = savedInputs(bag, activity);
199
- if (!outputs && !inputs)
209
+ const extracts = savedExtracts(bag);
210
+ if (!outputs && !inputs && !extracts)
200
211
  return undefined;
201
- return { owner, operation, ...(inputs ? { inputs } : {}), ...(outputs ? { outputs } : {}) };
212
+ return { owner, operation, ...(inputs ? { inputs } : {}), ...(outputs ? { outputs } : {}), ...(extracts ? { extracts } : {}) };
213
+ }
214
+ /** The fields compile writes on an extract row (`emitTaskOutput`). */
215
+ const EXTRACT_WRITTEN_FIELDS = new Set(['name', 'type', 'id', 'var', 'originalVar', 'value', 'source', 'target', 'elementId', 'custom']);
216
+ /**
217
+ * Whether `row` is an author's extract: a field of the response or the error
218
+ * (`=response.CreatedBy.Id`, `=Error.message`) read into a variable. Not an own
219
+ * row (`=response`, or `=response2` once a plan-wide suffix renamed it) and not
220
+ * a `{ assign }`.
221
+ */
222
+ function isExtract(row) {
223
+ return isObject(row) && row.custom !== true && typeof row.source === 'string' && /^=(?:response|Error)[.[]/.test(row.source) && typeof row.var === 'string';
224
+ }
225
+ const extractKey = (row) => `${row.source}\u0000${row.var}`;
226
+ /**
227
+ * Each saved extract's difference from the row compile writes: the fields it
228
+ * has that compile does not write, and a `target` it lacks. An extract that
229
+ * reads the same source into the same variable as another is left to compile:
230
+ * no one row would get the shape.
231
+ */
232
+ function savedExtracts(bag) {
233
+ const rows = (Array.isArray(bag.outputs) ? bag.outputs : []).filter(isExtract);
234
+ const count = new Map();
235
+ for (const row of rows)
236
+ count.set(extractKey(row), (count.get(extractKey(row)) ?? 0) + 1);
237
+ const out = [];
238
+ for (const row of rows) {
239
+ if (count.get(extractKey(row)) !== 1)
240
+ continue;
241
+ const fields = Object.fromEntries(Object.entries(row).filter(([key]) => !EXTRACT_WRITTEN_FIELDS.has(key)).map(([key, value]) => [key, structuredClone(value)]));
242
+ const omit = row.target === undefined;
243
+ if (!Object.keys(fields).length && !omit)
244
+ continue;
245
+ out.push({ source: row.source, var: row.var, ...(Object.keys(fields).length ? { fields } : {}), ...(omit ? { omit: ['target'] } : {}) });
246
+ }
247
+ return out.length ? out : undefined;
248
+ }
249
+ /** Put each saved extract's shape back on the one compiled extract that reads its source into its variable. */
250
+ function extractsBack(bag, shapes) {
251
+ const rows = (Array.isArray(bag.outputs) ? bag.outputs : []).filter(isExtract);
252
+ for (const shape of shapes) {
253
+ const holders = rows.filter((row) => row.source === shape.source && row.var === shape.var);
254
+ if (holders.length !== 1)
255
+ continue;
256
+ const [row] = holders;
257
+ for (const [key, value] of Object.entries(shape.fields ?? {}))
258
+ if (!Object.prototype.hasOwnProperty.call(row, key))
259
+ row[key] = structuredClone(value);
260
+ if (shape.omit?.includes('target'))
261
+ delete row.target;
262
+ }
202
263
  }
203
- /** Whether the element compile built calls the operation the rows were saved for. */
264
+ /**
265
+ * Whether the element compile built calls the operation the rows were saved
266
+ * for. An activity's saved `operation` row, which compile never writes there,
267
+ * does not count (`comparesContextRow`).
268
+ */
204
269
  function sameOperation(bag, entry) {
205
270
  const now = operationOf(bag);
206
- return OPERATION_ROWS.every((name) => now[name] === entry.operation[name]);
271
+ return OPERATION_ROWS.every((name) => !comparesContextRow(bag, name) || now[name] === entry.operation[name]);
207
272
  }
208
273
  /**
209
274
  * The saved outputs over the built ones: the saved own rows in saved order,
@@ -262,6 +327,8 @@ export function applyConnectorRows(result, entries) {
262
327
  const entry = byOwner.get(key);
263
328
  if (!entry || !sameOperation(bag, entry))
264
329
  continue;
330
+ if (entry.extracts)
331
+ extractsBack(bag, entry.extracts);
265
332
  for (const field of ['inputs', 'outputs']) {
266
333
  const set = entry[field];
267
334
  if (!set)
@@ -291,7 +358,7 @@ export function connectorRowErrors(entries) {
291
358
  continue;
292
359
  }
293
360
  for (const field of Object.keys(entry))
294
- if (!['owner', 'operation', 'inputs', 'outputs'].includes(field))
361
+ if (!['owner', 'operation', 'inputs', 'outputs', 'extracts'].includes(field))
295
362
  errors.push(`preserved connector rows "${owner}" field "${field}" is not allowed in the preservation channel`);
296
363
  const { operation, inputs, outputs } = entry;
297
364
  if (!isObject(operation) || typeof operation.connectorKey !== 'string' || !Object.values(operation).every((value) => typeof value === 'string'))
@@ -313,6 +380,17 @@ export function connectorRowErrors(entries) {
313
380
  };
314
381
  half(inputs, 'inputs', isInputRow, (row) => row.name);
315
382
  half(outputs, 'outputs', isOwnOutput, (row) => row.source);
383
+ const { extracts } = entry;
384
+ if (extracts !== undefined) {
385
+ const shapeOk = (shape) => isObject(shape) && typeof shape.source === 'string' && /^=(?:response|Error)[.[]/.test(shape.source)
386
+ && typeof shape.var === 'string' && Object.keys(shape).every((key) => ['source', 'var', 'fields', 'omit'].includes(key))
387
+ && (shape.fields === undefined || (isObject(shape.fields) && Object.keys(shape.fields).every((key) => !EXTRACT_WRITTEN_FIELDS.has(key))))
388
+ && (shape.omit === undefined || (Array.isArray(shape.omit) && shape.omit.length === 1 && shape.omit[0] === 'target'));
389
+ if (!Array.isArray(extracts) || !extracts.every(shapeOk))
390
+ errors.push(`preserved connector rows "${owner}" extracts must each name a source and a var, with only fields compile does not write and omit ["target"]`);
391
+ else if (new Set(extracts.map(extractKey)).size !== extracts.length)
392
+ errors.push(`preserved connector rows "${owner}" extracts name a source and var twice`);
393
+ }
316
394
  }
317
395
  return errors;
318
396
  }
@@ -924,7 +924,7 @@ function savedConfiguration(context) {
924
924
  /**
925
925
  * The activity type the task was saved against (`Curated`, ...): the saved
926
926
  * configuration's `instanceParameters.activityType`, else the activity
927
- * metadata's. It picks between a curated activity and the generic one on the
927
+ * metadata's, else `Curated` for an older Designer's `isCurated: true`. It picks between a curated activity and the generic one on the
928
928
  * same object and path (`Library.identifyAction`).
929
929
  */
930
930
  function connectorActivityType(context) {
@@ -941,7 +941,14 @@ function connectorActivityType(context) {
941
941
  }
942
942
  }
943
943
  const fromActivity = activity?.activityType;
944
- return typeof fromActivity === 'string' && fromActivity ? fromActivity : undefined;
944
+ if (typeof fromActivity === 'string' && fromActivity)
945
+ return fromActivity;
946
+ // An older Designer (the v10 canvas plan) saved neither, only
947
+ // `designTimeMetadata.activityConfig.isCurated`. `true` is a curated
948
+ // activity, e.g. Outlook "Send Email", which shares POST
949
+ // /hubs/productivity/send-mail-v2 with the generic `insert-record-deprecated-`.
950
+ // `false` is left unread: those plans save it on generic records and events alike.
951
+ return context.get('metadata')?.body?.designTimeMetadata?.activityConfig?.isCurated === true ? 'Curated' : undefined;
945
952
  }
946
953
  function connectorVersion(context) {
947
954
  const metadata = context.get('metadata')?.body;
@@ -1674,9 +1681,10 @@ function refuseUnwrittenOutputs(task, plan) {
1674
1681
  function escalationSource(escalation, slaName, index) {
1675
1682
  if (escalation.action?.type !== 'notification')
1676
1683
  throw new Error(`SLA escalation "${escalation.displayName ?? escalation.id ?? index}" has unsupported action "${escalation.action?.type}".`);
1684
+ // An empty list is carried as `notify: []`: compile writes it back as
1685
+ // `recipients: []`, and check warns ESCALATION_NO_RECIPIENTS, as `case
1686
+ // validate` warns CASE_MGMT_STAGE_ESCALATION_RECIPIENTS_MISSING.
1677
1687
  const recipients = escalation.action.recipients ?? [];
1678
- if (recipients.length === 0)
1679
- throw new Error(`SLA escalation "${escalation.displayName ?? escalation.id ?? index}" has no notification recipients.`);
1680
1688
  const notify = recipients.map((recipient) => {
1681
1689
  if (recipient.scope !== 'User' && recipient.scope !== 'UserGroup')
1682
1690
  throw new Error(`SLA escalation "${escalation.displayName ?? escalation.id ?? index}" has unsupported recipient scope "${recipient.scope}".`);
@@ -1716,7 +1724,8 @@ function emitStage(stageOut, depth, stage, refs, library, selectNextStage) {
1716
1724
  // The stage's own calls, collected first so they can be written as one chain or as statements.
1717
1725
  const out = new Emit();
1718
1726
  const inner = depth + 1;
1719
- if (data.description)
1727
+ // `""` too: a stage saved with `description: ""` keeps it (compile writes what the source gives).
1728
+ if (typeof data.description === 'string')
1720
1729
  out.line(inner, `.description(${tsLiteral(data.description)})`);
1721
1730
  if (data.isRequired !== undefined)
1722
1731
  out.line(inner, data.isRequired ? '.required()' : '.required(false)');
@@ -2318,7 +2327,13 @@ function ruleInputIdentity(inputs) {
2318
2327
  function slaIdentity(sla) {
2319
2328
  return {
2320
2329
  ...(sla.id ? { id: sla.id } : {}),
2321
- escalations: (sla.escalationRule ?? []).map((entry) => ({ ...(entry.id ? { id: entry.id } : {}) })),
2330
+ escalations: (sla.escalationRule ?? []).map((entry) => ({
2331
+ ...(entry.id ? { id: entry.id } : {}),
2332
+ // `escalationSource` writes atRiskPercentage only for an at-risk trigger.
2333
+ ...(entry.triggerInfo?.type === 'sla-breached' && typeof entry.triggerInfo.atRiskPercentage === 'number'
2334
+ ? { breachedAtRisk: entry.triggerInfo.atRiskPercentage }
2335
+ : {}),
2336
+ })),
2322
2337
  ...(Array.isArray(sla.escalationRule) && sla.escalationRule.length === 0 ? { emptyEscalationRule: true } : {}),
2323
2338
  };
2324
2339
  }
@@ -2507,6 +2522,21 @@ function customRowIdentity(task, row, plan) {
2507
2522
  function customElementIdIsOwn(version) {
2508
2523
  return typeof version === 'string' && /^\d+\.\d+\.\d+$/.test(version) && compareSchemaVersions(version, '32.0.3') >= 0;
2509
2524
  }
2525
+ /**
2526
+ * A task's saved `elementId` when it is not the `<stageId>-<taskId>` compile
2527
+ * writes, e.g. `Stage_old-tOld` on a task Studio Web copied from another stage
2528
+ * (preserve.ts, `elementId` on a task identity).
2529
+ */
2530
+ function savedTaskElementId(stage, task) {
2531
+ if (typeof task.elementId !== 'string' || !stage.id || !task.id)
2532
+ return {};
2533
+ return task.elementId === `${stage.id}-${task.id}` ? {} : { elementId: task.elementId };
2534
+ }
2535
+ /** `taskElementId: true` on an io row saved with its task's carried `elementId` ({@link savedTaskElementId}). */
2536
+ function rowHoldsSavedTaskElementId(stage, task, row) {
2537
+ const saved = savedTaskElementId(stage, task).elementId;
2538
+ return saved !== undefined && row.elementId === saved ? { taskElementId: true } : {};
2539
+ }
2510
2540
  function identityPreservation(plan) {
2511
2541
  const ambiguous = ambiguousSlaIds(plan);
2512
2542
  const conditionIdentity = (condition, _index, list) => conditionIdentityOf(condition, ambiguous, list);
@@ -2522,9 +2552,10 @@ function identityPreservation(plan) {
2522
2552
  tasks: (stage.data?.tasks ?? []).map((lane) => lane.map((task) => ({
2523
2553
  name: taskSourceName(task),
2524
2554
  ...(task.id ? { id: task.id } : {}),
2555
+ ...savedTaskElementId(stage, task),
2525
2556
  entryConditions: (task.entryConditions ?? []).map(conditionIdentity),
2526
2557
  ...emptyLists(task, TASK_EMPTY_LISTS),
2527
- inputs: (task.data?.inputs ?? []).map((row) => ({ name: row.name ?? '', ...(row.id ? { id: row.id } : {}), ...actionInputShape(task, row), ...resourceRowShape(task, row, 'inputs') })),
2558
+ inputs: (task.data?.inputs ?? []).map((row) => ({ name: row.name ?? '', ...(row.id ? { id: row.id } : {}), ...actionInputShape(task, row), ...resourceRowShape(task, row, 'inputs'), ...rowHoldsSavedTaskElementId(stage, task, row) })),
2528
2559
  outputs: (task.data?.outputs ?? []).map((row) => ({
2529
2560
  name: row.name ?? '',
2530
2561
  ...(row.id ? { id: row.id } : {}),
@@ -2539,6 +2570,7 @@ function identityPreservation(plan) {
2539
2570
  ...actionOutputShape(task, row),
2540
2571
  ...resourceRowShape(task, row, 'outputs'),
2541
2572
  ...customRowIdentity(task, row, plan),
2573
+ ...rowHoldsSavedTaskElementId(stage, task, row),
2542
2574
  })),
2543
2575
  ...emptyIoLists(task),
2544
2576
  ...carriedResource(task, plan),
@@ -262,33 +262,58 @@ function wireType(value) {
262
262
  return 'boolean';
263
263
  return undefined;
264
264
  }
265
- /** The connector ACTION's two tenant answers: the registry node and the `is resources describe` reply, from what the task saved. */
266
- function actionAnswers(w, nodeType) {
265
+ /**
266
+ * The connector ACTION's two tenant answers: the registry node and the `is
267
+ * resources describe` reply, from what the tasks on the operation saved.
268
+ *
269
+ * `w` is the first task on the operation, and the entry's text is its own.
270
+ * The fields are every task's (`wires`, `w` first): one entry stands for the
271
+ * operation, so it must declare each field any task on it sends. Two Data
272
+ * Service "Create Entity Record" tasks that write two entities send two field
273
+ * sets on one path, for instance `{ caseNumber, status }` and
274
+ * `{ caseNumber, eventTime, actor }`; the entry declares all four. A field two
275
+ * tasks send with values of different JSON types gets no type.
276
+ */
277
+ function actionAnswers(w, nodeType, wires = [w]) {
267
278
  const fields = new Map();
279
+ // The fields whose type was read off a sent value, not a saved declaration.
280
+ const valueTyped = new Set();
268
281
  const add = (name, location, type, displayName) => {
269
282
  if (typeof name !== 'string' || !name || fields.has(name))
270
283
  return;
271
284
  fields.set(name, { name, location, ...(type ? { type } : {}), ...(typeof displayName === 'string' && displayName ? { displayName } : {}) });
272
285
  };
273
- // The live connector's field list the Designer saved, then every value the task sends.
274
- const saved = w.optional.fieldsContainer?.inputFields;
275
- for (const f of Array.isArray(saved) ? saved : []) {
276
- if (!isObject(f) || f.request === false)
277
- continue;
278
- const location = typeof f.fieldLocation === 'string' ? ownEntry(LOCATIONS, f.fieldLocation) : undefined;
279
- if (location)
280
- add(f.name, location, typeof f.type === 'string' ? f.type : undefined, f.displayName);
286
+ const addSent = (name, location, type) => {
287
+ const field = fields.get(name);
288
+ if (!field) {
289
+ add(name, location, type);
290
+ valueTyped.add(name);
291
+ }
292
+ else if (valueTyped.has(name) && field.type !== type)
293
+ delete field.type;
294
+ };
295
+ // The live connector's field list each task's Designer saved, then every value each task sends.
296
+ for (const wire of wires) {
297
+ const saved = wire.optional.fieldsContainer?.inputFields;
298
+ for (const f of Array.isArray(saved) ? saved : []) {
299
+ if (!isObject(f) || f.request === false)
300
+ continue;
301
+ const location = typeof f.fieldLocation === 'string' ? ownEntry(LOCATIONS, f.fieldLocation) : undefined;
302
+ if (location)
303
+ add(f.name, location, typeof f.type === 'string' ? f.type : undefined, f.displayName);
304
+ }
281
305
  }
282
306
  for (const m of String(w.path ?? '').matchAll(/\{([^}]+)\}/g))
283
307
  add(m[1], 'path', 'string');
284
308
  const slot = { pathParameters: 'path', queryParameters: 'query', body: 'body' };
285
- for (const row of Array.isArray(w.bag.inputs) ? w.bag.inputs : []) {
286
- const location = typeof row?.name === 'string' ? ownEntry(slot, row.name) : undefined;
287
- if (!location || !isObject(row.body))
288
- continue;
289
- for (const [name, value] of Object.entries(row.body))
290
- add(name, location, wireType(value));
291
- }
309
+ for (const wire of wires)
310
+ for (const row of Array.isArray(wire.bag.inputs) ? wire.bag.inputs : []) {
311
+ const location = typeof row?.name === 'string' ? ownEntry(slot, row.name) : undefined;
312
+ if (!location || !isObject(row.body))
313
+ continue;
314
+ for (const [name, value] of Object.entries(row.body))
315
+ addSent(name, location, wireType(value));
316
+ }
292
317
  const parameters = [...fields.values()].filter((f) => f.location !== 'body')
293
318
  .map((f) => ({ name: f.name, type: f.location, dataType: f.type ?? 'string', required: false, ...(f.displayName ? { displayName: f.displayName } : {}) }));
294
319
  const multipart = Array.isArray(w.apc.multipartParameters) ? w.apc.multipartParameters : [];
@@ -410,6 +435,18 @@ export function planConnectors(plan, library) {
410
435
  // and the first wire on an operation is the one its entry is built from.
411
436
  const bags = planConnectorBags(plan);
412
437
  const ordered = [...bags.filter((b) => b.bag.serviceType === WAIT), ...bags.filter((b) => b.bag.serviceType !== WAIT)];
438
+ const actionKey = (w) => JSON.stringify([w.connectorKey, w.method, w.path, w.objectName, w.version]);
439
+ // Every action wire the library cannot name, by operation: the entry built
440
+ // from the first declares the fields of all (`actionAnswers`).
441
+ const actionWires = new Map();
442
+ for (const { bag } of ordered) {
443
+ const w = wireOf(bag);
444
+ if (!w || w.kind !== 'action' || known(library, w))
445
+ continue;
446
+ const list = actionWires.get(actionKey(w)) ?? [];
447
+ list.push(w);
448
+ actionWires.set(actionKey(w), list);
449
+ }
413
450
  for (const { owner, names, bag } of ordered) {
414
451
  const w = wireOf(bag);
415
452
  if (!w || known(library, w))
@@ -420,7 +457,7 @@ export function planConnectors(plan, library) {
420
457
  // One action id per operation: object and verb, with a counter when two
421
458
  // paths share them or a library layer already holds the node type.
422
459
  const base = `${slug(w.objectName)}-${slug(w.method)}`;
423
- const operationKey = JSON.stringify([w.connectorKey, w.method, w.path, w.objectName, w.version]);
460
+ const operationKey = actionKey(w);
424
461
  let id = actionIds.get(operationKey);
425
462
  if (id === undefined) {
426
463
  id = base;
@@ -430,7 +467,7 @@ export function planConnectors(plan, library) {
430
467
  id = `${base}-${n}`;
431
468
  actionIds.set(operationKey, id);
432
469
  }
433
- const answers = actionAnswers(w, `uipath.connector.${w.connectorKey}.${id}`);
470
+ const answers = actionAnswers(w, `uipath.connector.${w.connectorKey}.${id}`, actionWires.get(operationKey));
434
471
  node = answers.node;
435
472
  const canonical = extractCanonical(node);
436
473
  if (!canonical)
@@ -455,7 +492,7 @@ export function planConnectors(plan, library) {
455
492
  }
456
493
  entry.provenance = { source: PLAN_CONNECTOR_SOURCE };
457
494
  const question = libraryQuestion(w.kind, { connectorKey: w.connectorKey, httpMethod: w.method, endpoint: w.path, objectName: w.objectName, eventOperation: w.operation });
458
- // Two wires on one operation give one entry: the first one's.
495
+ // Two wires on one operation give one entry: the first one's text, with every one's fields (`actionAnswers`).
459
496
  const key = JSON.stringify([entry.nodeType, entry.operation?.objectName ?? '', entry.version]);
460
497
  let connector = byKey.get(key);
461
498
  if (!connector) {
@@ -194,8 +194,15 @@ interface ConditionIdentity {
194
194
  }
195
195
  interface SlaIdentity {
196
196
  id?: string;
197
+ /**
198
+ * `breachedAtRisk`: an `sla-breached` escalation's leftover
199
+ * `triggerInfo.atRiskPercentage`. The Designer keeps the percentage when an
200
+ * `at-risk` escalation is switched to `sla-breached`; the engine ignores it
201
+ * there and the source does not spell it, so the read value is carried.
202
+ */
197
203
  escalations?: Array<{
198
204
  id?: string;
205
+ breachedAtRisk?: number;
199
206
  }>;
200
207
  /**
201
208
  * The SLA spelled an empty `escalationRule: []`. The serializer omits the
@@ -212,6 +219,19 @@ interface StageIdentity {
212
219
  tasks?: Array<Array<{
213
220
  name: string;
214
221
  id?: string;
222
+ /**
223
+ * The task's saved `elementId`, only when it is not `<stageId>-<taskId>`, the
224
+ * value compile writes. A task Studio Web copied, or one whose stage or task
225
+ * id changed after it was saved, keeps the `elementId` it was created with
226
+ * (`Stage_old-tOld`), and so do the io rows that name it. The converter only
227
+ * matches a task's rows to it by equality, so the saved value is carried and
228
+ * written back on the task and on each of its rows saved with it
229
+ * (`taskElementId: true` on the row), and only those: Studio Web re-stamps
230
+ * some rows with `<stageId>-<taskId>` and leaves others, and the converter
231
+ * drops a row whose `elementId` is not the task's, so which rows hold it is
232
+ * part of what the plan does.
233
+ */
234
+ elementId?: string;
215
235
  entryConditions?: ConditionIdentity[];
216
236
  /** The resource the rows' `fields` / `omit` describe; they are applied only while the task still names it. */
217
237
  resource?: ResourceTaskIdentity;
@@ -222,6 +242,7 @@ interface StageIdentity {
222
242
  elementId?: string;
223
243
  canonicalId?: true;
224
244
  fields?: Record<string, unknown>;
245
+ taskElementId?: true;
225
246
  }>;
226
247
  /** `originalVar` only when it is not the row's `id` (the serializer's own spelling). `elementId` when an action form output names another element than its task. `fields` as on an input. `omit`: the fields an action form output (`target`, `_jsonSchema`, `elementId`) or a resource extract (`target`) was saved without that compile writes. `target`: which of the row's variables its saved `target` names when that is not its id (`=<var>` or `=<originalVar>`; compile writes `=<id>`). `bodyCopies`: the extra copies of its `body` an action form output was saved with (`jsonSchema`), which compile writes back from the body. */
227
248
  /** `var` and `custom: true`: a custom row whose label (`name`) is not the name of the variable it assigns. */
@@ -314,6 +335,8 @@ export interface PreservedOutputRow {
314
335
  custom?: true;
315
336
  noAlias?: true;
316
337
  customRow?: CustomRowShape;
338
+ /** The row was saved with its task's carried `elementId` (see `elementId` on the task identity). */
339
+ taskElementId?: true;
317
340
  }
318
341
  /**
319
342
  * Non-authoring Case JSON lanes retained by decompile/recompile.
@@ -1334,6 +1334,8 @@ function applyPreservedIdentities(result, preservation, warn) {
1334
1334
  if (!carriedCompanions.has(row.var))
1335
1335
  carriedCompanions.set(row.var, { id: row.var, name: row.var, type: row.type, elementId: 'root', custom: true });
1336
1336
  };
1337
+ // Tasks saved with an `elementId` other than `<stageId>-<taskId>`, written back once every id is final.
1338
+ const savedTaskElementIds = [];
1337
1339
  // Tasks whose custom rows carry a saved shape (`customRowShape`).
1338
1340
  const customRowShapes = [];
1339
1341
  const nodes = result.nodes;
@@ -1356,6 +1358,15 @@ function applyPreservedIdentities(result, preservation, warn) {
1356
1358
  for (const row of planOutputRows(result, stages))
1357
1359
  if (typeof row?.id === 'string')
1358
1360
  heldOutputIds.add(row.id);
1361
+ // A wait-for-connector rule's own output rows (`ruleOutputRows`), and the
1362
+ // carried ids they have taken. The one place two rows may share an output id:
1363
+ // the Designer copies a rule with its rows (`response2` on both copies, each
1364
+ // writing `response2`), and `case validate` checks only task outputs for a
1365
+ // repeat (CASE_MGMT_OUTPUT_ID_DUPLICATE), so the plan is valid as saved.
1366
+ // Giving the copy a fresh id would point it at another variable. A rule row
1367
+ // that carries an id another rule row took takes it too; a task row never does.
1368
+ const ruleRows = new WeakSet(planRuleOutputRows(result, stages));
1369
+ const ruleRowIds = new Set();
1359
1370
  // A resource task row's carried Designer fields (`fields`) and the `target`
1360
1371
  // it was saved without (`omit`), put back on the row of the same name after
1361
1372
  // the id renames. Example: `{ name: 'echoIn', fields: { displayName: 'echoIn',
@@ -1441,7 +1452,8 @@ function applyPreservedIdentities(result, preservation, warn) {
1441
1452
  heldOutputIds.add(row.id);
1442
1453
  return true;
1443
1454
  }
1444
- if (target && typeof row.id === 'string' && row.id !== currentId && heldOutputIds.has(row.id))
1455
+ const ruleRow = !!target && ruleRows.has(target);
1456
+ if (target && typeof row.id === 'string' && row.id !== currentId && heldOutputIds.has(row.id) && !(ruleRow && ruleRowIds.has(row.id)))
1445
1457
  return false;
1446
1458
  // A reassigned row (slot id, `originalVar` the slot) whose carried id IS
1447
1459
  // its variable was saved in the own-name shape; see `ownNameRestored`.
@@ -1470,6 +1482,8 @@ function applyPreservedIdentities(result, preservation, warn) {
1470
1482
  heldOutputIds.delete(currentId);
1471
1483
  heldOutputIds.add(row.id);
1472
1484
  }
1485
+ if (ruleRow && typeof row.id === 'string' && target.id === row.id)
1486
+ ruleRowIds.add(row.id);
1473
1487
  return true;
1474
1488
  };
1475
1489
  // Rows whose carried id another row held when they were reached. Example: a
@@ -1482,7 +1496,7 @@ function applyPreservedIdentities(result, preservation, warn) {
1482
1496
  // `elementId` (#1636). On any other row those would remove or re-point a
1483
1497
  // field compile writes: a resource extract without its task's `elementId`
1484
1498
  // is one the converter never reads (#1419).
1485
- const takeOutputRows = (outputRows, wantedRows, actionRows = false) => {
1499
+ const takeOutputRows = (outputRows, wantedRows, actionRows = false, elementIdRows) => {
1486
1500
  // A custom row's own label goes back on the one custom row that still
1487
1501
  // assigns its variable (matched once every id is final).
1488
1502
  for (const row of wantedRows)
@@ -1506,6 +1520,10 @@ function applyPreservedIdentities(result, preservation, warn) {
1506
1520
  // A positional match never takes a row a name match owns.
1507
1521
  : named.has(outputRows[index]?.name) ? undefined : outputRows[index];
1508
1522
  const currentId = target?.id;
1523
+ if (target)
1524
+ elementIdRows?.matched.add(target);
1525
+ if (target && row.taskElementId === true)
1526
+ elementIdRows?.saved.add(target);
1509
1527
  // An action form output the Designer saved with no `target` (or no
1510
1528
  // `_jsonSchema` copy of its body, or no `elementId`) keeps none, and one
1511
1529
  // whose `elementId` names another element keeps that.
@@ -1590,7 +1608,15 @@ function applyPreservedIdentities(result, preservation, warn) {
1590
1608
  (wanted ?? []).forEach((sla, index) => {
1591
1609
  const target = current?.[index];
1592
1610
  want(target, sla.id);
1593
- (sla.escalations ?? []).forEach((entry, escalationIndex) => want(target?.escalationRule?.[escalationIndex], entry.id));
1611
+ (sla.escalations ?? []).forEach((entry, escalationIndex) => {
1612
+ const escalation = target?.escalationRule?.[escalationIndex];
1613
+ want(escalation, entry.id);
1614
+ // The read sla-breached escalation kept a stale atRiskPercentage; put it
1615
+ // back only while this escalation is still sla-breached without one.
1616
+ const info = escalation?.triggerInfo;
1617
+ if (typeof entry.breachedAtRisk === 'number' && info?.type === 'sla-breached' && info.atRiskPercentage === undefined)
1618
+ info.atRiskPercentage = entry.breachedAtRisk;
1619
+ });
1594
1620
  // The read SLA spelled `escalationRule: []`; `emitSla` omits an empty list.
1595
1621
  if (sla.emptyEscalationRule === true && target && target.escalationRule === undefined)
1596
1622
  target.escalationRule = [];
@@ -1644,6 +1670,9 @@ function applyPreservedIdentities(result, preservation, warn) {
1644
1670
  && taskIdentity.resource.name === compiledRef.name && taskIdentity.resource.folderPath === compiledRef.folderPath;
1645
1671
  const rowShape = (row) => (resourceKept ? row : { name: row.name });
1646
1672
  take(task, taskIdentity.id);
1673
+ const elementIdRows = { saved: new Set(), matched: new Set() };
1674
+ if (task && stage && typeof taskIdentity.elementId === 'string')
1675
+ savedTaskElementIds.push({ stage, task, elementId: taskIdentity.elementId, rows: elementIdRows });
1647
1676
  restoreEmptyLists(task, taskIdentity.emptyLists, TASK_EMPTY_LISTS);
1648
1677
  takeConditions(task?.entryConditions, taskIdentity.entryConditions);
1649
1678
  // An input row is matched by name when the name is unique on both sides
@@ -1655,6 +1684,10 @@ function applyPreservedIdentities(result, preservation, warn) {
1655
1684
  wantedInputs.forEach((row, index) => {
1656
1685
  const byName = once(wantedInputs.map((r) => r.name), row.name) && once(inputRows.map((r) => r?.name), row.name);
1657
1686
  const input = byName ? inputRows.find((r) => r?.name === row.name) : inputRows[index];
1687
+ if (input)
1688
+ elementIdRows.matched.add(input);
1689
+ if (input && row.taskElementId === true)
1690
+ elementIdRows.saved.add(input);
1658
1691
  // An action form input is written `{ name, type, value }`; the Designer's
1659
1692
  // row also has its id, `var` (the id) and `elementId`, which come back.
1660
1693
  if (task?.type === 'action' && input && input.id === undefined && typeof row.id === 'string' && input.name === row.name) {
@@ -1680,7 +1713,7 @@ function applyPreservedIdentities(result, preservation, warn) {
1680
1713
  if (task && shapes.length)
1681
1714
  customRowShapes.push({ task, shapes });
1682
1715
  takeOutputRows(task?.data?.outputs ?? [], (taskIdentity.outputs ?? [])
1683
- .map((row) => ({ ...row, ...(!isAction && !resourceKept ? { fields: undefined, omit: undefined } : {}) })), isAction);
1716
+ .map((row) => ({ ...row, ...(!isAction && !resourceKept ? { fields: undefined, omit: undefined } : {}) })), isAction, elementIdRows);
1684
1717
  // Only on the kind the lists were saved on (`emptyIoType`; a payload from
1685
1718
  // before it was recorded was written for resource tasks only), and never
1686
1719
  // on a connector placeholder, whose `data: {}` is its contract (#1354).
@@ -1808,6 +1841,21 @@ function applyPreservedIdentities(result, preservation, warn) {
1808
1841
  row.source = source;
1809
1842
  for (const rename of rowRenames)
1810
1843
  rename();
1844
+ // A task's saved `elementId` (a copied task's `Stage_old-tOld`) goes back on
1845
+ // the task, and on each of its rows that compile gave the `<stageId>-<taskId>`
1846
+ // it writes and that either was saved with the task's value or is new (an
1847
+ // edit added it, and it is wired to its task as compile means it to be). A
1848
+ // row saved with `<stageId>-<taskId>` keeps it, and so does one naming
1849
+ // another element (`root`).
1850
+ for (const { stage, task, elementId, rows } of savedTaskElementIds) {
1851
+ const written = `${stage.id}-${task.id}`;
1852
+ if (task.elementId !== written)
1853
+ continue;
1854
+ task.elementId = elementId;
1855
+ for (const row of [...(task.data?.inputs ?? []), ...(task.data?.outputs ?? [])])
1856
+ if (row?.elementId === written && (rows.saved.has(row) || !rows.matched.has(row)))
1857
+ row.elementId = elementId;
1858
+ }
1811
1859
  settleOwnNameRows(result, stages, ownNameRestored, identities);
1812
1860
  for (const spell of targetSpellings)
1813
1861
  spell();
@@ -2220,7 +2268,7 @@ function emitStage(stage, lanes, si, stageId, laneTaskIds, ids, resolver) {
2220
2268
  isPendingParent: false,
2221
2269
  tasks: lanes.map((lane, li) => lane.map((task, ti) => emitTask(task, stage.label, laneTaskIds[li][ti], ids, resolver))),
2222
2270
  };
2223
- if (stage.description)
2271
+ if (stage.description !== undefined)
2224
2272
  data.description = stage.description;
2225
2273
  if (stage.required !== undefined)
2226
2274
  data.isRequired = stage.required;
@@ -2811,6 +2859,17 @@ function ruleOutputRows(conditions) {
2811
2859
  return (conditions ?? []).flatMap((condition) => (condition?.rules ?? []).flat().flatMap((rule) => rule?.[bag]?.outputs ?? []));
2812
2860
  }
2813
2861
  /** Every output row in the plan: stage and task rule rows, task rows, and case-exit rule rows. */
2862
+ /** Every wait-for-connector rule's own output row in the plan: stage and task conditions, and the case exit rules. */
2863
+ function planRuleOutputRows(result, stages) {
2864
+ return [
2865
+ ...stages.flatMap((stage) => [
2866
+ ...ruleOutputRows(stage.data?.entryConditions),
2867
+ ...ruleOutputRows(stage.data?.exitConditions),
2868
+ ...(stage.data?.tasks ?? []).flat().flatMap((task) => ruleOutputRows(task?.entryConditions)),
2869
+ ]),
2870
+ ...ruleOutputRows(result.metadata?.caseExitRules),
2871
+ ].filter((row) => row && typeof row === 'object');
2872
+ }
2814
2873
  function planOutputRows(result, stages) {
2815
2874
  return [
2816
2875
  ...stages.flatMap((stage) => [
@@ -2849,7 +2908,10 @@ const OWN_NAME_OUTPUT_ROWS = new WeakSet();
2849
2908
  * - **own name** — the output keeps its field's name (the `var` is the source's
2850
2909
  * last segment, or the Designer's camelCase of it, either one optionally
2851
2910
  * with a numeric suffix: `=APIOutput1` into `APIOutput1`, `aPIOutput1` or
2852
- * `aPIOutput12`, and `=response.app_id` into `app_id`; see `keepsOwnName`).
2911
+ * `aPIOutput12`, and `=response.app_id` into `app_id`; for a nested
2912
+ * response field the camelCase of its whole path, `=response.CreatedBy.Id`
2913
+ * into `createdById`; see `keepsOwnSourceName`). The row's `name` is the
2914
+ * field's path under `response`, else its last segment (`outputRowName`).
2853
2915
  * The row's `id` IS the `var`, with no `originalVar`:
2854
2916
  * `{ id: 'APIOutput1', var: 'APIOutput1', target: '=APIOutput1' }`. This is
2855
2917
  * the task-scoped output: it writes no case variable, and a later task reads
@@ -2867,8 +2929,7 @@ const OWN_NAME_OUTPUT_ROWS = new WeakSet();
2867
2929
  function emitTaskOutput(o, elementId, ids, seed, resolver) {
2868
2930
  if (o.custom)
2869
2931
  return emitCustomOutput(o, resolver);
2870
- const path = o.source.replace(/^=/, '');
2871
- const field = path.split('.').pop() || o.source;
2932
+ const field = outputRowName(o.source);
2872
2933
  // A reassigned row registers the readable companion once (declared vars take
2873
2934
  // precedence in the merge); an own-name row is the variable and registers none.
2874
2935
  const companion = () => {
@@ -3544,8 +3605,7 @@ function isCarriedNestedReassignment(row, carriedId) {
3544
3605
  return false;
3545
3606
  if (carriedId === row.id || typeof row.source !== 'string')
3546
3607
  return false;
3547
- const path = row.source.replace(/^=/, '');
3548
- return path.includes('.') && keepsOwnName(row.var, path.split('.').pop() ?? '');
3608
+ return row.source.replace(/^=/, '').includes('.') && keepsOwnSourceName(row.var, row.source);
3549
3609
  }
3550
3610
  /** Whether a task output is written in the own-name shape (see `emitTaskOutput`). */
3551
3611
  function isOwnNameOutput(o) {
@@ -3557,8 +3617,43 @@ function isOwnNameOutput(o) {
3557
3617
  // that bare row (`outputFor`: `{ id: 'app_id', var: 'app_id', source:
3558
3618
  // '=response.app_id' }`), so it stays on the task with no root companion
3559
3619
  // (builder-sdk#1241).
3560
- const field = o.source.replace(/^=/, '').split('.').pop() ?? '';
3561
- return keepsOwnName(o.var, field);
3620
+ return keepsOwnSourceName(o.var, o.source);
3621
+ }
3622
+ /**
3623
+ * The `name` of the row that reads `source`: a connector result field's path
3624
+ * under `response` (`=response.CreatedBy.Id` is `CreatedBy.Id`), else the
3625
+ * path's last segment (`=Decision.output` is `output`, `=APIOutput1` is
3626
+ * `APIOutput1`).
3627
+ *
3628
+ * The Case Designer names a connector task's extract after the field's path
3629
+ * in the response, so one task that reads `CreatedBy.Id`, `Id` and
3630
+ * `UpdatedBy.Id` has three rows with three names. The last segment would name
3631
+ * all three `Id`.
3632
+ */
3633
+ function outputRowName(source) {
3634
+ const path = source.replace(/^=/, '');
3635
+ if (path.startsWith('response.') && path.length > 'response.'.length)
3636
+ return path.slice('response.'.length);
3637
+ return path.split('.').pop() || source;
3638
+ }
3639
+ /**
3640
+ * Whether variable `name` is the own name of the field `source` reads: the
3641
+ * path's last segment (`keepsOwnName`, `=response.app_id` into `app_id`), or,
3642
+ * for a nested connector result field, the Designer's camelCase of its whole
3643
+ * path under `response`, with its optional counter: `=response.CreatedBy.Id`
3644
+ * into `createdById` or `createdById4`.
3645
+ */
3646
+ function keepsOwnSourceName(name, source) {
3647
+ const path = source.replace(/^=/, '');
3648
+ if (keepsOwnName(name, path.split('.').pop() ?? ''))
3649
+ return true;
3650
+ if (!path.startsWith('response.'))
3651
+ return false;
3652
+ const segments = path.slice('response.'.length).split('.');
3653
+ if (segments.length < 2 || !segments.every((segment) => /^[A-Za-z_]\w*$/.test(segment)))
3654
+ return false;
3655
+ const base = camelizeName(segments.join(''));
3656
+ return name === base || (name.startsWith(base) && /^(?:[2-9]|[1-9]\d+)$/.test(name.slice(base.length)));
3562
3657
  }
3563
3658
  /** The ids of the carried document-extraction tasks' saved output rows. */
3564
3659
  function savedOutputIds(entries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.120.2",
3
+ "version": "6.120.4",
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",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "53cda99a37bbc03af9ea7b89bc2a0c60d231ac28"
127
+ "gitref": "2e5b24a5f455c61476724c2095041b9a713267ab"
128
128
  }