autotel-subscribers 52.0.0 → 53.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.
@@ -0,0 +1,150 @@
1
+
2
+ //#region src/mock-event-subscriber.ts
3
+ /**
4
+ * Mock subscriber for testing
5
+ *
6
+ * Captures all events calls in memory for test assertions.
7
+ * Does not make any real API calls.
8
+ */
9
+ var MockEventSubscriber = class {
10
+ name = "MockEventSubscriber";
11
+ version = "1.0.0";
12
+ /**
13
+ * All captured events
14
+ */
15
+ events = [];
16
+ /**
17
+ * Track if shutdown was called
18
+ */
19
+ shutdownCalled = false;
20
+ async trackEvent(name, attributes) {
21
+ this.events.push({
22
+ type: "event",
23
+ name,
24
+ attributes,
25
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
26
+ });
27
+ }
28
+ async trackFunnelStep(funnelName, step, attributes) {
29
+ this.events.push({
30
+ type: "funnel",
31
+ name: `${funnelName}.${step}`,
32
+ funnel: funnelName,
33
+ step,
34
+ attributes,
35
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
36
+ });
37
+ }
38
+ async trackOutcome(operationName, outcome, attributes) {
39
+ this.events.push({
40
+ type: "outcome",
41
+ name: `${operationName}.${outcome}`,
42
+ operation: operationName,
43
+ outcome,
44
+ attributes,
45
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
46
+ });
47
+ }
48
+ async trackValue(name, value, attributes) {
49
+ this.events.push({
50
+ type: "value",
51
+ name,
52
+ value,
53
+ attributes,
54
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
55
+ });
56
+ }
57
+ async shutdown() {
58
+ this.shutdownCalled = true;
59
+ }
60
+ /**
61
+ * Reset captured events (useful between tests)
62
+ */
63
+ reset() {
64
+ this.events = [];
65
+ this.shutdownCalled = false;
66
+ }
67
+ /**
68
+ * Get events by type
69
+ */
70
+ getEventsByType(type) {
71
+ return this.events.filter((e) => e.type === type);
72
+ }
73
+ /**
74
+ * Get events by name
75
+ */
76
+ getEventsByName(name) {
77
+ return this.events.filter((e) => e.name === name);
78
+ }
79
+ /**
80
+ * Get funnel events for a specific funnel
81
+ */
82
+ getFunnelEvents(funnelName) {
83
+ return this.events.filter((e) => e.type === "funnel" && e.funnel === funnelName);
84
+ }
85
+ /**
86
+ * Get outcome events for a specific operation
87
+ */
88
+ getOutcomeEvents(operationName) {
89
+ return this.events.filter((e) => e.type === "outcome" && e.operation === operationName);
90
+ }
91
+ /**
92
+ * Get value events by metric name
93
+ */
94
+ getValueEvents(metricName) {
95
+ return this.events.filter((e) => e.type === "value" && e.name === metricName);
96
+ }
97
+ /**
98
+ * Assert that an event was tracked
99
+ */
100
+ assertEventTracked(name, attributes) {
101
+ const events = this.getEventsByName(name);
102
+ if (events.length === 0) throw new Error(`No events found with name: ${name}`);
103
+ if (attributes) {
104
+ if (!events.find((event) => {
105
+ if (!event.attributes) return false;
106
+ return Object.entries(attributes).every(([key, value]) => event.attributes[key] === value);
107
+ })) throw new Error(`Event "${name}" found, but no matching attributes: ${JSON.stringify(attributes)}`);
108
+ }
109
+ }
110
+ /**
111
+ * Assert that a funnel step was tracked
112
+ */
113
+ assertFunnelStepTracked(funnelName, step, attributes) {
114
+ const matchingEvent = this.getFunnelEvents(funnelName).find((e) => e.step === step);
115
+ if (!matchingEvent) throw new Error(`Funnel "${funnelName}" step "${step}" was not tracked`);
116
+ if (attributes) {
117
+ if (!Object.entries(attributes).every(([key, value]) => matchingEvent.attributes?.[key] === value)) throw new Error(`Funnel step tracked, but attributes don't match: ${JSON.stringify(attributes)}`);
118
+ }
119
+ }
120
+ /**
121
+ * Assert that an outcome was tracked
122
+ */
123
+ assertOutcomeTracked(operationName, outcome, attributes) {
124
+ const matchingEvent = this.getOutcomeEvents(operationName).find((e) => e.outcome === outcome);
125
+ if (!matchingEvent) throw new Error(`Outcome "${operationName}.${outcome}" was not tracked`);
126
+ if (attributes) {
127
+ if (!Object.entries(attributes).every(([key, value]) => matchingEvent.attributes?.[key] === value)) throw new Error(`Outcome tracked, but attributes don't match: ${JSON.stringify(attributes)}`);
128
+ }
129
+ }
130
+ /**
131
+ * Pretty print all captured events (useful for debugging)
132
+ */
133
+ printEvents() {
134
+ console.log(`\n[${this.name}] Captured ${this.events.length} events:\n`);
135
+ for (const [index, event] of this.events.entries()) {
136
+ console.log(`${index + 1}. [${event.type}] ${event.name}`);
137
+ if (event.attributes) console.log(` Attributes:`, event.attributes);
138
+ if (event.value !== void 0) console.log(` Value: ${event.value}`);
139
+ console.log(` Timestamp: ${event.timestamp}\n`);
140
+ }
141
+ }
142
+ };
143
+
144
+ //#endregion
145
+ Object.defineProperty(exports, 'MockEventSubscriber', {
146
+ enumerable: true,
147
+ get: function () {
148
+ return MockEventSubscriber;
149
+ }
150
+ });
@@ -0,0 +1,81 @@
1
+ import { EventAttributes, EventSubscriber, FunnelStatus, OutcomeStatus } from "autotel/event-subscriber";
2
+ //#region src/mock-event-subscriber.d.ts
3
+ /**
4
+ * Captured event data
5
+ */
6
+ interface CapturedEvent {
7
+ type: 'event' | 'funnel' | 'outcome' | 'value';
8
+ name: string;
9
+ attributes?: EventAttributes;
10
+ funnel?: string;
11
+ step?: FunnelStatus;
12
+ operation?: string;
13
+ outcome?: OutcomeStatus;
14
+ value?: number;
15
+ timestamp: string;
16
+ }
17
+ /**
18
+ * Mock subscriber for testing
19
+ *
20
+ * Captures all events calls in memory for test assertions.
21
+ * Does not make any real API calls.
22
+ */
23
+ declare class MockEventSubscriber implements EventSubscriber {
24
+ readonly name = "MockEventSubscriber";
25
+ readonly version = "1.0.0";
26
+ /**
27
+ * All captured events
28
+ */
29
+ events: CapturedEvent[];
30
+ /**
31
+ * Track if shutdown was called
32
+ */
33
+ shutdownCalled: boolean;
34
+ trackEvent(name: string, attributes?: EventAttributes): Promise<void>;
35
+ trackFunnelStep(funnelName: string, step: FunnelStatus, attributes?: EventAttributes): Promise<void>;
36
+ trackOutcome(operationName: string, outcome: OutcomeStatus, attributes?: EventAttributes): Promise<void>;
37
+ trackValue(name: string, value: number, attributes?: EventAttributes): Promise<void>;
38
+ shutdown(): Promise<void>;
39
+ /**
40
+ * Reset captured events (useful between tests)
41
+ */
42
+ reset(): void;
43
+ /**
44
+ * Get events by type
45
+ */
46
+ getEventsByType(type: 'event' | 'funnel' | 'outcome' | 'value'): CapturedEvent[];
47
+ /**
48
+ * Get events by name
49
+ */
50
+ getEventsByName(name: string): CapturedEvent[];
51
+ /**
52
+ * Get funnel events for a specific funnel
53
+ */
54
+ getFunnelEvents(funnelName: string): CapturedEvent[];
55
+ /**
56
+ * Get outcome events for a specific operation
57
+ */
58
+ getOutcomeEvents(operationName: string): CapturedEvent[];
59
+ /**
60
+ * Get value events by metric name
61
+ */
62
+ getValueEvents(metricName: string): CapturedEvent[];
63
+ /**
64
+ * Assert that an event was tracked
65
+ */
66
+ assertEventTracked(name: string, attributes?: Partial<EventAttributes>): void;
67
+ /**
68
+ * Assert that a funnel step was tracked
69
+ */
70
+ assertFunnelStepTracked(funnelName: string, step: FunnelStatus, attributes?: Partial<EventAttributes>): void;
71
+ /**
72
+ * Assert that an outcome was tracked
73
+ */
74
+ assertOutcomeTracked(operationName: string, outcome: OutcomeStatus, attributes?: Partial<EventAttributes>): void;
75
+ /**
76
+ * Pretty print all captured events (useful for debugging)
77
+ */
78
+ printEvents(): void;
79
+ }
80
+ //#endregion
81
+ export { MockEventSubscriber as t };
@@ -0,0 +1,81 @@
1
+ import { EventAttributes, EventSubscriber, FunnelStatus, OutcomeStatus } from "autotel/event-subscriber";
2
+ //#region src/mock-event-subscriber.d.ts
3
+ /**
4
+ * Captured event data
5
+ */
6
+ interface CapturedEvent {
7
+ type: 'event' | 'funnel' | 'outcome' | 'value';
8
+ name: string;
9
+ attributes?: EventAttributes;
10
+ funnel?: string;
11
+ step?: FunnelStatus;
12
+ operation?: string;
13
+ outcome?: OutcomeStatus;
14
+ value?: number;
15
+ timestamp: string;
16
+ }
17
+ /**
18
+ * Mock subscriber for testing
19
+ *
20
+ * Captures all events calls in memory for test assertions.
21
+ * Does not make any real API calls.
22
+ */
23
+ declare class MockEventSubscriber implements EventSubscriber {
24
+ readonly name = "MockEventSubscriber";
25
+ readonly version = "1.0.0";
26
+ /**
27
+ * All captured events
28
+ */
29
+ events: CapturedEvent[];
30
+ /**
31
+ * Track if shutdown was called
32
+ */
33
+ shutdownCalled: boolean;
34
+ trackEvent(name: string, attributes?: EventAttributes): Promise<void>;
35
+ trackFunnelStep(funnelName: string, step: FunnelStatus, attributes?: EventAttributes): Promise<void>;
36
+ trackOutcome(operationName: string, outcome: OutcomeStatus, attributes?: EventAttributes): Promise<void>;
37
+ trackValue(name: string, value: number, attributes?: EventAttributes): Promise<void>;
38
+ shutdown(): Promise<void>;
39
+ /**
40
+ * Reset captured events (useful between tests)
41
+ */
42
+ reset(): void;
43
+ /**
44
+ * Get events by type
45
+ */
46
+ getEventsByType(type: 'event' | 'funnel' | 'outcome' | 'value'): CapturedEvent[];
47
+ /**
48
+ * Get events by name
49
+ */
50
+ getEventsByName(name: string): CapturedEvent[];
51
+ /**
52
+ * Get funnel events for a specific funnel
53
+ */
54
+ getFunnelEvents(funnelName: string): CapturedEvent[];
55
+ /**
56
+ * Get outcome events for a specific operation
57
+ */
58
+ getOutcomeEvents(operationName: string): CapturedEvent[];
59
+ /**
60
+ * Get value events by metric name
61
+ */
62
+ getValueEvents(metricName: string): CapturedEvent[];
63
+ /**
64
+ * Assert that an event was tracked
65
+ */
66
+ assertEventTracked(name: string, attributes?: Partial<EventAttributes>): void;
67
+ /**
68
+ * Assert that a funnel step was tracked
69
+ */
70
+ assertFunnelStepTracked(funnelName: string, step: FunnelStatus, attributes?: Partial<EventAttributes>): void;
71
+ /**
72
+ * Assert that an outcome was tracked
73
+ */
74
+ assertOutcomeTracked(operationName: string, outcome: OutcomeStatus, attributes?: Partial<EventAttributes>): void;
75
+ /**
76
+ * Pretty print all captured events (useful for debugging)
77
+ */
78
+ printEvents(): void;
79
+ }
80
+ //#endregion
81
+ export { MockEventSubscriber as t };