Compare commits

...

18 Commits

Author SHA1 Message Date
e02b2253f5 4.0.11 2022-07-27 08:59:29 +02:00
862577745d fix(core): update 2022-07-27 08:59:29 +02:00
ca72206ab4 4.0.10 2021-08-24 11:41:22 +02:00
0221c3207e fix(core): update 2021-08-24 11:41:22 +02:00
f2b8fa57af 4.0.9 2021-08-24 11:40:44 +02:00
e5b072d99b fix(core): update 2021-08-24 11:40:44 +02:00
97c57b2865 4.0.8 2021-01-22 23:24:03 +00:00
e04485231d fix(core): update 2021-01-22 23:24:02 +00:00
228bc88d60 4.0.7 2021-01-22 22:40:17 +00:00
811041b036 fix(core): update 2021-01-22 22:40:16 +00:00
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
14 changed files with 14290 additions and 1097 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -12,29 +12,35 @@ stages:
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci git mirror
- 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:
- lossless
- docker
- notpriv
allow_failure: true
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- 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:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -49,9 +55,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -62,9 +66,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -84,11 +86,12 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -108,11 +111,10 @@ trigger:
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
- npmci command npm run buildDocs
tags:
- lossless
- docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"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"
"type": "node-terminal"
}
]
}

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

View File

@ -5,7 +5,7 @@
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartdns",
"shortDescription": "smart dns methods written in TypeScript",
"description": "smart dns methods written in TypeScript",
"npmPackagename": "@pushrocks/smartdns",
"license": "MIT"
}

15107
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
{
"name": "@pushrocks/smartdns",
"version": "4.0.2",
"version": "4.0.11",
"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)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -25,28 +26,35 @@
},
"homepage": "https://gitlab.com/pushrocks/dnsly#README",
"dependencies": {
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47",
"@tsclass/tsclass": "^3.0.6"
"@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.17",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^13.7.1",
"tslint": "^6.0.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_web/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
}

View File

@ -8,13 +8,20 @@ smart dns methods written in TypeScript
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdns/)
## Status for master
[![pipeline status](https://gitlab.com/pushrocks/smartdns/badges/master/pipeline.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)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartdns/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartdns)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
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

View File

@ -1,44 +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({});
expect(testDnsly).to.be.instanceOf(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',
dnsSecEnabled: false,
type: 'A'
}
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',
dnsSecEnabled: false,
type: 'AAAA'
}
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([
{
name: 'dnsly_txt.bleu.de',
value: 'sometext_txt',
type: 'TXT',
dnsSecEnabled: false
}
dnsSecEnabled: false,
},
]);
});
@ -48,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 () => {
@ -70,7 +67,7 @@ tap.test('should get name server for hostname', async () => {
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;
expect(result[0].dnsSecEnabled).toBeTrue();
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartdns',
version: '4.0.11',
description: 'smart dns methods written in TypeScript'
}

View File

@ -1,5 +1,8 @@
import * as smartenv from '@pushrocks/smartenv';
const smartenvInstance = new smartenv.Smartenv();
// node native scope
import * as dns from 'dns';
import type dnsType from 'dns';
const dns: typeof dnsType = await smartenvInstance.getSafeNodeModule('dns');
export { dns };
@ -8,8 +11,12 @@ import * as smartdelay from '@pushrocks/smartdelay';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
export { smartdelay, smartpromise, smartrequest };
export { smartdelay, smartenv, smartpromise, smartrequest };
import * as tsclass from '@tsclass/tsclass';
export { tsclass };
// third party scope
const dns2 = smartenvInstance.getSafeNodeModule('dns2');
export { dns2 };

View File

@ -1,7 +1,27 @@
import * as plugins from './dnsly.plugins';
import * as plugins from './dnsly.plugins.js';
export type TDnsProvider = 'google' | 'cloudflare';
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 {
@ -29,7 +49,7 @@ export class Smartdns {
AAAA: 28,
CNAME: 5,
MX: 15,
TXT: 16
TXT: 16,
};
/**
@ -56,20 +76,31 @@ export class Smartdns {
if (runCycles < cyclesArg) {
runCycles++;
try {
const myRecordArray = await this.getRecord(recordNameArg, recordTypeArg);
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(intervalArg);
return await doCheck();
}
} catch (err) {
// 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;
}
};
@ -101,9 +132,12 @@ export class Smartdns {
recordNameArg: string,
recordTypeArg: plugins.tsclass.network.TDnsRecordType
): Promise<plugins.tsclass.network.IDnsRecord[]> {
const requestUrl = `https://dns.google/resolve?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
const requestUrl = `https://cloudflare-dns.com/dns-query?name=${recordNameArg}&type=${recordTypeArg}&do=1`;
const response = await plugins.smartrequest.request(requestUrl, {
method: 'GET'
method: 'GET',
headers: {
accept: 'application/dns-json',
},
});
const returnArray: plugins.tsclass.network.IDnsRecord[] = [];
const responseBody: IGoogleDNSHTTPSResponse = response.body;
@ -118,7 +152,7 @@ export class Smartdns {
name: dnsEntry.name,
type: this.convertDnsTypeNumberToTypeName(dnsEntry.type),
dnsSecEnabled: responseBody.AD,
value: dnsEntry.data
value: dnsEntry.data,
});
}
// console.log(responseBody);
@ -142,9 +176,9 @@ export class Smartdns {
for (const recordKey in recordsArg) {
returnArray.push({
name: recordNameArg,
value: recordsArg[recordKey],
value: recordsArg[recordKey][0],
type: recordTypeArg,
dnsSecEnabled: false
dnsSecEnabled: false,
});
}
done.resolve(returnArray);
@ -165,26 +199,6 @@ export class Smartdns {
return await done.promise;
}
/**
* set the DNS provider
*/
public setNodeDnsProvider(dnsProvider: TDnsProvider) {
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.dnsServerPort = 53;
plugins.dns.setServers(['8.8.8.8', '8.8.4.4']);
} else if (dnsProvider === 'cloudflare') {
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];
}

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

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