@uipath/apms-tool 1.204.0 → 1.205.0-preview.258

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
  metadata,
5
5
  registerCommands
6
- } from "./tool-ygybzvnb.js";
6
+ } from "./tool-9bak1scf.js";
7
7
  import"./tool-1de529jm.js";
8
8
 
9
9
  // src/index.ts
@@ -2101,7 +2101,7 @@ var package_default = {
2101
2101
  name: "@uipath/apms-tool",
2102
2102
  author: "UiPath",
2103
2103
  license: "SEE LICENSE IN LICENSE.txt",
2104
- version: "1.204.0",
2104
+ version: "1.205.0-preview.258",
2105
2105
  description: "CLI plugin for the UiPath Access Policy Management Service.",
2106
2106
  private: false,
2107
2107
  repository: {
@@ -2234,7 +2234,9 @@ var ErrorDimensions = {
2234
2234
  Result: "Result",
2235
2235
  ErrorCode: "ErrorCode",
2236
2236
  Retry: "Retry",
2237
- ErrorMessage: "ErrorMessage"
2237
+ ErrorMessage: "ErrorMessage",
2238
+ HttpStatus: "HttpStatus",
2239
+ UpstreamErrorCode: "UpstreamErrorCode"
2238
2240
  };
2239
2241
  var AuthDimensions = {
2240
2242
  AuthenticationMethod: "AuthenticationMethod",
@@ -2658,7 +2660,7 @@ var package_default2 = {
2658
2660
  name: "@uipath/apms-sdk",
2659
2661
  author: "UiPath",
2660
2662
  license: "SEE LICENSE IN LICENSE.txt",
2661
- version: "1.204.0",
2663
+ version: "1.205.0",
2662
2664
  description: "SDK for the UiPath Access Policy Management Service API.",
2663
2665
  repository: {
2664
2666
  type: "git",
@@ -3793,22 +3795,12 @@ var resolveConfigAsync = async ({
3793
3795
  baseUrl = DEFAULT_BASE_URL;
3794
3796
  }
3795
3797
  baseUrl = normalizeAndValidateBaseUrl(baseUrl);
3796
- let clientId = customClientId;
3797
- if (!clientId && fileAuth.clientId) {
3798
- clientId = fileAuth.clientId;
3799
- }
3800
- if (!clientId) {
3801
- clientId = DEFAULT_CLIENT_ID;
3802
- }
3803
- let clientSecret = customClientSecret;
3804
- if (!clientSecret && fileAuth.clientSecret) {
3805
- clientSecret = fileAuth.clientSecret;
3806
- }
3807
- const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(clientSecret) || Boolean(customClientAssertion));
3798
+ const clientId = customClientId || DEFAULT_CLIENT_ID;
3799
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(customClientSecret) || Boolean(customClientAssertion));
3808
3800
  const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
3809
3801
  return {
3810
3802
  clientId,
3811
- clientSecret,
3803
+ clientSecret: customClientSecret,
3812
3804
  scopes,
3813
3805
  baseUrl,
3814
3806
  authorizationEndpoint: `${baseUrl}/identity_/connect/authorize`,
@@ -4001,6 +3993,16 @@ class NodeFileSystem {
4001
3993
  async rename(oldPath, newPath) {
4002
3994
  await fs.rename(oldPath, newPath);
4003
3995
  }
3996
+ async isSymbolicLink(filePath) {
3997
+ try {
3998
+ return (await fs.lstat(filePath)).isSymbolicLink();
3999
+ } catch (error) {
4000
+ if (this.isEnoent(error) || this.hasErrnoCode(error, "ENOTDIR")) {
4001
+ return false;
4002
+ }
4003
+ throw error;
4004
+ }
4005
+ }
4004
4006
  async realpath(filePath) {
4005
4007
  try {
4006
4008
  return await fs.realpath(filePath);
@@ -4212,6 +4214,16 @@ var resolveIdentityType = (claims, authFlow, email) => {
4212
4214
  }
4213
4215
  return;
4214
4216
  };
4217
+ var resolveApplicationSubtype = (claims, authFlow) => {
4218
+ switch (asString(claims?.sub_type)) {
4219
+ case "service.external":
4220
+ return "External";
4221
+ case "service.internal":
4222
+ return "Internal";
4223
+ default:
4224
+ return authFlow === "client_credentials" || authFlow === "federated_credentials" ? "External" : undefined;
4225
+ }
4226
+ };
4215
4227
  var looksLikeEmail = (value) => value?.includes("@") ?? false;
4216
4228
  var pickEmail = (claims) => {
4217
4229
  for (const candidate of [claims?.email, claims?.preferred_username]) {
@@ -4253,6 +4265,12 @@ var resolveSessionIdentity = (accessToken, authFlow) => {
4253
4265
  const clientId = asString(claims?.client_id);
4254
4266
  if (clientId)
4255
4267
  identity.clientId = clientId;
4268
+ const subType = asString(claims?.sub_type);
4269
+ if (subType)
4270
+ identity.subType = subType;
4271
+ const applicationSubtype = resolveApplicationSubtype(claims, authFlow);
4272
+ if (applicationSubtype)
4273
+ identity.applicationSubtype = applicationSubtype;
4256
4274
  return identity;
4257
4275
  };
4258
4276
  var readTokenScopes = (accessToken) => accessToken ? pickScopes(decodeClaims(accessToken)) : undefined;
@@ -4545,6 +4563,40 @@ var tryRobotClientFallback = async (options = {}) => {
4545
4563
  }
4546
4564
  };
4547
4565
 
4566
+ // ../../auth/src/tenantSelection.ts
4567
+ var LOGIN_STATUS_HINT = "Run 'uip login status' to see the organization the CLI is signed in to.";
4568
+ var organizationHint = (organizationId) => `The request used '${organizationId}' as the organization. ${LOGIN_STATUS_HINT}`;
4569
+ var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
4570
+ var describeNonJsonResponse = (organizationId, response, parseError) => {
4571
+ if (response.redirected) {
4572
+ return `Could not find organization '${organizationId}': the request was ` + `redirected to a sign-in page instead of the organization's tenant ` + `list. ${LOGIN_STATUS_HINT}`;
4573
+ }
4574
+ const contentType = response.headers.get("content-type") ?? "unknown";
4575
+ return `The organization service returned a '${contentType}' response instead ` + `of JSON: ${parseError.message}. ${organizationHint(organizationId)}`;
4576
+ };
4577
+ var fetchTenantsAndOrganizations = async (baseUrl, accessToken, organizationId, signal) => {
4578
+ const url = `${baseUrl}/${organizationId}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo`;
4579
+ const response = await fetch(url, {
4580
+ headers: {
4581
+ Authorization: `Bearer ${accessToken}`
4582
+ },
4583
+ ...signal ? { signal } : {}
4584
+ });
4585
+ if (!response.ok) {
4586
+ if (response.status === 401) {
4587
+ throw new Error(`Unauthorized: the access token was rejected, it was not ` + `issued for organization '${organizationId}', or ` + `'${organizationId}' was not accepted as an organization ` + `URL segment in this environment. ` + LOGIN_STATUS_HINT);
4588
+ }
4589
+ const errorText = await response.text();
4590
+ const message = `Failed to get tenants and organizations: ${response.status} ${errorText}`;
4591
+ throw new Error(IDENTIFIER_STATUSES.has(response.status) ? `${message}. ${organizationHint(organizationId)}` : message);
4592
+ }
4593
+ const [parseError, data] = await catchError(response.json());
4594
+ if (parseError) {
4595
+ throw new Error(describeNonJsonResponse(organizationId, response, parseError));
4596
+ }
4597
+ return data;
4598
+ };
4599
+
4548
4600
  // ../../auth/src/tokenRefresh.ts
4549
4601
  var TOKEN_REFRESH_REAUTHENTICATE_MESSAGE = "Token refresh failed. Run 'uip login' to re-authenticate.";
4550
4602
 
@@ -4757,6 +4809,8 @@ var saveEnvFileAsync = async ({
4757
4809
  };
4758
4810
 
4759
4811
  // ../../auth/src/loginStatus.ts
4812
+ var defaultRobotTenantIdCache = new Map;
4813
+ var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
4760
4814
  var getLoginStatusAsync = async (options = {}) => {
4761
4815
  return getLoginStatusWithDeps(options);
4762
4816
  };
@@ -4769,12 +4823,20 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
4769
4823
  refreshToken: refreshTokenFn = refreshAccessToken,
4770
4824
  resolveConfig = resolveConfigAsync,
4771
4825
  robotFallback = tryRobotClientFallback,
4826
+ fetchTenantsAndOrgs = fetchTenantsAndOrganizations,
4827
+ robotTenantIdCache = defaultRobotTenantIdCache,
4828
+ robotTenantLookupTimeoutMs = ROBOT_TENANT_LOOKUP_TIMEOUT_MS,
4772
4829
  loadBreaker = loadRefreshBreaker,
4773
4830
  saveBreaker = saveRefreshBreaker,
4774
4831
  clearBreaker = clearRefreshBreaker
4775
4832
  } = deps;
4833
+ const robotDeps = {
4834
+ fetchTenantsAndOrgs,
4835
+ cache: robotTenantIdCache,
4836
+ lookupTimeoutMs: robotTenantLookupTimeoutMs
4837
+ };
4776
4838
  if (isRobotAuthEnforced()) {
4777
- return resolveRobotEnforcedStatus(robotFallback);
4839
+ return resolveRobotEnforcedStatus(robotFallback, robotDeps);
4778
4840
  }
4779
4841
  if (isEnvAuthEnabled()) {
4780
4842
  return readAuthFromEnv();
@@ -4792,7 +4854,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
4792
4854
  hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
4793
4855
  };
4794
4856
  }
4795
- return resolveBorrowedRobotStatus(robotFallback);
4857
+ return resolveBorrowedRobotStatus(robotFallback, robotDeps);
4796
4858
  }
4797
4859
  const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
4798
4860
  if ("status" in loaded) {
@@ -4834,7 +4896,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
4834
4896
  }
4835
4897
  return buildFileStatus(tokens, credentials, globalHint);
4836
4898
  };
4837
- async function resolveRobotEnforcedStatus(robotFallback) {
4899
+ async function resolveRobotEnforcedStatus(robotFallback, deps) {
4838
4900
  if (isEnvAuthEnabled()) {
4839
4901
  throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
4840
4902
  }
@@ -4845,11 +4907,11 @@ async function resolveRobotEnforcedStatus(robotFallback) {
4845
4907
  hint: `${ENFORCE_ROBOT_AUTH_VAR}=true but the UiPath Robot ` + `session is unavailable. Start and sign in to the Assistant, ` + `or unset ${ENFORCE_ROBOT_AUTH_VAR} to fall back to file or ` + `env-var authentication.`
4846
4908
  };
4847
4909
  }
4848
- return buildRobotStatus(robotCreds);
4910
+ return buildRobotStatus(robotCreds, deps);
4849
4911
  }
4850
- async function resolveBorrowedRobotStatus(robotFallback) {
4912
+ async function resolveBorrowedRobotStatus(robotFallback, deps) {
4851
4913
  const robotCreds = await robotFallback();
4852
- return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
4914
+ return robotCreds ? buildRobotStatus(robotCreds, deps) : { loginStatus: "Not logged in" };
4853
4915
  }
4854
4916
  async function loadFileCredentials(loadEnvFile, absolutePath) {
4855
4917
  let credentials;
@@ -4984,9 +5046,10 @@ function identityFields(accessToken, credentials) {
4984
5046
  ...scopes ? { scopes } : {}
4985
5047
  };
4986
5048
  }
4987
- function buildRobotStatus(robotCreds) {
5049
+ async function buildRobotStatus(robotCreds, deps) {
4988
5050
  const identity = resolveSessionIdentity(robotCreds.accessToken);
4989
5051
  const scopes = readTokenScopes(robotCreds.accessToken);
5052
+ const tenant = robotCreds.tenantId ? { tenantId: robotCreds.tenantId } : await resolveRobotTenantId(robotCreds, deps);
4990
5053
  return {
4991
5054
  loginStatus: "Logged in",
4992
5055
  accessToken: robotCreds.accessToken,
@@ -4994,14 +5057,62 @@ function buildRobotStatus(robotCreds) {
4994
5057
  organizationName: robotCreds.organizationName,
4995
5058
  organizationId: robotCreds.organizationId,
4996
5059
  tenantName: robotCreds.tenantName,
4997
- tenantId: robotCreds.tenantId,
5060
+ tenantId: tenant.tenantId,
4998
5061
  issuer: robotCreds.issuer,
4999
5062
  expiration: getTokenExpiration(robotCreds.accessToken),
5000
5063
  source: "robot" /* Robot */,
5064
+ ...tenant.hint ? { hint: tenant.hint } : {},
5001
5065
  ...identity ? { identity } : {},
5002
5066
  ...scopes ? { scopes } : {}
5003
5067
  };
5004
5068
  }
5069
+ async function resolveRobotTenantId(robotCreds, deps) {
5070
+ const { baseUrl, accessToken, tenantName } = robotCreds;
5071
+ const organization = robotCreds.organizationName ?? robotCreds.organizationId;
5072
+ if (!tenantName || !organization) {
5073
+ return {};
5074
+ }
5075
+ const key = `${baseUrl}|${organization}|${tenantName}|${accessToken}`;
5076
+ let pending = deps.cache.get(key);
5077
+ if (!pending) {
5078
+ pending = catchError(lookupRobotTenantId({ baseUrl, accessToken, organization, tenantName }, deps)).then(([error, resolution]) => {
5079
+ const settled = error ? { hint: tenantLookupFailureHint(tenantName, error.message) } : resolution;
5080
+ if (!settled.tenantId) {
5081
+ deps.cache.delete(key);
5082
+ }
5083
+ return settled;
5084
+ });
5085
+ deps.cache.set(key, pending);
5086
+ }
5087
+ return pending;
5088
+ }
5089
+ async function lookupRobotTenantId(target, deps) {
5090
+ const { baseUrl, accessToken, organization, tenantName } = target;
5091
+ const [error, data] = await catchError(deps.fetchTenantsAndOrgs(baseUrl, accessToken, organization, AbortSignal.timeout(deps.lookupTimeoutMs)));
5092
+ if (error) {
5093
+ const reason = error.name === "TimeoutError" ? `the tenant list did not answer within ${deps.lookupTimeoutMs} ms.` : error.message;
5094
+ return { hint: tenantLookupFailureHint(tenantName, reason) };
5095
+ }
5096
+ const rows = data?.tenants;
5097
+ const tenants = Array.isArray(rows) ? rows.filter((tenant) => typeof tenant?.id === "string" && typeof tenant?.name === "string") : [];
5098
+ const wantedName = decodePathSegment(tenantName);
5099
+ const wanted = wantedName.toLowerCase();
5100
+ const match = tenants.find((tenant) => tenant.name === wantedName) ?? tenants.find((tenant) => tenant.name.toLowerCase() === wanted);
5101
+ if (!match) {
5102
+ const names = tenants.map((tenant) => tenant.name).join(", ");
5103
+ return {
5104
+ hint: `The Robot session targets tenant '${tenantName}', but ` + `organization '${organization}' lists no tenant of that name` + `${names ? ` (available: ${names})` : ""}. Commands that need ` + `the tenant id will fail until it can be resolved.`
5105
+ };
5106
+ }
5107
+ return { tenantId: match.id };
5108
+ }
5109
+ function tenantLookupFailureHint(tenantName, reason) {
5110
+ return `Could not resolve the id of tenant '${tenantName}' from the ` + `Robot session: ${reason} Commands that need the tenant id will ` + `fail until it can be resolved.`;
5111
+ }
5112
+ function decodePathSegment(segment) {
5113
+ const [error, decoded] = catchError(() => decodeURIComponent(segment));
5114
+ return error ? segment : decoded;
5115
+ }
5005
5116
  var isFileNotFoundError = (error) => {
5006
5117
  if (!(error instanceof Object))
5007
5118
  return false;
@@ -5237,9 +5348,6 @@ function normalizeTokenRefreshUnavailableFailure() {
5237
5348
  function errorMessage(error) {
5238
5349
  return error instanceof Error ? error.message : String(error);
5239
5350
  }
5240
- // ../../auth/src/tenantSelection.ts
5241
- var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
5242
-
5243
5351
  // ../../auth/src/selectTenant.ts
5244
5352
  var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
5245
5353
  var INVALID_TENANT_CODE = "INVALID_TENANT";
@@ -6245,7 +6353,7 @@ function setGlobalLogFilePath(path2) {
6245
6353
  function getGlobalLogFilePath() {
6246
6354
  return logFilePathSlot.get("");
6247
6355
  }
6248
- var DEFAULT_LOG_LEVEL = 3 /* ERROR */;
6356
+ var DEFAULT_LOG_LEVEL = 2 /* WARN */;
6249
6357
 
6250
6358
  class SimpleLogger {
6251
6359
  __brand = "SimpleLogger";
@@ -7347,7 +7455,9 @@ var CLI_ERROR_CODES = [
7347
7455
  "timeout",
7348
7456
  "server_error",
7349
7457
  "method_not_allowed",
7458
+ "not_supported",
7350
7459
  "configuration_error",
7460
+ "execution_failed",
7351
7461
  "unknown_error"
7352
7462
  ];
7353
7463
  var RETRY_HINTS = [
@@ -8304,7 +8414,9 @@ var OutputFormatter;
8304
8414
  [ErrorDimensions.Result]: data.Result,
8305
8415
  [ErrorDimensions.ErrorCode]: data.ErrorCode,
8306
8416
  [ErrorDimensions.Retry]: data.Retry,
8307
- [ErrorDimensions.ErrorMessage]: data.Message
8417
+ [ErrorDimensions.ErrorMessage]: data.Message,
8418
+ [ErrorDimensions.HttpStatus]: data.Context?.httpStatus?.toString(),
8419
+ [ErrorDimensions.UpstreamErrorCode]: data.Context?.errorCode
8308
8420
  });
8309
8421
  }
8310
8422
  logOutput(normalizeOutputKeys(envelope), getOutputFormat());
@@ -10286,4 +10398,4 @@ var registerCommands = async (program2) => {
10286
10398
 
10287
10399
  export { Command, metadata, registerCommands };
10288
10400
 
10289
- //# debugId=203EF68A80C8262264756E2164756E21
10401
+ //# debugId=0202EE80C663DE7764756E2164756E21
package/dist/tool.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  metadata,
3
3
  registerCommands
4
- } from "./tool-ygybzvnb.js";
4
+ } from "./tool-9bak1scf.js";
5
5
  import"./tool-1de529jm.js";
6
6
  export {
7
7
  metadata,
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.204.0",
5
+ "version": "1.205.0-preview.258",
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": "699c58dabb59414557755a8933bcbe40aa420df3"
30
+ "gitHead": "8f629ee9fa89abf94f197436a60cb3b9620f8b27"
31
31
  }