@uipath/maestro-builder-sdk 6.96.7 → 6.97.1
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.
- package/README.md +2 -1
- package/dist/api-index.md +62 -62
- package/dist/api-members.md +292 -289
- package/dist/bpmn/bpmn-sdk.d.ts +36 -0
- package/dist/bpmn/check-cli.js +8 -4
- package/dist/bpmn/compile-cli.js +4 -3
- package/dist/bpmn/decompile-cli.js +15 -1
- package/dist/bpmn/decompile-pipeline.d.ts +5 -0
- package/dist/bpmn/decompile-pipeline.js +3 -3
- package/dist/bpmn/decompile-stamp.d.ts +13 -0
- package/dist/bpmn/decompile-stamp.js +8 -0
- package/dist/bpmn/decompile.d.ts +17 -4
- package/dist/bpmn/decompile.js +19 -10
- package/dist/bpmn/merge-cli.js +32 -4
- package/dist/bpmn/merge-source.d.ts +2 -0
- package/dist/bpmn/merge-source.js +1 -0
- package/dist/bpmn/serialize.js +7 -1
- package/dist/bpmn/typed-node.d.ts +7 -0
- package/dist/bpmn/typed-node.js +50 -26
- package/dist/bpmn-api.md +3 -0
- package/dist/case/check-cli.js +4 -2
- package/dist/case/compile-cli.js +14 -9
- package/dist/case/decompile-cli.d.ts +1 -1
- package/dist/case/decompile-cli.js +12 -2
- package/dist/check-cli.js +12 -6
- package/dist/cli/commands/registry.js +2 -0
- package/dist/compile-cli.js +16 -10
- package/dist/core/cli-library.d.ts +18 -2
- package/dist/core/cli-library.js +25 -5
- package/dist/core/library.d.ts +74 -2
- package/dist/core/library.js +88 -11
- package/dist/decompile-cli.js +17 -2
- package/dist/decompile-stamp.d.ts +13 -0
- package/dist/decompile-stamp.js +7 -1
- package/dist/emit.js +5 -8
- package/dist/merge-cli.js +51 -1
- package/dist/registry/curated-overlay.d.ts +11 -0
- package/dist/registry/curated-overlay.js +27 -0
- package/dist/registry/describe-cli.d.ts +3 -0
- package/dist/registry/describe-cli.js +38 -6
- package/dist/registry/fetch/fetch-connectors.d.ts +21 -0
- package/dist/registry/fetch/fetch-connectors.js +84 -0
- package/dist/registry/fetch/fetch-definitions.d.ts +61 -0
- package/dist/registry/fetch/fetch-definitions.js +447 -0
- package/dist/registry/fetch/flow-requests.d.ts +14 -0
- package/dist/registry/fetch/flow-requests.js +81 -0
- package/dist/registry/fetch/with-fetched-definitions.d.ts +46 -0
- package/dist/registry/fetch/with-fetched-definitions.js +211 -0
- package/dist/registry/library-build/events.d.ts +9 -2
- package/dist/registry/library-build/events.js +4 -10
- package/dist/registry/pull-cli.d.ts +9 -0
- package/dist/registry/pull-cli.js +150 -10
- package/dist/registry/search-cli.d.ts +25 -0
- package/dist/registry/search-cli.js +94 -10
- package/package.json +4 -3
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch connector definitions through `uip` into the `connectors-local` overlay,
|
|
3
|
+
* for the node types no library layer carries.
|
|
4
|
+
*
|
|
5
|
+
* The published library (`library-json.zip`) is an optimization, not a
|
|
6
|
+
* requirement (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md). When it is absent —
|
|
7
|
+
* not downloadable, or never published, as on Automation Suite — the tenant is
|
|
8
|
+
* the catalog, and this asks it, one node type at a time, the questions the
|
|
9
|
+
* library build asks of its own tenant (`library-build/build.ts`):
|
|
10
|
+
*
|
|
11
|
+
* 1. `uip maestro flow registry get <nodeType>` — the node, the future sidecar;
|
|
12
|
+
* 2. `uip is resources describe` — the fields (`enrichEntry`);
|
|
13
|
+
* 3. `uip is connectors metadata` — the connector record, which says whether
|
|
14
|
+
* the connector's objects come from the connection;
|
|
15
|
+
* 4. `uip is resources list` / `describe` — a generic operation's objects,
|
|
16
|
+
* only the ones asked for when any were;
|
|
17
|
+
* 5. `uip is triggers objects` / `describe` — an event's vocabulary;
|
|
18
|
+
*
|
|
19
|
+
* then the curated op remaps and `planLibrary`, exactly as the build. Nothing
|
|
20
|
+
* here takes a connection: what only a connection can answer stays `registry
|
|
21
|
+
* prepare`'s, and `check` names that `prepare`.
|
|
22
|
+
*
|
|
23
|
+
* The result is merged with `prepare`'s own merge, minus every variant the
|
|
24
|
+
* overlay already holds, so a connection-resolved `prepare` entry is never
|
|
25
|
+
* replaced by a connection-free one. Each entry written is stamped
|
|
26
|
+
* `provenance: { source: "uip-fetch" }`. The curated corrections for the
|
|
27
|
+
* entries fetched, and the side-tables a pulled library carries, are applied
|
|
28
|
+
* too (`applyCorrectionsAndSideTables`), so compile reads the facts it would
|
|
29
|
+
* read from a pulled library.
|
|
30
|
+
*/
|
|
31
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
32
|
+
import { tmpdir } from "node:os";
|
|
33
|
+
import { join } from "node:path";
|
|
34
|
+
import { mapConcurrent } from "../concurrency.js";
|
|
35
|
+
import { applyCorrectionsAndSideTables } from "../curated-overlay.js";
|
|
36
|
+
import { messageOf } from "../errors.js";
|
|
37
|
+
import { fetchConnectorRecordsForKeys } from "../library-build/build.js";
|
|
38
|
+
import { applyCuratedOverrides, extractCanonical, isHttpPassthrough, mergeConnectorRecord, nodeOf, scopedConnectorKey, } from "../library-build/canonical.js";
|
|
39
|
+
import { createBuildContext, registryProbe } from "../library-build/context.js";
|
|
40
|
+
import { enrichAll } from "../library-build/enrich.js";
|
|
41
|
+
import { resolveConnectorEvents } from "../library-build/events.js";
|
|
42
|
+
import { asDiscoveryEntry, expandGenericForConnector, genericTemplatesByOp, listGenericObjects, objectsComeFromTheConnection, sortExpandedEntries, } from "../library-build/generic-expand.js";
|
|
43
|
+
import { planLibrary } from "../library-build/plan.js";
|
|
44
|
+
import { writePlan } from "../library-build/write.js";
|
|
45
|
+
import { sidecarPath } from "../library-reader.js";
|
|
46
|
+
import { INDEX_FILENAME, descriptorOverlayPath, mergeInto, variantKey } from "../prepare/overlay.js";
|
|
47
|
+
import { refreshRegistryCatalog } from "../prepare/actions.js";
|
|
48
|
+
import { loginScope } from "../prepare/catalog-absence.js";
|
|
49
|
+
import { writeInsideSync } from "../prepare/staged-files.js";
|
|
50
|
+
import { FETCHED_PROVENANCE } from "../../core/library.js";
|
|
51
|
+
import { silentReporter } from "../reporter.js";
|
|
52
|
+
import { defaultUipClient } from "../uip/client.js";
|
|
53
|
+
import { getCI } from "../uip/envelope.js";
|
|
54
|
+
import { loginStatusData } from "../uip/login-status.js";
|
|
55
|
+
import { MemoryResponseCache } from "../uip/response-cache.js";
|
|
56
|
+
/** The provenance every fetched entry carries. */
|
|
57
|
+
export const FETCHED_SOURCE = FETCHED_PROVENANCE;
|
|
58
|
+
/** Set `FLOW_SDK_FETCH_DEFINITIONS=0` to never call `uip` for a missing definition. */
|
|
59
|
+
export const FETCH_DEFINITIONS_ENV = "FLOW_SDK_FETCH_DEFINITIONS";
|
|
60
|
+
/** Whether a missing definition may be fetched through `uip` in this process. */
|
|
61
|
+
export function fetchDefinitionsEnabled(env = process.env) {
|
|
62
|
+
const value = env[FETCH_DEFINITIONS_ENV]?.trim().toLowerCase();
|
|
63
|
+
return value !== "0" && value !== "false";
|
|
64
|
+
}
|
|
65
|
+
const EVENT_NS = "uipath.connector.event.";
|
|
66
|
+
const TRIGGER_NS = "uipath.connector.trigger.";
|
|
67
|
+
/**
|
|
68
|
+
* The node type to ask the registry for: a start trigger as its wait form.
|
|
69
|
+
* `registry get` refuses the start form without `--connection-id`, and the
|
|
70
|
+
* library derives the start form from the wait form (`Library.resolveEvent`).
|
|
71
|
+
*/
|
|
72
|
+
export function fetchableNodeType(nodeType) {
|
|
73
|
+
return nodeType.startsWith(TRIGGER_NS) ? EVENT_NS + nodeType.slice(TRIGGER_NS.length) : nodeType;
|
|
74
|
+
}
|
|
75
|
+
/** The requests grouped by the node type fetched, with the objects asked for (none means every object). */
|
|
76
|
+
/** The versions asked for, by the node type fetched; a request with none asks for whichever the tenant serves. */
|
|
77
|
+
function requestedVersions(requests) {
|
|
78
|
+
const versions = new Map();
|
|
79
|
+
for (const request of requests) {
|
|
80
|
+
if (!request.version)
|
|
81
|
+
continue;
|
|
82
|
+
const nodeType = fetchableNodeType(request.nodeType);
|
|
83
|
+
versions.set(nodeType, (versions.get(nodeType) ?? new Set()).add(request.version));
|
|
84
|
+
}
|
|
85
|
+
return versions;
|
|
86
|
+
}
|
|
87
|
+
function groupRequests(requests) {
|
|
88
|
+
const grouped = new Map();
|
|
89
|
+
for (const request of requests) {
|
|
90
|
+
const nodeType = fetchableNodeType(request.nodeType);
|
|
91
|
+
if (scopedConnectorKey(nodeType) === null)
|
|
92
|
+
continue;
|
|
93
|
+
const objects = grouped.has(nodeType) ? grouped.get(nodeType) : new Set();
|
|
94
|
+
if (objects === undefined)
|
|
95
|
+
continue; // already "every object"
|
|
96
|
+
if (request.objectName)
|
|
97
|
+
objects.add(request.objectName);
|
|
98
|
+
else {
|
|
99
|
+
grouped.set(nodeType, undefined);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
grouped.set(nodeType, objects);
|
|
103
|
+
}
|
|
104
|
+
return grouped;
|
|
105
|
+
}
|
|
106
|
+
/** Why `uip` cannot be asked anything, or `undefined` when it is logged in. */
|
|
107
|
+
export async function uipUnavailableReason(client) {
|
|
108
|
+
let status;
|
|
109
|
+
try {
|
|
110
|
+
status = await loginStatusData(client);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return messageOf(error);
|
|
114
|
+
}
|
|
115
|
+
const state = getCI(status.data, "Status");
|
|
116
|
+
if (status.result.code === 0 && typeof state === "string" && /^logged in$/i.test(state.trim()))
|
|
117
|
+
return undefined;
|
|
118
|
+
return typeof state === "string" && state.trim() !== ""
|
|
119
|
+
? `uip login status is "${state.trim()}"; run \`uip login\``
|
|
120
|
+
: "uip is not logged in; run `uip login`";
|
|
121
|
+
}
|
|
122
|
+
/** Whether `entry` is a generic CRUD operation the build expands per object. */
|
|
123
|
+
function isExpandableGeneric(entry) {
|
|
124
|
+
return entry.operation?.activityType === "Generic" && !isHttpPassthrough(entry);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The entries for one fetched node: the generic CRUD template expanded into its
|
|
128
|
+
* objects (the ones asked for, or all), or the entry itself. A connector whose
|
|
129
|
+
* objects come from the connection keeps its discovery entry, as the build does:
|
|
130
|
+
* its objects are `prepare --object`'s to describe.
|
|
131
|
+
*/
|
|
132
|
+
async function entriesFor(ctx, entry, objects) {
|
|
133
|
+
if (!isExpandableGeneric(entry))
|
|
134
|
+
return [entry];
|
|
135
|
+
if (objectsComeFromTheConnection(entry))
|
|
136
|
+
return [asDiscoveryEntry(entry)];
|
|
137
|
+
const key = entry.connector?.key;
|
|
138
|
+
const templates = genericTemplatesByOp([entry]).get(key);
|
|
139
|
+
if (templates === undefined)
|
|
140
|
+
return [entry];
|
|
141
|
+
if (objects === undefined)
|
|
142
|
+
return expandGenericForConnector(ctx, key, templates);
|
|
143
|
+
// Matched in any case, as `Library` matches the object it reports missing:
|
|
144
|
+
// `contact` asked for, `Contact` listed, is the same object.
|
|
145
|
+
const listed = (await listGenericObjects(ctx, key, templates, [...objects]))
|
|
146
|
+
.map((obj) => obj.Name)
|
|
147
|
+
.filter((name) => typeof name === "string");
|
|
148
|
+
const wanted = [...objects].map((asked) => listed.find((name) => name.toLowerCase() === asked.toLowerCase()) ?? asked);
|
|
149
|
+
return expandGenericForConnector(ctx, key, templates, wanted);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* `plan` without the rows (and their files) the overlay already holds, each
|
|
153
|
+
* kept row stamped with {@link FETCHED_PROVENANCE}. A row whose variant the
|
|
154
|
+
* overlay holds is skipped: what is there may be a connection-resolved
|
|
155
|
+
* `prepare` entry. A row whose PATH the overlay holds for another variant
|
|
156
|
+
* (objects `A/B` and `A_B` sanitize to one path) is refused, never written over.
|
|
157
|
+
*/
|
|
158
|
+
function withoutExisting(plan, holds) {
|
|
159
|
+
const collisions = [];
|
|
160
|
+
const rows = plan.index.filter((row) => {
|
|
161
|
+
if (holds.variants.has(variantKey(row)))
|
|
162
|
+
return false;
|
|
163
|
+
if (holds.paths.has(descriptorOverlayPath(row.path))) {
|
|
164
|
+
collisions.push(row);
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}).map((row) => ({ ...row, provenance: FETCHED_PROVENANCE }));
|
|
169
|
+
const files = new Map();
|
|
170
|
+
const index = JSON.parse(plan.files.get(INDEX_FILENAME) ?? "{}");
|
|
171
|
+
files.set(INDEX_FILENAME, JSON.stringify({ ...index, entries: rows }));
|
|
172
|
+
for (const row of rows) {
|
|
173
|
+
for (const rel of [row.path, sidecarPath(row.path)]) {
|
|
174
|
+
const text = plan.files.get(rel);
|
|
175
|
+
if (text !== undefined)
|
|
176
|
+
files.set(rel, text);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { files, rows, collisions };
|
|
180
|
+
}
|
|
181
|
+
/** What `overlayDir`'s index holds, or nothing when it has no index. */
|
|
182
|
+
function overlayHolds(overlayDir) {
|
|
183
|
+
try {
|
|
184
|
+
const index = JSON.parse(readFileSync(join(overlayDir, INDEX_FILENAME), "utf8"));
|
|
185
|
+
const rows = (index.entries ?? []);
|
|
186
|
+
return {
|
|
187
|
+
variants: new Set(rows.map((row) => variantKey(row))),
|
|
188
|
+
// As the merge will write them: a row an older `prepare` left at `<key>/…`
|
|
189
|
+
// is moved under `descriptors/` by that merge, so it collides there.
|
|
190
|
+
paths: new Set(rows.map((row) => descriptorOverlayPath(String(row.path ?? "")))),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return { variants: new Set(), paths: new Set() };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** One probe, with a reply that cannot be read (malformed JSON) as a miss instead of a throw. */
|
|
198
|
+
async function probe(ctx, nodeType) {
|
|
199
|
+
try {
|
|
200
|
+
return await registryProbe(ctx, nodeType);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
return { miss: { nodeType, reason: `the registry's answer could not be read: ${messageOf(error)}`, notFound: false } };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* `planLibrary` over every entry, or, when one entry makes it throw, over the
|
|
208
|
+
* entries that plan alone: one bad tenant answer fails its own node type, not
|
|
209
|
+
* the whole fetch.
|
|
210
|
+
*/
|
|
211
|
+
function planEach(entries, loadNode, failed) {
|
|
212
|
+
try {
|
|
213
|
+
return planLibrary(entries, loadNode);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
const kept = entries.filter((entry) => {
|
|
217
|
+
try {
|
|
218
|
+
planLibrary([entry], loadNode);
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
failed.push({ nodeType: entry.nodeType, reason: `its definition could not be written: ${messageOf(error)}` });
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return planLibrary(kept, loadNode);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** How long a "the tenant does not serve it" answer is believed without asking again: `uip`'s own catalog lifetime. */
|
|
230
|
+
const NOT_SERVED_TTL_MS = 30 * 60 * 1000;
|
|
231
|
+
const NOT_SERVED_FILE = ".not-served.json";
|
|
232
|
+
function readNotServed(overlayDir, scope, now) {
|
|
233
|
+
try {
|
|
234
|
+
const memory = JSON.parse(readFileSync(join(overlayDir, NOT_SERVED_FILE), "utf8"));
|
|
235
|
+
if (memory.scope !== scope)
|
|
236
|
+
return new Set();
|
|
237
|
+
return new Set(Object.entries(memory.until ?? {}).filter(([, until]) => until > now).map(([nodeType]) => nodeType));
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return new Set();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function rememberNotServed(overlayDir, scope, nodeTypes, now) {
|
|
244
|
+
if (nodeTypes.length === 0)
|
|
245
|
+
return;
|
|
246
|
+
let until = {};
|
|
247
|
+
try {
|
|
248
|
+
const memory = JSON.parse(readFileSync(join(overlayDir, NOT_SERVED_FILE), "utf8"));
|
|
249
|
+
if (memory.scope === scope)
|
|
250
|
+
until = Object.fromEntries(Object.entries(memory.until ?? {}).filter(([, t]) => t > now));
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
// None yet, or unreadable: start over.
|
|
254
|
+
}
|
|
255
|
+
for (const nodeType of nodeTypes)
|
|
256
|
+
until[nodeType] = now + NOT_SERVED_TTL_MS;
|
|
257
|
+
mkdirSync(overlayDir, { recursive: true });
|
|
258
|
+
writeInsideSync(overlayDir, join(overlayDir, NOT_SERVED_FILE), `${JSON.stringify({ scope, until }, null, 2)}\n`);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Fetch every requested node type the tenant serves into `overlayDir`.
|
|
262
|
+
*
|
|
263
|
+
* Never throws for a tenant answer: a node type the tenant does not serve is
|
|
264
|
+
* `notServed`, any other failure is `failed`, and a `uip` that cannot be asked
|
|
265
|
+
* at all is `unavailable`. The caller turns those into its own refusals.
|
|
266
|
+
*
|
|
267
|
+
* `registry get` answers from `uip`'s local copy of the tenant catalog, so a
|
|
268
|
+
* "not found" is believed only after one `uip maestro flow registry pull
|
|
269
|
+
* --force` and a second probe, as `prepare` does (`prepare/actions.ts`). When
|
|
270
|
+
* that refresh fails, or writes only part of the catalog, a node type still
|
|
271
|
+
* not found is `failed` with the reason, not `notServed`.
|
|
272
|
+
*/
|
|
273
|
+
export async function fetchDefinitions(requests, options) {
|
|
274
|
+
const result = { fetched: [], notServed: [], failed: [] };
|
|
275
|
+
const grouped = groupRequests(requests);
|
|
276
|
+
if (grouped.size === 0)
|
|
277
|
+
return result;
|
|
278
|
+
const client = options.client ?? defaultUipClient();
|
|
279
|
+
const reporter = options.reporter ?? silentReporter;
|
|
280
|
+
const unavailable = await uipUnavailableReason(client);
|
|
281
|
+
if (unavailable !== undefined)
|
|
282
|
+
return { ...result, unavailable };
|
|
283
|
+
const scope = loginScope((await loginStatusData(client)).data);
|
|
284
|
+
const now = Date.now();
|
|
285
|
+
const remembered = readNotServed(options.overlayDir, scope, now);
|
|
286
|
+
for (const nodeType of [...grouped.keys()]) {
|
|
287
|
+
if (!remembered.has(nodeType))
|
|
288
|
+
continue;
|
|
289
|
+
result.notServed.push(nodeType);
|
|
290
|
+
grouped.delete(nodeType);
|
|
291
|
+
}
|
|
292
|
+
if (grouped.size === 0)
|
|
293
|
+
return finish(result);
|
|
294
|
+
const versions = requestedVersions(requests);
|
|
295
|
+
const ctx = createBuildContext({
|
|
296
|
+
client,
|
|
297
|
+
caches: { registry: new MemoryResponseCache(), is: new MemoryResponseCache(), connectors: new MemoryResponseCache() },
|
|
298
|
+
reporter: silentReporter,
|
|
299
|
+
concurrency: options.concurrency ?? 4,
|
|
300
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
301
|
+
});
|
|
302
|
+
// 1. The node of every requested node type, with a "not found" checked
|
|
303
|
+
// against a refreshed catalog before it is believed.
|
|
304
|
+
const nodeTypes = [...grouped.keys()].sort();
|
|
305
|
+
const probes = await mapConcurrent(nodeTypes, ctx.concurrency, (nodeType) => probe(ctx, nodeType));
|
|
306
|
+
if (probes.some((p) => "miss" in p && p.miss.notFound)) {
|
|
307
|
+
const refresh = await refreshRegistryCatalog(client, options.timeoutMs);
|
|
308
|
+
const doubt = !refresh.ok ? `the catalog refresh failed: ${refresh.reason}` : refresh.partial;
|
|
309
|
+
await Promise.all(nodeTypes.map(async (nodeType, i) => {
|
|
310
|
+
const first = probes[i];
|
|
311
|
+
if (!("miss" in first) || !first.miss.notFound)
|
|
312
|
+
return;
|
|
313
|
+
const again = await probe(ctx, nodeType);
|
|
314
|
+
probes[i] = "miss" in again && again.miss.notFound && doubt !== undefined
|
|
315
|
+
? { miss: { nodeType, reason: `not found in uip's catalog, and ${doubt}`, notFound: false } }
|
|
316
|
+
: again;
|
|
317
|
+
}));
|
|
318
|
+
}
|
|
319
|
+
const nodes = new Map();
|
|
320
|
+
let entries = [];
|
|
321
|
+
nodeTypes.forEach((nodeType, i) => {
|
|
322
|
+
const answer = probes[i];
|
|
323
|
+
if ("miss" in answer) {
|
|
324
|
+
if (answer.miss.notFound)
|
|
325
|
+
result.notServed.push(nodeType);
|
|
326
|
+
else
|
|
327
|
+
result.failed.push({ nodeType, reason: answer.miss.reason });
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
let entry;
|
|
331
|
+
let node;
|
|
332
|
+
try {
|
|
333
|
+
node = nodeOf(ctx.caches.registry.read(answer.name));
|
|
334
|
+
entry = extractCanonical(node);
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
result.failed.push({ nodeType, reason: messageOf(error) });
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (entry === undefined) {
|
|
341
|
+
result.failed.push({ nodeType, reason: "the registry's answer has no connector operation to read" });
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (entry.nodeType !== nodeType) {
|
|
345
|
+
result.failed.push({ nodeType, reason: `uip returned a definition, but for ${entry.nodeType}, not for ${nodeType}` });
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
nodes.set(entry.nodeType, node);
|
|
349
|
+
entries.push(entry);
|
|
350
|
+
});
|
|
351
|
+
if (entries.length === 0) {
|
|
352
|
+
rememberNotServed(options.overlayDir, scope, result.notServed.filter((n) => !remembered.has(n)), now);
|
|
353
|
+
return finish(result);
|
|
354
|
+
}
|
|
355
|
+
// 2–3. Fields, then the connector records the object decisions read.
|
|
356
|
+
entries = await enrichAll(ctx, entries);
|
|
357
|
+
const records = await fetchConnectorRecordsForKeys(ctx, entries.map((e) => e.connector?.key));
|
|
358
|
+
for (const entry of entries)
|
|
359
|
+
mergeConnectorRecord(entry, records.get(entry.connector?.key) ?? null);
|
|
360
|
+
// 4. Generic CRUD templates into their objects. An expansion that yields
|
|
361
|
+
// nothing (the object listing failed, or names no object asked for) is that
|
|
362
|
+
// node type's failure, not a silent drop.
|
|
363
|
+
const expanded = [];
|
|
364
|
+
for (const entry of entries) {
|
|
365
|
+
try {
|
|
366
|
+
const variants = await entriesFor(ctx, entry, grouped.get(entry.nodeType));
|
|
367
|
+
if (variants.length === 0) {
|
|
368
|
+
const asked = grouped.get(entry.nodeType);
|
|
369
|
+
result.failed.push({
|
|
370
|
+
nodeType: entry.nodeType,
|
|
371
|
+
reason: asked === undefined
|
|
372
|
+
? "the connector lists no object for this generic operation"
|
|
373
|
+
: `the connector lists none of the objects asked for (${[...asked].join(", ")})`,
|
|
374
|
+
});
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
expanded.push(...variants);
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
result.failed.push({ nodeType: entry.nodeType, reason: messageOf(error) });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// 5. Events, a generic one described only for the objects asked for, then
|
|
384
|
+
// the curated remaps the build applies last.
|
|
385
|
+
const keepObject = (template, objectName) => {
|
|
386
|
+
const asked = grouped.get(template.nodeType);
|
|
387
|
+
return asked === undefined || [...asked].some((o) => o.toLowerCase() === objectName.toLowerCase());
|
|
388
|
+
};
|
|
389
|
+
const [described, expandedEvents] = await resolveConnectorEvents(ctx, expanded, keepObject);
|
|
390
|
+
entries = [...described, ...sortExpandedEntries(expandedEvents)];
|
|
391
|
+
applyCuratedOverrides(entries);
|
|
392
|
+
for (const entry of entries)
|
|
393
|
+
entry.provenance = { source: FETCHED_SOURCE };
|
|
394
|
+
const plan = planEach(entries, (nodeType) => nodes.get(nodeType), result.failed);
|
|
395
|
+
for (const line of plan.warnings)
|
|
396
|
+
reporter.warn(line);
|
|
397
|
+
const { files, rows, collisions } = withoutExisting(plan, overlayHolds(options.overlayDir));
|
|
398
|
+
for (const row of collisions) {
|
|
399
|
+
result.failed.push({
|
|
400
|
+
nodeType: row.nodeType,
|
|
401
|
+
reason: `its object ${JSON.stringify(row.objectName ?? "")} would be written where the overlay already keeps another object (${descriptorOverlayPath(row.path)})`,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (rows.length > 0) {
|
|
405
|
+
const staging = mkdtempSync(join(tmpdir(), "flow-sdk-fetch-"));
|
|
406
|
+
try {
|
|
407
|
+
writePlan({ ...plan, files }, staging);
|
|
408
|
+
await applyCorrectionsAndSideTables(staging, options.overlayDir);
|
|
409
|
+
mergeInto(staging, options.overlayDir);
|
|
410
|
+
}
|
|
411
|
+
finally {
|
|
412
|
+
rmSync(staging, { recursive: true, force: true });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
// What was asked for and is not in the overlay now (dropped by a path
|
|
416
|
+
// collision, or another version than the one asked for) is a failure, not
|
|
417
|
+
// a success the next resolve contradicts.
|
|
418
|
+
const held = overlayHolds(options.overlayDir);
|
|
419
|
+
const heldRows = [...held.variants].map((v) => JSON.parse(v));
|
|
420
|
+
const holds = (nodeType, test) => heldRows.some(([n, version, objectName]) => n === nodeType && test(String(version ?? ""), String(objectName ?? "")));
|
|
421
|
+
for (const [nodeType, objects] of grouped) {
|
|
422
|
+
if (result.failed.some((f) => f.nodeType === nodeType) || !nodes.has(nodeType))
|
|
423
|
+
continue;
|
|
424
|
+
for (const asked of objects ?? []) {
|
|
425
|
+
if (!holds(nodeType, (_v, o) => o.toLowerCase() === asked.toLowerCase())) {
|
|
426
|
+
result.failed.push({ nodeType, reason: `the object ${JSON.stringify(asked)} was not written (see the warnings above)` });
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
for (const version of versions.get(nodeType) ?? []) {
|
|
430
|
+
if (!holds(nodeType, (v) => v === version)) {
|
|
431
|
+
const served = [...new Set(heldRows.filter(([n]) => n === nodeType).map(([, v]) => v))].sort().join(", ");
|
|
432
|
+
result.failed.push({ nodeType, reason: `the tenant serves version ${served || "none"}, not ${version}` });
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
rememberNotServed(options.overlayDir, scope, result.notServed.filter((n) => !remembered.has(n)), now);
|
|
437
|
+
result.fetched = [...new Set(rows.map((row) => row.nodeType))].sort();
|
|
438
|
+
for (const nodeType of result.fetched)
|
|
439
|
+
reporter.info(`fetched ${nodeType} from the tenant into ${options.overlayDir}`);
|
|
440
|
+
return finish(result);
|
|
441
|
+
}
|
|
442
|
+
/** `result` with its lists sorted, as callers print them. */
|
|
443
|
+
function finish(result) {
|
|
444
|
+
result.notServed.sort();
|
|
445
|
+
result.failed.sort((a, b) => (a.nodeType < b.nodeType ? -1 : a.nodeType > b.nodeType ? 1 : 0));
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DefinitionRequest } from "./fetch-definitions.js";
|
|
2
|
+
/** The connector node types `flow` uses, root and subflows, deduplicated, each with its saved object when it has one. */
|
|
3
|
+
export declare function flowConnectorRequests(flow: unknown): DefinitionRequest[];
|
|
4
|
+
/**
|
|
5
|
+
* The `LibraryOpts.hide` predicate that reproduces a decompile's library from
|
|
6
|
+
* its stamp's `lacked=`: every row of a node type that decompile lacked, under
|
|
7
|
+
* the name the fetch writes it as too. A start trigger the `.flow` names as
|
|
8
|
+
* `uipath.connector.trigger.K.E` is fetched (and indexed) as its wait form
|
|
9
|
+
* `uipath.connector.event.K.E`, from which the library derives the start form,
|
|
10
|
+
* so hiding only the trigger name would leave the trigger resolvable.
|
|
11
|
+
*/
|
|
12
|
+
export declare function hidesLacked(lacked: readonly string[]): (row: {
|
|
13
|
+
nodeType?: unknown;
|
|
14
|
+
}) => boolean;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connector definitions a saved `.flow` uses, as fetch requests: every
|
|
3
|
+
* `uipath.connector.*` node type its nodes and its `definitions[]` name, with
|
|
4
|
+
* the object a node's saved configuration records, so a generic operation is
|
|
5
|
+
* fetched for that object rather than for every object the connector has.
|
|
6
|
+
*
|
|
7
|
+
* `decompile` and `merge` fetch these before they open the library
|
|
8
|
+
* (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md §3.4): decompile decides what to
|
|
9
|
+
* carry from the file by what the library holds, so the library has to hold
|
|
10
|
+
* what the tenant serves before it decides.
|
|
11
|
+
*/
|
|
12
|
+
import { readConfigurationIdentity } from "../../core/connector-configuration.js";
|
|
13
|
+
import { fetchableNodeType } from "./fetch-definitions.js";
|
|
14
|
+
const CONNECTOR_PREFIX = "uipath.connector.";
|
|
15
|
+
/**
|
|
16
|
+
* The object a saved connector node names, by the rule decompile lifts it with
|
|
17
|
+
* (`liftedObject` in `nodes/connector/flow/node-type.ts`): the configuration's
|
|
18
|
+
* identity (flat or `essentialConfiguration` envelope), else the node's sibling
|
|
19
|
+
* `detail.objectName`; none for a curated operation, whose object is fixed.
|
|
20
|
+
*/
|
|
21
|
+
function savedObjectName(detail) {
|
|
22
|
+
if (!detail || typeof detail !== "object")
|
|
23
|
+
return undefined;
|
|
24
|
+
const d = detail;
|
|
25
|
+
const identity = readConfigurationIdentity(d.configuration);
|
|
26
|
+
if (identity.activityType === "Curated")
|
|
27
|
+
return undefined;
|
|
28
|
+
if (identity.objectName !== undefined)
|
|
29
|
+
return identity.objectName;
|
|
30
|
+
return typeof d.objectName === "string" && d.objectName !== "" ? d.objectName : undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Every node of `flow` and of each subflow it holds, however deep. */
|
|
33
|
+
function allNodes(flow) {
|
|
34
|
+
const doc = flow;
|
|
35
|
+
const own = Array.isArray(doc?.nodes) ? doc.nodes : [];
|
|
36
|
+
const subflows = doc?.subflows && typeof doc.subflows === "object" ? Object.values(doc.subflows) : [];
|
|
37
|
+
return [...own, ...subflows.flatMap(allNodes)];
|
|
38
|
+
}
|
|
39
|
+
/** Every `definitions[]` row of `flow` and of each subflow it holds. */
|
|
40
|
+
function allDefinitions(flow) {
|
|
41
|
+
const doc = flow;
|
|
42
|
+
const own = Array.isArray(doc?.definitions) ? doc.definitions : [];
|
|
43
|
+
const subflows = doc?.subflows && typeof doc.subflows === "object" ? Object.values(doc.subflows) : [];
|
|
44
|
+
return [...own, ...subflows.flatMap(allDefinitions)];
|
|
45
|
+
}
|
|
46
|
+
/** The connector node types `flow` uses, root and subflows, deduplicated, each with its saved object when it has one. */
|
|
47
|
+
export function flowConnectorRequests(flow) {
|
|
48
|
+
const requests = new Map();
|
|
49
|
+
const add = (nodeType, objectName) => {
|
|
50
|
+
if (typeof nodeType !== "string" || !nodeType.startsWith(CONNECTOR_PREFIX))
|
|
51
|
+
return;
|
|
52
|
+
const key = JSON.stringify([nodeType, objectName ?? null]);
|
|
53
|
+
if (!requests.has(key))
|
|
54
|
+
requests.set(key, { nodeType, ...(objectName ? { objectName } : {}) });
|
|
55
|
+
};
|
|
56
|
+
for (const node of allNodes(flow)) {
|
|
57
|
+
const n = node;
|
|
58
|
+
add(n.type, savedObjectName(n.inputs?.detail));
|
|
59
|
+
}
|
|
60
|
+
// A definition names a node type and no object: asked for only when no node did,
|
|
61
|
+
// since "no object" fetches every object of a generic operation.
|
|
62
|
+
const named = new Set([...requests.values()].map((r) => r.nodeType));
|
|
63
|
+
for (const definition of allDefinitions(flow)) {
|
|
64
|
+
const nodeType = definition.nodeType;
|
|
65
|
+
if (typeof nodeType === "string" && !named.has(nodeType))
|
|
66
|
+
add(nodeType);
|
|
67
|
+
}
|
|
68
|
+
return [...requests.values()];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The `LibraryOpts.hide` predicate that reproduces a decompile's library from
|
|
72
|
+
* its stamp's `lacked=`: every row of a node type that decompile lacked, under
|
|
73
|
+
* the name the fetch writes it as too. A start trigger the `.flow` names as
|
|
74
|
+
* `uipath.connector.trigger.K.E` is fetched (and indexed) as its wait form
|
|
75
|
+
* `uipath.connector.event.K.E`, from which the library derives the start form,
|
|
76
|
+
* so hiding only the trigger name would leave the trigger resolvable.
|
|
77
|
+
*/
|
|
78
|
+
export function hidesLacked(lacked) {
|
|
79
|
+
const hidden = new Set(lacked.flatMap((nodeType) => [nodeType, fetchableNodeType(nodeType)]));
|
|
80
|
+
return (row) => typeof row.nodeType === "string" && hidden.has(row.nodeType);
|
|
81
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Library } from "../../core/library.js";
|
|
2
|
+
import { type Reporter } from "../reporter.js";
|
|
3
|
+
import type { UipClient } from "../uip/client.js";
|
|
4
|
+
import { type DefinitionRequest } from "./fetch-definitions.js";
|
|
5
|
+
export interface WithFetchedDefinitionsOptions {
|
|
6
|
+
client?: UipClient;
|
|
7
|
+
reporter?: Reporter;
|
|
8
|
+
/** The CLI's name, for its stderr lines. */
|
|
9
|
+
who?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Why each node type (as fetched) is still missing, shared across calls: a
|
|
12
|
+
* command that fetches in two steps (`merge`: the original's operations, then
|
|
13
|
+
* what the edit adds) keeps the first step's notes for the second's refusal.
|
|
14
|
+
*/
|
|
15
|
+
notes?: Map<string, string>;
|
|
16
|
+
}
|
|
17
|
+
/** The overlay a fetch writes into: the one the library opens, else `.flow-sdk/connectors-local`. */
|
|
18
|
+
export declare function fetchOverlayDir(argv: readonly string[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* `work(library)`, after fetching what it missed. Returns its value or throws
|
|
21
|
+
* what its last pass threw.
|
|
22
|
+
*/
|
|
23
|
+
export declare function withFetchedDefinitions<T>(argv: readonly string[], work: (library: Library | undefined) => T | Promise<T>, options?: WithFetchedDefinitionsOptions): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* The library for a command that knows up front which node types it needs —
|
|
26
|
+
* `decompile` and `merge`, from the saved file — with every one of them no
|
|
27
|
+
* layer carries fetched first. The library opened after the fetch carries the
|
|
28
|
+
* notes for what is still missing, as {@link withFetchedDefinitions}'s last pass does.
|
|
29
|
+
*
|
|
30
|
+
* With the fetch off it is `openCliLibrary(argv)`, as before.
|
|
31
|
+
*/
|
|
32
|
+
export declare function openWithFetchedDefinitions(argv: readonly string[], requests: readonly DefinitionRequest[], options?: WithFetchedDefinitionsOptions): Promise<Library | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Fetch, through `uip`, what one probing run of `probe` found missing: the node
|
|
35
|
+
* types it resolved (`onMiss`) and the connectors it reversed a saved wire
|
|
36
|
+
* against (`onConnectorMiss`). A connector is fetched whole, with its typed
|
|
37
|
+
* module, because a decompiler identifies an operation from its saved method
|
|
38
|
+
* and path and so cannot name the node type it is missing.
|
|
39
|
+
*
|
|
40
|
+
* For the decompilers and BPMN `merge`, whose work has side effects or whose
|
|
41
|
+
* baseline must decompile the same way twice: the probe's result is discarded
|
|
42
|
+
* (and what it throws is swallowed), and the caller then opens the library
|
|
43
|
+
* once, with {@link openCliLibrary} and `always`, and runs for real. What could
|
|
44
|
+
* not be fetched is a warning; the caller's own refusal says the rest.
|
|
45
|
+
*/
|
|
46
|
+
export declare function fetchMissedBy(argv: readonly string[], probe: (library: Library) => unknown, options?: WithFetchedDefinitionsOptions): Promise<void>;
|