Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
dd8c97b99a | |||
9c56dc51e3 | |||
45cbd3a953 | |||
d3e2655212 | |||
e02b2253f5 | |||
862577745d | |||
ca72206ab4 | |||
0221c3207e | |||
f2b8fa57af | |||
e5b072d99b | |||
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/
|
||||
pages/
|
||||
public/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
114
.gitlab-ci.yml
114
.gitlab-ci.yml
@ -1,81 +1,52 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- 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
|
||||
- notpriv
|
||||
|
||||
sast:
|
||||
stage: security
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay2
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
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
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- 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
|
||||
@ -85,7 +56,17 @@ testSTABLE:
|
||||
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
|
||||
@ -95,6 +76,7 @@ release:
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
@ -103,20 +85,15 @@ 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 typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
@ -127,18 +104,19 @@ trigger:
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
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": {
|
||||
"compliance": "standard"
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartdns",
|
||||
"description": "smart dns methods written in TypeScript",
|
||||
"npmPackagename": "@pushrocks/smartdns",
|
||||
"license": "MIT"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
|
15151
package-lock.json
generated
15151
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "@pushrocks/smartdns",
|
||||
"version": "3.0.5",
|
||||
"version": "5.0.1",
|
||||
"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": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -25,15 +26,35 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^2.0.2",
|
||||
"@pushrocks/smartpromise": "^2.0.5"
|
||||
"@pushrocks/smartdelay": "^2.0.13",
|
||||
"@pushrocks/smartenv": "^5.0.2",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartrequest": "^1.1.56",
|
||||
"@tsclass/tsclass": "^4.0.17",
|
||||
"dns2": "^2.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.4",
|
||||
"@gitzone/tstest": "^1.0.18",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.18",
|
||||
"tslint": "^5.12.0",
|
||||
"tslint-config-prettier": "^1.17.0"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.1",
|
||||
"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"
|
||||
],
|
||||
"type": "module"
|
||||
}
|
||||
|
62
readme.md
62
readme.md
@ -1,43 +1,53 @@
|
||||
# @pushrocks/smartdns
|
||||
|
||||
smart dns methods written in TypeScript
|
||||
|
||||
## Availabililty
|
||||
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartdns)
|
||||
[](https://GitLab.com/pushrocks/smartdns)
|
||||
[](https://github.com/pushrocks/smartdns)
|
||||
[](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
|
||||
|
||||
[](https://GitLab.com/pushrocks/smartdns/commits/master)
|
||||
[](https://GitLab.com/pushrocks/smartdns/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartdns)
|
||||
[](https://david-dm.org/pushrocks/smartdns)
|
||||
[](https://www.bithound.io/github/pushrocks/smartdns/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartdns)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
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
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```typescript
|
||||
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
|
||||
});
|
||||
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'
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
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)
|
||||
> | 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)
|
||||
|
43
test/test.ts
43
test/test.ts
@ -1,42 +1,44 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartdns from '../ts/index';
|
||||
import * as smartdns from '../ts/index.js';
|
||||
|
||||
let testDnsly: smartdns.Smartdns;
|
||||
|
||||
tap.test('should create an instance of Dnsly', async () => {
|
||||
testDnsly = new smartdns.Smartdns('google');
|
||||
expect(testDnsly).to.be.instanceOf(smartdns.Smartdns);
|
||||
testDnsly = new smartdns.Smartdns({});
|
||||
expect(testDnsly).toBeInstanceOf(smartdns.Smartdns);
|
||||
});
|
||||
|
||||
tap.test('should get an A DNS Record', async () => {
|
||||
return expect(testDnsly.getRecordA('dnsly_a.bleu.de')).to.eventually.deep.equal([
|
||||
return expect(await testDnsly.getRecordA('dnsly_a.bleu.de')).toEqual([
|
||||
{
|
||||
name: 'dnsly_a.bleu.de',
|
||||
value: '127.0.0.1',
|
||||
type: 'A'
|
||||
}
|
||||
dnsSecEnabled: false,
|
||||
type: 'A',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
tap.test('should get an AAAA Record', async () => {
|
||||
return expect(testDnsly.getRecordAAAA('dnsly_aaaa.bleu.de')).to.eventually.deep.equal([
|
||||
return expect(await testDnsly.getRecordAAAA('dnsly_aaaa.bleu.de')).toEqual([
|
||||
{
|
||||
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([
|
||||
return expect(await testDnsly.getRecordTxt('dnsly_txt.bleu.de')).toEqual([
|
||||
{
|
||||
chunked: ['sometext_txt'],
|
||||
name: 'dnsly_txt.bleu.de',
|
||||
value: 'sometext_txt',
|
||||
type: 'TXT'
|
||||
}
|
||||
type: 'TXT',
|
||||
dnsSecEnabled: false,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@ -46,18 +48,15 @@ tap.test('should, get a mx record for a domain', async () => {
|
||||
});
|
||||
|
||||
tap.test('should check until DNS is available', async () => {
|
||||
return expect(testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt')).to
|
||||
.eventually.be.true;
|
||||
return expect(await testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt')).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should check until DNS is available an return false if it fails', async () => {
|
||||
return expect(testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2')).to
|
||||
.eventually.be.false;
|
||||
return expect(await testDnsly.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2')).toBeFalse()
|
||||
});
|
||||
|
||||
tap.test('should check until DNS is available an return false if it fails', async () => {
|
||||
return expect(testDnsly.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2'))
|
||||
.to.eventually.be.false;
|
||||
return expect(await testDnsly.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2')).toBeFalse()
|
||||
});
|
||||
|
||||
tap.test('should get name server for hostname', async () => {
|
||||
@ -65,4 +64,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).toBeTrue();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartdns',
|
||||
version: '5.0.1',
|
||||
description: 'smart dns methods written in TypeScript'
|
||||
}
|
@ -1,5 +1,22 @@
|
||||
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 = await smartenvInstance.getSafeNodeModule('dns');
|
||||
|
||||
export { dns };
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
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 };
|
||||
|
207
ts/index.ts
207
ts/index.ts
@ -1,37 +1,61 @@
|
||||
import * as plugins from './dnsly.plugins';
|
||||
import * as plugins from './dnsly.plugins.js';
|
||||
|
||||
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 const makeNodeProcessUseDnsProvider = async (providerArg: TDnsProvider) => {
|
||||
switch (providerArg) {
|
||||
case 'cloudflare':
|
||||
plugins.dns.setServers([
|
||||
'1.1.1.1',
|
||||
'1.0.0.1',
|
||||
'[2606:4700:4700::1111]',
|
||||
'[2606:4700:4700::1001]',
|
||||
]);
|
||||
break;
|
||||
case 'google':
|
||||
plugins.dns.setServers([
|
||||
'8.8.8.8',
|
||||
'8.8.4.4',
|
||||
'[2001:4860:4860::8888]',
|
||||
'[2606:4700:4700::1001]',
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
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) {}
|
||||
|
||||
/**
|
||||
* check a dns record until it has propagated to Google DNS
|
||||
@ -40,30 +64,43 @@ export class Smartdns {
|
||||
* @param recordTypeArg
|
||||
* @param expectedValue
|
||||
*/
|
||||
async checkUntilAvailable(
|
||||
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[0];
|
||||
let myRecordArray: plugins.tsclass.network.IDnsRecord[];
|
||||
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) {
|
||||
console.log(
|
||||
`smartdns: .checkUntilAvailable() verified that wanted >>>${recordTypeArg}<<< record exists for >>>${recordNameArg}<<< with value >>>${expectedValue}<<<`
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
await plugins.smartdelay.delayFor(2000);
|
||||
await plugins.smartdelay.delayFor(intervalArg);
|
||||
return await doCheck();
|
||||
}
|
||||
} catch (err) {
|
||||
await plugins.smartdelay.delayFor(2000);
|
||||
// console.log(err);
|
||||
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;
|
||||
}
|
||||
};
|
||||
@ -73,67 +110,84 @@ 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 = plugins.smartpromise.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 = plugins.smartpromise.defer<IDnsRecord[]>();
|
||||
public async getRecordWithNodeDNS(
|
||||
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) => {
|
||||
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 = plugins.smartpromise.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);
|
||||
@ -142,18 +196,21 @@ export class Smartdns {
|
||||
done.reject(err);
|
||||
}
|
||||
});
|
||||
return await done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the DNS provider
|
||||
*/
|
||||
private _setDnsProvider(dnsProvider: TDnsProvider) {
|
||||
if (dnsProvider === 'google') {
|
||||
this.dnsServerIp = '8.8.8.8';
|
||||
this.dnsServerPort = 53;
|
||||
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
Reference in New Issue
Block a user