@bernierllc/retry-suite 0.5.14 → 0.5.15

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.
@@ -0,0 +1,30 @@
1
+ import { AdminConfig } from '../types';
2
+ export declare class AdminServer {
3
+ private app;
4
+ private server;
5
+ private wss;
6
+ private config;
7
+ private retrySuite;
8
+ private connectedClients;
9
+ constructor(config: AdminConfig, retrySuite: any);
10
+ private setupMiddleware;
11
+ private setupRoutes;
12
+ private authMiddleware;
13
+ private handleGetMetrics;
14
+ private handleGetRetries;
15
+ private handleGetRetry;
16
+ private handleCancelRetry;
17
+ private handlePauseRetry;
18
+ private handleResumeRetry;
19
+ private handleGetAlerts;
20
+ private handleGetPerformanceReport;
21
+ private handleGetConfig;
22
+ private handleUpdateConfig;
23
+ private setupWebSocket;
24
+ private setupRealTimeUpdates;
25
+ private sendRealTimeUpdate;
26
+ private broadcastToClients;
27
+ start(port: number): Promise<void>;
28
+ stop(): Promise<void>;
29
+ getUrl(): string;
30
+ }
@@ -0,0 +1,335 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AdminServer = void 0;
11
+ // Mock implementations for development environment
12
+ const mockExpress = () => {
13
+ const app = {
14
+ use: jest.fn(),
15
+ get: jest.fn(),
16
+ post: jest.fn(),
17
+ put: jest.fn(),
18
+ listen: jest.fn()
19
+ };
20
+ return app;
21
+ };
22
+ mockExpress.json = () => (req, res, next) => next();
23
+ mockExpress.static = () => (req, res, next) => next();
24
+ const mockCors = () => (req, res, next) => next();
25
+ const mockHelmet = () => (req, res, next) => next();
26
+ const mockCompression = () => (req, res, next) => next();
27
+ class MockWebSocketServer {
28
+ constructor(options) { }
29
+ on(event, handler) { }
30
+ close(callback) { if (callback)
31
+ callback(); }
32
+ }
33
+ const mockHttp = {
34
+ createServer: (app) => ({
35
+ listen: jest.fn((port, host, callback) => {
36
+ if (typeof host === 'function') {
37
+ callback = host;
38
+ }
39
+ if (callback)
40
+ callback();
41
+ return {
42
+ close: jest.fn((cb) => cb && cb()),
43
+ on: jest.fn()
44
+ };
45
+ }),
46
+ close: jest.fn(),
47
+ on: jest.fn()
48
+ })
49
+ };
50
+ const mockPath = {
51
+ join: (...args) => args.join('/')
52
+ };
53
+ class AdminServer {
54
+ app;
55
+ server = null;
56
+ wss = null;
57
+ config;
58
+ retrySuite;
59
+ connectedClients = new Set();
60
+ constructor(config, retrySuite) {
61
+ this.config = config;
62
+ this.retrySuite = retrySuite;
63
+ this.app = mockExpress();
64
+ this.setupMiddleware();
65
+ this.setupRoutes();
66
+ }
67
+ setupMiddleware() {
68
+ this.app.use(mockCors());
69
+ this.app.use(mockExpress.json());
70
+ this.app.use(mockHelmet());
71
+ this.app.use(mockCompression());
72
+ if (this.config.auth.enabled) {
73
+ this.app.use('/api', this.authMiddleware.bind(this));
74
+ }
75
+ // Serve static files for admin interface
76
+ this.app.use(mockExpress.static());
77
+ }
78
+ setupRoutes() {
79
+ // Health check
80
+ this.app.get('/health', (req, res) => {
81
+ res.json({
82
+ status: 'healthy',
83
+ timestamp: new Date(),
84
+ version: '0.1.0'
85
+ });
86
+ });
87
+ // API routes
88
+ this.app.get('/api/metrics', this.handleGetMetrics.bind(this));
89
+ this.app.get('/api/retries', this.handleGetRetries.bind(this));
90
+ this.app.get('/api/retries/:id', this.handleGetRetry.bind(this));
91
+ this.app.post('/api/retries/:id/cancel', this.handleCancelRetry.bind(this));
92
+ this.app.post('/api/retries/:id/pause', this.handlePauseRetry.bind(this));
93
+ this.app.post('/api/retries/:id/resume', this.handleResumeRetry.bind(this));
94
+ this.app.get('/api/alerts', this.handleGetAlerts.bind(this));
95
+ this.app.get('/api/reports/performance', this.handleGetPerformanceReport.bind(this));
96
+ this.app.get('/api/config', this.handleGetConfig.bind(this));
97
+ this.app.put('/api/config', this.handleUpdateConfig.bind(this));
98
+ // Serve React app for all other routes
99
+ this.app.get('*', (req, res) => {
100
+ res.json({
101
+ message: 'Retry Suite Admin API',
102
+ endpoints: {
103
+ health: '/health',
104
+ metrics: '/api/metrics',
105
+ retries: '/api/retries',
106
+ alerts: '/api/alerts',
107
+ reports: '/api/reports/performance',
108
+ config: '/api/config'
109
+ }
110
+ });
111
+ });
112
+ }
113
+ authMiddleware(req, res, next) {
114
+ if (!this.config.auth.enabled) {
115
+ next();
116
+ return;
117
+ }
118
+ const auth = req.headers.authorization;
119
+ if (!auth || !auth.startsWith('Basic ')) {
120
+ res.status(401).json({ error: 'Authentication required' });
121
+ return;
122
+ }
123
+ const credentials = Buffer.from(auth.slice(6), 'base64').toString();
124
+ const [username, password] = credentials.split(':');
125
+ if (username === this.config.auth.username &&
126
+ password === this.config.auth.password) {
127
+ next();
128
+ return;
129
+ }
130
+ res.status(401).json({ error: 'Invalid credentials' });
131
+ }
132
+ async handleGetMetrics(req, res) {
133
+ try {
134
+ const metrics = await this.retrySuite.getMetrics();
135
+ res.json(metrics);
136
+ }
137
+ catch (error) {
138
+ res.status(500).json({ error: 'Failed to get metrics' });
139
+ }
140
+ }
141
+ async handleGetRetries(req, res) {
142
+ try {
143
+ // Get all retry statuses
144
+ const retries = Array.from(this.retrySuite.retryStates.values());
145
+ res.json(retries);
146
+ }
147
+ catch (error) {
148
+ res.status(500).json({ error: 'Failed to get retries' });
149
+ }
150
+ }
151
+ async handleGetRetry(req, res) {
152
+ try {
153
+ const { id } = req.params;
154
+ const retry = await this.retrySuite.getRetryStatus(id);
155
+ if (!retry) {
156
+ res.status(404).json({ error: 'Retry not found' });
157
+ return;
158
+ }
159
+ res.json(retry);
160
+ }
161
+ catch (error) {
162
+ res.status(500).json({ error: 'Failed to get retry' });
163
+ }
164
+ }
165
+ async handleCancelRetry(req, res) {
166
+ try {
167
+ const { id } = req.params;
168
+ const result = await this.retrySuite.cancelRetry(id);
169
+ res.json(result);
170
+ }
171
+ catch (error) {
172
+ res.status(500).json({ error: 'Failed to cancel retry' });
173
+ }
174
+ }
175
+ async handlePauseRetry(req, res) {
176
+ try {
177
+ const { id } = req.params;
178
+ const result = await this.retrySuite.pauseRetry(id);
179
+ res.json(result);
180
+ }
181
+ catch (error) {
182
+ res.status(500).json({ error: 'Failed to pause retry' });
183
+ }
184
+ }
185
+ async handleResumeRetry(req, res) {
186
+ try {
187
+ const { id } = req.params;
188
+ const result = await this.retrySuite.resumeRetry(id);
189
+ res.json(result);
190
+ }
191
+ catch (error) {
192
+ res.status(500).json({ error: 'Failed to resume retry' });
193
+ }
194
+ }
195
+ async handleGetAlerts(req, res) {
196
+ try {
197
+ const alerts = await this.retrySuite.getAlerts();
198
+ res.json(alerts);
199
+ }
200
+ catch (error) {
201
+ res.status(500).json({ error: 'Failed to get alerts' });
202
+ }
203
+ }
204
+ async handleGetPerformanceReport(req, res) {
205
+ try {
206
+ const { startDate, endDate } = req.query;
207
+ const options = {
208
+ startDate: startDate ? new Date(startDate) : undefined,
209
+ endDate: endDate ? new Date(endDate) : undefined
210
+ };
211
+ const report = await this.retrySuite.getPerformanceReport(options);
212
+ res.json(report);
213
+ }
214
+ catch (error) {
215
+ res.status(500).json({ error: 'Failed to get performance report' });
216
+ }
217
+ }
218
+ async handleGetConfig(req, res) {
219
+ try {
220
+ const config = this.retrySuite.getConfiguration();
221
+ // Remove sensitive information
222
+ const sanitizedConfig = { ...config };
223
+ if (sanitizedConfig.admin?.auth?.password) {
224
+ sanitizedConfig.admin.auth.password = '[REDACTED]';
225
+ }
226
+ res.json(sanitizedConfig);
227
+ }
228
+ catch (error) {
229
+ res.status(500).json({ error: 'Failed to get configuration' });
230
+ }
231
+ }
232
+ async handleUpdateConfig(req, res) {
233
+ try {
234
+ const result = await this.retrySuite.updateConfiguration(req.body);
235
+ res.json(result);
236
+ }
237
+ catch (error) {
238
+ res.status(500).json({ error: 'Failed to update configuration' });
239
+ }
240
+ }
241
+ setupWebSocket() {
242
+ if (!this.server)
243
+ return;
244
+ this.wss = new MockWebSocketServer({ server: this.server });
245
+ this.wss.on('connection', (ws) => {
246
+ this.connectedClients.add(ws);
247
+ ws.on('close', () => {
248
+ this.connectedClients.delete(ws);
249
+ });
250
+ ws.on('error', (error) => {
251
+ console.error('WebSocket error:', error);
252
+ this.connectedClients.delete(ws);
253
+ });
254
+ // Send initial data
255
+ this.sendRealTimeUpdate(ws, 'connection', { status: 'connected' });
256
+ });
257
+ // Setup periodic updates
258
+ this.setupRealTimeUpdates();
259
+ }
260
+ setupRealTimeUpdates() {
261
+ setInterval(async () => {
262
+ if (this.connectedClients.size === 0)
263
+ return;
264
+ try {
265
+ const metrics = await this.retrySuite.getMetrics();
266
+ const retries = Array.from(this.retrySuite.retryStates.values());
267
+ const update = {
268
+ type: 'metrics_update',
269
+ data: { metrics, retries },
270
+ timestamp: new Date()
271
+ };
272
+ this.broadcastToClients(update);
273
+ }
274
+ catch (error) {
275
+ console.error('Failed to send real-time updates:', error);
276
+ }
277
+ }, 5000); // Update every 5 seconds
278
+ }
279
+ sendRealTimeUpdate(ws, type, data) {
280
+ if (ws.readyState === WebSocket.OPEN) {
281
+ ws.send(JSON.stringify({
282
+ type,
283
+ data,
284
+ timestamp: new Date()
285
+ }));
286
+ }
287
+ }
288
+ broadcastToClients(data) {
289
+ const message = JSON.stringify(data);
290
+ this.connectedClients.forEach((ws) => {
291
+ if (ws.readyState === WebSocket.OPEN) {
292
+ ws.send(message);
293
+ }
294
+ else {
295
+ this.connectedClients.delete(ws);
296
+ }
297
+ });
298
+ }
299
+ async start(port) {
300
+ return new Promise((resolve, reject) => {
301
+ this.server = mockHttp.createServer(this.app);
302
+ this.server.listen(port, this.config.host, () => {
303
+ console.log(`Retry Suite Admin Server running on http://${this.config.host}:${port}`);
304
+ this.setupWebSocket();
305
+ resolve();
306
+ });
307
+ this.server.on('error', (error) => {
308
+ console.error('Server error:', error);
309
+ reject(error);
310
+ });
311
+ });
312
+ }
313
+ async stop() {
314
+ return new Promise((resolve) => {
315
+ if (this.wss) {
316
+ this.wss.close(() => {
317
+ console.log('WebSocket server closed');
318
+ });
319
+ }
320
+ if (this.server) {
321
+ this.server.close(() => {
322
+ console.log('Admin server stopped');
323
+ resolve();
324
+ });
325
+ }
326
+ else {
327
+ resolve();
328
+ }
329
+ });
330
+ }
331
+ getUrl() {
332
+ return `http://${this.config.host}:${this.config.port}`;
333
+ }
334
+ }
335
+ exports.AdminServer = AdminServer;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { RetryMetrics, Alert, RetryStatus } from '../types';
3
+ export interface RetryDashboardProps {
4
+ apiBaseUrl?: string;
5
+ }
6
+ export declare const RetryDashboard: React.FC<RetryDashboardProps>;
7
+ export declare const MetricsOverview: React.FC<{
8
+ metrics: RetryMetrics | null;
9
+ }>;
10
+ export declare const AlertsList: React.FC<{
11
+ alerts: Alert[];
12
+ onAcknowledge: (alertId: string) => void;
13
+ }>;
14
+ export declare const RetriesList: React.FC<{
15
+ retries: RetryStatus[];
16
+ onAction: (retryId: string, action: string) => void;
17
+ }>;