Compare commits

..

16 Commits

Author SHA1 Message Date
30f7fa9c8a 0.0.18 2017-01-29 18:22:20 +01:00
6bc7edceb9 update README 2017-01-29 18:22:17 +01:00
2ee94dd179 0.0.17 2017-01-29 18:05:42 +01:00
a4a006e490 fix tests to run in parallel 2017-01-29 18:05:39 +01:00
98d5127846 0.0.16 2017-01-29 17:52:28 +01:00
f63d8abfc6 fixed bad request retry 2017-01-29 17:51:53 +01:00
266f84f33a 0.0.15 2017-01-29 17:45:54 +01:00
6400e0f038 fix testing timeouts 2017-01-29 17:45:48 +01:00
b4838566ac 0.0.14 2017-01-29 17:42:22 +01:00
803f1ce41a added random retry times 2017-01-29 17:42:15 +01:00
8a8adb48c6 0.0.13 2017-01-29 17:29:13 +01:00
078731fe7b update to new ci 2017-01-29 17:29:06 +01:00
bf15b8aec7 0.0.12 2017-01-29 17:27:52 +01:00
55b305ca1c now using smartrequest 2017-01-29 17:27:48 +01:00
9699e4bf76 0.0.11 2017-01-22 19:37:04 +01:00
0692d16dd7 now reacting to rate limiting 2017-01-22 19:37:00 +01:00
18 changed files with 526 additions and 350 deletions

View File

@ -1,35 +1,30 @@
image: hosttoday/ht-docker-node:npmts image: hosttoday/ht-docker-node:npmts
stages: stages:
- test1 - test
- test2
- test3
- release - release
- trigger
- pages
testLEGACY: testLEGACY:
stage: test1 stage: test
script: script:
- npmci test legacy - npmci test legacy
only:
- tags
tags: tags:
- docker - docker
allow_failure: true
testLTS: testLTS:
stage: test2 stage: test
script: script:
- npmci test lts - npmci test lts
only:
- tags
tags: tags:
- docker - docker
testSTABLE: testSTABLE:
stage: test3 stage: test
script: script:
- npmci test stable - npmci test stable
only:
- tags
tags: tags:
- docker - docker
@ -41,3 +36,24 @@ release:
- tags - tags
tags: tags:
- docker - docker
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
script:
- npmci command npmpage --publish gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

View File

@ -1,31 +1,47 @@
# cflare # cflare
allows you to manage multiple cloudflare accounts. easy cloudflare management
> Note: this package is still in alpha, so some things do not yet work. ## Availabililty
I (Phil from Lossless) expect this package to be ready 1. of June 2016. [![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/cflare)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/cflare)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/cflare)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/cflare/)
## Status ## Status for master
[![Build Status](https://travis-ci.org/pushrocks/cflare.svg?branch=master)](https://travis-ci.org/pushrocks/cflare) [![build status](https://GitLab.com/pushrocks/cflare/badges/master/build.svg)](https://GitLab.com/pushrocks/cflare/commits/master)
[![coverage report](https://GitLab.com/pushrocks/cflare/badges/master/coverage.svg)](https://GitLab.com/pushrocks/cflare/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/cflare.svg)](https://www.npmjs.com/package/cflare)
[![Dependency Status](https://david-dm.org/pushrocks/cflare.svg)](https://david-dm.org/pushrocks/cflare)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/cflare/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/cflare/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/cflare/badges/code.svg)](https://www.bithound.io/github/pushrocks/cflare)
[![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
Use TypeScript for best in class instellisense.
```javascript ```javascript
var cflare = require("cflare"); import * as cflare from 'cflare'
var cflareInstance = new cflare();
cflareInstance.auth({ let myCflareAccount = new cflare.CflareAccount()
email:"", testCflareAccount.auth({
key:"" email: 'someuser@example.com',
}); key: 'someLongApiKey'
})
let myAsyncCflareManagement = async () => {
// get things
let myZones = await myCflareAccount.listZones() // zones are fully typed
let myIdForADomain = await myCflareAccount.getZoneId('example.com') // type number
let myRecordsForADomain = await myCflareAccount.listRecords('example.com') // records are fully typed
// set things
myCflareAccount.updateRecord(...)
myCflareAccount.createRecord(...)
myCflareAccount.deleteRecord(...)
}
cflareInstance.createRecord(); // returns promise with resolve function getting the response;
cflareInstance.removeRecord(); // returns promise with resolve function getting the response;
cflareInstance.copyRecord(); // returns promise with resolve function getting the response;
cflareInstance.listRecords(); // returns promise with resolve function getting the response;
cflareInstance.listDomains(); // returns promise with resolve function getting the response;
``` ```
### About the authors: [![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
[![Project Phase](https://mediaserve.lossless.digital/lossless.com/img/createdby_github.svg)](https://lossless.com/)
[![Gitter](https://img.shields.io/badge/Support%20us-PayPal-blue.svg)](https://paypal.me/lossless)

View File

@ -1,19 +1,20 @@
import "typings-global"; import 'typings-global';
import * as interfaces from './cflare.interfaces';
export declare class CflareAccount { export declare class CflareAccount {
private authEmail; private authEmail;
private authKey; private authKey;
private authCheck();
constructor(); constructor();
auth(optionsArg: { auth(optionsArg: {
email: string; email: string;
key: string; key: string;
}): void; }): void;
getZoneId(domainName: string): any; getZoneId(domainName: string): Promise<{}>;
getRecord(domainNameArg: string, typeArg: string): any; getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord>;
createRecord(domainNameArg: string, typeArg: string, contentArg: string): any; createRecord(domainNameArg: string, typeArg: string, contentArg: string): Promise<{}>;
removeRecord(domainNameArg: string, typeArg: string): any; removeRecord(domainNameArg: string, typeArg: string): Promise<{}>;
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): any; updateRecord(domainNameArg: string, typeArg: string, valueArg: any): Promise<{}>;
listRecords(domainNameArg: string): any; listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]>;
listZones(domainName?: string): any; listZones(domainName?: string): Promise<interfaces.ICflareZone[]>;
request(methodArg: string, routeArg: string, dataArg?: {}): any; request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>;
private authCheck();
} }

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSJ9 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF3QiJ9

56
dist/cflare.interfaces.d.ts vendored Normal file
View File

@ -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;
}

2
dist/cflare.interfaces.js vendored Normal file
View File

@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmludGVyZmFjZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUuaW50ZXJmYWNlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=

View File

@ -1,5 +1,6 @@
import "typings-global"; import "typings-global";
export declare let beautylog: any; export declare let beautylog: any;
export declare let q: any; export import q = require("smartq");
export declare let request: any; export import smartrequest = require("smartrequest");
export import smartstring = require("smartstring"); export import smartstring = require("smartstring");
export import smartdelay = require('smartdelay');

View File

@ -1,7 +1,8 @@
"use strict"; "use strict";
require("typings-global"); require("typings-global");
exports.beautylog = require("beautylog"); exports.beautylog = require("beautylog");
exports.q = require("q"); exports.q = require("smartq");
exports.request = require("request"); exports.smartrequest = require("smartrequest");
exports.smartstring = require("smartstring"); exports.smartstring = require("smartstring");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ2IsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsU0FBQyxHQUFHLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNqQixlQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDO0FBQzFCLG1CQUFXLFdBQVcsYUFBYSxDQUFDLENBQUMifQ== exports.smartdelay = require("smartdelay");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUNwQywrQ0FBcUQ7QUFDckQsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9

2
dist/index.js vendored
View File

@ -2,4 +2,4 @@
require("typings-global"); require("typings-global");
var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount"); var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount; exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLDZDQUE0QixnQ0FBZ0MsQ0FBQztBQUFyRCxxRUFBcUQifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLCtFQUE2RDtBQUFyRCx1REFBQSxhQUFhLENBQUEifQ==

View File

@ -1,7 +1,7 @@
{ {
"name": "cflare", "name": "cflare",
"version": "0.0.10", "version": "0.0.18",
"description": "cloudflare management for CoreOS", "description": "easy cloudflare management",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"scripts": { "scripts": {
@ -9,29 +9,30 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/pushrocks/cflare.git" "url": "git+https://gitlab.com/pushrocks/cflare.git"
}, },
"keywords": [ "keywords": [
"CoreOS", "Push.Rocks",
"cloudflare" "cloudflare"
], ],
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/pushrocks/cflare/issues" "url": "https://gitlab.com/pushrocks/cflare/issues"
}, },
"homepage": "https://github.com/pushrocks/cflare#readme", "homepage": "https://gitlab.com/pushrocks/cflare#readme",
"dependencies": { "dependencies": {
"beautylog": "^5.0.18", "beautylog": "^6.1.1",
"q": "^1.4.1", "smartdelay": "^1.0.1",
"request": "^2.74.0", "smartq": "^1.1.0",
"smartstring": "^2.0.15", "smartrequest": "^1.0.4",
"typings-global": "^1.0.6" "smartstring": "^2.0.22",
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"npmts-g": "^5.2.8", "npmts-g": "^6.0.0",
"qenv": "^1.0.8", "qenv": "^1.1.3",
"should": "^10.0.0", "smartchai": "^1.0.1",
"typings-test": "^1.0.1" "typings-test": "^1.0.3"
} }
} }

2
test/test.d.ts vendored
View File

@ -1 +1 @@
import "typings-test"; import 'typings-test';

View File

@ -1,84 +1,68 @@
"use strict"; "use strict";
require("typings-test"); require("typings-test");
const cflare = require("../dist/index"); const cflare = require("../dist/index");
let should = require("should");
const qenv_1 = require("qenv"); 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); console.log(testQenv.missingEnvVars);
let testCflareAccount = new cflare.CflareAccount(); let testCflareAccount = new cflare.CflareAccount();
testCflareAccount.auth({ testCflareAccount.auth({
email: process.env.CF_EMAIL, email: process.env.CF_EMAIL,
key: process.env.CF_KEY key: process.env.CF_KEY
}); });
describe("cflare", function () { let randomPrefix = Math.floor(Math.random() * 2000);
describe(".CflareAccount", function () { describe('cflare', function () {
describe(".listZones()", function () { describe('.CflareAccount', function () {
it("should display an entire account", function (done) { describe('.listZones()', function () {
this.timeout(10000); it('should display an entire account', function (done) {
this.timeout(600000);
testCflareAccount.listZones() testCflareAccount.listZones()
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg);
done(); done();
}); });
}); });
}); });
describe(".getZoneId(domainName)", function () { describe('.getZoneId(domainName)', function () {
it("should get an Cloudflare Id for a domain string", function (done) { it('should get an Cloudflare Id for a domain string', function (done) {
this.timeout(10000); this.timeout(600000);
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) {
this.timeout(600000);
testCflareAccount.listRecords('bleu.de')
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg); console.log(responseArg);
done(); done();
}); });
}); });
}); });
describe(".listRecords(domainName)", function () { describe('.createRecord', function () {
it("should list all records for a specific Domain Name", function (done) { it('should create a valid record for a subdomain', function (done) {
this.timeout(10000); this.timeout(600000);
testCflareAccount.listRecords("bleu.de") testCflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1')
.then((responseArg) => {
console.log(responseArg);
done();
});
});
});
describe(".createRecord", function () {
this.timeout(10000);
it("should create a valid record for a level 2 domain", function (done) {
testCflareAccount.createRecord("bleu.de", "A", "127.0.0.1")
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg);
done(); done();
}); });
}); });
it("should create a valid record for a subdomain", function (done) { });
testCflareAccount.createRecord("subdomain.bleu.de", "A", "127.0.0.1") describe('.getRecord', function () {
it('should get a record from Cloudflare', function (done) {
this.timeout(600000);
testCflareAccount.getRecord('bleu.de', 'A')
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg); console.log(responseArg);
done(); done();
}); });
}); });
}); });
describe(".getRecord", function () { describe('.removeRecord', function () {
it("should get a record from Cloudflare", function (done) { it('should remove a subdomain record from Cloudflare', function (done) {
testCflareAccount.getRecord("bleu.de", "A") this.timeout(600000);
.then(function (responseArg) { testCflareAccount.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
console.log(responseArg);
done();
});
});
});
describe(".removeRecord", function () {
it("should remove a record from Cloudflare", function (done) {
testCflareAccount.removeRecord("bleu.de", "A")
.then(function (responseArg) {
console.log(responseArg);
done();
});
});
it("should remove a subdomain record from Cloudflare", function (done) {
this.timeout(5000);
testCflareAccount.removeRecord("subdomain.bleu.de", "A")
.then(function (responseArg) { .then(function (responseArg) {
console.log(responseArg); console.log(responseArg);
done(); done();
@ -87,4 +71,4 @@ describe("cflare", function () {
}); });
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxNQUFNLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDekMsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFDO0FBQy9CLHVCQUFtQixNQUFNLENBQUMsQ0FBQTtBQUMxQixJQUFJLFFBQVEsR0FBRyxJQUFJLFdBQUksQ0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLEVBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxHQUFHLFNBQVMsQ0FBQyxDQUFDO0FBQ2pFLE9BQU8sQ0FBQyxHQUFHLENBQUMsUUFBUSxDQUFDLGNBQWMsQ0FBQyxDQUFDO0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QUFVLFdBQVc7b0JBQ3ZCLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUE7b0JBQ3hCLElBQUksRUFBRSxDQUFBO2dCQUNWLENBQUMsQ0FBQyxDQUFBO1lBQ1YsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -1,89 +1,75 @@
import "typings-test"; import 'typings-test'
import cflare = require("../dist/index"); import cflare = require('../dist/index')
let should = require("should"); import { expect } from 'smartchai'
import {Qenv} from "qenv"; import { Qenv } from 'qenv'
let testQenv = new Qenv(process.cwd(),process.cwd() + "/.nogit"); let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit')
console.log(testQenv.missingEnvVars); console.log(testQenv.missingEnvVars)
let testCflareAccount = new cflare.CflareAccount(); let testCflareAccount = new cflare.CflareAccount()
testCflareAccount.auth({ testCflareAccount.auth({
email: process.env.CF_EMAIL, email: process.env.CF_EMAIL,
key: process.env.CF_KEY key: process.env.CF_KEY
}); })
describe("cflare",function(){ let randomPrefix = Math.floor(Math.random() * 2000)
describe(".CflareAccount",function(){
describe(".listZones()",function(){ describe('cflare', function () {
it("should display an entire account",function(done){ describe('.CflareAccount', function () {
this.timeout(10000); describe('.listZones()', function () {
it('should display an entire account', function (done) {
this.timeout(600000)
testCflareAccount.listZones() testCflareAccount.listZones()
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg); done()
done();
}) })
}); })
}); })
describe(".getZoneId(domainName)",function(){ describe('.getZoneId(domainName)', function () {
it("should get an Cloudflare Id for a domain string",function(done){ it('should get an Cloudflare Id for a domain string', function (done) {
this.timeout(10000) this.timeout(600000)
testCflareAccount.getZoneId("bleu.de") testCflareAccount.getZoneId('bleu.de')
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg); done()
done(); })
}); })
}); })
}); describe('.listRecords(domainName)', function () {
describe(".listRecords(domainName)",function(){ it('should list all records for a specific Domain Name', function (done) {
it("should list all records for a specific Domain Name",function(done){ this.timeout(600000)
this.timeout(10000); testCflareAccount.listRecords('bleu.de')
testCflareAccount.listRecords("bleu.de")
.then((responseArg) => { .then((responseArg) => {
console.log(responseArg); console.log(responseArg)
done(); done()
}); })
}); })
})
describe('.createRecord', function () {
it('should create a valid record for a subdomain', function (done) {
this.timeout(600000)
testCflareAccount.createRecord(`${randomPrefix}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(600000)
testCflareAccount.getRecord('bleu.de', 'A')
.then(function (responseArg) {
console.log(responseArg)
done()
})
})
})
describe('.removeRecord', function () {
it('should remove a subdomain record from Cloudflare', function (done) {
this.timeout(600000)
testCflareAccount.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.then(function (responseArg) {
console.log(responseArg)
done()
})
})
})
}) })
describe(".createRecord",function(){
this.timeout(10000);
it("should create a valid record for a level 2 domain",function(done){
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){
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){
testCflareAccount.getRecord("bleu.de","A")
.then(function(responseArg){
console.log(responseArg);
done();
});
});
});
describe(".removeRecord",function(){
it("should remove a record from Cloudflare",function(done){
testCflareAccount.removeRecord("bleu.de","A")
.then(function(responseArg){
console.log(responseArg);
done();
});
});
it("should remove a subdomain record from Cloudflare",function(done){
this.timeout(5000);
testCflareAccount.removeRecord("subdomain.bleu.de","A")
.then(function(responseArg){
console.log(responseArg);
done();
});
});
});
}) })
});

View File

@ -1,135 +1,161 @@
import "typings-global"; import 'typings-global';
import plugins = require("./cflare.plugins"); import plugins = require('./cflare.plugins')
import helpers = require("./cflare.classes.helpers"); import helpers = require('./cflare.classes.helpers')
import * as interfaces from './cflare.interfaces'
export class CflareAccount { export class CflareAccount {
private authEmail:string; private authEmail: string
private authKey: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.authEmail = optionsArg.email
this.authKey = optionsArg.key; this.authKey = optionsArg.key
} }
getZoneId(domainName: string) { getZoneId(domainName: string) {
let done = plugins.q.defer(); let done = plugins.q.defer()
this.listZones(domainName) this.listZones(domainName)
.then((responseArg) => { .then(zoneArrayArg => {
let filteredResponse = responseArg.result.filter((zoneArg)=>{ let filteredResponse = zoneArrayArg.filter((zoneArg) => {
return zoneArg.name === domainName; return zoneArg.name === domainName
}); })
if (filteredResponse.length >= 1) { if (filteredResponse.length >= 1) {
done.resolve(filteredResponse[0].id); done.resolve(filteredResponse[ 0 ].id)
} else { } 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); done.reject(undefined)
} }
}); })
return done.promise; return done.promise
} }
getRecord(domainNameArg:string,typeArg:string){ getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord> {
let done = plugins.q.defer(); let done = plugins.q.defer()
let domain = new plugins.smartstring.Domain(domainNameArg); let result: interfaces.ICflareRecord
let domain = new plugins.smartstring.Domain(domainNameArg)
this.listRecords(domain.zoneName) this.listRecords(domain.zoneName)
.then((responseArg) => { .then((recordArrayArg) => {
let filteredResponse = responseArg.result.filter((recordArg) => { 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) { createRecord(domainNameArg: string, typeArg: string, contentArg: string) {
let done = plugins.q.defer(); let done = plugins.q.defer()
let domain = new plugins.smartstring.Domain(domainNameArg); let domain = new plugins.smartstring.Domain(domainNameArg)
this.getZoneId(domain.zoneName) this.getZoneId(domain.zoneName)
.then((domainIdArg) => { .then((domainIdArg) => {
let dataObject = { let dataObject = {
name: domain.fullName, name: domain.fullName,
type: typeArg, type: typeArg,
content: contentArg content: contentArg
}; }
this.request("POST","/zones/" + domainIdArg + "/dns_records",dataObject) this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject)
.then(function (responseArg) { .then(function (responseArg) {
done.resolve(responseArg); done.resolve(responseArg)
}); })
}); })
return done.promise; return done.promise
}; };
removeRecord(domainNameArg: string, typeArg: string) { removeRecord(domainNameArg: string, typeArg: string) {
let done = plugins.q.defer(); let done = plugins.q.defer()
let domain = new plugins.smartstring.Domain(domainNameArg); let domain = new plugins.smartstring.Domain(domainNameArg)
this.getRecord(domain.fullName, typeArg) this.getRecord(domain.fullName, typeArg)
.then((responseArg) => { .then((responseArg) => {
if (responseArg) { if (responseArg) {
let requestRoute:string = "/zones/" + responseArg.zone_id + "/dns_records/" + responseArg.id; let requestRoute: string = '/zones/' + responseArg.zone_id + '/dns_records/' + responseArg.id
this.request("DELETE",requestRoute) this.request('DELETE', requestRoute)
.then((responseArg) => { .then((responseArg) => {
done.resolve(responseArg); done.resolve(responseArg)
}); })
} else { } else {
done.reject(); done.reject()
} }
}); })
return done.promise; return done.promise
}; };
updateRecord(domainNameArg: string, typeArg: string, valueArg) { updateRecord(domainNameArg: string, typeArg: string, valueArg) {
let done = plugins.q.defer(); let done = plugins.q.defer()
let domain = new plugins.smartstring.Domain(domainNameArg); let domain = new plugins.smartstring.Domain(domainNameArg)
return done.promise; return done.promise
}; };
listRecords(domainNameArg:string){ listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
let done = plugins.q.defer(); let done = plugins.q.defer<interfaces.ICflareRecord[]>()
let domain = new plugins.smartstring.Domain(domainNameArg); let result: interfaces.ICflareRecord[] = []
let domain = new plugins.smartstring.Domain(domainNameArg)
this.getZoneId(domain.zoneName) this.getZoneId(domain.zoneName)
.then((domainIdArg) => { .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){ .then(function (responseArg: any) {
done.resolve(responseArg); result = responseArg.result
}); done.resolve(result)
}); })
return done.promise; })
return done.promise
} }
listZones(domainName?:string){ // TODO: handle pagination listZones(domainName?: string): Promise<interfaces.ICflareZone[]> { // TODO: handle pagination
let done = plugins.q.defer(); let done = plugins.q.defer<interfaces.ICflareZone[]>()
let requestRoute = "/zones?per_page=50" let requestRoute = '/zones?per_page=50'
if(domainName) requestRoute = requestRoute + "&name=" + domainName; if (domainName) requestRoute = requestRoute + '&name=' + domainName
let result = {}; let result = []
this.request("GET",requestRoute) this.request('GET', requestRoute)
.then(function(responseArg){ .then((responseArg: any) => {
result = responseArg; result = responseArg.result
done.resolve(result); done.resolve(result)
}); })
return done.promise; return done.promise
}; };
request(methodArg: string, routeArg: string, dataArg = {}) { request(methodArg: string, routeArg: string, dataArg = {}) {
let done = plugins.q.defer(); let done = plugins.q.defer()
let jsonArg:string = JSON.stringify(dataArg); let jsonArg: string = JSON.stringify(dataArg)
let options = { let options: plugins.smartrequest.ISmartRequestOptions = {
method: methodArg, method: methodArg,
url:"https://api.cloudflare.com/client/v4" + routeArg,
headers: { headers: {
"Content-Type":"application/json", 'Content-Type': 'application/json',
"X-Auth-Email":this.authEmail, 'X-Auth-Email': this.authEmail,
"X-Auth-Key":this.authKey 'X-Auth-Key': this.authKey
}, },
body:jsonArg requestBody: jsonArg
}; }
//console.log(options); // console.log(options);
plugins.request(options,function(err, res, body){ let retryCount = 0
if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body); let makeRequest = async () => {
done.resolve(responseObj); let response: any = await plugins.smartrequest.request(
} else { `https://api.cloudflare.com/client/v4${routeArg}`,
console.log(err); options
console.log(res); )
done.reject(err); if (response.statusCode === 200) {
}; done.resolve(response.body)
}); } else if (response.statusCode === 429) {
return done.promise; console.log('rate limited! Waiting for retry!')
retryRequest()
} else if(response.statusCode === 400) {
console.log('bad request! Going to retry!')
} else {
console.log(response.statusCode)
done.reject(new Error('request failed'))
}
}
let retryRequest = async (delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)) => {
console.log(`retry started and waiting for ${delayTimeArg} ms`)
await plugins.smartdelay.delayFor(delayTimeArg)
if (retryCount < 10) {
retryCount++
return await makeRequest()
}
}
makeRequest()
return done.promise
}
private authCheck() {
return (this.authEmail && this.authKey) // check if auth is available
}
} }
};

59
ts/cflare.interfaces.ts Normal file
View File

@ -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
}

View File

@ -1,5 +1,6 @@
import "typings-global"; import "typings-global";
export let beautylog = require("beautylog"); export let beautylog = require("beautylog");
export let q = require("q"); export import q = require("smartq");
export let request = require("request"); export import smartrequest = require("smartrequest");
export import smartstring = require("smartstring"); export import smartstring = require("smartstring");
export import smartdelay = require('smartdelay');

3
tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}