/** * AsyncStorage adapter for React Native */ import type { IIdentityStorage } from '../interfaces/IIdentity'; // AsyncStorage type definition for dependency injection interface IAsyncStorage { setItem(key: string, value: string): Promise; getItem(key: string): Promise; removeItem(key: string): Promise; getAllKeys(): Promise; multiRemove(keys: string[]): Promise; } export class AsyncStorageAdapter implements IIdentityStorage { private asyncStorage: IAsyncStorage; constructor(asyncStorage: IAsyncStorage) { this.asyncStorage = asyncStorage; } async setItem(key: string, value: string): Promise { await this.asyncStorage.setItem(key, value); } async getItem(key: string): Promise { return await this.asyncStorage.getItem(key); } async removeItem(key: string): Promise { await this.asyncStorage.removeItem(key); } async clear(): Promise { // Only clear identity-related keys const keys = await this.asyncStorage.getAllKeys(); const identityKeys = keys.filter((key) => key.startsWith('@IdentityManager')); if (identityKeys.length > 0) { await this.asyncStorage.multiRemove(identityKeys); } } }