Compare commits

...

29 Commits

Author SHA1 Message Date
a1203366d7 4.0.6 2021-01-22 22:20:40 +00:00
0deb77cda8 fix(core): update 2021-01-22 22:20:39 +00:00
ed8b7ec65a 4.0.5 2021-01-22 20:37:52 +00:00
6cfc12f83f fix(core): update 2021-01-22 20:37:51 +00:00
efd9bbb77a 4.0.4 2020-08-05 15:37:52 +00:00
b463aea274 fix(core): update 2020-08-05 15:37:51 +00:00
c8cf590a5a 4.0.3 2020-02-19 21:38:43 +00:00
42f679ef61 fix(core): update 2020-02-19 21:38:42 +00:00
0cb882bb7d 4.0.2 2020-02-15 16:46:46 +00:00
66f817cdf8 fix(core): update 2020-02-15 16:46:46 +00:00
5925c882c8 4.0.1 2020-02-15 16:46:04 +00:00
6f09a82eee fix(core): update 2020-02-15 16:46:04 +00:00
e23579709a 4.0.0 2020-02-15 16:41:38 +00:00
929e4152d3 BREAKING CHANGE(core): now uses Google DNS HTTPS API and handles DNSSEC validation 2020-02-15 16:41:37 +00:00
d0527affc2 3.0.8 2019-01-07 00:53:04 +01:00
f2ebaf74d9 fix(core): update 2019-01-07 00:53:04 +01:00
b6d8c36f3e 3.0.7 2019-01-07 00:28:27 +01:00
587600d571 3.0.6 2019-01-07 00:28:16 +01:00
17f293ca4e fix(core): update 2019-01-07 00:28:15 +01:00
0ed946ee63 3.0.5 2019-01-07 00:21:15 +01:00
e720d5905e fix(core): update 2019-01-07 00:21:15 +01:00
6286bfaa8f 3.0.4 2018-05-13 16:43:47 +02:00
9390bbae61 fix(core): fix .checkUntilAvailable error 2018-05-13 16:43:46 +02:00
ebb007bcdb 3.0.3 2018-05-13 16:22:38 +02:00
e6d99d5664 fix(ci): fix @gitzone/npmts package name 2018-05-13 16:22:37 +02:00
7b29efc398 3.0.2 2018-05-13 16:21:15 +02:00
64c381d42f fix(docs): update 2018-05-13 16:21:15 +02:00
d4dbf4f2b3 3.0.1 2018-05-13 16:18:40 +02:00
562dca35a7 fix(ci): add access level and correct global packages 2018-05-13 16:18:40 +02:00
14 changed files with 11566 additions and 592 deletions

22
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/
pages/
public/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,16 +1,16 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .yarn/
key: "$CI_BUILD_STAGE"
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
- security
- test
- release
- metadata
# ====================
# security stage
@ -19,56 +19,49 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
snyk:
audit:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command yarn global add snyk
- npmci command yarn install --ignore-scripts
- npmci command snyk test
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS:
stage: test
script:
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
@ -78,6 +71,7 @@ release:
only:
- tags
tags:
- lossless
- docker
- notpriv
@ -86,20 +80,16 @@ release:
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
only:
- tags
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
@ -110,16 +100,20 @@ trigger:
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command yarn global add npmpage
- npmci command npmpage
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
@ -128,3 +122,4 @@ pages:
expire_in: 1 week
paths:
- public
allow_failure: true

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -1,45 +0,0 @@
# dnsly
smart dns methods written in TypeScript
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/dnsly)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/dnsly)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/dnsly)
[![docs](https://pushrocks.gitlab.io/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)
[![npm downloads per month](https://img.shields.io/npm/dm/dnsly.svg)](https://www.npmjs.com/package/dnsly)
[![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
```javascript
import * as dnsly from 'dnsly';
let myDnsly = new dnsly.Dnsly('google'); // uses Google DNS Servers e.g 8.8.8.8
myDnsly
.getRecord('example.com', 'AAAA') // returns promise
.then((record: dnsly.I_AAAA) => {
// AAAA record for google.com, the I_AAAA will give you proper typings for the record return type
// do something
});
```
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> 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://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -1,8 +1,18 @@
{
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartdns",
"shortDescription": "smart dns methods written in TypeScript",
"npmPackagename": "@pushrocks/smartdns",
"license": "MIT"
}
},
"npmci": {
"npmGlobalTools": [
"npmts"
],
"npmAccessLevel": "public"
"npmGlobalTools": [],
"npmAccessLevel": "public",
"npmRegistryUrl": "registry.npmjs.org"
}
}

11169
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{
"name": "@pushrocks/smartdns",
"version": "3.0.0",
"version": "4.0.6",
"private": false,
"description": "smart dns methods written in TypeScript",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(ts-node -O '{\"lib\": [ \"es2015\" ]}' test/test.ts)",
"build": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild --web)"
},
"repository": {
"type": "git",
@ -24,12 +25,32 @@
},
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
"dependencies": {
"beautylog": "^6.1.10",
"smartdelay": "^1.0.4",
"smartq": "^1.1.8"
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47",
"@tsclass/tsclass": "^3.0.21"
},
"devDependencies": {
"@types/node": "^10.0.8",
"tapbundle": "^2.0.0"
}
"@gitzone/tsbuild": "^2.1.24",
"@gitzone/tstest": "^1.0.43",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.0.27",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -1,33 +1,53 @@
# @pushrocks/smartdns
smart dns methods written in TypeScript
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/@pushrocks/smartdns)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdns)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdns)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdns/)
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdns)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartdns)
* [github.com (source mirror)](https://github.com/pushrocks/smartdns)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdns/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartdns/badges/master/build.svg)](https://GitLab.com/pushrocks/smartdns/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartdns/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartdns/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartdns.svg)](https://www.npmjs.com/package/@pushrocks/smartdns)
[![Dependency Status](https://david-dm.org/pushrocks/smartdns.svg)](https://david-dm.org/pushrocks/smartdns)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartdns/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartdns/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartdns/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartdns)
[![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/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartdns/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartdns/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartdns)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartdns)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartdns)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartdns)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartdns)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
```typescript
const mySmartDns = new smartdns.SmartDns(); // uses Google DNS Https API
const demoRecord = await mySmartDns.getRecord('example.com', 'AAAA'); // returns promise
/*
demoRecord looks like this:
{
name: 'example.com',
type: 'A',
dnsSecEnabled: true,
value: '104.24.103.243'
}
*/
```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,11 +1,11 @@
import { expect, tap } from 'tapbundle';
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartdns from '../ts/index';
let testDnsly: smartdns.Smartdns;
tap.test('should create an instance of Dnsly', async () => {
testDnsly = new smartdns.Smartdns('google');
testDnsly = new smartdns.Smartdns({});
expect(testDnsly).to.be.instanceOf(smartdns.Smartdns);
});
@ -14,8 +14,9 @@ tap.test('should get an A DNS Record', async () => {
{
name: 'dnsly_a.bleu.de',
value: '127.0.0.1',
type: 'A'
}
dnsSecEnabled: false,
type: 'A',
},
]);
});
@ -24,24 +25,25 @@ tap.test('should get an AAAA Record', async () => {
{
name: 'dnsly_aaaa.bleu.de',
value: '::1',
type: 'AAAA'
}
dnsSecEnabled: false,
type: 'AAAA',
},
]);
});
tap.test('should get a txt record', async () => {
return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([
{
chunked: ['sometext_txt'],
name: 'dnsly_txt.bleu.de',
value: 'sometext_txt',
type: 'TXT'
}
type: 'TXT',
dnsSecEnabled: false,
},
]);
});
tap.test('should, get a mx record for a domain', async () => {
let res = await testDnsly.getRecord('bleu.de', 'MX');
const res = await testDnsly.getRecord('bleu.de', 'MX');
console.log(res);
});
@ -65,4 +67,10 @@ tap.test('should get name server for hostname', async () => {
console.log(result);
});
tap.test('should detect dns sec', async () => {
const result = await testDnsly.getRecordA('lossless.com');
console.log(result[0]);
expect(result[0].dnsSecEnabled).to.be.true;
});
tap.start();

View File

@ -1,5 +1,16 @@
import * as beautylog from 'beautylog';
// node native scope
import * as dns from 'dns';
import * as smartdelay from 'smartdelay';
export { beautylog, dns, smartdelay };
export { dns };
// pushrocks scope
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export { smartdelay, smartpromise, smartrequest };
import * as tsclass from '@tsclass/tsclass';
export { tsclass };

View File

@ -1,63 +1,80 @@
import * as smartq from 'smartq';
import * as plugins from './dnsly.plugins';
export type TDnsProvider = 'google';
export type TDnsRecordType =
| 'A'
| 'AAAA'
| 'CNAME'
| 'PTR'
| 'MX'
| 'NAPTR'
| 'NS'
| 'SOA'
| 'SRV'
| 'TXT';
export type TDnsProvider = 'google' | 'cloudflare';
export interface IDnsRecord {
chunked?: string[];
name: string;
type: TDnsRecordType;
value: string;
export interface ISmartDnsConstructorOptions {}
export interface IGoogleDNSHTTPSResponse {
Status: number;
TC: boolean;
RD: boolean;
RA: boolean;
AD: boolean;
CD: boolean;
Question: Array<{ name: string; type: number }>;
Answer: Array<{ name: string; type: number; TTL: number; data: string }>;
Additional: [];
Comment: string;
}
/**
* class dnsly offers methods for working with dns from a dns provider like Google DNS
*/
export class Smartdns {
dnsServerIp: string;
dnsServerPort: number;
public dnsServerIp: string;
public dnsServerPort: number;
public dnsTypeMap: { [key: string]: number } = {
A: 1,
AAAA: 28,
CNAME: 5,
MX: 15,
TXT: 16,
};
/**
* constructor for class dnsly
*/
constructor(dnsProviderArg: TDnsProvider = 'google') {
this._setDnsProvider(dnsProviderArg);
}
constructor(optionsArg: ISmartDnsConstructorOptions) {}
async checkUntilAvailable(
/**
* check a dns record until it has propagated to Google DNS
* should be considerably fast
* @param recordNameArg
* @param recordTypeArg
* @param expectedValue
*/
public async checkUntilAvailable(
recordNameArg: string,
recordTypeArg: TDnsRecordType,
expectedValue: string
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
expectedValue: string,
cyclesArg: number = 50,
intervalArg: number = 500
) {
let cycleArg = 0;
let doCheck = async () => {
if (cycleArg < 30) {
cycleArg++;
let runCycles = 0;
const doCheck = async () => {
if (runCycles < cyclesArg) {
runCycles++;
try {
let myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
let myRecord = myRecordArray[0].value;
const myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
const myRecord = myRecordArray[0].value;
if (myRecord === expectedValue) {
console.log(
`smartdns: .checkUntilAvailable() verified that wanted >>>${recordTypeArg}<<< record exists for >>>${recordNameArg}<<< with value >>>${expectedValue}<<<`
);
return true;
} else {
await plugins.smartdelay.delayFor(500);
await plugins.smartdelay.delayFor(intervalArg);
return await doCheck();
}
} catch (err) {
await plugins.smartdelay.delayFor(500);
await plugins.smartdelay.delayFor(intervalArg);
return await doCheck();
}
} else {
console.log('failed permanently...');
console.log(
`smartdns: .checkUntilAvailable() failed permanently for ${recordNameArg} with value ${recordTypeArg} - ${expectedValue}...`
);
return false;
}
};
@ -67,67 +84,85 @@ export class Smartdns {
/**
* get A Dns Record
*/
async getRecordA(recordNameArg: string): Promise<IDnsRecord[]> {
public async getRecordA(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
return await this.getRecord(recordNameArg, 'A');
}
/**
* get AAAA Record
*/
async getRecordAAAA(recordNameArg: string) {
public async getRecordAAAA(recordNameArg: string) {
return await this.getRecord(recordNameArg, 'AAAA');
}
/**
* gets a txt record
*/
getRecordTxt(recordNameArg: string): Promise<IDnsRecord[]> {
let done = smartq.defer<IDnsRecord[]>();
plugins.dns.resolveTxt(recordNameArg, (err, recordsArg) => {
if (err) {
done.reject(err);
return;
public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
return await this.getRecord(recordNameArg, 'TXT');
}
let responseArray: IDnsRecord[] = [];
for (let record of recordsArg) {
let recordAny: any = record; // fix wrong typings
responseArray.push({
chunked: recordAny,
name: recordNameArg,
value: recordAny.join(' '),
type: 'TXT'
public async getRecord(
recordNameArg: string,
recordTypeArg: plugins.tsclass.network.TDnsRecordType
): Promise<plugins.tsclass.network.IDnsRecord[]> {
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
const response = await plugins.smartrequest.request(requestUrl, {
method: 'GET',
headers: {
accept: 'application/dns-json',
},
});
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
const responseBody: IGoogleDNSHTTPSResponse = response.body;
for (const dnsEntry of responseBody.Answer) {
if (dnsEntry.data.startsWith('"') && dnsEntry.data.endsWith('"')) {
dnsEntry.data = dnsEntry.data.replace(/^"(.*)"$/, '$1');
}
if (dnsEntry.name.endsWith('.')) {
dnsEntry.name = dnsEntry.name.substring(0, dnsEntry.name.length - 1);
}
returnArray.push({
name: dnsEntry.name,
type: this.convertDnsTypeNumberToTypeName(dnsEntry.type),
dnsSecEnabled: responseBody.AD,
value: dnsEntry.data,
});
}
done.resolve(responseArray);
});
return done.promise;
// console.log(responseBody);
return returnArray;
}
/**
* get oridinary record
* gets a record using nodejs dns resolver
*/
getRecord(recordNameArg: string, recordTypeArg: TDnsRecordType): Promise<IDnsRecord[]> {
let done = smartq.defer<IDnsRecord[]>();
public async getRecordWithNodeDNS(
recordNameArg: string,
recordTypeArg: plugins.tsclass.network.TDnsRecordType
): Promise<plugins.tsclass.network.IDnsRecord[]> {
this.setNodeDnsProvider('cloudflare');
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
if (err) {
done.reject(err);
return;
}
let responseArray: IDnsRecord[] = [];
for (let recordKey in recordsArg) {
responseArray.push({
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
for (const recordKey in recordsArg) {
returnArray.push({
name: recordNameArg,
value: recordsArg[recordKey],
type: recordTypeArg
value: recordsArg[recordKey][0],
type: recordTypeArg,
dnsSecEnabled: false,
});
}
done.resolve(responseArray);
done.resolve(returnArray);
});
return done.promise;
}
getNameServer(domainNameArg: string) {
const done = smartq.defer();
public async getNameServer(domainNameArg: string): Promise<string[]> {
const done = plugins.smartpromise.defer<string[]>();
plugins.dns.resolveNs(domainNameArg, (err, result) => {
if (!err) {
done.resolve(result);
@ -136,18 +171,43 @@ export class Smartdns {
done.reject(err);
}
});
return await done.promise;
}
/**
* set the DNS provider
*/
private _setDnsProvider(dnsProvider: TDnsProvider) {
if (dnsProvider === 'google') {
public setNodeDnsProvider(dnsProvider: TDnsProvider) {
if (!this.dnsServerIp) {
console.log(
`Warning: Setting the nodejs dns authority to ${dnsProvider}. Only do this if you know what you are doing.`
);
}
if (dnsProvider === 'google' && this.dnsServerIp !== '8.8.8.8') {
this.dnsServerIp = '8.8.8.8';
this.dnsServerPort = 53;
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']);
} else if (dnsProvider === 'cloudflare' && this.dnsServerIp !== '1.1.1.1') {
this.dnsServerIp = '1.1.1.1';
this.dnsServerPort = 53;
plugins.dns.setServers(['1.1.1.1', '1.0.0.1']);
} else {
throw new Error('unknown dns provider');
}
}
public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
return this.dnsTypeMap[dnsTypeNameArg];
}
public convertDnsTypeNumberToTypeName(
dnsTypeNumberArg: number
): plugins.tsclass.network.TDnsRecordType {
for (const key in this.dnsTypeMap) {
if (this.dnsTypeMap[key] === dnsTypeNumberArg) {
return key as plugins.tsclass.network.TDnsRecordType;
}
}
return null;
}
}

View File

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

360
yarn.lock
View File

@ -1,360 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@types/chai-as-promised@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.0.tgz#010b04cde78eacfb6e72bfddb3e58fe23c2e78b9"
dependencies:
"@types/chai" "*"
"@types/chai-string@^1.4.0":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@types/chai-string/-/chai-string-1.4.1.tgz#3a9d22716c27f2759bf272a4dbbdb593f18399e3"
dependencies:
"@types/chai" "*"
"@types/chai@*", "@types/chai@^4.1.2":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.1.3.tgz#b8a74352977a23b604c01aa784f5b793443fb7dc"
"@types/lodash@^4.14.55":
version "4.14.108"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.108.tgz#02656af3add2e5b3174f830862c47421c00ef817"
"@types/node@^10.0.8":
version "10.0.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.0.8.tgz#37b4d91d4e958e4c2ba0be2b86e7ed4ff19b0858"
ansi-256-colors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-256-colors/-/ansi-256-colors-1.1.0.tgz#910de50efcc7c09e3d82f2f87abd6b700c18818a"
ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
dependencies:
color-convert "^1.9.0"
assertion-error@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b"
beautycolor@^1.0.7:
version "1.0.11"
resolved "https://registry.yarnpkg.com/beautycolor/-/beautycolor-1.0.11.tgz#71c5568d5a7ed5c144d3a54f753ad1b08862aea5"
dependencies:
ansi-256-colors "^1.1.0"
typings-global "^1.0.14"
beautylog@^6.1.10:
version "6.1.10"
resolved "https://registry.yarnpkg.com/beautylog/-/beautylog-6.1.10.tgz#9c27e566937684cb689f9372d98cfa5415d50b72"
dependencies:
"@types/lodash" "^4.14.55"
beautycolor "^1.0.7"
figlet "^1.2.0"
lodash "^4.17.4"
ora "^1.1.0"
smartenv "^2.0.0"
smartq "^1.1.1"
typings-global "^1.0.14"
bindings@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"
chai-as-promised@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/chai-as-promised/-/chai-as-promised-7.1.1.tgz#08645d825deb8696ee61725dbf590c012eb00ca0"
dependencies:
check-error "^1.0.2"
chai-string@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/chai-string/-/chai-string-1.4.0.tgz#359140c051d36a4e4b1a5fc6b910152f438a8d49"
chai@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
dependencies:
assertion-error "^1.0.1"
check-error "^1.0.1"
deep-eql "^3.0.0"
get-func-name "^2.0.0"
pathval "^1.0.0"
type-detect "^4.0.0"
chalk@^2.0.1, chalk@^2.1.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
check-error@^1.0.1, check-error@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
dependencies:
restore-cursor "^2.0.0"
cli-spinners@^1.0.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-1.3.1.tgz#002c1990912d0d59580c93bd36c056de99e4259a"
color-convert@^1.9.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.1.tgz#c1261107aeb2f294ebffec9ed9ecad529a6097ed"
dependencies:
color-name "^1.1.1"
color-name@^1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
deep-eql@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
dependencies:
type-detect "^4.0.0"
define-properties@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
dependencies:
foreach "^2.0.5"
object-keys "^1.0.8"
early@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/early/-/early-2.1.1.tgz#841e23254ea5dc54d8afaeee82f5ab65c00ee23c"
dependencies:
beautycolor "^1.0.7"
smartq "^1.1.1"
typings-global "^1.0.16"
es-abstract@^1.5.1:
version "1.11.0"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.11.0.tgz#cce87d518f0496893b1a30cd8461835535480681"
dependencies:
es-to-primitive "^1.1.1"
function-bind "^1.1.1"
has "^1.0.1"
is-callable "^1.1.3"
is-regex "^1.0.4"
es-to-primitive@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.1.1.tgz#45355248a88979034b6792e19bb81f2b7975dd0d"
dependencies:
is-callable "^1.1.1"
is-date-object "^1.0.1"
is-symbol "^1.0.1"
es6-error@^4.0.2:
version "4.1.1"
resolved "https://registry.yarnpkg.com/es6-error/-/es6-error-4.1.1.tgz#9e3af407459deed47e9a91f9b885a84eb05c561d"
escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
figlet@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/figlet/-/figlet-1.2.0.tgz#6c46537378fab649146b5a6143dda019b430b410"
foreach@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
function-bind@^1.0.2, function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
get-func-name@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
has@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28"
dependencies:
function-bind "^1.0.2"
is-callable@^1.1.1, is-callable@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
is-date-object@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16"
is-regex@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491"
dependencies:
has "^1.0.1"
is-symbol@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572"
leakage@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/leakage/-/leakage-0.3.0.tgz#15d698abdc76bbc6439601f4f3020e77e2d50c39"
dependencies:
es6-error "^4.0.2"
left-pad "^1.1.3"
memwatch-next "^0.3.0"
minimist "^1.2.0"
pretty-bytes "^4.0.2"
left-pad@^1.1.3:
version "1.3.0"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
lodash@^4.17.4:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
log-symbols@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
dependencies:
chalk "^2.0.1"
memwatch-next@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/memwatch-next/-/memwatch-next-0.3.0.tgz#2111050f9a906e0aa2d72a4ec0f0089c78726f8f"
dependencies:
bindings "^1.2.1"
nan "^2.3.2"
mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
minimist@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
nan@^2.3.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
object.getownpropertydescriptors@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16"
dependencies:
define-properties "^1.1.2"
es-abstract "^1.5.1"
onetime@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4"
dependencies:
mimic-fn "^1.0.0"
ora@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/ora/-/ora-1.4.0.tgz#884458215b3a5d4097592285f93321bb7a79e2e5"
dependencies:
chalk "^2.1.0"
cli-cursor "^2.1.0"
cli-spinners "^1.0.1"
log-symbols "^2.1.0"
pathval@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
pretty-bytes@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-4.0.2.tgz#b2bf82e7350d65c6c33aa95aaa5a4f6327f61cd9"
restore-cursor@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
dependencies:
onetime "^2.0.0"
signal-exit "^3.0.2"
signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
smartchai@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/smartchai/-/smartchai-2.0.1.tgz#d20f17221f0e3c6c3473600b78ddfba0ab0ea762"
dependencies:
"@types/chai" "^4.1.2"
"@types/chai-as-promised" "^7.1.0"
"@types/chai-string" "^1.4.0"
chai "^4.1.2"
chai-as-promised "^7.1.1"
chai-string "^1.4.0"
smartdelay@^1.0.3, smartdelay@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.4.tgz#791c1a4ee6770494064c10b1d2d2b8e6f3105b82"
dependencies:
smartq "^1.1.1"
typings-global "^1.0.16"
smartenv@^2.0.0:
version "2.0.6"
resolved "https://registry.yarnpkg.com/smartenv/-/smartenv-2.0.6.tgz#b38c679b0c151b9af548f68c3a072c29d1417e8d"
dependencies:
lodash "^4.17.4"
smartq "^1.1.1"
typings-global "^1.0.14"
smartq@^1.1.1, smartq@^1.1.8:
version "1.1.8"
resolved "https://registry.yarnpkg.com/smartq/-/smartq-1.1.8.tgz#7e2f3b9739eb5d6c9f45f2a86e339ec81e49e8d2"
dependencies:
util.promisify "^1.0.0"
supports-color@^5.3.0:
version "5.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
dependencies:
has-flag "^3.0.0"
tapbundle@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-2.0.0.tgz#79fce68ff185c786fabaf6eb589a4afc7d2714b7"
dependencies:
early "^2.1.1"
leakage "^0.3.0"
smartchai "^2.0.0"
smartdelay "^1.0.3"
smartq "^1.1.1"
type-detect@^4.0.0:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
typings-global@^1.0.14, typings-global@^1.0.16:
version "1.0.28"
resolved "https://registry.yarnpkg.com/typings-global/-/typings-global-1.0.28.tgz#e28cc965476564cbc00e438739e0aa0735d323d4"
util.promisify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/util.promisify/-/util.promisify-1.0.0.tgz#440f7165a459c9a16dc145eb8e72f35687097030"
dependencies:
define-properties "^1.1.2"
object.getownpropertydescriptors "^2.0.3"