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