@uipath/maestro-builder-sdk 6.93.2 → 6.93.3

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.
@@ -0,0 +1,34 @@
1
+ /** One saved connector element context, as `preserveCaseJson` carries it. */
2
+ export interface PreservedConnectorContext {
3
+ /** `trigger:<node id>`, `task:<stage id>:<task id>` or `rule:<stage id>:<rule id>`. */
4
+ owner: string;
5
+ /** The element's `context` list, verbatim. */
6
+ context: Array<Record<string, unknown>>;
7
+ /** Each input row's saved value (`body`, else `value`), by row name. */
8
+ inputs: Record<string, unknown>;
9
+ }
10
+ /**
11
+ * Every connector element in a plan with the bag that holds its `context`:
12
+ * the event subscriptions (`caseSubscriptionOwners`), and each
13
+ * `execute-connector-activity` task, keyed `task:<stage id>:<task id>` as a
14
+ * wait-for-connector task is.
15
+ */
16
+ export declare function caseConnectorOwners(plan: Record<string, any>): Array<{
17
+ key: string;
18
+ bag: Record<string, any>;
19
+ }>;
20
+ /**
21
+ * The saved context of a connector element, when it has a `metadata` row with
22
+ * an object body (the Designer's state) that compile could not have written
23
+ * ({@link sdkShaped}); else `undefined`.
24
+ */
25
+ export declare function savedConnectorContext(owner: string, bag: Record<string, any>): PreservedConnectorContext | undefined;
26
+ /**
27
+ * Write each saved connector context back onto the element compile built for
28
+ * the same owner, while that element is unchanged ({@link unchanged}). Runs
29
+ * after the ids are restored, so an owner key finds its element by the plan's
30
+ * own ids, also after a rename.
31
+ */
32
+ export declare function applyConnectorContexts(result: Record<string, any>, entries: readonly PreservedConnectorContext[] | undefined): void;
33
+ /** Problems with a payload's `connectorContexts`, for `caseJsonPreservationErrors`. */
34
+ export declare function connectorContextErrors(entries: unknown): string[];
@@ -0,0 +1,281 @@
1
+ /**
2
+ * A Designer-saved connector element's `context`, 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, a wait-for-connector rule, and an
7
+ * `execute-connector-activity` task. Each carries a `context` list: the
8
+ * connector rows (`connectorKey`, `connection`, `objectName`, `method`,
9
+ * `path`, ...) and a `metadata` row whose body is the Designer's state for
10
+ * that element (`activityPropertyConfiguration`, `activityMetadata`,
11
+ * `inputMetadata`, `telemetryData`, and, on an event, the `bindings` that name
12
+ * its trigger parameters and the `filterExpression` it shows).
13
+ *
14
+ * Compile rebuilds that `metadata` body from the library
15
+ * (`core/connector-v2-metadata.ts`): the functional half only, with no
16
+ * Designer cosmetics, no saved `connectorVersion`, and no event `bindings` or
17
+ * `filterExpression`. That is right for a new element. For one Studio Web
18
+ * saved, it rewrote the whole body on the first round trip, even with no edit:
19
+ * no Designer-saved connector trigger, wait or activity in the brownfield
20
+ * corpus came back as it was saved.
21
+ *
22
+ * So decompile records each connector element's saved `context` verbatim,
23
+ * with the input values it was saved against, keyed by owner
24
+ * (`caseConnectorOwners`). Compile writes the saved `context` back only while
25
+ * the element is unchanged: every connector row both sides carry holds the
26
+ * same value (the same connector, operation, connection and folder), and every
27
+ * input row holds the same value. Any edit to those, or a deleted element,
28
+ * gets the `context` compile built, as before. The `metadata` body describes
29
+ * input values (an event's filter, its trigger parameter `bindings`, the
30
+ * Designer's display caches), so a value edit must not keep it.
31
+ *
32
+ * For instance, an Outlook "Email Received" trigger saved with
33
+ * `filterExpression: "(parentFolderId == 'AAMk...')"` and a `bindings` entry
34
+ * for `parentFolderId` keeps both while the source still filters on that
35
+ * folder. Point it at another folder and compile writes its own body.
36
+ */
37
+ import { caseSubscriptionOwners } from './subscription.js';
38
+ const CONNECTOR_ACTIVITY_TYPE = 'execute-connector-activity';
39
+ /**
40
+ * Every connector element in a plan with the bag that holds its `context`:
41
+ * the event subscriptions (`caseSubscriptionOwners`), and each
42
+ * `execute-connector-activity` task, keyed `task:<stage id>:<task id>` as a
43
+ * wait-for-connector task is.
44
+ */
45
+ export function caseConnectorOwners(plan) {
46
+ const out = caseSubscriptionOwners(plan);
47
+ for (const node of Array.isArray(plan?.nodes) ? plan.nodes : []) {
48
+ if (!String(node?.type ?? '').endsWith('Stage'))
49
+ continue;
50
+ for (const lane of Array.isArray(node.data?.tasks) ? node.data.tasks : [])
51
+ for (const task of Array.isArray(lane) ? lane : [])
52
+ if (task?.type === CONNECTOR_ACTIVITY_TYPE && task.data && typeof task.data === 'object')
53
+ out.push({ key: `task:${node.id}:${task.id}`, bag: task.data });
54
+ }
55
+ return out;
56
+ }
57
+ const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
58
+ /** The value an input row holds: its `body`, else its `value`. */
59
+ function inputValue(row) {
60
+ return row.body !== undefined ? row.body : row.value;
61
+ }
62
+ /** Each input row's value, by name. */
63
+ function inputValues(bag) {
64
+ const out = {};
65
+ for (const row of Array.isArray(bag.inputs) ? bag.inputs : [])
66
+ if (isObject(row) && typeof row.name === 'string')
67
+ out[row.name] = inputValue(row);
68
+ return out;
69
+ }
70
+ /** `value` with object keys sorted, so key order does not count. */
71
+ function stable(value) {
72
+ if (Array.isArray(value))
73
+ return `[${value.map(stable).join(',')}]`;
74
+ if (isObject(value))
75
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stable(value[key])}`).join(',')}}`;
76
+ return JSON.stringify(value) ?? 'undefined';
77
+ }
78
+ /** An input that holds nothing: absent, `""`, `{}` or `[]`. */
79
+ function isEmptyInput(value) {
80
+ return value === undefined || value === null || value === ''
81
+ || (Array.isArray(value) && value.length === 0) || (isObject(value) && Object.keys(value).length === 0);
82
+ }
83
+ const EVENT_SERVICE_TYPES = new Set(['Intsvc.EventTrigger', 'Intsvc.WaitForEvent']);
84
+ const JSON_STRING = '=jsonString:';
85
+ /** The context row a flagged-V2 plan's connector elements carry (`stampConnectorConfigVersion`). */
86
+ const V2_CONFIG_ROW = 'activityConfigurationVersion';
87
+ /**
88
+ * The fields `core/connector-v2-metadata.ts` writes in a `metadata` body, per
89
+ * element kind: `connectorActivityMetadata` for a connector activity,
90
+ * `connectorEventMetadata` for an event. Compile writes no other.
91
+ */
92
+ const SDK_METADATA_FIELDS = {
93
+ activity: {
94
+ body: new Set(['activityPropertyConfiguration', 'activityMetadata', 'inputMetadata', 'telemetryData']),
95
+ apc: new Set(['multipartParameters', 'configuration', 'uiPathActivityTypeId', 'errorState', 'executionType', 'eventType', 'eventMode']),
96
+ },
97
+ event: {
98
+ body: new Set(['activityPropertyConfiguration', 'activityMetadata', 'telemetryData']),
99
+ apc: new Set(['objectName', 'eventType', 'eventMode', 'configuration', 'uiPathActivityTypeId', 'errorState', 'filterExpression']),
100
+ },
101
+ };
102
+ const SDK_ACTIVITY_FIELDS = new Set(['displayName', 'description', 'category', 'configuration', 'uiPathActivityTypeId', 'isEnabled']);
103
+ const SDK_TELEMETRY_FIELDS = new Set(['connectorKey', 'connectorName', 'objectName', 'objectDisplayName']);
104
+ const SDK_ROW_FIELDS = new Set(['name', 'type', 'value', 'body']);
105
+ const within = (value, fields) => isObject(value) && Object.keys(value).every((key) => fields.has(key));
106
+ /**
107
+ * Whether compile could have written this context: every row and every
108
+ * `metadata` field is one the SDK's builders write, and the configuration has
109
+ * no Designer half (`optionalConfiguration`) and no saved `connectorVersion`.
110
+ * A context the SDK wrote is left to compile, which rebuilds it from the
111
+ * library, so an SDK-authored plan's source carries no copy of it. Anything
112
+ * else (Studio Web's `activityMetadata.activity.svgIconUrl`, an event's
113
+ * `bindings`, `telemetryData.primaryKeyName`, a `metadata` row with no
114
+ * `type`) is a field compile never writes, so only the saved copy can keep it.
115
+ */
116
+ function sdkShaped(bag, context) {
117
+ if (!context.every((row) => within(row, SDK_ROW_FIELDS)))
118
+ return false;
119
+ const row = context.find((candidate) => candidate.name === 'metadata');
120
+ if (row.type !== 'json')
121
+ return false;
122
+ const body = row.body;
123
+ const fields = EVENT_SERVICE_TYPES.has(bag.serviceType) ? SDK_METADATA_FIELDS.event : SDK_METADATA_FIELDS.activity;
124
+ if (!within(body, fields.body) || !within(body.activityPropertyConfiguration, fields.apc))
125
+ return false;
126
+ if (!within(body.activityMetadata, new Set(['activity'])) || !within(body.activityMetadata.activity, SDK_ACTIVITY_FIELDS))
127
+ return false;
128
+ if (!within(body.telemetryData, SDK_TELEMETRY_FIELDS))
129
+ return false;
130
+ const encoded = body.activityPropertyConfiguration.configuration;
131
+ if (typeof encoded !== 'string' || !encoded.startsWith(JSON_STRING))
132
+ return false;
133
+ try {
134
+ const configuration = JSON.parse(encoded.slice(JSON_STRING.length));
135
+ return within(configuration, new Set(['essentialConfiguration']))
136
+ && (configuration.essentialConfiguration?.connectorVersion ?? null) === null;
137
+ }
138
+ catch {
139
+ return false;
140
+ }
141
+ }
142
+ /**
143
+ * The saved context of a connector element, when it has a `metadata` row with
144
+ * an object body (the Designer's state) that compile could not have written
145
+ * ({@link sdkShaped}); else `undefined`.
146
+ */
147
+ export function savedConnectorContext(owner, bag) {
148
+ const context = bag?.context;
149
+ if (!Array.isArray(context) || !context.every(isObject))
150
+ return undefined;
151
+ if (!context.some((row) => row.name === 'metadata' && isObject(row.body)))
152
+ return undefined;
153
+ if (sdkShaped(bag, context))
154
+ return undefined;
155
+ return { owner, context: structuredClone(context), inputs: inputValues(bag) };
156
+ }
157
+ /** Whether a wire `activityType` is a generic CRUD one (`Generic`, `GenericExpanded`, `GenericTrigger`). */
158
+ const isGenericKind = (activityType) => activityType.startsWith('Generic');
159
+ /**
160
+ * Which action a context was built for: the `uiPathActivityTypeId` its
161
+ * `metadata` row names (in `activityPropertyConfiguration`, else in
162
+ * `activityMetadata.activity`) and the essential configuration's
163
+ * `instanceParameters.activityType` (`Curated` or `Generic`). A curated
164
+ * activity and its generic twin share `method`, `path` and `objectName`
165
+ * (Outlook `send-email` and `insert-record-deprecated-`), so only these tell
166
+ * them apart. Either is `undefined` when the context does not say.
167
+ */
168
+ function actionIdentity(context) {
169
+ const raw = context.find((row) => row.name === 'metadata')?.body;
170
+ if (!isObject(raw))
171
+ return {};
172
+ const body = raw;
173
+ const id = body.activityPropertyConfiguration?.uiPathActivityTypeId ?? body.activityMetadata?.activity?.uiPathActivityTypeId;
174
+ let activityType;
175
+ const encoded = body.activityPropertyConfiguration?.configuration;
176
+ if (typeof encoded === 'string' && encoded.startsWith(JSON_STRING)) {
177
+ try {
178
+ activityType = JSON.parse(encoded.slice(JSON_STRING.length))?.essentialConfiguration?.instanceParameters?.activityType;
179
+ }
180
+ catch {
181
+ activityType = undefined;
182
+ }
183
+ }
184
+ return {
185
+ typeId: typeof id === 'string' && id ? id : undefined,
186
+ activityType: typeof activityType === 'string' && activityType ? activityType : undefined,
187
+ };
188
+ }
189
+ /**
190
+ * Whether the element compile built is the one the context was saved for:
191
+ *
192
+ * - every non-`metadata` row either side names holds the same value, a row on
193
+ * one side only reading as no value. So adding or removing a `folderKey`
194
+ * row (an edit that adds or drops `folder:`) gets compile's context, while
195
+ * a Designer row compile never writes and that holds no value (a bare
196
+ * `method`) still compares equal. `connectorKey` must be on both sides;
197
+ * - the action is the same: the activity type id agrees, and the wire
198
+ * activity type is curated on both sides or generic on both, wherever both
199
+ * sides carry them ({@link actionIdentity}), so switching to an action's
200
+ * curated or generic twin gets compile's context;
201
+ * - every input holds the same value (an input only one side has must be
202
+ * empty, as compile writes `body: {}` for an unused container).
203
+ */
204
+ function unchanged(bag, entry, v2) {
205
+ const built = Array.isArray(bag.context) ? bag.context.filter(isObject) : [];
206
+ const builtRows = new Map(built.map((row) => [row.name, row]));
207
+ const saved = new Map(entry.context.map((row) => [row.name, row]));
208
+ if (!builtRows.has('connectorKey') || !saved.has('connectorKey'))
209
+ return false;
210
+ for (const name of new Set([...builtRows.keys(), ...saved.keys()])) {
211
+ if (name === 'metadata')
212
+ continue;
213
+ // On a flagged-V2 plan `activityConfigurationVersion: v2` is compile's
214
+ // repair: it is written on connection-bound contexts, on a trigger or task
215
+ // after this pass (`stampConnectorConfigVersion` in serialize.ts), which
216
+ // keeps a row the context already has. A side that lacks it says nothing
217
+ // about the action, so it counts only when both sides carry it.
218
+ if (name === V2_CONFIG_ROW && v2 && !(builtRows.has(name) && saved.has(name)))
219
+ continue;
220
+ if (stable(builtRows.get(name)?.value) !== stable(saved.get(name)?.value))
221
+ return false;
222
+ }
223
+ const [now, then] = [actionIdentity(built), actionIdentity(entry.context)];
224
+ if (now.typeId && then.typeId && now.typeId !== then.typeId)
225
+ return false;
226
+ // Only the curated / generic split names a twin: an event's saved kind
227
+ // varies with no change of action (a trigger saved as `CuratedWaitFor` that
228
+ // compile writes as `CuratedTrigger`, the same activity type id).
229
+ if (now.activityType && then.activityType && isGenericKind(now.activityType) !== isGenericKind(then.activityType))
230
+ return false;
231
+ const values = inputValues(bag);
232
+ for (const name of new Set([...Object.keys(values), ...Object.keys(entry.inputs)])) {
233
+ const [a, b] = [values[name], entry.inputs[name]];
234
+ if (isEmptyInput(a) && isEmptyInput(b))
235
+ continue;
236
+ if (stable(a) !== stable(b))
237
+ return false;
238
+ }
239
+ return true;
240
+ }
241
+ /**
242
+ * Write each saved connector context back onto the element compile built for
243
+ * the same owner, while that element is unchanged ({@link unchanged}). Runs
244
+ * after the ids are restored, so an owner key finds its element by the plan's
245
+ * own ids, also after a rename.
246
+ */
247
+ export function applyConnectorContexts(result, entries) {
248
+ if (!entries?.length)
249
+ return;
250
+ const byOwner = new Map(entries.map((entry) => [entry.owner, entry]));
251
+ const v2 = result.metadata?.intsvcActivityConfig === 'v2';
252
+ for (const { key, bag } of caseConnectorOwners(result)) {
253
+ const entry = byOwner.get(key);
254
+ if (entry && unchanged(bag, entry, v2))
255
+ bag.context = structuredClone(entry.context);
256
+ }
257
+ }
258
+ /** Problems with a payload's `connectorContexts`, for `caseJsonPreservationErrors`. */
259
+ export function connectorContextErrors(entries) {
260
+ if (entries === undefined)
261
+ return [];
262
+ if (!Array.isArray(entries))
263
+ return ['preserved "connectorContexts" must be an array'];
264
+ const errors = [];
265
+ for (const entry of entries) {
266
+ const owner = entry?.owner;
267
+ if (typeof owner !== 'string' || !/^(trigger|task|rule):/.test(owner)) {
268
+ errors.push(`preserved connector context owner ${JSON.stringify(owner)} is not a trigger, task or rule key`);
269
+ continue;
270
+ }
271
+ for (const field of Object.keys(entry))
272
+ if (!['owner', 'context', 'inputs'].includes(field))
273
+ errors.push(`preserved connector context "${owner}" field "${field}" is not allowed in the preservation channel`);
274
+ const { context, inputs } = entry;
275
+ if (!Array.isArray(context) || !context.every(isObject) || !context.some((row) => row.name === 'metadata' && isObject(row.body)))
276
+ errors.push(`preserved connector context "${owner}" must be a list of context rows with a metadata row`);
277
+ if (!isObject(inputs))
278
+ errors.push(`preserved connector context "${owner}" inputs must be an object`);
279
+ }
280
+ return errors;
281
+ }
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { Library } from '../core/library.js';
7
7
  import { type ConnectorTaskIdentity } from './connector-saved-config.js';
8
+ import { type PreservedConnectorContext } from './connector-saved-context.js';
8
9
  import { type PreservedFilterLeafId, type PreservedTriggerDisplayFields } from './preserve.js';
9
10
  import { type PreservedResourceWire } from './resource-wire.js';
10
11
  interface IoRow {
@@ -274,6 +275,7 @@ type Preservation = {
274
275
  task: string;
275
276
  metadata: Record<string, unknown>;
276
277
  }>;
278
+ connectorContexts?: PreservedConnectorContext[];
277
279
  subscriptionFilters?: Array<{
278
280
  owner: string;
279
281
  expression?: 'inline';
@@ -8,6 +8,7 @@ import { isOlderDocumentExtractionData } from './document-extraction-saved.js';
8
8
  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
+ import { caseConnectorOwners, savedConnectorContext } from './connector-saved-context.js';
11
12
  import { builtChainSource, chainStatements } from '../core/builder-chain.js';
12
13
  import { literalSource } from './literal.js';
13
14
  import { ANY_ESCALATION_ID } from './rule-options.js';
@@ -2774,6 +2775,11 @@ export function collectPreservation(plan) {
2774
2775
  preservation.connectorConfigurations = connectorConfigurations;
2775
2776
  if (httpRequestMetadata.length)
2776
2777
  preservation.httpRequestMetadata = httpRequestMetadata;
2778
+ const connectorContexts = caseConnectorOwners(plan)
2779
+ .map(({ key, bag }) => savedConnectorContext(key, bag))
2780
+ .filter((entry) => entry !== undefined);
2781
+ if (connectorContexts.length)
2782
+ preservation.connectorContexts = connectorContexts;
2777
2783
  const subscriptionFilterEntries = preservedSubscriptionFilters(plan);
2778
2784
  if (subscriptionFilterEntries.length)
2779
2785
  preservation.subscriptionFilters = subscriptionFilterEntries;
@@ -1,3 +1,4 @@
1
+ import { type PreservedConnectorContext } from './connector-saved-context.js';
1
2
  import type { BuiltCase } from './case-sdk.js';
2
3
  import type { ReadEventFilter } from '../core/event-filters.js';
3
4
  import { Bindings } from '../core/bindings.js';
@@ -363,6 +364,13 @@ export interface CaseJsonPreservation {
363
364
  * another connector version is written back instead of downgraded.
364
365
  */
365
366
  httpRequestMetadata?: PreservedHttpRequestMetadata[];
367
+ /**
368
+ * Each Designer-saved connector element's `context` (an event trigger, a
369
+ * wait-for-connector task or rule, a connector activity task), verbatim,
370
+ * keyed by owner. Compile writes it back while the element is unchanged
371
+ * (`case/connector-saved-context.ts`).
372
+ */
373
+ connectorContexts?: PreservedConnectorContext[];
366
374
  /**
367
375
  * Action tasks' Designer-owned `data` fields: the `context` rows the Designer
368
376
  * saves with a form (its `hitlType`, quick-form schema ids, and a copy of the
@@ -1,3 +1,4 @@
1
+ import { connectorContextErrors } from './connector-saved-context.js';
1
2
  import { stableId } from '../core/stable-id.js';
2
3
  import { Bindings } from '../core/bindings.js';
3
4
  import { bindingIdCandidates, offlineBindingLabel } from './ids.js';
@@ -433,6 +434,7 @@ export function caseJsonPreservationErrors(payload) {
433
434
  if (!entry?.metadata || typeof entry.metadata !== 'object' || Array.isArray(entry.metadata))
434
435
  errors.push(`preserved http-request metadata of task "${entry?.task}" must be an object`);
435
436
  }
437
+ errors.push(...connectorContextErrors(payload.connectorContexts));
436
438
  for (const index of payload.manualTriggerServiceTypeNone ?? [])
437
439
  if (!Number.isInteger(index) || index < 0)
438
440
  errors.push(`manual trigger position "${index}" is not a non-negative integer`);
@@ -16,6 +16,7 @@ import { ACTION_CONTEXT_COPIES, ACTION_FORM_KIND_CONTEXT, ACTION_PASSTHROUGH_SET
16
16
  import { buildConnectorInputs, nestConnectorBody, transportHttpMethod } from '../core/connector-inputs.js';
17
17
  import { carriedConnectorFieldsRefusal, withCarriedFields } from '../core/carried-connector-fields.js';
18
18
  import { connectorTaskIdentity, sameConnectorOperation, withCurrentCaches, writeOptionalConfiguration } from './connector-saved-config.js';
19
+ import { applyConnectorContexts } from './connector-saved-context.js';
19
20
  import { connectorActivityMetadata, connectorEventFilterTree, connectorEventMetadata } from '../core/connector-v2-metadata.js';
20
21
  import { EQUALS_EXPR_DIALECT } from '../core/connector-checks.js';
21
22
  import { bindingLabelRefusal, connectionStubMessage } from '../core/binding-messages.js';
@@ -742,6 +743,9 @@ export function applyPreservation(result, preservation, options = {}) {
742
743
  continue;
743
744
  writeHttpRequestMetadata(task.data, entry.metadata);
744
745
  }
746
+ // After the subscription filters and the optional halves: an unchanged
747
+ // connector element takes its saved context whole.
748
+ applyConnectorContexts(result, preservation.connectorContexts);
745
749
  for (const entry of preservation.actionDataFields ?? []) {
746
750
  const stage = stageNodes.find((candidate) => candidate.data?.label === entry.stage);
747
751
  const task = stageTask(stage, entry.task);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.93.2",
3
+ "version": "6.93.3",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -111,5 +111,5 @@
111
111
  "@types/node": "^22.7.0",
112
112
  "esbuild": "^0.28.1"
113
113
  },
114
- "gitref": "4bc011b67ec4912b299602a55fe26ef6e41b382d"
114
+ "gitref": "b79fb2c5ae6006191f9e66aa74fdf305741d6fa4"
115
115
  }