UNPKG

@idealite/web-services

Version:

Comprehensive web services library with webhook system and Mux integration

72 lines (71 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseWebhookSender = void 0; /** * Abstract base class for webhook senders * Provides common functionality that all webhook senders should implement */ class BaseWebhookSender { config; constructor(config) { this.config = { timeout: 5000, retryAttempts: 3, retryDelay: 1000, ...config, }; } /** * Generate a unique webhook ID */ generateWebhookId() { return `webhook_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; } /** * Create a standardized webhook payload */ createPayload(type, data, metadata) { return { id: this.generateWebhookId(), timestamp: new Date().toISOString(), type, data, metadata, }; } /** * Validate webhook configuration */ validateConfig() { if (!this.config.url) { throw new Error('Webhook URL is required'); } try { new URL(this.config.url); } catch { throw new Error('Invalid webhook URL format'); } } /** * Calculate retry delay with exponential backoff */ calculateRetryDelay(attempt) { const baseDelay = this.config.retryDelay || 1000; return baseDelay * Math.pow(2, attempt - 1); } /** * Get webhook configuration */ getConfig() { return { ...this.config }; } /** * Update webhook configuration */ updateConfig(newConfig) { this.config = { ...this.config, ...newConfig }; this.validateConfig(); } } exports.BaseWebhookSender = BaseWebhookSender;