UNPKG

@redwoodjs/sdk

Version:

Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime

51 lines (50 loc) 2.35 kB
export declare const MAX_SESSION_DURATION: number; type GetSessionResult<Session> = { value: Session; } | { error: string; }; export interface DurableObjectMethods<Session, SessionInputData> extends Rpc.DurableObjectBranded { getSession(): Promise<GetSessionResult<Session>>; saveSession(data: SessionInputData): Promise<Session>; revokeSession(): void; } export type SessionStore<Session, SessionInputData = Session> = ReturnType<typeof defineSessionStore<Session, SessionInputData>>; export declare const createSessionCookie: ({ name, sessionId, maxAge, }: { name: string; sessionId: string; maxAge?: number | true; }) => string; export declare const signSessionId: ({ unsignedSessionId, secretKey, }: { unsignedSessionId: string; secretKey: string; }) => Promise<string>; export declare const generateSessionId: ({ secretKey, }: { secretKey: string; }) => Promise<string>; export declare const isValidSessionId: ({ sessionId, secretKey, }: { sessionId: string; secretKey: string; }) => Promise<boolean>; export declare const defineSessionStore: <Session, SessionInputData>({ cookieName, createCookie, secretKey, get, set, unset, }: { cookieName?: string; createCookie?: typeof createSessionCookie; secretKey: string; get: (sessionId: string) => Promise<Session>; set: (sessionId: string, sessionInputData: SessionInputData) => Promise<void>; unset: (sessionId: string) => Promise<void>; }) => { load: (request: Request) => Promise<Session | null>; save: (headers: Headers, sessionInputData: SessionInputData, { maxAge }?: { maxAge?: number | true; }) => Promise<void>; remove: (request: Request, headers: Headers) => Promise<void>; }; type SessionStoreFromDurableObject<SessionDurableObject> = SessionDurableObject extends DurableObjectMethods<infer Session, infer SessionInputData> ? SessionStore<Session, SessionInputData> : never; export declare const defineDurableSession: <SessionDurableObject extends DurableObjectMethods<any, any>>({ cookieName, createCookie, secretKey, sessionDurableObject, }: { cookieName?: string; createCookie?: typeof createSessionCookie; secretKey: string; sessionDurableObject: DurableObjectNamespace<SessionDurableObject>; }) => SessionStoreFromDurableObject<SessionDurableObject>; export {};