@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,71 @@
1
+ import { t as EdgeError } from "../errors-CO33_TDV.mjs";
2
+ //#region src/dns/index.ts
3
+ /**
4
+ * DNS Provider Interface
5
+ *
6
+ * Abstracts DNS operations for different providers.
7
+ * Built-in providers: HostingerProvider, Route53Provider, GoDaddyProvider
8
+ * Users can also supply custom implementations.
9
+ *
10
+ * Every value is the record's zone-file form, read and written alike: an MX
11
+ * record's is `<priority> <host>` (see {@link mxValue}).
12
+ */
13
+ /**
14
+ * An MX record's value as every provider here reads and writes it — the zone
15
+ * file's `<priority> <host>`, which is what Route53 and Hostinger take as is.
16
+ * A provider whose API keeps the priority apart (GoDaddy) splits it with
17
+ * {@link parseMxValue}.
18
+ */
19
+ function mxValue(priority, host) {
20
+ return `${priority} ${host.trim().replace(/\.$/, "")}`;
21
+ }
22
+ /** An MX value that is not `<priority> <host>`. */
23
+ var MxValueInvalid = class extends EdgeError {
24
+ value;
25
+ constructor(value) {
26
+ super(`'${value}' is not an MX record's value: it is written '<priority> <host>', like '10 inbound-smtp.eu-west-1.amazonaws.com'. Build it with mxValue(priority, host).`);
27
+ this.value = value;
28
+ this.name = "MxValueInvalid";
29
+ }
30
+ };
31
+ /**
32
+ * The priority and host of an MX value.
33
+ *
34
+ * @throws {MxValueInvalid} for a value that is not `<priority> <host>`
35
+ */
36
+ function parseMxValue(value) {
37
+ const match = value.trim().match(/^(\d{1,5})\s+(\S+)$/);
38
+ const priority = match ? Number(match[1]) : NaN;
39
+ if (!match || priority > 65535) throw new MxValueInvalid(value);
40
+ return {
41
+ priority,
42
+ host: match[2].replace(/\.$/, "")
43
+ };
44
+ }
45
+ /**
46
+ * Check if value is a DnsProvider implementation.
47
+ */
48
+ function isDnsProvider(value) {
49
+ return typeof value === "object" && value !== null && typeof value.name === "string" && typeof value.getRecords === "function" && typeof value.upsertRecords === "function" && typeof value.deleteRecords === "function";
50
+ }
51
+ /**
52
+ * The provider's credentials can write records and not read them — a key
53
+ * scoped to updates only. What reads them falls back to writing every record,
54
+ * which is idempotent, without a diff.
55
+ */
56
+ var DnsRecordsUnreadable = class extends EdgeError {
57
+ provider;
58
+ domain;
59
+ reason;
60
+ constructor(provider, domain, reason) {
61
+ super(`The ${provider} key cannot read ${domain}'s DNS records (${reason}), so changes cannot be compared with what is there: every record is written, which leaves one that already has its value as it was.`);
62
+ this.provider = provider;
63
+ this.domain = domain;
64
+ this.reason = reason;
65
+ this.name = "DnsRecordsUnreadable";
66
+ }
67
+ };
68
+ //#endregion
69
+ export { DnsRecordsUnreadable, MxValueInvalid, isDnsProvider, mxValue, parseMxValue };
70
+
71
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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"}
@@ -0,0 +1,210 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _aws_sdk_client_route_53 = require("@aws-sdk/client-route-53");
3
+ let _aws_sdk_credential_providers = require("@aws-sdk/credential-providers");
4
+ //#region src/dns/route53.ts
5
+ /**
6
+ * Route53 DNS Provider
7
+ *
8
+ * Implements DnsProvider interface using AWS Route53.
9
+ */
10
+ /**
11
+ * Route53 DNS provider implementation.
12
+ *
13
+ * Uses AWS default credential chain for authentication.
14
+ * Region can be specified or will use AWS_REGION/AWS_DEFAULT_REGION env vars.
15
+ * Profile can be specified to use a named profile from ~/.aws/credentials.
16
+ */
17
+ var Route53Provider = class {
18
+ name = "route53";
19
+ client;
20
+ hostedZoneId;
21
+ hostedZoneCache = /* @__PURE__ */ new Map();
22
+ constructor(options = {}) {
23
+ const region = options.region ?? process.env.AWS_REGION ?? "us-east-1";
24
+ this.client = new _aws_sdk_client_route_53.Route53Client({
25
+ region,
26
+ ...options.endpoint && { endpoint: options.endpoint },
27
+ ...options.profile && { credentials: (0, _aws_sdk_credential_providers.fromIni)({ profile: options.profile }) }
28
+ });
29
+ this.hostedZoneId = options.hostedZoneId;
30
+ }
31
+ /**
32
+ * Get the hosted zone ID for a domain.
33
+ * Uses cache to avoid repeated API calls.
34
+ */
35
+ async getHostedZoneId(domain) {
36
+ if (this.hostedZoneId) return this.hostedZoneId;
37
+ if (this.hostedZoneCache.has(domain)) return this.hostedZoneCache.get(domain);
38
+ const command = new _aws_sdk_client_route_53.ListHostedZonesByNameCommand({
39
+ DNSName: domain,
40
+ MaxItems: 1
41
+ });
42
+ const zones = (await this.client.send(command)).HostedZones ?? [];
43
+ const normalizedDomain = domain.endsWith(".") ? domain : `${domain}.`;
44
+ const zone = zones.find((z) => z.Name === normalizedDomain);
45
+ if (!zone?.Id) throw new Error(`No hosted zone found for domain: ${domain}. Create one in Route53 or provide hostedZoneId in config.`);
46
+ const zoneId = zone.Id.replace("/hostedzone/", "");
47
+ this.hostedZoneCache.set(domain, zoneId);
48
+ return zoneId;
49
+ }
50
+ /**
51
+ * Convert Route53 record type to our DnsRecordType.
52
+ * Excludes NS and SOA which are auto-managed by Route53 for the zone.
53
+ */
54
+ toRecordType(type) {
55
+ if (["NS", "SOA"].includes(type)) return null;
56
+ return [
57
+ "A",
58
+ "AAAA",
59
+ "CNAME",
60
+ "MX",
61
+ "TXT",
62
+ "SRV",
63
+ "CAA"
64
+ ].includes(type) ? type : null;
65
+ }
66
+ /**
67
+ * Extract subdomain from full record name relative to domain.
68
+ */
69
+ extractSubdomain(recordName, domain) {
70
+ const normalizedDomain = domain.endsWith(".") ? domain : `${domain}.`;
71
+ const normalizedName = recordName.endsWith(".") ? recordName : `${recordName}.`;
72
+ if (normalizedName === normalizedDomain) return "@";
73
+ return normalizedName.replace(`.${normalizedDomain}`, "").replace(/\.$/, "").replace(/\\(\d{3})/g, (_, code) => String.fromCharCode(Number.parseInt(code, 8)));
74
+ }
75
+ async getRecords(domain) {
76
+ const zoneId = await this.getHostedZoneId(domain);
77
+ const records = [];
78
+ let nextRecordName;
79
+ let nextRecordType;
80
+ do {
81
+ const command = new _aws_sdk_client_route_53.ListResourceRecordSetsCommand({
82
+ HostedZoneId: zoneId,
83
+ StartRecordName: nextRecordName,
84
+ StartRecordType: nextRecordType,
85
+ MaxItems: 100
86
+ });
87
+ const response = await this.client.send(command);
88
+ for (const recordSet of response.ResourceRecordSets ?? []) {
89
+ const type = this.toRecordType(recordSet.Type ?? "");
90
+ if (!type || !recordSet.Name) continue;
91
+ const values = (recordSet.ResourceRecords ?? []).map((r) => r.Value).filter((v) => !!v);
92
+ records.push({
93
+ name: this.extractSubdomain(recordSet.Name, domain),
94
+ type,
95
+ ttl: recordSet.TTL ?? 300,
96
+ values
97
+ });
98
+ }
99
+ if (response.IsTruncated) {
100
+ nextRecordName = response.NextRecordName;
101
+ nextRecordType = response.NextRecordType;
102
+ } else nextRecordName = void 0;
103
+ } while (nextRecordName);
104
+ return records;
105
+ }
106
+ async upsertRecords(domain, records) {
107
+ const zoneId = await this.getHostedZoneId(domain);
108
+ const results = [];
109
+ const existingRecords = await this.getRecords(domain);
110
+ const batchSize = 100;
111
+ for (let i = 0; i < records.length; i += batchSize) {
112
+ const batch = records.slice(i, i + batchSize);
113
+ const changes = [];
114
+ for (const record of batch) {
115
+ const existing = existingRecords.find((r) => r.name === record.name && r.type === record.type);
116
+ const existingValue = existing?.values?.[0];
117
+ if (existing && existingValue === record.value) {
118
+ results.push({
119
+ record,
120
+ created: false,
121
+ unchanged: true
122
+ });
123
+ continue;
124
+ }
125
+ const recordName = record.name === "@" ? domain : `${record.name}.${domain}`;
126
+ changes.push({
127
+ Action: "UPSERT",
128
+ ResourceRecordSet: {
129
+ Name: recordName,
130
+ Type: record.type,
131
+ TTL: record.ttl,
132
+ ResourceRecords: [{ Value: record.value }]
133
+ }
134
+ });
135
+ results.push({
136
+ record,
137
+ created: !existing,
138
+ unchanged: false
139
+ });
140
+ }
141
+ if (changes.length > 0) {
142
+ const command = new _aws_sdk_client_route_53.ChangeResourceRecordSetsCommand({
143
+ HostedZoneId: zoneId,
144
+ ChangeBatch: {
145
+ Comment: "Upsert by gkm deploy",
146
+ Changes: changes
147
+ }
148
+ });
149
+ await this.client.send(command);
150
+ }
151
+ }
152
+ return results;
153
+ }
154
+ async deleteRecords(domain, records) {
155
+ const zoneId = await this.getHostedZoneId(domain);
156
+ const results = [];
157
+ const existingRecords = await this.getRecords(domain);
158
+ const batchSize = 100;
159
+ for (let i = 0; i < records.length; i += batchSize) {
160
+ const batch = records.slice(i, i + batchSize);
161
+ const changes = [];
162
+ for (const record of batch) {
163
+ const existing = existingRecords.find((r) => r.name === record.name && r.type === record.type);
164
+ if (!existing) {
165
+ results.push({
166
+ record,
167
+ deleted: false,
168
+ notFound: true
169
+ });
170
+ continue;
171
+ }
172
+ const recordName = record.name === "@" ? domain : `${record.name}.${domain}`;
173
+ changes.push({
174
+ Action: "DELETE",
175
+ ResourceRecordSet: {
176
+ Name: recordName,
177
+ Type: record.type,
178
+ TTL: existing.ttl,
179
+ ResourceRecords: existing.values.map((v) => ({ Value: v }))
180
+ }
181
+ });
182
+ results.push({
183
+ record,
184
+ deleted: true,
185
+ notFound: false
186
+ });
187
+ }
188
+ if (changes.length > 0) try {
189
+ const command = new _aws_sdk_client_route_53.ChangeResourceRecordSetsCommand({
190
+ HostedZoneId: zoneId,
191
+ ChangeBatch: {
192
+ Comment: "Delete by gkm undeploy",
193
+ Changes: changes
194
+ }
195
+ });
196
+ await this.client.send(command);
197
+ } catch (error) {
198
+ for (const result of results.slice(-changes.length)) if (result.deleted) {
199
+ result.deleted = false;
200
+ result.error = String(error);
201
+ }
202
+ }
203
+ }
204
+ return results;
205
+ }
206
+ };
207
+ //#endregion
208
+ exports.Route53Provider = Route53Provider;
209
+
210
+ //# sourceMappingURL=route53.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route53.cjs","names":["Route53Client","fromIni","ListHostedZonesByNameCommand","ListResourceRecordSetsCommand","ChangeResourceRecordSetsCommand"],"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,IAAIA,yBAAAA,cAAc;GAC/B;GACA,GAAI,QAAQ,YAAY,EAAE,UAAU,QAAQ,SAAS;GACrD,GAAI,QAAQ,WAAW,EACtB,cAAA,GAAaC,8BAAAA,QAAAA,CAAQ,EAAE,SAAS,QAAQ,QAAQ,CAAC,EAClD;EACD,CAAC;EACD,KAAK,eAAe,QAAQ;CAC7B;;;;;CAMA,MAAc,gBAAgB,QAAiC;EAE9D,IAAI,KAAK,cACR,OAAO,KAAK;EAIb,IAAI,KAAK,gBAAgB,IAAI,MAAM,GAClC,OAAO,KAAK,gBAAgB,IAAI,MAAM;EAIvC,MAAM,UAAU,IAAIC,yBAAAA,6BAA6B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nD,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,45 @@
1
+ import { DeleteDnsRecord, DeleteResult, DnsProvider, DnsRecord, UpsertDnsRecord, UpsertResult } from "./index.cjs";
2
+ //#region src/dns/route53.d.ts
3
+ export interface Route53ProviderOptions {
4
+ /** AWS region (optional - uses AWS_REGION env var if not provided) */
5
+ region?: string;
6
+ /** AWS profile name (optional - uses default credential chain if not provided) */
7
+ profile?: string;
8
+ /** Hosted zone ID (optional - auto-detected from domain if not provided) */
9
+ hostedZoneId?: string;
10
+ /** Custom endpoint for testing with localstack */
11
+ endpoint?: string;
12
+ }
13
+ /**
14
+ * Route53 DNS provider implementation.
15
+ *
16
+ * Uses AWS default credential chain for authentication.
17
+ * Region can be specified or will use AWS_REGION/AWS_DEFAULT_REGION env vars.
18
+ * Profile can be specified to use a named profile from ~/.aws/credentials.
19
+ */
20
+ export declare class Route53Provider implements DnsProvider {
21
+ readonly name = "route53";
22
+ private client;
23
+ private hostedZoneId?;
24
+ private hostedZoneCache;
25
+ constructor(options?: Route53ProviderOptions);
26
+ /**
27
+ * Get the hosted zone ID for a domain.
28
+ * Uses cache to avoid repeated API calls.
29
+ */
30
+ private getHostedZoneId;
31
+ /**
32
+ * Convert Route53 record type to our DnsRecordType.
33
+ * Excludes NS and SOA which are auto-managed by Route53 for the zone.
34
+ */
35
+ private toRecordType;
36
+ /**
37
+ * Extract subdomain from full record name relative to domain.
38
+ */
39
+ private extractSubdomain;
40
+ getRecords(domain: string): Promise<DnsRecord[]>;
41
+ upsertRecords(domain: string, records: UpsertDnsRecord[]): Promise<UpsertResult[]>;
42
+ deleteRecords(domain: string, records: DeleteDnsRecord[]): Promise<DeleteResult[]>;
43
+ }
44
+ //#endregion
45
+ //# sourceMappingURL=route53.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route53.d.cts","names":[],"sources":["../../src/dns/route53.ts"],"mappings":";;iBAwBiB;;EAEhB;;EAEA;;EAEA;;EAEA;;;;;;;;;qBAUY,2BAA2B;WAC9B;UACD;UACA;UACA;EAER,YAAY,UAAS;;;;;UAkBP;;;;;UAwCN;;;;UAwBA;EAqBF,WAAW,iBAAiB,QAAQ;EA6CpC,cACL,gBACA,SAAS,oBACP,QAAQ;EAoEL,cACL,gBACA,SAAS,oBACP,QAAQ"}
@@ -0,0 +1,45 @@
1
+ import { DeleteDnsRecord, DeleteResult, DnsProvider, DnsRecord, UpsertDnsRecord, UpsertResult } from "./index.mjs";
2
+ //#region src/dns/route53.d.ts
3
+ export interface Route53ProviderOptions {
4
+ /** AWS region (optional - uses AWS_REGION env var if not provided) */
5
+ region?: string;
6
+ /** AWS profile name (optional - uses default credential chain if not provided) */
7
+ profile?: string;
8
+ /** Hosted zone ID (optional - auto-detected from domain if not provided) */
9
+ hostedZoneId?: string;
10
+ /** Custom endpoint for testing with localstack */
11
+ endpoint?: string;
12
+ }
13
+ /**
14
+ * Route53 DNS provider implementation.
15
+ *
16
+ * Uses AWS default credential chain for authentication.
17
+ * Region can be specified or will use AWS_REGION/AWS_DEFAULT_REGION env vars.
18
+ * Profile can be specified to use a named profile from ~/.aws/credentials.
19
+ */
20
+ export declare class Route53Provider implements DnsProvider {
21
+ readonly name = "route53";
22
+ private client;
23
+ private hostedZoneId?;
24
+ private hostedZoneCache;
25
+ constructor(options?: Route53ProviderOptions);
26
+ /**
27
+ * Get the hosted zone ID for a domain.
28
+ * Uses cache to avoid repeated API calls.
29
+ */
30
+ private getHostedZoneId;
31
+ /**
32
+ * Convert Route53 record type to our DnsRecordType.
33
+ * Excludes NS and SOA which are auto-managed by Route53 for the zone.
34
+ */
35
+ private toRecordType;
36
+ /**
37
+ * Extract subdomain from full record name relative to domain.
38
+ */
39
+ private extractSubdomain;
40
+ getRecords(domain: string): Promise<DnsRecord[]>;
41
+ upsertRecords(domain: string, records: UpsertDnsRecord[]): Promise<UpsertResult[]>;
42
+ deleteRecords(domain: string, records: DeleteDnsRecord[]): Promise<DeleteResult[]>;
43
+ }
44
+ //#endregion
45
+ //# sourceMappingURL=route53.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route53.d.mts","names":[],"sources":["../../src/dns/route53.ts"],"mappings":";;iBAwBiB;;EAEhB;;EAEA;;EAEA;;EAEA;;;;;;;;;qBAUY,2BAA2B;WAC9B;UACD;UACA;UACA;EAER,YAAY,UAAS;;;;;UAkBP;;;;;UAwCN;;;;UAwBA;EAqBF,WAAW,iBAAiB,QAAQ;EA6CpC,cACL,gBACA,SAAS,oBACP,QAAQ;EAoEL,cACL,gBACA,SAAS,oBACP,QAAQ"}
@@ -0,0 +1,209 @@
1
+ import { ChangeResourceRecordSetsCommand, ListHostedZonesByNameCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
2
+ import { fromIni } from "@aws-sdk/credential-providers";
3
+ //#region src/dns/route53.ts
4
+ /**
5
+ * Route53 DNS Provider
6
+ *
7
+ * Implements DnsProvider interface using AWS Route53.
8
+ */
9
+ /**
10
+ * Route53 DNS provider implementation.
11
+ *
12
+ * Uses AWS default credential chain for authentication.
13
+ * Region can be specified or will use AWS_REGION/AWS_DEFAULT_REGION env vars.
14
+ * Profile can be specified to use a named profile from ~/.aws/credentials.
15
+ */
16
+ var Route53Provider = class {
17
+ name = "route53";
18
+ client;
19
+ hostedZoneId;
20
+ hostedZoneCache = /* @__PURE__ */ new Map();
21
+ constructor(options = {}) {
22
+ const region = options.region ?? process.env.AWS_REGION ?? "us-east-1";
23
+ this.client = new Route53Client({
24
+ region,
25
+ ...options.endpoint && { endpoint: options.endpoint },
26
+ ...options.profile && { credentials: fromIni({ profile: options.profile }) }
27
+ });
28
+ this.hostedZoneId = options.hostedZoneId;
29
+ }
30
+ /**
31
+ * Get the hosted zone ID for a domain.
32
+ * Uses cache to avoid repeated API calls.
33
+ */
34
+ async getHostedZoneId(domain) {
35
+ if (this.hostedZoneId) return this.hostedZoneId;
36
+ if (this.hostedZoneCache.has(domain)) return this.hostedZoneCache.get(domain);
37
+ const command = new ListHostedZonesByNameCommand({
38
+ DNSName: domain,
39
+ MaxItems: 1
40
+ });
41
+ const zones = (await this.client.send(command)).HostedZones ?? [];
42
+ const normalizedDomain = domain.endsWith(".") ? domain : `${domain}.`;
43
+ const zone = zones.find((z) => z.Name === normalizedDomain);
44
+ if (!zone?.Id) throw new Error(`No hosted zone found for domain: ${domain}. Create one in Route53 or provide hostedZoneId in config.`);
45
+ const zoneId = zone.Id.replace("/hostedzone/", "");
46
+ this.hostedZoneCache.set(domain, zoneId);
47
+ return zoneId;
48
+ }
49
+ /**
50
+ * Convert Route53 record type to our DnsRecordType.
51
+ * Excludes NS and SOA which are auto-managed by Route53 for the zone.
52
+ */
53
+ toRecordType(type) {
54
+ if (["NS", "SOA"].includes(type)) return null;
55
+ return [
56
+ "A",
57
+ "AAAA",
58
+ "CNAME",
59
+ "MX",
60
+ "TXT",
61
+ "SRV",
62
+ "CAA"
63
+ ].includes(type) ? type : null;
64
+ }
65
+ /**
66
+ * Extract subdomain from full record name relative to domain.
67
+ */
68
+ extractSubdomain(recordName, domain) {
69
+ const normalizedDomain = domain.endsWith(".") ? domain : `${domain}.`;
70
+ const normalizedName = recordName.endsWith(".") ? recordName : `${recordName}.`;
71
+ if (normalizedName === normalizedDomain) return "@";
72
+ return normalizedName.replace(`.${normalizedDomain}`, "").replace(/\.$/, "").replace(/\\(\d{3})/g, (_, code) => String.fromCharCode(Number.parseInt(code, 8)));
73
+ }
74
+ async getRecords(domain) {
75
+ const zoneId = await this.getHostedZoneId(domain);
76
+ const records = [];
77
+ let nextRecordName;
78
+ let nextRecordType;
79
+ do {
80
+ const command = new ListResourceRecordSetsCommand({
81
+ HostedZoneId: zoneId,
82
+ StartRecordName: nextRecordName,
83
+ StartRecordType: nextRecordType,
84
+ MaxItems: 100
85
+ });
86
+ const response = await this.client.send(command);
87
+ for (const recordSet of response.ResourceRecordSets ?? []) {
88
+ const type = this.toRecordType(recordSet.Type ?? "");
89
+ if (!type || !recordSet.Name) continue;
90
+ const values = (recordSet.ResourceRecords ?? []).map((r) => r.Value).filter((v) => !!v);
91
+ records.push({
92
+ name: this.extractSubdomain(recordSet.Name, domain),
93
+ type,
94
+ ttl: recordSet.TTL ?? 300,
95
+ values
96
+ });
97
+ }
98
+ if (response.IsTruncated) {
99
+ nextRecordName = response.NextRecordName;
100
+ nextRecordType = response.NextRecordType;
101
+ } else nextRecordName = void 0;
102
+ } while (nextRecordName);
103
+ return records;
104
+ }
105
+ async upsertRecords(domain, records) {
106
+ const zoneId = await this.getHostedZoneId(domain);
107
+ const results = [];
108
+ const existingRecords = await this.getRecords(domain);
109
+ const batchSize = 100;
110
+ for (let i = 0; i < records.length; i += batchSize) {
111
+ const batch = records.slice(i, i + batchSize);
112
+ const changes = [];
113
+ for (const record of batch) {
114
+ const existing = existingRecords.find((r) => r.name === record.name && r.type === record.type);
115
+ const existingValue = existing?.values?.[0];
116
+ if (existing && existingValue === record.value) {
117
+ results.push({
118
+ record,
119
+ created: false,
120
+ unchanged: true
121
+ });
122
+ continue;
123
+ }
124
+ const recordName = record.name === "@" ? domain : `${record.name}.${domain}`;
125
+ changes.push({
126
+ Action: "UPSERT",
127
+ ResourceRecordSet: {
128
+ Name: recordName,
129
+ Type: record.type,
130
+ TTL: record.ttl,
131
+ ResourceRecords: [{ Value: record.value }]
132
+ }
133
+ });
134
+ results.push({
135
+ record,
136
+ created: !existing,
137
+ unchanged: false
138
+ });
139
+ }
140
+ if (changes.length > 0) {
141
+ const command = new ChangeResourceRecordSetsCommand({
142
+ HostedZoneId: zoneId,
143
+ ChangeBatch: {
144
+ Comment: "Upsert by gkm deploy",
145
+ Changes: changes
146
+ }
147
+ });
148
+ await this.client.send(command);
149
+ }
150
+ }
151
+ return results;
152
+ }
153
+ async deleteRecords(domain, records) {
154
+ const zoneId = await this.getHostedZoneId(domain);
155
+ const results = [];
156
+ const existingRecords = await this.getRecords(domain);
157
+ const batchSize = 100;
158
+ for (let i = 0; i < records.length; i += batchSize) {
159
+ const batch = records.slice(i, i + batchSize);
160
+ const changes = [];
161
+ for (const record of batch) {
162
+ const existing = existingRecords.find((r) => r.name === record.name && r.type === record.type);
163
+ if (!existing) {
164
+ results.push({
165
+ record,
166
+ deleted: false,
167
+ notFound: true
168
+ });
169
+ continue;
170
+ }
171
+ const recordName = record.name === "@" ? domain : `${record.name}.${domain}`;
172
+ changes.push({
173
+ Action: "DELETE",
174
+ ResourceRecordSet: {
175
+ Name: recordName,
176
+ Type: record.type,
177
+ TTL: existing.ttl,
178
+ ResourceRecords: existing.values.map((v) => ({ Value: v }))
179
+ }
180
+ });
181
+ results.push({
182
+ record,
183
+ deleted: true,
184
+ notFound: false
185
+ });
186
+ }
187
+ if (changes.length > 0) try {
188
+ const command = new ChangeResourceRecordSetsCommand({
189
+ HostedZoneId: zoneId,
190
+ ChangeBatch: {
191
+ Comment: "Delete by gkm undeploy",
192
+ Changes: changes
193
+ }
194
+ });
195
+ await this.client.send(command);
196
+ } catch (error) {
197
+ for (const result of results.slice(-changes.length)) if (result.deleted) {
198
+ result.deleted = false;
199
+ result.error = String(error);
200
+ }
201
+ }
202
+ }
203
+ return results;
204
+ }
205
+ };
206
+ //#endregion
207
+ export { Route53Provider };
208
+
209
+ //# sourceMappingURL=route53.mjs.map