@jitsu/functions-lib 1.9.11 → 1.9.13-canary.1167.20250215132227

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.
@@ -1,12 +1,12 @@
1
- @jitsu/functions-lib:build: cache hit, replaying output 0c8f3ad92b163467
2
- @jitsu/functions-lib:build: 
3
- @jitsu/functions-lib:build: > @jitsu/functions-lib@0.0.0 build /Users/ildarnurislamov/Projects/newjitsu/libs/functions
4
- @jitsu/functions-lib:build: > pnpm compile && rollup -c
5
- @jitsu/functions-lib:build: 
6
- @jitsu/functions-lib:build: 
7
- @jitsu/functions-lib:build: > @jitsu/functions-lib@0.0.0 compile /Users/ildarnurislamov/Projects/newjitsu/libs/functions
8
- @jitsu/functions-lib:build: > tsc -p .
9
- @jitsu/functions-lib:build: 
10
- @jitsu/functions-lib:build: 
11
- @jitsu/functions-lib:build: ./src/index.ts → dist/index.es.js, dist/index.cjs.js...
12
- @jitsu/functions-lib:build: created dist/index.es.js, dist/index.cjs.js in 717ms
1
+ @jitsu/functions-lib:build: cache hit, replaying output 314a8cfdde7a5d3e
2
+ @jitsu/functions-lib:build: 
3
+ @jitsu/functions-lib:build: > @jitsu/functions-lib@0.0.0 build /Users/ildarnurislamov/Projects/newjitsu/libs/functions
4
+ @jitsu/functions-lib:build: > pnpm compile && rollup -c
5
+ @jitsu/functions-lib:build: 
6
+ @jitsu/functions-lib:build: 
7
+ @jitsu/functions-lib:build: > @jitsu/functions-lib@0.0.0 compile /Users/ildarnurislamov/Projects/newjitsu/libs/functions
8
+ @jitsu/functions-lib:build: > tsc -p .
9
+ @jitsu/functions-lib:build: 
10
+ @jitsu/functions-lib:build: 
11
+ @jitsu/functions-lib:build: ./src/index.ts → dist/index.es.js, dist/index.cjs.js...
12
+ @jitsu/functions-lib:build: created dist/index.es.js, dist/index.cjs.js in 749ms
@@ -0,0 +1,315 @@
1
+ import { AnalyticsServerEvent } from "@jitsu/protocols/analytics";
2
+ import type { Event as JitsuLegacyEvent } from "@jitsu/sdk-js";
3
+ import { FullContext, UserAgent } from "@jitsu/protocols/functions";
4
+ import { fromJitsuClassic, removeUndefined, TableNameParameter, toJitsuClassic, toSnakeCase } from "../src";
5
+ import { classicEvents } from "./data/classic-events";
6
+
7
+ const identify: AnalyticsServerEvent = {
8
+ writeKey: "writeKey",
9
+ messageId: "a6c09b16-c2bc-4193-990f-5e2b694ae610",
10
+ anonymousId: "6638caf0-d2c2-4bc0-aecf-8b290b559a37",
11
+ context: {
12
+ ip: "141.136.89.181",
13
+ campaign: {
14
+ medium: "medium",
15
+ name: "campaign",
16
+ source: "source",
17
+ },
18
+ library: {
19
+ name: "jitsu-js",
20
+ version: "1.0.0",
21
+ },
22
+ locale: "en-US",
23
+ page: {
24
+ host: "localhost:3088",
25
+ path: "/basic.html",
26
+ referrer: "https://referrer.com",
27
+ referring_domain: "referrer.com",
28
+ search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
29
+ title: "Tracking page",
30
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
31
+ },
32
+ screen: {
33
+ density: 1,
34
+ height: 720,
35
+ innerHeight: 720,
36
+ innerWidth: 1280,
37
+ width: 1280,
38
+ },
39
+ userAgent:
40
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/107.0.5304.18 Safari/537.36",
41
+ },
42
+ sentAt: "2022-11-14T08:56:34.387Z",
43
+ receivedAt: "2022-11-14T08:56:40.000Z",
44
+ timestamp: "2022-11-14T08:56:34.387Z",
45
+ traits: {
46
+ caseName: "basic-identify",
47
+ CaseLastName: "Doe",
48
+ User_Name: "jj",
49
+ email: "john.doe2@gmail.com",
50
+ },
51
+ type: "identify",
52
+ userId: "userId2",
53
+ };
54
+
55
+ const legacyIdentifyExpectedS3: Omit<JitsuLegacyEvent, "local_tz_offset"> & { local_tz_offset?: number } = {
56
+ _timestamp: "2022-11-14T08:56:40.000Z",
57
+ anon_ip: "141.136.89.0",
58
+ doc_path: "/basic.html",
59
+ doc_search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
60
+ source_ip: "141.136.89.181",
61
+ api_key: "writeKey",
62
+ doc_host: "localhost:3088",
63
+ eventn_ctx_event_id: "a6c09b16-c2bc-4193-990f-5e2b694ae610",
64
+ event_type: "identify",
65
+ page_title: "Tracking page",
66
+ referer: "https://referrer.com",
67
+ src: "jitsu",
68
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
69
+ user: {
70
+ anonymous_id: "6638caf0-d2c2-4bc0-aecf-8b290b559a37",
71
+ id: "userId2",
72
+ email: "john.doe2@gmail.com",
73
+ caseName: "basic-identify",
74
+ CaseLastName: "Doe",
75
+ User_Name: "jj",
76
+ },
77
+ user_agent:
78
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/107.0.5304.18 Safari/537.36",
79
+ user_language: "en-US",
80
+ utc_time: "2022-11-14T08:56:34.387Z",
81
+ utm: {
82
+ medium: "medium",
83
+ name: "campaign",
84
+ source: "source",
85
+ },
86
+ screen_resolution: "1280x720",
87
+ vp_size: "1280x720",
88
+ };
89
+
90
+ const legacyIdentifyExpectedWarehouse: Omit<JitsuLegacyEvent, "local_tz_offset"> & { local_tz_offset?: number } = {
91
+ _timestamp: "2022-11-14T08:56:40.000Z",
92
+ anon_ip: "141.136.89.0",
93
+ doc_path: "/basic.html",
94
+ doc_search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
95
+ source_ip: "141.136.89.181",
96
+ api_key: "writeKey",
97
+ doc_host: "localhost:3088",
98
+ eventn_ctx_event_id: "a6c09b16-c2bc-4193-990f-5e2b694ae610",
99
+ event_type: "identify",
100
+ page_title: "Tracking page",
101
+ referer: "https://referrer.com",
102
+ src: "jitsu",
103
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
104
+ user: {
105
+ anonymous_id: "6638caf0-d2c2-4bc0-aecf-8b290b559a37",
106
+ id: "userId2",
107
+ email: "john.doe2@gmail.com",
108
+ casename: "basic-identify",
109
+ caselastname: "Doe",
110
+ user_name: "jj",
111
+ },
112
+ user_agent:
113
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/107.0.5304.18 Safari/537.36",
114
+ user_language: "en-US",
115
+ utc_time: "2022-11-14T08:56:34.387Z",
116
+ utm: {
117
+ medium: "medium",
118
+ name: "campaign",
119
+ source: "source",
120
+ },
121
+ screen_resolution: "1280x720",
122
+ vp_size: "1280x720",
123
+ };
124
+
125
+ const page: AnalyticsServerEvent = {
126
+ messageId: "d0c6abf6-97f7-487a-a197-8f236c728fa8",
127
+ anonymousId: "6638caf0-d2c2-4bc0-aecf-8b290b559a37",
128
+ context: {
129
+ campaign: {
130
+ medium: "medium",
131
+ name: "campaign",
132
+ source: "source",
133
+ },
134
+ library: {
135
+ name: "jitsu-js",
136
+ version: "1.0.0",
137
+ },
138
+ locale: "en-US",
139
+ page: {
140
+ host: "localhost:3088",
141
+ path: "/basic.html",
142
+ referrer: "https://referrer.com",
143
+ referring_domain: "",
144
+ search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
145
+ title: "Tracking page",
146
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
147
+ },
148
+ screen: {
149
+ density: 1,
150
+ height: 720,
151
+ innerHeight: 720,
152
+ innerWidth: 1280,
153
+ width: 1280,
154
+ },
155
+ traits: {
156
+ caseName: "identify-without-user-id",
157
+ CaseLastName: "Doe",
158
+ User_Name: "jj",
159
+ email: "john.doe3@gmail.com",
160
+ },
161
+ userAgent:
162
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/107.0.5304.18 Safari/537.36",
163
+ },
164
+ properties: {
165
+ caseName: "page-with-name",
166
+ nestedProp: {
167
+ "my-Prop1": "myValue",
168
+ myProp2: "myValue",
169
+ },
170
+ hash: "",
171
+ height: 720,
172
+ name: "test-page",
173
+ path: "/basic.html",
174
+ search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
175
+ title: "Tracking page",
176
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
177
+ width: 1280,
178
+ },
179
+ receivedAt: "2022-11-14T08:56:40.000Z",
180
+ sentAt: "2022-11-14T08:56:34.395Z",
181
+ timestamp: "2022-11-14T08:56:34.395Z",
182
+ type: "page",
183
+ userId: "userId2",
184
+ };
185
+
186
+ const legacyPageExpectedS3 = {
187
+ _timestamp: "2022-11-14T08:56:40.000Z",
188
+ api_key: "",
189
+ doc_host: "localhost:3088",
190
+ doc_path: "/basic.html",
191
+ doc_search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
192
+ eventn_ctx_event_id: "d0c6abf6-97f7-487a-a197-8f236c728fa8",
193
+ event_type: "page",
194
+ page_title: "Tracking page",
195
+ referer: "https://referrer.com",
196
+ src: "jitsu",
197
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
198
+ user: {
199
+ anonymous_id: "6638caf0-d2c2-4bc0-aecf-8b290b559a37",
200
+ id: "userId2",
201
+ email: "john.doe3@gmail.com",
202
+ caseName: "identify-without-user-id",
203
+ CaseLastName: "Doe",
204
+ User_Name: "jj",
205
+ },
206
+ user_agent:
207
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/107.0.5304.18 Safari/537.36",
208
+ user_language: "en-US",
209
+ utc_time: "2022-11-14T08:56:34.395Z",
210
+ utm: {
211
+ medium: "medium",
212
+ name: "campaign",
213
+ source: "source",
214
+ },
215
+ caseName: "page-with-name",
216
+ nestedProp: {
217
+ "my-Prop1": "myValue",
218
+ myProp2: "myValue",
219
+ },
220
+ hash: "",
221
+ name: "test-page",
222
+ screen_resolution: "1280x720",
223
+ vp_size: "1280x720",
224
+ };
225
+
226
+ const legacyPageExpectedWarehouse = {
227
+ _timestamp: "2022-11-14T08:56:40.000Z",
228
+ api_key: "",
229
+ doc_host: "localhost:3088",
230
+ doc_path: "/basic.html",
231
+ doc_search: "?utm_source=source&utm_medium=medium&utm_campaign=campaign",
232
+ eventn_ctx_event_id: "d0c6abf6-97f7-487a-a197-8f236c728fa8",
233
+ event_type: "page",
234
+ page_title: "Tracking page",
235
+ referer: "https://referrer.com",
236
+ src: "jitsu",
237
+ url: "https://localhost:3088/basic.html?utm_source=source&utm_medium=medium&utm_campaign=campaign",
238
+ user: {
239
+ anonymous_id: "6638caf0-d2c2-4bc0-aecf-8b290b559a37",
240
+ id: "userId2",
241
+ email: "john.doe3@gmail.com",
242
+ casename: "identify-without-user-id",
243
+ caselastname: "Doe",
244
+ user_name: "jj",
245
+ },
246
+ user_agent:
247
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/107.0.5304.18 Safari/537.36",
248
+ user_language: "en-US",
249
+ utc_time: "2022-11-14T08:56:34.395Z",
250
+ utm: {
251
+ medium: "medium",
252
+ name: "campaign",
253
+ source: "source",
254
+ },
255
+ casename: "page-with-name",
256
+ nestedprop: {
257
+ my_prop1: "myValue",
258
+ myprop2: "myValue",
259
+ },
260
+ hash: "",
261
+ name: "test-page",
262
+ screen_resolution: "1280x720",
263
+ vp_size: "1280x720",
264
+ };
265
+
266
+ test("legacy event s3", () => {
267
+ const identifyLegacyResult = toJitsuClassic(identify, {
268
+ props: { keepOriginalNames: true },
269
+ destination: { type: "s3" },
270
+ } as unknown as FullContext);
271
+ const pageLegacyResult = toJitsuClassic(page, {
272
+ props: { keepOriginalNames: true },
273
+ destination: { type: "s3" },
274
+ } as unknown as FullContext);
275
+ console.log(JSON.stringify(identifyLegacyResult, null, 2));
276
+ expect(identifyLegacyResult).toStrictEqual(legacyIdentifyExpectedS3);
277
+
278
+ console.log(JSON.stringify(pageLegacyResult, null, 2));
279
+ expect(pageLegacyResult).toStrictEqual(legacyPageExpectedS3);
280
+ });
281
+
282
+ test("legacy event warehouse", () => {
283
+ const identifyLegacyResult = toJitsuClassic(identify, {
284
+ props: { keepOriginalNames: true },
285
+ destination: { type: "postgres" },
286
+ } as unknown as FullContext);
287
+ const pageLegacyResult = toJitsuClassic(page, {
288
+ props: { keepOriginalNames: true },
289
+ destination: { type: "postgres" },
290
+ } as unknown as FullContext);
291
+ console.log(JSON.stringify(identifyLegacyResult, null, 2));
292
+ expect(identifyLegacyResult).toStrictEqual(legacyIdentifyExpectedWarehouse);
293
+
294
+ console.log(JSON.stringify(pageLegacyResult, null, 2));
295
+ expect(pageLegacyResult).toStrictEqual(legacyPageExpectedWarehouse);
296
+ });
297
+
298
+ test("classic events mapping", () => {
299
+ //load events from json
300
+ for (const event of classicEvents) {
301
+ if (Object.keys(event.click_id || {}).length === 0) {
302
+ delete event.click_id;
303
+ }
304
+ if (Object.keys(event.ids || {}).length === 0) {
305
+ delete event.ids;
306
+ }
307
+ const restored = fromJitsuClassic(event);
308
+ const mapped = toJitsuClassic(
309
+ restored as AnalyticsServerEvent,
310
+ { props: { keepOriginalNames: true }, destination: { type: "s3" } } as unknown as FullContext
311
+ );
312
+ delete mapped.anon_ip;
313
+ expect(mapped).toStrictEqual(event);
314
+ }
315
+ });