@vitemcp/server 1.2.0 → 1.3.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,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6;// src/auth/helpers.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7;// src/auth/helpers.ts
2
2
  function getAuthSession(session) {
3
3
  if (!session) {
4
4
  throw new Error("Session is not authenticated");
@@ -1394,16 +1394,24 @@ var OAuthProxy = (_class4 = class {
1394
1394
 
1395
1395
 
1396
1396
 
1397
+ /**
1398
+ * The fallback storage this proxy created for itself, if any. It runs a
1399
+ * cleanup timer that keeps the event loop alive, so `destroy()` has to stop
1400
+ * it — and once the storage is wrapped for encryption it is reachable
1401
+ * through nothing else. A caller-supplied storage is deliberately not
1402
+ * recorded here: its lifetime belongs to the caller.
1403
+ */
1404
+ __init7() {this.ownedTokenStorage = null}
1397
1405
  /**
1398
1406
  * Keyed by proxy-issued client_id for authorize/token-exchange lookups and
1399
1407
  * for the defence-in-depth callback checks. A registration never changes
1400
1408
  * after it is written, so caching it locally cannot go stale; it is also
1401
1409
  * persisted, so another instance can hydrate it.
1402
1410
  */
1403
- __init7() {this.registeredClientsByClientId = /* @__PURE__ */ new Map()}
1411
+ __init8() {this.registeredClientsByClientId = /* @__PURE__ */ new Map()}
1404
1412
 
1405
1413
 
1406
- constructor(config) {;_class4.prototype.__init5.call(this);_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);
1414
+ constructor(config) {;_class4.prototype.__init5.call(this);_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);
1407
1415
  this.config = {
1408
1416
  authorizationCodeTtl: DEFAULT_AUTHORIZATION_CODE_TTL,
1409
1417
  consentRequired: true,
@@ -1415,7 +1423,11 @@ var OAuthProxy = (_class4 = class {
1415
1423
  upstreamTokenEndpointAuthMethod: "client_secret_basic",
1416
1424
  ...config
1417
1425
  };
1418
- let storage = config.tokenStorage || new MemoryTokenStorage();
1426
+ let storage = config.tokenStorage;
1427
+ if (!storage) {
1428
+ this.ownedTokenStorage = new MemoryTokenStorage();
1429
+ storage = this.ownedTokenStorage;
1430
+ }
1419
1431
  const isAlreadyEncrypted = storage.constructor.name === "EncryptedTokenStorage";
1420
1432
  if (!isAlreadyEncrypted && config.encryptionKey !== false) {
1421
1433
  const encryptionKey = typeof config.encryptionKey === "string" ? config.encryptionKey : this.generateSigningKey();
@@ -1504,6 +1516,7 @@ var OAuthProxy = (_class4 = class {
1504
1516
  clearInterval(this.cleanupInterval);
1505
1517
  this.cleanupInterval = null;
1506
1518
  }
1519
+ _optionalChain([this, 'access', _10 => _10.ownedTokenStorage, 'optionalAccess', _11 => _11.destroy, 'call', _12 => _12()]);
1507
1520
  this.registeredClientsByClientId.clear();
1508
1521
  }
1509
1522
  /**
@@ -1728,7 +1741,7 @@ var OAuthProxy = (_class4 = class {
1728
1741
  return null;
1729
1742
  }
1730
1743
  const result = await this.jwtIssuer.verify(vitemcpToken);
1731
- if (!result.valid || !_optionalChain([result, 'access', _10 => _10.claims, 'optionalAccess', _11 => _11.jti])) {
1744
+ if (!result.valid || !_optionalChain([result, 'access', _13 => _13.claims, 'optionalAccess', _14 => _14.jti])) {
1732
1745
  return null;
1733
1746
  }
1734
1747
  const mapping = await this.tokenStorage.get(
@@ -1926,7 +1939,7 @@ var OAuthProxy = (_class4 = class {
1926
1939
  throw new Error("JWT issuer not initialized");
1927
1940
  }
1928
1941
  const result = await this.jwtIssuer.verify(token);
1929
- if (!result.valid || !_optionalChain([result, 'access', _12 => _12.claims, 'optionalAccess', _13 => _13.jti])) {
1942
+ if (!result.valid || !_optionalChain([result, 'access', _15 => _15.claims, 'optionalAccess', _16 => _16.jti])) {
1930
1943
  throw new Error("Failed to extract JTI from token");
1931
1944
  }
1932
1945
  return result.claims.jti;
@@ -2108,7 +2121,7 @@ var OAuthProxy = (_class4 = class {
2108
2121
  "Invalid or expired refresh token"
2109
2122
  );
2110
2123
  }
2111
- const jti = _optionalChain([verifyResult, 'access', _14 => _14.claims, 'optionalAccess', _15 => _15.jti]);
2124
+ const jti = _optionalChain([verifyResult, 'access', _17 => _17.claims, 'optionalAccess', _18 => _18.jti]);
2112
2125
  if (!jti) {
2113
2126
  throw new OAuthProxyError("invalid_grant", "Refresh token missing JTI");
2114
2127
  }
@@ -2587,19 +2600,33 @@ var OAuthProxyError = class extends Error {
2587
2600
  };
2588
2601
 
2589
2602
  // src/auth/providers/AuthProvider.ts
2590
- var AuthProvider = class {
2603
+ var AuthProvider = (_class5 = class {
2591
2604
 
2592
2605
  /**
2593
2606
  * Get the proxy, creating it lazily if needed.
2607
+ *
2608
+ * Refuses to rebuild after `destroy()`. Lazily replacing a torn-down proxy
2609
+ * would be silently wrong twice over: the replacement starts the very timers
2610
+ * `destroy()` released, and `ViteMCP` captured the original by reference when
2611
+ * it mounted the OAuth routes, so the token endpoint would keep answering
2612
+ * from the old instance while `authenticate()` verified against the new one —
2613
+ * with different auto-generated signing keys, every token minted by one is
2614
+ * invalid to the other.
2594
2615
  */
2595
2616
  get proxy() {
2617
+ if (this._destroyed) {
2618
+ throw new Error(
2619
+ "AuthProvider has been destroyed. Create a new provider rather than reusing this one."
2620
+ );
2621
+ }
2596
2622
  if (!this._proxy) {
2597
2623
  this._proxy = this.createProxy();
2598
2624
  }
2599
2625
  return this._proxy;
2600
2626
  }
2627
+ __init9() {this._destroyed = false}
2601
2628
 
2602
- constructor(config) {
2629
+ constructor(config) {;_class5.prototype.__init9.call(this);
2603
2630
  this.config = config;
2604
2631
  }
2605
2632
  /**
@@ -2621,6 +2648,28 @@ var AuthProvider = class {
2621
2648
  }
2622
2649
  return this.createSession(upstreamTokens);
2623
2650
  }
2651
+ /**
2652
+ * Release the resources held by the proxy this provider built for itself.
2653
+ *
2654
+ * That proxy runs two cleanup timers — its own sweep and its token
2655
+ * storage's — and both keep the Node event loop alive, so a process that has
2656
+ * stopped serving does not exit until this runs. `getProxy().destroy()`
2657
+ * reaches the same teardown; this exists so a caller holding only the
2658
+ * provider does not have to know that.
2659
+ *
2660
+ * Terminal: the provider will not serve again afterwards, and any later use
2661
+ * throws rather than quietly building a replacement. Call it when the process
2662
+ * is shutting down, after the HTTP server has finished draining — a request
2663
+ * still in flight would otherwise resurrect what this just released.
2664
+ *
2665
+ * Safe to call more than once, and a no-op if the lazy proxy was never
2666
+ * created.
2667
+ */
2668
+ destroy() {
2669
+ this._destroyed = true;
2670
+ _optionalChain([this, 'access', _19 => _19._proxy, 'optionalAccess', _20 => _20.destroy, 'call', _21 => _21()]);
2671
+ this._proxy = void 0;
2672
+ }
2624
2673
  /**
2625
2674
  * Get the OAuth configuration object for ViteMCP ServerOptions.
2626
2675
  */
@@ -2655,7 +2704,7 @@ var AuthProvider = class {
2655
2704
  scopes: upstreamTokens.scope
2656
2705
  };
2657
2706
  }
2658
- };
2707
+ }, _class5);
2659
2708
 
2660
2709
  // src/auth/providers/AzureProvider.ts
2661
2710
  var AzureProvider = class extends AuthProvider {
@@ -2810,11 +2859,11 @@ var OAuthProvider = class extends AuthProvider {
2810
2859
 
2811
2860
  var _promises = require('fs/promises');
2812
2861
  var _path = require('path');
2813
- var DiskStore = (_class5 = class {
2814
- __init8() {this.cleanupInterval = null}
2862
+ var DiskStore = (_class6 = class {
2863
+ __init10() {this.cleanupInterval = null}
2815
2864
 
2816
2865
 
2817
- constructor(options) {;_class5.prototype.__init8.call(this);
2866
+ constructor(options) {;_class6.prototype.__init10.call(this);
2818
2867
  this.directory = options.directory;
2819
2868
  this.fileExtension = options.fileExtension || ".json";
2820
2869
  void this.ensureDirectory();
@@ -2981,15 +3030,15 @@ var DiskStore = (_class5 = class {
2981
3030
  const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
2982
3031
  return _path.join.call(void 0, this.directory, `${sanitizedKey}${this.fileExtension}`);
2983
3032
  }
2984
- }, _class5);
3033
+ }, _class6);
2985
3034
 
2986
3035
  // src/auth/utils/jwks.ts
2987
- var JWKSVerifier = (_class6 = class {
3036
+ var JWKSVerifier = (_class7 = class {
2988
3037
 
2989
3038
 
2990
- __init9() {this.joseLoaded = false}
3039
+ __init11() {this.joseLoaded = false}
2991
3040
 
2992
- constructor(config) {;_class6.prototype.__init9.call(this);
3041
+ constructor(config) {;_class7.prototype.__init11.call(this);
2993
3042
  this.config = {
2994
3043
  cacheDuration: 36e5,
2995
3044
  // 1 hour
@@ -3118,7 +3167,7 @@ Original error: ${error.message}`
3118
3167
  }
3119
3168
  return [];
3120
3169
  }
3121
- }, _class6);
3170
+ }, _class7);
3122
3171
 
3123
3172
 
3124
3173
 
@@ -3147,4 +3196,4 @@ Original error: ${error.message}`
3147
3196
 
3148
3197
 
3149
3198
  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.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;
3150
- //# sourceMappingURL=chunk-MKS3TXYT.cjs.map
3199
+ //# sourceMappingURL=chunk-XC4BVJQZ.cjs.map