now supports purging of assets
This commit is contained in:
parent
426237b2a7
commit
162fff134e
1
dist/cflare.classes.cflareaccount.d.ts
vendored
1
dist/cflare.classes.cflareaccount.d.ts
vendored
@ -23,6 +23,7 @@ export declare class CflareAccount {
|
||||
* @param domainName
|
||||
*/
|
||||
listZones(domainName?: string): Promise<interfaces.ICflareZone[]>;
|
||||
purgeZone(domainName: string): Promise<void>;
|
||||
request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>;
|
||||
private authCheck();
|
||||
}
|
||||
|
30
dist/cflare.classes.cflareaccount.js
vendored
30
dist/cflare.classes.cflareaccount.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +1,2 @@
|
||||
import "typings-global";
|
||||
import 'typings-global';
|
||||
export { CflareAccount } from "./cflare.classes.cflareaccount";
|
||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
|
||||
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF3QjtBQUN4QiwrRUFBNkQ7QUFBckQsdURBQUEsYUFBYSxDQUFBIn0=
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwrRUFBNkQ7QUFBckQsdURBQUEsYUFBYSxDQUFBIn0=
|
14
package.json
14
package.json
@ -22,15 +22,15 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
|
||||
"dependencies": {
|
||||
"beautylog": "^6.1.1",
|
||||
"smartdelay": "^1.0.1",
|
||||
"smartq": "^1.1.0",
|
||||
"beautylog": "^6.1.10",
|
||||
"smartdelay": "^1.0.3",
|
||||
"smartq": "^1.1.1",
|
||||
"smartrequest": "^1.0.4",
|
||||
"smartstring": "^2.0.22",
|
||||
"typings-global": "^1.0.14"
|
||||
"smartstring": "^2.0.24",
|
||||
"typings-global": "^1.0.16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"qenv": "^1.1.3",
|
||||
"tapbundle": "^1.0.13"
|
||||
"qenv": "^1.1.7",
|
||||
"tapbundle": "^1.0.14"
|
||||
}
|
||||
}
|
||||
|
16
test/test.ts
16
test/test.ts
@ -12,18 +12,18 @@ testCflareAccount.auth({
|
||||
let randomPrefix = Math.floor(Math.random() * 2000)
|
||||
|
||||
tap.test('.listZones() -> should display an entire account', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
let result = await testCflareAccount.listZones()
|
||||
console.log(result)
|
||||
})
|
||||
|
||||
tap.test('.getZoneId(domainName) -> should get an Cloudflare Id for a domain string', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.getZoneId('bleu.de')
|
||||
})
|
||||
|
||||
tap.test('.listRecords(domainName) -> should list all records for a specific Domain Name', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.listRecords('bleu.de')
|
||||
.then(async (responseArg) => {
|
||||
console.log(responseArg)
|
||||
@ -31,12 +31,12 @@ tap.test('.listRecords(domainName) -> should list all records for a specific Dom
|
||||
})
|
||||
|
||||
tap.test('should create a valid record for a subdomain', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1')
|
||||
})
|
||||
|
||||
tap.test('should get a record from Cloudflare', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.getRecord('bleu.de', 'A')
|
||||
.then(function (responseArg) {
|
||||
console.log(responseArg)
|
||||
@ -44,11 +44,15 @@ tap.test('should get a record from Cloudflare', async (tools) => {
|
||||
})
|
||||
|
||||
tap.test('should remove a subdomain record from Cloudflare', async (tools) => {
|
||||
// tools.timeout(600000)
|
||||
tools.timeout(600000)
|
||||
await testCflareAccount.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
|
||||
.then(async (responseArg) => {
|
||||
console.log(responseArg)
|
||||
})
|
||||
})
|
||||
|
||||
tap.test('.purge(some.domain) -> should purge everything', async () => {
|
||||
await testCflareAccount.purgeZone('bleu.de')
|
||||
})
|
||||
|
||||
tap.start()
|
||||
|
@ -15,7 +15,8 @@ export class CflareAccount {
|
||||
}
|
||||
|
||||
async getZoneId (domainName: string) {
|
||||
let zoneArray = await this.listZones(domainName)
|
||||
let domain = new plugins.smartstring.Domain(domainName)
|
||||
let zoneArray = await this.listZones(domain.zoneName)
|
||||
let filteredResponse = zoneArray.filter((zoneArg) => {
|
||||
return zoneArg.name === domainName
|
||||
})
|
||||
@ -99,11 +100,11 @@ export class CflareAccount {
|
||||
* @param domainName
|
||||
*/
|
||||
async listZones (domainName?: string): Promise<interfaces.ICflareZone[]> { // TODO: handle pagination
|
||||
let requestRoute = '/zones?per_page=50'
|
||||
let requestRoute = `/zones?per_page=50`
|
||||
|
||||
// may be optionally filtered by domain name
|
||||
if (domainName) {
|
||||
requestRoute = requestRoute + '&name=' + domainName
|
||||
requestRoute = `${requestRoute}&name=${domainName}`
|
||||
}
|
||||
|
||||
let response: any = await this.request('GET', requestRoute)
|
||||
@ -111,17 +112,28 @@ export class CflareAccount {
|
||||
return result
|
||||
}
|
||||
|
||||
async purgeZone (domainName: string) {
|
||||
let domain = new plugins.smartstring.Domain(domainName)
|
||||
let domainId = await this.getZoneId(domain.zoneName)
|
||||
let requestUrl = `/zones/${domainId}/purge_cache`
|
||||
let payload = {
|
||||
purge_everything: true
|
||||
}
|
||||
let respone = await this.request('DELETE', requestUrl, payload)
|
||||
}
|
||||
|
||||
request (methodArg: string, routeArg: string, dataArg = {}) {
|
||||
let done = plugins.q.defer()
|
||||
let jsonArg: string = JSON.stringify(dataArg)
|
||||
let jsonStringArg: 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
|
||||
'X-Auth-Key': this.authKey,
|
||||
'Content-Length': Buffer.byteLength(jsonStringArg)
|
||||
},
|
||||
requestBody: jsonArg
|
||||
requestBody: jsonStringArg
|
||||
}
|
||||
// console.log(options);
|
||||
let retryCount = 0
|
||||
@ -137,7 +149,8 @@ export class CflareAccount {
|
||||
console.log('rate limited! Waiting for retry!')
|
||||
retryRequest()
|
||||
} else if (response.statusCode === 400) {
|
||||
console.log('bad request! Going to retry!')
|
||||
console.log(`bad request for route ${routeArg}! Going to retry!`)
|
||||
retryRequest()
|
||||
} else {
|
||||
console.log(response.statusCode)
|
||||
done.reject(new Error('request failed'))
|
||||
|
36
yarn.lock
36
yarn.lock
@ -76,7 +76,7 @@ beautycolor@^1.0.7:
|
||||
ansi-256-colors "^1.1.0"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
beautylog@^6.1.1:
|
||||
beautylog@^6.1.10:
|
||||
version "6.1.10"
|
||||
resolved "https://registry.yarnpkg.com/beautylog/-/beautylog-6.1.10.tgz#9c27e566937684cb689f9372d98cfa5415d50b72"
|
||||
dependencies:
|
||||
@ -184,6 +184,10 @@ early@^2.1.1:
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
es6-error@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.0.2.tgz#eec5c726eacef51b7f6b73c20db6e1b13b069c98"
|
||||
|
||||
escape-string-regexp@^1.0.2:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
@ -285,10 +289,11 @@ jsonfile@^3.0.0:
|
||||
optionalDependencies:
|
||||
graceful-fs "^4.1.6"
|
||||
|
||||
leakage@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.2.0.tgz#9e7a8cc1d241d8c8427e348769e192e172fd8733"
|
||||
leakage@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.3.0.tgz#15d698abdc76bbc6439601f4f3020e77e2d50c39"
|
||||
dependencies:
|
||||
es6-error "^4.0.2"
|
||||
left-pad "^1.1.3"
|
||||
memwatch-next "^0.3.0"
|
||||
minimist "^1.2.0"
|
||||
@ -378,7 +383,7 @@ process-nextick-args@^1.0.6, process-nextick-args@~1.0.6:
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
|
||||
|
||||
qenv@^1.1.3:
|
||||
qenv@^1.1.7:
|
||||
version "1.1.7"
|
||||
resolved "https://registry.yarnpkg.com/qenv/-/qenv-1.1.7.tgz#d03f8bf8fe37494cf08d0919fe765dca84d9afae"
|
||||
dependencies:
|
||||
@ -460,11 +465,12 @@ smartchai@^1.0.3:
|
||||
chai-as-promised "^6.0.0"
|
||||
chai-string "^1.3.0"
|
||||
|
||||
smartdelay@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.1.tgz#687f8bcc09d7c62c9c5a8a1771c1aba3aff54156"
|
||||
smartdelay@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.3.tgz#5fd44dad77262d110702f0293efa80c072cfb579"
|
||||
dependencies:
|
||||
typings-global "^1.0.14"
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
smartenv@^2.0.0:
|
||||
version "2.0.6"
|
||||
@ -512,7 +518,7 @@ smartrequest@^1.0.4:
|
||||
smartq "^1.1.0"
|
||||
typings-global "^1.0.14"
|
||||
|
||||
smartstring@^2.0.22:
|
||||
smartstring@^2.0.24:
|
||||
version "2.0.24"
|
||||
resolved "https://registry.yarnpkg.com/smartstring/-/smartstring-2.0.24.tgz#dc1c5efb738c10a2d7daeea3d800ad2ecc65a26c"
|
||||
dependencies:
|
||||
@ -558,14 +564,14 @@ supports-color@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
|
||||
|
||||
tapbundle@^1.0.13:
|
||||
version "1.0.13"
|
||||
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.13.tgz#0b274aed6a386c0c01d8d517709381ce96e3971e"
|
||||
tapbundle@^1.0.14:
|
||||
version "1.0.14"
|
||||
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.14.tgz#75827e335fcb02216f0267a26a26d702ddc02e3c"
|
||||
dependencies:
|
||||
early "^2.1.1"
|
||||
leakage "^0.2.0"
|
||||
leakage "^0.3.0"
|
||||
smartchai "^1.0.3"
|
||||
smartdelay "^1.0.1"
|
||||
smartdelay "^1.0.3"
|
||||
smartq "^1.1.1"
|
||||
typings-global "^1.0.16"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user