/** * Client-side environment variable access for Next.js applications. * * This module provides a function to read runtime environment variables * that were injected by the PublicEnvScript server component. * * @remarks * This is part of the simplified Next.js API. For advanced configuration loading * with custom loaders or direct AWS SDK integration, import from `@dyanet/config-aws` directly: * * ```typescript * import { ConfigManager, EnvironmentLoader } from '@dyanet/config-aws'; * ``` * * @example * ```tsx * 'use client'; * * import { env } from '@dyanet/nextjs-config-aws'; * * function MyComponent() { * const apiUrl = env('API_URL'); * const appName = env('APP_NAME', 'Default App'); * * return
API: {apiUrl}, App: {appName}
; * } * ``` */ /** * Type declaration for the global window object with environment variables. */ declare global { interface Window { __ENV?: Record; [key: string]: unknown; } } /** * Retrieves a runtime environment variable value. * * This function reads from the global window object where environment * variables were injected by the PublicEnvScript component. * * @param key - The environment variable name * @returns The value of the environment variable, or undefined if not found * * @example * ```ts * const apiUrl = env('API_URL'); * if (apiUrl) { * // Use the API URL * } * ``` */ export declare function env(key: string): string | undefined; /** * Retrieves a runtime environment variable value with a default. * * @param key - The environment variable name * @param defaultValue - The default value to return if the variable is not found * @returns The value of the environment variable, or the default value * * @example * ```ts * const apiUrl = env('API_URL', 'http://localhost:3000'); * // apiUrl is guaranteed to be a string * ``` */ export declare function env(key: string, defaultValue: T): string | T; /** * Retrieves a runtime environment variable from a custom variable name. * * Use this when you've configured PublicEnvScript with a custom variableName. * * @param variableName - The global variable name to read from * @param key - The environment variable name * @returns The value of the environment variable, or undefined if not found * * @example * ```ts * // If PublicEnvScript was configured with variableName="__MY_ENV" * const apiUrl = envFrom('__MY_ENV', 'API_URL'); * ``` */ export declare function envFrom(variableName: string, key: string): string | undefined; /** * Retrieves a runtime environment variable from a custom variable name with a default. * * @param variableName - The global variable name to read from * @param key - The environment variable name * @param defaultValue - The default value to return if the variable is not found * @returns The value of the environment variable, or the default value */ export declare function envFrom(variableName: string, key: string, defaultValue: T): string | T; /** * Gets all runtime environment variables. * * @param variableName - The global variable name to read from (default: '__ENV') * @returns A copy of all environment variables * * @example * ```ts * const allEnv = getAllEnv(); * console.log(allEnv); // { API_URL: '...', APP_NAME: '...' } * ``` */ export declare function getAllEnv(variableName?: string): Record; /** * Checks if a runtime environment variable exists. * * @param key - The environment variable name * @param variableName - The global variable name to read from (default: '__ENV') * @returns True if the variable exists, false otherwise * * @example * ```ts * if (hasEnv('FEATURE_FLAG')) { * // Feature is enabled * } * ``` */ export declare function hasEnv(key: string, variableName?: string): boolean; export default env; //# sourceMappingURL=env.d.ts.map