@uipath/codedapp-tool 1.206.0-preview.303 → 1.207.0-preview.305

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.
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  UIPATH_HOME_DIR,
3
3
  AUTH_FILENAME,
4
+ AUTH_FILE_MODE,
5
+ AUTH_DIR_MODE,
4
6
  DEFAULT_BASE_URL,
5
7
  DEFAULT_REDIRECT_URI
6
- } from "./packager-tool-1qg04b7q.js";
8
+ } from "./packager-tool-bzcphfa8.js";
7
9
  import {
8
10
  getFileSystem
9
- } from "./packager-tool-0ajs8pnk.js";
11
+ } from "./packager-tool-9thx6ae9.js";
10
12
  import {
11
13
  __require
12
14
  } from "./packager-tool-6an893wm.js";
@@ -684,7 +686,7 @@ var readTokenScopes2 = (accessToken) => accessToken ? pickScopes(decodeClaims(ac
684
686
  // ../auth/src/envAuth.ts
685
687
  var ENV_AUTH_ENABLE_VAR = "UIPATH_CLI_ENABLE_ENV_AUTH";
686
688
  var ENFORCE_ROBOT_AUTH_VAR = "UIPATH_CLI_ENFORCE_ROBOT_AUTH";
687
- var ENV_AUTH_VARS = {
689
+ var ENV_AUTH_VARS2 = {
688
690
  token: "UIPATH_CLI_AUTH_TOKEN",
689
691
  organizationName: "UIPATH_CLI_ORGANIZATION_NAME",
690
692
  organizationId: "UIPATH_CLI_ORGANIZATION_ID",
@@ -721,17 +723,17 @@ var resolveBaseUrl = (rawUrl, failureContext) => {
721
723
  return baseUrl;
722
724
  };
723
725
  var readAuthFromEnv = () => {
724
- const accessToken = requireEnv(ENV_AUTH_VARS.token);
725
- const organizationName = requireEnv(ENV_AUTH_VARS.organizationName);
726
- const organizationId = requireEnv(ENV_AUTH_VARS.organizationId);
727
- const tenantName = requireEnv(ENV_AUTH_VARS.tenantName);
728
- const tenantId = requireEnv(ENV_AUTH_VARS.tenantId);
726
+ const accessToken = requireEnv(ENV_AUTH_VARS2.token);
727
+ const organizationName = requireEnv(ENV_AUTH_VARS2.organizationName);
728
+ const organizationId = requireEnv(ENV_AUTH_VARS2.organizationId);
729
+ const tenantName = requireEnv(ENV_AUTH_VARS2.tenantName);
730
+ const tenantId = requireEnv(ENV_AUTH_VARS2.tenantId);
729
731
  const [parseError, payload] = catchError2(() => parseJWT(accessToken));
730
732
  if (parseError) {
731
733
  const parseErrorMessage = parseError instanceof Error ? parseError.message : String(parseError);
732
734
  const rawUrl = process.env[OPAQUE_TOKEN_BASE_URL_VAR];
733
735
  if (!rawUrl) {
734
- throw new EnvAuthConfigError(`${ENV_AUTH_VARS.token} is not a JWT (treating it as an opaque token, ` + `e.g. a Personal Access Token). Set ${OPAQUE_TOKEN_BASE_URL_VAR} to the ` + `UiPath base URL if this is a PAT, or fix the token if it was meant to ` + `be a JWT (parse error: ${parseErrorMessage}).`);
736
+ throw new EnvAuthConfigError(`${ENV_AUTH_VARS2.token} is not a JWT (treating it as an opaque token, ` + `e.g. a Personal Access Token). Set ${OPAQUE_TOKEN_BASE_URL_VAR} to the ` + `UiPath base URL if this is a PAT, or fix the token if it was meant to ` + `be a JWT (parse error: ${parseErrorMessage}).`);
735
737
  }
736
738
  const baseUrl = resolveBaseUrl(rawUrl, `Failed to validate ${OPAQUE_TOKEN_BASE_URL_VAR}`);
737
739
  return {
@@ -748,7 +750,7 @@ var readAuthFromEnv = () => {
748
750
  }
749
751
  const iss = payload.iss;
750
752
  if (typeof iss !== "string" || iss.length === 0) {
751
- throw new EnvAuthConfigError(`${ENV_AUTH_VARS.token} has no 'iss' claim; cannot determine ` + `the UiPath server. Ensure the token was issued by a UiPath identity server.`);
753
+ throw new EnvAuthConfigError(`${ENV_AUTH_VARS2.token} has no 'iss' claim; cannot determine ` + `the UiPath server. Ensure the token was issued by a UiPath identity server.`);
752
754
  }
753
755
  const baseUrl = resolveBaseUrl(iss, "Failed to derive server URL from token 'iss' claim");
754
756
  const expiration = getTokenExpiration(accessToken);
@@ -1186,6 +1188,38 @@ var loadEnvFileAsync = async ({ envPath }) => {
1186
1188
  }
1187
1189
  return parseEnvContent(content);
1188
1190
  };
1191
+ var findAuthHomeDir = (fs, dir) => {
1192
+ let current = dir;
1193
+ for (;; ) {
1194
+ if (fs.path.basename(current) === UIPATH_HOME_DIR)
1195
+ return current;
1196
+ const parent = fs.path.dirname(current);
1197
+ if (parent === current)
1198
+ return;
1199
+ current = parent;
1200
+ }
1201
+ };
1202
+ var TEMP_FILE_ATTEMPTS = 5;
1203
+ var isFileExists = (error) => error instanceof Error && error.code === "EEXIST";
1204
+ var writeTempFile = async (fs, targetPath, content) => {
1205
+ for (let attempt = 1;; attempt++) {
1206
+ const tempPath = `${targetPath}.${crypto.randomUUID()}.tmp`;
1207
+ try {
1208
+ await fs.writeFile(tempPath, content, {
1209
+ mode: AUTH_FILE_MODE,
1210
+ exclusive: true
1211
+ });
1212
+ return tempPath;
1213
+ } catch (error) {
1214
+ if (!isFileExists(error)) {
1215
+ await fs.rm(tempPath).catch(() => {});
1216
+ throw error;
1217
+ }
1218
+ if (attempt === TEMP_FILE_ATTEMPTS)
1219
+ throw error;
1220
+ }
1221
+ }
1222
+ };
1189
1223
  var saveEnvFileAsync2 = async ({
1190
1224
  envPath,
1191
1225
  data,
@@ -1213,10 +1247,18 @@ var saveEnvFileAsync2 = async ({
1213
1247
  `)}
1214
1248
  `;
1215
1249
  const dir = fs.path.dirname(absolutePath);
1216
- await fs.mkdir(dir);
1217
- const tempPath = `${absolutePath}.tmp`;
1218
- await fs.writeFile(tempPath, content);
1219
- await fs.rename(tempPath, absolutePath);
1250
+ await fs.mkdir(dir, { mode: AUTH_DIR_MODE });
1251
+ const authHomeDir = findAuthHomeDir(fs, dir);
1252
+ if (authHomeDir !== undefined) {
1253
+ await fs.chmod?.(authHomeDir, AUTH_DIR_MODE);
1254
+ }
1255
+ const tempPath = await writeTempFile(fs, absolutePath, content);
1256
+ try {
1257
+ await fs.rename(tempPath, absolutePath);
1258
+ } catch (error) {
1259
+ await fs.rm(tempPath).catch(() => {});
1260
+ throw error;
1261
+ }
1220
1262
  };
1221
1263
 
1222
1264
  // ../auth/src/loginStatus.ts
@@ -1868,10 +1910,10 @@ var authenticate2 = async ({
1868
1910
  const authUrl = `${authorizationEndpoint}?${authParams.toString()}`;
1869
1911
  let strategy;
1870
1912
  if (isBrowser()) {
1871
- const { BrowserAuthStrategy } = await import("./browser-strategy-z97p0ezf.js");
1913
+ const { BrowserAuthStrategy } = await import("./browser-strategy-zem90qdb.js");
1872
1914
  strategy = new BrowserAuthStrategy;
1873
1915
  } else {
1874
- const { NodeAuthStrategy } = await import("./node-strategy-fk02jqd8.js");
1916
+ const { NodeAuthStrategy } = await import("./node-strategy-ems5bj71.js");
1875
1917
  strategy = new NodeAuthStrategy;
1876
1918
  }
1877
1919
  const code = await strategy.execute(authUrl, effectiveRedirectUriUrl, state, {
@@ -1891,6 +1933,6 @@ var authenticate2 = async ({
1891
1933
  });
1892
1934
  };
1893
1935
 
1894
- export { resolveSessionIdentity2, readTokenScopes2, saveEnvFileAsync2, getLoginStatusAsync2, getAuthContext2, authenticate2 };
1936
+ export { resolveSessionIdentity2, readTokenScopes2, ENV_AUTH_VARS2, saveEnvFileAsync2, getLoginStatusAsync2, getAuthContext2, authenticate2 };
1895
1937
 
1896
- //# debugId=C06F925426D93BFE64756E2164756E21
1938
+ //# debugId=1B715F2D4408F9E064756E2164756E21