UNPKG

@cardql/react-native

Version:

CardQL SDK for React Native applications with mobile-optimized features

99 lines (83 loc) 2.58 kB
// Simple storage interface for React Native // In a real implementation, you might use: // - @react-native-async-storage/async-storage for general storage // - react-native-keychain for secure storage // - expo-secure-store for Expo projects export interface Storage { getItem(key: string): Promise<string | null>; setItem(key: string, value: string): Promise<void>; removeItem(key: string): Promise<void>; clear(): Promise<void>; } // Mock implementation for now - replace with actual storage in real usage class MockStorage implements Storage { private data: Map<string, string> = new Map(); async getItem(key: string): Promise<string | null> { return this.data.get(key) || null; } async setItem(key: string, value: string): Promise<void> { this.data.set(key, value); } async removeItem(key: string): Promise<void> { this.data.delete(key); } async clear(): Promise<void> { this.data.clear(); } } // For actual React Native implementation: /* import AsyncStorage from '@react-native-async-storage/async-storage'; import * as Keychain from 'react-native-keychain'; class SecureStorage implements Storage { async getItem(key: string): Promise<string | null> { try { // Use Keychain for sensitive data like API keys const credentials = await Keychain.getInternetCredentials(key); if (credentials) { return credentials.password; } return null; } catch (error) { console.warn('Failed to get secure item:', error); return null; } } async setItem(key: string, value: string): Promise<void> { try { await Keychain.setInternetCredentials(key, key, value); } catch (error) { console.warn('Failed to set secure item:', error); throw error; } } async removeItem(key: string): Promise<void> { try { await Keychain.resetInternetCredentials(key); } catch (error) { console.warn('Failed to remove secure item:', error); } } async clear(): Promise<void> { try { await Keychain.resetGenericPassword(); } catch (error) { console.warn('Failed to clear secure storage:', error); } } } export const storage: Storage = new SecureStorage(); */ // Export mock storage for now export const storage: Storage = new MockStorage(); // Utility functions export const createStorageKey = (prefix: string, key: string): string => { return `${prefix}:${key}`; }; export const isStorageAvailable = (): boolean => { try { return typeof storage !== "undefined"; } catch { return false; } };