import { AutotelEventContext, AutotelEventContext as AutotelEventContext$1, EventAttributes, EventAttributesInput, EventSubscriber, EventTrackingOptions, FunnelStatus, OutcomeStatus } from "autotel/event-subscriber"; //#region src/event-subscriber-base.d.ts /** * Payload sent to destination */ interface EventPayload { /** Event type: 'event', 'funnel', 'outcome', or 'value' */ type: 'event' | 'funnel' | 'outcome' | 'value'; /** Event name or metric name */ name: string; /** Optional attributes */ attributes?: EventAttributes; /** For funnel events: funnel name */ funnel?: string; /** For funnel events: step status (from FunnelStatus enum) */ step?: FunnelStatus | string; /** For funnel events: custom step name (from trackFunnelProgression) */ stepName?: string; /** For funnel events: numeric position in funnel */ stepNumber?: number; /** For outcome events: operation name */ operation?: string; /** For outcome events: outcome status */ outcome?: OutcomeStatus; /** For value events: numeric value */ value?: number; /** Timestamp (ISO 8601) */ timestamp: string; /** * Autotel trace context (present when events.includeTraceContext is enabled) * * Subscribers should map these to platform-specific field names: * - PostHog: autotel.trace_id → $trace_id * - Mixpanel: autotel.trace_id → trace_id */ autotel?: AutotelEventContext; /** Optional schema metadata for contract-aware subscribers. */ schema?: EventTrackingOptions['schema']; } /** * Standard base class for building custom events subscribers * * **What it provides:** * - Consistent payload structure (normalized across all event types) * - Enable/disable flag (runtime control) * - Automatic error handling (with customizable error handlers) * - Pending requests tracking (ensures no lost events during shutdown) * - Graceful shutdown (drains pending requests before closing) * * **Usage:** * Extend this class and implement `sendToDestination()`. All other methods * (trackEvent, trackFunnelStep, trackOutcome, trackValue, shutdown) are handled automatically. * * For high-throughput streaming platforms (Kafka, Kinesis, Pub/Sub), use `StreamingEventSubscriber` instead. */ declare abstract class EventSubscriber$1 implements EventSubscriber { /** * Subscriber name (required for debugging) */ abstract readonly name: string; /** * Subscriber version (optional) */ readonly version?: string; /** * Enable/disable the subscriber (default: true) */ protected enabled: boolean; /** * Track pending requests for graceful shutdown */ private pendingRequests; /** * Send payload to destination * * Override this method to implement your destination-specific logic. * This is called for all event types (event, funnel, outcome, value). * * @param payload - Normalized event payload */ protected abstract sendToDestination(payload: EventPayload): Promise; /** * Optional: Handle errors * * Override this to customize error handling (logging, retries, etc.). * Default behavior: log to console.error * * @param error - Error that occurred * @param payload - Event payload that failed */ protected handleError(error: Error, payload: EventPayload): void; /** * Filter out undefined and null values from attributes * * This improves DX by allowing callers to pass objects with optional properties * without having to manually filter them first. * * @param attributes - Input attributes (may contain undefined/null) * @returns Filtered attributes with only defined values, or undefined if empty * * @example * ```typescript * const filtered = this.filterAttributes({ * userId: user.id, * email: user.email, // might be undefined * plan: null, // will be filtered out * }); * // Result: { userId: 'abc', email: 'test@example.com' } or { userId: 'abc' } * ``` */ protected filterAttributes(attributes?: EventAttributesInput): EventAttributes | undefined; /** * Track an event */ trackEvent(name: string, attributes?: EventAttributes, options?: EventTrackingOptions): Promise; /** * Track a funnel step */ trackFunnelStep(funnelName: string, step: FunnelStatus, attributes?: EventAttributes, options?: EventTrackingOptions): Promise; /** * Track an outcome */ trackOutcome(operationName: string, outcome: OutcomeStatus, attributes?: EventAttributes, options?: EventTrackingOptions): Promise; /** * Track a value/metric */ trackValue(name: string, value: number, attributes?: EventAttributes, options?: EventTrackingOptions): Promise; /** * Track funnel progression with custom step names * * Unlike trackFunnelStep which uses FunnelStatus enum values, * this method allows any string as the step name for flexible funnel tracking. * * @param funnelName - Name of the funnel (e.g., "checkout", "onboarding") * @param stepName - Custom step name (e.g., "cart_viewed", "payment_entered") * @param stepNumber - Optional numeric position in the funnel * @param attributes - Optional event attributes * @param options - Optional tracking options including autotel context */ trackFunnelProgression(funnelName: string, stepName: string, stepNumber?: number, attributes?: EventAttributes, options?: EventTrackingOptions): Promise; /** * Flush pending requests and clean up * * CRITICAL: Prevents race condition during shutdown * 1. Disables subscriber to stop new events * 2. Drains all pending requests (with retry logic) * 3. Ensures flush guarantee * * Override this if you need custom cleanup logic (close connections, flush buffers, etc.), * but ALWAYS call super.shutdown() first to drain pending requests. */ shutdown(): Promise; /** * Internal: Send payload and track request */ private send; /** * Internal: Send with error handling */ private sendWithErrorHandling; } //#endregion export { EventPayload as n, EventSubscriber$1 as r, AutotelEventContext$1 as t };