@jitsu/functions-lib 2.14.0-beta.17 → 2.14.0-beta.19

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,498 @@
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
227
  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;
235
- 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),
228
+ const keepOriginalNames = !!ctx.props.keepOriginalNames;
229
+ const fileStorage = ctx.destination.type === "s3" || ctx.destination.type === "gcs";
230
+ let transferFunc = transferAsSnakeCase;
231
+ if (keepOriginalNames) {
232
+ if (fileStorage) {
233
+ transferFunc = transfer;
234
+ } else {
235
+ transferFunc = transferAsClassic;
236
+ }
237
+ }
238
+ let url = void 0;
239
+ const analyticsContext = event.context || {};
240
+ const urlStr = analyticsContext.page?.url || event.properties?.url;
241
+ try {
242
+ if (urlStr) {
243
+ url = new URL(urlStr);
244
+ }
245
+ } catch (e) {
246
+ }
247
+ const click_id = {};
248
+ transferFunc(click_id, analyticsContext.clientIds, ["ga4", "fbp", "fbc"]);
249
+ let ids = {};
250
+ if (Object.keys(analyticsContext.clientIds || {}).length > 0) {
251
+ ids = removeUndefined({
252
+ ga: analyticsContext.clientIds?.ga4?.clientId,
253
+ fbp: analyticsContext.clientIds?.fbp,
254
+ fbc: analyticsContext.clientIds?.fbc
269
255
  });
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);
256
+ }
257
+ const geo = analyticsContext.geo || {};
258
+ const ua = ctx?.ua || {};
259
+ const user = removeUndefined({
260
+ id: event.userId,
261
+ anonymous_id: event.anonymousId,
262
+ email: analyticsContext.traits?.email || event.traits?.email || void 0,
263
+ name: analyticsContext.traits?.name || event.traits?.name || void 0
264
+ });
265
+ transferFunc(user, analyticsContext.traits, ["email", "name"]);
266
+ transferFunc(user, event.traits, ["email", "name"]);
267
+ const classic = {
268
+ [TableNameParameter]: event[TableNameParameter],
269
+ anon_ip: analyticsContext.ip ? anonymizeIp(analyticsContext.ip) : void 0,
270
+ api_key: event.writeKey || "",
271
+ click_id: Object.keys(click_id).length > 0 ? click_id : void 0,
272
+ doc_encoding: analyticsContext.page?.encoding ?? event.properties?.encoding,
273
+ doc_host: (analyticsContext.page?.host ?? event.properties?.host) || url?.host,
274
+ doc_path: (analyticsContext.page?.path ?? event.properties?.path) || url?.pathname,
275
+ doc_search: (analyticsContext.page?.search ?? event.properties?.search) || url?.search,
276
+ eventn_ctx_event_id: event.messageId,
277
+ event_type: event.event || event.type,
278
+ local_tz_offset: analyticsContext.page?.timezoneOffset ?? event.properties?.timezoneOffset,
279
+ page_title: analyticsContext.page?.title,
280
+ referer: analyticsContext.page?.referrer,
281
+ screen_resolution: Object.keys(analyticsContext.screen || {}).length > 0 ? Math.max(analyticsContext.screen?.width || 0) + "x" + Math.max(analyticsContext.screen?.height || 0) : void 0,
282
+ source_ip: analyticsContext.ip,
283
+ src: event.properties?.src || "jitsu",
284
+ url: urlStr,
285
+ user: Object.keys(user).length > 0 ? user : void 0,
286
+ location: Object.keys(geo).length > 0 ? {
287
+ city: geo.city?.name,
288
+ continent: geo.continent?.name,
289
+ country: geo.country?.code,
290
+ country_name: geo.country?.name,
291
+ latitude: geo.location?.latitude,
292
+ longitude: geo.location?.longitude,
293
+ region: geo.region?.code,
294
+ zip: geo.postalCode?.code,
295
+ timezone: geo.location?.timezone,
296
+ autonomous_system_number: geo.provider?.as?.num,
297
+ autonomous_system_organization: geo.provider?.as?.name,
298
+ isp: geo.provider?.isp,
299
+ domain: geo.provider?.domain
300
+ } : void 0,
301
+ ids: Object.keys(ids).length > 0 ? ids : void 0,
302
+ parsed_ua: event.parsed_ua || (Object.keys(ua).length > 0 ? {
303
+ os_family: ua.os?.name,
304
+ os_version: ua.os?.version,
305
+ ua_family: ua.browser?.name,
306
+ ua_version: ua.browser?.version,
307
+ device_brand: ua.device?.vendor,
308
+ device_type: ua.device?.type,
309
+ device_model: ua.device?.model,
310
+ bot: ua.bot
311
+ } : void 0),
312
+ user_agent: analyticsContext.userAgent,
313
+ user_language: analyticsContext.locale,
314
+ utc_time: event.timestamp,
315
+ _timestamp: event.receivedAt,
316
+ utm: analyticsContext.campaign,
317
+ vp_size: Object.keys(analyticsContext.screen || {}).length > 0 ? Math.max(analyticsContext.screen?.innerWidth || 0) + "x" + Math.max(analyticsContext.screen?.innerHeight || 0) : void 0
318
+ };
319
+ if (event.type === "track") {
320
+ transferFunc(classic, event.properties);
321
+ } else {
322
+ transferFunc(classic, event.properties, ["url", "title", "referrer", "search", "host", "path", "width", "height"]);
323
+ }
324
+ return removeUndefined(classic);
340
325
  }
341
326
  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
- });
327
+ let type = "track";
328
+ let eventName = void 0;
329
+ switch ((event.event_type ?? "").toLowerCase()) {
330
+ case "pageview":
331
+ case "page_view":
332
+ case "page":
333
+ type = "page";
334
+ eventName = event.event_type;
335
+ break;
336
+ case "identify":
337
+ type = "identify";
338
+ break;
339
+ case "screen":
340
+ type = "screen";
341
+ break;
342
+ case "group":
343
+ type = "group";
344
+ break;
345
+ case "alias":
346
+ type = "alias";
347
+ break;
348
+ default:
349
+ type = "track";
350
+ eventName = event.event_type;
351
+ break;
352
+ }
353
+ const clientIds = Object.keys(event.ids || event.click_id || {}).length > 0 ? {
354
+ ga4: event.ids?.ga ? {
355
+ clientId: event.ids.ga
356
+ } : void 0,
357
+ fbp: event.ids?.fbp,
358
+ fbc: event.ids?.fbc,
359
+ ...event.click_id
360
+ } : void 0;
361
+ const loc = event.location || {};
362
+ const geo = Object.keys(loc).length > 0 ? {
363
+ city: {
364
+ name: loc.city
365
+ },
366
+ continent: {
367
+ code: loc.continent
368
+ },
369
+ country: {
370
+ code: loc.country,
371
+ name: loc.country_name
372
+ },
373
+ location: {
374
+ latitude: loc.latitude,
375
+ longitude: loc.longitude,
376
+ timezone: loc.timezone
377
+ },
378
+ region: {
379
+ code: loc.region
380
+ },
381
+ postalCode: {
382
+ code: loc.zip
383
+ },
384
+ provider: {
385
+ as: {
386
+ num: loc.autonomous_system_number,
387
+ name: loc.autonomous_system_organization
388
+ },
389
+ isp: loc.isp,
390
+ domain: loc.domain
391
+ }
392
+ } : void 0;
393
+ const traits = {};
394
+ transfer(traits, event.user, ["id", "anonymous_id"]);
395
+ const properties = {};
396
+ transfer(properties, event, [
397
+ TableNameParameter,
398
+ "anon_ip",
399
+ "api_key",
400
+ "click_id",
401
+ "doc_encoding",
402
+ "doc_host",
403
+ "doc_path",
404
+ "doc_search",
405
+ "eventn_ctx_event_id",
406
+ "event_type",
407
+ "local_tz_offset",
408
+ "page_title",
409
+ "referer",
410
+ "screen_resolution",
411
+ "source_ip",
412
+ "url",
413
+ "user",
414
+ "location",
415
+ "parsed_ua",
416
+ "user_agent",
417
+ "user_language",
418
+ "utc_time",
419
+ "_timestamp",
420
+ "utm",
421
+ "vp_size"
422
+ ]);
423
+ if (type === "page") {
424
+ properties.url = event.url;
425
+ properties.title = event.page_title;
426
+ properties.referrer = event.referer;
427
+ properties.search = event.doc_search;
428
+ properties.host = event.doc_host;
429
+ properties.path = event.doc_path;
430
+ properties.width = parseInt(event.vp_size?.split("x")[0]);
431
+ properties.height = parseInt(event.vp_size?.split("x")[1]);
432
+ }
433
+ const screen = {};
434
+ const sr = event.screen_resolution?.split("x");
435
+ if (sr?.length === 2) {
436
+ screen.width = parseInt(sr[0]);
437
+ screen.height = parseInt(sr[1]);
438
+ }
439
+ const vs = event.vp_size?.split("x");
440
+ if (vs?.length === 2) {
441
+ screen.innerWidth = parseInt(vs[0]);
442
+ screen.innerHeight = parseInt(vs[1]);
443
+ }
444
+ return removeUndefined({
445
+ [TableNameParameter]: event[TableNameParameter],
446
+ messageId: event.eventn_ctx_event_id,
447
+ userId: event.user?.id,
448
+ anonymousId: event.user?.anonymous_id,
449
+ timestamp: event.utc_time,
450
+ receivedAt: event._timestamp,
451
+ writeKey: event.api_key,
452
+ type,
453
+ event: eventName,
454
+ context: {
455
+ ip: event.source_ip,
456
+ locale: event.user_language,
457
+ userAgent: event.user_agent,
458
+ page: {
459
+ url: event.url,
460
+ title: event.page_title,
461
+ referrer: event.referer,
462
+ search: event.doc_search,
463
+ host: event.doc_host,
464
+ path: event.doc_path,
465
+ encoding: event.doc_encoding,
466
+ timezoneOffset: event.local_tz_offset
467
+ },
468
+ screen: Object.keys(screen).length > 0 ? screen : void 0,
469
+ clientIds,
470
+ campaign: event.utm,
471
+ traits,
472
+ geo
473
+ },
474
+ properties,
475
+ traits: type === "identify" || type === "group" ? traits : void 0
476
+ });
498
477
  }
499
-
500
- export { DropRetryErrorName, HTTPError, NoRetryError, NoRetryErrorName, RetryError, RetryErrorName, TableNameParameter, fromJitsuClassic, idToClassic, idToSnakeCaseFast, removeUndefined, toClassic, toJitsuClassic, toSnakeCase, transfer, transferAsClassic, transferAsSnakeCase, transferValue, transferValueAsSnakeCase };
478
+ export {
479
+ DropRetryErrorName,
480
+ HTTPError,
481
+ NoRetryError,
482
+ NoRetryErrorName,
483
+ RetryError,
484
+ RetryErrorName,
485
+ TableNameParameter,
486
+ fromJitsuClassic,
487
+ idToClassic,
488
+ idToSnakeCaseFast,
489
+ removeUndefined,
490
+ toClassic,
491
+ toJitsuClassic,
492
+ toSnakeCase,
493
+ transfer,
494
+ transferAsClassic,
495
+ transferAsSnakeCase,
496
+ transferValue,
497
+ transferValueAsSnakeCase
498
+ };