@walkeros/server-destination-rudderstack 4.8.1 → 4.8.3-next-1793115089237
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/CHANGELOG.md +56 -3
- package/README.md +7 -3
- package/dist/dev.d.mts +49 -12
- package/dist/dev.d.ts +49 -12
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/examples/index.d.mts +46 -11
- package/dist/examples/index.d.ts +46 -11
- package/dist/examples/index.js +117 -34
- package/dist/examples/index.mjs +117 -35
- package/dist/index.d.mts +19 -10
- package/dist/index.d.ts +19 -10
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/walkerOS.json +271 -41
- package/package.json +4 -4
package/dist/examples/index.mjs
CHANGED
|
@@ -10,17 +10,16 @@ __export(env_exports, {
|
|
|
10
10
|
push: () => push,
|
|
11
11
|
simulation: () => simulation
|
|
12
12
|
});
|
|
13
|
-
var
|
|
14
|
-
};
|
|
13
|
+
var sent = (_params, callback) => callback?.();
|
|
15
14
|
var asyncNoop = () => Promise.resolve();
|
|
16
15
|
function createMockAnalytics() {
|
|
17
16
|
return {
|
|
18
|
-
track:
|
|
19
|
-
identify:
|
|
20
|
-
group:
|
|
21
|
-
page:
|
|
22
|
-
screen:
|
|
23
|
-
alias:
|
|
17
|
+
track: sent,
|
|
18
|
+
identify: sent,
|
|
19
|
+
group: sent,
|
|
20
|
+
page: sent,
|
|
21
|
+
screen: sent,
|
|
22
|
+
alias: sent,
|
|
24
23
|
flush: asyncNoop
|
|
25
24
|
};
|
|
26
25
|
}
|
|
@@ -42,31 +41,42 @@ __export(step_exports, {
|
|
|
42
41
|
aliasUser: () => aliasUser,
|
|
43
42
|
anonymousOnly: () => anonymousOnly,
|
|
44
43
|
companyGroup: () => companyGroup,
|
|
44
|
+
companyGroupWithoutData: () => companyGroupWithoutData,
|
|
45
45
|
defaultTrack: () => defaultTrack,
|
|
46
46
|
destinationIdentify: () => destinationIdentify,
|
|
47
47
|
mappedEventName: () => mappedEventName,
|
|
48
|
+
noIdentityCompany: () => noIdentityCompany,
|
|
49
|
+
noIdentityLogin: () => noIdentityLogin,
|
|
50
|
+
noIdentityMerge: () => noIdentityMerge,
|
|
51
|
+
noIdentityOrder: () => noIdentityOrder,
|
|
52
|
+
noIdentityPage: () => noIdentityPage,
|
|
53
|
+
noIdentityProduct: () => noIdentityProduct,
|
|
54
|
+
noIdentityScreen: () => noIdentityScreen,
|
|
48
55
|
pageView: () => pageView,
|
|
49
56
|
screenView: () => screenView,
|
|
57
|
+
silentRule: () => silentRule,
|
|
50
58
|
userLoginIdentify: () => userLoginIdentify,
|
|
51
59
|
wildcardIgnored: () => wildcardIgnored
|
|
52
60
|
});
|
|
53
|
-
import { getEvent } from "@walkeros/core";
|
|
61
|
+
import { createEvent, getEvent } from "@walkeros/core";
|
|
54
62
|
var defaultTrack = {
|
|
55
63
|
title: "Default track",
|
|
56
64
|
description: "A walker event becomes a RudderStack analytics.track call with userId and anonymousId resolved from the event.",
|
|
57
65
|
in: getEvent("product view", {
|
|
58
|
-
|
|
66
|
+
id: "ev1700000100",
|
|
67
|
+
timestamp: 17000001e5,
|
|
59
68
|
user: { id: "us3r", session: "s3ss10n" }
|
|
60
69
|
}),
|
|
61
70
|
out: [
|
|
62
71
|
[
|
|
63
72
|
"analytics.track",
|
|
64
73
|
{
|
|
74
|
+
messageId: "ev1700000100",
|
|
65
75
|
userId: "us3r",
|
|
66
76
|
anonymousId: "s3ss10n",
|
|
67
77
|
event: "product view",
|
|
68
78
|
properties: {},
|
|
69
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
79
|
+
timestamp: /* @__PURE__ */ new Date(17000001e5)
|
|
70
80
|
}
|
|
71
81
|
]
|
|
72
82
|
]
|
|
@@ -75,7 +85,8 @@ var mappedEventName = {
|
|
|
75
85
|
title: "Renamed event",
|
|
76
86
|
description: "A mapping renames the event so the RudderStack track call uses a canonical name such as Order Completed.",
|
|
77
87
|
in: getEvent("order complete", {
|
|
78
|
-
|
|
88
|
+
id: "ev1700000101",
|
|
89
|
+
timestamp: 1700000101e3,
|
|
79
90
|
user: { id: "us3r", session: "s3ss10n" }
|
|
80
91
|
}),
|
|
81
92
|
mapping: {
|
|
@@ -85,20 +96,22 @@ var mappedEventName = {
|
|
|
85
96
|
[
|
|
86
97
|
"analytics.track",
|
|
87
98
|
{
|
|
99
|
+
messageId: "ev1700000101",
|
|
88
100
|
userId: "us3r",
|
|
89
101
|
anonymousId: "s3ss10n",
|
|
90
102
|
event: "Order Completed",
|
|
91
103
|
properties: {},
|
|
92
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
104
|
+
timestamp: /* @__PURE__ */ new Date(1700000101e3)
|
|
93
105
|
}
|
|
94
106
|
]
|
|
95
107
|
]
|
|
96
108
|
};
|
|
97
109
|
var destinationIdentify = {
|
|
98
110
|
title: "Destination identify",
|
|
99
|
-
description: "
|
|
111
|
+
description: "With settings.identify mapping the email trait to 'user.email', the first push fires analytics.identify with the traits before the track call. Later pushes repeat it only when the userId or traits differ.",
|
|
100
112
|
in: getEvent("page view", {
|
|
101
|
-
|
|
113
|
+
id: "ev1700000102",
|
|
114
|
+
timestamp: 1700000102e3,
|
|
102
115
|
user: { id: "us3r", session: "s3ss10n", email: "user@example.com" }
|
|
103
116
|
}),
|
|
104
117
|
settings: {
|
|
@@ -116,20 +129,22 @@ var destinationIdentify = {
|
|
|
116
129
|
[
|
|
117
130
|
"analytics.identify",
|
|
118
131
|
{
|
|
132
|
+
messageId: "ev1700000102-identify",
|
|
119
133
|
userId: "us3r",
|
|
120
134
|
anonymousId: "s3ss10n",
|
|
121
135
|
traits: { email: "user@example.com" },
|
|
122
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
136
|
+
timestamp: /* @__PURE__ */ new Date(1700000102e3)
|
|
123
137
|
}
|
|
124
138
|
],
|
|
125
139
|
[
|
|
126
140
|
"analytics.track",
|
|
127
141
|
{
|
|
142
|
+
messageId: "ev1700000102",
|
|
128
143
|
userId: "us3r",
|
|
129
144
|
anonymousId: "s3ss10n",
|
|
130
145
|
event: "page view",
|
|
131
146
|
properties: {},
|
|
132
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
147
|
+
timestamp: /* @__PURE__ */ new Date(1700000102e3)
|
|
133
148
|
}
|
|
134
149
|
]
|
|
135
150
|
]
|
|
@@ -137,8 +152,10 @@ var destinationIdentify = {
|
|
|
137
152
|
var userLoginIdentify = {
|
|
138
153
|
title: "User login identify",
|
|
139
154
|
description: "A user login fires only an analytics.identify call with the resolved userId and traits, skipping the track.",
|
|
140
|
-
in:
|
|
141
|
-
|
|
155
|
+
in: createEvent({
|
|
156
|
+
name: "user login",
|
|
157
|
+
id: "ev1700000103",
|
|
158
|
+
timestamp: 1700000103e3,
|
|
142
159
|
user: { id: "us3r", session: "s3ss10n" },
|
|
143
160
|
data: {
|
|
144
161
|
user_id: "new-user-123",
|
|
@@ -168,10 +185,11 @@ var userLoginIdentify = {
|
|
|
168
185
|
[
|
|
169
186
|
"analytics.identify",
|
|
170
187
|
{
|
|
188
|
+
messageId: "ev1700000103-identify",
|
|
171
189
|
userId: "new-user-123",
|
|
172
190
|
anonymousId: "s3ss10n",
|
|
173
191
|
traits: { email: "user@acme.com", name: "Jane Doe", plan: "premium" },
|
|
174
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
192
|
+
timestamp: /* @__PURE__ */ new Date(1700000103e3)
|
|
175
193
|
}
|
|
176
194
|
]
|
|
177
195
|
]
|
|
@@ -179,8 +197,10 @@ var userLoginIdentify = {
|
|
|
179
197
|
var companyGroup = {
|
|
180
198
|
title: "Group company",
|
|
181
199
|
description: "A company update fires analytics.group with the groupId and group traits for B2B account tracking.",
|
|
182
|
-
in:
|
|
183
|
-
|
|
200
|
+
in: createEvent({
|
|
201
|
+
name: "company update",
|
|
202
|
+
id: "ev1700000104",
|
|
203
|
+
timestamp: 1700000104e3,
|
|
184
204
|
user: { id: "us3r", session: "s3ss10n" },
|
|
185
205
|
data: {
|
|
186
206
|
company_id: "comp-456",
|
|
@@ -210,11 +230,12 @@ var companyGroup = {
|
|
|
210
230
|
[
|
|
211
231
|
"analytics.group",
|
|
212
232
|
{
|
|
233
|
+
messageId: "ev1700000104-group",
|
|
213
234
|
userId: "us3r",
|
|
214
235
|
anonymousId: "s3ss10n",
|
|
215
236
|
groupId: "comp-456",
|
|
216
237
|
traits: { name: "Acme", industry: "tech", employees: 50 },
|
|
217
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
238
|
+
timestamp: /* @__PURE__ */ new Date(1700000104e3)
|
|
218
239
|
}
|
|
219
240
|
]
|
|
220
241
|
]
|
|
@@ -223,7 +244,8 @@ var pageView = {
|
|
|
223
244
|
title: "Page view",
|
|
224
245
|
description: "A page view fires analytics.page with a resolved page name and properties instead of a generic track.",
|
|
225
246
|
in: getEvent("page view", {
|
|
226
|
-
|
|
247
|
+
id: "ev1700000105",
|
|
248
|
+
timestamp: 1700000105e3,
|
|
227
249
|
user: { id: "us3r", session: "s3ss10n" },
|
|
228
250
|
data: {
|
|
229
251
|
title: "Getting Started",
|
|
@@ -249,11 +271,12 @@ var pageView = {
|
|
|
249
271
|
[
|
|
250
272
|
"analytics.page",
|
|
251
273
|
{
|
|
274
|
+
messageId: "ev1700000105-page",
|
|
252
275
|
userId: "us3r",
|
|
253
276
|
anonymousId: "s3ss10n",
|
|
254
277
|
name: "Getting Started",
|
|
255
278
|
properties: { section: "tutorials" },
|
|
256
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
279
|
+
timestamp: /* @__PURE__ */ new Date(1700000105e3)
|
|
257
280
|
}
|
|
258
281
|
]
|
|
259
282
|
]
|
|
@@ -261,8 +284,10 @@ var pageView = {
|
|
|
261
284
|
var screenView = {
|
|
262
285
|
title: "Screen view",
|
|
263
286
|
description: "A screen view from a mobile app backend fires analytics.screen with a screen name and properties.",
|
|
264
|
-
in:
|
|
265
|
-
|
|
287
|
+
in: createEvent({
|
|
288
|
+
name: "screen view",
|
|
289
|
+
id: "ev1700000106",
|
|
290
|
+
timestamp: 1700000106e3,
|
|
266
291
|
user: { id: "us3r", session: "s3ss10n" },
|
|
267
292
|
data: {
|
|
268
293
|
screen_name: "Welcome",
|
|
@@ -289,11 +314,12 @@ var screenView = {
|
|
|
289
314
|
[
|
|
290
315
|
"analytics.screen",
|
|
291
316
|
{
|
|
317
|
+
messageId: "ev1700000106-screen",
|
|
292
318
|
userId: "us3r",
|
|
293
319
|
anonymousId: "s3ss10n",
|
|
294
320
|
name: "Welcome",
|
|
295
321
|
properties: { build: "1.2.3" },
|
|
296
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
322
|
+
timestamp: /* @__PURE__ */ new Date(1700000106e3)
|
|
297
323
|
}
|
|
298
324
|
]
|
|
299
325
|
]
|
|
@@ -301,8 +327,10 @@ var screenView = {
|
|
|
301
327
|
var aliasUser = {
|
|
302
328
|
title: "Alias user",
|
|
303
329
|
description: "An identity merge fires analytics.alias to link a previous anonymous id to the newly registered user id.",
|
|
304
|
-
in:
|
|
305
|
-
|
|
330
|
+
in: createEvent({
|
|
331
|
+
name: "identity merge",
|
|
332
|
+
id: "ev1700000107",
|
|
333
|
+
timestamp: 1700000107e3,
|
|
306
334
|
user: { id: "registered-456", session: "s3ss10n" },
|
|
307
335
|
data: {
|
|
308
336
|
anonymous_id: "anonymous-123"
|
|
@@ -322,9 +350,10 @@ var aliasUser = {
|
|
|
322
350
|
[
|
|
323
351
|
"analytics.alias",
|
|
324
352
|
{
|
|
353
|
+
messageId: "ev1700000107-alias",
|
|
325
354
|
userId: "registered-456",
|
|
326
355
|
previousId: "anonymous-123",
|
|
327
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
356
|
+
timestamp: /* @__PURE__ */ new Date(1700000107e3)
|
|
328
357
|
}
|
|
329
358
|
]
|
|
330
359
|
]
|
|
@@ -333,7 +362,8 @@ var anonymousOnly = {
|
|
|
333
362
|
title: "Anonymous only",
|
|
334
363
|
description: "When no userId is resolved RudderStack accepts the track call keyed solely by anonymousId.",
|
|
335
364
|
in: getEvent("product view", {
|
|
336
|
-
|
|
365
|
+
id: "ev1700000108",
|
|
366
|
+
timestamp: 1700000108e3,
|
|
337
367
|
user: { session: "s3ss10n" }
|
|
338
368
|
}),
|
|
339
369
|
settings: {
|
|
@@ -343,24 +373,76 @@ var anonymousOnly = {
|
|
|
343
373
|
[
|
|
344
374
|
"analytics.track",
|
|
345
375
|
{
|
|
376
|
+
messageId: "ev1700000108",
|
|
346
377
|
anonymousId: "s3ss10n",
|
|
347
378
|
event: "product view",
|
|
348
379
|
properties: {},
|
|
349
|
-
timestamp: /* @__PURE__ */ new Date(
|
|
380
|
+
timestamp: /* @__PURE__ */ new Date(1700000108e3)
|
|
350
381
|
}
|
|
351
382
|
]
|
|
352
383
|
]
|
|
353
384
|
};
|
|
385
|
+
function withoutIdentity(name, timestamp) {
|
|
386
|
+
const [entity, action] = name.split(" ");
|
|
387
|
+
return {
|
|
388
|
+
public: false,
|
|
389
|
+
description: `A ${name} event without userId or anonymousId cannot be sent to RudderStack: the push fails with missing-input instead of counting as delivered.`,
|
|
390
|
+
in: { name, entity, action, timestamp },
|
|
391
|
+
out: [],
|
|
392
|
+
outcome: { status: "failed", code: "missing-input", retryable: false }
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
var noIdentityProduct = withoutIdentity("product view", 1700000110);
|
|
396
|
+
var noIdentityOrder = withoutIdentity("order complete", 1700000111);
|
|
397
|
+
var noIdentityPage = withoutIdentity("page view", 1700000112);
|
|
398
|
+
var noIdentityLogin = withoutIdentity("user login", 1700000113);
|
|
399
|
+
var noIdentityCompany = withoutIdentity("company update", 1700000114);
|
|
400
|
+
var noIdentityScreen = withoutIdentity("screen view", 1700000115);
|
|
401
|
+
var noIdentityMerge = withoutIdentity("identity merge", 1700000116);
|
|
402
|
+
var silentRule = {
|
|
403
|
+
public: false,
|
|
404
|
+
description: "A rule with silent: true and no identify, group, page, screen or alias mapping sends nothing to RudderStack.",
|
|
405
|
+
in: getEvent("page view", {
|
|
406
|
+
timestamp: 1700000117e3,
|
|
407
|
+
user: { id: "us3r", session: "s3ss10n" }
|
|
408
|
+
}),
|
|
409
|
+
mapping: { silent: true },
|
|
410
|
+
out: []
|
|
411
|
+
};
|
|
354
412
|
var wildcardIgnored = {
|
|
355
413
|
public: false,
|
|
356
|
-
in:
|
|
357
|
-
|
|
414
|
+
in: createEvent({
|
|
415
|
+
name: "debug noise",
|
|
416
|
+
timestamp: 1700000109e3,
|
|
358
417
|
user: { id: "us3r", session: "s3ss10n" }
|
|
359
418
|
}),
|
|
360
419
|
mapping: { ignore: true },
|
|
361
420
|
out: []
|
|
362
421
|
};
|
|
422
|
+
var companyGroupWithoutData = {
|
|
423
|
+
public: false,
|
|
424
|
+
description: "A silent group rule whose groupId finds no data sends nothing: an unmet mapping, not a failure, so the push returns normally.",
|
|
425
|
+
in: {
|
|
426
|
+
name: "company update",
|
|
427
|
+
entity: "company",
|
|
428
|
+
action: "update",
|
|
429
|
+
timestamp: 170000012e4,
|
|
430
|
+
user: { id: "us3r", session: "s3ss10n" }
|
|
431
|
+
},
|
|
432
|
+
mapping: companyGroup.mapping,
|
|
433
|
+
out: []
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
// src/examples/minimal.ts
|
|
437
|
+
var minimal = {
|
|
438
|
+
settings: {
|
|
439
|
+
writeKey: "test-write-key",
|
|
440
|
+
dataPlaneUrl: "https://hosted.rudderlabs.com"
|
|
441
|
+
},
|
|
442
|
+
secrets: { writeKey: "RUDDERSTACK_WRITE_KEY" }
|
|
443
|
+
};
|
|
363
444
|
export {
|
|
364
445
|
env_exports as env,
|
|
446
|
+
minimal,
|
|
365
447
|
step_exports as step
|
|
366
448
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -28,15 +28,19 @@ interface Settings {
|
|
|
28
28
|
maxInternalQueueSize?: number;
|
|
29
29
|
/** Log level. Default: 'info'. */
|
|
30
30
|
logLevel?: string;
|
|
31
|
-
/**
|
|
31
|
+
/** Retries for a failed request. Default: 2, within config.timeout. */
|
|
32
32
|
retryCount?: number;
|
|
33
|
+
/** Time one request may take (ms). Default: a quarter of config.timeout. */
|
|
34
|
+
timeout?: number;
|
|
33
35
|
/** Completely disable the SDK. Default: false. */
|
|
34
36
|
enable?: boolean;
|
|
35
37
|
/** Enable gzip compression. Default: true. */
|
|
36
38
|
gzip?: boolean;
|
|
37
39
|
/** Runtime state -- not user-facing. Mutated by init/push. */
|
|
38
|
-
_analytics?:
|
|
40
|
+
_analytics?: RudderStackAnalyticsMock;
|
|
39
41
|
_state?: RuntimeState;
|
|
42
|
+
/** The running flush; the next one waits for it. Runtime only. */
|
|
43
|
+
_flushing?: Promise<void>;
|
|
40
44
|
}
|
|
41
45
|
interface RuntimeState {
|
|
42
46
|
lastIdentity?: {
|
|
@@ -75,14 +79,16 @@ interface Env extends DestinationServer.Env {
|
|
|
75
79
|
* destination actually calls. Tests can provide this via env.analytics
|
|
76
80
|
* instead of the real SDK.
|
|
77
81
|
*/
|
|
82
|
+
/** Called once the SDK sent the call, with the error if it failed. */
|
|
83
|
+
type RudderStackCallback = (error?: Error, data?: unknown) => void;
|
|
78
84
|
interface RudderStackAnalyticsMock {
|
|
79
|
-
track: (params: Record<string, unknown
|
|
80
|
-
identify: (params: Record<string, unknown
|
|
81
|
-
group: (params: Record<string, unknown
|
|
82
|
-
page: (params: Record<string, unknown
|
|
83
|
-
screen: (params: Record<string, unknown
|
|
84
|
-
alias: (params: Record<string, unknown
|
|
85
|
-
flush: (callback?:
|
|
85
|
+
track: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
86
|
+
identify: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
87
|
+
group: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
88
|
+
page: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
89
|
+
screen: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
90
|
+
alias: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
91
|
+
flush: (callback?: RudderStackCallback) => Promise<void>;
|
|
86
92
|
}
|
|
87
93
|
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
88
94
|
interface Destination extends DestinationServer.Destination<Types> {
|
|
@@ -93,6 +99,7 @@ type Config = {
|
|
|
93
99
|
} & DestinationServer.Config<Types>;
|
|
94
100
|
type InitFn = DestinationServer.InitFn<Types>;
|
|
95
101
|
type PushFn = DestinationServer.PushFn<Types>;
|
|
102
|
+
type PushBatchFn = Destination$1.PushBatchFn<Types>;
|
|
96
103
|
type PartialConfig = DestinationServer.PartialConfig<Types>;
|
|
97
104
|
type PushEvents = DestinationServer.PushEvents<Mapping>;
|
|
98
105
|
type Rule = Mapping$1.Rule<Mapping>;
|
|
@@ -105,16 +112,18 @@ type index_InitFn = InitFn;
|
|
|
105
112
|
type index_InitSettings = InitSettings;
|
|
106
113
|
type index_Mapping = Mapping;
|
|
107
114
|
type index_PartialConfig = PartialConfig;
|
|
115
|
+
type index_PushBatchFn = PushBatchFn;
|
|
108
116
|
type index_PushEvents = PushEvents;
|
|
109
117
|
type index_PushFn = PushFn;
|
|
110
118
|
type index_RudderStackAnalyticsMock = RudderStackAnalyticsMock;
|
|
119
|
+
type index_RudderStackCallback = RudderStackCallback;
|
|
111
120
|
type index_Rule = Rule;
|
|
112
121
|
type index_Rules = Rules;
|
|
113
122
|
type index_RuntimeState = RuntimeState;
|
|
114
123
|
type index_Settings = Settings;
|
|
115
124
|
type index_Types = Types;
|
|
116
125
|
declare namespace index {
|
|
117
|
-
export type { index_Config as Config, index_Destination as Destination, index_Env as Env, 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_RudderStackAnalyticsMock as RudderStackAnalyticsMock, index_Rule as Rule, index_Rules as Rules, index_RuntimeState as RuntimeState, index_Settings as Settings, index_Types as Types };
|
|
126
|
+
export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PushBatchFn as PushBatchFn, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RudderStackAnalyticsMock as RudderStackAnalyticsMock, index_RudderStackCallback as RudderStackCallback, index_Rule as Rule, index_Rules as Rules, index_RuntimeState as RuntimeState, index_Settings as Settings, index_Types as Types };
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
declare const destinationRudderStack: Destination;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,15 +28,19 @@ interface Settings {
|
|
|
28
28
|
maxInternalQueueSize?: number;
|
|
29
29
|
/** Log level. Default: 'info'. */
|
|
30
30
|
logLevel?: string;
|
|
31
|
-
/**
|
|
31
|
+
/** Retries for a failed request. Default: 2, within config.timeout. */
|
|
32
32
|
retryCount?: number;
|
|
33
|
+
/** Time one request may take (ms). Default: a quarter of config.timeout. */
|
|
34
|
+
timeout?: number;
|
|
33
35
|
/** Completely disable the SDK. Default: false. */
|
|
34
36
|
enable?: boolean;
|
|
35
37
|
/** Enable gzip compression. Default: true. */
|
|
36
38
|
gzip?: boolean;
|
|
37
39
|
/** Runtime state -- not user-facing. Mutated by init/push. */
|
|
38
|
-
_analytics?:
|
|
40
|
+
_analytics?: RudderStackAnalyticsMock;
|
|
39
41
|
_state?: RuntimeState;
|
|
42
|
+
/** The running flush; the next one waits for it. Runtime only. */
|
|
43
|
+
_flushing?: Promise<void>;
|
|
40
44
|
}
|
|
41
45
|
interface RuntimeState {
|
|
42
46
|
lastIdentity?: {
|
|
@@ -75,14 +79,16 @@ interface Env extends DestinationServer.Env {
|
|
|
75
79
|
* destination actually calls. Tests can provide this via env.analytics
|
|
76
80
|
* instead of the real SDK.
|
|
77
81
|
*/
|
|
82
|
+
/** Called once the SDK sent the call, with the error if it failed. */
|
|
83
|
+
type RudderStackCallback = (error?: Error, data?: unknown) => void;
|
|
78
84
|
interface RudderStackAnalyticsMock {
|
|
79
|
-
track: (params: Record<string, unknown
|
|
80
|
-
identify: (params: Record<string, unknown
|
|
81
|
-
group: (params: Record<string, unknown
|
|
82
|
-
page: (params: Record<string, unknown
|
|
83
|
-
screen: (params: Record<string, unknown
|
|
84
|
-
alias: (params: Record<string, unknown
|
|
85
|
-
flush: (callback?:
|
|
85
|
+
track: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
86
|
+
identify: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
87
|
+
group: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
88
|
+
page: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
89
|
+
screen: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
90
|
+
alias: (params: Record<string, unknown>, callback?: RudderStackCallback) => unknown;
|
|
91
|
+
flush: (callback?: RudderStackCallback) => Promise<void>;
|
|
86
92
|
}
|
|
87
93
|
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
88
94
|
interface Destination extends DestinationServer.Destination<Types> {
|
|
@@ -93,6 +99,7 @@ type Config = {
|
|
|
93
99
|
} & DestinationServer.Config<Types>;
|
|
94
100
|
type InitFn = DestinationServer.InitFn<Types>;
|
|
95
101
|
type PushFn = DestinationServer.PushFn<Types>;
|
|
102
|
+
type PushBatchFn = Destination$1.PushBatchFn<Types>;
|
|
96
103
|
type PartialConfig = DestinationServer.PartialConfig<Types>;
|
|
97
104
|
type PushEvents = DestinationServer.PushEvents<Mapping>;
|
|
98
105
|
type Rule = Mapping$1.Rule<Mapping>;
|
|
@@ -105,16 +112,18 @@ type index_InitFn = InitFn;
|
|
|
105
112
|
type index_InitSettings = InitSettings;
|
|
106
113
|
type index_Mapping = Mapping;
|
|
107
114
|
type index_PartialConfig = PartialConfig;
|
|
115
|
+
type index_PushBatchFn = PushBatchFn;
|
|
108
116
|
type index_PushEvents = PushEvents;
|
|
109
117
|
type index_PushFn = PushFn;
|
|
110
118
|
type index_RudderStackAnalyticsMock = RudderStackAnalyticsMock;
|
|
119
|
+
type index_RudderStackCallback = RudderStackCallback;
|
|
111
120
|
type index_Rule = Rule;
|
|
112
121
|
type index_Rules = Rules;
|
|
113
122
|
type index_RuntimeState = RuntimeState;
|
|
114
123
|
type index_Settings = Settings;
|
|
115
124
|
type index_Types = Types;
|
|
116
125
|
declare namespace index {
|
|
117
|
-
export type { index_Config as Config, index_Destination as Destination, index_Env as Env, 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_RudderStackAnalyticsMock as RudderStackAnalyticsMock, index_Rule as Rule, index_Rules as Rules, index_RuntimeState as RuntimeState, index_Settings as Settings, index_Types as Types };
|
|
126
|
+
export type { index_Config as Config, index_Destination as Destination, index_Env as Env, index_InitFn as InitFn, index_InitSettings as InitSettings, index_Mapping as Mapping, index_PartialConfig as PartialConfig, index_PushBatchFn as PushBatchFn, index_PushEvents as PushEvents, index_PushFn as PushFn, index_RudderStackAnalyticsMock as RudderStackAnalyticsMock, index_RudderStackCallback as RudderStackCallback, index_Rule as Rule, index_Rules as Rules, index_RuntimeState as RuntimeState, index_Settings as Settings, index_Types as Types };
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
declare const destinationRudderStack: Destination;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t,e=Object.defineProperty,
|
|
1
|
+
"use strict";var t,e=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,i={};((t,r)=>{for(var n in r)e(t,n,{get:r[n],enumerable:!0})})(i,{DestinationRudderStack:()=>S,default:()=>b,destinationRudderStack:()=>k}),module.exports=(t=i,((t,i,a,o)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of n(i))s.call(t,c)||c===a||e(t,c,{get:()=>i[c],enumerable:!(o=r(i,c))||o.enumerable});return t})(e({},"__esModule",{value:!0}),t));var a=require("@walkeros/core"),o=require("@walkeros/server-core"),c=require("@walkeros/core");var u=require("@walkeros/core"),d=require("@walkeros/server-core");function l(t,e){const r=new Promise((r,n)=>{const s=e=>n(function(t,e){const r="object"==typeof e&&null!==e?Reflect.get(e,"code"):void 0,n="ECONNABORTED"===r||"ETIMEDOUT"===r;return new u.StepError(t,{code:n?"timeout":"transport",cause:e})}(t,e));let i;try{i=e(t=>t?s(t):r())}catch(t){return void s(t)}(0,u.isThenable)(i)&&i.then(()=>r(),s)});return r.catch(()=>{}),r}function p(t,e){if(t.id)return e?`${t.id}-${e}`:t.id}function g(t,e,r){const n=p(e,r);return n?{...t,messageId:n}:t}function f(t,e){const r=(t._flushing??Promise.resolve()).then(()=>e.flush());return t._flushing=r.catch(()=>{}),r}function y(t,e,r,n){t.debug(`RudderStack skipped ${r}: ${n} resolved to nothing`,{event:e.name})}async function m(t){for(const e of await t)if("rejected"===e.status)throw e.reason}async function h(t,e,r,n,s,i,a){const o=n._state||{};n._state=o;const c=e?.settings||{},d=new Date(t.timestamp||Date.now()),f=n.userId?I(await(0,u.getMappingValue)(t,n.userId,{collector:i})):void 0,m=n.anonymousId?I(await(0,u.getMappingValue)(t,n.anonymousId,{collector:i})):void 0;if(!f&&!m)throw new u.StepError("RudderStack needs a userId or anonymousId for the event",{code:"missing-input"});const h={};f&&(h.userId=f),m&&(h.anonymousId=m);const w=[],S=c.identify??n.identify;if(void 0!==S){const e=await(0,u.getMappingValue)(t,S,{collector:i});(0,u.isObject)(e)?w.push(function(t,e,r,n,s){const i=n.lastIdentity||{},a=(0,u.isString)(e.userId)?e.userId:r.userId,o=(0,u.isObject)(e.traits)&&!(0,u.isArray)(e.traits)?e.traits:void 0,c=v(o),d=a!==i.userId,p=c!==(i.traitsHash??"");if(!d&&!p)return;const g={...r,timestamp:s};a&&(g.userId=a);o&&(g.traits=o);const f={userId:a,anonymousId:r.anonymousId,traitsHash:c};return n.lastIdentity=f,l("RudderStack identify failed",e=>t.identify(g,e)).catch(t=>{throw n.lastIdentity===f&&(n.lastIdentity=void 0),t})}(s,e,g(h,t,"identify"),o,d)):y(a,t,"identify","identify")}const k=c.group??n.group;if(void 0!==k){const e=await(0,u.getMappingValue)(t,k,{collector:i});(0,u.isObject)(e)&&(0,u.isString)(e.groupId)?w.push(function(t,e,r,n,s){const i=(0,u.isString)(e.groupId)?e.groupId:void 0;if(!i)return;const a=n.lastGroup||{},o=(0,u.isObject)(e.traits)&&!(0,u.isArray)(e.traits)?e.traits:void 0,c=v(o),d=i!==a.groupId,p=c!==(a.traitsHash??"");if(!d&&!p)return;const g={...r,groupId:i,timestamp:s};o&&(g.traits=o);const f={groupId:i,traitsHash:c};return n.lastGroup=f,l("RudderStack group failed",e=>t.group(g,e)).catch(t=>{throw n.lastGroup===f&&(n.lastGroup=void 0),t})}(s,e,g(h,t,"group"),o,d)):y(a,t,"group","group")}if(void 0!==c.page){const{sent:e}=await async function(t,e,r,n,s,i){const a={...n,timestamp:i};if(!0===e)return{sent:l("RudderStack page failed",e=>t.page(a,e))};const o=await(0,u.getMappingValue)(r,e,{collector:s});if(!(0,u.isObject)(o))return{};const c=o;(0,u.isString)(c.category)&&(a.category=c.category);(0,u.isString)(c.name)&&(a.name=c.name);(0,u.isObject)(c.properties)&&!(0,u.isArray)(c.properties)&&(a.properties=c.properties);return{sent:l("RudderStack page failed",e=>t.page(a,e))}}(s,c.page,t,g(h,t,"page"),i,d);e?w.push(e):y(a,t,"page","page")}if(void 0!==c.screen){const{sent:e}=await async function(t,e,r,n,s,i){const a={...n,timestamp:i};if(!0===e)return{sent:l("RudderStack screen failed",e=>t.screen(a,e))};const o=await(0,u.getMappingValue)(r,e,{collector:s});if(!(0,u.isObject)(o))return{};const c=o;(0,u.isString)(c.category)&&(a.category=c.category);(0,u.isString)(c.name)&&(a.name=c.name);(0,u.isObject)(c.properties)&&!(0,u.isArray)(c.properties)&&(a.properties=c.properties);return{sent:l("RudderStack screen failed",e=>t.screen(a,e))}}(s,c.screen,t,g(h,t,"screen"),i,d);e?w.push(e):y(a,t,"screen","screen")}if(void 0!==c.alias){const{sent:e}=await async function(t,e,r,n,s,i){const a=await(0,u.getMappingValue)(r,e,{collector:s});if(!(0,u.isObject)(a))return{};const o=a,c=(0,u.isString)(o.previousId)?o.previousId:void 0;if(!c)return{};const d={previousId:c,timestamp:i};n.userId&&(d.userId=n.userId);n.messageId&&(d.messageId=n.messageId);return{sent:l("RudderStack alias failed",e=>t.alias(d,e))}}(s,c.alias,t,g(h,t,"alias"),i,d);e?w.push(e):y(a,t,"alias","alias")}if(!0!==e?.silent){const n=(0,u.isString)(e?.name)?e.name:t.name,i=(0,u.isObject)(r)?r:{},a={...h,event:n,properties:i,timestamp:d},o=p(t);o&&(a.messageId=o),w.push(l("RudderStack track failed",t=>s.track(a,t)))}return w.filter(t=>void 0!==t)}function w(t,e){const r=e?.analytics||t?._analytics;if(!t||!r)throw new u.StepError("RudderStack Analytics not initialized",{code:"not-ready"});return r}function I(t){if((0,u.isString)(t)&&t.length>0)return t}function v(t){if(!t)return"";try{return JSON.stringify(t)}catch{return""}}var S={},k={type:"rudderstack",config:{batch:{size:20,wait:1e4}},init({config:t,env:e}){const r=function(t={}){const e=t.settings||{},{writeKey:r,dataPlaneUrl:n}=e;if(!r||!n){const t=[...r?[]:["writeKey"],...n?[]:["dataPlaneUrl"]];throw new c.StepError(`Config settings ${t.join(", ")} missing`,{code:"config"})}const s={...e,writeKey:r,dataPlaneUrl:n,userId:e.userId??"user.id",anonymousId:e.anonymousId??"user.session"};return{...t,settings:s}}(t),{settings:n}=r;if(!e?.analytics)try{const e=require("@rudderstack/rudder-sdk-node"),{writeKey:r,dataPlaneUrl:s,userId:i,anonymousId:a,identify:c,group:u,integrations:d,_analytics:l,_state:p,...g}=n,f=(0,o.retryBudget)(t.timeout);n._analytics=new e(r,{dataPlaneUrl:s,timeout:f.attempt,retryCount:f.retries,axiosRetryConfig:{retryDelay:()=>f.wait,shouldResetTimeout:!0},...g,errorHandler:()=>{}})}catch(t){throw new a.StepError("Failed to initialize the RudderStack SDK",{code:"not-ready",cause:t})}return n._state={},r},push:async function(t,{config:e,rule:r,data:n,collector:s,env:i,logger:a}){const o=e.settings??{},c=w(e.settings,i),u=await h(t,r,n,o,c,s,a);if(u.length){const t=Promise.allSettled(u);await f(o,c),await m(t)}},pushBatch:async function(t,{config:e,collector:r,env:n,logger:s}){const i=e.settings??{},a=w(e.settings,n),o=[];for(const e of t.entries)try{const t=await h(e.event,e.rule,e.data,i,a,r,s);o.push({settled:Promise.allSettled(t)})}catch(t){o.push({error:t})}await f(i,a);const c=[];for(const[t,{settled:e,error:r}]of o.entries())e?await m(e).catch(e=>c.push({index:t,error:e})):c.push({index:t,error:r});return(0,d.batchOutcome)(t.entries.length,c)},async destroy({config:t}){const e=t?.settings?._analytics;e&&await e.flush()}},b=k;//# sourceMappingURL=index.js.map
|