@formo/analytics 1.28.1 → 1.28.3

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 (66) hide show
  1. package/dist/cjs/src/FormoAnalytics.d.ts +3 -2
  2. package/dist/cjs/src/FormoAnalytics.js +19 -11
  3. package/dist/cjs/src/FormoAnalyticsProvider.js +1 -0
  4. package/dist/cjs/src/consent/index.js +12 -10
  5. package/dist/cjs/src/event/EventFactory.d.ts +1 -1
  6. package/dist/cjs/src/event/EventFactory.js +9 -9
  7. package/dist/cjs/src/event/utils.d.ts +2 -3
  8. package/dist/cjs/src/event/utils.js +24 -24
  9. package/dist/cjs/src/queue/EventQueue.d.ts +1 -1
  10. package/dist/cjs/src/queue/EventQueue.js +21 -20
  11. package/dist/cjs/src/session/index.d.ts +0 -9
  12. package/dist/cjs/src/session/index.js +7 -0
  13. package/dist/cjs/src/solana/SolanaAdapter.d.ts +3 -4
  14. package/dist/cjs/src/solana/SolanaAdapter.js +42 -29
  15. package/dist/cjs/src/storage/StorageManager.js +11 -3
  16. package/dist/cjs/src/storage/built-in/cookie.js +29 -3
  17. package/dist/cjs/src/storage/cookiePolicy.d.ts +10 -0
  18. package/dist/cjs/src/storage/cookiePolicy.js +27 -0
  19. package/dist/cjs/src/types/base.d.ts +12 -0
  20. package/dist/cjs/src/types/events.d.ts +0 -1
  21. package/dist/cjs/src/utils/address.js +4 -6
  22. package/dist/cjs/src/utils/domain.d.ts +27 -0
  23. package/dist/cjs/src/utils/domain.js +74 -0
  24. package/dist/cjs/src/utils/generate.js +23 -11
  25. package/dist/cjs/src/utils/index.d.ts +0 -1
  26. package/dist/cjs/src/utils/index.js +0 -1
  27. package/dist/cjs/src/validators/network.js +7 -2
  28. package/dist/cjs/src/version.d.ts +1 -1
  29. package/dist/cjs/src/version.js +1 -1
  30. package/dist/cjs/src/wagmi/WagmiEventHandler.js +12 -9
  31. package/dist/esm/src/FormoAnalytics.d.ts +3 -2
  32. package/dist/esm/src/FormoAnalytics.js +19 -11
  33. package/dist/esm/src/FormoAnalyticsProvider.js +1 -0
  34. package/dist/esm/src/consent/index.js +12 -10
  35. package/dist/esm/src/event/EventFactory.d.ts +1 -1
  36. package/dist/esm/src/event/EventFactory.js +9 -9
  37. package/dist/esm/src/event/utils.d.ts +2 -3
  38. package/dist/esm/src/event/utils.js +25 -24
  39. package/dist/esm/src/queue/EventQueue.d.ts +1 -1
  40. package/dist/esm/src/queue/EventQueue.js +21 -20
  41. package/dist/esm/src/session/index.d.ts +0 -9
  42. package/dist/esm/src/session/index.js +7 -0
  43. package/dist/esm/src/solana/SolanaAdapter.d.ts +3 -4
  44. package/dist/esm/src/solana/SolanaAdapter.js +42 -29
  45. package/dist/esm/src/storage/StorageManager.js +11 -3
  46. package/dist/esm/src/storage/built-in/cookie.js +29 -3
  47. package/dist/esm/src/storage/cookiePolicy.d.ts +10 -0
  48. package/dist/esm/src/storage/cookiePolicy.js +24 -0
  49. package/dist/esm/src/types/base.d.ts +12 -0
  50. package/dist/esm/src/types/events.d.ts +0 -1
  51. package/dist/esm/src/utils/address.js +4 -6
  52. package/dist/esm/src/utils/domain.d.ts +27 -0
  53. package/dist/esm/src/utils/domain.js +70 -0
  54. package/dist/esm/src/utils/generate.js +23 -11
  55. package/dist/esm/src/utils/index.d.ts +0 -1
  56. package/dist/esm/src/utils/index.js +0 -1
  57. package/dist/esm/src/validators/network.js +7 -2
  58. package/dist/esm/src/version.d.ts +1 -1
  59. package/dist/esm/src/version.js +1 -1
  60. package/dist/esm/src/wagmi/WagmiEventHandler.js +12 -9
  61. package/dist/index.umd.min.js +1 -1
  62. package/package.json +1 -1
  63. package/dist/cjs/src/utils/builderCode.d.ts +0 -30
  64. package/dist/cjs/src/utils/builderCode.js +0 -143
  65. package/dist/esm/src/utils/builderCode.d.ts +0 -30
  66. package/dist/esm/src/utils/builderCode.js +0 -140
@@ -115,6 +115,11 @@ var SolanaAdapter = /** @class */ (function () {
115
115
  * Key: transaction signature, Value: transaction details
116
116
  */
117
117
  this.pendingTransactions = new Map();
118
+ /**
119
+ * Per-adapter original methods stored in a WeakMap to prevent routing
120
+ * to the wrong wallet after switching adapters.
121
+ */
122
+ this.adapterOriginals = new WeakMap();
118
123
  /**
119
124
  * Track active polling timeout IDs for cleanup
120
125
  */
@@ -144,21 +149,22 @@ var SolanaAdapter = /** @class */ (function () {
144
149
  SolanaAdapter.prototype.restoreOriginalMethods = function () {
145
150
  // Restore adapter methods
146
151
  if (this.wrappedAdapter) {
147
- if (this.originalAdapterSendTransaction) {
148
- this.wrappedAdapter.sendTransaction = this.originalAdapterSendTransaction;
149
- }
150
- if (this.originalAdapterSignMessage) {
151
- this.wrappedAdapter.signMessage = this.originalAdapterSignMessage;
152
- }
153
- if (this.originalAdapterSignTransaction) {
154
- this.wrappedAdapter.signTransaction = this.originalAdapterSignTransaction;
152
+ var originals = this.adapterOriginals.get(this.wrappedAdapter);
153
+ if (originals) {
154
+ if (originals.sendTransaction) {
155
+ this.wrappedAdapter.sendTransaction = originals.sendTransaction;
156
+ }
157
+ if (originals.signMessage) {
158
+ this.wrappedAdapter.signMessage = originals.signMessage;
159
+ }
160
+ if (originals.signTransaction) {
161
+ this.wrappedAdapter.signTransaction = originals.signTransaction;
162
+ }
163
+ this.adapterOriginals.delete(this.wrappedAdapter);
155
164
  }
156
165
  this.wrappedAdapter = undefined;
157
166
  }
158
- // Clear original and bound wrapper references
159
- this.originalAdapterSendTransaction = undefined;
160
- this.originalAdapterSignMessage = undefined;
161
- this.originalAdapterSignTransaction = undefined;
167
+ // Clear bound wrapper references
162
168
  this.boundWrappedSendTransaction = undefined;
163
169
  this.boundWrappedSignMessage = undefined;
164
170
  this.boundWrappedSignTransaction = undefined;
@@ -387,24 +393,26 @@ var SolanaAdapter = /** @class */ (function () {
387
393
  }
388
394
  // Store reference to adapter for cleanup
389
395
  this.wrappedAdapter = adapter;
396
+ var originals = {};
390
397
  // Wrap sendTransaction
391
398
  if (adapter.sendTransaction) {
392
- this.originalAdapterSendTransaction = adapter.sendTransaction.bind(adapter);
399
+ originals.sendTransaction = adapter.sendTransaction.bind(adapter);
393
400
  this.boundWrappedSendTransaction = this.wrappedSendTransaction.bind(this);
394
401
  adapter.sendTransaction = this.boundWrappedSendTransaction;
395
402
  }
396
403
  // Wrap signMessage
397
404
  if (adapter.signMessage) {
398
- this.originalAdapterSignMessage = adapter.signMessage.bind(adapter);
405
+ originals.signMessage = adapter.signMessage.bind(adapter);
399
406
  this.boundWrappedSignMessage = this.wrappedSignMessage.bind(this);
400
407
  adapter.signMessage = this.boundWrappedSignMessage;
401
408
  }
402
409
  // Wrap signTransaction
403
410
  if (adapter.signTransaction) {
404
- this.originalAdapterSignTransaction = adapter.signTransaction.bind(adapter);
411
+ originals.signTransaction = adapter.signTransaction.bind(adapter);
405
412
  this.boundWrappedSignTransaction = this.wrappedSignTransaction.bind(this);
406
413
  adapter.signTransaction = this.boundWrappedSignTransaction;
407
414
  }
415
+ this.adapterOriginals.set(adapter, originals);
408
416
  };
409
417
  /**
410
418
  * Re-wrap methods that were overwritten by external code.
@@ -416,9 +424,10 @@ var SolanaAdapter = /** @class */ (function () {
416
424
  */
417
425
  SolanaAdapter.prototype.rewrapOverwrittenMethods = function (adapter) {
418
426
  var rewrapped = false;
427
+ var originals = this.adapterOriginals.get(adapter) || {};
419
428
  // signMessage
420
429
  if (adapter.signMessage && adapter.signMessage !== this.boundWrappedSignMessage) {
421
- this.originalAdapterSignMessage = adapter.signMessage.bind(adapter);
430
+ originals.signMessage = adapter.signMessage.bind(adapter);
422
431
  if (!this.boundWrappedSignMessage) {
423
432
  this.boundWrappedSignMessage = this.wrappedSignMessage.bind(this);
424
433
  }
@@ -426,11 +435,11 @@ var SolanaAdapter = /** @class */ (function () {
426
435
  rewrapped = true;
427
436
  }
428
437
  else if (!adapter.signMessage && this.boundWrappedSignMessage) {
429
- this.originalAdapterSignMessage = undefined;
438
+ originals.signMessage = undefined;
430
439
  }
431
440
  // signTransaction
432
441
  if (adapter.signTransaction && adapter.signTransaction !== this.boundWrappedSignTransaction) {
433
- this.originalAdapterSignTransaction = adapter.signTransaction.bind(adapter);
442
+ originals.signTransaction = adapter.signTransaction.bind(adapter);
434
443
  if (!this.boundWrappedSignTransaction) {
435
444
  this.boundWrappedSignTransaction = this.wrappedSignTransaction.bind(this);
436
445
  }
@@ -438,17 +447,18 @@ var SolanaAdapter = /** @class */ (function () {
438
447
  rewrapped = true;
439
448
  }
440
449
  else if (!adapter.signTransaction && this.boundWrappedSignTransaction) {
441
- this.originalAdapterSignTransaction = undefined;
450
+ originals.signTransaction = undefined;
442
451
  }
443
452
  // sendTransaction — unlikely to be overwritten but check for completeness
444
453
  if (adapter.sendTransaction && adapter.sendTransaction !== this.boundWrappedSendTransaction) {
445
- this.originalAdapterSendTransaction = adapter.sendTransaction.bind(adapter);
454
+ originals.sendTransaction = adapter.sendTransaction.bind(adapter);
446
455
  if (!this.boundWrappedSendTransaction) {
447
456
  this.boundWrappedSendTransaction = this.wrappedSendTransaction.bind(this);
448
457
  }
449
458
  adapter.sendTransaction = this.boundWrappedSendTransaction;
450
459
  rewrapped = true;
451
460
  }
461
+ this.adapterOriginals.set(adapter, originals);
452
462
  if (rewrapped) {
453
463
  logger.debug("SolanaAdapter: Re-wrapped overwritten adapter methods");
454
464
  }
@@ -458,12 +468,13 @@ var SolanaAdapter = /** @class */ (function () {
458
468
  */
459
469
  SolanaAdapter.prototype.wrappedSendTransaction = function (transaction, connection, options) {
460
470
  return __awaiter(this, void 0, void 0, function () {
461
- var chainId, address, signature, error_1;
471
+ var originals, chainId, address, signature, error_1;
462
472
  return __generator(this, function (_a) {
463
473
  switch (_a.label) {
464
474
  case 0:
465
475
  this.checkAndRebindContextAdapter();
466
- if (!this.originalAdapterSendTransaction) {
476
+ originals = this.wrappedAdapter ? this.adapterOriginals.get(this.wrappedAdapter) : undefined;
477
+ if (!(originals === null || originals === void 0 ? void 0 : originals.sendTransaction)) {
467
478
  throw new Error("sendTransaction not available");
468
479
  }
469
480
  chainId = this.chainId;
@@ -472,7 +483,7 @@ var SolanaAdapter = /** @class */ (function () {
472
483
  _a.label = 1;
473
484
  case 1:
474
485
  _a.trys.push([1, 3, , 4]);
475
- return [4 /*yield*/, this.originalAdapterSendTransaction(transaction, connection, options)];
486
+ return [4 /*yield*/, originals.sendTransaction(transaction, connection, options)];
476
487
  case 2:
477
488
  signature = _a.sent();
478
489
  this.emitTransactionEvent(TransactionStatus.BROADCASTED, address, chainId, signature);
@@ -498,12 +509,13 @@ var SolanaAdapter = /** @class */ (function () {
498
509
  */
499
510
  SolanaAdapter.prototype.wrappedSignMessage = function (message) {
500
511
  return __awaiter(this, void 0, void 0, function () {
501
- var chainId, address, messageString, signature, signatureHex, error_2;
512
+ var originals, chainId, address, messageString, signature, signatureHex, error_2;
502
513
  return __generator(this, function (_a) {
503
514
  switch (_a.label) {
504
515
  case 0:
505
516
  this.checkAndRebindContextAdapter();
506
- if (!this.originalAdapterSignMessage) {
517
+ originals = this.wrappedAdapter ? this.adapterOriginals.get(this.wrappedAdapter) : undefined;
518
+ if (!(originals === null || originals === void 0 ? void 0 : originals.signMessage)) {
507
519
  throw new Error("signMessage not available");
508
520
  }
509
521
  chainId = this.chainId;
@@ -513,7 +525,7 @@ var SolanaAdapter = /** @class */ (function () {
513
525
  _a.label = 1;
514
526
  case 1:
515
527
  _a.trys.push([1, 3, , 4]);
516
- return [4 /*yield*/, this.originalAdapterSignMessage(message)];
528
+ return [4 /*yield*/, originals.signMessage(message)];
517
529
  case 2:
518
530
  signature = _a.sent();
519
531
  signatureHex = uint8ArrayToHex(signature);
@@ -533,12 +545,13 @@ var SolanaAdapter = /** @class */ (function () {
533
545
  */
534
546
  SolanaAdapter.prototype.wrappedSignTransaction = function (transaction) {
535
547
  return __awaiter(this, void 0, void 0, function () {
536
- var chainId, address, message, signedTx, error_3;
548
+ var originals, chainId, address, message, signedTx, error_3;
537
549
  return __generator(this, function (_a) {
538
550
  switch (_a.label) {
539
551
  case 0:
540
552
  this.checkAndRebindContextAdapter();
541
- if (!this.originalAdapterSignTransaction) {
553
+ originals = this.wrappedAdapter ? this.adapterOriginals.get(this.wrappedAdapter) : undefined;
554
+ if (!(originals === null || originals === void 0 ? void 0 : originals.signTransaction)) {
542
555
  throw new Error("signTransaction not available");
543
556
  }
544
557
  chainId = this.chainId;
@@ -548,7 +561,7 @@ var SolanaAdapter = /** @class */ (function () {
548
561
  _a.label = 1;
549
562
  case 1:
550
563
  _a.trys.push([1, 3, , 4]);
551
- return [4 /*yield*/, this.originalAdapterSignTransaction(transaction)];
564
+ return [4 /*yield*/, originals.signTransaction(transaction)];
552
565
  case 2:
553
566
  signedTx = _a.sent();
554
567
  this.emitSignatureEvent(SignatureStatus.CONFIRMED, address, chainId, message);
@@ -17,11 +17,19 @@ var StorageManager = /** @class */ (function () {
17
17
  StorageManager.prototype.getStorage = function (type) {
18
18
  if (!this.storages.has(type)) {
19
19
  var storage = this.createStorage(type);
20
+ var currentType = type;
20
21
  // If storage is not available, try next
21
22
  while (!storage.isAvailable()) {
22
- var index = TYPES.indexOf(type);
23
- logger.warn("Storage ".concat(type, " is not available, trying ").concat(TYPES[index + 1]));
24
- storage = this.createStorage(TYPES[index + 1]);
23
+ var index = TYPES.indexOf(currentType);
24
+ if (index === -1 || index + 1 >= TYPES.length) {
25
+ // No more fallbacks, use memory storage as last resort
26
+ storage = this.createStorage("memoryStorage");
27
+ break;
28
+ }
29
+ var prevType = currentType;
30
+ currentType = TYPES[index + 1];
31
+ logger.warn("Storage ".concat(prevType, " is not available, trying ").concat(currentType));
32
+ storage = this.createStorage(currentType);
25
33
  }
26
34
  // Add to cache
27
35
  this.storages.set(type, storage);
@@ -14,6 +14,7 @@ var __extends = (this && this.__extends) || (function () {
14
14
  };
15
15
  })();
16
16
  import StorageBlueprint from "./blueprint";
17
+ import { getApexDomain } from "../../utils/domain";
17
18
  var CookieStorage = /** @class */ (function (_super) {
18
19
  __extends(CookieStorage, _super);
19
20
  function CookieStorage() {
@@ -26,10 +27,27 @@ var CookieStorage = /** @class */ (function (_super) {
26
27
  var expires = options === null || options === void 0 ? void 0 : options.expires;
27
28
  var maxAge = options === null || options === void 0 ? void 0 : options.maxAge;
28
29
  var path = (options === null || options === void 0 ? void 0 : options.path) || "/";
29
- var domain = options === null || options === void 0 ? void 0 : options.domain;
30
+ var domain = (options === null || options === void 0 ? void 0 : options.domain) || "";
30
31
  var sameSite = options === null || options === void 0 ? void 0 : options.sameSite;
31
32
  var secure = (options === null || options === void 0 ? void 0 : options.secure) || false;
32
- var cookie = "".concat(encodeURIComponent(this.getKey(key)), "=").concat(encodeURIComponent(value));
33
+ var encodedKey = encodeURIComponent(this.getKey(key));
34
+ // When writing a domain-wide cookie, expire any legacy host-only cookie
35
+ // on the current host so it doesn't shadow the domain-wide cookie in
36
+ // document.cookie reads. This only clears the cookie on the current host;
37
+ // host-only cookies on sibling hosts are not visible and cannot be cleared.
38
+ if (domain) {
39
+ document.cookie = "".concat(encodedKey, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(path, ";");
40
+ }
41
+ else {
42
+ // When writing a host-only cookie (no domain), expire any previously
43
+ // written apex-domain cookie so it doesn't shadow the new host cookie.
44
+ // This handles the transition from crossSubdomainCookies: true to false.
45
+ var apexDomain = getApexDomain();
46
+ if (apexDomain) {
47
+ document.cookie = "".concat(encodedKey, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(path, "; domain=.").concat(apexDomain);
48
+ }
49
+ }
50
+ var cookie = "".concat(encodedKey, "=").concat(encodeURIComponent(value));
33
51
  if (maxAge) {
34
52
  cookie += "; max-age=" + maxAge;
35
53
  }
@@ -55,7 +73,15 @@ var CookieStorage = /** @class */ (function (_super) {
55
73
  return match ? decodeURIComponent(match[1]) : null;
56
74
  };
57
75
  CookieStorage.prototype.remove = function (key) {
58
- document.cookie = "".concat(encodeURIComponent(this.getKey(key)), "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
76
+ var encodedKey = encodeURIComponent(this.getKey(key));
77
+ // Always expire host-only cookie
78
+ document.cookie = "".concat(encodedKey, "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
79
+ // Also expire apex-domain cookie if a valid apex domain exists,
80
+ // so that remove() works regardless of crossSubdomainCookies.
81
+ var domain = getApexDomain();
82
+ if (domain) {
83
+ document.cookie = "".concat(encodedKey, "=; path=/; domain=.").concat(domain, "; expires=Thu, 01 Jan 1970 00:00:00 GMT");
84
+ }
59
85
  };
60
86
  return CookieStorage;
61
87
  }(StorageBlueprint));
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns the domain attribute string for identity cookies.
3
+ * - false → "" (no domain attribute, host-only)
4
+ * - true → ".example.com" when a valid apex domain is detected,
5
+ * or "" on localhost / IP / single-label hosts
6
+ *
7
+ * @param crossSubdomain Whether cookies should be shared across subdomains.
8
+ */
9
+ export declare function getIdentityCookieDomain(crossSubdomain?: boolean): string;
10
+ //# sourceMappingURL=cookiePolicy.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Cookie domain policy — centralizes the decision of whether identity
3
+ * cookies should be host-scoped or apex-scoped.
4
+ *
5
+ * - true (default): domain set to .apexDomain → shared across subdomains
6
+ * - false: no domain attribute → cookie scoped to current host
7
+ */
8
+ import { getApexDomain } from "../utils/domain";
9
+ /**
10
+ * Returns the domain attribute string for identity cookies.
11
+ * - false → "" (no domain attribute, host-only)
12
+ * - true → ".example.com" when a valid apex domain is detected,
13
+ * or "" on localhost / IP / single-label hosts
14
+ *
15
+ * @param crossSubdomain Whether cookies should be shared across subdomains.
16
+ */
17
+ export function getIdentityCookieDomain(crossSubdomain) {
18
+ if (crossSubdomain === void 0) { crossSubdomain = true; }
19
+ if (!crossSubdomain)
20
+ return "";
21
+ var domain = getApexDomain();
22
+ return domain ? ".".concat(domain) : "";
23
+ }
24
+ //# sourceMappingURL=cookiePolicy.js.map
@@ -144,6 +144,18 @@ export interface WagmiOptions {
144
144
  export interface Options {
145
145
  provider?: EIP1193Provider;
146
146
  tracking?: boolean | TrackingOptions;
147
+ /**
148
+ * When `true`, identity cookies (anonymous ID, user ID) are set on the
149
+ * apex/root domain (e.g. `.example.com`), enabling cross-subdomain identity
150
+ * sharing between app.example.com and www.example.com.
151
+ *
152
+ * When `false`, cookies are scoped to the current host only.
153
+ *
154
+ * Session cookies (wallet detection, current URL) always remain host-scoped.
155
+ * Consent cookies are always apex-scoped independently for compliance.
156
+ * @default true
157
+ */
158
+ crossSubdomainCookies?: boolean;
147
159
  /**
148
160
  * Control wallet event autocapture
149
161
  * - `false`: Disable all wallet autocapture
@@ -65,7 +65,6 @@ export interface TransactionAPIEvent {
65
65
  transactionHash?: string;
66
66
  function_name?: string;
67
67
  function_args?: Record<string, unknown>;
68
- builder_codes?: string;
69
68
  }
70
69
  export interface SignatureAPIEvent {
71
70
  type: "signature";
@@ -46,15 +46,13 @@ export var getValidAddress = function (address) {
46
46
  * @returns true if the address is blocked, false otherwise
47
47
  */
48
48
  export var isBlockedAddress = function (address) {
49
- if (!address)
49
+ if (!address || typeof address !== 'string')
50
50
  return false;
51
- var validAddress = getValidAddress(address);
52
- if (!validAddress)
51
+ var normalized = address.trim().toLowerCase();
52
+ if (!normalized || !normalized.startsWith('0x') || normalized.length !== 42)
53
53
  return false;
54
- // Normalize to checksum format for comparison
55
- var checksumAddress = toChecksumAddress(validAddress);
56
54
  return BLOCKED_ADDRESSES.some(function (blockedAddr) {
57
- return toChecksumAddress(blockedAddr) === checksumAddress;
55
+ return blockedAddr.toLowerCase() === normalized;
58
56
  });
59
57
  };
60
58
  export var toChecksumAddress = function (address) {
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Domain utilities for cross-subdomain cookie sharing.
3
+ *
4
+ * Uses a cookie-probe approach: tries setting a test cookie on progressively
5
+ * shorter domain candidates until the browser accepts one. This is
6
+ * self-maintaining — no hardcoded public suffix lists to keep up to date.
7
+ * The browser itself is the authority on which domains accept cookies.
8
+ */
9
+ /**
10
+ * Extract the apex (registrable) domain for cookie sharing across subdomains.
11
+ *
12
+ * Walks up the hostname labels from shortest candidate to longest, probing
13
+ * with a test cookie. The shortest domain the browser accepts is the apex.
14
+ *
15
+ * Returns null for localhost, IP addresses, single-label hosts, SSR, or
16
+ * when no candidate domain accepts cookies (e.g. public suffix hosts like
17
+ * vercel.app or github.io).
18
+ *
19
+ * Results are cached for the lifetime of the page.
20
+ */
21
+ export declare function getApexDomain(): string | null;
22
+ /**
23
+ * Reset the cached apex domain. Exposed for testing only.
24
+ * @internal
25
+ */
26
+ export declare function _resetApexDomainCache(): void;
27
+ //# sourceMappingURL=domain.d.ts.map
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Domain utilities for cross-subdomain cookie sharing.
3
+ *
4
+ * Uses a cookie-probe approach: tries setting a test cookie on progressively
5
+ * shorter domain candidates until the browser accepts one. This is
6
+ * self-maintaining — no hardcoded public suffix lists to keep up to date.
7
+ * The browser itself is the authority on which domains accept cookies.
8
+ */
9
+ var TEST_COOKIE_NAME = '__formo_domain_probe';
10
+ /** Cached result so we only probe once per page load. */
11
+ var cachedApexDomain;
12
+ /**
13
+ * Try to set a test cookie on the given domain. Returns true if the browser
14
+ * accepted it (i.e. the cookie is readable back).
15
+ */
16
+ function canSetCookieOnDomain(domain) {
17
+ var cookieVal = 'probe';
18
+ document.cookie = "".concat(TEST_COOKIE_NAME, "=").concat(cookieVal, "; domain=.").concat(domain, "; path=/; max-age=10");
19
+ var accepted = document.cookie.indexOf("".concat(TEST_COOKIE_NAME, "=").concat(cookieVal)) !== -1;
20
+ // Clean up regardless of result
21
+ document.cookie = "".concat(TEST_COOKIE_NAME, "=; domain=.").concat(domain, "; path=/; max-age=0");
22
+ return accepted;
23
+ }
24
+ /**
25
+ * Extract the apex (registrable) domain for cookie sharing across subdomains.
26
+ *
27
+ * Walks up the hostname labels from shortest candidate to longest, probing
28
+ * with a test cookie. The shortest domain the browser accepts is the apex.
29
+ *
30
+ * Returns null for localhost, IP addresses, single-label hosts, SSR, or
31
+ * when no candidate domain accepts cookies (e.g. public suffix hosts like
32
+ * vercel.app or github.io).
33
+ *
34
+ * Results are cached for the lifetime of the page.
35
+ */
36
+ export function getApexDomain() {
37
+ if (typeof window === 'undefined')
38
+ return null;
39
+ if (cachedApexDomain !== undefined)
40
+ return cachedApexDomain;
41
+ var hostname = window.location.hostname;
42
+ if (hostname === 'localhost' || /^\d+\.\d+\.\d+\.\d+$/.test(hostname)) {
43
+ cachedApexDomain = null;
44
+ return null;
45
+ }
46
+ var parts = hostname.split('.');
47
+ if (parts.length < 2) {
48
+ cachedApexDomain = null;
49
+ return null;
50
+ }
51
+ // Walk from the shortest candidate (last 2 labels) to the full hostname.
52
+ // The shortest domain the browser accepts is the apex domain.
53
+ for (var i = 2; i <= parts.length; i++) {
54
+ var candidate = parts.slice(-i).join('.');
55
+ if (canSetCookieOnDomain(candidate)) {
56
+ cachedApexDomain = candidate;
57
+ return candidate;
58
+ }
59
+ }
60
+ cachedApexDomain = null;
61
+ return null;
62
+ }
63
+ /**
64
+ * Reset the cached apex domain. Exposed for testing only.
65
+ * @internal
66
+ */
67
+ export function _resetApexDomainCache() {
68
+ cachedApexDomain = undefined;
69
+ }
70
+ //# sourceMappingURL=domain.js.map
@@ -34,23 +34,35 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ import { sha256 } from 'ethereum-cryptography/sha256';
38
+ import { utf8ToBytes, bytesToHex } from 'ethereum-cryptography/utils';
37
39
  export function hash(input) {
38
40
  return __awaiter(this, void 0, void 0, function () {
39
- var hashBuffer, byteArray;
41
+ var bytes, hashBytes;
40
42
  return __generator(this, function (_a) {
41
- switch (_a.label) {
42
- case 0: return [4 /*yield*/, crypto.subtle.digest("SHA-256", new TextEncoder().encode(input))];
43
- case 1:
44
- hashBuffer = _a.sent();
45
- byteArray = new Uint8Array(hashBuffer);
46
- return [2 /*return*/, Array.from(byteArray)
47
- .map(function (byte) { return byte.toString(16).padStart(2, "0"); })
48
- .join("")];
49
- }
43
+ bytes = utf8ToBytes(input);
44
+ hashBytes = sha256(bytes);
45
+ return [2 /*return*/, bytesToHex(hashBytes)];
50
46
  });
51
47
  });
52
48
  }
53
49
  export function generateNativeUUID() {
54
- return crypto.randomUUID();
50
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
51
+ return crypto.randomUUID();
52
+ }
53
+ // Fallback using crypto.getRandomValues (available in insecure contexts)
54
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
55
+ var bytes = new Uint8Array(16);
56
+ crypto.getRandomValues(bytes);
57
+ bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
58
+ bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 1
59
+ var hex = Array.from(bytes).map(function (b) { return b.toString(16).padStart(2, '0'); }).join('');
60
+ return "".concat(hex.slice(0, 8), "-").concat(hex.slice(8, 12), "-").concat(hex.slice(12, 16), "-").concat(hex.slice(16, 20), "-").concat(hex.slice(20));
61
+ }
62
+ // Last resort: Math.random (not cryptographically secure, but functional)
63
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
64
+ var r = (Math.random() * 16) | 0;
65
+ return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
66
+ });
55
67
  }
56
68
  //# sourceMappingURL=generate.js.map
@@ -1,6 +1,5 @@
1
1
  export * from "./address";
2
2
  export * from "./base";
3
- export * from "./builderCode";
4
3
  export * from "./converter";
5
4
  export * from "./generate";
6
5
  export * from "./hash";
@@ -1,6 +1,5 @@
1
1
  export * from "./address";
2
2
  export * from "./base";
3
- export * from "./builderCode";
4
3
  export * from "./converter";
5
4
  export * from "./generate";
6
5
  export * from "./hash";
@@ -1,5 +1,9 @@
1
1
  var objectToString = Object.prototype.toString;
2
- var isError = function (value) { return objectToString.call(value) === "[object Error]"; };
2
+ var isError = function (value) {
3
+ var tag = objectToString.call(value);
4
+ return tag === "[object Error]" || tag === "[object DOMException]";
5
+ };
6
+ var errorNames = new Set(["TypeError", "TimeoutError", "NetworkError"]);
3
7
  var errorMessages = new Set([
4
8
  "network error", // Chrome
5
9
  "Failed to fetch", // Chrome
@@ -9,11 +13,12 @@ var errorMessages = new Set([
9
13
  "Network request failed", // `cross-fetch`
10
14
  "fetch failed", // Undici (Node.js)
11
15
  "terminated", // Undici (Node.js)
16
+ "The operation was aborted due to timeout", // AbortSignal.timeout()
12
17
  ]);
13
18
  export function isNetworkError(error) {
14
19
  var isValid = error &&
15
20
  isError(error) &&
16
- error.name === "TypeError" &&
21
+ errorNames.has(error.name) &&
17
22
  typeof error.message === "string";
18
23
  if (!isValid) {
19
24
  return false;
@@ -1,2 +1,2 @@
1
- export declare const version = "1.28.1";
1
+ export declare const version = "1.28.3";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,4 +1,4 @@
1
1
  // This file is auto-generated by scripts/update-version.js during npm version
2
2
  // Do not edit manually - it will be overwritten
3
- export var version = '1.28.1';
3
+ export var version = '1.28.3';
4
4
  //# sourceMappingURL=version.js.map
@@ -55,7 +55,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
55
55
  import { SignatureStatus, TransactionStatus } from "../types/events";
56
56
  import { logger } from "../logger";
57
57
  import { encodeWriteContractData, concatCalldataWithSuffix, extractFunctionArgs, buildSafeFunctionArgs, } from "./utils";
58
- import { extractBuilderCodes } from "../utils/builderCode";
59
58
  /**
60
59
  * Built-in transaction fields that could collide with function args.
61
60
  * Defined at module level to avoid recreating on every method call.
@@ -70,7 +69,6 @@ var RESERVED_FIELDS = new Set([
70
69
  "transactionHash",
71
70
  "function_name",
72
71
  "function_args",
73
- "builder_codes",
74
72
  ]);
75
73
  /**
76
74
  * Clean up old entries from a Set to prevent memory leaks.
@@ -385,7 +383,7 @@ var WagmiEventHandler = /** @class */ (function () {
385
383
  chainId: chainId,
386
384
  blockNumber: (_a = receipt === null || receipt === void 0 ? void 0 : receipt.blockNumber) === null || _a === void 0 ? void 0 : _a.toString(),
387
385
  });
388
- this.formo.transaction(__assign(__assign(__assign(__assign(__assign(__assign({ status: txStatus, chainId: chainId || 0, address: address, transactionHash: transactionHash }, ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.data) && { data: pendingTx.data })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.to) && { to: pendingTx.to })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.value) && { value: pendingTx.value })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_name) && { function_name: pendingTx.function_name })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_args) && { function_args: pendingTx.function_args })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.builder_codes) && { builder_codes: pendingTx.builder_codes })),
386
+ this.formo.transaction(__assign(__assign(__assign(__assign(__assign({ status: txStatus, chainId: chainId || 0, address: address, transactionHash: transactionHash }, ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.data) && { data: pendingTx.data })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.to) && { to: pendingTx.to })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.value) && { value: pendingTx.value })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_name) && { function_name: pendingTx.function_name })), ((pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.function_args) && { function_args: pendingTx.function_args })),
389
387
  // Spread function args as additional properties (only colliding keys are prefixed)
390
388
  pendingTx === null || pendingTx === void 0 ? void 0 : pendingTx.safeFunctionArgs);
391
389
  // Clean up the pending transaction after confirmation
@@ -548,7 +546,7 @@ var WagmiEventHandler = /** @class */ (function () {
548
546
  // Encode the function data synchronously if viem is available
549
547
  var encodedData = encodeWriteContractData(abi, fnName, args);
550
548
  if (encodedData) {
551
- // Include dataSuffix (ERC-8021 builder code) so extractBuilderCodes sees full calldata
549
+ // Include dataSuffix (e.g. ERC-8021 builder code) so full calldata is sent to server
552
550
  data = concatCalldataWithSuffix(encodedData, dataSuffix);
553
551
  logger.debug("WagmiEventHandler: Encoded writeContract data", data.substring(0, 10));
554
552
  }
@@ -560,9 +558,14 @@ var WagmiEventHandler = /** @class */ (function () {
560
558
  data = variables.data;
561
559
  to = variables.to;
562
560
  }
563
- // Extract builder codes from transaction data (ERC-8021)
564
- var builder_codes = extractBuilderCodes(data);
565
- logger.info("WagmiEventHandler: Tracking transaction event", __assign({ status: status_2, mutationType: mutationType, address: userAddress, chainId: chainId, transactionHash: transactionHash, function_name: function_name }, (builder_codes && { builder_codes: builder_codes })));
561
+ logger.info("WagmiEventHandler: Tracking transaction event", {
562
+ status: status_2,
563
+ mutationType: mutationType,
564
+ address: userAddress,
565
+ chainId: chainId,
566
+ transactionHash: transactionHash,
567
+ function_name: function_name,
568
+ });
566
569
  // Build safeFunctionArgs with collision handling and struct flattening
567
570
  var safeFunctionArgs = buildSafeFunctionArgs(function_args, RESERVED_FIELDS);
568
571
  // Store transaction details for BROADCASTED status to use in CONFIRMED/REVERTED
@@ -570,7 +573,7 @@ var WagmiEventHandler = /** @class */ (function () {
570
573
  // Include the sender address to handle wallet switches between broadcast and confirmation
571
574
  if (status_2 === TransactionStatus.BROADCASTED && transactionHash) {
572
575
  var normalizedHash = transactionHash.toLowerCase();
573
- var txDetails = __assign(__assign(__assign(__assign(__assign(__assign(__assign({ address: userAddress }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })), (builder_codes && { builder_codes: builder_codes })), (safeFunctionArgs && { safeFunctionArgs: safeFunctionArgs }));
576
+ var txDetails = __assign(__assign(__assign(__assign(__assign(__assign({ address: userAddress }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })), (safeFunctionArgs && { safeFunctionArgs: safeFunctionArgs }));
574
577
  this.pendingTransactions.set(normalizedHash, txDetails);
575
578
  logger.debug("WagmiEventHandler: Stored pending transaction for confirmation", {
576
579
  transactionHash: normalizedHash,
@@ -584,7 +587,7 @@ var WagmiEventHandler = /** @class */ (function () {
584
587
  }
585
588
  }
586
589
  }
587
- this.formo.transaction(__assign(__assign(__assign(__assign(__assign(__assign(__assign({ status: status_2, chainId: chainId || 0, address: userAddress }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (transactionHash && { transactionHash: transactionHash })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })), (builder_codes && { builder_codes: builder_codes })),
590
+ this.formo.transaction(__assign(__assign(__assign(__assign(__assign(__assign({ status: status_2, chainId: chainId || 0, address: userAddress }, (data && { data: data })), (to && { to: to })), (value && { value: value })), (transactionHash && { transactionHash: transactionHash })), (function_name && { function_name: function_name })), (function_args && { function_args: function_args })),
588
591
  // Spread function args as additional properties (only colliding keys are prefixed)
589
592
  safeFunctionArgs);
590
593
  }