@stacksjs/dns 0.57.4 โ†’ 0.58.20

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/README.md CHANGED
@@ -12,7 +12,7 @@ Easily manage your domains.
12
12
  ## ๐Ÿค– Usage
13
13
 
14
14
  ```bash
15
- pnpm i -D @stacksjs/dns
15
+ bun install -d @stacksjs/dns
16
16
  ```
17
17
 
18
18
  Now, you can use it in your project:
@@ -28,7 +28,7 @@ Learn more in the docs.
28
28
  ## ๐Ÿงช Testing
29
29
 
30
30
  ```bash
31
- pnpm test
31
+ bun test
32
32
  ```
33
33
 
34
34
  ## ๐Ÿ“ˆ Changelog
@@ -47,10 +47,10 @@ For help, discussion about best practices, or any other conversation that would
47
47
 
48
48
  For casual chit-chat with others using this package:
49
49
 
50
- [Join the Stacks Discord Server](https://discord.ow3.org)
50
+ [Join the Stacks Discord Server](https://discord.gg/stacksjs)
51
51
 
52
52
  ## ๐Ÿ“„ License
53
53
 
54
54
  The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
55
55
 
56
- Made with โค๏ธ
56
+ Made with ๐Ÿ’™
package/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ // @bun
2
+ // src/drivers/aws.ts
3
+ import {Route53} from "@aws-sdk/client-route-53";
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
+ import {runAction} from "@stacksjs/actions";
8
+ import {fs} from "@stacksjs/storage";
9
+ import {config as config2} from "@stacksjs/config";
10
+ import {path as p} from "@stacksjs/path";
11
+ import {Action} from "@stacksjs/enums";
12
+ async function deleteHostedZone(domainName) {
13
+ const route53 = new Route53;
14
+ const hostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
15
+ if (!hostedZones || !hostedZones.HostedZones)
16
+ return err(`No hosted zones found for domain: ${domainName}`);
17
+ const hostedZone = hostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`);
18
+ if (!hostedZone)
19
+ return err(`Hosted Zone not found for domain: ${domainName}`);
20
+ const recordSets = await route53.listResourceRecordSets({ HostedZoneId: hostedZone.Id });
21
+ if (!recordSets || !recordSets.ResourceRecordSets)
22
+ return err(`No DNS records found for domain: ${domainName}`);
23
+ for (const recordSet of recordSets.ResourceRecordSets) {
24
+ if (recordSet.Type !== "NS" && recordSet.Type !== "SOA") {
25
+ await route53.changeResourceRecordSets({
26
+ HostedZoneId: hostedZone.Id,
27
+ ChangeBatch: {
28
+ Changes: [{
29
+ Action: "DELETE",
30
+ ResourceRecordSet: recordSet
31
+ }]
32
+ }
33
+ });
34
+ }
35
+ }
36
+ await route53.deleteHostedZone({ Id: hostedZone.Id });
37
+ log.info(`Deleted Hosted Zone for domain: ${domainName}`);
38
+ return ok("success");
39
+ }
40
+ async function deleteHostedZoneRecords(domainName) {
41
+ const route53 = new Route53;
42
+ const hostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
43
+ if (!hostedZones || !hostedZones.HostedZones)
44
+ return err(`No hosted zones found for domain: ${domainName}`);
45
+ const hostedZone = hostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`);
46
+ if (!hostedZone)
47
+ return err(`Hosted Zone not found for domain: ${domainName}`);
48
+ const recordSets = await route53.listResourceRecordSets({ HostedZoneId: hostedZone.Id });
49
+ if (!recordSets || !recordSets.ResourceRecordSets)
50
+ return err(`No DNS records found for domain: ${domainName}`);
51
+ for (const recordSet of recordSets.ResourceRecordSets) {
52
+ if (recordSet.Type !== "NS" && recordSet.Type !== "SOA") {
53
+ await route53.changeResourceRecordSets({
54
+ HostedZoneId: hostedZone.Id,
55
+ ChangeBatch: {
56
+ Changes: [{
57
+ Action: "DELETE",
58
+ ResourceRecordSet: recordSet
59
+ }]
60
+ }
61
+ });
62
+ }
63
+ }
64
+ log.info(`Deleted DNS records for domain: ${domainName}`);
65
+ return ok("success");
66
+ }
67
+ async function createHostedZone(domainName) {
68
+ const route53 = new Route53;
69
+ const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
70
+ const existingHostedZone = existingHostedZones.HostedZones?.find((zone) => zone.Name === `${domainName}.`);
71
+ if (existingHostedZone)
72
+ return ok(existingHostedZone);
73
+ const createHostedZoneOutput = await route53.createHostedZone({
74
+ Name: domainName,
75
+ CallerReference: `${Date.now()}`
76
+ });
77
+ if (!createHostedZoneOutput.HostedZone)
78
+ return err("Failed to create hosted zone");
79
+ return ok(createHostedZoneOutput);
80
+ }
81
+ function writeNameserversToConfig(nameservers) {
82
+ try {
83
+ const path2 = p.projectConfigPath("dns.ts");
84
+ const fileContent = fs.readFileSync(path2, "utf-8");
85
+ const modifiedContent = fileContent.replace(/nameservers: \[.*?\]/s, `nameservers: [${nameservers.map((ns) => `'${ns}'`).join(", ")}]`);
86
+ fs.writeFileSync(path2, modifiedContent, "utf-8");
87
+ log.info("Nameservers have been set.");
88
+ } catch (err2) {
89
+ console.error("Error updating nameservers:", err2);
90
+ }
91
+ }
92
+ async function findHostedZone(domain) {
93
+ try {
94
+ const route53 = new Route53;
95
+ const { HostedZones } = await route53.listHostedZonesByName({ DNSName: domain });
96
+ if (!HostedZones)
97
+ return handleError(`No hosted zones found for domain ${domain}`);
98
+ const hostedZone = HostedZones[0];
99
+ if (hostedZone && hostedZone.Name === `${domain}.`)
100
+ return ok(hostedZone.Id);
101
+ return ok(null);
102
+ } 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);
105
+ }
106
+ }
107
+ async function getNameservers(domainName) {
108
+ if (!domainName)
109
+ return [];
110
+ try {
111
+ const route53Domains = new Route53Domains;
112
+ const domainDetail = await route53Domains.getDomainDetail({ DomainName: domainName });
113
+ return domainDetail?.Nameservers?.map((ns) => ns.Name) || [];
114
+ } catch (error) {
115
+ handleError("Error getting domain detail:", error);
116
+ }
117
+ }
118
+ async function updateNameservers(hostedZoneNameservers, domainName) {
119
+ if (!domainName)
120
+ domainName = config2.app.url;
121
+ const domainNameservers = await getNameservers(domainName);
122
+ if (domainNameservers && hostedZoneNameservers && JSON.stringify(domainNameservers.sort()) !== JSON.stringify(hostedZoneNameservers.sort())) {
123
+ log.info("Updating your domain nameservers to match the ones in your hosted zone...");
124
+ log.debug("Hosted zone nameservers:", hostedZoneNameservers);
125
+ log.debug("Domain nameservers:", domainNameservers);
126
+ const route53Domains = new Route53Domains;
127
+ await route53Domains.updateDomainNameservers({
128
+ DomainName: domainName,
129
+ Nameservers: hostedZoneNameservers.map((ns) => ({ Name: ns }))
130
+ });
131
+ writeNameserversToConfig(hostedZoneNameservers);
132
+ log.info("Nameservers updated.");
133
+ return true;
134
+ }
135
+ log.success("Your nameservers are up to date.");
136
+ }
137
+ async function hasUserDomainBeenAddedToCloud(domainName) {
138
+ if (!domainName)
139
+ domainName = config2.app.url;
140
+ const route53 = new Route53;
141
+ const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName });
142
+ if (!existingHostedZones || !existingHostedZones.HostedZones)
143
+ return false;
144
+ const existingHostedZone = existingHostedZones.HostedZones.find((zone) => zone.Name === `${domainName}.`);
145
+ if (existingHostedZone) {
146
+ const hostedZoneDetail = await route53.getHostedZone({ Id: existingHostedZone.Id });
147
+ const hostedZoneNameservers = hostedZoneDetail.DelegationSet?.NameServers || [];
148
+ await updateNameservers(hostedZoneNameservers, domainName);
149
+ return true;
150
+ }
151
+ return false;
152
+ }
153
+ async function addDomain(options) {
154
+ return await runAction(Action.DomainsAdd, options);
155
+ }
156
+ export {
157
+ writeNameserversToConfig,
158
+ updateNameservers,
159
+ hasUserDomainBeenAddedToCloud,
160
+ getNameservers,
161
+ findHostedZone,
162
+ deleteHostedZoneRecords,
163
+ deleteHostedZone,
164
+ createHostedZone,
165
+ addDomain
166
+ };
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@stacksjs/dns",
3
3
  "type": "module",
4
- "version": "0.57.4",
5
- "packageManager": "pnpm@8.6.6",
4
+ "version": "0.58.20",
6
5
  "description": "Easily manage your DNS.",
7
6
  "author": "Chris Breuer",
8
7
  "license": "MIT",
9
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
10
- "homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/dns#readme",
9
+ "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/src/dns#readme",
11
10
  "repository": {
12
11
  "type": "git",
13
12
  "url": "git+https://github.com/stacksjs/stacks.git",
14
- "directory": "./.stacks/core/dns"
13
+ "directory": "./storage/framework/core/src/dns"
15
14
  },
16
15
  "bugs": {
17
16
  "url": "https://github.com/stacksjs/stacks/issues"
@@ -30,26 +29,48 @@
30
29
  ],
31
30
  "exports": {
32
31
  ".": {
33
- "types": "./dist/index.d.ts",
34
- "import": "./dist/index.mjs"
32
+ "bun": "./src/index.ts",
33
+ "import": "./dist/index.js"
34
+ },
35
+ "./*": {
36
+ "bun": "./src/*",
37
+ "import": "./dist/*"
35
38
  }
36
39
  },
37
40
  "contributors": [
38
- "Chris Breuer <chris@ow3.org>"
41
+ "Chris Breuer <chris@stacksjs.org>"
39
42
  ],
40
43
  "files": [
41
- "dist",
42
- "README.md"
44
+ "README.md",
45
+ "dist"
43
46
  ],
47
+ "scripts": {
48
+ "build": "bun --bun build.ts",
49
+ "typecheck": "bun --bun tsc --noEmit",
50
+ "prepublishOnly": "bun --bun run build"
51
+ },
52
+ "peerDependencies": {
53
+ "@aws-sdk/client-route-53": "^3.490.0",
54
+ "@aws-sdk/client-route-53-domains": "^3.490.0",
55
+ "@stacksjs/actions": "workspace:*",
56
+ "@stacksjs/error-handling": "workspace:*",
57
+ "@stacksjs/path": "workspace:*",
58
+ "@stacksjs/storage": "workspace:*",
59
+ "@stacksjs/whois": "workspace:*",
60
+ "aws-cdk-lib": "^2.119.0"
61
+ },
44
62
  "dependencies": {
45
- "@aws-cdk/aws-route53": "^1.203.0"
63
+ "@aws-sdk/client-route-53": "^3.490.0",
64
+ "@stacksjs/actions": "workspace:*",
65
+ "@stacksjs/error-handling": "workspace:*",
66
+ "@stacksjs/path": "workspace:*",
67
+ "@stacksjs/storage": "workspace:*",
68
+ "@stacksjs/strings": "workspace:*",
69
+ "@stacksjs/whois": "workspace:*",
70
+ "aws-cdk-lib": "^2.119.0"
46
71
  },
47
72
  "devDependencies": {
48
- "@stacksjs/development": "0.57.4"
49
- },
50
- "scripts": {
51
- "build": "unbuild",
52
- "dev": "unbuild --stub",
53
- "typecheck": "tsc --noEmit"
73
+ "@stacksjs/development": "workspace:*",
74
+ "aws-cdk-lib": "^2.119.0"
54
75
  }
55
- }
76
+ }
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) 2022 Open Web Foundation
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { Construct, NestedStackProps } from '@aws-cdk/core';
2
- import { NestedStack } from '@aws-cdk/core';
3
- export declare class DnsStack extends NestedStack {
4
- constructor(scope: Construct, id: string, props?: NestedStackProps);
5
- }
package/dist/index.mjs DELETED
@@ -1,13 +0,0 @@
1
- import { NestedStack } from "@aws-cdk/core";
2
- import * as route53 from "@aws-cdk/aws-route53";
3
- import { app } from "@stacksjs/config";
4
- export class DnsStack extends NestedStack {
5
- constructor(scope, id, props) {
6
- super(scope, id, props);
7
- if (!app.url)
8
- throw new Error("./config app.url is not defined");
9
- new route53.PublicHostedZone(this, "HostedZone", {
10
- zoneName: app.url
11
- });
12
- }
13
- }