@nahisaho/musubix-core 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/bin/musubix.js +18 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +27 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/auth/auth-manager.d.ts +320 -0
- package/dist/auth/auth-manager.d.ts.map +1 -0
- package/dist/auth/auth-manager.js +580 -0
- package/dist/auth/auth-manager.js.map +1 -0
- package/dist/cli/base.d.ts +58 -0
- package/dist/cli/base.d.ts.map +1 -0
- package/dist/cli/base.js +93 -0
- package/dist/cli/base.js.map +1 -0
- package/dist/cli/commands/help.d.ts +17 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +228 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/index.d.ts +14 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +25 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/init.d.ts +38 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +258 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/codegen/coding-standards.d.ts +250 -0
- package/dist/codegen/coding-standards.d.ts.map +1 -0
- package/dist/codegen/coding-standards.js +976 -0
- package/dist/codegen/coding-standards.js.map +1 -0
- package/dist/codegen/coverage-reporter.d.ts +264 -0
- package/dist/codegen/coverage-reporter.d.ts.map +1 -0
- package/dist/codegen/coverage-reporter.js +697 -0
- package/dist/codegen/coverage-reporter.js.map +1 -0
- package/dist/codegen/dependency-analyzer.d.ts +271 -0
- package/dist/codegen/dependency-analyzer.d.ts.map +1 -0
- package/dist/codegen/dependency-analyzer.js +661 -0
- package/dist/codegen/dependency-analyzer.js.map +1 -0
- package/dist/codegen/generator.d.ts +275 -0
- package/dist/codegen/generator.d.ts.map +1 -0
- package/dist/codegen/generator.js +781 -0
- package/dist/codegen/generator.js.map +1 -0
- package/dist/codegen/index.d.ts +18 -0
- package/dist/codegen/index.d.ts.map +1 -0
- package/dist/codegen/index.js +27 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/integration-test-generator.d.ts +312 -0
- package/dist/codegen/integration-test-generator.d.ts.map +1 -0
- package/dist/codegen/integration-test-generator.js +765 -0
- package/dist/codegen/integration-test-generator.js.map +1 -0
- package/dist/codegen/pattern-conformance.d.ts +309 -0
- package/dist/codegen/pattern-conformance.d.ts.map +1 -0
- package/dist/codegen/pattern-conformance.js +590 -0
- package/dist/codegen/pattern-conformance.js.map +1 -0
- package/dist/codegen/quality-metrics.d.ts +235 -0
- package/dist/codegen/quality-metrics.d.ts.map +1 -0
- package/dist/codegen/quality-metrics.js +439 -0
- package/dist/codegen/quality-metrics.js.map +1 -0
- package/dist/codegen/security-scanner.d.ts +179 -0
- package/dist/codegen/security-scanner.d.ts.map +1 -0
- package/dist/codegen/security-scanner.js +495 -0
- package/dist/codegen/security-scanner.js.map +1 -0
- package/dist/codegen/static-analyzer.d.ts +188 -0
- package/dist/codegen/static-analyzer.d.ts.map +1 -0
- package/dist/codegen/static-analyzer.js +490 -0
- package/dist/codegen/static-analyzer.js.map +1 -0
- package/dist/codegen/unit-test-generator.d.ts +289 -0
- package/dist/codegen/unit-test-generator.d.ts.map +1 -0
- package/dist/codegen/unit-test-generator.js +634 -0
- package/dist/codegen/unit-test-generator.js.map +1 -0
- package/dist/design/adr-generator.d.ts +227 -0
- package/dist/design/adr-generator.d.ts.map +1 -0
- package/dist/design/adr-generator.js +423 -0
- package/dist/design/adr-generator.js.map +1 -0
- package/dist/design/c4-generator.d.ts +267 -0
- package/dist/design/c4-generator.d.ts.map +1 -0
- package/dist/design/c4-generator.js +453 -0
- package/dist/design/c4-generator.js.map +1 -0
- package/dist/design/framework-optimizer.d.ts +190 -0
- package/dist/design/framework-optimizer.d.ts.map +1 -0
- package/dist/design/framework-optimizer.js +589 -0
- package/dist/design/framework-optimizer.js.map +1 -0
- package/dist/design/index.d.ts +12 -0
- package/dist/design/index.d.ts.map +1 -0
- package/dist/design/index.js +13 -0
- package/dist/design/index.js.map +1 -0
- package/dist/design/pattern-detector.d.ts +270 -0
- package/dist/design/pattern-detector.d.ts.map +1 -0
- package/dist/design/pattern-detector.js +621 -0
- package/dist/design/pattern-detector.js.map +1 -0
- package/dist/design/solid-validator.d.ts +188 -0
- package/dist/design/solid-validator.d.ts.map +1 -0
- package/dist/design/solid-validator.js +579 -0
- package/dist/design/solid-validator.js.map +1 -0
- package/dist/error/data-persistence.d.ts +311 -0
- package/dist/error/data-persistence.d.ts.map +1 -0
- package/dist/error/data-persistence.js +586 -0
- package/dist/error/data-persistence.js.map +1 -0
- package/dist/error/graceful-degradation.d.ts +309 -0
- package/dist/error/graceful-degradation.d.ts.map +1 -0
- package/dist/error/graceful-degradation.js +510 -0
- package/dist/error/graceful-degradation.js.map +1 -0
- package/dist/error/index.d.ts +11 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/index.js +19 -0
- package/dist/error/index.js.map +1 -0
- package/dist/explanation/explanation-generator.d.ts +228 -0
- package/dist/explanation/explanation-generator.d.ts.map +1 -0
- package/dist/explanation/explanation-generator.js +662 -0
- package/dist/explanation/explanation-generator.js.map +1 -0
- package/dist/explanation/index.d.ts +11 -0
- package/dist/explanation/index.d.ts.map +1 -0
- package/dist/explanation/index.js +19 -0
- package/dist/explanation/index.js.map +1 -0
- package/dist/explanation/reasoning-chain.d.ts +314 -0
- package/dist/explanation/reasoning-chain.d.ts.map +1 -0
- package/dist/explanation/reasoning-chain.js +414 -0
- package/dist/explanation/reasoning-chain.js.map +1 -0
- package/dist/explanation/visual-explanation.d.ts +315 -0
- package/dist/explanation/visual-explanation.d.ts.map +1 -0
- package/dist/explanation/visual-explanation.js +667 -0
- package/dist/explanation/visual-explanation.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/requirements/decomposer.d.ts +235 -0
- package/dist/requirements/decomposer.d.ts.map +1 -0
- package/dist/requirements/decomposer.js +587 -0
- package/dist/requirements/decomposer.js.map +1 -0
- package/dist/requirements/related-finder.d.ts +261 -0
- package/dist/requirements/related-finder.d.ts.map +1 -0
- package/dist/requirements/related-finder.js +629 -0
- package/dist/requirements/related-finder.js.map +1 -0
- package/dist/traceability/impact.d.ts +196 -0
- package/dist/traceability/impact.d.ts.map +1 -0
- package/dist/traceability/impact.js +438 -0
- package/dist/traceability/impact.js.map +1 -0
- package/dist/traceability/index.d.ts +9 -0
- package/dist/traceability/index.d.ts.map +1 -0
- package/dist/traceability/index.js +10 -0
- package/dist/traceability/index.js.map +1 -0
- package/dist/traceability/manager.d.ts +266 -0
- package/dist/traceability/manager.d.ts.map +1 -0
- package/dist/traceability/manager.js +412 -0
- package/dist/traceability/manager.js.map +1 -0
- package/dist/types/common.d.ts +294 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +15 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/ears.d.ts +158 -0
- package/dist/types/ears.d.ts.map +1 -0
- package/dist/types/ears.js +33 -0
- package/dist/types/ears.js.map +1 -0
- package/dist/types/errors.d.ts +176 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +55 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/data-protector.d.ts +122 -0
- package/dist/utils/data-protector.d.ts.map +1 -0
- package/dist/utils/data-protector.js +275 -0
- package/dist/utils/data-protector.js.map +1 -0
- package/dist/utils/error-handler.d.ts +101 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +324 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/i18n-manager.d.ts +259 -0
- package/dist/utils/i18n-manager.d.ts.map +1 -0
- package/dist/utils/i18n-manager.js +554 -0
- package/dist/utils/i18n-manager.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +120 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +237 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/performance-profiler.d.ts +251 -0
- package/dist/utils/performance-profiler.d.ts.map +1 -0
- package/dist/utils/performance-profiler.js +458 -0
- package/dist/utils/performance-profiler.js.map +1 -0
- package/dist/utils/scalability-optimizer.d.ts +294 -0
- package/dist/utils/scalability-optimizer.d.ts.map +1 -0
- package/dist/utils/scalability-optimizer.js +606 -0
- package/dist/utils/scalability-optimizer.js.map +1 -0
- package/dist/utils/structured-logger.d.ts +294 -0
- package/dist/utils/structured-logger.d.ts.map +1 -0
- package/dist/utils/structured-logger.js +630 -0
- package/dist/utils/structured-logger.js.map +1 -0
- package/dist/utils/version-compatibility.d.ts +217 -0
- package/dist/utils/version-compatibility.d.ts.map +1 -0
- package/dist/utils/version-compatibility.js +443 -0
- package/dist/utils/version-compatibility.js.map +1 -0
- package/dist/validators/ears-validator.d.ts +182 -0
- package/dist/validators/ears-validator.d.ts.map +1 -0
- package/dist/validators/ears-validator.js +357 -0
- package/dist/validators/ears-validator.js.map +1 -0
- package/dist/validators/index.d.ts +8 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +9 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +8 -0
- package/dist/version.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Type Definitions for MUSUBIX
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module types/errors
|
|
6
|
+
*
|
|
7
|
+
* @see REQ-ERR-001 - Graceful Degradation
|
|
8
|
+
* @see REQ-MNT-002 - Error Handler
|
|
9
|
+
* @see DES-MUSUBIX-001 Section 10 - Error Handling Design
|
|
10
|
+
*/
|
|
11
|
+
import type { ID, Timestamp, Location } from './common.js';
|
|
12
|
+
/**
|
|
13
|
+
* MUSUBIX error codes
|
|
14
|
+
*/
|
|
15
|
+
export declare enum ErrorCode {
|
|
16
|
+
UNKNOWN = 1000,
|
|
17
|
+
INTERNAL = 1001,
|
|
18
|
+
INVALID_ARGUMENT = 1002,
|
|
19
|
+
NOT_FOUND = 1003,
|
|
20
|
+
ALREADY_EXISTS = 1004,
|
|
21
|
+
PERMISSION_DENIED = 1005,
|
|
22
|
+
CONFIG_NOT_FOUND = 2000,
|
|
23
|
+
CONFIG_INVALID = 2001,
|
|
24
|
+
CONFIG_MISSING_FIELD = 2002,
|
|
25
|
+
LLM_CONNECTION_FAILED = 3000,
|
|
26
|
+
LLM_RESPONSE_ERROR = 3001,
|
|
27
|
+
LLM_RATE_LIMIT = 3002,
|
|
28
|
+
YATA_CONNECTION_FAILED = 3100,
|
|
29
|
+
YATA_QUERY_ERROR = 3101,
|
|
30
|
+
YATA_TIMEOUT = 3102,
|
|
31
|
+
INTEGRATION_MISMATCH = 3200,
|
|
32
|
+
CONTRADICTION_DETECTED = 3201,
|
|
33
|
+
VALIDATION_FAILED = 4000,
|
|
34
|
+
EARS_SYNTAX_ERROR = 4001,
|
|
35
|
+
DESIGN_VIOLATION = 4002,
|
|
36
|
+
CODE_QUALITY_ERROR = 4003,
|
|
37
|
+
TEST_COVERAGE_LOW = 4004,
|
|
38
|
+
FILE_NOT_FOUND = 5000,
|
|
39
|
+
FILE_READ_ERROR = 5001,
|
|
40
|
+
FILE_WRITE_ERROR = 5002,
|
|
41
|
+
DIRECTORY_NOT_FOUND = 5003,
|
|
42
|
+
CLI_INVALID_COMMAND = 6000,
|
|
43
|
+
CLI_MISSING_ARGUMENT = 6001,
|
|
44
|
+
CLI_INVALID_OPTION = 6002
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Base MUSUBIX error
|
|
48
|
+
*/
|
|
49
|
+
export interface MuSubixErrorData {
|
|
50
|
+
/** Error code */
|
|
51
|
+
code: ErrorCode;
|
|
52
|
+
/** Human-readable message */
|
|
53
|
+
message: string;
|
|
54
|
+
/** Detailed description */
|
|
55
|
+
details?: string;
|
|
56
|
+
/** Timestamp */
|
|
57
|
+
timestamp: Timestamp;
|
|
58
|
+
/** Correlation ID for tracing */
|
|
59
|
+
correlationId?: ID;
|
|
60
|
+
/** Original error */
|
|
61
|
+
cause?: Error;
|
|
62
|
+
/** Location in source */
|
|
63
|
+
location?: Location;
|
|
64
|
+
/** Additional context */
|
|
65
|
+
context?: Record<string, unknown>;
|
|
66
|
+
/** Recovery suggestions */
|
|
67
|
+
recovery?: RecoverySuggestion[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Recovery suggestion for errors
|
|
71
|
+
*/
|
|
72
|
+
export interface RecoverySuggestion {
|
|
73
|
+
/** Suggestion type */
|
|
74
|
+
type: RecoveryType;
|
|
75
|
+
/** Description */
|
|
76
|
+
description: string;
|
|
77
|
+
/** Automated action available */
|
|
78
|
+
automatable: boolean;
|
|
79
|
+
/** Action command if automatable */
|
|
80
|
+
action?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Recovery types
|
|
84
|
+
*/
|
|
85
|
+
export type RecoveryType = 'retry' | 'fallback' | 'configure' | 'manual' | 'ignore';
|
|
86
|
+
/**
|
|
87
|
+
* Configuration error
|
|
88
|
+
*/
|
|
89
|
+
export interface ConfigurationError extends MuSubixErrorData {
|
|
90
|
+
code: ErrorCode.CONFIG_NOT_FOUND | ErrorCode.CONFIG_INVALID | ErrorCode.CONFIG_MISSING_FIELD;
|
|
91
|
+
configPath?: string;
|
|
92
|
+
missingField?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Integration error
|
|
96
|
+
*/
|
|
97
|
+
export interface IntegrationError extends MuSubixErrorData {
|
|
98
|
+
code: ErrorCode.LLM_CONNECTION_FAILED | ErrorCode.LLM_RESPONSE_ERROR | ErrorCode.LLM_RATE_LIMIT | ErrorCode.YATA_CONNECTION_FAILED | ErrorCode.YATA_QUERY_ERROR | ErrorCode.YATA_TIMEOUT | ErrorCode.INTEGRATION_MISMATCH | ErrorCode.CONTRADICTION_DETECTED;
|
|
99
|
+
service: 'llm' | 'yata' | 'integration';
|
|
100
|
+
endpoint?: string;
|
|
101
|
+
statusCode?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validation error
|
|
105
|
+
*/
|
|
106
|
+
export interface ValidationError extends MuSubixErrorData {
|
|
107
|
+
code: ErrorCode.VALIDATION_FAILED | ErrorCode.EARS_SYNTAX_ERROR | ErrorCode.DESIGN_VIOLATION | ErrorCode.CODE_QUALITY_ERROR | ErrorCode.TEST_COVERAGE_LOW;
|
|
108
|
+
validationType: string;
|
|
109
|
+
violations: ValidationViolation[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Validation violation detail
|
|
113
|
+
*/
|
|
114
|
+
export interface ValidationViolation {
|
|
115
|
+
/** Rule that was violated */
|
|
116
|
+
rule: string;
|
|
117
|
+
/** Violation message */
|
|
118
|
+
message: string;
|
|
119
|
+
/** Severity */
|
|
120
|
+
severity: 'error' | 'warning' | 'info';
|
|
121
|
+
/** Location */
|
|
122
|
+
location?: Location;
|
|
123
|
+
/** Suggestion */
|
|
124
|
+
suggestion?: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* File system error
|
|
128
|
+
*/
|
|
129
|
+
export interface FileSystemError extends MuSubixErrorData {
|
|
130
|
+
code: ErrorCode.FILE_NOT_FOUND | ErrorCode.FILE_READ_ERROR | ErrorCode.FILE_WRITE_ERROR | ErrorCode.DIRECTORY_NOT_FOUND;
|
|
131
|
+
path: string;
|
|
132
|
+
operation: 'read' | 'write' | 'delete' | 'create';
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* CLI error
|
|
136
|
+
*/
|
|
137
|
+
export interface CLIError extends MuSubixErrorData {
|
|
138
|
+
code: ErrorCode.CLI_INVALID_COMMAND | ErrorCode.CLI_MISSING_ARGUMENT | ErrorCode.CLI_INVALID_OPTION;
|
|
139
|
+
command?: string;
|
|
140
|
+
argument?: string;
|
|
141
|
+
option?: string;
|
|
142
|
+
usage?: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Error factory options
|
|
146
|
+
*/
|
|
147
|
+
export interface ErrorOptions {
|
|
148
|
+
cause?: Error;
|
|
149
|
+
details?: string;
|
|
150
|
+
context?: Record<string, unknown>;
|
|
151
|
+
recovery?: RecoverySuggestion[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Error severity levels
|
|
155
|
+
*/
|
|
156
|
+
export type ErrorSeverity = 'fatal' | 'error' | 'warn' | 'warning' | 'info';
|
|
157
|
+
/**
|
|
158
|
+
* Error classification
|
|
159
|
+
*/
|
|
160
|
+
export interface ErrorClassification {
|
|
161
|
+
/** Error category */
|
|
162
|
+
category: ErrorCategory;
|
|
163
|
+
/** Whether error is recoverable */
|
|
164
|
+
recoverable: boolean;
|
|
165
|
+
/** Whether to log error */
|
|
166
|
+
shouldLog: boolean;
|
|
167
|
+
/** Log level */
|
|
168
|
+
logLevel: ErrorSeverity;
|
|
169
|
+
/** Whether to report to user */
|
|
170
|
+
userFacing: boolean;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Error categories
|
|
174
|
+
*/
|
|
175
|
+
export type ErrorCategory = 'configuration' | 'integration' | 'validation' | 'filesystem' | 'cli' | 'internal';
|
|
176
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Type Definitions for MUSUBIX
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module types/errors
|
|
6
|
+
*
|
|
7
|
+
* @see REQ-ERR-001 - Graceful Degradation
|
|
8
|
+
* @see REQ-MNT-002 - Error Handler
|
|
9
|
+
* @see DES-MUSUBIX-001 Section 10 - Error Handling Design
|
|
10
|
+
*/
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Error Codes
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* MUSUBIX error codes
|
|
16
|
+
*/
|
|
17
|
+
export var ErrorCode;
|
|
18
|
+
(function (ErrorCode) {
|
|
19
|
+
// General errors (1xxx)
|
|
20
|
+
ErrorCode[ErrorCode["UNKNOWN"] = 1000] = "UNKNOWN";
|
|
21
|
+
ErrorCode[ErrorCode["INTERNAL"] = 1001] = "INTERNAL";
|
|
22
|
+
ErrorCode[ErrorCode["INVALID_ARGUMENT"] = 1002] = "INVALID_ARGUMENT";
|
|
23
|
+
ErrorCode[ErrorCode["NOT_FOUND"] = 1003] = "NOT_FOUND";
|
|
24
|
+
ErrorCode[ErrorCode["ALREADY_EXISTS"] = 1004] = "ALREADY_EXISTS";
|
|
25
|
+
ErrorCode[ErrorCode["PERMISSION_DENIED"] = 1005] = "PERMISSION_DENIED";
|
|
26
|
+
// Configuration errors (2xxx)
|
|
27
|
+
ErrorCode[ErrorCode["CONFIG_NOT_FOUND"] = 2000] = "CONFIG_NOT_FOUND";
|
|
28
|
+
ErrorCode[ErrorCode["CONFIG_INVALID"] = 2001] = "CONFIG_INVALID";
|
|
29
|
+
ErrorCode[ErrorCode["CONFIG_MISSING_FIELD"] = 2002] = "CONFIG_MISSING_FIELD";
|
|
30
|
+
// Integration errors (3xxx)
|
|
31
|
+
ErrorCode[ErrorCode["LLM_CONNECTION_FAILED"] = 3000] = "LLM_CONNECTION_FAILED";
|
|
32
|
+
ErrorCode[ErrorCode["LLM_RESPONSE_ERROR"] = 3001] = "LLM_RESPONSE_ERROR";
|
|
33
|
+
ErrorCode[ErrorCode["LLM_RATE_LIMIT"] = 3002] = "LLM_RATE_LIMIT";
|
|
34
|
+
ErrorCode[ErrorCode["YATA_CONNECTION_FAILED"] = 3100] = "YATA_CONNECTION_FAILED";
|
|
35
|
+
ErrorCode[ErrorCode["YATA_QUERY_ERROR"] = 3101] = "YATA_QUERY_ERROR";
|
|
36
|
+
ErrorCode[ErrorCode["YATA_TIMEOUT"] = 3102] = "YATA_TIMEOUT";
|
|
37
|
+
ErrorCode[ErrorCode["INTEGRATION_MISMATCH"] = 3200] = "INTEGRATION_MISMATCH";
|
|
38
|
+
ErrorCode[ErrorCode["CONTRADICTION_DETECTED"] = 3201] = "CONTRADICTION_DETECTED";
|
|
39
|
+
// Validation errors (4xxx)
|
|
40
|
+
ErrorCode[ErrorCode["VALIDATION_FAILED"] = 4000] = "VALIDATION_FAILED";
|
|
41
|
+
ErrorCode[ErrorCode["EARS_SYNTAX_ERROR"] = 4001] = "EARS_SYNTAX_ERROR";
|
|
42
|
+
ErrorCode[ErrorCode["DESIGN_VIOLATION"] = 4002] = "DESIGN_VIOLATION";
|
|
43
|
+
ErrorCode[ErrorCode["CODE_QUALITY_ERROR"] = 4003] = "CODE_QUALITY_ERROR";
|
|
44
|
+
ErrorCode[ErrorCode["TEST_COVERAGE_LOW"] = 4004] = "TEST_COVERAGE_LOW";
|
|
45
|
+
// File system errors (5xxx)
|
|
46
|
+
ErrorCode[ErrorCode["FILE_NOT_FOUND"] = 5000] = "FILE_NOT_FOUND";
|
|
47
|
+
ErrorCode[ErrorCode["FILE_READ_ERROR"] = 5001] = "FILE_READ_ERROR";
|
|
48
|
+
ErrorCode[ErrorCode["FILE_WRITE_ERROR"] = 5002] = "FILE_WRITE_ERROR";
|
|
49
|
+
ErrorCode[ErrorCode["DIRECTORY_NOT_FOUND"] = 5003] = "DIRECTORY_NOT_FOUND";
|
|
50
|
+
// CLI errors (6xxx)
|
|
51
|
+
ErrorCode[ErrorCode["CLI_INVALID_COMMAND"] = 6000] = "CLI_INVALID_COMMAND";
|
|
52
|
+
ErrorCode[ErrorCode["CLI_MISSING_ARGUMENT"] = 6001] = "CLI_MISSING_ARGUMENT";
|
|
53
|
+
ErrorCode[ErrorCode["CLI_INVALID_OPTION"] = 6002] = "CLI_INVALID_OPTION";
|
|
54
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
55
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAN,IAAY,SAyCX;AAzCD,WAAY,SAAS;IACnB,wBAAwB;IACxB,kDAAc,CAAA;IACd,oDAAe,CAAA;IACf,oEAAuB,CAAA;IACvB,sDAAgB,CAAA;IAChB,gEAAqB,CAAA;IACrB,sEAAwB,CAAA;IAExB,8BAA8B;IAC9B,oEAAuB,CAAA;IACvB,gEAAqB,CAAA;IACrB,4EAA2B,CAAA;IAE3B,4BAA4B;IAC5B,8EAA4B,CAAA;IAC5B,wEAAyB,CAAA;IACzB,gEAAqB,CAAA;IACrB,gFAA6B,CAAA;IAC7B,oEAAuB,CAAA;IACvB,4DAAmB,CAAA;IACnB,4EAA2B,CAAA;IAC3B,gFAA6B,CAAA;IAE7B,2BAA2B;IAC3B,sEAAwB,CAAA;IACxB,sEAAwB,CAAA;IACxB,oEAAuB,CAAA;IACvB,wEAAyB,CAAA;IACzB,sEAAwB,CAAA;IAExB,4BAA4B;IAC5B,gEAAqB,CAAA;IACrB,kEAAsB,CAAA;IACtB,oEAAuB,CAAA;IACvB,0EAA0B,CAAA;IAE1B,oBAAoB;IACpB,0EAA0B,CAAA;IAC1B,4EAA2B,CAAA;IAC3B,wEAAyB,CAAA;AAC3B,CAAC,EAzCW,SAAS,KAAT,SAAS,QAyCpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Protector Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides data protection, encryption, and security features
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module utils/data-protector
|
|
8
|
+
*
|
|
9
|
+
* @see REQ-SEC-001 - Data Protector
|
|
10
|
+
* @see REQ-ERR-002 - Data Persistence
|
|
11
|
+
* @see DES-MUSUBIX-001 Section 14.1 - Data Protector Design
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Data protection options
|
|
15
|
+
*/
|
|
16
|
+
export interface ProtectionOptions {
|
|
17
|
+
/** Enable encryption */
|
|
18
|
+
encrypt: boolean;
|
|
19
|
+
/** Encryption key or password */
|
|
20
|
+
key?: string;
|
|
21
|
+
/** Enable integrity verification */
|
|
22
|
+
verify: boolean;
|
|
23
|
+
/** Enable backup */
|
|
24
|
+
backup: boolean;
|
|
25
|
+
/** Backup path */
|
|
26
|
+
backupPath?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Protected data structure
|
|
30
|
+
*/
|
|
31
|
+
export interface ProtectedData {
|
|
32
|
+
/** Data version */
|
|
33
|
+
version: number;
|
|
34
|
+
/** Encrypted flag */
|
|
35
|
+
encrypted: boolean;
|
|
36
|
+
/** Encryption salt (hex) */
|
|
37
|
+
salt?: string;
|
|
38
|
+
/** Initialization vector (hex) */
|
|
39
|
+
iv?: string;
|
|
40
|
+
/** Authentication tag (hex) */
|
|
41
|
+
authTag?: string;
|
|
42
|
+
/** Data payload (encrypted or plain) */
|
|
43
|
+
payload: string;
|
|
44
|
+
/** Integrity hash */
|
|
45
|
+
hash: string;
|
|
46
|
+
/** Timestamp */
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Data Protector class
|
|
51
|
+
*/
|
|
52
|
+
export declare class DataProtector {
|
|
53
|
+
private options;
|
|
54
|
+
constructor(options?: Partial<ProtectionOptions>);
|
|
55
|
+
/**
|
|
56
|
+
* Update options
|
|
57
|
+
*/
|
|
58
|
+
configure(options: Partial<ProtectionOptions>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Protect and save data to file
|
|
61
|
+
*/
|
|
62
|
+
save<T>(filePath: string, data: T, options?: Partial<ProtectionOptions>): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Load and verify data from file
|
|
65
|
+
*/
|
|
66
|
+
load<T>(filePath: string, options?: Partial<ProtectionOptions>): Promise<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Check if file exists
|
|
69
|
+
*/
|
|
70
|
+
exists(filePath: string): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Delete protected file
|
|
73
|
+
*/
|
|
74
|
+
delete(filePath: string, options?: {
|
|
75
|
+
deleteBackups?: boolean;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Calculate hash of data
|
|
79
|
+
*/
|
|
80
|
+
hash(data: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Verify data integrity
|
|
83
|
+
*/
|
|
84
|
+
verifyIntegrity(protected_: ProtectedData): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Create plain protected data structure
|
|
87
|
+
*/
|
|
88
|
+
private createPlainProtected;
|
|
89
|
+
/**
|
|
90
|
+
* Encrypt data
|
|
91
|
+
*/
|
|
92
|
+
private encrypt;
|
|
93
|
+
/**
|
|
94
|
+
* Decrypt data
|
|
95
|
+
*/
|
|
96
|
+
private decrypt;
|
|
97
|
+
/**
|
|
98
|
+
* Create backup of file
|
|
99
|
+
*/
|
|
100
|
+
private createBackup;
|
|
101
|
+
/**
|
|
102
|
+
* Get backup file path
|
|
103
|
+
*/
|
|
104
|
+
private getBackupPath;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if key might contain sensitive data
|
|
108
|
+
*/
|
|
109
|
+
export declare function isSensitiveKey(key: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Mask sensitive value for logging
|
|
112
|
+
*/
|
|
113
|
+
export declare function maskValue(value: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Redact sensitive data from object for logging
|
|
116
|
+
*/
|
|
117
|
+
export declare function redactSensitive<T extends Record<string, unknown>>(obj: T): T;
|
|
118
|
+
/**
|
|
119
|
+
* Global data protector instance
|
|
120
|
+
*/
|
|
121
|
+
export declare const dataProtector: DataProtector;
|
|
122
|
+
//# sourceMappingURL=data-protector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-protector.d.ts","sourceRoot":"","sources":["../../src/utils/data-protector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAiBH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wBAAwB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,oBAAoB;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAWD;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAoB;gBAEvB,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAIhD;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI;IAIpD;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB7F;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA6BjF;;OAEG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAShD;;OAEG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAapF;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI1B;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,aAAa,GAAG,OAAO;IAKnD;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;YACW,OAAO;IA4BrB;;OAEG;YACW,OAAO;IA0BrB;;OAEG;YACW,YAAY;IAiB1B;;OAEG;IACH,OAAO,CAAC,aAAa;CAWtB;AAeD;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAc5E;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,eAAsB,CAAC"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Protector Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides data protection, encryption, and security features
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* @module utils/data-protector
|
|
8
|
+
*
|
|
9
|
+
* @see REQ-SEC-001 - Data Protector
|
|
10
|
+
* @see REQ-ERR-002 - Data Persistence
|
|
11
|
+
* @see DES-MUSUBIX-001 Section 14.1 - Data Protector Design
|
|
12
|
+
*/
|
|
13
|
+
import { createHash, createCipheriv, createDecipheriv, randomBytes, scrypt } from 'crypto';
|
|
14
|
+
import { promisify } from 'util';
|
|
15
|
+
import { readFile, writeFile, mkdir, access, unlink } from 'fs/promises';
|
|
16
|
+
import { join, dirname } from 'path';
|
|
17
|
+
const scryptAsync = promisify(scrypt);
|
|
18
|
+
/**
|
|
19
|
+
* Encryption algorithm
|
|
20
|
+
*/
|
|
21
|
+
const ALGORITHM = 'aes-256-gcm';
|
|
22
|
+
const KEY_LENGTH = 32;
|
|
23
|
+
const IV_LENGTH = 16;
|
|
24
|
+
const SALT_LENGTH = 32;
|
|
25
|
+
/**
|
|
26
|
+
* Default protection options
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_OPTIONS = {
|
|
29
|
+
encrypt: false,
|
|
30
|
+
verify: true,
|
|
31
|
+
backup: true,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Data Protector class
|
|
35
|
+
*/
|
|
36
|
+
export class DataProtector {
|
|
37
|
+
options;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Update options
|
|
43
|
+
*/
|
|
44
|
+
configure(options) {
|
|
45
|
+
this.options = { ...this.options, ...options };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Protect and save data to file
|
|
49
|
+
*/
|
|
50
|
+
async save(filePath, data, options) {
|
|
51
|
+
const opts = { ...this.options, ...options };
|
|
52
|
+
// Create backup if enabled
|
|
53
|
+
if (opts.backup) {
|
|
54
|
+
await this.createBackup(filePath, opts.backupPath);
|
|
55
|
+
}
|
|
56
|
+
// Serialize data
|
|
57
|
+
const serialized = JSON.stringify(data, null, 2);
|
|
58
|
+
// Create protected structure
|
|
59
|
+
const protected_ = opts.encrypt && opts.key
|
|
60
|
+
? await this.encrypt(serialized, opts.key)
|
|
61
|
+
: this.createPlainProtected(serialized);
|
|
62
|
+
// Ensure directory exists
|
|
63
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
64
|
+
// Write to file
|
|
65
|
+
await writeFile(filePath, JSON.stringify(protected_, null, 2));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Load and verify data from file
|
|
69
|
+
*/
|
|
70
|
+
async load(filePath, options) {
|
|
71
|
+
const opts = { ...this.options, ...options };
|
|
72
|
+
// Read file
|
|
73
|
+
const content = await readFile(filePath, 'utf-8');
|
|
74
|
+
const protected_ = JSON.parse(content);
|
|
75
|
+
// Verify integrity if enabled
|
|
76
|
+
if (opts.verify) {
|
|
77
|
+
const isValid = this.verifyIntegrity(protected_);
|
|
78
|
+
if (!isValid) {
|
|
79
|
+
throw new Error('Data integrity verification failed');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Decrypt if encrypted
|
|
83
|
+
let payload;
|
|
84
|
+
if (protected_.encrypted) {
|
|
85
|
+
if (!opts.key) {
|
|
86
|
+
throw new Error('Encryption key required to load encrypted data');
|
|
87
|
+
}
|
|
88
|
+
payload = await this.decrypt(protected_, opts.key);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
payload = protected_.payload;
|
|
92
|
+
}
|
|
93
|
+
return JSON.parse(payload);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if file exists
|
|
97
|
+
*/
|
|
98
|
+
async exists(filePath) {
|
|
99
|
+
try {
|
|
100
|
+
await access(filePath);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Delete protected file
|
|
109
|
+
*/
|
|
110
|
+
async delete(filePath, options) {
|
|
111
|
+
await unlink(filePath);
|
|
112
|
+
if (options?.deleteBackups && this.options.backupPath) {
|
|
113
|
+
const backupPath = this.getBackupPath(filePath, this.options.backupPath);
|
|
114
|
+
try {
|
|
115
|
+
await unlink(backupPath);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Backup may not exist
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Calculate hash of data
|
|
124
|
+
*/
|
|
125
|
+
hash(data) {
|
|
126
|
+
return createHash('sha256').update(data).digest('hex');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Verify data integrity
|
|
130
|
+
*/
|
|
131
|
+
verifyIntegrity(protected_) {
|
|
132
|
+
const calculatedHash = this.hash(protected_.payload);
|
|
133
|
+
return calculatedHash === protected_.hash;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create plain protected data structure
|
|
137
|
+
*/
|
|
138
|
+
createPlainProtected(data) {
|
|
139
|
+
return {
|
|
140
|
+
version: 1,
|
|
141
|
+
encrypted: false,
|
|
142
|
+
payload: data,
|
|
143
|
+
hash: this.hash(data),
|
|
144
|
+
timestamp: new Date().toISOString(),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Encrypt data
|
|
149
|
+
*/
|
|
150
|
+
async encrypt(data, password) {
|
|
151
|
+
// Generate salt and derive key
|
|
152
|
+
const salt = randomBytes(SALT_LENGTH);
|
|
153
|
+
const key = await scryptAsync(password, salt, KEY_LENGTH);
|
|
154
|
+
// Generate IV
|
|
155
|
+
const iv = randomBytes(IV_LENGTH);
|
|
156
|
+
// Encrypt
|
|
157
|
+
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
158
|
+
const encrypted = Buffer.concat([
|
|
159
|
+
cipher.update(data, 'utf8'),
|
|
160
|
+
cipher.final(),
|
|
161
|
+
]);
|
|
162
|
+
const authTag = cipher.getAuthTag();
|
|
163
|
+
return {
|
|
164
|
+
version: 1,
|
|
165
|
+
encrypted: true,
|
|
166
|
+
salt: salt.toString('hex'),
|
|
167
|
+
iv: iv.toString('hex'),
|
|
168
|
+
authTag: authTag.toString('hex'),
|
|
169
|
+
payload: encrypted.toString('hex'),
|
|
170
|
+
hash: this.hash(encrypted.toString('hex')),
|
|
171
|
+
timestamp: new Date().toISOString(),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Decrypt data
|
|
176
|
+
*/
|
|
177
|
+
async decrypt(protected_, password) {
|
|
178
|
+
if (!protected_.salt || !protected_.iv || !protected_.authTag) {
|
|
179
|
+
throw new Error('Invalid encrypted data structure');
|
|
180
|
+
}
|
|
181
|
+
// Derive key from password
|
|
182
|
+
const salt = Buffer.from(protected_.salt, 'hex');
|
|
183
|
+
const key = await scryptAsync(password, salt, KEY_LENGTH);
|
|
184
|
+
// Get IV and auth tag
|
|
185
|
+
const iv = Buffer.from(protected_.iv, 'hex');
|
|
186
|
+
const authTag = Buffer.from(protected_.authTag, 'hex');
|
|
187
|
+
const encrypted = Buffer.from(protected_.payload, 'hex');
|
|
188
|
+
// Decrypt
|
|
189
|
+
const decipher = createDecipheriv(ALGORITHM, key, iv);
|
|
190
|
+
decipher.setAuthTag(authTag);
|
|
191
|
+
const decrypted = Buffer.concat([
|
|
192
|
+
decipher.update(encrypted),
|
|
193
|
+
decipher.final(),
|
|
194
|
+
]);
|
|
195
|
+
return decrypted.toString('utf8');
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Create backup of file
|
|
199
|
+
*/
|
|
200
|
+
async createBackup(filePath, backupDir) {
|
|
201
|
+
try {
|
|
202
|
+
const exists = await this.exists(filePath);
|
|
203
|
+
if (!exists) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const content = await readFile(filePath, 'utf-8');
|
|
207
|
+
const backupPath = this.getBackupPath(filePath, backupDir);
|
|
208
|
+
await mkdir(dirname(backupPath), { recursive: true });
|
|
209
|
+
await writeFile(backupPath, content);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// Silently fail backup - don't block main operation
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get backup file path
|
|
217
|
+
*/
|
|
218
|
+
getBackupPath(filePath, backupDir) {
|
|
219
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
220
|
+
const fileName = filePath.split('/').pop() ?? 'backup';
|
|
221
|
+
const backupFileName = `${fileName}.${timestamp}.bak`;
|
|
222
|
+
if (backupDir) {
|
|
223
|
+
return join(backupDir, backupFileName);
|
|
224
|
+
}
|
|
225
|
+
return join(dirname(filePath), '.backups', backupFileName);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Sensitive data patterns for detection
|
|
230
|
+
*/
|
|
231
|
+
const SENSITIVE_PATTERNS = [
|
|
232
|
+
/api[_-]?key/i,
|
|
233
|
+
/secret/i,
|
|
234
|
+
/password/i,
|
|
235
|
+
/token/i,
|
|
236
|
+
/credential/i,
|
|
237
|
+
/private[_-]?key/i,
|
|
238
|
+
/auth/i,
|
|
239
|
+
];
|
|
240
|
+
/**
|
|
241
|
+
* Check if key might contain sensitive data
|
|
242
|
+
*/
|
|
243
|
+
export function isSensitiveKey(key) {
|
|
244
|
+
return SENSITIVE_PATTERNS.some(pattern => pattern.test(key));
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Mask sensitive value for logging
|
|
248
|
+
*/
|
|
249
|
+
export function maskValue(value) {
|
|
250
|
+
if (value.length <= 4) {
|
|
251
|
+
return '****';
|
|
252
|
+
}
|
|
253
|
+
return value.slice(0, 2) + '*'.repeat(value.length - 4) + value.slice(-2);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Redact sensitive data from object for logging
|
|
257
|
+
*/
|
|
258
|
+
export function redactSensitive(obj) {
|
|
259
|
+
const result = { ...obj };
|
|
260
|
+
for (const key of Object.keys(result)) {
|
|
261
|
+
const value = result[key];
|
|
262
|
+
if (isSensitiveKey(key) && typeof value === 'string') {
|
|
263
|
+
result[key] = maskValue(value);
|
|
264
|
+
}
|
|
265
|
+
else if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
266
|
+
result[key] = redactSensitive(value);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Global data protector instance
|
|
273
|
+
*/
|
|
274
|
+
export const dataProtector = new DataProtector();
|
|
275
|
+
//# sourceMappingURL=data-protector.js.map
|