@formo/analytics 1.20.0 → 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.
@@ -68,7 +68,7 @@ import { parseChainId } from "./utils/chain";
68
68
  var PROVIDER_SWITCH_REASONS = {
69
69
  ADDRESS_MISMATCH: "Address mismatch indicates wallet switch",
70
70
  NO_ACCOUNTS: "Current provider has no accounts",
71
- CHECK_FAILED: "Could not check current provider accounts"
71
+ CHECK_FAILED: "Could not check current provider accounts",
72
72
  };
73
73
  var FormoAnalytics = /** @class */ (function () {
74
74
  function FormoAnalytics(writeKey, options) {
@@ -133,7 +133,7 @@ var FormoAnalytics = /** @class */ (function () {
133
133
  if (optProvider) {
134
134
  provider = optProvider;
135
135
  }
136
- else if (typeof window !== 'undefined' && window.ethereum) {
136
+ else if (typeof window !== "undefined" && window.ethereum) {
137
137
  provider = window.ethereum;
138
138
  }
139
139
  if (provider) {
@@ -160,9 +160,9 @@ var FormoAnalytics = /** @class */ (function () {
160
160
  FormoAnalytics.prototype.isProviderInValidState = function (provider) {
161
161
  // Basic validation: ensure provider exists and has required methods
162
162
  return (provider &&
163
- typeof provider.request === 'function' &&
164
- typeof provider.on === 'function' &&
165
- typeof provider.removeListener === 'function');
163
+ typeof provider.request === "function" &&
164
+ typeof provider.on === "function" &&
165
+ typeof provider.removeListener === "function");
166
166
  };
167
167
  FormoAnalytics.init = function (writeKey, options) {
168
168
  return __awaiter(this, void 0, void 0, function () {
@@ -281,16 +281,18 @@ var FormoAnalytics = /** @class */ (function () {
281
281
  case 0:
282
282
  chainId = (params === null || params === void 0 ? void 0 : params.chainId) || this.currentChainId;
283
283
  address = (params === null || params === void 0 ? void 0 : params.address) || this.currentAddress;
284
- providerInfo = this._provider ? this.getProviderInfo(this._provider) : null;
284
+ providerInfo = this._provider
285
+ ? this.getProviderInfo(this._provider)
286
+ : null;
285
287
  logger.info("Disconnect: Emitting disconnect event with:", {
286
288
  chainId: chainId,
287
289
  address: address,
288
290
  providerName: providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.name,
289
- rdns: providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.rdns
291
+ rdns: providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.rdns,
290
292
  });
291
293
  disconnectProperties = __assign(__assign({}, (providerInfo && {
292
294
  providerName: providerInfo.name,
293
- rdns: providerInfo.rdns
295
+ rdns: providerInfo.rdns,
294
296
  })), properties);
295
297
  return [4 /*yield*/, this.trackEvent(EventType.DISCONNECT, __assign(__assign({}, (chainId && { chainId: chainId })), (address && { address: address })), disconnectProperties, context, callback)];
296
298
  case 1:
@@ -437,9 +439,12 @@ var FormoAnalytics = /** @class */ (function () {
437
439
  validAddress: validAddress_1,
438
440
  rdns: providerDetail.info.rdns,
439
441
  providerName: providerDetail.info.name,
440
- isAlreadyIdentified: validAddress_1 ? this.session.isWalletIdentified(validAddress_1, providerDetail.info.rdns) : false
442
+ isAlreadyIdentified: validAddress_1
443
+ ? this.session.isWalletIdentified(validAddress_1, providerDetail.info.rdns)
444
+ : false,
441
445
  });
442
- if (!(validAddress_1 && !this.session.isWalletIdentified(validAddress_1, providerDetail.info.rdns))) return [3 /*break*/, 5];
446
+ if (!(validAddress_1 &&
447
+ !this.session.isWalletIdentified(validAddress_1, providerDetail.info.rdns))) return [3 /*break*/, 5];
443
448
  logger.info("Auto-identifying", validAddress_1, providerDetail.info.name, providerDetail.info.rdns);
444
449
  // NOTE: do not set this.currentAddress without explicit connect or identify
445
450
  return [4 /*yield*/, this.identify({
@@ -483,23 +488,25 @@ var FormoAnalytics = /** @class */ (function () {
483
488
  this.currentUserId = userId;
484
489
  cookie().set(SESSION_USER_ID_KEY, userId);
485
490
  }
486
- isAlreadyIdentified = validAddress ? this.session.isWalletIdentified(validAddress, rdns || '') : false;
491
+ isAlreadyIdentified = validAddress
492
+ ? this.session.isWalletIdentified(validAddress, rdns || "")
493
+ : false;
487
494
  logger.debug("Identify: Checking deduplication", {
488
495
  validAddress: validAddress,
489
496
  rdns: rdns,
490
497
  providerName: providerName,
491
498
  hasValidAddress: !!validAddress,
492
499
  hasRdns: !!rdns,
493
- isAlreadyIdentified: isAlreadyIdentified
500
+ isAlreadyIdentified: isAlreadyIdentified,
494
501
  });
495
502
  if (isAlreadyIdentified) {
496
- logger.info("Identify: Wallet ".concat(providerName || 'Unknown', " with address ").concat(validAddress, " already identified in this session (rdns: ").concat(rdns || 'empty', ")"));
503
+ logger.info("Identify: Wallet ".concat(providerName || "Unknown", " with address ").concat(validAddress, " already identified in this session (rdns: ").concat(rdns || "empty", ")"));
497
504
  return [2 /*return*/];
498
505
  }
499
506
  // Mark as identified before emitting the event
500
507
  // Mark even if rdns is empty to prevent duplicate empty identifies
501
508
  if (validAddress) {
502
- this.session.markWalletIdentified(validAddress, rdns || '');
509
+ this.session.markWalletIdentified(validAddress, rdns || "");
503
510
  }
504
511
  return [4 /*yield*/, this.trackEvent(EventType.IDENTIFY, {
505
512
  address: validAddress,
@@ -667,7 +674,7 @@ var FormoAnalytics = /** @class */ (function () {
667
674
  // Prevent concurrent processing of accountsChanged events to avoid race conditions
668
675
  if (this._processingAccountsChanged) {
669
676
  logger.debug("OnAccountsChanged: Already processing accountsChanged, skipping", {
670
- provider: this.getProviderInfo(provider).name
677
+ provider: this.getProviderInfo(provider).name,
671
678
  });
672
679
  return [2 /*return*/];
673
680
  }
@@ -708,7 +715,7 @@ var FormoAnalytics = /** @class */ (function () {
708
715
  logger.info("OnAccountsChanged: Detecting disconnect, current state:", {
709
716
  currentAddress: this.currentAddress,
710
717
  currentChainId: this.currentChainId,
711
- providerMatch: this._provider === provider
718
+ providerMatch: this._provider === provider,
712
719
  });
713
720
  _a.label = 1;
714
721
  case 1:
@@ -716,7 +723,7 @@ var FormoAnalytics = /** @class */ (function () {
716
723
  // Pass current state explicitly to ensure we have the data for the disconnect event
717
724
  return [4 /*yield*/, this.disconnect({
718
725
  chainId: this.currentChainId,
719
- address: this.currentAddress
726
+ address: this.currentAddress,
720
727
  })];
721
728
  case 2:
722
729
  // Pass current state explicitly to ensure we have the data for the disconnect event
@@ -744,7 +751,7 @@ var FormoAnalytics = /** @class */ (function () {
744
751
  activeProvider: this.getProviderInfo(this._provider).name,
745
752
  eventProvider: this.getProviderInfo(provider).name,
746
753
  currentStoredAddress: currentStoredAddress,
747
- newProviderAddress: newProviderAddress
754
+ newProviderAddress: newProviderAddress,
748
755
  });
749
756
  _a.label = 8;
750
757
  case 8:
@@ -754,22 +761,26 @@ var FormoAnalytics = /** @class */ (function () {
754
761
  activeProviderAccounts = _a.sent();
755
762
  logger.info("OnAccountsChanged: Checking current provider accounts", {
756
763
  activeProvider: this.getProviderInfo(this._provider).name,
757
- accountsLength: activeProviderAccounts ? activeProviderAccounts.length : 0,
758
- accounts: activeProviderAccounts
764
+ accountsLength: activeProviderAccounts
765
+ ? activeProviderAccounts.length
766
+ : 0,
767
+ accounts: activeProviderAccounts,
759
768
  });
760
769
  if (!(activeProviderAccounts && activeProviderAccounts.length > 0)) return [3 /*break*/, 13];
761
- if (!(newProviderAddress && currentStoredAddress && newProviderAddress !== currentStoredAddress)) return [3 /*break*/, 11];
770
+ if (!(newProviderAddress &&
771
+ currentStoredAddress &&
772
+ newProviderAddress !== currentStoredAddress)) return [3 /*break*/, 11];
762
773
  logger.info("OnAccountsChanged: Different address detected, switching providers despite current provider having accounts", {
763
774
  activeProvider: this.getProviderInfo(this._provider).name,
764
775
  eventProvider: this.getProviderInfo(provider).name,
765
776
  currentAddress: currentStoredAddress,
766
777
  newAddress: newProviderAddress,
767
- reason: PROVIDER_SWITCH_REASONS.ADDRESS_MISMATCH
778
+ reason: PROVIDER_SWITCH_REASONS.ADDRESS_MISMATCH,
768
779
  });
769
780
  // Emit disconnect for the old provider
770
781
  return [4 /*yield*/, this.disconnect({
771
782
  chainId: this.currentChainId,
772
- address: this.currentAddress
783
+ address: this.currentAddress,
773
784
  })];
774
785
  case 10:
775
786
  // Emit disconnect for the old provider
@@ -783,7 +794,7 @@ var FormoAnalytics = /** @class */ (function () {
783
794
  eventProvider: this.getProviderInfo(provider).name,
784
795
  activeProviderAccountsCount: activeProviderAccounts.length,
785
796
  currentAddress: currentStoredAddress,
786
- newAddress: newProviderAddress
797
+ newAddress: newProviderAddress,
787
798
  });
788
799
  return [2 /*return*/];
789
800
  case 12: return [3 /*break*/, 15];
@@ -791,12 +802,12 @@ var FormoAnalytics = /** @class */ (function () {
791
802
  logger.info("OnAccountsChanged: Current provider has no accounts, switching to new provider", {
792
803
  oldProvider: this.getProviderInfo(this._provider).name,
793
804
  newProvider: this.getProviderInfo(provider).name,
794
- reason: PROVIDER_SWITCH_REASONS.NO_ACCOUNTS
805
+ reason: PROVIDER_SWITCH_REASONS.NO_ACCOUNTS,
795
806
  });
796
807
  // Emit disconnect for the old provider that didn't signal properly
797
808
  return [4 /*yield*/, this.disconnect({
798
809
  chainId: this.currentChainId,
799
- address: this.currentAddress
810
+ address: this.currentAddress,
800
811
  })];
801
812
  case 14:
802
813
  // Emit disconnect for the old provider that didn't signal properly
@@ -810,14 +821,16 @@ var FormoAnalytics = /** @class */ (function () {
810
821
  logger.warn("OnAccountsChanged: Could not check current provider accounts, switching to new provider", {
811
822
  error: error_2 instanceof Error ? error_2.message : String(error_2),
812
823
  errorType: error_2 instanceof Error ? error_2.constructor.name : typeof error_2,
813
- oldProvider: this._provider ? this.getProviderInfo(this._provider).name : 'unknown',
824
+ oldProvider: this._provider
825
+ ? this.getProviderInfo(this._provider).name
826
+ : "unknown",
814
827
  newProvider: this.getProviderInfo(provider).name,
815
- reason: PROVIDER_SWITCH_REASONS.CHECK_FAILED
828
+ reason: PROVIDER_SWITCH_REASONS.CHECK_FAILED,
816
829
  });
817
830
  // If we can't check the current provider, assume it's disconnected
818
831
  return [4 /*yield*/, this.disconnect({
819
832
  chainId: this.currentChainId,
820
- address: this.currentAddress
833
+ address: this.currentAddress,
821
834
  })];
822
835
  case 17:
823
836
  // If we can't check the current provider, assume it's disconnected
@@ -846,7 +859,7 @@ var FormoAnalytics = /** @class */ (function () {
846
859
  wasDisconnected: wasDisconnected,
847
860
  providerName: providerInfo.name,
848
861
  rdns: providerInfo.rdns,
849
- hasChainId: !!nextChainId
862
+ hasChainId: !!nextChainId,
850
863
  });
851
864
  effectiveChainId = nextChainId || 0;
852
865
  if (effectiveChainId === 0) {
@@ -854,10 +867,10 @@ var FormoAnalytics = /** @class */ (function () {
854
867
  }
855
868
  this.connect({
856
869
  chainId: effectiveChainId,
857
- address: address
870
+ address: address,
858
871
  }, {
859
872
  providerName: providerInfo.name,
860
- rdns: providerInfo.rdns
873
+ rdns: providerInfo.rdns,
861
874
  }).catch(function (error) {
862
875
  logger.error("Failed to track connect event during account change:", error);
863
876
  });
@@ -939,7 +952,7 @@ var FormoAnalytics = /** @class */ (function () {
939
952
  return [2 /*return*/];
940
953
  logger.info("OnDisconnect: Wallet disconnect event received, current state:", {
941
954
  currentAddress: this.currentAddress,
942
- currentChainId: this.currentChainId
955
+ currentChainId: this.currentChainId,
943
956
  });
944
957
  _a.label = 1;
945
958
  case 1:
@@ -947,7 +960,7 @@ var FormoAnalytics = /** @class */ (function () {
947
960
  // Pass current state explicitly to ensure we have the data for the disconnect event
948
961
  return [4 /*yield*/, this.disconnect({
949
962
  chainId: this.currentChainId,
950
- address: this.currentAddress
963
+ address: this.currentAddress,
951
964
  })];
952
965
  case 2:
953
966
  // Pass current state explicitly to ensure we have the data for the disconnect event
@@ -974,7 +987,7 @@ var FormoAnalytics = /** @class */ (function () {
974
987
  _a.label = 1;
975
988
  case 1:
976
989
  _a.trys.push([1, 3, , 4]);
977
- if (!(connection === null || connection === void 0 ? void 0 : connection.chainId) || typeof connection.chainId !== 'string')
990
+ if (!(connection === null || connection === void 0 ? void 0 : connection.chainId) || typeof connection.chainId !== "string")
978
991
  return [2 /*return*/];
979
992
  chainId = parseChainId(connection.chainId);
980
993
  return [4 /*yield*/, this.getAddress(provider)];
@@ -990,7 +1003,8 @@ var FormoAnalytics = /** @class */ (function () {
990
1003
  // Only update global state (chainId/address) from the active provider
991
1004
  if (isActiveProvider) {
992
1005
  this.currentChainId = chainId;
993
- this.currentAddress = this.validateAndChecksumAddress(address) || undefined;
1006
+ this.currentAddress =
1007
+ this.validateAndChecksumAddress(address) || undefined;
994
1008
  }
995
1009
  if (isActiveProvider && this.currentAddress) {
996
1010
  providerInfo = this.getProviderInfo(provider);
@@ -1000,7 +1014,7 @@ var FormoAnalytics = /** @class */ (function () {
1000
1014
  providerName: providerInfo.name,
1001
1015
  rdns: providerInfo.rdns,
1002
1016
  hasChainId: !!chainId,
1003
- isActiveProvider: isActiveProvider
1017
+ isActiveProvider: isActiveProvider,
1004
1018
  });
1005
1019
  effectiveChainId = chainId || 0;
1006
1020
  if (effectiveChainId === 0) {
@@ -1008,10 +1022,10 @@ var FormoAnalytics = /** @class */ (function () {
1008
1022
  }
1009
1023
  this.connect({
1010
1024
  chainId: effectiveChainId,
1011
- address: address
1025
+ address: address,
1012
1026
  }, {
1013
1027
  providerName: providerInfo.name,
1014
- rdns: providerInfo.rdns
1028
+ rdns: providerInfo.rdns,
1015
1029
  }).catch(function (error) {
1016
1030
  logger.error("Failed to track connect event during provider connection:", error);
1017
1031
  });
@@ -1023,7 +1037,9 @@ var FormoAnalytics = /** @class */ (function () {
1023
1037
  providerName: providerInfo.name,
1024
1038
  rdns: providerInfo.rdns,
1025
1039
  isActiveProvider: isActiveProvider,
1026
- activeProviderInfo: this._provider ? this.getProviderInfo(this._provider) : null
1040
+ activeProviderInfo: this._provider
1041
+ ? this.getProviderInfo(this._provider)
1042
+ : null,
1027
1043
  });
1028
1044
  }
1029
1045
  }
@@ -1205,7 +1221,8 @@ var FormoAnalytics = /** @class */ (function () {
1205
1221
  }); };
1206
1222
  // Mark the wrapper so we can detect if request is replaced externally and keep a reference on provider
1207
1223
  wrappedRequest[WRAPPED_REQUEST_SYMBOL] = true;
1208
- provider[WRAPPED_REQUEST_REF_SYMBOL] = wrappedRequest;
1224
+ provider[WRAPPED_REQUEST_REF_SYMBOL] =
1225
+ wrappedRequest;
1209
1226
  try {
1210
1227
  // Attempt to assign the wrapped request function (rely on try-catch for mutability errors)
1211
1228
  provider.request = wrappedRequest;
@@ -1295,18 +1312,25 @@ var FormoAnalytics = /** @class */ (function () {
1295
1312
  };
1296
1313
  FormoAnalytics.prototype.trackEvent = function (type, payload, properties, context, callback) {
1297
1314
  return __awaiter(this, void 0, void 0, function () {
1315
+ var error_5;
1298
1316
  return __generator(this, function (_a) {
1299
- try {
1300
- if (!this.shouldTrack()) {
1301
- logger.info("Skipping ".concat(type, " event due to tracking configuration"));
1302
- return [2 /*return*/];
1303
- }
1304
- this.eventManager.addEvent(__assign(__assign({ type: type }, payload), { properties: properties, context: context, callback: callback }), this.currentAddress, this.currentUserId);
1305
- }
1306
- catch (error) {
1307
- logger.error("Error tracking event:", error);
1317
+ switch (_a.label) {
1318
+ case 0:
1319
+ _a.trys.push([0, 2, , 3]);
1320
+ if (!this.shouldTrack()) {
1321
+ logger.info("Skipping ".concat(type, " event due to tracking configuration"));
1322
+ return [2 /*return*/];
1323
+ }
1324
+ return [4 /*yield*/, this.eventManager.addEvent(__assign(__assign({ type: type }, payload), { properties: properties, context: context, callback: callback }), this.currentAddress, this.currentUserId)];
1325
+ case 1:
1326
+ _a.sent();
1327
+ return [3 /*break*/, 3];
1328
+ case 2:
1329
+ error_5 = _a.sent();
1330
+ logger.error("Error tracking event:", error_5);
1331
+ return [3 /*break*/, 3];
1332
+ case 3: return [2 /*return*/];
1308
1333
  }
1309
- return [2 /*return*/];
1310
1334
  });
1311
1335
  });
1312
1336
  };
@@ -1320,23 +1344,23 @@ var FormoAnalytics = /** @class */ (function () {
1320
1344
  return false;
1321
1345
  }
1322
1346
  // Check if tracking is explicitly provided as a boolean
1323
- if (typeof this.options.tracking === 'boolean') {
1347
+ if (typeof this.options.tracking === "boolean") {
1324
1348
  return this.options.tracking;
1325
1349
  }
1326
1350
  // Handle object configuration with exclusion rules
1327
1351
  if (this.options.tracking !== null &&
1328
- typeof this.options.tracking === 'object' &&
1352
+ typeof this.options.tracking === "object" &&
1329
1353
  !Array.isArray(this.options.tracking)) {
1330
1354
  var _a = this.options.tracking, _b = _a.excludeHosts, excludeHosts = _b === void 0 ? [] : _b, _c = _a.excludePaths, excludePaths = _c === void 0 ? [] : _c, _d = _a.excludeChains, excludeChains = _d === void 0 ? [] : _d;
1331
1355
  // Check hostname exclusions - use exact matching
1332
- if (excludeHosts.length > 0 && typeof window !== 'undefined') {
1356
+ if (excludeHosts.length > 0 && typeof window !== "undefined") {
1333
1357
  var hostname = window.location.hostname;
1334
1358
  if (excludeHosts.includes(hostname)) {
1335
1359
  return false;
1336
1360
  }
1337
1361
  }
1338
1362
  // Check path exclusions - use exact matching
1339
- if (excludePaths.length > 0 && typeof window !== 'undefined') {
1363
+ if (excludePaths.length > 0 && typeof window !== "undefined") {
1340
1364
  var pathname = window.location.pathname;
1341
1365
  if (excludePaths.includes(pathname)) {
1342
1366
  return false;
@@ -1368,14 +1392,14 @@ var FormoAnalytics = /** @class */ (function () {
1368
1392
  if (eip6963Provider) {
1369
1393
  return {
1370
1394
  name: eip6963Provider.info.name,
1371
- rdns: eip6963Provider.info.rdns
1395
+ rdns: eip6963Provider.info.rdns,
1372
1396
  };
1373
1397
  }
1374
1398
  // Fallback to injected provider detection
1375
1399
  var injectedInfo = this.detectInjectedProviderInfo(provider);
1376
1400
  return {
1377
1401
  name: injectedInfo.name,
1378
- rdns: injectedInfo.rdns
1402
+ rdns: injectedInfo.rdns,
1379
1403
  };
1380
1404
  };
1381
1405
  /**
@@ -1385,45 +1409,45 @@ var FormoAnalytics = /** @class */ (function () {
1385
1409
  */
1386
1410
  FormoAnalytics.prototype.detectInjectedProviderInfo = function (provider) {
1387
1411
  // Try to detect provider type from common properties
1388
- var name = 'Injected Provider';
1389
- var rdns = 'io.injected.provider';
1412
+ var name = "Injected Provider";
1413
+ var rdns = "io.injected.provider";
1390
1414
  // Use WalletProviderFlags interface for type safety
1391
1415
  var flags = provider;
1392
1416
  // Check if it's MetaMask
1393
1417
  if (flags.isMetaMask) {
1394
- name = 'MetaMask';
1395
- rdns = 'io.metamask';
1418
+ name = "MetaMask";
1419
+ rdns = "io.metamask";
1396
1420
  }
1397
1421
  // Check if it's Coinbase Wallet
1398
1422
  else if (flags.isCoinbaseWallet) {
1399
- name = 'Coinbase Wallet';
1400
- rdns = 'com.coinbase.wallet';
1423
+ name = "Coinbase Wallet";
1424
+ rdns = "com.coinbase.wallet";
1401
1425
  }
1402
1426
  // Check if it's WalletConnect
1403
1427
  else if (flags.isWalletConnect) {
1404
- name = 'WalletConnect';
1405
- rdns = 'com.walletconnect';
1428
+ name = "WalletConnect";
1429
+ rdns = "com.walletconnect";
1406
1430
  }
1407
1431
  // Check if it's Trust Wallet
1408
1432
  else if (flags.isTrust) {
1409
- name = 'Trust Wallet';
1410
- rdns = 'com.trustwallet';
1433
+ name = "Trust Wallet";
1434
+ rdns = "com.trustwallet";
1411
1435
  }
1412
1436
  // Check if it's Brave Wallet
1413
1437
  else if (flags.isBraveWallet) {
1414
- name = 'Brave Wallet';
1415
- rdns = 'com.brave.wallet';
1438
+ name = "Brave Wallet";
1439
+ rdns = "com.brave.wallet";
1416
1440
  }
1417
1441
  // Check if it's Phantom
1418
1442
  else if (flags.isPhantom) {
1419
- name = 'Phantom';
1420
- rdns = 'app.phantom';
1443
+ name = "Phantom";
1444
+ rdns = "app.phantom";
1421
1445
  }
1422
1446
  return {
1423
1447
  name: name,
1424
1448
  rdns: rdns,
1425
- uuid: "injected-".concat(rdns.replace(/[^a-zA-Z0-9]/g, '-')),
1426
- icon: DEFAULT_PROVIDER_ICON
1449
+ uuid: "injected-".concat(rdns.replace(/[^a-zA-Z0-9]/g, "-")),
1450
+ icon: DEFAULT_PROVIDER_ICON,
1427
1451
  };
1428
1452
  };
1429
1453
  FormoAnalytics.prototype.getProviders = function () {
@@ -1477,7 +1501,7 @@ var FormoAnalytics = /** @class */ (function () {
1477
1501
  });
1478
1502
  // Fallback to injected provider if no providers are found
1479
1503
  if (providers.length === 0) {
1480
- injected_1 = typeof window !== 'undefined' ? window.ethereum : undefined;
1504
+ injected_1 = typeof window !== "undefined" ? window.ethereum : undefined;
1481
1505
  if (injected_1) {
1482
1506
  // If we have already detected and cached the injected provider, and it's the same instance, return the cached result
1483
1507
  if (this._injectedProviderDetail &&
@@ -1488,7 +1512,9 @@ var FormoAnalytics = /** @class */ (function () {
1488
1512
  }
1489
1513
  // Merge with existing providers instead of overwriting
1490
1514
  if (!this._providers.some(function (existing) { return existing.provider === injected_1; })) {
1491
- this._providers = __spreadArray(__spreadArray([], this._providers, true), [this._injectedProviderDetail], false);
1515
+ this._providers = __spreadArray(__spreadArray([], this._providers, true), [
1516
+ this._injectedProviderDetail,
1517
+ ], false);
1492
1518
  }
1493
1519
  return [2 /*return*/, this._providers];
1494
1520
  }
@@ -1499,7 +1525,7 @@ var FormoAnalytics = /** @class */ (function () {
1499
1525
  injectedProviderInfo = this.detectInjectedProviderInfo(injected_1);
1500
1526
  injectedDetail = {
1501
1527
  provider: injected_1,
1502
- info: injectedProviderInfo
1528
+ info: injectedProviderInfo,
1503
1529
  };
1504
1530
  // Cache the detected injected provider detail
1505
1531
  this._injectedProviderDetail = injectedDetail;
@@ -1838,9 +1864,10 @@ var FormoAnalytics = /** @class */ (function () {
1838
1864
  */
1839
1865
  FormoAnalytics.prototype.isProviderAlreadyWrapped = function (provider, currentRequest) {
1840
1866
  return !!(currentRequest &&
1841
- typeof currentRequest === 'function' &&
1867
+ typeof currentRequest === "function" &&
1842
1868
  currentRequest[WRAPPED_REQUEST_SYMBOL] &&
1843
- provider[WRAPPED_REQUEST_REF_SYMBOL] === currentRequest);
1869
+ provider[WRAPPED_REQUEST_REF_SYMBOL] ===
1870
+ currentRequest);
1844
1871
  };
1845
1872
  /**
1846
1873
  * Handle provider mismatch by switching to the new provider and invalidating old tokens
@@ -1929,7 +1956,7 @@ var FormoAnalyticsSession = /** @class */ (function () {
1929
1956
  logger.debug("Session: Checking wallet identification", {
1930
1957
  identifiedKey: identifiedKey,
1931
1958
  isIdentified: isIdentified,
1932
- hasRdns: !!rdns
1959
+ hasRdns: !!rdns,
1933
1960
  });
1934
1961
  return isIdentified;
1935
1962
  };
@@ -1947,14 +1974,14 @@ var FormoAnalyticsSession = /** @class */ (function () {
1947
1974
  });
1948
1975
  logger.debug("Session: Marked wallet as identified", {
1949
1976
  identifiedKey: identifiedKey,
1950
- hasRdns: !!rdns
1977
+ hasRdns: !!rdns,
1951
1978
  });
1952
1979
  }
1953
1980
  else {
1954
1981
  logger.info("Session: Wallet already marked as identified", {
1955
1982
  identifiedKey: identifiedKey,
1956
1983
  existingWallets: identifiedWallets,
1957
- hasRdns: !!rdns
1984
+ hasRdns: !!rdns,
1958
1985
  });
1959
1986
  }
1960
1987
  };
@@ -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