@uipath/maestro-builder-sdk 6.122.2 → 6.122.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,57 @@ export declare function caseConnectorOwners(plan: Record<string, any>): Array<{
17
17
  key: string;
18
18
  bag: Record<string, any>;
19
19
  }>;
20
+ /**
21
+ * What compile writes for a connector element from the library it compiles
22
+ * with, for the unedited source (`rebuiltConnectorElement` in decompile.ts):
23
+ * the `metadata` body, an activity's input container bodies by name
24
+ * (`pathParameters`, `queryParameters`, `body`), and the `response` row's
25
+ * schema. A field is absent where it was not worked out.
26
+ */
27
+ export interface RebuiltConnectorElement {
28
+ metadata?: Record<string, unknown>;
29
+ containers?: Record<string, unknown>;
30
+ responseSchema?: unknown;
31
+ }
32
+ /**
33
+ * Which kind of connector element a bag belongs to, which decides how its
34
+ * inputs compare: an activity's field by field across its containers
35
+ * ({@link activityFieldValues}), an event's (a trigger, a wait) row by row.
36
+ */
37
+ export declare enum ConnectorKind {
38
+ Activity = "activity",
39
+ Event = "event"
40
+ }
41
+ /** The {@link ConnectorKind} of a connector element's bag, by its `serviceType`. */
42
+ export declare function connectorKind(bag: Record<string, any>): ConnectorKind;
43
+ /**
44
+ * An activity's input values by field, across its containers: each
45
+ * `pathParameters` / `queryParameters` / `body` key with its value, and any
46
+ * other row (a multipart `file` part) by its name. This is what the source
47
+ * holds: decompile lifts the containers into one `inputs` object, and compile
48
+ * routes each field to the container the library names. `undefined` when a
49
+ * field sits in two containers, which only a container-by-container compare
50
+ * can tell apart.
51
+ *
52
+ * For instance `{ queryParameters: { start: 0 }, body: { filterGroup: {...} } }`
53
+ * and `{ body: { filterGroup: {...}, start: 0 } }` hold the same fields.
54
+ */
55
+ export declare function activityFieldValues(values: Record<string, unknown>): Map<string, unknown> | undefined;
56
+ /**
57
+ * Whether what compile writes now (`built`) differs from what an SDK wrote
58
+ * (`saved`) only in the library's values: the same fields, other text, ids or
59
+ * kinds. That is a library update, which the saved copy outlives. A different
60
+ * set of fields is the SDK's own builder changing (an older SDK's thinner
61
+ * essential configuration, #1420; its missing `inputMetadata`, #1427; its flat
62
+ * response schema, #1423), which compile repairs on purpose, so the saved copy
63
+ * is not kept.
64
+ *
65
+ * For instance a Slack task's `metadata` whose only difference is
66
+ * `activityMetadata.activity.description` is a library update; one whose
67
+ * configuration lacks `customFieldsRequestDetails` and `operation` is an older
68
+ * SDK's.
69
+ */
70
+ export declare function onlyLibraryValuesDiffer(built: unknown, saved: unknown, opaque?: ReadonlySet<string>): boolean;
20
71
  /**
21
72
  * Whether a context row named `name` counts when comparing the element
22
73
  * compile built (`bag`) with a saved one: always, except a row in
@@ -25,10 +76,32 @@ export declare function caseConnectorOwners(plan: Record<string, any>): Array<{
25
76
  export declare function comparesContextRow(bag: Record<string, any>, name: string): boolean;
26
77
  /**
27
78
  * The saved context of a connector element, when it has a `metadata` row with
28
- * an object body (the Designer's state) that compile could not have written
29
- * ({@link sdkShaped}); else `undefined`.
79
+ * an object body (the Designer's state) that compile will not write back as it
80
+ * is; else `undefined`.
81
+ *
82
+ * Each step is judged against what compile writes for the unedited source,
83
+ * from the library it runs with (`rebuild`, `rebuiltConnectorElement` in
84
+ * decompile.ts), not against the saved bytes alone:
85
+ *
86
+ * - A context compile could have written ({@link sdkShaped}) is kept when
87
+ * compile writes a `metadata` body that differs from it only in the
88
+ * library's values ({@link onlyLibraryValuesDiffer}): an SDK-authored plan
89
+ * compiled against an older library. The saved copy is what keeps the
90
+ * unedited plan as it was. For instance, a Slack task an SDK compiled when
91
+ * the library described it as `"(Slack) Send a message to an individual user
92
+ * in Slack."` keeps that description after a library that says `"Send a
93
+ * message to an individual user in Slack."`. A body of another shape (an
94
+ * older SDK's builder) is left to compile, which repairs it.
95
+ * - An activity's `inputs` are recorded as compile writes them for the
96
+ * unedited source, so a change compile makes to an input on purpose (an
97
+ * older SDK's `sendAs`, written as the declared `send_as`, #1601) is not
98
+ * read as an edit of the element ({@link unchanged}).
99
+ *
100
+ * Without `rebuild` (a merge, which has no library), or when it cannot work
101
+ * the element out, a context compile could have written is left to compile
102
+ * and the inputs are the saved ones, as before.
30
103
  */
31
- export declare function savedConnectorContext(owner: string, bag: Record<string, any>): PreservedConnectorContext | undefined;
104
+ export declare function savedConnectorContext(owner: string, bag: Record<string, any>, rebuild?: () => RebuiltConnectorElement | undefined): PreservedConnectorContext | undefined;
32
105
  /**
33
106
  * Write each saved connector context back onto the element compile built for
34
107
  * the same owner, while that element is unchanged ({@link unchanged}). Runs
@@ -81,6 +81,100 @@ 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
+ * Which kind of connector element a bag belongs to, which decides how its
86
+ * inputs compare: an activity's field by field across its containers
87
+ * ({@link activityFieldValues}), an event's (a trigger, a wait) row by row.
88
+ */
89
+ export var ConnectorKind;
90
+ (function (ConnectorKind) {
91
+ ConnectorKind["Activity"] = "activity";
92
+ ConnectorKind["Event"] = "event";
93
+ })(ConnectorKind || (ConnectorKind = {}));
94
+ /** The {@link ConnectorKind} of a connector element's bag, by its `serviceType`. */
95
+ export function connectorKind(bag) {
96
+ return EVENT_SERVICE_TYPES.has(bag?.serviceType) ? ConnectorKind.Event : ConnectorKind.Activity;
97
+ }
98
+ /** The input containers compile writes on every connector activity (`ioSlot`). */
99
+ const ACTIVITY_CONTAINERS = new Set(['pathParameters', 'queryParameters', 'body']);
100
+ /**
101
+ * An activity's input values by field, across its containers: each
102
+ * `pathParameters` / `queryParameters` / `body` key with its value, and any
103
+ * other row (a multipart `file` part) by its name. This is what the source
104
+ * holds: decompile lifts the containers into one `inputs` object, and compile
105
+ * routes each field to the container the library names. `undefined` when a
106
+ * field sits in two containers, which only a container-by-container compare
107
+ * can tell apart.
108
+ *
109
+ * For instance `{ queryParameters: { start: 0 }, body: { filterGroup: {...} } }`
110
+ * and `{ body: { filterGroup: {...}, start: 0 } }` hold the same fields.
111
+ */
112
+ export function activityFieldValues(values) {
113
+ const out = new Map();
114
+ for (const [name, value] of Object.entries(values)) {
115
+ if (!ACTIVITY_CONTAINERS.has(name)) {
116
+ out.set(`row:${name}`, value);
117
+ continue;
118
+ }
119
+ if (value === undefined || value === null || value === '')
120
+ continue;
121
+ if (!isObject(value))
122
+ return undefined;
123
+ for (const [field, fieldValue] of Object.entries(value)) {
124
+ if (out.has(field))
125
+ return undefined;
126
+ out.set(field, fieldValue);
127
+ }
128
+ }
129
+ return out;
130
+ }
131
+ /**
132
+ * A value's shape: its keys, all the way down, with every leaf value left
133
+ * out, so two values with the same fields and other text compare equal. An
134
+ * `=jsonString:` string is read as the JSON it holds. Under a key in `opaque`
135
+ * the whole value counts as one leaf: a response schema's `properties` and
136
+ * `definitions` are the library's data, not the builder's shape.
137
+ */
138
+ function shape(value, opaque) {
139
+ if (typeof value === 'string' && value.startsWith(JSON_STRING)) {
140
+ try {
141
+ return shape(JSON.parse(value.slice(JSON_STRING.length)), opaque);
142
+ }
143
+ catch {
144
+ return '';
145
+ }
146
+ }
147
+ if (Array.isArray(value))
148
+ return `[${value.map((item) => shape(item, opaque)).join(',')}]`;
149
+ if (isObject(value))
150
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${opaque.has(key) ? '*' : shape(value[key], opaque)}`).join(',')}}`;
151
+ return '';
152
+ }
153
+ /**
154
+ * Whether what compile writes now (`built`) differs from what an SDK wrote
155
+ * (`saved`) only in the library's values: the same fields, other text, ids or
156
+ * kinds. That is a library update, which the saved copy outlives. A different
157
+ * set of fields is the SDK's own builder changing (an older SDK's thinner
158
+ * essential configuration, #1420; its missing `inputMetadata`, #1427; its flat
159
+ * response schema, #1423), which compile repairs on purpose, so the saved copy
160
+ * is not kept.
161
+ *
162
+ * For instance a Slack task's `metadata` whose only difference is
163
+ * `activityMetadata.activity.description` is a library update; one whose
164
+ * configuration lacks `customFieldsRequestDetails` and `operation` is an older
165
+ * SDK's.
166
+ */
167
+ export function onlyLibraryValuesDiffer(built, saved, opaque = new Set()) {
168
+ return stable(built) !== stable(saved) && shape(built, opaque) === shape(saved, opaque);
169
+ }
170
+ /** Whether two input value maps hold the same values, an input on one side only reading as empty. */
171
+ function sameInputs(a, b, kind) {
172
+ const [now, then] = kind === ConnectorKind.Activity ? [activityFieldValues(a), activityFieldValues(b)] : [undefined, undefined];
173
+ const pairs = now && then
174
+ ? [...new Set([...now.keys(), ...then.keys()])].map((key) => [now.get(key), then.get(key)])
175
+ : [...new Set([...Object.keys(a), ...Object.keys(b)])].map((key) => [a[key], b[key]]);
176
+ return pairs.every(([x, y]) => (isEmptyInput(x) && isEmptyInput(y)) || stable(x) === stable(y));
177
+ }
84
178
  /**
85
179
  * Context rows an older Case Designer saves on an `execute-connector-activity`
86
180
  * task that compile never writes there (`connectorTaskData` in serialize.ts):
@@ -135,11 +229,14 @@ const within = (value, fields) => isObject(value) && Object.keys(value).every((k
135
229
  * Whether compile could have written this context: every row and every
136
230
  * `metadata` field is one the SDK's builders write, and the configuration has
137
231
  * no Designer half (`optionalConfiguration`) and no saved `connectorVersion`.
138
- * A context the SDK wrote is left to compile, which rebuilds it from the
139
- * library, so an SDK-authored plan's source carries no copy of it. Anything
140
- * else (Studio Web's `activityMetadata.activity.svgIconUrl`, an event's
141
- * `bindings`, `telemetryData.primaryKeyName`, a `metadata` row with no
232
+ * Anything else (Studio Web's `activityMetadata.activity.svgIconUrl`, an
233
+ * event's `bindings`, `telemetryData.primaryKeyName`, a `metadata` row with no
142
234
  * `type`) is a field compile never writes, so only the saved copy can keep it.
235
+ *
236
+ * A context of this shape is still not one compile WILL write: compile builds
237
+ * the `metadata` body from the library it runs with, and the plan may have been
238
+ * compiled against another one. So the shape alone does not let decompile drop
239
+ * the saved copy ({@link savedConnectorContext}).
143
240
  */
144
241
  function sdkShaped(bag, context) {
145
242
  if (!context.every((row) => within(row, SDK_ROW_FIELDS)))
@@ -169,21 +266,49 @@ function sdkShaped(bag, context) {
169
266
  }
170
267
  /**
171
268
  * The saved context of a connector element, when it has a `metadata` row with
172
- * an object body (the Designer's state) that compile could not have written
173
- * ({@link sdkShaped}); else `undefined`.
269
+ * an object body (the Designer's state) that compile will not write back as it
270
+ * is; else `undefined`.
271
+ *
272
+ * Each step is judged against what compile writes for the unedited source,
273
+ * from the library it runs with (`rebuild`, `rebuiltConnectorElement` in
274
+ * decompile.ts), not against the saved bytes alone:
275
+ *
276
+ * - A context compile could have written ({@link sdkShaped}) is kept when
277
+ * compile writes a `metadata` body that differs from it only in the
278
+ * library's values ({@link onlyLibraryValuesDiffer}): an SDK-authored plan
279
+ * compiled against an older library. The saved copy is what keeps the
280
+ * unedited plan as it was. For instance, a Slack task an SDK compiled when
281
+ * the library described it as `"(Slack) Send a message to an individual user
282
+ * in Slack."` keeps that description after a library that says `"Send a
283
+ * message to an individual user in Slack."`. A body of another shape (an
284
+ * older SDK's builder) is left to compile, which repairs it.
285
+ * - An activity's `inputs` are recorded as compile writes them for the
286
+ * unedited source, so a change compile makes to an input on purpose (an
287
+ * older SDK's `sendAs`, written as the declared `send_as`, #1601) is not
288
+ * read as an edit of the element ({@link unchanged}).
289
+ *
290
+ * Without `rebuild` (a merge, which has no library), or when it cannot work
291
+ * the element out, a context compile could have written is left to compile
292
+ * and the inputs are the saved ones, as before.
174
293
  */
175
- export function savedConnectorContext(owner, bag) {
294
+ export function savedConnectorContext(owner, bag, rebuild) {
176
295
  const context = bag?.context;
177
296
  if (!Array.isArray(context) || !context.every(isObject))
178
297
  return undefined;
179
298
  if (!context.some((row) => row.name === 'metadata' && isObject(row.body)))
180
299
  return undefined;
181
- if (sdkShaped(bag, context))
182
- return undefined;
300
+ const rebuilt = rebuild?.();
301
+ if (sdkShaped(bag, context)) {
302
+ const body = context.find((row) => row.name === 'metadata').body;
303
+ if (rebuilt?.metadata === undefined || !onlyLibraryValuesDiffer(rebuilt.metadata, body))
304
+ return undefined;
305
+ }
183
306
  const inputs = inputValues(bag);
184
307
  // A subscription body saved with no match expression compares as compile writes it.
185
308
  if (EVENT_SERVICE_TYPES.has(bag.serviceType) && inputs.body !== undefined)
186
309
  inputs.body = withScopeExpression(inputs.body, owner);
310
+ else if (rebuilt?.containers)
311
+ Object.assign(inputs, structuredClone(rebuilt.containers));
187
312
  return { owner, context: structuredClone(context), inputs };
188
313
  }
189
314
  /** Whether a wire `activityType` is a generic CRUD one (`Generic`, `GenericExpanded`, `GenericTrigger`). */
@@ -234,7 +359,10 @@ function wireActivityType(context) {
234
359
  * generic twin gets compile's context. The activity type id is not
235
360
  * compared: it is the saving catalog's, not the action's;
236
361
  * - every input holds the same value (an input only one side has must be
237
- * empty, as compile writes `body: {}` for an unused container).
362
+ * empty, as compile writes `body: {}` for an unused container). On an
363
+ * activity the values are compared field by field across the containers
364
+ * ({@link activityFieldValues}), as the source holds them: where a field
365
+ * rides is the library's routing, not an edit.
238
366
  */
239
367
  function unchanged(bag, entry, v2) {
240
368
  const built = Array.isArray(bag.context) ? bag.context.filter(isObject) : [];
@@ -261,15 +389,7 @@ function unchanged(bag, entry, v2) {
261
389
  // compile writes as `CuratedTrigger`).
262
390
  if (now && then && isGenericKind(now) !== isGenericKind(then))
263
391
  return false;
264
- const values = inputValues(bag);
265
- for (const name of new Set([...Object.keys(values), ...Object.keys(entry.inputs)])) {
266
- const [a, b] = [values[name], entry.inputs[name]];
267
- if (isEmptyInput(a) && isEmptyInput(b))
268
- continue;
269
- if (stable(a) !== stable(b))
270
- return false;
271
- }
272
- return true;
392
+ return sameInputs(inputValues(bag), entry.inputs, connectorKind(bag));
273
393
  }
274
394
  /**
275
395
  * Write each saved connector context back onto the element compile built for
@@ -1,3 +1,66 @@
1
+ /**
2
+ * A Designer-saved connector element's own io rows, kept through a decompile
3
+ * -> compile round trip while the element is unchanged.
4
+ *
5
+ * Four elements call Integration Service: an event trigger, a
6
+ * wait-for-connector task or rule, and an `execute-connector-activity` task.
7
+ * Each has rows of its own, which compile rebuilds from the library:
8
+ *
9
+ * - inputs: the request containers (`pathParameters`, `queryParameters`,
10
+ * `body`, a multipart `file` part; an event's `body` subscription), each
11
+ * written `{ name, type, target, body, var: "v<name>", id, elementId }`, with
12
+ * `body: {}` for an unused container (`ioSlot`, `eventInput`);
13
+ * - outputs: `response` (`source: "=response"`) and `Error` (`source:
14
+ * "=Error"`), written with `displayName: "Response"`, a `target: "=<var>"`,
15
+ * and the response schema built from the library's flat output fields
16
+ * (`connectorOutputs`), titles and types only.
17
+ *
18
+ * That is right for a new element. For one Studio Web saved, it rewrote those
19
+ * rows on the first round trip, even with no edit. The Designer saves its own
20
+ * copies: an event `body` row with no `id`, `var` or `elementId`; a container
21
+ * with no `body`, or no row at all for an unused one; an output label the
22
+ * author picked (`"Attachment"`), no `target`, the `_jsonSchema` copy of the
23
+ * body, and the schema as Integration Service described it (field
24
+ * `description`s, an array root); some elements have one output row or none.
25
+ *
26
+ * So decompile records each such element's own rows verbatim, with the
27
+ * operation they were saved for, keyed by owner (`trigger:<node id>`,
28
+ * `task:<task id>` or `rule:<stage id>:<rule id>`). Compile writes each half
29
+ * back while it still describes the element:
30
+ *
31
+ * - outputs, while the element calls the same operation (same `connectorKey`,
32
+ * `objectName`, `method`, `path` and event `operation`) and each saved row's
33
+ * compiled counterpart writes the same variable, or the saved row is the
34
+ * Designer's reassignment of the output to a case variable the plan still
35
+ * declares (`reassignedToCaseVariable`);
36
+ * - inputs, while it calls the same operation and every input holds the value
37
+ * it was saved with (an input only one side has must be empty).
38
+ *
39
+ * Any other edit gets the rows compile built, as before: another operation
40
+ * has another response, and an edited value must be written.
41
+ *
42
+ * For instance, an Outlook "Email received" trigger saved with `inputs: [{
43
+ * name: "body", type: "json", target: "body", body: { filters: … } }]` (no
44
+ * id) and no `outputs` comes back that way while it watches the same folder.
45
+ * Point it at another folder and compile writes its own `vbody` row.
46
+ *
47
+ * An element whose rows are what compile writes anyway (an SDK-authored
48
+ * plan's, compiled against the library decompile reads) records nothing for
49
+ * that half, so its source carries no copy. One an SDK compiled against an
50
+ * older library (another `response` schema, a field in another container) is
51
+ * kept like a Designer's: a library update is no edit.
52
+ *
53
+ * The author's extracts (`.outputs({ createdById: '=response.CreatedBy.Id' })`)
54
+ * are compile's to write, but the Designer saves them with a field compile
55
+ * does not write (`displayName: 'CreatedBy.Id'`), and without one it does
56
+ * (`target`) or with a stale one (`target: '=id15'` on the row `id16`, kept
57
+ * from the task it was copied from). `extracts` records that difference per extract, keyed by the
58
+ * `source` it reads and the `var` it writes, and compile puts it back on the
59
+ * row that still reads that source into that variable, while the element calls
60
+ * the same operation. An extract the author edits (another source or
61
+ * variable) gets compile's row.
62
+ */
63
+ import { type RebuiltConnectorElement } from './connector-saved-context.js';
1
64
  /** One half (inputs or outputs) of a saved connector element's own rows. */
2
65
  export interface PreservedConnectorRowSet {
3
66
  /** The own rows, verbatim, in saved order. */
@@ -57,7 +120,7 @@ export declare function caseConnectorRowOwners(plan: Record<string, any>): Array
57
120
  * another element (not one of `elementIds`, its own id's spellings), or no such
58
121
  * field. Else `undefined`.
59
122
  */
60
- export declare function savedConnectorRows(owner: string, bag: Record<string, any>, elementIds?: readonly string[]): PreservedConnectorRows | undefined;
123
+ export declare function savedConnectorRows(owner: string, bag: Record<string, any>, elementIds?: readonly string[], rebuild?: () => RebuiltConnectorElement | undefined): PreservedConnectorRows | undefined;
61
124
  /**
62
125
  * The own output rows compile built that {@link applyConnectorRows} drops: on an
63
126
  * element saved without that row (`Error` only, say), while it calls the same
@@ -45,7 +45,10 @@
45
45
  * Point it at another folder and compile writes its own `vbody` row.
46
46
  *
47
47
  * An element whose rows are what compile writes anyway (an SDK-authored
48
- * plan's) records nothing for that half, so its source carries no copy.
48
+ * plan's, compiled against the library decompile reads) records nothing for
49
+ * that half, so its source carries no copy. One an SDK compiled against an
50
+ * older library (another `response` schema, a field in another container) is
51
+ * kept like a Designer's: a library update is no edit.
49
52
  *
50
53
  * The author's extracts (`.outputs({ createdById: '=response.CreatedBy.Id' })`)
51
54
  * are compile's to write, but the Designer saves them with a field compile
@@ -57,12 +60,18 @@
57
60
  * the same operation. An extract the author edits (another source or
58
61
  * variable) gets compile's row.
59
62
  */
60
- import { comparesContextRow } from './connector-saved-context.js';
63
+ import { activityFieldValues, comparesContextRow, ConnectorKind, connectorKind, onlyLibraryValuesDiffer } from './connector-saved-context.js';
61
64
  import { caseSubscriptionOwners, withScopeExpression } from './subscription.js';
65
+ /** Two input values that hold the same thing: both empty, or equal with key order not counting. */
66
+ function sameInput(a, b) {
67
+ return (isEmpty(a) && isEmpty(b)) || stable(a) === stable(b);
68
+ }
62
69
  const CONNECTOR_ACTIVITY_TYPE = 'execute-connector-activity';
63
70
  /** The context rows that name the operation an element calls. */
64
71
  const OPERATION_ROWS = ['connectorKey', 'objectName', 'method', 'path', 'operation'];
65
72
  const OWN_SOURCES = new Set(['=response', '=Error']);
73
+ /** A response schema's library data: its fields and the objects they nest in. */
74
+ const SCHEMA_DATA = new Set(['properties', 'definitions']);
66
75
  /** The input containers compile writes on every connector activity (`ioSlot`). */
67
76
  const ACTIVITY_CONTAINERS = ['pathParameters', 'queryParameters', 'body'];
68
77
  const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
@@ -184,8 +193,13 @@ function sdkShapedInput(row, elementIds) {
184
193
  return row.target === 'file' && row.body === undefined;
185
194
  return row.type === 'json' && row.target === row.name && (row.body !== undefined) !== (row.value !== undefined);
186
195
  }
187
- /** The saved outputs half, when compile would not write it as it is. */
188
- function savedOutputs(bag, elementIds) {
196
+ /**
197
+ * The saved outputs half, when compile would not write it as it is: rows in
198
+ * another shape, or a `response` schema of the shape compile writes but with
199
+ * other fields than the library's now (`rebuilt`), as an SDK that compiled
200
+ * against an older library wrote it.
201
+ */
202
+ function savedOutputs(bag, elementIds, rebuilt) {
189
203
  if (bag.outputs !== undefined && !Array.isArray(bag.outputs))
190
204
  return undefined;
191
205
  const rows = (bag.outputs ?? []).filter(isOwnOutput);
@@ -195,12 +209,23 @@ function savedOutputs(bag, elementIds) {
195
209
  if (sources.size !== rows.length)
196
210
  return undefined;
197
211
  const complete = rows.length === 2 && sources.size === 2;
198
- if (bag.outputs !== undefined && complete && rows.every((row) => sdkShapedOutput(row, elementIds)))
212
+ const response = rows.find((row) => row.source === '=response');
213
+ // A schema of the shape compile writes, with the library's other fields, is
214
+ // a library update; another shape is an older SDK's, which compile repairs.
215
+ const libraryWrites = rebuilt?.responseSchema === undefined
216
+ || !onlyLibraryValuesDiffer(rebuilt.responseSchema, response?.body, SCHEMA_DATA);
217
+ if (bag.outputs !== undefined && complete && rows.every((row) => sdkShapedOutput(row, elementIds)) && libraryWrites)
199
218
  return undefined;
200
219
  return { rows: structuredClone(rows), ...(bag.outputs === undefined ? { absent: true } : {}) };
201
220
  }
202
- /** The saved inputs half, when compile would not write it as it is. */
203
- function savedInputs(bag, activity, elementIds, owner) {
221
+ /**
222
+ * The saved inputs half, when compile would not write it as it is: rows in
223
+ * another shape, or an activity whose fields hold what compile writes but sit
224
+ * in other containers than the library routes them to (`rebuilt`): a plan
225
+ * saved against a connector version that took `start` in the body, compiled
226
+ * by a library that routes it to the query string.
227
+ */
228
+ function savedInputs(bag, activity, elementIds, owner, rebuilt) {
204
229
  if (bag.inputs !== undefined && !Array.isArray(bag.inputs))
205
230
  return undefined;
206
231
  const rows = bag.inputs ?? [];
@@ -211,7 +236,18 @@ function savedInputs(bag, activity, elementIds, owner) {
211
236
  if (names.size !== rows.length)
212
237
  return undefined;
213
238
  const complete = activity ? ACTIVITY_CONTAINERS.every((name) => names.has(name)) : rows.length === 1;
214
- if (bag.inputs !== undefined && complete && rows.every((row) => sdkShapedInput(row, elementIds)))
239
+ // Kept only when the fields hold what compile writes but sit in other
240
+ // containers: that is the library's routing. Other values (an older SDK's
241
+ // `sendAs`, which compile writes as `send_as`) are compile's to repair, and
242
+ // an event's subscription body is judged by its shape alone, as before.
243
+ const containers = rebuilt?.containers;
244
+ const saved = Object.fromEntries(rows.map((row) => [String(row.name), inputValue(row)]));
245
+ const [now, then] = containers ? [activityFieldValues(containers), activityFieldValues(saved)] : [undefined, undefined];
246
+ const rerouted = activity && containers !== undefined && now !== undefined && then !== undefined
247
+ && [...new Set([...now.keys(), ...then.keys()])].every((field) => field.startsWith('row:') || sameInput(now.get(field), then.get(field)))
248
+ && !rows.every((row) => row.type === 'file' || sameInput(inputValue(row), containers[String(row.name)]));
249
+ const libraryRoutes = !rerouted;
250
+ if (bag.inputs !== undefined && complete && rows.every((row) => sdkShapedInput(row, elementIds)) && libraryRoutes)
215
251
  return undefined;
216
252
  // A subscription body saved with no match expression is carried as compile
217
253
  // writes it (`withScopeExpression`): the engine needs the expression.
@@ -225,13 +261,15 @@ function savedInputs(bag, activity, elementIds, owner) {
225
261
  * another element (not one of `elementIds`, its own id's spellings), or no such
226
262
  * field. Else `undefined`.
227
263
  */
228
- export function savedConnectorRows(owner, bag, elementIds) {
264
+ export function savedConnectorRows(owner, bag, elementIds, rebuild) {
229
265
  const operation = operationOf(bag);
230
266
  if (operation.connectorKey === undefined)
231
267
  return undefined;
232
268
  const activity = bag.serviceType !== 'Intsvc.EventTrigger' && bag.serviceType !== 'Intsvc.WaitForEvent';
233
- const outputs = savedOutputs(bag, elementIds);
234
- const inputs = savedInputs(bag, activity, elementIds, owner);
269
+ // Without a library (a merge), or an element it cannot rebuild, the shape decides, as before.
270
+ const rebuilt = rebuild?.();
271
+ const outputs = savedOutputs(bag, elementIds, rebuilt);
272
+ const inputs = savedInputs(bag, activity, elementIds, owner, rebuilt);
235
273
  const extracts = savedExtracts(bag);
236
274
  if (!outputs && !inputs && !extracts)
237
275
  return undefined;
@@ -405,10 +443,31 @@ function inputValue(row) {
405
443
  return undefined;
406
444
  return row.body !== undefined ? row.body : row.value;
407
445
  }
408
- /** The saved inputs, when every input holds the value it was saved with; else nothing. */
409
- function inputsBack(built, set) {
446
+ /**
447
+ * The saved inputs, when every input holds the value it was saved with; else
448
+ * nothing.
449
+ *
450
+ * On an activity the values are compared field by field, not container by
451
+ * container ({@link activityFieldValues}): a field the plan was saved with in
452
+ * the body and that the library now routes to the query string holds the same
453
+ * value, and the source cannot say where it goes. For instance, a query task
454
+ * saved with `body: { filterGroup, start: 0, limit: 20 }` that compile writes
455
+ * as `queryParameters: { start: 0, limit: 20 }, body: { filterGroup }` gets its
456
+ * saved rows back; one whose `limit` the edit changed gets compile's.
457
+ */
458
+ function inputsBack(built, set, kind) {
410
459
  if (!built.every(isInputRow))
411
460
  return undefined;
461
+ if (kind === ConnectorKind.Activity) {
462
+ const byName = (rows) => Object.fromEntries(rows.map((row) => [String(row.name), inputValue(row)]));
463
+ const [now, then] = [activityFieldValues(byName(built)), activityFieldValues(byName(set.rows))];
464
+ if (now && then) {
465
+ for (const field of new Set([...now.keys(), ...then.keys()]))
466
+ if (!sameInput(now.get(field), then.get(field)))
467
+ return undefined;
468
+ return structuredClone(set.rows);
469
+ }
470
+ }
412
471
  const builtByName = new Map(built.map((row) => [row.name, row]));
413
472
  const savedByName = new Map(set.rows.map((row) => [row.name, row]));
414
473
  for (const name of new Set([...builtByName.keys(), ...savedByName.keys()])) {
@@ -481,7 +540,7 @@ export function applyConnectorRows(result, entries) {
481
540
  if (!set)
482
541
  continue;
483
542
  const built = Array.isArray(bag[field]) ? bag[field] : [];
484
- const back = field === 'inputs' ? inputsBack(built, set) : outputsBack(built, set, caseVariables);
543
+ const back = field === 'inputs' ? inputsBack(built, set, connectorKind(bag)) : outputsBack(built, set, caseVariables);
485
544
  if (!back)
486
545
  continue;
487
546
  if (set.absent && back.length === 0)
@@ -361,7 +361,7 @@ type Preservation = {
361
361
  * `decompile` embeds in a `preserveCaseJson(...)` payload, only read from the
362
362
  * original file at merge time instead.
363
363
  */
364
- export declare function collectPreservation(plan: CasePlan): Preservation | undefined;
364
+ export declare function collectPreservation(plan: CasePlan, library?: Library): Preservation | undefined;
365
365
  export declare function decompileWithDiagnostics(plan: CasePlan, options?: DecompileOptions): CaseDecompileResult;
366
366
  export declare function decompile(plan: CasePlan, options?: DecompileOptions): string;
367
367
  export {};
@@ -9,6 +9,10 @@ import { isScriptOwnOutput, liftScript } from './decompile-script.js';
9
9
  import { isHttpRequestOwnOutput, liftHttpRequest } from './decompile-http-request.js';
10
10
  import { savedHttpRequestMetadata } from './http-request.js';
11
11
  import { caseConnectorOwners, savedConnectorContext } from './connector-saved-context.js';
12
+ import { connectorActivityMetadata, connectorEventMetadata } from '../core/connector-v2-metadata.js';
13
+ import { buildConnectorInputs, nestConnectorBody } from '../core/connector-inputs.js';
14
+ import { responseJsonSchema } from '../core/connector-response-schema.js';
15
+ import { EQUALS_EXPR_DIALECT } from '../core/connector-checks.js';
12
16
  import { elementConfigV2Owners } from './intsvc-activity-config.js';
13
17
  import { caseConnectorRowOwners, savedConnectorRows } from './connector-saved-rows.js';
14
18
  import { builtChainSource, chainStatements } from '../core/builder-chain.js';
@@ -2983,6 +2987,85 @@ function savedResourceWires(plan) {
2983
2987
  * The same list is `PRESERVED_VARIABLE_KEYS` in preserve.ts, which validates a payload.
2984
2988
  */
2985
2989
  const PRESERVED_VARIABLE_FIELDS = new Set(['subType', 'canonicalId', 'camelizedId', 'variableType', 'internal', 'description', 'value']);
2990
+ /**
2991
+ * What compile writes for a connector element from `library`, as far as a
2992
+ * saved copy is judged by it: the `metadata` body (`connectorActivityMetadata`,
2993
+ * `connectorEventMetadata`), an activity's input containers (`pathParameters`,
2994
+ * `queryParameters`, `body`, as `buildConnectorInputs` routes the element's
2995
+ * inputs) and the `response` schema (`responseJsonSchema` of the operation's
2996
+ * output fields). The same builders compile runs, on the operation the
2997
+ * element's rows name (`identifyAction`, `identifyEvent`, as the element is
2998
+ * decompiled) and with the element's own inputs. An event's filter tree is the
2999
+ * saved one: compile builds it from the filters decompile lifts out of it.
3000
+ *
3001
+ * `seed` is the element id an activity's configuration ids are minted from;
3002
+ * without it there is no activity `metadata`. `undefined` when any step fails.
3003
+ *
3004
+ * Decompile compares it with a context or row set compile could have written
3005
+ * (`connector-saved-context.ts`, `connector-saved-rows.ts`), to tell one this
3006
+ * library writes again from one an older library wrote.
3007
+ */
3008
+ function rebuiltConnectorElement(library, owner, bag, seed) {
3009
+ try {
3010
+ const context = contextMap(bag);
3011
+ const text = (name) => {
3012
+ const value = context.get(name)?.value;
3013
+ return typeof value === 'string' ? value : undefined;
3014
+ };
3015
+ const connectorKey = text('connectorKey');
3016
+ if (connectorKey === undefined)
3017
+ return undefined;
3018
+ const configuration = savedConfiguration(context);
3019
+ const responseSchema = (rc) => ({
3020
+ $schema: 'http://json-schema.org/draft-07/schema#',
3021
+ ...(rc.entry.outputSchema ? responseJsonSchema(rc.entry.outputSchema.fields ?? []) : { type: 'object', properties: {} }),
3022
+ });
3023
+ if (bag.serviceType === CASE_FORMAT_PROFILE.waitConnectorServiceType || bag.serviceType === CASE_FORMAT_PROFILE.eventServiceType) {
3024
+ const kind = owner.startsWith('trigger:') ? 'trigger' : 'event';
3025
+ const identity = library.identifyEvent(kind, {
3026
+ connectorKey,
3027
+ objectName: text('objectName'),
3028
+ eventOperation: text('operation'),
3029
+ eventMode: context.get('metadata')?.body?.activityPropertyConfiguration?.eventMode,
3030
+ version: configuration?.essentialConfiguration?.packageVersion,
3031
+ });
3032
+ const rc = library.resolveEvent(kind, identity.key, identity.event, identity.version, identity.object);
3033
+ return {
3034
+ metadata: connectorEventMetadata(rc, rc.entry.operation ?? {}, configuration?.essentialConfiguration?.filter ?? null),
3035
+ responseSchema: responseSchema(rc),
3036
+ };
3037
+ }
3038
+ const identity = library.identifyAction({
3039
+ connectorKey,
3040
+ httpMethod: text('method'),
3041
+ endpoint: text('path'),
3042
+ objectName: text('objectName'),
3043
+ version: connectorVersion(context),
3044
+ activityType: connectorActivityType(context),
3045
+ });
3046
+ // The fields the saved field list declares and the library lacks ride along, as `connectorCall` carries them.
3047
+ const fromLibrary = library.resolve(identity.key, identity.action, identity.version, identity.object);
3048
+ const rc = withCarriedFields(fromLibrary, savedFieldsMissingFromLibrary(configuration, fromLibrary));
3049
+ const inputs = connectorInputs(Array.isArray(bag.inputs) ? bag.inputs : [], rc, undefined, owner);
3050
+ const slots = buildConnectorInputs(rc, inputs, {
3051
+ dialect: EQUALS_EXPR_DIALECT,
3052
+ resolutions: library.lookupResolutions,
3053
+ lookups: library.lookupSpecs(identity.key, identity.action, identity.version, identity.object),
3054
+ });
3055
+ return {
3056
+ ...(seed !== undefined ? { metadata: connectorActivityMetadata(rc, rc.entry.operation ?? {}, slots, seed) } : {}),
3057
+ containers: {
3058
+ pathParameters: { ...slots.pathParameters },
3059
+ queryParameters: { ...slots.queryParameters },
3060
+ body: nestConnectorBody(slots.bodyParameters ?? {}),
3061
+ },
3062
+ responseSchema: responseSchema(rc),
3063
+ };
3064
+ }
3065
+ catch {
3066
+ return undefined;
3067
+ }
3068
+ }
2986
3069
  /**
2987
3070
  * Everything the ORIGINAL document owns and the typed builder does not model —
2988
3071
  * ids, layout, platform metadata, annotation nodes, node order, designer
@@ -2990,7 +3073,7 @@ const PRESERVED_VARIABLE_FIELDS = new Set(['subType', 'canonicalId', 'camelizedI
2990
3073
  * `decompile` embeds in a `preserveCaseJson(...)` payload, only read from the
2991
3074
  * original file at merge time instead.
2992
3075
  */
2993
- export function collectPreservation(plan) {
3076
+ export function collectPreservation(plan, library) {
2994
3077
  const preservation = { identities: identityPreservation(plan) };
2995
3078
  const topKnown = new Set(['id', 'name', 'description', 'version', 'bindings', 'variables', 'metadata', 'nodes', 'edges', 'layout']);
2996
3079
  const topLevel = Object.fromEntries(Object.entries(plan).filter(([name]) => !topKnown.has(name)));
@@ -3258,8 +3341,16 @@ export function collectPreservation(plan) {
3258
3341
  preservation.connectorConfigurations = connectorConfigurations;
3259
3342
  if (httpRequestMetadata.length)
3260
3343
  preservation.httpRequestMetadata = httpRequestMetadata;
3344
+ // What compile writes for each connector element from this library, to tell
3345
+ // a saved copy it writes again from one an older library wrote.
3261
3346
  const connectorContexts = caseConnectorOwners(plan)
3262
- .map(({ key, bag }) => savedConnectorContext(key, bag))
3347
+ .map(({ key, bag }) => savedConnectorContext(key, bag, library
3348
+ ? () => {
3349
+ // `task:<stage id>:<task id>`: an activity's configuration ids are minted from `<stage id>-<task id>`.
3350
+ const [kind, stageId, ...own] = key.split(':');
3351
+ return rebuiltConnectorElement(library, key, bag, kind === 'task' ? `${stageId}-${own.join(':')}` : undefined);
3352
+ }
3353
+ : undefined))
3263
3354
  .filter((entry) => entry !== undefined);
3264
3355
  if (connectorContexts.length)
3265
3356
  preservation.connectorContexts = connectorContexts;
@@ -3267,7 +3358,7 @@ export function collectPreservation(plan) {
3267
3358
  if (connectorConfigV2.length)
3268
3359
  preservation.connectorConfigV2 = connectorConfigV2;
3269
3360
  const connectorRows = caseConnectorRowOwners(plan)
3270
- .map(({ key, bag, elementIds }) => savedConnectorRows(key, bag, elementIds))
3361
+ .map(({ key, bag, elementIds }) => savedConnectorRows(key, bag, elementIds, library ? () => rebuiltConnectorElement(library, key, bag) : undefined))
3271
3362
  .filter((entry) => entry !== undefined);
3272
3363
  if (connectorRows.length)
3273
3364
  preservation.connectorRows = connectorRows;
@@ -3447,7 +3538,7 @@ export function decompileWithDiagnostics(plan, options = {}) {
3447
3538
  const diagnostics = [];
3448
3539
  refuseUnsupportedAuthoring(plan);
3449
3540
  plan = raiseTaskOutputRefs(plan);
3450
- const preservation = collectPreservation(plan);
3541
+ const preservation = collectPreservation(plan, options.library);
3451
3542
  const refs = buildRefs(plan, options.library, options.bestEffort ? diagnostics : undefined);
3452
3543
  const selectNextStage = selectNextStageByExit(plan, refs);
3453
3544
  const metadata = plan.metadata ?? {};
@@ -1,5 +1,6 @@
1
1
  /** The document node family, as flow-node-registry.ts lists it: Document Classify, Dynamic Extract and an IxP project's extractor. */
2
2
  import type { FlowNodeFamily } from '../../../flow-node-type.js';
3
+ export { isIxpNodeType } from './ixp.js';
3
4
  export declare const documentFlowFamily: FlowNodeFamily;
4
5
  /**
5
6
  * The IDP processor rules, for `compile` (`idp-processor-files.ts`) and
@@ -1,4 +1,5 @@
1
1
  import { IXP_DIAGNOSTICS, ixpExtractNodeType } from './ixp.js';
2
+ export { isIxpNodeType } from './ixp.js';
2
3
  import { documentClassifyNodeType, DOCUMENT_DIAGNOSTICS, dynamicExtractNodeType } from './node-type.js';
3
4
  export const documentFlowFamily = {
4
5
  id: 'document',
@@ -5,6 +5,15 @@ export type IxpExtractSpec = {
5
5
  kind: 'ixpExtract';
6
6
  inputs: IxpExtractInputs;
7
7
  };
8
+ /**
9
+ * Whether a node of `typeName` is an IxP node instance, which carries no
10
+ * node-level `model`: the slim `{ type, serviceType }` lives only in
11
+ * `definitions[]`, and `flow validate` rejects a node-level copy on every
12
+ * `uipath.ixp.*` node ("Top-level `model` block is forbidden on IxP node
13
+ * instances"). Keyed on the prefix, as the product's rule is, so it holds for
14
+ * a type no factory owns as well as for `ixpExtract()` and `dynamicExtract()`.
15
+ */
16
+ export declare function isIxpNodeType(typeName: string): boolean;
8
17
  export declare const IXP_DIAGNOSTICS: DiagnosticCatalog;
9
18
  /**
10
19
  * Build the definition for one published IxP project.
@@ -17,6 +17,17 @@ import { parseIxpProjectType } from './spec.js';
17
17
  import { CompileRefusal } from '../../../core/compile-refusal.js';
18
18
  import { declareKeys } from '../../../core/option-keys.js';
19
19
  const IXP_PREFIX = 'uipath.ixp.';
20
+ /**
21
+ * Whether a node of `typeName` is an IxP node instance, which carries no
22
+ * node-level `model`: the slim `{ type, serviceType }` lives only in
23
+ * `definitions[]`, and `flow validate` rejects a node-level copy on every
24
+ * `uipath.ixp.*` node ("Top-level `model` block is forbidden on IxP node
25
+ * instances"). Keyed on the prefix, as the product's rule is, so it holds for
26
+ * a type no factory owns as well as for `ixpExtract()` and `dynamicExtract()`.
27
+ */
28
+ export function isIxpNodeType(typeName) {
29
+ return typeName.startsWith(IXP_PREFIX);
30
+ }
20
31
  export const IXP_DIAGNOSTICS = {
21
32
  IXP_FORBIDDEN_INPUT: { severity: 'error', summary: 'an IxP step setting an input the current node does not declare' },
22
33
  IXP_NO_FILE: { severity: 'error', summary: 'an IxP step with no fileRef' },
@@ -351,8 +351,8 @@ export const dynamicExtractNodeType = {
351
351
  },
352
352
  // IxP instances must NOT carry the manifest's model block — the slim
353
353
  // { type, serviceType } lives only in definitions[] (product validate
354
- // rejects a node-level copy). Per call, not `nodeModel`: a rawNode of this
355
- // type keeps the model it always had.
354
+ // rejects a node-level copy). `makeNode` drops it for every
355
+ // `uipath.ixp.*` node, a rawNode included (`isIxpNodeType`).
356
356
  model: 'omit',
357
357
  };
358
358
  },
package/dist/serialize.js CHANGED
@@ -13,6 +13,7 @@ import { Expr, toExpr, flatNameSegmentsOf, parallelFork } from './flow-sdk.js';
13
13
  import { FlowAction, FlowTrigger } from './core/node-classes.js';
14
14
  import { connectorRawNodeRefusal } from './nodes/connector/flow/family.js';
15
15
  import { isAgentResourceType } from './nodes/agent/flow/family.js';
16
+ import { isIxpNodeType } from './nodes/document/flow/family.js';
16
17
  import { CompileRefusal, LibraryRequiredRefusal } from './core/compile-refusal.js';
17
18
  import { nearestName } from './core/edit-distance.js';
18
19
  import { unknownOptionRefusal } from './core/option-keys.js';
@@ -1879,8 +1880,10 @@ function serializeFlow(built, opts) {
1879
1880
  col++;
1880
1881
  // A registered node type may carry no node-level `model`, whichever path
1881
1882
  // emits it (its own serialize, or a rawNode through emitContribution) — the
1882
- // Data Fabric verbs, whose reasons are in their family (`nodeModel`).
1883
- const omitModel = registeredRawType(type, String(def?.version ?? ''))?.impl.nodeModel === 'omit';
1883
+ // Data Fabric verbs, whose reasons are in their family (`nodeModel`). Every
1884
+ // IxP node omits it too, registered type or not (`isIxpNodeType`).
1885
+ const omitModel = isIxpNodeType(type)
1886
+ || registeredRawType(type, String(def?.version ?? ''))?.impl.nodeModel === 'omit';
1884
1887
  if (def?.model && !omitModel)
1885
1888
  node.model = subNodeId(jsonClone(def.model), id);
1886
1889
  if (def?.outputDefinition)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.122.2",
3
+ "version": "6.122.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",
@@ -126,5 +126,5 @@
126
126
  "@types/node": "^22.7.0",
127
127
  "esbuild": "^0.28.1"
128
128
  },
129
- "gitref": "9dc07468c4ac6ba476bb237a0bbc206e3c3f22ab"
129
+ "gitref": "251bc711e6f04958da7a3bf9952d181ff03a7b08"
130
130
  }