@uipath/auth 1.205.0-preview.277 → 1.206.0-preview.279

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/dist/index.js CHANGED
@@ -1,19 +1,15 @@
1
1
  import { createRequire } from "node:module";
2
- var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, {
10
- get: all[name],
11
- enumerable: true,
12
- configurable: true,
13
- set: __exportSetter.bind(all, name)
14
- });
2
+ var __esm = (fn, res, err) => () => {
3
+ if (fn)
4
+ try {
5
+ res = fn(fn = 0);
6
+ } catch (e) {
7
+ err = [e];
8
+ }
9
+ if (err)
10
+ throw err[0];
11
+ return res;
15
12
  };
16
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
13
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
18
14
 
19
15
  // src/catch-error.ts
@@ -409,12 +405,6 @@ var init_is_in_ssh = __esm(() => {
409
405
  });
410
406
 
411
407
  // ../../node_modules/open/index.js
412
- var exports_open = {};
413
- __export(exports_open, {
414
- apps: () => apps,
415
- default: () => open_default,
416
- openApp: () => openApp
417
- });
418
408
  import process8 from "node:process";
419
409
  import path from "node:path";
420
410
  import { fileURLToPath } from "node:url";
@@ -648,21 +638,6 @@ var fallbackAttemptSymbol, __dirname2, localXdgOpenPath, platform, arch, tryEach
648
638
  ...options,
649
639
  target
650
640
  });
651
- }, openApp = (name, options) => {
652
- if (typeof name !== "string" && !Array.isArray(name)) {
653
- throw new TypeError("Expected a valid `name`");
654
- }
655
- const { arguments: appArguments = [] } = options ?? {};
656
- if (appArguments !== undefined && appArguments !== null && !Array.isArray(appArguments)) {
657
- throw new TypeError("Expected `appArguments` as Array type");
658
- }
659
- return baseOpen({
660
- ...options,
661
- app: {
662
- name,
663
- arguments: appArguments
664
- }
665
- });
666
641
  }, apps, open_default;
667
642
  var init_open = __esm(() => {
668
643
  init_wsl_utils();
@@ -719,7 +694,7 @@ var init_open = __esm(() => {
719
694
  });
720
695
 
721
696
  // ../filesystem/src/node.ts
722
- import { randomUUID } from "node:crypto";
697
+ import { createHash, randomUUID } from "node:crypto";
723
698
  import { existsSync } from "node:fs";
724
699
  import * as fs6 from "node:fs/promises";
725
700
  import * as os2 from "node:os";
@@ -742,16 +717,16 @@ class NodeFileSystem {
742
717
  };
743
718
  utils = {
744
719
  open: async (url) => {
745
- const { default: open2 } = await Promise.resolve().then(() => (init_open(), exports_open));
746
- await open2(url);
720
+ await Promise.resolve().then(() => init_open());
721
+ await open_default(url);
747
722
  }
748
723
  };
749
- async readFile(path3, options) {
724
+ async readFile(path, options) {
750
725
  try {
751
726
  if (options) {
752
- return await fs6.readFile(path3, "utf-8");
727
+ return await fs6.readFile(path, "utf-8");
753
728
  }
754
- return await fs6.readFile(path3);
729
+ return await fs6.readFile(path);
755
730
  } catch (error) {
756
731
  if (this.isEnoent(error))
757
732
  return null;
@@ -781,6 +756,15 @@ class NodeFileSystem {
781
756
  throw error;
782
757
  }
783
758
  }
759
+ async readdirEntries(dirPath) {
760
+ try {
761
+ return await fs6.readdir(dirPath, { withFileTypes: true });
762
+ } catch (error) {
763
+ if (this.isEnoent(error))
764
+ return [];
765
+ throw error;
766
+ }
767
+ }
784
768
  async stat(filePath) {
785
769
  try {
786
770
  const stats = await fs6.stat(filePath);
@@ -788,7 +772,8 @@ class NodeFileSystem {
788
772
  isFile: () => stats.isFile(),
789
773
  isDirectory: () => stats.isDirectory(),
790
774
  size: stats.size,
791
- mtimeMs: stats.mtimeMs
775
+ mtimeMs: stats.mtimeMs,
776
+ ctimeMs: stats.ctimeMs
792
777
  };
793
778
  } catch (error) {
794
779
  if (this.isEnoent(error))
@@ -902,6 +887,42 @@ class NodeFileSystem {
902
887
  throw error;
903
888
  }
904
889
  }
890
+ async hashFile(filePath) {
891
+ let handle;
892
+ try {
893
+ handle = await fs6.open(filePath, "r");
894
+ } catch (error) {
895
+ if (this.isEnoent(error))
896
+ return null;
897
+ throw error;
898
+ }
899
+ const buffer = hashBuffers.pop() ?? Buffer.allocUnsafe(HASH_CHUNK_BYTES);
900
+ try {
901
+ const opened = await handle.stat();
902
+ const stats = {
903
+ isFile: () => opened.isFile(),
904
+ isDirectory: () => opened.isDirectory(),
905
+ size: opened.size,
906
+ mtimeMs: opened.mtimeMs,
907
+ ctimeMs: opened.ctimeMs
908
+ };
909
+ const hash = createHash("sha256");
910
+ let size = 0;
911
+ for (;; ) {
912
+ const { bytesRead } = await handle.read(buffer, 0, buffer.byteLength, null);
913
+ if (bytesRead === 0)
914
+ break;
915
+ hash.update(buffer.subarray(0, bytesRead));
916
+ size += bytesRead;
917
+ }
918
+ return { sha256: hash.digest("hex"), size, stats };
919
+ } finally {
920
+ if (hashBuffers.length < HASH_BUFFERS_KEPT) {
921
+ hashBuffers.push(buffer);
922
+ }
923
+ await handle.close();
924
+ }
925
+ }
905
926
  async realpath(filePath) {
906
927
  try {
907
928
  return await fs6.realpath(filePath);
@@ -947,8 +968,11 @@ class NodeFileSystem {
947
968
  return typeof error === "object" && error !== null && "code" in error && error.code === code;
948
969
  }
949
970
  }
950
- var LOCK_HEARTBEAT_MS = 5000, LOCK_STALE_MS = 15000, LOCK_MAX_WAIT_MS = 20000, LOCK_MAX_HOLD_MS = 60000, LOCK_RETRY_MIN_MS = 100, LOCK_RETRY_JITTER_MS = 200;
951
- var init_node = () => {};
971
+ var LOCK_HEARTBEAT_MS = 5000, LOCK_STALE_MS = 15000, LOCK_MAX_WAIT_MS = 20000, LOCK_MAX_HOLD_MS = 60000, LOCK_RETRY_MIN_MS = 100, LOCK_RETRY_JITTER_MS = 200, HASH_CHUNK_BYTES, hashBuffers, HASH_BUFFERS_KEPT = 64;
972
+ var init_node = __esm(() => {
973
+ HASH_CHUNK_BYTES = 256 * 1024;
974
+ hashBuffers = [];
975
+ });
952
976
  // ../filesystem/src/index.ts
953
977
  var fsInstance, getFileSystem = () => fsInstance;
954
978
  var init_src = __esm(() => {
@@ -958,11 +982,6 @@ var init_src = __esm(() => {
958
982
  });
959
983
 
960
984
  // src/strategies/browser-strategy.ts
961
- var exports_browser_strategy = {};
962
- __export(exports_browser_strategy, {
963
- BrowserAuthStrategy: () => BrowserAuthStrategy
964
- });
965
-
966
985
  class BrowserAuthStrategy {
967
986
  async execute(url, _redirectUri, expectedState, opts) {
968
987
  const global = getGlobalThis();
@@ -990,7 +1009,7 @@ class BrowserAuthStrategy {
990
1009
 
991
1010
  ` + "If using an ad blocker, you may need to temporarily disable it.");
992
1011
  }
993
- return new Promise((resolve2, reject) => {
1012
+ return new Promise((resolve, reject) => {
994
1013
  let timer;
995
1014
  const messageHandler = (event) => {
996
1015
  if (event.data?.type === "UIP_AUTH_CODE" && event.data.code) {
@@ -1001,7 +1020,7 @@ class BrowserAuthStrategy {
1001
1020
  return;
1002
1021
  }
1003
1022
  cleanup();
1004
- resolve2(event.data.code);
1023
+ resolve(event.data.code);
1005
1024
  popup.close();
1006
1025
  } else if (event.data?.type === "UIP_AUTH_ERROR") {
1007
1026
  cleanup();
@@ -1215,13 +1234,13 @@ var CALLBACK_PAGE_TITLE_SUFFIX = " - UiPath CLI", escapeHtml = (value) => value.
1215
1234
  };
1216
1235
 
1217
1236
  // src/server.ts
1218
- var RECLAIM_PROBE_PATH = "/uip-reclaim-probe", RECLAIM_LISTENER_PID_HEADER = "x-uipath-cli-login-pid", RECLAIM_PROBER_PID_HEADER = "x-uipath-cli-prober-pid", RECLAIM_MARKER, RECLAIM_PROBE_TIMEOUT_MS = 1000, RECLAIM_REBIND_DELAY_MS = 150, RECLAIM_PROBE_READ_LIMIT, probeStaleCallbackListener = (http, host, port) => new Promise((resolve2) => {
1237
+ var RECLAIM_PROBE_PATH = "/uip-reclaim-probe", RECLAIM_LISTENER_PID_HEADER = "x-uipath-cli-login-pid", RECLAIM_PROBER_PID_HEADER = "x-uipath-cli-prober-pid", RECLAIM_MARKER, RECLAIM_PROBE_TIMEOUT_MS = 1000, RECLAIM_REBIND_DELAY_MS = 150, RECLAIM_PROBE_READ_LIMIT, probeStaleCallbackListener = (http, host, port) => new Promise((resolve) => {
1219
1238
  let sawResponse = false;
1220
1239
  let listenerPid;
1221
1240
  let deadline;
1222
1241
  const settle = (verdict) => {
1223
1242
  clearTimeout(deadline);
1224
- resolve2({ verdict, pid: listenerPid });
1243
+ resolve({ verdict, pid: listenerPid });
1225
1244
  };
1226
1245
  const req = http.get({
1227
1246
  host,
@@ -1268,7 +1287,7 @@ var RECLAIM_PROBE_PATH = "/uip-reclaim-probe", RECLAIM_LISTENER_PID_HEADER = "x-
1268
1287
  } catch {
1269
1288
  throw new Error("Local server authentication is not supported in this environment.");
1270
1289
  }
1271
- return new Promise((resolve2, reject) => {
1290
+ return new Promise((resolve, reject) => {
1272
1291
  const server = http.createServer((req, res) => {
1273
1292
  if (!req.url) {
1274
1293
  res.writeHead(400, {
@@ -1331,7 +1350,7 @@ var RECLAIM_PROBE_PATH = "/uip-reclaim-probe", RECLAIM_LISTENER_PID_HEADER = "x-
1331
1350
  type: "success"
1332
1351
  }));
1333
1352
  server.close();
1334
- resolve2(url);
1353
+ resolve(url);
1335
1354
  return;
1336
1355
  }
1337
1356
  res.writeHead(400, {
@@ -1442,14 +1461,9 @@ var init_server = __esm(() => {
1442
1461
  });
1443
1462
 
1444
1463
  // src/strategies/node-strategy.ts
1445
- var exports_node_strategy = {};
1446
- __export(exports_node_strategy, {
1447
- NodeAuthStrategy: () => NodeAuthStrategy
1448
- });
1449
-
1450
1464
  class NodeAuthStrategy {
1451
1465
  async execute(url, redirectUri, expectedState, opts) {
1452
- const fs7 = getFileSystem();
1466
+ const fs = getFileSystem();
1453
1467
  const callbackUrl = await startServer({
1454
1468
  redirectUri,
1455
1469
  timeoutMs: opts?.timeoutMs,
@@ -1469,7 +1483,7 @@ class NodeAuthStrategy {
1469
1483
  opts.onAuthUrl(safeUrl);
1470
1484
  return;
1471
1485
  }
1472
- const [openError] = await catchError(fs7.utils.open(url));
1486
+ const [openError] = await catchError(fs.utils.open(url));
1473
1487
  if (!openError)
1474
1488
  return;
1475
1489
  const isSpawnError = "code" in openError && openError.code === "ENOENT";
@@ -1777,14 +1791,14 @@ function ClientSecretPost2(clientSecret) {
1777
1791
  return ClientSecretPost(clientSecret);
1778
1792
  }
1779
1793
  tbi ||= new WeakMap;
1780
- return (as, client, body, headers2) => {
1794
+ return (as, client, body, headers) => {
1781
1795
  let auth;
1782
1796
  if (!(auth = tbi.get(client))) {
1783
1797
  assertString2(client.client_secret, '"metadata.client_secret"');
1784
1798
  auth = ClientSecretPost(client.client_secret);
1785
1799
  tbi.set(client, auth);
1786
1800
  }
1787
- return auth(as, client, body, headers2);
1801
+ return auth(as, client, body, headers);
1788
1802
  };
1789
1803
  }
1790
1804
  function assertString2(input, it) {
@@ -1956,6 +1970,7 @@ init_src();
1956
1970
  init_src();
1957
1971
  init_constants();
1958
1972
  var DEFAULT_AUTH_PROFILE = "default";
1973
+ var INHERITED_AUTH_PROFILE_ENV = "UIPATH_CLI_INHERITED_PROFILE";
1959
1974
  var PROFILE_DIR = "profiles";
1960
1975
  var PROFILE_NAME_RE = /^[A-Za-z0-9._-]+$/;
1961
1976
  var ACTIVE_AUTH_PROFILE_KEY = Symbol.for("@uipath/auth/ActiveAuthProfile");
@@ -2043,32 +2058,32 @@ function resolveAuthProfileFilePath(profile) {
2043
2058
  if (normalized === undefined) {
2044
2059
  throw new AuthProfileValidationError(`"${DEFAULT_AUTH_PROFILE}" is the built-in profile and does not have a profile file path.`);
2045
2060
  }
2046
- const fs7 = getFileSystem();
2047
- return fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR, normalized, AUTH_FILENAME);
2061
+ const fs = getFileSystem();
2062
+ return fs.path.join(fs.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR, normalized, AUTH_FILENAME);
2048
2063
  }
2049
2064
  function getActiveAuthProfileFilePath() {
2050
2065
  const profile = getActiveAuthProfile();
2051
2066
  return profile ? resolveAuthProfileFilePath(profile) : undefined;
2052
2067
  }
2053
2068
  function getAuthProfilesRootPath() {
2054
- const fs7 = getFileSystem();
2055
- return fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR);
2069
+ const fs = getFileSystem();
2070
+ return fs.path.join(fs.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR);
2056
2071
  }
2057
2072
  function resolveAuthProfileDirPath(profile) {
2058
2073
  const normalized = normalizeAuthProfileName(profile);
2059
2074
  if (normalized === undefined) {
2060
2075
  throw new AuthProfileValidationError(`"${DEFAULT_AUTH_PROFILE}" is the built-in profile and does not have a profile directory.`);
2061
2076
  }
2062
- const fs7 = getFileSystem();
2063
- return fs7.path.join(getAuthProfilesRootPath(), normalized);
2077
+ const fs = getFileSystem();
2078
+ return fs.path.join(getAuthProfilesRootPath(), normalized);
2064
2079
  }
2065
2080
  async function listAuthProfileNamesAsync() {
2066
- const fs7 = getFileSystem();
2081
+ const fs = getFileSystem();
2067
2082
  const root = getAuthProfilesRootPath();
2068
- if (!await fs7.exists(root)) {
2083
+ if (!await fs.exists(root)) {
2069
2084
  return [];
2070
2085
  }
2071
- const [readError, entries] = await catchError(fs7.readdir(root));
2086
+ const [readError, entries] = await catchError(fs.readdir(root));
2072
2087
  if (readError || !entries) {
2073
2088
  return [];
2074
2089
  }
@@ -2077,7 +2092,7 @@ async function listAuthProfileNamesAsync() {
2077
2092
  if (!PROFILE_NAME_RE.test(entry) || entry === DEFAULT_AUTH_PROFILE) {
2078
2093
  continue;
2079
2094
  }
2080
- const stats = await fs7.stat(fs7.path.join(root, entry));
2095
+ const stats = await fs.stat(fs.path.join(root, entry));
2081
2096
  if (stats?.isDirectory()) {
2082
2097
  names.push(entry);
2083
2098
  }
@@ -2085,26 +2100,26 @@ async function listAuthProfileNamesAsync() {
2085
2100
  return names.sort((a, b) => a.localeCompare(b));
2086
2101
  }
2087
2102
  async function authProfileExistsAsync(profile) {
2088
- const fs7 = getFileSystem();
2103
+ const fs = getFileSystem();
2089
2104
  const [pathError, dir] = catchError(() => resolveAuthProfileDirPath(profile));
2090
2105
  if (pathError || dir === undefined) {
2091
2106
  return false;
2092
2107
  }
2093
- const stats = await fs7.stat(dir);
2108
+ const stats = await fs.stat(dir);
2094
2109
  return stats?.isDirectory() === true;
2095
2110
  }
2096
2111
  async function deleteAuthProfileAsync(profile) {
2097
2112
  const dir = resolveAuthProfileDirPath(profile);
2098
- const fs7 = getFileSystem();
2099
- const relativeToRoot = fs7.path.relative(getAuthProfilesRootPath(), dir);
2100
- if (relativeToRoot === "" || relativeToRoot.startsWith("..") || fs7.path.isAbsolute(relativeToRoot)) {
2113
+ const fs = getFileSystem();
2114
+ const relativeToRoot = fs.path.relative(getAuthProfilesRootPath(), dir);
2115
+ if (relativeToRoot === "" || relativeToRoot.startsWith("..") || fs.path.isAbsolute(relativeToRoot)) {
2101
2116
  throw new AuthProfileValidationError(`Refusing to delete "${profile}": resolved path escapes the profiles directory.`);
2102
2117
  }
2103
- const stats = await fs7.stat(dir);
2118
+ const stats = await fs.stat(dir);
2104
2119
  if (stats?.isDirectory() !== true) {
2105
2120
  return;
2106
2121
  }
2107
- await fs7.rm(dir);
2122
+ await fs.rm(dir);
2108
2123
  return dir;
2109
2124
  }
2110
2125
  // src/utils/jwt.ts
@@ -2273,6 +2288,8 @@ var ENV_AUTH_VARS = {
2273
2288
  };
2274
2289
 
2275
2290
  class EnvAuthConfigError extends Error {
2291
+ errorCode = "configuration_error";
2292
+ retry = "RetryWillNotFix";
2276
2293
  constructor(message) {
2277
2294
  super(message);
2278
2295
  this.name = "EnvAuthConfigError";
@@ -2311,11 +2328,11 @@ var readAuthFromEnv = () => {
2311
2328
  if (!rawUrl) {
2312
2329
  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}).`);
2313
2330
  }
2314
- const baseUrl2 = resolveBaseUrl(rawUrl, `Failed to validate ${OPAQUE_TOKEN_BASE_URL_VAR}`);
2331
+ const baseUrl = resolveBaseUrl(rawUrl, `Failed to validate ${OPAQUE_TOKEN_BASE_URL_VAR}`);
2315
2332
  return {
2316
2333
  loginStatus: "Logged in",
2317
2334
  accessToken,
2318
- baseUrl: baseUrl2,
2335
+ baseUrl,
2319
2336
  organizationName,
2320
2337
  organizationId,
2321
2338
  tenantName,
@@ -2367,9 +2384,9 @@ function breakerPathFor(authPath) {
2367
2384
  return `${authPath}${BREAKER_SUFFIX}`;
2368
2385
  }
2369
2386
  async function loadRefreshBreaker(authPath) {
2370
- const fs7 = getFileSystem();
2387
+ const fs = getFileSystem();
2371
2388
  try {
2372
- const content = await fs7.readFile(breakerPathFor(authPath), "utf-8");
2389
+ const content = await fs.readFile(breakerPathFor(authPath), "utf-8");
2373
2390
  if (!content)
2374
2391
  return {};
2375
2392
  const parsed = JSON.parse(content);
@@ -2380,20 +2397,20 @@ async function loadRefreshBreaker(authPath) {
2380
2397
  }
2381
2398
  async function saveRefreshBreaker(authPath, state) {
2382
2399
  try {
2383
- const fs7 = getFileSystem();
2384
- const path3 = breakerPathFor(authPath);
2385
- await fs7.mkdir(fs7.path.dirname(path3));
2386
- const tempPath = `${path3}.tmp`;
2387
- await fs7.writeFile(tempPath, JSON.stringify(state));
2388
- await fs7.rename(tempPath, path3);
2400
+ const fs = getFileSystem();
2401
+ const path = breakerPathFor(authPath);
2402
+ await fs.mkdir(fs.path.dirname(path));
2403
+ const tempPath = `${path}.tmp`;
2404
+ await fs.writeFile(tempPath, JSON.stringify(state));
2405
+ await fs.rename(tempPath, path);
2389
2406
  } catch {}
2390
2407
  }
2391
2408
  async function clearRefreshBreaker(authPath) {
2392
- const fs7 = getFileSystem();
2393
- const path3 = breakerPathFor(authPath);
2409
+ const fs = getFileSystem();
2410
+ const path = breakerPathFor(authPath);
2394
2411
  try {
2395
- if (await fs7.exists(path3)) {
2396
- await fs7.rm(path3);
2412
+ if (await fs.exists(path)) {
2413
+ await fs.rm(path);
2397
2414
  }
2398
2415
  } catch {}
2399
2416
  }
@@ -2415,13 +2432,13 @@ var ROBOT_USER_SERVICES_PIPE = "UiPathUserServices";
2415
2432
  var ROBOT_USER_SERVICES_ALTERNATE_PIPE = `${ROBOT_USER_SERVICES_PIPE}Alternate`;
2416
2433
  var PIPE_NAME_MAX_LENGTH = 103;
2417
2434
  var getRobotIpcPipeNames = async () => {
2418
- const fs7 = getFileSystem();
2419
- const username = fs7.env.getenv("USER") ?? fs7.env.getenv("USERNAME");
2435
+ const fs = getFileSystem();
2436
+ const username = fs.env.getenv("USER") ?? fs.env.getenv("USERNAME");
2420
2437
  if (!username) {
2421
2438
  throw new Error("Unable to determine current username");
2422
2439
  }
2423
- const tempPath = fs7.env.getenv("TMPDIR") ?? "/tmp/";
2424
- return [ROBOT_USER_SERVICES_PIPE, ROBOT_USER_SERVICES_ALTERNATE_PIPE].map((baseName) => fs7.path.join(tempPath, `${baseName}_${username}`).substring(0, PIPE_NAME_MAX_LENGTH));
2440
+ const tempPath = fs.env.getenv("TMPDIR") ?? "/tmp/";
2441
+ return [ROBOT_USER_SERVICES_PIPE, ROBOT_USER_SERVICES_ALTERNATE_PIPE].map((baseName) => fs.path.join(tempPath, `${baseName}_${username}`).substring(0, PIPE_NAME_MAX_LENGTH));
2425
2442
  };
2426
2443
  var defaultIsRobotIpcAvailable = async () => {
2427
2444
  if (process.platform === "win32") {
@@ -2431,20 +2448,20 @@ var defaultIsRobotIpcAvailable = async () => {
2431
2448
  if (pipeNamesError || !pipeNames) {
2432
2449
  return false;
2433
2450
  }
2434
- const fs7 = getFileSystem();
2451
+ const fs = getFileSystem();
2435
2452
  for (const pipeName of pipeNames) {
2436
- const [existsError, exists] = await catchError(fs7.exists(pipeName));
2453
+ const [existsError, exists] = await catchError(fs.exists(pipeName));
2437
2454
  if (!existsError && exists === true) {
2438
2455
  return true;
2439
2456
  }
2440
2457
  }
2441
2458
  return false;
2442
2459
  };
2443
- var withTimeout = (promise, timeoutMs) => new Promise((resolve2, reject) => {
2460
+ var withTimeout = (promise, timeoutMs) => new Promise((resolve, reject) => {
2444
2461
  const timer = setTimeout(() => reject(new Error(`Robot IPC call timed out after ${timeoutMs}ms`)), timeoutMs);
2445
2462
  promise.then((value) => {
2446
2463
  clearTimeout(timer);
2447
- resolve2(value);
2464
+ resolve(value);
2448
2465
  }, (error) => {
2449
2466
  clearTimeout(timer);
2450
2467
  reject(error);
@@ -2620,9 +2637,12 @@ var refreshAccessToken = async ({
2620
2637
  body: tokenParams
2621
2638
  });
2622
2639
  const tokenData = await tokenResponse.json();
2623
- if (!tokenResponse.ok) {
2640
+ if (tokenResponse.status === 400 || tokenResponse.status === 401) {
2624
2641
  throw new TokenRefreshOAuthError;
2625
2642
  }
2643
+ if (!tokenResponse.ok) {
2644
+ throw new Error(`Token refresh failed: HTTP ${tokenResponse.status}`);
2645
+ }
2626
2646
  const newAccessToken = tokenData.access_token;
2627
2647
  const newRefreshToken = tokenData.refresh_token;
2628
2648
  if (typeof newAccessToken !== "string" || typeof newRefreshToken !== "string") {
@@ -2657,9 +2677,9 @@ var errorCode = (err) => {
2657
2677
  }
2658
2678
  return "EUNKNOWN";
2659
2679
  };
2660
- var probeAsync = async (fs7, candidate) => {
2680
+ var probeAsync = async (fs, candidate) => {
2661
2681
  try {
2662
- const stats = await fs7.stat(candidate);
2682
+ const stats = await fs.stat(candidate);
2663
2683
  if (stats === null) {
2664
2684
  return { exists: false };
2665
2685
  }
@@ -2686,36 +2706,36 @@ var probeAsync = async (fs7, candidate) => {
2686
2706
  }
2687
2707
  };
2688
2708
  var resolveEnvFileLocationAsync = async (envFilePath = DEFAULT_ENV_FILENAME, opts) => {
2689
- const fs7 = getFileSystem();
2690
- if (fs7.path.isAbsolute(envFilePath)) {
2691
- const probe2 = await probeAsync(fs7, envFilePath);
2692
- return probe2.exists ? { exists: true, absolutePath: envFilePath, source: "absolute" } : {
2709
+ const fs = getFileSystem();
2710
+ if (fs.path.isAbsolute(envFilePath)) {
2711
+ const probe = await probeAsync(fs, envFilePath);
2712
+ return probe.exists ? { exists: true, absolutePath: envFilePath, source: "absolute" } : {
2693
2713
  exists: false,
2694
2714
  absolutePath: envFilePath,
2695
2715
  source: "absolute",
2696
- ...probe2.unusable ? { unusable: probe2.unusable } : {}
2716
+ ...probe.unusable ? { unusable: probe.unusable } : {}
2697
2717
  };
2698
2718
  }
2699
- const cwd = opts?.cwd ?? fs7.env.cwd();
2719
+ const cwd = opts?.cwd ?? fs.env.cwd();
2700
2720
  let searchDir = cwd;
2701
2721
  while (true) {
2702
- const candidate = fs7.path.join(searchDir, envFilePath);
2703
- const probe2 = await probeAsync(fs7, candidate);
2704
- if (probe2.exists) {
2722
+ const candidate = fs.path.join(searchDir, envFilePath);
2723
+ const probe = await probeAsync(fs, candidate);
2724
+ if (probe.exists) {
2705
2725
  return {
2706
2726
  exists: true,
2707
2727
  absolutePath: candidate,
2708
2728
  source: searchDir === cwd ? "cwd" : "ancestor"
2709
2729
  };
2710
2730
  }
2711
- const parentDir = fs7.path.dirname(searchDir);
2731
+ const parentDir = fs.path.dirname(searchDir);
2712
2732
  if (parentDir === searchDir) {
2713
2733
  break;
2714
2734
  }
2715
2735
  searchDir = parentDir;
2716
2736
  }
2717
- const homePath = fs7.path.join(fs7.env.homedir(), envFilePath);
2718
- const probe = await probeAsync(fs7, homePath);
2737
+ const homePath = fs.path.join(fs.env.homedir(), envFilePath);
2738
+ const probe = await probeAsync(fs, homePath);
2719
2739
  if (probe.exists) {
2720
2740
  return { exists: true, absolutePath: homePath, source: "home" };
2721
2741
  }
@@ -2758,12 +2778,12 @@ var parseEnvContent = (content) => {
2758
2778
  return env;
2759
2779
  };
2760
2780
  var loadEnvFileAsync = async ({ envPath }) => {
2761
- const fs7 = getFileSystem();
2762
- const absolutePath = fs7.path.isAbsolute(envPath) ? envPath : fs7.path.join(fs7.env.cwd(), envPath);
2763
- if (!await fs7.exists(absolutePath)) {
2781
+ const fs = getFileSystem();
2782
+ const absolutePath = fs.path.isAbsolute(envPath) ? envPath : fs.path.join(fs.env.cwd(), envPath);
2783
+ if (!await fs.exists(absolutePath)) {
2764
2784
  throw new Error(`Environment file not found: ${envPath}`);
2765
2785
  }
2766
- const content = await fs7.readFile(absolutePath, "utf-8");
2786
+ const content = await fs.readFile(absolutePath, "utf-8");
2767
2787
  if (content === null) {
2768
2788
  throw new Error(`Environment file not found: ${envPath}`);
2769
2789
  }
@@ -2774,10 +2794,10 @@ var saveEnvFileAsync = async ({
2774
2794
  data,
2775
2795
  merge = true
2776
2796
  }) => {
2777
- const fs7 = getFileSystem();
2778
- const absolutePath = fs7.path.isAbsolute(envPath) ? envPath : fs7.path.join(fs7.env.homedir(), envPath);
2797
+ const fs = getFileSystem();
2798
+ const absolutePath = fs.path.isAbsolute(envPath) ? envPath : fs.path.join(fs.env.homedir(), envPath);
2779
2799
  let existingData = {};
2780
- if (merge && await fs7.exists(absolutePath)) {
2800
+ if (merge && await fs.exists(absolutePath)) {
2781
2801
  try {
2782
2802
  existingData = await loadEnvFileAsync({ envPath: absolutePath });
2783
2803
  } catch {}
@@ -2795,19 +2815,19 @@ var saveEnvFileAsync = async ({
2795
2815
  const content = `${lines.join(`
2796
2816
  `)}
2797
2817
  `;
2798
- const dir = fs7.path.dirname(absolutePath);
2799
- await fs7.mkdir(dir);
2818
+ const dir = fs.path.dirname(absolutePath);
2819
+ await fs.mkdir(dir);
2800
2820
  const tempPath = `${absolutePath}.tmp`;
2801
- await fs7.writeFile(tempPath, content);
2802
- await fs7.rename(tempPath, absolutePath);
2821
+ await fs.writeFile(tempPath, content);
2822
+ await fs.rename(tempPath, absolutePath);
2803
2823
  };
2804
2824
 
2805
2825
  // src/loginStatus.ts
2806
2826
  var CredentialSource;
2807
- ((CredentialSource2) => {
2808
- CredentialSource2["SavedLogin"] = "saved-login";
2809
- CredentialSource2["Robot"] = "robot";
2810
- CredentialSource2["EnvironmentVariables"] = "env-vars";
2827
+ ((CredentialSource) => {
2828
+ CredentialSource["SavedLogin"] = "saved-login";
2829
+ CredentialSource["Robot"] = "robot";
2830
+ CredentialSource["EnvironmentVariables"] = "env-vars";
2811
2831
  })(CredentialSource ||= {});
2812
2832
  var defaultRobotTenantIdCache = new Map;
2813
2833
  var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
@@ -2929,11 +2949,11 @@ async function loadFileCredentials(loadEnvFile, absolutePath) {
2929
2949
  return { credentials };
2930
2950
  }
2931
2951
  async function getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath) {
2932
- const fs7 = getFs();
2933
- const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
2952
+ const fs = getFs();
2953
+ const globalPath = fs.path.join(fs.env.homedir(), envFilePath);
2934
2954
  if (absolutePath === globalPath)
2935
2955
  return;
2936
- if (!await fs7.exists(globalPath))
2956
+ if (!await fs.exists(globalPath))
2937
2957
  return;
2938
2958
  try {
2939
2959
  const globalCreds = await loadEnvFile({ envPath: globalPath });
@@ -3350,26 +3370,38 @@ function errorMessage(error) {
3350
3370
  }
3351
3371
 
3352
3372
  // src/authContext.ts
3373
+ class AuthContextUnavailableError extends Error {
3374
+ instructionContext;
3375
+ sessionHint;
3376
+ errorCode = "authentication_required";
3377
+ retry = "RetryWillNotFix";
3378
+ constructor(message, instructionContext = "auth", sessionHint) {
3379
+ super(message);
3380
+ this.instructionContext = instructionContext;
3381
+ this.sessionHint = sessionHint;
3382
+ this.name = "AuthContextUnavailableError";
3383
+ }
3384
+ }
3353
3385
  var getAuthContext = async (options = {}) => {
3354
3386
  const status = await getLoginStatusAsync({
3355
3387
  ensureTokenValidityMinutes: options.ensureTokenValidityMinutes,
3356
3388
  envFilePath: options.envFilePath
3357
3389
  });
3358
3390
  if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
3359
- throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
3391
+ throw new AuthContextUnavailableError(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.", "auth", status.hint);
3360
3392
  }
3361
- const tenantName = options.tenant ?? status.tenantName;
3393
+ const tenantName = options.tenant || status.tenantName;
3362
3394
  if (options.requireOrganizationId && !status.organizationId) {
3363
- throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
3395
+ throw new AuthContextUnavailableError("Organization ID not available. Ensure you are logged in with an organization context.", "identity");
3364
3396
  }
3365
3397
  if (options.requireOrganizationName && !status.organizationName) {
3366
- throw new Error("Organization name not available. Ensure you are logged in with an organization context.");
3398
+ throw new AuthContextUnavailableError("Organization name not available. Ensure you are logged in with an organization context.", "identity");
3367
3399
  }
3368
3400
  if (options.requireTenantId && !status.tenantId) {
3369
- throw new Error("Tenant ID not available. Ensure UIPATH_TENANT_ID is set.");
3401
+ throw new AuthContextUnavailableError(`Tenant ID not available. Ensure UIPATH_TENANT_ID is set.${status.hint ? ` ${status.hint}` : ""}`, "identity", status.hint);
3370
3402
  }
3371
- if (options.requireTenantName && tenantName === undefined) {
3372
- throw new Error("Tenant not provided and UIPATH_TENANT_NAME not set. Run 'uip login' to select a tenant, or use 'uip login tenant set <tenant>' to switch tenants.");
3403
+ if (options.requireTenantName && !tenantName) {
3404
+ throw new AuthContextUnavailableError("Tenant not provided and UIPATH_TENANT_NAME not set. Run 'uip login' to select a tenant, or use 'uip login tenant set <tenant>' to switch tenants.", "identity");
3373
3405
  }
3374
3406
  return {
3375
3407
  baseUrl: status.baseUrl,
@@ -3395,7 +3427,7 @@ var getAuthEnv = async (options = {}) => {
3395
3427
  const org = status.organizationName || status.organizationId;
3396
3428
  const tenant = status.tenantName || status.tenantId;
3397
3429
  if (org && tenant) {
3398
- authEnv.UIPATH_URL = `${status.baseUrl.replace(/\/+$/, "")}/${org}/${tenant}`;
3430
+ authEnv.UIPATH_URL = `${status.baseUrl.replace(/\/+$/, "")}/${encodeURIComponent(org)}/${encodeURIComponent(tenant)}`;
3399
3431
  }
3400
3432
  }
3401
3433
  if (status.organizationId)
@@ -3437,8 +3469,8 @@ async function describeAuthProfileAsync(name, filePath, active) {
3437
3469
  if (!filePath) {
3438
3470
  return { ...base, status: "Not logged in" };
3439
3471
  }
3440
- const fs7 = getFileSystem();
3441
- const [readError, content] = await catchError(fs7.readFile(filePath, "utf-8"));
3472
+ const fs = getFileSystem();
3473
+ const [readError, content] = await catchError(fs.readFile(filePath, "utf-8"));
3442
3474
  if (readError) {
3443
3475
  return { ...base, status: "Unreadable" };
3444
3476
  }
@@ -3730,7 +3762,7 @@ var interactiveLoginWithDeps = async (options, deps) => {
3730
3762
  getFs = getFileSystem,
3731
3763
  jwtParser = parseJWT,
3732
3764
  issuerAsserter = assertIssuerMatchesAuthority,
3733
- tenantSelector = (baseUrl, accessToken, organizationId, tenantName, interactive2) => selectTenantWithDeps(baseUrl, accessToken, organizationId, tenantName, interactive2, { selectFromList: options.selectFromList })
3765
+ tenantSelector = (baseUrl, accessToken, organizationId, tenantName, interactive) => selectTenantWithDeps(baseUrl, accessToken, organizationId, tenantName, interactive, { selectFromList: options.selectFromList })
3734
3766
  } = deps;
3735
3767
  const {
3736
3768
  envFilePath,
@@ -3843,15 +3875,15 @@ var interactiveLoginWithDeps = async (options, deps) => {
3843
3875
  }
3844
3876
  throw error;
3845
3877
  }
3846
- const fs7 = getFs();
3878
+ const fs = getFs();
3847
3879
  const requestedPath = envFilePath ?? DEFAULT_ENV_FILENAME;
3848
3880
  let savePath = requestedPath;
3849
3881
  let savedLocally = false;
3850
- if (!fs7.path.isAbsolute(savePath)) {
3851
- let searchDir = fs7.env.cwd();
3882
+ if (!fs.path.isAbsolute(savePath)) {
3883
+ let searchDir = fs.env.cwd();
3852
3884
  while (true) {
3853
- const candidate = fs7.path.join(searchDir, savePath);
3854
- if (await fs7.exists(candidate)) {
3885
+ const candidate = fs.path.join(searchDir, savePath);
3886
+ if (await fs.exists(candidate)) {
3855
3887
  try {
3856
3888
  const existing = await loadEnvFile({
3857
3889
  envPath: candidate
@@ -3863,17 +3895,21 @@ var interactiveLoginWithDeps = async (options, deps) => {
3863
3895
  }
3864
3896
  } catch {}
3865
3897
  }
3866
- const parentDir = fs7.path.dirname(searchDir);
3898
+ const parentDir = fs.path.dirname(searchDir);
3867
3899
  if (parentDir === searchDir) {
3868
3900
  break;
3869
3901
  }
3870
3902
  searchDir = parentDir;
3871
3903
  }
3872
3904
  }
3905
+ if (!fs.path.isAbsolute(savePath)) {
3906
+ savePath = fs.path.join(fs.env.homedir(), savePath);
3907
+ }
3873
3908
  let saveRelease;
3874
3909
  try {
3875
- if (typeof fs7.acquireLock === "function") {
3876
- saveRelease = await fs7.acquireLock(savePath);
3910
+ await fs.mkdir(fs.path.dirname(savePath));
3911
+ if (typeof fs.acquireLock === "function") {
3912
+ saveRelease = await fs.acquireLock(savePath);
3877
3913
  }
3878
3914
  } catch {
3879
3915
  saveRelease = undefined;
@@ -3889,10 +3925,9 @@ var interactiveLoginWithDeps = async (options, deps) => {
3889
3925
  await saveRelease().catch(() => {});
3890
3926
  }
3891
3927
  }
3892
- const reportedPath = fs7.path.isAbsolute(savePath) ? savePath : fs7.path.join(fs7.env.homedir(), savePath);
3893
3928
  emit({
3894
3929
  type: "saved",
3895
- path: reportedPath,
3930
+ path: savePath,
3896
3931
  locality: savedLocally ? "local" : "global"
3897
3932
  });
3898
3933
  return credentials;
@@ -3909,19 +3944,19 @@ async function logoutWithDeps(options, deps = {}) {
3909
3944
  clearBreaker = clearRefreshBreaker,
3910
3945
  getActiveProfileFilePath = getActiveAuthProfileFilePath
3911
3946
  } = deps;
3912
- const fs7 = getFs();
3947
+ const fs = getFs();
3913
3948
  const { absolutePath } = await resolveEnvFilePath(options.file ?? getActiveProfileFilePath());
3914
- if (absolutePath && await fs7.exists(absolutePath)) {
3949
+ if (absolutePath && await fs.exists(absolutePath)) {
3915
3950
  let release;
3916
3951
  try {
3917
- if (typeof fs7.acquireLock === "function") {
3918
- release = await fs7.acquireLock(absolutePath);
3952
+ if (typeof fs.acquireLock === "function") {
3953
+ release = await fs.acquireLock(absolutePath);
3919
3954
  }
3920
3955
  } catch {
3921
3956
  release = undefined;
3922
3957
  }
3923
3958
  try {
3924
- await fs7.rm(absolutePath);
3959
+ await fs.rm(absolutePath);
3925
3960
  await clearBreaker(absolutePath);
3926
3961
  } finally {
3927
3962
  if (release) {
@@ -4000,11 +4035,11 @@ var authenticate = async ({
4000
4035
  const authUrl = `${authorizationEndpoint}?${authParams.toString()}`;
4001
4036
  let strategy;
4002
4037
  if (isBrowser()) {
4003
- const { BrowserAuthStrategy: BrowserAuthStrategy2 } = await Promise.resolve().then(() => (init_browser_strategy(), exports_browser_strategy));
4004
- strategy = new BrowserAuthStrategy2;
4038
+ await Promise.resolve().then(() => init_browser_strategy());
4039
+ strategy = new BrowserAuthStrategy;
4005
4040
  } else {
4006
- const { NodeAuthStrategy: NodeAuthStrategy2 } = await Promise.resolve().then(() => (init_node_strategy(), exports_node_strategy));
4007
- strategy = new NodeAuthStrategy2;
4041
+ await Promise.resolve().then(() => init_node_strategy());
4042
+ strategy = new NodeAuthStrategy;
4008
4043
  }
4009
4044
  const code = await strategy.execute(authUrl, effectiveRedirectUriUrl, state, {
4010
4045
  timeoutMs,
@@ -4027,6 +4062,7 @@ export {
4027
4062
  AUTH_FLOW_ENV_VAR,
4028
4063
  AUTH_RECLAIMED_ERROR_CODE,
4029
4064
  AUTH_TIMEOUT_ERROR_CODE,
4065
+ AuthContextUnavailableError,
4030
4066
  AuthProfileValidationError,
4031
4067
  ClientCredentialsAuthenticationError,
4032
4068
  CredentialSource,
@@ -4039,6 +4075,7 @@ export {
4039
4075
  ENV_AUTH_VARS,
4040
4076
  EnvAuthConfigError,
4041
4077
  FederatedCredentialsAuthenticationError,
4078
+ INHERITED_AUTH_PROFILE_ENV,
4042
4079
  INVALID_TENANT_CODE,
4043
4080
  InvalidBaseUrlError,
4044
4081
  InvalidTenantError,
@@ -4097,4 +4134,4 @@ export {
4097
4134
  setAuthFileConfig
4098
4135
  };
4099
4136
 
4100
- //# debugId=3C4FEB497AB4F8C264756E2164756E21
4137
+ //# debugId=2274E68B50F5117E64756E2164756E21