@walkeros/server-destination-amplitude 3.3.0-next-1776098542393

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,418 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/examples/env.ts
8
+ var env_exports = {};
9
+ __export(env_exports, {
10
+ init: () => init,
11
+ push: () => push,
12
+ simulation: () => simulation
13
+ });
14
+ var noop = () => {
15
+ };
16
+ var noopPromise = () => ({ promise: Promise.resolve() });
17
+ var MockIdentify = class {
18
+ set() {
19
+ return this;
20
+ }
21
+ setOnce() {
22
+ return this;
23
+ }
24
+ add() {
25
+ return this;
26
+ }
27
+ append() {
28
+ return this;
29
+ }
30
+ prepend() {
31
+ return this;
32
+ }
33
+ preInsert() {
34
+ return this;
35
+ }
36
+ postInsert() {
37
+ return this;
38
+ }
39
+ remove() {
40
+ return this;
41
+ }
42
+ unset() {
43
+ return this;
44
+ }
45
+ clearAll() {
46
+ return this;
47
+ }
48
+ };
49
+ var MockRevenue = class {
50
+ setProductId() {
51
+ return this;
52
+ }
53
+ setPrice() {
54
+ return this;
55
+ }
56
+ setQuantity() {
57
+ return this;
58
+ }
59
+ setRevenueType() {
60
+ return this;
61
+ }
62
+ setCurrency() {
63
+ return this;
64
+ }
65
+ setRevenue() {
66
+ return this;
67
+ }
68
+ setReceipt() {
69
+ return this;
70
+ }
71
+ setReceiptSig() {
72
+ return this;
73
+ }
74
+ setEventProperties() {
75
+ return this;
76
+ }
77
+ };
78
+ var init = {
79
+ amplitude: {
80
+ init: noopPromise,
81
+ track: noop,
82
+ identify: noop,
83
+ revenue: noop,
84
+ setOptOut: noop,
85
+ setGroup: noop,
86
+ groupIdentify: noop,
87
+ flush: noopPromise,
88
+ Identify: MockIdentify,
89
+ Revenue: MockRevenue
90
+ }
91
+ };
92
+ var push = {
93
+ amplitude: {
94
+ init: noopPromise,
95
+ track: noop,
96
+ identify: noop,
97
+ revenue: noop,
98
+ setOptOut: noop,
99
+ setGroup: noop,
100
+ groupIdentify: noop,
101
+ flush: noopPromise,
102
+ Identify: MockIdentify,
103
+ Revenue: MockRevenue
104
+ }
105
+ };
106
+ var simulation = [
107
+ "call:amplitude.init",
108
+ "call:amplitude.track",
109
+ "call:amplitude.identify",
110
+ "call:amplitude.revenue",
111
+ "call:amplitude.setOptOut",
112
+ "call:amplitude.setGroup",
113
+ "call:amplitude.groupIdentify"
114
+ ];
115
+
116
+ // src/examples/step.ts
117
+ var step_exports = {};
118
+ __export(step_exports, {
119
+ consentGrantOptIn: () => consentGrantOptIn,
120
+ consentRevokeOptOut: () => consentRevokeOptOut,
121
+ defaultEventForwarding: () => defaultEventForwarding,
122
+ destinationLevelIdentify: () => destinationLevelIdentify,
123
+ destinationLevelInclude: () => destinationLevelInclude,
124
+ eventOptionsTimeInsertId: () => eventOptionsTimeInsertId,
125
+ groupAssignmentWithProperties: () => groupAssignmentWithProperties,
126
+ orderCompleteMultiProduct: () => orderCompleteMultiProduct,
127
+ subscriptionRenewRevenue: () => subscriptionRenewRevenue,
128
+ userLoginIdentify: () => userLoginIdentify,
129
+ wildcardIgnored: () => wildcardIgnored
130
+ });
131
+ import { getEvent } from "@walkeros/core";
132
+ var defaultEventForwarding = {
133
+ in: getEvent("product view", { timestamp: 1700000100 }),
134
+ out: ["amplitude.track", "product view", {}]
135
+ };
136
+ var wildcardIgnored = {
137
+ in: getEvent("debug noise", { timestamp: 1700000101 }),
138
+ mapping: { ignore: true },
139
+ out: []
140
+ };
141
+ var destinationLevelInclude = {
142
+ in: getEvent("product view", { timestamp: 1700000102 }),
143
+ configInclude: ["data"],
144
+ out: [
145
+ "amplitude.track",
146
+ "product view",
147
+ {
148
+ data_id: "ers",
149
+ data_name: "Everyday Ruck Snack",
150
+ data_color: "black",
151
+ data_size: "l",
152
+ data_price: 420
153
+ }
154
+ ]
155
+ };
156
+ var destinationLevelIdentify = {
157
+ in: getEvent("page view", { timestamp: 1700000104 }),
158
+ settings: {
159
+ identify: {
160
+ map: {
161
+ user_id: "user.id",
162
+ device_id: "user.device",
163
+ session_id: "user.session"
164
+ }
165
+ }
166
+ },
167
+ out: [
168
+ "amplitude.track",
169
+ "page view",
170
+ {},
171
+ {
172
+ user_id: "us3r",
173
+ device_id: "c00k13",
174
+ session_id: 394324160
175
+ }
176
+ ]
177
+ };
178
+ var userLoginIdentify = {
179
+ in: getEvent("user login", {
180
+ timestamp: 1700000105,
181
+ data: {
182
+ user_id: "new-user-123",
183
+ plan: "premium",
184
+ company: "Acme",
185
+ email: "user@acme.com"
186
+ }
187
+ }),
188
+ mapping: {
189
+ skip: true,
190
+ settings: {
191
+ identify: {
192
+ map: {
193
+ user_id: "data.user_id",
194
+ set: {
195
+ map: {
196
+ plan: "data.plan",
197
+ company: "data.company",
198
+ email: "data.email"
199
+ }
200
+ },
201
+ setOnce: {
202
+ map: {
203
+ first_login: "timestamp"
204
+ }
205
+ },
206
+ add: {
207
+ map: {
208
+ login_count: { value: 1 }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ },
215
+ out: [
216
+ "amplitude.identify",
217
+ {
218
+ set: {
219
+ plan: "premium",
220
+ company: "Acme",
221
+ email: "user@acme.com"
222
+ },
223
+ setOnce: {
224
+ first_login: 1700000105
225
+ },
226
+ add: {
227
+ login_count: 1
228
+ }
229
+ },
230
+ {
231
+ user_id: "new-user-123"
232
+ }
233
+ ]
234
+ };
235
+ var subscriptionRenewRevenue = {
236
+ in: getEvent("subscription renew", {
237
+ timestamp: 1700000107,
238
+ data: {
239
+ plan_id: "plan-pro",
240
+ amount: 9.99
241
+ }
242
+ }),
243
+ mapping: {
244
+ skip: true,
245
+ settings: {
246
+ revenue: {
247
+ map: {
248
+ productId: "data.plan_id",
249
+ price: "data.amount",
250
+ revenueType: { value: "renewal" },
251
+ currency: { key: "data.currency", value: "EUR" }
252
+ }
253
+ }
254
+ }
255
+ },
256
+ out: [
257
+ "amplitude.revenue",
258
+ {
259
+ productId: "plan-pro",
260
+ price: 9.99,
261
+ revenueType: "renewal",
262
+ currency: "EUR"
263
+ }
264
+ ]
265
+ };
266
+ var orderCompleteMultiProduct = {
267
+ in: getEvent("order complete", { timestamp: 1700000108 }),
268
+ mapping: {
269
+ include: ["data", "globals"],
270
+ settings: {
271
+ revenue: {
272
+ loop: [
273
+ "nested",
274
+ {
275
+ condition: (value) => {
276
+ var _a;
277
+ const v = value;
278
+ return typeof ((_a = v == null ? void 0 : v.data) == null ? void 0 : _a.price) === "number";
279
+ },
280
+ map: {
281
+ productId: "data.id",
282
+ price: "data.price",
283
+ quantity: { key: "data.quantity", value: 1 },
284
+ revenueType: { value: "purchase" },
285
+ currency: { key: "data.currency", value: "EUR" }
286
+ }
287
+ }
288
+ ]
289
+ }
290
+ }
291
+ },
292
+ out: [
293
+ [
294
+ "amplitude.revenue",
295
+ {
296
+ productId: "ers",
297
+ price: 420,
298
+ quantity: 1,
299
+ revenueType: "purchase",
300
+ currency: "EUR"
301
+ }
302
+ ],
303
+ [
304
+ "amplitude.revenue",
305
+ {
306
+ productId: "cc",
307
+ price: 42,
308
+ quantity: 1,
309
+ revenueType: "purchase",
310
+ currency: "EUR"
311
+ }
312
+ ],
313
+ [
314
+ "amplitude.track",
315
+ "order complete",
316
+ {
317
+ data_id: "0rd3r1d",
318
+ data_currency: "EUR",
319
+ data_shipping: 5.22,
320
+ data_taxes: 73.76,
321
+ data_total: 555,
322
+ globals_pagegroup: "shop"
323
+ }
324
+ ]
325
+ ]
326
+ };
327
+ var groupAssignmentWithProperties = {
328
+ in: getEvent("company update", {
329
+ timestamp: 1700000109,
330
+ data: {
331
+ company: "Acme",
332
+ industry: "tech",
333
+ employee_count: 50,
334
+ founded_year: 2020
335
+ }
336
+ }),
337
+ mapping: {
338
+ skip: true,
339
+ settings: {
340
+ group: {
341
+ map: {
342
+ type: { value: "company" },
343
+ name: "data.company"
344
+ }
345
+ },
346
+ groupIdentify: {
347
+ map: {
348
+ type: { value: "company" },
349
+ name: "data.company",
350
+ set: {
351
+ map: {
352
+ industry: "data.industry",
353
+ size: "data.employee_count"
354
+ }
355
+ },
356
+ setOnce: {
357
+ map: {
358
+ founded: "data.founded_year"
359
+ }
360
+ }
361
+ }
362
+ }
363
+ }
364
+ },
365
+ out: [
366
+ ["amplitude.setGroup", "company", "Acme"],
367
+ [
368
+ "amplitude.groupIdentify",
369
+ "company",
370
+ "Acme",
371
+ {
372
+ set: {
373
+ industry: "tech",
374
+ size: 50
375
+ },
376
+ setOnce: {
377
+ founded: 2020
378
+ }
379
+ }
380
+ ]
381
+ ]
382
+ };
383
+ var eventOptionsTimeInsertId = {
384
+ in: getEvent("page view", { timestamp: 1700000110 }),
385
+ settings: {
386
+ eventOptions: {
387
+ map: {
388
+ time: "timestamp",
389
+ insert_id: "id"
390
+ }
391
+ }
392
+ },
393
+ out: [
394
+ "amplitude.track",
395
+ "page view",
396
+ {},
397
+ {
398
+ time: 1700000110,
399
+ insert_id: "1700000110-gr0up-1"
400
+ }
401
+ ]
402
+ };
403
+ var consentRevokeOptOut = {
404
+ command: "consent",
405
+ in: { analytics: false },
406
+ settings: {},
407
+ out: ["amplitude.setOptOut", true]
408
+ };
409
+ var consentGrantOptIn = {
410
+ command: "consent",
411
+ in: { analytics: true },
412
+ settings: {},
413
+ out: ["amplitude.setOptOut", false]
414
+ };
415
+ export {
416
+ env_exports as env,
417
+ step_exports as step
418
+ };
@@ -0,0 +1,167 @@
1
+ import { Mapping as Mapping$1, Destination as Destination$1 } from '@walkeros/core';
2
+ import { DestinationServer } from '@walkeros/server-core';
3
+
4
+ /**
5
+ * Amplitude SDK surface -- the subset of @amplitude/analytics-node the
6
+ * destination actually uses. Tests provide a mock via env.amplitude;
7
+ * production uses the real SDK import.
8
+ *
9
+ * Key difference from web: no setUserId/setDeviceId/setSessionId.
10
+ * Identity is per-event via EventOptions on every SDK call.
11
+ */
12
+ interface AmplitudeSDK {
13
+ init: (apiKey: string, options?: Record<string, unknown>) => {
14
+ promise: Promise<void>;
15
+ };
16
+ track: (eventType: string, eventProperties?: Record<string, unknown>, eventOptions?: EventOptions) => void;
17
+ identify: (identify: IdentifyInstance, eventOptions?: EventOptions) => void;
18
+ revenue: (revenue: RevenueInstance, eventOptions?: EventOptions) => void;
19
+ setGroup: (groupType: string, groupName: string | string[], eventOptions?: EventOptions) => void;
20
+ groupIdentify: (groupType: string, groupName: string, identify: IdentifyInstance, eventOptions?: EventOptions) => void;
21
+ setOptOut: (optOut: boolean) => void;
22
+ flush: () => {
23
+ promise: Promise<void>;
24
+ };
25
+ Identify: new () => IdentifyInstance;
26
+ Revenue: new () => RevenueInstance;
27
+ }
28
+ /**
29
+ * Per-event identity and metadata fields. Passed to every SDK call.
30
+ * Maps directly to Amplitude's EventOptions type from the Node SDK.
31
+ */
32
+ interface EventOptions {
33
+ user_id?: string;
34
+ device_id?: string;
35
+ session_id?: number;
36
+ time?: number;
37
+ insert_id?: string;
38
+ ip?: string;
39
+ city?: string;
40
+ country?: string;
41
+ region?: string;
42
+ language?: string;
43
+ platform?: string;
44
+ os_name?: string;
45
+ os_version?: string;
46
+ device_brand?: string;
47
+ device_manufacturer?: string;
48
+ device_model?: string;
49
+ app_version?: string;
50
+ carrier?: string;
51
+ user_agent?: string;
52
+ groups?: Record<string, unknown>;
53
+ plan?: Record<string, unknown>;
54
+ ingestion_metadata?: Record<string, unknown>;
55
+ partner_id?: string;
56
+ extra?: Record<string, unknown>;
57
+ }
58
+ /** Chainable Identify -- mirrors @amplitude/analytics-node Identify class. */
59
+ interface IdentifyInstance {
60
+ set: (property: string, value: unknown) => IdentifyInstance;
61
+ setOnce: (property: string, value: unknown) => IdentifyInstance;
62
+ add: (property: string, value: number) => IdentifyInstance;
63
+ append: (property: string, value: unknown) => IdentifyInstance;
64
+ prepend: (property: string, value: unknown) => IdentifyInstance;
65
+ preInsert: (property: string, value: unknown) => IdentifyInstance;
66
+ postInsert: (property: string, value: unknown) => IdentifyInstance;
67
+ remove: (property: string, value: unknown) => IdentifyInstance;
68
+ unset: (property: string) => IdentifyInstance;
69
+ clearAll: () => IdentifyInstance;
70
+ }
71
+ /** Chainable Revenue -- mirrors @amplitude/analytics-node Revenue class. */
72
+ interface RevenueInstance {
73
+ setProductId: (id: string) => RevenueInstance;
74
+ setPrice: (price: number) => RevenueInstance;
75
+ setQuantity: (quantity: number) => RevenueInstance;
76
+ setRevenueType: (type: string) => RevenueInstance;
77
+ setCurrency: (currency: string) => RevenueInstance;
78
+ setRevenue: (revenue: number) => RevenueInstance;
79
+ setReceipt: (receipt: string) => RevenueInstance;
80
+ setReceiptSig: (signature: string) => RevenueInstance;
81
+ setEventProperties: (properties: Record<string, unknown>) => RevenueInstance;
82
+ }
83
+ /**
84
+ * Destination-level settings. apiKey is required; all other fields
85
+ * are optional and passed through to the Amplitude Node SDK init().
86
+ */
87
+ interface Settings {
88
+ apiKey: string;
89
+ serverZone?: 'US' | 'EU';
90
+ flushIntervalMillis?: number;
91
+ flushQueueSize?: number;
92
+ flushMaxRetries?: number;
93
+ useBatch?: boolean;
94
+ minIdLength?: number;
95
+ serverUrl?: string;
96
+ logLevel?: number;
97
+ optOut?: boolean;
98
+ offline?: boolean;
99
+ enableRequestBodyCompression?: boolean;
100
+ plan?: Record<string, unknown>;
101
+ ingestionMetadata?: Record<string, unknown>;
102
+ /** walkerOS mapping value for per-event identity resolution. */
103
+ identify?: Mapping$1.Value;
104
+ /** walkerOS mapping value for per-event EventOptions (time, insert_id, ip, etc). */
105
+ eventOptions?: Mapping$1.Value;
106
+ /** Sections to include as event_properties (e.g., ['data', 'globals']). */
107
+ include?: string[];
108
+ }
109
+ type InitSettings = Partial<Settings>;
110
+ /**
111
+ * Per-rule mapping settings. Each is a walkerOS mapping value resolved
112
+ * via getMappingValue(). Revenue supports loop for multi-item orders.
113
+ */
114
+ interface Mapping {
115
+ identify?: Mapping$1.Value;
116
+ revenue?: Mapping$1.Value;
117
+ group?: Mapping$1.Value;
118
+ groupIdentify?: Mapping$1.Value;
119
+ eventOptions?: Mapping$1.Value;
120
+ include?: string[];
121
+ }
122
+ /**
123
+ * Env -- optional SDK override. Production leaves this undefined and the
124
+ * destination falls back to the real @amplitude/analytics-node import.
125
+ * Tests provide a mock via env.amplitude.
126
+ */
127
+ interface Env extends DestinationServer.Env {
128
+ amplitude?: AmplitudeSDK;
129
+ }
130
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
131
+ interface Destination extends DestinationServer.Destination<Types> {
132
+ init: DestinationServer.InitFn<Types>;
133
+ }
134
+ type Config = {
135
+ settings: Settings;
136
+ } & DestinationServer.Config<Types>;
137
+ type InitFn = DestinationServer.InitFn<Types>;
138
+ type PushFn = DestinationServer.PushFn<Types>;
139
+ type PartialConfig = DestinationServer.PartialConfig<Types>;
140
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
141
+ type Rule = Mapping$1.Rule<Mapping>;
142
+ type Rules = Mapping$1.Rules<Rule>;
143
+
144
+ type index_AmplitudeSDK = AmplitudeSDK;
145
+ type index_Config = Config;
146
+ type index_Destination = Destination;
147
+ type index_Env = Env;
148
+ type index_EventOptions = EventOptions;
149
+ type index_IdentifyInstance = IdentifyInstance;
150
+ type index_InitFn = InitFn;
151
+ type index_InitSettings = InitSettings;
152
+ type index_Mapping = Mapping;
153
+ type index_PartialConfig = PartialConfig;
154
+ type index_PushEvents = PushEvents;
155
+ type index_PushFn = PushFn;
156
+ type index_RevenueInstance = RevenueInstance;
157
+ type index_Rule = Rule;
158
+ type index_Rules = Rules;
159
+ type index_Settings = Settings;
160
+ type index_Types = Types;
161
+ declare namespace index {
162
+ export type { index_AmplitudeSDK as AmplitudeSDK, index_Config as Config, index_Destination as Destination, index_Env as Env, index_EventOptions as EventOptions, index_IdentifyInstance as IdentifyInstance, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RevenueInstance as RevenueInstance, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
163
+ }
164
+
165
+ declare const destinationAmplitude: Destination;
166
+
167
+ export { index as DestinationAmplitude, destinationAmplitude as default, destinationAmplitude };