@uipath/admin-vpngateway-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 +704 -1729
- package/dist/tool.js +705 -1729
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2145,7 +2145,7 @@ var {
|
|
|
2145
2145
|
var package_default = {
|
|
2146
2146
|
name: "@uipath/admin-vpngateway-tool",
|
|
2147
2147
|
license: "MIT",
|
|
2148
|
-
version: "1.
|
|
2148
|
+
version: "1.197.0-preview.59",
|
|
2149
2149
|
description: "CLI plugin for UiPath VPN Gateway management (Hypervisor service).",
|
|
2150
2150
|
private: false,
|
|
2151
2151
|
repository: {
|
|
@@ -2156,7 +2156,9 @@ var package_default = {
|
|
|
2156
2156
|
publishConfig: {
|
|
2157
2157
|
registry: "https://npm.pkg.github.com/@uipath"
|
|
2158
2158
|
},
|
|
2159
|
-
keywords: [
|
|
2159
|
+
keywords: [
|
|
2160
|
+
"cli-tool"
|
|
2161
|
+
],
|
|
2160
2162
|
type: "module",
|
|
2161
2163
|
main: "./dist/tool.js",
|
|
2162
2164
|
exports: {
|
|
@@ -2165,9 +2167,11 @@ var package_default = {
|
|
|
2165
2167
|
bin: {
|
|
2166
2168
|
"admin-vpngateway-tool": "./dist/index.js"
|
|
2167
2169
|
},
|
|
2168
|
-
files: [
|
|
2170
|
+
files: [
|
|
2171
|
+
"dist"
|
|
2172
|
+
],
|
|
2169
2173
|
scripts: {
|
|
2170
|
-
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",
|
|
2174
|
+
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",
|
|
2171
2175
|
package: "bun run build && bun pm pack",
|
|
2172
2176
|
lint: "biome check .",
|
|
2173
2177
|
"lint:fix": "biome check --write .",
|
|
@@ -20949,6 +20953,7 @@ function singleton(ctorOrName) {
|
|
|
20949
20953
|
}
|
|
20950
20954
|
};
|
|
20951
20955
|
}
|
|
20956
|
+
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
20952
20957
|
var USER_AGENT_HEADER = "User-Agent";
|
|
20953
20958
|
var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
|
|
20954
20959
|
function userAgentPatchKey(userAgent) {
|
|
@@ -20971,8 +20976,8 @@ function appendUserAgentToken(value, userAgent) {
|
|
|
20971
20976
|
function getEffectiveUserAgent(userAgent) {
|
|
20972
20977
|
return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
|
|
20973
20978
|
}
|
|
20974
|
-
function
|
|
20975
|
-
return
|
|
20979
|
+
function getHeaderName(headers, headerName) {
|
|
20980
|
+
return Object.keys(headers).find((key) => key.toLowerCase() === headerName.toLowerCase());
|
|
20976
20981
|
}
|
|
20977
20982
|
function getSdkUserAgentToken(pkg) {
|
|
20978
20983
|
const packageName = pkg.name.replace(/^@uipath\//, "");
|
|
@@ -20980,59 +20985,31 @@ function getSdkUserAgentToken(pkg) {
|
|
|
20980
20985
|
}
|
|
20981
20986
|
function addSdkUserAgentHeader(headers, userAgent) {
|
|
20982
20987
|
const result = { ...headers ?? {} };
|
|
20983
|
-
const
|
|
20984
|
-
|
|
20985
|
-
if (headerName) {
|
|
20986
|
-
result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
|
|
20987
|
-
} else {
|
|
20988
|
-
result[USER_AGENT_HEADER] = effectiveUserAgent;
|
|
20989
|
-
}
|
|
20988
|
+
const headerName = getHeaderName(result, USER_AGENT_HEADER);
|
|
20989
|
+
result[headerName ?? USER_AGENT_HEADER] = appendUserAgentToken(headerName ? result[headerName] : undefined, getEffectiveUserAgent(userAgent));
|
|
20990
20990
|
return result;
|
|
20991
20991
|
}
|
|
20992
|
-
function
|
|
20993
|
-
|
|
20994
|
-
if (isHeadersLike(headers)) {
|
|
20995
|
-
headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
|
|
20996
|
-
return headers;
|
|
20997
|
-
}
|
|
20998
|
-
if (Array.isArray(headers)) {
|
|
20999
|
-
const result = headers.map((entry) => {
|
|
21000
|
-
const [key, value] = entry;
|
|
21001
|
-
return [key, value];
|
|
21002
|
-
});
|
|
21003
|
-
const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
|
|
21004
|
-
if (headerIndex >= 0) {
|
|
21005
|
-
const [key, value] = result[headerIndex];
|
|
21006
|
-
result[headerIndex] = [
|
|
21007
|
-
key,
|
|
21008
|
-
appendUserAgentToken(value, effectiveUserAgent)
|
|
21009
|
-
];
|
|
21010
|
-
} else {
|
|
21011
|
-
result.push([USER_AGENT_HEADER, effectiveUserAgent]);
|
|
21012
|
-
}
|
|
21013
|
-
return result;
|
|
21014
|
-
}
|
|
21015
|
-
return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
|
|
20992
|
+
function asHeaderRecord(headers) {
|
|
20993
|
+
return typeof headers === "object" && headers !== null ? { ...headers } : {};
|
|
21016
20994
|
}
|
|
21017
|
-
function
|
|
20995
|
+
function withForwardedHeadersInitOverride(initOverrides, forward) {
|
|
21018
20996
|
return async (requestContext) => {
|
|
21019
|
-
const
|
|
20997
|
+
const initWithHeaders = {
|
|
21020
20998
|
...requestContext.init,
|
|
21021
|
-
headers:
|
|
20999
|
+
headers: forward(asHeaderRecord(requestContext.init.headers))
|
|
21022
21000
|
};
|
|
21023
21001
|
const override = typeof initOverrides === "function" ? await initOverrides({
|
|
21024
21002
|
...requestContext,
|
|
21025
|
-
init:
|
|
21003
|
+
init: initWithHeaders
|
|
21026
21004
|
}) : initOverrides;
|
|
21027
21005
|
return {
|
|
21028
21006
|
...override ?? {},
|
|
21029
|
-
headers:
|
|
21007
|
+
headers: forward(asHeaderRecord(override?.headers ?? initWithHeaders.headers))
|
|
21030
21008
|
};
|
|
21031
21009
|
};
|
|
21032
21010
|
}
|
|
21033
|
-
function
|
|
21011
|
+
function installRequestHeaderForwarding(BaseApiClass, patchKey, forward) {
|
|
21034
21012
|
const prototype = BaseApiClass.prototype;
|
|
21035
|
-
const patchKey = userAgentPatchKey(userAgent);
|
|
21036
21013
|
if (prototype[patchKey]) {
|
|
21037
21014
|
return;
|
|
21038
21015
|
}
|
|
@@ -21040,13 +21017,16 @@ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
|
21040
21017
|
throw new Error("Generated BaseAPI request function not found.");
|
|
21041
21018
|
}
|
|
21042
21019
|
const originalRequest = prototype.request;
|
|
21043
|
-
prototype.request = function
|
|
21044
|
-
return originalRequest.call(this, context,
|
|
21020
|
+
prototype.request = function requestWithForwardedHeaders(context, initOverrides) {
|
|
21021
|
+
return originalRequest.call(this, context, withForwardedHeadersInitOverride(initOverrides, forward));
|
|
21045
21022
|
};
|
|
21046
21023
|
Object.defineProperty(prototype, patchKey, {
|
|
21047
21024
|
value: true
|
|
21048
21025
|
});
|
|
21049
21026
|
}
|
|
21027
|
+
function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
21028
|
+
installRequestHeaderForwarding(BaseApiClass, userAgentPatchKey(userAgent), (headers) => addSdkUserAgentHeader(headers, userAgent));
|
|
21029
|
+
}
|
|
21050
21030
|
var BASE_PATH = "http://localhost".replace(/\/+$/, "");
|
|
21051
21031
|
|
|
21052
21032
|
class Configuration {
|
|
@@ -21298,7 +21278,7 @@ class VoidApiResponse {
|
|
|
21298
21278
|
var package_default2 = {
|
|
21299
21279
|
name: "@uipath/admin-vpngateway-sdk",
|
|
21300
21280
|
license: "MIT",
|
|
21301
|
-
version: "1.
|
|
21281
|
+
version: "1.197.0",
|
|
21302
21282
|
description: "SDK for the UiPath Hypervisor VPN Gateway management APIs.",
|
|
21303
21283
|
repository: {
|
|
21304
21284
|
type: "git",
|
|
@@ -21308,7 +21288,12 @@ var package_default2 = {
|
|
|
21308
21288
|
publishConfig: {
|
|
21309
21289
|
registry: "https://npm.pkg.github.com/@uipath"
|
|
21310
21290
|
},
|
|
21311
|
-
keywords: [
|
|
21291
|
+
keywords: [
|
|
21292
|
+
"uipath",
|
|
21293
|
+
"vpn-gateway",
|
|
21294
|
+
"hypervisor",
|
|
21295
|
+
"sdk"
|
|
21296
|
+
],
|
|
21312
21297
|
type: "module",
|
|
21313
21298
|
main: "./dist/index.js",
|
|
21314
21299
|
types: "./dist/src/index.d.ts",
|
|
@@ -21318,10 +21303,12 @@ var package_default2 = {
|
|
|
21318
21303
|
default: "./dist/index.js"
|
|
21319
21304
|
}
|
|
21320
21305
|
},
|
|
21321
|
-
files: [
|
|
21306
|
+
files: [
|
|
21307
|
+
"dist"
|
|
21308
|
+
],
|
|
21322
21309
|
private: true,
|
|
21323
21310
|
scripts: {
|
|
21324
|
-
build: "bun build ./src/index.ts --outdir dist --format esm --target node && tsc -p tsconfig.build.json --noCheck",
|
|
21311
|
+
build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
|
|
21325
21312
|
generate: "bun run src/scripts/generate-sdk.ts",
|
|
21326
21313
|
lint: "biome check ."
|
|
21327
21314
|
},
|
|
@@ -22050,6 +22037,12 @@ var normalizeAndValidateBaseUrl = (rawUrl) => {
|
|
|
22050
22037
|
}
|
|
22051
22038
|
return url.pathname.length > 1 ? url.origin : baseUrl;
|
|
22052
22039
|
};
|
|
22040
|
+
var resolveScopes = (isExternalAppAuth, customScopes, fileScopes) => {
|
|
22041
|
+
const requestedScopes = customScopes?.length ? customScopes : fileScopes ?? [];
|
|
22042
|
+
if (isExternalAppAuth)
|
|
22043
|
+
return requestedScopes;
|
|
22044
|
+
return [...new Set([...DEFAULT_SCOPES, ...requestedScopes])];
|
|
22045
|
+
};
|
|
22053
22046
|
var resolveConfigAsync = async ({
|
|
22054
22047
|
customAuthority,
|
|
22055
22048
|
customClientId,
|
|
@@ -22080,7 +22073,7 @@ var resolveConfigAsync = async ({
|
|
|
22080
22073
|
clientSecret = fileAuth.clientSecret;
|
|
22081
22074
|
}
|
|
22082
22075
|
const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && Boolean(clientSecret);
|
|
22083
|
-
const scopes =
|
|
22076
|
+
const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
|
|
22084
22077
|
return {
|
|
22085
22078
|
clientId,
|
|
22086
22079
|
clientSecret,
|
|
@@ -22092,6 +22085,74 @@ var resolveConfigAsync = async ({
|
|
|
22092
22085
|
};
|
|
22093
22086
|
init_constants();
|
|
22094
22087
|
init_src();
|
|
22088
|
+
init_src();
|
|
22089
|
+
init_constants();
|
|
22090
|
+
var DEFAULT_AUTH_PROFILE = "default";
|
|
22091
|
+
var PROFILE_DIR = "profiles";
|
|
22092
|
+
var PROFILE_NAME_RE = /^[A-Za-z0-9._-]+$/;
|
|
22093
|
+
var ACTIVE_AUTH_PROFILE_KEY = Symbol.for("@uipath/auth/ActiveAuthProfile");
|
|
22094
|
+
var AUTH_PROFILE_STORAGE_KEY = Symbol.for("@uipath/auth/ProfileStorage");
|
|
22095
|
+
var globalSlot2 = globalThis;
|
|
22096
|
+
function isAuthProfileStorage(value) {
|
|
22097
|
+
return value !== null && typeof value === "object" && "getStore" in value && "run" in value;
|
|
22098
|
+
}
|
|
22099
|
+
function createProfileStorage() {
|
|
22100
|
+
const [error, mod] = catchError(() => __require2("node:async_hooks"));
|
|
22101
|
+
if (error || typeof mod?.AsyncLocalStorage !== "function") {
|
|
22102
|
+
return {
|
|
22103
|
+
getStore: () => {
|
|
22104
|
+
return;
|
|
22105
|
+
},
|
|
22106
|
+
run: (_store, fn) => fn()
|
|
22107
|
+
};
|
|
22108
|
+
}
|
|
22109
|
+
return new mod.AsyncLocalStorage;
|
|
22110
|
+
}
|
|
22111
|
+
function getProfileStorage() {
|
|
22112
|
+
const existing = globalSlot2[AUTH_PROFILE_STORAGE_KEY];
|
|
22113
|
+
if (isAuthProfileStorage(existing)) {
|
|
22114
|
+
return existing;
|
|
22115
|
+
}
|
|
22116
|
+
const storage = createProfileStorage();
|
|
22117
|
+
globalSlot2[AUTH_PROFILE_STORAGE_KEY] = storage;
|
|
22118
|
+
return storage;
|
|
22119
|
+
}
|
|
22120
|
+
var profileStorage = getProfileStorage();
|
|
22121
|
+
|
|
22122
|
+
class AuthProfileValidationError extends Error {
|
|
22123
|
+
constructor(message) {
|
|
22124
|
+
super(message);
|
|
22125
|
+
this.name = "AuthProfileValidationError";
|
|
22126
|
+
}
|
|
22127
|
+
}
|
|
22128
|
+
function normalizeAuthProfileName(profile) {
|
|
22129
|
+
if (profile === undefined || profile === DEFAULT_AUTH_PROFILE) {
|
|
22130
|
+
return;
|
|
22131
|
+
}
|
|
22132
|
+
if (profile.length === 0 || profile === "." || profile === ".." || !PROFILE_NAME_RE.test(profile)) {
|
|
22133
|
+
throw new AuthProfileValidationError(`Invalid profile name "${profile}". Profile names may contain only letters, numbers, '.', '_', and '-'.`);
|
|
22134
|
+
}
|
|
22135
|
+
return profile;
|
|
22136
|
+
}
|
|
22137
|
+
function getActiveAuthProfile() {
|
|
22138
|
+
const scopedState = profileStorage.getStore();
|
|
22139
|
+
if (scopedState !== undefined) {
|
|
22140
|
+
return scopedState.profile;
|
|
22141
|
+
}
|
|
22142
|
+
return globalSlot2[ACTIVE_AUTH_PROFILE_KEY]?.profile;
|
|
22143
|
+
}
|
|
22144
|
+
function resolveAuthProfileFilePath(profile) {
|
|
22145
|
+
const normalized = normalizeAuthProfileName(profile);
|
|
22146
|
+
if (normalized === undefined) {
|
|
22147
|
+
throw new AuthProfileValidationError(`"${DEFAULT_AUTH_PROFILE}" is the built-in profile and does not have a profile file path.`);
|
|
22148
|
+
}
|
|
22149
|
+
const fs7 = getFileSystem();
|
|
22150
|
+
return fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR, normalized, AUTH_FILENAME);
|
|
22151
|
+
}
|
|
22152
|
+
function getActiveAuthProfileFilePath() {
|
|
22153
|
+
const profile = getActiveAuthProfile();
|
|
22154
|
+
return profile ? resolveAuthProfileFilePath(profile) : undefined;
|
|
22155
|
+
}
|
|
22095
22156
|
|
|
22096
22157
|
class InvalidIssuerError extends Error {
|
|
22097
22158
|
expected;
|
|
@@ -22218,21 +22279,70 @@ var readAuthFromEnv = () => {
|
|
|
22218
22279
|
organizationId,
|
|
22219
22280
|
tenantName,
|
|
22220
22281
|
tenantId,
|
|
22221
|
-
expiration
|
|
22282
|
+
expiration,
|
|
22283
|
+
source: "env"
|
|
22222
22284
|
};
|
|
22223
22285
|
};
|
|
22224
22286
|
init_src();
|
|
22287
|
+
var BREAKER_SUFFIX = ".refresh-state";
|
|
22288
|
+
var BACKOFF_BASE_MS = 60000;
|
|
22289
|
+
var BACKOFF_CAP_MS = 60 * 60 * 1000;
|
|
22290
|
+
var SURFACE_WINDOW_MS = 60 * 60 * 1000;
|
|
22291
|
+
async function refreshTokenFingerprint(refreshToken) {
|
|
22292
|
+
const bytes = new TextEncoder().encode(refreshToken);
|
|
22293
|
+
if (globalThis.crypto?.subtle) {
|
|
22294
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
22295
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
22296
|
+
}
|
|
22297
|
+
const { createHash } = await import("node:crypto");
|
|
22298
|
+
return createHash("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
22299
|
+
}
|
|
22300
|
+
function breakerPathFor(authPath) {
|
|
22301
|
+
return `${authPath}${BREAKER_SUFFIX}`;
|
|
22302
|
+
}
|
|
22303
|
+
async function loadRefreshBreaker(authPath) {
|
|
22304
|
+
const fs7 = getFileSystem();
|
|
22305
|
+
try {
|
|
22306
|
+
const content = await fs7.readFile(breakerPathFor(authPath), "utf-8");
|
|
22307
|
+
if (!content)
|
|
22308
|
+
return {};
|
|
22309
|
+
const parsed = JSON.parse(content);
|
|
22310
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
22311
|
+
} catch {
|
|
22312
|
+
return {};
|
|
22313
|
+
}
|
|
22314
|
+
}
|
|
22315
|
+
async function saveRefreshBreaker(authPath, state) {
|
|
22316
|
+
try {
|
|
22317
|
+
const fs7 = getFileSystem();
|
|
22318
|
+
const path3 = breakerPathFor(authPath);
|
|
22319
|
+
await fs7.mkdir(fs7.path.dirname(path3));
|
|
22320
|
+
const tempPath = `${path3}.tmp`;
|
|
22321
|
+
await fs7.writeFile(tempPath, JSON.stringify(state));
|
|
22322
|
+
await fs7.rename(tempPath, path3);
|
|
22323
|
+
} catch {}
|
|
22324
|
+
}
|
|
22325
|
+
async function clearRefreshBreaker(authPath) {
|
|
22326
|
+
const fs7 = getFileSystem();
|
|
22327
|
+
const path3 = breakerPathFor(authPath);
|
|
22328
|
+
try {
|
|
22329
|
+
if (await fs7.exists(path3)) {
|
|
22330
|
+
await fs7.rm(path3);
|
|
22331
|
+
}
|
|
22332
|
+
} catch {}
|
|
22333
|
+
}
|
|
22334
|
+
function nextBackoffMs(attempts) {
|
|
22335
|
+
const shift = Math.max(0, attempts - 1);
|
|
22336
|
+
return Math.min(BACKOFF_BASE_MS * 2 ** shift, BACKOFF_CAP_MS);
|
|
22337
|
+
}
|
|
22338
|
+
function shouldSurface(state, nowMs) {
|
|
22339
|
+
if (state.lastSurfacedAtMs === undefined)
|
|
22340
|
+
return true;
|
|
22341
|
+
return nowMs - state.lastSurfacedAtMs >= SURFACE_WINDOW_MS;
|
|
22342
|
+
}
|
|
22343
|
+
init_src();
|
|
22225
22344
|
var DEFAULT_TIMEOUT_MS = 1000;
|
|
22226
22345
|
var CLOSE_TIMEOUT_MS = 500;
|
|
22227
|
-
var NOTICE_SENTINEL = Symbol.for("@uipath/auth/robotFallbackNoticePrinted");
|
|
22228
|
-
var printNoticeOnce = () => {
|
|
22229
|
-
const slot = globalThis;
|
|
22230
|
-
if (slot[NOTICE_SENTINEL])
|
|
22231
|
-
return;
|
|
22232
|
-
slot[NOTICE_SENTINEL] = true;
|
|
22233
|
-
catchError(() => process.stderr.write(`Using UiPath Robot credentials. Run 'uip login' for a dedicated session.
|
|
22234
|
-
`));
|
|
22235
|
-
};
|
|
22236
22346
|
var ROBOT_USER_SERVICES_PIPE = "UiPathUserServices";
|
|
22237
22347
|
var ROBOT_USER_SERVICES_ALTERNATE_PIPE = `${ROBOT_USER_SERVICES_PIPE}Alternate`;
|
|
22238
22348
|
var PIPE_NAME_MAX_LENGTH = 103;
|
|
@@ -22348,7 +22458,6 @@ var tryRobotClientFallback = async (options = {}) => {
|
|
|
22348
22458
|
issuerFromToken = issClaim;
|
|
22349
22459
|
}
|
|
22350
22460
|
}
|
|
22351
|
-
printNoticeOnce();
|
|
22352
22461
|
return {
|
|
22353
22462
|
accessToken,
|
|
22354
22463
|
baseUrl: parsedUrl.baseUrl,
|
|
@@ -22567,18 +22676,327 @@ var saveEnvFileAsync = async ({
|
|
|
22567
22676
|
await fs7.writeFile(tempPath, content);
|
|
22568
22677
|
await fs7.rename(tempPath, absolutePath);
|
|
22569
22678
|
};
|
|
22570
|
-
|
|
22571
|
-
return
|
|
22679
|
+
var getLoginStatusAsync = async (options = {}) => {
|
|
22680
|
+
return getLoginStatusWithDeps(options);
|
|
22681
|
+
};
|
|
22682
|
+
var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
|
|
22683
|
+
const {
|
|
22684
|
+
resolveEnvFilePath = resolveEnvFilePathAsync,
|
|
22685
|
+
loadEnvFile = loadEnvFileAsync,
|
|
22686
|
+
saveEnvFile = saveEnvFileAsync,
|
|
22687
|
+
getFs = getFileSystem,
|
|
22688
|
+
refreshToken: refreshTokenFn = refreshAccessToken,
|
|
22689
|
+
resolveConfig = resolveConfigAsync,
|
|
22690
|
+
robotFallback = tryRobotClientFallback,
|
|
22691
|
+
loadBreaker = loadRefreshBreaker,
|
|
22692
|
+
saveBreaker = saveRefreshBreaker,
|
|
22693
|
+
clearBreaker = clearRefreshBreaker
|
|
22694
|
+
} = deps;
|
|
22695
|
+
if (isRobotAuthEnforced()) {
|
|
22696
|
+
return resolveRobotEnforcedStatus(robotFallback);
|
|
22697
|
+
}
|
|
22698
|
+
if (isEnvAuthEnabled()) {
|
|
22699
|
+
return readAuthFromEnv();
|
|
22700
|
+
}
|
|
22701
|
+
const activeProfile = getActiveAuthProfile();
|
|
22702
|
+
const activeProfileFilePath = getActiveAuthProfileFilePath();
|
|
22703
|
+
const usingActiveProfile = activeProfile !== undefined && (options.envFilePath === undefined || options.envFilePath === activeProfileFilePath);
|
|
22704
|
+
const envFilePath = options.envFilePath ?? activeProfileFilePath ?? DEFAULT_ENV_FILENAME;
|
|
22705
|
+
const { ensureTokenValidityMinutes } = options;
|
|
22706
|
+
const { absolutePath } = await resolveEnvFilePath(envFilePath);
|
|
22707
|
+
if (absolutePath === undefined) {
|
|
22708
|
+
if (usingActiveProfile) {
|
|
22709
|
+
return {
|
|
22710
|
+
loginStatus: "Not logged in",
|
|
22711
|
+
hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
|
|
22712
|
+
};
|
|
22713
|
+
}
|
|
22714
|
+
return resolveBorrowedRobotStatus(robotFallback);
|
|
22715
|
+
}
|
|
22716
|
+
const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
|
|
22717
|
+
if ("status" in loaded) {
|
|
22718
|
+
return loaded.status;
|
|
22719
|
+
}
|
|
22720
|
+
const { credentials } = loaded;
|
|
22721
|
+
const globalHint = () => usingActiveProfile ? Promise.resolve(undefined) : getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath);
|
|
22722
|
+
const expiration = getTokenExpiration(credentials.UIPATH_ACCESS_TOKEN);
|
|
22723
|
+
const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
22724
|
+
let tokens = {
|
|
22725
|
+
accessToken: credentials.UIPATH_ACCESS_TOKEN,
|
|
22726
|
+
refreshToken: credentials.UIPATH_REFRESH_TOKEN,
|
|
22727
|
+
expiration,
|
|
22728
|
+
lockReleaseFailed: false
|
|
22729
|
+
};
|
|
22730
|
+
const refreshToken = credentials.UIPATH_REFRESH_TOKEN;
|
|
22731
|
+
if (expiration && expiration <= outerThreshold && refreshToken) {
|
|
22732
|
+
const refreshed = await attemptRefresh({
|
|
22733
|
+
absolutePath,
|
|
22734
|
+
credentials,
|
|
22735
|
+
accessToken: credentials.UIPATH_ACCESS_TOKEN,
|
|
22736
|
+
refreshToken,
|
|
22737
|
+
expiration,
|
|
22738
|
+
ensureTokenValidityMinutes,
|
|
22739
|
+
getFs,
|
|
22740
|
+
loadEnvFile,
|
|
22741
|
+
saveEnvFile,
|
|
22742
|
+
refreshFn: refreshTokenFn,
|
|
22743
|
+
resolveConfig,
|
|
22744
|
+
loadBreaker,
|
|
22745
|
+
saveBreaker,
|
|
22746
|
+
clearBreaker,
|
|
22747
|
+
globalHint
|
|
22748
|
+
});
|
|
22749
|
+
if (refreshed.kind === "terminal") {
|
|
22750
|
+
return refreshed.status;
|
|
22751
|
+
}
|
|
22752
|
+
tokens = refreshed.tokens;
|
|
22753
|
+
}
|
|
22754
|
+
return buildFileStatus(tokens, credentials, globalHint);
|
|
22755
|
+
};
|
|
22756
|
+
async function resolveRobotEnforcedStatus(robotFallback) {
|
|
22757
|
+
if (isEnvAuthEnabled()) {
|
|
22758
|
+
throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true are mutually exclusive. Unset one of them and re-run.`);
|
|
22759
|
+
}
|
|
22760
|
+
const robotCreds = await robotFallback({ force: true });
|
|
22761
|
+
if (!robotCreds) {
|
|
22762
|
+
return {
|
|
22763
|
+
loginStatus: "Not logged in",
|
|
22764
|
+
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.`
|
|
22765
|
+
};
|
|
22766
|
+
}
|
|
22767
|
+
return buildRobotStatus(robotCreds);
|
|
22572
22768
|
}
|
|
22573
|
-
function
|
|
22574
|
-
|
|
22769
|
+
async function resolveBorrowedRobotStatus(robotFallback) {
|
|
22770
|
+
const robotCreds = await robotFallback();
|
|
22771
|
+
return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
|
|
22575
22772
|
}
|
|
22576
|
-
function
|
|
22577
|
-
|
|
22773
|
+
async function loadFileCredentials(loadEnvFile, absolutePath) {
|
|
22774
|
+
let credentials;
|
|
22775
|
+
try {
|
|
22776
|
+
credentials = await loadEnvFile({ envPath: absolutePath });
|
|
22777
|
+
} catch (error) {
|
|
22778
|
+
if (isFileNotFoundError(error)) {
|
|
22779
|
+
return { status: { loginStatus: "Not logged in" } };
|
|
22780
|
+
}
|
|
22781
|
+
throw error;
|
|
22782
|
+
}
|
|
22783
|
+
if (!credentials.UIPATH_ACCESS_TOKEN) {
|
|
22784
|
+
return { status: { loginStatus: "Not logged in" } };
|
|
22785
|
+
}
|
|
22786
|
+
return { credentials };
|
|
22787
|
+
}
|
|
22788
|
+
async function getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath) {
|
|
22789
|
+
const fs7 = getFs();
|
|
22790
|
+
const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
|
|
22791
|
+
if (absolutePath === globalPath)
|
|
22792
|
+
return;
|
|
22793
|
+
if (!await fs7.exists(globalPath))
|
|
22794
|
+
return;
|
|
22795
|
+
try {
|
|
22796
|
+
const globalCreds = await loadEnvFile({ envPath: globalPath });
|
|
22797
|
+
if (!globalCreds.UIPATH_ACCESS_TOKEN)
|
|
22798
|
+
return;
|
|
22799
|
+
const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
|
|
22800
|
+
if (globalExp && globalExp <= new Date)
|
|
22801
|
+
return;
|
|
22802
|
+
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.`;
|
|
22803
|
+
} catch {
|
|
22804
|
+
return;
|
|
22805
|
+
}
|
|
22578
22806
|
}
|
|
22579
22807
|
function computeExpirationThreshold(ensureTokenValidityMinutes) {
|
|
22580
22808
|
return new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
|
|
22581
22809
|
}
|
|
22810
|
+
async function attemptRefresh(ctx) {
|
|
22811
|
+
const shortCircuit = await circuitBreakerShortCircuit(ctx);
|
|
22812
|
+
if (shortCircuit) {
|
|
22813
|
+
return { kind: "terminal", status: shortCircuit };
|
|
22814
|
+
}
|
|
22815
|
+
let release;
|
|
22816
|
+
try {
|
|
22817
|
+
release = await ctx.getFs().acquireLock(ctx.absolutePath);
|
|
22818
|
+
} catch (error) {
|
|
22819
|
+
return {
|
|
22820
|
+
kind: "terminal",
|
|
22821
|
+
status: await lockAcquireFailureStatus(ctx, error)
|
|
22822
|
+
};
|
|
22823
|
+
}
|
|
22824
|
+
let lockedFailure;
|
|
22825
|
+
let lockReleaseFailed = false;
|
|
22826
|
+
let success;
|
|
22827
|
+
try {
|
|
22828
|
+
const outcome = await runRefreshLocked({
|
|
22829
|
+
absolutePath: ctx.absolutePath,
|
|
22830
|
+
refreshToken: ctx.refreshToken,
|
|
22831
|
+
customAuthority: ctx.credentials.UIPATH_URL,
|
|
22832
|
+
ensureTokenValidityMinutes: ctx.ensureTokenValidityMinutes,
|
|
22833
|
+
loadEnvFile: ctx.loadEnvFile,
|
|
22834
|
+
saveEnvFile: ctx.saveEnvFile,
|
|
22835
|
+
refreshFn: ctx.refreshFn,
|
|
22836
|
+
resolveConfig: ctx.resolveConfig,
|
|
22837
|
+
loadBreaker: ctx.loadBreaker,
|
|
22838
|
+
saveBreaker: ctx.saveBreaker,
|
|
22839
|
+
clearBreaker: ctx.clearBreaker
|
|
22840
|
+
});
|
|
22841
|
+
if (outcome.kind === "fail") {
|
|
22842
|
+
lockedFailure = outcome.status;
|
|
22843
|
+
} else {
|
|
22844
|
+
success = outcome;
|
|
22845
|
+
}
|
|
22846
|
+
} finally {
|
|
22847
|
+
try {
|
|
22848
|
+
await release();
|
|
22849
|
+
} catch {
|
|
22850
|
+
lockReleaseFailed = true;
|
|
22851
|
+
}
|
|
22852
|
+
}
|
|
22853
|
+
if (lockedFailure) {
|
|
22854
|
+
const globalHint = await ctx.globalHint();
|
|
22855
|
+
const base = globalHint ? { ...lockedFailure, loginStatus: "Expired", hint: globalHint } : lockedFailure;
|
|
22856
|
+
return {
|
|
22857
|
+
kind: "terminal",
|
|
22858
|
+
status: lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base
|
|
22859
|
+
};
|
|
22860
|
+
}
|
|
22861
|
+
return {
|
|
22862
|
+
kind: "refreshed",
|
|
22863
|
+
tokens: {
|
|
22864
|
+
accessToken: success?.accessToken,
|
|
22865
|
+
refreshToken: success?.refreshToken,
|
|
22866
|
+
expiration: success?.expiration,
|
|
22867
|
+
tokenRefresh: success?.tokenRefresh,
|
|
22868
|
+
persistenceWarning: success?.persistenceWarning,
|
|
22869
|
+
lockReleaseFailed
|
|
22870
|
+
}
|
|
22871
|
+
};
|
|
22872
|
+
}
|
|
22873
|
+
async function buildFileStatus(tokens, credentials, globalHint) {
|
|
22874
|
+
const result = {
|
|
22875
|
+
loginStatus: tokens.expiration && tokens.expiration <= new Date ? "Expired" : "Logged in",
|
|
22876
|
+
accessToken: tokens.accessToken,
|
|
22877
|
+
refreshToken: tokens.refreshToken,
|
|
22878
|
+
baseUrl: credentials.UIPATH_URL,
|
|
22879
|
+
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22880
|
+
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22881
|
+
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22882
|
+
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22883
|
+
expiration: tokens.expiration,
|
|
22884
|
+
source: "file",
|
|
22885
|
+
...tokens.persistenceWarning ? { hint: tokens.persistenceWarning, persistenceFailed: true } : {},
|
|
22886
|
+
...tokens.lockReleaseFailed ? { lockReleaseFailed: true } : {},
|
|
22887
|
+
...tokens.tokenRefresh ? { tokenRefresh: tokens.tokenRefresh } : {}
|
|
22888
|
+
};
|
|
22889
|
+
if (result.loginStatus === "Expired") {
|
|
22890
|
+
const hint = await globalHint();
|
|
22891
|
+
if (hint) {
|
|
22892
|
+
result.hint = hint;
|
|
22893
|
+
}
|
|
22894
|
+
}
|
|
22895
|
+
return result;
|
|
22896
|
+
}
|
|
22897
|
+
function buildRobotStatus(robotCreds) {
|
|
22898
|
+
return {
|
|
22899
|
+
loginStatus: "Logged in",
|
|
22900
|
+
accessToken: robotCreds.accessToken,
|
|
22901
|
+
baseUrl: robotCreds.baseUrl,
|
|
22902
|
+
organizationName: robotCreds.organizationName,
|
|
22903
|
+
organizationId: robotCreds.organizationId,
|
|
22904
|
+
tenantName: robotCreds.tenantName,
|
|
22905
|
+
tenantId: robotCreds.tenantId,
|
|
22906
|
+
issuer: robotCreds.issuer,
|
|
22907
|
+
expiration: getTokenExpiration(robotCreds.accessToken),
|
|
22908
|
+
source: "robot"
|
|
22909
|
+
};
|
|
22910
|
+
}
|
|
22911
|
+
var isFileNotFoundError = (error) => {
|
|
22912
|
+
if (!(error instanceof Object))
|
|
22913
|
+
return false;
|
|
22914
|
+
return error.code === "ENOENT";
|
|
22915
|
+
};
|
|
22916
|
+
async function circuitBreakerShortCircuit(ctx) {
|
|
22917
|
+
const {
|
|
22918
|
+
absolutePath,
|
|
22919
|
+
refreshToken,
|
|
22920
|
+
accessToken,
|
|
22921
|
+
credentials,
|
|
22922
|
+
expiration,
|
|
22923
|
+
loadBreaker,
|
|
22924
|
+
saveBreaker,
|
|
22925
|
+
clearBreaker
|
|
22926
|
+
} = ctx;
|
|
22927
|
+
const fingerprint = await refreshTokenFingerprint(refreshToken);
|
|
22928
|
+
const breaker = await loadBreaker(absolutePath).catch(() => ({}));
|
|
22929
|
+
if (breaker.deadTokenFp && breaker.deadTokenFp !== fingerprint) {
|
|
22930
|
+
await clearBreaker(absolutePath);
|
|
22931
|
+
breaker.deadTokenFp = undefined;
|
|
22932
|
+
}
|
|
22933
|
+
const nowMs = Date.now();
|
|
22934
|
+
const tokenIsDead = breaker.deadTokenFp === fingerprint;
|
|
22935
|
+
const inBackoff = breaker.backoffUntilMs !== undefined && nowMs < breaker.backoffUntilMs;
|
|
22936
|
+
if (!tokenIsDead && !inBackoff)
|
|
22937
|
+
return;
|
|
22938
|
+
const globalHint = await ctx.globalHint();
|
|
22939
|
+
const suppressed = !shouldSurface(breaker, nowMs);
|
|
22940
|
+
if (!suppressed) {
|
|
22941
|
+
await saveBreaker(absolutePath, {
|
|
22942
|
+
...breaker,
|
|
22943
|
+
lastSurfacedAtMs: nowMs
|
|
22944
|
+
});
|
|
22945
|
+
}
|
|
22946
|
+
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>.";
|
|
22947
|
+
const backoffHint = "Token refresh is temporarily backed off after a recent network error and will retry automatically once the backoff window elapses.";
|
|
22948
|
+
return {
|
|
22949
|
+
loginStatus: globalHint ? "Expired" : "Refresh Failed",
|
|
22950
|
+
...globalHint ? {
|
|
22951
|
+
accessToken,
|
|
22952
|
+
refreshToken,
|
|
22953
|
+
baseUrl: credentials.UIPATH_URL,
|
|
22954
|
+
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22955
|
+
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22956
|
+
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22957
|
+
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22958
|
+
expiration,
|
|
22959
|
+
source: "file"
|
|
22960
|
+
} : {},
|
|
22961
|
+
hint: globalHint ?? (tokenIsDead ? deadHint : backoffHint),
|
|
22962
|
+
refreshCircuitOpen: true,
|
|
22963
|
+
refreshTelemetrySuppressed: suppressed,
|
|
22964
|
+
tokenRefresh: { attempted: false, success: false }
|
|
22965
|
+
};
|
|
22966
|
+
}
|
|
22967
|
+
async function lockAcquireFailureStatus(ctx, error) {
|
|
22968
|
+
const msg = errorMessage(error);
|
|
22969
|
+
const globalHint = await ctx.globalHint();
|
|
22970
|
+
if (globalHint) {
|
|
22971
|
+
return {
|
|
22972
|
+
loginStatus: "Expired",
|
|
22973
|
+
accessToken: ctx.accessToken,
|
|
22974
|
+
refreshToken: ctx.refreshToken,
|
|
22975
|
+
baseUrl: ctx.credentials.UIPATH_URL,
|
|
22976
|
+
organizationName: ctx.credentials.UIPATH_ORGANIZATION_NAME,
|
|
22977
|
+
organizationId: ctx.credentials.UIPATH_ORGANIZATION_ID,
|
|
22978
|
+
tenantName: ctx.credentials.UIPATH_TENANT_NAME,
|
|
22979
|
+
tenantId: ctx.credentials.UIPATH_TENANT_ID,
|
|
22980
|
+
expiration: ctx.expiration,
|
|
22981
|
+
source: "file",
|
|
22982
|
+
hint: globalHint,
|
|
22983
|
+
tokenRefresh: {
|
|
22984
|
+
attempted: false,
|
|
22985
|
+
success: false,
|
|
22986
|
+
errorMessage: `lock acquisition failed: ${msg}`
|
|
22987
|
+
}
|
|
22988
|
+
};
|
|
22989
|
+
}
|
|
22990
|
+
return {
|
|
22991
|
+
loginStatus: "Refresh Failed",
|
|
22992
|
+
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.",
|
|
22993
|
+
tokenRefresh: {
|
|
22994
|
+
attempted: false,
|
|
22995
|
+
success: false,
|
|
22996
|
+
errorMessage: `lock acquisition failed: ${msg}`
|
|
22997
|
+
}
|
|
22998
|
+
};
|
|
22999
|
+
}
|
|
22582
23000
|
async function runRefreshLocked(inputs) {
|
|
22583
23001
|
const {
|
|
22584
23002
|
absolutePath,
|
|
@@ -22588,7 +23006,10 @@ async function runRefreshLocked(inputs) {
|
|
|
22588
23006
|
loadEnvFile,
|
|
22589
23007
|
saveEnvFile,
|
|
22590
23008
|
refreshFn,
|
|
22591
|
-
resolveConfig
|
|
23009
|
+
resolveConfig,
|
|
23010
|
+
loadBreaker,
|
|
23011
|
+
saveBreaker,
|
|
23012
|
+
clearBreaker
|
|
22592
23013
|
} = inputs;
|
|
22593
23014
|
const expirationThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
22594
23015
|
let fresh;
|
|
@@ -22611,6 +23032,7 @@ async function runRefreshLocked(inputs) {
|
|
|
22611
23032
|
const freshAccess = fresh.UIPATH_ACCESS_TOKEN;
|
|
22612
23033
|
const freshExp = freshAccess ? getTokenExpiration(freshAccess) : undefined;
|
|
22613
23034
|
if (freshAccess && freshExp && freshExp > expirationThreshold) {
|
|
23035
|
+
await clearBreaker(absolutePath);
|
|
22614
23036
|
return {
|
|
22615
23037
|
kind: "ok",
|
|
22616
23038
|
accessToken: freshAccess,
|
|
@@ -22634,8 +23056,21 @@ async function runRefreshLocked(inputs) {
|
|
|
22634
23056
|
refreshedRefresh = refreshed.refreshToken;
|
|
22635
23057
|
} catch (error) {
|
|
22636
23058
|
const isOAuthFailure = isTokenRefreshOAuthFailure(error);
|
|
22637
|
-
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.";
|
|
23059
|
+
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.";
|
|
22638
23060
|
const message = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
|
|
23061
|
+
const fp = await refreshTokenFingerprint(tokenForIdP);
|
|
23062
|
+
if (isOAuthFailure) {
|
|
23063
|
+
await saveBreaker(absolutePath, { deadTokenFp: fp });
|
|
23064
|
+
} else {
|
|
23065
|
+
const prior = await loadBreaker(absolutePath).catch(() => ({}));
|
|
23066
|
+
const attempts = (prior.attempts ?? 0) + 1;
|
|
23067
|
+
await saveBreaker(absolutePath, {
|
|
23068
|
+
...prior,
|
|
23069
|
+
deadTokenFp: undefined,
|
|
23070
|
+
attempts,
|
|
23071
|
+
backoffUntilMs: Date.now() + nextBackoffMs(attempts)
|
|
23072
|
+
});
|
|
23073
|
+
}
|
|
22639
23074
|
return {
|
|
22640
23075
|
kind: "fail",
|
|
22641
23076
|
status: {
|
|
@@ -22664,6 +23099,7 @@ async function runRefreshLocked(inputs) {
|
|
|
22664
23099
|
}
|
|
22665
23100
|
};
|
|
22666
23101
|
}
|
|
23102
|
+
await clearBreaker(absolutePath);
|
|
22667
23103
|
try {
|
|
22668
23104
|
await saveEnvFile({
|
|
22669
23105
|
envPath: absolutePath,
|
|
@@ -22696,226 +23132,35 @@ async function runRefreshLocked(inputs) {
|
|
|
22696
23132
|
};
|
|
22697
23133
|
}
|
|
22698
23134
|
}
|
|
22699
|
-
|
|
22700
|
-
|
|
22701
|
-
|
|
22702
|
-
|
|
22703
|
-
|
|
22704
|
-
|
|
22705
|
-
|
|
22706
|
-
|
|
22707
|
-
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
|
|
22715
|
-
|
|
22716
|
-
|
|
22717
|
-
|
|
22718
|
-
|
|
22719
|
-
|
|
22720
|
-
|
|
22721
|
-
return {
|
|
22722
|
-
loginStatus: "Logged in",
|
|
22723
|
-
accessToken: robotCreds.accessToken,
|
|
22724
|
-
baseUrl: robotCreds.baseUrl,
|
|
22725
|
-
organizationName: robotCreds.organizationName,
|
|
22726
|
-
organizationId: robotCreds.organizationId,
|
|
22727
|
-
tenantName: robotCreds.tenantName,
|
|
22728
|
-
tenantId: robotCreds.tenantId,
|
|
22729
|
-
issuer: robotCreds.issuer,
|
|
22730
|
-
expiration: expiration2,
|
|
22731
|
-
source: "robot"
|
|
22732
|
-
};
|
|
22733
|
-
}
|
|
22734
|
-
if (isEnvAuthEnabled()) {
|
|
22735
|
-
return readAuthFromEnv();
|
|
22736
|
-
}
|
|
22737
|
-
const { envFilePath = DEFAULT_ENV_FILENAME, ensureTokenValidityMinutes } = options;
|
|
22738
|
-
const { absolutePath } = await resolveEnvFilePath(envFilePath);
|
|
22739
|
-
if (absolutePath === undefined) {
|
|
22740
|
-
const robotCreds = await robotFallback();
|
|
22741
|
-
if (robotCreds) {
|
|
22742
|
-
const expiration2 = getTokenExpiration(robotCreds.accessToken);
|
|
22743
|
-
const status = {
|
|
22744
|
-
loginStatus: "Logged in",
|
|
22745
|
-
accessToken: robotCreds.accessToken,
|
|
22746
|
-
baseUrl: robotCreds.baseUrl,
|
|
22747
|
-
organizationName: robotCreds.organizationName,
|
|
22748
|
-
organizationId: robotCreds.organizationId,
|
|
22749
|
-
tenantName: robotCreds.tenantName,
|
|
22750
|
-
tenantId: robotCreds.tenantId,
|
|
22751
|
-
issuer: robotCreds.issuer,
|
|
22752
|
-
expiration: expiration2,
|
|
22753
|
-
source: "robot"
|
|
22754
|
-
};
|
|
22755
|
-
return status;
|
|
22756
|
-
}
|
|
22757
|
-
return { loginStatus: "Not logged in" };
|
|
23135
|
+
function normalizeTokenRefreshFailure() {
|
|
23136
|
+
return "stored refresh token is invalid or expired";
|
|
23137
|
+
}
|
|
23138
|
+
function normalizeTokenRefreshUnavailableFailure() {
|
|
23139
|
+
return "token refresh failed before authentication completed";
|
|
23140
|
+
}
|
|
23141
|
+
function errorMessage(error) {
|
|
23142
|
+
return error instanceof Error ? error.message : String(error);
|
|
23143
|
+
}
|
|
23144
|
+
init_src();
|
|
23145
|
+
var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
|
|
23146
|
+
var INVALID_TENANT_CODE = "INVALID_TENANT";
|
|
23147
|
+
var TENANT_SELECTION_CODES = new Set([
|
|
23148
|
+
TENANT_SELECTION_REQUIRED_CODE,
|
|
23149
|
+
INVALID_TENANT_CODE
|
|
23150
|
+
]);
|
|
23151
|
+
init_src();
|
|
23152
|
+
init_server();
|
|
23153
|
+
async function resolveConfig(options) {
|
|
23154
|
+
const status = await getLoginStatusAsync();
|
|
23155
|
+
if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
|
|
23156
|
+
throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
|
|
22758
23157
|
}
|
|
22759
|
-
|
|
22760
|
-
|
|
22761
|
-
credentials = await loadEnvFile({ envPath: absolutePath });
|
|
22762
|
-
} catch (error) {
|
|
22763
|
-
if (isFileNotFoundError(error)) {
|
|
22764
|
-
return { loginStatus: "Not logged in" };
|
|
22765
|
-
}
|
|
22766
|
-
throw error;
|
|
23158
|
+
if (!status.organizationId) {
|
|
23159
|
+
throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
|
|
22767
23160
|
}
|
|
22768
|
-
|
|
22769
|
-
|
|
22770
|
-
|
|
22771
|
-
let accessToken = credentials.UIPATH_ACCESS_TOKEN;
|
|
22772
|
-
let refreshToken = credentials.UIPATH_REFRESH_TOKEN;
|
|
22773
|
-
let expiration = getTokenExpiration(accessToken);
|
|
22774
|
-
let persistenceWarning;
|
|
22775
|
-
let lockReleaseFailed = false;
|
|
22776
|
-
let tokenRefresh;
|
|
22777
|
-
const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
22778
|
-
const tryGlobalCredsHint = async () => {
|
|
22779
|
-
const fs7 = getFs();
|
|
22780
|
-
const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
|
|
22781
|
-
if (absolutePath === globalPath)
|
|
22782
|
-
return;
|
|
22783
|
-
if (!await fs7.exists(globalPath))
|
|
22784
|
-
return;
|
|
22785
|
-
try {
|
|
22786
|
-
const globalCreds = await loadEnvFile({ envPath: globalPath });
|
|
22787
|
-
if (!globalCreds.UIPATH_ACCESS_TOKEN)
|
|
22788
|
-
return;
|
|
22789
|
-
const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
|
|
22790
|
-
if (globalExp && globalExp <= new Date)
|
|
22791
|
-
return;
|
|
22792
|
-
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.`;
|
|
22793
|
-
} catch {
|
|
22794
|
-
return;
|
|
22795
|
-
}
|
|
22796
|
-
};
|
|
22797
|
-
if (expiration && expiration <= outerThreshold && refreshToken) {
|
|
22798
|
-
let release;
|
|
22799
|
-
try {
|
|
22800
|
-
release = await getFs().acquireLock(absolutePath);
|
|
22801
|
-
} catch (error) {
|
|
22802
|
-
const msg = errorMessage(error);
|
|
22803
|
-
const globalHint = await tryGlobalCredsHint();
|
|
22804
|
-
if (globalHint) {
|
|
22805
|
-
return {
|
|
22806
|
-
loginStatus: "Expired",
|
|
22807
|
-
accessToken,
|
|
22808
|
-
refreshToken,
|
|
22809
|
-
baseUrl: credentials.UIPATH_URL,
|
|
22810
|
-
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22811
|
-
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22812
|
-
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22813
|
-
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22814
|
-
expiration,
|
|
22815
|
-
source: "file",
|
|
22816
|
-
hint: globalHint,
|
|
22817
|
-
tokenRefresh: {
|
|
22818
|
-
attempted: false,
|
|
22819
|
-
success: false,
|
|
22820
|
-
errorMessage: `lock acquisition failed: ${msg}`
|
|
22821
|
-
}
|
|
22822
|
-
};
|
|
22823
|
-
}
|
|
22824
|
-
return {
|
|
22825
|
-
loginStatus: "Refresh Failed",
|
|
22826
|
-
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.",
|
|
22827
|
-
tokenRefresh: {
|
|
22828
|
-
attempted: false,
|
|
22829
|
-
success: false,
|
|
22830
|
-
errorMessage: `lock acquisition failed: ${msg}`
|
|
22831
|
-
}
|
|
22832
|
-
};
|
|
22833
|
-
}
|
|
22834
|
-
let lockedFailure;
|
|
22835
|
-
try {
|
|
22836
|
-
const outcome = await runRefreshLocked({
|
|
22837
|
-
absolutePath,
|
|
22838
|
-
refreshToken,
|
|
22839
|
-
customAuthority: credentials.UIPATH_URL,
|
|
22840
|
-
ensureTokenValidityMinutes,
|
|
22841
|
-
loadEnvFile,
|
|
22842
|
-
saveEnvFile,
|
|
22843
|
-
refreshFn: refreshTokenFn,
|
|
22844
|
-
resolveConfig
|
|
22845
|
-
});
|
|
22846
|
-
if (outcome.kind === "fail") {
|
|
22847
|
-
lockedFailure = outcome.status;
|
|
22848
|
-
} else {
|
|
22849
|
-
accessToken = outcome.accessToken;
|
|
22850
|
-
refreshToken = outcome.refreshToken;
|
|
22851
|
-
expiration = outcome.expiration;
|
|
22852
|
-
tokenRefresh = outcome.tokenRefresh;
|
|
22853
|
-
if (outcome.persistenceWarning) {
|
|
22854
|
-
persistenceWarning = outcome.persistenceWarning;
|
|
22855
|
-
}
|
|
22856
|
-
}
|
|
22857
|
-
} finally {
|
|
22858
|
-
try {
|
|
22859
|
-
await release();
|
|
22860
|
-
} catch {
|
|
22861
|
-
lockReleaseFailed = true;
|
|
22862
|
-
}
|
|
22863
|
-
}
|
|
22864
|
-
if (lockedFailure) {
|
|
22865
|
-
const globalHint = await tryGlobalCredsHint();
|
|
22866
|
-
const base = globalHint ? {
|
|
22867
|
-
...lockedFailure,
|
|
22868
|
-
loginStatus: "Expired",
|
|
22869
|
-
hint: globalHint
|
|
22870
|
-
} : lockedFailure;
|
|
22871
|
-
return lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base;
|
|
22872
|
-
}
|
|
22873
|
-
}
|
|
22874
|
-
const result = {
|
|
22875
|
-
loginStatus: expiration && expiration <= new Date ? "Expired" : "Logged in",
|
|
22876
|
-
accessToken,
|
|
22877
|
-
refreshToken,
|
|
22878
|
-
baseUrl: credentials.UIPATH_URL,
|
|
22879
|
-
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
22880
|
-
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
22881
|
-
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
22882
|
-
tenantId: credentials.UIPATH_TENANT_ID,
|
|
22883
|
-
expiration,
|
|
22884
|
-
source: "file",
|
|
22885
|
-
...persistenceWarning ? { hint: persistenceWarning, persistenceFailed: true } : {},
|
|
22886
|
-
...lockReleaseFailed ? { lockReleaseFailed: true } : {},
|
|
22887
|
-
...tokenRefresh ? { tokenRefresh } : {}
|
|
22888
|
-
};
|
|
22889
|
-
if (result.loginStatus === "Expired") {
|
|
22890
|
-
const globalHint = await tryGlobalCredsHint();
|
|
22891
|
-
if (globalHint) {
|
|
22892
|
-
result.hint = globalHint;
|
|
22893
|
-
}
|
|
22894
|
-
}
|
|
22895
|
-
return result;
|
|
22896
|
-
};
|
|
22897
|
-
var isFileNotFoundError = (error) => {
|
|
22898
|
-
if (!(error instanceof Object))
|
|
22899
|
-
return false;
|
|
22900
|
-
return error.code === "ENOENT";
|
|
22901
|
-
};
|
|
22902
|
-
var getLoginStatusAsync = async (options = {}) => {
|
|
22903
|
-
return getLoginStatusWithDeps(options);
|
|
22904
|
-
};
|
|
22905
|
-
init_src();
|
|
22906
|
-
init_src();
|
|
22907
|
-
init_server();
|
|
22908
|
-
async function resolveConfig(options) {
|
|
22909
|
-
const status = await getLoginStatusAsync();
|
|
22910
|
-
if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
|
|
22911
|
-
throw new Error(status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.");
|
|
22912
|
-
}
|
|
22913
|
-
if (!status.organizationId) {
|
|
22914
|
-
throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
|
|
22915
|
-
}
|
|
22916
|
-
const tenant = options?.tenantName ?? status.tenantName;
|
|
22917
|
-
if (!tenant) {
|
|
22918
|
-
throw new Error("Tenant not available. Pass --tenant <name> or log in with a tenant context.");
|
|
23161
|
+
const tenant = options?.tenantName ?? status.tenantName;
|
|
23162
|
+
if (!tenant) {
|
|
23163
|
+
throw new Error("Tenant not available. Pass --tenant <name> or log in with a tenant context.");
|
|
22919
23164
|
}
|
|
22920
23165
|
const basePath = `${status.baseUrl}/${encodeURIComponent(status.organizationId)}/${encodeURIComponent(tenant)}/hypervisor_`;
|
|
22921
23166
|
const bearerToken = options?.s2sToken ?? status.accessToken;
|
|
@@ -23825,27 +24070,54 @@ var NETWORK_ERROR_CODES = new Set([
|
|
|
23825
24070
|
"ENETUNREACH",
|
|
23826
24071
|
"EAI_FAIL"
|
|
23827
24072
|
]);
|
|
23828
|
-
|
|
23829
|
-
|
|
23830
|
-
|
|
23831
|
-
|
|
23832
|
-
|
|
23833
|
-
|
|
23834
|
-
|
|
23835
|
-
|
|
23836
|
-
|
|
23837
|
-
|
|
23838
|
-
|
|
23839
|
-
|
|
23840
|
-
|
|
23841
|
-
|
|
23842
|
-
|
|
23843
|
-
|
|
23844
|
-
|
|
24073
|
+
var TLS_ERROR_CODES = new Set([
|
|
24074
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
24075
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
24076
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
24077
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
24078
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
24079
|
+
"CERT_HAS_EXPIRED",
|
|
24080
|
+
"CERT_UNTRUSTED",
|
|
24081
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
24082
|
+
]);
|
|
24083
|
+
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.";
|
|
24084
|
+
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.";
|
|
24085
|
+
function describeConnectivityError(error) {
|
|
24086
|
+
let current = error;
|
|
24087
|
+
for (let depth = 0;depth < 5 && current !== null && typeof current === "object"; depth++) {
|
|
24088
|
+
const cur = current;
|
|
24089
|
+
const code = typeof cur.code === "string" ? cur.code : undefined;
|
|
24090
|
+
const message = typeof cur.message === "string" ? cur.message : undefined;
|
|
24091
|
+
if (code && TLS_ERROR_CODES.has(code)) {
|
|
24092
|
+
return {
|
|
24093
|
+
code,
|
|
24094
|
+
kind: "tls",
|
|
24095
|
+
message: message ?? code,
|
|
24096
|
+
instructions: TLS_INSTRUCTIONS
|
|
24097
|
+
};
|
|
23845
24098
|
}
|
|
24099
|
+
if (code && NETWORK_ERROR_CODES.has(code)) {
|
|
24100
|
+
return {
|
|
24101
|
+
code,
|
|
24102
|
+
kind: "network",
|
|
24103
|
+
message: message ?? code,
|
|
24104
|
+
instructions: NETWORK_INSTRUCTIONS
|
|
24105
|
+
};
|
|
24106
|
+
}
|
|
24107
|
+
current = cur.cause;
|
|
23846
24108
|
}
|
|
23847
24109
|
return;
|
|
23848
24110
|
}
|
|
24111
|
+
function parseHttpStatusFromMessage(message) {
|
|
24112
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
24113
|
+
if (!match)
|
|
24114
|
+
return;
|
|
24115
|
+
const status = Number(match[1]);
|
|
24116
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
24117
|
+
}
|
|
24118
|
+
function isHtmlDocument(body) {
|
|
24119
|
+
return /^\s*(<!doctype html|<html\b)/i.test(body);
|
|
24120
|
+
}
|
|
23849
24121
|
function retryHintForRetryAfter(seconds) {
|
|
23850
24122
|
if (seconds <= 1) {
|
|
23851
24123
|
return "RetryAfter1Second";
|
|
@@ -23886,15 +24158,28 @@ function classifyError(status, error) {
|
|
|
23886
24158
|
if (status !== undefined && status >= 500 && status < 600) {
|
|
23887
24159
|
return { errorCode: "server_error", retry: "RetryLater" };
|
|
23888
24160
|
}
|
|
23889
|
-
|
|
23890
|
-
|
|
24161
|
+
const connectivity = describeConnectivityError(error);
|
|
24162
|
+
if (connectivity) {
|
|
24163
|
+
return {
|
|
24164
|
+
errorCode: "network_error",
|
|
24165
|
+
retry: connectivity.kind === "tls" ? "RetryWillNotFix" : "RetryLater"
|
|
24166
|
+
};
|
|
23891
24167
|
}
|
|
23892
24168
|
return { errorCode: "unknown_error", retry: "RetryWillNotFix" };
|
|
23893
24169
|
}
|
|
24170
|
+
function formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus) {
|
|
24171
|
+
if (extractedMessage) {
|
|
24172
|
+
return `HTTP ${status}: ${extractedMessage}`;
|
|
24173
|
+
}
|
|
24174
|
+
return inferredStatus !== undefined ? rawMessage : `HTTP ${status}: ${rawMessage}`;
|
|
24175
|
+
}
|
|
23894
24176
|
async function extractErrorDetails(error, options) {
|
|
23895
24177
|
const err = error !== null && error !== undefined && typeof error === "object" ? error : {};
|
|
23896
24178
|
const response = err.response;
|
|
23897
|
-
const
|
|
24179
|
+
const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
|
|
24180
|
+
const explicitStatus = err.status ?? response?.status;
|
|
24181
|
+
const inferredStatus = explicitStatus === undefined ? parseHttpStatusFromMessage(rawMessage) : undefined;
|
|
24182
|
+
const status = explicitStatus ?? inferredStatus;
|
|
23898
24183
|
const isSuccessfulResponse = status !== undefined && status >= 200 && status < 300;
|
|
23899
24184
|
let rawBody;
|
|
23900
24185
|
let extractedMessage;
|
|
@@ -23929,7 +24214,6 @@ async function extractErrorDetails(error, options) {
|
|
|
23929
24214
|
}
|
|
23930
24215
|
}
|
|
23931
24216
|
}
|
|
23932
|
-
const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
|
|
23933
24217
|
let message;
|
|
23934
24218
|
let result = "Failure";
|
|
23935
24219
|
const classification = classifyError(status, error);
|
|
@@ -23943,10 +24227,10 @@ async function extractErrorDetails(error, options) {
|
|
|
23943
24227
|
} else if (status === 405) {
|
|
23944
24228
|
message = DEFAULT_405;
|
|
23945
24229
|
} else if (status === 400 || status === 422) {
|
|
23946
|
-
message =
|
|
24230
|
+
message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
|
|
23947
24231
|
result = "ValidationError";
|
|
23948
24232
|
} else if (status === 429) {
|
|
23949
|
-
message =
|
|
24233
|
+
message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
|
|
23950
24234
|
} else if (extractedMessage) {
|
|
23951
24235
|
if (isSuccessfulResponse && rawMessage !== "Unknown error") {
|
|
23952
24236
|
message = rawMessage;
|
|
@@ -23954,7 +24238,9 @@ async function extractErrorDetails(error, options) {
|
|
|
23954
24238
|
message = status ? `HTTP ${status}: ${extractedMessage}` : extractedMessage;
|
|
23955
24239
|
}
|
|
23956
24240
|
} else if (status) {
|
|
23957
|
-
if (
|
|
24241
|
+
if (inferredStatus !== undefined) {
|
|
24242
|
+
message = rawMessage;
|
|
24243
|
+
} else if (rawMessage === "Unknown error" && response) {
|
|
23958
24244
|
const statusText = response.statusText;
|
|
23959
24245
|
message = statusText ? `HTTP ${status} ${statusText}` : `HTTP ${status} - request failed`;
|
|
23960
24246
|
} else {
|
|
@@ -23963,6 +24249,12 @@ async function extractErrorDetails(error, options) {
|
|
|
23963
24249
|
} else {
|
|
23964
24250
|
message = rawMessage;
|
|
23965
24251
|
}
|
|
24252
|
+
if (status === undefined) {
|
|
24253
|
+
const connectivity = describeConnectivityError(error);
|
|
24254
|
+
if (connectivity && connectivity.message !== message && !message.includes(connectivity.message)) {
|
|
24255
|
+
message = `${message}: ${connectivity.message}`;
|
|
24256
|
+
}
|
|
24257
|
+
}
|
|
23966
24258
|
let details = rawMessage;
|
|
23967
24259
|
if (rawBody) {
|
|
23968
24260
|
if (parsedBody) {
|
|
@@ -24110,6 +24402,7 @@ var CONSOLE_FALLBACK = {
|
|
|
24110
24402
|
writeLog: (str) => process.stdout.write(str),
|
|
24111
24403
|
capabilities: {
|
|
24112
24404
|
isInteractive: false,
|
|
24405
|
+
canReadInput: false,
|
|
24113
24406
|
supportsColor: false,
|
|
24114
24407
|
outputWidth: 80
|
|
24115
24408
|
}
|
|
@@ -29115,9 +29408,9 @@ class NodeContextStorage {
|
|
|
29115
29408
|
}
|
|
29116
29409
|
}
|
|
29117
29410
|
// ../../common/src/telemetry/global-telemetry-properties.ts
|
|
29118
|
-
var
|
|
29411
|
+
var telemetryPropsSlot2 = singleton2("TelemetryDefaultProps");
|
|
29119
29412
|
function getGlobalTelemetryProperties() {
|
|
29120
|
-
return
|
|
29413
|
+
return telemetryPropsSlot2.get();
|
|
29121
29414
|
}
|
|
29122
29415
|
|
|
29123
29416
|
// ../../common/src/telemetry/telemetry-service.ts
|
|
@@ -29309,6 +29602,29 @@ function isPlainRecord(value) {
|
|
|
29309
29602
|
const prototype = Object.getPrototypeOf(value);
|
|
29310
29603
|
return prototype === Object.prototype || prototype === null;
|
|
29311
29604
|
}
|
|
29605
|
+
function extractPagedRows(value) {
|
|
29606
|
+
if (Array.isArray(value) || !isPlainRecord(value))
|
|
29607
|
+
return null;
|
|
29608
|
+
const entries = Object.values(value);
|
|
29609
|
+
if (entries.length === 0)
|
|
29610
|
+
return null;
|
|
29611
|
+
let rows = null;
|
|
29612
|
+
let hasScalarSibling = false;
|
|
29613
|
+
for (const entry of entries) {
|
|
29614
|
+
if (Array.isArray(entry)) {
|
|
29615
|
+
if (rows !== null)
|
|
29616
|
+
return null;
|
|
29617
|
+
rows = entry;
|
|
29618
|
+
} else if (entry !== null && typeof entry === "object") {
|
|
29619
|
+
return null;
|
|
29620
|
+
} else {
|
|
29621
|
+
hasScalarSibling = true;
|
|
29622
|
+
}
|
|
29623
|
+
}
|
|
29624
|
+
if (rows === null || !hasScalarSibling)
|
|
29625
|
+
return null;
|
|
29626
|
+
return rows;
|
|
29627
|
+
}
|
|
29312
29628
|
function toLowerCamelCaseKey(key) {
|
|
29313
29629
|
if (!key)
|
|
29314
29630
|
return key;
|
|
@@ -29373,7 +29689,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
29373
29689
|
break;
|
|
29374
29690
|
case "plain": {
|
|
29375
29691
|
if ("Data" in data && data.Data != null) {
|
|
29376
|
-
const
|
|
29692
|
+
const pagedRows = extractPagedRows(data.Data);
|
|
29693
|
+
const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
|
|
29377
29694
|
items.forEach((item) => {
|
|
29378
29695
|
const values = Object.values(item).map((v) => v ?? "").join("\t");
|
|
29379
29696
|
logFn(values);
|
|
@@ -29385,10 +29702,13 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
29385
29702
|
break;
|
|
29386
29703
|
}
|
|
29387
29704
|
default: {
|
|
29388
|
-
|
|
29705
|
+
const hasData = "Data" in data && data.Data != null;
|
|
29706
|
+
const pagedRows = hasData ? extractPagedRows(data.Data) : null;
|
|
29707
|
+
const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
|
|
29708
|
+
if (hasData && !(rows !== null && rows.length === 0)) {
|
|
29389
29709
|
const logValue = data.Log;
|
|
29390
|
-
if (
|
|
29391
|
-
printResizableTable(
|
|
29710
|
+
if (rows !== null) {
|
|
29711
|
+
printResizableTable(rows, logFn, logValue);
|
|
29392
29712
|
} else {
|
|
29393
29713
|
printVerticalTable(data.Data, logFn, logValue);
|
|
29394
29714
|
}
|
|
@@ -29576,6 +29896,44 @@ function defaultErrorCodeForResult(result) {
|
|
|
29576
29896
|
return "unknown_error";
|
|
29577
29897
|
}
|
|
29578
29898
|
}
|
|
29899
|
+
function parseHttpStatusFromMessage2(message) {
|
|
29900
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
29901
|
+
if (!match)
|
|
29902
|
+
return;
|
|
29903
|
+
const status = Number(match[1]);
|
|
29904
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
29905
|
+
}
|
|
29906
|
+
function defaultErrorCodeForHttpStatus(status) {
|
|
29907
|
+
if (status === undefined)
|
|
29908
|
+
return;
|
|
29909
|
+
if (status === 400 || status === 409 || status === 422) {
|
|
29910
|
+
return "invalid_argument";
|
|
29911
|
+
}
|
|
29912
|
+
if (status === 401)
|
|
29913
|
+
return "authentication_required";
|
|
29914
|
+
if (status === 403)
|
|
29915
|
+
return "permission_denied";
|
|
29916
|
+
if (status === 404)
|
|
29917
|
+
return "not_found";
|
|
29918
|
+
if (status === 405)
|
|
29919
|
+
return "method_not_allowed";
|
|
29920
|
+
if (status === 408)
|
|
29921
|
+
return "timeout";
|
|
29922
|
+
if (status === 429)
|
|
29923
|
+
return "rate_limited";
|
|
29924
|
+
if (status >= 500 && status < 600)
|
|
29925
|
+
return "server_error";
|
|
29926
|
+
return;
|
|
29927
|
+
}
|
|
29928
|
+
function defaultErrorCodeForFailure(data) {
|
|
29929
|
+
if (data.Result === RESULTS.Failure) {
|
|
29930
|
+
const status = data.Context?.httpStatus ?? parseHttpStatusFromMessage2(data.Message);
|
|
29931
|
+
const errorCode2 = defaultErrorCodeForHttpStatus(status);
|
|
29932
|
+
if (errorCode2)
|
|
29933
|
+
return errorCode2;
|
|
29934
|
+
}
|
|
29935
|
+
return defaultErrorCodeForResult(data.Result);
|
|
29936
|
+
}
|
|
29579
29937
|
function defaultRetryForErrorCode(errorCode2) {
|
|
29580
29938
|
switch (errorCode2) {
|
|
29581
29939
|
case "network_error":
|
|
@@ -29605,16 +29963,19 @@ var OutputFormatter;
|
|
|
29605
29963
|
OutputFormatter.success = success;
|
|
29606
29964
|
function error(data) {
|
|
29607
29965
|
data.Log ??= getLogFilePath() || undefined;
|
|
29608
|
-
data.ErrorCode ??=
|
|
29966
|
+
data.ErrorCode ??= defaultErrorCodeForFailure(data);
|
|
29609
29967
|
data.Retry ??= defaultRetryForErrorCode(data.ErrorCode);
|
|
29610
29968
|
process.exitCode = EXIT_CODES[data.Result] ?? 1;
|
|
29611
|
-
|
|
29612
|
-
|
|
29613
|
-
|
|
29614
|
-
|
|
29615
|
-
|
|
29616
|
-
|
|
29617
|
-
|
|
29969
|
+
const { SuppressTelemetry, ...envelope } = data;
|
|
29970
|
+
if (!SuppressTelemetry) {
|
|
29971
|
+
telemetry.trackEvent(CommonTelemetryEvents.Error, {
|
|
29972
|
+
result: data.Result,
|
|
29973
|
+
errorCode: data.ErrorCode,
|
|
29974
|
+
retry: data.Retry,
|
|
29975
|
+
message: data.Message
|
|
29976
|
+
});
|
|
29977
|
+
}
|
|
29978
|
+
logOutput(normalizeOutputKeys(envelope), getOutputFormat());
|
|
29618
29979
|
}
|
|
29619
29980
|
OutputFormatter.error = error;
|
|
29620
29981
|
function emitList(code, items, opts) {
|
|
@@ -29941,1415 +30302,16 @@ function instructionsFor(ctx, err) {
|
|
|
29941
30302
|
if (status !== undefined && status >= 500 && status < 600) {
|
|
29942
30303
|
return "Orchestrator returned a server error — retry; if it persists, check service status";
|
|
29943
30304
|
}
|
|
30305
|
+
const connectivity = describeConnectivityError(err);
|
|
30306
|
+
if (connectivity) {
|
|
30307
|
+
return connectivity.instructions;
|
|
30308
|
+
}
|
|
29944
30309
|
return GENERIC;
|
|
29945
30310
|
}
|
|
29946
30311
|
}
|
|
29947
30312
|
}
|
|
29948
30313
|
// ../../common/src/interactivity-context.ts
|
|
29949
30314
|
var modeSlot = singleton2("InteractivityMode");
|
|
29950
|
-
// ../../../node_modules/jsonpath-plus/dist/index-node-esm.js
|
|
29951
|
-
import vm from "vm";
|
|
29952
|
-
|
|
29953
|
-
class Hooks {
|
|
29954
|
-
add(name, callback, first) {
|
|
29955
|
-
if (typeof arguments[0] != "string") {
|
|
29956
|
-
for (let name2 in arguments[0]) {
|
|
29957
|
-
this.add(name2, arguments[0][name2], arguments[1]);
|
|
29958
|
-
}
|
|
29959
|
-
} else {
|
|
29960
|
-
(Array.isArray(name) ? name : [name]).forEach(function(name2) {
|
|
29961
|
-
this[name2] = this[name2] || [];
|
|
29962
|
-
if (callback) {
|
|
29963
|
-
this[name2][first ? "unshift" : "push"](callback);
|
|
29964
|
-
}
|
|
29965
|
-
}, this);
|
|
29966
|
-
}
|
|
29967
|
-
}
|
|
29968
|
-
run(name, env) {
|
|
29969
|
-
this[name] = this[name] || [];
|
|
29970
|
-
this[name].forEach(function(callback) {
|
|
29971
|
-
callback.call(env && env.context ? env.context : env, env);
|
|
29972
|
-
});
|
|
29973
|
-
}
|
|
29974
|
-
}
|
|
29975
|
-
|
|
29976
|
-
class Plugins {
|
|
29977
|
-
constructor(jsep) {
|
|
29978
|
-
this.jsep = jsep;
|
|
29979
|
-
this.registered = {};
|
|
29980
|
-
}
|
|
29981
|
-
register(...plugins) {
|
|
29982
|
-
plugins.forEach((plugin) => {
|
|
29983
|
-
if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
|
|
29984
|
-
throw new Error("Invalid JSEP plugin format");
|
|
29985
|
-
}
|
|
29986
|
-
if (this.registered[plugin.name]) {
|
|
29987
|
-
return;
|
|
29988
|
-
}
|
|
29989
|
-
plugin.init(this.jsep);
|
|
29990
|
-
this.registered[plugin.name] = plugin;
|
|
29991
|
-
});
|
|
29992
|
-
}
|
|
29993
|
-
}
|
|
29994
|
-
|
|
29995
|
-
class Jsep {
|
|
29996
|
-
static get version() {
|
|
29997
|
-
return "1.4.0";
|
|
29998
|
-
}
|
|
29999
|
-
static toString() {
|
|
30000
|
-
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
30001
|
-
}
|
|
30002
|
-
static addUnaryOp(op_name) {
|
|
30003
|
-
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
30004
|
-
Jsep.unary_ops[op_name] = 1;
|
|
30005
|
-
return Jsep;
|
|
30006
|
-
}
|
|
30007
|
-
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
30008
|
-
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
30009
|
-
Jsep.binary_ops[op_name] = precedence;
|
|
30010
|
-
if (isRightAssociative) {
|
|
30011
|
-
Jsep.right_associative.add(op_name);
|
|
30012
|
-
} else {
|
|
30013
|
-
Jsep.right_associative.delete(op_name);
|
|
30014
|
-
}
|
|
30015
|
-
return Jsep;
|
|
30016
|
-
}
|
|
30017
|
-
static addIdentifierChar(char) {
|
|
30018
|
-
Jsep.additional_identifier_chars.add(char);
|
|
30019
|
-
return Jsep;
|
|
30020
|
-
}
|
|
30021
|
-
static addLiteral(literal_name, literal_value) {
|
|
30022
|
-
Jsep.literals[literal_name] = literal_value;
|
|
30023
|
-
return Jsep;
|
|
30024
|
-
}
|
|
30025
|
-
static removeUnaryOp(op_name) {
|
|
30026
|
-
delete Jsep.unary_ops[op_name];
|
|
30027
|
-
if (op_name.length === Jsep.max_unop_len) {
|
|
30028
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
30029
|
-
}
|
|
30030
|
-
return Jsep;
|
|
30031
|
-
}
|
|
30032
|
-
static removeAllUnaryOps() {
|
|
30033
|
-
Jsep.unary_ops = {};
|
|
30034
|
-
Jsep.max_unop_len = 0;
|
|
30035
|
-
return Jsep;
|
|
30036
|
-
}
|
|
30037
|
-
static removeIdentifierChar(char) {
|
|
30038
|
-
Jsep.additional_identifier_chars.delete(char);
|
|
30039
|
-
return Jsep;
|
|
30040
|
-
}
|
|
30041
|
-
static removeBinaryOp(op_name) {
|
|
30042
|
-
delete Jsep.binary_ops[op_name];
|
|
30043
|
-
if (op_name.length === Jsep.max_binop_len) {
|
|
30044
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
30045
|
-
}
|
|
30046
|
-
Jsep.right_associative.delete(op_name);
|
|
30047
|
-
return Jsep;
|
|
30048
|
-
}
|
|
30049
|
-
static removeAllBinaryOps() {
|
|
30050
|
-
Jsep.binary_ops = {};
|
|
30051
|
-
Jsep.max_binop_len = 0;
|
|
30052
|
-
return Jsep;
|
|
30053
|
-
}
|
|
30054
|
-
static removeLiteral(literal_name) {
|
|
30055
|
-
delete Jsep.literals[literal_name];
|
|
30056
|
-
return Jsep;
|
|
30057
|
-
}
|
|
30058
|
-
static removeAllLiterals() {
|
|
30059
|
-
Jsep.literals = {};
|
|
30060
|
-
return Jsep;
|
|
30061
|
-
}
|
|
30062
|
-
get char() {
|
|
30063
|
-
return this.expr.charAt(this.index);
|
|
30064
|
-
}
|
|
30065
|
-
get code() {
|
|
30066
|
-
return this.expr.charCodeAt(this.index);
|
|
30067
|
-
}
|
|
30068
|
-
constructor(expr) {
|
|
30069
|
-
this.expr = expr;
|
|
30070
|
-
this.index = 0;
|
|
30071
|
-
}
|
|
30072
|
-
static parse(expr) {
|
|
30073
|
-
return new Jsep(expr).parse();
|
|
30074
|
-
}
|
|
30075
|
-
static getMaxKeyLen(obj) {
|
|
30076
|
-
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
30077
|
-
}
|
|
30078
|
-
static isDecimalDigit(ch) {
|
|
30079
|
-
return ch >= 48 && ch <= 57;
|
|
30080
|
-
}
|
|
30081
|
-
static binaryPrecedence(op_val) {
|
|
30082
|
-
return Jsep.binary_ops[op_val] || 0;
|
|
30083
|
-
}
|
|
30084
|
-
static isIdentifierStart(ch) {
|
|
30085
|
-
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));
|
|
30086
|
-
}
|
|
30087
|
-
static isIdentifierPart(ch) {
|
|
30088
|
-
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
30089
|
-
}
|
|
30090
|
-
throwError(message) {
|
|
30091
|
-
const error = new Error(message + " at character " + this.index);
|
|
30092
|
-
error.index = this.index;
|
|
30093
|
-
error.description = message;
|
|
30094
|
-
throw error;
|
|
30095
|
-
}
|
|
30096
|
-
runHook(name, node) {
|
|
30097
|
-
if (Jsep.hooks[name]) {
|
|
30098
|
-
const env = {
|
|
30099
|
-
context: this,
|
|
30100
|
-
node
|
|
30101
|
-
};
|
|
30102
|
-
Jsep.hooks.run(name, env);
|
|
30103
|
-
return env.node;
|
|
30104
|
-
}
|
|
30105
|
-
return node;
|
|
30106
|
-
}
|
|
30107
|
-
searchHook(name) {
|
|
30108
|
-
if (Jsep.hooks[name]) {
|
|
30109
|
-
const env = {
|
|
30110
|
-
context: this
|
|
30111
|
-
};
|
|
30112
|
-
Jsep.hooks[name].find(function(callback) {
|
|
30113
|
-
callback.call(env.context, env);
|
|
30114
|
-
return env.node;
|
|
30115
|
-
});
|
|
30116
|
-
return env.node;
|
|
30117
|
-
}
|
|
30118
|
-
}
|
|
30119
|
-
gobbleSpaces() {
|
|
30120
|
-
let ch = this.code;
|
|
30121
|
-
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
30122
|
-
ch = this.expr.charCodeAt(++this.index);
|
|
30123
|
-
}
|
|
30124
|
-
this.runHook("gobble-spaces");
|
|
30125
|
-
}
|
|
30126
|
-
parse() {
|
|
30127
|
-
this.runHook("before-all");
|
|
30128
|
-
const nodes = this.gobbleExpressions();
|
|
30129
|
-
const node = nodes.length === 1 ? nodes[0] : {
|
|
30130
|
-
type: Jsep.COMPOUND,
|
|
30131
|
-
body: nodes
|
|
30132
|
-
};
|
|
30133
|
-
return this.runHook("after-all", node);
|
|
30134
|
-
}
|
|
30135
|
-
gobbleExpressions(untilICode) {
|
|
30136
|
-
let nodes = [], ch_i, node;
|
|
30137
|
-
while (this.index < this.expr.length) {
|
|
30138
|
-
ch_i = this.code;
|
|
30139
|
-
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
30140
|
-
this.index++;
|
|
30141
|
-
} else {
|
|
30142
|
-
if (node = this.gobbleExpression()) {
|
|
30143
|
-
nodes.push(node);
|
|
30144
|
-
} else if (this.index < this.expr.length) {
|
|
30145
|
-
if (ch_i === untilICode) {
|
|
30146
|
-
break;
|
|
30147
|
-
}
|
|
30148
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
30149
|
-
}
|
|
30150
|
-
}
|
|
30151
|
-
}
|
|
30152
|
-
return nodes;
|
|
30153
|
-
}
|
|
30154
|
-
gobbleExpression() {
|
|
30155
|
-
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
30156
|
-
this.gobbleSpaces();
|
|
30157
|
-
return this.runHook("after-expression", node);
|
|
30158
|
-
}
|
|
30159
|
-
gobbleBinaryOp() {
|
|
30160
|
-
this.gobbleSpaces();
|
|
30161
|
-
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
30162
|
-
let tc_len = to_check.length;
|
|
30163
|
-
while (tc_len > 0) {
|
|
30164
|
-
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)))) {
|
|
30165
|
-
this.index += tc_len;
|
|
30166
|
-
return to_check;
|
|
30167
|
-
}
|
|
30168
|
-
to_check = to_check.substr(0, --tc_len);
|
|
30169
|
-
}
|
|
30170
|
-
return false;
|
|
30171
|
-
}
|
|
30172
|
-
gobbleBinaryExpression() {
|
|
30173
|
-
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
30174
|
-
left = this.gobbleToken();
|
|
30175
|
-
if (!left) {
|
|
30176
|
-
return left;
|
|
30177
|
-
}
|
|
30178
|
-
biop = this.gobbleBinaryOp();
|
|
30179
|
-
if (!biop) {
|
|
30180
|
-
return left;
|
|
30181
|
-
}
|
|
30182
|
-
biop_info = {
|
|
30183
|
-
value: biop,
|
|
30184
|
-
prec: Jsep.binaryPrecedence(biop),
|
|
30185
|
-
right_a: Jsep.right_associative.has(biop)
|
|
30186
|
-
};
|
|
30187
|
-
right = this.gobbleToken();
|
|
30188
|
-
if (!right) {
|
|
30189
|
-
this.throwError("Expected expression after " + biop);
|
|
30190
|
-
}
|
|
30191
|
-
stack = [left, biop_info, right];
|
|
30192
|
-
while (biop = this.gobbleBinaryOp()) {
|
|
30193
|
-
prec = Jsep.binaryPrecedence(biop);
|
|
30194
|
-
if (prec === 0) {
|
|
30195
|
-
this.index -= biop.length;
|
|
30196
|
-
break;
|
|
30197
|
-
}
|
|
30198
|
-
biop_info = {
|
|
30199
|
-
value: biop,
|
|
30200
|
-
prec,
|
|
30201
|
-
right_a: Jsep.right_associative.has(biop)
|
|
30202
|
-
};
|
|
30203
|
-
cur_biop = biop;
|
|
30204
|
-
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
30205
|
-
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
30206
|
-
right = stack.pop();
|
|
30207
|
-
biop = stack.pop().value;
|
|
30208
|
-
left = stack.pop();
|
|
30209
|
-
node = {
|
|
30210
|
-
type: Jsep.BINARY_EXP,
|
|
30211
|
-
operator: biop,
|
|
30212
|
-
left,
|
|
30213
|
-
right
|
|
30214
|
-
};
|
|
30215
|
-
stack.push(node);
|
|
30216
|
-
}
|
|
30217
|
-
node = this.gobbleToken();
|
|
30218
|
-
if (!node) {
|
|
30219
|
-
this.throwError("Expected expression after " + cur_biop);
|
|
30220
|
-
}
|
|
30221
|
-
stack.push(biop_info, node);
|
|
30222
|
-
}
|
|
30223
|
-
i = stack.length - 1;
|
|
30224
|
-
node = stack[i];
|
|
30225
|
-
while (i > 1) {
|
|
30226
|
-
node = {
|
|
30227
|
-
type: Jsep.BINARY_EXP,
|
|
30228
|
-
operator: stack[i - 1].value,
|
|
30229
|
-
left: stack[i - 2],
|
|
30230
|
-
right: node
|
|
30231
|
-
};
|
|
30232
|
-
i -= 2;
|
|
30233
|
-
}
|
|
30234
|
-
return node;
|
|
30235
|
-
}
|
|
30236
|
-
gobbleToken() {
|
|
30237
|
-
let ch, to_check, tc_len, node;
|
|
30238
|
-
this.gobbleSpaces();
|
|
30239
|
-
node = this.searchHook("gobble-token");
|
|
30240
|
-
if (node) {
|
|
30241
|
-
return this.runHook("after-token", node);
|
|
30242
|
-
}
|
|
30243
|
-
ch = this.code;
|
|
30244
|
-
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
30245
|
-
return this.gobbleNumericLiteral();
|
|
30246
|
-
}
|
|
30247
|
-
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
30248
|
-
node = this.gobbleStringLiteral();
|
|
30249
|
-
} else if (ch === Jsep.OBRACK_CODE) {
|
|
30250
|
-
node = this.gobbleArray();
|
|
30251
|
-
} else {
|
|
30252
|
-
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
30253
|
-
tc_len = to_check.length;
|
|
30254
|
-
while (tc_len > 0) {
|
|
30255
|
-
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)))) {
|
|
30256
|
-
this.index += tc_len;
|
|
30257
|
-
const argument = this.gobbleToken();
|
|
30258
|
-
if (!argument) {
|
|
30259
|
-
this.throwError("missing unaryOp argument");
|
|
30260
|
-
}
|
|
30261
|
-
return this.runHook("after-token", {
|
|
30262
|
-
type: Jsep.UNARY_EXP,
|
|
30263
|
-
operator: to_check,
|
|
30264
|
-
argument,
|
|
30265
|
-
prefix: true
|
|
30266
|
-
});
|
|
30267
|
-
}
|
|
30268
|
-
to_check = to_check.substr(0, --tc_len);
|
|
30269
|
-
}
|
|
30270
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
30271
|
-
node = this.gobbleIdentifier();
|
|
30272
|
-
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
30273
|
-
node = {
|
|
30274
|
-
type: Jsep.LITERAL,
|
|
30275
|
-
value: Jsep.literals[node.name],
|
|
30276
|
-
raw: node.name
|
|
30277
|
-
};
|
|
30278
|
-
} else if (node.name === Jsep.this_str) {
|
|
30279
|
-
node = {
|
|
30280
|
-
type: Jsep.THIS_EXP
|
|
30281
|
-
};
|
|
30282
|
-
}
|
|
30283
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
30284
|
-
node = this.gobbleGroup();
|
|
30285
|
-
}
|
|
30286
|
-
}
|
|
30287
|
-
if (!node) {
|
|
30288
|
-
return this.runHook("after-token", false);
|
|
30289
|
-
}
|
|
30290
|
-
node = this.gobbleTokenProperty(node);
|
|
30291
|
-
return this.runHook("after-token", node);
|
|
30292
|
-
}
|
|
30293
|
-
gobbleTokenProperty(node) {
|
|
30294
|
-
this.gobbleSpaces();
|
|
30295
|
-
let ch = this.code;
|
|
30296
|
-
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
30297
|
-
let optional;
|
|
30298
|
-
if (ch === Jsep.QUMARK_CODE) {
|
|
30299
|
-
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
30300
|
-
break;
|
|
30301
|
-
}
|
|
30302
|
-
optional = true;
|
|
30303
|
-
this.index += 2;
|
|
30304
|
-
this.gobbleSpaces();
|
|
30305
|
-
ch = this.code;
|
|
30306
|
-
}
|
|
30307
|
-
this.index++;
|
|
30308
|
-
if (ch === Jsep.OBRACK_CODE) {
|
|
30309
|
-
node = {
|
|
30310
|
-
type: Jsep.MEMBER_EXP,
|
|
30311
|
-
computed: true,
|
|
30312
|
-
object: node,
|
|
30313
|
-
property: this.gobbleExpression()
|
|
30314
|
-
};
|
|
30315
|
-
if (!node.property) {
|
|
30316
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
30317
|
-
}
|
|
30318
|
-
this.gobbleSpaces();
|
|
30319
|
-
ch = this.code;
|
|
30320
|
-
if (ch !== Jsep.CBRACK_CODE) {
|
|
30321
|
-
this.throwError("Unclosed [");
|
|
30322
|
-
}
|
|
30323
|
-
this.index++;
|
|
30324
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
30325
|
-
node = {
|
|
30326
|
-
type: Jsep.CALL_EXP,
|
|
30327
|
-
arguments: this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
30328
|
-
callee: node
|
|
30329
|
-
};
|
|
30330
|
-
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
30331
|
-
if (optional) {
|
|
30332
|
-
this.index--;
|
|
30333
|
-
}
|
|
30334
|
-
this.gobbleSpaces();
|
|
30335
|
-
node = {
|
|
30336
|
-
type: Jsep.MEMBER_EXP,
|
|
30337
|
-
computed: false,
|
|
30338
|
-
object: node,
|
|
30339
|
-
property: this.gobbleIdentifier()
|
|
30340
|
-
};
|
|
30341
|
-
}
|
|
30342
|
-
if (optional) {
|
|
30343
|
-
node.optional = true;
|
|
30344
|
-
}
|
|
30345
|
-
this.gobbleSpaces();
|
|
30346
|
-
ch = this.code;
|
|
30347
|
-
}
|
|
30348
|
-
return node;
|
|
30349
|
-
}
|
|
30350
|
-
gobbleNumericLiteral() {
|
|
30351
|
-
let number = "", ch, chCode;
|
|
30352
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
30353
|
-
number += this.expr.charAt(this.index++);
|
|
30354
|
-
}
|
|
30355
|
-
if (this.code === Jsep.PERIOD_CODE) {
|
|
30356
|
-
number += this.expr.charAt(this.index++);
|
|
30357
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
30358
|
-
number += this.expr.charAt(this.index++);
|
|
30359
|
-
}
|
|
30360
|
-
}
|
|
30361
|
-
ch = this.char;
|
|
30362
|
-
if (ch === "e" || ch === "E") {
|
|
30363
|
-
number += this.expr.charAt(this.index++);
|
|
30364
|
-
ch = this.char;
|
|
30365
|
-
if (ch === "+" || ch === "-") {
|
|
30366
|
-
number += this.expr.charAt(this.index++);
|
|
30367
|
-
}
|
|
30368
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
30369
|
-
number += this.expr.charAt(this.index++);
|
|
30370
|
-
}
|
|
30371
|
-
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
30372
|
-
this.throwError("Expected exponent (" + number + this.char + ")");
|
|
30373
|
-
}
|
|
30374
|
-
}
|
|
30375
|
-
chCode = this.code;
|
|
30376
|
-
if (Jsep.isIdentifierStart(chCode)) {
|
|
30377
|
-
this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
|
|
30378
|
-
} else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
30379
|
-
this.throwError("Unexpected period");
|
|
30380
|
-
}
|
|
30381
|
-
return {
|
|
30382
|
-
type: Jsep.LITERAL,
|
|
30383
|
-
value: parseFloat(number),
|
|
30384
|
-
raw: number
|
|
30385
|
-
};
|
|
30386
|
-
}
|
|
30387
|
-
gobbleStringLiteral() {
|
|
30388
|
-
let str = "";
|
|
30389
|
-
const startIndex = this.index;
|
|
30390
|
-
const quote = this.expr.charAt(this.index++);
|
|
30391
|
-
let closed = false;
|
|
30392
|
-
while (this.index < this.expr.length) {
|
|
30393
|
-
let ch = this.expr.charAt(this.index++);
|
|
30394
|
-
if (ch === quote) {
|
|
30395
|
-
closed = true;
|
|
30396
|
-
break;
|
|
30397
|
-
} else if (ch === "\\") {
|
|
30398
|
-
ch = this.expr.charAt(this.index++);
|
|
30399
|
-
switch (ch) {
|
|
30400
|
-
case "n":
|
|
30401
|
-
str += `
|
|
30402
|
-
`;
|
|
30403
|
-
break;
|
|
30404
|
-
case "r":
|
|
30405
|
-
str += "\r";
|
|
30406
|
-
break;
|
|
30407
|
-
case "t":
|
|
30408
|
-
str += "\t";
|
|
30409
|
-
break;
|
|
30410
|
-
case "b":
|
|
30411
|
-
str += "\b";
|
|
30412
|
-
break;
|
|
30413
|
-
case "f":
|
|
30414
|
-
str += "\f";
|
|
30415
|
-
break;
|
|
30416
|
-
case "v":
|
|
30417
|
-
str += "\v";
|
|
30418
|
-
break;
|
|
30419
|
-
default:
|
|
30420
|
-
str += ch;
|
|
30421
|
-
}
|
|
30422
|
-
} else {
|
|
30423
|
-
str += ch;
|
|
30424
|
-
}
|
|
30425
|
-
}
|
|
30426
|
-
if (!closed) {
|
|
30427
|
-
this.throwError('Unclosed quote after "' + str + '"');
|
|
30428
|
-
}
|
|
30429
|
-
return {
|
|
30430
|
-
type: Jsep.LITERAL,
|
|
30431
|
-
value: str,
|
|
30432
|
-
raw: this.expr.substring(startIndex, this.index)
|
|
30433
|
-
};
|
|
30434
|
-
}
|
|
30435
|
-
gobbleIdentifier() {
|
|
30436
|
-
let ch = this.code, start = this.index;
|
|
30437
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
30438
|
-
this.index++;
|
|
30439
|
-
} else {
|
|
30440
|
-
this.throwError("Unexpected " + this.char);
|
|
30441
|
-
}
|
|
30442
|
-
while (this.index < this.expr.length) {
|
|
30443
|
-
ch = this.code;
|
|
30444
|
-
if (Jsep.isIdentifierPart(ch)) {
|
|
30445
|
-
this.index++;
|
|
30446
|
-
} else {
|
|
30447
|
-
break;
|
|
30448
|
-
}
|
|
30449
|
-
}
|
|
30450
|
-
return {
|
|
30451
|
-
type: Jsep.IDENTIFIER,
|
|
30452
|
-
name: this.expr.slice(start, this.index)
|
|
30453
|
-
};
|
|
30454
|
-
}
|
|
30455
|
-
gobbleArguments(termination) {
|
|
30456
|
-
const args = [];
|
|
30457
|
-
let closed = false;
|
|
30458
|
-
let separator_count = 0;
|
|
30459
|
-
while (this.index < this.expr.length) {
|
|
30460
|
-
this.gobbleSpaces();
|
|
30461
|
-
let ch_i = this.code;
|
|
30462
|
-
if (ch_i === termination) {
|
|
30463
|
-
closed = true;
|
|
30464
|
-
this.index++;
|
|
30465
|
-
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
30466
|
-
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
30467
|
-
}
|
|
30468
|
-
break;
|
|
30469
|
-
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
30470
|
-
this.index++;
|
|
30471
|
-
separator_count++;
|
|
30472
|
-
if (separator_count !== args.length) {
|
|
30473
|
-
if (termination === Jsep.CPAREN_CODE) {
|
|
30474
|
-
this.throwError("Unexpected token ,");
|
|
30475
|
-
} else if (termination === Jsep.CBRACK_CODE) {
|
|
30476
|
-
for (let arg = args.length;arg < separator_count; arg++) {
|
|
30477
|
-
args.push(null);
|
|
30478
|
-
}
|
|
30479
|
-
}
|
|
30480
|
-
}
|
|
30481
|
-
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
30482
|
-
this.throwError("Expected comma");
|
|
30483
|
-
} else {
|
|
30484
|
-
const node = this.gobbleExpression();
|
|
30485
|
-
if (!node || node.type === Jsep.COMPOUND) {
|
|
30486
|
-
this.throwError("Expected comma");
|
|
30487
|
-
}
|
|
30488
|
-
args.push(node);
|
|
30489
|
-
}
|
|
30490
|
-
}
|
|
30491
|
-
if (!closed) {
|
|
30492
|
-
this.throwError("Expected " + String.fromCharCode(termination));
|
|
30493
|
-
}
|
|
30494
|
-
return args;
|
|
30495
|
-
}
|
|
30496
|
-
gobbleGroup() {
|
|
30497
|
-
this.index++;
|
|
30498
|
-
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
30499
|
-
if (this.code === Jsep.CPAREN_CODE) {
|
|
30500
|
-
this.index++;
|
|
30501
|
-
if (nodes.length === 1) {
|
|
30502
|
-
return nodes[0];
|
|
30503
|
-
} else if (!nodes.length) {
|
|
30504
|
-
return false;
|
|
30505
|
-
} else {
|
|
30506
|
-
return {
|
|
30507
|
-
type: Jsep.SEQUENCE_EXP,
|
|
30508
|
-
expressions: nodes
|
|
30509
|
-
};
|
|
30510
|
-
}
|
|
30511
|
-
} else {
|
|
30512
|
-
this.throwError("Unclosed (");
|
|
30513
|
-
}
|
|
30514
|
-
}
|
|
30515
|
-
gobbleArray() {
|
|
30516
|
-
this.index++;
|
|
30517
|
-
return {
|
|
30518
|
-
type: Jsep.ARRAY_EXP,
|
|
30519
|
-
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
30520
|
-
};
|
|
30521
|
-
}
|
|
30522
|
-
}
|
|
30523
|
-
var hooks = new Hooks;
|
|
30524
|
-
Object.assign(Jsep, {
|
|
30525
|
-
hooks,
|
|
30526
|
-
plugins: new Plugins(Jsep),
|
|
30527
|
-
COMPOUND: "Compound",
|
|
30528
|
-
SEQUENCE_EXP: "SequenceExpression",
|
|
30529
|
-
IDENTIFIER: "Identifier",
|
|
30530
|
-
MEMBER_EXP: "MemberExpression",
|
|
30531
|
-
LITERAL: "Literal",
|
|
30532
|
-
THIS_EXP: "ThisExpression",
|
|
30533
|
-
CALL_EXP: "CallExpression",
|
|
30534
|
-
UNARY_EXP: "UnaryExpression",
|
|
30535
|
-
BINARY_EXP: "BinaryExpression",
|
|
30536
|
-
ARRAY_EXP: "ArrayExpression",
|
|
30537
|
-
TAB_CODE: 9,
|
|
30538
|
-
LF_CODE: 10,
|
|
30539
|
-
CR_CODE: 13,
|
|
30540
|
-
SPACE_CODE: 32,
|
|
30541
|
-
PERIOD_CODE: 46,
|
|
30542
|
-
COMMA_CODE: 44,
|
|
30543
|
-
SQUOTE_CODE: 39,
|
|
30544
|
-
DQUOTE_CODE: 34,
|
|
30545
|
-
OPAREN_CODE: 40,
|
|
30546
|
-
CPAREN_CODE: 41,
|
|
30547
|
-
OBRACK_CODE: 91,
|
|
30548
|
-
CBRACK_CODE: 93,
|
|
30549
|
-
QUMARK_CODE: 63,
|
|
30550
|
-
SEMCOL_CODE: 59,
|
|
30551
|
-
COLON_CODE: 58,
|
|
30552
|
-
unary_ops: {
|
|
30553
|
-
"-": 1,
|
|
30554
|
-
"!": 1,
|
|
30555
|
-
"~": 1,
|
|
30556
|
-
"+": 1
|
|
30557
|
-
},
|
|
30558
|
-
binary_ops: {
|
|
30559
|
-
"||": 1,
|
|
30560
|
-
"??": 1,
|
|
30561
|
-
"&&": 2,
|
|
30562
|
-
"|": 3,
|
|
30563
|
-
"^": 4,
|
|
30564
|
-
"&": 5,
|
|
30565
|
-
"==": 6,
|
|
30566
|
-
"!=": 6,
|
|
30567
|
-
"===": 6,
|
|
30568
|
-
"!==": 6,
|
|
30569
|
-
"<": 7,
|
|
30570
|
-
">": 7,
|
|
30571
|
-
"<=": 7,
|
|
30572
|
-
">=": 7,
|
|
30573
|
-
"<<": 8,
|
|
30574
|
-
">>": 8,
|
|
30575
|
-
">>>": 8,
|
|
30576
|
-
"+": 9,
|
|
30577
|
-
"-": 9,
|
|
30578
|
-
"*": 10,
|
|
30579
|
-
"/": 10,
|
|
30580
|
-
"%": 10,
|
|
30581
|
-
"**": 11
|
|
30582
|
-
},
|
|
30583
|
-
right_associative: new Set(["**"]),
|
|
30584
|
-
additional_identifier_chars: new Set(["$", "_"]),
|
|
30585
|
-
literals: {
|
|
30586
|
-
true: true,
|
|
30587
|
-
false: false,
|
|
30588
|
-
null: null
|
|
30589
|
-
},
|
|
30590
|
-
this_str: "this"
|
|
30591
|
-
});
|
|
30592
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
30593
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
30594
|
-
var jsep = (expr) => new Jsep(expr).parse();
|
|
30595
|
-
var stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
30596
|
-
});
|
|
30597
|
-
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === undefined).forEach((m) => {
|
|
30598
|
-
jsep[m] = Jsep[m];
|
|
30599
|
-
});
|
|
30600
|
-
jsep.Jsep = Jsep;
|
|
30601
|
-
var CONDITIONAL_EXP = "ConditionalExpression";
|
|
30602
|
-
var ternary = {
|
|
30603
|
-
name: "ternary",
|
|
30604
|
-
init(jsep2) {
|
|
30605
|
-
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
30606
|
-
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
30607
|
-
this.index++;
|
|
30608
|
-
const test = env.node;
|
|
30609
|
-
const consequent = this.gobbleExpression();
|
|
30610
|
-
if (!consequent) {
|
|
30611
|
-
this.throwError("Expected expression");
|
|
30612
|
-
}
|
|
30613
|
-
this.gobbleSpaces();
|
|
30614
|
-
if (this.code === jsep2.COLON_CODE) {
|
|
30615
|
-
this.index++;
|
|
30616
|
-
const alternate = this.gobbleExpression();
|
|
30617
|
-
if (!alternate) {
|
|
30618
|
-
this.throwError("Expected expression");
|
|
30619
|
-
}
|
|
30620
|
-
env.node = {
|
|
30621
|
-
type: CONDITIONAL_EXP,
|
|
30622
|
-
test,
|
|
30623
|
-
consequent,
|
|
30624
|
-
alternate
|
|
30625
|
-
};
|
|
30626
|
-
if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
|
|
30627
|
-
let newTest = test;
|
|
30628
|
-
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
30629
|
-
newTest = newTest.right;
|
|
30630
|
-
}
|
|
30631
|
-
env.node.test = newTest.right;
|
|
30632
|
-
newTest.right = env.node;
|
|
30633
|
-
env.node = test;
|
|
30634
|
-
}
|
|
30635
|
-
} else {
|
|
30636
|
-
this.throwError("Expected :");
|
|
30637
|
-
}
|
|
30638
|
-
}
|
|
30639
|
-
});
|
|
30640
|
-
}
|
|
30641
|
-
};
|
|
30642
|
-
jsep.plugins.register(ternary);
|
|
30643
|
-
var FSLASH_CODE = 47;
|
|
30644
|
-
var BSLASH_CODE = 92;
|
|
30645
|
-
var index = {
|
|
30646
|
-
name: "regex",
|
|
30647
|
-
init(jsep2) {
|
|
30648
|
-
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
30649
|
-
if (this.code === FSLASH_CODE) {
|
|
30650
|
-
const patternIndex = ++this.index;
|
|
30651
|
-
let inCharSet = false;
|
|
30652
|
-
while (this.index < this.expr.length) {
|
|
30653
|
-
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
30654
|
-
const pattern = this.expr.slice(patternIndex, this.index);
|
|
30655
|
-
let flags = "";
|
|
30656
|
-
while (++this.index < this.expr.length) {
|
|
30657
|
-
const code = this.code;
|
|
30658
|
-
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
30659
|
-
flags += this.char;
|
|
30660
|
-
} else {
|
|
30661
|
-
break;
|
|
30662
|
-
}
|
|
30663
|
-
}
|
|
30664
|
-
let value;
|
|
30665
|
-
try {
|
|
30666
|
-
value = new RegExp(pattern, flags);
|
|
30667
|
-
} catch (e) {
|
|
30668
|
-
this.throwError(e.message);
|
|
30669
|
-
}
|
|
30670
|
-
env.node = {
|
|
30671
|
-
type: jsep2.LITERAL,
|
|
30672
|
-
value,
|
|
30673
|
-
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
30674
|
-
};
|
|
30675
|
-
env.node = this.gobbleTokenProperty(env.node);
|
|
30676
|
-
return env.node;
|
|
30677
|
-
}
|
|
30678
|
-
if (this.code === jsep2.OBRACK_CODE) {
|
|
30679
|
-
inCharSet = true;
|
|
30680
|
-
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
30681
|
-
inCharSet = false;
|
|
30682
|
-
}
|
|
30683
|
-
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
30684
|
-
}
|
|
30685
|
-
this.throwError("Unclosed Regex");
|
|
30686
|
-
}
|
|
30687
|
-
});
|
|
30688
|
-
}
|
|
30689
|
-
};
|
|
30690
|
-
var PLUS_CODE = 43;
|
|
30691
|
-
var MINUS_CODE = 45;
|
|
30692
|
-
var plugin = {
|
|
30693
|
-
name: "assignment",
|
|
30694
|
-
assignmentOperators: new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
30695
|
-
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
30696
|
-
assignmentPrecedence: 0.9,
|
|
30697
|
-
init(jsep2) {
|
|
30698
|
-
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
30699
|
-
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
30700
|
-
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
30701
|
-
const code = this.code;
|
|
30702
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
30703
|
-
this.index += 2;
|
|
30704
|
-
env.node = {
|
|
30705
|
-
type: "UpdateExpression",
|
|
30706
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
30707
|
-
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
30708
|
-
prefix: true
|
|
30709
|
-
};
|
|
30710
|
-
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
30711
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
30712
|
-
}
|
|
30713
|
-
}
|
|
30714
|
-
});
|
|
30715
|
-
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
30716
|
-
if (env.node) {
|
|
30717
|
-
const code = this.code;
|
|
30718
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
30719
|
-
if (!updateNodeTypes.includes(env.node.type)) {
|
|
30720
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
30721
|
-
}
|
|
30722
|
-
this.index += 2;
|
|
30723
|
-
env.node = {
|
|
30724
|
-
type: "UpdateExpression",
|
|
30725
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
30726
|
-
argument: env.node,
|
|
30727
|
-
prefix: false
|
|
30728
|
-
};
|
|
30729
|
-
}
|
|
30730
|
-
}
|
|
30731
|
-
});
|
|
30732
|
-
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
30733
|
-
if (env.node) {
|
|
30734
|
-
updateBinariesToAssignments(env.node);
|
|
30735
|
-
}
|
|
30736
|
-
});
|
|
30737
|
-
function updateBinariesToAssignments(node) {
|
|
30738
|
-
if (plugin.assignmentOperators.has(node.operator)) {
|
|
30739
|
-
node.type = "AssignmentExpression";
|
|
30740
|
-
updateBinariesToAssignments(node.left);
|
|
30741
|
-
updateBinariesToAssignments(node.right);
|
|
30742
|
-
} else if (!node.operator) {
|
|
30743
|
-
Object.values(node).forEach((val) => {
|
|
30744
|
-
if (val && typeof val === "object") {
|
|
30745
|
-
updateBinariesToAssignments(val);
|
|
30746
|
-
}
|
|
30747
|
-
});
|
|
30748
|
-
}
|
|
30749
|
-
}
|
|
30750
|
-
}
|
|
30751
|
-
};
|
|
30752
|
-
jsep.plugins.register(index, plugin);
|
|
30753
|
-
jsep.addUnaryOp("typeof");
|
|
30754
|
-
jsep.addUnaryOp("void");
|
|
30755
|
-
jsep.addLiteral("null", null);
|
|
30756
|
-
jsep.addLiteral("undefined", undefined);
|
|
30757
|
-
var BLOCKED_PROTO_PROPERTIES = new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
30758
|
-
var SafeEval = {
|
|
30759
|
-
evalAst(ast, subs) {
|
|
30760
|
-
switch (ast.type) {
|
|
30761
|
-
case "BinaryExpression":
|
|
30762
|
-
case "LogicalExpression":
|
|
30763
|
-
return SafeEval.evalBinaryExpression(ast, subs);
|
|
30764
|
-
case "Compound":
|
|
30765
|
-
return SafeEval.evalCompound(ast, subs);
|
|
30766
|
-
case "ConditionalExpression":
|
|
30767
|
-
return SafeEval.evalConditionalExpression(ast, subs);
|
|
30768
|
-
case "Identifier":
|
|
30769
|
-
return SafeEval.evalIdentifier(ast, subs);
|
|
30770
|
-
case "Literal":
|
|
30771
|
-
return SafeEval.evalLiteral(ast, subs);
|
|
30772
|
-
case "MemberExpression":
|
|
30773
|
-
return SafeEval.evalMemberExpression(ast, subs);
|
|
30774
|
-
case "UnaryExpression":
|
|
30775
|
-
return SafeEval.evalUnaryExpression(ast, subs);
|
|
30776
|
-
case "ArrayExpression":
|
|
30777
|
-
return SafeEval.evalArrayExpression(ast, subs);
|
|
30778
|
-
case "CallExpression":
|
|
30779
|
-
return SafeEval.evalCallExpression(ast, subs);
|
|
30780
|
-
case "AssignmentExpression":
|
|
30781
|
-
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
30782
|
-
default:
|
|
30783
|
-
throw SyntaxError("Unexpected expression", ast);
|
|
30784
|
-
}
|
|
30785
|
-
},
|
|
30786
|
-
evalBinaryExpression(ast, subs) {
|
|
30787
|
-
const result = {
|
|
30788
|
-
"||": (a, b) => a || b(),
|
|
30789
|
-
"&&": (a, b) => a && b(),
|
|
30790
|
-
"|": (a, b) => a | b(),
|
|
30791
|
-
"^": (a, b) => a ^ b(),
|
|
30792
|
-
"&": (a, b) => a & b(),
|
|
30793
|
-
"==": (a, b) => a == b(),
|
|
30794
|
-
"!=": (a, b) => a != b(),
|
|
30795
|
-
"===": (a, b) => a === b(),
|
|
30796
|
-
"!==": (a, b) => a !== b(),
|
|
30797
|
-
"<": (a, b) => a < b(),
|
|
30798
|
-
">": (a, b) => a > b(),
|
|
30799
|
-
"<=": (a, b) => a <= b(),
|
|
30800
|
-
">=": (a, b) => a >= b(),
|
|
30801
|
-
"<<": (a, b) => a << b(),
|
|
30802
|
-
">>": (a, b) => a >> b(),
|
|
30803
|
-
">>>": (a, b) => a >>> b(),
|
|
30804
|
-
"+": (a, b) => a + b(),
|
|
30805
|
-
"-": (a, b) => a - b(),
|
|
30806
|
-
"*": (a, b) => a * b(),
|
|
30807
|
-
"/": (a, b) => a / b(),
|
|
30808
|
-
"%": (a, b) => a % b()
|
|
30809
|
-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
30810
|
-
return result;
|
|
30811
|
-
},
|
|
30812
|
-
evalCompound(ast, subs) {
|
|
30813
|
-
let last;
|
|
30814
|
-
for (let i = 0;i < ast.body.length; i++) {
|
|
30815
|
-
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
30816
|
-
i += 1;
|
|
30817
|
-
}
|
|
30818
|
-
const expr = ast.body[i];
|
|
30819
|
-
last = SafeEval.evalAst(expr, subs);
|
|
30820
|
-
}
|
|
30821
|
-
return last;
|
|
30822
|
-
},
|
|
30823
|
-
evalConditionalExpression(ast, subs) {
|
|
30824
|
-
if (SafeEval.evalAst(ast.test, subs)) {
|
|
30825
|
-
return SafeEval.evalAst(ast.consequent, subs);
|
|
30826
|
-
}
|
|
30827
|
-
return SafeEval.evalAst(ast.alternate, subs);
|
|
30828
|
-
},
|
|
30829
|
-
evalIdentifier(ast, subs) {
|
|
30830
|
-
if (Object.hasOwn(subs, ast.name)) {
|
|
30831
|
-
return subs[ast.name];
|
|
30832
|
-
}
|
|
30833
|
-
throw ReferenceError(`${ast.name} is not defined`);
|
|
30834
|
-
},
|
|
30835
|
-
evalLiteral(ast) {
|
|
30836
|
-
return ast.value;
|
|
30837
|
-
},
|
|
30838
|
-
evalMemberExpression(ast, subs) {
|
|
30839
|
-
const prop = String(ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name);
|
|
30840
|
-
const obj = SafeEval.evalAst(ast.object, subs);
|
|
30841
|
-
if (obj === undefined || obj === null) {
|
|
30842
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
30843
|
-
}
|
|
30844
|
-
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
30845
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
30846
|
-
}
|
|
30847
|
-
const result = obj[prop];
|
|
30848
|
-
if (typeof result === "function") {
|
|
30849
|
-
return result.bind(obj);
|
|
30850
|
-
}
|
|
30851
|
-
return result;
|
|
30852
|
-
},
|
|
30853
|
-
evalUnaryExpression(ast, subs) {
|
|
30854
|
-
const result = {
|
|
30855
|
-
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
30856
|
-
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
30857
|
-
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
30858
|
-
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
30859
|
-
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
30860
|
-
void: (a) => void SafeEval.evalAst(a, subs)
|
|
30861
|
-
}[ast.operator](ast.argument);
|
|
30862
|
-
return result;
|
|
30863
|
-
},
|
|
30864
|
-
evalArrayExpression(ast, subs) {
|
|
30865
|
-
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
30866
|
-
},
|
|
30867
|
-
evalCallExpression(ast, subs) {
|
|
30868
|
-
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
30869
|
-
const func = SafeEval.evalAst(ast.callee, subs);
|
|
30870
|
-
if (func === Function) {
|
|
30871
|
-
throw new Error("Function constructor is disabled");
|
|
30872
|
-
}
|
|
30873
|
-
return func(...args);
|
|
30874
|
-
},
|
|
30875
|
-
evalAssignmentExpression(ast, subs) {
|
|
30876
|
-
if (ast.left.type !== "Identifier") {
|
|
30877
|
-
throw SyntaxError("Invalid left-hand side in assignment");
|
|
30878
|
-
}
|
|
30879
|
-
const id = ast.left.name;
|
|
30880
|
-
const value = SafeEval.evalAst(ast.right, subs);
|
|
30881
|
-
subs[id] = value;
|
|
30882
|
-
return subs[id];
|
|
30883
|
-
}
|
|
30884
|
-
};
|
|
30885
|
-
|
|
30886
|
-
class SafeScript {
|
|
30887
|
-
constructor(expr) {
|
|
30888
|
-
this.code = expr;
|
|
30889
|
-
this.ast = jsep(this.code);
|
|
30890
|
-
}
|
|
30891
|
-
runInNewContext(context) {
|
|
30892
|
-
const keyMap = Object.assign(Object.create(null), context);
|
|
30893
|
-
return SafeEval.evalAst(this.ast, keyMap);
|
|
30894
|
-
}
|
|
30895
|
-
}
|
|
30896
|
-
function push(arr, item) {
|
|
30897
|
-
arr = arr.slice();
|
|
30898
|
-
arr.push(item);
|
|
30899
|
-
return arr;
|
|
30900
|
-
}
|
|
30901
|
-
function unshift(item, arr) {
|
|
30902
|
-
arr = arr.slice();
|
|
30903
|
-
arr.unshift(item);
|
|
30904
|
-
return arr;
|
|
30905
|
-
}
|
|
30906
|
-
|
|
30907
|
-
class NewError extends Error {
|
|
30908
|
-
constructor(value) {
|
|
30909
|
-
super('JSONPath should not be called with "new" (it prevents return ' + "of (unwrapped) scalar values)");
|
|
30910
|
-
this.avoidNew = true;
|
|
30911
|
-
this.value = value;
|
|
30912
|
-
this.name = "NewError";
|
|
30913
|
-
}
|
|
30914
|
-
}
|
|
30915
|
-
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
30916
|
-
if (!(this instanceof JSONPath)) {
|
|
30917
|
-
try {
|
|
30918
|
-
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
30919
|
-
} catch (e) {
|
|
30920
|
-
if (!e.avoidNew) {
|
|
30921
|
-
throw e;
|
|
30922
|
-
}
|
|
30923
|
-
return e.value;
|
|
30924
|
-
}
|
|
30925
|
-
}
|
|
30926
|
-
if (typeof opts === "string") {
|
|
30927
|
-
otherTypeCallback = callback;
|
|
30928
|
-
callback = obj;
|
|
30929
|
-
obj = expr;
|
|
30930
|
-
expr = opts;
|
|
30931
|
-
opts = null;
|
|
30932
|
-
}
|
|
30933
|
-
const optObj = opts && typeof opts === "object";
|
|
30934
|
-
opts = opts || {};
|
|
30935
|
-
this.json = opts.json || obj;
|
|
30936
|
-
this.path = opts.path || expr;
|
|
30937
|
-
this.resultType = opts.resultType || "value";
|
|
30938
|
-
this.flatten = opts.flatten || false;
|
|
30939
|
-
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
30940
|
-
this.sandbox = opts.sandbox || {};
|
|
30941
|
-
this.eval = opts.eval === undefined ? "safe" : opts.eval;
|
|
30942
|
-
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
30943
|
-
this.parent = opts.parent || null;
|
|
30944
|
-
this.parentProperty = opts.parentProperty || null;
|
|
30945
|
-
this.callback = opts.callback || callback || null;
|
|
30946
|
-
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
30947
|
-
throw new TypeError("You must supply an otherTypeCallback callback option " + "with the @other() operator.");
|
|
30948
|
-
};
|
|
30949
|
-
if (opts.autostart !== false) {
|
|
30950
|
-
const args = {
|
|
30951
|
-
path: optObj ? opts.path : expr
|
|
30952
|
-
};
|
|
30953
|
-
if (!optObj) {
|
|
30954
|
-
args.json = obj;
|
|
30955
|
-
} else if ("json" in opts) {
|
|
30956
|
-
args.json = opts.json;
|
|
30957
|
-
}
|
|
30958
|
-
const ret = this.evaluate(args);
|
|
30959
|
-
if (!ret || typeof ret !== "object") {
|
|
30960
|
-
throw new NewError(ret);
|
|
30961
|
-
}
|
|
30962
|
-
return ret;
|
|
30963
|
-
}
|
|
30964
|
-
}
|
|
30965
|
-
JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
|
|
30966
|
-
let currParent = this.parent, currParentProperty = this.parentProperty;
|
|
30967
|
-
let {
|
|
30968
|
-
flatten,
|
|
30969
|
-
wrap
|
|
30970
|
-
} = this;
|
|
30971
|
-
this.currResultType = this.resultType;
|
|
30972
|
-
this.currEval = this.eval;
|
|
30973
|
-
this.currSandbox = this.sandbox;
|
|
30974
|
-
callback = callback || this.callback;
|
|
30975
|
-
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
30976
|
-
json = json || this.json;
|
|
30977
|
-
expr = expr || this.path;
|
|
30978
|
-
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
30979
|
-
if (!expr.path && expr.path !== "") {
|
|
30980
|
-
throw new TypeError('You must supply a "path" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
30981
|
-
}
|
|
30982
|
-
if (!Object.hasOwn(expr, "json")) {
|
|
30983
|
-
throw new TypeError('You must supply a "json" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
30984
|
-
}
|
|
30985
|
-
({
|
|
30986
|
-
json
|
|
30987
|
-
} = expr);
|
|
30988
|
-
flatten = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten;
|
|
30989
|
-
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
30990
|
-
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
30991
|
-
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
30992
|
-
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
30993
|
-
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
30994
|
-
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
30995
|
-
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
30996
|
-
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
30997
|
-
expr = expr.path;
|
|
30998
|
-
}
|
|
30999
|
-
currParent = currParent || null;
|
|
31000
|
-
currParentProperty = currParentProperty || null;
|
|
31001
|
-
if (Array.isArray(expr)) {
|
|
31002
|
-
expr = JSONPath.toPathString(expr);
|
|
31003
|
-
}
|
|
31004
|
-
if (!expr && expr !== "" || !json) {
|
|
31005
|
-
return;
|
|
31006
|
-
}
|
|
31007
|
-
const exprList = JSONPath.toPathArray(expr);
|
|
31008
|
-
if (exprList[0] === "$" && exprList.length > 1) {
|
|
31009
|
-
exprList.shift();
|
|
31010
|
-
}
|
|
31011
|
-
this._hasParentSelector = null;
|
|
31012
|
-
const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea) {
|
|
31013
|
-
return ea && !ea.isParentSelector;
|
|
31014
|
-
});
|
|
31015
|
-
if (!result.length) {
|
|
31016
|
-
return wrap ? [] : undefined;
|
|
31017
|
-
}
|
|
31018
|
-
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
31019
|
-
return this._getPreferredOutput(result[0]);
|
|
31020
|
-
}
|
|
31021
|
-
return result.reduce((rslt, ea) => {
|
|
31022
|
-
const valOrPath = this._getPreferredOutput(ea);
|
|
31023
|
-
if (flatten && Array.isArray(valOrPath)) {
|
|
31024
|
-
rslt = rslt.concat(valOrPath);
|
|
31025
|
-
} else {
|
|
31026
|
-
rslt.push(valOrPath);
|
|
31027
|
-
}
|
|
31028
|
-
return rslt;
|
|
31029
|
-
}, []);
|
|
31030
|
-
};
|
|
31031
|
-
JSONPath.prototype._getPreferredOutput = function(ea) {
|
|
31032
|
-
const resultType = this.currResultType;
|
|
31033
|
-
switch (resultType) {
|
|
31034
|
-
case "all": {
|
|
31035
|
-
const path4 = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
31036
|
-
ea.pointer = JSONPath.toPointer(path4);
|
|
31037
|
-
ea.path = typeof ea.path === "string" ? ea.path : JSONPath.toPathString(ea.path);
|
|
31038
|
-
return ea;
|
|
31039
|
-
}
|
|
31040
|
-
case "value":
|
|
31041
|
-
case "parent":
|
|
31042
|
-
case "parentProperty":
|
|
31043
|
-
return ea[resultType];
|
|
31044
|
-
case "path":
|
|
31045
|
-
return JSONPath.toPathString(ea[resultType]);
|
|
31046
|
-
case "pointer":
|
|
31047
|
-
return JSONPath.toPointer(ea.path);
|
|
31048
|
-
default:
|
|
31049
|
-
throw new TypeError("Unknown result type");
|
|
31050
|
-
}
|
|
31051
|
-
};
|
|
31052
|
-
JSONPath.prototype._handleCallback = function(fullRetObj, callback, type) {
|
|
31053
|
-
if (callback) {
|
|
31054
|
-
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
31055
|
-
fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
|
|
31056
|
-
callback(preferredOutput, type, fullRetObj);
|
|
31057
|
-
}
|
|
31058
|
-
};
|
|
31059
|
-
JSONPath.prototype._trace = function(expr, val, path4, parent, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
31060
|
-
let retObj;
|
|
31061
|
-
if (!expr.length) {
|
|
31062
|
-
retObj = {
|
|
31063
|
-
path: path4,
|
|
31064
|
-
value: val,
|
|
31065
|
-
parent,
|
|
31066
|
-
parentProperty: parentPropName,
|
|
31067
|
-
hasArrExpr
|
|
31068
|
-
};
|
|
31069
|
-
this._handleCallback(retObj, callback, "value");
|
|
31070
|
-
return retObj;
|
|
31071
|
-
}
|
|
31072
|
-
const loc = expr[0], x = expr.slice(1);
|
|
31073
|
-
const ret = [];
|
|
31074
|
-
function addRet(elems) {
|
|
31075
|
-
if (Array.isArray(elems)) {
|
|
31076
|
-
elems.forEach((t) => {
|
|
31077
|
-
ret.push(t);
|
|
31078
|
-
});
|
|
31079
|
-
} else {
|
|
31080
|
-
ret.push(elems);
|
|
31081
|
-
}
|
|
31082
|
-
}
|
|
31083
|
-
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
31084
|
-
addRet(this._trace(x, val[loc], push(path4, loc), val, loc, callback, hasArrExpr));
|
|
31085
|
-
} else if (loc === "*") {
|
|
31086
|
-
this._walk(val, (m) => {
|
|
31087
|
-
addRet(this._trace(x, val[m], push(path4, m), val, m, callback, true, true));
|
|
31088
|
-
});
|
|
31089
|
-
} else if (loc === "..") {
|
|
31090
|
-
addRet(this._trace(x, val, path4, parent, parentPropName, callback, hasArrExpr));
|
|
31091
|
-
this._walk(val, (m) => {
|
|
31092
|
-
if (typeof val[m] === "object") {
|
|
31093
|
-
addRet(this._trace(expr.slice(), val[m], push(path4, m), val, m, callback, true));
|
|
31094
|
-
}
|
|
31095
|
-
});
|
|
31096
|
-
} else if (loc === "^") {
|
|
31097
|
-
this._hasParentSelector = true;
|
|
31098
|
-
return {
|
|
31099
|
-
path: path4.slice(0, -1),
|
|
31100
|
-
expr: x,
|
|
31101
|
-
isParentSelector: true
|
|
31102
|
-
};
|
|
31103
|
-
} else if (loc === "~") {
|
|
31104
|
-
retObj = {
|
|
31105
|
-
path: push(path4, loc),
|
|
31106
|
-
value: parentPropName,
|
|
31107
|
-
parent,
|
|
31108
|
-
parentProperty: null
|
|
31109
|
-
};
|
|
31110
|
-
this._handleCallback(retObj, callback, "property");
|
|
31111
|
-
return retObj;
|
|
31112
|
-
} else if (loc === "$") {
|
|
31113
|
-
addRet(this._trace(x, val, path4, null, null, callback, hasArrExpr));
|
|
31114
|
-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
31115
|
-
addRet(this._slice(loc, x, val, path4, parent, parentPropName, callback));
|
|
31116
|
-
} else if (loc.indexOf("?(") === 0) {
|
|
31117
|
-
if (this.currEval === false) {
|
|
31118
|
-
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
31119
|
-
}
|
|
31120
|
-
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
31121
|
-
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
31122
|
-
if (nested) {
|
|
31123
|
-
this._walk(val, (m) => {
|
|
31124
|
-
const npath = [nested[2]];
|
|
31125
|
-
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
31126
|
-
const filterResults = this._trace(npath, nvalue, path4, parent, parentPropName, callback, true);
|
|
31127
|
-
if (filterResults.length > 0) {
|
|
31128
|
-
addRet(this._trace(x, val[m], push(path4, m), val, m, callback, true));
|
|
31129
|
-
}
|
|
31130
|
-
});
|
|
31131
|
-
} else {
|
|
31132
|
-
this._walk(val, (m) => {
|
|
31133
|
-
if (this._eval(safeLoc, val[m], m, path4, parent, parentPropName)) {
|
|
31134
|
-
addRet(this._trace(x, val[m], push(path4, m), val, m, callback, true));
|
|
31135
|
-
}
|
|
31136
|
-
});
|
|
31137
|
-
}
|
|
31138
|
-
} else if (loc[0] === "(") {
|
|
31139
|
-
if (this.currEval === false) {
|
|
31140
|
-
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
31141
|
-
}
|
|
31142
|
-
addRet(this._trace(unshift(this._eval(loc, val, path4.at(-1), path4.slice(0, -1), parent, parentPropName), x), val, path4, parent, parentPropName, callback, hasArrExpr));
|
|
31143
|
-
} else if (loc[0] === "@") {
|
|
31144
|
-
let addType = false;
|
|
31145
|
-
const valueType = loc.slice(1, -2);
|
|
31146
|
-
switch (valueType) {
|
|
31147
|
-
case "scalar":
|
|
31148
|
-
if (!val || !["object", "function"].includes(typeof val)) {
|
|
31149
|
-
addType = true;
|
|
31150
|
-
}
|
|
31151
|
-
break;
|
|
31152
|
-
case "boolean":
|
|
31153
|
-
case "string":
|
|
31154
|
-
case "undefined":
|
|
31155
|
-
case "function":
|
|
31156
|
-
if (typeof val === valueType) {
|
|
31157
|
-
addType = true;
|
|
31158
|
-
}
|
|
31159
|
-
break;
|
|
31160
|
-
case "integer":
|
|
31161
|
-
if (Number.isFinite(val) && !(val % 1)) {
|
|
31162
|
-
addType = true;
|
|
31163
|
-
}
|
|
31164
|
-
break;
|
|
31165
|
-
case "number":
|
|
31166
|
-
if (Number.isFinite(val)) {
|
|
31167
|
-
addType = true;
|
|
31168
|
-
}
|
|
31169
|
-
break;
|
|
31170
|
-
case "nonFinite":
|
|
31171
|
-
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
31172
|
-
addType = true;
|
|
31173
|
-
}
|
|
31174
|
-
break;
|
|
31175
|
-
case "object":
|
|
31176
|
-
if (val && typeof val === valueType) {
|
|
31177
|
-
addType = true;
|
|
31178
|
-
}
|
|
31179
|
-
break;
|
|
31180
|
-
case "array":
|
|
31181
|
-
if (Array.isArray(val)) {
|
|
31182
|
-
addType = true;
|
|
31183
|
-
}
|
|
31184
|
-
break;
|
|
31185
|
-
case "other":
|
|
31186
|
-
addType = this.currOtherTypeCallback(val, path4, parent, parentPropName);
|
|
31187
|
-
break;
|
|
31188
|
-
case "null":
|
|
31189
|
-
if (val === null) {
|
|
31190
|
-
addType = true;
|
|
31191
|
-
}
|
|
31192
|
-
break;
|
|
31193
|
-
default:
|
|
31194
|
-
throw new TypeError("Unknown value type " + valueType);
|
|
31195
|
-
}
|
|
31196
|
-
if (addType) {
|
|
31197
|
-
retObj = {
|
|
31198
|
-
path: path4,
|
|
31199
|
-
value: val,
|
|
31200
|
-
parent,
|
|
31201
|
-
parentProperty: parentPropName
|
|
31202
|
-
};
|
|
31203
|
-
this._handleCallback(retObj, callback, "value");
|
|
31204
|
-
return retObj;
|
|
31205
|
-
}
|
|
31206
|
-
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
31207
|
-
const locProp = loc.slice(1);
|
|
31208
|
-
addRet(this._trace(x, val[locProp], push(path4, locProp), val, locProp, callback, hasArrExpr, true));
|
|
31209
|
-
} else if (loc.includes(",")) {
|
|
31210
|
-
const parts = loc.split(",");
|
|
31211
|
-
for (const part of parts) {
|
|
31212
|
-
addRet(this._trace(unshift(part, x), val, path4, parent, parentPropName, callback, true));
|
|
31213
|
-
}
|
|
31214
|
-
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
31215
|
-
addRet(this._trace(x, val[loc], push(path4, loc), val, loc, callback, hasArrExpr, true));
|
|
31216
|
-
}
|
|
31217
|
-
if (this._hasParentSelector) {
|
|
31218
|
-
for (let t = 0;t < ret.length; t++) {
|
|
31219
|
-
const rett = ret[t];
|
|
31220
|
-
if (rett && rett.isParentSelector) {
|
|
31221
|
-
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
31222
|
-
if (Array.isArray(tmp)) {
|
|
31223
|
-
ret[t] = tmp[0];
|
|
31224
|
-
const tl = tmp.length;
|
|
31225
|
-
for (let tt = 1;tt < tl; tt++) {
|
|
31226
|
-
t++;
|
|
31227
|
-
ret.splice(t, 0, tmp[tt]);
|
|
31228
|
-
}
|
|
31229
|
-
} else {
|
|
31230
|
-
ret[t] = tmp;
|
|
31231
|
-
}
|
|
31232
|
-
}
|
|
31233
|
-
}
|
|
31234
|
-
}
|
|
31235
|
-
return ret;
|
|
31236
|
-
};
|
|
31237
|
-
JSONPath.prototype._walk = function(val, f) {
|
|
31238
|
-
if (Array.isArray(val)) {
|
|
31239
|
-
const n = val.length;
|
|
31240
|
-
for (let i = 0;i < n; i++) {
|
|
31241
|
-
f(i);
|
|
31242
|
-
}
|
|
31243
|
-
} else if (val && typeof val === "object") {
|
|
31244
|
-
Object.keys(val).forEach((m) => {
|
|
31245
|
-
f(m);
|
|
31246
|
-
});
|
|
31247
|
-
}
|
|
31248
|
-
};
|
|
31249
|
-
JSONPath.prototype._slice = function(loc, expr, val, path4, parent, parentPropName, callback) {
|
|
31250
|
-
if (!Array.isArray(val)) {
|
|
31251
|
-
return;
|
|
31252
|
-
}
|
|
31253
|
-
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
31254
|
-
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
31255
|
-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
31256
|
-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
31257
|
-
const ret = [];
|
|
31258
|
-
for (let i = start;i < end; i += step) {
|
|
31259
|
-
const tmp = this._trace(unshift(i, expr), val, path4, parent, parentPropName, callback, true);
|
|
31260
|
-
tmp.forEach((t) => {
|
|
31261
|
-
ret.push(t);
|
|
31262
|
-
});
|
|
31263
|
-
}
|
|
31264
|
-
return ret;
|
|
31265
|
-
};
|
|
31266
|
-
JSONPath.prototype._eval = function(code, _v, _vname, path4, parent, parentPropName) {
|
|
31267
|
-
this.currSandbox._$_parentProperty = parentPropName;
|
|
31268
|
-
this.currSandbox._$_parent = parent;
|
|
31269
|
-
this.currSandbox._$_property = _vname;
|
|
31270
|
-
this.currSandbox._$_root = this.json;
|
|
31271
|
-
this.currSandbox._$_v = _v;
|
|
31272
|
-
const containsPath = code.includes("@path");
|
|
31273
|
-
if (containsPath) {
|
|
31274
|
-
this.currSandbox._$_path = JSONPath.toPathString(path4.concat([_vname]));
|
|
31275
|
-
}
|
|
31276
|
-
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
31277
|
-
if (!JSONPath.cache[scriptCacheKey]) {
|
|
31278
|
-
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
31279
|
-
if (containsPath) {
|
|
31280
|
-
script = script.replaceAll("@path", "_$_path");
|
|
31281
|
-
}
|
|
31282
|
-
if (this.currEval === "safe" || this.currEval === true || this.currEval === undefined) {
|
|
31283
|
-
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
31284
|
-
} else if (this.currEval === "native") {
|
|
31285
|
-
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
31286
|
-
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
31287
|
-
const CurrEval = this.currEval;
|
|
31288
|
-
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
31289
|
-
} else if (typeof this.currEval === "function") {
|
|
31290
|
-
JSONPath.cache[scriptCacheKey] = {
|
|
31291
|
-
runInNewContext: (context) => this.currEval(script, context)
|
|
31292
|
-
};
|
|
31293
|
-
} else {
|
|
31294
|
-
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
31295
|
-
}
|
|
31296
|
-
}
|
|
31297
|
-
try {
|
|
31298
|
-
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
31299
|
-
} catch (e) {
|
|
31300
|
-
if (this.ignoreEvalErrors) {
|
|
31301
|
-
return false;
|
|
31302
|
-
}
|
|
31303
|
-
throw new Error("jsonPath: " + e.message + ": " + code);
|
|
31304
|
-
}
|
|
31305
|
-
};
|
|
31306
|
-
JSONPath.cache = {};
|
|
31307
|
-
JSONPath.toPathString = function(pathArr) {
|
|
31308
|
-
const x = pathArr, n = x.length;
|
|
31309
|
-
let p = "$";
|
|
31310
|
-
for (let i = 1;i < n; i++) {
|
|
31311
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
31312
|
-
p += /^[0-9*]+$/u.test(x[i]) ? "[" + x[i] + "]" : "['" + x[i] + "']";
|
|
31313
|
-
}
|
|
31314
|
-
}
|
|
31315
|
-
return p;
|
|
31316
|
-
};
|
|
31317
|
-
JSONPath.toPointer = function(pointer) {
|
|
31318
|
-
const x = pointer, n = x.length;
|
|
31319
|
-
let p = "";
|
|
31320
|
-
for (let i = 1;i < n; i++) {
|
|
31321
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
31322
|
-
p += "/" + x[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
|
|
31323
|
-
}
|
|
31324
|
-
}
|
|
31325
|
-
return p;
|
|
31326
|
-
};
|
|
31327
|
-
JSONPath.toPathArray = function(expr) {
|
|
31328
|
-
const {
|
|
31329
|
-
cache
|
|
31330
|
-
} = JSONPath;
|
|
31331
|
-
if (cache[expr]) {
|
|
31332
|
-
return cache[expr].concat();
|
|
31333
|
-
}
|
|
31334
|
-
const subx = [];
|
|
31335
|
-
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
31336
|
-
return "[#" + (subx.push($1) - 1) + "]";
|
|
31337
|
-
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
31338
|
-
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
31339
|
-
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
31340
|
-
return ";" + ups.split("").join(";") + ";";
|
|
31341
|
-
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
31342
|
-
const exprList = normalized.split(";").map(function(exp) {
|
|
31343
|
-
const match = exp.match(/#(\d+)/u);
|
|
31344
|
-
return !match || !match[1] ? exp : subx[match[1]];
|
|
31345
|
-
});
|
|
31346
|
-
cache[expr] = exprList;
|
|
31347
|
-
return cache[expr].concat();
|
|
31348
|
-
};
|
|
31349
|
-
JSONPath.prototype.safeVm = {
|
|
31350
|
-
Script: SafeScript
|
|
31351
|
-
};
|
|
31352
|
-
JSONPath.prototype.vm = vm;
|
|
31353
30315
|
// ../../common/src/polling/types.ts
|
|
31354
30316
|
var PollOutcome = {
|
|
31355
30317
|
Completed: "completed",
|
|
@@ -31384,6 +30346,17 @@ var FAILURE_STATUSES = new Set([
|
|
|
31384
30346
|
"canceled",
|
|
31385
30347
|
"stopped"
|
|
31386
30348
|
]);
|
|
30349
|
+
// ../../common/src/preview.ts
|
|
30350
|
+
var previewSlot = singleton2("PreviewBuild");
|
|
30351
|
+
function isPreviewBuild() {
|
|
30352
|
+
return previewSlot.get(false) ?? false;
|
|
30353
|
+
}
|
|
30354
|
+
Command.prototype.previewCommand = function(nameAndArgs, opts) {
|
|
30355
|
+
if (isPreviewBuild()) {
|
|
30356
|
+
return this.command(nameAndArgs, opts);
|
|
30357
|
+
}
|
|
30358
|
+
return new Command(nameAndArgs.split(/\s+/)[0] ?? nameAndArgs);
|
|
30359
|
+
};
|
|
31387
30360
|
// ../../common/src/screen-logger.ts
|
|
31388
30361
|
var ScreenLogger;
|
|
31389
30362
|
((ScreenLogger) => {
|
|
@@ -32597,3 +31570,5 @@ var program2 = new Command;
|
|
|
32597
31570
|
program2.name(metadata.commandPrefix).description(metadata.description).version(metadata.version);
|
|
32598
31571
|
await registerCommands(program2);
|
|
32599
31572
|
program2.parse(process.argv);
|
|
31573
|
+
|
|
31574
|
+
//# debugId=A5F8987B395C8A9964756E2164756E21
|