fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-06 18:26:32 +02:00
parent 311852efe8
commit beb6680856
8 changed files with 509 additions and 376 deletions

19
.gitignore vendored
View File

@ -1,5 +1,22 @@
.nogit/ .nogit/
node_modules/
# artifacts
coverage/ coverage/
public/ public/
pages/ pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,5 +1,5 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
@ -38,19 +38,7 @@ snyk:
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
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:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
@ -60,12 +48,24 @@ testSTABLE:
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv - notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install lts
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
@ -78,19 +78,11 @@ release:
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services:
- docker:stable-dind
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 install
--env SOURCE_CODE="$PWD" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--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]
tags: tags:
- docker - docker
- priv - priv
@ -106,13 +98,15 @@ trigger:
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-dbase:npmci
services:
- docker:stable-dind
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - 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:
- docker - docker
- notpriv - notpriv

717
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,17 +12,30 @@
"build": "(tsbuild)" "build": "(tsbuild)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.8", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.20", "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.9", "@pushrocks/tapbundle": "^3.0.13",
"tslint": "^5.16.0", "tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartstring": "^3.0.10", "@pushrocks/smartstring": "^3.0.10",
"@types/default-gateway": "^3.0.0",
"@types/portscanner": "^2.1.0", "@types/portscanner": "^2.1.0",
"default-gateway": "^5.0.3",
"portscanner": "^2.2.0", "portscanner": "^2.2.0",
"speedtest-net": "^1.5.1" "speedtest-net": "^1.5.1"
} },
"files": [
"ts/*",
"ts_web/*",
"dist/*",
"dist_web/*",
"dist_ts_web/*",
"assets/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

View File

@ -22,21 +22,25 @@ network diagnostics
import * as smartnetwork from 'smartnetwork'; import * as smartnetwork from 'smartnetwork';
const testSmartNetwork = new smartnetwork.SmartNetwork(); const testSmartNetwork = new smartnetwork.SmartNetwork();
const run = async () => { const run = async () => {
// measure average speed over a period of 5 seconds // measure average speed over a period of 5 seconds
// the structure of speedResult is self explanatory using TypeScript (or the linked TypeDoc above) // the structure of speedResult is self explanatory using TypeScript (or the linked TypeDoc above)
const speedResult = testSmartNetwork.getSpeed(5000) const speedResult = testSmartNetwork.getSpeed(5000);
// //
const isLocalPortAvailable: boolean = await testSmartNetwork.isLocalPortAvailable(1234); const isLocalPortAvailable: boolean = await testSmartNetwork.isLocalPortAvailable(1234);
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable('google.com:80'); const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable(
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable('google.com', 80); 'google.com:80'
} );
const isRemotePortAvailable: boolean = await testSmartNetwork.isRemotePortAvailable(
'google.com',
80
);
};
``` ```
For further information read the linked docs at the top of this readme. 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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -19,9 +19,14 @@ tap.test('should determine wether a port is free', async () => {
}); });
tap.test('should scan a port', async () => { tap.test('should scan a port', async () => {
await expect(testSmartNetwork.isRemotePortAvailable('google.com:80')).to.eventually.be.true; await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:443')).to.eventually.be.true;
await expect(testSmartNetwork.isRemotePortAvailable('google.com', 80)).to.be.eventually.true; await expect(testSmartNetwork.isRemotePortAvailable('lossless.com', 443)).to.be.eventually.true;
await expect(testSmartNetwork.isRemotePortAvailable('67.207.79.63:12346')).to.eventually.be.false; // await expect(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).to.eventually.be.false;
}); });
tap.test('should get the default gateways', async () => {
const gatewayResult = await testSmartNetwork.getDefaultGateway();
console.log(gatewayResult);
})
tap.start(); tap.start();

View File

@ -36,8 +36,12 @@ export interface ISpeedtestData {
* SmartNetwork simplifies actions within the network * SmartNetwork simplifies actions within the network
*/ */
export class SmartNetwork { export class SmartNetwork {
async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> { /**
let done = plugins.smartpromise.defer<ISpeedtestData>(); * get network speed
* @param measurementTime
*/
public async getSpeed(measurementTime = 5000): Promise<ISpeedtestData> {
const done = plugins.smartpromise.defer<ISpeedtestData>();
const test = plugins.speedtestNet({ maxTime: measurementTime }); const test = plugins.speedtestNet({ maxTime: measurementTime });
test.on('data', data => { test.on('data', data => {
done.resolve(data); done.resolve(data);
@ -53,21 +57,21 @@ export class SmartNetwork {
* note: false also resolves with false as argument * note: false also resolves with false as argument
* @param port * @param port
*/ */
async isLocalPortAvailable(port: number): Promise<boolean> { public async isLocalPortAvailable(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
// test IPv4 space // test IPv4 space
const ipv4Test = net.createServer(); const ipv4Test = net.createServer();
ipv4Test.once('error', function(err: any) { ipv4Test.once('error', (err: any) => {
if (err.code !== 'EADDRINUSE') { if (err.code !== 'EADDRINUSE') {
doneIpV4.resolve(false); doneIpV4.resolve(false);
return; return;
} }
doneIpV4.resolve(false); doneIpV4.resolve(false);
}); });
ipv4Test.once('listening', function() { ipv4Test.once('listening', () => {
ipv4Test.once('close', () => { ipv4Test.once('close', () => {
doneIpV4.resolve(true); doneIpV4.resolve(true);
}); });
@ -78,21 +82,21 @@ export class SmartNetwork {
await doneIpV4.promise; await doneIpV4.promise;
// test IPv6 space // test IPv6 space
const test_ipv6 = net.createServer(); const ipv6Test = net.createServer();
test_ipv6.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;
} }
doneIpV6.resolve(false); doneIpV6.resolve(false);
}); });
test_ipv6.once('listening', function() { ipv6Test.once('listening', () => {
test_ipv6.once('close', () => { ipv6Test.once('close', () => {
doneIpV6.resolve(true); doneIpV6.resolve(true);
}); });
test_ipv6.close(); ipv6Test.close();
}); });
test_ipv6.listen(port, '::'); ipv6Test.listen(port, '::');
// lets wait for the result // lets wait for the result
const resultIpV4 = await doneIpV4.promise; const resultIpV4 = await doneIpV4.promise;
@ -110,7 +114,7 @@ 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.portscanner.checkPortStatus(port, domainPart, (err, status) => {
if (err) { if (err) {
// console.log(err); // console.log(err);
return done.resolve(false); return done.resolve(false);
@ -120,8 +124,16 @@ export class SmartNetwork {
} else { } else {
done.resolve(false); done.resolve(false);
} }
}) });
const result = await done.promise; const result = await done.promise;
return result; return result;
} }
public async getDefaultGateway() {
const result = {
v4: await plugins.defaultGateway.v4(),
v6: await plugins.defaultGateway.v6()
};
return result;
}
} }

View File

@ -7,7 +7,8 @@ import * as smartstring from '@pushrocks/smartstring';
export { smartpromise, smartstring }; export { smartpromise, smartstring };
// @third party scope // @third party scope
let speedtestNet = require('speedtest-net'); import defaultGateway from 'default-gateway';
const speedtestNet = require('speedtest-net');
import * as portscanner from 'portscanner'; import * as portscanner from 'portscanner';
export { speedtestNet, portscanner }; export { defaultGateway, speedtestNet, portscanner };