@stacksjs/ts-cloud 0.7.5 → 0.7.7
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.
- package/dist/aws/index.js +259 -0
- package/dist/bin/cli.js +231 -231
- package/dist/chunk-0wxyppza.js +146 -0
- package/dist/chunk-3knnr7wh.js +601 -0
- package/dist/chunk-3rsfns7x.js +10427 -0
- package/dist/chunk-93hjhs78.js +1752 -0
- package/dist/chunk-arsh1g5h.js +1749 -0
- package/dist/chunk-b82pbxyp.js +1572 -0
- package/dist/chunk-c6rgvg1j.js +46124 -0
- package/dist/chunk-d2p5n2aq.js +23 -0
- package/dist/chunk-d7p84vz5.js +1699 -0
- package/dist/chunk-eq08r166.js +8 -0
- package/dist/chunk-hsk6fe6x.js +371 -0
- package/dist/chunk-mj1tmhte.js +13 -0
- package/dist/chunk-pegd7rmf.js +10 -0
- package/dist/chunk-pqfzdg68.js +12 -0
- package/dist/chunk-qpj3edwz.js +601 -0
- package/dist/chunk-tjjgajbh.js +1032 -0
- package/dist/chunk-tnztxpcb.js +630 -0
- package/dist/chunk-tt4kxske.js +1788 -0
- package/dist/chunk-v0bahtg2.js +4 -0
- package/dist/chunk-vd87cpvn.js +1754 -0
- package/dist/chunk-x07dz3sd.js +12828 -0
- package/dist/chunk-xzn0ntr0.js +4616 -0
- package/dist/chunk-zn0nxxa8.js +1779 -0
- package/dist/deploy/index.js +87 -0
- package/dist/dns/index.js +31 -0
- package/dist/drivers/index.d.ts +2 -0
- package/dist/drivers/index.js +108 -0
- package/dist/drivers/shared/box-provision.d.ts +102 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4383 -91358
- package/dist/push/index.js +509 -0
- package/dist/ui/index.html +3 -3
- package/dist/ui/server/actions.html +3 -3
- package/dist/ui/server/backups.html +3 -3
- package/dist/ui/server/database.html +3 -3
- package/dist/ui/server/deployments.html +3 -3
- package/dist/ui/server/firewall.html +3 -3
- package/dist/ui/server/logs.html +3 -3
- package/dist/ui/server/services.html +3 -3
- package/dist/ui/server/sites.html +3 -3
- package/dist/ui/server/ssh-keys.html +3 -3
- package/dist/ui/server/terminal.html +3 -3
- package/dist/ui/server/workers.html +3 -3
- package/dist/ui/serverless/alarms.html +3 -3
- package/dist/ui/serverless/assets.html +3 -3
- package/dist/ui/serverless/data.html +3 -3
- package/dist/ui/serverless/deployments.html +3 -3
- package/dist/ui/serverless/functions.html +3 -3
- package/dist/ui/serverless/logs.html +3 -3
- package/dist/ui/serverless/queues.html +3 -3
- package/dist/ui/serverless/scheduler.html +3 -3
- package/dist/ui/serverless/secrets.html +3 -3
- package/dist/ui/serverless/traces.html +3 -3
- package/dist/ui/serverless.html +3 -3
- package/package.json +3 -3
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AWSClient
|
|
3
|
+
} from "./chunk-arsh1g5h.js";
|
|
4
|
+
|
|
5
|
+
// src/aws/route53.ts
|
|
6
|
+
class Route53Client {
|
|
7
|
+
client;
|
|
8
|
+
region;
|
|
9
|
+
constructor(region = "us-east-1") {
|
|
10
|
+
this.region = region;
|
|
11
|
+
this.client = new AWSClient;
|
|
12
|
+
}
|
|
13
|
+
async createHostedZone(params) {
|
|
14
|
+
const callerReference = params.CallerReference || `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
15
|
+
let xmlBody = `<?xml version="1.0" encoding="UTF-8"?>
|
|
16
|
+
<CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
|
|
17
|
+
<Name>${params.Name}</Name>
|
|
18
|
+
<CallerReference>${callerReference}</CallerReference>`;
|
|
19
|
+
if (params.HostedZoneConfig) {
|
|
20
|
+
xmlBody += `
|
|
21
|
+
<HostedZoneConfig>`;
|
|
22
|
+
if (params.HostedZoneConfig.Comment) {
|
|
23
|
+
xmlBody += `
|
|
24
|
+
<Comment>${params.HostedZoneConfig.Comment}</Comment>`;
|
|
25
|
+
}
|
|
26
|
+
if (params.HostedZoneConfig.PrivateZone !== undefined) {
|
|
27
|
+
xmlBody += `
|
|
28
|
+
<PrivateZone>${params.HostedZoneConfig.PrivateZone}</PrivateZone>`;
|
|
29
|
+
}
|
|
30
|
+
xmlBody += `
|
|
31
|
+
</HostedZoneConfig>`;
|
|
32
|
+
}
|
|
33
|
+
if (params.VPC) {
|
|
34
|
+
xmlBody += `
|
|
35
|
+
<VPC>
|
|
36
|
+
<VPCRegion>${params.VPC.VPCRegion}</VPCRegion>
|
|
37
|
+
<VPCId>${params.VPC.VPCId}</VPCId>
|
|
38
|
+
</VPC>`;
|
|
39
|
+
}
|
|
40
|
+
if (params.DelegationSetId) {
|
|
41
|
+
xmlBody += `
|
|
42
|
+
<DelegationSetId>${params.DelegationSetId}</DelegationSetId>`;
|
|
43
|
+
}
|
|
44
|
+
xmlBody += `
|
|
45
|
+
</CreateHostedZoneRequest>`;
|
|
46
|
+
const result = await this.client.request({
|
|
47
|
+
service: "route53",
|
|
48
|
+
region: this.region,
|
|
49
|
+
method: "POST",
|
|
50
|
+
path: "/2013-04-01/hostedzone",
|
|
51
|
+
headers: {
|
|
52
|
+
"content-type": "application/xml"
|
|
53
|
+
},
|
|
54
|
+
body: xmlBody
|
|
55
|
+
});
|
|
56
|
+
return this.parseCreateHostedZoneResponse(result);
|
|
57
|
+
}
|
|
58
|
+
async listHostedZones(params) {
|
|
59
|
+
const queryParams = {};
|
|
60
|
+
if (params?.Marker)
|
|
61
|
+
queryParams.marker = params.Marker;
|
|
62
|
+
if (params?.MaxItems)
|
|
63
|
+
queryParams.maxitems = params.MaxItems;
|
|
64
|
+
const result = await this.client.request({
|
|
65
|
+
service: "route53",
|
|
66
|
+
region: this.region,
|
|
67
|
+
method: "GET",
|
|
68
|
+
path: "/2013-04-01/hostedzone",
|
|
69
|
+
queryParams: Object.keys(queryParams).length > 0 ? queryParams : undefined
|
|
70
|
+
});
|
|
71
|
+
return this.parseListHostedZonesResponse(result);
|
|
72
|
+
}
|
|
73
|
+
async listHostedZonesByName(params) {
|
|
74
|
+
const queryParams = {};
|
|
75
|
+
if (params?.DNSName)
|
|
76
|
+
queryParams.dnsname = params.DNSName;
|
|
77
|
+
if (params?.HostedZoneId)
|
|
78
|
+
queryParams.hostedzoneid = params.HostedZoneId;
|
|
79
|
+
if (params?.MaxItems)
|
|
80
|
+
queryParams.maxitems = params.MaxItems;
|
|
81
|
+
const result = await this.client.request({
|
|
82
|
+
service: "route53",
|
|
83
|
+
region: this.region,
|
|
84
|
+
method: "GET",
|
|
85
|
+
path: "/2013-04-01/hostedzonesbyname",
|
|
86
|
+
queryParams: Object.keys(queryParams).length > 0 ? queryParams : undefined
|
|
87
|
+
});
|
|
88
|
+
return this.parseListHostedZonesResponse(result);
|
|
89
|
+
}
|
|
90
|
+
async getHostedZone(params) {
|
|
91
|
+
const hostedZoneId = params.Id.replace("/hostedzone/", "");
|
|
92
|
+
const result = await this.client.request({
|
|
93
|
+
service: "route53",
|
|
94
|
+
region: this.region,
|
|
95
|
+
method: "GET",
|
|
96
|
+
path: `/2013-04-01/hostedzone/${hostedZoneId}`
|
|
97
|
+
});
|
|
98
|
+
return this.parseGetHostedZoneResponse(result);
|
|
99
|
+
}
|
|
100
|
+
async deleteHostedZone(params) {
|
|
101
|
+
const hostedZoneId = params.Id.replace("/hostedzone/", "");
|
|
102
|
+
await this.client.request({
|
|
103
|
+
service: "route53",
|
|
104
|
+
region: this.region,
|
|
105
|
+
method: "DELETE",
|
|
106
|
+
path: `/2013-04-01/hostedzone/${hostedZoneId}`
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async listResourceRecordSets(params) {
|
|
110
|
+
const hostedZoneId = params.HostedZoneId.replace("/hostedzone/", "");
|
|
111
|
+
const queryParams = {};
|
|
112
|
+
if (params.StartRecordName)
|
|
113
|
+
queryParams.name = params.StartRecordName;
|
|
114
|
+
if (params.StartRecordType)
|
|
115
|
+
queryParams.type = params.StartRecordType;
|
|
116
|
+
if (params.StartRecordIdentifier)
|
|
117
|
+
queryParams.identifier = params.StartRecordIdentifier;
|
|
118
|
+
if (params.MaxItems)
|
|
119
|
+
queryParams.maxitems = params.MaxItems;
|
|
120
|
+
const result = await this.client.request({
|
|
121
|
+
service: "route53",
|
|
122
|
+
region: this.region,
|
|
123
|
+
method: "GET",
|
|
124
|
+
path: `/2013-04-01/hostedzone/${hostedZoneId}/rrset`,
|
|
125
|
+
queryParams: Object.keys(queryParams).length > 0 ? queryParams : undefined
|
|
126
|
+
});
|
|
127
|
+
return this.parseListResourceRecordSetsResponse(result);
|
|
128
|
+
}
|
|
129
|
+
async changeResourceRecordSets(params) {
|
|
130
|
+
const hostedZoneId = params.HostedZoneId.replace("/hostedzone/", "");
|
|
131
|
+
let xmlBody = `<?xml version="1.0" encoding="UTF-8"?>
|
|
132
|
+
<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
|
|
133
|
+
<ChangeBatch>`;
|
|
134
|
+
if (params.ChangeBatch.Comment) {
|
|
135
|
+
xmlBody += `
|
|
136
|
+
<Comment>${this.escapeXml(params.ChangeBatch.Comment)}</Comment>`;
|
|
137
|
+
}
|
|
138
|
+
xmlBody += `
|
|
139
|
+
<Changes>`;
|
|
140
|
+
for (const change of params.ChangeBatch.Changes) {
|
|
141
|
+
xmlBody += `
|
|
142
|
+
<Change>
|
|
143
|
+
<Action>${change.Action}</Action>
|
|
144
|
+
<ResourceRecordSet>
|
|
145
|
+
<Name>${change.ResourceRecordSet.Name}</Name>
|
|
146
|
+
<Type>${change.ResourceRecordSet.Type}</Type>`;
|
|
147
|
+
if (change.ResourceRecordSet.TTL !== undefined) {
|
|
148
|
+
xmlBody += `
|
|
149
|
+
<TTL>${change.ResourceRecordSet.TTL}</TTL>`;
|
|
150
|
+
}
|
|
151
|
+
if (change.ResourceRecordSet.SetIdentifier) {
|
|
152
|
+
xmlBody += `
|
|
153
|
+
<SetIdentifier>${change.ResourceRecordSet.SetIdentifier}</SetIdentifier>`;
|
|
154
|
+
}
|
|
155
|
+
if (change.ResourceRecordSet.Weight !== undefined) {
|
|
156
|
+
xmlBody += `
|
|
157
|
+
<Weight>${change.ResourceRecordSet.Weight}</Weight>`;
|
|
158
|
+
}
|
|
159
|
+
if (change.ResourceRecordSet.Region) {
|
|
160
|
+
xmlBody += `
|
|
161
|
+
<Region>${change.ResourceRecordSet.Region}</Region>`;
|
|
162
|
+
}
|
|
163
|
+
if (change.ResourceRecordSet.Failover) {
|
|
164
|
+
xmlBody += `
|
|
165
|
+
<Failover>${change.ResourceRecordSet.Failover}</Failover>`;
|
|
166
|
+
}
|
|
167
|
+
if (change.ResourceRecordSet.HealthCheckId) {
|
|
168
|
+
xmlBody += `
|
|
169
|
+
<HealthCheckId>${change.ResourceRecordSet.HealthCheckId}</HealthCheckId>`;
|
|
170
|
+
}
|
|
171
|
+
if (change.ResourceRecordSet.ResourceRecords && change.ResourceRecordSet.ResourceRecords.length > 0) {
|
|
172
|
+
xmlBody += `
|
|
173
|
+
<ResourceRecords>`;
|
|
174
|
+
for (const record of change.ResourceRecordSet.ResourceRecords) {
|
|
175
|
+
xmlBody += `
|
|
176
|
+
<ResourceRecord>
|
|
177
|
+
<Value>${this.escapeXml(record.Value)}</Value>
|
|
178
|
+
</ResourceRecord>`;
|
|
179
|
+
}
|
|
180
|
+
xmlBody += `
|
|
181
|
+
</ResourceRecords>`;
|
|
182
|
+
}
|
|
183
|
+
if (change.ResourceRecordSet.AliasTarget) {
|
|
184
|
+
xmlBody += `
|
|
185
|
+
<AliasTarget>
|
|
186
|
+
<HostedZoneId>${change.ResourceRecordSet.AliasTarget.HostedZoneId}</HostedZoneId>
|
|
187
|
+
<DNSName>${change.ResourceRecordSet.AliasTarget.DNSName}</DNSName>
|
|
188
|
+
<EvaluateTargetHealth>${change.ResourceRecordSet.AliasTarget.EvaluateTargetHealth}</EvaluateTargetHealth>
|
|
189
|
+
</AliasTarget>`;
|
|
190
|
+
}
|
|
191
|
+
if (change.ResourceRecordSet.GeoLocation) {
|
|
192
|
+
xmlBody += `
|
|
193
|
+
<GeoLocation>`;
|
|
194
|
+
if (change.ResourceRecordSet.GeoLocation.ContinentCode) {
|
|
195
|
+
xmlBody += `
|
|
196
|
+
<ContinentCode>${change.ResourceRecordSet.GeoLocation.ContinentCode}</ContinentCode>`;
|
|
197
|
+
}
|
|
198
|
+
if (change.ResourceRecordSet.GeoLocation.CountryCode) {
|
|
199
|
+
xmlBody += `
|
|
200
|
+
<CountryCode>${change.ResourceRecordSet.GeoLocation.CountryCode}</CountryCode>`;
|
|
201
|
+
}
|
|
202
|
+
if (change.ResourceRecordSet.GeoLocation.SubdivisionCode) {
|
|
203
|
+
xmlBody += `
|
|
204
|
+
<SubdivisionCode>${change.ResourceRecordSet.GeoLocation.SubdivisionCode}</SubdivisionCode>`;
|
|
205
|
+
}
|
|
206
|
+
xmlBody += `
|
|
207
|
+
</GeoLocation>`;
|
|
208
|
+
}
|
|
209
|
+
xmlBody += `
|
|
210
|
+
</ResourceRecordSet>
|
|
211
|
+
</Change>`;
|
|
212
|
+
}
|
|
213
|
+
xmlBody += `
|
|
214
|
+
</Changes>
|
|
215
|
+
</ChangeBatch>
|
|
216
|
+
</ChangeResourceRecordSetsRequest>`;
|
|
217
|
+
const result = await this.client.request({
|
|
218
|
+
service: "route53",
|
|
219
|
+
region: this.region,
|
|
220
|
+
method: "POST",
|
|
221
|
+
path: `/2013-04-01/hostedzone/${hostedZoneId}/rrset`,
|
|
222
|
+
headers: {
|
|
223
|
+
"content-type": "application/xml"
|
|
224
|
+
},
|
|
225
|
+
body: xmlBody
|
|
226
|
+
});
|
|
227
|
+
return this.parseChangeResourceRecordSetsResponse(result);
|
|
228
|
+
}
|
|
229
|
+
escapeXml(str) {
|
|
230
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
231
|
+
}
|
|
232
|
+
parseCreateHostedZoneResponse(result) {
|
|
233
|
+
const response = result.CreateHostedZoneResponse || result;
|
|
234
|
+
return {
|
|
235
|
+
HostedZone: this.parseHostedZone(response.HostedZone),
|
|
236
|
+
ChangeInfo: {
|
|
237
|
+
Id: response.ChangeInfo?.Id || "",
|
|
238
|
+
Status: response.ChangeInfo?.Status || "",
|
|
239
|
+
SubmittedAt: response.ChangeInfo?.SubmittedAt || ""
|
|
240
|
+
},
|
|
241
|
+
DelegationSet: this.parseDelegationSet(response.DelegationSet),
|
|
242
|
+
Location: response.Location || ""
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
parseListHostedZonesResponse(result) {
|
|
246
|
+
const response = result.ListHostedZonesResponse || result.ListHostedZonesByNameResponse || result;
|
|
247
|
+
let hostedZones = response.HostedZones?.HostedZone || response.HostedZones || [];
|
|
248
|
+
if (!Array.isArray(hostedZones)) {
|
|
249
|
+
hostedZones = hostedZones ? [hostedZones] : [];
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
HostedZones: hostedZones.map((hz) => this.parseHostedZone(hz)),
|
|
253
|
+
IsTruncated: response.IsTruncated === "true" || response.IsTruncated === true,
|
|
254
|
+
MaxItems: response.MaxItems || "100",
|
|
255
|
+
Marker: response.Marker,
|
|
256
|
+
NextMarker: response.NextMarker
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
parseGetHostedZoneResponse(result) {
|
|
260
|
+
const response = result.GetHostedZoneResponse || result;
|
|
261
|
+
return {
|
|
262
|
+
HostedZone: this.parseHostedZone(response.HostedZone),
|
|
263
|
+
DelegationSet: this.parseDelegationSet(response.DelegationSet),
|
|
264
|
+
VPCs: response.VPCs?.VPC ? Array.isArray(response.VPCs.VPC) ? response.VPCs.VPC : [response.VPCs.VPC] : undefined
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
parseListResourceRecordSetsResponse(result) {
|
|
268
|
+
const response = result.ListResourceRecordSetsResponse || result;
|
|
269
|
+
let recordSets = response.ResourceRecordSets?.ResourceRecordSet || response.ResourceRecordSets || [];
|
|
270
|
+
if (!Array.isArray(recordSets)) {
|
|
271
|
+
recordSets = recordSets ? [recordSets] : [];
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
ResourceRecordSets: recordSets.map((rs) => this.parseResourceRecordSet(rs)),
|
|
275
|
+
IsTruncated: response.IsTruncated === "true" || response.IsTruncated === true,
|
|
276
|
+
MaxItems: response.MaxItems || "100",
|
|
277
|
+
NextRecordName: response.NextRecordName,
|
|
278
|
+
NextRecordType: response.NextRecordType,
|
|
279
|
+
NextRecordIdentifier: response.NextRecordIdentifier
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
parseChangeResourceRecordSetsResponse(result) {
|
|
283
|
+
const response = result.ChangeResourceRecordSetsResponse || result;
|
|
284
|
+
return {
|
|
285
|
+
ChangeInfo: {
|
|
286
|
+
Id: response.ChangeInfo?.Id || "",
|
|
287
|
+
Status: response.ChangeInfo?.Status || "",
|
|
288
|
+
SubmittedAt: response.ChangeInfo?.SubmittedAt || "",
|
|
289
|
+
Comment: response.ChangeInfo?.Comment
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
parseHostedZone(hz) {
|
|
294
|
+
if (!hz)
|
|
295
|
+
return { Id: "", Name: "" };
|
|
296
|
+
return {
|
|
297
|
+
Id: hz.Id || "",
|
|
298
|
+
Name: hz.Name || "",
|
|
299
|
+
CallerReference: hz.CallerReference,
|
|
300
|
+
Config: hz.Config ? {
|
|
301
|
+
Comment: hz.Config.Comment,
|
|
302
|
+
PrivateZone: hz.Config.PrivateZone === "true" || hz.Config.PrivateZone === true
|
|
303
|
+
} : undefined,
|
|
304
|
+
ResourceRecordSetCount: hz.ResourceRecordSetCount ? Number(hz.ResourceRecordSetCount) : undefined
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
parseDelegationSet(ds) {
|
|
308
|
+
if (!ds)
|
|
309
|
+
return { NameServers: [] };
|
|
310
|
+
let nameServers = ds.NameServers?.NameServer || ds.NameServers || [];
|
|
311
|
+
if (!Array.isArray(nameServers)) {
|
|
312
|
+
nameServers = nameServers ? [nameServers] : [];
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
Id: ds.Id,
|
|
316
|
+
CallerReference: ds.CallerReference,
|
|
317
|
+
NameServers: nameServers
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
parseResourceRecordSet(rs) {
|
|
321
|
+
if (!rs)
|
|
322
|
+
return { Name: "", Type: "" };
|
|
323
|
+
let resourceRecords = rs.ResourceRecords?.ResourceRecord || rs.ResourceRecords || [];
|
|
324
|
+
if (!Array.isArray(resourceRecords)) {
|
|
325
|
+
resourceRecords = resourceRecords ? [resourceRecords] : [];
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
Name: rs.Name || "",
|
|
329
|
+
Type: rs.Type || "",
|
|
330
|
+
TTL: rs.TTL ? Number(rs.TTL) : undefined,
|
|
331
|
+
ResourceRecords: resourceRecords.map((rr) => ({
|
|
332
|
+
Value: rr.Value || rr
|
|
333
|
+
})),
|
|
334
|
+
AliasTarget: rs.AliasTarget ? {
|
|
335
|
+
HostedZoneId: rs.AliasTarget.HostedZoneId,
|
|
336
|
+
DNSName: rs.AliasTarget.DNSName,
|
|
337
|
+
EvaluateTargetHealth: rs.AliasTarget.EvaluateTargetHealth === "true" || rs.AliasTarget.EvaluateTargetHealth === true
|
|
338
|
+
} : undefined,
|
|
339
|
+
SetIdentifier: rs.SetIdentifier,
|
|
340
|
+
Weight: rs.Weight ? Number(rs.Weight) : undefined,
|
|
341
|
+
Region: rs.Region,
|
|
342
|
+
GeoLocation: rs.GeoLocation,
|
|
343
|
+
Failover: rs.Failover,
|
|
344
|
+
HealthCheckId: rs.HealthCheckId
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
async findHostedZoneByName(domainName) {
|
|
348
|
+
const normalizedDomain = domainName.endsWith(".") ? domainName : `${domainName}.`;
|
|
349
|
+
const result = await this.listHostedZonesByName({ DNSName: normalizedDomain });
|
|
350
|
+
const zone = result.HostedZones.find((z) => z.Name === normalizedDomain);
|
|
351
|
+
return zone || null;
|
|
352
|
+
}
|
|
353
|
+
async createARecord(params) {
|
|
354
|
+
const values = Array.isArray(params.Value) ? params.Value : [params.Value];
|
|
355
|
+
return this.changeResourceRecordSets({
|
|
356
|
+
HostedZoneId: params.HostedZoneId,
|
|
357
|
+
ChangeBatch: {
|
|
358
|
+
Changes: [{
|
|
359
|
+
Action: "UPSERT",
|
|
360
|
+
ResourceRecordSet: {
|
|
361
|
+
Name: params.Name,
|
|
362
|
+
Type: "A",
|
|
363
|
+
TTL: params.TTL || 300,
|
|
364
|
+
ResourceRecords: values.map((v) => ({ Value: v }))
|
|
365
|
+
}
|
|
366
|
+
}]
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
async createCnameRecord(params) {
|
|
371
|
+
return this.changeResourceRecordSets({
|
|
372
|
+
HostedZoneId: params.HostedZoneId,
|
|
373
|
+
ChangeBatch: {
|
|
374
|
+
Changes: [{
|
|
375
|
+
Action: "UPSERT",
|
|
376
|
+
ResourceRecordSet: {
|
|
377
|
+
Name: params.Name,
|
|
378
|
+
Type: "CNAME",
|
|
379
|
+
TTL: params.TTL || 300,
|
|
380
|
+
ResourceRecords: [{ Value: params.Value }]
|
|
381
|
+
}
|
|
382
|
+
}]
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
async createAliasRecord(params) {
|
|
387
|
+
return this.changeResourceRecordSets({
|
|
388
|
+
HostedZoneId: params.HostedZoneId,
|
|
389
|
+
ChangeBatch: {
|
|
390
|
+
Changes: [{
|
|
391
|
+
Action: "UPSERT",
|
|
392
|
+
ResourceRecordSet: {
|
|
393
|
+
Name: params.Name,
|
|
394
|
+
Type: params.Type || "A",
|
|
395
|
+
AliasTarget: {
|
|
396
|
+
HostedZoneId: params.TargetHostedZoneId,
|
|
397
|
+
DNSName: params.TargetDNSName,
|
|
398
|
+
EvaluateTargetHealth: params.EvaluateTargetHealth ?? false
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}]
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
async createTxtRecord(params) {
|
|
406
|
+
const values = Array.isArray(params.Value) ? params.Value : [params.Value];
|
|
407
|
+
const quotedValues = values.map((v) => {
|
|
408
|
+
if (!v.startsWith('"')) {
|
|
409
|
+
return `"${v}"`;
|
|
410
|
+
}
|
|
411
|
+
return v;
|
|
412
|
+
});
|
|
413
|
+
return this.changeResourceRecordSets({
|
|
414
|
+
HostedZoneId: params.HostedZoneId,
|
|
415
|
+
ChangeBatch: {
|
|
416
|
+
Changes: [{
|
|
417
|
+
Action: "UPSERT",
|
|
418
|
+
ResourceRecordSet: {
|
|
419
|
+
Name: params.Name,
|
|
420
|
+
Type: "TXT",
|
|
421
|
+
TTL: params.TTL || 300,
|
|
422
|
+
ResourceRecords: quotedValues.map((v) => ({ Value: v }))
|
|
423
|
+
}
|
|
424
|
+
}]
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async createMxRecord(params) {
|
|
429
|
+
return this.changeResourceRecordSets({
|
|
430
|
+
HostedZoneId: params.HostedZoneId,
|
|
431
|
+
ChangeBatch: {
|
|
432
|
+
Changes: [{
|
|
433
|
+
Action: "UPSERT",
|
|
434
|
+
ResourceRecordSet: {
|
|
435
|
+
Name: params.Name,
|
|
436
|
+
Type: "MX",
|
|
437
|
+
TTL: params.TTL || 300,
|
|
438
|
+
ResourceRecords: params.Values.map((v) => ({
|
|
439
|
+
Value: `${v.priority} ${v.mailServer}`
|
|
440
|
+
}))
|
|
441
|
+
}
|
|
442
|
+
}]
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
async deleteRecord(params) {
|
|
447
|
+
return this.changeResourceRecordSets({
|
|
448
|
+
HostedZoneId: params.HostedZoneId,
|
|
449
|
+
ChangeBatch: {
|
|
450
|
+
Changes: [{
|
|
451
|
+
Action: "DELETE",
|
|
452
|
+
ResourceRecordSet: params.RecordSet
|
|
453
|
+
}]
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
async waitForChange(changeId, maxAttempts = 60, delayMs = 5000) {
|
|
458
|
+
const id = changeId.replace("/change/", "");
|
|
459
|
+
for (let i = 0;i < maxAttempts; i++) {
|
|
460
|
+
const result = await this.client.request({
|
|
461
|
+
service: "route53",
|
|
462
|
+
region: this.region,
|
|
463
|
+
method: "GET",
|
|
464
|
+
path: `/2013-04-01/change/${id}`
|
|
465
|
+
});
|
|
466
|
+
const status = result.GetChangeResponse?.ChangeInfo?.Status || result.ChangeInfo?.Status;
|
|
467
|
+
if (status === "INSYNC") {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
async findOrCreateHostedZone(params) {
|
|
475
|
+
const normalizedDomain = params.domainName.endsWith(".") ? params.domainName : `${params.domainName}.`;
|
|
476
|
+
const existing = await this.findHostedZoneByName(normalizedDomain);
|
|
477
|
+
if (existing) {
|
|
478
|
+
const zoneDetails = await this.getHostedZone({ Id: existing.Id });
|
|
479
|
+
return {
|
|
480
|
+
hostedZone: existing,
|
|
481
|
+
nameServers: zoneDetails.DelegationSet.NameServers,
|
|
482
|
+
isNew: false
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
const result = await this.createHostedZone({
|
|
486
|
+
Name: normalizedDomain,
|
|
487
|
+
HostedZoneConfig: {
|
|
488
|
+
Comment: params.comment || `Hosted zone for ${params.domainName}`,
|
|
489
|
+
PrivateZone: params.privateZone
|
|
490
|
+
},
|
|
491
|
+
VPC: params.vpc
|
|
492
|
+
});
|
|
493
|
+
return {
|
|
494
|
+
hostedZone: result.HostedZone,
|
|
495
|
+
nameServers: result.DelegationSet.NameServers,
|
|
496
|
+
isNew: true
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
static getRootDomain(domain) {
|
|
500
|
+
const parts = domain.replace(/\.$/, "").split(".");
|
|
501
|
+
if (parts.length <= 2) {
|
|
502
|
+
return domain;
|
|
503
|
+
}
|
|
504
|
+
return parts.slice(-2).join(".");
|
|
505
|
+
}
|
|
506
|
+
async findHostedZoneForDomain(domain) {
|
|
507
|
+
const normalizedDomain = domain.replace(/\.$/, "");
|
|
508
|
+
const parts = normalizedDomain.split(".");
|
|
509
|
+
for (let i = 0;i < parts.length - 1; i++) {
|
|
510
|
+
const testDomain = parts.slice(i).join(".");
|
|
511
|
+
const zone = await this.findHostedZoneByName(testDomain);
|
|
512
|
+
if (zone) {
|
|
513
|
+
return zone;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return null;
|
|
517
|
+
}
|
|
518
|
+
async ensureHostedZone(params) {
|
|
519
|
+
const result = await this.findOrCreateHostedZone({
|
|
520
|
+
domainName: params.domainName,
|
|
521
|
+
comment: params.comment
|
|
522
|
+
});
|
|
523
|
+
const hostedZoneId = result.hostedZone.Id.replace("/hostedzone/", "");
|
|
524
|
+
return {
|
|
525
|
+
hostedZoneId,
|
|
526
|
+
nameServers: result.nameServers,
|
|
527
|
+
isNew: result.isNew,
|
|
528
|
+
action: result.isNew ? "created" : "found"
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
async setupDomainDns(params) {
|
|
532
|
+
const { domain, createIfNotExists = true } = params;
|
|
533
|
+
const existing = await this.findHostedZoneByName(domain);
|
|
534
|
+
if (existing) {
|
|
535
|
+
const zoneDetails = await this.getHostedZone({ Id: existing.Id });
|
|
536
|
+
return {
|
|
537
|
+
success: true,
|
|
538
|
+
hostedZoneId: existing.Id.replace("/hostedzone/", ""),
|
|
539
|
+
nameServers: zoneDetails.DelegationSet.NameServers,
|
|
540
|
+
isNew: false,
|
|
541
|
+
message: `Found existing hosted zone for ${domain}`
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (!createIfNotExists) {
|
|
545
|
+
return {
|
|
546
|
+
success: false,
|
|
547
|
+
hostedZoneId: null,
|
|
548
|
+
nameServers: [],
|
|
549
|
+
isNew: false,
|
|
550
|
+
message: `No hosted zone found for ${domain} and createIfNotExists is false`
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const result = await this.createHostedZone({
|
|
554
|
+
Name: domain,
|
|
555
|
+
HostedZoneConfig: {
|
|
556
|
+
Comment: `Created automatically by ts-cloud for ${domain}`
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
return {
|
|
560
|
+
success: true,
|
|
561
|
+
hostedZoneId: result.HostedZone.Id.replace("/hostedzone/", ""),
|
|
562
|
+
nameServers: result.DelegationSet.NameServers,
|
|
563
|
+
isNew: true,
|
|
564
|
+
message: `Created new hosted zone for ${domain}. Please update your domain registrar with these name servers: ${result.DelegationSet.NameServers.join(", ")}`
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
static CloudFrontHostedZoneId = "Z2FDTNDATAQYW2";
|
|
568
|
+
static S3WebsiteHostedZoneIds = {
|
|
569
|
+
"us-east-1": "Z3AQBSTGFYJSTF",
|
|
570
|
+
"us-east-2": "Z2O1EMRO9K5GLX",
|
|
571
|
+
"us-west-1": "Z2F56UZL2M1ACD",
|
|
572
|
+
"us-west-2": "Z3BJ6K6RIION7M",
|
|
573
|
+
"ap-east-1": "ZNB98KWMFR0R6",
|
|
574
|
+
"ap-south-1": "Z11RGJOFQNVJUP",
|
|
575
|
+
"ap-northeast-1": "Z2M4EHUR26P7ZW",
|
|
576
|
+
"ap-northeast-2": "Z3W03O7B5YMIYP",
|
|
577
|
+
"ap-northeast-3": "Z2YQB5RD63NC85",
|
|
578
|
+
"ap-southeast-1": "Z3O0J2DXBE1FTB",
|
|
579
|
+
"ap-southeast-2": "Z1WCIGYICN2BYD",
|
|
580
|
+
"ca-central-1": "Z1QDHH18159H29",
|
|
581
|
+
"eu-central-1": "Z21DNDUVLTQW6Q",
|
|
582
|
+
"eu-west-1": "Z1BKCTXD74EZPE",
|
|
583
|
+
"eu-west-2": "Z3GKZC51ZF0DB4",
|
|
584
|
+
"eu-west-3": "Z3R1K369G5AVDG",
|
|
585
|
+
"eu-north-1": "Z3BAZG2TWCNX0D",
|
|
586
|
+
"sa-east-1": "Z7KQH4QJS55SO"
|
|
587
|
+
};
|
|
588
|
+
static ALBHostedZoneIds = {
|
|
589
|
+
"us-east-1": "Z35SXDOTRQ7X7K",
|
|
590
|
+
"us-east-2": "Z3AADJGX6KTTL2",
|
|
591
|
+
"us-west-1": "Z368ELLRRE2KJ0",
|
|
592
|
+
"us-west-2": "Z1H1FL5HABSF5",
|
|
593
|
+
"ap-east-1": "Z3DQVH9N71FHZ0",
|
|
594
|
+
"ap-south-1": "ZP97RAFLXTNZK",
|
|
595
|
+
"ap-northeast-1": "Z14GRHDCWA56QT",
|
|
596
|
+
"ap-northeast-2": "ZWKZPGTI48KDX",
|
|
597
|
+
"ap-northeast-3": "Z5LXEBD8Y73MNV",
|
|
598
|
+
"ap-southeast-1": "Z1LMS91P8CMLE5",
|
|
599
|
+
"ap-southeast-2": "Z1GM3OXH4ZPM65",
|
|
600
|
+
"ca-central-1": "ZQSVJUPU6J1EY",
|
|
601
|
+
"eu-central-1": "Z215JYRZR1TBD5",
|
|
602
|
+
"eu-west-1": "Z32O12XQLNTSW2",
|
|
603
|
+
"eu-west-2": "ZHURV8PSTC4K8",
|
|
604
|
+
"eu-west-3": "Z3Q77PNBQS71R4",
|
|
605
|
+
"eu-north-1": "Z23TAZ6LKFMNIO",
|
|
606
|
+
"sa-east-1": "Z2P70J7HTTTPLU"
|
|
607
|
+
};
|
|
608
|
+
static APIGatewayHostedZoneIds = {
|
|
609
|
+
"us-east-1": "Z1UJRXOUMOOFQ8",
|
|
610
|
+
"us-east-2": "ZOJJZC49E0EPZ",
|
|
611
|
+
"us-west-1": "Z2MUQ32089INYE",
|
|
612
|
+
"us-west-2": "Z2OJLYMUO9EFXC",
|
|
613
|
+
"ap-east-1": "Z3FD1VL90ND7K5",
|
|
614
|
+
"ap-south-1": "Z3VO1THU9YC4UR",
|
|
615
|
+
"ap-northeast-1": "Z1YSHQZHG15GKL",
|
|
616
|
+
"ap-northeast-2": "Z20JF4UZKIW1U8",
|
|
617
|
+
"ap-northeast-3": "Z2YQB5RD63NC85",
|
|
618
|
+
"ap-southeast-1": "ZL327KTPIQFUL",
|
|
619
|
+
"ap-southeast-2": "Z2RPCDW04V8134",
|
|
620
|
+
"ca-central-1": "Z19DQILCV0OWEC",
|
|
621
|
+
"eu-central-1": "Z1U9ULNL0V5AJ3",
|
|
622
|
+
"eu-west-1": "ZLY8HYME6SFDD",
|
|
623
|
+
"eu-west-2": "ZJ5UAJN8Y3Z2Q",
|
|
624
|
+
"eu-west-3": "Z3KY65QIEKYHQQ",
|
|
625
|
+
"eu-north-1": "Z3UWIKFBOOGXPP",
|
|
626
|
+
"sa-east-1": "ZCMLWB8V5SYIT"
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export { Route53Client };
|