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

main
ts 41 lines 1.51 KB
Raw
1 import { Credentials } from "@distilled.cloud/hetzner";
2 import type { RuntimeContext } from "alchemy/RuntimeContext";
3 import * as Effect from "effect/Effect";
4 import type * as HttpClient from "effect/http/HttpClient";
5 import type { Zone } from "./Zone.ts";
6
7 /**
8 * Shared scaffolding for the HTTP-backed Hetzner DNS bindings.
9 *
10 * Hetzner Cloud tokens are project-scoped (`HCLOUD_TOKEN`) and issued
11 * read-write or read-only — there is no per-permission token API. This
12 * layer captures the ambient credentials available during stack-eval and
13 * builds a {@link DnsAuth} that provides them to distilled RRSet ops. The
14 * zone is fixed at `bind(zone)` time so callers never pass `id_or_name`.
15 *
16 * NOT exported from `index.ts`.
17 */
18 export const makeHttpDnsBinding = <Client>(options: {
19 makeClient: (auth: DnsAuth, zoneId: Effect.Effect<number>) => Client;
20 }) =>
21 Effect.gen(function* () {
22 const context = yield* Effect.context<Credentials | HttpClient.HttpClient>();
23
24 return Effect.fn(function* (zone: Zone) {
25 const zoneId = yield* zone.zoneId;
26 const auth: DnsAuth = {
27 authorize: (eff) => eff.pipe(Effect.provideContext(context)),
28 };
29 return options.makeClient(auth, zoneId);
30 });
31 });
32
33 /**
34 * Injectable auth for the DNS HTTP client builders. Supplies an `authorize`
35 * that provides `Credentials` + `HttpClient` to a raw SDK op.
36 */
37 export interface DnsAuth {
38 authorize: <A, E>(
39 eff: Effect.Effect<A, E, Credentials | HttpClient.HttpClient>,
40 ) => Effect.Effect<A, E, RuntimeContext>;
41 }