@uipath/insights-sdk 1.1.0 → 1.195.0

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.
Files changed (2) hide show
  1. package/dist/index.js +435 -115
  2. package/package.json +26 -31
package/dist/index.js CHANGED
@@ -667,6 +667,7 @@ var init_open = __esm(() => {
667
667
  });
668
668
 
669
669
  // ../filesystem/src/node.ts
670
+ import { randomUUID } from "node:crypto";
670
671
  import { existsSync } from "node:fs";
671
672
  import * as fs6 from "node:fs/promises";
672
673
  import * as os2 from "node:os";
@@ -748,6 +749,90 @@ class NodeFileSystem {
748
749
  async mkdir(dirPath) {
749
750
  await fs6.mkdir(dirPath, { recursive: true });
750
751
  }
752
+ async acquireLock(lockPath) {
753
+ const canonicalPath = await this.canonicalizeLockTarget(lockPath);
754
+ const lockFile = `${canonicalPath}.lock`;
755
+ const ownerId = randomUUID();
756
+ const start = Date.now();
757
+ while (true) {
758
+ try {
759
+ await fs6.writeFile(lockFile, ownerId, { flag: "wx" });
760
+ return this.createLockRelease(lockFile, ownerId);
761
+ } catch (error) {
762
+ if (!this.hasErrnoCode(error, "EEXIST")) {
763
+ throw error;
764
+ }
765
+ const stats = await fs6.stat(lockFile).catch(() => null);
766
+ if (stats && Date.now() - stats.mtimeMs > LOCK_STALE_MS) {
767
+ const reclaimed = await fs6.rm(lockFile, { force: true }).then(() => true).catch(() => false);
768
+ if (reclaimed)
769
+ continue;
770
+ }
771
+ if (Date.now() - start > LOCK_MAX_WAIT_MS) {
772
+ throw new Error(`ELOCKED: timed out waiting for lock on ${canonicalPath}`);
773
+ }
774
+ await new Promise((resolve2) => setTimeout(resolve2, LOCK_RETRY_MIN_MS + Math.random() * LOCK_RETRY_JITTER_MS));
775
+ }
776
+ }
777
+ }
778
+ async canonicalizeLockTarget(lockPath) {
779
+ const absolute = path2.resolve(lockPath);
780
+ const fullReal = await fs6.realpath(absolute).catch(() => null);
781
+ if (fullReal)
782
+ return fullReal;
783
+ const parent = path2.dirname(absolute);
784
+ const base = path2.basename(absolute);
785
+ const canonicalParent = await fs6.realpath(parent).catch(() => parent);
786
+ return path2.join(canonicalParent, base);
787
+ }
788
+ createLockRelease(lockFile, ownerId) {
789
+ const heartbeatStart = Date.now();
790
+ let heartbeatTimer;
791
+ let stopped = false;
792
+ const stopHeartbeat = () => {
793
+ stopped = true;
794
+ if (heartbeatTimer)
795
+ clearTimeout(heartbeatTimer);
796
+ };
797
+ const scheduleNextHeartbeat = () => {
798
+ if (stopped)
799
+ return;
800
+ if (Date.now() - heartbeatStart >= LOCK_MAX_HOLD_MS) {
801
+ stopped = true;
802
+ return;
803
+ }
804
+ heartbeatTimer = setTimeout(() => {
805
+ runHeartbeat();
806
+ }, LOCK_HEARTBEAT_MS);
807
+ heartbeatTimer.unref?.();
808
+ };
809
+ const runHeartbeat = async () => {
810
+ if (stopped)
811
+ return;
812
+ const current = await fs6.readFile(lockFile, "utf-8").catch(() => null);
813
+ if (stopped)
814
+ return;
815
+ if (current !== ownerId) {
816
+ stopped = true;
817
+ return;
818
+ }
819
+ const now = Date.now() / 1000;
820
+ await fs6.utimes(lockFile, now, now).catch(() => {});
821
+ scheduleNextHeartbeat();
822
+ };
823
+ scheduleNextHeartbeat();
824
+ let released = false;
825
+ return async () => {
826
+ if (released)
827
+ return;
828
+ released = true;
829
+ stopHeartbeat();
830
+ const current = await fs6.readFile(lockFile, "utf-8").catch(() => null);
831
+ if (current === ownerId) {
832
+ await fs6.rm(lockFile, { force: true });
833
+ }
834
+ };
835
+ }
751
836
  async rm(filePath) {
752
837
  await fs6.rm(filePath, { recursive: true, force: true });
753
838
  }
@@ -793,9 +878,13 @@ class NodeFileSystem {
793
878
  }
794
879
  }
795
880
  isEnoent(error) {
796
- return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
881
+ return this.hasErrnoCode(error, "ENOENT");
882
+ }
883
+ hasErrnoCode(error, code) {
884
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
797
885
  }
798
886
  }
887
+ 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;
799
888
  var init_node = __esm(() => {
800
889
  init_open();
801
890
  });
@@ -2941,7 +3030,7 @@ function isBrowser() {
2941
3030
 
2942
3031
  // ../../node_modules/@uipath/coreipc/index.js
2943
3032
  var require_coreipc = __commonJS((exports, module) => {
2944
- var __dirname = "/Users/alexandru.oltean/github/cli/node_modules/@uipath/coreipc";
3033
+ var __dirname = "/home/runner/work/cli/cli/node_modules/@uipath/coreipc";
2945
3034
  /*! For license information please see index.js.LICENSE.txt */
2946
3035
  (function(e, t) {
2947
3036
  typeof exports == "object" && typeof module == "object" ? module.exports = t() : typeof define == "function" && define.amd ? define([], t) : typeof exports == "object" ? exports.ipc = t() : e.ipc = t();
@@ -21133,6 +21222,10 @@ var require_dist = __commonJS((exports) => {
21133
21222
  exports.RobotProxyConstructor = RobotProxyConstructor;
21134
21223
  __exportStar(require_agent(), exports);
21135
21224
  });
21225
+ // ../auth/src/server.ts
21226
+ var init_server = __esm(() => {
21227
+ init_constants();
21228
+ });
21136
21229
 
21137
21230
  // ../common/src/attachment-binding.ts
21138
21231
  init_src();
@@ -26305,6 +26398,60 @@ function escapeNonAscii(jsonText) {
26305
26398
  function needsAsciiSafeJson(sink) {
26306
26399
  return process.platform === "win32" && !sink.capabilities.isInteractive;
26307
26400
  }
26401
+ function isPlainRecord(value) {
26402
+ if (value === null || typeof value !== "object")
26403
+ return false;
26404
+ const prototype = Object.getPrototypeOf(value);
26405
+ return prototype === Object.prototype || prototype === null;
26406
+ }
26407
+ function toLowerCamelCaseKey(key) {
26408
+ if (!key)
26409
+ return key;
26410
+ if (/[_\-\s]/.test(key)) {
26411
+ const [firstPart, ...restParts] = key.split(/[_\-\s]+/).filter(Boolean);
26412
+ if (!firstPart)
26413
+ return key;
26414
+ return [
26415
+ toLowerCamelCaseSimpleKey(firstPart),
26416
+ ...restParts.map((part) => {
26417
+ const normalized = toLowerCamelCaseSimpleKey(part);
26418
+ return normalized.charAt(0).toUpperCase() + normalized.slice(1);
26419
+ })
26420
+ ].join("");
26421
+ }
26422
+ return toLowerCamelCaseSimpleKey(key);
26423
+ }
26424
+ function toLowerCamelCaseSimpleKey(key) {
26425
+ if (/^[A-Z0-9]+$/.test(key))
26426
+ return key.toLowerCase();
26427
+ return key.replace(/^[A-Z]+(?=[A-Z][a-z]|\d|$)|^[A-Z]/, (match) => match.toLowerCase());
26428
+ }
26429
+ function toPascalCaseKey(key) {
26430
+ const lowerCamelKey = toLowerCamelCaseKey(key);
26431
+ return lowerCamelKey ? lowerCamelKey.charAt(0).toUpperCase() + lowerCamelKey.slice(1) : lowerCamelKey;
26432
+ }
26433
+ function toPascalCaseData(value) {
26434
+ if (Array.isArray(value))
26435
+ return value.map(toPascalCaseData);
26436
+ if (!isPlainRecord(value))
26437
+ return value;
26438
+ const result = {};
26439
+ for (const [key, nestedValue] of Object.entries(value)) {
26440
+ result[toPascalCaseKey(key)] = toPascalCaseData(nestedValue);
26441
+ }
26442
+ return result;
26443
+ }
26444
+ function normalizeDataKeys(data) {
26445
+ return toPascalCaseData(data);
26446
+ }
26447
+ function normalizeOutputKeys(data) {
26448
+ const result = {};
26449
+ for (const [key, value] of Object.entries(data)) {
26450
+ const pascalKey = toPascalCaseKey(key);
26451
+ result[pascalKey] = pascalKey === "Data" ? value : toPascalCaseData(value);
26452
+ }
26453
+ return result;
26454
+ }
26308
26455
  function printOutput(data, format = "json", logFn, asciiSafe = false) {
26309
26456
  if (!data) {
26310
26457
  logFn("Empty response object. No data to display.");
@@ -26367,7 +26514,7 @@ function wrapText(text, width) {
26367
26514
  function printTable(data, logFn, externalLogValue) {
26368
26515
  if (data.length === 0)
26369
26516
  return;
26370
- const keys = Object.keys(data[0]).filter((key) => key !== "Code" && key !== "Log");
26517
+ const keys = Object.keys(data[0]).filter((key) => !["code", "log"].includes(key.toLowerCase()));
26371
26518
  const maxWidths = keys.map((key) => Math.max(key.length, ...data.map((item) => cellToString(item[key]).length)));
26372
26519
  const header = keys.map((key, i2) => key.padEnd(maxWidths[i2])).join(" | ");
26373
26520
  logFn(header);
@@ -26382,7 +26529,7 @@ function printTable(data, logFn, externalLogValue) {
26382
26529
  }
26383
26530
  }
26384
26531
  function printVerticalTable(data, logFn = console.log, externalLogValue) {
26385
- const keys = Object.keys(data).filter((key) => key !== "Code" && key !== "Log");
26532
+ const keys = Object.keys(data).filter((key) => !["code", "log"].includes(key.toLowerCase()));
26386
26533
  if (keys.length === 0)
26387
26534
  return;
26388
26535
  const maxKeyWidth = Math.max(...keys.map((key) => key.length));
@@ -26398,7 +26545,7 @@ function printVerticalTable(data, logFn = console.log, externalLogValue) {
26398
26545
  function printResizableTable(data, logFn = console.log, externalLogValue) {
26399
26546
  if (data.length === 0)
26400
26547
  return;
26401
- const keys = Object.keys(data[0]).filter((key) => key !== "Code" && key !== "Log");
26548
+ const keys = Object.keys(data[0]).filter((key) => !["code", "log"].includes(key.toLowerCase()));
26402
26549
  if (keys.length === 0)
26403
26550
  return;
26404
26551
  if (!process.stdout.isTTY) {
@@ -26474,8 +26621,26 @@ function printResizableTable(data, logFn = console.log, externalLogValue) {
26474
26621
  function toYaml(data) {
26475
26622
  return dump(data);
26476
26623
  }
26624
+ class FilterEvaluationError extends Error {
26625
+ __brand = "FilterEvaluationError";
26626
+ filter;
26627
+ instructions;
26628
+ result = RESULTS.ValidationError;
26629
+ constructor(filter, cause) {
26630
+ const underlying = cause instanceof Error ? cause.message : String(cause);
26631
+ super(`Filter '${filter}' failed to evaluate: ${underlying}`);
26632
+ this.name = "FilterEvaluationError";
26633
+ this.filter = filter;
26634
+ this.instructions = `The --output-filter expression '${filter}' failed at evaluation time. ` + "Note that --output-filter operates on the 'Data' field of the envelope, not the full object. " + "For example, on a list result use 'length(@)' instead of 'Data | length(@)'.";
26635
+ }
26636
+ }
26477
26637
  function applyFilter(data, filter) {
26478
- const result = search(data, filter);
26638
+ let result;
26639
+ try {
26640
+ result = search(data, filter);
26641
+ } catch (err) {
26642
+ throw new FilterEvaluationError(filter, err);
26643
+ }
26479
26644
  if (result == null)
26480
26645
  return [];
26481
26646
  if (Array.isArray(result)) {
@@ -26492,13 +26657,18 @@ function applyFilter(data, filter) {
26492
26657
  }
26493
26658
  var OutputFormatter;
26494
26659
  ((OutputFormatter) => {
26495
- function success(data) {
26660
+ function success(data, options) {
26496
26661
  data.Log ??= getLogFilePath() || undefined;
26662
+ const normalize = !options?.preserveDataKeys;
26663
+ if (normalize) {
26664
+ data.Data = normalizeDataKeys(data.Data);
26665
+ }
26497
26666
  const filter = getOutputFilter();
26498
26667
  if (filter) {
26499
- data.Data = applyFilter(data.Data, filter);
26668
+ const filtered = applyFilter(data.Data, filter);
26669
+ data.Data = normalize ? normalizeDataKeys(filtered) : filtered;
26500
26670
  }
26501
- logOutput(data, getOutputFormat());
26671
+ logOutput(normalizeOutputKeys(data), getOutputFormat());
26502
26672
  }
26503
26673
  OutputFormatter.success = success;
26504
26674
  function error(data) {
@@ -26508,7 +26678,7 @@ var OutputFormatter;
26508
26678
  result: data.Result,
26509
26679
  message: data.Message
26510
26680
  });
26511
- logOutput(data, getOutputFormat());
26681
+ logOutput(normalizeOutputKeys(data), getOutputFormat());
26512
26682
  }
26513
26683
  OutputFormatter.error = error;
26514
26684
  function emitList(code, items, opts) {
@@ -26529,13 +26699,14 @@ var OutputFormatter;
26529
26699
  function log(data) {
26530
26700
  const format = getOutputFormat();
26531
26701
  const sink = getOutputSink();
26702
+ const normalized = toPascalCaseData(data);
26532
26703
  if (format === "json") {
26533
- const json2 = JSON.stringify(data);
26704
+ const json2 = JSON.stringify(normalized);
26534
26705
  const safe = needsAsciiSafeJson(sink) ? escapeNonAscii(json2) : json2;
26535
26706
  sink.writeErr(`${safe}
26536
26707
  `);
26537
26708
  } else {
26538
- for (const [key, value] of Object.entries(data)) {
26709
+ for (const [key, value] of Object.entries(normalized)) {
26539
26710
  sink.writeErr(`${key}: ${value}
26540
26711
  `);
26541
26712
  }
@@ -26544,12 +26715,16 @@ var OutputFormatter;
26544
26715
  OutputFormatter.log = log;
26545
26716
  function formatToString(data) {
26546
26717
  const filter = getOutputFilter();
26547
- if (filter && "Data" in data && data.Data != null) {
26548
- data.Data = applyFilter(data.Data, filter);
26718
+ if ("Data" in data && data.Data != null) {
26719
+ data.Data = normalizeDataKeys(data.Data);
26720
+ if (filter) {
26721
+ data.Data = normalizeDataKeys(applyFilter(data.Data, filter));
26722
+ }
26549
26723
  }
26724
+ const output = normalizeOutputKeys(data);
26550
26725
  const lines = [];
26551
26726
  const sink = getOutputSink();
26552
- printOutput(data, getOutputFormat(), (msg) => {
26727
+ printOutput(output, getOutputFormat(), (msg) => {
26553
26728
  lines.push(msg);
26554
26729
  }, needsAsciiSafeJson(sink));
26555
26730
  return lines.join(`
@@ -27960,6 +28135,22 @@ JSONPath.prototype.safeVm = {
27960
28135
  Script: SafeScript
27961
28136
  };
27962
28137
  JSONPath.prototype.vm = vm;
28138
+ // ../common/src/polling/types.ts
28139
+ var PollOutcome = {
28140
+ Completed: "completed",
28141
+ Timeout: "timeout",
28142
+ Interrupted: "interrupted",
28143
+ Aborted: "aborted",
28144
+ Failed: "failed"
28145
+ };
28146
+
28147
+ // ../common/src/polling/poll-failure-mapping.ts
28148
+ var REASON_BY_OUTCOME = {
28149
+ [PollOutcome.Timeout]: "poll_timeout",
28150
+ [PollOutcome.Failed]: "poll_failed",
28151
+ [PollOutcome.Interrupted]: "poll_failed",
28152
+ [PollOutcome.Aborted]: "poll_aborted"
28153
+ };
27963
28154
  // ../common/src/polling/terminal-statuses.ts
27964
28155
  var TERMINAL_STATUSES = new Set([
27965
28156
  "completed",
@@ -27987,6 +28178,8 @@ var ScreenLogger;
27987
28178
  }
27988
28179
  ScreenLogger.progress = progress;
27989
28180
  })(ScreenLogger ||= {});
28181
+ // ../common/src/sdk-user-agent.ts
28182
+ var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
27990
28183
  // ../common/src/tool-provider.ts
27991
28184
  var factorySlot = singleton("PackagerFactoryProvider");
27992
28185
  // ../common/src/telemetry/pii-redactor.ts
@@ -28161,13 +28354,17 @@ Command.prototype.trackedAction = function(context, fn, properties) {
28161
28354
  const [error] = await catchError(fn(...args));
28162
28355
  if (error) {
28163
28356
  errorMessage = error instanceof Error ? error.message : String(error);
28164
- logger.error(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
28357
+ logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
28358
+ const typed = error;
28359
+ const customInstructions = typeof typed.instructions === "string" ? typed.instructions : undefined;
28360
+ const customResult = typeof typed.result === "string" && typed.result !== RESULTS.Success && Object.values(RESULTS).includes(typed.result) ? typed.result : undefined;
28361
+ const finalResult = customResult ?? RESULTS.Failure;
28165
28362
  OutputFormatter.error({
28166
- Result: RESULTS.Failure,
28363
+ Result: finalResult,
28167
28364
  Message: errorMessage,
28168
- Instructions: "An unexpected error occurred. Run with --log-level debug for details."
28365
+ Instructions: customInstructions ?? "An unexpected error occurred. Run with --log-level debug for details."
28169
28366
  });
28170
- context.exit(1);
28367
+ context.exit(EXIT_CODES[finalResult]);
28171
28368
  }
28172
28369
  const durationMs = performance.now() - startTime;
28173
28370
  const success = !error && (process.exitCode === undefined || process.exitCode === 0);
@@ -28238,32 +28435,7 @@ class InvalidBaseUrlError extends Error {
28238
28435
  this.name = "InvalidBaseUrlError";
28239
28436
  }
28240
28437
  }
28241
- var DEFAULT_SCOPES = [
28242
- "offline_access",
28243
- "ProcessMining",
28244
- "OrchestratorApiUserAccess",
28245
- "StudioWebBackend",
28246
- "IdentityServerApi",
28247
- "ConnectionService",
28248
- "DataService",
28249
- "DataServiceApiUserAccess",
28250
- "DocumentUnderstanding",
28251
- "EnterpriseContextService",
28252
- "Directory",
28253
- "JamJamApi",
28254
- "LLMGateway",
28255
- "LLMOps",
28256
- "OMS",
28257
- "RCS.FolderAuthorization",
28258
- "RCS.TagsManagement",
28259
- "TestmanagerApiUserAccess",
28260
- "AutomationSolutions",
28261
- "StudioWebTypeCacheService",
28262
- "Docs.GPT.Search",
28263
- "Insights",
28264
- "ReferenceToken",
28265
- "Audit.Read"
28266
- ];
28438
+ var DEFAULT_SCOPES = ["openid", "profile", "offline_access"];
28267
28439
  var normalizeAndValidateBaseUrl = (rawUrl) => {
28268
28440
  let baseUrl = rawUrl;
28269
28441
  if (baseUrl.endsWith("/identity_/")) {
@@ -28313,7 +28485,8 @@ var resolveConfigAsync = async ({
28313
28485
  if (!clientSecret && fileAuth.clientSecret) {
28314
28486
  clientSecret = fileAuth.clientSecret;
28315
28487
  }
28316
- const scopes = customScopes && customScopes.length > 0 ? customScopes : fileAuth.scopes && fileAuth.scopes.length > 0 ? fileAuth.scopes : DEFAULT_SCOPES;
28488
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && Boolean(clientSecret);
28489
+ const scopes = customScopes && customScopes.length > 0 ? customScopes : fileAuth.scopes && fileAuth.scopes.length > 0 ? fileAuth.scopes : isExternalAppAuth ? [] : DEFAULT_SCOPES;
28317
28490
  return {
28318
28491
  clientId,
28319
28492
  clientSecret,
@@ -28813,6 +28986,129 @@ function normalizeTokenRefreshFailure() {
28813
28986
  function normalizeTokenRefreshUnavailableFailure() {
28814
28987
  return "token refresh failed before authentication completed";
28815
28988
  }
28989
+ function errorMessage(error) {
28990
+ return error instanceof Error ? error.message : String(error);
28991
+ }
28992
+ function computeExpirationThreshold(ensureTokenValidityMinutes) {
28993
+ return new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
28994
+ }
28995
+ async function runRefreshLocked(inputs) {
28996
+ const {
28997
+ absolutePath,
28998
+ refreshToken: callerRefreshToken,
28999
+ customAuthority,
29000
+ ensureTokenValidityMinutes,
29001
+ loadEnvFile,
29002
+ saveEnvFile,
29003
+ refreshFn,
29004
+ resolveConfig
29005
+ } = inputs;
29006
+ const expirationThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
29007
+ let fresh;
29008
+ try {
29009
+ fresh = await loadEnvFile({ envPath: absolutePath });
29010
+ } catch (error) {
29011
+ return {
29012
+ kind: "fail",
29013
+ status: {
29014
+ loginStatus: "Refresh Failed",
29015
+ hint: "Could not read the auth file while refreshing. Retry, or run 'uip login' to re-authenticate.",
29016
+ tokenRefresh: {
29017
+ attempted: false,
29018
+ success: false,
29019
+ errorMessage: `auth file read failed: ${errorMessage(error)}`
29020
+ }
29021
+ }
29022
+ };
29023
+ }
29024
+ const freshAccess = fresh.UIPATH_ACCESS_TOKEN;
29025
+ const freshExp = freshAccess ? getTokenExpiration(freshAccess) : undefined;
29026
+ if (freshAccess && freshExp && freshExp > expirationThreshold) {
29027
+ return {
29028
+ kind: "ok",
29029
+ accessToken: freshAccess,
29030
+ refreshToken: fresh.UIPATH_REFRESH_TOKEN ?? callerRefreshToken,
29031
+ expiration: freshExp,
29032
+ tokenRefresh: { attempted: false, success: true }
29033
+ };
29034
+ }
29035
+ const tokenForIdP = fresh.UIPATH_REFRESH_TOKEN ?? callerRefreshToken;
29036
+ let refreshedAccess;
29037
+ let refreshedRefresh;
29038
+ try {
29039
+ const config = await resolveConfig({ customAuthority });
29040
+ const refreshed = await refreshFn({
29041
+ refreshToken: tokenForIdP,
29042
+ tokenEndpoint: config.tokenEndpoint,
29043
+ clientId: config.clientId,
29044
+ expectedAuthority: customAuthority
29045
+ });
29046
+ refreshedAccess = refreshed.accessToken;
29047
+ refreshedRefresh = refreshed.refreshToken;
29048
+ } catch (error) {
29049
+ const isOAuthFailure = isTokenRefreshOAuthFailure(error);
29050
+ const hint = isOAuthFailure ? "Run 'uip login' to re-authenticate — the stored refresh token is invalid or expired." : "Token refresh failed. Check your network connection, then retry or run 'uip login' to re-authenticate.";
29051
+ const message = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
29052
+ return {
29053
+ kind: "fail",
29054
+ status: {
29055
+ loginStatus: "Refresh Failed",
29056
+ hint,
29057
+ tokenRefresh: {
29058
+ attempted: true,
29059
+ success: false,
29060
+ errorMessage: message
29061
+ }
29062
+ }
29063
+ };
29064
+ }
29065
+ const refreshedExp = getTokenExpiration(refreshedAccess);
29066
+ if (!refreshedExp || refreshedExp <= new Date) {
29067
+ return {
29068
+ kind: "fail",
29069
+ status: {
29070
+ loginStatus: "Refresh Failed",
29071
+ hint: "The identity server returned an unusable token. Run 'uip login' to re-authenticate.",
29072
+ tokenRefresh: {
29073
+ attempted: true,
29074
+ success: false,
29075
+ errorMessage: "refreshed token has no valid expiration claim"
29076
+ }
29077
+ }
29078
+ };
29079
+ }
29080
+ try {
29081
+ await saveEnvFile({
29082
+ envPath: absolutePath,
29083
+ data: {
29084
+ UIPATH_ACCESS_TOKEN: refreshedAccess,
29085
+ UIPATH_REFRESH_TOKEN: refreshedRefresh
29086
+ },
29087
+ merge: true
29088
+ });
29089
+ return {
29090
+ kind: "ok",
29091
+ accessToken: refreshedAccess,
29092
+ refreshToken: refreshedRefresh,
29093
+ expiration: refreshedExp,
29094
+ tokenRefresh: { attempted: true, success: true }
29095
+ };
29096
+ } catch (error) {
29097
+ const msg = errorMessage(error);
29098
+ return {
29099
+ kind: "ok",
29100
+ accessToken: refreshedAccess,
29101
+ refreshToken: refreshedRefresh,
29102
+ expiration: refreshedExp,
29103
+ persistenceWarning: `Access token refreshed in memory but could not be written to ${absolutePath}: ${msg}. The next CLI invocation will fail until the file can be updated — run 'uip login' to re-authenticate.`,
29104
+ tokenRefresh: {
29105
+ attempted: true,
29106
+ success: true,
29107
+ errorMessage: `persistence failed: ${msg}`
29108
+ }
29109
+ };
29110
+ }
29111
+ }
28816
29112
  var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
28817
29113
  const {
28818
29114
  resolveEnvFilePath = resolveEnvFilePathAsync,
@@ -28887,73 +29183,103 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
28887
29183
  let refreshToken = credentials.UIPATH_REFRESH_TOKEN;
28888
29184
  let expiration = getTokenExpiration(accessToken);
28889
29185
  let persistenceWarning;
29186
+ let lockReleaseFailed = false;
28890
29187
  let tokenRefresh;
28891
- const expirationThreshold = new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
28892
- if (expiration && expiration <= expirationThreshold && refreshToken) {
28893
- let refreshedAccess;
28894
- let refreshedRefresh;
29188
+ const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
29189
+ const tryGlobalCredsHint = async () => {
29190
+ const fs7 = getFs();
29191
+ const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
29192
+ if (absolutePath === globalPath)
29193
+ return;
29194
+ if (!await fs7.exists(globalPath))
29195
+ return;
28895
29196
  try {
28896
- const config = await resolveConfig({
28897
- customAuthority: credentials.UIPATH_URL
28898
- });
28899
- const refreshed = await refreshTokenFn({
28900
- refreshToken,
28901
- tokenEndpoint: config.tokenEndpoint,
28902
- clientId: config.clientId,
28903
- expectedAuthority: credentials.UIPATH_URL
28904
- });
28905
- refreshedAccess = refreshed.accessToken;
28906
- refreshedRefresh = refreshed.refreshToken;
28907
- } catch (error) {
28908
- const isOAuthFailure = isTokenRefreshOAuthFailure(error);
28909
- const hint = isOAuthFailure ? "Run 'uip login' to re-authenticate — the stored refresh token is invalid or expired." : "Token refresh failed. Check your network connection, then retry or run 'uip login' to re-authenticate.";
28910
- const errorMessage = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
28911
- return {
28912
- loginStatus: "Refresh Failed",
28913
- hint,
28914
- tokenRefresh: {
28915
- attempted: true,
28916
- success: false,
28917
- errorMessage
28918
- }
28919
- };
29197
+ const globalCreds = await loadEnvFile({ envPath: globalPath });
29198
+ if (!globalCreds.UIPATH_ACCESS_TOKEN)
29199
+ return;
29200
+ const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
29201
+ if (globalExp && globalExp <= new Date)
29202
+ return;
29203
+ return `Local credentials file at ${absolutePath} has expired credentials. Valid credentials exist in ${globalPath}. Remove the local file or run 'uip login' to re-authenticate.`;
29204
+ } catch {
29205
+ return;
28920
29206
  }
28921
- const refreshedExp = getTokenExpiration(refreshedAccess);
28922
- if (!refreshedExp || refreshedExp <= new Date) {
29207
+ };
29208
+ if (expiration && expiration <= outerThreshold && refreshToken) {
29209
+ let release;
29210
+ try {
29211
+ release = await getFs().acquireLock(absolutePath);
29212
+ } catch (error) {
29213
+ const msg = errorMessage(error);
29214
+ const globalHint = await tryGlobalCredsHint();
29215
+ if (globalHint) {
29216
+ return {
29217
+ loginStatus: "Expired",
29218
+ accessToken,
29219
+ refreshToken,
29220
+ baseUrl: credentials.UIPATH_URL,
29221
+ organizationName: credentials.UIPATH_ORGANIZATION_NAME,
29222
+ organizationId: credentials.UIPATH_ORGANIZATION_ID,
29223
+ tenantName: credentials.UIPATH_TENANT_NAME,
29224
+ tenantId: credentials.UIPATH_TENANT_ID,
29225
+ expiration,
29226
+ source: "file" /* File */,
29227
+ hint: globalHint,
29228
+ tokenRefresh: {
29229
+ attempted: false,
29230
+ success: false,
29231
+ errorMessage: `lock acquisition failed: ${msg}`
29232
+ }
29233
+ };
29234
+ }
28923
29235
  return {
28924
29236
  loginStatus: "Refresh Failed",
28925
- hint: "The identity server returned an unusable token. Run 'uip login' to re-authenticate.",
29237
+ hint: "Could not acquire the auth-file lock — too many concurrent `uip` processes, or a permission issue on the auth directory. Retry, or run 'uip login' to re-authenticate.",
28926
29238
  tokenRefresh: {
28927
- attempted: true,
29239
+ attempted: false,
28928
29240
  success: false,
28929
- errorMessage: "refreshed token has no valid expiration claim"
29241
+ errorMessage: `lock acquisition failed: ${msg}`
28930
29242
  }
28931
29243
  };
28932
29244
  }
28933
- accessToken = refreshedAccess;
28934
- refreshToken = refreshedRefresh;
28935
- expiration = refreshedExp;
29245
+ let lockedFailure;
28936
29246
  try {
28937
- await saveEnvFile({
28938
- envPath: absolutePath,
28939
- data: {
28940
- UIPATH_ACCESS_TOKEN: accessToken,
28941
- UIPATH_REFRESH_TOKEN: refreshToken
28942
- },
28943
- merge: true
29247
+ const outcome = await runRefreshLocked({
29248
+ absolutePath,
29249
+ refreshToken,
29250
+ customAuthority: credentials.UIPATH_URL,
29251
+ ensureTokenValidityMinutes,
29252
+ loadEnvFile,
29253
+ saveEnvFile,
29254
+ refreshFn: refreshTokenFn,
29255
+ resolveConfig
28944
29256
  });
28945
- tokenRefresh = {
28946
- attempted: true,
28947
- success: true
28948
- };
28949
- } catch (error) {
28950
- const msg = error instanceof Error ? error.message : String(error);
28951
- persistenceWarning = `Access token refreshed in memory but could not be written to ${absolutePath}: ${msg}. The next CLI invocation will fail until the file can be updated — run 'uip login' to re-authenticate.`;
28952
- tokenRefresh = {
28953
- attempted: true,
28954
- success: true,
28955
- errorMessage: `persistence failed: ${msg}`
28956
- };
29257
+ if (outcome.kind === "fail") {
29258
+ lockedFailure = outcome.status;
29259
+ } else {
29260
+ accessToken = outcome.accessToken;
29261
+ refreshToken = outcome.refreshToken;
29262
+ expiration = outcome.expiration;
29263
+ tokenRefresh = outcome.tokenRefresh;
29264
+ if (outcome.persistenceWarning) {
29265
+ persistenceWarning = outcome.persistenceWarning;
29266
+ }
29267
+ }
29268
+ } finally {
29269
+ try {
29270
+ await release();
29271
+ } catch {
29272
+ lockReleaseFailed = true;
29273
+ }
29274
+ }
29275
+ if (lockedFailure) {
29276
+ const globalHint = await tryGlobalCredsHint();
29277
+ const base = globalHint ? {
29278
+ ...lockedFailure,
29279
+ loginStatus: "Expired",
29280
+ hint: globalHint
29281
+ } : lockedFailure;
29282
+ return lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base;
28957
29283
  }
28958
29284
  }
28959
29285
  const result = {
@@ -28968,23 +29294,13 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
28968
29294
  expiration,
28969
29295
  source: "file" /* File */,
28970
29296
  ...persistenceWarning ? { hint: persistenceWarning, persistenceFailed: true } : {},
29297
+ ...lockReleaseFailed ? { lockReleaseFailed: true } : {},
28971
29298
  ...tokenRefresh ? { tokenRefresh } : {}
28972
29299
  };
28973
29300
  if (result.loginStatus === "Expired") {
28974
- const fs7 = getFs();
28975
- const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
28976
- if (absolutePath !== globalPath && await fs7.exists(globalPath)) {
28977
- try {
28978
- const globalCreds = await loadEnvFile({
28979
- envPath: globalPath
28980
- });
28981
- if (globalCreds.UIPATH_ACCESS_TOKEN) {
28982
- const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
28983
- if (!globalExp || globalExp > new Date) {
28984
- result.hint = `Local credentials file at ${absolutePath} has expired credentials. Valid credentials exist in ${globalPath}. Remove the local file or run 'uip login' to re-authenticate.`;
28985
- }
28986
- }
28987
- } catch {}
29301
+ const globalHint = await tryGlobalCredsHint();
29302
+ if (globalHint) {
29303
+ result.hint = globalHint;
28988
29304
  }
28989
29305
  }
28990
29306
  return result;
@@ -29032,6 +29348,10 @@ var getAuthContext = async (options = {}) => {
29032
29348
  init_src();
29033
29349
  // ../auth/src/logout.ts
29034
29350
  init_src();
29351
+
29352
+ // ../auth/src/index.ts
29353
+ init_server();
29354
+
29035
29355
  // src/client-factory.ts
29036
29356
  async function createInsightsConfig(tenantOverride) {
29037
29357
  const ctx = await getAuthContext({
package/package.json CHANGED
@@ -1,33 +1,28 @@
1
1
  {
2
- "name": "@uipath/insights-sdk",
3
- "version": "1.1.0",
4
- "description": "SDK for the UiPath Insights API — jobs, failures, and performance metrics.",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/UiPath/cli.git",
8
- "directory": "packages/insights-sdk"
9
- },
10
- "publishConfig": {
11
- "registry": "https://registry.npmjs.org/"
12
- },
13
- "keywords": [
14
- "uipath",
15
- "insights",
16
- "sdk"
17
- ],
18
- "type": "module",
19
- "main": "./dist/index.js",
20
- "exports": {
21
- ".": "./dist/index.js"
22
- },
23
- "files": [
24
- "dist"
25
- ],
26
- "devDependencies": {
27
- "@uipath/auth": "1.1.0",
28
- "@uipath/common": "1.1.0",
29
- "@types/node": "^25.5.2",
30
- "typescript": "^6.0.2"
31
- },
32
- "gitHead": "06e8c8f566df4b87da4a008635483c62f64f33f0"
2
+ "name": "@uipath/insights-sdk",
3
+ "license": "MIT",
4
+ "version": "1.195.0",
5
+ "description": "SDK for the UiPath Insights API — jobs, failures, and performance metrics.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/UiPath/cli.git",
9
+ "directory": "packages/insights-sdk"
10
+ },
11
+ "publishConfig": {
12
+ "registry": "https://registry.npmjs.org/"
13
+ },
14
+ "keywords": [
15
+ "uipath",
16
+ "insights",
17
+ "sdk"
18
+ ],
19
+ "type": "module",
20
+ "main": "./dist/index.js",
21
+ "exports": {
22
+ ".": "./dist/index.js"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "gitHead": "65fabb84552758b2710d8ca68470e70a9b1d19bc"
33
28
  }