@uipath/aops-policy-sdk 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.
Files changed (2) hide show
  1. package/dist/index.js +135 -26
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -883,6 +883,16 @@ class NodeFileSystem {
883
883
  async rename(oldPath, newPath) {
884
884
  await fs6.rename(oldPath, newPath);
885
885
  }
886
+ async isSymbolicLink(filePath) {
887
+ try {
888
+ return (await fs6.lstat(filePath)).isSymbolicLink();
889
+ } catch (error) {
890
+ if (this.isEnoent(error) || this.hasErrnoCode(error, "ENOTDIR")) {
891
+ return false;
892
+ }
893
+ throw error;
894
+ }
895
+ }
886
896
  async realpath(filePath) {
887
897
  try {
888
898
  return await fs6.realpath(filePath);
@@ -1024,7 +1034,9 @@ var ErrorDimensions = {
1024
1034
  Result: "Result",
1025
1035
  ErrorCode: "ErrorCode",
1026
1036
  Retry: "Retry",
1027
- ErrorMessage: "ErrorMessage"
1037
+ ErrorMessage: "ErrorMessage",
1038
+ HttpStatus: "HttpStatus",
1039
+ UpstreamErrorCode: "UpstreamErrorCode"
1028
1040
  };
1029
1041
  var AuthDimensions = {
1030
1042
  AuthenticationMethod: "AuthenticationMethod",
@@ -1475,7 +1487,7 @@ var package_default = {
1475
1487
  name: "@uipath/aops-policy-sdk",
1476
1488
  author: "UiPath",
1477
1489
  license: "SEE LICENSE IN LICENSE.txt",
1478
- version: "1.204.0",
1490
+ version: "1.205.0-preview.258",
1479
1491
  description: "SDK for the UiPath AOps Governance API — policy management and deployment.",
1480
1492
  repository: {
1481
1493
  type: "git",
@@ -7007,22 +7019,12 @@ var resolveConfigAsync = async ({
7007
7019
  baseUrl = DEFAULT_BASE_URL;
7008
7020
  }
7009
7021
  baseUrl = normalizeAndValidateBaseUrl(baseUrl);
7010
- let clientId = customClientId;
7011
- if (!clientId && fileAuth.clientId) {
7012
- clientId = fileAuth.clientId;
7013
- }
7014
- if (!clientId) {
7015
- clientId = DEFAULT_CLIENT_ID;
7016
- }
7017
- let clientSecret = customClientSecret;
7018
- if (!clientSecret && fileAuth.clientSecret) {
7019
- clientSecret = fileAuth.clientSecret;
7020
- }
7021
- const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(clientSecret) || Boolean(customClientAssertion));
7022
+ const clientId = customClientId || DEFAULT_CLIENT_ID;
7023
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(customClientSecret) || Boolean(customClientAssertion));
7022
7024
  const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
7023
7025
  return {
7024
7026
  clientId,
7025
- clientSecret,
7027
+ clientSecret: customClientSecret,
7026
7028
  scopes,
7027
7029
  baseUrl,
7028
7030
  authorizationEndpoint: `${baseUrl}/identity_/connect/authorize`,
@@ -7197,6 +7199,16 @@ var resolveIdentityType = (claims, authFlow, email) => {
7197
7199
  }
7198
7200
  return;
7199
7201
  };
7202
+ var resolveApplicationSubtype = (claims, authFlow) => {
7203
+ switch (asString(claims?.sub_type)) {
7204
+ case "service.external":
7205
+ return "External";
7206
+ case "service.internal":
7207
+ return "Internal";
7208
+ default:
7209
+ return authFlow === "client_credentials" || authFlow === "federated_credentials" ? "External" : undefined;
7210
+ }
7211
+ };
7200
7212
  var looksLikeEmail = (value) => value?.includes("@") ?? false;
7201
7213
  var pickEmail = (claims) => {
7202
7214
  for (const candidate of [claims?.email, claims?.preferred_username]) {
@@ -7238,6 +7250,12 @@ var resolveSessionIdentity = (accessToken, authFlow) => {
7238
7250
  const clientId = asString(claims?.client_id);
7239
7251
  if (clientId)
7240
7252
  identity.clientId = clientId;
7253
+ const subType = asString(claims?.sub_type);
7254
+ if (subType)
7255
+ identity.subType = subType;
7256
+ const applicationSubtype = resolveApplicationSubtype(claims, authFlow);
7257
+ if (applicationSubtype)
7258
+ identity.applicationSubtype = applicationSubtype;
7241
7259
  return identity;
7242
7260
  };
7243
7261
  var readTokenScopes = (accessToken) => accessToken ? pickScopes(decodeClaims(accessToken)) : undefined;
@@ -7532,6 +7550,40 @@ var tryRobotClientFallback = async (options = {}) => {
7532
7550
  }
7533
7551
  };
7534
7552
 
7553
+ // ../../auth/src/tenantSelection.ts
7554
+ var LOGIN_STATUS_HINT = "Run 'uip login status' to see the organization the CLI is signed in to.";
7555
+ var organizationHint = (organizationId) => `The request used '${organizationId}' as the organization. ${LOGIN_STATUS_HINT}`;
7556
+ var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
7557
+ var describeNonJsonResponse = (organizationId, response, parseError) => {
7558
+ if (response.redirected) {
7559
+ 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}`;
7560
+ }
7561
+ const contentType = response.headers.get("content-type") ?? "unknown";
7562
+ return `The organization service returned a '${contentType}' response instead ` + `of JSON: ${parseError.message}. ${organizationHint(organizationId)}`;
7563
+ };
7564
+ var fetchTenantsAndOrganizations = async (baseUrl, accessToken, organizationId, signal) => {
7565
+ const url = `${baseUrl}/${organizationId}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo`;
7566
+ const response = await fetch(url, {
7567
+ headers: {
7568
+ Authorization: `Bearer ${accessToken}`
7569
+ },
7570
+ ...signal ? { signal } : {}
7571
+ });
7572
+ if (!response.ok) {
7573
+ if (response.status === 401) {
7574
+ 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);
7575
+ }
7576
+ const errorText = await response.text();
7577
+ const message = `Failed to get tenants and organizations: ${response.status} ${errorText}`;
7578
+ throw new Error(IDENTIFIER_STATUSES.has(response.status) ? `${message}. ${organizationHint(organizationId)}` : message);
7579
+ }
7580
+ const [parseError, data] = await catchError(response.json());
7581
+ if (parseError) {
7582
+ throw new Error(describeNonJsonResponse(organizationId, response, parseError));
7583
+ }
7584
+ return data;
7585
+ };
7586
+
7535
7587
  // ../../auth/src/tokenRefresh.ts
7536
7588
  var TOKEN_REFRESH_REAUTHENTICATE_MESSAGE = "Token refresh failed. Run 'uip login' to re-authenticate.";
7537
7589
 
@@ -7746,6 +7798,8 @@ var saveEnvFileAsync = async ({
7746
7798
  };
7747
7799
 
7748
7800
  // ../../auth/src/loginStatus.ts
7801
+ var defaultRobotTenantIdCache = new Map;
7802
+ var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
7749
7803
  var getLoginStatusAsync = async (options = {}) => {
7750
7804
  return getLoginStatusWithDeps(options);
7751
7805
  };
@@ -7758,12 +7812,20 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
7758
7812
  refreshToken: refreshTokenFn = refreshAccessToken,
7759
7813
  resolveConfig = resolveConfigAsync,
7760
7814
  robotFallback = tryRobotClientFallback,
7815
+ fetchTenantsAndOrgs = fetchTenantsAndOrganizations,
7816
+ robotTenantIdCache = defaultRobotTenantIdCache,
7817
+ robotTenantLookupTimeoutMs = ROBOT_TENANT_LOOKUP_TIMEOUT_MS,
7761
7818
  loadBreaker = loadRefreshBreaker,
7762
7819
  saveBreaker = saveRefreshBreaker,
7763
7820
  clearBreaker = clearRefreshBreaker
7764
7821
  } = deps;
7822
+ const robotDeps = {
7823
+ fetchTenantsAndOrgs,
7824
+ cache: robotTenantIdCache,
7825
+ lookupTimeoutMs: robotTenantLookupTimeoutMs
7826
+ };
7765
7827
  if (isRobotAuthEnforced()) {
7766
- return resolveRobotEnforcedStatus(robotFallback);
7828
+ return resolveRobotEnforcedStatus(robotFallback, robotDeps);
7767
7829
  }
7768
7830
  if (isEnvAuthEnabled()) {
7769
7831
  return readAuthFromEnv();
@@ -7781,7 +7843,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
7781
7843
  hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
7782
7844
  };
7783
7845
  }
7784
- return resolveBorrowedRobotStatus(robotFallback);
7846
+ return resolveBorrowedRobotStatus(robotFallback, robotDeps);
7785
7847
  }
7786
7848
  const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
7787
7849
  if ("status" in loaded) {
@@ -7823,7 +7885,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
7823
7885
  }
7824
7886
  return buildFileStatus(tokens, credentials, globalHint);
7825
7887
  };
7826
- async function resolveRobotEnforcedStatus(robotFallback) {
7888
+ async function resolveRobotEnforcedStatus(robotFallback, deps) {
7827
7889
  if (isEnvAuthEnabled()) {
7828
7890
  throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
7829
7891
  }
@@ -7834,11 +7896,11 @@ async function resolveRobotEnforcedStatus(robotFallback) {
7834
7896
  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.`
7835
7897
  };
7836
7898
  }
7837
- return buildRobotStatus(robotCreds);
7899
+ return buildRobotStatus(robotCreds, deps);
7838
7900
  }
7839
- async function resolveBorrowedRobotStatus(robotFallback) {
7901
+ async function resolveBorrowedRobotStatus(robotFallback, deps) {
7840
7902
  const robotCreds = await robotFallback();
7841
- return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
7903
+ return robotCreds ? buildRobotStatus(robotCreds, deps) : { loginStatus: "Not logged in" };
7842
7904
  }
7843
7905
  async function loadFileCredentials(loadEnvFile, absolutePath) {
7844
7906
  let credentials;
@@ -7973,9 +8035,10 @@ function identityFields(accessToken, credentials) {
7973
8035
  ...scopes ? { scopes } : {}
7974
8036
  };
7975
8037
  }
7976
- function buildRobotStatus(robotCreds) {
8038
+ async function buildRobotStatus(robotCreds, deps) {
7977
8039
  const identity = resolveSessionIdentity(robotCreds.accessToken);
7978
8040
  const scopes = readTokenScopes(robotCreds.accessToken);
8041
+ const tenant = robotCreds.tenantId ? { tenantId: robotCreds.tenantId } : await resolveRobotTenantId(robotCreds, deps);
7979
8042
  return {
7980
8043
  loginStatus: "Logged in",
7981
8044
  accessToken: robotCreds.accessToken,
@@ -7983,14 +8046,62 @@ function buildRobotStatus(robotCreds) {
7983
8046
  organizationName: robotCreds.organizationName,
7984
8047
  organizationId: robotCreds.organizationId,
7985
8048
  tenantName: robotCreds.tenantName,
7986
- tenantId: robotCreds.tenantId,
8049
+ tenantId: tenant.tenantId,
7987
8050
  issuer: robotCreds.issuer,
7988
8051
  expiration: getTokenExpiration(robotCreds.accessToken),
7989
8052
  source: "robot" /* Robot */,
8053
+ ...tenant.hint ? { hint: tenant.hint } : {},
7990
8054
  ...identity ? { identity } : {},
7991
8055
  ...scopes ? { scopes } : {}
7992
8056
  };
7993
8057
  }
8058
+ async function resolveRobotTenantId(robotCreds, deps) {
8059
+ const { baseUrl, accessToken, tenantName } = robotCreds;
8060
+ const organization = robotCreds.organizationName ?? robotCreds.organizationId;
8061
+ if (!tenantName || !organization) {
8062
+ return {};
8063
+ }
8064
+ const key = `${baseUrl}|${organization}|${tenantName}|${accessToken}`;
8065
+ let pending = deps.cache.get(key);
8066
+ if (!pending) {
8067
+ pending = catchError(lookupRobotTenantId({ baseUrl, accessToken, organization, tenantName }, deps)).then(([error, resolution]) => {
8068
+ const settled = error ? { hint: tenantLookupFailureHint(tenantName, error.message) } : resolution;
8069
+ if (!settled.tenantId) {
8070
+ deps.cache.delete(key);
8071
+ }
8072
+ return settled;
8073
+ });
8074
+ deps.cache.set(key, pending);
8075
+ }
8076
+ return pending;
8077
+ }
8078
+ async function lookupRobotTenantId(target, deps) {
8079
+ const { baseUrl, accessToken, organization, tenantName } = target;
8080
+ const [error, data] = await catchError(deps.fetchTenantsAndOrgs(baseUrl, accessToken, organization, AbortSignal.timeout(deps.lookupTimeoutMs)));
8081
+ if (error) {
8082
+ const reason = error.name === "TimeoutError" ? `the tenant list did not answer within ${deps.lookupTimeoutMs} ms.` : error.message;
8083
+ return { hint: tenantLookupFailureHint(tenantName, reason) };
8084
+ }
8085
+ const rows = data?.tenants;
8086
+ const tenants = Array.isArray(rows) ? rows.filter((tenant) => typeof tenant?.id === "string" && typeof tenant?.name === "string") : [];
8087
+ const wantedName = decodePathSegment(tenantName);
8088
+ const wanted = wantedName.toLowerCase();
8089
+ const match = tenants.find((tenant) => tenant.name === wantedName) ?? tenants.find((tenant) => tenant.name.toLowerCase() === wanted);
8090
+ if (!match) {
8091
+ const names = tenants.map((tenant) => tenant.name).join(", ");
8092
+ return {
8093
+ 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.`
8094
+ };
8095
+ }
8096
+ return { tenantId: match.id };
8097
+ }
8098
+ function tenantLookupFailureHint(tenantName, reason) {
8099
+ 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.`;
8100
+ }
8101
+ function decodePathSegment(segment) {
8102
+ const [error, decoded] = catchError(() => decodeURIComponent(segment));
8103
+ return error ? segment : decoded;
8104
+ }
7994
8105
  var isFileNotFoundError = (error) => {
7995
8106
  if (!(error instanceof Object))
7996
8107
  return false;
@@ -8234,8 +8345,6 @@ init_constants();
8234
8345
  // ../../auth/src/interactive.ts
8235
8346
  init_src();
8236
8347
  init_constants();
8237
- // ../../auth/src/tenantSelection.ts
8238
- var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
8239
8348
 
8240
8349
  // ../../auth/src/selectTenant.ts
8241
8350
  var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
@@ -8682,4 +8791,4 @@ export {
8682
8791
  querystring
8683
8792
  };
8684
8793
 
8685
- //# debugId=A85A7ABE810B783364756E2164756E21
8794
+ //# debugId=2B48815A466542C064756E2164756E21
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uipath/aops-policy-sdk",
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": "SDK for the UiPath AOps Governance API — policy management and deployment.",
7
7
  "repository": {
8
8
  "type": "git",
@@ -35,5 +35,5 @@
35
35
  "dist"
36
36
  ],
37
37
  "private": false,
38
- "gitHead": "699c58dabb59414557755a8933bcbe40aa420df3"
38
+ "gitHead": "8f629ee9fa89abf94f197436a60cb3b9620f8b27"
39
39
  }