fastmcp 4.29.2 → 4.30.0

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  cancelResponseBody
3
- } from "./chunk-PA3GWZUK.js";
3
+ } from "./chunk-XPTUOWUT.js";
4
4
  import {
5
5
  objectRootSchema,
6
6
  strictInputSchema,
@@ -3699,4 +3699,4 @@ export {
3699
3699
  FastMCPSession,
3700
3700
  FastMCP
3701
3701
  };
3702
- //# sourceMappingURL=chunk-T7EFBHCA.js.map
3702
+ //# sourceMappingURL=chunk-5KA6SOWT.js.map
@@ -3273,6 +3273,8 @@ var OAuthProvider = class extends AuthProvider {
3273
3273
  var _promises = require('fs/promises');
3274
3274
  var _path = require('path');
3275
3275
  var _promises3 = require('timers/promises');
3276
+ var MAX_ENCODED_KEY_LENGTH = 180;
3277
+ var MAX_FILE_NAME_BYTES = 255;
3276
3278
  var DiskStore = (_class5 = class {
3277
3279
  __init9() {this.cleanupInterval = null}
3278
3280
 
@@ -3322,12 +3324,13 @@ var DiskStore = (_class5 = class {
3322
3324
  * Delete a value
3323
3325
  */
3324
3326
  async delete(key) {
3325
- const filePath = this.getFilePath(key);
3326
- try {
3327
- await _promises.rm.call(void 0, filePath);
3328
- } catch (error) {
3329
- if (error.code !== "ENOENT") {
3330
- console.error(`Failed to delete key ${key}:`, error);
3327
+ for (const filePath of this.getFilePaths(key)) {
3328
+ try {
3329
+ await _promises.rm.call(void 0, filePath);
3330
+ } catch (error) {
3331
+ if (error.code !== "ENOENT") {
3332
+ console.error(`Failed to delete key ${key}:`, error);
3333
+ }
3331
3334
  }
3332
3335
  }
3333
3336
  }
@@ -3344,22 +3347,24 @@ var DiskStore = (_class5 = class {
3344
3347
  * Retrieve a value
3345
3348
  */
3346
3349
  async get(key) {
3347
- const filePath = this.getFilePath(key);
3348
- try {
3349
- const content = await _promises.readFile.call(void 0, filePath, "utf-8");
3350
- const entry = JSON.parse(content);
3351
- if (entry.expiresAt < Date.now()) {
3352
- await _promises.rm.call(void 0, filePath);
3353
- return null;
3354
- }
3355
- return entry.value;
3356
- } catch (error) {
3357
- if (error.code === "ENOENT") {
3350
+ for (const filePath of this.getFilePaths(key)) {
3351
+ try {
3352
+ const content = await _promises.readFile.call(void 0, filePath, "utf-8");
3353
+ const entry = JSON.parse(content);
3354
+ if (entry.expiresAt < Date.now()) {
3355
+ await _promises.rm.call(void 0, filePath);
3356
+ return null;
3357
+ }
3358
+ return entry.value;
3359
+ } catch (error) {
3360
+ if (error.code === "ENOENT") {
3361
+ continue;
3362
+ }
3363
+ console.error(`Failed to read key ${key}:`, error);
3358
3364
  return null;
3359
3365
  }
3360
- console.error(`Failed to read key ${key}:`, error);
3361
- return null;
3362
3366
  }
3367
+ return null;
3363
3368
  }
3364
3369
  /**
3365
3370
  * Save a value with optional TTL
@@ -3384,6 +3389,10 @@ var DiskStore = (_class5 = class {
3384
3389
  console.error(`Failed to save key ${key}:`, error);
3385
3390
  throw error;
3386
3391
  }
3392
+ const legacyPath = this.getLegacyFilePath(key);
3393
+ if (legacyPath !== void 0 && legacyPath !== filePath) {
3394
+ await _promises.rm.call(void 0, legacyPath, { force: true });
3395
+ }
3387
3396
  }
3388
3397
  /**
3389
3398
  * Get the number of stored items
@@ -3406,14 +3415,21 @@ var DiskStore = (_class5 = class {
3406
3415
  * process shares the directory.
3407
3416
  */
3408
3417
  async take(key) {
3409
- const filePath = this.getFilePath(key);
3410
- const claimPath = `${filePath}.${_crypto.randomUUID.call(void 0, )}.claim${this.fileExtension}`;
3411
- try {
3412
- await _promises.rename.call(void 0, filePath, claimPath);
3413
- } catch (error) {
3414
- if (error.code !== "ENOENT") {
3415
- console.error(`Failed to take key ${key}:`, error);
3418
+ let claimPath;
3419
+ for (const filePath of this.getFilePaths(key)) {
3420
+ const candidate = `${filePath}.${_crypto.randomUUID.call(void 0, )}.claim${this.fileExtension}`;
3421
+ try {
3422
+ await _promises.rename.call(void 0, filePath, candidate);
3423
+ claimPath = candidate;
3424
+ break;
3425
+ } catch (error) {
3426
+ if (error.code !== "ENOENT") {
3427
+ console.error(`Failed to take key ${key}:`, error);
3428
+ return null;
3429
+ }
3416
3430
  }
3431
+ }
3432
+ if (claimPath === void 0) {
3417
3433
  return null;
3418
3434
  }
3419
3435
  try {
@@ -3445,11 +3461,46 @@ var DiskStore = (_class5 = class {
3445
3461
  }
3446
3462
  }
3447
3463
  /**
3448
- * Get file path for a key
3464
+ * Get file path for a key.
3465
+ *
3466
+ * The file name must not let a key escape the directory, and distinct keys
3467
+ * must get distinct files, also on case-insensitive filesystems (the macOS
3468
+ * and Windows defaults). Lowercase letters, digits and `-` are kept; every
3469
+ * other UTF-8 byte, uppercase letters and `_` included, becomes `_` and two
3470
+ * lowercase hex digits, so neither `client:a.b` and `client:a_b` nor
3471
+ * `code:A` and `code:a` share a file. Names that would get too long for
3472
+ * common filesystems are replaced by a SHA-256 digest, under a prefix the
3473
+ * escaping above never produces.
3449
3474
  */
3450
3475
  getFilePath(key) {
3451
- const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
3452
- return _path.join.call(void 0, this.directory, `${sanitizedKey}${this.fileExtension}`);
3476
+ let name = "";
3477
+ for (const byte of Buffer.from(key, "utf8")) {
3478
+ const char = String.fromCharCode(byte);
3479
+ name += /[a-z0-9-]/.test(char) ? char : `_${byte.toString(16).padStart(2, "0")}`;
3480
+ }
3481
+ if (name.length > MAX_ENCODED_KEY_LENGTH) {
3482
+ name = `_sha256_${_crypto.createHash.call(void 0, "sha256").update(key, "utf8").digest("hex")}`;
3483
+ }
3484
+ return _path.join.call(void 0, this.directory, `${name}${this.fileExtension}`);
3485
+ }
3486
+ /**
3487
+ * The paths a key's entry may be stored at: its current file, then the
3488
+ * file name earlier versions used. The earlier scheme replaced every other
3489
+ * character with `_`, so distinct keys could share a file; it is still read
3490
+ * so that entries persisted before an upgrade survive it.
3491
+ */
3492
+ getFilePaths(key) {
3493
+ const filePath = this.getFilePath(key);
3494
+ const legacyPath = this.getLegacyFilePath(key);
3495
+ return legacyPath === void 0 || legacyPath === filePath ? [filePath] : [filePath, legacyPath];
3496
+ }
3497
+ /**
3498
+ * The file name earlier versions stored a key under, or `undefined` when
3499
+ * that name is too long to have ever been written.
3500
+ */
3501
+ getLegacyFilePath(key) {
3502
+ const name = `${key.replace(/[^a-zA-Z0-9_-]/g, "_")}${this.fileExtension}`;
3503
+ return Buffer.byteLength(name) > MAX_FILE_NAME_BYTES ? void 0 : _path.join.call(void 0, this.directory, name);
3453
3504
  }
3454
3505
  /**
3455
3506
  * Windows can temporarily deny replacing a file that is being read. Retry
@@ -3637,4 +3688,4 @@ Original error: ${error.message}`
3637
3688
 
3638
3689
 
3639
3690
  exports.cancelResponseBody = cancelResponseBody; exports.getAuthSession = getAuthSession; exports.requireAll = requireAll; exports.requireAny = requireAny; exports.requireAuth = requireAuth; exports.requireRole = requireRole; exports.requireScopes = requireScopes; exports.DEFAULT_ACCESS_TOKEN_TTL = DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_REFRESH_TOKEN_TTL = DEFAULT_REFRESH_TOKEN_TTL; exports.TOKEN_ENDPOINT_AUTH_METHODS = TOKEN_ENDPOINT_AUTH_METHODS; exports.DEFAULT_AUTHORIZATION_CODE_TTL = DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_TRANSACTION_TTL = DEFAULT_TRANSACTION_TTL; exports.ConsentManager = ConsentManager; exports.JWTIssuer = JWTIssuer; exports.PKCEUtils = PKCEUtils; exports.EncryptedTokenStorage = EncryptedTokenStorage; exports.MemoryTokenStorage = MemoryTokenStorage; exports.OAuthProxy = OAuthProxy; exports.OAuthProxyError = OAuthProxyError; exports.AuthProvider = AuthProvider; exports.AzureProvider = AzureProvider; exports.GitHubProvider = GitHubProvider; exports.GoogleProvider = GoogleProvider; exports.OAuthProvider = OAuthProvider; exports.DiskStore = DiskStore; exports.JWKSVerifier = JWKSVerifier;
3640
- //# sourceMappingURL=chunk-XP4NENWX.cjs.map
3691
+ //# sourceMappingURL=chunk-CZGQ2WTQ.cjs.map