fix(core): update

This commit is contained in:
Philipp Kunz 2019-04-16 10:21:11 +02:00
parent e6e6d86c15
commit 9e18e2089f
12 changed files with 1345 additions and 436 deletions

View File

@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -36,21 +37,11 @@ snyk:
# ====================
# 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 npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
@ -62,6 +53,7 @@ testLTS:
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
@ -118,6 +110,7 @@ pages:
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
@ -130,13 +123,3 @@ pages:
paths:
- public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@ -4,5 +4,15 @@
"npmts"
],
"npmAccessLevel": "public"
},
"gitzone": {
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartnetwork",
"shortDescription": "network diagnostics",
"npmPackagename": "@pushrocks/smartnetwork",
"license": "MIT"
}
}
}
}

1307
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,11 +12,14 @@
"build": "(npmts)"
},
"devDependencies": {
"@gitzone/tsrun": "^1.1.9",
"@pushrocks/tapbundle": "^3.0.1"
"@gitzone/tsrun": "^1.2.5",
"@pushrocks/tapbundle": "^3.0.9"
},
"dependencies": {
"@pushrocks/smartpromise": "^2.0.5",
"speedtest-net": "^1.4.3"
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartstring": "^3.0.10",
"@types/portscanner": "^2.1.0",
"portscanner": "^2.2.0",
"speedtest-net": "^1.5.1"
}
}

32
readme.md Normal file
View File

@ -0,0 +1,32 @@
# @pushrocks/smartnetwork
network diagnostics
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartnetwork)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartnetwork)
* [github.com (source mirror)](https://github.com/pushrocks/smartnetwork)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartnetwork/)
## 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)
[![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)
[![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/)
## Usage
```typescript
import * as smartnetwork from 'smartnetwork';
testSmartNetwork = new smartnetwork.SmartNetwork();
testSmartNetwork.getSpeed
```
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://maintainedby.lossless.com)

View File

@ -18,4 +18,9 @@ tap.test('should determine wether a port is free', async () => {
await expect(testSmartNetwork.isLocalPortAvailable(8080)).to.eventually.be.true;
});
tap.test('should scan a port', async () => {
const portscanner = new smartnetwork.PortScanner();
expect(portscanner.checkPortStatus('google.com:80')).to.eventually.be.true;
});
tap.start();

View File

@ -1,103 +1,2 @@
import * as plugins from './smartnetwork.plugins';
export class ISpeedtestData {
speeds: {
download: number;
upload: number;
originalDownload: number;
originalUpload: number;
};
client: {
ip: string;
lat: number;
lon: number;
isp: string;
isprating: string;
rating: number;
ispdlavg: number;
ispulavg: number;
};
server: {
host: string;
lat: number;
lon: number;
location: string;
country: string;
cc: string;
sponsor: string;
distance: number;
distanceMi: number;
ping: number;
id: string;
};
}
/**
* SmartNetwork simplifies actions within the network
*/
export class SmartNetwork {
async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
let done = plugins.smartpromise.defer<ISpeedtestData>();
const test = plugins.speedtestNet({ maxTime: measurementTime });
test.on('data', data => {
done.resolve(data);
});
test.on('error', err => {
done.reject(err);
});
return await done.promise;
}
/**
* returns a promise with a boolean answer
* note: false also resolves with false as argument
* @param port
*/
async isLocalPortAvailable(port: number): Promise<boolean> {
const doneIpV4 = 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
// test IPv4 space
const ipv4Test = net.createServer();
ipv4Test.once('error', function(err: any) {
if (err.code !== 'EADDRINUSE') {
doneIpV4.resolve(false);
return;
}
doneIpV4.resolve(false);
});
ipv4Test.once('listening', function() {
ipv4Test.once('close', () => {
doneIpV4.resolve(true);
});
ipv4Test.close();
});
ipv4Test.listen(port, '0.0.0.0');
await doneIpV4.promise;
// test IPv6 space
const test_ipv6 = net.createServer();
test_ipv6.once('error', function(err: any) {
if (err.code !== 'EADDRINUSE') {
doneIpV6.resolve(false);
return;
}
doneIpV6.resolve(false);
});
test_ipv6.once('listening', function() {
test_ipv6.once('close', () => {
doneIpV6.resolve(true);
});
test_ipv6.close();
});
test_ipv6.listen(port, '::');
// lets wait for the result
const resultIpV4 = await doneIpV4.promise;
const resultIpV6 = await doneIpV6.promise;
const result = resultIpV4 === true && resultIpV6 === true;
return result;
}
}
export * from './smartnetwork.classes.portscanner';
export * from './smartnetwork.classes.speedtest';

View File

@ -0,0 +1,22 @@
import * as plugins from './smartnetwork.plugins';
export class PortScanner {
public async checkPortStatus(domainArg: string): Promise<boolean> {
const done = plugins.smartpromise.defer<boolean>();
const domainPart = domainArg.split(':')[0];
const port = parseInt(domainArg.split(':')[1], 10);
plugins.portscanner.checkPortStatus(port, domainPart, (err, status ) => {
if (err) {
throw err;
}
if (status === 'open') {
done.resolve(true);
} else {
done.resolve(false)
}
})
const result = await done.promise;
return result;
}
}

View File

@ -0,0 +1,128 @@
import * as plugins from './smartnetwork.plugins';
export class ISpeedtestData {
speeds: {
download: number;
upload: number;
originalDownload: number;
originalUpload: number;
};
client: {
ip: string;
lat: number;
lon: number;
isp: string;
isprating: string;
rating: number;
ispdlavg: number;
ispulavg: number;
};
server: {
host: string;
lat: number;
lon: number;
location: string;
country: string;
cc: string;
sponsor: string;
distance: number;
distanceMi: number;
ping: number;
id: string;
};
}
/**
* SmartNetwork simplifies actions within the network
*/
export class SmartNetwork {
async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
let done = plugins.smartpromise.defer<ISpeedtestData>();
const test = plugins.speedtestNet({ maxTime: measurementTime });
test.on('data', data => {
done.resolve(data);
});
test.on('error', err => {
done.reject(err);
});
return await done.promise;
}
/**
* returns a promise with a boolean answer
* note: false also resolves with false as argument
* @param port
*/
async isLocalPortAvailable(port: number): Promise<boolean> {
const doneIpV4 = 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
// test IPv4 space
const ipv4Test = net.createServer();
ipv4Test.once('error', function(err: any) {
if (err.code !== 'EADDRINUSE') {
doneIpV4.resolve(false);
return;
}
doneIpV4.resolve(false);
});
ipv4Test.once('listening', function() {
ipv4Test.once('close', () => {
doneIpV4.resolve(true);
});
ipv4Test.close();
});
ipv4Test.listen(port, '0.0.0.0');
await doneIpV4.promise;
// test IPv6 space
const test_ipv6 = net.createServer();
test_ipv6.once('error', function(err: any) {
if (err.code !== 'EADDRINUSE') {
doneIpV6.resolve(false);
return;
}
doneIpV6.resolve(false);
});
test_ipv6.once('listening', function() {
test_ipv6.once('close', () => {
doneIpV6.resolve(true);
});
test_ipv6.close();
});
test_ipv6.listen(port, '::');
// lets wait for the result
const resultIpV4 = await doneIpV4.promise;
const resultIpV6 = await doneIpV6.promise;
const result = resultIpV4 === true && resultIpV6 === true;
return result;
}
/**
* checks wether a remote port is available
* @param domainArg
*/
public async isRemotePortAvailable(domainArg: string, portArg?: number): Promise<boolean> {
const done = plugins.smartpromise.defer<boolean>();
const domainPart = domainArg.split(':')[0];
const port = (() => {
return portArg ? portArg : parseInt(domainArg.split(':')[1], 10);
})()
plugins.portscanner.checkPortStatus(port, domainPart, (err, status ) => {
if (err) {
throw err;
}
if (status === 'open') {
done.resolve(true);
} else {
done.resolve(false)
}
})
const result = await done.promise;
return result;
}
}

View File

@ -0,0 +1,103 @@
import * as plugins from './smartnetwork.plugins';
export class ISpeedtestData {
speeds: {
download: number;
upload: number;
originalDownload: number;
originalUpload: number;
};
client: {
ip: string;
lat: number;
lon: number;
isp: string;
isprating: string;
rating: number;
ispdlavg: number;
ispulavg: number;
};
server: {
host: string;
lat: number;
lon: number;
location: string;
country: string;
cc: string;
sponsor: string;
distance: number;
distanceMi: number;
ping: number;
id: string;
};
}
/**
* SmartNetwork simplifies actions within the network
*/
export class SmartNetwork {
async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
let done = plugins.smartpromise.defer<ISpeedtestData>();
const test = plugins.speedtestNet({ maxTime: measurementTime });
test.on('data', data => {
done.resolve(data);
});
test.on('error', err => {
done.reject(err);
});
return await done.promise;
}
/**
* returns a promise with a boolean answer
* note: false also resolves with false as argument
* @param port
*/
async isLocalPortAvailable(port: number): Promise<boolean> {
const doneIpV4 = 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
// test IPv4 space
const ipv4Test = net.createServer();
ipv4Test.once('error', function(err: any) {
if (err.code !== 'EADDRINUSE') {
doneIpV4.resolve(false);
return;
}
doneIpV4.resolve(false);
});
ipv4Test.once('listening', function() {
ipv4Test.once('close', () => {
doneIpV4.resolve(true);
});
ipv4Test.close();
});
ipv4Test.listen(port, '0.0.0.0');
await doneIpV4.promise;
// test IPv6 space
const test_ipv6 = net.createServer();
test_ipv6.once('error', function(err: any) {
if (err.code !== 'EADDRINUSE') {
doneIpV6.resolve(false);
return;
}
doneIpV6.resolve(false);
});
test_ipv6.once('listening', function() {
test_ipv6.once('close', () => {
doneIpV6.resolve(true);
});
test_ipv6.close();
});
test_ipv6.listen(port, '::');
// lets wait for the result
const resultIpV4 = await doneIpV4.promise;
const resultIpV6 = await doneIpV6.promise;
const result = resultIpV4 === true && resultIpV6 === true;
return result;
}
}

View File

@ -1,4 +1,13 @@
let speedtestNet = require('speedtest-net');
import * as smartpromise from '@pushrocks/smartpromise';
// native scope
export { speedtestNet, smartpromise };
// @pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartstring from '@pushrocks/smartstring';
export { smartpromise, smartstring };
// @third party scope
let speedtestNet = require('speedtest-net');
import * as portscanner from 'portscanner';
export { speedtestNet, portscanner };

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