@uipath/uipath-extensions-sdk 0.1.22 → 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 +45 -8
- package/dist/adopt.d.ts +6 -0
- package/dist/adopt.js +459 -77
- package/dist/adopt.js.map +1 -1
- package/dist/cli.js +4 -2
- 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.js +9 -15
- 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 +15 -1
- package/dist/commands/submit.js +147 -35
- 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.js +14 -2
- package/dist/connector.js.map +1 -1
- package/dist/lib.d.ts +2 -1
- package/dist/lib.js +223 -21
- 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/sourceWalk.d.ts +2 -1
- package/dist/sourceWalk.js +5 -3
- package/dist/sourceWalk.js.map +1 -1
- package/dist/verdict.d.ts +6 -0
- package/dist/verdict.js +13 -0
- package/dist/verdict.js.map +1 -0
- package/package.json +3 -2
package/dist/commands/pack.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { lstat, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { defaultExec, loadTemplate, packageNameProblem, } from "@uipath/uipath-extensions-gates";
|
|
3
|
+
import { defaultExec, kindOfDir, loadTemplate, PYPROJECT, packageNameProblem, readTomlFile, UV_LOCK, } from "@uipath/uipath-extensions-gates";
|
|
4
4
|
import semver from "semver";
|
|
5
5
|
import { exists } from "../exists.js";
|
|
6
|
+
import { setProjectField } from "../pyproject.js";
|
|
7
|
+
import { isPythonFunctionProject } from "../python-source.js";
|
|
6
8
|
import { REGISTRATION_FILE } from "../registrationFile.js";
|
|
7
9
|
import { UipMissingError } from "../uip.js";
|
|
8
|
-
|
|
10
|
+
import { packPythonFunction } from "./validate-python.js";
|
|
11
|
+
export const PACK_TIMEOUT_MS = 600_000;
|
|
9
12
|
const NUPKG_DIRS = [".uipath", ""];
|
|
10
13
|
const MAX_OUTPUT_CHARS = 2000;
|
|
11
14
|
export class PackError extends Error {
|
|
@@ -16,13 +19,47 @@ export class PackError extends Error {
|
|
|
16
19
|
this.name = "PackError";
|
|
17
20
|
}
|
|
18
21
|
}
|
|
22
|
+
const PACK_COMMAND = {
|
|
23
|
+
function: "uip function pack",
|
|
24
|
+
agent: "uip codedagent pack",
|
|
25
|
+
};
|
|
26
|
+
export async function projectKind(projectDir) {
|
|
27
|
+
return (await kindOfDir(projectDir)) === "agent" &&
|
|
28
|
+
!(await isPythonFunctionProject(projectDir))
|
|
29
|
+
? "agent"
|
|
30
|
+
: "function";
|
|
31
|
+
}
|
|
19
32
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
33
|
function jsonLike(original, value) {
|
|
21
34
|
const indent = /^(\s+)"/m.exec(original)?.[1] ?? " ";
|
|
22
35
|
const newline = original.endsWith("\n") ? "\n" : "";
|
|
23
36
|
return `${JSON.stringify(value, null, indent)}${newline}`;
|
|
24
37
|
}
|
|
38
|
+
async function readAgentInfo(projectDir) {
|
|
39
|
+
const toml = await readTomlFile(join(projectDir, PYPROJECT));
|
|
40
|
+
if ("error" in toml)
|
|
41
|
+
throw new PackError(`${PYPROJECT}: ${toml.error}`);
|
|
42
|
+
const { project } = toml.value;
|
|
43
|
+
if (!isRecord(project)) {
|
|
44
|
+
throw new PackError(`${PYPROJECT} has no [project] table`);
|
|
45
|
+
}
|
|
46
|
+
const problem = packageNameProblem(project.name);
|
|
47
|
+
if (problem) {
|
|
48
|
+
throw new PackError(problem.replace(/^package\.json name/, `${PYPROJECT} [project].name`), true);
|
|
49
|
+
}
|
|
50
|
+
if (typeof project.version !== "string") {
|
|
51
|
+
throw new PackError(`${PYPROJECT} [project].version must be a string`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
name: project.name,
|
|
55
|
+
version: project.version,
|
|
56
|
+
kind: "agent",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
25
59
|
export async function readPackageInfo(projectDir) {
|
|
60
|
+
if ((await projectKind(projectDir)) === "agent") {
|
|
61
|
+
return readAgentInfo(projectDir);
|
|
62
|
+
}
|
|
26
63
|
const path = join(projectDir, "package.json");
|
|
27
64
|
let text;
|
|
28
65
|
try {
|
|
@@ -46,9 +83,13 @@ export async function readPackageInfo(projectDir) {
|
|
|
46
83
|
if (typeof parsed.version !== "string") {
|
|
47
84
|
throw new PackError("package.json version must be a string");
|
|
48
85
|
}
|
|
49
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
name: parsed.name,
|
|
88
|
+
version: parsed.version,
|
|
89
|
+
kind: "function",
|
|
90
|
+
};
|
|
50
91
|
}
|
|
51
|
-
function tail(text) {
|
|
92
|
+
export function tail(text) {
|
|
52
93
|
return text.length > MAX_OUTPUT_CHARS
|
|
53
94
|
? `...${text.slice(-MAX_OUTPUT_CHARS)}`
|
|
54
95
|
: text;
|
|
@@ -65,6 +106,25 @@ async function withPackageVersion(projectDir, version, run) {
|
|
|
65
106
|
await writeFile(path, original);
|
|
66
107
|
}
|
|
67
108
|
}
|
|
109
|
+
async function withProjectVersion(projectDir, version, run) {
|
|
110
|
+
const path = join(projectDir, PYPROJECT);
|
|
111
|
+
const lockPath = join(projectDir, UV_LOCK);
|
|
112
|
+
const original = await readFile(path, "utf8");
|
|
113
|
+
const lock = await readFile(lockPath, "utf8").catch(() => undefined);
|
|
114
|
+
const next = setProjectField(original, "version", version);
|
|
115
|
+
if (next === undefined) {
|
|
116
|
+
throw new PackError(`${PYPROJECT} has no [project] version line to set`);
|
|
117
|
+
}
|
|
118
|
+
await writeFile(path, next);
|
|
119
|
+
try {
|
|
120
|
+
return await run();
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
await writeFile(path, original);
|
|
124
|
+
if (lock !== undefined)
|
|
125
|
+
await writeFile(lockPath, lock);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
68
128
|
async function restoreUipathJson(path, original, temporary, added) {
|
|
69
129
|
let current;
|
|
70
130
|
try {
|
|
@@ -145,18 +205,11 @@ export async function withRegistrationExcluded(projectDir, run) {
|
|
|
145
205
|
});
|
|
146
206
|
}
|
|
147
207
|
}
|
|
148
|
-
export async function
|
|
149
|
-
const { projectDir } = options;
|
|
150
|
-
const
|
|
151
|
-
await loadTemplate(projectDir);
|
|
152
|
-
const { name: packageId, version: packageVersion } = await readPackageInfo(projectDir);
|
|
153
|
-
const version = options.version ?? packageVersion;
|
|
154
|
-
if (semver.valid(version) !== version) {
|
|
155
|
-
throw new PackError(`pack version ${JSON.stringify(version)} is not semver`);
|
|
156
|
-
}
|
|
157
|
-
const runPack = async () => {
|
|
208
|
+
export async function runUipPack(options) {
|
|
209
|
+
const { projectDir, exec, command, nupkgName } = options;
|
|
210
|
+
const run = async () => {
|
|
158
211
|
try {
|
|
159
|
-
return await exec("uip",
|
|
212
|
+
return await exec("uip", command.split(" ").slice(1), {
|
|
160
213
|
cwd: projectDir,
|
|
161
214
|
timeout: PACK_TIMEOUT_MS,
|
|
162
215
|
});
|
|
@@ -168,27 +221,40 @@ export async function pack(options) {
|
|
|
168
221
|
throw error;
|
|
169
222
|
}
|
|
170
223
|
};
|
|
171
|
-
const
|
|
172
|
-
const result = version === packageVersion
|
|
173
|
-
? await runExcludingRegistration()
|
|
174
|
-
: await withPackageVersion(projectDir, version, runExcludingRegistration);
|
|
224
|
+
const result = await withRegistrationExcluded(projectDir, run);
|
|
175
225
|
if (result.timedOut)
|
|
176
|
-
throw new PackError(
|
|
226
|
+
throw new PackError(`${command} timed out`);
|
|
177
227
|
if (result.code !== 0) {
|
|
178
|
-
throw new PackError(
|
|
228
|
+
throw new PackError(`${command} exited with code ${result.code}: ${tail(result.stderr || result.stdout)}`);
|
|
179
229
|
}
|
|
180
|
-
const nupkgName = `${packageId}.${version}.nupkg`;
|
|
181
|
-
let nupkgPath;
|
|
182
230
|
for (const dir of NUPKG_DIRS) {
|
|
183
231
|
const candidate = join(projectDir, dir, nupkgName);
|
|
184
|
-
if (await exists(candidate))
|
|
185
|
-
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
232
|
+
if (await exists(candidate))
|
|
233
|
+
return candidate;
|
|
188
234
|
}
|
|
189
|
-
|
|
190
|
-
|
|
235
|
+
throw new PackError(`${command} finished but ${nupkgName} was not created in the project or in .uipath`);
|
|
236
|
+
}
|
|
237
|
+
export async function pack(options) {
|
|
238
|
+
const { projectDir } = options;
|
|
239
|
+
if (await isPythonFunctionProject(projectDir))
|
|
240
|
+
return packPythonFunction(options);
|
|
241
|
+
const exec = options.exec ?? defaultExec;
|
|
242
|
+
await loadTemplate(projectDir);
|
|
243
|
+
const { name: packageId, version: packageVersion, kind, } = await readPackageInfo(projectDir);
|
|
244
|
+
const command = PACK_COMMAND[kind];
|
|
245
|
+
const version = options.version ?? packageVersion;
|
|
246
|
+
if (semver.valid(version) !== version) {
|
|
247
|
+
throw new PackError(`pack version ${JSON.stringify(version)} is not semver`);
|
|
191
248
|
}
|
|
192
|
-
|
|
249
|
+
const packOnce = () => runUipPack({
|
|
250
|
+
projectDir,
|
|
251
|
+
exec,
|
|
252
|
+
command,
|
|
253
|
+
nupkgName: `${packageId}.${version}.nupkg`,
|
|
254
|
+
});
|
|
255
|
+
const nupkgPath = version === packageVersion
|
|
256
|
+
? await packOnce()
|
|
257
|
+
: await (kind === "agent" ? withProjectVersion : withPackageVersion)(projectDir, version, packOnce);
|
|
258
|
+
return { version, nupkgPath, packageId, kind };
|
|
193
259
|
}
|
|
194
260
|
//# sourceMappingURL=pack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.js","sourceRoot":"","sources":["../../src/commands/pack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,WAAW,EAEX,YAAY,EACZ,kBAAkB,
|
|
1
|
+
{"version":3,"file":"pack.js","sourceRoot":"","sources":["../../src/commands/pack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,WAAW,EAEX,SAAS,EACT,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,OAAO,GACR,MAAM,iCAAiC,CAAC;AACzC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AACvC,MAAM,UA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I,GACL,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,cAAc,CAAC;IAClD,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,EAAE,CAAC;QACtC,MAAM,IAAI,SAAS,CACjB,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,gBAAgB,CACxD,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,EAAE,CACpB,UAAU,CAAC;QACT,UAAU;QACV,IAAI;QACJ,OAAO;QACP,SAAS,EAAE,GAAG,SAAS,IAAI,OAAO,QAAQ;KAC3C,CAAC,CAAC;IACL,MAAM,SAAS,GACb,OAAO,KAAK,cAAc;QACxB,CAAC,CAAC,MAAM,QAAQ,EAAE;QAClB,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAChE,UAAU,EACV,OAAO,EACP,QAAQ,CACT,CAAC;IACR,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Exec, type GateReport } from "@uipath/uipath-extensions-gates";
|
|
2
|
-
import { type GitHubClient, type PullReview } from "../github.js";
|
|
2
|
+
import { type GitHubClient, type PullInfo, type PullReview, type TreeChange } from "../github.js";
|
|
3
3
|
import { type Maintainer } from "../registrationFile.js";
|
|
4
4
|
import { type ValidateOptions, type ValidateResult } from "./validate.js";
|
|
5
5
|
export declare const DEFAULT_INDEX_REPO = "UiPath/uipath-extensions";
|
|
6
|
+
export declare const PYTHON_SUBMIT_BLOCKED = "Python functions can be checked with submit --dry-run, but the registry does not yet support publishing them";
|
|
6
7
|
export declare class SubmitError extends Error {
|
|
7
8
|
constructor(message: string, options?: ErrorOptions);
|
|
8
9
|
}
|
|
@@ -94,6 +95,7 @@ export declare function registrationText(input: {
|
|
|
94
95
|
maintainers?: Maintainer[];
|
|
95
96
|
existing?: string;
|
|
96
97
|
higherThanApproved?: boolean;
|
|
98
|
+
kind?: "function" | "agent";
|
|
97
99
|
}): string;
|
|
98
100
|
export declare function fillTemplate(template: string, fields: {
|
|
99
101
|
id: string;
|
|
@@ -102,6 +104,18 @@ export declare function fillTemplate(template: string, fields: {
|
|
|
102
104
|
}): string;
|
|
103
105
|
export declare function approvers(reviews: PullReview[]): string[];
|
|
104
106
|
export declare function withVersionLine(body: string, version: string): string | undefined;
|
|
107
|
+
interface Prepared extends SubmitPlan {
|
|
108
|
+
base: string;
|
|
109
|
+
baseSha: string;
|
|
110
|
+
head: string;
|
|
111
|
+
body: string;
|
|
112
|
+
changes: TreeChange[];
|
|
113
|
+
pull?: PullInfo;
|
|
114
|
+
parents?: string[];
|
|
115
|
+
}
|
|
116
|
+
export declare function prepare(options: SubmitOptions & {
|
|
117
|
+
dryRun?: boolean;
|
|
118
|
+
}): Promise<Prepared>;
|
|
105
119
|
export declare function submit(options: SubmitOptions & {
|
|
106
120
|
dryRun: true;
|
|
107
121
|
}): Promise<SubmitPlan>;
|
package/dist/commands/submit.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { lstat, mkdir, mkdtemp, readFile, rm, writeFile, } from "node:fs/promises";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
import {
|
|
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
5
|
import semver from "semver";
|
|
6
6
|
import { parse, stringify } from "yaml";
|
|
7
|
+
import { isPythonFunctionProject } from "../adopt.js";
|
|
7
8
|
import { connectorPackageId, validateConnector, withConnectorKey, withConnectorVersion, } from "../connector.js";
|
|
8
9
|
import { GitHubError, HeadMovedError, } from "../github.js";
|
|
9
10
|
import { SDK_PACKAGE } from "../manifest.js";
|
|
11
|
+
import { pythonFunctions, readDeclaredKind, readPythonFunctionSource, suggestedKind, } from "../python-source.js";
|
|
10
12
|
import { EMAIL, isMaintainerLogin, maintainerProblems, REGISTRATION_FILE, registrationFileCheck, withoutControls, } from "../registrationFile.js";
|
|
11
13
|
import { excludedNames, isSkippedEntry, offListRemedy, walkSources, } from "../sourceWalk.js";
|
|
14
|
+
import { PackError, projectKind, readPackageInfo } from "./pack.js";
|
|
12
15
|
import { validate as runValidate, } from "./validate.js";
|
|
16
|
+
import { validatePythonFunction } from "./validate-python.js";
|
|
13
17
|
export const DEFAULT_INDEX_REPO = "UiPath/uipath-extensions";
|
|
14
18
|
const TEMPLATE_PATH = ".github/PULL_REQUEST_TEMPLATE.md";
|
|
15
19
|
const REPO = /^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/;
|
|
16
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";
|
|
17
22
|
const MAX_FILES = 200;
|
|
18
23
|
const MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
19
24
|
const MAX_TOTAL_BYTES = 20 * 1024 * 1024;
|
|
@@ -21,6 +26,7 @@ const MAX_REPORTED_PROBLEMS = 10;
|
|
|
21
26
|
const READ_ON_PROBLEMS = new Set([
|
|
22
27
|
MANIFEST_FILE,
|
|
23
28
|
"package.json",
|
|
29
|
+
"pyproject.toml",
|
|
24
30
|
"project.uiproj",
|
|
25
31
|
]);
|
|
26
32
|
const OLD_LAYOUT = "src/ is the old node layout; put functions in functions/ and node.ts in maestro/";
|
|
@@ -100,25 +106,26 @@ export async function collectFolder(root) {
|
|
|
100
106
|
const problems = [];
|
|
101
107
|
const skipped = [];
|
|
102
108
|
const found = [];
|
|
109
|
+
const kind = await projectKind(root);
|
|
103
110
|
const excluded = excludedNames(await readUipathJson(root));
|
|
104
111
|
await walkSources(root, async (entry, path, dir) => {
|
|
105
|
-
if (dir === "" && isLocalOnlySource(entry.name)) {
|
|
112
|
+
if (dir === "" && isLocalOnlySource(entry.name, kind)) {
|
|
106
113
|
skipped.push(entry.isDirectory() ? `${path}/` : path);
|
|
107
114
|
}
|
|
108
115
|
else if (dir === "" && entry.isFile() && path === REGISTRATION_FILE) {
|
|
109
116
|
skipped.push(path);
|
|
110
117
|
}
|
|
111
|
-
else if (isSkippedEntry(entry, dir, excluded)) {
|
|
118
|
+
else if (isSkippedEntry(entry, dir, excluded, kind)) {
|
|
112
119
|
return false;
|
|
113
120
|
}
|
|
114
121
|
else if (entry.isSymbolicLink()) {
|
|
115
122
|
problems.push(`${path} is a symlink`);
|
|
116
123
|
}
|
|
117
124
|
else if (entry.isDirectory()) {
|
|
118
|
-
if (dir === "" && entry.name === "src") {
|
|
125
|
+
if (kind === "function" && dir === "" && entry.name === "src") {
|
|
119
126
|
problems.push(OLD_LAYOUT);
|
|
120
127
|
}
|
|
121
|
-
else if (dir === "" && !isAllowedSourceDir(entry.name)) {
|
|
128
|
+
else if (dir === "" && !isAllowedSourceDir(entry.name, kind)) {
|
|
122
129
|
problems.push(`${path}/ is not on the allow list, ${offListRemedy(`${path}/`)}`);
|
|
123
130
|
}
|
|
124
131
|
else {
|
|
@@ -128,7 +135,7 @@ export async function collectFolder(root) {
|
|
|
128
135
|
else if (!entry.isFile()) {
|
|
129
136
|
problems.push(`${path} is not a regular file`);
|
|
130
137
|
}
|
|
131
|
-
else if (!isAllowedSourcePath(path)) {
|
|
138
|
+
else if (!isAllowedSourcePath(path, kind)) {
|
|
132
139
|
problems.push(`${path} is not on the allow list, ${offListRemedy(path)}`);
|
|
133
140
|
}
|
|
134
141
|
else {
|
|
@@ -143,6 +150,9 @@ export async function collectFolder(root) {
|
|
|
143
150
|
if (found.length + 1 > MAX_FILES) {
|
|
144
151
|
problems.push(`the folder holds ${found.length} files, and the limit is ${MAX_FILES} with ${REGISTRATION_FILE}`);
|
|
145
152
|
}
|
|
153
|
+
const assets = assetsProblem(found.map((file) => file.path));
|
|
154
|
+
if (assets !== undefined)
|
|
155
|
+
problems.push(assets);
|
|
146
156
|
const total = found.reduce((sum, file) => sum + file.size, 0);
|
|
147
157
|
if (total > MAX_TOTAL_BYTES) {
|
|
148
158
|
problems.push(`the files add up to ${mebibytes(total)}, over the ${mebibytes(MAX_TOTAL_BYTES)} limit for one pull request`);
|
|
@@ -171,15 +181,15 @@ const CONNECTOR_SKIPPED = [
|
|
|
171
181
|
"app/package.json",
|
|
172
182
|
"node_modules",
|
|
173
183
|
];
|
|
174
|
-
// The gates run on the same bytes that submit
|
|
175
|
-
async function
|
|
176
|
-
const snapshot = await mkdtemp(join(tmpdir(), "
|
|
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-"));
|
|
177
187
|
try {
|
|
178
188
|
for (const file of files) {
|
|
179
189
|
await mkdir(dirname(join(snapshot, file.path)), { recursive: true });
|
|
180
|
-
await writeFile(join(snapshot, file.path), file.content);
|
|
190
|
+
await writeFile(join(snapshot, file.path), file.content, { flag: "wx" });
|
|
181
191
|
}
|
|
182
|
-
return await
|
|
192
|
+
return await validate(snapshot);
|
|
183
193
|
}
|
|
184
194
|
finally {
|
|
185
195
|
await rm(snapshot, { recursive: true, force: true });
|
|
@@ -252,14 +262,38 @@ function withFolderProblems(checked, problems) {
|
|
|
252
262
|
];
|
|
253
263
|
return { report: { ...checked.report, results }, ok: false };
|
|
254
264
|
}
|
|
255
|
-
function
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
}
|
|
263
297
|
}
|
|
264
298
|
async function collectConnectorFolder(root) {
|
|
265
299
|
const { files, problems } = await readConnectorFiles(root);
|
|
@@ -377,6 +411,28 @@ function readPackageJson(files) {
|
|
|
377
411
|
throw new SubmitError(problem);
|
|
378
412
|
return { packageId: declared.name, version: declared.version };
|
|
379
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
|
+
}
|
|
380
436
|
export function registrationText(input) {
|
|
381
437
|
const { id, packageId, version, date, securityContact, existing } = input;
|
|
382
438
|
const entry = {
|
|
@@ -391,6 +447,7 @@ export function registrationText(input) {
|
|
|
391
447
|
id,
|
|
392
448
|
package: packageId,
|
|
393
449
|
security_contact: securityContact,
|
|
450
|
+
...(input.kind && { kind: input.kind }),
|
|
394
451
|
deprecated: null,
|
|
395
452
|
approved: [entry],
|
|
396
453
|
...(input.maintainers &&
|
|
@@ -586,7 +643,7 @@ async function forkProblems(github, index, target, baseSha) {
|
|
|
586
643
|
}
|
|
587
644
|
const kind = registered === undefined
|
|
588
645
|
? undefined
|
|
589
|
-
:
|
|
646
|
+
: kindOfPaths((await github.folderPaths(index, baseSha, shared)) ?? []);
|
|
590
647
|
if (kind === "connector")
|
|
591
648
|
return [];
|
|
592
649
|
const held = kind === undefined
|
|
@@ -601,7 +658,7 @@ function githubFailure(error) {
|
|
|
601
658
|
throw error;
|
|
602
659
|
return error.message;
|
|
603
660
|
}
|
|
604
|
-
async function prepare(options) {
|
|
661
|
+
export async function prepare(options) {
|
|
605
662
|
const { github, securityContact } = options;
|
|
606
663
|
const index = options.index ?? DEFAULT_INDEX_REPO;
|
|
607
664
|
checkInputs(index, securityContact);
|
|
@@ -615,9 +672,34 @@ async function prepare(options) {
|
|
|
615
672
|
else {
|
|
616
673
|
await loadTemplate(options.projectDir);
|
|
617
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);
|
|
618
691
|
const collected = connector
|
|
619
692
|
? await collectConnectorFolder(options.projectDir)
|
|
620
|
-
:
|
|
693
|
+
: python
|
|
694
|
+
? {
|
|
695
|
+
files: [...python.files].map(([path, content]) => ({
|
|
696
|
+
path,
|
|
697
|
+
content,
|
|
698
|
+
})),
|
|
699
|
+
skipped: [],
|
|
700
|
+
problems: [],
|
|
701
|
+
}
|
|
702
|
+
: undefined;
|
|
621
703
|
const failures = [];
|
|
622
704
|
let indexInfo;
|
|
623
705
|
try {
|
|
@@ -634,12 +716,21 @@ async function prepare(options) {
|
|
|
634
716
|
}
|
|
635
717
|
const { files: folderFiles, skipped, problems, } = collected ?? (await collectFolder(options.projectDir));
|
|
636
718
|
let files = folderFiles;
|
|
637
|
-
|
|
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
|
+
: []));
|
|
638
725
|
let target;
|
|
639
726
|
try {
|
|
640
727
|
target = nodeTarget(connector
|
|
641
728
|
? connectorIdentity(files, options.connectorId)
|
|
642
|
-
:
|
|
729
|
+
: python
|
|
730
|
+
? { packageId: python.name, version: python.version }
|
|
731
|
+
: agent
|
|
732
|
+
? await agentIdentity(options.projectDir)
|
|
733
|
+
: readPackageJson(files), index);
|
|
643
734
|
}
|
|
644
735
|
catch (error) {
|
|
645
736
|
if (!(error instanceof SubmitError))
|
|
@@ -666,7 +757,7 @@ async function prepare(options) {
|
|
|
666
757
|
}
|
|
667
758
|
let connectorKey;
|
|
668
759
|
const context = {};
|
|
669
|
-
if (
|
|
760
|
+
if (connector && target) {
|
|
670
761
|
try {
|
|
671
762
|
const keyed = withConnectorKey(files, target.id);
|
|
672
763
|
files = keyed.files;
|
|
@@ -679,7 +770,7 @@ async function prepare(options) {
|
|
|
679
770
|
failures.push(error.message);
|
|
680
771
|
}
|
|
681
772
|
}
|
|
682
|
-
if (
|
|
773
|
+
if (connector && indexInfo && target && remote) {
|
|
683
774
|
try {
|
|
684
775
|
const registered = (await github.fileText(index, target.registrationPath, remote.baseSha)) ?? (await github.fileText(index, target.flatPath, remote.baseSha));
|
|
685
776
|
const previous = approvedVersions(registered);
|
|
@@ -699,7 +790,7 @@ async function prepare(options) {
|
|
|
699
790
|
}
|
|
700
791
|
}
|
|
701
792
|
}
|
|
702
|
-
const rewritten =
|
|
793
|
+
const rewritten = connector
|
|
703
794
|
? files.flatMap((file, at) => {
|
|
704
795
|
const before = folderFiles[at]?.content;
|
|
705
796
|
return before !== undefined &&
|
|
@@ -708,12 +799,14 @@ async function prepare(options) {
|
|
|
708
799
|
: [file.path];
|
|
709
800
|
})
|
|
710
801
|
: [];
|
|
711
|
-
const checks =
|
|
712
|
-
? await
|
|
713
|
-
:
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
+
});
|
|
717
810
|
if (!checks.ok || failures.length > 0 || !indexInfo || !target || !remote) {
|
|
718
811
|
throw checks.ok
|
|
719
812
|
? new PrepareFailedError(failures)
|
|
@@ -732,8 +825,22 @@ async function prepare(options) {
|
|
|
732
825
|
const basePaths = current === undefined
|
|
733
826
|
? []
|
|
734
827
|
: ((await github.folderPaths(index, baseSha, folder)) ?? []);
|
|
735
|
-
const
|
|
736
|
-
|
|
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.`);
|
|
737
844
|
if (existing !== undefined &&
|
|
738
845
|
sentKind === "connector" &&
|
|
739
846
|
baseKind !== "connector") {
|
|
@@ -783,6 +890,7 @@ async function prepare(options) {
|
|
|
783
890
|
}),
|
|
784
891
|
...(existing !== undefined && { existing }),
|
|
785
892
|
...(connector && { higherThanApproved: true }),
|
|
893
|
+
...(existing === undefined && declaredKind && { kind: declaredKind }),
|
|
786
894
|
});
|
|
787
895
|
const written = parse(registration);
|
|
788
896
|
const writtenContact = isRecord(written)
|
|
@@ -810,6 +918,8 @@ async function prepare(options) {
|
|
|
810
918
|
const warnings = skipped.includes(REGISTRATION_FILE)
|
|
811
919
|
? await registrationFileCheck(options.projectDir, { id, packageId })
|
|
812
920
|
: [];
|
|
921
|
+
if (python)
|
|
922
|
+
warnings.push(PYTHON_SUBMIT_BLOCKED);
|
|
813
923
|
return {
|
|
814
924
|
index,
|
|
815
925
|
id,
|
|
@@ -845,6 +955,8 @@ async function prepare(options) {
|
|
|
845
955
|
};
|
|
846
956
|
}
|
|
847
957
|
export async function submit(options) {
|
|
958
|
+
if (!options.dryRun && (await isPythonFunctionProject(options.projectDir)))
|
|
959
|
+
throw new SubmitError(PYTHON_SUBMIT_BLOCKED);
|
|
848
960
|
const { github } = options;
|
|
849
961
|
const { base, baseSha, head, body, changes, pull, parents, ...plan } = await prepare(options);
|
|
850
962
|
const { index, branch, title } = plan;
|