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.
- package/LICENSE +21 -0
- package/README.md +669 -0
- package/dist/amplitude.cjs +2486 -0
- package/dist/amplitude.cjs.map +1 -0
- package/dist/amplitude.d.cts +49 -0
- package/dist/amplitude.d.ts +49 -0
- package/dist/amplitude.js +2463 -0
- package/dist/amplitude.js.map +1 -0
- package/dist/event-subscriber-base-CnF3V56W.d.cts +182 -0
- package/dist/event-subscriber-base-CnF3V56W.d.ts +182 -0
- package/dist/factories.cjs +16660 -0
- package/dist/factories.cjs.map +1 -0
- package/dist/factories.d.cts +304 -0
- package/dist/factories.d.ts +304 -0
- package/dist/factories.js +16624 -0
- package/dist/factories.js.map +1 -0
- package/dist/index.cjs +16575 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +179 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +16539 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.cjs +220 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +227 -0
- package/dist/middleware.d.ts +227 -0
- package/dist/middleware.js +208 -0
- package/dist/middleware.js.map +1 -0
- package/dist/mixpanel.cjs +2940 -0
- package/dist/mixpanel.cjs.map +1 -0
- package/dist/mixpanel.d.cts +47 -0
- package/dist/mixpanel.d.ts +47 -0
- package/dist/mixpanel.js +2932 -0
- package/dist/mixpanel.js.map +1 -0
- package/dist/posthog.cjs +4115 -0
- package/dist/posthog.cjs.map +1 -0
- package/dist/posthog.d.cts +299 -0
- package/dist/posthog.d.ts +299 -0
- package/dist/posthog.js +4113 -0
- package/dist/posthog.js.map +1 -0
- package/dist/segment.cjs +6822 -0
- package/dist/segment.cjs.map +1 -0
- package/dist/segment.d.cts +49 -0
- package/dist/segment.d.ts +49 -0
- package/dist/segment.js +6794 -0
- package/dist/segment.js.map +1 -0
- package/dist/slack.cjs +368 -0
- package/dist/slack.cjs.map +1 -0
- package/dist/slack.d.cts +126 -0
- package/dist/slack.d.ts +126 -0
- package/dist/slack.js +366 -0
- package/dist/slack.js.map +1 -0
- package/dist/webhook.cjs +100 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +53 -0
- package/dist/webhook.d.ts +53 -0
- package/dist/webhook.js +98 -0
- package/dist/webhook.js.map +1 -0
- package/examples/quickstart-custom-subscriber.ts +144 -0
- package/examples/subscriber-bigquery.ts +219 -0
- package/examples/subscriber-databricks.ts +280 -0
- package/examples/subscriber-kafka.ts +326 -0
- package/examples/subscriber-kinesis.ts +307 -0
- package/examples/subscriber-posthog.ts +421 -0
- package/examples/subscriber-pubsub.ts +336 -0
- package/examples/subscriber-snowflake.ts +232 -0
- package/package.json +141 -0
- package/src/amplitude.test.ts +231 -0
- package/src/amplitude.ts +148 -0
- package/src/event-subscriber-base.ts +325 -0
- package/src/factories.ts +197 -0
- package/src/index.ts +50 -0
- package/src/middleware.ts +489 -0
- package/src/mixpanel.test.ts +194 -0
- package/src/mixpanel.ts +134 -0
- package/src/mock-event-subscriber.ts +333 -0
- package/src/posthog.test.ts +629 -0
- package/src/posthog.ts +530 -0
- package/src/segment.test.ts +228 -0
- package/src/segment.ts +148 -0
- package/src/slack.ts +383 -0
- package/src/streaming-event-subscriber.ts +323 -0
- package/src/testing/index.ts +37 -0
- package/src/testing/mock-webhook-server.ts +242 -0
- package/src/testing/subscriber-test-harness.ts +365 -0
- package/src/webhook.test.ts +264 -0
- package/src/webhook.ts +158 -0
package/dist/index.d.cts
ADDED
|
@@ -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 };
|
package/dist/index.d.ts
ADDED
|
@@ -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 };
|