@frontmcp/plugin-cache 1.9.1 → 1.9.3
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/esm/index.mjs +265 -294
- package/esm/package.json +3 -3
- package/index.js +265 -294
- package/package.json +3 -3
- package/providers/cache-vercel-kv.provider.d.ts +8 -2
- package/providers/cache-vercel-kv.provider.d.ts.map +1 -1
package/esm/index.mjs
CHANGED
|
@@ -108,22 +108,22 @@ var require_node = __commonJS({
|
|
|
108
108
|
mod
|
|
109
109
|
));
|
|
110
110
|
var __toCommonJS = (mod) => __copyProps2(__defProp3({}, "__esModule", { value: true }), mod);
|
|
111
|
-
var
|
|
112
|
-
__export2(
|
|
113
|
-
createSignedJwt: () =>
|
|
114
|
-
cryptoProvider: () =>
|
|
115
|
-
generateRsaKeyPair: () =>
|
|
111
|
+
var node_exports = {};
|
|
112
|
+
__export2(node_exports, {
|
|
113
|
+
createSignedJwt: () => createSignedJwt,
|
|
114
|
+
cryptoProvider: () => nodeCrypto,
|
|
115
|
+
generateRsaKeyPair: () => generateRsaKeyPair3,
|
|
116
116
|
isRsaPssAlg: () => isRsaPssAlg2,
|
|
117
|
-
jwtAlgToNodeAlg: () =>
|
|
118
|
-
nodeCrypto: () =>
|
|
119
|
-
pemToPublicJwk: () =>
|
|
120
|
-
rsaSign: () =>
|
|
121
|
-
rsaSignBase64Url: () =>
|
|
122
|
-
rsaVerify: () =>
|
|
123
|
-
rsaVerifySync: () =>
|
|
117
|
+
jwtAlgToNodeAlg: () => jwtAlgToNodeAlg,
|
|
118
|
+
nodeCrypto: () => nodeCrypto,
|
|
119
|
+
pemToPublicJwk: () => pemToPublicJwk3,
|
|
120
|
+
rsaSign: () => rsaSign,
|
|
121
|
+
rsaSignBase64Url: () => rsaSignBase64Url3,
|
|
122
|
+
rsaVerify: () => rsaVerify3,
|
|
123
|
+
rsaVerifySync: () => rsaVerifySync3
|
|
124
124
|
});
|
|
125
|
-
module.exports = __toCommonJS(
|
|
126
|
-
var
|
|
125
|
+
module.exports = __toCommonJS(node_exports);
|
|
126
|
+
var import_node_crypto = __toESM2(__require("node:crypto"));
|
|
127
127
|
var JWT_ALG_TO_NODE_DIGEST2 = {
|
|
128
128
|
RS256: "RSA-SHA256",
|
|
129
129
|
RS384: "RSA-SHA384",
|
|
@@ -133,7 +133,7 @@ var require_node = __commonJS({
|
|
|
133
133
|
PS384: "RSA-SHA384",
|
|
134
134
|
PS512: "RSA-SHA512"
|
|
135
135
|
};
|
|
136
|
-
function
|
|
136
|
+
function jwtAlgToNodeAlg(jwtAlg) {
|
|
137
137
|
const nodeAlg = JWT_ALG_TO_NODE_DIGEST2[jwtAlg];
|
|
138
138
|
if (!nodeAlg) {
|
|
139
139
|
throw new Error(`Unsupported JWT algorithm: ${jwtAlg}`);
|
|
@@ -143,70 +143,70 @@ var require_node = __commonJS({
|
|
|
143
143
|
function isRsaPssAlg2(jwtAlg) {
|
|
144
144
|
return jwtAlg.startsWith("PS");
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function toUint8Array(buf) {
|
|
147
147
|
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function toBuffer(data) {
|
|
150
150
|
if (typeof data === "string") {
|
|
151
151
|
return Buffer.from(data, "utf8");
|
|
152
152
|
}
|
|
153
153
|
return Buffer.from(data);
|
|
154
154
|
}
|
|
155
|
-
var
|
|
155
|
+
var nodeCrypto = {
|
|
156
156
|
randomUUID() {
|
|
157
|
-
return
|
|
157
|
+
return import_node_crypto.default.randomUUID();
|
|
158
158
|
},
|
|
159
159
|
randomBytes(length) {
|
|
160
|
-
return
|
|
160
|
+
return toUint8Array(import_node_crypto.default.randomBytes(length));
|
|
161
161
|
},
|
|
162
162
|
sha256(data) {
|
|
163
|
-
const hash =
|
|
164
|
-
return
|
|
163
|
+
const hash = import_node_crypto.default.createHash("sha256").update(toBuffer(data)).digest();
|
|
164
|
+
return toUint8Array(hash);
|
|
165
165
|
},
|
|
166
166
|
sha256Hex(data) {
|
|
167
|
-
return
|
|
167
|
+
return import_node_crypto.default.createHash("sha256").update(toBuffer(data)).digest("hex");
|
|
168
168
|
},
|
|
169
169
|
hmacSha256(key, data) {
|
|
170
|
-
const hmac2 =
|
|
171
|
-
return
|
|
170
|
+
const hmac2 = import_node_crypto.default.createHmac("sha256", Buffer.from(key)).update(Buffer.from(data)).digest();
|
|
171
|
+
return toUint8Array(hmac2);
|
|
172
172
|
},
|
|
173
173
|
hkdfSha256(ikm, salt, info, length) {
|
|
174
174
|
const ikmBuf = Buffer.from(ikm);
|
|
175
175
|
const saltBuf = salt.length > 0 ? Buffer.from(salt) : Buffer.alloc(32);
|
|
176
|
-
const prk =
|
|
176
|
+
const prk = import_node_crypto.default.createHmac("sha256", saltBuf).update(ikmBuf).digest();
|
|
177
177
|
const hashLen = 32;
|
|
178
178
|
const n = Math.ceil(length / hashLen);
|
|
179
179
|
const chunks = [];
|
|
180
180
|
let prev = Buffer.alloc(0);
|
|
181
181
|
for (let i = 1; i <= n; i++) {
|
|
182
|
-
prev =
|
|
182
|
+
prev = import_node_crypto.default.createHmac("sha256", prk).update(Buffer.concat([prev, Buffer.from(info), Buffer.from([i])])).digest();
|
|
183
183
|
chunks.push(prev);
|
|
184
184
|
}
|
|
185
|
-
return
|
|
185
|
+
return toUint8Array(Buffer.concat(chunks).subarray(0, length));
|
|
186
186
|
},
|
|
187
187
|
encryptAesGcm(key, plaintext, iv) {
|
|
188
|
-
const cipher =
|
|
188
|
+
const cipher = import_node_crypto.default.createCipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
189
189
|
const encrypted = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
|
|
190
190
|
const tag = cipher.getAuthTag();
|
|
191
191
|
return {
|
|
192
|
-
ciphertext:
|
|
193
|
-
tag:
|
|
192
|
+
ciphertext: toUint8Array(encrypted),
|
|
193
|
+
tag: toUint8Array(tag)
|
|
194
194
|
};
|
|
195
195
|
},
|
|
196
196
|
decryptAesGcm(key, ciphertext, iv, tag) {
|
|
197
|
-
const decipher =
|
|
197
|
+
const decipher = import_node_crypto.default.createDecipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
198
198
|
decipher.setAuthTag(Buffer.from(tag));
|
|
199
199
|
const decrypted = Buffer.concat([decipher.update(Buffer.from(ciphertext)), decipher.final()]);
|
|
200
|
-
return
|
|
200
|
+
return toUint8Array(decrypted);
|
|
201
201
|
},
|
|
202
202
|
timingSafeEqual(a, b) {
|
|
203
203
|
if (a.length !== b.length) return false;
|
|
204
|
-
return
|
|
204
|
+
return import_node_crypto.default.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
|
-
function
|
|
208
|
-
const kid = `rsa-key-${Date.now()}-${
|
|
209
|
-
const { privateKey, publicKey } =
|
|
207
|
+
function generateRsaKeyPair3(modulusLength = 2048, alg = "RS256") {
|
|
208
|
+
const kid = `rsa-key-${Date.now()}-${import_node_crypto.default.randomBytes(8).toString("hex")}`;
|
|
209
|
+
const { privateKey, publicKey } = import_node_crypto.default.generateKeyPairSync("rsa", {
|
|
210
210
|
modulusLength
|
|
211
211
|
});
|
|
212
212
|
const exported = publicKey.export({ format: "jwk" });
|
|
@@ -219,66 +219,66 @@ var require_node = __commonJS({
|
|
|
219
219
|
};
|
|
220
220
|
return { privateKey, publicKey, publicJwk };
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function rsaSign(algorithm, data, privateKey, options) {
|
|
223
223
|
const signingKey = options ? { key: privateKey, ...options } : privateKey;
|
|
224
|
-
return
|
|
224
|
+
return import_node_crypto.default.sign(algorithm, data, signingKey);
|
|
225
225
|
}
|
|
226
|
-
function
|
|
227
|
-
const publicKey =
|
|
228
|
-
const nodeAlgorithm =
|
|
226
|
+
function rsaVerify3(jwtAlg, data, publicJwk, signature) {
|
|
227
|
+
const publicKey = import_node_crypto.default.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
228
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
229
229
|
const verifyKey = isRsaPssAlg2(jwtAlg) ? {
|
|
230
230
|
key: publicKey,
|
|
231
|
-
padding:
|
|
232
|
-
saltLength:
|
|
231
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
232
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
233
233
|
} : publicKey;
|
|
234
|
-
return
|
|
234
|
+
return import_node_crypto.default.verify(nodeAlgorithm, data, verifyKey, signature);
|
|
235
235
|
}
|
|
236
|
-
function
|
|
237
|
-
const privateKey =
|
|
238
|
-
const nodeAlgorithm =
|
|
236
|
+
function rsaSignBase64Url3(jwtAlg, data, privateJwk) {
|
|
237
|
+
const privateKey = import_node_crypto.default.createPrivateKey({ key: privateJwk, format: "jwk" });
|
|
238
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
239
239
|
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
240
|
-
const sig = isRsaPssAlg2(jwtAlg) ?
|
|
241
|
-
padding:
|
|
242
|
-
saltLength:
|
|
243
|
-
}) :
|
|
240
|
+
const sig = isRsaPssAlg2(jwtAlg) ? rsaSign(nodeAlgorithm, buf, privateKey, {
|
|
241
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
242
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
243
|
+
}) : rsaSign(nodeAlgorithm, buf, privateKey);
|
|
244
244
|
return sig.toString("base64url");
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function rsaVerifySync3(jwtAlg, data, publicJwk, signature) {
|
|
247
247
|
try {
|
|
248
|
-
const publicKey =
|
|
248
|
+
const publicKey = import_node_crypto.default.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
249
249
|
const dataBuf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
250
250
|
const sigBuf = Buffer.isBuffer(signature) ? signature : Buffer.from(signature);
|
|
251
251
|
if (jwtAlg === "EdDSA") {
|
|
252
|
-
return
|
|
252
|
+
return import_node_crypto.default.verify(null, dataBuf, publicKey, sigBuf);
|
|
253
253
|
}
|
|
254
|
-
const nodeAlgorithm =
|
|
254
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
255
255
|
const verifyKey = isRsaPssAlg2(jwtAlg) ? {
|
|
256
256
|
key: publicKey,
|
|
257
|
-
padding:
|
|
258
|
-
saltLength:
|
|
257
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
258
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
259
259
|
} : publicKey;
|
|
260
|
-
return
|
|
260
|
+
return import_node_crypto.default.verify(nodeAlgorithm, dataBuf, verifyKey, sigBuf);
|
|
261
261
|
} catch {
|
|
262
262
|
return false;
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
function
|
|
266
|
-
const key =
|
|
265
|
+
function pemToPublicJwk3(pem) {
|
|
266
|
+
const key = import_node_crypto.default.createPublicKey({ key: pem, format: "pem" });
|
|
267
267
|
return key.export({ format: "jwk" });
|
|
268
268
|
}
|
|
269
|
-
function
|
|
269
|
+
function createSignedJwt(payload, privateKey, kid, alg = "RS256") {
|
|
270
270
|
const header = { alg, typ: "JWT", kid };
|
|
271
271
|
const headerB64 = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
272
272
|
const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
273
273
|
const signatureInput = `${headerB64}.${payloadB64}`;
|
|
274
|
-
const nodeAlgorithm =
|
|
275
|
-
const signature =
|
|
274
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(alg);
|
|
275
|
+
const signature = rsaSign(
|
|
276
276
|
nodeAlgorithm,
|
|
277
277
|
Buffer.from(signatureInput),
|
|
278
278
|
privateKey,
|
|
279
279
|
isRsaPssAlg2(alg) ? {
|
|
280
|
-
padding:
|
|
281
|
-
saltLength:
|
|
280
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
281
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
282
282
|
} : void 0
|
|
283
283
|
);
|
|
284
284
|
const signatureB64 = signature.toString("base64url");
|
|
@@ -302,13 +302,12 @@ import {
|
|
|
302
302
|
import { z } from "@frontmcp/lazy-zod";
|
|
303
303
|
var import_event_emitter = __toESM(require_node_event_emitter(), 1);
|
|
304
304
|
import { z as z2 } from "@frontmcp/lazy-zod";
|
|
305
|
-
var
|
|
306
|
-
import
|
|
307
|
-
import { sha256 as sha256Hash } from "@noble/hashes/sha2.js";
|
|
308
|
-
import { hmac } from "@noble/hashes/hmac.js";
|
|
305
|
+
var platformCrypto = __toESM(require_node(), 1);
|
|
306
|
+
import { gcm } from "@noble/ciphers/aes.js";
|
|
309
307
|
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
308
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
309
|
+
import { sha256 as sha256Hash } from "@noble/hashes/sha2.js";
|
|
310
310
|
import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils.js";
|
|
311
|
-
import { gcm } from "@noble/ciphers/aes.js";
|
|
312
311
|
import { analyzeForReDoS, REDOS_THRESHOLDS } from "@enclave-vm/ast";
|
|
313
312
|
var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : void 0;
|
|
314
313
|
var require2 = __frontmcpModule ? __frontmcpModule.createRequire(import.meta.url || "file:///") : void 0;
|
|
@@ -414,13 +413,6 @@ var init_fs2 = __esm({
|
|
|
414
413
|
init_fs();
|
|
415
414
|
}
|
|
416
415
|
});
|
|
417
|
-
function jwtAlgToNodeAlg(jwtAlg) {
|
|
418
|
-
const nodeAlg = JWT_ALG_TO_NODE_DIGEST[jwtAlg];
|
|
419
|
-
if (!nodeAlg) {
|
|
420
|
-
throw new Error(`Unsupported JWT algorithm: ${jwtAlg}`);
|
|
421
|
-
}
|
|
422
|
-
return nodeAlg;
|
|
423
|
-
}
|
|
424
416
|
function isRsaPssAlg(jwtAlg) {
|
|
425
417
|
return jwtAlg.startsWith("PS");
|
|
426
418
|
}
|
|
@@ -2207,176 +2199,18 @@ var init_key_persistence2 = __esm({
|
|
|
2207
2199
|
init_factory();
|
|
2208
2200
|
}
|
|
2209
2201
|
});
|
|
2210
|
-
var node_exports = {};
|
|
2211
|
-
__export(node_exports, {
|
|
2212
|
-
createSignedJwt: () => createSignedJwt,
|
|
2213
|
-
cryptoProvider: () => nodeCrypto,
|
|
2214
|
-
generateRsaKeyPair: () => generateRsaKeyPair,
|
|
2215
|
-
isRsaPssAlg: () => isRsaPssAlg,
|
|
2216
|
-
jwtAlgToNodeAlg: () => jwtAlgToNodeAlg,
|
|
2217
|
-
nodeCrypto: () => nodeCrypto,
|
|
2218
|
-
pemToPublicJwk: () => pemToPublicJwk,
|
|
2219
|
-
rsaSign: () => rsaSign,
|
|
2220
|
-
rsaSignBase64Url: () => rsaSignBase64Url,
|
|
2221
|
-
rsaVerify: () => rsaVerify,
|
|
2222
|
-
rsaVerifySync: () => rsaVerifySync
|
|
2223
|
-
});
|
|
2224
|
-
function toUint8Array(buf) {
|
|
2225
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
2226
|
-
}
|
|
2227
|
-
function toBuffer(data) {
|
|
2228
|
-
if (typeof data === "string") {
|
|
2229
|
-
return Buffer.from(data, "utf8");
|
|
2230
|
-
}
|
|
2231
|
-
return Buffer.from(data);
|
|
2232
|
-
}
|
|
2233
|
-
function generateRsaKeyPair(modulusLength = 2048, alg = "RS256") {
|
|
2234
|
-
const kid = `rsa-key-${Date.now()}-${crypto2.randomBytes(8).toString("hex")}`;
|
|
2235
|
-
const { privateKey, publicKey } = crypto2.generateKeyPairSync("rsa", {
|
|
2236
|
-
modulusLength
|
|
2237
|
-
});
|
|
2238
|
-
const exported = publicKey.export({ format: "jwk" });
|
|
2239
|
-
const publicJwk = {
|
|
2240
|
-
...exported,
|
|
2241
|
-
kid,
|
|
2242
|
-
alg,
|
|
2243
|
-
use: "sig",
|
|
2244
|
-
kty: "RSA"
|
|
2245
|
-
};
|
|
2246
|
-
return { privateKey, publicKey, publicJwk };
|
|
2247
|
-
}
|
|
2248
|
-
function rsaSign(algorithm, data, privateKey, options) {
|
|
2249
|
-
const signingKey = options ? { key: privateKey, ...options } : privateKey;
|
|
2250
|
-
return crypto2.sign(algorithm, data, signingKey);
|
|
2251
|
-
}
|
|
2252
|
-
function rsaVerify(jwtAlg, data, publicJwk, signature) {
|
|
2253
|
-
const publicKey = crypto2.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
2254
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
2255
|
-
const verifyKey = isRsaPssAlg(jwtAlg) ? {
|
|
2256
|
-
key: publicKey,
|
|
2257
|
-
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
2258
|
-
saltLength: crypto2.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2259
|
-
} : publicKey;
|
|
2260
|
-
return crypto2.verify(nodeAlgorithm, data, verifyKey, signature);
|
|
2261
|
-
}
|
|
2262
|
-
function rsaSignBase64Url(jwtAlg, data, privateJwk) {
|
|
2263
|
-
const privateKey = crypto2.createPrivateKey({ key: privateJwk, format: "jwk" });
|
|
2264
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
2265
|
-
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
2266
|
-
const sig = isRsaPssAlg(jwtAlg) ? rsaSign(nodeAlgorithm, buf, privateKey, {
|
|
2267
|
-
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
2268
|
-
saltLength: crypto2.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2269
|
-
}) : rsaSign(nodeAlgorithm, buf, privateKey);
|
|
2270
|
-
return sig.toString("base64url");
|
|
2271
|
-
}
|
|
2272
|
-
function rsaVerifySync(jwtAlg, data, publicJwk, signature) {
|
|
2273
|
-
try {
|
|
2274
|
-
const publicKey = crypto2.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
2275
|
-
const dataBuf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
2276
|
-
const sigBuf = Buffer.isBuffer(signature) ? signature : Buffer.from(signature);
|
|
2277
|
-
if (jwtAlg === "EdDSA") {
|
|
2278
|
-
return crypto2.verify(null, dataBuf, publicKey, sigBuf);
|
|
2279
|
-
}
|
|
2280
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
2281
|
-
const verifyKey = isRsaPssAlg(jwtAlg) ? {
|
|
2282
|
-
key: publicKey,
|
|
2283
|
-
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
2284
|
-
saltLength: crypto2.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2285
|
-
} : publicKey;
|
|
2286
|
-
return crypto2.verify(nodeAlgorithm, dataBuf, verifyKey, sigBuf);
|
|
2287
|
-
} catch {
|
|
2288
|
-
return false;
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
function pemToPublicJwk(pem) {
|
|
2292
|
-
const key = crypto2.createPublicKey({ key: pem, format: "pem" });
|
|
2293
|
-
return key.export({ format: "jwk" });
|
|
2294
|
-
}
|
|
2295
|
-
function createSignedJwt(payload, privateKey, kid, alg = "RS256") {
|
|
2296
|
-
const header = { alg, typ: "JWT", kid };
|
|
2297
|
-
const headerB64 = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
2298
|
-
const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
2299
|
-
const signatureInput = `${headerB64}.${payloadB64}`;
|
|
2300
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(alg);
|
|
2301
|
-
const signature = rsaSign(
|
|
2302
|
-
nodeAlgorithm,
|
|
2303
|
-
Buffer.from(signatureInput),
|
|
2304
|
-
privateKey,
|
|
2305
|
-
isRsaPssAlg(alg) ? {
|
|
2306
|
-
padding: crypto2.constants.RSA_PKCS1_PSS_PADDING,
|
|
2307
|
-
saltLength: crypto2.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2308
|
-
} : void 0
|
|
2309
|
-
);
|
|
2310
|
-
const signatureB64 = signature.toString("base64url");
|
|
2311
|
-
return `${headerB64}.${payloadB64}.${signatureB64}`;
|
|
2312
|
-
}
|
|
2313
|
-
var nodeCrypto;
|
|
2314
|
-
var init_node = __esm({
|
|
2315
|
-
"libs/utils/src/crypto/node.ts"() {
|
|
2316
|
-
"use strict";
|
|
2317
|
-
init_jwt_alg();
|
|
2318
|
-
init_jwt_alg();
|
|
2319
|
-
nodeCrypto = {
|
|
2320
|
-
randomUUID() {
|
|
2321
|
-
return crypto2.randomUUID();
|
|
2322
|
-
},
|
|
2323
|
-
randomBytes(length) {
|
|
2324
|
-
return toUint8Array(crypto2.randomBytes(length));
|
|
2325
|
-
},
|
|
2326
|
-
sha256(data) {
|
|
2327
|
-
const hash = crypto2.createHash("sha256").update(toBuffer(data)).digest();
|
|
2328
|
-
return toUint8Array(hash);
|
|
2329
|
-
},
|
|
2330
|
-
sha256Hex(data) {
|
|
2331
|
-
return crypto2.createHash("sha256").update(toBuffer(data)).digest("hex");
|
|
2332
|
-
},
|
|
2333
|
-
hmacSha256(key, data) {
|
|
2334
|
-
const hmac2 = crypto2.createHmac("sha256", Buffer.from(key)).update(Buffer.from(data)).digest();
|
|
2335
|
-
return toUint8Array(hmac2);
|
|
2336
|
-
},
|
|
2337
|
-
hkdfSha256(ikm, salt, info, length) {
|
|
2338
|
-
const ikmBuf = Buffer.from(ikm);
|
|
2339
|
-
const saltBuf = salt.length > 0 ? Buffer.from(salt) : Buffer.alloc(32);
|
|
2340
|
-
const prk = crypto2.createHmac("sha256", saltBuf).update(ikmBuf).digest();
|
|
2341
|
-
const hashLen = 32;
|
|
2342
|
-
const n = Math.ceil(length / hashLen);
|
|
2343
|
-
const chunks = [];
|
|
2344
|
-
let prev = Buffer.alloc(0);
|
|
2345
|
-
for (let i = 1; i <= n; i++) {
|
|
2346
|
-
prev = crypto2.createHmac("sha256", prk).update(Buffer.concat([prev, Buffer.from(info), Buffer.from([i])])).digest();
|
|
2347
|
-
chunks.push(prev);
|
|
2348
|
-
}
|
|
2349
|
-
return toUint8Array(Buffer.concat(chunks).subarray(0, length));
|
|
2350
|
-
},
|
|
2351
|
-
encryptAesGcm(key, plaintext, iv) {
|
|
2352
|
-
const cipher = crypto2.createCipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
2353
|
-
const encrypted = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
|
|
2354
|
-
const tag = cipher.getAuthTag();
|
|
2355
|
-
return {
|
|
2356
|
-
ciphertext: toUint8Array(encrypted),
|
|
2357
|
-
tag: toUint8Array(tag)
|
|
2358
|
-
};
|
|
2359
|
-
},
|
|
2360
|
-
decryptAesGcm(key, ciphertext, iv, tag) {
|
|
2361
|
-
const decipher = crypto2.createDecipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
2362
|
-
decipher.setAuthTag(Buffer.from(tag));
|
|
2363
|
-
const decrypted = Buffer.concat([decipher.update(Buffer.from(ciphertext)), decipher.final()]);
|
|
2364
|
-
return toUint8Array(decrypted);
|
|
2365
|
-
},
|
|
2366
|
-
timingSafeEqual(a, b) {
|
|
2367
|
-
if (a.length !== b.length) return false;
|
|
2368
|
-
return crypto2.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
2369
|
-
}
|
|
2370
|
-
};
|
|
2371
|
-
}
|
|
2372
|
-
});
|
|
2373
2202
|
var browser_exports = {};
|
|
2374
2203
|
__export(browser_exports, {
|
|
2375
2204
|
browserCrypto: () => browserCrypto,
|
|
2376
2205
|
cryptoProvider: () => browserCrypto,
|
|
2206
|
+
generateRsaKeyPair: () => generateRsaKeyPair2,
|
|
2377
2207
|
isRsaPssAlg: () => isRsaPssAlg,
|
|
2378
2208
|
jwtAlgToWebCryptoAlg: () => jwtAlgToWebCryptoAlg,
|
|
2379
|
-
|
|
2209
|
+
pemToPublicJwk: () => pemToPublicJwk2,
|
|
2210
|
+
rsaSignBase64Url: () => rsaSignBase64Url2,
|
|
2211
|
+
rsaVerify: () => rsaVerify2,
|
|
2212
|
+
rsaVerifyBrowser: () => rsaVerifyBrowser,
|
|
2213
|
+
rsaVerifySync: () => rsaVerifySync2
|
|
2380
2214
|
});
|
|
2381
2215
|
function toBytes(data) {
|
|
2382
2216
|
if (typeof data === "string") {
|
|
@@ -2405,6 +2239,24 @@ function constantTimeEqual(a, b) {
|
|
|
2405
2239
|
}
|
|
2406
2240
|
return result === 0;
|
|
2407
2241
|
}
|
|
2242
|
+
function nodeOnly(name) {
|
|
2243
|
+
throw new Error(`${name} is only available in Node.js runtimes`);
|
|
2244
|
+
}
|
|
2245
|
+
function rsaVerify2() {
|
|
2246
|
+
return nodeOnly("rsaVerify");
|
|
2247
|
+
}
|
|
2248
|
+
function rsaSignBase64Url2() {
|
|
2249
|
+
return nodeOnly("rsaSignBase64Url");
|
|
2250
|
+
}
|
|
2251
|
+
function rsaVerifySync2() {
|
|
2252
|
+
return nodeOnly("rsaVerifySync");
|
|
2253
|
+
}
|
|
2254
|
+
function pemToPublicJwk2() {
|
|
2255
|
+
return nodeOnly("pemToPublicJwk");
|
|
2256
|
+
}
|
|
2257
|
+
function generateRsaKeyPair2() {
|
|
2258
|
+
return nodeOnly("generateRsaKeyPair");
|
|
2259
|
+
}
|
|
2408
2260
|
async function rsaVerifyBrowser(jwtAlg, data, publicJwk, signature) {
|
|
2409
2261
|
if (typeof globalThis.crypto?.subtle === "undefined") {
|
|
2410
2262
|
throw new Error("WebCrypto API (crypto.subtle) is not available in this environment");
|
|
@@ -2483,7 +2335,7 @@ var init_browser = __esm({
|
|
|
2483
2335
|
}
|
|
2484
2336
|
});
|
|
2485
2337
|
function getCrypto() {
|
|
2486
|
-
return
|
|
2338
|
+
return platformCrypto.cryptoProvider;
|
|
2487
2339
|
}
|
|
2488
2340
|
function randomUUID() {
|
|
2489
2341
|
return getCrypto().randomUUID();
|
|
@@ -2597,6 +2449,71 @@ var init_redis_error_listener = __esm({
|
|
|
2597
2449
|
DEFAULT_REDIS_ERROR_LOG_INTERVAL_MS = 3e4;
|
|
2598
2450
|
}
|
|
2599
2451
|
});
|
|
2452
|
+
function decodeOrRaw(encoded) {
|
|
2453
|
+
try {
|
|
2454
|
+
return decodeURIComponent(encoded);
|
|
2455
|
+
} catch {
|
|
2456
|
+
return encoded;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
function integerOrUndefined(text) {
|
|
2460
|
+
const value = Number.parseInt(text ?? "", 10);
|
|
2461
|
+
return Number.isNaN(value) ? void 0 : value;
|
|
2462
|
+
}
|
|
2463
|
+
function readRedisUrl(rawUrl) {
|
|
2464
|
+
let url;
|
|
2465
|
+
try {
|
|
2466
|
+
url = new URL(rawUrl);
|
|
2467
|
+
} catch {
|
|
2468
|
+
return void 0;
|
|
2469
|
+
}
|
|
2470
|
+
if (url.protocol !== "redis:" && url.protocol !== "rediss:") return void 0;
|
|
2471
|
+
const query = Object.fromEntries(url.searchParams);
|
|
2472
|
+
const { host, port, username, password, db, ...otherOptions } = query;
|
|
2473
|
+
const queryOptions = {};
|
|
2474
|
+
for (const [name, value = ""] of Object.entries(otherOptions)) {
|
|
2475
|
+
queryOptions[name] = name === "family" ? integerOrUndefined(value) ?? value : value;
|
|
2476
|
+
}
|
|
2477
|
+
return {
|
|
2478
|
+
host: url.hostname.replace(/^\[(.*)\]$/, "$1") || host,
|
|
2479
|
+
port: integerOrUndefined(url.port || port),
|
|
2480
|
+
username: decodeOrRaw(url.username) || username || void 0,
|
|
2481
|
+
password: decodeOrRaw(url.password) || password || void 0,
|
|
2482
|
+
db: integerOrUndefined(url.pathname.replace(/^\/+/, "") || db),
|
|
2483
|
+
tls: url.protocol === "rediss:",
|
|
2484
|
+
queryOptions
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
function mergeRedisUrlFields(rawUrl, fields) {
|
|
2488
|
+
const connection = readRedisUrl(rawUrl);
|
|
2489
|
+
if (!connection) return void 0;
|
|
2490
|
+
const fillIns = {};
|
|
2491
|
+
const conflicts = [];
|
|
2492
|
+
if (fields.host !== void 0 && fields.host !== connection.host) conflicts.push("host");
|
|
2493
|
+
if (fields.port !== void 0) {
|
|
2494
|
+
if (connection.port === void 0) fillIns.port = fields.port;
|
|
2495
|
+
else if (fields.port !== connection.port) conflicts.push("port");
|
|
2496
|
+
}
|
|
2497
|
+
if (fields.password !== void 0) {
|
|
2498
|
+
if (connection.password === void 0) fillIns.password = fields.password;
|
|
2499
|
+
else if (fields.password !== connection.password) conflicts.push("password");
|
|
2500
|
+
}
|
|
2501
|
+
if (fields.db !== void 0) {
|
|
2502
|
+
if (connection.db === void 0) fillIns.db = fields.db;
|
|
2503
|
+
else if (fields.db !== connection.db) conflicts.push("db");
|
|
2504
|
+
}
|
|
2505
|
+
if (fields.tls === true && !connection.tls) fillIns.tls = true;
|
|
2506
|
+
if (fields.tls === false && connection.tls) conflicts.push("tls");
|
|
2507
|
+
return { connection, fillIns, conflicts };
|
|
2508
|
+
}
|
|
2509
|
+
function describeRedisUrlConflicts(conflicts) {
|
|
2510
|
+
return `redis ${conflicts.join(", ")} contradict${conflicts.length === 1 ? "s" : ""} redis.url. Fields beside a url only fill in what the URL leaves out (port, password, db, tls); put the value in the URL or drop the field.`;
|
|
2511
|
+
}
|
|
2512
|
+
var init_redis_url = __esm({
|
|
2513
|
+
"libs/utils/src/storage/redis-url.ts"() {
|
|
2514
|
+
"use strict";
|
|
2515
|
+
}
|
|
2516
|
+
});
|
|
2600
2517
|
var init_utils = __esm({
|
|
2601
2518
|
"libs/utils/src/storage/utils/index.ts"() {
|
|
2602
2519
|
"use strict";
|
|
@@ -2631,17 +2548,49 @@ function getRedisClass() {
|
|
|
2631
2548
|
});
|
|
2632
2549
|
}
|
|
2633
2550
|
}
|
|
2551
|
+
function resolveUrlOptions(connectionUrl, options) {
|
|
2552
|
+
const { url: configUrl, ...siblingFields } = { url: void 0, ...options.config };
|
|
2553
|
+
if (options.url && configUrl && configUrl !== options.url) {
|
|
2554
|
+
throw new StorageConfigError("redis", "redis.url and redis.config.url name different servers; set one of them.");
|
|
2555
|
+
}
|
|
2556
|
+
return urlConnectionOptions(connectionUrl, siblingFields);
|
|
2557
|
+
}
|
|
2558
|
+
function urlConnectionOptions(url, fields) {
|
|
2559
|
+
const merge = mergeRedisUrlFields(url, fields);
|
|
2560
|
+
if (!merge) return void 0;
|
|
2561
|
+
if (merge.conflicts.length > 0) {
|
|
2562
|
+
throw new StorageConfigError("redis", describeRedisUrlConflicts(merge.conflicts));
|
|
2563
|
+
}
|
|
2564
|
+
const { queryOptions, tls, ...stated } = merge.connection;
|
|
2565
|
+
return { ...queryOptions, ...stated, ...toFillInOptions(merge.fillIns), ...tls ? { tls: {} } : {} };
|
|
2566
|
+
}
|
|
2567
|
+
function toFillInOptions({ port, password, db, tls }) {
|
|
2568
|
+
return {
|
|
2569
|
+
...port !== void 0 ? { port } : {},
|
|
2570
|
+
...password !== void 0 ? { password } : {},
|
|
2571
|
+
...db !== void 0 ? { db } : {},
|
|
2572
|
+
...tls ? { tls: {} } : {}
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2634
2575
|
function createRedisClient(options) {
|
|
2576
|
+
const urlOptions = options.url ? urlConnectionOptions(options.url, options) : void 0;
|
|
2635
2577
|
const RedisClass = getRedisClass();
|
|
2636
2578
|
const baseOptions = { lazyConnect: false, maxRetriesPerRequest: 3 };
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2579
|
+
let client;
|
|
2580
|
+
if (urlOptions) {
|
|
2581
|
+
client = new RedisClass({ ...baseOptions, ...urlOptions });
|
|
2582
|
+
} else if (options.url) {
|
|
2583
|
+
client = new RedisClass(options.url, baseOptions);
|
|
2584
|
+
} else {
|
|
2585
|
+
client = new RedisClass({
|
|
2586
|
+
...baseOptions,
|
|
2587
|
+
host: options.host ?? "localhost",
|
|
2588
|
+
port: options.port ?? 6379,
|
|
2589
|
+
password: options.password,
|
|
2590
|
+
db: options.db ?? 0,
|
|
2591
|
+
tls: options.tls ? {} : void 0
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2645
2594
|
attachRedisErrorListener(client, { label: options.label ?? "redis", logger: options.logger });
|
|
2646
2595
|
return client;
|
|
2647
2596
|
}
|
|
@@ -2651,6 +2600,7 @@ var init_redis = __esm({
|
|
|
2651
2600
|
"use strict";
|
|
2652
2601
|
init_errors();
|
|
2653
2602
|
init_redis_error_listener();
|
|
2603
|
+
init_redis_url();
|
|
2654
2604
|
init_utils();
|
|
2655
2605
|
init_compare_and_delete();
|
|
2656
2606
|
init_base();
|
|
@@ -2664,6 +2614,9 @@ var init_redis = __esm({
|
|
|
2664
2614
|
connecting;
|
|
2665
2615
|
keyPrefix;
|
|
2666
2616
|
subscriptionHandlers = /* @__PURE__ */ new Map();
|
|
2617
|
+
connectionUrl;
|
|
2618
|
+
/** The connection options of a URL this adapter reads itself; undefined for one only ioredis reads. */
|
|
2619
|
+
urlOptions;
|
|
2667
2620
|
constructor(options = {}) {
|
|
2668
2621
|
super();
|
|
2669
2622
|
const hasClient = options.client !== void 0;
|
|
@@ -2685,6 +2638,9 @@ var init_redis = __esm({
|
|
|
2685
2638
|
this.options = options;
|
|
2686
2639
|
this.ownsClient = !hasClient;
|
|
2687
2640
|
this.keyPrefix = options.keyPrefix ?? "";
|
|
2641
|
+
const configUrl = options.config?.url;
|
|
2642
|
+
this.connectionUrl = options.url ?? (typeof configUrl === "string" ? configUrl : void 0);
|
|
2643
|
+
this.urlOptions = this.connectionUrl ? resolveUrlOptions(this.connectionUrl, options) : void 0;
|
|
2688
2644
|
}
|
|
2689
2645
|
// ============================================
|
|
2690
2646
|
// Connection Lifecycle
|
|
@@ -2706,12 +2662,7 @@ var init_redis = __esm({
|
|
|
2706
2662
|
if (this.options.client) {
|
|
2707
2663
|
client = this.options.client;
|
|
2708
2664
|
} else {
|
|
2709
|
-
|
|
2710
|
-
if (this.options.url) {
|
|
2711
|
-
client = new RedisClass(this.options.url, this.buildRedisOptions());
|
|
2712
|
-
} else {
|
|
2713
|
-
client = new RedisClass(this.buildRedisOptions());
|
|
2714
|
-
}
|
|
2665
|
+
client = this.newClient();
|
|
2715
2666
|
client.on("error", recordSocketError);
|
|
2716
2667
|
}
|
|
2717
2668
|
await client.ping();
|
|
@@ -2944,14 +2895,11 @@ var init_redis = __esm({
|
|
|
2944
2895
|
* Build Redis options from config.
|
|
2945
2896
|
*/
|
|
2946
2897
|
buildRedisOptions() {
|
|
2947
|
-
if (this.
|
|
2948
|
-
return {
|
|
2949
|
-
lazyConnect: false,
|
|
2950
|
-
maxRetriesPerRequest: 3
|
|
2951
|
-
};
|
|
2898
|
+
if (this.connectionUrl) {
|
|
2899
|
+
return { lazyConnect: false, maxRetriesPerRequest: 3, ...this.urlOptions };
|
|
2952
2900
|
}
|
|
2953
2901
|
const config = this.options.config;
|
|
2954
|
-
if (!config) {
|
|
2902
|
+
if (!config || typeof config.url === "string" || config.host === void 0) {
|
|
2955
2903
|
throw new StorageConfigError("redis", "Redis config is required when URL is not provided");
|
|
2956
2904
|
}
|
|
2957
2905
|
return {
|
|
@@ -2964,16 +2912,23 @@ var init_redis = __esm({
|
|
|
2964
2912
|
maxRetriesPerRequest: 3
|
|
2965
2913
|
};
|
|
2966
2914
|
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Create a client this adapter owns. A URL only ioredis reads goes to it as is.
|
|
2917
|
+
*/
|
|
2918
|
+
newClient() {
|
|
2919
|
+
const RedisClass = getRedisClass();
|
|
2920
|
+
if (this.connectionUrl && !this.urlOptions) {
|
|
2921
|
+
return new RedisClass(this.connectionUrl, this.buildRedisOptions());
|
|
2922
|
+
}
|
|
2923
|
+
return new RedisClass(this.buildRedisOptions());
|
|
2924
|
+
}
|
|
2967
2925
|
/**
|
|
2968
2926
|
* Create subscriber connection.
|
|
2969
2927
|
*/
|
|
2970
2928
|
async createSubscriber() {
|
|
2971
|
-
const RedisClass = getRedisClass();
|
|
2972
2929
|
let subscriber;
|
|
2973
|
-
if (this.options.
|
|
2974
|
-
subscriber =
|
|
2975
|
-
} else if (this.options.config) {
|
|
2976
|
-
subscriber = new RedisClass(this.buildRedisOptions());
|
|
2930
|
+
if (this.connectionUrl || this.options.config) {
|
|
2931
|
+
subscriber = this.newClient();
|
|
2977
2932
|
} else if (this.options.client) {
|
|
2978
2933
|
subscriber = this.options.client.duplicate();
|
|
2979
2934
|
} else {
|
|
@@ -3020,7 +2975,8 @@ var init_redis = __esm({
|
|
|
3020
2975
|
});
|
|
3021
2976
|
var vercel_kv_exports = {};
|
|
3022
2977
|
__export(vercel_kv_exports, {
|
|
3023
|
-
VercelKvStorageAdapter: () => VercelKvStorageAdapter
|
|
2978
|
+
VercelKvStorageAdapter: () => VercelKvStorageAdapter,
|
|
2979
|
+
createVercelKvClient: () => createVercelKvClient
|
|
3024
2980
|
});
|
|
3025
2981
|
async function loadVercelKv() {
|
|
3026
2982
|
try {
|
|
@@ -3032,6 +2988,15 @@ async function loadVercelKv() {
|
|
|
3032
2988
|
throw new Error("@vercel/kv is required for Vercel KV storage adapter. Install it with: npm install @vercel/kv");
|
|
3033
2989
|
}
|
|
3034
2990
|
}
|
|
2991
|
+
async function createVercelKvClient(connection = {}) {
|
|
2992
|
+
const url = connection.url ?? process.env["KV_REST_API_URL"];
|
|
2993
|
+
const token = connection.token ?? process.env["KV_REST_API_TOKEN"];
|
|
2994
|
+
if (!url || !token) {
|
|
2995
|
+
throw new StorageConfigError("vercel-kv", "Pass url and token, or set KV_REST_API_URL and KV_REST_API_TOKEN.");
|
|
2996
|
+
}
|
|
2997
|
+
const { createClient } = await loadVercelKv();
|
|
2998
|
+
return createClient({ url, token, cache: void 0, automaticDeserialization: false });
|
|
2999
|
+
}
|
|
3035
3000
|
var VercelKvStorageAdapter;
|
|
3036
3001
|
var init_vercel_kv = __esm({
|
|
3037
3002
|
"libs/utils/src/storage/adapters/vercel-kv.ts"() {
|
|
@@ -3064,13 +3029,7 @@ var init_vercel_kv = __esm({
|
|
|
3064
3029
|
async connect() {
|
|
3065
3030
|
if (this.connected) return;
|
|
3066
3031
|
try {
|
|
3067
|
-
|
|
3068
|
-
const url = this.options.url;
|
|
3069
|
-
const token = this.options.token;
|
|
3070
|
-
if (!url || !token) {
|
|
3071
|
-
throw new StorageConfigError("vercel-kv", "URL and token are required");
|
|
3072
|
-
}
|
|
3073
|
-
this.client = createClient({ url, token, cache: void 0, automaticDeserialization: false });
|
|
3032
|
+
this.client = await createVercelKvClient({ url: this.options.url, token: this.options.token });
|
|
3074
3033
|
await this.client.exists("__healthcheck__");
|
|
3075
3034
|
this.connected = true;
|
|
3076
3035
|
} catch (e) {
|
|
@@ -3241,9 +3200,12 @@ var upstash_exports = {};
|
|
|
3241
3200
|
__export(upstash_exports, {
|
|
3242
3201
|
UpstashStorageAdapter: () => UpstashStorageAdapter
|
|
3243
3202
|
});
|
|
3244
|
-
function
|
|
3203
|
+
async function loadUpstashRedis() {
|
|
3245
3204
|
try {
|
|
3246
|
-
|
|
3205
|
+
const mod = await import("@upstash/redis");
|
|
3206
|
+
const resolved = typeof mod.Redis === "function" ? mod : mod.default;
|
|
3207
|
+
if (!resolved || typeof resolved.Redis !== "function") throw new Error("Redis missing");
|
|
3208
|
+
return resolved;
|
|
3247
3209
|
} catch {
|
|
3248
3210
|
throw new Error(
|
|
3249
3211
|
"@upstash/redis is required for Upstash storage adapter. Install it with: npm install @upstash/redis"
|
|
@@ -3289,7 +3251,7 @@ var init_upstash = __esm({
|
|
|
3289
3251
|
async connect() {
|
|
3290
3252
|
if (this.connected) return;
|
|
3291
3253
|
try {
|
|
3292
|
-
const { Redis: Redis2 } =
|
|
3254
|
+
const { Redis: Redis2 } = await loadUpstashRedis();
|
|
3293
3255
|
const url = this.options.url;
|
|
3294
3256
|
const token = this.options.token;
|
|
3295
3257
|
if (!url || !token) {
|
|
@@ -3778,6 +3740,7 @@ init_errors();
|
|
|
3778
3740
|
init_errors();
|
|
3779
3741
|
init_memory();
|
|
3780
3742
|
init_redis_error_listener();
|
|
3743
|
+
init_redis_url();
|
|
3781
3744
|
init_errors();
|
|
3782
3745
|
init_crypto();
|
|
3783
3746
|
init_errors();
|
|
@@ -3962,11 +3925,11 @@ CacheRedisProvider = __decorateClass([
|
|
|
3962
3925
|
// plugins/plugin-cache/src/providers/cache-vercel-kv.provider.ts
|
|
3963
3926
|
import { Provider as Provider3, ProviderScope as ProviderScope3 } from "@frontmcp/sdk";
|
|
3964
3927
|
var CacheVercelKvProvider = class {
|
|
3965
|
-
|
|
3928
|
+
connection;
|
|
3929
|
+
client;
|
|
3966
3930
|
keyPrefix;
|
|
3967
3931
|
defaultTTL;
|
|
3968
3932
|
constructor(options = {}) {
|
|
3969
|
-
const vercelKv = __require("@vercel/kv");
|
|
3970
3933
|
const hasUrl = options.url !== void 0;
|
|
3971
3934
|
const hasToken = options.token !== void 0;
|
|
3972
3935
|
if (hasUrl !== hasToken) {
|
|
@@ -3974,17 +3937,21 @@ var CacheVercelKvProvider = class {
|
|
|
3974
3937
|
`CacheVercelKvProvider: Both 'url' and 'token' must be provided together, or neither. Received: url=${hasUrl ? "provided" : "missing"}, token=${hasToken ? "provided" : "missing"}`
|
|
3975
3938
|
);
|
|
3976
3939
|
}
|
|
3977
|
-
|
|
3978
|
-
this.kv = vercelKv.createClient({
|
|
3979
|
-
url: options.url,
|
|
3980
|
-
token: options.token
|
|
3981
|
-
});
|
|
3982
|
-
} else {
|
|
3983
|
-
this.kv = vercelKv.kv;
|
|
3984
|
-
}
|
|
3940
|
+
this.connection = { url: options.url, token: options.token };
|
|
3985
3941
|
this.keyPrefix = options.keyPrefix ?? "cache:";
|
|
3986
3942
|
this.defaultTTL = options.defaultTTL ?? 60 * 60 * 24;
|
|
3987
3943
|
}
|
|
3944
|
+
/**
|
|
3945
|
+
* The client, built on first use from the url and token (or KV_REST_API_URL / KV_REST_API_TOKEN)
|
|
3946
|
+
* by the shared loader, which a Cloudflare Worker can bundle (#711). A failed attempt is retried.
|
|
3947
|
+
*/
|
|
3948
|
+
kv() {
|
|
3949
|
+
this.client ??= createVercelKvClient(this.connection).catch((error) => {
|
|
3950
|
+
this.client = void 0;
|
|
3951
|
+
throw error;
|
|
3952
|
+
});
|
|
3953
|
+
return this.client;
|
|
3954
|
+
}
|
|
3988
3955
|
prefixKey(key) {
|
|
3989
3956
|
return `${this.keyPrefix}${key}`;
|
|
3990
3957
|
}
|
|
@@ -3992,15 +3959,17 @@ var CacheVercelKvProvider = class {
|
|
|
3992
3959
|
async setValue(key, value, ttlSeconds) {
|
|
3993
3960
|
const strValue = typeof value === "string" ? value : JSON.stringify(value);
|
|
3994
3961
|
const ttl = ttlSeconds ?? this.defaultTTL;
|
|
3962
|
+
const kv = await this.kv();
|
|
3995
3963
|
if (ttl > 0) {
|
|
3996
|
-
await
|
|
3964
|
+
await kv.set(this.prefixKey(key), strValue, { ex: ttl });
|
|
3997
3965
|
} else {
|
|
3998
|
-
await
|
|
3966
|
+
await kv.set(this.prefixKey(key), strValue);
|
|
3999
3967
|
}
|
|
4000
3968
|
}
|
|
4001
3969
|
/** Get a value and automatically parse JSON if possible */
|
|
4002
3970
|
async getValue(key, defaultValue) {
|
|
4003
|
-
const
|
|
3971
|
+
const kv = await this.kv();
|
|
3972
|
+
const raw = await kv.get(this.prefixKey(key));
|
|
4004
3973
|
if (raw === null || raw === void 0) return defaultValue;
|
|
4005
3974
|
if (typeof raw === "string") {
|
|
4006
3975
|
try {
|
|
@@ -4013,11 +3982,13 @@ var CacheVercelKvProvider = class {
|
|
|
4013
3982
|
}
|
|
4014
3983
|
/** Delete a key */
|
|
4015
3984
|
async delete(key) {
|
|
4016
|
-
await this.kv
|
|
3985
|
+
const kv = await this.kv();
|
|
3986
|
+
await kv.del(this.prefixKey(key));
|
|
4017
3987
|
}
|
|
4018
3988
|
/** Check if a key exists */
|
|
4019
3989
|
async exists(key) {
|
|
4020
|
-
|
|
3990
|
+
const kv = await this.kv();
|
|
3991
|
+
return await kv.exists(this.prefixKey(key)) === 1;
|
|
4021
3992
|
}
|
|
4022
3993
|
/** Gracefully close the provider (no-op for Vercel KV - stateless REST API) */
|
|
4023
3994
|
async close() {
|