1import * as Layer from "effect/Layer";
2import { readClient, ReadTunnel } from "./ReadTunnel.ts";
3import { makeLocalTunnelClient } from "./TunnelLocalBinding.ts";
4
5/**
6 * Local implementation of the {@link ReadTunnel} binding — reads Cloudflare
7 * Tunnels over the cfd_tunnel HTTP API using the **current credentials**
8 * instead of a native Worker binding (`ReadTunnelBinding`) or a scoped API
9 * token. No `host.bind`, no minted token, no Worker host.
10 *
11 * Provide it on an {@link Action} (or any deploy-time Effect) so you can read
12 * tunnels with the same `get`/`list`/`getToken`/`getConfiguration` client you'd
13 * use inside a Worker.
14 *
15 * @example Read a tunnel's connector token from an Action
16 * ```typescript
17 * const Inspect = Alchemy.Action(
18 * "Inspect",
19 * Effect.gen(function* () {
20 * const tunnels = yield* Cloudflare.Tunnel.ReadTunnel();
21 * const tunnelId = yield* tunnel.tunnelId;
22 * return Effect.fn(function* () {
23 * const t = yield* tunnels.get(yield* tunnelId);
24 * return t.result?.name;
25 * });
26 * }).pipe(Effect.provide(Cloudflare.Tunnel.ReadTunnelLocal)),
27 * );
28 * ```
29 */
30export const ReadTunnelLocal = Layer.effect(
31 ReadTunnel,
32 makeLocalTunnelClient(readClient),
33);