applyAppScopeMocks
Overrides one installed app's private app.* settings with preview values in the browser; platform plumbing for app previews, not for themes.
import { applyAppScopeMocks, AppScopeContexts, AppConfigBag } from '@salla.sa/twilight-theme-engine/utils';In plain words
Salla apps that inject scripts into a storefront each read their own settings (app.color, app.pixel_id…) from a private copy the engine installs, Salla.appScope(scopeId). applyAppScopeMocks(scopeId, values) lays preview values over one app's real settings, so a partner can see a setting before saving it.
It exists for the platform's app preview tooling. A theme has no reason to call it.
Signature
function applyAppScopeMocks(appScopeId: string, mocks: AppConfigBag): boolean
type AppConfigBag = Record<string, unknown>; // keys without 'app.': app.color → color
interface AppScopeContexts {
apps: Record<string, AppConfigBag>; // one bucket per appScopeId
}Example
import { applyAppScopeMocks, type AppConfigBag } from '@salla.sa/twilight-theme-engine/utils';
/** Preview tooling: show an app with unsaved settings. False when the app is not on this page. */
export function previewAppSettings(scopeId: string, draft: AppConfigBag): boolean {
return applyAppScopeMocks(scopeId, draft);
}
How it behaves
It calls
Salla.__appScopeMock, which the engine's app-scope installer defines (inline in the root head, or fromAppsSnippetsin the browser). The app's bucket becomes{ ...its real values, ...mocks }.Each call starts again from the real values: mocks do not pile up, and
applyAppScopeMocks(scopeId, {})restores the real settings.It returns
falseon the server, before the installer has run, and for a scope id with no bucket.Only
app.*keys are private.config.getfor any other key reads the realSalla.config.AppScopeContextsis the shape of the per-app settings the engine fills those buckets from.
Gotchas
Nothing re-runs the app. It sees the new values only on its next
config.get('app.…'), so an app that read its settings once at start-up keeps showing the old ones.
Related
Source and docs
- Engine source:
packages/theme-engine/src/utils/app-scope.ts