Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
97c57b2865 | |||
e04485231d | |||
228bc88d60 | |||
811041b036 | |||
a1203366d7 | |||
0deb77cda8 | |||
ed8b7ec65a | |||
6cfc12f83f | |||
efd9bbb77a | |||
b463aea274 | |||
c8cf590a5a | |||
42f679ef61 | |||
0cb882bb7d | |||
66f817cdf8 | |||
5925c882c8 | |||
6f09a82eee | |||
e23579709a | |||
929e4152d3 | |||
d0527affc2 | |||
f2ebaf74d9 | |||
b6d8c36f3e | |||
587600d571 | |||
17f293ca4e |
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,4 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
pages/
|
|
||||||
public/
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
149
.gitlab-ci.yml
149
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -18,127 +18,114 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
sast:
|
|
||||||
stage: security
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay2
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
|
|
||||||
--volume "$PWD:/code"
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
|
|
||||||
artifacts:
|
|
||||||
reports:
|
|
||||||
sast: gl-sast-report.json
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
testBuild:
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
only:
|
||||||
- docker:stable-dind
|
- tags
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -146,5 +133,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal 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
26
.vscode/settings.json
vendored
Normal 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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,6 +1,14 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
"compliance": "standard"
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartdns",
|
||||||
|
"shortDescription": "smart dns methods written in TypeScript",
|
||||||
|
"npmPackagename": "@pushrocks/smartdns",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
|
11595
package-lock.json
generated
11595
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdns",
|
"name": "@pushrocks/smartdns",
|
||||||
"version": "3.0.5",
|
"version": "4.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "smart dns methods written in TypeScript",
|
"description": "smart dns methods written in TypeScript",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,15 +25,34 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.2",
|
"@pushrocks/smartdelay": "^2.0.10",
|
||||||
"@pushrocks/smartpromise": "^2.0.5"
|
"@pushrocks/smartenv": "^4.0.16",
|
||||||
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
|
"@tsclass/tsclass": "^3.0.21",
|
||||||
|
"dns2": "^1.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.4",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
"@gitzone/tstest": "^1.0.18",
|
"@gitzone/tstest": "^1.0.43",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^10.12.18",
|
"@types/node": "^14.0.27",
|
||||||
"tslint": "^5.12.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.17.0"
|
"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"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
62
readme.md
62
readme.md
@ -1,43 +1,53 @@
|
|||||||
# @pushrocks/smartdns
|
# @pushrocks/smartdns
|
||||||
|
|
||||||
smart dns methods written in TypeScript
|
smart dns methods written in TypeScript
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdns)
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartdns)
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartdns)
|
||||||
[](https://GitLab.com/pushrocks/smartdns)
|
* [github.com (source mirror)](https://github.com/pushrocks/smartdns)
|
||||||
[](https://github.com/pushrocks/smartdns)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdns/)
|
||||||
[](https://pushrocks.gitlab.io/smartdns/)
|
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartdns/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://GitLab.com/pushrocks/smartdns/commits/master)
|
-- | --
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartdns)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://david-dm.org/pushrocks/smartdns)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartdns/master/dependencies/npm)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://www.bithound.io/github/pushrocks/smartdns)
|
Snyk | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
[](http://standardjs.com/)
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
let myDnsly = new dnsly.Dnsly('google'); // uses Google DNS Servers e.g 8.8.8.8
|
const mySmartDns = new smartdns.SmartDns(); // uses Google DNS Https API
|
||||||
myDnsly
|
const demoRecord = await mySmartDns.getRecord('example.com', 'AAAA'); // returns promise
|
||||||
.getRecord('example.com', 'AAAA') // returns promise
|
/*
|
||||||
.then((record: dnsly.I_AAAA) => {
|
demoRecord looks like this:
|
||||||
// AAAA record for google.com, the I_AAAA will give you proper typings for the record return type
|
{
|
||||||
// do something
|
name: 'example.com',
|
||||||
});
|
type: 'A',
|
||||||
|
dnsSecEnabled: true,
|
||||||
|
value: '104.24.103.243'
|
||||||
|
}
|
||||||
|
*/
|
||||||
```
|
```
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
## 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)
|
> 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)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://maintainedby.lossless.com)
|
||||||
|
24
test/test.ts
24
test/test.ts
@ -5,7 +5,7 @@ import * as smartdns from '../ts/index';
|
|||||||
let testDnsly: smartdns.Smartdns;
|
let testDnsly: smartdns.Smartdns;
|
||||||
|
|
||||||
tap.test('should create an instance of Dnsly', async () => {
|
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);
|
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',
|
name: 'dnsly_a.bleu.de',
|
||||||
value: '127.0.0.1',
|
value: '127.0.0.1',
|
||||||
type: 'A'
|
dnsSecEnabled: false,
|
||||||
}
|
type: 'A',
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -24,19 +25,20 @@ tap.test('should get an AAAA Record', async () => {
|
|||||||
{
|
{
|
||||||
name: 'dnsly_aaaa.bleu.de',
|
name: 'dnsly_aaaa.bleu.de',
|
||||||
value: '::1',
|
value: '::1',
|
||||||
type: 'AAAA'
|
dnsSecEnabled: false,
|
||||||
}
|
type: 'AAAA',
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get a txt record', async () => {
|
tap.test('should get a txt record', async () => {
|
||||||
return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([
|
return expect(testDnsly.getRecordTxt('dnsly_txt.bleu.de')).to.eventually.deep.equal([
|
||||||
{
|
{
|
||||||
chunked: ['sometext_txt'],
|
|
||||||
name: 'dnsly_txt.bleu.de',
|
name: 'dnsly_txt.bleu.de',
|
||||||
value: 'sometext_txt',
|
value: 'sometext_txt',
|
||||||
type: 'TXT'
|
type: 'TXT',
|
||||||
}
|
dnsSecEnabled: false,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -65,4 +67,10 @@ tap.test('should get name server for hostname', async () => {
|
|||||||
console.log(result);
|
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();
|
tap.start();
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
import * as dns from 'dns';
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
|
const smartenvInstance = new smartenv.Smartenv();
|
||||||
|
// node native scope
|
||||||
|
import type dnsType from 'dns';
|
||||||
|
const dns: typeof dnsType = smartenvInstance.getSafeNodeModule('dns');
|
||||||
|
|
||||||
|
export { dns };
|
||||||
|
|
||||||
|
// pushrocks scope
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
export { dns, smartdelay, smartpromise };
|
export { smartdelay, smartenv, smartpromise, smartrequest };
|
||||||
|
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export { tsclass };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
|
||||||
|
const dns2 = smartenvInstance.getSafeNodeModule('dns2');
|
||||||
|
|
||||||
|
export {
|
||||||
|
dns2
|
||||||
|
}
|
||||||
|
189
ts/index.ts
189
ts/index.ts
@ -1,37 +1,41 @@
|
|||||||
import * as plugins from './dnsly.plugins';
|
import * as plugins from './dnsly.plugins';
|
||||||
|
|
||||||
export type TDnsProvider = 'google';
|
export type TDnsProvider = 'google' | 'cloudflare';
|
||||||
export type TDnsRecordType =
|
|
||||||
| 'A'
|
|
||||||
| 'AAAA'
|
|
||||||
| 'CNAME'
|
|
||||||
| 'PTR'
|
|
||||||
| 'MX'
|
|
||||||
| 'NAPTR'
|
|
||||||
| 'NS'
|
|
||||||
| 'SOA'
|
|
||||||
| 'SRV'
|
|
||||||
| 'TXT';
|
|
||||||
|
|
||||||
export interface IDnsRecord {
|
export interface ISmartDnsConstructorOptions {}
|
||||||
chunked?: string[];
|
|
||||||
name: string;
|
export interface IGoogleDNSHTTPSResponse {
|
||||||
type: TDnsRecordType;
|
Status: number;
|
||||||
value: string;
|
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
|
* class dnsly offers methods for working with dns from a dns provider like Google DNS
|
||||||
*/
|
*/
|
||||||
export class Smartdns {
|
export class Smartdns {
|
||||||
dnsServerIp: string;
|
public dnsServerIp: string;
|
||||||
dnsServerPort: number;
|
public dnsServerPort: number;
|
||||||
|
|
||||||
|
public dnsTypeMap: { [key: string]: number } = {
|
||||||
|
A: 1,
|
||||||
|
AAAA: 28,
|
||||||
|
CNAME: 5,
|
||||||
|
MX: 15,
|
||||||
|
TXT: 16,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor for class dnsly
|
* constructor for class dnsly
|
||||||
*/
|
*/
|
||||||
constructor(dnsProviderArg: TDnsProvider = 'google') {
|
constructor(optionsArg: ISmartDnsConstructorOptions) {}
|
||||||
this._setDnsProvider(dnsProviderArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check a dns record until it has propagated to Google DNS
|
* check a dns record until it has propagated to Google DNS
|
||||||
@ -40,30 +44,43 @@ export class Smartdns {
|
|||||||
* @param recordTypeArg
|
* @param recordTypeArg
|
||||||
* @param expectedValue
|
* @param expectedValue
|
||||||
*/
|
*/
|
||||||
async checkUntilAvailable(
|
public async checkUntilAvailable(
|
||||||
recordNameArg: string,
|
recordNameArg: string,
|
||||||
recordTypeArg: TDnsRecordType,
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType,
|
||||||
expectedValue: string
|
expectedValue: string,
|
||||||
|
cyclesArg: number = 50,
|
||||||
|
intervalArg: number = 500
|
||||||
) {
|
) {
|
||||||
let cycleArg = 0;
|
let runCycles = 0;
|
||||||
let doCheck = async () => {
|
const doCheck = async () => {
|
||||||
if (cycleArg < 30) {
|
if (runCycles < cyclesArg) {
|
||||||
cycleArg++;
|
runCycles++;
|
||||||
try {
|
try {
|
||||||
let myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
|
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
|
||||||
let myRecord = myRecordArray[0].value[0];
|
if (runCycles % 2 === 0 || !plugins.dns) {
|
||||||
|
myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
|
||||||
|
} else {
|
||||||
|
myRecordArray = await this.getRecordWithNodeDNS(recordNameArg, recordTypeArg);
|
||||||
|
}
|
||||||
|
const myRecord = myRecordArray[0].value;
|
||||||
if (myRecord === expectedValue) {
|
if (myRecord === expectedValue) {
|
||||||
|
console.log(
|
||||||
|
`smartdns: .checkUntilAvailable() verified that wanted >>>${recordTypeArg}<<< record exists for >>>${recordNameArg}<<< with value >>>${expectedValue}<<<`
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
await plugins.smartdelay.delayFor(2000);
|
await plugins.smartdelay.delayFor(intervalArg);
|
||||||
return await doCheck();
|
return await doCheck();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await plugins.smartdelay.delayFor(2000);
|
// console.log(err);
|
||||||
|
await plugins.smartdelay.delayFor(intervalArg);
|
||||||
return await doCheck();
|
return await doCheck();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('failed permanently...');
|
console.log(
|
||||||
|
`smartdns: .checkUntilAvailable() failed permanently for ${recordNameArg} with value ${recordTypeArg} - ${expectedValue}...`
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -73,67 +90,84 @@ export class Smartdns {
|
|||||||
/**
|
/**
|
||||||
* get A Dns Record
|
* 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');
|
return await this.getRecord(recordNameArg, 'A');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get AAAA Record
|
* get AAAA Record
|
||||||
*/
|
*/
|
||||||
async getRecordAAAA(recordNameArg: string) {
|
public async getRecordAAAA(recordNameArg: string) {
|
||||||
return await this.getRecord(recordNameArg, 'AAAA');
|
return await this.getRecord(recordNameArg, 'AAAA');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets a txt record
|
* gets a txt record
|
||||||
*/
|
*/
|
||||||
getRecordTxt(recordNameArg: string): Promise<IDnsRecord[]> {
|
public async getRecordTxt(recordNameArg: string): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
let done = plugins.smartpromise.defer<IDnsRecord[]>();
|
return await this.getRecord(recordNameArg, 'TXT');
|
||||||
plugins.dns.resolveTxt(recordNameArg, (err, recordsArg) => {
|
}
|
||||||
if (err) {
|
|
||||||
done.reject(err);
|
public async getRecord(
|
||||||
return;
|
recordNameArg: string,
|
||||||
}
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
||||||
let responseArray: IDnsRecord[] = [];
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
for (let record of recordsArg) {
|
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
|
||||||
let recordAny: any = record; // fix wrong typings
|
const response = await plugins.smartrequest.request(requestUrl, {
|
||||||
responseArray.push({
|
method: 'GET',
|
||||||
chunked: recordAny,
|
headers: {
|
||||||
name: recordNameArg,
|
accept: 'application/dns-json',
|
||||||
value: recordAny.join(' '),
|
},
|
||||||
type: 'TXT'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
done.resolve(responseArray);
|
|
||||||
});
|
});
|
||||||
return done.promise;
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// console.log(responseBody);
|
||||||
|
return returnArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get oridinary record
|
* gets a record using nodejs dns resolver
|
||||||
*/
|
*/
|
||||||
getRecord(recordNameArg: string, recordTypeArg: TDnsRecordType): Promise<IDnsRecord[]> {
|
public async getRecordWithNodeDNS(
|
||||||
let done = plugins.smartpromise.defer<IDnsRecord[]>();
|
recordNameArg: string,
|
||||||
|
recordTypeArg: plugins.tsclass.network.TDnsRecordType
|
||||||
|
): Promise<plugins.tsclass.network.IDnsRecord[]> {
|
||||||
|
const done = plugins.smartpromise.defer<plugins.tsclass.network.IDnsRecord[]>();
|
||||||
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
plugins.dns.resolve(recordNameArg, recordTypeArg, (err, recordsArg) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
done.reject(err);
|
done.reject(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let responseArray: IDnsRecord[] = [];
|
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
|
||||||
for (let recordKey in recordsArg) {
|
for (const recordKey in recordsArg) {
|
||||||
responseArray.push({
|
returnArray.push({
|
||||||
name: recordNameArg,
|
name: recordNameArg,
|
||||||
value: recordsArg[recordKey],
|
value: recordsArg[recordKey][0],
|
||||||
type: recordTypeArg
|
type: recordTypeArg,
|
||||||
|
dnsSecEnabled: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
done.resolve(responseArray);
|
done.resolve(returnArray);
|
||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
getNameServer(domainNameArg: string) {
|
public async getNameServer(domainNameArg: string): Promise<string[]> {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer<string[]>();
|
||||||
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
plugins.dns.resolveNs(domainNameArg, (err, result) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
done.resolve(result);
|
done.resolve(result);
|
||||||
@ -142,18 +176,21 @@ export class Smartdns {
|
|||||||
done.reject(err);
|
done.reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return await done.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public convertDnsTypeNameToTypeNumber(dnsTypeNameArg: string): number {
|
||||||
* set the DNS provider
|
return this.dnsTypeMap[dnsTypeNameArg];
|
||||||
*/
|
}
|
||||||
private _setDnsProvider(dnsProvider: TDnsProvider) {
|
|
||||||
if (dnsProvider === 'google') {
|
public convertDnsTypeNumberToTypeName(
|
||||||
this.dnsServerIp = '8.8.8.8';
|
dnsTypeNumberArg: number
|
||||||
this.dnsServerPort = 53;
|
): plugins.tsclass.network.TDnsRecordType {
|
||||||
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']);
|
for (const key in this.dnsTypeMap) {
|
||||||
} else {
|
if (this.dnsTypeMap[key] === dnsTypeNumberArg) {
|
||||||
throw new Error('unknown dns provider');
|
return key as plugins.tsclass.network.TDnsRecordType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user