Compare commits

..

46 Commits

Author SHA1 Message Date
a050271574 0.0.19 2017-02-12 21:24:58 +01:00
d54884ded7 update README 2017-02-12 21:18:32 +01:00
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
c76643d700 0.0.10 2016-07-31 23:55:25 +02:00
de088ba550 update dependencies 2016-07-31 23:54:13 +02:00
1ecf660368 0.0.9 2016-06-22 13:30:02 +02:00
a04ce339f2 0.0.8 2016-06-22 13:29:58 +02:00
feed201dc1 0.0.7 2016-06-22 13:01:38 +02:00
cb73164c8f updated dependencies 2016-06-22 13:01:28 +02:00
4758f31132 0.0.6 2016-06-21 19:11:48 +02:00
5a0ab5080d fix stages 2016-06-21 19:11:45 +02:00
26bb194814 0.0.5 2016-06-21 19:08:37 +02:00
4a656cf7f1 fix stages 2016-06-21 19:08:31 +02:00
9a35e69ab6 0.0.4 2016-06-21 19:04:46 +02:00
757a9acd09 now works for most things 2016-06-21 19:04:43 +02:00
9cb3c1508e update to latest dependencies 2016-06-20 22:56:09 +02:00
d25033b84b update .gitlab.yml 2016-06-19 20:09:41 +02:00
941611b7fb update 2016-06-18 15:36:15 +02:00
441d66d6f6 add .gitlab-ci.yml 2016-05-30 06:09:13 +02:00
ba2d6f4237 0.0.3 2016-05-25 07:17:50 +02:00
ff71de8f6c improve domain string handling 2016-05-25 07:06:06 +02:00
e99d597c12 update .getRecord 2016-05-25 06:32:56 +02:00
f44698078e improve .createRecord 2016-05-25 06:26:48 +02:00
0ed9c7f4f4 implemented .createRecord 2016-05-24 23:36:06 +02:00
f4d4bc238b compile 2016-05-16 03:44:02 +02:00
f4c2bb6e5b add functionality 2016-05-16 03:29:29 +02:00
b2182ec63d start with tests 2016-05-15 19:51:48 +02:00
6cc91c0a5e improved request method of cflare class 2016-04-27 06:01:50 +02:00
69ef50f69c 0.0.2 2016-04-27 03:08:23 +02:00
71dcdd0d66 now returning promises 2016-04-27 03:08:14 +02:00
229b652c69 add lossless badge 2016-04-27 02:27:52 +02:00
28 changed files with 773 additions and 73 deletions

7
.gitignore vendored
View File

@ -1,7 +1,6 @@
coverage/ coverage/
docs/ docs/
ts/typings/
ts/**/*.js
ts/**/*.js.map
.idea/
node_modules/ node_modules/
.nogit/
nogit/

59
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,59 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- trigger
- pages
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- 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,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Push.Rocks Copyright (c) 2016 Lossless GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,25 +1,51 @@
# cflare # cflare
allows you to manage cloudflare from CoreOS 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://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/cflare)
[![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/cflare)
[![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/cflare)
[![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/cflare/)
## Status ## Status for master
[![build status](https://GitLab.com/mojoio/cflare/badges/master/build.svg)](https://GitLab.com/mojoio/cflare/commits/master)
[![coverage report](https://GitLab.com/mojoio/cflare/badges/master/coverage.svg)](https://GitLab.com/mojoio/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/mojoio/cflare.svg)](https://david-dm.org/mojoio/cflare)
[![bitHound Dependencies](https://www.bithound.io/github/mojoio/cflare/badges/dependencies.svg)](https://www.bithound.io/github/mojoio/cflare/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/mojoio/cflare/badges/code.svg)](https://www.bithound.io/github/mojoio/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();
cflareInstance.removeRecord();
cflareInstance.copyRecord();
cflareInstance.listRecords();
cflareInstance.listDomains();
``` ```
For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

20
dist/cflare.classes.cflareaccount.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
import 'typings-global';
import * as interfaces from './cflare.interfaces';
export declare class CflareAccount {
private authEmail;
private authKey;
constructor();
auth(optionsArg: {
email: string;
key: string;
}): void;
getZoneId(domainName: string): Promise<{}>;
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord>;
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<interfaces.ICflareRecord[]>;
listZones(domainName?: string): Promise<interfaces.ICflareZone[]>;
request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{}>;
private authCheck();
}

168
dist/cflare.classes.cflareaccount.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/cflare.classes.helpers.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import "typings-global";

View File

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

View File

@ -1,10 +0,0 @@
"use strict";
var cflare = (function () {
function cflare() {
}
;
return cflare;
}());
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5jbGFzc2VzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFJQTtJQUdJO0lBRUEsQ0FBQzs7SUFFTCxhQUFDO0FBQUQsQ0FQQSxBQU9DLElBQUE7QUFBQSxDQUFDIiwiZmlsZSI6ImNmbGFyZS5jbGFzc2VzLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLy8vIDxyZWZlcmVuY2UgcGF0aD1cIi4vdHlwaW5ncy9tYWluLmQudHNcIiAvPlxuaW1wb3J0IHBsdWdpbnMgPSByZXF1aXJlKFwiLi9jZmxhcmUucGx1Z2luc1wiKTtcbmltcG9ydCBoZWxwZXJzID0gcmVxdWlyZShcIi4vY2ZsYXJlLmNsYXNzZXMuaGVscGVyc1wiKTtcblxuY2xhc3MgY2ZsYXJlIHtcbiAgICBwcml2YXRlIGF1dGhFbWFpbDpzdHJpbmc7XG4gICAgcHJpdmF0ZSBhdXRoS2V5OnN0cmluZztcbiAgICBjb25zdHJ1Y3Rvcigpe1xuICAgICAgICBcbiAgICB9O1xuICAgIFxufTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

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=

6
dist/cflare.plugins.d.ts vendored Normal file
View File

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

View File

@ -1,6 +1,8 @@
"use strict"; "use strict";
/// <reference path="./typings/main.d.ts" /> require("typings-global");
exports.beautylog = require("beautylog"); exports.beautylog = require("beautylog");
exports.request = require("request"); exports.q = require("smartq");
exports.smartrequest = require("smartrequest");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNmbGFyZS5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw0Q0FBNEM7QUFDakMsaUJBQVMsR0FBRyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7QUFDakMsZUFBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsQ0FBQyIsImZpbGUiOiJjZmxhcmUucGx1Z2lucy5qcyIsInNvdXJjZXNDb250ZW50IjpbIi8vLyA8cmVmZXJlbmNlIHBhdGg9XCIuL3R5cGluZ3MvbWFpbi5kLnRzXCIgLz5cbmV4cG9ydCBsZXQgYmVhdXR5bG9nID0gcmVxdWlyZShcImJlYXV0eWxvZ1wiKTtcbmV4cG9ydCBsZXQgcmVxdWVzdCA9IHJlcXVpcmUoXCJyZXF1ZXN0XCIpOyJdLCJzb3VyY2VSb290IjoiL3NvdXJjZS8ifQ== exports.smartstring = require("smartstring");
exports.smartdelay = require("smartdelay");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ2IsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0FBQzVDLDhCQUFvQztBQUNwQywrQ0FBcUQ7QUFDckQsNkNBQW1EO0FBQ25ELDJDQUFpRCJ9

2
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
import "typings-global";
export { CflareAccount } from "./cflare.classes.cflareaccount";

6
dist/index.js vendored
View File

@ -1,3 +1,5 @@
"use strict"; "use strict";
require("typings-global");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0= var cflare_classes_cflareaccount_1 = require("./cflare.classes.cflareaccount");
exports.CflareAccount = cflare_classes_cflareaccount_1.CflareAccount;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXdCO0FBQ3hCLCtFQUE2RDtBQUFyRCx1REFBQSxhQUFhLENBQUEifQ==

View File

@ -1,30 +1,38 @@
{ {
"name": "cflare", "name": "cflare",
"version": "0.0.1", "version": "0.0.19",
"description": "cloudflare management for CoreOS", "description": "easy cloudflare management",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(npmts)"
}, },
"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": "^4.1.2", "beautylog": "^6.1.1",
"request": "^2.72.0" "smartdelay": "^1.0.1",
"smartq": "^1.1.0",
"smartrequest": "^1.0.4",
"smartstring": "^2.0.22",
"typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"npmts": "^5.0.4" "npmts-g": "^6.0.0",
"qenv": "^1.1.3",
"smartchai": "^1.0.1",
"typings-test": "^1.0.3"
} }
} }

3
qenv.yml Normal file
View File

@ -0,0 +1,3 @@
vars:
- CF_EMAIL
- CF_KEY

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

74
test/test.js Normal file
View File

@ -0,0 +1,74 @@
"use strict";
require("typings-test");
const cflare = require("../dist/index");
const qenv_1 = require("qenv");
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
});
let randomPrefix = Math.floor(Math.random() * 2000);
describe('cflare', function () {
describe('.CflareAccount', function () {
describe('.listZones()', function () {
it('should display an entire account', function (done) {
this.timeout(600000);
testCflareAccount.listZones()
.then((responseArg) => {
done();
});
});
});
describe('.getZoneId(domainName)', function () {
it('should get an Cloudflare Id for a domain string', function (done) {
this.timeout(600000);
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) => {
console.log(responseArg);
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();
});
});
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzd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.ts Normal file
View File

@ -0,0 +1,75 @@
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
})
let randomPrefix = Math.floor(Math.random() * 2000)
describe('cflare', function () {
describe('.CflareAccount', function () {
describe('.listZones()', function () {
it('should display an entire account', function (done) {
this.timeout(600000)
testCflareAccount.listZones()
.then((responseArg) => {
done()
})
})
})
describe('.getZoneId(domainName)', function () {
it('should get an Cloudflare Id for a domain string', function (done) {
this.timeout(600000)
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) => {
console.log(responseArg)
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()
})
})
})
})
})

View File

@ -0,0 +1,161 @@
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
constructor() {
}
auth(optionsArg: { email: string, key: string }) {
this.authEmail = optionsArg.email
this.authKey = optionsArg.key
}
getZoneId(domainName: string) {
let done = plugins.q.defer()
this.listZones(domainName)
.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} does not appear to be in this account!`)
done.reject(undefined)
}
})
return done.promise
}
getRecord(domainNameArg: string, typeArg: string): Promise<interfaces.ICflareRecord> {
let done = plugins.q.defer()
let result: interfaces.ICflareRecord
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)
})
done.resolve(filteredResponse[ 0 ])
})
return done.promise
};
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) => {
let dataObject = {
name: domain.fullName,
type: typeArg,
content: contentArg
}
this.request('POST', '/zones/' + domainIdArg + '/dns_records', dataObject)
.then(function (responseArg) {
done.resolve(responseArg)
})
})
return done.promise
};
removeRecord(domainNameArg: string, typeArg: string) {
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)
.then((responseArg) => {
done.resolve(responseArg)
})
} else {
done.reject()
}
})
return done.promise
};
updateRecord(domainNameArg: string, typeArg: string, valueArg) {
let done = plugins.q.defer()
let domain = new plugins.smartstring.Domain(domainNameArg)
return done.promise
};
listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
let done = plugins.q.defer<interfaces.ICflareRecord[]>()
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: any) {
result = responseArg.result
done.resolve(result)
})
})
return done.promise
}
listZones(domainName?: string): Promise<interfaces.ICflareZone[]> { // TODO: handle pagination
let done = plugins.q.defer<interfaces.ICflareZone[]>()
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
};
request(methodArg: string, routeArg: string, dataArg = {}) {
let done = plugins.q.defer()
let jsonArg: 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
},
requestBody: jsonArg
}
// console.log(options);
let retryCount = 0
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 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
}
}

View File

@ -1,2 +1,2 @@
/// <reference path="./typings/main.d.ts" /> import "typings-global";
import plugins = require("./cflare.plugins"); import plugins = require("./cflare.plugins");

View File

@ -1,12 +0,0 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./cflare.plugins");
import helpers = require("./cflare.classes.helpers");
class cflare {
private authEmail:string;
private authKey:string;
constructor(){
};
};

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,3 +1,6 @@
/// <reference path="./typings/main.d.ts" /> import "typings-global";
export let beautylog = require("beautylog"); export let beautylog = require("beautylog");
export let request = require("request"); export import q = require("smartq");
export import smartrequest = require("smartrequest");
export import smartstring = require("smartstring");
export import smartdelay = require('smartdelay');

View File

@ -1,2 +1,2 @@
/// <reference path="./typings/main.d.ts" /> import "typings-global";
import plugins = require("./cflare.plugins"); export {CflareAccount} from "./cflare.classes.cflareaccount";

View File

@ -1,8 +0,0 @@
{
"version": false,
"dependencies": {},
"ambientDependencies": {
"colors": "registry:dt/colors#0.6.0-1+20160425153322",
"node": "registry:dt/node#4.0.0+20160423143914"
}
}

3
tslint.json Normal file
View File

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