1import * as dns from "@distilled.cloud/cloudflare/dns";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import { type DnsAuth, makeHttpDnsBinding } from "./DnsHttp.ts";
5import { ReadDns, type ReadDnsClient } from "./ReadDns.ts";
6
7/** Runtime layer for {@link ReadDns}. */
8export const ReadDnsHttp = Layer.effect(
9 ReadDns,
10 Effect.suspend(() =>
11 makeHttpDnsBinding({
12 permissionGroups: ["DNS Read"],
13 makeClient: dnsReadClient,
14 }),
15 ),
16);
17
18/** Build the read-only client over an injectable auth and zone id. */
19export const dnsReadClient = (
20 auth: DnsAuth,
21 zoneId: Effect.Effect<string>,
22): ReadDnsClient => {
23 const authorize = auth.authorize;
24 return {
25 getDnsRecord: Effect.fn("Cloudflare.DNS.getDnsRecord")(
26 function* (dnsRecordId) {
27 return yield* authorize(
28 dns.getRecord({ zoneId: yield* zoneId, dnsRecordId }),
29 );
30 },
31 ),
32 listDnsRecords: Effect.fn("Cloudflare.DNS.listDnsRecords")(
33 function* (request) {
34 return yield* authorize(
35 dns.listRecords({ zoneId: yield* zoneId, ...request }),
36 );
37 },
38 ),
39 };
40};