Compare commits

...

25 Commits

Author SHA1 Message Date
d8044507ed 2.0.5 2021-04-27 09:46:32 +00:00
b9380be999 fix(core): update 2021-04-27 09:46:31 +00:00
1b9c354d69 2.0.4 2021-04-13 13:05:48 +00:00
a8f4ecf98f fix(core): update 2021-04-13 13:05:47 +00:00
6350088d2a 2.0.3 2021-04-13 10:29:43 +00:00
10ef1d0455 fix(core): update 2021-04-13 10:29:42 +00:00
f709238e50 2.0.2 2021-04-13 10:09:40 +00:00
49940635d5 fix(core): update 2021-04-13 10:09:39 +00:00
ec4121cbcf 2.0.1 2021-04-13 10:09:09 +00:00
ea9a2572f9 fix(core): update 2021-04-13 10:09:09 +00:00
cc0f1c40a6 2.0.0 2021-04-13 10:07:39 +00:00
9da04081e4 BREAKING CHANGE(core): update 2021-04-13 10:07:39 +00:00
4ae0925043 1.1.22 2020-08-13 02:34:06 +00:00
4e862e784b fix(core): update 2020-08-13 02:34:06 +00:00
cf8abfd4f0 1.1.21 2020-08-13 02:29:10 +00:00
93c4488b9b fix(core): update 2020-08-13 02:29:09 +00:00
39493465c6 1.1.20 2020-08-12 16:30:18 +00:00
cab696e45b fix(core): update 2020-08-12 16:30:17 +00:00
67682892ae 1.1.19 2020-08-12 16:29:04 +00:00
5c13987686 fix(core): update 2020-08-12 16:29:03 +00:00
97841e0973 1.1.18 2019-11-23 19:33:49 +00:00
c8ccde9d84 1.1.17 2019-11-23 16:07:05 +00:00
654a4c6b54 fix(core): update 2019-11-23 16:07:04 +00:00
12b8793c19 1.1.16 2019-11-19 23:01:22 +00:00
24e861e5b4 fix(security): add snyk config 2019-11-19 23:01:21 +00:00
12 changed files with 12147 additions and 998 deletions

4
.gitignore vendored
View File

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

View File

@ -19,22 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk 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 --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:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -49,9 +62,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -62,9 +73,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -84,6 +93,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

4
.snyk Normal file
View File

@ -0,0 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.13.5
ignore: {}
patch: {}

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

@ -4,6 +4,7 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",

12894
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +1,46 @@
{ {
"name": "@pushrocks/smartnetwork", "name": "@pushrocks/smartnetwork",
"version": "1.1.15", "version": "2.0.5",
"private": false, "private": false,
"description": "network diagnostics", "description": "network diagnostics",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)" "build": "(tsbuild --web)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.0", "@pushrocks/tapbundle": "^3.2.14",
"tslint": "^5.20.1", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartstring": "^3.0.14", "@pushrocks/smartstring": "^3.0.24",
"@types/default-gateway": "^3.0.0", "@types/default-gateway": "^3.0.1",
"@types/portscanner": "^2.1.0", "isopen": "^1.3.0",
"default-gateway": "^5.0.5", "public-ip": "^4.0.3",
"portscanner": "^2.2.0", "speed-cloudflare-cli": "^2.0.3",
"speedtest-net": "^1.6.0", "speedtest-net": "^2.1.1",
"systeminformation": "^4.15.3" "systeminformation": "^5.6.12"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@ -8,13 +8,20 @@ network diagnostics
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnetwork/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartnetwork/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartnetwork/badges/master/build.svg)](https://gitlab.com/pushrocks/smartnetwork/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartnetwork/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartnetwork/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartnetwork.svg)](https://www.npmjs.com/package/@pushrocks/smartnetwork) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartnetwork/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartnetwork) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartnetwork/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartnetwork/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartnetwork)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartnetwork)](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/smartnetwork)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartnetwork)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartnetwork)](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 ## Usage

View File

@ -9,13 +9,13 @@ tap.test('should create a valid instance of SmartNetwork', async () => {
}); });
tap.test('should perform a speedtest', async () => { tap.test('should perform a speedtest', async () => {
let result = await testSmartNetwork.getSpeed(); const result = await testSmartNetwork.getSpeed();
console.log(`Download speed for this instance is ${result.speeds.download}`); // console.log(`Download speed for this instance is ${result.download.bandwidth}`);
console.log(`Upload speed for this instance is ${result.speeds.upload}`); // console.log(`Upload speed for this instance is ${result.download.bandwidth}`);
}); });
tap.test('should determine wether a port is free', async () => { tap.test('should determine wether a port is free', async () => {
await expect(testSmartNetwork.isLocalPortAvailable(8080)).to.eventually.be.true; await expect(testSmartNetwork.isLocalPortUnused(8080)).to.eventually.be.true;
}); });
tap.test('should scan a port', async () => { tap.test('should scan a port', async () => {
@ -34,4 +34,9 @@ tap.test('should get the default gateway', async () => {
console.log(gatewayResult); console.log(gatewayResult);
}); });
tap.test('should get public ips', async () => {
const ips = await testSmartNetwork.getPublicIps();
console.log(ips);
});
tap.start(); tap.start();

View File

@ -1,34 +1,31 @@
import * as plugins from './smartnetwork.plugins'; import * as plugins from './smartnetwork.plugins';
export interface ISpeedtestData { export interface ISpeedtestData {
speeds: { timestamp: Date;
download: number; ping: { jitter: number; latency: number };
upload: number; download: { bandwidth: number; bytes: number; elapsed: number };
originalDownload: number; upload: { bandwidth: number; bytes: number; elapsed: number };
originalUpload: number; packetLoss: number;
}; isp: string;
client: { interface: {
ip: string; internalIp: string;
lat: number; name: string;
lon: number; macAddr: string;
isp: string; isVpn: false;
isprating: string; externalIp: string;
rating: number;
ispdlavg: number;
ispulavg: number;
}; };
server: { server: {
host: string; id: number;
lat: number; name: string;
lon: number;
location: string; location: string;
country: string; country: string;
cc: string; host: string;
sponsor: string; port: number;
distance: number; ip: string;
distanceMi: number; };
ping: number; result: {
id: string; id: string;
url: string;
}; };
} }
@ -40,16 +37,9 @@ export class SmartNetwork {
* get network speed * get network speed
* @param measurementTime * @param measurementTime
*/ */
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> { public async getSpeed() {
const done = plugins.smartpromise.defer<ISpeedtestData>(); const test = null;
const test = plugins.speedtestNet({ maxTime: measurementTime }); return test;
test.on('data', data => {
done.resolve(data);
});
test.on('error', err => {
done.reject(err);
});
return await done.promise;
} }
/** /**
@ -57,7 +47,7 @@ export class SmartNetwork {
* note: false also resolves with false as argument * note: false also resolves with false as argument
* @param port * @param port
*/ */
public async isLocalPortAvailable(port: number): Promise<boolean> { public async isLocalPortUnused(port: number): Promise<boolean> {
const doneIpV4 = plugins.smartpromise.defer<boolean>(); const doneIpV4 = plugins.smartpromise.defer<boolean>();
const doneIpV6 = plugins.smartpromise.defer<boolean>(); const doneIpV6 = plugins.smartpromise.defer<boolean>();
const net = await import('net'); // creates only one instance of net ;) even on multiple calls const net = await import('net'); // creates only one instance of net ;) even on multiple calls
@ -83,7 +73,7 @@ export class SmartNetwork {
// test IPv6 space // test IPv6 space
const ipv6Test = net.createServer(); const ipv6Test = net.createServer();
ipv6Test.once('error', function(err: any) { ipv6Test.once('error', function (err: any) {
if (err.code !== 'EADDRINUSE') { if (err.code !== 'EADDRINUSE') {
doneIpV6.resolve(false); doneIpV6.resolve(false);
return; return;
@ -114,12 +104,9 @@ export class SmartNetwork {
const domainPart = domainArg.split(':')[0]; const domainPart = domainArg.split(':')[0];
const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10); const port = portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
plugins.portscanner.checkPortStatus(port, domainPart, (err, status) => { plugins.isopen(domainPart, port, (response) => {
if (err) { console.log(response);
// console.log(err); if (response[port.toString()].isOpen) {
return done.resolve(false);
}
if (status === 'open') {
done.resolve(true); done.resolve(true);
} else { } else {
done.resolve(false); done.resolve(false);
@ -147,7 +134,16 @@ export class SmartNetwork {
const defaultGateway = gateways[defaultGatewayName]; const defaultGateway = gateways[defaultGatewayName];
return { return {
ipv4: defaultGateway[0], ipv4: defaultGateway[0],
ipv6: defaultGateway[1] ipv6: defaultGateway[1],
};
}
public async getPublicIps() {
return {
v4: await plugins.publicIp.v4({
timeout: 1000,
onlyHttps: true,
}),
}; };
} }
} }

View File

@ -10,8 +10,8 @@ import * as smartstring from '@pushrocks/smartstring';
export { smartpromise, smartstring }; export { smartpromise, smartstring };
// @third party scope // @third party scope
import * as portscanner from 'portscanner'; import isopen from 'isopen';
import speedtestNet from 'speedtest-net'; import publicIp from 'public-ip';
import * as systeminformation from 'systeminformation'; import * as systeminformation from 'systeminformation';
export { speedtestNet, portscanner, systeminformation }; export { isopen, publicIp, systeminformation };