fix(core): update

This commit is contained in:
Philipp Kunz 2022-10-21 17:13:06 +02:00
parent 15744d3c4e
commit bcfa3be58b
7 changed files with 4537 additions and 18419 deletions

18396
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,17 +14,19 @@
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.61", "@gitzone/tsbuild": "^2.1.61",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.69", "@gitzone/tstest": "^1.0.69",
"@pushrocks/smartenv": "^5.0.0", "@pushrocks/smartenv": "^5.0.0",
"@pushrocks/tapbundle": "^5.0.3" "@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^18.11.3"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartping": "^1.0.7",
"@pushrocks/smartpromise": "^3.1.7", "@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartstring": "^4.0.2", "@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": "^6.0.1",
"systeminformation": "^5.11.9" "systeminformation": "^5.11.9"
}, },
"files": [ "files": [

4501
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,16 @@ tap.test('should create a vlid instance of SmartNetwork', async () => {
}); });
tap.test('should send a ping to Google', async () => { tap.test('should send a ping to Google', async () => {
expectAsync(testSmartnetwork.ping('https://lossless.com')).toBeTrue(); console.log(await testSmartnetwork.ping('google.com'));
expectAsync(testSmartnetwork.ping('https://notthere.lossless.com')).toBeTrue(); await expectAsync(testSmartnetwork.ping('google.com')).property('alive').toBeTrue();
expectAsync(testSmartnetwork.ping('192.168.186.999')).toBeFalse();
}); });
tap.test('should state when a ping is not alive ', async () => {
await expectAsync(testSmartnetwork.ping('notthere.lossless.com')).property('alive').toBeFalse();
});
tap.test('should send a ping to an IP', async () => {
await expectAsync(testSmartnetwork.ping('192.168.186.999')).property('alive').toBeFalse();
})
tap.start(); 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/smartnetwork',
version: '3.0.1',
description: 'network diagnostics'
}

View File

@ -16,17 +16,10 @@ export class SmartNetwork {
return test; return test;
} }
public async ping(hostArg: string, timeoutArg: number = 500): Promise<boolean> { public async ping(hostArg: string, timeoutArg: number = 500): Promise<ReturnType<typeof plugins.smartping.Smartping.prototype.ping>> {
if (process.getuid() !== 0) { const smartpingInstance = new plugins.smartping.Smartping();
console.log('icmp not allowed for nonroot!'); const pingResult = await smartpingInstance.ping(hostArg, timeoutArg);
return; return pingResult;
}
const result = await plugins.icmp.ping(hostArg, timeoutArg).catch();
if (result) {
return true;
} else {
return false;
}
} }
/** /**
@ -127,10 +120,14 @@ export class SmartNetwork {
public async getPublicIps() { public async getPublicIps() {
return { return {
v4: await plugins.publicIp.v4({ v4: await plugins.publicIp.publicIpv4({
timeout: 1000, timeout: 1000,
onlyHttps: true, onlyHttps: true,
}), }),
v6: await plugins.publicIp.publicIpv6({
timeout: 1000,
onlyHttps: true,
})
}; };
} }
} }

View File

@ -6,18 +6,17 @@ import * as perfHooks from 'perf_hooks';
export { os, https, perfHooks }; export { os, https, perfHooks };
// @pushrocks scope // @pushrocks scope
import * as smartping from '@pushrocks/smartping';
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartstring from '@pushrocks/smartstring'; import * as smartstring from '@pushrocks/smartstring';
export { smartpromise, smartstring }; export { smartpromise, smartping, smartstring };
// @third party scope // @third party scope
// @ts-ignore // @ts-ignore
import isopen from 'isopen'; import isopen from 'isopen';
// @ts-ignore // @ts-ignore
import icmp from 'icmp'; import * as publicIp from 'public-ip';
// @ts-ignore
import publicIp from 'public-ip';
import * as systeminformation from 'systeminformation'; import * as systeminformation from 'systeminformation';
export { isopen, icmp, publicIp, systeminformation }; export { isopen, publicIp, systeminformation };