@uipath/solution-tool
Advanced tools
Sorry, the diff of this file is too big to display
| import { | ||
| Configuration, | ||
| Configuration1 as Configuration2, | ||
| PackagesApi, | ||
| PipelinesApi, | ||
| resolveFeedScope | ||
| } from "./packager-tool-vdajdv03.js"; | ||
| import { | ||
| PollOutcome, | ||
| catchError, | ||
| extractErrorDetails, | ||
| getSolutionAuthContext, | ||
| logger, | ||
| mapPollFailure, | ||
| pollUntil | ||
| } from "./packager-tool-y4wacqkp.js"; | ||
| import { | ||
| getFileSystem | ||
| } from "./packager-tool-q90kqh83.js"; | ||
| import { | ||
| strFromU8, | ||
| strToU8, | ||
| unzipSync, | ||
| zipSync | ||
| } from "./packager-tool-129wn232.js"; | ||
| // src/services/package-metadata-rewrite.ts | ||
| import { randomUUID } from "node:crypto"; | ||
| var SOLUTION_METADATA_ENTRY = "solutionMetadata.json"; | ||
| function isRecord(value) { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
| var requireValue = (value, flag) => { | ||
| const trimmed = value.trim(); | ||
| if (!trimmed) { | ||
| throw new Error(`${flag} cannot be empty.`); | ||
| } | ||
| return trimmed; | ||
| }; | ||
| function rewritePackageMetadata(archive, overrides) { | ||
| const entries = unzipSync(archive); | ||
| const metadataBytes = entries[SOLUTION_METADATA_ENTRY]; | ||
| if (!metadataBytes) { | ||
| throw new Error(`Package archive has no ${SOLUTION_METADATA_ENTRY} at its root, so its name and version cannot be rewritten. Only a .zip produced by 'uip solution pack' carries that file.`); | ||
| } | ||
| let parsed; | ||
| try { | ||
| parsed = JSON.parse(strFromU8(metadataBytes)); | ||
| } catch (err) { | ||
| throw new Error(`${SOLUTION_METADATA_ENTRY} in the package archive is not valid JSON: ${err instanceof Error ? err.message : String(err)}`); | ||
| } | ||
| if (!isRecord(parsed) || !isRecord(parsed.spec)) { | ||
| throw new Error(`${SOLUTION_METADATA_ENTRY} in the package archive has no 'spec' object, so its name and version cannot be rewritten.`); | ||
| } | ||
| const spec = parsed.spec; | ||
| const packageName = overrides.packageName === undefined ? String(spec.packageName ?? "") : requireValue(overrides.packageName, "--package-name"); | ||
| const packageVersion = overrides.packageVersion === undefined ? String(spec.packageVersion ?? "") : requireValue(overrides.packageVersion, "--package-version"); | ||
| const packageVersionKey = randomUUID(); | ||
| const rewritten = { | ||
| ...parsed, | ||
| spec: { ...spec, packageName, packageVersion, packageVersionKey } | ||
| }; | ||
| const zipInput = {}; | ||
| for (const [entryName, entryBytes] of Object.entries(entries)) { | ||
| const level = entryName.toLowerCase().endsWith(".nupkg") ? 0 : 6; | ||
| zipInput[entryName] = [entryBytes, { level }]; | ||
| } | ||
| zipInput[SOLUTION_METADATA_ENTRY] = [ | ||
| strToU8(JSON.stringify(rewritten)), | ||
| { level: 6 } | ||
| ]; | ||
| return { | ||
| archive: zipSync(zipInput), | ||
| packageName, | ||
| packageVersion, | ||
| packageVersionKey | ||
| }; | ||
| } | ||
| // src/services/publish-service.ts | ||
| var TERMINAL_STATES = new Set([ | ||
| "Ready", | ||
| "Active", | ||
| "Failed" | ||
| ]); | ||
| var VERSION_CONFLICT_PATTERNS = [ | ||
| /\balready exists\b/i, | ||
| /\bduplicate\b.*\bversion\b/i, | ||
| /\bversion\b.*\bduplicate\b/i, | ||
| /\bpackage[-\s]?version\b.*\bexists\b/i, | ||
| /\bversion[-\s]?exists\b/i, | ||
| /\bversion\b.*\balready exists\b/i | ||
| ]; | ||
| var isVersionConflictError = (message, details) => { | ||
| const errorText = `${message} ${details ?? ""}`; | ||
| return VERSION_CONFLICT_PATTERNS.some((pattern) => pattern.test(errorText)); | ||
| }; | ||
| async function publishSolutionAsync(packagePath, options = {}) { | ||
| const [authError, auth] = await catchError(getSolutionAuthContext({ | ||
| tenant: options.tenant, | ||
| loginValidity: options.loginValidity, | ||
| envFilePath: options.envFilePath | ||
| })); | ||
| if (authError) { | ||
| return { | ||
| ok: false, | ||
| reason: "auth_failed", | ||
| message: authError.message | ||
| }; | ||
| } | ||
| const fs = getFileSystem(); | ||
| const resolvedPath = fs.path.resolve(packagePath); | ||
| if (!await fs.exists(resolvedPath)) { | ||
| return { | ||
| ok: false, | ||
| reason: "file_not_found", | ||
| message: `File not found: ${resolvedPath}` | ||
| }; | ||
| } | ||
| if (!resolvedPath.endsWith(".zip")) { | ||
| const stats = await fs.stat(resolvedPath); | ||
| const isSolutionSource = stats?.isDirectory() === true || resolvedPath.endsWith(".uis") || resolvedPath.endsWith(".uipx"); | ||
| if (isSolutionSource) { | ||
| return { | ||
| ok: false, | ||
| reason: "not_packed", | ||
| message: `'${packagePath}' is a solution source, not a packed package. 'publish' uploads the .zip produced by 'solution pack'.`, | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| return { | ||
| ok: false, | ||
| reason: "not_a_zip", | ||
| message: `Invalid file type. Expected a .zip file, got: ${resolvedPath}` | ||
| }; | ||
| } | ||
| const [fileBufferError, readBuffer] = await catchError(fs.readFile(resolvedPath)); | ||
| if (fileBufferError) { | ||
| const { message } = await extractErrorDetails(fileBufferError); | ||
| return { | ||
| ok: false, | ||
| reason: "file_read_failed", | ||
| message, | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| if (!readBuffer) { | ||
| return { | ||
| ok: false, | ||
| reason: "file_read_failed", | ||
| message: `File is empty or unreadable: ${resolvedPath}`, | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| let fileBuffer = readBuffer; | ||
| if (options.packageName !== undefined || options.packageVersion !== undefined) { | ||
| const [rewriteError, rewritten] = await catchError(Promise.resolve().then(() => rewritePackageMetadata(new Uint8Array(fileBuffer), { | ||
| packageName: options.packageName, | ||
| packageVersion: options.packageVersion | ||
| }))); | ||
| if (rewriteError || !rewritten) { | ||
| return { | ||
| ok: false, | ||
| reason: "metadata_rewrite_failed", | ||
| message: rewriteError?.message ?? "Could not rewrite the package name/version.", | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| logger.info(`Publishing ${resolvedPath} as ${rewritten.packageName} ${rewritten.packageVersion} (package version key ${rewritten.packageVersionKey}); the file on disk is unchanged.`); | ||
| fileBuffer = rewritten.archive; | ||
| } | ||
| const [scopeError, scope] = await catchError(resolveFeedScope({ | ||
| personalWorkspace: options.personalWorkspace, | ||
| feed: options.feed, | ||
| tenant: options.tenant, | ||
| loginValidity: options.loginValidity, | ||
| envFilePath: options.envFilePath | ||
| })); | ||
| if (scopeError) { | ||
| return { | ||
| ok: false, | ||
| reason: options.feed !== undefined ? "feed_resolution_failed" : "personal_workspace_resolution_failed", | ||
| message: scopeError.message | ||
| }; | ||
| } | ||
| if (scope.kind !== "tenant") { | ||
| return publishToFeed(auth, fileBuffer, scope, options); | ||
| } | ||
| const configuration = new Configuration({ | ||
| basePath: auth.basePath, | ||
| accessToken: auth.accessToken | ||
| }); | ||
| const api = new PipelinesApi(configuration); | ||
| const [uploadError, uploadResult] = await catchError(api.pipelinesPackageUpload({ body: fileBuffer })); | ||
| if (uploadError) { | ||
| return mapUploadError(uploadError); | ||
| } | ||
| let packageVersionInfo = uploadResult; | ||
| if (options.wait) { | ||
| const pollResult = await pollUntil({ | ||
| fn: () => api.pipelinesGetPackageVersion({ | ||
| packageName: uploadResult.packageName, | ||
| packageVersion: uploadResult.packageVersion | ||
| }), | ||
| until: (result) => TERMINAL_STATES.has(result.state), | ||
| getStatus: (result) => result.state, | ||
| label: `publish ${uploadResult.packageName}:${uploadResult.packageVersion}`, | ||
| logPrefix: "publish", | ||
| timeoutMs: (options.timeout ?? 360) * 1000, | ||
| intervalMs: options.pollInterval ?? 5000, | ||
| signal: options.signal | ||
| }); | ||
| if (pollResult.outcome !== PollOutcome.Completed) { | ||
| const { reason, message } = mapPollFailure(pollResult, "Package publish"); | ||
| return { ok: false, reason, message }; | ||
| } | ||
| if (!pollResult.data) { | ||
| return { | ||
| ok: false, | ||
| reason: "poll_failed", | ||
| message: "Package publish did not return a final state." | ||
| }; | ||
| } | ||
| packageVersionInfo = pollResult.data; | ||
| if (packageVersionInfo.state === "Failed") { | ||
| return { | ||
| ok: false, | ||
| reason: "publish_failed", | ||
| message: `Package publish failed with state: ${packageVersionInfo.state}` | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| ok: true, | ||
| packageVersionKey: packageVersionInfo.key, | ||
| packageName: packageVersionInfo.packageName, | ||
| packageVersion: packageVersionInfo.packageVersion, | ||
| state: packageVersionInfo.state, | ||
| feedKind: "tenant" | ||
| }; | ||
| } | ||
| async function publishToFeed(auth, fileBuffer, scope, options) { | ||
| const config = new Configuration2({ | ||
| basePath: auth.basePath, | ||
| accessToken: auth.accessToken | ||
| }); | ||
| const api = new PackagesApi(config); | ||
| const [uploadError, packageVersionKey] = await catchError(api.packagesUpload({ | ||
| body: fileBuffer, | ||
| locationKey: scope.folderKey | ||
| })); | ||
| if (uploadError) { | ||
| return mapUploadError(uploadError); | ||
| } | ||
| const [getError, initialInfo] = await catchError(api.packagesGetVersion({ packageVersionKey })); | ||
| if (getError) { | ||
| logger.warn(`Package uploaded (key ${packageVersionKey}) but its metadata was not yet retrievable; PackageName/PackageVersion/State will be absent from output: ${getError.message}`); | ||
| } | ||
| let packageVersionInfo = getError ? undefined : initialInfo; | ||
| if (options.wait) { | ||
| const pollResult = await pollUntil({ | ||
| fn: () => api.packagesGetVersion({ packageVersionKey }), | ||
| until: (result) => TERMINAL_STATES.has(result.state), | ||
| getStatus: (result) => result.state, | ||
| label: `publish ${packageVersionInfo ? `${packageVersionInfo.packageName}:${packageVersionInfo.packageVersion}` : packageVersionKey}`, | ||
| logPrefix: "publish", | ||
| timeoutMs: (options.timeout ?? 360) * 1000, | ||
| intervalMs: options.pollInterval ?? 5000, | ||
| signal: options.signal | ||
| }); | ||
| if (pollResult.outcome !== PollOutcome.Completed) { | ||
| const { reason, message } = mapPollFailure(pollResult, "Package publish"); | ||
| return { ok: false, reason, message }; | ||
| } | ||
| if (!pollResult.data) { | ||
| return { | ||
| ok: false, | ||
| reason: "poll_failed", | ||
| message: "Package publish did not return a final state." | ||
| }; | ||
| } | ||
| packageVersionInfo = pollResult.data; | ||
| if (packageVersionInfo.state === "Failed") { | ||
| return { | ||
| ok: false, | ||
| reason: "publish_failed", | ||
| message: `Package publish failed with state: ${packageVersionInfo.state}` | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| ok: true, | ||
| packageVersionKey: packageVersionInfo?.key ?? packageVersionKey, | ||
| packageName: packageVersionInfo?.packageName, | ||
| packageVersion: packageVersionInfo?.packageVersion, | ||
| state: packageVersionInfo?.state, | ||
| feedKind: scope.kind | ||
| }; | ||
| } | ||
| async function mapUploadError(uploadError) { | ||
| const { message, details, context, retry } = await extractErrorDetails(uploadError); | ||
| const fetchCause = uploadError instanceof Error && uploadError.name === "FetchError" && uploadError.cause instanceof Error ? uploadError.cause : null; | ||
| const surfacedMessage = fetchCause ? `Failed to upload package: ${fetchCause.message}` : message; | ||
| const httpStatus = context?.httpStatus; | ||
| let reason = "upload_failed"; | ||
| if (isVersionConflictError(message, details)) { | ||
| reason = "upload_version_conflict"; | ||
| } else if (fetchCause || httpStatus !== undefined && httpStatus >= 500) { | ||
| reason = "upload_network"; | ||
| } else if (httpStatus === 400 || httpStatus === 422) { | ||
| reason = "upload_rejected"; | ||
| } | ||
| return { | ||
| ok: false, | ||
| reason, | ||
| message: surfacedMessage, | ||
| details, | ||
| errorCode: context?.errorCode, | ||
| retry, | ||
| context | ||
| }; | ||
| } | ||
| export { publishSolutionAsync }; | ||
| //# debugId=696E04915672C64A64756E2164756E21 |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
+2
-2
@@ -7,4 +7,4 @@ import { | ||
| uninstallDeploymentAsync | ||
| } from "./packager-tool-dmdgqh56.js"; | ||
| import"./packager-tool-9j8d0ts5.js"; | ||
| } from "./packager-tool-s9phcc1z.js"; | ||
| import"./packager-tool-vdajdv03.js"; | ||
| import"./packager-tool-y4wacqkp.js"; | ||
@@ -11,0 +11,0 @@ import"./packager-tool-9qecd4wb.js"; |
+5
-5
@@ -5,9 +5,9 @@ #!/usr/bin/env bun | ||
| registerCommands | ||
| } from "./packager-tool-v3bmxrve.js"; | ||
| import"./packager-tool-dmdgqh56.js"; | ||
| } from "./packager-tool-nek785e1.js"; | ||
| import"./packager-tool-s9phcc1z.js"; | ||
| import"./packager-tool-kfzzznjr.js"; | ||
| import"./packager-tool-epwm26av.js"; | ||
| import"./packager-tool-t6cck14z.js"; | ||
| import"./packager-tool-sdhdmkt8.js"; | ||
| import"./packager-tool-r1hk3s30.js"; | ||
| import"./packager-tool-9j8d0ts5.js"; | ||
| import"./packager-tool-ry2wtgx7.js"; | ||
| import"./packager-tool-vdajdv03.js"; | ||
| import"./packager-tool-37g19zk3.js"; | ||
@@ -14,0 +14,0 @@ import"./packager-tool-vpr77gre.js"; |
+1
-1
| import { | ||
| PackCommandService | ||
| } from "./packager-tool-epwm26av.js"; | ||
| } from "./packager-tool-t6cck14z.js"; | ||
| import"./packager-tool-sdhdmkt8.js"; | ||
@@ -5,0 +5,0 @@ import"./packager-tool-37g19zk3.js"; |
+2
-2
| import { | ||
| publishSolutionAsync | ||
| } from "./packager-tool-r1hk3s30.js"; | ||
| import"./packager-tool-9j8d0ts5.js"; | ||
| } from "./packager-tool-ry2wtgx7.js"; | ||
| import"./packager-tool-vdajdv03.js"; | ||
| import"./packager-tool-y4wacqkp.js"; | ||
@@ -6,0 +6,0 @@ import"./packager-tool-9qecd4wb.js"; |
+5
-5
| import { | ||
| metadata, | ||
| registerCommands | ||
| } from "./packager-tool-v3bmxrve.js"; | ||
| import"./packager-tool-dmdgqh56.js"; | ||
| } from "./packager-tool-nek785e1.js"; | ||
| import"./packager-tool-s9phcc1z.js"; | ||
| import"./packager-tool-kfzzznjr.js"; | ||
| import"./packager-tool-epwm26av.js"; | ||
| import"./packager-tool-t6cck14z.js"; | ||
| import"./packager-tool-sdhdmkt8.js"; | ||
| import"./packager-tool-r1hk3s30.js"; | ||
| import"./packager-tool-9j8d0ts5.js"; | ||
| import"./packager-tool-ry2wtgx7.js"; | ||
| import"./packager-tool-vdajdv03.js"; | ||
| import"./packager-tool-37g19zk3.js"; | ||
@@ -12,0 +12,0 @@ import"./packager-tool-vpr77gre.js"; |
+1
-1
| { | ||
| "name": "@uipath/solution-tool", | ||
| "license": "MIT", | ||
| "version": "1.200.0-preview.120", | ||
| "version": "1.200.0", | ||
| "description": "Create, pack, publish, and deploy UiPath Automation Solutions.", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| import { | ||
| Configuration, | ||
| Configuration1 as Configuration2, | ||
| PackagesApi, | ||
| PipelinesApi, | ||
| resolveFeedScope | ||
| } from "./packager-tool-9j8d0ts5.js"; | ||
| import { | ||
| PollOutcome, | ||
| catchError, | ||
| extractErrorDetails, | ||
| getSolutionAuthContext, | ||
| logger, | ||
| mapPollFailure, | ||
| pollUntil | ||
| } from "./packager-tool-y4wacqkp.js"; | ||
| import { | ||
| getFileSystem | ||
| } from "./packager-tool-q90kqh83.js"; | ||
| import { | ||
| strFromU8, | ||
| strToU8, | ||
| unzipSync, | ||
| zipSync | ||
| } from "./packager-tool-129wn232.js"; | ||
| // src/services/package-metadata-rewrite.ts | ||
| import { randomUUID } from "node:crypto"; | ||
| var SOLUTION_METADATA_ENTRY = "solutionMetadata.json"; | ||
| function isRecord(value) { | ||
| return typeof value === "object" && value !== null && !Array.isArray(value); | ||
| } | ||
| var requireValue = (value, flag) => { | ||
| const trimmed = value.trim(); | ||
| if (!trimmed) { | ||
| throw new Error(`${flag} cannot be empty.`); | ||
| } | ||
| return trimmed; | ||
| }; | ||
| function rewritePackageMetadata(archive, overrides) { | ||
| const entries = unzipSync(archive); | ||
| const metadataBytes = entries[SOLUTION_METADATA_ENTRY]; | ||
| if (!metadataBytes) { | ||
| throw new Error(`Package archive has no ${SOLUTION_METADATA_ENTRY} at its root, so its name and version cannot be rewritten. Only a .zip produced by 'uip solution pack' carries that file.`); | ||
| } | ||
| let parsed; | ||
| try { | ||
| parsed = JSON.parse(strFromU8(metadataBytes)); | ||
| } catch (err) { | ||
| throw new Error(`${SOLUTION_METADATA_ENTRY} in the package archive is not valid JSON: ${err instanceof Error ? err.message : String(err)}`); | ||
| } | ||
| if (!isRecord(parsed) || !isRecord(parsed.spec)) { | ||
| throw new Error(`${SOLUTION_METADATA_ENTRY} in the package archive has no 'spec' object, so its name and version cannot be rewritten.`); | ||
| } | ||
| const spec = parsed.spec; | ||
| const packageName = overrides.packageName === undefined ? String(spec.packageName ?? "") : requireValue(overrides.packageName, "--package-name"); | ||
| const packageVersion = overrides.packageVersion === undefined ? String(spec.packageVersion ?? "") : requireValue(overrides.packageVersion, "--package-version"); | ||
| const packageVersionKey = randomUUID(); | ||
| const rewritten = { | ||
| ...parsed, | ||
| spec: { ...spec, packageName, packageVersion, packageVersionKey } | ||
| }; | ||
| const zipInput = {}; | ||
| for (const [entryName, entryBytes] of Object.entries(entries)) { | ||
| const level = entryName.toLowerCase().endsWith(".nupkg") ? 0 : 6; | ||
| zipInput[entryName] = [entryBytes, { level }]; | ||
| } | ||
| zipInput[SOLUTION_METADATA_ENTRY] = [ | ||
| strToU8(JSON.stringify(rewritten)), | ||
| { level: 6 } | ||
| ]; | ||
| return { | ||
| archive: zipSync(zipInput), | ||
| packageName, | ||
| packageVersion, | ||
| packageVersionKey | ||
| }; | ||
| } | ||
| // src/services/publish-service.ts | ||
| var TERMINAL_STATES = new Set([ | ||
| "Ready", | ||
| "Active", | ||
| "Failed" | ||
| ]); | ||
| var VERSION_CONFLICT_PATTERNS = [ | ||
| /\balready exists\b/i, | ||
| /\bduplicate\b.*\bversion\b/i, | ||
| /\bversion\b.*\bduplicate\b/i, | ||
| /\bpackage[-\s]?version\b.*\bexists\b/i, | ||
| /\bversion[-\s]?exists\b/i, | ||
| /\bversion\b.*\balready exists\b/i | ||
| ]; | ||
| var isVersionConflictError = (message, details) => { | ||
| const errorText = `${message} ${details ?? ""}`; | ||
| return VERSION_CONFLICT_PATTERNS.some((pattern) => pattern.test(errorText)); | ||
| }; | ||
| async function publishSolutionAsync(packagePath, options = {}) { | ||
| const [authError, auth] = await catchError(getSolutionAuthContext({ | ||
| tenant: options.tenant, | ||
| loginValidity: options.loginValidity, | ||
| envFilePath: options.envFilePath | ||
| })); | ||
| if (authError) { | ||
| return { | ||
| ok: false, | ||
| reason: "auth_failed", | ||
| message: authError.message | ||
| }; | ||
| } | ||
| const fs = getFileSystem(); | ||
| const resolvedPath = fs.path.resolve(packagePath); | ||
| if (!await fs.exists(resolvedPath)) { | ||
| return { | ||
| ok: false, | ||
| reason: "file_not_found", | ||
| message: `File not found: ${resolvedPath}` | ||
| }; | ||
| } | ||
| if (!resolvedPath.endsWith(".zip")) { | ||
| const stats = await fs.stat(resolvedPath); | ||
| const isSolutionSource = stats?.isDirectory() === true || resolvedPath.endsWith(".uis") || resolvedPath.endsWith(".uipx"); | ||
| if (isSolutionSource) { | ||
| return { | ||
| ok: false, | ||
| reason: "not_packed", | ||
| message: `'${packagePath}' is a solution source, not a packed package. 'publish' uploads the .zip produced by 'solution pack'.`, | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| return { | ||
| ok: false, | ||
| reason: "not_a_zip", | ||
| message: `Invalid file type. Expected a .zip file, got: ${resolvedPath}` | ||
| }; | ||
| } | ||
| const [fileBufferError, readBuffer] = await catchError(fs.readFile(resolvedPath)); | ||
| if (fileBufferError) { | ||
| const { message } = await extractErrorDetails(fileBufferError); | ||
| return { | ||
| ok: false, | ||
| reason: "file_read_failed", | ||
| message, | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| if (!readBuffer) { | ||
| return { | ||
| ok: false, | ||
| reason: "file_read_failed", | ||
| message: `File is empty or unreadable: ${resolvedPath}`, | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| let fileBuffer = readBuffer; | ||
| if (options.packageName !== undefined || options.packageVersion !== undefined) { | ||
| const [rewriteError, rewritten] = await catchError(Promise.resolve().then(() => rewritePackageMetadata(new Uint8Array(fileBuffer), { | ||
| packageName: options.packageName, | ||
| packageVersion: options.packageVersion | ||
| }))); | ||
| if (rewriteError || !rewritten) { | ||
| return { | ||
| ok: false, | ||
| reason: "metadata_rewrite_failed", | ||
| message: rewriteError?.message ?? "Could not rewrite the package name/version.", | ||
| details: resolvedPath | ||
| }; | ||
| } | ||
| logger.info(`Publishing ${resolvedPath} as ${rewritten.packageName} ${rewritten.packageVersion} (package version key ${rewritten.packageVersionKey}); the file on disk is unchanged.`); | ||
| fileBuffer = rewritten.archive; | ||
| } | ||
| const [scopeError, scope] = await catchError(resolveFeedScope({ | ||
| personalWorkspace: options.personalWorkspace, | ||
| feed: options.feed, | ||
| tenant: options.tenant, | ||
| loginValidity: options.loginValidity, | ||
| envFilePath: options.envFilePath | ||
| })); | ||
| if (scopeError) { | ||
| return { | ||
| ok: false, | ||
| reason: options.feed !== undefined ? "feed_resolution_failed" : "personal_workspace_resolution_failed", | ||
| message: scopeError.message | ||
| }; | ||
| } | ||
| if (scope.kind !== "tenant") { | ||
| return publishToFeed(auth, fileBuffer, scope, options); | ||
| } | ||
| const configuration = new Configuration({ | ||
| basePath: auth.basePath, | ||
| accessToken: auth.accessToken | ||
| }); | ||
| const api = new PipelinesApi(configuration); | ||
| const [uploadError, uploadResult] = await catchError(api.pipelinesPackageUpload({ body: fileBuffer })); | ||
| if (uploadError) { | ||
| return mapUploadError(uploadError); | ||
| } | ||
| let packageVersionInfo = uploadResult; | ||
| if (options.wait) { | ||
| const pollResult = await pollUntil({ | ||
| fn: () => api.pipelinesGetPackageVersion({ | ||
| packageName: uploadResult.packageName, | ||
| packageVersion: uploadResult.packageVersion | ||
| }), | ||
| until: (result) => TERMINAL_STATES.has(result.state), | ||
| getStatus: (result) => result.state, | ||
| label: `publish ${uploadResult.packageName}:${uploadResult.packageVersion}`, | ||
| logPrefix: "publish", | ||
| timeoutMs: (options.timeout ?? 360) * 1000, | ||
| intervalMs: options.pollInterval ?? 5000, | ||
| signal: options.signal | ||
| }); | ||
| if (pollResult.outcome !== PollOutcome.Completed) { | ||
| const { reason, message } = mapPollFailure(pollResult, "Package publish"); | ||
| return { ok: false, reason, message }; | ||
| } | ||
| if (!pollResult.data) { | ||
| return { | ||
| ok: false, | ||
| reason: "poll_failed", | ||
| message: "Package publish did not return a final state." | ||
| }; | ||
| } | ||
| packageVersionInfo = pollResult.data; | ||
| if (packageVersionInfo.state === "Failed") { | ||
| return { | ||
| ok: false, | ||
| reason: "publish_failed", | ||
| message: `Package publish failed with state: ${packageVersionInfo.state}` | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| ok: true, | ||
| packageVersionKey: packageVersionInfo.key, | ||
| packageName: packageVersionInfo.packageName, | ||
| packageVersion: packageVersionInfo.packageVersion, | ||
| state: packageVersionInfo.state, | ||
| feedKind: "tenant" | ||
| }; | ||
| } | ||
| async function publishToFeed(auth, fileBuffer, scope, options) { | ||
| const config = new Configuration2({ | ||
| basePath: auth.basePath, | ||
| accessToken: auth.accessToken | ||
| }); | ||
| const api = new PackagesApi(config); | ||
| const [uploadError, packageVersionKey] = await catchError(api.packagesUpload({ | ||
| body: fileBuffer, | ||
| locationKey: scope.folderKey | ||
| })); | ||
| if (uploadError) { | ||
| return mapUploadError(uploadError); | ||
| } | ||
| const [getError, initialInfo] = await catchError(api.packagesGetVersion({ packageVersionKey })); | ||
| if (getError) { | ||
| logger.warn(`Package uploaded (key ${packageVersionKey}) but its metadata was not yet retrievable; PackageName/PackageVersion/State will be absent from output: ${getError.message}`); | ||
| } | ||
| let packageVersionInfo = getError ? undefined : initialInfo; | ||
| if (options.wait) { | ||
| const pollResult = await pollUntil({ | ||
| fn: () => api.packagesGetVersion({ packageVersionKey }), | ||
| until: (result) => TERMINAL_STATES.has(result.state), | ||
| getStatus: (result) => result.state, | ||
| label: `publish ${packageVersionInfo ? `${packageVersionInfo.packageName}:${packageVersionInfo.packageVersion}` : packageVersionKey}`, | ||
| logPrefix: "publish", | ||
| timeoutMs: (options.timeout ?? 360) * 1000, | ||
| intervalMs: options.pollInterval ?? 5000, | ||
| signal: options.signal | ||
| }); | ||
| if (pollResult.outcome !== PollOutcome.Completed) { | ||
| const { reason, message } = mapPollFailure(pollResult, "Package publish"); | ||
| return { ok: false, reason, message }; | ||
| } | ||
| if (!pollResult.data) { | ||
| return { | ||
| ok: false, | ||
| reason: "poll_failed", | ||
| message: "Package publish did not return a final state." | ||
| }; | ||
| } | ||
| packageVersionInfo = pollResult.data; | ||
| if (packageVersionInfo.state === "Failed") { | ||
| return { | ||
| ok: false, | ||
| reason: "publish_failed", | ||
| message: `Package publish failed with state: ${packageVersionInfo.state}` | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| ok: true, | ||
| packageVersionKey: packageVersionInfo?.key ?? packageVersionKey, | ||
| packageName: packageVersionInfo?.packageName, | ||
| packageVersion: packageVersionInfo?.packageVersion, | ||
| state: packageVersionInfo?.state, | ||
| feedKind: scope.kind | ||
| }; | ||
| } | ||
| async function mapUploadError(uploadError) { | ||
| const { message, details, context, retry } = await extractErrorDetails(uploadError); | ||
| const fetchCause = uploadError instanceof Error && uploadError.name === "FetchError" && uploadError.cause instanceof Error ? uploadError.cause : null; | ||
| const surfacedMessage = fetchCause ? `Failed to upload package: ${fetchCause.message}` : message; | ||
| const httpStatus = context?.httpStatus; | ||
| let reason = "upload_failed"; | ||
| if (isVersionConflictError(message, details)) { | ||
| reason = "upload_version_conflict"; | ||
| } else if (fetchCause || httpStatus !== undefined && httpStatus >= 500) { | ||
| reason = "upload_network"; | ||
| } else if (httpStatus === 400 || httpStatus === 422) { | ||
| reason = "upload_rejected"; | ||
| } | ||
| return { | ||
| ok: false, | ||
| reason, | ||
| message: surfacedMessage, | ||
| details, | ||
| errorCode: context?.errorCode, | ||
| retry, | ||
| context | ||
| }; | ||
| } | ||
| export { publishSolutionAsync }; | ||
| //# debugId=696E04915672C64A64756E2164756E21 |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
2
-33.33%5780717
0