diff --git a/dist/cflare.classes.cflareaccount.d.ts b/dist/cflare.classes.cflareaccount.d.ts index 90c31ed..5cc3485 100644 --- a/dist/cflare.classes.cflareaccount.d.ts +++ b/dist/cflare.classes.cflareaccount.d.ts @@ -23,6 +23,7 @@ export declare class CflareAccount { * @param domainName */ listZones(domainName?: string): Promise; + purgeZone(domainName: string): Promise; request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>; private authCheck(); } diff --git a/dist/cflare.classes.cflareaccount.js b/dist/cflare.classes.cflareaccount.js index 4aec321..3d3b00d 100644 --- a/dist/cflare.classes.cflareaccount.js +++ b/dist/cflare.classes.cflareaccount.js @@ -19,7 +19,8 @@ class CflareAccount { } getZoneId(domainName) { return __awaiter(this, void 0, void 0, function* () { - let zoneArray = yield this.listZones(domainName); + let domain = new plugins.smartstring.Domain(domainName); + let zoneArray = yield this.listZones(domain.zoneName); let filteredResponse = zoneArray.filter((zoneArg) => { return zoneArg.name === domainName; }); @@ -104,27 +105,39 @@ class CflareAccount { */ listZones(domainName) { return __awaiter(this, void 0, void 0, function* () { - 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 = yield this.request('GET', requestRoute); let result = response.result; return result; }); } + purgeZone(domainName) { + return __awaiter(this, void 0, void 0, function* () { + let domain = new plugins.smartstring.Domain(domainName); + let domainId = yield this.getZoneId(domain.zoneName); + let requestUrl = `/zones/${domainId}/purge_cache`; + let payload = { + purge_everything: true + }; + let respone = yield this.request('DELETE', requestUrl, payload); + }); + } request(methodArg, routeArg, dataArg = {}) { let done = plugins.q.defer(); - let jsonArg = JSON.stringify(dataArg); + let jsonStringArg = JSON.stringify(dataArg); let options = { 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; @@ -138,7 +151,8 @@ class CflareAccount { 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); @@ -161,4 +175,4 @@ class CflareAccount { } } exports.CflareAccount = CflareAccount; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuY2ZsYXJlYWNjb3VudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmNmbGFyZWFjY291bnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7OztBQUFBLDBCQUF1QjtBQUN2Qiw0Q0FBNEM7QUFHNUM7SUFHRTtJQUVBLENBQUM7SUFFRCxJQUFJLENBQUUsVUFBMEM7UUFDOUMsSUFBSSxDQUFDLFNBQVMsR0FBRyxVQUFVLENBQUMsS0FBSyxDQUFBO1FBQ2pDLElBQUksQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDLEdBQUcsQ0FBQTtJQUMvQixDQUFDO0lBRUssU0FBUyxDQUFFLFVBQWtCOztZQUNqQyxJQUFJLFNBQVMsR0FBRyxNQUFNLElBQUksQ0FBQyxTQUFTLENBQUMsVUFBVSxDQUFDLENBQUE7WUFDaEQsSUFBSSxnQkFBZ0IsR0FBRyxTQUFTLENBQUMsTUFBTSxDQUFDLENBQUMsT0FBTztnQkFDOUMsTUFBTSxDQUFDLE9BQU8sQ0FBQyxJQUFJLEtBQUssVUFBVSxDQUFBO1lBQ3BDLENBQUMsQ0FBQyxDQUFBO1lBQ0YsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLENBQUMsTUFBTSxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQ2pDLE1BQU0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91b1e5..d05ee1e 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,2 +1,2 @@ -import "typings-global"; +import 'typings-global'; export { CflareAccount } from "./cflare.classes.cflareaccount"; diff --git a/dist/index.js b/dist/index.js index 04b6077..81fd978 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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= \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2QiwrRUFBNkQ7QUFBckQsdURBQUEsYUFBYSxDQUFBIn0= \ No newline at end of file diff --git a/package.json b/package.json index 43b839f..db3482a 100644 --- a/package.json +++ b/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" } } diff --git a/test/test.ts b/test/test.ts index 9e2094b..db8cbbc 100644 --- a/test/test.ts +++ b/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() diff --git a/ts/cflare.classes.cflareaccount.ts b/ts/cflare.classes.cflareaccount.ts index cd76e24..3a740e1 100644 --- a/ts/cflare.classes.cflareaccount.ts +++ b/ts/cflare.classes.cflareaccount.ts @@ -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 { // 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')) diff --git a/yarn.lock b/yarn.lock index 38d718d..38af39c 100644 --- a/yarn.lock +++ b/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"