fix(core): update
This commit is contained in:
parent
b86391ca00
commit
8a4126a49c
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,6 +1,22 @@
|
|||||||
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
.nogit/
|
# caches
|
||||||
nogit/
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
@ -1,5 +1,5 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
@ -26,6 +26,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -36,21 +37,11 @@ snyk:
|
|||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install legacy
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -58,13 +49,14 @@ testLTS:
|
|||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
testSTABLE:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci npm prepare
|
||||||
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
@ -73,7 +65,7 @@ testSTABLE:
|
|||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install lts
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
@ -86,19 +78,11 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm install
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
@ -117,9 +101,10 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -130,13 +115,3 @@ pages:
|
|||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|
||||||
windowsCompatibility:
|
|
||||||
image: stefanscherer/node-windows:10-build-tools
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npm install & npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- windows
|
|
||||||
allow_failure: true
|
|
||||||
|
36
README.md
36
README.md
@ -1,25 +1,20 @@
|
|||||||
# cflare
|
# @mojoio/cloudflare
|
||||||
|
|
||||||
easy cloudflare management
|
easy cloudflare management
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/cloudflare)
|
||||||
[![npm](https://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/cflare)
|
* [gitlab.com (source)](https://gitlab.com/mojoio/cloudflare)
|
||||||
[![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/cflare)
|
* [github.com (source mirror)](https://github.com/mojoio/cloudflare)
|
||||||
[![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/cflare)
|
* [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/)
|
||||||
[![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/cflare/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
[![build status](https://gitlab.com/mojoio/cloudflare/badges/master/build.svg)](https://gitlab.com/mojoio/cloudflare/commits/master)
|
||||||
[![build status](https://GitLab.com/mojoio/cflare/badges/master/build.svg)](https://GitLab.com/mojoio/cflare/commits/master)
|
[![coverage report](https://gitlab.com/mojoio/cloudflare/badges/master/coverage.svg)](https://gitlab.com/mojoio/cloudflare/commits/master)
|
||||||
[![coverage report](https://GitLab.com/mojoio/cflare/badges/master/coverage.svg)](https://GitLab.com/mojoio/cflare/commits/master)
|
[![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/cloudflare.svg)](https://www.npmjs.com/package/@mojoio/cloudflare)
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/cflare.svg)](https://www.npmjs.com/package/cflare)
|
[![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/cloudflare/badge.svg)](https://snyk.io/test/npm/@mojoio/cloudflare)
|
||||||
[![Dependency Status](https://david-dm.org/mojoio/cflare.svg)](https://david-dm.org/mojoio/cflare)
|
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[![bitHound Dependencies](https://www.bithound.io/github/mojoio/cflare/badges/dependencies.svg)](https://www.bithound.io/github/mojoio/cflare/master/dependencies/npm)
|
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[![bitHound Code](https://www.bithound.io/github/mojoio/cflare/badges/code.svg)](https://www.bithound.io/github/mojoio/cflare)
|
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
|
||||||
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -47,8 +42,9 @@ let myAsyncCflareManagement = async () => {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io)
|
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
||||||
|
@ -2,5 +2,15 @@
|
|||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "mojoio",
|
||||||
|
"gitrepo": "cloudflare",
|
||||||
|
"shortDescription": "easy cloudflare management",
|
||||||
|
"npmPackagename": "@mojoio/cloudflare",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1380
package-lock.json
generated
1380
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
41
package.json
41
package.json
@ -24,19 +24,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
|
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"@pushrocks/smartlog": "^2.0.1",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartrequest": "^1.1.16",
|
||||||
"@pushrocks/smartstring": "^3.0.4",
|
"@pushrocks/smartstring": "^3.0.10",
|
||||||
"@tsclass/tsclass": "^1.0.48"
|
"@tsclass/tsclass": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.11",
|
||||||
"@gitzone/tsrun": "^1.1.12",
|
"@gitzone/tsrun": "^1.2.6",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.24",
|
||||||
"@pushrocks/qenv": "^2.0.2",
|
"@pushrocks/qenv": "^4.0.0",
|
||||||
"@pushrocks/tapbundle": "^3.0.5",
|
"@pushrocks/tapbundle": "^3.0.11",
|
||||||
"@types/node": "^10.5.8"
|
"@types/node": "^12.6.6",
|
||||||
}
|
"tslint": "^5.18.0",
|
||||||
}
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/*",
|
||||||
|
"ts_web/*",
|
||||||
|
"dist/*",
|
||||||
|
"dist_web/*",
|
||||||
|
"dist_ts_web/*",
|
||||||
|
"assets/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
|
}
|
14
test/test.ts
14
test/test.ts
@ -1,19 +1,19 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import cloudflare = require('../ts/index');
|
import cloudflare = require('../ts/index');
|
||||||
import { Qenv } from '@pushrocks/qenv';
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
|
||||||
|
|
||||||
let testCloudflareAccount = new cloudflare.CloudflareAccount();
|
const testCloudflareAccount = new cloudflare.CloudflareAccount();
|
||||||
testCloudflareAccount.auth({
|
testCloudflareAccount.auth({
|
||||||
email: process.env.CF_EMAIL,
|
email: testQenv.getEnvVarOnDemand('CF_EMAIL'),
|
||||||
key: process.env.CF_KEY
|
key: testQenv.getEnvVarOnDemand('CF_KEY')
|
||||||
});
|
});
|
||||||
|
|
||||||
let randomPrefix = Math.floor(Math.random() * 2000);
|
const randomPrefix = Math.floor(Math.random() * 2000);
|
||||||
|
|
||||||
tap.skip.test('.listZones() -> should display an entire account', async tools => {
|
tap.skip.test('.listZones() -> should display an entire account', async tools => {
|
||||||
tools.timeout(600000);
|
tools.timeout(600000);
|
||||||
let result = await testCloudflareAccount.listZones();
|
const result = await testCloudflareAccount.listZones();
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ tap.test('should create a valid record for a subdomain', async tools => {
|
|||||||
|
|
||||||
tap.test('should get a record from Cloudflare', async tools => {
|
tap.test('should get a record from Cloudflare', async tools => {
|
||||||
tools.timeout(600000);
|
tools.timeout(600000);
|
||||||
await testCloudflareAccount.getRecord('bleu.de', 'A').then(function(responseArg) {
|
await testCloudflareAccount.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A').then(responseArg => {
|
||||||
console.log(responseArg);
|
console.log(responseArg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
import plugins = require('./cloudflare.plugins');
|
import plugins = require('./cloudflare.plugins');
|
||||||
import * as interfaces from './cloudflare.interfaces';
|
import * as interfaces from './interfaces/cloudflare.interfaces';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
import { TDnsRecord } from '@tsclass/tsclass';
|
import { TDnsRecord } from '@tsclass/tsclass';
|
||||||
|
import { WorkerManager } from './cloudflare.classes.workermanager';
|
||||||
|
import { ZoneManager } from './cloudflare.classes.zonemanager';
|
||||||
|
|
||||||
export class CloudflareAccount {
|
export class CloudflareAccount {
|
||||||
private authEmail: string;
|
private authEmail: string;
|
||||||
private authKey: string;
|
private authKey: string;
|
||||||
|
|
||||||
|
public workerManager = new WorkerManager(this);
|
||||||
|
public zoneManager = new ZoneManager(this);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// Nothing here
|
// Nothing here
|
||||||
}
|
}
|
||||||
|
|
||||||
auth(optionsArg: { email: string; key: string }) {
|
public auth(optionsArg: { email: string; key: string }) {
|
||||||
this.authEmail = optionsArg.email;
|
this.authEmail = optionsArg.email;
|
||||||
this.authKey = optionsArg.key;
|
this.authKey = optionsArg.key;
|
||||||
}
|
}
|
||||||
@ -20,16 +26,19 @@ export class CloudflareAccount {
|
|||||||
* gets a zone id of a domain from cloudflare
|
* gets a zone id of a domain from cloudflare
|
||||||
* @param domainName
|
* @param domainName
|
||||||
*/
|
*/
|
||||||
async getZoneId(domainName: string) {
|
public async getZoneId(domainName: string) {
|
||||||
let domain = new plugins.smartstring.Domain(domainName);
|
const domain = new plugins.smartstring.Domain(domainName);
|
||||||
let zoneArray = await this.listZones(domain.zoneName);
|
const zoneArray = await this.listZones(domain.zoneName);
|
||||||
let filteredResponse = zoneArray.filter(zoneArg => {
|
const filteredResponse = zoneArray.filter(zoneArg => {
|
||||||
return zoneArg.name === domainName;
|
return zoneArg.name === domainName;
|
||||||
});
|
});
|
||||||
if (filteredResponse.length >= 1) {
|
if (filteredResponse.length >= 1) {
|
||||||
return filteredResponse[0].id;
|
return filteredResponse[0].id;
|
||||||
} else {
|
} else {
|
||||||
plugins.smartlog.defaultLogger.error(`the domain ${domainName} does not appear to be in this account!`);
|
plugins.smartlog.defaultLogger.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!`);
|
throw new Error(`the domain ${domainName} does not appear to be in this account!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,45 +46,46 @@ export class CloudflareAccount {
|
|||||||
/**
|
/**
|
||||||
* gets a record
|
* gets a record
|
||||||
* @param domainNameArg
|
* @param domainNameArg
|
||||||
* @param typeArg
|
* @param typeArg
|
||||||
*/
|
*/
|
||||||
async getRecord(domainNameArg: string, typeArg: TDnsRecord): Promise<interfaces.ICflareRecord> {
|
public async getRecord(
|
||||||
let done = plugins.smartpromise.defer<interfaces.ICflareRecord>();
|
domainNameArg: string,
|
||||||
let result: interfaces.ICflareRecord;
|
typeArg: TDnsRecord
|
||||||
|
): Promise<interfaces.ICflareRecord> {
|
||||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
this.listRecords(domain.zoneName).then(recordArrayArg => {
|
const recordArrayArg = await this.listRecords(domain.zoneName);
|
||||||
let filteredResponse = recordArrayArg.filter(recordArg => {
|
const filteredResponse = recordArrayArg.filter(recordArg => {
|
||||||
return recordArg.type === typeArg && recordArg.name === domainNameArg;
|
return recordArg.type === typeArg && recordArg.name === domainNameArg;
|
||||||
});
|
|
||||||
done.resolve(filteredResponse[0]);
|
|
||||||
});
|
});
|
||||||
return done.promise;
|
return filteredResponse[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async createRecord(domainNameArg: string, typeArg: TDnsRecord, contentArg: string) {
|
public async createRecord(
|
||||||
let done = plugins.smartpromise.defer();
|
domainNameArg: string,
|
||||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
typeArg: TDnsRecord,
|
||||||
let domainIdArg = await this.getZoneId(domain.zoneName);
|
contentArg: string
|
||||||
let dataObject = {
|
): Promise<any> {
|
||||||
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
|
const domainIdArg = await this.getZoneId(domain.zoneName);
|
||||||
|
const dataObject = {
|
||||||
name: domain.fullName,
|
name: domain.fullName,
|
||||||
type: typeArg,
|
type: typeArg,
|
||||||
content: contentArg
|
content: contentArg
|
||||||
};
|
};
|
||||||
this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject).then(function(
|
const response = await this.request(
|
||||||
responseArg
|
'POST',
|
||||||
) {
|
'/zones/' + domainIdArg + '/dns_records',
|
||||||
done.resolve(responseArg);
|
dataObject
|
||||||
});
|
);
|
||||||
return done.promise;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRecord(domainNameArg: string, typeArg: TDnsRecord) {
|
public removeRecord(domainNameArg: string, typeArg: TDnsRecord) {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
this.getRecord(domain.fullName, typeArg).then(responseArg => {
|
this.getRecord(domain.fullName, typeArg).then(responseArg => {
|
||||||
if (responseArg) {
|
if (responseArg) {
|
||||||
let requestRoute: string =
|
const requestRoute: string =
|
||||||
'/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id;
|
'/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id;
|
||||||
this.request('DELETE', requestRoute).then(responseArg => {
|
this.request('DELETE', requestRoute).then(responseArg => {
|
||||||
done.resolve(responseArg);
|
done.resolve(responseArg);
|
||||||
@ -87,9 +97,9 @@ export class CloudflareAccount {
|
|||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRecord(domainNameArg: string, typeArg: string, valueArg) {
|
public updateRecord(domainNameArg: string, typeArg: string, valueArg) {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,14 +107,14 @@ export class CloudflareAccount {
|
|||||||
* list all records of a specified domain name
|
* list all records of a specified domain name
|
||||||
* @param domainNameArg - the domain name that you want to get the records from
|
* @param domainNameArg - the domain name that you want to get the records from
|
||||||
*/
|
*/
|
||||||
async listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
|
public async listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
|
||||||
let domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
let domainId = await this.getZoneId(domain.zoneName);
|
const domainId = await this.getZoneId(domain.zoneName);
|
||||||
let responseArg: any = await this.request(
|
const responseArg: any = await this.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/zones/' + domainId + '/dns_records?per_page=100'
|
'/zones/' + domainId + '/dns_records?per_page=100'
|
||||||
);
|
);
|
||||||
let result: interfaces.ICflareRecord[] = responseArg.result;
|
const result: interfaces.ICflareRecord[] = responseArg.result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +122,7 @@ export class CloudflareAccount {
|
|||||||
* list all zones in the associated authenticated account
|
* list all zones in the associated authenticated account
|
||||||
* @param domainName
|
* @param domainName
|
||||||
*/
|
*/
|
||||||
async listZones(domainName?: string): Promise<interfaces.ICflareZone[]> {
|
public async listZones(domainName?: string): Promise<interfaces.ICflareZone[]> {
|
||||||
// TODO: handle pagination
|
// TODO: handle pagination
|
||||||
let requestRoute = `/zones?per_page=50`;
|
let requestRoute = `/zones?per_page=50`;
|
||||||
|
|
||||||
@ -121,24 +131,24 @@ export class CloudflareAccount {
|
|||||||
requestRoute = `${requestRoute}&name=${domainName}`;
|
requestRoute = `${requestRoute}&name=${domainName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: any = await this.request('GET', requestRoute);
|
const response: any = await this.request('GET', requestRoute);
|
||||||
let result = response.result;
|
const result = response.result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async purgeZone(domainName: string) {
|
public async purgeZone(domainName: string) {
|
||||||
let domain = new plugins.smartstring.Domain(domainName);
|
const domain = new plugins.smartstring.Domain(domainName);
|
||||||
let domainId = await this.getZoneId(domain.zoneName);
|
const domainId = await this.getZoneId(domain.zoneName);
|
||||||
let requestUrl = `/zones/${domainId}/purge_cache`;
|
const requestUrl = `/zones/${domainId}/purge_cache`;
|
||||||
let payload = {
|
const payload = {
|
||||||
purge_everything: true
|
purge_everything: true
|
||||||
};
|
};
|
||||||
let respone = await this.request('DELETE', requestUrl, payload);
|
const respone = await this.request('DELETE', requestUrl, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
request(methodArg: string, routeArg: string, dataArg = {}) {
|
public request(methodArg: string, routeArg: string, dataArg = {}) {
|
||||||
let done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
let options: plugins.smartrequest.ISmartRequestOptions = {
|
const options: plugins.smartrequest.ISmartRequestOptions = {
|
||||||
method: methodArg,
|
method: methodArg,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -151,8 +161,8 @@ export class CloudflareAccount {
|
|||||||
|
|
||||||
let retryCount = 0; // count the amount of retries
|
let retryCount = 0; // count the amount of retries
|
||||||
|
|
||||||
let makeRequest = async () => {
|
const makeRequest = async () => {
|
||||||
let response: any = await plugins.smartrequest.request(
|
const response: any = await plugins.smartrequest.request(
|
||||||
`https://api.cloudflare.com/client/v4${routeArg}`,
|
`https://api.cloudflare.com/client/v4${routeArg}`,
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
@ -169,7 +179,9 @@ export class CloudflareAccount {
|
|||||||
done.reject(new Error('request failed'));
|
done.reject(new Error('request failed'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let retryRequest = async (delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)) => {
|
const retryRequest = async (
|
||||||
|
delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)
|
||||||
|
) => {
|
||||||
console.log(`retry started and waiting for ${delayTimeArg} ms`);
|
console.log(`retry started and waiting for ${delayTimeArg} ms`);
|
||||||
await plugins.smartdelay.delayFor(delayTimeArg);
|
await plugins.smartdelay.delayFor(delayTimeArg);
|
||||||
if (retryCount < 10) {
|
if (retryCount < 10) {
|
||||||
|
10
ts/cloudflare.classes.workermanager.ts
Normal file
10
ts/cloudflare.classes.workermanager.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import * as plugins from './cloudflare.plugins';
|
||||||
|
import { CloudflareAccount } from './cloudflare.classes.account';
|
||||||
|
|
||||||
|
export class WorkerManager {
|
||||||
|
public cfAccount: CloudflareAccount;
|
||||||
|
|
||||||
|
constructor(cfAccountArg: CloudflareAccount) {
|
||||||
|
this.cfAccount = cfAccountArg;
|
||||||
|
}
|
||||||
|
}
|
11
ts/cloudflare.classes.zonemanager.ts
Normal file
11
ts/cloudflare.classes.zonemanager.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as plugins from './cloudflare.plugins';
|
||||||
|
import { CloudflareAccount } from './cloudflare.classes.account';
|
||||||
|
|
||||||
|
export class ZoneManager {
|
||||||
|
public cfAccount: CloudflareAccount;
|
||||||
|
public zoneName: string;
|
||||||
|
|
||||||
|
constructor(cfAccountArg: CloudflareAccount) {
|
||||||
|
this.cfAccount = cfAccountArg;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './cloudflare.plugins';
|
import * as plugins from '../cloudflare.plugins';
|
||||||
|
|
||||||
export interface ICflareZone {
|
export interface ICflareZone {
|
||||||
id: string;
|
id: string;
|
1
ts/interfaces/index.ts
Normal file
1
ts/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './cloudflare.interfaces';
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user