The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import * as DNS from "alchemy/DNS/Adapter"; |
| 2 | import type { Input } from "alchemy/Input"; |
| 3 | import * as Output from "alchemy/Output"; |
| 4 | /** |
| 5 | * Custom-domain plumbing shared by AWS composites (the `AWS.Website.*` |
| 6 | * sites and Router, `AWS.ECS.Service`, `AWS.Lambda.Function`): the ACM |
| 7 | * certificate and the records pointing hostnames at the AWS target, through |
| 8 | * whichever DNS host `domain.dns` names. |
| 9 | * |
| 10 | * Route 53 — the default — keeps the exact resources AWS composites |
| 11 | * declared before DNS adapters existed (an inline-validated |
| 12 | * `AWS.ACM.Certificate` plus `AWS.Route53.Record`s), so existing stacks plan |
| 13 | * no changes. Any other DNS host validates the certificate externally: |
| 14 | * `Certificate` (`dnsValidation: "external"`) → the adapter's validation |
| 15 | * records → `AWS.ACM.CertificateValidation`. |
| 16 | * |
| 17 | * Not exported from the AWS barrel. |
| 18 | */ |
| 19 | import * as Effect from "effect/Effect"; |
| 20 | import { Certificate, validationRecordsOf, type CertificateProps } from "./ACM/Certificate.ts"; |
| 21 | import { CertificateValidation } from "./ACM/CertificateValidation.ts"; |
| 22 | import type { Providers } from "./Providers.ts"; |
| 23 | import { adapter as route53Adapter, ROUTE53_DNS } from "./Route53/Adapter.ts"; |
| 24 | |
| 25 | /** Whether `dns` is Route 53 (explicit, or the default when omitted). */ |
| 26 | export const isRoute53Dns = (dns: DNS.DnsConfig | undefined) => |
| 27 | dns === undefined || dns.type === ROUTE53_DNS; |
| 28 | |
| 29 | /** |
| 30 | * The DNS adapter of an AWS custom domain: the explicit `dns` adapter, or |
| 31 | * Route 53 (pinned to `hostedZoneId` when given) when omitted. Route 53 is |
| 32 | * built directly — AWS composites need no registry lookup for their own |
| 33 | * DNS host. |
| 34 | */ |
| 35 | export const resolveDomainDns = ( |
| 36 | dns: DNS.DnsConfig | undefined, |
| 37 | hostedZoneId?: Input<string>, |
| 38 | ): Effect.Effect<DNS.DnsAdapter<Providers>> => |
| 39 | isRoute53Dns(dns) |
| 40 | ? Effect.succeed( |
| 41 | DNS.bind( |
| 42 | route53Adapter, |
| 43 | dns ?? { |
| 44 | type: ROUTE53_DNS, |
| 45 | ...(hostedZoneId === undefined ? {} : { zone: hostedZoneId }), |
| 46 | }, |
| 47 | ), |
| 48 | ) |
| 49 | : DNS.resolve(dns!); |
| 50 | |
| 51 | /** |
| 52 | * An ACM certificate for a custom domain, validated through `dns`. |
| 53 | * |
| 54 | * - Route 53 (omitted, explicit, or `false` — "no alias records" still |
| 55 | * validates in Route 53): `Certificate(id, props)` exactly as given; the |
| 56 | * provider publishes the validation records inline and waits. |
| 57 | * - Any other host: `Certificate(id, { ...props, dnsValidation: |
| 58 | * "external" })`, the adapter's `{id}Validation` records (retained on |
| 59 | * destroy — ACM reuses one CNAME per name across certificates), and |
| 60 | * `{id}Issued` (`AWS.ACM.CertificateValidation`). |
| 61 | * |
| 62 | * `certificateArn` resolves only once the certificate is issued, so a |
| 63 | * distribution, listener, or API Gateway domain that takes it deploys after |
| 64 | * issuance. |
| 65 | */ |
| 66 | export const domainCertificate = Effect.fn("AWS.domainCertificate")(function* ( |
| 67 | id: string, |
| 68 | props: CertificateProps, |
| 69 | dns: DNS.DnsConfig | false | undefined, |
| 70 | ) { |
| 71 | if (dns === false || isRoute53Dns(dns)) { |
| 72 | const certificate = yield* Certificate(id, props); |
| 73 | return { certificate, certificateArn: certificate.certificateArn }; |
| 74 | } |
| 75 | const adapter = yield* DNS.resolve(dns!); |
| 76 | const { hostedZoneId: _ignored, ...rest } = props; |
| 77 | const certificate = yield* Certificate(id, { |
| 78 | ...rest, |
| 79 | dnsValidation: "external", |
| 80 | }); |
| 81 | yield* adapter.records(`${id}Validation`, { |
| 82 | records: Output.map( |
| 83 | certificate.domainValidationOptions, |
| 84 | validationRecordsOf, |
| 85 | ) as unknown as Input<DNS.DnsRecord[]>, |
| 86 | retain: true, |
| 87 | }); |
| 88 | const issued = yield* CertificateValidation(`${id}Issued`, { |
| 89 | certificateArn: certificate.certificateArn, |
| 90 | }); |
| 91 | return { certificate, certificateArn: issued.certificateArn }; |
| 92 | }); |