/*! * @package @coolgk/utils * @version 3.1.4 * @link https://github.com/coolgk/node-utils * @license MIT * @author Daniel Gong * * Copyright (c) 2017 Daniel Gong . All rights reserved. * Licensed under the MIT License. */ /// /*! * Copyright (c) 2017 Daniel Gong . All rights reserved. * Licensed under the MIT License. */ import { Token, IRedisClient } from '@coolgk/token'; import { CookieSerializeOptions } from 'cookie'; import { ServerResponse, IncomingMessage } from 'http'; export interface IBaseConfig { readonly secret: string; readonly redisClient: IRedisClient; readonly expiry?: number; readonly cookie?: CookieSerializeOptions; readonly response?: ServerResponse; [index: string]: any; } export interface IConfig extends IBaseConfig { readonly request: IncomingMessage; } export interface ISignature { [index: string]: any; } export declare const SESSION_NAME = "session"; export declare const COOKIE_NAME = "accessToken"; export declare class Session extends Token { private _jwt; private _sessionToken; private _cookie; private _response; constructor(options: IConfig); init(signature?: ISignature): Promise; rotate(signature?: ISignature): Promise; start(signature?: ISignature): Promise; destroy(): Promise; verify(signature?: ISignature): Promise; verifyAndRenew(signature?: ISignature, expiry?: number): Promise; renew(expiry?: number): Promise; private _renewCacheAndCookie(expiry?); private _verifyJwt(); } export default Session; export interface IExpressConfig extends IBaseConfig { requestFieldName?: string; } export interface IRequest extends IncomingMessage { [key: string]: any; } export declare function express(options: IExpressConfig): (request: IRequest, response: ServerResponse, next: () => void) => void;