// A WORLD'S OWN ENV VALUES, as a twin reads them. A World hands its env to every twin it runs (a spawned process, a // colocated host, a worker) on top of the caller's own, which only `runtime.environment.strip` keeps out. The runtime // names the variables the World itself sets in WORLD_ENV_NAMES_ENV; a twin that must agree with the app (a signing // secret the app verifies with) reads only those, so a developer's own exported secret never becomes World state. // Read per call: an import reads nothing, and a runtime with no `process` (a browser tab) has no World env. export const WORLD_ENV_NAMES_ENV = 'VOLTER_WORLD_ENV_NAMES'; /** The value the World set for `name`; undefined when the World sets none (whatever the caller's shell holds). */ export function worldEnvValue(name: string): string | undefined { const env = typeof process === 'undefined' ? undefined : process.env; const raw = env?.[WORLD_ENV_NAMES_ENV]; if (!raw) return undefined; let names: unknown; try { names = JSON.parse(raw); } catch { return undefined; } const value = Array.isArray(names) && names.includes(name) ? env![name] : undefined; return value ? value : undefined; }