nox-openclaw-hunter 1.0.0
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 +21 -0
- package/README.md +140 -0
- package/bin/nox.js +2 -0
- package/dist/branding.d.ts +39 -0
- package/dist/branding.d.ts.map +1 -0
- package/dist/branding.js +66 -0
- package/dist/branding.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +94 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/export.d.ts +21 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +616 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/index.d.ts +8 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +8 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/isolate.d.ts +30 -0
- package/dist/commands/isolate.d.ts.map +1 -0
- package/dist/commands/isolate.js +547 -0
- package/dist/commands/isolate.js.map +1 -0
- package/dist/commands/purge.d.ts +22 -0
- package/dist/commands/purge.d.ts.map +1 -0
- package/dist/commands/purge.js +295 -0
- package/dist/commands/purge.js.map +1 -0
- package/dist/commands/scan.d.ts +23 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +155 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/detector/app-bundle.d.ts +13 -0
- package/dist/detector/app-bundle.d.ts.map +1 -0
- package/dist/detector/app-bundle.js +27 -0
- package/dist/detector/app-bundle.js.map +1 -0
- package/dist/detector/cli-binary.d.ts +12 -0
- package/dist/detector/cli-binary.d.ts.map +1 -0
- package/dist/detector/cli-binary.js +66 -0
- package/dist/detector/cli-binary.js.map +1 -0
- package/dist/detector/config.d.ts +21 -0
- package/dist/detector/config.d.ts.map +1 -0
- package/dist/detector/config.js +337 -0
- package/dist/detector/config.js.map +1 -0
- package/dist/detector/detection-config.d.ts +24 -0
- package/dist/detector/detection-config.d.ts.map +1 -0
- package/dist/detector/detection-config.js +242 -0
- package/dist/detector/detection-config.js.map +1 -0
- package/dist/detector/docker.d.ts +10 -0
- package/dist/detector/docker.d.ts.map +1 -0
- package/dist/detector/docker.js +94 -0
- package/dist/detector/docker.js.map +1 -0
- package/dist/detector/index.d.ts +50 -0
- package/dist/detector/index.d.ts.map +1 -0
- package/dist/detector/index.js +155 -0
- package/dist/detector/index.js.map +1 -0
- package/dist/detector/network.d.ts +34 -0
- package/dist/detector/network.d.ts.map +1 -0
- package/dist/detector/network.js +205 -0
- package/dist/detector/network.js.map +1 -0
- package/dist/detector/process.d.ts +16 -0
- package/dist/detector/process.d.ts.map +1 -0
- package/dist/detector/process.js +47 -0
- package/dist/detector/process.js.map +1 -0
- package/dist/detector/service.d.ts +17 -0
- package/dist/detector/service.d.ts.map +1 -0
- package/dist/detector/service.js +51 -0
- package/dist/detector/service.js.map +1 -0
- package/dist/enforcer/docker-cleaner.d.ts +30 -0
- package/dist/enforcer/docker-cleaner.d.ts.map +1 -0
- package/dist/enforcer/docker-cleaner.js +163 -0
- package/dist/enforcer/docker-cleaner.js.map +1 -0
- package/dist/enforcer/file-remover.d.ts +34 -0
- package/dist/enforcer/file-remover.d.ts.map +1 -0
- package/dist/enforcer/file-remover.js +137 -0
- package/dist/enforcer/file-remover.js.map +1 -0
- package/dist/enforcer/index.d.ts +33 -0
- package/dist/enforcer/index.d.ts.map +1 -0
- package/dist/enforcer/index.js +142 -0
- package/dist/enforcer/index.js.map +1 -0
- package/dist/enforcer/process-killer.d.ts +18 -0
- package/dist/enforcer/process-killer.d.ts.map +1 -0
- package/dist/enforcer/process-killer.js +80 -0
- package/dist/enforcer/process-killer.js.map +1 -0
- package/dist/enforcer/service-stopper.d.ts +23 -0
- package/dist/enforcer/service-stopper.d.ts.map +1 -0
- package/dist/enforcer/service-stopper.js +95 -0
- package/dist/enforcer/service-stopper.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/isolator/firewall.d.ts +25 -0
- package/dist/isolator/firewall.d.ts.map +1 -0
- package/dist/isolator/firewall.js +114 -0
- package/dist/isolator/firewall.js.map +1 -0
- package/dist/isolator/index.d.ts +63 -0
- package/dist/isolator/index.d.ts.map +1 -0
- package/dist/isolator/index.js +201 -0
- package/dist/isolator/index.js.map +1 -0
- package/dist/isolator/lockdown.d.ts +22 -0
- package/dist/isolator/lockdown.d.ts.map +1 -0
- package/dist/isolator/lockdown.js +401 -0
- package/dist/isolator/lockdown.js.map +1 -0
- package/dist/isolator/quarantine.d.ts +39 -0
- package/dist/isolator/quarantine.d.ts.map +1 -0
- package/dist/isolator/quarantine.js +364 -0
- package/dist/isolator/quarantine.js.map +1 -0
- package/dist/mdm/index.d.ts +93 -0
- package/dist/mdm/index.d.ts.map +1 -0
- package/dist/mdm/index.js +414 -0
- package/dist/mdm/index.js.map +1 -0
- package/dist/mdm/intune.d.ts +69 -0
- package/dist/mdm/intune.d.ts.map +1 -0
- package/dist/mdm/intune.js +409 -0
- package/dist/mdm/intune.js.map +1 -0
- package/dist/mdm/jamf.d.ts +58 -0
- package/dist/mdm/jamf.d.ts.map +1 -0
- package/dist/mdm/jamf.js +441 -0
- package/dist/mdm/jamf.js.map +1 -0
- package/dist/mdm/jumpcloud.d.ts +73 -0
- package/dist/mdm/jumpcloud.d.ts.map +1 -0
- package/dist/mdm/jumpcloud.js +470 -0
- package/dist/mdm/jumpcloud.js.map +1 -0
- package/dist/mdm/templates/detect.ps1.d.ts +30 -0
- package/dist/mdm/templates/detect.ps1.d.ts.map +1 -0
- package/dist/mdm/templates/detect.ps1.js +463 -0
- package/dist/mdm/templates/detect.ps1.js.map +1 -0
- package/dist/mdm/templates/detect.sh.d.ts +30 -0
- package/dist/mdm/templates/detect.sh.d.ts.map +1 -0
- package/dist/mdm/templates/detect.sh.js +474 -0
- package/dist/mdm/templates/detect.sh.js.map +1 -0
- package/dist/mdm/templates/enforce.ps1.d.ts +33 -0
- package/dist/mdm/templates/enforce.ps1.d.ts.map +1 -0
- package/dist/mdm/templates/enforce.ps1.js +681 -0
- package/dist/mdm/templates/enforce.ps1.js.map +1 -0
- package/dist/mdm/templates/enforce.sh.d.ts +33 -0
- package/dist/mdm/templates/enforce.sh.d.ts.map +1 -0
- package/dist/mdm/templates/enforce.sh.js +591 -0
- package/dist/mdm/templates/enforce.sh.js.map +1 -0
- package/dist/platform/darwin.d.ts +6 -0
- package/dist/platform/darwin.d.ts.map +1 -0
- package/dist/platform/darwin.js +192 -0
- package/dist/platform/darwin.js.map +1 -0
- package/dist/platform/index.d.ts +43 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +27 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/platform/linux.d.ts +6 -0
- package/dist/platform/linux.d.ts.map +1 -0
- package/dist/platform/linux.js +134 -0
- package/dist/platform/linux.js.map +1 -0
- package/dist/platform/windows.d.ts +6 -0
- package/dist/platform/windows.d.ts.map +1 -0
- package/dist/platform/windows.js +134 -0
- package/dist/platform/windows.js.map +1 -0
- package/dist/reporter/console.d.ts +27 -0
- package/dist/reporter/console.d.ts.map +1 -0
- package/dist/reporter/console.js +431 -0
- package/dist/reporter/console.js.map +1 -0
- package/dist/reporter/index.d.ts +11 -0
- package/dist/reporter/index.d.ts.map +1 -0
- package/dist/reporter/index.js +13 -0
- package/dist/reporter/index.js.map +1 -0
- package/dist/reporter/json.d.ts +61 -0
- package/dist/reporter/json.d.ts.map +1 -0
- package/dist/reporter/json.js +75 -0
- package/dist/reporter/json.js.map +1 -0
- package/dist/reporter/webhook.d.ts +57 -0
- package/dist/reporter/webhook.d.ts.map +1 -0
- package/dist/reporter/webhook.js +230 -0
- package/dist/reporter/webhook.js.map +1 -0
- package/dist/types/config.d.ts +116 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +6 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/detection.d.ts +85 -0
- package/dist/types/detection.d.ts.map +1 -0
- package/dist/types/detection.js +5 -0
- package/dist/types/detection.js.map +1 -0
- package/dist/types/enforcement.d.ts +33 -0
- package/dist/types/enforcement.d.ts.map +1 -0
- package/dist/types/enforcement.js +5 -0
- package/dist/types/enforcement.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/isolation.d.ts +55 -0
- package/dist/types/isolation.d.ts.map +1 -0
- package/dist/types/isolation.js +5 -0
- package/dist/types/isolation.js.map +1 -0
- package/dist/utils/exec.d.ts +48 -0
- package/dist/utils/exec.d.ts.map +1 -0
- package/dist/utils/exec.js +103 -0
- package/dist/utils/exec.js.map +1 -0
- package/dist/utils/fs.d.ts +34 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +111 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +48 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/intune.md +390 -0
- package/docs/jamf.md +400 -0
- package/docs/jumpcloud.md +510 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation.d.ts","sourceRoot":"","sources":["../../src/types/isolation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,GAAG,UAAU,CAAC;AAE3E,MAAM,MAAM,qBAAqB,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,qBAAqB,C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
|
+
{"version":3,"file":"isolation.js","sourceRoot":"","sources":["../../src/types/isolation.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promise-based and sync shell execution with timeout support.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Sanitize a string for safe use in shell commands.
|
|
6
|
+
* Removes or escapes characters that could enable command injection.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sanitizeShellArg(arg: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Validate that a value is a safe positive integer (e.g., for PIDs, ports).
|
|
11
|
+
* Returns the number if valid, throws if invalid.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validatePositiveInt(value: unknown, name: string, max?: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Validate a port number (1-65535).
|
|
16
|
+
*/
|
|
17
|
+
export declare function validatePort(port: unknown): number;
|
|
18
|
+
/**
|
|
19
|
+
* Validate a process ID (1-max PID).
|
|
20
|
+
*/
|
|
21
|
+
export declare function validatePid(pid: unknown): number;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a service name (alphanumeric, dots, hyphens, underscores only).
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateServiceName(name: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Validate a process name for searching.
|
|
28
|
+
* Only allows alphanumeric characters, dots, hyphens, and underscores.
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateProcessName(name: string): string;
|
|
31
|
+
export interface ExecOptions {
|
|
32
|
+
timeout?: number;
|
|
33
|
+
encoding?: BufferEncoding;
|
|
34
|
+
maxBuffer?: number;
|
|
35
|
+
}
|
|
36
|
+
export interface ExecResult {
|
|
37
|
+
stdout: string;
|
|
38
|
+
stderr: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Execute a shell command asynchronously with optional timeout.
|
|
42
|
+
*/
|
|
43
|
+
export declare function exec(cmd: string, options?: ExecOptions): Promise<ExecResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Execute a shell command synchronously for quick checks.
|
|
46
|
+
*/
|
|
47
|
+
export declare function execSync(cmd: string, options?: ExecOptions): string;
|
|
48
|
+
//# sourceMappingURL=exec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAapD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAgC,GAAG,MAAM,CAQ/G;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAGhD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQxD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQxD;AAID,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CAerB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM,CAUvE"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promise-based and sync shell execution with timeout support.
|
|
3
|
+
*/
|
|
4
|
+
import { execSync as nodeExecSync, exec as nodeExec } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
const execAsync = promisify(nodeExec);
|
|
7
|
+
/**
|
|
8
|
+
* Sanitize a string for safe use in shell commands.
|
|
9
|
+
* Removes or escapes characters that could enable command injection.
|
|
10
|
+
*/
|
|
11
|
+
export function sanitizeShellArg(arg) {
|
|
12
|
+
// Remove null bytes
|
|
13
|
+
let sanitized = arg.replace(/\0/g, '');
|
|
14
|
+
// For simple alphanumeric strings with limited special chars, return as-is
|
|
15
|
+
if (/^[a-zA-Z0-9._\-/]+$/.test(sanitized)) {
|
|
16
|
+
return sanitized;
|
|
17
|
+
}
|
|
18
|
+
// Escape single quotes and wrap in single quotes for shell safety
|
|
19
|
+
// This is the safest approach for arbitrary strings
|
|
20
|
+
sanitized = sanitized.replace(/'/g, "'\\''");
|
|
21
|
+
return `'${sanitized}'`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validate that a value is a safe positive integer (e.g., for PIDs, ports).
|
|
25
|
+
* Returns the number if valid, throws if invalid.
|
|
26
|
+
*/
|
|
27
|
+
export function validatePositiveInt(value, name, max = Number.MAX_SAFE_INTEGER) {
|
|
28
|
+
const num = typeof value === 'string' ? parseInt(value, 10) : value;
|
|
29
|
+
if (typeof num !== 'number' || !Number.isInteger(num) || num <= 0 || num > max || Number.isNaN(num)) {
|
|
30
|
+
throw new Error(`Invalid ${name}: must be a positive integer (got ${value})`);
|
|
31
|
+
}
|
|
32
|
+
return num;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate a port number (1-65535).
|
|
36
|
+
*/
|
|
37
|
+
export function validatePort(port) {
|
|
38
|
+
return validatePositiveInt(port, 'port', 65535);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate a process ID (1-max PID).
|
|
42
|
+
*/
|
|
43
|
+
export function validatePid(pid) {
|
|
44
|
+
// Max PID varies by OS but 4194304 is a safe upper bound (Linux with PID ns)
|
|
45
|
+
return validatePositiveInt(pid, 'PID', 4194304);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validate a service name (alphanumeric, dots, hyphens, underscores only).
|
|
49
|
+
*/
|
|
50
|
+
export function validateServiceName(name) {
|
|
51
|
+
if (!/^[a-zA-Z0-9._\-]+$/.test(name)) {
|
|
52
|
+
throw new Error(`Invalid service name: contains disallowed characters (got ${name})`);
|
|
53
|
+
}
|
|
54
|
+
if (name.length > 256) {
|
|
55
|
+
throw new Error(`Invalid service name: too long (max 256 characters)`);
|
|
56
|
+
}
|
|
57
|
+
return name;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validate a process name for searching.
|
|
61
|
+
* Only allows alphanumeric characters, dots, hyphens, and underscores.
|
|
62
|
+
*/
|
|
63
|
+
export function validateProcessName(name) {
|
|
64
|
+
if (!/^[a-zA-Z0-9._\-]+$/.test(name)) {
|
|
65
|
+
throw new Error(`Invalid process name: contains disallowed characters (got ${name})`);
|
|
66
|
+
}
|
|
67
|
+
if (name.length > 256) {
|
|
68
|
+
throw new Error(`Invalid process name: too long (max 256 characters)`);
|
|
69
|
+
}
|
|
70
|
+
return name;
|
|
71
|
+
}
|
|
72
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
73
|
+
/**
|
|
74
|
+
* Execute a shell command asynchronously with optional timeout.
|
|
75
|
+
*/
|
|
76
|
+
export async function exec(cmd, options = {}) {
|
|
77
|
+
const timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
78
|
+
const encoding = options.encoding ?? 'utf8';
|
|
79
|
+
const maxBuffer = options.maxBuffer ?? 10 * 1024 * 1024; // 10MB
|
|
80
|
+
const { stdout, stderr } = await execAsync(cmd, {
|
|
81
|
+
encoding,
|
|
82
|
+
maxBuffer,
|
|
83
|
+
timeout,
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
stdout: String(stdout ?? ''),
|
|
87
|
+
stderr: String(stderr ?? ''),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Execute a shell command synchronously for quick checks.
|
|
92
|
+
*/
|
|
93
|
+
export function execSync(cmd, options = {}) {
|
|
94
|
+
const encoding = options.encoding ?? 'utf8';
|
|
95
|
+
const timeout = options.timeout ?? 10_000;
|
|
96
|
+
const maxBuffer = options.maxBuffer ?? 10 * 1024 * 1024;
|
|
97
|
+
return nodeExecSync(cmd, {
|
|
98
|
+
encoding: encoding,
|
|
99
|
+
maxBuffer,
|
|
100
|
+
timeout,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/utils/exec.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,oBAAoB;IACpB,IAAI,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvC,2EAA2E;IAC3E,IAAI,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,kEAAkE;IAClE,oDAAoD;IACpD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,OAAO,IAAI,SAAS,GAAG,CAAC;AAC1B,C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,SAAS;QACT,OAAO;KACR,CAAW,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system utilities with error handling.
|
|
3
|
+
*/
|
|
4
|
+
import type { RmOptions } from 'node:fs';
|
|
5
|
+
/**
|
|
6
|
+
* Validate that a path is within an allowed base directory.
|
|
7
|
+
* Prevents path traversal attacks.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validatePathWithinBase(targetPath: string, basePath: string): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Synchronous version of validatePathWithinBase.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validatePathWithinBaseSync(targetPath: string, basePath: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a file or directory exists.
|
|
16
|
+
*/
|
|
17
|
+
export declare function pathExists(path: string): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Synchronous check if a file or directory exists.
|
|
20
|
+
*/
|
|
21
|
+
export declare function pathExistsSync(path: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Remove a file or directory with error handling.
|
|
24
|
+
* For directories, uses recursive removal.
|
|
25
|
+
*/
|
|
26
|
+
export declare function safeRemove(path: string, options?: RmOptions): Promise<{
|
|
27
|
+
success: boolean;
|
|
28
|
+
error?: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Ensure a directory exists, creating it recursively if needed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function ensureDir(path: string): Promise<void>;
|
|
34
|
+
//# sourceMappingURL=fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BlG;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA2BvF;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO/D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAQ/C;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3D"}
|
package/dist/utils/fs.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File system utilities with error handling.
|
|
3
|
+
*/
|
|
4
|
+
import { accessSync, constants } from 'node:fs';
|
|
5
|
+
import { access, mkdir, rm, realpath } from 'node:fs/promises';
|
|
6
|
+
import { realpathSync } from 'node:fs';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a path is within an allowed base directory.
|
|
10
|
+
* Prevents path traversal attacks.
|
|
11
|
+
*/
|
|
12
|
+
export async function validatePathWithinBase(targetPath, basePath) {
|
|
13
|
+
// Resolve to absolute paths
|
|
14
|
+
const resolvedTarget = path.resolve(targetPath);
|
|
15
|
+
const resolvedBase = path.resolve(basePath);
|
|
16
|
+
// Check if target is within base (after resolving symlinks if they exist)
|
|
17
|
+
let realTarget;
|
|
18
|
+
try {
|
|
19
|
+
realTarget = await realpath(resolvedTarget);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// If path doesn't exist, use resolved path
|
|
23
|
+
realTarget = resolvedTarget;
|
|
24
|
+
}
|
|
25
|
+
let realBase;
|
|
26
|
+
try {
|
|
27
|
+
realBase = await realpath(resolvedBase);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
realBase = resolvedBase;
|
|
31
|
+
}
|
|
32
|
+
// Ensure the target starts with the base path
|
|
33
|
+
if (!realTarget.startsWith(realBase + path.sep) && realTarget !== realBase) {
|
|
34
|
+
throw new Error(`Path traversal detected: ${targetPath} is outside ${basePath}`);
|
|
35
|
+
}
|
|
36
|
+
return resolvedTarget;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Synchronous version of validatePathWithinBase.
|
|
40
|
+
*/
|
|
41
|
+
export function validatePathWithinBaseSync(targetPath, basePath) {
|
|
42
|
+
// Resolve to absolute paths
|
|
43
|
+
const resolvedTarget = path.resolve(targetPath);
|
|
44
|
+
const resolvedBase = path.resolve(basePath);
|
|
45
|
+
// Check if target is within base (after resolving symlinks if they exist)
|
|
46
|
+
let realTarget;
|
|
47
|
+
try {
|
|
48
|
+
realTarget = realpathSync(resolvedTarget);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// If path doesn't exist, use resolved path
|
|
52
|
+
realTarget = resolvedTarget;
|
|
53
|
+
}
|
|
54
|
+
let realBase;
|
|
55
|
+
try {
|
|
56
|
+
realBase = realpathSync(resolvedBase);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
realBase = resolvedBase;
|
|
60
|
+
}
|
|
61
|
+
// Ensure the target starts with the base path
|
|
62
|
+
if (!realTarget.startsWith(realBase + path.sep) && realTarget !== realBase) {
|
|
63
|
+
throw new Error(`Path traversal detected: ${targetPath} is outside ${basePath}`);
|
|
64
|
+
}
|
|
65
|
+
return resolvedTarget;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if a file or directory exists.
|
|
69
|
+
*/
|
|
70
|
+
export async function pathExists(path) {
|
|
71
|
+
try {
|
|
72
|
+
await access(path, constants.F_OK);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Synchronous check if a file or directory exists.
|
|
81
|
+
*/
|
|
82
|
+
export function pathExistsSync(path) {
|
|
83
|
+
try {
|
|
84
|
+
accessSync(path, constants.F_OK);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Remove a file or directory with error handling.
|
|
93
|
+
* For directories, uses recursive removal.
|
|
94
|
+
*/
|
|
95
|
+
export async function safeRemove(path, options = {}) {
|
|
96
|
+
try {
|
|
97
|
+
await rm(path, { recursive: true, force: true, ...options });
|
|
98
|
+
return { success: true };
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
102
|
+
return { success: false, error: message };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Ensure a directory exists, creating it recursively if needed.
|
|
107
|
+
*/
|
|
108
|
+
export async function ensureDir(path) {
|
|
109
|
+
await mkdir(path, { recursive: true });
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC;;;GAGG;AAC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AG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC5C,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAY;IAC1C,MAAM,KAAK,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colored console output with log levels.
|
|
3
|
+
*/
|
|
4
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
6
|
+
export declare function getLogLevel(): LogLevel;
|
|
7
|
+
export declare const logger: {
|
|
8
|
+
debug(message: string, ...args: unknown[]): void;
|
|
9
|
+
info(message: string, ...args: unknown[]): void;
|
|
10
|
+
warn(message: string, ...args: unknown[]): void;
|
|
11
|
+
error(message: string, ...args: unknown[]): void;
|
|
12
|
+
success(message: string, ...args: unknown[]): void;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAW3D,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAEjD;AAED,wBAAgB,WAAW,IAAI,QAAQ,CAEtC;AAMD,eAAO,MAAM,MAAM;mBACF,MAAM,WAAW,OAAO,EAAE,GAAG,IAAI;kBAMlC,MAAM,WAAW,OAAO,EAAE,GAAG,IAAI;kBAMjC,MAAM,WAAW,OAAO,EAAE,GAAG,IAAI;mBAMhC,MAAM,WAAW,OAAO,EAAE,GAAG,IAAI;qBAM/B,MAAM,WAAW,OAAO,EAAE,GAAG,IAAI;CAKnD,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colored console output with log levels.
|
|
3
|
+
*/
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
const LEVEL_ORDER = {
|
|
6
|
+
debug: 0,
|
|
7
|
+
info: 1,
|
|
8
|
+
warn: 2,
|
|
9
|
+
error: 3,
|
|
10
|
+
};
|
|
11
|
+
let minLevel = 'info';
|
|
12
|
+
export function setLogLevel(level) {
|
|
13
|
+
minLevel = level;
|
|
14
|
+
}
|
|
15
|
+
export function getLogLevel() {
|
|
16
|
+
return minLevel;
|
|
17
|
+
}
|
|
18
|
+
function shouldLog(level) {
|
|
19
|
+
return LEVEL_ORDER[level] >= LEVEL_ORDER[minLevel];
|
|
20
|
+
}
|
|
21
|
+
export const logger = {
|
|
22
|
+
debug(message, ...args) {
|
|
23
|
+
if (shouldLog('debug')) {
|
|
24
|
+
console.debug(chalk.gray('[debug]'), message, ...args);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
info(message, ...args) {
|
|
28
|
+
if (shouldLog('info')) {
|
|
29
|
+
console.info(chalk.blue('ℹ'), message, ...args);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
warn(message, ...args) {
|
|
33
|
+
if (shouldLog('warn')) {
|
|
34
|
+
console.warn(chalk.yellow('⚠'), message, ...args);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
error(message, ...args) {
|
|
38
|
+
if (shouldLog('error')) {
|
|
39
|
+
console.error(chalk.red('✖'), message, ...args);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
success(message, ...args) {
|
|
43
|
+
if (shouldLog('info')) {
|
|
44
|
+
console.info(chalk.green('✓'), message, ...args);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,GAA6B;IAC5C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,IAAI,QAAQ,GAAa,MAAM,CAAC;AAEhC,MAAM,UAAU,WAAW,CAAC,KAAe;IACzC,QAAQ,GAAG,KAAK,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW;IACzB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,SAAS,CAAC,KAAe;IAChC,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,C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