@jitsu/functions-lib 2.14.0-beta.5 → 2.14.0-beta.57

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