| 1 | import type { |
| 2 | GetZoneRrsetError, |
| 3 | GetZoneRrsetResponse, |
| 4 | ListZoneRrsetsError, |
| 5 | ListZoneRrsetsRequest, |
| 6 | ListZoneRrsetsResponse, |
| 7 | } from "@distilled.cloud/hetzner/zone_rrsets"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | import * as Binding from "../Binding.ts"; |
| 10 | import type { RuntimeContext } from "../RuntimeContext.ts"; |
| 11 | import type { Zone } from "./Zone.ts"; |
| 12 | |
| 13 | /** |
| 14 | * Binding that lets runtime code read Hetzner Cloud DNS RRSets. |
| 15 | * |
| 16 | * Authenticates with the ambient `HCLOUD_TOKEN` (a project-scoped Cloud |
| 17 | * API token). The zone is fixed by `ReadDns(zone)` so calls take no |
| 18 | * zone id. Provide {@link ReadDnsHttp} on the Action / Function Effect. |
| 19 | * |
| 20 | * |
| 21 | * ### Reading RRSets at runtime |
| 22 | * **Example:** List and get RRSets from an Action |
| 23 | * Bind the client in the Action's Init phase and provide {@link ReadDnsHttp}. |
| 24 | * Pass the {@link Zone} resource directly (it's an `Effect`), or |
| 25 | * `yield* Zone` for a resolved value. |
| 26 | * ```typescript |
| 27 | * import * as Alchemy from "alchemy"; |
| 28 | * import * as Hetzner from "alchemy/Hetzner"; |
| 29 | * import * as Effect from "effect/Effect"; |
| 30 | * |
| 31 | * const Check = Alchemy.Action( |
| 32 | * "Check", |
| 33 | * Effect.gen(function* () { |
| 34 | * const dns = yield* Hetzner.ReadDns(zone); |
| 35 | * return Effect.fn(function* () { |
| 36 | * const listed = yield* dns.listRecordSets({ type: ["A"] }); |
| 37 | * const rrset = yield* dns.getRecordSet("www", "A"); |
| 38 | * return { listed, rrset }; |
| 39 | * }); |
| 40 | * }).pipe(Effect.provide(Hetzner.ReadDnsHttp)), |
| 41 | * ); |
| 42 | * ``` |
| 43 | * |
| 44 | * @binding |
| 45 | * @product DNS |
| 46 | */ |
| 47 | export interface ReadDns extends Binding.Service< |
| 48 | ReadDns, |
| 49 | "Hetzner.DNS.ReadDns", |
| 50 | (zone: Zone) => Effect.Effect<ReadDnsClient> |
| 51 | > {} |
| 52 | |
| 53 | export const ReadDns = Binding.Service<ReadDns>("Hetzner.DNS.ReadDns"); |
| 54 | |
| 55 | /** List-RRSets request, minus the zone id (bound at `ReadDns(zone)` time). */ |
| 56 | export type ListRecordSetsRequestInput = Omit< |
| 57 | ListZoneRrsetsRequest, |
| 58 | "id_or_name" |
| 59 | >; |
| 60 | |
| 61 | /** |
| 62 | * Read-only DNS RRSet operations. The zone is fixed when the client is |
| 63 | * bound, so no `id_or_name` is passed per call. |
| 64 | */ |
| 65 | export interface ReadDnsClient { |
| 66 | /** Fetch a single RRSet by name and type. */ |
| 67 | getRecordSet( |
| 68 | name: string, |
| 69 | type: string, |
| 70 | ): Effect.Effect<GetZoneRrsetResponse, GetZoneRrsetError, RuntimeContext>; |
| 71 | /** List RRSets in the bound zone. */ |
| 72 | listRecordSets( |
| 73 | request?: ListRecordSetsRequestInput, |
| 74 | ): Effect.Effect<ListZoneRrsetsResponse, ListZoneRrsetsError, RuntimeContext>; |
| 75 | } |