@happyvertical/smrt-app-mcp 0.51.37 → 0.51.38
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/AGENTS.md +3 -2
- package/README.md +113 -3
- package/dist/auth.d.ts +53 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +815 -0
- package/dist/auth.js.map +1 -0
- package/dist/chunks/protocol-Ce0U_XSp.js +184 -0
- package/dist/chunks/protocol-Ce0U_XSp.js.map +1 -0
- package/dist/continuation.d.ts +30 -0
- package/dist/continuation.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7268 -44
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/protocol.d.ts +12 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/resources.d.ts +56 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/server.d.ts +19 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +8 -5
- package/dist/sveltekit.d.ts +3 -0
- package/dist/sveltekit.d.ts.map +1 -1
- package/dist/sveltekit.js +6 -2
- package/dist/sveltekit.js.map +1 -1
- package/dist/tools.d.ts +11 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/workflow-tools.d.ts +41 -0
- package/dist/workflow-tools.d.ts.map +1 -0
- package/package.json +10 -4
- package/dist/chunks/protocol-DoieND6v.js +0 -99
- package/dist/chunks/protocol-DoieND6v.js.map +0 -1
package/dist/auth.js
ADDED
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
2
|
+
var encoder = new TextEncoder(), decoder = new TextDecoder(), strictDecoder = new TextDecoder("utf-8", { fatal: !0 });
|
|
3
|
+
function concat(...buffers) {
|
|
4
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0), buf = new Uint8Array(size);
|
|
5
|
+
let i = 0;
|
|
6
|
+
for (const buffer of buffers) buf.set(buffer, i), i += buffer.length;
|
|
7
|
+
return buf;
|
|
8
|
+
}
|
|
9
|
+
var NON_ASCII = /[^\x00-\x7f]/;
|
|
10
|
+
function encode(string) {
|
|
11
|
+
if (typeof string == "string" && string.length >= 128) {
|
|
12
|
+
if (NON_ASCII.test(string)) throw new TypeError("non-ASCII string encountered in encode()");
|
|
13
|
+
return encoder.encode(string);
|
|
14
|
+
}
|
|
15
|
+
const bytes = new Uint8Array(string.length);
|
|
16
|
+
for (let i = 0; i < string.length; i++) {
|
|
17
|
+
const code = string.charCodeAt(i);
|
|
18
|
+
if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
|
|
19
|
+
bytes[i] = code;
|
|
20
|
+
}
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
|
23
|
+
function decodeBase64(encoded, url = !1) {
|
|
24
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded, { alphabet: url ? "base64url" : "base64" });
|
|
25
|
+
if (url) {
|
|
26
|
+
if (encoded.includes("+") || encoded.includes("/")) throw new TypeError("Invalid base64url");
|
|
27
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
28
|
+
}
|
|
29
|
+
const binary = atob(encoded), bytes = new Uint8Array(binary.length);
|
|
30
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
31
|
+
return bytes;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/util/errors.js
|
|
35
|
+
var JOSEError = class extends Error {
|
|
36
|
+
static code = "ERR_JOSE_GENERIC";
|
|
37
|
+
code = "ERR_JOSE_GENERIC";
|
|
38
|
+
constructor(message, options) {
|
|
39
|
+
super(message, options), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
43
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
44
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
45
|
+
claim;
|
|
46
|
+
reason;
|
|
47
|
+
payload;
|
|
48
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
49
|
+
super(message, { cause: {
|
|
50
|
+
claim,
|
|
51
|
+
reason,
|
|
52
|
+
payload
|
|
53
|
+
} }), this.claim = claim, this.reason = reason, this.payload = payload;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var JWTExpired = class extends JOSEError {
|
|
57
|
+
static code = "ERR_JWT_EXPIRED";
|
|
58
|
+
code = "ERR_JWT_EXPIRED";
|
|
59
|
+
claim;
|
|
60
|
+
reason;
|
|
61
|
+
payload;
|
|
62
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
63
|
+
super(message, { cause: {
|
|
64
|
+
claim,
|
|
65
|
+
reason,
|
|
66
|
+
payload
|
|
67
|
+
} }), this.claim = claim, this.reason = reason, this.payload = payload;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
71
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
72
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
73
|
+
};
|
|
74
|
+
var JOSENotSupported = class extends JOSEError {
|
|
75
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
76
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
77
|
+
};
|
|
78
|
+
var JWSInvalid = class extends JOSEError {
|
|
79
|
+
static code = "ERR_JWS_INVALID";
|
|
80
|
+
code = "ERR_JWS_INVALID";
|
|
81
|
+
};
|
|
82
|
+
var JWTInvalid = class extends JOSEError {
|
|
83
|
+
static code = "ERR_JWT_INVALID";
|
|
84
|
+
code = "ERR_JWT_INVALID";
|
|
85
|
+
};
|
|
86
|
+
var JWKSInvalid = class extends JOSEError {
|
|
87
|
+
static code = "ERR_JWKS_INVALID";
|
|
88
|
+
code = "ERR_JWKS_INVALID";
|
|
89
|
+
};
|
|
90
|
+
var JWKSNoMatchingKey = class extends JOSEError {
|
|
91
|
+
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
92
|
+
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
93
|
+
constructor(message = "no applicable key found in the JSON Web Key Set", options) {
|
|
94
|
+
super(message, options);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
98
|
+
[Symbol.asyncIterator] = async function* () {};
|
|
99
|
+
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
100
|
+
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
101
|
+
constructor(message = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
102
|
+
super(message, options);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var JWKSTimeout = class extends JOSEError {
|
|
106
|
+
static code = "ERR_JWKS_TIMEOUT";
|
|
107
|
+
code = "ERR_JWKS_TIMEOUT";
|
|
108
|
+
constructor(message = "request timed out", options) {
|
|
109
|
+
super(message, options);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
113
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
114
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
115
|
+
constructor(message = "signature verification failed", options) {
|
|
116
|
+
super(message, options);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/util/base64url.js
|
|
121
|
+
var invalid = "The input to be decoded is not correctly encoded.";
|
|
122
|
+
function decode(input) {
|
|
123
|
+
try {
|
|
124
|
+
return decodeBase64(typeof input == "string" ? input : decoder.decode(input), !0);
|
|
125
|
+
} catch (cause) {
|
|
126
|
+
throw new TypeError(invalid, { cause });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/validate.js
|
|
131
|
+
function isObject(input) {
|
|
132
|
+
if (typeof input != "object" || input === null || Object.prototype.toString.call(input) !== "[object Object]") return !1;
|
|
133
|
+
const prototype = Object.getPrototypeOf(input);
|
|
134
|
+
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
135
|
+
}
|
|
136
|
+
function isJwkSet(input) {
|
|
137
|
+
return isObject(input) && Array.isArray(input.keys) && Array.from(input.keys).every(isObject);
|
|
138
|
+
}
|
|
139
|
+
function isDisjoint(...headers) {
|
|
140
|
+
const parameters = /* @__PURE__ */ new Set();
|
|
141
|
+
for (const header of headers) if (header) for (const parameter of Object.keys(header)) {
|
|
142
|
+
if (parameters.has(parameter)) return !1;
|
|
143
|
+
parameters.add(parameter);
|
|
144
|
+
}
|
|
145
|
+
return !0;
|
|
146
|
+
}
|
|
147
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
148
|
+
try {
|
|
149
|
+
return decode(value);
|
|
150
|
+
} catch {
|
|
151
|
+
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function encodeBase64url(value, label, ErrorClass) {
|
|
155
|
+
try {
|
|
156
|
+
return encode(value);
|
|
157
|
+
} catch {
|
|
158
|
+
throw new ErrorClass(`The ${label} is not a valid base64url string`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function parseJoseHeader(b64, ErrorClass, message) {
|
|
162
|
+
let parsed;
|
|
163
|
+
try {
|
|
164
|
+
parsed = JSON.parse(strictDecoder.decode(decode(b64)));
|
|
165
|
+
} catch {
|
|
166
|
+
throw new ErrorClass(message);
|
|
167
|
+
}
|
|
168
|
+
if (!isObject(parsed)) throw new ErrorClass(message);
|
|
169
|
+
return parsed;
|
|
170
|
+
}
|
|
171
|
+
var JWS_RECOGNIZED = {
|
|
172
|
+
__proto__: null,
|
|
173
|
+
b64: !0
|
|
174
|
+
};
|
|
175
|
+
function validateAlgorithms(option, algorithms) {
|
|
176
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s != "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
|
|
177
|
+
return algorithms === void 0 ? void 0 : new Set(algorithms);
|
|
178
|
+
}
|
|
179
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
180
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
181
|
+
if (!protectedHeader || protectedHeader.crit === void 0) return [];
|
|
182
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input != "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
183
|
+
const recognized = recognizedOption === void 0 ? recognizedDefault : {
|
|
184
|
+
__proto__: null,
|
|
185
|
+
...recognizedOption,
|
|
186
|
+
...recognizedDefault
|
|
187
|
+
};
|
|
188
|
+
for (const parameter of protectedHeader.crit) {
|
|
189
|
+
if (!(parameter in recognized)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
190
|
+
if (!Object.hasOwn(joseHeader, parameter) || joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
191
|
+
if (recognized[parameter] && (!Object.hasOwn(protectedHeader, parameter) || protectedHeader[parameter] === void 0)) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
192
|
+
}
|
|
193
|
+
return protectedHeader.crit;
|
|
194
|
+
}
|
|
195
|
+
function validateB64(protectedHeader, extensions) {
|
|
196
|
+
if (extensions.includes("b64")) {
|
|
197
|
+
const b64 = protectedHeader.b64;
|
|
198
|
+
if (typeof b64 != "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
199
|
+
return b64;
|
|
200
|
+
}
|
|
201
|
+
return !0;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/key.js
|
|
205
|
+
var tag = (key) => key[Symbol.toStringTag], jwkMatchesOp = (entry, key, usage) => {
|
|
206
|
+
const { alg } = entry;
|
|
207
|
+
if (key.use !== void 0) {
|
|
208
|
+
const expected = usage === "sign" || usage === "verify" ? "sig" : "enc";
|
|
209
|
+
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
210
|
+
}
|
|
211
|
+
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
212
|
+
if (Array.isArray(key.key_ops)) {
|
|
213
|
+
const expectedKeyOp = usage === "encrypt" || usage === "decrypt" ? entry.ops?.[usage === "encrypt" ? 0 : 1] : usage;
|
|
214
|
+
if (expectedKeyOp && !key.key_ops.includes(expectedKeyOp)) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
async function prepareKey(entry, key, usage) {
|
|
218
|
+
const { alg, secret } = entry, privateKey = usage === "decrypt" || usage === "sign";
|
|
219
|
+
if (secret && key instanceof Uint8Array) return key;
|
|
220
|
+
let normalized, keyObject;
|
|
221
|
+
if (isObject(key)) {
|
|
222
|
+
if (normalized = normalizeJwk(key), typeof normalized.kty != "string") throw invalidKeyType(alg, key, secret);
|
|
223
|
+
if (!(secret ? normalized.kty === "oct" && typeof normalized.k == "string" : normalized.kty !== "oct" && (privateKey ? normalized.kty === "AKP" && typeof normalized.priv == "string" || typeof normalized.d == "string" : normalized.d === void 0 && normalized.priv === void 0))) throw new TypeError(secret ? "JSON Web Key for symmetric algorithms must have JWK \"kty\" (Key Type) equal to \"oct\" and the JWK \"k\" (Key Value) present" : `JSON Web Key for this operation must be a ${privateKey ? "private" : "public"} JWK`);
|
|
224
|
+
if (jwkMatchesOp(entry, normalized, usage), normalized.kty === "oct") return decode(normalized.k);
|
|
225
|
+
if (!Object.isFrozen(key)) {
|
|
226
|
+
const { key_ops } = key;
|
|
227
|
+
Array.isArray(key_ops) && Object.freeze(key_ops), Object.freeze(key);
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
if (!isKeyLike(key)) throw invalidKeyType(alg, key, secret);
|
|
231
|
+
const expectedType = secret ? "secret" : privateKey ? "private" : "public";
|
|
232
|
+
if (key.type !== expectedType && (secret || [
|
|
233
|
+
"secret",
|
|
234
|
+
"public",
|
|
235
|
+
"private"
|
|
236
|
+
].includes(key.type))) throw new TypeError(`${tag(key)} instances must be of type "${expectedType}" for the ${alg} algorithm`);
|
|
237
|
+
if (isCryptoKey(key)) return key;
|
|
238
|
+
if (keyObject = key, keyObject.type === "secret") return keyObject.export();
|
|
239
|
+
}
|
|
240
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
241
|
+
const cacheKey = key;
|
|
242
|
+
let cached = cache.get(cacheKey);
|
|
243
|
+
if (cached?.[alg]) return cached[alg];
|
|
244
|
+
if (cached || cache.set(cacheKey, cached = {}), keyObject && typeof keyObject.toCryptoKey == "function") {
|
|
245
|
+
const isPublic = keyObject.type === "public", crv = nist[keyObject.asymmetricKeyDetails?.namedCurve], params = entry.resolve?.({
|
|
246
|
+
crv,
|
|
247
|
+
asymmetricKeyType: keyObject.asymmetricKeyType
|
|
248
|
+
}) ?? entry.subtle;
|
|
249
|
+
return cached[alg] = keyObject.toCryptoKey(params, isPublic, entry.usages[isPublic ? 0 : 1]);
|
|
250
|
+
}
|
|
251
|
+
return normalized ??= keyObject.export({ format: "jwk" }), normalized.alg = alg, cached[alg] = await jwkToKey(entry, normalized);
|
|
252
|
+
}
|
|
253
|
+
var cache;
|
|
254
|
+
var nist = {
|
|
255
|
+
__proto__: null,
|
|
256
|
+
prime256v1: "P-256",
|
|
257
|
+
secp384r1: "P-384",
|
|
258
|
+
secp521r1: "P-521"
|
|
259
|
+
};
|
|
260
|
+
var isCryptoKey = (key) => {
|
|
261
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey") return !0;
|
|
262
|
+
try {
|
|
263
|
+
return key instanceof CryptoKey;
|
|
264
|
+
} catch {
|
|
265
|
+
return !1;
|
|
266
|
+
}
|
|
267
|
+
}, isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject", isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
268
|
+
function message(msg, actual, ...types) {
|
|
269
|
+
if (types.length > 2) {
|
|
270
|
+
const last = types.pop();
|
|
271
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
272
|
+
} else types.length === 2 ? msg += `one of type ${types[0]} or ${types[1]}.` : msg += `of type ${types[0]}.`;
|
|
273
|
+
return actual == null ? msg += ` Received ${actual}` : typeof actual == "function" && actual.name ? msg += ` Received function ${actual.name}` : typeof actual == "object" && actual != null && actual.constructor?.name && (msg += ` Received an instance of ${actual.constructor.name}`), msg;
|
|
274
|
+
}
|
|
275
|
+
function invalidKeyType(alg, actual, secret) {
|
|
276
|
+
const types = [
|
|
277
|
+
"CryptoKey",
|
|
278
|
+
"KeyObject",
|
|
279
|
+
"JSON Web Key"
|
|
280
|
+
];
|
|
281
|
+
return secret && types.push("Uint8Array"), new TypeError(message(`Key for the ${alg} algorithm must be `, actual, ...types));
|
|
282
|
+
}
|
|
283
|
+
var unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
284
|
+
function checkUsage(key, usage) {
|
|
285
|
+
if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
286
|
+
}
|
|
287
|
+
function checkModulusLength(alg, key) {
|
|
288
|
+
const { modulusLength } = key.algorithm;
|
|
289
|
+
if (typeof modulusLength != "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
290
|
+
}
|
|
291
|
+
function checkCryptoKey(key, expected, usage) {
|
|
292
|
+
const algorithm = key.algorithm;
|
|
293
|
+
if (algorithm.name !== expected.name) throw unusable(expected.name);
|
|
294
|
+
if (expected.hash && algorithm.hash?.name !== expected.hash) throw unusable(expected.hash, "algorithm.hash");
|
|
295
|
+
if (expected.namedCurve && algorithm.namedCurve !== expected.namedCurve) throw unusable(expected.namedCurve, "algorithm.namedCurve");
|
|
296
|
+
if (expected.length !== void 0 && algorithm.length !== expected.length) throw unusable(expected.length, "algorithm.length");
|
|
297
|
+
checkUsage(key, usage);
|
|
298
|
+
}
|
|
299
|
+
function snapshotJwk(jwk) {
|
|
300
|
+
return {
|
|
301
|
+
__proto__: null,
|
|
302
|
+
...jwk
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function normalizeJwk(jwk) {
|
|
306
|
+
const normalized = snapshotJwk(jwk);
|
|
307
|
+
if (normalized.ext !== void 0 && typeof normalized.ext != "boolean") throw new TypeError("\"ext\" (Extractable) Parameter must be a boolean");
|
|
308
|
+
if (normalized.key_ops !== void 0) {
|
|
309
|
+
const value = normalized.key_ops, keyOps = Array.isArray(value) ? [...value] : void 0;
|
|
310
|
+
if (!keyOps || keyOps.some((operation) => typeof operation != "string") || new Set(keyOps).size !== keyOps.length) throw new TypeError("\"key_ops\" (Key Operations) Parameter must be an array of unique strings");
|
|
311
|
+
normalized.key_ops = keyOps;
|
|
312
|
+
}
|
|
313
|
+
return normalized;
|
|
314
|
+
}
|
|
315
|
+
async function jwkToKey(entry, jwk, extractable) {
|
|
316
|
+
if (!entry.kty.includes(jwk.kty)) throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
317
|
+
const algorithm = entry.resolve?.({
|
|
318
|
+
kty: jwk.kty,
|
|
319
|
+
crv: jwk.crv
|
|
320
|
+
}) ?? entry.subtle, isPrivate = !!(jwk.d || jwk.priv), keyData = {
|
|
321
|
+
...jwk,
|
|
322
|
+
ext: extractable ?? jwk.ext
|
|
323
|
+
};
|
|
324
|
+
return keyData.kty !== "AKP" && delete keyData.alg, delete keyData.use, crypto.subtle.importKey("jwk", keyData, algorithm, keyData.ext ?? !isPrivate, jwk.key_ops ?? entry.usages[isPrivate ? 1 : 0]);
|
|
325
|
+
}
|
|
326
|
+
async function rawKey(key, expected, usage, extractable = !1) {
|
|
327
|
+
return key instanceof Uint8Array && (key = await crypto.subtle.importKey("raw", key, expected, extractable, [usage])), checkCryptoKey(key, expected, usage), key;
|
|
328
|
+
}
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/key_descriptor.js
|
|
331
|
+
function table(entries) {
|
|
332
|
+
const out = { __proto__: null };
|
|
333
|
+
for (const alg in entries) out[alg] = {
|
|
334
|
+
...entries[alg],
|
|
335
|
+
alg
|
|
336
|
+
};
|
|
337
|
+
return out;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/jws_algorithms.js
|
|
341
|
+
var sig = [["verify"], ["sign"]];
|
|
342
|
+
function hmac(bits) {
|
|
343
|
+
const subtle = {
|
|
344
|
+
name: "HMAC",
|
|
345
|
+
hash: `SHA-${bits}`
|
|
346
|
+
};
|
|
347
|
+
return {
|
|
348
|
+
kty: ["oct"],
|
|
349
|
+
secret: !0,
|
|
350
|
+
subtle,
|
|
351
|
+
signing: subtle,
|
|
352
|
+
usages: sig
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function rsa(bits, saltLength) {
|
|
356
|
+
const subtle = {
|
|
357
|
+
name: saltLength ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
358
|
+
hash: `SHA-${bits}`
|
|
359
|
+
};
|
|
360
|
+
return {
|
|
361
|
+
kty: ["RSA"],
|
|
362
|
+
subtle,
|
|
363
|
+
signing: saltLength ? {
|
|
364
|
+
...subtle,
|
|
365
|
+
saltLength
|
|
366
|
+
} : subtle,
|
|
367
|
+
usages: sig,
|
|
368
|
+
minRsaBits: 2048
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function ecdsa(crv, bits) {
|
|
372
|
+
return {
|
|
373
|
+
kty: ["EC"],
|
|
374
|
+
crv,
|
|
375
|
+
subtle: {
|
|
376
|
+
name: "ECDSA",
|
|
377
|
+
namedCurve: crv
|
|
378
|
+
},
|
|
379
|
+
signing: {
|
|
380
|
+
name: "ECDSA",
|
|
381
|
+
hash: `SHA-${bits}`
|
|
382
|
+
},
|
|
383
|
+
usages: sig
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function eddsa() {
|
|
387
|
+
const subtle = { name: "Ed25519" };
|
|
388
|
+
return {
|
|
389
|
+
kty: ["OKP"],
|
|
390
|
+
crv: "Ed25519",
|
|
391
|
+
subtle,
|
|
392
|
+
signing: subtle,
|
|
393
|
+
usages: sig
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function mldsa(bits) {
|
|
397
|
+
const subtle = { name: `ML-DSA-${bits}` };
|
|
398
|
+
return {
|
|
399
|
+
kty: ["AKP"],
|
|
400
|
+
subtle,
|
|
401
|
+
signing: subtle,
|
|
402
|
+
usages: sig
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
var JWS = table({
|
|
406
|
+
HS256: hmac(256),
|
|
407
|
+
HS384: hmac(384),
|
|
408
|
+
HS512: hmac(512),
|
|
409
|
+
RS256: rsa(256),
|
|
410
|
+
RS384: rsa(384),
|
|
411
|
+
RS512: rsa(512),
|
|
412
|
+
PS256: rsa(256, 32),
|
|
413
|
+
PS384: rsa(384, 48),
|
|
414
|
+
PS512: rsa(512, 64),
|
|
415
|
+
ES256: ecdsa("P-256", 256),
|
|
416
|
+
ES384: ecdsa("P-384", 384),
|
|
417
|
+
ES512: ecdsa("P-521", 512),
|
|
418
|
+
EdDSA: eddsa(),
|
|
419
|
+
Ed25519: eddsa(),
|
|
420
|
+
"ML-DSA-44": mldsa(44),
|
|
421
|
+
"ML-DSA-65": mldsa(65),
|
|
422
|
+
"ML-DSA-87": mldsa(87)
|
|
423
|
+
});
|
|
424
|
+
function jwsAlgorithm(alg) {
|
|
425
|
+
const entry = typeof alg == "string" ? JWS[alg] : void 0;
|
|
426
|
+
if (!entry) throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
427
|
+
return entry;
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/jws_verify.js
|
|
431
|
+
function prepareVerify(options) {
|
|
432
|
+
return [options && validateAlgorithms("algorithms", options.algorithms), options?.crit];
|
|
433
|
+
}
|
|
434
|
+
function parseProtectedHeader(encodedProtected) {
|
|
435
|
+
return encodedProtected === void 0 ? {} : parseJoseHeader(encodedProtected, JWSInvalid, "JWS Protected Header is invalid");
|
|
436
|
+
}
|
|
437
|
+
function encodeCompactUnencodedPayload(payload) {
|
|
438
|
+
try {
|
|
439
|
+
return encode(payload);
|
|
440
|
+
} catch {
|
|
441
|
+
throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters");
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedProtected) {
|
|
445
|
+
const { protected: encodedProtected, header, payload: inputPayload } = jws, parsedProt = parsedProtected ?? parseProtectedHeader(encodedProtected);
|
|
446
|
+
if (!isDisjoint(parsedProt, header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
447
|
+
const joseHeader = {
|
|
448
|
+
...parsedProt,
|
|
449
|
+
...header
|
|
450
|
+
}, b64 = validateB64(parsedProt, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], parsedProt, joseHeader)), { alg } = joseHeader;
|
|
451
|
+
if (typeof alg != "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
452
|
+
if (shared[0] && !shared[0].has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
453
|
+
if (b64) {
|
|
454
|
+
if (typeof inputPayload != "string") throw new JWSInvalid("JWS Payload must be a string");
|
|
455
|
+
} else if (typeof inputPayload != "string" && !(inputPayload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
456
|
+
const signingPayload = b64 || typeof inputPayload != "string" ? inputPayload : encodeUnencodedPayload(inputPayload);
|
|
457
|
+
let resolvedKey = !1;
|
|
458
|
+
typeof key == "function" && (key = await key(parsedProt, jws), resolvedKey = !0);
|
|
459
|
+
const entry = jwsAlgorithm(alg), data = concat(encodedProtected !== void 0 ? encode(encodedProtected) : /* @__PURE__ */ new Uint8Array(), encode("."), typeof signingPayload == "string" ? shared[2] ??= encodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload), signature = decodeBase64url(jws.signature, "signature", JWSInvalid), k = await prepareKey(entry, key, "verify"), cryptoKey = await rawKey(k, entry.subtle, "verify");
|
|
460
|
+
entry.minRsaBits && checkModulusLength(entry.alg, cryptoKey);
|
|
461
|
+
let verified = !1;
|
|
462
|
+
try {
|
|
463
|
+
verified = await crypto.subtle.verify(entry.signing, cryptoKey, signature, data);
|
|
464
|
+
} catch {}
|
|
465
|
+
if (!verified) throw new JWSSignatureVerificationFailed();
|
|
466
|
+
const result = { payload: typeof signingPayload == "string" ? decodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload };
|
|
467
|
+
return encodedProtected !== void 0 && (result.protectedHeader = parsedProt), header !== void 0 && (result.unprotectedHeader = header), resolvedKey ? [{
|
|
468
|
+
...result,
|
|
469
|
+
key: k
|
|
470
|
+
}, b64] : [result, b64];
|
|
471
|
+
}
|
|
472
|
+
async function verifyCompact(jws, shared, key) {
|
|
473
|
+
if (jws instanceof Uint8Array && (jws = decoder.decode(jws)), typeof jws != "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
474
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
475
|
+
if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
|
|
476
|
+
return verifySignature({
|
|
477
|
+
payload,
|
|
478
|
+
protected: protectedHeader,
|
|
479
|
+
signature
|
|
480
|
+
}, shared, key, encodeCompactUnencodedPayload);
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
484
|
+
var epoch = (date) => Math.floor(date.getTime() / 1e3), multipliers = {
|
|
485
|
+
s: 1,
|
|
486
|
+
m: 60,
|
|
487
|
+
h: 3600,
|
|
488
|
+
d: 86400,
|
|
489
|
+
w: 604800,
|
|
490
|
+
y: 31557600
|
|
491
|
+
}, REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, checkFailed = "check_failed";
|
|
492
|
+
function invalidDuration() {
|
|
493
|
+
throw new TypeError("Invalid time period format");
|
|
494
|
+
}
|
|
495
|
+
function secs(str) {
|
|
496
|
+
typeof str != "string" && invalidDuration();
|
|
497
|
+
const matched = REGEX.exec(str);
|
|
498
|
+
(!matched || matched[4] && matched[1]) && invalidDuration();
|
|
499
|
+
const value = parseFloat(matched[2]), numericDate2 = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
500
|
+
return Number.isFinite(numericDate2) || invalidDuration(), matched[1] === "-" || matched[4] === "ago" ? -numericDate2 : numericDate2;
|
|
501
|
+
}
|
|
502
|
+
function validateInput(label, input) {
|
|
503
|
+
if (!Number.isFinite(input)) throw new TypeError(`Invalid ${label} input`);
|
|
504
|
+
return input;
|
|
505
|
+
}
|
|
506
|
+
var normalizeTyp = (value) => {
|
|
507
|
+
const normalized = value.toLowerCase();
|
|
508
|
+
return value.includes("/") ? normalized : `application/${normalized}`;
|
|
509
|
+
}, checkAudiencePresence = (audPayload, audOption) => typeof audPayload == "string" ? audOption.includes(audPayload) : Array.isArray(audPayload) ? audOption.some((aud) => audPayload.includes(aud)) : !1;
|
|
510
|
+
function validateNumericDate(payload, claim, required = !1) {
|
|
511
|
+
const value = payload[claim];
|
|
512
|
+
if (!(value === void 0 && !required)) {
|
|
513
|
+
if (typeof value != "number") throw new JWTClaimValidationFailed(`"${claim}" claim must be a number`, payload, claim, "invalid");
|
|
514
|
+
return value;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function unexpectedClaim(payload, claim) {
|
|
518
|
+
throw new JWTClaimValidationFailed(`unexpected "${claim}" claim value`, payload, claim, checkFailed);
|
|
519
|
+
}
|
|
520
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
521
|
+
let payload;
|
|
522
|
+
try {
|
|
523
|
+
payload = JSON.parse(strictDecoder.decode(encodedPayload));
|
|
524
|
+
} catch {}
|
|
525
|
+
if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
526
|
+
const { typ } = options;
|
|
527
|
+
if (typ !== void 0 && (typeof protectedHeader.typ != "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", checkFailed);
|
|
528
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options, presenceCheck = [...requiredClaims];
|
|
529
|
+
maxTokenAge !== void 0 && presenceCheck.push("iat"), audience !== void 0 && presenceCheck.push("aud"), subject !== void 0 && presenceCheck.push("sub"), issuer !== void 0 && presenceCheck.push("iss");
|
|
530
|
+
for (const claim of new Set(presenceCheck.reverse())) if (!Object.hasOwn(payload, claim)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
531
|
+
issuer !== void 0 && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss) && unexpectedClaim(payload, "iss"), subject !== void 0 && payload.sub !== subject && unexpectedClaim(payload, "sub"), audience !== void 0 && !checkAudiencePresence(payload.aud, typeof audience == "string" ? [audience] : audience) && unexpectedClaim(payload, "aud");
|
|
532
|
+
const { clockTolerance } = options;
|
|
533
|
+
let tolerance = 0;
|
|
534
|
+
if (typeof clockTolerance == "string") tolerance = secs(clockTolerance);
|
|
535
|
+
else if (clockTolerance !== void 0) {
|
|
536
|
+
if (typeof clockTolerance != "number") throw new TypeError("Invalid clockTolerance option type");
|
|
537
|
+
tolerance = clockTolerance;
|
|
538
|
+
}
|
|
539
|
+
validateInput("clockTolerance option", tolerance);
|
|
540
|
+
const { currentDate } = options, now = validateInput("currentDate option", epoch(currentDate === void 0 ? /* @__PURE__ */ new Date() : currentDate)), iat = validateNumericDate(payload, "iat", maxTokenAge !== void 0), nbf = validateNumericDate(payload, "nbf");
|
|
541
|
+
if (nbf !== void 0 && nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", checkFailed);
|
|
542
|
+
const exp = validateNumericDate(payload, "exp");
|
|
543
|
+
if (exp !== void 0 && exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", checkFailed);
|
|
544
|
+
if (maxTokenAge !== void 0) {
|
|
545
|
+
const age = now - iat, max = validateInput("maxTokenAge option", typeof maxTokenAge == "number" ? maxTokenAge : secs(maxTokenAge));
|
|
546
|
+
if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", checkFailed);
|
|
547
|
+
if (age < -tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", checkFailed);
|
|
548
|
+
}
|
|
549
|
+
return payload;
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/jwt/verify.js
|
|
553
|
+
async function jwtVerify(jwt, key, options) {
|
|
554
|
+
const [verified, b64] = await verifyCompact(jwt, prepareVerify(options), key);
|
|
555
|
+
if (!b64) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
556
|
+
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
557
|
+
return {
|
|
558
|
+
...verified,
|
|
559
|
+
payload
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/jwks/local.js
|
|
564
|
+
function isUsableJWK(jwk, entry, alg, kid) {
|
|
565
|
+
const { kty, key_ops: keyOps, ext, kid: jwkKid, alg: jwkAlg, use, crv } = jwk;
|
|
566
|
+
return (ext === void 0 || typeof ext == "boolean") && (keyOps === void 0 || Array.isArray(keyOps) && keyOps.every((operation, index) => typeof operation == "string" && keyOps.indexOf(operation) === index) && keyOps.includes("verify")) && entry.kty.includes(kty) && (kid === void 0 || typeof kid == "string" && kid === jwkKid) && (jwkAlg === void 0 ? kty !== "AKP" : alg === jwkAlg) && (use === void 0 || use === "sig") && (!entry.crv || crv === entry.crv);
|
|
567
|
+
}
|
|
568
|
+
async function importWithAlgCache(cache, jwk, entry) {
|
|
569
|
+
const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk), { alg } = entry;
|
|
570
|
+
if (cached[alg] === void 0) {
|
|
571
|
+
const pending = jwkToKey(entry, jwk, !0).then((key) => {
|
|
572
|
+
if (key.type !== "public") throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
573
|
+
return cached[alg] = key, key;
|
|
574
|
+
}).catch((error) => {
|
|
575
|
+
throw cached[alg] === pending && delete cached[alg], error;
|
|
576
|
+
});
|
|
577
|
+
cached[alg] = pending;
|
|
578
|
+
}
|
|
579
|
+
return cached[alg];
|
|
580
|
+
}
|
|
581
|
+
function createLocalJWKSet(jwks) {
|
|
582
|
+
let snapshot;
|
|
583
|
+
try {
|
|
584
|
+
snapshot = structuredClone(jwks);
|
|
585
|
+
} catch {}
|
|
586
|
+
if (!isJwkSet(snapshot)) throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
587
|
+
const metadata = snapshot.keys.map((jwk) => {
|
|
588
|
+
const normalized = snapshotJwk(jwk);
|
|
589
|
+
return Array.isArray(normalized.key_ops) && (normalized.key_ops = [...normalized.key_ops]), normalized;
|
|
590
|
+
}), cached = /* @__PURE__ */ new WeakMap();
|
|
591
|
+
return Object.defineProperty(async (protectedHeader, token) => {
|
|
592
|
+
const { alg, kid } = {
|
|
593
|
+
...protectedHeader,
|
|
594
|
+
...token?.header
|
|
595
|
+
}, entry = typeof alg == "string" ? JWS[alg] : void 0;
|
|
596
|
+
if (!entry || entry.secret) throw new JOSENotSupported("Unsupported \"alg\" value for a JSON Web Key Set");
|
|
597
|
+
const candidates = snapshot.keys.filter((_, index) => isUsableJWK(metadata[index], entry, alg, kid)), { 0: jwk, length } = candidates;
|
|
598
|
+
if (!length) throw new JWKSNoMatchingKey();
|
|
599
|
+
if (length !== 1) {
|
|
600
|
+
const error = new JWKSMultipleMatchingKeys();
|
|
601
|
+
throw error[Symbol.asyncIterator] = async function* () {
|
|
602
|
+
for (const jwk2 of candidates) try {
|
|
603
|
+
yield await importWithAlgCache(cached, jwk2, entry);
|
|
604
|
+
} catch {}
|
|
605
|
+
}, error;
|
|
606
|
+
}
|
|
607
|
+
return importWithAlgCache(cached, jwk, entry);
|
|
608
|
+
}, "jwks", { value: () => structuredClone(snapshot) });
|
|
609
|
+
}
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region ../../node_modules/.pnpm/jose@6.2.12/node_modules/jose/dist/webapi/jwks/remote.js
|
|
612
|
+
function isCloudflareWorkers() {
|
|
613
|
+
return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
|
|
614
|
+
}
|
|
615
|
+
var USER_AGENT;
|
|
616
|
+
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.12");
|
|
617
|
+
var customFetch = /* @__PURE__ */ Symbol();
|
|
618
|
+
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
619
|
+
const response = await fetchImpl(url, {
|
|
620
|
+
method: "GET",
|
|
621
|
+
signal,
|
|
622
|
+
redirect: "manual",
|
|
623
|
+
headers
|
|
624
|
+
}).catch((err) => {
|
|
625
|
+
throw err.name === "TimeoutError" ? new JWKSTimeout() : err;
|
|
626
|
+
});
|
|
627
|
+
if (response.status !== 200) throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
628
|
+
try {
|
|
629
|
+
return await response.json();
|
|
630
|
+
} catch {
|
|
631
|
+
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
var jwksCache = /* @__PURE__ */ Symbol();
|
|
635
|
+
function isFreshFor(timestamp, duration) {
|
|
636
|
+
return Number.isFinite(timestamp) && Date.now() < timestamp + duration;
|
|
637
|
+
}
|
|
638
|
+
function validateDuration(value, fallback, option) {
|
|
639
|
+
if (Number.isNaN(value)) throw new TypeError(`"${option}" option must not be NaN`);
|
|
640
|
+
return typeof value == "number" ? value : fallback;
|
|
641
|
+
}
|
|
642
|
+
function createRemoteJWKSet(url, options) {
|
|
643
|
+
if (!(url instanceof URL)) throw new TypeError("url must be an instance of URL");
|
|
644
|
+
const href = new URL(url.href).href, opts = options ?? {}, timeoutOption = opts.timeoutDuration;
|
|
645
|
+
if (typeof timeoutOption == "number" && (!Number.isInteger(timeoutOption) || timeoutOption < 0)) throw new TypeError("\"timeoutDuration\" option must be a non-negative integer");
|
|
646
|
+
const timeoutDuration = typeof timeoutOption == "number" ? timeoutOption : 5e3, cooldownDuration = validateDuration(opts.cooldownDuration, 3e4, "cooldownDuration"), cacheMaxAge = validateDuration(opts.cacheMaxAge, 6e5, "cacheMaxAge"), headers = new Headers(opts.headers);
|
|
647
|
+
USER_AGENT && !headers.has("User-Agent") && headers.set("User-Agent", USER_AGENT), headers.has("accept") || headers.set("accept", "application/json, application/jwk-set+json");
|
|
648
|
+
const fetchImpl = opts[customFetch], cache = opts[jwksCache];
|
|
649
|
+
let jwksTimestamp, pendingFetch, reloadSequence = 0, appliedSequence = 0, local;
|
|
650
|
+
if (cache && typeof cache == "object") {
|
|
651
|
+
const { uat, jwks } = cache;
|
|
652
|
+
isFreshFor(uat, cacheMaxAge) && isJwkSet(jwks) && (jwksTimestamp = uat, local = createLocalJWKSet(jwks));
|
|
653
|
+
}
|
|
654
|
+
const reload = async () => {
|
|
655
|
+
if (pendingFetch && isCloudflareWorkers() && (pendingFetch = void 0), !pendingFetch) {
|
|
656
|
+
const sequence = ++reloadSequence, current = pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl).then((json) => {
|
|
657
|
+
const next = createLocalJWKSet(json);
|
|
658
|
+
if (sequence <= appliedSequence) return;
|
|
659
|
+
local = next;
|
|
660
|
+
const updatedAt = Date.now();
|
|
661
|
+
cache && (cache.uat = updatedAt, cache.jwks = json), jwksTimestamp = updatedAt, appliedSequence = sequence;
|
|
662
|
+
}).finally(() => {
|
|
663
|
+
pendingFetch === current && (pendingFetch = void 0);
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
await pendingFetch;
|
|
667
|
+
};
|
|
668
|
+
return Object.defineProperties(async (protectedHeader, token) => {
|
|
669
|
+
(!local || !isFreshFor(jwksTimestamp, cacheMaxAge)) && await reload();
|
|
670
|
+
try {
|
|
671
|
+
return await local(protectedHeader, token);
|
|
672
|
+
} catch (err) {
|
|
673
|
+
if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration)) return await reload(), local(protectedHeader, token);
|
|
674
|
+
throw err;
|
|
675
|
+
}
|
|
676
|
+
}, {
|
|
677
|
+
coolingDown: {
|
|
678
|
+
get: () => isFreshFor(jwksTimestamp, cooldownDuration),
|
|
679
|
+
enumerable: !0
|
|
680
|
+
},
|
|
681
|
+
fresh: {
|
|
682
|
+
get: () => isFreshFor(jwksTimestamp, cacheMaxAge),
|
|
683
|
+
enumerable: !0
|
|
684
|
+
},
|
|
685
|
+
reload: {
|
|
686
|
+
value: reload,
|
|
687
|
+
enumerable: !0
|
|
688
|
+
},
|
|
689
|
+
reloading: {
|
|
690
|
+
get: () => !!pendingFetch,
|
|
691
|
+
enumerable: !0
|
|
692
|
+
},
|
|
693
|
+
jwks: {
|
|
694
|
+
value: () => local?.jwks(),
|
|
695
|
+
enumerable: !0
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
//#endregion
|
|
700
|
+
//#region src/auth.ts
|
|
701
|
+
var scopePattern = /^[\x21\x23-\x5b\x5d-\x7e]+$/u;
|
|
702
|
+
function validateUrl(value, profile) {
|
|
703
|
+
let url;
|
|
704
|
+
try {
|
|
705
|
+
url = new URL(value);
|
|
706
|
+
} catch {
|
|
707
|
+
throw new Error("Invalid MCP authorization URL.");
|
|
708
|
+
}
|
|
709
|
+
const loopback = [
|
|
710
|
+
"127.0.0.1",
|
|
711
|
+
"[::1]",
|
|
712
|
+
"localhost"
|
|
713
|
+
].includes(url.hostname);
|
|
714
|
+
if (url.username || url.password || url.search || url.hash || /[\s"\\]/u.test(value) || (profile === "local" ? !loopback || !["http:", "https:"].includes(url.protocol) : url.protocol !== "https:")) throw new Error("Invalid MCP authorization URL for deployment profile.");
|
|
715
|
+
return url;
|
|
716
|
+
}
|
|
717
|
+
function validString(value) {
|
|
718
|
+
return typeof value === "string" && value.length > 0 && value.length <= 1024 && value.trim() === value && [...value].every((character) => character.charCodeAt(0) > 31 && character.charCodeAt(0) !== 127);
|
|
719
|
+
}
|
|
720
|
+
function createMcpResourceAuth(options) {
|
|
721
|
+
if (![
|
|
722
|
+
"local",
|
|
723
|
+
"self-hosted",
|
|
724
|
+
"cloud"
|
|
725
|
+
].includes(options.profile)) throw new Error("Unknown MCP deployment profile.");
|
|
726
|
+
const resourceUrl = validateUrl(options.resource, options.profile);
|
|
727
|
+
validateUrl(options.issuer, options.profile);
|
|
728
|
+
validateUrl(options.jwksUri, options.profile);
|
|
729
|
+
if (!options.algorithms.length || options.algorithms.some((alg) => !["RS256", "ES256"].includes(alg))) throw new Error("Explicit asymmetric MCP token algorithms are required.");
|
|
730
|
+
if (options.scopes.some((scope) => !scopePattern.test(scope))) throw new Error("Invalid MCP OAuth scope.");
|
|
731
|
+
if (options.tokenType !== void 0 && !["at+jwt", "JWT"].includes(options.tokenType)) throw new Error("Unsupported MCP access-token type.");
|
|
732
|
+
const issuer = options.issuer;
|
|
733
|
+
const resource = options.resource;
|
|
734
|
+
const scopes = [...new Set(options.scopes)];
|
|
735
|
+
const algorithms = [...options.algorithms];
|
|
736
|
+
const tokenType = options.tokenType ?? "at+jwt";
|
|
737
|
+
const requireTenant = options.requireTenant !== false;
|
|
738
|
+
const resolvePrincipal = options.resolvePrincipal;
|
|
739
|
+
const keys = createRemoteJWKSet(new URL(options.jwksUri), { timeoutDuration: 5e3 });
|
|
740
|
+
const metadataUrl = `${resourceUrl.origin}/.well-known/oauth-protected-resource${resourceUrl.pathname === "/" ? "" : resourceUrl.pathname}`;
|
|
741
|
+
function deny(error) {
|
|
742
|
+
const challenge = [
|
|
743
|
+
`Bearer resource_metadata="${metadataUrl}"`,
|
|
744
|
+
...scopes.length ? [`scope="${scopes.join(" ")}"`] : [],
|
|
745
|
+
...error ? [`error="${error}"`] : []
|
|
746
|
+
].join(", ");
|
|
747
|
+
return {
|
|
748
|
+
ok: false,
|
|
749
|
+
response: new Response(null, {
|
|
750
|
+
status: error === "insufficient_scope" ? 403 : 401,
|
|
751
|
+
headers: {
|
|
752
|
+
"WWW-Authenticate": challenge,
|
|
753
|
+
"Cache-Control": "no-store"
|
|
754
|
+
}
|
|
755
|
+
})
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
return {
|
|
759
|
+
metadataUrl,
|
|
760
|
+
metadataResponse: () => Response.json({
|
|
761
|
+
resource,
|
|
762
|
+
authorization_servers: [issuer],
|
|
763
|
+
scopes_supported: scopes,
|
|
764
|
+
bearer_methods_supported: ["header"]
|
|
765
|
+
}, { headers: { "Cache-Control": "no-store" } }),
|
|
766
|
+
async authenticate(request) {
|
|
767
|
+
const authorization = request.headers.get("authorization");
|
|
768
|
+
if (!authorization) return deny();
|
|
769
|
+
const match = /^Bearer +([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)$/iu.exec(authorization);
|
|
770
|
+
if (!match) return deny("invalid_token");
|
|
771
|
+
try {
|
|
772
|
+
const { payload } = await jwtVerify(match[1], keys, {
|
|
773
|
+
issuer,
|
|
774
|
+
audience: resource,
|
|
775
|
+
algorithms,
|
|
776
|
+
typ: tokenType,
|
|
777
|
+
requiredClaims: [
|
|
778
|
+
"iss",
|
|
779
|
+
"aud",
|
|
780
|
+
"sub",
|
|
781
|
+
"exp"
|
|
782
|
+
],
|
|
783
|
+
clockTolerance: 0
|
|
784
|
+
});
|
|
785
|
+
if (!validString(payload.sub) || typeof payload.scope !== "string") return deny("invalid_token");
|
|
786
|
+
const granted = payload.scope === "" ? [] : payload.scope.split(" ");
|
|
787
|
+
if (granted.some((scope) => !scopePattern.test(scope))) return deny("invalid_token");
|
|
788
|
+
if (scopes.some((scope) => !granted.includes(scope))) return deny("insufficient_scope");
|
|
789
|
+
const mapping = await resolvePrincipal(Object.freeze({
|
|
790
|
+
issuer,
|
|
791
|
+
subject: payload.sub,
|
|
792
|
+
scopes: Object.freeze([...granted]),
|
|
793
|
+
claims: Object.freeze(payload)
|
|
794
|
+
}));
|
|
795
|
+
if (!mapping || !validString(mapping.id) || requireTenant && !validString(mapping.tenantId) || mapping.tenantId !== void 0 && !validString(mapping.tenantId) || mapping.kind !== void 0 && !validString(mapping.kind) || mapping.roles !== void 0 && (!Array.isArray(mapping.roles) || !mapping.roles.every(validString))) return deny("invalid_token");
|
|
796
|
+
return {
|
|
797
|
+
ok: true,
|
|
798
|
+
principal: {
|
|
799
|
+
id: mapping.id,
|
|
800
|
+
tenantId: mapping.tenantId,
|
|
801
|
+
kind: mapping.kind,
|
|
802
|
+
roles: mapping.roles ? [...mapping.roles] : void 0,
|
|
803
|
+
scopes: [...granted]
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
} catch {
|
|
807
|
+
return deny("invalid_token");
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
//#endregion
|
|
813
|
+
export { createMcpResourceAuth };
|
|
814
|
+
|
|
815
|
+
//# sourceMappingURL=auth.js.map
|