@uipath/authz-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.
- package/dist/index.js +889 -1924
- package/dist/tool.js +890 -1924
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -21247,7 +21247,7 @@ var {
|
|
|
21247
21247
|
var package_default = {
|
|
21248
21248
|
name: "@uipath/authz-tool",
|
|
21249
21249
|
license: "MIT",
|
|
21250
|
-
version: "1.
|
|
21250
|
+
version: "1.197.0-preview.59",
|
|
21251
21251
|
description: "CLI plugin for the UiPath Authorization service.",
|
|
21252
21252
|
private: false,
|
|
21253
21253
|
repository: {
|
|
@@ -21273,7 +21273,7 @@ var package_default = {
|
|
|
21273
21273
|
"dist"
|
|
21274
21274
|
],
|
|
21275
21275
|
scripts: {
|
|
21276
|
-
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",
|
|
21276
|
+
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",
|
|
21277
21277
|
package: "bun run build && bun pm pack",
|
|
21278
21278
|
lint: "biome check .",
|
|
21279
21279
|
"lint:fix": "biome check --write .",
|
|
@@ -21337,6 +21337,12 @@ var normalizeAndValidateBaseUrl = (rawUrl) => {
|
|
|
21337
21337
|
}
|
|
21338
21338
|
return url.pathname.length > 1 ? url.origin : baseUrl;
|
|
21339
21339
|
};
|
|
21340
|
+
var resolveScopes = (isExternalAppAuth, customScopes, fileScopes) => {
|
|
21341
|
+
const requestedScopes = customScopes?.length ? customScopes : fileScopes ?? [];
|
|
21342
|
+
if (isExternalAppAuth)
|
|
21343
|
+
return requestedScopes;
|
|
21344
|
+
return [...new Set([...DEFAULT_SCOPES, ...requestedScopes])];
|
|
21345
|
+
};
|
|
21340
21346
|
var resolveConfigAsync = async ({
|
|
21341
21347
|
customAuthority,
|
|
21342
21348
|
customClientId,
|
|
@@ -21367,7 +21373,7 @@ var resolveConfigAsync = async ({
|
|
|
21367
21373
|
clientSecret = fileAuth.clientSecret;
|
|
21368
21374
|
}
|
|
21369
21375
|
const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && Boolean(clientSecret);
|
|
21370
|
-
const scopes =
|
|
21376
|
+
const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
|
|
21371
21377
|
return {
|
|
21372
21378
|
clientId,
|
|
21373
21379
|
clientSecret,
|
|
@@ -21382,6 +21388,76 @@ var resolveConfigAsync = async ({
|
|
|
21382
21388
|
init_constants();
|
|
21383
21389
|
// ../../auth/src/loginStatus.ts
|
|
21384
21390
|
init_src();
|
|
21391
|
+
|
|
21392
|
+
// ../../auth/src/authProfile.ts
|
|
21393
|
+
init_src();
|
|
21394
|
+
init_constants();
|
|
21395
|
+
var DEFAULT_AUTH_PROFILE = "default";
|
|
21396
|
+
var PROFILE_DIR = "profiles";
|
|
21397
|
+
var PROFILE_NAME_RE = /^[A-Za-z0-9._-]+$/;
|
|
21398
|
+
var ACTIVE_AUTH_PROFILE_KEY = Symbol.for("@uipath/auth/ActiveAuthProfile");
|
|
21399
|
+
var AUTH_PROFILE_STORAGE_KEY = Symbol.for("@uipath/auth/ProfileStorage");
|
|
21400
|
+
var globalSlot2 = globalThis;
|
|
21401
|
+
function isAuthProfileStorage(value) {
|
|
21402
|
+
return value !== null && typeof value === "object" && "getStore" in value && "run" in value;
|
|
21403
|
+
}
|
|
21404
|
+
function createProfileStorage() {
|
|
21405
|
+
const [error, mod] = catchError(() => __require("node:async_hooks"));
|
|
21406
|
+
if (error || typeof mod?.AsyncLocalStorage !== "function") {
|
|
21407
|
+
return {
|
|
21408
|
+
getStore: () => {
|
|
21409
|
+
return;
|
|
21410
|
+
},
|
|
21411
|
+
run: (_store, fn) => fn()
|
|
21412
|
+
};
|
|
21413
|
+
}
|
|
21414
|
+
return new mod.AsyncLocalStorage;
|
|
21415
|
+
}
|
|
21416
|
+
function getProfileStorage() {
|
|
21417
|
+
const existing = globalSlot2[AUTH_PROFILE_STORAGE_KEY];
|
|
21418
|
+
if (isAuthProfileStorage(existing)) {
|
|
21419
|
+
return existing;
|
|
21420
|
+
}
|
|
21421
|
+
const storage = createProfileStorage();
|
|
21422
|
+
globalSlot2[AUTH_PROFILE_STORAGE_KEY] = storage;
|
|
21423
|
+
return storage;
|
|
21424
|
+
}
|
|
21425
|
+
var profileStorage = getProfileStorage();
|
|
21426
|
+
|
|
21427
|
+
class AuthProfileValidationError extends Error {
|
|
21428
|
+
constructor(message) {
|
|
21429
|
+
super(message);
|
|
21430
|
+
this.name = "AuthProfileValidationError";
|
|
21431
|
+
}
|
|
21432
|
+
}
|
|
21433
|
+
function normalizeAuthProfileName(profile) {
|
|
21434
|
+
if (profile === undefined || profile === DEFAULT_AUTH_PROFILE) {
|
|
21435
|
+
return;
|
|
21436
|
+
}
|
|
21437
|
+
if (profile.length === 0 || profile === "." || profile === ".." || !PROFILE_NAME_RE.test(profile)) {
|
|
21438
|
+
throw new AuthProfileValidationError(`Invalid profile name "${profile}". Profile names may contain only letters, numbers, '.', '_', and '-'.`);
|
|
21439
|
+
}
|
|
21440
|
+
return profile;
|
|
21441
|
+
}
|
|
21442
|
+
function getActiveAuthProfile() {
|
|
21443
|
+
const scopedState = profileStorage.getStore();
|
|
21444
|
+
if (scopedState !== undefined) {
|
|
21445
|
+
return scopedState.profile;
|
|
21446
|
+
}
|
|
21447
|
+
return globalSlot2[ACTIVE_AUTH_PROFILE_KEY]?.profile;
|
|
21448
|
+
}
|
|
21449
|
+
function resolveAuthProfileFilePath(profile) {
|
|
21450
|
+
const normalized = normalizeAuthProfileName(profile);
|
|
21451
|
+
if (normalized === undefined) {
|
|
21452
|
+
throw new AuthProfileValidationError(`"${DEFAULT_AUTH_PROFILE}" is the built-in profile and does not have a profile file path.`);
|
|
21453
|
+
}
|
|
21454
|
+
const fs7 = getFileSystem();
|
|
21455
|
+
return fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR, normalized, AUTH_FILENAME);
|
|
21456
|
+
}
|
|
21457
|
+
function getActiveAuthProfileFilePath() {
|
|
21458
|
+
const profile = getActiveAuthProfile();
|
|
21459
|
+
return profile ? resolveAuthProfileFilePath(profile) : undefined;
|
|
21460
|
+
}
|
|
21385
21461
|
// ../../auth/src/utils/jwt.ts
|
|
21386
21462
|
class InvalidIssuerError extends Error {
|
|
21387
21463
|
expected;
|
|
@@ -21510,23 +21586,74 @@ var readAuthFromEnv = () => {
|
|
|
21510
21586
|
organizationId,
|
|
21511
21587
|
tenantName,
|
|
21512
21588
|
tenantId,
|
|
21513
|
-
expiration
|
|
21589
|
+
expiration,
|
|
21590
|
+
source: "env" /* Env */
|
|
21514
21591
|
};
|
|
21515
21592
|
};
|
|
21516
21593
|
|
|
21594
|
+
// ../../auth/src/refreshCircuitBreaker.ts
|
|
21595
|
+
init_src();
|
|
21596
|
+
var BREAKER_SUFFIX = ".refresh-state";
|
|
21597
|
+
var BACKOFF_BASE_MS = 60000;
|
|
21598
|
+
var BACKOFF_CAP_MS = 60 * 60 * 1000;
|
|
21599
|
+
var SURFACE_WINDOW_MS = 60 * 60 * 1000;
|
|
21600
|
+
async function refreshTokenFingerprint(refreshToken) {
|
|
21601
|
+
const bytes = new TextEncoder().encode(refreshToken);
|
|
21602
|
+
if (globalThis.crypto?.subtle) {
|
|
21603
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
21604
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
21605
|
+
}
|
|
21606
|
+
const { createHash } = await import("node:crypto");
|
|
21607
|
+
return createHash("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
21608
|
+
}
|
|
21609
|
+
function breakerPathFor(authPath) {
|
|
21610
|
+
return `${authPath}${BREAKER_SUFFIX}`;
|
|
21611
|
+
}
|
|
21612
|
+
async function loadRefreshBreaker(authPath) {
|
|
21613
|
+
const fs7 = getFileSystem();
|
|
21614
|
+
try {
|
|
21615
|
+
const content = await fs7.readFile(breakerPathFor(authPath), "utf-8");
|
|
21616
|
+
if (!content)
|
|
21617
|
+
return {};
|
|
21618
|
+
const parsed = JSON.parse(content);
|
|
21619
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
21620
|
+
} catch {
|
|
21621
|
+
return {};
|
|
21622
|
+
}
|
|
21623
|
+
}
|
|
21624
|
+
async function saveRefreshBreaker(authPath, state) {
|
|
21625
|
+
try {
|
|
21626
|
+
const fs7 = getFileSystem();
|
|
21627
|
+
const path3 = breakerPathFor(authPath);
|
|
21628
|
+
await fs7.mkdir(fs7.path.dirname(path3));
|
|
21629
|
+
const tempPath = `${path3}.tmp`;
|
|
21630
|
+
await fs7.writeFile(tempPath, JSON.stringify(state));
|
|
21631
|
+
await fs7.rename(tempPath, path3);
|
|
21632
|
+
} catch {}
|
|
21633
|
+
}
|
|
21634
|
+
async function clearRefreshBreaker(authPath) {
|
|
21635
|
+
const fs7 = getFileSystem();
|
|
21636
|
+
const path3 = breakerPathFor(authPath);
|
|
21637
|
+
try {
|
|
21638
|
+
if (await fs7.exists(path3)) {
|
|
21639
|
+
await fs7.rm(path3);
|
|
21640
|
+
}
|
|
21641
|
+
} catch {}
|
|
21642
|
+
}
|
|
21643
|
+
function nextBackoffMs(attempts) {
|
|
21644
|
+
const shift = Math.max(0, attempts - 1);
|
|
21645
|
+
return Math.min(BACKOFF_BASE_MS * 2 ** shift, BACKOFF_CAP_MS);
|
|
21646
|
+
}
|
|
21647
|
+
function shouldSurface(state, nowMs) {
|
|
21648
|
+
if (state.lastSurfacedAtMs === undefined)
|
|
21649
|
+
return true;
|
|
21650
|
+
return nowMs - state.lastSurfacedAtMs >= SURFACE_WINDOW_MS;
|
|
21651
|
+
}
|
|
21652
|
+
|
|
21517
21653
|
// ../../auth/src/robotClientFallback.ts
|
|
21518
21654
|
init_src();
|
|
21519
21655
|
var DEFAULT_TIMEOUT_MS = 1000;
|
|
21520
21656
|
var CLOSE_TIMEOUT_MS = 500;
|
|
21521
|
-
var NOTICE_SENTINEL = Symbol.for("@uipath/auth/robotFallbackNoticePrinted");
|
|
21522
|
-
var printNoticeOnce = () => {
|
|
21523
|
-
const slot = globalThis;
|
|
21524
|
-
if (slot[NOTICE_SENTINEL])
|
|
21525
|
-
return;
|
|
21526
|
-
slot[NOTICE_SENTINEL] = true;
|
|
21527
|
-
catchError(() => process.stderr.write(`Using UiPath Robot credentials. Run 'uip login' for a dedicated session.
|
|
21528
|
-
`));
|
|
21529
|
-
};
|
|
21530
21657
|
var ROBOT_USER_SERVICES_PIPE = "UiPathUserServices";
|
|
21531
21658
|
var ROBOT_USER_SERVICES_ALTERNATE_PIPE = `${ROBOT_USER_SERVICES_PIPE}Alternate`;
|
|
21532
21659
|
var PIPE_NAME_MAX_LENGTH = 103;
|
|
@@ -21642,7 +21769,6 @@ var tryRobotClientFallback = async (options = {}) => {
|
|
|
21642
21769
|
issuerFromToken = issClaim;
|
|
21643
21770
|
}
|
|
21644
21771
|
}
|
|
21645
|
-
printNoticeOnce();
|
|
21646
21772
|
return {
|
|
21647
21773
|
accessToken,
|
|
21648
21774
|
baseUrl: parsedUrl.baseUrl,
|
|
@@ -21867,18 +21993,327 @@ var saveEnvFileAsync = async ({
|
|
|
21867
21993
|
};
|
|
21868
21994
|
|
|
21869
21995
|
// ../../auth/src/loginStatus.ts
|
|
21870
|
-
|
|
21871
|
-
return
|
|
21996
|
+
var getLoginStatusAsync = async (options = {}) => {
|
|
21997
|
+
return getLoginStatusWithDeps(options);
|
|
21998
|
+
};
|
|
21999
|
+
var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
|
|
22000
|
+
const {
|
|
22001
|
+
resolveEnvFilePath = resolveEnvFilePathAsync,
|
|
22002
|
+
loadEnvFile = loadEnvFileAsync,
|
|
22003
|
+
saveEnvFile = saveEnvFileAsync,
|
|
22004
|
+
getFs = getFileSystem,
|
|
22005
|
+
refreshToken: refreshTokenFn = refreshAccessToken,
|
|
22006
|
+
resolveConfig = resolveConfigAsync,
|
|
22007
|
+
robotFallback = tryRobotClientFallback,
|
|
22008
|
+
loadBreaker = loadRefreshBreaker,
|
|
22009
|
+
saveBreaker = saveRefreshBreaker,
|
|
22010
|
+
clearBreaker = clearRefreshBreaker
|
|
22011
|
+
} = deps;
|
|
22012
|
+
if (isRobotAuthEnforced()) {
|
|
22013
|
+
return resolveRobotEnforcedStatus(robotFallback);
|
|
22014
|
+
}
|
|
22015
|
+
if (isEnvAuthEnabled()) {
|
|
22016
|
+
return readAuthFromEnv();
|
|
22017
|
+
}
|
|
22018
|
+
const activeProfile = getActiveAuthProfile();
|
|
22019
|
+
const activeProfileFilePath = getActiveAuthProfileFilePath();
|
|
22020
|
+
const usingActiveProfile = activeProfile !== undefined && (options.envFilePath === undefined || options.envFilePath === activeProfileFilePath);
|
|
22021
|
+
const envFilePath = options.envFilePath ?? activeProfileFilePath ?? DEFAULT_ENV_FILENAME;
|
|
22022
|
+
const { ensureTokenValidityMinutes } = options;
|
|
22023
|
+
const { absolutePath } = await resolveEnvFilePath(envFilePath);
|
|
22024
|
+
if (absolutePath === undefined) {
|
|
22025
|
+
if (usingActiveProfile) {
|
|
22026
|
+
return {
|
|
22027
|
+
loginStatus: "Not logged in",
|
|
22028
|
+
hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
|
|
22029
|
+
};
|
|
22030
|
+
}
|
|
22031
|
+
return resolveBorrowedRobotStatus(robotFallback);
|
|
22032
|
+
}
|
|
22033
|
+
const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
|
|
22034
|
+
if ("status" in loaded) {
|
|
22035
|
+
return loaded.status;
|
|
22036
|
+
}
|
|
22037
|
+
const { credentials } = loaded;
|
|
22038
|
+
const globalHint = () => usingActiveProfile ? Promise.resolve(undefined) : getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath);
|
|
22039
|
+
const expiration = getTokenExpiration(credentials.UIPATH_ACCESS_TOKEN);
|
|
22040
|
+
const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
22041
|
+
let tokens = {
|
|
22042
|
+
accessToken: credentials.UIPATH_ACCESS_TOKEN,
|
|
22043
|
+
refreshToken: credentials.UIPATH_REFRESH_TOKEN,
|
|
22044
|
+
expiration,
|
|
22045
|
+
lockReleaseFailed: false
|
|
22046
|
+
};
|
|
22047
|
+
const refreshToken = credentials.UIPATH_REFRESH_TOKEN;
|
|
22048
|
+
if (expiration && expiration <= outerThreshold && refreshToken) {
|
|
22049
|
+
const refreshed = await attemptRefresh({
|
|
22050
|
+
absolutePath,
|
|
22051
|
+
credentials,
|
|
22052
|
+
accessToken: credentials.UIPATH_ACCESS_TOKEN,
|
|
22053
|
+
refreshToken,
|
|
22054
|
+
expiration,
|
|
22055
|
+
ensureTokenValidityMinutes,
|
|
22056
|
+
getFs,
|
|
22057
|
+
loadEnvFile,
|
|
22058
|
+
saveEnvFile,
|
|
22059
|
+
refreshFn: refreshTokenFn,
|
|
22060
|
+
resolveConfig,
|
|
22061
|
+
loadBreaker,
|
|
22062
|
+
saveBreaker,
|
|
22063
|
+
clearBreaker,
|
|
22064
|
+
globalHint
|
|
22065
|
+
});
|
|
22066
|
+
if (refreshed.kind === "terminal") {
|
|
22067
|
+
return refreshed.status;
|
|
22068
|
+
}
|
|
22069
|
+
tokens = refreshed.tokens;
|
|
22070
|
+
}
|
|
22071
|
+
return buildFileStatus(tokens, credentials, globalHint);
|
|
22072
|
+
};
|
|
22073
|
+
async function resolveRobotEnforcedStatus(robotFallback) {
|
|
22074
|
+
if (isEnvAuthEnabled()) {
|
|
22075
|
+
throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
|
|
22076
|
+
}
|
|
22077
|
+
const robotCreds = await robotFallback({ force: true });
|
|
22078
|
+
if (!robotCreds) {
|
|
22079
|
+
return {
|
|
22080
|
+
loginStatus: "Not logged in",
|
|
22081
|
+
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.`
|
|
22082
|
+
};
|
|
22083
|
+
}
|
|
22084
|
+
return buildRobotStatus(robotCreds);
|
|
21872
22085
|
}
|
|
21873
|
-
function
|
|
21874
|
-
|
|
22086
|
+
async function resolveBorrowedRobotStatus(robotFallback) {
|
|
22087
|
+
const robotCreds = await robotFallback();
|
|
22088
|
+
return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
|
|
21875
22089
|
}
|
|
21876
|
-
function
|
|
21877
|
-
|
|
22090
|
+
async function loadFileCredentials(loadEnvFile, absolutePath) {
|
|
22091
|
+
let credentials;
|
|
22092
|
+
try {
|
|
22093
|
+
credentials = await loadEnvFile({ envPath: absolutePath });
|
|
22094
|
+
} catch (error) {
|
|
22095
|
+
if (isFileNotFoundError(error)) {
|
|
22096
|
+
return { status: { loginStatus: "Not logged in" } };
|
|
22097
|
+
}
|
|
22098
|
+
throw error;
|
|
22099
|
+
}
|
|
22100
|
+
if (!credentials.UIPATH_ACCESS_TOKEN) {
|
|
22101
|
+
return { status: { loginStatus: "Not logged in" } };
|
|
22102
|
+
}
|
|
22103
|
+
return { credentials };
|
|
22104
|
+
}
|
|
22105
|
+
async function getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath) {
|
|
22106
|
+
const fs7 = getFs();
|
|
22107
|
+
const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
|
|
22108
|
+
if (absolutePath === globalPath)
|
|
22109
|
+
return;
|
|
22110
|
+
if (!await fs7.exists(globalPath))
|
|
22111
|
+
return;
|
|
22112
|
+
try {
|
|
22113
|
+
const globalCreds = await loadEnvFile({ envPath: globalPath });
|
|
22114
|
+
if (!globalCreds.UIPATH_ACCESS_TOKEN)
|
|
22115
|
+
return;
|
|
22116
|
+
const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
|
|
22117
|
+
if (globalExp && globalExp <= new Date)
|
|
22118
|
+
return;
|
|
22119
|
+
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.`;
|
|
22120
|
+
} catch {
|
|
22121
|
+
return;
|
|
22122
|
+
}
|
|
21878
22123
|
}
|
|
21879
22124
|
function computeExpirationThreshold(ensureTokenValidityMinutes) {
|
|
21880
22125
|
return new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
|
|
21881
22126
|
}
|
|
22127
|
+
async function attemptRefresh(ctx) {
|
|
22128
|
+
const shortCircuit = await circuitBreakerShortCircuit(ctx);
|
|
22129
|
+
if (shortCircuit) {
|
|
22130
|
+
return { kind: "terminal", status: shortCircuit };
|
|
22131
|
+
}
|
|
22132
|
+
let release;
|
|
22133
|
+
try {
|
|
22134
|
+
release = await ctx.getFs().acquireLock(ctx.absolutePath);
|
|
22135
|
+
} catch (error) {
|
|
22136
|
+
return {
|
|
22137
|
+
kind: "terminal",
|
|
22138
|
+
status: await lockAcquireFailureStatus(ctx, error)
|
|
22139
|
+
};
|
|
22140
|
+
}
|
|
22141
|
+
let lockedFailure;
|
|
22142
|
+
let lockReleaseFailed = false;
|
|
22143
|
+
let success;
|
|
22144
|
+
try {
|
|
22145
|
+
const outcome = await runRefreshLocked({
|
|
22146
|
+
absolutePath: ctx.absolutePath,
|
|
22147
|
+
refreshToken: ctx.refreshToken,
|
|
22148
|
+
customAuthority: ctx.credentials.UIPATH_URL,
|
|
22149
|
+
ensureTokenValidityMinutes: ctx.ensureTokenValidityMinutes,
|
|
22150
|
+
loadEnvFile: ctx.loadEnvFile,
|
|
22151
|
+
saveEnvFile: ctx.saveEnvFile,
|
|
22152
|
+
refreshFn: ctx.refreshFn,
|
|
22153
|
+
resolveConfig: ctx.resolveConfig,
|
|
22154
|
+
loadBreaker: ctx.loadBreaker,
|
|
22155
|
+
saveBreaker: ctx.saveBreaker,
|
|
22156
|
+
clearBreaker: ctx.clearBreaker
|
|
22157
|
+
});
|
|
22158
|
+
if (outcome.kind === "fail") {
|
|
22159
|
+
lockedFailure = outcome.status;
|
|
22160
|
+
} else {
|
|
22161
|
+
success = outcome;
|
|
22162
|
+
}
|
|
22163
|
+
} finally {
|
|
22164
|
+
try {
|
|
22165
|
+
await release();
|
|
22166
|
+
} catch {
|
|
22167
|
+
lockReleaseFailed = true;
|
|
22168
|
+
}
|
|
22169
|
+
}
|
|
22170
|
+
if (lockedFailure) {
|
|
22171
|
+
const globalHint = await ctx.globalHint();
|
|
22172
|
+
const base = globalHint ? { ...lockedFailure, loginStatus: "Expired", hint: globalHint } : lockedFailure;
|
|
22173
|
+
return {
|
|
22174
|
+
kind: "terminal",
|
|
22175
|
+
status: lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base
|
|
22176
|
+
};
|
|
22177
|
+
}
|
|
22178
|
+
return {
|
|
22179
|
+
kind: "refreshed",
|
|
22180
|
+
tokens: {
|
|
22181
|
+
accessToken: success?.accessToken,
|
|
22182
|
+
refreshToken: success?.refreshToken,
|
|
22183
|
+
expiration: success?.expiration,
|
|
22184
|
+
tokenRefresh: success?.tokenRefresh,
|
|
22185
|
+
persistenceWarning: success?.persistenceWarning,
|
|
22186
|
+
lockReleaseFailed
|
|
22187
|
+
}
|
|
22188
|
+
};
|
|
22189
|
+
}
|
|
22190
|
+
async function buildFileStatus(tokens, credentials, globalHint) {
|
|
22191
|
+
const result = {
|
|
22192
|
+
loginStatus: tokens.expiration && tokens.expiration <= new Date ? "Expired" : "Logged in",
|
|
22193
|
+
accessToken: tokens.accessToken,
|
|
22194
|
+
refreshToken: tokens.refreshToken,
|
|
22195
|
+
baseUrl: credentials.UIPATH_URL,
|
|
22196
|
+
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22197
|
+
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22198
|
+
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22199
|
+
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22200
|
+
expiration: tokens.expiration,
|
|
22201
|
+
source: "file" /* File */,
|
|
22202
|
+
...tokens.persistenceWarning ? { hint: tokens.persistenceWarning, persistenceFailed: true } : {},
|
|
22203
|
+
...tokens.lockReleaseFailed ? { lockReleaseFailed: true } : {},
|
|
22204
|
+
...tokens.tokenRefresh ? { tokenRefresh: tokens.tokenRefresh } : {}
|
|
22205
|
+
};
|
|
22206
|
+
if (result.loginStatus === "Expired") {
|
|
22207
|
+
const hint = await globalHint();
|
|
22208
|
+
if (hint) {
|
|
22209
|
+
result.hint = hint;
|
|
22210
|
+
}
|
|
22211
|
+
}
|
|
22212
|
+
return result;
|
|
22213
|
+
}
|
|
22214
|
+
function buildRobotStatus(robotCreds) {
|
|
22215
|
+
return {
|
|
22216
|
+
loginStatus: "Logged in",
|
|
22217
|
+
accessToken: robotCreds.accessToken,
|
|
22218
|
+
baseUrl: robotCreds.baseUrl,
|
|
22219
|
+
organizationName: robotCreds.organizationName,
|
|
22220
|
+
organizationId: robotCreds.organizationId,
|
|
22221
|
+
tenantName: robotCreds.tenantName,
|
|
22222
|
+
tenantId: robotCreds.tenantId,
|
|
22223
|
+
issuer: robotCreds.issuer,
|
|
22224
|
+
expiration: getTokenExpiration(robotCreds.accessToken),
|
|
22225
|
+
source: "robot" /* Robot */
|
|
22226
|
+
};
|
|
22227
|
+
}
|
|
22228
|
+
var isFileNotFoundError = (error) => {
|
|
22229
|
+
if (!(error instanceof Object))
|
|
22230
|
+
return false;
|
|
22231
|
+
return error.code === "ENOENT";
|
|
22232
|
+
};
|
|
22233
|
+
async function circuitBreakerShortCircuit(ctx) {
|
|
22234
|
+
const {
|
|
22235
|
+
absolutePath,
|
|
22236
|
+
refreshToken,
|
|
22237
|
+
accessToken,
|
|
22238
|
+
credentials,
|
|
22239
|
+
expiration,
|
|
22240
|
+
loadBreaker,
|
|
22241
|
+
saveBreaker,
|
|
22242
|
+
clearBreaker
|
|
22243
|
+
} = ctx;
|
|
22244
|
+
const fingerprint = await refreshTokenFingerprint(refreshToken);
|
|
22245
|
+
const breaker = await loadBreaker(absolutePath).catch(() => ({}));
|
|
22246
|
+
if (breaker.deadTokenFp && breaker.deadTokenFp !== fingerprint) {
|
|
22247
|
+
await clearBreaker(absolutePath);
|
|
22248
|
+
breaker.deadTokenFp = undefined;
|
|
22249
|
+
}
|
|
22250
|
+
const nowMs = Date.now();
|
|
22251
|
+
const tokenIsDead = breaker.deadTokenFp === fingerprint;
|
|
22252
|
+
const inBackoff = breaker.backoffUntilMs !== undefined && nowMs < breaker.backoffUntilMs;
|
|
22253
|
+
if (!tokenIsDead && !inBackoff)
|
|
22254
|
+
return;
|
|
22255
|
+
const globalHint = await ctx.globalHint();
|
|
22256
|
+
const suppressed = !shouldSurface(breaker, nowMs);
|
|
22257
|
+
if (!suppressed) {
|
|
22258
|
+
await saveBreaker(absolutePath, {
|
|
22259
|
+
...breaker,
|
|
22260
|
+
lastSurfacedAtMs: nowMs
|
|
22261
|
+
});
|
|
22262
|
+
}
|
|
22263
|
+
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>.";
|
|
22264
|
+
const backoffHint = "Token refresh is temporarily backed off after a recent network error and will retry automatically once the backoff window elapses.";
|
|
22265
|
+
return {
|
|
22266
|
+
loginStatus: globalHint ? "Expired" : "Refresh Failed",
|
|
22267
|
+
...globalHint ? {
|
|
22268
|
+
accessToken,
|
|
22269
|
+
refreshToken,
|
|
22270
|
+
baseUrl: credentials.UIPATH_URL,
|
|
22271
|
+
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22272
|
+
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22273
|
+
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22274
|
+
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22275
|
+
expiration,
|
|
22276
|
+
source: "file" /* File */
|
|
22277
|
+
} : {},
|
|
22278
|
+
hint: globalHint ?? (tokenIsDead ? deadHint : backoffHint),
|
|
22279
|
+
refreshCircuitOpen: true,
|
|
22280
|
+
refreshTelemetrySuppressed: suppressed,
|
|
22281
|
+
tokenRefresh: { attempted: false, success: false }
|
|
22282
|
+
};
|
|
22283
|
+
}
|
|
22284
|
+
async function lockAcquireFailureStatus(ctx, error) {
|
|
22285
|
+
const msg = errorMessage(error);
|
|
22286
|
+
const globalHint = await ctx.globalHint();
|
|
22287
|
+
if (globalHint) {
|
|
22288
|
+
return {
|
|
22289
|
+
loginStatus: "Expired",
|
|
22290
|
+
accessToken: ctx.accessToken,
|
|
22291
|
+
refreshToken: ctx.refreshToken,
|
|
22292
|
+
baseUrl: ctx.credentials.UIPATH_URL,
|
|
22293
|
+
organizationName: ctx.credentials.UIPATH_ORGANIZATION_NAME,
|
|
22294
|
+
organizationId: ctx.credentials.UIPATH_ORGANIZATION_ID,
|
|
22295
|
+
tenantName: ctx.credentials.UIPATH_TENANT_NAME,
|
|
22296
|
+
tenantId: ctx.credentials.UIPATH_TENANT_ID,
|
|
22297
|
+
expiration: ctx.expiration,
|
|
22298
|
+
source: "file" /* File */,
|
|
22299
|
+
hint: globalHint,
|
|
22300
|
+
tokenRefresh: {
|
|
22301
|
+
attempted: false,
|
|
22302
|
+
success: false,
|
|
22303
|
+
errorMessage: `lock acquisition failed: ${msg}`
|
|
22304
|
+
}
|
|
22305
|
+
};
|
|
22306
|
+
}
|
|
22307
|
+
return {
|
|
22308
|
+
loginStatus: "Refresh Failed",
|
|
22309
|
+
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.",
|
|
22310
|
+
tokenRefresh: {
|
|
22311
|
+
attempted: false,
|
|
22312
|
+
success: false,
|
|
22313
|
+
errorMessage: `lock acquisition failed: ${msg}`
|
|
22314
|
+
}
|
|
22315
|
+
};
|
|
22316
|
+
}
|
|
21882
22317
|
async function runRefreshLocked(inputs) {
|
|
21883
22318
|
const {
|
|
21884
22319
|
absolutePath,
|
|
@@ -21888,7 +22323,10 @@ async function runRefreshLocked(inputs) {
|
|
|
21888
22323
|
loadEnvFile,
|
|
21889
22324
|
saveEnvFile,
|
|
21890
22325
|
refreshFn,
|
|
21891
|
-
resolveConfig
|
|
22326
|
+
resolveConfig,
|
|
22327
|
+
loadBreaker,
|
|
22328
|
+
saveBreaker,
|
|
22329
|
+
clearBreaker
|
|
21892
22330
|
} = inputs;
|
|
21893
22331
|
const expirationThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
21894
22332
|
let fresh;
|
|
@@ -21911,6 +22349,7 @@ async function runRefreshLocked(inputs) {
|
|
|
21911
22349
|
const freshAccess = fresh.UIPATH_ACCESS_TOKEN;
|
|
21912
22350
|
const freshExp = freshAccess ? getTokenExpiration(freshAccess) : undefined;
|
|
21913
22351
|
if (freshAccess && freshExp && freshExp > expirationThreshold) {
|
|
22352
|
+
await clearBreaker(absolutePath);
|
|
21914
22353
|
return {
|
|
21915
22354
|
kind: "ok",
|
|
21916
22355
|
accessToken: freshAccess,
|
|
@@ -21934,8 +22373,21 @@ async function runRefreshLocked(inputs) {
|
|
|
21934
22373
|
refreshedRefresh = refreshed.refreshToken;
|
|
21935
22374
|
} catch (error) {
|
|
21936
22375
|
const isOAuthFailure = isTokenRefreshOAuthFailure(error);
|
|
21937
|
-
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.";
|
|
22376
|
+
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.";
|
|
21938
22377
|
const message = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
|
|
22378
|
+
const fp = await refreshTokenFingerprint(tokenForIdP);
|
|
22379
|
+
if (isOAuthFailure) {
|
|
22380
|
+
await saveBreaker(absolutePath, { deadTokenFp: fp });
|
|
22381
|
+
} else {
|
|
22382
|
+
const prior = await loadBreaker(absolutePath).catch(() => ({}));
|
|
22383
|
+
const attempts = (prior.attempts ?? 0) + 1;
|
|
22384
|
+
await saveBreaker(absolutePath, {
|
|
22385
|
+
...prior,
|
|
22386
|
+
deadTokenFp: undefined,
|
|
22387
|
+
attempts,
|
|
22388
|
+
backoffUntilMs: Date.now() + nextBackoffMs(attempts)
|
|
22389
|
+
});
|
|
22390
|
+
}
|
|
21939
22391
|
return {
|
|
21940
22392
|
kind: "fail",
|
|
21941
22393
|
status: {
|
|
@@ -21964,6 +22416,7 @@ async function runRefreshLocked(inputs) {
|
|
|
21964
22416
|
}
|
|
21965
22417
|
};
|
|
21966
22418
|
}
|
|
22419
|
+
await clearBreaker(absolutePath);
|
|
21967
22420
|
try {
|
|
21968
22421
|
await saveEnvFile({
|
|
21969
22422
|
envPath: absolutePath,
|
|
@@ -21996,234 +22449,37 @@ async function runRefreshLocked(inputs) {
|
|
|
21996
22449
|
};
|
|
21997
22450
|
}
|
|
21998
22451
|
}
|
|
21999
|
-
|
|
22000
|
-
|
|
22001
|
-
|
|
22002
|
-
|
|
22003
|
-
|
|
22004
|
-
|
|
22005
|
-
|
|
22006
|
-
|
|
22007
|
-
|
|
22008
|
-
|
|
22009
|
-
|
|
22010
|
-
|
|
22011
|
-
|
|
22012
|
-
|
|
22013
|
-
|
|
22014
|
-
|
|
22015
|
-
|
|
22016
|
-
|
|
22017
|
-
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.`
|
|
22018
|
-
};
|
|
22019
|
-
}
|
|
22020
|
-
const expiration2 = getTokenExpiration(robotCreds.accessToken);
|
|
22021
|
-
return {
|
|
22022
|
-
loginStatus: "Logged in",
|
|
22023
|
-
accessToken: robotCreds.accessToken,
|
|
22024
|
-
baseUrl: robotCreds.baseUrl,
|
|
22025
|
-
organizationName: robotCreds.organizationName,
|
|
22026
|
-
organizationId: robotCreds.organizationId,
|
|
22027
|
-
tenantName: robotCreds.tenantName,
|
|
22028
|
-
tenantId: robotCreds.tenantId,
|
|
22029
|
-
issuer: robotCreds.issuer,
|
|
22030
|
-
expiration: expiration2,
|
|
22031
|
-
source: "robot" /* Robot */
|
|
22032
|
-
};
|
|
22452
|
+
function normalizeTokenRefreshFailure() {
|
|
22453
|
+
return "stored refresh token is invalid or expired";
|
|
22454
|
+
}
|
|
22455
|
+
function normalizeTokenRefreshUnavailableFailure() {
|
|
22456
|
+
return "token refresh failed before authentication completed";
|
|
22457
|
+
}
|
|
22458
|
+
function errorMessage(error) {
|
|
22459
|
+
return error instanceof Error ? error.message : String(error);
|
|
22460
|
+
}
|
|
22461
|
+
|
|
22462
|
+
// ../../auth/src/authContext.ts
|
|
22463
|
+
var getAuthContext = async (options = {}) => {
|
|
22464
|
+
const status = await getLoginStatusAsync({
|
|
22465
|
+
ensureTokenValidityMinutes: options.ensureTokenValidityMinutes,
|
|
22466
|
+
envFilePath: options.envFilePath
|
|
22467
|
+
});
|
|
22468
|
+
if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
|
|
22469
|
+
throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
|
|
22033
22470
|
}
|
|
22034
|
-
|
|
22035
|
-
|
|
22471
|
+
const tenantName = options.tenant ?? status.tenantName;
|
|
22472
|
+
if (options.requireOrganizationId && !status.organizationId) {
|
|
22473
|
+
throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
|
|
22036
22474
|
}
|
|
22037
|
-
|
|
22038
|
-
|
|
22039
|
-
if (absolutePath === undefined) {
|
|
22040
|
-
const robotCreds = await robotFallback();
|
|
22041
|
-
if (robotCreds) {
|
|
22042
|
-
const expiration2 = getTokenExpiration(robotCreds.accessToken);
|
|
22043
|
-
const status = {
|
|
22044
|
-
loginStatus: "Logged in",
|
|
22045
|
-
accessToken: robotCreds.accessToken,
|
|
22046
|
-
baseUrl: robotCreds.baseUrl,
|
|
22047
|
-
organizationName: robotCreds.organizationName,
|
|
22048
|
-
organizationId: robotCreds.organizationId,
|
|
22049
|
-
tenantName: robotCreds.tenantName,
|
|
22050
|
-
tenantId: robotCreds.tenantId,
|
|
22051
|
-
issuer: robotCreds.issuer,
|
|
22052
|
-
expiration: expiration2,
|
|
22053
|
-
source: "robot" /* Robot */
|
|
22054
|
-
};
|
|
22055
|
-
return status;
|
|
22056
|
-
}
|
|
22057
|
-
return { loginStatus: "Not logged in" };
|
|
22475
|
+
if (options.requireOrganizationName && !status.organizationName) {
|
|
22476
|
+
throw new Error("Organization name not available. Ensure you are logged in with an organization context.");
|
|
22058
22477
|
}
|
|
22059
|
-
|
|
22060
|
-
|
|
22061
|
-
credentials = await loadEnvFile({ envPath: absolutePath });
|
|
22062
|
-
} catch (error) {
|
|
22063
|
-
if (isFileNotFoundError(error)) {
|
|
22064
|
-
return { loginStatus: "Not logged in" };
|
|
22065
|
-
}
|
|
22066
|
-
throw error;
|
|
22478
|
+
if (options.requireTenantId && !status.tenantId) {
|
|
22479
|
+
throw new Error("Tenant ID not available. Ensure UIPATH_TENANT_ID is set.");
|
|
22067
22480
|
}
|
|
22068
|
-
if (
|
|
22069
|
-
|
|
22070
|
-
}
|
|
22071
|
-
let accessToken = credentials.UIPATH_ACCESS_TOKEN;
|
|
22072
|
-
let refreshToken = credentials.UIPATH_REFRESH_TOKEN;
|
|
22073
|
-
let expiration = getTokenExpiration(accessToken);
|
|
22074
|
-
let persistenceWarning;
|
|
22075
|
-
let lockReleaseFailed = false;
|
|
22076
|
-
let tokenRefresh;
|
|
22077
|
-
const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
22078
|
-
const tryGlobalCredsHint = async () => {
|
|
22079
|
-
const fs7 = getFs();
|
|
22080
|
-
const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
|
|
22081
|
-
if (absolutePath === globalPath)
|
|
22082
|
-
return;
|
|
22083
|
-
if (!await fs7.exists(globalPath))
|
|
22084
|
-
return;
|
|
22085
|
-
try {
|
|
22086
|
-
const globalCreds = await loadEnvFile({ envPath: globalPath });
|
|
22087
|
-
if (!globalCreds.UIPATH_ACCESS_TOKEN)
|
|
22088
|
-
return;
|
|
22089
|
-
const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
|
|
22090
|
-
if (globalExp && globalExp <= new Date)
|
|
22091
|
-
return;
|
|
22092
|
-
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.`;
|
|
22093
|
-
} catch {
|
|
22094
|
-
return;
|
|
22095
|
-
}
|
|
22096
|
-
};
|
|
22097
|
-
if (expiration && expiration <= outerThreshold && refreshToken) {
|
|
22098
|
-
let release;
|
|
22099
|
-
try {
|
|
22100
|
-
release = await getFs().acquireLock(absolutePath);
|
|
22101
|
-
} catch (error) {
|
|
22102
|
-
const msg = errorMessage(error);
|
|
22103
|
-
const globalHint = await tryGlobalCredsHint();
|
|
22104
|
-
if (globalHint) {
|
|
22105
|
-
return {
|
|
22106
|
-
loginStatus: "Expired",
|
|
22107
|
-
accessToken,
|
|
22108
|
-
refreshToken,
|
|
22109
|
-
baseUrl: credentials.UIPATH_URL,
|
|
22110
|
-
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22111
|
-
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22112
|
-
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22113
|
-
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22114
|
-
expiration,
|
|
22115
|
-
source: "file" /* File */,
|
|
22116
|
-
hint: globalHint,
|
|
22117
|
-
tokenRefresh: {
|
|
22118
|
-
attempted: false,
|
|
22119
|
-
success: false,
|
|
22120
|
-
errorMessage: `lock acquisition failed: ${msg}`
|
|
22121
|
-
}
|
|
22122
|
-
};
|
|
22123
|
-
}
|
|
22124
|
-
return {
|
|
22125
|
-
loginStatus: "Refresh Failed",
|
|
22126
|
-
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.",
|
|
22127
|
-
tokenRefresh: {
|
|
22128
|
-
attempted: false,
|
|
22129
|
-
success: false,
|
|
22130
|
-
errorMessage: `lock acquisition failed: ${msg}`
|
|
22131
|
-
}
|
|
22132
|
-
};
|
|
22133
|
-
}
|
|
22134
|
-
let lockedFailure;
|
|
22135
|
-
try {
|
|
22136
|
-
const outcome = await runRefreshLocked({
|
|
22137
|
-
absolutePath,
|
|
22138
|
-
refreshToken,
|
|
22139
|
-
customAuthority: credentials.UIPATH_URL,
|
|
22140
|
-
ensureTokenValidityMinutes,
|
|
22141
|
-
loadEnvFile,
|
|
22142
|
-
saveEnvFile,
|
|
22143
|
-
refreshFn: refreshTokenFn,
|
|
22144
|
-
resolveConfig
|
|
22145
|
-
});
|
|
22146
|
-
if (outcome.kind === "fail") {
|
|
22147
|
-
lockedFailure = outcome.status;
|
|
22148
|
-
} else {
|
|
22149
|
-
accessToken = outcome.accessToken;
|
|
22150
|
-
refreshToken = outcome.refreshToken;
|
|
22151
|
-
expiration = outcome.expiration;
|
|
22152
|
-
tokenRefresh = outcome.tokenRefresh;
|
|
22153
|
-
if (outcome.persistenceWarning) {
|
|
22154
|
-
persistenceWarning = outcome.persistenceWarning;
|
|
22155
|
-
}
|
|
22156
|
-
}
|
|
22157
|
-
} finally {
|
|
22158
|
-
try {
|
|
22159
|
-
await release();
|
|
22160
|
-
} catch {
|
|
22161
|
-
lockReleaseFailed = true;
|
|
22162
|
-
}
|
|
22163
|
-
}
|
|
22164
|
-
if (lockedFailure) {
|
|
22165
|
-
const globalHint = await tryGlobalCredsHint();
|
|
22166
|
-
const base = globalHint ? {
|
|
22167
|
-
...lockedFailure,
|
|
22168
|
-
loginStatus: "Expired",
|
|
22169
|
-
hint: globalHint
|
|
22170
|
-
} : lockedFailure;
|
|
22171
|
-
return lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base;
|
|
22172
|
-
}
|
|
22173
|
-
}
|
|
22174
|
-
const result = {
|
|
22175
|
-
loginStatus: expiration && expiration <= new Date ? "Expired" : "Logged in",
|
|
22176
|
-
accessToken,
|
|
22177
|
-
refreshToken,
|
|
22178
|
-
baseUrl: credentials.UIPATH_URL,
|
|
22179
|
-
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22180
|
-
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22181
|
-
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22182
|
-
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22183
|
-
expiration,
|
|
22184
|
-
source: "file" /* File */,
|
|
22185
|
-
...persistenceWarning ? { hint: persistenceWarning, persistenceFailed: true } : {},
|
|
22186
|
-
...lockReleaseFailed ? { lockReleaseFailed: true } : {},
|
|
22187
|
-
...tokenRefresh ? { tokenRefresh } : {}
|
|
22188
|
-
};
|
|
22189
|
-
if (result.loginStatus === "Expired") {
|
|
22190
|
-
const globalHint = await tryGlobalCredsHint();
|
|
22191
|
-
if (globalHint) {
|
|
22192
|
-
result.hint = globalHint;
|
|
22193
|
-
}
|
|
22194
|
-
}
|
|
22195
|
-
return result;
|
|
22196
|
-
};
|
|
22197
|
-
var isFileNotFoundError = (error) => {
|
|
22198
|
-
if (!(error instanceof Object))
|
|
22199
|
-
return false;
|
|
22200
|
-
return error.code === "ENOENT";
|
|
22201
|
-
};
|
|
22202
|
-
var getLoginStatusAsync = async (options = {}) => {
|
|
22203
|
-
return getLoginStatusWithDeps(options);
|
|
22204
|
-
};
|
|
22205
|
-
|
|
22206
|
-
// ../../auth/src/authContext.ts
|
|
22207
|
-
var getAuthContext = async (options = {}) => {
|
|
22208
|
-
const status = await getLoginStatusAsync({
|
|
22209
|
-
ensureTokenValidityMinutes: options.ensureTokenValidityMinutes,
|
|
22210
|
-
envFilePath: options.envFilePath
|
|
22211
|
-
});
|
|
22212
|
-
if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
|
|
22213
|
-
throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
|
|
22214
|
-
}
|
|
22215
|
-
const tenantName = options.tenant ?? status.tenantName;
|
|
22216
|
-
if (options.requireOrganizationId && !status.organizationId) {
|
|
22217
|
-
throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
|
|
22218
|
-
}
|
|
22219
|
-
if (options.requireOrganizationName && !status.organizationName) {
|
|
22220
|
-
throw new Error("Organization name not available. Ensure you are logged in with an organization context.");
|
|
22221
|
-
}
|
|
22222
|
-
if (options.requireTenantId && !status.tenantId) {
|
|
22223
|
-
throw new Error("Tenant ID not available. Ensure UIPATH_TENANT_ID is set.");
|
|
22224
|
-
}
|
|
22225
|
-
if (options.requireTenantName && tenantName === undefined) {
|
|
22226
|
-
throw new Error("Tenant not provided and UIPATH_TENANT_NAME not set. Run 'uip login' to select a tenant, or use 'uip login tenant set <tenant>' to switch tenants.");
|
|
22481
|
+
if (options.requireTenantName && tenantName === undefined) {
|
|
22482
|
+
throw new Error("Tenant not provided and UIPATH_TENANT_NAME not set. Run 'uip login' to select a tenant, or use 'uip login tenant set <tenant>' to switch tenants.");
|
|
22227
22483
|
}
|
|
22228
22484
|
return {
|
|
22229
22485
|
baseUrl: status.baseUrl,
|
|
@@ -22236,6 +22492,14 @@ var getAuthContext = async (options = {}) => {
|
|
|
22236
22492
|
};
|
|
22237
22493
|
// ../../auth/src/interactive.ts
|
|
22238
22494
|
init_src();
|
|
22495
|
+
|
|
22496
|
+
// ../../auth/src/selectTenant.ts
|
|
22497
|
+
var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
|
|
22498
|
+
var INVALID_TENANT_CODE = "INVALID_TENANT";
|
|
22499
|
+
var TENANT_SELECTION_CODES = new Set([
|
|
22500
|
+
TENANT_SELECTION_REQUIRED_CODE,
|
|
22501
|
+
INVALID_TENANT_CODE
|
|
22502
|
+
]);
|
|
22239
22503
|
// ../../auth/src/logout.ts
|
|
22240
22504
|
init_src();
|
|
22241
22505
|
|
|
@@ -22272,6 +22536,12 @@ function singleton(ctorOrName) {
|
|
|
22272
22536
|
};
|
|
22273
22537
|
}
|
|
22274
22538
|
|
|
22539
|
+
// ../../common/src/telemetry/global-telemetry-properties.ts
|
|
22540
|
+
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
22541
|
+
function getGlobalTelemetryProperties() {
|
|
22542
|
+
return telemetryPropsSlot.get();
|
|
22543
|
+
}
|
|
22544
|
+
|
|
22275
22545
|
// ../../common/src/sdk-user-agent.ts
|
|
22276
22546
|
var USER_AGENT_HEADER = "User-Agent";
|
|
22277
22547
|
var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
|
|
@@ -22295,8 +22565,8 @@ function appendUserAgentToken(value, userAgent) {
|
|
|
22295
22565
|
function getEffectiveUserAgent(userAgent) {
|
|
22296
22566
|
return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
|
|
22297
22567
|
}
|
|
22298
|
-
function
|
|
22299
|
-
return
|
|
22568
|
+
function getHeaderName(headers, headerName) {
|
|
22569
|
+
return Object.keys(headers).find((key) => key.toLowerCase() === headerName.toLowerCase());
|
|
22300
22570
|
}
|
|
22301
22571
|
function getSdkUserAgentToken(pkg) {
|
|
22302
22572
|
const packageName = pkg.name.replace(/^@uipath\//, "");
|
|
@@ -22304,59 +22574,31 @@ function getSdkUserAgentToken(pkg) {
|
|
|
22304
22574
|
}
|
|
22305
22575
|
function addSdkUserAgentHeader(headers, userAgent) {
|
|
22306
22576
|
const result = { ...headers ?? {} };
|
|
22307
|
-
const
|
|
22308
|
-
|
|
22309
|
-
if (headerName) {
|
|
22310
|
-
result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
|
|
22311
|
-
} else {
|
|
22312
|
-
result[USER_AGENT_HEADER] = effectiveUserAgent;
|
|
22313
|
-
}
|
|
22577
|
+
const headerName = getHeaderName(result, USER_AGENT_HEADER);
|
|
22578
|
+
result[headerName ?? USER_AGENT_HEADER] = appendUserAgentToken(headerName ? result[headerName] : undefined, getEffectiveUserAgent(userAgent));
|
|
22314
22579
|
return result;
|
|
22315
22580
|
}
|
|
22316
|
-
function
|
|
22317
|
-
|
|
22318
|
-
if (isHeadersLike(headers)) {
|
|
22319
|
-
headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
|
|
22320
|
-
return headers;
|
|
22321
|
-
}
|
|
22322
|
-
if (Array.isArray(headers)) {
|
|
22323
|
-
const result = headers.map((entry) => {
|
|
22324
|
-
const [key, value] = entry;
|
|
22325
|
-
return [key, value];
|
|
22326
|
-
});
|
|
22327
|
-
const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
|
|
22328
|
-
if (headerIndex >= 0) {
|
|
22329
|
-
const [key, value] = result[headerIndex];
|
|
22330
|
-
result[headerIndex] = [
|
|
22331
|
-
key,
|
|
22332
|
-
appendUserAgentToken(value, effectiveUserAgent)
|
|
22333
|
-
];
|
|
22334
|
-
} else {
|
|
22335
|
-
result.push([USER_AGENT_HEADER, effectiveUserAgent]);
|
|
22336
|
-
}
|
|
22337
|
-
return result;
|
|
22338
|
-
}
|
|
22339
|
-
return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
|
|
22581
|
+
function asHeaderRecord(headers) {
|
|
22582
|
+
return typeof headers === "object" && headers !== null ? { ...headers } : {};
|
|
22340
22583
|
}
|
|
22341
|
-
function
|
|
22584
|
+
function withForwardedHeadersInitOverride(initOverrides, forward) {
|
|
22342
22585
|
return async (requestContext) => {
|
|
22343
|
-
const
|
|
22586
|
+
const initWithHeaders = {
|
|
22344
22587
|
...requestContext.init,
|
|
22345
|
-
headers:
|
|
22588
|
+
headers: forward(asHeaderRecord(requestContext.init.headers))
|
|
22346
22589
|
};
|
|
22347
22590
|
const override = typeof initOverrides === "function" ? await initOverrides({
|
|
22348
22591
|
...requestContext,
|
|
22349
|
-
init:
|
|
22592
|
+
init: initWithHeaders
|
|
22350
22593
|
}) : initOverrides;
|
|
22351
22594
|
return {
|
|
22352
22595
|
...override ?? {},
|
|
22353
|
-
headers:
|
|
22596
|
+
headers: forward(asHeaderRecord(override?.headers ?? initWithHeaders.headers))
|
|
22354
22597
|
};
|
|
22355
22598
|
};
|
|
22356
22599
|
}
|
|
22357
|
-
function
|
|
22600
|
+
function installRequestHeaderForwarding(BaseApiClass, patchKey, forward) {
|
|
22358
22601
|
const prototype = BaseApiClass.prototype;
|
|
22359
|
-
const patchKey = userAgentPatchKey(userAgent);
|
|
22360
22602
|
if (prototype[patchKey]) {
|
|
22361
22603
|
return;
|
|
22362
22604
|
}
|
|
@@ -22364,13 +22606,16 @@ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
|
22364
22606
|
throw new Error("Generated BaseAPI request function not found.");
|
|
22365
22607
|
}
|
|
22366
22608
|
const originalRequest = prototype.request;
|
|
22367
|
-
prototype.request = function
|
|
22368
|
-
return originalRequest.call(this, context,
|
|
22609
|
+
prototype.request = function requestWithForwardedHeaders(context, initOverrides) {
|
|
22610
|
+
return originalRequest.call(this, context, withForwardedHeadersInitOverride(initOverrides, forward));
|
|
22369
22611
|
};
|
|
22370
22612
|
Object.defineProperty(prototype, patchKey, {
|
|
22371
22613
|
value: true
|
|
22372
22614
|
});
|
|
22373
22615
|
}
|
|
22616
|
+
function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
22617
|
+
installRequestHeaderForwarding(BaseApiClass, userAgentPatchKey(userAgent), (headers) => addSdkUserAgentHeader(headers, userAgent));
|
|
22618
|
+
}
|
|
22374
22619
|
|
|
22375
22620
|
// ../authz-sdk/generated/src/runtime.ts
|
|
22376
22621
|
var BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
|
@@ -22625,7 +22870,7 @@ class VoidApiResponse {
|
|
|
22625
22870
|
var package_default2 = {
|
|
22626
22871
|
name: "@uipath/authz-sdk",
|
|
22627
22872
|
license: "MIT",
|
|
22628
|
-
version: "1.
|
|
22873
|
+
version: "1.197.0",
|
|
22629
22874
|
description: "SDK for the UiPath Authorization Service API.",
|
|
22630
22875
|
repository: {
|
|
22631
22876
|
type: "git",
|
|
@@ -22655,7 +22900,7 @@ var package_default2 = {
|
|
|
22655
22900
|
],
|
|
22656
22901
|
private: true,
|
|
22657
22902
|
scripts: {
|
|
22658
|
-
build: "bun build ./src/index.ts --outdir dist --format esm --target node && tsc -p tsconfig.build.json --noCheck",
|
|
22903
|
+
build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
|
|
22659
22904
|
generate: "bun run src/scripts/generate-sdk.ts",
|
|
22660
22905
|
lint: "biome check ."
|
|
22661
22906
|
},
|
|
@@ -23269,27 +23514,54 @@ var NETWORK_ERROR_CODES = new Set([
|
|
|
23269
23514
|
"ENETUNREACH",
|
|
23270
23515
|
"EAI_FAIL"
|
|
23271
23516
|
]);
|
|
23272
|
-
|
|
23273
|
-
|
|
23274
|
-
|
|
23275
|
-
|
|
23276
|
-
|
|
23277
|
-
|
|
23278
|
-
|
|
23279
|
-
|
|
23280
|
-
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
|
|
23288
|
-
|
|
23517
|
+
var TLS_ERROR_CODES = new Set([
|
|
23518
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
23519
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
23520
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
23521
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
23522
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
23523
|
+
"CERT_HAS_EXPIRED",
|
|
23524
|
+
"CERT_UNTRUSTED",
|
|
23525
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
23526
|
+
]);
|
|
23527
|
+
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.";
|
|
23528
|
+
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.";
|
|
23529
|
+
function describeConnectivityError(error) {
|
|
23530
|
+
let current = error;
|
|
23531
|
+
for (let depth = 0;depth < 5 && current !== null && typeof current === "object"; depth++) {
|
|
23532
|
+
const cur = current;
|
|
23533
|
+
const code = typeof cur.code === "string" ? cur.code : undefined;
|
|
23534
|
+
const message = typeof cur.message === "string" ? cur.message : undefined;
|
|
23535
|
+
if (code && TLS_ERROR_CODES.has(code)) {
|
|
23536
|
+
return {
|
|
23537
|
+
code,
|
|
23538
|
+
kind: "tls",
|
|
23539
|
+
message: message ?? code,
|
|
23540
|
+
instructions: TLS_INSTRUCTIONS
|
|
23541
|
+
};
|
|
23542
|
+
}
|
|
23543
|
+
if (code && NETWORK_ERROR_CODES.has(code)) {
|
|
23544
|
+
return {
|
|
23545
|
+
code,
|
|
23546
|
+
kind: "network",
|
|
23547
|
+
message: message ?? code,
|
|
23548
|
+
instructions: NETWORK_INSTRUCTIONS
|
|
23549
|
+
};
|
|
23289
23550
|
}
|
|
23551
|
+
current = cur.cause;
|
|
23290
23552
|
}
|
|
23291
23553
|
return;
|
|
23292
23554
|
}
|
|
23555
|
+
function parseHttpStatusFromMessage(message) {
|
|
23556
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
23557
|
+
if (!match)
|
|
23558
|
+
return;
|
|
23559
|
+
const status = Number(match[1]);
|
|
23560
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
23561
|
+
}
|
|
23562
|
+
function isHtmlDocument(body) {
|
|
23563
|
+
return /^\s*(<!doctype html|<html\b)/i.test(body);
|
|
23564
|
+
}
|
|
23293
23565
|
function retryHintForRetryAfter(seconds) {
|
|
23294
23566
|
if (seconds <= 1) {
|
|
23295
23567
|
return "RetryAfter1Second";
|
|
@@ -23330,15 +23602,28 @@ function classifyError(status, error) {
|
|
|
23330
23602
|
if (status !== undefined && status >= 500 && status < 600) {
|
|
23331
23603
|
return { errorCode: "server_error", retry: "RetryLater" };
|
|
23332
23604
|
}
|
|
23333
|
-
|
|
23334
|
-
|
|
23605
|
+
const connectivity = describeConnectivityError(error);
|
|
23606
|
+
if (connectivity) {
|
|
23607
|
+
return {
|
|
23608
|
+
errorCode: "network_error",
|
|
23609
|
+
retry: connectivity.kind === "tls" ? "RetryWillNotFix" : "RetryLater"
|
|
23610
|
+
};
|
|
23335
23611
|
}
|
|
23336
23612
|
return { errorCode: "unknown_error", retry: "RetryWillNotFix" };
|
|
23337
23613
|
}
|
|
23614
|
+
function formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus) {
|
|
23615
|
+
if (extractedMessage) {
|
|
23616
|
+
return `HTTP ${status}: ${extractedMessage}`;
|
|
23617
|
+
}
|
|
23618
|
+
return inferredStatus !== undefined ? rawMessage : `HTTP ${status}: ${rawMessage}`;
|
|
23619
|
+
}
|
|
23338
23620
|
async function extractErrorDetails(error, options) {
|
|
23339
23621
|
const err = error !== null && error !== undefined && typeof error === "object" ? error : {};
|
|
23340
23622
|
const response = err.response;
|
|
23341
|
-
const
|
|
23623
|
+
const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
|
|
23624
|
+
const explicitStatus = err.status ?? response?.status;
|
|
23625
|
+
const inferredStatus = explicitStatus === undefined ? parseHttpStatusFromMessage(rawMessage) : undefined;
|
|
23626
|
+
const status = explicitStatus ?? inferredStatus;
|
|
23342
23627
|
const isSuccessfulResponse = status !== undefined && status >= 200 && status < 300;
|
|
23343
23628
|
let rawBody;
|
|
23344
23629
|
let extractedMessage;
|
|
@@ -23373,7 +23658,6 @@ async function extractErrorDetails(error, options) {
|
|
|
23373
23658
|
}
|
|
23374
23659
|
}
|
|
23375
23660
|
}
|
|
23376
|
-
const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
|
|
23377
23661
|
let message;
|
|
23378
23662
|
let result = "Failure";
|
|
23379
23663
|
const classification = classifyError(status, error);
|
|
@@ -23387,10 +23671,10 @@ async function extractErrorDetails(error, options) {
|
|
|
23387
23671
|
} else if (status === 405) {
|
|
23388
23672
|
message = DEFAULT_405;
|
|
23389
23673
|
} else if (status === 400 || status === 422) {
|
|
23390
|
-
message =
|
|
23674
|
+
message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
|
|
23391
23675
|
result = "ValidationError";
|
|
23392
23676
|
} else if (status === 429) {
|
|
23393
|
-
message =
|
|
23677
|
+
message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
|
|
23394
23678
|
} else if (extractedMessage) {
|
|
23395
23679
|
if (isSuccessfulResponse && rawMessage !== "Unknown error") {
|
|
23396
23680
|
message = rawMessage;
|
|
@@ -23398,7 +23682,9 @@ async function extractErrorDetails(error, options) {
|
|
|
23398
23682
|
message = status ? `HTTP ${status}: ${extractedMessage}` : extractedMessage;
|
|
23399
23683
|
}
|
|
23400
23684
|
} else if (status) {
|
|
23401
|
-
if (
|
|
23685
|
+
if (inferredStatus !== undefined) {
|
|
23686
|
+
message = rawMessage;
|
|
23687
|
+
} else if (rawMessage === "Unknown error" && response) {
|
|
23402
23688
|
const statusText = response.statusText;
|
|
23403
23689
|
message = statusText ? `HTTP ${status} ${statusText}` : `HTTP ${status} - request failed`;
|
|
23404
23690
|
} else {
|
|
@@ -23407,6 +23693,12 @@ async function extractErrorDetails(error, options) {
|
|
|
23407
23693
|
} else {
|
|
23408
23694
|
message = rawMessage;
|
|
23409
23695
|
}
|
|
23696
|
+
if (status === undefined) {
|
|
23697
|
+
const connectivity = describeConnectivityError(error);
|
|
23698
|
+
if (connectivity && connectivity.message !== message && !message.includes(connectivity.message)) {
|
|
23699
|
+
message = `${message}: ${connectivity.message}`;
|
|
23700
|
+
}
|
|
23701
|
+
}
|
|
23410
23702
|
let details = rawMessage;
|
|
23411
23703
|
if (rawBody) {
|
|
23412
23704
|
if (parsedBody) {
|
|
@@ -23528,6 +23820,7 @@ var CONSOLE_FALLBACK = {
|
|
|
23528
23820
|
writeLog: (str) => process.stdout.write(str),
|
|
23529
23821
|
capabilities: {
|
|
23530
23822
|
isInteractive: false,
|
|
23823
|
+
canReadInput: false,
|
|
23531
23824
|
supportsColor: false,
|
|
23532
23825
|
outputWidth: 80
|
|
23533
23826
|
}
|
|
@@ -28533,12 +28826,6 @@ class NodeContextStorage {
|
|
|
28533
28826
|
return this.storage.getStore();
|
|
28534
28827
|
}
|
|
28535
28828
|
}
|
|
28536
|
-
// ../../common/src/telemetry/global-telemetry-properties.ts
|
|
28537
|
-
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
28538
|
-
function getGlobalTelemetryProperties() {
|
|
28539
|
-
return telemetryPropsSlot.get();
|
|
28540
|
-
}
|
|
28541
|
-
|
|
28542
28829
|
// ../../common/src/telemetry/telemetry-service.ts
|
|
28543
28830
|
class TelemetryService {
|
|
28544
28831
|
telemetryProvider;
|
|
@@ -28728,6 +29015,29 @@ function isPlainRecord(value) {
|
|
|
28728
29015
|
const prototype = Object.getPrototypeOf(value);
|
|
28729
29016
|
return prototype === Object.prototype || prototype === null;
|
|
28730
29017
|
}
|
|
29018
|
+
function extractPagedRows(value) {
|
|
29019
|
+
if (Array.isArray(value) || !isPlainRecord(value))
|
|
29020
|
+
return null;
|
|
29021
|
+
const entries = Object.values(value);
|
|
29022
|
+
if (entries.length === 0)
|
|
29023
|
+
return null;
|
|
29024
|
+
let rows = null;
|
|
29025
|
+
let hasScalarSibling = false;
|
|
29026
|
+
for (const entry of entries) {
|
|
29027
|
+
if (Array.isArray(entry)) {
|
|
29028
|
+
if (rows !== null)
|
|
29029
|
+
return null;
|
|
29030
|
+
rows = entry;
|
|
29031
|
+
} else if (entry !== null && typeof entry === "object") {
|
|
29032
|
+
return null;
|
|
29033
|
+
} else {
|
|
29034
|
+
hasScalarSibling = true;
|
|
29035
|
+
}
|
|
29036
|
+
}
|
|
29037
|
+
if (rows === null || !hasScalarSibling)
|
|
29038
|
+
return null;
|
|
29039
|
+
return rows;
|
|
29040
|
+
}
|
|
28731
29041
|
function toLowerCamelCaseKey(key) {
|
|
28732
29042
|
if (!key)
|
|
28733
29043
|
return key;
|
|
@@ -28792,7 +29102,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
28792
29102
|
break;
|
|
28793
29103
|
case "plain": {
|
|
28794
29104
|
if ("Data" in data && data.Data != null) {
|
|
28795
|
-
const
|
|
29105
|
+
const pagedRows = extractPagedRows(data.Data);
|
|
29106
|
+
const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
|
|
28796
29107
|
items.forEach((item) => {
|
|
28797
29108
|
const values = Object.values(item).map((v) => v ?? "").join("\t");
|
|
28798
29109
|
logFn(values);
|
|
@@ -28804,10 +29115,13 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
28804
29115
|
break;
|
|
28805
29116
|
}
|
|
28806
29117
|
default: {
|
|
28807
|
-
|
|
29118
|
+
const hasData = "Data" in data && data.Data != null;
|
|
29119
|
+
const pagedRows = hasData ? extractPagedRows(data.Data) : null;
|
|
29120
|
+
const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
|
|
29121
|
+
if (hasData && !(rows !== null && rows.length === 0)) {
|
|
28808
29122
|
const logValue = data.Log;
|
|
28809
|
-
if (
|
|
28810
|
-
printResizableTable(
|
|
29123
|
+
if (rows !== null) {
|
|
29124
|
+
printResizableTable(rows, logFn, logValue);
|
|
28811
29125
|
} else {
|
|
28812
29126
|
printVerticalTable(data.Data, logFn, logValue);
|
|
28813
29127
|
}
|
|
@@ -28995,6 +29309,44 @@ function defaultErrorCodeForResult(result) {
|
|
|
28995
29309
|
return "unknown_error";
|
|
28996
29310
|
}
|
|
28997
29311
|
}
|
|
29312
|
+
function parseHttpStatusFromMessage2(message) {
|
|
29313
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
29314
|
+
if (!match)
|
|
29315
|
+
return;
|
|
29316
|
+
const status = Number(match[1]);
|
|
29317
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
29318
|
+
}
|
|
29319
|
+
function defaultErrorCodeForHttpStatus(status) {
|
|
29320
|
+
if (status === undefined)
|
|
29321
|
+
return;
|
|
29322
|
+
if (status === 400 || status === 409 || status === 422) {
|
|
29323
|
+
return "invalid_argument";
|
|
29324
|
+
}
|
|
29325
|
+
if (status === 401)
|
|
29326
|
+
return "authentication_required";
|
|
29327
|
+
if (status === 403)
|
|
29328
|
+
return "permission_denied";
|
|
29329
|
+
if (status === 404)
|
|
29330
|
+
return "not_found";
|
|
29331
|
+
if (status === 405)
|
|
29332
|
+
return "method_not_allowed";
|
|
29333
|
+
if (status === 408)
|
|
29334
|
+
return "timeout";
|
|
29335
|
+
if (status === 429)
|
|
29336
|
+
return "rate_limited";
|
|
29337
|
+
if (status >= 500 && status < 600)
|
|
29338
|
+
return "server_error";
|
|
29339
|
+
return;
|
|
29340
|
+
}
|
|
29341
|
+
function defaultErrorCodeForFailure(data) {
|
|
29342
|
+
if (data.Result === RESULTS.Failure) {
|
|
29343
|
+
const status = data.Context?.httpStatus ?? parseHttpStatusFromMessage2(data.Message);
|
|
29344
|
+
const errorCode2 = defaultErrorCodeForHttpStatus(status);
|
|
29345
|
+
if (errorCode2)
|
|
29346
|
+
return errorCode2;
|
|
29347
|
+
}
|
|
29348
|
+
return defaultErrorCodeForResult(data.Result);
|
|
29349
|
+
}
|
|
28998
29350
|
function defaultRetryForErrorCode(errorCode2) {
|
|
28999
29351
|
switch (errorCode2) {
|
|
29000
29352
|
case "network_error":
|
|
@@ -29024,16 +29376,19 @@ var OutputFormatter;
|
|
|
29024
29376
|
OutputFormatter.success = success;
|
|
29025
29377
|
function error(data) {
|
|
29026
29378
|
data.Log ??= getLogFilePath() || undefined;
|
|
29027
|
-
data.ErrorCode ??=
|
|
29379
|
+
data.ErrorCode ??= defaultErrorCodeForFailure(data);
|
|
29028
29380
|
data.Retry ??= defaultRetryForErrorCode(data.ErrorCode);
|
|
29029
29381
|
process.exitCode = EXIT_CODES[data.Result] ?? 1;
|
|
29030
|
-
|
|
29031
|
-
|
|
29032
|
-
|
|
29033
|
-
|
|
29034
|
-
|
|
29035
|
-
|
|
29036
|
-
|
|
29382
|
+
const { SuppressTelemetry, ...envelope } = data;
|
|
29383
|
+
if (!SuppressTelemetry) {
|
|
29384
|
+
telemetry.trackEvent(CommonTelemetryEvents.Error, {
|
|
29385
|
+
result: data.Result,
|
|
29386
|
+
errorCode: data.ErrorCode,
|
|
29387
|
+
retry: data.Retry,
|
|
29388
|
+
message: data.Message
|
|
29389
|
+
});
|
|
29390
|
+
}
|
|
29391
|
+
logOutput(normalizeOutputKeys(envelope), getOutputFormat());
|
|
29037
29392
|
}
|
|
29038
29393
|
OutputFormatter.error = error;
|
|
29039
29394
|
function emitList(code, items, opts) {
|
|
@@ -29109,1623 +29464,220 @@ var SENSITIVE_NAME_TOKENS = new Set([
|
|
|
29109
29464
|
"certificate",
|
|
29110
29465
|
"certificates"
|
|
29111
29466
|
]);
|
|
29112
|
-
var SENSITIVE_KEY_PREFIXES = new Set([
|
|
29113
|
-
"api",
|
|
29114
|
-
"access",
|
|
29115
|
-
"client",
|
|
29116
|
-
"private",
|
|
29117
|
-
"public",
|
|
29118
|
-
"signing",
|
|
29119
|
-
"encryption",
|
|
29120
|
-
"session",
|
|
29121
|
-
"master",
|
|
29122
|
-
"shared",
|
|
29123
|
-
"root",
|
|
29124
|
-
"ssh",
|
|
29125
|
-
"rsa",
|
|
29126
|
-
"aes",
|
|
29127
|
-
"hmac",
|
|
29128
|
-
"oauth"
|
|
29129
|
-
]);
|
|
29130
|
-
var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
|
|
29131
|
-
var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
|
|
29132
|
-
var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
|
|
29133
|
-
var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
|
|
29134
|
-
var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
|
|
29135
|
-
var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
|
|
29136
|
-
var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
|
|
29137
|
-
function shortHash(input) {
|
|
29138
|
-
let hash = 2166136261;
|
|
29139
|
-
for (let i = 0;i < input.length; i++) {
|
|
29140
|
-
hash ^= input.charCodeAt(i);
|
|
29141
|
-
hash = Math.imul(hash, 16777619);
|
|
29142
|
-
}
|
|
29143
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
29144
|
-
}
|
|
29145
|
-
function redactUrl(raw) {
|
|
29146
|
-
try {
|
|
29147
|
-
const url = new URL(raw);
|
|
29148
|
-
return `${url.protocol}//${url.host}`;
|
|
29149
|
-
} catch {
|
|
29150
|
-
return `url#${shortHash(raw)}`;
|
|
29151
|
-
}
|
|
29152
|
-
}
|
|
29153
|
-
function redactValueDetectors(value) {
|
|
29154
|
-
let out = value;
|
|
29155
|
-
out = out.replace(JWT_PATTERN, () => REDACTED);
|
|
29156
|
-
out = out.replace(URL_PATTERN, (match) => {
|
|
29157
|
-
const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
|
|
29158
|
-
const core = trailing ? match.slice(0, -trailing.length) : match;
|
|
29159
|
-
return `${redactUrl(core)}${trailing}`;
|
|
29160
|
-
});
|
|
29161
|
-
out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
|
|
29162
|
-
out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
|
|
29163
|
-
out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
|
|
29164
|
-
out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
|
|
29165
|
-
if (out.length > MAX_VALUE_LENGTH) {
|
|
29166
|
-
out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
|
|
29167
|
-
}
|
|
29168
|
-
return out;
|
|
29169
|
-
}
|
|
29170
|
-
function nameTokens(name) {
|
|
29171
|
-
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((t) => t.toLowerCase()).filter(Boolean);
|
|
29172
|
-
}
|
|
29173
|
-
function isSensitiveName(name) {
|
|
29174
|
-
const tokens = nameTokens(name);
|
|
29175
|
-
for (let i = 0;i < tokens.length; i++) {
|
|
29176
|
-
const token = tokens[i];
|
|
29177
|
-
if (SENSITIVE_NAME_TOKENS.has(token)) {
|
|
29178
|
-
return true;
|
|
29179
|
-
}
|
|
29180
|
-
if (token === "key" || token === "keys") {
|
|
29181
|
-
const prev = tokens[i - 1];
|
|
29182
|
-
if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
|
|
29183
|
-
return true;
|
|
29184
|
-
}
|
|
29185
|
-
}
|
|
29186
|
-
}
|
|
29187
|
-
return false;
|
|
29188
|
-
}
|
|
29189
|
-
function redactProperty(name, value) {
|
|
29190
|
-
if (value === undefined || value === null) {
|
|
29191
|
-
return;
|
|
29192
|
-
}
|
|
29193
|
-
if (isSensitiveName(name)) {
|
|
29194
|
-
return REDACTED;
|
|
29195
|
-
}
|
|
29196
|
-
if (typeof value === "boolean" || typeof value === "number") {
|
|
29197
|
-
return value;
|
|
29198
|
-
}
|
|
29199
|
-
if (typeof value !== "string") {
|
|
29200
|
-
return "[OBJECT]";
|
|
29201
|
-
}
|
|
29202
|
-
return redactValueDetectors(value);
|
|
29203
|
-
}
|
|
29204
|
-
function redactProperties(properties) {
|
|
29205
|
-
const out = {};
|
|
29206
|
-
for (const [name, value] of Object.entries(properties)) {
|
|
29207
|
-
const redacted = redactProperty(name, value);
|
|
29208
|
-
if (redacted !== undefined) {
|
|
29209
|
-
out[name] = redacted;
|
|
29210
|
-
}
|
|
29211
|
-
}
|
|
29212
|
-
return out;
|
|
29213
|
-
}
|
|
29214
|
-
|
|
29215
|
-
// ../../common/src/trackedAction.ts
|
|
29216
|
-
var pollSignalSlot = singleton("PollSignal");
|
|
29217
|
-
var cliErrorCodeValues = new Set(CLI_ERROR_CODES);
|
|
29218
|
-
var retryHintValues = new Set(RETRY_HINTS);
|
|
29219
|
-
var processContext = {
|
|
29220
|
-
exit: (code) => {
|
|
29221
|
-
process.exitCode = code;
|
|
29222
|
-
},
|
|
29223
|
-
get pollSignal() {
|
|
29224
|
-
return pollSignalSlot.get();
|
|
29225
|
-
}
|
|
29226
|
-
};
|
|
29227
|
-
function extractCommandParams(cmd) {
|
|
29228
|
-
const params = {};
|
|
29229
|
-
const registered = cmd.registeredArguments ?? [];
|
|
29230
|
-
const processed = cmd.processedArgs ?? [];
|
|
29231
|
-
for (let i = 0;i < registered.length; i++) {
|
|
29232
|
-
const value = processed[i];
|
|
29233
|
-
if (value === undefined) {
|
|
29234
|
-
continue;
|
|
29235
|
-
}
|
|
29236
|
-
const name = registered[i].name();
|
|
29237
|
-
if (name) {
|
|
29238
|
-
params[name] = value;
|
|
29239
|
-
}
|
|
29240
|
-
}
|
|
29241
|
-
for (const [key, value] of Object.entries(cmd.opts())) {
|
|
29242
|
-
if (value !== undefined) {
|
|
29243
|
-
params[key] = value;
|
|
29244
|
-
}
|
|
29245
|
-
}
|
|
29246
|
-
return params;
|
|
29247
|
-
}
|
|
29248
|
-
function deriveCommandPath(cmd) {
|
|
29249
|
-
const parts = [];
|
|
29250
|
-
let current = cmd;
|
|
29251
|
-
while (current) {
|
|
29252
|
-
const name = current.name();
|
|
29253
|
-
if (name) {
|
|
29254
|
-
parts.unshift(name);
|
|
29255
|
-
}
|
|
29256
|
-
current = current.parent;
|
|
29257
|
-
}
|
|
29258
|
-
if (parts.length > 1) {
|
|
29259
|
-
parts.shift();
|
|
29260
|
-
}
|
|
29261
|
-
return ["uip", ...parts.filter((p) => p !== "uip")].join(".");
|
|
29262
|
-
}
|
|
29263
|
-
function isCliErrorCode(value) {
|
|
29264
|
-
return typeof value === "string" && cliErrorCodeValues.has(value);
|
|
29265
|
-
}
|
|
29266
|
-
function isRetryHint(value) {
|
|
29267
|
-
return typeof value === "string" && retryHintValues.has(value);
|
|
29268
|
-
}
|
|
29269
|
-
function isErrorContext(value) {
|
|
29270
|
-
return value !== null && typeof value === "object";
|
|
29271
|
-
}
|
|
29272
|
-
function commandHelpHint(commandPath) {
|
|
29273
|
-
const command = commandPath.replace(/\./g, " ");
|
|
29274
|
-
return `An unexpected error occurred. Run '${command} --help' to verify command syntax, or run with --log-level debug for details.`;
|
|
29275
|
-
}
|
|
29276
|
-
Command.prototype.trackedAction = function(context, fn, properties) {
|
|
29277
|
-
const command = this;
|
|
29278
|
-
return this.action(async (...args) => {
|
|
29279
|
-
const telemetryName = deriveCommandPath(command);
|
|
29280
|
-
const props = typeof properties === "function" ? properties(...args) : properties;
|
|
29281
|
-
const startTime = performance.now();
|
|
29282
|
-
let errorMessage2;
|
|
29283
|
-
const [error] = await catchError2(fn(...args));
|
|
29284
|
-
if (error) {
|
|
29285
|
-
errorMessage2 = error instanceof Error ? error.message : String(error);
|
|
29286
|
-
logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage2}`);
|
|
29287
|
-
const typed = error;
|
|
29288
|
-
const customInstructions = typeof typed.instructions === "string" ? typed.instructions : undefined;
|
|
29289
|
-
const customResult = typeof typed.result === "string" && typed.result !== RESULTS.Success && Object.values(RESULTS).includes(typed.result) ? typed.result : undefined;
|
|
29290
|
-
const finalResult = customResult ?? RESULTS.Failure;
|
|
29291
|
-
const typedErrorCode = typed.errorCode ?? typed.ErrorCode;
|
|
29292
|
-
const customErrorCode = isCliErrorCode(typedErrorCode) ? typedErrorCode : undefined;
|
|
29293
|
-
const typedRetry = typed.retry ?? typed.Retry;
|
|
29294
|
-
const customRetry = isRetryHint(typedRetry) ? typedRetry : undefined;
|
|
29295
|
-
const typedContext = typed.context ?? typed.Context;
|
|
29296
|
-
const customContext = isErrorContext(typedContext) ? typedContext : undefined;
|
|
29297
|
-
OutputFormatter.error({
|
|
29298
|
-
Result: finalResult,
|
|
29299
|
-
...customErrorCode ? { ErrorCode: customErrorCode } : {},
|
|
29300
|
-
Message: errorMessage2,
|
|
29301
|
-
Instructions: customInstructions ?? commandHelpHint(telemetryName),
|
|
29302
|
-
...customRetry ? { Retry: customRetry } : {},
|
|
29303
|
-
...customContext ? { Context: customContext } : {}
|
|
29304
|
-
});
|
|
29305
|
-
context.exit(EXIT_CODES[finalResult]);
|
|
29306
|
-
}
|
|
29307
|
-
const durationMs = performance.now() - startTime;
|
|
29308
|
-
const success = !error && (process.exitCode === undefined || process.exitCode === 0);
|
|
29309
|
-
telemetry.trackEvent(telemetryName, redactProperties({
|
|
29310
|
-
...extractCommandParams(command),
|
|
29311
|
-
...props,
|
|
29312
|
-
command: "true",
|
|
29313
|
-
duration: String(durationMs),
|
|
29314
|
-
success: String(success),
|
|
29315
|
-
...errorMessage2 ? { errorMessage: errorMessage2 } : {}
|
|
29316
|
-
}));
|
|
29317
|
-
});
|
|
29318
|
-
};
|
|
29319
|
-
// ../../common/src/console-guard.ts
|
|
29320
|
-
var guardInstalledSlot = singleton("ConsoleGuardInstalled");
|
|
29321
|
-
var savedOriginalsSlot = singleton("ConsoleGuardOriginals");
|
|
29322
|
-
// ../../common/src/constants.ts
|
|
29323
|
-
var DEFAULT_AUTH_TIMEOUT_MS2 = 5 * 60 * 1000;
|
|
29324
|
-
// ../../common/src/interactivity-context.ts
|
|
29325
|
-
var modeSlot = singleton("InteractivityMode");
|
|
29326
|
-
// ../../../node_modules/jsonpath-plus/dist/index-node-esm.js
|
|
29327
|
-
import vm from "vm";
|
|
29328
|
-
|
|
29329
|
-
class Hooks {
|
|
29330
|
-
add(name, callback, first) {
|
|
29331
|
-
if (typeof arguments[0] != "string") {
|
|
29332
|
-
for (let name2 in arguments[0]) {
|
|
29333
|
-
this.add(name2, arguments[0][name2], arguments[1]);
|
|
29334
|
-
}
|
|
29335
|
-
} else {
|
|
29336
|
-
(Array.isArray(name) ? name : [name]).forEach(function(name2) {
|
|
29337
|
-
this[name2] = this[name2] || [];
|
|
29338
|
-
if (callback) {
|
|
29339
|
-
this[name2][first ? "unshift" : "push"](callback);
|
|
29340
|
-
}
|
|
29341
|
-
}, this);
|
|
29342
|
-
}
|
|
29343
|
-
}
|
|
29344
|
-
run(name, env) {
|
|
29345
|
-
this[name] = this[name] || [];
|
|
29346
|
-
this[name].forEach(function(callback) {
|
|
29347
|
-
callback.call(env && env.context ? env.context : env, env);
|
|
29348
|
-
});
|
|
29349
|
-
}
|
|
29350
|
-
}
|
|
29351
|
-
|
|
29352
|
-
class Plugins {
|
|
29353
|
-
constructor(jsep) {
|
|
29354
|
-
this.jsep = jsep;
|
|
29355
|
-
this.registered = {};
|
|
29356
|
-
}
|
|
29357
|
-
register(...plugins) {
|
|
29358
|
-
plugins.forEach((plugin) => {
|
|
29359
|
-
if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
|
|
29360
|
-
throw new Error("Invalid JSEP plugin format");
|
|
29361
|
-
}
|
|
29362
|
-
if (this.registered[plugin.name]) {
|
|
29363
|
-
return;
|
|
29364
|
-
}
|
|
29365
|
-
plugin.init(this.jsep);
|
|
29366
|
-
this.registered[plugin.name] = plugin;
|
|
29367
|
-
});
|
|
29368
|
-
}
|
|
29369
|
-
}
|
|
29370
|
-
|
|
29371
|
-
class Jsep {
|
|
29372
|
-
static get version() {
|
|
29373
|
-
return "1.4.0";
|
|
29374
|
-
}
|
|
29375
|
-
static toString() {
|
|
29376
|
-
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
29377
|
-
}
|
|
29378
|
-
static addUnaryOp(op_name) {
|
|
29379
|
-
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
29380
|
-
Jsep.unary_ops[op_name] = 1;
|
|
29381
|
-
return Jsep;
|
|
29382
|
-
}
|
|
29383
|
-
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
29384
|
-
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
29385
|
-
Jsep.binary_ops[op_name] = precedence;
|
|
29386
|
-
if (isRightAssociative) {
|
|
29387
|
-
Jsep.right_associative.add(op_name);
|
|
29388
|
-
} else {
|
|
29389
|
-
Jsep.right_associative.delete(op_name);
|
|
29390
|
-
}
|
|
29391
|
-
return Jsep;
|
|
29392
|
-
}
|
|
29393
|
-
static addIdentifierChar(char) {
|
|
29394
|
-
Jsep.additional_identifier_chars.add(char);
|
|
29395
|
-
return Jsep;
|
|
29396
|
-
}
|
|
29397
|
-
static addLiteral(literal_name, literal_value) {
|
|
29398
|
-
Jsep.literals[literal_name] = literal_value;
|
|
29399
|
-
return Jsep;
|
|
29400
|
-
}
|
|
29401
|
-
static removeUnaryOp(op_name) {
|
|
29402
|
-
delete Jsep.unary_ops[op_name];
|
|
29403
|
-
if (op_name.length === Jsep.max_unop_len) {
|
|
29404
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
29405
|
-
}
|
|
29406
|
-
return Jsep;
|
|
29407
|
-
}
|
|
29408
|
-
static removeAllUnaryOps() {
|
|
29409
|
-
Jsep.unary_ops = {};
|
|
29410
|
-
Jsep.max_unop_len = 0;
|
|
29411
|
-
return Jsep;
|
|
29412
|
-
}
|
|
29413
|
-
static removeIdentifierChar(char) {
|
|
29414
|
-
Jsep.additional_identifier_chars.delete(char);
|
|
29415
|
-
return Jsep;
|
|
29416
|
-
}
|
|
29417
|
-
static removeBinaryOp(op_name) {
|
|
29418
|
-
delete Jsep.binary_ops[op_name];
|
|
29419
|
-
if (op_name.length === Jsep.max_binop_len) {
|
|
29420
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
29421
|
-
}
|
|
29422
|
-
Jsep.right_associative.delete(op_name);
|
|
29423
|
-
return Jsep;
|
|
29424
|
-
}
|
|
29425
|
-
static removeAllBinaryOps() {
|
|
29426
|
-
Jsep.binary_ops = {};
|
|
29427
|
-
Jsep.max_binop_len = 0;
|
|
29428
|
-
return Jsep;
|
|
29429
|
-
}
|
|
29430
|
-
static removeLiteral(literal_name) {
|
|
29431
|
-
delete Jsep.literals[literal_name];
|
|
29432
|
-
return Jsep;
|
|
29433
|
-
}
|
|
29434
|
-
static removeAllLiterals() {
|
|
29435
|
-
Jsep.literals = {};
|
|
29436
|
-
return Jsep;
|
|
29437
|
-
}
|
|
29438
|
-
get char() {
|
|
29439
|
-
return this.expr.charAt(this.index);
|
|
29440
|
-
}
|
|
29441
|
-
get code() {
|
|
29442
|
-
return this.expr.charCodeAt(this.index);
|
|
29443
|
-
}
|
|
29444
|
-
constructor(expr) {
|
|
29445
|
-
this.expr = expr;
|
|
29446
|
-
this.index = 0;
|
|
29447
|
-
}
|
|
29448
|
-
static parse(expr) {
|
|
29449
|
-
return new Jsep(expr).parse();
|
|
29450
|
-
}
|
|
29451
|
-
static getMaxKeyLen(obj) {
|
|
29452
|
-
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
29453
|
-
}
|
|
29454
|
-
static isDecimalDigit(ch) {
|
|
29455
|
-
return ch >= 48 && ch <= 57;
|
|
29456
|
-
}
|
|
29457
|
-
static binaryPrecedence(op_val) {
|
|
29458
|
-
return Jsep.binary_ops[op_val] || 0;
|
|
29459
|
-
}
|
|
29460
|
-
static isIdentifierStart(ch) {
|
|
29461
|
-
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));
|
|
29462
|
-
}
|
|
29463
|
-
static isIdentifierPart(ch) {
|
|
29464
|
-
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
29465
|
-
}
|
|
29466
|
-
throwError(message) {
|
|
29467
|
-
const error = new Error(message + " at character " + this.index);
|
|
29468
|
-
error.index = this.index;
|
|
29469
|
-
error.description = message;
|
|
29470
|
-
throw error;
|
|
29471
|
-
}
|
|
29472
|
-
runHook(name, node) {
|
|
29473
|
-
if (Jsep.hooks[name]) {
|
|
29474
|
-
const env = {
|
|
29475
|
-
context: this,
|
|
29476
|
-
node
|
|
29477
|
-
};
|
|
29478
|
-
Jsep.hooks.run(name, env);
|
|
29479
|
-
return env.node;
|
|
29480
|
-
}
|
|
29481
|
-
return node;
|
|
29482
|
-
}
|
|
29483
|
-
searchHook(name) {
|
|
29484
|
-
if (Jsep.hooks[name]) {
|
|
29485
|
-
const env = {
|
|
29486
|
-
context: this
|
|
29487
|
-
};
|
|
29488
|
-
Jsep.hooks[name].find(function(callback) {
|
|
29489
|
-
callback.call(env.context, env);
|
|
29490
|
-
return env.node;
|
|
29491
|
-
});
|
|
29492
|
-
return env.node;
|
|
29493
|
-
}
|
|
29494
|
-
}
|
|
29495
|
-
gobbleSpaces() {
|
|
29496
|
-
let ch = this.code;
|
|
29497
|
-
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
29498
|
-
ch = this.expr.charCodeAt(++this.index);
|
|
29499
|
-
}
|
|
29500
|
-
this.runHook("gobble-spaces");
|
|
29501
|
-
}
|
|
29502
|
-
parse() {
|
|
29503
|
-
this.runHook("before-all");
|
|
29504
|
-
const nodes = this.gobbleExpressions();
|
|
29505
|
-
const node = nodes.length === 1 ? nodes[0] : {
|
|
29506
|
-
type: Jsep.COMPOUND,
|
|
29507
|
-
body: nodes
|
|
29508
|
-
};
|
|
29509
|
-
return this.runHook("after-all", node);
|
|
29510
|
-
}
|
|
29511
|
-
gobbleExpressions(untilICode) {
|
|
29512
|
-
let nodes = [], ch_i, node;
|
|
29513
|
-
while (this.index < this.expr.length) {
|
|
29514
|
-
ch_i = this.code;
|
|
29515
|
-
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
29516
|
-
this.index++;
|
|
29517
|
-
} else {
|
|
29518
|
-
if (node = this.gobbleExpression()) {
|
|
29519
|
-
nodes.push(node);
|
|
29520
|
-
} else if (this.index < this.expr.length) {
|
|
29521
|
-
if (ch_i === untilICode) {
|
|
29522
|
-
break;
|
|
29523
|
-
}
|
|
29524
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
29525
|
-
}
|
|
29526
|
-
}
|
|
29527
|
-
}
|
|
29528
|
-
return nodes;
|
|
29529
|
-
}
|
|
29530
|
-
gobbleExpression() {
|
|
29531
|
-
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
29532
|
-
this.gobbleSpaces();
|
|
29533
|
-
return this.runHook("after-expression", node);
|
|
29534
|
-
}
|
|
29535
|
-
gobbleBinaryOp() {
|
|
29536
|
-
this.gobbleSpaces();
|
|
29537
|
-
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
29538
|
-
let tc_len = to_check.length;
|
|
29539
|
-
while (tc_len > 0) {
|
|
29540
|
-
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)))) {
|
|
29541
|
-
this.index += tc_len;
|
|
29542
|
-
return to_check;
|
|
29543
|
-
}
|
|
29544
|
-
to_check = to_check.substr(0, --tc_len);
|
|
29545
|
-
}
|
|
29546
|
-
return false;
|
|
29547
|
-
}
|
|
29548
|
-
gobbleBinaryExpression() {
|
|
29549
|
-
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
29550
|
-
left = this.gobbleToken();
|
|
29551
|
-
if (!left) {
|
|
29552
|
-
return left;
|
|
29553
|
-
}
|
|
29554
|
-
biop = this.gobbleBinaryOp();
|
|
29555
|
-
if (!biop) {
|
|
29556
|
-
return left;
|
|
29557
|
-
}
|
|
29558
|
-
biop_info = {
|
|
29559
|
-
value: biop,
|
|
29560
|
-
prec: Jsep.binaryPrecedence(biop),
|
|
29561
|
-
right_a: Jsep.right_associative.has(biop)
|
|
29562
|
-
};
|
|
29563
|
-
right = this.gobbleToken();
|
|
29564
|
-
if (!right) {
|
|
29565
|
-
this.throwError("Expected expression after " + biop);
|
|
29566
|
-
}
|
|
29567
|
-
stack = [left, biop_info, right];
|
|
29568
|
-
while (biop = this.gobbleBinaryOp()) {
|
|
29569
|
-
prec = Jsep.binaryPrecedence(biop);
|
|
29570
|
-
if (prec === 0) {
|
|
29571
|
-
this.index -= biop.length;
|
|
29572
|
-
break;
|
|
29573
|
-
}
|
|
29574
|
-
biop_info = {
|
|
29575
|
-
value: biop,
|
|
29576
|
-
prec,
|
|
29577
|
-
right_a: Jsep.right_associative.has(biop)
|
|
29578
|
-
};
|
|
29579
|
-
cur_biop = biop;
|
|
29580
|
-
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
29581
|
-
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
29582
|
-
right = stack.pop();
|
|
29583
|
-
biop = stack.pop().value;
|
|
29584
|
-
left = stack.pop();
|
|
29585
|
-
node = {
|
|
29586
|
-
type: Jsep.BINARY_EXP,
|
|
29587
|
-
operator: biop,
|
|
29588
|
-
left,
|
|
29589
|
-
right
|
|
29590
|
-
};
|
|
29591
|
-
stack.push(node);
|
|
29592
|
-
}
|
|
29593
|
-
node = this.gobbleToken();
|
|
29594
|
-
if (!node) {
|
|
29595
|
-
this.throwError("Expected expression after " + cur_biop);
|
|
29596
|
-
}
|
|
29597
|
-
stack.push(biop_info, node);
|
|
29598
|
-
}
|
|
29599
|
-
i = stack.length - 1;
|
|
29600
|
-
node = stack[i];
|
|
29601
|
-
while (i > 1) {
|
|
29602
|
-
node = {
|
|
29603
|
-
type: Jsep.BINARY_EXP,
|
|
29604
|
-
operator: stack[i - 1].value,
|
|
29605
|
-
left: stack[i - 2],
|
|
29606
|
-
right: node
|
|
29607
|
-
};
|
|
29608
|
-
i -= 2;
|
|
29609
|
-
}
|
|
29610
|
-
return node;
|
|
29611
|
-
}
|
|
29612
|
-
gobbleToken() {
|
|
29613
|
-
let ch, to_check, tc_len, node;
|
|
29614
|
-
this.gobbleSpaces();
|
|
29615
|
-
node = this.searchHook("gobble-token");
|
|
29616
|
-
if (node) {
|
|
29617
|
-
return this.runHook("after-token", node);
|
|
29618
|
-
}
|
|
29619
|
-
ch = this.code;
|
|
29620
|
-
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
29621
|
-
return this.gobbleNumericLiteral();
|
|
29622
|
-
}
|
|
29623
|
-
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
29624
|
-
node = this.gobbleStringLiteral();
|
|
29625
|
-
} else if (ch === Jsep.OBRACK_CODE) {
|
|
29626
|
-
node = this.gobbleArray();
|
|
29627
|
-
} else {
|
|
29628
|
-
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
29629
|
-
tc_len = to_check.length;
|
|
29630
|
-
while (tc_len > 0) {
|
|
29631
|
-
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)))) {
|
|
29632
|
-
this.index += tc_len;
|
|
29633
|
-
const argument = this.gobbleToken();
|
|
29634
|
-
if (!argument) {
|
|
29635
|
-
this.throwError("missing unaryOp argument");
|
|
29636
|
-
}
|
|
29637
|
-
return this.runHook("after-token", {
|
|
29638
|
-
type: Jsep.UNARY_EXP,
|
|
29639
|
-
operator: to_check,
|
|
29640
|
-
argument,
|
|
29641
|
-
prefix: true
|
|
29642
|
-
});
|
|
29643
|
-
}
|
|
29644
|
-
to_check = to_check.substr(0, --tc_len);
|
|
29645
|
-
}
|
|
29646
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
29647
|
-
node = this.gobbleIdentifier();
|
|
29648
|
-
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
29649
|
-
node = {
|
|
29650
|
-
type: Jsep.LITERAL,
|
|
29651
|
-
value: Jsep.literals[node.name],
|
|
29652
|
-
raw: node.name
|
|
29653
|
-
};
|
|
29654
|
-
} else if (node.name === Jsep.this_str) {
|
|
29655
|
-
node = {
|
|
29656
|
-
type: Jsep.THIS_EXP
|
|
29657
|
-
};
|
|
29658
|
-
}
|
|
29659
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
29660
|
-
node = this.gobbleGroup();
|
|
29661
|
-
}
|
|
29662
|
-
}
|
|
29663
|
-
if (!node) {
|
|
29664
|
-
return this.runHook("after-token", false);
|
|
29665
|
-
}
|
|
29666
|
-
node = this.gobbleTokenProperty(node);
|
|
29667
|
-
return this.runHook("after-token", node);
|
|
29668
|
-
}
|
|
29669
|
-
gobbleTokenProperty(node) {
|
|
29670
|
-
this.gobbleSpaces();
|
|
29671
|
-
let ch = this.code;
|
|
29672
|
-
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
29673
|
-
let optional;
|
|
29674
|
-
if (ch === Jsep.QUMARK_CODE) {
|
|
29675
|
-
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
29676
|
-
break;
|
|
29677
|
-
}
|
|
29678
|
-
optional = true;
|
|
29679
|
-
this.index += 2;
|
|
29680
|
-
this.gobbleSpaces();
|
|
29681
|
-
ch = this.code;
|
|
29682
|
-
}
|
|
29683
|
-
this.index++;
|
|
29684
|
-
if (ch === Jsep.OBRACK_CODE) {
|
|
29685
|
-
node = {
|
|
29686
|
-
type: Jsep.MEMBER_EXP,
|
|
29687
|
-
computed: true,
|
|
29688
|
-
object: node,
|
|
29689
|
-
property: this.gobbleExpression()
|
|
29690
|
-
};
|
|
29691
|
-
if (!node.property) {
|
|
29692
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
29693
|
-
}
|
|
29694
|
-
this.gobbleSpaces();
|
|
29695
|
-
ch = this.code;
|
|
29696
|
-
if (ch !== Jsep.CBRACK_CODE) {
|
|
29697
|
-
this.throwError("Unclosed [");
|
|
29698
|
-
}
|
|
29699
|
-
this.index++;
|
|
29700
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
29701
|
-
node = {
|
|
29702
|
-
type: Jsep.CALL_EXP,
|
|
29703
|
-
arguments: this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
29704
|
-
callee: node
|
|
29705
|
-
};
|
|
29706
|
-
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
29707
|
-
if (optional) {
|
|
29708
|
-
this.index--;
|
|
29709
|
-
}
|
|
29710
|
-
this.gobbleSpaces();
|
|
29711
|
-
node = {
|
|
29712
|
-
type: Jsep.MEMBER_EXP,
|
|
29713
|
-
computed: false,
|
|
29714
|
-
object: node,
|
|
29715
|
-
property: this.gobbleIdentifier()
|
|
29716
|
-
};
|
|
29717
|
-
}
|
|
29718
|
-
if (optional) {
|
|
29719
|
-
node.optional = true;
|
|
29720
|
-
}
|
|
29721
|
-
this.gobbleSpaces();
|
|
29722
|
-
ch = this.code;
|
|
29723
|
-
}
|
|
29724
|
-
return node;
|
|
29725
|
-
}
|
|
29726
|
-
gobbleNumericLiteral() {
|
|
29727
|
-
let number = "", ch, chCode;
|
|
29728
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
29729
|
-
number += this.expr.charAt(this.index++);
|
|
29730
|
-
}
|
|
29731
|
-
if (this.code === Jsep.PERIOD_CODE) {
|
|
29732
|
-
number += this.expr.charAt(this.index++);
|
|
29733
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
29734
|
-
number += this.expr.charAt(this.index++);
|
|
29735
|
-
}
|
|
29736
|
-
}
|
|
29737
|
-
ch = this.char;
|
|
29738
|
-
if (ch === "e" || ch === "E") {
|
|
29739
|
-
number += this.expr.charAt(this.index++);
|
|
29740
|
-
ch = this.char;
|
|
29741
|
-
if (ch === "+" || ch === "-") {
|
|
29742
|
-
number += this.expr.charAt(this.index++);
|
|
29743
|
-
}
|
|
29744
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
29745
|
-
number += this.expr.charAt(this.index++);
|
|
29746
|
-
}
|
|
29747
|
-
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
29748
|
-
this.throwError("Expected exponent (" + number + this.char + ")");
|
|
29749
|
-
}
|
|
29750
|
-
}
|
|
29751
|
-
chCode = this.code;
|
|
29752
|
-
if (Jsep.isIdentifierStart(chCode)) {
|
|
29753
|
-
this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
|
|
29754
|
-
} else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
29755
|
-
this.throwError("Unexpected period");
|
|
29756
|
-
}
|
|
29757
|
-
return {
|
|
29758
|
-
type: Jsep.LITERAL,
|
|
29759
|
-
value: parseFloat(number),
|
|
29760
|
-
raw: number
|
|
29761
|
-
};
|
|
29762
|
-
}
|
|
29763
|
-
gobbleStringLiteral() {
|
|
29764
|
-
let str = "";
|
|
29765
|
-
const startIndex = this.index;
|
|
29766
|
-
const quote = this.expr.charAt(this.index++);
|
|
29767
|
-
let closed = false;
|
|
29768
|
-
while (this.index < this.expr.length) {
|
|
29769
|
-
let ch = this.expr.charAt(this.index++);
|
|
29770
|
-
if (ch === quote) {
|
|
29771
|
-
closed = true;
|
|
29772
|
-
break;
|
|
29773
|
-
} else if (ch === "\\") {
|
|
29774
|
-
ch = this.expr.charAt(this.index++);
|
|
29775
|
-
switch (ch) {
|
|
29776
|
-
case "n":
|
|
29777
|
-
str += `
|
|
29778
|
-
`;
|
|
29779
|
-
break;
|
|
29780
|
-
case "r":
|
|
29781
|
-
str += "\r";
|
|
29782
|
-
break;
|
|
29783
|
-
case "t":
|
|
29784
|
-
str += "\t";
|
|
29785
|
-
break;
|
|
29786
|
-
case "b":
|
|
29787
|
-
str += "\b";
|
|
29788
|
-
break;
|
|
29789
|
-
case "f":
|
|
29790
|
-
str += "\f";
|
|
29791
|
-
break;
|
|
29792
|
-
case "v":
|
|
29793
|
-
str += "\v";
|
|
29794
|
-
break;
|
|
29795
|
-
default:
|
|
29796
|
-
str += ch;
|
|
29797
|
-
}
|
|
29798
|
-
} else {
|
|
29799
|
-
str += ch;
|
|
29800
|
-
}
|
|
29801
|
-
}
|
|
29802
|
-
if (!closed) {
|
|
29803
|
-
this.throwError('Unclosed quote after "' + str + '"');
|
|
29804
|
-
}
|
|
29805
|
-
return {
|
|
29806
|
-
type: Jsep.LITERAL,
|
|
29807
|
-
value: str,
|
|
29808
|
-
raw: this.expr.substring(startIndex, this.index)
|
|
29809
|
-
};
|
|
29810
|
-
}
|
|
29811
|
-
gobbleIdentifier() {
|
|
29812
|
-
let ch = this.code, start = this.index;
|
|
29813
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
29814
|
-
this.index++;
|
|
29815
|
-
} else {
|
|
29816
|
-
this.throwError("Unexpected " + this.char);
|
|
29817
|
-
}
|
|
29818
|
-
while (this.index < this.expr.length) {
|
|
29819
|
-
ch = this.code;
|
|
29820
|
-
if (Jsep.isIdentifierPart(ch)) {
|
|
29821
|
-
this.index++;
|
|
29822
|
-
} else {
|
|
29823
|
-
break;
|
|
29824
|
-
}
|
|
29825
|
-
}
|
|
29826
|
-
return {
|
|
29827
|
-
type: Jsep.IDENTIFIER,
|
|
29828
|
-
name: this.expr.slice(start, this.index)
|
|
29829
|
-
};
|
|
29830
|
-
}
|
|
29831
|
-
gobbleArguments(termination) {
|
|
29832
|
-
const args = [];
|
|
29833
|
-
let closed = false;
|
|
29834
|
-
let separator_count = 0;
|
|
29835
|
-
while (this.index < this.expr.length) {
|
|
29836
|
-
this.gobbleSpaces();
|
|
29837
|
-
let ch_i = this.code;
|
|
29838
|
-
if (ch_i === termination) {
|
|
29839
|
-
closed = true;
|
|
29840
|
-
this.index++;
|
|
29841
|
-
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
29842
|
-
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
29843
|
-
}
|
|
29844
|
-
break;
|
|
29845
|
-
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
29846
|
-
this.index++;
|
|
29847
|
-
separator_count++;
|
|
29848
|
-
if (separator_count !== args.length) {
|
|
29849
|
-
if (termination === Jsep.CPAREN_CODE) {
|
|
29850
|
-
this.throwError("Unexpected token ,");
|
|
29851
|
-
} else if (termination === Jsep.CBRACK_CODE) {
|
|
29852
|
-
for (let arg = args.length;arg < separator_count; arg++) {
|
|
29853
|
-
args.push(null);
|
|
29854
|
-
}
|
|
29855
|
-
}
|
|
29856
|
-
}
|
|
29857
|
-
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
29858
|
-
this.throwError("Expected comma");
|
|
29859
|
-
} else {
|
|
29860
|
-
const node = this.gobbleExpression();
|
|
29861
|
-
if (!node || node.type === Jsep.COMPOUND) {
|
|
29862
|
-
this.throwError("Expected comma");
|
|
29863
|
-
}
|
|
29864
|
-
args.push(node);
|
|
29865
|
-
}
|
|
29866
|
-
}
|
|
29867
|
-
if (!closed) {
|
|
29868
|
-
this.throwError("Expected " + String.fromCharCode(termination));
|
|
29869
|
-
}
|
|
29870
|
-
return args;
|
|
29871
|
-
}
|
|
29872
|
-
gobbleGroup() {
|
|
29873
|
-
this.index++;
|
|
29874
|
-
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
29875
|
-
if (this.code === Jsep.CPAREN_CODE) {
|
|
29876
|
-
this.index++;
|
|
29877
|
-
if (nodes.length === 1) {
|
|
29878
|
-
return nodes[0];
|
|
29879
|
-
} else if (!nodes.length) {
|
|
29880
|
-
return false;
|
|
29881
|
-
} else {
|
|
29882
|
-
return {
|
|
29883
|
-
type: Jsep.SEQUENCE_EXP,
|
|
29884
|
-
expressions: nodes
|
|
29885
|
-
};
|
|
29886
|
-
}
|
|
29887
|
-
} else {
|
|
29888
|
-
this.throwError("Unclosed (");
|
|
29889
|
-
}
|
|
29890
|
-
}
|
|
29891
|
-
gobbleArray() {
|
|
29892
|
-
this.index++;
|
|
29893
|
-
return {
|
|
29894
|
-
type: Jsep.ARRAY_EXP,
|
|
29895
|
-
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
29896
|
-
};
|
|
29897
|
-
}
|
|
29898
|
-
}
|
|
29899
|
-
var hooks = new Hooks;
|
|
29900
|
-
Object.assign(Jsep, {
|
|
29901
|
-
hooks,
|
|
29902
|
-
plugins: new Plugins(Jsep),
|
|
29903
|
-
COMPOUND: "Compound",
|
|
29904
|
-
SEQUENCE_EXP: "SequenceExpression",
|
|
29905
|
-
IDENTIFIER: "Identifier",
|
|
29906
|
-
MEMBER_EXP: "MemberExpression",
|
|
29907
|
-
LITERAL: "Literal",
|
|
29908
|
-
THIS_EXP: "ThisExpression",
|
|
29909
|
-
CALL_EXP: "CallExpression",
|
|
29910
|
-
UNARY_EXP: "UnaryExpression",
|
|
29911
|
-
BINARY_EXP: "BinaryExpression",
|
|
29912
|
-
ARRAY_EXP: "ArrayExpression",
|
|
29913
|
-
TAB_CODE: 9,
|
|
29914
|
-
LF_CODE: 10,
|
|
29915
|
-
CR_CODE: 13,
|
|
29916
|
-
SPACE_CODE: 32,
|
|
29917
|
-
PERIOD_CODE: 46,
|
|
29918
|
-
COMMA_CODE: 44,
|
|
29919
|
-
SQUOTE_CODE: 39,
|
|
29920
|
-
DQUOTE_CODE: 34,
|
|
29921
|
-
OPAREN_CODE: 40,
|
|
29922
|
-
CPAREN_CODE: 41,
|
|
29923
|
-
OBRACK_CODE: 91,
|
|
29924
|
-
CBRACK_CODE: 93,
|
|
29925
|
-
QUMARK_CODE: 63,
|
|
29926
|
-
SEMCOL_CODE: 59,
|
|
29927
|
-
COLON_CODE: 58,
|
|
29928
|
-
unary_ops: {
|
|
29929
|
-
"-": 1,
|
|
29930
|
-
"!": 1,
|
|
29931
|
-
"~": 1,
|
|
29932
|
-
"+": 1
|
|
29933
|
-
},
|
|
29934
|
-
binary_ops: {
|
|
29935
|
-
"||": 1,
|
|
29936
|
-
"??": 1,
|
|
29937
|
-
"&&": 2,
|
|
29938
|
-
"|": 3,
|
|
29939
|
-
"^": 4,
|
|
29940
|
-
"&": 5,
|
|
29941
|
-
"==": 6,
|
|
29942
|
-
"!=": 6,
|
|
29943
|
-
"===": 6,
|
|
29944
|
-
"!==": 6,
|
|
29945
|
-
"<": 7,
|
|
29946
|
-
">": 7,
|
|
29947
|
-
"<=": 7,
|
|
29948
|
-
">=": 7,
|
|
29949
|
-
"<<": 8,
|
|
29950
|
-
">>": 8,
|
|
29951
|
-
">>>": 8,
|
|
29952
|
-
"+": 9,
|
|
29953
|
-
"-": 9,
|
|
29954
|
-
"*": 10,
|
|
29955
|
-
"/": 10,
|
|
29956
|
-
"%": 10,
|
|
29957
|
-
"**": 11
|
|
29958
|
-
},
|
|
29959
|
-
right_associative: new Set(["**"]),
|
|
29960
|
-
additional_identifier_chars: new Set(["$", "_"]),
|
|
29961
|
-
literals: {
|
|
29962
|
-
true: true,
|
|
29963
|
-
false: false,
|
|
29964
|
-
null: null
|
|
29965
|
-
},
|
|
29966
|
-
this_str: "this"
|
|
29967
|
-
});
|
|
29968
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
29969
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
29970
|
-
var jsep = (expr) => new Jsep(expr).parse();
|
|
29971
|
-
var stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
29972
|
-
});
|
|
29973
|
-
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === undefined).forEach((m) => {
|
|
29974
|
-
jsep[m] = Jsep[m];
|
|
29975
|
-
});
|
|
29976
|
-
jsep.Jsep = Jsep;
|
|
29977
|
-
var CONDITIONAL_EXP = "ConditionalExpression";
|
|
29978
|
-
var ternary = {
|
|
29979
|
-
name: "ternary",
|
|
29980
|
-
init(jsep2) {
|
|
29981
|
-
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
29982
|
-
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
29983
|
-
this.index++;
|
|
29984
|
-
const test = env.node;
|
|
29985
|
-
const consequent = this.gobbleExpression();
|
|
29986
|
-
if (!consequent) {
|
|
29987
|
-
this.throwError("Expected expression");
|
|
29988
|
-
}
|
|
29989
|
-
this.gobbleSpaces();
|
|
29990
|
-
if (this.code === jsep2.COLON_CODE) {
|
|
29991
|
-
this.index++;
|
|
29992
|
-
const alternate = this.gobbleExpression();
|
|
29993
|
-
if (!alternate) {
|
|
29994
|
-
this.throwError("Expected expression");
|
|
29995
|
-
}
|
|
29996
|
-
env.node = {
|
|
29997
|
-
type: CONDITIONAL_EXP,
|
|
29998
|
-
test,
|
|
29999
|
-
consequent,
|
|
30000
|
-
alternate
|
|
30001
|
-
};
|
|
30002
|
-
if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
|
|
30003
|
-
let newTest = test;
|
|
30004
|
-
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
30005
|
-
newTest = newTest.right;
|
|
30006
|
-
}
|
|
30007
|
-
env.node.test = newTest.right;
|
|
30008
|
-
newTest.right = env.node;
|
|
30009
|
-
env.node = test;
|
|
30010
|
-
}
|
|
30011
|
-
} else {
|
|
30012
|
-
this.throwError("Expected :");
|
|
30013
|
-
}
|
|
30014
|
-
}
|
|
30015
|
-
});
|
|
30016
|
-
}
|
|
30017
|
-
};
|
|
30018
|
-
jsep.plugins.register(ternary);
|
|
30019
|
-
var FSLASH_CODE = 47;
|
|
30020
|
-
var BSLASH_CODE = 92;
|
|
30021
|
-
var index = {
|
|
30022
|
-
name: "regex",
|
|
30023
|
-
init(jsep2) {
|
|
30024
|
-
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
30025
|
-
if (this.code === FSLASH_CODE) {
|
|
30026
|
-
const patternIndex = ++this.index;
|
|
30027
|
-
let inCharSet = false;
|
|
30028
|
-
while (this.index < this.expr.length) {
|
|
30029
|
-
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
30030
|
-
const pattern = this.expr.slice(patternIndex, this.index);
|
|
30031
|
-
let flags = "";
|
|
30032
|
-
while (++this.index < this.expr.length) {
|
|
30033
|
-
const code = this.code;
|
|
30034
|
-
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
30035
|
-
flags += this.char;
|
|
30036
|
-
} else {
|
|
30037
|
-
break;
|
|
30038
|
-
}
|
|
30039
|
-
}
|
|
30040
|
-
let value;
|
|
30041
|
-
try {
|
|
30042
|
-
value = new RegExp(pattern, flags);
|
|
30043
|
-
} catch (e) {
|
|
30044
|
-
this.throwError(e.message);
|
|
30045
|
-
}
|
|
30046
|
-
env.node = {
|
|
30047
|
-
type: jsep2.LITERAL,
|
|
30048
|
-
value,
|
|
30049
|
-
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
30050
|
-
};
|
|
30051
|
-
env.node = this.gobbleTokenProperty(env.node);
|
|
30052
|
-
return env.node;
|
|
30053
|
-
}
|
|
30054
|
-
if (this.code === jsep2.OBRACK_CODE) {
|
|
30055
|
-
inCharSet = true;
|
|
30056
|
-
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
30057
|
-
inCharSet = false;
|
|
30058
|
-
}
|
|
30059
|
-
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
30060
|
-
}
|
|
30061
|
-
this.throwError("Unclosed Regex");
|
|
30062
|
-
}
|
|
30063
|
-
});
|
|
30064
|
-
}
|
|
30065
|
-
};
|
|
30066
|
-
var PLUS_CODE = 43;
|
|
30067
|
-
var MINUS_CODE = 45;
|
|
30068
|
-
var plugin = {
|
|
30069
|
-
name: "assignment",
|
|
30070
|
-
assignmentOperators: new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
30071
|
-
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
30072
|
-
assignmentPrecedence: 0.9,
|
|
30073
|
-
init(jsep2) {
|
|
30074
|
-
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
30075
|
-
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
30076
|
-
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
30077
|
-
const code = this.code;
|
|
30078
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
30079
|
-
this.index += 2;
|
|
30080
|
-
env.node = {
|
|
30081
|
-
type: "UpdateExpression",
|
|
30082
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
30083
|
-
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
30084
|
-
prefix: true
|
|
30085
|
-
};
|
|
30086
|
-
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
30087
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
30088
|
-
}
|
|
30089
|
-
}
|
|
30090
|
-
});
|
|
30091
|
-
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
30092
|
-
if (env.node) {
|
|
30093
|
-
const code = this.code;
|
|
30094
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
30095
|
-
if (!updateNodeTypes.includes(env.node.type)) {
|
|
30096
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
30097
|
-
}
|
|
30098
|
-
this.index += 2;
|
|
30099
|
-
env.node = {
|
|
30100
|
-
type: "UpdateExpression",
|
|
30101
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
30102
|
-
argument: env.node,
|
|
30103
|
-
prefix: false
|
|
30104
|
-
};
|
|
30105
|
-
}
|
|
30106
|
-
}
|
|
30107
|
-
});
|
|
30108
|
-
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
30109
|
-
if (env.node) {
|
|
30110
|
-
updateBinariesToAssignments(env.node);
|
|
30111
|
-
}
|
|
30112
|
-
});
|
|
30113
|
-
function updateBinariesToAssignments(node) {
|
|
30114
|
-
if (plugin.assignmentOperators.has(node.operator)) {
|
|
30115
|
-
node.type = "AssignmentExpression";
|
|
30116
|
-
updateBinariesToAssignments(node.left);
|
|
30117
|
-
updateBinariesToAssignments(node.right);
|
|
30118
|
-
} else if (!node.operator) {
|
|
30119
|
-
Object.values(node).forEach((val) => {
|
|
30120
|
-
if (val && typeof val === "object") {
|
|
30121
|
-
updateBinariesToAssignments(val);
|
|
30122
|
-
}
|
|
30123
|
-
});
|
|
30124
|
-
}
|
|
30125
|
-
}
|
|
30126
|
-
}
|
|
30127
|
-
};
|
|
30128
|
-
jsep.plugins.register(index, plugin);
|
|
30129
|
-
jsep.addUnaryOp("typeof");
|
|
30130
|
-
jsep.addUnaryOp("void");
|
|
30131
|
-
jsep.addLiteral("null", null);
|
|
30132
|
-
jsep.addLiteral("undefined", undefined);
|
|
30133
|
-
var BLOCKED_PROTO_PROPERTIES = new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
30134
|
-
var SafeEval = {
|
|
30135
|
-
evalAst(ast, subs) {
|
|
30136
|
-
switch (ast.type) {
|
|
30137
|
-
case "BinaryExpression":
|
|
30138
|
-
case "LogicalExpression":
|
|
30139
|
-
return SafeEval.evalBinaryExpression(ast, subs);
|
|
30140
|
-
case "Compound":
|
|
30141
|
-
return SafeEval.evalCompound(ast, subs);
|
|
30142
|
-
case "ConditionalExpression":
|
|
30143
|
-
return SafeEval.evalConditionalExpression(ast, subs);
|
|
30144
|
-
case "Identifier":
|
|
30145
|
-
return SafeEval.evalIdentifier(ast, subs);
|
|
30146
|
-
case "Literal":
|
|
30147
|
-
return SafeEval.evalLiteral(ast, subs);
|
|
30148
|
-
case "MemberExpression":
|
|
30149
|
-
return SafeEval.evalMemberExpression(ast, subs);
|
|
30150
|
-
case "UnaryExpression":
|
|
30151
|
-
return SafeEval.evalUnaryExpression(ast, subs);
|
|
30152
|
-
case "ArrayExpression":
|
|
30153
|
-
return SafeEval.evalArrayExpression(ast, subs);
|
|
30154
|
-
case "CallExpression":
|
|
30155
|
-
return SafeEval.evalCallExpression(ast, subs);
|
|
30156
|
-
case "AssignmentExpression":
|
|
30157
|
-
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
30158
|
-
default:
|
|
30159
|
-
throw SyntaxError("Unexpected expression", ast);
|
|
30160
|
-
}
|
|
30161
|
-
},
|
|
30162
|
-
evalBinaryExpression(ast, subs) {
|
|
30163
|
-
const result = {
|
|
30164
|
-
"||": (a, b) => a || b(),
|
|
30165
|
-
"&&": (a, b) => a && b(),
|
|
30166
|
-
"|": (a, b) => a | b(),
|
|
30167
|
-
"^": (a, b) => a ^ b(),
|
|
30168
|
-
"&": (a, b) => a & b(),
|
|
30169
|
-
"==": (a, b) => a == b(),
|
|
30170
|
-
"!=": (a, b) => a != b(),
|
|
30171
|
-
"===": (a, b) => a === b(),
|
|
30172
|
-
"!==": (a, b) => a !== b(),
|
|
30173
|
-
"<": (a, b) => a < b(),
|
|
30174
|
-
">": (a, b) => a > b(),
|
|
30175
|
-
"<=": (a, b) => a <= b(),
|
|
30176
|
-
">=": (a, b) => a >= b(),
|
|
30177
|
-
"<<": (a, b) => a << b(),
|
|
30178
|
-
">>": (a, b) => a >> b(),
|
|
30179
|
-
">>>": (a, b) => a >>> b(),
|
|
30180
|
-
"+": (a, b) => a + b(),
|
|
30181
|
-
"-": (a, b) => a - b(),
|
|
30182
|
-
"*": (a, b) => a * b(),
|
|
30183
|
-
"/": (a, b) => a / b(),
|
|
30184
|
-
"%": (a, b) => a % b()
|
|
30185
|
-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
30186
|
-
return result;
|
|
30187
|
-
},
|
|
30188
|
-
evalCompound(ast, subs) {
|
|
30189
|
-
let last;
|
|
30190
|
-
for (let i = 0;i < ast.body.length; i++) {
|
|
30191
|
-
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
30192
|
-
i += 1;
|
|
30193
|
-
}
|
|
30194
|
-
const expr = ast.body[i];
|
|
30195
|
-
last = SafeEval.evalAst(expr, subs);
|
|
30196
|
-
}
|
|
30197
|
-
return last;
|
|
30198
|
-
},
|
|
30199
|
-
evalConditionalExpression(ast, subs) {
|
|
30200
|
-
if (SafeEval.evalAst(ast.test, subs)) {
|
|
30201
|
-
return SafeEval.evalAst(ast.consequent, subs);
|
|
30202
|
-
}
|
|
30203
|
-
return SafeEval.evalAst(ast.alternate, subs);
|
|
30204
|
-
},
|
|
30205
|
-
evalIdentifier(ast, subs) {
|
|
30206
|
-
if (Object.hasOwn(subs, ast.name)) {
|
|
30207
|
-
return subs[ast.name];
|
|
30208
|
-
}
|
|
30209
|
-
throw ReferenceError(`${ast.name} is not defined`);
|
|
30210
|
-
},
|
|
30211
|
-
evalLiteral(ast) {
|
|
30212
|
-
return ast.value;
|
|
30213
|
-
},
|
|
30214
|
-
evalMemberExpression(ast, subs) {
|
|
30215
|
-
const prop = String(ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name);
|
|
30216
|
-
const obj = SafeEval.evalAst(ast.object, subs);
|
|
30217
|
-
if (obj === undefined || obj === null) {
|
|
30218
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
30219
|
-
}
|
|
30220
|
-
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
30221
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
30222
|
-
}
|
|
30223
|
-
const result = obj[prop];
|
|
30224
|
-
if (typeof result === "function") {
|
|
30225
|
-
return result.bind(obj);
|
|
30226
|
-
}
|
|
30227
|
-
return result;
|
|
30228
|
-
},
|
|
30229
|
-
evalUnaryExpression(ast, subs) {
|
|
30230
|
-
const result = {
|
|
30231
|
-
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
30232
|
-
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
30233
|
-
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
30234
|
-
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
30235
|
-
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
30236
|
-
void: (a) => void SafeEval.evalAst(a, subs)
|
|
30237
|
-
}[ast.operator](ast.argument);
|
|
30238
|
-
return result;
|
|
30239
|
-
},
|
|
30240
|
-
evalArrayExpression(ast, subs) {
|
|
30241
|
-
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
30242
|
-
},
|
|
30243
|
-
evalCallExpression(ast, subs) {
|
|
30244
|
-
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
30245
|
-
const func = SafeEval.evalAst(ast.callee, subs);
|
|
30246
|
-
if (func === Function) {
|
|
30247
|
-
throw new Error("Function constructor is disabled");
|
|
30248
|
-
}
|
|
30249
|
-
return func(...args);
|
|
30250
|
-
},
|
|
30251
|
-
evalAssignmentExpression(ast, subs) {
|
|
30252
|
-
if (ast.left.type !== "Identifier") {
|
|
30253
|
-
throw SyntaxError("Invalid left-hand side in assignment");
|
|
30254
|
-
}
|
|
30255
|
-
const id = ast.left.name;
|
|
30256
|
-
const value = SafeEval.evalAst(ast.right, subs);
|
|
30257
|
-
subs[id] = value;
|
|
30258
|
-
return subs[id];
|
|
30259
|
-
}
|
|
30260
|
-
};
|
|
30261
|
-
|
|
30262
|
-
class SafeScript {
|
|
30263
|
-
constructor(expr) {
|
|
30264
|
-
this.code = expr;
|
|
30265
|
-
this.ast = jsep(this.code);
|
|
30266
|
-
}
|
|
30267
|
-
runInNewContext(context) {
|
|
30268
|
-
const keyMap = Object.assign(Object.create(null), context);
|
|
30269
|
-
return SafeEval.evalAst(this.ast, keyMap);
|
|
29467
|
+
var SENSITIVE_KEY_PREFIXES = new Set([
|
|
29468
|
+
"api",
|
|
29469
|
+
"access",
|
|
29470
|
+
"client",
|
|
29471
|
+
"private",
|
|
29472
|
+
"public",
|
|
29473
|
+
"signing",
|
|
29474
|
+
"encryption",
|
|
29475
|
+
"session",
|
|
29476
|
+
"master",
|
|
29477
|
+
"shared",
|
|
29478
|
+
"root",
|
|
29479
|
+
"ssh",
|
|
29480
|
+
"rsa",
|
|
29481
|
+
"aes",
|
|
29482
|
+
"hmac",
|
|
29483
|
+
"oauth"
|
|
29484
|
+
]);
|
|
29485
|
+
var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi;
|
|
29486
|
+
var EMAIL_PATTERN = /\b[^\s@]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
|
|
29487
|
+
var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
|
|
29488
|
+
var LONG_TOKEN_PATTERN = /\b[A-Za-z0-9_-]{40,}\b/g;
|
|
29489
|
+
var USER_HOME_PATTERN = /([/\\])(Users|home)([/\\])([^/\\]+)/gi;
|
|
29490
|
+
var URL_PATTERN = /\bhttps?:\/\/[^\s,;]+/gi;
|
|
29491
|
+
var URL_TRAILING_PUNCT = /[.,;:!?)\]}>'"]+$/;
|
|
29492
|
+
function shortHash(input) {
|
|
29493
|
+
let hash = 2166136261;
|
|
29494
|
+
for (let i = 0;i < input.length; i++) {
|
|
29495
|
+
hash ^= input.charCodeAt(i);
|
|
29496
|
+
hash = Math.imul(hash, 16777619);
|
|
30270
29497
|
}
|
|
29498
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
30271
29499
|
}
|
|
30272
|
-
function
|
|
30273
|
-
|
|
30274
|
-
|
|
30275
|
-
|
|
30276
|
-
}
|
|
30277
|
-
|
|
30278
|
-
|
|
30279
|
-
arr.unshift(item);
|
|
30280
|
-
return arr;
|
|
29500
|
+
function redactUrl(raw) {
|
|
29501
|
+
try {
|
|
29502
|
+
const url = new URL(raw);
|
|
29503
|
+
return `${url.protocol}//${url.host}`;
|
|
29504
|
+
} catch {
|
|
29505
|
+
return `url#${shortHash(raw)}`;
|
|
29506
|
+
}
|
|
30281
29507
|
}
|
|
30282
|
-
|
|
30283
|
-
|
|
30284
|
-
|
|
30285
|
-
|
|
30286
|
-
|
|
30287
|
-
|
|
30288
|
-
|
|
29508
|
+
function redactValueDetectors(value) {
|
|
29509
|
+
let out = value;
|
|
29510
|
+
out = out.replace(JWT_PATTERN, () => REDACTED);
|
|
29511
|
+
out = out.replace(URL_PATTERN, (match) => {
|
|
29512
|
+
const trailing = match.match(URL_TRAILING_PUNCT)?.[0] ?? "";
|
|
29513
|
+
const core = trailing ? match.slice(0, -trailing.length) : match;
|
|
29514
|
+
return `${redactUrl(core)}${trailing}`;
|
|
29515
|
+
});
|
|
29516
|
+
out = out.replace(USER_HOME_PATTERN, (_match, sep1, folder, sep2) => `${sep1}${folder}${sep2}<user>`);
|
|
29517
|
+
out = out.replace(EMAIL_PATTERN, (match) => `email#${shortHash(match)}`);
|
|
29518
|
+
out = out.replace(UUID_PATTERN, (match) => `uuid#${shortHash(match)}`);
|
|
29519
|
+
out = out.replace(LONG_TOKEN_PATTERN, () => REDACTED);
|
|
29520
|
+
if (out.length > MAX_VALUE_LENGTH) {
|
|
29521
|
+
out = `${out.slice(0, MAX_VALUE_LENGTH)}…`;
|
|
30289
29522
|
}
|
|
29523
|
+
return out;
|
|
30290
29524
|
}
|
|
30291
|
-
function
|
|
30292
|
-
|
|
30293
|
-
|
|
30294
|
-
|
|
30295
|
-
|
|
30296
|
-
|
|
30297
|
-
|
|
30298
|
-
|
|
30299
|
-
return
|
|
30300
|
-
}
|
|
30301
|
-
}
|
|
30302
|
-
if (typeof opts === "string") {
|
|
30303
|
-
otherTypeCallback = callback;
|
|
30304
|
-
callback = obj;
|
|
30305
|
-
obj = expr;
|
|
30306
|
-
expr = opts;
|
|
30307
|
-
opts = null;
|
|
30308
|
-
}
|
|
30309
|
-
const optObj = opts && typeof opts === "object";
|
|
30310
|
-
opts = opts || {};
|
|
30311
|
-
this.json = opts.json || obj;
|
|
30312
|
-
this.path = opts.path || expr;
|
|
30313
|
-
this.resultType = opts.resultType || "value";
|
|
30314
|
-
this.flatten = opts.flatten || false;
|
|
30315
|
-
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
30316
|
-
this.sandbox = opts.sandbox || {};
|
|
30317
|
-
this.eval = opts.eval === undefined ? "safe" : opts.eval;
|
|
30318
|
-
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
30319
|
-
this.parent = opts.parent || null;
|
|
30320
|
-
this.parentProperty = opts.parentProperty || null;
|
|
30321
|
-
this.callback = opts.callback || callback || null;
|
|
30322
|
-
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
30323
|
-
throw new TypeError("You must supply an otherTypeCallback callback option " + "with the @other() operator.");
|
|
30324
|
-
};
|
|
30325
|
-
if (opts.autostart !== false) {
|
|
30326
|
-
const args = {
|
|
30327
|
-
path: optObj ? opts.path : expr
|
|
30328
|
-
};
|
|
30329
|
-
if (!optObj) {
|
|
30330
|
-
args.json = obj;
|
|
30331
|
-
} else if ("json" in opts) {
|
|
30332
|
-
args.json = opts.json;
|
|
29525
|
+
function nameTokens(name) {
|
|
29526
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).map((t) => t.toLowerCase()).filter(Boolean);
|
|
29527
|
+
}
|
|
29528
|
+
function isSensitiveName(name) {
|
|
29529
|
+
const tokens = nameTokens(name);
|
|
29530
|
+
for (let i = 0;i < tokens.length; i++) {
|
|
29531
|
+
const token = tokens[i];
|
|
29532
|
+
if (SENSITIVE_NAME_TOKENS.has(token)) {
|
|
29533
|
+
return true;
|
|
30333
29534
|
}
|
|
30334
|
-
|
|
30335
|
-
|
|
30336
|
-
|
|
29535
|
+
if (token === "key" || token === "keys") {
|
|
29536
|
+
const prev = tokens[i - 1];
|
|
29537
|
+
if (prev && SENSITIVE_KEY_PREFIXES.has(prev)) {
|
|
29538
|
+
return true;
|
|
29539
|
+
}
|
|
30337
29540
|
}
|
|
30338
|
-
return ret;
|
|
30339
29541
|
}
|
|
29542
|
+
return false;
|
|
30340
29543
|
}
|
|
30341
|
-
|
|
30342
|
-
|
|
30343
|
-
let {
|
|
30344
|
-
flatten,
|
|
30345
|
-
wrap
|
|
30346
|
-
} = this;
|
|
30347
|
-
this.currResultType = this.resultType;
|
|
30348
|
-
this.currEval = this.eval;
|
|
30349
|
-
this.currSandbox = this.sandbox;
|
|
30350
|
-
callback = callback || this.callback;
|
|
30351
|
-
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
30352
|
-
json = json || this.json;
|
|
30353
|
-
expr = expr || this.path;
|
|
30354
|
-
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
30355
|
-
if (!expr.path && expr.path !== "") {
|
|
30356
|
-
throw new TypeError('You must supply a "path" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
30357
|
-
}
|
|
30358
|
-
if (!Object.hasOwn(expr, "json")) {
|
|
30359
|
-
throw new TypeError('You must supply a "json" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
30360
|
-
}
|
|
30361
|
-
({
|
|
30362
|
-
json
|
|
30363
|
-
} = expr);
|
|
30364
|
-
flatten = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten;
|
|
30365
|
-
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
30366
|
-
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
30367
|
-
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
30368
|
-
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
30369
|
-
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
30370
|
-
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
30371
|
-
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
30372
|
-
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
30373
|
-
expr = expr.path;
|
|
30374
|
-
}
|
|
30375
|
-
currParent = currParent || null;
|
|
30376
|
-
currParentProperty = currParentProperty || null;
|
|
30377
|
-
if (Array.isArray(expr)) {
|
|
30378
|
-
expr = JSONPath.toPathString(expr);
|
|
30379
|
-
}
|
|
30380
|
-
if (!expr && expr !== "" || !json) {
|
|
29544
|
+
function redactProperty(name, value) {
|
|
29545
|
+
if (value === undefined || value === null) {
|
|
30381
29546
|
return;
|
|
30382
29547
|
}
|
|
30383
|
-
|
|
30384
|
-
|
|
30385
|
-
exprList.shift();
|
|
29548
|
+
if (isSensitiveName(name)) {
|
|
29549
|
+
return REDACTED;
|
|
30386
29550
|
}
|
|
30387
|
-
|
|
30388
|
-
|
|
30389
|
-
return ea && !ea.isParentSelector;
|
|
30390
|
-
});
|
|
30391
|
-
if (!result.length) {
|
|
30392
|
-
return wrap ? [] : undefined;
|
|
29551
|
+
if (typeof value === "boolean" || typeof value === "number") {
|
|
29552
|
+
return value;
|
|
30393
29553
|
}
|
|
30394
|
-
if (
|
|
30395
|
-
return
|
|
29554
|
+
if (typeof value !== "string") {
|
|
29555
|
+
return "[OBJECT]";
|
|
30396
29556
|
}
|
|
30397
|
-
return
|
|
30398
|
-
|
|
30399
|
-
|
|
30400
|
-
|
|
30401
|
-
|
|
30402
|
-
|
|
29557
|
+
return redactValueDetectors(value);
|
|
29558
|
+
}
|
|
29559
|
+
function redactProperties(properties) {
|
|
29560
|
+
const out = {};
|
|
29561
|
+
for (const [name, value] of Object.entries(properties)) {
|
|
29562
|
+
const redacted = redactProperty(name, value);
|
|
29563
|
+
if (redacted !== undefined) {
|
|
29564
|
+
out[name] = redacted;
|
|
30403
29565
|
}
|
|
30404
|
-
return rslt;
|
|
30405
|
-
}, []);
|
|
30406
|
-
};
|
|
30407
|
-
JSONPath.prototype._getPreferredOutput = function(ea) {
|
|
30408
|
-
const resultType = this.currResultType;
|
|
30409
|
-
switch (resultType) {
|
|
30410
|
-
case "all": {
|
|
30411
|
-
const path3 = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
30412
|
-
ea.pointer = JSONPath.toPointer(path3);
|
|
30413
|
-
ea.path = typeof ea.path === "string" ? ea.path : JSONPath.toPathString(ea.path);
|
|
30414
|
-
return ea;
|
|
30415
|
-
}
|
|
30416
|
-
case "value":
|
|
30417
|
-
case "parent":
|
|
30418
|
-
case "parentProperty":
|
|
30419
|
-
return ea[resultType];
|
|
30420
|
-
case "path":
|
|
30421
|
-
return JSONPath.toPathString(ea[resultType]);
|
|
30422
|
-
case "pointer":
|
|
30423
|
-
return JSONPath.toPointer(ea.path);
|
|
30424
|
-
default:
|
|
30425
|
-
throw new TypeError("Unknown result type");
|
|
30426
29566
|
}
|
|
30427
|
-
|
|
30428
|
-
|
|
30429
|
-
|
|
30430
|
-
|
|
30431
|
-
|
|
30432
|
-
|
|
29567
|
+
return out;
|
|
29568
|
+
}
|
|
29569
|
+
|
|
29570
|
+
// ../../common/src/trackedAction.ts
|
|
29571
|
+
var pollSignalSlot = singleton("PollSignal");
|
|
29572
|
+
var cliErrorCodeValues = new Set(CLI_ERROR_CODES);
|
|
29573
|
+
var retryHintValues = new Set(RETRY_HINTS);
|
|
29574
|
+
var processContext = {
|
|
29575
|
+
exit: (code) => {
|
|
29576
|
+
process.exitCode = code;
|
|
29577
|
+
},
|
|
29578
|
+
get pollSignal() {
|
|
29579
|
+
return pollSignalSlot.get();
|
|
30433
29580
|
}
|
|
30434
29581
|
};
|
|
30435
|
-
|
|
30436
|
-
|
|
30437
|
-
|
|
30438
|
-
|
|
30439
|
-
|
|
30440
|
-
|
|
30441
|
-
|
|
30442
|
-
|
|
30443
|
-
hasArrExpr
|
|
30444
|
-
};
|
|
30445
|
-
this._handleCallback(retObj, callback, "value");
|
|
30446
|
-
return retObj;
|
|
30447
|
-
}
|
|
30448
|
-
const loc = expr[0], x = expr.slice(1);
|
|
30449
|
-
const ret = [];
|
|
30450
|
-
function addRet(elems) {
|
|
30451
|
-
if (Array.isArray(elems)) {
|
|
30452
|
-
elems.forEach((t) => {
|
|
30453
|
-
ret.push(t);
|
|
30454
|
-
});
|
|
30455
|
-
} else {
|
|
30456
|
-
ret.push(elems);
|
|
30457
|
-
}
|
|
30458
|
-
}
|
|
30459
|
-
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
30460
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr));
|
|
30461
|
-
} else if (loc === "*") {
|
|
30462
|
-
this._walk(val, (m) => {
|
|
30463
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true, true));
|
|
30464
|
-
});
|
|
30465
|
-
} else if (loc === "..") {
|
|
30466
|
-
addRet(this._trace(x, val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
30467
|
-
this._walk(val, (m) => {
|
|
30468
|
-
if (typeof val[m] === "object") {
|
|
30469
|
-
addRet(this._trace(expr.slice(), val[m], push(path3, m), val, m, callback, true));
|
|
30470
|
-
}
|
|
30471
|
-
});
|
|
30472
|
-
} else if (loc === "^") {
|
|
30473
|
-
this._hasParentSelector = true;
|
|
30474
|
-
return {
|
|
30475
|
-
path: path3.slice(0, -1),
|
|
30476
|
-
expr: x,
|
|
30477
|
-
isParentSelector: true
|
|
30478
|
-
};
|
|
30479
|
-
} else if (loc === "~") {
|
|
30480
|
-
retObj = {
|
|
30481
|
-
path: push(path3, loc),
|
|
30482
|
-
value: parentPropName,
|
|
30483
|
-
parent,
|
|
30484
|
-
parentProperty: null
|
|
30485
|
-
};
|
|
30486
|
-
this._handleCallback(retObj, callback, "property");
|
|
30487
|
-
return retObj;
|
|
30488
|
-
} else if (loc === "$") {
|
|
30489
|
-
addRet(this._trace(x, val, path3, null, null, callback, hasArrExpr));
|
|
30490
|
-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
30491
|
-
addRet(this._slice(loc, x, val, path3, parent, parentPropName, callback));
|
|
30492
|
-
} else if (loc.indexOf("?(") === 0) {
|
|
30493
|
-
if (this.currEval === false) {
|
|
30494
|
-
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
30495
|
-
}
|
|
30496
|
-
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
30497
|
-
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
30498
|
-
if (nested) {
|
|
30499
|
-
this._walk(val, (m) => {
|
|
30500
|
-
const npath = [nested[2]];
|
|
30501
|
-
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
30502
|
-
const filterResults = this._trace(npath, nvalue, path3, parent, parentPropName, callback, true);
|
|
30503
|
-
if (filterResults.length > 0) {
|
|
30504
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
30505
|
-
}
|
|
30506
|
-
});
|
|
30507
|
-
} else {
|
|
30508
|
-
this._walk(val, (m) => {
|
|
30509
|
-
if (this._eval(safeLoc, val[m], m, path3, parent, parentPropName)) {
|
|
30510
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
30511
|
-
}
|
|
30512
|
-
});
|
|
30513
|
-
}
|
|
30514
|
-
} else if (loc[0] === "(") {
|
|
30515
|
-
if (this.currEval === false) {
|
|
30516
|
-
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
29582
|
+
function extractCommandParams(cmd) {
|
|
29583
|
+
const params = {};
|
|
29584
|
+
const registered = cmd.registeredArguments ?? [];
|
|
29585
|
+
const processed = cmd.processedArgs ?? [];
|
|
29586
|
+
for (let i = 0;i < registered.length; i++) {
|
|
29587
|
+
const value = processed[i];
|
|
29588
|
+
if (value === undefined) {
|
|
29589
|
+
continue;
|
|
30517
29590
|
}
|
|
30518
|
-
|
|
30519
|
-
|
|
30520
|
-
|
|
30521
|
-
const valueType = loc.slice(1, -2);
|
|
30522
|
-
switch (valueType) {
|
|
30523
|
-
case "scalar":
|
|
30524
|
-
if (!val || !["object", "function"].includes(typeof val)) {
|
|
30525
|
-
addType = true;
|
|
30526
|
-
}
|
|
30527
|
-
break;
|
|
30528
|
-
case "boolean":
|
|
30529
|
-
case "string":
|
|
30530
|
-
case "undefined":
|
|
30531
|
-
case "function":
|
|
30532
|
-
if (typeof val === valueType) {
|
|
30533
|
-
addType = true;
|
|
30534
|
-
}
|
|
30535
|
-
break;
|
|
30536
|
-
case "integer":
|
|
30537
|
-
if (Number.isFinite(val) && !(val % 1)) {
|
|
30538
|
-
addType = true;
|
|
30539
|
-
}
|
|
30540
|
-
break;
|
|
30541
|
-
case "number":
|
|
30542
|
-
if (Number.isFinite(val)) {
|
|
30543
|
-
addType = true;
|
|
30544
|
-
}
|
|
30545
|
-
break;
|
|
30546
|
-
case "nonFinite":
|
|
30547
|
-
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
30548
|
-
addType = true;
|
|
30549
|
-
}
|
|
30550
|
-
break;
|
|
30551
|
-
case "object":
|
|
30552
|
-
if (val && typeof val === valueType) {
|
|
30553
|
-
addType = true;
|
|
30554
|
-
}
|
|
30555
|
-
break;
|
|
30556
|
-
case "array":
|
|
30557
|
-
if (Array.isArray(val)) {
|
|
30558
|
-
addType = true;
|
|
30559
|
-
}
|
|
30560
|
-
break;
|
|
30561
|
-
case "other":
|
|
30562
|
-
addType = this.currOtherTypeCallback(val, path3, parent, parentPropName);
|
|
30563
|
-
break;
|
|
30564
|
-
case "null":
|
|
30565
|
-
if (val === null) {
|
|
30566
|
-
addType = true;
|
|
30567
|
-
}
|
|
30568
|
-
break;
|
|
30569
|
-
default:
|
|
30570
|
-
throw new TypeError("Unknown value type " + valueType);
|
|
30571
|
-
}
|
|
30572
|
-
if (addType) {
|
|
30573
|
-
retObj = {
|
|
30574
|
-
path: path3,
|
|
30575
|
-
value: val,
|
|
30576
|
-
parent,
|
|
30577
|
-
parentProperty: parentPropName
|
|
30578
|
-
};
|
|
30579
|
-
this._handleCallback(retObj, callback, "value");
|
|
30580
|
-
return retObj;
|
|
30581
|
-
}
|
|
30582
|
-
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
30583
|
-
const locProp = loc.slice(1);
|
|
30584
|
-
addRet(this._trace(x, val[locProp], push(path3, locProp), val, locProp, callback, hasArrExpr, true));
|
|
30585
|
-
} else if (loc.includes(",")) {
|
|
30586
|
-
const parts = loc.split(",");
|
|
30587
|
-
for (const part of parts) {
|
|
30588
|
-
addRet(this._trace(unshift(part, x), val, path3, parent, parentPropName, callback, true));
|
|
30589
|
-
}
|
|
30590
|
-
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
30591
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr, true));
|
|
30592
|
-
}
|
|
30593
|
-
if (this._hasParentSelector) {
|
|
30594
|
-
for (let t = 0;t < ret.length; t++) {
|
|
30595
|
-
const rett = ret[t];
|
|
30596
|
-
if (rett && rett.isParentSelector) {
|
|
30597
|
-
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
30598
|
-
if (Array.isArray(tmp)) {
|
|
30599
|
-
ret[t] = tmp[0];
|
|
30600
|
-
const tl = tmp.length;
|
|
30601
|
-
for (let tt = 1;tt < tl; tt++) {
|
|
30602
|
-
t++;
|
|
30603
|
-
ret.splice(t, 0, tmp[tt]);
|
|
30604
|
-
}
|
|
30605
|
-
} else {
|
|
30606
|
-
ret[t] = tmp;
|
|
30607
|
-
}
|
|
30608
|
-
}
|
|
29591
|
+
const name = registered[i].name();
|
|
29592
|
+
if (name) {
|
|
29593
|
+
params[name] = value;
|
|
30609
29594
|
}
|
|
30610
29595
|
}
|
|
30611
|
-
|
|
30612
|
-
|
|
30613
|
-
|
|
30614
|
-
if (Array.isArray(val)) {
|
|
30615
|
-
const n = val.length;
|
|
30616
|
-
for (let i = 0;i < n; i++) {
|
|
30617
|
-
f(i);
|
|
30618
|
-
}
|
|
30619
|
-
} else if (val && typeof val === "object") {
|
|
30620
|
-
Object.keys(val).forEach((m) => {
|
|
30621
|
-
f(m);
|
|
30622
|
-
});
|
|
30623
|
-
}
|
|
30624
|
-
};
|
|
30625
|
-
JSONPath.prototype._slice = function(loc, expr, val, path3, parent, parentPropName, callback) {
|
|
30626
|
-
if (!Array.isArray(val)) {
|
|
30627
|
-
return;
|
|
30628
|
-
}
|
|
30629
|
-
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
30630
|
-
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
30631
|
-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
30632
|
-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
30633
|
-
const ret = [];
|
|
30634
|
-
for (let i = start;i < end; i += step) {
|
|
30635
|
-
const tmp = this._trace(unshift(i, expr), val, path3, parent, parentPropName, callback, true);
|
|
30636
|
-
tmp.forEach((t) => {
|
|
30637
|
-
ret.push(t);
|
|
30638
|
-
});
|
|
30639
|
-
}
|
|
30640
|
-
return ret;
|
|
30641
|
-
};
|
|
30642
|
-
JSONPath.prototype._eval = function(code, _v, _vname, path3, parent, parentPropName) {
|
|
30643
|
-
this.currSandbox._$_parentProperty = parentPropName;
|
|
30644
|
-
this.currSandbox._$_parent = parent;
|
|
30645
|
-
this.currSandbox._$_property = _vname;
|
|
30646
|
-
this.currSandbox._$_root = this.json;
|
|
30647
|
-
this.currSandbox._$_v = _v;
|
|
30648
|
-
const containsPath = code.includes("@path");
|
|
30649
|
-
if (containsPath) {
|
|
30650
|
-
this.currSandbox._$_path = JSONPath.toPathString(path3.concat([_vname]));
|
|
30651
|
-
}
|
|
30652
|
-
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
30653
|
-
if (!JSONPath.cache[scriptCacheKey]) {
|
|
30654
|
-
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
30655
|
-
if (containsPath) {
|
|
30656
|
-
script = script.replaceAll("@path", "_$_path");
|
|
30657
|
-
}
|
|
30658
|
-
if (this.currEval === "safe" || this.currEval === true || this.currEval === undefined) {
|
|
30659
|
-
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
30660
|
-
} else if (this.currEval === "native") {
|
|
30661
|
-
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
30662
|
-
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
30663
|
-
const CurrEval = this.currEval;
|
|
30664
|
-
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
30665
|
-
} else if (typeof this.currEval === "function") {
|
|
30666
|
-
JSONPath.cache[scriptCacheKey] = {
|
|
30667
|
-
runInNewContext: (context) => this.currEval(script, context)
|
|
30668
|
-
};
|
|
30669
|
-
} else {
|
|
30670
|
-
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
29596
|
+
for (const [key, value] of Object.entries(cmd.opts())) {
|
|
29597
|
+
if (value !== undefined) {
|
|
29598
|
+
params[key] = value;
|
|
30671
29599
|
}
|
|
30672
29600
|
}
|
|
30673
|
-
|
|
30674
|
-
|
|
30675
|
-
|
|
30676
|
-
|
|
30677
|
-
|
|
29601
|
+
return params;
|
|
29602
|
+
}
|
|
29603
|
+
function deriveCommandPath(cmd) {
|
|
29604
|
+
const parts = [];
|
|
29605
|
+
let current = cmd;
|
|
29606
|
+
while (current) {
|
|
29607
|
+
const name = current.name();
|
|
29608
|
+
if (name) {
|
|
29609
|
+
parts.unshift(name);
|
|
30678
29610
|
}
|
|
30679
|
-
|
|
29611
|
+
current = current.parent;
|
|
30680
29612
|
}
|
|
30681
|
-
|
|
30682
|
-
|
|
30683
|
-
JSONPath.toPathString = function(pathArr) {
|
|
30684
|
-
const x = pathArr, n = x.length;
|
|
30685
|
-
let p = "$";
|
|
30686
|
-
for (let i = 1;i < n; i++) {
|
|
30687
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
30688
|
-
p += /^[0-9*]+$/u.test(x[i]) ? "[" + x[i] + "]" : "['" + x[i] + "']";
|
|
30689
|
-
}
|
|
29613
|
+
if (parts.length > 1) {
|
|
29614
|
+
parts.shift();
|
|
30690
29615
|
}
|
|
30691
|
-
return p;
|
|
30692
|
-
}
|
|
30693
|
-
|
|
30694
|
-
|
|
30695
|
-
|
|
30696
|
-
|
|
30697
|
-
|
|
30698
|
-
|
|
29616
|
+
return ["uip", ...parts.filter((p) => p !== "uip")].join(".");
|
|
29617
|
+
}
|
|
29618
|
+
function isCliErrorCode(value) {
|
|
29619
|
+
return typeof value === "string" && cliErrorCodeValues.has(value);
|
|
29620
|
+
}
|
|
29621
|
+
function isRetryHint(value) {
|
|
29622
|
+
return typeof value === "string" && retryHintValues.has(value);
|
|
29623
|
+
}
|
|
29624
|
+
function isErrorContext(value) {
|
|
29625
|
+
return value !== null && typeof value === "object";
|
|
29626
|
+
}
|
|
29627
|
+
function commandHelpHint(commandPath) {
|
|
29628
|
+
const command = commandPath.replace(/\./g, " ");
|
|
29629
|
+
return `An unexpected error occurred. Run '${command} --help' to verify command syntax, or run with --log-level debug for details.`;
|
|
29630
|
+
}
|
|
29631
|
+
Command.prototype.trackedAction = function(context, fn, properties) {
|
|
29632
|
+
const command = this;
|
|
29633
|
+
return this.action(async (...args) => {
|
|
29634
|
+
const telemetryName = deriveCommandPath(command);
|
|
29635
|
+
const props = typeof properties === "function" ? properties(...args) : properties;
|
|
29636
|
+
const startTime = performance.now();
|
|
29637
|
+
let errorMessage2;
|
|
29638
|
+
const [error] = await catchError2(fn(...args));
|
|
29639
|
+
if (error) {
|
|
29640
|
+
errorMessage2 = error instanceof Error ? error.message : String(error);
|
|
29641
|
+
logger.debug(`[trackedAction] ${telemetryName} failed: ${errorMessage2}`);
|
|
29642
|
+
const typed = error;
|
|
29643
|
+
const customInstructions = typeof typed.instructions === "string" ? typed.instructions : undefined;
|
|
29644
|
+
const customResult = typeof typed.result === "string" && typed.result !== RESULTS.Success && Object.values(RESULTS).includes(typed.result) ? typed.result : undefined;
|
|
29645
|
+
const finalResult = customResult ?? RESULTS.Failure;
|
|
29646
|
+
const typedErrorCode = typed.errorCode ?? typed.ErrorCode;
|
|
29647
|
+
const customErrorCode = isCliErrorCode(typedErrorCode) ? typedErrorCode : undefined;
|
|
29648
|
+
const typedRetry = typed.retry ?? typed.Retry;
|
|
29649
|
+
const customRetry = isRetryHint(typedRetry) ? typedRetry : undefined;
|
|
29650
|
+
const typedContext = typed.context ?? typed.Context;
|
|
29651
|
+
const customContext = isErrorContext(typedContext) ? typedContext : undefined;
|
|
29652
|
+
OutputFormatter.error({
|
|
29653
|
+
Result: finalResult,
|
|
29654
|
+
...customErrorCode ? { ErrorCode: customErrorCode } : {},
|
|
29655
|
+
Message: errorMessage2,
|
|
29656
|
+
Instructions: customInstructions ?? commandHelpHint(telemetryName),
|
|
29657
|
+
...customRetry ? { Retry: customRetry } : {},
|
|
29658
|
+
...customContext ? { Context: customContext } : {}
|
|
29659
|
+
});
|
|
29660
|
+
context.exit(EXIT_CODES[finalResult]);
|
|
30699
29661
|
}
|
|
30700
|
-
|
|
30701
|
-
|
|
30702
|
-
|
|
30703
|
-
|
|
30704
|
-
|
|
30705
|
-
|
|
30706
|
-
|
|
30707
|
-
|
|
30708
|
-
|
|
30709
|
-
|
|
30710
|
-
const subx = [];
|
|
30711
|
-
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
30712
|
-
return "[#" + (subx.push($1) - 1) + "]";
|
|
30713
|
-
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
30714
|
-
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
30715
|
-
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
30716
|
-
return ";" + ups.split("").join(";") + ";";
|
|
30717
|
-
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
30718
|
-
const exprList = normalized.split(";").map(function(exp) {
|
|
30719
|
-
const match = exp.match(/#(\d+)/u);
|
|
30720
|
-
return !match || !match[1] ? exp : subx[match[1]];
|
|
29662
|
+
const durationMs = performance.now() - startTime;
|
|
29663
|
+
const success = !error && (process.exitCode === undefined || process.exitCode === 0);
|
|
29664
|
+
telemetry.trackEvent(telemetryName, redactProperties({
|
|
29665
|
+
...extractCommandParams(command),
|
|
29666
|
+
...props,
|
|
29667
|
+
command: "true",
|
|
29668
|
+
duration: String(durationMs),
|
|
29669
|
+
success: String(success),
|
|
29670
|
+
...errorMessage2 ? { errorMessage: errorMessage2 } : {}
|
|
29671
|
+
}));
|
|
30721
29672
|
});
|
|
30722
|
-
cache[expr] = exprList;
|
|
30723
|
-
return cache[expr].concat();
|
|
30724
29673
|
};
|
|
30725
|
-
|
|
30726
|
-
|
|
30727
|
-
|
|
30728
|
-
|
|
29674
|
+
// ../../common/src/console-guard.ts
|
|
29675
|
+
var guardInstalledSlot = singleton("ConsoleGuardInstalled");
|
|
29676
|
+
var savedOriginalsSlot = singleton("ConsoleGuardOriginals");
|
|
29677
|
+
// ../../common/src/constants.ts
|
|
29678
|
+
var DEFAULT_AUTH_TIMEOUT_MS2 = 5 * 60 * 1000;
|
|
29679
|
+
// ../../common/src/interactivity-context.ts
|
|
29680
|
+
var modeSlot = singleton("InteractivityMode");
|
|
30729
29681
|
// ../../common/src/polling/types.ts
|
|
30730
29682
|
var PollOutcome = {
|
|
30731
29683
|
Completed: "completed",
|
|
@@ -30760,6 +29712,17 @@ var FAILURE_STATUSES = new Set([
|
|
|
30760
29712
|
"canceled",
|
|
30761
29713
|
"stopped"
|
|
30762
29714
|
]);
|
|
29715
|
+
// ../../common/src/preview.ts
|
|
29716
|
+
var previewSlot = singleton("PreviewBuild");
|
|
29717
|
+
function isPreviewBuild() {
|
|
29718
|
+
return previewSlot.get(false) ?? false;
|
|
29719
|
+
}
|
|
29720
|
+
Command.prototype.previewCommand = function(nameAndArgs, opts) {
|
|
29721
|
+
if (isPreviewBuild()) {
|
|
29722
|
+
return this.command(nameAndArgs, opts);
|
|
29723
|
+
}
|
|
29724
|
+
return new Command(nameAndArgs.split(/\s+/)[0] ?? nameAndArgs);
|
|
29725
|
+
};
|
|
30763
29726
|
// ../../common/src/screen-logger.ts
|
|
30764
29727
|
var ScreenLogger;
|
|
30765
29728
|
((ScreenLogger) => {
|
|
@@ -31024,7 +29987,7 @@ class VoidApiResponse2 {
|
|
|
31024
29987
|
var package_default3 = {
|
|
31025
29988
|
name: "@uipath/identity-sdk",
|
|
31026
29989
|
license: "MIT",
|
|
31027
|
-
version: "1.
|
|
29990
|
+
version: "1.197.0",
|
|
31028
29991
|
repository: {
|
|
31029
29992
|
type: "git",
|
|
31030
29993
|
url: "https://github.com/UiPath/cli.git",
|
|
@@ -31052,7 +30015,7 @@ var package_default3 = {
|
|
|
31052
30015
|
],
|
|
31053
30016
|
private: true,
|
|
31054
30017
|
scripts: {
|
|
31055
|
-
build: "bun build ./src/index.ts --outdir dist --format esm --target node && tsc -p tsconfig.build.json --noCheck",
|
|
30018
|
+
build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
|
|
31056
30019
|
generate: "bun run src/scripts/generate-sdk.ts",
|
|
31057
30020
|
lint: "biome check .",
|
|
31058
30021
|
test: "vitest run",
|
|
@@ -32343,12 +31306,12 @@ async function resolveIdentityToId(identity, options) {
|
|
|
32343
31306
|
const exact = users.find((u) => u.email?.toLowerCase() === lower2 || u.userName?.toLowerCase() === lower2);
|
|
32344
31307
|
if (exact?.id !== undefined && exact.id !== "")
|
|
32345
31308
|
return exact.id;
|
|
32346
|
-
const
|
|
31309
|
+
const preview2 = users.slice(0, 5).map(formatCandidate).join("; ");
|
|
32347
31310
|
const more = users.length > 5 ? `; ... (+${users.length - 5} more)` : "";
|
|
32348
31311
|
OutputFormatter.error({
|
|
32349
31312
|
Result: RESULTS.Failure,
|
|
32350
31313
|
Message: `Multiple users matched '${identity}'. Pass a UUID or a more specific value.`,
|
|
32351
|
-
Instructions: `Candidates: ${
|
|
31314
|
+
Instructions: `Candidates: ${preview2}${more}.`
|
|
32352
31315
|
});
|
|
32353
31316
|
processContext.exit(1);
|
|
32354
31317
|
return null;
|
|
@@ -33488,3 +32451,5 @@ var program2 = new Command;
|
|
|
33488
32451
|
program2.name(metadata.commandPrefix).description(metadata.description).version(metadata.version);
|
|
33489
32452
|
await registerCommands(program2);
|
|
33490
32453
|
program2.parse(process.argv);
|
|
32454
|
+
|
|
32455
|
+
//# debugId=C22AF885DF62A80364756E2164756E21
|