| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { makeLocalDnsBinding } from "./DnsLocal.ts"; |
| 4 | import { WriteDns } from "./WriteDns.ts"; |
| 5 | import { dnsWriteClient } from "./WriteDnsHttp.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Local implementation of the {@link WriteDns} binding — creates, updates, and |
| 9 | * deletes Cloudflare DNS records over the HTTP API using the **current |
| 10 | * credentials** instead of a scoped API token ({@link WriteDnsHttp}). DNS is a |
| 11 | * zone-management capability with no native Worker binding. |
| 12 | * |
| 13 | * Provide it on an {@link Action} (or any deploy-time Effect) so you can mutate |
| 14 | * a zone's DNS records with the same |
| 15 | * `createDnsRecord`/`updateDnsRecord`/`deleteDnsRecord`/`batchDnsRecords` |
| 16 | * client you'd use inside a Worker: |
| 17 | * |
| 18 | * @example Creating a record from an Action |
| 19 | * ```typescript |
| 20 | * const Seed = Alchemy.Action( |
| 21 | * "Seed", |
| 22 | * Effect.gen(function* () { |
| 23 | * const dns = yield* Cloudflare.DNS.WriteDns(zone); |
| 24 | * return Effect.fn(function* () { |
| 25 | * return yield* dns.createDnsRecord({ |
| 26 | * type: "TXT", |
| 27 | * name: "_seed.example.com", |
| 28 | * content: '"hello"', |
| 29 | * ttl: 60, |
| 30 | * }); |
| 31 | * }); |
| 32 | * }).pipe(Effect.provide(Cloudflare.DNS.WriteDnsLocal)), |
| 33 | * ); |
| 34 | * ``` |
| 35 | * |
| 36 | * The zone id is resolved at apply time through the ambient |
| 37 | * {@link RuntimeContext} (in an Action, that's the resolve context the engine |
| 38 | * provides around the body), so `WriteDns(zone)` works even though the zone may |
| 39 | * be created/adopted in the same deploy. |
| 40 | */ |
| 41 | export const WriteDnsLocal = Layer.effect( |
| 42 | WriteDns, |
| 43 | Effect.suspend(() => makeLocalDnsBinding({ makeClient: dnsWriteClient })), |
| 44 | ); |