@formo/analytics 1.19.10 → 1.21.0
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/README.md +3 -1
- package/dist/cjs/src/FormoAnalytics.d.ts +17 -1
- package/dist/cjs/src/FormoAnalytics.js +150 -82
- package/dist/cjs/src/FormoAnalyticsProvider.js +5 -1
- package/dist/cjs/src/constants/base.d.ts +4 -0
- package/dist/cjs/src/constants/base.js +8 -1
- package/dist/cjs/src/lib/browser/browsers.d.ts +3 -0
- package/dist/cjs/src/lib/browser/browsers.js +132 -0
- package/dist/cjs/src/lib/consent.d.ts +35 -0
- package/dist/cjs/src/lib/consent.js +102 -0
- package/dist/cjs/src/lib/event/EventFactory.d.ts +10 -10
- package/dist/cjs/src/lib/event/EventFactory.js +272 -140
- package/dist/cjs/src/lib/event/EventManager.d.ts +1 -1
- package/dist/cjs/src/lib/event/EventManager.js +62 -9
- package/dist/cjs/src/lib/event/type.d.ts +2 -2
- package/dist/cjs/src/lib/index.d.ts +1 -0
- package/dist/cjs/src/lib/index.js +1 -0
- package/dist/cjs/src/lib/storage/built-in/blueprint.js +2 -1
- package/dist/cjs/src/lib/version.d.ts +1 -1
- package/dist/cjs/src/lib/version.js +1 -1
- package/dist/cjs/src/types/base.d.ts +3 -0
- package/dist/cjs/src/utils/address.d.ts +7 -0
- package/dist/cjs/src/utils/address.js +21 -1
- package/dist/cjs/src/utils/hash.d.ts +10 -0
- package/dist/cjs/src/utils/hash.js +21 -0
- package/dist/cjs/src/utils/index.d.ts +1 -0
- package/dist/cjs/src/utils/index.js +1 -0
- package/dist/esm/src/FormoAnalytics.d.ts +17 -1
- package/dist/esm/src/FormoAnalytics.js +152 -84
- package/dist/esm/src/FormoAnalyticsProvider.js +5 -1
- package/dist/esm/src/constants/base.d.ts +4 -0
- package/dist/esm/src/constants/base.js +7 -0
- package/dist/esm/src/lib/browser/browsers.d.ts +3 -0
- package/dist/esm/src/lib/browser/browsers.js +129 -0
- package/dist/esm/src/lib/consent.d.ts +35 -0
- package/dist/esm/src/lib/consent.js +97 -0
- package/dist/esm/src/lib/event/EventFactory.d.ts +10 -10
- package/dist/esm/src/lib/event/EventFactory.js +272 -140
- package/dist/esm/src/lib/event/EventManager.d.ts +1 -1
- package/dist/esm/src/lib/event/EventManager.js +62 -9
- package/dist/esm/src/lib/event/type.d.ts +2 -2
- package/dist/esm/src/lib/index.d.ts +1 -0
- package/dist/esm/src/lib/index.js +1 -0
- package/dist/esm/src/lib/storage/built-in/blueprint.js +2 -1
- package/dist/esm/src/lib/version.d.ts +1 -1
- package/dist/esm/src/lib/version.js +1 -1
- package/dist/esm/src/types/base.d.ts +3 -0
- package/dist/esm/src/utils/address.d.ts +7 -0
- package/dist/esm/src/utils/address.js +19 -0
- package/dist/esm/src/utils/hash.d.ts +10 -0
- package/dist/esm/src/utils/hash.js +18 -0
- package/dist/esm/src/utils/index.d.ts +1 -0
- package/dist/esm/src/utils/index.js +1 -0
- package/dist/index.umd.min.js +1 -1
- package/package.json +2 -2
|
@@ -9,6 +9,42 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
12
48
|
import { COUNTRY_LIST, LOCAL_ANONYMOUS_ID_KEY, SESSION_TRAFFIC_SOURCE_KEY, } from "../../constants";
|
|
13
49
|
import { toChecksumAddress, toSnakeCase } from "../../utils";
|
|
14
50
|
import { getValidAddress } from "../../utils/address";
|
|
@@ -20,6 +56,7 @@ import { session } from "../storage";
|
|
|
20
56
|
import { version } from "../version";
|
|
21
57
|
import { CHANNEL, VERSION } from "./constants";
|
|
22
58
|
import { generateAnonymousId } from "./utils";
|
|
59
|
+
import { detectBrowser } from "../browser/browsers";
|
|
23
60
|
var EventFactory = /** @class */ (function () {
|
|
24
61
|
function EventFactory() {
|
|
25
62
|
var _this = this;
|
|
@@ -105,33 +142,6 @@ var EventFactory = /** @class */ (function () {
|
|
|
105
142
|
}
|
|
106
143
|
return pageProps;
|
|
107
144
|
};
|
|
108
|
-
this.getEnrichedEvent = function (formoEvent, context) {
|
|
109
|
-
var commonEventData = {
|
|
110
|
-
context: _this.generateContext(context),
|
|
111
|
-
original_timestamp: getCurrentTimeFormatted(),
|
|
112
|
-
user_id: formoEvent.user_id,
|
|
113
|
-
type: formoEvent.type,
|
|
114
|
-
channel: CHANNEL,
|
|
115
|
-
version: VERSION,
|
|
116
|
-
};
|
|
117
|
-
commonEventData.anonymous_id = generateAnonymousId(LOCAL_ANONYMOUS_ID_KEY);
|
|
118
|
-
// Handle address - convert undefined to null for consistency
|
|
119
|
-
var validAddress = getValidAddress(formoEvent.address);
|
|
120
|
-
if (validAddress) {
|
|
121
|
-
commonEventData.address = toChecksumAddress(validAddress);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
commonEventData.address = null;
|
|
125
|
-
}
|
|
126
|
-
var processedEvent = mergeDeepRight(formoEvent, commonEventData);
|
|
127
|
-
if (processedEvent.event === undefined) {
|
|
128
|
-
processedEvent.event = null;
|
|
129
|
-
}
|
|
130
|
-
if (processedEvent.properties === undefined) {
|
|
131
|
-
processedEvent.properties = null;
|
|
132
|
-
}
|
|
133
|
-
return toSnakeCase(processedEvent);
|
|
134
|
-
};
|
|
135
145
|
}
|
|
136
146
|
EventFactory.prototype.getTimezone = function () {
|
|
137
147
|
try {
|
|
@@ -170,140 +180,262 @@ var EventFactory = /** @class */ (function () {
|
|
|
170
180
|
};
|
|
171
181
|
// Contextual fields that are automatically collected and populated by the Formo SDK
|
|
172
182
|
EventFactory.prototype.generateContext = function (context) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
184
|
+
var path, browserName, language, timezone, location, library_version, defaultContext, mergedContext;
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
switch (_a.label) {
|
|
187
|
+
case 0:
|
|
188
|
+
path = globalThis.location.pathname;
|
|
189
|
+
return [4 /*yield*/, detectBrowser()];
|
|
190
|
+
case 1:
|
|
191
|
+
browserName = _a.sent();
|
|
192
|
+
language = this.getLanguage();
|
|
193
|
+
timezone = this.getTimezone();
|
|
194
|
+
location = this.getLocation();
|
|
195
|
+
library_version = this.getLibraryVersion();
|
|
196
|
+
defaultContext = __assign(__assign({ user_agent: globalThis.navigator.userAgent, locale: language, timezone: timezone, location: location }, this.getTrafficSources(globalThis.location.href)), { page_path: path, page_title: document.title, page_url: globalThis.location.href, library_name: "Formo Web SDK", library_version: library_version, browser: browserName });
|
|
197
|
+
mergedContext = mergeDeepRight(defaultContext, context || {});
|
|
198
|
+
return [2 /*return*/, mergedContext];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
EventFactory.prototype.getEnrichedEvent = function (formoEvent, context) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
var commonEventData, validAddress, processedEvent;
|
|
206
|
+
var _a;
|
|
207
|
+
return __generator(this, function (_b) {
|
|
208
|
+
switch (_b.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
_a = {};
|
|
211
|
+
return [4 /*yield*/, this.generateContext(context)];
|
|
212
|
+
case 1:
|
|
213
|
+
commonEventData = (_a.context = _b.sent(),
|
|
214
|
+
_a.original_timestamp = getCurrentTimeFormatted(),
|
|
215
|
+
_a.user_id = formoEvent.user_id,
|
|
216
|
+
_a.type = formoEvent.type,
|
|
217
|
+
_a.channel = CHANNEL,
|
|
218
|
+
_a.version = VERSION,
|
|
219
|
+
_a);
|
|
220
|
+
commonEventData.anonymous_id = generateAnonymousId(LOCAL_ANONYMOUS_ID_KEY);
|
|
221
|
+
validAddress = getValidAddress(formoEvent.address);
|
|
222
|
+
if (validAddress) {
|
|
223
|
+
commonEventData.address = toChecksumAddress(validAddress);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
commonEventData.address = null;
|
|
227
|
+
}
|
|
228
|
+
processedEvent = mergeDeepRight(formoEvent, commonEventData);
|
|
229
|
+
if (processedEvent.event === undefined) {
|
|
230
|
+
processedEvent.event = null;
|
|
231
|
+
}
|
|
232
|
+
if (processedEvent.properties === undefined) {
|
|
233
|
+
processedEvent.properties = null;
|
|
234
|
+
}
|
|
235
|
+
return [2 /*return*/, toSnakeCase(processedEvent)];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
182
239
|
};
|
|
183
240
|
EventFactory.prototype.generatePageEvent = function (category, name, properties, context) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
241
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
+
var props, pageEvent;
|
|
243
|
+
return __generator(this, function (_a) {
|
|
244
|
+
props = properties !== null && properties !== void 0 ? properties : {};
|
|
245
|
+
props.category = category;
|
|
246
|
+
props.name = name;
|
|
247
|
+
props = this.getPageProperties(props);
|
|
248
|
+
pageEvent = {
|
|
249
|
+
properties: props,
|
|
250
|
+
type: "page",
|
|
251
|
+
};
|
|
252
|
+
return [2 /*return*/, this.getEnrichedEvent(pageEvent, context)];
|
|
253
|
+
});
|
|
254
|
+
});
|
|
193
255
|
};
|
|
194
256
|
EventFactory.prototype.generateDetectWalletEvent = function (providerName, rdns, properties, context) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var detectEvent;
|
|
259
|
+
return __generator(this, function (_a) {
|
|
260
|
+
detectEvent = {
|
|
261
|
+
properties: __assign({ providerName: providerName, rdns: rdns }, properties),
|
|
262
|
+
type: "detect",
|
|
263
|
+
};
|
|
264
|
+
return [2 /*return*/, this.getEnrichedEvent(detectEvent, context)];
|
|
265
|
+
});
|
|
266
|
+
});
|
|
200
267
|
};
|
|
201
268
|
EventFactory.prototype.generateIdentifyEvent = function (providerName, rdns, address, userId, properties, context) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var identifyEvent;
|
|
271
|
+
return __generator(this, function (_a) {
|
|
272
|
+
identifyEvent = {
|
|
273
|
+
properties: __assign({ providerName: providerName, rdns: rdns }, properties),
|
|
274
|
+
user_id: userId,
|
|
275
|
+
address: address,
|
|
276
|
+
type: "identify",
|
|
277
|
+
};
|
|
278
|
+
return [2 /*return*/, this.getEnrichedEvent(identifyEvent, context)];
|
|
279
|
+
});
|
|
280
|
+
});
|
|
209
281
|
};
|
|
210
282
|
EventFactory.prototype.generateConnectEvent = function (chainId, address, properties, context) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
283
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
284
|
+
var connectEvent;
|
|
285
|
+
return __generator(this, function (_a) {
|
|
286
|
+
connectEvent = {
|
|
287
|
+
properties: __assign({ chainId: chainId }, properties),
|
|
288
|
+
address: address,
|
|
289
|
+
type: "connect",
|
|
290
|
+
};
|
|
291
|
+
return [2 /*return*/, this.getEnrichedEvent(connectEvent, context)];
|
|
292
|
+
});
|
|
293
|
+
});
|
|
217
294
|
};
|
|
218
295
|
EventFactory.prototype.generateDisconnectEvent = function (chainId, address, properties, context) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
296
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
+
var disconnectEvent;
|
|
298
|
+
return __generator(this, function (_a) {
|
|
299
|
+
disconnectEvent = {
|
|
300
|
+
properties: __assign({ chainId: chainId }, properties),
|
|
301
|
+
address: address,
|
|
302
|
+
type: "disconnect",
|
|
303
|
+
};
|
|
304
|
+
return [2 /*return*/, this.getEnrichedEvent(disconnectEvent, context)];
|
|
305
|
+
});
|
|
306
|
+
});
|
|
225
307
|
};
|
|
226
308
|
EventFactory.prototype.generateChainChangedEvent = function (chainId, address, properties, context) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
309
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
310
|
+
var chainEvent;
|
|
311
|
+
return __generator(this, function (_a) {
|
|
312
|
+
chainEvent = {
|
|
313
|
+
properties: __assign({ chainId: chainId }, properties),
|
|
314
|
+
address: address,
|
|
315
|
+
type: "chain",
|
|
316
|
+
};
|
|
317
|
+
return [2 /*return*/, this.getEnrichedEvent(chainEvent, context)];
|
|
318
|
+
});
|
|
319
|
+
});
|
|
233
320
|
};
|
|
234
321
|
EventFactory.prototype.generateSignatureEvent = function (status, chainId, address, message, signatureHash, properties, context) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
322
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
+
var signatureEvent;
|
|
324
|
+
return __generator(this, function (_a) {
|
|
325
|
+
signatureEvent = {
|
|
326
|
+
properties: __assign(__assign({ status: status, chainId: chainId, message: message }, (signatureHash && { signatureHash: signatureHash })), properties),
|
|
327
|
+
address: address,
|
|
328
|
+
type: "signature",
|
|
329
|
+
};
|
|
330
|
+
return [2 /*return*/, this.getEnrichedEvent(signatureEvent, context)];
|
|
331
|
+
});
|
|
332
|
+
});
|
|
241
333
|
};
|
|
242
334
|
EventFactory.prototype.generateTransactionEvent = function (status, chainId, address, data, to, value, transactionHash, properties, context) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
335
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
336
|
+
var transactionEvent;
|
|
337
|
+
return __generator(this, function (_a) {
|
|
338
|
+
transactionEvent = {
|
|
339
|
+
properties: __assign(__assign({ status: status, chainId: chainId, data: data, to: to, value: value }, (transactionHash && { transactionHash: transactionHash })), properties),
|
|
340
|
+
address: address,
|
|
341
|
+
type: "transaction",
|
|
342
|
+
};
|
|
343
|
+
return [2 /*return*/, this.getEnrichedEvent(transactionEvent, context)];
|
|
344
|
+
});
|
|
345
|
+
});
|
|
249
346
|
};
|
|
250
347
|
EventFactory.prototype.generateTrackEvent = function (event, properties, context) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
? properties.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
348
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
349
|
+
var trackEvent;
|
|
350
|
+
return __generator(this, function (_a) {
|
|
351
|
+
trackEvent = {
|
|
352
|
+
properties: __assign(__assign(__assign(__assign({}, properties), ((properties === null || properties === void 0 ? void 0 : properties.revenue) !== undefined && {
|
|
353
|
+
revenue: Number(properties.revenue),
|
|
354
|
+
currency: (typeof (properties === null || properties === void 0 ? void 0 : properties.currency) === "string"
|
|
355
|
+
? properties.currency
|
|
356
|
+
: "USD").toLowerCase(),
|
|
357
|
+
})), ((properties === null || properties === void 0 ? void 0 : properties.points) !== undefined && {
|
|
358
|
+
points: Number(properties.points),
|
|
359
|
+
})), ((properties === null || properties === void 0 ? void 0 : properties.volume) !== undefined && {
|
|
360
|
+
volume: Number(properties.volume),
|
|
361
|
+
})),
|
|
362
|
+
event: event,
|
|
363
|
+
type: "track",
|
|
364
|
+
};
|
|
365
|
+
return [2 /*return*/, this.getEnrichedEvent(trackEvent, context)];
|
|
366
|
+
});
|
|
367
|
+
});
|
|
266
368
|
};
|
|
267
369
|
// Returns an event with type, context, properties, and common properties
|
|
268
370
|
EventFactory.prototype.create = function (event, address, userId) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
371
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
+
var formoEvent, _a, validAddress;
|
|
373
|
+
return __generator(this, function (_b) {
|
|
374
|
+
switch (_b.label) {
|
|
375
|
+
case 0:
|
|
376
|
+
formoEvent = {};
|
|
377
|
+
_a = event.type;
|
|
378
|
+
switch (_a) {
|
|
379
|
+
case "page": return [3 /*break*/, 1];
|
|
380
|
+
case "detect": return [3 /*break*/, 3];
|
|
381
|
+
case "identify": return [3 /*break*/, 5];
|
|
382
|
+
case "chain": return [3 /*break*/, 7];
|
|
383
|
+
case "connect": return [3 /*break*/, 9];
|
|
384
|
+
case "disconnect": return [3 /*break*/, 11];
|
|
385
|
+
case "signature": return [3 /*break*/, 13];
|
|
386
|
+
case "transaction": return [3 /*break*/, 15];
|
|
387
|
+
case "track": return [3 /*break*/, 17];
|
|
388
|
+
}
|
|
389
|
+
return [3 /*break*/, 17];
|
|
390
|
+
case 1: return [4 /*yield*/, this.generatePageEvent(event.category, event.name, event.properties, event.context)];
|
|
391
|
+
case 2:
|
|
392
|
+
formoEvent = _b.sent();
|
|
393
|
+
return [3 /*break*/, 19];
|
|
394
|
+
case 3: return [4 /*yield*/, this.generateDetectWalletEvent(event.providerName, event.rdns, event.properties, event.context)];
|
|
395
|
+
case 4:
|
|
396
|
+
formoEvent = _b.sent();
|
|
397
|
+
return [3 /*break*/, 19];
|
|
398
|
+
case 5: return [4 /*yield*/, this.generateIdentifyEvent(event.providerName, event.rdns, event.address, event.userId, event.properties, event.context)];
|
|
399
|
+
case 6:
|
|
400
|
+
formoEvent = _b.sent();
|
|
401
|
+
return [3 /*break*/, 19];
|
|
402
|
+
case 7: return [4 /*yield*/, this.generateChainChangedEvent(event.chainId, event.address, event.properties, event.context)];
|
|
403
|
+
case 8:
|
|
404
|
+
formoEvent = _b.sent();
|
|
405
|
+
return [3 /*break*/, 19];
|
|
406
|
+
case 9: return [4 /*yield*/, this.generateConnectEvent(event.chainId, event.address, event.properties, event.context)];
|
|
407
|
+
case 10:
|
|
408
|
+
formoEvent = _b.sent();
|
|
409
|
+
return [3 /*break*/, 19];
|
|
410
|
+
case 11: return [4 /*yield*/, this.generateDisconnectEvent(event.chainId, event.address, event.properties, event.context)];
|
|
411
|
+
case 12:
|
|
412
|
+
formoEvent = _b.sent();
|
|
413
|
+
return [3 /*break*/, 19];
|
|
414
|
+
case 13: return [4 /*yield*/, this.generateSignatureEvent(event.status, event.chainId, event.address, event.message, event.signatureHash, event.properties, event.context)];
|
|
415
|
+
case 14:
|
|
416
|
+
formoEvent = _b.sent();
|
|
417
|
+
return [3 /*break*/, 19];
|
|
418
|
+
case 15: return [4 /*yield*/, this.generateTransactionEvent(event.status, event.chainId, event.address, event.data, event.to, event.value, event.transactionHash, event.properties, event.context)];
|
|
419
|
+
case 16:
|
|
420
|
+
formoEvent = _b.sent();
|
|
421
|
+
return [3 /*break*/, 19];
|
|
422
|
+
case 17: return [4 /*yield*/, this.generateTrackEvent(event.event, event.properties, event.context)];
|
|
423
|
+
case 18:
|
|
424
|
+
formoEvent = _b.sent();
|
|
425
|
+
return [3 /*break*/, 19];
|
|
426
|
+
case 19:
|
|
427
|
+
// Set address if not already set by the specific event generator
|
|
428
|
+
if (formoEvent.address === undefined || formoEvent.address === null) {
|
|
429
|
+
validAddress = getValidAddress(address);
|
|
430
|
+
formoEvent.address = validAddress
|
|
431
|
+
? toChecksumAddress(validAddress)
|
|
432
|
+
: null;
|
|
433
|
+
}
|
|
434
|
+
formoEvent.user_id = userId || null;
|
|
435
|
+
return [2 /*return*/, formoEvent];
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
});
|
|
307
439
|
};
|
|
308
440
|
return EventFactory;
|
|
309
441
|
}());
|
|
@@ -16,7 +16,7 @@ declare class EventManager implements IEventManager {
|
|
|
16
16
|
* Consumes a new incoming event
|
|
17
17
|
* @param event Incoming event data
|
|
18
18
|
*/
|
|
19
|
-
addEvent(event: APIEvent, address?: Address, userId?: string): void
|
|
19
|
+
addEvent(event: APIEvent, address?: Address, userId?: string): Promise<void>;
|
|
20
20
|
}
|
|
21
21
|
export { EventManager };
|
|
22
22
|
//# sourceMappingURL=EventManager.d.ts.map
|
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
1
37
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
38
|
var t = {};
|
|
3
39
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -11,6 +47,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
47
|
};
|
|
12
48
|
import { logger } from "../logger";
|
|
13
49
|
import { EventFactory } from "./EventFactory";
|
|
50
|
+
import { isBlockedAddress } from "../../utils/address";
|
|
14
51
|
/**
|
|
15
52
|
* A service to generate valid event payloads and queue them for processing
|
|
16
53
|
*/
|
|
@@ -28,15 +65,31 @@ var EventManager = /** @class */ (function () {
|
|
|
28
65
|
* @param event Incoming event data
|
|
29
66
|
*/
|
|
30
67
|
EventManager.prototype.addEvent = function (event, address, userId) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
68
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
+
var callback, _event, formoEvent;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
callback = event.callback, _event = __rest(event, ["callback"]);
|
|
74
|
+
return [4 /*yield*/, this.eventFactory.create(_event, address, userId)];
|
|
75
|
+
case 1:
|
|
76
|
+
formoEvent = _a.sent();
|
|
77
|
+
// Check if the final event has a blocked address - don't queue it
|
|
78
|
+
if (formoEvent.address && isBlockedAddress(formoEvent.address)) {
|
|
79
|
+
logger.warn("Event blocked: Address ".concat(formoEvent.address, " is in the blocked list and cannot emit events"));
|
|
80
|
+
return [2 /*return*/];
|
|
81
|
+
}
|
|
82
|
+
this.eventQueue.enqueue(formoEvent, function (err, _, data) {
|
|
83
|
+
if (err) {
|
|
84
|
+
logger.error("Error sending events:", err);
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
logger.info("Events sent successfully: ".concat(data.length, " events"));
|
|
88
|
+
callback === null || callback === void 0 ? void 0 : callback(err, _, data);
|
|
89
|
+
});
|
|
90
|
+
return [2 /*return*/];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
40
93
|
});
|
|
41
94
|
};
|
|
42
95
|
return EventManager;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Address, APIEvent, IFormoEvent } from "../../types";
|
|
2
2
|
export interface IEventManager {
|
|
3
|
-
addEvent(event: APIEvent, address?: Address, userId?: string): void
|
|
3
|
+
addEvent(event: APIEvent, address?: Address, userId?: string): Promise<void>;
|
|
4
4
|
}
|
|
5
5
|
export interface IEventFactory {
|
|
6
|
-
create(event: APIEvent, address?: Address, userId?: string): IFormoEvent
|
|
6
|
+
create(event: APIEvent, address?: Address, userId?: string): Promise<IFormoEvent>;
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { KEY_PREFIX } from "../constant";
|
|
2
|
+
import { secureHash } from "../../../utils/hash";
|
|
2
3
|
var StorageBlueprint = /** @class */ (function () {
|
|
3
4
|
function StorageBlueprint(writeKey) {
|
|
4
5
|
this.writeKey = writeKey;
|
|
5
6
|
}
|
|
6
7
|
StorageBlueprint.prototype.getKey = function (key) {
|
|
7
|
-
return "".concat(KEY_PREFIX, "_").concat(this.writeKey, "
|
|
8
|
+
return "".concat(KEY_PREFIX, "_").concat(secureHash(this.writeKey), "_").concat(key);
|
|
8
9
|
};
|
|
9
10
|
return StorageBlueprint;
|
|
10
11
|
}());
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.20.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -48,6 +48,9 @@ export interface IFormoAnalytics {
|
|
|
48
48
|
rdns?: string;
|
|
49
49
|
}, properties?: IFormoEventProperties, context?: IFormoEventContext, callback?: (...args: unknown[]) => void): Promise<void>;
|
|
50
50
|
track(event: string, properties?: IFormoEventProperties, context?: IFormoEventContext, callback?: (...args: unknown[]) => void): Promise<void>;
|
|
51
|
+
optOutTracking(): void;
|
|
52
|
+
optInTracking(): void;
|
|
53
|
+
hasOptedOutTracking(): boolean;
|
|
51
54
|
}
|
|
52
55
|
export interface Config {
|
|
53
56
|
writeKey: string;
|