@uipath/audit-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 +828 -1784
- package/dist/tool.js +829 -1784
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -21649,9 +21649,9 @@ var require_utils = __commonJS((exports, module) => {
|
|
|
21649
21649
|
return typeof input === "string" ? encoder(input) : Buffer.alloc(0);
|
|
21650
21650
|
}
|
|
21651
21651
|
};
|
|
21652
|
-
Utils.readBigUInt64LE = function(buffer,
|
|
21653
|
-
const lo = buffer.readUInt32LE(
|
|
21654
|
-
const hi = buffer.readUInt32LE(
|
|
21652
|
+
Utils.readBigUInt64LE = function(buffer, index) {
|
|
21653
|
+
const lo = buffer.readUInt32LE(index);
|
|
21654
|
+
const hi = buffer.readUInt32LE(index + 4);
|
|
21655
21655
|
return hi * 4294967296 + lo;
|
|
21656
21656
|
};
|
|
21657
21657
|
Utils.fromDOS2Date = function(val) {
|
|
@@ -22689,9 +22689,9 @@ var require_zipFile = __commonJS((exports, module) => {
|
|
|
22689
22689
|
throw Utils.Errors.DISK_ENTRY_TOO_LARGE();
|
|
22690
22690
|
}
|
|
22691
22691
|
entryList = new Array(mainHeader.diskEntries);
|
|
22692
|
-
var
|
|
22692
|
+
var index = mainHeader.offset;
|
|
22693
22693
|
for (var i = 0;i < entryList.length; i++) {
|
|
22694
|
-
var tmp =
|
|
22694
|
+
var tmp = index, entry = new ZipEntry(opts, inBuffer);
|
|
22695
22695
|
entry.header = inBuffer.slice(tmp, tmp += Utils.Constants.CENHDR);
|
|
22696
22696
|
entry.entryName = inBuffer.slice(tmp, tmp += entry.header.fileNameLength);
|
|
22697
22697
|
if (entry.header.extraLength) {
|
|
@@ -22699,7 +22699,7 @@ var require_zipFile = __commonJS((exports, module) => {
|
|
|
22699
22699
|
}
|
|
22700
22700
|
if (entry.header.commentLength)
|
|
22701
22701
|
entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);
|
|
22702
|
-
|
|
22702
|
+
index += entry.header.centralHeaderSize;
|
|
22703
22703
|
entryList[i] = entry;
|
|
22704
22704
|
entryTable[entry.entryName] = entry;
|
|
22705
22705
|
}
|
|
@@ -22795,9 +22795,9 @@ var require_zipFile = __commonJS((exports, module) => {
|
|
|
22795
22795
|
readEntries();
|
|
22796
22796
|
}
|
|
22797
22797
|
const entry = entryTable[entryName];
|
|
22798
|
-
const
|
|
22799
|
-
if (
|
|
22800
|
-
entryList.splice(
|
|
22798
|
+
const index = entryList.indexOf(entry);
|
|
22799
|
+
if (index >= 0) {
|
|
22800
|
+
entryList.splice(index, 1);
|
|
22801
22801
|
delete entryTable[entryName];
|
|
22802
22802
|
mainHeader.totalEntries = entryList.length;
|
|
22803
22803
|
}
|
|
@@ -23545,7 +23545,7 @@ var {
|
|
|
23545
23545
|
var package_default = {
|
|
23546
23546
|
name: "@uipath/audit-tool",
|
|
23547
23547
|
license: "MIT",
|
|
23548
|
-
version: "1.
|
|
23548
|
+
version: "1.197.0-preview.59",
|
|
23549
23549
|
description: "CLI plugin for the UiPath Audit Service — query event sources, paginate events, and export ZIPs from the long-term store.",
|
|
23550
23550
|
private: false,
|
|
23551
23551
|
repository: {
|
|
@@ -23556,7 +23556,9 @@ var package_default = {
|
|
|
23556
23556
|
publishConfig: {
|
|
23557
23557
|
registry: "https://npm.pkg.github.com/@uipath"
|
|
23558
23558
|
},
|
|
23559
|
-
keywords: [
|
|
23559
|
+
keywords: [
|
|
23560
|
+
"cli-tool"
|
|
23561
|
+
],
|
|
23560
23562
|
type: "module",
|
|
23561
23563
|
main: "./dist/tool.js",
|
|
23562
23564
|
exports: {
|
|
@@ -23565,9 +23567,11 @@ var package_default = {
|
|
|
23565
23567
|
bin: {
|
|
23566
23568
|
"audit-tool": "./dist/index.js"
|
|
23567
23569
|
},
|
|
23568
|
-
files: [
|
|
23570
|
+
files: [
|
|
23571
|
+
"dist"
|
|
23572
|
+
],
|
|
23569
23573
|
scripts: {
|
|
23570
|
-
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",
|
|
23574
|
+
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",
|
|
23571
23575
|
package: "bun run build && bun pm pack",
|
|
23572
23576
|
lint: "biome check .",
|
|
23573
23577
|
"lint:fix": "biome check --write .",
|
|
@@ -23616,6 +23620,12 @@ function singleton(ctorOrName) {
|
|
|
23616
23620
|
};
|
|
23617
23621
|
}
|
|
23618
23622
|
|
|
23623
|
+
// ../../common/src/telemetry/global-telemetry-properties.ts
|
|
23624
|
+
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
23625
|
+
function getGlobalTelemetryProperties() {
|
|
23626
|
+
return telemetryPropsSlot.get();
|
|
23627
|
+
}
|
|
23628
|
+
|
|
23619
23629
|
// ../../common/src/sdk-user-agent.ts
|
|
23620
23630
|
var USER_AGENT_HEADER = "User-Agent";
|
|
23621
23631
|
var sdkUserAgentHostToken = singleton("SdkUserAgentHostToken");
|
|
@@ -23639,8 +23649,8 @@ function appendUserAgentToken(value, userAgent) {
|
|
|
23639
23649
|
function getEffectiveUserAgent(userAgent) {
|
|
23640
23650
|
return appendUserAgentToken(sdkUserAgentHostToken.get(), userAgent);
|
|
23641
23651
|
}
|
|
23642
|
-
function
|
|
23643
|
-
return
|
|
23652
|
+
function getHeaderName(headers, headerName) {
|
|
23653
|
+
return Object.keys(headers).find((key) => key.toLowerCase() === headerName.toLowerCase());
|
|
23644
23654
|
}
|
|
23645
23655
|
function getSdkUserAgentToken(pkg) {
|
|
23646
23656
|
const packageName = pkg.name.replace(/^@uipath\//, "");
|
|
@@ -23648,59 +23658,31 @@ function getSdkUserAgentToken(pkg) {
|
|
|
23648
23658
|
}
|
|
23649
23659
|
function addSdkUserAgentHeader(headers, userAgent) {
|
|
23650
23660
|
const result = { ...headers ?? {} };
|
|
23651
|
-
const
|
|
23652
|
-
|
|
23653
|
-
if (headerName) {
|
|
23654
|
-
result[headerName] = appendUserAgentToken(result[headerName], effectiveUserAgent);
|
|
23655
|
-
} else {
|
|
23656
|
-
result[USER_AGENT_HEADER] = effectiveUserAgent;
|
|
23657
|
-
}
|
|
23661
|
+
const headerName = getHeaderName(result, USER_AGENT_HEADER);
|
|
23662
|
+
result[headerName ?? USER_AGENT_HEADER] = appendUserAgentToken(headerName ? result[headerName] : undefined, getEffectiveUserAgent(userAgent));
|
|
23658
23663
|
return result;
|
|
23659
23664
|
}
|
|
23660
|
-
function
|
|
23661
|
-
|
|
23662
|
-
if (isHeadersLike(headers)) {
|
|
23663
|
-
headers.set(USER_AGENT_HEADER, appendUserAgentToken(headers.get(USER_AGENT_HEADER), effectiveUserAgent));
|
|
23664
|
-
return headers;
|
|
23665
|
-
}
|
|
23666
|
-
if (Array.isArray(headers)) {
|
|
23667
|
-
const result = headers.map((entry) => {
|
|
23668
|
-
const [key, value] = entry;
|
|
23669
|
-
return [key, value];
|
|
23670
|
-
});
|
|
23671
|
-
const headerIndex = result.findIndex(([key]) => key.toLowerCase() === USER_AGENT_HEADER.toLowerCase());
|
|
23672
|
-
if (headerIndex >= 0) {
|
|
23673
|
-
const [key, value] = result[headerIndex];
|
|
23674
|
-
result[headerIndex] = [
|
|
23675
|
-
key,
|
|
23676
|
-
appendUserAgentToken(value, effectiveUserAgent)
|
|
23677
|
-
];
|
|
23678
|
-
} else {
|
|
23679
|
-
result.push([USER_AGENT_HEADER, effectiveUserAgent]);
|
|
23680
|
-
}
|
|
23681
|
-
return result;
|
|
23682
|
-
}
|
|
23683
|
-
return addSdkUserAgentHeader(typeof headers === "object" && headers !== null ? { ...headers } : {}, effectiveUserAgent);
|
|
23665
|
+
function asHeaderRecord(headers) {
|
|
23666
|
+
return typeof headers === "object" && headers !== null ? { ...headers } : {};
|
|
23684
23667
|
}
|
|
23685
|
-
function
|
|
23668
|
+
function withForwardedHeadersInitOverride(initOverrides, forward) {
|
|
23686
23669
|
return async (requestContext) => {
|
|
23687
|
-
const
|
|
23670
|
+
const initWithHeaders = {
|
|
23688
23671
|
...requestContext.init,
|
|
23689
|
-
headers:
|
|
23672
|
+
headers: forward(asHeaderRecord(requestContext.init.headers))
|
|
23690
23673
|
};
|
|
23691
23674
|
const override = typeof initOverrides === "function" ? await initOverrides({
|
|
23692
23675
|
...requestContext,
|
|
23693
|
-
init:
|
|
23676
|
+
init: initWithHeaders
|
|
23694
23677
|
}) : initOverrides;
|
|
23695
23678
|
return {
|
|
23696
23679
|
...override ?? {},
|
|
23697
|
-
headers:
|
|
23680
|
+
headers: forward(asHeaderRecord(override?.headers ?? initWithHeaders.headers))
|
|
23698
23681
|
};
|
|
23699
23682
|
};
|
|
23700
23683
|
}
|
|
23701
|
-
function
|
|
23684
|
+
function installRequestHeaderForwarding(BaseApiClass, patchKey, forward) {
|
|
23702
23685
|
const prototype = BaseApiClass.prototype;
|
|
23703
|
-
const patchKey = userAgentPatchKey(userAgent);
|
|
23704
23686
|
if (prototype[patchKey]) {
|
|
23705
23687
|
return;
|
|
23706
23688
|
}
|
|
@@ -23708,13 +23690,16 @@ function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
|
23708
23690
|
throw new Error("Generated BaseAPI request function not found.");
|
|
23709
23691
|
}
|
|
23710
23692
|
const originalRequest = prototype.request;
|
|
23711
|
-
prototype.request = function
|
|
23712
|
-
return originalRequest.call(this, context,
|
|
23693
|
+
prototype.request = function requestWithForwardedHeaders(context, initOverrides) {
|
|
23694
|
+
return originalRequest.call(this, context, withForwardedHeadersInitOverride(initOverrides, forward));
|
|
23713
23695
|
};
|
|
23714
23696
|
Object.defineProperty(prototype, patchKey, {
|
|
23715
23697
|
value: true
|
|
23716
23698
|
});
|
|
23717
23699
|
}
|
|
23700
|
+
function installSdkUserAgentHeader(BaseApiClass, userAgent) {
|
|
23701
|
+
installRequestHeaderForwarding(BaseApiClass, userAgentPatchKey(userAgent), (headers) => addSdkUserAgentHeader(headers, userAgent));
|
|
23702
|
+
}
|
|
23718
23703
|
|
|
23719
23704
|
// ../audit-sdk/generated/src/runtime.ts
|
|
23720
23705
|
var BASE_PATH = "https://localhost:7008".replace(/\/+$/, "");
|
|
@@ -23968,7 +23953,7 @@ class VoidApiResponse {
|
|
|
23968
23953
|
var package_default2 = {
|
|
23969
23954
|
name: "@uipath/audit-sdk",
|
|
23970
23955
|
license: "MIT",
|
|
23971
|
-
version: "1.
|
|
23956
|
+
version: "1.197.0",
|
|
23972
23957
|
description: "SDK for the UiPath Audit Service — query audit event sources, list events, and download long-term-store exports.",
|
|
23973
23958
|
repository: {
|
|
23974
23959
|
type: "git",
|
|
@@ -23978,7 +23963,11 @@ var package_default2 = {
|
|
|
23978
23963
|
publishConfig: {
|
|
23979
23964
|
registry: "https://npm.pkg.github.com/@uipath"
|
|
23980
23965
|
},
|
|
23981
|
-
keywords: [
|
|
23966
|
+
keywords: [
|
|
23967
|
+
"uipath",
|
|
23968
|
+
"audit",
|
|
23969
|
+
"sdk"
|
|
23970
|
+
],
|
|
23982
23971
|
type: "module",
|
|
23983
23972
|
main: "./dist/index.js",
|
|
23984
23973
|
types: "./dist/src/index.d.ts",
|
|
@@ -23988,10 +23977,12 @@ var package_default2 = {
|
|
|
23988
23977
|
default: "./dist/index.js"
|
|
23989
23978
|
}
|
|
23990
23979
|
},
|
|
23991
|
-
files: [
|
|
23980
|
+
files: [
|
|
23981
|
+
"dist"
|
|
23982
|
+
],
|
|
23992
23983
|
private: true,
|
|
23993
23984
|
scripts: {
|
|
23994
|
-
build: "bun build ./src/index.ts --outdir dist --format esm --target node && tsc -p tsconfig.build.json --noCheck",
|
|
23985
|
+
build: "bun build ./src/index.ts --outdir dist --format esm --target node --sourcemap=linked && tsc -p tsconfig.build.json --noCheck",
|
|
23995
23986
|
generate: "bun run src/scripts/generate-sdk.ts",
|
|
23996
23987
|
lint: "biome check ."
|
|
23997
23988
|
},
|
|
@@ -24288,6 +24279,12 @@ var normalizeAndValidateBaseUrl = (rawUrl) => {
|
|
|
24288
24279
|
}
|
|
24289
24280
|
return url.pathname.length > 1 ? url.origin : baseUrl;
|
|
24290
24281
|
};
|
|
24282
|
+
var resolveScopes = (isExternalAppAuth, customScopes, fileScopes) => {
|
|
24283
|
+
const requestedScopes = customScopes?.length ? customScopes : fileScopes ?? [];
|
|
24284
|
+
if (isExternalAppAuth)
|
|
24285
|
+
return requestedScopes;
|
|
24286
|
+
return [...new Set([...DEFAULT_SCOPES, ...requestedScopes])];
|
|
24287
|
+
};
|
|
24291
24288
|
var resolveConfigAsync = async ({
|
|
24292
24289
|
customAuthority,
|
|
24293
24290
|
customClientId,
|
|
@@ -24318,7 +24315,7 @@ var resolveConfigAsync = async ({
|
|
|
24318
24315
|
clientSecret = fileAuth.clientSecret;
|
|
24319
24316
|
}
|
|
24320
24317
|
const isExternalAppAuth = clientId !== DEFAULT_CLIENT_ID && Boolean(clientSecret);
|
|
24321
|
-
const scopes =
|
|
24318
|
+
const scopes = resolveScopes(isExternalAppAuth, customScopes, fileAuth.scopes);
|
|
24322
24319
|
return {
|
|
24323
24320
|
clientId,
|
|
24324
24321
|
clientSecret,
|
|
@@ -24333,6 +24330,76 @@ var resolveConfigAsync = async ({
|
|
|
24333
24330
|
init_constants();
|
|
24334
24331
|
// ../../auth/src/loginStatus.ts
|
|
24335
24332
|
init_src();
|
|
24333
|
+
|
|
24334
|
+
// ../../auth/src/authProfile.ts
|
|
24335
|
+
init_src();
|
|
24336
|
+
init_constants();
|
|
24337
|
+
var DEFAULT_AUTH_PROFILE = "default";
|
|
24338
|
+
var PROFILE_DIR = "profiles";
|
|
24339
|
+
var PROFILE_NAME_RE = /^[A-Za-z0-9._-]+$/;
|
|
24340
|
+
var ACTIVE_AUTH_PROFILE_KEY = Symbol.for("@uipath/auth/ActiveAuthProfile");
|
|
24341
|
+
var AUTH_PROFILE_STORAGE_KEY = Symbol.for("@uipath/auth/ProfileStorage");
|
|
24342
|
+
var globalSlot2 = globalThis;
|
|
24343
|
+
function isAuthProfileStorage(value) {
|
|
24344
|
+
return value !== null && typeof value === "object" && "getStore" in value && "run" in value;
|
|
24345
|
+
}
|
|
24346
|
+
function createProfileStorage() {
|
|
24347
|
+
const [error, mod] = catchError(() => __require("node:async_hooks"));
|
|
24348
|
+
if (error || typeof mod?.AsyncLocalStorage !== "function") {
|
|
24349
|
+
return {
|
|
24350
|
+
getStore: () => {
|
|
24351
|
+
return;
|
|
24352
|
+
},
|
|
24353
|
+
run: (_store, fn) => fn()
|
|
24354
|
+
};
|
|
24355
|
+
}
|
|
24356
|
+
return new mod.AsyncLocalStorage;
|
|
24357
|
+
}
|
|
24358
|
+
function getProfileStorage() {
|
|
24359
|
+
const existing = globalSlot2[AUTH_PROFILE_STORAGE_KEY];
|
|
24360
|
+
if (isAuthProfileStorage(existing)) {
|
|
24361
|
+
return existing;
|
|
24362
|
+
}
|
|
24363
|
+
const storage = createProfileStorage();
|
|
24364
|
+
globalSlot2[AUTH_PROFILE_STORAGE_KEY] = storage;
|
|
24365
|
+
return storage;
|
|
24366
|
+
}
|
|
24367
|
+
var profileStorage = getProfileStorage();
|
|
24368
|
+
|
|
24369
|
+
class AuthProfileValidationError extends Error {
|
|
24370
|
+
constructor(message) {
|
|
24371
|
+
super(message);
|
|
24372
|
+
this.name = "AuthProfileValidationError";
|
|
24373
|
+
}
|
|
24374
|
+
}
|
|
24375
|
+
function normalizeAuthProfileName(profile) {
|
|
24376
|
+
if (profile === undefined || profile === DEFAULT_AUTH_PROFILE) {
|
|
24377
|
+
return;
|
|
24378
|
+
}
|
|
24379
|
+
if (profile.length === 0 || profile === "." || profile === ".." || !PROFILE_NAME_RE.test(profile)) {
|
|
24380
|
+
throw new AuthProfileValidationError(`Invalid profile name "${profile}". Profile names may contain only letters, numbers, '.', '_', and '-'.`);
|
|
24381
|
+
}
|
|
24382
|
+
return profile;
|
|
24383
|
+
}
|
|
24384
|
+
function getActiveAuthProfile() {
|
|
24385
|
+
const scopedState = profileStorage.getStore();
|
|
24386
|
+
if (scopedState !== undefined) {
|
|
24387
|
+
return scopedState.profile;
|
|
24388
|
+
}
|
|
24389
|
+
return globalSlot2[ACTIVE_AUTH_PROFILE_KEY]?.profile;
|
|
24390
|
+
}
|
|
24391
|
+
function resolveAuthProfileFilePath(profile) {
|
|
24392
|
+
const normalized = normalizeAuthProfileName(profile);
|
|
24393
|
+
if (normalized === undefined) {
|
|
24394
|
+
throw new AuthProfileValidationError(`"${DEFAULT_AUTH_PROFILE}" is the built-in profile and does not have a profile file path.`);
|
|
24395
|
+
}
|
|
24396
|
+
const fs7 = getFileSystem();
|
|
24397
|
+
return fs7.path.join(fs7.env.homedir(), UIPATH_HOME_DIR, PROFILE_DIR, normalized, AUTH_FILENAME);
|
|
24398
|
+
}
|
|
24399
|
+
function getActiveAuthProfileFilePath() {
|
|
24400
|
+
const profile = getActiveAuthProfile();
|
|
24401
|
+
return profile ? resolveAuthProfileFilePath(profile) : undefined;
|
|
24402
|
+
}
|
|
24336
24403
|
// ../../auth/src/utils/jwt.ts
|
|
24337
24404
|
class InvalidIssuerError extends Error {
|
|
24338
24405
|
expected;
|
|
@@ -24461,23 +24528,74 @@ var readAuthFromEnv = () => {
|
|
|
24461
24528
|
organizationId,
|
|
24462
24529
|
tenantName,
|
|
24463
24530
|
tenantId,
|
|
24464
|
-
expiration
|
|
24531
|
+
expiration,
|
|
24532
|
+
source: "env" /* Env */
|
|
24465
24533
|
};
|
|
24466
24534
|
};
|
|
24467
24535
|
|
|
24536
|
+
// ../../auth/src/refreshCircuitBreaker.ts
|
|
24537
|
+
init_src();
|
|
24538
|
+
var BREAKER_SUFFIX = ".refresh-state";
|
|
24539
|
+
var BACKOFF_BASE_MS = 60000;
|
|
24540
|
+
var BACKOFF_CAP_MS = 60 * 60 * 1000;
|
|
24541
|
+
var SURFACE_WINDOW_MS = 60 * 60 * 1000;
|
|
24542
|
+
async function refreshTokenFingerprint(refreshToken) {
|
|
24543
|
+
const bytes = new TextEncoder().encode(refreshToken);
|
|
24544
|
+
if (globalThis.crypto?.subtle) {
|
|
24545
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", bytes);
|
|
24546
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
24547
|
+
}
|
|
24548
|
+
const { createHash } = await import("node:crypto");
|
|
24549
|
+
return createHash("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
24550
|
+
}
|
|
24551
|
+
function breakerPathFor(authPath) {
|
|
24552
|
+
return `${authPath}${BREAKER_SUFFIX}`;
|
|
24553
|
+
}
|
|
24554
|
+
async function loadRefreshBreaker(authPath) {
|
|
24555
|
+
const fs7 = getFileSystem();
|
|
24556
|
+
try {
|
|
24557
|
+
const content = await fs7.readFile(breakerPathFor(authPath), "utf-8");
|
|
24558
|
+
if (!content)
|
|
24559
|
+
return {};
|
|
24560
|
+
const parsed = JSON.parse(content);
|
|
24561
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
24562
|
+
} catch {
|
|
24563
|
+
return {};
|
|
24564
|
+
}
|
|
24565
|
+
}
|
|
24566
|
+
async function saveRefreshBreaker(authPath, state) {
|
|
24567
|
+
try {
|
|
24568
|
+
const fs7 = getFileSystem();
|
|
24569
|
+
const path3 = breakerPathFor(authPath);
|
|
24570
|
+
await fs7.mkdir(fs7.path.dirname(path3));
|
|
24571
|
+
const tempPath = `${path3}.tmp`;
|
|
24572
|
+
await fs7.writeFile(tempPath, JSON.stringify(state));
|
|
24573
|
+
await fs7.rename(tempPath, path3);
|
|
24574
|
+
} catch {}
|
|
24575
|
+
}
|
|
24576
|
+
async function clearRefreshBreaker(authPath) {
|
|
24577
|
+
const fs7 = getFileSystem();
|
|
24578
|
+
const path3 = breakerPathFor(authPath);
|
|
24579
|
+
try {
|
|
24580
|
+
if (await fs7.exists(path3)) {
|
|
24581
|
+
await fs7.rm(path3);
|
|
24582
|
+
}
|
|
24583
|
+
} catch {}
|
|
24584
|
+
}
|
|
24585
|
+
function nextBackoffMs(attempts) {
|
|
24586
|
+
const shift = Math.max(0, attempts - 1);
|
|
24587
|
+
return Math.min(BACKOFF_BASE_MS * 2 ** shift, BACKOFF_CAP_MS);
|
|
24588
|
+
}
|
|
24589
|
+
function shouldSurface(state, nowMs) {
|
|
24590
|
+
if (state.lastSurfacedAtMs === undefined)
|
|
24591
|
+
return true;
|
|
24592
|
+
return nowMs - state.lastSurfacedAtMs >= SURFACE_WINDOW_MS;
|
|
24593
|
+
}
|
|
24594
|
+
|
|
24468
24595
|
// ../../auth/src/robotClientFallback.ts
|
|
24469
24596
|
init_src();
|
|
24470
24597
|
var DEFAULT_TIMEOUT_MS = 1000;
|
|
24471
24598
|
var CLOSE_TIMEOUT_MS = 500;
|
|
24472
|
-
var NOTICE_SENTINEL = Symbol.for("@uipath/auth/robotFallbackNoticePrinted");
|
|
24473
|
-
var printNoticeOnce = () => {
|
|
24474
|
-
const slot = globalThis;
|
|
24475
|
-
if (slot[NOTICE_SENTINEL])
|
|
24476
|
-
return;
|
|
24477
|
-
slot[NOTICE_SENTINEL] = true;
|
|
24478
|
-
catchError(() => process.stderr.write(`Using UiPath Robot credentials. Run 'uip login' for a dedicated session.
|
|
24479
|
-
`));
|
|
24480
|
-
};
|
|
24481
24599
|
var ROBOT_USER_SERVICES_PIPE = "UiPathUserServices";
|
|
24482
24600
|
var ROBOT_USER_SERVICES_ALTERNATE_PIPE = `${ROBOT_USER_SERVICES_PIPE}Alternate`;
|
|
24483
24601
|
var PIPE_NAME_MAX_LENGTH = 103;
|
|
@@ -24593,7 +24711,6 @@ var tryRobotClientFallback = async (options = {}) => {
|
|
|
24593
24711
|
issuerFromToken = issClaim;
|
|
24594
24712
|
}
|
|
24595
24713
|
}
|
|
24596
|
-
printNoticeOnce();
|
|
24597
24714
|
return {
|
|
24598
24715
|
accessToken,
|
|
24599
24716
|
baseUrl: parsedUrl.baseUrl,
|
|
@@ -24818,18 +24935,327 @@ var saveEnvFileAsync = async ({
|
|
|
24818
24935
|
};
|
|
24819
24936
|
|
|
24820
24937
|
// ../../auth/src/loginStatus.ts
|
|
24821
|
-
|
|
24822
|
-
return
|
|
24938
|
+
var getLoginStatusAsync = async (options = {}) => {
|
|
24939
|
+
return getLoginStatusWithDeps(options);
|
|
24940
|
+
};
|
|
24941
|
+
var getLoginStatusWithDeps = async (options = {}, deps = {}) => {
|
|
24942
|
+
const {
|
|
24943
|
+
resolveEnvFilePath = resolveEnvFilePathAsync,
|
|
24944
|
+
loadEnvFile = loadEnvFileAsync,
|
|
24945
|
+
saveEnvFile = saveEnvFileAsync,
|
|
24946
|
+
getFs = getFileSystem,
|
|
24947
|
+
refreshToken: refreshTokenFn = refreshAccessToken,
|
|
24948
|
+
resolveConfig = resolveConfigAsync,
|
|
24949
|
+
robotFallback = tryRobotClientFallback,
|
|
24950
|
+
loadBreaker = loadRefreshBreaker,
|
|
24951
|
+
saveBreaker = saveRefreshBreaker,
|
|
24952
|
+
clearBreaker = clearRefreshBreaker
|
|
24953
|
+
} = deps;
|
|
24954
|
+
if (isRobotAuthEnforced()) {
|
|
24955
|
+
return resolveRobotEnforcedStatus(robotFallback);
|
|
24956
|
+
}
|
|
24957
|
+
if (isEnvAuthEnabled()) {
|
|
24958
|
+
return readAuthFromEnv();
|
|
24959
|
+
}
|
|
24960
|
+
const activeProfile = getActiveAuthProfile();
|
|
24961
|
+
const activeProfileFilePath = getActiveAuthProfileFilePath();
|
|
24962
|
+
const usingActiveProfile = activeProfile !== undefined && (options.envFilePath === undefined || options.envFilePath === activeProfileFilePath);
|
|
24963
|
+
const envFilePath = options.envFilePath ?? activeProfileFilePath ?? DEFAULT_ENV_FILENAME;
|
|
24964
|
+
const { ensureTokenValidityMinutes } = options;
|
|
24965
|
+
const { absolutePath } = await resolveEnvFilePath(envFilePath);
|
|
24966
|
+
if (absolutePath === undefined) {
|
|
24967
|
+
if (usingActiveProfile) {
|
|
24968
|
+
return {
|
|
24969
|
+
loginStatus: "Not logged in",
|
|
24970
|
+
hint: `No credentials found for profile "${activeProfile}". Run 'uip login --profile ${activeProfile}' to authenticate this profile.`
|
|
24971
|
+
};
|
|
24972
|
+
}
|
|
24973
|
+
return resolveBorrowedRobotStatus(robotFallback);
|
|
24974
|
+
}
|
|
24975
|
+
const loaded = await loadFileCredentials(loadEnvFile, absolutePath);
|
|
24976
|
+
if ("status" in loaded) {
|
|
24977
|
+
return loaded.status;
|
|
24978
|
+
}
|
|
24979
|
+
const { credentials } = loaded;
|
|
24980
|
+
const globalHint = () => usingActiveProfile ? Promise.resolve(undefined) : getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath);
|
|
24981
|
+
const expiration = getTokenExpiration(credentials.UIPATH_ACCESS_TOKEN);
|
|
24982
|
+
const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
24983
|
+
let tokens = {
|
|
24984
|
+
accessToken: credentials.UIPATH_ACCESS_TOKEN,
|
|
24985
|
+
refreshToken: credentials.UIPATH_REFRESH_TOKEN,
|
|
24986
|
+
expiration,
|
|
24987
|
+
lockReleaseFailed: false
|
|
24988
|
+
};
|
|
24989
|
+
const refreshToken = credentials.UIPATH_REFRESH_TOKEN;
|
|
24990
|
+
if (expiration && expiration <= outerThreshold && refreshToken) {
|
|
24991
|
+
const refreshed = await attemptRefresh({
|
|
24992
|
+
absolutePath,
|
|
24993
|
+
credentials,
|
|
24994
|
+
accessToken: credentials.UIPATH_ACCESS_TOKEN,
|
|
24995
|
+
refreshToken,
|
|
24996
|
+
expiration,
|
|
24997
|
+
ensureTokenValidityMinutes,
|
|
24998
|
+
getFs,
|
|
24999
|
+
loadEnvFile,
|
|
25000
|
+
saveEnvFile,
|
|
25001
|
+
refreshFn: refreshTokenFn,
|
|
25002
|
+
resolveConfig,
|
|
25003
|
+
loadBreaker,
|
|
25004
|
+
saveBreaker,
|
|
25005
|
+
clearBreaker,
|
|
25006
|
+
globalHint
|
|
25007
|
+
});
|
|
25008
|
+
if (refreshed.kind === "terminal") {
|
|
25009
|
+
return refreshed.status;
|
|
25010
|
+
}
|
|
25011
|
+
tokens = refreshed.tokens;
|
|
25012
|
+
}
|
|
25013
|
+
return buildFileStatus(tokens, credentials, globalHint);
|
|
25014
|
+
};
|
|
25015
|
+
async function resolveRobotEnforcedStatus(robotFallback) {
|
|
25016
|
+
if (isEnvAuthEnabled()) {
|
|
25017
|
+
throw new EnvAuthConfigError(`${ENV_AUTH_ENABLE_VAR}=true and ${ENFORCE_ROBOT_AUTH_VAR}=true ` + `are mutually exclusive. Unset one of them and re-run.`);
|
|
25018
|
+
}
|
|
25019
|
+
const robotCreds = await robotFallback({ force: true });
|
|
25020
|
+
if (!robotCreds) {
|
|
25021
|
+
return {
|
|
25022
|
+
loginStatus: "Not logged in",
|
|
25023
|
+
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.`
|
|
25024
|
+
};
|
|
25025
|
+
}
|
|
25026
|
+
return buildRobotStatus(robotCreds);
|
|
24823
25027
|
}
|
|
24824
|
-
function
|
|
24825
|
-
|
|
25028
|
+
async function resolveBorrowedRobotStatus(robotFallback) {
|
|
25029
|
+
const robotCreds = await robotFallback();
|
|
25030
|
+
return robotCreds ? buildRobotStatus(robotCreds) : { loginStatus: "Not logged in" };
|
|
24826
25031
|
}
|
|
24827
|
-
function
|
|
24828
|
-
|
|
25032
|
+
async function loadFileCredentials(loadEnvFile, absolutePath) {
|
|
25033
|
+
let credentials;
|
|
25034
|
+
try {
|
|
25035
|
+
credentials = await loadEnvFile({ envPath: absolutePath });
|
|
25036
|
+
} catch (error) {
|
|
25037
|
+
if (isFileNotFoundError(error)) {
|
|
25038
|
+
return { status: { loginStatus: "Not logged in" } };
|
|
25039
|
+
}
|
|
25040
|
+
throw error;
|
|
25041
|
+
}
|
|
25042
|
+
if (!credentials.UIPATH_ACCESS_TOKEN) {
|
|
25043
|
+
return { status: { loginStatus: "Not logged in" } };
|
|
25044
|
+
}
|
|
25045
|
+
return { credentials };
|
|
25046
|
+
}
|
|
25047
|
+
async function getGlobalCredsHint(getFs, loadEnvFile, absolutePath, envFilePath) {
|
|
25048
|
+
const fs7 = getFs();
|
|
25049
|
+
const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
|
|
25050
|
+
if (absolutePath === globalPath)
|
|
25051
|
+
return;
|
|
25052
|
+
if (!await fs7.exists(globalPath))
|
|
25053
|
+
return;
|
|
25054
|
+
try {
|
|
25055
|
+
const globalCreds = await loadEnvFile({ envPath: globalPath });
|
|
25056
|
+
if (!globalCreds.UIPATH_ACCESS_TOKEN)
|
|
25057
|
+
return;
|
|
25058
|
+
const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
|
|
25059
|
+
if (globalExp && globalExp <= new Date)
|
|
25060
|
+
return;
|
|
25061
|
+
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.`;
|
|
25062
|
+
} catch {
|
|
25063
|
+
return;
|
|
25064
|
+
}
|
|
24829
25065
|
}
|
|
24830
25066
|
function computeExpirationThreshold(ensureTokenValidityMinutes) {
|
|
24831
25067
|
return new Date(Date.now() + (ensureTokenValidityMinutes ?? 0) * 60 * 1000);
|
|
24832
25068
|
}
|
|
25069
|
+
async function attemptRefresh(ctx) {
|
|
25070
|
+
const shortCircuit = await circuitBreakerShortCircuit(ctx);
|
|
25071
|
+
if (shortCircuit) {
|
|
25072
|
+
return { kind: "terminal", status: shortCircuit };
|
|
25073
|
+
}
|
|
25074
|
+
let release;
|
|
25075
|
+
try {
|
|
25076
|
+
release = await ctx.getFs().acquireLock(ctx.absolutePath);
|
|
25077
|
+
} catch (error) {
|
|
25078
|
+
return {
|
|
25079
|
+
kind: "terminal",
|
|
25080
|
+
status: await lockAcquireFailureStatus(ctx, error)
|
|
25081
|
+
};
|
|
25082
|
+
}
|
|
25083
|
+
let lockedFailure;
|
|
25084
|
+
let lockReleaseFailed = false;
|
|
25085
|
+
let success;
|
|
25086
|
+
try {
|
|
25087
|
+
const outcome = await runRefreshLocked({
|
|
25088
|
+
absolutePath: ctx.absolutePath,
|
|
25089
|
+
refreshToken: ctx.refreshToken,
|
|
25090
|
+
customAuthority: ctx.credentials.UIPATH_URL,
|
|
25091
|
+
ensureTokenValidityMinutes: ctx.ensureTokenValidityMinutes,
|
|
25092
|
+
loadEnvFile: ctx.loadEnvFile,
|
|
25093
|
+
saveEnvFile: ctx.saveEnvFile,
|
|
25094
|
+
refreshFn: ctx.refreshFn,
|
|
25095
|
+
resolveConfig: ctx.resolveConfig,
|
|
25096
|
+
loadBreaker: ctx.loadBreaker,
|
|
25097
|
+
saveBreaker: ctx.saveBreaker,
|
|
25098
|
+
clearBreaker: ctx.clearBreaker
|
|
25099
|
+
});
|
|
25100
|
+
if (outcome.kind === "fail") {
|
|
25101
|
+
lockedFailure = outcome.status;
|
|
25102
|
+
} else {
|
|
25103
|
+
success = outcome;
|
|
25104
|
+
}
|
|
25105
|
+
} finally {
|
|
25106
|
+
try {
|
|
25107
|
+
await release();
|
|
25108
|
+
} catch {
|
|
25109
|
+
lockReleaseFailed = true;
|
|
25110
|
+
}
|
|
25111
|
+
}
|
|
25112
|
+
if (lockedFailure) {
|
|
25113
|
+
const globalHint = await ctx.globalHint();
|
|
25114
|
+
const base = globalHint ? { ...lockedFailure, loginStatus: "Expired", hint: globalHint } : lockedFailure;
|
|
25115
|
+
return {
|
|
25116
|
+
kind: "terminal",
|
|
25117
|
+
status: lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base
|
|
25118
|
+
};
|
|
25119
|
+
}
|
|
25120
|
+
return {
|
|
25121
|
+
kind: "refreshed",
|
|
25122
|
+
tokens: {
|
|
25123
|
+
accessToken: success?.accessToken,
|
|
25124
|
+
refreshToken: success?.refreshToken,
|
|
25125
|
+
expiration: success?.expiration,
|
|
25126
|
+
tokenRefresh: success?.tokenRefresh,
|
|
25127
|
+
persistenceWarning: success?.persistenceWarning,
|
|
25128
|
+
lockReleaseFailed
|
|
25129
|
+
}
|
|
25130
|
+
};
|
|
25131
|
+
}
|
|
25132
|
+
async function buildFileStatus(tokens, credentials, globalHint) {
|
|
25133
|
+
const result = {
|
|
25134
|
+
loginStatus: tokens.expiration && tokens.expiration <= new Date ? "Expired" : "Logged in",
|
|
25135
|
+
accessToken: tokens.accessToken,
|
|
25136
|
+
refreshToken: tokens.refreshToken,
|
|
25137
|
+
baseUrl: credentials.UIPATH_URL,
|
|
25138
|
+
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
25139
|
+
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
25140
|
+
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
25141
|
+
tenantId: credentials.UIPATH_TENANT_ID,
|
|
25142
|
+
expiration: tokens.expiration,
|
|
25143
|
+
source: "file" /* File */,
|
|
25144
|
+
...tokens.persistenceWarning ? { hint: tokens.persistenceWarning, persistenceFailed: true } : {},
|
|
25145
|
+
...tokens.lockReleaseFailed ? { lockReleaseFailed: true } : {},
|
|
25146
|
+
...tokens.tokenRefresh ? { tokenRefresh: tokens.tokenRefresh } : {}
|
|
25147
|
+
};
|
|
25148
|
+
if (result.loginStatus === "Expired") {
|
|
25149
|
+
const hint = await globalHint();
|
|
25150
|
+
if (hint) {
|
|
25151
|
+
result.hint = hint;
|
|
25152
|
+
}
|
|
25153
|
+
}
|
|
25154
|
+
return result;
|
|
25155
|
+
}
|
|
25156
|
+
function buildRobotStatus(robotCreds) {
|
|
25157
|
+
return {
|
|
25158
|
+
loginStatus: "Logged in",
|
|
25159
|
+
accessToken: robotCreds.accessToken,
|
|
25160
|
+
baseUrl: robotCreds.baseUrl,
|
|
25161
|
+
organizationName: robotCreds.organizationName,
|
|
25162
|
+
organizationId: robotCreds.organizationId,
|
|
25163
|
+
tenantName: robotCreds.tenantName,
|
|
25164
|
+
tenantId: robotCreds.tenantId,
|
|
25165
|
+
issuer: robotCreds.issuer,
|
|
25166
|
+
expiration: getTokenExpiration(robotCreds.accessToken),
|
|
25167
|
+
source: "robot" /* Robot */
|
|
25168
|
+
};
|
|
25169
|
+
}
|
|
25170
|
+
var isFileNotFoundError = (error) => {
|
|
25171
|
+
if (!(error instanceof Object))
|
|
25172
|
+
return false;
|
|
25173
|
+
return error.code === "ENOENT";
|
|
25174
|
+
};
|
|
25175
|
+
async function circuitBreakerShortCircuit(ctx) {
|
|
25176
|
+
const {
|
|
25177
|
+
absolutePath,
|
|
25178
|
+
refreshToken,
|
|
25179
|
+
accessToken,
|
|
25180
|
+
credentials,
|
|
25181
|
+
expiration,
|
|
25182
|
+
loadBreaker,
|
|
25183
|
+
saveBreaker,
|
|
25184
|
+
clearBreaker
|
|
25185
|
+
} = ctx;
|
|
25186
|
+
const fingerprint = await refreshTokenFingerprint(refreshToken);
|
|
25187
|
+
const breaker = await loadBreaker(absolutePath).catch(() => ({}));
|
|
25188
|
+
if (breaker.deadTokenFp && breaker.deadTokenFp !== fingerprint) {
|
|
25189
|
+
await clearBreaker(absolutePath);
|
|
25190
|
+
breaker.deadTokenFp = undefined;
|
|
25191
|
+
}
|
|
25192
|
+
const nowMs = Date.now();
|
|
25193
|
+
const tokenIsDead = breaker.deadTokenFp === fingerprint;
|
|
25194
|
+
const inBackoff = breaker.backoffUntilMs !== undefined && nowMs < breaker.backoffUntilMs;
|
|
25195
|
+
if (!tokenIsDead && !inBackoff)
|
|
25196
|
+
return;
|
|
25197
|
+
const globalHint = await ctx.globalHint();
|
|
25198
|
+
const suppressed = !shouldSurface(breaker, nowMs);
|
|
25199
|
+
if (!suppressed) {
|
|
25200
|
+
await saveBreaker(absolutePath, {
|
|
25201
|
+
...breaker,
|
|
25202
|
+
lastSurfacedAtMs: nowMs
|
|
25203
|
+
});
|
|
25204
|
+
}
|
|
25205
|
+
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>.";
|
|
25206
|
+
const backoffHint = "Token refresh is temporarily backed off after a recent network error and will retry automatically once the backoff window elapses.";
|
|
25207
|
+
return {
|
|
25208
|
+
loginStatus: globalHint ? "Expired" : "Refresh Failed",
|
|
25209
|
+
...globalHint ? {
|
|
25210
|
+
accessToken,
|
|
25211
|
+
refreshToken,
|
|
25212
|
+
baseUrl: credentials.UIPATH_URL,
|
|
25213
|
+
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
25214
|
+
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
25215
|
+
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
25216
|
+
tenantId: credentials.UIPATH_TENANT_ID,
|
|
25217
|
+
expiration,
|
|
25218
|
+
source: "file" /* File */
|
|
25219
|
+
} : {},
|
|
25220
|
+
hint: globalHint ?? (tokenIsDead ? deadHint : backoffHint),
|
|
25221
|
+
refreshCircuitOpen: true,
|
|
25222
|
+
refreshTelemetrySuppressed: suppressed,
|
|
25223
|
+
tokenRefresh: { attempted: false, success: false }
|
|
25224
|
+
};
|
|
25225
|
+
}
|
|
25226
|
+
async function lockAcquireFailureStatus(ctx, error) {
|
|
25227
|
+
const msg = errorMessage(error);
|
|
25228
|
+
const globalHint = await ctx.globalHint();
|
|
25229
|
+
if (globalHint) {
|
|
25230
|
+
return {
|
|
25231
|
+
loginStatus: "Expired",
|
|
25232
|
+
accessToken: ctx.accessToken,
|
|
25233
|
+
refreshToken: ctx.refreshToken,
|
|
25234
|
+
baseUrl: ctx.credentials.UIPATH_URL,
|
|
25235
|
+
organizationName: ctx.credentials.UIPATH_ORGANIZATION_NAME,
|
|
25236
|
+
organizationId: ctx.credentials.UIPATH_ORGANIZATION_ID,
|
|
25237
|
+
tenantName: ctx.credentials.UIPATH_TENANT_NAME,
|
|
25238
|
+
tenantId: ctx.credentials.UIPATH_TENANT_ID,
|
|
25239
|
+
expiration: ctx.expiration,
|
|
25240
|
+
source: "file" /* File */,
|
|
25241
|
+
hint: globalHint,
|
|
25242
|
+
tokenRefresh: {
|
|
25243
|
+
attempted: false,
|
|
25244
|
+
success: false,
|
|
25245
|
+
errorMessage: `lock acquisition failed: ${msg}`
|
|
25246
|
+
}
|
|
25247
|
+
};
|
|
25248
|
+
}
|
|
25249
|
+
return {
|
|
25250
|
+
loginStatus: "Refresh Failed",
|
|
25251
|
+
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.",
|
|
25252
|
+
tokenRefresh: {
|
|
25253
|
+
attempted: false,
|
|
25254
|
+
success: false,
|
|
25255
|
+
errorMessage: `lock acquisition failed: ${msg}`
|
|
25256
|
+
}
|
|
25257
|
+
};
|
|
25258
|
+
}
|
|
24833
25259
|
async function runRefreshLocked(inputs) {
|
|
24834
25260
|
const {
|
|
24835
25261
|
absolutePath,
|
|
@@ -24839,7 +25265,10 @@ async function runRefreshLocked(inputs) {
|
|
|
24839
25265
|
loadEnvFile,
|
|
24840
25266
|
saveEnvFile,
|
|
24841
25267
|
refreshFn,
|
|
24842
|
-
resolveConfig
|
|
25268
|
+
resolveConfig,
|
|
25269
|
+
loadBreaker,
|
|
25270
|
+
saveBreaker,
|
|
25271
|
+
clearBreaker
|
|
24843
25272
|
} = inputs;
|
|
24844
25273
|
const expirationThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
24845
25274
|
let fresh;
|
|
@@ -24862,6 +25291,7 @@ async function runRefreshLocked(inputs) {
|
|
|
24862
25291
|
const freshAccess = fresh.UIPATH_ACCESS_TOKEN;
|
|
24863
25292
|
const freshExp = freshAccess ? getTokenExpiration(freshAccess) : undefined;
|
|
24864
25293
|
if (freshAccess && freshExp && freshExp > expirationThreshold) {
|
|
25294
|
+
await clearBreaker(absolutePath);
|
|
24865
25295
|
return {
|
|
24866
25296
|
kind: "ok",
|
|
24867
25297
|
accessToken: freshAccess,
|
|
@@ -24885,8 +25315,21 @@ async function runRefreshLocked(inputs) {
|
|
|
24885
25315
|
refreshedRefresh = refreshed.refreshToken;
|
|
24886
25316
|
} catch (error) {
|
|
24887
25317
|
const isOAuthFailure = isTokenRefreshOAuthFailure(error);
|
|
24888
|
-
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.";
|
|
25318
|
+
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.";
|
|
24889
25319
|
const message = isOAuthFailure ? normalizeTokenRefreshFailure() : normalizeTokenRefreshUnavailableFailure();
|
|
25320
|
+
const fp = await refreshTokenFingerprint(tokenForIdP);
|
|
25321
|
+
if (isOAuthFailure) {
|
|
25322
|
+
await saveBreaker(absolutePath, { deadTokenFp: fp });
|
|
25323
|
+
} else {
|
|
25324
|
+
const prior = await loadBreaker(absolutePath).catch(() => ({}));
|
|
25325
|
+
const attempts = (prior.attempts ?? 0) + 1;
|
|
25326
|
+
await saveBreaker(absolutePath, {
|
|
25327
|
+
...prior,
|
|
25328
|
+
deadTokenFp: undefined,
|
|
25329
|
+
attempts,
|
|
25330
|
+
backoffUntilMs: Date.now() + nextBackoffMs(attempts)
|
|
25331
|
+
});
|
|
25332
|
+
}
|
|
24890
25333
|
return {
|
|
24891
25334
|
kind: "fail",
|
|
24892
25335
|
status: {
|
|
@@ -24915,6 +25358,7 @@ async function runRefreshLocked(inputs) {
|
|
|
24915
25358
|
}
|
|
24916
25359
|
};
|
|
24917
25360
|
}
|
|
25361
|
+
await clearBreaker(absolutePath);
|
|
24918
25362
|
try {
|
|
24919
25363
|
await saveEnvFile({
|
|
24920
25364
|
envPath: absolutePath,
|
|
@@ -24947,231 +25391,42 @@ async function runRefreshLocked(inputs) {
|
|
|
24947
25391
|
};
|
|
24948
25392
|
}
|
|
24949
25393
|
}
|
|
24950
|
-
|
|
24951
|
-
|
|
24952
|
-
|
|
24953
|
-
|
|
24954
|
-
|
|
24955
|
-
|
|
24956
|
-
|
|
24957
|
-
|
|
24958
|
-
|
|
24959
|
-
|
|
24960
|
-
|
|
24961
|
-
|
|
24962
|
-
|
|
24963
|
-
|
|
24964
|
-
|
|
24965
|
-
|
|
24966
|
-
|
|
24967
|
-
|
|
24968
|
-
|
|
24969
|
-
|
|
24970
|
-
|
|
24971
|
-
|
|
24972
|
-
|
|
24973
|
-
|
|
24974
|
-
|
|
24975
|
-
|
|
24976
|
-
|
|
24977
|
-
|
|
24978
|
-
|
|
24979
|
-
|
|
24980
|
-
|
|
24981
|
-
|
|
24982
|
-
|
|
24983
|
-
};
|
|
25394
|
+
function normalizeTokenRefreshFailure() {
|
|
25395
|
+
return "stored refresh token is invalid or expired";
|
|
25396
|
+
}
|
|
25397
|
+
function normalizeTokenRefreshUnavailableFailure() {
|
|
25398
|
+
return "token refresh failed before authentication completed";
|
|
25399
|
+
}
|
|
25400
|
+
function errorMessage(error) {
|
|
25401
|
+
return error instanceof Error ? error.message : String(error);
|
|
25402
|
+
}
|
|
25403
|
+
// ../../auth/src/interactive.ts
|
|
25404
|
+
init_src();
|
|
25405
|
+
|
|
25406
|
+
// ../../auth/src/selectTenant.ts
|
|
25407
|
+
var TENANT_SELECTION_REQUIRED_CODE = "TENANT_SELECTION_REQUIRED";
|
|
25408
|
+
var INVALID_TENANT_CODE = "INVALID_TENANT";
|
|
25409
|
+
var TENANT_SELECTION_CODES = new Set([
|
|
25410
|
+
TENANT_SELECTION_REQUIRED_CODE,
|
|
25411
|
+
INVALID_TENANT_CODE
|
|
25412
|
+
]);
|
|
25413
|
+
// ../../auth/src/logout.ts
|
|
25414
|
+
init_src();
|
|
25415
|
+
|
|
25416
|
+
// ../../auth/src/index.ts
|
|
25417
|
+
init_server();
|
|
25418
|
+
|
|
25419
|
+
// ../audit-sdk/src/client-factory.ts
|
|
25420
|
+
async function createAuditConfig(options) {
|
|
25421
|
+
const status = await getLoginStatusAsync({
|
|
25422
|
+
ensureTokenValidityMinutes: options.loginValidity
|
|
25423
|
+
});
|
|
25424
|
+
if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
|
|
25425
|
+
const message = status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.";
|
|
25426
|
+
throw new Error(message);
|
|
24984
25427
|
}
|
|
24985
|
-
if (
|
|
24986
|
-
|
|
24987
|
-
}
|
|
24988
|
-
const { envFilePath = DEFAULT_ENV_FILENAME, ensureTokenValidityMinutes } = options;
|
|
24989
|
-
const { absolutePath } = await resolveEnvFilePath(envFilePath);
|
|
24990
|
-
if (absolutePath === undefined) {
|
|
24991
|
-
const robotCreds = await robotFallback();
|
|
24992
|
-
if (robotCreds) {
|
|
24993
|
-
const expiration2 = getTokenExpiration(robotCreds.accessToken);
|
|
24994
|
-
const status = {
|
|
24995
|
-
loginStatus: "Logged in",
|
|
24996
|
-
accessToken: robotCreds.accessToken,
|
|
24997
|
-
baseUrl: robotCreds.baseUrl,
|
|
24998
|
-
organizationName: robotCreds.organizationName,
|
|
24999
|
-
organizationId: robotCreds.organizationId,
|
|
25000
|
-
tenantName: robotCreds.tenantName,
|
|
25001
|
-
tenantId: robotCreds.tenantId,
|
|
25002
|
-
issuer: robotCreds.issuer,
|
|
25003
|
-
expiration: expiration2,
|
|
25004
|
-
source: "robot" /* Robot */
|
|
25005
|
-
};
|
|
25006
|
-
return status;
|
|
25007
|
-
}
|
|
25008
|
-
return { loginStatus: "Not logged in" };
|
|
25009
|
-
}
|
|
25010
|
-
let credentials;
|
|
25011
|
-
try {
|
|
25012
|
-
credentials = await loadEnvFile({ envPath: absolutePath });
|
|
25013
|
-
} catch (error) {
|
|
25014
|
-
if (isFileNotFoundError(error)) {
|
|
25015
|
-
return { loginStatus: "Not logged in" };
|
|
25016
|
-
}
|
|
25017
|
-
throw error;
|
|
25018
|
-
}
|
|
25019
|
-
if (!credentials.UIPATH_ACCESS_TOKEN) {
|
|
25020
|
-
return { loginStatus: "Not logged in" };
|
|
25021
|
-
}
|
|
25022
|
-
let accessToken = credentials.UIPATH_ACCESS_TOKEN;
|
|
25023
|
-
let refreshToken = credentials.UIPATH_REFRESH_TOKEN;
|
|
25024
|
-
let expiration = getTokenExpiration(accessToken);
|
|
25025
|
-
let persistenceWarning;
|
|
25026
|
-
let lockReleaseFailed = false;
|
|
25027
|
-
let tokenRefresh;
|
|
25028
|
-
const outerThreshold = computeExpirationThreshold(ensureTokenValidityMinutes);
|
|
25029
|
-
const tryGlobalCredsHint = async () => {
|
|
25030
|
-
const fs7 = getFs();
|
|
25031
|
-
const globalPath = fs7.path.join(fs7.env.homedir(), envFilePath);
|
|
25032
|
-
if (absolutePath === globalPath)
|
|
25033
|
-
return;
|
|
25034
|
-
if (!await fs7.exists(globalPath))
|
|
25035
|
-
return;
|
|
25036
|
-
try {
|
|
25037
|
-
const globalCreds = await loadEnvFile({ envPath: globalPath });
|
|
25038
|
-
if (!globalCreds.UIPATH_ACCESS_TOKEN)
|
|
25039
|
-
return;
|
|
25040
|
-
const globalExp = getTokenExpiration(globalCreds.UIPATH_ACCESS_TOKEN);
|
|
25041
|
-
if (globalExp && globalExp <= new Date)
|
|
25042
|
-
return;
|
|
25043
|
-
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.`;
|
|
25044
|
-
} catch {
|
|
25045
|
-
return;
|
|
25046
|
-
}
|
|
25047
|
-
};
|
|
25048
|
-
if (expiration && expiration <= outerThreshold && refreshToken) {
|
|
25049
|
-
let release;
|
|
25050
|
-
try {
|
|
25051
|
-
release = await getFs().acquireLock(absolutePath);
|
|
25052
|
-
} catch (error) {
|
|
25053
|
-
const msg = errorMessage(error);
|
|
25054
|
-
const globalHint = await tryGlobalCredsHint();
|
|
25055
|
-
if (globalHint) {
|
|
25056
|
-
return {
|
|
25057
|
-
loginStatus: "Expired",
|
|
25058
|
-
accessToken,
|
|
25059
|
-
refreshToken,
|
|
25060
|
-
baseUrl: credentials.UIPATH_URL,
|
|
25061
|
-
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
25062
|
-
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
25063
|
-
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
25064
|
-
tenantId: credentials.UIPATH_TENANT_ID,
|
|
25065
|
-
expiration,
|
|
25066
|
-
source: "file" /* File */,
|
|
25067
|
-
hint: globalHint,
|
|
25068
|
-
tokenRefresh: {
|
|
25069
|
-
attempted: false,
|
|
25070
|
-
success: false,
|
|
25071
|
-
errorMessage: `lock acquisition failed: ${msg}`
|
|
25072
|
-
}
|
|
25073
|
-
};
|
|
25074
|
-
}
|
|
25075
|
-
return {
|
|
25076
|
-
loginStatus: "Refresh Failed",
|
|
25077
|
-
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.",
|
|
25078
|
-
tokenRefresh: {
|
|
25079
|
-
attempted: false,
|
|
25080
|
-
success: false,
|
|
25081
|
-
errorMessage: `lock acquisition failed: ${msg}`
|
|
25082
|
-
}
|
|
25083
|
-
};
|
|
25084
|
-
}
|
|
25085
|
-
let lockedFailure;
|
|
25086
|
-
try {
|
|
25087
|
-
const outcome = await runRefreshLocked({
|
|
25088
|
-
absolutePath,
|
|
25089
|
-
refreshToken,
|
|
25090
|
-
customAuthority: credentials.UIPATH_URL,
|
|
25091
|
-
ensureTokenValidityMinutes,
|
|
25092
|
-
loadEnvFile,
|
|
25093
|
-
saveEnvFile,
|
|
25094
|
-
refreshFn: refreshTokenFn,
|
|
25095
|
-
resolveConfig
|
|
25096
|
-
});
|
|
25097
|
-
if (outcome.kind === "fail") {
|
|
25098
|
-
lockedFailure = outcome.status;
|
|
25099
|
-
} else {
|
|
25100
|
-
accessToken = outcome.accessToken;
|
|
25101
|
-
refreshToken = outcome.refreshToken;
|
|
25102
|
-
expiration = outcome.expiration;
|
|
25103
|
-
tokenRefresh = outcome.tokenRefresh;
|
|
25104
|
-
if (outcome.persistenceWarning) {
|
|
25105
|
-
persistenceWarning = outcome.persistenceWarning;
|
|
25106
|
-
}
|
|
25107
|
-
}
|
|
25108
|
-
} finally {
|
|
25109
|
-
try {
|
|
25110
|
-
await release();
|
|
25111
|
-
} catch {
|
|
25112
|
-
lockReleaseFailed = true;
|
|
25113
|
-
}
|
|
25114
|
-
}
|
|
25115
|
-
if (lockedFailure) {
|
|
25116
|
-
const globalHint = await tryGlobalCredsHint();
|
|
25117
|
-
const base = globalHint ? {
|
|
25118
|
-
...lockedFailure,
|
|
25119
|
-
loginStatus: "Expired",
|
|
25120
|
-
hint: globalHint
|
|
25121
|
-
} : lockedFailure;
|
|
25122
|
-
return lockReleaseFailed ? { ...base, lockReleaseFailed: true } : base;
|
|
25123
|
-
}
|
|
25124
|
-
}
|
|
25125
|
-
const result = {
|
|
25126
|
-
loginStatus: expiration && expiration <= new Date ? "Expired" : "Logged in",
|
|
25127
|
-
accessToken,
|
|
25128
|
-
refreshToken,
|
|
25129
|
-
baseUrl: credentials.UIPATH_URL,
|
|
25130
|
-
organizationName: credentials.UIPATH_ORGANIZATION_NAME,
|
|
25131
|
-
organizationId: credentials.UIPATH_ORGANIZATION_ID,
|
|
25132
|
-
tenantName: credentials.UIPATH_TENANT_NAME,
|
|
25133
|
-
tenantId: credentials.UIPATH_TENANT_ID,
|
|
25134
|
-
expiration,
|
|
25135
|
-
source: "file" /* File */,
|
|
25136
|
-
...persistenceWarning ? { hint: persistenceWarning, persistenceFailed: true } : {},
|
|
25137
|
-
...lockReleaseFailed ? { lockReleaseFailed: true } : {},
|
|
25138
|
-
...tokenRefresh ? { tokenRefresh } : {}
|
|
25139
|
-
};
|
|
25140
|
-
if (result.loginStatus === "Expired") {
|
|
25141
|
-
const globalHint = await tryGlobalCredsHint();
|
|
25142
|
-
if (globalHint) {
|
|
25143
|
-
result.hint = globalHint;
|
|
25144
|
-
}
|
|
25145
|
-
}
|
|
25146
|
-
return result;
|
|
25147
|
-
};
|
|
25148
|
-
var isFileNotFoundError = (error) => {
|
|
25149
|
-
if (!(error instanceof Object))
|
|
25150
|
-
return false;
|
|
25151
|
-
return error.code === "ENOENT";
|
|
25152
|
-
};
|
|
25153
|
-
var getLoginStatusAsync = async (options = {}) => {
|
|
25154
|
-
return getLoginStatusWithDeps(options);
|
|
25155
|
-
};
|
|
25156
|
-
// ../../auth/src/interactive.ts
|
|
25157
|
-
init_src();
|
|
25158
|
-
// ../../auth/src/logout.ts
|
|
25159
|
-
init_src();
|
|
25160
|
-
|
|
25161
|
-
// ../../auth/src/index.ts
|
|
25162
|
-
init_server();
|
|
25163
|
-
|
|
25164
|
-
// ../audit-sdk/src/client-factory.ts
|
|
25165
|
-
async function createAuditConfig(options) {
|
|
25166
|
-
const status = await getLoginStatusAsync({
|
|
25167
|
-
ensureTokenValidityMinutes: options.loginValidity
|
|
25168
|
-
});
|
|
25169
|
-
if (status.loginStatus !== "Logged in" || !status.baseUrl || !status.accessToken) {
|
|
25170
|
-
const message = status.hint ? `Not logged in. ${status.hint}` : "Not logged in. Run 'uip login' first.";
|
|
25171
|
-
throw new Error(message);
|
|
25172
|
-
}
|
|
25173
|
-
if (!status.organizationId) {
|
|
25174
|
-
throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
|
|
25428
|
+
if (!status.organizationId) {
|
|
25429
|
+
throw new Error("Organization ID not available. Ensure you are logged in with an organization context.");
|
|
25175
25430
|
}
|
|
25176
25431
|
let suffix;
|
|
25177
25432
|
if (options.scope === "tenant") {
|
|
@@ -25242,27 +25497,54 @@ var NETWORK_ERROR_CODES = new Set([
|
|
|
25242
25497
|
"ENETUNREACH",
|
|
25243
25498
|
"EAI_FAIL"
|
|
25244
25499
|
]);
|
|
25245
|
-
|
|
25246
|
-
|
|
25247
|
-
|
|
25248
|
-
|
|
25249
|
-
|
|
25250
|
-
|
|
25251
|
-
|
|
25252
|
-
|
|
25253
|
-
|
|
25254
|
-
|
|
25255
|
-
|
|
25256
|
-
|
|
25257
|
-
|
|
25258
|
-
|
|
25259
|
-
|
|
25260
|
-
|
|
25261
|
-
|
|
25500
|
+
var TLS_ERROR_CODES = new Set([
|
|
25501
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
25502
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
25503
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
25504
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
25505
|
+
"UNABLE_TO_GET_ISSUER_CERT",
|
|
25506
|
+
"CERT_HAS_EXPIRED",
|
|
25507
|
+
"CERT_UNTRUSTED",
|
|
25508
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
25509
|
+
]);
|
|
25510
|
+
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.";
|
|
25511
|
+
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.";
|
|
25512
|
+
function describeConnectivityError(error) {
|
|
25513
|
+
let current = error;
|
|
25514
|
+
for (let depth = 0;depth < 5 && current !== null && typeof current === "object"; depth++) {
|
|
25515
|
+
const cur = current;
|
|
25516
|
+
const code = typeof cur.code === "string" ? cur.code : undefined;
|
|
25517
|
+
const message = typeof cur.message === "string" ? cur.message : undefined;
|
|
25518
|
+
if (code && TLS_ERROR_CODES.has(code)) {
|
|
25519
|
+
return {
|
|
25520
|
+
code,
|
|
25521
|
+
kind: "tls",
|
|
25522
|
+
message: message ?? code,
|
|
25523
|
+
instructions: TLS_INSTRUCTIONS
|
|
25524
|
+
};
|
|
25525
|
+
}
|
|
25526
|
+
if (code && NETWORK_ERROR_CODES.has(code)) {
|
|
25527
|
+
return {
|
|
25528
|
+
code,
|
|
25529
|
+
kind: "network",
|
|
25530
|
+
message: message ?? code,
|
|
25531
|
+
instructions: NETWORK_INSTRUCTIONS
|
|
25532
|
+
};
|
|
25262
25533
|
}
|
|
25534
|
+
current = cur.cause;
|
|
25263
25535
|
}
|
|
25264
25536
|
return;
|
|
25265
25537
|
}
|
|
25538
|
+
function parseHttpStatusFromMessage(message) {
|
|
25539
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
25540
|
+
if (!match)
|
|
25541
|
+
return;
|
|
25542
|
+
const status = Number(match[1]);
|
|
25543
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
25544
|
+
}
|
|
25545
|
+
function isHtmlDocument(body) {
|
|
25546
|
+
return /^\s*(<!doctype html|<html\b)/i.test(body);
|
|
25547
|
+
}
|
|
25266
25548
|
function retryHintForRetryAfter(seconds) {
|
|
25267
25549
|
if (seconds <= 1) {
|
|
25268
25550
|
return "RetryAfter1Second";
|
|
@@ -25303,15 +25585,28 @@ function classifyError(status, error) {
|
|
|
25303
25585
|
if (status !== undefined && status >= 500 && status < 600) {
|
|
25304
25586
|
return { errorCode: "server_error", retry: "RetryLater" };
|
|
25305
25587
|
}
|
|
25306
|
-
|
|
25307
|
-
|
|
25588
|
+
const connectivity = describeConnectivityError(error);
|
|
25589
|
+
if (connectivity) {
|
|
25590
|
+
return {
|
|
25591
|
+
errorCode: "network_error",
|
|
25592
|
+
retry: connectivity.kind === "tls" ? "RetryWillNotFix" : "RetryLater"
|
|
25593
|
+
};
|
|
25308
25594
|
}
|
|
25309
25595
|
return { errorCode: "unknown_error", retry: "RetryWillNotFix" };
|
|
25310
25596
|
}
|
|
25597
|
+
function formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus) {
|
|
25598
|
+
if (extractedMessage) {
|
|
25599
|
+
return `HTTP ${status}: ${extractedMessage}`;
|
|
25600
|
+
}
|
|
25601
|
+
return inferredStatus !== undefined ? rawMessage : `HTTP ${status}: ${rawMessage}`;
|
|
25602
|
+
}
|
|
25311
25603
|
async function extractErrorDetails(error, options) {
|
|
25312
25604
|
const err = error !== null && error !== undefined && typeof error === "object" ? error : {};
|
|
25313
25605
|
const response = err.response;
|
|
25314
|
-
const
|
|
25606
|
+
const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
|
|
25607
|
+
const explicitStatus = err.status ?? response?.status;
|
|
25608
|
+
const inferredStatus = explicitStatus === undefined ? parseHttpStatusFromMessage(rawMessage) : undefined;
|
|
25609
|
+
const status = explicitStatus ?? inferredStatus;
|
|
25315
25610
|
const isSuccessfulResponse = status !== undefined && status >= 200 && status < 300;
|
|
25316
25611
|
let rawBody;
|
|
25317
25612
|
let extractedMessage;
|
|
@@ -25346,7 +25641,6 @@ async function extractErrorDetails(error, options) {
|
|
|
25346
25641
|
}
|
|
25347
25642
|
}
|
|
25348
25643
|
}
|
|
25349
|
-
const rawMessage = typeof err.message === "string" ? err.message : "Unknown error";
|
|
25350
25644
|
let message;
|
|
25351
25645
|
let result = "Failure";
|
|
25352
25646
|
const classification = classifyError(status, error);
|
|
@@ -25360,10 +25654,10 @@ async function extractErrorDetails(error, options) {
|
|
|
25360
25654
|
} else if (status === 405) {
|
|
25361
25655
|
message = DEFAULT_405;
|
|
25362
25656
|
} else if (status === 400 || status === 422) {
|
|
25363
|
-
message =
|
|
25657
|
+
message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
|
|
25364
25658
|
result = "ValidationError";
|
|
25365
25659
|
} else if (status === 429) {
|
|
25366
|
-
message =
|
|
25660
|
+
message = formatHttpStatusMessage(status, rawMessage, extractedMessage, inferredStatus);
|
|
25367
25661
|
} else if (extractedMessage) {
|
|
25368
25662
|
if (isSuccessfulResponse && rawMessage !== "Unknown error") {
|
|
25369
25663
|
message = rawMessage;
|
|
@@ -25371,7 +25665,9 @@ async function extractErrorDetails(error, options) {
|
|
|
25371
25665
|
message = status ? `HTTP ${status}: ${extractedMessage}` : extractedMessage;
|
|
25372
25666
|
}
|
|
25373
25667
|
} else if (status) {
|
|
25374
|
-
if (
|
|
25668
|
+
if (inferredStatus !== undefined) {
|
|
25669
|
+
message = rawMessage;
|
|
25670
|
+
} else if (rawMessage === "Unknown error" && response) {
|
|
25375
25671
|
const statusText = response.statusText;
|
|
25376
25672
|
message = statusText ? `HTTP ${status} ${statusText}` : `HTTP ${status} - request failed`;
|
|
25377
25673
|
} else {
|
|
@@ -25380,6 +25676,12 @@ async function extractErrorDetails(error, options) {
|
|
|
25380
25676
|
} else {
|
|
25381
25677
|
message = rawMessage;
|
|
25382
25678
|
}
|
|
25679
|
+
if (status === undefined) {
|
|
25680
|
+
const connectivity = describeConnectivityError(error);
|
|
25681
|
+
if (connectivity && connectivity.message !== message && !message.includes(connectivity.message)) {
|
|
25682
|
+
message = `${message}: ${connectivity.message}`;
|
|
25683
|
+
}
|
|
25684
|
+
}
|
|
25383
25685
|
let details = rawMessage;
|
|
25384
25686
|
if (rawBody) {
|
|
25385
25687
|
if (parsedBody) {
|
|
@@ -25501,6 +25803,7 @@ var CONSOLE_FALLBACK = {
|
|
|
25501
25803
|
writeLog: (str) => process.stdout.write(str),
|
|
25502
25804
|
capabilities: {
|
|
25503
25805
|
isInteractive: false,
|
|
25806
|
+
canReadInput: false,
|
|
25504
25807
|
supportsColor: false,
|
|
25505
25808
|
outputWidth: 80
|
|
25506
25809
|
}
|
|
@@ -30506,12 +30809,6 @@ class NodeContextStorage {
|
|
|
30506
30809
|
return this.storage.getStore();
|
|
30507
30810
|
}
|
|
30508
30811
|
}
|
|
30509
|
-
// ../../common/src/telemetry/global-telemetry-properties.ts
|
|
30510
|
-
var telemetryPropsSlot = singleton("TelemetryDefaultProps");
|
|
30511
|
-
function getGlobalTelemetryProperties() {
|
|
30512
|
-
return telemetryPropsSlot.get();
|
|
30513
|
-
}
|
|
30514
|
-
|
|
30515
30812
|
// ../../common/src/telemetry/telemetry-service.ts
|
|
30516
30813
|
class TelemetryService {
|
|
30517
30814
|
telemetryProvider;
|
|
@@ -30701,6 +30998,29 @@ function isPlainRecord(value) {
|
|
|
30701
30998
|
const prototype = Object.getPrototypeOf(value);
|
|
30702
30999
|
return prototype === Object.prototype || prototype === null;
|
|
30703
31000
|
}
|
|
31001
|
+
function extractPagedRows(value) {
|
|
31002
|
+
if (Array.isArray(value) || !isPlainRecord(value))
|
|
31003
|
+
return null;
|
|
31004
|
+
const entries = Object.values(value);
|
|
31005
|
+
if (entries.length === 0)
|
|
31006
|
+
return null;
|
|
31007
|
+
let rows = null;
|
|
31008
|
+
let hasScalarSibling = false;
|
|
31009
|
+
for (const entry of entries) {
|
|
31010
|
+
if (Array.isArray(entry)) {
|
|
31011
|
+
if (rows !== null)
|
|
31012
|
+
return null;
|
|
31013
|
+
rows = entry;
|
|
31014
|
+
} else if (entry !== null && typeof entry === "object") {
|
|
31015
|
+
return null;
|
|
31016
|
+
} else {
|
|
31017
|
+
hasScalarSibling = true;
|
|
31018
|
+
}
|
|
31019
|
+
}
|
|
31020
|
+
if (rows === null || !hasScalarSibling)
|
|
31021
|
+
return null;
|
|
31022
|
+
return rows;
|
|
31023
|
+
}
|
|
30704
31024
|
function toLowerCamelCaseKey(key) {
|
|
30705
31025
|
if (!key)
|
|
30706
31026
|
return key;
|
|
@@ -30765,7 +31085,8 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
30765
31085
|
break;
|
|
30766
31086
|
case "plain": {
|
|
30767
31087
|
if ("Data" in data && data.Data != null) {
|
|
30768
|
-
const
|
|
31088
|
+
const pagedRows = extractPagedRows(data.Data);
|
|
31089
|
+
const items = pagedRows ?? (Array.isArray(data.Data) ? data.Data : [data.Data]);
|
|
30769
31090
|
items.forEach((item) => {
|
|
30770
31091
|
const values = Object.values(item).map((v) => v ?? "").join("\t");
|
|
30771
31092
|
logFn(values);
|
|
@@ -30777,10 +31098,13 @@ function printOutput(data, format = "json", logFn, asciiSafe = false) {
|
|
|
30777
31098
|
break;
|
|
30778
31099
|
}
|
|
30779
31100
|
default: {
|
|
30780
|
-
|
|
31101
|
+
const hasData = "Data" in data && data.Data != null;
|
|
31102
|
+
const pagedRows = hasData ? extractPagedRows(data.Data) : null;
|
|
31103
|
+
const rows = pagedRows ? pagedRows : Array.isArray(data.Data) ? data.Data : null;
|
|
31104
|
+
if (hasData && !(rows !== null && rows.length === 0)) {
|
|
30781
31105
|
const logValue = data.Log;
|
|
30782
|
-
if (
|
|
30783
|
-
printResizableTable(
|
|
31106
|
+
if (rows !== null) {
|
|
31107
|
+
printResizableTable(rows, logFn, logValue);
|
|
30784
31108
|
} else {
|
|
30785
31109
|
printVerticalTable(data.Data, logFn, logValue);
|
|
30786
31110
|
}
|
|
@@ -30968,6 +31292,44 @@ function defaultErrorCodeForResult(result) {
|
|
|
30968
31292
|
return "unknown_error";
|
|
30969
31293
|
}
|
|
30970
31294
|
}
|
|
31295
|
+
function parseHttpStatusFromMessage2(message) {
|
|
31296
|
+
const match = /^HTTP\s+(\d{3})(?::|\s|-|$)/i.exec(message.trim());
|
|
31297
|
+
if (!match)
|
|
31298
|
+
return;
|
|
31299
|
+
const status = Number(match[1]);
|
|
31300
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
31301
|
+
}
|
|
31302
|
+
function defaultErrorCodeForHttpStatus(status) {
|
|
31303
|
+
if (status === undefined)
|
|
31304
|
+
return;
|
|
31305
|
+
if (status === 400 || status === 409 || status === 422) {
|
|
31306
|
+
return "invalid_argument";
|
|
31307
|
+
}
|
|
31308
|
+
if (status === 401)
|
|
31309
|
+
return "authentication_required";
|
|
31310
|
+
if (status === 403)
|
|
31311
|
+
return "permission_denied";
|
|
31312
|
+
if (status === 404)
|
|
31313
|
+
return "not_found";
|
|
31314
|
+
if (status === 405)
|
|
31315
|
+
return "method_not_allowed";
|
|
31316
|
+
if (status === 408)
|
|
31317
|
+
return "timeout";
|
|
31318
|
+
if (status === 429)
|
|
31319
|
+
return "rate_limited";
|
|
31320
|
+
if (status >= 500 && status < 600)
|
|
31321
|
+
return "server_error";
|
|
31322
|
+
return;
|
|
31323
|
+
}
|
|
31324
|
+
function defaultErrorCodeForFailure(data) {
|
|
31325
|
+
if (data.Result === RESULTS.Failure) {
|
|
31326
|
+
const status = data.Context?.httpStatus ?? parseHttpStatusFromMessage2(data.Message);
|
|
31327
|
+
const errorCode2 = defaultErrorCodeForHttpStatus(status);
|
|
31328
|
+
if (errorCode2)
|
|
31329
|
+
return errorCode2;
|
|
31330
|
+
}
|
|
31331
|
+
return defaultErrorCodeForResult(data.Result);
|
|
31332
|
+
}
|
|
30971
31333
|
function defaultRetryForErrorCode(errorCode2) {
|
|
30972
31334
|
switch (errorCode2) {
|
|
30973
31335
|
case "network_error":
|
|
@@ -30997,16 +31359,19 @@ var OutputFormatter;
|
|
|
30997
31359
|
OutputFormatter.success = success;
|
|
30998
31360
|
function error(data) {
|
|
30999
31361
|
data.Log ??= getLogFilePath() || undefined;
|
|
31000
|
-
data.ErrorCode ??=
|
|
31362
|
+
data.ErrorCode ??= defaultErrorCodeForFailure(data);
|
|
31001
31363
|
data.Retry ??= defaultRetryForErrorCode(data.ErrorCode);
|
|
31002
31364
|
process.exitCode = EXIT_CODES[data.Result] ?? 1;
|
|
31003
|
-
|
|
31004
|
-
|
|
31005
|
-
|
|
31006
|
-
|
|
31007
|
-
|
|
31008
|
-
|
|
31009
|
-
|
|
31365
|
+
const { SuppressTelemetry, ...envelope } = data;
|
|
31366
|
+
if (!SuppressTelemetry) {
|
|
31367
|
+
telemetry.trackEvent(CommonTelemetryEvents.Error, {
|
|
31368
|
+
result: data.Result,
|
|
31369
|
+
errorCode: data.ErrorCode,
|
|
31370
|
+
retry: data.Retry,
|
|
31371
|
+
message: data.Message
|
|
31372
|
+
});
|
|
31373
|
+
}
|
|
31374
|
+
logOutput(normalizeOutputKeys(envelope), getOutputFormat());
|
|
31010
31375
|
}
|
|
31011
31376
|
OutputFormatter.error = error;
|
|
31012
31377
|
function emitList(code, items, opts) {
|
|
@@ -31296,1409 +31661,6 @@ var savedOriginalsSlot = singleton("ConsoleGuardOriginals");
|
|
|
31296
31661
|
var DEFAULT_AUTH_TIMEOUT_MS2 = 5 * 60 * 1000;
|
|
31297
31662
|
// ../../common/src/interactivity-context.ts
|
|
31298
31663
|
var modeSlot = singleton("InteractivityMode");
|
|
31299
|
-
// ../../../node_modules/jsonpath-plus/dist/index-node-esm.js
|
|
31300
|
-
import vm from "vm";
|
|
31301
|
-
|
|
31302
|
-
class Hooks {
|
|
31303
|
-
add(name, callback, first) {
|
|
31304
|
-
if (typeof arguments[0] != "string") {
|
|
31305
|
-
for (let name2 in arguments[0]) {
|
|
31306
|
-
this.add(name2, arguments[0][name2], arguments[1]);
|
|
31307
|
-
}
|
|
31308
|
-
} else {
|
|
31309
|
-
(Array.isArray(name) ? name : [name]).forEach(function(name2) {
|
|
31310
|
-
this[name2] = this[name2] || [];
|
|
31311
|
-
if (callback) {
|
|
31312
|
-
this[name2][first ? "unshift" : "push"](callback);
|
|
31313
|
-
}
|
|
31314
|
-
}, this);
|
|
31315
|
-
}
|
|
31316
|
-
}
|
|
31317
|
-
run(name, env) {
|
|
31318
|
-
this[name] = this[name] || [];
|
|
31319
|
-
this[name].forEach(function(callback) {
|
|
31320
|
-
callback.call(env && env.context ? env.context : env, env);
|
|
31321
|
-
});
|
|
31322
|
-
}
|
|
31323
|
-
}
|
|
31324
|
-
|
|
31325
|
-
class Plugins {
|
|
31326
|
-
constructor(jsep) {
|
|
31327
|
-
this.jsep = jsep;
|
|
31328
|
-
this.registered = {};
|
|
31329
|
-
}
|
|
31330
|
-
register(...plugins) {
|
|
31331
|
-
plugins.forEach((plugin) => {
|
|
31332
|
-
if (typeof plugin !== "object" || !plugin.name || !plugin.init) {
|
|
31333
|
-
throw new Error("Invalid JSEP plugin format");
|
|
31334
|
-
}
|
|
31335
|
-
if (this.registered[plugin.name]) {
|
|
31336
|
-
return;
|
|
31337
|
-
}
|
|
31338
|
-
plugin.init(this.jsep);
|
|
31339
|
-
this.registered[plugin.name] = plugin;
|
|
31340
|
-
});
|
|
31341
|
-
}
|
|
31342
|
-
}
|
|
31343
|
-
|
|
31344
|
-
class Jsep {
|
|
31345
|
-
static get version() {
|
|
31346
|
-
return "1.4.0";
|
|
31347
|
-
}
|
|
31348
|
-
static toString() {
|
|
31349
|
-
return "JavaScript Expression Parser (JSEP) v" + Jsep.version;
|
|
31350
|
-
}
|
|
31351
|
-
static addUnaryOp(op_name) {
|
|
31352
|
-
Jsep.max_unop_len = Math.max(op_name.length, Jsep.max_unop_len);
|
|
31353
|
-
Jsep.unary_ops[op_name] = 1;
|
|
31354
|
-
return Jsep;
|
|
31355
|
-
}
|
|
31356
|
-
static addBinaryOp(op_name, precedence, isRightAssociative) {
|
|
31357
|
-
Jsep.max_binop_len = Math.max(op_name.length, Jsep.max_binop_len);
|
|
31358
|
-
Jsep.binary_ops[op_name] = precedence;
|
|
31359
|
-
if (isRightAssociative) {
|
|
31360
|
-
Jsep.right_associative.add(op_name);
|
|
31361
|
-
} else {
|
|
31362
|
-
Jsep.right_associative.delete(op_name);
|
|
31363
|
-
}
|
|
31364
|
-
return Jsep;
|
|
31365
|
-
}
|
|
31366
|
-
static addIdentifierChar(char) {
|
|
31367
|
-
Jsep.additional_identifier_chars.add(char);
|
|
31368
|
-
return Jsep;
|
|
31369
|
-
}
|
|
31370
|
-
static addLiteral(literal_name, literal_value) {
|
|
31371
|
-
Jsep.literals[literal_name] = literal_value;
|
|
31372
|
-
return Jsep;
|
|
31373
|
-
}
|
|
31374
|
-
static removeUnaryOp(op_name) {
|
|
31375
|
-
delete Jsep.unary_ops[op_name];
|
|
31376
|
-
if (op_name.length === Jsep.max_unop_len) {
|
|
31377
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
31378
|
-
}
|
|
31379
|
-
return Jsep;
|
|
31380
|
-
}
|
|
31381
|
-
static removeAllUnaryOps() {
|
|
31382
|
-
Jsep.unary_ops = {};
|
|
31383
|
-
Jsep.max_unop_len = 0;
|
|
31384
|
-
return Jsep;
|
|
31385
|
-
}
|
|
31386
|
-
static removeIdentifierChar(char) {
|
|
31387
|
-
Jsep.additional_identifier_chars.delete(char);
|
|
31388
|
-
return Jsep;
|
|
31389
|
-
}
|
|
31390
|
-
static removeBinaryOp(op_name) {
|
|
31391
|
-
delete Jsep.binary_ops[op_name];
|
|
31392
|
-
if (op_name.length === Jsep.max_binop_len) {
|
|
31393
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
31394
|
-
}
|
|
31395
|
-
Jsep.right_associative.delete(op_name);
|
|
31396
|
-
return Jsep;
|
|
31397
|
-
}
|
|
31398
|
-
static removeAllBinaryOps() {
|
|
31399
|
-
Jsep.binary_ops = {};
|
|
31400
|
-
Jsep.max_binop_len = 0;
|
|
31401
|
-
return Jsep;
|
|
31402
|
-
}
|
|
31403
|
-
static removeLiteral(literal_name) {
|
|
31404
|
-
delete Jsep.literals[literal_name];
|
|
31405
|
-
return Jsep;
|
|
31406
|
-
}
|
|
31407
|
-
static removeAllLiterals() {
|
|
31408
|
-
Jsep.literals = {};
|
|
31409
|
-
return Jsep;
|
|
31410
|
-
}
|
|
31411
|
-
get char() {
|
|
31412
|
-
return this.expr.charAt(this.index);
|
|
31413
|
-
}
|
|
31414
|
-
get code() {
|
|
31415
|
-
return this.expr.charCodeAt(this.index);
|
|
31416
|
-
}
|
|
31417
|
-
constructor(expr) {
|
|
31418
|
-
this.expr = expr;
|
|
31419
|
-
this.index = 0;
|
|
31420
|
-
}
|
|
31421
|
-
static parse(expr) {
|
|
31422
|
-
return new Jsep(expr).parse();
|
|
31423
|
-
}
|
|
31424
|
-
static getMaxKeyLen(obj) {
|
|
31425
|
-
return Math.max(0, ...Object.keys(obj).map((k) => k.length));
|
|
31426
|
-
}
|
|
31427
|
-
static isDecimalDigit(ch) {
|
|
31428
|
-
return ch >= 48 && ch <= 57;
|
|
31429
|
-
}
|
|
31430
|
-
static binaryPrecedence(op_val) {
|
|
31431
|
-
return Jsep.binary_ops[op_val] || 0;
|
|
31432
|
-
}
|
|
31433
|
-
static isIdentifierStart(ch) {
|
|
31434
|
-
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));
|
|
31435
|
-
}
|
|
31436
|
-
static isIdentifierPart(ch) {
|
|
31437
|
-
return Jsep.isIdentifierStart(ch) || Jsep.isDecimalDigit(ch);
|
|
31438
|
-
}
|
|
31439
|
-
throwError(message) {
|
|
31440
|
-
const error = new Error(message + " at character " + this.index);
|
|
31441
|
-
error.index = this.index;
|
|
31442
|
-
error.description = message;
|
|
31443
|
-
throw error;
|
|
31444
|
-
}
|
|
31445
|
-
runHook(name, node) {
|
|
31446
|
-
if (Jsep.hooks[name]) {
|
|
31447
|
-
const env = {
|
|
31448
|
-
context: this,
|
|
31449
|
-
node
|
|
31450
|
-
};
|
|
31451
|
-
Jsep.hooks.run(name, env);
|
|
31452
|
-
return env.node;
|
|
31453
|
-
}
|
|
31454
|
-
return node;
|
|
31455
|
-
}
|
|
31456
|
-
searchHook(name) {
|
|
31457
|
-
if (Jsep.hooks[name]) {
|
|
31458
|
-
const env = {
|
|
31459
|
-
context: this
|
|
31460
|
-
};
|
|
31461
|
-
Jsep.hooks[name].find(function(callback) {
|
|
31462
|
-
callback.call(env.context, env);
|
|
31463
|
-
return env.node;
|
|
31464
|
-
});
|
|
31465
|
-
return env.node;
|
|
31466
|
-
}
|
|
31467
|
-
}
|
|
31468
|
-
gobbleSpaces() {
|
|
31469
|
-
let ch = this.code;
|
|
31470
|
-
while (ch === Jsep.SPACE_CODE || ch === Jsep.TAB_CODE || ch === Jsep.LF_CODE || ch === Jsep.CR_CODE) {
|
|
31471
|
-
ch = this.expr.charCodeAt(++this.index);
|
|
31472
|
-
}
|
|
31473
|
-
this.runHook("gobble-spaces");
|
|
31474
|
-
}
|
|
31475
|
-
parse() {
|
|
31476
|
-
this.runHook("before-all");
|
|
31477
|
-
const nodes = this.gobbleExpressions();
|
|
31478
|
-
const node = nodes.length === 1 ? nodes[0] : {
|
|
31479
|
-
type: Jsep.COMPOUND,
|
|
31480
|
-
body: nodes
|
|
31481
|
-
};
|
|
31482
|
-
return this.runHook("after-all", node);
|
|
31483
|
-
}
|
|
31484
|
-
gobbleExpressions(untilICode) {
|
|
31485
|
-
let nodes = [], ch_i, node;
|
|
31486
|
-
while (this.index < this.expr.length) {
|
|
31487
|
-
ch_i = this.code;
|
|
31488
|
-
if (ch_i === Jsep.SEMCOL_CODE || ch_i === Jsep.COMMA_CODE) {
|
|
31489
|
-
this.index++;
|
|
31490
|
-
} else {
|
|
31491
|
-
if (node = this.gobbleExpression()) {
|
|
31492
|
-
nodes.push(node);
|
|
31493
|
-
} else if (this.index < this.expr.length) {
|
|
31494
|
-
if (ch_i === untilICode) {
|
|
31495
|
-
break;
|
|
31496
|
-
}
|
|
31497
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
31498
|
-
}
|
|
31499
|
-
}
|
|
31500
|
-
}
|
|
31501
|
-
return nodes;
|
|
31502
|
-
}
|
|
31503
|
-
gobbleExpression() {
|
|
31504
|
-
const node = this.searchHook("gobble-expression") || this.gobbleBinaryExpression();
|
|
31505
|
-
this.gobbleSpaces();
|
|
31506
|
-
return this.runHook("after-expression", node);
|
|
31507
|
-
}
|
|
31508
|
-
gobbleBinaryOp() {
|
|
31509
|
-
this.gobbleSpaces();
|
|
31510
|
-
let to_check = this.expr.substr(this.index, Jsep.max_binop_len);
|
|
31511
|
-
let tc_len = to_check.length;
|
|
31512
|
-
while (tc_len > 0) {
|
|
31513
|
-
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)))) {
|
|
31514
|
-
this.index += tc_len;
|
|
31515
|
-
return to_check;
|
|
31516
|
-
}
|
|
31517
|
-
to_check = to_check.substr(0, --tc_len);
|
|
31518
|
-
}
|
|
31519
|
-
return false;
|
|
31520
|
-
}
|
|
31521
|
-
gobbleBinaryExpression() {
|
|
31522
|
-
let node, biop, prec, stack, biop_info, left, right, i, cur_biop;
|
|
31523
|
-
left = this.gobbleToken();
|
|
31524
|
-
if (!left) {
|
|
31525
|
-
return left;
|
|
31526
|
-
}
|
|
31527
|
-
biop = this.gobbleBinaryOp();
|
|
31528
|
-
if (!biop) {
|
|
31529
|
-
return left;
|
|
31530
|
-
}
|
|
31531
|
-
biop_info = {
|
|
31532
|
-
value: biop,
|
|
31533
|
-
prec: Jsep.binaryPrecedence(biop),
|
|
31534
|
-
right_a: Jsep.right_associative.has(biop)
|
|
31535
|
-
};
|
|
31536
|
-
right = this.gobbleToken();
|
|
31537
|
-
if (!right) {
|
|
31538
|
-
this.throwError("Expected expression after " + biop);
|
|
31539
|
-
}
|
|
31540
|
-
stack = [left, biop_info, right];
|
|
31541
|
-
while (biop = this.gobbleBinaryOp()) {
|
|
31542
|
-
prec = Jsep.binaryPrecedence(biop);
|
|
31543
|
-
if (prec === 0) {
|
|
31544
|
-
this.index -= biop.length;
|
|
31545
|
-
break;
|
|
31546
|
-
}
|
|
31547
|
-
biop_info = {
|
|
31548
|
-
value: biop,
|
|
31549
|
-
prec,
|
|
31550
|
-
right_a: Jsep.right_associative.has(biop)
|
|
31551
|
-
};
|
|
31552
|
-
cur_biop = biop;
|
|
31553
|
-
const comparePrev = (prev) => biop_info.right_a && prev.right_a ? prec > prev.prec : prec <= prev.prec;
|
|
31554
|
-
while (stack.length > 2 && comparePrev(stack[stack.length - 2])) {
|
|
31555
|
-
right = stack.pop();
|
|
31556
|
-
biop = stack.pop().value;
|
|
31557
|
-
left = stack.pop();
|
|
31558
|
-
node = {
|
|
31559
|
-
type: Jsep.BINARY_EXP,
|
|
31560
|
-
operator: biop,
|
|
31561
|
-
left,
|
|
31562
|
-
right
|
|
31563
|
-
};
|
|
31564
|
-
stack.push(node);
|
|
31565
|
-
}
|
|
31566
|
-
node = this.gobbleToken();
|
|
31567
|
-
if (!node) {
|
|
31568
|
-
this.throwError("Expected expression after " + cur_biop);
|
|
31569
|
-
}
|
|
31570
|
-
stack.push(biop_info, node);
|
|
31571
|
-
}
|
|
31572
|
-
i = stack.length - 1;
|
|
31573
|
-
node = stack[i];
|
|
31574
|
-
while (i > 1) {
|
|
31575
|
-
node = {
|
|
31576
|
-
type: Jsep.BINARY_EXP,
|
|
31577
|
-
operator: stack[i - 1].value,
|
|
31578
|
-
left: stack[i - 2],
|
|
31579
|
-
right: node
|
|
31580
|
-
};
|
|
31581
|
-
i -= 2;
|
|
31582
|
-
}
|
|
31583
|
-
return node;
|
|
31584
|
-
}
|
|
31585
|
-
gobbleToken() {
|
|
31586
|
-
let ch, to_check, tc_len, node;
|
|
31587
|
-
this.gobbleSpaces();
|
|
31588
|
-
node = this.searchHook("gobble-token");
|
|
31589
|
-
if (node) {
|
|
31590
|
-
return this.runHook("after-token", node);
|
|
31591
|
-
}
|
|
31592
|
-
ch = this.code;
|
|
31593
|
-
if (Jsep.isDecimalDigit(ch) || ch === Jsep.PERIOD_CODE) {
|
|
31594
|
-
return this.gobbleNumericLiteral();
|
|
31595
|
-
}
|
|
31596
|
-
if (ch === Jsep.SQUOTE_CODE || ch === Jsep.DQUOTE_CODE) {
|
|
31597
|
-
node = this.gobbleStringLiteral();
|
|
31598
|
-
} else if (ch === Jsep.OBRACK_CODE) {
|
|
31599
|
-
node = this.gobbleArray();
|
|
31600
|
-
} else {
|
|
31601
|
-
to_check = this.expr.substr(this.index, Jsep.max_unop_len);
|
|
31602
|
-
tc_len = to_check.length;
|
|
31603
|
-
while (tc_len > 0) {
|
|
31604
|
-
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)))) {
|
|
31605
|
-
this.index += tc_len;
|
|
31606
|
-
const argument = this.gobbleToken();
|
|
31607
|
-
if (!argument) {
|
|
31608
|
-
this.throwError("missing unaryOp argument");
|
|
31609
|
-
}
|
|
31610
|
-
return this.runHook("after-token", {
|
|
31611
|
-
type: Jsep.UNARY_EXP,
|
|
31612
|
-
operator: to_check,
|
|
31613
|
-
argument,
|
|
31614
|
-
prefix: true
|
|
31615
|
-
});
|
|
31616
|
-
}
|
|
31617
|
-
to_check = to_check.substr(0, --tc_len);
|
|
31618
|
-
}
|
|
31619
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
31620
|
-
node = this.gobbleIdentifier();
|
|
31621
|
-
if (Jsep.literals.hasOwnProperty(node.name)) {
|
|
31622
|
-
node = {
|
|
31623
|
-
type: Jsep.LITERAL,
|
|
31624
|
-
value: Jsep.literals[node.name],
|
|
31625
|
-
raw: node.name
|
|
31626
|
-
};
|
|
31627
|
-
} else if (node.name === Jsep.this_str) {
|
|
31628
|
-
node = {
|
|
31629
|
-
type: Jsep.THIS_EXP
|
|
31630
|
-
};
|
|
31631
|
-
}
|
|
31632
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
31633
|
-
node = this.gobbleGroup();
|
|
31634
|
-
}
|
|
31635
|
-
}
|
|
31636
|
-
if (!node) {
|
|
31637
|
-
return this.runHook("after-token", false);
|
|
31638
|
-
}
|
|
31639
|
-
node = this.gobbleTokenProperty(node);
|
|
31640
|
-
return this.runHook("after-token", node);
|
|
31641
|
-
}
|
|
31642
|
-
gobbleTokenProperty(node) {
|
|
31643
|
-
this.gobbleSpaces();
|
|
31644
|
-
let ch = this.code;
|
|
31645
|
-
while (ch === Jsep.PERIOD_CODE || ch === Jsep.OBRACK_CODE || ch === Jsep.OPAREN_CODE || ch === Jsep.QUMARK_CODE) {
|
|
31646
|
-
let optional;
|
|
31647
|
-
if (ch === Jsep.QUMARK_CODE) {
|
|
31648
|
-
if (this.expr.charCodeAt(this.index + 1) !== Jsep.PERIOD_CODE) {
|
|
31649
|
-
break;
|
|
31650
|
-
}
|
|
31651
|
-
optional = true;
|
|
31652
|
-
this.index += 2;
|
|
31653
|
-
this.gobbleSpaces();
|
|
31654
|
-
ch = this.code;
|
|
31655
|
-
}
|
|
31656
|
-
this.index++;
|
|
31657
|
-
if (ch === Jsep.OBRACK_CODE) {
|
|
31658
|
-
node = {
|
|
31659
|
-
type: Jsep.MEMBER_EXP,
|
|
31660
|
-
computed: true,
|
|
31661
|
-
object: node,
|
|
31662
|
-
property: this.gobbleExpression()
|
|
31663
|
-
};
|
|
31664
|
-
if (!node.property) {
|
|
31665
|
-
this.throwError('Unexpected "' + this.char + '"');
|
|
31666
|
-
}
|
|
31667
|
-
this.gobbleSpaces();
|
|
31668
|
-
ch = this.code;
|
|
31669
|
-
if (ch !== Jsep.CBRACK_CODE) {
|
|
31670
|
-
this.throwError("Unclosed [");
|
|
31671
|
-
}
|
|
31672
|
-
this.index++;
|
|
31673
|
-
} else if (ch === Jsep.OPAREN_CODE) {
|
|
31674
|
-
node = {
|
|
31675
|
-
type: Jsep.CALL_EXP,
|
|
31676
|
-
arguments: this.gobbleArguments(Jsep.CPAREN_CODE),
|
|
31677
|
-
callee: node
|
|
31678
|
-
};
|
|
31679
|
-
} else if (ch === Jsep.PERIOD_CODE || optional) {
|
|
31680
|
-
if (optional) {
|
|
31681
|
-
this.index--;
|
|
31682
|
-
}
|
|
31683
|
-
this.gobbleSpaces();
|
|
31684
|
-
node = {
|
|
31685
|
-
type: Jsep.MEMBER_EXP,
|
|
31686
|
-
computed: false,
|
|
31687
|
-
object: node,
|
|
31688
|
-
property: this.gobbleIdentifier()
|
|
31689
|
-
};
|
|
31690
|
-
}
|
|
31691
|
-
if (optional) {
|
|
31692
|
-
node.optional = true;
|
|
31693
|
-
}
|
|
31694
|
-
this.gobbleSpaces();
|
|
31695
|
-
ch = this.code;
|
|
31696
|
-
}
|
|
31697
|
-
return node;
|
|
31698
|
-
}
|
|
31699
|
-
gobbleNumericLiteral() {
|
|
31700
|
-
let number = "", ch, chCode;
|
|
31701
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
31702
|
-
number += this.expr.charAt(this.index++);
|
|
31703
|
-
}
|
|
31704
|
-
if (this.code === Jsep.PERIOD_CODE) {
|
|
31705
|
-
number += this.expr.charAt(this.index++);
|
|
31706
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
31707
|
-
number += this.expr.charAt(this.index++);
|
|
31708
|
-
}
|
|
31709
|
-
}
|
|
31710
|
-
ch = this.char;
|
|
31711
|
-
if (ch === "e" || ch === "E") {
|
|
31712
|
-
number += this.expr.charAt(this.index++);
|
|
31713
|
-
ch = this.char;
|
|
31714
|
-
if (ch === "+" || ch === "-") {
|
|
31715
|
-
number += this.expr.charAt(this.index++);
|
|
31716
|
-
}
|
|
31717
|
-
while (Jsep.isDecimalDigit(this.code)) {
|
|
31718
|
-
number += this.expr.charAt(this.index++);
|
|
31719
|
-
}
|
|
31720
|
-
if (!Jsep.isDecimalDigit(this.expr.charCodeAt(this.index - 1))) {
|
|
31721
|
-
this.throwError("Expected exponent (" + number + this.char + ")");
|
|
31722
|
-
}
|
|
31723
|
-
}
|
|
31724
|
-
chCode = this.code;
|
|
31725
|
-
if (Jsep.isIdentifierStart(chCode)) {
|
|
31726
|
-
this.throwError("Variable names cannot start with a number (" + number + this.char + ")");
|
|
31727
|
-
} else if (chCode === Jsep.PERIOD_CODE || number.length === 1 && number.charCodeAt(0) === Jsep.PERIOD_CODE) {
|
|
31728
|
-
this.throwError("Unexpected period");
|
|
31729
|
-
}
|
|
31730
|
-
return {
|
|
31731
|
-
type: Jsep.LITERAL,
|
|
31732
|
-
value: parseFloat(number),
|
|
31733
|
-
raw: number
|
|
31734
|
-
};
|
|
31735
|
-
}
|
|
31736
|
-
gobbleStringLiteral() {
|
|
31737
|
-
let str = "";
|
|
31738
|
-
const startIndex = this.index;
|
|
31739
|
-
const quote = this.expr.charAt(this.index++);
|
|
31740
|
-
let closed = false;
|
|
31741
|
-
while (this.index < this.expr.length) {
|
|
31742
|
-
let ch = this.expr.charAt(this.index++);
|
|
31743
|
-
if (ch === quote) {
|
|
31744
|
-
closed = true;
|
|
31745
|
-
break;
|
|
31746
|
-
} else if (ch === "\\") {
|
|
31747
|
-
ch = this.expr.charAt(this.index++);
|
|
31748
|
-
switch (ch) {
|
|
31749
|
-
case "n":
|
|
31750
|
-
str += `
|
|
31751
|
-
`;
|
|
31752
|
-
break;
|
|
31753
|
-
case "r":
|
|
31754
|
-
str += "\r";
|
|
31755
|
-
break;
|
|
31756
|
-
case "t":
|
|
31757
|
-
str += "\t";
|
|
31758
|
-
break;
|
|
31759
|
-
case "b":
|
|
31760
|
-
str += "\b";
|
|
31761
|
-
break;
|
|
31762
|
-
case "f":
|
|
31763
|
-
str += "\f";
|
|
31764
|
-
break;
|
|
31765
|
-
case "v":
|
|
31766
|
-
str += "\v";
|
|
31767
|
-
break;
|
|
31768
|
-
default:
|
|
31769
|
-
str += ch;
|
|
31770
|
-
}
|
|
31771
|
-
} else {
|
|
31772
|
-
str += ch;
|
|
31773
|
-
}
|
|
31774
|
-
}
|
|
31775
|
-
if (!closed) {
|
|
31776
|
-
this.throwError('Unclosed quote after "' + str + '"');
|
|
31777
|
-
}
|
|
31778
|
-
return {
|
|
31779
|
-
type: Jsep.LITERAL,
|
|
31780
|
-
value: str,
|
|
31781
|
-
raw: this.expr.substring(startIndex, this.index)
|
|
31782
|
-
};
|
|
31783
|
-
}
|
|
31784
|
-
gobbleIdentifier() {
|
|
31785
|
-
let ch = this.code, start = this.index;
|
|
31786
|
-
if (Jsep.isIdentifierStart(ch)) {
|
|
31787
|
-
this.index++;
|
|
31788
|
-
} else {
|
|
31789
|
-
this.throwError("Unexpected " + this.char);
|
|
31790
|
-
}
|
|
31791
|
-
while (this.index < this.expr.length) {
|
|
31792
|
-
ch = this.code;
|
|
31793
|
-
if (Jsep.isIdentifierPart(ch)) {
|
|
31794
|
-
this.index++;
|
|
31795
|
-
} else {
|
|
31796
|
-
break;
|
|
31797
|
-
}
|
|
31798
|
-
}
|
|
31799
|
-
return {
|
|
31800
|
-
type: Jsep.IDENTIFIER,
|
|
31801
|
-
name: this.expr.slice(start, this.index)
|
|
31802
|
-
};
|
|
31803
|
-
}
|
|
31804
|
-
gobbleArguments(termination) {
|
|
31805
|
-
const args = [];
|
|
31806
|
-
let closed = false;
|
|
31807
|
-
let separator_count = 0;
|
|
31808
|
-
while (this.index < this.expr.length) {
|
|
31809
|
-
this.gobbleSpaces();
|
|
31810
|
-
let ch_i = this.code;
|
|
31811
|
-
if (ch_i === termination) {
|
|
31812
|
-
closed = true;
|
|
31813
|
-
this.index++;
|
|
31814
|
-
if (termination === Jsep.CPAREN_CODE && separator_count && separator_count >= args.length) {
|
|
31815
|
-
this.throwError("Unexpected token " + String.fromCharCode(termination));
|
|
31816
|
-
}
|
|
31817
|
-
break;
|
|
31818
|
-
} else if (ch_i === Jsep.COMMA_CODE) {
|
|
31819
|
-
this.index++;
|
|
31820
|
-
separator_count++;
|
|
31821
|
-
if (separator_count !== args.length) {
|
|
31822
|
-
if (termination === Jsep.CPAREN_CODE) {
|
|
31823
|
-
this.throwError("Unexpected token ,");
|
|
31824
|
-
} else if (termination === Jsep.CBRACK_CODE) {
|
|
31825
|
-
for (let arg = args.length;arg < separator_count; arg++) {
|
|
31826
|
-
args.push(null);
|
|
31827
|
-
}
|
|
31828
|
-
}
|
|
31829
|
-
}
|
|
31830
|
-
} else if (args.length !== separator_count && separator_count !== 0) {
|
|
31831
|
-
this.throwError("Expected comma");
|
|
31832
|
-
} else {
|
|
31833
|
-
const node = this.gobbleExpression();
|
|
31834
|
-
if (!node || node.type === Jsep.COMPOUND) {
|
|
31835
|
-
this.throwError("Expected comma");
|
|
31836
|
-
}
|
|
31837
|
-
args.push(node);
|
|
31838
|
-
}
|
|
31839
|
-
}
|
|
31840
|
-
if (!closed) {
|
|
31841
|
-
this.throwError("Expected " + String.fromCharCode(termination));
|
|
31842
|
-
}
|
|
31843
|
-
return args;
|
|
31844
|
-
}
|
|
31845
|
-
gobbleGroup() {
|
|
31846
|
-
this.index++;
|
|
31847
|
-
let nodes = this.gobbleExpressions(Jsep.CPAREN_CODE);
|
|
31848
|
-
if (this.code === Jsep.CPAREN_CODE) {
|
|
31849
|
-
this.index++;
|
|
31850
|
-
if (nodes.length === 1) {
|
|
31851
|
-
return nodes[0];
|
|
31852
|
-
} else if (!nodes.length) {
|
|
31853
|
-
return false;
|
|
31854
|
-
} else {
|
|
31855
|
-
return {
|
|
31856
|
-
type: Jsep.SEQUENCE_EXP,
|
|
31857
|
-
expressions: nodes
|
|
31858
|
-
};
|
|
31859
|
-
}
|
|
31860
|
-
} else {
|
|
31861
|
-
this.throwError("Unclosed (");
|
|
31862
|
-
}
|
|
31863
|
-
}
|
|
31864
|
-
gobbleArray() {
|
|
31865
|
-
this.index++;
|
|
31866
|
-
return {
|
|
31867
|
-
type: Jsep.ARRAY_EXP,
|
|
31868
|
-
elements: this.gobbleArguments(Jsep.CBRACK_CODE)
|
|
31869
|
-
};
|
|
31870
|
-
}
|
|
31871
|
-
}
|
|
31872
|
-
var hooks = new Hooks;
|
|
31873
|
-
Object.assign(Jsep, {
|
|
31874
|
-
hooks,
|
|
31875
|
-
plugins: new Plugins(Jsep),
|
|
31876
|
-
COMPOUND: "Compound",
|
|
31877
|
-
SEQUENCE_EXP: "SequenceExpression",
|
|
31878
|
-
IDENTIFIER: "Identifier",
|
|
31879
|
-
MEMBER_EXP: "MemberExpression",
|
|
31880
|
-
LITERAL: "Literal",
|
|
31881
|
-
THIS_EXP: "ThisExpression",
|
|
31882
|
-
CALL_EXP: "CallExpression",
|
|
31883
|
-
UNARY_EXP: "UnaryExpression",
|
|
31884
|
-
BINARY_EXP: "BinaryExpression",
|
|
31885
|
-
ARRAY_EXP: "ArrayExpression",
|
|
31886
|
-
TAB_CODE: 9,
|
|
31887
|
-
LF_CODE: 10,
|
|
31888
|
-
CR_CODE: 13,
|
|
31889
|
-
SPACE_CODE: 32,
|
|
31890
|
-
PERIOD_CODE: 46,
|
|
31891
|
-
COMMA_CODE: 44,
|
|
31892
|
-
SQUOTE_CODE: 39,
|
|
31893
|
-
DQUOTE_CODE: 34,
|
|
31894
|
-
OPAREN_CODE: 40,
|
|
31895
|
-
CPAREN_CODE: 41,
|
|
31896
|
-
OBRACK_CODE: 91,
|
|
31897
|
-
CBRACK_CODE: 93,
|
|
31898
|
-
QUMARK_CODE: 63,
|
|
31899
|
-
SEMCOL_CODE: 59,
|
|
31900
|
-
COLON_CODE: 58,
|
|
31901
|
-
unary_ops: {
|
|
31902
|
-
"-": 1,
|
|
31903
|
-
"!": 1,
|
|
31904
|
-
"~": 1,
|
|
31905
|
-
"+": 1
|
|
31906
|
-
},
|
|
31907
|
-
binary_ops: {
|
|
31908
|
-
"||": 1,
|
|
31909
|
-
"??": 1,
|
|
31910
|
-
"&&": 2,
|
|
31911
|
-
"|": 3,
|
|
31912
|
-
"^": 4,
|
|
31913
|
-
"&": 5,
|
|
31914
|
-
"==": 6,
|
|
31915
|
-
"!=": 6,
|
|
31916
|
-
"===": 6,
|
|
31917
|
-
"!==": 6,
|
|
31918
|
-
"<": 7,
|
|
31919
|
-
">": 7,
|
|
31920
|
-
"<=": 7,
|
|
31921
|
-
">=": 7,
|
|
31922
|
-
"<<": 8,
|
|
31923
|
-
">>": 8,
|
|
31924
|
-
">>>": 8,
|
|
31925
|
-
"+": 9,
|
|
31926
|
-
"-": 9,
|
|
31927
|
-
"*": 10,
|
|
31928
|
-
"/": 10,
|
|
31929
|
-
"%": 10,
|
|
31930
|
-
"**": 11
|
|
31931
|
-
},
|
|
31932
|
-
right_associative: new Set(["**"]),
|
|
31933
|
-
additional_identifier_chars: new Set(["$", "_"]),
|
|
31934
|
-
literals: {
|
|
31935
|
-
true: true,
|
|
31936
|
-
false: false,
|
|
31937
|
-
null: null
|
|
31938
|
-
},
|
|
31939
|
-
this_str: "this"
|
|
31940
|
-
});
|
|
31941
|
-
Jsep.max_unop_len = Jsep.getMaxKeyLen(Jsep.unary_ops);
|
|
31942
|
-
Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);
|
|
31943
|
-
var jsep = (expr) => new Jsep(expr).parse();
|
|
31944
|
-
var stdClassProps = Object.getOwnPropertyNames(class Test {
|
|
31945
|
-
});
|
|
31946
|
-
Object.getOwnPropertyNames(Jsep).filter((prop) => !stdClassProps.includes(prop) && jsep[prop] === undefined).forEach((m) => {
|
|
31947
|
-
jsep[m] = Jsep[m];
|
|
31948
|
-
});
|
|
31949
|
-
jsep.Jsep = Jsep;
|
|
31950
|
-
var CONDITIONAL_EXP = "ConditionalExpression";
|
|
31951
|
-
var ternary = {
|
|
31952
|
-
name: "ternary",
|
|
31953
|
-
init(jsep2) {
|
|
31954
|
-
jsep2.hooks.add("after-expression", function gobbleTernary(env) {
|
|
31955
|
-
if (env.node && this.code === jsep2.QUMARK_CODE) {
|
|
31956
|
-
this.index++;
|
|
31957
|
-
const test = env.node;
|
|
31958
|
-
const consequent = this.gobbleExpression();
|
|
31959
|
-
if (!consequent) {
|
|
31960
|
-
this.throwError("Expected expression");
|
|
31961
|
-
}
|
|
31962
|
-
this.gobbleSpaces();
|
|
31963
|
-
if (this.code === jsep2.COLON_CODE) {
|
|
31964
|
-
this.index++;
|
|
31965
|
-
const alternate = this.gobbleExpression();
|
|
31966
|
-
if (!alternate) {
|
|
31967
|
-
this.throwError("Expected expression");
|
|
31968
|
-
}
|
|
31969
|
-
env.node = {
|
|
31970
|
-
type: CONDITIONAL_EXP,
|
|
31971
|
-
test,
|
|
31972
|
-
consequent,
|
|
31973
|
-
alternate
|
|
31974
|
-
};
|
|
31975
|
-
if (test.operator && jsep2.binary_ops[test.operator] <= 0.9) {
|
|
31976
|
-
let newTest = test;
|
|
31977
|
-
while (newTest.right.operator && jsep2.binary_ops[newTest.right.operator] <= 0.9) {
|
|
31978
|
-
newTest = newTest.right;
|
|
31979
|
-
}
|
|
31980
|
-
env.node.test = newTest.right;
|
|
31981
|
-
newTest.right = env.node;
|
|
31982
|
-
env.node = test;
|
|
31983
|
-
}
|
|
31984
|
-
} else {
|
|
31985
|
-
this.throwError("Expected :");
|
|
31986
|
-
}
|
|
31987
|
-
}
|
|
31988
|
-
});
|
|
31989
|
-
}
|
|
31990
|
-
};
|
|
31991
|
-
jsep.plugins.register(ternary);
|
|
31992
|
-
var FSLASH_CODE = 47;
|
|
31993
|
-
var BSLASH_CODE = 92;
|
|
31994
|
-
var index = {
|
|
31995
|
-
name: "regex",
|
|
31996
|
-
init(jsep2) {
|
|
31997
|
-
jsep2.hooks.add("gobble-token", function gobbleRegexLiteral(env) {
|
|
31998
|
-
if (this.code === FSLASH_CODE) {
|
|
31999
|
-
const patternIndex = ++this.index;
|
|
32000
|
-
let inCharSet = false;
|
|
32001
|
-
while (this.index < this.expr.length) {
|
|
32002
|
-
if (this.code === FSLASH_CODE && !inCharSet) {
|
|
32003
|
-
const pattern = this.expr.slice(patternIndex, this.index);
|
|
32004
|
-
let flags = "";
|
|
32005
|
-
while (++this.index < this.expr.length) {
|
|
32006
|
-
const code = this.code;
|
|
32007
|
-
if (code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57) {
|
|
32008
|
-
flags += this.char;
|
|
32009
|
-
} else {
|
|
32010
|
-
break;
|
|
32011
|
-
}
|
|
32012
|
-
}
|
|
32013
|
-
let value;
|
|
32014
|
-
try {
|
|
32015
|
-
value = new RegExp(pattern, flags);
|
|
32016
|
-
} catch (e) {
|
|
32017
|
-
this.throwError(e.message);
|
|
32018
|
-
}
|
|
32019
|
-
env.node = {
|
|
32020
|
-
type: jsep2.LITERAL,
|
|
32021
|
-
value,
|
|
32022
|
-
raw: this.expr.slice(patternIndex - 1, this.index)
|
|
32023
|
-
};
|
|
32024
|
-
env.node = this.gobbleTokenProperty(env.node);
|
|
32025
|
-
return env.node;
|
|
32026
|
-
}
|
|
32027
|
-
if (this.code === jsep2.OBRACK_CODE) {
|
|
32028
|
-
inCharSet = true;
|
|
32029
|
-
} else if (inCharSet && this.code === jsep2.CBRACK_CODE) {
|
|
32030
|
-
inCharSet = false;
|
|
32031
|
-
}
|
|
32032
|
-
this.index += this.code === BSLASH_CODE ? 2 : 1;
|
|
32033
|
-
}
|
|
32034
|
-
this.throwError("Unclosed Regex");
|
|
32035
|
-
}
|
|
32036
|
-
});
|
|
32037
|
-
}
|
|
32038
|
-
};
|
|
32039
|
-
var PLUS_CODE = 43;
|
|
32040
|
-
var MINUS_CODE = 45;
|
|
32041
|
-
var plugin = {
|
|
32042
|
-
name: "assignment",
|
|
32043
|
-
assignmentOperators: new Set(["=", "*=", "**=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "||=", "&&=", "??="]),
|
|
32044
|
-
updateOperators: [PLUS_CODE, MINUS_CODE],
|
|
32045
|
-
assignmentPrecedence: 0.9,
|
|
32046
|
-
init(jsep2) {
|
|
32047
|
-
const updateNodeTypes = [jsep2.IDENTIFIER, jsep2.MEMBER_EXP];
|
|
32048
|
-
plugin.assignmentOperators.forEach((op) => jsep2.addBinaryOp(op, plugin.assignmentPrecedence, true));
|
|
32049
|
-
jsep2.hooks.add("gobble-token", function gobbleUpdatePrefix(env) {
|
|
32050
|
-
const code = this.code;
|
|
32051
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
32052
|
-
this.index += 2;
|
|
32053
|
-
env.node = {
|
|
32054
|
-
type: "UpdateExpression",
|
|
32055
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
32056
|
-
argument: this.gobbleTokenProperty(this.gobbleIdentifier()),
|
|
32057
|
-
prefix: true
|
|
32058
|
-
};
|
|
32059
|
-
if (!env.node.argument || !updateNodeTypes.includes(env.node.argument.type)) {
|
|
32060
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
32061
|
-
}
|
|
32062
|
-
}
|
|
32063
|
-
});
|
|
32064
|
-
jsep2.hooks.add("after-token", function gobbleUpdatePostfix(env) {
|
|
32065
|
-
if (env.node) {
|
|
32066
|
-
const code = this.code;
|
|
32067
|
-
if (plugin.updateOperators.some((c) => c === code && c === this.expr.charCodeAt(this.index + 1))) {
|
|
32068
|
-
if (!updateNodeTypes.includes(env.node.type)) {
|
|
32069
|
-
this.throwError(`Unexpected ${env.node.operator}`);
|
|
32070
|
-
}
|
|
32071
|
-
this.index += 2;
|
|
32072
|
-
env.node = {
|
|
32073
|
-
type: "UpdateExpression",
|
|
32074
|
-
operator: code === PLUS_CODE ? "++" : "--",
|
|
32075
|
-
argument: env.node,
|
|
32076
|
-
prefix: false
|
|
32077
|
-
};
|
|
32078
|
-
}
|
|
32079
|
-
}
|
|
32080
|
-
});
|
|
32081
|
-
jsep2.hooks.add("after-expression", function gobbleAssignment(env) {
|
|
32082
|
-
if (env.node) {
|
|
32083
|
-
updateBinariesToAssignments(env.node);
|
|
32084
|
-
}
|
|
32085
|
-
});
|
|
32086
|
-
function updateBinariesToAssignments(node) {
|
|
32087
|
-
if (plugin.assignmentOperators.has(node.operator)) {
|
|
32088
|
-
node.type = "AssignmentExpression";
|
|
32089
|
-
updateBinariesToAssignments(node.left);
|
|
32090
|
-
updateBinariesToAssignments(node.right);
|
|
32091
|
-
} else if (!node.operator) {
|
|
32092
|
-
Object.values(node).forEach((val) => {
|
|
32093
|
-
if (val && typeof val === "object") {
|
|
32094
|
-
updateBinariesToAssignments(val);
|
|
32095
|
-
}
|
|
32096
|
-
});
|
|
32097
|
-
}
|
|
32098
|
-
}
|
|
32099
|
-
}
|
|
32100
|
-
};
|
|
32101
|
-
jsep.plugins.register(index, plugin);
|
|
32102
|
-
jsep.addUnaryOp("typeof");
|
|
32103
|
-
jsep.addUnaryOp("void");
|
|
32104
|
-
jsep.addLiteral("null", null);
|
|
32105
|
-
jsep.addLiteral("undefined", undefined);
|
|
32106
|
-
var BLOCKED_PROTO_PROPERTIES = new Set(["constructor", "__proto__", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"]);
|
|
32107
|
-
var SafeEval = {
|
|
32108
|
-
evalAst(ast, subs) {
|
|
32109
|
-
switch (ast.type) {
|
|
32110
|
-
case "BinaryExpression":
|
|
32111
|
-
case "LogicalExpression":
|
|
32112
|
-
return SafeEval.evalBinaryExpression(ast, subs);
|
|
32113
|
-
case "Compound":
|
|
32114
|
-
return SafeEval.evalCompound(ast, subs);
|
|
32115
|
-
case "ConditionalExpression":
|
|
32116
|
-
return SafeEval.evalConditionalExpression(ast, subs);
|
|
32117
|
-
case "Identifier":
|
|
32118
|
-
return SafeEval.evalIdentifier(ast, subs);
|
|
32119
|
-
case "Literal":
|
|
32120
|
-
return SafeEval.evalLiteral(ast, subs);
|
|
32121
|
-
case "MemberExpression":
|
|
32122
|
-
return SafeEval.evalMemberExpression(ast, subs);
|
|
32123
|
-
case "UnaryExpression":
|
|
32124
|
-
return SafeEval.evalUnaryExpression(ast, subs);
|
|
32125
|
-
case "ArrayExpression":
|
|
32126
|
-
return SafeEval.evalArrayExpression(ast, subs);
|
|
32127
|
-
case "CallExpression":
|
|
32128
|
-
return SafeEval.evalCallExpression(ast, subs);
|
|
32129
|
-
case "AssignmentExpression":
|
|
32130
|
-
return SafeEval.evalAssignmentExpression(ast, subs);
|
|
32131
|
-
default:
|
|
32132
|
-
throw SyntaxError("Unexpected expression", ast);
|
|
32133
|
-
}
|
|
32134
|
-
},
|
|
32135
|
-
evalBinaryExpression(ast, subs) {
|
|
32136
|
-
const result = {
|
|
32137
|
-
"||": (a, b) => a || b(),
|
|
32138
|
-
"&&": (a, b) => a && b(),
|
|
32139
|
-
"|": (a, b) => a | b(),
|
|
32140
|
-
"^": (a, b) => a ^ b(),
|
|
32141
|
-
"&": (a, b) => a & b(),
|
|
32142
|
-
"==": (a, b) => a == b(),
|
|
32143
|
-
"!=": (a, b) => a != b(),
|
|
32144
|
-
"===": (a, b) => a === b(),
|
|
32145
|
-
"!==": (a, b) => a !== b(),
|
|
32146
|
-
"<": (a, b) => a < b(),
|
|
32147
|
-
">": (a, b) => a > b(),
|
|
32148
|
-
"<=": (a, b) => a <= b(),
|
|
32149
|
-
">=": (a, b) => a >= b(),
|
|
32150
|
-
"<<": (a, b) => a << b(),
|
|
32151
|
-
">>": (a, b) => a >> b(),
|
|
32152
|
-
">>>": (a, b) => a >>> b(),
|
|
32153
|
-
"+": (a, b) => a + b(),
|
|
32154
|
-
"-": (a, b) => a - b(),
|
|
32155
|
-
"*": (a, b) => a * b(),
|
|
32156
|
-
"/": (a, b) => a / b(),
|
|
32157
|
-
"%": (a, b) => a % b()
|
|
32158
|
-
}[ast.operator](SafeEval.evalAst(ast.left, subs), () => SafeEval.evalAst(ast.right, subs));
|
|
32159
|
-
return result;
|
|
32160
|
-
},
|
|
32161
|
-
evalCompound(ast, subs) {
|
|
32162
|
-
let last;
|
|
32163
|
-
for (let i = 0;i < ast.body.length; i++) {
|
|
32164
|
-
if (ast.body[i].type === "Identifier" && ["var", "let", "const"].includes(ast.body[i].name) && ast.body[i + 1] && ast.body[i + 1].type === "AssignmentExpression") {
|
|
32165
|
-
i += 1;
|
|
32166
|
-
}
|
|
32167
|
-
const expr = ast.body[i];
|
|
32168
|
-
last = SafeEval.evalAst(expr, subs);
|
|
32169
|
-
}
|
|
32170
|
-
return last;
|
|
32171
|
-
},
|
|
32172
|
-
evalConditionalExpression(ast, subs) {
|
|
32173
|
-
if (SafeEval.evalAst(ast.test, subs)) {
|
|
32174
|
-
return SafeEval.evalAst(ast.consequent, subs);
|
|
32175
|
-
}
|
|
32176
|
-
return SafeEval.evalAst(ast.alternate, subs);
|
|
32177
|
-
},
|
|
32178
|
-
evalIdentifier(ast, subs) {
|
|
32179
|
-
if (Object.hasOwn(subs, ast.name)) {
|
|
32180
|
-
return subs[ast.name];
|
|
32181
|
-
}
|
|
32182
|
-
throw ReferenceError(`${ast.name} is not defined`);
|
|
32183
|
-
},
|
|
32184
|
-
evalLiteral(ast) {
|
|
32185
|
-
return ast.value;
|
|
32186
|
-
},
|
|
32187
|
-
evalMemberExpression(ast, subs) {
|
|
32188
|
-
const prop = String(ast.computed ? SafeEval.evalAst(ast.property) : ast.property.name);
|
|
32189
|
-
const obj = SafeEval.evalAst(ast.object, subs);
|
|
32190
|
-
if (obj === undefined || obj === null) {
|
|
32191
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
32192
|
-
}
|
|
32193
|
-
if (!Object.hasOwn(obj, prop) && BLOCKED_PROTO_PROPERTIES.has(prop)) {
|
|
32194
|
-
throw TypeError(`Cannot read properties of ${obj} (reading '${prop}')`);
|
|
32195
|
-
}
|
|
32196
|
-
const result = obj[prop];
|
|
32197
|
-
if (typeof result === "function") {
|
|
32198
|
-
return result.bind(obj);
|
|
32199
|
-
}
|
|
32200
|
-
return result;
|
|
32201
|
-
},
|
|
32202
|
-
evalUnaryExpression(ast, subs) {
|
|
32203
|
-
const result = {
|
|
32204
|
-
"-": (a) => -SafeEval.evalAst(a, subs),
|
|
32205
|
-
"!": (a) => !SafeEval.evalAst(a, subs),
|
|
32206
|
-
"~": (a) => ~SafeEval.evalAst(a, subs),
|
|
32207
|
-
"+": (a) => +SafeEval.evalAst(a, subs),
|
|
32208
|
-
typeof: (a) => typeof SafeEval.evalAst(a, subs),
|
|
32209
|
-
void: (a) => void SafeEval.evalAst(a, subs)
|
|
32210
|
-
}[ast.operator](ast.argument);
|
|
32211
|
-
return result;
|
|
32212
|
-
},
|
|
32213
|
-
evalArrayExpression(ast, subs) {
|
|
32214
|
-
return ast.elements.map((el) => SafeEval.evalAst(el, subs));
|
|
32215
|
-
},
|
|
32216
|
-
evalCallExpression(ast, subs) {
|
|
32217
|
-
const args = ast.arguments.map((arg) => SafeEval.evalAst(arg, subs));
|
|
32218
|
-
const func = SafeEval.evalAst(ast.callee, subs);
|
|
32219
|
-
if (func === Function) {
|
|
32220
|
-
throw new Error("Function constructor is disabled");
|
|
32221
|
-
}
|
|
32222
|
-
return func(...args);
|
|
32223
|
-
},
|
|
32224
|
-
evalAssignmentExpression(ast, subs) {
|
|
32225
|
-
if (ast.left.type !== "Identifier") {
|
|
32226
|
-
throw SyntaxError("Invalid left-hand side in assignment");
|
|
32227
|
-
}
|
|
32228
|
-
const id = ast.left.name;
|
|
32229
|
-
const value = SafeEval.evalAst(ast.right, subs);
|
|
32230
|
-
subs[id] = value;
|
|
32231
|
-
return subs[id];
|
|
32232
|
-
}
|
|
32233
|
-
};
|
|
32234
|
-
|
|
32235
|
-
class SafeScript {
|
|
32236
|
-
constructor(expr) {
|
|
32237
|
-
this.code = expr;
|
|
32238
|
-
this.ast = jsep(this.code);
|
|
32239
|
-
}
|
|
32240
|
-
runInNewContext(context) {
|
|
32241
|
-
const keyMap = Object.assign(Object.create(null), context);
|
|
32242
|
-
return SafeEval.evalAst(this.ast, keyMap);
|
|
32243
|
-
}
|
|
32244
|
-
}
|
|
32245
|
-
function push(arr, item) {
|
|
32246
|
-
arr = arr.slice();
|
|
32247
|
-
arr.push(item);
|
|
32248
|
-
return arr;
|
|
32249
|
-
}
|
|
32250
|
-
function unshift(item, arr) {
|
|
32251
|
-
arr = arr.slice();
|
|
32252
|
-
arr.unshift(item);
|
|
32253
|
-
return arr;
|
|
32254
|
-
}
|
|
32255
|
-
|
|
32256
|
-
class NewError extends Error {
|
|
32257
|
-
constructor(value) {
|
|
32258
|
-
super('JSONPath should not be called with "new" (it prevents return ' + "of (unwrapped) scalar values)");
|
|
32259
|
-
this.avoidNew = true;
|
|
32260
|
-
this.value = value;
|
|
32261
|
-
this.name = "NewError";
|
|
32262
|
-
}
|
|
32263
|
-
}
|
|
32264
|
-
function JSONPath(opts, expr, obj, callback, otherTypeCallback) {
|
|
32265
|
-
if (!(this instanceof JSONPath)) {
|
|
32266
|
-
try {
|
|
32267
|
-
return new JSONPath(opts, expr, obj, callback, otherTypeCallback);
|
|
32268
|
-
} catch (e) {
|
|
32269
|
-
if (!e.avoidNew) {
|
|
32270
|
-
throw e;
|
|
32271
|
-
}
|
|
32272
|
-
return e.value;
|
|
32273
|
-
}
|
|
32274
|
-
}
|
|
32275
|
-
if (typeof opts === "string") {
|
|
32276
|
-
otherTypeCallback = callback;
|
|
32277
|
-
callback = obj;
|
|
32278
|
-
obj = expr;
|
|
32279
|
-
expr = opts;
|
|
32280
|
-
opts = null;
|
|
32281
|
-
}
|
|
32282
|
-
const optObj = opts && typeof opts === "object";
|
|
32283
|
-
opts = opts || {};
|
|
32284
|
-
this.json = opts.json || obj;
|
|
32285
|
-
this.path = opts.path || expr;
|
|
32286
|
-
this.resultType = opts.resultType || "value";
|
|
32287
|
-
this.flatten = opts.flatten || false;
|
|
32288
|
-
this.wrap = Object.hasOwn(opts, "wrap") ? opts.wrap : true;
|
|
32289
|
-
this.sandbox = opts.sandbox || {};
|
|
32290
|
-
this.eval = opts.eval === undefined ? "safe" : opts.eval;
|
|
32291
|
-
this.ignoreEvalErrors = typeof opts.ignoreEvalErrors === "undefined" ? false : opts.ignoreEvalErrors;
|
|
32292
|
-
this.parent = opts.parent || null;
|
|
32293
|
-
this.parentProperty = opts.parentProperty || null;
|
|
32294
|
-
this.callback = opts.callback || callback || null;
|
|
32295
|
-
this.otherTypeCallback = opts.otherTypeCallback || otherTypeCallback || function() {
|
|
32296
|
-
throw new TypeError("You must supply an otherTypeCallback callback option " + "with the @other() operator.");
|
|
32297
|
-
};
|
|
32298
|
-
if (opts.autostart !== false) {
|
|
32299
|
-
const args = {
|
|
32300
|
-
path: optObj ? opts.path : expr
|
|
32301
|
-
};
|
|
32302
|
-
if (!optObj) {
|
|
32303
|
-
args.json = obj;
|
|
32304
|
-
} else if ("json" in opts) {
|
|
32305
|
-
args.json = opts.json;
|
|
32306
|
-
}
|
|
32307
|
-
const ret = this.evaluate(args);
|
|
32308
|
-
if (!ret || typeof ret !== "object") {
|
|
32309
|
-
throw new NewError(ret);
|
|
32310
|
-
}
|
|
32311
|
-
return ret;
|
|
32312
|
-
}
|
|
32313
|
-
}
|
|
32314
|
-
JSONPath.prototype.evaluate = function(expr, json, callback, otherTypeCallback) {
|
|
32315
|
-
let currParent = this.parent, currParentProperty = this.parentProperty;
|
|
32316
|
-
let {
|
|
32317
|
-
flatten,
|
|
32318
|
-
wrap
|
|
32319
|
-
} = this;
|
|
32320
|
-
this.currResultType = this.resultType;
|
|
32321
|
-
this.currEval = this.eval;
|
|
32322
|
-
this.currSandbox = this.sandbox;
|
|
32323
|
-
callback = callback || this.callback;
|
|
32324
|
-
this.currOtherTypeCallback = otherTypeCallback || this.otherTypeCallback;
|
|
32325
|
-
json = json || this.json;
|
|
32326
|
-
expr = expr || this.path;
|
|
32327
|
-
if (expr && typeof expr === "object" && !Array.isArray(expr)) {
|
|
32328
|
-
if (!expr.path && expr.path !== "") {
|
|
32329
|
-
throw new TypeError('You must supply a "path" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
32330
|
-
}
|
|
32331
|
-
if (!Object.hasOwn(expr, "json")) {
|
|
32332
|
-
throw new TypeError('You must supply a "json" property when providing an object ' + "argument to JSONPath.evaluate().");
|
|
32333
|
-
}
|
|
32334
|
-
({
|
|
32335
|
-
json
|
|
32336
|
-
} = expr);
|
|
32337
|
-
flatten = Object.hasOwn(expr, "flatten") ? expr.flatten : flatten;
|
|
32338
|
-
this.currResultType = Object.hasOwn(expr, "resultType") ? expr.resultType : this.currResultType;
|
|
32339
|
-
this.currSandbox = Object.hasOwn(expr, "sandbox") ? expr.sandbox : this.currSandbox;
|
|
32340
|
-
wrap = Object.hasOwn(expr, "wrap") ? expr.wrap : wrap;
|
|
32341
|
-
this.currEval = Object.hasOwn(expr, "eval") ? expr.eval : this.currEval;
|
|
32342
|
-
callback = Object.hasOwn(expr, "callback") ? expr.callback : callback;
|
|
32343
|
-
this.currOtherTypeCallback = Object.hasOwn(expr, "otherTypeCallback") ? expr.otherTypeCallback : this.currOtherTypeCallback;
|
|
32344
|
-
currParent = Object.hasOwn(expr, "parent") ? expr.parent : currParent;
|
|
32345
|
-
currParentProperty = Object.hasOwn(expr, "parentProperty") ? expr.parentProperty : currParentProperty;
|
|
32346
|
-
expr = expr.path;
|
|
32347
|
-
}
|
|
32348
|
-
currParent = currParent || null;
|
|
32349
|
-
currParentProperty = currParentProperty || null;
|
|
32350
|
-
if (Array.isArray(expr)) {
|
|
32351
|
-
expr = JSONPath.toPathString(expr);
|
|
32352
|
-
}
|
|
32353
|
-
if (!expr && expr !== "" || !json) {
|
|
32354
|
-
return;
|
|
32355
|
-
}
|
|
32356
|
-
const exprList = JSONPath.toPathArray(expr);
|
|
32357
|
-
if (exprList[0] === "$" && exprList.length > 1) {
|
|
32358
|
-
exprList.shift();
|
|
32359
|
-
}
|
|
32360
|
-
this._hasParentSelector = null;
|
|
32361
|
-
const result = this._trace(exprList, json, ["$"], currParent, currParentProperty, callback).filter(function(ea) {
|
|
32362
|
-
return ea && !ea.isParentSelector;
|
|
32363
|
-
});
|
|
32364
|
-
if (!result.length) {
|
|
32365
|
-
return wrap ? [] : undefined;
|
|
32366
|
-
}
|
|
32367
|
-
if (!wrap && result.length === 1 && !result[0].hasArrExpr) {
|
|
32368
|
-
return this._getPreferredOutput(result[0]);
|
|
32369
|
-
}
|
|
32370
|
-
return result.reduce((rslt, ea) => {
|
|
32371
|
-
const valOrPath = this._getPreferredOutput(ea);
|
|
32372
|
-
if (flatten && Array.isArray(valOrPath)) {
|
|
32373
|
-
rslt = rslt.concat(valOrPath);
|
|
32374
|
-
} else {
|
|
32375
|
-
rslt.push(valOrPath);
|
|
32376
|
-
}
|
|
32377
|
-
return rslt;
|
|
32378
|
-
}, []);
|
|
32379
|
-
};
|
|
32380
|
-
JSONPath.prototype._getPreferredOutput = function(ea) {
|
|
32381
|
-
const resultType = this.currResultType;
|
|
32382
|
-
switch (resultType) {
|
|
32383
|
-
case "all": {
|
|
32384
|
-
const path3 = Array.isArray(ea.path) ? ea.path : JSONPath.toPathArray(ea.path);
|
|
32385
|
-
ea.pointer = JSONPath.toPointer(path3);
|
|
32386
|
-
ea.path = typeof ea.path === "string" ? ea.path : JSONPath.toPathString(ea.path);
|
|
32387
|
-
return ea;
|
|
32388
|
-
}
|
|
32389
|
-
case "value":
|
|
32390
|
-
case "parent":
|
|
32391
|
-
case "parentProperty":
|
|
32392
|
-
return ea[resultType];
|
|
32393
|
-
case "path":
|
|
32394
|
-
return JSONPath.toPathString(ea[resultType]);
|
|
32395
|
-
case "pointer":
|
|
32396
|
-
return JSONPath.toPointer(ea.path);
|
|
32397
|
-
default:
|
|
32398
|
-
throw new TypeError("Unknown result type");
|
|
32399
|
-
}
|
|
32400
|
-
};
|
|
32401
|
-
JSONPath.prototype._handleCallback = function(fullRetObj, callback, type) {
|
|
32402
|
-
if (callback) {
|
|
32403
|
-
const preferredOutput = this._getPreferredOutput(fullRetObj);
|
|
32404
|
-
fullRetObj.path = typeof fullRetObj.path === "string" ? fullRetObj.path : JSONPath.toPathString(fullRetObj.path);
|
|
32405
|
-
callback(preferredOutput, type, fullRetObj);
|
|
32406
|
-
}
|
|
32407
|
-
};
|
|
32408
|
-
JSONPath.prototype._trace = function(expr, val, path3, parent, parentPropName, callback, hasArrExpr, literalPriority) {
|
|
32409
|
-
let retObj;
|
|
32410
|
-
if (!expr.length) {
|
|
32411
|
-
retObj = {
|
|
32412
|
-
path: path3,
|
|
32413
|
-
value: val,
|
|
32414
|
-
parent,
|
|
32415
|
-
parentProperty: parentPropName,
|
|
32416
|
-
hasArrExpr
|
|
32417
|
-
};
|
|
32418
|
-
this._handleCallback(retObj, callback, "value");
|
|
32419
|
-
return retObj;
|
|
32420
|
-
}
|
|
32421
|
-
const loc = expr[0], x = expr.slice(1);
|
|
32422
|
-
const ret = [];
|
|
32423
|
-
function addRet(elems) {
|
|
32424
|
-
if (Array.isArray(elems)) {
|
|
32425
|
-
elems.forEach((t) => {
|
|
32426
|
-
ret.push(t);
|
|
32427
|
-
});
|
|
32428
|
-
} else {
|
|
32429
|
-
ret.push(elems);
|
|
32430
|
-
}
|
|
32431
|
-
}
|
|
32432
|
-
if ((typeof loc !== "string" || literalPriority) && val && Object.hasOwn(val, loc)) {
|
|
32433
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr));
|
|
32434
|
-
} else if (loc === "*") {
|
|
32435
|
-
this._walk(val, (m) => {
|
|
32436
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true, true));
|
|
32437
|
-
});
|
|
32438
|
-
} else if (loc === "..") {
|
|
32439
|
-
addRet(this._trace(x, val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
32440
|
-
this._walk(val, (m) => {
|
|
32441
|
-
if (typeof val[m] === "object") {
|
|
32442
|
-
addRet(this._trace(expr.slice(), val[m], push(path3, m), val, m, callback, true));
|
|
32443
|
-
}
|
|
32444
|
-
});
|
|
32445
|
-
} else if (loc === "^") {
|
|
32446
|
-
this._hasParentSelector = true;
|
|
32447
|
-
return {
|
|
32448
|
-
path: path3.slice(0, -1),
|
|
32449
|
-
expr: x,
|
|
32450
|
-
isParentSelector: true
|
|
32451
|
-
};
|
|
32452
|
-
} else if (loc === "~") {
|
|
32453
|
-
retObj = {
|
|
32454
|
-
path: push(path3, loc),
|
|
32455
|
-
value: parentPropName,
|
|
32456
|
-
parent,
|
|
32457
|
-
parentProperty: null
|
|
32458
|
-
};
|
|
32459
|
-
this._handleCallback(retObj, callback, "property");
|
|
32460
|
-
return retObj;
|
|
32461
|
-
} else if (loc === "$") {
|
|
32462
|
-
addRet(this._trace(x, val, path3, null, null, callback, hasArrExpr));
|
|
32463
|
-
} else if (/^(-?\d*):(-?\d*):?(\d*)$/u.test(loc)) {
|
|
32464
|
-
addRet(this._slice(loc, x, val, path3, parent, parentPropName, callback));
|
|
32465
|
-
} else if (loc.indexOf("?(") === 0) {
|
|
32466
|
-
if (this.currEval === false) {
|
|
32467
|
-
throw new Error("Eval [?(expr)] prevented in JSONPath expression.");
|
|
32468
|
-
}
|
|
32469
|
-
const safeLoc = loc.replace(/^\?\((.*?)\)$/u, "$1");
|
|
32470
|
-
const nested = /@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(safeLoc);
|
|
32471
|
-
if (nested) {
|
|
32472
|
-
this._walk(val, (m) => {
|
|
32473
|
-
const npath = [nested[2]];
|
|
32474
|
-
const nvalue = nested[1] ? val[m][nested[1]] : val[m];
|
|
32475
|
-
const filterResults = this._trace(npath, nvalue, path3, parent, parentPropName, callback, true);
|
|
32476
|
-
if (filterResults.length > 0) {
|
|
32477
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
32478
|
-
}
|
|
32479
|
-
});
|
|
32480
|
-
} else {
|
|
32481
|
-
this._walk(val, (m) => {
|
|
32482
|
-
if (this._eval(safeLoc, val[m], m, path3, parent, parentPropName)) {
|
|
32483
|
-
addRet(this._trace(x, val[m], push(path3, m), val, m, callback, true));
|
|
32484
|
-
}
|
|
32485
|
-
});
|
|
32486
|
-
}
|
|
32487
|
-
} else if (loc[0] === "(") {
|
|
32488
|
-
if (this.currEval === false) {
|
|
32489
|
-
throw new Error("Eval [(expr)] prevented in JSONPath expression.");
|
|
32490
|
-
}
|
|
32491
|
-
addRet(this._trace(unshift(this._eval(loc, val, path3.at(-1), path3.slice(0, -1), parent, parentPropName), x), val, path3, parent, parentPropName, callback, hasArrExpr));
|
|
32492
|
-
} else if (loc[0] === "@") {
|
|
32493
|
-
let addType = false;
|
|
32494
|
-
const valueType = loc.slice(1, -2);
|
|
32495
|
-
switch (valueType) {
|
|
32496
|
-
case "scalar":
|
|
32497
|
-
if (!val || !["object", "function"].includes(typeof val)) {
|
|
32498
|
-
addType = true;
|
|
32499
|
-
}
|
|
32500
|
-
break;
|
|
32501
|
-
case "boolean":
|
|
32502
|
-
case "string":
|
|
32503
|
-
case "undefined":
|
|
32504
|
-
case "function":
|
|
32505
|
-
if (typeof val === valueType) {
|
|
32506
|
-
addType = true;
|
|
32507
|
-
}
|
|
32508
|
-
break;
|
|
32509
|
-
case "integer":
|
|
32510
|
-
if (Number.isFinite(val) && !(val % 1)) {
|
|
32511
|
-
addType = true;
|
|
32512
|
-
}
|
|
32513
|
-
break;
|
|
32514
|
-
case "number":
|
|
32515
|
-
if (Number.isFinite(val)) {
|
|
32516
|
-
addType = true;
|
|
32517
|
-
}
|
|
32518
|
-
break;
|
|
32519
|
-
case "nonFinite":
|
|
32520
|
-
if (typeof val === "number" && !Number.isFinite(val)) {
|
|
32521
|
-
addType = true;
|
|
32522
|
-
}
|
|
32523
|
-
break;
|
|
32524
|
-
case "object":
|
|
32525
|
-
if (val && typeof val === valueType) {
|
|
32526
|
-
addType = true;
|
|
32527
|
-
}
|
|
32528
|
-
break;
|
|
32529
|
-
case "array":
|
|
32530
|
-
if (Array.isArray(val)) {
|
|
32531
|
-
addType = true;
|
|
32532
|
-
}
|
|
32533
|
-
break;
|
|
32534
|
-
case "other":
|
|
32535
|
-
addType = this.currOtherTypeCallback(val, path3, parent, parentPropName);
|
|
32536
|
-
break;
|
|
32537
|
-
case "null":
|
|
32538
|
-
if (val === null) {
|
|
32539
|
-
addType = true;
|
|
32540
|
-
}
|
|
32541
|
-
break;
|
|
32542
|
-
default:
|
|
32543
|
-
throw new TypeError("Unknown value type " + valueType);
|
|
32544
|
-
}
|
|
32545
|
-
if (addType) {
|
|
32546
|
-
retObj = {
|
|
32547
|
-
path: path3,
|
|
32548
|
-
value: val,
|
|
32549
|
-
parent,
|
|
32550
|
-
parentProperty: parentPropName
|
|
32551
|
-
};
|
|
32552
|
-
this._handleCallback(retObj, callback, "value");
|
|
32553
|
-
return retObj;
|
|
32554
|
-
}
|
|
32555
|
-
} else if (loc[0] === "`" && val && Object.hasOwn(val, loc.slice(1))) {
|
|
32556
|
-
const locProp = loc.slice(1);
|
|
32557
|
-
addRet(this._trace(x, val[locProp], push(path3, locProp), val, locProp, callback, hasArrExpr, true));
|
|
32558
|
-
} else if (loc.includes(",")) {
|
|
32559
|
-
const parts = loc.split(",");
|
|
32560
|
-
for (const part of parts) {
|
|
32561
|
-
addRet(this._trace(unshift(part, x), val, path3, parent, parentPropName, callback, true));
|
|
32562
|
-
}
|
|
32563
|
-
} else if (!literalPriority && val && Object.hasOwn(val, loc)) {
|
|
32564
|
-
addRet(this._trace(x, val[loc], push(path3, loc), val, loc, callback, hasArrExpr, true));
|
|
32565
|
-
}
|
|
32566
|
-
if (this._hasParentSelector) {
|
|
32567
|
-
for (let t = 0;t < ret.length; t++) {
|
|
32568
|
-
const rett = ret[t];
|
|
32569
|
-
if (rett && rett.isParentSelector) {
|
|
32570
|
-
const tmp = this._trace(rett.expr, val, rett.path, parent, parentPropName, callback, hasArrExpr);
|
|
32571
|
-
if (Array.isArray(tmp)) {
|
|
32572
|
-
ret[t] = tmp[0];
|
|
32573
|
-
const tl = tmp.length;
|
|
32574
|
-
for (let tt = 1;tt < tl; tt++) {
|
|
32575
|
-
t++;
|
|
32576
|
-
ret.splice(t, 0, tmp[tt]);
|
|
32577
|
-
}
|
|
32578
|
-
} else {
|
|
32579
|
-
ret[t] = tmp;
|
|
32580
|
-
}
|
|
32581
|
-
}
|
|
32582
|
-
}
|
|
32583
|
-
}
|
|
32584
|
-
return ret;
|
|
32585
|
-
};
|
|
32586
|
-
JSONPath.prototype._walk = function(val, f) {
|
|
32587
|
-
if (Array.isArray(val)) {
|
|
32588
|
-
const n = val.length;
|
|
32589
|
-
for (let i = 0;i < n; i++) {
|
|
32590
|
-
f(i);
|
|
32591
|
-
}
|
|
32592
|
-
} else if (val && typeof val === "object") {
|
|
32593
|
-
Object.keys(val).forEach((m) => {
|
|
32594
|
-
f(m);
|
|
32595
|
-
});
|
|
32596
|
-
}
|
|
32597
|
-
};
|
|
32598
|
-
JSONPath.prototype._slice = function(loc, expr, val, path3, parent, parentPropName, callback) {
|
|
32599
|
-
if (!Array.isArray(val)) {
|
|
32600
|
-
return;
|
|
32601
|
-
}
|
|
32602
|
-
const len = val.length, parts = loc.split(":"), step = parts[2] && Number.parseInt(parts[2]) || 1;
|
|
32603
|
-
let start = parts[0] && Number.parseInt(parts[0]) || 0, end = parts[1] && Number.parseInt(parts[1]) || len;
|
|
32604
|
-
start = start < 0 ? Math.max(0, start + len) : Math.min(len, start);
|
|
32605
|
-
end = end < 0 ? Math.max(0, end + len) : Math.min(len, end);
|
|
32606
|
-
const ret = [];
|
|
32607
|
-
for (let i = start;i < end; i += step) {
|
|
32608
|
-
const tmp = this._trace(unshift(i, expr), val, path3, parent, parentPropName, callback, true);
|
|
32609
|
-
tmp.forEach((t) => {
|
|
32610
|
-
ret.push(t);
|
|
32611
|
-
});
|
|
32612
|
-
}
|
|
32613
|
-
return ret;
|
|
32614
|
-
};
|
|
32615
|
-
JSONPath.prototype._eval = function(code, _v, _vname, path3, parent, parentPropName) {
|
|
32616
|
-
this.currSandbox._$_parentProperty = parentPropName;
|
|
32617
|
-
this.currSandbox._$_parent = parent;
|
|
32618
|
-
this.currSandbox._$_property = _vname;
|
|
32619
|
-
this.currSandbox._$_root = this.json;
|
|
32620
|
-
this.currSandbox._$_v = _v;
|
|
32621
|
-
const containsPath = code.includes("@path");
|
|
32622
|
-
if (containsPath) {
|
|
32623
|
-
this.currSandbox._$_path = JSONPath.toPathString(path3.concat([_vname]));
|
|
32624
|
-
}
|
|
32625
|
-
const scriptCacheKey = this.currEval + "Script:" + code;
|
|
32626
|
-
if (!JSONPath.cache[scriptCacheKey]) {
|
|
32627
|
-
let script = code.replaceAll("@parentProperty", "_$_parentProperty").replaceAll("@parent", "_$_parent").replaceAll("@property", "_$_property").replaceAll("@root", "_$_root").replaceAll(/@([.\s)[])/gu, "_$_v$1");
|
|
32628
|
-
if (containsPath) {
|
|
32629
|
-
script = script.replaceAll("@path", "_$_path");
|
|
32630
|
-
}
|
|
32631
|
-
if (this.currEval === "safe" || this.currEval === true || this.currEval === undefined) {
|
|
32632
|
-
JSONPath.cache[scriptCacheKey] = new this.safeVm.Script(script);
|
|
32633
|
-
} else if (this.currEval === "native") {
|
|
32634
|
-
JSONPath.cache[scriptCacheKey] = new this.vm.Script(script);
|
|
32635
|
-
} else if (typeof this.currEval === "function" && this.currEval.prototype && Object.hasOwn(this.currEval.prototype, "runInNewContext")) {
|
|
32636
|
-
const CurrEval = this.currEval;
|
|
32637
|
-
JSONPath.cache[scriptCacheKey] = new CurrEval(script);
|
|
32638
|
-
} else if (typeof this.currEval === "function") {
|
|
32639
|
-
JSONPath.cache[scriptCacheKey] = {
|
|
32640
|
-
runInNewContext: (context) => this.currEval(script, context)
|
|
32641
|
-
};
|
|
32642
|
-
} else {
|
|
32643
|
-
throw new TypeError(`Unknown "eval" property "${this.currEval}"`);
|
|
32644
|
-
}
|
|
32645
|
-
}
|
|
32646
|
-
try {
|
|
32647
|
-
return JSONPath.cache[scriptCacheKey].runInNewContext(this.currSandbox);
|
|
32648
|
-
} catch (e) {
|
|
32649
|
-
if (this.ignoreEvalErrors) {
|
|
32650
|
-
return false;
|
|
32651
|
-
}
|
|
32652
|
-
throw new Error("jsonPath: " + e.message + ": " + code);
|
|
32653
|
-
}
|
|
32654
|
-
};
|
|
32655
|
-
JSONPath.cache = {};
|
|
32656
|
-
JSONPath.toPathString = function(pathArr) {
|
|
32657
|
-
const x = pathArr, n = x.length;
|
|
32658
|
-
let p = "$";
|
|
32659
|
-
for (let i = 1;i < n; i++) {
|
|
32660
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
32661
|
-
p += /^[0-9*]+$/u.test(x[i]) ? "[" + x[i] + "]" : "['" + x[i] + "']";
|
|
32662
|
-
}
|
|
32663
|
-
}
|
|
32664
|
-
return p;
|
|
32665
|
-
};
|
|
32666
|
-
JSONPath.toPointer = function(pointer) {
|
|
32667
|
-
const x = pointer, n = x.length;
|
|
32668
|
-
let p = "";
|
|
32669
|
-
for (let i = 1;i < n; i++) {
|
|
32670
|
-
if (!/^(~|\^|@.*?\(\))$/u.test(x[i])) {
|
|
32671
|
-
p += "/" + x[i].toString().replaceAll("~", "~0").replaceAll("/", "~1");
|
|
32672
|
-
}
|
|
32673
|
-
}
|
|
32674
|
-
return p;
|
|
32675
|
-
};
|
|
32676
|
-
JSONPath.toPathArray = function(expr) {
|
|
32677
|
-
const {
|
|
32678
|
-
cache
|
|
32679
|
-
} = JSONPath;
|
|
32680
|
-
if (cache[expr]) {
|
|
32681
|
-
return cache[expr].concat();
|
|
32682
|
-
}
|
|
32683
|
-
const subx = [];
|
|
32684
|
-
const normalized = expr.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu, ";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu, function($0, $1) {
|
|
32685
|
-
return "[#" + (subx.push($1) - 1) + "]";
|
|
32686
|
-
}).replaceAll(/\[['"]([^'\]]*)['"]\]/gu, function($0, prop) {
|
|
32687
|
-
return "['" + prop.replaceAll(".", "%@%").replaceAll("~", "%%@@%%") + "']";
|
|
32688
|
-
}).replaceAll("~", ";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu, ";").replaceAll("%@%", ".").replaceAll("%%@@%%", "~").replaceAll(/(?:;)?(\^+)(?:;)?/gu, function($0, ups) {
|
|
32689
|
-
return ";" + ups.split("").join(";") + ";";
|
|
32690
|
-
}).replaceAll(/;;;|;;/gu, ";..;").replaceAll(/;$|'?\]|'$/gu, "");
|
|
32691
|
-
const exprList = normalized.split(";").map(function(exp) {
|
|
32692
|
-
const match = exp.match(/#(\d+)/u);
|
|
32693
|
-
return !match || !match[1] ? exp : subx[match[1]];
|
|
32694
|
-
});
|
|
32695
|
-
cache[expr] = exprList;
|
|
32696
|
-
return cache[expr].concat();
|
|
32697
|
-
};
|
|
32698
|
-
JSONPath.prototype.safeVm = {
|
|
32699
|
-
Script: SafeScript
|
|
32700
|
-
};
|
|
32701
|
-
JSONPath.prototype.vm = vm;
|
|
32702
31664
|
// ../../common/src/option-validators.ts
|
|
32703
31665
|
function parseLimit(raw, _previous) {
|
|
32704
31666
|
return parseBoundedInt(raw, "--limit", { min: 1, max: 1e4 });
|
|
@@ -32751,6 +31713,17 @@ var FAILURE_STATUSES = new Set([
|
|
|
32751
31713
|
"canceled",
|
|
32752
31714
|
"stopped"
|
|
32753
31715
|
]);
|
|
31716
|
+
// ../../common/src/preview.ts
|
|
31717
|
+
var previewSlot = singleton("PreviewBuild");
|
|
31718
|
+
function isPreviewBuild() {
|
|
31719
|
+
return previewSlot.get(false) ?? false;
|
|
31720
|
+
}
|
|
31721
|
+
Command.prototype.previewCommand = function(nameAndArgs, opts) {
|
|
31722
|
+
if (isPreviewBuild()) {
|
|
31723
|
+
return this.command(nameAndArgs, opts);
|
|
31724
|
+
}
|
|
31725
|
+
return new Command(nameAndArgs.split(/\s+/)[0] ?? nameAndArgs);
|
|
31726
|
+
};
|
|
32754
31727
|
// ../../common/src/screen-logger.ts
|
|
32755
31728
|
var ScreenLogger;
|
|
32756
31729
|
((ScreenLogger) => {
|
|
@@ -32855,8 +31828,27 @@ async function forEachExportEntry(api, from, to, onEntry) {
|
|
|
32855
31828
|
}
|
|
32856
31829
|
return { days: chunks.length, nonEmptyDays };
|
|
32857
31830
|
}
|
|
32858
|
-
|
|
32859
|
-
const
|
|
31831
|
+
function exportBaseName(from, to, generatedAt) {
|
|
31832
|
+
const day = (d) => d.toISOString().slice(0, 10);
|
|
31833
|
+
const stamp = generatedAt.toISOString().slice(0, 19).replace(/[-:]/g, "");
|
|
31834
|
+
return `audit_${day(from)}_${day(to)}_${stamp}`;
|
|
31835
|
+
}
|
|
31836
|
+
function toJsonFileName(preferredName) {
|
|
31837
|
+
return `${basenameNoExt(preferredName)}.json`;
|
|
31838
|
+
}
|
|
31839
|
+
function isSafeExportEntryName(name) {
|
|
31840
|
+
return name.length > 0 && name !== "." && name !== ".." && !name.includes("/") && !name.includes("\\") && !name.includes("\x00");
|
|
31841
|
+
}
|
|
31842
|
+
function isWithinDir(dir, resolved) {
|
|
31843
|
+
let end = dir.length;
|
|
31844
|
+
while (end > 0 && (dir[end - 1] === "/" || dir[end - 1] === "\\")) {
|
|
31845
|
+
end -= 1;
|
|
31846
|
+
}
|
|
31847
|
+
const base = dir.slice(0, end);
|
|
31848
|
+
return resolved === base || resolved.startsWith(`${base}/`) || resolved.startsWith(`${base}\\`);
|
|
31849
|
+
}
|
|
31850
|
+
async function downloadChunkedJsonExport(api, from, to) {
|
|
31851
|
+
const files = [];
|
|
32860
31852
|
const used = new Set;
|
|
32861
31853
|
function addUnique(preferredName, isoDay, data) {
|
|
32862
31854
|
let name = preferredName;
|
|
@@ -32871,10 +31863,10 @@ async function downloadChunkedExport(api, from, to) {
|
|
|
32871
31863
|
}
|
|
32872
31864
|
}
|
|
32873
31865
|
used.add(name);
|
|
32874
|
-
|
|
31866
|
+
files.push({ name, data });
|
|
32875
31867
|
}
|
|
32876
|
-
const { days, nonEmptyDays } = await forEachExportEntry(api, from, to, ({ isoDay, preferredName, data }) => addUnique(preferredName, isoDay, data));
|
|
32877
|
-
return {
|
|
31868
|
+
const { days, nonEmptyDays } = await forEachExportEntry(api, from, to, ({ isoDay, preferredName, data }) => addUnique(toJsonFileName(preferredName), isoDay, data));
|
|
31869
|
+
return { files, days, nonEmptyDays };
|
|
32878
31870
|
}
|
|
32879
31871
|
var PREFERRED_CSV_COLUMNS = [
|
|
32880
31872
|
"Id",
|
|
@@ -32983,12 +31975,14 @@ function instructionsFor(verb, error) {
|
|
|
32983
31975
|
if (/Invalid --status/.test(msg))
|
|
32984
31976
|
return "Use --status Success or --status Failure (case-insensitive).";
|
|
32985
31977
|
if (/Invalid --file-format/.test(msg))
|
|
32986
|
-
return "Use --file-format
|
|
31978
|
+
return "Use --file-format json (default) or --file-format csv.";
|
|
31979
|
+
if (/unsafe name|outside the output folder/i.test(msg))
|
|
31980
|
+
return "The export contained a file whose name would escape --output-path. This indicates a malformed server response — re-run, and report it if it persists.";
|
|
32987
31981
|
if (verb === "sources")
|
|
32988
31982
|
return "Confirm scope (org vs tenant) matches your intent and that you are logged in.";
|
|
32989
31983
|
if (verb === "events")
|
|
32990
31984
|
return "Discover GUIDs via 'audit <scope> sources --output json' before passing --source/--target/--type. Verify --from-date/--to-date are ISO 8601.";
|
|
32991
|
-
return "Verify --from-date/--to-date are ISO 8601 and the --output-
|
|
31985
|
+
return "Verify --from-date/--to-date are ISO 8601 and the --output-path directory is writable. Single-day chunk failures are transient — re-run.";
|
|
32992
31986
|
}
|
|
32993
31987
|
function registerScopeCommands(parent, opts) {
|
|
32994
31988
|
registerSources(parent, opts);
|
|
@@ -33201,10 +32195,10 @@ function registerEvents(parent, opts) {
|
|
|
33201
32195
|
});
|
|
33202
32196
|
}
|
|
33203
32197
|
function parseFormat(raw) {
|
|
33204
|
-
const normalized = (raw ?? "
|
|
33205
|
-
if (normalized === "
|
|
32198
|
+
const normalized = (raw ?? "json").trim().toLowerCase();
|
|
32199
|
+
if (normalized === "json" || normalized === "csv")
|
|
33206
32200
|
return normalized;
|
|
33207
|
-
throw new Error(`Invalid --file-format '${raw}'. Use '
|
|
32201
|
+
throw new Error(`Invalid --file-format '${raw}'. Use 'json' or 'csv'.`);
|
|
33208
32202
|
}
|
|
33209
32203
|
function exportExamples({
|
|
33210
32204
|
scope,
|
|
@@ -33212,31 +32206,34 @@ function exportExamples({
|
|
|
33212
32206
|
}) {
|
|
33213
32207
|
return [
|
|
33214
32208
|
{
|
|
33215
|
-
Description: `Export ${scope} audit events for January 2026
|
|
33216
|
-
Command: `uip admin audit ${scope} export --from-date 2026-01-01 --to-date 2026-02-01 --output-
|
|
32209
|
+
Description: `Export ${scope} audit events for January 2026 — a timestamped folder of day-wise JSON files is created under the base dir`,
|
|
32210
|
+
Command: `uip admin audit ${scope} export --from-date 2026-01-01 --to-date 2026-02-01 --output-path ./audit-exports`,
|
|
33217
32211
|
Output: {
|
|
33218
32212
|
Code: `Audit${codeSuffix}Export`,
|
|
33219
32213
|
Data: {
|
|
33220
|
-
Path: `./audit
|
|
32214
|
+
Path: `./audit-exports/audit_2026-01-01_2026-02-01_20260617T112630`,
|
|
32215
|
+
Format: "json",
|
|
32216
|
+
Files: 27,
|
|
33221
32217
|
Bytes: 12345,
|
|
33222
|
-
Format: "zip",
|
|
33223
32218
|
Days: 31,
|
|
33224
|
-
NonEmptyDays: 27
|
|
32219
|
+
NonEmptyDays: 27,
|
|
32220
|
+
GeneratedAt: "2026-06-17T11:26:30.000Z"
|
|
33225
32221
|
}
|
|
33226
32222
|
}
|
|
33227
32223
|
},
|
|
33228
32224
|
{
|
|
33229
|
-
Description: `Export the same window into a single merged CSV instead of a
|
|
33230
|
-
Command: `uip admin audit ${scope} export --from-date 2026-01-01 --to-date 2026-02-01 --file-format csv --output-
|
|
32225
|
+
Description: `Export the same window into a single merged CSV (a uniquely-named .csv under the base dir) instead of a folder`,
|
|
32226
|
+
Command: `uip admin audit ${scope} export --from-date 2026-01-01 --to-date 2026-02-01 --file-format csv --output-path ./audit-exports`,
|
|
33231
32227
|
Output: {
|
|
33232
32228
|
Code: `Audit${codeSuffix}Export`,
|
|
33233
32229
|
Data: {
|
|
33234
|
-
Path: `./audit
|
|
33235
|
-
Bytes: 98765,
|
|
32230
|
+
Path: `./audit-exports/audit_2026-01-01_2026-02-01_20260617T112630.csv`,
|
|
33236
32231
|
Format: "csv",
|
|
32232
|
+
Bytes: 98765,
|
|
33237
32233
|
Days: 31,
|
|
33238
32234
|
NonEmptyDays: 27,
|
|
33239
|
-
Events: 1234
|
|
32235
|
+
Events: 1234,
|
|
32236
|
+
GeneratedAt: "2026-06-17T11:26:30.000Z"
|
|
33240
32237
|
}
|
|
33241
32238
|
}
|
|
33242
32239
|
}
|
|
@@ -33247,22 +32244,33 @@ function registerExport(parent, opts) {
|
|
|
33247
32244
|
const cmd = parent.command("export").description([
|
|
33248
32245
|
`Export audit events from the long-term store at the ${scope} scope.`,
|
|
33249
32246
|
"",
|
|
33250
|
-
"Issues one HTTP call per UTC day inside [--from-date, --to-date]
|
|
33251
|
-
"responses in memory
|
|
33252
|
-
"
|
|
33253
|
-
"
|
|
32247
|
+
"Issues one HTTP call per UTC day inside [--from-date, --to-date] and aggregates the daily",
|
|
32248
|
+
"responses in memory before writing them out. The full window is fetched first: on any chunk",
|
|
32249
|
+
"failure the export is aborted atomically — nothing is written, and the structured Failure",
|
|
32250
|
+
"result identifies the day that failed.",
|
|
33254
32251
|
"",
|
|
33255
|
-
"--
|
|
33256
|
-
"
|
|
33257
|
-
"
|
|
32252
|
+
"--output-path is a base DIRECTORY, not a file path — pass a folder and the CLI",
|
|
32253
|
+
"generates the per-export name for you (you do NOT supply a filename). Each run creates",
|
|
32254
|
+
"a uniquely-named output inside it, stamped with the window + generation time",
|
|
32255
|
+
"(e.g. audit_2026-01-01_2026-02-01_20260617T112630), so repeated exports of the same",
|
|
32256
|
+
"window never collide. --file-format controls the shape:",
|
|
32257
|
+
" json (default) — a folder of one JSON file per UTC day.",
|
|
32258
|
+
" csv — a single CSV file with every event merged under a shared header."
|
|
33258
32259
|
].join(`
|
|
33259
|
-
`)).
|
|
32260
|
+
`)).option("--output-path <dir>", "Base directory for the export (created if missing). Pass a directory only — do NOT include a filename or extension; the CLI generates the per-export name. A uniquely-named output is created inside it — a folder of day-wise JSON files ('json') or a single '.csv' file ('csv'), named audit_<from>_<to>_<generated-at> (to the second) so repeated exports don't collide.").option("--output-file <dir>", "Deprecated alias for --output-path (kept for backward compatibility). Despite the name it is treated as a base DIRECTORY, not a file path. Prefer --output-path.").requiredOption("--from-date <iso>", "Start of time interval (ISO 8601). Required.").requiredOption("--to-date <iso>", "End of time interval (ISO 8601). Required.").option("--file-format <format>", "Output format: 'json' (default — day-wise JSON files written into the --output-path folder) or 'csv' (a single merged CSV of every event).", "json").option("--login-validity <minutes>", "Override the interactive-login token lifetime for this call. Rarely needed.", (v) => Number.parseInt(v, 10));
|
|
33260
32261
|
if (scope === "tenant") {
|
|
33261
32262
|
cmd.option("--tenant-id <guid>", "Override the tenant ID from login context.");
|
|
33262
32263
|
}
|
|
33263
32264
|
cmd.examples(exportExamples(opts)).trackedAction(processContext, async (options) => {
|
|
33264
32265
|
const [error, summary] = await catchError2((async () => {
|
|
33265
32266
|
const format = parseFormat(options.fileFormat);
|
|
32267
|
+
const outputPath = options.outputPath ?? options.outputFile;
|
|
32268
|
+
if (outputPath === undefined) {
|
|
32269
|
+
throw new Error("Missing required option '--output-path <dir>'.");
|
|
32270
|
+
}
|
|
32271
|
+
if (options.outputFile !== undefined) {
|
|
32272
|
+
logger.warn(options.outputPath !== undefined ? "--output-file is deprecated and ignored when --output-path is also provided; using --output-path." : "--output-file is deprecated; use --output-path instead. It is treated as a base directory.");
|
|
32273
|
+
}
|
|
33266
32274
|
const api = await createApiClient(QueryApi, {
|
|
33267
32275
|
scope,
|
|
33268
32276
|
tenantId: options.tenantId,
|
|
@@ -33270,17 +32278,51 @@ function registerExport(parent, opts) {
|
|
|
33270
32278
|
});
|
|
33271
32279
|
const from = new Date(options.fromDate);
|
|
33272
32280
|
const to = new Date(options.toDate);
|
|
33273
|
-
const result = format === "csv" ? await downloadChunkedCsvExport(api, from, to) : await downloadChunkedExport(api, from, to);
|
|
33274
32281
|
const fs7 = getFileSystem();
|
|
33275
|
-
const
|
|
33276
|
-
|
|
32282
|
+
const generatedAt = new Date;
|
|
32283
|
+
const baseDir = fs7.path.resolve(outputPath);
|
|
32284
|
+
const baseName = exportBaseName(from, to, generatedAt);
|
|
32285
|
+
if (format === "csv") {
|
|
32286
|
+
const result2 = await downloadChunkedCsvExport(api, from, to);
|
|
32287
|
+
await fs7.mkdir(baseDir);
|
|
32288
|
+
const target = fs7.path.join(baseDir, `${baseName}.csv`);
|
|
32289
|
+
await fs7.writeFile(target, result2.buffer);
|
|
32290
|
+
return {
|
|
32291
|
+
Path: target,
|
|
32292
|
+
Format: "csv",
|
|
32293
|
+
Bytes: result2.buffer.byteLength,
|
|
32294
|
+
Days: result2.days,
|
|
32295
|
+
NonEmptyDays: result2.nonEmptyDays,
|
|
32296
|
+
Events: result2.eventCount,
|
|
32297
|
+
GeneratedAt: generatedAt.toISOString()
|
|
32298
|
+
};
|
|
32299
|
+
}
|
|
32300
|
+
const result = await downloadChunkedJsonExport(api, from, to);
|
|
32301
|
+
const outDir = fs7.path.join(baseDir, baseName);
|
|
32302
|
+
const targets = result.files.map((file) => {
|
|
32303
|
+
if (!isSafeExportEntryName(file.name)) {
|
|
32304
|
+
throw new Error(`Export contained a file with an unsafe name '${file.name}'.`);
|
|
32305
|
+
}
|
|
32306
|
+
const target = fs7.path.join(outDir, file.name);
|
|
32307
|
+
if (!isWithinDir(outDir, fs7.path.resolve(target))) {
|
|
32308
|
+
throw new Error(`Export file '${file.name}' resolves outside the output folder.`);
|
|
32309
|
+
}
|
|
32310
|
+
return { target, data: file.data };
|
|
32311
|
+
});
|
|
32312
|
+
await fs7.mkdir(outDir);
|
|
32313
|
+
let bytes = 0;
|
|
32314
|
+
for (const { target, data } of targets) {
|
|
32315
|
+
await fs7.writeFile(target, data);
|
|
32316
|
+
bytes += data.byteLength;
|
|
32317
|
+
}
|
|
33277
32318
|
return {
|
|
33278
|
-
Path:
|
|
33279
|
-
|
|
33280
|
-
|
|
32319
|
+
Path: outDir,
|
|
32320
|
+
Format: "json",
|
|
32321
|
+
Files: result.files.length,
|
|
32322
|
+
Bytes: bytes,
|
|
33281
32323
|
Days: result.days,
|
|
33282
32324
|
NonEmptyDays: result.nonEmptyDays,
|
|
33283
|
-
|
|
32325
|
+
GeneratedAt: generatedAt.toISOString()
|
|
33284
32326
|
};
|
|
33285
32327
|
})());
|
|
33286
32328
|
if (error) {
|
|
@@ -33315,7 +32357,7 @@ var registerAuditCommand = (program2) => {
|
|
|
33315
32357
|
" export — chunked download from the long-term store as a ZIP of day-wise files or a single merged CSV (requires --from-date / --to-date).",
|
|
33316
32358
|
"",
|
|
33317
32359
|
"Typical workflow: `audit <scope> sources` (discover IDs) → `audit <scope> events --source <guid>",
|
|
33318
|
-
"--from-date … --to-date …` (find the rows) → `audit <scope> export --from-date … --to-date … --output-
|
|
32360
|
+
"--from-date … --to-date …` (find the rows) → `audit <scope> export --from-date … --to-date … --output-path …`."
|
|
33319
32361
|
].join(`
|
|
33320
32362
|
`));
|
|
33321
32363
|
const org = audit.command("org").description("Organization-scoped audit operations.");
|
|
@@ -33340,3 +32382,5 @@ var program2 = new Command;
|
|
|
33340
32382
|
program2.name(metadata.commandPrefix).description(metadata.description).version(metadata.version);
|
|
33341
32383
|
await registerCommands(program2);
|
|
33342
32384
|
program2.parse(process.argv);
|
|
32385
|
+
|
|
32386
|
+
//# debugId=2DEF9849249B665C64756E2164756E21
|