@haatlabs-core/config-core
The environment variables every app reads, as parts an app composes with its own. A plain shape is exported, not a finished schema: in zod 4 an object schema with refinements cannot be extended.
const EnvSchema = z
.object({
...coreEnvShape({ apiPort: 4100, workerHealthPort: 4101 }),
...shopifyEnvShape({ defaultScopes: 'read_products' }),
...ownShape,
})
.superRefine((env, ctx) => {
coreEnvChecks(env, ctx);
shopifyEnvChecks(env, ctx, { required: true });
ownChecks(env, ctx);
});
export const loadConfig = (env = process.env) =>
loadConfigWith(EnvSchema, (e) => ({ ...mapCoreConfig(e), shopify: requireShopify(mapShopify(e)), ... }), env);
- Core (
coreEnvShape,coreEnvChecks,mapCoreConfig): environment, log level, the API's port and addresses, CORS, proxies, both databases, Redis, sessions, the fixed sign-in code, tracing, metrics, the worker and mail. A fixed code is refused in production unlessALLOW_FIXED_SIGN_IN_CODE=true. - Shopify (
shopifyEnvShape,shopifyEnvChecks,mapShopify,mapTokenEncryption): required, or optional with both keys or neither. - S3 and payments blocks, for the apps that have them.
loadConfigWith: a bad environment is aConfigErrornaming each variable, never its value.refuseInProduction,buildTestEnv(appName).
zod is a peer: the app's own copy is used.
CACHE_REDIS_URL (optional): the cache's own Redis, config.cache.redisUrl; never the
queues'. Unset: no cache. One that names the server (host and port) of REDIS_URL or
QUEUE_REDIS_URL is refused at start: the cache evicts, and would evict theirs.
Install
pnpm add @haatlabs-core/config-core
It leaves one package to your app, so the app holds one copy: zod.