@uipath/maestro-builder-sdk 6.96.1 → 6.96.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,545 @@
1
+ /**
2
+ * Connector descriptions a Case plan CARRIES: the library entries for the
3
+ * connector elements the library and the `connectors-local` overlay lack, read
4
+ * from what the plan itself saved.
5
+ *
6
+ * Case decompile names every connector task, event trigger and
7
+ * wait-for-connector through the connector library (`identifyAction`,
8
+ * `identifyEvent`). A connector only one tenant has (a Data Service entity
9
+ * such as `uipath-uipath-dataservice CREATED Invoice`, a custom connector, an
10
+ * operation newer than the library) is in no shipped library, so decompile
11
+ * refused the whole plan: `connector trigger event not found in library`. The
12
+ * way past that was `uip maestro registry prepare` against the tenant, which
13
+ * writes the connector into the overlay. Without a tenant, the plan could not
14
+ * be edited at all, though it describes the connector itself.
15
+ *
16
+ * A saved plan carries most of what `prepare` reads from the tenant: the
17
+ * connector key, object, method and path, the activity's instance parameters,
18
+ * its display text, the fields it fills and the response schema. So this
19
+ * module writes the two tenant answers `prepare` reads (the registry node and
20
+ * the Integration Service describe, or for an event the trigger definition)
21
+ * from the plan's own wire, and hands them to the writers `prepare` runs:
22
+ * `extractCanonical`, `applyDescribe`, `assembleEventDefinition`,
23
+ * `planLibrary`, `mergeFilesInto`. Decompile writes the result into the overlay
24
+ * that `check` and `compile` already read. This is the same idea as Flow's
25
+ * carried node definitions (`core/carried-definitions.ts`) and Case's carried
26
+ * fields (`core/carried-connector-fields.ts`): the file's own description is
27
+ * the third source, after the SDK and the library.
28
+ *
29
+ * The rules are the carried fields' rules:
30
+ *
31
+ * - It only fills a gap. Decompile writes an entry only when it asks the
32
+ * library about an element and neither the library nor the overlay can
33
+ * answer ({@link decompileWithPlanConnectors}). An entry whose node type and
34
+ * version a library layer already holds is not written, so a plan's entry
35
+ * never shadows a library one. A later `registry prepare` of the same
36
+ * operation replaces it: the overlay merge drops a plan-described row whose
37
+ * operation (connector, verb, path and object; or connector, object and
38
+ * event) the tenant's entry describes, whatever node type each was written
39
+ * under (`describedOperation` in `registry/prepare/overlay.ts`). The plan's
40
+ * action id is its own making (`curated-create-issue-post` where prepare
41
+ * writes `create-issue`), so a source decompiled before the prepare names an
42
+ * id that is gone; prepare says so, and a fresh decompile names the tenant's.
43
+ * - It describes only what the plan saved. A connector element the plan does
44
+ * not describe (no connector key, object, method and path for an action; no
45
+ * object and event operation for an event) gets nothing, and decompile still
46
+ * refuses it by name.
47
+ * - Every field it declares is optional, and the plan cannot know a field it
48
+ * never used, nor a field's real type and `required`. The tenant's describe
49
+ * can; `registry prepare` stays the way to get it.
50
+ *
51
+ * Each entry is marked `provenance: { source: "case-plan" }`.
52
+ *
53
+ * For instance, a plan whose stage waits for `uipath-uipath-dataservice CREATED
54
+ * Invoice` gets one overlay entry, `uipath.connector.event.uipath-uipath-dataservice.created`
55
+ * for the object `Invoice`, with the event parameters and response fields the
56
+ * subscription saved; decompile then names it as
57
+ * `{ connector: 'uipath-uipath-dataservice', event: 'created', object: 'Invoice' }`.
58
+ */
59
+ import { extractCanonical } from '../registry/library-build/canonical.js';
60
+ import { applyDescribe, HTTP_METHOD_TO_OPERATION } from '../registry/library-build/enrich.js';
61
+ import { planLibrary } from '../registry/library-build/plan.js';
62
+ import { assembleEventDefinition } from '../registry/prepare/event.js';
63
+ import { activityActionId } from '../registry/prepare/integration-service.js';
64
+ import { mergeFilesInto, PLAN_DESCRIBED_SOURCE } from '../registry/prepare/overlay.js';
65
+ import { ConnectorResolveError } from '../core/connector-resolve-error.js';
66
+ import { ownEntry } from '../core/own-entry.js';
67
+ /** `provenance.source` of every entry this module writes. A `registry prepare` of the same operation replaces such an entry. */
68
+ export const PLAN_CONNECTOR_SOURCE = PLAN_DESCRIBED_SOURCE;
69
+ const JSON_STRING = '=jsonString:';
70
+ const TRIGGER = 'Intsvc.EventTrigger';
71
+ const WAIT = 'Intsvc.WaitForEvent';
72
+ const ACTIVITY = 'Intsvc.ActivityExecution';
73
+ const STAGE = 'case-management:Stage';
74
+ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
75
+ const presentString = (v) => (typeof v === 'string' && v ? v : undefined);
76
+ function parseJson(text) {
77
+ try {
78
+ return JSON.parse(text);
79
+ }
80
+ catch {
81
+ return undefined;
82
+ }
83
+ }
84
+ /** The names an element goes by in a message. */
85
+ function namesOf(element) {
86
+ return [element.displayName, element.name, element.label, element.data?.label, element.display?.label, element.data?.display?.label]
87
+ .filter((n) => typeof n === 'string' && n.trim().length > 2);
88
+ }
89
+ /**
90
+ * Every connector bag in `plan`, with the element that owns it.
91
+ *
92
+ * The owner is the nearest object with an `id` above the bag, but never a stage
93
+ * or the case itself: a bag in an id-less wrapper directly under a stage has no
94
+ * owner.
95
+ */
96
+ export function planConnectorBags(plan) {
97
+ const out = [];
98
+ const walk = (value, owner) => {
99
+ if (Array.isArray(value)) {
100
+ for (const v of value)
101
+ walk(v, owner);
102
+ return;
103
+ }
104
+ if (!isObject(value))
105
+ return;
106
+ let here = owner;
107
+ if (typeof value.id === 'string')
108
+ here = value === plan || value.type === STAGE ? undefined : { id: value.id, names: namesOf(value) };
109
+ if (Array.isArray(value.context) && value.context.some((row) => row?.name === 'connectorKey')) {
110
+ out.push({ ...(here ? { owner: here.id } : {}), names: here?.names ?? [], bag: value });
111
+ return;
112
+ }
113
+ for (const v of Object.values(value))
114
+ walk(v, here);
115
+ };
116
+ walk(plan, undefined);
117
+ return out;
118
+ }
119
+ /**
120
+ * The wire facts of one bag, or `undefined` for a bag the plan does not
121
+ * describe well enough to name: a placeholder, an external task, an action
122
+ * without its object, method and path, an event without its object and
123
+ * operation. Those stay refused by name.
124
+ */
125
+ function wireOf(bag) {
126
+ const rows = new Map(bag.context.filter(isObject).map((row) => [row.name, row]));
127
+ const value = (name) => presentString(rows.get(name)?.value);
128
+ const connectorKey = value('connectorKey');
129
+ const kind = bag.serviceType === TRIGGER ? 'trigger' : bag.serviceType === WAIT ? 'event' : bag.serviceType === ACTIVITY ? 'action' : undefined;
130
+ // A placeholder (`connectorKey: "placeholder"`) names no connector: decompile lifts it as the placeholder.
131
+ if (!connectorKey || !kind || connectorKey === 'placeholder')
132
+ return undefined;
133
+ const metadata = isObject(rows.get('metadata')?.body) ? rows.get('metadata').body : {};
134
+ const apc = isObject(metadata.activityPropertyConfiguration) ? metadata.activityPropertyConfiguration : {};
135
+ const encoded = typeof apc.configuration === 'string' && apc.configuration.startsWith(JSON_STRING);
136
+ const parsed = encoded ? parseJson(apc.configuration.slice(JSON_STRING.length)) : undefined;
137
+ const config = isObject(parsed) ? parsed : {};
138
+ const essential = isObject(config.essentialConfiguration) ? config.essentialConfiguration : {};
139
+ const activity = isObject(metadata.activityMetadata?.activity) ? metadata.activityMetadata.activity : {};
140
+ const activityConfig = typeof activity.configuration === 'string' ? parseJson(activity.configuration) : undefined;
141
+ const instance = isObject(essential.instanceParameters) ? essential.instanceParameters : isObject(activityConfig) ? activityConfig : {};
142
+ const optional = isObject(config.optionalConfiguration) ? config.optionalConfiguration : {};
143
+ const telemetry = isObject(metadata.telemetryData) ? metadata.telemetryData : {};
144
+ const objectName = value('objectName');
145
+ const method = value('method');
146
+ const path = value('path');
147
+ const operation = value('operation');
148
+ if (!objectName)
149
+ return undefined;
150
+ if (kind === 'action' && (!method || !path))
151
+ return undefined;
152
+ if (kind !== 'action' && !operation)
153
+ return undefined;
154
+ return {
155
+ kind, connectorKey, bag, apc, essential, instance, optional, activity, telemetry, objectName, method, path, operation,
156
+ // As decompile reads it (`connectorActivityType`): the saved instance parameters, else the activity's.
157
+ activityType: presentString(essential.instanceParameters?.activityType) ?? (isObject(activityConfig) ? presentString(activityConfig.activityType) : undefined),
158
+ version: encoded ? presentString(essential.instanceParameters?.version) ?? presentString(essential.packageVersion)
159
+ : isObject(activityConfig) ? presentString(activityConfig.version) : undefined,
160
+ connectorName: String(telemetry.connectorName ?? optional.connectorName ?? connectorKey),
161
+ };
162
+ }
163
+ /** Whether `library` already names the wire, asked the way decompile asks it. */
164
+ function known(library, w) {
165
+ try {
166
+ if (w.kind === 'action') {
167
+ library.identifyAction({
168
+ connectorKey: w.connectorKey, httpMethod: w.method, endpoint: w.path, objectName: w.objectName,
169
+ version: w.version, activityType: w.activityType,
170
+ });
171
+ }
172
+ else {
173
+ library.identifyEvent(w.kind, {
174
+ connectorKey: w.connectorKey, objectName: w.objectName, eventOperation: w.operation,
175
+ eventMode: w.apc.eventMode, version: w.essential.packageVersion,
176
+ });
177
+ }
178
+ return true;
179
+ }
180
+ catch {
181
+ return false;
182
+ }
183
+ }
184
+ /** Whether a library layer already holds `nodeType` at `version`, for any object. */
185
+ function nodeTypeTaken(library, nodeType, version) {
186
+ try {
187
+ library.pageSource(nodeType, version);
188
+ return true;
189
+ }
190
+ catch (e) {
191
+ return !(e instanceof ConnectorResolveError && e.code === 'CONNECTOR_NOT_IN_LIBRARY');
192
+ }
193
+ }
194
+ /**
195
+ * The response JSON schema a plan saved, read back as library fields: the
196
+ * inverse of `responseJsonSchema` (`core/connector-response-schema.ts`). A
197
+ * nested object is `parent.child`, an array of objects `items[*].child`.
198
+ *
199
+ * For instance `{ properties: { CreatedBy: { $ref: '#/definitions/U' } }, definitions: { U: { properties: { Email: { type: 'string' } } } } }`
200
+ * reads as `[{ name: 'CreatedBy.Email', type: 'string' }]`.
201
+ */
202
+ export function responseSchemaFields(schema) {
203
+ if (!isObject(schema))
204
+ return [];
205
+ const definitions = isObject(schema.definitions) ? schema.definitions : {};
206
+ const out = [];
207
+ const seen = new Set();
208
+ const ref = (p) => (typeof p?.$ref === 'string' && p.$ref.startsWith('#/definitions/') ? definitions[p.$ref.slice(14)] : undefined);
209
+ const titled = (prop) => (typeof prop.title === 'string' && prop.title ? { displayName: prop.title } : {});
210
+ const visit = (properties, prefix, depth) => {
211
+ if (!isObject(properties) || depth > 8)
212
+ return;
213
+ for (const [name, prop] of Object.entries(properties)) {
214
+ if (!isObject(prop))
215
+ continue;
216
+ const path = `${prefix}${name}`;
217
+ const target = ref(prop) ?? (prop.type === 'object' && isObject(prop.properties) ? prop : undefined);
218
+ if (target && !seen.has(target)) {
219
+ seen.add(target);
220
+ visit(target.properties, `${path}.`, depth + 1);
221
+ seen.delete(target);
222
+ continue;
223
+ }
224
+ if (prop.type === 'array') {
225
+ const items = ref(prop.items) ?? (isObject(prop.items?.properties) ? prop.items : undefined);
226
+ if (items) {
227
+ visit(items.properties, `${path}[*].`, depth + 1);
228
+ continue;
229
+ }
230
+ out.push({ name: `${path}[*]`, type: typeof prop.items?.type === 'string' ? prop.items.type : 'string', ...titled(prop) });
231
+ continue;
232
+ }
233
+ out.push({ name: path, type: typeof prop.type === 'string' ? prop.type : 'string', ...titled(prop) });
234
+ }
235
+ };
236
+ visit(schema.properties, '', 0);
237
+ return out;
238
+ }
239
+ const responseSchemaOf = (bag) => (Array.isArray(bag.outputs) ? bag.outputs : []).find((o) => o?.name === 'response' && isObject(o.body))?.body;
240
+ /** The registry form block `extractCanonical` reads the activity's configuration from. */
241
+ function connectorForm(configuration) {
242
+ return {
243
+ sections: [{
244
+ fields: [{
245
+ componentProps: {
246
+ connectorDetail: { isEnabled: true, targetPlatform: 'CrossPlatform', isExperimental: false, configuration: JSON.stringify(configuration) },
247
+ },
248
+ }],
249
+ }],
250
+ };
251
+ }
252
+ const LOCATIONS = { body: 'body', query: 'query', path: 'path' };
253
+ /** A field's type as the value the task sends says it; none for a string or an expression, which fit any. */
254
+ function wireType(value) {
255
+ if (Array.isArray(value))
256
+ return 'array';
257
+ if (isObject(value))
258
+ return 'object';
259
+ if (typeof value === 'number')
260
+ return 'number';
261
+ if (typeof value === 'boolean')
262
+ return 'boolean';
263
+ return undefined;
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) {
267
+ const fields = new Map();
268
+ const add = (name, location, type, displayName) => {
269
+ if (typeof name !== 'string' || !name || fields.has(name))
270
+ return;
271
+ fields.set(name, { name, location, ...(type ? { type } : {}), ...(typeof displayName === 'string' && displayName ? { displayName } : {}) });
272
+ };
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);
281
+ }
282
+ for (const m of String(w.path ?? '').matchAll(/\{([^}]+)\}/g))
283
+ add(m[1], 'path', 'string');
284
+ 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
+ }
292
+ const parameters = [...fields.values()].filter((f) => f.location !== 'body')
293
+ .map((f) => ({ name: f.name, type: f.location, dataType: f.type ?? 'string', required: false, ...(f.displayName ? { displayName: f.displayName } : {}) }));
294
+ const multipart = Array.isArray(w.apc.multipartParameters) ? w.apc.multipartParameters : [];
295
+ for (const part of multipart)
296
+ if (isObject(part) && typeof part.name === 'string')
297
+ parameters.push({ name: part.name, type: 'multipart', dataType: part.dataType ?? 'string', required: false });
298
+ const requestFields = [...fields.values()].filter((f) => f.location === 'body')
299
+ .map((f) => ({ name: f.name, required: false, ...(f.type ? { type: f.type } : {}), ...(f.displayName ? { displayName: f.displayName } : {}) }));
300
+ const httpMethod = String(w.instance.httpMethod ?? w.method ?? '').toUpperCase();
301
+ const operation = String(w.essential.operation ?? HTTP_METHOD_TO_OPERATION.get(httpMethod) ?? '');
302
+ const label = String(w.activity.displayName ?? w.objectName);
303
+ const node = {
304
+ nodeType,
305
+ version: w.version ?? '1.0.0',
306
+ category: 'connector',
307
+ tags: ['connector', 'activity'],
308
+ display: { label, description: String(w.activity.description ?? '') },
309
+ model: {
310
+ type: 'bpmn:SendTask',
311
+ serviceType: ACTIVITY,
312
+ context: [{ name: 'connectorKey', value: w.connectorKey }, { name: 'connection' }, { name: 'folderKey' }, { name: 'operation', value: operation }],
313
+ },
314
+ form: connectorForm({ ...w.instance, connectorKey: w.connectorKey, objectName: w.objectName, httpMethod }),
315
+ connectorMethodInfo: { operation, path: w.path, curated: { displayName: String(w.telemetry.objectDisplayName ?? '') } },
316
+ uiPathActivityTypeId: String(w.apc.uiPathActivityTypeId ?? ''),
317
+ };
318
+ const describe = {
319
+ Operation: { Name: operation, Path: w.path, Curated: label },
320
+ DisplayName: String(w.telemetry.objectDisplayName ?? w.objectName),
321
+ Parameters: parameters,
322
+ RequestFields: requestFields,
323
+ ResponseFields: responseSchemaFields(responseSchemaOf(w.bag)),
324
+ };
325
+ return { node, describe };
326
+ }
327
+ /**
328
+ * The connector EVENT's `uip is triggers objects` row: the object and its
329
+ * parameters, each in the bucket the subscription saved it in (`queryParams`
330
+ * holds the event bucket, `parameters` the query bucket).
331
+ */
332
+ function eventObjectRow(w) {
333
+ const body = (Array.isArray(w.bag.inputs) ? w.bag.inputs : []).find((row) => row?.name === 'body')?.body;
334
+ return {
335
+ Name: w.objectName,
336
+ DisplayName: String(w.telemetry.objectDisplayName ?? w.objectName),
337
+ Parameters: [
338
+ ...Object.keys(isObject(body?.queryParams) ? body.queryParams : {}).map((name) => ({ Name: name, Type: 'event', DataType: 'string' })),
339
+ ...Object.keys(isObject(body?.parameters) ? body.parameters : {}).map((name) => ({ Name: name, Type: 'query', DataType: 'string' })),
340
+ ],
341
+ };
342
+ }
343
+ /**
344
+ * The activity type of an event's WAIT form, the one the entry is stored as
345
+ * (`uipath.connector.event.*`, as the registry ships it), from what a wire saved.
346
+ * A start's `CuratedTrigger` is its wait form's `CuratedWaitFor`: the library
347
+ * derives the start from the wait (`deriveTriggerForm` in `core/library.ts`),
348
+ * and compile writes a trigger's own kind itself. A generic one keeps its type.
349
+ * Built from a start's wire as saved, a wait-for-connector on the same event
350
+ * would compile to `CuratedTrigger`.
351
+ */
352
+ function waitActivityType(saved) {
353
+ const type = presentString(saved) ?? 'CuratedWaitFor';
354
+ return type === 'CuratedTrigger' ? 'CuratedWaitFor' : type;
355
+ }
356
+ /** The connector EVENT's registry node (its wait form), from what the subscription saved. */
357
+ function eventNode(w, nodeType) {
358
+ const eventMode = String(w.apc.eventMode ?? w.instance.eventMode ?? '');
359
+ const eventOperation = String(w.operation ?? w.instance.eventOperation ?? '');
360
+ const activityType = waitActivityType(w.instance.activityType);
361
+ return {
362
+ nodeType,
363
+ version: String(w.essential.packageVersion ?? w.instance.version ?? '1.0.0'),
364
+ category: 'connector',
365
+ tags: ['connector', 'trigger'],
366
+ display: { label: String(w.activity.displayName ?? eventOperation), description: String(w.activity.description ?? '') },
367
+ model: {
368
+ type: 'bpmn:ReceiveTask',
369
+ serviceType: WAIT,
370
+ context: [{ name: 'connectorKey', value: w.connectorKey }, { name: 'connection' }, { name: 'folderKey' }, { name: 'operation', value: eventOperation }],
371
+ },
372
+ form: connectorForm({
373
+ connectorKey: w.connectorKey, objectName: w.objectName, activityType, version: String(w.essential.packageVersion ?? '1.0.0'),
374
+ eventOperation, eventMode, supportsStreaming: w.instance.supportsStreaming ?? false,
375
+ }),
376
+ connectorMethodInfo: { operation: eventOperation, curated: { displayName: String(w.telemetry.objectDisplayName ?? '') } },
377
+ eventMode,
378
+ outputResponseDefinition: { fields: responseSchemaFields(responseSchemaOf(w.bag)) },
379
+ uiPathActivityTypeId: String(w.apc.uiPathActivityTypeId ?? ''),
380
+ };
381
+ }
382
+ const slug = (s) => activityActionId(String(s ?? '')).replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '') || 'op';
383
+ /**
384
+ * One library question decompile asks, as a string: the `identifyAction` or
385
+ * `identifyEvent` wire it passes, minus the version and activity type (the
386
+ * entry is written at the version asked). For instance
387
+ * `["action","custom-acme","POST","/tickets","ticket"]`.
388
+ */
389
+ export function libraryQuestion(kind, wire) {
390
+ return JSON.stringify(kind === 'action'
391
+ ? [kind, wire.connectorKey, String(wire.httpMethod ?? '').toUpperCase(), wire.endpoint ?? '', wire.objectName ?? '']
392
+ : [kind, wire.connectorKey, wire.objectName ?? '', wire.eventOperation ?? '']);
393
+ }
394
+ /**
395
+ * The connector operations `plan` describes and `library` cannot name (see the
396
+ * module comment), one per operation and object. Pure: reads `library`,
397
+ * writes nothing. It reads every connector element of the plan, also one
398
+ * decompile never asks the library about (a placeholder is skipped); decompile
399
+ * writes only the ones it asks for ({@link decompileWithPlanConnectors}).
400
+ *
401
+ * @param plan - The Case plan, as saved (`caseplan.json`).
402
+ * @param library - The library decompile opens: the shipped one plus the `connectors-local` overlay.
403
+ * @returns An empty list when the library names every connector element the plan describes.
404
+ */
405
+ export function planConnectors(plan, library) {
406
+ const out = [];
407
+ const byKey = new Map();
408
+ const actionIds = new Map();
409
+ // A wait-for-connector's wire first: an event entry is stored as its wait form,
410
+ // and the first wire on an operation is the one its entry is built from.
411
+ const bags = planConnectorBags(plan);
412
+ const ordered = [...bags.filter((b) => b.bag.serviceType === WAIT), ...bags.filter((b) => b.bag.serviceType !== WAIT)];
413
+ for (const { owner, names, bag } of ordered) {
414
+ const w = wireOf(bag);
415
+ if (!w || known(library, w))
416
+ continue;
417
+ let entry;
418
+ let node;
419
+ if (w.kind === 'action') {
420
+ // One action id per operation: object and verb, with a counter when two
421
+ // paths share them or a library layer already holds the node type.
422
+ const base = `${slug(w.objectName)}-${slug(w.method)}`;
423
+ const operationKey = JSON.stringify([w.connectorKey, w.method, w.path, w.objectName, w.version]);
424
+ let id = actionIds.get(operationKey);
425
+ if (id === undefined) {
426
+ id = base;
427
+ const taken = (candidate) => [...actionIds.values()].includes(candidate)
428
+ || nodeTypeTaken(library, `uipath.connector.${w.connectorKey}.${candidate}`, w.version ?? '1.0.0');
429
+ for (let n = 2; taken(id); n++)
430
+ id = `${base}-${n}`;
431
+ actionIds.set(operationKey, id);
432
+ }
433
+ const answers = actionAnswers(w, `uipath.connector.${w.connectorKey}.${id}`);
434
+ node = answers.node;
435
+ const canonical = extractCanonical(node);
436
+ if (!canonical)
437
+ continue;
438
+ canonical.connector.name = w.connectorName;
439
+ entry = applyDescribe(canonical, answers.describe);
440
+ }
441
+ else {
442
+ const nodeType = `uipath.connector.event.${w.connectorKey}.${slug(w.operation)}`;
443
+ const eventDef = eventNode(w, nodeType);
444
+ // An event's node type is the event's name, so one a library layer holds is left to the library.
445
+ if (nodeTypeTaken(library, nodeType, String(eventDef.version)))
446
+ continue;
447
+ const canonical = extractCanonical(eventDef);
448
+ if (!canonical)
449
+ continue;
450
+ canonical.connector.name = w.connectorName;
451
+ // The stored shape `prepare` writes for an event: generic per object, curated as is.
452
+ const definition = assembleEventDefinition(eventDef, { ...canonical, operation: { ...canonical.operation, objectName: w.objectName } }, undefined, eventObjectRow(w), nodeType);
453
+ entry = definition.entry;
454
+ node = definition.node;
455
+ }
456
+ entry.provenance = { source: PLAN_CONNECTOR_SOURCE };
457
+ 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.
459
+ const key = JSON.stringify([entry.nodeType, entry.operation?.objectName ?? '', entry.version]);
460
+ let connector = byKey.get(key);
461
+ if (!connector) {
462
+ // One library per entry, so each sidecar is built from its own node (two objects share a node type).
463
+ connector = { entry, files: planLibrary([entry], () => node).files, owners: [], names: [], questions: [] };
464
+ byKey.set(key, connector);
465
+ out.push(connector);
466
+ }
467
+ if (owner && !connector.owners.includes(owner))
468
+ connector.owners.push(owner);
469
+ for (const n of names)
470
+ if (!connector.names.includes(n))
471
+ connector.names.push(n);
472
+ if (!connector.questions.includes(question))
473
+ connector.questions.push(question);
474
+ }
475
+ return out;
476
+ }
477
+ /**
478
+ * Merge `connectors` into the overlay at `overlayDir`, as `registry prepare`
479
+ * merges an operation.
480
+ */
481
+ export function writePlanConnectors(connectors, overlayDir) {
482
+ for (const c of connectors)
483
+ mergeFilesInto(c.files, overlayDir);
484
+ }
485
+ /**
486
+ * `library`, with every question its `identifyAction` and `identifyEvent`
487
+ * cannot answer recorded in `misses` (as {@link libraryQuestion} spells it).
488
+ * The answers and the errors are the library's own.
489
+ */
490
+ function recordingMisses(library, misses) {
491
+ const identifyAction = library.identifyAction.bind(library);
492
+ const identifyEvent = library.identifyEvent.bind(library);
493
+ library.identifyAction = (wire) => {
494
+ try {
495
+ return identifyAction(wire);
496
+ }
497
+ catch (e) {
498
+ misses.add(libraryQuestion('action', wire));
499
+ throw e;
500
+ }
501
+ };
502
+ library.identifyEvent = (kind, wire) => {
503
+ try {
504
+ return identifyEvent(kind, wire);
505
+ }
506
+ catch (e) {
507
+ misses.add(libraryQuestion(kind, wire));
508
+ throw e;
509
+ }
510
+ };
511
+ return library;
512
+ }
513
+ /**
514
+ * Run `decompile` and, each time it fails on a connector question the library
515
+ * cannot answer and the plan describes, write that connector into the overlay
516
+ * and run it again. Only the connectors decompile asks for are written: a
517
+ * connector element it never names through the library (a placeholder, a
518
+ * global event kept verbatim) is not.
519
+ *
520
+ * @param plan - The plan being decompiled.
521
+ * @param open - Opens the library with the overlay at the given directory (`undefined`: none).
522
+ * @param overlayDir - The overlay the library reads, or `undefined` for none yet.
523
+ * @param newOverlayDir - Where the overlay goes when there is none yet, e.g. `.flow-sdk/connectors-local`.
524
+ * @param decompile - The decompile to run, with the library to use.
525
+ */
526
+ export function decompileWithPlanConnectors(plan, open, overlayDir, newOverlayDir, decompile) {
527
+ let library = open(overlayDir);
528
+ const candidates = planConnectors(plan, library);
529
+ const written = [];
530
+ for (;;) {
531
+ const misses = new Set();
532
+ try {
533
+ return { result: decompile(recordingMisses(library, misses)), written, library, overlayDir };
534
+ }
535
+ catch (e) {
536
+ const needed = candidates.filter((c) => !written.includes(c) && c.questions.some((q) => misses.has(q)));
537
+ if (!needed.length)
538
+ throw e;
539
+ overlayDir ??= newOverlayDir();
540
+ writePlanConnectors(needed, overlayDir);
541
+ written.push(...needed);
542
+ library = open(overlayDir);
543
+ }
544
+ }
545
+ }
package/dist/check-cli.js CHANGED
@@ -93,7 +93,7 @@ async function checkAgainstBaseline(built, originalPath, original, opts, package
93
93
  const loaded = await loadNodePackages(originalPath, original, packages);
94
94
  for (const message of loaded.warnings)
95
95
  console.error(`check: warning: ${message}`);
96
- const baseline = await withDecompiledOriginal(originalPath, (b) => checkCompiled(b, opts), (m) => console.error(`check: decompile warning: ${m}`));
96
+ const baseline = await withDecompiledOriginal(originalPath, (b) => checkCompiled(b, opts), (m) => console.error(`check: decompile warning: ${m}`), opts.library ? { library: opts.library } : {});
97
97
  return scopeToEdit(checkCompiled(built, opts), baseline);
98
98
  }
99
99
  /**
@@ -107,11 +107,13 @@ export function registerFlowCommands(program) {
107
107
  .option('--no-pipeline', 'do not emit a brownfield pipeline helper')
108
108
  .option('--package <name...>', 'trust and load this node-type package (repeatable); otherwise package.json "maestroBuilderSdk".nodePackages decides')
109
109
  .option('--scripts <form>', 'print script steps as "function" (the default) or "string"')
110
+ .option('--library <dir>', 'connector library compile will use (default $FLOW_SDK_LIBRARY_JSON, else the pulled cache); an operation it lacks is carried from the file')
110
111
  .action(async (input, options) => {
111
112
  const argv = [input];
112
113
  addValue(argv, '-o', options.output);
113
114
  addValue(argv, '--import', options.import);
114
115
  addValue(argv, '--scripts', options.scripts);
116
+ addValue(argv, '--library', options.library);
115
117
  if (options.strict)
116
118
  argv.push('--strict');
117
119
  if (options.pipeline === false)
@@ -12,6 +12,7 @@ import type { LookupToken } from './lookups.js';
12
12
  import type { EventFilterExpression } from './event-filters.js';
13
13
  export type { EventFilterExpression } from './event-filters.js';
14
14
  import { type ConnectorDescriptor, type TriggerDescriptor } from './connectors.js';
15
+ import type { CarriedConnectorOperation } from './carried-connector-operation.js';
15
16
  export interface ConnectorOpts {
16
17
  /** Connector action version (defaults to the library's newest match). */
17
18
  version?: string;
@@ -55,6 +56,20 @@ export interface ConnectorOpts {
55
56
  * different object is an error: nothing could make that right.
56
57
  */
57
58
  object?: string;
59
+ /**
60
+ * Flow only, and written by decompile, not by an author: the `.flow` file's own
61
+ * description of an operation the connector library does not have — the
62
+ * method and endpoint its node calls, the verb its configuration records, and
63
+ * the slot of each input it sets. Compile reads it only when the library has
64
+ * no entry for the node type, together with the definition the source carries
65
+ * in `.definitions([...])`; see `core/carried-connector-operation.ts`.
66
+ *
67
+ * ```ts
68
+ * { method: 'POST', endpoint: '/v2/{entityName}/CreateEntityRecord', operation: 'create',
69
+ * fields: [{ name: 'Name', location: 'body' }, { name: 'entityName', location: 'path' }] }
70
+ * ```
71
+ */
72
+ carried?: CarriedConnectorOperation;
58
73
  }
59
74
  /**
60
75
  * The platform's 11 canonical quick-form field types (`@uipath/hitl-schema-types`
@@ -924,6 +939,8 @@ export interface FlowActionSpecs {
924
939
  folder?: string;
925
940
  /** Which OBJECT a generic operation addresses — see {@link ConnectorOpts.object}. */
926
941
  object?: string;
942
+ /** The file's description of an operation the library lacks — see {@link ConnectorOpts.carried}. */
943
+ carried?: CarriedConnectorOperation;
927
944
  /** The operation's inputs, by field. */
928
945
  inputs: Record<string, unknown>;
929
946
  };
@@ -60,6 +60,7 @@ export function connector(a, b, c, d) {
60
60
  connection: opts.connection,
61
61
  folder: opts.folder,
62
62
  object: opts.object,
63
+ ...(opts.carried !== undefined ? { carried: opts.carried } : {}),
63
64
  inputs: c ?? {},
64
65
  });
65
66
  }
@@ -74,6 +75,7 @@ export function connector(a, b, c, d) {
74
75
  connection: opts.connection,
75
76
  folder: opts.folder,
76
77
  object: opts.object ?? a.objectName,
78
+ ...(opts.carried !== undefined ? { carried: opts.carried } : {}),
77
79
  inputs: b ?? {},
78
80
  });
79
81
  }