- Added @eslint/js dependency - Updated eslint.config.js for ESLint 9 compatibility - Added required globals (crypto, localStorage, React, etc.) - Fixed unused imports and variables - Disabled sort-imports temporarily - Formatted all files with Prettier
27 lines
818 B
TypeScript
27 lines
818 B
TypeScript
/**
|
|
* Config loader — parses process.env against the base schema + any extensions.
|
|
*/
|
|
|
|
import { type ZodRawShape, z } from 'zod';
|
|
import { baseEnvSchema } from './base-schema.js';
|
|
|
|
/**
|
|
* Load and validate environment configuration.
|
|
*
|
|
* @param extension - Additional Zod fields specific to this service
|
|
* @returns Parsed and validated config object
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const config = loadConfig({
|
|
* STRIPE_SECRET_KEY: z.string().min(1),
|
|
* BILLING_INTERNAL_KEY: z.string().optional(),
|
|
* });
|
|
* ```
|
|
*/
|
|
export function loadConfig<T extends ZodRawShape>(extension?: T) {
|
|
const schema = extension ? baseEnvSchema.extend(extension) : baseEnvSchema;
|
|
return schema.parse(process.env) as z.infer<typeof baseEnvSchema> &
|
|
(T extends ZodRawShape ? z.infer<z.ZodObject<T>> : Record<string, never>);
|
|
}
|