@coolgk/utils
Version:
javascript, typescript utility and wrapper functions and classes: array, string, base64, ampq, bcrypt, cache, captcha, csv, email, jwt, number, pdf, tmp, token, unit conversion, url params, session, form data, google sign in, facebook sign in
60 lines (58 loc) • 2.01 kB
TypeScript
/*!
* @package @coolgk/utils
* @version 3.1.4
* @link https://github.com/coolgk/node-utils
* @license MIT
* @author Daniel Gong <daniel.k.gong@gmail.com>
*
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
/// <reference types="node" />
/*!
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. 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<string>;
rotate(signature?: ISignature): Promise<string>;
start(signature?: ISignature): Promise<string>;
destroy(): Promise<any>;
verify(signature?: ISignature): Promise<boolean>;
verifyAndRenew(signature?: ISignature, expiry?: number): Promise<boolean>;
renew(expiry?: number): Promise<any>;
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;