avana-cli 2.11.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/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +584 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +153 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/install.d.ts +6 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +101 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/scan.d.ts +19 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +383 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/uninstall.d.ts +6 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +80 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +475 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/additional-patterns.d.ts +12 -0
- package/dist/rules/additional-patterns.d.ts.map +1 -0
- package/dist/rules/additional-patterns.js +170 -0
- package/dist/rules/additional-patterns.js.map +1 -0
- package/dist/rules/code-patterns.d.ts +26 -0
- package/dist/rules/code-patterns.d.ts.map +1 -0
- package/dist/rules/code-patterns.js +220 -0
- package/dist/rules/code-patterns.js.map +1 -0
- package/dist/rules/secret-patterns.d.ts +28 -0
- package/dist/rules/secret-patterns.d.ts.map +1 -0
- package/dist/rules/secret-patterns.js +1729 -0
- package/dist/rules/secret-patterns.js.map +1 -0
- package/dist/scanners/secret-scanner.d.ts +34 -0
- package/dist/scanners/secret-scanner.d.ts.map +1 -0
- package/dist/scanners/secret-scanner.js +281 -0
- package/dist/scanners/secret-scanner.js.map +1 -0
- package/dist/types/index.d.ts +116 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/error-handler.d.ts +126 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +222 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/exit-codes.d.ts +52 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/exit-codes.js +89 -0
- package/dist/utils/exit-codes.js.map +1 -0
- package/dist/utils/file-stream-scanner.d.ts +31 -0
- package/dist/utils/file-stream-scanner.d.ts.map +1 -0
- package/dist/utils/file-stream-scanner.js +159 -0
- package/dist/utils/file-stream-scanner.js.map +1 -0
- package/dist/utils/file-type-detector.d.ts +45 -0
- package/dist/utils/file-type-detector.d.ts.map +1 -0
- package/dist/utils/file-type-detector.js +237 -0
- package/dist/utils/file-type-detector.js.map +1 -0
- package/dist/utils/ignore-pattern-manager.d.ts +61 -0
- package/dist/utils/ignore-pattern-manager.d.ts.map +1 -0
- package/dist/utils/ignore-pattern-manager.js +204 -0
- package/dist/utils/ignore-pattern-manager.js.map +1 -0
- package/dist/utils/json-output-formatter.d.ts +232 -0
- package/dist/utils/json-output-formatter.d.ts.map +1 -0
- package/dist/utils/json-output-formatter.js +367 -0
- package/dist/utils/json-output-formatter.js.map +1 -0
- package/dist/utils/logger.d.ts +181 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +414 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown-output-formatter.d.ts +65 -0
- package/dist/utils/markdown-output-formatter.d.ts.map +1 -0
- package/dist/utils/markdown-output-formatter.js +316 -0
- package/dist/utils/markdown-output-formatter.js.map +1 -0
- package/dist/utils/memory-manager.d.ts +77 -0
- package/dist/utils/memory-manager.d.ts.map +1 -0
- package/dist/utils/memory-manager.js +157 -0
- package/dist/utils/memory-manager.js.map +1 -0
- package/dist/utils/parallel-scanner-worker.d.ts +19 -0
- package/dist/utils/parallel-scanner-worker.d.ts.map +1 -0
- package/dist/utils/parallel-scanner-worker.js +51 -0
- package/dist/utils/parallel-scanner-worker.js.map +1 -0
- package/dist/utils/parallel-scanner.d.ts +82 -0
- package/dist/utils/parallel-scanner.d.ts.map +1 -0
- package/dist/utils/parallel-scanner.js +229 -0
- package/dist/utils/parallel-scanner.js.map +1 -0
- package/dist/utils/pattern-validator.d.ts +108 -0
- package/dist/utils/pattern-validator.d.ts.map +1 -0
- package/dist/utils/pattern-validator.js +315 -0
- package/dist/utils/pattern-validator.js.map +1 -0
- package/dist/utils/progress-reporter.d.ts +68 -0
- package/dist/utils/progress-reporter.d.ts.map +1 -0
- package/dist/utils/progress-reporter.js +194 -0
- package/dist/utils/progress-reporter.js.map +1 -0
- package/dist/utils/result-cache.d.ts +99 -0
- package/dist/utils/result-cache.d.ts.map +1 -0
- package/dist/utils/result-cache.js +335 -0
- package/dist/utils/result-cache.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,oBAAY,QAAQ;IAClB,OAAO,IAAI;IACX,YAAY,IAAI;IAChB,aAAa,IAAI;IACjB,gBAAgB,IAAI;CACrB;AAED;;GAEG;AAEH;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAEnC,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM;CAKnB;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAEjC,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM;CAKnB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAEpC,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;gBADhB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM;CAKnB;AAED;;GA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E;IAIjD;;OAEG;IACI,WAAW,IAAI,IAAI;IAI1B;;OAEG;IACI,SAAS,IAAI,OAAO;IAI3B;;OAEG;IACI,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CASjD"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error Handler
|
|
4
|
+
* Centralized error handling with proper exit codes and error tracking
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ErrorHandler = exports.PatternCompilationError = exports.OutOfMemoryError = exports.ConfigurationError = exports.InvalidEncodingError = exports.FileNotFoundError = exports.FilePermissionError = exports.ExitCode = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Exit codes for the CLI
|
|
10
|
+
*/
|
|
11
|
+
var ExitCode;
|
|
12
|
+
(function (ExitCode) {
|
|
13
|
+
ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
|
|
14
|
+
ExitCode[ExitCode["ISSUES_FOUND"] = 1] = "ISSUES_FOUND";
|
|
15
|
+
ExitCode[ExitCode["INVALID_USAGE"] = 2] = "INVALID_USAGE";
|
|
16
|
+
ExitCode[ExitCode["UNEXPECTED_ERROR"] = 3] = "UNEXPECTED_ERROR";
|
|
17
|
+
})(ExitCode || (exports.ExitCode = ExitCode = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Custom error types for different error categories
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* File permission error - thrown when file cannot be read due to permissions
|
|
23
|
+
*/
|
|
24
|
+
class FilePermissionError extends Error {
|
|
25
|
+
filePath;
|
|
26
|
+
constructor(filePath, message) {
|
|
27
|
+
super(message || `Permission denied: ${filePath}`);
|
|
28
|
+
this.filePath = filePath;
|
|
29
|
+
this.name = 'FilePermissionError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.FilePermissionError = FilePermissionError;
|
|
33
|
+
/**
|
|
34
|
+
* File not found error - thrown when file doesn't exist
|
|
35
|
+
*/
|
|
36
|
+
class FileNotFoundError extends Error {
|
|
37
|
+
filePath;
|
|
38
|
+
constructor(filePath, message) {
|
|
39
|
+
super(message || `File not found: ${filePath}`);
|
|
40
|
+
this.filePath = filePath;
|
|
41
|
+
this.name = 'FileNotFoundError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.FileNotFoundError = FileNotFoundError;
|
|
45
|
+
/**
|
|
46
|
+
* Invalid encoding error - thrown when file encoding cannot be processed
|
|
47
|
+
*/
|
|
48
|
+
class InvalidEncodingError extends Error {
|
|
49
|
+
filePath;
|
|
50
|
+
encoding;
|
|
51
|
+
constructor(filePath, encoding, message) {
|
|
52
|
+
super(message || `Invalid encoding '${encoding}' for file: ${filePath}`);
|
|
53
|
+
this.filePath = filePath;
|
|
54
|
+
this.encoding = encoding;
|
|
55
|
+
this.name = 'InvalidEncodingError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.InvalidEncodingError = InvalidEncodingError;
|
|
59
|
+
/**
|
|
60
|
+
* Configuration error - thrown when configuration is invalid
|
|
61
|
+
*/
|
|
62
|
+
class ConfigurationError extends Error {
|
|
63
|
+
configKey;
|
|
64
|
+
constructor(configKey, message) {
|
|
65
|
+
super(message || `Invalid configuration: ${configKey}`);
|
|
66
|
+
this.configKey = configKey;
|
|
67
|
+
this.name = 'ConfigurationError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ConfigurationError = ConfigurationError;
|
|
71
|
+
/**
|
|
72
|
+
* Out of memory error - thrown when memory limit is exceeded
|
|
73
|
+
*/
|
|
74
|
+
class OutOfMemoryError extends Error {
|
|
75
|
+
currentUsage;
|
|
76
|
+
limit;
|
|
77
|
+
constructor(currentUsage, limit, message) {
|
|
78
|
+
super(message || `Out of memory: ${currentUsage}MB exceeds limit of ${limit}MB`);
|
|
79
|
+
this.currentUsage = currentUsage;
|
|
80
|
+
this.limit = limit;
|
|
81
|
+
this.name = 'OutOfMemoryError';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.OutOfMemoryError = OutOfMemoryError;
|
|
85
|
+
/**
|
|
86
|
+
* Pattern compilation error - thrown when regex pattern fails to compile
|
|
87
|
+
*/
|
|
88
|
+
class PatternCompilationError extends Error {
|
|
89
|
+
patternId;
|
|
90
|
+
pattern;
|
|
91
|
+
constructor(patternId, pattern, message) {
|
|
92
|
+
super(message || `Failed to compile pattern '${patternId}': ${pattern}`);
|
|
93
|
+
this.patternId = patternId;
|
|
94
|
+
this.pattern = pattern;
|
|
95
|
+
this.name = 'PatternCompilationError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.PatternCompilationError = PatternCompilationError;
|
|
99
|
+
/**
|
|
100
|
+
* Error Handler class
|
|
101
|
+
* Centralized error handling with logging and tracking
|
|
102
|
+
*/
|
|
103
|
+
class ErrorHandler {
|
|
104
|
+
errors = [];
|
|
105
|
+
debugMode = false;
|
|
106
|
+
constructor(debugMode = false) {
|
|
107
|
+
this.debugMode = debugMode;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Handle file-related errors (permission, not found, encoding)
|
|
111
|
+
* These errors should not stop the scan - log and continue
|
|
112
|
+
*/
|
|
113
|
+
handleFileError(filePath, error) {
|
|
114
|
+
const errorInfo = {
|
|
115
|
+
type: error.name || 'FileError',
|
|
116
|
+
message: error.message,
|
|
117
|
+
filePath,
|
|
118
|
+
timestamp: new Date(),
|
|
119
|
+
stack: this.debugMode ? error.stack : undefined,
|
|
120
|
+
};
|
|
121
|
+
this.errors.push(errorInfo);
|
|
122
|
+
// Log error to console
|
|
123
|
+
console.error(`Error scanning file ${filePath}: ${error.message}`);
|
|
124
|
+
if (this.debugMode && error.stack) {
|
|
125
|
+
console.error(error.stack);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Handle scan-related errors (unexpected errors during scanning)
|
|
130
|
+
* These errors should not stop the scan - log and continue
|
|
131
|
+
*/
|
|
132
|
+
handleScanError(error) {
|
|
133
|
+
const errorInfo = {
|
|
134
|
+
type: error.name || 'ScanError',
|
|
135
|
+
message: error.message,
|
|
136
|
+
timestamp: new Date(),
|
|
137
|
+
stack: this.debugMode ? error.stack : undefined,
|
|
138
|
+
};
|
|
139
|
+
this.errors.push(errorInfo);
|
|
140
|
+
// Log error to console
|
|
141
|
+
console.error(`Scan error: ${error.message}`);
|
|
142
|
+
if (this.debugMode && error.stack) {
|
|
143
|
+
console.error(error.stack);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Handle validation errors (invalid arguments, configuration)
|
|
148
|
+
* These errors should stop execution immediately
|
|
149
|
+
*/
|
|
150
|
+
handleValidationError(message) {
|
|
151
|
+
const errorInfo = {
|
|
152
|
+
type: 'ValidationError',
|
|
153
|
+
message,
|
|
154
|
+
timestamp: new Date(),
|
|
155
|
+
};
|
|
156
|
+
this.errors.push(errorInfo);
|
|
157
|
+
// Log error and exit
|
|
158
|
+
console.error(`Validation error: ${message}`);
|
|
159
|
+
process.exit(ExitCode.INVALID_USAGE);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Handle critical errors (out of memory, system errors)
|
|
163
|
+
* These errors should stop execution immediately
|
|
164
|
+
*/
|
|
165
|
+
handleCriticalError(error) {
|
|
166
|
+
const errorInfo = {
|
|
167
|
+
type: error.name || 'CriticalError',
|
|
168
|
+
message: error.message,
|
|
169
|
+
timestamp: new Date(),
|
|
170
|
+
stack: this.debugMode ? error.stack : undefined,
|
|
171
|
+
};
|
|
172
|
+
this.errors.push(errorInfo);
|
|
173
|
+
// Log error and exit
|
|
174
|
+
console.error(`Critical error: ${error.message}`);
|
|
175
|
+
if (this.debugMode && error.stack) {
|
|
176
|
+
console.error(error.stack);
|
|
177
|
+
}
|
|
178
|
+
process.exit(ExitCode.UNEXPECTED_ERROR);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get total error count
|
|
182
|
+
*/
|
|
183
|
+
getErrorCount() {
|
|
184
|
+
return this.errors.length;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get all errors
|
|
188
|
+
*/
|
|
189
|
+
getErrors() {
|
|
190
|
+
return [...this.errors];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get errors by type
|
|
194
|
+
*/
|
|
195
|
+
getErrorsByType(type) {
|
|
196
|
+
return this.errors.filter(error => error.type === type);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Clear all errors
|
|
200
|
+
*/
|
|
201
|
+
clearErrors() {
|
|
202
|
+
this.errors = [];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if there are any errors
|
|
206
|
+
*/
|
|
207
|
+
hasErrors() {
|
|
208
|
+
return this.errors.length > 0;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get error summary
|
|
212
|
+
*/
|
|
213
|
+
getErrorSummary() {
|
|
214
|
+
const summary = {};
|
|
215
|
+
for (const error of this.errors) {
|
|
216
|
+
summary[error.type] = (summary[error.type] || 0) + 1;
|
|
217
|
+
}
|
|
218
|
+
return summary;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.ErrorHandler = ErrorHandler;
|
|
222
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACH,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,6CAAW,CAAA;IACX,uDAAgB,CAAA;IAChB,yDAAiB,CAAA;IACjB,+DAAoB,CAAA;AACtB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB;AAED;;GAEG;AAEH;;GAEG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAEnC;IADT,YACS,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
|
+
/**
|
|
2
|
+
* Exit Code Utilities
|
|
3
|
+
* Standard exit codes for CI/CD integration
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Standard exit codes for Avana CLI
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ExitCode {
|
|
9
|
+
/** No critical or high severity issues found */
|
|
10
|
+
SUCCESS = 0,
|
|
11
|
+
/** Critical or high severity issues found */
|
|
12
|
+
ISSUES_FOUND = 1,
|
|
13
|
+
/** Invalid arguments or configuration */
|
|
14
|
+
INVALID_ARGUMENTS = 2,
|
|
15
|
+
/** Unexpected error occurred */
|
|
16
|
+
UNEXPECTED_ERROR = 3
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Exit code descriptions for documentation
|
|
20
|
+
*/
|
|
21
|
+
export declare const EXIT_CODE_DESCRIPTIONS: {
|
|
22
|
+
readonly 0: "No critical or high severity issues found";
|
|
23
|
+
readonly 1: "Critical or high severity issues found";
|
|
24
|
+
readonly 2: "Invalid arguments or configuration";
|
|
25
|
+
readonly 3: "Unexpected error occurred";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Determine exit code based on scan results and options
|
|
29
|
+
*/
|
|
30
|
+
export declare function determineExitCode(result: {
|
|
31
|
+
summary: {
|
|
32
|
+
critical: number;
|
|
33
|
+
high: number;
|
|
34
|
+
medium: number;
|
|
35
|
+
low: number;
|
|
36
|
+
};
|
|
37
|
+
}, options?: {
|
|
38
|
+
failOnHigh?: boolean;
|
|
39
|
+
}): ExitCode;
|
|
40
|
+
/**
|
|
41
|
+
* Exit the process with the appropriate code and message
|
|
42
|
+
*/
|
|
43
|
+
export declare function exitWithCode(code: ExitCode, message?: string): never;
|
|
44
|
+
/**
|
|
45
|
+
* Handle unexpected errors with proper exit code
|
|
46
|
+
*/
|
|
47
|
+
export declare function handleUnexpectedError(error: Error): never;
|
|
48
|
+
/**
|
|
49
|
+
* Handle invalid arguments with proper exit code
|
|
50
|
+
*/
|
|
51
|
+
export declare function handleInvalidArguments(message: string): never;
|
|
52
|
+
//# 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;;;GAGG;AAEH;;GAEG;AACH,oBAAY,QAAQ;IAClB,gDAAgD;IAChD,OAAO,IAAI;IAEX,6CAA6C;IAC7C,YAAY,IAAI;IAEhB,yCAAyC;IACzC,iBAAiB,IAAI;IAErB,gCAAgC;IAChC,gBAAgB,IAAI;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;CAKzB,CAAC;AAEX;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpF,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACrC,QAAQ,CAmBV;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAUpE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAUzD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAM7D"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Exit Code Utilities
|
|
4
|
+
* Standard exit codes for CI/CD integration
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.EXIT_CODE_DESCRIPTIONS = exports.ExitCode = void 0;
|
|
8
|
+
exports.determineExitCode = determineExitCode;
|
|
9
|
+
exports.exitWithCode = exitWithCode;
|
|
10
|
+
exports.handleUnexpectedError = handleUnexpectedError;
|
|
11
|
+
exports.handleInvalidArguments = handleInvalidArguments;
|
|
12
|
+
/**
|
|
13
|
+
* Standard exit codes for Avana CLI
|
|
14
|
+
*/
|
|
15
|
+
var ExitCode;
|
|
16
|
+
(function (ExitCode) {
|
|
17
|
+
/** No critical or high severity issues found */
|
|
18
|
+
ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
|
|
19
|
+
/** Critical or high severity issues found */
|
|
20
|
+
ExitCode[ExitCode["ISSUES_FOUND"] = 1] = "ISSUES_FOUND";
|
|
21
|
+
/** Invalid arguments or configuration */
|
|
22
|
+
ExitCode[ExitCode["INVALID_ARGUMENTS"] = 2] = "INVALID_ARGUMENTS";
|
|
23
|
+
/** Unexpected error occurred */
|
|
24
|
+
ExitCode[ExitCode["UNEXPECTED_ERROR"] = 3] = "UNEXPECTED_ERROR";
|
|
25
|
+
})(ExitCode || (exports.ExitCode = ExitCode = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Exit code descriptions for documentation
|
|
28
|
+
*/
|
|
29
|
+
exports.EXIT_CODE_DESCRIPTIONS = {
|
|
30
|
+
[ExitCode.SUCCESS]: 'No critical or high severity issues found',
|
|
31
|
+
[ExitCode.ISSUES_FOUND]: 'Critical or high severity issues found',
|
|
32
|
+
[ExitCode.INVALID_ARGUMENTS]: 'Invalid arguments or configuration',
|
|
33
|
+
[ExitCode.UNEXPECTED_ERROR]: 'Unexpected error occurred'
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Determine exit code based on scan results and options
|
|
37
|
+
*/
|
|
38
|
+
function determineExitCode(result, options = {}) {
|
|
39
|
+
const { critical, high } = result.summary;
|
|
40
|
+
// Always exit with error code if critical issues found
|
|
41
|
+
if (critical > 0) {
|
|
42
|
+
return ExitCode.ISSUES_FOUND;
|
|
43
|
+
}
|
|
44
|
+
// Exit with error code if high issues found and --fail-on-high is set
|
|
45
|
+
if (high > 0 && options.failOnHigh) {
|
|
46
|
+
return ExitCode.ISSUES_FOUND;
|
|
47
|
+
}
|
|
48
|
+
// Exit with error code if high issues found (default behavior)
|
|
49
|
+
if (high > 0) {
|
|
50
|
+
return ExitCode.ISSUES_FOUND;
|
|
51
|
+
}
|
|
52
|
+
return ExitCode.SUCCESS;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Exit the process with the appropriate code and message
|
|
56
|
+
*/
|
|
57
|
+
function exitWithCode(code, message) {
|
|
58
|
+
if (message) {
|
|
59
|
+
if (code === ExitCode.SUCCESS) {
|
|
60
|
+
console.log(message);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
process.exit(code);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle unexpected errors with proper exit code
|
|
70
|
+
*/
|
|
71
|
+
function handleUnexpectedError(error) {
|
|
72
|
+
console.error('❌ Unexpected error occurred:');
|
|
73
|
+
console.error(error.message);
|
|
74
|
+
if (process.env.DEBUG) {
|
|
75
|
+
console.error('\nStack trace:');
|
|
76
|
+
console.error(error.stack);
|
|
77
|
+
}
|
|
78
|
+
process.exit(ExitCode.UNEXPECTED_ERROR);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Handle invalid arguments with proper exit code
|
|
82
|
+
*/
|
|
83
|
+
function handleInvalidArguments(message) {
|
|
84
|
+
console.error('❌ Invalid arguments:');
|
|
85
|
+
console.error(message);
|
|
86
|
+
console.error('\nRun "avana --help" for usage information');
|
|
87
|
+
process.exit(ExitCode.INVALID_ARGUMENTS);
|
|
88
|
+
}
|
|
89
|
+
//# 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;;;G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AE,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,KAAY;IAChD,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC9C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE7B,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IACpD,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACtC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAE5D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Stream Scanner
|
|
3
|
+
* Scans large files in chunks to avoid memory issues
|
|
4
|
+
*/
|
|
5
|
+
import type { SecurityIssue, FileEncoding } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Stream options for file scanning
|
|
8
|
+
*/
|
|
9
|
+
interface StreamOptions {
|
|
10
|
+
chunkSize: number;
|
|
11
|
+
overlap: number;
|
|
12
|
+
maxMemory: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* FileStreamScanner class
|
|
16
|
+
* Scans large files in chunks to avoid memory issues
|
|
17
|
+
*/
|
|
18
|
+
export declare class FileStreamScanner {
|
|
19
|
+
private options;
|
|
20
|
+
constructor(options?: Partial<StreamOptions>);
|
|
21
|
+
/**
|
|
22
|
+
* Scan a large file using streaming
|
|
23
|
+
*/
|
|
24
|
+
scanStream(filePath: string, encoding?: FileEncoding): Promise<SecurityIssue[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Decode buffer to string using specified encoding
|
|
27
|
+
*/
|
|
28
|
+
private decodeBuffer;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=file-stream-scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-stream-scanner.d.ts","sourceRoot":"","sources":["../../src/utils/file-stream-scanner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAe5D;;GAEG;AACH,UAAU,aAAa;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAgB;gBAEnB,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;IAS5C;;OAEG;IACU,UAAU,CACrB,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,YAAsB,GAC/B,OAAO,CAAC,aAAa,EAAE,CAAC;IAsF3B;;OAEG;IACH,OAAO,CAAC,YAAY;CAgBrB"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* File Stream Scanner
|
|
4
|
+
* Scans large files in chunks to avoid memory issues
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.FileStreamScanner = void 0;
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const iconv = __importStar(require("iconv-lite"));
|
|
43
|
+
const secret_patterns_1 = require("../rules/secret-patterns");
|
|
44
|
+
const additional_patterns_1 = require("../rules/additional-patterns");
|
|
45
|
+
/**
|
|
46
|
+
* Default chunk size: 64KB
|
|
47
|
+
*/
|
|
48
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
49
|
+
/**
|
|
50
|
+
* Default overlap between chunks: 1KB
|
|
51
|
+
* This ensures patterns spanning chunk boundaries are detected
|
|
52
|
+
*/
|
|
53
|
+
const DEFAULT_OVERLAP = 1024;
|
|
54
|
+
/**
|
|
55
|
+
* FileStreamScanner class
|
|
56
|
+
* Scans large files in chunks to avoid memory issues
|
|
57
|
+
*/
|
|
58
|
+
class FileStreamScanner {
|
|
59
|
+
options;
|
|
60
|
+
constructor(options) {
|
|
61
|
+
this.options = {
|
|
62
|
+
chunkSize: DEFAULT_CHUNK_SIZE,
|
|
63
|
+
overlap: DEFAULT_OVERLAP,
|
|
64
|
+
maxMemory: 500 * 1024 * 1024, // 500MB
|
|
65
|
+
...options,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Scan a large file using streaming
|
|
70
|
+
*/
|
|
71
|
+
async scanStream(filePath, encoding = 'utf-8') {
|
|
72
|
+
const issues = [];
|
|
73
|
+
const fd = fs.openSync(filePath, 'r');
|
|
74
|
+
try {
|
|
75
|
+
const stats = fs.fstatSync(fd);
|
|
76
|
+
const fileSize = stats.size;
|
|
77
|
+
// Get all patterns
|
|
78
|
+
const patterns = [
|
|
79
|
+
...(0, secret_patterns_1.getAllSecretPatterns)(),
|
|
80
|
+
...(0, additional_patterns_1.getAdditionalSecretPatterns)()
|
|
81
|
+
];
|
|
82
|
+
let position = 0;
|
|
83
|
+
let lineNumber = 1;
|
|
84
|
+
let previousOverlap = '';
|
|
85
|
+
while (position < fileSize) {
|
|
86
|
+
// Read chunk
|
|
87
|
+
const chunkSize = Math.min(this.options.chunkSize, fileSize - position);
|
|
88
|
+
const buffer = Buffer.alloc(chunkSize);
|
|
89
|
+
const bytesRead = fs.readSync(fd, buffer, 0, chunkSize, position);
|
|
90
|
+
if (bytesRead === 0) {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
// Convert encoding to UTF-8
|
|
94
|
+
const chunkText = this.decodeBuffer(buffer.slice(0, bytesRead), encoding);
|
|
95
|
+
// Combine with previous overlap
|
|
96
|
+
const textToScan = previousOverlap + chunkText;
|
|
97
|
+
const lines = textToScan.split('\n');
|
|
98
|
+
// Scan the chunk for patterns
|
|
99
|
+
patterns.forEach(pattern => {
|
|
100
|
+
lines.forEach((line, lineIndex) => {
|
|
101
|
+
const matches = line.matchAll(pattern.pattern);
|
|
102
|
+
for (const match of matches) {
|
|
103
|
+
const actualLineNumber = lineNumber + lineIndex;
|
|
104
|
+
// Only add if not a duplicate from overlap region
|
|
105
|
+
const issueKey = `${pattern.id}-${actualLineNumber}-${match.index}`;
|
|
106
|
+
const isDuplicate = issues.some(existing => existing.id === `${pattern.id}-${filePath}-${actualLineNumber - 1}` ||
|
|
107
|
+
existing.id === issueKey);
|
|
108
|
+
if (!isDuplicate) {
|
|
109
|
+
issues.push({
|
|
110
|
+
id: `${pattern.id}-${filePath}-${actualLineNumber - 1}`,
|
|
111
|
+
type: 'secret',
|
|
112
|
+
severity: pattern.severity,
|
|
113
|
+
title: pattern.name,
|
|
114
|
+
description: pattern.description,
|
|
115
|
+
file: filePath,
|
|
116
|
+
line: actualLineNumber,
|
|
117
|
+
column: match.index,
|
|
118
|
+
code: line.trim(),
|
|
119
|
+
suggestion: pattern.suggestion,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
// Update line number for next chunk
|
|
126
|
+
lineNumber += chunkText.split('\n').length - 1;
|
|
127
|
+
// Save overlap for next iteration
|
|
128
|
+
const overlapSize = Math.min(this.options.overlap, chunkText.length);
|
|
129
|
+
previousOverlap = chunkText.slice(-overlapSize);
|
|
130
|
+
// Move position forward
|
|
131
|
+
position += bytesRead;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
fs.closeSync(fd);
|
|
136
|
+
}
|
|
137
|
+
return issues;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Decode buffer to string using specified encoding
|
|
141
|
+
*/
|
|
142
|
+
decodeBuffer(buffer, encoding) {
|
|
143
|
+
switch (encoding) {
|
|
144
|
+
case 'utf-8':
|
|
145
|
+
return buffer.toString('utf-8');
|
|
146
|
+
case 'utf-16':
|
|
147
|
+
return iconv.decode(buffer, 'utf-16le');
|
|
148
|
+
case 'latin-1':
|
|
149
|
+
return iconv.decode(buffer, 'latin1');
|
|
150
|
+
case 'ascii':
|
|
151
|
+
return buffer.toString('ascii');
|
|
152
|
+
default:
|
|
153
|
+
// Default to UTF-8
|
|
154
|
+
return buffer.toString('utf-8');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.FileStreamScanner = FileStreamScanner;
|
|
159
|
+
//# sourceMappingURL=file-stream-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-stream-scanner.js","sourceRoot":"","sources":["../../src/utils/file-stream-scanner.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,kDAAoC;AAEpC,8DAAgE;AAChE,sEAA2E;AAE3E;;GAEG;AACH,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC;;;GAGG;AACH,MAAM,eAAe,GAAG,IAAI,CAAC;AAW7B;;;GAGG;AACH,MAAa,iBAAiB;IACpB,OAAO,CAAgB;IAE/B,YAAY,OAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG;YACb,SAAS,EAAE,kBAAkB;YAC7B,OAAO,EAAE,eAAe;YACxB,SAAS,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,QAAQ;YACtC,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CA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gBACpC,UAAU,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;gBAE/C,kCAAkC;gBAClC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;gBACrE,eAAe,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC;gBAEhD,wBAAwB;gBACxB,QAAQ,IAAI,SAAS,CAAC;YACxB,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,MAAc,EAAE,QAAsB;QACzD,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,OAAO;gBACV,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAClC,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YAC1C,KAAK,SAAS;gBACZ,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACxC,KAAK,OAAO;gBACV,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAClC;gBACE,mBAAmB;gBACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;CAEF;AA3HD,8CA2HC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Type Detector
|
|
3
|
+
* Detects file types, encodings, and determines scanning strategy
|
|
4
|
+
*/
|
|
5
|
+
import type { FileEncoding, FileInfo } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* FileTypeDetector class
|
|
8
|
+
* Detects file types and encodings before scanning
|
|
9
|
+
*/
|
|
10
|
+
export declare class FileTypeDetector {
|
|
11
|
+
/**
|
|
12
|
+
* Check if a file is binary based on extension and content
|
|
13
|
+
*/
|
|
14
|
+
isBinary(filePath: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Detect file encoding
|
|
17
|
+
*/
|
|
18
|
+
detectEncoding(filePath: string): FileEncoding;
|
|
19
|
+
/**
|
|
20
|
+
* Check if file should be streamed (> 10MB)
|
|
21
|
+
*/
|
|
22
|
+
shouldStream(filePath: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get complete file information
|
|
25
|
+
*/
|
|
26
|
+
getFileInfo(filePath: string): FileInfo;
|
|
27
|
+
/**
|
|
28
|
+
* Read file buffer for detection
|
|
29
|
+
*/
|
|
30
|
+
private readFileBuffer;
|
|
31
|
+
/**
|
|
32
|
+
* Check if buffer contains binary content
|
|
33
|
+
* Binary files typically have null bytes or high-bit characters
|
|
34
|
+
*/
|
|
35
|
+
private isBinaryContent;
|
|
36
|
+
/**
|
|
37
|
+
* Detect BOM (Byte Order Mark)
|
|
38
|
+
*/
|
|
39
|
+
private detectBOM;
|
|
40
|
+
/**
|
|
41
|
+
* Normalize encoding name from chardet to our FileEncoding type
|
|
42
|
+
*/
|
|
43
|
+
private normalizeEncoding;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=file-type-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-type-detector.d.ts","sourceRoot":"","sources":["../../src/utils/file-type-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAoCvD;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;IACI,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAiB1C;;OAEG;IACI,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY;IAwBrD;;OAEG;IACI,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAU9C;;OAEG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ;IAsB9C;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAqBvB;;OAEG;IACH,OAAO,CAAC,SAAS;IAmBjB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAsB1B"}
|