@jitsu/functions-lib 2.14.0-beta.6 → 2.14.0-beta.61

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/dist/index.es.js CHANGED
@@ -1,500 +1,501 @@
1
- const ACode = "A".charCodeAt(0);
2
- const ZCode = "Z".charCodeAt(0);
3
- const aCode = "a".charCodeAt(0);
4
- const zCode = "z".charCodeAt(0);
5
- const zeroCode = "0".charCodeAt(0);
6
- const nineCode = "9".charCodeAt(0);
7
- const spaceCode = " ".charCodeAt(0);
8
- const underscodeCode = "_".charCodeAt(0);
1
+ // src/lib/strings.ts
2
+ var ACode = "A".charCodeAt(0);
3
+ var ZCode = "Z".charCodeAt(0);
4
+ var aCode = "a".charCodeAt(0);
5
+ var zCode = "z".charCodeAt(0);
6
+ var zeroCode = "0".charCodeAt(0);
7
+ var nineCode = "9".charCodeAt(0);
8
+ var spaceCode = " ".charCodeAt(0);
9
+ var underscodeCode = "_".charCodeAt(0);
9
10
  function idToSnakeCaseFast(id) {
10
- let res = "";
11
- let concatIndex = 0;
12
- let i = 0;
13
- let needUnderscore = false;
14
- for (; i < id.length; i++) {
15
- const c = id.charCodeAt(i);
16
- if (c >= ACode && c <= ZCode) {
17
- res += id.substring(concatIndex, i) + (needUnderscore ? "_" : "") + id.charAt(i).toLowerCase();
18
- concatIndex = i + 1;
19
- }
20
- else if (c == spaceCode) {
21
- res += id.substring(concatIndex, i) + "_";
22
- concatIndex = i + 1;
23
- }
24
- needUnderscore = (c >= aCode && c <= zCode) || (c >= ACode && c <= ZCode);
25
- }
26
- if (concatIndex == 0) {
27
- return id;
28
- }
29
- else if (concatIndex < i) {
30
- res += id.substring(concatIndex, i);
31
- }
32
- return res;
11
+ let res = "";
12
+ let concatIndex = 0;
13
+ let i = 0;
14
+ let needUnderscore = false;
15
+ for (; i < id.length; i++) {
16
+ const c = id.charCodeAt(i);
17
+ if (c >= ACode && c <= ZCode) {
18
+ res += id.substring(concatIndex, i) + (needUnderscore ? "_" : "") + id.charAt(i).toLowerCase();
19
+ concatIndex = i + 1;
20
+ } else if (c == spaceCode) {
21
+ res += id.substring(concatIndex, i) + "_";
22
+ concatIndex = i + 1;
23
+ }
24
+ needUnderscore = c >= aCode && c <= zCode || c >= ACode && c <= ZCode;
25
+ }
26
+ if (concatIndex == 0) {
27
+ return id;
28
+ } else if (concatIndex < i) {
29
+ res += id.substring(concatIndex, i);
30
+ }
31
+ return res;
33
32
  }
34
33
  function idToClassic(id) {
35
- let needConvert = false;
36
- for (let i = 0; i < id.length; i++) {
37
- const c = id.charCodeAt(i);
38
- if (!((c >= aCode && c <= zCode) || (c >= zeroCode && c <= nineCode) || c == underscodeCode)) {
39
- needConvert = true;
40
- break;
41
- }
42
- }
43
- if (!needConvert) {
44
- return id;
45
- }
46
- let res = "";
47
- for (let i = 0; i < id.length; i++) {
48
- const c = id.charCodeAt(i);
49
- if (c >= ACode && c <= ZCode) {
50
- res += id.charAt(i).toLowerCase();
51
- }
52
- else if ((c >= aCode && c <= zCode) || (c >= zeroCode && c <= nineCode)) {
53
- res += id.charAt(i);
54
- }
55
- else {
56
- res += "_";
57
- }
58
- }
59
- return res;
34
+ let needConvert = false;
35
+ for (let i = 0; i < id.length; i++) {
36
+ const c = id.charCodeAt(i);
37
+ if (!(c >= aCode && c <= zCode || c >= zeroCode && c <= nineCode || c == underscodeCode)) {
38
+ needConvert = true;
39
+ break;
40
+ }
41
+ }
42
+ if (!needConvert) {
43
+ return id;
44
+ }
45
+ let res = "";
46
+ for (let i = 0; i < id.length; i++) {
47
+ const c = id.charCodeAt(i);
48
+ if (c >= ACode && c <= ZCode) {
49
+ res += id.charAt(i).toLowerCase();
50
+ } else if (c >= aCode && c <= zCode || c >= zeroCode && c <= nineCode) {
51
+ res += id.charAt(i);
52
+ } else {
53
+ res += "_";
54
+ }
55
+ }
56
+ return res;
60
57
  }
61
58
 
59
+ // src/lib/objects.ts
62
60
  function toSnakeCase(param) {
63
- if (Array.isArray(param)) {
64
- return param.map(toSnakeCase);
65
- }
66
- else if (typeof param === "object" && param !== null) {
67
- const r = {};
68
- for (const [key, value] of Object.entries(param)) {
69
- r[idToSnakeCaseFast(key)] = toSnakeCase(value);
70
- }
71
- return r;
72
- }
73
- else {
74
- return param;
75
- }
61
+ if (Array.isArray(param)) {
62
+ return param.map(toSnakeCase);
63
+ } else if (typeof param === "object" && param !== null) {
64
+ const r = {};
65
+ for (const [key, value] of Object.entries(param)) {
66
+ r[idToSnakeCaseFast(key)] = toSnakeCase(value);
67
+ }
68
+ return r;
69
+ } else {
70
+ return param;
71
+ }
76
72
  }
77
73
  function toClassic(param) {
78
- if (Array.isArray(param)) {
79
- return param.map(toClassic);
80
- }
81
- else if (typeof param === "object" && param !== null) {
82
- const r = {};
83
- for (const [key, value] of Object.entries(param)) {
84
- r[idToClassic(key)] = toClassic(value);
85
- }
86
- return r;
87
- }
88
- else {
89
- return param;
90
- }
74
+ if (Array.isArray(param)) {
75
+ return param.map(toClassic);
76
+ } else if (typeof param === "object" && param !== null) {
77
+ const r = {};
78
+ for (const [key, value] of Object.entries(param)) {
79
+ r[idToClassic(key)] = toClassic(value);
80
+ }
81
+ return r;
82
+ } else {
83
+ return param;
84
+ }
91
85
  }
92
86
  function removeUndefined(param) {
93
- if (Array.isArray(param)) {
94
- return param.map(removeUndefined);
95
- }
96
- else if (typeof param === "object" && param !== null) {
97
- for (const [key, value] of Object.entries(param)) {
98
- switch (typeof value) {
99
- case "undefined":
100
- delete param[key];
101
- break;
102
- case "object":
103
- if (value !== null) {
104
- removeUndefined(value);
105
- }
106
- break;
107
- }
108
- }
109
- }
110
- return param;
87
+ if (Array.isArray(param)) {
88
+ return param.map(removeUndefined);
89
+ } else if (typeof param === "object" && param !== null) {
90
+ for (const [key, value] of Object.entries(param)) {
91
+ switch (typeof value) {
92
+ case "undefined":
93
+ delete param[key];
94
+ break;
95
+ case "object":
96
+ if (value !== null) {
97
+ removeUndefined(value);
98
+ }
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ return param;
111
104
  }
112
105
  function transferAsSnakeCase(target, source, omit) {
113
- if (typeof source !== "object") {
114
- return;
115
- }
116
- for (const [k, v] of Object.entries(source)) {
117
- if (!omit || !omit.includes(k)) {
118
- target[idToSnakeCaseFast(k)] = toSnakeCase(v);
119
- }
120
- }
106
+ if (typeof source !== "object") {
107
+ return;
108
+ }
109
+ for (const [k, v] of Object.entries(source)) {
110
+ if (!omit || !omit.includes(k)) {
111
+ target[idToSnakeCaseFast(k)] = toSnakeCase(v);
112
+ }
113
+ }
121
114
  }
122
115
  function transferAsClassic(target, source, omit) {
123
- if (typeof source !== "object") {
124
- return;
125
- }
126
- for (const [k, v] of Object.entries(source)) {
127
- if (!omit || !omit.includes(k)) {
128
- target[idToClassic(k)] = toClassic(v);
129
- }
130
- }
116
+ if (typeof source !== "object") {
117
+ return;
118
+ }
119
+ for (const [k, v] of Object.entries(source)) {
120
+ if (!omit || !omit.includes(k)) {
121
+ target[idToClassic(k)] = toClassic(v);
122
+ }
123
+ }
131
124
  }
132
125
  function transferValueAsSnakeCase(target, property, source) {
133
- if (typeof source === "undefined") {
134
- return;
135
- }
136
- target[property] = toSnakeCase(source);
126
+ if (typeof source === "undefined") {
127
+ return;
128
+ }
129
+ target[property] = toSnakeCase(source);
137
130
  }
138
131
  function transfer(target, source, omit) {
139
- if (typeof source !== "object") {
140
- return;
141
- }
142
- for (const [k, v] of Object.entries(source)) {
143
- if (!omit || !omit.includes(k)) {
144
- target[k] = v;
145
- }
146
- }
132
+ if (typeof source !== "object") {
133
+ return;
134
+ }
135
+ for (const [k, v] of Object.entries(source)) {
136
+ if (!omit || !omit.includes(k)) {
137
+ target[k] = v;
138
+ }
139
+ }
147
140
  }
148
141
  function transferValue(target, property, source) {
149
- if (typeof source === "undefined") {
150
- return;
151
- }
152
- target[property] = source;
142
+ if (typeof source === "undefined") {
143
+ return;
144
+ }
145
+ target[property] = source;
153
146
  }
154
147
 
155
- const TableNameParameter = "JITSU_TABLE_NAME";
156
- const DropRetryErrorName = "Drop & RetryError";
157
- const RetryErrorName = "RetryError";
158
- const NoRetryErrorName = "NoRetryError";
159
- class RetryError extends Error {
160
- constructor(message, options) {
161
- if (typeof message === "object") {
162
- super(message.message);
163
- this.message = message.message;
164
- this.status = message.status;
165
- this.response = message.response;
166
- }
167
- else {
168
- super(message);
169
- this.message = message;
170
- }
171
- this.name = options?.drop ? `${DropRetryErrorName}` : `${RetryErrorName}`;
172
- }
173
- toJSON() {
174
- return {
175
- name: this.name,
176
- message: this.message,
177
- status: this.status,
178
- response: this.response,
179
- };
180
- }
181
- }
182
- class NoRetryError extends Error {
183
- constructor(message) {
184
- if (typeof message === "object") {
185
- super(message.message);
186
- this.message = message.message;
187
- this.status = message.status;
188
- this.response = message.response;
189
- }
190
- else {
191
- super(message);
192
- this.message = message;
193
- }
194
- this.name = "NoRetryError";
195
- }
196
- toJSON() {
197
- return {
198
- name: this.name,
199
- message: this.message,
200
- status: this.status,
201
- response: this.response,
202
- };
203
- }
204
- }
205
- class HTTPError extends Error {
206
- constructor(message, status, response) {
207
- super(message);
208
- this.message = message;
209
- this.name = "HTTPError";
210
- this.status = status;
211
- this.response = response.length > 1000 ? response.slice(0, 1000) + "..." : response;
212
- }
213
- toJSON() {
214
- return {
215
- name: this.name,
216
- message: this.message,
217
- status: this.status,
218
- response: this.response,
219
- };
220
- }
221
- }
148
+ // src/lib/functions.ts
149
+ var TableNameParameter = "JITSU_TABLE_NAME";
150
+ var DropRetryErrorName = "Drop & RetryError";
151
+ var RetryErrorName = "RetryError";
152
+ var NoRetryErrorName = "NoRetryError";
153
+ var RetryError = class extends Error {
154
+ constructor(message, options) {
155
+ if (typeof message === "object") {
156
+ super(message.message);
157
+ this.message = message.message;
158
+ this.status = message.status;
159
+ this.response = message.response;
160
+ } else {
161
+ super(message);
162
+ this.message = message;
163
+ this.status = 0;
164
+ this.response = "";
165
+ }
166
+ this.name = options?.drop ? `${DropRetryErrorName}` : `${RetryErrorName}`;
167
+ }
168
+ toJSON() {
169
+ return {
170
+ name: this.name,
171
+ message: this.message,
172
+ status: this.status,
173
+ response: this.response
174
+ };
175
+ }
176
+ };
177
+ var NoRetryError = class extends Error {
178
+ constructor(message) {
179
+ if (typeof message === "object") {
180
+ super(message.message);
181
+ this.message = message.message;
182
+ this.status = message.status;
183
+ this.response = message.response;
184
+ } else {
185
+ super(message);
186
+ this.message = message;
187
+ this.status = 0;
188
+ this.response = "";
189
+ }
190
+ this.name = "NoRetryError";
191
+ }
192
+ toJSON() {
193
+ return {
194
+ name: this.name,
195
+ message: this.message,
196
+ status: this.status,
197
+ response: this.response
198
+ };
199
+ }
200
+ };
201
+ var HTTPError = class extends Error {
202
+ constructor(message, status, response) {
203
+ super(message);
204
+ this.message = message;
205
+ this.name = "HTTPError";
206
+ this.status = status;
207
+ this.response = response.length > 1e3 ? response.slice(0, 1e3) + "..." : response;
208
+ }
209
+ toJSON() {
210
+ return {
211
+ name: this.name,
212
+ message: this.message,
213
+ status: this.status,
214
+ response: this.response
215
+ };
216
+ }
217
+ };
222
218
  function anonymizeIp(ip) {
223
- if (!ip) {
224
- return;
225
- }
226
- const parts = ip.split(".");
227
- if (parts.length === 4) {
228
- return `${parts[0]}.${parts[1]}.${parts[2]}.0`;
229
- }
219
+ if (!ip) {
220
+ return;
221
+ }
222
+ const parts = ip.split(".");
223
+ if (parts.length === 4) {
224
+ return `${parts[0]}.${parts[1]}.${parts[2]}.0`;
225
+ }
230
226
  }
231
- function toJitsuClassic(event, ctx) {
232
- const keepOriginalNames = !!ctx.props.keepOriginalNames;
233
- const fileStorage = ctx.destination.type === "s3" || ctx.destination.type === "gcs";
234
- let transferFunc = transferAsSnakeCase;
227
+ function toJitsuClassic(event, ctx, bulker = false) {
228
+ let transferFunc = transfer;
229
+ if (bulker) {
230
+ const keepOriginalNames = !!ctx?.props?.keepOriginalNames;
231
+ const fileStorage = ctx?.destination?.type === "s3" || ctx?.destination?.type === "gcs";
232
+ transferFunc = transferAsSnakeCase;
235
233
  if (keepOriginalNames) {
236
- if (fileStorage) {
237
- transferFunc = transfer;
238
- }
239
- else {
240
- transferFunc = transferAsClassic;
241
- }
242
- }
243
- let url = undefined;
244
- const analyticsContext = event.context || {};
245
- const urlStr = analyticsContext.page?.url || event.properties?.url;
246
- try {
247
- if (urlStr) {
248
- url = new URL(urlStr);
249
- }
250
- }
251
- catch (e) { }
252
- const click_id = {};
253
- transferFunc(click_id, analyticsContext.clientIds, ["ga4", "fbp", "fbc"]);
254
- let ids = {};
255
- if (Object.keys(analyticsContext.clientIds || {}).length > 0) {
256
- ids = removeUndefined({
257
- ga: analyticsContext.clientIds.ga4?.clientId,
258
- fbp: analyticsContext.clientIds.fbp,
259
- fbc: analyticsContext.clientIds.fbc,
260
- });
261
- }
262
- const geo = analyticsContext.geo || {};
263
- const ua = ctx?.ua || {};
264
- const user = removeUndefined({
265
- id: event.userId,
266
- anonymous_id: event.anonymousId,
267
- email: (analyticsContext.traits?.email || event.traits?.email || undefined),
268
- name: (analyticsContext.traits?.name || event.traits?.name || undefined),
234
+ if (fileStorage) {
235
+ transferFunc = transfer;
236
+ } else {
237
+ transferFunc = transferAsClassic;
238
+ }
239
+ }
240
+ }
241
+ let url = void 0;
242
+ const analyticsContext = event.context || {};
243
+ const urlStr = analyticsContext.page?.url || event.properties?.url;
244
+ try {
245
+ if (urlStr) {
246
+ url = new URL(urlStr);
247
+ }
248
+ } catch (e) {
249
+ }
250
+ const click_id = {};
251
+ transferFunc(click_id, analyticsContext.clientIds, ["ga4", "fbp", "fbc"]);
252
+ let ids = {};
253
+ if (Object.keys(analyticsContext.clientIds || {}).length > 0) {
254
+ ids = removeUndefined({
255
+ ga: analyticsContext.clientIds?.ga4?.clientId,
256
+ fbp: analyticsContext.clientIds?.fbp,
257
+ fbc: analyticsContext.clientIds?.fbc
269
258
  });
270
- transferFunc(user, analyticsContext.traits, ["email", "name"]);
271
- transferFunc(user, event.traits, ["email", "name"]);
272
- const classic = {
273
- [TableNameParameter]: event[TableNameParameter],
274
- anon_ip: analyticsContext.ip ? anonymizeIp(analyticsContext.ip) : undefined,
275
- api_key: event.writeKey || "",
276
- click_id: Object.keys(click_id).length > 0 ? click_id : undefined,
277
- doc_encoding: analyticsContext.page?.encoding ?? event.properties?.encoding,
278
- doc_host: (analyticsContext.page?.host ?? event.properties?.host) || url?.host,
279
- doc_path: (analyticsContext.page?.path ?? event.properties?.path) || url?.pathname,
280
- doc_search: (analyticsContext.page?.search ?? event.properties?.search) || url?.search,
281
- eventn_ctx_event_id: event.messageId,
282
- event_type: event.event || event.type,
283
- local_tz_offset: analyticsContext.page?.timezoneOffset ?? event.properties?.timezoneOffset,
284
- page_title: analyticsContext.page?.title,
285
- referer: analyticsContext.page?.referrer,
286
- screen_resolution: Object.keys(analyticsContext.screen || {}).length > 0
287
- ? Math.max(analyticsContext.screen.width || 0) + "x" + Math.max(analyticsContext.screen.height || 0)
288
- : undefined,
289
- source_ip: analyticsContext.ip,
290
- src: event.properties?.src || "jitsu",
291
- url: urlStr,
292
- user: Object.keys(user).length > 0 ? user : undefined,
293
- location: Object.keys(geo).length > 0
294
- ? {
295
- city: geo.city?.name,
296
- continent: geo.continent?.name,
297
- country: geo.country?.code,
298
- country_name: geo.country?.name,
299
- latitude: geo.location?.latitude,
300
- longitude: geo.location?.longitude,
301
- region: geo.region?.code,
302
- zip: geo.postalCode?.code,
303
- timezone: geo.location?.timezone,
304
- autonomous_system_number: geo.provider?.as?.num,
305
- autonomous_system_organization: geo.provider?.as?.name,
306
- isp: geo.provider?.isp,
307
- domain: geo.provider?.domain,
308
- }
309
- : undefined,
310
- ids: Object.keys(ids).length > 0 ? ids : undefined,
311
- parsed_ua: event.parsed_ua ||
312
- (Object.keys(ua).length > 0
313
- ? {
314
- os_family: ua.os?.name,
315
- os_version: ua.os?.version,
316
- ua_family: ua.browser?.name,
317
- ua_version: ua.browser?.version,
318
- device_brand: ua.device?.vendor,
319
- device_type: ua.device?.type,
320
- device_model: ua.device?.model,
321
- bot: ua.bot,
322
- }
323
- : undefined),
324
- user_agent: analyticsContext.userAgent,
325
- user_language: analyticsContext.locale,
326
- utc_time: event.timestamp,
327
- _timestamp: event.receivedAt,
328
- utm: analyticsContext.campaign,
329
- vp_size: Object.keys(analyticsContext.screen || {}).length > 0
330
- ? Math.max(analyticsContext.screen.innerWidth || 0) + "x" + Math.max(analyticsContext.screen.innerHeight || 0)
331
- : undefined,
332
- };
333
- if (event.type === "track") {
334
- transferFunc(classic, event.properties);
335
- }
336
- else {
337
- transferFunc(classic, event.properties, ["url", "title", "referrer", "search", "host", "path", "width", "height"]);
338
- }
339
- return removeUndefined(classic);
259
+ }
260
+ const geo = analyticsContext.geo || {};
261
+ const ua = ctx?.ua || {};
262
+ const user = removeUndefined({
263
+ id: event.userId,
264
+ anonymous_id: event.anonymousId,
265
+ email: analyticsContext.traits?.email || event.traits?.email || void 0,
266
+ name: analyticsContext.traits?.name || event.traits?.name || void 0
267
+ });
268
+ transferFunc(user, analyticsContext.traits, ["email", "name"]);
269
+ transferFunc(user, event.traits, ["email", "name"]);
270
+ const classic = {
271
+ [TableNameParameter]: event[TableNameParameter],
272
+ anon_ip: analyticsContext.ip ? anonymizeIp(analyticsContext.ip) : void 0,
273
+ api_key: event.writeKey || "",
274
+ click_id: Object.keys(click_id).length > 0 ? click_id : void 0,
275
+ doc_encoding: analyticsContext.page?.encoding ?? event.properties?.encoding,
276
+ doc_host: (analyticsContext.page?.host ?? event.properties?.host) || url?.host,
277
+ doc_path: (analyticsContext.page?.path ?? event.properties?.path) || url?.pathname,
278
+ doc_search: (analyticsContext.page?.search ?? event.properties?.search) || url?.search,
279
+ eventn_ctx_event_id: event.messageId,
280
+ event_type: event.event || event.type,
281
+ local_tz_offset: analyticsContext.page?.timezoneOffset ?? event.properties?.timezoneOffset,
282
+ page_title: analyticsContext.page?.title,
283
+ referer: analyticsContext.page?.referrer,
284
+ screen_resolution: Object.keys(analyticsContext.screen || {}).length > 0 ? Math.max(analyticsContext.screen?.width || 0) + "x" + Math.max(analyticsContext.screen?.height || 0) : void 0,
285
+ source_ip: analyticsContext.ip,
286
+ src: event.properties?.src || "jitsu",
287
+ url: urlStr,
288
+ user: Object.keys(user).length > 0 ? user : void 0,
289
+ location: Object.keys(geo).length > 0 ? {
290
+ city: geo.city?.name,
291
+ continent: geo.continent?.name,
292
+ country: geo.country?.code,
293
+ country_name: geo.country?.name,
294
+ latitude: geo.location?.latitude,
295
+ longitude: geo.location?.longitude,
296
+ region: geo.region?.code,
297
+ zip: geo.postalCode?.code,
298
+ timezone: geo.location?.timezone,
299
+ autonomous_system_number: geo.provider?.as?.num,
300
+ autonomous_system_organization: geo.provider?.as?.name,
301
+ isp: geo.provider?.isp,
302
+ domain: geo.provider?.domain
303
+ } : void 0,
304
+ ids: Object.keys(ids).length > 0 ? ids : void 0,
305
+ parsed_ua: event.parsed_ua || (Object.keys(ua).length > 0 ? {
306
+ os_family: ua.os?.name,
307
+ os_version: ua.os?.version,
308
+ ua_family: ua.browser?.name,
309
+ ua_version: ua.browser?.version,
310
+ device_brand: ua.device?.vendor,
311
+ device_type: ua.device?.type,
312
+ device_model: ua.device?.model,
313
+ bot: ua.bot
314
+ } : void 0),
315
+ user_agent: analyticsContext.userAgent,
316
+ user_language: analyticsContext.locale,
317
+ utc_time: event.timestamp,
318
+ _timestamp: event.receivedAt,
319
+ utm: analyticsContext.campaign,
320
+ vp_size: Object.keys(analyticsContext.screen || {}).length > 0 ? Math.max(analyticsContext.screen?.innerWidth || 0) + "x" + Math.max(analyticsContext.screen?.innerHeight || 0) : void 0
321
+ };
322
+ if (event.type === "track") {
323
+ transferFunc(classic, event.properties);
324
+ } else {
325
+ transferFunc(classic, event.properties, ["url", "title", "referrer", "search", "host", "path", "width", "height"]);
326
+ }
327
+ return removeUndefined(classic);
340
328
  }
341
329
  function fromJitsuClassic(event) {
342
- let type = "track";
343
- let eventName = undefined;
344
- switch ((event.event_type ?? "").toLowerCase()) {
345
- case "pageview":
346
- case "page_view":
347
- case "page":
348
- type = "page";
349
- eventName = event.event_type;
350
- break;
351
- case "identify":
352
- type = "identify";
353
- break;
354
- case "screen":
355
- type = "screen";
356
- break;
357
- case "group":
358
- type = "group";
359
- break;
360
- case "alias":
361
- type = "alias";
362
- break;
363
- default:
364
- type = "track";
365
- eventName = event.event_type;
366
- break;
367
- }
368
- const clientIds = Object.keys(event.ids || event.click_id || {}).length > 0
369
- ? {
370
- ga4: event.ids?.ga
371
- ? {
372
- clientId: event.ids.ga,
373
- }
374
- : undefined,
375
- fbp: event.ids?.fbp,
376
- fbc: event.ids?.fbc,
377
- ...event.click_id,
378
- }
379
- : undefined;
380
- const loc = event.location || {};
381
- const geo = Object.keys(loc).length > 0
382
- ? {
383
- city: {
384
- name: loc.city,
385
- },
386
- continent: {
387
- code: loc.continent,
388
- },
389
- country: {
390
- code: loc.country,
391
- name: loc.country_name,
392
- },
393
- location: {
394
- latitude: loc.latitude,
395
- longitude: loc.longitude,
396
- timezone: loc.timezone,
397
- },
398
- region: {
399
- code: loc.region,
400
- },
401
- postalCode: {
402
- code: loc.zip,
403
- },
404
- provider: {
405
- as: {
406
- num: loc.autonomous_system_number,
407
- name: loc.autonomous_system_organization,
408
- },
409
- isp: loc.isp,
410
- domain: loc.domain,
411
- },
412
- }
413
- : undefined;
414
- const traits = {};
415
- transfer(traits, event.user, ["id", "anonymous_id"]);
416
- const properties = {};
417
- transfer(properties, event, [
418
- TableNameParameter,
419
- "anon_ip",
420
- "api_key",
421
- "click_id",
422
- "doc_encoding",
423
- "doc_host",
424
- "doc_path",
425
- "doc_search",
426
- "eventn_ctx_event_id",
427
- "event_type",
428
- "local_tz_offset",
429
- "page_title",
430
- "referer",
431
- "screen_resolution",
432
- "source_ip",
433
- "url",
434
- "user",
435
- "location",
436
- "parsed_ua",
437
- "user_agent",
438
- "user_language",
439
- "utc_time",
440
- "_timestamp",
441
- "utm",
442
- "vp_size",
443
- ]);
444
- if (type === "page") {
445
- properties.url = event.url;
446
- properties.title = event.page_title;
447
- properties.referrer = event.referer;
448
- properties.search = event.doc_search;
449
- properties.host = event.doc_host;
450
- properties.path = event.doc_path;
451
- properties.width = parseInt(event.vp_size?.split("x")[0]);
452
- properties.height = parseInt(event.vp_size?.split("x")[1]);
453
- }
454
- const screen = {};
455
- const sr = event.screen_resolution?.split("x");
456
- if (sr?.length === 2) {
457
- screen.width = parseInt(sr[0]);
458
- screen.height = parseInt(sr[1]);
459
- }
460
- const vs = event.vp_size?.split("x");
461
- if (vs?.length === 2) {
462
- screen.innerWidth = parseInt(vs[0]);
463
- screen.innerHeight = parseInt(vs[1]);
464
- }
465
- return removeUndefined({
466
- [TableNameParameter]: event[TableNameParameter],
467
- messageId: event.eventn_ctx_event_id,
468
- userId: event.user?.id,
469
- anonymousId: event.user?.anonymous_id,
470
- timestamp: event.utc_time,
471
- receivedAt: event._timestamp,
472
- writeKey: event.api_key,
473
- type,
474
- event: eventName,
475
- context: {
476
- ip: event.source_ip,
477
- locale: event.user_language,
478
- userAgent: event.user_agent,
479
- page: {
480
- url: event.url,
481
- title: event.page_title,
482
- referrer: event.referer,
483
- search: event.doc_search,
484
- host: event.doc_host,
485
- path: event.doc_path,
486
- encoding: event.doc_encoding,
487
- timezoneOffset: event.local_tz_offset,
488
- },
489
- screen: Object.keys(screen).length > 0 ? screen : undefined,
490
- clientIds,
491
- campaign: event.utm,
492
- traits,
493
- geo,
494
- },
495
- properties,
496
- traits: type === "identify" || type === "group" ? traits : undefined,
497
- });
330
+ let type = "track";
331
+ let eventName = void 0;
332
+ switch ((event.event_type ?? "").toLowerCase()) {
333
+ case "pageview":
334
+ case "page_view":
335
+ case "page":
336
+ type = "page";
337
+ eventName = event.event_type;
338
+ break;
339
+ case "identify":
340
+ type = "identify";
341
+ break;
342
+ case "screen":
343
+ type = "screen";
344
+ break;
345
+ case "group":
346
+ type = "group";
347
+ break;
348
+ case "alias":
349
+ type = "alias";
350
+ break;
351
+ default:
352
+ type = "track";
353
+ eventName = event.event_type;
354
+ break;
355
+ }
356
+ const clientIds = Object.keys(event.ids || event.click_id || {}).length > 0 ? {
357
+ ga4: event.ids?.ga ? {
358
+ clientId: event.ids.ga
359
+ } : void 0,
360
+ fbp: event.ids?.fbp,
361
+ fbc: event.ids?.fbc,
362
+ ...event.click_id
363
+ } : void 0;
364
+ const loc = event.location || {};
365
+ const geo = Object.keys(loc).length > 0 ? {
366
+ city: {
367
+ name: loc.city
368
+ },
369
+ continent: {
370
+ code: loc.continent
371
+ },
372
+ country: {
373
+ code: loc.country,
374
+ name: loc.country_name
375
+ },
376
+ location: {
377
+ latitude: loc.latitude,
378
+ longitude: loc.longitude,
379
+ timezone: loc.timezone
380
+ },
381
+ region: {
382
+ code: loc.region
383
+ },
384
+ postalCode: {
385
+ code: loc.zip
386
+ },
387
+ provider: {
388
+ as: {
389
+ num: loc.autonomous_system_number,
390
+ name: loc.autonomous_system_organization
391
+ },
392
+ isp: loc.isp,
393
+ domain: loc.domain
394
+ }
395
+ } : void 0;
396
+ const traits = {};
397
+ transfer(traits, event.user, ["id", "anonymous_id"]);
398
+ const properties = {};
399
+ transfer(properties, event, [
400
+ TableNameParameter,
401
+ "anon_ip",
402
+ "api_key",
403
+ "click_id",
404
+ "doc_encoding",
405
+ "doc_host",
406
+ "doc_path",
407
+ "doc_search",
408
+ "eventn_ctx_event_id",
409
+ "event_type",
410
+ "local_tz_offset",
411
+ "page_title",
412
+ "referer",
413
+ "screen_resolution",
414
+ "source_ip",
415
+ "url",
416
+ "user",
417
+ "location",
418
+ "parsed_ua",
419
+ "user_agent",
420
+ "user_language",
421
+ "utc_time",
422
+ "_timestamp",
423
+ "utm",
424
+ "vp_size"
425
+ ]);
426
+ if (type === "page") {
427
+ properties.url = event.url;
428
+ properties.title = event.page_title;
429
+ properties.referrer = event.referer;
430
+ properties.search = event.doc_search;
431
+ properties.host = event.doc_host;
432
+ properties.path = event.doc_path;
433
+ properties.width = parseInt(event.vp_size?.split("x")[0]);
434
+ properties.height = parseInt(event.vp_size?.split("x")[1]);
435
+ }
436
+ const screen = {};
437
+ const sr = event.screen_resolution?.split("x");
438
+ if (sr?.length === 2) {
439
+ screen.width = parseInt(sr[0]);
440
+ screen.height = parseInt(sr[1]);
441
+ }
442
+ const vs = event.vp_size?.split("x");
443
+ if (vs?.length === 2) {
444
+ screen.innerWidth = parseInt(vs[0]);
445
+ screen.innerHeight = parseInt(vs[1]);
446
+ }
447
+ return removeUndefined({
448
+ [TableNameParameter]: event[TableNameParameter],
449
+ messageId: event.eventn_ctx_event_id,
450
+ userId: event.user?.id,
451
+ anonymousId: event.user?.anonymous_id,
452
+ timestamp: event.utc_time,
453
+ receivedAt: event._timestamp,
454
+ writeKey: event.api_key,
455
+ type,
456
+ event: eventName,
457
+ context: {
458
+ ip: event.source_ip,
459
+ locale: event.user_language,
460
+ userAgent: event.user_agent,
461
+ page: {
462
+ url: event.url,
463
+ title: event.page_title,
464
+ referrer: event.referer,
465
+ search: event.doc_search,
466
+ host: event.doc_host,
467
+ path: event.doc_path,
468
+ encoding: event.doc_encoding,
469
+ timezoneOffset: event.local_tz_offset
470
+ },
471
+ screen: Object.keys(screen).length > 0 ? screen : void 0,
472
+ clientIds,
473
+ campaign: event.utm,
474
+ traits,
475
+ geo
476
+ },
477
+ properties,
478
+ traits: type === "identify" || type === "group" ? traits : void 0
479
+ });
498
480
  }
499
-
500
- export { DropRetryErrorName, HTTPError, NoRetryError, NoRetryErrorName, RetryError, RetryErrorName, TableNameParameter, fromJitsuClassic, idToClassic, idToSnakeCaseFast, removeUndefined, toClassic, toJitsuClassic, toSnakeCase, transfer, transferAsClassic, transferAsSnakeCase, transferValue, transferValueAsSnakeCase };
481
+ export {
482
+ DropRetryErrorName,
483
+ HTTPError,
484
+ NoRetryError,
485
+ NoRetryErrorName,
486
+ RetryError,
487
+ RetryErrorName,
488
+ TableNameParameter,
489
+ fromJitsuClassic,
490
+ idToClassic,
491
+ idToSnakeCaseFast,
492
+ removeUndefined,
493
+ toClassic,
494
+ toJitsuClassic,
495
+ toSnakeCase,
496
+ transfer,
497
+ transferAsClassic,
498
+ transferAsSnakeCase,
499
+ transferValue,
500
+ transferValueAsSnakeCase
501
+ };