@dotsetlabs/tollgate 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +885 -0
- package/dist/analyzers/filesystem.d.ts +26 -0
- package/dist/analyzers/filesystem.d.ts.map +1 -0
- package/dist/analyzers/filesystem.js +284 -0
- package/dist/analyzers/filesystem.js.map +1 -0
- package/dist/analyzers/http.d.ts +90 -0
- package/dist/analyzers/http.d.ts.map +1 -0
- package/dist/analyzers/http.js +433 -0
- package/dist/analyzers/http.js.map +1 -0
- package/dist/analyzers/index.d.ts +101 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +342 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/analyzers/loader.d.ts +114 -0
- package/dist/analyzers/loader.d.ts.map +1 -0
- package/dist/analyzers/loader.js +184 -0
- package/dist/analyzers/loader.js.map +1 -0
- package/dist/analyzers/prompt-injection.d.ts +95 -0
- package/dist/analyzers/prompt-injection.d.ts.map +1 -0
- package/dist/analyzers/prompt-injection.js +725 -0
- package/dist/analyzers/prompt-injection.js.map +1 -0
- package/dist/analyzers/sdk.d.ts +230 -0
- package/dist/analyzers/sdk.d.ts.map +1 -0
- package/dist/analyzers/sdk.js +283 -0
- package/dist/analyzers/sdk.js.map +1 -0
- package/dist/analyzers/shell.d.ts +20 -0
- package/dist/analyzers/shell.d.ts.map +1 -0
- package/dist/analyzers/shell.js +297 -0
- package/dist/analyzers/shell.js.map +1 -0
- package/dist/analyzers/sql.d.ts +37 -0
- package/dist/analyzers/sql.d.ts.map +1 -0
- package/dist/analyzers/sql.js +455 -0
- package/dist/analyzers/sql.js.map +1 -0
- package/dist/analyzers/types.d.ts +117 -0
- package/dist/analyzers/types.d.ts.map +1 -0
- package/dist/analyzers/types.js +46 -0
- package/dist/analyzers/types.js.map +1 -0
- package/dist/approval/interactive.d.ts +72 -0
- package/dist/approval/interactive.d.ts.map +1 -0
- package/dist/approval/interactive.js +550 -0
- package/dist/approval/interactive.js.map +1 -0
- package/dist/approval/terminal.d.ts +59 -0
- package/dist/approval/terminal.d.ts.map +1 -0
- package/dist/approval/terminal.js +238 -0
- package/dist/approval/terminal.js.map +1 -0
- package/dist/approval/types.d.ts +66 -0
- package/dist/approval/types.d.ts.map +1 -0
- package/dist/approval/types.js +2 -0
- package/dist/approval/types.js.map +1 -0
- package/dist/audit/exporter.d.ts +138 -0
- package/dist/audit/exporter.d.ts.map +1 -0
- package/dist/audit/exporter.js +366 -0
- package/dist/audit/exporter.js.map +1 -0
- package/dist/audit/logger.d.ts +156 -0
- package/dist/audit/logger.d.ts.map +1 -0
- package/dist/audit/logger.js +406 -0
- package/dist/audit/logger.js.map +1 -0
- package/dist/audit/redaction.d.ts +110 -0
- package/dist/audit/redaction.d.ts.map +1 -0
- package/dist/audit/redaction.js +307 -0
- package/dist/audit/redaction.js.map +1 -0
- package/dist/audit/schema.d.ts +76 -0
- package/dist/audit/schema.d.ts.map +1 -0
- package/dist/audit/schema.js +122 -0
- package/dist/audit/schema.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +34 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +431 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/export.d.ts +18 -0
- package/dist/cli/commands/export.d.ts.map +1 -0
- package/dist/cli/commands/export.js +63 -0
- package/dist/cli/commands/export.js.map +1 -0
- package/dist/cli/commands/init.d.ts +12 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +102 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/logs.d.ts +11 -0
- package/dist/cli/commands/logs.d.ts.map +1 -0
- package/dist/cli/commands/logs.js +60 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/scan.d.ts +29 -0
- package/dist/cli/commands/scan.d.ts.map +1 -0
- package/dist/cli/commands/scan.js +251 -0
- package/dist/cli/commands/scan.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +26 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +424 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/start.d.ts +20 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +82 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/stats.d.ts +10 -0
- package/dist/cli/commands/stats.d.ts.map +1 -0
- package/dist/cli/commands/stats.js +42 -0
- package/dist/cli/commands/stats.js.map +1 -0
- package/dist/cli/commands/templates.d.ts +26 -0
- package/dist/cli/commands/templates.d.ts.map +1 -0
- package/dist/cli/commands/templates.js +221 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +12 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +107 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/commands/wrap.d.ts +19 -0
- package/dist/cli/commands/wrap.d.ts.map +1 -0
- package/dist/cli/commands/wrap.js +59 -0
- package/dist/cli/commands/wrap.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +202 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/ui.d.ts +139 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/ui.js +271 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +54 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrator/index.d.ts +11 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +10 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/manager.d.ts +127 -0
- package/dist/orchestrator/manager.d.ts.map +1 -0
- package/dist/orchestrator/manager.js +498 -0
- package/dist/orchestrator/manager.js.map +1 -0
- package/dist/orchestrator/types.d.ts +141 -0
- package/dist/orchestrator/types.d.ts.map +1 -0
- package/dist/orchestrator/types.js +9 -0
- package/dist/orchestrator/types.js.map +1 -0
- package/dist/policy/engine.d.ts +55 -0
- package/dist/policy/engine.d.ts.map +1 -0
- package/dist/policy/engine.js +288 -0
- package/dist/policy/engine.js.map +1 -0
- package/dist/policy/natural-language.d.ts +141 -0
- package/dist/policy/natural-language.d.ts.map +1 -0
- package/dist/policy/natural-language.js +552 -0
- package/dist/policy/natural-language.js.map +1 -0
- package/dist/policy/parser.d.ts +141 -0
- package/dist/policy/parser.d.ts.map +1 -0
- package/dist/policy/parser.js +314 -0
- package/dist/policy/parser.js.map +1 -0
- package/dist/policy/types.d.ts +428 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +32 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/policy/validator.d.ts +72 -0
- package/dist/policy/validator.d.ts.map +1 -0
- package/dist/policy/validator.js +453 -0
- package/dist/policy/validator.js.map +1 -0
- package/dist/proxy/bridge.d.ts +84 -0
- package/dist/proxy/bridge.d.ts.map +1 -0
- package/dist/proxy/bridge.js +217 -0
- package/dist/proxy/bridge.js.map +1 -0
- package/dist/proxy/client.d.ts +130 -0
- package/dist/proxy/client.d.ts.map +1 -0
- package/dist/proxy/client.js +290 -0
- package/dist/proxy/client.js.map +1 -0
- package/dist/proxy/server.d.ts +111 -0
- package/dist/proxy/server.d.ts.map +1 -0
- package/dist/proxy/server.js +444 -0
- package/dist/proxy/server.js.map +1 -0
- package/dist/scanner.d.ts +91 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +373 -0
- package/dist/scanner.js.map +1 -0
- package/dist/session/index.d.ts +32 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +31 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +166 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +454 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/session/sqlite-store.d.ts +54 -0
- package/dist/session/sqlite-store.d.ts.map +1 -0
- package/dist/session/sqlite-store.js +209 -0
- package/dist/session/sqlite-store.js.map +1 -0
- package/dist/session/types.d.ts +179 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +38 -0
- package/dist/session/types.js.map +1 -0
- package/dist/templates.d.ts +64 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +451 -0
- package/dist/templates.js.map +1 -0
- package/dist/utils/config.d.ts +57 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +104 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +35 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/logger.d.ts +144 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +300 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/wizard.d.ts +68 -0
- package/dist/wizard.d.ts.map +1 -0
- package/dist/wizard.js +395 -0
- package/dist/wizard.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PII Redaction Module for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Detects and masks sensitive information in audit logs to comply with
|
|
5
|
+
* data protection regulations (GDPR, CCPA, SOC2).
|
|
6
|
+
*
|
|
7
|
+
* Supported patterns:
|
|
8
|
+
* - Passwords and secrets
|
|
9
|
+
* - API keys and tokens
|
|
10
|
+
* - Credit card numbers
|
|
11
|
+
* - Social Security Numbers (SSN)
|
|
12
|
+
* - Email addresses
|
|
13
|
+
* - Phone numbers
|
|
14
|
+
* - IP addresses (optional)
|
|
15
|
+
* - Private keys and certificates
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { redactPii, createRedactor } from './redaction.js';
|
|
20
|
+
*
|
|
21
|
+
* // Quick redaction with defaults
|
|
22
|
+
* const redacted = redactPii('password=secret123');
|
|
23
|
+
* // Returns: 'password=[REDACTED]'
|
|
24
|
+
*
|
|
25
|
+
* // Custom redactor with options
|
|
26
|
+
* const redactor = createRedactor({ redactEmails: true, redactIPs: true });
|
|
27
|
+
* const result = redactor.redact({ email: 'user@example.com' });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Default redaction options.
|
|
32
|
+
*/
|
|
33
|
+
const DEFAULT_OPTIONS = {
|
|
34
|
+
redactEmails: true,
|
|
35
|
+
redactIPs: false,
|
|
36
|
+
redactPhones: true,
|
|
37
|
+
customPatterns: [],
|
|
38
|
+
replacement: '[REDACTED]',
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Core patterns that are always applied.
|
|
42
|
+
* Each pattern uses a simple replacement approach for reliability.
|
|
43
|
+
*/
|
|
44
|
+
const CORE_PATTERNS = [
|
|
45
|
+
// Passwords in various formats (key=value or key: value)
|
|
46
|
+
{
|
|
47
|
+
name: 'password_field',
|
|
48
|
+
pattern: /(["']?password["']?\s*[:=]\s*["']?)([^"'\s,}]+)/gi,
|
|
49
|
+
description: 'Password field values',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'passwd_field',
|
|
53
|
+
pattern: /(["']?passwd["']?\s*[:=]\s*["']?)([^"'\s,}]+)/gi,
|
|
54
|
+
description: 'Passwd field values',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'secret_field',
|
|
58
|
+
pattern: /(["']?secret["']?\s*[:=]\s*["']?)([^"'\s,}]+)/gi,
|
|
59
|
+
description: 'Secret field values',
|
|
60
|
+
},
|
|
61
|
+
// API keys and tokens (key=value or key: value)
|
|
62
|
+
{
|
|
63
|
+
name: 'api_key',
|
|
64
|
+
pattern: /(["']?api[_-]?key["']?\s*[:=]\s*["']?)([A-Za-z0-9_-]{4,})/gi,
|
|
65
|
+
description: 'API keys',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'access_token',
|
|
69
|
+
pattern: /(["']?access[_-]?token["']?\s*[:=]\s*["']?)([A-Za-z0-9_.-]{8,})/gi,
|
|
70
|
+
description: 'Access tokens',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'auth_token',
|
|
74
|
+
pattern: /(["']?auth[_-]?token["']?\s*[:=]\s*["']?)([A-Za-z0-9_.-]{8,})/gi,
|
|
75
|
+
description: 'Auth tokens',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'token_field',
|
|
79
|
+
pattern: /(["']?token["']?\s*[:=]\s*["']?)([A-Za-z0-9_.-]{4,})/gi,
|
|
80
|
+
description: 'Generic token fields',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'bearer_token',
|
|
84
|
+
pattern: /(bearer\s+)([A-Za-z0-9_.-]+)/gi,
|
|
85
|
+
description: 'Bearer tokens',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'jwt_token',
|
|
89
|
+
pattern: /eyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g,
|
|
90
|
+
description: 'JWT tokens',
|
|
91
|
+
},
|
|
92
|
+
// AWS credentials
|
|
93
|
+
{
|
|
94
|
+
name: 'aws_access_key',
|
|
95
|
+
pattern: /AKIA[0-9A-Z]{16}/g,
|
|
96
|
+
description: 'AWS access key IDs',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'aws_secret_key',
|
|
100
|
+
pattern: /(["']?aws[_-]?secret[_-]?(?:access[_-]?)?key["']?\s*[:=]\s*["']?)([A-Za-z0-9/+=]{40})/gi,
|
|
101
|
+
description: 'AWS secret keys',
|
|
102
|
+
},
|
|
103
|
+
// GitHub tokens (ghp_ for PAT, gho_ for OAuth)
|
|
104
|
+
{
|
|
105
|
+
name: 'github_token',
|
|
106
|
+
pattern: /ghp_[A-Za-z0-9]{20,}/g,
|
|
107
|
+
description: 'GitHub personal access tokens',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'github_oauth',
|
|
111
|
+
pattern: /gho_[A-Za-z0-9]{20,}/g,
|
|
112
|
+
description: 'GitHub OAuth tokens',
|
|
113
|
+
},
|
|
114
|
+
// Private keys and certificates
|
|
115
|
+
{
|
|
116
|
+
name: 'private_key',
|
|
117
|
+
pattern: /-----BEGIN\s+(?:RSA\s+)?PRIVATE\s+KEY-----[\s\S]*?-----END\s+(?:RSA\s+)?PRIVATE\s+KEY-----/g,
|
|
118
|
+
description: 'Private keys',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'certificate',
|
|
122
|
+
pattern: /-----BEGIN\s+CERTIFICATE-----[\s\S]*?-----END\s+CERTIFICATE-----/g,
|
|
123
|
+
description: 'Certificates',
|
|
124
|
+
},
|
|
125
|
+
// Credit card numbers (basic patterns)
|
|
126
|
+
{
|
|
127
|
+
name: 'credit_card',
|
|
128
|
+
pattern: /\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\b/g,
|
|
129
|
+
description: 'Credit card numbers',
|
|
130
|
+
},
|
|
131
|
+
// Social Security Numbers
|
|
132
|
+
{
|
|
133
|
+
name: 'ssn',
|
|
134
|
+
pattern: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/g,
|
|
135
|
+
description: 'Social Security Numbers',
|
|
136
|
+
},
|
|
137
|
+
// Database connection strings with passwords (preserve structure)
|
|
138
|
+
{
|
|
139
|
+
name: 'connection_string',
|
|
140
|
+
pattern: /(:\/\/[^:]+:)([^@]+)(@)/g,
|
|
141
|
+
description: 'Database connection string credentials',
|
|
142
|
+
},
|
|
143
|
+
];
|
|
144
|
+
/**
|
|
145
|
+
* Optional patterns that can be enabled via configuration.
|
|
146
|
+
*/
|
|
147
|
+
const OPTIONAL_PATTERNS = {
|
|
148
|
+
email: {
|
|
149
|
+
name: 'email',
|
|
150
|
+
pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
|
|
151
|
+
description: 'Email addresses',
|
|
152
|
+
},
|
|
153
|
+
ipv4: {
|
|
154
|
+
name: 'ipv4',
|
|
155
|
+
pattern: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g,
|
|
156
|
+
description: 'IPv4 addresses',
|
|
157
|
+
},
|
|
158
|
+
ipv6: {
|
|
159
|
+
name: 'ipv6',
|
|
160
|
+
pattern: /\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g,
|
|
161
|
+
description: 'IPv6 addresses',
|
|
162
|
+
},
|
|
163
|
+
phone: {
|
|
164
|
+
name: 'phone',
|
|
165
|
+
pattern: /\b(?:\+?1[-.\s]?)?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}\b/g,
|
|
166
|
+
description: 'Phone numbers',
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* PII Redactor class for detecting and masking sensitive data.
|
|
171
|
+
*/
|
|
172
|
+
export class PiiRedactor {
|
|
173
|
+
options;
|
|
174
|
+
patterns;
|
|
175
|
+
constructor(options = {}) {
|
|
176
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
177
|
+
this.patterns = this.buildPatternList();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Builds the list of patterns to apply based on options.
|
|
181
|
+
*/
|
|
182
|
+
buildPatternList() {
|
|
183
|
+
const patterns = [...CORE_PATTERNS];
|
|
184
|
+
if (this.options.redactEmails) {
|
|
185
|
+
patterns.push(OPTIONAL_PATTERNS.email);
|
|
186
|
+
}
|
|
187
|
+
if (this.options.redactIPs) {
|
|
188
|
+
patterns.push(OPTIONAL_PATTERNS.ipv4);
|
|
189
|
+
patterns.push(OPTIONAL_PATTERNS.ipv6);
|
|
190
|
+
}
|
|
191
|
+
if (this.options.redactPhones) {
|
|
192
|
+
patterns.push(OPTIONAL_PATTERNS.phone);
|
|
193
|
+
}
|
|
194
|
+
// Add custom patterns
|
|
195
|
+
for (const pattern of this.options.customPatterns) {
|
|
196
|
+
patterns.push({
|
|
197
|
+
name: 'custom',
|
|
198
|
+
pattern,
|
|
199
|
+
description: 'Custom pattern',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return patterns;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Redacts sensitive data from a string.
|
|
206
|
+
*
|
|
207
|
+
* @param input - The string to redact
|
|
208
|
+
* @returns The redacted string
|
|
209
|
+
*/
|
|
210
|
+
redactString(input) {
|
|
211
|
+
let result = input;
|
|
212
|
+
const replacement = this.options.replacement;
|
|
213
|
+
for (const { pattern, name } of this.patterns) {
|
|
214
|
+
// Reset regex state for global patterns
|
|
215
|
+
pattern.lastIndex = 0;
|
|
216
|
+
// Handle different pattern types based on their structure
|
|
217
|
+
if (name === 'connection_string') {
|
|
218
|
+
// Connection strings: preserve ://user: and @ parts
|
|
219
|
+
result = result.replace(pattern, `$1${replacement}$3`);
|
|
220
|
+
}
|
|
221
|
+
else if (name === 'jwt_token' || name === 'aws_access_key' ||
|
|
222
|
+
name === 'github_token' || name === 'github_oauth' ||
|
|
223
|
+
name === 'credit_card' || name === 'ssn' ||
|
|
224
|
+
name === 'private_key' || name === 'certificate') {
|
|
225
|
+
// Direct replacement patterns (no capture groups to preserve)
|
|
226
|
+
result = result.replace(pattern, replacement);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
// Field patterns: preserve the field name (first capture group)
|
|
230
|
+
result = result.replace(pattern, `$1${replacement}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Redacts sensitive data from an object by converting to JSON and back.
|
|
237
|
+
*
|
|
238
|
+
* @param input - The object to redact
|
|
239
|
+
* @returns The redacted object as a JSON string
|
|
240
|
+
*/
|
|
241
|
+
redactObject(input) {
|
|
242
|
+
const jsonString = JSON.stringify(input, null, 2);
|
|
243
|
+
return this.redactString(jsonString);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Checks if a string contains potentially sensitive data.
|
|
247
|
+
*
|
|
248
|
+
* @param input - The string to check
|
|
249
|
+
* @returns True if sensitive data was detected
|
|
250
|
+
*/
|
|
251
|
+
containsSensitiveData(input) {
|
|
252
|
+
for (const { pattern } of this.patterns) {
|
|
253
|
+
pattern.lastIndex = 0;
|
|
254
|
+
if (pattern.test(input)) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Returns the list of pattern names being applied.
|
|
262
|
+
*/
|
|
263
|
+
getActivePatterns() {
|
|
264
|
+
return this.patterns.map((p) => p.name);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Creates a new PII redactor with the specified options.
|
|
269
|
+
*
|
|
270
|
+
* @param options - Redaction options
|
|
271
|
+
* @returns A configured PiiRedactor instance
|
|
272
|
+
*/
|
|
273
|
+
export function createRedactor(options = {}) {
|
|
274
|
+
return new PiiRedactor(options);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Default redactor instance for quick usage.
|
|
278
|
+
*/
|
|
279
|
+
const defaultRedactor = new PiiRedactor();
|
|
280
|
+
/**
|
|
281
|
+
* Redacts PII from a string using default settings.
|
|
282
|
+
*
|
|
283
|
+
* @param input - The string to redact
|
|
284
|
+
* @returns The redacted string
|
|
285
|
+
*/
|
|
286
|
+
export function redactPii(input) {
|
|
287
|
+
return defaultRedactor.redactString(input);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Redacts PII from an object and returns a JSON string.
|
|
291
|
+
*
|
|
292
|
+
* @param input - The object to redact
|
|
293
|
+
* @returns The redacted JSON string
|
|
294
|
+
*/
|
|
295
|
+
export function redactPiiFromObject(input) {
|
|
296
|
+
return defaultRedactor.redactObject(input);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Checks if a string contains potentially sensitive data.
|
|
300
|
+
*
|
|
301
|
+
* @param input - The string to check
|
|
302
|
+
* @returns True if sensitive data was detected
|
|
303
|
+
*/
|
|
304
|
+
export function containsPii(input) {
|
|
305
|
+
return defaultRedactor.containsSensitiveData(input);
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=redaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redaction.js","sourceRoot":"","sources":["../../src/audit/redaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAkBH;;GAEG;AACH,MAAM,eAAe,GAA+B;IAClD,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,YAAY;CAC1B,CAAC;AAYF;;;GAGG;AACH,MAAM,aAAa,GAAuB;IACxC,yDAAyD;IACzD;QACE,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,mDAAmD;QAC5D,WAAW,EAAE,uBAAuB;KACrC;IACD;QACE,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,iDAAiD;QAC1D,WAAW,EAAE,qBAAqB;KACnC;IACD;QACE,IAAI,EAAE,cAAc;QACpB,OAAO,EAA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,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,eAAe,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit database schema for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Two main tables:
|
|
5
|
+
* - tool_calls: Records every tool invocation with policy and approval decisions
|
|
6
|
+
* - session_grants: Records session-based approval grants
|
|
7
|
+
*
|
|
8
|
+
* Schema version 2 adds:
|
|
9
|
+
* - Enhanced compliance fields (risk_level, analyzer, policy_reason)
|
|
10
|
+
* - PII redaction support (args_redacted)
|
|
11
|
+
* - Correlation and context tracking (correlation_id, client_id)
|
|
12
|
+
*/
|
|
13
|
+
/** Current schema version for migrations */
|
|
14
|
+
export declare const SCHEMA_VERSION = 2;
|
|
15
|
+
export declare const AUDIT_SCHEMA = "\n-- Schema version tracking\nCREATE TABLE IF NOT EXISTS schema_version (\n version INTEGER PRIMARY KEY,\n applied_at DATETIME DEFAULT CURRENT_TIMESTAMP\n);\n\n-- Tool calls table: records every tool invocation\nCREATE TABLE IF NOT EXISTS tool_calls (\n id TEXT PRIMARY KEY,\n timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,\n server TEXT NOT NULL,\n tool TEXT NOT NULL,\n args TEXT,\n -- PII-redacted version of args for compliance\n args_redacted TEXT,\n policy_decision TEXT NOT NULL,\n policy_rule TEXT,\n -- Reason for the policy decision (for deny/prompt)\n policy_reason TEXT,\n -- Smart analysis metadata\n analyzer TEXT,\n risk_level TEXT,\n user_decision TEXT,\n result TEXT,\n error_message TEXT,\n duration_ms INTEGER,\n -- Session grant that authorized this call (if any)\n session_grant_id TEXT,\n -- Correlation ID for linking related events\n correlation_id TEXT,\n -- Client identifier (for multi-client scenarios)\n client_id TEXT,\n FOREIGN KEY (session_grant_id) REFERENCES session_grants(id)\n);\n\nCREATE INDEX IF NOT EXISTS idx_tool_calls_timestamp ON tool_calls(timestamp);\nCREATE INDEX IF NOT EXISTS idx_tool_calls_server_tool ON tool_calls(server, tool);\nCREATE INDEX IF NOT EXISTS idx_tool_calls_policy_decision ON tool_calls(policy_decision);\nCREATE INDEX IF NOT EXISTS idx_tool_calls_session_grant ON tool_calls(session_grant_id);\nCREATE INDEX IF NOT EXISTS idx_tool_calls_risk_level ON tool_calls(risk_level);\nCREATE INDEX IF NOT EXISTS idx_tool_calls_correlation ON tool_calls(correlation_id);\n\n-- Session grants table: records time-bounded approval grants\nCREATE TABLE IF NOT EXISTS session_grants (\n id TEXT PRIMARY KEY,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n expires_at DATETIME,\n server TEXT NOT NULL,\n scope TEXT NOT NULL,\n scope_value TEXT,\n tool TEXT,\n granted_by TEXT NOT NULL,\n original_request_id TEXT,\n usage_count INTEGER DEFAULT 0,\n revoked_at DATETIME,\n revoked_by TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_session_grants_server ON session_grants(server);\nCREATE INDEX IF NOT EXISTS idx_session_grants_expires ON session_grants(expires_at);\nCREATE INDEX IF NOT EXISTS idx_session_grants_active ON session_grants(server, expires_at) WHERE revoked_at IS NULL;\n";
|
|
16
|
+
/**
|
|
17
|
+
* Migration from version 1 to version 2.
|
|
18
|
+
* Adds compliance fields for enhanced audit logging.
|
|
19
|
+
*/
|
|
20
|
+
export declare const MIGRATION_V2 = "\n-- Add new columns for compliance (SQLite requires separate ALTER statements)\nALTER TABLE tool_calls ADD COLUMN args_redacted TEXT;\nALTER TABLE tool_calls ADD COLUMN policy_reason TEXT;\nALTER TABLE tool_calls ADD COLUMN analyzer TEXT;\nALTER TABLE tool_calls ADD COLUMN risk_level TEXT;\nALTER TABLE tool_calls ADD COLUMN correlation_id TEXT;\nALTER TABLE tool_calls ADD COLUMN client_id TEXT;\n\n-- Add new indexes\nCREATE INDEX IF NOT EXISTS idx_tool_calls_risk_level ON tool_calls(risk_level);\nCREATE INDEX IF NOT EXISTS idx_tool_calls_correlation ON tool_calls(correlation_id);\n";
|
|
21
|
+
/**
|
|
22
|
+
* Migration to add session support to existing databases.
|
|
23
|
+
* Run this on upgrade from pre-session versions.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SESSION_MIGRATION = "\n-- Add session_grant_id column if it doesn't exist\nALTER TABLE tool_calls ADD COLUMN session_grant_id TEXT REFERENCES session_grants(id);\n\n-- Create session_grants table if it doesn't exist\nCREATE TABLE IF NOT EXISTS session_grants (\n id TEXT PRIMARY KEY,\n created_at DATETIME DEFAULT CURRENT_TIMESTAMP,\n expires_at DATETIME,\n server TEXT NOT NULL,\n scope TEXT NOT NULL,\n scope_value TEXT,\n tool TEXT,\n granted_by TEXT NOT NULL,\n original_request_id TEXT,\n usage_count INTEGER DEFAULT 0,\n revoked_at DATETIME,\n revoked_by TEXT\n);\n\nCREATE INDEX IF NOT EXISTS idx_session_grants_server ON session_grants(server);\nCREATE INDEX IF NOT EXISTS idx_session_grants_expires ON session_grants(expires_at);\n";
|
|
26
|
+
/** Risk level classification for audit records */
|
|
27
|
+
export type RiskLevel = 'safe' | 'read' | 'write' | 'destructive' | 'dangerous';
|
|
28
|
+
/**
|
|
29
|
+
* Record of a tool call in the audit log.
|
|
30
|
+
*/
|
|
31
|
+
export interface AuditRecord {
|
|
32
|
+
id: string;
|
|
33
|
+
timestamp: Date;
|
|
34
|
+
server: string;
|
|
35
|
+
tool: string;
|
|
36
|
+
/** Original arguments (may contain sensitive data) */
|
|
37
|
+
args: Record<string, unknown>;
|
|
38
|
+
/** PII-redacted version of args for compliance reporting */
|
|
39
|
+
argsRedacted?: string;
|
|
40
|
+
policyDecision: 'allow' | 'deny' | 'prompt';
|
|
41
|
+
policyRule?: string;
|
|
42
|
+
/** Reason for the policy decision */
|
|
43
|
+
policyReason?: string;
|
|
44
|
+
/** Analyzer used for smart decisions */
|
|
45
|
+
analyzer?: string;
|
|
46
|
+
/** Risk level from smart analysis */
|
|
47
|
+
riskLevel?: RiskLevel;
|
|
48
|
+
userDecision?: 'approved' | 'denied' | 'timeout' | null;
|
|
49
|
+
result?: 'success' | 'error';
|
|
50
|
+
errorMessage?: string;
|
|
51
|
+
durationMs?: number;
|
|
52
|
+
/** ID of the session grant that authorized this call */
|
|
53
|
+
sessionGrantId?: string;
|
|
54
|
+
/** Correlation ID for linking related events */
|
|
55
|
+
correlationId?: string;
|
|
56
|
+
/** Client identifier */
|
|
57
|
+
clientId?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Record of a session grant in the audit log.
|
|
61
|
+
*/
|
|
62
|
+
export interface SessionGrantRecord {
|
|
63
|
+
id: string;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
expiresAt: Date | null;
|
|
66
|
+
server: string;
|
|
67
|
+
scope: 'exact' | 'tool' | 'server' | 'pattern';
|
|
68
|
+
scopeValue?: string;
|
|
69
|
+
tool?: string;
|
|
70
|
+
grantedBy: 'terminal' | 'webhook' | 'api';
|
|
71
|
+
originalRequestId?: string;
|
|
72
|
+
usageCount: number;
|
|
73
|
+
revokedAt?: Date;
|
|
74
|
+
revokedBy?: string;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/audit/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,4CAA4C;AAC5C,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,eAAO,MAAM,YAAY,uuEA8DxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,klBAYxB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,guBAsB7B,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,WAAW,CAAC;AAEhF;;G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;IAC1C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit database schema for Tollgate
|
|
3
|
+
*
|
|
4
|
+
* Two main tables:
|
|
5
|
+
* - tool_calls: Records every tool invocation with policy and approval decisions
|
|
6
|
+
* - session_grants: Records session-based approval grants
|
|
7
|
+
*
|
|
8
|
+
* Schema version 2 adds:
|
|
9
|
+
* - Enhanced compliance fields (risk_level, analyzer, policy_reason)
|
|
10
|
+
* - PII redaction support (args_redacted)
|
|
11
|
+
* - Correlation and context tracking (correlation_id, client_id)
|
|
12
|
+
*/
|
|
13
|
+
/** Current schema version for migrations */
|
|
14
|
+
export const SCHEMA_VERSION = 2;
|
|
15
|
+
export const AUDIT_SCHEMA = `
|
|
16
|
+
-- Schema version tracking
|
|
17
|
+
CREATE TABLE IF NOT EXISTS schema_version (
|
|
18
|
+
version INTEGER PRIMARY KEY,
|
|
19
|
+
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
-- Tool calls table: records every tool invocation
|
|
23
|
+
CREATE TABLE IF NOT EXISTS tool_calls (
|
|
24
|
+
id TEXT PRIMARY KEY,
|
|
25
|
+
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
26
|
+
server TEXT NOT NULL,
|
|
27
|
+
tool TEXT NOT NULL,
|
|
28
|
+
args TEXT,
|
|
29
|
+
-- PII-redacted version of args for compliance
|
|
30
|
+
args_redacted TEXT,
|
|
31
|
+
policy_decision TEXT NOT NULL,
|
|
32
|
+
policy_rule TEXT,
|
|
33
|
+
-- Reason for the policy decision (for deny/prompt)
|
|
34
|
+
policy_reason TEXT,
|
|
35
|
+
-- Smart analysis metadata
|
|
36
|
+
analyzer TEXT,
|
|
37
|
+
risk_level TEXT,
|
|
38
|
+
user_decision TEXT,
|
|
39
|
+
result TEXT,
|
|
40
|
+
error_message TEXT,
|
|
41
|
+
duration_ms INTEGER,
|
|
42
|
+
-- Session grant that authorized this call (if any)
|
|
43
|
+
session_grant_id TEXT,
|
|
44
|
+
-- Correlation ID for linking related events
|
|
45
|
+
correlation_id TEXT,
|
|
46
|
+
-- Client identifier (for multi-client scenarios)
|
|
47
|
+
client_id TEXT,
|
|
48
|
+
FOREIGN KEY (session_grant_id) REFERENCES session_grants(id)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_timestamp ON tool_calls(timestamp);
|
|
52
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_server_tool ON tool_calls(server, tool);
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_policy_decision ON tool_calls(policy_decision);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_session_grant ON tool_calls(session_grant_id);
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_risk_level ON tool_calls(risk_level);
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_correlation ON tool_calls(correlation_id);
|
|
57
|
+
|
|
58
|
+
-- Session grants table: records time-bounded approval grants
|
|
59
|
+
CREATE TABLE IF NOT EXISTS session_grants (
|
|
60
|
+
id TEXT PRIMARY KEY,
|
|
61
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
62
|
+
expires_at DATETIME,
|
|
63
|
+
server TEXT NOT NULL,
|
|
64
|
+
scope TEXT NOT NULL,
|
|
65
|
+
scope_value TEXT,
|
|
66
|
+
tool TEXT,
|
|
67
|
+
granted_by TEXT NOT NULL,
|
|
68
|
+
original_request_id TEXT,
|
|
69
|
+
usage_count INTEGER DEFAULT 0,
|
|
70
|
+
revoked_at DATETIME,
|
|
71
|
+
revoked_by TEXT
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_server ON session_grants(server);
|
|
75
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_expires ON session_grants(expires_at);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_active ON session_grants(server, expires_at) WHERE revoked_at IS NULL;
|
|
77
|
+
`;
|
|
78
|
+
/**
|
|
79
|
+
* Migration from version 1 to version 2.
|
|
80
|
+
* Adds compliance fields for enhanced audit logging.
|
|
81
|
+
*/
|
|
82
|
+
export const MIGRATION_V2 = `
|
|
83
|
+
-- Add new columns for compliance (SQLite requires separate ALTER statements)
|
|
84
|
+
ALTER TABLE tool_calls ADD COLUMN args_redacted TEXT;
|
|
85
|
+
ALTER TABLE tool_calls ADD COLUMN policy_reason TEXT;
|
|
86
|
+
ALTER TABLE tool_calls ADD COLUMN analyzer TEXT;
|
|
87
|
+
ALTER TABLE tool_calls ADD COLUMN risk_level TEXT;
|
|
88
|
+
ALTER TABLE tool_calls ADD COLUMN correlation_id TEXT;
|
|
89
|
+
ALTER TABLE tool_calls ADD COLUMN client_id TEXT;
|
|
90
|
+
|
|
91
|
+
-- Add new indexes
|
|
92
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_risk_level ON tool_calls(risk_level);
|
|
93
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_correlation ON tool_calls(correlation_id);
|
|
94
|
+
`;
|
|
95
|
+
/**
|
|
96
|
+
* Migration to add session support to existing databases.
|
|
97
|
+
* Run this on upgrade from pre-session versions.
|
|
98
|
+
*/
|
|
99
|
+
export const SESSION_MIGRATION = `
|
|
100
|
+
-- Add session_grant_id column if it doesn't exist
|
|
101
|
+
ALTER TABLE tool_calls ADD COLUMN session_grant_id TEXT REFERENCES session_grants(id);
|
|
102
|
+
|
|
103
|
+
-- Create session_grants table if it doesn't exist
|
|
104
|
+
CREATE TABLE IF NOT EXISTS session_grants (
|
|
105
|
+
id TEXT PRIMARY KEY,
|
|
106
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
107
|
+
expires_at DATETIME,
|
|
108
|
+
server TEXT NOT NULL,
|
|
109
|
+
scope TEXT NOT NULL,
|
|
110
|
+
scope_value TEXT,
|
|
111
|
+
tool TEXT,
|
|
112
|
+
granted_by TEXT NOT NULL,
|
|
113
|
+
original_request_id TEXT,
|
|
114
|
+
usage_count INTEGER DEFAULT 0,
|
|
115
|
+
revoked_at DATETIME,
|
|
116
|
+
revoked_by TEXT
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_server ON session_grants(server);
|
|
120
|
+
CREATE INDEX IF NOT EXISTS idx_session_grants_expires ON session_grants(expires_at);
|
|
121
|
+
`;
|
|
122
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/audit/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,4CAA4C;AAC5C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8D3B,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;;;;;;;;;;;;CAY3B,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBhC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tollgate Doctor Command
|
|
3
|
+
*
|
|
4
|
+
* Diagnostic command to verify configuration and environment before running.
|
|
5
|
+
* Checks configuration validity, environment variables, and system resources.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* tollgate doctor - Run all diagnostics
|
|
9
|
+
* tollgate doctor --config path - Check specific config file
|
|
10
|
+
* tollgate doctor --server name - Check specific server only
|
|
11
|
+
*/
|
|
12
|
+
export interface DoctorOptions {
|
|
13
|
+
config?: string;
|
|
14
|
+
server?: string;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
fix?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface DiagnosticResult {
|
|
19
|
+
name: string;
|
|
20
|
+
status: 'pass' | 'warn' | 'fail';
|
|
21
|
+
message: string;
|
|
22
|
+
details?: string;
|
|
23
|
+
fixable?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface DoctorReport {
|
|
26
|
+
timestamp: string;
|
|
27
|
+
configPath: string;
|
|
28
|
+
passed: number;
|
|
29
|
+
warnings: number;
|
|
30
|
+
failed: number;
|
|
31
|
+
results: DiagnosticResult[];
|
|
32
|
+
}
|
|
33
|
+
export declare function runDoctor(options: DoctorOptions): Promise<void>;
|
|
34
|
+
//# sourceMappingURL=doctor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/doctor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAiBH,MAAM,WAAW,aAAa;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC/B;AAwVD,wBAAsB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAwDrE"}
|