From 0692d16dd7dca87aebbc1438a366fe16eca1e8ec Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 22 Jan 2017 19:37:00 +0100 Subject: [PATCH] now reacting to rate limiting --- dist/cflare.classes.cflareaccount.d.ts | 17 +-- dist/cflare.classes.cflareaccount.js | 82 ++++++++++---- dist/cflare.classes.helpers.js | 2 +- dist/cflare.interfaces.d.ts | 56 ++++++++++ dist/cflare.interfaces.js | 2 + dist/cflare.plugins.d.ts | 3 +- dist/cflare.plugins.js | 5 +- dist/index.js | 2 +- package.json | 19 ++-- test/test.js | 19 ++-- test/test.ts | 17 ++- ts/cflare.classes.cflareaccount.ts | 148 +++++++++++++++---------- ts/cflare.interfaces.ts | 59 ++++++++++ ts/cflare.plugins.ts | 5 +- 14 files changed, 313 insertions(+), 123 deletions(-) create mode 100644 dist/cflare.interfaces.d.ts create mode 100644 dist/cflare.interfaces.js create mode 100644 ts/cflare.interfaces.ts diff --git a/dist/cflare.classes.cflareaccount.d.ts b/dist/cflare.classes.cflareaccount.d.ts index 44943d3..fc52a53 100644 --- a/dist/cflare.classes.cflareaccount.d.ts +++ b/dist/cflare.classes.cflareaccount.d.ts @@ -1,4 +1,5 @@ import "typings-global"; +import * as interfaces from './cflare.interfaces'; export declare class CflareAccount { private authEmail; private authKey; @@ -8,12 +9,12 @@ export declare class CflareAccount { email: string; key: string; }): void; - getZoneId(domainName: string): any; - getRecord(domainNameArg: string, typeArg: string): any; - createRecord(domainNameArg: string, typeArg: string, contentArg: string): any; - removeRecord(domainNameArg: string, typeArg: string): any; - updateRecord(domainNameArg: string, typeArg: string, valueArg: any): any; - listRecords(domainNameArg: string): any; - listZones(domainName?: string): any; - request(methodArg: string, routeArg: string, dataArg?: {}): any; + getZoneId(domainName: string): Promise<{}>; + getRecord(domainNameArg: string, typeArg: string): Promise; + 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; + listZones(domainName?: string): Promise; + request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>; } diff --git a/dist/cflare.classes.cflareaccount.js b/dist/cflare.classes.cflareaccount.js index 9c45e60..2cd33a9 100644 --- a/dist/cflare.classes.cflareaccount.js +++ b/dist/cflare.classes.cflareaccount.js @@ -1,12 +1,20 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; require("typings-global"); const plugins = require("./cflare.plugins"); class CflareAccount { - constructor() { - } authCheck() { return (this.authEmail && this.authKey); //check if auth is available } + constructor() { + } ; auth(optionsArg) { this.authEmail = optionsArg.email; @@ -15,15 +23,15 @@ class CflareAccount { getZoneId(domainName) { let done = plugins.q.defer(); this.listZones(domainName) - .then((responseArg) => { - let filteredResponse = responseArg.result.filter((zoneArg) => { + .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.blue + " does not appear to be in this account!"); + plugins.beautylog.error(`the domain ${domainName} does not appear to be in this account!`); done.reject(undefined); } }); @@ -31,10 +39,11 @@ class CflareAccount { } getRecord(domainNameArg, typeArg) { let done = plugins.q.defer(); + let result; let domain = new plugins.smartstring.Domain(domainNameArg); this.listRecords(domain.zoneName) - .then((responseArg) => { - let filteredResponse = responseArg.result.filter((recordArg) => { + .then((recordArrayArg) => { + let filteredResponse = recordArrayArg.filter((recordArg) => { return (recordArg.type == typeArg && recordArg.name == domainNameArg); }); done.resolve(filteredResponse[0]); @@ -87,12 +96,14 @@ class CflareAccount { ; listRecords(domainNameArg) { let done = plugins.q.defer(); + let result = []; 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) { - done.resolve(responseArg); + result = responseArg.result; + done.resolve(result); }); }); return done.promise; @@ -102,10 +113,10 @@ class CflareAccount { let requestRoute = "/zones?per_page=50"; if (domainName) requestRoute = requestRoute + "&name=" + domainName; - let result = {}; + let result = []; this.request("GET", requestRoute) - .then(function (responseArg) { - result = responseArg; + .then((responseArg) => { + result = responseArg.result; done.resolve(result); }); return done.promise; @@ -125,21 +136,48 @@ class CflareAccount { body: jsonArg }; //console.log(options); - plugins.request(options, function (err, res, body) { - if (!err && res.statusCode == 200) { - var responseObj = JSON.parse(body); - done.resolve(responseObj); + 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* () { + console.log(`retry started and waiting for ${delayTimeArg} ms`); + yield plugins.smartdelay.delayFor(delayTimeArg); + if (retryCount < 3) { + retryCount++; + makeRequest(); + return; } - else { - console.log(err); - console.log(res); - done.reject(err); - } - ; }); + makeRequest(); return done.promise; } } exports.CflareAccount = CflareAccount; ; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuY2ZsYXJlYWNjb3VudC5qcyIsInNvdXJjZVJvb3QiOiI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SyxDQUFDLENBQUE7WUFDL0QsTUFBTSxPQUFPLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxZQUFZLENBQUMsQ0FBQTtZQUMvQyxFQUFFLENBQUMsQ0FBQyxVQUFVLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQztnQkFDakIsVUFBVSxFQUFFLENBQUE7Z0JBQ1osV0FBVyxFQUFFLENBQUE7Z0JBQ2IsTUFBTSxDQUFBO1lBQ1YsQ0FBQztRQUNMLENBQUMsQ0FBQSxDQUFBO1FBQ0QsV0FBVyxFQUFFLENBQUE7UUFDYixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDO0NBQ0o7QUFqS0Qsc0NBaUtDO0FBQUEsQ0FBQyJ9 \ No newline at end of file diff --git a/dist/cflare.classes.helpers.js b/dist/cflare.classes.helpers.js index ded7d16..6b5b51a 100644 --- a/dist/cflare.classes.helpers.js +++ b/dist/cflare.classes.helpers.js @@ -1,3 +1,3 @@ "use strict"; require("typings-global"); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSJ9 \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QiJ9 \ No newline at end of file diff --git a/dist/cflare.interfaces.d.ts b/dist/cflare.interfaces.d.ts new file mode 100644 index 0000000..750fdcb --- /dev/null +++ b/dist/cflare.interfaces.d.ts @@ -0,0 +1,56 @@ +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; +} diff --git a/dist/cflare.interfaces.js b/dist/cflare.interfaces.js new file mode 100644 index 0000000..a352bcc --- /dev/null +++ b/dist/cflare.interfaces.js @@ -0,0 +1,2 @@ +"use strict"; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmludGVyZmFjZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUuaW50ZXJmYWNlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0= \ No newline at end of file diff --git a/dist/cflare.plugins.d.ts b/dist/cflare.plugins.d.ts index e33d5ca..3e6c3ec 100644 --- a/dist/cflare.plugins.d.ts +++ b/dist/cflare.plugins.d.ts @@ -1,5 +1,6 @@ import "typings-global"; export declare let beautylog: any; -export declare let q: any; +export import q = require("smartq"); export declare let request: any; export import smartstring = require("smartstring"); +export import smartdelay = require('smartdelay'); diff --git a/dist/cflare.plugins.js b/dist/cflare.plugins.js index be2266b..4bc989c 100644 --- a/dist/cflare.plugins.js +++ b/dist/cflare.plugins.js @@ -1,7 +1,8 @@ "use strict"; require("typings-global"); exports.beautylog = require("beautylog"); -exports.q = require("q"); +exports.q = require("smartq"); exports.request = require("request"); exports.smartstring = require("smartstring"); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ2IsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsU0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNqQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLG1CQUFXLFdBQVcsYUFBYSxDQUFDLENBQUMifQ== \ No newline at end of file +exports.smartdelay = require("smartdelay"); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUN6QixRQUFBLE9BQU8sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDeEMsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9 \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 705e3b2..17ae176 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,4 +2,4 @@ require("typings-global"); var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount"); exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLDZDQUE0QixnQ0FBZ0MsQ0FBQztBQUFyRCxxRUFBcUQifQ== \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLCtFQUE2RDtBQUFyRCx1REFBQSxhQUFhLENBQUEifQ== \ No newline at end of file diff --git a/package.json b/package.json index d780d90..faeb518 100644 --- a/package.json +++ b/package.json @@ -22,16 +22,17 @@ }, "homepage": "https://github.com/pushrocks/cflare#readme", "dependencies": { - "beautylog": "^5.0.18", - "q": "^1.4.1", - "request": "^2.74.0", - "smartstring": "^2.0.15", - "typings-global": "^1.0.6" + "beautylog": "^6.1.1", + "request": "^2.79.0", + "smartdelay": "^1.0.1", + "smartq": "^1.0.4", + "smartstring": "^2.0.22", + "typings-global": "^1.0.14" }, "devDependencies": { - "npmts-g": "^5.2.8", - "qenv": "^1.0.8", - "should": "^10.0.0", - "typings-test": "^1.0.1" + "npmts-g": "^6.0.0", + "qenv": "^1.1.3", + "should": "^11.1.2", + "typings-test": "^1.0.3" } } diff --git a/test/test.js b/test/test.js index 1c399ef..6691585 100644 --- a/test/test.js +++ b/test/test.js @@ -14,27 +14,25 @@ describe("cflare", function () { describe(".CflareAccount", function () { describe(".listZones()", function () { it("should display an entire account", function (done) { - this.timeout(10000); + this.timeout(30000); testCflareAccount.listZones() .then((responseArg) => { - console.log(responseArg); done(); }); }); }); describe(".getZoneId(domainName)", function () { it("should get an Cloudflare Id for a domain string", function (done) { - this.timeout(10000); + this.timeout(30000); testCflareAccount.getZoneId("bleu.de") .then((responseArg) => { - console.log(responseArg); done(); }); }); }); describe(".listRecords(domainName)", function () { it("should list all records for a specific Domain Name", function (done) { - this.timeout(10000); + this.timeout(30000); testCflareAccount.listRecords("bleu.de") .then((responseArg) => { console.log(responseArg); @@ -43,24 +41,24 @@ describe("cflare", function () { }); }); describe(".createRecord", function () { - this.timeout(10000); 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) { - console.log(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) { - console.log(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); @@ -70,6 +68,7 @@ describe("cflare", function () { }); 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); @@ -77,7 +76,7 @@ describe("cflare", function () { }); }); it("should remove a subdomain record from Cloudflare", function (done) { - this.timeout(5000); + this.timeout(30000); testCflareAccount.removeRecord("subdomain.bleu.de", "A") .then(function (responseArg) { console.log(responseArg); @@ -87,4 +86,4 @@ describe("cflare", function () { }); }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5nc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EVBQUUsQ0FBQztnQkFDWCxDQUFDLENBQUMsQ0FBQztZQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ1AsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0= \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index f63e143..5cf4f11 100644 --- a/test/test.ts +++ b/test/test.ts @@ -14,27 +14,25 @@ describe("cflare",function(){ describe(".CflareAccount",function(){ describe(".listZones()",function(){ it("should display an entire account",function(done){ - this.timeout(10000); + this.timeout(30000); testCflareAccount.listZones() .then((responseArg)=>{ - console.log(responseArg); done(); }) }); }); describe(".getZoneId(domainName)",function(){ it("should get an Cloudflare Id for a domain string",function(done){ - this.timeout(10000) + this.timeout(30000) testCflareAccount.getZoneId("bleu.de") .then((responseArg)=>{ - console.log(responseArg); done(); }); }); }); describe(".listRecords(domainName)",function(){ it("should list all records for a specific Domain Name",function(done){ - this.timeout(10000); + this.timeout(30000); testCflareAccount.listRecords("bleu.de") .then((responseArg) => { console.log(responseArg); @@ -43,24 +41,24 @@ describe("cflare",function(){ }); }) describe(".createRecord",function(){ - this.timeout(10000); 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){ - console.log(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){ - console.log(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); @@ -70,6 +68,7 @@ describe("cflare",function(){ }); 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); @@ -77,7 +76,7 @@ describe("cflare",function(){ }); }); it("should remove a subdomain record from Cloudflare",function(done){ - this.timeout(5000); + this.timeout(30000); testCflareAccount.removeRecord("subdomain.bleu.de","A") .then(function(responseArg){ console.log(responseArg); diff --git a/ts/cflare.classes.cflareaccount.ts b/ts/cflare.classes.cflareaccount.ts index 2647b5f..2027a95 100644 --- a/ts/cflare.classes.cflareaccount.ts +++ b/ts/cflare.classes.cflareaccount.ts @@ -1,73 +1,76 @@ 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(){ + private authEmail: string; + private authKey: string; + private authCheck() { return (this.authEmail && this.authKey); //check if auth is available } - constructor(){ - + constructor() { + }; - auth(optionsArg:{email:string,key:string}){ + auth(optionsArg: { email: string, key: string }) { this.authEmail = optionsArg.email; - this.authKey = optionsArg.key; + this.authKey = optionsArg.key; } - getZoneId(domainName:string){ + getZoneId(domainName: string) { let done = plugins.q.defer(); this.listZones(domainName) - .then((responseArg) => { - let filteredResponse = responseArg.result.filter((zoneArg)=>{ + .then(zoneArrayArg => { + let filteredResponse = zoneArrayArg.filter((zoneArg) => { return zoneArg.name === domainName; }); - if (filteredResponse.length >= 1){ + if (filteredResponse.length >= 1) { done.resolve(filteredResponse[0].id); } else { - plugins.beautylog.error("the domain " + domainName.blue + " does not appear to be in this account!"); + 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){ + getRecord(domainNameArg: string, typeArg: string): Promise { let done = plugins.q.defer(); + let result: interfaces.ICflareRecord + let domain = new plugins.smartstring.Domain(domainNameArg); this.listRecords(domain.zoneName) - .then((responseArg) => { - let filteredResponse = responseArg.result.filter((recordArg) => { - return (recordArg.type == typeArg && recordArg.name == domainNameArg); + .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){ + 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)=>{ + .then((domainIdArg) => { let dataObject = { name: domain.fullName, type: typeArg, content: contentArg }; - this.request("POST","/zones/" + domainIdArg + "/dns_records",dataObject) - .then(function(responseArg){ + this.request("POST", "/zones/" + domainIdArg + "/dns_records", dataObject) + .then(function (responseArg) { done.resolve(responseArg); }); }); return done.promise; }; - removeRecord(domainNameArg:string,typeArg:string){ + removeRecord(domainNameArg: string, typeArg: string) { let done = plugins.q.defer(); let domain = new plugins.smartstring.Domain(domainNameArg); - this.getRecord(domain.fullName,typeArg) + this.getRecord(domain.fullName, typeArg) .then((responseArg) => { - if(responseArg){ - let requestRoute:string = "/zones/" + responseArg.zone_id + "/dns_records/" + responseArg.id; - this.request("DELETE",requestRoute) + if (responseArg) { + let requestRoute: string = "/zones/" + responseArg.zone_id + "/dns_records/" + responseArg.id; + this.request("DELETE", requestRoute) .then((responseArg) => { done.resolve(responseArg); }); @@ -77,59 +80,88 @@ export class CflareAccount { }); return done.promise; }; - updateRecord(domainNameArg:string,typeArg:string,valueArg){ + updateRecord(domainNameArg: string, typeArg: string, valueArg) { let done = plugins.q.defer(); let domain = new plugins.smartstring.Domain(domainNameArg); return done.promise; }; - listRecords(domainNameArg:string){ - let done = plugins.q.defer(); + listRecords(domainNameArg: string): Promise { + let done = plugins.q.defer(); + 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){ - done.resolve(responseArg); + .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){ // TODO: handle pagination - let done = plugins.q.defer(); + 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) - .then(function(responseArg){ - result = responseArg; + 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 = {}){ + request(methodArg: string, routeArg: string, dataArg = {}) { let done = plugins.q.defer(); - let jsonArg:string = JSON.stringify(dataArg); + let jsonArg: string = 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 + 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 }, - body:jsonArg + body: jsonArg }; //console.log(options); - plugins.request(options,function(err, res, body){ - if (!err && res.statusCode == 200) { - var responseObj = JSON.parse(body); - done.resolve(responseObj); - } else { - console.log(err); - console.log(res); - done.reject(err); - }; - }); + 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 = async (delayTimeArg = 15000) => { + console.log(`retry started and waiting for ${delayTimeArg} ms`) + await plugins.smartdelay.delayFor(delayTimeArg) + if (retryCount < 3) { + retryCount++ + makeRequest() + return + } + } + makeRequest() return done.promise; } }; \ No newline at end of file diff --git a/ts/cflare.interfaces.ts b/ts/cflare.interfaces.ts new file mode 100644 index 0000000..47e5df4 --- /dev/null +++ b/ts/cflare.interfaces.ts @@ -0,0 +1,59 @@ +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 +} \ No newline at end of file diff --git a/ts/cflare.plugins.ts b/ts/cflare.plugins.ts index 1347ac4..8ac0822 100644 --- a/ts/cflare.plugins.ts +++ b/ts/cflare.plugins.ts @@ -1,5 +1,6 @@ import "typings-global"; export let beautylog = require("beautylog"); -export let q = require("q"); +export import q = require("smartq"); export let request = require("request"); -export import smartstring = require("smartstring"); \ No newline at end of file +export import smartstring = require("smartstring"); +export import smartdelay = require('smartdelay'); \ No newline at end of file