diff --git a/dist/cflare.classes.cflareaccount.d.ts b/dist/cflare.classes.cflareaccount.d.ts index fc52a53..beeb991 100644 --- a/dist/cflare.classes.cflareaccount.d.ts +++ b/dist/cflare.classes.cflareaccount.d.ts @@ -1,9 +1,8 @@ -import "typings-global"; +import 'typings-global'; import * as interfaces from './cflare.interfaces'; export declare class CflareAccount { private authEmail; private authKey; - private authCheck(); constructor(); auth(optionsArg: { email: string; @@ -17,4 +16,5 @@ export declare class CflareAccount { listRecords(domainNameArg: string): Promise; listZones(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 2cd33a9..7e21972 100644 --- a/dist/cflare.classes.cflareaccount.js +++ b/dist/cflare.classes.cflareaccount.js @@ -10,12 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge require("typings-global"); const plugins = require("./cflare.plugins"); class CflareAccount { - authCheck() { - return (this.authEmail && this.authKey); //check if auth is available - } constructor() { } - ; auth(optionsArg) { this.authEmail = optionsArg.email; this.authKey = optionsArg.key; @@ -44,7 +40,7 @@ class CflareAccount { this.listRecords(domain.zoneName) .then((recordArrayArg) => { let filteredResponse = recordArrayArg.filter((recordArg) => { - return (recordArg.type == typeArg && recordArg.name == domainNameArg); + return (recordArg.type === typeArg && recordArg.name === domainNameArg); }); done.resolve(filteredResponse[0]); }); @@ -61,7 +57,7 @@ class CflareAccount { type: typeArg, content: contentArg }; - this.request("POST", "/zones/" + domainIdArg + "/dns_records", dataObject) + this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject) .then(function (responseArg) { done.resolve(responseArg); }); @@ -75,8 +71,8 @@ class CflareAccount { this.getRecord(domain.fullName, typeArg) .then((responseArg) => { if (responseArg) { - let requestRoute = "/zones/" + responseArg.zone_id + "/dns_records/" + responseArg.id; - this.request("DELETE", requestRoute) + let requestRoute = '/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id; + this.request('DELETE', requestRoute) .then((responseArg) => { done.resolve(responseArg); }); @@ -100,7 +96,7 @@ class CflareAccount { let domain = new plugins.smartstring.Domain(domainNameArg); this.getZoneId(domain.zoneName) .then((domainIdArg) => { - this.request("GET", "/zones/" + domainIdArg + "/dns_records?per_page=100") + this.request('GET', '/zones/' + domainIdArg + '/dns_records?per_page=100') .then(function (responseArg) { result = responseArg.result; done.resolve(result); @@ -110,11 +106,11 @@ class CflareAccount { } listZones(domainName) { let done = plugins.q.defer(); - let requestRoute = "/zones?per_page=50"; + let requestRoute = '/zones?per_page=50'; if (domainName) - requestRoute = requestRoute + "&name=" + domainName; + requestRoute = requestRoute + '&name=' + domainName; let result = []; - this.request("GET", requestRoute) + this.request('GET', requestRoute) .then((responseArg) => { result = responseArg.result; done.resolve(result); @@ -127,57 +123,45 @@ class CflareAccount { let jsonArg = JSON.stringify(dataArg); let options = { method: methodArg, - url: "https://api.cloudflare.com/client/v4" + routeArg, headers: { - "Content-Type": "application/json", - "X-Auth-Email": this.authEmail, - "X-Auth-Key": this.authKey + 'Content-Type': 'application/json', + 'X-Auth-Email': this.authEmail, + 'X-Auth-Key': this.authKey }, - body: jsonArg + requestBody: jsonArg }; - //console.log(options); + // console.log(options); let retryCount = 0; - let makeRequest = () => { - plugins.request(options, function (err, res, body) { - let responseObj; - try { - responseObj = JSON.parse(body); - } - catch (err) { - console.log(res.statusCode); - retryRequest(); - return; - } - if (!err && res.statusCode === 200) { - done.resolve(responseObj); - } - else if (!err && res.statusCode === 429) { - console.log('rate limited! Waiting for retry!'); - retryRequest(); - return; - } - else { - console.log(res.statusCode); - console.log(responseObj.messages); - console.log(responseObj.errors); - done.reject(err); - } - ; - }); - }; - let retryRequest = (delayTimeArg = 15000) => __awaiter(this, void 0, void 0, function* () { + let makeRequest = () => __awaiter(this, void 0, void 0, function* () { + let response = yield 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 { + console.log(response.status); + console.log(response.messages); + console.log(response.errors); + done.reject(new Error('request failed')); + } + }); + let retryRequest = (delayTimeArg = 6000) => __awaiter(this, void 0, void 0, function* () { console.log(`retry started and waiting for ${delayTimeArg} ms`); yield plugins.smartdelay.delayFor(delayTimeArg); - if (retryCount < 3) { + if (retryCount < 10) { retryCount++; - makeRequest(); - return; + return yield makeRequest(); } }); makeRequest(); return done.promise; } + authCheck() { + return (this.authEmail && this.authKey); // check if auth is available + } } exports.CflareAccount = CflareAccount; -; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuY2ZsYXJlYWNjb3VudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmNmbGFyZWFjY291bnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsMEJBQXdCO0FBQ3hCLDRDQUE2QztBQUk3QztJQUdZLFNBQVM7UUFDYixNQUFNLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxJQUFJLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLDRCQUE0QjtJQUN6RSxDQUFDO0lBQ0Q7SUFFQSxDQUFDO0lBQUEsQ0FBQztJQUNGLElBQUksQ0FBQyxVQUEwQztRQUMzQyxJQUFJLENBQUMsU0FBUyxHQUFHLFVBQVUsQ0FBQyxLQUFLLENBQUM7UUFDbEMsSUFBSSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUMsR0FBRyxDQUFDO0lBQ2xDLENBQUM7SUFDRCxTQUFTLENBQUMsVUFBa0I7UUFDeEIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztRQUM3QixJQUFJ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FBQ0QsSUFBSSxZQUFZLEdBQUcsQ0FBTyxZQUFZLEdBQUcsSUFBSTtZQUN6QyxPQUFPLENBQUMsR0FBRyxDQUFDLGlDQUFpQyxZQUFZLEtBQUssQ0FBQyxDQUFBO1lBQy9ELE1BQU0sT0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsWUFBWSxDQUFDLENBQUE7WUFDL0MsRUFBRSxDQUFDLENBQUMsVUFBVSxHQUFHLEVBQUUsQ0FBQyxDQUFDLENBQUM7Z0JBQ2xCLFVBQVUsRUFBRSxDQUFBO2dCQUNaLE1BQU0sQ0FBQyxNQUFNLFdBQVcsRUFBRSxDQUFBO1lBQzlCLENBQUM7UUFDTCxDQUFDLENBQUEsQ0FBQTtRQUNELFdBQVcsRUFBRSxDQUFBO1FBQ2IsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVPLFNBQVM7UUFDYixNQUFNLENBQUMsQ0FBQyxJQUFJLENBQUMsU0FBUyxJQUFJLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQSxDQUFDLDZCQUE2QjtJQUN6RSxDQUFDO0NBQ0o7QUEzSkQsc0NBMkpDIn0= \ No newline at end of file diff --git a/dist/cflare.plugins.d.ts b/dist/cflare.plugins.d.ts index 3e6c3ec..7e651cf 100644 --- a/dist/cflare.plugins.d.ts +++ b/dist/cflare.plugins.d.ts @@ -1,6 +1,6 @@ import "typings-global"; export declare let beautylog: any; export import q = require("smartq"); -export declare let request: any; +export import smartrequest = require("smartrequest"); export import smartstring = require("smartstring"); export import smartdelay = require('smartdelay'); diff --git a/dist/cflare.plugins.js b/dist/cflare.plugins.js index 4bc989c..57b890d 100644 --- a/dist/cflare.plugins.js +++ b/dist/cflare.plugins.js @@ -2,7 +2,7 @@ require("typings-global"); exports.beautylog = require("beautylog"); exports.q = require("smartq"); -exports.request = require("request"); +exports.smartrequest = require("smartrequest"); exports.smartstring = require("smartstring"); exports.smartdelay = require("smartdelay"); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUN6QixRQUFBLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDeEMsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUNwQywrQ0FBcUQ7QUFDckQsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9 \ No newline at end of file diff --git a/package.json b/package.json index 3e9e21f..2d264b7 100644 --- a/package.json +++ b/package.json @@ -23,16 +23,16 @@ "homepage": "https://github.com/pushrocks/cflare#readme", "dependencies": { "beautylog": "^6.1.1", - "request": "^2.79.0", "smartdelay": "^1.0.1", - "smartq": "^1.0.4", + "smartq": "^1.1.0", + "smartrequest": "^1.0.4", "smartstring": "^2.0.22", "typings-global": "^1.0.14" }, "devDependencies": { "npmts-g": "^6.0.0", "qenv": "^1.1.3", - "should": "^11.1.2", + "smartchai": "^1.0.1", "typings-test": "^1.0.3" } } diff --git a/test/test.d.ts b/test/test.d.ts index e7cc8ee..2fd432a 100644 --- a/test/test.d.ts +++ b/test/test.d.ts @@ -1 +1 @@ -import "typings-test"; +import 'typings-test'; diff --git a/test/test.js b/test/test.js index 6691585..621f784 100644 --- a/test/test.js +++ b/test/test.js @@ -1,19 +1,18 @@ "use strict"; require("typings-test"); const cflare = require("../dist/index"); -let should = require("should"); const qenv_1 = require("qenv"); -let testQenv = new qenv_1.Qenv(process.cwd(), process.cwd() + "/.nogit"); +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 }); -describe("cflare", function () { - describe(".CflareAccount", function () { - describe(".listZones()", function () { - it("should display an entire account", function (done) { +describe('cflare', function () { + describe('.CflareAccount', function () { + describe('.listZones()', function () { + it('should display an entire account', function (done) { this.timeout(30000); testCflareAccount.listZones() .then((responseArg) => { @@ -21,63 +20,63 @@ describe("cflare", function () { }); }); }); - describe(".getZoneId(domainName)", function () { - it("should get an Cloudflare Id for a domain string", function (done) { + describe('.getZoneId(domainName)', function () { + it('should get an Cloudflare Id for a domain string', function (done) { this.timeout(30000); - testCflareAccount.getZoneId("bleu.de") + testCflareAccount.getZoneId('bleu.de') .then((responseArg) => { done(); }); }); }); - describe(".listRecords(domainName)", function () { - it("should list all records for a specific Domain Name", function (done) { + describe('.listRecords(domainName)', function () { + it('should list all records for a specific Domain Name', function (done) { this.timeout(30000); - testCflareAccount.listRecords("bleu.de") + testCflareAccount.listRecords('bleu.de') .then((responseArg) => { console.log(responseArg); done(); }); }); }); - describe(".createRecord", function () { - it("should create a valid record for a level 2 domain", function (done) { + describe('.createRecord', function () { + it('should create a valid record for a level 2 domain', function (done) { this.timeout(30000); - testCflareAccount.createRecord("bleu.de", "A", "127.0.0.1") + testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1') .then(function (responseArg) { done(); }); }); - it("should create a valid record for a subdomain", function (done) { + it('should create a valid record for a subdomain', function (done) { this.timeout(30000); - testCflareAccount.createRecord("subdomain.bleu.de", "A", "127.0.0.1") + testCflareAccount.createRecord('subdomain.bleu.de', 'A', '127.0.0.1') .then(function (responseArg) { done(); }); }); }); - describe(".getRecord", function () { - it("should get a record from Cloudflare", function (done) { + describe('.getRecord', function () { + it('should get a record from Cloudflare', function (done) { this.timeout(30000); - testCflareAccount.getRecord("bleu.de", "A") + testCflareAccount.getRecord('bleu.de', 'A') .then(function (responseArg) { console.log(responseArg); done(); }); }); }); - describe(".removeRecord", function () { - it("should remove a record from Cloudflare", function (done) { + describe('.removeRecord', function () { + it('should remove a record from Cloudflare', function (done) { this.timeout(30000); - testCflareAccount.removeRecord("bleu.de", "A") + testCflareAccount.removeRecord('bleu.de', 'A') .then(function (responseArg) { console.log(responseArg); done(); }); }); - it("should remove a subdomain record from Cloudflare", function (done) { + it('should remove a subdomain record from Cloudflare', function (done) { this.timeout(30000); - testCflareAccount.removeRecord("subdomain.bleu.de", "A") + testCflareAccount.removeRecord('subdomain.bleu.de', 'A') .then(function (responseArg) { console.log(responseArg); done(); @@ -86,4 +85,4 @@ describe("cflare", function () { }); }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUN0Qix3Q0FBeUM7QUFDekMsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0FBQy9CLCtCQUEwQjtBQUMxQixJQUFJLFFBQVEsR0FBRyxJQUFJLFdBQUksQ0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLEVBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxHQUFHLFNBQVMsQ0FBQyxDQUFDO0FBQ2pFLE9BQU8sQ0FBQyxHQUFHLENBQUMs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QUFJO2dCQUN2RCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO2dCQUNuQixpQkFBaUIsQ0FBQyxZQUFZLENBQUMsU0FBUyxFQUFFLEdBQUcsQ0FBQztxQkFDekMsSUFBSSxDQUFDLFVBQVUsV0FBVztvQkFDdkIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLENBQUMsQ0FBQTtvQkFDeEIsSUFBSSxFQUFFLENBQUE7Z0JBQ1YsQ0FBQyxDQUFDLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQTtZQUNGLEVBQUUsQ0FBQyxrREFBa0QsRUFBRSxVQUFVLElBQUk7Z0JBQ2pFLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7Z0JBQ25CLGlCQUFpQixDQUFDLFlBQVksQ0FBQyxtQkFBbUIsRUFBRSxHQUFHLENBQUM7cUJBQ25ELElBQUksQ0FBQyxVQUFVLFdBQVc7b0JBQ3ZCLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUE7b0JBQ3hCLElBQUksRUFBRSxDQUFBO2dCQUNWLENBQUMsQ0FBQyxDQUFBO1lBQ1YsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ== \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 5cf4f11..69dc110 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,88 +1,88 @@ -import "typings-test"; -import cflare = require("../dist/index"); -let should = require("should"); -import {Qenv} from "qenv"; -let testQenv = new Qenv(process.cwd(),process.cwd() + "/.nogit"); -console.log(testQenv.missingEnvVars); -let testCflareAccount = new cflare.CflareAccount(); +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 -}); +}) -describe("cflare",function(){ - describe(".CflareAccount",function(){ - describe(".listZones()",function(){ - it("should display an entire account",function(done){ - this.timeout(30000); - testCflareAccount.listZones() - .then((responseArg)=>{ - done(); - }) - }); - }); - describe(".getZoneId(domainName)",function(){ - it("should get an Cloudflare Id for a domain string",function(done){ +describe('cflare', function () { + describe('.CflareAccount', function () { + describe('.listZones()', function () { + it('should display an entire account', function (done) { this.timeout(30000) - 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(30000); - testCflareAccount.listRecords("bleu.de") + testCflareAccount.listZones() .then((responseArg) => { - console.log(responseArg); - done(); - }); - }); + done() + }) + }) + }) + describe('.getZoneId(domainName)', function () { + it('should get an Cloudflare Id for a domain string', function (done) { + this.timeout(30000) + 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(30000) + testCflareAccount.listRecords('bleu.de') + .then((responseArg) => { + console.log(responseArg) + done() + }) + }) + }) + describe('.createRecord', function () { + it('should create a valid record for a level 2 domain', function (done) { + this.timeout(30000) + testCflareAccount.createRecord('bleu.de', 'A', '127.0.0.1') + .then(function (responseArg) { + done() + }) + }) + it('should create a valid record for a subdomain', function (done) { + this.timeout(30000) + testCflareAccount.createRecord('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(30000) + testCflareAccount.getRecord('bleu.de', 'A') + .then(function (responseArg) { + console.log(responseArg) + done() + }) + }) + }) + describe('.removeRecord', function () { + it('should remove a record from Cloudflare', function (done) { + this.timeout(30000) + testCflareAccount.removeRecord('bleu.de', 'A') + .then(function (responseArg) { + console.log(responseArg) + done() + }) + }) + it('should remove a subdomain record from Cloudflare', function (done) { + this.timeout(30000) + testCflareAccount.removeRecord('subdomain.bleu.de', 'A') + .then(function (responseArg) { + console.log(responseArg) + done() + }) + }) }) - describe(".createRecord",function(){ - it("should create a valid record for a level 2 domain",function(done){ - this.timeout(30000); - testCflareAccount.createRecord("bleu.de","A","127.0.0.1") - .then(function(responseArg){ - done(); - }); - }); - it("should create a valid record for a subdomain",function(done){ - this.timeout(30000); - testCflareAccount.createRecord("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(30000); - testCflareAccount.getRecord("bleu.de","A") - .then(function(responseArg){ - console.log(responseArg); - done(); - }); - }); - }); - describe(".removeRecord",function(){ - it("should remove a record from Cloudflare",function(done){ - this.timeout(30000); - testCflareAccount.removeRecord("bleu.de","A") - .then(function(responseArg){ - console.log(responseArg); - done(); - }); - }); - it("should remove a subdomain record from Cloudflare",function(done){ - this.timeout(30000); - testCflareAccount.removeRecord("subdomain.bleu.de","A") - .then(function(responseArg){ - console.log(responseArg); - done(); - }); - }); - }); }) -}); +}) diff --git a/ts/cflare.classes.cflareaccount.ts b/ts/cflare.classes.cflareaccount.ts index 2027a95..641a0a7 100644 --- a/ts/cflare.classes.cflareaccount.ts +++ b/ts/cflare.classes.cflareaccount.ts @@ -1,167 +1,161 @@ -import "typings-global"; -import plugins = require("./cflare.plugins"); -import helpers = require("./cflare.classes.helpers"); +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; - private authCheck() { - return (this.authEmail && this.authKey); //check if auth is available - } + private authEmail: string + private authKey: string constructor() { - }; - auth(optionsArg: { email: string, key: string }) { - this.authEmail = optionsArg.email; - this.authKey = optionsArg.key; } + + auth(optionsArg: { email: string, key: string }) { + this.authEmail = optionsArg.email + this.authKey = optionsArg.key + } + getZoneId(domainName: string) { - let done = plugins.q.defer(); + let done = plugins.q.defer() this.listZones(domainName) .then(zoneArrayArg => { let filteredResponse = zoneArrayArg.filter((zoneArg) => { - return zoneArg.name === domainName; - }); + return zoneArg.name === domainName + }) if (filteredResponse.length >= 1) { - done.resolve(filteredResponse[0].id); + done.resolve(filteredResponse[ 0 ].id) } else { - plugins.beautylog.error(`the domain ${domainName} does not appear to be in this account!`); - done.reject(undefined); + plugins.beautylog.error(`the domain ${domainName} does not appear to be in this account!`) + done.reject(undefined) } - }); - return done.promise; + }) + return done.promise } getRecord(domainNameArg: string, typeArg: string): Promise { - let done = plugins.q.defer(); + let done = plugins.q.defer() let result: interfaces.ICflareRecord - let domain = new plugins.smartstring.Domain(domainNameArg); + 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); + return (recordArg.type === typeArg && recordArg.name === domainNameArg) }) - done.resolve(filteredResponse[0]); + done.resolve(filteredResponse[ 0 ]) }) - return done.promise; + return done.promise }; createRecord(domainNameArg: string, typeArg: string, contentArg: string) { - let done = plugins.q.defer(); - let domain = new plugins.smartstring.Domain(domainNameArg); + 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) + } + this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject) .then(function (responseArg) { - done.resolve(responseArg); - }); - }); - return done.promise; + done.resolve(responseArg) + }) + }) + return done.promise }; removeRecord(domainNameArg: string, typeArg: string) { - let done = plugins.q.defer(); - let domain = new plugins.smartstring.Domain(domainNameArg); + 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) + let requestRoute: string = '/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id + this.request('DELETE', requestRoute) .then((responseArg) => { - done.resolve(responseArg); - }); + done.resolve(responseArg) + }) } else { - done.reject(); + done.reject() } - }); - return done.promise; + }) + return done.promise }; updateRecord(domainNameArg: string, typeArg: string, valueArg) { - let done = plugins.q.defer(); - let domain = new plugins.smartstring.Domain(domainNameArg); - return done.promise; + let done = plugins.q.defer() + let domain = new plugins.smartstring.Domain(domainNameArg) + return done.promise }; listRecords(domainNameArg: string): Promise { - let done = plugins.q.defer(); + let done = plugins.q.defer() let result: interfaces.ICflareRecord[] = [] - let domain = new plugins.smartstring.Domain(domainNameArg); + let domain = new plugins.smartstring.Domain(domainNameArg) this.getZoneId(domain.zoneName) .then((domainIdArg) => { - this.request("GET", "/zones/" + domainIdArg + "/dns_records?per_page=100") + this.request('GET', '/zones/' + domainIdArg + '/dns_records?per_page=100') .then(function (responseArg: any) { result = responseArg.result - done.resolve(result); - }); - }); - return done.promise; + done.resolve(result) + }) + }) + return done.promise } listZones(domainName?: string): Promise { // TODO: handle pagination - let done = plugins.q.defer(); - let requestRoute = "/zones?per_page=50" - if (domainName) requestRoute = requestRoute + "&name=" + domainName; - let result = []; - this.request("GET", requestRoute) + let done = plugins.q.defer() + 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; + 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 = { + let done = plugins.q.defer() + let jsonArg: string = JSON.stringify(dataArg) + let options: plugins.smartrequest.ISmartRequestOptions = { method: methodArg, - url: "https://api.cloudflare.com/client/v4" + routeArg, headers: { - "Content-Type": "application/json", - "X-Auth-Email": this.authEmail, - "X-Auth-Key": this.authKey + 'Content-Type': 'application/json', + 'X-Auth-Email': this.authEmail, + 'X-Auth-Key': this.authKey }, - body: jsonArg - }; - //console.log(options); + requestBody: jsonArg + } + // console.log(options); let retryCount = 0 - let makeRequest = () => { - plugins.request(options, function (err, res, body) { - let responseObj - try { - responseObj = JSON.parse(body); - } catch (err) { - console.log(res.statusCode) - retryRequest() - return - } - if (!err && res.statusCode === 200) { - done.resolve(responseObj); - } else if (!err && res.statusCode === 429) { - console.log('rate limited! Waiting for retry!') - retryRequest() - return - } else { - console.log(res.statusCode) - console.log(responseObj.messages); - console.log(responseObj.errors); - done.reject(err); - }; - }); + 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 { + console.log(response.status) + console.log(response.messages) + console.log(response.errors) + done.reject(new Error('request failed')) + } } - let retryRequest = async (delayTimeArg = 15000) => { + let retryRequest = async (delayTimeArg = 6000) => { console.log(`retry started and waiting for ${delayTimeArg} ms`) await plugins.smartdelay.delayFor(delayTimeArg) - if (retryCount < 3) { + if (retryCount < 10) { retryCount++ - makeRequest() - return + return await makeRequest() } } makeRequest() - return done.promise; + return done.promise } -}; \ No newline at end of file + + private authCheck() { + return (this.authEmail && this.authKey) // check if auth is available + } +} diff --git a/ts/cflare.plugins.ts b/ts/cflare.plugins.ts index 8ac0822..4db5a79 100644 --- a/ts/cflare.plugins.ts +++ b/ts/cflare.plugins.ts @@ -1,6 +1,6 @@ import "typings-global"; export let beautylog = require("beautylog"); export import q = require("smartq"); -export let request = require("request"); +export import smartrequest = require("smartrequest"); export import smartstring = require("smartstring"); export import smartdelay = require('smartdelay'); \ No newline at end of file diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..45052ad --- /dev/null +++ b/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "tslint-config-standard" +}