// Sandbox Mode is a per-browser, staff-only choice. It is read once, at module load in environment.ts, // because a hundred-odd modules capture their API hosts at load; a live switch would leave half of // them pointing at the old stack. Entering and leaving therefore reload the page. export const SANDBOX_MODE_KEY = 'akashic_mode_staff'; type ModeStorage = Pick; export const readSandboxMode = (storage: ModeStorage): 'sandbox' | null => { try { return storage.getItem(SANDBOX_MODE_KEY) === 'sandbox' ? 'sandbox' : null; } catch { return null; } }; export const enterSandboxMode = (storage: ModeStorage, reload: () => void): void => { try { storage.setItem(SANDBOX_MODE_KEY, 'sandbox'); } catch { } reload(); }; export const leaveSandboxMode = (storage: ModeStorage, reload: () => void): void => { try { storage.removeItem(SANDBOX_MODE_KEY); } catch { } reload(); }; // Callers pass their own `reload` so enter/leave stay testable without touching the real page. This // is that reload, for the one caller - the banner's Leave button - that is not free to write // `window.location` in its own source: a regression test on that file greps for exactly that // substring, to guarantee the banner never reads the URL to decide what to show. export const reloadPage = (): void => { window.location.reload(); };