autotel 2.1.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 +1946 -0
- package/dist/chunk-2LNRY4QK.js +273 -0
- package/dist/chunk-2LNRY4QK.js.map +1 -0
- package/dist/chunk-3HENGDW2.js +587 -0
- package/dist/chunk-3HENGDW2.js.map +1 -0
- package/dist/chunk-4OAT42CA.cjs +73 -0
- package/dist/chunk-4OAT42CA.cjs.map +1 -0
- package/dist/chunk-5GWX5LFW.js +70 -0
- package/dist/chunk-5GWX5LFW.js.map +1 -0
- package/dist/chunk-5R2M36QB.js +195 -0
- package/dist/chunk-5R2M36QB.js.map +1 -0
- package/dist/chunk-5ZN622AO.js +73 -0
- package/dist/chunk-5ZN622AO.js.map +1 -0
- package/dist/chunk-77MSMAUQ.cjs +498 -0
- package/dist/chunk-77MSMAUQ.cjs.map +1 -0
- package/dist/chunk-ABPEQ6RK.cjs +596 -0
- package/dist/chunk-ABPEQ6RK.cjs.map +1 -0
- package/dist/chunk-BWYGJKRB.js +95 -0
- package/dist/chunk-BWYGJKRB.js.map +1 -0
- package/dist/chunk-BZHG5IZ4.js +73 -0
- package/dist/chunk-BZHG5IZ4.js.map +1 -0
- package/dist/chunk-G7VZBCD6.cjs +35 -0
- package/dist/chunk-G7VZBCD6.cjs.map +1 -0
- package/dist/chunk-GVLK7YUU.cjs +30 -0
- package/dist/chunk-GVLK7YUU.cjs.map +1 -0
- package/dist/chunk-HCCXC7XG.js +205 -0
- package/dist/chunk-HCCXC7XG.js.map +1 -0
- package/dist/chunk-HE6T6FIX.cjs +203 -0
- package/dist/chunk-HE6T6FIX.cjs.map +1 -0
- package/dist/chunk-KIXWPOCO.cjs +100 -0
- package/dist/chunk-KIXWPOCO.cjs.map +1 -0
- package/dist/chunk-KVGNW3FC.js +87 -0
- package/dist/chunk-KVGNW3FC.js.map +1 -0
- package/dist/chunk-LITNXTTT.js +3 -0
- package/dist/chunk-LITNXTTT.js.map +1 -0
- package/dist/chunk-M4ANN7RL.js +114 -0
- package/dist/chunk-M4ANN7RL.js.map +1 -0
- package/dist/chunk-NC52UBR2.cjs +32 -0
- package/dist/chunk-NC52UBR2.cjs.map +1 -0
- package/dist/chunk-NHCNRQD3.cjs +212 -0
- package/dist/chunk-NHCNRQD3.cjs.map +1 -0
- package/dist/chunk-NZ72VDNY.cjs +4 -0
- package/dist/chunk-NZ72VDNY.cjs.map +1 -0
- package/dist/chunk-P6JUDYNO.js +57 -0
- package/dist/chunk-P6JUDYNO.js.map +1 -0
- package/dist/chunk-RJYY7BWX.js +1349 -0
- package/dist/chunk-RJYY7BWX.js.map +1 -0
- package/dist/chunk-TRI4V5BF.cjs +126 -0
- package/dist/chunk-TRI4V5BF.cjs.map +1 -0
- package/dist/chunk-UL33I6IS.js +139 -0
- package/dist/chunk-UL33I6IS.js.map +1 -0
- package/dist/chunk-URRW6M2C.cjs +61 -0
- package/dist/chunk-URRW6M2C.cjs.map +1 -0
- package/dist/chunk-UY3UYPBZ.cjs +77 -0
- package/dist/chunk-UY3UYPBZ.cjs.map +1 -0
- package/dist/chunk-W3253FGB.cjs +277 -0
- package/dist/chunk-W3253FGB.cjs.map +1 -0
- package/dist/chunk-W7LHZVQF.js +26 -0
- package/dist/chunk-W7LHZVQF.js.map +1 -0
- package/dist/chunk-WBWNM6LB.cjs +1360 -0
- package/dist/chunk-WBWNM6LB.cjs.map +1 -0
- package/dist/chunk-WFJ7L2RV.js +494 -0
- package/dist/chunk-WFJ7L2RV.js.map +1 -0
- package/dist/chunk-X4RMFFMR.js +28 -0
- package/dist/chunk-X4RMFFMR.js.map +1 -0
- package/dist/chunk-Y4Y2S7BM.cjs +92 -0
- package/dist/chunk-Y4Y2S7BM.cjs.map +1 -0
- package/dist/chunk-YLPNXZFI.cjs +143 -0
- package/dist/chunk-YLPNXZFI.cjs.map +1 -0
- package/dist/chunk-YTXEZ4SD.cjs +77 -0
- package/dist/chunk-YTXEZ4SD.cjs.map +1 -0
- package/dist/chunk-Z6ZWNWWR.js +30 -0
- package/dist/chunk-Z6ZWNWWR.js.map +1 -0
- package/dist/config.cjs +26 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +75 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +5 -0
- package/dist/config.js.map +1 -0
- package/dist/db.cjs +233 -0
- package/dist/db.cjs.map +1 -0
- package/dist/db.d.cts +123 -0
- package/dist/db.d.ts +123 -0
- package/dist/db.js +228 -0
- package/dist/db.js.map +1 -0
- package/dist/decorators.cjs +67 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +91 -0
- package/dist/decorators.d.ts +91 -0
- package/dist/decorators.js +65 -0
- package/dist/decorators.js.map +1 -0
- package/dist/event-subscriber.cjs +6 -0
- package/dist/event-subscriber.cjs.map +1 -0
- package/dist/event-subscriber.d.cts +116 -0
- package/dist/event-subscriber.d.ts +116 -0
- package/dist/event-subscriber.js +3 -0
- package/dist/event-subscriber.js.map +1 -0
- package/dist/event-testing.cjs +21 -0
- package/dist/event-testing.cjs.map +1 -0
- package/dist/event-testing.d.cts +110 -0
- package/dist/event-testing.d.ts +110 -0
- package/dist/event-testing.js +4 -0
- package/dist/event-testing.js.map +1 -0
- package/dist/event.cjs +30 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +282 -0
- package/dist/event.d.ts +282 -0
- package/dist/event.js +13 -0
- package/dist/event.js.map +1 -0
- package/dist/exporters.cjs +17 -0
- package/dist/exporters.cjs.map +1 -0
- package/dist/exporters.d.cts +1 -0
- package/dist/exporters.d.ts +1 -0
- package/dist/exporters.js +4 -0
- package/dist/exporters.js.map +1 -0
- package/dist/functional.cjs +46 -0
- package/dist/functional.cjs.map +1 -0
- package/dist/functional.d.cts +478 -0
- package/dist/functional.d.ts +478 -0
- package/dist/functional.js +13 -0
- package/dist/functional.js.map +1 -0
- package/dist/http.cjs +189 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +169 -0
- package/dist/http.d.ts +169 -0
- package/dist/http.js +184 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +333 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +758 -0
- package/dist/index.d.ts +758 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation.cjs +182 -0
- package/dist/instrumentation.cjs.map +1 -0
- package/dist/instrumentation.d.cts +49 -0
- package/dist/instrumentation.d.ts +49 -0
- package/dist/instrumentation.js +179 -0
- package/dist/instrumentation.js.map +1 -0
- package/dist/logger.cjs +19 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +146 -0
- package/dist/logger.d.ts +146 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/dist/metric-helpers.cjs +31 -0
- package/dist/metric-helpers.cjs.map +1 -0
- package/dist/metric-helpers.d.cts +13 -0
- package/dist/metric-helpers.d.ts +13 -0
- package/dist/metric-helpers.js +6 -0
- package/dist/metric-helpers.js.map +1 -0
- package/dist/metric-testing.cjs +21 -0
- package/dist/metric-testing.cjs.map +1 -0
- package/dist/metric-testing.d.cts +110 -0
- package/dist/metric-testing.d.ts +110 -0
- package/dist/metric-testing.js +4 -0
- package/dist/metric-testing.js.map +1 -0
- package/dist/metric.cjs +26 -0
- package/dist/metric.cjs.map +1 -0
- package/dist/metric.d.cts +240 -0
- package/dist/metric.d.ts +240 -0
- package/dist/metric.js +9 -0
- package/dist/metric.js.map +1 -0
- package/dist/processors.cjs +17 -0
- package/dist/processors.cjs.map +1 -0
- package/dist/processors.d.cts +1 -0
- package/dist/processors.d.ts +1 -0
- package/dist/processors.js +4 -0
- package/dist/processors.js.map +1 -0
- package/dist/sampling.cjs +40 -0
- package/dist/sampling.cjs.map +1 -0
- package/dist/sampling.d.cts +260 -0
- package/dist/sampling.d.ts +260 -0
- package/dist/sampling.js +7 -0
- package/dist/sampling.js.map +1 -0
- package/dist/semantic-helpers.cjs +35 -0
- package/dist/semantic-helpers.cjs.map +1 -0
- package/dist/semantic-helpers.d.cts +442 -0
- package/dist/semantic-helpers.d.ts +442 -0
- package/dist/semantic-helpers.js +14 -0
- package/dist/semantic-helpers.js.map +1 -0
- package/dist/tail-sampling-processor.cjs +13 -0
- package/dist/tail-sampling-processor.cjs.map +1 -0
- package/dist/tail-sampling-processor.d.cts +27 -0
- package/dist/tail-sampling-processor.d.ts +27 -0
- package/dist/tail-sampling-processor.js +4 -0
- package/dist/tail-sampling-processor.js.map +1 -0
- package/dist/testing.cjs +286 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +291 -0
- package/dist/testing.d.ts +291 -0
- package/dist/testing.js +263 -0
- package/dist/testing.js.map +1 -0
- package/dist/trace-context-DRZdUvVY.d.cts +181 -0
- package/dist/trace-context-DRZdUvVY.d.ts +181 -0
- package/dist/trace-helpers.cjs +54 -0
- package/dist/trace-helpers.cjs.map +1 -0
- package/dist/trace-helpers.d.cts +524 -0
- package/dist/trace-helpers.d.ts +524 -0
- package/dist/trace-helpers.js +5 -0
- package/dist/trace-helpers.js.map +1 -0
- package/dist/tracer-provider.cjs +21 -0
- package/dist/tracer-provider.cjs.map +1 -0
- package/dist/tracer-provider.d.cts +169 -0
- package/dist/tracer-provider.d.ts +169 -0
- package/dist/tracer-provider.js +4 -0
- package/dist/tracer-provider.js.map +1 -0
- package/package.json +280 -0
- package/src/baggage-span-processor.test.ts +202 -0
- package/src/baggage-span-processor.ts +98 -0
- package/src/circuit-breaker.test.ts +341 -0
- package/src/circuit-breaker.ts +184 -0
- package/src/config.test.ts +94 -0
- package/src/config.ts +169 -0
- package/src/db.test.ts +252 -0
- package/src/db.ts +447 -0
- package/src/decorators.test.ts +203 -0
- package/src/decorators.ts +188 -0
- package/src/env-config.test.ts +246 -0
- package/src/env-config.ts +158 -0
- package/src/event-queue.test.ts +222 -0
- package/src/event-queue.ts +203 -0
- package/src/event-subscriber.ts +136 -0
- package/src/event-testing.ts +197 -0
- package/src/event.test.ts +718 -0
- package/src/event.ts +556 -0
- package/src/exporters.ts +96 -0
- package/src/functional.test.ts +1059 -0
- package/src/functional.ts +2295 -0
- package/src/http.test.ts +487 -0
- package/src/http.ts +424 -0
- package/src/index.ts +158 -0
- package/src/init.customization.test.ts +210 -0
- package/src/init.integrations.test.ts +366 -0
- package/src/init.openllmetry.test.ts +282 -0
- package/src/init.protocol.test.ts +215 -0
- package/src/init.ts +1426 -0
- package/src/instrumentation.test.ts +108 -0
- package/src/instrumentation.ts +308 -0
- package/src/logger.test.ts +117 -0
- package/src/logger.ts +246 -0
- package/src/metric-helpers.ts +47 -0
- package/src/metric-testing.ts +197 -0
- package/src/metric.ts +434 -0
- package/src/metrics.test.ts +205 -0
- package/src/operation-context.ts +93 -0
- package/src/processors.ts +106 -0
- package/src/rate-limiter.test.ts +199 -0
- package/src/rate-limiter.ts +98 -0
- package/src/sampling.test.ts +513 -0
- package/src/sampling.ts +428 -0
- package/src/semantic-helpers.test.ts +311 -0
- package/src/semantic-helpers.ts +584 -0
- package/src/shutdown.test.ts +311 -0
- package/src/shutdown.ts +222 -0
- package/src/stub.integration.test.ts +361 -0
- package/src/tail-sampling-processor.test.ts +226 -0
- package/src/tail-sampling-processor.ts +51 -0
- package/src/testing.ts +670 -0
- package/src/trace-context.ts +470 -0
- package/src/trace-helpers.new.test.ts +278 -0
- package/src/trace-helpers.test.ts +242 -0
- package/src/trace-helpers.ts +690 -0
- package/src/tracer-provider.test.ts +183 -0
- package/src/tracer-provider.ts +266 -0
- package/src/track.test.ts +153 -0
- package/src/track.ts +120 -0
- package/src/validation.test.ts +306 -0
- package/src/validation.ts +239 -0
- package/src/variable-name-inference.test.ts +178 -0
- package/src/variable-name-inference.ts +242 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Subscriber Interface (Type-only)
|
|
3
|
+
*
|
|
4
|
+
* Import this interface to create custom subscribers without importing implementations.
|
|
5
|
+
* Keeps core package focused on OpenTelemetry with zero extra dependencies.
|
|
6
|
+
*
|
|
7
|
+
* For ready-made subscribers (PostHog, Mixpanel, Amplitude, Segment),
|
|
8
|
+
* see the separate `autotel-subscribers` package.
|
|
9
|
+
*
|
|
10
|
+
* @example Custom subscriber
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { EventSubscriber } from 'autotel/event-subscriber';
|
|
13
|
+
*
|
|
14
|
+
* class MyCustomSubscriber implements EventSubscriber {
|
|
15
|
+
* trackEvent(name: string, attributes?: Record<string, any>): void {
|
|
16
|
+
* // Send to your events platform
|
|
17
|
+
* }
|
|
18
|
+
* // ... implement other methods
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Use pre-built subscribers
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { Events } from 'autotel/events';
|
|
25
|
+
* import { PostHogSubscriber } from 'autotel-subscribers/posthog';
|
|
26
|
+
* import { MixpanelSubscriber } from 'autotel-subscribers/mixpanel';
|
|
27
|
+
*
|
|
28
|
+
* const event =new Event('checkout', {
|
|
29
|
+
* subscribers: [
|
|
30
|
+
* new PostHogSubscriber({ apiKey: 'phc_...' }),
|
|
31
|
+
* new MixpanelSubscriber({ token: '...' })
|
|
32
|
+
* ]
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Event attributes (supports any JSON-serializable values)
|
|
38
|
+
*/
|
|
39
|
+
type EventAttributes = Record<string, string | number | boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Funnel step status
|
|
42
|
+
*/
|
|
43
|
+
type FunnelStatus = 'started' | 'completed' | 'abandoned' | 'failed';
|
|
44
|
+
/**
|
|
45
|
+
* Outcome status
|
|
46
|
+
*/
|
|
47
|
+
type OutcomeStatus = 'success' | 'failure' | 'partial';
|
|
48
|
+
/**
|
|
49
|
+
* Event subscriber interface
|
|
50
|
+
*
|
|
51
|
+
* Implement this to send events to any platform.
|
|
52
|
+
* Zero runtime dependencies - just types.
|
|
53
|
+
*
|
|
54
|
+
* All tracking methods are async to support:
|
|
55
|
+
* - Backpressure signaling (buffer full)
|
|
56
|
+
* - Streaming platforms (Kafka, Kinesis, Pub/Sub)
|
|
57
|
+
* - Await delivery confirmation
|
|
58
|
+
* - Proper error propagation
|
|
59
|
+
*/
|
|
60
|
+
interface EventSubscriber {
|
|
61
|
+
/**
|
|
62
|
+
* Track an event (e.g., "user.registered", "order.created")
|
|
63
|
+
*
|
|
64
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
65
|
+
*/
|
|
66
|
+
trackEvent(name: string, attributes?: EventAttributes): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Track a funnel step (e.g., checkout: started → completed)
|
|
69
|
+
*
|
|
70
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
71
|
+
*/
|
|
72
|
+
trackFunnelStep(funnelName: string, step: FunnelStatus, attributes?: EventAttributes): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Track an outcome (e.g., "payment.processing" → success/failure)
|
|
75
|
+
*
|
|
76
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
77
|
+
*/
|
|
78
|
+
trackOutcome(operationName: string, outcome: OutcomeStatus, attributes?: EventAttributes): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Track a value/metric (e.g., revenue, cart value)
|
|
81
|
+
*
|
|
82
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
83
|
+
*/
|
|
84
|
+
trackValue(name: string, value: number, attributes?: EventAttributes): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Optional: Flush pending events and clean up resources
|
|
87
|
+
*
|
|
88
|
+
* Implement this if your subscriber buffers events, maintains connections,
|
|
89
|
+
* or needs cleanup before shutdown. Called during graceful shutdown.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* class MySubscriber implements EventSubscriber {
|
|
94
|
+
* async shutdown(): Promise<void> {
|
|
95
|
+
* await this.flushBuffer();
|
|
96
|
+
* await this.closeConnections();
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
shutdown?(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Optional: Subscriber name for debugging and error reporting
|
|
104
|
+
*
|
|
105
|
+
* @example "PostHogSubscriber", "SnowflakeSubscriber", "CustomWebhookSubscriber"
|
|
106
|
+
*/
|
|
107
|
+
readonly name?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Optional: Subscriber version for debugging
|
|
110
|
+
*
|
|
111
|
+
* @example "1.0.0"
|
|
112
|
+
*/
|
|
113
|
+
readonly version?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type { EventAttributes, EventSubscriber, FunnelStatus, OutcomeStatus };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Subscriber Interface (Type-only)
|
|
3
|
+
*
|
|
4
|
+
* Import this interface to create custom subscribers without importing implementations.
|
|
5
|
+
* Keeps core package focused on OpenTelemetry with zero extra dependencies.
|
|
6
|
+
*
|
|
7
|
+
* For ready-made subscribers (PostHog, Mixpanel, Amplitude, Segment),
|
|
8
|
+
* see the separate `autotel-subscribers` package.
|
|
9
|
+
*
|
|
10
|
+
* @example Custom subscriber
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { EventSubscriber } from 'autotel/event-subscriber';
|
|
13
|
+
*
|
|
14
|
+
* class MyCustomSubscriber implements EventSubscriber {
|
|
15
|
+
* trackEvent(name: string, attributes?: Record<string, any>): void {
|
|
16
|
+
* // Send to your events platform
|
|
17
|
+
* }
|
|
18
|
+
* // ... implement other methods
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Use pre-built subscribers
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { Events } from 'autotel/events';
|
|
25
|
+
* import { PostHogSubscriber } from 'autotel-subscribers/posthog';
|
|
26
|
+
* import { MixpanelSubscriber } from 'autotel-subscribers/mixpanel';
|
|
27
|
+
*
|
|
28
|
+
* const event =new Event('checkout', {
|
|
29
|
+
* subscribers: [
|
|
30
|
+
* new PostHogSubscriber({ apiKey: 'phc_...' }),
|
|
31
|
+
* new MixpanelSubscriber({ token: '...' })
|
|
32
|
+
* ]
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Event attributes (supports any JSON-serializable values)
|
|
38
|
+
*/
|
|
39
|
+
type EventAttributes = Record<string, string | number | boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Funnel step status
|
|
42
|
+
*/
|
|
43
|
+
type FunnelStatus = 'started' | 'completed' | 'abandoned' | 'failed';
|
|
44
|
+
/**
|
|
45
|
+
* Outcome status
|
|
46
|
+
*/
|
|
47
|
+
type OutcomeStatus = 'success' | 'failure' | 'partial';
|
|
48
|
+
/**
|
|
49
|
+
* Event subscriber interface
|
|
50
|
+
*
|
|
51
|
+
* Implement this to send events to any platform.
|
|
52
|
+
* Zero runtime dependencies - just types.
|
|
53
|
+
*
|
|
54
|
+
* All tracking methods are async to support:
|
|
55
|
+
* - Backpressure signaling (buffer full)
|
|
56
|
+
* - Streaming platforms (Kafka, Kinesis, Pub/Sub)
|
|
57
|
+
* - Await delivery confirmation
|
|
58
|
+
* - Proper error propagation
|
|
59
|
+
*/
|
|
60
|
+
interface EventSubscriber {
|
|
61
|
+
/**
|
|
62
|
+
* Track an event (e.g., "user.registered", "order.created")
|
|
63
|
+
*
|
|
64
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
65
|
+
*/
|
|
66
|
+
trackEvent(name: string, attributes?: EventAttributes): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Track a funnel step (e.g., checkout: started → completed)
|
|
69
|
+
*
|
|
70
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
71
|
+
*/
|
|
72
|
+
trackFunnelStep(funnelName: string, step: FunnelStatus, attributes?: EventAttributes): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Track an outcome (e.g., "payment.processing" → success/failure)
|
|
75
|
+
*
|
|
76
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
77
|
+
*/
|
|
78
|
+
trackOutcome(operationName: string, outcome: OutcomeStatus, attributes?: EventAttributes): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Track a value/metric (e.g., revenue, cart value)
|
|
81
|
+
*
|
|
82
|
+
* @returns Promise that resolves when event is sent (or buffered)
|
|
83
|
+
*/
|
|
84
|
+
trackValue(name: string, value: number, attributes?: EventAttributes): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Optional: Flush pending events and clean up resources
|
|
87
|
+
*
|
|
88
|
+
* Implement this if your subscriber buffers events, maintains connections,
|
|
89
|
+
* or needs cleanup before shutdown. Called during graceful shutdown.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* class MySubscriber implements EventSubscriber {
|
|
94
|
+
* async shutdown(): Promise<void> {
|
|
95
|
+
* await this.flushBuffer();
|
|
96
|
+
* await this.closeConnections();
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
shutdown?(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Optional: Subscriber name for debugging and error reporting
|
|
104
|
+
*
|
|
105
|
+
* @example "PostHogSubscriber", "SnowflakeSubscriber", "CustomWebhookSubscriber"
|
|
106
|
+
*/
|
|
107
|
+
readonly name?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Optional: Subscriber version for debugging
|
|
110
|
+
*
|
|
111
|
+
* @example "1.0.0"
|
|
112
|
+
*/
|
|
113
|
+
readonly version?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type { EventAttributes, EventSubscriber, FunnelStatus, OutcomeStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"event-subscriber.js"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUY3UYPBZ_cjs = require('./chunk-UY3UYPBZ.cjs');
|
|
4
|
+
require('./chunk-G7VZBCD6.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "assertEventTracked", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkUY3UYPBZ_cjs.assertEventTracked; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "assertOutcomeTracked", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkUY3UYPBZ_cjs.assertOutcomeTracked; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "createEventCollector", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkUY3UYPBZ_cjs.createEventCollector; }
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=event-testing.cjs.map
|
|
21
|
+
//# sourceMappingURL=event-testing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"event-testing.cjs"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { EventAttributes, FunnelStatus, OutcomeStatus } from './event-subscriber.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Testing utilities for Events
|
|
5
|
+
*
|
|
6
|
+
* Provides in-memory collection of events for testing purposes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface EventData {
|
|
10
|
+
event: string;
|
|
11
|
+
attributes?: EventAttributes;
|
|
12
|
+
service: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
}
|
|
15
|
+
interface EventsFunnelStep {
|
|
16
|
+
funnel: string;
|
|
17
|
+
status: FunnelStatus;
|
|
18
|
+
attributes?: EventAttributes;
|
|
19
|
+
service: string;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
}
|
|
22
|
+
interface EventsOutcome {
|
|
23
|
+
operation: string;
|
|
24
|
+
status: OutcomeStatus;
|
|
25
|
+
attributes?: EventAttributes;
|
|
26
|
+
service: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
interface EventsValue {
|
|
30
|
+
metric: string;
|
|
31
|
+
value: number;
|
|
32
|
+
attributes?: EventAttributes;
|
|
33
|
+
service: string;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* In-memory events collector for testing
|
|
38
|
+
*/
|
|
39
|
+
interface EventCollector {
|
|
40
|
+
/** Get all collected events */
|
|
41
|
+
getEvents(): EventData[];
|
|
42
|
+
/** Get all collected funnel steps */
|
|
43
|
+
getFunnelSteps(): EventsFunnelStep[];
|
|
44
|
+
/** Get all collected outcomes */
|
|
45
|
+
getOutcomes(): EventsOutcome[];
|
|
46
|
+
/** Get all collected values */
|
|
47
|
+
getValues(): EventsValue[];
|
|
48
|
+
/** Clear all collected events */
|
|
49
|
+
clear(): void;
|
|
50
|
+
/** Record an event (internal use) */
|
|
51
|
+
recordEvent(event: EventData): void;
|
|
52
|
+
/** Record a funnel step (internal use) */
|
|
53
|
+
recordFunnelStep(step: EventsFunnelStep): void;
|
|
54
|
+
/** Record an outcome (internal use) */
|
|
55
|
+
recordOutcome(outcome: EventsOutcome): void;
|
|
56
|
+
/** Record a value (internal use) */
|
|
57
|
+
recordValue(value: EventsValue): void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create an in-memory events collector for testing
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const collector = createEventCollector()
|
|
65
|
+
*
|
|
66
|
+
* const events = new Event('test-service', { collector })
|
|
67
|
+
* events.trackEvent('application.submitted', { jobId: '123' })
|
|
68
|
+
*
|
|
69
|
+
* const event =collector.getEvents()
|
|
70
|
+
* expect(events).toHaveLength(1)
|
|
71
|
+
* expect(events[0].event).toBe('application.submitted')
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare function createEventCollector(): EventCollector;
|
|
75
|
+
/**
|
|
76
|
+
* Assert that an events event was tracked
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* assertEventTracked({
|
|
81
|
+
* collector,
|
|
82
|
+
* eventName: 'application.submitted',
|
|
83
|
+
* attributes: { jobId: '123' }
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function assertEventTracked(options: {
|
|
88
|
+
collector: EventCollector;
|
|
89
|
+
eventName: string;
|
|
90
|
+
attributes?: Record<string, unknown>;
|
|
91
|
+
}): void;
|
|
92
|
+
/**
|
|
93
|
+
* Assert that an outcome was tracked
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* assertOutcomeTracked({
|
|
98
|
+
* collector,
|
|
99
|
+
* operation: 'email.delivery',
|
|
100
|
+
* status: 'success'
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function assertOutcomeTracked(options: {
|
|
105
|
+
collector: EventCollector;
|
|
106
|
+
operation: string;
|
|
107
|
+
status: 'success' | 'failure' | 'partial';
|
|
108
|
+
}): void;
|
|
109
|
+
|
|
110
|
+
export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, assertEventTracked, assertOutcomeTracked, createEventCollector };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { EventAttributes, FunnelStatus, OutcomeStatus } from './event-subscriber.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Testing utilities for Events
|
|
5
|
+
*
|
|
6
|
+
* Provides in-memory collection of events for testing purposes.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface EventData {
|
|
10
|
+
event: string;
|
|
11
|
+
attributes?: EventAttributes;
|
|
12
|
+
service: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
}
|
|
15
|
+
interface EventsFunnelStep {
|
|
16
|
+
funnel: string;
|
|
17
|
+
status: FunnelStatus;
|
|
18
|
+
attributes?: EventAttributes;
|
|
19
|
+
service: string;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
}
|
|
22
|
+
interface EventsOutcome {
|
|
23
|
+
operation: string;
|
|
24
|
+
status: OutcomeStatus;
|
|
25
|
+
attributes?: EventAttributes;
|
|
26
|
+
service: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
interface EventsValue {
|
|
30
|
+
metric: string;
|
|
31
|
+
value: number;
|
|
32
|
+
attributes?: EventAttributes;
|
|
33
|
+
service: string;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* In-memory events collector for testing
|
|
38
|
+
*/
|
|
39
|
+
interface EventCollector {
|
|
40
|
+
/** Get all collected events */
|
|
41
|
+
getEvents(): EventData[];
|
|
42
|
+
/** Get all collected funnel steps */
|
|
43
|
+
getFunnelSteps(): EventsFunnelStep[];
|
|
44
|
+
/** Get all collected outcomes */
|
|
45
|
+
getOutcomes(): EventsOutcome[];
|
|
46
|
+
/** Get all collected values */
|
|
47
|
+
getValues(): EventsValue[];
|
|
48
|
+
/** Clear all collected events */
|
|
49
|
+
clear(): void;
|
|
50
|
+
/** Record an event (internal use) */
|
|
51
|
+
recordEvent(event: EventData): void;
|
|
52
|
+
/** Record a funnel step (internal use) */
|
|
53
|
+
recordFunnelStep(step: EventsFunnelStep): void;
|
|
54
|
+
/** Record an outcome (internal use) */
|
|
55
|
+
recordOutcome(outcome: EventsOutcome): void;
|
|
56
|
+
/** Record a value (internal use) */
|
|
57
|
+
recordValue(value: EventsValue): void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create an in-memory events collector for testing
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const collector = createEventCollector()
|
|
65
|
+
*
|
|
66
|
+
* const events = new Event('test-service', { collector })
|
|
67
|
+
* events.trackEvent('application.submitted', { jobId: '123' })
|
|
68
|
+
*
|
|
69
|
+
* const event =collector.getEvents()
|
|
70
|
+
* expect(events).toHaveLength(1)
|
|
71
|
+
* expect(events[0].event).toBe('application.submitted')
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare function createEventCollector(): EventCollector;
|
|
75
|
+
/**
|
|
76
|
+
* Assert that an events event was tracked
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* assertEventTracked({
|
|
81
|
+
* collector,
|
|
82
|
+
* eventName: 'application.submitted',
|
|
83
|
+
* attributes: { jobId: '123' }
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare function assertEventTracked(options: {
|
|
88
|
+
collector: EventCollector;
|
|
89
|
+
eventName: string;
|
|
90
|
+
attributes?: Record<string, unknown>;
|
|
91
|
+
}): void;
|
|
92
|
+
/**
|
|
93
|
+
* Assert that an outcome was tracked
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* assertOutcomeTracked({
|
|
98
|
+
* collector,
|
|
99
|
+
* operation: 'email.delivery',
|
|
100
|
+
* status: 'success'
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function assertOutcomeTracked(options: {
|
|
105
|
+
collector: EventCollector;
|
|
106
|
+
operation: string;
|
|
107
|
+
status: 'success' | 'failure' | 'partial';
|
|
108
|
+
}): void;
|
|
109
|
+
|
|
110
|
+
export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, assertEventTracked, assertOutcomeTracked, createEventCollector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"event-testing.js"}
|
package/dist/event.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk77MSMAUQ_cjs = require('./chunk-77MSMAUQ.cjs');
|
|
4
|
+
require('./chunk-NZ72VDNY.cjs');
|
|
5
|
+
require('./chunk-UY3UYPBZ.cjs');
|
|
6
|
+
require('./chunk-YLPNXZFI.cjs');
|
|
7
|
+
require('./chunk-ABPEQ6RK.cjs');
|
|
8
|
+
require('./chunk-GVLK7YUU.cjs');
|
|
9
|
+
require('./chunk-HE6T6FIX.cjs');
|
|
10
|
+
require('./chunk-4OAT42CA.cjs');
|
|
11
|
+
require('./chunk-Y4Y2S7BM.cjs');
|
|
12
|
+
require('./chunk-URRW6M2C.cjs');
|
|
13
|
+
require('./chunk-G7VZBCD6.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Object.defineProperty(exports, "Event", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunk77MSMAUQ_cjs.Event; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "getEvents", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunk77MSMAUQ_cjs.getEvents; }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "resetEvents", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return chunk77MSMAUQ_cjs.resetEvents; }
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=event.cjs.map
|
|
30
|
+
//# sourceMappingURL=event.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"event.cjs"}
|