@cross-deck/web 1.5.7 → 1.6.2

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.
package/dist/vue.cjs CHANGED
@@ -92,7 +92,7 @@ function typeMapForStatus(status) {
92
92
  }
93
93
 
94
94
  // src/_version.ts
95
- var SDK_VERSION = "1.5.7";
95
+ var SDK_VERSION = "1.6.2";
96
96
  var SDK_NAME = "@cross-deck/web";
97
97
 
98
98
  // src/http.ts
@@ -1441,6 +1441,8 @@ var DEFAULT_AUTO_TRACK = {
1441
1441
  errors: true
1442
1442
  };
1443
1443
  var SESSION_RESUME_THRESHOLD_MS = 30 * 60 * 1e3;
1444
+ var SESSION_STORAGE_KEY = "crossdeck:session";
1445
+ var ACTIVITY_PERSIST_THROTTLE_MS = 5e3;
1444
1446
  var EMPTY_ACQUISITION = {
1445
1447
  utm_source: "",
1446
1448
  utm_medium: "",
@@ -1456,11 +1458,13 @@ var EMPTY_ACQUISITION = {
1456
1458
  twclid: ""
1457
1459
  };
1458
1460
  var AutoTracker = class {
1459
- constructor(cfg, track) {
1461
+ constructor(cfg, track, opts) {
1460
1462
  this.cfg = cfg;
1461
1463
  this.track = track;
1462
1464
  this.session = null;
1463
1465
  this.cleanups = [];
1466
+ /** Last time we flushed lastActivityAt to storage (throttle gate). */
1467
+ this.lastPersistAt = 0;
1464
1468
  /**
1465
1469
  * Stable per-page-view identifier. Minted at every `page.viewed`
1466
1470
  * emission and attached to every subsequent event until the next
@@ -1472,6 +1476,8 @@ var AutoTracker = class {
1472
1476
  * install if `autoTrack.pageViews !== false`).
1473
1477
  */
1474
1478
  this.pageviewId = null;
1479
+ this.storage = opts?.storage ?? null;
1480
+ this.sessionKey = opts?.storageKey ?? SESSION_STORAGE_KEY;
1475
1481
  }
1476
1482
  install() {
1477
1483
  if (!isBrowserSafe()) return;
@@ -1490,6 +1496,7 @@ var AutoTracker = class {
1490
1496
  if (this.session && !this.session.endedSent) {
1491
1497
  this.emitSessionEnd();
1492
1498
  }
1499
+ this.clearStoredSession();
1493
1500
  this.session = null;
1494
1501
  }
1495
1502
  /** Exposed for tests + consumers that want to reset the session manually. */
@@ -1497,8 +1504,31 @@ var AutoTracker = class {
1497
1504
  if (this.session && !this.session.endedSent) this.emitSessionEnd();
1498
1505
  this.pageviewId = null;
1499
1506
  this.session = this.startNewSession();
1507
+ this.persistSession();
1500
1508
  this.emitSessionStart();
1501
1509
  }
1510
+ /**
1511
+ * Keep the rolling session window alive. Called by the host on EVERY
1512
+ * tracked event (auto or custom) so any activity — not just the
1513
+ * pageviews/clicks AutoTracker emits itself — pushes the 30-min idle
1514
+ * boundary forward. In-memory time is updated exactly; the storage
1515
+ * flush is throttled (pagehide forces a final flush).
1516
+ */
1517
+ markActivity() {
1518
+ if (!this.session) return;
1519
+ const now = Date.now();
1520
+ if (now - this.session.lastActivityAt >= SESSION_RESUME_THRESHOLD_MS) {
1521
+ this.pageviewId = null;
1522
+ this.session = this.startNewSession();
1523
+ this.persistSession();
1524
+ this.emitSessionStart();
1525
+ return;
1526
+ }
1527
+ this.session.lastActivityAt = now;
1528
+ if (now - this.lastPersistAt >= ACTIVITY_PERSIST_THROTTLE_MS) {
1529
+ this.persistSession();
1530
+ }
1531
+ }
1502
1532
  /** Exposed for inspection/tests — returns the current sessionId (or null if not in a session). */
1503
1533
  get currentSessionId() {
1504
1534
  return this.session?.sessionId ?? null;
@@ -1521,26 +1551,42 @@ var AutoTracker = class {
1521
1551
  }
1522
1552
  // ---------- sessions ----------
1523
1553
  installSessionTracking() {
1524
- this.session = this.startNewSession();
1525
- this.emitSessionStart();
1554
+ const now = Date.now();
1555
+ const stored = this.readStoredSession();
1556
+ if (stored && now - stored.lastActivityAt < SESSION_RESUME_THRESHOLD_MS) {
1557
+ this.session = {
1558
+ sessionId: stored.id,
1559
+ startedAt: stored.startedAt,
1560
+ lastActivityAt: now,
1561
+ hiddenAt: null,
1562
+ endedSent: false,
1563
+ acquisition: stored.acquisition
1564
+ };
1565
+ this.persistSession();
1566
+ } else {
1567
+ this.session = this.startNewSession();
1568
+ this.persistSession();
1569
+ this.emitSessionStart();
1570
+ }
1526
1571
  const onVisChange = () => {
1527
1572
  if (!this.session) return;
1528
1573
  const doc2 = globalThis.document;
1529
1574
  if (doc2.visibilityState === "hidden") {
1530
1575
  this.session.hiddenAt = Date.now();
1576
+ this.persistSession();
1531
1577
  } else if (doc2.visibilityState === "visible") {
1532
- const hiddenFor = this.session.hiddenAt ? Date.now() - this.session.hiddenAt : 0;
1533
- if (hiddenFor >= SESSION_RESUME_THRESHOLD_MS) {
1534
- this.emitSessionEnd();
1578
+ const idleFor = Date.now() - this.session.lastActivityAt;
1579
+ if (idleFor >= SESSION_RESUME_THRESHOLD_MS) {
1535
1580
  this.pageviewId = null;
1536
1581
  this.session = this.startNewSession();
1582
+ this.persistSession();
1537
1583
  this.emitSessionStart();
1538
1584
  } else {
1539
1585
  this.session.hiddenAt = null;
1540
1586
  }
1541
1587
  }
1542
1588
  };
1543
- const onPageHide = () => this.emitSessionEnd();
1589
+ const onPageHide = () => this.persistSession();
1544
1590
  const w = globalThis.window;
1545
1591
  const doc = globalThis.document;
1546
1592
  doc.addEventListener("visibilitychange", onVisChange);
@@ -1553,14 +1599,63 @@ var AutoTracker = class {
1553
1599
  });
1554
1600
  }
1555
1601
  startNewSession() {
1602
+ const now = Date.now();
1556
1603
  return {
1557
1604
  sessionId: mintSessionId(),
1558
- startedAt: Date.now(),
1605
+ startedAt: now,
1606
+ lastActivityAt: now,
1559
1607
  hiddenAt: null,
1560
1608
  endedSent: false,
1561
1609
  acquisition: captureAcquisition()
1562
1610
  };
1563
1611
  }
1612
+ /**
1613
+ * Read the persisted session continuity record. Returns null on no
1614
+ * storage, no record, malformed JSON, or a record missing its required
1615
+ * fields — every failure degrades to "no session to resume", which is
1616
+ * the safe (start-fresh) path.
1617
+ */
1618
+ readStoredSession() {
1619
+ if (!this.storage) return null;
1620
+ try {
1621
+ const raw = this.storage.getItem(this.sessionKey);
1622
+ if (!raw) return null;
1623
+ const p = JSON.parse(raw);
1624
+ if (!p || typeof p.id !== "string" || typeof p.startedAt !== "number" || typeof p.lastActivityAt !== "number") {
1625
+ return null;
1626
+ }
1627
+ return {
1628
+ id: p.id,
1629
+ startedAt: p.startedAt,
1630
+ lastActivityAt: p.lastActivityAt,
1631
+ acquisition: p.acquisition && typeof p.acquisition === "object" ? p.acquisition : EMPTY_ACQUISITION
1632
+ };
1633
+ } catch {
1634
+ return null;
1635
+ }
1636
+ }
1637
+ /** Flush the current session to storage. No-op without storage/session. */
1638
+ persistSession() {
1639
+ if (!this.storage || !this.session) return;
1640
+ this.lastPersistAt = Date.now();
1641
+ try {
1642
+ const rec = {
1643
+ id: this.session.sessionId,
1644
+ startedAt: this.session.startedAt,
1645
+ lastActivityAt: this.session.lastActivityAt,
1646
+ acquisition: this.session.acquisition
1647
+ };
1648
+ this.storage.setItem(this.sessionKey, JSON.stringify(rec));
1649
+ } catch {
1650
+ }
1651
+ }
1652
+ clearStoredSession() {
1653
+ if (!this.storage) return;
1654
+ try {
1655
+ this.storage.removeItem(this.sessionKey);
1656
+ } catch {
1657
+ }
1658
+ }
1564
1659
  emitSessionStart() {
1565
1660
  if (!this.session) return;
1566
1661
  this.track("session.started", { sessionId: this.session.sessionId });
@@ -1732,6 +1827,78 @@ function isInsidePasswordField(el) {
1732
1827
  if (el.closest('input[type="password"]')) return true;
1733
1828
  return false;
1734
1829
  }
1830
+ var INLINE_LABEL_TAGS = /* @__PURE__ */ new Set([
1831
+ "span",
1832
+ "b",
1833
+ "strong",
1834
+ "em",
1835
+ "i",
1836
+ "small",
1837
+ "mark",
1838
+ "u",
1839
+ "label",
1840
+ "abbr",
1841
+ "time",
1842
+ "bdi",
1843
+ "cite",
1844
+ "code",
1845
+ "kbd",
1846
+ "q",
1847
+ "sub",
1848
+ "sup"
1849
+ ]);
1850
+ var NON_LABEL_SUBTREES = /* @__PURE__ */ new Set(["svg", "style", "script", "noscript"]);
1851
+ var CONTAINER_MARKERS = "a[href], button, input, select, textarea, [role='button'], [role='link'], h1, h2, h3, h4, h5, h6";
1852
+ var HEADING_SELECTOR = "h1, h2, h3, h4, h5, h6";
1853
+ function collapseWs(s) {
1854
+ return s.replace(/\s+/g, " ").trim();
1855
+ }
1856
+ function boundaryText(el) {
1857
+ let out = "";
1858
+ const walk = (node) => {
1859
+ const kids = node.childNodes;
1860
+ for (let i = 0; i < kids.length; i++) {
1861
+ const child = kids[i];
1862
+ if (!child) continue;
1863
+ if (child.nodeType === 3) {
1864
+ out += child.textContent || "";
1865
+ } else if (child.nodeType === 1) {
1866
+ if (NON_LABEL_SUBTREES.has(child.tagName.toLowerCase())) continue;
1867
+ out += " ";
1868
+ walk(child);
1869
+ out += " ";
1870
+ }
1871
+ }
1872
+ };
1873
+ walk(el);
1874
+ return collapseWs(out);
1875
+ }
1876
+ function directLabel(el) {
1877
+ let out = "";
1878
+ const kids = el.childNodes;
1879
+ for (let i = 0; i < kids.length; i++) {
1880
+ const child = kids[i];
1881
+ if (!child) continue;
1882
+ if (child.nodeType === 3) {
1883
+ out += " " + (child.textContent || "");
1884
+ } else if (child.nodeType === 1 && INLINE_LABEL_TAGS.has(child.tagName.toLowerCase())) {
1885
+ out += " " + boundaryText(child);
1886
+ }
1887
+ }
1888
+ return collapseWs(out);
1889
+ }
1890
+ function visibleLabel(el) {
1891
+ const isContainer = el.querySelector(CONTAINER_MARKERS) !== null;
1892
+ if (!isContainer) return boundaryText(el);
1893
+ const direct = directLabel(el);
1894
+ if (direct) return direct;
1895
+ const heading = el.querySelector(HEADING_SELECTOR);
1896
+ if (heading) {
1897
+ const h = boundaryText(heading);
1898
+ if (h) return h;
1899
+ }
1900
+ return "";
1901
+ }
1735
1902
  function extractText(el) {
1736
1903
  const clean = (s) => s.replace(/\s+/g, " ").trim();
1737
1904
  const explicit = el.getAttribute("data-cd-track") || el.getAttribute("data-track") || el.getAttribute("data-testid");
@@ -1758,7 +1925,7 @@ function extractText(el) {
1758
1925
  const t = clean(el.value);
1759
1926
  if (t) return t;
1760
1927
  }
1761
- const text = clean(el.textContent || "");
1928
+ const text = visibleLabel(el);
1762
1929
  if (text) return text;
1763
1930
  const title = el.getAttribute("title");
1764
1931
  if (title) {
@@ -2471,6 +2638,210 @@ function sendDiagnosticTelemetry(payload) {
2471
2638
  }
2472
2639
  }
2473
2640
 
2641
+ // src/error-codes.ts
2642
+ var CROSSDECK_ERROR_CODES = Object.freeze([
2643
+ // ----- Configuration -----
2644
+ {
2645
+ code: "invalid_public_key",
2646
+ type: "configuration_error",
2647
+ description: "The publishable key passed to Crossdeck.init() doesn't start with cd_pub_.",
2648
+ resolution: "Copy the key from your Crossdeck dashboard \u2192 API keys page.",
2649
+ retryable: false
2650
+ },
2651
+ {
2652
+ code: "missing_app_id",
2653
+ type: "configuration_error",
2654
+ description: "Crossdeck.init() was called without an appId.",
2655
+ resolution: "Add appId to your init options \u2014 find it in the dashboard's Apps page.",
2656
+ retryable: false
2657
+ },
2658
+ {
2659
+ code: "invalid_environment",
2660
+ type: "configuration_error",
2661
+ description: "Crossdeck.init() requires environment: 'production' | 'sandbox'.",
2662
+ resolution: 'Pass the literal string "production" or "sandbox" \u2014 no other values are accepted.',
2663
+ retryable: false
2664
+ },
2665
+ {
2666
+ code: "environment_mismatch",
2667
+ type: "configuration_error",
2668
+ description: "The publishable key's env prefix doesn't match the declared environment option.",
2669
+ resolution: "Either change `environment` to match the key prefix (cd_pub_test_ \u2194 sandbox, cd_pub_live_ \u2194 production), or swap the key for one minted in the right env.",
2670
+ retryable: false
2671
+ },
2672
+ {
2673
+ code: "not_initialized",
2674
+ type: "configuration_error",
2675
+ description: "An SDK method was called before Crossdeck.init().",
2676
+ resolution: "Call Crossdeck.init({ appId, publicKey, environment }) once at app startup before any other method.",
2677
+ retryable: false
2678
+ },
2679
+ // ----- Identify / track / purchase argument validation -----
2680
+ {
2681
+ code: "missing_user_id",
2682
+ type: "invalid_request_error",
2683
+ description: "identify() was called with an empty userId.",
2684
+ resolution: "Pass a stable, non-empty user identifier from your auth layer \u2014 never a hardcoded placeholder.",
2685
+ retryable: false
2686
+ },
2687
+ {
2688
+ code: "missing_event_name",
2689
+ type: "invalid_request_error",
2690
+ description: "track() was called without an event name.",
2691
+ resolution: "Pass a non-empty string as the first argument.",
2692
+ retryable: false
2693
+ },
2694
+ {
2695
+ code: "missing_group_type",
2696
+ type: "invalid_request_error",
2697
+ description: "group() was called without a group type.",
2698
+ resolution: 'Pass a non-empty type (e.g. "org", "team") as the first argument.',
2699
+ retryable: false
2700
+ },
2701
+ {
2702
+ code: "missing_signed_transaction_info",
2703
+ type: "invalid_request_error",
2704
+ description: "syncPurchases() was called without StoreKit 2 signed transaction info.",
2705
+ resolution: "Pass the JWS string from Transaction.currentEntitlements / Transaction.updates.",
2706
+ retryable: false
2707
+ },
2708
+ // ----- Network / transport -----
2709
+ {
2710
+ code: "fetch_failed",
2711
+ type: "network_error",
2712
+ description: "The underlying fetch() call failed (typically a network outage or DNS issue).",
2713
+ resolution: "Check the user's network. The SDK will retry automatically with exponential backoff.",
2714
+ retryable: true
2715
+ },
2716
+ {
2717
+ code: "request_timeout",
2718
+ type: "network_error",
2719
+ description: "A request was aborted after the configured timeoutMs (default 15s).",
2720
+ resolution: "Check the user's connection. Increase timeoutMs in init options if the user is on a known-slow network.",
2721
+ retryable: true
2722
+ },
2723
+ {
2724
+ code: "invalid_json_response",
2725
+ type: "internal_error",
2726
+ description: "The server returned a 2xx with an unparseable body.",
2727
+ resolution: "Likely a transient backend bug. Retry; if it persists, contact support with the requestId.",
2728
+ retryable: true
2729
+ },
2730
+ // ----- Backend-emitted codes (v1.4.0 Phase 6.2 backfill) -----
2731
+ // Mirror of backend/src/api/v1-errors.ts ApiErrorCode. A developer
2732
+ // hitting any of these on the wire can look them up via
2733
+ // getErrorCode(code) for a canonical remediation step instead of
2734
+ // hunting through Slack history.
2735
+ {
2736
+ code: "missing_api_key",
2737
+ type: "authentication_error",
2738
+ description: "No Authorization header (or Crossdeck-Api-Key header) on the request.",
2739
+ resolution: "Make sure Crossdeck.init({ publicKey }) was called with a cd_pub_\u2026 key before the request fired. Re-check your env-vars in CI / Docker if the key is empty at runtime.",
2740
+ retryable: false
2741
+ },
2742
+ {
2743
+ code: "invalid_api_key",
2744
+ type: "authentication_error",
2745
+ description: "The API key is malformed, unknown, or doesn't resolve to a project.",
2746
+ resolution: "Copy the key from your Crossdeck dashboard \u2192 API keys. Confirm prefix is cd_pub_test_ / cd_pub_live_ for client SDKs and cd_sk_test_ / cd_sk_live_ for the Node server SDK.",
2747
+ retryable: false
2748
+ },
2749
+ {
2750
+ code: "key_revoked",
2751
+ type: "authentication_error",
2752
+ description: "The API key was revoked in the Crossdeck dashboard.",
2753
+ resolution: "Mint a fresh key in the dashboard \u2192 API keys \u2192 Create new, swap it in, and redeploy. The revoked key cannot be reactivated.",
2754
+ retryable: false
2755
+ },
2756
+ {
2757
+ code: "identity_token_invalid",
2758
+ type: "authentication_error",
2759
+ description: "The Firebase / Apple / Google ID token supplied with the request didn't verify against the dashboard's configured signers.",
2760
+ resolution: "Refresh the token client-side (Firebase auth.currentUser.getIdToken(true)) and retry. If the failure persists, confirm the signer is registered under dashboard \u2192 Authentication \u2192 Identity sources.",
2761
+ retryable: true
2762
+ },
2763
+ {
2764
+ code: "origin_not_allowed",
2765
+ type: "permission_error",
2766
+ description: "The Origin header isn't in the project's Allowed origins list.",
2767
+ resolution: "Add the origin (e.g. https://app.example.com) under dashboard \u2192 Settings \u2192 Allowed origins. Wildcards like https://*.example.com are supported.",
2768
+ retryable: false
2769
+ },
2770
+ {
2771
+ code: "bundle_id_not_allowed",
2772
+ type: "permission_error",
2773
+ description: "The iOS bundle ID sent via X-Crossdeck-Bundle-Id isn't registered under this app's Apple identity lock.",
2774
+ resolution: "Add the bundle ID under dashboard \u2192 Apps \u2192 <your app> \u2192 iOS bundle IDs.",
2775
+ retryable: false
2776
+ },
2777
+ {
2778
+ code: "package_name_not_allowed",
2779
+ type: "permission_error",
2780
+ description: "The Android package name sent via X-Crossdeck-Package-Name isn't registered under this app's Android identity lock.",
2781
+ resolution: "Add the package name under dashboard \u2192 Apps \u2192 <your app> \u2192 Android package names.",
2782
+ retryable: false
2783
+ },
2784
+ {
2785
+ code: "env_mismatch",
2786
+ type: "permission_error",
2787
+ description: "The request env (inferred from key prefix) doesn't match the resolved app's configured env.",
2788
+ resolution: "Use a cd_pub_live_ / cd_sk_live_ key with a production app, cd_pub_test_ / cd_sk_test_ with a sandbox app. The two cannot cross.",
2789
+ retryable: false
2790
+ },
2791
+ {
2792
+ code: "idempotency_key_in_use",
2793
+ type: "invalid_request_error",
2794
+ description: "An Idempotency-Key was reused for a request with a different body (Stripe-grade contract).",
2795
+ resolution: "Generate a fresh key for a different transaction, or reuse the key only with the EXACT same body. The v1.4.0 SDKs derive keys deterministically from the body so this should never fire on SDK-managed calls.",
2796
+ retryable: false
2797
+ },
2798
+ {
2799
+ code: "rate_limited",
2800
+ type: "rate_limit_error",
2801
+ description: "Request rate exceeded the project's per-second cap.",
2802
+ resolution: "Honour the Retry-After header \u2014 the SDK does this automatically on managed retries. If you're hitting it from a custom code path, throttle to <100 req/s/key.",
2803
+ retryable: true
2804
+ },
2805
+ {
2806
+ code: "internal_error",
2807
+ type: "internal_error",
2808
+ description: "Server-side issue. Safe to retry with backoff.",
2809
+ resolution: "The SDK retries automatically. If your code paths through to this error, contact support with the requestId from the response envelope.",
2810
+ retryable: true
2811
+ },
2812
+ {
2813
+ code: "google_not_supported",
2814
+ type: "invalid_request_error",
2815
+ description: "POST /purchases/sync with rail=google is gated until the Play Developer API reconciliation worker ships.",
2816
+ resolution: "Until v1.5+, Google Play purchases verify via Real-time Developer Notifications. The SDK auto-track path handles this transparently for Android consumers.",
2817
+ retryable: false
2818
+ },
2819
+ {
2820
+ code: "stripe_not_supported",
2821
+ type: "invalid_request_error",
2822
+ description: "POST /purchases/sync with rail=stripe is unsupported \u2014 Stripe Checkout's redirect flow uses platform webhooks instead.",
2823
+ resolution: "Wire Stripe via the standard Checkout / Customer Portal flow; Crossdeck reconciles via the platform webhook automatically. No SDK call needed.",
2824
+ retryable: false
2825
+ },
2826
+ {
2827
+ code: "missing_required_param",
2828
+ type: "invalid_request_error",
2829
+ description: "A required field is absent from the request body.",
2830
+ resolution: "Inspect the error.message \u2014 the missing field name is included verbatim. Refer to the SDK's TypeScript types for the canonical request shape.",
2831
+ retryable: false
2832
+ },
2833
+ {
2834
+ code: "invalid_param_value",
2835
+ type: "invalid_request_error",
2836
+ description: "A field is present but the value failed validation (wrong shape, wrong length, wrong enum value).",
2837
+ resolution: "Read error.message for the specific field + reason. SDK-managed call sites should never emit this \u2014 file a bug if you do.",
2838
+ retryable: false
2839
+ }
2840
+ ]);
2841
+ function getErrorCode(code) {
2842
+ return CROSSDECK_ERROR_CODES.find((e) => e.code === code);
2843
+ }
2844
+
2474
2845
  // src/_contract-verifiers.ts
2475
2846
  function buildVerifierContext(opts) {
2476
2847
  return {
@@ -2995,13 +3366,64 @@ var VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK = {
2995
3366
  );
2996
3367
  }
2997
3368
  };
3369
+ var BACKEND_WIRE_CODES = Object.freeze([
3370
+ "missing_api_key",
3371
+ "invalid_api_key",
3372
+ "key_revoked",
3373
+ "identity_token_invalid",
3374
+ "origin_not_allowed",
3375
+ "bundle_id_not_allowed",
3376
+ "package_name_not_allowed",
3377
+ "env_mismatch",
3378
+ "idempotency_key_in_use",
3379
+ "rate_limited",
3380
+ "internal_error",
3381
+ "google_not_supported",
3382
+ "stripe_not_supported",
3383
+ "missing_required_param",
3384
+ "invalid_param_value"
3385
+ ]);
3386
+ var VERIFIER_SDK_ERROR_CODES_CATALOGUE = {
3387
+ contractId: "sdk-error-codes-catalogue",
3388
+ bootTest() {
3389
+ const t0 = nowMs();
3390
+ try {
3391
+ const missing = [];
3392
+ for (const code of BACKEND_WIRE_CODES) {
3393
+ const entry = getErrorCode(code);
3394
+ if (!entry || !entry.description || entry.description.trim().length === 0 || !entry.resolution || entry.resolution.trim().length === 0) {
3395
+ missing.push(code);
3396
+ }
3397
+ }
3398
+ if (missing.length > 0) {
3399
+ return fail(
3400
+ "sdk-error-codes-catalogue",
3401
+ `catalogue missing description+resolution for backend code(s): ${missing.join(", ")}`,
3402
+ nowMs() - t0
3403
+ );
3404
+ }
3405
+ return pass(
3406
+ "sdk-error-codes-catalogue",
3407
+ `all ${BACKEND_WIRE_CODES.length} backend wire codes carry description + resolution`,
3408
+ nowMs() - t0
3409
+ );
3410
+ } catch (err) {
3411
+ return fail(
3412
+ "sdk-error-codes-catalogue",
3413
+ `boot test threw: ${err.message?.slice(0, 80) ?? "unknown error"}`,
3414
+ nowMs() - t0
3415
+ );
3416
+ }
3417
+ }
3418
+ };
2998
3419
  var STATIC_VERIFIERS = Object.freeze([
2999
3420
  VERIFIER_PER_USER_CACHE_ISOLATION,
3000
3421
  VERIFIER_IDEMPOTENCY_KEY_DETERMINISTIC,
3001
3422
  VERIFIER_ERROR_ENVELOPE_SHAPE,
3002
3423
  VERIFIER_FLUSH_INTERVAL_PARITY,
3003
3424
  VERIFIER_SUPER_PROPERTY_MERGE_PRECEDENCE,
3004
- VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK
3425
+ VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK,
3426
+ VERIFIER_SDK_ERROR_CODES_CATALOGUE
3005
3427
  ]);
3006
3428
  async function runBootSelfTest(verifiers, reporter, ctx) {
3007
3429
  if (ctx.disableContractAssertions) {
@@ -3305,19 +3727,58 @@ var DEFAULT_ERROR_CAPTURE = {
3305
3727
  "ResizeObserver loop completed with undelivered notifications",
3306
3728
  "Non-Error promise rejection captured"
3307
3729
  // NOTE: We deliberately do NOT drop cross-origin "Script error."
3308
- // events here. They used to be silently filtered as noise, but
3309
- // silent drops are the opposite of "developer sleeps well at
3310
- // night". We now capture them with a clear label and the
3311
- // `cross_origin` tag so the dashboard surfaces them as a
3312
- // distinct, actionable category (the fix is always the same
3313
- // add `crossorigin="anonymous"` to the script tag + CORS
3314
- // headers on the script's origin). Apps that genuinely want
3315
- // them muted can re-add "Script error" to ignoreErrors via
3316
- // init config.
3730
+ // events here. The actionability principle (see denyUrls
3731
+ // comment below) draws the line at "developer cannot act":
3732
+ // cross-origin CORS opacity HAS a real, code-shaped fix (add
3733
+ // `crossorigin="anonymous"` to the script tag + CORS headers
3734
+ // on the script's origin). The dashboard surfaces these with a
3735
+ // `cross_origin` tag pointing at that fix. Apps that genuinely
3736
+ // want them muted can re-add "Script error" to ignoreErrors
3737
+ // via init config.
3317
3738
  ],
3318
3739
  allowUrls: [],
3319
3740
  denyUrls: [
3320
- // Common third-party extensions that pollute error streams.
3741
+ // The actionability principle
3742
+ // ---------------------------
3743
+ // Crossdeck's default philosophy is "classify, don't silently
3744
+ // drop" — surfacing errors the developer can fix is more useful
3745
+ // than hiding them. That's right for cross-origin "Script
3746
+ // error." (real, code-shaped CORS fix) and for plain
3747
+ // application bugs (obviously real).
3748
+ //
3749
+ // It's NOT right for events the developer cannot act on.
3750
+ // - A user's installed browser extension throwing inside
3751
+ // its own `chrome-extension://` URL: the developer can't
3752
+ // ship a fix for someone else's extension.
3753
+ // - An ad blocker preventing `googletagmanager.com` from
3754
+ // loading: the developer can't unblock the user's blocker.
3755
+ //
3756
+ // Capturing these creates a noise tab that's always non-empty
3757
+ // and never actionable, which trains the dev to ignore the
3758
+ // noise tab — and then the actionable noise (CORS opacity,
3759
+ // etc.) gets ignored along with it. Same lesson as Crossdeck's
3760
+ // "0-2 notifications a week" discipline: a signal that fires
3761
+ // constantly with nothing actionable behind it stops being a
3762
+ // signal.
3763
+ //
3764
+ // So we drop at the source for the unactionable category, and
3765
+ // keep capturing for the actionable category. Same principle
3766
+ // applied to two structurally different inputs — not a new
3767
+ // philosophy.
3768
+ //
3769
+ // The bootstrap list below is the minimum that ships in code.
3770
+ // The full, versioned list arrives at boot via /v1/config —
3771
+ // see `backend/src/lib/error-noise-deny-list.ts`. The SDK
3772
+ // applies the union of (bootstrap + remote), so a freshly-
3773
+ // installed SDK protects users immediately, and remote updates
3774
+ // (new ad-network domains, new pixel hosts) reach every
3775
+ // install without an SDK release.
3776
+ //
3777
+ // The backend Layer-2 classifier
3778
+ // (`backend/src/api/lib/noise-classifier.ts`) is the safety
3779
+ // net for events that slip past these patterns — older SDK
3780
+ // versions in the wild that haven't fetched the remote list
3781
+ // yet, or brand-new patterns the list hasn't named.
3321
3782
  /^chrome-extension:\/\//,
3322
3783
  /^moz-extension:\/\//,
3323
3784
  /^safari-extension:\/\//,
@@ -4110,7 +4571,12 @@ var CrossdeckClient = class {
4110
4571
  if (autoTrack.sessions || autoTrack.pageViews) {
4111
4572
  const tracker = new AutoTracker(
4112
4573
  autoTrack,
4113
- (name, properties) => this.track(name, properties)
4574
+ (name, properties) => this.track(name, properties),
4575
+ // Persist session continuity on the SAME adapter as identity, so
4576
+ // a visit survives full-page navigations (multi-page sites
4577
+ // re-install the SDK on every page) and honours the same consent
4578
+ // posture — MemoryStorage when identity persistence is off.
4579
+ { storage: effectiveStorage, storageKey: opts.storagePrefix + "session" }
4114
4580
  );
4115
4581
  this.state.autoTracker = tracker;
4116
4582
  tracker.install();
@@ -4575,6 +5041,12 @@ var CrossdeckClient = class {
4575
5041
  * true even before the session's first network round-trip. Returns
4576
5042
  * false only for a genuinely new install that has never completed a
4577
5043
  * getEntitlements(), or for an entitlement past its own validUntil.
5044
+ *
5045
+ * Throws `not_initialized` (CrossdeckError, type
5046
+ * `configuration_error`) if called before `Crossdeck.init()`. The
5047
+ * `useEntitlement` React hook and the Vue composable both swallow
5048
+ * this and return `false`; bare callers must guard for it (or call
5049
+ * after `init()` resolves).
4578
5050
  */
4579
5051
  isEntitled(key) {
4580
5052
  const s = this.requireStarted();
@@ -4590,8 +5062,21 @@ var CrossdeckClient = class {
4590
5062
  *
4591
5063
  * The listener is invoked AFTER the cache mutates — once after a
4592
5064
  * successful `getEntitlements()` warms it, again after `syncPurchases()`
4593
- * delivers fresh entitlements, and once on `reset()` to fire the
4594
- * empty-cache state for logout flows.
5065
+ * delivers fresh entitlements, once on `reset()` to fire the empty-
5066
+ * cache state for logout flows, AND once on `identify()` after the
5067
+ * per-user cache slot rotates and re-hydrates from device storage.
5068
+ *
5069
+ * IMPORTANT — the `identify()` fire is a TRAP if you treat it as
5070
+ * authoritative network state. `identify()` does NOT fetch entitlements;
5071
+ * it switches the per-user cache slot and rehydrates from device
5072
+ * storage (which is empty for a brand-new install, and last-known-good
5073
+ * — possibly stale — for a returning user). A listener that gates a
5074
+ * paywall on the first fire after an identity switch will read
5075
+ * `false` for a paying customer on a fresh device and let them past
5076
+ * the gate as free. The network-truth fire is the one that follows
5077
+ * the next `getEntitlements()` resolution. Either call
5078
+ * `getEntitlements()` explicitly after `identify()`, or have your
5079
+ * gating code tolerate the empty-then-populated transition.
4595
5080
  *
4596
5081
  * It is NOT invoked synchronously on subscribe. Callers that need
4597
5082
  * the current state should read it via `isEntitled()` / `listEntitlements()`
@@ -4700,6 +5185,7 @@ var CrossdeckClient = class {
4700
5185
  );
4701
5186
  }
4702
5187
  }
5188
+ s.autoTracker?.markActivity();
4703
5189
  const enriched = { ...s.deviceInfo };
4704
5190
  const sessionId = s.autoTracker?.currentSessionId;
4705
5191
  if (sessionId) enriched.sessionId = sessionId;
@@ -4954,6 +5440,25 @@ var CrossdeckClient = class {
4954
5440
  events: s.events.getStats()
4955
5441
  };
4956
5442
  }
5443
+ /**
5444
+ * The stable reference to hand Stripe at checkout so the resulting
5445
+ * purchase attributes to THIS person. Stamp it on the Checkout Session
5446
+ * as `metadata.crossdeck_ref` (see docs/connect-stripe) — the platform
5447
+ * webhook reads it back, validates it, and attaches the subscription to
5448
+ * the right customer instead of stranding it on an anonymous record.
5449
+ *
5450
+ * Returns the strongest identifier the SDK currently holds, in the same
5451
+ * precedence the server resolves by:
5452
+ * crossdeckCustomerId (cdcust_…) > developerUserId > anonymousId
5453
+ * anonymousId is always present, so this always returns a usable,
5454
+ * non-empty reference — even before identify(). Identify the user as
5455
+ * early as you can, though, so the reference is their stable identity
5456
+ * and not a per-device anon id.
5457
+ */
5458
+ getCheckoutReference() {
5459
+ const s = this.requireStarted();
5460
+ return s.identity.crossdeckCustomerId ?? s.developerUserId ?? s.identity.anonymousId;
5461
+ }
4957
5462
  // ---------- private helpers ----------
4958
5463
  requireStarted() {
4959
5464
  if (!this.state) {