import config from './config' ; interface TestVariationsMap { [ key ] : string ; } export class UserSession { public setTestVariation ( testName , variationName ) { const variationsMap = this . loadVariations ( ) ; variationsMap [ testName ] = variationName ; this . saveVariations ( variationsMap ) ; } public getTestVariation ( testName ) { const variationsMap = this . loadVariations ( ) ; return variationsMap [ testName ] ; } public reset ( ) { this . saveVariations ( { } ) ; } private saveVariations ( variationsMap ) { config . sessionPersister . saveUserSession ( JSON . stringify ( variationsMap ) , config . userSessionDaysToLive ) ; } private loadVariations ( ) { const variationsMap = JSON . parse ( config . sessionPersister . loadUserSession ( ) || '{}' ) ; return variationsMap ; } } export default new UserSession ( ) ;