1import * as Layer from "effect/Layer";
2import { makeLocalTunnelClient } from "./TunnelLocalBinding.ts";
3import { WriteTunnel, writeClient } from "./WriteTunnel.ts";
4
5/**
6 * Local implementation of the {@link WriteTunnel} binding — creates, updates,
7 * and deletes Cloudflare Tunnels over the cfd_tunnel HTTP API using the
8 * **current credentials** instead of a native Worker binding
9 * (`WriteTunnelBinding`) or a scoped API token. No `host.bind`, no minted
10 * token, no Worker host.
11 *
12 * Provide it on an {@link Action} (or any deploy-time Effect) so you can mutate
13 * tunnels with the same `create`/`update`/`delete`/`putConfiguration` client
14 * you'd use inside a Worker.
15 *
16 * @example Provision a tunnel from an Action
17 * ```typescript
18 * const Provision = Alchemy.Action(
19 * "Provision",
20 * Effect.gen(function* () {
21 * const tunnels = yield* Cloudflare.Tunnel.WriteTunnel();
22 * return Effect.fn(function* () {
23 * const tunnel = yield* tunnels.create({ name: "on-demand-tunnel" });
24 * return tunnel.result?.id;
25 * });
26 * }).pipe(Effect.provide(Cloudflare.Tunnel.WriteTunnelLocal)),
27 * );
28 * ```
29 */
30export const WriteTunnelLocal = Layer.effect(
31 WriteTunnel,
32 makeLocalTunnelClient(writeClient),
33);