import { EventEmitter } from 'events' ; import logdown from 'logdown' ; import type { AccessTokenData } from '../auth/' ; enum TOPIC { ACCESS_TOKEN_REFRESH = 'AccessTokenStore.TOPIC.ACCESS_TOKEN_REFRESH' } export interface AccessTokenStore { on ( event , listener ) : this ; } export class AccessTokenStore extends EventEmitter { private readonly logger : logdown . Logger ; public static readonly TOPIC = TOPIC ; public accessToken ? : AccessTokenData ; constructor ( ) { super ( ) ; this . logger = logdown ( '@wireapp/api-client/AccessTokenStore' , { logger : console , markdown : false , } ) ; } public async delete ( ) { this . logger . log ( 'Deleting local access token' ) ; this . accessToken = undefined ; } public async updateToken ( accessToken ) { if ( this . accessToken !== accessToken ) { this . logger . log ( 'Saving local access token' ) ; this . accessToken = accessToken ; this . emit ( AccessTokenStore . TOPIC . ACCESS_TOKEN_REFRESH , this . accessToken ) ; } return this . accessToken ; } }