@jitsu/functions-lib 2.14.0-beta.8 → 2.14.0-beta.85

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.
@@ -42,5 +42,5 @@ export declare class HTTPError extends Error {
42
42
  response: string;
43
43
  };
44
44
  }
45
- export declare function toJitsuClassic(event: AnalyticsServerEvent, ctx: FullContext): AnyEvent;
45
+ export declare function toJitsuClassic(event: AnalyticsServerEvent, ctx: FullContext, bulker?: boolean): AnyEvent;
46
46
  export declare function fromJitsuClassic(event: AnyEvent): AnyEvent;
package/package.json CHANGED
@@ -1,31 +1,40 @@
1
1
  {
2
2
  "name": "@jitsu/functions-lib",
3
- "version": "2.14.0-beta.8",
4
- "main": "dist/index.cjs.js",
5
- "module": "dist/index.es.js",
6
- "types": "dist/index.d.ts",
3
+ "version": "2.14.0-beta.85",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/jitsucom/jitsu",
7
+ "directory": "libs/functions"
8
+ },
9
+ "main": "src/index.ts",
10
+ "types": "src/index.ts",
7
11
  "description": "",
8
12
  "author": "Jitsu Dev Team <dev@jitsu.com>",
9
13
  "publishConfig": {
14
+ "main": "dist/index.cjs.js",
15
+ "module": "dist/index.es.js",
16
+ "types": "dist/index.d.ts",
10
17
  "access": "public"
11
18
  },
19
+ "files": [
20
+ "dist",
21
+ "package.json"
22
+ ],
12
23
  "license": "MIT",
13
24
  "private": false,
14
25
  "scripts": {
15
26
  "//build-deps": "Required by turbo ^build-deps - builds dist/ for workspace packages that import this",
16
27
  "build-deps": "pnpm run build",
17
- "//typecheck": "Since this module generates types, we should run build during typecheck",
18
- "typecheck": "tsc -p . && rollup -c",
19
- "build": "tsc -p . && rollup -c",
28
+ "typecheck": "tsc --noEmit",
29
+ "build": "tsc && tsx bundle.mts",
30
+ "prepublishOnly": "pnpm run build",
20
31
  "test": "vitest run"
21
32
  },
22
33
  "devDependencies": {
23
34
  "@jitsu/common-config": "workspace:*",
24
35
  "@jitsu/protocols": "workspace:*",
25
- "rollup": "^4.24.3",
26
- "@rollup/plugin-typescript": "^11.1.5",
27
- "@rollup/plugin-node-resolve": "^16.0.0",
28
- "@rollup/plugin-commonjs": "^28.0.2",
36
+ "esbuild": "catalog:",
37
+ "tsx": "catalog:",
29
38
  "@types/node": "catalog:",
30
39
  "@vitest/ui": "catalog:",
31
40
  "tslib": "catalog:",
@@ -1,315 +0,0 @@
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
- });
@@ -1,168 +0,0 @@
1
- export const classicEvents = [
2
- {
3
- _timestamp: "2024-12-25T14:23:48.606561Z",
4
- api_key: "js.123.123",
5
- click_id: {},
6
- doc_encoding: "UTF-8",
7
- doc_host: "events.example.com",
8
- doc_path: "/a-v/123",
9
- doc_search: "",
10
- event_type: "user_identify",
11
- eventn_ctx_event_id: "1d199165-fdf3-4051-82fc-08a8c5502f33",
12
- ids: {
13
- ga: "GA1.1.123.123",
14
- },
15
- local_tz_offset: 420,
16
- page_title: "aa.aa.24",
17
- referer: "",
18
- screen_resolution: "1680x1050",
19
- source_ip: "127.0.13.36",
20
- src: "jitsu",
21
- url: "https://events.example.com/a-v/123",
22
- user: {
23
- anonymous_id: "5adv25gea6",
24
- email: "user@example.com",
25
- hashed_anonymous_id: "41217f4f06dba2b145dbd7d0879a871e",
26
- name: "John Doe",
27
- uid: "123",
28
- },
29
- user_agent:
30
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
31
- user_language: "en-US",
32
- utc_time: "2024-12-25T14:23:46.483000Z",
33
- utm: {},
34
- vp_size: "1384x775",
35
- },
36
- {
37
- _timestamp: "2024-12-25T14:31:48.875505Z",
38
- api_key: "s2s.123.123",
39
- common_properties: {
40
- c_version: "1.1.11",
41
- client: {
42
- creation_timestamp: "2024-12-25T14:31:48.794613+00:00",
43
- id: "123",
44
- },
45
- in_v: false,
46
- a_version: null,
47
- },
48
- event_type: "serve_init",
49
- eventn_ctx_event_id: "99406a96-3bc3-4939-a3cc-6f5eeb458078",
50
- session_id: "abc",
51
- source_ip: "127.0.41.132",
52
- src: "api",
53
- },
54
- {
55
- _timestamp: "2024-12-25T14:26:22.484904Z",
56
- api_key: "js.123.123",
57
- chromeVersion: "131",
58
- click_id: {},
59
- companyId: 123,
60
- email: "john.doe@example.com",
61
- event_type: "workflow-complete",
62
- eventn_ctx_event_id: "62615da7-a605-420f-9b73-d88ca488fa6d",
63
- ids: {},
64
- info: {
65
- billing: {
66
- nodeTypeCounts: {
67
- "click-element": 13,
68
- },
69
- ticketDurationsMs: [],
70
- },
71
- callCount: 1,
72
- metrics: {
73
- actual: {},
74
- },
75
- results: [
76
- {
77
- callCount: 1,
78
- },
79
- ],
80
- status: "complete",
81
- },
82
- jobId: "f3b97b73-15e5-4d5b-af73-43bbbf237b24",
83
- local_tz_offset: 0,
84
- manifestVersion: "1.0.0",
85
- runtimeEnvironment: "production",
86
- source_ip: "127.0.32.11",
87
- src: "jitsu",
88
- teamId: 1,
89
- timestamp: 1735136772062,
90
- type: "workflow-complete",
91
- user: {
92
- anonymous_id: "",
93
- hashed_anonymous_id: "bef91c4d78dbf5b10b791d1f483faa9a",
94
- },
95
- user_agent:
96
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
97
- utc_time: "2024-12-25T14:26:12.097000Z",
98
- utm: {},
99
- },
100
- {
101
- _timestamp: "2024-12-25T00:26:56.305721Z",
102
- api_key: "js.123.123",
103
- click_id: {
104
- gclid: "123",
105
- dclid: "1233",
106
- },
107
- doc_encoding: "UTF-8",
108
- doc_host: "app.example.com",
109
- doc_path: "/login",
110
- doc_search: "?next=%2F",
111
- event_type: "pageview",
112
- eventn_ctx_event_id: "15fea8d7-14af-4488-92a9-0ae52eba5499",
113
- ids: {},
114
- local_tz_offset: 300,
115
- page_title: "Login - Litnerd",
116
- referer: "",
117
- screen_resolution: "1920x1080",
118
- source_ip: "127.0.56.1",
119
- src: "jitsu",
120
- url: "https://app.example.com/login?next=%2F",
121
- user: {
122
- anonymous_id: "123",
123
- hashed_anonymous_id: "49a8381a0fe28827b68a48416dd69a23",
124
- id: "student:123",
125
- name: "JOHN DOE",
126
- role: "student",
127
- school_id: 123,
128
- },
129
- user_agent:
130
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
131
- user_language: "en-US",
132
- utc_time: "2024-12-25T00:26:56.481000Z",
133
- utm: {},
134
- vp_size: "1920x911",
135
- },
136
- {
137
- _timestamp: "2024-12-25T15:33:08.369746Z",
138
- api_key: "s2s.123.123",
139
- click_id: {
140
- gclid: "123",
141
- dclid: "1233",
142
- },
143
- doc_host: "localhost:3000",
144
- doc_path: "/auth/login",
145
- doc_search: "",
146
- event_type: "page_view",
147
- eventn_ctx_event_id: "98373e80-6228-4163-957e-90703182e9de",
148
- ids: {
149
- ga: "GA1.1.123.123",
150
- },
151
- isAuthorized: false,
152
- nextPrefetch: false,
153
- onVercel: false,
154
- page_title: "",
155
- page_url: "http://localhost:3000/auth/login",
156
- referer: "",
157
- source_ip: "",
158
- src: "api",
159
- url: "http://localhost:3000/auth/login",
160
- user: {
161
- anonymous_id: "123",
162
- hashed_anonymous_id: "ee3cd46ca7a46adb9fa1c9599e64249f",
163
- },
164
- user_agent: "Wget/1.21.3",
165
- utc_time: "2024-12-25T15:33:07.992Z",
166
- utm: {},
167
- },
168
- ];
package/rollup.config.js DELETED
@@ -1,14 +0,0 @@
1
- const typescript = require("@rollup/plugin-typescript");
2
- const resolve = require("@rollup/plugin-node-resolve");
3
- const commonjs = require("@rollup/plugin-commonjs");
4
-
5
- module.exports = [
6
- {
7
- plugins: [typescript(), resolve({ preferBuiltins: false }), commonjs()],
8
- input: ["./src/index.ts"],
9
- output: [
10
- { file: "dist/index.es.js", format: "es" },
11
- { file: "dist/index.cjs.js", format: "cjs" },
12
- ],
13
- },
14
- ];