import * as _angular_platform_browser from '@angular/platform-browser'; import * as _angular_core from '@angular/core'; import { InjectionToken, ApplicationRef } from '@angular/core'; /** * A function type definition for loading environment data for an application. * It's a generic loader function that accepts parameters and returns a Promise of environment data. * * @template EnvironmentData The type of the environment data to be loaded. * @template Params The types of the parameters accepted by the loader function. * @param {...Params} args - Parameters passed to the loader function. * @returns {Promise} A promise resolving to the loaded environment data. */ type ApplicationEnvironmentLoader = (...args: Params) => Promise; /** * Creates a loader function for fetching application environment data over HTTP and caching it. * Utilizes `CacheStorageClient` for caching the fetched data to optimize performance and reduce network load. * * @template Data The type of the data expected from the HTTP request. * @param {Function} handler - A function that processes the fetched data and returns a promise resolving to the desired environment data format. * @returns {ApplicationEnvironmentLoader>} A loader function that fetches, caches, and processes environment data. * @example * const environmentLoader = createHttpApplicationEnvironmentLoader(async (dto) => { * return { apiEndpoint: dto.apiEndpoint, featureFlags: dto.featureFlags }; * }); */ declare function createHttpApplicationEnvironmentLoader(handler: (dto: unknown) => Promise): ApplicationEnvironmentLoader>; /** * The application environment module can be used to load environment data before application startup, * that can be used to load environment variables from an external URL. * * @template Data The type of the environment data. * @template Params The types of the parameters accepted by the loader function. * @param {ApplicationEnvironmentLoader} loader - A loader function that asynchronously loads the environment data. * @returns An object containing utilities for working with the application environment, including the InjectionToken * and functions for loading and bootstrapping the application with the environment. * @example * To add an application environment to your Angular application, follow the following steps: * 1. Create the application environment with your loader: * ```ts * import { createApplicationEnvironment, createHttpApplicationEnvironmentLoader } from '@odx/angular/sdk'; * import { z } from 'zod'; * * export const ApplicationConfigSchema = z.object({ * environment: z.enum(['dev', 'stage', 'prod']), * appName: z.string().default('App'), * }); * * const httpEnvironmentLoader = createHttpApplicationEnvironmentLoader((res) => res.json().then(ApplicationConfigSchema.parse)); * export const { injectApplicationEnvironment, bootstrapApplicationWithEnvironment } = createApplicationEnvironment(httpEnvironmentLoader); * ``` * This example creates an HTTP environment loader which parses the response as JSON and validate it against a schema * * 2. Provide the application environment: * ```ts * bootstrapApplicationWithEnvironment(['assets/config.json'], AppComponent, { providers: [] }); * ``` * * 3. Use the application environment via DI * ```ts * class MyService { * private readonly environment = injectApplicationEnvironment(); * } * ``` */ declare function createApplicationEnvironment(loader: ApplicationEnvironmentLoader): { APPLICATION_ENVIRONMENT: InjectionToken; injectApplicationEnvironment: () => Data; bootstrapApplicationWithEnvironment: (params: Parameters, rootComponent: _angular_core.Type, options?: _angular_core.ApplicationConfig | undefined, context?: _angular_platform_browser.BootstrapContext | undefined) => Promise; loadApplicationEnvironment: (...args: Parameters) => Promise; }; export { createApplicationEnvironment, createHttpApplicationEnvironmentLoader }; export type { ApplicationEnvironmentLoader };