@uipath/agent-tool 1.204.0-preview.255 → 1.205.0-preview.256

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getFileSystem
3
- } from "./packager-tool-2tf3hrem.js";
3
+ } from "./packager-tool-je2re4j6.js";
4
4
  import {
5
5
  __require
6
6
  } from "./packager-tool-1yh8g550.js";
@@ -182,22 +182,12 @@ var resolveConfigAsync = async ({
182
182
  baseUrl = DEFAULT_BASE_URL;
183
183
  }
184
184
  baseUrl = normalizeAndValidateBaseUrl(baseUrl);
185
- let clientId = customClientId;
186
- if (!clientId && fileAuth.clientId) {
187
- clientId = fileAuth.clientId;
188
- }
189
- if (!clientId) {
190
- clientId = DEFAULT_CLIENT_ID;
191
- }
192
- let clientSecret = customClientSecret;
193
- if (!clientSecret && fileAuth.clientSecret) {
194
- clientSecret = fileAuth.clientSecret;
195
- }
196
- const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(clientSecret) || Boolean(customClientAssertion));
185
+ const clientId = customClientId || DEFAULT_CLIENT_ID;
186
+ const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && (Boolean(customClientSecret) || Boolean(customClientAssertion));
197
187
  const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
198
188
  return {
199
189
  clientId,
200
- clientSecret,
190
+ clientSecret: customClientSecret,
201
191
  scopes,
202
192
  baseUrl,
203
193
  authorizationEndpoint: `${baseUrl}/identity_/connect/authorize`,
@@ -303,6 +293,16 @@ var resolveIdentityType = (claims, authFlow, email) => {
303
293
  }
304
294
  return;
305
295
  };
296
+ var resolveApplicationSubtype = (claims, authFlow) => {
297
+ switch (asString(claims?.sub_type)) {
298
+ case "service.external":
299
+ return "External";
300
+ case "service.internal":
301
+ return "Internal";
302
+ default:
303
+ return authFlow === "client_credentials" || authFlow === "federated_credentials" ? "External" : undefined;
304
+ }
305
+ };
306
306
  var looksLikeEmail = (value) => value?.includes("@") ?? false;
307
307
  var pickEmail = (claims) => {
308
308
  for (const candidate of [claims?.email, claims?.preferred_username]) {
@@ -344,6 +344,12 @@ var resolveSessionIdentity = (accessToken, authFlow) => {
344
344
  const clientId = asString(claims?.client_id);
345
345
  if (clientId)
346
346
  identity.clientId = clientId;
347
+ const subType = asString(claims?.sub_type);
348
+ if (subType)
349
+ identity.subType = subType;
350
+ const applicationSubtype = resolveApplicationSubtype(claims, authFlow);
351
+ if (applicationSubtype)
352
+ identity.applicationSubtype = applicationSubtype;
347
353
  return identity;
348
354
  };
349
355
  var readTokenScopes = (accessToken) => accessToken ? pickScopes(decodeClaims(accessToken)) : undefined;
@@ -636,6 +642,40 @@ var tryRobotClientFallback = async (options = {}) => {
636
642
  }
637
643
  };
638
644
 
645
+ // ../auth/src/tenantSelection.ts
646
+ var LOGIN_STATUS_HINT = "Run 'uip login status' to see the organization the CLI is signed in to.";
647
+ var organizationHint = (organizationId) => `The request used '${organizationId}' as the organization. ${LOGIN_STATUS_HINT}`;
648
+ var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
649
+ var describeNonJsonResponse = (organizationId, response, parseError) => {
650
+ if (response.redirected) {
651
+ 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}`;
652
+ }
653
+ const contentType = response.headers.get("content-type") ?? "unknown";
654
+ return `The organization service returned a '${contentType}' response instead ` + `of JSON: ${parseError.message}. ${organizationHint(organizationId)}`;
655
+ };
656
+ var fetchTenantsAndOrganizations = async (baseUrl, accessToken, organizationId, signal) => {
657
+ const url = `${baseUrl}/${organizationId}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo`;
658
+ const response = await fetch(url, {
659
+ headers: {
660
+ Authorization: `Bearer ${accessToken}`
661
+ },
662
+ ...signal ? { signal } : {}
663
+ });
664
+ if (!response.ok) {
665
+ if (response.status === 401) {
666
+ 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);
667
+ }
668
+ const errorText = await response.text();
669
+ const message = `Failed to get tenants and organizations: ${response.status} ${errorText}`;
670
+ throw new Error(IDENTIFIER_STATUSES.has(response.status) ? `${message}. ${organizationHint(organizationId)}` : message);
671
+ }
672
+ const [parseError, data] = await catchError(response.json());
673
+ if (parseError) {
674
+ throw new Error(describeNonJsonResponse(organizationId, response, parseError));
675
+ }
676
+ return data;
677
+ };
678
+
639
679
  // ../auth/src/tokenRefresh.ts
640
680
  var TOKEN_REFRESH_REAUTHENTICATE_MESSAGE = "Token refresh failed. Run 'uip login' to re-authenticate.";
641
681
 
@@ -848,6 +888,8 @@ var saveEnvFileAsync = async ({
848
888
  };
849
889
 
850
890
  // ../auth/src/loginStatus.ts
891
+ var defaultRobotTenantIdCache = new Map;
892
+ var ROBOT_TENANT_LOOKUP_TIMEOUT_MS = 5000;
851
893
  var getLoginStatusAsync = async (options = {}) => {
852
894
  return getLoginStatusWithDeps(options);
853
895
  };
@@ -860,12 +902,20 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
860
902
  refreshToken: refreshTokenFn = refreshAccessToken,
861
903
  resolveConfig = resolveConfigAsync,
862
904
  robotFallback = tryRobotClientFallback,
905
+ fetchTenantsAndOrgs = fetchTenantsAndOrganizations,
906
+ robotTenantIdCache = defaultRobotTenantIdCache,
907
+ robotTenantLookupTimeoutMs = ROBOT_TENANT_LOOKUP_TIMEOUT_MS,
863
908
  loadBreaker = loadRefreshBreaker,
864
909
  saveBreaker = saveRefreshBreaker,
865
910
  clearBreaker = clearRefreshBreaker
866
911
  } = deps;
912
+ const robotDeps = {
913
+ fetchTenantsAndOrgs,
914
+ cache: robotTenantIdCache,
915
+ lookupTimeoutMs: robotTenantLookupTimeoutMs
916
+ };
867
917
  if (isRobotAuthEnforced()) {
868
- return resolveRobotEnforcedStatus(robotFallback);
918
+ return resolveRobotEnforcedStatus(robotFallback, robotDeps);
869
919
  }
870
920
  if (isEnvAuthEnabled()) {
871
921
  return readAuthFromEnv();
@@ -883,7 +933,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
883
933
  hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
884
934
  };
885
935
  }
886
- return resolveBorrowedRobotStatus(robotFallback);
936
+ return resolveBorrowedRobotStatus(robotFallback, robotDeps);
887
937
  }
888
938
  const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
889
939
  if ("status" in loaded) {
@@ -925,7 +975,7 @@ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
925
975
  }
926
976
  return buildFileStatus(tokens, credentials, globalHint);
927
977
  };
928
- async function resolveRobotEnforcedStatus(robotFallback) {
978
+ async function resolveRobotEnforcedStatus(robotFallback, deps) {
929
979
  if (isEnvAuthEnabled()) {
930
980
  throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
931
981
  }
@@ -936,11 +986,11 @@ async function resolveRobotEnforcedStatus(robotFallback) {
936
986
  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.`
937
987
  };
938
988
  }
939
- return buildRobotStatus(robotCreds);
989
+ return buildRobotStatus(robotCreds, deps);
940
990
  }
941
- async function resolveBorrowedRobotStatus(robotFallback) {
991
+ async function resolveBorrowedRobotStatus(robotFallback, deps) {
942
992
  const robotCreds = await robotFallback();
943
- return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
993
+ return robotCreds ? buildRobotStatus(robotCreds, deps) : { loginStatus: "Not logged in" };
944
994
  }
945
995
  async function loadFileCredentials(loadEnvFile, absolutePath) {
946
996
  let credentials;
@@ -1075,9 +1125,10 @@ function identityFields(accessToken, credentials) {
1075
1125
  ...scopes ? { scopes } : {}
1076
1126
  };
1077
1127
  }
1078
- function buildRobotStatus(robotCreds) {
1128
+ async function buildRobotStatus(robotCreds, deps) {
1079
1129
  const identity = resolveSessionIdentity(robotCreds.accessToken);
1080
1130
  const scopes = readTokenScopes(robotCreds.accessToken);
1131
+ const tenant = robotCreds.tenantId ? { tenantId: robotCreds.tenantId } : await resolveRobotTenantId(robotCreds, deps);
1081
1132
  return {
1082
1133
  loginStatus: "Logged in",
1083
1134
  accessToken: robotCreds.accessToken,
@@ -1085,14 +1136,62 @@ function buildRobotStatus(robotCreds) {
1085
1136
  organizationName: robotCreds.organizationName,
1086
1137
  organizationId: robotCreds.organizationId,
1087
1138
  tenantName: robotCreds.tenantName,
1088
- tenantId: robotCreds.tenantId,
1139
+ tenantId: tenant.tenantId,
1089
1140
  issuer: robotCreds.issuer,
1090
1141
  expiration: getTokenExpiration(robotCreds.accessToken),
1091
1142
  source: "robot" /* Robot */,
1143
+ ...tenant.hint ? { hint: tenant.hint } : {},
1092
1144
  ...identity ? { identity } : {},
1093
1145
  ...scopes ? { scopes } : {}
1094
1146
  };
1095
1147
  }
1148
+ async function resolveRobotTenantId(robotCreds, deps) {
1149
+ const { baseUrl, accessToken, tenantName } = robotCreds;
1150
+ const organization = robotCreds.organizationName ?? robotCreds.organizationId;
1151
+ if (!tenantName || !organization) {
1152
+ return {};
1153
+ }
1154
+ const key = `${baseUrl}|${organization}|${tenantName}|${accessToken}`;
1155
+ let pending = deps.cache.get(key);
1156
+ if (!pending) {
1157
+ pending = catchError(lookupRobotTenantId({ baseUrl, accessToken, organization, tenantName }, deps)).then(([error, resolution]) => {
1158
+ const settled = error ? { hint: tenantLookupFailureHint(tenantName, error.message) } : resolution;
1159
+ if (!settled.tenantId) {
1160
+ deps.cache.delete(key);
1161
+ }
1162
+ return settled;
1163
+ });
1164
+ deps.cache.set(key, pending);
1165
+ }
1166
+ return pending;
1167
+ }
1168
+ async function lookupRobotTenantId(target, deps) {
1169
+ const { baseUrl, accessToken, organization, tenantName } = target;
1170
+ const [error, data] = await catchError(deps.fetchTenantsAndOrgs(baseUrl, accessToken, organization, AbortSignal.timeout(deps.lookupTimeoutMs)));
1171
+ if (error) {
1172
+ const reason = error.name === "TimeoutError" ? `the tenant list did not answer within ${deps.lookupTimeoutMs} ms.` : error.message;
1173
+ return { hint: tenantLookupFailureHint(tenantName, reason) };
1174
+ }
1175
+ const rows = data?.tenants;
1176
+ const tenants = Array.isArray(rows) ? rows.filter((tenant) => typeof tenant?.id === "string" && typeof tenant?.name === "string") : [];
1177
+ const wantedName = decodePathSegment(tenantName);
1178
+ const wanted = wantedName.toLowerCase();
1179
+ const match = tenants.find((tenant) => tenant.name === wantedName) ?? tenants.find((tenant) => tenant.name.toLowerCase() === wanted);
1180
+ if (!match) {
1181
+ const names = tenants.map((tenant) => tenant.name).join(", ");
1182
+ return {
1183
+ 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.`
1184
+ };
1185
+ }
1186
+ return { tenantId: match.id };
1187
+ }
1188
+ function tenantLookupFailureHint(tenantName, reason) {
1189
+ 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.`;
1190
+ }
1191
+ function decodePathSegment(segment) {
1192
+ const [error, decoded] = catchError(() => decodeURIComponent(segment));
1193
+ return error ? segment : decoded;
1194
+ }
1096
1195
  var isFileNotFoundError = (error) => {
1097
1196
  if (!(error instanceof Object))
1098
1197
  return false;
@@ -1361,9 +1460,6 @@ var getAuthContext = async (options = {}) => {
1361
1460
  identity: status.identity
1362
1461
  };
1363
1462
  };
1364
- // ../auth/src/tenantSelection.ts
1365
- var IDENTIFIER_STATUSES = new Set([400, 403, 404]);
1366
-
1367
1463
  // ../auth/src/selectTenant.ts
1368
1464
  var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
1369
1465
  var INVALID_TENANT_CODE = "INVALID_TENANT";
@@ -1371,6 +1467,6 @@ var TENANT_SELECTION_CODES = new Set([
1371
1467
  TENANT_SELECTION_REQUIRED_CODE,
1372
1468
  INVALID_TENANT_CODE
1373
1469
  ]);
1374
- export { parseJWT, getLoginStatusAsync, getAuthContext };
1470
+ export { parseJWT, resolveSessionIdentity, getLoginStatusAsync, getAuthContext };
1375
1471
 
1376
- //# debugId=2E898FF76A5D278A64756E2164756E21
1472
+ //# debugId=017ED5AAB2A212BB64756E2164756E21
@@ -0,0 +1,11 @@
1
+ import {
2
+ getSolutionAuthContext
3
+ } from "./packager-tool-7sbsrgd5.js";
4
+ import"./packager-tool-vwsq85y7.js";
5
+ import"./packager-tool-je2re4j6.js";
6
+ import"./packager-tool-1yh8g550.js";
7
+ export {
8
+ getSolutionAuthContext
9
+ };
10
+
11
+ //# debugId=4D0CD43FE95C1EC164756E2164756E21
package/dist/tool.js CHANGED
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  metadata,
3
3
  registerCommands
4
- } from "./packager-tool-vyry6fha.js";
4
+ } from "./packager-tool-1zdqafyj.js";
5
5
  import"./packager-tool-4mna26cc.js";
6
6
  import"./packager-tool-c23zrhj8.js";
7
- import"./packager-tool-n95spghc.js";
8
- import"./packager-tool-e9c9f8zx.js";
9
- import"./packager-tool-z8ryp7pb.js";
10
- import"./packager-tool-xxd71jja.js";
11
- import"./packager-tool-h4ymyb9t.js";
12
- import"./packager-tool-2tf3hrem.js";
7
+ import"./packager-tool-sda9pzxz.js";
8
+ import"./packager-tool-mrrc7jr3.js";
9
+ import"./packager-tool-jd8cfevc.js";
10
+ import"./packager-tool-607v4t05.js";
11
+ import"./packager-tool-vwsq85y7.js";
12
+ import"./packager-tool-fza8z686.js";
13
+ import"./packager-tool-je2re4j6.js";
13
14
  import"./packager-tool-thr9mncj.js";
14
15
  import"./packager-tool-b098y4a2.js";
15
16
  import"./packager-tool-1yh8g550.js";
@@ -18,4 +19,4 @@ export {
18
19
  registerCommands
19
20
  };
20
21
 
21
- //# debugId=6C6B1CCBC158CF9764756E2164756E21
22
+ //# debugId=4E0A5B04996A3AAE64756E2164756E21
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uipath/agent-tool",
3
3
  "author": "UiPath",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
- "version": "1.204.0-preview.255",
5
+ "version": "1.205.0-preview.256",
6
6
  "description": "cli plugin for creating and managing UiPath low-code agents",
7
7
  "private": false,
8
8
  "repository": {
@@ -29,5 +29,5 @@
29
29
  "files": [
30
30
  "dist"
31
31
  ],
32
- "gitHead": "699c58dabb59414557755a8933bcbe40aa420df3"
32
+ "gitHead": "63740c6cbb7ff282fa9118cc16a148eb030b245f"
33
33
  }