cfdns 2.2.0 → 2.2.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/LICENSE +22 -0
- package/README.md +6 -9
- package/dist/index.js +2 -2
- package/package.json +8 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) silverwind
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
17
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
18
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
19
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
20
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
21
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
22
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# cfdns
|
|
2
|
-
[](https://www.npmjs.org/package/cfdns) [](https://www.npmjs.org/package/cfdns) [](https://packagephobia.com/result?p=cfdns)
|
|
2
|
+
[](https://www.npmjs.org/package/cfdns) [](https://www.npmjs.org/package/cfdns) [](https://packagephobia.com/result?p=cfdns)
|
|
3
3
|
|
|
4
4
|
> CLI to modify DNS records hosted on Cloudflare
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## Usage
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
|
|
9
|
+
pnpm dlx cfdns login user@example.com 4c689aa3462a44a121c1f199c1081240b9be4
|
|
10
|
+
pnpm dlx cfdns set example.com a 1.2.3.4 120
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
+
## Options
|
|
13
14
|
|
|
14
15
|
```
|
|
15
16
|
usage: cfdns [options] command [args]
|
|
@@ -34,10 +35,6 @@ usage: cfdns [options] command [args]
|
|
|
34
35
|
$ cfdns del example.com a
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- Only supports one record per name and type combination
|
|
40
|
-
|
|
41
|
-
## License
|
|
38
|
+
Only one record per name and type combination is supported.
|
|
42
39
|
|
|
43
40
|
© [silverwind](https://github.com/silverwind), distributed under BSD licence
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{parseArgs as e,styleText as t}from"node:util";import{join as n}from"node:path";import{homedir as r}from"node:os";import{chmod as i,readFile as a,unlink as o,writeFile as s}from"node:fs/promises";import{argv as c,exit as l}from"node:process";var u=`2.2.
|
|
2
|
+
import{parseArgs as e,styleText as t}from"node:util";import{join as n}from"node:path";import{homedir as r}from"node:os";import{chmod as i,readFile as a,unlink as o,writeFile as s}from"node:fs/promises";import{argv as c,exit as l}from"node:process";var u=`2.2.1`;function d(t){try{return e(t)}catch(e){return h(e.message)}}const{values:f,positionals:p}=d({args:c.slice(2),options:{color:{type:`boolean`,short:`c`},help:{type:`boolean`,short:`h`},"no-color":{type:`boolean`,short:`n`},version:{type:`boolean`,short:`v`}},allowPositionals:!0,strict:!0});function m(e,n){return f[`no-color`]?n:t(e,n,{validateStream:!f.color})}function h(e){e&&console.info(`Error: ${e}`),l(+!!e)}f.version&&(console.info(u),h());const g={login:[2,2],logout:[0,0],get:[2,2],set:[3,4],add:[3,4],del:[2,2]},[_,...v]=p,y=_&&g[_]&&v.length>=g[_][0]&&v.length<=g[_][1];(f.help||!y)&&(console.info(`usage: cfdns [options] command [args]
|
|
3
3
|
|
|
4
4
|
Commands:
|
|
5
5
|
login <email> <key> Log in to the API
|
|
@@ -18,4 +18,4 @@ import{parseArgs as e,styleText as t}from"node:util";import{join as n}from"node:
|
|
|
18
18
|
$ cfdns login user@example.com 4c689aa3462a44a121c1f199c1081240b9be4
|
|
19
19
|
$ cfdns set example.com a 1.2.3.4 120
|
|
20
20
|
$ cfdns get example.com a
|
|
21
|
-
$ cfdns del example.com a`),h());let b,x;async function S(e,t,n){let r=await fetch(`https://api.cloudflare.com/client/v4/${t}`,{method:e
|
|
21
|
+
$ cfdns del example.com a`),h());let b,x;async function S(e,t,n){let r=await fetch(`https://api.cloudflare.com/client/v4/${t}`,{method:e,headers:{"Content-Type":`application/json`,"X-Auth-Email":b,"X-Auth-Key":x},body:JSON.stringify(n)}),i=await r.json();if(!r.ok)throw Error(`${r.status} ${r.statusText}: ${JSON.stringify(i)}`);return i.result}const C=n(r(),`.cfdnsrc`);if(_===`login`||_===`logout`){if(_===`login`)[b,x]=v,await s(C,JSON.stringify({email:b,key:x})),await i(C,384),console.info(`login data saved`);else try{await o(C),console.info(`login data deleted`)}catch{console.info(`no login data found`)}h()}else try{({email:b,key:x}=JSON.parse(await a(C,`utf8`)))}catch{h(`login data not found, please log in first.`)}const[w,T,E,D]=v,O=T.toUpperCase(),k=D?Number(D):120;let A;for(let e=1;!A;e++){let t=await S(`GET`,`zones?per_page=50&page=${e}`);if(A=t.find(e=>w===e.name||w.endsWith(`.${e.name}`)),t.length<50)break}A||h(`no matching zone found`);const j=(await S(`GET`,`zones/${A.id}/dns_records?name=${w}&type=${O}`))[0];_===`get`?console.info(j):_===`set`||_===`add`?j?E!==j.content||k!==j.ttl?(await S(`PUT`,`zones/${A.id}/dns_records/${j.id}`,{name:w,type:O,content:E,ttl:k,proxied:j.proxied}),console.info(`updated ${m(`magenta`,w)} ${k} IN ${O} ${m(`green`,E)}`)):console.info(`${m(`magenta`,w)} is up to date`):(await S(`POST`,`zones/${A.id}/dns_records`,{name:w,type:O,content:E,ttl:k,proxied:!1}),console.info(`created ${m(`magenta`,w)} ${k} IN ${O} ${m(`green`,E)}`)):_===`del`&&j&&(await S(`DELETE`,`zones/${A.id}/dns_records/${j.id}`),console.info(`deleted ${m(`magenta`,w)} ${j.ttl} IN ${O} ${m(`green`,j.content)}`)),h();export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cfdns",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "CLI to modify DNS records hosted on Cloudflare",
|
|
5
5
|
"author": "silverwind <me@silverwind.io>",
|
|
6
6
|
"repository": {
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"ddns"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "26.6.
|
|
32
|
+
"@types/node": "26.6.3",
|
|
33
33
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
34
34
|
"eslint": "10.11.0",
|
|
35
|
-
"eslint-config-silverwind": "151.0.
|
|
35
|
+
"eslint-config-silverwind": "151.0.1",
|
|
36
36
|
"tsdown": "0.23.0",
|
|
37
|
-
"tsdown-config-silverwind": "4.1.
|
|
37
|
+
"tsdown-config-silverwind": "4.1.2",
|
|
38
38
|
"typescript": "6.0.3",
|
|
39
|
-
"typescript-config-silverwind": "21.0.
|
|
40
|
-
"updates": "19.0.
|
|
41
|
-
"updates-config-silverwind": "4.0.
|
|
42
|
-
"versions": "15.5.
|
|
39
|
+
"typescript-config-silverwind": "21.0.1",
|
|
40
|
+
"updates": "19.0.2",
|
|
41
|
+
"updates-config-silverwind": "4.0.7",
|
|
42
|
+
"versions": "15.5.1"
|
|
43
43
|
}
|
|
44
44
|
}
|