UNPKG

rauth

Version:

Authentication and Authorization library via JWT

74 lines (73 loc) 2.57 kB
import { SessionControl } from './SessionControl'; import { JWTControl } from './JWTControl'; export declare type Mode = 'OnlyAccessToken' | 'Token'; declare type RT<T extends Mode> = T extends 'OnlyAccessToken' ? undefined : string; export declare type SessionId = string; export declare type Scope = string | string[]; export declare type UserID = string; export declare type Data = { [prop: string]: any; }; export declare type Meta = { [prop: string]: any; }; export declare type AccessToken = string; export declare type RefreshToken = string; export interface SessionRegister { userId?: UserID; scope?: Scope; clientId?: string; sessionId?: SessionId; data?: Data; meta?: Meta; iat?: number; exp?: number; [prop: string]: any; } export declare type StrictSessionRegister = SessionRegister; export declare const msToSec: (inp: string | number) => number; export declare const scopeToString: (scope?: string | string[] | undefined) => string | undefined; interface OptionSession { readonly userId?: UserID; readonly scope?: Scope; readonly sessionId?: SessionId; readonly data?: Data; readonly meta?: Meta; readonly sessionControl?: SessionControl; readonly clientId?: string; readonly otherDataSession?: { [k: string]: string; }; readonly mode?: Mode; readonly refreshAt?: number; readonly createdAt?: number; } export declare class Session<M extends Mode = 'Token'> implements SessionRegister { private readonly options?; static from({ userId, scope, sessionId, data, meta, clientId, mode, refreshAt, createdAt, ...otherDataSession }: StrictSessionRegister & Pick<OptionSession, 'mode'>, sessionControl: SessionControl): Session; private constructor(); readonly refreshAt: number | undefined; readonly createdAt: number | undefined; readonly sessionControl: SessionControl | undefined; readonly jwtControl: JWTControl; readonly userId: string | undefined; readonly scope: string | undefined; readonly sessionId: string | undefined; readonly clientId: string | undefined; readonly data: Data | undefined; readonly meta: Meta | undefined; readonly otherDataSession: { [k: string]: string; } | undefined; readonly mode: Mode; readonly accessTokenExpires: number; readonly refreshTokenExpires: number; get refreshToken(): RT<M>; get accessToken(): string; toJSON(): { access_token: string; refresh_token: RT<M>; expires_in: number; }; } export {};