@uipath/apms-tool 1.196.0 → 1.197.0-preview.59

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 (3) hide show
  1. package/dist/index.js +701 -1736
  2. package/dist/tool.js +702 -1736
  3. package/package.json +2 -2
package/dist/tool.js CHANGED
@@ -19137,7 +19137,7 @@ var init_server = __esm(() => {
19137
19137
  var package_default = {
19138
19138
  name: "@uipath/apms-tool",
19139
19139
  license: "MIT",
19140
- version: "1.196.0",
19140
+ version: "1.197.0-preview.59",
19141
19141
  description: "CLI plugin for the UiPath Access Policy Management Service.",
19142
19142
  private: false,
19143
19143
  repository: {
@@ -19163,7 +19163,7 @@ var package_default = {
19163
19163
  "dist"
19164
19164
  ],
19165
19165
  scripts: {
19166
- build: "bun build ./src/tool.ts --outdir dist --format esm --target node --external commander && bun build ./src/index.ts --outdir dist --format esm --target node",
19166
+ build: "bun build ./src/tool.ts --outdir dist --format esm --target node --external commander --sourcemap=linked && bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked",
19167
19167
  package: "bun run build && bun pm pack",
19168
19168
  lint: "biome check .",
19169
19169
  "lint:fix": "biome check --write .",
@@ -19211,6 +19211,12 @@ function singleton(ctorOrName) {
19211
19211
  };
19212
19212
  }
19213
19213
 
19214
+ // ../../common/src/telemetry/global-telemetry-properties.ts
19215
+ var telemetryPropsSlot = singleton("TelemetryDefaultProps");
19216
+ function getGlobalTelemetryProperties() {
19217
+ return telemetryPropsSlot.get();
19218
+ }
19219
+
19214
19220
  // ../../common/src/sdk-user-agent.ts
19215
19221
  var USER_AGENT_HEADER = "User-Agent";
19216
19222
  var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
@@ -19234,8 +19240,8 @@ function appendUserAgentToken(value, userAgent) {
19234
19240
  function getEffectiveUserAgent(userAgent) {
19235
19241
  return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
19236
19242
  }
19237
- function isHeadersLike(headers) {
19238
- return typeof headers === "object" && headers !== null && "get" in headers && typeof headers.get === "function" && "set" in headers && typeof headers.set === "function";
19243
+ function getHeaderName(headers, headerName) {
19244
+ return Object.keys(headers).find((key) => key.toLowerCase() === headerName.toLowerCase());
19239
19245
  }
19240
19246
  function getSdkUserAgentToken(pkg) {
19241
19247
  const packageName = pkg.name.replace(/^@uipath\//, "");
@@ -19243,59 +19249,31 @@ function getSdkUserAgentToken(pkg) {
19243
19249
  }
19244
19250
  function addSdkUserAgentHeader(headers, userAgent) {
19245
19251
  const result = { ...headers ?? {} };
19246
- const effectiveUserAgent = getEffectiveUserAgent(userAgent);
19247
- const headerName = Object.keys(result).find((key) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
19248
- if (headerName) {
19249
- result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
19250
- } else {
19251
- result[USER_AGENT_HEADER] = effectiveUserAgent;
19252
- }
19252
+ const headerName = getHeaderName(result, USER_AGENT_HEADER);
19253
+ result[headerName ?? USER_AGENT_HEADER] = appendUserAgentToken(headerName ? result[headerName] : undefined, getEffectiveUserAgent(userAgent));
19253
19254
  return result;
19254
19255
  }
19255
- function withSdkUserAgentHeader(headers, userAgent) {
19256
- const effectiveUserAgent = getEffectiveUserAgent(userAgent);
19257
- if (isHeadersLike(headers)) {
19258
- headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
19259
- return headers;
19260
- }
19261
- if (Array.isArray(headers)) {
19262
- const result = headers.map((entry) => {
19263
- const [key, value] = entry;
19264
- return [key, value];
19265
- });
19266
- const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
19267
- if (headerIndex >= 0) {
19268
- const [key, value] = result[headerIndex];
19269
- result[headerIndex] = [
19270
- key,
19271
- appendUserAgentToken(value, effectiveUserAgent)
19272
- ];
19273
- } else {
19274
- result.push([USER_AGENT_HEADER, effectiveUserAgent]);
19275
- }
19276
- return result;
19277
- }
19278
- return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
19256
+ function asHeaderRecord(headers) {
19257
+ return typeof headers === "object" && headers !== null ? { ...headers } : {};
19279
19258
  }
19280
- function withUserAgentInitOverride(initOverrides, userAgent) {
19259
+ function withForwardedHeadersInitOverride(initOverrides, forward) {
19281
19260
  return async (requestContext) => {
19282
- const initWithUserAgent = {
19261
+ const initWithHeaders = {
19283
19262
  ...requestContext.init,
19284
- headers: withSdkUserAgentHeader(requestContext.init.headers, userAgent)
19263
+ headers: forward(asHeaderRecord(requestContext.init.headers))
19285
19264
  };
19286
19265
  const override = typeof initOverrides === "function" ? await initOverrides({
19287
19266
  ...requestContext,
19288
- init: initWithUserAgent
19267
+ init: initWithHeaders
19289
19268
  }) : initOverrides;
19290
19269
  return {
19291
19270
  ...override ?? {},
19292
- headers: withSdkUserAgentHeader(override?.headers ?? initWithUserAgent.headers, userAgent)
19271
+ headers: forward(asHeaderRecord(override?.headers ?? initWithHeaders.headers))
19293
19272
  };
19294
19273
  };
19295
19274
  }
19296
- function installSdkUserAgentHeader(BaseApiClass, userAgent) {
19275
+ function installRequestHeaderForwarding(BaseApiClass, patchKey, forward) {
19297
19276
  const prototype = BaseApiClass.prototype;
19298
- const patchKey = userAgentPatchKey(userAgent);
19299
19277
  if (prototype[patchKey]) {
19300
19278
  return;
19301
19279
  }
@@ -19303,13 +19281,16 @@ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
19303
19281
  throw new Error("Generated BaseAPI request function not found.");
19304
19282
  }
19305
19283
  const originalRequest = prototype.request;
19306
- prototype.request = function requestWithUserAgent(context, initOverrides) {
19307
- return originalRequest.call(this, context, withUserAgentInitOverride(initOverrides, userAgent));
19284
+ prototype.request = function requestWithForwardedHeaders(context, initOverrides) {
19285
+ return originalRequest.call(this, context, withForwardedHeadersInitOverride(initOverrides, forward));
19308
19286
  };
19309
19287
  Object.defineProperty(prototype, patchKey, {
19310
19288
  value: true
19311
19289
  });
19312
19290
  }
19291
+ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
19292
+ installRequestHeaderForwarding(BaseApiClass, userAgentPatchKey(userAgent), (headers) => addSdkUserAgentHeader(headers, userAgent));
19293
+ }
19313
19294
 
19314
19295
  // ../apms-sdk/generated/src/runtime.ts
19315
19296
  var BASE_PATH = "http://localhost:35599".replace(/\/+$/, "");
@@ -19564,7 +19545,7 @@ class VoidApiResponse {
19564
19545
  var package_default2 = {
19565
19546
  name: "@uipath/apms-sdk",
19566
19547
  license: "MIT",
19567
- version: "1.196.0",
19548
+ version: "1.197.0",
19568
19549
  description: "SDK for the UiPath Access Policy Management Service API.",
19569
19550
  repository: {
19570
19551
  type: "git",
@@ -19594,7 +19575,7 @@ var package_default2 = {
19594
19575
  ],
19595
19576
  private: true,
19596
19577
  scripts: {
19597
- build: "bun build ./src/index.ts --outdir dist --format esm --target node && tsc -p tsconfig.build.json --noCheck",
19578
+ build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
19598
19579
  generate: "bun run src/scripts/generate-sdk.ts",
19599
19580
  lint: "biome check ."
19600
19581
  },
@@ -20635,6 +20616,12 @@ var normalizeAndValidateBaseUrl = (rawUrl) => {
20635
20616
  }
20636
20617
  return url.pathname.length > 1 ? url.origin : baseUrl;
20637
20618
  };
20619
+ var resolveScopes = (isExternalAppAuth, customScopes, fileScopes) => {
20620
+ const requestedScopes = customScopes?.length ? customScopes : fileScopes ?? [];
20621
+ if (isExternalAppAuth)
20622
+ return requestedScopes;
20623
+ return [...new Set([...DEFAULT_SCOPES, ...requestedScopes])];
20624
+ };
20638
20625
  var resolveConfigAsync = async ({
20639
20626
  customAuthority,
20640
20627
  customClientId,
@@ -20665,7 +20652,7 @@ var resolveConfigAsync = async ({
20665
20652
  clientSecret = fileAuth.clientSecret;
20666
20653
  }
20667
20654
  const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && Boolean(clientSecret);
20668
- const scopes = customScopes && customScopes.length > 0 ? customScopes : fileAuth.scopes && fileAuth.scopes.length > 0 ? fileAuth.scopes : isExternalAppAuth ? [] : DEFAULT_SCOPES;
20655
+ const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
20669
20656
  return {
20670
20657
  clientId,
20671
20658
  clientSecret,
@@ -20680,6 +20667,76 @@ var resolveConfigAsync = async ({
20680
20667
  init_constants();
20681
20668
  // ../../auth/src/loginStatus.ts
20682
20669
  init_src();
20670
+
20671
+ // ../../auth/src/authProfile.ts
20672
+ init_src();
20673
+ init_constants();
20674
+ var DEFAULT_AUTH_PROFILE = "default";
20675
+ var PROFILE_DIR = "profiles";
20676
+ var PROFILE_NAME_RE = /^[A-Za-z0-9._-]+$/;
20677
+ var ACTIVE_AUTH_PROFILE_KEY = Symbol.for("@uipath/auth/ActiveAuthProfile");
20678
+ var AUTH_PROFILE_STORAGE_KEY = Symbol.for("@uipath/auth/ProfileStorage");
20679
+ var globalSlot2 = globalThis;
20680
+ function isAuthProfileStorage(value) {
20681
+ return value !== null && typeof value === "object" && "getStore" in value && "run" in value;
20682
+ }
20683
+ function createProfileStorage() {
20684
+ const [error, mod] = catchError(() => __require("node:async_hooks"));
20685
+ if (error || typeof mod?.AsyncLocalStorage !== "function") {
20686
+ return {
20687
+ getStore: () => {
20688
+ return;
20689
+ },
20690
+ run: (_store, fn) => fn()
20691
+ };
20692
+ }
20693
+ return new mod.AsyncLocalStorage;
20694
+ }
20695
+ function getProfileStorage() {
20696
+ const existing = globalSlot2[AUTH_PROFILE_STORAGE_KEY];
20697
+ if (isAuthProfileStorage(existing)) {
20698
+ return existing;
20699
+ }
20700
+ const storage = createProfileStorage();
20701
+ globalSlot2[AUTH_PROFILE_STORAGE_KEY] = storage;
20702
+ return storage;
20703
+ }
20704
+ var profileStorage = getProfileStorage();
20705
+
20706
+ class AuthProfileValidationError extends Error {
20707
+ constructor(message) {
20708
+ super(message);
20709
+ this.name = "AuthProfileValidationError";
20710
+ }
20711
+ }
20712
+ function normalizeAuthProfileName(profile) {
20713
+ if (profile === undefined || profile === DEFAULT_AUTH_PROFILE) {
20714
+ return;
20715
+ }
20716
+ if (profile.length === 0 || profile === "." || profile === ".." || !PROFILE_NAME_RE.test(profile)) {
20717
+ throw new AuthProfileValidationError(`Invalid profile name "${profile}". Profile names may contain only letters, numbers, '.', '_', and '-'.`);
20718
+ }
20719
+ return profile;
20720
+ }
20721
+ function getActiveAuthProfile() {
20722
+ const scopedState = profileStorage.getStore();
20723
+ if (scopedState !== undefined) {
20724
+ return scopedState.profile;
20725
+ }
20726
+ return globalSlot2[ACTIVE_AUTH_PROFILE_KEY]?.profile;
20727
+ }
20728
+ function resolveAuthProfileFilePath(profile) {
20729
+ const normalized = normalizeAuthProfileName(profile);
20730
+ if (normalized === undefined) {
20731
+ throw new AuthProfileValidationError(`"${DEFAULT_AUTH_PROFILE}" is the built-in profile and does not have a profile file path.`);
20732
+ }
20733
+ const fs7 = getFileSystem();
20734
+ return fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR, normalized, AUTH_FILENAME);
20735
+ }
20736
+ function getActiveAuthProfileFilePath() {
20737
+ const profile = getActiveAuthProfile();
20738
+ return profile ? resolveAuthProfileFilePath(profile) : undefined;
20739
+ }
20683
20740
  // ../../auth/src/utils/jwt.ts
20684
20741
  class InvalidIssuerError extends Error {
20685
20742
  expected;
@@ -20808,23 +20865,74 @@ var readAuthFromEnv = () => {
20808
20865
  organizationId,
20809
20866
  tenantName,
20810
20867
  tenantId,
20811
- expiration
20868
+ expiration,
20869
+ source: "env" /* Env */
20812
20870
  };
20813
20871
  };
20814
20872
 
20873
+ // ../../auth/src/refreshCircuitBreaker.ts
20874
+ init_src();
20875
+ var BREAKER_SUFFIX = ".refresh-state";
20876
+ var BACKOFF_BASE_MS = 60000;
20877
+ var BACKOFF_CAP_MS = 60 * 60 * 1000;
20878
+ var SURFACE_WINDOW_MS = 60 * 60 * 1000;
20879
+ async function refreshTokenFingerprint(refreshToken) {
20880
+ const bytes = new TextEncoder().encode(refreshToken);
20881
+ if (globalThis.crypto?.subtle) {
20882
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
20883
+ return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
20884
+ }
20885
+ const { createHash } = await import("node:crypto");
20886
+ return createHash("sha256").update(refreshToken).digest("hex").slice(0, 16);
20887
+ }
20888
+ function breakerPathFor(authPath) {
20889
+ return `${authPath}${BREAKER_SUFFIX}`;
20890
+ }
20891
+ async function loadRefreshBreaker(authPath) {
20892
+ const fs7 = getFileSystem();
20893
+ try {
20894
+ const content = await fs7.readFile(breakerPathFor(authPath), "utf-8");
20895
+ if (!content)
20896
+ return {};
20897
+ const parsed = JSON.parse(content);
20898
+ return parsed && typeof parsed === "object" ? parsed : {};
20899
+ } catch {
20900
+ return {};
20901
+ }
20902
+ }
20903
+ async function saveRefreshBreaker(authPath, state) {
20904
+ try {
20905
+ const fs7 = getFileSystem();
20906
+ const path3 = breakerPathFor(authPath);
20907
+ await fs7.mkdir(fs7.path.dirname(path3));
20908
+ const tempPath = `${path3}.tmp`;
20909
+ await fs7.writeFile(tempPath, JSON.stringify(state));
20910
+ await fs7.rename(tempPath, path3);
20911
+ } catch {}
20912
+ }
20913
+ async function clearRefreshBreaker(authPath) {
20914
+ const fs7 = getFileSystem();
20915
+ const path3 = breakerPathFor(authPath);
20916
+ try {
20917
+ if (await fs7.exists(path3)) {
20918
+ await fs7.rm(path3);
20919
+ }
20920
+ } catch {}
20921
+ }
20922
+ function nextBackoffMs(attempts) {
20923
+ const shift = Math.max(0, attempts - 1);
20924
+ return Math.min(BACKOFF_BASE_MS * 2 ** shift, BACKOFF_CAP_MS);
20925
+ }
20926
+ function shouldSurface(state, nowMs) {
20927
+ if (state.lastSurfacedAtMs === undefined)
20928
+ return true;
20929
+ return nowMs - state.lastSurfacedAtMs >= SURFACE_WINDOW_MS;
20930
+ }
20931
+
20815
20932
  // ../../auth/src/robotClientFallback.ts
20816
20933
  init_src();
20817
20934
  var DEFAULT_TIMEOUT_MS = 1000;
20818
20935
  var CLOSE_TIMEOUT_MS = 500;
20819
- var NOTICE_SENTINEL = Symbol.for("@uipath/auth/robotFallbackNoticePrinted");
20820
- var printNoticeOnce = () => {
20821
- const slot = globalThis;
20822
- if (slot[NOTICE_SENTINEL])
20823
- return;
20824
- slot[NOTICE_SENTINEL] = true;
20825
- catchError(() => process.stderr.write(`Using UiPath Robot credentials. Run 'uip login' for a dedicated session.
20826
- `));
20827
- };
20828
20936
  var ROBOT_USER_SERVICES_PIPE = "UiPathUserServices";
20829
20937
  var ROBOT_USER_SERVICES_ALTERNATE_PIPE = `${ROBOT_USER_SERVICES_PIPE}Alternate`;
20830
20938
  var PIPE_NAME_MAX_LENGTH = 103;
@@ -20940,7 +21048,6 @@ var tryRobotClientFallback = async (options = {}) => {
20940
21048
  issuerFromToken = issClaim;
20941
21049
  }
20942
21050
  }
20943
- printNoticeOnce();
20944
21051
  return {
20945
21052
  accessToken,
20946
21053
  baseUrl: parsedUrl.baseUrl,
@@ -21165,18 +21272,327 @@ var saveEnvFileAsync = async ({
21165
21272
  };
21166
21273
 
21167
21274
  // ../../auth/src/loginStatus.ts
21168
- function normalizeTokenRefreshFailure() {
21169
- return "stored refresh token is invalid or expired";
21275
+ var getLoginStatusAsync = async (options = {}) => {
21276
+ return getLoginStatusWithDeps(options);
21277
+ };
21278
+ var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
21279
+ const {
21280
+ resolveEnvFilePath = resolveEnvFilePathAsync,
21281
+ loadEnvFile = loadEnvFileAsync,
21282
+ saveEnvFile = saveEnvFileAsync,
21283
+ getFs = getFileSystem,
21284
+ refreshToken: refreshTokenFn = refreshAccessToken,
21285
+ resolveConfig = resolveConfigAsync,
21286
+ robotFallback = tryRobotClientFallback,
21287
+ loadBreaker = loadRefreshBreaker,
21288
+ saveBreaker = saveRefreshBreaker,
21289
+ clearBreaker = clearRefreshBreaker
21290
+ } = deps;
21291
+ if (isRobotAuthEnforced()) {
21292
+ return resolveRobotEnforcedStatus(robotFallback);
21293
+ }
21294
+ if (isEnvAuthEnabled()) {
21295
+ return readAuthFromEnv();
21296
+ }
21297
+ const activeProfile = getActiveAuthProfile();
21298
+ const activeProfileFilePath = getActiveAuthProfileFilePath();
21299
+ const usingActiveProfile = activeProfile !== undefined && (options.envFilePath === undefined || options.envFilePath === activeProfileFilePath);
21300
+ const envFilePath = options.envFilePath ?? activeProfileFilePath ?? DEFAULT_ENV_FILENAME;
21301
+ const { ensureTokenValidityMinutes } = options;
21302
+ const { absolutePath } = await resolveEnvFilePath(envFilePath);
21303
+ if (absolutePath === undefined) {
21304
+ if (usingActiveProfile) {
21305
+ return {
21306
+ loginStatus: "Not logged in",
21307
+ hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
21308
+ };
21309
+ }
21310
+ return resolveBorrowedRobotStatus(robotFallback);
21311
+ }
21312
+ const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
21313
+ if ("status" in loaded) {
21314
+ return loaded.status;
21315
+ }
21316
+ const { credentials } = loaded;
21317
+ const globalHint = () => usingActiveProfile ? Promise.resolve(undefined) : getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath);
21318
+ const expiration = getTokenExpiration(credentials.UIPATH_ACCESS_TOKEN);
21319
+ const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
21320
+ let tokens = {
21321
+ accessToken: credentials.UIPATH_ACCESS_TOKEN,
21322
+ refreshToken: credentials.UIPATH_REFRESH_TOKEN,
21323
+ expiration,
21324
+ lockReleaseFailed: false
21325
+ };
21326
+ const refreshToken = credentials.UIPATH_REFRESH_TOKEN;
21327
+ if (expiration && expiration <= outerThreshold && refreshToken) {
21328
+ const refreshed = await attemptRefresh({
21329
+ absolutePath,
21330
+ credentials,
21331
+ accessToken: credentials.UIPATH_ACCESS_TOKEN,
21332
+ refreshToken,
21333
+ expiration,
21334
+ ensureTokenValidityMinutes,
21335
+ getFs,
21336
+ loadEnvFile,
21337
+ saveEnvFile,
21338
+ refreshFn: refreshTokenFn,
21339
+ resolveConfig,
21340
+ loadBreaker,
21341
+ saveBreaker,
21342
+ clearBreaker,
21343
+ globalHint
21344
+ });
21345
+ if (refreshed.kind === "terminal") {
21346
+ return refreshed.status;
21347
+ }
21348
+ tokens = refreshed.tokens;
21349
+ }
21350
+ return buildFileStatus(tokens, credentials, globalHint);
21351
+ };
21352
+ async function resolveRobotEnforcedStatus(robotFallback) {
21353
+ if (isEnvAuthEnabled()) {
21354
+ throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
21355
+ }
21356
+ const robotCreds = await robotFallback({ force: true });
21357
+ if (!robotCreds) {
21358
+ return {
21359
+ loginStatus: "Not logged in",
21360
+ 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.`
21361
+ };
21362
+ }
21363
+ return buildRobotStatus(robotCreds);
21170
21364
  }
21171
- function normalizeTokenRefreshUnavailableFailure() {
21172
- return "token refresh failed before authentication completed";
21365
+ async function resolveBorrowedRobotStatus(robotFallback) {
21366
+ const robotCreds = await robotFallback();
21367
+ return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
21173
21368
  }
21174
- function errorMessage(error) {
21175
- return error instanceof Error ? error.message : String(error);
21369
+ async function loadFileCredentials(loadEnvFile, absolutePath) {
21370
+ let credentials;
21371
+ try {
21372
+ credentials = await loadEnvFile({ envPath: absolutePath });
21373
+ } catch (error) {
21374
+ if (isFileNotFoundError(error)) {
21375
+ return { status: { loginStatus: "Not logged in" } };
21376
+ }
21377
+ throw error;
21378
+ }
21379
+ if (!credentials.UIPATH_ACCESS_TOKEN) {
21380
+ return { status: { loginStatus: "Not logged in" } };
21381
+ }
21382
+ return { credentials };
21383
+ }
21384
+ async function getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath) {
21385
+ const fs7 = getFs();
21386
+ const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
21387
+ if (absolutePath === globalPath)
21388
+ return;
21389
+ if (!await fs7.exists(globalPath))
21390
+ return;
21391
+ try {
21392
+ const globalCreds = await loadEnvFile({ envPath: globalPath });
21393
+ if (!globalCreds.UIPATH_ACCESS_TOKEN)
21394
+ return;
21395
+ const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
21396
+ if (globalExp && globalExp <= new Date)
21397
+ return;
21398
+ 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.`;
21399
+ } catch {
21400
+ return;
21401
+ }
21176
21402
  }
21177
21403
  function computeExpirationThreshold(ensureTokenValidityMinutes) {
21178
21404
  return new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
21179
21405
  }
21406
+ async function attemptRefresh(ctx) {
21407
+ const shortCircuit = await circuitBreakerShortCircuit(ctx);
21408
+ if (shortCircuit) {
21409
+ return { kind: "terminal", status: shortCircuit };
21410
+ }
21411
+ let release;
21412
+ try {
21413
+ release = await ctx.getFs().acquireLock(ctx.absolutePath);
21414
+ } catch (error) {
21415
+ return {
21416
+ kind: "terminal",
21417
+ status: await lockAcquireFailureStatus(ctx, error)
21418
+ };
21419
+ }
21420
+ let lockedFailure;
21421
+ let lockReleaseFailed = false;
21422
+ let success;
21423
+ try {
21424
+ const outcome = await runRefreshLocked({
21425
+ absolutePath: ctx.absolutePath,
21426
+ refreshToken: ctx.refreshToken,
21427
+ customAuthority: ctx.credentials.UIPATH_URL,
21428
+ ensureTokenValidityMinutes: ctx.ensureTokenValidityMinutes,
21429
+ loadEnvFile: ctx.loadEnvFile,
21430
+ saveEnvFile: ctx.saveEnvFile,
21431
+ refreshFn: ctx.refreshFn,
21432
+ resolveConfig: ctx.resolveConfig,
21433
+ loadBreaker: ctx.loadBreaker,
21434
+ saveBreaker: ctx.saveBreaker,
21435
+ clearBreaker: ctx.clearBreaker
21436
+ });
21437
+ if (outcome.kind === "fail") {
21438
+ lockedFailure = outcome.status;
21439
+ } else {
21440
+ success = outcome;
21441
+ }
21442
+ } finally {
21443
+ try {
21444
+ await release();
21445
+ } catch {
21446
+ lockReleaseFailed = true;
21447
+ }
21448
+ }
21449
+ if (lockedFailure) {
21450
+ const globalHint = await ctx.globalHint();
21451
+ const base = globalHint ? { ...lockedFailure, loginStatus: "Expired", hint: globalHint } : lockedFailure;
21452
+ return {
21453
+ kind: "terminal",
21454
+ status: lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base
21455
+ };
21456
+ }
21457
+ return {
21458
+ kind: "refreshed",
21459
+ tokens: {
21460
+ accessToken: success?.accessToken,
21461
+ refreshToken: success?.refreshToken,
21462
+ expiration: success?.expiration,
21463
+ tokenRefresh: success?.tokenRefresh,
21464
+ persistenceWarning: success?.persistenceWarning,
21465
+ lockReleaseFailed
21466
+ }
21467
+ };
21468
+ }
21469
+ async function buildFileStatus(tokens, credentials, globalHint) {
21470
+ const result = {
21471
+ loginStatus: tokens.expiration && tokens.expiration <= new Date ? "Expired" : "Logged in",
21472
+ accessToken: tokens.accessToken,
21473
+ refreshToken: tokens.refreshToken,
21474
+ baseUrl: credentials.UIPATH_URL,
21475
+ organizationName: credentials.UIPATH_ORGANIZATION_NAME,
21476
+ organizationId: credentials.UIPATH_ORGANIZATION_ID,
21477
+ tenantName: credentials.UIPATH_TENANT_NAME,
21478
+ tenantId: credentials.UIPATH_TENANT_ID,
21479
+ expiration: tokens.expiration,
21480
+ source: "file" /* File */,
21481
+ ...tokens.persistenceWarning ? { hint: tokens.persistenceWarning, persistenceFailed: true } : {},
21482
+ ...tokens.lockReleaseFailed ? { lockReleaseFailed: true } : {},
21483
+ ...tokens.tokenRefresh ? { tokenRefresh: tokens.tokenRefresh } : {}
21484
+ };
21485
+ if (result.loginStatus === "Expired") {
21486
+ const hint = await globalHint();
21487
+ if (hint) {
21488
+ result.hint = hint;
21489
+ }
21490
+ }
21491
+ return result;
21492
+ }
21493
+ function buildRobotStatus(robotCreds) {
21494
+ return {
21495
+ loginStatus: "Logged in",
21496
+ accessToken: robotCreds.accessToken,
21497
+ baseUrl: robotCreds.baseUrl,
21498
+ organizationName: robotCreds.organizationName,
21499
+ organizationId: robotCreds.organizationId,
21500
+ tenantName: robotCreds.tenantName,
21501
+ tenantId: robotCreds.tenantId,
21502
+ issuer: robotCreds.issuer,
21503
+ expiration: getTokenExpiration(robotCreds.accessToken),
21504
+ source: "robot" /* Robot */
21505
+ };
21506
+ }
21507
+ var isFileNotFoundError = (error) => {
21508
+ if (!(error instanceof Object))
21509
+ return false;
21510
+ return error.code === "ENOENT";
21511
+ };
21512
+ async function circuitBreakerShortCircuit(ctx) {
21513
+ const {
21514
+ absolutePath,
21515
+ refreshToken,
21516
+ accessToken,
21517
+ credentials,
21518
+ expiration,
21519
+ loadBreaker,
21520
+ saveBreaker,
21521
+ clearBreaker
21522
+ } = ctx;
21523
+ const fingerprint = await refreshTokenFingerprint(refreshToken);
21524
+ const breaker = await loadBreaker(absolutePath).catch(() => ({}));
21525
+ if (breaker.deadTokenFp && breaker.deadTokenFp !== fingerprint) {
21526
+ await clearBreaker(absolutePath);
21527
+ breaker.deadTokenFp = undefined;
21528
+ }
21529
+ const nowMs = Date.now();
21530
+ const tokenIsDead = breaker.deadTokenFp === fingerprint;
21531
+ const inBackoff = breaker.backoffUntilMs !== undefined && nowMs < breaker.backoffUntilMs;
21532
+ if (!tokenIsDead && !inBackoff)
21533
+ return;
21534
+ const globalHint = await ctx.globalHint();
21535
+ const suppressed = !shouldSurface(breaker, nowMs);
21536
+ if (!suppressed) {
21537
+ await saveBreaker(absolutePath, {
21538
+ ...breaker,
21539
+ lastSurfacedAtMs: nowMs
21540
+ });
21541
+ }
21542
+ const deadHint = "Run 'uip login' to re-authenticate — the stored refresh token is invalid or expired. In a non-interactive context, authenticate with: uip login --client-id <id> --client-secret <secret> -t <tenant>.";
21543
+ const backoffHint = "Token refresh is temporarily backed off after a recent network error and will retry automatically once the backoff window elapses.";
21544
+ return {
21545
+ loginStatus: globalHint ? "Expired" : "Refresh Failed",
21546
+ ...globalHint ? {
21547
+ accessToken,
21548
+ refreshToken,
21549
+ baseUrl: credentials.UIPATH_URL,
21550
+ organizationName: credentials.UIPATH_ORGANIZATION_NAME,
21551
+ organizationId: credentials.UIPATH_ORGANIZATION_ID,
21552
+ tenantName: credentials.UIPATH_TENANT_NAME,
21553
+ tenantId: credentials.UIPATH_TENANT_ID,
21554
+ expiration,
21555
+ source: "file" /* File */
21556
+ } : {},
21557
+ hint: globalHint ?? (tokenIsDead ? deadHint : backoffHint),
21558
+ refreshCircuitOpen: true,
21559
+ refreshTelemetrySuppressed: suppressed,
21560
+ tokenRefresh: { attempted: false, success: false }
21561
+ };
21562
+ }
21563
+ async function lockAcquireFailureStatus(ctx, error) {
21564
+ const msg = errorMessage(error);
21565
+ const globalHint = await ctx.globalHint();
21566
+ if (globalHint) {
21567
+ return {
21568
+ loginStatus: "Expired",
21569
+ accessToken: ctx.accessToken,
21570
+ refreshToken: ctx.refreshToken,
21571
+ baseUrl: ctx.credentials.UIPATH_URL,
21572
+ organizationName: ctx.credentials.UIPATH_ORGANIZATION_NAME,
21573
+ organizationId: ctx.credentials.UIPATH_ORGANIZATION_ID,
21574
+ tenantName: ctx.credentials.UIPATH_TENANT_NAME,
21575
+ tenantId: ctx.credentials.UIPATH_TENANT_ID,
21576
+ expiration: ctx.expiration,
21577
+ source: "file" /* File */,
21578
+ hint: globalHint,
21579
+ tokenRefresh: {
21580
+ attempted: false,
21581
+ success: false,
21582
+ errorMessage: `lock acquisition failed: ${msg}`
21583
+ }
21584
+ };
21585
+ }
21586
+ return {
21587
+ loginStatus: "Refresh Failed",
21588
+ 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.",
21589
+ tokenRefresh: {
21590
+ attempted: false,
21591
+ success: false,
21592
+ errorMessage: `lock acquisition failed: ${msg}`
21593
+ }
21594
+ };
21595
+ }
21180
21596
  async function runRefreshLocked(inputs) {
21181
21597
  const {
21182
21598
  absolutePath,
@@ -21186,7 +21602,10 @@ async function runRefreshLocked(inputs) {
21186
21602
  loadEnvFile,
21187
21603
  saveEnvFile,
21188
21604
  refreshFn,
21189
- resolveConfig
21605
+ resolveConfig,
21606
+ loadBreaker,
21607
+ saveBreaker,
21608
+ clearBreaker
21190
21609
  } = inputs;
21191
21610
  const expirationThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
21192
21611
  let fresh;
@@ -21209,6 +21628,7 @@ async function runRefreshLocked(inputs) {
21209
21628
  const freshAccess = fresh.UIPATH_ACCESS_TOKEN;
21210
21629
  const freshExp = freshAccess ? getTokenExpiration(freshAccess) : undefined;
21211
21630
  if (freshAccess && freshExp && freshExp > expirationThreshold) {
21631
+ await clearBreaker(absolutePath);
21212
21632
  return {
21213
21633
  kind: "ok",
21214
21634
  accessToken: freshAccess,
@@ -21232,8 +21652,21 @@ async function runRefreshLocked(inputs) {
21232
21652
  refreshedRefresh = refreshed.refreshToken;
21233
21653
  } catch (error) {
21234
21654
  const isOAuthFailure = isTokenRefreshOAuthFailure(error);
21235
- 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.";
21655
+ const hint = isOAuthFailure ? "Run 'uip login' to re-authenticate — the stored refresh token is invalid or expired. In a non-interactive context, authenticate with: uip login --client-id <id> --client-secret <secret> -t <tenant>." : "Token refresh failed. Check your network connection, then retry or run 'uip login' to re-authenticate.";
21236
21656
  const message = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
21657
+ const fp = await refreshTokenFingerprint(tokenForIdP);
21658
+ if (isOAuthFailure) {
21659
+ await saveBreaker(absolutePath, { deadTokenFp: fp });
21660
+ } else {
21661
+ const prior = await loadBreaker(absolutePath).catch(() => ({}));
21662
+ const attempts = (prior.attempts ?? 0) + 1;
21663
+ await saveBreaker(absolutePath, {
21664
+ ...prior,
21665
+ deadTokenFp: undefined,
21666
+ attempts,
21667
+ backoffUntilMs: Date.now() + nextBackoffMs(attempts)
21668
+ });
21669
+ }
21237
21670
  return {
21238
21671
  kind: "fail",
21239
21672
  status: {
@@ -21262,6 +21695,7 @@ async function runRefreshLocked(inputs) {
21262
21695
  }
21263
21696
  };
21264
21697
  }
21698
+ await clearBreaker(absolutePath);
21265
21699
  try {
21266
21700
  await saveEnvFile({
21267
21701
  envPath: absolutePath,
@@ -21294,231 +21728,42 @@ async function runRefreshLocked(inputs) {
21294
21728
  };
21295
21729
  }
21296
21730
  }
21297
- var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
21298
- const {
21299
- resolveEnvFilePath = resolveEnvFilePathAsync,
21300
- loadEnvFile = loadEnvFileAsync,
21301
- saveEnvFile = saveEnvFileAsync,
21302
- getFs = getFileSystem,
21303
- refreshToken: refreshTokenFn = refreshAccessToken,
21304
- resolveConfig = resolveConfigAsync,
21305
- robotFallback = tryRobotClientFallback
21306
- } = deps;
21307
- if (isRobotAuthEnforced()) {
21308
- if (isEnvAuthEnabled()) {
21309
- throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
21310
- }
21311
- const robotCreds = await robotFallback({ force: true });
21312
- if (!robotCreds) {
21313
- return {
21314
- loginStatus: "Not logged in",
21315
- 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.`
21316
- };
21317
- }
21318
- const expiration2 = getTokenExpiration(robotCreds.accessToken);
21319
- return {
21320
- loginStatus: "Logged in",
21321
- accessToken: robotCreds.accessToken,
21322
- baseUrl: robotCreds.baseUrl,
21323
- organizationName: robotCreds.organizationName,
21324
- organizationId: robotCreds.organizationId,
21325
- tenantName: robotCreds.tenantName,
21326
- tenantId: robotCreds.tenantId,
21327
- issuer: robotCreds.issuer,
21328
- expiration: expiration2,
21329
- source: "robot" /* Robot */
21330
- };
21331
- }
21332
- if (isEnvAuthEnabled()) {
21333
- return readAuthFromEnv();
21334
- }
21335
- const { envFilePath = DEFAULT_ENV_FILENAME, ensureTokenValidityMinutes } = options;
21336
- const { absolutePath } = await resolveEnvFilePath(envFilePath);
21337
- if (absolutePath === undefined) {
21338
- const robotCreds = await robotFallback();
21339
- if (robotCreds) {
21340
- const expiration2 = getTokenExpiration(robotCreds.accessToken);
21341
- const status = {
21342
- loginStatus: "Logged in",
21343
- accessToken: robotCreds.accessToken,
21344
- baseUrl: robotCreds.baseUrl,
21345
- organizationName: robotCreds.organizationName,
21346
- organizationId: robotCreds.organizationId,
21347
- tenantName: robotCreds.tenantName,
21348
- tenantId: robotCreds.tenantId,
21349
- issuer: robotCreds.issuer,
21350
- expiration: expiration2,
21351
- source: "robot" /* Robot */
21352
- };
21353
- return status;
21354
- }
21355
- return { loginStatus: "Not logged in" };
21356
- }
21357
- let credentials;
21358
- try {
21359
- credentials = await loadEnvFile({ envPath: absolutePath });
21360
- } catch (error) {
21361
- if (isFileNotFoundError(error)) {
21362
- return { loginStatus: "Not logged in" };
21363
- }
21364
- throw error;
21365
- }
21366
- if (!credentials.UIPATH_ACCESS_TOKEN) {
21367
- return { loginStatus: "Not logged in" };
21368
- }
21369
- let accessToken = credentials.UIPATH_ACCESS_TOKEN;
21370
- let refreshToken = credentials.UIPATH_REFRESH_TOKEN;
21371
- let expiration = getTokenExpiration(accessToken);
21372
- let persistenceWarning;
21373
- let lockReleaseFailed = false;
21374
- let tokenRefresh;
21375
- const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
21376
- const tryGlobalCredsHint = async () => {
21377
- const fs7 = getFs();
21378
- const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
21379
- if (absolutePath === globalPath)
21380
- return;
21381
- if (!await fs7.exists(globalPath))
21382
- return;
21383
- try {
21384
- const globalCreds = await loadEnvFile({ envPath: globalPath });
21385
- if (!globalCreds.UIPATH_ACCESS_TOKEN)
21386
- return;
21387
- const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
21388
- if (globalExp && globalExp <= new Date)
21389
- return;
21390
- 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.`;
21391
- } catch {
21392
- return;
21393
- }
21394
- };
21395
- if (expiration && expiration <= outerThreshold && refreshToken) {
21396
- let release;
21397
- try {
21398
- release = await getFs().acquireLock(absolutePath);
21399
- } catch (error) {
21400
- const msg = errorMessage(error);
21401
- const globalHint = await tryGlobalCredsHint();
21402
- if (globalHint) {
21403
- return {
21404
- loginStatus: "Expired",
21405
- accessToken,
21406
- refreshToken,
21407
- baseUrl: credentials.UIPATH_URL,
21408
- organizationName: credentials.UIPATH_ORGANIZATION_NAME,
21409
- organizationId: credentials.UIPATH_ORGANIZATION_ID,
21410
- tenantName: credentials.UIPATH_TENANT_NAME,
21411
- tenantId: credentials.UIPATH_TENANT_ID,
21412
- expiration,
21413
- source: "file" /* File */,
21414
- hint: globalHint,
21415
- tokenRefresh: {
21416
- attempted: false,
21417
- success: false,
21418
- errorMessage: `lock acquisition failed: ${msg}`
21419
- }
21420
- };
21421
- }
21422
- return {
21423
- loginStatus: "Refresh Failed",
21424
- 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.",
21425
- tokenRefresh: {
21426
- attempted: false,
21427
- success: false,
21428
- errorMessage: `lock acquisition failed: ${msg}`
21429
- }
21430
- };
21431
- }
21432
- let lockedFailure;
21433
- try {
21434
- const outcome = await runRefreshLocked({
21435
- absolutePath,
21436
- refreshToken,
21437
- customAuthority: credentials.UIPATH_URL,
21438
- ensureTokenValidityMinutes,
21439
- loadEnvFile,
21440
- saveEnvFile,
21441
- refreshFn: refreshTokenFn,
21442
- resolveConfig
21443
- });
21444
- if (outcome.kind === "fail") {
21445
- lockedFailure = outcome.status;
21446
- } else {
21447
- accessToken = outcome.accessToken;
21448
- refreshToken = outcome.refreshToken;
21449
- expiration = outcome.expiration;
21450
- tokenRefresh = outcome.tokenRefresh;
21451
- if (outcome.persistenceWarning) {
21452
- persistenceWarning = outcome.persistenceWarning;
21453
- }
21454
- }
21455
- } finally {
21456
- try {
21457
- await release();
21458
- } catch {
21459
- lockReleaseFailed = true;
21460
- }
21461
- }
21462
- if (lockedFailure) {
21463
- const globalHint = await tryGlobalCredsHint();
21464
- const base = globalHint ? {
21465
- ...lockedFailure,
21466
- loginStatus: "Expired",
21467
- hint: globalHint
21468
- } : lockedFailure;
21469
- return lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base;
21470
- }
21471
- }
21472
- const result = {
21473
- loginStatus: expiration && expiration <= new Date ? "Expired" : "Logged in",
21474
- accessToken,
21475
- refreshToken,
21476
- baseUrl: credentials.UIPATH_URL,
21477
- organizationName: credentials.UIPATH_ORGANIZATION_NAME,
21478
- organizationId: credentials.UIPATH_ORGANIZATION_ID,
21479
- tenantName: credentials.UIPATH_TENANT_NAME,
21480
- tenantId: credentials.UIPATH_TENANT_ID,
21481
- expiration,
21482
- source: "file" /* File */,
21483
- ...persistenceWarning ? { hint: persistenceWarning, persistenceFailed: true } : {},
21484
- ...lockReleaseFailed ? { lockReleaseFailed: true } : {},
21485
- ...tokenRefresh ? { tokenRefresh } : {}
21486
- };
21487
- if (result.loginStatus === "Expired") {
21488
- const globalHint = await tryGlobalCredsHint();
21489
- if (globalHint) {
21490
- result.hint = globalHint;
21491
- }
21492
- }
21493
- return result;
21494
- };
21495
- var isFileNotFoundError = (error) => {
21496
- if (!(error instanceof Object))
21497
- return false;
21498
- return error.code === "ENOENT";
21499
- };
21500
- var getLoginStatusAsync = async (options = {}) => {
21501
- return getLoginStatusWithDeps(options);
21502
- };
21503
- // ../../auth/src/interactive.ts
21504
- init_src();
21505
- // ../../auth/src/logout.ts
21506
- init_src();
21507
-
21508
- // ../../auth/src/index.ts
21509
- init_server();
21510
-
21511
- // ../apms-sdk/src/client-factory.ts
21512
- var STRIP_PREFIX_RE = /\/accesspolicy_\/api\/(?:accessPolicy\/)?organization\/[^/]+/;
21513
- function rewriteApmsUrl(url) {
21514
- return url.replace(STRIP_PREFIX_RE, "/accesspolicy_");
21515
- }
21516
- async function resolveConfig(options) {
21517
- const status = await getLoginStatusAsync({
21518
- ensureTokenValidityMinutes: options?.loginValidity
21519
- });
21520
- if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
21521
- throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
21731
+ function normalizeTokenRefreshFailure() {
21732
+ return "stored refresh token is invalid or expired";
21733
+ }
21734
+ function normalizeTokenRefreshUnavailableFailure() {
21735
+ return "token refresh failed before authentication completed";
21736
+ }
21737
+ function errorMessage(error) {
21738
+ return error instanceof Error ? error.message : String(error);
21739
+ }
21740
+ // ../../auth/src/interactive.ts
21741
+ init_src();
21742
+
21743
+ // ../../auth/src/selectTenant.ts
21744
+ var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
21745
+ var INVALID_TENANT_CODE = "INVALID_TENANT";
21746
+ var TENANT_SELECTION_CODES = new Set([
21747
+ TENANT_SELECTION_REQUIRED_CODE,
21748
+ INVALID_TENANT_CODE
21749
+ ]);
21750
+ // ../../auth/src/logout.ts
21751
+ init_src();
21752
+
21753
+ // ../../auth/src/index.ts
21754
+ init_server();
21755
+
21756
+ // ../apms-sdk/src/client-factory.ts
21757
+ var STRIP_PREFIX_RE = /\/accesspolicy_\/api\/(?:accessPolicy\/)?organization\/[^/]+/;
21758
+ function rewriteApmsUrl(url) {
21759
+ return url.replace(STRIP_PREFIX_RE, "/accesspolicy_");
21760
+ }
21761
+ async function resolveConfig(options) {
21762
+ const status = await getLoginStatusAsync({
21763
+ ensureTokenValidityMinutes: options?.loginValidity
21764
+ });
21765
+ if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
21766
+ throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
21522
21767
  }
21523
21768
  if (!status.organizationId) {
21524
21769
  throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
@@ -21598,27 +21843,54 @@ var NETWORK_ERROR_CODES = new Set([
21598
21843
  "ENETUNREACH",
21599
21844
  "EAI_FAIL"
21600
21845
  ]);
21601
- function isHtmlDocument(body) {
21602
- return /^\s*(<!doctype html|<html\b)/i.test(body);
21603
- }
21604
- function extractNetworkErrorCode(error) {
21605
- if (error === null || typeof error !== "object") {
21606
- return;
21607
- }
21608
- const err = error;
21609
- const code = typeof err.code === "string" ? err.code : undefined;
21610
- if (code && NETWORK_ERROR_CODES.has(code)) {
21611
- return code;
21612
- }
21613
- const cause = err.cause;
21614
- if (cause !== null && typeof cause === "object") {
21615
- const causeCode = cause.code;
21616
- if (typeof causeCode === "string" && NETWORK_ERROR_CODES.has(causeCode)) {
21617
- return causeCode;
21846
+ var TLS_ERROR_CODES = new Set([
21847
+ "SELF_SIGNED_CERT_IN_CHAIN",
21848
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
21849
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
21850
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
21851
+ "UNABLE_TO_GET_ISSUER_CERT",
21852
+ "CERT_HAS_EXPIRED",
21853
+ "CERT_UNTRUSTED",
21854
+ "ERR_TLS_CERT_ALTNAME_INVALID"
21855
+ ]);
21856
+ var TLS_INSTRUCTIONS = "The server's TLS certificate could not be verified. Most often a " + "corporate proxy/firewall re-signs HTTPS with a root CA that Node does " + "not trust — set NODE_EXTRA_CA_CERTS to that CA's PEM file (and HTTPS_PROXY " + "if you connect through a proxy). If the certificate is instead expired or " + "its hostname does not match, fix the endpoint URL or the system clock. " + "Then retry.";
21857
+ var NETWORK_INSTRUCTIONS = "Could not reach the UiPath service. Check your network connection and " + "VPN, confirm any HTTP_PROXY/HTTPS_PROXY/NO_PROXY settings are correct, " + "then retry.";
21858
+ function describeConnectivityError(error) {
21859
+ let current = error;
21860
+ for (let depth = 0;depth < 5 && current !== null && typeof current === "object"; depth++) {
21861
+ const cur = current;
21862
+ const code = typeof cur.code === "string" ? cur.code : undefined;
21863
+ const message = typeof cur.message === "string" ? cur.message : undefined;
21864
+ if (code && TLS_ERROR_CODES.has(code)) {
21865
+ return {
21866
+ code,
21867
+ kind: "tls",
21868
+ message: message ?? code,
21869
+ instructions: TLS_INSTRUCTIONS
21870
+ };
21871
+ }
21872
+ if (code && NETWORK_ERROR_CODES.has(code)) {
21873
+ return {
21874
+ code,
21875
+ kind: "network",
21876
+ message: message ?? code,
21877
+ instructions: NETWORK_INSTRUCTIONS
21878
+ };
21618
21879
  }
21880
+ current = cur.cause;
21619
21881
  }
21620
21882
  return;
21621
21883
  }
21884
+ function parseHttpStatusFromMessage(message) {
21885
+ const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
21886
+ if (!match)
21887
+ return;
21888
+ const status = Number(match[1]);
21889
+ return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
21890
+ }
21891
+ function isHtmlDocument(body) {
21892
+ return /^\s*(<!doctype html|<html\b)/i.test(body);
21893
+ }
21622
21894
  function retryHintForRetryAfter(seconds) {
21623
21895
  if (seconds <= 1) {
21624
21896
  return "RetryAfter1Second";
@@ -21659,15 +21931,28 @@ function classifyError(status, error) {
21659
21931
  if (status !== undefined && status >= 500 && status < 600) {
21660
21932
  return { errorCode: "server_error", retry: "RetryLater" };
21661
21933
  }
21662
- if (extractNetworkErrorCode(error)) {
21663
- return { errorCode: "network_error", retry: "RetryLater" };
21934
+ const connectivity = describeConnectivityError(error);
21935
+ if (connectivity) {
21936
+ return {
21937
+ errorCode: "network_error",
21938
+ retry: connectivity.kind === "tls" ? "RetryWillNotFix" : "RetryLater"
21939
+ };
21664
21940
  }
21665
21941
  return { errorCode: "unknown_error", retry: "RetryWillNotFix" };
21666
21942
  }
21943
+ function formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus) {
21944
+ if (extractedMessage) {
21945
+ return `HTTP ${status}: ${extractedMessage}`;
21946
+ }
21947
+ return inferredStatus !== undefined ? rawMessage : `HTTP ${status}: ${rawMessage}`;
21948
+ }
21667
21949
  async function extractErrorDetails(error, options) {
21668
21950
  const err = error !== null && error !== undefined && typeof error === "object" ? error : {};
21669
21951
  const response = err.response;
21670
- const status = err.status ?? response?.status;
21952
+ const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
21953
+ const explicitStatus = err.status ?? response?.status;
21954
+ const inferredStatus = explicitStatus === undefined ? parseHttpStatusFromMessage(rawMessage) : undefined;
21955
+ const status = explicitStatus ?? inferredStatus;
21671
21956
  const isSuccessfulResponse = status !== undefined && status >= 200 && status < 300;
21672
21957
  let rawBody;
21673
21958
  let extractedMessage;
@@ -21702,7 +21987,6 @@ async function extractErrorDetails(error, options) {
21702
21987
  }
21703
21988
  }
21704
21989
  }
21705
- const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
21706
21990
  let message;
21707
21991
  let result = "Failure";
21708
21992
  const classification = classifyError(status, error);
@@ -21716,10 +22000,10 @@ async function extractErrorDetails(error, options) {
21716
22000
  } else if (status === 405) {
21717
22001
  message = DEFAULT_405;
21718
22002
  } else if (status === 400 || status === 422) {
21719
- message = extractedMessage ? `HTTP ${status}: ${extractedMessage}` : `HTTP ${status}: ${rawMessage}`;
22003
+ message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
21720
22004
  result = "ValidationError";
21721
22005
  } else if (status === 429) {
21722
- message = extractedMessage ? `HTTP ${status}: ${extractedMessage}` : `HTTP ${status}: ${rawMessage}`;
22006
+ message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
21723
22007
  } else if (extractedMessage) {
21724
22008
  if (isSuccessfulResponse && rawMessage !== "Unknown error") {
21725
22009
  message = rawMessage;
@@ -21727,7 +22011,9 @@ async function extractErrorDetails(error, options) {
21727
22011
  message = status ? `HTTP ${status}: ${extractedMessage}` : extractedMessage;
21728
22012
  }
21729
22013
  } else if (status) {
21730
- if (rawMessage === "Unknown error" && response) {
22014
+ if (inferredStatus !== undefined) {
22015
+ message = rawMessage;
22016
+ } else if (rawMessage === "Unknown error" && response) {
21731
22017
  const statusText = response.statusText;
21732
22018
  message = statusText ? `HTTP ${status} ${statusText}` : `HTTP ${status} - request failed`;
21733
22019
  } else {
@@ -21736,6 +22022,12 @@ async function extractErrorDetails(error, options) {
21736
22022
  } else {
21737
22023
  message = rawMessage;
21738
22024
  }
22025
+ if (status === undefined) {
22026
+ const connectivity = describeConnectivityError(error);
22027
+ if (connectivity && connectivity.message !== message && !message.includes(connectivity.message)) {
22028
+ message = `${message}: ${connectivity.message}`;
22029
+ }
22030
+ }
21739
22031
  let details = rawMessage;
21740
22032
  if (rawBody) {
21741
22033
  if (parsedBody) {
@@ -21858,6 +22150,7 @@ var CONSOLE_FALLBACK = {
21858
22150
  writeLog: (str) => process.stdout.write(str),
21859
22151
  capabilities: {
21860
22152
  isInteractive: false,
22153
+ canReadInput: false,
21861
22154
  supportsColor: false,
21862
22155
  outputWidth: 80
21863
22156
  }
@@ -26863,12 +27156,6 @@ class NodeContextStorage {
26863
27156
  return this.storage.getStore();
26864
27157
  }
26865
27158
  }
26866
- // ../../common/src/telemetry/global-telemetry-properties.ts
26867
- var telemetryPropsSlot = singleton("TelemetryDefaultProps");
26868
- function getGlobalTelemetryProperties() {
26869
- return telemetryPropsSlot.get();
26870
- }
26871
-
26872
27159
  // ../../common/src/telemetry/telemetry-service.ts
26873
27160
  class TelemetryService {
26874
27161
  telemetryProvider;
@@ -27058,6 +27345,29 @@ function isPlainRecord(value) {
27058
27345
  const prototype = Object.getPrototypeOf(value);
27059
27346
  return prototype === Object.prototype || prototype === null;
27060
27347
  }
27348
+ function extractPagedRows(value) {
27349
+ if (Array.isArray(value) || !isPlainRecord(value))
27350
+ return null;
27351
+ const entries = Object.values(value);
27352
+ if (entries.length === 0)
27353
+ return null;
27354
+ let rows = null;
27355
+ let hasScalarSibling = false;
27356
+ for (const entry of entries) {
27357
+ if (Array.isArray(entry)) {
27358
+ if (rows !== null)
27359
+ return null;
27360
+ rows = entry;
27361
+ } else if (entry !== null && typeof entry === "object") {
27362
+ return null;
27363
+ } else {
27364
+ hasScalarSibling = true;
27365
+ }
27366
+ }
27367
+ if (rows === null || !hasScalarSibling)
27368
+ return null;
27369
+ return rows;
27370
+ }
27061
27371
  function toLowerCamelCaseKey(key) {
27062
27372
  if (!key)
27063
27373
  return key;
@@ -27122,7 +27432,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
27122
27432
  break;
27123
27433
  case "plain": {
27124
27434
  if ("Data" in data && data.Data != null) {
27125
- const items = Array.isArray(data.Data) ? data.Data : [data.Data];
27435
+ const pagedRows = extractPagedRows(data.Data);
27436
+ const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
27126
27437
  items.forEach((item) => {
27127
27438
  const values = Object.values(item).map((v) => v ?? "").join("\t");
27128
27439
  logFn(values);
@@ -27134,10 +27445,13 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
27134
27445
  break;
27135
27446
  }
27136
27447
  default: {
27137
- if ("Data" in data && data.Data != null && !(Array.isArray(data.Data) && data.Data.length === 0)) {
27448
+ const hasData = "Data" in data && data.Data != null;
27449
+ const pagedRows = hasData ? extractPagedRows(data.Data) : null;
27450
+ const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
27451
+ if (hasData && !(rows !== null && rows.length === 0)) {
27138
27452
  const logValue = data.Log;
27139
- if (Array.isArray(data.Data)) {
27140
- printResizableTable(data.Data, logFn, logValue);
27453
+ if (rows !== null) {
27454
+ printResizableTable(rows, logFn, logValue);
27141
27455
  } else {
27142
27456
  printVerticalTable(data.Data, logFn, logValue);
27143
27457
  }
@@ -27325,6 +27639,44 @@ function defaultErrorCodeForResult(result) {
27325
27639
  return "unknown_error";
27326
27640
  }
27327
27641
  }
27642
+ function parseHttpStatusFromMessage2(message) {
27643
+ const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
27644
+ if (!match)
27645
+ return;
27646
+ const status = Number(match[1]);
27647
+ return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
27648
+ }
27649
+ function defaultErrorCodeForHttpStatus(status) {
27650
+ if (status === undefined)
27651
+ return;
27652
+ if (status === 400 || status === 409 || status === 422) {
27653
+ return "invalid_argument";
27654
+ }
27655
+ if (status === 401)
27656
+ return "authentication_required";
27657
+ if (status === 403)
27658
+ return "permission_denied";
27659
+ if (status === 404)
27660
+ return "not_found";
27661
+ if (status === 405)
27662
+ return "method_not_allowed";
27663
+ if (status === 408)
27664
+ return "timeout";
27665
+ if (status === 429)
27666
+ return "rate_limited";
27667
+ if (status >= 500 && status < 600)
27668
+ return "server_error";
27669
+ return;
27670
+ }
27671
+ function defaultErrorCodeForFailure(data) {
27672
+ if (data.Result === RESULTS.Failure) {
27673
+ const status = data.Context?.httpStatus ?? parseHttpStatusFromMessage2(data.Message);
27674
+ const errorCode2 = defaultErrorCodeForHttpStatus(status);
27675
+ if (errorCode2)
27676
+ return errorCode2;
27677
+ }
27678
+ return defaultErrorCodeForResult(data.Result);
27679
+ }
27328
27680
  function defaultRetryForErrorCode(errorCode2) {
27329
27681
  switch (errorCode2) {
27330
27682
  case "network_error":
@@ -27354,16 +27706,19 @@ var OutputFormatter;
27354
27706
  OutputFormatter.success = success;
27355
27707
  function error(data) {
27356
27708
  data.Log ??= getLogFilePath() || undefined;
27357
- data.ErrorCode ??= defaultErrorCodeForResult(data.Result);
27709
+ data.ErrorCode ??= defaultErrorCodeForFailure(data);
27358
27710
  data.Retry ??= defaultRetryForErrorCode(data.ErrorCode);
27359
27711
  process.exitCode = EXIT_CODES[data.Result] ?? 1;
27360
- telemetry.trackEvent(CommonTelemetryEvents.Error, {
27361
- result: data.Result,
27362
- errorCode: data.ErrorCode,
27363
- retry: data.Retry,
27364
- message: data.Message
27365
- });
27366
- logOutput(normalizeOutputKeys(data), getOutputFormat());
27712
+ const { SuppressTelemetry, ...envelope } = data;
27713
+ if (!SuppressTelemetry) {
27714
+ telemetry.trackEvent(CommonTelemetryEvents.Error, {
27715
+ result: data.Result,
27716
+ errorCode: data.ErrorCode,
27717
+ retry: data.Retry,
27718
+ message: data.Message
27719
+ });
27720
+ }
27721
+ logOutput(normalizeOutputKeys(envelope), getOutputFormat());
27367
27722
  }
27368
27723
  OutputFormatter.error = error;
27369
27724
  function emitList(code, items, opts) {
@@ -27656,1409 +28011,6 @@ var savedOriginalsSlot = singleton("ConsoleGuardOriginals");
27656
28011
  var DEFAULT_AUTH_TIMEOUT_MS2 = 5 * 60 * 1000;
27657
28012
  // ../../common/src/interactivity-context.ts
27658
28013
  var modeSlot = singleton("InteractivityMode");
27659
- // ../../../node_modules/jsonpath-plus/dist/index-node-esm.js
27660
- import vm from "vm";
27661
-
27662
- class Hooks {
27663
- add(name, callback, first) {
27664
- if (typeof arguments[0] != "string") {
27665
- for (let name2 in arguments[0]) {
27666
- this.add(name2, arguments[0][name2], arguments[1]);
27667
- }
27668
- } else {
27669
- (Array.isArray(name) ? name : [name]).forEach(function(name2) {
27670
- this[name2] = this[name2] || [];
27671
- if (callback) {
27672
- this[name2][first ? "unshift" : "push"](callback);
27673
- }
27674
- }, this);
27675
- }
27676
- }
27677
- run(name, env) {
27678
- this[name] = this[name] || [];
27679
- this[name].forEach(function(callback) {
27680
- callback.call(env && env.context ? env.context : env, env);
27681
- });
27682
- }
27683
- }
27684
-
27685
- class Plugins {
27686
- constructor(jsep) {
27687
- this.jsep = jsep;
27688
- this.registered = {};
27689
- }
27690
- register(...plugins) {
27691
- plugins.forEach((plugin) => {
27692
- if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
27693
- throw new Error("Invalid JSEP plugin format");
27694
- }
27695
- if (this.registered[plugin.name]) {
27696
- return;
27697
- }
27698
- plugin.init(this.jsep);
27699
- this.registered[plugin.name] = plugin;
27700
- });
27701
- }
27702
- }
27703
-
27704
- class Jsep {
27705
- static get version() {
27706
- return "1.4.0";
27707
- }
27708
- static toString() {
27709
- return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
27710
- }
27711
- static addUnaryOp(op_name) {
27712
- Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
27713
- Jsep.unary_ops[op_name] = 1;
27714
- return Jsep;
27715
- }
27716
- static addBinaryOp(op_name, precedence, isRightAssociative) {
27717
- Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
27718
- Jsep.binary_ops[op_name] = precedence;
27719
- if (isRightAssociative) {
27720
- Jsep.right_associative.add(op_name);
27721
- } else {
27722
- Jsep.right_associative.delete(op_name);
27723
- }
27724
- return Jsep;
27725
- }
27726
- static addIdentifierChar(char) {
27727
- Jsep.additional_identifier_chars.add(char);
27728
- return Jsep;
27729
- }
27730
- static addLiteral(literal_name, literal_value) {
27731
- Jsep.literals[literal_name] = literal_value;
27732
- return Jsep;
27733
- }
27734
- static removeUnaryOp(op_name) {
27735
- delete Jsep.unary_ops[op_name];
27736
- if (op_name.length === Jsep.max_unop_len) {
27737
- Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
27738
- }
27739
- return Jsep;
27740
- }
27741
- static removeAllUnaryOps() {
27742
- Jsep.unary_ops = {};
27743
- Jsep.max_unop_len = 0;
27744
- return Jsep;
27745
- }
27746
- static removeIdentifierChar(char) {
27747
- Jsep.additional_identifier_chars.delete(char);
27748
- return Jsep;
27749
- }
27750
- static removeBinaryOp(op_name) {
27751
- delete Jsep.binary_ops[op_name];
27752
- if (op_name.length === Jsep.max_binop_len) {
27753
- Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
27754
- }
27755
- Jsep.right_associative.delete(op_name);
27756
- return Jsep;
27757
- }
27758
- static removeAllBinaryOps() {
27759
- Jsep.binary_ops = {};
27760
- Jsep.max_binop_len = 0;
27761
- return Jsep;
27762
- }
27763
- static removeLiteral(literal_name) {
27764
- delete Jsep.literals[literal_name];
27765
- return Jsep;
27766
- }
27767
- static removeAllLiterals() {
27768
- Jsep.literals = {};
27769
- return Jsep;
27770
- }
27771
- get char() {
27772
- return this.expr.charAt(this.index);
27773
- }
27774
- get code() {
27775
- return this.expr.charCodeAt(this.index);
27776
- }
27777
- constructor(expr) {
27778
- this.expr = expr;
27779
- this.index = 0;
27780
- }
27781
- static parse(expr) {
27782
- return new Jsep(expr).parse();
27783
- }
27784
- static getMaxKeyLen(obj) {
27785
- return Math.max(0, ...Object.keys(obj).map((k) => k.length));
27786
- }
27787
- static isDecimalDigit(ch) {
27788
- return ch >= 48 && ch <= 57;
27789
- }
27790
- static binaryPrecedence(op_val) {
27791
- return Jsep.binary_ops[op_val] || 0;
27792
- }
27793
- static isIdentifierStart(ch) {
27794
- return ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 128 && !Jsep.binary_ops[String.fromCharCode(ch)] || Jsep.additional_identifier_chars.has(String.fromCharCode(ch));
27795
- }
27796
- static isIdentifierPart(ch) {
27797
- return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
27798
- }
27799
- throwError(message) {
27800
- const error = new Error(message + " at character " + this.index);
27801
- error.index = this.index;
27802
- error.description = message;
27803
- throw error;
27804
- }
27805
- runHook(name, node) {
27806
- if (Jsep.hooks[name]) {
27807
- const env = {
27808
- context: this,
27809
- node
27810
- };
27811
- Jsep.hooks.run(name, env);
27812
- return env.node;
27813
- }
27814
- return node;
27815
- }
27816
- searchHook(name) {
27817
- if (Jsep.hooks[name]) {
27818
- const env = {
27819
- context: this
27820
- };
27821
- Jsep.hooks[name].find(function(callback) {
27822
- callback.call(env.context, env);
27823
- return env.node;
27824
- });
27825
- return env.node;
27826
- }
27827
- }
27828
- gobbleSpaces() {
27829
- let ch = this.code;
27830
- while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
27831
- ch = this.expr.charCodeAt(++this.index);
27832
- }
27833
- this.runHook("gobble-spaces");
27834
- }
27835
- parse() {
27836
- this.runHook("before-all");
27837
- const nodes = this.gobbleExpressions();
27838
- const node = nodes.length === 1 ? nodes[0] : {
27839
- type: Jsep.COMPOUND,
27840
- body: nodes
27841
- };
27842
- return this.runHook("after-all", node);
27843
- }
27844
- gobbleExpressions(untilICode) {
27845
- let nodes = [], ch_i, node;
27846
- while (this.index < this.expr.length) {
27847
- ch_i = this.code;
27848
- if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
27849
- this.index++;
27850
- } else {
27851
- if (node = this.gobbleExpression()) {
27852
- nodes.push(node);
27853
- } else if (this.index < this.expr.length) {
27854
- if (ch_i === untilICode) {
27855
- break;
27856
- }
27857
- this.throwError('Unexpected "' + this.char + '"');
27858
- }
27859
- }
27860
- }
27861
- return nodes;
27862
- }
27863
- gobbleExpression() {
27864
- const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
27865
- this.gobbleSpaces();
27866
- return this.runHook("after-expression", node);
27867
- }
27868
- gobbleBinaryOp() {
27869
- this.gobbleSpaces();
27870
- let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
27871
- let tc_len = to_check.length;
27872
- while (tc_len > 0) {
27873
- if (Jsep.binary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
27874
- this.index += tc_len;
27875
- return to_check;
27876
- }
27877
- to_check = to_check.substr(0, --tc_len);
27878
- }
27879
- return false;
27880
- }
27881
- gobbleBinaryExpression() {
27882
- let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
27883
- left = this.gobbleToken();
27884
- if (!left) {
27885
- return left;
27886
- }
27887
- biop = this.gobbleBinaryOp();
27888
- if (!biop) {
27889
- return left;
27890
- }
27891
- biop_info = {
27892
- value: biop,
27893
- prec: Jsep.binaryPrecedence(biop),
27894
- right_a: Jsep.right_associative.has(biop)
27895
- };
27896
- right = this.gobbleToken();
27897
- if (!right) {
27898
- this.throwError("Expected expression after " + biop);
27899
- }
27900
- stack = [left, biop_info, right];
27901
- while (biop = this.gobbleBinaryOp()) {
27902
- prec = Jsep.binaryPrecedence(biop);
27903
- if (prec === 0) {
27904
- this.index -= biop.length;
27905
- break;
27906
- }
27907
- biop_info = {
27908
- value: biop,
27909
- prec,
27910
- right_a: Jsep.right_associative.has(biop)
27911
- };
27912
- cur_biop = biop;
27913
- const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
27914
- while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
27915
- right = stack.pop();
27916
- biop = stack.pop().value;
27917
- left = stack.pop();
27918
- node = {
27919
- type: Jsep.BINARY_EXP,
27920
- operator: biop,
27921
- left,
27922
- right
27923
- };
27924
- stack.push(node);
27925
- }
27926
- node = this.gobbleToken();
27927
- if (!node) {
27928
- this.throwError("Expected expression after " + cur_biop);
27929
- }
27930
- stack.push(biop_info, node);
27931
- }
27932
- i = stack.length - 1;
27933
- node = stack[i];
27934
- while (i > 1) {
27935
- node = {
27936
- type: Jsep.BINARY_EXP,
27937
- operator: stack[i - 1].value,
27938
- left: stack[i - 2],
27939
- right: node
27940
- };
27941
- i -= 2;
27942
- }
27943
- return node;
27944
- }
27945
- gobbleToken() {
27946
- let ch, to_check, tc_len, node;
27947
- this.gobbleSpaces();
27948
- node = this.searchHook("gobble-token");
27949
- if (node) {
27950
- return this.runHook("after-token", node);
27951
- }
27952
- ch = this.code;
27953
- if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
27954
- return this.gobbleNumericLiteral();
27955
- }
27956
- if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
27957
- node = this.gobbleStringLiteral();
27958
- } else if (ch === Jsep.OBRACK_CODE) {
27959
- node = this.gobbleArray();
27960
- } else {
27961
- to_check = this.expr.substr(this.index, Jsep.max_unop_len);
27962
- tc_len = to_check.length;
27963
- while (tc_len > 0) {
27964
- if (Jsep.unary_ops.hasOwnProperty(to_check) && (!Jsep.isIdentifierStart(this.code) || this.index + to_check.length < this.expr.length && !Jsep.isIdentifierPart(this.expr.charCodeAt(this.index + to_check.length)))) {
27965
- this.index += tc_len;
27966
- const argument = this.gobbleToken();
27967
- if (!argument) {
27968
- this.throwError("missing unaryOp argument");
27969
- }
27970
- return this.runHook("after-token", {
27971
- type: Jsep.UNARY_EXP,
27972
- operator: to_check,
27973
- argument,
27974
- prefix: true
27975
- });
27976
- }
27977
- to_check = to_check.substr(0, --tc_len);
27978
- }
27979
- if (Jsep.isIdentifierStart(ch)) {
27980
- node = this.gobbleIdentifier();
27981
- if (Jsep.literals.hasOwnProperty(node.name)) {
27982
- node = {
27983
- type: Jsep.LITERAL,
27984
- value: Jsep.literals[node.name],
27985
- raw: node.name
27986
- };
27987
- } else if (node.name === Jsep.this_str) {
27988
- node = {
27989
- type: Jsep.THIS_EXP
27990
- };
27991
- }
27992
- } else if (ch === Jsep.OPAREN_CODE) {
27993
- node = this.gobbleGroup();
27994
- }
27995
- }
27996
- if (!node) {
27997
- return this.runHook("after-token", false);
27998
- }
27999
- node = this.gobbleTokenProperty(node);
28000
- return this.runHook("after-token", node);
28001
- }
28002
- gobbleTokenProperty(node) {
28003
- this.gobbleSpaces();
28004
- let ch = this.code;
28005
- while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
28006
- let optional;
28007
- if (ch === Jsep.QUMARK_CODE) {
28008
- if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
28009
- break;
28010
- }
28011
- optional = true;
28012
- this.index += 2;
28013
- this.gobbleSpaces();
28014
- ch = this.code;
28015
- }
28016
- this.index++;
28017
- if (ch === Jsep.OBRACK_CODE) {
28018
- node = {
28019
- type: Jsep.MEMBER_EXP,
28020
- computed: true,
28021
- object: node,
28022
- property: this.gobbleExpression()
28023
- };
28024
- if (!node.property) {
28025
- this.throwError('Unexpected "' + this.char + '"');
28026
- }
28027
- this.gobbleSpaces();
28028
- ch = this.code;
28029
- if (ch !== Jsep.CBRACK_CODE) {
28030
- this.throwError("Unclosed [");
28031
- }
28032
- this.index++;
28033
- } else if (ch === Jsep.OPAREN_CODE) {
28034
- node = {
28035
- type: Jsep.CALL_EXP,
28036
- arguments: this.gobbleArguments(Jsep.CPAREN_CODE),
28037
- callee: node
28038
- };
28039
- } else if (ch === Jsep.PERIOD_CODE || optional) {
28040
- if (optional) {
28041
- this.index--;
28042
- }
28043
- this.gobbleSpaces();
28044
- node = {
28045
- type: Jsep.MEMBER_EXP,
28046
- computed: false,
28047
- object: node,
28048
- property: this.gobbleIdentifier()
28049
- };
28050
- }
28051
- if (optional) {
28052
- node.optional = true;
28053
- }
28054
- this.gobbleSpaces();
28055
- ch = this.code;
28056
- }
28057
- return node;
28058
- }
28059
- gobbleNumericLiteral() {
28060
- let number = "", ch, chCode;
28061
- while (Jsep.isDecimalDigit(this.code)) {
28062
- number += this.expr.charAt(this.index++);
28063
- }
28064
- if (this.code === Jsep.PERIOD_CODE) {
28065
- number += this.expr.charAt(this.index++);
28066
- while (Jsep.isDecimalDigit(this.code)) {
28067
- number += this.expr.charAt(this.index++);
28068
- }
28069
- }
28070
- ch = this.char;
28071
- if (ch === "e" || ch === "E") {
28072
- number += this.expr.charAt(this.index++);
28073
- ch = this.char;
28074
- if (ch === "+" || ch === "-") {
28075
- number += this.expr.charAt(this.index++);
28076
- }
28077
- while (Jsep.isDecimalDigit(this.code)) {
28078
- number += this.expr.charAt(this.index++);
28079
- }
28080
- if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
28081
- this.throwError("Expected exponent (" + number + this.char + ")");
28082
- }
28083
- }
28084
- chCode = this.code;
28085
- if (Jsep.isIdentifierStart(chCode)) {
28086
- this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
28087
- } else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) {
28088
- this.throwError("Unexpected period");
28089
- }
28090
- return {
28091
- type: Jsep.LITERAL,
28092
- value: parseFloat(number),
28093
- raw: number
28094
- };
28095
- }
28096
- gobbleStringLiteral() {
28097
- let str = "";
28098
- const startIndex = this.index;
28099
- const quote = this.expr.charAt(this.index++);
28100
- let closed = false;
28101
- while (this.index < this.expr.length) {
28102
- let ch = this.expr.charAt(this.index++);
28103
- if (ch === quote) {
28104
- closed = true;
28105
- break;
28106
- } else if (ch === "\\") {
28107
- ch = this.expr.charAt(this.index++);
28108
- switch (ch) {
28109
- case "n":
28110
- str += `
28111
- `;
28112
- break;
28113
- case "r":
28114
- str += "\r";
28115
- break;
28116
- case "t":
28117
- str += "\t";
28118
- break;
28119
- case "b":
28120
- str += "\b";
28121
- break;
28122
- case "f":
28123
- str += "\f";
28124
- break;
28125
- case "v":
28126
- str += "\v";
28127
- break;
28128
- default:
28129
- str += ch;
28130
- }
28131
- } else {
28132
- str += ch;
28133
- }
28134
- }
28135
- if (!closed) {
28136
- this.throwError('Unclosed quote after "' + str + '"');
28137
- }
28138
- return {
28139
- type: Jsep.LITERAL,
28140
- value: str,
28141
- raw: this.expr.substring(startIndex, this.index)
28142
- };
28143
- }
28144
- gobbleIdentifier() {
28145
- let ch = this.code, start = this.index;
28146
- if (Jsep.isIdentifierStart(ch)) {
28147
- this.index++;
28148
- } else {
28149
- this.throwError("Unexpected " + this.char);
28150
- }
28151
- while (this.index < this.expr.length) {
28152
- ch = this.code;
28153
- if (Jsep.isIdentifierPart(ch)) {
28154
- this.index++;
28155
- } else {
28156
- break;
28157
- }
28158
- }
28159
- return {
28160
- type: Jsep.IDENTIFIER,
28161
- name: this.expr.slice(start, this.index)
28162
- };
28163
- }
28164
- gobbleArguments(termination) {
28165
- const args = [];
28166
- let closed = false;
28167
- let separator_count = 0;
28168
- while (this.index < this.expr.length) {
28169
- this.gobbleSpaces();
28170
- let ch_i = this.code;
28171
- if (ch_i === termination) {
28172
- closed = true;
28173
- this.index++;
28174
- if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
28175
- this.throwError("Unexpected token " + String.fromCharCode(termination));
28176
- }
28177
- break;
28178
- } else if (ch_i === Jsep.COMMA_CODE) {
28179
- this.index++;
28180
- separator_count++;
28181
- if (separator_count !== args.length) {
28182
- if (termination === Jsep.CPAREN_CODE) {
28183
- this.throwError("Unexpected token ,");
28184
- } else if (termination === Jsep.CBRACK_CODE) {
28185
- for (let arg = args.length;arg < separator_count; arg++) {
28186
- args.push(null);
28187
- }
28188
- }
28189
- }
28190
- } else if (args.length !== separator_count && separator_count !== 0) {
28191
- this.throwError("Expected comma");
28192
- } else {
28193
- const node = this.gobbleExpression();
28194
- if (!node || node.type === Jsep.COMPOUND) {
28195
- this.throwError("Expected comma");
28196
- }
28197
- args.push(node);
28198
- }
28199
- }
28200
- if (!closed) {
28201
- this.throwError("Expected " + String.fromCharCode(termination));
28202
- }
28203
- return args;
28204
- }
28205
- gobbleGroup() {
28206
- this.index++;
28207
- let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
28208
- if (this.code === Jsep.CPAREN_CODE) {
28209
- this.index++;
28210
- if (nodes.length === 1) {
28211
- return nodes[0];
28212
- } else if (!nodes.length) {
28213
- return false;
28214
- } else {
28215
- return {
28216
- type: Jsep.SEQUENCE_EXP,
28217
- expressions: nodes
28218
- };
28219
- }
28220
- } else {
28221
- this.throwError("Unclosed (");
28222
- }
28223
- }
28224
- gobbleArray() {
28225
- this.index++;
28226
- return {
28227
- type: Jsep.ARRAY_EXP,
28228
- elements: this.gobbleArguments(Jsep.CBRACK_CODE)
28229
- };
28230
- }
28231
- }
28232
- var hooks = new Hooks;
28233
- Object.assign(Jsep, {
28234
- hooks,
28235
- plugins: new Plugins(Jsep),
28236
- COMPOUND: "Compound",
28237
- SEQUENCE_EXP: "SequenceExpression",
28238
- IDENTIFIER: "Identifier",
28239
- MEMBER_EXP: "MemberExpression",
28240
- LITERAL: "Literal",
28241
- THIS_EXP: "ThisExpression",
28242
- CALL_EXP: "CallExpression",
28243
- UNARY_EXP: "UnaryExpression",
28244
- BINARY_EXP: "BinaryExpression",
28245
- ARRAY_EXP: "ArrayExpression",
28246
- TAB_CODE: 9,
28247
- LF_CODE: 10,
28248
- CR_CODE: 13,
28249
- SPACE_CODE: 32,
28250
- PERIOD_CODE: 46,
28251
- COMMA_CODE: 44,
28252
- SQUOTE_CODE: 39,
28253
- DQUOTE_CODE: 34,
28254
- OPAREN_CODE: 40,
28255
- CPAREN_CODE: 41,
28256
- OBRACK_CODE: 91,
28257
- CBRACK_CODE: 93,
28258
- QUMARK_CODE: 63,
28259
- SEMCOL_CODE: 59,
28260
- COLON_CODE: 58,
28261
- unary_ops: {
28262
- "-": 1,
28263
- "!": 1,
28264
- "~": 1,
28265
- "+": 1
28266
- },
28267
- binary_ops: {
28268
- "||": 1,
28269
- "??": 1,
28270
- "&&": 2,
28271
- "|": 3,
28272
- "^": 4,
28273
- "&": 5,
28274
- "==": 6,
28275
- "!=": 6,
28276
- "===": 6,
28277
- "!==": 6,
28278
- "<": 7,
28279
- ">": 7,
28280
- "<=": 7,
28281
- ">=": 7,
28282
- "<<": 8,
28283
- ">>": 8,
28284
- ">>>": 8,
28285
- "+": 9,
28286
- "-": 9,
28287
- "*": 10,
28288
- "/": 10,
28289
- "%": 10,
28290
- "**": 11
28291
- },
28292
- right_associative: new Set(["**"]),
28293
- additional_identifier_chars: new Set(["$", "_"]),
28294
- literals: {
28295
- true: true,
28296
- false: false,
28297
- null: null
28298
- },
28299
- this_str: "this"
28300
- });
28301
- Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
28302
- Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
28303
- var jsep = (expr) => new Jsep(expr).parse();
28304
- var stdClassProps = Object.getOwnPropertyNames(class Test {
28305
- });
28306
- Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === undefined).forEach((m) => {
28307
- jsep[m] = Jsep[m];
28308
- });
28309
- jsep.Jsep = Jsep;
28310
- var CONDITIONAL_EXP = "ConditionalExpression";
28311
- var ternary = {
28312
- name: "ternary",
28313
- init(jsep2) {
28314
- jsep2.hooks.add("after-expression", function gobbleTernary(env) {
28315
- if (env.node && this.code === jsep2.QUMARK_CODE) {
28316
- this.index++;
28317
- const test = env.node;
28318
- const consequent = this.gobbleExpression();
28319
- if (!consequent) {
28320
- this.throwError("Expected expression");
28321
- }
28322
- this.gobbleSpaces();
28323
- if (this.code === jsep2.COLON_CODE) {
28324
- this.index++;
28325
- const alternate = this.gobbleExpression();
28326
- if (!alternate) {
28327
- this.throwError("Expected expression");
28328
- }
28329
- env.node = {
28330
- type: CONDITIONAL_EXP,
28331
- test,
28332
- consequent,
28333
- alternate
28334
- };
28335
- if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
28336
- let newTest = test;
28337
- while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
28338
- newTest = newTest.right;
28339
- }
28340
- env.node.test = newTest.right;
28341
- newTest.right = env.node;
28342
- env.node = test;
28343
- }
28344
- } else {
28345
- this.throwError("Expected :");
28346
- }
28347
- }
28348
- });
28349
- }
28350
- };
28351
- jsep.plugins.register(ternary);
28352
- var FSLASH_CODE = 47;
28353
- var BSLASH_CODE = 92;
28354
- var index = {
28355
- name: "regex",
28356
- init(jsep2) {
28357
- jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
28358
- if (this.code === FSLASH_CODE) {
28359
- const patternIndex = ++this.index;
28360
- let inCharSet = false;
28361
- while (this.index < this.expr.length) {
28362
- if (this.code === FSLASH_CODE && !inCharSet) {
28363
- const pattern = this.expr.slice(patternIndex, this.index);
28364
- let flags = "";
28365
- while (++this.index < this.expr.length) {
28366
- const code = this.code;
28367
- if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
28368
- flags += this.char;
28369
- } else {
28370
- break;
28371
- }
28372
- }
28373
- let value;
28374
- try {
28375
- value = new RegExp(pattern, flags);
28376
- } catch (e) {
28377
- this.throwError(e.message);
28378
- }
28379
- env.node = {
28380
- type: jsep2.LITERAL,
28381
- value,
28382
- raw: this.expr.slice(patternIndex - 1, this.index)
28383
- };
28384
- env.node = this.gobbleTokenProperty(env.node);
28385
- return env.node;
28386
- }
28387
- if (this.code === jsep2.OBRACK_CODE) {
28388
- inCharSet = true;
28389
- } else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
28390
- inCharSet = false;
28391
- }
28392
- this.index += this.code === BSLASH_CODE ? 2 : 1;
28393
- }
28394
- this.throwError("Unclosed Regex");
28395
- }
28396
- });
28397
- }
28398
- };
28399
- var PLUS_CODE = 43;
28400
- var MINUS_CODE = 45;
28401
- var plugin = {
28402
- name: "assignment",
28403
- assignmentOperators: new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
28404
- updateOperators: [PLUS_CODE, MINUS_CODE],
28405
- assignmentPrecedence: 0.9,
28406
- init(jsep2) {
28407
- const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
28408
- plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
28409
- jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
28410
- const code = this.code;
28411
- if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
28412
- this.index += 2;
28413
- env.node = {
28414
- type: "UpdateExpression",
28415
- operator: code === PLUS_CODE ? "++" : "--",
28416
- argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
28417
- prefix: true
28418
- };
28419
- if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
28420
- this.throwError(`Unexpected ${env.node.operator}`);
28421
- }
28422
- }
28423
- });
28424
- jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
28425
- if (env.node) {
28426
- const code = this.code;
28427
- if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
28428
- if (!updateNodeTypes.includes(env.node.type)) {
28429
- this.throwError(`Unexpected ${env.node.operator}`);
28430
- }
28431
- this.index += 2;
28432
- env.node = {
28433
- type: "UpdateExpression",
28434
- operator: code === PLUS_CODE ? "++" : "--",
28435
- argument: env.node,
28436
- prefix: false
28437
- };
28438
- }
28439
- }
28440
- });
28441
- jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
28442
- if (env.node) {
28443
- updateBinariesToAssignments(env.node);
28444
- }
28445
- });
28446
- function updateBinariesToAssignments(node) {
28447
- if (plugin.assignmentOperators.has(node.operator)) {
28448
- node.type = "AssignmentExpression";
28449
- updateBinariesToAssignments(node.left);
28450
- updateBinariesToAssignments(node.right);
28451
- } else if (!node.operator) {
28452
- Object.values(node).forEach((val) => {
28453
- if (val && typeof val === "object") {
28454
- updateBinariesToAssignments(val);
28455
- }
28456
- });
28457
- }
28458
- }
28459
- }
28460
- };
28461
- jsep.plugins.register(index, plugin);
28462
- jsep.addUnaryOp("typeof");
28463
- jsep.addUnaryOp("void");
28464
- jsep.addLiteral("null", null);
28465
- jsep.addLiteral("undefined", undefined);
28466
- var BLOCKED_PROTO_PROPERTIES = new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
28467
- var SafeEval = {
28468
- evalAst(ast, subs) {
28469
- switch (ast.type) {
28470
- case "BinaryExpression":
28471
- case "LogicalExpression":
28472
- return SafeEval.evalBinaryExpression(ast, subs);
28473
- case "Compound":
28474
- return SafeEval.evalCompound(ast, subs);
28475
- case "ConditionalExpression":
28476
- return SafeEval.evalConditionalExpression(ast, subs);
28477
- case "Identifier":
28478
- return SafeEval.evalIdentifier(ast, subs);
28479
- case "Literal":
28480
- return SafeEval.evalLiteral(ast, subs);
28481
- case "MemberExpression":
28482
- return SafeEval.evalMemberExpression(ast, subs);
28483
- case "UnaryExpression":
28484
- return SafeEval.evalUnaryExpression(ast, subs);
28485
- case "ArrayExpression":
28486
- return SafeEval.evalArrayExpression(ast, subs);
28487
- case "CallExpression":
28488
- return SafeEval.evalCallExpression(ast, subs);
28489
- case "AssignmentExpression":
28490
- return SafeEval.evalAssignmentExpression(ast, subs);
28491
- default:
28492
- throw SyntaxError("Unexpected expression", ast);
28493
- }
28494
- },
28495
- evalBinaryExpression(ast, subs) {
28496
- const result = {
28497
- "||": (a, b) => a || b(),
28498
- "&&": (a, b) => a && b(),
28499
- "|": (a, b) => a | b(),
28500
- "^": (a, b) => a ^ b(),
28501
- "&": (a, b) => a & b(),
28502
- "==": (a, b) => a == b(),
28503
- "!=": (a, b) => a != b(),
28504
- "===": (a, b) => a === b(),
28505
- "!==": (a, b) => a !== b(),
28506
- "<": (a, b) => a < b(),
28507
- ">": (a, b) => a > b(),
28508
- "<=": (a, b) => a <= b(),
28509
- ">=": (a, b) => a >= b(),
28510
- "<<": (a, b) => a << b(),
28511
- ">>": (a, b) => a >> b(),
28512
- ">>>": (a, b) => a >>> b(),
28513
- "+": (a, b) => a + b(),
28514
- "-": (a, b) => a - b(),
28515
- "*": (a, b) => a * b(),
28516
- "/": (a, b) => a / b(),
28517
- "%": (a, b) => a % b()
28518
- }[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
28519
- return result;
28520
- },
28521
- evalCompound(ast, subs) {
28522
- let last;
28523
- for (let i = 0;i < ast.body.length; i++) {
28524
- if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
28525
- i += 1;
28526
- }
28527
- const expr = ast.body[i];
28528
- last = SafeEval.evalAst(expr, subs);
28529
- }
28530
- return last;
28531
- },
28532
- evalConditionalExpression(ast, subs) {
28533
- if (SafeEval.evalAst(ast.test, subs)) {
28534
- return SafeEval.evalAst(ast.consequent, subs);
28535
- }
28536
- return SafeEval.evalAst(ast.alternate, subs);
28537
- },
28538
- evalIdentifier(ast, subs) {
28539
- if (Object.hasOwn(subs, ast.name)) {
28540
- return subs[ast.name];
28541
- }
28542
- throw ReferenceError(`${ast.name} is not defined`);
28543
- },
28544
- evalLiteral(ast) {
28545
- return ast.value;
28546
- },
28547
- evalMemberExpression(ast, subs) {
28548
- const prop = String(ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name);
28549
- const obj = SafeEval.evalAst(ast.object, subs);
28550
- if (obj === undefined || obj === null) {
28551
- throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
28552
- }
28553
- if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
28554
- throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
28555
- }
28556
- const result = obj[prop];
28557
- if (typeof result === "function") {
28558
- return result.bind(obj);
28559
- }
28560
- return result;
28561
- },
28562
- evalUnaryExpression(ast, subs) {
28563
- const result = {
28564
- "-": (a) => -SafeEval.evalAst(a, subs),
28565
- "!": (a) => !SafeEval.evalAst(a, subs),
28566
- "~": (a) => ~SafeEval.evalAst(a, subs),
28567
- "+": (a) => +SafeEval.evalAst(a, subs),
28568
- typeof: (a) => typeof SafeEval.evalAst(a, subs),
28569
- void: (a) => void SafeEval.evalAst(a, subs)
28570
- }[ast.operator](ast.argument);
28571
- return result;
28572
- },
28573
- evalArrayExpression(ast, subs) {
28574
- return ast.elements.map((el) => SafeEval.evalAst(el, subs));
28575
- },
28576
- evalCallExpression(ast, subs) {
28577
- const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
28578
- const func = SafeEval.evalAst(ast.callee, subs);
28579
- if (func === Function) {
28580
- throw new Error("Function constructor is disabled");
28581
- }
28582
- return func(...args);
28583
- },
28584
- evalAssignmentExpression(ast, subs) {
28585
- if (ast.left.type !== "Identifier") {
28586
- throw SyntaxError("Invalid left-hand side in assignment");
28587
- }
28588
- const id = ast.left.name;
28589
- const value = SafeEval.evalAst(ast.right, subs);
28590
- subs[id] = value;
28591
- return subs[id];
28592
- }
28593
- };
28594
-
28595
- class SafeScript {
28596
- constructor(expr) {
28597
- this.code = expr;
28598
- this.ast = jsep(this.code);
28599
- }
28600
- runInNewContext(context) {
28601
- const keyMap = Object.assign(Object.create(null), context);
28602
- return SafeEval.evalAst(this.ast, keyMap);
28603
- }
28604
- }
28605
- function push(arr, item) {
28606
- arr = arr.slice();
28607
- arr.push(item);
28608
- return arr;
28609
- }
28610
- function unshift(item, arr) {
28611
- arr = arr.slice();
28612
- arr.unshift(item);
28613
- return arr;
28614
- }
28615
-
28616
- class NewError extends Error {
28617
- constructor(value) {
28618
- super('JSONPath should not be called with "new" (it prevents return ' + "of (unwrapped) scalar values)");
28619
- this.avoidNew = true;
28620
- this.value = value;
28621
- this.name = "NewError";
28622
- }
28623
- }
28624
- function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
28625
- if (!(this instanceof JSONPath)) {
28626
- try {
28627
- return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
28628
- } catch (e) {
28629
- if (!e.avoidNew) {
28630
- throw e;
28631
- }
28632
- return e.value;
28633
- }
28634
- }
28635
- if (typeof opts === "string") {
28636
- otherTypeCallback = callback;
28637
- callback = obj;
28638
- obj = expr;
28639
- expr = opts;
28640
- opts = null;
28641
- }
28642
- const optObj = opts && typeof opts === "object";
28643
- opts = opts || {};
28644
- this.json = opts.json || obj;
28645
- this.path = opts.path || expr;
28646
- this.resultType = opts.resultType || "value";
28647
- this.flatten = opts.flatten || false;
28648
- this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
28649
- this.sandbox = opts.sandbox || {};
28650
- this.eval = opts.eval === undefined ? "safe" : opts.eval;
28651
- this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
28652
- this.parent = opts.parent || null;
28653
- this.parentProperty = opts.parentProperty || null;
28654
- this.callback = opts.callback || callback || null;
28655
- this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
28656
- throw new TypeError("You must supply an otherTypeCallback callback option " + "with the @other() operator.");
28657
- };
28658
- if (opts.autostart !== false) {
28659
- const args = {
28660
- path: optObj ? opts.path : expr
28661
- };
28662
- if (!optObj) {
28663
- args.json = obj;
28664
- } else if ("json" in opts) {
28665
- args.json = opts.json;
28666
- }
28667
- const ret = this.evaluate(args);
28668
- if (!ret || typeof ret !== "object") {
28669
- throw new NewError(ret);
28670
- }
28671
- return ret;
28672
- }
28673
- }
28674
- JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
28675
- let currParent = this.parent, currParentProperty = this.parentProperty;
28676
- let {
28677
- flatten,
28678
- wrap
28679
- } = this;
28680
- this.currResultType = this.resultType;
28681
- this.currEval = this.eval;
28682
- this.currSandbox = this.sandbox;
28683
- callback = callback || this.callback;
28684
- this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
28685
- json = json || this.json;
28686
- expr = expr || this.path;
28687
- if (expr && typeof expr === "object" && !Array.isArray(expr)) {
28688
- if (!expr.path && expr.path !== "") {
28689
- throw new TypeError('You must supply a "path" property when providing an object ' + "argument to JSONPath.evaluate().");
28690
- }
28691
- if (!Object.hasOwn(expr, "json")) {
28692
- throw new TypeError('You must supply a "json" property when providing an object ' + "argument to JSONPath.evaluate().");
28693
- }
28694
- ({
28695
- json
28696
- } = expr);
28697
- flatten = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten;
28698
- this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
28699
- this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
28700
- wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
28701
- this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
28702
- callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
28703
- this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
28704
- currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
28705
- currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
28706
- expr = expr.path;
28707
- }
28708
- currParent = currParent || null;
28709
- currParentProperty = currParentProperty || null;
28710
- if (Array.isArray(expr)) {
28711
- expr = JSONPath.toPathString(expr);
28712
- }
28713
- if (!expr && expr !== "" || !json) {
28714
- return;
28715
- }
28716
- const exprList = JSONPath.toPathArray(expr);
28717
- if (exprList[0] === "$" && exprList.length > 1) {
28718
- exprList.shift();
28719
- }
28720
- this._hasParentSelector = null;
28721
- const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea) {
28722
- return ea && !ea.isParentSelector;
28723
- });
28724
- if (!result.length) {
28725
- return wrap ? [] : undefined;
28726
- }
28727
- if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
28728
- return this._getPreferredOutput(result[0]);
28729
- }
28730
- return result.reduce((rslt, ea) => {
28731
- const valOrPath = this._getPreferredOutput(ea);
28732
- if (flatten && Array.isArray(valOrPath)) {
28733
- rslt = rslt.concat(valOrPath);
28734
- } else {
28735
- rslt.push(valOrPath);
28736
- }
28737
- return rslt;
28738
- }, []);
28739
- };
28740
- JSONPath.prototype._getPreferredOutput = function(ea) {
28741
- const resultType = this.currResultType;
28742
- switch (resultType) {
28743
- case "all": {
28744
- const path3 = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
28745
- ea.pointer = JSONPath.toPointer(path3);
28746
- ea.path = typeof ea.path === "string" ? ea.path : JSONPath.toPathString(ea.path);
28747
- return ea;
28748
- }
28749
- case "value":
28750
- case "parent":
28751
- case "parentProperty":
28752
- return ea[resultType];
28753
- case "path":
28754
- return JSONPath.toPathString(ea[resultType]);
28755
- case "pointer":
28756
- return JSONPath.toPointer(ea.path);
28757
- default:
28758
- throw new TypeError("Unknown result type");
28759
- }
28760
- };
28761
- JSONPath.prototype._handleCallback = function(fullRetObj, callback, type) {
28762
- if (callback) {
28763
- const preferredOutput = this._getPreferredOutput(fullRetObj);
28764
- fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
28765
- callback(preferredOutput, type, fullRetObj);
28766
- }
28767
- };
28768
- JSONPath.prototype._trace = function(expr, val, path3, parent, parentPropName, callback, hasArrExpr, literalPriority) {
28769
- let retObj;
28770
- if (!expr.length) {
28771
- retObj = {
28772
- path: path3,
28773
- value: val,
28774
- parent,
28775
- parentProperty: parentPropName,
28776
- hasArrExpr
28777
- };
28778
- this._handleCallback(retObj, callback, "value");
28779
- return retObj;
28780
- }
28781
- const loc = expr[0], x = expr.slice(1);
28782
- const ret = [];
28783
- function addRet(elems) {
28784
- if (Array.isArray(elems)) {
28785
- elems.forEach((t) => {
28786
- ret.push(t);
28787
- });
28788
- } else {
28789
- ret.push(elems);
28790
- }
28791
- }
28792
- if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
28793
- addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr));
28794
- } else if (loc === "*") {
28795
- this._walk(val, (m) => {
28796
- addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true, true));
28797
- });
28798
- } else if (loc === "..") {
28799
- addRet(this._trace(x, val, path3, parent, parentPropName, callback, hasArrExpr));
28800
- this._walk(val, (m) => {
28801
- if (typeof val[m] === "object") {
28802
- addRet(this._trace(expr.slice(), val[m], push(path3, m), val, m, callback, true));
28803
- }
28804
- });
28805
- } else if (loc === "^") {
28806
- this._hasParentSelector = true;
28807
- return {
28808
- path: path3.slice(0, -1),
28809
- expr: x,
28810
- isParentSelector: true
28811
- };
28812
- } else if (loc === "~") {
28813
- retObj = {
28814
- path: push(path3, loc),
28815
- value: parentPropName,
28816
- parent,
28817
- parentProperty: null
28818
- };
28819
- this._handleCallback(retObj, callback, "property");
28820
- return retObj;
28821
- } else if (loc === "$") {
28822
- addRet(this._trace(x, val, path3, null, null, callback, hasArrExpr));
28823
- } else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
28824
- addRet(this._slice(loc, x, val, path3, parent, parentPropName, callback));
28825
- } else if (loc.indexOf("?(") === 0) {
28826
- if (this.currEval === false) {
28827
- throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
28828
- }
28829
- const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
28830
- const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
28831
- if (nested) {
28832
- this._walk(val, (m) => {
28833
- const npath = [nested[2]];
28834
- const nvalue = nested[1] ? val[m][nested[1]] : val[m];
28835
- const filterResults = this._trace(npath, nvalue, path3, parent, parentPropName, callback, true);
28836
- if (filterResults.length > 0) {
28837
- addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
28838
- }
28839
- });
28840
- } else {
28841
- this._walk(val, (m) => {
28842
- if (this._eval(safeLoc, val[m], m, path3, parent, parentPropName)) {
28843
- addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
28844
- }
28845
- });
28846
- }
28847
- } else if (loc[0] === "(") {
28848
- if (this.currEval === false) {
28849
- throw new Error("Eval [(expr)] prevented in JSONPath expression.");
28850
- }
28851
- addRet(this._trace(unshift(this._eval(loc, val, path3.at(-1), path3.slice(0, -1), parent, parentPropName), x), val, path3, parent, parentPropName, callback, hasArrExpr));
28852
- } else if (loc[0] === "@") {
28853
- let addType = false;
28854
- const valueType = loc.slice(1, -2);
28855
- switch (valueType) {
28856
- case "scalar":
28857
- if (!val || !["object", "function"].includes(typeof val)) {
28858
- addType = true;
28859
- }
28860
- break;
28861
- case "boolean":
28862
- case "string":
28863
- case "undefined":
28864
- case "function":
28865
- if (typeof val === valueType) {
28866
- addType = true;
28867
- }
28868
- break;
28869
- case "integer":
28870
- if (Number.isFinite(val) && !(val % 1)) {
28871
- addType = true;
28872
- }
28873
- break;
28874
- case "number":
28875
- if (Number.isFinite(val)) {
28876
- addType = true;
28877
- }
28878
- break;
28879
- case "nonFinite":
28880
- if (typeof val === "number" && !Number.isFinite(val)) {
28881
- addType = true;
28882
- }
28883
- break;
28884
- case "object":
28885
- if (val && typeof val === valueType) {
28886
- addType = true;
28887
- }
28888
- break;
28889
- case "array":
28890
- if (Array.isArray(val)) {
28891
- addType = true;
28892
- }
28893
- break;
28894
- case "other":
28895
- addType = this.currOtherTypeCallback(val, path3, parent, parentPropName);
28896
- break;
28897
- case "null":
28898
- if (val === null) {
28899
- addType = true;
28900
- }
28901
- break;
28902
- default:
28903
- throw new TypeError("Unknown value type " + valueType);
28904
- }
28905
- if (addType) {
28906
- retObj = {
28907
- path: path3,
28908
- value: val,
28909
- parent,
28910
- parentProperty: parentPropName
28911
- };
28912
- this._handleCallback(retObj, callback, "value");
28913
- return retObj;
28914
- }
28915
- } else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
28916
- const locProp = loc.slice(1);
28917
- addRet(this._trace(x, val[locProp], push(path3, locProp), val, locProp, callback, hasArrExpr, true));
28918
- } else if (loc.includes(",")) {
28919
- const parts = loc.split(",");
28920
- for (const part of parts) {
28921
- addRet(this._trace(unshift(part, x), val, path3, parent, parentPropName, callback, true));
28922
- }
28923
- } else if (!literalPriority && val && Object.hasOwn(val, loc)) {
28924
- addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr, true));
28925
- }
28926
- if (this._hasParentSelector) {
28927
- for (let t = 0;t < ret.length; t++) {
28928
- const rett = ret[t];
28929
- if (rett && rett.isParentSelector) {
28930
- const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
28931
- if (Array.isArray(tmp)) {
28932
- ret[t] = tmp[0];
28933
- const tl = tmp.length;
28934
- for (let tt = 1;tt < tl; tt++) {
28935
- t++;
28936
- ret.splice(t, 0, tmp[tt]);
28937
- }
28938
- } else {
28939
- ret[t] = tmp;
28940
- }
28941
- }
28942
- }
28943
- }
28944
- return ret;
28945
- };
28946
- JSONPath.prototype._walk = function(val, f) {
28947
- if (Array.isArray(val)) {
28948
- const n = val.length;
28949
- for (let i = 0;i < n; i++) {
28950
- f(i);
28951
- }
28952
- } else if (val && typeof val === "object") {
28953
- Object.keys(val).forEach((m) => {
28954
- f(m);
28955
- });
28956
- }
28957
- };
28958
- JSONPath.prototype._slice = function(loc, expr, val, path3, parent, parentPropName, callback) {
28959
- if (!Array.isArray(val)) {
28960
- return;
28961
- }
28962
- const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
28963
- let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
28964
- start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
28965
- end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
28966
- const ret = [];
28967
- for (let i = start;i < end; i += step) {
28968
- const tmp = this._trace(unshift(i, expr), val, path3, parent, parentPropName, callback, true);
28969
- tmp.forEach((t) => {
28970
- ret.push(t);
28971
- });
28972
- }
28973
- return ret;
28974
- };
28975
- JSONPath.prototype._eval = function(code, _v, _vname, path3, parent, parentPropName) {
28976
- this.currSandbox._$_parentProperty = parentPropName;
28977
- this.currSandbox._$_parent = parent;
28978
- this.currSandbox._$_property = _vname;
28979
- this.currSandbox._$_root = this.json;
28980
- this.currSandbox._$_v = _v;
28981
- const containsPath = code.includes("@path");
28982
- if (containsPath) {
28983
- this.currSandbox._$_path = JSONPath.toPathString(path3.concat([_vname]));
28984
- }
28985
- const scriptCacheKey = this.currEval + "Script:" + code;
28986
- if (!JSONPath.cache[scriptCacheKey]) {
28987
- let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
28988
- if (containsPath) {
28989
- script = script.replaceAll("@path", "_$_path");
28990
- }
28991
- if (this.currEval === "safe" || this.currEval === true || this.currEval === undefined) {
28992
- JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
28993
- } else if (this.currEval === "native") {
28994
- JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
28995
- } else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
28996
- const CurrEval = this.currEval;
28997
- JSONPath.cache[scriptCacheKey] = new CurrEval(script);
28998
- } else if (typeof this.currEval === "function") {
28999
- JSONPath.cache[scriptCacheKey] = {
29000
- runInNewContext: (context) => this.currEval(script, context)
29001
- };
29002
- } else {
29003
- throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
29004
- }
29005
- }
29006
- try {
29007
- return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
29008
- } catch (e) {
29009
- if (this.ignoreEvalErrors) {
29010
- return false;
29011
- }
29012
- throw new Error("jsonPath: " + e.message + ": " + code);
29013
- }
29014
- };
29015
- JSONPath.cache = {};
29016
- JSONPath.toPathString = function(pathArr) {
29017
- const x = pathArr, n = x.length;
29018
- let p = "$";
29019
- for (let i = 1;i < n; i++) {
29020
- if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
29021
- p += /^[0-9*]+$/u.test(x[i]) ? "[" + x[i] + "]" : "['" + x[i] + "']";
29022
- }
29023
- }
29024
- return p;
29025
- };
29026
- JSONPath.toPointer = function(pointer) {
29027
- const x = pointer, n = x.length;
29028
- let p = "";
29029
- for (let i = 1;i < n; i++) {
29030
- if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
29031
- p += "/" + x[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
29032
- }
29033
- }
29034
- return p;
29035
- };
29036
- JSONPath.toPathArray = function(expr) {
29037
- const {
29038
- cache
29039
- } = JSONPath;
29040
- if (cache[expr]) {
29041
- return cache[expr].concat();
29042
- }
29043
- const subx = [];
29044
- const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
29045
- return "[#" + (subx.push($1) - 1) + "]";
29046
- }).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
29047
- return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
29048
- }).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
29049
- return ";" + ups.split("").join(";") + ";";
29050
- }).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
29051
- const exprList = normalized.split(";").map(function(exp) {
29052
- const match = exp.match(/#(\d+)/u);
29053
- return !match || !match[1] ? exp : subx[match[1]];
29054
- });
29055
- cache[expr] = exprList;
29056
- return cache[expr].concat();
29057
- };
29058
- JSONPath.prototype.safeVm = {
29059
- Script: SafeScript
29060
- };
29061
- JSONPath.prototype.vm = vm;
29062
28014
  // ../../common/src/option-aliases.ts
29063
28015
  import { Option } from "commander";
29064
28016
  // ../../common/src/option-validators.ts
@@ -29097,6 +28049,18 @@ var FAILURE_STATUSES = new Set([
29097
28049
  "canceled",
29098
28050
  "stopped"
29099
28051
  ]);
28052
+ // ../../common/src/preview.ts
28053
+ import { Command as Command3 } from "commander";
28054
+ var previewSlot = singleton("PreviewBuild");
28055
+ function isPreviewBuild() {
28056
+ return previewSlot.get(false) ?? false;
28057
+ }
28058
+ Command3.prototype.previewCommand = function(nameAndArgs, opts) {
28059
+ if (isPreviewBuild()) {
28060
+ return this.command(nameAndArgs, opts);
28061
+ }
28062
+ return new Command3(nameAndArgs.split(/\s+/)[0] ?? nameAndArgs);
28063
+ };
29100
28064
  // ../../common/src/screen-logger.ts
29101
28065
  var ScreenLogger;
29102
28066
  ((ScreenLogger) => {
@@ -30247,3 +29211,5 @@ export {
30247
29211
  registerCommands,
30248
29212
  metadata
30249
29213
  };
29214
+
29215
+ //# debugId=412A610D3D0C634C64756E2164756E21