| 1 | import type * as appconfigdata from "@distilled.cloud/aws/appconfigdata"; |
| 2 | import type * as Duration from "effect/Duration"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import type { Application } from "./Application.ts"; |
| 6 | import type { ConfigurationProfile } from "./ConfigurationProfile.ts"; |
| 7 | import type { Environment } from "./Environment.ts"; |
| 8 | |
| 9 | /** |
| 10 | * Options for a {@link GetConfiguration} binding. |
| 11 | */ |
| 12 | export interface GetConfigurationOptions { |
| 13 | /** |
| 14 | * The minimum interval the configuration session enforces between polls |
| 15 | * (e.g. `"30 seconds"` or `Duration.seconds(30)`; a bare number is |
| 16 | * milliseconds). Sent to AppConfig as whole seconds. If omitted, AppConfig |
| 17 | * uses the session default (60 seconds). |
| 18 | */ |
| 19 | requiredMinimumPollInterval?: Duration.Input; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * The configuration returned by a {@link GetConfiguration} poll. |
| 24 | */ |
| 25 | export interface GetConfigurationResult { |
| 26 | /** |
| 27 | * The deployed configuration content as text. `undefined` on the very first |
| 28 | * poll if the deployment has not completed; on subsequent polls AppConfig |
| 29 | * returns an empty body when nothing changed and the last-seen content is |
| 30 | * returned instead. |
| 31 | */ |
| 32 | content: string | undefined; |
| 33 | /** MIME type of the content (e.g. `application/json`). */ |
| 34 | contentType: string | undefined; |
| 35 | /** The version label of the deployed configuration, if any. */ |
| 36 | versionLabel: string | undefined; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Fetch the live, deployed configuration for a Lambda (or other AWS runtime) |
| 41 | * via the AppConfig data plane. Backed by `StartConfigurationSession` + |
| 42 | * `GetLatestConfiguration`: the binding starts a session on first use, caches |
| 43 | * the poll token, and returns the latest content on each call. |
| 44 | * |
| 45 | * Provide `AppConfig.GetConfigurationHttp` on the hosting function's Effect |
| 46 | * (`Effect.provide(AppConfig.GetConfigurationHttp)`) to satisfy the binding. |
| 47 | * |
| 48 | * ### Reading Live Configuration |
| 49 | * **Example:** Fetch config from a Lambda |
| 50 | * ```typescript |
| 51 | * const getConfig = yield* AppConfig.GetConfiguration(app, env, profile); |
| 52 | * const { content, contentType } = yield* getConfig(); |
| 53 | * const settings = JSON.parse(content ?? "{}"); |
| 54 | * ``` |
| 55 | * |
| 56 | * @binding |
| 57 | */ |
| 58 | export interface GetConfiguration extends Binding.Service< |
| 59 | GetConfiguration, |
| 60 | "AWS.AppConfig.GetConfiguration", |
| 61 | ( |
| 62 | application: Application, |
| 63 | environment: Environment, |
| 64 | configurationProfile: ConfigurationProfile, |
| 65 | options?: GetConfigurationOptions, |
| 66 | ) => Effect.Effect< |
| 67 | () => Effect.Effect< |
| 68 | GetConfigurationResult, |
| 69 | | appconfigdata.StartConfigurationSessionError |
| 70 | | appconfigdata.GetLatestConfigurationError |
| 71 | > |
| 72 | > |
| 73 | > {} |
| 74 | export const GetConfiguration = Binding.Service<GetConfiguration>( |
| 75 | "AWS.AppConfig.GetConfiguration", |
| 76 | ); |