@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,109 @@
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.IntegrationManager = void 0;
11
+ const slack_integration_1 = require("./slack-integration");
12
+ const email_integration_1 = require("./email-integration");
13
+ const webhook_integration_1 = require("./webhook-integration");
14
+ class IntegrationManager {
15
+ integrations = new Map();
16
+ config;
17
+ constructor(config) {
18
+ this.config = config;
19
+ this.setupIntegrations();
20
+ }
21
+ setupIntegrations() {
22
+ for (const integrationConfig of this.config) {
23
+ try {
24
+ const integration = this.createIntegration(integrationConfig);
25
+ this.integrations.set(integrationConfig.type, integration);
26
+ }
27
+ catch (error) {
28
+ console.error(`Failed to setup integration ${integrationConfig.type}:`, error);
29
+ }
30
+ }
31
+ }
32
+ createIntegration(config) {
33
+ switch (config.type) {
34
+ case 'slack':
35
+ return new slack_integration_1.SlackIntegration(config.config);
36
+ case 'email':
37
+ return new email_integration_1.EmailIntegration(config.config);
38
+ case 'webhook':
39
+ return new webhook_integration_1.WebhookIntegration(config.config);
40
+ case 'pagerduty':
41
+ // PagerDuty integration would be implemented similarly
42
+ throw new Error('PagerDuty integration not yet implemented');
43
+ default:
44
+ throw new Error(`Unknown integration type: ${config.type}`);
45
+ }
46
+ }
47
+ async sendAlert(alert) {
48
+ if (this.integrations.size === 0) {
49
+ console.log('No integrations configured, skipping alert:', alert.message);
50
+ return;
51
+ }
52
+ const promises = Array.from(this.integrations.values()).map(integration => integration.sendAlert(alert).catch(error => {
53
+ console.error(`Failed to send alert via ${integration.type}:`, error);
54
+ }));
55
+ await Promise.all(promises);
56
+ }
57
+ async sendCriticalAlert(alert) {
58
+ if (this.integrations.size === 0) {
59
+ console.error('CRITICAL ALERT - No integrations configured:', alert.message);
60
+ return;
61
+ }
62
+ const promises = Array.from(this.integrations.values()).map(integration => integration.sendCriticalAlert(alert).catch(error => {
63
+ console.error(`Failed to send critical alert via ${integration.type}:`, error);
64
+ }));
65
+ await Promise.all(promises);
66
+ }
67
+ getIntegrations() {
68
+ return Array.from(this.integrations.keys());
69
+ }
70
+ hasIntegration(type) {
71
+ return this.integrations.has(type);
72
+ }
73
+ async testIntegration(type) {
74
+ const integration = this.integrations.get(type);
75
+ if (!integration) {
76
+ return false;
77
+ }
78
+ try {
79
+ const testAlert = {
80
+ id: `test_${Date.now()}`,
81
+ type: 'info',
82
+ message: 'Test alert from Retry Suite',
83
+ severity: 'low',
84
+ timestamp: new Date(),
85
+ metadata: { test: true },
86
+ acknowledged: false
87
+ };
88
+ await integration.sendAlert(testAlert);
89
+ return true;
90
+ }
91
+ catch (error) {
92
+ console.error(`Integration test failed for ${type}:`, error);
93
+ return false;
94
+ }
95
+ }
96
+ async testAllIntegrations() {
97
+ const results = {};
98
+ for (const type of this.integrations.keys()) {
99
+ results[type] = await this.testIntegration(type);
100
+ }
101
+ return results;
102
+ }
103
+ updateConfiguration(config) {
104
+ this.config = config;
105
+ this.integrations.clear();
106
+ this.setupIntegrations();
107
+ }
108
+ }
109
+ exports.IntegrationManager = IntegrationManager;
@@ -0,0 +1,10 @@
1
+ import { Alert, Integration, SlackConfig } from '../types';
2
+ export declare class SlackIntegration implements Integration {
3
+ readonly type = "slack";
4
+ private config;
5
+ constructor(config: SlackConfig);
6
+ sendAlert(alert: Alert): Promise<void>;
7
+ sendCriticalAlert(alert: Alert): Promise<void>;
8
+ private getSeverityColor;
9
+ private sendToSlack;
10
+ }
@@ -0,0 +1,95 @@
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.SlackIntegration = void 0;
11
+ class SlackIntegration {
12
+ type = 'slack';
13
+ config;
14
+ constructor(config) {
15
+ this.config = config;
16
+ }
17
+ async sendAlert(alert) {
18
+ if (alert.severity === 'low') {
19
+ return;
20
+ }
21
+ const message = {
22
+ channel: this.config.channel,
23
+ text: `🚨 *${alert.message}*`,
24
+ attachments: [{
25
+ color: this.getSeverityColor(alert.severity),
26
+ fields: [
27
+ { title: 'Type', value: alert.type, short: true },
28
+ { title: 'Severity', value: alert.severity, short: true },
29
+ { title: 'Time', value: alert.timestamp.toISOString(), short: true }
30
+ ],
31
+ footer: 'Retry Suite',
32
+ ts: Math.floor(alert.timestamp.getTime() / 1000)
33
+ }]
34
+ };
35
+ await this.sendToSlack(message);
36
+ }
37
+ async sendCriticalAlert(alert) {
38
+ const channels = [this.config.channel];
39
+ if (this.config.criticalChannel) {
40
+ channels.push(this.config.criticalChannel);
41
+ }
42
+ for (const channel of channels) {
43
+ const message = {
44
+ channel,
45
+ text: `🚨🚨 *CRITICAL: ${alert.message}* 🚨🚨`,
46
+ attachments: [{
47
+ color: 'danger',
48
+ fields: [
49
+ { title: 'Type', value: alert.type, short: true },
50
+ { title: 'Severity', value: alert.severity, short: true },
51
+ { title: 'Time', value: alert.timestamp.toISOString(), short: true },
52
+ { title: 'Details', value: JSON.stringify(alert.metadata, null, 2) }
53
+ ],
54
+ footer: 'Retry Suite - CRITICAL ALERT',
55
+ ts: Math.floor(alert.timestamp.getTime() / 1000)
56
+ }]
57
+ };
58
+ await this.sendToSlack(message);
59
+ }
60
+ }
61
+ getSeverityColor(severity) {
62
+ switch (severity) {
63
+ case 'low': return '#36a64f';
64
+ case 'medium': return '#ffa500';
65
+ case 'high': return '#ff0000';
66
+ case 'critical': return '#8b0000';
67
+ default: return '#36a64f';
68
+ }
69
+ }
70
+ async sendToSlack(message) {
71
+ try {
72
+ const response = await fetch('https://slack.com/api/chat.postMessage', {
73
+ method: 'POST',
74
+ headers: {
75
+ 'Authorization': `Bearer ${this.config.token}`,
76
+ 'Content-Type': 'application/json'
77
+ },
78
+ body: JSON.stringify(message)
79
+ });
80
+ if (!response.ok) {
81
+ const error = await response.text();
82
+ throw new Error(`Slack API error: ${response.status} - ${error}`);
83
+ }
84
+ const result = await response.json();
85
+ if (!result.ok) {
86
+ throw new Error(`Slack API error: ${result.error}`);
87
+ }
88
+ }
89
+ catch (error) {
90
+ console.error('Failed to send Slack message:', error);
91
+ throw error;
92
+ }
93
+ }
94
+ }
95
+ exports.SlackIntegration = SlackIntegration;
@@ -0,0 +1,10 @@
1
+ import { Alert, Integration, WebhookConfig } from '../types';
2
+ export declare class WebhookIntegration implements Integration {
3
+ readonly type = "webhook";
4
+ private config;
5
+ constructor(config: WebhookConfig);
6
+ sendAlert(alert: Alert): Promise<void>;
7
+ sendCriticalAlert(alert: Alert): Promise<void>;
8
+ private sendWebhook;
9
+ testConnection(): Promise<boolean>;
10
+ }
@@ -0,0 +1,83 @@
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.WebhookIntegration = void 0;
11
+ class WebhookIntegration {
12
+ type = 'webhook';
13
+ config;
14
+ constructor(config) {
15
+ this.config = config;
16
+ }
17
+ async sendAlert(alert) {
18
+ const payload = {
19
+ type: 'alert',
20
+ alert,
21
+ timestamp: new Date().toISOString(),
22
+ source: 'retry-suite'
23
+ };
24
+ await this.sendWebhook(payload);
25
+ }
26
+ async sendCriticalAlert(alert) {
27
+ const payload = {
28
+ type: 'critical_alert',
29
+ alert,
30
+ timestamp: new Date().toISOString(),
31
+ source: 'retry-suite',
32
+ priority: 'critical'
33
+ };
34
+ await this.sendWebhook(payload);
35
+ }
36
+ async sendWebhook(payload) {
37
+ try {
38
+ const headers = {
39
+ 'Content-Type': 'application/json',
40
+ 'User-Agent': 'BernierLLC-RetrySuite/0.1.0',
41
+ ...this.config.headers
42
+ };
43
+ const controller = new AbortController();
44
+ const timeout = this.config.timeout || 10000;
45
+ const timeoutId = setTimeout(() => {
46
+ controller.abort();
47
+ }, timeout);
48
+ const response = await fetch(this.config.url, {
49
+ method: 'POST',
50
+ headers,
51
+ body: JSON.stringify(payload),
52
+ signal: controller.signal
53
+ });
54
+ clearTimeout(timeoutId);
55
+ if (!response.ok) {
56
+ const errorText = await response.text();
57
+ throw new Error(`Webhook request failed: ${response.status} - ${errorText}`);
58
+ }
59
+ console.log(`[WEBHOOK] Alert sent successfully to ${this.config.url}`);
60
+ }
61
+ catch (error) {
62
+ console.error(`[WEBHOOK] Failed to send webhook to ${this.config.url}:`, error);
63
+ throw error;
64
+ }
65
+ }
66
+ async testConnection() {
67
+ try {
68
+ const testPayload = {
69
+ type: 'test',
70
+ message: 'Test webhook from Retry Suite',
71
+ timestamp: new Date().toISOString(),
72
+ source: 'retry-suite'
73
+ };
74
+ await this.sendWebhook(testPayload);
75
+ return true;
76
+ }
77
+ catch (error) {
78
+ console.error('Webhook test failed:', error);
79
+ return false;
80
+ }
81
+ }
82
+ }
83
+ exports.WebhookIntegration = WebhookIntegration;
@@ -0,0 +1,36 @@
1
+ import { RetrySuiteConfig, RetryOptions, RetryResult, RetryStatus, RetryMetrics, Alert, PerformanceReport, MetricsOptions, AlertOptions, ReportOptions, ScheduleResult, CancelResult, PauseResult, ResumeResult, ConfigResult, ValidationResult } from './types';
2
+ export declare class RetrySuite {
3
+ private retryManager;
4
+ private stateStorage;
5
+ private metricsCollector;
6
+ private adminServer;
7
+ private integrationManager;
8
+ private configManager;
9
+ private config;
10
+ private retryStates;
11
+ private metrics;
12
+ constructor(config: RetrySuiteConfig);
13
+ executeWithRetry<T>(id: string, fn: () => Promise<T>, options?: RetryOptions): Promise<RetryResult<T>>;
14
+ retryWithBackoff<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
15
+ scheduleRetry(id: string, fn: () => Promise<any>, scheduleTime: Date): Promise<ScheduleResult>;
16
+ getRetryStatus(id: string): Promise<RetryStatus | null>;
17
+ cancelRetry(id: string): Promise<CancelResult>;
18
+ pauseRetry(id: string): Promise<PauseResult>;
19
+ resumeRetry(id: string): Promise<ResumeResult>;
20
+ getMetrics(options?: MetricsOptions): Promise<RetryMetrics>;
21
+ getAlerts(options?: AlertOptions): Promise<Alert[]>;
22
+ getPerformanceReport(options?: ReportOptions): Promise<PerformanceReport>;
23
+ updateConfiguration(config: Partial<RetrySuiteConfig>): Promise<ConfigResult>;
24
+ getConfiguration(): RetrySuiteConfig;
25
+ validateConfiguration(config: RetrySuiteConfig): ValidationResult;
26
+ startAdminServer(port?: number): Promise<void>;
27
+ stopAdminServer(): Promise<void>;
28
+ getAdminUrl(): string;
29
+ private generateRetryId;
30
+ private initializeMetrics;
31
+ private updateMetrics;
32
+ private sendFailureAlert;
33
+ private sendCriticalAlert;
34
+ private generateRecommendations;
35
+ private setupEventListeners;
36
+ }