import { UpdateResult } from 'typeorm'; import { OperationToken, TokenRule } from './entities'; export declare const SysTokenServiceName: { AdminLogin: string; SysInvite: string; }; export interface CommonTokenOpts { payload?: object; identifier: string; role: keyof typeof TokenRule; service: string; key: string; } /** * @param payload * @param identifier id=user.id * @param role 'sys' | 'app' | 'web' | 'other' * @param expiredIn in minutes. default: 1 year * @param service 用于定位所使用的服务 * @param remainingCount default: 1 */ export declare type ObtainTokenOpts = ({ type: 'Unlimited'; } | { type: 'OneTime'; } | { type: 'MultiTimes'; remainingCount: number; } | { type: 'TimeBased'; expiredAt: Date; } | { type: 'TimeBased'; expiredInMinutes: number; }) & CommonTokenOpts; export interface RedeemTokenOpts { key?: string; identifier: string; role: keyof typeof TokenRule; service: string; } export declare class OperationTokenOpts { readonly key: string; readonly service: string; readonly role: keyof typeof TokenRule; readonly identifier: string; readonly payload?: object; readonly type: 'Unlimited' | 'OneTime' | 'MultiTimes' | 'TimeBased' | 'TimeBased'; readonly remainingCount?: number; readonly expiredAt?: Date; readonly expiredInMinutes?: number; constructor(o: OperationTokenOpts); static obtain(o: ObtainTokenOpts): OperationTokenOpts; } export interface DeprecateTokenParams { identifier: string; role: keyof typeof TokenRule; service: string; key: string; } export declare class OperationTokenHelper { static resolver: { [key: string]: ({ identifier, user }: { identifier: any; user: any; }) => Promise; }; /** * same { role, identifier, service } will return same token */ static obtainToken(opts: ObtainTokenOpts): Promise; /** * 同一个 key 下的 service 下只有一个可用的 token,失效的 token 可以尝试一定时间后移除。 * @param key * @param role * @param identifier * @param service */ static redeemTokens({ key, role, identifier, service }: RedeemTokenOpts): Promise; static deprecateToken({ key, role, identifier, service }: DeprecateTokenParams): Promise; static getTokenByToken(tokenOrShortId: string): Promise | null; static getToken({ token, shortId }: { token?: string; shortId?: string; }): Promise; static consumeToken(token: string): Promise; static checkAvailableByToken: (token: string) => Promise; static extend(operationToken: OperationToken, minutes: number): void; static checkAvailable(operationToken: OperationToken): Promise; }