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

main
ts 90 lines 3.04 KB
Raw
1 import type {
2 CertificateCheckResponse,
3 CertificateDetail,
4 CheckAppCertificateError,
5 CreateAppAcmeCertificateError,
6 CreateAppCustomCertificateError,
7 DeleteAppCertificateError,
8 DeleteAppCustomCertificateError,
9 GetAppCertificateError,
10 } from "@distilled.cloud/fly-io/machines";
11 import * as Binding from "alchemy/Binding";
12 import type { RuntimeContext } from "alchemy/RuntimeContext";
13 import type * as Effect from "effect/Effect";
14 import type * as Redacted from "effect/Redacted";
15 import type { App } from "./App.ts";
16
17 /**
18 * Manage an App's TLS certificates at runtime — the companion to the
19 * deploy-time {@link Certificate} resource, for services that mint or
20 * rotate certificates on their own (a relay adding a tenant's wildcard,
21 * a renewal loop).
22 *
23 * The App is fixed by `WriteCertificates(app)`; calls take a hostname.
24 *
25 * ### Fly-managed (Let's Encrypt)
26 * **Example:** Request and check
27 * ```typescript
28 * const certs = yield* Fly.WriteCertificates(Site);
29 * const requested = yield* certs.request("www.example.com");
30 * // publish requested.dns_requirements, then:
31 * const status = yield* certs.check("www.example.com");
32 * ```
33 *
34 * ### Bring your own PEM
35 * A certificate issued elsewhere (an `ACME.IssueCertificate` wildcard
36 * from ZeroSSL, say) goes up as a custom certificate.
37 *
38 * **Example:** Upload
39 * ```typescript
40 * yield* certs.upload({
41 * hostname: "*.tenant.example.com",
42 * fullchain: issued.chain,
43 * privateKey: issued.privateKey,
44 * });
45 * ```
46 *
47 * @binding
48 * @product Certificate
49 */
50 export interface WriteCertificates extends Binding.Service<
51 WriteCertificates,
52 "Fly.WriteCertificates",
53 (app: App) => Effect.Effect<WriteCertificatesClient>
54 > {}
55
56 export const WriteCertificates = Binding.Service<WriteCertificates>("Fly.WriteCertificates");
57
58 export interface UploadCertificateRequest {
59 readonly hostname: string;
60 /** PEM chain, leaf first. */
61 readonly fullchain: string;
62 /** PEM private key. */
63 readonly privateKey: Redacted.Redacted<string> | string;
64 }
65
66 /** Certificate operations on one App. */
67 export interface WriteCertificatesClient {
68 /** Request a Fly-managed (Let's Encrypt) certificate. Idempotent. */
69 request(
70 hostname: string,
71 ): Effect.Effect<CertificateDetail | undefined, CreateAppAcmeCertificateError, RuntimeContext>;
72 /** Upload a custom PEM. Replaces an existing custom certificate. */
73 upload(
74 request: UploadCertificateRequest,
75 ): Effect.Effect<
76 CertificateDetail | undefined,
77 CreateAppCustomCertificateError | DeleteAppCustomCertificateError,
78 RuntimeContext
79 >;
80 /** Re-run Fly's validation checks for the hostname. */
81 check(
82 hostname: string,
83 ): Effect.Effect<CertificateCheckResponse, CheckAppCertificateError, RuntimeContext>;
84 /** The certificate for a hostname, or `undefined`. */
85 get(
86 hostname: string,
87 ): Effect.Effect<CertificateDetail | undefined, GetAppCertificateError, RuntimeContext>;
88 /** Remove the hostname's certificate. Missing counts as removed. */
89 remove(hostname: string): Effect.Effect<void, DeleteAppCertificateError, RuntimeContext>;
90 }