@geekmidas/edge 0.0.0-stage → 10.0.0-alpha.182

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 (84) hide show
  1. package/README.md +14 -2
  2. package/dist/certificates/local.cjs +393 -0
  3. package/dist/certificates/local.cjs.map +1 -0
  4. package/dist/certificates/local.d.cts +92 -0
  5. package/dist/certificates/local.d.cts.map +1 -0
  6. package/dist/certificates/local.d.mts +92 -0
  7. package/dist/certificates/local.d.mts.map +1 -0
  8. package/dist/certificates/local.mjs +361 -0
  9. package/dist/certificates/local.mjs.map +1 -0
  10. package/dist/compose-BHWyQvsD.cjs +22 -0
  11. package/dist/compose-BHWyQvsD.cjs.map +1 -0
  12. package/dist/compose-CcNlj65h.mjs +17 -0
  13. package/dist/compose-CcNlj65h.mjs.map +1 -0
  14. package/dist/dns/godaddy/index.cjs +448 -0
  15. package/dist/dns/godaddy/index.cjs.map +1 -0
  16. package/dist/dns/godaddy/index.d.cts +164 -0
  17. package/dist/dns/godaddy/index.d.cts.map +1 -0
  18. package/dist/dns/godaddy/index.d.mts +164 -0
  19. package/dist/dns/godaddy/index.d.mts.map +1 -0
  20. package/dist/dns/godaddy/index.mjs +435 -0
  21. package/dist/dns/godaddy/index.mjs.map +1 -0
  22. package/dist/dns/hostinger/index.cjs +252 -0
  23. package/dist/dns/hostinger/index.cjs.map +1 -0
  24. package/dist/dns/hostinger/index.d.cts +143 -0
  25. package/dist/dns/hostinger/index.d.cts.map +1 -0
  26. package/dist/dns/hostinger/index.d.mts +143 -0
  27. package/dist/dns/hostinger/index.d.mts.map +1 -0
  28. package/dist/dns/hostinger/index.mjs +249 -0
  29. package/dist/dns/hostinger/index.mjs.map +1 -0
  30. package/dist/dns/index.cjs +76 -0
  31. package/dist/dns/index.cjs.map +1 -0
  32. package/dist/dns/index.d.cts +144 -0
  33. package/dist/dns/index.d.cts.map +1 -0
  34. package/dist/dns/index.d.mts +144 -0
  35. package/dist/dns/index.d.mts.map +1 -0
  36. package/dist/dns/index.mjs +71 -0
  37. package/dist/dns/index.mjs.map +1 -0
  38. package/dist/dns/route53.cjs +210 -0
  39. package/dist/dns/route53.cjs.map +1 -0
  40. package/dist/dns/route53.d.cts +45 -0
  41. package/dist/dns/route53.d.cts.map +1 -0
  42. package/dist/dns/route53.d.mts +45 -0
  43. package/dist/dns/route53.d.mts.map +1 -0
  44. package/dist/dns/route53.mjs +209 -0
  45. package/dist/dns/route53.mjs.map +1 -0
  46. package/dist/errors-CO33_TDV.mjs +16 -0
  47. package/dist/errors-CO33_TDV.mjs.map +1 -0
  48. package/dist/errors-DBZfelEN.d.cts +13 -0
  49. package/dist/errors-DBZfelEN.d.cts.map +1 -0
  50. package/dist/errors-DBZfelEN.d.mts +13 -0
  51. package/dist/errors-DBZfelEN.d.mts.map +1 -0
  52. package/dist/errors-DlRLQOyZ.cjs +27 -0
  53. package/dist/errors-DlRLQOyZ.cjs.map +1 -0
  54. package/dist/index.cjs +6 -0
  55. package/dist/index.d.cts +15 -0
  56. package/dist/index.d.cts.map +1 -0
  57. package/dist/index.d.mts +15 -0
  58. package/dist/index.d.mts.map +1 -0
  59. package/dist/index.mjs +3 -0
  60. package/dist/proxy/caddy.cjs +167 -0
  61. package/dist/proxy/caddy.cjs.map +1 -0
  62. package/dist/proxy/caddy.d.cts +35 -0
  63. package/dist/proxy/caddy.d.cts.map +1 -0
  64. package/dist/proxy/caddy.d.mts +35 -0
  65. package/dist/proxy/caddy.d.mts.map +1 -0
  66. package/dist/proxy/caddy.mjs +164 -0
  67. package/dist/proxy/caddy.mjs.map +1 -0
  68. package/dist/proxy/traefik.cjs +460 -0
  69. package/dist/proxy/traefik.cjs.map +1 -0
  70. package/dist/proxy/traefik.d.cts +129 -0
  71. package/dist/proxy/traefik.d.cts.map +1 -0
  72. package/dist/proxy/traefik.d.mts +129 -0
  73. package/dist/proxy/traefik.d.mts.map +1 -0
  74. package/dist/proxy/traefik.mjs +437 -0
  75. package/dist/proxy/traefik.mjs.map +1 -0
  76. package/dist/routes/index.cjs +49 -0
  77. package/dist/routes/index.cjs.map +1 -0
  78. package/dist/routes/index.d.cts +205 -0
  79. package/dist/routes/index.d.cts.map +1 -0
  80. package/dist/routes/index.d.mts +205 -0
  81. package/dist/routes/index.d.mts.map +1 -0
  82. package/dist/routes/index.mjs +44 -0
  83. package/dist/routes/index.mjs.map +1 -0
  84. package/package.json +131 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route53.mjs","names":[],"sources":["../../src/dns/route53.ts"],"sourcesContent":["/**\n * Route53 DNS Provider\n *\n * Implements DnsProvider interface using AWS Route53.\n */\n\nimport {\n\tChangeResourceRecordSetsCommand,\n\tListHostedZonesByNameCommand,\n\tListResourceRecordSetsCommand,\n\tRoute53Client,\n\ttype RRType,\n} from '@aws-sdk/client-route-53';\nimport { fromIni } from '@aws-sdk/credential-providers';\nimport type {\n\tDeleteDnsRecord,\n\tDeleteResult,\n\tDnsProvider,\n\tDnsRecord,\n\tDnsRecordType,\n\tUpsertDnsRecord,\n\tUpsertResult,\n} from './index';\n\nexport interface Route53ProviderOptions {\n\t/** AWS region (optional - uses AWS_REGION env var if not provided) */\n\tregion?: string;\n\t/** AWS profile name (optional - uses default credential chain if not provided) */\n\tprofile?: string;\n\t/** Hosted zone ID (optional - auto-detected from domain if not provided) */\n\thostedZoneId?: string;\n\t/** Custom endpoint for testing with localstack */\n\tendpoint?: string;\n}\n\n/**\n * Route53 DNS provider implementation.\n *\n * Uses AWS default credential chain for authentication.\n * Region can be specified or will use AWS_REGION/AWS_DEFAULT_REGION env vars.\n * Profile can be specified to use a named profile from ~/.aws/credentials.\n */\nexport class Route53Provider implements DnsProvider {\n\treadonly name = 'route53';\n\tprivate client: Route53Client;\n\tprivate hostedZoneId?: string;\n\tprivate hostedZoneCache: Map<string, string> = new Map();\n\n\tconstructor(options: Route53ProviderOptions = {}) {\n\t\t// Route53 is a global service, default to us-east-1 if no region specified\n\t\tconst region = options.region ?? process.env.AWS_REGION ?? 'us-east-1';\n\n\t\tthis.client = new Route53Client({\n\t\t\tregion,\n\t\t\t...(options.endpoint && { endpoint: options.endpoint }),\n\t\t\t...(options.profile && {\n\t\t\t\tcredentials: fromIni({ profile: options.profile }),\n\t\t\t}),\n\t\t});\n\t\tthis.hostedZoneId = options.hostedZoneId;\n\t}\n\n\t/**\n\t * Get the hosted zone ID for a domain.\n\t * Uses cache to avoid repeated API calls.\n\t */\n\tprivate async getHostedZoneId(domain: string): Promise<string> {\n\t\t// Use configured zone ID if provided\n\t\tif (this.hostedZoneId) {\n\t\t\treturn this.hostedZoneId;\n\t\t}\n\n\t\t// Check cache\n\t\tif (this.hostedZoneCache.has(domain)) {\n\t\t\treturn this.hostedZoneCache.get(domain)!;\n\t\t}\n\n\t\t// Auto-detect from domain\n\t\tconst command = new ListHostedZonesByNameCommand({\n\t\t\tDNSName: domain,\n\t\t\tMaxItems: 1,\n\t\t});\n\n\t\tconst response = await this.client.send(command);\n\t\tconst zones = response.HostedZones ?? [];\n\n\t\t// Find exact match (domain with trailing dot)\n\t\tconst normalizedDomain = domain.endsWith('.') ? domain : `${domain}.`;\n\t\tconst zone = zones.find((z) => z.Name === normalizedDomain);\n\n\t\tif (!zone?.Id) {\n\t\t\tthrow new Error(\n\t\t\t\t`No hosted zone found for domain: ${domain}. Create one in Route53 or provide hostedZoneId in config.`,\n\t\t\t);\n\t\t}\n\n\t\t// Zone ID comes as \"/hostedzone/Z1234567890\" - extract just the ID\n\t\tconst zoneId = zone.Id.replace('/hostedzone/', '');\n\t\tthis.hostedZoneCache.set(domain, zoneId);\n\t\treturn zoneId;\n\t}\n\n\t/**\n\t * Convert Route53 record type to our DnsRecordType.\n\t * Excludes NS and SOA which are auto-managed by Route53 for the zone.\n\t */\n\tprivate toRecordType(type: string): DnsRecordType | null {\n\t\t// Exclude NS and SOA which are auto-managed zone records\n\t\tconst managedTypes = ['NS', 'SOA'];\n\t\tif (managedTypes.includes(type)) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst validTypes: DnsRecordType[] = [\n\t\t\t'A',\n\t\t\t'AAAA',\n\t\t\t'CNAME',\n\t\t\t'MX',\n\t\t\t'TXT',\n\t\t\t'SRV',\n\t\t\t'CAA',\n\t\t];\n\t\treturn validTypes.includes(type as DnsRecordType)\n\t\t\t? (type as DnsRecordType)\n\t\t\t: null;\n\t}\n\n\t/**\n\t * Extract subdomain from full record name relative to domain.\n\t */\n\tprivate extractSubdomain(recordName: string, domain: string): string {\n\t\tconst normalizedDomain = domain.endsWith('.') ? domain : `${domain}.`;\n\t\tconst normalizedName = recordName.endsWith('.')\n\t\t\t? recordName\n\t\t\t: `${recordName}.`;\n\n\t\tif (normalizedName === normalizedDomain) {\n\t\t\treturn '@';\n\t\t}\n\n\t\t// Remove the domain suffix\n\t\tconst subdomain = normalizedName.replace(`.${normalizedDomain}`, '');\n\t\t// Route 53 returns a name's special characters as octal escapes — a\n\t\t// wildcard record's `*` as `\\052` — so the label is read back as written.\n\t\treturn subdomain\n\t\t\t.replace(/\\.$/, '') // Remove trailing dot if any\n\t\t\t.replace(/\\\\(\\d{3})/g, (_, code: string) =>\n\t\t\t\tString.fromCharCode(Number.parseInt(code, 8)),\n\t\t\t);\n\t}\n\n\tasync getRecords(domain: string): Promise<DnsRecord[]> {\n\t\tconst zoneId = await this.getHostedZoneId(domain);\n\t\tconst records: DnsRecord[] = [];\n\n\t\tlet nextRecordName: string | undefined;\n\t\tlet nextRecordType: RRType | undefined;\n\n\t\t// Paginate through all records\n\t\tdo {\n\t\t\tconst command = new ListResourceRecordSetsCommand({\n\t\t\t\tHostedZoneId: zoneId,\n\t\t\t\tStartRecordName: nextRecordName,\n\t\t\t\tStartRecordType: nextRecordType,\n\t\t\t\tMaxItems: 100,\n\t\t\t});\n\n\t\t\tconst response = await this.client.send(command);\n\n\t\t\tfor (const recordSet of response.ResourceRecordSets ?? []) {\n\t\t\t\tconst type = this.toRecordType(recordSet.Type ?? '');\n\t\t\t\tif (!type || !recordSet.Name) continue;\n\n\t\t\t\tconst values = (recordSet.ResourceRecords ?? [])\n\t\t\t\t\t.map((r) => r.Value)\n\t\t\t\t\t.filter((v): v is string => !!v);\n\n\t\t\t\trecords.push({\n\t\t\t\t\tname: this.extractSubdomain(recordSet.Name, domain),\n\t\t\t\t\ttype,\n\t\t\t\t\tttl: recordSet.TTL ?? 300,\n\t\t\t\t\tvalues,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (response.IsTruncated) {\n\t\t\t\tnextRecordName = response.NextRecordName;\n\t\t\t\tnextRecordType = response.NextRecordType;\n\t\t\t} else {\n\t\t\t\tnextRecordName = undefined;\n\t\t\t}\n\t\t} while (nextRecordName);\n\n\t\treturn records;\n\t}\n\n\tasync upsertRecords(\n\t\tdomain: string,\n\t\trecords: UpsertDnsRecord[],\n\t): Promise<UpsertResult[]> {\n\t\tconst zoneId = await this.getHostedZoneId(domain);\n\t\tconst results: UpsertResult[] = [];\n\n\t\t// Get existing records to determine if creating or updating\n\t\tconst existingRecords = await this.getRecords(domain);\n\n\t\t// Process records in batches (Route53 allows max 1000 changes per request)\n\t\tconst batchSize = 100;\n\t\tfor (let i = 0; i < records.length; i += batchSize) {\n\t\t\tconst batch = records.slice(i, i + batchSize);\n\t\t\tconst changes = [];\n\n\t\t\tfor (const record of batch) {\n\t\t\t\tconst existing = existingRecords.find(\n\t\t\t\t\t(r) => r.name === record.name && r.type === record.type,\n\t\t\t\t);\n\n\t\t\t\tconst existingValue = existing?.values?.[0];\n\n\t\t\t\tif (existing && existingValue === record.value) {\n\t\t\t\t\t// Record exists with same value - unchanged\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\trecord,\n\t\t\t\t\t\tcreated: false,\n\t\t\t\t\t\tunchanged: true,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Build full record name\n\t\t\t\tconst recordName =\n\t\t\t\t\trecord.name === '@' ? domain : `${record.name}.${domain}`;\n\n\t\t\t\tchanges.push({\n\t\t\t\t\tAction: 'UPSERT' as const,\n\t\t\t\t\tResourceRecordSet: {\n\t\t\t\t\t\tName: recordName,\n\t\t\t\t\t\tType: record.type,\n\t\t\t\t\t\tTTL: record.ttl,\n\t\t\t\t\t\tResourceRecords: [{ Value: record.value }],\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tresults.push({\n\t\t\t\t\trecord,\n\t\t\t\t\tcreated: !existing,\n\t\t\t\t\tunchanged: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Execute batch if there are changes\n\t\t\tif (changes.length > 0) {\n\t\t\t\tconst command = new ChangeResourceRecordSetsCommand({\n\t\t\t\t\tHostedZoneId: zoneId,\n\t\t\t\t\tChangeBatch: {\n\t\t\t\t\t\tComment: 'Upsert by gkm deploy',\n\t\t\t\t\t\tChanges: changes,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tawait this.client.send(command);\n\t\t\t}\n\t\t}\n\n\t\treturn results;\n\t}\n\n\tasync deleteRecords(\n\t\tdomain: string,\n\t\trecords: DeleteDnsRecord[],\n\t): Promise<DeleteResult[]> {\n\t\tconst zoneId = await this.getHostedZoneId(domain);\n\t\tconst results: DeleteResult[] = [];\n\n\t\t// Get existing records to find the ones to delete\n\t\tconst existingRecords = await this.getRecords(domain);\n\n\t\t// Process records in batches (Route53 allows max 1000 changes per request)\n\t\tconst batchSize = 100;\n\t\tfor (let i = 0; i < records.length; i += batchSize) {\n\t\t\tconst batch = records.slice(i, i + batchSize);\n\t\t\tconst changes = [];\n\n\t\t\tfor (const record of batch) {\n\t\t\t\tconst existing = existingRecords.find(\n\t\t\t\t\t(r) => r.name === record.name && r.type === record.type,\n\t\t\t\t);\n\n\t\t\t\tif (!existing) {\n\t\t\t\t\t// Record doesn't exist - already deleted\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\trecord,\n\t\t\t\t\t\tdeleted: false,\n\t\t\t\t\t\tnotFound: true,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Build full record name\n\t\t\t\tconst recordName =\n\t\t\t\t\trecord.name === '@' ? domain : `${record.name}.${domain}`;\n\n\t\t\t\tchanges.push({\n\t\t\t\t\tAction: 'DELETE' as const,\n\t\t\t\t\tResourceRecordSet: {\n\t\t\t\t\t\tName: recordName,\n\t\t\t\t\t\tType: record.type,\n\t\t\t\t\t\tTTL: existing.ttl,\n\t\t\t\t\t\tResourceRecords: existing.values.map((v) => ({ Value: v })),\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tresults.push({\n\t\t\t\t\trecord,\n\t\t\t\t\tdeleted: true,\n\t\t\t\t\tnotFound: false,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Execute batch if there are changes\n\t\t\tif (changes.length > 0) {\n\t\t\t\ttry {\n\t\t\t\t\tconst command = new ChangeResourceRecordSetsCommand({\n\t\t\t\t\t\tHostedZoneId: zoneId,\n\t\t\t\t\t\tChangeBatch: {\n\t\t\t\t\t\t\tComment: 'Delete by gkm undeploy',\n\t\t\t\t\t\t\tChanges: changes,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\n\t\t\t\t\tawait this.client.send(command);\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Mark all records in this batch as failed\n\t\t\t\t\tfor (const result of results.slice(-changes.length)) {\n\t\t\t\t\t\tif (result.deleted) {\n\t\t\t\t\t\t\tresult.deleted = false;\n\t\t\t\t\t\t\tresult.error = String(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn results;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0CA,IAAa,kBAAb,MAAoD;CACnD,OAAgB;CAChB;CACA;CACA,kCAA+C,IAAI,IAAI;CAEvD,YAAY,UAAkC,CAAC,GAAG;EAEjD,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI,cAAc;EAE3D,KAAK,SAAS,IAAI,cAAc;GA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,GAAG,OAAO,KAAK,GAAG;IAElD,QAAQ,KAAK;KACZ,QAAQ;KACR,mBAAmB;MAClB,MAAM;MACN,MAAM,OAAO;MACb,KAAK,SAAS;MACd,iBAAiB,SAAS,OAAO,KAAK,OAAO,EAAE,OAAO,EAAE,EAAE;KAC3D;IACD,CAAC;IAED,QAAQ,KAAK;KACZ;KACA,SAAS;KACT,UAAU;IACX,CAAC;GACF;GAGA,IAAI,QAAQ,SAAS,GACpB,IAAI;IACH,MAAM,UAAU,IAAI,gCAAgC;KACnD,cAAc;KACd,aAAa;MACZ,SAAS;MACT,SAAS;KACV;IACD,CAAC;IAED,MAAM,KAAK,OAAO,KAAK,OAAO;GAC/B,SAAS,OAAO;IAEf,KAAK,MAAM,UAAU,QAAQ,MAAM,CAAC,QAAQ,MAAM,GACjD,IAAI,OAAO,SAAS;KACnB,OAAO,UAAU;KACjB,OAAO,QAAQ,OAAO,KAAK;IAC5B;GAEF;EAEF;EAEA,OAAO;CACR;AACD"}
@@ -0,0 +1,16 @@
1
+ //#region src/errors.ts
2
+ /**
3
+ * The errors the edge raises on purpose.
4
+ *
5
+ * Like the CLI's `GkmError`: a failure seen coming and explained, whose
6
+ * message is the whole answer. The CLI prints one without a stack trace.
7
+ */
8
+ var EdgeError = class extends Error {};
9
+ /** Whether `error` is one the edge raised on purpose. */
10
+ function isEdgeError(error) {
11
+ return error instanceof EdgeError;
12
+ }
13
+ //#endregion
14
+ export { isEdgeError as n, EdgeError as t };
15
+
16
+ //# sourceMappingURL=errors-CO33_TDV.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-CO33_TDV.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * The errors the edge raises on purpose.\n *\n * Like the CLI's `GkmError`: a failure seen coming and explained, whose\n * message is the whole answer. The CLI prints one without a stack trace.\n */\nexport class EdgeError extends Error {}\n\n/** Whether `error` is one the edge raised on purpose. */\nexport function isEdgeError(error: unknown): error is EdgeError {\n\treturn error instanceof EdgeError;\n}\n"],"mappings":";;;;;;;AAMA,IAAa,YAAb,cAA+B,MAAM,CAAC;;AAGtC,SAAgB,YAAY,OAAoC;CAC/D,OAAO,iBAAiB;AACzB"}
@@ -0,0 +1,13 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * The errors the edge raises on purpose.
4
+ *
5
+ * Like the CLI's `GkmError`: a failure seen coming and explained, whose
6
+ * message is the whole answer. The CLI prints one without a stack trace.
7
+ */
8
+ declare class EdgeError extends Error {}
9
+ /** Whether `error` is one the edge raised on purpose. */
10
+ declare function isEdgeError(error: unknown): error is EdgeError;
11
+ //#endregion
12
+ export { isEdgeError as n, EdgeError as t };
13
+ //# sourceMappingURL=errors-DBZfelEN.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-DBZfelEN.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;;cAMa,kBAAkB;;iBAGf,YAAY,iBAAiB,SAAS"}
@@ -0,0 +1,13 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * The errors the edge raises on purpose.
4
+ *
5
+ * Like the CLI's `GkmError`: a failure seen coming and explained, whose
6
+ * message is the whole answer. The CLI prints one without a stack trace.
7
+ */
8
+ declare class EdgeError extends Error {}
9
+ /** Whether `error` is one the edge raised on purpose. */
10
+ declare function isEdgeError(error: unknown): error is EdgeError;
11
+ //#endregion
12
+ export { isEdgeError as n, EdgeError as t };
13
+ //# sourceMappingURL=errors-DBZfelEN.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-DBZfelEN.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;;cAMa,kBAAkB;;iBAGf,YAAY,iBAAiB,SAAS"}
@@ -0,0 +1,27 @@
1
+ //#region src/errors.ts
2
+ /**
3
+ * The errors the edge raises on purpose.
4
+ *
5
+ * Like the CLI's `GkmError`: a failure seen coming and explained, whose
6
+ * message is the whole answer. The CLI prints one without a stack trace.
7
+ */
8
+ var EdgeError = class extends Error {};
9
+ /** Whether `error` is one the edge raised on purpose. */
10
+ function isEdgeError(error) {
11
+ return error instanceof EdgeError;
12
+ }
13
+ //#endregion
14
+ Object.defineProperty(exports, "EdgeError", {
15
+ enumerable: true,
16
+ get: function() {
17
+ return EdgeError;
18
+ }
19
+ });
20
+ Object.defineProperty(exports, "isEdgeError", {
21
+ enumerable: true,
22
+ get: function() {
23
+ return isEdgeError;
24
+ }
25
+ });
26
+
27
+ //# sourceMappingURL=errors-DlRLQOyZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-DlRLQOyZ.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * The errors the edge raises on purpose.\n *\n * Like the CLI's `GkmError`: a failure seen coming and explained, whose\n * message is the whole answer. The CLI prints one without a stack trace.\n */\nexport class EdgeError extends Error {}\n\n/** Whether `error` is one the edge raised on purpose. */\nexport function isEdgeError(error: unknown): error is EdgeError {\n\treturn error instanceof EdgeError;\n}\n"],"mappings":";;;;;;;AAMA,IAAa,YAAb,cAA+B,MAAM,CAAC;;AAGtC,SAAgB,YAAY,OAAoC;CAC/D,OAAO,iBAAiB;AACzB"}
package/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_compose = require("./compose-BHWyQvsD.cjs");
3
+ const require_errors = require("./errors-DlRLQOyZ.cjs");
4
+ exports.EdgeError = require_errors.EdgeError;
5
+ exports.composeLiteral = require_compose.composeLiteral;
6
+ exports.isEdgeError = require_errors.isEdgeError;
@@ -0,0 +1,15 @@
1
+ import { n as isEdgeError, t as EdgeError } from "./errors-DBZfelEN.cjs";
2
+ //#region src/compose.d.ts
3
+ /**
4
+ * Text written into a compose file as it is, for compose to read back
5
+ * unchanged: every `$` doubled, compose's escape for a literal `$`.
6
+ *
7
+ * Compose interpolates variables throughout the file — an inline config's
8
+ * `content` included — so a `$` left alone is read as the start of a
9
+ * variable's name. A bcrypt hash in a Caddyfile (`$2a$10$AbCd…`) lost the
10
+ * salt's first letters to an unset `$AbCd`, and one with `${` failed to parse.
11
+ */
12
+ export declare function composeLiteral(text: string): string;
13
+ //#endregion
14
+ export { EdgeError, isEdgeError };
15
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/compose.ts"],"mappings":";;;;;;;;;;;wBASgB,eAAe"}
@@ -0,0 +1,15 @@
1
+ import { n as isEdgeError, t as EdgeError } from "./errors-DBZfelEN.mjs";
2
+ //#region src/compose.d.ts
3
+ /**
4
+ * Text written into a compose file as it is, for compose to read back
5
+ * unchanged: every `$` doubled, compose's escape for a literal `$`.
6
+ *
7
+ * Compose interpolates variables throughout the file — an inline config's
8
+ * `content` included — so a `$` left alone is read as the start of a
9
+ * variable's name. A bcrypt hash in a Caddyfile (`$2a$10$AbCd…`) lost the
10
+ * salt's first letters to an unset `$AbCd`, and one with `${` failed to parse.
11
+ */
12
+ export declare function composeLiteral(text: string): string;
13
+ //#endregion
14
+ export { EdgeError, isEdgeError };
15
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/compose.ts"],"mappings":";;;;;;;;;;;wBASgB,eAAe"}
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { t as composeLiteral } from "./compose-CcNlj65h.mjs";
2
+ import { n as isEdgeError, t as EdgeError } from "./errors-CO33_TDV.mjs";
3
+ export { EdgeError, composeLiteral, isEdgeError };
@@ -0,0 +1,167 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_routes_index = require("../routes/index.cjs");
3
+ let _geekmidas_manifest = require("@geekmidas/manifest");
4
+ //#region src/proxy/caddy.ts
5
+ /**
6
+ * The stack's own edge, rendered for Caddy: one site block per route.
7
+ *
8
+ * Deployed, each host is the stage's real domain and Caddy gets it a
9
+ * certificate from Let's Encrypt on first request — the same automatic HTTPS
10
+ * it does anywhere, with nothing to configure but the name — or serves the
11
+ * stage's own certificate (`deploy.compose.tls`). Locally the hosts are
12
+ * `*.localhost` and the certificate is the one gkm's local authority issued,
13
+ * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed
14
+ * one.
15
+ *
16
+ * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.
17
+ */
18
+ /** Where Caddy reads a stage's own certificate, inside its container. */
19
+ const CADDY_TLS_DIR = "/etc/caddy/tls";
20
+ /** An upstream on the stack's own network: its service name. */
21
+ function address({ service, port }) {
22
+ return `${service}:${port}`;
23
+ }
24
+ /** The Caddyfile for a stack's edge. */
25
+ function edgeCaddyfile(routes, options) {
26
+ const { tls } = options;
27
+ const ask = routes.find((route) => route.wildcard?.tls.kind === "on-demand")?.wildcard?.tls;
28
+ const onDemand = ask?.kind === "on-demand" ? `
29
+ on_demand_tls {
30
+ ask ${ask.ask}
31
+ }` : "";
32
+ const settings = `${options.email ? `\n\temail ${options.email}` : ""}${options.redirects === false ? "\n auto_https disable_redirects" : ""}${onDemand}`;
33
+ const global = settings ? `{${settings}\n}` : "";
34
+ const certificate = tls.kind === "files" ? `
35
+ tls ${tls.certFile} ${tls.keyFile}
36
+ ` : "";
37
+ const blocks = [...routes.filter((route) => !route.wildcard), ...routes.filter((route) => route.wildcard)].map((route) => siteBlock(route, options.edgeToken, route.wildcard?.tls.kind === "on-demand" ? `
38
+ tls {
39
+ on_demand
40
+ }
41
+ ` : certificate));
42
+ return `${HEADER}${global ? `${global}\n\n` : ""}${blocks.join("\n\n")}\n`;
43
+ }
44
+ /** One route's site block. */
45
+ function siteBlock(route, edgeToken, certificate) {
46
+ require_routes_index.assertRouteRenderable(route);
47
+ const { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;
48
+ const allowed = [...paths ?? [], ...(prefixes ?? []).map((prefix) => `${prefix}*`)];
49
+ const except = route.wildcard?.except ?? [];
50
+ const checks = `${except.length ? `
51
+ # Labels no tenant may take, although nothing in this stack answers them.
52
+ @protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(" ")}
53
+ respond @protected 404
54
+ ` : ""}${allow ? `
55
+ # Only these addresses — the peer Caddy sees, never a header a client
56
+ # could set. Everything else is refused before it reaches the upstream.
57
+ @denied not remote_ip ${allow.join(" ")}
58
+ respond @denied 403
59
+ ` : ""}${requireHeader ? `
60
+ # Only what the CDN sends: it adds this header to every request, and this
61
+ # host would be reached around the CDN otherwise.
62
+ @forged not header ${requireHeader.name} "${requireHeader.value}"
63
+ respond @forged 403
64
+ ` : ""}${auth ? `
65
+ # The stage's login, asked for before anything reaches the upstream.
66
+ basic_auth {
67
+ ${auth.user} ${auth.hash}
68
+ }
69
+ ` : ""}${allowed.length ? `
70
+ # Only these paths answer. Everything else on this host is refused before
71
+ # it reaches the upstream.
72
+ @elsewhere not path ${allowed.join(" ")}
73
+ respond @elsewhere 404
74
+ ` : ""}`;
75
+ const proxy = proxyBlock(route);
76
+ const body = handlers?.length ? `${handlers.map((handler, index) => `
77
+ # Answered by another service: ${handler.name}.
78
+ @handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(" ")}
79
+ handle @handler${index} {
80
+ reverse_proxy ${handler.upstreams.map(address).join(" ")}
81
+ }
82
+ `).join("")}
83
+ handle {${proxy.replace(/\n/g, "\n ")}
84
+ }` : proxy;
85
+ const names = [host, ...route.aliases ?? []].map((name) => `https://${name}`).join(", ");
86
+ const redirects = (route.redirects?.hosts ?? []).map((from) => `
87
+
88
+ https://${from} {${certificate}
89
+ redir ${route.redirects?.to}{uri} permanent
90
+ }`).join("");
91
+ return `${names} {${certificate}${clientIpRule(edgeToken)}
92
+ ${checks}${body}
93
+ }${redirects}`;
94
+ }
95
+ /** Where a route's requests go, when no handler took them. */
96
+ function proxyBlock(route) {
97
+ const { upstreams, prefix, streaming } = route;
98
+ const health = healthCheck(route);
99
+ return prefix ? `
100
+ # A bucket, served at a host of its own: the bucket is a prefix on MinIO,
101
+ # which routes and signs on the Host header — so it is sent the upstream's.
102
+ reverse_proxy ${upstreams.map(address).join(" ")} {
103
+ rewrite ${prefix}{uri}
104
+ header_up Host {upstream_hostport}${health}
105
+ }` : `
106
+ # Host and X-Forwarded-* are passed through as Caddy does by default, so
107
+ # an app builds redirects, cookies and links on the address a caller used.
108
+ reverse_proxy ${upstreams.map(address).join(" ")}${streaming || health ? ` {${streaming ? `
109
+ # Never buffer: a streamed response — server-sent events, a Next.js
110
+ # RSC payload — reaches the client as each chunk is written.
111
+ flush_interval -1` : ""}${health}
112
+ }` : ""}`;
113
+ }
114
+ /**
115
+ * Caddy's own check of each upstream, as the Traefik edge's
116
+ * `loadBalancer.healthCheck`: one that stops answering is taken out of
117
+ * rotation until it does again. Caddy starts once its apps have — not once
118
+ * they are healthy — so this is what keeps a request from an upstream that
119
+ * is not up, and a route to an app with none up answers an error (503)
120
+ * rather than going missing.
121
+ */
122
+ function healthCheck({ health }) {
123
+ return health ? `
124
+ # Each upstream asked on its own: one that stops answering is out of
125
+ # rotation until it answers again.
126
+ health_uri ${health}
127
+ health_interval 5s
128
+ health_timeout 3s` : "";
129
+ }
130
+ const HEADER = `# Generated by gkm compose from the construct manifest — do not edit.
131
+ #
132
+ # One host per API and site, each in front of its own container, one per
133
+ # file server in front of the stack's MinIO — its processors' paths sent to
134
+ # their own service — one per worker SNS pushes to and per processor unit a
135
+ # CDN reaches, answering only those paths, and — when its logs are served
136
+ # publicly — one for OpenObserve, to the addresses it allows. A site the
137
+ # stage puts behind a password asks for its login first.
138
+ `;
139
+ /**
140
+ * The lines every site block of an edge opens with, for gkm's own
141
+ * `x-gkm-client-ip` — the client address the auth server rate-limits by.
142
+ *
143
+ * Only a service of this stack may send it. One that calls a sibling at its
144
+ * public address comes through this edge, and proves where it comes from with
145
+ * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and
146
+ * handed to every process of the stack — never to a browser. A request
147
+ * without it has the header removed, so nobody outside can choose the address
148
+ * they are rate-limited by. Without a token, it is removed from every request.
149
+ */
150
+ function clientIpRule(edgeToken) {
151
+ if (!edgeToken) return `
152
+ # gkm's own header, which only a service of this stack may send: the auth
153
+ # server rate-limits by the client address it carries.
154
+ request_header -${_geekmidas_manifest.CLIENT_IP_HEADER}`;
155
+ return `
156
+ # gkm's own header, which only a service of this stack may send — proven by
157
+ # the stack's token: the auth server rate-limits by the client address it
158
+ # carries. Removed from every other request.
159
+ @gkm_outside not header ${_geekmidas_manifest.EDGE_TOKEN_HEADER} ${edgeToken}
160
+ request_header @gkm_outside -${_geekmidas_manifest.CLIENT_IP_HEADER}`;
161
+ }
162
+ //#endregion
163
+ exports.CADDY_TLS_DIR = CADDY_TLS_DIR;
164
+ exports.clientIpRule = clientIpRule;
165
+ exports.edgeCaddyfile = edgeCaddyfile;
166
+
167
+ //# sourceMappingURL=caddy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caddy.cjs","names":["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} 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. */\nfunction address({ service, port }: Upstream): string {\n\treturn `${service}:${port}`;\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}\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":";;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;;AAmB7B,SAAS,QAAQ,EAAE,SAAS,QAA0B;CACrD,OAAO,GAAG,QAAQ,GAAG;AACtB;;AAGA,SAAgB,cACf,QACA,SACS;CACT,MAAM,EAAE,QAAQ;CAIhB,MAAM,MAAM,OAAO,MAAM,UAAU,MAAM,UAAU,IAAI,SAAS,WAAW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A,oBAAAA;CAElB,OAAO;;;;2BAImBC,oBAAAA,kBAAkB,GAAG,UAAU;gCAC1BD,oBAAAA;AAChC"}
@@ -0,0 +1,35 @@
1
+ import { EdgeRoute, EdgeTls } from "../routes/index.cjs";
2
+ //#region src/proxy/caddy.d.ts
3
+ /** Where Caddy reads a stage's own certificate, inside its container. */
4
+ export declare const CADDY_TLS_DIR = "/etc/caddy/tls";
5
+ export interface CaddyfileOptions {
6
+ tls: EdgeTls;
7
+ /**
8
+ * The stack's token, on which a service of the stack keeps gkm's client
9
+ * address through the edge — see `clientIpRule`.
10
+ */
11
+ edgeToken?: string;
12
+ /** Where ACME sends expiry notices, when someone wants them. */
13
+ email?: string;
14
+ /**
15
+ * `false` on the local stage: plain HTTP is not sent to HTTPS, whose
16
+ * published port there may not be 443.
17
+ */
18
+ redirects?: boolean;
19
+ }
20
+ /** The Caddyfile for a stack's edge. */
21
+ export declare function edgeCaddyfile(routes: readonly EdgeRoute[], options: CaddyfileOptions): string;
22
+ /**
23
+ * The lines every site block of an edge opens with, for gkm's own
24
+ * `x-gkm-client-ip` — the client address the auth server rate-limits by.
25
+ *
26
+ * Only a service of this stack may send it. One that calls a sibling at its
27
+ * public address comes through this edge, and proves where it comes from with
28
+ * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and
29
+ * handed to every process of the stack — never to a browser. A request
30
+ * without it has the header removed, so nobody outside can choose the address
31
+ * they are rate-limited by. Without a token, it is removed from every request.
32
+ */
33
+ export declare function clientIpRule(edgeToken: string | undefined): string;
34
+ //#endregion
35
+ //# sourceMappingURL=caddy.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caddy.d.cts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAuBa;iBAEI;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBA0NM,aAAa"}
@@ -0,0 +1,35 @@
1
+ import { EdgeRoute, EdgeTls } from "../routes/index.mjs";
2
+ //#region src/proxy/caddy.d.ts
3
+ /** Where Caddy reads a stage's own certificate, inside its container. */
4
+ export declare const CADDY_TLS_DIR = "/etc/caddy/tls";
5
+ export interface CaddyfileOptions {
6
+ tls: EdgeTls;
7
+ /**
8
+ * The stack's token, on which a service of the stack keeps gkm's client
9
+ * address through the edge — see `clientIpRule`.
10
+ */
11
+ edgeToken?: string;
12
+ /** Where ACME sends expiry notices, when someone wants them. */
13
+ email?: string;
14
+ /**
15
+ * `false` on the local stage: plain HTTP is not sent to HTTPS, whose
16
+ * published port there may not be 443.
17
+ */
18
+ redirects?: boolean;
19
+ }
20
+ /** The Caddyfile for a stack's edge. */
21
+ export declare function edgeCaddyfile(routes: readonly EdgeRoute[], options: CaddyfileOptions): string;
22
+ /**
23
+ * The lines every site block of an edge opens with, for gkm's own
24
+ * `x-gkm-client-ip` — the client address the auth server rate-limits by.
25
+ *
26
+ * Only a service of this stack may send it. One that calls a sibling at its
27
+ * public address comes through this edge, and proves where it comes from with
28
+ * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and
29
+ * handed to every process of the stack — never to a browser. A request
30
+ * without it has the header removed, so nobody outside can choose the address
31
+ * they are rate-limited by. Without a token, it is removed from every request.
32
+ */
33
+ export declare function clientIpRule(edgeToken: string | undefined): string;
34
+ //#endregion
35
+ //# sourceMappingURL=caddy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caddy.d.mts","names":[],"sources":["../../src/proxy/caddy.ts"],"mappings":";;;qBAuBa;iBAEI;EAChB,KAAK;;;;;EAKL;;EAEA;;;;;EAKA;;;wBASe,cACf,iBAAiB,aACjB,SAAS;;;;;;;;;;;;wBA0NM,aAAa"}
@@ -0,0 +1,164 @@
1
+ import { assertRouteRenderable } from "../routes/index.mjs";
2
+ import { CLIENT_IP_HEADER, EDGE_TOKEN_HEADER } from "@geekmidas/manifest";
3
+ //#region src/proxy/caddy.ts
4
+ /**
5
+ * The stack's own edge, rendered for Caddy: one site block per route.
6
+ *
7
+ * Deployed, each host is the stage's real domain and Caddy gets it a
8
+ * certificate from Let's Encrypt on first request — the same automatic HTTPS
9
+ * it does anywhere, with nothing to configure but the name — or serves the
10
+ * stage's own certificate (`deploy.compose.tls`). Locally the hosts are
11
+ * `*.localhost` and the certificate is the one gkm's local authority issued,
12
+ * as the `gkm dev` edge's is, so a local stack is `https://` like a deployed
13
+ * one.
14
+ *
15
+ * Pure: the routes are data (`@geekmidas/edge/routes`), and rendering them is one string.
16
+ */
17
+ /** Where Caddy reads a stage's own certificate, inside its container. */
18
+ const CADDY_TLS_DIR = "/etc/caddy/tls";
19
+ /** An upstream on the stack's own network: its service name. */
20
+ function address({ service, port }) {
21
+ return `${service}:${port}`;
22
+ }
23
+ /** The Caddyfile for a stack's edge. */
24
+ function edgeCaddyfile(routes, options) {
25
+ const { tls } = options;
26
+ const ask = routes.find((route) => route.wildcard?.tls.kind === "on-demand")?.wildcard?.tls;
27
+ const onDemand = ask?.kind === "on-demand" ? `
28
+ on_demand_tls {
29
+ ask ${ask.ask}
30
+ }` : "";
31
+ const settings = `${options.email ? `\n\temail ${options.email}` : ""}${options.redirects === false ? "\n auto_https disable_redirects" : ""}${onDemand}`;
32
+ const global = settings ? `{${settings}\n}` : "";
33
+ const certificate = tls.kind === "files" ? `
34
+ tls ${tls.certFile} ${tls.keyFile}
35
+ ` : "";
36
+ const blocks = [...routes.filter((route) => !route.wildcard), ...routes.filter((route) => route.wildcard)].map((route) => siteBlock(route, options.edgeToken, route.wildcard?.tls.kind === "on-demand" ? `
37
+ tls {
38
+ on_demand
39
+ }
40
+ ` : certificate));
41
+ return `${HEADER}${global ? `${global}\n\n` : ""}${blocks.join("\n\n")}\n`;
42
+ }
43
+ /** One route's site block. */
44
+ function siteBlock(route, edgeToken, certificate) {
45
+ assertRouteRenderable(route);
46
+ const { host, allow, auth, paths, prefixes, requireHeader, handlers } = route;
47
+ const allowed = [...paths ?? [], ...(prefixes ?? []).map((prefix) => `${prefix}*`)];
48
+ const except = route.wildcard?.except ?? [];
49
+ const checks = `${except.length ? `
50
+ # Labels no tenant may take, although nothing in this stack answers them.
51
+ @protected host ${except.map((label) => `${label}.${route.wildcard?.domain}`).join(" ")}
52
+ respond @protected 404
53
+ ` : ""}${allow ? `
54
+ # Only these addresses — the peer Caddy sees, never a header a client
55
+ # could set. Everything else is refused before it reaches the upstream.
56
+ @denied not remote_ip ${allow.join(" ")}
57
+ respond @denied 403
58
+ ` : ""}${requireHeader ? `
59
+ # Only what the CDN sends: it adds this header to every request, and this
60
+ # host would be reached around the CDN otherwise.
61
+ @forged not header ${requireHeader.name} "${requireHeader.value}"
62
+ respond @forged 403
63
+ ` : ""}${auth ? `
64
+ # The stage's login, asked for before anything reaches the upstream.
65
+ basic_auth {
66
+ ${auth.user} ${auth.hash}
67
+ }
68
+ ` : ""}${allowed.length ? `
69
+ # Only these paths answer. Everything else on this host is refused before
70
+ # it reaches the upstream.
71
+ @elsewhere not path ${allowed.join(" ")}
72
+ respond @elsewhere 404
73
+ ` : ""}`;
74
+ const proxy = proxyBlock(route);
75
+ const body = handlers?.length ? `${handlers.map((handler, index) => `
76
+ # Answered by another service: ${handler.name}.
77
+ @handler${index} path ${handler.prefixes.map((prefix) => `${prefix}*`).join(" ")}
78
+ handle @handler${index} {
79
+ reverse_proxy ${handler.upstreams.map(address).join(" ")}
80
+ }
81
+ `).join("")}
82
+ handle {${proxy.replace(/\n/g, "\n ")}
83
+ }` : proxy;
84
+ const names = [host, ...route.aliases ?? []].map((name) => `https://${name}`).join(", ");
85
+ const redirects = (route.redirects?.hosts ?? []).map((from) => `
86
+
87
+ https://${from} {${certificate}
88
+ redir ${route.redirects?.to}{uri} permanent
89
+ }`).join("");
90
+ return `${names} {${certificate}${clientIpRule(edgeToken)}
91
+ ${checks}${body}
92
+ }${redirects}`;
93
+ }
94
+ /** Where a route's requests go, when no handler took them. */
95
+ function proxyBlock(route) {
96
+ const { upstreams, prefix, streaming } = route;
97
+ const health = healthCheck(route);
98
+ return prefix ? `
99
+ # A bucket, served at a host of its own: the bucket is a prefix on MinIO,
100
+ # which routes and signs on the Host header — so it is sent the upstream's.
101
+ reverse_proxy ${upstreams.map(address).join(" ")} {
102
+ rewrite ${prefix}{uri}
103
+ header_up Host {upstream_hostport}${health}
104
+ }` : `
105
+ # Host and X-Forwarded-* are passed through as Caddy does by default, so
106
+ # an app builds redirects, cookies and links on the address a caller used.
107
+ reverse_proxy ${upstreams.map(address).join(" ")}${streaming || health ? ` {${streaming ? `
108
+ # Never buffer: a streamed response — server-sent events, a Next.js
109
+ # RSC payload — reaches the client as each chunk is written.
110
+ flush_interval -1` : ""}${health}
111
+ }` : ""}`;
112
+ }
113
+ /**
114
+ * Caddy's own check of each upstream, as the Traefik edge's
115
+ * `loadBalancer.healthCheck`: one that stops answering is taken out of
116
+ * rotation until it does again. Caddy starts once its apps have — not once
117
+ * they are healthy — so this is what keeps a request from an upstream that
118
+ * is not up, and a route to an app with none up answers an error (503)
119
+ * rather than going missing.
120
+ */
121
+ function healthCheck({ health }) {
122
+ return health ? `
123
+ # Each upstream asked on its own: one that stops answering is out of
124
+ # rotation until it answers again.
125
+ health_uri ${health}
126
+ health_interval 5s
127
+ health_timeout 3s` : "";
128
+ }
129
+ const HEADER = `# Generated by gkm compose from the construct manifest — do not edit.
130
+ #
131
+ # One host per API and site, each in front of its own container, one per
132
+ # file server in front of the stack's MinIO — its processors' paths sent to
133
+ # their own service — one per worker SNS pushes to and per processor unit a
134
+ # CDN reaches, answering only those paths, and — when its logs are served
135
+ # publicly — one for OpenObserve, to the addresses it allows. A site the
136
+ # stage puts behind a password asks for its login first.
137
+ `;
138
+ /**
139
+ * The lines every site block of an edge opens with, for gkm's own
140
+ * `x-gkm-client-ip` — the client address the auth server rate-limits by.
141
+ *
142
+ * Only a service of this stack may send it. One that calls a sibling at its
143
+ * public address comes through this edge, and proves where it comes from with
144
+ * the stack's token (`x-gkm-edge-token`), derived from the stage's seed and
145
+ * handed to every process of the stack — never to a browser. A request
146
+ * without it has the header removed, so nobody outside can choose the address
147
+ * they are rate-limited by. Without a token, it is removed from every request.
148
+ */
149
+ function clientIpRule(edgeToken) {
150
+ if (!edgeToken) return `
151
+ # gkm's own header, which only a service of this stack may send: the auth
152
+ # server rate-limits by the client address it carries.
153
+ request_header -${CLIENT_IP_HEADER}`;
154
+ return `
155
+ # gkm's own header, which only a service of this stack may send — proven by
156
+ # the stack's token: the auth server rate-limits by the client address it
157
+ # carries. Removed from every other request.
158
+ @gkm_outside not header ${EDGE_TOKEN_HEADER} ${edgeToken}
159
+ request_header @gkm_outside -${CLIENT_IP_HEADER}`;
160
+ }
161
+ //#endregion
162
+ export { CADDY_TLS_DIR, clientIpRule, edgeCaddyfile };
163
+
164
+ //# sourceMappingURL=caddy.mjs.map