@frontmcp/auth 0.10.0 → 0.11.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.
- package/__test-utils__/assertion.helpers.d.ts +2 -0
- package/__test-utils__/assertion.helpers.d.ts.map +1 -0
- package/authorization/authorization.class.d.ts +122 -0
- package/authorization/authorization.class.d.ts.map +1 -0
- package/authorization/authorization.types.d.ts +65 -1
- package/authorization/authorization.types.d.ts.map +1 -1
- package/authorization/index.d.ts +11 -2
- package/authorization/index.d.ts.map +1 -1
- package/authorization/orchestrated.accessor.d.ts +161 -0
- package/authorization/orchestrated.accessor.d.ts.map +1 -0
- package/authorization/orchestrated.authorization.d.ts +257 -0
- package/authorization/orchestrated.authorization.d.ts.map +1 -0
- package/authorization/public.authorization.d.ts +92 -0
- package/authorization/public.authorization.d.ts.map +1 -0
- package/authorization/transparent.authorization.d.ts +130 -0
- package/authorization/transparent.authorization.d.ts.map +1 -0
- package/common/auth-logger.interface.d.ts +15 -0
- package/common/auth-logger.interface.d.ts.map +1 -0
- package/common/index.d.ts +6 -0
- package/common/index.d.ts.map +1 -0
- package/common/jwt.types.d.ts +87 -0
- package/common/jwt.types.d.ts.map +1 -0
- package/common/session-user.types.d.ts +17 -0
- package/common/session-user.types.d.ts.map +1 -0
- package/common/session.types.d.ts +190 -0
- package/common/session.types.d.ts.map +1 -0
- package/common/zod-utils.d.ts +5 -0
- package/common/zod-utils.d.ts.map +1 -0
- package/consent/consent.types.d.ts +112 -0
- package/consent/consent.types.d.ts.map +1 -0
- package/consent/index.d.ts +2 -0
- package/consent/index.d.ts.map +1 -0
- package/detection/auth-provider-detection.d.ts +53 -0
- package/detection/auth-provider-detection.d.ts.map +1 -0
- package/detection/index.d.ts +3 -0
- package/detection/index.d.ts.map +1 -0
- package/errors/auth-internal.error.d.ts +33 -0
- package/errors/auth-internal.error.d.ts.map +1 -0
- package/errors/auth-internal.errors.d.ts +123 -0
- package/errors/auth-internal.errors.d.ts.map +1 -0
- package/errors/index.d.ts +3 -0
- package/errors/index.d.ts.map +1 -0
- package/esm/index.mjs +5473 -1204
- package/esm/package.json +18 -3
- package/index.d.ts +18 -5
- package/index.d.ts.map +1 -1
- package/index.js +5351 -961
- package/jwks/jwks.service.d.ts +1 -0
- package/jwks/jwks.service.d.ts.map +1 -1
- package/jwks/jwks.types.d.ts +3 -0
- package/jwks/jwks.types.d.ts.map +1 -1
- package/machine-id/index.d.ts +2 -0
- package/machine-id/index.d.ts.map +1 -0
- package/machine-id/machine-id.d.ts +28 -0
- package/machine-id/machine-id.d.ts.map +1 -0
- package/options/app-auth.schema.d.ts +272 -0
- package/options/app-auth.schema.d.ts.map +1 -0
- package/options/index.d.ts +15 -0
- package/options/index.d.ts.map +1 -0
- package/options/interfaces.d.ts +250 -0
- package/options/interfaces.d.ts.map +1 -0
- package/options/orchestrated.schema.d.ts +446 -0
- package/options/orchestrated.schema.d.ts.map +1 -0
- package/options/public.schema.d.ts +19 -0
- package/options/public.schema.d.ts.map +1 -0
- package/options/schema.d.ts +265 -0
- package/options/schema.d.ts.map +1 -0
- package/options/shared.schemas.d.ts +128 -0
- package/options/shared.schemas.d.ts.map +1 -0
- package/options/transparent.schema.d.ts +33 -0
- package/options/transparent.schema.d.ts.map +1 -0
- package/options/typecheck.d.ts +2 -0
- package/options/typecheck.d.ts.map +1 -0
- package/options/utils.d.ts +33 -0
- package/options/utils.d.ts.map +1 -0
- package/package.json +18 -3
- package/session/encrypted-authorization-vault.d.ts +182 -0
- package/session/encrypted-authorization-vault.d.ts.map +1 -0
- package/session/federated-auth.session.d.ts +252 -0
- package/session/federated-auth.session.d.ts.map +1 -0
- package/session/index.d.ts +21 -1
- package/session/index.d.ts.map +1 -1
- package/session/orchestrated-token.store.d.ts +155 -0
- package/session/orchestrated-token.store.d.ts.map +1 -0
- package/session/redis-session.store.d.ts +93 -0
- package/session/redis-session.store.d.ts.map +1 -0
- package/session/session-crypto.d.ts +84 -0
- package/session/session-crypto.d.ts.map +1 -0
- package/session/session-rate-limiter.d.ts +114 -0
- package/session/session-rate-limiter.d.ts.map +1 -0
- package/session/session.transport.d.ts +11 -0
- package/session/session.transport.d.ts.map +1 -0
- package/session/session.types.d.ts +66 -0
- package/session/session.types.d.ts.map +1 -0
- package/session/token.refresh.d.ts +61 -0
- package/session/token.refresh.d.ts.map +1 -0
- package/session/transport-session.types.d.ts +479 -0
- package/session/transport-session.types.d.ts.map +1 -0
- package/session/utils/auth-token.utils.d.ts +12 -0
- package/session/utils/auth-token.utils.d.ts.map +1 -0
- package/session/utils/index.d.ts +2 -0
- package/session/utils/index.d.ts.map +1 -1
- package/session/utils/session-crypto.utils.d.ts +30 -0
- package/session/utils/session-crypto.utils.d.ts.map +1 -0
- package/session/vercel-kv-session.store.d.ts +123 -0
- package/session/vercel-kv-session.store.d.ts.map +1 -0
- package/utils/authorization-id.utils.d.ts +12 -0
- package/utils/authorization-id.utils.d.ts.map +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.d.ts.map +1 -1
- package/vault/auth-providers.accessor.d.ts +154 -0
- package/vault/auth-providers.accessor.d.ts.map +1 -0
- package/vault/auth-providers.accessor.impl.d.ts +54 -0
- package/vault/auth-providers.accessor.impl.d.ts.map +1 -0
- package/vault/auth-providers.registry.d.ts +111 -0
- package/vault/auth-providers.registry.d.ts.map +1 -0
- package/vault/auth-providers.types.d.ts +3 -3
- package/vault/auth-providers.vault.d.ts +94 -0
- package/vault/auth-providers.vault.d.ts.map +1 -0
- package/vault/credential-loaders/eager-loader.d.ts +47 -0
- package/vault/credential-loaders/eager-loader.d.ts.map +1 -0
- package/vault/credential-loaders/index.d.ts +7 -0
- package/vault/credential-loaders/index.d.ts.map +1 -0
- package/vault/credential-loaders/lazy-loader.d.ts +54 -0
- package/vault/credential-loaders/lazy-loader.d.ts.map +1 -0
- package/vault/index.d.ts +9 -0
- package/vault/index.d.ts.map +1 -1
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Transport protocol types supported by MCP
|
|
4
|
+
* These are the actual transport protocols for sessions (excludes 'delete-session' action)
|
|
5
|
+
*/
|
|
6
|
+
export type TransportProtocol = 'legacy-sse' | 'sse' | 'streamable-http' | 'stateful-http' | 'stateless-http';
|
|
7
|
+
/**
|
|
8
|
+
* Session storage mode for distributed systems
|
|
9
|
+
*/
|
|
10
|
+
export type SessionStorageMode = 'stateless' | 'stateful';
|
|
11
|
+
/**
|
|
12
|
+
* TransportSession represents a single client connection.
|
|
13
|
+
* Multiple sessions can share the same authorization.
|
|
14
|
+
* Each session is bound to a specific transport protocol.
|
|
15
|
+
*/
|
|
16
|
+
export interface TransportSession {
|
|
17
|
+
/** Unique session ID (encrypted JWT or UUID) */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Reference to the authorization this session uses */
|
|
20
|
+
authorizationId: string;
|
|
21
|
+
/** Transport protocol for this session */
|
|
22
|
+
protocol: TransportProtocol;
|
|
23
|
+
/** Session creation timestamp (epoch ms) */
|
|
24
|
+
createdAt: number;
|
|
25
|
+
/** Session expiration (epoch ms, independent of auth expiration) */
|
|
26
|
+
expiresAt?: number;
|
|
27
|
+
/** Node ID for distributed systems */
|
|
28
|
+
nodeId: string;
|
|
29
|
+
/** Client fingerprint for rate limiting/tracking */
|
|
30
|
+
clientFingerprint?: string;
|
|
31
|
+
/** Transport-specific state */
|
|
32
|
+
transportState?: TransportState;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Transport-specific state that varies by protocol
|
|
36
|
+
*/
|
|
37
|
+
export type TransportState = SseTransportState | StreamableHttpTransportState | StatefulHttpTransportState | StatelessHttpTransportState | LegacySseTransportState;
|
|
38
|
+
/**
|
|
39
|
+
* SSE (Server-Sent Events) transport state
|
|
40
|
+
*/
|
|
41
|
+
export interface SseTransportState {
|
|
42
|
+
type: 'sse';
|
|
43
|
+
/** Last event ID for reconnection (per SSE spec) */
|
|
44
|
+
lastEventId?: string;
|
|
45
|
+
/** Connection keep-alive timestamp */
|
|
46
|
+
lastPing?: number;
|
|
47
|
+
/** Connection state */
|
|
48
|
+
connectionState?: 'connecting' | 'open' | 'closed';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Streamable HTTP transport state
|
|
52
|
+
*/
|
|
53
|
+
export interface StreamableHttpTransportState {
|
|
54
|
+
type: 'streamable-http';
|
|
55
|
+
/** Request sequence number */
|
|
56
|
+
requestSeq: number;
|
|
57
|
+
/** Active stream ID if streaming */
|
|
58
|
+
activeStreamId?: string;
|
|
59
|
+
/** Pending request IDs */
|
|
60
|
+
pendingRequests?: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Stateful HTTP transport state
|
|
64
|
+
*/
|
|
65
|
+
export interface StatefulHttpTransportState {
|
|
66
|
+
type: 'stateful-http';
|
|
67
|
+
/** Request sequence number */
|
|
68
|
+
requestSeq: number;
|
|
69
|
+
/** Pending responses awaiting delivery */
|
|
70
|
+
pendingResponses?: string[];
|
|
71
|
+
/** Last activity timestamp */
|
|
72
|
+
lastActivity?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stateless HTTP transport state
|
|
76
|
+
*/
|
|
77
|
+
export interface StatelessHttpTransportState {
|
|
78
|
+
type: 'stateless-http';
|
|
79
|
+
/** Request count for rate limiting */
|
|
80
|
+
requestCount: number;
|
|
81
|
+
/** Window start for rate limiting */
|
|
82
|
+
windowStart?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Legacy SSE transport state (for backwards compatibility)
|
|
86
|
+
*/
|
|
87
|
+
export interface LegacySseTransportState {
|
|
88
|
+
type: 'legacy-sse';
|
|
89
|
+
/** Message endpoint path */
|
|
90
|
+
messagePath: string;
|
|
91
|
+
/** Last event ID */
|
|
92
|
+
lastEventId?: string;
|
|
93
|
+
/** Connection state */
|
|
94
|
+
connectionState?: 'connecting' | 'open' | 'closed';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Session JWT payload - encodes both auth ref and transport context
|
|
98
|
+
* This is the structure encrypted in the mcp-session-id header
|
|
99
|
+
*/
|
|
100
|
+
export interface SessionJwtPayload {
|
|
101
|
+
/** Session ID (UUID) */
|
|
102
|
+
sid: string;
|
|
103
|
+
/** Authorization ID (token signature fingerprint) */
|
|
104
|
+
aid: string;
|
|
105
|
+
/** Transport protocol */
|
|
106
|
+
proto: TransportProtocol;
|
|
107
|
+
/** Node ID (for distributed systems) */
|
|
108
|
+
nid: string;
|
|
109
|
+
/** Issued at (epoch seconds) */
|
|
110
|
+
iat: number;
|
|
111
|
+
/** Expiration (epoch seconds) */
|
|
112
|
+
exp?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extended session JWT payload for stateless mode
|
|
116
|
+
* Includes encrypted state and tokens
|
|
117
|
+
*/
|
|
118
|
+
export interface StatelessSessionJwtPayload extends SessionJwtPayload {
|
|
119
|
+
/** Encrypted transport state (AES-256-GCM) */
|
|
120
|
+
state?: string;
|
|
121
|
+
/** Encrypted provider tokens (AES-256-GCM, for orchestrated mode) */
|
|
122
|
+
tokens?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Stored session record (for stateful mode in Redis/memory)
|
|
126
|
+
*/
|
|
127
|
+
export interface StoredSession {
|
|
128
|
+
/** The transport session data */
|
|
129
|
+
session: TransportSession;
|
|
130
|
+
/** Authorization ID reference */
|
|
131
|
+
authorizationId: string;
|
|
132
|
+
/** Encrypted provider tokens (for orchestrated mode) */
|
|
133
|
+
tokens?: Record<string, EncryptedBlob>;
|
|
134
|
+
/** Creation timestamp */
|
|
135
|
+
createdAt: number;
|
|
136
|
+
/** Last accessed timestamp */
|
|
137
|
+
lastAccessedAt: number;
|
|
138
|
+
/** Whether the MCP protocol initialization handshake was completed */
|
|
139
|
+
initialized?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Absolute maximum lifetime timestamp (epoch ms).
|
|
142
|
+
* Session is invalid after this time regardless of access patterns.
|
|
143
|
+
* This prevents indefinite session extension via sliding expiration.
|
|
144
|
+
*/
|
|
145
|
+
maxLifetimeAt?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Encrypted blob structure (AES-256-GCM)
|
|
149
|
+
*/
|
|
150
|
+
export interface EncryptedBlob {
|
|
151
|
+
/** Algorithm identifier */
|
|
152
|
+
alg: 'A256GCM';
|
|
153
|
+
/** Key ID (for rotation) */
|
|
154
|
+
kid?: string;
|
|
155
|
+
/** Initialization vector (base64url) */
|
|
156
|
+
iv: string;
|
|
157
|
+
/** Authentication tag (base64url) */
|
|
158
|
+
tag: string;
|
|
159
|
+
/** Ciphertext (base64url) */
|
|
160
|
+
data: string;
|
|
161
|
+
/** Expiration hint (epoch seconds) */
|
|
162
|
+
exp?: number;
|
|
163
|
+
/** Additional metadata */
|
|
164
|
+
meta?: Record<string, unknown>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Session store interface for stateful sessions
|
|
168
|
+
*/
|
|
169
|
+
export interface SessionStore {
|
|
170
|
+
/**
|
|
171
|
+
* Get a stored session by ID
|
|
172
|
+
*/
|
|
173
|
+
get(sessionId: string): Promise<StoredSession | null>;
|
|
174
|
+
/**
|
|
175
|
+
* Store a session with optional TTL
|
|
176
|
+
*/
|
|
177
|
+
set(sessionId: string, session: StoredSession, ttlMs?: number): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Delete a session
|
|
180
|
+
*/
|
|
181
|
+
delete(sessionId: string): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Check if a session exists
|
|
184
|
+
*/
|
|
185
|
+
exists(sessionId: string): Promise<boolean>;
|
|
186
|
+
/**
|
|
187
|
+
* Allocate a new session ID
|
|
188
|
+
*/
|
|
189
|
+
allocId(): string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Session storage configuration
|
|
193
|
+
*/
|
|
194
|
+
export type SessionStorageConfig = {
|
|
195
|
+
mode: 'stateless';
|
|
196
|
+
} | {
|
|
197
|
+
mode: 'stateful';
|
|
198
|
+
store: 'memory';
|
|
199
|
+
} | {
|
|
200
|
+
mode: 'stateful';
|
|
201
|
+
store: 'redis';
|
|
202
|
+
config: RedisConfig;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Redis configuration
|
|
206
|
+
*/
|
|
207
|
+
export interface RedisConfig {
|
|
208
|
+
host: string;
|
|
209
|
+
port?: number;
|
|
210
|
+
password?: string;
|
|
211
|
+
db?: number;
|
|
212
|
+
tls?: boolean;
|
|
213
|
+
keyPrefix?: string;
|
|
214
|
+
/** Default TTL in milliseconds for session extension on access (sliding expiration) */
|
|
215
|
+
defaultTtlMs?: number;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Security configuration options for session stores.
|
|
219
|
+
* These options enable additional security hardening features.
|
|
220
|
+
*/
|
|
221
|
+
export interface SessionSecurityConfig {
|
|
222
|
+
/**
|
|
223
|
+
* Default maximum session lifetime in milliseconds.
|
|
224
|
+
* Sessions will be invalidated after this time regardless of access.
|
|
225
|
+
* Set to prevent indefinite session extension via sliding expiration.
|
|
226
|
+
* @example 86400000 // 24 hours
|
|
227
|
+
*/
|
|
228
|
+
maxLifetimeMs?: number;
|
|
229
|
+
/**
|
|
230
|
+
* Enable HMAC signing for stored sessions.
|
|
231
|
+
* When enabled, sessions are signed to detect tampering.
|
|
232
|
+
* Requires MCP_SESSION_SECRET environment variable or signing.secret config.
|
|
233
|
+
* @default false
|
|
234
|
+
*/
|
|
235
|
+
enableSigning?: boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Secret key for HMAC signing.
|
|
238
|
+
* If not provided, falls back to MCP_SESSION_SECRET environment variable.
|
|
239
|
+
*/
|
|
240
|
+
signingSecret?: string;
|
|
241
|
+
/**
|
|
242
|
+
* Enable rate limiting for session lookups.
|
|
243
|
+
* Protects against session enumeration attacks.
|
|
244
|
+
* @default false
|
|
245
|
+
*/
|
|
246
|
+
enableRateLimiting?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Rate limiting configuration.
|
|
249
|
+
* Only used if enableRateLimiting is true.
|
|
250
|
+
*/
|
|
251
|
+
rateLimiting?: {
|
|
252
|
+
/** Time window in milliseconds. @default 60000 */
|
|
253
|
+
windowMs?: number;
|
|
254
|
+
/** Maximum requests per window. @default 100 */
|
|
255
|
+
maxRequests?: number;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
export declare const transportProtocolSchema: z.ZodEnum<{
|
|
259
|
+
"legacy-sse": "legacy-sse";
|
|
260
|
+
sse: "sse";
|
|
261
|
+
"streamable-http": "streamable-http";
|
|
262
|
+
"stateful-http": "stateful-http";
|
|
263
|
+
"stateless-http": "stateless-http";
|
|
264
|
+
}>;
|
|
265
|
+
export declare const sseTransportStateSchema: z.ZodObject<{
|
|
266
|
+
type: z.ZodLiteral<"sse">;
|
|
267
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
268
|
+
lastPing: z.ZodOptional<z.ZodNumber>;
|
|
269
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
270
|
+
connecting: "connecting";
|
|
271
|
+
open: "open";
|
|
272
|
+
closed: "closed";
|
|
273
|
+
}>>;
|
|
274
|
+
}, z.core.$strip>;
|
|
275
|
+
export declare const streamableHttpTransportStateSchema: z.ZodObject<{
|
|
276
|
+
type: z.ZodLiteral<"streamable-http">;
|
|
277
|
+
requestSeq: z.ZodNumber;
|
|
278
|
+
activeStreamId: z.ZodOptional<z.ZodString>;
|
|
279
|
+
pendingRequests: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
280
|
+
}, z.core.$strip>;
|
|
281
|
+
export declare const statefulHttpTransportStateSchema: z.ZodObject<{
|
|
282
|
+
type: z.ZodLiteral<"stateful-http">;
|
|
283
|
+
requestSeq: z.ZodNumber;
|
|
284
|
+
pendingResponses: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
285
|
+
lastActivity: z.ZodOptional<z.ZodNumber>;
|
|
286
|
+
}, z.core.$strip>;
|
|
287
|
+
export declare const statelessHttpTransportStateSchema: z.ZodObject<{
|
|
288
|
+
type: z.ZodLiteral<"stateless-http">;
|
|
289
|
+
requestCount: z.ZodNumber;
|
|
290
|
+
windowStart: z.ZodOptional<z.ZodNumber>;
|
|
291
|
+
}, z.core.$strip>;
|
|
292
|
+
export declare const legacySseTransportStateSchema: z.ZodObject<{
|
|
293
|
+
type: z.ZodLiteral<"legacy-sse">;
|
|
294
|
+
messagePath: z.ZodString;
|
|
295
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
296
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
297
|
+
connecting: "connecting";
|
|
298
|
+
open: "open";
|
|
299
|
+
closed: "closed";
|
|
300
|
+
}>>;
|
|
301
|
+
}, z.core.$strip>;
|
|
302
|
+
export declare const transportStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
303
|
+
type: z.ZodLiteral<"sse">;
|
|
304
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
305
|
+
lastPing: z.ZodOptional<z.ZodNumber>;
|
|
306
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
307
|
+
connecting: "connecting";
|
|
308
|
+
open: "open";
|
|
309
|
+
closed: "closed";
|
|
310
|
+
}>>;
|
|
311
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
312
|
+
type: z.ZodLiteral<"streamable-http">;
|
|
313
|
+
requestSeq: z.ZodNumber;
|
|
314
|
+
activeStreamId: z.ZodOptional<z.ZodString>;
|
|
315
|
+
pendingRequests: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
316
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
317
|
+
type: z.ZodLiteral<"stateful-http">;
|
|
318
|
+
requestSeq: z.ZodNumber;
|
|
319
|
+
pendingResponses: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
320
|
+
lastActivity: z.ZodOptional<z.ZodNumber>;
|
|
321
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
322
|
+
type: z.ZodLiteral<"stateless-http">;
|
|
323
|
+
requestCount: z.ZodNumber;
|
|
324
|
+
windowStart: z.ZodOptional<z.ZodNumber>;
|
|
325
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
326
|
+
type: z.ZodLiteral<"legacy-sse">;
|
|
327
|
+
messagePath: z.ZodString;
|
|
328
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
329
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
330
|
+
connecting: "connecting";
|
|
331
|
+
open: "open";
|
|
332
|
+
closed: "closed";
|
|
333
|
+
}>>;
|
|
334
|
+
}, z.core.$strip>], "type">;
|
|
335
|
+
export declare const transportSessionSchema: z.ZodObject<{
|
|
336
|
+
id: z.ZodString;
|
|
337
|
+
authorizationId: z.ZodString;
|
|
338
|
+
protocol: z.ZodEnum<{
|
|
339
|
+
"legacy-sse": "legacy-sse";
|
|
340
|
+
sse: "sse";
|
|
341
|
+
"streamable-http": "streamable-http";
|
|
342
|
+
"stateful-http": "stateful-http";
|
|
343
|
+
"stateless-http": "stateless-http";
|
|
344
|
+
}>;
|
|
345
|
+
createdAt: z.ZodNumber;
|
|
346
|
+
expiresAt: z.ZodOptional<z.ZodNumber>;
|
|
347
|
+
nodeId: z.ZodString;
|
|
348
|
+
clientFingerprint: z.ZodOptional<z.ZodString>;
|
|
349
|
+
transportState: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
350
|
+
type: z.ZodLiteral<"sse">;
|
|
351
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
352
|
+
lastPing: z.ZodOptional<z.ZodNumber>;
|
|
353
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
354
|
+
connecting: "connecting";
|
|
355
|
+
open: "open";
|
|
356
|
+
closed: "closed";
|
|
357
|
+
}>>;
|
|
358
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
359
|
+
type: z.ZodLiteral<"streamable-http">;
|
|
360
|
+
requestSeq: z.ZodNumber;
|
|
361
|
+
activeStreamId: z.ZodOptional<z.ZodString>;
|
|
362
|
+
pendingRequests: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
363
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
364
|
+
type: z.ZodLiteral<"stateful-http">;
|
|
365
|
+
requestSeq: z.ZodNumber;
|
|
366
|
+
pendingResponses: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
367
|
+
lastActivity: z.ZodOptional<z.ZodNumber>;
|
|
368
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
369
|
+
type: z.ZodLiteral<"stateless-http">;
|
|
370
|
+
requestCount: z.ZodNumber;
|
|
371
|
+
windowStart: z.ZodOptional<z.ZodNumber>;
|
|
372
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
373
|
+
type: z.ZodLiteral<"legacy-sse">;
|
|
374
|
+
messagePath: z.ZodString;
|
|
375
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
376
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
377
|
+
connecting: "connecting";
|
|
378
|
+
open: "open";
|
|
379
|
+
closed: "closed";
|
|
380
|
+
}>>;
|
|
381
|
+
}, z.core.$strip>], "type">>;
|
|
382
|
+
}, z.core.$strip>;
|
|
383
|
+
export declare const sessionJwtPayloadSchema: z.ZodObject<{
|
|
384
|
+
sid: z.ZodString;
|
|
385
|
+
aid: z.ZodString;
|
|
386
|
+
proto: z.ZodEnum<{
|
|
387
|
+
"legacy-sse": "legacy-sse";
|
|
388
|
+
sse: "sse";
|
|
389
|
+
"streamable-http": "streamable-http";
|
|
390
|
+
"stateful-http": "stateful-http";
|
|
391
|
+
"stateless-http": "stateless-http";
|
|
392
|
+
}>;
|
|
393
|
+
nid: z.ZodString;
|
|
394
|
+
iat: z.ZodNumber;
|
|
395
|
+
exp: z.ZodOptional<z.ZodNumber>;
|
|
396
|
+
}, z.core.$strip>;
|
|
397
|
+
export declare const encryptedBlobSchema: z.ZodObject<{
|
|
398
|
+
alg: z.ZodLiteral<"A256GCM">;
|
|
399
|
+
kid: z.ZodOptional<z.ZodString>;
|
|
400
|
+
iv: z.ZodString;
|
|
401
|
+
tag: z.ZodString;
|
|
402
|
+
data: z.ZodString;
|
|
403
|
+
exp: z.ZodOptional<z.ZodNumber>;
|
|
404
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
405
|
+
}, z.core.$strip>;
|
|
406
|
+
export declare const storedSessionSchema: z.ZodObject<{
|
|
407
|
+
session: z.ZodObject<{
|
|
408
|
+
id: z.ZodString;
|
|
409
|
+
authorizationId: z.ZodString;
|
|
410
|
+
protocol: z.ZodEnum<{
|
|
411
|
+
"legacy-sse": "legacy-sse";
|
|
412
|
+
sse: "sse";
|
|
413
|
+
"streamable-http": "streamable-http";
|
|
414
|
+
"stateful-http": "stateful-http";
|
|
415
|
+
"stateless-http": "stateless-http";
|
|
416
|
+
}>;
|
|
417
|
+
createdAt: z.ZodNumber;
|
|
418
|
+
expiresAt: z.ZodOptional<z.ZodNumber>;
|
|
419
|
+
nodeId: z.ZodString;
|
|
420
|
+
clientFingerprint: z.ZodOptional<z.ZodString>;
|
|
421
|
+
transportState: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
422
|
+
type: z.ZodLiteral<"sse">;
|
|
423
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
424
|
+
lastPing: z.ZodOptional<z.ZodNumber>;
|
|
425
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
426
|
+
connecting: "connecting";
|
|
427
|
+
open: "open";
|
|
428
|
+
closed: "closed";
|
|
429
|
+
}>>;
|
|
430
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
431
|
+
type: z.ZodLiteral<"streamable-http">;
|
|
432
|
+
requestSeq: z.ZodNumber;
|
|
433
|
+
activeStreamId: z.ZodOptional<z.ZodString>;
|
|
434
|
+
pendingRequests: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
435
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
436
|
+
type: z.ZodLiteral<"stateful-http">;
|
|
437
|
+
requestSeq: z.ZodNumber;
|
|
438
|
+
pendingResponses: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
439
|
+
lastActivity: z.ZodOptional<z.ZodNumber>;
|
|
440
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
441
|
+
type: z.ZodLiteral<"stateless-http">;
|
|
442
|
+
requestCount: z.ZodNumber;
|
|
443
|
+
windowStart: z.ZodOptional<z.ZodNumber>;
|
|
444
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
445
|
+
type: z.ZodLiteral<"legacy-sse">;
|
|
446
|
+
messagePath: z.ZodString;
|
|
447
|
+
lastEventId: z.ZodOptional<z.ZodString>;
|
|
448
|
+
connectionState: z.ZodOptional<z.ZodEnum<{
|
|
449
|
+
connecting: "connecting";
|
|
450
|
+
open: "open";
|
|
451
|
+
closed: "closed";
|
|
452
|
+
}>>;
|
|
453
|
+
}, z.core.$strip>], "type">>;
|
|
454
|
+
}, z.core.$strip>;
|
|
455
|
+
authorizationId: z.ZodString;
|
|
456
|
+
tokens: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
457
|
+
alg: z.ZodLiteral<"A256GCM">;
|
|
458
|
+
kid: z.ZodOptional<z.ZodString>;
|
|
459
|
+
iv: z.ZodString;
|
|
460
|
+
tag: z.ZodString;
|
|
461
|
+
data: z.ZodString;
|
|
462
|
+
exp: z.ZodOptional<z.ZodNumber>;
|
|
463
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
464
|
+
}, z.core.$strip>>>;
|
|
465
|
+
createdAt: z.ZodNumber;
|
|
466
|
+
lastAccessedAt: z.ZodNumber;
|
|
467
|
+
initialized: z.ZodOptional<z.ZodBoolean>;
|
|
468
|
+
maxLifetimeAt: z.ZodOptional<z.ZodNumber>;
|
|
469
|
+
}, z.core.$strip>;
|
|
470
|
+
export declare const redisConfigSchema: z.ZodObject<{
|
|
471
|
+
host: z.ZodString;
|
|
472
|
+
port: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
473
|
+
password: z.ZodOptional<z.ZodString>;
|
|
474
|
+
db: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
475
|
+
tls: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
476
|
+
keyPrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
477
|
+
defaultTtlMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
478
|
+
}, z.core.$strip>;
|
|
479
|
+
//# sourceMappingURL=transport-session.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-session.types.d.ts","sourceRoot":"","sources":["../../src/session/transport-session.types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,KAAK,GAAG,iBAAiB,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAE9G;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,UAAU,CAAC;AAE1D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IAEX,uDAAuD;IACvD,eAAe,EAAE,MAAM,CAAC;IAExB,0CAA0C;IAC1C,QAAQ,EAAE,iBAAiB,CAAC;IAE5B,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IAEf,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,+BAA+B;IAC/B,cAAc,CAAC,EA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,MAAM,CAAC;IAEvB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,YAAY,CAAC,EAAE;QACb,kDAAkD;QAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,gDAAgD;QAChD,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAMD,eAAO,MAAM,uBAAuB;;;;;;EAMlC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;iBAKlC,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;iBAK7C,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;;;iBAK3C,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;iBAI5C,CAAC;AAEH,eAAO,MAAM,6BAA6B;;;;;;;;;iBAKxC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAM/B,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBASjC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;iBAOlC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;iBAQ9B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAQ9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;iBAQ5B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UserClaim } from '../../common/session.types';
|
|
2
|
+
export declare function isJwt(token: string | undefined): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* If the token is a JWT, returns the raw signature segment (3rd part) as base64url.
|
|
5
|
+
* Otherwise, returns a stable SHA-256(base64url) fingerprint of the whole token,
|
|
6
|
+
* so we can still bind a session id to "this Authorization" deterministically.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getTokenSignatureFingerprint(token: string): string;
|
|
9
|
+
/** Best-effort typed user derivation from claims */
|
|
10
|
+
export declare function deriveTypedUser(claims: Record<string, unknown>): UserClaim;
|
|
11
|
+
export declare function extractBearerToken(header?: string): string | undefined;
|
|
12
|
+
//# sourceMappingURL=auth-token.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-token.utils.d.ts","sourceRoot":"","sources":["../../../src/session/utils/auth-token.utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGvD,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGxD;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlE;AAkBD,oDAAoD;AACpD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAe1E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAItE"}
|
package/session/utils/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
* Session utilities
|
|
3
3
|
*/
|
|
4
4
|
export { TinyTtlCache } from './tiny-ttl-cache';
|
|
5
|
+
export { isJwt, getTokenSignatureFingerprint, deriveTypedUser, extractBearerToken } from './auth-token.utils';
|
|
6
|
+
export { getKey, encryptJson, decryptSessionJson, safeDecrypt, resetCachedKey } from './session-crypto.utils';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/session/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/session/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,4BAA4B,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symmetric key derived from secret or machine id (stable for the process).
|
|
3
|
+
* Uses getMachineId() from authorization module as single source of truth.
|
|
4
|
+
*
|
|
5
|
+
* SECURITY: In production, MCP_SESSION_SECRET is REQUIRED.
|
|
6
|
+
* Falls back to getMachineId() only in development/test environments.
|
|
7
|
+
*
|
|
8
|
+
* @throws Error if MCP_SESSION_SECRET is not set in production
|
|
9
|
+
*/
|
|
10
|
+
export declare function getKey(): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Encrypt an object to a compact session ID format (iv.tag.ct).
|
|
13
|
+
*/
|
|
14
|
+
export declare function encryptJson(obj: unknown): string;
|
|
15
|
+
/**
|
|
16
|
+
* Low-level decryption that returns the raw JSON payload or null if the
|
|
17
|
+
* session ID format is invalid. Crypto/parsing errors may throw; use
|
|
18
|
+
* {@link safeDecrypt} for a version that catches all errors and returns null.
|
|
19
|
+
*/
|
|
20
|
+
export declare function decryptSessionJson(sessionId: string): unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Safe wrapper around decryptSessionJson that catches crypto/parse errors.
|
|
23
|
+
*/
|
|
24
|
+
export declare function safeDecrypt(sessionId: string): unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Reset the cached key. Useful for testing.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function resetCachedKey(): void;
|
|
30
|
+
//# sourceMappingURL=session-crypto.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-crypto.utils.d.ts","sourceRoot":"","sources":["../../../src/session/utils/session-crypto.utils.ts"],"names":[],"mappings":"AAYA;;;;;;;;GAQG;AACH,wBAAgB,MAAM,IAAI,UAAU,CAqBnC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAKhD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAS7D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAMtD;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel KV Session Store
|
|
3
|
+
*
|
|
4
|
+
* Session store implementation using Vercel KV (edge-compatible REST-based key-value store).
|
|
5
|
+
* Uses @frontmcp/utils VercelKvStorageAdapter internally.
|
|
6
|
+
*
|
|
7
|
+
* @warning **Atomicity Limitation**: Vercel KV does not support atomic GET+EXPIRE (GETEX).
|
|
8
|
+
* The `get()` method uses separate GET and EXPIRE calls, creating a small race window
|
|
9
|
+
* where the session could expire between these two operations. For mission-critical
|
|
10
|
+
* session handling requiring strict atomicity guarantees, consider using Redis directly
|
|
11
|
+
* via `RedisSessionStore`.
|
|
12
|
+
*
|
|
13
|
+
* @see https://vercel.com/docs/storage/vercel-kv
|
|
14
|
+
*/
|
|
15
|
+
import { SessionStore, StoredSession, SessionSecurityConfig } from './transport-session.types';
|
|
16
|
+
import type { AuthLogger } from '../common/auth-logger.interface';
|
|
17
|
+
export interface VercelKvSessionConfig {
|
|
18
|
+
/**
|
|
19
|
+
* KV REST API URL
|
|
20
|
+
* @default process.env.KV_REST_API_URL
|
|
21
|
+
*/
|
|
22
|
+
url?: string;
|
|
23
|
+
/**
|
|
24
|
+
* KV REST API Token
|
|
25
|
+
* @default process.env.KV_REST_API_TOKEN
|
|
26
|
+
*/
|
|
27
|
+
token?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Key prefix for session keys
|
|
30
|
+
* @default 'mcp:session:'
|
|
31
|
+
*/
|
|
32
|
+
keyPrefix?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Default TTL in milliseconds for session extension on access
|
|
35
|
+
* @default 3600000 (1 hour)
|
|
36
|
+
*/
|
|
37
|
+
defaultTtlMs?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Security hardening options
|
|
40
|
+
*/
|
|
41
|
+
security?: SessionSecurityConfig;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Vercel KV-backed session store implementation
|
|
45
|
+
*
|
|
46
|
+
* Provides persistent session storage for edge deployments using Vercel KV.
|
|
47
|
+
* Sessions are stored as JSON with optional TTL.
|
|
48
|
+
* Uses @frontmcp/utils VercelKvStorageAdapter internally.
|
|
49
|
+
*/
|
|
50
|
+
export declare class VercelKvSessionStore implements SessionStore {
|
|
51
|
+
private readonly storage;
|
|
52
|
+
private readonly keyPrefix;
|
|
53
|
+
private readonly defaultTtlMs;
|
|
54
|
+
private readonly logger?;
|
|
55
|
+
private readonly security;
|
|
56
|
+
private readonly rateLimiter?;
|
|
57
|
+
constructor(config: VercelKvSessionConfig | {
|
|
58
|
+
provider?: string;
|
|
59
|
+
url?: string;
|
|
60
|
+
token?: string;
|
|
61
|
+
keyPrefix?: string;
|
|
62
|
+
defaultTtlMs?: number;
|
|
63
|
+
security?: SessionSecurityConfig;
|
|
64
|
+
}, logger?: AuthLogger);
|
|
65
|
+
/**
|
|
66
|
+
* Validate session ID
|
|
67
|
+
* @throws Error if sessionId is empty
|
|
68
|
+
*/
|
|
69
|
+
private validateSessionId;
|
|
70
|
+
/**
|
|
71
|
+
* Connect to Vercel KV
|
|
72
|
+
* Thread-safe: concurrent calls will share the same connection via adapter.
|
|
73
|
+
*/
|
|
74
|
+
connect(): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Ensure the storage adapter is connected
|
|
77
|
+
*/
|
|
78
|
+
private ensureConnected;
|
|
79
|
+
/**
|
|
80
|
+
* Get a stored session by ID
|
|
81
|
+
*
|
|
82
|
+
* Note: Vercel KV doesn't support GETEX, so we use GET + EXPIRE separately.
|
|
83
|
+
* This is slightly less atomic than Redis GETEX but sufficient for most use cases.
|
|
84
|
+
*
|
|
85
|
+
* @param sessionId - The session ID to look up
|
|
86
|
+
* @param options - Optional parameters for rate limiting
|
|
87
|
+
* @param options.clientIdentifier - Client identifier (e.g., IP address) for rate limiting.
|
|
88
|
+
* When provided, rate limiting is applied per-client to prevent session enumeration.
|
|
89
|
+
* If not provided, falls back to sessionId which provides DoS protection per-session.
|
|
90
|
+
*/
|
|
91
|
+
get(sessionId: string, options?: {
|
|
92
|
+
clientIdentifier?: string;
|
|
93
|
+
}): Promise<StoredSession | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Store a session with optional TTL
|
|
96
|
+
*/
|
|
97
|
+
set(sessionId: string, session: StoredSession, ttlMs?: number): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Delete a session
|
|
100
|
+
*/
|
|
101
|
+
delete(sessionId: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Check if a session exists
|
|
104
|
+
*/
|
|
105
|
+
exists(sessionId: string): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Allocate a new session ID
|
|
108
|
+
*/
|
|
109
|
+
allocId(): string;
|
|
110
|
+
/**
|
|
111
|
+
* Disconnect from Vercel KV
|
|
112
|
+
* Vercel KV uses REST API, so this just clears internal state
|
|
113
|
+
*/
|
|
114
|
+
disconnect(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Test Vercel KV connection by checking if we can access the API.
|
|
117
|
+
* Useful for validating connection on startup.
|
|
118
|
+
*
|
|
119
|
+
* @returns true if connection is healthy, false otherwise
|
|
120
|
+
*/
|
|
121
|
+
ping(): Promise<boolean>;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=vercel-kv-session.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel-kv-session.store.d.ts","sourceRoot":"","sources":["../../src/session/vercel-kv-session.store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAuB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACpH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAKlE,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAa;IAGrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAqB;gBAGhD,MAAM,EACF,qBAAqB,GACrB;QACE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAA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