@kevisual/cli 0.0.92 → 0.0.93
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/assistant-opencode.js +20144 -2308
- package/dist/assistant-server.js +38511 -17934
- package/dist/assistant.js +19215 -1608
- package/dist/envision.js +3061 -404
- package/package.json +8 -6
package/dist/envision.js
CHANGED
|
@@ -2290,37 +2290,37 @@ var require_core = __commonJS((exports, module) => {
|
|
|
2290
2290
|
}
|
|
2291
2291
|
})(exports, function() {
|
|
2292
2292
|
var CryptoJS = CryptoJS || function(Math2, undefined2) {
|
|
2293
|
-
var
|
|
2293
|
+
var crypto2;
|
|
2294
2294
|
if (typeof window !== "undefined" && window.crypto) {
|
|
2295
|
-
|
|
2295
|
+
crypto2 = window.crypto;
|
|
2296
2296
|
}
|
|
2297
2297
|
if (typeof self !== "undefined" && self.crypto) {
|
|
2298
|
-
|
|
2298
|
+
crypto2 = self.crypto;
|
|
2299
2299
|
}
|
|
2300
2300
|
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
2301
|
-
|
|
2301
|
+
crypto2 = globalThis.crypto;
|
|
2302
2302
|
}
|
|
2303
|
-
if (!
|
|
2304
|
-
|
|
2303
|
+
if (!crypto2 && typeof window !== "undefined" && window.msCrypto) {
|
|
2304
|
+
crypto2 = window.msCrypto;
|
|
2305
2305
|
}
|
|
2306
|
-
if (!
|
|
2307
|
-
|
|
2306
|
+
if (!crypto2 && typeof global !== "undefined" && global.crypto) {
|
|
2307
|
+
crypto2 = global.crypto;
|
|
2308
2308
|
}
|
|
2309
|
-
if (!
|
|
2309
|
+
if (!crypto2 && true) {
|
|
2310
2310
|
try {
|
|
2311
|
-
|
|
2311
|
+
crypto2 = __require("crypto");
|
|
2312
2312
|
} catch (err) {}
|
|
2313
2313
|
}
|
|
2314
2314
|
var cryptoSecureRandomInt = function() {
|
|
2315
|
-
if (
|
|
2316
|
-
if (typeof
|
|
2315
|
+
if (crypto2) {
|
|
2316
|
+
if (typeof crypto2.getRandomValues === "function") {
|
|
2317
2317
|
try {
|
|
2318
|
-
return
|
|
2318
|
+
return crypto2.getRandomValues(new Uint32Array(1))[0];
|
|
2319
2319
|
} catch (err) {}
|
|
2320
2320
|
}
|
|
2321
|
-
if (typeof
|
|
2321
|
+
if (typeof crypto2.randomBytes === "function") {
|
|
2322
2322
|
try {
|
|
2323
|
-
return
|
|
2323
|
+
return crypto2.randomBytes(4).readInt32LE();
|
|
2324
2324
|
} catch (err) {}
|
|
2325
2325
|
}
|
|
2326
2326
|
}
|
|
@@ -3035,7 +3035,7 @@ var require_buffer_equal_constant_time = __commonJS((exports, module) => {
|
|
|
3035
3035
|
// node_modules/.pnpm/jwa@2.0.1/node_modules/jwa/index.js
|
|
3036
3036
|
var require_jwa = __commonJS((exports, module) => {
|
|
3037
3037
|
var Buffer2 = require_safe_buffer().Buffer;
|
|
3038
|
-
var
|
|
3038
|
+
var crypto2 = __require("crypto");
|
|
3039
3039
|
var formatEcdsa = require_ecdsa_sig_formatter();
|
|
3040
3040
|
var util = __require("util");
|
|
3041
3041
|
var MSG_INVALID_ALGORITHM = `"%s" is not a valid algorithm.
|
|
@@ -3044,7 +3044,7 @@ var require_jwa = __commonJS((exports, module) => {
|
|
|
3044
3044
|
var MSG_INVALID_SECRET = "secret must be a string or buffer";
|
|
3045
3045
|
var MSG_INVALID_VERIFIER_KEY = "key must be a string or a buffer";
|
|
3046
3046
|
var MSG_INVALID_SIGNER_KEY = "key must be a string, a buffer or an object";
|
|
3047
|
-
var supportsKeyObjects = typeof
|
|
3047
|
+
var supportsKeyObjects = typeof crypto2.createPublicKey === "function";
|
|
3048
3048
|
if (supportsKeyObjects) {
|
|
3049
3049
|
MSG_INVALID_VERIFIER_KEY += " or a KeyObject";
|
|
3050
3050
|
MSG_INVALID_SECRET += "or a KeyObject";
|
|
@@ -3134,17 +3134,17 @@ var require_jwa = __commonJS((exports, module) => {
|
|
|
3134
3134
|
return function sign(thing, secret) {
|
|
3135
3135
|
checkIsSecretKey(secret);
|
|
3136
3136
|
thing = normalizeInput(thing);
|
|
3137
|
-
var hmac =
|
|
3137
|
+
var hmac = crypto2.createHmac("sha" + bits, secret);
|
|
3138
3138
|
var sig = (hmac.update(thing), hmac.digest("base64"));
|
|
3139
3139
|
return fromBase64(sig);
|
|
3140
3140
|
};
|
|
3141
3141
|
}
|
|
3142
3142
|
var bufferEqual;
|
|
3143
|
-
var timingSafeEqual = "timingSafeEqual" in
|
|
3143
|
+
var timingSafeEqual = "timingSafeEqual" in crypto2 ? function timingSafeEqual(a, b) {
|
|
3144
3144
|
if (a.byteLength !== b.byteLength) {
|
|
3145
3145
|
return false;
|
|
3146
3146
|
}
|
|
3147
|
-
return
|
|
3147
|
+
return crypto2.timingSafeEqual(a, b);
|
|
3148
3148
|
} : function timingSafeEqual(a, b) {
|
|
3149
3149
|
if (!bufferEqual) {
|
|
3150
3150
|
bufferEqual = require_buffer_equal_constant_time();
|
|
@@ -3161,7 +3161,7 @@ var require_jwa = __commonJS((exports, module) => {
|
|
|
3161
3161
|
return function sign(thing, privateKey) {
|
|
3162
3162
|
checkIsPrivateKey(privateKey);
|
|
3163
3163
|
thing = normalizeInput(thing);
|
|
3164
|
-
var signer =
|
|
3164
|
+
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
3165
3165
|
var sig = (signer.update(thing), signer.sign(privateKey, "base64"));
|
|
3166
3166
|
return fromBase64(sig);
|
|
3167
3167
|
};
|
|
@@ -3171,7 +3171,7 @@ var require_jwa = __commonJS((exports, module) => {
|
|
|
3171
3171
|
checkIsPublicKey(publicKey);
|
|
3172
3172
|
thing = normalizeInput(thing);
|
|
3173
3173
|
signature = toBase64(signature);
|
|
3174
|
-
var verifier =
|
|
3174
|
+
var verifier = crypto2.createVerify("RSA-SHA" + bits);
|
|
3175
3175
|
verifier.update(thing);
|
|
3176
3176
|
return verifier.verify(publicKey, signature, "base64");
|
|
3177
3177
|
};
|
|
@@ -3180,11 +3180,11 @@ var require_jwa = __commonJS((exports, module) => {
|
|
|
3180
3180
|
return function sign(thing, privateKey) {
|
|
3181
3181
|
checkIsPrivateKey(privateKey);
|
|
3182
3182
|
thing = normalizeInput(thing);
|
|
3183
|
-
var signer =
|
|
3183
|
+
var signer = crypto2.createSign("RSA-SHA" + bits);
|
|
3184
3184
|
var sig = (signer.update(thing), signer.sign({
|
|
3185
3185
|
key: privateKey,
|
|
3186
|
-
padding:
|
|
3187
|
-
saltLength:
|
|
3186
|
+
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
3187
|
+
saltLength: crypto2.constants.RSA_PSS_SALTLEN_DIGEST
|
|
3188
3188
|
}, "base64"));
|
|
3189
3189
|
return fromBase64(sig);
|
|
3190
3190
|
};
|
|
@@ -3194,12 +3194,12 @@ var require_jwa = __commonJS((exports, module) => {
|
|
|
3194
3194
|
checkIsPublicKey(publicKey);
|
|
3195
3195
|
thing = normalizeInput(thing);
|
|
3196
3196
|
signature = toBase64(signature);
|
|
3197
|
-
var verifier =
|
|
3197
|
+
var verifier = crypto2.createVerify("RSA-SHA" + bits);
|
|
3198
3198
|
verifier.update(thing);
|
|
3199
3199
|
return verifier.verify({
|
|
3200
3200
|
key: publicKey,
|
|
3201
|
-
padding:
|
|
3202
|
-
saltLength:
|
|
3201
|
+
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
3202
|
+
saltLength: crypto2.constants.RSA_PSS_SALTLEN_DIGEST
|
|
3203
3203
|
}, signature, "base64");
|
|
3204
3204
|
};
|
|
3205
3205
|
}
|
|
@@ -21448,7 +21448,7 @@ var require_form_data = __commonJS((exports, module) => {
|
|
|
21448
21448
|
var parseUrl = __require("url").parse;
|
|
21449
21449
|
var fs5 = __require("fs");
|
|
21450
21450
|
var Stream = __require("stream").Stream;
|
|
21451
|
-
var
|
|
21451
|
+
var crypto2 = __require("crypto");
|
|
21452
21452
|
var mime = require_mime_types();
|
|
21453
21453
|
var asynckit = require_asynckit();
|
|
21454
21454
|
var setToStringTag = require_es_set_tostringtag();
|
|
@@ -21653,7 +21653,7 @@ var require_form_data = __commonJS((exports, module) => {
|
|
|
21653
21653
|
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
|
21654
21654
|
};
|
|
21655
21655
|
FormData.prototype._generateBoundary = function() {
|
|
21656
|
-
this._boundary = "--------------------------" +
|
|
21656
|
+
this._boundary = "--------------------------" + crypto2.randomBytes(12).toString("hex");
|
|
21657
21657
|
};
|
|
21658
21658
|
FormData.prototype.getLengthSync = function() {
|
|
21659
21659
|
var knownLength = this._overheadLength + this._valueLength;
|
|
@@ -22327,8 +22327,8 @@ InitEnv.init();
|
|
|
22327
22327
|
var version = useContextKey("version", () => {
|
|
22328
22328
|
let version2 = "0.0.64";
|
|
22329
22329
|
try {
|
|
22330
|
-
if ("0.0.
|
|
22331
|
-
version2 = "0.0.
|
|
22330
|
+
if ("0.0.93")
|
|
22331
|
+
version2 = "0.0.93";
|
|
22332
22332
|
} catch (e) {}
|
|
22333
22333
|
return version2;
|
|
22334
22334
|
});
|
|
@@ -22434,7 +22434,7 @@ var require_main = __commonJS2((exports, module) => {
|
|
|
22434
22434
|
var fs3 = __require2("fs");
|
|
22435
22435
|
var path2 = __require2("path");
|
|
22436
22436
|
var os = __require2("os");
|
|
22437
|
-
var
|
|
22437
|
+
var crypto2 = __require2("crypto");
|
|
22438
22438
|
var packageJson = require_package();
|
|
22439
22439
|
var version2 = packageJson.version;
|
|
22440
22440
|
var TIPS = [
|
|
@@ -22690,7 +22690,7 @@ var require_main = __commonJS2((exports, module) => {
|
|
|
22690
22690
|
const authTag = ciphertext.subarray(-16);
|
|
22691
22691
|
ciphertext = ciphertext.subarray(12, -16);
|
|
22692
22692
|
try {
|
|
22693
|
-
const aesgcm =
|
|
22693
|
+
const aesgcm = crypto2.createDecipheriv("aes-256-gcm", key, nonce);
|
|
22694
22694
|
aesgcm.setAuthTag(authTag);
|
|
22695
22695
|
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
22696
22696
|
} catch (error) {
|
|
@@ -23445,14 +23445,14 @@ var getEnvToken = () => {
|
|
|
23445
23445
|
return envTokne;
|
|
23446
23446
|
};
|
|
23447
23447
|
|
|
23448
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23448
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/key.js
|
|
23449
23449
|
var isUpKey = (key, keybindings = []) => key.name === "up" || keybindings.includes("vim") && key.name === "k" || keybindings.includes("emacs") && key.ctrl && key.name === "p";
|
|
23450
23450
|
var isDownKey = (key, keybindings = []) => key.name === "down" || keybindings.includes("vim") && key.name === "j" || keybindings.includes("emacs") && key.ctrl && key.name === "n";
|
|
23451
23451
|
var isBackspaceKey = (key) => key.name === "backspace";
|
|
23452
23452
|
var isTabKey = (key) => key.name === "tab";
|
|
23453
23453
|
var isNumberKey = (key) => "1234567890".includes(key.name);
|
|
23454
23454
|
var isEnterKey = (key) => key.name === "enter" || key.name === "return";
|
|
23455
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23455
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/errors.js
|
|
23456
23456
|
class AbortPromptError extends Error {
|
|
23457
23457
|
name = "AbortPromptError";
|
|
23458
23458
|
message = "Prompt was aborted";
|
|
@@ -23478,10 +23478,10 @@ class HookError extends Error {
|
|
|
23478
23478
|
class ValidationError extends Error {
|
|
23479
23479
|
name = "ValidationError";
|
|
23480
23480
|
}
|
|
23481
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23481
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-state.js
|
|
23482
23482
|
import { AsyncResource as AsyncResource2 } from "node:async_hooks";
|
|
23483
23483
|
|
|
23484
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23484
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/hook-engine.js
|
|
23485
23485
|
import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
|
|
23486
23486
|
var hookStorage = new AsyncLocalStorage;
|
|
23487
23487
|
function createStore(rl) {
|
|
@@ -23586,7 +23586,7 @@ var effectScheduler = {
|
|
|
23586
23586
|
}
|
|
23587
23587
|
};
|
|
23588
23588
|
|
|
23589
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23589
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-state.js
|
|
23590
23590
|
function useState(defaultValue) {
|
|
23591
23591
|
return withPointer((pointer) => {
|
|
23592
23592
|
const setState = AsyncResource2.bind(function setState(newValue) {
|
|
@@ -23604,7 +23604,7 @@ function useState(defaultValue) {
|
|
|
23604
23604
|
});
|
|
23605
23605
|
}
|
|
23606
23606
|
|
|
23607
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23607
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-effect.js
|
|
23608
23608
|
function useEffect(cb, depArray) {
|
|
23609
23609
|
withPointer((pointer) => {
|
|
23610
23610
|
const oldDeps = pointer.get();
|
|
@@ -23616,7 +23616,7 @@ function useEffect(cb, depArray) {
|
|
|
23616
23616
|
});
|
|
23617
23617
|
}
|
|
23618
23618
|
|
|
23619
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23619
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/theme.js
|
|
23620
23620
|
import { styleText } from "node:util";
|
|
23621
23621
|
|
|
23622
23622
|
// node_modules/.pnpm/@inquirer+figures@2.0.3/node_modules/@inquirer/figures/dist/index.js
|
|
@@ -23908,7 +23908,7 @@ var figures = shouldUseMain ? mainSymbols : fallbackSymbols;
|
|
|
23908
23908
|
var dist_default = figures;
|
|
23909
23909
|
var replacements = Object.entries(specialMainSymbols);
|
|
23910
23910
|
|
|
23911
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23911
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/theme.js
|
|
23912
23912
|
var defaultTheme = {
|
|
23913
23913
|
prefix: {
|
|
23914
23914
|
idle: styleText("blue", "?"),
|
|
@@ -23929,7 +23929,7 @@ var defaultTheme = {
|
|
|
23929
23929
|
}
|
|
23930
23930
|
};
|
|
23931
23931
|
|
|
23932
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23932
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/make-theme.js
|
|
23933
23933
|
function isPlainObject(value) {
|
|
23934
23934
|
if (typeof value !== "object" || value === null)
|
|
23935
23935
|
return false;
|
|
@@ -23957,7 +23957,7 @@ function makeTheme(...themes) {
|
|
|
23957
23957
|
return deepMerge(...themesToMerge);
|
|
23958
23958
|
}
|
|
23959
23959
|
|
|
23960
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23960
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-prefix.js
|
|
23961
23961
|
function usePrefix({ status = "idle", theme }) {
|
|
23962
23962
|
const [showLoader, setShowLoader] = useState(false);
|
|
23963
23963
|
const [tick, setTick] = useState(0);
|
|
@@ -23987,7 +23987,7 @@ function usePrefix({ status = "idle", theme }) {
|
|
|
23987
23987
|
const iconName = status === "loading" ? "idle" : status;
|
|
23988
23988
|
return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix["idle"];
|
|
23989
23989
|
}
|
|
23990
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
23990
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-memo.js
|
|
23991
23991
|
function useMemo(fn, dependencies) {
|
|
23992
23992
|
return withPointer((pointer) => {
|
|
23993
23993
|
const prev = pointer.get();
|
|
@@ -23999,11 +23999,11 @@ function useMemo(fn, dependencies) {
|
|
|
23999
23999
|
return prev.value;
|
|
24000
24000
|
});
|
|
24001
24001
|
}
|
|
24002
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24002
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-ref.js
|
|
24003
24003
|
function useRef(val) {
|
|
24004
24004
|
return useState({ current: val })[0];
|
|
24005
24005
|
}
|
|
24006
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24006
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/use-keypress.js
|
|
24007
24007
|
function useKeypress(userHandler) {
|
|
24008
24008
|
const signal = useRef(userHandler);
|
|
24009
24009
|
signal.current = userHandler;
|
|
@@ -24021,7 +24021,7 @@ function useKeypress(userHandler) {
|
|
|
24021
24021
|
};
|
|
24022
24022
|
}, []);
|
|
24023
24023
|
}
|
|
24024
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24024
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/utils.js
|
|
24025
24025
|
var import_cli_width = __toESM(require_cli_width(), 1);
|
|
24026
24026
|
|
|
24027
24027
|
// node_modules/.pnpm/ansi-regex@6.2.2/node_modules/ansi-regex/index.js
|
|
@@ -24455,7 +24455,7 @@ function wrapAnsi(string, columns, options) {
|
|
|
24455
24455
|
`);
|
|
24456
24456
|
}
|
|
24457
24457
|
|
|
24458
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24458
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/utils.js
|
|
24459
24459
|
function breakLines(content, width) {
|
|
24460
24460
|
return content.split(`
|
|
24461
24461
|
`).flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true }).split(`
|
|
@@ -24466,7 +24466,7 @@ function readlineWidth() {
|
|
|
24466
24466
|
return import_cli_width.default({ defaultWidth: 80, output: readline().output });
|
|
24467
24467
|
}
|
|
24468
24468
|
|
|
24469
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24469
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/pagination/use-pagination.js
|
|
24470
24470
|
function usePointerPosition({ active, renderedItems, pageSize, loop }) {
|
|
24471
24471
|
const state = useRef({
|
|
24472
24472
|
lastPointer: active,
|
|
@@ -24532,7 +24532,7 @@ function usePagination({ items, active, renderItem, pageSize, loop = true }) {
|
|
|
24532
24532
|
return pageBuffer.filter((line) => typeof line === "string").join(`
|
|
24533
24533
|
`);
|
|
24534
24534
|
}
|
|
24535
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24535
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/create-prompt.js
|
|
24536
24536
|
var import_mute_stream = __toESM(require_lib(), 1);
|
|
24537
24537
|
import * as readline2 from "node:readline";
|
|
24538
24538
|
import { AsyncResource as AsyncResource3 } from "node:async_hooks";
|
|
@@ -24745,7 +24745,7 @@ var {
|
|
|
24745
24745
|
unload
|
|
24746
24746
|
} = signalExitWrap(processOk(process3) ? new SignalExit(process3) : new SignalExitFallback);
|
|
24747
24747
|
|
|
24748
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24748
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/screen-manager.js
|
|
24749
24749
|
import { stripVTControlCharacters } from "node:util";
|
|
24750
24750
|
|
|
24751
24751
|
// node_modules/.pnpm/@inquirer+ansi@2.0.3/node_modules/@inquirer/ansi/dist/index.js
|
|
@@ -24764,7 +24764,7 @@ var cursorTo = (x, y) => {
|
|
|
24764
24764
|
var eraseLine = ESC + "2K";
|
|
24765
24765
|
var eraseLines = (lines) => lines > 0 ? (eraseLine + cursorUp(1)).repeat(lines - 1) + eraseLine + cursorLeft : "";
|
|
24766
24766
|
|
|
24767
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24767
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/screen-manager.js
|
|
24768
24768
|
var height = (content) => content.split(`
|
|
24769
24769
|
`).length;
|
|
24770
24770
|
var lastLine = (content) => content.split(`
|
|
@@ -24829,7 +24829,7 @@ class ScreenManager {
|
|
|
24829
24829
|
}
|
|
24830
24830
|
}
|
|
24831
24831
|
|
|
24832
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24832
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/promise-polyfill.js
|
|
24833
24833
|
class PromisePolyfill extends Promise {
|
|
24834
24834
|
static withResolver() {
|
|
24835
24835
|
let resolve;
|
|
@@ -24842,7 +24842,7 @@ class PromisePolyfill extends Promise {
|
|
|
24842
24842
|
}
|
|
24843
24843
|
}
|
|
24844
24844
|
|
|
24845
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24845
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/create-prompt.js
|
|
24846
24846
|
function getCallSites() {
|
|
24847
24847
|
const _prepareStackTrace = Error.prepareStackTrace;
|
|
24848
24848
|
let result = [];
|
|
@@ -24928,7 +24928,7 @@ function createPrompt(view) {
|
|
|
24928
24928
|
};
|
|
24929
24929
|
return prompt;
|
|
24930
24930
|
}
|
|
24931
|
-
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.
|
|
24931
|
+
// node_modules/.pnpm/@inquirer+core@11.1.1_@types+node@25.0.10/node_modules/@inquirer/core/dist/lib/Separator.js
|
|
24932
24932
|
import { styleText as styleText2 } from "node:util";
|
|
24933
24933
|
class Separator {
|
|
24934
24934
|
separator = styleText2("dim", Array.from({ length: 15 }).join(dist_default.line));
|
|
@@ -24942,7 +24942,7 @@ class Separator {
|
|
|
24942
24942
|
return Boolean(choice && typeof choice === "object" && "type" in choice && choice.type === "separator");
|
|
24943
24943
|
}
|
|
24944
24944
|
}
|
|
24945
|
-
// node_modules/.pnpm/@inquirer+confirm@6.0.4_@types+node@25.0.
|
|
24945
|
+
// node_modules/.pnpm/@inquirer+confirm@6.0.4_@types+node@25.0.10/node_modules/@inquirer/confirm/dist/index.js
|
|
24946
24946
|
function getBooleanValue(value, defaultValue) {
|
|
24947
24947
|
let answer = defaultValue !== false;
|
|
24948
24948
|
if (/^(y|yes)/i.test(value))
|
|
@@ -24987,7 +24987,7 @@ var dist_default2 = createPrompt((config, done) => {
|
|
|
24987
24987
|
const message = theme.style.message(config.message, status);
|
|
24988
24988
|
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
|
24989
24989
|
});
|
|
24990
|
-
// node_modules/.pnpm/@inquirer+input@5.0.4_@types+node@25.0.
|
|
24990
|
+
// node_modules/.pnpm/@inquirer+input@5.0.4_@types+node@25.0.10/node_modules/@inquirer/input/dist/index.js
|
|
24991
24991
|
var inputTheme = {
|
|
24992
24992
|
validationFailureMode: "keep"
|
|
24993
24993
|
};
|
|
@@ -25071,7 +25071,7 @@ var dist_default3 = createPrompt((config, done) => {
|
|
|
25071
25071
|
error
|
|
25072
25072
|
];
|
|
25073
25073
|
});
|
|
25074
|
-
// node_modules/.pnpm/@inquirer+select@5.0.4_@types+node@25.0.
|
|
25074
|
+
// node_modules/.pnpm/@inquirer+select@5.0.4_@types+node@25.0.10/node_modules/@inquirer/select/dist/index.js
|
|
25075
25075
|
import { styleText as styleText3 } from "node:util";
|
|
25076
25076
|
var selectTheme = {
|
|
25077
25077
|
icon: { cursor: dist_default.pointer },
|
|
@@ -25231,7 +25231,7 @@ var dist_default4 = createPrompt((config, done) => {
|
|
|
25231
25231
|
var import_md5 = __toESM(require_md5(), 1);
|
|
25232
25232
|
var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
|
|
25233
25233
|
|
|
25234
|
-
// node_modules/.pnpm/@kevisual+query@0.0.
|
|
25234
|
+
// node_modules/.pnpm/@kevisual+query@0.0.38/node_modules/@kevisual/query/dist/query.js
|
|
25235
25235
|
var isTextForContentType = (contentType) => {
|
|
25236
25236
|
if (!contentType)
|
|
25237
25237
|
return false;
|
|
@@ -25318,11 +25318,14 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
25318
25318
|
}
|
|
25319
25319
|
}).catch((err) => {
|
|
25320
25320
|
if (err.name === "AbortError") {
|
|
25321
|
-
|
|
25321
|
+
return {
|
|
25322
|
+
code: 408,
|
|
25323
|
+
message: "请求超时"
|
|
25324
|
+
};
|
|
25322
25325
|
}
|
|
25323
|
-
console.error(err);
|
|
25324
25326
|
return {
|
|
25325
|
-
code: 500
|
|
25327
|
+
code: 500,
|
|
25328
|
+
message: err.message || "网络错误"
|
|
25326
25329
|
};
|
|
25327
25330
|
}).finally(() => {
|
|
25328
25331
|
clearTimeout(timer);
|
|
@@ -25490,7 +25493,7 @@ class Query {
|
|
|
25490
25493
|
}
|
|
25491
25494
|
}
|
|
25492
25495
|
|
|
25493
|
-
// node_modules/.pnpm/@kevisual+query@0.0.
|
|
25496
|
+
// node_modules/.pnpm/@kevisual+query@0.0.38/node_modules/@kevisual/query/dist/query-browser.js
|
|
25494
25497
|
var isTextForContentType2 = (contentType) => {
|
|
25495
25498
|
if (!contentType)
|
|
25496
25499
|
return false;
|
|
@@ -25577,11 +25580,14 @@ var adapter2 = async (opts = {}, overloadOpts) => {
|
|
|
25577
25580
|
}
|
|
25578
25581
|
}).catch((err) => {
|
|
25579
25582
|
if (err.name === "AbortError") {
|
|
25580
|
-
|
|
25583
|
+
return {
|
|
25584
|
+
code: 408,
|
|
25585
|
+
message: "请求超时"
|
|
25586
|
+
};
|
|
25581
25587
|
}
|
|
25582
|
-
console.error(err);
|
|
25583
25588
|
return {
|
|
25584
|
-
code: 500
|
|
25589
|
+
code: 500,
|
|
25590
|
+
message: err.message || "网络错误"
|
|
25585
25591
|
};
|
|
25586
25592
|
}).finally(() => {
|
|
25587
25593
|
clearTimeout(timer);
|
|
@@ -25765,7 +25771,7 @@ class BaseQuery {
|
|
|
25765
25771
|
}
|
|
25766
25772
|
}
|
|
25767
25773
|
|
|
25768
|
-
// node_modules/.pnpm/@kevisual+query-login@0.0.7_@kevisual+query@0.0.
|
|
25774
|
+
// node_modules/.pnpm/@kevisual+query-login@0.0.7_@kevisual+query@0.0.38/node_modules/@kevisual/query-login/dist/query-login-node.js
|
|
25769
25775
|
import { homedir } from "os";
|
|
25770
25776
|
import { join, dirname } from "path";
|
|
25771
25777
|
import fs4 from "fs";
|
|
@@ -27626,16 +27632,16 @@ import path3 from "path";
|
|
|
27626
27632
|
import fs6 from "fs";
|
|
27627
27633
|
|
|
27628
27634
|
// src/uitls/hash.ts
|
|
27629
|
-
import
|
|
27635
|
+
import crypto2 from "node:crypto";
|
|
27630
27636
|
import fs5 from "node:fs";
|
|
27631
27637
|
var getHash = (file) => {
|
|
27632
27638
|
if (!fs5.existsSync(file))
|
|
27633
27639
|
return "";
|
|
27634
27640
|
const buffer = fs5.readFileSync(file);
|
|
27635
|
-
return
|
|
27641
|
+
return crypto2.createHash("md5").update(buffer).digest("hex");
|
|
27636
27642
|
};
|
|
27637
27643
|
var getBufferHash = (buffer) => {
|
|
27638
|
-
return
|
|
27644
|
+
return crypto2.createHash("md5").update(buffer).digest("hex");
|
|
27639
27645
|
};
|
|
27640
27646
|
|
|
27641
27647
|
// src/module/download/upload.ts
|
|
@@ -28532,8 +28538,9 @@ var uploadFiles = async (files, directory, opts) => {
|
|
|
28532
28538
|
}
|
|
28533
28539
|
const filename = path3.basename(filePath);
|
|
28534
28540
|
logger.debug("upload file", file, filename);
|
|
28541
|
+
const encodedFilename = Buffer.from(filename, "utf-8").toString("binary");
|
|
28535
28542
|
form.append("file", fs6.createReadStream(filePath), {
|
|
28536
|
-
filename,
|
|
28543
|
+
filename: encodedFilename,
|
|
28537
28544
|
filepath: file
|
|
28538
28545
|
});
|
|
28539
28546
|
needUpload = true;
|
|
@@ -29251,14 +29258,9 @@ var packCommand = new Command("pack").description("打包应用, 使用 package.
|
|
|
29251
29258
|
let appKey;
|
|
29252
29259
|
let version2 = packageInfo.version || "";
|
|
29253
29260
|
if (!version2) {
|
|
29254
|
-
|
|
29255
|
-
|
|
29256
|
-
|
|
29257
|
-
name: "version",
|
|
29258
|
-
message: "Enter your version:"
|
|
29259
|
-
}
|
|
29260
|
-
]);
|
|
29261
|
-
version2 = answers.version || version2;
|
|
29261
|
+
version2 = await dist_default3({
|
|
29262
|
+
message: "Enter your version:"
|
|
29263
|
+
});
|
|
29262
29264
|
}
|
|
29263
29265
|
if (basename) {
|
|
29264
29266
|
if (basename.startsWith("/")) {
|
|
@@ -29272,14 +29274,9 @@ var packCommand = new Command("pack").description("打包应用, 使用 package.
|
|
|
29272
29274
|
appKey = basenameArr[1] || "";
|
|
29273
29275
|
}
|
|
29274
29276
|
if (!appKey) {
|
|
29275
|
-
|
|
29276
|
-
|
|
29277
|
-
|
|
29278
|
-
name: "appKey",
|
|
29279
|
-
message: "Enter your appKey:"
|
|
29280
|
-
}
|
|
29281
|
-
]);
|
|
29282
|
-
appKey = answers.appKey || appKey;
|
|
29277
|
+
appKey = await dist_default3({
|
|
29278
|
+
message: "Enter your appKey:"
|
|
29279
|
+
});
|
|
29283
29280
|
}
|
|
29284
29281
|
let value = await pack({
|
|
29285
29282
|
packDist,
|
|
@@ -30648,7 +30645,7 @@ command10.addCommand(deleteCommand2);
|
|
|
30648
30645
|
program.addCommand(command10);
|
|
30649
30646
|
|
|
30650
30647
|
// node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/index.js
|
|
30651
|
-
import { webcrypto as
|
|
30648
|
+
import { webcrypto as crypto3 } from "node:crypto";
|
|
30652
30649
|
|
|
30653
30650
|
// node_modules/.pnpm/nanoid@5.1.6/node_modules/nanoid/url-alphabet/index.js
|
|
30654
30651
|
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
@@ -30660,10 +30657,10 @@ var poolOffset;
|
|
|
30660
30657
|
function fillPool(bytes) {
|
|
30661
30658
|
if (!pool || pool.length < bytes) {
|
|
30662
30659
|
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
30663
|
-
|
|
30660
|
+
crypto3.getRandomValues(pool);
|
|
30664
30661
|
poolOffset = 0;
|
|
30665
30662
|
} else if (poolOffset + bytes > pool.length) {
|
|
30666
|
-
|
|
30663
|
+
crypto3.getRandomValues(pool);
|
|
30667
30664
|
poolOffset = 0;
|
|
30668
30665
|
}
|
|
30669
30666
|
poolOffset += bytes;
|
|
@@ -31511,37 +31508,37 @@ var require_core2 = __commonJS3((exports, module) => {
|
|
|
31511
31508
|
}
|
|
31512
31509
|
})(exports, function() {
|
|
31513
31510
|
var CryptoJS = CryptoJS || function(Math2, undefined2) {
|
|
31514
|
-
var
|
|
31511
|
+
var crypto4;
|
|
31515
31512
|
if (typeof window !== "undefined" && window.crypto) {
|
|
31516
|
-
|
|
31513
|
+
crypto4 = window.crypto;
|
|
31517
31514
|
}
|
|
31518
31515
|
if (typeof self !== "undefined" && self.crypto) {
|
|
31519
|
-
|
|
31516
|
+
crypto4 = self.crypto;
|
|
31520
31517
|
}
|
|
31521
31518
|
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
31522
|
-
|
|
31519
|
+
crypto4 = globalThis.crypto;
|
|
31523
31520
|
}
|
|
31524
|
-
if (!
|
|
31525
|
-
|
|
31521
|
+
if (!crypto4 && typeof window !== "undefined" && window.msCrypto) {
|
|
31522
|
+
crypto4 = window.msCrypto;
|
|
31526
31523
|
}
|
|
31527
|
-
if (!
|
|
31528
|
-
|
|
31524
|
+
if (!crypto4 && typeof global !== "undefined" && global.crypto) {
|
|
31525
|
+
crypto4 = global.crypto;
|
|
31529
31526
|
}
|
|
31530
|
-
if (!
|
|
31527
|
+
if (!crypto4 && true) {
|
|
31531
31528
|
try {
|
|
31532
|
-
|
|
31529
|
+
crypto4 = __require3("crypto");
|
|
31533
31530
|
} catch (err) {}
|
|
31534
31531
|
}
|
|
31535
31532
|
var cryptoSecureRandomInt = function() {
|
|
31536
|
-
if (
|
|
31537
|
-
if (typeof
|
|
31533
|
+
if (crypto4) {
|
|
31534
|
+
if (typeof crypto4.getRandomValues === "function") {
|
|
31538
31535
|
try {
|
|
31539
|
-
return
|
|
31536
|
+
return crypto4.getRandomValues(new Uint32Array(1))[0];
|
|
31540
31537
|
} catch (err) {}
|
|
31541
31538
|
}
|
|
31542
|
-
if (typeof
|
|
31539
|
+
if (typeof crypto4.randomBytes === "function") {
|
|
31543
31540
|
try {
|
|
31544
|
-
return
|
|
31541
|
+
return crypto4.randomBytes(4).readInt32LE();
|
|
31545
31542
|
} catch (err) {}
|
|
31546
31543
|
}
|
|
31547
31544
|
}
|
|
@@ -34068,7 +34065,2917 @@ class LRUCache {
|
|
|
34068
34065
|
if (this.#isBackgroundFetch(v)) {
|
|
34069
34066
|
return v;
|
|
34070
34067
|
}
|
|
34071
|
-
const ac = new AC;
|
|
34068
|
+
const ac = new AC;
|
|
34069
|
+
const { signal } = options;
|
|
34070
|
+
signal?.addEventListener("abort", () => ac.abort(signal.reason), {
|
|
34071
|
+
signal: ac.signal
|
|
34072
|
+
});
|
|
34073
|
+
const fetchOpts = {
|
|
34074
|
+
signal: ac.signal,
|
|
34075
|
+
options,
|
|
34076
|
+
context
|
|
34077
|
+
};
|
|
34078
|
+
const cb = (v2, updateCache = false) => {
|
|
34079
|
+
const { aborted } = ac.signal;
|
|
34080
|
+
const ignoreAbort = options.ignoreFetchAbort && v2 !== undefined;
|
|
34081
|
+
if (options.status) {
|
|
34082
|
+
if (aborted && !updateCache) {
|
|
34083
|
+
options.status.fetchAborted = true;
|
|
34084
|
+
options.status.fetchError = ac.signal.reason;
|
|
34085
|
+
if (ignoreAbort)
|
|
34086
|
+
options.status.fetchAbortIgnored = true;
|
|
34087
|
+
} else {
|
|
34088
|
+
options.status.fetchResolved = true;
|
|
34089
|
+
}
|
|
34090
|
+
}
|
|
34091
|
+
if (aborted && !ignoreAbort && !updateCache) {
|
|
34092
|
+
return fetchFail(ac.signal.reason);
|
|
34093
|
+
}
|
|
34094
|
+
const bf2 = p;
|
|
34095
|
+
const vl = this.#valList[index];
|
|
34096
|
+
if (vl === p || ignoreAbort && updateCache && vl === undefined) {
|
|
34097
|
+
if (v2 === undefined) {
|
|
34098
|
+
if (bf2.__staleWhileFetching !== undefined) {
|
|
34099
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
34100
|
+
} else {
|
|
34101
|
+
this.#delete(k, "fetch");
|
|
34102
|
+
}
|
|
34103
|
+
} else {
|
|
34104
|
+
if (options.status)
|
|
34105
|
+
options.status.fetchUpdated = true;
|
|
34106
|
+
this.set(k, v2, fetchOpts.options);
|
|
34107
|
+
}
|
|
34108
|
+
}
|
|
34109
|
+
return v2;
|
|
34110
|
+
};
|
|
34111
|
+
const eb = (er) => {
|
|
34112
|
+
if (options.status) {
|
|
34113
|
+
options.status.fetchRejected = true;
|
|
34114
|
+
options.status.fetchError = er;
|
|
34115
|
+
}
|
|
34116
|
+
return fetchFail(er);
|
|
34117
|
+
};
|
|
34118
|
+
const fetchFail = (er) => {
|
|
34119
|
+
const { aborted } = ac.signal;
|
|
34120
|
+
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
|
34121
|
+
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
34122
|
+
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
34123
|
+
const bf2 = p;
|
|
34124
|
+
if (this.#valList[index] === p) {
|
|
34125
|
+
const del = !noDelete || bf2.__staleWhileFetching === undefined;
|
|
34126
|
+
if (del) {
|
|
34127
|
+
this.#delete(k, "fetch");
|
|
34128
|
+
} else if (!allowStaleAborted) {
|
|
34129
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
34130
|
+
}
|
|
34131
|
+
}
|
|
34132
|
+
if (allowStale) {
|
|
34133
|
+
if (options.status && bf2.__staleWhileFetching !== undefined) {
|
|
34134
|
+
options.status.returnedStale = true;
|
|
34135
|
+
}
|
|
34136
|
+
return bf2.__staleWhileFetching;
|
|
34137
|
+
} else if (bf2.__returned === bf2) {
|
|
34138
|
+
throw er;
|
|
34139
|
+
}
|
|
34140
|
+
};
|
|
34141
|
+
const pcall = (res, rej) => {
|
|
34142
|
+
const fmp = this.#fetchMethod?.(k, v, fetchOpts);
|
|
34143
|
+
if (fmp && fmp instanceof Promise) {
|
|
34144
|
+
fmp.then((v2) => res(v2 === undefined ? undefined : v2), rej);
|
|
34145
|
+
}
|
|
34146
|
+
ac.signal.addEventListener("abort", () => {
|
|
34147
|
+
if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
|
|
34148
|
+
res(undefined);
|
|
34149
|
+
if (options.allowStaleOnFetchAbort) {
|
|
34150
|
+
res = (v2) => cb(v2, true);
|
|
34151
|
+
}
|
|
34152
|
+
}
|
|
34153
|
+
});
|
|
34154
|
+
};
|
|
34155
|
+
if (options.status)
|
|
34156
|
+
options.status.fetchDispatched = true;
|
|
34157
|
+
const p = new Promise(pcall).then(cb, eb);
|
|
34158
|
+
const bf = Object.assign(p, {
|
|
34159
|
+
__abortController: ac,
|
|
34160
|
+
__staleWhileFetching: v,
|
|
34161
|
+
__returned: undefined
|
|
34162
|
+
});
|
|
34163
|
+
if (index === undefined) {
|
|
34164
|
+
this.set(k, bf, { ...fetchOpts.options, status: undefined });
|
|
34165
|
+
index = this.#keyMap.get(k);
|
|
34166
|
+
} else {
|
|
34167
|
+
this.#valList[index] = bf;
|
|
34168
|
+
}
|
|
34169
|
+
return bf;
|
|
34170
|
+
}
|
|
34171
|
+
#isBackgroundFetch(p) {
|
|
34172
|
+
if (!this.#hasFetchMethod)
|
|
34173
|
+
return false;
|
|
34174
|
+
const b = p;
|
|
34175
|
+
return !!b && b instanceof Promise && b.hasOwnProperty("__staleWhileFetching") && b.__abortController instanceof AC;
|
|
34176
|
+
}
|
|
34177
|
+
async fetch(k, fetchOptions = {}) {
|
|
34178
|
+
const {
|
|
34179
|
+
allowStale = this.allowStale,
|
|
34180
|
+
updateAgeOnGet = this.updateAgeOnGet,
|
|
34181
|
+
noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
34182
|
+
ttl = this.ttl,
|
|
34183
|
+
noDisposeOnSet = this.noDisposeOnSet,
|
|
34184
|
+
size = 0,
|
|
34185
|
+
sizeCalculation = this.sizeCalculation,
|
|
34186
|
+
noUpdateTTL = this.noUpdateTTL,
|
|
34187
|
+
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
|
|
34188
|
+
allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
|
|
34189
|
+
ignoreFetchAbort = this.ignoreFetchAbort,
|
|
34190
|
+
allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
|
|
34191
|
+
context,
|
|
34192
|
+
forceRefresh = false,
|
|
34193
|
+
status,
|
|
34194
|
+
signal
|
|
34195
|
+
} = fetchOptions;
|
|
34196
|
+
if (!this.#hasFetchMethod) {
|
|
34197
|
+
if (status)
|
|
34198
|
+
status.fetch = "get";
|
|
34199
|
+
return this.get(k, {
|
|
34200
|
+
allowStale,
|
|
34201
|
+
updateAgeOnGet,
|
|
34202
|
+
noDeleteOnStaleGet,
|
|
34203
|
+
status
|
|
34204
|
+
});
|
|
34205
|
+
}
|
|
34206
|
+
const options = {
|
|
34207
|
+
allowStale,
|
|
34208
|
+
updateAgeOnGet,
|
|
34209
|
+
noDeleteOnStaleGet,
|
|
34210
|
+
ttl,
|
|
34211
|
+
noDisposeOnSet,
|
|
34212
|
+
size,
|
|
34213
|
+
sizeCalculation,
|
|
34214
|
+
noUpdateTTL,
|
|
34215
|
+
noDeleteOnFetchRejection,
|
|
34216
|
+
allowStaleOnFetchRejection,
|
|
34217
|
+
allowStaleOnFetchAbort,
|
|
34218
|
+
ignoreFetchAbort,
|
|
34219
|
+
status,
|
|
34220
|
+
signal
|
|
34221
|
+
};
|
|
34222
|
+
let index = this.#keyMap.get(k);
|
|
34223
|
+
if (index === undefined) {
|
|
34224
|
+
if (status)
|
|
34225
|
+
status.fetch = "miss";
|
|
34226
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
34227
|
+
return p.__returned = p;
|
|
34228
|
+
} else {
|
|
34229
|
+
const v = this.#valList[index];
|
|
34230
|
+
if (this.#isBackgroundFetch(v)) {
|
|
34231
|
+
const stale = allowStale && v.__staleWhileFetching !== undefined;
|
|
34232
|
+
if (status) {
|
|
34233
|
+
status.fetch = "inflight";
|
|
34234
|
+
if (stale)
|
|
34235
|
+
status.returnedStale = true;
|
|
34236
|
+
}
|
|
34237
|
+
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
34238
|
+
}
|
|
34239
|
+
const isStale = this.#isStale(index);
|
|
34240
|
+
if (!forceRefresh && !isStale) {
|
|
34241
|
+
if (status)
|
|
34242
|
+
status.fetch = "hit";
|
|
34243
|
+
this.#moveToTail(index);
|
|
34244
|
+
if (updateAgeOnGet) {
|
|
34245
|
+
this.#updateItemAge(index);
|
|
34246
|
+
}
|
|
34247
|
+
if (status)
|
|
34248
|
+
this.#statusTTL(status, index);
|
|
34249
|
+
return v;
|
|
34250
|
+
}
|
|
34251
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
34252
|
+
const hasStale = p.__staleWhileFetching !== undefined;
|
|
34253
|
+
const staleVal = hasStale && allowStale;
|
|
34254
|
+
if (status) {
|
|
34255
|
+
status.fetch = isStale ? "stale" : "refresh";
|
|
34256
|
+
if (staleVal && isStale)
|
|
34257
|
+
status.returnedStale = true;
|
|
34258
|
+
}
|
|
34259
|
+
return staleVal ? p.__staleWhileFetching : p.__returned = p;
|
|
34260
|
+
}
|
|
34261
|
+
}
|
|
34262
|
+
async forceFetch(k, fetchOptions = {}) {
|
|
34263
|
+
const v = await this.fetch(k, fetchOptions);
|
|
34264
|
+
if (v === undefined)
|
|
34265
|
+
throw new Error("fetch() returned undefined");
|
|
34266
|
+
return v;
|
|
34267
|
+
}
|
|
34268
|
+
memo(k, memoOptions = {}) {
|
|
34269
|
+
const memoMethod = this.#memoMethod;
|
|
34270
|
+
if (!memoMethod) {
|
|
34271
|
+
throw new Error("no memoMethod provided to constructor");
|
|
34272
|
+
}
|
|
34273
|
+
const { context, forceRefresh, ...options } = memoOptions;
|
|
34274
|
+
const v = this.get(k, options);
|
|
34275
|
+
if (!forceRefresh && v !== undefined)
|
|
34276
|
+
return v;
|
|
34277
|
+
const vv = memoMethod(k, v, {
|
|
34278
|
+
options,
|
|
34279
|
+
context
|
|
34280
|
+
});
|
|
34281
|
+
this.set(k, vv, options);
|
|
34282
|
+
return vv;
|
|
34283
|
+
}
|
|
34284
|
+
get(k, getOptions = {}) {
|
|
34285
|
+
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
34286
|
+
const index = this.#keyMap.get(k);
|
|
34287
|
+
if (index !== undefined) {
|
|
34288
|
+
const value = this.#valList[index];
|
|
34289
|
+
const fetching = this.#isBackgroundFetch(value);
|
|
34290
|
+
if (status)
|
|
34291
|
+
this.#statusTTL(status, index);
|
|
34292
|
+
if (this.#isStale(index)) {
|
|
34293
|
+
if (status)
|
|
34294
|
+
status.get = "stale";
|
|
34295
|
+
if (!fetching) {
|
|
34296
|
+
if (!noDeleteOnStaleGet) {
|
|
34297
|
+
this.#delete(k, "expire");
|
|
34298
|
+
}
|
|
34299
|
+
if (status && allowStale)
|
|
34300
|
+
status.returnedStale = true;
|
|
34301
|
+
return allowStale ? value : undefined;
|
|
34302
|
+
} else {
|
|
34303
|
+
if (status && allowStale && value.__staleWhileFetching !== undefined) {
|
|
34304
|
+
status.returnedStale = true;
|
|
34305
|
+
}
|
|
34306
|
+
return allowStale ? value.__staleWhileFetching : undefined;
|
|
34307
|
+
}
|
|
34308
|
+
} else {
|
|
34309
|
+
if (status)
|
|
34310
|
+
status.get = "hit";
|
|
34311
|
+
if (fetching) {
|
|
34312
|
+
return value.__staleWhileFetching;
|
|
34313
|
+
}
|
|
34314
|
+
this.#moveToTail(index);
|
|
34315
|
+
if (updateAgeOnGet) {
|
|
34316
|
+
this.#updateItemAge(index);
|
|
34317
|
+
}
|
|
34318
|
+
return value;
|
|
34319
|
+
}
|
|
34320
|
+
} else if (status) {
|
|
34321
|
+
status.get = "miss";
|
|
34322
|
+
}
|
|
34323
|
+
}
|
|
34324
|
+
#connect(p, n) {
|
|
34325
|
+
this.#prev[n] = p;
|
|
34326
|
+
this.#next[p] = n;
|
|
34327
|
+
}
|
|
34328
|
+
#moveToTail(index) {
|
|
34329
|
+
if (index !== this.#tail) {
|
|
34330
|
+
if (index === this.#head) {
|
|
34331
|
+
this.#head = this.#next[index];
|
|
34332
|
+
} else {
|
|
34333
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
34334
|
+
}
|
|
34335
|
+
this.#connect(this.#tail, index);
|
|
34336
|
+
this.#tail = index;
|
|
34337
|
+
}
|
|
34338
|
+
}
|
|
34339
|
+
delete(k) {
|
|
34340
|
+
return this.#delete(k, "delete");
|
|
34341
|
+
}
|
|
34342
|
+
#delete(k, reason) {
|
|
34343
|
+
let deleted = false;
|
|
34344
|
+
if (this.#size !== 0) {
|
|
34345
|
+
const index = this.#keyMap.get(k);
|
|
34346
|
+
if (index !== undefined) {
|
|
34347
|
+
if (this.#autopurgeTimers?.[index]) {
|
|
34348
|
+
clearTimeout(this.#autopurgeTimers?.[index]);
|
|
34349
|
+
this.#autopurgeTimers[index] = undefined;
|
|
34350
|
+
}
|
|
34351
|
+
deleted = true;
|
|
34352
|
+
if (this.#size === 1) {
|
|
34353
|
+
this.#clear(reason);
|
|
34354
|
+
} else {
|
|
34355
|
+
this.#removeItemSize(index);
|
|
34356
|
+
const v = this.#valList[index];
|
|
34357
|
+
if (this.#isBackgroundFetch(v)) {
|
|
34358
|
+
v.__abortController.abort(new Error("deleted"));
|
|
34359
|
+
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
34360
|
+
if (this.#hasDispose) {
|
|
34361
|
+
this.#dispose?.(v, k, reason);
|
|
34362
|
+
}
|
|
34363
|
+
if (this.#hasDisposeAfter) {
|
|
34364
|
+
this.#disposed?.push([v, k, reason]);
|
|
34365
|
+
}
|
|
34366
|
+
}
|
|
34367
|
+
this.#keyMap.delete(k);
|
|
34368
|
+
this.#keyList[index] = undefined;
|
|
34369
|
+
this.#valList[index] = undefined;
|
|
34370
|
+
if (index === this.#tail) {
|
|
34371
|
+
this.#tail = this.#prev[index];
|
|
34372
|
+
} else if (index === this.#head) {
|
|
34373
|
+
this.#head = this.#next[index];
|
|
34374
|
+
} else {
|
|
34375
|
+
const pi = this.#prev[index];
|
|
34376
|
+
this.#next[pi] = this.#next[index];
|
|
34377
|
+
const ni = this.#next[index];
|
|
34378
|
+
this.#prev[ni] = this.#prev[index];
|
|
34379
|
+
}
|
|
34380
|
+
this.#size--;
|
|
34381
|
+
this.#free.push(index);
|
|
34382
|
+
}
|
|
34383
|
+
}
|
|
34384
|
+
}
|
|
34385
|
+
if (this.#hasDisposeAfter && this.#disposed?.length) {
|
|
34386
|
+
const dt = this.#disposed;
|
|
34387
|
+
let task;
|
|
34388
|
+
while (task = dt?.shift()) {
|
|
34389
|
+
this.#disposeAfter?.(...task);
|
|
34390
|
+
}
|
|
34391
|
+
}
|
|
34392
|
+
return deleted;
|
|
34393
|
+
}
|
|
34394
|
+
clear() {
|
|
34395
|
+
return this.#clear("delete");
|
|
34396
|
+
}
|
|
34397
|
+
#clear(reason) {
|
|
34398
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
34399
|
+
const v = this.#valList[index];
|
|
34400
|
+
if (this.#isBackgroundFetch(v)) {
|
|
34401
|
+
v.__abortController.abort(new Error("deleted"));
|
|
34402
|
+
} else {
|
|
34403
|
+
const k = this.#keyList[index];
|
|
34404
|
+
if (this.#hasDispose) {
|
|
34405
|
+
this.#dispose?.(v, k, reason);
|
|
34406
|
+
}
|
|
34407
|
+
if (this.#hasDisposeAfter) {
|
|
34408
|
+
this.#disposed?.push([v, k, reason]);
|
|
34409
|
+
}
|
|
34410
|
+
}
|
|
34411
|
+
}
|
|
34412
|
+
this.#keyMap.clear();
|
|
34413
|
+
this.#valList.fill(undefined);
|
|
34414
|
+
this.#keyList.fill(undefined);
|
|
34415
|
+
if (this.#ttls && this.#starts) {
|
|
34416
|
+
this.#ttls.fill(0);
|
|
34417
|
+
this.#starts.fill(0);
|
|
34418
|
+
for (const t of this.#autopurgeTimers ?? []) {
|
|
34419
|
+
if (t !== undefined)
|
|
34420
|
+
clearTimeout(t);
|
|
34421
|
+
}
|
|
34422
|
+
this.#autopurgeTimers?.fill(undefined);
|
|
34423
|
+
}
|
|
34424
|
+
if (this.#sizes) {
|
|
34425
|
+
this.#sizes.fill(0);
|
|
34426
|
+
}
|
|
34427
|
+
this.#head = 0;
|
|
34428
|
+
this.#tail = 0;
|
|
34429
|
+
this.#free.length = 0;
|
|
34430
|
+
this.#calculatedSize = 0;
|
|
34431
|
+
this.#size = 0;
|
|
34432
|
+
if (this.#hasDisposeAfter && this.#disposed) {
|
|
34433
|
+
const dt = this.#disposed;
|
|
34434
|
+
let task;
|
|
34435
|
+
while (task = dt?.shift()) {
|
|
34436
|
+
this.#disposeAfter?.(...task);
|
|
34437
|
+
}
|
|
34438
|
+
}
|
|
34439
|
+
}
|
|
34440
|
+
}
|
|
34441
|
+
|
|
34442
|
+
// src/module/cache.ts
|
|
34443
|
+
var cache = new LRUCache({
|
|
34444
|
+
max: 1e4,
|
|
34445
|
+
ttl: 1000 * 60 * 60 * 24 * 7
|
|
34446
|
+
});
|
|
34447
|
+
var sessionStorage2 = {
|
|
34448
|
+
setItem: (key, value) => {
|
|
34449
|
+
cache.set(key, value);
|
|
34450
|
+
},
|
|
34451
|
+
getItem: (key) => {
|
|
34452
|
+
return cache.get(key);
|
|
34453
|
+
},
|
|
34454
|
+
removeItem: (key) => {
|
|
34455
|
+
cache.delete(key);
|
|
34456
|
+
},
|
|
34457
|
+
clear: () => {
|
|
34458
|
+
cache.clear();
|
|
34459
|
+
}
|
|
34460
|
+
};
|
|
34461
|
+
|
|
34462
|
+
// src/ai/ai.ts
|
|
34463
|
+
var app2 = new App({ token: storage.getItem("token") || "", storage: sessionStorage2 });
|
|
34464
|
+
|
|
34465
|
+
// src/ai/routes/cmd-run.ts
|
|
34466
|
+
import { execSync as execSync2 } from "node:child_process";
|
|
34467
|
+
var promptTemplate = `# CMD 结果判断器
|
|
34468
|
+
|
|
34469
|
+
分析上一条 CMD 命令的执行结果,判断是否需要执行下一条命令。
|
|
34470
|
+
|
|
34471
|
+
- 若结果中隐含或明确指示需继续执行 → 返回:\`{"cmd": "推断出的下一条命令", "type": "cmd"}\`
|
|
34472
|
+
- 若无后续操作,甚至上一次执行的返回为空或者成功 → 返回:\`{"type": "none"}\`
|
|
34473
|
+
|
|
34474
|
+
1. 仅输出合法 JSON,无任何额外文本。
|
|
34475
|
+
2. \`cmd\` 必须从执行结果中合理推断得出,非预设或猜测。
|
|
34476
|
+
3. 禁止解释、注释、换行或格式错误。`;
|
|
34477
|
+
app2.router.route({
|
|
34478
|
+
path: "cmd-run",
|
|
34479
|
+
description: "执行 CMD 命令并判断下一步操作, 参数是 cmd 字符串"
|
|
34480
|
+
}).define(async (ctx) => {
|
|
34481
|
+
const cmd = ctx.query.cmd || "";
|
|
34482
|
+
if (!cmd) {
|
|
34483
|
+
ctx.throw(400, "cmd is required");
|
|
34484
|
+
}
|
|
34485
|
+
let result = "";
|
|
34486
|
+
ctx.state.steps = ctx.state?.steps || [];
|
|
34487
|
+
try {
|
|
34488
|
+
logger.info("执行命令:", cmd);
|
|
34489
|
+
result = execSync2(cmd, { encoding: "utf-8" });
|
|
34490
|
+
ctx.state.steps.push({ cmd, result });
|
|
34491
|
+
logger.info(result);
|
|
34492
|
+
} catch (error) {
|
|
34493
|
+
result = error.message || "";
|
|
34494
|
+
ctx.state.steps.push({ cmd, result, error: true });
|
|
34495
|
+
ctx.body = {
|
|
34496
|
+
steps: ctx.state.steps
|
|
34497
|
+
};
|
|
34498
|
+
return;
|
|
34499
|
+
}
|
|
34500
|
+
await app2.loadAI();
|
|
34501
|
+
const prompt = `${promptTemplate}
|
|
34502
|
+
上一条命令:
|
|
34503
|
+
${cmd}
|
|
34504
|
+
执行结果:
|
|
34505
|
+
${result}
|
|
34506
|
+
`;
|
|
34507
|
+
const response = await app2.ai.question(prompt);
|
|
34508
|
+
const msg = app2.ai.utils.extractJsonFromMarkdown(app2.ai.responseText);
|
|
34509
|
+
try {
|
|
34510
|
+
logger.debug("AI Prompt", prompt);
|
|
34511
|
+
logger.debug("AI 分析结果:", msg);
|
|
34512
|
+
const { cmd: cmd2, type } = msg;
|
|
34513
|
+
if (type === "cmd" && cmd2) {
|
|
34514
|
+
await app2.router.call({ path: "cmd-run", payload: { cmd: cmd2 } }, { state: ctx.state });
|
|
34515
|
+
} else {
|
|
34516
|
+
logger.info("无后续命令,结束执行");
|
|
34517
|
+
ctx.state.steps.push({ type: "none" });
|
|
34518
|
+
}
|
|
34519
|
+
} catch (error) {
|
|
34520
|
+
result = "执行错误,无法解析返回结果为合法 JSON" + app2.ai.responseText;
|
|
34521
|
+
logger.error(result);
|
|
34522
|
+
ctx.state.steps.push({ cmd, result, parseError: true });
|
|
34523
|
+
}
|
|
34524
|
+
ctx.body = {
|
|
34525
|
+
steps: ctx.state.steps
|
|
34526
|
+
};
|
|
34527
|
+
}).addTo(app2.router);
|
|
34528
|
+
|
|
34529
|
+
// src/command/ai.ts
|
|
34530
|
+
var aiCmd = new Command("ai").description("AI 相关命令").action(async (opts) => {});
|
|
34531
|
+
var runCmd = async (cmd) => {
|
|
34532
|
+
const res = await app2.router.call({ path: "cmd-run", payload: { cmd } });
|
|
34533
|
+
const { body } = res;
|
|
34534
|
+
const steps = body?.steps || [];
|
|
34535
|
+
for (const step of steps) {
|
|
34536
|
+
logger.debug(chalk2.blue(`
|
|
34537
|
+
==== 步骤: ${step.cmd || "结束"} ====`));
|
|
34538
|
+
logger.debug(step.result || "No result");
|
|
34539
|
+
}
|
|
34540
|
+
};
|
|
34541
|
+
var aiRun = new Command("run").description("执行 AI 命令").option("-c, --cmd <cmd>", "要执行的 CMD 命令").action(async (opts) => {
|
|
34542
|
+
if (opts.cmd) {
|
|
34543
|
+
await runCmd(opts.cmd);
|
|
34544
|
+
} else {
|
|
34545
|
+
console.log("请提供要执行的 CMD 命令");
|
|
34546
|
+
}
|
|
34547
|
+
});
|
|
34548
|
+
var aiRunDeploy = new Command("deploy").description("部署 AI 后端应用").action(async (opts) => {
|
|
34549
|
+
const cmd = "ev pack -p -u";
|
|
34550
|
+
const res = await runCmd(cmd);
|
|
34551
|
+
});
|
|
34552
|
+
aiCmd.addCommand(aiRun);
|
|
34553
|
+
aiCmd.addCommand(aiRunDeploy);
|
|
34554
|
+
program.addCommand(aiCmd);
|
|
34555
|
+
|
|
34556
|
+
// src/command/claude/cc.ts
|
|
34557
|
+
import path14 from "node:path";
|
|
34558
|
+
import os4 from "node:os";
|
|
34559
|
+
import fs18 from "node:fs";
|
|
34560
|
+
var MODELS = ["minimax", "glm", "volcengine", "bailian"];
|
|
34561
|
+
var changeMinimax = (token2) => {
|
|
34562
|
+
const auth_token = token2 || useKey("MINIMAX_API_KEY");
|
|
34563
|
+
return {
|
|
34564
|
+
env: {
|
|
34565
|
+
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34566
|
+
ANTHROPIC_BASE_URL: "https://api.minimaxi.com/anthropic",
|
|
34567
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: "MiniMax-M2.1",
|
|
34568
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: "MiniMax-M2.1",
|
|
34569
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: "MiniMax-M2.1",
|
|
34570
|
+
ANTHROPIC_MODEL: "MiniMax-M2.1",
|
|
34571
|
+
API_TIMEOUT_MS: "3000000",
|
|
34572
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 1
|
|
34573
|
+
}
|
|
34574
|
+
};
|
|
34575
|
+
};
|
|
34576
|
+
var changeGLM = (token2) => {
|
|
34577
|
+
const auth_token = token2 || useKey("ZHIPU_API_KEY");
|
|
34578
|
+
return {
|
|
34579
|
+
env: {
|
|
34580
|
+
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34581
|
+
ANTHROPIC_BASE_URL: "https://open.bigmodel.cn/api/anthropic",
|
|
34582
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: "glm-4.7",
|
|
34583
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: "glm-4.7",
|
|
34584
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: "glm-4.7",
|
|
34585
|
+
ANTHROPIC_MODEL: "glm-4.7"
|
|
34586
|
+
}
|
|
34587
|
+
};
|
|
34588
|
+
};
|
|
34589
|
+
var changeVolcengine = (token2) => {
|
|
34590
|
+
const auth_token = token2 || useKey("VOLCENGINE_API_KEY");
|
|
34591
|
+
return {
|
|
34592
|
+
env: {
|
|
34593
|
+
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34594
|
+
ANTHROPIC_BASE_URL: "https://ark.cn-beijing.volces.com/api/coding",
|
|
34595
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: "ark-code-latest",
|
|
34596
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: "ark-code-latest",
|
|
34597
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: "ark-code-latest",
|
|
34598
|
+
ANTHROPIC_MODEL: "ark-code-latest",
|
|
34599
|
+
API_TIMEOUT_MS: "3000000"
|
|
34600
|
+
}
|
|
34601
|
+
};
|
|
34602
|
+
};
|
|
34603
|
+
var changeBailian = (token2) => {
|
|
34604
|
+
const auth_token = token2 || useKey("BAILIAN_API_KEY");
|
|
34605
|
+
return {
|
|
34606
|
+
env: {
|
|
34607
|
+
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34608
|
+
ANTHROPIC_BASE_URL: "https://coding.dashscope.aliyuncs.com/apps/anthropic",
|
|
34609
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: "qwen3-coder-plus",
|
|
34610
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: "qwen3-coder-plus",
|
|
34611
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: "qwen3-coder-plus",
|
|
34612
|
+
ANTHROPIC_MODEL: "qwen3-coder-plus"
|
|
34613
|
+
},
|
|
34614
|
+
includeCoAuthoredBy: false
|
|
34615
|
+
};
|
|
34616
|
+
};
|
|
34617
|
+
var changeNoCheck = () => {
|
|
34618
|
+
const homeDir = os4.homedir();
|
|
34619
|
+
const claudeConfigPath = path14.join(homeDir, ".claude.json");
|
|
34620
|
+
let claudeConfig = {};
|
|
34621
|
+
if (fs18.existsSync(claudeConfigPath)) {
|
|
34622
|
+
const content = fs18.readFileSync(claudeConfigPath, "utf-8");
|
|
34623
|
+
try {
|
|
34624
|
+
claudeConfig = JSON.parse(content);
|
|
34625
|
+
} catch {
|
|
34626
|
+
claudeConfig = {};
|
|
34627
|
+
}
|
|
34628
|
+
}
|
|
34629
|
+
claudeConfig = {
|
|
34630
|
+
...claudeConfig,
|
|
34631
|
+
hasCompletedOnboarding: true
|
|
34632
|
+
};
|
|
34633
|
+
fs18.writeFileSync(claudeConfigPath, JSON.stringify(claudeConfig, null, 2));
|
|
34634
|
+
};
|
|
34635
|
+
var modelConfig = {
|
|
34636
|
+
minimax: changeMinimax,
|
|
34637
|
+
glm: changeGLM,
|
|
34638
|
+
volcengine: changeVolcengine,
|
|
34639
|
+
bailian: changeBailian
|
|
34640
|
+
};
|
|
34641
|
+
var readOrCreateConfig = (configPath2) => {
|
|
34642
|
+
if (fs18.existsSync(configPath2)) {
|
|
34643
|
+
const content = fs18.readFileSync(configPath2, "utf-8");
|
|
34644
|
+
try {
|
|
34645
|
+
return JSON.parse(content);
|
|
34646
|
+
} catch {
|
|
34647
|
+
return {};
|
|
34648
|
+
}
|
|
34649
|
+
}
|
|
34650
|
+
return {};
|
|
34651
|
+
};
|
|
34652
|
+
var saveConfig = (configPath2, config2) => {
|
|
34653
|
+
fs18.writeFileSync(configPath2, JSON.stringify(config2, null, 2));
|
|
34654
|
+
};
|
|
34655
|
+
var command11 = new Command("cc").description("切换claude code模型,支持GLM4.7、Minimax和豆包").option("-m, --models <model:string>", `选择模型: ${MODELS.join(" | ")}`).action(async (options) => {
|
|
34656
|
+
const configPath2 = path14.join(os4.homedir(), ".claude/settings.json");
|
|
34657
|
+
const config2 = readOrCreateConfig(configPath2);
|
|
34658
|
+
let selectedModel;
|
|
34659
|
+
if (options.models && MODELS.includes(options.models)) {
|
|
34660
|
+
selectedModel = options.models;
|
|
34661
|
+
} else {
|
|
34662
|
+
selectedModel = await dist_default4({
|
|
34663
|
+
message: "请选择模型:",
|
|
34664
|
+
choices: MODELS
|
|
34665
|
+
});
|
|
34666
|
+
}
|
|
34667
|
+
const updateConfig = modelConfig[selectedModel]();
|
|
34668
|
+
Object.assign(config2, updateConfig);
|
|
34669
|
+
saveConfig(configPath2, config2);
|
|
34670
|
+
changeNoCheck();
|
|
34671
|
+
console.log(`已切换到模型: ${chalk2.green(selectedModel)}`);
|
|
34672
|
+
console.log(`配置已保存到: ${configPath2}`);
|
|
34673
|
+
});
|
|
34674
|
+
program.addCommand(command11);
|
|
34675
|
+
|
|
34676
|
+
// src/command/docker.ts
|
|
34677
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
34678
|
+
var dockerCommand = new Command("docker").description("Docker 相关指令").action(async () => {
|
|
34679
|
+
console.log(chalk2.green("Docker command executed"));
|
|
34680
|
+
});
|
|
34681
|
+
var login = new Command("login").description("登录 Docker 镜像仓库").option("-r , --registry <registry>", "Docker 镜像仓库地址", "default").action(async (options) => {
|
|
34682
|
+
const { registry = "default" } = options;
|
|
34683
|
+
let DOCKER_USERNAME = useKey("DOCKER_USERNAME");
|
|
34684
|
+
let DOCKER_PASSWORD = useKey("DOCKER_PASSWORD");
|
|
34685
|
+
let DOCKER_REGISTRY = useKey("DOCKER_REGISTRY");
|
|
34686
|
+
if (registry !== "default") {
|
|
34687
|
+
DOCKER_USERNAME = "cnb";
|
|
34688
|
+
DOCKER_PASSWORD = useKey("CNB_TOKEN");
|
|
34689
|
+
DOCKER_REGISTRY = "docker.cnb.cool";
|
|
34690
|
+
}
|
|
34691
|
+
if (!DOCKER_USERNAME || !DOCKER_PASSWORD) {
|
|
34692
|
+
console.log(chalk2.red("请先配置 DOCKER_USERNAME 和 DOCKER_PASSWORD"));
|
|
34693
|
+
return;
|
|
34694
|
+
}
|
|
34695
|
+
const loginProcess = spawn4("docker", [
|
|
34696
|
+
"login",
|
|
34697
|
+
"--username",
|
|
34698
|
+
DOCKER_USERNAME,
|
|
34699
|
+
DOCKER_REGISTRY,
|
|
34700
|
+
"--password-stdin"
|
|
34701
|
+
], {
|
|
34702
|
+
stdio: ["pipe", "inherit", "inherit"]
|
|
34703
|
+
});
|
|
34704
|
+
loginProcess.stdin.write(DOCKER_PASSWORD + `
|
|
34705
|
+
`);
|
|
34706
|
+
loginProcess.stdin.end();
|
|
34707
|
+
loginProcess.on("close", (code) => {
|
|
34708
|
+
if (code === 0) {
|
|
34709
|
+
console.log(chalk2.green("登录成功"));
|
|
34710
|
+
} else {
|
|
34711
|
+
console.log(chalk2.red(`登录失败,退出码:${code}`));
|
|
34712
|
+
}
|
|
34713
|
+
});
|
|
34714
|
+
});
|
|
34715
|
+
dockerCommand.addCommand(login);
|
|
34716
|
+
var helmLogin = new Command("helm").description("Helm 登录镜像仓库").action(async () => {});
|
|
34717
|
+
var helmLoginCommand = new Command("login").description("登录 Helm 镜像仓库").action(async () => {
|
|
34718
|
+
let DOCKER_USERNAME = "cnb";
|
|
34719
|
+
let DOCKER_PASSWORD = useKey("CNB_TOKEN");
|
|
34720
|
+
if (!DOCKER_PASSWORD) {
|
|
34721
|
+
console.log(chalk2.red("请先配置 CNB_TOKEN"));
|
|
34722
|
+
return;
|
|
34723
|
+
}
|
|
34724
|
+
const helmLoginProcess = spawn4("helm", [
|
|
34725
|
+
"registry",
|
|
34726
|
+
"login",
|
|
34727
|
+
"--username",
|
|
34728
|
+
DOCKER_USERNAME,
|
|
34729
|
+
"--password-stdin",
|
|
34730
|
+
"helm.cnb.cool"
|
|
34731
|
+
], {
|
|
34732
|
+
stdio: ["pipe", "inherit", "inherit"]
|
|
34733
|
+
});
|
|
34734
|
+
helmLoginProcess.stdin.write(DOCKER_PASSWORD + `
|
|
34735
|
+
`);
|
|
34736
|
+
helmLoginProcess.stdin.end();
|
|
34737
|
+
helmLoginProcess.on("close", (code) => {
|
|
34738
|
+
if (code === 0) {
|
|
34739
|
+
console.log(chalk2.green("Helm 登录成功"));
|
|
34740
|
+
} else {
|
|
34741
|
+
console.log(chalk2.red(`Helm 登录失败,退出码:${code}`));
|
|
34742
|
+
}
|
|
34743
|
+
});
|
|
34744
|
+
});
|
|
34745
|
+
helmLogin.addCommand(helmLoginCommand);
|
|
34746
|
+
program.addCommand(dockerCommand);
|
|
34747
|
+
program.addCommand(helmLogin);
|
|
34748
|
+
|
|
34749
|
+
// node_modules/.pnpm/@kevisual+auth@2.0.3/node_modules/@kevisual/auth/dist/app.js
|
|
34750
|
+
var __defProp4 = Object.defineProperty;
|
|
34751
|
+
var __export = (target, all) => {
|
|
34752
|
+
for (var name in all)
|
|
34753
|
+
__defProp4(target, name, {
|
|
34754
|
+
get: all[name],
|
|
34755
|
+
enumerable: true,
|
|
34756
|
+
configurable: true,
|
|
34757
|
+
set: (newValue) => all[name] = () => newValue
|
|
34758
|
+
});
|
|
34759
|
+
};
|
|
34760
|
+
var encoder = new TextEncoder;
|
|
34761
|
+
var decoder = new TextDecoder;
|
|
34762
|
+
var MAX_INT32 = 2 ** 32;
|
|
34763
|
+
function concat(...buffers) {
|
|
34764
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
34765
|
+
const buf = new Uint8Array(size);
|
|
34766
|
+
let i = 0;
|
|
34767
|
+
for (const buffer of buffers) {
|
|
34768
|
+
buf.set(buffer, i);
|
|
34769
|
+
i += buffer.length;
|
|
34770
|
+
}
|
|
34771
|
+
return buf;
|
|
34772
|
+
}
|
|
34773
|
+
function encode(string) {
|
|
34774
|
+
const bytes = new Uint8Array(string.length);
|
|
34775
|
+
for (let i = 0;i < string.length; i++) {
|
|
34776
|
+
const code = string.charCodeAt(i);
|
|
34777
|
+
if (code > 127) {
|
|
34778
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
34779
|
+
}
|
|
34780
|
+
bytes[i] = code;
|
|
34781
|
+
}
|
|
34782
|
+
return bytes;
|
|
34783
|
+
}
|
|
34784
|
+
function encodeBase64(input) {
|
|
34785
|
+
if (Uint8Array.prototype.toBase64) {
|
|
34786
|
+
return input.toBase64();
|
|
34787
|
+
}
|
|
34788
|
+
const CHUNK_SIZE = 32768;
|
|
34789
|
+
const arr = [];
|
|
34790
|
+
for (let i = 0;i < input.length; i += CHUNK_SIZE) {
|
|
34791
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
34792
|
+
}
|
|
34793
|
+
return btoa(arr.join(""));
|
|
34794
|
+
}
|
|
34795
|
+
function decodeBase64(encoded) {
|
|
34796
|
+
if (Uint8Array.fromBase64) {
|
|
34797
|
+
return Uint8Array.fromBase64(encoded);
|
|
34798
|
+
}
|
|
34799
|
+
const binary = atob(encoded);
|
|
34800
|
+
const bytes = new Uint8Array(binary.length);
|
|
34801
|
+
for (let i = 0;i < binary.length; i++) {
|
|
34802
|
+
bytes[i] = binary.charCodeAt(i);
|
|
34803
|
+
}
|
|
34804
|
+
return bytes;
|
|
34805
|
+
}
|
|
34806
|
+
function decode(input) {
|
|
34807
|
+
if (Uint8Array.fromBase64) {
|
|
34808
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
34809
|
+
alphabet: "base64url"
|
|
34810
|
+
});
|
|
34811
|
+
}
|
|
34812
|
+
let encoded = input;
|
|
34813
|
+
if (encoded instanceof Uint8Array) {
|
|
34814
|
+
encoded = decoder.decode(encoded);
|
|
34815
|
+
}
|
|
34816
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
34817
|
+
try {
|
|
34818
|
+
return decodeBase64(encoded);
|
|
34819
|
+
} catch {
|
|
34820
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
34821
|
+
}
|
|
34822
|
+
}
|
|
34823
|
+
function encode2(input) {
|
|
34824
|
+
let unencoded = input;
|
|
34825
|
+
if (typeof unencoded === "string") {
|
|
34826
|
+
unencoded = encoder.encode(unencoded);
|
|
34827
|
+
}
|
|
34828
|
+
if (Uint8Array.prototype.toBase64) {
|
|
34829
|
+
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
34830
|
+
}
|
|
34831
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
34832
|
+
}
|
|
34833
|
+
var exports_errors = {};
|
|
34834
|
+
__export(exports_errors, {
|
|
34835
|
+
JWTInvalid: () => JWTInvalid,
|
|
34836
|
+
JWTExpired: () => JWTExpired,
|
|
34837
|
+
JWTClaimValidationFailed: () => JWTClaimValidationFailed,
|
|
34838
|
+
JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
|
|
34839
|
+
JWSInvalid: () => JWSInvalid,
|
|
34840
|
+
JWKSTimeout: () => JWKSTimeout,
|
|
34841
|
+
JWKSNoMatchingKey: () => JWKSNoMatchingKey,
|
|
34842
|
+
JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
|
|
34843
|
+
JWKSInvalid: () => JWKSInvalid,
|
|
34844
|
+
JWKInvalid: () => JWKInvalid,
|
|
34845
|
+
JWEInvalid: () => JWEInvalid,
|
|
34846
|
+
JWEDecryptionFailed: () => JWEDecryptionFailed,
|
|
34847
|
+
JOSENotSupported: () => JOSENotSupported,
|
|
34848
|
+
JOSEError: () => JOSEError,
|
|
34849
|
+
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed
|
|
34850
|
+
});
|
|
34851
|
+
|
|
34852
|
+
class JOSEError extends Error {
|
|
34853
|
+
static code = "ERR_JOSE_GENERIC";
|
|
34854
|
+
code = "ERR_JOSE_GENERIC";
|
|
34855
|
+
constructor(message, options) {
|
|
34856
|
+
super(message, options);
|
|
34857
|
+
this.name = this.constructor.name;
|
|
34858
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
34859
|
+
}
|
|
34860
|
+
}
|
|
34861
|
+
|
|
34862
|
+
class JWTClaimValidationFailed extends JOSEError {
|
|
34863
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
34864
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
34865
|
+
claim;
|
|
34866
|
+
reason;
|
|
34867
|
+
payload;
|
|
34868
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
34869
|
+
super(message, { cause: { claim, reason, payload } });
|
|
34870
|
+
this.claim = claim;
|
|
34871
|
+
this.reason = reason;
|
|
34872
|
+
this.payload = payload;
|
|
34873
|
+
}
|
|
34874
|
+
}
|
|
34875
|
+
|
|
34876
|
+
class JWTExpired extends JOSEError {
|
|
34877
|
+
static code = "ERR_JWT_EXPIRED";
|
|
34878
|
+
code = "ERR_JWT_EXPIRED";
|
|
34879
|
+
claim;
|
|
34880
|
+
reason;
|
|
34881
|
+
payload;
|
|
34882
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
34883
|
+
super(message, { cause: { claim, reason, payload } });
|
|
34884
|
+
this.claim = claim;
|
|
34885
|
+
this.reason = reason;
|
|
34886
|
+
this.payload = payload;
|
|
34887
|
+
}
|
|
34888
|
+
}
|
|
34889
|
+
|
|
34890
|
+
class JOSEAlgNotAllowed extends JOSEError {
|
|
34891
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
34892
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
34893
|
+
}
|
|
34894
|
+
|
|
34895
|
+
class JOSENotSupported extends JOSEError {
|
|
34896
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
34897
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
34898
|
+
}
|
|
34899
|
+
|
|
34900
|
+
class JWEDecryptionFailed extends JOSEError {
|
|
34901
|
+
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
34902
|
+
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
34903
|
+
constructor(message = "decryption operation failed", options) {
|
|
34904
|
+
super(message, options);
|
|
34905
|
+
}
|
|
34906
|
+
}
|
|
34907
|
+
|
|
34908
|
+
class JWEInvalid extends JOSEError {
|
|
34909
|
+
static code = "ERR_JWE_INVALID";
|
|
34910
|
+
code = "ERR_JWE_INVALID";
|
|
34911
|
+
}
|
|
34912
|
+
|
|
34913
|
+
class JWSInvalid extends JOSEError {
|
|
34914
|
+
static code = "ERR_JWS_INVALID";
|
|
34915
|
+
code = "ERR_JWS_INVALID";
|
|
34916
|
+
}
|
|
34917
|
+
|
|
34918
|
+
class JWTInvalid extends JOSEError {
|
|
34919
|
+
static code = "ERR_JWT_INVALID";
|
|
34920
|
+
code = "ERR_JWT_INVALID";
|
|
34921
|
+
}
|
|
34922
|
+
|
|
34923
|
+
class JWKInvalid extends JOSEError {
|
|
34924
|
+
static code = "ERR_JWK_INVALID";
|
|
34925
|
+
code = "ERR_JWK_INVALID";
|
|
34926
|
+
}
|
|
34927
|
+
|
|
34928
|
+
class JWKSInvalid extends JOSEError {
|
|
34929
|
+
static code = "ERR_JWKS_INVALID";
|
|
34930
|
+
code = "ERR_JWKS_INVALID";
|
|
34931
|
+
}
|
|
34932
|
+
|
|
34933
|
+
class JWKSNoMatchingKey extends JOSEError {
|
|
34934
|
+
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
34935
|
+
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
34936
|
+
constructor(message = "no applicable key found in the JSON Web Key Set", options) {
|
|
34937
|
+
super(message, options);
|
|
34938
|
+
}
|
|
34939
|
+
}
|
|
34940
|
+
|
|
34941
|
+
class JWKSMultipleMatchingKeys extends JOSEError {
|
|
34942
|
+
[Symbol.asyncIterator];
|
|
34943
|
+
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
34944
|
+
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
34945
|
+
constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
34946
|
+
super(message, options);
|
|
34947
|
+
}
|
|
34948
|
+
}
|
|
34949
|
+
|
|
34950
|
+
class JWKSTimeout extends JOSEError {
|
|
34951
|
+
static code = "ERR_JWKS_TIMEOUT";
|
|
34952
|
+
code = "ERR_JWKS_TIMEOUT";
|
|
34953
|
+
constructor(message = "request timed out", options) {
|
|
34954
|
+
super(message, options);
|
|
34955
|
+
}
|
|
34956
|
+
}
|
|
34957
|
+
|
|
34958
|
+
class JWSSignatureVerificationFailed extends JOSEError {
|
|
34959
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
34960
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
34961
|
+
constructor(message = "signature verification failed", options) {
|
|
34962
|
+
super(message, options);
|
|
34963
|
+
}
|
|
34964
|
+
}
|
|
34965
|
+
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
34966
|
+
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
34967
|
+
function getHashLength(hash) {
|
|
34968
|
+
return parseInt(hash.name.slice(4), 10);
|
|
34969
|
+
}
|
|
34970
|
+
function getNamedCurve(alg) {
|
|
34971
|
+
switch (alg) {
|
|
34972
|
+
case "ES256":
|
|
34973
|
+
return "P-256";
|
|
34974
|
+
case "ES384":
|
|
34975
|
+
return "P-384";
|
|
34976
|
+
case "ES512":
|
|
34977
|
+
return "P-521";
|
|
34978
|
+
default:
|
|
34979
|
+
throw new Error("unreachable");
|
|
34980
|
+
}
|
|
34981
|
+
}
|
|
34982
|
+
function checkUsage(key, usage) {
|
|
34983
|
+
if (usage && !key.usages.includes(usage)) {
|
|
34984
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
34985
|
+
}
|
|
34986
|
+
}
|
|
34987
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
34988
|
+
switch (alg) {
|
|
34989
|
+
case "HS256":
|
|
34990
|
+
case "HS384":
|
|
34991
|
+
case "HS512": {
|
|
34992
|
+
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
34993
|
+
throw unusable("HMAC");
|
|
34994
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
34995
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
34996
|
+
if (actual !== expected)
|
|
34997
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
34998
|
+
break;
|
|
34999
|
+
}
|
|
35000
|
+
case "RS256":
|
|
35001
|
+
case "RS384":
|
|
35002
|
+
case "RS512": {
|
|
35003
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
35004
|
+
throw unusable("RSASSA-PKCS1-v1_5");
|
|
35005
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
35006
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
35007
|
+
if (actual !== expected)
|
|
35008
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
35009
|
+
break;
|
|
35010
|
+
}
|
|
35011
|
+
case "PS256":
|
|
35012
|
+
case "PS384":
|
|
35013
|
+
case "PS512": {
|
|
35014
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
35015
|
+
throw unusable("RSA-PSS");
|
|
35016
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
35017
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
35018
|
+
if (actual !== expected)
|
|
35019
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
35020
|
+
break;
|
|
35021
|
+
}
|
|
35022
|
+
case "Ed25519":
|
|
35023
|
+
case "EdDSA": {
|
|
35024
|
+
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
35025
|
+
throw unusable("Ed25519");
|
|
35026
|
+
break;
|
|
35027
|
+
}
|
|
35028
|
+
case "ML-DSA-44":
|
|
35029
|
+
case "ML-DSA-65":
|
|
35030
|
+
case "ML-DSA-87": {
|
|
35031
|
+
if (!isAlgorithm(key.algorithm, alg))
|
|
35032
|
+
throw unusable(alg);
|
|
35033
|
+
break;
|
|
35034
|
+
}
|
|
35035
|
+
case "ES256":
|
|
35036
|
+
case "ES384":
|
|
35037
|
+
case "ES512": {
|
|
35038
|
+
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
35039
|
+
throw unusable("ECDSA");
|
|
35040
|
+
const expected = getNamedCurve(alg);
|
|
35041
|
+
const actual = key.algorithm.namedCurve;
|
|
35042
|
+
if (actual !== expected)
|
|
35043
|
+
throw unusable(expected, "algorithm.namedCurve");
|
|
35044
|
+
break;
|
|
35045
|
+
}
|
|
35046
|
+
default:
|
|
35047
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
35048
|
+
}
|
|
35049
|
+
checkUsage(key, usage);
|
|
35050
|
+
}
|
|
35051
|
+
function message(msg, actual, ...types) {
|
|
35052
|
+
types = types.filter(Boolean);
|
|
35053
|
+
if (types.length > 2) {
|
|
35054
|
+
const last = types.pop();
|
|
35055
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
35056
|
+
} else if (types.length === 2) {
|
|
35057
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
35058
|
+
} else {
|
|
35059
|
+
msg += `of type ${types[0]}.`;
|
|
35060
|
+
}
|
|
35061
|
+
if (actual == null) {
|
|
35062
|
+
msg += ` Received ${actual}`;
|
|
35063
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
35064
|
+
msg += ` Received function ${actual.name}`;
|
|
35065
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
35066
|
+
if (actual.constructor?.name) {
|
|
35067
|
+
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
35068
|
+
}
|
|
35069
|
+
}
|
|
35070
|
+
return msg;
|
|
35071
|
+
}
|
|
35072
|
+
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
35073
|
+
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
35074
|
+
var isCryptoKey = (key) => {
|
|
35075
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
35076
|
+
return true;
|
|
35077
|
+
try {
|
|
35078
|
+
return key instanceof CryptoKey;
|
|
35079
|
+
} catch {
|
|
35080
|
+
return false;
|
|
35081
|
+
}
|
|
35082
|
+
};
|
|
35083
|
+
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
35084
|
+
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
35085
|
+
function isDisjoint(...headers) {
|
|
35086
|
+
const sources = headers.filter(Boolean);
|
|
35087
|
+
if (sources.length === 0 || sources.length === 1) {
|
|
35088
|
+
return true;
|
|
35089
|
+
}
|
|
35090
|
+
let acc;
|
|
35091
|
+
for (const header of sources) {
|
|
35092
|
+
const parameters = Object.keys(header);
|
|
35093
|
+
if (!acc || acc.size === 0) {
|
|
35094
|
+
acc = new Set(parameters);
|
|
35095
|
+
continue;
|
|
35096
|
+
}
|
|
35097
|
+
for (const parameter of parameters) {
|
|
35098
|
+
if (acc.has(parameter)) {
|
|
35099
|
+
return false;
|
|
35100
|
+
}
|
|
35101
|
+
acc.add(parameter);
|
|
35102
|
+
}
|
|
35103
|
+
}
|
|
35104
|
+
return true;
|
|
35105
|
+
}
|
|
35106
|
+
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
35107
|
+
function isObject(input) {
|
|
35108
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
35109
|
+
return false;
|
|
35110
|
+
}
|
|
35111
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
35112
|
+
return true;
|
|
35113
|
+
}
|
|
35114
|
+
let proto3 = input;
|
|
35115
|
+
while (Object.getPrototypeOf(proto3) !== null) {
|
|
35116
|
+
proto3 = Object.getPrototypeOf(proto3);
|
|
35117
|
+
}
|
|
35118
|
+
return Object.getPrototypeOf(input) === proto3;
|
|
35119
|
+
}
|
|
35120
|
+
function checkKeyLength(alg, key) {
|
|
35121
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
35122
|
+
const { modulusLength } = key.algorithm;
|
|
35123
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
35124
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
35125
|
+
}
|
|
35126
|
+
}
|
|
35127
|
+
}
|
|
35128
|
+
var formatPEM = (b64, descriptor) => {
|
|
35129
|
+
const newlined = (b64.match(/.{1,64}/g) || []).join(`
|
|
35130
|
+
`);
|
|
35131
|
+
return `-----BEGIN ${descriptor}-----
|
|
35132
|
+
${newlined}
|
|
35133
|
+
-----END ${descriptor}-----`;
|
|
35134
|
+
};
|
|
35135
|
+
var genericExport = async (keyType, keyFormat, key) => {
|
|
35136
|
+
if (isKeyObject(key)) {
|
|
35137
|
+
if (key.type !== keyType) {
|
|
35138
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
35139
|
+
}
|
|
35140
|
+
return key.export({ format: "pem", type: keyFormat });
|
|
35141
|
+
}
|
|
35142
|
+
if (!isCryptoKey(key)) {
|
|
35143
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
35144
|
+
}
|
|
35145
|
+
if (!key.extractable) {
|
|
35146
|
+
throw new TypeError("CryptoKey is not extractable");
|
|
35147
|
+
}
|
|
35148
|
+
if (key.type !== keyType) {
|
|
35149
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
35150
|
+
}
|
|
35151
|
+
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
35152
|
+
};
|
|
35153
|
+
var toSPKI = (key) => genericExport("public", "spki", key);
|
|
35154
|
+
var toPKCS8 = (key) => genericExport("private", "pkcs8", key);
|
|
35155
|
+
function subtleMapping(jwk) {
|
|
35156
|
+
let algorithm;
|
|
35157
|
+
let keyUsages;
|
|
35158
|
+
switch (jwk.kty) {
|
|
35159
|
+
case "AKP": {
|
|
35160
|
+
switch (jwk.alg) {
|
|
35161
|
+
case "ML-DSA-44":
|
|
35162
|
+
case "ML-DSA-65":
|
|
35163
|
+
case "ML-DSA-87":
|
|
35164
|
+
algorithm = { name: jwk.alg };
|
|
35165
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
35166
|
+
break;
|
|
35167
|
+
default:
|
|
35168
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
35169
|
+
}
|
|
35170
|
+
break;
|
|
35171
|
+
}
|
|
35172
|
+
case "RSA": {
|
|
35173
|
+
switch (jwk.alg) {
|
|
35174
|
+
case "PS256":
|
|
35175
|
+
case "PS384":
|
|
35176
|
+
case "PS512":
|
|
35177
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
35178
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
35179
|
+
break;
|
|
35180
|
+
case "RS256":
|
|
35181
|
+
case "RS384":
|
|
35182
|
+
case "RS512":
|
|
35183
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
35184
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
35185
|
+
break;
|
|
35186
|
+
case "RSA-OAEP":
|
|
35187
|
+
case "RSA-OAEP-256":
|
|
35188
|
+
case "RSA-OAEP-384":
|
|
35189
|
+
case "RSA-OAEP-512":
|
|
35190
|
+
algorithm = {
|
|
35191
|
+
name: "RSA-OAEP",
|
|
35192
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
35193
|
+
};
|
|
35194
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
35195
|
+
break;
|
|
35196
|
+
default:
|
|
35197
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
35198
|
+
}
|
|
35199
|
+
break;
|
|
35200
|
+
}
|
|
35201
|
+
case "EC": {
|
|
35202
|
+
switch (jwk.alg) {
|
|
35203
|
+
case "ES256":
|
|
35204
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
35205
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
35206
|
+
break;
|
|
35207
|
+
case "ES384":
|
|
35208
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
35209
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
35210
|
+
break;
|
|
35211
|
+
case "ES512":
|
|
35212
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
35213
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
35214
|
+
break;
|
|
35215
|
+
case "ECDH-ES":
|
|
35216
|
+
case "ECDH-ES+A128KW":
|
|
35217
|
+
case "ECDH-ES+A192KW":
|
|
35218
|
+
case "ECDH-ES+A256KW":
|
|
35219
|
+
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
35220
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
35221
|
+
break;
|
|
35222
|
+
default:
|
|
35223
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
35224
|
+
}
|
|
35225
|
+
break;
|
|
35226
|
+
}
|
|
35227
|
+
case "OKP": {
|
|
35228
|
+
switch (jwk.alg) {
|
|
35229
|
+
case "Ed25519":
|
|
35230
|
+
case "EdDSA":
|
|
35231
|
+
algorithm = { name: "Ed25519" };
|
|
35232
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
35233
|
+
break;
|
|
35234
|
+
case "ECDH-ES":
|
|
35235
|
+
case "ECDH-ES+A128KW":
|
|
35236
|
+
case "ECDH-ES+A192KW":
|
|
35237
|
+
case "ECDH-ES+A256KW":
|
|
35238
|
+
algorithm = { name: jwk.crv };
|
|
35239
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
35240
|
+
break;
|
|
35241
|
+
default:
|
|
35242
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
35243
|
+
}
|
|
35244
|
+
break;
|
|
35245
|
+
}
|
|
35246
|
+
default:
|
|
35247
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
35248
|
+
}
|
|
35249
|
+
return { algorithm, keyUsages };
|
|
35250
|
+
}
|
|
35251
|
+
async function jwkToKey(jwk) {
|
|
35252
|
+
if (!jwk.alg) {
|
|
35253
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
35254
|
+
}
|
|
35255
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
35256
|
+
const keyData = { ...jwk };
|
|
35257
|
+
if (keyData.kty !== "AKP") {
|
|
35258
|
+
delete keyData.alg;
|
|
35259
|
+
}
|
|
35260
|
+
delete keyData.use;
|
|
35261
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
35262
|
+
}
|
|
35263
|
+
async function importJWK(jwk, alg, options) {
|
|
35264
|
+
if (!isObject(jwk)) {
|
|
35265
|
+
throw new TypeError("JWK must be an object");
|
|
35266
|
+
}
|
|
35267
|
+
let ext;
|
|
35268
|
+
alg ??= jwk.alg;
|
|
35269
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
35270
|
+
switch (jwk.kty) {
|
|
35271
|
+
case "oct":
|
|
35272
|
+
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
35273
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
35274
|
+
}
|
|
35275
|
+
return decode(jwk.k);
|
|
35276
|
+
case "RSA":
|
|
35277
|
+
if ("oth" in jwk && jwk.oth !== undefined) {
|
|
35278
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
35279
|
+
}
|
|
35280
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
35281
|
+
case "AKP": {
|
|
35282
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
35283
|
+
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
35284
|
+
}
|
|
35285
|
+
if (alg !== undefined && alg !== jwk.alg) {
|
|
35286
|
+
throw new TypeError("JWK alg and alg option value mismatch");
|
|
35287
|
+
}
|
|
35288
|
+
return jwkToKey({ ...jwk, ext });
|
|
35289
|
+
}
|
|
35290
|
+
case "EC":
|
|
35291
|
+
case "OKP":
|
|
35292
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
35293
|
+
default:
|
|
35294
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
35295
|
+
}
|
|
35296
|
+
}
|
|
35297
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
35298
|
+
if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
|
|
35299
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
35300
|
+
}
|
|
35301
|
+
if (!protectedHeader || protectedHeader.crit === undefined) {
|
|
35302
|
+
return new Set;
|
|
35303
|
+
}
|
|
35304
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
35305
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
35306
|
+
}
|
|
35307
|
+
let recognized;
|
|
35308
|
+
if (recognizedOption !== undefined) {
|
|
35309
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
35310
|
+
} else {
|
|
35311
|
+
recognized = recognizedDefault;
|
|
35312
|
+
}
|
|
35313
|
+
for (const parameter of protectedHeader.crit) {
|
|
35314
|
+
if (!recognized.has(parameter)) {
|
|
35315
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
35316
|
+
}
|
|
35317
|
+
if (joseHeader[parameter] === undefined) {
|
|
35318
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
35319
|
+
}
|
|
35320
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === undefined) {
|
|
35321
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
35322
|
+
}
|
|
35323
|
+
}
|
|
35324
|
+
return new Set(protectedHeader.crit);
|
|
35325
|
+
}
|
|
35326
|
+
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
35327
|
+
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
35328
|
+
var isPublicJWK = (key) => key.kty !== "oct" && key.d === undefined && key.priv === undefined;
|
|
35329
|
+
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
35330
|
+
var cache2;
|
|
35331
|
+
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
35332
|
+
cache2 ||= new WeakMap;
|
|
35333
|
+
let cached = cache2.get(key);
|
|
35334
|
+
if (cached?.[alg]) {
|
|
35335
|
+
return cached[alg];
|
|
35336
|
+
}
|
|
35337
|
+
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
35338
|
+
if (freeze)
|
|
35339
|
+
Object.freeze(key);
|
|
35340
|
+
if (!cached) {
|
|
35341
|
+
cache2.set(key, { [alg]: cryptoKey });
|
|
35342
|
+
} else {
|
|
35343
|
+
cached[alg] = cryptoKey;
|
|
35344
|
+
}
|
|
35345
|
+
return cryptoKey;
|
|
35346
|
+
};
|
|
35347
|
+
var handleKeyObject = (keyObject, alg) => {
|
|
35348
|
+
cache2 ||= new WeakMap;
|
|
35349
|
+
let cached = cache2.get(keyObject);
|
|
35350
|
+
if (cached?.[alg]) {
|
|
35351
|
+
return cached[alg];
|
|
35352
|
+
}
|
|
35353
|
+
const isPublic = keyObject.type === "public";
|
|
35354
|
+
const extractable = isPublic ? true : false;
|
|
35355
|
+
let cryptoKey;
|
|
35356
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
35357
|
+
switch (alg) {
|
|
35358
|
+
case "ECDH-ES":
|
|
35359
|
+
case "ECDH-ES+A128KW":
|
|
35360
|
+
case "ECDH-ES+A192KW":
|
|
35361
|
+
case "ECDH-ES+A256KW":
|
|
35362
|
+
break;
|
|
35363
|
+
default:
|
|
35364
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
35365
|
+
}
|
|
35366
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
35367
|
+
}
|
|
35368
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
35369
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
35370
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
35371
|
+
}
|
|
35372
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
35373
|
+
isPublic ? "verify" : "sign"
|
|
35374
|
+
]);
|
|
35375
|
+
}
|
|
35376
|
+
switch (keyObject.asymmetricKeyType) {
|
|
35377
|
+
case "ml-dsa-44":
|
|
35378
|
+
case "ml-dsa-65":
|
|
35379
|
+
case "ml-dsa-87": {
|
|
35380
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
35381
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
35382
|
+
}
|
|
35383
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
35384
|
+
isPublic ? "verify" : "sign"
|
|
35385
|
+
]);
|
|
35386
|
+
}
|
|
35387
|
+
}
|
|
35388
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
35389
|
+
let hash;
|
|
35390
|
+
switch (alg) {
|
|
35391
|
+
case "RSA-OAEP":
|
|
35392
|
+
hash = "SHA-1";
|
|
35393
|
+
break;
|
|
35394
|
+
case "RS256":
|
|
35395
|
+
case "PS256":
|
|
35396
|
+
case "RSA-OAEP-256":
|
|
35397
|
+
hash = "SHA-256";
|
|
35398
|
+
break;
|
|
35399
|
+
case "RS384":
|
|
35400
|
+
case "PS384":
|
|
35401
|
+
case "RSA-OAEP-384":
|
|
35402
|
+
hash = "SHA-384";
|
|
35403
|
+
break;
|
|
35404
|
+
case "RS512":
|
|
35405
|
+
case "PS512":
|
|
35406
|
+
case "RSA-OAEP-512":
|
|
35407
|
+
hash = "SHA-512";
|
|
35408
|
+
break;
|
|
35409
|
+
default:
|
|
35410
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
35411
|
+
}
|
|
35412
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
35413
|
+
return keyObject.toCryptoKey({
|
|
35414
|
+
name: "RSA-OAEP",
|
|
35415
|
+
hash
|
|
35416
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
35417
|
+
}
|
|
35418
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
35419
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
35420
|
+
hash
|
|
35421
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
35422
|
+
}
|
|
35423
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
35424
|
+
const nist = new Map([
|
|
35425
|
+
["prime256v1", "P-256"],
|
|
35426
|
+
["secp384r1", "P-384"],
|
|
35427
|
+
["secp521r1", "P-521"]
|
|
35428
|
+
]);
|
|
35429
|
+
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
35430
|
+
if (!namedCurve) {
|
|
35431
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
35432
|
+
}
|
|
35433
|
+
if (alg === "ES256" && namedCurve === "P-256") {
|
|
35434
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
35435
|
+
name: "ECDSA",
|
|
35436
|
+
namedCurve
|
|
35437
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
35438
|
+
}
|
|
35439
|
+
if (alg === "ES384" && namedCurve === "P-384") {
|
|
35440
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
35441
|
+
name: "ECDSA",
|
|
35442
|
+
namedCurve
|
|
35443
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
35444
|
+
}
|
|
35445
|
+
if (alg === "ES512" && namedCurve === "P-521") {
|
|
35446
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
35447
|
+
name: "ECDSA",
|
|
35448
|
+
namedCurve
|
|
35449
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
35450
|
+
}
|
|
35451
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
35452
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
35453
|
+
name: "ECDH",
|
|
35454
|
+
namedCurve
|
|
35455
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
35456
|
+
}
|
|
35457
|
+
}
|
|
35458
|
+
if (!cryptoKey) {
|
|
35459
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
35460
|
+
}
|
|
35461
|
+
if (!cached) {
|
|
35462
|
+
cache2.set(keyObject, { [alg]: cryptoKey });
|
|
35463
|
+
} else {
|
|
35464
|
+
cached[alg] = cryptoKey;
|
|
35465
|
+
}
|
|
35466
|
+
return cryptoKey;
|
|
35467
|
+
};
|
|
35468
|
+
async function normalizeKey(key, alg) {
|
|
35469
|
+
if (key instanceof Uint8Array) {
|
|
35470
|
+
return key;
|
|
35471
|
+
}
|
|
35472
|
+
if (isCryptoKey(key)) {
|
|
35473
|
+
return key;
|
|
35474
|
+
}
|
|
35475
|
+
if (isKeyObject(key)) {
|
|
35476
|
+
if (key.type === "secret") {
|
|
35477
|
+
return key.export();
|
|
35478
|
+
}
|
|
35479
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
35480
|
+
try {
|
|
35481
|
+
return handleKeyObject(key, alg);
|
|
35482
|
+
} catch (err) {
|
|
35483
|
+
if (err instanceof TypeError) {
|
|
35484
|
+
throw err;
|
|
35485
|
+
}
|
|
35486
|
+
}
|
|
35487
|
+
}
|
|
35488
|
+
let jwk = key.export({ format: "jwk" });
|
|
35489
|
+
return handleJWK(key, jwk, alg);
|
|
35490
|
+
}
|
|
35491
|
+
if (isJWK(key)) {
|
|
35492
|
+
if (key.k) {
|
|
35493
|
+
return decode(key.k);
|
|
35494
|
+
}
|
|
35495
|
+
return handleJWK(key, key, alg, true);
|
|
35496
|
+
}
|
|
35497
|
+
throw new Error("unreachable");
|
|
35498
|
+
}
|
|
35499
|
+
var tag = (key) => key?.[Symbol.toStringTag];
|
|
35500
|
+
var jwkMatchesOp = (alg, key, usage) => {
|
|
35501
|
+
if (key.use !== undefined) {
|
|
35502
|
+
let expected;
|
|
35503
|
+
switch (usage) {
|
|
35504
|
+
case "sign":
|
|
35505
|
+
case "verify":
|
|
35506
|
+
expected = "sig";
|
|
35507
|
+
break;
|
|
35508
|
+
case "encrypt":
|
|
35509
|
+
case "decrypt":
|
|
35510
|
+
expected = "enc";
|
|
35511
|
+
break;
|
|
35512
|
+
}
|
|
35513
|
+
if (key.use !== expected) {
|
|
35514
|
+
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
35515
|
+
}
|
|
35516
|
+
}
|
|
35517
|
+
if (key.alg !== undefined && key.alg !== alg) {
|
|
35518
|
+
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
35519
|
+
}
|
|
35520
|
+
if (Array.isArray(key.key_ops)) {
|
|
35521
|
+
let expectedKeyOp;
|
|
35522
|
+
switch (true) {
|
|
35523
|
+
case (usage === "sign" || usage === "verify"):
|
|
35524
|
+
case alg === "dir":
|
|
35525
|
+
case alg.includes("CBC-HS"):
|
|
35526
|
+
expectedKeyOp = usage;
|
|
35527
|
+
break;
|
|
35528
|
+
case alg.startsWith("PBES2"):
|
|
35529
|
+
expectedKeyOp = "deriveBits";
|
|
35530
|
+
break;
|
|
35531
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
35532
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
35533
|
+
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
35534
|
+
} else {
|
|
35535
|
+
expectedKeyOp = usage;
|
|
35536
|
+
}
|
|
35537
|
+
break;
|
|
35538
|
+
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
35539
|
+
expectedKeyOp = "wrapKey";
|
|
35540
|
+
break;
|
|
35541
|
+
case usage === "decrypt":
|
|
35542
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
35543
|
+
break;
|
|
35544
|
+
}
|
|
35545
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
35546
|
+
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
35547
|
+
}
|
|
35548
|
+
}
|
|
35549
|
+
return true;
|
|
35550
|
+
};
|
|
35551
|
+
var symmetricTypeCheck = (alg, key, usage) => {
|
|
35552
|
+
if (key instanceof Uint8Array)
|
|
35553
|
+
return;
|
|
35554
|
+
if (isJWK(key)) {
|
|
35555
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
35556
|
+
return;
|
|
35557
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
35558
|
+
}
|
|
35559
|
+
if (!isKeyLike(key)) {
|
|
35560
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
35561
|
+
}
|
|
35562
|
+
if (key.type !== "secret") {
|
|
35563
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
35564
|
+
}
|
|
35565
|
+
};
|
|
35566
|
+
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
35567
|
+
if (isJWK(key)) {
|
|
35568
|
+
switch (usage) {
|
|
35569
|
+
case "decrypt":
|
|
35570
|
+
case "sign":
|
|
35571
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
35572
|
+
return;
|
|
35573
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
35574
|
+
case "encrypt":
|
|
35575
|
+
case "verify":
|
|
35576
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
35577
|
+
return;
|
|
35578
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
35579
|
+
}
|
|
35580
|
+
}
|
|
35581
|
+
if (!isKeyLike(key)) {
|
|
35582
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
35583
|
+
}
|
|
35584
|
+
if (key.type === "secret") {
|
|
35585
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
35586
|
+
}
|
|
35587
|
+
if (key.type === "public") {
|
|
35588
|
+
switch (usage) {
|
|
35589
|
+
case "sign":
|
|
35590
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
35591
|
+
case "decrypt":
|
|
35592
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
35593
|
+
}
|
|
35594
|
+
}
|
|
35595
|
+
if (key.type === "private") {
|
|
35596
|
+
switch (usage) {
|
|
35597
|
+
case "verify":
|
|
35598
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
35599
|
+
case "encrypt":
|
|
35600
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
35601
|
+
}
|
|
35602
|
+
}
|
|
35603
|
+
};
|
|
35604
|
+
function checkKeyType(alg, key, usage) {
|
|
35605
|
+
switch (alg.substring(0, 2)) {
|
|
35606
|
+
case "A1":
|
|
35607
|
+
case "A2":
|
|
35608
|
+
case "di":
|
|
35609
|
+
case "HS":
|
|
35610
|
+
case "PB":
|
|
35611
|
+
symmetricTypeCheck(alg, key, usage);
|
|
35612
|
+
break;
|
|
35613
|
+
default:
|
|
35614
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
35615
|
+
}
|
|
35616
|
+
}
|
|
35617
|
+
async function keyToJWK(key) {
|
|
35618
|
+
if (isKeyObject(key)) {
|
|
35619
|
+
if (key.type === "secret") {
|
|
35620
|
+
key = key.export();
|
|
35621
|
+
} else {
|
|
35622
|
+
return key.export({ format: "jwk" });
|
|
35623
|
+
}
|
|
35624
|
+
}
|
|
35625
|
+
if (key instanceof Uint8Array) {
|
|
35626
|
+
return {
|
|
35627
|
+
kty: "oct",
|
|
35628
|
+
k: encode2(key)
|
|
35629
|
+
};
|
|
35630
|
+
}
|
|
35631
|
+
if (!isCryptoKey(key)) {
|
|
35632
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
35633
|
+
}
|
|
35634
|
+
if (!key.extractable) {
|
|
35635
|
+
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
35636
|
+
}
|
|
35637
|
+
const { ext, key_ops, alg, use: use3, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
35638
|
+
if (jwk.kty === "AKP") {
|
|
35639
|
+
jwk.alg = alg;
|
|
35640
|
+
}
|
|
35641
|
+
return jwk;
|
|
35642
|
+
}
|
|
35643
|
+
async function exportSPKI(key) {
|
|
35644
|
+
return toSPKI(key);
|
|
35645
|
+
}
|
|
35646
|
+
async function exportPKCS8(key) {
|
|
35647
|
+
return toPKCS8(key);
|
|
35648
|
+
}
|
|
35649
|
+
async function exportJWK(key) {
|
|
35650
|
+
return keyToJWK(key);
|
|
35651
|
+
}
|
|
35652
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
35653
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
35654
|
+
switch (alg) {
|
|
35655
|
+
case "HS256":
|
|
35656
|
+
case "HS384":
|
|
35657
|
+
case "HS512":
|
|
35658
|
+
return { hash, name: "HMAC" };
|
|
35659
|
+
case "PS256":
|
|
35660
|
+
case "PS384":
|
|
35661
|
+
case "PS512":
|
|
35662
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
35663
|
+
case "RS256":
|
|
35664
|
+
case "RS384":
|
|
35665
|
+
case "RS512":
|
|
35666
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
35667
|
+
case "ES256":
|
|
35668
|
+
case "ES384":
|
|
35669
|
+
case "ES512":
|
|
35670
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
35671
|
+
case "Ed25519":
|
|
35672
|
+
case "EdDSA":
|
|
35673
|
+
return { name: "Ed25519" };
|
|
35674
|
+
case "ML-DSA-44":
|
|
35675
|
+
case "ML-DSA-65":
|
|
35676
|
+
case "ML-DSA-87":
|
|
35677
|
+
return { name: alg };
|
|
35678
|
+
default:
|
|
35679
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
35680
|
+
}
|
|
35681
|
+
}
|
|
35682
|
+
async function getSigKey(alg, key, usage) {
|
|
35683
|
+
if (key instanceof Uint8Array) {
|
|
35684
|
+
if (!alg.startsWith("HS")) {
|
|
35685
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
35686
|
+
}
|
|
35687
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
35688
|
+
}
|
|
35689
|
+
checkSigCryptoKey(key, alg, usage);
|
|
35690
|
+
return key;
|
|
35691
|
+
}
|
|
35692
|
+
var epoch = (date) => Math.floor(date.getTime() / 1000);
|
|
35693
|
+
var minute = 60;
|
|
35694
|
+
var hour = minute * 60;
|
|
35695
|
+
var day = hour * 24;
|
|
35696
|
+
var week = day * 7;
|
|
35697
|
+
var year = day * 365.25;
|
|
35698
|
+
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
35699
|
+
function secs(str) {
|
|
35700
|
+
const matched = REGEX.exec(str);
|
|
35701
|
+
if (!matched || matched[4] && matched[1]) {
|
|
35702
|
+
throw new TypeError("Invalid time period format");
|
|
35703
|
+
}
|
|
35704
|
+
const value = parseFloat(matched[2]);
|
|
35705
|
+
const unit = matched[3].toLowerCase();
|
|
35706
|
+
let numericDate;
|
|
35707
|
+
switch (unit) {
|
|
35708
|
+
case "sec":
|
|
35709
|
+
case "secs":
|
|
35710
|
+
case "second":
|
|
35711
|
+
case "seconds":
|
|
35712
|
+
case "s":
|
|
35713
|
+
numericDate = Math.round(value);
|
|
35714
|
+
break;
|
|
35715
|
+
case "minute":
|
|
35716
|
+
case "minutes":
|
|
35717
|
+
case "min":
|
|
35718
|
+
case "mins":
|
|
35719
|
+
case "m":
|
|
35720
|
+
numericDate = Math.round(value * minute);
|
|
35721
|
+
break;
|
|
35722
|
+
case "hour":
|
|
35723
|
+
case "hours":
|
|
35724
|
+
case "hr":
|
|
35725
|
+
case "hrs":
|
|
35726
|
+
case "h":
|
|
35727
|
+
numericDate = Math.round(value * hour);
|
|
35728
|
+
break;
|
|
35729
|
+
case "day":
|
|
35730
|
+
case "days":
|
|
35731
|
+
case "d":
|
|
35732
|
+
numericDate = Math.round(value * day);
|
|
35733
|
+
break;
|
|
35734
|
+
case "week":
|
|
35735
|
+
case "weeks":
|
|
35736
|
+
case "w":
|
|
35737
|
+
numericDate = Math.round(value * week);
|
|
35738
|
+
break;
|
|
35739
|
+
default:
|
|
35740
|
+
numericDate = Math.round(value * year);
|
|
35741
|
+
break;
|
|
35742
|
+
}
|
|
35743
|
+
if (matched[1] === "-" || matched[4] === "ago") {
|
|
35744
|
+
return -numericDate;
|
|
35745
|
+
}
|
|
35746
|
+
return numericDate;
|
|
35747
|
+
}
|
|
35748
|
+
function validateInput(label, input) {
|
|
35749
|
+
if (!Number.isFinite(input)) {
|
|
35750
|
+
throw new TypeError(`Invalid ${label} input`);
|
|
35751
|
+
}
|
|
35752
|
+
return input;
|
|
35753
|
+
}
|
|
35754
|
+
class JWTClaimsBuilder {
|
|
35755
|
+
#payload;
|
|
35756
|
+
constructor(payload) {
|
|
35757
|
+
if (!isObject(payload)) {
|
|
35758
|
+
throw new TypeError("JWT Claims Set MUST be an object");
|
|
35759
|
+
}
|
|
35760
|
+
this.#payload = structuredClone(payload);
|
|
35761
|
+
}
|
|
35762
|
+
data() {
|
|
35763
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
35764
|
+
}
|
|
35765
|
+
get iss() {
|
|
35766
|
+
return this.#payload.iss;
|
|
35767
|
+
}
|
|
35768
|
+
set iss(value) {
|
|
35769
|
+
this.#payload.iss = value;
|
|
35770
|
+
}
|
|
35771
|
+
get sub() {
|
|
35772
|
+
return this.#payload.sub;
|
|
35773
|
+
}
|
|
35774
|
+
set sub(value) {
|
|
35775
|
+
this.#payload.sub = value;
|
|
35776
|
+
}
|
|
35777
|
+
get aud() {
|
|
35778
|
+
return this.#payload.aud;
|
|
35779
|
+
}
|
|
35780
|
+
set aud(value) {
|
|
35781
|
+
this.#payload.aud = value;
|
|
35782
|
+
}
|
|
35783
|
+
set jti(value) {
|
|
35784
|
+
this.#payload.jti = value;
|
|
35785
|
+
}
|
|
35786
|
+
set nbf(value) {
|
|
35787
|
+
if (typeof value === "number") {
|
|
35788
|
+
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
35789
|
+
} else if (value instanceof Date) {
|
|
35790
|
+
this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
35791
|
+
} else {
|
|
35792
|
+
this.#payload.nbf = epoch(new Date) + secs(value);
|
|
35793
|
+
}
|
|
35794
|
+
}
|
|
35795
|
+
set exp(value) {
|
|
35796
|
+
if (typeof value === "number") {
|
|
35797
|
+
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
35798
|
+
} else if (value instanceof Date) {
|
|
35799
|
+
this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
35800
|
+
} else {
|
|
35801
|
+
this.#payload.exp = epoch(new Date) + secs(value);
|
|
35802
|
+
}
|
|
35803
|
+
}
|
|
35804
|
+
set iat(value) {
|
|
35805
|
+
if (value === undefined) {
|
|
35806
|
+
this.#payload.iat = epoch(new Date);
|
|
35807
|
+
} else if (value instanceof Date) {
|
|
35808
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
35809
|
+
} else if (typeof value === "string") {
|
|
35810
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(new Date) + secs(value));
|
|
35811
|
+
} else {
|
|
35812
|
+
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
35813
|
+
}
|
|
35814
|
+
}
|
|
35815
|
+
}
|
|
35816
|
+
async function sign(alg, key, data) {
|
|
35817
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
35818
|
+
checkKeyLength(alg, cryptoKey);
|
|
35819
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
35820
|
+
return new Uint8Array(signature);
|
|
35821
|
+
}
|
|
35822
|
+
|
|
35823
|
+
class FlattenedSign {
|
|
35824
|
+
#payload;
|
|
35825
|
+
#protectedHeader;
|
|
35826
|
+
#unprotectedHeader;
|
|
35827
|
+
constructor(payload) {
|
|
35828
|
+
if (!(payload instanceof Uint8Array)) {
|
|
35829
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
35830
|
+
}
|
|
35831
|
+
this.#payload = payload;
|
|
35832
|
+
}
|
|
35833
|
+
setProtectedHeader(protectedHeader) {
|
|
35834
|
+
if (this.#protectedHeader) {
|
|
35835
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
35836
|
+
}
|
|
35837
|
+
this.#protectedHeader = protectedHeader;
|
|
35838
|
+
return this;
|
|
35839
|
+
}
|
|
35840
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
35841
|
+
if (this.#unprotectedHeader) {
|
|
35842
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
35843
|
+
}
|
|
35844
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
35845
|
+
return this;
|
|
35846
|
+
}
|
|
35847
|
+
async sign(key, options) {
|
|
35848
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
35849
|
+
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
35850
|
+
}
|
|
35851
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
35852
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
35853
|
+
}
|
|
35854
|
+
const joseHeader = {
|
|
35855
|
+
...this.#protectedHeader,
|
|
35856
|
+
...this.#unprotectedHeader
|
|
35857
|
+
};
|
|
35858
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
35859
|
+
let b64 = true;
|
|
35860
|
+
if (extensions.has("b64")) {
|
|
35861
|
+
b64 = this.#protectedHeader.b64;
|
|
35862
|
+
if (typeof b64 !== "boolean") {
|
|
35863
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
35864
|
+
}
|
|
35865
|
+
}
|
|
35866
|
+
const { alg } = joseHeader;
|
|
35867
|
+
if (typeof alg !== "string" || !alg) {
|
|
35868
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
35869
|
+
}
|
|
35870
|
+
checkKeyType(alg, key, "sign");
|
|
35871
|
+
let payloadS;
|
|
35872
|
+
let payloadB;
|
|
35873
|
+
if (b64) {
|
|
35874
|
+
payloadS = encode2(this.#payload);
|
|
35875
|
+
payloadB = encode(payloadS);
|
|
35876
|
+
} else {
|
|
35877
|
+
payloadB = this.#payload;
|
|
35878
|
+
payloadS = "";
|
|
35879
|
+
}
|
|
35880
|
+
let protectedHeaderString;
|
|
35881
|
+
let protectedHeaderBytes;
|
|
35882
|
+
if (this.#protectedHeader) {
|
|
35883
|
+
protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
|
|
35884
|
+
protectedHeaderBytes = encode(protectedHeaderString);
|
|
35885
|
+
} else {
|
|
35886
|
+
protectedHeaderString = "";
|
|
35887
|
+
protectedHeaderBytes = new Uint8Array;
|
|
35888
|
+
}
|
|
35889
|
+
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
35890
|
+
const k = await normalizeKey(key, alg);
|
|
35891
|
+
const signature = await sign(alg, k, data);
|
|
35892
|
+
const jws = {
|
|
35893
|
+
signature: encode2(signature),
|
|
35894
|
+
payload: payloadS
|
|
35895
|
+
};
|
|
35896
|
+
if (this.#unprotectedHeader) {
|
|
35897
|
+
jws.header = this.#unprotectedHeader;
|
|
35898
|
+
}
|
|
35899
|
+
if (this.#protectedHeader) {
|
|
35900
|
+
jws.protected = protectedHeaderString;
|
|
35901
|
+
}
|
|
35902
|
+
return jws;
|
|
35903
|
+
}
|
|
35904
|
+
}
|
|
35905
|
+
|
|
35906
|
+
class CompactSign {
|
|
35907
|
+
#flattened;
|
|
35908
|
+
constructor(payload) {
|
|
35909
|
+
this.#flattened = new FlattenedSign(payload);
|
|
35910
|
+
}
|
|
35911
|
+
setProtectedHeader(protectedHeader) {
|
|
35912
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
35913
|
+
return this;
|
|
35914
|
+
}
|
|
35915
|
+
async sign(key, options) {
|
|
35916
|
+
const jws = await this.#flattened.sign(key, options);
|
|
35917
|
+
if (jws.payload === undefined) {
|
|
35918
|
+
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
35919
|
+
}
|
|
35920
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
35921
|
+
}
|
|
35922
|
+
}
|
|
35923
|
+
|
|
35924
|
+
class SignJWT {
|
|
35925
|
+
#protectedHeader;
|
|
35926
|
+
#jwt;
|
|
35927
|
+
constructor(payload = {}) {
|
|
35928
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
35929
|
+
}
|
|
35930
|
+
setIssuer(issuer) {
|
|
35931
|
+
this.#jwt.iss = issuer;
|
|
35932
|
+
return this;
|
|
35933
|
+
}
|
|
35934
|
+
setSubject(subject) {
|
|
35935
|
+
this.#jwt.sub = subject;
|
|
35936
|
+
return this;
|
|
35937
|
+
}
|
|
35938
|
+
setAudience(audience) {
|
|
35939
|
+
this.#jwt.aud = audience;
|
|
35940
|
+
return this;
|
|
35941
|
+
}
|
|
35942
|
+
setJti(jwtId) {
|
|
35943
|
+
this.#jwt.jti = jwtId;
|
|
35944
|
+
return this;
|
|
35945
|
+
}
|
|
35946
|
+
setNotBefore(input) {
|
|
35947
|
+
this.#jwt.nbf = input;
|
|
35948
|
+
return this;
|
|
35949
|
+
}
|
|
35950
|
+
setExpirationTime(input) {
|
|
35951
|
+
this.#jwt.exp = input;
|
|
35952
|
+
return this;
|
|
35953
|
+
}
|
|
35954
|
+
setIssuedAt(input) {
|
|
35955
|
+
this.#jwt.iat = input;
|
|
35956
|
+
return this;
|
|
35957
|
+
}
|
|
35958
|
+
setProtectedHeader(protectedHeader) {
|
|
35959
|
+
this.#protectedHeader = protectedHeader;
|
|
35960
|
+
return this;
|
|
35961
|
+
}
|
|
35962
|
+
async sign(key, options) {
|
|
35963
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
35964
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
35965
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
35966
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
35967
|
+
}
|
|
35968
|
+
return sig.sign(key, options);
|
|
35969
|
+
}
|
|
35970
|
+
}
|
|
35971
|
+
function getKtyFromAlg(alg) {
|
|
35972
|
+
switch (typeof alg === "string" && alg.slice(0, 2)) {
|
|
35973
|
+
case "RS":
|
|
35974
|
+
case "PS":
|
|
35975
|
+
return "RSA";
|
|
35976
|
+
case "ES":
|
|
35977
|
+
return "EC";
|
|
35978
|
+
case "Ed":
|
|
35979
|
+
return "OKP";
|
|
35980
|
+
case "ML":
|
|
35981
|
+
return "AKP";
|
|
35982
|
+
default:
|
|
35983
|
+
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
35984
|
+
}
|
|
35985
|
+
}
|
|
35986
|
+
function isJWKSLike(jwks) {
|
|
35987
|
+
return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
|
|
35988
|
+
}
|
|
35989
|
+
function isJWKLike(key) {
|
|
35990
|
+
return isObject(key);
|
|
35991
|
+
}
|
|
35992
|
+
|
|
35993
|
+
class LocalJWKSet {
|
|
35994
|
+
#jwks;
|
|
35995
|
+
#cached = new WeakMap;
|
|
35996
|
+
constructor(jwks) {
|
|
35997
|
+
if (!isJWKSLike(jwks)) {
|
|
35998
|
+
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
35999
|
+
}
|
|
36000
|
+
this.#jwks = structuredClone(jwks);
|
|
36001
|
+
}
|
|
36002
|
+
jwks() {
|
|
36003
|
+
return this.#jwks;
|
|
36004
|
+
}
|
|
36005
|
+
async getKey(protectedHeader, token2) {
|
|
36006
|
+
const { alg, kid } = { ...protectedHeader, ...token2?.header };
|
|
36007
|
+
const kty = getKtyFromAlg(alg);
|
|
36008
|
+
const candidates = this.#jwks.keys.filter((jwk2) => {
|
|
36009
|
+
let candidate = kty === jwk2.kty;
|
|
36010
|
+
if (candidate && typeof kid === "string") {
|
|
36011
|
+
candidate = kid === jwk2.kid;
|
|
36012
|
+
}
|
|
36013
|
+
if (candidate && (typeof jwk2.alg === "string" || kty === "AKP")) {
|
|
36014
|
+
candidate = alg === jwk2.alg;
|
|
36015
|
+
}
|
|
36016
|
+
if (candidate && typeof jwk2.use === "string") {
|
|
36017
|
+
candidate = jwk2.use === "sig";
|
|
36018
|
+
}
|
|
36019
|
+
if (candidate && Array.isArray(jwk2.key_ops)) {
|
|
36020
|
+
candidate = jwk2.key_ops.includes("verify");
|
|
36021
|
+
}
|
|
36022
|
+
if (candidate) {
|
|
36023
|
+
switch (alg) {
|
|
36024
|
+
case "ES256":
|
|
36025
|
+
candidate = jwk2.crv === "P-256";
|
|
36026
|
+
break;
|
|
36027
|
+
case "ES384":
|
|
36028
|
+
candidate = jwk2.crv === "P-384";
|
|
36029
|
+
break;
|
|
36030
|
+
case "ES512":
|
|
36031
|
+
candidate = jwk2.crv === "P-521";
|
|
36032
|
+
break;
|
|
36033
|
+
case "Ed25519":
|
|
36034
|
+
case "EdDSA":
|
|
36035
|
+
candidate = jwk2.crv === "Ed25519";
|
|
36036
|
+
break;
|
|
36037
|
+
}
|
|
36038
|
+
}
|
|
36039
|
+
return candidate;
|
|
36040
|
+
});
|
|
36041
|
+
const { 0: jwk, length } = candidates;
|
|
36042
|
+
if (length === 0) {
|
|
36043
|
+
throw new JWKSNoMatchingKey;
|
|
36044
|
+
}
|
|
36045
|
+
if (length !== 1) {
|
|
36046
|
+
const error = new JWKSMultipleMatchingKeys;
|
|
36047
|
+
const _cached = this.#cached;
|
|
36048
|
+
error[Symbol.asyncIterator] = async function* () {
|
|
36049
|
+
for (const jwk2 of candidates) {
|
|
36050
|
+
try {
|
|
36051
|
+
yield await importWithAlgCache(_cached, jwk2, alg);
|
|
36052
|
+
} catch {}
|
|
36053
|
+
}
|
|
36054
|
+
};
|
|
36055
|
+
throw error;
|
|
36056
|
+
}
|
|
36057
|
+
return importWithAlgCache(this.#cached, jwk, alg);
|
|
36058
|
+
}
|
|
36059
|
+
}
|
|
36060
|
+
async function importWithAlgCache(cache22, jwk, alg) {
|
|
36061
|
+
const cached = cache22.get(jwk) || cache22.set(jwk, {}).get(jwk);
|
|
36062
|
+
if (cached[alg] === undefined) {
|
|
36063
|
+
const key = await importJWK({ ...jwk, ext: true }, alg);
|
|
36064
|
+
if (key instanceof Uint8Array || key.type !== "public") {
|
|
36065
|
+
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
36066
|
+
}
|
|
36067
|
+
cached[alg] = key;
|
|
36068
|
+
}
|
|
36069
|
+
return cached[alg];
|
|
36070
|
+
}
|
|
36071
|
+
function getModulusLengthOption(options) {
|
|
36072
|
+
const modulusLength = options?.modulusLength ?? 2048;
|
|
36073
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
36074
|
+
throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
36075
|
+
}
|
|
36076
|
+
return modulusLength;
|
|
36077
|
+
}
|
|
36078
|
+
async function generateKeyPair(alg, options) {
|
|
36079
|
+
let algorithm;
|
|
36080
|
+
let keyUsages;
|
|
36081
|
+
switch (alg) {
|
|
36082
|
+
case "PS256":
|
|
36083
|
+
case "PS384":
|
|
36084
|
+
case "PS512":
|
|
36085
|
+
algorithm = {
|
|
36086
|
+
name: "RSA-PSS",
|
|
36087
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
36088
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
36089
|
+
modulusLength: getModulusLengthOption(options)
|
|
36090
|
+
};
|
|
36091
|
+
keyUsages = ["sign", "verify"];
|
|
36092
|
+
break;
|
|
36093
|
+
case "RS256":
|
|
36094
|
+
case "RS384":
|
|
36095
|
+
case "RS512":
|
|
36096
|
+
algorithm = {
|
|
36097
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
36098
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
36099
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
36100
|
+
modulusLength: getModulusLengthOption(options)
|
|
36101
|
+
};
|
|
36102
|
+
keyUsages = ["sign", "verify"];
|
|
36103
|
+
break;
|
|
36104
|
+
case "RSA-OAEP":
|
|
36105
|
+
case "RSA-OAEP-256":
|
|
36106
|
+
case "RSA-OAEP-384":
|
|
36107
|
+
case "RSA-OAEP-512":
|
|
36108
|
+
algorithm = {
|
|
36109
|
+
name: "RSA-OAEP",
|
|
36110
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
|
36111
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
36112
|
+
modulusLength: getModulusLengthOption(options)
|
|
36113
|
+
};
|
|
36114
|
+
keyUsages = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
|
|
36115
|
+
break;
|
|
36116
|
+
case "ES256":
|
|
36117
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
36118
|
+
keyUsages = ["sign", "verify"];
|
|
36119
|
+
break;
|
|
36120
|
+
case "ES384":
|
|
36121
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
36122
|
+
keyUsages = ["sign", "verify"];
|
|
36123
|
+
break;
|
|
36124
|
+
case "ES512":
|
|
36125
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
36126
|
+
keyUsages = ["sign", "verify"];
|
|
36127
|
+
break;
|
|
36128
|
+
case "Ed25519":
|
|
36129
|
+
case "EdDSA": {
|
|
36130
|
+
keyUsages = ["sign", "verify"];
|
|
36131
|
+
algorithm = { name: "Ed25519" };
|
|
36132
|
+
break;
|
|
36133
|
+
}
|
|
36134
|
+
case "ML-DSA-44":
|
|
36135
|
+
case "ML-DSA-65":
|
|
36136
|
+
case "ML-DSA-87": {
|
|
36137
|
+
keyUsages = ["sign", "verify"];
|
|
36138
|
+
algorithm = { name: alg };
|
|
36139
|
+
break;
|
|
36140
|
+
}
|
|
36141
|
+
case "ECDH-ES":
|
|
36142
|
+
case "ECDH-ES+A128KW":
|
|
36143
|
+
case "ECDH-ES+A192KW":
|
|
36144
|
+
case "ECDH-ES+A256KW": {
|
|
36145
|
+
keyUsages = ["deriveBits"];
|
|
36146
|
+
const crv = options?.crv ?? "P-256";
|
|
36147
|
+
switch (crv) {
|
|
36148
|
+
case "P-256":
|
|
36149
|
+
case "P-384":
|
|
36150
|
+
case "P-521": {
|
|
36151
|
+
algorithm = { name: "ECDH", namedCurve: crv };
|
|
36152
|
+
break;
|
|
36153
|
+
}
|
|
36154
|
+
case "X25519":
|
|
36155
|
+
algorithm = { name: "X25519" };
|
|
36156
|
+
break;
|
|
36157
|
+
default:
|
|
36158
|
+
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
36159
|
+
}
|
|
36160
|
+
break;
|
|
36161
|
+
}
|
|
36162
|
+
default:
|
|
36163
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
36164
|
+
}
|
|
36165
|
+
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
36166
|
+
}
|
|
36167
|
+
async function generateKeyPair2() {
|
|
36168
|
+
const { privateKey, publicKey } = await generateKeyPair("RS256", {
|
|
36169
|
+
modulusLength: 2048,
|
|
36170
|
+
extractable: true
|
|
36171
|
+
});
|
|
36172
|
+
return { privateKey, publicKey };
|
|
36173
|
+
}
|
|
36174
|
+
async function createJWKS(publicKey, kid) {
|
|
36175
|
+
const jwk = await exportJWK(publicKey);
|
|
36176
|
+
jwk.kid = kid || "kid-key-1";
|
|
36177
|
+
const jwks = {
|
|
36178
|
+
keys: [jwk]
|
|
36179
|
+
};
|
|
36180
|
+
return jwks;
|
|
36181
|
+
}
|
|
36182
|
+
var generate = async (opts = {}) => {
|
|
36183
|
+
const { privateKey, publicKey } = await generateKeyPair2();
|
|
36184
|
+
const jwks = await createJWKS(publicKey, opts.kid);
|
|
36185
|
+
const privateJWK = await exportJWK(privateKey);
|
|
36186
|
+
const privatePEM = await exportPKCS8(privateKey);
|
|
36187
|
+
const publicPEM = await exportSPKI(publicKey);
|
|
36188
|
+
return {
|
|
36189
|
+
jwks,
|
|
36190
|
+
privateJWK,
|
|
36191
|
+
privatePEM,
|
|
36192
|
+
publicPEM
|
|
36193
|
+
};
|
|
36194
|
+
};
|
|
36195
|
+
var defaultPerf2 = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
36196
|
+
var warned2 = new Set;
|
|
36197
|
+
var PROCESS2 = typeof process === "object" && !!process ? process : {};
|
|
36198
|
+
var emitWarning2 = (msg, type, code, fn) => {
|
|
36199
|
+
typeof PROCESS2.emitWarning === "function" ? PROCESS2.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
|
|
36200
|
+
};
|
|
36201
|
+
var AC2 = globalThis.AbortController;
|
|
36202
|
+
var AS2 = globalThis.AbortSignal;
|
|
36203
|
+
if (typeof AC2 === "undefined") {
|
|
36204
|
+
AS2 = class AbortSignal {
|
|
36205
|
+
onabort;
|
|
36206
|
+
_onabort = [];
|
|
36207
|
+
reason;
|
|
36208
|
+
aborted = false;
|
|
36209
|
+
addEventListener(_, fn) {
|
|
36210
|
+
this._onabort.push(fn);
|
|
36211
|
+
}
|
|
36212
|
+
};
|
|
36213
|
+
AC2 = class AbortController2 {
|
|
36214
|
+
constructor() {
|
|
36215
|
+
warnACPolyfill();
|
|
36216
|
+
}
|
|
36217
|
+
signal = new AS2;
|
|
36218
|
+
abort(reason) {
|
|
36219
|
+
if (this.signal.aborted)
|
|
36220
|
+
return;
|
|
36221
|
+
this.signal.reason = reason;
|
|
36222
|
+
this.signal.aborted = true;
|
|
36223
|
+
for (const fn of this.signal._onabort) {
|
|
36224
|
+
fn(reason);
|
|
36225
|
+
}
|
|
36226
|
+
this.signal.onabort?.(reason);
|
|
36227
|
+
}
|
|
36228
|
+
};
|
|
36229
|
+
let printACPolyfillWarning = PROCESS2.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
|
|
36230
|
+
const warnACPolyfill = () => {
|
|
36231
|
+
if (!printACPolyfillWarning)
|
|
36232
|
+
return;
|
|
36233
|
+
printACPolyfillWarning = false;
|
|
36234
|
+
emitWarning2("AbortController is not defined. If using lru-cache in " + "node 14, load an AbortController polyfill from the " + "`node-abort-controller` package. A minimal polyfill is " + "provided for use by LRUCache.fetch(), but it should not be " + "relied upon in other contexts (eg, passing it to other APIs that " + "use AbortController/AbortSignal might have undesirable effects). " + "You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
|
|
36235
|
+
};
|
|
36236
|
+
}
|
|
36237
|
+
var shouldWarn2 = (code) => !warned2.has(code);
|
|
36238
|
+
var TYPE2 = Symbol("type");
|
|
36239
|
+
var isPosInt2 = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
36240
|
+
var getUintArray2 = (max) => !isPosInt2(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray2 : null;
|
|
36241
|
+
|
|
36242
|
+
class ZeroArray2 extends Array {
|
|
36243
|
+
constructor(size) {
|
|
36244
|
+
super(size);
|
|
36245
|
+
this.fill(0);
|
|
36246
|
+
}
|
|
36247
|
+
}
|
|
36248
|
+
|
|
36249
|
+
class Stack2 {
|
|
36250
|
+
heap;
|
|
36251
|
+
length;
|
|
36252
|
+
static #constructing = false;
|
|
36253
|
+
static create(max) {
|
|
36254
|
+
const HeapCls = getUintArray2(max);
|
|
36255
|
+
if (!HeapCls)
|
|
36256
|
+
return [];
|
|
36257
|
+
Stack2.#constructing = true;
|
|
36258
|
+
const s = new Stack2(max, HeapCls);
|
|
36259
|
+
Stack2.#constructing = false;
|
|
36260
|
+
return s;
|
|
36261
|
+
}
|
|
36262
|
+
constructor(max, HeapCls) {
|
|
36263
|
+
if (!Stack2.#constructing) {
|
|
36264
|
+
throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
36265
|
+
}
|
|
36266
|
+
this.heap = new HeapCls(max);
|
|
36267
|
+
this.length = 0;
|
|
36268
|
+
}
|
|
36269
|
+
push(n) {
|
|
36270
|
+
this.heap[this.length++] = n;
|
|
36271
|
+
}
|
|
36272
|
+
pop() {
|
|
36273
|
+
return this.heap[--this.length];
|
|
36274
|
+
}
|
|
36275
|
+
}
|
|
36276
|
+
|
|
36277
|
+
class LRUCache2 {
|
|
36278
|
+
#max;
|
|
36279
|
+
#maxSize;
|
|
36280
|
+
#dispose;
|
|
36281
|
+
#onInsert;
|
|
36282
|
+
#disposeAfter;
|
|
36283
|
+
#fetchMethod;
|
|
36284
|
+
#memoMethod;
|
|
36285
|
+
#perf;
|
|
36286
|
+
get perf() {
|
|
36287
|
+
return this.#perf;
|
|
36288
|
+
}
|
|
36289
|
+
ttl;
|
|
36290
|
+
ttlResolution;
|
|
36291
|
+
ttlAutopurge;
|
|
36292
|
+
updateAgeOnGet;
|
|
36293
|
+
updateAgeOnHas;
|
|
36294
|
+
allowStale;
|
|
36295
|
+
noDisposeOnSet;
|
|
36296
|
+
noUpdateTTL;
|
|
36297
|
+
maxEntrySize;
|
|
36298
|
+
sizeCalculation;
|
|
36299
|
+
noDeleteOnFetchRejection;
|
|
36300
|
+
noDeleteOnStaleGet;
|
|
36301
|
+
allowStaleOnFetchAbort;
|
|
36302
|
+
allowStaleOnFetchRejection;
|
|
36303
|
+
ignoreFetchAbort;
|
|
36304
|
+
#size;
|
|
36305
|
+
#calculatedSize;
|
|
36306
|
+
#keyMap;
|
|
36307
|
+
#keyList;
|
|
36308
|
+
#valList;
|
|
36309
|
+
#next;
|
|
36310
|
+
#prev;
|
|
36311
|
+
#head;
|
|
36312
|
+
#tail;
|
|
36313
|
+
#free;
|
|
36314
|
+
#disposed;
|
|
36315
|
+
#sizes;
|
|
36316
|
+
#starts;
|
|
36317
|
+
#ttls;
|
|
36318
|
+
#autopurgeTimers;
|
|
36319
|
+
#hasDispose;
|
|
36320
|
+
#hasFetchMethod;
|
|
36321
|
+
#hasDisposeAfter;
|
|
36322
|
+
#hasOnInsert;
|
|
36323
|
+
static unsafeExposeInternals(c) {
|
|
36324
|
+
return {
|
|
36325
|
+
starts: c.#starts,
|
|
36326
|
+
ttls: c.#ttls,
|
|
36327
|
+
autopurgeTimers: c.#autopurgeTimers,
|
|
36328
|
+
sizes: c.#sizes,
|
|
36329
|
+
keyMap: c.#keyMap,
|
|
36330
|
+
keyList: c.#keyList,
|
|
36331
|
+
valList: c.#valList,
|
|
36332
|
+
next: c.#next,
|
|
36333
|
+
prev: c.#prev,
|
|
36334
|
+
get head() {
|
|
36335
|
+
return c.#head;
|
|
36336
|
+
},
|
|
36337
|
+
get tail() {
|
|
36338
|
+
return c.#tail;
|
|
36339
|
+
},
|
|
36340
|
+
free: c.#free,
|
|
36341
|
+
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
36342
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
36343
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
36344
|
+
indexes: (options) => c.#indexes(options),
|
|
36345
|
+
rindexes: (options) => c.#rindexes(options),
|
|
36346
|
+
isStale: (index) => c.#isStale(index)
|
|
36347
|
+
};
|
|
36348
|
+
}
|
|
36349
|
+
get max() {
|
|
36350
|
+
return this.#max;
|
|
36351
|
+
}
|
|
36352
|
+
get maxSize() {
|
|
36353
|
+
return this.#maxSize;
|
|
36354
|
+
}
|
|
36355
|
+
get calculatedSize() {
|
|
36356
|
+
return this.#calculatedSize;
|
|
36357
|
+
}
|
|
36358
|
+
get size() {
|
|
36359
|
+
return this.#size;
|
|
36360
|
+
}
|
|
36361
|
+
get fetchMethod() {
|
|
36362
|
+
return this.#fetchMethod;
|
|
36363
|
+
}
|
|
36364
|
+
get memoMethod() {
|
|
36365
|
+
return this.#memoMethod;
|
|
36366
|
+
}
|
|
36367
|
+
get dispose() {
|
|
36368
|
+
return this.#dispose;
|
|
36369
|
+
}
|
|
36370
|
+
get onInsert() {
|
|
36371
|
+
return this.#onInsert;
|
|
36372
|
+
}
|
|
36373
|
+
get disposeAfter() {
|
|
36374
|
+
return this.#disposeAfter;
|
|
36375
|
+
}
|
|
36376
|
+
constructor(options) {
|
|
36377
|
+
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, onInsert, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort, perf } = options;
|
|
36378
|
+
if (perf !== undefined) {
|
|
36379
|
+
if (typeof perf?.now !== "function") {
|
|
36380
|
+
throw new TypeError("perf option must have a now() method if specified");
|
|
36381
|
+
}
|
|
36382
|
+
}
|
|
36383
|
+
this.#perf = perf ?? defaultPerf2;
|
|
36384
|
+
if (max !== 0 && !isPosInt2(max)) {
|
|
36385
|
+
throw new TypeError("max option must be a nonnegative integer");
|
|
36386
|
+
}
|
|
36387
|
+
const UintArray = max ? getUintArray2(max) : Array;
|
|
36388
|
+
if (!UintArray) {
|
|
36389
|
+
throw new Error("invalid max value: " + max);
|
|
36390
|
+
}
|
|
36391
|
+
this.#max = max;
|
|
36392
|
+
this.#maxSize = maxSize;
|
|
36393
|
+
this.maxEntrySize = maxEntrySize || this.#maxSize;
|
|
36394
|
+
this.sizeCalculation = sizeCalculation;
|
|
36395
|
+
if (this.sizeCalculation) {
|
|
36396
|
+
if (!this.#maxSize && !this.maxEntrySize) {
|
|
36397
|
+
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
36398
|
+
}
|
|
36399
|
+
if (typeof this.sizeCalculation !== "function") {
|
|
36400
|
+
throw new TypeError("sizeCalculation set to non-function");
|
|
36401
|
+
}
|
|
36402
|
+
}
|
|
36403
|
+
if (memoMethod !== undefined && typeof memoMethod !== "function") {
|
|
36404
|
+
throw new TypeError("memoMethod must be a function if defined");
|
|
36405
|
+
}
|
|
36406
|
+
this.#memoMethod = memoMethod;
|
|
36407
|
+
if (fetchMethod !== undefined && typeof fetchMethod !== "function") {
|
|
36408
|
+
throw new TypeError("fetchMethod must be a function if specified");
|
|
36409
|
+
}
|
|
36410
|
+
this.#fetchMethod = fetchMethod;
|
|
36411
|
+
this.#hasFetchMethod = !!fetchMethod;
|
|
36412
|
+
this.#keyMap = new Map;
|
|
36413
|
+
this.#keyList = new Array(max).fill(undefined);
|
|
36414
|
+
this.#valList = new Array(max).fill(undefined);
|
|
36415
|
+
this.#next = new UintArray(max);
|
|
36416
|
+
this.#prev = new UintArray(max);
|
|
36417
|
+
this.#head = 0;
|
|
36418
|
+
this.#tail = 0;
|
|
36419
|
+
this.#free = Stack2.create(max);
|
|
36420
|
+
this.#size = 0;
|
|
36421
|
+
this.#calculatedSize = 0;
|
|
36422
|
+
if (typeof dispose === "function") {
|
|
36423
|
+
this.#dispose = dispose;
|
|
36424
|
+
}
|
|
36425
|
+
if (typeof onInsert === "function") {
|
|
36426
|
+
this.#onInsert = onInsert;
|
|
36427
|
+
}
|
|
36428
|
+
if (typeof disposeAfter === "function") {
|
|
36429
|
+
this.#disposeAfter = disposeAfter;
|
|
36430
|
+
this.#disposed = [];
|
|
36431
|
+
} else {
|
|
36432
|
+
this.#disposeAfter = undefined;
|
|
36433
|
+
this.#disposed = undefined;
|
|
36434
|
+
}
|
|
36435
|
+
this.#hasDispose = !!this.#dispose;
|
|
36436
|
+
this.#hasOnInsert = !!this.#onInsert;
|
|
36437
|
+
this.#hasDisposeAfter = !!this.#disposeAfter;
|
|
36438
|
+
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
36439
|
+
this.noUpdateTTL = !!noUpdateTTL;
|
|
36440
|
+
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
|
36441
|
+
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
|
36442
|
+
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
|
36443
|
+
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
|
36444
|
+
if (this.maxEntrySize !== 0) {
|
|
36445
|
+
if (this.#maxSize !== 0) {
|
|
36446
|
+
if (!isPosInt2(this.#maxSize)) {
|
|
36447
|
+
throw new TypeError("maxSize must be a positive integer if specified");
|
|
36448
|
+
}
|
|
36449
|
+
}
|
|
36450
|
+
if (!isPosInt2(this.maxEntrySize)) {
|
|
36451
|
+
throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
36452
|
+
}
|
|
36453
|
+
this.#initializeSizeTracking();
|
|
36454
|
+
}
|
|
36455
|
+
this.allowStale = !!allowStale;
|
|
36456
|
+
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
|
36457
|
+
this.updateAgeOnGet = !!updateAgeOnGet;
|
|
36458
|
+
this.updateAgeOnHas = !!updateAgeOnHas;
|
|
36459
|
+
this.ttlResolution = isPosInt2(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
|
|
36460
|
+
this.ttlAutopurge = !!ttlAutopurge;
|
|
36461
|
+
this.ttl = ttl || 0;
|
|
36462
|
+
if (this.ttl) {
|
|
36463
|
+
if (!isPosInt2(this.ttl)) {
|
|
36464
|
+
throw new TypeError("ttl must be a positive integer if specified");
|
|
36465
|
+
}
|
|
36466
|
+
this.#initializeTTLTracking();
|
|
36467
|
+
}
|
|
36468
|
+
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
|
|
36469
|
+
throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
36470
|
+
}
|
|
36471
|
+
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
|
36472
|
+
const code = "LRU_CACHE_UNBOUNDED";
|
|
36473
|
+
if (shouldWarn2(code)) {
|
|
36474
|
+
warned2.add(code);
|
|
36475
|
+
const msg = "TTL caching without ttlAutopurge, max, or maxSize can " + "result in unbounded memory consumption.";
|
|
36476
|
+
emitWarning2(msg, "UnboundedCacheWarning", code, LRUCache2);
|
|
36477
|
+
}
|
|
36478
|
+
}
|
|
36479
|
+
}
|
|
36480
|
+
getRemainingTTL(key) {
|
|
36481
|
+
return this.#keyMap.has(key) ? Infinity : 0;
|
|
36482
|
+
}
|
|
36483
|
+
#initializeTTLTracking() {
|
|
36484
|
+
const ttls = new ZeroArray2(this.#max);
|
|
36485
|
+
const starts = new ZeroArray2(this.#max);
|
|
36486
|
+
this.#ttls = ttls;
|
|
36487
|
+
this.#starts = starts;
|
|
36488
|
+
const purgeTimers = this.ttlAutopurge ? new Array(this.#max) : undefined;
|
|
36489
|
+
this.#autopurgeTimers = purgeTimers;
|
|
36490
|
+
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
|
|
36491
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
36492
|
+
ttls[index] = ttl;
|
|
36493
|
+
if (purgeTimers?.[index]) {
|
|
36494
|
+
clearTimeout(purgeTimers[index]);
|
|
36495
|
+
purgeTimers[index] = undefined;
|
|
36496
|
+
}
|
|
36497
|
+
if (ttl !== 0 && purgeTimers) {
|
|
36498
|
+
const t = setTimeout(() => {
|
|
36499
|
+
if (this.#isStale(index)) {
|
|
36500
|
+
this.#delete(this.#keyList[index], "expire");
|
|
36501
|
+
}
|
|
36502
|
+
}, ttl + 1);
|
|
36503
|
+
if (t.unref) {
|
|
36504
|
+
t.unref();
|
|
36505
|
+
}
|
|
36506
|
+
purgeTimers[index] = t;
|
|
36507
|
+
}
|
|
36508
|
+
};
|
|
36509
|
+
this.#updateItemAge = (index) => {
|
|
36510
|
+
starts[index] = ttls[index] !== 0 ? this.#perf.now() : 0;
|
|
36511
|
+
};
|
|
36512
|
+
this.#statusTTL = (status, index) => {
|
|
36513
|
+
if (ttls[index]) {
|
|
36514
|
+
const ttl = ttls[index];
|
|
36515
|
+
const start = starts[index];
|
|
36516
|
+
if (!ttl || !start)
|
|
36517
|
+
return;
|
|
36518
|
+
status.ttl = ttl;
|
|
36519
|
+
status.start = start;
|
|
36520
|
+
status.now = cachedNow || getNow();
|
|
36521
|
+
const age = status.now - start;
|
|
36522
|
+
status.remainingTTL = ttl - age;
|
|
36523
|
+
}
|
|
36524
|
+
};
|
|
36525
|
+
let cachedNow = 0;
|
|
36526
|
+
const getNow = () => {
|
|
36527
|
+
const n = this.#perf.now();
|
|
36528
|
+
if (this.ttlResolution > 0) {
|
|
36529
|
+
cachedNow = n;
|
|
36530
|
+
const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
|
|
36531
|
+
if (t.unref) {
|
|
36532
|
+
t.unref();
|
|
36533
|
+
}
|
|
36534
|
+
}
|
|
36535
|
+
return n;
|
|
36536
|
+
};
|
|
36537
|
+
this.getRemainingTTL = (key) => {
|
|
36538
|
+
const index = this.#keyMap.get(key);
|
|
36539
|
+
if (index === undefined) {
|
|
36540
|
+
return 0;
|
|
36541
|
+
}
|
|
36542
|
+
const ttl = ttls[index];
|
|
36543
|
+
const start = starts[index];
|
|
36544
|
+
if (!ttl || !start) {
|
|
36545
|
+
return Infinity;
|
|
36546
|
+
}
|
|
36547
|
+
const age = (cachedNow || getNow()) - start;
|
|
36548
|
+
return ttl - age;
|
|
36549
|
+
};
|
|
36550
|
+
this.#isStale = (index) => {
|
|
36551
|
+
const s = starts[index];
|
|
36552
|
+
const t = ttls[index];
|
|
36553
|
+
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
36554
|
+
};
|
|
36555
|
+
}
|
|
36556
|
+
#updateItemAge = () => {};
|
|
36557
|
+
#statusTTL = () => {};
|
|
36558
|
+
#setItemTTL = () => {};
|
|
36559
|
+
#isStale = () => false;
|
|
36560
|
+
#initializeSizeTracking() {
|
|
36561
|
+
const sizes = new ZeroArray2(this.#max);
|
|
36562
|
+
this.#calculatedSize = 0;
|
|
36563
|
+
this.#sizes = sizes;
|
|
36564
|
+
this.#removeItemSize = (index) => {
|
|
36565
|
+
this.#calculatedSize -= sizes[index];
|
|
36566
|
+
sizes[index] = 0;
|
|
36567
|
+
};
|
|
36568
|
+
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
36569
|
+
if (this.#isBackgroundFetch(v)) {
|
|
36570
|
+
return 0;
|
|
36571
|
+
}
|
|
36572
|
+
if (!isPosInt2(size)) {
|
|
36573
|
+
if (sizeCalculation) {
|
|
36574
|
+
if (typeof sizeCalculation !== "function") {
|
|
36575
|
+
throw new TypeError("sizeCalculation must be a function");
|
|
36576
|
+
}
|
|
36577
|
+
size = sizeCalculation(v, k);
|
|
36578
|
+
if (!isPosInt2(size)) {
|
|
36579
|
+
throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
36580
|
+
}
|
|
36581
|
+
} else {
|
|
36582
|
+
throw new TypeError("invalid size value (must be positive integer). " + "When maxSize or maxEntrySize is used, sizeCalculation " + "or size must be set.");
|
|
36583
|
+
}
|
|
36584
|
+
}
|
|
36585
|
+
return size;
|
|
36586
|
+
};
|
|
36587
|
+
this.#addItemSize = (index, size, status) => {
|
|
36588
|
+
sizes[index] = size;
|
|
36589
|
+
if (this.#maxSize) {
|
|
36590
|
+
const maxSize = this.#maxSize - sizes[index];
|
|
36591
|
+
while (this.#calculatedSize > maxSize) {
|
|
36592
|
+
this.#evict(true);
|
|
36593
|
+
}
|
|
36594
|
+
}
|
|
36595
|
+
this.#calculatedSize += sizes[index];
|
|
36596
|
+
if (status) {
|
|
36597
|
+
status.entrySize = size;
|
|
36598
|
+
status.totalCalculatedSize = this.#calculatedSize;
|
|
36599
|
+
}
|
|
36600
|
+
};
|
|
36601
|
+
}
|
|
36602
|
+
#removeItemSize = (_i) => {};
|
|
36603
|
+
#addItemSize = (_i, _s, _st) => {};
|
|
36604
|
+
#requireSize = (_k, _v, size, sizeCalculation) => {
|
|
36605
|
+
if (size || sizeCalculation) {
|
|
36606
|
+
throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
36607
|
+
}
|
|
36608
|
+
return 0;
|
|
36609
|
+
};
|
|
36610
|
+
*#indexes({ allowStale = this.allowStale } = {}) {
|
|
36611
|
+
if (this.#size) {
|
|
36612
|
+
for (let i = this.#tail;; ) {
|
|
36613
|
+
if (!this.#isValidIndex(i)) {
|
|
36614
|
+
break;
|
|
36615
|
+
}
|
|
36616
|
+
if (allowStale || !this.#isStale(i)) {
|
|
36617
|
+
yield i;
|
|
36618
|
+
}
|
|
36619
|
+
if (i === this.#head) {
|
|
36620
|
+
break;
|
|
36621
|
+
} else {
|
|
36622
|
+
i = this.#prev[i];
|
|
36623
|
+
}
|
|
36624
|
+
}
|
|
36625
|
+
}
|
|
36626
|
+
}
|
|
36627
|
+
*#rindexes({ allowStale = this.allowStale } = {}) {
|
|
36628
|
+
if (this.#size) {
|
|
36629
|
+
for (let i = this.#head;; ) {
|
|
36630
|
+
if (!this.#isValidIndex(i)) {
|
|
36631
|
+
break;
|
|
36632
|
+
}
|
|
36633
|
+
if (allowStale || !this.#isStale(i)) {
|
|
36634
|
+
yield i;
|
|
36635
|
+
}
|
|
36636
|
+
if (i === this.#tail) {
|
|
36637
|
+
break;
|
|
36638
|
+
} else {
|
|
36639
|
+
i = this.#next[i];
|
|
36640
|
+
}
|
|
36641
|
+
}
|
|
36642
|
+
}
|
|
36643
|
+
}
|
|
36644
|
+
#isValidIndex(index) {
|
|
36645
|
+
return index !== undefined && this.#keyMap.get(this.#keyList[index]) === index;
|
|
36646
|
+
}
|
|
36647
|
+
*entries() {
|
|
36648
|
+
for (const i of this.#indexes()) {
|
|
36649
|
+
if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
36650
|
+
yield [this.#keyList[i], this.#valList[i]];
|
|
36651
|
+
}
|
|
36652
|
+
}
|
|
36653
|
+
}
|
|
36654
|
+
*rentries() {
|
|
36655
|
+
for (const i of this.#rindexes()) {
|
|
36656
|
+
if (this.#valList[i] !== undefined && this.#keyList[i] !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
36657
|
+
yield [this.#keyList[i], this.#valList[i]];
|
|
36658
|
+
}
|
|
36659
|
+
}
|
|
36660
|
+
}
|
|
36661
|
+
*keys() {
|
|
36662
|
+
for (const i of this.#indexes()) {
|
|
36663
|
+
const k = this.#keyList[i];
|
|
36664
|
+
if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
36665
|
+
yield k;
|
|
36666
|
+
}
|
|
36667
|
+
}
|
|
36668
|
+
}
|
|
36669
|
+
*rkeys() {
|
|
36670
|
+
for (const i of this.#rindexes()) {
|
|
36671
|
+
const k = this.#keyList[i];
|
|
36672
|
+
if (k !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
36673
|
+
yield k;
|
|
36674
|
+
}
|
|
36675
|
+
}
|
|
36676
|
+
}
|
|
36677
|
+
*values() {
|
|
36678
|
+
for (const i of this.#indexes()) {
|
|
36679
|
+
const v = this.#valList[i];
|
|
36680
|
+
if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
36681
|
+
yield this.#valList[i];
|
|
36682
|
+
}
|
|
36683
|
+
}
|
|
36684
|
+
}
|
|
36685
|
+
*rvalues() {
|
|
36686
|
+
for (const i of this.#rindexes()) {
|
|
36687
|
+
const v = this.#valList[i];
|
|
36688
|
+
if (v !== undefined && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
36689
|
+
yield this.#valList[i];
|
|
36690
|
+
}
|
|
36691
|
+
}
|
|
36692
|
+
}
|
|
36693
|
+
[Symbol.iterator]() {
|
|
36694
|
+
return this.entries();
|
|
36695
|
+
}
|
|
36696
|
+
[Symbol.toStringTag] = "LRUCache";
|
|
36697
|
+
find(fn, getOptions = {}) {
|
|
36698
|
+
for (const i of this.#indexes()) {
|
|
36699
|
+
const v = this.#valList[i];
|
|
36700
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
36701
|
+
if (value === undefined)
|
|
36702
|
+
continue;
|
|
36703
|
+
if (fn(value, this.#keyList[i], this)) {
|
|
36704
|
+
return this.get(this.#keyList[i], getOptions);
|
|
36705
|
+
}
|
|
36706
|
+
}
|
|
36707
|
+
}
|
|
36708
|
+
forEach(fn, thisp = this) {
|
|
36709
|
+
for (const i of this.#indexes()) {
|
|
36710
|
+
const v = this.#valList[i];
|
|
36711
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
36712
|
+
if (value === undefined)
|
|
36713
|
+
continue;
|
|
36714
|
+
fn.call(thisp, value, this.#keyList[i], this);
|
|
36715
|
+
}
|
|
36716
|
+
}
|
|
36717
|
+
rforEach(fn, thisp = this) {
|
|
36718
|
+
for (const i of this.#rindexes()) {
|
|
36719
|
+
const v = this.#valList[i];
|
|
36720
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
36721
|
+
if (value === undefined)
|
|
36722
|
+
continue;
|
|
36723
|
+
fn.call(thisp, value, this.#keyList[i], this);
|
|
36724
|
+
}
|
|
36725
|
+
}
|
|
36726
|
+
purgeStale() {
|
|
36727
|
+
let deleted = false;
|
|
36728
|
+
for (const i of this.#rindexes({ allowStale: true })) {
|
|
36729
|
+
if (this.#isStale(i)) {
|
|
36730
|
+
this.#delete(this.#keyList[i], "expire");
|
|
36731
|
+
deleted = true;
|
|
36732
|
+
}
|
|
36733
|
+
}
|
|
36734
|
+
return deleted;
|
|
36735
|
+
}
|
|
36736
|
+
info(key) {
|
|
36737
|
+
const i = this.#keyMap.get(key);
|
|
36738
|
+
if (i === undefined)
|
|
36739
|
+
return;
|
|
36740
|
+
const v = this.#valList[i];
|
|
36741
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
36742
|
+
if (value === undefined)
|
|
36743
|
+
return;
|
|
36744
|
+
const entry = { value };
|
|
36745
|
+
if (this.#ttls && this.#starts) {
|
|
36746
|
+
const ttl = this.#ttls[i];
|
|
36747
|
+
const start = this.#starts[i];
|
|
36748
|
+
if (ttl && start) {
|
|
36749
|
+
const remain = ttl - (this.#perf.now() - start);
|
|
36750
|
+
entry.ttl = remain;
|
|
36751
|
+
entry.start = Date.now();
|
|
36752
|
+
}
|
|
36753
|
+
}
|
|
36754
|
+
if (this.#sizes) {
|
|
36755
|
+
entry.size = this.#sizes[i];
|
|
36756
|
+
}
|
|
36757
|
+
return entry;
|
|
36758
|
+
}
|
|
36759
|
+
dump() {
|
|
36760
|
+
const arr = [];
|
|
36761
|
+
for (const i of this.#indexes({ allowStale: true })) {
|
|
36762
|
+
const key = this.#keyList[i];
|
|
36763
|
+
const v = this.#valList[i];
|
|
36764
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
36765
|
+
if (value === undefined || key === undefined)
|
|
36766
|
+
continue;
|
|
36767
|
+
const entry = { value };
|
|
36768
|
+
if (this.#ttls && this.#starts) {
|
|
36769
|
+
entry.ttl = this.#ttls[i];
|
|
36770
|
+
const age = this.#perf.now() - this.#starts[i];
|
|
36771
|
+
entry.start = Math.floor(Date.now() - age);
|
|
36772
|
+
}
|
|
36773
|
+
if (this.#sizes) {
|
|
36774
|
+
entry.size = this.#sizes[i];
|
|
36775
|
+
}
|
|
36776
|
+
arr.unshift([key, entry]);
|
|
36777
|
+
}
|
|
36778
|
+
return arr;
|
|
36779
|
+
}
|
|
36780
|
+
load(arr) {
|
|
36781
|
+
this.clear();
|
|
36782
|
+
for (const [key, entry] of arr) {
|
|
36783
|
+
if (entry.start) {
|
|
36784
|
+
const age = Date.now() - entry.start;
|
|
36785
|
+
entry.start = this.#perf.now() - age;
|
|
36786
|
+
}
|
|
36787
|
+
this.set(key, entry.value, entry);
|
|
36788
|
+
}
|
|
36789
|
+
}
|
|
36790
|
+
set(k, v, setOptions = {}) {
|
|
36791
|
+
if (v === undefined) {
|
|
36792
|
+
this.delete(k);
|
|
36793
|
+
return this;
|
|
36794
|
+
}
|
|
36795
|
+
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
|
|
36796
|
+
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
|
36797
|
+
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
|
|
36798
|
+
if (this.maxEntrySize && size > this.maxEntrySize) {
|
|
36799
|
+
if (status) {
|
|
36800
|
+
status.set = "miss";
|
|
36801
|
+
status.maxEntrySizeExceeded = true;
|
|
36802
|
+
}
|
|
36803
|
+
this.#delete(k, "set");
|
|
36804
|
+
return this;
|
|
36805
|
+
}
|
|
36806
|
+
let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
|
|
36807
|
+
if (index === undefined) {
|
|
36808
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
36809
|
+
this.#keyList[index] = k;
|
|
36810
|
+
this.#valList[index] = v;
|
|
36811
|
+
this.#keyMap.set(k, index);
|
|
36812
|
+
this.#next[this.#tail] = index;
|
|
36813
|
+
this.#prev[index] = this.#tail;
|
|
36814
|
+
this.#tail = index;
|
|
36815
|
+
this.#size++;
|
|
36816
|
+
this.#addItemSize(index, size, status);
|
|
36817
|
+
if (status)
|
|
36818
|
+
status.set = "add";
|
|
36819
|
+
noUpdateTTL = false;
|
|
36820
|
+
if (this.#hasOnInsert) {
|
|
36821
|
+
this.#onInsert?.(v, k, "add");
|
|
36822
|
+
}
|
|
36823
|
+
} else {
|
|
36824
|
+
this.#moveToTail(index);
|
|
36825
|
+
const oldVal = this.#valList[index];
|
|
36826
|
+
if (v !== oldVal) {
|
|
36827
|
+
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
36828
|
+
oldVal.__abortController.abort(new Error("replaced"));
|
|
36829
|
+
const { __staleWhileFetching: s } = oldVal;
|
|
36830
|
+
if (s !== undefined && !noDisposeOnSet) {
|
|
36831
|
+
if (this.#hasDispose) {
|
|
36832
|
+
this.#dispose?.(s, k, "set");
|
|
36833
|
+
}
|
|
36834
|
+
if (this.#hasDisposeAfter) {
|
|
36835
|
+
this.#disposed?.push([s, k, "set"]);
|
|
36836
|
+
}
|
|
36837
|
+
}
|
|
36838
|
+
} else if (!noDisposeOnSet) {
|
|
36839
|
+
if (this.#hasDispose) {
|
|
36840
|
+
this.#dispose?.(oldVal, k, "set");
|
|
36841
|
+
}
|
|
36842
|
+
if (this.#hasDisposeAfter) {
|
|
36843
|
+
this.#disposed?.push([oldVal, k, "set"]);
|
|
36844
|
+
}
|
|
36845
|
+
}
|
|
36846
|
+
this.#removeItemSize(index);
|
|
36847
|
+
this.#addItemSize(index, size, status);
|
|
36848
|
+
this.#valList[index] = v;
|
|
36849
|
+
if (status) {
|
|
36850
|
+
status.set = "replace";
|
|
36851
|
+
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
36852
|
+
if (oldValue !== undefined)
|
|
36853
|
+
status.oldValue = oldValue;
|
|
36854
|
+
}
|
|
36855
|
+
} else if (status) {
|
|
36856
|
+
status.set = "update";
|
|
36857
|
+
}
|
|
36858
|
+
if (this.#hasOnInsert) {
|
|
36859
|
+
this.onInsert?.(v, k, v === oldVal ? "update" : "replace");
|
|
36860
|
+
}
|
|
36861
|
+
}
|
|
36862
|
+
if (ttl !== 0 && !this.#ttls) {
|
|
36863
|
+
this.#initializeTTLTracking();
|
|
36864
|
+
}
|
|
36865
|
+
if (this.#ttls) {
|
|
36866
|
+
if (!noUpdateTTL) {
|
|
36867
|
+
this.#setItemTTL(index, ttl, start);
|
|
36868
|
+
}
|
|
36869
|
+
if (status)
|
|
36870
|
+
this.#statusTTL(status, index);
|
|
36871
|
+
}
|
|
36872
|
+
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
36873
|
+
const dt = this.#disposed;
|
|
36874
|
+
let task;
|
|
36875
|
+
while (task = dt?.shift()) {
|
|
36876
|
+
this.#disposeAfter?.(...task);
|
|
36877
|
+
}
|
|
36878
|
+
}
|
|
36879
|
+
return this;
|
|
36880
|
+
}
|
|
36881
|
+
pop() {
|
|
36882
|
+
try {
|
|
36883
|
+
while (this.#size) {
|
|
36884
|
+
const val = this.#valList[this.#head];
|
|
36885
|
+
this.#evict(true);
|
|
36886
|
+
if (this.#isBackgroundFetch(val)) {
|
|
36887
|
+
if (val.__staleWhileFetching) {
|
|
36888
|
+
return val.__staleWhileFetching;
|
|
36889
|
+
}
|
|
36890
|
+
} else if (val !== undefined) {
|
|
36891
|
+
return val;
|
|
36892
|
+
}
|
|
36893
|
+
}
|
|
36894
|
+
} finally {
|
|
36895
|
+
if (this.#hasDisposeAfter && this.#disposed) {
|
|
36896
|
+
const dt = this.#disposed;
|
|
36897
|
+
let task;
|
|
36898
|
+
while (task = dt?.shift()) {
|
|
36899
|
+
this.#disposeAfter?.(...task);
|
|
36900
|
+
}
|
|
36901
|
+
}
|
|
36902
|
+
}
|
|
36903
|
+
}
|
|
36904
|
+
#evict(free) {
|
|
36905
|
+
const head = this.#head;
|
|
36906
|
+
const k = this.#keyList[head];
|
|
36907
|
+
const v = this.#valList[head];
|
|
36908
|
+
if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
|
|
36909
|
+
v.__abortController.abort(new Error("evicted"));
|
|
36910
|
+
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
36911
|
+
if (this.#hasDispose) {
|
|
36912
|
+
this.#dispose?.(v, k, "evict");
|
|
36913
|
+
}
|
|
36914
|
+
if (this.#hasDisposeAfter) {
|
|
36915
|
+
this.#disposed?.push([v, k, "evict"]);
|
|
36916
|
+
}
|
|
36917
|
+
}
|
|
36918
|
+
this.#removeItemSize(head);
|
|
36919
|
+
if (this.#autopurgeTimers?.[head]) {
|
|
36920
|
+
clearTimeout(this.#autopurgeTimers[head]);
|
|
36921
|
+
this.#autopurgeTimers[head] = undefined;
|
|
36922
|
+
}
|
|
36923
|
+
if (free) {
|
|
36924
|
+
this.#keyList[head] = undefined;
|
|
36925
|
+
this.#valList[head] = undefined;
|
|
36926
|
+
this.#free.push(head);
|
|
36927
|
+
}
|
|
36928
|
+
if (this.#size === 1) {
|
|
36929
|
+
this.#head = this.#tail = 0;
|
|
36930
|
+
this.#free.length = 0;
|
|
36931
|
+
} else {
|
|
36932
|
+
this.#head = this.#next[head];
|
|
36933
|
+
}
|
|
36934
|
+
this.#keyMap.delete(k);
|
|
36935
|
+
this.#size--;
|
|
36936
|
+
return head;
|
|
36937
|
+
}
|
|
36938
|
+
has(k, hasOptions = {}) {
|
|
36939
|
+
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
36940
|
+
const index = this.#keyMap.get(k);
|
|
36941
|
+
if (index !== undefined) {
|
|
36942
|
+
const v = this.#valList[index];
|
|
36943
|
+
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === undefined) {
|
|
36944
|
+
return false;
|
|
36945
|
+
}
|
|
36946
|
+
if (!this.#isStale(index)) {
|
|
36947
|
+
if (updateAgeOnHas) {
|
|
36948
|
+
this.#updateItemAge(index);
|
|
36949
|
+
}
|
|
36950
|
+
if (status) {
|
|
36951
|
+
status.has = "hit";
|
|
36952
|
+
this.#statusTTL(status, index);
|
|
36953
|
+
}
|
|
36954
|
+
return true;
|
|
36955
|
+
} else if (status) {
|
|
36956
|
+
status.has = "stale";
|
|
36957
|
+
this.#statusTTL(status, index);
|
|
36958
|
+
}
|
|
36959
|
+
} else if (status) {
|
|
36960
|
+
status.has = "miss";
|
|
36961
|
+
}
|
|
36962
|
+
return false;
|
|
36963
|
+
}
|
|
36964
|
+
peek(k, peekOptions = {}) {
|
|
36965
|
+
const { allowStale = this.allowStale } = peekOptions;
|
|
36966
|
+
const index = this.#keyMap.get(k);
|
|
36967
|
+
if (index === undefined || !allowStale && this.#isStale(index)) {
|
|
36968
|
+
return;
|
|
36969
|
+
}
|
|
36970
|
+
const v = this.#valList[index];
|
|
36971
|
+
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
36972
|
+
}
|
|
36973
|
+
#backgroundFetch(k, index, options, context) {
|
|
36974
|
+
const v = index === undefined ? undefined : this.#valList[index];
|
|
36975
|
+
if (this.#isBackgroundFetch(v)) {
|
|
36976
|
+
return v;
|
|
36977
|
+
}
|
|
36978
|
+
const ac = new AC2;
|
|
34072
36979
|
const { signal } = options;
|
|
34073
36980
|
signal?.addEventListener("abort", () => ac.abort(signal.reason), {
|
|
34074
36981
|
signal: ac.signal
|
|
@@ -34175,7 +37082,7 @@ class LRUCache {
|
|
|
34175
37082
|
if (!this.#hasFetchMethod)
|
|
34176
37083
|
return false;
|
|
34177
37084
|
const b = p;
|
|
34178
|
-
return !!b && b instanceof Promise && b.hasOwnProperty("__staleWhileFetching") && b.__abortController instanceof
|
|
37085
|
+
return !!b && b instanceof Promise && b.hasOwnProperty("__staleWhileFetching") && b.__abortController instanceof AC2;
|
|
34179
37086
|
}
|
|
34180
37087
|
async fetch(k, fetchOptions = {}) {
|
|
34181
37088
|
const {
|
|
@@ -34442,312 +37349,62 @@ class LRUCache {
|
|
|
34442
37349
|
}
|
|
34443
37350
|
}
|
|
34444
37351
|
|
|
34445
|
-
// src/
|
|
34446
|
-
|
|
34447
|
-
|
|
34448
|
-
|
|
34449
|
-
|
|
34450
|
-
|
|
34451
|
-
|
|
34452
|
-
|
|
34453
|
-
},
|
|
34454
|
-
getItem: (key) => {
|
|
34455
|
-
return cache.get(key);
|
|
34456
|
-
},
|
|
34457
|
-
removeItem: (key) => {
|
|
34458
|
-
cache.delete(key);
|
|
34459
|
-
},
|
|
34460
|
-
clear: () => {
|
|
34461
|
-
cache.clear();
|
|
34462
|
-
}
|
|
34463
|
-
};
|
|
34464
|
-
|
|
34465
|
-
// src/ai/ai.ts
|
|
34466
|
-
var app2 = new App({ token: storage.getItem("token") || "", storage: sessionStorage2 });
|
|
34467
|
-
|
|
34468
|
-
// src/ai/routes/cmd-run.ts
|
|
34469
|
-
import { execSync as execSync2 } from "node:child_process";
|
|
34470
|
-
var promptTemplate = `# CMD 结果判断器
|
|
34471
|
-
|
|
34472
|
-
分析上一条 CMD 命令的执行结果,判断是否需要执行下一条命令。
|
|
34473
|
-
|
|
34474
|
-
- 若结果中隐含或明确指示需继续执行 → 返回:\`{"cmd": "推断出的下一条命令", "type": "cmd"}\`
|
|
34475
|
-
- 若无后续操作,甚至上一次执行的返回为空或者成功 → 返回:\`{"type": "none"}\`
|
|
34476
|
-
|
|
34477
|
-
1. 仅输出合法 JSON,无任何额外文本。
|
|
34478
|
-
2. \`cmd\` 必须从执行结果中合理推断得出,非预设或猜测。
|
|
34479
|
-
3. 禁止解释、注释、换行或格式错误。`;
|
|
34480
|
-
app2.router.route({
|
|
34481
|
-
path: "cmd-run",
|
|
34482
|
-
description: "执行 CMD 命令并判断下一步操作, 参数是 cmd 字符串"
|
|
34483
|
-
}).define(async (ctx) => {
|
|
34484
|
-
const cmd = ctx.query.cmd || "";
|
|
34485
|
-
if (!cmd) {
|
|
34486
|
-
ctx.throw(400, "cmd is required");
|
|
34487
|
-
}
|
|
34488
|
-
let result = "";
|
|
34489
|
-
ctx.state.steps = ctx.state?.steps || [];
|
|
34490
|
-
try {
|
|
34491
|
-
logger.info("执行命令:", cmd);
|
|
34492
|
-
result = execSync2(cmd, { encoding: "utf-8" });
|
|
34493
|
-
ctx.state.steps.push({ cmd, result });
|
|
34494
|
-
logger.info(result);
|
|
34495
|
-
} catch (error) {
|
|
34496
|
-
result = error.message || "";
|
|
34497
|
-
ctx.state.steps.push({ cmd, result, error: true });
|
|
34498
|
-
ctx.body = {
|
|
34499
|
-
steps: ctx.state.steps
|
|
34500
|
-
};
|
|
34501
|
-
return;
|
|
34502
|
-
}
|
|
34503
|
-
await app2.loadAI();
|
|
34504
|
-
const prompt = `${promptTemplate}
|
|
34505
|
-
上一条命令:
|
|
34506
|
-
${cmd}
|
|
34507
|
-
执行结果:
|
|
34508
|
-
${result}
|
|
34509
|
-
`;
|
|
34510
|
-
const response = await app2.ai.question(prompt);
|
|
34511
|
-
const msg = app2.ai.utils.extractJsonFromMarkdown(app2.ai.responseText);
|
|
34512
|
-
try {
|
|
34513
|
-
logger.debug("AI Prompt", prompt);
|
|
34514
|
-
logger.debug("AI 分析结果:", msg);
|
|
34515
|
-
const { cmd: cmd2, type } = msg;
|
|
34516
|
-
if (type === "cmd" && cmd2) {
|
|
34517
|
-
await app2.router.call({ path: "cmd-run", payload: { cmd: cmd2 } }, { state: ctx.state });
|
|
34518
|
-
} else {
|
|
34519
|
-
logger.info("无后续命令,结束执行");
|
|
34520
|
-
ctx.state.steps.push({ type: "none" });
|
|
34521
|
-
}
|
|
34522
|
-
} catch (error) {
|
|
34523
|
-
result = "执行错误,无法解析返回结果为合法 JSON" + app2.ai.responseText;
|
|
34524
|
-
logger.error(result);
|
|
34525
|
-
ctx.state.steps.push({ cmd, result, parseError: true });
|
|
34526
|
-
}
|
|
34527
|
-
ctx.body = {
|
|
34528
|
-
steps: ctx.state.steps
|
|
34529
|
-
};
|
|
34530
|
-
}).addTo(app2.router);
|
|
34531
|
-
|
|
34532
|
-
// src/command/ai.ts
|
|
34533
|
-
var aiCmd = new Command("ai").description("AI 相关命令").action(async (opts) => {});
|
|
34534
|
-
var runCmd = async (cmd) => {
|
|
34535
|
-
const res = await app2.router.call({ path: "cmd-run", payload: { cmd } });
|
|
34536
|
-
const { body } = res;
|
|
34537
|
-
const steps = body?.steps || [];
|
|
34538
|
-
for (const step of steps) {
|
|
34539
|
-
logger.debug(chalk2.blue(`
|
|
34540
|
-
==== 步骤: ${step.cmd || "结束"} ====`));
|
|
34541
|
-
logger.debug(step.result || "No result");
|
|
34542
|
-
}
|
|
34543
|
-
};
|
|
34544
|
-
var aiRun = new Command("run").description("执行 AI 命令").option("-c, --cmd <cmd>", "要执行的 CMD 命令").action(async (opts) => {
|
|
34545
|
-
if (opts.cmd) {
|
|
34546
|
-
await runCmd(opts.cmd);
|
|
34547
|
-
} else {
|
|
34548
|
-
console.log("请提供要执行的 CMD 命令");
|
|
34549
|
-
}
|
|
34550
|
-
});
|
|
34551
|
-
var aiRunDeploy = new Command("deploy").description("部署 AI 后端应用").action(async (opts) => {
|
|
34552
|
-
const cmd = "ev pack -p -u";
|
|
34553
|
-
const res = await runCmd(cmd);
|
|
34554
|
-
});
|
|
34555
|
-
aiCmd.addCommand(aiRun);
|
|
34556
|
-
aiCmd.addCommand(aiRunDeploy);
|
|
34557
|
-
program.addCommand(aiCmd);
|
|
34558
|
-
|
|
34559
|
-
// src/command/claude/cc.ts
|
|
34560
|
-
import path14 from "node:path";
|
|
34561
|
-
import os4 from "node:os";
|
|
34562
|
-
import fs18 from "node:fs";
|
|
34563
|
-
var MODELS = ["minimax", "glm", "volcengine", "bailian"];
|
|
34564
|
-
var changeMinimax = (token2) => {
|
|
34565
|
-
const auth_token = token2 || useKey("MINIMAX_API_KEY");
|
|
34566
|
-
return {
|
|
34567
|
-
env: {
|
|
34568
|
-
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34569
|
-
ANTHROPIC_BASE_URL: "https://api.minimaxi.com/anthropic",
|
|
34570
|
-
ANTHROPIC_DEFAULT_HAIKU_MODEL: "MiniMax-M2.1",
|
|
34571
|
-
ANTHROPIC_DEFAULT_OPUS_MODEL: "MiniMax-M2.1",
|
|
34572
|
-
ANTHROPIC_DEFAULT_SONNET_MODEL: "MiniMax-M2.1",
|
|
34573
|
-
ANTHROPIC_MODEL: "MiniMax-M2.1",
|
|
34574
|
-
API_TIMEOUT_MS: "3000000",
|
|
34575
|
-
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: 1
|
|
34576
|
-
}
|
|
34577
|
-
};
|
|
34578
|
-
};
|
|
34579
|
-
var changeGLM = (token2) => {
|
|
34580
|
-
const auth_token = token2 || useKey("ZHIPU_API_KEY");
|
|
34581
|
-
return {
|
|
34582
|
-
env: {
|
|
34583
|
-
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34584
|
-
ANTHROPIC_BASE_URL: "https://open.bigmodel.cn/api/anthropic",
|
|
34585
|
-
ANTHROPIC_DEFAULT_HAIKU_MODEL: "glm-4.7",
|
|
34586
|
-
ANTHROPIC_DEFAULT_OPUS_MODEL: "glm-4.7",
|
|
34587
|
-
ANTHROPIC_DEFAULT_SONNET_MODEL: "glm-4.7",
|
|
34588
|
-
ANTHROPIC_MODEL: "glm-4.7"
|
|
34589
|
-
}
|
|
34590
|
-
};
|
|
34591
|
-
};
|
|
34592
|
-
var changeVolcengine = (token2) => {
|
|
34593
|
-
const auth_token = token2 || useKey("VOLCENGINE_API_KEY");
|
|
37352
|
+
// src/command/jwks.ts
|
|
37353
|
+
import fs19 from "node:fs";
|
|
37354
|
+
import path15 from "node:path";
|
|
37355
|
+
var getPath = async (dir) => {
|
|
37356
|
+
const JWKS_PATH = path15.join(dir, "jwks.json");
|
|
37357
|
+
const PRIVATE_JWK_PATH = path15.join(dir, "privateKey.json");
|
|
37358
|
+
const PRIVATE_KEY_PATH = path15.join(dir, "privateKey.txt");
|
|
37359
|
+
const PUBLIC_KEY_PATH = path15.join(dir, "publicKey.txt");
|
|
34594
37360
|
return {
|
|
34595
|
-
|
|
34596
|
-
|
|
34597
|
-
|
|
34598
|
-
|
|
34599
|
-
ANTHROPIC_DEFAULT_OPUS_MODEL: "ark-code-latest",
|
|
34600
|
-
ANTHROPIC_DEFAULT_SONNET_MODEL: "ark-code-latest",
|
|
34601
|
-
ANTHROPIC_MODEL: "ark-code-latest",
|
|
34602
|
-
API_TIMEOUT_MS: "3000000"
|
|
34603
|
-
}
|
|
34604
|
-
};
|
|
34605
|
-
};
|
|
34606
|
-
var changeBailian = (token2) => {
|
|
34607
|
-
const auth_token = token2 || useKey("BAILIAN_API_KEY");
|
|
34608
|
-
return {
|
|
34609
|
-
env: {
|
|
34610
|
-
ANTHROPIC_AUTH_TOKEN: auth_token,
|
|
34611
|
-
ANTHROPIC_BASE_URL: "https://coding.dashscope.aliyuncs.com/apps/anthropic",
|
|
34612
|
-
ANTHROPIC_DEFAULT_HAIKU_MODEL: "qwen3-coder-plus",
|
|
34613
|
-
ANTHROPIC_DEFAULT_OPUS_MODEL: "qwen3-coder-plus",
|
|
34614
|
-
ANTHROPIC_DEFAULT_SONNET_MODEL: "qwen3-coder-plus",
|
|
34615
|
-
ANTHROPIC_MODEL: "qwen3-coder-plus"
|
|
34616
|
-
},
|
|
34617
|
-
includeCoAuthoredBy: false
|
|
37361
|
+
JWKS_PATH,
|
|
37362
|
+
PRIVATE_JWK_PATH,
|
|
37363
|
+
PRIVATE_KEY_PATH,
|
|
37364
|
+
PUBLIC_KEY_PATH
|
|
34618
37365
|
};
|
|
34619
37366
|
};
|
|
34620
|
-
var
|
|
34621
|
-
|
|
34622
|
-
const
|
|
34623
|
-
|
|
34624
|
-
|
|
34625
|
-
|
|
34626
|
-
|
|
34627
|
-
|
|
34628
|
-
|
|
34629
|
-
|
|
34630
|
-
|
|
34631
|
-
|
|
34632
|
-
|
|
34633
|
-
|
|
34634
|
-
|
|
34635
|
-
|
|
34636
|
-
|
|
34637
|
-
};
|
|
34638
|
-
|
|
34639
|
-
|
|
34640
|
-
|
|
34641
|
-
|
|
34642
|
-
|
|
34643
|
-
};
|
|
34644
|
-
var readOrCreateConfig = (configPath2) => {
|
|
34645
|
-
if (fs18.existsSync(configPath2)) {
|
|
34646
|
-
const content = fs18.readFileSync(configPath2, "utf-8");
|
|
34647
|
-
try {
|
|
34648
|
-
return JSON.parse(content);
|
|
34649
|
-
} catch {
|
|
34650
|
-
return {};
|
|
37367
|
+
var jwksCmd = new Command("jwks").description("JWKS 相关命令").action(async (opts) => {});
|
|
37368
|
+
var jwksGenerate = new Command("generate").alias("gen").option("-d , --dir <dir>", "指定保存目录,默认当前目录下 jwt 文件夹", "jwt").description("生成 JWKS 密钥对").action(async (opts) => {
|
|
37369
|
+
const dir = path15.isAbsolute(opts.dir) ? opts.dir : path15.join(process.cwd(), opts.dir);
|
|
37370
|
+
if (!fs19.existsSync(dir)) {
|
|
37371
|
+
fs19.mkdirSync(dir, { recursive: true });
|
|
37372
|
+
}
|
|
37373
|
+
const { JWKS_PATH, PRIVATE_JWK_PATH, PRIVATE_KEY_PATH, PUBLIC_KEY_PATH } = await getPath(dir);
|
|
37374
|
+
const { jwks, privateJWK, privatePEM, publicPEM } = await generate();
|
|
37375
|
+
fs19.writeFileSync(PUBLIC_KEY_PATH, publicPEM);
|
|
37376
|
+
fs19.writeFileSync(PRIVATE_KEY_PATH, privatePEM);
|
|
37377
|
+
fs19.writeFileSync(PRIVATE_JWK_PATH, JSON.stringify(privateJWK, null, 2));
|
|
37378
|
+
fs19.writeFileSync(JWKS_PATH, JSON.stringify(jwks, null, 2));
|
|
37379
|
+
console.log(`Keys have been saved to directory: ${dir}`);
|
|
37380
|
+
});
|
|
37381
|
+
jwksCmd.addCommand(jwksGenerate);
|
|
37382
|
+
var getJWKS = new Command("get").description("获取 JWKS 内容").option("-d , --dir <dir>", "指定 JWKS 所在目录,默认当前目录下 jwt 文件夹", "jwt").option("-t, --type <type>", "指定获取类型,jwks 或 privateJWK", "jwks").action(async (opts) => {
|
|
37383
|
+
const dir = path15.isAbsolute(opts.dir) ? opts.dir : path15.join(process.cwd(), opts.dir);
|
|
37384
|
+
const { JWKS_PATH, PRIVATE_JWK_PATH } = await getPath(dir);
|
|
37385
|
+
const type = opts.type || "jwks";
|
|
37386
|
+
if (type !== "jwks") {
|
|
37387
|
+
if (!fs19.existsSync(PRIVATE_JWK_PATH)) {
|
|
37388
|
+
console.error(`Private JWK file not found in directory: ${dir}`);
|
|
37389
|
+
return;
|
|
34651
37390
|
}
|
|
34652
|
-
|
|
34653
|
-
|
|
34654
|
-
|
|
34655
|
-
|
|
34656
|
-
fs18.writeFileSync(configPath2, JSON.stringify(config2, null, 2));
|
|
34657
|
-
};
|
|
34658
|
-
var command11 = new Command("cc").description("切换claude code模型,支持GLM4.7、Minimax和豆包").option("-m, --models <model:string>", `选择模型: ${MODELS.join(" | ")}`).action(async (options) => {
|
|
34659
|
-
const configPath2 = path14.join(os4.homedir(), ".claude/settings.json");
|
|
34660
|
-
const config2 = readOrCreateConfig(configPath2);
|
|
34661
|
-
let selectedModel;
|
|
34662
|
-
if (options.models && MODELS.includes(options.models)) {
|
|
34663
|
-
selectedModel = options.models;
|
|
34664
|
-
} else {
|
|
34665
|
-
selectedModel = await dist_default4({
|
|
34666
|
-
message: "请选择模型:",
|
|
34667
|
-
choices: MODELS
|
|
34668
|
-
});
|
|
34669
|
-
}
|
|
34670
|
-
const updateConfig = modelConfig[selectedModel]();
|
|
34671
|
-
Object.assign(config2, updateConfig);
|
|
34672
|
-
saveConfig(configPath2, config2);
|
|
34673
|
-
changeNoCheck();
|
|
34674
|
-
console.log(`已切换到模型: ${chalk2.green(selectedModel)}`);
|
|
34675
|
-
console.log(`配置已保存到: ${configPath2}`);
|
|
34676
|
-
});
|
|
34677
|
-
program.addCommand(command11);
|
|
34678
|
-
|
|
34679
|
-
// src/command/docker.ts
|
|
34680
|
-
import { spawn as spawn4 } from "node:child_process";
|
|
34681
|
-
var dockerCommand = new Command("docker").description("Docker 相关指令").action(async () => {
|
|
34682
|
-
console.log(chalk2.green("Docker command executed"));
|
|
34683
|
-
});
|
|
34684
|
-
var login = new Command("login").description("登录 Docker 镜像仓库").option("-r , --registry <registry>", "Docker 镜像仓库地址", "default").action(async (options) => {
|
|
34685
|
-
const { registry = "default" } = options;
|
|
34686
|
-
let DOCKER_USERNAME = useKey("DOCKER_USERNAME");
|
|
34687
|
-
let DOCKER_PASSWORD = useKey("DOCKER_PASSWORD");
|
|
34688
|
-
let DOCKER_REGISTRY = useKey("DOCKER_REGISTRY");
|
|
34689
|
-
if (registry !== "default") {
|
|
34690
|
-
DOCKER_USERNAME = "cnb";
|
|
34691
|
-
DOCKER_PASSWORD = useKey("CNB_TOKEN");
|
|
34692
|
-
DOCKER_REGISTRY = "docker.cnb.cool";
|
|
34693
|
-
}
|
|
34694
|
-
if (!DOCKER_USERNAME || !DOCKER_PASSWORD) {
|
|
34695
|
-
console.log(chalk2.red("请先配置 DOCKER_USERNAME 和 DOCKER_PASSWORD"));
|
|
37391
|
+
const privateJWKContent = fs19.readFileSync(PRIVATE_JWK_PATH, "utf-8");
|
|
37392
|
+
console.log(`Private JWK:
|
|
37393
|
+
`);
|
|
37394
|
+
console.log(privateJWKContent);
|
|
34696
37395
|
return;
|
|
34697
37396
|
}
|
|
34698
|
-
|
|
34699
|
-
|
|
34700
|
-
"--username",
|
|
34701
|
-
DOCKER_USERNAME,
|
|
34702
|
-
DOCKER_REGISTRY,
|
|
34703
|
-
"--password-stdin"
|
|
34704
|
-
], {
|
|
34705
|
-
stdio: ["pipe", "inherit", "inherit"]
|
|
34706
|
-
});
|
|
34707
|
-
loginProcess.stdin.write(DOCKER_PASSWORD + `
|
|
34708
|
-
`);
|
|
34709
|
-
loginProcess.stdin.end();
|
|
34710
|
-
loginProcess.on("close", (code) => {
|
|
34711
|
-
if (code === 0) {
|
|
34712
|
-
console.log(chalk2.green("登录成功"));
|
|
34713
|
-
} else {
|
|
34714
|
-
console.log(chalk2.red(`登录失败,退出码:${code}`));
|
|
34715
|
-
}
|
|
34716
|
-
});
|
|
34717
|
-
});
|
|
34718
|
-
dockerCommand.addCommand(login);
|
|
34719
|
-
var helmLogin = new Command("helm").description("Helm 登录镜像仓库").action(async () => {});
|
|
34720
|
-
var helmLoginCommand = new Command("login").description("登录 Helm 镜像仓库").action(async () => {
|
|
34721
|
-
let DOCKER_USERNAME = "cnb";
|
|
34722
|
-
let DOCKER_PASSWORD = useKey("CNB_TOKEN");
|
|
34723
|
-
if (!DOCKER_PASSWORD) {
|
|
34724
|
-
console.log(chalk2.red("请先配置 CNB_TOKEN"));
|
|
37397
|
+
if (!fs19.existsSync(JWKS_PATH)) {
|
|
37398
|
+
console.error(`JWKS file not found in directory: ${dir}`);
|
|
34725
37399
|
return;
|
|
34726
37400
|
}
|
|
34727
|
-
const
|
|
34728
|
-
|
|
34729
|
-
"login",
|
|
34730
|
-
"--username",
|
|
34731
|
-
DOCKER_USERNAME,
|
|
34732
|
-
"--password-stdin",
|
|
34733
|
-
"helm.cnb.cool"
|
|
34734
|
-
], {
|
|
34735
|
-
stdio: ["pipe", "inherit", "inherit"]
|
|
34736
|
-
});
|
|
34737
|
-
helmLoginProcess.stdin.write(DOCKER_PASSWORD + `
|
|
37401
|
+
const jwksContent = fs19.readFileSync(JWKS_PATH, "utf-8");
|
|
37402
|
+
console.log(`PublicJWKS:
|
|
34738
37403
|
`);
|
|
34739
|
-
|
|
34740
|
-
helmLoginProcess.on("close", (code) => {
|
|
34741
|
-
if (code === 0) {
|
|
34742
|
-
console.log(chalk2.green("Helm 登录成功"));
|
|
34743
|
-
} else {
|
|
34744
|
-
console.log(chalk2.red(`Helm 登录失败,退出码:${code}`));
|
|
34745
|
-
}
|
|
34746
|
-
});
|
|
37404
|
+
console.log(jwksContent);
|
|
34747
37405
|
});
|
|
34748
|
-
|
|
34749
|
-
program.addCommand(
|
|
34750
|
-
program.addCommand(helmLogin);
|
|
37406
|
+
jwksCmd.addCommand(getJWKS);
|
|
37407
|
+
program.addCommand(jwksCmd);
|
|
34751
37408
|
|
|
34752
37409
|
// src/index.ts
|
|
34753
37410
|
var runParser = async (argv) => {
|