import Scope from '../constants/scope'; import Identifiable from './identifiable'; export default class Token implements Identifiable { public readonly id: string; public readonly token: string; public readonly type: string; public readonly scope: Scope[]; public readonly expiryDate: Date; public readonly userId: string; constructor(token: {token: string, type: string, expiryDate: Date, scope?: Scope[], userId: string}) { this.id = `${token.type} ${token.token}`; this.token = token.token; this.type = token.type; this.scope = token.scope || []; this.expiryDate = token.expiryDate; this.userId = token.userId; } public getTimeToLiveInSeconds(): number { return Math.ceil((this.expiryDate.getTime() - Date.now()) / 1000); } }