Compare commits

..

28 Commits

Author SHA1 Message Date
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
24 changed files with 578 additions and 58 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/

43
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,43 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test1
- test2
- test3
- release
testLEGACY:
stage: test1
script:
- npmci test legacy
only:
- tags
tags:
- docker
testLTS:
stage: test2
script:
- npmci test lts
only:
- tags
tags:
- docker
testSTABLE:
stage: test3
script:
- npmci test stable
only:
- tags
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker

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,10 +1,11 @@
# cflare # cflare
allows you to manage cloudflare from CoreOS allows you to manage multiple cloudflare accounts.
> Note: this package is still in alpha, so some things do not yet work. > 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. I (Phil from Lossless) expect this package to be ready 1. of June 2016.
## Status ## Status
[![Build Status](https://travis-ci.org/pushrocks/cflare.svg?branch=master)](https://travis-ci.org/pushrocks/cflare)
## Usage ## Usage
@ -17,9 +18,14 @@ cflareInstance.auth({
key:"" key:""
}); });
cflareInstance.createRecord(); cflareInstance.createRecord(); // returns promise with resolve function getting the response;
cflareInstance.removeRecord(); cflareInstance.removeRecord(); // returns promise with resolve function getting the response;
cflareInstance.copyRecord(); cflareInstance.copyRecord(); // returns promise with resolve function getting the response;
cflareInstance.listRecords(); cflareInstance.listRecords(); // returns promise with resolve function getting the response;
cflareInstance.listDomains(); cflareInstance.listDomains(); // returns promise with resolve function getting the response;
``` ```
### About the authors:
[![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)

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

@ -0,0 +1,19 @@
import "typings-global";
export declare class CflareAccount {
private authEmail;
private authKey;
private authCheck();
constructor();
auth(optionsArg: {
email: string;
key: string;
}): void;
getZoneId(domainName: string): any;
getRecord(domainNameArg: string, typeArg: string): any;
createRecord(domainNameArg: string, typeArg: string, contentArg: string): any;
removeRecord(domainNameArg: string, typeArg: string): any;
updateRecord(domainNameArg: string, typeArg: string, valueArg: any): any;
listRecords(domainNameArg: string): any;
listZones(domainName?: string): any;
request(methodArg: string, routeArg: string, dataArg?: {}): any;
}

145
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2ZsYXJlLmNsYXNzZXMuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NmbGFyZS5jbGFzc2VzLmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQSJ9

View File

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

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

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

View File

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

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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBQ3hCLDZDQUE0QixnQ0FBZ0MsQ0FBQztBQUFyRCxxRUFBcUQifQ==

View File

@ -1,8 +1,9 @@
{ {
"name": "cflare", "name": "cflare",
"version": "0.0.1", "version": "0.0.10",
"description": "cloudflare management for CoreOS", "description": "cloudflare management for CoreOS",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(npmts)"
}, },
@ -21,10 +22,16 @@
}, },
"homepage": "https://github.com/pushrocks/cflare#readme", "homepage": "https://github.com/pushrocks/cflare#readme",
"dependencies": { "dependencies": {
"beautylog": "^4.1.2", "beautylog": "^5.0.18",
"request": "^2.72.0" "q": "^1.4.1",
"request": "^2.74.0",
"smartstring": "^2.0.15",
"typings-global": "^1.0.6"
}, },
"devDependencies": { "devDependencies": {
"npmts": "^5.0.4" "npmts-g": "^5.2.8",
"qenv": "^1.0.8",
"should": "^10.0.0",
"typings-test": "^1.0.1"
} }
} }

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";

90
test/test.js Normal file
View File

@ -0,0 +1,90 @@
"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(10000);
testCflareAccount.listZones()
.then((responseArg) => {
console.log(responseArg);
done();
});
});
});
describe(".getZoneId(domainName)", function () {
it("should get an Cloudflare Id for a domain string", function (done) {
this.timeout(10000);
testCflareAccount.getZoneId("bleu.de")
.then((responseArg) => {
console.log(responseArg);
done();
});
});
});
describe(".listRecords(domainName)", function () {
it("should list all records for a specific Domain Name", function (done) {
this.timeout(10000);
testCflareAccount.listRecords("bleu.de")
.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) {
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();
});
});
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxNQUFNLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDekMsSUFBSSxNQUFNLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQy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QUMsQ0FBQztZQUNILEVBQUUsQ0FBQyxrREFBa0QsRUFBQyxVQUFTLElBQUk7Z0JBQy9ELElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Z0JBQ25CLGlCQUFpQixDQUFDLFlBQVksQ0FBQyxtQkFBbUIsRUFBQyxHQUFHLENBQUM7cUJBQ2xELElBQUksQ0FBQyxVQUFTLFdBQVc7b0JBQ3RCLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxDQUFDLENBQUM7b0JBQ3pCLElBQUksRUFBRSxDQUFDO2dCQUNYLENBQUMsQ0FBQyxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUM7UUFDUCxDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUMifQ==

89
test/test.ts Normal file
View File

@ -0,0 +1,89 @@
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
});
describe("cflare",function(){
describe(".CflareAccount",function(){
describe(".listZones()",function(){
it("should display an entire account",function(done){
this.timeout(10000);
testCflareAccount.listZones()
.then((responseArg)=>{
console.log(responseArg);
done();
})
});
});
describe(".getZoneId(domainName)",function(){
it("should get an Cloudflare Id for a domain string",function(done){
this.timeout(10000)
testCflareAccount.getZoneId("bleu.de")
.then((responseArg)=>{
console.log(responseArg);
done();
});
});
});
describe(".listRecords(domainName)",function(){
it("should list all records for a specific Domain Name",function(done){
this.timeout(10000);
testCflareAccount.listRecords("bleu.de")
.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){
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

@ -0,0 +1,135 @@
import "typings-global";
import plugins = require("./cflare.plugins");
import helpers = require("./cflare.classes.helpers");
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((responseArg) => {
let filteredResponse = responseArg.result.filter((zoneArg)=>{
return zoneArg.name === domainName;
});
if (filteredResponse.length >= 1){
done.resolve(filteredResponse[0].id);
} else {
plugins.beautylog.error("the domain " + domainName.blue + " does not appear to be in this account!");
done.reject(undefined);
}
});
return done.promise;
}
getRecord(domainNameArg:string,typeArg:string){
let done = plugins.q.defer();
let domain = new plugins.smartstring.Domain(domainNameArg);
this.listRecords(domain.zoneName)
.then((responseArg) => {
let filteredResponse = responseArg.result.filter((recordArg) => {
return (recordArg.type == typeArg && recordArg.name == domainNameArg);
})
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){
let done = plugins.q.defer();
let domain = new plugins.smartstring.Domain(domainNameArg);
this.getZoneId(domain.zoneName)
.then((domainIdArg)=>{
this.request("GET","/zones/" + domainIdArg + "/dns_records?per_page=100")
.then(function(responseArg){
done.resolve(responseArg);
});
});
return done.promise;
}
listZones(domainName?:string){ // TODO: handle pagination
let done = plugins.q.defer();
let requestRoute = "/zones?per_page=50"
if(domainName) requestRoute = requestRoute + "&name=" + domainName;
let result = {};
this.request("GET",requestRoute)
.then(function(responseArg){
result = responseArg;
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);
plugins.request(options,function(err, res, body){
if (!err && res.statusCode == 200) {
var responseObj = JSON.parse(body);
done.resolve(responseObj);
} else {
console.log(err);
console.log(res);
done.reject(err);
};
});
return done.promise;
}
};

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(){
};
};

View File

@ -1,3 +1,5 @@
/// <reference path="./typings/main.d.ts" /> import "typings-global";
export let beautylog = require("beautylog"); export let beautylog = require("beautylog");
export let q = require("q");
export let request = require("request"); export let request = require("request");
export import smartstring = require("smartstring");

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