import { GetAsyncStorageItemParams, SetAsyncStorageItemParams, RemoveAsyncStorageItemParams, } from '@shopify/shop-minis-platform/actions' import {useHandleAction} from '../../internal/useHandleAction' import {useShopActions} from '../../internal/useShopActions' export interface UseAsyncStorageReturns { /** * Get an item from the async storage. */ getItem: (params: GetAsyncStorageItemParams) => Promise /** * Set an item in the async storage. */ setItem: (params: SetAsyncStorageItemParams) => Promise /** * Remove an item from the async storage. */ removeItem: (params: RemoveAsyncStorageItemParams) => Promise /** * Get all keys in the async storage. */ getAllKeys: () => Promise /** * Clear all items from the async storage. */ clear: () => Promise } export function useAsyncStorage(): UseAsyncStorageReturns { const { getPersistedItem, setPersistedItem, removePersistedItem, getAllPersistedKeys, clearPersistedItems, } = useShopActions() return { getItem: useHandleAction(getPersistedItem), setItem: useHandleAction(setPersistedItem), removeItem: useHandleAction(removePersistedItem), getAllKeys: useHandleAction(getAllPersistedKeys), clear: useHandleAction(clearPersistedItems), } } /** * The `useAsyncStorage` hook provides functions to interact with persistent storage for non-sensitive data. Use this for user preferences, UI state, cached content, or any data where performance matters and encryption is not required. Data is stored in plaintext and persists between app sessions. * * > Note: Use `useAsyncStorage` for non-sensitive data like themes, preferences, cached content, or application state. It supports multiple key-value pairs. Use `useSecureStorage` for sensitive data like authentication tokens. It provides hardware-backed encryption but only stores one secret per Mini and has slower performance. * * > Caution: Do not store images, base64-encoded images, blobs, or any other binary data in async storage. This is against Shop Minis guidelines and will cause your Mini to be rejected during review. Async storage is designed for small, serializable key-value pairs only. For image handling, use the `useImageUpload` or `useCreateImageContent` hooks instead. * @publicDocs */ export type UseAsyncStorageGeneratedType = () => UseAsyncStorageReturns