@uipath/uipath-extensions-sdk 0.1.21 → 0.1.23
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 +64 -14
- package/dist/adopt.d.ts +6 -0
- package/dist/adopt.js +462 -101
- package/dist/adopt.js.map +1 -1
- package/dist/cli.js +42 -7
- package/dist/cli.js.map +1 -1
- package/dist/commands/build-check.d.ts +2 -2
- package/dist/commands/build-check.js +43 -18
- package/dist/commands/build-check.js.map +1 -1
- package/dist/commands/new.d.ts +1 -0
- package/dist/commands/new.js +44 -2
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/pack.d.ts +12 -0
- package/dist/commands/pack.js +96 -30
- package/dist/commands/pack.js.map +1 -1
- package/dist/commands/submit.d.ts +41 -1
- package/dist/commands/submit.js +484 -23
- package/dist/commands/submit.js.map +1 -1
- package/dist/commands/upload.d.ts +4 -0
- package/dist/commands/upload.js +98 -26
- package/dist/commands/upload.js.map +1 -1
- package/dist/commands/validate-python.d.ts +15 -0
- package/dist/commands/validate-python.js +334 -0
- package/dist/commands/validate-python.js.map +1 -0
- package/dist/commands/validate.js +2 -1
- package/dist/commands/validate.js.map +1 -1
- package/dist/connector.d.ts +23 -0
- package/dist/connector.js +258 -0
- package/dist/connector.js.map +1 -0
- package/dist/github.d.ts +6 -0
- package/dist/github.js +12 -0
- package/dist/github.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +4 -1
- package/dist/lib.js +307 -27
- package/dist/lib.js.map +1 -1
- package/dist/pyproject.d.ts +1 -0
- package/dist/pyproject.js +16 -0
- package/dist/pyproject.js.map +1 -0
- package/dist/python-source.d.ts +25 -0
- package/dist/python-source.js +359 -0
- package/dist/python-source.js.map +1 -0
- package/dist/registrationFile.d.ts +10 -0
- package/dist/registrationFile.js +51 -1
- package/dist/registrationFile.js.map +1 -1
- package/dist/sourceWalk.d.ts +2 -1
- package/dist/sourceWalk.js +5 -3
- package/dist/sourceWalk.js.map +1 -1
- package/dist/symlinkProblem.d.ts +1 -0
- package/dist/symlinkProblem.js +25 -0
- package/dist/symlinkProblem.js.map +1 -0
- package/dist/verdict.d.ts +6 -0
- package/dist/verdict.js +13 -0
- package/dist/verdict.js.map +1 -0
- package/package.json +6 -2
package/dist/commands/submit.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readFile, rm, writeFile, } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { assetsProblem, CONNECTOR_KEY, ConnectorError, connectorFacts, connectorIdParts, connectorKeyFor, idOf, isAllowedSourceDir, isAllowedSourcePath, isConnectorProject, isFaultFixture, isLocalOnlySource, kindOfPaths, loadConnectorTemplate, loadTemplate, MANIFEST_FILE, packageNameProblem, readConnectorFiles, SHARED_PUBLISHER, secretFindings, } from "@uipath/uipath-extensions-gates";
|
|
5
|
+
import semver from "semver";
|
|
4
6
|
import { parse, stringify } from "yaml";
|
|
7
|
+
import { isPythonFunctionProject } from "../adopt.js";
|
|
8
|
+
import { connectorPackageId, validateConnector, withConnectorKey, withConnectorVersion, } from "../connector.js";
|
|
5
9
|
import { GitHubError, HeadMovedError, } from "../github.js";
|
|
6
10
|
import { SDK_PACKAGE } from "../manifest.js";
|
|
7
|
-
import {
|
|
11
|
+
import { pythonFunctions, readDeclaredKind, readPythonFunctionSource, suggestedKind, } from "../python-source.js";
|
|
12
|
+
import { EMAIL, isMaintainerLogin, maintainerProblems, REGISTRATION_FILE, registrationFileCheck, withoutControls, } from "../registrationFile.js";
|
|
8
13
|
import { excludedNames, isSkippedEntry, offListRemedy, walkSources, } from "../sourceWalk.js";
|
|
14
|
+
import { PackError, projectKind, readPackageInfo } from "./pack.js";
|
|
9
15
|
import { validate as runValidate, } from "./validate.js";
|
|
16
|
+
import { validatePythonFunction } from "./validate-python.js";
|
|
10
17
|
export const DEFAULT_INDEX_REPO = "UiPath/uipath-extensions";
|
|
11
18
|
const TEMPLATE_PATH = ".github/PULL_REQUEST_TEMPLATE.md";
|
|
12
19
|
const REPO = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
|
|
13
20
|
const LABEL = "registration";
|
|
21
|
+
export const PYTHON_SUBMIT_BLOCKED = "Python functions can be checked with submit --dry-run, but the registry does not yet support publishing them";
|
|
14
22
|
const MAX_FILES = 200;
|
|
15
23
|
const MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
16
24
|
const MAX_TOTAL_BYTES = 20 * 1024 * 1024;
|
|
@@ -18,6 +26,7 @@ const MAX_REPORTED_PROBLEMS = 10;
|
|
|
18
26
|
const READ_ON_PROBLEMS = new Set([
|
|
19
27
|
MANIFEST_FILE,
|
|
20
28
|
"package.json",
|
|
29
|
+
"pyproject.toml",
|
|
21
30
|
"project.uiproj",
|
|
22
31
|
]);
|
|
23
32
|
const OLD_LAYOUT = "src/ is the old node layout; put functions in functions/ and node.ts in maestro/";
|
|
@@ -97,25 +106,26 @@ export async function collectFolder(root) {
|
|
|
97
106
|
const problems = [];
|
|
98
107
|
const skipped = [];
|
|
99
108
|
const found = [];
|
|
109
|
+
const kind = await projectKind(root);
|
|
100
110
|
const excluded = excludedNames(await readUipathJson(root));
|
|
101
111
|
await walkSources(root, async (entry, path, dir) => {
|
|
102
|
-
if (dir === "" && isLocalOnlySource(entry.name)) {
|
|
112
|
+
if (dir === "" && isLocalOnlySource(entry.name, kind)) {
|
|
103
113
|
skipped.push(entry.isDirectory() ? `${path}/` : path);
|
|
104
114
|
}
|
|
105
115
|
else if (dir === "" && entry.isFile() && path === REGISTRATION_FILE) {
|
|
106
116
|
skipped.push(path);
|
|
107
117
|
}
|
|
108
|
-
else if (isSkippedEntry(entry, dir, excluded)) {
|
|
118
|
+
else if (isSkippedEntry(entry, dir, excluded, kind)) {
|
|
109
119
|
return false;
|
|
110
120
|
}
|
|
111
121
|
else if (entry.isSymbolicLink()) {
|
|
112
122
|
problems.push(`${path} is a symlink`);
|
|
113
123
|
}
|
|
114
124
|
else if (entry.isDirectory()) {
|
|
115
|
-
if (dir === "" && entry.name === "src") {
|
|
125
|
+
if (kind === "function" && dir === "" && entry.name === "src") {
|
|
116
126
|
problems.push(OLD_LAYOUT);
|
|
117
127
|
}
|
|
118
|
-
else if (dir === "" && !isAllowedSourceDir(entry.name)) {
|
|
128
|
+
else if (dir === "" && !isAllowedSourceDir(entry.name, kind)) {
|
|
119
129
|
problems.push(`${path}/ is not on the allow list, ${offListRemedy(`${path}/`)}`);
|
|
120
130
|
}
|
|
121
131
|
else {
|
|
@@ -125,7 +135,7 @@ export async function collectFolder(root) {
|
|
|
125
135
|
else if (!entry.isFile()) {
|
|
126
136
|
problems.push(`${path} is not a regular file`);
|
|
127
137
|
}
|
|
128
|
-
else if (!isAllowedSourcePath(path)) {
|
|
138
|
+
else if (!isAllowedSourcePath(path, kind)) {
|
|
129
139
|
problems.push(`${path} is not on the allow list, ${offListRemedy(path)}`);
|
|
130
140
|
}
|
|
131
141
|
else {
|
|
@@ -140,6 +150,9 @@ export async function collectFolder(root) {
|
|
|
140
150
|
if (found.length + 1 > MAX_FILES) {
|
|
141
151
|
problems.push(`the folder holds ${found.length} files, and the limit is ${MAX_FILES} with ${REGISTRATION_FILE}`);
|
|
142
152
|
}
|
|
153
|
+
const assets = assetsProblem(found.map((file) => file.path));
|
|
154
|
+
if (assets !== undefined)
|
|
155
|
+
problems.push(assets);
|
|
143
156
|
const total = found.reduce((sum, file) => sum + file.size, 0);
|
|
144
157
|
if (total > MAX_TOTAL_BYTES) {
|
|
145
158
|
problems.push(`the files add up to ${mebibytes(total)}, over the ${mebibytes(MAX_TOTAL_BYTES)} limit for one pull request`);
|
|
@@ -162,6 +175,198 @@ export async function collectFolder(root) {
|
|
|
162
175
|
}));
|
|
163
176
|
return { files, skipped, problems: reported };
|
|
164
177
|
}
|
|
178
|
+
const CONNECTOR_SKIPPED = [
|
|
179
|
+
"package.json",
|
|
180
|
+
"package-lock.json",
|
|
181
|
+
"app/package.json",
|
|
182
|
+
"node_modules",
|
|
183
|
+
];
|
|
184
|
+
// The gates run on the same bytes that submit selects.
|
|
185
|
+
async function inSourceSnapshot(files, validate) {
|
|
186
|
+
const snapshot = await mkdtemp(join(tmpdir(), "extension-submit-"));
|
|
187
|
+
try {
|
|
188
|
+
for (const file of files) {
|
|
189
|
+
await mkdir(dirname(join(snapshot, file.path)), { recursive: true });
|
|
190
|
+
await writeFile(join(snapshot, file.path), file.content, { flag: "wx" });
|
|
191
|
+
}
|
|
192
|
+
return await validate(snapshot);
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
await rm(snapshot, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function sharedIdOf(folderKey) {
|
|
199
|
+
const name = folderKey.split("-").at(-1) ?? "";
|
|
200
|
+
const id = `${SHARED_PUBLISHER}.${name}`;
|
|
201
|
+
try {
|
|
202
|
+
connectorKeyFor(id);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (!(error instanceof ConnectorError))
|
|
206
|
+
throw error;
|
|
207
|
+
throw new ConnectorError(`the folder key ${JSON.stringify(folderKey.slice(0, 80))} does not end in a name of lowercase letters and digits, so pass the node id as <publisher>.<name>`);
|
|
208
|
+
}
|
|
209
|
+
return id;
|
|
210
|
+
}
|
|
211
|
+
// validate checks what submit would send: the folder's files with the community key of the node id, in a copy.
|
|
212
|
+
export async function validateConnectorSource(projectDir, id) {
|
|
213
|
+
const collected = await collectConnectorFolder(projectDir);
|
|
214
|
+
let folderKey;
|
|
215
|
+
try {
|
|
216
|
+
folderKey = connectorFacts(collected.files).key;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (!(error instanceof ConnectorError))
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
const nodeId = id ??
|
|
223
|
+
(folderKey === undefined || CONNECTOR_KEY.test(folderKey)
|
|
224
|
+
? undefined
|
|
225
|
+
: sharedIdOf(folderKey));
|
|
226
|
+
if (nodeId === undefined) {
|
|
227
|
+
return {
|
|
228
|
+
...withFolderProblems(await validateSnapshot(collected.files), collected.problems),
|
|
229
|
+
...(folderKey !== undefined && { folderKey }),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
const keyed = withConnectorKey(collected.files, nodeId);
|
|
233
|
+
return {
|
|
234
|
+
...withFolderProblems(await validateSnapshot(keyed.files, { nodeId }), collected.problems),
|
|
235
|
+
...(folderKey !== undefined && { folderKey }),
|
|
236
|
+
key: keyed.key,
|
|
237
|
+
id: nodeId,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const CONTENTS_GATE = "connector-contents";
|
|
241
|
+
// The copy holds only the files submit would send, so what the folder walk refused is reported here.
|
|
242
|
+
function withFolderProblems(checked, problems) {
|
|
243
|
+
if (problems.length === 0)
|
|
244
|
+
return checked;
|
|
245
|
+
const findings = problems.map((message) => ({
|
|
246
|
+
gate: CONTENTS_GATE,
|
|
247
|
+
severity: "error",
|
|
248
|
+
message,
|
|
249
|
+
}));
|
|
250
|
+
const held = checked.report.results.some((result) => result.id === CONTENTS_GATE);
|
|
251
|
+
const results = held
|
|
252
|
+
? checked.report.results.map((result) => result.id === CONTENTS_GATE
|
|
253
|
+
? {
|
|
254
|
+
...result,
|
|
255
|
+
status: "fail",
|
|
256
|
+
findings: [...result.findings, ...findings],
|
|
257
|
+
}
|
|
258
|
+
: result)
|
|
259
|
+
: [
|
|
260
|
+
...checked.report.results,
|
|
261
|
+
{ id: CONTENTS_GATE, status: "fail", findings },
|
|
262
|
+
];
|
|
263
|
+
return { report: { ...checked.report, results }, ok: false };
|
|
264
|
+
}
|
|
265
|
+
function validateSnapshot(files, context = {}) {
|
|
266
|
+
return inSourceSnapshot(files, (projectDir) => validateConnector({ projectDir, ...context }));
|
|
267
|
+
}
|
|
268
|
+
async function validatePythonSnapshot(files, exec) {
|
|
269
|
+
return inSourceSnapshot(files, async (projectDir) => {
|
|
270
|
+
const result = await validatePythonFunction({
|
|
271
|
+
projectDir,
|
|
272
|
+
...(exec && { exec }),
|
|
273
|
+
});
|
|
274
|
+
try {
|
|
275
|
+
return {
|
|
276
|
+
report: result.report,
|
|
277
|
+
ok: result.report.results.every(({ status }) => status !== "fail"),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
await result.cleanup();
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function nodeKindOf(paths, config) {
|
|
286
|
+
const kind = kindOfPaths(paths);
|
|
287
|
+
if (kind !== "agent" || config === undefined)
|
|
288
|
+
return kind;
|
|
289
|
+
try {
|
|
290
|
+
return pythonFunctions(JSON.parse(config)) === undefined
|
|
291
|
+
? kind
|
|
292
|
+
: "python-function";
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
return kind;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function collectConnectorFolder(root) {
|
|
299
|
+
const { files, problems } = await readConnectorFiles(root);
|
|
300
|
+
const skipped = [];
|
|
301
|
+
const registration = await lstat(join(root, REGISTRATION_FILE)).catch(() => undefined);
|
|
302
|
+
if (registration?.isFile())
|
|
303
|
+
skipped.push(REGISTRATION_FILE);
|
|
304
|
+
for (const path of CONNECTOR_SKIPPED) {
|
|
305
|
+
if (await lstat(join(root, path)).then(() => true, () => false)) {
|
|
306
|
+
skipped.push(path);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (files.length + 1 > MAX_FILES) {
|
|
310
|
+
problems.push(`the folder holds ${files.length} files, and the limit is ${MAX_FILES} with ${REGISTRATION_FILE}`);
|
|
311
|
+
}
|
|
312
|
+
return { files, skipped, problems: problems.slice(0, MAX_REPORTED_PROBLEMS) };
|
|
313
|
+
}
|
|
314
|
+
function connectorIdentity(files, id) {
|
|
315
|
+
try {
|
|
316
|
+
return {
|
|
317
|
+
packageId: connectorPackageId(id),
|
|
318
|
+
version: connectorFacts(files).version,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
if (error instanceof ConnectorError)
|
|
323
|
+
throw new SubmitError(error.message);
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const BUMPS = new Set(["patch", "minor", "major"]);
|
|
328
|
+
export const FIRST_CONNECTOR_VERSION = "1.0.0";
|
|
329
|
+
export function approvedVersions(existing) {
|
|
330
|
+
if (existing === undefined)
|
|
331
|
+
return [];
|
|
332
|
+
let data;
|
|
333
|
+
try {
|
|
334
|
+
data = parse(existing);
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
throw new SubmitError("the registration file in the index is not YAML");
|
|
338
|
+
}
|
|
339
|
+
const approved = isRecord(data) ? data.approved : undefined;
|
|
340
|
+
return Array.isArray(approved)
|
|
341
|
+
? approved.flatMap((item) => isRecord(item) && typeof item.version === "string"
|
|
342
|
+
? [item.version]
|
|
343
|
+
: [])
|
|
344
|
+
: [];
|
|
345
|
+
}
|
|
346
|
+
export function bumpProblem(bump, connector) {
|
|
347
|
+
if (bump === undefined)
|
|
348
|
+
return undefined;
|
|
349
|
+
if (!BUMPS.has(bump))
|
|
350
|
+
return "--bump must be patch, minor or major";
|
|
351
|
+
if (!connector) {
|
|
352
|
+
return "--bump is for connectors only. A function or agent takes its version from package.json, so set it there and run submit without --bump";
|
|
353
|
+
}
|
|
354
|
+
return undefined;
|
|
355
|
+
}
|
|
356
|
+
// The index holds the version history, so the next version is the highest approved one plus the bump.
|
|
357
|
+
export function nextConnectorVersion(previous, bump) {
|
|
358
|
+
const problem = bumpProblem(bump, true);
|
|
359
|
+
if (problem !== undefined)
|
|
360
|
+
throw new SubmitError(problem);
|
|
361
|
+
const valid = previous.filter((version) => semver.valid(version) === version);
|
|
362
|
+
if (valid.length === 0)
|
|
363
|
+
return FIRST_CONNECTOR_VERSION;
|
|
364
|
+
const highest = semver.rsort([...valid])[0];
|
|
365
|
+
if (bump === undefined) {
|
|
366
|
+
throw new SubmitError(`the index already holds this connector up to ${highest}, so pass --bump patch, minor or major`);
|
|
367
|
+
}
|
|
368
|
+
return semver.inc(highest, bump);
|
|
369
|
+
}
|
|
165
370
|
const SCANNED_ON_SEND = [MANIFEST_FILE, "project.uiproj"];
|
|
166
371
|
function sentSecretProblems(files) {
|
|
167
372
|
return SCANNED_ON_SEND.flatMap((name) => {
|
|
@@ -206,6 +411,28 @@ function readPackageJson(files) {
|
|
|
206
411
|
throw new SubmitError(problem);
|
|
207
412
|
return { packageId: declared.name, version: declared.version };
|
|
208
413
|
}
|
|
414
|
+
async function agentIdentity(projectDir) {
|
|
415
|
+
try {
|
|
416
|
+
const { name, version } = await readPackageInfo(projectDir);
|
|
417
|
+
return { packageId: name, version };
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
if (error instanceof PackError)
|
|
421
|
+
throw new SubmitError(error.message);
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function registrationKind(text) {
|
|
426
|
+
try {
|
|
427
|
+
const data = parse(text);
|
|
428
|
+
return isRecord(data) && typeof data.kind === "string"
|
|
429
|
+
? data.kind
|
|
430
|
+
: undefined;
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
209
436
|
export function registrationText(input) {
|
|
210
437
|
const { id, packageId, version, date, securityContact, existing } = input;
|
|
211
438
|
const entry = {
|
|
@@ -220,8 +447,11 @@ export function registrationText(input) {
|
|
|
220
447
|
id,
|
|
221
448
|
package: packageId,
|
|
222
449
|
security_contact: securityContact,
|
|
450
|
+
...(input.kind && { kind: input.kind }),
|
|
223
451
|
deprecated: null,
|
|
224
452
|
approved: [entry],
|
|
453
|
+
...(input.maintainers &&
|
|
454
|
+
input.maintainers.length > 0 && { maintainers: input.maintainers }),
|
|
225
455
|
}, options);
|
|
226
456
|
}
|
|
227
457
|
let data;
|
|
@@ -244,6 +474,17 @@ export function registrationText(input) {
|
|
|
244
474
|
if (approved.some((item) => isRecord(item) && item.version === version)) {
|
|
245
475
|
throw new SubmitError(`${id} ${version} is already in the registration file of the index. Bump the version, then run submit again.`);
|
|
246
476
|
}
|
|
477
|
+
if (input.higherThanApproved) {
|
|
478
|
+
const notLower = approved.flatMap((item) => isRecord(item) &&
|
|
479
|
+
typeof item.version === "string" &&
|
|
480
|
+
semver.valid(item.version) === item.version &&
|
|
481
|
+
!semver.gt(version, item.version)
|
|
482
|
+
? [item.version]
|
|
483
|
+
: []);
|
|
484
|
+
if (notLower.length > 0) {
|
|
485
|
+
throw new SubmitError(`${id} ${version} is not higher than ${notLower.join(", ")} in the registration file of the index, and a connector version only goes up`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
247
488
|
return stringify({
|
|
248
489
|
...data,
|
|
249
490
|
...(securityContact && { security_contact: securityContact }),
|
|
@@ -277,6 +518,44 @@ function checkInputs(index, securityContact) {
|
|
|
277
518
|
throw new SubmitError("the security contact must be an email address such as security@acme.example");
|
|
278
519
|
}
|
|
279
520
|
}
|
|
521
|
+
async function signedInMaintainer(github) {
|
|
522
|
+
let login;
|
|
523
|
+
let user;
|
|
524
|
+
try {
|
|
525
|
+
login = (await github.currentLogin()).toLowerCase();
|
|
526
|
+
if (!isMaintainerLogin(login)) {
|
|
527
|
+
return {
|
|
528
|
+
reason: `the signed-in account ${login} does not have the login shape of a user`,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
user = await github.user(login);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
if (!(error instanceof GitHubError))
|
|
535
|
+
throw error;
|
|
536
|
+
return {
|
|
537
|
+
reason: `GitHub did not say who is signed in (${error.message})`,
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
if (!user)
|
|
541
|
+
return { reason: `GitHub has no user ${login}` };
|
|
542
|
+
if (user.type !== "User") {
|
|
543
|
+
return { reason: `the signed-in account ${login} is a ${user.type}` };
|
|
544
|
+
}
|
|
545
|
+
return { maintainer: { login, id: user.id } };
|
|
546
|
+
}
|
|
547
|
+
function registeredMaintainers(existing) {
|
|
548
|
+
try {
|
|
549
|
+
const data = parse(existing);
|
|
550
|
+
const listed = isRecord(data) ? data.maintainers : undefined;
|
|
551
|
+
return listed !== undefined && maintainerProblems(listed).length === 0
|
|
552
|
+
? listed.map((kept) => ({ ...kept, from: "index" }))
|
|
553
|
+
: [];
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
return [];
|
|
557
|
+
}
|
|
558
|
+
}
|
|
280
559
|
const APPROVAL_STATES = new Set(["APPROVED", "CHANGES_REQUESTED", "DISMISSED"]);
|
|
281
560
|
export function approvers(reviews) {
|
|
282
561
|
const latest = new Map();
|
|
@@ -347,20 +626,80 @@ async function checkPull(github, index, { branch, head }, baseSha, failures) {
|
|
|
347
626
|
: [headSha, baseSha],
|
|
348
627
|
};
|
|
349
628
|
}
|
|
629
|
+
async function forkProblems(github, index, target, baseSha) {
|
|
630
|
+
const { publisher, name } = connectorIdParts(target.id);
|
|
631
|
+
if (publisher === SHARED_PUBLISHER)
|
|
632
|
+
return [];
|
|
633
|
+
const shared = `nodes/${SHARED_PUBLISHER}/${name}`;
|
|
634
|
+
const sharedId = `${SHARED_PUBLISHER}/${name}`;
|
|
635
|
+
const registered = await github.fileText(index, `${shared}/${REGISTRATION_FILE}`, baseSha);
|
|
636
|
+
const flat = registered === undefined
|
|
637
|
+
? await github.fileText(index, `${shared}.yaml`, baseSha)
|
|
638
|
+
: undefined;
|
|
639
|
+
if (registered === undefined && flat === undefined) {
|
|
640
|
+
return [
|
|
641
|
+
`${target.id} is a fork, and a fork needs the shared connector ${sharedId} in ${index}. Improve the shared connector with a pull request to ${shared}/, or ask its maintainers to add it first`,
|
|
642
|
+
];
|
|
643
|
+
}
|
|
644
|
+
const kind = registered === undefined
|
|
645
|
+
? undefined
|
|
646
|
+
: kindOfPaths((await github.folderPaths(index, baseSha, shared)) ?? []);
|
|
647
|
+
if (kind === "connector")
|
|
648
|
+
return [];
|
|
649
|
+
const held = kind === undefined
|
|
650
|
+
? `${index} holds ${sharedId} with no connector files`
|
|
651
|
+
: `${sharedId} is a ${kind} node in ${index}`;
|
|
652
|
+
return [
|
|
653
|
+
`${target.id} is a fork, and a fork needs the shared connector ${sharedId}, but ${held}. Use a name that no other node of ${SHARED_PUBLISHER} has`,
|
|
654
|
+
];
|
|
655
|
+
}
|
|
350
656
|
function githubFailure(error) {
|
|
351
657
|
if (!(error instanceof GitHubError))
|
|
352
658
|
throw error;
|
|
353
659
|
return error.message;
|
|
354
660
|
}
|
|
355
|
-
async function prepare(options) {
|
|
661
|
+
export async function prepare(options) {
|
|
356
662
|
const { github, securityContact } = options;
|
|
357
663
|
const index = options.index ?? DEFAULT_INDEX_REPO;
|
|
358
664
|
checkInputs(index, securityContact);
|
|
359
|
-
await
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
665
|
+
const connector = await isConnectorProject(options.projectDir);
|
|
666
|
+
const bumped = bumpProblem(options.bump, connector);
|
|
667
|
+
if (bumped !== undefined)
|
|
668
|
+
throw new SubmitError(bumped);
|
|
669
|
+
if (connector) {
|
|
670
|
+
await loadConnectorTemplate(options.projectDir);
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
await loadTemplate(options.projectDir);
|
|
674
|
+
}
|
|
675
|
+
const pythonProject = !connector && (await isPythonFunctionProject(options.projectDir));
|
|
676
|
+
const declaredKind = pythonProject
|
|
677
|
+
? await readDeclaredKind(options.projectDir)
|
|
678
|
+
: undefined;
|
|
679
|
+
if (pythonProject && declaredKind === undefined)
|
|
680
|
+
throw new SubmitError("pyproject.toml does not declare a kind. Run uipath-extensions init --yes (add --kind function|agent when not on a terminal) to record it.");
|
|
681
|
+
if (pythonProject && declaredKind !== undefined) {
|
|
682
|
+
const shape = suggestedKind(JSON.parse(await readFile(join(options.projectDir, "uipath.json"), "utf8")));
|
|
683
|
+
if (shape !== declaredKind)
|
|
684
|
+
throw new SubmitError(`pyproject.toml declares ${declaredKind}, but uipath.json describes a ${shape}`);
|
|
685
|
+
}
|
|
686
|
+
const python = pythonProject
|
|
687
|
+
? await readPythonFunctionSource(options.projectDir)
|
|
688
|
+
: undefined;
|
|
689
|
+
if (python && options.dryRun !== true)
|
|
690
|
+
throw new SubmitError(PYTHON_SUBMIT_BLOCKED);
|
|
691
|
+
const collected = connector
|
|
692
|
+
? await collectConnectorFolder(options.projectDir)
|
|
693
|
+
: python
|
|
694
|
+
? {
|
|
695
|
+
files: [...python.files].map(([path, content]) => ({
|
|
696
|
+
path,
|
|
697
|
+
content,
|
|
698
|
+
})),
|
|
699
|
+
skipped: [],
|
|
700
|
+
problems: [],
|
|
701
|
+
}
|
|
702
|
+
: undefined;
|
|
364
703
|
const failures = [];
|
|
365
704
|
let indexInfo;
|
|
366
705
|
try {
|
|
@@ -375,11 +714,23 @@ async function prepare(options) {
|
|
|
375
714
|
catch (error) {
|
|
376
715
|
failures.push(githubFailure(error));
|
|
377
716
|
}
|
|
378
|
-
const { files, skipped, problems } = await collectFolder(options.projectDir);
|
|
379
|
-
|
|
717
|
+
const { files: folderFiles, skipped, problems, } = collected ?? (await collectFolder(options.projectDir));
|
|
718
|
+
let files = folderFiles;
|
|
719
|
+
const agent = !connector &&
|
|
720
|
+
!python &&
|
|
721
|
+
(await projectKind(options.projectDir)) === "agent";
|
|
722
|
+
failures.push(...problems, ...sentSecretProblems(files), ...(problems.length === 0 && !connector && !python && !agent
|
|
723
|
+
? fixtureSendProblems(files)
|
|
724
|
+
: []));
|
|
380
725
|
let target;
|
|
381
726
|
try {
|
|
382
|
-
target = nodeTarget(
|
|
727
|
+
target = nodeTarget(connector
|
|
728
|
+
? connectorIdentity(files, options.connectorId)
|
|
729
|
+
: python
|
|
730
|
+
? { packageId: python.name, version: python.version }
|
|
731
|
+
: agent
|
|
732
|
+
? await agentIdentity(options.projectDir)
|
|
733
|
+
: readPackageJson(files), index);
|
|
383
734
|
}
|
|
384
735
|
catch (error) {
|
|
385
736
|
if (!(error instanceof SubmitError))
|
|
@@ -404,6 +755,58 @@ async function prepare(options) {
|
|
|
404
755
|
failures.push(githubFailure(error));
|
|
405
756
|
}
|
|
406
757
|
}
|
|
758
|
+
let connectorKey;
|
|
759
|
+
const context = {};
|
|
760
|
+
if (connector && target) {
|
|
761
|
+
try {
|
|
762
|
+
const keyed = withConnectorKey(files, target.id);
|
|
763
|
+
files = keyed.files;
|
|
764
|
+
connectorKey = keyed.key;
|
|
765
|
+
context.nodeId = target.id;
|
|
766
|
+
}
|
|
767
|
+
catch (error) {
|
|
768
|
+
if (!(error instanceof ConnectorError))
|
|
769
|
+
throw error;
|
|
770
|
+
failures.push(error.message);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (connector && indexInfo && target && remote) {
|
|
774
|
+
try {
|
|
775
|
+
const registered = (await github.fileText(index, target.registrationPath, remote.baseSha)) ?? (await github.fileText(index, target.flatPath, remote.baseSha));
|
|
776
|
+
const previous = approvedVersions(registered);
|
|
777
|
+
const version = nextConnectorVersion(previous, options.bump);
|
|
778
|
+
files = withConnectorVersion(files, version);
|
|
779
|
+
target.version = version;
|
|
780
|
+
context.expectedVersion = version;
|
|
781
|
+
context.previousVersions = previous;
|
|
782
|
+
failures.push(...(await forkProblems(github, index, target, remote.baseSha)));
|
|
783
|
+
}
|
|
784
|
+
catch (error) {
|
|
785
|
+
if (error instanceof SubmitError || error instanceof ConnectorError) {
|
|
786
|
+
failures.push(error.message);
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
failures.push(githubFailure(error));
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
const rewritten = connector
|
|
794
|
+
? files.flatMap((file, at) => {
|
|
795
|
+
const before = folderFiles[at]?.content;
|
|
796
|
+
return before !== undefined &&
|
|
797
|
+
Buffer.compare(Buffer.from(before), Buffer.from(file.content)) === 0
|
|
798
|
+
? []
|
|
799
|
+
: [file.path];
|
|
800
|
+
})
|
|
801
|
+
: [];
|
|
802
|
+
const checks = python
|
|
803
|
+
? await validatePythonSnapshot(files, options.exec)
|
|
804
|
+
: connector
|
|
805
|
+
? await validateSnapshot(files, context)
|
|
806
|
+
: await (options.validate ?? runValidate)({
|
|
807
|
+
projectDir: options.projectDir,
|
|
808
|
+
...(options.exec && { exec: options.exec }),
|
|
809
|
+
});
|
|
407
810
|
if (!checks.ok || failures.length > 0 || !indexInfo || !target || !remote) {
|
|
408
811
|
throw checks.ok
|
|
409
812
|
? new PrepareFailedError(failures)
|
|
@@ -419,6 +822,35 @@ async function prepare(options) {
|
|
|
419
822
|
throw new SubmitError(`${index} holds both ${flatPath} and ${registrationPath}, and a node may have only one. Remove one of them, then run submit again.`);
|
|
420
823
|
}
|
|
421
824
|
const existing = current ?? flat;
|
|
825
|
+
const basePaths = current === undefined
|
|
826
|
+
? []
|
|
827
|
+
: ((await github.folderPaths(index, baseSha, folder)) ?? []);
|
|
828
|
+
const baseConfig = basePaths.includes("pyproject.toml") && basePaths.includes("uipath.json")
|
|
829
|
+
? await github.fileText(index, `${folder}/uipath.json`, baseSha)
|
|
830
|
+
: undefined;
|
|
831
|
+
const baseKind = nodeKindOf(basePaths, baseConfig);
|
|
832
|
+
const sentKind = python
|
|
833
|
+
? "python-function"
|
|
834
|
+
: nodeKindOf(files.map((file) => file.path));
|
|
835
|
+
const registeredKind = existing === undefined ? undefined : registrationKind(existing);
|
|
836
|
+
if (declaredKind !== undefined &&
|
|
837
|
+
registeredKind !== undefined &&
|
|
838
|
+
registeredKind !== declaredKind)
|
|
839
|
+
throw new SubmitError(`${id} is registered as ${registeredKind}, but pyproject.toml declares ${declaredKind}. Use a new id for the ${declaredKind}.`);
|
|
840
|
+
if (existing !== undefined &&
|
|
841
|
+
sentKind === "python-function" &&
|
|
842
|
+
baseKind !== "python-function")
|
|
843
|
+
throw new SubmitError(`${id} is already registered as a different node kind. Use a new id for the Python function.`);
|
|
844
|
+
if (existing !== undefined &&
|
|
845
|
+
sentKind === "connector" &&
|
|
846
|
+
baseKind !== "connector") {
|
|
847
|
+
throw new SubmitError(`${id} is registered in ${index} as a ${baseKind ?? "function"} node, and a connector cannot take over its registration. Use a new id for the connector.`);
|
|
848
|
+
}
|
|
849
|
+
if (baseKind !== undefined &&
|
|
850
|
+
sentKind !== undefined &&
|
|
851
|
+
baseKind !== sentKind) {
|
|
852
|
+
throw new SubmitError(`${id} is a ${baseKind} node in ${index}, and submit does not change the kind of a node. Use a new id for the ${sentKind}.`);
|
|
853
|
+
}
|
|
422
854
|
if (existing === undefined && securityContact === undefined) {
|
|
423
855
|
throw new SecurityContactRequiredError(id);
|
|
424
856
|
}
|
|
@@ -441,19 +873,32 @@ async function prepare(options) {
|
|
|
441
873
|
body = `${body.trimEnd()}\n\nGate library: ${checks.report.gateLibraryVersion}\n`;
|
|
442
874
|
}
|
|
443
875
|
}
|
|
876
|
+
const signedIn = existing === undefined ? await signedInMaintainer(github) : undefined;
|
|
877
|
+
const maintainers = existing !== undefined
|
|
878
|
+
? registeredMaintainers(existing)
|
|
879
|
+
: signedIn && "maintainer" in signedIn
|
|
880
|
+
? [{ ...signedIn.maintainer, from: "signed-in" }]
|
|
881
|
+
: [];
|
|
444
882
|
const registration = registrationText({
|
|
445
883
|
id,
|
|
446
884
|
packageId,
|
|
447
885
|
version,
|
|
448
886
|
date: (options.now?.() ?? new Date()).toISOString().slice(0, 10),
|
|
449
887
|
...(securityContact && { securityContact }),
|
|
888
|
+
...(existing === undefined && {
|
|
889
|
+
maintainers: maintainers.map(({ login, id }) => ({ login, id })),
|
|
890
|
+
}),
|
|
450
891
|
...(existing !== undefined && { existing }),
|
|
892
|
+
...(connector && { higherThanApproved: true }),
|
|
893
|
+
...(existing === undefined && declaredKind && { kind: declaredKind }),
|
|
451
894
|
});
|
|
895
|
+
const written = parse(registration);
|
|
896
|
+
const writtenContact = isRecord(written)
|
|
897
|
+
? written.security_contact
|
|
898
|
+
: undefined;
|
|
452
899
|
const sent = new Set(files.map((file) => file.path));
|
|
453
900
|
const notSent = (paths) => paths.filter((path) => path !== REGISTRATION_FILE && !sent.has(path));
|
|
454
|
-
const deleted = notSent(
|
|
455
|
-
? []
|
|
456
|
-
: ((await github.folderPaths(index, baseSha, folder)) ?? []));
|
|
901
|
+
const deleted = notSent(basePaths);
|
|
457
902
|
const droppedFromPull = notSent(headSha === undefined
|
|
458
903
|
? []
|
|
459
904
|
: ((await github.folderPaths(index, headSha, folder)) ?? []));
|
|
@@ -473,6 +918,8 @@ async function prepare(options) {
|
|
|
473
918
|
const warnings = skipped.includes(REGISTRATION_FILE)
|
|
474
919
|
? await registrationFileCheck(options.projectDir, { id, packageId })
|
|
475
920
|
: [];
|
|
921
|
+
if (python)
|
|
922
|
+
warnings.push(PYTHON_SUBMIT_BLOCKED);
|
|
476
923
|
return {
|
|
477
924
|
index,
|
|
478
925
|
id,
|
|
@@ -489,6 +936,15 @@ async function prepare(options) {
|
|
|
489
936
|
checks: checks.report,
|
|
490
937
|
approvedBy: [],
|
|
491
938
|
warnings,
|
|
939
|
+
...(typeof writtenContact === "string" && {
|
|
940
|
+
securityContact: writtenContact,
|
|
941
|
+
}),
|
|
942
|
+
maintainers,
|
|
943
|
+
...(connectorKey !== undefined && { connectorKey, rewritten }),
|
|
944
|
+
...(signedIn &&
|
|
945
|
+
"reason" in signedIn && {
|
|
946
|
+
maintainersNote: `no maintainers were written, because ${withoutControls(signedIn.reason)}`,
|
|
947
|
+
}),
|
|
492
948
|
base,
|
|
493
949
|
baseSha,
|
|
494
950
|
head,
|
|
@@ -499,6 +955,8 @@ async function prepare(options) {
|
|
|
499
955
|
};
|
|
500
956
|
}
|
|
501
957
|
export async function submit(options) {
|
|
958
|
+
if (!options.dryRun && (await isPythonFunctionProject(options.projectDir)))
|
|
959
|
+
throw new SubmitError(PYTHON_SUBMIT_BLOCKED);
|
|
502
960
|
const { github } = options;
|
|
503
961
|
const { base, baseSha, head, body, changes, pull, parents, ...plan } = await prepare(options);
|
|
504
962
|
const { index, branch, title } = plan;
|
|
@@ -510,6 +968,9 @@ export async function submit(options) {
|
|
|
510
968
|
}
|
|
511
969
|
: plan;
|
|
512
970
|
}
|
|
971
|
+
const writeWarnings = plan.maintainersNote
|
|
972
|
+
? [...plan.warnings, plan.maintainersNote]
|
|
973
|
+
: [...plan.warnings];
|
|
513
974
|
if (!pull) {
|
|
514
975
|
await github.pushTree({
|
|
515
976
|
repo: index,
|
|
@@ -534,7 +995,7 @@ export async function submit(options) {
|
|
|
534
995
|
throw new SubmitError(`the branch ${branch} was pushed to ${index}, but opening the pull request failed: ${error.message}. GitHub may still have created the pull request. Check ${index} for an open pull request from ${branch}. If there is one, run submit again to update it. If there is none, delete the branch (gh api -X DELETE repos/${index}/git/refs/heads/${branch}), because submit refuses a branch that has no pull request, then run submit again.`, { cause: error });
|
|
535
996
|
}
|
|
536
997
|
const labelled = await github.addLabel(index, created.number, LABEL);
|
|
537
|
-
return { ...plan, url: created.url, labelled };
|
|
998
|
+
return { ...plan, warnings: writeWarnings, url: created.url, labelled };
|
|
538
999
|
}
|
|
539
1000
|
try {
|
|
540
1001
|
await github.pushTree({
|
|
@@ -553,7 +1014,7 @@ export async function submit(options) {
|
|
|
553
1014
|
}
|
|
554
1015
|
throw error;
|
|
555
1016
|
}
|
|
556
|
-
const warnings = [...
|
|
1017
|
+
const warnings = [...writeWarnings];
|
|
557
1018
|
const current = await github.pullBody(index, pull.number);
|
|
558
1019
|
const next = withVersionLine(current, plan.version);
|
|
559
1020
|
if (next === undefined) {
|