@walkeros/server-destination-rudderstack 3.4.0-next-1776749829492

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,347 @@
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
+ push: () => push,
11
+ simulation: () => simulation
12
+ });
13
+ var noop = () => {
14
+ };
15
+ var asyncNoop = () => Promise.resolve();
16
+ function createMockAnalytics() {
17
+ return {
18
+ track: noop,
19
+ identify: noop,
20
+ group: noop,
21
+ page: noop,
22
+ screen: noop,
23
+ alias: noop,
24
+ flush: asyncNoop
25
+ };
26
+ }
27
+ var push = {
28
+ analytics: createMockAnalytics()
29
+ };
30
+ var simulation = [
31
+ "call:analytics.track",
32
+ "call:analytics.identify",
33
+ "call:analytics.group",
34
+ "call:analytics.page",
35
+ "call:analytics.screen",
36
+ "call:analytics.alias"
37
+ ];
38
+
39
+ // src/examples/step.ts
40
+ var step_exports = {};
41
+ __export(step_exports, {
42
+ aliasUser: () => aliasUser,
43
+ anonymousOnly: () => anonymousOnly,
44
+ companyGroup: () => companyGroup,
45
+ defaultTrack: () => defaultTrack,
46
+ destinationIdentify: () => destinationIdentify,
47
+ mappedEventName: () => mappedEventName,
48
+ pageView: () => pageView,
49
+ screenView: () => screenView,
50
+ userLoginIdentify: () => userLoginIdentify,
51
+ wildcardIgnored: () => wildcardIgnored
52
+ });
53
+ import { getEvent } from "@walkeros/core";
54
+ var defaultTrack = {
55
+ in: getEvent("product view", {
56
+ timestamp: 1700000100,
57
+ user: { id: "us3r", session: "s3ss10n" }
58
+ }),
59
+ out: [
60
+ [
61
+ "analytics.track",
62
+ {
63
+ userId: "us3r",
64
+ anonymousId: "s3ss10n",
65
+ event: "product view",
66
+ properties: {},
67
+ timestamp: /* @__PURE__ */ new Date(1700000100)
68
+ }
69
+ ]
70
+ ]
71
+ };
72
+ var mappedEventName = {
73
+ in: getEvent("order complete", {
74
+ timestamp: 1700000101,
75
+ user: { id: "us3r", session: "s3ss10n" }
76
+ }),
77
+ mapping: {
78
+ name: "Order Completed"
79
+ },
80
+ out: [
81
+ [
82
+ "analytics.track",
83
+ {
84
+ userId: "us3r",
85
+ anonymousId: "s3ss10n",
86
+ event: "Order Completed",
87
+ properties: {},
88
+ timestamp: /* @__PURE__ */ new Date(1700000101)
89
+ }
90
+ ]
91
+ ]
92
+ };
93
+ var destinationIdentify = {
94
+ in: getEvent("page view", {
95
+ timestamp: 1700000102,
96
+ user: { id: "us3r", session: "s3ss10n", email: "user@example.com" }
97
+ }),
98
+ settings: {
99
+ identify: {
100
+ map: {
101
+ traits: {
102
+ map: {
103
+ email: "user.email"
104
+ }
105
+ }
106
+ }
107
+ }
108
+ },
109
+ out: [
110
+ [
111
+ "analytics.identify",
112
+ {
113
+ userId: "us3r",
114
+ anonymousId: "s3ss10n",
115
+ traits: { email: "user@example.com" },
116
+ timestamp: /* @__PURE__ */ new Date(1700000102)
117
+ }
118
+ ],
119
+ [
120
+ "analytics.track",
121
+ {
122
+ userId: "us3r",
123
+ anonymousId: "s3ss10n",
124
+ event: "page view",
125
+ properties: {},
126
+ timestamp: /* @__PURE__ */ new Date(1700000102)
127
+ }
128
+ ]
129
+ ]
130
+ };
131
+ var userLoginIdentify = {
132
+ in: getEvent("user login", {
133
+ timestamp: 1700000103,
134
+ user: { id: "us3r", session: "s3ss10n" },
135
+ data: {
136
+ user_id: "new-user-123",
137
+ email: "user@acme.com",
138
+ name: "Jane Doe",
139
+ plan: "premium"
140
+ }
141
+ }),
142
+ mapping: {
143
+ skip: true,
144
+ settings: {
145
+ identify: {
146
+ map: {
147
+ userId: "data.user_id",
148
+ traits: {
149
+ map: {
150
+ email: "data.email",
151
+ name: "data.name",
152
+ plan: "data.plan"
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ },
159
+ out: [
160
+ [
161
+ "analytics.identify",
162
+ {
163
+ userId: "new-user-123",
164
+ anonymousId: "s3ss10n",
165
+ traits: { email: "user@acme.com", name: "Jane Doe", plan: "premium" },
166
+ timestamp: /* @__PURE__ */ new Date(1700000103)
167
+ }
168
+ ]
169
+ ]
170
+ };
171
+ var companyGroup = {
172
+ in: getEvent("company update", {
173
+ timestamp: 1700000104,
174
+ user: { id: "us3r", session: "s3ss10n" },
175
+ data: {
176
+ company_id: "comp-456",
177
+ company_name: "Acme",
178
+ industry: "tech",
179
+ employees: 50
180
+ }
181
+ }),
182
+ mapping: {
183
+ skip: true,
184
+ settings: {
185
+ group: {
186
+ map: {
187
+ groupId: "data.company_id",
188
+ traits: {
189
+ map: {
190
+ name: "data.company_name",
191
+ industry: "data.industry",
192
+ employees: "data.employees"
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+ },
199
+ out: [
200
+ [
201
+ "analytics.group",
202
+ {
203
+ userId: "us3r",
204
+ anonymousId: "s3ss10n",
205
+ groupId: "comp-456",
206
+ traits: { name: "Acme", industry: "tech", employees: 50 },
207
+ timestamp: /* @__PURE__ */ new Date(1700000104)
208
+ }
209
+ ]
210
+ ]
211
+ };
212
+ var pageView = {
213
+ in: getEvent("page view", {
214
+ timestamp: 1700000105,
215
+ user: { id: "us3r", session: "s3ss10n" },
216
+ data: {
217
+ title: "Getting Started",
218
+ section: "tutorials"
219
+ }
220
+ }),
221
+ mapping: {
222
+ skip: true,
223
+ settings: {
224
+ page: {
225
+ map: {
226
+ name: "data.title",
227
+ properties: {
228
+ map: {
229
+ section: "data.section"
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
235
+ },
236
+ out: [
237
+ [
238
+ "analytics.page",
239
+ {
240
+ userId: "us3r",
241
+ anonymousId: "s3ss10n",
242
+ name: "Getting Started",
243
+ properties: { section: "tutorials" },
244
+ timestamp: /* @__PURE__ */ new Date(1700000105)
245
+ }
246
+ ]
247
+ ]
248
+ };
249
+ var screenView = {
250
+ in: getEvent("screen view", {
251
+ timestamp: 1700000106,
252
+ user: { id: "us3r", session: "s3ss10n" },
253
+ data: {
254
+ screen_name: "Welcome",
255
+ section: "onboarding",
256
+ build: "1.2.3"
257
+ }
258
+ }),
259
+ mapping: {
260
+ skip: true,
261
+ settings: {
262
+ screen: {
263
+ map: {
264
+ name: "data.screen_name",
265
+ properties: {
266
+ map: {
267
+ build: "data.build"
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+ },
274
+ out: [
275
+ [
276
+ "analytics.screen",
277
+ {
278
+ userId: "us3r",
279
+ anonymousId: "s3ss10n",
280
+ name: "Welcome",
281
+ properties: { build: "1.2.3" },
282
+ timestamp: /* @__PURE__ */ new Date(1700000106)
283
+ }
284
+ ]
285
+ ]
286
+ };
287
+ var aliasUser = {
288
+ in: getEvent("identity merge", {
289
+ timestamp: 1700000107,
290
+ user: { id: "registered-456", session: "s3ss10n" },
291
+ data: {
292
+ anonymous_id: "anonymous-123"
293
+ }
294
+ }),
295
+ mapping: {
296
+ skip: true,
297
+ settings: {
298
+ alias: {
299
+ map: {
300
+ previousId: "data.anonymous_id"
301
+ }
302
+ }
303
+ }
304
+ },
305
+ out: [
306
+ [
307
+ "analytics.alias",
308
+ {
309
+ userId: "registered-456",
310
+ previousId: "anonymous-123",
311
+ timestamp: /* @__PURE__ */ new Date(1700000107)
312
+ }
313
+ ]
314
+ ]
315
+ };
316
+ var anonymousOnly = {
317
+ in: getEvent("product view", {
318
+ timestamp: 1700000108,
319
+ user: { session: "s3ss10n" }
320
+ }),
321
+ settings: {
322
+ userId: void 0
323
+ },
324
+ out: [
325
+ [
326
+ "analytics.track",
327
+ {
328
+ anonymousId: "s3ss10n",
329
+ event: "product view",
330
+ properties: {},
331
+ timestamp: /* @__PURE__ */ new Date(1700000108)
332
+ }
333
+ ]
334
+ ]
335
+ };
336
+ var wildcardIgnored = {
337
+ in: getEvent("debug noise", {
338
+ timestamp: 1700000109,
339
+ user: { id: "us3r", session: "s3ss10n" }
340
+ }),
341
+ mapping: { ignore: true },
342
+ out: []
343
+ };
344
+ export {
345
+ env_exports as env,
346
+ step_exports as step
347
+ };
@@ -0,0 +1,122 @@
1
+ import { Mapping as Mapping$1, Destination as Destination$1 } from '@walkeros/core';
2
+ import { DestinationServer } from '@walkeros/server-core';
3
+
4
+ interface Settings {
5
+ /** RudderStack source write key (required). */
6
+ writeKey: string;
7
+ /** RudderStack data plane URL (required). */
8
+ dataPlaneUrl: string;
9
+ /** walkerOS mapping value path to resolve userId from each event. */
10
+ userId?: string;
11
+ /** walkerOS mapping value path to resolve anonymousId from each event. */
12
+ anonymousId?: string;
13
+ /** Destination-level identity mapping (fires identify() on first push / change). */
14
+ identify?: Mapping$1.Value;
15
+ /** Destination-level group mapping (fires group() on first push / change). */
16
+ group?: Mapping$1.Value;
17
+ /** Downstream destination filtering. Passthrough to SDK integrations param. */
18
+ integrations?: Record<string, boolean | Record<string, unknown>>;
19
+ /** API path. Default: '/v1/batch'. */
20
+ path?: string;
21
+ /** Events to enqueue before flushing. Default: 20. */
22
+ flushAt?: number;
23
+ /** Max milliseconds before auto-flush. Default: 10000. */
24
+ flushInterval?: number;
25
+ /** Maximum batch payload size in bytes. Default: 460800 (~500KB). */
26
+ maxQueueSize?: number;
27
+ /** Maximum in-memory queue length. Default: 20000. */
28
+ maxInternalQueueSize?: number;
29
+ /** Log level. Default: 'info'. */
30
+ logLevel?: string;
31
+ /** Retry attempts for failed batches. Default: 3. */
32
+ retryCount?: number;
33
+ /** Completely disable the SDK. Default: false. */
34
+ enable?: boolean;
35
+ /** Enable gzip compression. Default: true. */
36
+ gzip?: boolean;
37
+ /** Runtime state -- not user-facing. Mutated by init/push. */
38
+ _analytics?: unknown;
39
+ _state?: RuntimeState;
40
+ }
41
+ interface RuntimeState {
42
+ lastIdentity?: {
43
+ userId?: string;
44
+ anonymousId?: string;
45
+ traitsHash?: string;
46
+ };
47
+ lastGroup?: {
48
+ groupId?: string;
49
+ traitsHash?: string;
50
+ };
51
+ }
52
+ type InitSettings = Partial<Settings>;
53
+ /**
54
+ * Per-rule mapping settings. Every feature is a walkerOS mapping value
55
+ * resolved via getMappingValue(). The resolved object's keys drive
56
+ * which RudderStack SDK methods to call.
57
+ */
58
+ interface Mapping {
59
+ identify?: Mapping$1.Value;
60
+ group?: Mapping$1.Value;
61
+ page?: Mapping$1.Value | boolean;
62
+ screen?: Mapping$1.Value | boolean;
63
+ alias?: Mapping$1.Value;
64
+ }
65
+ /**
66
+ * Env -- optional SDK override. Production leaves this undefined and the
67
+ * destination creates a real Analytics instance. Tests provide a mock via
68
+ * env.analytics.
69
+ */
70
+ interface Env extends DestinationServer.Env {
71
+ analytics?: RudderStackAnalyticsMock;
72
+ }
73
+ /**
74
+ * Mock-friendly interface for the Analytics instance methods the
75
+ * destination actually calls. Tests can provide this via env.analytics
76
+ * instead of the real SDK.
77
+ */
78
+ interface RudderStackAnalyticsMock {
79
+ track: (params: Record<string, unknown>) => void;
80
+ identify: (params: Record<string, unknown>) => void;
81
+ group: (params: Record<string, unknown>) => void;
82
+ page: (params: Record<string, unknown>) => void;
83
+ screen: (params: Record<string, unknown>) => void;
84
+ alias: (params: Record<string, unknown>) => void;
85
+ flush: (callback?: (err?: Error, data?: unknown) => void) => Promise<void>;
86
+ }
87
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
88
+ interface Destination extends DestinationServer.Destination<Types> {
89
+ init: DestinationServer.InitFn<Types>;
90
+ }
91
+ type Config = {
92
+ settings: Settings;
93
+ } & DestinationServer.Config<Types>;
94
+ type InitFn = DestinationServer.InitFn<Types>;
95
+ type PushFn = DestinationServer.PushFn<Types>;
96
+ type PartialConfig = DestinationServer.PartialConfig<Types>;
97
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
98
+ type Rule = Mapping$1.Rule<Mapping>;
99
+ type Rules = Mapping$1.Rules<Rule>;
100
+
101
+ type index_Config = Config;
102
+ type index_Destination = Destination;
103
+ type index_Env = Env;
104
+ type index_InitFn = InitFn;
105
+ type index_InitSettings = InitSettings;
106
+ type index_Mapping = Mapping;
107
+ type index_PartialConfig = PartialConfig;
108
+ type index_PushEvents = PushEvents;
109
+ type index_PushFn = PushFn;
110
+ type index_RudderStackAnalyticsMock = RudderStackAnalyticsMock;
111
+ type index_Rule = Rule;
112
+ type index_Rules = Rules;
113
+ type index_RuntimeState = RuntimeState;
114
+ type index_Settings = Settings;
115
+ type index_Types = Types;
116
+ 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 };
118
+ }
119
+
120
+ declare const destinationRudderStack: Destination;
121
+
122
+ export { index as DestinationRudderStack, destinationRudderStack as default, destinationRudderStack };
@@ -0,0 +1,122 @@
1
+ import { Mapping as Mapping$1, Destination as Destination$1 } from '@walkeros/core';
2
+ import { DestinationServer } from '@walkeros/server-core';
3
+
4
+ interface Settings {
5
+ /** RudderStack source write key (required). */
6
+ writeKey: string;
7
+ /** RudderStack data plane URL (required). */
8
+ dataPlaneUrl: string;
9
+ /** walkerOS mapping value path to resolve userId from each event. */
10
+ userId?: string;
11
+ /** walkerOS mapping value path to resolve anonymousId from each event. */
12
+ anonymousId?: string;
13
+ /** Destination-level identity mapping (fires identify() on first push / change). */
14
+ identify?: Mapping$1.Value;
15
+ /** Destination-level group mapping (fires group() on first push / change). */
16
+ group?: Mapping$1.Value;
17
+ /** Downstream destination filtering. Passthrough to SDK integrations param. */
18
+ integrations?: Record<string, boolean | Record<string, unknown>>;
19
+ /** API path. Default: '/v1/batch'. */
20
+ path?: string;
21
+ /** Events to enqueue before flushing. Default: 20. */
22
+ flushAt?: number;
23
+ /** Max milliseconds before auto-flush. Default: 10000. */
24
+ flushInterval?: number;
25
+ /** Maximum batch payload size in bytes. Default: 460800 (~500KB). */
26
+ maxQueueSize?: number;
27
+ /** Maximum in-memory queue length. Default: 20000. */
28
+ maxInternalQueueSize?: number;
29
+ /** Log level. Default: 'info'. */
30
+ logLevel?: string;
31
+ /** Retry attempts for failed batches. Default: 3. */
32
+ retryCount?: number;
33
+ /** Completely disable the SDK. Default: false. */
34
+ enable?: boolean;
35
+ /** Enable gzip compression. Default: true. */
36
+ gzip?: boolean;
37
+ /** Runtime state -- not user-facing. Mutated by init/push. */
38
+ _analytics?: unknown;
39
+ _state?: RuntimeState;
40
+ }
41
+ interface RuntimeState {
42
+ lastIdentity?: {
43
+ userId?: string;
44
+ anonymousId?: string;
45
+ traitsHash?: string;
46
+ };
47
+ lastGroup?: {
48
+ groupId?: string;
49
+ traitsHash?: string;
50
+ };
51
+ }
52
+ type InitSettings = Partial<Settings>;
53
+ /**
54
+ * Per-rule mapping settings. Every feature is a walkerOS mapping value
55
+ * resolved via getMappingValue(). The resolved object's keys drive
56
+ * which RudderStack SDK methods to call.
57
+ */
58
+ interface Mapping {
59
+ identify?: Mapping$1.Value;
60
+ group?: Mapping$1.Value;
61
+ page?: Mapping$1.Value | boolean;
62
+ screen?: Mapping$1.Value | boolean;
63
+ alias?: Mapping$1.Value;
64
+ }
65
+ /**
66
+ * Env -- optional SDK override. Production leaves this undefined and the
67
+ * destination creates a real Analytics instance. Tests provide a mock via
68
+ * env.analytics.
69
+ */
70
+ interface Env extends DestinationServer.Env {
71
+ analytics?: RudderStackAnalyticsMock;
72
+ }
73
+ /**
74
+ * Mock-friendly interface for the Analytics instance methods the
75
+ * destination actually calls. Tests can provide this via env.analytics
76
+ * instead of the real SDK.
77
+ */
78
+ interface RudderStackAnalyticsMock {
79
+ track: (params: Record<string, unknown>) => void;
80
+ identify: (params: Record<string, unknown>) => void;
81
+ group: (params: Record<string, unknown>) => void;
82
+ page: (params: Record<string, unknown>) => void;
83
+ screen: (params: Record<string, unknown>) => void;
84
+ alias: (params: Record<string, unknown>) => void;
85
+ flush: (callback?: (err?: Error, data?: unknown) => void) => Promise<void>;
86
+ }
87
+ type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
88
+ interface Destination extends DestinationServer.Destination<Types> {
89
+ init: DestinationServer.InitFn<Types>;
90
+ }
91
+ type Config = {
92
+ settings: Settings;
93
+ } & DestinationServer.Config<Types>;
94
+ type InitFn = DestinationServer.InitFn<Types>;
95
+ type PushFn = DestinationServer.PushFn<Types>;
96
+ type PartialConfig = DestinationServer.PartialConfig<Types>;
97
+ type PushEvents = DestinationServer.PushEvents<Mapping>;
98
+ type Rule = Mapping$1.Rule<Mapping>;
99
+ type Rules = Mapping$1.Rules<Rule>;
100
+
101
+ type index_Config = Config;
102
+ type index_Destination = Destination;
103
+ type index_Env = Env;
104
+ type index_InitFn = InitFn;
105
+ type index_InitSettings = InitSettings;
106
+ type index_Mapping = Mapping;
107
+ type index_PartialConfig = PartialConfig;
108
+ type index_PushEvents = PushEvents;
109
+ type index_PushFn = PushFn;
110
+ type index_RudderStackAnalyticsMock = RudderStackAnalyticsMock;
111
+ type index_Rule = Rule;
112
+ type index_Rules = Rules;
113
+ type index_RuntimeState = RuntimeState;
114
+ type index_Settings = Settings;
115
+ type index_Types = Types;
116
+ 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 };
118
+ }
119
+
120
+ declare const destinationRudderStack: Destination;
121
+
122
+ export { index as DestinationRudderStack, destinationRudderStack as default, destinationRudderStack };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var t,e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,s={};((t,i)=>{for(var n in i)e(t,n,{get:i[n],enumerable:!0})})(s,{DestinationRudderStack:()=>d,default:()=>p,destinationRudderStack:()=>l}),module.exports=(t=s,((t,s,a,o)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let u of n(s))r.call(t,u)||u===a||e(t,u,{get:()=>s[u],enumerable:!(o=i(s,u))||o.enumerable});return t})(e({},"__esModule",{value:!0}),t));var a=require("@walkeros/core"),o=async function(t,{config:e,rule:i,data:n,collector:r,env:s,logger:o}){var d,l;const p=e.settings,g=p._analytics,y=(null==s?void 0:s.analytics)||g;if(!y)return void o.warn("RudderStack Analytics not initialized");const f=p._state||{},m=(null==i?void 0:i.settings)||{},v=new Date(t.timestamp||Date.now()),I=p.userId?u(await(0,a.getMappingValue)(t,p.userId,{collector:r})):void 0,w=p.anonymousId?u(await(0,a.getMappingValue)(t,p.anonymousId,{collector:r})):void 0;if(!I&&!w)return void o.warn("RudderStack requires userId or anonymousId; skipping event",{event:t.name});const b={};I&&(b.userId=I),w&&(b.anonymousId=w);const O=null!=(d=m.identify)?d:p.identify;if(void 0!==O){const e=await(0,a.getMappingValue)(t,O,{collector:r});(0,a.isObject)(e)&&function(t,e,i,n,r){var s;const o=n.lastIdentity||{},u=(0,a.isString)(e.userId)?e.userId:i.userId,d=(0,a.isObject)(e.traits)&&!(0,a.isArray)(e.traits)?e.traits:void 0,l=c(d),p=u!==o.userId,g=l!==(null!=(s=o.traitsHash)?s:"");if(!p&&!g)return;const y={...i,timestamp:r};u&&(y.userId=u);d&&(y.traits=d);t.identify(y),n.lastIdentity={userId:u,anonymousId:i.anonymousId,traitsHash:l}}(y,e,b,f,v)}const j=null!=(l=m.group)?l:p.group;if(void 0!==j){const e=await(0,a.getMappingValue)(t,j,{collector:r});(0,a.isObject)(e)&&function(t,e,i,n,r){var s;const o=(0,a.isString)(e.groupId)?e.groupId:void 0;if(!o)return;const u=n.lastGroup||{},d=(0,a.isObject)(e.traits)&&!(0,a.isArray)(e.traits)?e.traits:void 0,l=c(d),p=o!==u.groupId,g=l!==(null!=(s=u.traitsHash)?s:"");if(!p&&!g)return;const y={...i,groupId:o,timestamp:r};d&&(y.traits=d);t.group(y),n.lastGroup={groupId:o,traitsHash:l}}(y,e,b,f,v)}if(void 0!==m.page&&await async function(t,e,i,n,r,s){const o={...n,timestamp:s};if(!0===e)return o.name="",void t.page(o);const u=await(0,a.getMappingValue)(i,e,{collector:r});if(!(0,a.isObject)(u))return;const c=u;o.name=(0,a.isString)(c.name)?c.name:"",(0,a.isObject)(c.properties)&&!(0,a.isArray)(c.properties)&&(o.properties=c.properties);t.page(o)}(y,m.page,t,b,r,v),void 0!==m.screen&&await async function(t,e,i,n,r,s){const o={...n,timestamp:s};if(!0===e)return o.name="",void t.screen(o);const u=await(0,a.getMappingValue)(i,e,{collector:r});if(!(0,a.isObject)(u))return;const c=u;o.name=(0,a.isString)(c.name)?c.name:"",(0,a.isObject)(c.properties)&&!(0,a.isArray)(c.properties)&&(o.properties=c.properties);t.screen(o)}(y,m.screen,t,b,r,v),void 0!==m.alias&&await async function(t,e,i,n,r,s){const o=await(0,a.getMappingValue)(i,e,{collector:r});if(!(0,a.isObject)(o))return;const u=o,c=(0,a.isString)(u.previousId)?u.previousId:void 0;if(!c)return;const d={previousId:c,timestamp:s};n.userId&&(d.userId=n.userId);t.alias(d)}(y,m.alias,t,b,r,v),!0!==(null==i?void 0:i.skip)){const e=(0,a.isString)(null==i?void 0:i.name)?i.name:t.name,r=(0,a.isObject)(n)?n:{};y.track({...b,event:e,properties:r,timestamp:v})}p._state=f};function u(t){if((0,a.isString)(t)&&t.length>0)return t}function c(t){if(!t)return"";try{return JSON.stringify(t)}catch(t){return""}}var d={},l={type:"rudderstack",config:{},init({config:t,logger:e,env:i}){const n=function(t={},e){var i,n;const r=t.settings||{},{writeKey:s,dataPlaneUrl:a}=r;s||e.throw("Config settings writeKey missing"),a||e.throw("Config settings dataPlaneUrl missing");const o={...r,writeKey:s,dataPlaneUrl:a,userId:null!=(i=r.userId)?i:"user.id",anonymousId:null!=(n=r.anonymousId)?n:"user.session"};return{...t,settings:o}}(t,e),r=n.settings;if(!(null==i?void 0:i.analytics))try{const t=require("@rudderstack/rudder-sdk-node"),{writeKey:e,dataPlaneUrl:i,userId:n,anonymousId:s,identify:a,group:o,integrations:u,_analytics:c,_state:d,...l}=r,p=new t(e,{dataPlaneUrl:i,...l});r._analytics=p}catch(t){e.throw(`Failed to initialize RudderStack SDK: ${t}`)}return r._state={},n},push:async(t,e)=>await o(t,e),async destroy({config:t}){const e=((null==t?void 0:t.settings)||{})._analytics;e&&await e.flush()}},p=l;//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/push.ts","../src/types/index.ts"],"sourcesContent":["import type { Destination, Settings, RudderStackAnalyticsMock } from './types';\nimport { getConfig } from './config';\nimport { push } from './push';\n\n// Types\nexport * as DestinationRudderStack from './types';\n\nexport const destinationRudderStack: Destination = {\n type: 'rudderstack',\n\n config: {},\n\n init({ config: partialConfig, logger, env }) {\n const config = getConfig(partialConfig, logger);\n const settings = config.settings as Settings;\n\n // Use env.analytics mock if provided (testing), otherwise create real SDK\n const envAnalytics = (\n env as { analytics?: RudderStackAnalyticsMock } | undefined\n )?.analytics;\n\n if (!envAnalytics) {\n // Production path: create real Analytics instance\n try {\n const Analytics = require('@rudderstack/rudder-sdk-node');\n const {\n writeKey,\n dataPlaneUrl,\n userId: _u,\n anonymousId: _a,\n identify: _i,\n group: _g,\n integrations: _int,\n _analytics: _existing,\n _state: _existingState,\n ...sdkOptions\n } = settings;\n\n // RudderStack uses positional constructor: new Analytics(writeKey, opts)\n const analytics = new Analytics(writeKey, {\n dataPlaneUrl,\n ...sdkOptions,\n });\n settings._analytics = analytics;\n } catch (err) {\n logger.throw(`Failed to initialize RudderStack SDK: ${err}`);\n }\n }\n\n settings._state = {};\n\n return config;\n },\n\n async push(event, context) {\n return await push(event, context);\n },\n\n async destroy({ config }) {\n const settings = (config?.settings || {}) as Settings;\n const analytics = settings._analytics;\n if (analytics) {\n await (analytics as unknown as RudderStackAnalyticsMock).flush();\n }\n },\n};\n\nexport default destinationRudderStack;\n","import type { Config, Settings, PartialConfig } from './types';\nimport type { Logger } from '@walkeros/core';\n\nexport function getConfig(\n partialConfig: PartialConfig = {},\n logger: Logger.Instance,\n): Config {\n const settings = (partialConfig.settings || {}) as Partial<Settings>;\n const { writeKey, dataPlaneUrl } = settings;\n\n if (!writeKey) logger.throw('Config settings writeKey missing');\n if (!dataPlaneUrl) logger.throw('Config settings dataPlaneUrl missing');\n\n const settingsConfig: Settings = {\n ...settings,\n writeKey,\n dataPlaneUrl,\n userId: settings.userId ?? 'user.id',\n anonymousId: settings.anonymousId ?? 'user.session',\n };\n\n return { ...partialConfig, settings: settingsConfig };\n}\n","import type { WalkerOS } from '@walkeros/core';\nimport type {\n PushFn,\n Settings,\n RuntimeState,\n RudderStackAnalyticsMock,\n} from './types';\nimport { getMappingValue, isObject, isString, isArray } from '@walkeros/core';\n\nexport const push: PushFn = async function (\n event,\n { config, rule, data, collector, env, logger },\n) {\n const settings = config.settings as Settings;\n const analytics = settings._analytics as unknown as\n | RudderStackAnalyticsMock\n | undefined;\n const envAnalytics = (\n env as { analytics?: RudderStackAnalyticsMock } | undefined\n )?.analytics;\n const sdk = envAnalytics || analytics;\n\n if (!sdk) {\n logger.warn('RudderStack Analytics not initialized');\n return;\n }\n\n const state: RuntimeState = settings._state || {};\n const mappingSettings = rule?.settings || {};\n const timestamp = new Date(event.timestamp || Date.now());\n\n // 1. Resolve identity from event\n const userId = settings.userId\n ? resolveString(\n await getMappingValue(event, settings.userId, { collector }),\n )\n : undefined;\n const anonymousId = settings.anonymousId\n ? resolveString(\n await getMappingValue(event, settings.anonymousId, { collector }),\n )\n : undefined;\n\n if (!userId && !anonymousId) {\n logger.warn('RudderStack requires userId or anonymousId; skipping event', {\n event: event.name,\n });\n return;\n }\n\n // Build identity object for every SDK call\n const identity: Record<string, unknown> = {};\n if (userId) identity.userId = userId;\n if (anonymousId) identity.anonymousId = anonymousId;\n\n // 2. Identify -- rule-level overrides destination-level\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n applyIdentify(\n sdk,\n resolved as Record<string, unknown>,\n identity,\n state,\n timestamp,\n );\n }\n }\n\n // 3. Group -- rule-level overrides destination-level\n const groupMapping = mappingSettings.group ?? settings.group;\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, { collector });\n if (isObject(resolved)) {\n applyGroup(\n sdk,\n resolved as Record<string, unknown>,\n identity,\n state,\n timestamp,\n );\n }\n }\n\n // 4. Page\n if (mappingSettings.page !== undefined) {\n await applyPage(\n sdk,\n mappingSettings.page,\n event,\n identity,\n collector,\n timestamp,\n );\n }\n\n // 5. Screen\n if (mappingSettings.screen !== undefined) {\n await applyScreen(\n sdk,\n mappingSettings.screen,\n event,\n identity,\n collector,\n timestamp,\n );\n }\n\n // 6. Alias\n if (mappingSettings.alias !== undefined) {\n await applyAlias(\n sdk,\n mappingSettings.alias,\n event,\n identity,\n collector,\n timestamp,\n );\n }\n\n // 7. Track (unless skip: true)\n if (rule?.skip !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data) ? (data as Record<string, unknown>) : {};\n\n sdk.track({\n ...identity,\n event: eventName,\n properties,\n timestamp,\n });\n }\n\n settings._state = state;\n};\n\nfunction resolveString(value: unknown): string | undefined {\n if (isString(value) && value.length > 0) return value;\n return undefined;\n}\n\nfunction hashTraits(traits: Record<string, unknown> | undefined): string {\n if (!traits) return '';\n try {\n return JSON.stringify(traits);\n } catch {\n return '';\n }\n}\n\nfunction applyIdentify(\n sdk: RudderStackAnalyticsMock,\n resolved: Record<string, unknown>,\n identity: Record<string, unknown>,\n state: RuntimeState,\n timestamp: Date,\n): void {\n const last = state.lastIdentity || {};\n\n // Per-event identify can override userId\n const identifyUserId = isString(resolved.userId)\n ? resolved.userId\n : (identity.userId as string | undefined);\n const traits =\n isObject(resolved.traits) && !isArray(resolved.traits)\n ? (resolved.traits as Record<string, unknown>)\n : undefined;\n\n const traitsHash = hashTraits(traits);\n const userIdChanged = identifyUserId !== last.userId;\n const traitsChanged = traitsHash !== (last.traitsHash ?? '');\n\n if (!userIdChanged && !traitsChanged) return;\n\n const params: Record<string, unknown> = {\n ...identity,\n timestamp,\n };\n if (identifyUserId) params.userId = identifyUserId;\n if (traits) params.traits = traits;\n\n sdk.identify(params);\n\n state.lastIdentity = {\n userId: identifyUserId,\n anonymousId: identity.anonymousId as string | undefined,\n traitsHash,\n };\n}\n\nfunction applyGroup(\n sdk: RudderStackAnalyticsMock,\n resolved: Record<string, unknown>,\n identity: Record<string, unknown>,\n state: RuntimeState,\n timestamp: Date,\n): void {\n const groupId = isString(resolved.groupId) ? resolved.groupId : undefined;\n if (!groupId) return;\n\n const last = state.lastGroup || {};\n const traits =\n isObject(resolved.traits) && !isArray(resolved.traits)\n ? (resolved.traits as Record<string, unknown>)\n : undefined;\n\n const traitsHash = hashTraits(traits);\n const groupIdChanged = groupId !== last.groupId;\n const traitsChanged = traitsHash !== (last.traitsHash ?? '');\n if (!groupIdChanged && !traitsChanged) return;\n\n const params: Record<string, unknown> = {\n ...identity,\n groupId,\n timestamp,\n };\n if (traits) params.traits = traits;\n\n sdk.group(params);\n\n state.lastGroup = { groupId, traitsHash };\n}\n\nasync function applyPage(\n sdk: RudderStackAnalyticsMock,\n pageMapping: unknown,\n event: WalkerOS.Event,\n identity: Record<string, unknown>,\n collector: unknown,\n timestamp: Date,\n): Promise<void> {\n const params: Record<string, unknown> = { ...identity, timestamp };\n\n if (pageMapping === true) {\n // Minimal page call -- RudderStack requires name, use empty string\n params.name = '';\n sdk.page(params);\n return;\n }\n\n const resolved = await getMappingValue(\n event,\n pageMapping as Parameters<typeof getMappingValue>[1],\n { collector } as Parameters<typeof getMappingValue>[2],\n );\n if (!isObject(resolved)) return;\n\n const r = resolved as {\n name?: unknown;\n properties?: unknown;\n };\n // RudderStack requires name -- fall back to empty string\n params.name = isString(r.name) ? r.name : '';\n if (isObject(r.properties) && !isArray(r.properties)) {\n params.properties = r.properties;\n }\n\n sdk.page(params);\n}\n\nasync function applyScreen(\n sdk: RudderStackAnalyticsMock,\n screenMapping: unknown,\n event: WalkerOS.Event,\n identity: Record<string, unknown>,\n collector: unknown,\n timestamp: Date,\n): Promise<void> {\n const params: Record<string, unknown> = { ...identity, timestamp };\n\n if (screenMapping === true) {\n // Minimal screen call -- RudderStack requires name, use empty string\n params.name = '';\n sdk.screen(params);\n return;\n }\n\n const resolved = await getMappingValue(\n event,\n screenMapping as Parameters<typeof getMappingValue>[1],\n { collector } as Parameters<typeof getMappingValue>[2],\n );\n if (!isObject(resolved)) return;\n\n const r = resolved as {\n name?: unknown;\n properties?: unknown;\n };\n // RudderStack requires name -- fall back to empty string\n params.name = isString(r.name) ? r.name : '';\n if (isObject(r.properties) && !isArray(r.properties)) {\n params.properties = r.properties;\n }\n\n sdk.screen(params);\n}\n\nasync function applyAlias(\n sdk: RudderStackAnalyticsMock,\n aliasMapping: unknown,\n event: WalkerOS.Event,\n identity: Record<string, unknown>,\n collector: unknown,\n timestamp: Date,\n): Promise<void> {\n const resolved = await getMappingValue(\n event,\n aliasMapping as Parameters<typeof getMappingValue>[1],\n { collector } as Parameters<typeof getMappingValue>[2],\n );\n if (!isObject(resolved)) return;\n\n const r = resolved as { previousId?: unknown };\n const previousId = isString(r.previousId) ? r.previousId : undefined;\n if (!previousId) return;\n\n const params: Record<string, unknown> = {\n previousId,\n timestamp,\n };\n // Alias uses userId (the new canonical ID) -- not full identity spread\n if (identity.userId) params.userId = identity.userId;\n\n sdk.alias(params);\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationServer } from '@walkeros/server-core';\n\nexport interface Settings {\n /** RudderStack source write key (required). */\n writeKey: string;\n /** RudderStack data plane URL (required). */\n dataPlaneUrl: string;\n /** walkerOS mapping value path to resolve userId from each event. */\n userId?: string;\n /** walkerOS mapping value path to resolve anonymousId from each event. */\n anonymousId?: string;\n /** Destination-level identity mapping (fires identify() on first push / change). */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group mapping (fires group() on first push / change). */\n group?: WalkerOSMapping.Value;\n /** Downstream destination filtering. Passthrough to SDK integrations param. */\n integrations?: Record<string, boolean | Record<string, unknown>>;\n // SDK constructor options (passthrough)\n /** API path. Default: '/v1/batch'. */\n path?: string;\n /** Events to enqueue before flushing. Default: 20. */\n flushAt?: number;\n /** Max milliseconds before auto-flush. Default: 10000. */\n flushInterval?: number;\n /** Maximum batch payload size in bytes. Default: 460800 (~500KB). */\n maxQueueSize?: number;\n /** Maximum in-memory queue length. Default: 20000. */\n maxInternalQueueSize?: number;\n /** Log level. Default: 'info'. */\n logLevel?: string;\n /** Retry attempts for failed batches. Default: 3. */\n retryCount?: number;\n /** Completely disable the SDK. Default: false. */\n enable?: boolean;\n /** Enable gzip compression. Default: true. */\n gzip?: boolean;\n /** Runtime state -- not user-facing. Mutated by init/push. */\n _analytics?: unknown;\n _state?: RuntimeState;\n}\n\nexport interface RuntimeState {\n lastIdentity?: {\n userId?: string;\n anonymousId?: string;\n traitsHash?: string;\n };\n lastGroup?: {\n groupId?: string;\n traitsHash?: string;\n };\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Every feature is a walkerOS mapping value\n * resolved via getMappingValue(). The resolved object's keys drive\n * which RudderStack SDK methods to call.\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n page?: WalkerOSMapping.Value | boolean;\n screen?: WalkerOSMapping.Value | boolean;\n alias?: WalkerOSMapping.Value;\n}\n\n/**\n * Env -- optional SDK override. Production leaves this undefined and the\n * destination creates a real Analytics instance. Tests provide a mock via\n * env.analytics.\n */\nexport interface Env extends DestinationServer.Env {\n analytics?: RudderStackAnalyticsMock;\n}\n\n/**\n * Mock-friendly interface for the Analytics instance methods the\n * destination actually calls. Tests can provide this via env.analytics\n * instead of the real SDK.\n */\nexport interface RudderStackAnalyticsMock {\n track: (params: Record<string, unknown>) => void;\n identify: (params: Record<string, unknown>) => void;\n group: (params: Record<string, unknown>) => void;\n page: (params: Record<string, unknown>) => void;\n screen: (params: Record<string, unknown>) => void;\n alias: (params: Record<string, unknown>) => void;\n flush: (callback?: (err?: Error, data?: unknown) => void) => Promise<void>;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport interface Destination extends DestinationServer.Destination<Types> {\n init: DestinationServer.InitFn<Types>;\n}\n\nexport type Config = {\n settings: Settings;\n} & DestinationServer.Config<Types>;\n\nexport type InitFn = DestinationServer.InitFn<Types>;\nexport type PushFn = DestinationServer.PushFn<Types>;\nexport type PartialConfig = DestinationServer.PartialConfig<Types>;\nexport type PushEvents = DestinationServer.PushEvents<Mapping>;\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,UACd,gBAA+B,CAAC,GAChC,QACQ;AANV;AAOE,QAAM,WAAY,cAAc,YAAY,CAAC;AAC7C,QAAM,EAAE,UAAU,aAAa,IAAI;AAEnC,MAAI,CAAC,SAAU,QAAO,MAAM,kCAAkC;AAC9D,MAAI,CAAC,aAAc,QAAO,MAAM,sCAAsC;AAEtE,QAAM,iBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,SAAQ,cAAS,WAAT,YAAmB;AAAA,IAC3B,cAAa,cAAS,gBAAT,YAAwB;AAAA,EACvC;AAEA,SAAO,EAAE,GAAG,eAAe,UAAU,eAAe;AACtD;;;ACfA,k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IAAM,yBAAsC;AAAA,EACjD,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAQ,eAAe,QAAQ,IAAI,GAAG;AAC3C,UAAM,SAAS,UAAU,eAAe,MAAM;AAC9C,UAAM,WAAW,OAAO;AAGxB,UAAM,eACJ,2BACC;AAEH,QAAI,CAAC,cAAc;AAEjB,UAAI;AACF,cAAM,YAAY,QAAQ,8BAA8B;AACxD,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,UACR,aAAa;AAAA,UACb,UAAU;AAAA,UACV,OAAO;AAAA,UACP,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,QAAQ;AAAA,UACR,GAAG;AAAA,QACL,IAAI;AAGJ,cAAM,YAAY,IAAI,UAAU,UAAU;AAAA,UACxC;AAAA,UACA,GAAG;AAAA,QACL,CAAC;AACD,iBAAS,aAAa;AAAA,MACxB,SAAS,KAAK;AACZ,eAAO,MAAM,yCAAyC,GAAG,EAAE;AAAA,MAC7D;AAAA,IACF;AAEA,aAAS,SAAS,CAAC;AAEnB,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,OAAO,SAAS;AACzB,WAAO,MAAM,KAAK,OAAO,OAAO;AAAA,EAClC;AAAA,EAEA,MAAM,QAAQ,EAAE,OAAO,GAAG;AACxB,UAAM,YAAY,iCAAQ,aAAY,CAAC;AACvC,UAAM,YAAY,SAAS;AAC3B,QAAI,WAAW;AACb,YAAO,UAAkD,MAAM;AAAA,IACjE;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var t=(t=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(t,{get:(t,e)=>("undefined"!=typeof require?require:t)[e]}):t)(function(t){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import{getMappingValue as e,isObject as n,isString as r,isArray as i}from"@walkeros/core";var s=async function(t,{config:s,rule:u,data:d,collector:c,env:l,logger:p}){var f,y;const m=s.settings,g=m._analytics,v=(null==l?void 0:l.analytics)||g;if(!v)return void p.warn("RudderStack Analytics not initialized");const I=m._state||{},w=(null==u?void 0:u.settings)||{},h=new Date(t.timestamp||Date.now()),k=m.userId?a(await e(t,m.userId,{collector:c})):void 0,q=m.anonymousId?a(await e(t,m.anonymousId,{collector:c})):void 0;if(!k&&!q)return void p.warn("RudderStack requires userId or anonymousId; skipping event",{event:t.name});const _={};k&&(_.userId=k),q&&(_.anonymousId=q);const P=null!=(f=w.identify)?f:m.identify;if(void 0!==P){const s=await e(t,P,{collector:c});n(s)&&function(t,e,s,a,u){var d;const c=a.lastIdentity||{},l=r(e.userId)?e.userId:s.userId,p=n(e.traits)&&!i(e.traits)?e.traits:void 0,f=o(p),y=l!==c.userId,m=f!==(null!=(d=c.traitsHash)?d:"");if(!y&&!m)return;const g={...s,timestamp:u};l&&(g.userId=l);p&&(g.traits=p);t.identify(g),a.lastIdentity={userId:l,anonymousId:s.anonymousId,traitsHash:f}}(v,s,_,I,h)}const S=null!=(y=w.group)?y:m.group;if(void 0!==S){const s=await e(t,S,{collector:c});n(s)&&function(t,e,s,a,u){var d;const c=r(e.groupId)?e.groupId:void 0;if(!c)return;const l=a.lastGroup||{},p=n(e.traits)&&!i(e.traits)?e.traits:void 0,f=o(p),y=c!==l.groupId,m=f!==(null!=(d=l.traitsHash)?d:"");if(!y&&!m)return;const g={...s,groupId:c,timestamp:u};p&&(g.traits=p);t.group(g),a.lastGroup={groupId:c,traitsHash:f}}(v,s,_,I,h)}if(void 0!==w.page&&await async function(t,s,a,o,u,d){const c={...o,timestamp:d};if(!0===s)return c.name="",void t.page(c);const l=await e(a,s,{collector:u});if(!n(l))return;const p=l;c.name=r(p.name)?p.name:"",n(p.properties)&&!i(p.properties)&&(c.properties=p.properties);t.page(c)}(v,w.page,t,_,c,h),void 0!==w.screen&&await async function(t,s,a,o,u,d){const c={...o,timestamp:d};if(!0===s)return c.name="",void t.screen(c);const l=await e(a,s,{collector:u});if(!n(l))return;const p=l;c.name=r(p.name)?p.name:"",n(p.properties)&&!i(p.properties)&&(c.properties=p.properties);t.screen(c)}(v,w.screen,t,_,c,h),void 0!==w.alias&&await async function(t,i,s,a,o,u){const d=await e(s,i,{collector:o});if(!n(d))return;const c=d,l=r(c.previousId)?c.previousId:void 0;if(!l)return;const p={previousId:l,timestamp:u};a.userId&&(p.userId=a.userId);t.alias(p)}(v,w.alias,t,_,c,h),!0!==(null==u?void 0:u.skip)){const e=r(null==u?void 0:u.name)?u.name:t.name,i=n(d)?d:{};v.track({..._,event:e,properties:i,timestamp:h})}m._state=I};function a(t){if(r(t)&&t.length>0)return t}function o(t){if(!t)return"";try{return JSON.stringify(t)}catch(t){return""}}var u={},d={type:"rudderstack",config:{},init({config:e,logger:n,env:r}){const i=function(t={},e){var n,r;const i=t.settings||{},{writeKey:s,dataPlaneUrl:a}=i;s||e.throw("Config settings writeKey missing"),a||e.throw("Config settings dataPlaneUrl missing");const o={...i,writeKey:s,dataPlaneUrl:a,userId:null!=(n=i.userId)?n:"user.id",anonymousId:null!=(r=i.anonymousId)?r:"user.session"};return{...t,settings:o}}(e,n),s=i.settings;if(!(null==r?void 0:r.analytics))try{const e=t("@rudderstack/rudder-sdk-node"),{writeKey:n,dataPlaneUrl:r,userId:i,anonymousId:a,identify:o,group:u,integrations:d,_analytics:c,_state:l,...p}=s,f=new e(n,{dataPlaneUrl:r,...p});s._analytics=f}catch(t){n.throw(`Failed to initialize RudderStack SDK: ${t}`)}return s._state={},i},push:async(t,e)=>await s(t,e),async destroy({config:t}){const e=((null==t?void 0:t.settings)||{})._analytics;e&&await e.flush()}},c=d;export{u as DestinationRudderStack,c as default,d as destinationRudderStack};//# sourceMappingURL=index.mjs.map