about-system 0.0.18 → 0.0.19

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Internal type definitions
3
+ * @module internal-types
4
+ */
5
+
6
+ import type { Cache, CacheEntry } from "../cache/cache";
7
+ import type { IPInfo } from "../utils/network";
8
+
9
+ /**
10
+ * Context object passed to info collection functions
11
+ * @interface InfoContext
12
+ */
13
+ export interface InfoContext {
14
+ /** Cache storage */
15
+ cache: Cache;
16
+ /** IP information from external API */
17
+ ipInfo?: IPInfo;
18
+ }
19
+
20
+ // Re-export cache types for convenience
21
+ export type { Cache, CacheEntry };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Command execution utilities
3
+ * @module command
4
+ */
5
+
6
+ import { execSync } from "child_process";
7
+ import { IS_WINDOWS } from "./platform";
8
+
9
+ /**
10
+ * Executes a shell command safely with timeout
11
+ * @param {string} command - Command to execute
12
+ * @param {object} options - Additional options for execSync
13
+ * @returns {string} Command output or empty string on error
14
+ */
15
+ export function execCommand(command: string, options = {}): string {
16
+ try {
17
+ const cmd = IS_WINDOWS ? `cmd /c ${command}` : command;
18
+ return execSync(cmd, {
19
+ encoding: "utf8",
20
+ timeout: 10000,
21
+ stdio: ["pipe", "pipe", "ignore"],
22
+ ...options,
23
+ })
24
+ .toString()
25
+ .trim();
26
+ } catch (error) {
27
+ return "";
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Checks if a command exists in the system PATH
33
+ * @param {string} command - Command name to check
34
+ * @returns {boolean} True if command exists
35
+ */
36
+ export function commandExists(command: string): boolean {
37
+ try {
38
+ if (IS_WINDOWS) {
39
+ execSync(`where ${command}`, { stdio: "ignore" });
40
+ } else {
41
+ execSync(`which ${command}`, { stdio: "ignore" });
42
+ }
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Network utilities for IP information fetching
3
+ * @module network
4
+ */
5
+
6
+ import https from "https";
7
+ import {
8
+ DEFAULT_IPINFO_TOKEN,
9
+ DEFAULT_NETWORK_TIMEOUT,
10
+ } from "../cache/cache-config";
11
+
12
+ /**
13
+ * IP information from ipinfo.io API
14
+ * @interface IPInfo
15
+ */
16
+ export interface IPInfo {
17
+ /** Public IP address */
18
+ ip?: string;
19
+ /** City location */
20
+ city?: string;
21
+ /** Reverse DNS hostname */
22
+ hostname?: string;
23
+ /** ISP organization string (includes AS number) */
24
+ org?: string;
25
+ }
26
+
27
+ /**
28
+ * Fetches IP geolocation information from ipinfo.io API
29
+ * @param {string} token - IPInfo.io API token
30
+ * @param {number} timeout - Request timeout in milliseconds
31
+ * @returns {Promise<IPInfo>} IP information object or empty object on error
32
+ */
33
+ export async function fetchIPInfo(
34
+ token: string = DEFAULT_IPINFO_TOKEN,
35
+ timeout: number = DEFAULT_NETWORK_TIMEOUT
36
+ ): Promise<IPInfo> {
37
+ return new Promise((resolve) => {
38
+ const url = `https://ipinfo.io/json${token ? `?token=${token}` : ""}`;
39
+
40
+ const req = https.get(url, (res) => {
41
+ let data = "";
42
+ res.on("data", (chunk) => (data += chunk));
43
+ res.on("end", () => {
44
+ try {
45
+ resolve(JSON.parse(data));
46
+ } catch {
47
+ resolve({});
48
+ }
49
+ });
50
+ });
51
+
52
+ req.on("error", () => resolve({}));
53
+ req.setTimeout(timeout, () => {
54
+ req.destroy();
55
+ resolve({});
56
+ });
57
+ });
58
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Platform detection utilities
3
+ * @module platform
4
+ */
5
+
6
+ import os from "os";
7
+
8
+ /**
9
+ * Platform detection constants
10
+ */
11
+ export const IS_WINDOWS = os.platform() === "win32";
12
+ export const IS_MAC = os.platform() === "darwin";
13
+ export const IS_LINUX = os.platform() === "linux";