@formo/analytics 1.20.0 → 1.22.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.
@@ -0,0 +1,3 @@
1
+ export type BrowserName = "brave" | "chrome" | "edge" | "firefox" | "safari" | "opera" | "unknown";
2
+ export declare function detectBrowser(): Promise<BrowserName>;
3
+ //# sourceMappingURL=browsers.d.ts.map
@@ -0,0 +1,129 @@
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
+ };
37
+ var inFlight = null;
38
+ var cached = null;
39
+ function getUA() {
40
+ try {
41
+ return typeof globalThis.navigator !== "undefined"
42
+ ? globalThis.navigator.userAgent
43
+ : "";
44
+ }
45
+ catch (_a) {
46
+ return "";
47
+ }
48
+ }
49
+ function isBraveHeuristic() {
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var nav, ok, _a, brands;
52
+ var _b, _c;
53
+ return __generator(this, function (_d) {
54
+ switch (_d.label) {
55
+ case 0:
56
+ nav = typeof globalThis.navigator !== "undefined"
57
+ ? globalThis.navigator
58
+ : undefined;
59
+ if (!nav)
60
+ return [2 /*return*/, false];
61
+ _d.label = 1;
62
+ case 1:
63
+ _d.trys.push([1, 4, , 5]);
64
+ if (!((_b = nav.brave) === null || _b === void 0 ? void 0 : _b.isBrave)) return [3 /*break*/, 3];
65
+ return [4 /*yield*/, nav.brave.isBrave().catch(function () { return false; })];
66
+ case 2:
67
+ ok = _d.sent();
68
+ if (ok)
69
+ return [2 /*return*/, true];
70
+ _d.label = 3;
71
+ case 3: return [3 /*break*/, 5];
72
+ case 4:
73
+ _a = _d.sent();
74
+ return [3 /*break*/, 5];
75
+ case 5:
76
+ try {
77
+ brands = (_c = nav.userAgentData) === null || _c === void 0 ? void 0 : _c.brands;
78
+ if (brands === null || brands === void 0 ? void 0 : brands.some(function (b) { return /Brave/i.test(b.brand); }))
79
+ return [2 /*return*/, true];
80
+ }
81
+ catch (_e) { }
82
+ try {
83
+ if (/Brave/i.test(nav.userAgent))
84
+ return [2 /*return*/, true];
85
+ }
86
+ catch (_f) { }
87
+ return [2 /*return*/, false];
88
+ }
89
+ });
90
+ });
91
+ }
92
+ function classifyNonBrave(ua) {
93
+ if (/Firefox\/\d+/i.test(ua))
94
+ return "firefox";
95
+ if (/Edg\/\d+/i.test(ua))
96
+ return "edge";
97
+ if (/OPR\/\d+/i.test(ua))
98
+ return "opera";
99
+ if (/Safari\/\d+/i.test(ua) && !/Chrome\/\d+/i.test(ua))
100
+ return "safari";
101
+ if (/Chrome\/\d+/i.test(ua))
102
+ return "chrome";
103
+ return "unknown";
104
+ }
105
+ export function detectBrowser() {
106
+ var _this = this;
107
+ if (cached)
108
+ return Promise.resolve(cached);
109
+ if (inFlight)
110
+ return inFlight;
111
+ inFlight = (function () { return __awaiter(_this, void 0, void 0, function () {
112
+ var ua, brave;
113
+ return __generator(this, function (_a) {
114
+ switch (_a.label) {
115
+ case 0:
116
+ ua = getUA();
117
+ return [4 /*yield*/, isBraveHeuristic().catch(function () { return false; })];
118
+ case 1:
119
+ brave = _a.sent();
120
+ cached = brave ? "brave" : classifyNonBrave(ua);
121
+ return [2 /*return*/, cached];
122
+ }
123
+ });
124
+ }); })().finally(function () {
125
+ inFlight = null; // subsequent calls hit cache
126
+ });
127
+ return inFlight;
128
+ }
129
+ //# sourceMappingURL=browsers.js.map
@@ -16,16 +16,16 @@ declare class EventFactory implements IEventFactory {
16
16
  */
17
17
  private getPageProperties;
18
18
  private getEnrichedEvent;
19
- generatePageEvent(category?: string, name?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
20
- generateDetectWalletEvent(providerName: string, rdns: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
21
- generateIdentifyEvent(providerName: string, rdns: string, address: Nullable<Address>, userId?: Nullable<string>, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
22
- generateConnectEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
23
- generateDisconnectEvent(chainId?: ChainID, address?: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
24
- generateChainChangedEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
25
- generateSignatureEvent(status: SignatureStatus, chainId: ChainID, address: Address, message: string, signatureHash?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
26
- generateTransactionEvent(status: TransactionStatus, chainId: ChainID, address: Address, data: string, to: string, value: string, transactionHash?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
27
- generateTrackEvent(event: string, properties?: IFormoEventProperties, context?: IFormoEventContext): IFormoEvent;
28
- create(event: APIEvent, address?: Address, userId?: string): IFormoEvent;
19
+ generatePageEvent(category?: string, name?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
20
+ generateDetectWalletEvent(providerName: string, rdns: string, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
21
+ generateIdentifyEvent(providerName: string, rdns: string, address: Nullable<Address>, userId?: Nullable<string>, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
22
+ generateConnectEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
23
+ generateDisconnectEvent(chainId?: ChainID, address?: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
24
+ generateChainChangedEvent(chainId: ChainID, address: Address, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
25
+ generateSignatureEvent(status: SignatureStatus, chainId: ChainID, address: Address, message: string, signatureHash?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
26
+ generateTransactionEvent(status: TransactionStatus, chainId: ChainID, address: Address, data: string, to: string, value: string, transactionHash?: string, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
27
+ generateTrackEvent(event: string, properties?: IFormoEventProperties, context?: IFormoEventContext): Promise<IFormoEvent>;
28
+ create(event: APIEvent, address?: Address, userId?: string): Promise<IFormoEvent>;
29
29
  }
30
30
  export { EventFactory };
31
31
  //# sourceMappingURL=EventFactory.d.ts.map
@@ -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
- var path = globalThis.location.pathname;
174
- var language = this.getLanguage();
175
- var timezone = this.getTimezone();
176
- var location = this.getLocation();
177
- var library_version = this.getLibraryVersion();
178
- // contextual properties
179
- var 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 });
180
- var mergedContext = mergeDeepRight(defaultContext, context || {});
181
- return mergedContext;
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
- var props = properties !== null && properties !== void 0 ? properties : {};
185
- props.category = category;
186
- props.name = name;
187
- props = this.getPageProperties(props);
188
- var pageEvent = {
189
- properties: props,
190
- type: "page",
191
- };
192
- return this.getEnrichedEvent(pageEvent, context);
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
- var detectEvent = {
196
- properties: __assign({ providerName: providerName, rdns: rdns }, properties),
197
- type: "detect",
198
- };
199
- return this.getEnrichedEvent(detectEvent, context);
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
- var identifyEvent = {
203
- properties: __assign({ providerName: providerName, rdns: rdns }, properties),
204
- user_id: userId,
205
- address: address,
206
- type: "identify",
207
- };
208
- return this.getEnrichedEvent(identifyEvent, context);
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
- var connectEvent = {
212
- properties: __assign({ chainId: chainId }, properties),
213
- address: address,
214
- type: "connect",
215
- };
216
- return this.getEnrichedEvent(connectEvent, context);
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
- var disconnectEvent = {
220
- properties: __assign({ chainId: chainId }, properties),
221
- address: address,
222
- type: "disconnect",
223
- };
224
- return this.getEnrichedEvent(disconnectEvent, context);
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
- var chainEvent = {
228
- properties: __assign({ chainId: chainId }, properties),
229
- address: address,
230
- type: "chain",
231
- };
232
- return this.getEnrichedEvent(chainEvent, context);
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
- var signatureEvent = {
236
- properties: __assign(__assign({ status: status, chainId: chainId, message: message }, (signatureHash && { signatureHash: signatureHash })), properties),
237
- address: address,
238
- type: "signature",
239
- };
240
- return this.getEnrichedEvent(signatureEvent, context);
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
- var transactionEvent = {
244
- properties: __assign(__assign({ status: status, chainId: chainId, data: data, to: to, value: value }, (transactionHash && { transactionHash: transactionHash })), properties),
245
- address: address,
246
- type: "transaction",
247
- };
248
- return this.getEnrichedEvent(transactionEvent, context);
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
- var trackEvent = {
252
- properties: __assign(__assign(__assign(__assign({}, properties), ((properties === null || properties === void 0 ? void 0 : properties.revenue) !== undefined && {
253
- revenue: Number(properties.revenue),
254
- currency: (typeof (properties === null || properties === void 0 ? void 0 : properties.currency) === "string"
255
- ? properties.currency
256
- : "USD").toLowerCase(),
257
- })), ((properties === null || properties === void 0 ? void 0 : properties.points) !== undefined && {
258
- points: Number(properties.points),
259
- })), ((properties === null || properties === void 0 ? void 0 : properties.volume) !== undefined && {
260
- volume: Number(properties.volume),
261
- })),
262
- event: event,
263
- type: "track",
264
- };
265
- return this.getEnrichedEvent(trackEvent, context);
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
- var formoEvent = {};
270
- switch (event.type) {
271
- case "page":
272
- formoEvent = this.generatePageEvent(event.category, event.name, event.properties, event.context);
273
- break;
274
- case "detect":
275
- formoEvent = this.generateDetectWalletEvent(event.providerName, event.rdns, event.properties, event.context);
276
- break;
277
- case "identify":
278
- formoEvent = this.generateIdentifyEvent(event.providerName, event.rdns, event.address, event.userId, event.properties, event.context);
279
- break;
280
- case "chain":
281
- formoEvent = this.generateChainChangedEvent(event.chainId, event.address, event.properties, event.context);
282
- break;
283
- case "connect":
284
- formoEvent = this.generateConnectEvent(event.chainId, event.address, event.properties, event.context);
285
- break;
286
- case "disconnect":
287
- formoEvent = this.generateDisconnectEvent(event.chainId, event.address, event.properties, event.context);
288
- break;
289
- case "signature":
290
- formoEvent = this.generateSignatureEvent(event.status, event.chainId, event.address, event.message, event.signatureHash, event.properties, event.context);
291
- break;
292
- case "transaction":
293
- formoEvent = this.generateTransactionEvent(event.status, event.chainId, event.address, event.data, event.to, event.value, event.transactionHash, event.properties, event.context);
294
- break;
295
- case "track":
296
- default:
297
- formoEvent = this.generateTrackEvent(event.event, event.properties, event.context);
298
- break;
299
- }
300
- // Set address if not already set by the specific event generator
301
- if (formoEvent.address === undefined || formoEvent.address === null) {
302
- var validAddress = getValidAddress(address);
303
- formoEvent.address = validAddress ? toChecksumAddress(validAddress) : null;
304
- }
305
- formoEvent.user_id = userId || null;
306
- return formoEvent;
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