@uipath/apms-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.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Command,
4
4
  metadata2,
5
5
  registerCommands2
6
- } from "./tool-qz76qmsh.js";
6
+ } from "./tool-2aj1ee3m.js";
7
7
 
8
8
  // src/index.ts
9
9
  var program = new Command;
@@ -2082,7 +2082,7 @@ var package_default = {
2082
2082
  name: "@uipath/apms-tool",
2083
2083
  author: "UiPath",
2084
2084
  license: "SEE LICENSE IN LICENSE.txt",
2085
- version: "1.206.0-preview.303",
2085
+ version: "1.207.0-preview.305",
2086
2086
  description: "CLI plugin for the UiPath Access Policy Management Service.",
2087
2087
  private: false,
2088
2088
  repository: {
@@ -2214,13 +2214,15 @@ var ProjectDimensions = {
2214
2214
  SolutionKey: "SolutionKey",
2215
2215
  SolutionProjectKey: "SolutionProjectKey",
2216
2216
  SolutionIdentityStatus: "SolutionIdentityStatus",
2217
- PreviousSolutionKey: "PreviousSolutionKey"
2217
+ PreviousSolutionKey: "PreviousSolutionKey",
2218
+ PreviousProjectKey: "PreviousProjectKey"
2218
2219
  };
2219
2220
  var GUID_KEY_DIMENSIONS = new Set([
2220
2221
  ProjectDimensions.ProjectKey,
2221
2222
  ProjectDimensions.SolutionKey,
2222
2223
  ProjectDimensions.SolutionProjectKey,
2223
- ProjectDimensions.PreviousSolutionKey
2224
+ ProjectDimensions.PreviousSolutionKey,
2225
+ ProjectDimensions.PreviousProjectKey
2224
2226
  ]);
2225
2227
  var ShipDimensions = {
2226
2228
  ShipKind: "ShipKind",
@@ -2668,7 +2670,7 @@ var package_default2 = {
2668
2670
  name: "@uipath/apms-sdk",
2669
2671
  author: "UiPath",
2670
2672
  license: "SEE LICENSE IN LICENSE.txt",
2671
- version: "1.206.0",
2673
+ version: "1.207.0",
2672
2674
  description: "SDK for the UiPath Access Policy Management Service API.",
2673
2675
  repository: {
2674
2676
  type: "git",
@@ -3722,6 +3724,8 @@ function settlePromiseLike(thenable) {
3722
3724
  // ../../auth/src/constants.ts
3723
3725
  var UIPATH_HOME_DIR = ".uipath";
3724
3726
  var AUTH_FILENAME = ".auth";
3727
+ var AUTH_FILE_MODE = 384;
3728
+ var AUTH_DIR_MODE = 448;
3725
3729
  var DEFAULT_BASE_URL = "https://cloud.uipath.com";
3726
3730
  var DEFAULT_AUTH_TIMEOUT_MS = 5 * 60 * 1000;
3727
3731
 
@@ -3867,12 +3871,26 @@ class NodeFileSystem {
3867
3871
  throw error;
3868
3872
  }
3869
3873
  }
3870
- async writeFile(filePath, data) {
3874
+ async writeFile(filePath, data, options) {
3871
3875
  const dir = path.dirname(filePath);
3872
3876
  if (dir) {
3873
3877
  await fs.mkdir(dir, { recursive: true });
3874
3878
  }
3875
- await fs.writeFile(filePath, data);
3879
+ if (options?.mode === undefined || process.platform === "win32") {
3880
+ if (options?.exclusive) {
3881
+ await fs.writeFile(filePath, data, { flag: "wx" });
3882
+ } else {
3883
+ await fs.writeFile(filePath, data);
3884
+ }
3885
+ return;
3886
+ }
3887
+ const handle = await fs.open(filePath, options.exclusive ? "wx" : "w", options.mode);
3888
+ try {
3889
+ await handle.chmod(options.mode);
3890
+ await handle.writeFile(data);
3891
+ } finally {
3892
+ await handle.close();
3893
+ }
3876
3894
  }
3877
3895
  async appendFile(filePath, data) {
3878
3896
  const dir = path.dirname(filePath);
@@ -3907,7 +3925,8 @@ class NodeFileSystem {
3907
3925
  isDirectory: () => stats.isDirectory(),
3908
3926
  size: stats.size,
3909
3927
  mtimeMs: stats.mtimeMs,
3910
- ctimeMs: stats.ctimeMs
3928
+ ctimeMs: stats.ctimeMs,
3929
+ mode: stats.mode
3911
3930
  };
3912
3931
  } catch (error) {
3913
3932
  if (this.isEnoent(error))
@@ -3918,8 +3937,13 @@ class NodeFileSystem {
3918
3937
  async exists(filePath) {
3919
3938
  return existsSync(filePath);
3920
3939
  }
3921
- async mkdir(dirPath) {
3922
- await fs.mkdir(dirPath, { recursive: true });
3940
+ async mkdir(dirPath, options) {
3941
+ await fs.mkdir(dirPath, { recursive: true, mode: options?.mode });
3942
+ }
3943
+ async chmod(targetPath, mode) {
3944
+ if (process.platform === "win32")
3945
+ return;
3946
+ await fs.chmod(targetPath, mode);
3923
3947
  }
3924
3948
  async acquireLock(lockPath) {
3925
3949
  const canonicalPath = await this.canonicalizeLockTarget(lockPath);
@@ -4069,7 +4093,7 @@ class NodeFileSystem {
4069
4093
  async getTempDir() {
4070
4094
  return await fs.mkdtemp(path.join(os.tmpdir(), "uipath-fs-"));
4071
4095
  }
4072
- async copyDirectory(sourcePath, destPath) {
4096
+ async copyDirectory(sourcePath, destPath, options) {
4073
4097
  const sourceStats = await this.stat(sourcePath);
4074
4098
  if (!sourceStats) {
4075
4099
  throw new Error(`Source directory does not exist: ${sourcePath}`);
@@ -4086,7 +4110,9 @@ class NodeFileSystem {
4086
4110
  if (!entryStats)
4087
4111
  continue;
4088
4112
  if (entryStats.isDirectory()) {
4089
- await this.copyDirectory(srcEntry, destEntry);
4113
+ if (options?.skipDirectoryNames?.includes(entry))
4114
+ continue;
4115
+ await this.copyDirectory(srcEntry, destEntry, options);
4090
4116
  } else if (entryStats.isFile()) {
4091
4117
  const content = await this.readFile(srcEntry);
4092
4118
  if (content !== null) {
@@ -4834,6 +4860,38 @@ var loadEnvFileAsync = async ({ envPath }) => {
4834
4860
  }
4835
4861
  return parseEnvContent(content);
4836
4862
  };
4863
+ var findAuthHomeDir = (fs, dir) => {
4864
+ let current = dir;
4865
+ for (;; ) {
4866
+ if (fs.path.basename(current) === UIPATH_HOME_DIR)
4867
+ return current;
4868
+ const parent = fs.path.dirname(current);
4869
+ if (parent === current)
4870
+ return;
4871
+ current = parent;
4872
+ }
4873
+ };
4874
+ var TEMP_FILE_ATTEMPTS = 5;
4875
+ var isFileExists = (error) => error instanceof Error && error.code === "EEXIST";
4876
+ var writeTempFile = async (fs, targetPath, content) => {
4877
+ for (let attempt = 1;; attempt++) {
4878
+ const tempPath = `${targetPath}.${crypto.randomUUID()}.tmp`;
4879
+ try {
4880
+ await fs.writeFile(tempPath, content, {
4881
+ mode: AUTH_FILE_MODE,
4882
+ exclusive: true
4883
+ });
4884
+ return tempPath;
4885
+ } catch (error) {
4886
+ if (!isFileExists(error)) {
4887
+ await fs.rm(tempPath).catch(() => {});
4888
+ throw error;
4889
+ }
4890
+ if (attempt === TEMP_FILE_ATTEMPTS)
4891
+ throw error;
4892
+ }
4893
+ }
4894
+ };
4837
4895
  var saveEnvFileAsync = async ({
4838
4896
  envPath,
4839
4897
  data,
@@ -4861,10 +4919,18 @@ var saveEnvFileAsync = async ({
4861
4919
  `)}
4862
4920
  `;
4863
4921
  const dir = fs.path.dirname(absolutePath);
4864
- await fs.mkdir(dir);
4865
- const tempPath = `${absolutePath}.tmp`;
4866
- await fs.writeFile(tempPath, content);
4867
- await fs.rename(tempPath, absolutePath);
4922
+ await fs.mkdir(dir, { mode: AUTH_DIR_MODE });
4923
+ const authHomeDir = findAuthHomeDir(fs, dir);
4924
+ if (authHomeDir !== undefined) {
4925
+ await fs.chmod?.(authHomeDir, AUTH_DIR_MODE);
4926
+ }
4927
+ const tempPath = await writeTempFile(fs, absolutePath, content);
4928
+ try {
4929
+ await fs.rename(tempPath, absolutePath);
4930
+ } catch (error) {
4931
+ await fs.rm(tempPath).catch(() => {});
4932
+ throw error;
4933
+ }
4868
4934
  };
4869
4935
 
4870
4936
  // ../../auth/src/loginStatus.ts
@@ -5459,44 +5525,6 @@ var TENANT_SELECTION_CODES = new Set([
5459
5525
  TENANT_SELECTION_REQUIRED_CODE,
5460
5526
  INVALID_TENANT_CODE
5461
5527
  ]);
5462
- // ../apms-sdk/src/client-factory.ts
5463
- var STRIP_PREFIX_RE = /\/accesspolicy_\/api\/(?:accessPolicy\/)?organization\/[^/]+/;
5464
- function rewriteApmsUrl(url) {
5465
- return url.replace(STRIP_PREFIX_RE, "/accesspolicy_");
5466
- }
5467
- async function resolveConfig(options) {
5468
- const auth = await getAuthContext({
5469
- ensureTokenValidityMinutes: options?.loginValidity,
5470
- requireOrganizationId: true
5471
- });
5472
- const basePath = `${auth.baseUrl}/${encodeURIComponent(auth.organizationId)}/accesspolicy_`;
5473
- const bearerToken = options?.s2sToken ?? auth.accessToken;
5474
- const fetchApi = (input, init) => {
5475
- if (typeof input === "string") {
5476
- return fetch(rewriteApmsUrl(input), init);
5477
- }
5478
- if (input instanceof URL) {
5479
- return fetch(rewriteApmsUrl(input.toString()), init);
5480
- }
5481
- return fetch(new Request(rewriteApmsUrl(input.url), input), init);
5482
- };
5483
- return {
5484
- config: new Configuration({
5485
- basePath,
5486
- accessToken: async () => bearerToken,
5487
- headers: addSdkUserAgentHeader(undefined, SDK_USER_AGENT),
5488
- fetchApi
5489
- }),
5490
- organizationId: auth.organizationId
5491
- };
5492
- }
5493
- async function createApiClient(ApiClass, options) {
5494
- const { config, organizationId } = await resolveConfig(options);
5495
- return {
5496
- api: new ApiClass(config),
5497
- organizationId
5498
- };
5499
- }
5500
5528
  // ../../common/src/telemetry/project-identity.ts
5501
5529
  function projectKey(id) {
5502
5530
  if (typeof id !== "string")
@@ -5533,9 +5561,7 @@ async function withinProjectIdentityBudget(work, onTimeout) {
5533
5561
  }
5534
5562
  }
5535
5563
 
5536
- // ../../common/src/telemetry/pseudonymize.ts
5537
- var PSEUDONYM_DOMAIN = "uipath-cli/telemetry/pseudonym/v1:";
5538
- var PSEUDONYM_HEX_LENGTH = 32;
5564
+ // ../../common/src/sha256.ts
5539
5565
  var SHA256_K = new Uint32Array([
5540
5566
  1116352408,
5541
5567
  1899447441,
@@ -5615,7 +5641,7 @@ var SHA256_INITIAL_STATE = new Uint32Array([
5615
5641
  function rotr(value, bits) {
5616
5642
  return (value >>> bits | value << 32 - bits) >>> 0;
5617
5643
  }
5618
- function sha256Hex(input) {
5644
+ function sha256Words(input) {
5619
5645
  const bytes = new TextEncoder().encode(input);
5620
5646
  const paddedLength = bytes.length + 9 + 63 >> 6 << 6;
5621
5647
  const buffer = new Uint8Array(paddedLength);
@@ -5671,12 +5697,19 @@ function sha256Hex(input) {
5671
5697
  state[6] = state[6] + g >>> 0;
5672
5698
  state[7] = state[7] + h >>> 0;
5673
5699
  }
5700
+ return state;
5701
+ }
5702
+ function sha256Hex(input) {
5674
5703
  let hex = "";
5675
- for (const word of state) {
5704
+ for (const word of sha256Words(input)) {
5676
5705
  hex += word.toString(16).padStart(8, "0");
5677
5706
  }
5678
5707
  return hex;
5679
5708
  }
5709
+
5710
+ // ../../common/src/telemetry/pseudonymize.ts
5711
+ var PSEUDONYM_DOMAIN = "uipath-cli/telemetry/pseudonym/v1:";
5712
+ var PSEUDONYM_HEX_LENGTH = 32;
5680
5713
  function resolveSha256Hex() {
5681
5714
  try {
5682
5715
  const nodeCrypto = __require("node:crypto");
@@ -6042,13 +6075,25 @@ function settlePromiseLike2(thenable) {
6042
6075
  return Promise.resolve(thenable).then((data) => [undefined, data]).catch((error) => [toError(error), undefined]);
6043
6076
  }
6044
6077
 
6078
+ // ../../common/src/result-types.ts
6079
+ var RESULTS = {
6080
+ Success: "Success",
6081
+ Failure: "Failure",
6082
+ ConfigError: "ConfigError",
6083
+ AuthenticationError: "AuthenticationError",
6084
+ ValidationError: "ValidationError",
6085
+ TimeoutError: "TimeoutError"
6086
+ };
6087
+
6045
6088
  // ../../common/src/error-codes.ts
6046
6089
  var CLI_ERROR_CODES = [
6047
6090
  "invalid_argument",
6091
+ "confirmation_required",
6048
6092
  "authentication_required",
6049
6093
  "permission_denied",
6050
6094
  "local_permission_denied",
6051
6095
  "not_found",
6096
+ "not_enabled",
6052
6097
  "rate_limited",
6053
6098
  "network_error",
6054
6099
  "timeout",
@@ -6087,6 +6132,12 @@ function carriedRetry(error) {
6087
6132
  const retry = error.retry;
6088
6133
  return isRetryHint(retry) ? retry : undefined;
6089
6134
  }
6135
+ function carriedResult(error) {
6136
+ if (!error || typeof error !== "object")
6137
+ return;
6138
+ const result = error.result;
6139
+ return typeof result === "string" && result !== RESULTS.Success && Object.values(RESULTS).includes(result) ? result : undefined;
6140
+ }
6090
6141
  function defaultRetryForErrorCode(errorCode) {
6091
6142
  switch (errorCode) {
6092
6143
  case "network_error":
@@ -6476,6 +6527,8 @@ async function extractErrorDetails(error, options) {
6476
6527
  }
6477
6528
  if (parsedBody?.errorCode && typeof parsedBody.errorCode === "string") {
6478
6529
  context.errorCode = parsedBody.errorCode;
6530
+ } else if (typeof parsedBody?.errorCode === "number") {
6531
+ context.errorCode = String(parsedBody.errorCode);
6479
6532
  } else if (parsedBody?.code && typeof parsedBody.code === "string") {
6480
6533
  context.errorCode = parsedBody.code;
6481
6534
  }
@@ -6536,6 +6589,83 @@ async function extractErrorMessage(error, options) {
6536
6589
  const { message } = await extractErrorDetails(error, options);
6537
6590
  return message;
6538
6591
  }
6592
+
6593
+ // ../apms-sdk/src/client-factory.ts
6594
+ var STRIP_PREFIX_RE = /\/accesspolicy_\/api\/(?:accessPolicy\/)?organization\/[^/]+/;
6595
+ function rewriteApmsUrl(url) {
6596
+ return url.replace(STRIP_PREFIX_RE, "/accesspolicy_");
6597
+ }
6598
+ var APMS_UNAVAILABLE_ERROR = "ApmsUnavailableError";
6599
+
6600
+ class ApmsUnavailableError extends Error {
6601
+ constructor(url) {
6602
+ super(`The Access Policy Management Service is not available: ${url} is not served by the API.`);
6603
+ this.name = APMS_UNAVAILABLE_ERROR;
6604
+ }
6605
+ }
6606
+ var isApmsUnavailableError = (error) => error instanceof Error && error.name === APMS_UNAVAILABLE_ERROR;
6607
+ var APMS_SIGN_IN_REDIRECT_ERROR = "ApmsSignInRedirectError";
6608
+
6609
+ class ApmsSignInRedirectError extends Error {
6610
+ status = 401;
6611
+ constructor(url) {
6612
+ super(`The request was redirected to the sign-in page (${url}).`);
6613
+ this.name = APMS_SIGN_IN_REDIRECT_ERROR;
6614
+ }
6615
+ }
6616
+ var SIGN_IN_URL_RE = /\/identity_\/|\/(?:account\/)?(?:login|signin)\b/i;
6617
+ var isSignInRedirect = (response) => response.redirected && SIGN_IN_URL_RE.test(response.url);
6618
+ async function isHtmlPage(response) {
6619
+ if (!response.ok)
6620
+ return false;
6621
+ if (/json/i.test(response.headers.get("content-type") ?? ""))
6622
+ return false;
6623
+ return isHtmlDocument(await response.clone().text());
6624
+ }
6625
+ var rejectHtmlPages = {
6626
+ async post({ url, response }) {
6627
+ if (!await isHtmlPage(response))
6628
+ return response;
6629
+ if (isSignInRedirect(response)) {
6630
+ throw new ApmsSignInRedirectError(response.url);
6631
+ }
6632
+ throw new ApmsUnavailableError(url);
6633
+ }
6634
+ };
6635
+ async function resolveConfig(options) {
6636
+ const auth = await getAuthContext({
6637
+ ensureTokenValidityMinutes: options?.loginValidity,
6638
+ requireOrganizationId: true
6639
+ });
6640
+ const basePath = `${auth.baseUrl}/${encodeURIComponent(auth.organizationId)}/accesspolicy_`;
6641
+ const bearerToken = options?.s2sToken ?? auth.accessToken;
6642
+ const fetchApi = (input, init) => {
6643
+ if (typeof input === "string") {
6644
+ return fetch(rewriteApmsUrl(input), init);
6645
+ }
6646
+ if (input instanceof URL) {
6647
+ return fetch(rewriteApmsUrl(input.toString()), init);
6648
+ }
6649
+ return fetch(new Request(rewriteApmsUrl(input.url), input), init);
6650
+ };
6651
+ return {
6652
+ config: new Configuration({
6653
+ basePath,
6654
+ accessToken: async () => bearerToken,
6655
+ headers: addSdkUserAgentHeader(undefined, SDK_USER_AGENT),
6656
+ fetchApi,
6657
+ middleware: [rejectHtmlPages]
6658
+ }),
6659
+ organizationId: auth.organizationId
6660
+ };
6661
+ }
6662
+ async function createApiClient(ApiClass, options) {
6663
+ const { config, organizationId } = await resolveConfig(options);
6664
+ return {
6665
+ api: new ApiClass(config),
6666
+ organizationId
6667
+ };
6668
+ }
6539
6669
  // ../../common/src/error-instructions.ts
6540
6670
  function extractHttpStatus(err) {
6541
6671
  if (!err || typeof err !== "object")
@@ -6614,16 +6744,6 @@ function instructionsFor(ctx, err) {
6614
6744
  }
6615
6745
  }
6616
6746
 
6617
- // ../../common/src/result-types.ts
6618
- var RESULTS = {
6619
- Success: "Success",
6620
- Failure: "Failure",
6621
- ConfigError: "ConfigError",
6622
- AuthenticationError: "AuthenticationError",
6623
- ValidationError: "ValidationError",
6624
- TimeoutError: "TimeoutError"
6625
- };
6626
-
6627
6747
  // ../../common/src/classified-failure.ts
6628
6748
  async function authContextFailure(error, sessionInstructions) {
6629
6749
  const details = await extractErrorDetails(error);
@@ -6637,6 +6757,16 @@ async function authContextFailure(error, sessionInstructions) {
6637
6757
  ...details.context ? { Context: details.context } : {}
6638
6758
  };
6639
6759
  }
6760
+ function notSupportedFailure(operation, instructions, context) {
6761
+ return {
6762
+ Result: RESULTS.Failure,
6763
+ ErrorCode: "not_supported",
6764
+ Message: `${operation} isn't supported on the connected environment.`,
6765
+ Instructions: instructions,
6766
+ Retry: "RetryWillNotFix",
6767
+ ...context ? { Context: context } : {}
6768
+ };
6769
+ }
6640
6770
  // ../../../node_modules/commander/index.js
6641
6771
  var exports_commander = {};
6642
6772
  __exportCjs(exports_commander, {
@@ -7069,7 +7199,10 @@ var AUTH_ERROR_CODES = new Set([
7069
7199
  var LOCAL_PERMISSION_CLI_ERROR_CODES = new Set([
7070
7200
  "local_permission_denied"
7071
7201
  ]);
7072
- var VALIDATION_ERROR_CODES = new Set(["invalid_argument"]);
7202
+ var VALIDATION_ERROR_CODES = new Set([
7203
+ "invalid_argument",
7204
+ "confirmation_required"
7205
+ ]);
7073
7206
  var NETWORK_HTTP_ERROR_CODES = new Set([
7074
7207
  "network_error",
7075
7208
  "rate_limited",
@@ -7295,6 +7428,103 @@ var CommonTelemetryEvents = {
7295
7428
  ShipSucceeded: "Cli.ShipSucceeded"
7296
7429
  };
7297
7430
 
7431
+ // ../../common/src/telemetry/trace-context.ts
7432
+ var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
7433
+ var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
7434
+ function getProcessEnv() {
7435
+ return globalThis.process?.env;
7436
+ }
7437
+ function parseInboundTraceparent(value) {
7438
+ if (!value) {
7439
+ return;
7440
+ }
7441
+ const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
7442
+ if (!match) {
7443
+ return;
7444
+ }
7445
+ const [, traceId, parentSpanId] = match;
7446
+ if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
7447
+ return;
7448
+ }
7449
+ return { traceId, parentSpanId };
7450
+ }
7451
+ function getInboundTraceContext() {
7452
+ return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
7453
+ }
7454
+
7455
+ // ../../common/src/telemetry/session-id.ts
7456
+ var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
7457
+ var SESSION_ID_MAX_LENGTH = 64;
7458
+ var RANDOM_SESSION_ID_LENGTH = 32;
7459
+ var TELEMETRY_SESSION_SOURCE_PROPERTY = "SessionIdSource";
7460
+ var CONTROL_CHARACTERS = /\p{Cc}/gu;
7461
+ var INHERITED_SESSION_SOURCES = [
7462
+ { envVar: "CLAUDE_CODE_SESSION_ID", source: "claude-code" },
7463
+ { envVar: "CODEX_THREAD_ID", source: "codex" },
7464
+ { envVar: "ANTIGRAVITY_TRAJECTORY_ID", source: "antigravity" },
7465
+ { envVar: "TERM_SESSION_ID", source: "terminal" },
7466
+ { envVar: "WT_SESSION", source: "terminal" }
7467
+ ];
7468
+ var telemetrySessionSlot = singleton("TelemetrySession");
7469
+ var telemetryOperationIdSlot = singleton("TelemetryOperationId");
7470
+ function getProcessEnv2() {
7471
+ return globalThis.process?.env;
7472
+ }
7473
+ function normalizeSessionId(value) {
7474
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
7475
+ return;
7476
+ }
7477
+ const cleaned = String(value).replace(CONTROL_CHARACTERS, "").trim().slice(0, SESSION_ID_MAX_LENGTH);
7478
+ return cleaned || undefined;
7479
+ }
7480
+ function getConfiguredTelemetrySessionId() {
7481
+ return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
7482
+ }
7483
+ function getInheritedSession(env) {
7484
+ for (const candidate of INHERITED_SESSION_SOURCES) {
7485
+ const handle = normalizeSessionId(env[candidate.envVar]);
7486
+ if (handle) {
7487
+ return { id: handle, source: candidate.source };
7488
+ }
7489
+ }
7490
+ return;
7491
+ }
7492
+ function generateRandomSession() {
7493
+ const bytes = new Uint8Array(RANDOM_SESSION_ID_LENGTH / 2);
7494
+ crypto.getRandomValues(bytes);
7495
+ let hex = "";
7496
+ for (const byte of bytes) {
7497
+ hex += byte.toString(16).padStart(2, "0");
7498
+ }
7499
+ return { id: hex, source: "random" };
7500
+ }
7501
+ function resolveTelemetrySession() {
7502
+ const existing = telemetrySessionSlot.get();
7503
+ if (existing) {
7504
+ return existing;
7505
+ }
7506
+ const declaredHandle = getConfiguredTelemetrySessionId();
7507
+ const resolved = declaredHandle ? { id: declaredHandle, source: "declared" } : getInheritedSession(getProcessEnv2() ?? {}) ?? generateRandomSession();
7508
+ telemetrySessionSlot.set(resolved);
7509
+ return resolved;
7510
+ }
7511
+ function getTelemetrySessionId() {
7512
+ return resolveTelemetrySession().id;
7513
+ }
7514
+ function getTelemetrySessionSource() {
7515
+ return resolveTelemetrySession().source;
7516
+ }
7517
+ function getTelemetryOperationId() {
7518
+ const existing = telemetryOperationIdSlot.get();
7519
+ if (existing) {
7520
+ return existing;
7521
+ }
7522
+ const inboundTraceId = getInboundTraceContext()?.traceId;
7523
+ const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
7524
+ telemetryOperationIdSlot.set(generated);
7525
+ return generated;
7526
+ }
7527
+
7298
7528
  // ../../common/src/registry.ts
7299
7529
  import { execFileSync } from "node:child_process";
7300
7530
  function readRegistryValue(keyPath, valueName) {
@@ -7516,102 +7746,6 @@ class NodeContextStorage {
7516
7746
  return this.storage.getStore();
7517
7747
  }
7518
7748
  }
7519
- // ../../common/src/telemetry/trace-context.ts
7520
- var TELEMETRY_TRACEPARENT_ENV = "TRACEPARENT";
7521
- var TRACEPARENT_PATTERN = /^00-([0-9a-f]{32})-([0-9a-f]{16})-[0-9a-f]{2}$/;
7522
- function getProcessEnv() {
7523
- return globalThis.process?.env;
7524
- }
7525
- function parseInboundTraceparent(value) {
7526
- if (!value) {
7527
- return;
7528
- }
7529
- const match = TRACEPARENT_PATTERN.exec(value.trim().toLowerCase());
7530
- if (!match) {
7531
- return;
7532
- }
7533
- const [, traceId, parentSpanId] = match;
7534
- if (/^0+$/.test(traceId) || /^0+$/.test(parentSpanId)) {
7535
- return;
7536
- }
7537
- return { traceId, parentSpanId };
7538
- }
7539
- function getInboundTraceContext() {
7540
- return parseInboundTraceparent(getProcessEnv()?.[TELEMETRY_TRACEPARENT_ENV]);
7541
- }
7542
-
7543
- // ../../common/src/telemetry/session-id.ts
7544
- var TELEMETRY_SESSION_ID_ENV = "UIPATH_SESSION_ID";
7545
- var SESSION_ID_MAX_LENGTH = 64;
7546
- var RANDOM_SESSION_ID_LENGTH = 32;
7547
- var TELEMETRY_SESSION_SOURCE_PROPERTY = "SessionIdSource";
7548
- var CONTROL_CHARACTERS = /\p{Cc}/gu;
7549
- var INHERITED_SESSION_SOURCES = [
7550
- { envVar: "CLAUDE_CODE_SESSION_ID", source: "claude-code" },
7551
- { envVar: "CODEX_THREAD_ID", source: "codex" },
7552
- { envVar: "ANTIGRAVITY_TRAJECTORY_ID", source: "antigravity" },
7553
- { envVar: "TERM_SESSION_ID", source: "terminal" },
7554
- { envVar: "WT_SESSION", source: "terminal" }
7555
- ];
7556
- var telemetrySessionSlot = singleton("TelemetrySession");
7557
- var telemetryOperationIdSlot = singleton("TelemetryOperationId");
7558
- function getProcessEnv2() {
7559
- return globalThis.process?.env;
7560
- }
7561
- function normalizeSessionId(value) {
7562
- if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
7563
- return;
7564
- }
7565
- const cleaned = String(value).replace(CONTROL_CHARACTERS, "").trim().slice(0, SESSION_ID_MAX_LENGTH);
7566
- return cleaned || undefined;
7567
- }
7568
- function getConfiguredTelemetrySessionId() {
7569
- return normalizeSessionId(getProcessEnv2()?.[TELEMETRY_SESSION_ID_ENV]);
7570
- }
7571
- function getInheritedSession(env) {
7572
- for (const candidate of INHERITED_SESSION_SOURCES) {
7573
- const handle = normalizeSessionId(env[candidate.envVar]);
7574
- if (handle) {
7575
- return { id: handle, source: candidate.source };
7576
- }
7577
- }
7578
- return;
7579
- }
7580
- function generateRandomSession() {
7581
- const bytes = new Uint8Array(RANDOM_SESSION_ID_LENGTH / 2);
7582
- crypto.getRandomValues(bytes);
7583
- let hex = "";
7584
- for (const byte of bytes) {
7585
- hex += byte.toString(16).padStart(2, "0");
7586
- }
7587
- return { id: hex, source: "random" };
7588
- }
7589
- function resolveTelemetrySession() {
7590
- const existing = telemetrySessionSlot.get();
7591
- if (existing) {
7592
- return existing;
7593
- }
7594
- const declaredHandle = getConfiguredTelemetrySessionId();
7595
- const resolved = declaredHandle ? { id: declaredHandle, source: "declared" } : getInheritedSession(getProcessEnv2() ?? {}) ?? generateRandomSession();
7596
- telemetrySessionSlot.set(resolved);
7597
- return resolved;
7598
- }
7599
- function getTelemetrySessionId() {
7600
- return resolveTelemetrySession().id;
7601
- }
7602
- function getTelemetrySessionSource() {
7603
- return resolveTelemetrySession().source;
7604
- }
7605
- function getTelemetryOperationId() {
7606
- const existing = telemetryOperationIdSlot.get();
7607
- if (existing) {
7608
- return existing;
7609
- }
7610
- const inboundTraceId = getInboundTraceContext()?.traceId;
7611
- const generated = inboundTraceId ?? crypto.randomUUID().replaceAll("-", "");
7612
- telemetryOperationIdSlot.set(generated);
7613
- return generated;
7614
- }
7615
7749
  // ../../common/src/telemetry/span-clock.ts
7616
7750
  function startSpanClock() {
7617
7751
  const started = performance.now();
@@ -7816,6 +7950,7 @@ var MAX_SPOOL_AGE_MS = 72 * 60 * 60 * 1000;
7816
7950
  // ../../common/src/telemetry/telemetry-init.ts
7817
7951
  var telemetryInstanceSlot = singleton("TelemetryService");
7818
7952
  var DEFAULT_AI_CONNECTION_STRING = atob("SW5zdHJ1bWVudGF0aW9uS2V5PTliZDM3NDgyLTgxMGUtNDQyYS1hYWE2LWQzOGVmNjVjNjY3NDtJbmdlc3Rpb25FbmRwb2ludD1odHRwczovL3dlc3RldXJvcGUtNS5pbi5hcHBsaWNhdGlvbmluc2lnaHRzLmF6dXJlLmNvbS87TGl2ZUVuZHBvaW50PWh0dHBzOi8vd2VzdGV1cm9wZS5saXZlZGlhZ25vc3RpY3MubW9uaXRvci5henVyZS5jb20vO0FwcGxpY2F0aW9uSWQ9MzU2OTdlZjEtOGJkMC00ZjE5LWEyN2MtZDg3Y2NhYzY2ZDJj");
7953
+ var browserProviderSlot = singleton("BrowserAppInsightsTelemetryProvider");
7819
7954
  function getGlobalTelemetryInstance() {
7820
7955
  const existing = telemetryInstanceSlot.get();
7821
7956
  if (existing && typeof existing === "object" && "trackEvent" in existing && typeof existing.trackEvent === "function") {
@@ -7999,7 +8134,7 @@ function printOutput(data, format = "json", logFn, asciiSafe = false, tableRowSt
7999
8134
  const pagedRows = extractPagedRows(data.Data);
8000
8135
  const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
8001
8136
  items.forEach((item) => {
8002
- const values = Object.values(item).map((v) => v ?? "").join("\t");
8137
+ const values = item === null || typeof item !== "object" ? String(item ?? "") : Object.values(item).map((v) => v ?? "").join("\t");
8003
8138
  logFn(values);
8004
8139
  });
8005
8140
  } else {
@@ -8014,7 +8149,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false, tableRowSt
8014
8149
  default: {
8015
8150
  const hasData = "Data" in data && data.Data != null;
8016
8151
  const pagedRows = hasData ? extractPagedRows(data.Data) : null;
8017
- const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
8152
+ const resolvedRows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
8153
+ const rows = resolvedRows && isPrimitiveArray(resolvedRows) ? resolvedRows.map((entry) => ({ Value: entry })) : resolvedRows;
8018
8154
  if (hasData && !(rows !== null && rows.length === 0)) {
8019
8155
  const logValue = data.Log;
8020
8156
  if (rows !== null) {
@@ -8071,6 +8207,9 @@ function printTable(data, logFn, externalLogValue, tableRowStyle) {
8071
8207
  function isPlainObjectArray(value) {
8072
8208
  return Array.isArray(value) && value.length > 0 && value.every(isPlainRecord);
8073
8209
  }
8210
+ function isPrimitiveArray(value) {
8211
+ return Array.isArray(value) && value.length > 0 && value.every((entry) => entry === null || typeof entry !== "object");
8212
+ }
8074
8213
  function isNonEmptyPlainObject(value) {
8075
8214
  return isPlainRecord(value) && Object.keys(value).length > 0;
8076
8215
  }
@@ -8417,12 +8556,12 @@ class FilterEvaluationError extends Error {
8417
8556
  instructions;
8418
8557
  retry = "RetryWillNotFix";
8419
8558
  result = RESULTS.ValidationError;
8420
- constructor(filter, cause) {
8559
+ constructor(filter, cause, hint) {
8421
8560
  const underlying = cause instanceof Error ? cause.message : String(cause);
8422
- super(`Filter '${filter}' failed to evaluate: ${underlying}`);
8561
+ super(`Filter '${filter}' failed to evaluate: ${underlying}` + (hint ? ` ${hint.detail}` : ""));
8423
8562
  this.name = "FilterEvaluationError";
8424
8563
  this.filter = filter;
8425
- 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(@)'.";
8564
+ this.instructions = (hint ? `${hint.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(@)'.";
8426
8565
  }
8427
8566
  }
8428
8567
 
@@ -8544,6 +8683,93 @@ function nameList(names, cap = 12) {
8544
8683
  const rest = names.length - shown.length;
8545
8684
  return shown.join(", ") + (rest > 0 ? `, and ${rest} more` : "");
8546
8685
  }
8686
+ function notFieldsOn(names, scope) {
8687
+ return `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
8688
+ }
8689
+ function failingFieldRead(ast, isList, fn, argIndex) {
8690
+ const [left, right, condition] = ast.children ?? [];
8691
+ let scopes = [];
8692
+ if (!isList) {
8693
+ scopes = [ast];
8694
+ } else if (ast.type === "FilterProjection" && left?.type === "Identity") {
8695
+ scopes = [condition, right];
8696
+ } else if (ast.type === "Projection" && (left?.type === "Identity" || left?.type === "Flatten" && left.children?.[0]?.type === "Identity")) {
8697
+ scopes = [right];
8698
+ }
8699
+ const reads = new Set;
8700
+ let tracked = 0;
8701
+ const visit = (node) => {
8702
+ if (!node)
8703
+ return;
8704
+ switch (node.type) {
8705
+ case "Function": {
8706
+ const arg = node.children?.[argIndex - 1];
8707
+ if (node.name === fn && arg?.type === "Field" && arg.name) {
8708
+ reads.add(arg.name);
8709
+ tracked++;
8710
+ }
8711
+ node.children?.forEach(visit);
8712
+ return;
8713
+ }
8714
+ case "AndExpression":
8715
+ case "OrExpression":
8716
+ case "NotExpression":
8717
+ case "Comparator":
8718
+ case "MultiSelectList":
8719
+ case "MultiSelectHash":
8720
+ node.children?.forEach(visit);
8721
+ return;
8722
+ case "KeyValuePair":
8723
+ visit(node.value);
8724
+ return;
8725
+ }
8726
+ };
8727
+ scopes.forEach(visit);
8728
+ const calls = (node) => {
8729
+ if (node === null || typeof node !== "object")
8730
+ return 0;
8731
+ const own = node.type === "Function" && node.name === fn ? 1 : 0;
8732
+ const next = node.type === "KeyValuePair" ? [node.value] : node.children ?? [];
8733
+ return own + next.reduce((sum, child) => sum + calls(child), 0);
8734
+ };
8735
+ return reads.size === 1 && tracked === calls(ast) ? [...reads][0] : undefined;
8736
+ }
8737
+ function fieldExpression(name) {
8738
+ return /^[A-Za-z_]\w*$/.test(name) ? name : JSON.stringify(name);
8739
+ }
8740
+ function evaluationHint(codec, filter, data, cause) {
8741
+ const underlying = cause instanceof Error ? cause.message : String(cause);
8742
+ const failure = /\b(\w+)\(\) expected argument (\d+) to be type (\S+) but received type null\b/.exec(underlying);
8743
+ if (!failure)
8744
+ return;
8745
+ const [, fn, position, expected] = failure;
8746
+ const name = failingFieldRead(codec.compile(filter), Array.isArray(data), fn, Number(position));
8747
+ if (name === undefined)
8748
+ return;
8749
+ const present = availableFields(data);
8750
+ if (present.length === 0)
8751
+ return;
8752
+ const scope = `${countRecords(data)} record(s)`;
8753
+ if (!present.includes(name)) {
8754
+ return {
8755
+ detail: `${notFieldsOn([name], scope)}. Available fields: ${nameList(present)}.`,
8756
+ instructions: "Use a field the records have; names are case-sensitive."
8757
+ };
8758
+ }
8759
+ const records = Array.isArray(data) ? data : [data];
8760
+ const unset = records.filter((r) => r?.[name] == null).length;
8761
+ const field = fieldExpression(name);
8762
+ let fallback;
8763
+ if (expected.split(",").includes("string")) {
8764
+ fallback = "''";
8765
+ } else if (expected.split(",").includes("array")) {
8766
+ fallback = "`[]`";
8767
+ }
8768
+ return {
8769
+ detail: `\`${name}\` is null or missing on ${unset} of the ${scope} it read.`,
8770
+ instructions: fallback ? `Give it a default where ${fn}() reads it, e.g. \`${field} || ${fallback}\`.` : `Filter out the records where \`${name}\` is null before ${fn}() reads it.`
8771
+ };
8772
+ }
8547
8773
  function buildFilterWarning(filter, data, outcome) {
8548
8774
  const present = availableFields(data);
8549
8775
  const refs = referencedFields(filter);
@@ -8551,7 +8777,7 @@ function buildFilterWarning(filter, data, outcome) {
8551
8777
  const unchecked = refs.nested.filter((name) => !present.includes(name));
8552
8778
  const count = countRecords(data);
8553
8779
  const scope = `${count} record(s)`;
8554
- const isNotAField = (names) => `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
8780
+ const isNotAField = (names) => notFieldsOn(names, scope);
8555
8781
  const soundness = unchecked.length > 0 ? `${nameList(unchecked)} ${unchecked.length === 1 ? "reads" : "read"} below the top level, so ${unchecked.length === 1 ? "it was" : "they were"} not checked against the record keys` : refs.top.length > 0 ? "every field it names exists" : "";
8556
8782
  const withSoundness = (base) => soundness ? `${base}, and ${soundness}` : base;
8557
8783
  let detail;
@@ -8602,7 +8828,8 @@ function applyFilter(data, filter, onWarning) {
8602
8828
  try {
8603
8829
  result = codec.search(data, filter);
8604
8830
  } catch (err) {
8605
- throw new FilterEvaluationError(filter, err);
8831
+ const [, hint] = catchError2(() => evaluationHint(codec, filter, data, err));
8832
+ throw new FilterEvaluationError(filter, err, hint);
8606
8833
  }
8607
8834
  const inputCount = countRecords(data);
8608
8835
  const warn = (outcome) => {
@@ -9493,7 +9720,7 @@ Command.prototype.trackedAction = function(context, fn, properties) {
9493
9720
  logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage}`);
9494
9721
  const typed = error;
9495
9722
  const customInstructions = typeof typed.instructions === "string" ? typed.instructions : undefined;
9496
- const customResult = typeof typed.result === "string" && typed.result !== RESULTS.Success && Object.values(RESULTS).includes(typed.result) ? typed.result : undefined;
9723
+ const customResult = carriedResult(error);
9497
9724
  const cancellationExitCode = typed.exitCode === 130 || isPromptCancellation(error) ? 130 : undefined;
9498
9725
  const classified = cancellationExitCode === undefined ? await extractErrorDetails(error) : undefined;
9499
9726
  const finalResult = customResult ?? classified?.result ?? RESULTS.Failure;
@@ -9855,6 +10082,8 @@ var FAILURE_STATUSES = new Set([
9855
10082
  "canceled",
9856
10083
  "stopped"
9857
10084
  ]);
10085
+ // ../../common/src/relayed-output.ts
10086
+ var RELAYED_OUTPUT_SYMBOL = Symbol.for("@uipath/common/relayed-output");
9858
10087
  // ../../common/src/screen-logger.ts
9859
10088
  var ScreenLogger;
9860
10089
  ((ScreenLogger) => {
@@ -9870,6 +10099,8 @@ var shippedKeysSlot = singleton("ShipSucceededDedupeKeys");
9870
10099
  var factorySlot = singleton("PackagerFactoryProvider");
9871
10100
  // src/commands/_shared.ts
9872
10101
  var LOGIN_INSTRUCTIONS = "Ensure you are logged in with 'uip login' and have access to the Access Policy Management service.";
10102
+ var IP_RESTRICTION_NOT_SUPPORTED_INSTRUCTIONS = "The connected environment does not run the Access Policy Management service that IP restriction needs. Manage IP restriction on an environment that runs it.";
10103
+ var MY_IP_NOT_SUPPORTED_INSTRUCTIONS = "The platform reports the public IP its edge network saw for the caller, and the connected environment answered without one. Find the address another way, such as from your network administrator.";
9873
10104
  var NON_NEGATIVE_INTEGER_RE = /^\d+$/;
9874
10105
  var parseIntOption = (raw) => {
9875
10106
  const trimmed = raw.trim();
@@ -9919,7 +10150,12 @@ var emitLoadError = (err) => {
9919
10150
  processContext.exit(1);
9920
10151
  };
9921
10152
  var emitFailure = async (error, instructions) => {
9922
- if (error instanceof Error && (error.name === "AuthContextUnavailableError" || error.name === "EnvAuthConfigError")) {
10153
+ if (isApmsUnavailableError(error)) {
10154
+ OutputFormatter.error(notSupportedFailure("IP restriction", IP_RESTRICTION_NOT_SUPPORTED_INSTRUCTIONS));
10155
+ processContext.exit(1);
10156
+ return;
10157
+ }
10158
+ if (error instanceof Error && (error.name === "AuthContextUnavailableError" || error.name === "EnvAuthConfigError" || error.name === "ApmsSignInRedirectError")) {
9923
10159
  OutputFormatter.error(await authContextFailure(error, instructions));
9924
10160
  processContext.exit(1);
9925
10161
  return;
@@ -9955,13 +10191,19 @@ async function fetchCurrentIp(loginValidity) {
9955
10191
  method: "GET",
9956
10192
  headers: { Authorization: `Bearer ${auth.accessToken}` }
9957
10193
  });
10194
+ if (isSignInRedirect(res))
10195
+ throw new ApmsSignInRedirectError(res.url);
9958
10196
  const text = (await res.text()).trim();
10197
+ if (res.status === 404)
10198
+ throw new ApmsUnavailableError(url);
9959
10199
  if (!res.ok) {
9960
10200
  throw new Error(`HTTP ${res.status}${res.statusText ? ` ${res.statusText}` : ""}${text ? `: ${text}` : ""}`);
9961
10201
  }
9962
10202
  if (isIPv4(text)) {
9963
10203
  return { body: { ipAddress: text }, ip: text };
9964
10204
  }
10205
+ if (isHtmlDocument(text))
10206
+ throw new ApmsUnavailableError(url);
9965
10207
  const [, parsed] = catchError2(() => JSON.parse(text));
9966
10208
  if (typeof parsed === "string" && isIPv4(parsed)) {
9967
10209
  return { body: { ipAddress: parsed }, ip: parsed };
@@ -10973,6 +11215,11 @@ var registerMyIpCommand = (apms) => {
10973
11215
  await emitFailure(err ?? new Error("Failed to determine current IP"), LOGIN_INSTRUCTIONS);
10974
11216
  return;
10975
11217
  }
11218
+ if (result.ip === undefined && Object.keys(result.body).length === 0) {
11219
+ OutputFormatter.error(notSupportedFailure("Showing the caller's public IP", MY_IP_NOT_SUPPORTED_INSTRUCTIONS));
11220
+ processContext.exit(1);
11221
+ return;
11222
+ }
10976
11223
  OutputFormatter.success({
10977
11224
  Result: RESULTS.Success,
10978
11225
  Code: "ApmsMyIpGet",
@@ -11012,4 +11259,4 @@ var registerCommands2 = async (program) => {
11012
11259
 
11013
11260
  export { Command, metadata2, registerCommands2 };
11014
11261
 
11015
- //# debugId=F16CAC222799138664756E2164756E21
11262
+ //# debugId=40BF3A9569E6F21F64756E2164756E21
package/dist/tool.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  metadata2,
3
3
  registerCommands2
4
- } from "./tool-qz76qmsh.js";
4
+ } from "./tool-2aj1ee3m.js";
5
5
  export {
6
6
  metadata2 as metadata,
7
7
  registerCommands2 as registerCommands
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uipath/apms-tool",
3
3
  "author": "UiPath",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
- "version": "1.206.0-preview.303",
5
+ "version": "1.207.0-preview.305",
6
6
  "description": "CLI plugin for the UiPath Access Policy Management Service.",
7
7
  "private": false,
8
8
  "repository": {
@@ -27,5 +27,5 @@
27
27
  "files": [
28
28
  "dist"
29
29
  ],
30
- "gitHead": "7d17b8a3c1a50892d42c9302087abc8307b04409"
30
+ "gitHead": "1600aa89255c37c1b8bc68d9882c3395c1d5bff4"
31
31
  }