| 1 | import * as Layer from "effect/Layer"; |
| 2 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 3 | import * as Provider from "../Provider.ts"; |
| 4 | import { Account, AccountProvider } from "./Account.ts"; |
| 5 | import { Certificate, CertificateProvider } from "./Certificate.ts"; |
| 6 | import { IssueCertificateHttp } from "./IssueCertificateHttp.ts"; |
| 7 | |
| 8 | export class Providers extends Provider.ProviderCollection<Providers>()( |
| 9 | "ACME", |
| 10 | ) {} |
| 11 | |
| 12 | export type ProviderRequirements = Layer.Services<ReturnType<typeof providers>>; |
| 13 | |
| 14 | /** |
| 15 | * Registers the ACME resource providers ({@link Account}, |
| 16 | * {@link Certificate}) and the {@link IssueCertificateHttp} binding. |
| 17 | * |
| 18 | * DNS-01 solvers come from the DNS provider's own `providers()` layer — |
| 19 | * include e.g. `Cloudflare.providers()` alongside this one. |
| 20 | * |
| 21 | * @example |
| 22 | * ```typescript |
| 23 | * export default Alchemy.Stack( |
| 24 | * "Certs", |
| 25 | * { |
| 26 | * providers: Layer.mergeAll(ACME.providers(), Cloudflare.providers()), |
| 27 | * state: Alchemy.localState(), |
| 28 | * }, |
| 29 | * Effect.gen(function* () { |
| 30 | * const wildcard = yield* Wildcard; |
| 31 | * return { notAfter: wildcard.notAfter }; |
| 32 | * }), |
| 33 | * ); |
| 34 | * ``` |
| 35 | */ |
| 36 | export const providers = () => |
| 37 | Layer.effect(Providers, Provider.collection([Account, Certificate])).pipe( |
| 38 | Layer.provide(Layer.mergeAll(AccountProvider(), CertificateProvider())), |
| 39 | Layer.provideMerge(IssueCertificateHttp), |
| 40 | Layer.provideMerge(FetchHttpClient.layer), |
| 41 | Layer.orDie, |
| 42 | ); |