si-hawk 0.0.0-stage → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +37 -0
- package/README.md +218 -3
- package/assets/hawk.jpeg +0 -0
- package/assets/manifest.json +19 -0
- package/package.json +52 -6
- package/src/capabilities.js +152 -0
- package/src/cli.js +182 -0
- package/src/detect.js +165 -0
- package/src/evo.js +3 -0
- package/src/fingerprint.js +122 -0
- package/src/format.js +447 -0
- package/src/index.js +192 -0
- package/src/inv.js +3 -0
- package/src/monitor.js +110 -0
- package/src/network.js +211 -0
- package/src/node.js +184 -0
- package/src/portable.js +84 -0
- package/src/processes.js +41 -0
- package/src/scan.js +263 -0
- package/src/services.js +30 -0
- package/src/types.d.ts +216 -0
- package/src/util.js +16 -0
- package/src/windows.js +201 -0
package/src/format.js
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
export const HEALTH_THRESHOLDS = Object.freeze({
|
|
2
|
+
disk: Object.freeze({ warning: 90, critical: 97 }),
|
|
3
|
+
memory: Object.freeze({ warning: 75, critical: 85 }),
|
|
4
|
+
cpu: Object.freeze({ warning: 50, critical: 90 }),
|
|
5
|
+
battery: Object.freeze({ warning: 20, critical: 10 }),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const GOLD = { truecolor: '\u001b[38;2;212;175;55m', indexed: '\u001b[38;5;178m', basic: '\u001b[33m' };
|
|
9
|
+
const GREEN = { truecolor: '\u001b[38;2;63;185;80m', indexed: '\u001b[38;5;71m', basic: '\u001b[32m' };
|
|
10
|
+
const RESET = '\u001b[0m';
|
|
11
|
+
const BOLD = '\u001b[1m';
|
|
12
|
+
|
|
13
|
+
export function colorMode({ stdout = process.stdout, env = process.env, noColor = false } = {}) {
|
|
14
|
+
if (noColor) return null;
|
|
15
|
+
if (env.FORCE_COLOR && env.FORCE_COLOR !== '0') return env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit' || env.WT_SESSION ? 'truecolor' : Number(stdout.getColorDepth?.() ?? 1) >= 8 ? 'indexed' : 'basic';
|
|
16
|
+
if (!stdout.isTTY || Object.hasOwn(env, 'NO_COLOR')) return null;
|
|
17
|
+
if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit' || env.WT_SESSION) return 'truecolor';
|
|
18
|
+
return Number(stdout.getColorDepth?.() ?? 1) >= 8 || /256color/i.test(env.TERM ?? '') ? 'indexed' : 'basic';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function paint(value, kind, mode, bold = false) {
|
|
22
|
+
if (!mode) return String(value);
|
|
23
|
+
const color = kind === 'green' ? GREEN[mode] : GOLD[mode];
|
|
24
|
+
return (bold ? BOLD : '') + color + value + RESET;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function rule(width = 60, ascii = false) {
|
|
28
|
+
return (ascii ? '-' : '─').repeat(width);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function humanBytes(value) {
|
|
32
|
+
if (value === null || value === undefined || !Number.isFinite(Number(value))) return 'unavailable';
|
|
33
|
+
const bytes = Number(value);
|
|
34
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
35
|
+
let size = Math.abs(bytes);
|
|
36
|
+
let index = 0;
|
|
37
|
+
while (size >= 1024 && index < units.length - 1) { size /= 1024; index++; }
|
|
38
|
+
const precision = size >= 100 ? 0 : size >= 10 ? 1 : 2;
|
|
39
|
+
return (bytes < 0 ? '-' : '') + size.toFixed(precision) + ' ' + units[index];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function value(obj, ...keys) {
|
|
43
|
+
for (const key of keys) if (obj?.[key] !== undefined && obj?.[key] !== null) return obj[key];
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function nice(value) {
|
|
48
|
+
return value ? String(value).replace(/([a-z])([A-Z])/g, '$1 $2') : 'unavailable';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function sanitizeTerminalText(value) {
|
|
52
|
+
return String(value ?? '')
|
|
53
|
+
.replace(/\u001b(?:\][\s\S]*?(?:\u0007|\u001b\\)|[PX^_][\s\S]*?\u001b\\|\[[0-?]*[ -/]*[@-~])/g, '')
|
|
54
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function groupProcesses(processes = []) {
|
|
58
|
+
const groups = new Map();
|
|
59
|
+
for (const process of processes) {
|
|
60
|
+
const name = String(process?.name ?? 'Unknown');
|
|
61
|
+
const key = name.toLocaleLowerCase();
|
|
62
|
+
const entry = groups.get(key) ?? { name, memoryBytes: 0, count: 0 };
|
|
63
|
+
entry.memoryBytes += Number(process?.memoryBytes) || 0;
|
|
64
|
+
entry.count++;
|
|
65
|
+
groups.set(key, entry);
|
|
66
|
+
}
|
|
67
|
+
return [...groups.values()].sort((a, b) => b.memoryBytes - a.memoryBytes || a.name.localeCompare(b.name));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function validUnicastMac(mac) {
|
|
71
|
+
if (typeof mac !== 'string' || !/^(?:[0-9a-f]{2}[:-]){5}[0-9a-f]{2}$/i.test(mac)) return false;
|
|
72
|
+
const first = parseInt(mac.slice(0, 2), 16);
|
|
73
|
+
return (first & 1) === 0 && !/^ff(?::ff){5}$/i.test(mac.replaceAll('-', ':'));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function isNonUnicastIp(address) {
|
|
77
|
+
const parts = String(address ?? '').split('.').map(Number);
|
|
78
|
+
if (parts.length !== 4 || parts.some(part => !Number.isInteger(part) || part < 0 || part > 255)) return false;
|
|
79
|
+
return parts[0] >= 224 || parts.every(part => part === 255) || parts[0] === 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function filterNeighbors(neighbors = []) {
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
return neighbors.filter(item => {
|
|
85
|
+
if (!validUnicastMac(item?.mac) || isNonUnicastIp(item?.address)) return false;
|
|
86
|
+
const key = String(item.address).toLowerCase();
|
|
87
|
+
if (seen.has(key)) return false;
|
|
88
|
+
seen.add(key);
|
|
89
|
+
return true;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function healthItems(snapshot) {
|
|
94
|
+
const checks = [];
|
|
95
|
+
const disk = snapshot?.storage;
|
|
96
|
+
const memory = snapshot?.host?.memory;
|
|
97
|
+
const cpu = snapshot?.host?.cpu;
|
|
98
|
+
const battery = snapshot?.battery;
|
|
99
|
+
const add = (name, percent, limits, detail, available = true) => {
|
|
100
|
+
if (!available || !Number.isFinite(Number(percent))) return;
|
|
101
|
+
const level = Number(percent) >= limits.critical ? 'critical' : Number(percent) >= limits.warning ? 'warning' : 'ok';
|
|
102
|
+
checks.push({ name, level, percent: Number(percent), detail });
|
|
103
|
+
};
|
|
104
|
+
add('Disk', disk?.usedPercent, HEALTH_THRESHOLDS.disk,
|
|
105
|
+
humanBytes(value(disk, 'availableBytes')) + ' free of ' + humanBytes(value(disk, 'totalBytes')) + ' · ' + Math.round(Number(disk?.usedPercent)) + '% used', disk?.available === true);
|
|
106
|
+
add('Memory', memory?.usedPercent, HEALTH_THRESHOLDS.memory,
|
|
107
|
+
humanBytes(memory?.availableBytes) + ' free of ' + humanBytes(memory?.totalBytes) + ' · ' + Math.round(Number(memory?.usedPercent)) + '% used');
|
|
108
|
+
add('CPU', cpu?.utilizationPercent, HEALTH_THRESHOLDS.cpu,
|
|
109
|
+
Math.round(Number(cpu?.utilizationPercent)) + '% in the last ' + Math.max(1, Math.round(Number(cpu?.measurement?.windowMs ?? 1000) / 1000)) + 's window');
|
|
110
|
+
if (battery?.available && battery?.charging === false && Number.isFinite(Number(battery.levelPercent))) {
|
|
111
|
+
const level = Number(battery.levelPercent);
|
|
112
|
+
const state = level <= HEALTH_THRESHOLDS.battery.critical ? 'critical' : level <= HEALTH_THRESHOLDS.battery.warning ? 'warning' : 'ok';
|
|
113
|
+
checks.push({ name: 'Battery', level: state, percent: level, detail: level + '% remaining — on battery' });
|
|
114
|
+
}
|
|
115
|
+
const order = { critical: 0, warning: 1, ok: 2 };
|
|
116
|
+
return checks.sort((a, b) => order[a.level] - order[b.level] || a.name.localeCompare(b.name));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function renderTable(rows, columns, {
|
|
120
|
+
indent = ' ', mode = null, ascii = false,
|
|
121
|
+
terminalWidth = process.stdout.columns || 100,
|
|
122
|
+
numericColumns = [], style = null, labels = columns,
|
|
123
|
+
} = {}) {
|
|
124
|
+
const gap = ' ';
|
|
125
|
+
const sourceRows = rows ?? [];
|
|
126
|
+
const cells = sourceRows.map(row => columns.map(key => {
|
|
127
|
+
const item = row?.[key];
|
|
128
|
+
if (item === null || item === undefined) return '—';
|
|
129
|
+
if (isByteField(key) && Number.isFinite(Number(item))) return humanBytes(item);
|
|
130
|
+
if (typeof item === 'object') return JSON.stringify(item);
|
|
131
|
+
return sanitizeTerminalText(item).replace(/\r?\n/g, ' ');
|
|
132
|
+
}));
|
|
133
|
+
const natural = columns.map((column, i) => Math.max(labels[i].length, ...cells.map(row => row[i].length)));
|
|
134
|
+
const widths = [...natural];
|
|
135
|
+
const available = Math.max(columns.length, Number(terminalWidth) - indent.length);
|
|
136
|
+
const total = () => widths.reduce((sum, width) => sum + width, 0) + gap.length * Math.max(0, widths.length - 1);
|
|
137
|
+
while (total() > available) {
|
|
138
|
+
let index = -1;
|
|
139
|
+
for (let i = 0; i < widths.length; i++) if (widths[i] > 1 && (index < 0 || widths[i] > widths[index])) index = i;
|
|
140
|
+
if (index < 0) break;
|
|
141
|
+
widths[index]--;
|
|
142
|
+
}
|
|
143
|
+
const fit = (text, width) => {
|
|
144
|
+
const value = String(text);
|
|
145
|
+
if (value.length <= width) return value;
|
|
146
|
+
if (width <= 1) return '…'.slice(0, width);
|
|
147
|
+
return value.slice(0, width - 1) + '…';
|
|
148
|
+
};
|
|
149
|
+
const numeric = column => numericColumns.includes(column) || /^(memory|procs|child nodes|signal|channel|count|pid|processes)$/i.test(column);
|
|
150
|
+
const align = (text, width, right) => right ? text.padStart(width) : text.padEnd(width);
|
|
151
|
+
const header = indent + labels.map((column, i) => paint(align(fit(column, widths[i]), widths[i], numericColumns.includes(columns[i])), 'gold', mode, true)).join(gap);
|
|
152
|
+
const separator = paint(indent + widths.map(width => (ascii ? '-' : '─').repeat(width)).join(gap), 'gold', mode);
|
|
153
|
+
const dataRows = cells.map((row, rowIndex) => indent + row.map((value, i) => {
|
|
154
|
+
const raw = align(fit(value, widths[i]), widths[i], numeric(columns[i]));
|
|
155
|
+
const color = style?.(columns[i], sourceRows[rowIndex]) ?? null;
|
|
156
|
+
return color ? paint(raw, color.kind ?? color, mode, Boolean(color.bold)) : raw;
|
|
157
|
+
}).join(gap));
|
|
158
|
+
const result = [header, separator, ...dataRows];
|
|
159
|
+
if (!sourceRows.length) result.push(indent + 'none reported');
|
|
160
|
+
return result.join('\n');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function table(rows, columns, indent = ' ', mode = null, ascii = false, options = {}) {
|
|
164
|
+
return renderTable(rows, columns, { indent, mode, ascii, ...options }).split('\n');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isByteField(key) {
|
|
168
|
+
return /Bytes$/.test(key) || ['totalmem', 'freemem'].includes(String(key).toLowerCase());
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function titleCase(key) {
|
|
172
|
+
return String(key).replace(/([a-z])([A-Z])/g, '$1 $2').replace(/^./, char => char.toUpperCase());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function detailLines(obj, indent = ' ', mode = null, ascii = false) {
|
|
176
|
+
const lines = [];
|
|
177
|
+
for (const [key, item] of Object.entries(obj ?? {})) {
|
|
178
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
179
|
+
lines.push(indent + titleCase(key) + ':');
|
|
180
|
+
lines.push(...detailLines(item, indent + ' ', mode, ascii));
|
|
181
|
+
} else if (Array.isArray(item) && item.every(row => row && typeof row === 'object' && !Array.isArray(row)) && item.length) {
|
|
182
|
+
lines.push(indent + titleCase(key) + ' (' + item.length + '):');
|
|
183
|
+
const columns = [...new Set(item.flatMap(row => Object.keys(row)))];
|
|
184
|
+
lines.push(...table(item, columns, indent + ' ', mode, ascii));
|
|
185
|
+
} else if (Array.isArray(item)) {
|
|
186
|
+
lines.push(indent + titleCase(key) + ': ' + (item.length ? item.map(row => typeof row === 'object' ? sanitizeTerminalText(JSON.stringify(row)) : sanitizeTerminalText(row)).join(', ') : 'none reported'));
|
|
187
|
+
} else if (item !== null && item !== undefined && isByteField(key) && Number.isFinite(Number(item))) {
|
|
188
|
+
lines.push(indent + titleCase(key) + ': ' + humanBytes(item));
|
|
189
|
+
} else {
|
|
190
|
+
lines.push(indent + titleCase(key) + ': ' + (item === null || item === undefined || item === '' ? 'unavailable' : sanitizeTerminalText(item)));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return lines;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function fitTerminalLine(line, width = process.stdout.columns || 100) {
|
|
197
|
+
const input = String(line);
|
|
198
|
+
const limit = Math.max(1, Number(width) || 100);
|
|
199
|
+
const tokens = input.match(/\u001b\[[0-9;]*m|[\s\S]/g) ?? [];
|
|
200
|
+
const visible = tokens.filter(token => !token.startsWith('\u001b['));
|
|
201
|
+
if (visible.length <= limit) return input;
|
|
202
|
+
let output = '';
|
|
203
|
+
let count = 0;
|
|
204
|
+
for (const token of tokens) {
|
|
205
|
+
if (token.startsWith('\u001b[')) { output += token; continue; }
|
|
206
|
+
if (count >= limit - 1) break;
|
|
207
|
+
output += token;
|
|
208
|
+
count++;
|
|
209
|
+
}
|
|
210
|
+
return output + '…' + RESET;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function sectionHeader(label, mode) {
|
|
214
|
+
return paint(label.toUpperCase(), 'gold', mode);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function deviceLines(snapshot, mode, full = false) {
|
|
218
|
+
const host = snapshot.host ?? {};
|
|
219
|
+
const identity = snapshot.deviceIdentity ?? {};
|
|
220
|
+
const battery = snapshot.battery ?? {};
|
|
221
|
+
const cpu = host.cpu ?? {};
|
|
222
|
+
const maker = value(identity, 'manufacturer') ?? value(host, 'manufacturer');
|
|
223
|
+
const model = value(identity, 'model') ?? value(host, 'model');
|
|
224
|
+
const name = value(identity, 'name') ?? value(host, 'name');
|
|
225
|
+
const osName = host.platform === 'win32' ? 'Windows' : host.platform === 'darwin' ? 'macOS' : host.platform;
|
|
226
|
+
const batteryText = battery.available
|
|
227
|
+
? (battery.levelPercent === null ? 'level unavailable' : battery.levelPercent + '%') + (battery.charging ? ' · charging' : battery.charging === false ? ' · on battery (not charging)' : '')
|
|
228
|
+
: 'unavailable' + (battery.reason ? ' (' + battery.reason + ')' : '');
|
|
229
|
+
const field = (label, text) => ' ' + paint(label.padEnd(10), 'gold', mode) + text;
|
|
230
|
+
const lines = [
|
|
231
|
+
field('Name', String(name ?? 'unavailable') + (host.deviceType ? ' · ' + nice(host.deviceType) : '')),
|
|
232
|
+
field('Maker', maker || model ? [maker, model].filter(Boolean).join(' · ') : 'unavailable'),
|
|
233
|
+
field('OS', [osName, host.release, host.arch].filter(Boolean).join(' · ') || 'unavailable'),
|
|
234
|
+
field('CPU', [cpu.model, cpu.logicalCores ? cpu.logicalCores + ' cores' : null].filter(Boolean).join(' · ') || 'unavailable'),
|
|
235
|
+
field('Battery', batteryText),
|
|
236
|
+
field('Runtime', 'Node ' + (host.nodeVersion ?? process.version)),
|
|
237
|
+
];
|
|
238
|
+
if (full) {
|
|
239
|
+
const hostExtra = { ...host };
|
|
240
|
+
for (const key of ['name', 'platform', 'release', 'arch', 'manufacturer', 'model', 'deviceType', 'nodeVersion', 'cpu']) delete hostExtra[key];
|
|
241
|
+
const identityExtra = { ...identity };
|
|
242
|
+
for (const key of ['name', 'manufacturer', 'model', 'deviceType']) delete identityExtra[key];
|
|
243
|
+
const cpuExtra = { ...cpu };
|
|
244
|
+
for (const key of ['model', 'logicalCores']) delete cpuExtra[key];
|
|
245
|
+
const batteryExtra = { ...battery };
|
|
246
|
+
for (const key of ['available', 'levelPercent', 'charging', 'powerSource']) delete batteryExtra[key];
|
|
247
|
+
lines.push(...detailLines({ host: hostExtra, cpu: cpuExtra, identity: identityExtra, storage: snapshot.storage, battery: batteryExtra }, ' ', mode, false));
|
|
248
|
+
}
|
|
249
|
+
return lines;
|
|
250
|
+
}
|
|
251
|
+
function neighborsLines(snapshot, full, mode = null, ascii = false) {
|
|
252
|
+
const data = snapshot.network?.neighbors;
|
|
253
|
+
if (!data?.available) return [' On the LAN: unavailable' + (data?.reason ? ' (' + data.reason + ')' : '')];
|
|
254
|
+
const neighbors = filterNeighbors(data.devices ?? []);
|
|
255
|
+
const lines = [' ' + paint('On the LAN:', 'gold', mode) + ' ' + neighbors.length + ' devices'];
|
|
256
|
+
const shown = full ? neighbors : neighbors.slice(0, 5);
|
|
257
|
+
if (shown.length) lines.push(...table(shown, ['address', 'mac'], ' ', mode, ascii, { labels: ['IP Address', 'MAC'] }));
|
|
258
|
+
if (!full && neighbors.length > shown.length) lines.push(' … ' + (neighbors.length - shown.length) + ' more (si-hawk inv --section network)');
|
|
259
|
+
return lines;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function networkLines(snapshot, full, mode = null, ascii = false) {
|
|
263
|
+
const network = snapshot.network ?? {};
|
|
264
|
+
if (full) {
|
|
265
|
+
const safeNetwork = { ...network };
|
|
266
|
+
if (network.neighbors) safeNetwork.neighbors = { ...network.neighbors, devices: filterNeighbors(network.neighbors.devices ?? []) };
|
|
267
|
+
return detailLines(safeNetwork, ' ', mode, ascii);
|
|
268
|
+
}
|
|
269
|
+
const connection = network.wifiConnection;
|
|
270
|
+
const wifi = connection?.connections?.[0];
|
|
271
|
+
const lines = [];
|
|
272
|
+
if (wifi) {
|
|
273
|
+
lines.push(' ' + paint('Wi-Fi'.padEnd(10), 'gold', mode) + wifi.ssid + (wifi.securityType ? ' · ' + wifi.securityType : '') + (wifi.radioType ? ' · ' + wifi.radioType : '') + (wifi.channel ? ' · ch ' + wifi.channel : '') + (wifi.signalPercent !== undefined ? ' · signal ' + wifi.signalPercent + '%' : ''));
|
|
274
|
+
} else if (!connection?.available || connection?.reason) {
|
|
275
|
+
lines.push(' ' + paint('Wi-Fi'.padEnd(10), 'gold', mode) + 'unavailable' + (connection?.reason ? ' (' + connection.reason + ')' : ''));
|
|
276
|
+
} else lines.push(' ' + paint('Wi-Fi'.padEnd(10), 'gold', mode) + 'no active connection reported');
|
|
277
|
+
const ip = (network.interfaces?.devices ?? []).find(item => !item.internal && item.family === 'IPv4')?.address;
|
|
278
|
+
lines.push(' ' + paint('Address'.padEnd(10), 'gold', mode) + (ip ?? 'unavailable'));
|
|
279
|
+
const nearby = network.nearby;
|
|
280
|
+
if (nearby?.wifi?.available) lines.push(' ' + paint('Nearby'.padEnd(10), 'gold', mode) + nearby.wifi.count + ' access point' + (nearby.wifi.count === 1 ? '' : 's') + ' visible');
|
|
281
|
+
else lines.push(' ' + paint('Nearby'.padEnd(10), 'gold', mode) + 'unavailable' + (nearby?.wifi?.reason ? ' (' + nearby.wifi.reason + ')' : ' (run si-hawk evo)'));
|
|
282
|
+
if (nearby?.bluetooth?.available) lines.push(' ' + paint('Bluetooth LE'.padEnd(14), 'gold', mode) + nearby.bluetooth.count + ' device' + (nearby.bluetooth.count === 1 ? '' : 's') + ' visible');
|
|
283
|
+
else lines.push(' ' + paint('Bluetooth LE'.padEnd(14), 'gold', mode) + 'unavailable' + (nearby?.bluetooth?.reason ? ' (' + nearby.bluetooth.reason + ')' : ''));
|
|
284
|
+
lines.push(...neighborsLines(snapshot, full, mode, ascii));
|
|
285
|
+
if (full) lines.push(...detailLines(network, ' ', mode, ascii));
|
|
286
|
+
return lines;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function hardwareLines(snapshot, full, mode = null, ascii = false) {
|
|
290
|
+
const connected = snapshot.connectedDevices;
|
|
291
|
+
const devices = connected?.devices ?? [];
|
|
292
|
+
const lines = [paint('CONNECTED HARDWARE (' + (connected?.count ?? 'unavailable') + ')', 'gold', mode)];
|
|
293
|
+
if (!connected?.available) return lines.concat(' unavailable' + (connected?.reason ? ' (' + connected.reason + ')' : ''));
|
|
294
|
+
const visible = full ? devices : devices.slice(0, 5);
|
|
295
|
+
if (visible.length) lines.push(...table(visible.map(device => ({ name: device.name ?? 'Unknown device', childNodes: device.devices?.length ?? 0 })), ['name', 'childNodes'], ' ', mode, ascii, { labels: ['Device', 'Child nodes'], numericColumns: ['childNodes'] }));
|
|
296
|
+
if (full) for (const device of visible) for (const child of device.devices ?? []) lines.push(' - ' + (child.name ?? 'Unknown') + ' · ' + (child.status ?? 'status unavailable'));
|
|
297
|
+
if (!full && devices.length > visible.length) lines.push(' … ' + (devices.length - visible.length) + ' more (si-hawk inv --section hardware)');
|
|
298
|
+
if (full) lines.push(' Source: ' + (connected.source ?? 'unavailable'), ' Scope: ' + (connected.scope ?? 'unavailable'));
|
|
299
|
+
return lines;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function processLines(snapshot, full, mode = null, ascii = false) {
|
|
303
|
+
const processes = groupProcesses(snapshot.processes?.processes ?? []);
|
|
304
|
+
const visible = full ? processes : processes.slice(0, 5);
|
|
305
|
+
const lines = [paint('TOP MEMORY (grouped by app)', 'gold', mode)];
|
|
306
|
+
if (visible.length) lines.push(...table(visible.map(item => ({ name: item.name, memoryBytes: item.memoryBytes, procs: item.count })), ['name', 'memoryBytes', 'procs'], ' ', mode, ascii, { labels: ['App', 'Memory', 'Procs'], numericColumns: ['memoryBytes', 'procs'] }));
|
|
307
|
+
if (!full && (snapshot.processes?.count ?? 0) > 5) lines.push(' … ' + snapshot.processes.count + ' processes total (si-hawk inv --section processes)');
|
|
308
|
+
if (full && snapshot.processes?.processes?.length) {
|
|
309
|
+
lines.push('', ' ALL PROCESS DETAILS');
|
|
310
|
+
const rows = snapshot.processes.processes;
|
|
311
|
+
lines.push(...table(rows, [...new Set(rows.flatMap(item => Object.keys(item)))], ' '));
|
|
312
|
+
}
|
|
313
|
+
if (!snapshot.processes?.available) lines.push(' unavailable' + (snapshot.processes?.reason ? ' (' + snapshot.processes.reason + ')' : ''));
|
|
314
|
+
if (full) lines.push(' Source: ' + (snapshot.processes?.source ?? 'unavailable'), ' Scope: ' + (snapshot.processes?.scope ?? 'unavailable'));
|
|
315
|
+
return lines;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const notableService = /postgres|mysql|maria|sql|mongo|redis|defender|security|firewall|mpssvc|windefend|remote|ssh|rdp|anydesk|teamviewer|agent|sandbox|docker|vmware|hyper-v|wsl/i;
|
|
319
|
+
|
|
320
|
+
function serviceLines(snapshot, full, mode = null, ascii = false) {
|
|
321
|
+
const data = snapshot.services ?? {};
|
|
322
|
+
const services = data.services ?? [];
|
|
323
|
+
const running = services.filter(service => /running|active/i.test(String(service.status ?? service.active ?? '')));
|
|
324
|
+
const notable = running.filter(service => notableService.test(String(service.name) + ' ' + String(service.displayName ?? '')));
|
|
325
|
+
const visible = full ? services : notable.slice(0, 5);
|
|
326
|
+
const lines = [paint(full ? 'SERVICES ' + (data.count ?? services.length) + ' total' : 'SERVICES ' + (data.count ?? services.length) + ' total · notable running', 'gold', mode)];
|
|
327
|
+
if (!full) lines.push(' All services: si-hawk inv --section services');
|
|
328
|
+
if (!data.available) lines.push(' unavailable' + (data.reason ? ' (' + data.reason + ')' : ''));
|
|
329
|
+
else if (visible.length) lines.push(...table(visible.map(service => ({ name: String(service.displayName ?? service.name ?? 'Unknown service').replace(/^\\S+\\s+-\\s+/, ''), status: service.status ?? service.active ?? 'Unknown' })), ['name', 'status'], ' ', mode, ascii, { labels: ['Service', 'Status'] }));
|
|
330
|
+
if (!full && notable.length > visible.length) lines.push(' … ' + (notable.length - visible.length) + ' more (si-hawk inv --section services)');
|
|
331
|
+
if (full) lines.push(' Source: ' + (data.source ?? 'unavailable'), ' Scope: ' + (data.scope ?? 'unavailable'));
|
|
332
|
+
return lines;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function sourcesLine(snapshot) {
|
|
336
|
+
const text = Object.values(snapshot.sources ?? {}).filter(Boolean).join(' ');
|
|
337
|
+
const ids = ['node:os', 'node:fs', 'PnPUtil', 'GetSystemPowerStatus', 'Get-Process', 'Get-Service', 'netsh', 'arp'];
|
|
338
|
+
const labels = ids.filter(id => text.toLowerCase().includes(id.toLowerCase()));
|
|
339
|
+
return 'Sources: ' + (labels.join(', ') || 'OS interfaces');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function rawSection(snapshot, section) {
|
|
343
|
+
const map = { network: snapshot.network, processes: snapshot.processes, services: snapshot.services, hardware: snapshot.connectedDevices, device: { host: snapshot.host, identity: snapshot.deviceIdentity, battery: snapshot.battery, storage: snapshot.storage } };
|
|
344
|
+
return map[section];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function renderHostSnapshot(snapshot, { section = null, full = false, color = false, ascii = false } = {}) {
|
|
348
|
+
const mode = color ? (color === true ? 'basic' : color) : null;
|
|
349
|
+
const name = snapshot.deviceIdentity?.name ?? snapshot.host?.name ?? 'Unknown device';
|
|
350
|
+
const time = snapshot.observedAt ? new Date(snapshot.observedAt).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : 'time unavailable';
|
|
351
|
+
const lines = [paint('SI-HAWK · ' + name + ' · ' + time, 'gold', mode), paint(rule(60, ascii), 'gold', mode)];
|
|
352
|
+
if (section) {
|
|
353
|
+
const selected = rawSection(snapshot, section);
|
|
354
|
+
if (!selected) return 'Unknown section "' + section + '". Choose network, processes, services, hardware, or device.';
|
|
355
|
+
lines.push(sectionHeader(section, mode));
|
|
356
|
+
if (section === 'network') lines.push(...networkLines(snapshot, true, mode, ascii));
|
|
357
|
+
else if (section === 'processes') lines.push(...processLines(snapshot, true, mode, ascii));
|
|
358
|
+
else if (section === 'services') lines.push(...serviceLines(snapshot, true, mode, ascii));
|
|
359
|
+
else if (section === 'hardware') lines.push(...hardwareLines(snapshot, true, mode, ascii));
|
|
360
|
+
else if (section === 'device') lines.push(...deviceLines(snapshot, mode, true));
|
|
361
|
+
else lines.push(...detailLines(selected, ' ', mode, ascii));
|
|
362
|
+
lines.push('', 'Sources and scope:');
|
|
363
|
+
lines.push(...detailLines(snapshot.sources ?? {}));
|
|
364
|
+
return lines.map(line => fitTerminalLine(line)).join('\n');
|
|
365
|
+
}
|
|
366
|
+
const alerts = healthItems(snapshot);
|
|
367
|
+
const critical = alerts.filter(item => item.level === 'critical').length;
|
|
368
|
+
const warning = alerts.filter(item => item.level === 'warning').length;
|
|
369
|
+
lines.push('');
|
|
370
|
+
const status = [critical ? critical + ' critical' : null, warning ? warning + ' warning' : null].filter(Boolean).join(' · ');
|
|
371
|
+
lines.push('STATUS ' + (status || paint('all clear', 'green', mode)));
|
|
372
|
+
const alertRows = alerts.filter(item => item.level !== 'ok').map(alert => ({ level: alert.level === 'critical' ? '[!!]' : '[! ]', item: alert.name, detail: alert.detail }));
|
|
373
|
+
if (alertRows.length) lines.push(...table(alertRows, ['level', 'item', 'detail'], ' ', mode, ascii, { labels: ['Level', 'Item', 'Detail'] }));
|
|
374
|
+
if (!critical && !warning) lines.push(' ' + paint('[ok] No threshold alerts', 'green', mode));
|
|
375
|
+
lines.push('', sectionHeader('device', mode), ...deviceLines(snapshot, mode, full));
|
|
376
|
+
lines.push('', sectionHeader('network', mode), ...networkLines(snapshot, full, mode, ascii));
|
|
377
|
+
lines.push('', ...hardwareLines(snapshot, full, mode, ascii));
|
|
378
|
+
lines.push('', ...processLines(snapshot, full, mode, ascii));
|
|
379
|
+
lines.push('', ...serviceLines(snapshot, full, mode, ascii));
|
|
380
|
+
const app = snapshot.activeApplication;
|
|
381
|
+
lines.push('', paint('FOREGROUND', 'gold', mode) + ' ' + (app?.available ? app.name ?? 'unavailable' : 'unavailable' + (app?.reason ? ' (' + app.reason + ')' : '')));
|
|
382
|
+
lines.push('', paint(rule(60, ascii), 'gold', mode));
|
|
383
|
+
lines.push('Full detail: si-hawk inv --full · Raw data: si-hawk inv --json');
|
|
384
|
+
lines.push(sourcesLine(snapshot));
|
|
385
|
+
if (full) {
|
|
386
|
+
lines.push('', 'Sources and scope:');
|
|
387
|
+
lines.push(...detailLines(snapshot.sources ?? {}));
|
|
388
|
+
}
|
|
389
|
+
return lines.map(line => fitTerminalLine(line)).join('\n');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export function renderScanReport(report, { full = false, color = false, ascii = false, command = 'si-hawk evo' } = {}) {
|
|
393
|
+
const mode = color ? (color === true ? 'basic' : color) : null;
|
|
394
|
+
const lines = [paint('SI-HAWK · ' + command + ' · ' + (report.observedAt ? new Date(report.observedAt).toISOString().slice(0, 16).replace('T', ' ') + ' UTC' : 'time unavailable'), 'gold', mode), paint(rule(60, ascii), 'gold', mode)];
|
|
395
|
+
for (const [label, result, key, cols] of [
|
|
396
|
+
['Wi-Fi access points', report.wifi, 'networks', ['ssid', 'bssid', 'signalPercent', 'channel', 'securityType', 'radioType']],
|
|
397
|
+
['Bluetooth LE devices', report.bluetooth, 'devices', ['name', 'address', 'signalDbm']],
|
|
398
|
+
]) {
|
|
399
|
+
lines.push('', sectionHeader(label, mode));
|
|
400
|
+
if (!result?.available) {
|
|
401
|
+
lines.push(' unavailable' + (result?.reason ? ' — ' + result.reason : ''));
|
|
402
|
+
if (result?.source) lines.push(' Source: ' + result.source);
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
const rows = result[key] ?? [];
|
|
406
|
+
lines.push(' ' + rows.length + ' found');
|
|
407
|
+
const visible = full ? rows : rows.slice(0, 5);
|
|
408
|
+
if (visible.length) lines.push(...table(visible, cols, ' ', mode, ascii, { labels: label === 'Wi-Fi access points' ? ['SSID', 'BSSID', 'Signal', 'Channel', 'Security', 'Radio'] : ['Device', 'Address', 'Signal'] }));
|
|
409
|
+
else lines.push(' none reported' + (result.reason ? ' — ' + result.reason : ''));
|
|
410
|
+
if (!full && rows.length > visible.length) lines.push(' … ' + (rows.length - visible.length) + ' more (' + command + ' --full)');
|
|
411
|
+
if (full) lines.push(' Source: ' + (result.source ?? 'unavailable'), ' Scope: ' + (result.scope ?? 'unavailable'));
|
|
412
|
+
}
|
|
413
|
+
lines.push('', paint(rule(60, ascii), 'gold', mode), 'Full detail: ' + command + ' --full · Raw data: ' + command + ' --json');
|
|
414
|
+
lines.push('Sources: ' + [report.wifi?.source, report.bluetooth?.source].filter(Boolean).join(', '));
|
|
415
|
+
return lines.map(line => fitTerminalLine(line)).join('\n');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export function jsonFileArgument(args = []) {
|
|
419
|
+
const index = args.indexOf('--json-file');
|
|
420
|
+
return index < 0 ? null : args[index + 1] ?? '';
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const STANDARD_REDACTED_KEYS = new Set(['address', 'bssid', 'mac', 'ip', 'ipv4', 'ipv6', 'serial', 'uuid', 'ssid', 'hostname', 'pid']);
|
|
424
|
+
const STRICT_REDACTED_KEYS = new Set(['name', 'displayName', 'ssid', 'model', 'hostname', 'pid']);
|
|
425
|
+
|
|
426
|
+
/** Return a copy suitable for sharing, with device identifiers removed by default. */
|
|
427
|
+
export function redactReport(value, { mode = 'standard' } = {}) {
|
|
428
|
+
if (!['none', 'standard', 'strict'].includes(mode)) throw new TypeError('redaction mode must be none, standard, or strict');
|
|
429
|
+
if (mode === 'none') return value;
|
|
430
|
+
const redact = (item, key = '') => {
|
|
431
|
+
if (item === null || item === undefined || typeof item !== 'object') {
|
|
432
|
+
return item;
|
|
433
|
+
}
|
|
434
|
+
if (Array.isArray(item)) return item.map(entry => redact(entry));
|
|
435
|
+
const result = {};
|
|
436
|
+
for (const [childKey, childValue] of Object.entries(item)) {
|
|
437
|
+
const contextualName = childKey === 'name' && ['host', 'deviceIdentity'].includes(key);
|
|
438
|
+
if (STANDARD_REDACTED_KEYS.has(childKey.toLowerCase()) || contextualName || (mode === 'strict' && STRICT_REDACTED_KEYS.has(childKey))) {
|
|
439
|
+
result[childKey] = '[redacted]';
|
|
440
|
+
} else {
|
|
441
|
+
result[childKey] = redact(childValue, childKey, key);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return result;
|
|
445
|
+
};
|
|
446
|
+
return redact(value);
|
|
447
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { parseUserAgent, detectDevice } from './detect.js';
|
|
2
|
+
import { detectCapabilities } from './capabilities.js';
|
|
3
|
+
import { generateFingerprint } from './fingerprint.js';
|
|
4
|
+
import { tryFn } from './util.js';
|
|
5
|
+
import { snapshotNode } from './node.js';
|
|
6
|
+
import { scanNearby } from './scan.js';
|
|
7
|
+
|
|
8
|
+
export function detect(env = globalThis) {
|
|
9
|
+
const e = env || {};
|
|
10
|
+
const nav = tryFn(() => e.navigator || {}, {});
|
|
11
|
+
const ua = tryFn(() => nav.userAgent || '', '');
|
|
12
|
+
const parsed = parseUserAgent(ua);
|
|
13
|
+
const device = detectDevice(e);
|
|
14
|
+
const capabilities = detectCapabilities(e);
|
|
15
|
+
return { ...parsed, ...device, ...capabilities };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function fingerprint(env = globalThis) {
|
|
19
|
+
return generateFingerprint(env || {});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function snapshot(env = globalThis) {
|
|
23
|
+
return {
|
|
24
|
+
detect: detect(env),
|
|
25
|
+
fingerprint: fingerprint(env),
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Subscribes to environment changes. Returns an unsubscribe function.
|
|
32
|
+
*
|
|
33
|
+
* Supported event types:
|
|
34
|
+
* - 'visibility' — { hidden }
|
|
35
|
+
* - 'network' — { online }
|
|
36
|
+
* - 'connection' — { effectiveType, downlink, rtt }
|
|
37
|
+
* - 'battery' — { charging, level }
|
|
38
|
+
*
|
|
39
|
+
* @param {(event: object) => void} callback
|
|
40
|
+
* @param {object} [env=globalThis]
|
|
41
|
+
* @returns {() => void} Unsubscribe function.
|
|
42
|
+
*/
|
|
43
|
+
export function monitor(callback, env = globalThis) {
|
|
44
|
+
if (typeof callback !== 'function') throw new TypeError('callback must be a function');
|
|
45
|
+
env = env || globalThis;
|
|
46
|
+
const listeners = [];
|
|
47
|
+
const nav = tryFn(() => env.navigator || {}, {});
|
|
48
|
+
const doc = tryFn(() => env.document || {}, {});
|
|
49
|
+
|
|
50
|
+
let unsubscribed = false;
|
|
51
|
+
let batteryRef = null;
|
|
52
|
+
let batteryPromise = null;
|
|
53
|
+
|
|
54
|
+
const visibilityHandler = () => {
|
|
55
|
+
if (unsubscribed) return;
|
|
56
|
+
try {
|
|
57
|
+
callback({ type: 'visibility', hidden: tryFn(() => doc.hidden, false) });
|
|
58
|
+
} catch { /* swallow callback errors to keep monitor alive */ }
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const onlineHandler = (event) => {
|
|
62
|
+
if (unsubscribed) return;
|
|
63
|
+
try {
|
|
64
|
+
const online = event?.type === 'online' ? true : event?.type === 'offline' ? false : tryFn(() => nav.onLine, null);
|
|
65
|
+
callback({ type: 'network', online });
|
|
66
|
+
} catch { /* swallow callback errors */ }
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const connectionHandler = () => {
|
|
70
|
+
if (unsubscribed) return;
|
|
71
|
+
const conn = tryFn(() => nav.connection || nav.mozConnection || nav.webkitConnection, null);
|
|
72
|
+
const detail = {
|
|
73
|
+
effectiveType: tryFn(() => conn?.effectiveType, null),
|
|
74
|
+
downlink: tryFn(() => conn?.downlink, null),
|
|
75
|
+
rtt: tryFn(() => conn?.rtt, null),
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
callback({ type: 'connection', ...detail });
|
|
79
|
+
} catch { /* swallow callback errors */ }
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const batteryHandler = () => {
|
|
83
|
+
if (unsubscribed || !batteryRef) return;
|
|
84
|
+
try {
|
|
85
|
+
const detail = {
|
|
86
|
+
charging: tryFn(() => batteryRef.charging, null),
|
|
87
|
+
level: tryFn(() => batteryRef.level, null),
|
|
88
|
+
};
|
|
89
|
+
callback({ type: 'battery', ...detail });
|
|
90
|
+
} catch { /* swallow callback errors */ }
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// Register visibility listener
|
|
94
|
+
tryFn(() => {
|
|
95
|
+
if (typeof doc.addEventListener === 'function') {
|
|
96
|
+
doc.addEventListener('visibilitychange', visibilityHandler);
|
|
97
|
+
listeners.push(() => tryFn(() => {
|
|
98
|
+
if (typeof doc.removeEventListener === 'function') doc.removeEventListener('visibilitychange', visibilityHandler);
|
|
99
|
+
}, null));
|
|
100
|
+
}
|
|
101
|
+
}, null);
|
|
102
|
+
|
|
103
|
+
// Register online/offline listeners
|
|
104
|
+
tryFn(() => {
|
|
105
|
+
if (typeof env.addEventListener === 'function') {
|
|
106
|
+
env.addEventListener('online', onlineHandler);
|
|
107
|
+
env.addEventListener('offline', onlineHandler);
|
|
108
|
+
listeners.push(
|
|
109
|
+
() => tryFn(() => { if (typeof env.removeEventListener === 'function') env.removeEventListener('online', onlineHandler); }, null),
|
|
110
|
+
() => tryFn(() => { if (typeof env.removeEventListener === 'function') env.removeEventListener('offline', onlineHandler); }, null)
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}, null);
|
|
114
|
+
|
|
115
|
+
// Register connection listener
|
|
116
|
+
tryFn(() => {
|
|
117
|
+
const conn = nav.connection || nav.mozConnection || nav.webkitConnection;
|
|
118
|
+
if (conn && typeof conn.addEventListener === 'function') {
|
|
119
|
+
conn.addEventListener('change', connectionHandler);
|
|
120
|
+
listeners.push(() => tryFn(() => {
|
|
121
|
+
if (typeof conn.removeEventListener === 'function') conn.removeEventListener('change', connectionHandler);
|
|
122
|
+
}, null));
|
|
123
|
+
}
|
|
124
|
+
}, null);
|
|
125
|
+
|
|
126
|
+
// Register battery listeners (async — may resolve after unsubscribe)
|
|
127
|
+
if (tryFn(() => typeof nav.getBattery === 'function', false)) {
|
|
128
|
+
batteryPromise = tryFn(() => nav.getBattery(), null);
|
|
129
|
+
if (batteryPromise) {
|
|
130
|
+
Promise.resolve(batteryPromise).then(battery => {
|
|
131
|
+
batteryRef = battery;
|
|
132
|
+
if (unsubscribed || !batteryRef) return;
|
|
133
|
+
tryFn(() => {
|
|
134
|
+
if (typeof batteryRef.addEventListener === 'function') {
|
|
135
|
+
batteryRef.addEventListener('levelchange', batteryHandler);
|
|
136
|
+
batteryRef.addEventListener('chargingchange', batteryHandler);
|
|
137
|
+
}
|
|
138
|
+
}, null);
|
|
139
|
+
}).catch(() => { /* getBattery rejected — no battery info */ });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return function unsubscribe() {
|
|
144
|
+
if (unsubscribed) return;
|
|
145
|
+
unsubscribed = true;
|
|
146
|
+
// Run all sync listener removals immediately
|
|
147
|
+
for (const remove of listeners) tryFn(() => remove(), null);
|
|
148
|
+
listeners.length = 0;
|
|
149
|
+
// If battery promise resolved, remove battery listeners
|
|
150
|
+
tryFn(() => {
|
|
151
|
+
if (batteryRef && typeof batteryRef.removeEventListener === 'function') {
|
|
152
|
+
batteryRef.removeEventListener('levelchange', batteryHandler);
|
|
153
|
+
batteryRef.removeEventListener('chargingchange', batteryHandler);
|
|
154
|
+
}
|
|
155
|
+
}, null);
|
|
156
|
+
// If battery promise hasn't resolved yet, wait for it and then remove
|
|
157
|
+
if (batteryPromise) {
|
|
158
|
+
Promise.resolve(batteryPromise).then(battery => {
|
|
159
|
+
tryFn(() => {
|
|
160
|
+
if (unsubscribed && battery && typeof battery.removeEventListener === 'function') {
|
|
161
|
+
battery.removeEventListener('levelchange', batteryHandler);
|
|
162
|
+
battery.removeEventListener('chargingchange', batteryHandler);
|
|
163
|
+
}
|
|
164
|
+
}, null);
|
|
165
|
+
}).catch(() => { /* ignore */ });
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Collect a point-in-time report about the current host device. */
|
|
171
|
+
export function hawkInv(options) {
|
|
172
|
+
return snapshotNode(options);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Observe Wi-Fi access points and passive Bluetooth LE advertisements nearby. */
|
|
176
|
+
export function hawkEvo() {
|
|
177
|
+
return scanNearby();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const hawk = { detect, fingerprint, snapshot, monitor, inv: hawkInv, evo: hawkEvo };
|
|
181
|
+
export default hawk;
|
|
182
|
+
|
|
183
|
+
export { parseUserAgent, detectDevice } from './detect.js';
|
|
184
|
+
export { detectCapabilities, detectScreen, detectTouch, detectWebGL, detectAudio, detectStorage, detectNetwork, detectServiceWorker, detectBattery, detectPerformance } from './capabilities.js';
|
|
185
|
+
export { generateFingerprint, djb2 } from './fingerprint.js';
|
|
186
|
+
export { detectNode, snapshotNode, fingerprintNode } from './node.js';
|
|
187
|
+
export { watchNode, compareNodeSnapshots } from './monitor.js';
|
|
188
|
+
export { watchScan } from './monitor.js';
|
|
189
|
+
export { scanNearby, parseWindowsWifiScan, parseWindowsBleScan, parseIwWifiScan, parseMacWifiScan, parseHciLeScan } from './scan.js';
|
|
190
|
+
export { tryFn, isObject, isString, hasProperty } from './util.js';
|
|
191
|
+
|
|
192
|
+
|
package/src/inv.js
ADDED