@fluid-app/storage-manager
Version:
Storage management utilities for Fluid Commerce applications
101 lines (97 loc) • 2.67 kB
TypeScript
/**
* Storage keys
*/
declare const STORAGE_KEYS: {
readonly CART: "fs_cart";
readonly EVENT_QUEUE: "fs_event_queue";
readonly SERVER_SETTINGS: "fs_server_settings";
readonly SETTINGS_OVERRIDE: "fs_settings_override";
readonly ATTRIBUTION_CACHE: "fs_attribution_cache";
readonly AUTHENTICATED_USER: "fs_authenticated_user";
};
/**
* Cookie keys
*/
declare const COOKIE_KEYS: {
readonly LOCALE: "fluid_locale";
readonly COUNTRY: "fluid_country";
readonly LANGUAGE: "fluid_language";
readonly JOURNEY: "fluid_journey";
readonly JOURNEY_SYNCED: "fluid_journey_synced";
readonly AFFILIATE: "fluid_affiliate";
readonly SESSION: "fluid_session";
readonly AUTHENTICATED_JWT: "fluid_authenticated_jwt";
readonly AUTHENTICATED_AT: "fluid_authenticated_at";
};
type StorageKey = (typeof STORAGE_KEYS)[keyof typeof STORAGE_KEYS];
type CookieKey = (typeof COOKIE_KEYS)[keyof typeof COOKIE_KEYS];
type SetArg = {
key: StorageKey;
value: string;
} | {
key: CookieKey;
value: string;
};
type GetArg = {
key: StorageKey;
} | {
key: CookieKey;
};
type SetObjectArg<T> = {
key: StorageKey;
value: T;
} | {
key: CookieKey;
value: T;
};
type GetObjectArg = {
key: StorageKey;
} | {
key: CookieKey;
};
/**
* Manages storage operations
*/
declare class StorageManager {
private localStorage;
private isCookieKey;
private isStorageKey;
/**
* Set an item in storage (localStorage or cookie)
*/
setItem(arg: SetArg): void;
/**
* Get an item from storage (localStorage or cookie)
*/
getItem(arg: GetArg): string | null;
/**
* Remove an item from storage (localStorage or cookie)
*/
removeItem(arg: GetArg): void;
/**
* Set an object in storage (localStorage or cookie)
*/
setObject<T>(arg: SetObjectArg<T>): void;
/**
* Get an object from storage (localStorage or cookie)
*/
getObject<T>(arg: GetObjectArg): T | null;
/**
* Utility to set a cookie on both the current domain and apex domain (if different)
* @param name Cookie name
* @param value Cookie value
* @param options Optional cookie options (expires, path, secure, sameSite)
*/
private setCookieOnApexAndSubdomains;
}
/**
* Check if the code is running in a browser environment
*/
declare const isBrowser: boolean;
/**
* Get a cookie value by name
* @param name The name of the cookie to retrieve
* @returns The cookie value or null if not found
*/
declare const getCookie: (name: string) => string | null;
export { COOKIE_KEYS, STORAGE_KEYS, StorageManager, getCookie, isBrowser };