| 1 | import * as Layer from "effect/Layer"; |
| 2 | import { readWriteClient, ReadWriteTunnel } from "./ReadWriteTunnel.ts"; |
| 3 | import { makeLocalTunnelClient } from "./TunnelLocalBinding.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Local implementation of the {@link ReadWriteTunnel} binding — performs the |
| 7 | * full cfd_tunnel CRUD surface over the HTTP API using the **current |
| 8 | * credentials** instead of a native Worker binding (`ReadWriteTunnelBinding`) |
| 9 | * or a scoped API 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 manage |
| 12 | * tunnels with the same combined read + write client you'd use inside a Worker. |
| 13 | * |
| 14 | * @example Configure a deployed tunnel from an Action |
| 15 | * ```typescript |
| 16 | * const Configure = Alchemy.Action( |
| 17 | * "Configure", |
| 18 | * Effect.gen(function* () { |
| 19 | * const tunnels = yield* Cloudflare.Tunnel.ReadWriteTunnel(); |
| 20 | * const tunnelId = yield* tunnel.tunnelId; |
| 21 | * return Effect.fn(function* () { |
| 22 | * const id = yield* tunnelId; |
| 23 | * yield* tunnels.putConfiguration(id, { |
| 24 | * ingress: [ |
| 25 | * { hostname: "app.example.com", service: "http://localhost:3000" }, |
| 26 | * { service: "http_status:404" }, |
| 27 | * ], |
| 28 | * }); |
| 29 | * const { config } = yield* tunnels.getConfiguration(id); |
| 30 | * return config; |
| 31 | * }); |
| 32 | * }).pipe(Effect.provide(Cloudflare.Tunnel.ReadWriteTunnelLocal)), |
| 33 | * ); |
| 34 | * ``` |
| 35 | */ |
| 36 | export const ReadWriteTunnelLocal = Layer.effect( |
| 37 | ReadWriteTunnel, |
| 38 | makeLocalTunnelClient(readWriteClient), |
| 39 | ); |