store
Loads the store, its theme, languages and currencies in one call: the same call the root loader makes before every page.
import { store, StoreContext } from '@salla.sa/twilight-theme-engine/api/store';In plain words
Before any page can render, the engine needs to know which store it is drawing: its name and logo, the merchant's theme colors, the languages it sells in. store.settings() fetches all of that in one request.
You rarely call it yourself. The engine calls it for every page and shares the result through useStore, useTheme and useTwilight. Reach for this module when you need a part those hooks do not expose, such as the list of currencies.
Signature
store.settings(storeIdentifier?: string): Promise<StoreContext | null>
store.queries.settings(storeIdentifier?: string)
// key ['store', 'settings', storeIdentifier, locale, scope, requestedVersionId]
interface StoreContext {
store?: Store;
theme?: Theme;
languages?: Language[]; // an array here; the API sends an object
currencies?: Record<string, { code: string; name: string; symbol: string; amount: number; country_code: string }>;
external_services?: Record<string, unknown>;
headers?: Record<string, unknown>;
login?: { url: string; turnstile_site_key: string };
affiliate?: { utm_url: string; cta_enabled: boolean };
policy_url?: string;
debug?: boolean; // declared, never filled
trace_console?: boolean; // declared, never filled
}Try it live
- queryKey
- ["store","settings",null,"ar",null,null]
- fetchStatus
- idle
- fetched in this browser
- false
settings.store: {…} 24 keys
import { useQuery } from '@tanstack/react-query';
import { store } from '@salla.sa/twilight-theme-engine/api/store';
export function SettingsPanel() {
// Already cached: the root loader fetched these settings before the page rendered.
const { data } = useQuery(store.queries.settings());
const value = data?.store;
return <pre dir="ltr">{JSON.stringify(value, null, 2)}</pre>;
}
Example
import { useQuery } from '@tanstack/react-query';
import { store } from '@salla.sa/twilight-theme-engine/api/store';
export function CurrencyList() {
// Already cached: the root loader fetched these settings for this request.
const { data } = useQuery(store.queries.settings());
const currencies = Object.values(data?.currencies ?? {});
return (
<ul className="currency-list">
{currencies.map((currency) => (
<li key={currency.code}>
{currency.name} ({currency.symbol})
</li>
))}
</ul>
);
}
How it behaves
Endpoint:
GET store/settingswithinclude[]=store, settings, theme, theme_settings, external_services, currencies, languages, payments, product_widgets, rating and ratings, plusscope=<id>when a branch is selected. Its timeout is 5 s, shorter than the client default of 8 s.The identifier it resolved is sent explicitly in the
store-identifierheader, so the store it checked is the store that answers.It never throws. With no identifier it logs a warning and returns
null; any HTTP or network error is logged and also returnsnull. The root loader turnsnullinto the "Store Unavailable" page (SettingsError).languagesarrives as an object keyed by code ({ AR: {…}, EN: {…} }) and becomes an array; each entry also getsiso_code, which the Salla SDK's language switcher reads.rootBeforeLoadrunsensureQueryData(store.queries.settings())on every navigation, so a component reading the same options answers from the cache. The version in the key is the version the request asked for, not the one the settings report, so the server and browser keys match.
Gotchas
store.queries.settings('1510890315')andstore.queries.settings()are two cache entries even when they name the same store: the argument is part of the key. Call it with no argument to reuse what the root loader fetched.debugandtrace_consoleare declared onStoreContextbut never copied from the response, so they are alwaysundefined.docs/07-data-types.md imports
StoreContextfrom@salla.sa/twilight-theme-engine, which does not export it. Import the type from@salla.sa/twilight-theme-engine/api/store.docs/11-internationalization.md shows
storeQueries.settings(locale)andstoreQueries.keys.all. Neither exists: the export isstore,settingstakes an optional store identifier, and there is no keys factory.
Related
Reads the current store (name, logo, settings, contacts…) and can refresh it from the Salla SDK.
useTwilightReads everything TwilightProvider knows: store, theme, settings, language, direction, current page, login token and the Salla SDK.
resolveStoreIdentifierDecides which store the current request is about: the explicit value, the preview request, the URL, the server render or the host.