Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
15744d3c4e | |||
8b2f541150 | |||
b52bb4b474 | |||
42f5d66fc4 | |||
54bb9549a1 | |||
95c3314400 | |||
695d047200 | |||
c308589d28 |
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -36,6 +39,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartnetwork",
|
"gitrepo": "smartnetwork",
|
||||||
"shortDescription": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"npmPackagename": "@pushrocks/smartnetwork",
|
"npmPackagename": "@pushrocks/smartnetwork",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
21198
package-lock.json
generated
21198
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
21
package.json
21
package.json
@ -1,30 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartnetwork",
|
"name": "@pushrocks/smartnetwork",
|
||||||
"version": "2.0.11",
|
"version": "3.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "network diagnostics",
|
"description": "network diagnostics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web --allowimplicitany)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.29",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tstest": "^1.0.64",
|
"@gitzone/tstest": "^1.0.69",
|
||||||
"@pushrocks/tapbundle": "^4.0.7",
|
"@pushrocks/smartenv": "^5.0.0",
|
||||||
"tslint": "^6.1.3",
|
"@pushrocks/tapbundle": "^5.0.3"
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": "^3.1.6",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartstring": "^3.0.24",
|
"@pushrocks/smartstring": "^4.0.2",
|
||||||
"@types/default-gateway": "^3.0.1",
|
"@types/default-gateway": "^3.0.1",
|
||||||
|
"icmp": "^2.0.1",
|
||||||
"isopen": "^1.3.0",
|
"isopen": "^1.3.0",
|
||||||
"public-ip": "^4.0.4",
|
"public-ip": "^4.0.4",
|
||||||
"systeminformation": "^5.11.3"
|
"systeminformation": "^5.11.9"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
18
test/test.ping.ts
Normal file
18
test/test.ping.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
|
import * as smartnetwork from '../ts/index.js';
|
||||||
|
|
||||||
|
let testSmartnetwork: smartnetwork.SmartNetwork;
|
||||||
|
|
||||||
|
tap.test('should create a vlid instance of SmartNetwork', async () => {
|
||||||
|
testSmartnetwork = new smartnetwork.SmartNetwork();
|
||||||
|
expect(testSmartnetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should send a ping to Google', async () => {
|
||||||
|
expectAsync(testSmartnetwork.ping('https://lossless.com')).toBeTrue();
|
||||||
|
expectAsync(testSmartnetwork.ping('https://notthere.lossless.com')).toBeTrue();
|
||||||
|
expectAsync(testSmartnetwork.ping('192.168.186.999')).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,5 +1,5 @@
|
|||||||
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartnetwork from '../ts/index';
|
import * as smartnetwork from '../ts/index.js';
|
||||||
|
|
||||||
let testSmartNetwork: smartnetwork.SmartNetwork;
|
let testSmartNetwork: smartnetwork.SmartNetwork;
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from './smartnetwork.classes.smartnetwork';
|
export * from './smartnetwork.classes.smartnetwork.js';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './smartnetwork.plugins';
|
import * as plugins from './smartnetwork.plugins.js';
|
||||||
import * as stats from './helpers/stats';
|
import * as stats from './helpers/stats.js';
|
||||||
|
|
||||||
export class CloudflareSpeed {
|
export class CloudflareSpeed {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
@ -106,7 +106,7 @@ export class CloudflareSpeed {
|
|||||||
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
public async fetchServerLocations(): Promise<{ [key: string]: string }> {
|
||||||
const res = JSON.parse(await this.get('speed.cloudflare.com', '/locations'));
|
const res = JSON.parse(await this.get('speed.cloudflare.com', '/locations'));
|
||||||
|
|
||||||
return res.reduce((data: any, optionsArg: { iata: string, city: string}) => {
|
return res.reduce((data: any, optionsArg: { iata: string; city: string }) => {
|
||||||
// Bypass prettier "no-assign-param" rules
|
// Bypass prettier "no-assign-param" rules
|
||||||
const data1 = data;
|
const data1 = data;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ export class CloudflareSpeed {
|
|||||||
public async request(options: plugins.https.RequestOptions, data = ''): Promise<number[]> {
|
public async request(options: plugins.https.RequestOptions, data = ''): Promise<number[]> {
|
||||||
let started: number;
|
let started: number;
|
||||||
let dnsLookup: number;
|
let dnsLookup: number;
|
||||||
let tcpHandshake : number;
|
let tcpHandshake: number;
|
||||||
let sslHandshake: number;
|
let sslHandshake: number;
|
||||||
let ttfb: number;
|
let ttfb: number;
|
||||||
let ended: number;
|
let ended: number;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as plugins from './smartnetwork.plugins';
|
import * as plugins from './smartnetwork.plugins.js';
|
||||||
|
|
||||||
import { CloudflareSpeed } from './smartnetwork.classes.cloudflarespeed';
|
import { CloudflareSpeed } from './smartnetwork.classes.cloudflarespeed.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartNetwork simplifies actions within the network
|
* SmartNetwork simplifies actions within the network
|
||||||
@ -16,6 +16,19 @@ export class SmartNetwork {
|
|||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async ping(hostArg: string, timeoutArg: number = 500): Promise<boolean> {
|
||||||
|
if (process.getuid() !== 0) {
|
||||||
|
console.log('icmp not allowed for nonroot!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await plugins.icmp.ping(hostArg, timeoutArg).catch();
|
||||||
|
if (result) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a promise with a boolean answer
|
* returns a promise with a boolean answer
|
||||||
* note: false also resolves with false as argument
|
* note: false also resolves with false as argument
|
||||||
|
@ -12,8 +12,12 @@ import * as smartstring from '@pushrocks/smartstring';
|
|||||||
export { smartpromise, smartstring };
|
export { smartpromise, smartstring };
|
||||||
|
|
||||||
// @third party scope
|
// @third party scope
|
||||||
const isopen = require('isopen');
|
// @ts-ignore
|
||||||
|
import isopen from 'isopen';
|
||||||
|
// @ts-ignore
|
||||||
|
import icmp from 'icmp';
|
||||||
|
// @ts-ignore
|
||||||
import publicIp from 'public-ip';
|
import publicIp from 'public-ip';
|
||||||
import * as systeminformation from 'systeminformation';
|
import * as systeminformation from 'systeminformation';
|
||||||
|
|
||||||
export { isopen, publicIp, systeminformation };
|
export { isopen, icmp, publicIp, systeminformation };
|
||||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
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