import { readFile as _readFile } from 'node:fs/promises'; import { type ServiceProperties } from 'knifecycle'; import { type LogService } from 'common-services'; export declare enum NodeEnv { Test = "test", Development = "development", Production = "production" } export type BaseAppEnv = 'local'; export interface BaseAppEnvVars { NODE_ENV: NodeEnv; ISOLATED_ENV?: string; } export interface AppEnvVars extends BaseAppEnvVars { } export declare const DEFAULT_BASE_ENV: Partial; export declare const NODE_ENVS: NodeEnv[]; export declare const DEFAULT_ENV_SECRETS_FILES: ProcessEnvSecretFileOptions; export type ProcessEnvSecretFileOptions = { /** Whether non existing secret files lead to failure or not */ silentlyFail?: 'all' | 'none' | string[]; /** To avoid removing the secrets file env vars */ leaveSecretFileEnvVar?: boolean; /** Trim file content (defaults to 'end-new-line') */ trim?: 'none' | 'all' | 'start' | 'end' | 'end-new-line'; } & ({ /** Prefix to detect secrets to load in files */ prefix: string; } | { /** Suffix to detect secrets to load in files */ suffix: string; } | object); export interface ProcessEnvConfig { BASE_ENV?: Partial; ENV_SECRETS_FILES?: ProcessEnvSecretFileOptions; } export type ProcessEnvDependencies = ProcessEnvConfig & { APP_ENV: T; PROJECT_DIR: string; PROCESS_ENV: Partial; log?: LogService; readFile?: typeof _readFile; }; /** * Initialize the ENV service using process env plus dotenv files * loaded in `.env.node.${ENV.NODE_ENV}` and `.env.app.${APP_ENV}`. * @param {Object} services * The services `ENV` depends on * @param {Object} [services.BASE_ENV] * Base env vars that will be added to the environment * @param {Object} [services.ENV_SECRETS_FILES] * Options allowing to detect env vars to load in secret files * @param {Object} services.APP_ENV * The injected `APP_ENV` value * @param {Object} services.PROCESS_ENV * The injected `process.env` value * @param {Object} services.PROJECT_DIR * The NodeJS project directory * @param {Object} [services.log=noop] * An optional logging service * @return {Promise} * A promise of an object containing the actual env vars. */ declare function initENV({ BASE_ENV, ENV_SECRETS_FILES, APP_ENV, PROCESS_ENV, PROJECT_DIR, log, readFile, }: ProcessEnvDependencies): Promise; export declare function readEnvFile({ PROJECT_DIR, readFile, log, }: Required, 'PROJECT_DIR' | 'readFile' | 'log'>>, filePath: string): Promise>; /** * Extracts a secret from a file. Useful if you prefer * extracting your secrets yourself considering the * ENV service as unsafe. */ export declare function readSecretFile({ ENV_SECRETS_FILES, PROJECT_DIR, readFile, log, }: Required, 'ENV_SECRETS_FILES' | 'PROJECT_DIR' | 'readFile' | 'log'>>, ENV: Partial, name: keyof AppEnvVars): Promise>; declare const _default: ServiceProperties & typeof initENV; export default _default;