autotel-subscribers 13.0.0 → 14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autotel-subscribers",
3
- "version": "13.0.0",
3
+ "version": "14.1.0",
4
4
  "description": "Write Once, Observe Anywhere - Event subscribers for autotel (PostHog, Mixpanel, Amplitude, Segment)",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -82,7 +82,7 @@
82
82
  "author": "Jag Reehal<jag@jagreehal.com> (https://jagreehal.com)",
83
83
  "license": "MIT",
84
84
  "peerDependencies": {
85
- "autotel": "2.9.0"
85
+ "autotel": "2.10.0"
86
86
  },
87
87
  "peerDependenciesMeta": {
88
88
  "posthog-node": {
@@ -99,27 +99,27 @@
99
99
  }
100
100
  },
101
101
  "devDependencies": {
102
- "@amplitude/analytics-node": "^1.5.26",
102
+ "@amplitude/analytics-node": "^1.5.29",
103
103
  "@arethetypeswrong/cli": "^0.18.2",
104
- "@cloudflare/workers-types": "^4.20251126.0",
105
- "@prisma/client": "^7.0.1",
104
+ "@cloudflare/workers-types": "^4.20260103.0",
105
+ "@prisma/client": "^7.2.0",
106
106
  "@segment/analytics-node": "^2.3.0",
107
- "@types/node": "^24.10.1",
108
- "@typescript-eslint/eslint-plugin": "^8.48.0",
109
- "@typescript-eslint/parser": "^8.48.0",
110
- "drizzle-orm": "^0.44.7",
107
+ "@types/node": "^25.0.3",
108
+ "@typescript-eslint/eslint-plugin": "^8.51.0",
109
+ "@typescript-eslint/parser": "^8.51.0",
110
+ "drizzle-orm": "^0.45.1",
111
111
  "eslint-config-prettier": "^10.1.8",
112
112
  "eslint-plugin-unicorn": "^62.0.0",
113
113
  "mixpanel": "^0.19.1",
114
- "mongoose": "^9.0.0",
115
- "posthog-node": "^5.14.0",
116
- "prettier": "^3.6.2",
114
+ "mongoose": "^9.1.1",
115
+ "posthog-node": "^5.18.1",
116
+ "prettier": "^3.7.4",
117
117
  "rimraf": "^6.1.2",
118
118
  "tsup": "^8.5.1",
119
119
  "typescript": "^5.9.3",
120
- "typescript-eslint": "^8.48.0",
121
- "vitest": "^4.0.14",
122
- "autotel": "2.9.0"
120
+ "typescript-eslint": "^8.51.0",
121
+ "vitest": "^4.0.16",
122
+ "autotel": "2.10.0"
123
123
  },
124
124
  "repository": {
125
125
  "type": "git",
@@ -2,26 +2,22 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
2
  import { AmplitudeSubscriber } from './amplitude';
3
3
 
4
4
  // Mock the @amplitude/analytics-node module
5
+ // The SDK exports init(), track(), flush() as separate functions
5
6
  const mockTrack = vi.fn();
6
- const mockTrackEvent = vi.fn();
7
+ const mockInit = vi.fn();
7
8
  const mockFlush = vi.fn(() => Promise.resolve());
8
9
 
9
- // Create a mock init function that returns instances with mocked methods
10
- const mockInit = vi.fn(() => ({
11
- track: mockTrack,
12
- trackEvent: mockTrackEvent,
13
- flush: mockFlush,
14
- }));
15
-
16
10
  vi.mock('@amplitude/analytics-node', () => ({
17
11
  init: mockInit,
12
+ track: mockTrack,
13
+ flush: mockFlush,
18
14
  }));
19
15
 
20
16
  describe('AmplitudeSubscriber', () => {
21
17
  beforeEach(() => {
22
18
  vi.clearAllMocks();
23
19
  mockTrack.mockClear();
24
- mockTrackEvent.mockClear();
20
+ mockInit.mockClear();
25
21
  mockFlush.mockClear();
26
22
  });
27
23
 
@@ -139,7 +135,7 @@ describe('AmplitudeSubscriber', () => {
139
135
 
140
136
  await new Promise((resolve) => setTimeout(resolve, 100));
141
137
 
142
- expect(mockTrackEvent).toHaveBeenCalledWith({
138
+ expect(mockTrack).toHaveBeenCalledWith({
143
139
  event_type: 'checkout.started',
144
140
  user_id: 'user-123',
145
141
  event_properties: {
@@ -167,7 +163,7 @@ describe('AmplitudeSubscriber', () => {
167
163
 
168
164
  await new Promise((resolve) => setTimeout(resolve, 100));
169
165
 
170
- expect(mockTrackEvent).toHaveBeenCalledWith({
166
+ expect(mockTrack).toHaveBeenCalledWith({
171
167
  event_type: 'payment.processing.success',
172
168
  user_id: 'user-123',
173
169
  event_properties: {
@@ -195,7 +191,7 @@ describe('AmplitudeSubscriber', () => {
195
191
 
196
192
  await new Promise((resolve) => setTimeout(resolve, 100));
197
193
 
198
- expect(mockTrackEvent).toHaveBeenCalledWith({
194
+ expect(mockTrack).toHaveBeenCalledWith({
199
195
  event_type: 'revenue',
200
196
  user_id: 'user-123',
201
197
  event_properties: {
package/src/amplitude.ts CHANGED
@@ -38,7 +38,8 @@ export class AmplitudeSubscriber implements EventSubscriber {
38
38
  readonly name = 'AmplitudeSubscriber';
39
39
  readonly version = '1.0.0';
40
40
 
41
- private amplitude: any;
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ private amplitudeModule: any = null;
42
43
  private enabled: boolean;
43
44
  private config: AmplitudeConfig;
44
45
  private initPromise: Promise<void> | null = null;
@@ -55,12 +56,14 @@ export class AmplitudeSubscriber implements EventSubscriber {
55
56
 
56
57
  private async initialize(): Promise<void> {
57
58
  try {
58
- // Dynamic import to avoid adding @amplitude/events-node as a hard dependency
59
- const { init } = await import('@amplitude/analytics-node');
60
- this.amplitude = init(this.config.apiKey);
59
+ // Dynamic import to avoid adding @amplitude/analytics-node as a hard dependency
60
+ // The SDK exports init(), track(), flush() as separate functions
61
+ const amplitude = await import('@amplitude/analytics-node');
62
+ amplitude.init(this.config.apiKey);
63
+ this.amplitudeModule = amplitude;
61
64
  } catch (error) {
62
65
  console.error(
63
- 'Amplitude subscriber failed to initialize. Install @amplitude/events-node: pnpm add @amplitude/events-node',
66
+ 'Amplitude subscriber failed to initialize. Install @amplitude/analytics-node: pnpm add @amplitude/analytics-node',
64
67
  error,
65
68
  );
66
69
  this.enabled = false;
@@ -78,7 +81,7 @@ export class AmplitudeSubscriber implements EventSubscriber {
78
81
  if (!this.enabled) return;
79
82
 
80
83
  await this.ensureInitialized();
81
- this.amplitude?.track({
84
+ this.amplitudeModule?.track({
82
85
  event_type: name,
83
86
  user_id: attributes?.userId || attributes?.user_id || 'anonymous',
84
87
  event_properties: attributes,
@@ -93,7 +96,7 @@ export class AmplitudeSubscriber implements EventSubscriber {
93
96
  if (!this.enabled) return;
94
97
 
95
98
  await this.ensureInitialized();
96
- this.amplitude?.trackEvent({
99
+ this.amplitudeModule?.track({
97
100
  event_type: `${funnelName}.${step}`,
98
101
  user_id: attributes?.userId || attributes?.user_id || 'anonymous',
99
102
  event_properties: {
@@ -112,7 +115,7 @@ export class AmplitudeSubscriber implements EventSubscriber {
112
115
  if (!this.enabled) return;
113
116
 
114
117
  await this.ensureInitialized();
115
- this.amplitude?.trackEvent({
118
+ this.amplitudeModule?.track({
116
119
  event_type: `${operationName}.${outcome}`,
117
120
  user_id: attributes?.userId || attributes?.user_id || 'anonymous',
118
121
  event_properties: {
@@ -127,7 +130,7 @@ export class AmplitudeSubscriber implements EventSubscriber {
127
130
  if (!this.enabled) return;
128
131
 
129
132
  await this.ensureInitialized();
130
- this.amplitude?.trackEvent({
133
+ this.amplitudeModule?.track({
131
134
  event_type: name,
132
135
  user_id: attributes?.userId || attributes?.user_id || 'anonymous',
133
136
  event_properties: {
@@ -140,8 +143,8 @@ export class AmplitudeSubscriber implements EventSubscriber {
140
143
  /** Flush pending events before shutdown */
141
144
  async shutdown(): Promise<void> {
142
145
  await this.ensureInitialized();
143
- if (this.amplitude) {
144
- await this.amplitude.flush();
146
+ if (this.amplitudeModule) {
147
+ await this.amplitudeModule.flush();
145
148
  }
146
149
  }
147
150
  }