@geekmidas/edge 10.0.0-alpha.188 → 10.0.0-alpha.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/dns/cloudflare/index.cjs +431 -0
  2. package/dist/dns/cloudflare/index.cjs.map +1 -0
  3. package/dist/dns/cloudflare/index.d.cts +182 -0
  4. package/dist/dns/cloudflare/index.d.cts.map +1 -0
  5. package/dist/dns/cloudflare/index.d.mts +182 -0
  6. package/dist/dns/cloudflare/index.d.mts.map +1 -0
  7. package/dist/dns/cloudflare/index.mjs +419 -0
  8. package/dist/dns/cloudflare/index.mjs.map +1 -0
  9. package/dist/dns/index.cjs +2 -1
  10. package/dist/dns/index.cjs.map +1 -1
  11. package/dist/dns/index.d.cts +12 -0
  12. package/dist/dns/index.d.cts.map +1 -1
  13. package/dist/dns/index.d.mts +12 -0
  14. package/dist/dns/index.d.mts.map +1 -1
  15. package/dist/dns/index.mjs +2 -1
  16. package/dist/dns/index.mjs.map +1 -1
  17. package/dist/{index-BVE0VFku.d.cts → index-BhrEC4ux.d.cts} +37 -3
  18. package/dist/index-BhrEC4ux.d.cts.map +1 -0
  19. package/dist/{index-BVE0VFku.d.mts → index-BhrEC4ux.d.mts} +37 -3
  20. package/dist/index-BhrEC4ux.d.mts.map +1 -0
  21. package/dist/proxy/caddy.cjs +8 -0
  22. package/dist/proxy/caddy.cjs.map +1 -1
  23. package/dist/proxy/caddy.d.cts +6 -1
  24. package/dist/proxy/caddy.d.cts.map +1 -1
  25. package/dist/proxy/caddy.d.mts +6 -1
  26. package/dist/proxy/caddy.d.mts.map +1 -1
  27. package/dist/proxy/caddy.mjs +8 -1
  28. package/dist/proxy/caddy.mjs.map +1 -1
  29. package/dist/proxy/traefik.cjs +24 -6
  30. package/dist/proxy/traefik.cjs.map +1 -1
  31. package/dist/proxy/traefik.d.cts +2 -2
  32. package/dist/proxy/traefik.d.mts +2 -2
  33. package/dist/proxy/traefik.mjs +24 -7
  34. package/dist/proxy/traefik.mjs.map +1 -1
  35. package/dist/routes/index.cjs.map +1 -1
  36. package/dist/routes/index.d.cts +2 -2
  37. package/dist/routes/index.d.mts +2 -2
  38. package/dist/routes/index.mjs.map +1 -1
  39. package/package.json +12 -2
  40. package/dist/index-BVE0VFku.d.cts.map +0 -1
  41. package/dist/index-BVE0VFku.d.mts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/dns/cloudflare/api.ts","../../../src/dns/cloudflare/index.ts"],"sourcesContent":["/**\n * Cloudflare's v4 DNS API, as gkm uses it: the records of one name and type\n * at a time, inside a zone found by its name.\n *\n * - zone: `GET /zones?name={domain}` — the one call that is not a record's\n * - read: `GET /zones/{zone}/dns_records?type={type}&name.exact={fqdn}`\n * - create: `POST /zones/{zone}/dns_records`\n * - update: `PATCH /zones/{zone}/dns_records/{id}`\n * - delete: `DELETE /zones/{zone}/dns_records/{id}`\n *\n * Never the zone itself, its settings or the account. An API token with\n * `Zone:Read` and `DNS:Edit` on the zone is all it needs, sent as\n * `Authorization: Bearer <token>`.\n *\n * Every answer is the v4 envelope — `{ success, errors, result }` — and a\n * failure is read from its `errors`, not from the status alone. A 429 is\n * waited out a few times (its `Retry-After`, else a second) before the run\n * gives up with {@link CloudflareRateLimited}.\n */\n\nimport { EdgeError } from '../../errors';\n\n/** A Cloudflare API token, sent as `Authorization: Bearer <token>`. */\nexport interface CloudflareCredential {\n\ttoken: string;\n}\n\nexport const CLOUDFLARE_API_BASE = 'https://api.cloudflare.com/client/v4';\n\n/**\n * Cloudflare's \"automatic\" TTL — 300 seconds, and the only TTL a proxied\n * record takes.\n */\nexport const CLOUDFLARE_AUTO_TTL = 1;\n\n/** The record types gkm writes. Never TXT, NS, SOA, SRV or CAA. */\nexport const CLOUDFLARE_MANAGED_TYPES = ['A', 'AAAA', 'CNAME', 'MX'] as const;\n\nexport type CloudflareRecordType = (typeof CLOUDFLARE_MANAGED_TYPES)[number];\n\n/** One record as Cloudflare returns it. */\nexport interface CloudflareRecord {\n\tid: string;\n\ttype: string;\n\t/** The full name: `api.example.com`. */\n\tname: string;\n\tcontent: string;\n\tttl: number;\n\t/** Whether Cloudflare's proxy answers for it — its CDN, the orange cloud. */\n\tproxied?: boolean;\n\t/** An MX record's: Cloudflare keeps it apart from `content`. */\n\tpriority?: number;\n}\n\n/** What a write sends. */\nexport interface CloudflareRecordInput {\n\ttype: CloudflareRecordType;\n\t/** The full name: `api.example.com`. */\n\tname: string;\n\tcontent: string;\n\tttl: number;\n\tproxied?: boolean;\n\tpriority?: number;\n}\n\n/** An origin certificate as the Origin CA returns it. */\nexport interface CloudflareOriginCertificate {\n\t/** Its serial number. */\n\tid: string;\n\t/** PEM. */\n\tcertificate: string;\n\thostnames: string[];\n\t/** `2041-11-22 10:00:00 +0000 UTC` */\n\texpires_on: string;\n}\n\n/** The v4 envelope. */\ninterface Envelope<T> {\n\tsuccess: boolean;\n\terrors?: { code: number; message: string }[];\n\tresult: T;\n\tresult_info?: { page: number; total_pages: number };\n}\n\n/** The token is missing, malformed, expired or revoked. */\nexport class CloudflareCredentialsInvalid extends EdgeError {\n\tconstructor(readonly detail?: string) {\n\t\tsuper(\n\t\t\t`Cloudflare refused the API token${detail ? ` (${detail})` : ''}. ` +\n\t\t\t\t'Create one at dash.cloudflare.com/profile/api-tokens with Zone:Read ' +\n\t\t\t\t'and DNS:Edit on the zone, then set CLOUDFLARE_API_TOKEN or run ' +\n\t\t\t\t'`gkm login --provider cloudflare`.',\n\t\t);\n\t\tthis.name = 'CloudflareCredentialsInvalid';\n\t}\n}\n\n/** The token is good, and may not do this to this zone. */\nexport class CloudflarePermissionMissing extends EdgeError {\n\tconstructor(\n\t\treadonly domain: string,\n\t\treadonly detail?: string,\n\t\t/** What the token needs for it: `Zone:Read and DNS:Edit`. */\n\t\treadonly permission: string = DNS_PERMISSIONS,\n\t) {\n\t\tsuper(\n\t\t\t`The Cloudflare token was refused on ${domain}` +\n\t\t\t\t`${detail ? ` (${detail})` : ''}. Give it ${permission} on ` +\n\t\t\t\t`${domain} (dash.cloudflare.com/profile/api-tokens → the token → Edit).`,\n\t\t);\n\t\tthis.name = 'CloudflarePermissionMissing';\n\t}\n}\n\n/** No zone of that name is in the token's reach. */\nexport class CloudflareZoneNotFound extends EdgeError {\n\tconstructor(readonly domain: string) {\n\t\tsuper(\n\t\t\t`Cloudflare has no zone ${domain} the token can read. Add ${domain} to ` +\n\t\t\t\t'the Cloudflare account and point its nameservers at Cloudflare, and ' +\n\t\t\t\t\"make sure the token's zone resources include it.\",\n\t\t);\n\t\tthis.name = 'CloudflareZoneNotFound';\n\t}\n}\n\n/** Still rate limited after waiting it out. */\nexport class CloudflareRateLimited extends EdgeError {\n\tconstructor(readonly attempts: number) {\n\t\tsuper(\n\t\t\t`Cloudflare kept answering 429 Too Many Requests after ${attempts} ` +\n\t\t\t\t'attempts. Wait a few minutes and deploy again: every record written ' +\n\t\t\t\t'so far is kept.',\n\t\t);\n\t\tthis.name = 'CloudflareRateLimited';\n\t}\n}\n\n/** Any other answer that is not a success. */\nexport class CloudflareRequestFailed extends EdgeError {\n\tconstructor(\n\t\treadonly method: string,\n\t\treadonly path: string,\n\t\treadonly status: number,\n\t\t/** Cloudflare's `errors`, as it answered them. */\n\t\treadonly failures: readonly { code: number; message: string }[],\n\t) {\n\t\tconst detail =\n\t\t\tfailures.length > 0\n\t\t\t\t? failures.map((e) => `${e.code}: ${e.message}`).join('; ')\n\t\t\t\t: `HTTP ${status}`;\n\t\tsuper(`Cloudflare refused ${method} ${path}: ${detail}.`);\n\t\tthis.name = 'CloudflareRequestFailed';\n\t}\n}\n\n/** A record type gkm does not write. */\nexport class CloudflareRecordNotAllowed extends EdgeError {\n\tconstructor(\n\t\treadonly domain: string,\n\t\treadonly type: string,\n\t\t/** The record's name, as it was asked for: `api`, `@`. */\n\t\treadonly record: string,\n\t) {\n\t\tsuper(\n\t\t\t`gkm does not manage ${type} records, so it will not touch '${record}' ` +\n\t\t\t\t`${type} in ${domain}: only ${CLOUDFLARE_MANAGED_TYPES.join(', ')}.`,\n\t\t);\n\t\tthis.name = 'CloudflareRecordNotAllowed';\n\t}\n}\n\n/** What reading and writing a zone's records needs. */\nconst DNS_PERMISSIONS = 'Zone:Read and DNS:Edit';\n\n/** What an origin certificate needs, beside finding the zone. */\nconst ORIGIN_CA_PERMISSIONS = 'Zone:Read and SSL and Certificates:Edit';\n\n/** Cloudflare's authentication error codes: a bad or unusable token. */\nconst AUTH_CODES = new Set([6003, 6111, 9106, 9109, 10000]);\n\nexport interface CloudflareApiOptions {\n\tcredential: CloudflareCredential;\n\t/** The API's base URL, for tests. */\n\tbaseUrl?: string;\n\t/** How a 429 is waited out, for tests. */\n\tsleep?: (ms: number) => Promise<void>;\n\tmaxAttempts?: number;\n}\n\nexport class CloudflareApi {\n\tprivate readonly baseUrl: string;\n\tprivate readonly sleep: (ms: number) => Promise<void>;\n\tprivate readonly maxAttempts: number;\n\tprivate readonly zones = new Map<string, string>();\n\n\tconstructor(private readonly options: CloudflareApiOptions) {\n\t\tthis.baseUrl = (options.baseUrl ?? CLOUDFLARE_API_BASE).replace(/\\/$/, '');\n\t\tthis.sleep =\n\t\t\toptions.sleep ??\n\t\t\t((ms) => new Promise((resolve) => setTimeout(resolve, ms)));\n\t\tthis.maxAttempts = options.maxAttempts ?? 4;\n\t}\n\n\tprivate async request<T>(\n\t\tdomain: string,\n\t\tmethod: 'GET' | 'POST' | 'PATCH' | 'DELETE',\n\t\tpath: string,\n\t\tbody?: unknown,\n\t\tpermission: string = DNS_PERMISSIONS,\n\t): Promise<Envelope<T>> {\n\t\tfor (let attempt = 1; ; attempt++) {\n\t\t\tconst response = await fetch(`${this.baseUrl}${path}`, {\n\t\t\t\tmethod,\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${this.options.credential.token}`,\n\t\t\t\t\t...(body ? { 'Content-Type': 'application/json' } : {}),\n\t\t\t\t},\n\t\t\t\t...(body ? { body: JSON.stringify(body) } : {}),\n\t\t\t});\n\t\t\tif (response.status === 429) {\n\t\t\t\tif (attempt >= this.maxAttempts) {\n\t\t\t\t\tthrow new CloudflareRateLimited(attempt);\n\t\t\t\t}\n\t\t\t\tconst after = Number(response.headers.get('retry-after'));\n\t\t\t\tawait this.sleep(\n\t\t\t\t\tNumber.isFinite(after) && after > 0 ? after * 1000 : 1000,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet envelope: Envelope<T> | undefined;\n\t\t\ttry {\n\t\t\t\tenvelope = (await response.json()) as Envelope<T>;\n\t\t\t} catch {\n\t\t\t\tenvelope = undefined;\n\t\t\t}\n\t\t\tif (response.ok && envelope?.success) return envelope;\n\t\t\tconst errors = envelope?.errors ?? [];\n\t\t\tconst detail = errors.map((e) => e.message).join('; ') || undefined;\n\t\t\tif (\n\t\t\t\tresponse.status === 401 ||\n\t\t\t\terrors.some((e) => AUTH_CODES.has(e.code))\n\t\t\t) {\n\t\t\t\tthrow new CloudflareCredentialsInvalid(detail);\n\t\t\t}\n\t\t\tif (response.status === 403) {\n\t\t\t\tthrow new CloudflarePermissionMissing(domain, detail, permission);\n\t\t\t}\n\t\t\tthrow new CloudflareRequestFailed(method, path, response.status, errors);\n\t\t}\n\t}\n\n\t/** The zone's id, found once by its name. */\n\tasync zoneId(domain: string): Promise<string> {\n\t\tconst key = domain.toLowerCase();\n\t\tconst known = this.zones.get(key);\n\t\tif (known) return known;\n\t\tconst { result } = await this.request<{ id: string; name: string }[]>(\n\t\t\tkey,\n\t\t\t'GET',\n\t\t\t`/zones?name=${encodeURIComponent(key)}`,\n\t\t);\n\t\tconst zone = result.find((z) => z.name.toLowerCase() === key);\n\t\tif (!zone) throw new CloudflareZoneNotFound(key);\n\t\tthis.zones.set(key, zone.id);\n\t\treturn zone.id;\n\t}\n\n\t/** Every record of exactly this name and type — of the type, without a name. */\n\tasync getRecords(\n\t\tdomain: string,\n\t\ttype: CloudflareRecordType,\n\t\tfqdn?: string,\n\t): Promise<CloudflareRecord[]> {\n\t\tconst zone = await this.zoneId(domain);\n\t\tconst found: CloudflareRecord[] = [];\n\t\tfor (let page = 1; ; page++) {\n\t\t\tconst query = new URLSearchParams({\n\t\t\t\ttype,\n\t\t\t\t...(fqdn ? { 'name.exact': fqdn } : {}),\n\t\t\t\tper_page: '100',\n\t\t\t\tpage: String(page),\n\t\t\t});\n\t\t\tconst envelope = await this.request<CloudflareRecord[]>(\n\t\t\t\tdomain,\n\t\t\t\t'GET',\n\t\t\t\t`/zones/${zone}/dns_records?${query}`,\n\t\t\t);\n\t\t\tfound.push(...envelope.result);\n\t\t\tconst info = envelope.result_info;\n\t\t\tif (!info || info.page >= info.total_pages) return found;\n\t\t}\n\t}\n\n\tasync createRecord(\n\t\tdomain: string,\n\t\trecord: CloudflareRecordInput,\n\t): Promise<CloudflareRecord> {\n\t\tconst zone = await this.zoneId(domain);\n\t\tconst { result } = await this.request<CloudflareRecord>(\n\t\t\tdomain,\n\t\t\t'POST',\n\t\t\t`/zones/${zone}/dns_records`,\n\t\t\trecord,\n\t\t);\n\t\treturn result;\n\t}\n\n\tasync updateRecord(\n\t\tdomain: string,\n\t\tid: string,\n\t\trecord: CloudflareRecordInput,\n\t): Promise<CloudflareRecord> {\n\t\tconst zone = await this.zoneId(domain);\n\t\tconst { result } = await this.request<CloudflareRecord>(\n\t\t\tdomain,\n\t\t\t'PATCH',\n\t\t\t`/zones/${zone}/dns_records/${id}`,\n\t\t\trecord,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * An origin certificate from Cloudflare's Origin CA, for a CSR made where\n\t * the key is: trusted by Cloudflare's proxy alone, for `hostnames`, valid\n\t * `days` (one of 7, 30, 90, 365, 730, 1095, 5475). The token needs\n\t * `Zone → SSL and Certificates → Edit` on the zone.\n\t *\n\t * @param domain - the zone, for what an error says\n\t */\n\tasync createOriginCertificate(\n\t\tdomain: string,\n\t\trequest: {\n\t\t\tcsr: string;\n\t\t\thostnames: readonly string[];\n\t\t\tdays: number;\n\t\t\ttype: 'origin-rsa' | 'origin-ecc';\n\t\t},\n\t): Promise<CloudflareOriginCertificate> {\n\t\tconst { result } = await this.request<CloudflareOriginCertificate>(\n\t\t\tdomain,\n\t\t\t'POST',\n\t\t\t'/certificates',\n\t\t\t{\n\t\t\t\tcsr: request.csr,\n\t\t\t\thostnames: [...request.hostnames],\n\t\t\t\trequested_validity: request.days,\n\t\t\t\trequest_type: request.type,\n\t\t\t},\n\t\t\tORIGIN_CA_PERMISSIONS,\n\t\t);\n\t\treturn result;\n\t}\n\n\tasync deleteRecord(domain: string, id: string): Promise<void> {\n\t\tconst zone = await this.zoneId(domain);\n\t\tawait this.request<unknown>(\n\t\t\tdomain,\n\t\t\t'DELETE',\n\t\t\t`/zones/${zone}/dns_records/${id}`,\n\t\t);\n\t}\n}\n","/**\n * Cloudflare DNS Provider\n *\n * Implements DnsProvider against Cloudflare's v4 API, one name and type at a\n * time: it reads and writes only the A, AAAA, CNAME and MX records of the\n * names it is handed, inside the zone found by the domain's name, and never\n * the zone's settings or the account. An API token with `Zone:Read` and\n * `DNS:Edit` on the zone is all it needs.\n *\n * Cloudflare is also a CDN: a record it proxies (`proxied: true`, the orange\n * cloud) is answered by Cloudflare's edge, which forwards to the record's\n * value. A write that says `proxied` sets it; one that does not leaves an\n * existing record's as it was and creates a new one unproxied — so a\n * certificate's validation CNAME, which Cloudflare must not answer, is\n * never proxied by accident. A proxied record's TTL is always Cloudflare's\n * automatic one.\n *\n * Cloudflare can hold several records of one name and type; an upsert leaves\n * exactly one, with its value. An MX value is `<priority> <host>` on the\n * DnsProvider side, as everywhere in gkm; Cloudflare keeps the priority\n * apart, so it is split on a write and joined on a read.\n *\n * Credentials: `CLOUDFLARE_API_TOKEN`, else what `gkm login --provider\n * cloudflare` stored. Never logged.\n */\n\nimport {\n\ttype DeleteDnsRecord,\n\ttype DeleteResult,\n\ttype DnsProvider,\n\ttype DnsRecord,\n\tmxValue,\n\tparseMxValue,\n\ttype UpsertDnsRecord,\n\ttype UpsertResult,\n} from '../index';\nimport {\n\tCLOUDFLARE_AUTO_TTL,\n\tCLOUDFLARE_MANAGED_TYPES,\n\tCloudflareApi,\n\ttype CloudflareApiOptions,\n\ttype CloudflareCredential,\n\ttype CloudflareRecord,\n\ttype CloudflareRecordInput,\n\tCloudflareRecordNotAllowed,\n\ttype CloudflareRecordType,\n} from './api';\n\n/** Cloudflare refuses a TTL under this, but for its automatic one. */\nconst CLOUDFLARE_MIN_TTL = 60;\n\nexport interface CloudflareProviderOptions {\n\t/**\n\t * Where the token comes from, asked the first time the API is called. It\n\t * throws when there is none: what to do about a missing token is the\n\t * caller's to say.\n\t */\n\tcredential: () => Promise<CloudflareCredential>;\n\t/** The API's base URL, for tests. */\n\tbaseUrl?: string;\n\t/** How a 429 is waited out, for tests. */\n\tsleep?: CloudflareApiOptions['sleep'];\n\tmaxAttempts?: number;\n}\n\n/** A value compared the way DNS does: case-insensitive, no trailing dot. */\nfunction normalize(value: string): string {\n\treturn value.trim().replace(/\\.$/, '').replace(/\\s+/g, ' ').toLowerCase();\n}\n\n/** `api` under `example.com` → `api.example.com`; `@` → `example.com`. */\nexport function fullName(name: string, domain: string): string {\n\tconst zone = domain.toLowerCase().replace(/\\.$/, '');\n\tconst label = name.trim().toLowerCase().replace(/\\.$/, '');\n\tif (label === '@' || label === '' || label === zone) return zone;\n\treturn label.endsWith(`.${zone}`) ? label : `${label}.${zone}`;\n}\n\n/** A Cloudflare record's value in gkm's form: an MX's is `<priority> <host>`. */\nfunction valueOf(record: CloudflareRecord): string {\n\treturn record.type === 'MX'\n\t\t? mxValue(record.priority ?? 0, record.content)\n\t\t: record.content;\n}\n\nfunction managed(type: string): type is CloudflareRecordType {\n\treturn (CLOUDFLARE_MANAGED_TYPES as readonly string[]).includes(type);\n}\n\n/** Only an address or an alias can be proxied. */\nfunction proxiable(type: string): boolean {\n\treturn type === 'A' || type === 'AAAA' || type === 'CNAME';\n}\n\nexport class CloudflareProvider implements DnsProvider {\n\treadonly name = 'cloudflare';\n\tprivate api: CloudflareApi | null = null;\n\n\tconstructor(private readonly options: CloudflareProviderOptions) {}\n\n\tprivate async getApi(): Promise<CloudflareApi> {\n\t\tif (this.api) return this.api;\n\t\tconst credential = await this.options.credential();\n\t\tthis.api = new CloudflareApi({\n\t\t\tcredential,\n\t\t\t...(this.options.baseUrl ? { baseUrl: this.options.baseUrl } : {}),\n\t\t\t...(this.options.sleep ? { sleep: this.options.sleep } : {}),\n\t\t\t...(this.options.maxAttempts\n\t\t\t\t? { maxAttempts: this.options.maxAttempts }\n\t\t\t\t: {}),\n\t\t});\n\t\treturn this.api;\n\t}\n\n\tprivate assertManaged(domain: string, type: string, name: string): void {\n\t\tif (!managed(type))\n\t\t\tthrow new CloudflareRecordNotAllowed(domain, type, name);\n\t}\n\n\t/**\n\t * The managed records of the whole zone: A, AAAA, CNAME and MX. Prefer\n\t * {@link readRecords}, which asks for exactly the names it needs.\n\t */\n\tasync getRecords(domain: string): Promise<DnsRecord[]> {\n\t\tconst api = await this.getApi();\n\t\tconst zone = domain.toLowerCase();\n\t\tconst out: DnsRecord[] = [];\n\t\tfor (const type of CLOUDFLARE_MANAGED_TYPES) {\n\t\t\tconst records = await api.getRecords(zone, type);\n\t\t\tout.push(...group(zone, type, records));\n\t\t}\n\t\treturn out;\n\t}\n\n\t/** The records of exactly these names and types, one request each. */\n\tasync readRecords(\n\t\tdomain: string,\n\t\twanted: readonly DeleteDnsRecord[],\n\t): Promise<DnsRecord[]> {\n\t\tfor (const { name, type } of wanted) this.assertManaged(domain, type, name);\n\t\tconst api = await this.getApi();\n\t\tconst found: DnsRecord[] = [];\n\t\tfor (const { name, type } of wanted) {\n\t\t\tconst records = await api.getRecords(\n\t\t\t\tdomain,\n\t\t\t\ttype as CloudflareRecordType,\n\t\t\t\tfullName(name, domain),\n\t\t\t);\n\t\t\tfound.push(...group(domain, type as CloudflareRecordType, records, name));\n\t\t}\n\t\treturn found;\n\t}\n\n\t/**\n\t * Each name and type set to exactly its one value: read it, and write it\n\t * only when its value or its proxy differ. The first record of the name\n\t * is updated in place and any other of that type deleted, so the set\n\t * ends up with one.\n\t */\n\tasync upsertRecords(\n\t\tdomain: string,\n\t\trecords: UpsertDnsRecord[],\n\t): Promise<UpsertResult[]> {\n\t\t// Every record is checked before any is written, so a refused one\n\t\t// leaves the zone as it was.\n\t\tfor (const record of records) {\n\t\t\tthis.assertManaged(domain, record.type, record.name);\n\t\t}\n\t\tconst api = await this.getApi();\n\n\t\tconst results: UpsertResult[] = [];\n\t\tfor (const record of records) {\n\t\t\tconst type = record.type as CloudflareRecordType;\n\t\t\tconst name = fullName(record.name, domain);\n\t\t\tconst existing = await api.getRecords(domain, type, name);\n\t\t\tconst [first, ...rest] = existing;\n\t\t\tconst proxied = proxiable(type)\n\t\t\t\t? (record.proxied ?? first?.proxied ?? false)\n\t\t\t\t: undefined;\n\n\t\t\tif (\n\t\t\t\tfirst &&\n\t\t\t\trest.length === 0 &&\n\t\t\t\tnormalize(valueOf(first)) === normalize(record.value) &&\n\t\t\t\t(proxied === undefined || (first.proxied ?? false) === proxied)\n\t\t\t) {\n\t\t\t\tresults.push({ record, created: false, unchanged: true });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst input = recordInput(type, name, record, proxied);\n\t\t\tif (first) await api.updateRecord(domain, first.id, input);\n\t\t\telse await api.createRecord(domain, input);\n\t\t\tfor (const extra of rest) await api.deleteRecord(domain, extra.id);\n\t\t\tresults.push({ record, created: !first, unchanged: false });\n\t\t}\n\t\treturn results;\n\t}\n\n\tasync deleteRecords(\n\t\tdomain: string,\n\t\trecords: DeleteDnsRecord[],\n\t): Promise<DeleteResult[]> {\n\t\tfor (const record of records) {\n\t\t\tthis.assertManaged(domain, record.type, record.name);\n\t\t}\n\t\tconst api = await this.getApi();\n\t\tconst results: DeleteResult[] = [];\n\t\tfor (const record of records) {\n\t\t\tconst existing = await api.getRecords(\n\t\t\t\tdomain,\n\t\t\t\trecord.type as CloudflareRecordType,\n\t\t\t\tfullName(record.name, domain),\n\t\t\t);\n\t\t\tif (existing.length === 0) {\n\t\t\t\tresults.push({ record, deleted: false, notFound: true });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const found of existing) await api.deleteRecord(domain, found.id);\n\t\t\tresults.push({ record, deleted: true, notFound: false });\n\t\t}\n\t\treturn results;\n\t}\n}\n\n/** What a write sends for one record. */\nfunction recordInput(\n\ttype: CloudflareRecordType,\n\tname: string,\n\trecord: UpsertDnsRecord,\n\tproxied: boolean | undefined,\n): CloudflareRecordInput {\n\tconst ttl = proxied\n\t\t? CLOUDFLARE_AUTO_TTL\n\t\t: Math.max(record.ttl, CLOUDFLARE_MIN_TTL);\n\tif (type === 'MX') {\n\t\tconst { priority, host } = parseMxValue(record.value);\n\t\treturn { type, name, content: host, priority, ttl };\n\t}\n\treturn {\n\t\ttype,\n\t\tname,\n\t\tcontent: record.value.trim().replace(/\\.$/, ''),\n\t\tttl,\n\t\t...(proxied !== undefined ? { proxied } : {}),\n\t};\n}\n\n/**\n * Cloudflare's records as DnsRecords: one per name, its values together,\n * named relative to the domain (`@` for the apex) — or as `asked`, when the\n * caller named it.\n */\nfunction group(\n\tdomain: string,\n\ttype: CloudflareRecordType,\n\trecords: readonly CloudflareRecord[],\n\tasked?: string,\n): DnsRecord[] {\n\tconst zone = domain.toLowerCase();\n\tconst byName = new Map<string, CloudflareRecord[]>();\n\tfor (const record of records) {\n\t\tconst fqdn = record.name.toLowerCase();\n\t\tbyName.set(fqdn, [...(byName.get(fqdn) ?? []), record]);\n\t}\n\treturn [...byName.entries()].map(([fqdn, set]) => ({\n\t\tname:\n\t\t\tasked ??\n\t\t\t(fqdn === zone ? '@' : fqdn.slice(0, fqdn.length - zone.length - 1)),\n\t\ttype,\n\t\tttl: set[0]!.ttl === CLOUDFLARE_AUTO_TTL ? 300 : set[0]!.ttl,\n\t\tvalues: set.map(valueOf),\n\t\t...(proxiable(type) ? { proxied: set[0]!.proxied ?? false } : {}),\n\t}));\n}\n\nexport {\n\tCLOUDFLARE_API_BASE,\n\tCLOUDFLARE_AUTO_TTL,\n\tCLOUDFLARE_MANAGED_TYPES,\n\tCloudflareApi,\n\ttype CloudflareApiOptions,\n\ttype CloudflareCredential,\n\tCloudflareCredentialsInvalid,\n\ttype CloudflareOriginCertificate,\n\tCloudflarePermissionMissing,\n\tCloudflareRateLimited,\n\ttype CloudflareRecord,\n\ttype CloudflareRecordInput,\n\tCloudflareRecordNotAllowed,\n\ttype CloudflareRecordType,\n\tCloudflareRequestFailed,\n\tCloudflareZoneNotFound,\n} from './api';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,sBAAsB;;;;;AAMnC,MAAa,sBAAsB;;AAGnC,MAAa,2BAA2B;CAAC;CAAK;CAAQ;CAAS;AAAI;;AAiDnE,IAAa,+BAAb,cAAkD,UAAU;CACtC;CAArB,YAAY,QAA0B;EACrC,MACC,mCAAmC,SAAS,KAAK,OAAO,KAAK,GAAG,0KAIjE;EANoB,KAAA,SAAA;EAOpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,8BAAb,cAAiD,UAAU;CAEhD;CACA;CAEA;CAJV,YACC,QACA,QAEA,aAA8B,iBAC7B;EACD,MACC,uCAAuC,SACnC,SAAS,KAAK,OAAO,KAAK,GAAG,YAAY,WAAW,MACpD,OAAO,8DACZ;EATS,KAAA,SAAA;EACA,KAAA,SAAA;EAEA,KAAA,aAAA;EAOT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,yBAAb,cAA4C,UAAU;CAChC;CAArB,YAAY,QAAyB;EACpC,MACC,0BAA0B,OAAO,2BAA2B,OAAO,yHAGpE;EALoB,KAAA,SAAA;EAMpB,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,wBAAb,cAA2C,UAAU;CAC/B;CAArB,YAAY,UAA2B;EACtC,MACC,yDAAyD,SAAS,qFAGnE;EALoB,KAAA,WAAA;EAMpB,KAAK,O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AM;GAAM,SAAS;GAAM;GAAU;EAAI;CACnD;CACA,OAAO;EACN;EACA;EACA,SAAS,OAAO,MAAM,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;EAC9C;EACA,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;CAC5C;AACD;;;;;;AAOA,SAAS,MACR,QACA,MACA,SACA,OACc;CACd,MAAM,OAAO,OAAO,YAAY;CAChC,MAAM,yBAAS,IAAI,IAAgC;CACnD,KAAK,MAAM,UAAU,SAAS;EAC7B,MAAM,OAAO,OAAO,KAAK,YAAY;EACrC,OAAO,IAAI,MAAM,CAAC,GAAI,OAAO,IAAI,IAAI,KAAK,CAAC,GAAI,MAAM,CAAC;CACvD;CACA,OAAO,CAAC,GAAG,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU;EAClD,MACC,UACC,SAAS,OAAO,MAAM,KAAK,MAAM,GAAG,KAAK,SAAS,KAAK,SAAS,CAAC;EACnE;EACA,KAAK,IAAI,EAAE,CAAE,QAAA,IAA8B,MAAM,IAAI,EAAE,CAAE;EACzD,QAAQ,IAAI,IAAI,OAAO;EACvB,GAAI,UAAU,IAAI,IAAI,EAAE,SAAS,IAAI,EAAE,CAAE,WAAW,MAAM,IAAI,CAAC;CAChE,EAAE;AACH"}
@@ -5,7 +5,8 @@ const require_errors = require("../errors-DlRLQOyZ.cjs");
5
5
  * DNS Provider Interface
6
6
  *
7
7
  * Abstracts DNS operations for different providers.
8
- * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider
8
+ * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider,
9
+ * CloudflareProvider
9
10
  * Users can also supply custom implementations.
10
11
  *
11
12
  * Every value is the record's zone-file form, read and written alike: an MX
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["EdgeError"],"sources":["../../src/dns/index.ts"],"sourcesContent":["/**\n * DNS Provider Interface\n *\n * Abstracts DNS operations for different providers.\n * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider\n * Users can also supply custom implementations.\n *\n * Every value is the record's zone-file form, read and written alike: an MX\n * record's is `<priority> <host>` (see {@link mxValue}).\n */\n\nimport { EdgeError } from '../errors';\n\n// =============================================================================\n// DNS Record Types (derived from Zod schemas)\n// =============================================================================\n\n/** DNS record types supported across providers. */\nexport type DnsRecordType =\n\t| 'A'\n\t| 'AAAA'\n\t| 'CNAME'\n\t| 'MX'\n\t| 'TXT'\n\t| 'NS'\n\t| 'SRV'\n\t| 'CAA';\n\n/** A DNS record as returned by the provider. */\nexport interface DnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record values, as a zone file writes them: an MX record's is\n\t * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).\n\t */\n\tvalues: string[];\n}\n\n/** A DNS record to create or update. */\nexport interface UpsertDnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record value (IP address, hostname, etc.), as a zone file writes it: an\n\t * MX record's is `<priority> <host>` — see `mxValue`.\n\t */\n\tvalue: string;\n}\n\n/** Result of an upsert operation. */\nexport interface UpsertResult {\n\t/** The record that was upserted */\n\trecord: UpsertDnsRecord;\n\t/** Whether the record was created (true) or updated (false) */\n\tcreated: boolean;\n\t/** Whether the record already existed with the same value */\n\tunchanged: boolean;\n}\n\n// =============================================================================\n// MX values\n// =============================================================================\n\n/**\n * An MX record's value as every provider here reads and writes it — the zone\n * file's `<priority> <host>`, which is what Route53 and Hostinger take as is.\n * A provider whose API keeps the priority apart (GoDaddy) splits it with\n * {@link parseMxValue}.\n */\nexport function mxValue(priority: number, host: string): string {\n\treturn `${priority} ${host.trim().replace(/\\.$/, '')}`;\n}\n\n/** An MX value that is not `<priority> <host>`. */\nexport class MxValueInvalid extends EdgeError {\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`'${value}' is not an MX record's value: it is written ` +\n\t\t\t\t\"'<priority> <host>', like '10 inbound-smtp.eu-west-1.amazonaws.com'. \" +\n\t\t\t\t'Build it with mxValue(priority, host).',\n\t\t);\n\t\tthis.name = 'MxValueInvalid';\n\t}\n}\n\n/**\n * The priority and host of an MX value.\n *\n * @throws {MxValueInvalid} for a value that is not `<priority> <host>`\n */\nexport function parseMxValue(value: string): {\n\tpriority: number;\n\thost: string;\n} {\n\tconst match = value.trim().match(/^(\\d{1,5})\\s+(\\S+)$/);\n\tconst priority = match ? Number(match[1]) : Number.NaN;\n\tif (!match || priority > 65535) throw new MxValueInvalid(value);\n\treturn { priority, host: match[2]!.replace(/\\.$/, '') };\n}\n\n// =============================================================================\n// DNS Provider Interface\n// =============================================================================\n\n/**\n * A record to delete from DNS.\n */\nexport interface DeleteDnsRecord {\n\t/** Record name/subdomain (e.g., 'api' or '@' for root) */\n\tname: string;\n\t/** Record type (A, CNAME, etc.) */\n\ttype: DnsRecordType;\n}\n\n/**\n * Result of a delete operation.\n */\nexport interface DeleteResult {\n\t/** The record that was requested for deletion */\n\trecord: DeleteDnsRecord;\n\t/** Whether the record was deleted */\n\tdeleted: boolean;\n\t/** Whether the record was not found (already deleted) */\n\tnotFound: boolean;\n\t/** Error message if deletion failed */\n\terror?: string;\n}\n\n/**\n * Interface for DNS providers.\n *\n * Implementations must handle:\n * - Getting all records for a domain\n * - Creating or updating records for a domain\n * - Deleting records from a domain\n */\nexport interface DnsProvider {\n\t/** Provider name for logging */\n\treadonly name: string;\n\n\t/**\n\t * Get all DNS records for a domain.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @returns Array of DNS records\n\t */\n\tgetRecords(domain: string): Promise<DnsRecord[]>;\n\n\t/**\n\t * The records of exactly these names and types, where the provider can\n\t * read them one at a time — cheaper than the whole zone on an API that\n\t * counts requests. Optional: without it, `getRecords` is filtered.\n\t * Throws {@link DnsRecordsUnreadable} when the credentials can only write.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param wanted - The names ('@' for the root) and types to read\n\t */\n\treadRecords?(\n\t\tdomain: string,\n\t\twanted: readonly DeleteDnsRecord[],\n\t): Promise<DnsRecord[]>;\n\n\t/**\n\t * Create or update DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to create or update\n\t * @returns Results of the upsert operations\n\t */\n\tupsertRecords(\n\t\tdomain: string,\n\t\trecords: UpsertDnsRecord[],\n\t): Promise<UpsertResult[]>;\n\n\t/**\n\t * Delete DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to delete\n\t * @returns Results of the delete operations\n\t */\n\tdeleteRecords(\n\t\tdomain: string,\n\t\trecords: DeleteDnsRecord[],\n\t): Promise<DeleteResult[]>;\n}\n\n/**\n * Check if value is a DnsProvider implementation.\n */\nexport function isDnsProvider(value: unknown): value is DnsProvider {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof (value as DnsProvider).name === 'string' &&\n\t\ttypeof (value as DnsProvider).getRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).upsertRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).deleteRecords === 'function'\n\t);\n}\n\n/**\n * The provider's credentials can write records and not read them — a key\n * scoped to updates only. What reads them falls back to writing every record,\n * which is idempotent, without a diff.\n */\nexport class DnsRecordsUnreadable extends EdgeError {\n\tconstructor(\n\t\treadonly provider: string,\n\t\treadonly domain: string,\n\t\treadonly reason: string,\n\t) {\n\t\tsuper(\n\t\t\t`The ${provider} key cannot read ${domain}'s DNS records (${reason}), so ` +\n\t\t\t\t'changes cannot be compared with what is there: every record is ' +\n\t\t\t\t'written, which leaves one that already has its value as it was.',\n\t\t);\n\t\tthis.name = 'DnsRecordsUnreadable';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4EA,SAAgB,QAAQ,UAAkB,MAAsB;CAC/D,OAAO,GAAG,SAAS,GAAG,KAAK,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;AACpD;;AAGA,IAAa,iBAAb,cAAoCA,eAAAA,UAAU;CACxB;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,yJAGX;EALoB,KAAA,QAAA;EAMpB,KAAK,OAAO;CACb;AACD;;;;;;AAOA,SAAgB,aAAa,OAG3B;CACD,MAAM,QAAQ,MAAM,KAAK,CAAC,CAAC,MAAM,qBAAqB;CACtD,MAAM,WAAW,QAAQ,OAAO,MAAM,EAAE,IAAI;CAC5C,IAAI,CAAC,SAAS,WAAW,OAAO,MAAM,IAAI,eAAe,KAAK;CAC9D,OAAO;EAAE;EAAU,MAAM,MAAM,EAAE,CAAE,QAAQ,OAAO,EAAE;CAAE;AACvD;;;;AA4FA,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAsB,SAAS,YACvC,OAAQ,MAAsB,eAAe,cAC7C,OAAQ,MAAsB,kBAAkB,cAChD,OAAQ,MAAsB,kBAAkB;AAElD;;;;;;AAOA,IAAa,uBAAb,cAA0CA,eAAAA,UAAU;CAEzC;CACA;CACA;CAHV,YACC,UACA,QACA,QACC;EACD,MACC,OAAO,SAAS,mBAAmB,OAAO,kBAAkB,OAAO,qIAGpE;EARS,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACb;AACD"}
1
+ {"version":3,"file":"index.cjs","names":["EdgeError"],"sources":["../../src/dns/index.ts"],"sourcesContent":["/**\n * DNS Provider Interface\n *\n * Abstracts DNS operations for different providers.\n * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider,\n * CloudflareProvider\n * Users can also supply custom implementations.\n *\n * Every value is the record's zone-file form, read and written alike: an MX\n * record's is `<priority> <host>` (see {@link mxValue}).\n */\n\nimport { EdgeError } from '../errors';\n\n// =============================================================================\n// DNS Record Types (derived from Zod schemas)\n// =============================================================================\n\n/** DNS record types supported across providers. */\nexport type DnsRecordType =\n\t| 'A'\n\t| 'AAAA'\n\t| 'CNAME'\n\t| 'MX'\n\t| 'TXT'\n\t| 'NS'\n\t| 'SRV'\n\t| 'CAA';\n\n/** A DNS record as returned by the provider. */\nexport interface DnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record values, as a zone file writes them: an MX record's is\n\t * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).\n\t */\n\tvalues: string[];\n\t/**\n\t * Whether the provider's own proxy answers for the name rather than the\n\t * address in it — Cloudflare's CDN. Absent where the provider has none.\n\t */\n\tproxied?: boolean;\n}\n\n/** A DNS record to create or update. */\nexport interface UpsertDnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record value (IP address, hostname, etc.), as a zone file writes it: an\n\t * MX record's is `<priority> <host>` — see `mxValue`.\n\t */\n\tvalue: string;\n\t/**\n\t * Put the provider's own proxy in front of it — Cloudflare's CDN, which\n\t * answers the name and forwards to `value`. Only an A, AAAA or CNAME can\n\t * be. `false` takes it out; absent leaves an existing record as it is\n\t * and creates one unproxied. A provider without a proxy ignores it.\n\t */\n\tproxied?: boolean;\n}\n\n/** Result of an upsert operation. */\nexport interface UpsertResult {\n\t/** The record that was upserted */\n\trecord: UpsertDnsRecord;\n\t/** Whether the record was created (true) or updated (false) */\n\tcreated: boolean;\n\t/** Whether the record already existed with the same value */\n\tunchanged: boolean;\n}\n\n// =============================================================================\n// MX values\n// =============================================================================\n\n/**\n * An MX record's value as every provider here reads and writes it — the zone\n * file's `<priority> <host>`, which is what Route53 and Hostinger take as is.\n * A provider whose API keeps the priority apart (GoDaddy) splits it with\n * {@link parseMxValue}.\n */\nexport function mxValue(priority: number, host: string): string {\n\treturn `${priority} ${host.trim().replace(/\\.$/, '')}`;\n}\n\n/** An MX value that is not `<priority> <host>`. */\nexport class MxValueInvalid extends EdgeError {\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`'${value}' is not an MX record's value: it is written ` +\n\t\t\t\t\"'<priority> <host>', like '10 inbound-smtp.eu-west-1.amazonaws.com'. \" +\n\t\t\t\t'Build it with mxValue(priority, host).',\n\t\t);\n\t\tthis.name = 'MxValueInvalid';\n\t}\n}\n\n/**\n * The priority and host of an MX value.\n *\n * @throws {MxValueInvalid} for a value that is not `<priority> <host>`\n */\nexport function parseMxValue(value: string): {\n\tpriority: number;\n\thost: string;\n} {\n\tconst match = value.trim().match(/^(\\d{1,5})\\s+(\\S+)$/);\n\tconst priority = match ? Number(match[1]) : Number.NaN;\n\tif (!match || priority > 65535) throw new MxValueInvalid(value);\n\treturn { priority, host: match[2]!.replace(/\\.$/, '') };\n}\n\n// =============================================================================\n// DNS Provider Interface\n// =============================================================================\n\n/**\n * A record to delete from DNS.\n */\nexport interface DeleteDnsRecord {\n\t/** Record name/subdomain (e.g., 'api' or '@' for root) */\n\tname: string;\n\t/** Record type (A, CNAME, etc.) */\n\ttype: DnsRecordType;\n}\n\n/**\n * Result of a delete operation.\n */\nexport interface DeleteResult {\n\t/** The record that was requested for deletion */\n\trecord: DeleteDnsRecord;\n\t/** Whether the record was deleted */\n\tdeleted: boolean;\n\t/** Whether the record was not found (already deleted) */\n\tnotFound: boolean;\n\t/** Error message if deletion failed */\n\terror?: string;\n}\n\n/**\n * Interface for DNS providers.\n *\n * Implementations must handle:\n * - Getting all records for a domain\n * - Creating or updating records for a domain\n * - Deleting records from a domain\n */\nexport interface DnsProvider {\n\t/** Provider name for logging */\n\treadonly name: string;\n\n\t/**\n\t * Get all DNS records for a domain.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @returns Array of DNS records\n\t */\n\tgetRecords(domain: string): Promise<DnsRecord[]>;\n\n\t/**\n\t * The records of exactly these names and types, where the provider can\n\t * read them one at a time — cheaper than the whole zone on an API that\n\t * counts requests. Optional: without it, `getRecords` is filtered.\n\t * Throws {@link DnsRecordsUnreadable} when the credentials can only write.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param wanted - The names ('@' for the root) and types to read\n\t */\n\treadRecords?(\n\t\tdomain: string,\n\t\twanted: readonly DeleteDnsRecord[],\n\t): Promise<DnsRecord[]>;\n\n\t/**\n\t * Create or update DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to create or update\n\t * @returns Results of the upsert operations\n\t */\n\tupsertRecords(\n\t\tdomain: string,\n\t\trecords: UpsertDnsRecord[],\n\t): Promise<UpsertResult[]>;\n\n\t/**\n\t * Delete DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to delete\n\t * @returns Results of the delete operations\n\t */\n\tdeleteRecords(\n\t\tdomain: string,\n\t\trecords: DeleteDnsRecord[],\n\t): Promise<DeleteResult[]>;\n}\n\n/**\n * Check if value is a DnsProvider implementation.\n */\nexport function isDnsProvider(value: unknown): value is DnsProvider {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof (value as DnsProvider).name === 'string' &&\n\t\ttypeof (value as DnsProvider).getRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).upsertRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).deleteRecords === 'function'\n\t);\n}\n\n/**\n * The provider's credentials can write records and not read them — a key\n * scoped to updates only. What reads them falls back to writing every record,\n * which is idempotent, without a diff.\n */\nexport class DnsRecordsUnreadable extends EdgeError {\n\tconstructor(\n\t\treadonly provider: string,\n\t\treadonly domain: string,\n\t\treadonly reason: string,\n\t) {\n\t\tsuper(\n\t\t\t`The ${provider} key cannot read ${domain}'s DNS records (${reason}), so ` +\n\t\t\t\t'changes cannot be compared with what is there: every record is ' +\n\t\t\t\t'written, which leaves one that already has its value as it was.',\n\t\t);\n\t\tthis.name = 'DnsRecordsUnreadable';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,QAAQ,UAAkB,MAAsB;CAC/D,OAAO,GAAG,SAAS,GAAG,KAAK,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;AACpD;;AAGA,IAAa,iBAAb,cAAoCA,eAAAA,UAAU;CACxB;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,yJAGX;EALoB,KAAA,QAAA;EAMpB,KAAK,OAAO;CACb;AACD;;;;;;AAOA,SAAgB,aAAa,OAG3B;CACD,MAAM,QAAQ,MAAM,KAAK,CAAC,CAAC,MAAM,qBAAqB;CACtD,MAAM,WAAW,QAAQ,OAAO,MAAM,EAAE,IAAI;CAC5C,IAAI,CAAC,SAAS,WAAW,OAAO,MAAM,IAAI,eAAe,KAAK;CAC9D,OAAO;EAAE;EAAU,MAAM,MAAM,EAAE,CAAE,QAAQ,OAAO,EAAE;CAAE;AACvD;;;;AA4FA,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAsB,SAAS,YACvC,OAAQ,MAAsB,eAAe,cAC7C,OAAQ,MAAsB,kBAAkB,cAChD,OAAQ,MAAsB,kBAAkB;AAElD;;;;;;AAOA,IAAa,uBAAb,cAA0CA,eAAAA,UAAU;CAEzC;CACA;CACA;CAHV,YACC,UACA,QACA,QACC;EACD,MACC,OAAO,SAAS,mBAAmB,OAAO,kBAAkB,OAAO,qIAGpE;EARS,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACb;AACD"}
@@ -14,6 +14,11 @@ export interface DnsRecord {
14
14
  * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).
15
15
  */
16
16
  values: string[];
17
+ /**
18
+ * Whether the provider's own proxy answers for the name rather than the
19
+ * address in it — Cloudflare's CDN. Absent where the provider has none.
20
+ */
21
+ proxied?: boolean;
17
22
  }
18
23
  /** A DNS record to create or update. */
19
24
  export interface UpsertDnsRecord {
@@ -27,6 +32,13 @@ export interface UpsertDnsRecord {
27
32
  * MX record's is `<priority> <host>` — see `mxValue`.
28
33
  */
29
34
  value: string;
35
+ /**
36
+ * Put the provider's own proxy in front of it — Cloudflare's CDN, which
37
+ * answers the name and forwards to `value`. Only an A, AAAA or CNAME can
38
+ * be. `false` takes it out; absent leaves an existing record as it is
39
+ * and creates one unproxied. A provider without a proxy ignores it.
40
+ */
41
+ proxied?: boolean;
30
42
  }
31
43
  /** Result of an upsert operation. */
32
44
  export interface UpsertResult {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/dns/index.ts"],"mappings":";;;YAkBY;;iBAWK;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;iBAIgB;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;iBAIgB;;EAEhB,QAAQ;;EAER;;EAEA;;;;;;;;wBAae,QAAQ,kBAAkB;;qBAK7B,uBAAuB;WACd;EAArB,YAAqB;;;;;;;wBAeN,aAAa;EAC5B;EACA;;;;;iBAegB;;EAEhB;;EAEA,MAAM;;;;;iBAMU;;EAEhB,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWgB;;WAEP;;;;;;;EAQT,WAAW,iBAAiB,QAAQ;;;;;;;;;;EAWpC,aACC,gBACA,iBAAiB,oBACf,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;wBAMI,cAAc,iBAAiB,SAAS;;;;;;qBAgB3C,6BAA6B;WAE/B;WACA;WACA;EAHV,YACU,kBACA,gBACA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/dns/index.ts"],"mappings":";;;YAmBY;;iBAWK;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;;;EAKA;;;iBAIgB;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;;;;;EAOA;;;iBAIgB;;EAEhB,QAAQ;;EAER;;EAEA;;;;;;;;wBAae,QAAQ,kBAAkB;;qBAK7B,uBAAuB;WACd;EAArB,YAAqB;;;;;;;wBAeN,aAAa;EAC5B;EACA;;;;;iBAegB;;EAEhB;;EAEA,MAAM;;;;;iBAMU;;EAEhB,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWgB;;WAEP;;;;;;;EAQT,WAAW,iBAAiB,QAAQ;;;;;;;;;;EAWpC,aACC,gBACA,iBAAiB,oBACf,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;wBAMI,cAAc,iBAAiB,SAAS;;;;;;qBAgB3C,6BAA6B;WAE/B;WACA;WACA;EAHV,YACU,kBACA,gBACA"}
@@ -14,6 +14,11 @@ export interface DnsRecord {
14
14
  * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).
15
15
  */
16
16
  values: string[];
17
+ /**
18
+ * Whether the provider's own proxy answers for the name rather than the
19
+ * address in it — Cloudflare's CDN. Absent where the provider has none.
20
+ */
21
+ proxied?: boolean;
17
22
  }
18
23
  /** A DNS record to create or update. */
19
24
  export interface UpsertDnsRecord {
@@ -27,6 +32,13 @@ export interface UpsertDnsRecord {
27
32
  * MX record's is `<priority> <host>` — see `mxValue`.
28
33
  */
29
34
  value: string;
35
+ /**
36
+ * Put the provider's own proxy in front of it — Cloudflare's CDN, which
37
+ * answers the name and forwards to `value`. Only an A, AAAA or CNAME can
38
+ * be. `false` takes it out; absent leaves an existing record as it is
39
+ * and creates one unproxied. A provider without a proxy ignores it.
40
+ */
41
+ proxied?: boolean;
30
42
  }
31
43
  /** Result of an upsert operation. */
32
44
  export interface UpsertResult {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/dns/index.ts"],"mappings":";;;YAkBY;;iBAWK;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;iBAIgB;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;iBAIgB;;EAEhB,QAAQ;;EAER;;EAEA;;;;;;;;wBAae,QAAQ,kBAAkB;;qBAK7B,uBAAuB;WACd;EAArB,YAAqB;;;;;;;wBAeN,aAAa;EAC5B;EACA;;;;;iBAegB;;EAEhB;;EAEA,MAAM;;;;;iBAMU;;EAEhB,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWgB;;WAEP;;;;;;;EAQT,WAAW,iBAAiB,QAAQ;;;;;;;;;;EAWpC,aACC,gBACA,iBAAiB,oBACf,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;wBAMI,cAAc,iBAAiB,SAAS;;;;;;qBAgB3C,6BAA6B;WAE/B;WACA;WACA;EAHV,YACU,kBACA,gBACA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/dns/index.ts"],"mappings":";;;YAmBY;;iBAWK;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;;;EAKA;;;iBAIgB;;EAEhB;EACA,MAAM;;EAEN;;;;;EAKA;;;;;;;EAOA;;;iBAIgB;;EAEhB,QAAQ;;EAER;;EAEA;;;;;;;;wBAae,QAAQ,kBAAkB;;qBAK7B,uBAAuB;WACd;EAArB,YAAqB;;;;;;;wBAeN,aAAa;EAC5B;EACA;;;;;iBAegB;;EAEhB;;EAEA,MAAM;;;;;iBAMU;;EAEhB,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWgB;;WAEP;;;;;;;EAQT,WAAW,iBAAiB,QAAQ;;;;;;;;;;EAWpC,aACC,gBACA,iBAAiB,oBACf,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;;;;EASX,cACC,gBACA,SAAS,oBACP,QAAQ;;;;;wBAMI,cAAc,iBAAiB,SAAS;;;;;;qBAgB3C,6BAA6B;WAE/B;WACA;WACA;EAHV,YACU,kBACA,gBACA"}
@@ -4,7 +4,8 @@ import { t as EdgeError } from "../errors-CO33_TDV.mjs";
4
4
  * DNS Provider Interface
5
5
  *
6
6
  * Abstracts DNS operations for different providers.
7
- * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider
7
+ * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider,
8
+ * CloudflareProvider
8
9
  * Users can also supply custom implementations.
9
10
  *
10
11
  * Every value is the record's zone-file form, read and written alike: an MX
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/dns/index.ts"],"sourcesContent":["/**\n * DNS Provider Interface\n *\n * Abstracts DNS operations for different providers.\n * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider\n * Users can also supply custom implementations.\n *\n * Every value is the record's zone-file form, read and written alike: an MX\n * record's is `<priority> <host>` (see {@link mxValue}).\n */\n\nimport { EdgeError } from '../errors';\n\n// =============================================================================\n// DNS Record Types (derived from Zod schemas)\n// =============================================================================\n\n/** DNS record types supported across providers. */\nexport type DnsRecordType =\n\t| 'A'\n\t| 'AAAA'\n\t| 'CNAME'\n\t| 'MX'\n\t| 'TXT'\n\t| 'NS'\n\t| 'SRV'\n\t| 'CAA';\n\n/** A DNS record as returned by the provider. */\nexport interface DnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record values, as a zone file writes them: an MX record's is\n\t * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).\n\t */\n\tvalues: string[];\n}\n\n/** A DNS record to create or update. */\nexport interface UpsertDnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record value (IP address, hostname, etc.), as a zone file writes it: an\n\t * MX record's is `<priority> <host>` — see `mxValue`.\n\t */\n\tvalue: string;\n}\n\n/** Result of an upsert operation. */\nexport interface UpsertResult {\n\t/** The record that was upserted */\n\trecord: UpsertDnsRecord;\n\t/** Whether the record was created (true) or updated (false) */\n\tcreated: boolean;\n\t/** Whether the record already existed with the same value */\n\tunchanged: boolean;\n}\n\n// =============================================================================\n// MX values\n// =============================================================================\n\n/**\n * An MX record's value as every provider here reads and writes it — the zone\n * file's `<priority> <host>`, which is what Route53 and Hostinger take as is.\n * A provider whose API keeps the priority apart (GoDaddy) splits it with\n * {@link parseMxValue}.\n */\nexport function mxValue(priority: number, host: string): string {\n\treturn `${priority} ${host.trim().replace(/\\.$/, '')}`;\n}\n\n/** An MX value that is not `<priority> <host>`. */\nexport class MxValueInvalid extends EdgeError {\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`'${value}' is not an MX record's value: it is written ` +\n\t\t\t\t\"'<priority> <host>', like '10 inbound-smtp.eu-west-1.amazonaws.com'. \" +\n\t\t\t\t'Build it with mxValue(priority, host).',\n\t\t);\n\t\tthis.name = 'MxValueInvalid';\n\t}\n}\n\n/**\n * The priority and host of an MX value.\n *\n * @throws {MxValueInvalid} for a value that is not `<priority> <host>`\n */\nexport function parseMxValue(value: string): {\n\tpriority: number;\n\thost: string;\n} {\n\tconst match = value.trim().match(/^(\\d{1,5})\\s+(\\S+)$/);\n\tconst priority = match ? Number(match[1]) : Number.NaN;\n\tif (!match || priority > 65535) throw new MxValueInvalid(value);\n\treturn { priority, host: match[2]!.replace(/\\.$/, '') };\n}\n\n// =============================================================================\n// DNS Provider Interface\n// =============================================================================\n\n/**\n * A record to delete from DNS.\n */\nexport interface DeleteDnsRecord {\n\t/** Record name/subdomain (e.g., 'api' or '@' for root) */\n\tname: string;\n\t/** Record type (A, CNAME, etc.) */\n\ttype: DnsRecordType;\n}\n\n/**\n * Result of a delete operation.\n */\nexport interface DeleteResult {\n\t/** The record that was requested for deletion */\n\trecord: DeleteDnsRecord;\n\t/** Whether the record was deleted */\n\tdeleted: boolean;\n\t/** Whether the record was not found (already deleted) */\n\tnotFound: boolean;\n\t/** Error message if deletion failed */\n\terror?: string;\n}\n\n/**\n * Interface for DNS providers.\n *\n * Implementations must handle:\n * - Getting all records for a domain\n * - Creating or updating records for a domain\n * - Deleting records from a domain\n */\nexport interface DnsProvider {\n\t/** Provider name for logging */\n\treadonly name: string;\n\n\t/**\n\t * Get all DNS records for a domain.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @returns Array of DNS records\n\t */\n\tgetRecords(domain: string): Promise<DnsRecord[]>;\n\n\t/**\n\t * The records of exactly these names and types, where the provider can\n\t * read them one at a time — cheaper than the whole zone on an API that\n\t * counts requests. Optional: without it, `getRecords` is filtered.\n\t * Throws {@link DnsRecordsUnreadable} when the credentials can only write.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param wanted - The names ('@' for the root) and types to read\n\t */\n\treadRecords?(\n\t\tdomain: string,\n\t\twanted: readonly DeleteDnsRecord[],\n\t): Promise<DnsRecord[]>;\n\n\t/**\n\t * Create or update DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to create or update\n\t * @returns Results of the upsert operations\n\t */\n\tupsertRecords(\n\t\tdomain: string,\n\t\trecords: UpsertDnsRecord[],\n\t): Promise<UpsertResult[]>;\n\n\t/**\n\t * Delete DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to delete\n\t * @returns Results of the delete operations\n\t */\n\tdeleteRecords(\n\t\tdomain: string,\n\t\trecords: DeleteDnsRecord[],\n\t): Promise<DeleteResult[]>;\n}\n\n/**\n * Check if value is a DnsProvider implementation.\n */\nexport function isDnsProvider(value: unknown): value is DnsProvider {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof (value as DnsProvider).name === 'string' &&\n\t\ttypeof (value as DnsProvider).getRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).upsertRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).deleteRecords === 'function'\n\t);\n}\n\n/**\n * The provider's credentials can write records and not read them — a key\n * scoped to updates only. What reads them falls back to writing every record,\n * which is idempotent, without a diff.\n */\nexport class DnsRecordsUnreadable extends EdgeError {\n\tconstructor(\n\t\treadonly provider: string,\n\t\treadonly domain: string,\n\t\treadonly reason: string,\n\t) {\n\t\tsuper(\n\t\t\t`The ${provider} key cannot read ${domain}'s DNS records (${reason}), so ` +\n\t\t\t\t'changes cannot be compared with what is there: every record is ' +\n\t\t\t\t'written, which leaves one that already has its value as it was.',\n\t\t);\n\t\tthis.name = 'DnsRecordsUnreadable';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4EA,SAAgB,QAAQ,UAAkB,MAAsB;CAC/D,OAAO,GAAG,SAAS,GAAG,KAAK,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;AACpD;;AAGA,IAAa,iBAAb,cAAoC,UAAU;CACxB;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,yJAGX;EALoB,KAAA,QAAA;EAMpB,KAAK,OAAO;CACb;AACD;;;;;;AAOA,SAAgB,aAAa,OAG3B;CACD,MAAM,QAAQ,MAAM,KAAK,CAAC,CAAC,MAAM,qBAAqB;CACtD,MAAM,WAAW,QAAQ,OAAO,MAAM,EAAE,IAAI;CAC5C,IAAI,CAAC,SAAS,WAAW,OAAO,MAAM,IAAI,eAAe,KAAK;CAC9D,OAAO;EAAE;EAAU,MAAM,MAAM,EAAE,CAAE,QAAQ,OAAO,EAAE;CAAE;AACvD;;;;AA4FA,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAsB,SAAS,YACvC,OAAQ,MAAsB,eAAe,cAC7C,OAAQ,MAAsB,kBAAkB,cAChD,OAAQ,MAAsB,kBAAkB;AAElD;;;;;;AAOA,IAAa,uBAAb,cAA0C,UAAU;CAEzC;CACA;CACA;CAHV,YACC,UACA,QACA,QACC;EACD,MACC,OAAO,SAAS,mBAAmB,OAAO,kBAAkB,OAAO,qIAGpE;EARS,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACb;AACD"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/dns/index.ts"],"sourcesContent":["/**\n * DNS Provider Interface\n *\n * Abstracts DNS operations for different providers.\n * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider,\n * CloudflareProvider\n * Users can also supply custom implementations.\n *\n * Every value is the record's zone-file form, read and written alike: an MX\n * record's is `<priority> <host>` (see {@link mxValue}).\n */\n\nimport { EdgeError } from '../errors';\n\n// =============================================================================\n// DNS Record Types (derived from Zod schemas)\n// =============================================================================\n\n/** DNS record types supported across providers. */\nexport type DnsRecordType =\n\t| 'A'\n\t| 'AAAA'\n\t| 'CNAME'\n\t| 'MX'\n\t| 'TXT'\n\t| 'NS'\n\t| 'SRV'\n\t| 'CAA';\n\n/** A DNS record as returned by the provider. */\nexport interface DnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record values, as a zone file writes them: an MX record's is\n\t * `<priority> <host>` (`10 inbound-smtp.eu-west-1.amazonaws.com`).\n\t */\n\tvalues: string[];\n\t/**\n\t * Whether the provider's own proxy answers for the name rather than the\n\t * address in it — Cloudflare's CDN. Absent where the provider has none.\n\t */\n\tproxied?: boolean;\n}\n\n/** A DNS record to create or update. */\nexport interface UpsertDnsRecord {\n\t/** Subdomain name (e.g., 'api' for api.example.com, '@' for root) */\n\tname: string;\n\ttype: DnsRecordType;\n\t/** TTL in seconds */\n\tttl: number;\n\t/**\n\t * Record value (IP address, hostname, etc.), as a zone file writes it: an\n\t * MX record's is `<priority> <host>` — see `mxValue`.\n\t */\n\tvalue: string;\n\t/**\n\t * Put the provider's own proxy in front of it — Cloudflare's CDN, which\n\t * answers the name and forwards to `value`. Only an A, AAAA or CNAME can\n\t * be. `false` takes it out; absent leaves an existing record as it is\n\t * and creates one unproxied. A provider without a proxy ignores it.\n\t */\n\tproxied?: boolean;\n}\n\n/** Result of an upsert operation. */\nexport interface UpsertResult {\n\t/** The record that was upserted */\n\trecord: UpsertDnsRecord;\n\t/** Whether the record was created (true) or updated (false) */\n\tcreated: boolean;\n\t/** Whether the record already existed with the same value */\n\tunchanged: boolean;\n}\n\n// =============================================================================\n// MX values\n// =============================================================================\n\n/**\n * An MX record's value as every provider here reads and writes it — the zone\n * file's `<priority> <host>`, which is what Route53 and Hostinger take as is.\n * A provider whose API keeps the priority apart (GoDaddy) splits it with\n * {@link parseMxValue}.\n */\nexport function mxValue(priority: number, host: string): string {\n\treturn `${priority} ${host.trim().replace(/\\.$/, '')}`;\n}\n\n/** An MX value that is not `<priority> <host>`. */\nexport class MxValueInvalid extends EdgeError {\n\tconstructor(readonly value: string) {\n\t\tsuper(\n\t\t\t`'${value}' is not an MX record's value: it is written ` +\n\t\t\t\t\"'<priority> <host>', like '10 inbound-smtp.eu-west-1.amazonaws.com'. \" +\n\t\t\t\t'Build it with mxValue(priority, host).',\n\t\t);\n\t\tthis.name = 'MxValueInvalid';\n\t}\n}\n\n/**\n * The priority and host of an MX value.\n *\n * @throws {MxValueInvalid} for a value that is not `<priority> <host>`\n */\nexport function parseMxValue(value: string): {\n\tpriority: number;\n\thost: string;\n} {\n\tconst match = value.trim().match(/^(\\d{1,5})\\s+(\\S+)$/);\n\tconst priority = match ? Number(match[1]) : Number.NaN;\n\tif (!match || priority > 65535) throw new MxValueInvalid(value);\n\treturn { priority, host: match[2]!.replace(/\\.$/, '') };\n}\n\n// =============================================================================\n// DNS Provider Interface\n// =============================================================================\n\n/**\n * A record to delete from DNS.\n */\nexport interface DeleteDnsRecord {\n\t/** Record name/subdomain (e.g., 'api' or '@' for root) */\n\tname: string;\n\t/** Record type (A, CNAME, etc.) */\n\ttype: DnsRecordType;\n}\n\n/**\n * Result of a delete operation.\n */\nexport interface DeleteResult {\n\t/** The record that was requested for deletion */\n\trecord: DeleteDnsRecord;\n\t/** Whether the record was deleted */\n\tdeleted: boolean;\n\t/** Whether the record was not found (already deleted) */\n\tnotFound: boolean;\n\t/** Error message if deletion failed */\n\terror?: string;\n}\n\n/**\n * Interface for DNS providers.\n *\n * Implementations must handle:\n * - Getting all records for a domain\n * - Creating or updating records for a domain\n * - Deleting records from a domain\n */\nexport interface DnsProvider {\n\t/** Provider name for logging */\n\treadonly name: string;\n\n\t/**\n\t * Get all DNS records for a domain.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @returns Array of DNS records\n\t */\n\tgetRecords(domain: string): Promise<DnsRecord[]>;\n\n\t/**\n\t * The records of exactly these names and types, where the provider can\n\t * read them one at a time — cheaper than the whole zone on an API that\n\t * counts requests. Optional: without it, `getRecords` is filtered.\n\t * Throws {@link DnsRecordsUnreadable} when the credentials can only write.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param wanted - The names ('@' for the root) and types to read\n\t */\n\treadRecords?(\n\t\tdomain: string,\n\t\twanted: readonly DeleteDnsRecord[],\n\t): Promise<DnsRecord[]>;\n\n\t/**\n\t * Create or update DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to create or update\n\t * @returns Results of the upsert operations\n\t */\n\tupsertRecords(\n\t\tdomain: string,\n\t\trecords: UpsertDnsRecord[],\n\t): Promise<UpsertResult[]>;\n\n\t/**\n\t * Delete DNS records.\n\t *\n\t * @param domain - Root domain (e.g., 'example.com')\n\t * @param records - Records to delete\n\t * @returns Results of the delete operations\n\t */\n\tdeleteRecords(\n\t\tdomain: string,\n\t\trecords: DeleteDnsRecord[],\n\t): Promise<DeleteResult[]>;\n}\n\n/**\n * Check if value is a DnsProvider implementation.\n */\nexport function isDnsProvider(value: unknown): value is DnsProvider {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof (value as DnsProvider).name === 'string' &&\n\t\ttypeof (value as DnsProvider).getRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).upsertRecords === 'function' &&\n\t\ttypeof (value as DnsProvider).deleteRecords === 'function'\n\t);\n}\n\n/**\n * The provider's credentials can write records and not read them — a key\n * scoped to updates only. What reads them falls back to writing every record,\n * which is idempotent, without a diff.\n */\nexport class DnsRecordsUnreadable extends EdgeError {\n\tconstructor(\n\t\treadonly provider: string,\n\t\treadonly domain: string,\n\t\treadonly reason: string,\n\t) {\n\t\tsuper(\n\t\t\t`The ${provider} key cannot read ${domain}'s DNS records (${reason}), so ` +\n\t\t\t\t'changes cannot be compared with what is there: every record is ' +\n\t\t\t\t'written, which leaves one that already has its value as it was.',\n\t\t);\n\t\tthis.name = 'DnsRecordsUnreadable';\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,QAAQ,UAAkB,MAAsB;CAC/D,OAAO,GAAG,SAAS,GAAG,KAAK,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;AACpD;;AAGA,IAAa,iBAAb,cAAoC,UAAU;CACxB;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,yJAGX;EALoB,KAAA,QAAA;EAMpB,KAAK,OAAO;CACb;AACD;;;;;;AAOA,SAAgB,aAAa,OAG3B;CACD,MAAM,QAAQ,MAAM,KAAK,CAAC,CAAC,MAAM,qBAAqB;CACtD,MAAM,WAAW,QAAQ,OAAO,MAAM,EAAE,IAAI;CAC5C,IAAI,CAAC,SAAS,WAAW,OAAO,MAAM,IAAI,eAAe,KAAK;CAC9D,OAAO;EAAE;EAAU,MAAM,MAAM,EAAE,CAAE,QAAQ,OAAO,EAAE;CAAE;AACvD;;;;AA4FA,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAsB,SAAS,YACvC,OAAQ,MAAsB,eAAe,cAC7C,OAAQ,MAAsB,kBAAkB,cAChD,OAAQ,MAAsB,kBAAkB;AAElD;;;;;;AAOA,IAAa,uBAAb,cAA0C,UAAU;CAEzC;CACA;CACA;CAHV,YACC,UACA,QACA,QACC;EACD,MACC,OAAO,SAAS,mBAAmB,OAAO,kBAAkB,OAAO,qIAGpE;EARS,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;EAOT,KAAK,OAAO;CACb;AACD"}
@@ -59,7 +59,8 @@ interface AcmeDnsChallenge {
59
59
  environment?: Readonly<Record<string, string>>;
60
60
  }
61
61
  /**
62
- * Every DNS provider the edge can get a wildcard certificate through, by the
62
+ * Every DNS provider the edge can get a certificate through over the DNS
63
+ * challenge — a wildcard's, or a host a CDN answers — by the
63
64
  * name a workspace's `dns` entry gives it. Another provider is one entry
64
65
  * here — lego's code for it and the variables it reads — and nothing else:
65
66
  * its resolver, its ACME storage and its edge environment follow from it.
@@ -81,6 +82,10 @@ declare const ACME_DNS_CHALLENGES: {
81
82
  readonly provider: 'godaddy';
82
83
  readonly secrets: readonly ["GODADDY_API_KEY", "GODADDY_API_SECRET"];
83
84
  };
85
+ readonly cloudflare: {
86
+ readonly provider: 'cloudflare';
87
+ readonly secrets: readonly ["CF_DNS_API_TOKEN"];
88
+ };
84
89
  };
85
90
  /** A DNS provider the edge answers the DNS challenge through. */
86
91
  type AcmeDnsProvider = keyof typeof ACME_DNS_CHALLENGES;
@@ -111,6 +116,14 @@ declare function edgeCertificatePaths(project: string): {
111
116
  certFile: string;
112
117
  keyFile: string;
113
118
  };
119
+ /**
120
+ * A stack's origin certificate — the one its CDN issued, served for the
121
+ * hosts the CDN answers — as the edge's container reads it.
122
+ */
123
+ declare function edgeOriginCertificatePaths(project: string): {
124
+ certFile: string;
125
+ keyFile: string;
126
+ };
114
127
  /** The edge's ports on the host. */
115
128
  interface EdgePorts {
116
129
  https: number;
@@ -317,7 +330,28 @@ interface EdgeRoute {
317
330
  * certificate is had. Named hosts always win over it.
318
331
  */
319
332
  wildcard?: EdgeWildcard;
333
+ /**
334
+ * Where its hosts' certificate comes from when it is not the stack's —
335
+ * for a route a CDN answers, whose hosts resolve to the CDN and not to
336
+ * this edge, so Let's Encrypt's HTTP request never reliably reaches it:
337
+ *
338
+ * - `files`: a certificate and key as the proxy reads them — one the CDN
339
+ * issued for its origin (Cloudflare's Origin CA), trusted by the CDN
340
+ * alone, so served for this route's hosts and nobody else's;
341
+ * - `dns`: Let's Encrypt over the DNS challenge, through this DNS
342
+ * provider. Rendered by Traefik; Caddy is never handed one.
343
+ */
344
+ certificate?: EdgeRouteCertificate;
320
345
  }
346
+ /** A route's own certificate — see {@link EdgeRoute.certificate}. */
347
+ type EdgeRouteCertificate = {
348
+ kind: 'files';
349
+ certFile: string;
350
+ keyFile: string;
351
+ } | {
352
+ kind: 'dns';
353
+ provider: AcmeDnsProvider;
354
+ };
321
355
  /**
322
356
  * Every host a route answers on — its own, its aliases and its redirects —
323
357
  * in that order: what DNS, certificates and the edge's claims cover.
@@ -423,5 +457,5 @@ declare const EDGE_LIMITS: {
423
457
  /** The proxies a stack can be served by — `deploy.compose.proxy`. */
424
458
  type ComposeProxy = 'caddy' | 'traefik';
425
459
  //#endregion
426
- export { EdgeClaim as A, edgeComposeFile as B, EDGE_AWS_CREDENTIALS as C, EDGE_PROJECT as D, EDGE_NETWORK as E, claimsOverlap as F, traefikDynamic as G, edgeProject as H, edgeAlias as I, traefikStaticFile as J, traefikDynamicFile as K, edgeCertificatePaths as L, TRAEFIK_IMAGE as M, TraefikStackOptions as N, EDGE_PROJECT_ENV as O, acmeDnsResolver as P, edgeClaims as R, DEFAULT_EDGE_PROJECT as S, EDGE_DYNAMIC_DIR as T, isAcmeDnsProvider as U, edgeDnsSecretPath as V, readEdgeClaims as W, ACME_DNS_RESOLVER as _, EdgeRouteConflict as a, AcmeDnsChallenge as b, HOST_GATEWAY as c, ServiceUpstream as d, Upstream as f, ACME_DNS_CHALLENGES as g, upstreamAddress as h, EdgeRoute as i, EdgePorts as j, EDGE_SERVICE as k, HostUpstream as l, routeHosts as m, EDGE_LIMITS as n, EdgeTls as o, assertRouteRenderable as p, traefikStatic as q, EdgeHandler as r, EdgeWildcard as s, ComposeProxy as t, NOFILE as u, ACME_DNS_SECRET_KEYS as v, EDGE_CERTS_DIR as w, AcmeDnsProvider as x, ACME_RESOLVER as y, edgeCompose as z };
427
- //# sourceMappingURL=index-BVE0VFku.d.cts.map
460
+ export { EDGE_SERVICE as A, edgeCompose as B, DEFAULT_EDGE_PROJECT as C, EDGE_NETWORK as D, EDGE_DYNAMIC_DIR as E, acmeDnsResolver as F, isAcmeDnsProvider as G, edgeDnsSecretPath as H, claimsOverlap as I, traefikDynamicFile as J, readEdgeClaims as K, edgeAlias as L, EdgePorts as M, TRAEFIK_IMAGE as N, EDGE_PROJECT as O, TraefikStackOptions as P, edgeCertificatePaths as R, AcmeDnsProvider as S, EDGE_CERTS_DIR as T, edgeOriginCertificatePaths as U, edgeComposeFile as V, edgeProject as W, traefikStaticFile as X, traefikStatic as Y, ACME_DNS_CHALLENGES as _, EdgeRouteCertificate as a, ACME_RESOLVER as b, EdgeWildcard as c, NOFILE as d, ServiceUpstream as f, upstreamAddress as g, routeHosts as h, EdgeRoute as i, EdgeClaim as j, EDGE_PROJECT_ENV as k, HOST_GATEWAY as l, assertRouteRenderable as m, EDGE_LIMITS as n, EdgeRouteConflict as o, Upstream as p, traefikDynamic as q, EdgeHandler as r, EdgeTls as s, ComposeProxy as t, HostUpstream as u, ACME_DNS_RESOLVER as v, EDGE_AWS_CREDENTIALS as w, AcmeDnsChallenge as x, ACME_DNS_SECRET_KEYS as y, edgeClaims as z };
461
+ //# sourceMappingURL=index-BhrEC4ux.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BhrEC4ux.d.cts","names":[],"sources":["../src/proxy/traefik.ts","../src/routes/index.ts"],"mappings":";;;;;cAwCa;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vB;IAAW;IAA8B;;;EAEzC;;;;;;EAMA,WAAW;;;;;;;;;;;;EAYX,cAAc;;;KAIH;EACP;EAAe;EAAkB;;EACjC;EAAa,UAAU;;;;;;iBAMZ,WAAW,OAAO;;UASjB;;EAEhB;;;;;;EAMA;;;;;;;;;;EAUA;IACK;;IACA;IAAa,UAAU;;IACvB;IAAmB;;;;;;;;;;;EAUxB;IAAU,UAAU;IAAU;;;;UAId;;EAEhB;;EAEA;EACA,oBAAoB;;;;;;EAMpB;;;cAIY,0BAA0B;WACjB;EAArB,YAAqB;;;iBAWN,sBAAsB,OAAO;;KAUjC;;;EAEP;;;;;;;;EAMA;EAAe;EAAkB;;;cAGzB;EAAW;EAAiB;;;;;;;;cAQ5B;EACZ,SAAS;EACT,SAAS;IAAiB;IAAc;;;;KAO7B"}
@@ -59,7 +59,8 @@ interface AcmeDnsChallenge {
59
59
  environment?: Readonly<Record<string, string>>;
60
60
  }
61
61
  /**
62
- * Every DNS provider the edge can get a wildcard certificate through, by the
62
+ * Every DNS provider the edge can get a certificate through over the DNS
63
+ * challenge — a wildcard's, or a host a CDN answers — by the
63
64
  * name a workspace's `dns` entry gives it. Another provider is one entry
64
65
  * here — lego's code for it and the variables it reads — and nothing else:
65
66
  * its resolver, its ACME storage and its edge environment follow from it.
@@ -81,6 +82,10 @@ declare const ACME_DNS_CHALLENGES: {
81
82
  readonly provider: 'godaddy';
82
83
  readonly secrets: readonly ["GODADDY_API_KEY", "GODADDY_API_SECRET"];
83
84
  };
85
+ readonly cloudflare: {
86
+ readonly provider: 'cloudflare';
87
+ readonly secrets: readonly ["CF_DNS_API_TOKEN"];
88
+ };
84
89
  };
85
90
  /** A DNS provider the edge answers the DNS challenge through. */
86
91
  type AcmeDnsProvider = keyof typeof ACME_DNS_CHALLENGES;
@@ -111,6 +116,14 @@ declare function edgeCertificatePaths(project: string): {
111
116
  certFile: string;
112
117
  keyFile: string;
113
118
  };
119
+ /**
120
+ * A stack's origin certificate — the one its CDN issued, served for the
121
+ * hosts the CDN answers — as the edge's container reads it.
122
+ */
123
+ declare function edgeOriginCertificatePaths(project: string): {
124
+ certFile: string;
125
+ keyFile: string;
126
+ };
114
127
  /** The edge's ports on the host. */
115
128
  interface EdgePorts {
116
129
  https: number;
@@ -317,7 +330,28 @@ interface EdgeRoute {
317
330
  * certificate is had. Named hosts always win over it.
318
331
  */
319
332
  wildcard?: EdgeWildcard;
333
+ /**
334
+ * Where its hosts' certificate comes from when it is not the stack's —
335
+ * for a route a CDN answers, whose hosts resolve to the CDN and not to
336
+ * this edge, so Let's Encrypt's HTTP request never reliably reaches it:
337
+ *
338
+ * - `files`: a certificate and key as the proxy reads them — one the CDN
339
+ * issued for its origin (Cloudflare's Origin CA), trusted by the CDN
340
+ * alone, so served for this route's hosts and nobody else's;
341
+ * - `dns`: Let's Encrypt over the DNS challenge, through this DNS
342
+ * provider. Rendered by Traefik; Caddy is never handed one.
343
+ */
344
+ certificate?: EdgeRouteCertificate;
320
345
  }
346
+ /** A route's own certificate — see {@link EdgeRoute.certificate}. */
347
+ type EdgeRouteCertificate = {
348
+ kind: 'files';
349
+ certFile: string;
350
+ keyFile: string;
351
+ } | {
352
+ kind: 'dns';
353
+ provider: AcmeDnsProvider;
354
+ };
321
355
  /**
322
356
  * Every host a route answers on — its own, its aliases and its redirects —
323
357
  * in that order: what DNS, certificates and the edge's claims cover.
@@ -423,5 +457,5 @@ declare const EDGE_LIMITS: {
423
457
  /** The proxies a stack can be served by — `deploy.compose.proxy`. */
424
458
  type ComposeProxy = 'caddy' | 'traefik';
425
459
  //#endregion
426
- export { EdgeClaim as A, edgeComposeFile as B, EDGE_AWS_CREDENTIALS as C, EDGE_PROJECT as D, EDGE_NETWORK as E, claimsOverlap as F, traefikDynamic as G, edgeProject as H, edgeAlias as I, traefikStaticFile as J, traefikDynamicFile as K, edgeCertificatePaths as L, TRAEFIK_IMAGE as M, TraefikStackOptions as N, EDGE_PROJECT_ENV as O, acmeDnsResolver as P, edgeClaims as R, DEFAULT_EDGE_PROJECT as S, EDGE_DYNAMIC_DIR as T, isAcmeDnsProvider as U, edgeDnsSecretPath as V, readEdgeClaims as W, ACME_DNS_RESOLVER as _, EdgeRouteConflict as a, AcmeDnsChallenge as b, HOST_GATEWAY as c, ServiceUpstream as d, Upstream as f, ACME_DNS_CHALLENGES as g, upstreamAddress as h, EdgeRoute as i, EdgePorts as j, EDGE_SERVICE as k, HostUpstream as l, routeHosts as m, EDGE_LIMITS as n, EdgeTls as o, assertRouteRenderable as p, traefikStatic as q, EdgeHandler as r, EdgeWildcard as s, ComposeProxy as t, NOFILE as u, ACME_DNS_SECRET_KEYS as v, EDGE_CERTS_DIR as w, AcmeDnsProvider as x, ACME_RESOLVER as y, edgeCompose as z };
427
- //# sourceMappingURL=index-BVE0VFku.d.mts.map
460
+ export { EDGE_SERVICE as A, edgeCompose as B, DEFAULT_EDGE_PROJECT as C, EDGE_NETWORK as D, EDGE_DYNAMIC_DIR as E, acmeDnsResolver as F, isAcmeDnsProvider as G, edgeDnsSecretPath as H, claimsOverlap as I, traefikDynamicFile as J, readEdgeClaims as K, edgeAlias as L, EdgePorts as M, TRAEFIK_IMAGE as N, EDGE_PROJECT as O, TraefikStackOptions as P, edgeCertificatePaths as R, AcmeDnsProvider as S, EDGE_CERTS_DIR as T, edgeOriginCertificatePaths as U, edgeComposeFile as V, edgeProject as W, traefikStaticFile as X, traefikStatic as Y, ACME_DNS_CHALLENGES as _, EdgeRouteCertificate as a, ACME_RESOLVER as b, EdgeWildcard as c, NOFILE as d, ServiceUpstream as f, upstreamAddress as g, routeHosts as h, EdgeRoute as i, EdgeClaim as j, EDGE_PROJECT_ENV as k, HOST_GATEWAY as l, assertRouteRenderable as m, EDGE_LIMITS as n, EdgeRouteConflict as o, Upstream as p, traefikDynamic as q, EdgeHandler as r, EdgeTls as s, ComposeProxy as t, HostUpstream as u, ACME_DNS_RESOLVER as v, EDGE_AWS_CREDENTIALS as w, AcmeDnsChallenge as x, ACME_DNS_SECRET_KEYS as y, edgeClaims as z };
461
+ //# sourceMappingURL=index-BhrEC4ux.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BhrEC4ux.d.mts","names":[],"sources":["../src/proxy/traefik.ts","../src/routes/index.ts"],"mappings":";;;;;cAwCa;;cAGA;;;;;;;;cASA;;iBAGG,YAAY,MAAK,OAAO;;;;;cAQ3B;;;;;cAMA;;cAGA;;cAGA;cACA;;cAGA;;;;;;;cAQA;;;;;UAMI;;EAEhB;;;;;;;;EAQA;;EAEA,cAAc,SAAS;;;;;;;;;;;;;cAcX;;aAEX;aACA;aACA;eACC;eACA;;;;aAID;aACA;;;aAIA;aACA;;;;KAKU,+BAA+B;;iBAG3B,kBACf,oBACE,YAAY;;cAOF;;;;;;;;;iBAUG,gBAAgB,UAAU;;;;;iBAiB1B,kBAAkB;;cAKrB;;iBAyBG,UAAU,iBAAiB;;iBAK3B,qBAAqB;EACpC;EACA;;;;;;iBAYe,2BAA2B;EAC1C;EACA;;;UASgB;EAChB;EACA;;;;;;;iBAQe,cAAc,OAAO,YAAY;;iBA4DjC,YAAY;EAC3B,OAAO;;;;;;EAMP;EACA;IAAW;IAAgB,SAAS;;IACjC;;UAsDa;EAChB;;EAEA,KAAK;;;;;EAKL;;;iBAIe,eACf,iBAAiB,aACjB,SAAS,sBACP;;;;;KA0QS;EACP;;EACA;EAAkB;;;;;;iBAMP,WAAW,iBAAiB,cAAc;;;;;;iBAyB1C,eAAe,eAAe;;;;;;;iBAqE9B,cAAc,GAAG,WAAW,GAAG;;iBAqB/B,mBACf,iBAAiB,aACjB,SAAS;;iBAWM,kBAAkB,OAAO;;iBAMzB,gBACf,SAAS,kBAAkB;;;;KChxBhB,WAAW,kBAAkB;;UAGxB;;EAEhB;;EAEA;;;;;;;UAQgB;EAChB;;EAEA;;;;;;;cAQY;;iBAGG,gBACf,UAAU,UAEV;;AAAA,WAAU;;UAQM;;;;;EAKhB;;EAEA;;;;;EAKA;;;;;;EAMA;IAAc;IAA0B;;;;;;EAKxC,oBAAoB;;;;;EAKpB;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;EAMA;IAAkB;IAAc;;;;;;;;;EAQhC,oBAAoB;;;;;;EAMpB;IAAS;IAAc;;;;;;;;EAOvB;IAAW;IAA8B;;;EAEzC;;;;;;EAMA,WAAW;;;;;;;;;;;;EAYX,cAAc;;;KAIH;EACP;EAAe;EAAkB;;EACjC;EAAa,UAAU;;;;;;iBAMZ,WAAW,OAAO;;UASjB;;EAEhB;;;;;;EAMA;;;;;;;;;;EAUA;IACK;;IACA;IAAa,UAAU;;IACvB;IAAmB;;;;;;;;;;;EAUxB;IAAU,UAAU;IAAU;;;;UAId;;EAEhB;;EAEA;EACA,oBAAoB;;;;;;EAMpB;;;cAIY,0BAA0B;WACjB;EAArB,YAAqB;;;iBAWN,sBAAsB,OAAO;;KAUjC;;;EAEP;;;;;;;;EAMA;EAAe;EAAkB;;;cAGzB;EAAW;EAAiB;;;;;;;;cAQ5B;EACZ,SAAS;EACT,SAAS;IAAiB;IAAc;;;;KAO7B"}
@@ -17,6 +17,11 @@ let _geekmidas_manifest = require("@geekmidas/manifest");
17
17
  */
18
18
  /** Where Caddy reads a stage's own certificate, inside its container. */
19
19
  const CADDY_TLS_DIR = "/etc/caddy/tls";
20
+ /** The origin certificate a CDN issued, as the stack's Caddy reads it. */
21
+ const CADDY_ORIGIN_CERTIFICATE = {
22
+ certFile: `${CADDY_TLS_DIR}/origin-cert.pem`,
23
+ keyFile: `${CADDY_TLS_DIR}/origin-key.pem`
24
+ };
20
25
  /** An upstream on the stack's own network — its service name — or on the host. */
21
26
  function address(upstream) {
22
27
  return require_routes_index.upstreamAddress(upstream);
@@ -38,6 +43,8 @@ function edgeCaddyfile(routes, options) {
38
43
  tls {
39
44
  on_demand
40
45
  }
46
+ ` : route.certificate?.kind === "files" ? `
47
+ tls ${route.certificate.certFile} ${route.certificate.keyFile}
41
48
  ` : certificate));
42
49
  return `${HEADER}${global ? `${global}\n\n` : ""}${blocks.join("\n\n")}\n`;
43
50
  }
@@ -162,6 +169,7 @@ function clientIpRule(edgeToken) {
162
169
  request_header @gkm_outside -${_geekmidas_manifest.CLIENT_IP_HEADER}`;
163
170
  }
164
171
  //#endregion
172
+ exports.CADDY_ORIGIN_CERTIFICATE = CADDY_ORIGIN_CERTIFICATE;
165
173
  exports.CADDY_TLS_DIR = CADDY_TLS_DIR;
166
174
  exports.clientIpRule = clientIpRule;
167
175
  exports.edgeCaddyfile = edgeCaddyfile;
@@ -1 +1 @@
1
- {"version":3,"file":"caddy.cjs","names":["upstreamAddress","CLIENT_IP_HEADER","EDGE_TOKEN_HEADER"],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n\tupstreamAddress,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network — its service name — or on the host. */\nfunction address(upstream: Upstream): string {\n\treturn upstreamAddress(upstream);\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}${\n\t\t\thandler.under\n\t\t\t\t? ` {\n\t\t\trewrite ${handler.under}{uri}\n\t\t}`\n\t\t\t\t: ''\n\t\t}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_header @gkm_outside -${CLIENT_IP_HEADER}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,MAAa,gBAAgB;;AAmB7B,SAAS,QAAQ,UAA4B;CAC5C,OAAOA,qBAAAA,gBAAgB,QAAQ;AAChC;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW,CAAC,EACzE,UAAU;CACb,MAAM,WACL,KAAK,SAAS,cACX;;QAEG,IA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;;;;2BAImBC,oBAAAA,kBAAkB,GAAG,UAAU;gCAC1BD,oBAAAA;AAChC"}
1
+ {"version":3,"file":"caddy.cjs","names":["upstreamAddress","CLIENT_IP_HEADER","EDGE_TOKEN_HEADER"],"sources":["../../src/proxy/caddy.ts"],"sourcesContent":["/**\n * The stack's own edge, rendered for Caddy: one site block per route.\n *\n * Deployed, each host is the stage's real domain and Caddy gets it a\n * certificate from Let's Encrypt on first request — the same automatic HTTPS\n * it does anywhere, with nothing to configure but the name — or serves the\n * stage's own certificate (`deploy.compose.tls`). Locally the hosts are\n * `*.localhost` and the certificate is the one gkm's local authority issued,\n * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed\n * one.\n *\n * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.\n */\n\nimport { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from '@geekmidas/manifest';\nimport {\n\tassertRouteRenderable,\n\ttype EdgeRoute,\n\ttype EdgeTls,\n\ttype Upstream,\n\tupstreamAddress,\n} from '../routes';\n\n/** Where Caddy reads a stage's own certificate, inside its container. */\nexport const CADDY_TLS_DIR = '/etc/caddy/tls';\n\n/** The origin certificate a CDN issued, as the stack's Caddy reads it. */\nexport const CADDY_ORIGIN_CERTIFICATE = {\n\tcertFile: `${CADDY_TLS_DIR}/origin-cert.pem`,\n\tkeyFile: `${CADDY_TLS_DIR}/origin-key.pem`,\n} as const;\n\nexport interface CaddyfileOptions {\n\ttls: EdgeTls;\n\t/**\n\t * The stack's token, on which a service of the stack keeps gkm's client\n\t * address through the edge — see `clientIpRule`.\n\t */\n\tedgeToken?: string;\n\t/** Where ACME sends expiry notices, when someone wants them. */\n\temail?: string;\n\t/**\n\t * `false` on the local stage: plain HTTP is not sent to HTTPS, whose\n\t * published port there may not be 443.\n\t */\n\tredirects?: boolean;\n}\n\n/** An upstream on the stack's own network — its service name — or on the host. */\nfunction address(upstream: Upstream): string {\n\treturn upstreamAddress(upstream);\n}\n\n/** The Caddyfile for a stack's edge. */\nexport function edgeCaddyfile(\n\troutes: readonly EdgeRoute[],\n\toptions: CaddyfileOptions,\n): string {\n\tconst { tls } = options;\n\t// A wildcard site certified host by host: Caddy asks its `hosts` route\n\t// before it gets a certificate for one, so a name no tenant has is never\n\t// sent to Let's Encrypt.\n\tconst ask = routes.find((route) => route.wildcard?.tls.kind === 'on-demand')\n\t\t?.wildcard?.tls;\n\tconst onDemand =\n\t\task?.kind === 'on-demand'\n\t\t\t? `\n\ton_demand_tls {\n\t\task ${ask.ask}\n\t}`\n\t\t\t: '';\n\tconst settings = `${options.email ? `\\n\\temail ${options.email}` : ''}${\n\t\toptions.redirects === false ? '\\n\\tauto_https disable_redirects' : ''\n\t}${onDemand}`;\n\tconst global = settings ? `{${settings}\\n}` : '';\n\n\tconst certificate =\n\t\ttls.kind === 'files'\n\t\t\t? `\n\ttls ${tls.certFile} ${tls.keyFile}\n`\n\t\t\t: '';\n\n\t// The wildcard site last: Caddy prefers a named host to `*.<domain>`\n\t// wherever the blocks are, and reading it last says the same.\n\tconst blocks = [\n\t\t...routes.filter((route) => !route.wildcard),\n\t\t...routes.filter((route) => route.wildcard),\n\t].map((route) =>\n\t\tsiteBlock(\n\t\t\troute,\n\t\t\toptions.edgeToken,\n\t\t\troute.wildcard?.tls.kind === 'on-demand'\n\t\t\t\t? `\n\ttls {\n\t\ton_demand\n\t}\n`\n\t\t\t\t: route.certificate?.kind === 'files'\n\t\t\t\t\t? `\n\ttls ${route.certificate.certFile} ${route.certificate.keyFile}\n`\n\t\t\t\t\t: certificate,\n\t\t),\n\t);\n\n\t// No blank line under the header: `caddy fmt` wants the first block there.\n\treturn `${HEADER}${global ? `${global}\\n\\n` : ''}${blocks.join('\\n\\n')}\\n`;\n}\n\n/** One route's site block. */\nfunction siteBlock(\n\troute: EdgeRoute,\n\tedgeToken: string | undefined,\n\tcertificate: string,\n): string {\n\tassertRouteRenderable(route);\n\tconst { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;\n\tconst allowed = [\n\t\t...(paths ?? []),\n\t\t...(prefixes ?? []).map((prefix) => `${prefix}*`),\n\t];\n\n\tconst except = route.wildcard?.except ?? [];\n\tconst checks = `${\n\t\texcept.length\n\t\t\t? `\n\t# Labels no tenant may take, although nothing in this stack answers them.\n\t@protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(' ')}\n\trespond @protected 404\n`\n\t\t\t: ''\n\t}${\n\t\tallow\n\t\t\t? `\n\t# Only these addresses — the peer Caddy sees, never a header a client\n\t# could set. Everything else is refused before it reaches the upstream.\n\t@denied not remote_ip ${allow.join(' ')}\n\trespond @denied 403\n`\n\t\t\t: ''\n\t}${\n\t\trequireHeader\n\t\t\t? `\n\t# Only what the CDN sends: it adds this header to every request, and this\n\t# host would be reached around the CDN otherwise.\n\t@forged not header ${requireHeader.name} \"${requireHeader.value}\"\n\trespond @forged 403\n`\n\t\t\t: ''\n\t}${\n\t\tauth\n\t\t\t? `\n\t# The stage's login, asked for before anything reaches the upstream.\n\tbasic_auth {\n\t\t${auth.user} ${auth.hash}\n\t}\n`\n\t\t\t: ''\n\t}${\n\t\tallowed.length\n\t\t\t? `\n\t# Only these paths answer. Everything else on this host is refused before\n\t# it reaches the upstream.\n\t@elsewhere not path ${allowed.join(' ')}\n\trespond @elsewhere 404\n`\n\t\t\t: ''\n\t}`;\n\n\tconst proxy = proxyBlock(route);\n\tconst body = handlers?.length\n\t\t? `${handlers\n\t\t\t\t.map(\n\t\t\t\t\t(handler, index) => `\n\t# Answered by another service: ${handler.name}.\n\t@handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(' ')}\n\thandle @handler${index} {\n\t\treverse_proxy ${handler.upstreams.map(address).join(' ')}${\n\t\t\thandler.under\n\t\t\t\t? ` {\n\t\t\trewrite ${handler.under}{uri}\n\t\t}`\n\t\t\t\t: ''\n\t\t}\n\t}\n`,\n\t\t\t\t)\n\t\t\t\t.join('')}\n\thandle {${proxy.replace(/\\n/g, '\\n\\t')}\n\t}`\n\t\t: proxy;\n\n\t// Its aliases join the block: every check and handler holds on each.\n\tconst names = [host, ...(route.aliases ?? [])]\n\t\t.map((name) => `https://${name}`)\n\t\t.join(', ');\n\t// Each redirect host, a block of its own that sends the browser to the\n\t// canonical host, path and query kept, and proxies nothing.\n\tconst redirects = (route.redirects?.hosts ?? [])\n\t\t.map(\n\t\t\t(from) => `\n\nhttps://${from} {${certificate}\n\tredir ${route.redirects?.to}{uri} permanent\n}`,\n\t\t)\n\t\t.join('');\n\n\treturn `${names} {${certificate}${clientIpRule(edgeToken)}\n${checks}${body}\n}${redirects}`;\n}\n\n/** Where a route's requests go, when no handler took them. */\nfunction proxyBlock(route: EdgeRoute): string {\n\tconst { upstreams, prefix, streaming } = route;\n\tconst health = healthCheck(route);\n\treturn prefix\n\t\t? `\n\t# A bucket, served at a host of its own: the bucket is a prefix on MinIO,\n\t# which routes and signs on the Host header — so it is sent the upstream's.\n\treverse_proxy ${upstreams.map(address).join(' ')} {\n\t\trewrite ${prefix}{uri}\n\t\theader_up Host {upstream_hostport}${health}\n\t}`\n\t\t: `\n\t# Host and X-Forwarded-* are passed through as Caddy does by default, so\n\t# an app builds redirects, cookies and links on the address a caller used.\n\treverse_proxy ${upstreams.map(address).join(' ')}${\n\t\tstreaming || health\n\t\t\t? ` {${\n\t\t\t\t\tstreaming\n\t\t\t\t\t\t? `\n\t\t# Never buffer: a streamed response — server-sent events, a Next.js\n\t\t# RSC payload — reaches the client as each chunk is written.\n\t\tflush_interval -1`\n\t\t\t\t\t\t: ''\n\t\t\t\t}${health}\n\t}`\n\t\t\t: ''\n\t}`;\n}\n\n/**\n * Caddy's own check of each upstream, as the Traefik edge's\n * `loadBalancer.healthCheck`: one that stops answering is taken out of\n * rotation until it does again. Caddy starts once its apps have — not once\n * they are healthy — so this is what keeps a request from an upstream that\n * is not up, and a route to an app with none up answers an error (503)\n * rather than going missing.\n */\nfunction healthCheck({ health }: EdgeRoute): string {\n\treturn health\n\t\t? `\n\t\t# Each upstream asked on its own: one that stops answering is out of\n\t\t# rotation until it answers again.\n\t\thealth_uri ${health}\n\t\thealth_interval 5s\n\t\thealth_timeout 3s`\n\t\t: '';\n}\n\nconst HEADER = `# Generated by gkm compose from the construct manifest — do not edit.\n#\n# One host per API and site, each in front of its own container, one per\n# file server in front of the stack's MinIO — its processors' paths sent to\n# their own service — one per worker SNS pushes to and per processor unit a\n# CDN reaches, answering only those paths, and — when its logs are served\n# publicly — one for OpenObserve, to the addresses it allows. A site the\n# stage puts behind a password asks for its login first.\n`;\n\n/**\n * The lines every site block of an edge opens with, for gkm's own\n * `x-gkm-client-ip` — the client address the auth server rate-limits by.\n *\n * Only a service of this stack may send it. One that calls a sibling at its\n * public address comes through this edge, and proves where it comes from with\n * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and\n * handed to every process of the stack — never to a browser. A request\n * without it has the header removed, so nobody outside can choose the address\n * they are rate-limited by. Without a token, it is removed from every request.\n */\nexport function clientIpRule(edgeToken: string | undefined): string {\n\tif (!edgeToken) {\n\t\treturn `\n\t# gkm's own header, which only a service of this stack may send: the auth\n\t# server rate-limits by the client address it carries.\n\trequest_header -${CLIENT_IP_HEADER}`;\n\t}\n\treturn `\n\t# gkm's own header, which only a service of this stack may send — proven by\n\t# the stack's token: the auth server rate-limits by the client address it\n\t# carries. Removed from every other request.\n\t@gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}\n\trequest_header @gkm_outside -${CLIENT_IP_HEADER}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,MAAa,gBAAgB;;AAG7B,MAAa,2BAA2B;CACvC,UAAU,GAAG,cAAc;CAC3B,SAAS,GAAG,cAAc;AAC3B;;AAmBA,SAAS,QAAQ,UAA4B;CAC5C,OAAOA,qBAAAA,gBAAgB,QAAQ;AAChC;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW,CA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;AACJ;AAEA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;AAqBf,SAAgB,aAAa,WAAuC;CACnE,IAAI,CAAC,WACJ,OAAO;;;mBAGUC,oBAAAA;CAElB,OAAO;;;;2BAImBC,oBAAAA,kBAAkB,GAAG,UAAU;gCAC1BD,oBAAAA;AAChC"}
@@ -1,7 +1,12 @@
1
- import { i as EdgeRoute, o as EdgeTls } from "../index-BVE0VFku.cjs";
1
+ import { i as EdgeRoute, s as EdgeTls } from "../index-BhrEC4ux.cjs";
2
2
  //#region src/proxy/caddy.d.ts
3
3
  /** Where Caddy reads a stage's own certificate, inside its container. */
4
4
  export declare const CADDY_TLS_DIR = "/etc/caddy/tls";
5
+ /** The origin certificate a CDN issued, as the stack's Caddy reads it. */
6
+ export declare const CADDY_ORIGIN_CERTIFICATE: {
7
+ readonly certFile: "/etc/caddy/tls/origin-cert.pem";
8
+ readonly keyFile: "/etc/caddy/tls/origin-key.pem";
9
+ };
5
10
  export interface CaddyfileOptions {
6
11
  tls: EdgeTls;
7
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"caddy.d.cts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAwBa;iBAEI;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBAgOM,aAAa"}
1
+ {"version":3,"file":"caddy.d.cts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAwBa;;qBAGA;WACZ;WACA;;iBAGgB;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBAoOM,aAAa"}
@@ -1,7 +1,12 @@
1
- import { i as EdgeRoute, o as EdgeTls } from "../index-BVE0VFku.mjs";
1
+ import { i as EdgeRoute, s as EdgeTls } from "../index-BhrEC4ux.mjs";
2
2
  //#region src/proxy/caddy.d.ts
3
3
  /** Where Caddy reads a stage's own certificate, inside its container. */
4
4
  export declare const CADDY_TLS_DIR = "/etc/caddy/tls";
5
+ /** The origin certificate a CDN issued, as the stack's Caddy reads it. */
6
+ export declare const CADDY_ORIGIN_CERTIFICATE: {
7
+ readonly certFile: "/etc/caddy/tls/origin-cert.pem";
8
+ readonly keyFile: "/etc/caddy/tls/origin-key.pem";
9
+ };
5
10
  export interface CaddyfileOptions {
6
11
  tls: EdgeTls;
7
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"caddy.d.mts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAwBa;iBAEI;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBAgOM,aAAa"}
1
+ {"version":3,"file":"caddy.d.mts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAwBa;;qBAGA;WACZ;WACA;;iBAGgB;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBAoOM,aAAa"}
@@ -16,6 +16,11 @@ import { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from "@geekmidas/manifest";
16
16
  */
17
17
  /** Where Caddy reads a stage's own certificate, inside its container. */
18
18
  const CADDY_TLS_DIR = "/etc/caddy/tls";
19
+ /** The origin certificate a CDN issued, as the stack's Caddy reads it. */
20
+ const CADDY_ORIGIN_CERTIFICATE = {
21
+ certFile: `${CADDY_TLS_DIR}/origin-cert.pem`,
22
+ keyFile: `${CADDY_TLS_DIR}/origin-key.pem`
23
+ };
19
24
  /** An upstream on the stack's own network — its service name — or on the host. */
20
25
  function address(upstream) {
21
26
  return upstreamAddress(upstream);
@@ -37,6 +42,8 @@ function edgeCaddyfile(routes, options) {
37
42
  tls {
38
43
  on_demand
39
44
  }
45
+ ` : route.certificate?.kind === "files" ? `
46
+ tls ${route.certificate.certFile} ${route.certificate.keyFile}
40
47
  ` : certificate));
41
48
  return `${HEADER}${global ? `${global}\n\n` : ""}${blocks.join("\n\n")}\n`;
42
49
  }
@@ -161,6 +168,6 @@ function clientIpRule(edgeToken) {
161
168
  request_header @gkm_outside -${CLIENT_IP_HEADER}`;
162
169
  }
163
170
  //#endregion
164
- export { CADDY_TLS_DIR, clientIpRule, edgeCaddyfile };
171
+ export { CADDY_ORIGIN_CERTIFICATE, CADDY_TLS_DIR, clientIpRule, edgeCaddyfile };
165
172
 
166
173
  //# sourceMappingURL=caddy.mjs.map