export type StorageDriver = Readonly<{ get: (key: string) => Promise; set: (key: string, newValue: T | null) => Promise; has: (key: string) => Promise; }>; export type GetStorageType = Readonly<{ [key in `get${Capitalize}`]: () => Promise; }>; export type SetStorageType = Readonly<{ [key in `set${Capitalize}`]: (newValue: T | null) => Promise; }>; export type HasStorageType = Readonly<{ [key in `has${Capitalize}`]: () => Promise; }>; export type StorageType = GetStorageType & SetStorageType & HasStorageType; export type Authorization = Readonly<{ token: string; expiry: string; }>; export type AuthorizationStorage = StorageType<'authorization', Authorization>; export type Roles = ReadonlyArray; export type RolesStorage = StorageType<'roles', Roles>; const KEY_AUTHORIZATION = 'authorization'; const KEY_ROLES = 'roles'; export type NotifiStorage = AuthorizationStorage & RolesStorage; export class NotifiFrontendStorage implements NotifiStorage { constructor(private _driver: StorageDriver) {} getAuthorization(): Promise { return this._driver.get(KEY_AUTHORIZATION); } setAuthorization(newValue: Authorization | null): Promise { return this._driver.set(KEY_AUTHORIZATION, newValue); } hasAuthorization(): Promise { return this._driver.has(KEY_AUTHORIZATION); } getRoles(): Promise { return this._driver.get(KEY_ROLES); } setRoles(newValue: Roles | null): Promise { return this._driver.set(KEY_ROLES, newValue); } hasRoles(): Promise { return this._driver.has(KEY_ROLES); } }