import type { Context } from "../context"; import { type CloudflareApi, type CloudflareApiOptions } from "./api.ts"; import type { Tunnel } from "./tunnel.ts"; /** * Properties for creating or updating a VPC service. */ export interface VpcServiceProps extends CloudflareApiOptions { /** * The name of the VPC service to create. * * @default ${app}-${stage}-${id} */ name?: string; /** * The type of the VPC service. Currently only "http" is supported, but tcp will be supported in the future. * * @default "http" */ serviceType?: "http"; /** * The TCP port for the VPC service. */ tcpPort?: number; /** * The application protocol for the VPC service. */ appProtocol?: string; /** * The HTTP port for the VPC service. * * @default 80 */ httpPort?: number; /** * The HTTPS port for the VPC service. * * @default 443 */ httpsPort?: number; /** * The host for the VPC service. */ host: VpcService.IPv4Host | VpcService.IPv6Host | VpcService.DualStackHost | VpcService.HostnameHost; /** * Whether to adopt the VPC service if it already exists. * * @default false */ adopt?: boolean; } export declare namespace VpcService { /** Host definition: hostname (with resolver network) or IPv4/IPv6/dual-stack with network. */ type Host = IPv4Host | IPv6Host | DualStackHost | HostnameHost; /** * Represents a VPC service that is accessible via an IPv4 address. */ interface IPv4Host { ipv4: string; network: Network; } /** * Represents a VPC service that is accessible via an IPv6 address. */ interface IPv6Host { ipv6: string; network: Network; } /** * Represents a VPC service that is accessible via both IPv4 and IPv6 addresses. */ interface DualStackHost { ipv4: string; ipv6: string; network: Network; } /** * Network the VPC service is reached through. Use a `Tunnel` resource or an existing `tunnelId`. */ type Network = { tunnelId: string; } | { tunnel: Tunnel; }; /** * Hostname-based host. DNS is resolved over the resolver network (tunnel). * Optionally specify `resolverIps` for explicit DNS resolver IPs. */ interface HostnameHost { hostname: string; resolverNetwork: Network & { resolverIps?: string[]; }; } } /** * A VPC service instance. Bind to a Worker to allow the Worker to fetch from * the private host (hostname or IP) over the configured tunnel. */ export type VpcService = Omit & { /** Display name of the service. */ name: string; /** Cloudflare-assigned service ID. */ serviceId: string; /** Creation time (Unix ms). */ createdAt: number; /** Last update time (Unix ms). */ updatedAt: number; /** Resource kind for bindings. */ type: "vpc_service"; }; /** * Create or update a VPC service that routes Worker traffic to a private host * (hostname or IP) through a Cloudflare Tunnel. * * [VPC Services](https://developers.cloudflare.com/workers-vpc/configuration/vpc-services/) * enable Workers to securely access private network resources through Cloudflare Tunnel. * Configure a host (hostname or IP) and optional ports, then bind the service to a Worker * to reach private backends. * * @example * // Minimal: hostname through a tunnel * ```ts * const tunnel = await Tunnel("my-tunnel", { * ingress: [{ service: "http://localhost:3000" }], * }); * const vpcService = await VpcService("my-service", { * host: { * hostname: "localhost", * resolverNetwork: { tunnel, resolverIps: ["127.0.0.1"] }, * }, * }); * ``` * * @example * // IPv4 address * ```ts * const vpcService = await VpcService("internal-api", { * host: { * ipv4: "192.168.1.100", * network: { tunnel }, * }, * }); * ``` * * @example * // IPv6 address * ```ts * const vpcService = await VpcService("ipv6-service", { * host: { ipv6: "::1", network: { tunnel } }, * }); * ``` * * @example * // Dual stack (IPv4 + IPv6) * ```ts * const vpcService = await VpcService("dual-stack-service", { * host: { * ipv4: "192.168.1.100", * ipv6: "::1", * network: { tunnel }, * }, * }); * ``` * * @example * // Custom HTTP/HTTPS ports * ```ts * const vpcService = await VpcService("dev-server", { * httpPort: 5173, * httpsPort: 5174, * host: { * hostname: "localhost", * resolverNetwork: { tunnel, resolverIps: ["127.0.0.1"] }, * }, * }); * ``` * * @example * // Bind to a Worker * ```ts * const vpcService = await VpcService("private-api", { * httpPort: 8080, * host: { * hostname: "internal-api", * resolverNetwork: { tunnel, resolverIps: ["10.0.0.1"] }, * }, * }); * const worker = await Worker("api-gateway", { * entrypoint: "./src/worker.ts", * bindings: { PRIVATE_API: vpcService }, * }); * ``` * * @example * // Existing tunnel by ID * ```ts * const vpcService = await VpcService("existing-tunnel-service", { * host: { * hostname: "internal.example.com", * resolverNetwork: { * tunnelId: "e6a0817c-79c5-40ca-9776-a1c019defe70", * resolverIps: ["10.0.0.53"], * }, * }, * }); * ``` * * @example * // Adopt an existing VPC service * ```ts * const vpcService = await VpcService("adopted-service", { * name: "existing-service-name", * adopt: true, * host: { * hostname: "localhost", * resolverNetwork: { tunnel }, * }, * }); * ``` */ export declare const VpcService: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context, id: string, props: VpcServiceProps) => Promise); /** * Create a connectivity (VPC) service via the Cloudflare API. * @internal */ export declare function createService(api: CloudflareApi, body: ConnectivityService.Input): Promise; /** * Delete a connectivity (VPC) service. No-op if the service is already gone (404). * @internal */ export declare function deleteService(api: CloudflareApi, serviceId: string): Promise; /** * Fetch a single connectivity (VPC) service by ID. * @internal */ export declare function getService(api: CloudflareApi, serviceId: string): Promise; /** * List connectivity (VPC) services for the account. * @internal */ export declare function findVpcServiceByName(api: CloudflareApi, name: string): Promise; /** * Update an existing connectivity (VPC) service. * @internal */ export declare function updateService(api: CloudflareApi, serviceId: string, body: ConnectivityService.Input): Promise; interface ConnectivityService extends ConnectivityService.Input { service_id: string; created_at: string; updated_at: string; } declare namespace ConnectivityService { interface Input { name: string; type: "http"; tcp_port?: number; app_protocol?: string; http_port?: number; https_port?: number; host: Host; } type Host = IPv4Host | IPv6Host | DualStackHost | HostnameHost; interface IPv4Host { ipv4: string; network: Network; } interface IPv6Host { ipv6: string; network: Network; } interface DualStackHost { ipv4: string; ipv6: string; network: Network; } interface Network { tunnel_id: string; } interface HostnameHost { hostname: string; resolver_network: ResolverNetwork; } interface ResolverNetwork extends Network { resolver_ips?: string[]; } } export {}; //# sourceMappingURL=vpc-service.d.ts.map