Compare commits

...

42 Commits

Author SHA1 Message Date
f510408fce 3.0.2 2019-07-18 15:31:25 +02:00
e250e9b1a2 fix(core): update 2019-07-18 15:31:24 +02:00
5a9b7bbeee 3.0.1 2019-07-18 14:44:45 +02:00
1158b4ff99 fix(core): update 2019-07-18 14:44:45 +02:00
8eb777dd45 3.0.0 2019-07-18 14:25:40 +02:00
acf5c242d3 2.0.2 2019-07-18 14:25:10 +02:00
9e9dd8d935 fix(core): update 2019-07-18 14:25:10 +02:00
b7cc500f4d 2.0.1 2019-07-18 11:51:57 +02:00
8a4126a49c fix(core): update 2019-07-18 11:51:56 +02:00
b86391ca00 2.0.0 2018-08-14 01:53:52 +02:00
92682c1276 BREAKING CHANGE(scope): change scope, tools and package name 2018-08-14 01:53:52 +02:00
05677231f7 1.0.5 2017-06-11 21:07:45 +02:00
9c036925fd now using tsclass 2017-06-11 21:07:41 +02:00
d3d5f72193 1.0.4 2017-06-09 22:25:22 +02:00
3d7c0e6b64 update dependencies 2017-06-09 22:25:19 +02:00
4faefb0bd7 1.0.3 2017-06-05 19:14:29 +02:00
162fff134e now supports purging of assets 2017-06-05 19:14:26 +02:00
426237b2a7 improve test 2017-06-04 18:14:19 +02:00
b2d48d793a 1.0.2 2017-06-04 18:11:39 +02:00
54282bdc14 add npmextra.json 2017-06-04 18:11:37 +02:00
208fba0887 1.0.1 2017-06-04 18:09:49 +02:00
2f065b57fc add type TRecord, update ci 2017-06-04 18:09:46 +02:00
3503fbc7b3 1.0.0 2017-06-04 17:31:10 +02:00
1db3342353 0.0.20 2017-06-04 17:29:20 +02:00
03380b0d28 go async/await 2017-06-04 17:29:19 +02:00
4fe7ec8a66 update brand link 2017-02-12 22:28:26 +01:00
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
34 changed files with 2532 additions and 777 deletions

22
.gitignore vendored
View File

@ -1,6 +1,22 @@
.nogit/
# artifacts
coverage/
docs/
public/
pages/
# installs
node_modules/
.nogit/
nogit/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,43 +1,117 @@
image: hosttoday/ht-docker-node:npmts
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- test1
- test2
- test3
- security
- test
- release
- metadata
testLEGACY:
stage: test1
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci test legacy
only:
- tags
- npmci git mirror
tags:
- docker
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLTS:
stage: test2
stage: test
script:
- npmci test lts
only:
- tags
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testSTABLE:
stage: test3
- docker
- notpriv
testBuild:
stage: test
script:
- npmci test stable
only:
- tags
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
release:
stage: release
script:
- npmci publish
- npmci node install lts
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
script:
- npmci command npm install -g tslint typescript
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- docker
- notpriv
only:
- tags
tags:
- docker
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -1,12 +0,0 @@
language: node_js
node_js:
- '4'
- stable
deploy:
provider: npm
email: npm@lossless.digital
api_key:
secure: uWqO634z8xMWI8tcIpSvUeVeG4ypX5fppXWxrSKbO5zOHCHGqJK90XiGFfKUekMf0cYQPb5dLT5+J/3nd4mf4KtU3+v1OK6ZikEqn/PcSeqOmK7EnI9wDFZwDTgJWIn0lRwX2mfB9meblSZ7XthTXumX78fmRTyeyImLm9P0ak+CrNzs8rzKauBoqeVryOez4/LaH3f0kxSz7o7zYLxFqx5xjQ7TFqd1kkVTf4pSQanLHY3z+7+mKrkbcNVxx2gF76hyx6E4pntSJHrOEE/VU/KMk2B6yzrVWYUHUiSRGYOV9U17YaaWlC9DZmnS1cvYcqq3YNujTwPWtci3It9S98hLrSTnCCqin6xhj8IuV6U4WADiXOUvNKuTRcd0/leQ4w3xpPJ1FR2gRtEhwQ0NsnY0vL9tuRAW71lf31122TTJI8lJQNrnaeIGbX7eE0Pq0jeTpmM2W/Tl8pl6s6zBjlEC/mCynQq1pBiz7UmxMYCPE162I8V5USeZOBLzDPZV2y7hmPWjMrWTT+i/IpFmXHjQtVrwlyU6fCOeYHgK/5GdyhnrRYYlx+ce6pCn4tmkVxduimC3m1G8cTkPl00fIpy7KSVcaeQrc1N+KQUqK4FpIjeqB904SVPsI5v3P7sdobaT1aqFqszhR+JK5tXaoesew8R2RncjFK69J7DHJWk=
on:
tags: true
repo: pushrocks/cflare

View File

@ -1,31 +1,50 @@
# cflare
allows you to manage multiple cloudflare accounts.
# @mojoio/cloudflare
easy cloudflare management
> Note: this package is still in alpha, so some things do not yet work.
I (Phil from Lossless) expect this package to be ready 1. of June 2016.
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/cloudflare)
* [gitlab.com (source)](https://gitlab.com/mojoio/cloudflare)
* [github.com (source mirror)](https://github.com/mojoio/cloudflare)
* [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/)
## Status
[![Build Status](https://travis-ci.org/pushrocks/cflare.svg?branch=master)](https://travis-ci.org/pushrocks/cflare)
## Status for master
[![build status](https://gitlab.com/mojoio/cloudflare/badges/master/build.svg)](https://gitlab.com/mojoio/cloudflare/commits/master)
[![coverage report](https://gitlab.com/mojoio/cloudflare/badges/master/coverage.svg)](https://gitlab.com/mojoio/cloudflare/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/cloudflare.svg)](https://www.npmjs.com/package/@mojoio/cloudflare)
[![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/cloudflare/badge.svg)](https://snyk.io/test/npm/@mojoio/cloudflare)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
Use TypeScript for best in class instellisense.
```javascript
var cflare = require("cflare");
var cflareInstance = new cflare();
import * as cflare from 'cflare'
cflareInstance.auth({
email:"",
key:""
});
let myCflareAccount = new cflare.CflareAccount()
testCflareAccount.auth({
email: 'someuser@example.com',
key: 'someLongApiKey'
})
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;
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(...)
}
```
### About the authors:
[![Project Phase](https://mediaserve.lossless.digital/lossless.com/img/createdby_github.svg)](https://lossless.com/)
For further information read the linked docs at the top of this readme.
[![Gitter](https://img.shields.io/badge/Support%20us-PayPal-blue.svg)](https://paypal.me/lossless)
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

View File

@ -1,20 +0,0 @@
import "typings-global";
import * as interfaces from './cflare.interfaces';
export declare class CflareAccount {
private authEmail;
private authKey;
private authCheck();
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<{}>;
}

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

@ -1,56 +0,0 @@
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,2 +0,0 @@
"use strict";
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmludGVyZmFjZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZmxhcmUuaW50ZXJmYWNlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=

View File

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

View File

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

2
dist/index.d.ts vendored
View File

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

5
dist/index.js vendored
View File

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

16
npmextra.json Normal file
View File

@ -0,0 +1,16 @@
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "mojoio",
"gitrepo": "cloudflare",
"shortDescription": "easy cloudflare management",
"npmPackagename": "@mojoio/cloudflare",
"license": "MIT"
}
}
}

1865
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +1,55 @@
{
"name": "cflare",
"version": "0.0.11",
"description": "cloudflare management for CoreOS",
"name": "@mojoio/cloudflare",
"version": "3.0.2",
"private": false,
"description": "easy cloudflare management",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pushrocks/cflare.git"
"url": "git+https://gitlab.com/pushrocks/cflare.git"
},
"keywords": [
"CoreOS",
"Push.Rocks",
"cloudflare"
],
"author": "Lossless GmbH",
"license": "MIT",
"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": {
"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"
"@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartrequest": "^1.1.16",
"@pushrocks/smartstring": "^3.0.10",
"@tsclass/tsclass": "^2.0.1"
},
"devDependencies": {
"npmts-g": "^6.0.0",
"qenv": "^1.1.3",
"should": "^11.1.2",
"typings-test": "^1.0.3"
}
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/qenv": "^4.0.0",
"@pushrocks/tapbundle": "^3.0.11",
"@types/node": "^12.6.6",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

View File

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

1
test/test.d.ts vendored
View File

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

View File

@ -1,89 +0,0 @@
"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");
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) {
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();
});
});
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjo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BQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUM7b0JBQ3pCLElBQUksRUFBRSxDQUFDO2dCQUNYLENBQUMsQ0FBQyxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7WUFDSCxFQUFFLENBQUMsa0RBQWtELEVBQUMsVUFBUyxJQUFJO2dCQUMvRCxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDO2dCQUNwQixpQkFBaUIsQ0FBQyxZQUFZLENBQUMsbUJBQW1CLEVBQUMsR0FBRyxDQUFDO3FCQUNsRCxJQUFJLENBQUMsVUFBUyxXQUFXO29CQUN0QixPQUFPLENBQUMsR0FBRyxDQUFDLFdBQVcsQ0FBQyxDQUFDO29CQUN6QixJQUFJLEVBQUUsQ0FBQztnQkFDWCxDQUFDLENBQUMsQ0FBQztZQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ1AsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0=

View File

@ -1,88 +1,80 @@
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();
testCflareAccount.auth({
email: process.env.CF_EMAIL,
key: process.env.CF_KEY
// tslint:disable-next-line: no-implicit-dependencies
import { expect, tap } from '@pushrocks/tapbundle';
// tslint:disable-next-line: no-implicit-dependencies
import { Qenv } from '@pushrocks/qenv';
import cloudflare = require('../ts/index');
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
const randomPrefix = Math.floor(Math.random() * 2000);
let testCloudflareAccount: cloudflare.CloudflareAccount;
tap.test('should create a valid instance of CloudflareAccount', async () => {
testCloudflareAccount = new cloudflare.CloudflareAccount({
email: testQenv.getEnvVarOnDemand('CF_EMAIL'),
key: testQenv.getEnvVarOnDemand('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){
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();
});
});
});
})
tap.skip.test('.listZones() -> should display an entire account', async tools => {
tools.timeout(600000);
const result = await testCloudflareAccount.listZones();
console.log(result);
});
tap.test(
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
async tools => {
tools.timeout(600000);
await testCloudflareAccount.getZoneId('bleu.de');
}
);
tap.test(
'.listRecords(domainName) -> should list all records for a specific Domain Name',
async tools => {
tools.timeout(600000);
await testCloudflareAccount.listRecords('bleu.de').then(async responseArg => {
console.log(responseArg);
});
}
);
tap.test('should create a valid record for a subdomain', async tools => {
tools.timeout(600000);
await testCloudflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1');
});
tap.test('should get a record from Cloudflare', async tools => {
tools.timeout(600000);
await testCloudflareAccount.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A').then(responseArg => {
console.log(responseArg);
});
});
tap.test('should remove a subdomain record from Cloudflare', async tools => {
tools.timeout(600000);
await testCloudflareAccount
.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.then(async responseArg => {
console.log(responseArg);
});
});
tap.test('.purge(some.domain) -> should purge everything', async () => {
await testCloudflareAccount.purgeZone('bleu.de');
});
// WORKERS
tap.test('should create a worker', async () => {
await testCloudflareAccount.workerManager.createWorker('myawesomescript', `addEventListener('fetch', event => { event.respondWith(fetch(event.request)) })`);
});
tap.test('should get workers', async () => {
await testCloudflareAccount.workerManager.listWorkers();
});
tap.start();

View File

@ -1,167 +0,0 @@
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
}
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 = {
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
};
//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 = 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;
}
};

View File

@ -1,2 +0,0 @@
import "typings-global";
import plugins = require("./cflare.plugins");

View File

@ -1,59 +0,0 @@
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,6 +0,0 @@
import "typings-global";
export let beautylog = require("beautylog");
export import q = require("smartq");
export let request = require("request");
export import smartstring = require("smartstring");
export import smartdelay = require('smartdelay');

View File

@ -0,0 +1,217 @@
import plugins = require('./cloudflare.plugins');
import * as interfaces from './interfaces/cloudflare.interfaces';
// interfaces
import { TDnsRecord } from '@tsclass/tsclass';
import { WorkerManager } from './cloudflare.classes.workermanager';
import { ZoneManager } from './cloudflare.classes.zonemanager';
export class CloudflareAccount {
private authEmail: string;
private authKey: string;
private accountIdentifier: string;
public workerManager = new WorkerManager(this);
public zoneManager = new ZoneManager(this);
/**
* constructor sets auth information on the CloudflareAccountInstance
* @param optionsArg
*/
constructor(optionsArg: { email: string; key: string }) {
this.authEmail = optionsArg.email;
this.authKey = optionsArg.key;
}
public async getAccountIdentifier() {
const route = `/accounts?page=1&per_page=20&direction=desc`;
const response: any = await this.request('GET', route);
this.accountIdentifier = response.result[0].id;
console.log('Account identifier is: ' + this.accountIdentifier);
return this.accountIdentifier;
}
/**
* gets a zone id of a domain from cloudflare
* @param domainName
*/
public async getZoneId(domainName: string) {
const domain = new plugins.smartstring.Domain(domainName);
const zoneArray = await this.listZones(domain.zoneName);
const filteredResponse = zoneArray.filter(zoneArg => {
return zoneArg.name === domainName;
});
if (filteredResponse.length >= 1) {
return filteredResponse[0].id;
} else {
plugins.smartlog.defaultLogger.log(
'error',
`the domain ${domainName} does not appear to be in this account!`
);
throw new Error(`the domain ${domainName} does not appear to be in this account!`);
}
}
/**
* gets a record
* @param domainNameArg
* @param typeArg
*/
public async getRecord(
domainNameArg: string,
typeArg: TDnsRecord
): Promise<interfaces.ICflareRecord> {
const domain = new plugins.smartstring.Domain(domainNameArg);
const recordArrayArg = await this.listRecords(domain.zoneName);
const filteredResponse = recordArrayArg.filter(recordArg => {
return recordArg.type === typeArg && recordArg.name === domainNameArg;
});
return filteredResponse[0];
}
public async createRecord(
domainNameArg: string,
typeArg: TDnsRecord,
contentArg: string
): Promise<any> {
const domain = new plugins.smartstring.Domain(domainNameArg);
const domainIdArg = await this.getZoneId(domain.zoneName);
const dataObject = {
name: domain.fullName,
type: typeArg,
content: contentArg
};
const response = await this.request(
'POST',
'/zones/' + domainIdArg + '/dns_records',
dataObject
);
return response;
}
/**
* removes a record from Cloudflare
* @param domainNameArg
* @param typeArg
*/
public async removeRecord(domainNameArg: string, typeArg: TDnsRecord): Promise<any> {
const domain = new plugins.smartstring.Domain(domainNameArg);
const cflareRecord = await this.getRecord(domain.fullName, typeArg);
if (cflareRecord) {
const requestRoute: string = `/zones/${cflareRecord.zone_id}/dns_records/${cflareRecord.id}`;
return await this.request('DELETE', requestRoute);
} else {
throw new Error(`could not remove record for ${domainNameArg} with type ${typeArg}`);
}
}
/**
* updates a record
* @param domainNameArg
* @param typeArg
* @param valueArg
*/
public updateRecord(domainNameArg: string, typeArg: string, valueArg) {
// TODO: implement
const done = plugins.smartpromise.defer();
const domain = new plugins.smartstring.Domain(domainNameArg);
return done.promise;
}
/**
* list all records of a specified domain name
* @param domainNameArg - the domain name that you want to get the records from
*/
public async listRecords(domainNameArg: string): Promise<interfaces.ICflareRecord[]> {
const domain = new plugins.smartstring.Domain(domainNameArg);
const domainId = await this.getZoneId(domain.zoneName);
const responseArg: any = await this.request(
'GET',
'/zones/' + domainId + '/dns_records?per_page=100'
);
const result: interfaces.ICflareRecord[] = responseArg.result;
return result;
}
/**
* list all zones in the associated authenticated account
* @param domainName
*/
public async listZones(domainName?: string): Promise<interfaces.ICflareZone[]> {
// TODO: handle pagination
let requestRoute = `/zones?per_page=50`;
// may be optionally filtered by domain name
if (domainName) {
requestRoute = `${requestRoute}&name=${domainName}`;
}
const response: any = await this.request('GET', requestRoute);
const result = response.result;
return result;
}
public async purgeZone(domainName: string) {
const domain = new plugins.smartstring.Domain(domainName);
const domainId = await this.getZoneId(domain.zoneName);
const requestUrl = `/zones/${domainId}/purge_cache`;
const payload = {
purge_everything: true
};
const respone = await this.request('DELETE', requestUrl, payload);
}
public request(methodArg: string, routeArg: string, dataArg: any = {}, requestHeadersArg = {}): Promise<any> {
const done = plugins.smartpromise.defer();
const options: plugins.smartrequest.ISmartRequestOptions = {
method: methodArg,
headers: {
'Content-Type': 'application/json',
'X-Auth-Email': this.authEmail,
'X-Auth-Key': this.authKey,
'Content-Length': Buffer.byteLength(JSON.stringify(dataArg)),
...requestHeadersArg
},
requestBody: dataArg,
};
// console.log(options);
let retryCount = 0; // count the amount of retries
const makeRequest = async () => {
const 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 for route ${routeArg}! Going to retry!`);
console.log(response.body);
} else {
console.log(response.statusCode);
done.reject(new Error('request failed'));
}
};
const 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

@ -0,0 +1,34 @@
import { WorkerManager } from './cloudflare.classes.workermanager';
export class Worker {
// STATIC
public static async fromApiObject(workerManager: WorkerManager, apiObject): Promise<Worker> {
console.log(apiObject);
return new Worker(workerManager);
}
// INSTANCE
private workerManager: WorkerManager;
public id: string;
public etag: string;
public createdOn: string;
public modifiedOn: string;
public routes: string[] = [];
constructor(workerManagerArg: WorkerManager) {
this.workerManager = workerManagerArg;
}
/**
* gets all routes for a worker
*/
public async getRoutes(){
const zones = await this.workerManager.cfAccount.listZones();
console.log(zones);
}
public setRoutes(routeArray: string[]) {
}
}

View File

@ -0,0 +1,31 @@
import * as plugins from './cloudflare.plugins';
import { CloudflareAccount } from './cloudflare.classes.account';
import { Worker } from './cloudflare.classes.worker';
export class WorkerManager {
public cfAccount: CloudflareAccount;
constructor(cfAccountArg: CloudflareAccount) {
this.cfAccount = cfAccountArg;
}
public async createWorker(workerName: string, workerScript: string): Promise<Worker> {
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`;
const responseBody = await this.cfAccount.request('PUT', route, workerScript, {
'Content-Type': 'application/javascript',
'Content-Length': Buffer.byteLength(workerScript)
});
return Worker.fromApiObject(this, responseBody);
}
/**
* lists workers
*/
public async listWorkers() {
const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts`;
const response = await this.cfAccount.request('GET', route);
console.log(response);
}
}

View File

@ -0,0 +1,11 @@
import * as plugins from './cloudflare.plugins';
import { CloudflareAccount } from './cloudflare.classes.account';
export class ZoneManager {
public cfAccount: CloudflareAccount;
public zoneName: string;
constructor(cfAccountArg: CloudflareAccount) {
this.cfAccount = cfAccountArg;
}
}

8
ts/cloudflare.plugins.ts Normal file
View File

@ -0,0 +1,8 @@
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartstring from '@pushrocks/smartstring';
import * as tsclass from '@tsclass/tsclass';
export { smartlog, smartpromise, smartdelay, smartrequest, smartstring, tsclass };

View File

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

View File

@ -0,0 +1,59 @@
import * as plugins from '../cloudflare.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;
}

1
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './cloudflare.interfaces';

18
tslint.json Normal file
View File

@ -0,0 +1,18 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"no-return-await": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}