@1mcp/agent 0.12.0 → 0.13.1

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.
Files changed (183) hide show
  1. package/README.md +22 -37
  2. package/build/auth/sdkOAuthClientProvider.d.ts +93 -0
  3. package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -0
  4. package/build/auth/sdkOAuthClientProvider.js +204 -0
  5. package/build/auth/sdkOAuthClientProvider.js.map +1 -0
  6. package/build/auth/sdkOAuthServerProvider.d.ts +64 -0
  7. package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -0
  8. package/build/auth/sdkOAuthServerProvider.js +359 -0
  9. package/build/auth/sdkOAuthServerProvider.js.map +1 -0
  10. package/build/auth/sessionTypes.d.ts +38 -0
  11. package/build/auth/sessionTypes.d.ts.map +1 -0
  12. package/build/auth/sessionTypes.js +3 -0
  13. package/build/auth/sessionTypes.js.map +1 -0
  14. package/build/auth/storage/authCodeRepository.d.ts +25 -0
  15. package/build/auth/storage/authCodeRepository.d.ts.map +1 -0
  16. package/build/auth/storage/authCodeRepository.js +50 -0
  17. package/build/auth/storage/authCodeRepository.js.map +1 -0
  18. package/build/auth/storage/authRequestRepository.d.ts +25 -0
  19. package/build/auth/storage/authRequestRepository.d.ts.map +1 -0
  20. package/build/auth/storage/authRequestRepository.js +51 -0
  21. package/build/auth/storage/authRequestRepository.js.map +1 -0
  22. package/build/auth/storage/clientDataRepository.d.ts +25 -0
  23. package/build/auth/storage/clientDataRepository.d.ts.map +1 -0
  24. package/build/auth/storage/clientDataRepository.js +45 -0
  25. package/build/auth/storage/clientDataRepository.js.map +1 -0
  26. package/build/auth/storage/clientSessionRepository.d.ts +77 -0
  27. package/build/auth/storage/clientSessionRepository.d.ts.map +1 -0
  28. package/build/auth/storage/clientSessionRepository.js +120 -0
  29. package/build/auth/storage/clientSessionRepository.js.map +1 -0
  30. package/build/auth/storage/fileStorageService.d.ts +68 -0
  31. package/build/auth/storage/fileStorageService.d.ts.map +1 -0
  32. package/build/auth/storage/fileStorageService.js +262 -0
  33. package/build/auth/storage/fileStorageService.js.map +1 -0
  34. package/build/auth/storage/oauthStorageService.d.ts +57 -0
  35. package/build/auth/storage/oauthStorageService.d.ts.map +1 -0
  36. package/build/auth/storage/oauthStorageService.js +131 -0
  37. package/build/auth/storage/oauthStorageService.js.map +1 -0
  38. package/build/auth/storage/sessionRepository.d.ts +29 -0
  39. package/build/auth/storage/sessionRepository.d.ts.map +1 -0
  40. package/build/auth/storage/sessionRepository.js +64 -0
  41. package/build/auth/storage/sessionRepository.js.map +1 -0
  42. package/build/capabilities/capabilityManager.d.ts +2 -2
  43. package/build/capabilities/capabilityManager.d.ts.map +1 -1
  44. package/build/capabilities/capabilityManager.js +1 -1
  45. package/build/capabilities/capabilityManager.js.map +1 -1
  46. package/build/config/{configManager.d.ts → mcpConfigManager.d.ts} +11 -6
  47. package/build/config/mcpConfigManager.d.ts.map +1 -0
  48. package/build/config/{configManager.js → mcpConfigManager.js} +26 -8
  49. package/build/config/mcpConfigManager.js.map +1 -0
  50. package/build/constants.d.ts +51 -14
  51. package/build/constants.d.ts.map +1 -1
  52. package/build/constants.js +61 -17
  53. package/build/constants.js.map +1 -1
  54. package/build/core/client/clientManager.d.ts +14 -6
  55. package/build/core/client/clientManager.d.ts.map +1 -1
  56. package/build/core/client/clientManager.js +90 -28
  57. package/build/core/client/clientManager.js.map +1 -1
  58. package/build/core/server/{serverConfig.d.ts → agentConfig.d.ts} +50 -15
  59. package/build/core/server/agentConfig.d.ts.map +1 -0
  60. package/build/core/server/agentConfig.js +166 -0
  61. package/build/core/server/agentConfig.js.map +1 -0
  62. package/build/core/server/serverManager.d.ts +12 -5
  63. package/build/core/server/serverManager.d.ts.map +1 -1
  64. package/build/core/server/serverManager.js +12 -2
  65. package/build/core/server/serverManager.js.map +1 -1
  66. package/build/core/types/client.d.ts +22 -9
  67. package/build/core/types/client.d.ts.map +1 -1
  68. package/build/core/types/client.js +2 -0
  69. package/build/core/types/client.js.map +1 -1
  70. package/build/core/types/server.d.ts +3 -3
  71. package/build/core/types/server.d.ts.map +1 -1
  72. package/build/core/types/transport.d.ts +58 -0
  73. package/build/core/types/transport.d.ts.map +1 -1
  74. package/build/core/types/transport.js +10 -0
  75. package/build/core/types/transport.js.map +1 -1
  76. package/build/handlers/notificationHandlers.d.ts +3 -3
  77. package/build/handlers/notificationHandlers.d.ts.map +1 -1
  78. package/build/handlers/notificationHandlers.js +2 -2
  79. package/build/handlers/notificationHandlers.js.map +1 -1
  80. package/build/handlers/requestHandlers.d.ts +2 -2
  81. package/build/handlers/requestHandlers.d.ts.map +1 -1
  82. package/build/handlers/requestHandlers.js +4 -3
  83. package/build/handlers/requestHandlers.js.map +1 -1
  84. package/build/index.js +47 -7
  85. package/build/index.js.map +1 -1
  86. package/build/{transport/http/middleware/loggingMiddleware.d.ts → logger/mcpLoggingEnhancer.d.ts} +1 -1
  87. package/build/logger/mcpLoggingEnhancer.d.ts.map +1 -0
  88. package/build/{transport/http/middleware/loggingMiddleware.js → logger/mcpLoggingEnhancer.js} +2 -2
  89. package/build/logger/mcpLoggingEnhancer.js.map +1 -0
  90. package/build/server.js +4 -4
  91. package/build/server.js.map +1 -1
  92. package/build/services/configReloadService.d.ts +2 -2
  93. package/build/services/configReloadService.d.ts.map +1 -1
  94. package/build/services/configReloadService.js +4 -4
  95. package/build/services/configReloadService.js.map +1 -1
  96. package/build/transport/http/middlewares/errorHandler.d.ts.map +1 -0
  97. package/build/transport/http/{errorHandler.js → middlewares/errorHandler.js} +1 -1
  98. package/build/transport/http/middlewares/errorHandler.js.map +1 -0
  99. package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +39 -0
  100. package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -0
  101. package/build/transport/http/middlewares/scopeAuthMiddleware.js +129 -0
  102. package/build/transport/http/middlewares/scopeAuthMiddleware.js.map +1 -0
  103. package/build/transport/http/middlewares/securityMiddleware.d.ts +30 -0
  104. package/build/transport/http/middlewares/securityMiddleware.d.ts.map +1 -0
  105. package/build/transport/http/middlewares/securityMiddleware.js +201 -0
  106. package/build/transport/http/middlewares/securityMiddleware.js.map +1 -0
  107. package/build/transport/http/middlewares/tagsExtractor.d.ts.map +1 -0
  108. package/build/transport/http/middlewares/tagsExtractor.js.map +1 -0
  109. package/build/transport/http/routes/oauthRoutes.d.ts +5 -11
  110. package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
  111. package/build/transport/http/routes/oauthRoutes.js +460 -122
  112. package/build/transport/http/routes/oauthRoutes.js.map +1 -1
  113. package/build/transport/http/routes/sseRoutes.d.ts +3 -2
  114. package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
  115. package/build/transport/http/routes/sseRoutes.js +10 -7
  116. package/build/transport/http/routes/sseRoutes.js.map +1 -1
  117. package/build/transport/http/routes/streamableHttpRoutes.d.ts +3 -2
  118. package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
  119. package/build/transport/http/routes/streamableHttpRoutes.js +17 -10
  120. package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
  121. package/build/transport/http/server.d.ts +3 -2
  122. package/build/transport/http/server.d.ts.map +1 -1
  123. package/build/transport/http/server.js +58 -21
  124. package/build/transport/http/server.js.map +1 -1
  125. package/build/transport/transportFactory.d.ts +9 -0
  126. package/build/transport/transportFactory.d.ts.map +1 -0
  127. package/build/transport/transportFactory.js +148 -0
  128. package/build/transport/transportFactory.js.map +1 -0
  129. package/build/utils/clientFiltering.d.ts +4 -4
  130. package/build/utils/clientFiltering.d.ts.map +1 -1
  131. package/build/utils/clientFiltering.js +54 -19
  132. package/build/utils/clientFiltering.js.map +1 -1
  133. package/build/utils/errorHandling.d.ts +0 -12
  134. package/build/utils/errorHandling.d.ts.map +1 -1
  135. package/build/utils/errorHandling.js +1 -42
  136. package/build/utils/errorHandling.js.map +1 -1
  137. package/build/utils/pagination.d.ts +2 -2
  138. package/build/utils/pagination.d.ts.map +1 -1
  139. package/build/utils/pagination.js +4 -4
  140. package/build/utils/pagination.js.map +1 -1
  141. package/build/utils/parsing.d.ts +13 -0
  142. package/build/utils/parsing.d.ts.map +1 -0
  143. package/build/utils/parsing.js +32 -0
  144. package/build/utils/parsing.js.map +1 -0
  145. package/build/utils/sanitization.d.ts +60 -0
  146. package/build/utils/sanitization.d.ts.map +1 -0
  147. package/build/utils/sanitization.js +149 -0
  148. package/build/utils/sanitization.js.map +1 -0
  149. package/build/utils/scopeValidation.d.ts +102 -0
  150. package/build/utils/scopeValidation.d.ts.map +1 -0
  151. package/build/utils/scopeValidation.js +244 -0
  152. package/build/utils/scopeValidation.js.map +1 -0
  153. package/package.json +20 -11
  154. package/build/auth/authManager.d.ts +0 -109
  155. package/build/auth/authManager.d.ts.map +0 -1
  156. package/build/auth/authManager.js +0 -173
  157. package/build/auth/authManager.js.map +0 -1
  158. package/build/auth/authMiddleware.d.ts +0 -16
  159. package/build/auth/authMiddleware.d.ts.map +0 -1
  160. package/build/auth/authMiddleware.js +0 -45
  161. package/build/auth/authMiddleware.js.map +0 -1
  162. package/build/auth/sessionManager.d.ts +0 -197
  163. package/build/auth/sessionManager.d.ts.map +0 -1
  164. package/build/auth/sessionManager.js +0 -408
  165. package/build/auth/sessionManager.js.map +0 -1
  166. package/build/config/configManager.d.ts.map +0 -1
  167. package/build/config/configManager.js.map +0 -1
  168. package/build/core/server/serverConfig.d.ts.map +0 -1
  169. package/build/core/server/serverConfig.js +0 -117
  170. package/build/core/server/serverConfig.js.map +0 -1
  171. package/build/transport/config.d.ts +0 -7
  172. package/build/transport/config.d.ts.map +0 -1
  173. package/build/transport/config.js +0 -90
  174. package/build/transport/config.js.map +0 -1
  175. package/build/transport/http/errorHandler.d.ts.map +0 -1
  176. package/build/transport/http/errorHandler.js.map +0 -1
  177. package/build/transport/http/middleware/loggingMiddleware.d.ts.map +0 -1
  178. package/build/transport/http/middleware/loggingMiddleware.js.map +0 -1
  179. package/build/utils/tagsExtractor.d.ts.map +0 -1
  180. package/build/utils/tagsExtractor.js.map +0 -1
  181. /package/build/transport/http/{errorHandler.d.ts → middlewares/errorHandler.d.ts} +0 -0
  182. /package/build/{utils → transport/http/middlewares}/tagsExtractor.d.ts +0 -0
  183. /package/build/{utils → transport/http/middlewares}/tagsExtractor.js +0 -0
@@ -1,173 +0,0 @@
1
- import logger from '../logger/logger.js';
2
- import { SessionManager } from './sessionManager.js';
3
- import { ServerConfigManager } from '../core/server/serverConfig.js';
4
- import { AUTH_CONFIG } from '../constants.js';
5
- import { v4 as uuidv4 } from 'uuid';
6
- /**
7
- * AuthManager handles OAuth 2.1 authentication flow and token validation.
8
- *
9
- * This class orchestrates the OAuth 2.1 authorization code grant flow,
10
- * manages access token validation, and provides session information.
11
- * It integrates with SessionManager for persistent storage and
12
- * ServerConfigManager for configuration settings.
13
- *
14
- * Features:
15
- * - OAuth 2.1 authorization code grant flow
16
- * - Access token validation with prefix support
17
- * - Session information retrieval
18
- * - Configurable authentication settings
19
- *
20
- * @example
21
- * ```typescript
22
- * const authManager = new AuthManager('/custom/sessions');
23
- * const token = authManager.exchangeCodeForToken('code-123', 'client-456');
24
- * const session = authManager.validateAccessToken('tk-sess-789');
25
- * ```
26
- */
27
- export class AuthManager {
28
- sessionManager;
29
- configManager;
30
- /**
31
- * Creates a new AuthManager instance.
32
- *
33
- * Initializes the session manager with optional custom storage path
34
- * and retrieves the server configuration manager instance.
35
- *
36
- * @param sessionStoragePath - Optional custom path for session storage
37
- */
38
- constructor(sessionStoragePath) {
39
- this.sessionManager = new SessionManager(sessionStoragePath);
40
- this.configManager = ServerConfigManager.getInstance();
41
- }
42
- /**
43
- * Checks if authentication is currently enabled.
44
- *
45
- * @returns True if OAuth 2.1 authentication is enabled, false otherwise
46
- */
47
- isAuthEnabled() {
48
- return this.configManager.isAuthEnabled();
49
- }
50
- /**
51
- * Validates an access token and returns session data.
52
- *
53
- * If authentication is disabled, returns null (always valid).
54
- * For enabled authentication, strips the token prefix if present
55
- * and validates the underlying session.
56
- *
57
- * @param token - The access token to validate (with or without prefix)
58
- * @returns Session data if token is valid, null otherwise
59
- */
60
- validateAccessToken(token) {
61
- if (!this.isAuthEnabled()) {
62
- return null; // Auth disabled, always valid
63
- }
64
- if (!token) {
65
- return null;
66
- }
67
- // Strip token prefix if present
68
- const tokenId = token.startsWith(AUTH_CONFIG.PREFIXES.ACCESS_TOKEN)
69
- ? token.slice(AUTH_CONFIG.PREFIXES.ACCESS_TOKEN.length)
70
- : token;
71
- // Session is stored with 'sess-' + tokenId
72
- const sessionId = AUTH_CONFIG.PREFIXES.SESSION_ID + tokenId;
73
- return this.sessionManager.getSession(sessionId);
74
- }
75
- /**
76
- * Creates an authorization code for OAuth 2.1 flow.
77
- *
78
- * Delegates to the session manager to create a prefixed authorization
79
- * code with the configured time-to-live.
80
- *
81
- * @param clientId - The client identifier
82
- * @param redirectUri - The redirect URI for this code
83
- * @param resource - The resource this code grants access to
84
- * @returns The generated authorization code with prefix
85
- */
86
- createAuthCode(clientId, redirectUri, resource) {
87
- const ttlMs = this.configManager.getOAuthCodeTtlMs();
88
- return this.sessionManager.createAuthCode(clientId, redirectUri, resource, ttlMs);
89
- }
90
- /**
91
- * Exchanges an authorization code for an access token.
92
- *
93
- * Validates the authorization code, checks client ID and redirect URI
94
- * matches, then creates a new access token with the configured TTL.
95
- * The authorization code is deleted after successful exchange.
96
- *
97
- * @param code - The authorization code to exchange
98
- * @param clientId - The client identifier
99
- * @param redirectUri - Optional redirect URI for validation
100
- * @param resource - Optional resource for validation
101
- * @returns Access token with prefix if exchange successful, null otherwise
102
- */
103
- exchangeCodeForToken(code, clientId, redirectUri, resource) {
104
- const codeData = this.sessionManager.getAuthCode(code);
105
- if (!codeData) {
106
- logger.warn(`Invalid or expired auth code: ${code}`);
107
- return null;
108
- }
109
- if (codeData.clientId !== clientId) {
110
- logger.warn(`Client ID mismatch for code ${code}: expected ${codeData.clientId}, got ${clientId}`);
111
- return null;
112
- }
113
- if (redirectUri && codeData.redirectUri !== redirectUri) {
114
- logger.warn(`Redirect URI mismatch for code ${code}: expected ${codeData.redirectUri}, got ${redirectUri}`);
115
- return null;
116
- }
117
- if (resource && codeData.resource && codeData.resource !== resource) {
118
- logger.warn(`Resource mismatch for code ${code}: expected ${codeData.resource}, got ${resource}`);
119
- return null;
120
- }
121
- // Delete the auth code after successful exchange
122
- this.sessionManager.deleteAuthCode(code);
123
- // Create access token with prefix and a new UUID
124
- const rawTokenId = uuidv4();
125
- const accessToken = AUTH_CONFIG.PREFIXES.ACCESS_TOKEN + rawTokenId;
126
- const ttlMs = this.configManager.getOAuthTokenTtlMs();
127
- // Store the session using the rawTokenId (not prefixed)
128
- this.sessionManager.createSessionWithId(rawTokenId, clientId, codeData.resource, ttlMs);
129
- logger.info(`Exchanged code ${code} for token ${accessToken} for client ${clientId}`);
130
- return accessToken;
131
- }
132
- /**
133
- * Gets information about an access token.
134
- *
135
- * Retrieves session data for the token and returns formatted
136
- * information including client ID, resource, and time until expiration.
137
- *
138
- * @param token - The access token to get information for
139
- * @returns Token information if valid, null otherwise
140
- */
141
- getTokenInfo(token) {
142
- const session = this.sessionManager.getSession(token);
143
- if (!session) {
144
- return null;
145
- }
146
- return {
147
- clientId: session.clientId,
148
- resource: session.resource,
149
- expiresIn: Math.max(0, Math.floor((session.expires - Date.now()) / 1000)),
150
- };
151
- }
152
- /**
153
- * Revokes an access token.
154
- *
155
- * Removes the session associated with the token from storage.
156
- *
157
- * @param token - The access token to revoke
158
- * @returns True if token was revoked, false if it didn't exist
159
- */
160
- revokeToken(token) {
161
- return this.sessionManager.deleteSession(token);
162
- }
163
- /**
164
- * Performs graceful shutdown of the AuthManager.
165
- *
166
- * Delegates shutdown to the session manager to ensure proper
167
- * cleanup of resources and timers.
168
- */
169
- shutdown() {
170
- this.sessionManager.shutdown();
171
- }
172
- }
173
- //# sourceMappingURL=authManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authManager.js","sourceRoot":"","sources":["../../src/auth/authManager.ts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Manager } from './authManager.js';
3
- export declare function createAuthMiddleware(authManager: AuthManager): (req: express.Request, res: express.Response, next: express.NextFunction) => void;
4
- declare global {
5
- namespace Express {
6
- interface Request {
7
- sessionData?: {
8
- clientId: string;
9
- resource: string;
10
- expires: number;
11
- createdAt: number;
12
- };
13
- }
14
- }
15
- }
16
- //# sourceMappingURL=authMiddleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authMiddleware.d.ts","sourceRoot":"","sources":["../../src/auth/authMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,IACnD,KAAK,OAAO,CAAC,OAAO,EAAE,KAAK,OAAO,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,YAAY,UA8ChF;AAGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,WAAW,CAAC,EAAE;gBACZ,QAAQ,EAAE,MAAM,CAAC;gBACjB,QAAQ,EAAE,MAAM,CAAC;gBACjB,OAAO,EAAE,MAAM,CAAC;gBAChB,SAAS,EAAE,MAAM,CAAC;aACnB,CAAC;SACH;KACF;CACF"}
@@ -1,45 +0,0 @@
1
- import logger from '../logger/logger.js';
2
- export function createAuthMiddleware(authManager) {
3
- return (req, res, next) => {
4
- // Skip auth if disabled
5
- if (!authManager.isAuthEnabled()) {
6
- return next();
7
- }
8
- const auth = req.headers['authorization'];
9
- if (!auth || !auth.startsWith('Bearer ')) {
10
- logger.warn('Missing Bearer token in request', {
11
- url: req.url,
12
- method: req.method,
13
- headers: req.headers,
14
- });
15
- res.status(401).json({
16
- error: 'invalid_token',
17
- error_description: 'Missing Bearer token',
18
- });
19
- return;
20
- }
21
- const token = auth.slice('Bearer '.length);
22
- const sessionData = authManager.validateAccessToken(token);
23
- if (!sessionData) {
24
- logger.warn('Invalid or expired token', {
25
- url: req.url,
26
- method: req.method,
27
- token: token.substring(0, 8) + '...',
28
- });
29
- res.status(401).json({
30
- error: 'invalid_token',
31
- error_description: 'Invalid or expired token',
32
- });
33
- return;
34
- }
35
- // Add session data to request for downstream use
36
- req.sessionData = sessionData;
37
- logger.debug('Valid token for request', {
38
- url: req.url,
39
- method: req.method,
40
- clientId: sessionData.clientId,
41
- });
42
- next();
43
- };
44
- }
45
- //# sourceMappingURL=authMiddleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authMiddleware.js","sourceRoot":"","sources":["../../src/auth/authMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAGzC,MAAM,UAAU,oBAAoB,CAAC,WAAwB;IAC3D,OAAO,CAAC,GAAoB,EAAE,GAAqB,EAAE,IAA0B,EAAE,EAAE;QACjF,wBAAwB;QACxB,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,CAAC;YACjC,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC,iCAAiC,EAAE;gBAC7C,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB,CAAC,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,eAAe;gBACtB,iBAAiB,EAAE,sBAAsB;aAC1C,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,WAAW,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAE3D,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE;gBACtC,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK;aACrC,CAAC,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,eAAe;gBACtB,iBAAiB,EAAE,0BAA0B;aAC9C,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,iDAAiD;QACjD,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE;YACtC,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,QAAQ,EAAE,WAAW,CAAC,QAAQ;SAC/B,CAAC,CAAC;QAEH,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
@@ -1,197 +0,0 @@
1
- /**
2
- * Represents session data stored for access tokens.
3
- *
4
- * Contains all necessary information to validate and manage user sessions
5
- * including client identification, resource access, and expiration details.
6
- */
7
- export interface SessionData {
8
- /** The client ID that owns this session */
9
- clientId: string;
10
- /** The resource this session has access to */
11
- resource: string;
12
- /** Unix timestamp when this session expires */
13
- expires: number;
14
- /** Unix timestamp when this session was created */
15
- createdAt: number;
16
- }
17
- /**
18
- * Represents authorization code data for OAuth 2.1 flow.
19
- *
20
- * Contains information about authorization codes used in the OAuth
21
- * authorization code grant flow, including client and redirect details.
22
- */
23
- export interface AuthCodeData {
24
- /** The client ID that requested this authorization code */
25
- clientId: string;
26
- /** The redirect URI where the code should be used */
27
- redirectUri: string;
28
- /** The resource this code grants access to */
29
- resource: string;
30
- /** Unix timestamp when this code expires */
31
- expires: number;
32
- /** Unix timestamp when this code was created */
33
- createdAt: number;
34
- }
35
- /**
36
- * SessionManager handles file-based session storage with automatic cleanup.
37
- *
38
- * This class manages OAuth 2.1 sessions and authorization codes using
39
- * the local filesystem. It provides automatic cleanup of expired sessions
40
- * and supports configurable storage locations.
41
- *
42
- * Features:
43
- * - File-based session storage with JSON format
44
- * - Automatic cleanup of expired sessions every 5 minutes
45
- * - Prefixed identifiers for easy debugging
46
- * - Configurable storage directory
47
- *
48
- * @example
49
- * ```typescript
50
- * const sessionManager = new SessionManager('/custom/path');
51
- * const sessionId = sessionManager.createSession('client-123', 'resource', 3600000);
52
- * const session = sessionManager.getSession(sessionId);
53
- * ```
54
- */
55
- export declare class SessionManager {
56
- private sessionStoragePath;
57
- private cleanupInterval;
58
- /**
59
- * Creates a new SessionManager instance.
60
- *
61
- * Initializes the session storage directory and starts the automatic
62
- * cleanup process for expired sessions.
63
- *
64
- * @param sessionStoragePath - Optional custom path for session storage
65
- */
66
- constructor(sessionStoragePath?: string);
67
- /**
68
- * Ensures the session storage directory exists.
69
- *
70
- * Creates the directory structure if it doesn't exist, including
71
- * parent directories as needed.
72
- *
73
- * @throws Error if directory creation fails
74
- */
75
- private ensureSessionDirectory;
76
- /**
77
- * Gets the file path for a session ID.
78
- *
79
- * @param sessionId - The session identifier
80
- * @returns Full file path for the session file
81
- */
82
- private getSessionFilePath;
83
- /**
84
- * Gets the file path for an authorization code.
85
- *
86
- * @param code - The authorization code
87
- * @returns Full file path for the auth code file
88
- */
89
- private getAuthCodeFilePath;
90
- /**
91
- * Utility to validate session IDs and auth codes for proper format and security.
92
- * Ensures proper format with prefix and UUID structure for security.
93
- * @param id - The session ID or auth code to validate
94
- * @returns true if valid, false otherwise
95
- */
96
- private isValidId;
97
- /**
98
- * Creates a new session with the specified parameters.
99
- *
100
- * Generates a unique session ID with prefix, stores the session data
101
- * as a JSON file, and returns the session identifier.
102
- *
103
- * @param clientId - The client identifier
104
- * @param resource - The resource this session can access
105
- * @param ttlMs - Time-to-live in milliseconds
106
- * @returns The generated session ID with prefix
107
- * @throws Error if session creation fails
108
- */
109
- createSession(clientId: string, resource: string, ttlMs: number): string;
110
- /**
111
- * Retrieves session data by session ID.
112
- *
113
- * Reads the session file and validates expiration. If the session
114
- * is expired, it's automatically deleted and null is returned.
115
- *
116
- * @param sessionId - The session identifier to retrieve
117
- * @returns Session data if valid and not expired, null otherwise
118
- */
119
- getSession(sessionId: string): SessionData | null;
120
- /**
121
- * Deletes a session by session ID.
122
- *
123
- * Removes the session file from the filesystem if it exists.
124
- *
125
- * @param sessionId - The session identifier to delete
126
- * @returns True if session was deleted, false if it didn't exist
127
- */
128
- deleteSession(sessionId: string): boolean;
129
- /**
130
- * Creates a new authorization code for OAuth 2.1 flow.
131
- *
132
- * Generates a unique authorization code with prefix, stores the code data
133
- * as a JSON file, and returns the code identifier.
134
- *
135
- * @param clientId - The client identifier
136
- * @param redirectUri - The redirect URI for this code
137
- * @param resource - The resource this code grants access to
138
- * @param ttlMs - Time-to-live in milliseconds
139
- * @returns The generated authorization code with prefix
140
- * @throws Error if code creation fails
141
- */
142
- createAuthCode(clientId: string, redirectUri: string, resource: string, ttlMs: number): string;
143
- /**
144
- * Retrieves authorization code data by code.
145
- *
146
- * Reads the auth code file and validates expiration. If the code
147
- * is expired, it's automatically deleted and null is returned.
148
- *
149
- * @param code - The authorization code to retrieve
150
- * @returns Auth code data if valid and not expired, null otherwise
151
- */
152
- getAuthCode(code: string): AuthCodeData | null;
153
- /**
154
- * Deletes an authorization code by code.
155
- *
156
- * Removes the auth code file from the filesystem if it exists.
157
- *
158
- * @param code - The authorization code to delete
159
- * @returns True if code was deleted, false if it didn't exist
160
- */
161
- deleteAuthCode(code: string): boolean;
162
- /**
163
- * Starts the automatic cleanup interval for expired sessions.
164
- *
165
- * Runs cleanup every 5 minutes to remove expired sessions and
166
- * authorization codes from the filesystem.
167
- */
168
- private startCleanupInterval;
169
- /**
170
- * Cleans up expired sessions and authorization codes.
171
- *
172
- * Scans the session storage directory and removes all expired
173
- * session and auth code files. Also handles corrupted files
174
- * by removing them to prevent future errors.
175
- */
176
- private cleanupExpiredSessions;
177
- /**
178
- * Performs graceful shutdown of the SessionManager.
179
- *
180
- * Stops the cleanup interval to prevent memory leaks and
181
- * ensures proper resource cleanup.
182
- */
183
- shutdown(): void;
184
- /**
185
- * Creates a new session with a custom ID (no prefix).
186
- * Used for access tokens where the token ID is generated separately.
187
- *
188
- * @param tokenId - The raw UUID to use for the session (no prefix)
189
- * @param clientId - The client identifier
190
- * @param resource - The resource this session can access
191
- * @param ttlMs - Time-to-live in milliseconds
192
- * @returns The generated session ID with prefix
193
- * @throws Error if session creation fails
194
- */
195
- createSessionWithId(tokenId: string, clientId: string, resource: string, ttlMs: number): string;
196
- }
197
- //# sourceMappingURL=sessionManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sessionManager.d.ts","sourceRoot":"","sources":["../../src/auth/sessionManager.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,kBAAkB,CAAS;IACnC,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