@stacksjs/dns 0.59.11 → 0.61.1

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/index.js CHANGED
@@ -2,22 +2,26 @@
2
2
  // src/drivers/aws.ts
3
3
  import {Route53} from "@aws-sdk/client-route-53";
4
4
  import {Route53Domains} from "@aws-sdk/client-route-53-domains";
5
- import {err, handleError, ok} from "@stacksjs/error-handling";
6
- import {log} from "@stacksjs/logging";
7
5
  import {runAction} from "@stacksjs/actions";
8
- import {fs} from "@stacksjs/storage";
9
6
  import {config as config2} from "@stacksjs/config";
10
- import {path as p} from "@stacksjs/path";
11
7
  import {Action} from "@stacksjs/enums";
8
+ import {err, handleError, ok} from "@stacksjs/error-handling";
9
+ import {log} from "@stacksjs/logging";
10
+ import {path as p} from "@stacksjs/path";
11
+ import {fs} from "@stacksjs/storage";
12
12
  async function deleteHostedZone(domainName) {
13
13
  const route53 = new Route53;
14
- const hostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
14
+ const hostedZones = await route53.listHostedZonesByName({
15
+ DNSName: domainName
16
+ });
15
17
  if (!hostedZones || !hostedZones.HostedZones)
16
18
  return err(`No hosted zones found for domain: ${domainName}`);
17
19
  const hostedZone = hostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`);
18
20
  if (!hostedZone)
19
21
  return err(`Hosted Zone not found for domain: ${domainName}`);
20
- const recordSets = await route53.listResourceRecordSets({ HostedZoneId: hostedZone.Id });
22
+ const recordSets = await route53.listResourceRecordSets({
23
+ HostedZoneId: hostedZone.Id
24
+ });
21
25
  if (!recordSets || !recordSets.ResourceRecordSets)
22
26
  return err(`No DNS records found for domain: ${domainName}`);
23
27
  for (const recordSet of recordSets.ResourceRecordSets) {
@@ -25,10 +29,12 @@ async function deleteHostedZone(domainName) {
25
29
  await route53.changeResourceRecordSets({
26
30
  HostedZoneId: hostedZone.Id,
27
31
  ChangeBatch: {
28
- Changes: [{
29
- Action: "DELETE",
30
- ResourceRecordSet: recordSet
31
- }]
32
+ Changes: [
33
+ {
34
+ Action: "DELETE",
35
+ ResourceRecordSet: recordSet
36
+ }
37
+ ]
32
38
  }
33
39
  });
34
40
  }
@@ -39,13 +45,17 @@ async function deleteHostedZone(domainName) {
39
45
  }
40
46
  async function deleteHostedZoneRecords(domainName) {
41
47
  const route53 = new Route53;
42
- const hostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
48
+ const hostedZones = await route53.listHostedZonesByName({
49
+ DNSName: domainName
50
+ });
43
51
  if (!hostedZones || !hostedZones.HostedZones)
44
52
  return err(`No hosted zones found for domain: ${domainName}`);
45
53
  const hostedZone = hostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`);
46
54
  if (!hostedZone)
47
55
  return err(`Hosted Zone not found for domain: ${domainName}`);
48
- const recordSets = await route53.listResourceRecordSets({ HostedZoneId: hostedZone.Id });
56
+ const recordSets = await route53.listResourceRecordSets({
57
+ HostedZoneId: hostedZone.Id
58
+ });
49
59
  if (!recordSets || !recordSets.ResourceRecordSets)
50
60
  return err(`No DNS records found for domain: ${domainName}`);
51
61
  for (const recordSet of recordSets.ResourceRecordSets) {
@@ -53,10 +63,12 @@ async function deleteHostedZoneRecords(domainName) {
53
63
  await route53.changeResourceRecordSets({
54
64
  HostedZoneId: hostedZone.Id,
55
65
  ChangeBatch: {
56
- Changes: [{
57
- Action: "DELETE",
58
- ResourceRecordSet: recordSet
59
- }]
66
+ Changes: [
67
+ {
68
+ Action: "DELETE",
69
+ ResourceRecordSet: recordSet
70
+ }
71
+ ]
60
72
  }
61
73
  });
62
74
  }
@@ -66,7 +78,9 @@ async function deleteHostedZoneRecords(domainName) {
66
78
  }
67
79
  async function createHostedZone(domainName) {
68
80
  const route53 = new Route53;
69
- const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
81
+ const existingHostedZones = await route53.listHostedZonesByName({
82
+ DNSName: domainName
83
+ });
70
84
  const existingHostedZone = existingHostedZones.HostedZones?.find((zone) => zone.Name === `${domainName}.`);
71
85
  if (existingHostedZone)
72
86
  return ok(existingHostedZone);
@@ -92,7 +106,9 @@ function writeNameserversToConfig(nameservers) {
92
106
  async function findHostedZone(domain) {
93
107
  try {
94
108
  const route53 = new Route53;
95
- const { HostedZones } = await route53.listHostedZonesByName({ DNSName: domain });
109
+ const { HostedZones } = await route53.listHostedZonesByName({
110
+ DNSName: domain
111
+ });
96
112
  if (!HostedZones)
97
113
  return handleError(`No hosted zones found for domain ${domain}`);
98
114
  const hostedZone = HostedZones[0];
@@ -100,8 +116,8 @@ async function findHostedZone(domain) {
100
116
  return ok(hostedZone.Id);
101
117
  return ok(null);
102
118
  } catch (error) {
103
- console.error(`Failed to find hosted zone for domain ${domain}:`, error);
104
- return handleError(`Failed to find hosted zone for domain ${domain}:`, error);
119
+ console.error(error);
120
+ return handleError(`Failed to find hosted zone for domain ${domain}`);
105
121
  }
106
122
  }
107
123
  async function getNameservers(domainName) {
@@ -109,10 +125,13 @@ async function getNameservers(domainName) {
109
125
  return [];
110
126
  try {
111
127
  const route53Domains = new Route53Domains;
112
- const domainDetail = await route53Domains.getDomainDetail({ DomainName: domainName });
128
+ const domainDetail = await route53Domains.getDomainDetail({
129
+ DomainName: domainName
130
+ });
113
131
  return domainDetail?.Nameservers?.map((ns) => ns.Name) || [];
114
132
  } catch (error) {
115
- handleError("Error getting domain detail:", error);
133
+ console.error(error);
134
+ handleError("Error getting domain detail");
116
135
  }
117
136
  }
118
137
  async function updateNameservers(hostedZoneNameservers, domainName) {
@@ -138,12 +157,16 @@ async function hasUserDomainBeenAddedToCloud(domainName) {
138
157
  if (!domainName)
139
158
  domainName = config2.app.url;
140
159
  const route53 = new Route53;
141
- const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
160
+ const existingHostedZones = await route53.listHostedZonesByName({
161
+ DNSName: domainName
162
+ });
142
163
  if (!existingHostedZones || !existingHostedZones.HostedZones)
143
164
  return false;
144
165
  const existingHostedZone = existingHostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`);
145
166
  if (existingHostedZone) {
146
- const hostedZoneDetail = await route53.getHostedZone({ Id: existingHostedZone.Id });
167
+ const hostedZoneDetail = await route53.getHostedZone({
168
+ Id: existingHostedZone.Id
169
+ });
147
170
  const hostedZoneNameservers = hostedZoneDetail.DelegationSet?.NameServers || [];
148
171
  await updateNameservers(hostedZoneNameservers, domainName);
149
172
  return true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/dns",
3
3
  "type": "module",
4
- "version": "0.59.11",
4
+ "version": "0.61.1",
5
5
  "description": "Easily manage your DNS.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
@@ -51,27 +51,27 @@
51
51
  "prepublishOnly": "bun run build"
52
52
  },
53
53
  "peerDependencies": {
54
- "@aws-sdk/client-route-53": "^3.525.0",
55
- "@aws-sdk/client-route-53-domains": "^3.525.0",
54
+ "@aws-sdk/client-route-53": "^3.577.0",
55
+ "@aws-sdk/client-route-53-domains": "^3.577.0",
56
56
  "@stacksjs/actions": "latest",
57
57
  "@stacksjs/error-handling": "latest",
58
58
  "@stacksjs/path": "latest",
59
59
  "@stacksjs/storage": "latest",
60
60
  "@stacksjs/whois": "latest",
61
- "aws-cdk-lib": "^2.131.0"
61
+ "aws-cdk-lib": "^2.142.1"
62
62
  },
63
63
  "dependencies": {
64
- "@aws-sdk/client-route-53": "^3.525.0",
64
+ "@aws-sdk/client-route-53": "^3.577.0",
65
65
  "@stacksjs/actions": "latest",
66
66
  "@stacksjs/error-handling": "latest",
67
67
  "@stacksjs/path": "latest",
68
68
  "@stacksjs/storage": "latest",
69
69
  "@stacksjs/strings": "latest",
70
70
  "@stacksjs/whois": "latest",
71
- "aws-cdk-lib": "^2.131.0"
71
+ "aws-cdk-lib": "^2.142.1"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@stacksjs/development": "latest",
75
- "aws-cdk-lib": "^2.131.0"
75
+ "aws-cdk-lib": "^2.142.1"
76
76
  }
77
77
  }
@@ -1,40 +1,43 @@
1
1
  import { Route53 } from '@aws-sdk/client-route-53'
2
2
  import { Route53Domains } from '@aws-sdk/client-route-53-domains'
3
- import { err, handleError, ok } from '@stacksjs/error-handling'
4
- import { log } from '@stacksjs/logging'
5
3
  import { runAction } from '@stacksjs/actions'
6
- import { fs } from '@stacksjs/storage'
7
4
  import { config } from '@stacksjs/config'
8
- import { path as p } from '@stacksjs/path'
9
5
  import { Action } from '@stacksjs/enums'
6
+ import { err, handleError, ok } from '@stacksjs/error-handling'
7
+ import { log } from '@stacksjs/logging'
8
+ import { path as p } from '@stacksjs/path'
9
+ import { fs } from '@stacksjs/storage'
10
10
  import type { DeployOptions } from '@stacksjs/types'
11
11
 
12
12
  export async function deleteHostedZone(domainName: string) {
13
13
  const route53 = new Route53()
14
14
 
15
15
  // First, we need to get the Hosted Zone ID using the domain name
16
- const hostedZones = await route53.listHostedZonesByName({ DNSName: domainName })
17
- if (!hostedZones || !hostedZones.HostedZones)
18
- return err((`No hosted zones found for domain: ${domainName}`))
16
+ const hostedZones = await route53.listHostedZonesByName({
17
+ DNSName: domainName,
18
+ })
19
+ if (!hostedZones || !hostedZones.HostedZones) return err(`No hosted zones found for domain: ${domainName}`)
19
20
 
20
- const hostedZone = hostedZones.HostedZones.find(zone => zone.Name === `${domainName}.`)
21
- if (!hostedZone)
22
- return err((`Hosted Zone not found for domain: ${domainName}`))
21
+ const hostedZone = hostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`)
22
+ if (!hostedZone) return err(`Hosted Zone not found for domain: ${domainName}`)
23
23
 
24
24
  // Delete all record sets
25
- const recordSets = await route53.listResourceRecordSets({ HostedZoneId: hostedZone.Id })
26
- if (!recordSets || !recordSets.ResourceRecordSets)
27
- return err((`No DNS records found for domain: ${domainName}`))
25
+ const recordSets = await route53.listResourceRecordSets({
26
+ HostedZoneId: hostedZone.Id,
27
+ })
28
+ if (!recordSets || !recordSets.ResourceRecordSets) return err(`No DNS records found for domain: ${domainName}`)
28
29
 
29
30
  for (const recordSet of recordSets.ResourceRecordSets) {
30
31
  if (recordSet.Type !== 'NS' && recordSet.Type !== 'SOA') {
31
32
  await route53.changeResourceRecordSets({
32
33
  HostedZoneId: hostedZone.Id,
33
34
  ChangeBatch: {
34
- Changes: [{
35
- Action: 'DELETE',
36
- ResourceRecordSet: recordSet,
37
- }],
35
+ Changes: [
36
+ {
37
+ Action: 'DELETE',
38
+ ResourceRecordSet: recordSet,
39
+ },
40
+ ],
38
41
  },
39
42
  })
40
43
  }
@@ -54,28 +57,31 @@ export async function deleteHostedZoneRecords(domainName: string) {
54
57
  const route53 = new Route53()
55
58
 
56
59
  // First, we need to get the Hosted Zone ID using the domain name
57
- const hostedZones = await route53.listHostedZonesByName({ DNSName: domainName })
58
- if (!hostedZones || !hostedZones.HostedZones)
59
- return err((`No hosted zones found for domain: ${domainName}`))
60
+ const hostedZones = await route53.listHostedZonesByName({
61
+ DNSName: domainName,
62
+ })
63
+ if (!hostedZones || !hostedZones.HostedZones) return err(`No hosted zones found for domain: ${domainName}`)
60
64
 
61
- const hostedZone = hostedZones.HostedZones.find(zone => zone.Name === `${domainName}.`)
62
- if (!hostedZone)
63
- return err((`Hosted Zone not found for domain: ${domainName}`))
65
+ const hostedZone = hostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`)
66
+ if (!hostedZone) return err(`Hosted Zone not found for domain: ${domainName}`)
64
67
 
65
68
  // Delete all record sets
66
- const recordSets = await route53.listResourceRecordSets({ HostedZoneId: hostedZone.Id })
67
- if (!recordSets || !recordSets.ResourceRecordSets)
68
- return err((`No DNS records found for domain: ${domainName}`))
69
+ const recordSets = await route53.listResourceRecordSets({
70
+ HostedZoneId: hostedZone.Id,
71
+ })
72
+ if (!recordSets || !recordSets.ResourceRecordSets) return err(`No DNS records found for domain: ${domainName}`)
69
73
 
70
74
  for (const recordSet of recordSets.ResourceRecordSets) {
71
75
  if (recordSet.Type !== 'NS' && recordSet.Type !== 'SOA') {
72
76
  await route53.changeResourceRecordSets({
73
77
  HostedZoneId: hostedZone.Id,
74
78
  ChangeBatch: {
75
- Changes: [{
76
- Action: 'DELETE',
77
- ResourceRecordSet: recordSet,
78
- }],
79
+ Changes: [
80
+ {
81
+ Action: 'DELETE',
82
+ ResourceRecordSet: recordSet,
83
+ },
84
+ ],
79
85
  },
80
86
  })
81
87
  }
@@ -90,12 +96,13 @@ export async function createHostedZone(domainName: string) {
90
96
  const route53 = new Route53()
91
97
 
92
98
  // Check if the hosted zone already exists
93
- const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName })
94
- const existingHostedZone = existingHostedZones.HostedZones?.find(zone => zone.Name === `${domainName}.`)
99
+ const existingHostedZones = await route53.listHostedZonesByName({
100
+ DNSName: domainName,
101
+ })
102
+ const existingHostedZone = existingHostedZones.HostedZones?.find((zone) => zone.Name === `${domainName}.`)
95
103
 
96
104
  // if the hosted zone already exists, then we want to
97
- if (existingHostedZone)
98
- return ok(existingHostedZone)
105
+ if (existingHostedZone) return ok(existingHostedZone)
99
106
 
100
107
  // Create the hosted zone
101
108
  const createHostedZoneOutput = await route53.createHostedZone({
@@ -103,8 +110,7 @@ export async function createHostedZone(domainName: string) {
103
110
  CallerReference: `${Date.now()}`,
104
111
  })
105
112
 
106
- if (!createHostedZoneOutput.HostedZone)
107
- return err('Failed to create hosted zone')
113
+ if (!createHostedZoneOutput.HostedZone) return err('Failed to create hosted zone')
108
114
 
109
115
  return ok(createHostedZoneOutput)
110
116
  }
@@ -115,13 +121,12 @@ export function writeNameserversToConfig(nameservers: string[]) {
115
121
  const fileContent = fs.readFileSync(path, 'utf-8')
116
122
  const modifiedContent = fileContent.replace(
117
123
  /nameservers: \[.*?\]/s,
118
- `nameservers: [${nameservers.map(ns => `'${ns}'`).join(', ')}]`,
124
+ `nameservers: [${nameservers.map((ns) => `'${ns}'`).join(', ')}]`,
119
125
  )
120
126
  fs.writeFileSync(path, modifiedContent, 'utf-8')
121
127
 
122
128
  log.info('Nameservers have been set.')
123
- }
124
- catch (err) {
129
+ } catch (err) {
125
130
  console.error('Error updating nameservers:', err)
126
131
  }
127
132
  }
@@ -129,48 +134,51 @@ export function writeNameserversToConfig(nameservers: string[]) {
129
134
  export async function findHostedZone(domain: string) {
130
135
  try {
131
136
  const route53 = new Route53()
132
- const { HostedZones } = await route53.listHostedZonesByName({ DNSName: domain })
137
+ const { HostedZones } = await route53.listHostedZonesByName({
138
+ DNSName: domain,
139
+ })
133
140
 
134
- if (!HostedZones)
135
- return handleError(`No hosted zones found for domain ${domain}`)
141
+ if (!HostedZones) return handleError(`No hosted zones found for domain ${domain}`)
136
142
 
137
143
  // The API returns hosted zones sorted by name in ASCII order,
138
144
  // so the desired hosted zone (if it exists) should be the first one in the list
139
145
  const hostedZone = HostedZones[0]
140
146
 
141
- if (hostedZone && hostedZone.Name === `${domain}.`)
142
- return ok(hostedZone.Id)
147
+ if (hostedZone && hostedZone.Name === `${domain}.`) return ok(hostedZone.Id)
143
148
 
144
149
  return ok(null)
145
- }
146
- catch (error) {
147
- console.error(`Failed to find hosted zone for domain ${domain}:`, error)
148
- return handleError(`Failed to find hosted zone for domain ${domain}:`, error as Error)
150
+ } catch (error) {
151
+ console.error(error)
152
+ return handleError(`Failed to find hosted zone for domain ${domain}`)
149
153
  }
150
154
  }
151
155
 
152
156
  export async function getNameservers(domainName?: string) {
153
- if (!domainName)
154
- return []
157
+ if (!domainName) return []
155
158
 
156
159
  try {
157
160
  const route53Domains = new Route53Domains()
158
- const domainDetail = await route53Domains.getDomainDetail({ DomainName: domainName })
161
+ const domainDetail = await route53Domains.getDomainDetail({
162
+ DomainName: domainName,
163
+ })
159
164
 
160
- return domainDetail?.Nameservers?.map(ns => ns.Name as string) || []
161
- }
162
- catch (error) {
163
- handleError('Error getting domain detail:', error as Error)
165
+ return domainDetail?.Nameservers?.map((ns) => ns.Name as string) || []
166
+ } catch (error) {
167
+ console.error(error)
168
+ handleError('Error getting domain detail')
164
169
  }
165
170
  }
166
171
 
167
172
  export async function updateNameservers(hostedZoneNameservers: string[], domainName?: string) {
168
- if (!domainName)
169
- domainName = config.app.url
173
+ if (!domainName) domainName = config.app.url
170
174
 
171
175
  const domainNameservers = await getNameservers(domainName)
172
176
 
173
- if (domainNameservers && hostedZoneNameservers && JSON.stringify(domainNameservers.sort()) !== JSON.stringify(hostedZoneNameservers.sort())) {
177
+ if (
178
+ domainNameservers &&
179
+ hostedZoneNameservers &&
180
+ JSON.stringify(domainNameservers.sort()) !== JSON.stringify(hostedZoneNameservers.sort())
181
+ ) {
174
182
  log.info('Updating your domain nameservers to match the ones in your hosted zone...')
175
183
  log.debug('Hosted zone nameservers:', hostedZoneNameservers)
176
184
  log.debug('Domain nameservers:', domainNameservers)
@@ -178,7 +186,7 @@ export async function updateNameservers(hostedZoneNameservers: string[], domainN
178
186
 
179
187
  await route53Domains.updateDomainNameservers({
180
188
  DomainName: domainName,
181
- Nameservers: hostedZoneNameservers.map(ns => ({ Name: ns })),
189
+ Nameservers: hostedZoneNameservers.map((ns) => ({ Name: ns })),
182
190
  })
183
191
 
184
192
  writeNameserversToConfig(hostedZoneNameservers)
@@ -192,21 +200,23 @@ export async function updateNameservers(hostedZoneNameservers: string[], domainN
192
200
 
193
201
  // please note, this function also updates the user's nameservers if they are out of date
194
202
  export async function hasUserDomainBeenAddedToCloud(domainName?: string) {
195
- if (!domainName)
196
- domainName = config.app.url
203
+ if (!domainName) domainName = config.app.url
197
204
 
198
205
  const route53 = new Route53()
199
206
 
200
207
  // check if the hosted zone already exists
201
- const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName })
208
+ const existingHostedZones = await route53.listHostedZonesByName({
209
+ DNSName: domainName,
210
+ })
202
211
 
203
- if (!existingHostedZones || !existingHostedZones.HostedZones)
204
- return false
212
+ if (!existingHostedZones || !existingHostedZones.HostedZones) return false
205
213
 
206
- const existingHostedZone = existingHostedZones.HostedZones.find(zone => zone.Name === `${domainName}.`)
214
+ const existingHostedZone = existingHostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`)
207
215
 
208
216
  if (existingHostedZone) {
209
- const hostedZoneDetail = await route53.getHostedZone({ Id: existingHostedZone.Id })
217
+ const hostedZoneDetail = await route53.getHostedZone({
218
+ Id: existingHostedZone.Id,
219
+ })
210
220
  const hostedZoneNameservers = hostedZoneDetail.DelegationSet?.NameServers || []
211
221
 
212
222
  await updateNameservers(hostedZoneNameservers, domainName)
package/src/index.ts CHANGED
@@ -10,7 +10,6 @@
10
10
  // if (!app.url)
11
11
  // throw new Error('./config app.url is not defined')
12
12
 
13
- // // eslint-disable-next-line no-new
14
13
  // new route53.PublicHostedZone(this, 'HostedZone', {
15
14
  // zoneName: app.url,
16
15
  // })
@@ -1,10 +0,0 @@
1
- import type { DeployOptions } from '@stacksjs/types';
2
- export declare function deleteHostedZone(domainName: string): Promise<import("neverthrow").Err<never, string> | import("neverthrow").Ok<string, never>>;
3
- export declare function deleteHostedZoneRecords(domainName: string): Promise<import("neverthrow").Err<never, string> | import("neverthrow").Ok<string, never>>;
4
- export declare function createHostedZone(domainName: string): Promise<import("neverthrow").Err<never, string> | import("neverthrow").Ok<import("@aws-sdk/client-route-53").HostedZone, never> | import("neverthrow").Ok<import("@aws-sdk/client-route-53").CreateHostedZoneCommandOutput, never>>;
5
- export declare function writeNameserversToConfig(nameservers: string[]): void;
6
- export declare function findHostedZone(domain: string): Promise<Error | import("neverthrow").Ok<string | undefined, never> | import("neverthrow").Ok<null, never>>;
7
- export declare function getNameservers(domainName?: string): Promise<string[] | undefined>;
8
- export declare function updateNameservers(hostedZoneNameservers: string[], domainName?: string): Promise<true | undefined>;
9
- export declare function hasUserDomainBeenAddedToCloud(domainName?: string): Promise<boolean>;
10
- export declare function addDomain(options: DeployOptions): Promise<any>;
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './drivers/aws';