BootData and the settings response types
Describes the raw store settings response: store, theme, currencies, languages, login and analytics configuration, and echoed headers.
import { BootData, CurrencyConfig, LanguageConfig, Language, ResponseHeaders, LoginConfig, JitsuConfig, AffiliateConfig, ExternalServices } from '@salla.sa/twilight-theme-engine/types';In plain words
Before the first page renders, the engine asks Salla for the store's settings in one request. BootData is the shape of that whole answer: the store, its theme, the currencies and languages it sells in, and configuration for signing in and analytics.
The engine keeps the useful part as useTwilight().settings (typed StoreContext), and that is where you usually meet these types: settings.languages is a list of Language, and each value of settings.currencies is a CurrencyConfig.
Signature
interface BootData {
store: Store;
theme: Theme;
currencies: Record<string, CurrencyConfig>;
languages: Record<string, LanguageConfig>;
external_services: ExternalServices;
headers: ResponseHeaders;
login: LoginConfig;
jitsu: JitsuConfig;
affiliate: AffiliateConfig;
swoole: string[];
policy_url: string;
debug: boolean;
trace_console: boolean;
}
interface CurrencyConfig { code: string; name: string; symbol: string; amount: number; country_code: string }
interface LanguageConfig { name: string; code: string; url: string; is_rtl: boolean; country_code: string }
interface Language { // an item of useTwilight().settings.languages
name: string; code: string; iso_code?: string;
url: string; // the flag image
is_rtl: boolean; country_code: string;
}
interface ResponseHeaders { 'S-Ray': number; 's-version-id': number; 's-scope-id': number; 's-scope-type': string }
interface LoginConfig {
url: string; turnstile_site_key: string;
turnstile: { key: string; level: string };
social: { google: boolean; facebook: boolean; apple: boolean; x: boolean };
}
interface JitsuConfig { host: string; key: string; events: string[]; context: { extra: { version: string; headers: string[] } } }
interface AffiliateConfig { utm_url: string; cta_enabled: boolean }
interface ExternalServices { [serviceName: string]: { services: Record<string, unknown> } }Try it live
BootData), and what the engine kept of it in useTwilight().settings for this page.Try this: read languages: the response sends an object keyed AR and EN, the engine an array.| BootData key | store.settings() | in useTwilight().settings |
|---|---|---|
store | kept | present |
theme | kept | present |
currencies | kept | present |
languages | converted to an array | present |
external_services | kept | present |
headers | kept | present |
login | kept | present |
affiliate | kept | present |
policy_url | kept | present |
debug | dropped | undefined |
trace_console | dropped | undefined |
jitsu | dropped | undefined |
swoole | dropped | undefined |
settings.languages: Array(2)
import { useTwilight } from '@salla.sa/twilight-theme-engine';
import type { Language } from '@salla.sa/twilight-theme-engine/types';
export function useLanguages(): Language[] {
// An array here, converted from { AR: {...}, EN: {...} } with iso_code added.
return useTwilight().settings.languages ?? [];
}
Example
import type { CurrencyConfig, Language } from '@salla.sa/twilight-theme-engine/types';
import { useTwilight } from '@salla.sa/twilight-theme-engine';
export function LocaleOptions() {
const { settings } = useTwilight();
const languages: Language[] = settings.languages ?? [];
const currencies: CurrencyConfig[] = Object.values(settings.currencies ?? {});
return (
<div className="locale-options">
<ul>
{languages.map((language) => (
<li key={language.code}>{language.name}</li>
))}
</ul>
<ul>
{currencies.map((currency) => (
<li key={currency.code}>
{currency.code} {currency.symbol.trim()}
</li>
))}
</ul>
</div>
);
}
How it behaves
store.settings()(@salla.sa/twilight-theme-engine/api/store) requestsstore/settingsand returnsStoreContext. It keepsstore,theme,currencies,external_services,headers,login,affiliateandpolicy_url, convertslanguages, and dropsjitsu,swoole,debugandtrace_console. The live demo lists it key by key.languagesarrives keyed by uppercase code ({ AR: {…}, EN: {…} }, each aLanguageConfig) and becomes an array ofLanguage, each withiso_codecopied fromcode, because the SDK's language picker readsiso_code.Language.urlis the flag image (https://assets.salla.sa/images/flags/ar.svg), not a link to the store in that language.CurrencyConfig.amountis a conversion rate from the store currency: on the demo store, whose currency is SAR, AED hasamount: 0.978296.No engine code imports
BootDataor its parts: they exist for code of yours that handles the raw response.StoreContexthas its own page under Utilities.
Gotchas
useTwilight().settings.debugandtrace_consoleare alwaysundefined:StoreContextdeclares both, butstore.settings()never copies them from the response.ResponseHeadersrequiress-scope-idands-scope-type; the demo store's response carries onlyS-Rayands-version-id.CurrencyConfig.symbolcan carry spaces: AED is" د.إ"on the demo store. Trim it before placing it next to a number.
Related
The processed store settings type, re-exported here so code that calls the head helpers can type the settings it passes.
storeLoads the store, its theme, languages and currencies in one call: the same call the root loader makes before every page.
useTwilightReads everything TwilightProvider knows: store, theme, settings, language, direction, current page, login token and the Salla SDK.
StoreDescribes the current store and its store-wide settings: name, logo, address, contacts, social accounts, apps and feature switches.
ThemeDescribes the merchant's theme record: colors, font, live or preview mode, and the settings object your twilight.json declares.