@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
55 lines (53 loc) • 1.57 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.
*/
/*!
* Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved.
* Licensed under the MIT License.
*/
import { Cache, ICacheClient } from '@coolgk/cache';
export interface IConfig {
readonly token: string;
readonly expiry?: number;
readonly prefix?: string;
}
export interface ITokenConfigWithCache extends IConfig {
readonly cache: Cache;
}
export interface ITokenConfig extends IConfig {
readonly redisClient: ICacheClient;
}
export interface ITokenValues {
[field: string]: any;
}
export { ICacheClient as IRedisClient };
export declare const DEFAULT_PREFIX = "token";
export declare enum TokenError {
INVALID_TOKEN = "INVALID_TOKEN",
RESERVED_NAME = "RESERVED_NAME",
EXPIRED_TOKEN = "EXPIRED_TOKEN",
}
export declare class Token {
private _token;
private _cache;
private _expiry;
private _name;
private _prefix;
constructor(options: ITokenConfig | ITokenConfigWithCache);
renew(expiry?: number): Promise<any>;
set(name: string, value: any): Promise<any>;
verify(): Promise<boolean>;
get(name: string): Promise<any>;
destroy(): Promise<any>;
delete(name: string): Promise<any>;
getAll(): Promise<ITokenValues>;
setToken(token: string): void;
}
export default Token;