@mainwp/control 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 +674 -0
- package/README.md +583 -0
- package/bin/_exit.js +12 -0
- package/bin/dev.js +7 -0
- package/bin/run.js +7 -0
- package/dist/chat/chat-engine.d.ts +213 -0
- package/dist/chat/chat-engine.d.ts.map +1 -0
- package/dist/chat/chat-engine.js +636 -0
- package/dist/chat/chat-engine.js.map +1 -0
- package/dist/chat/index.d.ts +10 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +14 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/providers/anthropic.d.ts +52 -0
- package/dist/chat/providers/anthropic.d.ts.map +1 -0
- package/dist/chat/providers/anthropic.js +292 -0
- package/dist/chat/providers/anthropic.js.map +1 -0
- package/dist/chat/providers/gemini.d.ts +52 -0
- package/dist/chat/providers/gemini.d.ts.map +1 -0
- package/dist/chat/providers/gemini.js +284 -0
- package/dist/chat/providers/gemini.js.map +1 -0
- package/dist/chat/providers/index.d.ts +19 -0
- package/dist/chat/providers/index.d.ts.map +1 -0
- package/dist/chat/providers/index.js +23 -0
- package/dist/chat/providers/index.js.map +1 -0
- package/dist/chat/providers/local.d.ts +37 -0
- package/dist/chat/providers/local.d.ts.map +1 -0
- package/dist/chat/providers/local.js +130 -0
- package/dist/chat/providers/local.js.map +1 -0
- package/dist/chat/providers/openai-compatible.d.ts +155 -0
- package/dist/chat/providers/openai-compatible.d.ts.map +1 -0
- package/dist/chat/providers/openai-compatible.js +264 -0
- package/dist/chat/providers/openai-compatible.js.map +1 -0
- package/dist/chat/providers/openai.d.ts +24 -0
- package/dist/chat/providers/openai.d.ts.map +1 -0
- package/dist/chat/providers/openai.js +62 -0
- package/dist/chat/providers/openai.js.map +1 -0
- package/dist/chat/providers/openrouter.d.ts +26 -0
- package/dist/chat/providers/openrouter.d.ts.map +1 -0
- package/dist/chat/providers/openrouter.js +65 -0
- package/dist/chat/providers/openrouter.js.map +1 -0
- package/dist/chat/providers/provider-fetch.d.ts +15 -0
- package/dist/chat/providers/provider-fetch.d.ts.map +1 -0
- package/dist/chat/providers/provider-fetch.js +35 -0
- package/dist/chat/providers/provider-fetch.js.map +1 -0
- package/dist/chat/providers/provider.d.ts +214 -0
- package/dist/chat/providers/provider.d.ts.map +1 -0
- package/dist/chat/providers/provider.js +166 -0
- package/dist/chat/providers/provider.js.map +1 -0
- package/dist/chat/providers/sse-reader.d.ts +21 -0
- package/dist/chat/providers/sse-reader.d.ts.map +1 -0
- package/dist/chat/providers/sse-reader.js +48 -0
- package/dist/chat/providers/sse-reader.js.map +1 -0
- package/dist/chat/system-prompt.d.ts +33 -0
- package/dist/chat/system-prompt.d.ts.map +1 -0
- package/dist/chat/system-prompt.js +166 -0
- package/dist/chat/system-prompt.js.map +1 -0
- package/dist/chat/tool-envelope.d.ts +72 -0
- package/dist/chat/tool-envelope.d.ts.map +1 -0
- package/dist/chat/tool-envelope.js +263 -0
- package/dist/chat/tool-envelope.js.map +1 -0
- package/dist/commands/abilities/info.d.ts +21 -0
- package/dist/commands/abilities/info.d.ts.map +1 -0
- package/dist/commands/abilities/info.js +80 -0
- package/dist/commands/abilities/info.js.map +1 -0
- package/dist/commands/abilities/list.d.ts +19 -0
- package/dist/commands/abilities/list.d.ts.map +1 -0
- package/dist/commands/abilities/list.js +98 -0
- package/dist/commands/abilities/list.js.map +1 -0
- package/dist/commands/abilities/run.d.ts +75 -0
- package/dist/commands/abilities/run.d.ts.map +1 -0
- package/dist/commands/abilities/run.js +468 -0
- package/dist/commands/abilities/run.js.map +1 -0
- package/dist/commands/chat.d.ts +54 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +384 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config/show.d.ts +54 -0
- package/dist/commands/config/show.d.ts.map +1 -0
- package/dist/commands/config/show.js +324 -0
- package/dist/commands/config/show.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +412 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/jobs/watch.d.ts +50 -0
- package/dist/commands/jobs/watch.d.ts.map +1 -0
- package/dist/commands/jobs/watch.js +269 -0
- package/dist/commands/jobs/watch.js.map +1 -0
- package/dist/commands/login.d.ts +25 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +165 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/profile/delete.d.ts +22 -0
- package/dist/commands/profile/delete.d.ts.map +1 -0
- package/dist/commands/profile/delete.js +57 -0
- package/dist/commands/profile/delete.js.map +1 -0
- package/dist/commands/profile/list.d.ts +19 -0
- package/dist/commands/profile/list.d.ts.map +1 -0
- package/dist/commands/profile/list.js +53 -0
- package/dist/commands/profile/list.js.map +1 -0
- package/dist/commands/profile/use.d.ts +22 -0
- package/dist/commands/profile/use.d.ts.map +1 -0
- package/dist/commands/profile/use.js +46 -0
- package/dist/commands/profile/use.js.map +1 -0
- package/dist/config/fs-utils.d.ts +14 -0
- package/dist/config/fs-utils.d.ts.map +1 -0
- package/dist/config/fs-utils.js +31 -0
- package/dist/config/fs-utils.js.map +1 -0
- package/dist/config/keychain.d.ts +53 -0
- package/dist/config/keychain.d.ts.map +1 -0
- package/dist/config/keychain.js +175 -0
- package/dist/config/keychain.js.map +1 -0
- package/dist/config/profile-store.d.ts +85 -0
- package/dist/config/profile-store.d.ts.map +1 -0
- package/dist/config/profile-store.js +228 -0
- package/dist/config/profile-store.js.map +1 -0
- package/dist/config/settings.d.ts +71 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +151 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/core/abilities-executor.d.ts +126 -0
- package/dist/core/abilities-executor.d.ts.map +1 -0
- package/dist/core/abilities-executor.js +264 -0
- package/dist/core/abilities-executor.js.map +1 -0
- package/dist/core/batch-manager.d.ts +113 -0
- package/dist/core/batch-manager.d.ts.map +1 -0
- package/dist/core/batch-manager.js +244 -0
- package/dist/core/batch-manager.js.map +1 -0
- package/dist/core/http-client.d.ts +111 -0
- package/dist/core/http-client.d.ts.map +1 -0
- package/dist/core/http-client.js +329 -0
- package/dist/core/http-client.js.map +1 -0
- package/dist/core/safety-controller.d.ts +114 -0
- package/dist/core/safety-controller.d.ts.map +1 -0
- package/dist/core/safety-controller.js +229 -0
- package/dist/core/safety-controller.js.map +1 -0
- package/dist/hooks/command-not-found.d.ts +12 -0
- package/dist/hooks/command-not-found.d.ts.map +1 -0
- package/dist/hooks/command-not-found.js +58 -0
- package/dist/hooks/command-not-found.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-command.d.ts +123 -0
- package/dist/lib/base-command.d.ts.map +1 -0
- package/dist/lib/base-command.js +285 -0
- package/dist/lib/base-command.js.map +1 -0
- package/dist/output/formatter.d.ts +48 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +138 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/json-envelope.d.ts +43 -0
- package/dist/output/json-envelope.d.ts.map +1 -0
- package/dist/output/json-envelope.js +73 -0
- package/dist/output/json-envelope.js.map +1 -0
- package/dist/utils/audit-logger.d.ts +97 -0
- package/dist/utils/audit-logger.d.ts.map +1 -0
- package/dist/utils/audit-logger.js +169 -0
- package/dist/utils/audit-logger.js.map +1 -0
- package/dist/utils/colors.d.ts +29 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/colors.js +36 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/errors.d.ts +107 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +149 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/exit-codes.d.ts +21 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/exit-codes.js +20 -0
- package/dist/utils/exit-codes.js.map +1 -0
- package/dist/utils/format.d.ts +64 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +69 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/prompt.d.ts +34 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +132 -0
- package/dist/utils/prompt.js.map +1 -0
- package/dist/utils/retry.d.ts +59 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +96 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/terminal-sanitizer.d.ts +60 -0
- package/dist/utils/terminal-sanitizer.d.ts.map +1 -0
- package/dist/utils/terminal-sanitizer.js +166 -0
- package/dist/utils/terminal-sanitizer.js.map +1 -0
- package/dist/validation/input-sanitizer.d.ts +76 -0
- package/dist/validation/input-sanitizer.d.ts.map +1 -0
- package/dist/validation/input-sanitizer.js +199 -0
- package/dist/validation/input-sanitizer.js.map +1 -0
- package/dist/validation/schema-validator.d.ts +75 -0
- package/dist/validation/schema-validator.d.ts.map +1 -0
- package/dist/validation/schema-validator.js +147 -0
- package/dist/validation/schema-validator.js.map +1 -0
- package/oclif.manifest.json +857 -0
- package/package.json +101 -0
- package/scripts/completions/README.md +221 -0
- package/scripts/completions/mainwpcontrol.bash +193 -0
- package/scripts/completions/mainwpcontrol.zsh +267 -0
- package/scripts/completions/profile-completer.sh +35 -0
- package/scripts/completions/regenerate.sh +78 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Logger for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Logs all destructive actions with preview, user decision, and execution result.
|
|
5
|
+
*
|
|
6
|
+
* Log location: ~/.config/mainwpcontrol/audit.log
|
|
7
|
+
* Format: Newline-delimited JSON (NDJSON)
|
|
8
|
+
* Rotation: When file exceeds 10MB, rotates to audit.log.1, audit.log.2, etc.
|
|
9
|
+
* Retention: Keeps last 5 rotated files
|
|
10
|
+
*
|
|
11
|
+
* Sensitive data (passwords, tokens, API keys) is automatically redacted.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Audit entry structure
|
|
15
|
+
*/
|
|
16
|
+
export interface AuditEntry {
|
|
17
|
+
/** ISO 8601 timestamp */
|
|
18
|
+
timestamp: string;
|
|
19
|
+
/** Name of the ability executed */
|
|
20
|
+
abilityName: string;
|
|
21
|
+
/** Preview information (optional - not available in CLI executeDestructive path) */
|
|
22
|
+
preview?: {
|
|
23
|
+
summary: string;
|
|
24
|
+
affectedCount: number;
|
|
25
|
+
};
|
|
26
|
+
/** User's decision */
|
|
27
|
+
userDecision: 'approved' | 'declined';
|
|
28
|
+
/** Execution result (only present when approved) */
|
|
29
|
+
execution?: {
|
|
30
|
+
success: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
/** Input parameters (redacted of sensitive data) */
|
|
34
|
+
input: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Input for logging a destructive action
|
|
38
|
+
*/
|
|
39
|
+
export interface LogDestructiveActionInput {
|
|
40
|
+
abilityName: string;
|
|
41
|
+
preview?: {
|
|
42
|
+
summary: string;
|
|
43
|
+
affectedCount: number;
|
|
44
|
+
};
|
|
45
|
+
userDecision: 'approved' | 'declined';
|
|
46
|
+
execution?: {
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
};
|
|
50
|
+
input: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get the audit log file path
|
|
54
|
+
*/
|
|
55
|
+
export declare function getAuditLogPath(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Audit Logger class
|
|
58
|
+
*/
|
|
59
|
+
export declare class AuditLogger {
|
|
60
|
+
private readonly inputSanitizer;
|
|
61
|
+
/**
|
|
62
|
+
* Log a destructive action
|
|
63
|
+
*
|
|
64
|
+
* SECURITY: Uses restricted permissions for audit logs.
|
|
65
|
+
*
|
|
66
|
+
* @param params - Action details to log
|
|
67
|
+
*/
|
|
68
|
+
logDestructiveAction(params: LogDestructiveActionInput): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Ensure log file exists with proper permissions
|
|
71
|
+
*
|
|
72
|
+
* SECURITY: Creates file with 0o600 (owner read/write only) if it doesn't exist.
|
|
73
|
+
*/
|
|
74
|
+
private ensureLogFile;
|
|
75
|
+
/**
|
|
76
|
+
* Check if the log file should be rotated
|
|
77
|
+
*/
|
|
78
|
+
private shouldRotate;
|
|
79
|
+
/**
|
|
80
|
+
* Rotate log files
|
|
81
|
+
*
|
|
82
|
+
* Rotation sequence: audit.log → audit.log.1 → audit.log.2 → ... → audit.log.5
|
|
83
|
+
* Oldest rotation (audit.log.5) is deleted
|
|
84
|
+
*/
|
|
85
|
+
private rotateLogFile;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the audit logger singleton
|
|
89
|
+
*/
|
|
90
|
+
export declare function getAuditLogger(): AuditLogger;
|
|
91
|
+
/**
|
|
92
|
+
* Fire-and-forget wrapper for logDestructiveAction.
|
|
93
|
+
* Swallows errors to prevent audit logging failures from
|
|
94
|
+
* interrupting the primary execution flow.
|
|
95
|
+
*/
|
|
96
|
+
export declare function logDestructiveActionSafe(params: LogDestructiveActionInput): Promise<void>;
|
|
97
|
+
//# sourceMappingURL=audit-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-logger.d.ts","sourceRoot":"","sources":["../../src/utils/audit-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAsBH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,oFAAoF;IACpF,OAAO,CAAC,EAAE;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,sBAAsB;IACtB,YAAY,EAAE,UAAU,GAAG,UAAU,CAAC;IACtC,oDAAoD;IACpD,SAAS,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE;QACR,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,YAAY,EAAE,UAAU,GAAG,UAAU,CAAC;IACtC,SAAS,CAAC,EAAE;QACV,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAuB;IAEtD;;;;;;OAMG;IACG,oBAAoB,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyC5E;;;;OAIG;YACW,aAAa;IAU3B;;OAEG;YACW,YAAY;IAU1B;;;;;OAKG;YACW,aAAa;CA2B5B;AAOD;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAGD;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit Logger for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Logs all destructive actions with preview, user decision, and execution result.
|
|
5
|
+
*
|
|
6
|
+
* Log location: ~/.config/mainwpcontrol/audit.log
|
|
7
|
+
* Format: Newline-delimited JSON (NDJSON)
|
|
8
|
+
* Rotation: When file exceeds 10MB, rotates to audit.log.1, audit.log.2, etc.
|
|
9
|
+
* Retention: Keeps last 5 rotated files
|
|
10
|
+
*
|
|
11
|
+
* Sensitive data (passwords, tokens, API keys) is automatically redacted.
|
|
12
|
+
*/
|
|
13
|
+
import { promises as fs } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { getConfigDir } from '../config/settings.js';
|
|
16
|
+
import { getInputSanitizer } from '../validation/input-sanitizer.js';
|
|
17
|
+
/**
|
|
18
|
+
* Maximum log file size before rotation (10MB)
|
|
19
|
+
*/
|
|
20
|
+
const MAX_LOG_SIZE = 10 * 1024 * 1024;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of rotated log files to keep
|
|
23
|
+
*/
|
|
24
|
+
const MAX_ROTATIONS = 5;
|
|
25
|
+
/**
|
|
26
|
+
* Audit log filename
|
|
27
|
+
*/
|
|
28
|
+
const AUDIT_LOG_FILENAME = 'audit.log';
|
|
29
|
+
/**
|
|
30
|
+
* Get the audit log file path
|
|
31
|
+
*/
|
|
32
|
+
export function getAuditLogPath() {
|
|
33
|
+
return join(getConfigDir(), AUDIT_LOG_FILENAME);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Audit Logger class
|
|
37
|
+
*/
|
|
38
|
+
export class AuditLogger {
|
|
39
|
+
inputSanitizer = getInputSanitizer();
|
|
40
|
+
/**
|
|
41
|
+
* Log a destructive action
|
|
42
|
+
*
|
|
43
|
+
* SECURITY: Uses restricted permissions for audit logs.
|
|
44
|
+
*
|
|
45
|
+
* @param params - Action details to log
|
|
46
|
+
*/
|
|
47
|
+
async logDestructiveAction(params) {
|
|
48
|
+
const logPath = getAuditLogPath();
|
|
49
|
+
// Create directory with restricted permissions (owner only)
|
|
50
|
+
const dir = getConfigDir();
|
|
51
|
+
await fs.mkdir(dir, { recursive: true, mode: 0o700 });
|
|
52
|
+
// Check if rotation is needed
|
|
53
|
+
if (await this.shouldRotate(logPath)) {
|
|
54
|
+
await this.rotateLogFile(logPath);
|
|
55
|
+
}
|
|
56
|
+
// Redact sensitive data from input
|
|
57
|
+
const redactedInput = this.inputSanitizer.redactSensitive(params.input);
|
|
58
|
+
// Build audit entry
|
|
59
|
+
const entry = {
|
|
60
|
+
timestamp: new Date().toISOString(),
|
|
61
|
+
abilityName: params.abilityName,
|
|
62
|
+
userDecision: params.userDecision,
|
|
63
|
+
input: redactedInput,
|
|
64
|
+
};
|
|
65
|
+
// Add optional fields
|
|
66
|
+
if (params.preview) {
|
|
67
|
+
entry.preview = params.preview;
|
|
68
|
+
}
|
|
69
|
+
if (params.execution) {
|
|
70
|
+
entry.execution = params.execution;
|
|
71
|
+
}
|
|
72
|
+
// Format as NDJSON line
|
|
73
|
+
const line = JSON.stringify(entry) + '\n';
|
|
74
|
+
// Ensure file exists with proper permissions before appending
|
|
75
|
+
await this.ensureLogFile(logPath);
|
|
76
|
+
// Append to log file
|
|
77
|
+
await fs.appendFile(logPath, line, 'utf-8');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Ensure log file exists with proper permissions
|
|
81
|
+
*
|
|
82
|
+
* SECURITY: Creates file with 0o600 (owner read/write only) if it doesn't exist.
|
|
83
|
+
*/
|
|
84
|
+
async ensureLogFile(logPath) {
|
|
85
|
+
try {
|
|
86
|
+
await fs.access(logPath);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// File doesn't exist, create with restricted permissions
|
|
90
|
+
const fd = await fs.open(logPath, 'w', 0o600);
|
|
91
|
+
await fd.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if the log file should be rotated
|
|
96
|
+
*/
|
|
97
|
+
async shouldRotate(logPath) {
|
|
98
|
+
try {
|
|
99
|
+
const stats = await fs.stat(logPath);
|
|
100
|
+
return stats.size > MAX_LOG_SIZE;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// File doesn't exist yet
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Rotate log files
|
|
109
|
+
*
|
|
110
|
+
* Rotation sequence: audit.log → audit.log.1 → audit.log.2 → ... → audit.log.5
|
|
111
|
+
* Oldest rotation (audit.log.5) is deleted
|
|
112
|
+
*/
|
|
113
|
+
async rotateLogFile(logPath) {
|
|
114
|
+
// Delete oldest rotation
|
|
115
|
+
const oldestPath = `${logPath}.${MAX_ROTATIONS}`;
|
|
116
|
+
try {
|
|
117
|
+
await fs.unlink(oldestPath);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// Ignore if doesn't exist
|
|
121
|
+
}
|
|
122
|
+
// Rotate existing files (5 → delete, 4 → 5, 3 → 4, 2 → 3, 1 → 2)
|
|
123
|
+
for (let i = MAX_ROTATIONS - 1; i >= 1; i--) {
|
|
124
|
+
const from = `${logPath}.${i}`;
|
|
125
|
+
const to = `${logPath}.${i + 1}`;
|
|
126
|
+
try {
|
|
127
|
+
await fs.rename(from, to);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Ignore if doesn't exist
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Rotate current log (audit.log → audit.log.1)
|
|
134
|
+
try {
|
|
135
|
+
await fs.rename(logPath, `${logPath}.1`);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Ignore if doesn't exist
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Singleton instance
|
|
144
|
+
*/
|
|
145
|
+
let instance = null;
|
|
146
|
+
/**
|
|
147
|
+
* Get the audit logger singleton
|
|
148
|
+
*/
|
|
149
|
+
export function getAuditLogger() {
|
|
150
|
+
if (!instance) {
|
|
151
|
+
instance = new AuditLogger();
|
|
152
|
+
}
|
|
153
|
+
return instance;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Fire-and-forget wrapper for logDestructiveAction.
|
|
157
|
+
* Swallows errors to prevent audit logging failures from
|
|
158
|
+
* interrupting the primary execution flow.
|
|
159
|
+
*/
|
|
160
|
+
export async function logDestructiveActionSafe(params) {
|
|
161
|
+
try {
|
|
162
|
+
await getAuditLogger().logDestructiveAction(params);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error(`CRITICAL: [AuditLogger] Failed to log destructive action: ${error instanceof Error ? error.message : String(error)}. ` +
|
|
166
|
+
`Audit log path: ${getAuditLogPath()}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=audit-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-logger.js","sourceRoot":"","sources":["../../src/utils/audit-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE;;GAEG;AACH,MAAM,YAAY,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEtC;;GAEG;AACH,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB;;GAEG;AACH,MAAM,kBAAkB,GAAG,WAAW,CAAC;AA2CvC;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,kBAAkB,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,WAAW;IACL,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAEtD;;;;;;OAMG;IACH,KAAK,CAAC,oBAA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,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,0BAA0B;QAC5B,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,IAAI,QAAQ,GAAuB,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAGD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAAiC;IAEjC,IAAI,CAAC;QACH,MAAM,cAAc,EAAE,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACtD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,6DAA6D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI;YACvH,mBAAmB,eAAe,EAAE,EAAE,CACvC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared color utilities for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Respects NO_COLOR env var and non-TTY detection.
|
|
5
|
+
* All terminal coloring should go through these functions.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* ANSI color codes
|
|
9
|
+
*/
|
|
10
|
+
export declare const colors: {
|
|
11
|
+
reset: string;
|
|
12
|
+
bold: string;
|
|
13
|
+
dim: string;
|
|
14
|
+
red: string;
|
|
15
|
+
green: string;
|
|
16
|
+
yellow: string;
|
|
17
|
+
blue: string;
|
|
18
|
+
cyan: string;
|
|
19
|
+
gray: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Check if we should use colored output
|
|
23
|
+
*/
|
|
24
|
+
export declare function useColors(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Apply color if colors are enabled
|
|
27
|
+
*/
|
|
28
|
+
export declare function color(text: string, ...codes: string[]): string;
|
|
29
|
+
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/utils/colors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;CAUlB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAK9D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared color utilities for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Respects NO_COLOR env var and non-TTY detection.
|
|
5
|
+
* All terminal coloring should go through these functions.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* ANSI color codes
|
|
9
|
+
*/
|
|
10
|
+
export const colors = {
|
|
11
|
+
reset: '\x1b[0m',
|
|
12
|
+
bold: '\x1b[1m',
|
|
13
|
+
dim: '\x1b[2m',
|
|
14
|
+
red: '\x1b[31m',
|
|
15
|
+
green: '\x1b[32m',
|
|
16
|
+
yellow: '\x1b[33m',
|
|
17
|
+
blue: '\x1b[34m',
|
|
18
|
+
cyan: '\x1b[36m',
|
|
19
|
+
gray: '\x1b[90m',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Check if we should use colored output
|
|
23
|
+
*/
|
|
24
|
+
export function useColors() {
|
|
25
|
+
return process.stdout.isTTY === true && !('NO_COLOR' in process.env);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Apply color if colors are enabled
|
|
29
|
+
*/
|
|
30
|
+
export function color(text, ...codes) {
|
|
31
|
+
if (!useColors()) {
|
|
32
|
+
return text;
|
|
33
|
+
}
|
|
34
|
+
return codes.join('') + text + colors.reset;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/utils/colors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY,EAAE,GAAG,KAAe;IACpD,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Each error class maps to a specific exit code.
|
|
5
|
+
*/
|
|
6
|
+
import { type ExitCodeValue } from './exit-codes.js';
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for mainwpcontrol errors
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class MainWPCTLError extends Error {
|
|
11
|
+
readonly details?: unknown | undefined;
|
|
12
|
+
readonly hint?: string | undefined;
|
|
13
|
+
abstract readonly exitCode: ExitCodeValue;
|
|
14
|
+
abstract readonly code: string;
|
|
15
|
+
constructor(message: string, details?: unknown | undefined, hint?: string | undefined);
|
|
16
|
+
toJSON(): Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Input validation error (exit code 1)
|
|
20
|
+
*/
|
|
21
|
+
export declare class InputError extends MainWPCTLError {
|
|
22
|
+
readonly exitCode: 1;
|
|
23
|
+
readonly code = "INPUT_ERROR";
|
|
24
|
+
constructor(message: string, details?: unknown, hint?: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Schema validation error (exit code 1)
|
|
28
|
+
*/
|
|
29
|
+
export declare class SchemaValidationError extends MainWPCTLError {
|
|
30
|
+
readonly validationErrors: unknown[];
|
|
31
|
+
readonly exitCode: 1;
|
|
32
|
+
readonly code = "SCHEMA_VALIDATION_ERROR";
|
|
33
|
+
constructor(message: string, validationErrors: unknown[], hint?: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Authentication error (exit code 2)
|
|
37
|
+
*/
|
|
38
|
+
export declare class AuthError extends MainWPCTLError {
|
|
39
|
+
readonly exitCode: 2;
|
|
40
|
+
readonly code = "AUTH_ERROR";
|
|
41
|
+
constructor(message: string, details?: unknown, hint?: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration error (exit code 2)
|
|
45
|
+
*/
|
|
46
|
+
export declare class ConfigError extends MainWPCTLError {
|
|
47
|
+
readonly exitCode: 2;
|
|
48
|
+
readonly code = "CONFIG_ERROR";
|
|
49
|
+
constructor(message: string, details?: unknown, hint?: string);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Network error (exit code 3)
|
|
53
|
+
*/
|
|
54
|
+
export declare class NetworkError extends MainWPCTLError {
|
|
55
|
+
readonly cause?: Error | undefined;
|
|
56
|
+
readonly exitCode: 3;
|
|
57
|
+
readonly code = "NETWORK_ERROR";
|
|
58
|
+
constructor(message: string, cause?: Error | undefined, hint?: string);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* TLS/SSL error (exit code 3)
|
|
62
|
+
*/
|
|
63
|
+
export declare class TLSError extends MainWPCTLError {
|
|
64
|
+
readonly exitCode: 3;
|
|
65
|
+
readonly code = "TLS_ERROR";
|
|
66
|
+
constructor(message: string, details?: unknown, hint?: string);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* API error (exit code 4)
|
|
70
|
+
*/
|
|
71
|
+
export declare class APIError extends MainWPCTLError {
|
|
72
|
+
readonly statusCode?: number | undefined;
|
|
73
|
+
readonly exitCode: 4;
|
|
74
|
+
readonly code: string;
|
|
75
|
+
constructor(code: string, message: string, statusCode?: number | undefined, details?: unknown, hint?: string);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Confirmation required error (exit code 4)
|
|
79
|
+
*/
|
|
80
|
+
export declare class ConfirmationRequiredError extends MainWPCTLError {
|
|
81
|
+
readonly preview?: unknown | undefined;
|
|
82
|
+
readonly exitCode: 4;
|
|
83
|
+
readonly code = "CONFIRMATION_REQUIRED";
|
|
84
|
+
constructor(message: string, preview?: unknown | undefined, hint?: string);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Mutual exclusion error (exit code 1)
|
|
88
|
+
*/
|
|
89
|
+
export declare class MutualExclusionError extends MainWPCTLError {
|
|
90
|
+
readonly exitCode: 1;
|
|
91
|
+
readonly code = "MUTUAL_EXCLUSION_ERROR";
|
|
92
|
+
constructor(message?: string, hint?: string);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Internal error (exit code 5)
|
|
96
|
+
*/
|
|
97
|
+
export declare class InternalError extends MainWPCTLError {
|
|
98
|
+
readonly cause?: Error | undefined;
|
|
99
|
+
readonly exitCode: 5;
|
|
100
|
+
readonly code = "INTERNAL_ERROR";
|
|
101
|
+
constructor(message: string, cause?: Error | undefined, hint?: string);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if an error is a MainWPCTLError
|
|
105
|
+
*/
|
|
106
|
+
export declare function isMainWPCTLError(error: unknown): error is MainWPCTLError;
|
|
107
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;GAEG;AACH,8BAAsB,cAAe,SAAQ,KAAK;aAM9B,OAAO,CAAC,EAAE,OAAO;aACjB,IAAI,CAAC,EAAE,MAAM;IAN/B,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IAC1C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAG7B,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,OAAO,YAAA,EACjB,IAAI,CAAC,EAAE,MAAM,YAAA;IAO/B,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAWlC;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,cAAc;IAC5C,QAAQ,CAAC,QAAQ,IAAwB;IACzC,QAAQ,CAAC,IAAI,iBAAiB;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM;CAG9D;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,cAAc;aAMrC,gBAAgB,EAAE,OAAO,EAAE;IAL7C,QAAQ,CAAC,QAAQ,IAAwB;IACzC,QAAQ,CAAC,IAAI,6BAA6B;gBAGxC,OAAO,EAAE,MAAM,EACC,gBAAgB,EAAE,OAAO,EAAE,EAC3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AAQ,cAAc;aAMzC,OAAO,CAAC,EAAE,OAAO;IALnC,QAAQ,CAAC,QAAQ,IAAsB;IACvC,QAAQ,CAAC,IAAI,2BAA2B;gBAGtC,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,OAAO,YAAA,EACjC,IAAI,CAAC,EAAE,MAAM;CAIhB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,cAAc;IACtD,QAAQ,CAAC,QAAQ,IAAwB;IACzC,QAAQ,CAAC,IAAI,4BAA4B;gBAGvC,OAAO,SAA+C,EACtD,IAAI,CAAC,EAAE,MAAM;CAIhB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,cAAc;aAM7B,KAAK,CAAC,EAAE,KAAK;IAL/B,QAAQ,CAAC,QAAQ,IAA2B;IAC5C,QAAQ,CAAC,IAAI,oBAAoB;gBAG/B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,KAAK,YAAA,EAC7B,IAAI,CAAC,EAAE,MAAM;CAIhB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Each error class maps to a specific exit code.
|
|
5
|
+
*/
|
|
6
|
+
import { ExitCode } from './exit-codes.js';
|
|
7
|
+
/**
|
|
8
|
+
* Base error class for mainwpcontrol errors
|
|
9
|
+
*/
|
|
10
|
+
export class MainWPCTLError extends Error {
|
|
11
|
+
details;
|
|
12
|
+
hint;
|
|
13
|
+
constructor(message, details, hint) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.details = details;
|
|
16
|
+
this.hint = hint;
|
|
17
|
+
this.name = this.constructor.name;
|
|
18
|
+
Error.captureStackTrace(this, this.constructor);
|
|
19
|
+
}
|
|
20
|
+
toJSON() {
|
|
21
|
+
const result = {
|
|
22
|
+
code: this.code,
|
|
23
|
+
message: this.message,
|
|
24
|
+
details: this.details,
|
|
25
|
+
};
|
|
26
|
+
if (this.hint) {
|
|
27
|
+
result.hint = this.hint;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Input validation error (exit code 1)
|
|
34
|
+
*/
|
|
35
|
+
export class InputError extends MainWPCTLError {
|
|
36
|
+
exitCode = ExitCode.INPUT_ERROR;
|
|
37
|
+
code = 'INPUT_ERROR';
|
|
38
|
+
constructor(message, details, hint) {
|
|
39
|
+
super(message, details, hint);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Schema validation error (exit code 1)
|
|
44
|
+
*/
|
|
45
|
+
export class SchemaValidationError extends MainWPCTLError {
|
|
46
|
+
validationErrors;
|
|
47
|
+
exitCode = ExitCode.INPUT_ERROR;
|
|
48
|
+
code = 'SCHEMA_VALIDATION_ERROR';
|
|
49
|
+
constructor(message, validationErrors, hint) {
|
|
50
|
+
super(message, { validationErrors }, hint);
|
|
51
|
+
this.validationErrors = validationErrors;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Authentication error (exit code 2)
|
|
56
|
+
*/
|
|
57
|
+
export class AuthError extends MainWPCTLError {
|
|
58
|
+
exitCode = ExitCode.AUTH_ERROR;
|
|
59
|
+
code = 'AUTH_ERROR';
|
|
60
|
+
constructor(message, details, hint) {
|
|
61
|
+
super(message, details, hint);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Configuration error (exit code 2)
|
|
66
|
+
*/
|
|
67
|
+
export class ConfigError extends MainWPCTLError {
|
|
68
|
+
exitCode = ExitCode.AUTH_ERROR;
|
|
69
|
+
code = 'CONFIG_ERROR';
|
|
70
|
+
constructor(message, details, hint) {
|
|
71
|
+
super(message, details, hint);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Network error (exit code 3)
|
|
76
|
+
*/
|
|
77
|
+
export class NetworkError extends MainWPCTLError {
|
|
78
|
+
cause;
|
|
79
|
+
exitCode = ExitCode.NETWORK_ERROR;
|
|
80
|
+
code = 'NETWORK_ERROR';
|
|
81
|
+
constructor(message, cause, hint) {
|
|
82
|
+
super(message, cause ? { cause: cause.message } : undefined, hint);
|
|
83
|
+
this.cause = cause;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* TLS/SSL error (exit code 3)
|
|
88
|
+
*/
|
|
89
|
+
export class TLSError extends MainWPCTLError {
|
|
90
|
+
exitCode = ExitCode.NETWORK_ERROR;
|
|
91
|
+
code = 'TLS_ERROR';
|
|
92
|
+
constructor(message, details, hint) {
|
|
93
|
+
super(message, details, hint);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* API error (exit code 4)
|
|
98
|
+
*/
|
|
99
|
+
export class APIError extends MainWPCTLError {
|
|
100
|
+
statusCode;
|
|
101
|
+
exitCode = ExitCode.API_ERROR;
|
|
102
|
+
code;
|
|
103
|
+
constructor(code, message, statusCode, details, hint) {
|
|
104
|
+
super(message, details, hint);
|
|
105
|
+
this.statusCode = statusCode;
|
|
106
|
+
this.code = code;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Confirmation required error (exit code 4)
|
|
111
|
+
*/
|
|
112
|
+
export class ConfirmationRequiredError extends MainWPCTLError {
|
|
113
|
+
preview;
|
|
114
|
+
exitCode = ExitCode.API_ERROR;
|
|
115
|
+
code = 'CONFIRMATION_REQUIRED';
|
|
116
|
+
constructor(message, preview, hint) {
|
|
117
|
+
super(message, { preview }, hint);
|
|
118
|
+
this.preview = preview;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Mutual exclusion error (exit code 1)
|
|
123
|
+
*/
|
|
124
|
+
export class MutualExclusionError extends MainWPCTLError {
|
|
125
|
+
exitCode = ExitCode.INPUT_ERROR;
|
|
126
|
+
code = 'MUTUAL_EXCLUSION_ERROR';
|
|
127
|
+
constructor(message = 'dry_run and confirm are mutually exclusive', hint) {
|
|
128
|
+
super(message, undefined, hint);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Internal error (exit code 5)
|
|
133
|
+
*/
|
|
134
|
+
export class InternalError extends MainWPCTLError {
|
|
135
|
+
cause;
|
|
136
|
+
exitCode = ExitCode.INTERNAL_ERROR;
|
|
137
|
+
code = 'INTERNAL_ERROR';
|
|
138
|
+
constructor(message, cause, hint) {
|
|
139
|
+
super(message, cause ? { cause: cause.message } : undefined, hint);
|
|
140
|
+
this.cause = cause;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if an error is a MainWPCTLError
|
|
145
|
+
*/
|
|
146
|
+
export function isMainWPCTLError(error) {
|
|
147
|
+
return error instanceof MainWPCTLError;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAsB,MAAM,iBAAiB,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAgB,cAAe,SAAQ,KAAK;IAM9B;IACA;IAHlB,YACE,OAAe,EACC,OAAiB,EACjB,IAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,YAAO,GAAP,OAAO,CAAU;QACjB,SAAI,GAAJ,IAAI,CAAS;QAG7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,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O,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;QAHlB,YAAO,GAAP,OAAO,CAAU;IAInC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IAC7C,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC;IAChC,IAAI,GAAG,wBAAwB,CAAC;IAEzC,YACE,OAAO,GAAG,4CAA4C,EACtD,IAAa;QAEb,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAM7B;IALT,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC;IACnC,IAAI,GAAG,gBAAgB,CAAC;IAEjC,YACE,OAAe,EACC,KAAa,EAC7B,IAAa;QAEb,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAHnD,UAAK,GAAL,KAAK,CAAQ;IAI/B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,cAAc,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit codes for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* These codes are stable and documented. Do not change without updating docs.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ExitCode: {
|
|
7
|
+
/** Operation completed successfully */
|
|
8
|
+
readonly SUCCESS: 0;
|
|
9
|
+
/** User, schema, or input error */
|
|
10
|
+
readonly INPUT_ERROR: 1;
|
|
11
|
+
/** Authentication or configuration error */
|
|
12
|
+
readonly AUTH_ERROR: 2;
|
|
13
|
+
/** Network or TLS error */
|
|
14
|
+
readonly NETWORK_ERROR: 3;
|
|
15
|
+
/** API or ability execution error */
|
|
16
|
+
readonly API_ERROR: 4;
|
|
17
|
+
/** Internal error (stack trace only with --debug) */
|
|
18
|
+
readonly INTERNAL_ERROR: 5;
|
|
19
|
+
};
|
|
20
|
+
export type ExitCodeValue = (typeof ExitCode)[keyof typeof ExitCode];
|
|
21
|
+
//# sourceMappingURL=exit-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.d.ts","sourceRoot":"","sources":["../../src/utils/exit-codes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,QAAQ;IACnB,uCAAuC;;IAGvC,mCAAmC;;IAGnC,4CAA4C;;IAG5C,2BAA2B;;IAG3B,qCAAqC;;IAGrC,qDAAqD;;CAE7C,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exit codes for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* These codes are stable and documented. Do not change without updating docs.
|
|
5
|
+
*/
|
|
6
|
+
export const ExitCode = {
|
|
7
|
+
/** Operation completed successfully */
|
|
8
|
+
SUCCESS: 0,
|
|
9
|
+
/** User, schema, or input error */
|
|
10
|
+
INPUT_ERROR: 1,
|
|
11
|
+
/** Authentication or configuration error */
|
|
12
|
+
AUTH_ERROR: 2,
|
|
13
|
+
/** Network or TLS error */
|
|
14
|
+
NETWORK_ERROR: 3,
|
|
15
|
+
/** API or ability execution error */
|
|
16
|
+
API_ERROR: 4,
|
|
17
|
+
/** Internal error (stack trace only with --debug) */
|
|
18
|
+
INTERNAL_ERROR: 5,
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=exit-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-codes.js","sourceRoot":"","sources":["../../src/utils/exit-codes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,uCAAuC;IACvC,OAAO,EAAE,CAAC;IAEV,mCAAmC;IACnC,WAAW,EAAE,CAAC;IAEd,4CAA4C;IAC5C,UAAU,EAAE,CAAC;IAEb,2BAA2B;IAC3B,aAAa,EAAE,CAAC;IAEhB,qCAAqC;IACrC,SAAS,EAAE,CAAC;IAEZ,qDAAqD;IACrD,cAAc,EAAE,CAAC;CACT,CAAC"}
|