autotel-subscribers 4.0.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.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +669 -0
  3. package/dist/amplitude.cjs +2486 -0
  4. package/dist/amplitude.cjs.map +1 -0
  5. package/dist/amplitude.d.cts +49 -0
  6. package/dist/amplitude.d.ts +49 -0
  7. package/dist/amplitude.js +2463 -0
  8. package/dist/amplitude.js.map +1 -0
  9. package/dist/event-subscriber-base-CnF3V56W.d.cts +182 -0
  10. package/dist/event-subscriber-base-CnF3V56W.d.ts +182 -0
  11. package/dist/factories.cjs +16660 -0
  12. package/dist/factories.cjs.map +1 -0
  13. package/dist/factories.d.cts +304 -0
  14. package/dist/factories.d.ts +304 -0
  15. package/dist/factories.js +16624 -0
  16. package/dist/factories.js.map +1 -0
  17. package/dist/index.cjs +16575 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +179 -0
  20. package/dist/index.d.ts +179 -0
  21. package/dist/index.js +16539 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/middleware.cjs +220 -0
  24. package/dist/middleware.cjs.map +1 -0
  25. package/dist/middleware.d.cts +227 -0
  26. package/dist/middleware.d.ts +227 -0
  27. package/dist/middleware.js +208 -0
  28. package/dist/middleware.js.map +1 -0
  29. package/dist/mixpanel.cjs +2940 -0
  30. package/dist/mixpanel.cjs.map +1 -0
  31. package/dist/mixpanel.d.cts +47 -0
  32. package/dist/mixpanel.d.ts +47 -0
  33. package/dist/mixpanel.js +2932 -0
  34. package/dist/mixpanel.js.map +1 -0
  35. package/dist/posthog.cjs +4115 -0
  36. package/dist/posthog.cjs.map +1 -0
  37. package/dist/posthog.d.cts +299 -0
  38. package/dist/posthog.d.ts +299 -0
  39. package/dist/posthog.js +4113 -0
  40. package/dist/posthog.js.map +1 -0
  41. package/dist/segment.cjs +6822 -0
  42. package/dist/segment.cjs.map +1 -0
  43. package/dist/segment.d.cts +49 -0
  44. package/dist/segment.d.ts +49 -0
  45. package/dist/segment.js +6794 -0
  46. package/dist/segment.js.map +1 -0
  47. package/dist/slack.cjs +368 -0
  48. package/dist/slack.cjs.map +1 -0
  49. package/dist/slack.d.cts +126 -0
  50. package/dist/slack.d.ts +126 -0
  51. package/dist/slack.js +366 -0
  52. package/dist/slack.js.map +1 -0
  53. package/dist/webhook.cjs +100 -0
  54. package/dist/webhook.cjs.map +1 -0
  55. package/dist/webhook.d.cts +53 -0
  56. package/dist/webhook.d.ts +53 -0
  57. package/dist/webhook.js +98 -0
  58. package/dist/webhook.js.map +1 -0
  59. package/examples/quickstart-custom-subscriber.ts +144 -0
  60. package/examples/subscriber-bigquery.ts +219 -0
  61. package/examples/subscriber-databricks.ts +280 -0
  62. package/examples/subscriber-kafka.ts +326 -0
  63. package/examples/subscriber-kinesis.ts +307 -0
  64. package/examples/subscriber-posthog.ts +421 -0
  65. package/examples/subscriber-pubsub.ts +336 -0
  66. package/examples/subscriber-snowflake.ts +232 -0
  67. package/package.json +141 -0
  68. package/src/amplitude.test.ts +231 -0
  69. package/src/amplitude.ts +148 -0
  70. package/src/event-subscriber-base.ts +325 -0
  71. package/src/factories.ts +197 -0
  72. package/src/index.ts +50 -0
  73. package/src/middleware.ts +489 -0
  74. package/src/mixpanel.test.ts +194 -0
  75. package/src/mixpanel.ts +134 -0
  76. package/src/mock-event-subscriber.ts +333 -0
  77. package/src/posthog.test.ts +629 -0
  78. package/src/posthog.ts +530 -0
  79. package/src/segment.test.ts +228 -0
  80. package/src/segment.ts +148 -0
  81. package/src/slack.ts +383 -0
  82. package/src/streaming-event-subscriber.ts +323 -0
  83. package/src/testing/index.ts +37 -0
  84. package/src/testing/mock-webhook-server.ts +242 -0
  85. package/src/testing/subscriber-test-harness.ts +365 -0
  86. package/src/webhook.test.ts +264 -0
  87. package/src/webhook.ts +158 -0
@@ -0,0 +1,179 @@
1
+ export { PostHogConfig, PostHogSubscriber } from './posthog.cjs';
2
+ export { MixpanelConfig, MixpanelSubscriber } from './mixpanel.cjs';
3
+ export { SegmentConfig, SegmentSubscriber } from './segment.cjs';
4
+ export { AmplitudeConfig, AmplitudeSubscriber } from './amplitude.cjs';
5
+ export { SlackSubscriber, SlackSubscriberConfig } from './slack.cjs';
6
+ export { WebhookConfig, WebhookSubscriber } from './webhook.cjs';
7
+ import { E as EventSubscriber, a as EventPayload } from './event-subscriber-base-CnF3V56W.cjs';
8
+ import 'autotel/event-subscriber';
9
+ import 'posthog-node';
10
+
11
+ /**
12
+ * Streaming Events Subscriber Base Class
13
+ *
14
+ * Specialized base class for high-throughput streaming platforms like
15
+ * Kafka, Kinesis, Pub/Sub, etc.
16
+ *
17
+ * Extends EventSubscriber with streaming-specific features:
18
+ * - Partitioning strategy for ordered delivery
19
+ * - Buffer overflow handling (drop/block/disk)
20
+ * - High-throughput optimizations
21
+ * - Backpressure signaling
22
+ *
23
+ * @example Kafka Streaming Subscriber
24
+ * ```typescript
25
+ * import { StreamingEventSubscriber } from 'autotel-subscribers/streaming-event-subscriber';
26
+ *
27
+ * class KafkaSubscriber extends StreamingEventSubscriber {
28
+ * name = 'KafkaSubscriber';
29
+ * version = '1.0.0';
30
+ *
31
+ * constructor(config: KafkaConfig) {
32
+ * super({
33
+ * maxBufferSize: 10000,
34
+ * bufferOverflowStrategy: 'block',
35
+ * maxBatchSize: 500
36
+ * });
37
+ * }
38
+ *
39
+ * protected getPartitionKey(payload: EventPayload): string {
40
+ * // Partition by userId for ordered events per user
41
+ * return payload.attributes?.userId || 'default';
42
+ * }
43
+ *
44
+ * protected async sendBatch(events: EventPayload[]): Promise<void> {
45
+ * await this.producer.send({
46
+ * topic: this.topic,
47
+ * messages: events.map(e => ({
48
+ * key: this.getPartitionKey(e),
49
+ * value: JSON.stringify(e)
50
+ * }))
51
+ * });
52
+ * }
53
+ * }
54
+ * ```
55
+ */
56
+
57
+ /**
58
+ * Buffer overflow strategy
59
+ *
60
+ * - 'drop': Drop new events when buffer is full (prevents blocking, but loses data)
61
+ * - 'block': Wait for space in buffer (backpressure, may slow application)
62
+ * - 'disk': Spill to disk when memory buffer full (reliable, but complex - not implemented yet)
63
+ */
64
+ type BufferOverflowStrategy = 'drop' | 'block' | 'disk';
65
+ /**
66
+ * Streaming subscriber configuration
67
+ */
68
+ interface StreamingSubscriberConfig {
69
+ /** Maximum buffer size before triggering overflow strategy (default: 10000) */
70
+ maxBufferSize?: number;
71
+ /** Strategy when buffer is full (default: 'block') */
72
+ bufferOverflowStrategy?: BufferOverflowStrategy;
73
+ /** Maximum batch size for sending (default: 500) */
74
+ maxBatchSize?: number;
75
+ /** Flush interval in milliseconds (default: 1000) */
76
+ flushIntervalMs?: number;
77
+ /** Enable compression (default: false) */
78
+ compressionEnabled?: boolean;
79
+ }
80
+ /**
81
+ * Buffer status for monitoring
82
+ */
83
+ interface BufferStatus {
84
+ /** Current number of events in buffer */
85
+ size: number;
86
+ /** Maximum capacity */
87
+ capacity: number;
88
+ /** Utilization percentage (0-100) */
89
+ utilization: number;
90
+ /** Is buffer near full (>80%) */
91
+ isNearFull: boolean;
92
+ /** Is buffer full (100%) */
93
+ isFull: boolean;
94
+ }
95
+ /**
96
+ * Streaming Events Subscriber Base Class
97
+ *
98
+ * Provides streaming-specific patterns on top of EventSubscriber.
99
+ */
100
+ declare abstract class StreamingEventSubscriber extends EventSubscriber {
101
+ protected config: Required<StreamingSubscriberConfig>;
102
+ protected buffer: EventPayload[];
103
+ protected flushIntervalHandle: NodeJS.Timeout | null;
104
+ private isShuttingDown;
105
+ constructor(config?: StreamingSubscriberConfig);
106
+ /**
107
+ * Get partition key for event
108
+ *
109
+ * Override this to implement your partitioning strategy.
110
+ * Events with the same partition key go to the same partition/shard.
111
+ *
112
+ * Common strategies:
113
+ * - By userId: Ordered events per user
114
+ * - By tenantId: Isolate tenants
115
+ * - By eventType: Group similar events
116
+ * - Round-robin: Load balancing
117
+ *
118
+ * @param payload - Event payload
119
+ * @returns Partition key (string)
120
+ *
121
+ * @example Partition by userId
122
+ * ```typescript
123
+ * protected getPartitionKey(payload: EventPayload): string {
124
+ * return payload.attributes?.userId || 'default';
125
+ * }
126
+ * ```
127
+ */
128
+ protected abstract getPartitionKey(payload: EventPayload): string;
129
+ /**
130
+ * Send batch of events to streaming platform
131
+ *
132
+ * Override this to implement platform-specific batch sending.
133
+ * Called when buffer reaches maxBatchSize or flush interval triggers.
134
+ *
135
+ * @param events - Batch of events to send
136
+ */
137
+ protected abstract sendBatch(events: EventPayload[]): Promise<void>;
138
+ /**
139
+ * Send single event to destination (from EventSubscriber)
140
+ *
141
+ * This buffers events and sends in batches for performance.
142
+ * Override sendBatch() instead of this method.
143
+ */
144
+ protected sendToDestination(payload: EventPayload): Promise<void>;
145
+ /**
146
+ * Ensure buffer has capacity for new event
147
+ *
148
+ * Implements buffer overflow strategy:
149
+ * - 'drop': Returns immediately (event will be added, oldest may be dropped)
150
+ * - 'block': Waits until space available (backpressure)
151
+ * - 'disk': Not implemented yet (would spill to disk)
152
+ */
153
+ private ensureBufferCapacity;
154
+ /**
155
+ * Flush buffer to destination
156
+ */
157
+ private flushBuffer;
158
+ /**
159
+ * Start periodic flushing
160
+ */
161
+ private startFlushInterval;
162
+ /**
163
+ * Get current buffer status (for monitoring/observability)
164
+ */
165
+ getBufferStatus(): BufferStatus;
166
+ /**
167
+ * Shutdown with proper buffer draining
168
+ */
169
+ shutdown(): Promise<void>;
170
+ /**
171
+ * Optional: Compress payload before sending
172
+ *
173
+ * Override this if your streaming platform supports compression.
174
+ * Only called if compressionEnabled = true.
175
+ */
176
+ protected compressPayload(payload: string): Promise<Buffer | string>;
177
+ }
178
+
179
+ export { EventPayload, EventSubscriber, StreamingEventSubscriber };
@@ -0,0 +1,179 @@
1
+ export { PostHogConfig, PostHogSubscriber } from './posthog.js';
2
+ export { MixpanelConfig, MixpanelSubscriber } from './mixpanel.js';
3
+ export { SegmentConfig, SegmentSubscriber } from './segment.js';
4
+ export { AmplitudeConfig, AmplitudeSubscriber } from './amplitude.js';
5
+ export { SlackSubscriber, SlackSubscriberConfig } from './slack.js';
6
+ export { WebhookConfig, WebhookSubscriber } from './webhook.js';
7
+ import { E as EventSubscriber, a as EventPayload } from './event-subscriber-base-CnF3V56W.js';
8
+ import 'autotel/event-subscriber';
9
+ import 'posthog-node';
10
+
11
+ /**
12
+ * Streaming Events Subscriber Base Class
13
+ *
14
+ * Specialized base class for high-throughput streaming platforms like
15
+ * Kafka, Kinesis, Pub/Sub, etc.
16
+ *
17
+ * Extends EventSubscriber with streaming-specific features:
18
+ * - Partitioning strategy for ordered delivery
19
+ * - Buffer overflow handling (drop/block/disk)
20
+ * - High-throughput optimizations
21
+ * - Backpressure signaling
22
+ *
23
+ * @example Kafka Streaming Subscriber
24
+ * ```typescript
25
+ * import { StreamingEventSubscriber } from 'autotel-subscribers/streaming-event-subscriber';
26
+ *
27
+ * class KafkaSubscriber extends StreamingEventSubscriber {
28
+ * name = 'KafkaSubscriber';
29
+ * version = '1.0.0';
30
+ *
31
+ * constructor(config: KafkaConfig) {
32
+ * super({
33
+ * maxBufferSize: 10000,
34
+ * bufferOverflowStrategy: 'block',
35
+ * maxBatchSize: 500
36
+ * });
37
+ * }
38
+ *
39
+ * protected getPartitionKey(payload: EventPayload): string {
40
+ * // Partition by userId for ordered events per user
41
+ * return payload.attributes?.userId || 'default';
42
+ * }
43
+ *
44
+ * protected async sendBatch(events: EventPayload[]): Promise<void> {
45
+ * await this.producer.send({
46
+ * topic: this.topic,
47
+ * messages: events.map(e => ({
48
+ * key: this.getPartitionKey(e),
49
+ * value: JSON.stringify(e)
50
+ * }))
51
+ * });
52
+ * }
53
+ * }
54
+ * ```
55
+ */
56
+
57
+ /**
58
+ * Buffer overflow strategy
59
+ *
60
+ * - 'drop': Drop new events when buffer is full (prevents blocking, but loses data)
61
+ * - 'block': Wait for space in buffer (backpressure, may slow application)
62
+ * - 'disk': Spill to disk when memory buffer full (reliable, but complex - not implemented yet)
63
+ */
64
+ type BufferOverflowStrategy = 'drop' | 'block' | 'disk';
65
+ /**
66
+ * Streaming subscriber configuration
67
+ */
68
+ interface StreamingSubscriberConfig {
69
+ /** Maximum buffer size before triggering overflow strategy (default: 10000) */
70
+ maxBufferSize?: number;
71
+ /** Strategy when buffer is full (default: 'block') */
72
+ bufferOverflowStrategy?: BufferOverflowStrategy;
73
+ /** Maximum batch size for sending (default: 500) */
74
+ maxBatchSize?: number;
75
+ /** Flush interval in milliseconds (default: 1000) */
76
+ flushIntervalMs?: number;
77
+ /** Enable compression (default: false) */
78
+ compressionEnabled?: boolean;
79
+ }
80
+ /**
81
+ * Buffer status for monitoring
82
+ */
83
+ interface BufferStatus {
84
+ /** Current number of events in buffer */
85
+ size: number;
86
+ /** Maximum capacity */
87
+ capacity: number;
88
+ /** Utilization percentage (0-100) */
89
+ utilization: number;
90
+ /** Is buffer near full (>80%) */
91
+ isNearFull: boolean;
92
+ /** Is buffer full (100%) */
93
+ isFull: boolean;
94
+ }
95
+ /**
96
+ * Streaming Events Subscriber Base Class
97
+ *
98
+ * Provides streaming-specific patterns on top of EventSubscriber.
99
+ */
100
+ declare abstract class StreamingEventSubscriber extends EventSubscriber {
101
+ protected config: Required<StreamingSubscriberConfig>;
102
+ protected buffer: EventPayload[];
103
+ protected flushIntervalHandle: NodeJS.Timeout | null;
104
+ private isShuttingDown;
105
+ constructor(config?: StreamingSubscriberConfig);
106
+ /**
107
+ * Get partition key for event
108
+ *
109
+ * Override this to implement your partitioning strategy.
110
+ * Events with the same partition key go to the same partition/shard.
111
+ *
112
+ * Common strategies:
113
+ * - By userId: Ordered events per user
114
+ * - By tenantId: Isolate tenants
115
+ * - By eventType: Group similar events
116
+ * - Round-robin: Load balancing
117
+ *
118
+ * @param payload - Event payload
119
+ * @returns Partition key (string)
120
+ *
121
+ * @example Partition by userId
122
+ * ```typescript
123
+ * protected getPartitionKey(payload: EventPayload): string {
124
+ * return payload.attributes?.userId || 'default';
125
+ * }
126
+ * ```
127
+ */
128
+ protected abstract getPartitionKey(payload: EventPayload): string;
129
+ /**
130
+ * Send batch of events to streaming platform
131
+ *
132
+ * Override this to implement platform-specific batch sending.
133
+ * Called when buffer reaches maxBatchSize or flush interval triggers.
134
+ *
135
+ * @param events - Batch of events to send
136
+ */
137
+ protected abstract sendBatch(events: EventPayload[]): Promise<void>;
138
+ /**
139
+ * Send single event to destination (from EventSubscriber)
140
+ *
141
+ * This buffers events and sends in batches for performance.
142
+ * Override sendBatch() instead of this method.
143
+ */
144
+ protected sendToDestination(payload: EventPayload): Promise<void>;
145
+ /**
146
+ * Ensure buffer has capacity for new event
147
+ *
148
+ * Implements buffer overflow strategy:
149
+ * - 'drop': Returns immediately (event will be added, oldest may be dropped)
150
+ * - 'block': Waits until space available (backpressure)
151
+ * - 'disk': Not implemented yet (would spill to disk)
152
+ */
153
+ private ensureBufferCapacity;
154
+ /**
155
+ * Flush buffer to destination
156
+ */
157
+ private flushBuffer;
158
+ /**
159
+ * Start periodic flushing
160
+ */
161
+ private startFlushInterval;
162
+ /**
163
+ * Get current buffer status (for monitoring/observability)
164
+ */
165
+ getBufferStatus(): BufferStatus;
166
+ /**
167
+ * Shutdown with proper buffer draining
168
+ */
169
+ shutdown(): Promise<void>;
170
+ /**
171
+ * Optional: Compress payload before sending
172
+ *
173
+ * Override this if your streaming platform supports compression.
174
+ * Only called if compressionEnabled = true.
175
+ */
176
+ protected compressPayload(payload: string): Promise<Buffer | string>;
177
+ }
178
+
179
+ export { EventPayload, EventSubscriber, StreamingEventSubscriber };