forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1export interface SessionData {
2 sessionId: string;
3 userId: string;
4 handle?: string;
5 isAuthenticated: boolean;
6 data?: Record<string, unknown>;
7 createdAt: number;
8 expiresAt: number;
9 lastAccessedAt: number;
10}
11
12export interface SessionUser {
13 sessionId?: string;
14 sub?: string;
15 handle?: string;
16 isAuthenticated: boolean;
17 [key: string]: unknown;
18}
19
20export interface SessionOptions {
21 adapter: SessionAdapter;
22 cookieName?: string;
23 cookieOptions?: CookieOptions;
24 sessionTTL?: number; // milliseconds, default 30 days
25 cleanupInterval?: number; // milliseconds, default 1 hour
26 generateId?: () => string;
27}
28
29export interface CookieOptions {
30 httpOnly?: boolean;
31 secure?: boolean;
32 sameSite?: "strict" | "lax" | "none";
33 domain?: string;
34 path?: string;
35 maxAge?: number; // seconds
36}
37
38export interface SessionAdapter {
39 get(sessionId: string): Promise<SessionData | null>;
40 set(sessionId: string, data: SessionData): Promise<void>;
41 update(sessionId: string, data: Partial<SessionData>): Promise<boolean>;
42 delete(sessionId: string): Promise<void>;
43 cleanup(expiresBeforeMs: number): Promise<number>;
44 exists(sessionId: string): Promise<boolean>;
45}