import { nanoid } from 'nanoid' ; import { BrowserStorageService , StorageService } from '@empathyco/x-storage-service' ; import { SessionService } from './types' ; /**
 * Default implementation for the  SessionService .
 *
 *  public export class DefaultSessionService implements SessionService { public public static readonly SESSION_ID_KEY = 'session-id' ; /**
     * Global instance of the  SessionService .
      public static instance : SessionService = new DefaultSessionService ( ) ; public constructor ( protected storageService = new BrowserStorageService ( localStorage , 'x' ) , protected ttlMs = 1800000 ) { } returns public getSessionId ( ) { const sessionId = this . storageService . getItem ( DefaultSessionService . SESSION_ID_KEY ) ?? nanoid ( ) ; this . storageService . setItem ( DefaultSessionService . SESSION_ID_KEY , sessionId , Date . now ( ) + this . ttlMs ) ; return sessionId ; } public clearSessionId ( ) { this . storageService . removeItem ( DefaultSessionService . SESSION_ID_KEY ) ; } }