The best way to control Claude Code, Codex and more from any computer or phone

main
ts 182 lines 6.15 KB
Raw
1 import type {
2 AddZoneRrsetRecordsError,
3 AddZoneRrsetRecordsRequest,
4 AddZoneRrsetRecordsResponse,
5 ChangeZoneRrsetProtectionError,
6 ChangeZoneRrsetProtectionResponse,
7 ChangeZoneRrsetTtlError,
8 ChangeZoneRrsetTtlResponse,
9 RemoveZoneRrsetRecordsError,
10 RemoveZoneRrsetRecordsRequest,
11 RemoveZoneRrsetRecordsResponse,
12 SetZoneRrsetRecordsError,
13 SetZoneRrsetRecordsRequest,
14 SetZoneRrsetRecordsResponse,
15 UpdateZoneRrsetRecordsError,
16 UpdateZoneRrsetRecordsRequest,
17 UpdateZoneRrsetRecordsResponse,
18 } from "@distilled.cloud/hetzner/zone_rrset_actions";
19 import type {
20 CreateZoneRrsetError,
21 CreateZoneRrsetRequest,
22 CreateZoneRrsetResponse,
23 DeleteZoneRrsetError,
24 DeleteZoneRrsetResponse,
25 UpdateZoneRrsetError,
26 UpdateZoneRrsetRequest,
27 UpdateZoneRrsetResponse,
28 } from "@distilled.cloud/hetzner/zone_rrsets";
29 import * as Binding from "alchemy/Binding";
30 import type { RuntimeContext } from "alchemy/RuntimeContext";
31 import * as Effect from "effect/Effect";
32 import type { Zone } from "./Zone.ts";
33
34 /**
35 * Binding that lets runtime code create, update, and delete Hetzner Cloud
36 * DNS RRSets.
37 *
38 * Authenticates with the ambient `HCLOUD_TOKEN`. A read-only token is
39 * rejected on these methods as `Forbidden`. The zone is fixed by
40 * `WriteDns(zone)` so calls take no zone id. Provide {@link WriteDnsHttp}
41 * on the Action / Function Effect.
42 *
43 * Mutating RRSet endpoints are asynchronous — they return an `action`
44 * that must reach `success` before a subsequent read is guaranteed to
45 * see the change. Poll with {@link waitForZoneAction}.
46 *
47 *
48 * ### Mutating RRSets at runtime
49 * **Example:** Create, replace records, and delete from an Action
50 * Bind the client in the Action's Init phase and provide {@link WriteDnsHttp}.
51 * ```typescript
52 * import * as Alchemy from "alchemy";
53 * import * as Hetzner from "@alchemy.run/hetzner";
54 * import * as Effect from "effect/Effect";
55 *
56 * const Seed = Alchemy.Action(
57 * "Seed",
58 * Effect.gen(function* () {
59 * const dns = yield* Hetzner.WriteDns(zone);
60 * return Effect.fn(function* () {
61 * const created = yield* dns.createRecordSet({
62 * name: "app",
63 * type: "A",
64 * records: [{ value: "192.0.2.1" }],
65 * ttl: 300,
66 * });
67 * yield* Hetzner.waitForZoneAction(created.action);
68 * yield* dns.setRecordSetRecords("app", "A", {
69 * records: [{ value: "192.0.2.2" }],
70 * });
71 * yield* dns.deleteRecordSet("app", "A");
72 * return created.rrset.id;
73 * });
74 * }).pipe(Effect.provide(Hetzner.WriteDnsHttp)),
75 * );
76 * ```
77 *
78 * @binding
79 * @product DNS
80 */
81 export interface WriteDns extends Binding.Service<
82 WriteDns,
83 "Hetzner.DNS.WriteDns",
84 (zone: Zone) => Effect.Effect<WriteDnsClient>
85 > {}
86
87 export const WriteDns = Binding.Service<WriteDns>("Hetzner.DNS.WriteDns");
88
89 /** Create-RRSet request, minus the zone id (bound at `WriteDns(zone)` time). */
90 export type CreateRecordSetRequestInput = Omit<CreateZoneRrsetRequest, "id_or_name">;
91
92 /** Update-RRSet (labels) request, minus the zone id and RRSet identity. */
93 export type UpdateRecordSetRequestInput = Omit<
94 UpdateZoneRrsetRequest,
95 "id_or_name" | "rr_name" | "rr_type"
96 >;
97
98 /** Add-records request, minus the zone id and RRSet identity. */
99 export type AddRecordSetRecordsRequestInput = Omit<
100 AddZoneRrsetRecordsRequest,
101 "id_or_name" | "rr_name" | "rr_type"
102 >;
103
104 /** Remove-records request, minus the zone id and RRSet identity. */
105 export type RemoveRecordSetRecordsRequestInput = Omit<
106 RemoveZoneRrsetRecordsRequest,
107 "id_or_name" | "rr_name" | "rr_type"
108 >;
109
110 /** Set-records request, minus the zone id and RRSet identity. */
111 export type SetRecordSetRecordsRequestInput = Omit<
112 SetZoneRrsetRecordsRequest,
113 "id_or_name" | "rr_name" | "rr_type"
114 >;
115
116 /** Update-record-comments request, minus the zone id and RRSet identity. */
117 export type UpdateRecordSetRecordsRequestInput = Omit<
118 UpdateZoneRrsetRecordsRequest,
119 "id_or_name" | "rr_name" | "rr_type"
120 >;
121
122 /**
123 * Mutating DNS RRSet operations. The zone is fixed when the client is
124 * bound, so no `id_or_name` is passed per call.
125 */
126 export interface WriteDnsClient {
127 /** Create an RRSet. */
128 createRecordSet(
129 request: CreateRecordSetRequestInput,
130 ): Effect.Effect<CreateZoneRrsetResponse, CreateZoneRrsetError, RuntimeContext>;
131 /** Overwrite the RRSet's labels (PUT). */
132 updateRecordSet(
133 name: string,
134 type: string,
135 request?: UpdateRecordSetRequestInput,
136 ): Effect.Effect<UpdateZoneRrsetResponse, UpdateZoneRrsetError, RuntimeContext>;
137 /** Delete an RRSet by name and type. */
138 deleteRecordSet(
139 name: string,
140 type: string,
141 ): Effect.Effect<DeleteZoneRrsetResponse, DeleteZoneRrsetError, RuntimeContext>;
142 /** Append records to an RRSet (creates the RRSet if it is missing). */
143 addRecordSetRecords(
144 name: string,
145 type: string,
146 request: AddRecordSetRecordsRequestInput,
147 ): Effect.Effect<AddZoneRrsetRecordsResponse, AddZoneRrsetRecordsError, RuntimeContext>;
148 /** Remove records from an RRSet (deletes it if it becomes empty). */
149 removeRecordSetRecords(
150 name: string,
151 type: string,
152 request: RemoveRecordSetRecordsRequestInput,
153 ): Effect.Effect<RemoveZoneRrsetRecordsResponse, RemoveZoneRrsetRecordsError, RuntimeContext>;
154 /** Replace every record in an existing RRSet. */
155 setRecordSetRecords(
156 name: string,
157 type: string,
158 request: SetRecordSetRecordsRequestInput,
159 ): Effect.Effect<SetZoneRrsetRecordsResponse, SetZoneRrsetRecordsError, RuntimeContext>;
160 /** Update comments on existing records. */
161 updateRecordSetRecords(
162 name: string,
163 type: string,
164 request: UpdateRecordSetRecordsRequestInput,
165 ): Effect.Effect<UpdateZoneRrsetRecordsResponse, UpdateZoneRrsetRecordsError, RuntimeContext>;
166 /** Change the RRSet TTL. Pass `null` to inherit the zone default. */
167 changeRecordSetTtl(
168 name: string,
169 type: string,
170 ttl: number | null,
171 ): Effect.Effect<ChangeZoneRrsetTtlResponse, ChangeZoneRrsetTtlError, RuntimeContext>;
172 /** Enable or disable change protection on the RRSet. */
173 changeRecordSetProtection(
174 name: string,
175 type: string,
176 change: boolean,
177 ): Effect.Effect<
178 ChangeZoneRrsetProtectionResponse,
179 ChangeZoneRrsetProtectionError,
180 RuntimeContext
181 >;
182 }