Compare commits
78 Commits
Author | SHA1 | Date | |
---|---|---|---|
42feb09b4f | |||
d72bb28cf9 | |||
b9f0b798c9 | |||
9b5f42ef9b | |||
4e3355dc43 | |||
fc0a27f5b6 | |||
0248d52548 | |||
c3984819cc | |||
045b87a4a2 | |||
48ca9fdbb9 | |||
e466944c55 | |||
6d8deca9d4 | |||
a4518f3068 | |||
9e338354c6 | |||
9d8c14d187 | |||
5a0b12f6aa | |||
387f00078f | |||
fe2f45e3a9 | |||
90c9bfc906 | |||
4f9e81f612 | |||
a4e280f9f0 | |||
52bd80aebd | |||
15e3cdae83 | |||
c72147b469 | |||
d98c2f89c5 | |||
2b722816f6 | |||
91d58277dd | |||
2458da6754 | |||
d4379d19d3 | |||
b0fdd520f3 | |||
a746577945 | |||
bc4cae3333 | |||
e0614b5956 | |||
f568949085 | |||
bee256416f | |||
afa2679501 | |||
7838642fd5 | |||
7a992badf4 | |||
c65790e2f9 | |||
7ec0fe78fc | |||
12f4456ebd | |||
3e8cf73877 | |||
0032292714 | |||
ead87ceb63 | |||
04d70a4d12 | |||
8da43a79d3 | |||
3153021190 | |||
82701c19e7 | |||
d3a68b4fef | |||
c4c1367306 | |||
1f5352d9f5 | |||
f652cc72fe | |||
f510408fce | |||
e250e9b1a2 | |||
5a9b7bbeee | |||
1158b4ff99 | |||
8eb777dd45 | |||
acf5c242d3 | |||
9e9dd8d935 | |||
b7cc500f4d | |||
8a4126a49c | |||
b86391ca00 | |||
92682c1276 | |||
05677231f7 | |||
9c036925fd | |||
d3d5f72193 | |||
3d7c0e6b64 | |||
4faefb0bd7 | |||
162fff134e | |||
426237b2a7 | |||
b2d48d793a | |||
54282bdc14 | |||
208fba0887 | |||
2f065b57fc | |||
3503fbc7b3 | |||
1db3342353 | |||
03380b0d28 | |||
4fe7ec8a66 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,6 +1,20 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
.nogit/
|
||||
nogit/
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
109
.gitlab-ci.yml
109
.gitlab-ci.yml
@ -1,59 +1,128 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npmpage --publish gitlab
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
12
.travis.yml
12
.travis.yml
@ -1,12 +0,0 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '4'
|
||||
- stable
|
||||
deploy:
|
||||
provider: npm
|
||||
email: npm@lossless.digital
|
||||
api_key:
|
||||
secure: uWqO634z8xMWI8tcIpSvUeVeG4ypX5fppXWxrSKbO5zOHCHGqJK90XiGFfKUekMf0cYQPb5dLT5+J/3nd4mf4KtU3+v1OK6ZikEqn/PcSeqOmK7EnI9wDFZwDTgJWIn0lRwX2mfB9meblSZ7XthTXumX78fmRTyeyImLm9P0ak+CrNzs8rzKauBoqeVryOez4/LaH3f0kxSz7o7zYLxFqx5xjQ7TFqd1kkVTf4pSQanLHY3z+7+mKrkbcNVxx2gF76hyx6E4pntSJHrOEE/VU/KMk2B6yzrVWYUHUiSRGYOV9U17YaaWlC9DZmnS1cvYcqq3YNujTwPWtci3It9S98hLrSTnCCqin6xhj8IuV6U4WADiXOUvNKuTRcd0/leQ4w3xpPJ1FR2gRtEhwQ0NsnY0vL9tuRAW71lf31122TTJI8lJQNrnaeIGbX7eE0Pq0jeTpmM2W/Tl8pl6s6zBjlEC/mCynQq1pBiz7UmxMYCPE162I8V5USeZOBLzDPZV2y7hmPWjMrWTT+i/IpFmXHjQtVrwlyU6fCOeYHgK/5GdyhnrRYYlx+ce6pCn4tmkVxduimC3m1G8cTkPl00fIpy7KSVcaeQrc1N+KQUqK4FpIjeqB904SVPsI5v3P7sdobaT1aqFqszhR+JK5tXaoesew8R2RncjFK69J7DHJWk=
|
||||
on:
|
||||
tags: true
|
||||
repo: pushrocks/cflare
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
51
README.md
51
README.md
@ -1,51 +0,0 @@
|
||||
# cflare
|
||||
easy cloudflare management
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/cflare)
|
||||
[](https://GitLab.com/mojoio/cflare)
|
||||
[](https://github.com/mojoio/cflare)
|
||||
[](https://mojoio.gitlab.io/cflare/)
|
||||
|
||||
## Status for master
|
||||
[](https://GitLab.com/mojoio/cflare/commits/master)
|
||||
[](https://GitLab.com/mojoio/cflare/commits/master)
|
||||
[](https://www.npmjs.com/package/cflare)
|
||||
[](https://david-dm.org/mojoio/cflare)
|
||||
[](https://www.bithound.io/github/mojoio/cflare/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/mojoio/cflare)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import * as cflare from 'cflare'
|
||||
|
||||
let myCflareAccount = new cflare.CflareAccount()
|
||||
testCflareAccount.auth({
|
||||
email: 'someuser@example.com',
|
||||
key: 'someLongApiKey'
|
||||
})
|
||||
|
||||
let myAsyncCflareManagement = async () => {
|
||||
// get things
|
||||
let myZones = await myCflareAccount.listZones() // zones are fully typed
|
||||
let myIdForADomain = await myCflareAccount.getZoneId('example.com') // type number
|
||||
let myRecordsForADomain = await myCflareAccount.listRecords('example.com') // records are fully typed
|
||||
|
||||
// set things
|
||||
myCflareAccount.updateRecord(...)
|
||||
myCflareAccount.createRecord(...)
|
||||
myCflareAccount.deleteRecord(...)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this README.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
|
||||
[](https://push.rocks)
|
20
dist/cflare.classes.cflareaccount.d.ts
vendored
20
dist/cflare.classes.cflareaccount.d.ts
vendored
@ -1,20 +0,0 @@
|
||||
import 'typings-global';
|
||||
import * as interfaces from './cflare.interfaces';
|
||||
export declare class CflareAccount {
|
||||
private authEmail;
|
||||
private authKey;
|
||||
constructor();
|
||||
auth(optionsArg: {
|
||||
email: string;
|
||||
key: string;
|
||||
}): void;
|
||||
getZoneId(domainName: string): Promise<{}>;
|
||||
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord>;
|
||||
createRecord(domainNameArg: string, typeArg: string, contentArg: string): Promise<{}>;
|
||||
removeRecord(domainNameArg: string, typeArg: string): Promise<{}>;
|
||||
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): Promise<{}>;
|
||||
listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]>;
|
||||
listZones(domainName?: string): Promise<interfaces.ICflareZone[]>;
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>;
|
||||
private authCheck();
|
||||
}
|
168
dist/cflare.classes.cflareaccount.js
vendored
168
dist/cflare.classes.cflareaccount.js
vendored
File diff suppressed because one or more lines are too long
1
dist/cflare.classes.helpers.d.ts
vendored
1
dist/cflare.classes.helpers.d.ts
vendored
@ -1 +0,0 @@
|
||||
import "typings-global";
|
3
dist/cflare.classes.helpers.js
vendored
3
dist/cflare.classes.helpers.js
vendored
@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QiJ9
|
56
dist/cflare.interfaces.d.ts
vendored
56
dist/cflare.interfaces.d.ts
vendored
@ -1,56 +0,0 @@
|
||||
export interface ICflareZone {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"development_mode": number;
|
||||
"original_name_servers": string[];
|
||||
"original_registrar": string;
|
||||
"original_dnshost": string;
|
||||
"created_on": string;
|
||||
"modified_on": string;
|
||||
"name_servers": string[];
|
||||
"owner": {
|
||||
"id": string;
|
||||
"email": string;
|
||||
"owner_type": string;
|
||||
};
|
||||
"permissions": string[];
|
||||
"plan": {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"price": number;
|
||||
"currency": string;
|
||||
"frequency": string;
|
||||
"legacy_id": string;
|
||||
"is_subscribed": boolean;
|
||||
"can_subscribe": boolean;
|
||||
};
|
||||
"plan_pending": {
|
||||
"id": string;
|
||||
"name": string;
|
||||
"price": number;
|
||||
"currency": string;
|
||||
"frequency": string;
|
||||
"legacy_id": string;
|
||||
"is_subscribed": string;
|
||||
"can_subscribe": string;
|
||||
};
|
||||
"status": string;
|
||||
"paused": boolean;
|
||||
"type": string;
|
||||
"checked_on": string;
|
||||
}
|
||||
export interface ICflareRecord {
|
||||
"id": string;
|
||||
"type": string;
|
||||
"name": string;
|
||||
"content": string;
|
||||
"proxiable": boolean;
|
||||
"proxied": boolean;
|
||||
"ttl": number;
|
||||
"locked": boolean;
|
||||
"zone_id": string;
|
||||
"zone_name": string;
|
||||
"created_on": string;
|
||||
"modified_on": string;
|
||||
"data": any;
|
||||
}
|
2
dist/cflare.interfaces.js
vendored
2
dist/cflare.interfaces.js
vendored
@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmludGVyZmFjZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUuaW50ZXJmYWNlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
6
dist/cflare.plugins.d.ts
vendored
6
dist/cflare.plugins.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
import "typings-global";
|
||||
export declare let beautylog: any;
|
||||
export import q = require("smartq");
|
||||
export import smartrequest = require("smartrequest");
|
||||
export import smartstring = require("smartstring");
|
||||
export import smartdelay = require('smartdelay');
|
8
dist/cflare.plugins.js
vendored
8
dist/cflare.plugins.js
vendored
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
exports.beautylog = require("beautylog");
|
||||
exports.q = require("smartq");
|
||||
exports.smartrequest = require("smartrequest");
|
||||
exports.smartstring = require("smartstring");
|
||||
exports.smartdelay = require("smartdelay");
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUNwQywrQ0FBcUQ7QUFDckQsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9
|
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import "typings-global";
|
||||
export { CflareAccount } from "./cflare.classes.cflareaccount";
|
5
dist/index.js
vendored
5
dist/index.js
vendored
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
|
||||
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLCtFQUE2RDtBQUFyRCx1REFBQSxhQUFhLENBQUEifQ==
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "mojoio",
|
||||
"gitrepo": "cloudflare",
|
||||
"description": "easy cloudflare management",
|
||||
"npmPackagename": "@apiclient.xyz/cloudflare",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
13094
package-lock.json
generated
Normal file
13094
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@ -1,11 +1,15 @@
|
||||
{
|
||||
"name": "cflare",
|
||||
"version": "0.0.19",
|
||||
"name": "@apiclient.xyz/cloudflare",
|
||||
"version": "6.0.3",
|
||||
"private": false,
|
||||
"description": "easy cloudflare management",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,17 +26,34 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
|
||||
"dependencies": {
|
||||
"beautylog": "^6.1.1",
|
||||
"smartdelay": "^1.0.1",
|
||||
"smartq": "^1.1.0",
|
||||
"smartrequest": "^1.0.4",
|
||||
"smartstring": "^2.0.22",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/smartdelay": "^3.0.1",
|
||||
"@pushrocks/smartlog": "^3.0.2",
|
||||
"@pushrocks/smartpromise": "^4.0.2",
|
||||
"@pushrocks/smartrequest": "^2.0.15",
|
||||
"@pushrocks/smartstring": "^4.0.5",
|
||||
"@tsclass/tsclass": "^4.0.42"
|
||||
},
|
||||
"devDependencies": {
|
||||
"npmts-g": "^6.0.0",
|
||||
"qenv": "^1.1.3",
|
||||
"smartchai": "^1.0.1",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.42",
|
||||
"@gitzone/tstest": "^1.0.74",
|
||||
"@pushrocks/qenv": "^5.0.2",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^20.3.1"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
4420
pnpm-lock.yaml
generated
Normal file
4420
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
52
readme.md
Normal file
52
readme.md
Normal file
@ -0,0 +1,52 @@
|
||||
# @apiclient.xyz/cloudflare
|
||||
easy cloudflare management
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiclient.xyz/cloudflare)
|
||||
* [gitlab.com (source)](https://gitlab.com/mojoio/cloudflare)
|
||||
* [github.com (source mirror)](https://github.com/mojoio/cloudflare)
|
||||
* [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import * as cflare from '@apiclient.xyz/cloudflare';
|
||||
|
||||
const myCflareAccount = new cflare.CflareAccount('mySuperAwesomeAccountToken');
|
||||
|
||||
const myAsyncCflareManagement = async () => {
|
||||
// get things
|
||||
const myZones = await myCflareAccount.listZones(); // zones are fully typed
|
||||
const myIdForADomain = await myCflareAccount.getZoneId('example.com'); // type number
|
||||
const myRecordsForADomain = await myCflareAccount.listRecords('example.com'); // records are fully typed
|
||||
};
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
74
test/test.js
74
test/test.js
@ -1,74 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const cflare = require("../dist/index");
|
||||
const qenv_1 = require("qenv");
|
||||
let testQenv = new qenv_1.Qenv(process.cwd(), process.cwd() + '/.nogit');
|
||||
console.log(testQenv.missingEnvVars);
|
||||
let testCflareAccount = new cflare.CflareAccount();
|
||||
testCflareAccount.auth({
|
||||
email: process.env.CF_EMAIL,
|
||||
key: process.env.CF_KEY
|
||||
});
|
||||
let randomPrefix = Math.floor(Math.random() * 2000);
|
||||
describe('cflare', function () {
|
||||
describe('.CflareAccount', function () {
|
||||
describe('.listZones()', function () {
|
||||
it('should display an entire account', function (done) {
|
||||
this.timeout(600000);
|
||||
testCflareAccount.listZones()
|
||||
.then((responseArg) => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.getZoneId(domainName)', function () {
|
||||
it('should get an Cloudflare Id for a domain string', function (done) {
|
||||
this.timeout(600000);
|
||||
testCflareAccount.getZoneId('bleu.de')
|
||||
.then((responseArg) => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.listRecords(domainName)', function () {
|
||||
it('should list all records for a specific Domain Name', function (done) {
|
||||
this.timeout(600000);
|
||||
testCflareAccount.listRecords('bleu.de')
|
||||
.then((responseArg) => {
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.createRecord', function () {
|
||||
it('should create a valid record for a subdomain', function (done) {
|
||||
this.timeout(600000);
|
||||
testCflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1')
|
||||
.then(function (responseArg) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.getRecord', function () {
|
||||
it('should get a record from Cloudflare', function (done) {
|
||||
this.timeout(600000);
|
||||
testCflareAccount.getRecord('bleu.de', 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('.removeRecord', function () {
|
||||
it('should remove a subdomain record from Cloudflare', function (done) {
|
||||
this.timeout(600000);
|
||||
testCflareAccount.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQix3Q0FBd0M7QUFFeEMsK0JBQTJCO0FBQzNCLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBRSxPQUFPLENBQUMsR0FBRyxFQUFFLEdBQUcsU0FBUyxDQUFDLENBQUE7QUFDakUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLENBQUMsY0FBYyxDQUFDLENBQUE7QUFDcEMsSUFBSSxpQkFBaUIsR0FBRyxJQUFJLE1BQU0sQ0FBQyxhQUFhLEVBQUUsQ0FBQTtBQUNsRCxpQkFBaUIsQ0FBQyxJQUFJLENBQUM7SUFDbkIsS0FBSyxFQUFFLE9BQU8sQ0FBQyxHQUFHLENBQUMsUUFBUTtJQUMzQixHQUFHLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxNQUFNO0NBQzFCLENBQUMsQ0FBQTtBQUVGLElBQUksWUFBWSxHQUFHLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLE1BQU0sRUFBRSxHQUFHLElBQUksQ0FBQyxDQUFBO0FBRW5ELFFBQVEsQ0FBQyxRQUFRLEVBQUU7SUFDZixRQUFRLENBQUMsZ0JBQWdCLEVBQUU7UUFDdkIsUUFBUSxDQUFDLGNBQWMsRUFBRTtZQUNyQixFQUFFLENBQUMsa0NBQWtDLEVBQUUsVUFBVSxJQUFJO2dCQUNqRCxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO2dCQUNwQixpQkFBaUIsQ0FBQyxTQUFTLEVBQUU7cUJBQ3hCLElBQUksQ0FBQyxDQUFDLFdBQVc7b0JBQ2QsSUFBSSxFQUFFLENBQUE7Z0JBQ1YsQ0FBQyxDQUFDLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUMsQ0FBQyxDQUFBO1FBQ0YsUUFBUSxDQUFDLHdCQUF3QixFQUFFO1lBQy9CLEVBQUUsQ0FBQyxpREFBaUQsRUFBRSxVQUFVLElBQUk7Z0JBQ2hFLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7Z0JBQ3BCLGlCQUFpQixDQUFDLFNBQVMsQ0FBQyxTQUFTLENBQUM7cUJBQ2pDLElBQUksQ0FBQyxDQUFDLFdBQVc7b0JBQ2QsSUFBSSxFQUFFLENBQUE7Z0JBQ1YsQ0FBQyxDQUFDLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUMsQ0FBQyxDQUFBO1FBQ0YsUUFBUSxDQUFDLDBCQUEwQixFQUFFO1lBQ2pDLEVBQUUsQ0FBQyxvREFBb0QsRUFBRSxVQUFVLElBQUk7Z0JBQ25FLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7Z0JBQ3BCLGlCQUFpQixDQUFDLFdBQVcsQ0FBQyxTQUFTLENBQUM7cUJBQ25DLElBQUksQ0FBQyxDQUFDLFdBQVc7b0JBQ2QsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLENBQUMsQ0FBQTtvQkFDeEIsSUFBSSxFQUFFLENBQUE7Z0JBQ1YsQ0FBQyxDQUFDLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUMsQ0FBQyxDQUFBO1FBQ0YsUUFBUSxDQUFDLGVBQWUsRUFBRTtZQUN0QixFQUFFLENBQUMsOENBQThDLEVBQUUsVUFBVSxJQUFJO2dCQUM3RCxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO2dCQUNwQixpQkFBaUIsQ0FBQyxZQUFZLENBQUMsR0FBRyxZQUFZLG1CQUFtQixFQUFFLEdBQUcsRUFBRSxXQUFXLENBQUM7cUJBQy9FLElBQUksQ0FBQyxVQUFVLFdBQVc7b0JBQ3ZCLElBQUksRUFBRSxDQUFBO2dCQUNWLENBQUMsQ0FBQyxDQUFBO1lBQ1YsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtRQUNGLFFBQVEsQ0FBQyxZQUFZLEVBQUU7WUFDbkIsRUFBRSxDQUFDLHFDQUFxQyxFQUFFLFVBQVUsSUFBSTtnQkFDcEQsSUFBSSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQTtnQkFDcEIsaUJBQWlCLENBQUMsU0FBUyxDQUFDLFNBQVMsRUFBRSxHQUFHLENBQUM7cUJBQ3RDLElBQUksQ0FBQyxVQUFVLFdBQVc7b0JBQ3ZCLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUE7b0JBQ3hCLElBQUksRUFBRSxDQUFBO2dCQUNWLENBQUMsQ0FBQyxDQUFBO1lBQ1YsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtRQUNGLFFBQVEsQ0FBQyxlQUFlLEVBQUU7WUFDdEIsRUFBRSxDQUFDLGtEQUFrRCxFQUFFLFVBQVUsSUFBSTtnQkFDakUsSUFBSSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQTtnQkFDcEIsaUJBQWlCLENBQUMsWUFBWSxDQUFDLEdBQUcsWUFBWSxtQkFBbUIsRUFBRSxHQUFHLENBQUM7cUJBQ2xFLElBQUksQ0FBQyxVQUFVLFdBQVc7b0JBQ3ZCLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUE7b0JBQ3hCLElBQUksRUFBRSxDQUFBO2dCQUNWLENBQUMsQ0FBQyxDQUFBO1lBQ1YsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
164
test/test.ts
164
test/test.ts
@ -1,75 +1,93 @@
|
||||
import 'typings-test'
|
||||
import cflare = require('../dist/index')
|
||||
import { expect } from 'smartchai'
|
||||
import { Qenv } from 'qenv'
|
||||
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit')
|
||||
console.log(testQenv.missingEnvVars)
|
||||
let testCflareAccount = new cflare.CflareAccount()
|
||||
testCflareAccount.auth({
|
||||
email: process.env.CF_EMAIL,
|
||||
key: process.env.CF_KEY
|
||||
})
|
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { Qenv } from '@pushrocks/qenv';
|
||||
|
||||
let randomPrefix = Math.floor(Math.random() * 2000)
|
||||
import * as cloudflare from '../ts/index.js';
|
||||
|
||||
describe('cflare', function () {
|
||||
describe('.CflareAccount', function () {
|
||||
describe('.listZones()', function () {
|
||||
it('should display an entire account', function (done) {
|
||||
this.timeout(600000)
|
||||
testCflareAccount.listZones()
|
||||
.then((responseArg) => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.getZoneId(domainName)', function () {
|
||||
it('should get an Cloudflare Id for a domain string', function (done) {
|
||||
this.timeout(600000)
|
||||
testCflareAccount.getZoneId('bleu.de')
|
||||
.then((responseArg) => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.listRecords(domainName)', function () {
|
||||
it('should list all records for a specific Domain Name', function (done) {
|
||||
this.timeout(600000)
|
||||
testCflareAccount.listRecords('bleu.de')
|
||||
.then((responseArg) => {
|
||||
console.log(responseArg)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.createRecord', function () {
|
||||
it('should create a valid record for a subdomain', function (done) {
|
||||
this.timeout(600000)
|
||||
testCflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1')
|
||||
.then(function (responseArg) {
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.getRecord', function () {
|
||||
it('should get a record from Cloudflare', function (done) {
|
||||
this.timeout(600000)
|
||||
testCflareAccount.getRecord('bleu.de', 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.removeRecord', function () {
|
||||
it('should remove a subdomain record from Cloudflare', function (done) {
|
||||
this.timeout(600000)
|
||||
testCflareAccount.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
||||
|
||||
const randomPrefix = Math.floor(Math.random() * 2000);
|
||||
let testCloudflareAccount: cloudflare.CloudflareAccount;
|
||||
|
||||
tap.test('should create a valid instance of CloudflareAccount', async () => {
|
||||
testCloudflareAccount = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_KEY'));
|
||||
});
|
||||
|
||||
tap.test('.listZones() -> should display an entire account', async (tools) => {
|
||||
tools.timeout(600000);
|
||||
const result = await testCloudflareAccount.convenience.listZones();
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test(
|
||||
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
|
||||
async (tools) => {
|
||||
tools.timeout(600000);
|
||||
await testCloudflareAccount.convenience.getZoneId('bleu.de');
|
||||
}
|
||||
);
|
||||
|
||||
tap.test(
|
||||
'.listRecords(domainName) -> should list all records for a specific Domain Name',
|
||||
async (tools) => {
|
||||
tools.timeout(600000);
|
||||
await testCloudflareAccount.convenience.listRecords('bleu.de').then(async (responseArg) => {
|
||||
console.log(responseArg);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
tap.test('should create a valid record for a subdomain', async (tools) => {
|
||||
tools.timeout(600000);
|
||||
await testCloudflareAccount.convenience.createRecord(
|
||||
`${randomPrefix}subdomain.bleu.de`,
|
||||
'A',
|
||||
'127.0.0.1',
|
||||
120
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('should get a record from Cloudflare', async (tools) => {
|
||||
tools.timeout(600000);
|
||||
await testCloudflareAccount.convenience
|
||||
.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
|
||||
.then((responseArg) => {
|
||||
console.log(responseArg);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('should remove a subdomain record from Cloudflare', async (tools) => {
|
||||
tools.timeout(600000);
|
||||
await testCloudflareAccount.convenience
|
||||
.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
|
||||
.then(async (responseArg) => {
|
||||
console.log(responseArg);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('.purge(some.domain) -> should purge everything', async () => {
|
||||
await testCloudflareAccount.convenience.purgeZone('bleu.de');
|
||||
});
|
||||
|
||||
// WORKERS
|
||||
tap.test('should create a worker', async () => {
|
||||
const worker = await testCloudflareAccount.workerManager.createWorker(
|
||||
'myawesomescript',
|
||||
`addEventListener('fetch', event => { event.respondWith(fetch(event.request)) })`
|
||||
);
|
||||
await worker.setRoutes([
|
||||
{
|
||||
zoneName: 'bleu.de',
|
||||
pattern: 'https://*bleu.de/hello',
|
||||
},
|
||||
]);
|
||||
console.log(worker);
|
||||
});
|
||||
|
||||
tap.test('should get workers', async () => {
|
||||
const workerArray = await testCloudflareAccount.workerManager.listWorkers();
|
||||
console.log(workerArray);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/cloudflare',
|
||||
version: '6.0.3',
|
||||
description: 'easy cloudflare management'
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
import 'typings-global';
|
||||
import plugins = require('./cflare.plugins')
|
||||
import helpers = require('./cflare.classes.helpers')
|
||||
import * as interfaces from './cflare.interfaces'
|
||||
|
||||
export class CflareAccount {
|
||||
private authEmail: string
|
||||
private authKey: string
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
auth(optionsArg: { email: string, key: string }) {
|
||||
this.authEmail = optionsArg.email
|
||||
this.authKey = optionsArg.key
|
||||
}
|
||||
|
||||
getZoneId(domainName: string) {
|
||||
let done = plugins.q.defer()
|
||||
this.listZones(domainName)
|
||||
.then(zoneArrayArg => {
|
||||
let filteredResponse = zoneArrayArg.filter((zoneArg) => {
|
||||
return zoneArg.name === domainName
|
||||
})
|
||||
if (filteredResponse.length >= 1) {
|
||||
done.resolve(filteredResponse[ 0 ].id)
|
||||
} else {
|
||||
plugins.beautylog.error(`the domain ${domainName} does not appear to be in this account!`)
|
||||
done.reject(undefined)
|
||||
}
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord> {
|
||||
let done = plugins.q.defer()
|
||||
let result: interfaces.ICflareRecord
|
||||
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.listRecords(domain.zoneName)
|
||||
.then((recordArrayArg) => {
|
||||
let filteredResponse = recordArrayArg.filter((recordArg) => {
|
||||
return (recordArg.type === typeArg && recordArg.name === domainNameArg)
|
||||
})
|
||||
done.resolve(filteredResponse[ 0 ])
|
||||
})
|
||||
return done.promise
|
||||
};
|
||||
createRecord(domainNameArg: string, typeArg: string, contentArg: string) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.getZoneId(domain.zoneName)
|
||||
.then((domainIdArg) => {
|
||||
let dataObject = {
|
||||
name: domain.fullName,
|
||||
type: typeArg,
|
||||
content: contentArg
|
||||
}
|
||||
this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject)
|
||||
.then(function (responseArg) {
|
||||
done.resolve(responseArg)
|
||||
})
|
||||
})
|
||||
return done.promise
|
||||
};
|
||||
removeRecord(domainNameArg: string, typeArg: string) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.getRecord(domain.fullName, typeArg)
|
||||
.then((responseArg) => {
|
||||
if (responseArg) {
|
||||
let requestRoute: string = '/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id
|
||||
this.request('DELETE', requestRoute)
|
||||
.then((responseArg) => {
|
||||
done.resolve(responseArg)
|
||||
})
|
||||
} else {
|
||||
done.reject()
|
||||
}
|
||||
})
|
||||
return done.promise
|
||||
};
|
||||
updateRecord(domainNameArg: string, typeArg: string, valueArg) {
|
||||
let done = plugins.q.defer()
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
return done.promise
|
||||
};
|
||||
listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
|
||||
let done = plugins.q.defer<interfaces.ICflareRecord[]>()
|
||||
let result: interfaces.ICflareRecord[] = []
|
||||
|
||||
let domain = new plugins.smartstring.Domain(domainNameArg)
|
||||
this.getZoneId(domain.zoneName)
|
||||
.then((domainIdArg) => {
|
||||
this.request('GET', '/zones/' + domainIdArg + '/dns_records?per_page=100')
|
||||
.then(function (responseArg: any) {
|
||||
result = responseArg.result
|
||||
done.resolve(result)
|
||||
})
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
listZones(domainName?: string): Promise<interfaces.ICflareZone[]> { // TODO: handle pagination
|
||||
let done = plugins.q.defer<interfaces.ICflareZone[]>()
|
||||
let requestRoute = '/zones?per_page=50'
|
||||
if (domainName) requestRoute = requestRoute + '&name=' + domainName
|
||||
let result = []
|
||||
this.request('GET', requestRoute)
|
||||
.then((responseArg: any) => {
|
||||
result = responseArg.result
|
||||
done.resolve(result)
|
||||
})
|
||||
return done.promise
|
||||
};
|
||||
request(methodArg: string, routeArg: string, dataArg = {}) {
|
||||
let done = plugins.q.defer()
|
||||
let jsonArg: string = JSON.stringify(dataArg)
|
||||
let options: plugins.smartrequest.ISmartRequestOptions = {
|
||||
method: methodArg,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Auth-Email': this.authEmail,
|
||||
'X-Auth-Key': this.authKey
|
||||
},
|
||||
requestBody: jsonArg
|
||||
}
|
||||
// console.log(options);
|
||||
let retryCount = 0
|
||||
|
||||
let makeRequest = async () => {
|
||||
let response: any = await plugins.smartrequest.request(
|
||||
`https://api.cloudflare.com/client/v4${routeArg}`,
|
||||
options
|
||||
)
|
||||
if (response.statusCode === 200) {
|
||||
done.resolve(response.body)
|
||||
} else if (response.statusCode === 429) {
|
||||
console.log('rate limited! Waiting for retry!')
|
||||
retryRequest()
|
||||
} else if(response.statusCode === 400) {
|
||||
console.log('bad request! Going to retry!')
|
||||
} else {
|
||||
console.log(response.statusCode)
|
||||
done.reject(new Error('request failed'))
|
||||
}
|
||||
}
|
||||
let retryRequest = async (delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)) => {
|
||||
console.log(`retry started and waiting for ${delayTimeArg} ms`)
|
||||
await plugins.smartdelay.delayFor(delayTimeArg)
|
||||
if (retryCount < 10) {
|
||||
retryCount++
|
||||
return await makeRequest()
|
||||
}
|
||||
}
|
||||
makeRequest()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
private authCheck() {
|
||||
return (this.authEmail && this.authKey) // check if auth is available
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
import "typings-global";
|
||||
import plugins = require("./cflare.plugins");
|
@ -1,59 +0,0 @@
|
||||
import * as plugins from './cflare.plugins'
|
||||
|
||||
export interface ICflareZone {
|
||||
"id": string
|
||||
"name": string
|
||||
"development_mode": number
|
||||
"original_name_servers": string[]
|
||||
"original_registrar": string
|
||||
"original_dnshost": string
|
||||
"created_on": string
|
||||
"modified_on": string
|
||||
"name_servers": string[]
|
||||
"owner": {
|
||||
"id": string
|
||||
"email": string
|
||||
"owner_type": string
|
||||
},
|
||||
"permissions": string []
|
||||
"plan": {
|
||||
"id": string
|
||||
"name": string
|
||||
"price": number
|
||||
"currency": string
|
||||
"frequency": string
|
||||
"legacy_id": string
|
||||
"is_subscribed": boolean
|
||||
"can_subscribe": boolean
|
||||
},
|
||||
"plan_pending": {
|
||||
"id": string
|
||||
"name": string
|
||||
"price": number
|
||||
"currency": string
|
||||
"frequency": string
|
||||
"legacy_id": string
|
||||
"is_subscribed": string
|
||||
"can_subscribe": string
|
||||
},
|
||||
"status": string
|
||||
"paused": boolean
|
||||
"type": string
|
||||
"checked_on": string
|
||||
}
|
||||
|
||||
export interface ICflareRecord {
|
||||
"id": string
|
||||
"type": string
|
||||
"name": string
|
||||
"content": string
|
||||
"proxiable": boolean
|
||||
"proxied": boolean
|
||||
"ttl": number
|
||||
"locked": boolean
|
||||
"zone_id": string
|
||||
"zone_name": string
|
||||
"created_on": string
|
||||
"modified_on": string
|
||||
"data": any
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
import "typings-global";
|
||||
export let beautylog = require("beautylog");
|
||||
export import q = require("smartq");
|
||||
export import smartrequest = require("smartrequest");
|
||||
export import smartstring = require("smartstring");
|
||||
export import smartdelay = require('smartdelay');
|
290
ts/cloudflare.classes.account.ts
Normal file
290
ts/cloudflare.classes.account.ts
Normal file
@ -0,0 +1,290 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
import { logger } from './cloudflare.logger.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
// interfaces
|
||||
import { WorkerManager } from './cloudflare.classes.workermanager.js';
|
||||
import { ZoneManager } from './cloudflare.classes.zonemanager.js';
|
||||
|
||||
export class CloudflareAccount {
|
||||
private authToken: string;
|
||||
private accountIdentifier: string;
|
||||
|
||||
public workerManager = new WorkerManager(this);
|
||||
public zoneManager = new ZoneManager(this);
|
||||
|
||||
/**
|
||||
* constructor sets auth information on the CloudflareAccountInstance
|
||||
* @param optionsArg
|
||||
*/
|
||||
constructor(authTokenArg: string) {
|
||||
this.authToken = authTokenArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets you the account identifier
|
||||
*/
|
||||
public async getAccountIdentifier() {
|
||||
if (!this.accountIdentifier) {
|
||||
const route = `/accounts?page=1&per_page=20&direction=desc`;
|
||||
const response: any = await this.request('GET', route);
|
||||
this.accountIdentifier = response.result[0].id;
|
||||
}
|
||||
return this.accountIdentifier;
|
||||
}
|
||||
|
||||
public convenience = {
|
||||
/**
|
||||
* gets a zone id of a domain from cloudflare
|
||||
* @param domainName
|
||||
*/
|
||||
getZoneId: async (domainName: string) => {
|
||||
const domain = new plugins.smartstring.Domain(domainName);
|
||||
const zoneArray = await this.convenience.listZones(domain.zoneName);
|
||||
const filteredResponse = zoneArray.filter((zoneArg) => {
|
||||
return zoneArg.name === domainName;
|
||||
});
|
||||
if (filteredResponse.length >= 1) {
|
||||
return filteredResponse[0].id;
|
||||
} else {
|
||||
logger.log('error', `the domain ${domainName} does not appear to be in this account!`);
|
||||
throw new Error(`the domain ${domainName} does not appear to be in this account!`);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* gets a record
|
||||
* @param domainNameArg
|
||||
* @param typeArg
|
||||
*/
|
||||
getRecord: async (
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType
|
||||
): Promise<interfaces.ICflareRecord> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const recordArrayArg = await this.convenience.listRecords(domain.zoneName);
|
||||
const filteredResponse = recordArrayArg.filter((recordArg) => {
|
||||
return recordArg.type === typeArg && recordArg.name === domainNameArg;
|
||||
});
|
||||
return filteredResponse[0];
|
||||
},
|
||||
/**
|
||||
* creates a record
|
||||
*/
|
||||
createRecord: async (
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
contentArg: string,
|
||||
ttlArg = 1
|
||||
): Promise<any> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const domainIdArg = await this.convenience.getZoneId(domain.zoneName);
|
||||
const dataObject = {
|
||||
name: domain.fullName,
|
||||
type: typeArg,
|
||||
content: contentArg,
|
||||
ttl: ttlArg,
|
||||
};
|
||||
const response = await this.request(
|
||||
'POST',
|
||||
'/zones/' + domainIdArg + '/dns_records',
|
||||
dataObject
|
||||
);
|
||||
return response;
|
||||
},
|
||||
/**
|
||||
* removes a record from Cloudflare
|
||||
* @param domainNameArg
|
||||
* @param typeArg
|
||||
*/
|
||||
removeRecord: async (
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType
|
||||
): Promise<any> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const cflareRecord = await this.convenience.getRecord(domain.fullName, typeArg);
|
||||
if (cflareRecord) {
|
||||
const requestRoute: string = `/zones/${cflareRecord.zone_id}/dns_records/${cflareRecord.id}`;
|
||||
return await this.request('DELETE', requestRoute);
|
||||
} else {
|
||||
throw new Error(`could not remove record for ${domainNameArg} with type ${typeArg}`);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* cleanrecord allows the cleaning of any previous records to avoid unwanted sideeffects
|
||||
*/
|
||||
cleanRecord: async (domainNameArg: string, typeArg: plugins.tsclass.network.TDnsRecordType) => {
|
||||
console.log(`cleaning record for ${domainNameArg}`);
|
||||
},
|
||||
/**
|
||||
* updates a record
|
||||
* @param domainNameArg
|
||||
* @param typeArg
|
||||
* @param valueArg
|
||||
*/
|
||||
updateRecord: async (
|
||||
domainNameArg: string,
|
||||
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||
valueArg
|
||||
) => {
|
||||
// TODO: implement
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
},
|
||||
/**
|
||||
* list all records of a specified domain name
|
||||
* @param domainNameArg - the domain name that you want to get the records from
|
||||
*/
|
||||
listRecords: async (domainNameArg: string): Promise<interfaces.ICflareRecord[]> => {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const domainId = await this.convenience.getZoneId(domain.zoneName);
|
||||
const responseArg: any = await this.request(
|
||||
'GET',
|
||||
'/zones/' + domainId + '/dns_records?per_page=100'
|
||||
);
|
||||
const result: interfaces.ICflareRecord[] = responseArg.result;
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
* list all zones in the associated authenticated account
|
||||
* @param domainName
|
||||
*/
|
||||
listZones: async (domainName?: string): Promise<interfaces.ICflareZone[]> => {
|
||||
// TODO: handle pagination
|
||||
let requestRoute = `/zones?per_page=50`;
|
||||
|
||||
// may be optionally filtered by domain name
|
||||
if (domainName) {
|
||||
requestRoute = `${requestRoute}&name=${domainName}`;
|
||||
}
|
||||
|
||||
const response: any = await this.request('GET', requestRoute);
|
||||
const result = response.result;
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
* purges a zone
|
||||
*/
|
||||
purgeZone: async (domainName: string): Promise<void> => {
|
||||
const domain = new plugins.smartstring.Domain(domainName);
|
||||
const domainId = await this.convenience.getZoneId(domain.zoneName);
|
||||
const requestUrl = `/zones/${domainId}/purge_cache`;
|
||||
const payload = {
|
||||
purge_everything: true,
|
||||
};
|
||||
const respone = await this.request('DELETE', requestUrl, payload);
|
||||
},
|
||||
// acme convenience functions
|
||||
acmeSetDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
||||
await this.convenience.cleanRecord(dnsChallenge.hostName, 'TXT');
|
||||
await this.convenience.createRecord(
|
||||
dnsChallenge.hostName,
|
||||
'TXT',
|
||||
dnsChallenge.challenge,
|
||||
120
|
||||
);
|
||||
},
|
||||
acmeRemoveDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
||||
await this.convenience.removeRecord(dnsChallenge.hostName, 'TXT');
|
||||
},
|
||||
};
|
||||
|
||||
public async request(
|
||||
methodArg: string,
|
||||
routeArg: string,
|
||||
dataArg: any = {},
|
||||
requestHeadersArg = {}
|
||||
): Promise<any> {
|
||||
const options: plugins.smartrequest.ISmartRequestOptions = {
|
||||
method: methodArg,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.authToken}`,
|
||||
'Content-Length': Buffer.byteLength(JSON.stringify(dataArg)),
|
||||
...requestHeadersArg,
|
||||
},
|
||||
requestBody: dataArg,
|
||||
};
|
||||
|
||||
// route analysis
|
||||
const routeWithoutQuery = routeArg.split('?')[0];
|
||||
let queryParams: string[] = [];
|
||||
if (routeArg.split('?').length > 1) {
|
||||
queryParams = routeArg.split('?')[1].split('&');
|
||||
}
|
||||
|
||||
// console.log(options);
|
||||
|
||||
let retryCount = 0; // count the amount of retries
|
||||
let pageCount = 1;
|
||||
|
||||
const getQueryParams = () => {
|
||||
let result = '';
|
||||
if (queryParams.length > 0) {
|
||||
result += '?';
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
|
||||
let isFirst = true;
|
||||
for (const queryParam of queryParams) {
|
||||
if (!isFirst) {
|
||||
result += '&';
|
||||
}
|
||||
isFirst = false;
|
||||
const queryParamSerialized = queryParam.split('=');
|
||||
if (queryParam === 'page') {
|
||||
result += `page=${pageCount}`;
|
||||
} else {
|
||||
result += queryParam;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const makeRequest = async (): Promise<plugins.smartrequest.IExtendedIncomingMessage> => {
|
||||
const requestUrl = `https://api.cloudflare.com/client/v4${routeWithoutQuery}${getQueryParams()}`;
|
||||
const response = await plugins.smartrequest.request(requestUrl, options);
|
||||
if (response.statusCode === 200) {
|
||||
if (response.body.result_info) {
|
||||
const rI = response.body.result_info;
|
||||
if (rI.total_count / rI.per_page > pageCount) {
|
||||
pageCount++;
|
||||
const subresponse = await makeRequest();
|
||||
response.body.result = response.body.result.concat(subresponse.body.result);
|
||||
return response;
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
} else if (response.statusCode === 429) {
|
||||
console.log('rate limited! Waiting for retry!');
|
||||
return await retryRequest();
|
||||
} else if (response.statusCode === 400) {
|
||||
console.log(`bad request for route ${requestUrl}!`);
|
||||
console.log(response.body);
|
||||
throw new Error(`request failed for ${requestUrl}`);
|
||||
} else {
|
||||
console.log(response.body);
|
||||
throw new Error(`request failed for ${requestUrl} with status${response.statusCode}}`);
|
||||
}
|
||||
};
|
||||
|
||||
const retryRequest = async (
|
||||
delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)
|
||||
) => {
|
||||
console.log(`retry started and waiting for ${delayTimeArg} ms`);
|
||||
await plugins.smartdelay.delayFor(delayTimeArg);
|
||||
if (retryCount < 10) {
|
||||
retryCount++;
|
||||
return await makeRequest();
|
||||
}
|
||||
};
|
||||
const response = await makeRequest();
|
||||
return response.body;
|
||||
}
|
||||
|
||||
private authCheck() {
|
||||
return !!this.authToken; // check if auth is available
|
||||
}
|
||||
}
|
3
ts/cloudflare.classes.record.ts
Normal file
3
ts/cloudflare.classes.record.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
|
||||
export class CloudflareRecord {}
|
93
ts/cloudflare.classes.worker.ts
Normal file
93
ts/cloudflare.classes.worker.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
import { WorkerManager } from './cloudflare.classes.workermanager.js';
|
||||
import { logger } from './cloudflare.logger.js';
|
||||
|
||||
export interface IWorkerRoute extends interfaces.ICflareWorkerRoute {
|
||||
zoneName: string;
|
||||
}
|
||||
|
||||
export class CloudflareWorker {
|
||||
// STATIC
|
||||
public static async fromApiObject(
|
||||
workerManager: WorkerManager,
|
||||
apiObject
|
||||
): Promise<CloudflareWorker> {
|
||||
const newWorker = new CloudflareWorker(workerManager);
|
||||
Object.assign(newWorker, apiObject);
|
||||
await newWorker.getRoutes();
|
||||
return newWorker;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
private workerManager: WorkerManager;
|
||||
|
||||
public script: string;
|
||||
public id: string;
|
||||
public etag: string;
|
||||
// tslint:disable-next-line: variable-name
|
||||
public created_on: string;
|
||||
// tslint:disable-next-line: variable-name
|
||||
public modified_on: string;
|
||||
|
||||
public routes: IWorkerRoute[] = [];
|
||||
constructor(workerManagerArg: WorkerManager) {
|
||||
this.workerManager = workerManagerArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all routes for a worker
|
||||
*/
|
||||
public async getRoutes() {
|
||||
const zones = await this.workerManager.cfAccount.convenience.listZones();
|
||||
for (const zone of zones) {
|
||||
const requestRoute = `/zones/${zone.id}/workers/routes`;
|
||||
const response: {
|
||||
result: interfaces.ICflareWorkerRoute[];
|
||||
} = await this.workerManager.cfAccount.request('GET', requestRoute);
|
||||
for (const route of response.result) {
|
||||
console.log('hey');
|
||||
console.log(route);
|
||||
console.log(this.id);
|
||||
if (route.script === this.id) {
|
||||
this.routes.push({ ...route, zoneName: zone.name });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async setRoutes(routeArray: Array<{ zoneName: string; pattern: string }>) {
|
||||
for (const newRoute of routeArray) {
|
||||
// lets determine wether a route is new, needs an update or already up to date.
|
||||
let routeStatus: 'new' | 'needsUpdate' | 'alreadyUpToDate' = 'new';
|
||||
let routeIdForUpdate: string;
|
||||
for (const existingRoute of this.routes) {
|
||||
if (existingRoute.pattern === newRoute.pattern) {
|
||||
routeStatus = 'needsUpdate';
|
||||
routeIdForUpdate = existingRoute.id;
|
||||
if (existingRoute.script === this.id) {
|
||||
routeStatus = 'alreadyUpToDate';
|
||||
logger.log('info', `route already exists, no update needed`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lets care about actually setting routes
|
||||
if (routeStatus === 'new') {
|
||||
const zoneId = await this.workerManager.cfAccount.convenience.getZoneId(newRoute.zoneName);
|
||||
const requestRoute = `/zones/${zoneId}/workers/routes`;
|
||||
await this.workerManager.cfAccount.request('POST', requestRoute, {
|
||||
pattern: newRoute.pattern,
|
||||
script: this.id,
|
||||
});
|
||||
} else if (routeStatus === 'needsUpdate') {
|
||||
const zoneId = await this.workerManager.cfAccount.convenience.getZoneId(newRoute.zoneName);
|
||||
const requestRoute = `/zones/${zoneId}/workers/routes/${routeIdForUpdate}`;
|
||||
await this.workerManager.cfAccount.request('PUT', requestRoute, {
|
||||
pattern: newRoute.pattern,
|
||||
script: this.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
ts/cloudflare.classes.workermanager.ts
Normal file
36
ts/cloudflare.classes.workermanager.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
import { CloudflareAccount } from './cloudflare.classes.account.js';
|
||||
import { CloudflareWorker } from './cloudflare.classes.worker.js';
|
||||
|
||||
export class WorkerManager {
|
||||
public cfAccount: CloudflareAccount;
|
||||
|
||||
constructor(cfAccountArg: CloudflareAccount) {
|
||||
this.cfAccount = cfAccountArg;
|
||||
}
|
||||
|
||||
public async createWorker(workerName: string, workerScript: string): Promise<CloudflareWorker> {
|
||||
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
|
||||
const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`;
|
||||
const responseBody = await this.cfAccount.request('PUT', route, workerScript, {
|
||||
'Content-Type': 'application/javascript',
|
||||
'Content-Length': Buffer.byteLength(workerScript),
|
||||
});
|
||||
return CloudflareWorker.fromApiObject(this, responseBody.result);
|
||||
}
|
||||
|
||||
/**
|
||||
* lists workers
|
||||
*/
|
||||
public async listWorkers() {
|
||||
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
|
||||
const route = `/accounts/${accountIdentifier}/workers/scripts`;
|
||||
const response = await this.cfAccount.request('GET', route);
|
||||
const results = response.result;
|
||||
const workers: CloudflareWorker[] = [];
|
||||
for (const apiObject of results) {
|
||||
workers.push(await CloudflareWorker.fromApiObject(this, apiObject));
|
||||
}
|
||||
return workers;
|
||||
}
|
||||
}
|
50
ts/cloudflare.classes.zone.ts
Normal file
50
ts/cloudflare.classes.zone.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
export class CloudflareZone implements interfaces.ICflareZone {
|
||||
public static createFromApiObject(apiObject: interfaces.ICflareZone) {
|
||||
const cloudflareZone = new CloudflareZone();
|
||||
Object.assign(cloudflareZone, apiObject);
|
||||
return cloudflareZone;
|
||||
}
|
||||
|
||||
id: string;
|
||||
name: string;
|
||||
development_mode: number;
|
||||
original_name_servers: string[];
|
||||
original_registrar: string;
|
||||
original_dnshost: string;
|
||||
created_on: string;
|
||||
modified_on: string;
|
||||
name_servers: string[];
|
||||
owner: {
|
||||
id: string;
|
||||
email: string;
|
||||
owner_type: string;
|
||||
};
|
||||
permissions: string[];
|
||||
plan: {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
frequency: string;
|
||||
legacy_id: string;
|
||||
is_subscribed: boolean;
|
||||
can_subscribe: boolean;
|
||||
};
|
||||
plan_pending: {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
frequency: string;
|
||||
legacy_id: string;
|
||||
is_subscribed: string;
|
||||
can_subscribe: string;
|
||||
};
|
||||
status: string;
|
||||
paused: boolean;
|
||||
type: string;
|
||||
checked_on: string;
|
||||
}
|
32
ts/cloudflare.classes.zonemanager.ts
Normal file
32
ts/cloudflare.classes.zonemanager.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
import { CloudflareAccount } from './cloudflare.classes.account.js';
|
||||
import { CloudflareZone } from './cloudflare.classes.zone.js';
|
||||
|
||||
export class ZoneManager {
|
||||
public cfAccount: CloudflareAccount;
|
||||
public zoneName: string;
|
||||
|
||||
constructor(cfAccountArg: CloudflareAccount) {
|
||||
this.cfAccount = cfAccountArg;
|
||||
}
|
||||
|
||||
public async getZones(zoneName: string) {
|
||||
let requestRoute = `/zones?per_page=50`;
|
||||
// may be optionally filtered by domain name
|
||||
|
||||
if (zoneName) {
|
||||
requestRoute = `${requestRoute}&name=${zoneName}`;
|
||||
}
|
||||
|
||||
const response: any = await this.cfAccount.request('GET', requestRoute);
|
||||
const apiObjects: interfaces.ICflareZone[] = response.result;
|
||||
|
||||
const cloudflareZoneArray = [];
|
||||
for (const apiObject of apiObjects) {
|
||||
cloudflareZoneArray.push(CloudflareZone.createFromApiObject(apiObject));
|
||||
}
|
||||
|
||||
return cloudflareZoneArray;
|
||||
}
|
||||
}
|
3
ts/cloudflare.logger.ts
Normal file
3
ts/cloudflare.logger.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as plugins from './cloudflare.plugins.js';
|
||||
|
||||
export const logger = new plugins.smartlog.ConsoleLog();
|
8
ts/cloudflare.plugins.ts
Normal file
8
ts/cloudflare.plugins.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import * as smartlog from '@pushrocks/smartlog';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
import * as tsclass from '@tsclass/tsclass';
|
||||
|
||||
export { smartlog, smartpromise, smartdelay, smartrequest, smartstring, tsclass };
|
@ -1,2 +1,2 @@
|
||||
import "typings-global";
|
||||
export {CflareAccount} from "./cflare.classes.cflareaccount";
|
||||
export { CloudflareAccount } from './cloudflare.classes.account.js';
|
||||
export { CloudflareWorker } from './cloudflare.classes.worker.js';
|
||||
|
15
ts/interfaces/cloudflare.api.record.ts
Normal file
15
ts/interfaces/cloudflare.api.record.ts
Normal file
@ -0,0 +1,15 @@
|
||||
export interface ICflareRecord {
|
||||
id: string;
|
||||
type: string;
|
||||
name: string;
|
||||
content: string;
|
||||
proxiable: boolean;
|
||||
proxied: boolean;
|
||||
ttl: number;
|
||||
locked: boolean;
|
||||
zone_id: string;
|
||||
zone_name: string;
|
||||
created_on: string;
|
||||
modified_on: string;
|
||||
data: any;
|
||||
}
|
5
ts/interfaces/cloudflare.api.workerroute.ts
Normal file
5
ts/interfaces/cloudflare.api.workerroute.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface ICflareWorkerRoute {
|
||||
id: string;
|
||||
pattern: string;
|
||||
script: string;
|
||||
}
|
41
ts/interfaces/cloudflare.api.zone.ts
Normal file
41
ts/interfaces/cloudflare.api.zone.ts
Normal file
@ -0,0 +1,41 @@
|
||||
export interface ICflareZone {
|
||||
id: string;
|
||||
name: string;
|
||||
development_mode: number;
|
||||
original_name_servers: string[];
|
||||
original_registrar: string;
|
||||
original_dnshost: string;
|
||||
created_on: string;
|
||||
modified_on: string;
|
||||
name_servers: string[];
|
||||
owner: {
|
||||
id: string;
|
||||
email: string;
|
||||
owner_type: string;
|
||||
};
|
||||
permissions: string[];
|
||||
plan: {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
frequency: string;
|
||||
legacy_id: string;
|
||||
is_subscribed: boolean;
|
||||
can_subscribe: boolean;
|
||||
};
|
||||
plan_pending: {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
currency: string;
|
||||
frequency: string;
|
||||
legacy_id: string;
|
||||
is_subscribed: string;
|
||||
can_subscribe: string;
|
||||
};
|
||||
status: string;
|
||||
paused: boolean;
|
||||
type: string;
|
||||
checked_on: string;
|
||||
}
|
3
ts/interfaces/index.ts
Normal file
3
ts/interfaces/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './cloudflare.api.record.js';
|
||||
export * from './cloudflare.api.zone.js';
|
||||
export * from './cloudflare.api.workerroute.js';
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user