@stacksjs/dns 0.70.44 → 0.70.53
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/LICENSE.md +21 -0
- package/dist/index.js +3 -3
- package/dist/src/index.d.ts +0 -1
- package/package.json +8 -8
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 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.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{runAction as
|
|
3
|
-
${
|
|
4
|
-
`)}`))}return
|
|
2
|
+
import{runAction as O}from"@stacksjs/actions";import{config as y}from"@stacksjs/config";import{Action as b}from"@stacksjs/enums";import{err as Q,handleError as P,ok as V}from"@stacksjs/error-handling";import{log as K}from"@stacksjs/logging";import{path as D}from"@stacksjs/path";import{fs as $}from"@stacksjs/storage";import{Route53Client as W,Route53DomainsClient as J}from"@stacksjs/ts-cloud";function T(q){if(!q)return;return q.replace(/^https?:\/\//,"").replace(/\/$/,"")}async function A(q,B){let I=await q.listHostedZonesByName({DNSName:B});if(!I||!I.HostedZones||I.HostedZones.length===0)return Q(P(`No hosted zones found for domain: ${B}`));let G=I.HostedZones.find((U)=>U.Name===`${B}.`);if(!G)return Q(P(`Hosted Zone not found for domain: ${B}`));let L=await q.listResourceRecordSets({HostedZoneId:G.Id});if(!L||!L.ResourceRecordSets)return Q(P(`No DNS records found for domain: ${B}`));let M=L.ResourceRecordSets.filter((U)=>U.Type!=="NS"&&U.Type!=="SOA").map((U)=>({Action:"DELETE",ResourceRecordSet:U}));if(M.length>0)try{await q.changeResourceRecordSets({HostedZoneId:G.Id,ChangeBatch:{Changes:M}})}catch(U){K.warn(`Batch delete failed (${M.length} records), falling back to individual deletion`);let X=[];for(let Y of M)try{await q.changeResourceRecordSets({HostedZoneId:G.Id,ChangeBatch:{Changes:[Y]}})}catch(F){X.push(`${Y.ResourceRecordSet.Name} (${Y.ResourceRecordSet.Type}): ${F.message}`)}if(X.length>0)return Q(P(`Failed to delete ${X.length} DNS record(s):
|
|
3
|
+
${X.join(`
|
|
4
|
+
`)}`))}return V(G)}async function H(q){let B=new W,I=await A(B,q);if(I.isErr)return Q(P(`Failed to delete records for zone: ${q}`));let G=I.unwrap();return await B.deleteHostedZone({Id:G.Id}),K.info(`Deleted Hosted Zone for domain: ${q}`),V("success")}async function v(q){let B=new W;if((await A(B,q)).isErr)return Q(P(`Failed to delete records for zone: ${q}`));return K.info(`Deleted DNS records for domain: ${q}`),V("success")}async function c(q){let B=new W,G=(await B.listHostedZonesByName({DNSName:q})).HostedZones?.find((M)=>M.Name===`${q}.`);if(G)return V(G);let L=await B.createHostedZone({Name:q,CallerReference:`${Date.now()}`});if(!L.HostedZone)return Q(P("Failed to create hosted zone"));return V(L)}function w(q){if(!/^[a-zA-Z0-9.-]+$/.test(q))throw Error(`Invalid nameserver value: ${q}`);return q}function _(q){try{let B=D.projectConfigPath("dns.ts"),G=$.readFileSync(B,"utf-8").replace(/nameservers: \[.*?\]/s,`nameservers: [${q.map((L)=>`'${w(L)}'`).join(", ")}]`);$.writeFileSync(B,G,"utf-8"),K.info("Nameservers have been set.")}catch(B){K.error("Error updating nameservers:",B)}}async function Z(q){try{let B=new W,{HostedZones:I}=await B.listHostedZonesByName({DNSName:q});if(!I||I.length===0)return Q(P(`No hosted zones found for domain ${q}`));let G=I[0];if(G&&G.Name===`${q}.`)return V(G.Id);return V(null)}catch(B){return Q(P(`Failed to find hosted zone for domain ${q}`,B))}}async function S(q){if(K.debug("Getting nameservers for domain:",q),!q)return[];try{return(await new J().getDomainDetail({DomainName:q}))?.Nameservers?.map((G)=>G.Name)||[]}catch(B){return K.debug("Domain not registered via Route53 Domains:",B),[]}}async function g(q){K.debug("Getting hosted zone nameservers for domain:",q);try{let B=new W,G=(await B.listHostedZonesByName({DNSName:q})).HostedZones?.find((M)=>M.Name===`${q}.`);if(!G)return K.debug("No hosted zone found for domain:",q),[];return(await B.getHostedZone({Id:G.Id})).DelegationSet?.NameServers||[]}catch(B){return P("Error getting hosted zone nameservers",B),[]}}async function j(q,B){if(!B)B=y.app.url;let I=await S(B);if(!I||I.length===0)return K.debug("Domain is not registered via Route53 Domains - skipping automatic nameserver update"),_(q),!1;if(JSON.stringify(I.sort())!==JSON.stringify(q.sort())){K.info("Updating your domain nameservers to match the ones in your hosted zone..."),K.debug("Hosted zone nameservers:",q),K.debug("Domain nameservers:",I);try{return await new J().updateDomainNameservers({DomainName:B,Nameservers:q.map((L)=>({Name:L}))}),_(q),K.info("Nameservers updated."),!0}catch(G){return K.debug("Failed to update nameservers via Route53 Domains:",G),_(q),!1}}return K.success("Your nameservers are up to date."),!0}async function u(q){if(K.debug("Checking if domain has been added to cloud..."),!q)q=y.app.url;if(q=T(q),!q)return!1;K.debug("domainName:",q);let B=new W,I=await B.listHostedZonesByName({DNSName:q});if(K.debug("Existing hosted zones:",I),!I||!I.HostedZones||I.HostedZones.length===0)return!1;let G=I.HostedZones.find((L)=>L.Name===`${q}.`);if(G){K.debug("Hosted zone found:",G);let M=(await B.getHostedZone({Id:G.Id})).DelegationSet?.NameServers||[];return await j(M,q),!0}return!1}async function h(q){return await O(b.DomainsAdd,q)}export{_ as writeNameserversToConfig,j as updateNameservers,u as hasUserDomainBeenAddedToCloud,S as getNameservers,g as getHostedZoneNameservers,Z as findHostedZone,v as deleteHostedZoneRecords,H as deleteHostedZone,c as createHostedZone,h as addDomain};
|
package/dist/src/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/dns",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.53",
|
|
5
5
|
"description": "Easily manage your DNS.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -52,16 +52,16 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@stacksjs/dnsx": "^0.2.3",
|
|
55
|
-
"@stacksjs/ts-cloud": "^0.
|
|
55
|
+
"@stacksjs/ts-cloud": "^0.7.12"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@stacksjs/actions": "
|
|
58
|
+
"@stacksjs/actions": "0.70.53",
|
|
59
59
|
"better-dx": "^0.2.12",
|
|
60
|
-
"@stacksjs/error-handling": "
|
|
61
|
-
"@stacksjs/path": "
|
|
62
|
-
"@stacksjs/storage": "
|
|
63
|
-
"@stacksjs/strings": "
|
|
64
|
-
"@stacksjs/whois": "
|
|
60
|
+
"@stacksjs/error-handling": "0.70.53",
|
|
61
|
+
"@stacksjs/path": "0.70.53",
|
|
62
|
+
"@stacksjs/storage": "0.70.53",
|
|
63
|
+
"@stacksjs/strings": "0.70.53",
|
|
64
|
+
"@stacksjs/whois": "0.70.53"
|
|
65
65
|
},
|
|
66
66
|
"sideEffects": false
|
|
67
67
|
}
|