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