initial
This commit is contained in:
commit
cb7c442e19
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
pages/
|
||||
public/
|
||||
|
59
.gitlab-ci.yml
Normal file
59
.gitlab-ci.yml
Normal 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 --host gitlab
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# dnsly
|
||||
smart dns methods written in TypeScript
|
||||
|
||||
## Availabililty
|
||||
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/dnsly)
|
||||
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/dnsly)
|
||||
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/dnsly)
|
||||
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/dnsly/)
|
||||
|
||||
## Status for master
|
||||
[![build status](https://gitlab.com/pushrocks/dnsly/badges/master/build.svg)](https://gitlab.com/pushrocks/dnsly/commits/master)
|
||||
[![coverage report](https://gitlab.com/pushrocks/dnsly/badges/master/coverage.svg)](https://gitlab.com/pushrocks/dnsly/commits/master)
|
||||
[![Dependency Status](https://david-dm.org/pushrocks/dnsly.svg)](https://david-dm.org/pushrocks/dnsly)
|
||||
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/dnsly/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/dnsly/master/dependencies/npm)
|
||||
[![bitHound Code](https://www.bithound.io/github/pushrocks/dnsly/badges/code.svg)](https://www.bithound.io/github/pushrocks/dnsly)
|
||||
[![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
|
||||
we recommend the use of TypeScript
|
||||
```javascript
|
||||
|
||||
```
|
||||
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
|
3
coverage/coverage-final.json
Normal file
3
coverage/coverage-final.json
Normal file
File diff suppressed because one or more lines are too long
80
coverage/lcov.info
Normal file
80
coverage/lcov.info
Normal file
@ -0,0 +1,80 @@
|
||||
TN:
|
||||
SF:/Users/philkunz/gitlab/pushrocks/dnsly/dist/index.js
|
||||
FN:3,(anonymous_1)
|
||||
FN:3,defineProperties
|
||||
FN:3,(anonymous_3)
|
||||
FN:5,_classCallCheck
|
||||
FN:13,(anonymous_5)
|
||||
FN:17,Dnsly
|
||||
FN:30,getRecord
|
||||
FN:37,(anonymous_8)
|
||||
FN:51,close
|
||||
FN:60,_setDnsProvider
|
||||
FNF:10
|
||||
FNH:10
|
||||
FNDA:1,(anonymous_1)
|
||||
FNDA:1,defineProperties
|
||||
FNDA:1,(anonymous_3)
|
||||
FNDA:2,_classCallCheck
|
||||
FNDA:1,(anonymous_5)
|
||||
FNDA:2,Dnsly
|
||||
FNDA:3,getRecord
|
||||
FNDA:3,(anonymous_8)
|
||||
FNDA:2,close
|
||||
FNDA:2,_setDnsProvider
|
||||
DA:3,3
|
||||
DA:5,2
|
||||
DA:7,1
|
||||
DA:8,1
|
||||
DA:13,1
|
||||
DA:17,1
|
||||
DA:18,2
|
||||
DA:20,2
|
||||
DA:21,2
|
||||
DA:28,1
|
||||
DA:31,3
|
||||
DA:32,3
|
||||
DA:38,3
|
||||
DA:39,0
|
||||
DA:41,3
|
||||
DA:43,3
|
||||
DA:52,2
|
||||
DA:61,2
|
||||
DA:62,2
|
||||
DA:63,2
|
||||
DA:65,0
|
||||
DA:70,1
|
||||
DA:73,1
|
||||
LF:23
|
||||
LH:21
|
||||
BRDA:3,1,0,3
|
||||
BRDA:3,1,1,3
|
||||
BRDA:3,2,0,3
|
||||
BRDA:3,2,1,0
|
||||
BRDA:3,3,0,1
|
||||
BRDA:3,3,1,0
|
||||
BRDA:3,4,0,0
|
||||
BRDA:3,4,1,1
|
||||
BRDA:5,5,0,0
|
||||
BRDA:5,5,1,2
|
||||
BRDA:38,6,0,0
|
||||
BRDA:38,6,1,3
|
||||
BRDA:61,7,0,2
|
||||
BRDA:61,7,1,0
|
||||
BRF:14
|
||||
BRH:8
|
||||
end_of_record
|
||||
TN:
|
||||
SF:/Users/philkunz/gitlab/pushrocks/dnsly/dist/dnsly.plugins.js
|
||||
FNF:0
|
||||
FNH:0
|
||||
DA:3,1
|
||||
DA:4,1
|
||||
DA:5,1
|
||||
DA:6,1
|
||||
DA:7,1
|
||||
LF:5
|
||||
LH:5
|
||||
BRF:0
|
||||
BRH:0
|
||||
end_of_record
|
4
dist/dnsly.plugins.d.ts
vendored
Normal file
4
dist/dnsly.plugins.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import 'typings-global';
|
||||
import * as beautylog from 'beautylog';
|
||||
declare let dnsSocket: any;
|
||||
export { beautylog, dnsSocket };
|
7
dist/dnsly.plugins.js
vendored
Normal file
7
dist/dnsly.plugins.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const beautylog = require("beautylog");
|
||||
exports.beautylog = beautylog;
|
||||
let dnsSocket = require('dns-socket');
|
||||
exports.dnsSocket = dnsSocket;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZG5zbHkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2Ruc2x5LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix1Q0FBc0M7QUFJbEMsOEJBQVM7QUFIYixJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsWUFBWSxDQUFDLENBQUE7QUFJakMsOEJBQVMifQ==
|
28
dist/index.d.ts
vendored
Normal file
28
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/// <reference types="q" />
|
||||
import * as q from 'q';
|
||||
export declare type TDnsProvider = 'google';
|
||||
export declare type TDnsRecordType = 'A' | 'AAAA' | 'CNAME' | 'PTR' | 'MX' | 'NAPTR' | 'NS' | 'SOA' | 'SRV' | 'TXT';
|
||||
/**
|
||||
* class dnsly offers methods for working with dns from a dns provider like Google DNS
|
||||
*/
|
||||
export declare class Dnsly {
|
||||
dnsServerIp: string;
|
||||
dnsServerPort: number;
|
||||
dnsSocketInstance: any;
|
||||
/**
|
||||
* constructor for class dnsly
|
||||
*/
|
||||
constructor(dnsProviderArg: TDnsProvider);
|
||||
/**
|
||||
* gets a record
|
||||
*/
|
||||
getRecord(recordNameArg: string, recordTypeArg: TDnsRecordType): q.Promise<{}>;
|
||||
/**
|
||||
* close the dnsly instance
|
||||
*/
|
||||
close(): void;
|
||||
/**
|
||||
* set the DNS provider
|
||||
*/
|
||||
private _setDnsProvider(dnsProvider);
|
||||
}
|
53
dist/index.js
vendored
Normal file
53
dist/index.js
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
const q = require("q");
|
||||
const plugins = require("./dnsly.plugins");
|
||||
/**
|
||||
* class dnsly offers methods for working with dns from a dns provider like Google DNS
|
||||
*/
|
||||
class Dnsly {
|
||||
/**
|
||||
* constructor for class dnsly
|
||||
*/
|
||||
constructor(dnsProviderArg) {
|
||||
this._setDnsProvider(dnsProviderArg);
|
||||
this.dnsSocketInstance = plugins.dnsSocket();
|
||||
}
|
||||
/**
|
||||
* gets a record
|
||||
*/
|
||||
getRecord(recordNameArg, recordTypeArg) {
|
||||
let done = q.defer();
|
||||
this.dnsSocketInstance.query({
|
||||
questions: [{
|
||||
type: recordTypeArg,
|
||||
name: recordNameArg
|
||||
}]
|
||||
}, this.dnsServerPort, this.dnsServerIp, (err, res) => {
|
||||
if (err) {
|
||||
done.reject(err);
|
||||
}
|
||||
done.resolve(res);
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* close the dnsly instance
|
||||
*/
|
||||
close() {
|
||||
this.dnsSocketInstance.destroy();
|
||||
}
|
||||
/**
|
||||
* set the DNS provider
|
||||
*/
|
||||
_setDnsProvider(dnsProvider) {
|
||||
if (dnsProvider === 'google') {
|
||||
this.dnsServerIp = '8.8.8.8';
|
||||
this.dnsServerPort = 53;
|
||||
}
|
||||
else {
|
||||
throw new Error('unknown dns provider');
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Dnsly = Dnsly;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQU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SxDQUFDLENBQUMsQ0FBQztZQUMzQixJQUFJLENBQUMsV0FBVyxHQUFHLFNBQVMsQ0FBQTtZQUM1QixJQUFJLENBQUMsYUFBYSxHQUFHLEVBQUUsQ0FBQTtRQUMzQixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixNQUFNLElBQUksS0FBSyxDQUFDLHNCQUFzQixDQUFDLENBQUE7UUFDM0MsQ0FBQztJQUNMLENBQUM7Q0FDSjtBQXJERCxzQkFxREMifQ==
|
37
package.json
Normal file
37
package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "dnsly",
|
||||
"version": "1.0.0",
|
||||
"description": "smart dns methods written in TypeScript",
|
||||
"main": "dist/index.js",
|
||||
"typings": "../dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/dnsly.git"
|
||||
},
|
||||
"keywords": [
|
||||
"dns",
|
||||
"google dns",
|
||||
"dns record"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/dnsly/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||
"dependencies": {
|
||||
"@types/q": "0.0.32",
|
||||
"beautylog": "^6.0.0",
|
||||
"dns-socket": "^1.4.2",
|
||||
"q": "^1.4.1",
|
||||
"typings-global": "^1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/should": "^8.1.30",
|
||||
"should": "^11.1.1",
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
}
|
1
test/test.d.ts
vendored
Normal file
1
test/test.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
import 'typings-test';
|
49
test/test.js
Normal file
49
test/test.js
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const should = require("should");
|
||||
const dnsly = require("../dist/index");
|
||||
let testDnsly;
|
||||
describe('dnsly', function () {
|
||||
it('should create an instance of Dnsly', function () {
|
||||
testDnsly = new dnsly.Dnsly('google');
|
||||
should(testDnsly).be.instanceOf(dnsly.Dnsly);
|
||||
});
|
||||
it('should, get a dns record for a domain when called quickly', function (done) {
|
||||
testDnsly.getRecord('google.com', 'A').then(res => {
|
||||
console.log(res);
|
||||
done();
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
it('should, get a dns record for a domain when called with timeout', function (done) {
|
||||
setTimeout(() => {
|
||||
testDnsly.getRecord('google.com', 'A').then(res => {
|
||||
console.log(res);
|
||||
done();
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
done(err);
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
it('should get a dns record for a domain when called with second instance and timeout', function (done) {
|
||||
this.timeout(10000);
|
||||
let testDnsly2 = new dnsly.Dnsly('google');
|
||||
setTimeout(() => {
|
||||
testDnsly2.getRecord('google.com', 'MX').then(res => {
|
||||
console.log(res);
|
||||
done();
|
||||
testDnsly2.close();
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
done(err);
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
it('should close the instance', function () {
|
||||
testDnsly.close();
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsdUNBQXNDO0FBRXRDLElBQUksU0FBc0IsQ0FBQTtBQUUxQixRQUFRLENBQUMsT0FBTyxFQUFFO0lBQ2QsRUFBRSxDQUFDLG9DQUFvQyxFQUFFO1FBQ3JDLFNBQVMsR0FBRyxJQUFJLEtBQUssQ0F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BO0lBRVosQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsbUZBQW1GLEVBQUUsVUFBVSxJQUFJO1FBQ2xHLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDbkIsSUFBSSxVQUFVLEdBQUcsSUFBSSxLQUFLLENBQUMsS0FBSyxDQUFDLFFBQVEsQ0FBQyxDQUFBO1FBQzFDLFVBQVUsQ0FBQztZQUNQLFVBQVUsQ0FBQyxTQUFTLENBQUMsWUFBWSxFQUFFLElBQUksQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHO2dCQUM3QyxPQUFPLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFBO2dCQUNoQixJQUFJLEVBQUUsQ0FBQTtnQkFDTixVQUFVLENBQUMsS0FBSyxFQUFFLENBQUE7WUFDdEIsQ0FBQyxDQUFDLENBQUMsS0FBSyxDQUFDLEdBQUc7Z0JBQ1IsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQTtnQkFDaEIsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFBO1lBQ2IsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLEVBQUUsSUFBSSxDQUFDLENBQUE7SUFFWixDQUFDLENBQUMsQ0FBQTtJQUVGLEVBQUUsQ0FBQywyQkFBMkIsRUFBRTtRQUM1QixTQUFTLENBQUMsS0FBSyxFQUFFLENBQUE7SUFDckIsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
28
test/test.ts
Normal file
28
test/test.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import 'typings-test'
|
||||
import * as should from 'should'
|
||||
|
||||
import * as dnsly from '../dist/index'
|
||||
|
||||
let testDnsly: dnsly.Dnsly
|
||||
|
||||
describe('dnsly', function () {
|
||||
it('should create an instance of Dnsly', function () {
|
||||
testDnsly = new dnsly.Dnsly('google')
|
||||
should(testDnsly).be.instanceOf(dnsly.Dnsly)
|
||||
})
|
||||
|
||||
it('should, get a dns record for a domain', function (done) {
|
||||
testDnsly.getRecord('google.com', 'A').then(res => {
|
||||
console.log(res)
|
||||
done()
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
done(err)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it('should close the instance', function () {
|
||||
testDnsly.close()
|
||||
})
|
||||
})
|
8
ts/dnsly.plugins.ts
Normal file
8
ts/dnsly.plugins.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import 'typings-global'
|
||||
import * as beautylog from 'beautylog'
|
||||
let dnsSocket = require('dns-socket')
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
dnsSocket
|
||||
}
|
72
ts/index.ts
Normal file
72
ts/index.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import * as q from 'q'
|
||||
import * as plugins from './dnsly.plugins'
|
||||
|
||||
export type TDnsProvider = 'google'
|
||||
export type TDnsRecordType = 'A'
|
||||
| 'AAAA'
|
||||
| 'CNAME'
|
||||
| 'PTR'
|
||||
| 'MX'
|
||||
| 'NAPTR'
|
||||
| 'NS'
|
||||
| 'SOA'
|
||||
| 'SRV'
|
||||
| 'TXT'
|
||||
|
||||
/**
|
||||
* class dnsly offers methods for working with dns from a dns provider like Google DNS
|
||||
*/
|
||||
export class Dnsly {
|
||||
dnsServerIp: string
|
||||
dnsServerPort: number
|
||||
dnsSocketInstance
|
||||
/**
|
||||
* constructor for class dnsly
|
||||
*/
|
||||
constructor(dnsProviderArg: TDnsProvider) {
|
||||
this._setDnsProvider(dnsProviderArg)
|
||||
this.dnsSocketInstance = plugins.dnsSocket()
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a record
|
||||
*/
|
||||
getRecord(recordNameArg: string, recordTypeArg: TDnsRecordType) {
|
||||
let done = q.defer()
|
||||
this.dnsSocketInstance.query(
|
||||
{
|
||||
questions: [{
|
||||
type: recordTypeArg,
|
||||
name: recordNameArg
|
||||
}]
|
||||
},
|
||||
this.dnsServerPort,
|
||||
this.dnsServerIp,
|
||||
(err, res) => {
|
||||
if (err) {
|
||||
done.reject(err)
|
||||
}
|
||||
done.resolve(res)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* close the dnsly instance
|
||||
*/
|
||||
close() {
|
||||
this.dnsSocketInstance.destroy()
|
||||
}
|
||||
|
||||
/**
|
||||
* set the DNS provider
|
||||
*/
|
||||
private _setDnsProvider(dnsProvider: TDnsProvider) {
|
||||
if (dnsProvider === 'google') {
|
||||
this.dnsServerIp = '8.8.8.8'
|
||||
this.dnsServerPort = 53
|
||||
} else {
|
||||
throw new Error('unknown dns provider')
|
||||
}
|
||||
}
|
||||
}
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Loading…
Reference in New Issue
Block a user