import ClientStorage from './storage'; const COOKIE_KEY = 'Auth0.login.transactions'; interface Transaction { state: string; nonce: string; scope: string; audience: string; appState?: any; code_verifier: string; code_challenge: string; } interface Transactions { [key: string]: Transaction; } export default class TransactionManager { private storage: ClientStorage; private transactions: Transactions; constructor() { this.storage = new ClientStorage(); this.transactions = this.storage.get(COOKIE_KEY) || {}; } public create(options: Transaction) { this.transactions[options.state] = options; this.storage.save(COOKIE_KEY, this.transactions, { daysUntilExpire: 1 }); } public get(state: string): Transaction { return this.transactions[state]; } public remove(state: string) { delete this.transactions[state]; this.storage.save(COOKIE_KEY, this.transactions, { daysUntilExpire: 1 }); } }