@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/LICENSE +21 -0
- package/dist/index.cjs.js +516 -490
- package/dist/index.es.js +472 -471
- package/dist/lib/functions.d.ts +1 -1
- package/package.json +20 -19
- package/__tests__/classic-mapping.test.ts +0 -315
- package/__tests__/data/classic-events.ts +0 -168
- package/rollup.config.js +0 -14
- package/src/index.ts +0 -3
- package/src/lib/functions.ts +0 -368
- package/src/lib/objects.ts +0 -96
- package/src/lib/strings.ts +0 -60
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -8
package/dist/index.cjs.js
CHANGED
|
@@ -1,520 +1,546 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
170
|
+
if (typeof source === "undefined") {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
target[property] = toSnakeCase(source);
|
|
139
174
|
}
|
|
140
175
|
function transfer(target, source, omit) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
186
|
+
if (typeof source === "undefined") {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
target[property] = source;
|
|
155
190
|
}
|
|
156
191
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
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
|
+
});
|