@bernierllc/backoff-retry 0.1.1 → 0.3.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 +13 -0
- package/README.md +110 -0
- package/dist/enhancement-manager.d.ts +205 -0
- package/dist/enhancement-manager.d.ts.map +1 -0
- package/dist/enhancement-manager.js +533 -0
- package/dist/enhancement-manager.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-protection.js +1 -1
- package/dist/memory-protection.js.map +1 -1
- package/dist/neveradmin/components/RetryAnalyticsPage.d.ts +15 -0
- package/dist/neveradmin/components/RetryAnalyticsPage.d.ts.map +1 -0
- package/dist/neveradmin/components/RetryAnalyticsPage.js +28 -0
- package/dist/neveradmin/components/RetryAnalyticsPage.js.map +1 -0
- package/dist/neveradmin/components/RetryConfigurationPage.d.ts +15 -0
- package/dist/neveradmin/components/RetryConfigurationPage.d.ts.map +1 -0
- package/dist/neveradmin/components/RetryConfigurationPage.js +28 -0
- package/dist/neveradmin/components/RetryConfigurationPage.js.map +1 -0
- package/dist/neveradmin/components/RetryEnhancementsPage.d.ts +15 -0
- package/dist/neveradmin/components/RetryEnhancementsPage.d.ts.map +1 -0
- package/dist/neveradmin/components/RetryEnhancementsPage.js +28 -0
- package/dist/neveradmin/components/RetryEnhancementsPage.js.map +1 -0
- package/dist/neveradmin/components/RetryOperationsPage.d.ts +15 -0
- package/dist/neveradmin/components/RetryOperationsPage.d.ts.map +1 -0
- package/dist/neveradmin/components/RetryOperationsPage.js +28 -0
- package/dist/neveradmin/components/RetryOperationsPage.js.map +1 -0
- package/dist/neveradmin/components/RetryOverviewPage.d.ts +15 -0
- package/dist/neveradmin/components/RetryOverviewPage.d.ts.map +1 -0
- package/dist/neveradmin/components/RetryOverviewPage.js +28 -0
- package/dist/neveradmin/components/RetryOverviewPage.js.map +1 -0
- package/dist/neveradmin/components/index.d.ts +7 -0
- package/dist/neveradmin/components/index.d.ts.map +1 -0
- package/dist/neveradmin/components/index.js +32 -0
- package/dist/neveradmin/components/index.js.map +1 -0
- package/dist/neveradmin/components/types.d.ts +64 -0
- package/dist/neveradmin/components/types.d.ts.map +1 -0
- package/dist/neveradmin/components/types.js +10 -0
- package/dist/neveradmin/components/types.js.map +1 -0
- package/dist/neveradmin/hooks/index.d.ts +5 -0
- package/dist/neveradmin/hooks/index.d.ts.map +1 -0
- package/dist/neveradmin/hooks/index.js +28 -0
- package/dist/neveradmin/hooks/index.js.map +1 -0
- package/dist/neveradmin/hooks/useRetryConfiguration.d.ts +23 -0
- package/dist/neveradmin/hooks/useRetryConfiguration.d.ts.map +1 -0
- package/dist/neveradmin/hooks/useRetryConfiguration.js +162 -0
- package/dist/neveradmin/hooks/useRetryConfiguration.js.map +1 -0
- package/dist/neveradmin/hooks/useRetryEnhancements.d.ts +39 -0
- package/dist/neveradmin/hooks/useRetryEnhancements.d.ts.map +1 -0
- package/dist/neveradmin/hooks/useRetryEnhancements.js +197 -0
- package/dist/neveradmin/hooks/useRetryEnhancements.js.map +1 -0
- package/dist/neveradmin/hooks/useRetryOperations.d.ts +28 -0
- package/dist/neveradmin/hooks/useRetryOperations.d.ts.map +1 -0
- package/dist/neveradmin/hooks/useRetryOperations.js +166 -0
- package/dist/neveradmin/hooks/useRetryOperations.js.map +1 -0
- package/dist/neveradmin/hooks/useRetryStats.d.ts +19 -0
- package/dist/neveradmin/hooks/useRetryStats.d.ts.map +1 -0
- package/dist/neveradmin/hooks/useRetryStats.js +81 -0
- package/dist/neveradmin/hooks/useRetryStats.js.map +1 -0
- package/dist/neveradmin/index.d.ts +6 -0
- package/dist/neveradmin/index.d.ts.map +1 -0
- package/dist/neveradmin/index.js +29 -0
- package/dist/neveradmin/index.js.map +1 -0
- package/dist/neveradmin/registration.d.ts +33 -0
- package/dist/neveradmin/registration.d.ts.map +1 -0
- package/dist/neveradmin/registration.js +96 -0
- package/dist/neveradmin/registration.js.map +1 -0
- package/dist/neveradmin/types.d.ts +88 -0
- package/dist/neveradmin/types.d.ts.map +1 -0
- package/dist/neveradmin/types.js +10 -0
- package/dist/neveradmin/types.js.map +1 -0
- package/dist/neveradmin/utils/formatting.d.ts +41 -0
- package/dist/neveradmin/utils/formatting.d.ts.map +1 -0
- package/dist/neveradmin/utils/formatting.js +142 -0
- package/dist/neveradmin/utils/formatting.js.map +1 -0
- package/dist/neveradmin/utils/index.d.ts +4 -0
- package/dist/neveradmin/utils/index.d.ts.map +1 -0
- package/dist/neveradmin/utils/index.js +27 -0
- package/dist/neveradmin/utils/index.js.map +1 -0
- package/dist/neveradmin/utils/permissions.d.ts +74 -0
- package/dist/neveradmin/utils/permissions.d.ts.map +1 -0
- package/dist/neveradmin/utils/permissions.js +152 -0
- package/dist/neveradmin/utils/permissions.js.map +1 -0
- package/dist/neveradmin/utils/validation.d.ts +38 -0
- package/dist/neveradmin/utils/validation.d.ts.map +1 -0
- package/dist/neveradmin/utils/validation.js +142 -0
- package/dist/neveradmin/utils/validation.js.map +1 -0
- package/dist/retry-manager.d.ts +32 -11
- package/dist/retry-manager.d.ts.map +1 -1
- package/dist/retry-manager.js +128 -82
- package/dist/retry-manager.js.map +1 -1
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +26 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/secure-storage.d.ts +61 -0
- package/dist/security/secure-storage.d.ts.map +1 -0
- package/dist/security/secure-storage.js +418 -0
- package/dist/security/secure-storage.js.map +1 -0
- package/dist/security/security-manager.d.ts +172 -0
- package/dist/security/security-manager.d.ts.map +1 -0
- package/dist/security/security-manager.js +417 -0
- package/dist/security/security-manager.js.map +1 -0
- package/dist/storage/backend-selector.d.ts +96 -0
- package/dist/storage/backend-selector.d.ts.map +1 -0
- package/dist/storage/backend-selector.js +466 -0
- package/dist/storage/backend-selector.js.map +1 -0
- package/dist/storage/index.d.ts +7 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +30 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/memory-storage.d.ts +55 -0
- package/dist/storage/memory-storage.d.ts.map +1 -0
- package/dist/storage/memory-storage.js +106 -0
- package/dist/storage/memory-storage.js.map +1 -0
- package/dist/storage/postgresql-storage.d.ts +77 -0
- package/dist/storage/postgresql-storage.d.ts.map +1 -0
- package/dist/storage/postgresql-storage.js +314 -0
- package/dist/storage/postgresql-storage.js.map +1 -0
- package/dist/storage/redis-cluster-storage.d.ts +88 -0
- package/dist/storage/redis-cluster-storage.d.ts.map +1 -0
- package/dist/storage/redis-cluster-storage.js +414 -0
- package/dist/storage/redis-cluster-storage.js.map +1 -0
- package/dist/storage/redis-storage.d.ts +67 -0
- package/dist/storage/redis-storage.d.ts.map +1 -0
- package/dist/storage/redis-storage.js +236 -0
- package/dist/storage/redis-storage.js.map +1 -0
- package/dist/storage/types.d.ts +55 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +10 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/types.d.ts +7 -32
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +15 -2
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
26
|
+
var ownKeys = function(o) {
|
|
27
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
28
|
+
var ar = [];
|
|
29
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
return ownKeys(o);
|
|
33
|
+
};
|
|
34
|
+
return function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
})();
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.SecurityManager = exports.DEFAULT_SECURITY_CONFIG = void 0;
|
|
44
|
+
const events_1 = require("events");
|
|
45
|
+
// Dynamic import for crypto-js to make it optional
|
|
46
|
+
let CryptoJS = null;
|
|
47
|
+
/**
|
|
48
|
+
* Default security configuration
|
|
49
|
+
*/
|
|
50
|
+
exports.DEFAULT_SECURITY_CONFIG = {
|
|
51
|
+
encryption: {
|
|
52
|
+
enabled: false,
|
|
53
|
+
algorithm: 'AES-256-CBC',
|
|
54
|
+
keyEnvVar: 'BACKOFF_RETRY_ENCRYPTION_KEY'
|
|
55
|
+
},
|
|
56
|
+
accessControl: {
|
|
57
|
+
enabled: false,
|
|
58
|
+
roles: ['admin', 'user', 'readonly'],
|
|
59
|
+
permissions: {
|
|
60
|
+
admin: ['read', 'write', 'delete', 'clear', 'configure'],
|
|
61
|
+
user: ['read', 'write'],
|
|
62
|
+
readonly: ['read']
|
|
63
|
+
},
|
|
64
|
+
defaultRole: 'user'
|
|
65
|
+
},
|
|
66
|
+
auditLogging: {
|
|
67
|
+
enabled: false,
|
|
68
|
+
level: 'basic',
|
|
69
|
+
includeSensitiveData: false,
|
|
70
|
+
maxLogSize: 1000
|
|
71
|
+
},
|
|
72
|
+
rateLimiting: {
|
|
73
|
+
enabled: false,
|
|
74
|
+
maxRequestsPerMinute: 100,
|
|
75
|
+
maxRequestsPerHour: 1000,
|
|
76
|
+
windowMs: 60000
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Security Manager for handling encryption, access control, and audit logging
|
|
81
|
+
*/
|
|
82
|
+
class SecurityManager extends events_1.EventEmitter {
|
|
83
|
+
constructor(config = {}) {
|
|
84
|
+
super();
|
|
85
|
+
this.auditLog = [];
|
|
86
|
+
this.rateLimitStore = new Map();
|
|
87
|
+
this.encryptionKey = null;
|
|
88
|
+
this.config = { ...exports.DEFAULT_SECURITY_CONFIG, ...config };
|
|
89
|
+
// For encryption, validate immediately if enabled to catch errors synchronously
|
|
90
|
+
if (this.config.encryption?.enabled) {
|
|
91
|
+
this.validateEncryptionConfig();
|
|
92
|
+
// Still initialize asynchronously for actual setup
|
|
93
|
+
this.initializeSecurity();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Validate encryption configuration synchronously
|
|
98
|
+
*/
|
|
99
|
+
validateEncryptionConfig() {
|
|
100
|
+
// Get encryption key
|
|
101
|
+
this.encryptionKey = this.config.encryption?.key ||
|
|
102
|
+
process.env[this.config.encryption?.keyEnvVar || 'BACKOFF_RETRY_ENCRYPTION_KEY'] ||
|
|
103
|
+
null;
|
|
104
|
+
if (!this.encryptionKey) {
|
|
105
|
+
throw new Error('Encryption key not provided. Set BACKOFF_RETRY_ENCRYPTION_KEY environment variable or provide key in config.');
|
|
106
|
+
}
|
|
107
|
+
// Validate key length (minimum 32 characters for AES-256)
|
|
108
|
+
if (this.encryptionKey.length < 32) {
|
|
109
|
+
throw new Error('Encryption key must be at least 32 characters long for AES-256.');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Initialize security features
|
|
114
|
+
*/
|
|
115
|
+
async initializeSecurity() {
|
|
116
|
+
if (this.config.encryption?.enabled) {
|
|
117
|
+
await this.initializeEncryption();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Initialize encryption
|
|
122
|
+
*/
|
|
123
|
+
async initializeEncryption() {
|
|
124
|
+
try {
|
|
125
|
+
// Dynamic import of crypto-js
|
|
126
|
+
if (!CryptoJS) {
|
|
127
|
+
CryptoJS = await Promise.resolve().then(() => __importStar(require('crypto-js')));
|
|
128
|
+
}
|
|
129
|
+
// Key validation is already done in validateEncryptionConfig()
|
|
130
|
+
// Just emit the initialization event
|
|
131
|
+
this.emit('encryption_initialized', { algorithm: this.config.encryption?.algorithm || 'AES-256-CBC' });
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
this.emit('encryption_error', { error: error instanceof Error ? error.message : 'Unknown error' });
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Encrypt retry state data
|
|
140
|
+
*/
|
|
141
|
+
async encryptData(data) {
|
|
142
|
+
if (!this.config.encryption?.enabled || !this.encryptionKey) {
|
|
143
|
+
return JSON.stringify(data);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const jsonData = JSON.stringify(data);
|
|
147
|
+
const encrypted = CryptoJS.AES.encrypt(jsonData, this.encryptionKey).toString();
|
|
148
|
+
return encrypted;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
this.emit('encryption_error', { error: error instanceof Error ? error.message : 'Unknown error' });
|
|
152
|
+
throw new Error(`Failed to encrypt data: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Decrypt retry state data
|
|
157
|
+
*/
|
|
158
|
+
async decryptData(encryptedData) {
|
|
159
|
+
if (!this.config.encryption?.enabled || !this.encryptionKey) {
|
|
160
|
+
return JSON.parse(encryptedData);
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const decrypted = CryptoJS.AES.decrypt(encryptedData, this.encryptionKey);
|
|
164
|
+
const jsonData = decrypted.toString(CryptoJS.enc.Utf8);
|
|
165
|
+
return JSON.parse(jsonData);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
this.emit('decryption_error', { error: error instanceof Error ? error.message : 'Unknown error' });
|
|
169
|
+
throw new Error(`Failed to decrypt data: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check access permissions
|
|
174
|
+
*/
|
|
175
|
+
checkAccess(accessControl, action, resource) {
|
|
176
|
+
if (!this.config.accessControl?.enabled) {
|
|
177
|
+
return true; // No access control enabled
|
|
178
|
+
}
|
|
179
|
+
const { userRole, permissions } = accessControl;
|
|
180
|
+
const allowedPermissions = this.config.accessControl?.permissions?.[userRole] || [];
|
|
181
|
+
// Check if user has the required permission
|
|
182
|
+
if (!allowedPermissions.includes(action)) {
|
|
183
|
+
this.logAudit({
|
|
184
|
+
userId: accessControl.userId,
|
|
185
|
+
userRole,
|
|
186
|
+
action,
|
|
187
|
+
resource,
|
|
188
|
+
success: false,
|
|
189
|
+
details: { reason: 'Insufficient permissions', requiredPermission: action }
|
|
190
|
+
});
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
this.logAudit({
|
|
194
|
+
userId: accessControl.userId,
|
|
195
|
+
userRole,
|
|
196
|
+
action,
|
|
197
|
+
resource,
|
|
198
|
+
success: true
|
|
199
|
+
});
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Check rate limiting
|
|
204
|
+
*/
|
|
205
|
+
checkRateLimit(identifier, limit = this.config.rateLimiting?.maxRequestsPerMinute || 100) {
|
|
206
|
+
if (!this.config.rateLimiting?.enabled) {
|
|
207
|
+
return true; // No rate limiting enabled
|
|
208
|
+
}
|
|
209
|
+
const now = new Date();
|
|
210
|
+
const windowMs = this.config.rateLimiting?.windowMs || 60000;
|
|
211
|
+
const windowStart = new Date(now.getTime() - windowMs);
|
|
212
|
+
// Get or create rate limit info
|
|
213
|
+
let rateLimitInfo = this.rateLimitStore.get(identifier);
|
|
214
|
+
if (!rateLimitInfo || rateLimitInfo.windowStart < windowStart) {
|
|
215
|
+
rateLimitInfo = {
|
|
216
|
+
requests: 0,
|
|
217
|
+
windowStart: now,
|
|
218
|
+
limit
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Check if limit exceeded
|
|
222
|
+
if (rateLimitInfo.requests >= rateLimitInfo.limit) {
|
|
223
|
+
this.logAudit({
|
|
224
|
+
action: 'rate_limit_exceeded',
|
|
225
|
+
resource: identifier,
|
|
226
|
+
success: false,
|
|
227
|
+
details: {
|
|
228
|
+
requests: rateLimitInfo.requests,
|
|
229
|
+
limit: rateLimitInfo.limit,
|
|
230
|
+
windowStart: rateLimitInfo.windowStart
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
// Increment request count
|
|
236
|
+
rateLimitInfo.requests++;
|
|
237
|
+
this.rateLimitStore.set(identifier, rateLimitInfo);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Log audit entry
|
|
242
|
+
*/
|
|
243
|
+
logAudit(entry) {
|
|
244
|
+
if (!this.config.auditLogging?.enabled) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const auditEntry = {
|
|
248
|
+
id: this.generateId(),
|
|
249
|
+
timestamp: new Date(),
|
|
250
|
+
...entry
|
|
251
|
+
};
|
|
252
|
+
// Add to audit log
|
|
253
|
+
this.auditLog.push(auditEntry);
|
|
254
|
+
// Maintain log size limit
|
|
255
|
+
if (this.auditLog.length > (this.config.auditLogging?.maxLogSize || 1000)) {
|
|
256
|
+
this.auditLog.shift();
|
|
257
|
+
}
|
|
258
|
+
// Emit audit event
|
|
259
|
+
this.emit('audit_log', auditEntry);
|
|
260
|
+
// Emit specific events based on action
|
|
261
|
+
if (entry.success) {
|
|
262
|
+
this.emit('audit_success', auditEntry);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
this.emit('audit_failure', auditEntry);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get audit log entries
|
|
270
|
+
*/
|
|
271
|
+
getAuditLog(limit = 100, offset = 0) {
|
|
272
|
+
return this.auditLog
|
|
273
|
+
.slice(offset, offset + limit)
|
|
274
|
+
.reverse(); // Most recent first
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Get audit log entries by user
|
|
278
|
+
*/
|
|
279
|
+
getAuditLogByUser(userId, limit = 100) {
|
|
280
|
+
return this.auditLog
|
|
281
|
+
.filter(entry => entry.userId === userId)
|
|
282
|
+
.slice(-limit)
|
|
283
|
+
.reverse();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get audit log entries by action
|
|
287
|
+
*/
|
|
288
|
+
getAuditLogByAction(action, limit = 100) {
|
|
289
|
+
return this.auditLog
|
|
290
|
+
.filter(entry => entry.action === action)
|
|
291
|
+
.slice(-limit)
|
|
292
|
+
.reverse();
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get audit statistics
|
|
296
|
+
*/
|
|
297
|
+
getAuditStats() {
|
|
298
|
+
const totalEntries = this.auditLog.length;
|
|
299
|
+
const successCount = this.auditLog.filter(entry => entry.success).length;
|
|
300
|
+
const failureCount = totalEntries - successCount;
|
|
301
|
+
const actionStats = this.auditLog.reduce((stats, entry) => {
|
|
302
|
+
stats[entry.action] = (stats[entry.action] || 0) + 1;
|
|
303
|
+
return stats;
|
|
304
|
+
}, {});
|
|
305
|
+
const userStats = this.auditLog.reduce((stats, entry) => {
|
|
306
|
+
const userId = entry.userId || 'anonymous';
|
|
307
|
+
stats[userId] = (stats[userId] || 0) + 1;
|
|
308
|
+
return stats;
|
|
309
|
+
}, {});
|
|
310
|
+
return {
|
|
311
|
+
totalEntries,
|
|
312
|
+
successCount,
|
|
313
|
+
failureCount,
|
|
314
|
+
successRate: totalEntries > 0 ? (successCount / totalEntries) * 100 : 0,
|
|
315
|
+
actionStats,
|
|
316
|
+
userStats,
|
|
317
|
+
timeRange: {
|
|
318
|
+
start: this.auditLog[0]?.timestamp,
|
|
319
|
+
end: this.auditLog[this.auditLog.length - 1]?.timestamp
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Clear audit log
|
|
325
|
+
*/
|
|
326
|
+
clearAuditLog() {
|
|
327
|
+
this.auditLog = [];
|
|
328
|
+
this.emit('audit_log_cleared');
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get rate limit information
|
|
332
|
+
*/
|
|
333
|
+
getRateLimitInfo(identifier) {
|
|
334
|
+
return this.rateLimitStore.get(identifier) || null;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Reset rate limit for an identifier
|
|
338
|
+
*/
|
|
339
|
+
resetRateLimit(identifier) {
|
|
340
|
+
this.rateLimitStore.delete(identifier);
|
|
341
|
+
this.emit('rate_limit_reset', { identifier });
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Get security configuration
|
|
345
|
+
*/
|
|
346
|
+
getConfig() {
|
|
347
|
+
return { ...this.config };
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Update security configuration
|
|
351
|
+
*/
|
|
352
|
+
updateConfig(newConfig) {
|
|
353
|
+
this.config = { ...this.config, ...newConfig };
|
|
354
|
+
this.emit('config_updated', { config: this.config });
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Check if encryption is enabled
|
|
358
|
+
*/
|
|
359
|
+
isEncryptionEnabled() {
|
|
360
|
+
return this.config.encryption?.enabled === true;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Check if access control is enabled
|
|
364
|
+
*/
|
|
365
|
+
isAccessControlEnabled() {
|
|
366
|
+
return this.config.accessControl?.enabled === true;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Check if audit logging is enabled
|
|
370
|
+
*/
|
|
371
|
+
isAuditLoggingEnabled() {
|
|
372
|
+
return this.config.auditLogging?.enabled === true;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Check if rate limiting is enabled
|
|
376
|
+
*/
|
|
377
|
+
isRateLimitingEnabled() {
|
|
378
|
+
return this.config.rateLimiting?.enabled === true;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Generate unique ID for audit entries
|
|
382
|
+
*/
|
|
383
|
+
generateId() {
|
|
384
|
+
return `audit_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get security status
|
|
388
|
+
*/
|
|
389
|
+
getSecurityStatus() {
|
|
390
|
+
return {
|
|
391
|
+
encryption: {
|
|
392
|
+
enabled: this.isEncryptionEnabled(),
|
|
393
|
+
algorithm: this.config.encryption?.algorithm,
|
|
394
|
+
keyConfigured: !!this.encryptionKey
|
|
395
|
+
},
|
|
396
|
+
accessControl: {
|
|
397
|
+
enabled: this.isAccessControlEnabled(),
|
|
398
|
+
roles: this.config.accessControl?.roles || [],
|
|
399
|
+
permissions: this.config.accessControl?.permissions || {}
|
|
400
|
+
},
|
|
401
|
+
auditLogging: {
|
|
402
|
+
enabled: this.isAuditLoggingEnabled(),
|
|
403
|
+
level: this.config.auditLogging?.level,
|
|
404
|
+
logSize: this.auditLog.length,
|
|
405
|
+
maxLogSize: this.config.auditLogging?.maxLogSize
|
|
406
|
+
},
|
|
407
|
+
rateLimiting: {
|
|
408
|
+
enabled: this.isRateLimitingEnabled(),
|
|
409
|
+
activeLimits: this.rateLimitStore.size,
|
|
410
|
+
maxRequestsPerMinute: this.config.rateLimiting?.maxRequestsPerMinute,
|
|
411
|
+
maxRequestsPerHour: this.config.rateLimiting?.maxRequestsPerHour
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
exports.SecurityManager = SecurityManager;
|
|
417
|
+
//# sourceMappingURL=security-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-manager.js","sourceRoot":"","sources":["../../src/security/security-manager.ts"],"names":[],"mappings":";AAAA;;;;;;EAME;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,mCAAsC;AAGtC,mDAAmD;AACnD,IAAI,QAAQ,GAAQ,IAAI,CAAC;AAgCzB;;GAEG;AACU,QAAA,uBAAuB,GAAmB;IACrD,UAAU,EAAE;QACV,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,aAAa;QACxB,SAAS,EAAE,8BAA8B;KAC1C;IACD,aAAa,EAAE;QACb,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC;QACpC,WAAW,EAAE;YACX,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC;YACxD,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YACvB,QAAQ,EAAE,CAAC,MAAM,CAAC;SACn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
|
+
type: 'postgresql' | 'mongodb' | 'redis-cluster' | 'redis' | 'memory';
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
connectionString?: string;
|
|
7
|
+
options?: Record<string, any>;
|
|
8
|
+
fallbackTo?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface StorageBackendTestResult {
|
|
11
|
+
success: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
latency?: number;
|
|
14
|
+
capabilities?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface StorageBackendInfo {
|
|
17
|
+
type: string;
|
|
18
|
+
priority: number;
|
|
19
|
+
available: boolean;
|
|
20
|
+
connectionString?: string;
|
|
21
|
+
testResult?: StorageBackendTestResult;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Storage backend selector that implements priority-based fallback logic
|
|
25
|
+
*/
|
|
26
|
+
export declare class StorageBackendSelector {
|
|
27
|
+
private config;
|
|
28
|
+
private selectedBackend?;
|
|
29
|
+
private backendInfo;
|
|
30
|
+
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Get the default storage backend configuration with priority order
|
|
33
|
+
*/
|
|
34
|
+
private getDefaultConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Detect environment variables for each backend type
|
|
37
|
+
*/
|
|
38
|
+
private detectEnvironmentVariables;
|
|
39
|
+
/**
|
|
40
|
+
* Handle manual override environment variables
|
|
41
|
+
*/
|
|
42
|
+
private handleManualOverrides;
|
|
43
|
+
/**
|
|
44
|
+
* Test connection to a storage backend
|
|
45
|
+
*/
|
|
46
|
+
private testConnection;
|
|
47
|
+
/**
|
|
48
|
+
* Test PostgreSQL connection
|
|
49
|
+
*/
|
|
50
|
+
private testPostgreSQLConnection;
|
|
51
|
+
/**
|
|
52
|
+
* Test MongoDB connection
|
|
53
|
+
*/
|
|
54
|
+
private testMongoDBConnection;
|
|
55
|
+
/**
|
|
56
|
+
* Test Redis Cluster connection
|
|
57
|
+
*/
|
|
58
|
+
private testRedisClusterConnection;
|
|
59
|
+
/**
|
|
60
|
+
* Test Redis connection
|
|
61
|
+
*/
|
|
62
|
+
private testRedisConnection;
|
|
63
|
+
/**
|
|
64
|
+
* Test Memory connection (always available)
|
|
65
|
+
*/
|
|
66
|
+
private testMemoryConnection;
|
|
67
|
+
/**
|
|
68
|
+
* Select the best available storage backend
|
|
69
|
+
*/
|
|
70
|
+
selectBackend(): Promise<StorageBackend>;
|
|
71
|
+
/**
|
|
72
|
+
* Create a storage backend instance
|
|
73
|
+
*/
|
|
74
|
+
private createBackend;
|
|
75
|
+
/**
|
|
76
|
+
* Get information about all tested backends
|
|
77
|
+
*/
|
|
78
|
+
getBackendInfo(): StorageBackendInfo[];
|
|
79
|
+
/**
|
|
80
|
+
* Get the currently selected backend
|
|
81
|
+
*/
|
|
82
|
+
getSelectedBackend(): StorageBackend | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Get the configuration for all backends
|
|
85
|
+
*/
|
|
86
|
+
getConfig(): StorageBackendConfig[];
|
|
87
|
+
/**
|
|
88
|
+
* Update the configuration for a specific backend
|
|
89
|
+
*/
|
|
90
|
+
updateConfig(type: StorageBackendConfig['type'], updates: Partial<StorageBackendConfig>): void;
|
|
91
|
+
/**
|
|
92
|
+
* Cleanup resources and close connections
|
|
93
|
+
*/
|
|
94
|
+
cleanup(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=backend-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-selector.d.ts","sourceRoot":"","sources":["../../src/storage/backend-selector.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,eAAe,GAAG,OAAO,GAAG,QAAQ,CAAC;IACtE,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAA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