75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/**
|
|
* In-memory stand-in for `expo-secure-store`.
|
|
*
|
|
* The real module is native-only. Both `StorageService` (auth token) and
|
|
* `StorageServiceCasual` (cart/region/OTP keys) run against this store, so
|
|
* persistence can be asserted directly instead of via mocks.
|
|
*/
|
|
|
|
const store = new Map<string, string>()
|
|
|
|
export const __store = store
|
|
|
|
export function __reset() {
|
|
store.clear()
|
|
}
|
|
|
|
export function __snapshot(): Record<string, string> {
|
|
return Object.fromEntries(store.entries())
|
|
}
|
|
|
|
/** Synchronous seeding for test setup (avoids waiting a microtask). */
|
|
export function __set(key: string, value: string) {
|
|
store.set(key, value)
|
|
}
|
|
|
|
export function __delete(key: string) {
|
|
store.delete(key)
|
|
}
|
|
|
|
export async function setItemAsync(key: string, value: string): Promise<void> {
|
|
if (typeof value !== 'string') {
|
|
throw new Error(`expo-secure-store mock: value for "${key}" must be a string`)
|
|
}
|
|
store.set(key, value)
|
|
}
|
|
|
|
export async function getItemAsync(key: string): Promise<string | null> {
|
|
return store.has(key) ? (store.get(key) as string) : null
|
|
}
|
|
|
|
export async function deleteItemAsync(key: string): Promise<void> {
|
|
store.delete(key)
|
|
}
|
|
|
|
export async function isAvailableAsync(): Promise<boolean> {
|
|
return true
|
|
}
|
|
|
|
export async function getItem(key: string): Promise<string | null> {
|
|
return getItemAsync(key)
|
|
}
|
|
|
|
export async function setItem(key: string, value: string): Promise<void> {
|
|
return setItemAsync(key, value)
|
|
}
|
|
|
|
export async function removeItem(key: string): Promise<void> {
|
|
return deleteItemAsync(key)
|
|
}
|
|
|
|
export const AFTER_FIRST_UNLOCK = 'AFTER_FIRST_UNLOCK'
|
|
export const WHEN_UNLOCKED = 'WHEN_UNLOCKED'
|
|
|
|
export default {
|
|
setItemAsync,
|
|
getItemAsync,
|
|
deleteItemAsync,
|
|
isAvailableAsync,
|
|
getItem,
|
|
setItem,
|
|
removeItem,
|
|
__reset,
|
|
__store,
|
|
}
|