Skip to content
Twilight React Playground
ثيم رائدaren

getStoreIdentifier

functionAdvancedserverbrowser

Returns which store the current request or page is for, as sent in the store-identifier header; platform plumbing that themes rarely need.

import { getStoreIdentifier } from '@salla.sa/twilight-theme-engine/utils';

In plain words

Every call to the Salla API names the store it is about. getStoreIdentifier() returns that name: a store id, a username or a domain, whichever the request, the address or the server render provided.

It exists for the platform: the API client already sends it with every request. A theme needs it only to label its own requests, caches or logs.

Signature

function getStoreIdentifier(explicit?: string): string   // '' when nothing answers

Example

app/lib/cacheKey.ts
import { getStoreIdentifier } from '@salla.sa/twilight-theme-engine/utils';

/** Prefixes a cache key with the store it belongs to. */
export function storeCacheKey(key: string): string {
  return `${getStoreIdentifier() || 'unknown-store'}:${key}`;
}

How it behaves

  • It only delegates: getStoreIdentifier(x) returns resolveStoreIdentifier(x) from @salla.sa/twilight-theme-engine/api/store, whose page lists the order of the answers. The API client sets the store-identifier header through this name.

  • On a merchant's own domain the answer is the host. On localhost and preview.salla.design it comes from ?storeId=, its cookie, or the store username in the first path segment.

Gotchas

  • The answer's form depends on the host: a numeric id on one, a username such as dev-vgckq3fssfhjewwi or a domain on another. Treat it as an opaque string; never parse it as a number.

Related

Source and docs