/** * Server-side configuration loading for Next.js applications. * Provides a cached getConfig() function that uses ConfigManager from @dyanet/config-aws. * * This module provides a simplified, opinionated API that hides loader complexity. * For advanced usage such as custom loaders, direct AWS SDK integration, or * fine-grained control over configuration loading, import from `@dyanet/config-aws` directly: * * @example * ```typescript * // Advanced usage with custom loaders * import { * ConfigManager, * EnvironmentLoader, * SecretsManagerLoader, * SSMParameterStoreLoader, * } from '@dyanet/config-aws'; * * const manager = new ConfigManager({ * loaders: [ * new EnvironmentLoader({ prefix: 'APP_' }), * new SecretsManagerLoader({ secretName: '/my-app/config' }), * ], * schema: mySchema, * }); * await manager.load(); * const config = manager.getAll(); * ``` */ import type { ZodType } from 'zod'; import { EnvironmentMode } from './internal/environment'; import { AwsOptions } from './internal/loader-factory'; /** * Options for Next.js configuration loading. * * This interface provides a simplified, opinionated API that hides loader complexity * and provides automatic environment detection. * * @example * ```typescript * // Minimal usage - just schema * const config = await getConfig({ schema: mySchema }); * * // With AWS Secrets Manager * const config = await getConfig({ * schema: mySchema, * aws: { secretName: '/myapp/config' } * }); * * // Force AWS in development * const config = await getConfig({ * schema: mySchema, * aws: { secretName: '/myapp/config' }, * forceAwsInDev: true * }); * ``` */ export interface NextConfigOptions> { /** Zod schema for validation */ schema?: ZodType; /** * AWS configuration options. * When provided, enables loading from AWS services based on environment. */ aws?: AwsOptions; /** * Override environment detection ('development' | 'production' | 'test'). * When provided, this takes precedence over NODE_ENV auto-detection. */ environment?: EnvironmentMode; /** * Force AWS loading even in development mode. * By default, AWS sources are only loaded in production. * @default false */ forceAwsInDev?: boolean; /** * Enable caching. * @default true */ cache?: boolean; /** * Cache TTL in milliseconds. * @default 60000 (1 minute) */ cacheTTL?: number; /** * Enable logging. * @default false */ enableLogging?: boolean; } /** * Load configuration for Next.js server-side use. * * This function provides automatic environment detection and caching to avoid * repeated AWS API calls during request handling. Configuration is cached based * on the AWS options, environment, and forceAwsInDev setting. * * Environment Behavior: * - development: env vars + .env.local/.env files, AWS only if forceAwsInDev * - production: env vars + .env file + AWS sources (if configured) * - test: env vars only (no file or AWS access) * * @example * ```typescript * import { getConfig } from '@dyanet/nextjs-config-aws'; * import { z } from 'zod'; * * const schema = z.object({ * DATABASE_URL: z.string(), * API_KEY: z.string(), * }); * * // Minimal usage - auto-detects environment * const config = await getConfig({ schema }); * * // With AWS Secrets Manager (loaded in production) * const config = await getConfig({ * schema, * aws: { secretName: '/my-app/config', region: 'us-east-1' } * }); * * // Force AWS in development for testing * const config = await getConfig({ * schema, * aws: { secretName: '/my-app/config' }, * forceAwsInDev: true * }); * ``` * * @param options Configuration options * @returns Promise resolving to the validated configuration object * @throws {ValidationError} When schema validation fails (includes invalid key names) */ export declare function getConfig>(options?: NextConfigOptions): Promise; /** * Clear the configuration cache. * Useful for testing or when configuration needs to be reloaded. */ export declare function clearConfigCache(): void; /** * Get the current cache size. * @returns Number of cached configurations */ export declare function getConfigCacheSize(): number; /** * Get the AWS API call count. * This is primarily for testing the caching behavior. * @internal */ export declare function getAwsApiCallCount(): number; /** * Reset the AWS API call count. * This is primarily for testing the caching behavior. * @internal */ export declare function resetAwsApiCallCount(): void; /** * Invalidate a specific cache entry by regenerating with the same options. * @param options The options used to create the cache entry */ export declare function invalidateConfig(options: NextConfigOptions): void; //# sourceMappingURL=get-config.d.ts.map