@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
@@ -118,6 +118,11 @@ var SolanaAdapter = /** @class */ (function () {
118
118
  * Key: transaction signature, Value: transaction details
119
119
  */
120
120
  this.pendingTransactions = new Map();
121
+ /**
122
+ * Per-adapter original methods stored in a WeakMap to prevent routing
123
+ * to the wrong wallet after switching adapters.
124
+ */
125
+ this.adapterOriginals = new WeakMap();
121
126
  /**
122
127
  * Track active polling timeout IDs for cleanup
123
128
  */
@@ -147,21 +152,22 @@ var SolanaAdapter = /** @class */ (function () {
147
152
  SolanaAdapter.prototype.restoreOriginalMethods = function () {
148
153
  // Restore adapter methods
149
154
  if (this.wrappedAdapter) {
150
- if (this.originalAdapterSendTransaction) {
151
- this.wrappedAdapter.sendTransaction = this.originalAdapterSendTransaction;
152
- }
153
- if (this.originalAdapterSignMessage) {
154
- this.wrappedAdapter.signMessage = this.originalAdapterSignMessage;
155
- }
156
- if (this.originalAdapterSignTransaction) {
157
- this.wrappedAdapter.signTransaction = this.originalAdapterSignTransaction;
155
+ var originals = this.adapterOriginals.get(this.wrappedAdapter);
156
+ if (originals) {
157
+ if (originals.sendTransaction) {
158
+ this.wrappedAdapter.sendTransaction = originals.sendTransaction;
159
+ }
160
+ if (originals.signMessage) {
161
+ this.wrappedAdapter.signMessage = originals.signMessage;
162
+ }
163
+ if (originals.signTransaction) {
164
+ this.wrappedAdapter.signTransaction = originals.signTransaction;
165
+ }
166
+ this.adapterOriginals.delete(this.wrappedAdapter);
158
167
  }
159
168
  this.wrappedAdapter = undefined;
160
169
  }
161
- // Clear original and bound wrapper references
162
- this.originalAdapterSendTransaction = undefined;
163
- this.originalAdapterSignMessage = undefined;
164
- this.originalAdapterSignTransaction = undefined;
170
+ // Clear bound wrapper references
165
171
  this.boundWrappedSendTransaction = undefined;
166
172
  this.boundWrappedSignMessage = undefined;
167
173
  this.boundWrappedSignTransaction = undefined;
@@ -390,24 +396,26 @@ var SolanaAdapter = /** @class */ (function () {
390
396
  }
391
397
  // Store reference to adapter for cleanup
392
398
  this.wrappedAdapter = adapter;
399
+ var originals = {};
393
400
  // Wrap sendTransaction
394
401
  if (adapter.sendTransaction) {
395
- this.originalAdapterSendTransaction = adapter.sendTransaction.bind(adapter);
402
+ originals.sendTransaction = adapter.sendTransaction.bind(adapter);
396
403
  this.boundWrappedSendTransaction = this.wrappedSendTransaction.bind(this);
397
404
  adapter.sendTransaction = this.boundWrappedSendTransaction;
398
405
  }
399
406
  // Wrap signMessage
400
407
  if (adapter.signMessage) {
401
- this.originalAdapterSignMessage = adapter.signMessage.bind(adapter);
408
+ originals.signMessage = adapter.signMessage.bind(adapter);
402
409
  this.boundWrappedSignMessage = this.wrappedSignMessage.bind(this);
403
410
  adapter.signMessage = this.boundWrappedSignMessage;
404
411
  }
405
412
  // Wrap signTransaction
406
413
  if (adapter.signTransaction) {
407
- this.originalAdapterSignTransaction = adapter.signTransaction.bind(adapter);
414
+ originals.signTransaction = adapter.signTransaction.bind(adapter);
408
415
  this.boundWrappedSignTransaction = this.wrappedSignTransaction.bind(this);
409
416
  adapter.signTransaction = this.boundWrappedSignTransaction;
410
417
  }
418
+ this.adapterOriginals.set(adapter, originals);
411
419
  };
412
420
  /**
413
421
  * Re-wrap methods that were overwritten by external code.
@@ -419,9 +427,10 @@ var SolanaAdapter = /** @class */ (function () {
419
427
  */
420
428
  SolanaAdapter.prototype.rewrapOverwrittenMethods = function (adapter) {
421
429
  var rewrapped = false;
430
+ var originals = this.adapterOriginals.get(adapter) || {};
422
431
  // signMessage
423
432
  if (adapter.signMessage && adapter.signMessage !== this.boundWrappedSignMessage) {
424
- this.originalAdapterSignMessage = adapter.signMessage.bind(adapter);
433
+ originals.signMessage = adapter.signMessage.bind(adapter);
425
434
  if (!this.boundWrappedSignMessage) {
426
435
  this.boundWrappedSignMessage = this.wrappedSignMessage.bind(this);
427
436
  }
@@ -429,11 +438,11 @@ var SolanaAdapter = /** @class */ (function () {
429
438
  rewrapped = true;
430
439
  }
431
440
  else if (!adapter.signMessage && this.boundWrappedSignMessage) {
432
- this.originalAdapterSignMessage = undefined;
441
+ originals.signMessage = undefined;
433
442
  }
434
443
  // signTransaction
435
444
  if (adapter.signTransaction && adapter.signTransaction !== this.boundWrappedSignTransaction) {
436
- this.originalAdapterSignTransaction = adapter.signTransaction.bind(adapter);
445
+ originals.signTransaction = adapter.signTransaction.bind(adapter);
437
446
  if (!this.boundWrappedSignTransaction) {
438
447
  this.boundWrappedSignTransaction = this.wrappedSignTransaction.bind(this);
439
448
  }
@@ -441,17 +450,18 @@ var SolanaAdapter = /** @class */ (function () {
441
450
  rewrapped = true;
442
451
  }
443
452
  else if (!adapter.signTransaction && this.boundWrappedSignTransaction) {
444
- this.originalAdapterSignTransaction = undefined;
453
+ originals.signTransaction = undefined;
445
454
  }
446
455
  // sendTransaction — unlikely to be overwritten but check for completeness
447
456
  if (adapter.sendTransaction && adapter.sendTransaction !== this.boundWrappedSendTransaction) {
448
- this.originalAdapterSendTransaction = adapter.sendTransaction.bind(adapter);
457
+ originals.sendTransaction = adapter.sendTransaction.bind(adapter);
449
458
  if (!this.boundWrappedSendTransaction) {
450
459
  this.boundWrappedSendTransaction = this.wrappedSendTransaction.bind(this);
451
460
  }
452
461
  adapter.sendTransaction = this.boundWrappedSendTransaction;
453
462
  rewrapped = true;
454
463
  }
464
+ this.adapterOriginals.set(adapter, originals);
455
465
  if (rewrapped) {
456
466
  logger_1.logger.debug("SolanaAdapter: Re-wrapped overwritten adapter methods");
457
467
  }
@@ -461,12 +471,13 @@ var SolanaAdapter = /** @class */ (function () {
461
471
  */
462
472
  SolanaAdapter.prototype.wrappedSendTransaction = function (transaction, connection, options) {
463
473
  return __awaiter(this, void 0, void 0, function () {
464
- var chainId, address, signature, error_1;
474
+ var originals, chainId, address, signature, error_1;
465
475
  return __generator(this, function (_a) {
466
476
  switch (_a.label) {
467
477
  case 0:
468
478
  this.checkAndRebindContextAdapter();
469
- if (!this.originalAdapterSendTransaction) {
479
+ originals = this.wrappedAdapter ? this.adapterOriginals.get(this.wrappedAdapter) : undefined;
480
+ if (!(originals === null || originals === void 0 ? void 0 : originals.sendTransaction)) {
470
481
  throw new Error("sendTransaction not available");
471
482
  }
472
483
  chainId = this.chainId;
@@ -475,7 +486,7 @@ var SolanaAdapter = /** @class */ (function () {
475
486
  _a.label = 1;
476
487
  case 1:
477
488
  _a.trys.push([1, 3, , 4]);
478
- return [4 /*yield*/, this.originalAdapterSendTransaction(transaction, connection, options)];
489
+ return [4 /*yield*/, originals.sendTransaction(transaction, connection, options)];
479
490
  case 2:
480
491
  signature = _a.sent();
481
492
  this.emitTransactionEvent(events_1.TransactionStatus.BROADCASTED, address, chainId, signature);
@@ -501,12 +512,13 @@ var SolanaAdapter = /** @class */ (function () {
501
512
  */
502
513
  SolanaAdapter.prototype.wrappedSignMessage = function (message) {
503
514
  return __awaiter(this, void 0, void 0, function () {
504
- var chainId, address, messageString, signature, signatureHex, error_2;
515
+ var originals, chainId, address, messageString, signature, signatureHex, error_2;
505
516
  return __generator(this, function (_a) {
506
517
  switch (_a.label) {
507
518
  case 0:
508
519
  this.checkAndRebindContextAdapter();
509
- if (!this.originalAdapterSignMessage) {
520
+ originals = this.wrappedAdapter ? this.adapterOriginals.get(this.wrappedAdapter) : undefined;
521
+ if (!(originals === null || originals === void 0 ? void 0 : originals.signMessage)) {
510
522
  throw new Error("signMessage not available");
511
523
  }
512
524
  chainId = this.chainId;
@@ -516,7 +528,7 @@ var SolanaAdapter = /** @class */ (function () {
516
528
  _a.label = 1;
517
529
  case 1:
518
530
  _a.trys.push([1, 3, , 4]);
519
- return [4 /*yield*/, this.originalAdapterSignMessage(message)];
531
+ return [4 /*yield*/, originals.signMessage(message)];
520
532
  case 2:
521
533
  signature = _a.sent();
522
534
  signatureHex = uint8ArrayToHex(signature);
@@ -536,12 +548,13 @@ var SolanaAdapter = /** @class */ (function () {
536
548
  */
537
549
  SolanaAdapter.prototype.wrappedSignTransaction = function (transaction) {
538
550
  return __awaiter(this, void 0, void 0, function () {
539
- var chainId, address, message, signedTx, error_3;
551
+ var originals, chainId, address, message, signedTx, error_3;
540
552
  return __generator(this, function (_a) {
541
553
  switch (_a.label) {
542
554
  case 0:
543
555
  this.checkAndRebindContextAdapter();
544
- if (!this.originalAdapterSignTransaction) {
556
+ originals = this.wrappedAdapter ? this.adapterOriginals.get(this.wrappedAdapter) : undefined;
557
+ if (!(originals === null || originals === void 0 ? void 0 : originals.signTransaction)) {
545
558
  throw new Error("signTransaction not available");
546
559
  }
547
560
  chainId = this.chainId;
@@ -551,7 +564,7 @@ var SolanaAdapter = /** @class */ (function () {
551
564
  _a.label = 1;
552
565
  case 1:
553
566
  _a.trys.push([1, 3, , 4]);
554
- return [4 /*yield*/, this.originalAdapterSignTransaction(transaction)];
567
+ return [4 /*yield*/, originals.signTransaction(transaction)];
555
568
  case 2:
556
569
  signedTx = _a.sent();
557
570
  this.emitSignatureEvent(events_1.SignatureStatus.CONFIRMED, address, chainId, message);
@@ -23,11 +23,19 @@ var StorageManager = /** @class */ (function () {
23
23
  StorageManager.prototype.getStorage = function (type) {
24
24
  if (!this.storages.has(type)) {
25
25
  var storage = this.createStorage(type);
26
+ var currentType = type;
26
27
  // If storage is not available, try next
27
28
  while (!storage.isAvailable()) {
28
- var index = TYPES.indexOf(type);
29
- logger_1.logger.warn("Storage ".concat(type, " is not available, trying ").concat(TYPES[index + 1]));
30
- storage = this.createStorage(TYPES[index + 1]);
29
+ var index = TYPES.indexOf(currentType);
30
+ if (index === -1 || index + 1 >= TYPES.length) {
31
+ // No more fallbacks, use memory storage as last resort
32
+ storage = this.createStorage("memoryStorage");
33
+ break;
34
+ }
35
+ var prevType = currentType;
36
+ currentType = TYPES[index + 1];
37
+ logger_1.logger.warn("Storage ".concat(prevType, " is not available, trying ").concat(currentType));
38
+ storage = this.createStorage(currentType);
31
39
  }
32
40
  // Add to cache
33
41
  this.storages.set(type, storage);
@@ -19,6 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  var blueprint_1 = __importDefault(require("./blueprint"));
22
+ var domain_1 = require("../../utils/domain");
22
23
  var CookieStorage = /** @class */ (function (_super) {
23
24
  __extends(CookieStorage, _super);
24
25
  function CookieStorage() {
@@ -31,10 +32,27 @@ var CookieStorage = /** @class */ (function (_super) {
31
32
  var expires = options === null || options === void 0 ? void 0 : options.expires;
32
33
  var maxAge = options === null || options === void 0 ? void 0 : options.maxAge;
33
34
  var path = (options === null || options === void 0 ? void 0 : options.path) || "/";
34
- var domain = options === null || options === void 0 ? void 0 : options.domain;
35
+ var domain = (options === null || options === void 0 ? void 0 : options.domain) || "";
35
36
  var sameSite = options === null || options === void 0 ? void 0 : options.sameSite;
36
37
  var secure = (options === null || options === void 0 ? void 0 : options.secure) || false;
37
- var cookie = "".concat(encodeURIComponent(this.getKey(key)), "=").concat(encodeURIComponent(value));
38
+ var encodedKey = encodeURIComponent(this.getKey(key));
39
+ // When writing a domain-wide cookie, expire any legacy host-only cookie
40
+ // on the current host so it doesn't shadow the domain-wide cookie in
41
+ // document.cookie reads. This only clears the cookie on the current host;
42
+ // host-only cookies on sibling hosts are not visible and cannot be cleared.
43
+ if (domain) {
44
+ document.cookie = "".concat(encodedKey, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(path, ";");
45
+ }
46
+ else {
47
+ // When writing a host-only cookie (no domain), expire any previously
48
+ // written apex-domain cookie so it doesn't shadow the new host cookie.
49
+ // This handles the transition from crossSubdomainCookies: true to false.
50
+ var apexDomain = (0, domain_1.getApexDomain)();
51
+ if (apexDomain) {
52
+ document.cookie = "".concat(encodedKey, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=").concat(path, "; domain=.").concat(apexDomain);
53
+ }
54
+ }
55
+ var cookie = "".concat(encodedKey, "=").concat(encodeURIComponent(value));
38
56
  if (maxAge) {
39
57
  cookie += "; max-age=" + maxAge;
40
58
  }
@@ -60,7 +78,15 @@ var CookieStorage = /** @class */ (function (_super) {
60
78
  return match ? decodeURIComponent(match[1]) : null;
61
79
  };
62
80
  CookieStorage.prototype.remove = function (key) {
63
- document.cookie = "".concat(encodeURIComponent(this.getKey(key)), "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
81
+ var encodedKey = encodeURIComponent(this.getKey(key));
82
+ // Always expire host-only cookie
83
+ document.cookie = "".concat(encodedKey, "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
84
+ // Also expire apex-domain cookie if a valid apex domain exists,
85
+ // so that remove() works regardless of crossSubdomainCookies.
86
+ var domain = (0, domain_1.getApexDomain)();
87
+ if (domain) {
88
+ document.cookie = "".concat(encodedKey, "=; path=/; domain=.").concat(domain, "; expires=Thu, 01 Jan 1970 00:00:00 GMT");
89
+ }
64
90
  };
65
91
  return CookieStorage;
66
92
  }(blueprint_1.default));
@@ -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,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIdentityCookieDomain = getIdentityCookieDomain;
4
+ /**
5
+ * Cookie domain policy — centralizes the decision of whether identity
6
+ * cookies should be host-scoped or apex-scoped.
7
+ *
8
+ * - true (default): domain set to .apexDomain → shared across subdomains
9
+ * - false: no domain attribute → cookie scoped to current host
10
+ */
11
+ var domain_1 = require("../utils/domain");
12
+ /**
13
+ * Returns the domain attribute string for identity cookies.
14
+ * - false → "" (no domain attribute, host-only)
15
+ * - true → ".example.com" when a valid apex domain is detected,
16
+ * or "" on localhost / IP / single-label hosts
17
+ *
18
+ * @param crossSubdomain Whether cookies should be shared across subdomains.
19
+ */
20
+ function getIdentityCookieDomain(crossSubdomain) {
21
+ if (crossSubdomain === void 0) { crossSubdomain = true; }
22
+ if (!crossSubdomain)
23
+ return "";
24
+ var domain = (0, domain_1.getApexDomain)();
25
+ return domain ? ".".concat(domain) : "";
26
+ }
27
+ //# 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";
@@ -51,15 +51,13 @@ exports.getValidAddress = getValidAddress;
51
51
  * @returns true if the address is blocked, false otherwise
52
52
  */
53
53
  var isBlockedAddress = function (address) {
54
- if (!address)
54
+ if (!address || typeof address !== 'string')
55
55
  return false;
56
- var validAddress = (0, exports.getValidAddress)(address);
57
- if (!validAddress)
56
+ var normalized = address.trim().toLowerCase();
57
+ if (!normalized || !normalized.startsWith('0x') || normalized.length !== 42)
58
58
  return false;
59
- // Normalize to checksum format for comparison
60
- var checksumAddress = (0, exports.toChecksumAddress)(validAddress);
61
59
  return constants_1.BLOCKED_ADDRESSES.some(function (blockedAddr) {
62
- return (0, exports.toChecksumAddress)(blockedAddr) === checksumAddress;
60
+ return blockedAddr.toLowerCase() === normalized;
63
61
  });
64
62
  };
65
63
  exports.isBlockedAddress = isBlockedAddress;
@@ -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,74 @@
1
+ "use strict";
2
+ /**
3
+ * Domain utilities for cross-subdomain cookie sharing.
4
+ *
5
+ * Uses a cookie-probe approach: tries setting a test cookie on progressively
6
+ * shorter domain candidates until the browser accepts one. This is
7
+ * self-maintaining — no hardcoded public suffix lists to keep up to date.
8
+ * The browser itself is the authority on which domains accept cookies.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.getApexDomain = getApexDomain;
12
+ exports._resetApexDomainCache = _resetApexDomainCache;
13
+ var TEST_COOKIE_NAME = '__formo_domain_probe';
14
+ /** Cached result so we only probe once per page load. */
15
+ var cachedApexDomain;
16
+ /**
17
+ * Try to set a test cookie on the given domain. Returns true if the browser
18
+ * accepted it (i.e. the cookie is readable back).
19
+ */
20
+ function canSetCookieOnDomain(domain) {
21
+ var cookieVal = 'probe';
22
+ document.cookie = "".concat(TEST_COOKIE_NAME, "=").concat(cookieVal, "; domain=.").concat(domain, "; path=/; max-age=10");
23
+ var accepted = document.cookie.indexOf("".concat(TEST_COOKIE_NAME, "=").concat(cookieVal)) !== -1;
24
+ // Clean up regardless of result
25
+ document.cookie = "".concat(TEST_COOKIE_NAME, "=; domain=.").concat(domain, "; path=/; max-age=0");
26
+ return accepted;
27
+ }
28
+ /**
29
+ * Extract the apex (registrable) domain for cookie sharing across subdomains.
30
+ *
31
+ * Walks up the hostname labels from shortest candidate to longest, probing
32
+ * with a test cookie. The shortest domain the browser accepts is the apex.
33
+ *
34
+ * Returns null for localhost, IP addresses, single-label hosts, SSR, or
35
+ * when no candidate domain accepts cookies (e.g. public suffix hosts like
36
+ * vercel.app or github.io).
37
+ *
38
+ * Results are cached for the lifetime of the page.
39
+ */
40
+ function getApexDomain() {
41
+ if (typeof window === 'undefined')
42
+ return null;
43
+ if (cachedApexDomain !== undefined)
44
+ return cachedApexDomain;
45
+ var hostname = window.location.hostname;
46
+ if (hostname === 'localhost' || /^\d+\.\d+\.\d+\.\d+$/.test(hostname)) {
47
+ cachedApexDomain = null;
48
+ return null;
49
+ }
50
+ var parts = hostname.split('.');
51
+ if (parts.length < 2) {
52
+ cachedApexDomain = null;
53
+ return null;
54
+ }
55
+ // Walk from the shortest candidate (last 2 labels) to the full hostname.
56
+ // The shortest domain the browser accepts is the apex domain.
57
+ for (var i = 2; i <= parts.length; i++) {
58
+ var candidate = parts.slice(-i).join('.');
59
+ if (canSetCookieOnDomain(candidate)) {
60
+ cachedApexDomain = candidate;
61
+ return candidate;
62
+ }
63
+ }
64
+ cachedApexDomain = null;
65
+ return null;
66
+ }
67
+ /**
68
+ * Reset the cached apex domain. Exposed for testing only.
69
+ * @internal
70
+ */
71
+ function _resetApexDomainCache() {
72
+ cachedApexDomain = undefined;
73
+ }
74
+ //# sourceMappingURL=domain.js.map
@@ -38,23 +38,35 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.hash = hash;
40
40
  exports.generateNativeUUID = generateNativeUUID;
41
+ var sha256_1 = require("ethereum-cryptography/sha256");
42
+ var utils_1 = require("ethereum-cryptography/utils");
41
43
  function hash(input) {
42
44
  return __awaiter(this, void 0, void 0, function () {
43
- var hashBuffer, byteArray;
45
+ var bytes, hashBytes;
44
46
  return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0: return [4 /*yield*/, crypto.subtle.digest("SHA-256", new TextEncoder().encode(input))];
47
- case 1:
48
- hashBuffer = _a.sent();
49
- byteArray = new Uint8Array(hashBuffer);
50
- return [2 /*return*/, Array.from(byteArray)
51
- .map(function (byte) { return byte.toString(16).padStart(2, "0"); })
52
- .join("")];
53
- }
47
+ bytes = (0, utils_1.utf8ToBytes)(input);
48
+ hashBytes = (0, sha256_1.sha256)(bytes);
49
+ return [2 /*return*/, (0, utils_1.bytesToHex)(hashBytes)];
54
50
  });
55
51
  });
56
52
  }
57
53
  function generateNativeUUID() {
58
- return crypto.randomUUID();
54
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
55
+ return crypto.randomUUID();
56
+ }
57
+ // Fallback using crypto.getRandomValues (available in insecure contexts)
58
+ if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
59
+ var bytes = new Uint8Array(16);
60
+ crypto.getRandomValues(bytes);
61
+ bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
62
+ bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 1
63
+ var hex = Array.from(bytes).map(function (b) { return b.toString(16).padStart(2, '0'); }).join('');
64
+ 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));
65
+ }
66
+ // Last resort: Math.random (not cryptographically secure, but functional)
67
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
68
+ var r = (Math.random() * 16) | 0;
69
+ return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
70
+ });
59
71
  }
60
72
  //# 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";
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./address"), exports);
18
18
  __exportStar(require("./base"), exports);
19
- __exportStar(require("./builderCode"), exports);
20
19
  __exportStar(require("./converter"), exports);
21
20
  __exportStar(require("./generate"), exports);
22
21
  __exportStar(require("./hash"), exports);
@@ -2,7 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNetworkError = isNetworkError;
4
4
  var objectToString = Object.prototype.toString;
5
- var isError = function (value) { return objectToString.call(value) === "[object Error]"; };
5
+ var isError = function (value) {
6
+ var tag = objectToString.call(value);
7
+ return tag === "[object Error]" || tag === "[object DOMException]";
8
+ };
9
+ var errorNames = new Set(["TypeError", "TimeoutError", "NetworkError"]);
6
10
  var errorMessages = new Set([
7
11
  "network error", // Chrome
8
12
  "Failed to fetch", // Chrome
@@ -12,11 +16,12 @@ var errorMessages = new Set([
12
16
  "Network request failed", // `cross-fetch`
13
17
  "fetch failed", // Undici (Node.js)
14
18
  "terminated", // Undici (Node.js)
19
+ "The operation was aborted due to timeout", // AbortSignal.timeout()
15
20
  ]);
16
21
  function isNetworkError(error) {
17
22
  var isValid = error &&
18
23
  isError(error) &&
19
- error.name === "TypeError" &&
24
+ errorNames.has(error.name) &&
20
25
  typeof error.message === "string";
21
26
  if (!isValid) {
22
27
  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
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // This file is auto-generated by scripts/update-version.js during npm version
5
5
  // Do not edit manually - it will be overwritten
6
- exports.version = '1.28.1';
6
+ exports.version = '1.28.3';
7
7
  //# sourceMappingURL=version.js.map