@cross-deck/web 1.5.1 → 1.5.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.
Files changed (47) hide show
  1. package/dist/crossdeck.umd.min.js +2 -2
  2. package/dist/crossdeck.umd.min.js.map +1 -1
  3. package/dist/error-codes.json +1 -106
  4. package/dist/index.cjs +22 -940
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.mts +4 -177
  7. package/dist/index.d.ts +4 -177
  8. package/dist/index.mjs +22 -939
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/react.cjs +22 -404
  11. package/dist/react.cjs.map +1 -1
  12. package/dist/react.d.mts +1 -1
  13. package/dist/react.d.ts +1 -1
  14. package/dist/react.mjs +22 -404
  15. package/dist/react.mjs.map +1 -1
  16. package/dist/{types-Bu3jbmdq.d.mts → types-BzoKor4z.d.mts} +0 -4
  17. package/dist/{types-Bu3jbmdq.d.ts → types-BzoKor4z.d.ts} +0 -4
  18. package/dist/vue.cjs +22 -404
  19. package/dist/vue.cjs.map +1 -1
  20. package/dist/vue.mjs +22 -404
  21. package/dist/vue.mjs.map +1 -1
  22. package/package.json +1 -1
  23. package/dist/contracts 2.json +0 -378
  24. package/dist/contracts.json +0 -378
  25. package/dist/crossdeck.umd.min 2.js +0 -3
  26. package/dist/crossdeck.umd.min.js 2.map +0 -1
  27. package/dist/error-codes 2.json +0 -196
  28. package/dist/index 2.cjs +0 -4778
  29. package/dist/index 2.mjs +0 -4742
  30. package/dist/index.cjs 2.map +0 -1
  31. package/dist/index.d 2.mts +0 -938
  32. package/dist/index.d 2.ts +0 -938
  33. package/dist/index.mjs 2.map +0 -1
  34. package/dist/react 2.cjs +0 -4220
  35. package/dist/react 2.mjs +0 -4193
  36. package/dist/react.cjs 2.map +0 -1
  37. package/dist/react.d 2.mts +0 -91
  38. package/dist/react.d 2.ts +0 -91
  39. package/dist/react.mjs 2.map +0 -1
  40. package/dist/types-Bu3jbmdq.d 2.mts +0 -314
  41. package/dist/types-Bu3jbmdq.d 2.ts +0 -314
  42. package/dist/vue 2.cjs +0 -4185
  43. package/dist/vue 2.mjs +0 -4159
  44. package/dist/vue.cjs 2.map +0 -1
  45. package/dist/vue.d 2.mts +0 -37
  46. package/dist/vue.d 2.ts +0 -37
  47. package/dist/vue.mjs 2.map +0 -1
package/dist/index.cjs CHANGED
@@ -23,7 +23,6 @@ __export(index_exports, {
23
23
  CROSSDECK_ERROR_CODES: () => CROSSDECK_ERROR_CODES,
24
24
  Crossdeck: () => Crossdeck,
25
25
  CrossdeckClient: () => CrossdeckClient,
26
- CrossdeckContracts: () => CrossdeckContracts,
27
26
  CrossdeckError: () => CrossdeckError,
28
27
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
29
28
  MemoryStorage: () => MemoryStorage,
@@ -99,7 +98,7 @@ function typeMapForStatus(status) {
99
98
  }
100
99
 
101
100
  // src/_version.ts
102
- var SDK_VERSION = "1.4.2";
101
+ var SDK_VERSION = "1.3.0";
103
102
  var SDK_NAME = "@cross-deck/web";
104
103
 
105
104
  // src/http.ts
@@ -349,258 +348,29 @@ function randomChars(count) {
349
348
  return out.join("");
350
349
  }
351
350
 
352
- // src/hash.ts
353
- var K = new Uint32Array([
354
- 1116352408,
355
- 1899447441,
356
- 3049323471,
357
- 3921009573,
358
- 961987163,
359
- 1508970993,
360
- 2453635748,
361
- 2870763221,
362
- 3624381080,
363
- 310598401,
364
- 607225278,
365
- 1426881987,
366
- 1925078388,
367
- 2162078206,
368
- 2614888103,
369
- 3248222580,
370
- 3835390401,
371
- 4022224774,
372
- 264347078,
373
- 604807628,
374
- 770255983,
375
- 1249150122,
376
- 1555081692,
377
- 1996064986,
378
- 2554220882,
379
- 2821834349,
380
- 2952996808,
381
- 3210313671,
382
- 3336571891,
383
- 3584528711,
384
- 113926993,
385
- 338241895,
386
- 666307205,
387
- 773529912,
388
- 1294757372,
389
- 1396182291,
390
- 1695183700,
391
- 1986661051,
392
- 2177026350,
393
- 2456956037,
394
- 2730485921,
395
- 2820302411,
396
- 3259730800,
397
- 3345764771,
398
- 3516065817,
399
- 3600352804,
400
- 4094571909,
401
- 275423344,
402
- 430227734,
403
- 506948616,
404
- 659060556,
405
- 883997877,
406
- 958139571,
407
- 1322822218,
408
- 1537002063,
409
- 1747873779,
410
- 1955562222,
411
- 2024104815,
412
- 2227730452,
413
- 2361852424,
414
- 2428436474,
415
- 2756734187,
416
- 3204031479,
417
- 3329325298
418
- ]);
419
- function utf8Bytes(input) {
420
- if (typeof TextEncoder !== "undefined") {
421
- return new TextEncoder().encode(input);
422
- }
423
- const out = [];
424
- for (let i = 0; i < input.length; i++) {
425
- let codePoint = input.charCodeAt(i);
426
- if (codePoint >= 55296 && codePoint <= 56319 && i + 1 < input.length) {
427
- const next = input.charCodeAt(i + 1);
428
- if (next >= 56320 && next <= 57343) {
429
- codePoint = 65536 + (codePoint - 55296 << 10) + (next - 56320);
430
- i++;
431
- }
432
- }
433
- if (codePoint < 128) {
434
- out.push(codePoint);
435
- } else if (codePoint < 2048) {
436
- out.push(192 | codePoint >> 6);
437
- out.push(128 | codePoint & 63);
438
- } else if (codePoint < 65536) {
439
- out.push(224 | codePoint >> 12);
440
- out.push(128 | codePoint >> 6 & 63);
441
- out.push(128 | codePoint & 63);
442
- } else {
443
- out.push(240 | codePoint >> 18);
444
- out.push(128 | codePoint >> 12 & 63);
445
- out.push(128 | codePoint >> 6 & 63);
446
- out.push(128 | codePoint & 63);
447
- }
448
- }
449
- return new Uint8Array(out);
450
- }
451
- function sha256Hex(input) {
452
- const bytes = utf8Bytes(input);
453
- const bitLength = bytes.length * 8;
454
- const blockCount = Math.floor((bytes.length + 9 + 63) / 64);
455
- const padded = new Uint8Array(blockCount * 64);
456
- padded.set(bytes);
457
- padded[bytes.length] = 128;
458
- const high = Math.floor(bitLength / 4294967296);
459
- const low = bitLength >>> 0;
460
- const lenOffset = padded.length - 8;
461
- padded[lenOffset + 0] = high >>> 24 & 255;
462
- padded[lenOffset + 1] = high >>> 16 & 255;
463
- padded[lenOffset + 2] = high >>> 8 & 255;
464
- padded[lenOffset + 3] = high & 255;
465
- padded[lenOffset + 4] = low >>> 24 & 255;
466
- padded[lenOffset + 5] = low >>> 16 & 255;
467
- padded[lenOffset + 6] = low >>> 8 & 255;
468
- padded[lenOffset + 7] = low & 255;
469
- const H = new Uint32Array([
470
- 1779033703,
471
- 3144134277,
472
- 1013904242,
473
- 2773480762,
474
- 1359893119,
475
- 2600822924,
476
- 528734635,
477
- 1541459225
478
- ]);
479
- const W = new Uint32Array(64);
480
- for (let block = 0; block < blockCount; block++) {
481
- const offset = block * 64;
482
- for (let t = 0; t < 16; t++) {
483
- W[t] = (padded[offset + t * 4] << 24 | padded[offset + t * 4 + 1] << 16 | padded[offset + t * 4 + 2] << 8 | padded[offset + t * 4 + 3]) >>> 0;
484
- }
485
- for (let t = 16; t < 64; t++) {
486
- const w15 = W[t - 15];
487
- const w2 = W[t - 2];
488
- const s0 = (w15 >>> 7 | w15 << 25) ^ (w15 >>> 18 | w15 << 14) ^ w15 >>> 3;
489
- const s1 = (w2 >>> 17 | w2 << 15) ^ (w2 >>> 19 | w2 << 13) ^ w2 >>> 10;
490
- W[t] = W[t - 16] + s0 + W[t - 7] + s1 >>> 0;
491
- }
492
- let a = H[0], b = H[1], c = H[2], d = H[3];
493
- let e = H[4], f = H[5], g = H[6], h = H[7];
494
- for (let t = 0; t < 64; t++) {
495
- const S1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
496
- const ch = e & f ^ ~e & g;
497
- const temp1 = h + S1 + ch + K[t] + W[t] >>> 0;
498
- const S0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
499
- const maj = a & b ^ a & c ^ b & c;
500
- const temp2 = S0 + maj >>> 0;
501
- h = g;
502
- g = f;
503
- f = e;
504
- e = d + temp1 >>> 0;
505
- d = c;
506
- c = b;
507
- b = a;
508
- a = temp1 + temp2 >>> 0;
509
- }
510
- H[0] = H[0] + a >>> 0;
511
- H[1] = H[1] + b >>> 0;
512
- H[2] = H[2] + c >>> 0;
513
- H[3] = H[3] + d >>> 0;
514
- H[4] = H[4] + e >>> 0;
515
- H[5] = H[5] + f >>> 0;
516
- H[6] = H[6] + g >>> 0;
517
- H[7] = H[7] + h >>> 0;
518
- }
519
- let hex = "";
520
- for (let i = 0; i < 8; i++) {
521
- hex += H[i].toString(16).padStart(8, "0");
522
- }
523
- return hex;
524
- }
525
-
526
351
  // src/entitlement-cache.ts
527
352
  var DEFAULT_STALE_AFTER_MS = 24 * 60 * 60 * 1e3;
528
- var ANON_SUFFIX = "_anon";
529
- var INDEX_SUFFIX = "_index";
530
- var EntitlementCache = class _EntitlementCache {
353
+ var EntitlementCache = class {
531
354
  /**
532
- * @param storage Device storage adapter. When omitted (tests) or
533
- * a MemoryStorage (strict-consent / no-persistence
534
- * mode) the cache is session-only — durability is
535
- * simply absent, never wrong.
536
- * @param storageKeyPrefix Prefix used to derive per-user storage keys
537
- * (`<prefix>:<sha256(userId)>`). Default
538
- * `crossdeck:entitlements`. The trailing user
539
- * suffix is filled at identify() / reset()
540
- * time — see [[setUserKey]].
541
- * @param staleAfterMs Age past which last-known-good is flagged stale
542
- * even without a failed refresh. Default 24h.
355
+ * @param storage Device storage adapter. When omitted (tests) or
356
+ * a MemoryStorage (strict-consent / no-persistence
357
+ * mode) the cache is session-only — durability is
358
+ * simply absent, never wrong.
359
+ * @param storageKey Full key the persisted blob lives under.
360
+ * @param staleAfterMs Age past which last-known-good is flagged stale
361
+ * even without a failed refresh. Default 24h.
543
362
  */
544
- constructor(storage, storageKeyPrefix = "crossdeck:entitlements", staleAfterMs = DEFAULT_STALE_AFTER_MS) {
363
+ constructor(storage, storageKey = "crossdeck:entitlements", staleAfterMs = DEFAULT_STALE_AFTER_MS) {
545
364
  this.all = [];
546
365
  this.lastUpdated = 0;
547
366
  this.lastRefreshFailedAt = 0;
548
367
  this.listeners = /* @__PURE__ */ new Set();
549
368
  this.listenerErrorCount = 0;
550
- this.currentSuffix = ANON_SUFFIX;
551
369
  this.storage = storage;
552
- this.storageKeyPrefix = storageKeyPrefix;
370
+ this.storageKey = storageKey;
553
371
  this.staleAfterMs = staleAfterMs;
554
372
  this.hydrate();
555
373
  }
556
- /** The full storage key the current-user blob is persisted under. */
557
- get storageKey() {
558
- return `${this.storageKeyPrefix}:${this.currentSuffix}`;
559
- }
560
- /** Key of the index blob — a JSON array of every suffix we've
561
- * written. Used by clearAll() to scope a logout-wipe. */
562
- get indexKey() {
563
- return `${this.storageKeyPrefix}:${INDEX_SUFFIX}`;
564
- }
565
- /** Derive a stable suffix for a developerUserId via SHA-256. The
566
- * raw userId never lands in the storage key — protects against
567
- * accidentally leaking email-style identifiers through DevTools
568
- * inspection. Pass `null` to switch back to the anonymous slot. */
569
- static suffixForUserId(userId) {
570
- if (userId == null || userId === "") return ANON_SUFFIX;
571
- return sha256Hex(userId);
572
- }
573
- /**
574
- * Switch the cache to a different user's storage slot. Bank-grade
575
- * three-layer isolation:
576
- * (a) Physical key separation — `<prefix>:<sha256(userId)>` so
577
- * a user-switch can't physically read prior user's data
578
- * even if the in-memory clear was skipped.
579
- * (b) Unconditional in-memory clear — invoked whenever the
580
- * active suffix changes, even on same-id re-identify.
581
- * (c) Re-hydrate from the new slot — a returning user observes
582
- * their last-known-good cache from storage immediately.
583
- *
584
- * Caller (identify() / reset()) MUST invoke this BEFORE the next
585
- * setFromList() so the write lands under the right key.
586
- */
587
- setUserKey(userId) {
588
- const nextSuffix = _EntitlementCache.suffixForUserId(userId);
589
- if (nextSuffix === this.currentSuffix) {
590
- this.all = [];
591
- this.lastUpdated = 0;
592
- this.lastRefreshFailedAt = 0;
593
- this.notify();
594
- this.hydrate();
595
- return;
596
- }
597
- this.currentSuffix = nextSuffix;
598
- this.all = [];
599
- this.lastUpdated = 0;
600
- this.lastRefreshFailedAt = 0;
601
- this.hydrate();
602
- this.notify();
603
- }
604
374
  /**
605
375
  * Sync read — true iff the entitlement is currently granting access.
606
376
  *
@@ -670,13 +440,12 @@ var EntitlementCache = class _EntitlementCache {
670
440
  this.lastUpdated = Date.now();
671
441
  this.lastRefreshFailedAt = 0;
672
442
  this.persist();
673
- this.recordSuffixInIndex(this.currentSuffix);
674
443
  this.notify();
675
444
  }
676
445
  /**
677
- * Wipe the CURRENT user's slot. Used internally when a single
678
- * user's cache needs to be invalidated without affecting other
679
- * persisted slots. The full-logout path is [[clearAll]].
446
+ * Wipe used on reset() (logout) and on an identity switch. Clears
447
+ * BOTH memory and durable storage so a prior user's entitlements can
448
+ * never leak to the next person on this device.
680
449
  */
681
450
  clear() {
682
451
  this.all = [];
@@ -688,40 +457,6 @@ var EntitlementCache = class _EntitlementCache {
688
457
  } catch {
689
458
  }
690
459
  }
691
- this.removeSuffixFromIndex(this.currentSuffix);
692
- this.notify();
693
- }
694
- /**
695
- * Logout-grade wipe — bank-grade contract: removes EVERY per-user
696
- * entitlement slot the SDK has ever written on this device, then
697
- * clears the index. Used by `Crossdeck.reset()` so a logout on a
698
- * shared device can never leave another user's entitlements
699
- * readable (layer (c) of the v1.4.0 isolation fix).
700
- *
701
- * After clearAll(), the cache is back to anonymous + empty.
702
- */
703
- clearAll() {
704
- this.all = [];
705
- this.lastUpdated = 0;
706
- this.lastRefreshFailedAt = 0;
707
- this.currentSuffix = ANON_SUFFIX;
708
- if (this.storage) {
709
- const suffixes = this.readIndex();
710
- for (const suffix of suffixes) {
711
- try {
712
- this.storage.removeItem(`${this.storageKeyPrefix}:${suffix}`);
713
- } catch {
714
- }
715
- }
716
- try {
717
- this.storage.removeItem(`${this.storageKeyPrefix}:${ANON_SUFFIX}`);
718
- } catch {
719
- }
720
- try {
721
- this.storage.removeItem(this.indexKey);
722
- } catch {
723
- }
724
- }
725
460
  this.notify();
726
461
  }
727
462
  /**
@@ -771,47 +506,6 @@ var EntitlementCache = class _EntitlementCache {
771
506
  } catch {
772
507
  }
773
508
  }
774
- /** Read the index of all per-user suffixes the SDK has written. */
775
- readIndex() {
776
- if (!this.storage) return [];
777
- try {
778
- const raw = this.storage.getItem(this.indexKey);
779
- if (!raw) return [];
780
- const parsed = JSON.parse(raw);
781
- if (Array.isArray(parsed)) {
782
- return parsed.filter((x) => typeof x === "string");
783
- }
784
- return [];
785
- } catch {
786
- return [];
787
- }
788
- }
789
- /** Add a suffix to the persisted index. Idempotent. */
790
- recordSuffixInIndex(suffix) {
791
- if (!this.storage) return;
792
- const existing = this.readIndex();
793
- if (existing.includes(suffix)) return;
794
- existing.push(suffix);
795
- try {
796
- this.storage.setItem(this.indexKey, JSON.stringify(existing));
797
- } catch {
798
- }
799
- }
800
- /** Remove a suffix from the persisted index. No-op if absent. */
801
- removeSuffixFromIndex(suffix) {
802
- if (!this.storage) return;
803
- const existing = this.readIndex();
804
- const next = existing.filter((s) => s !== suffix);
805
- if (next.length === existing.length) return;
806
- try {
807
- if (next.length === 0) {
808
- this.storage.removeItem(this.indexKey);
809
- } else {
810
- this.storage.setItem(this.indexKey, JSON.stringify(next));
811
- }
812
- } catch {
813
- }
814
- }
815
509
  notify() {
816
510
  if (this.listeners.size === 0) return;
817
511
  const snapshot = this.all.slice();
@@ -826,34 +520,6 @@ var EntitlementCache = class _EntitlementCache {
826
520
  }
827
521
  };
828
522
 
829
- // src/idempotency-key.ts
830
- function formatAsUuid(hex) {
831
- return [
832
- hex.slice(0, 8),
833
- hex.slice(8, 12),
834
- hex.slice(12, 16),
835
- hex.slice(16, 20),
836
- hex.slice(20, 32)
837
- ].join("-");
838
- }
839
- function deriveIdempotencyKeyForPurchase(body) {
840
- let identifier;
841
- if (body.rail === "apple") {
842
- identifier = body.signedTransactionInfo ?? "";
843
- } else if (body.rail === "google") {
844
- identifier = body.purchaseToken ?? "";
845
- } else {
846
- identifier = "";
847
- }
848
- if (!identifier) {
849
- throw new Error(
850
- `deriveIdempotencyKeyForPurchase: no stable identifier in body (rail=${body.rail}). Apple needs signedTransactionInfo; Google needs purchaseToken.`
851
- );
852
- }
853
- const namespaced = `crossdeck:purchases/sync:${body.rail}:${identifier}`;
854
- return formatAsUuid(sha256Hex(namespaced));
855
- }
856
-
857
523
  // src/retry-policy.ts
858
524
  var DEFAULT_BASE = 1e3;
859
525
  var DEFAULT_MAX = 6e4;
@@ -3116,10 +2782,6 @@ var CrossdeckClient = class {
3116
2782
  this.state.errors?.uninstall();
3117
2783
  } catch {
3118
2784
  }
3119
- try {
3120
- void this.state.events.flush({ keepalive: true });
3121
- } catch {
3122
- }
3123
2785
  }
3124
2786
  if (!options.publicKey || !options.publicKey.startsWith("cd_pub_")) {
3125
2787
  throw new CrossdeckError({
@@ -3167,12 +2829,7 @@ var CrossdeckClient = class {
3167
2829
  // load still flushes if the user leaves quickly (the keepalive
3168
2830
  // pagehide handler picks up anything that doesn't); long enough
3169
2831
  // that bursts of clicks coalesce into one network round-trip.
3170
- // v1.4.0 Phase 3.3 — flush interval default parity. Pre-
3171
- // v1.4.0: Web/Node 1500ms, RN/Swift/Android 5000ms. All
3172
- // converged on 2000ms (the Stripe-adjacent industry norm)
3173
- // so cross-platform funnels show events landing at the
3174
- // same cadence on every SDK. Per-instance override stays.
3175
- eventFlushIntervalMs: options.eventFlushIntervalMs ?? 2e3,
2832
+ eventFlushIntervalMs: options.eventFlushIntervalMs ?? 1500,
3176
2833
  sdkVersion: options.sdkVersion ?? SDK_VERSION,
3177
2834
  autoTrack,
3178
2835
  appVersion: options.appVersion ?? null
@@ -3400,10 +3057,14 @@ var CrossdeckClient = class {
3400
3057
  };
3401
3058
  if (options?.email) body.email = options.email;
3402
3059
  if (traits) body.traits = traits;
3403
- s.entitlements.setUserKey(userId);
3404
3060
  const result = await s.http.request("POST", "/identity/alias", {
3405
3061
  body
3406
3062
  });
3063
+ const priorCdcust = s.identity.crossdeckCustomerId;
3064
+ const cacheHasEntries = s.entitlements.list().length > 0;
3065
+ if (priorCdcust && result.crossdeckCustomerId && priorCdcust !== result.crossdeckCustomerId || !priorCdcust && cacheHasEntries) {
3066
+ s.entitlements.clear();
3067
+ }
3407
3068
  s.identity.setCrossdeckCustomerId(result.crossdeckCustomerId);
3408
3069
  s.developerUserId = userId;
3409
3070
  return result;
@@ -3708,37 +3369,6 @@ var CrossdeckClient = class {
3708
3369
  * trip happens in the background. To flush before the page unloads,
3709
3370
  * call flush().
3710
3371
  */
3711
- /**
3712
- * Emit `crossdeck.contract_failed` with the canonical property
3713
- * shape (`contract_id`, `sdk_version`, `sdk_platform`,
3714
- * `failure_reason`, `run_context`, `run_id`). Goes through the
3715
- * standard track() pipeline — same consent gate, same queue,
3716
- * same ingest, no new endpoint.
3717
- *
3718
- * Wire the call from a test hook, dogfood failure path, or
3719
- * customer contract-verification harness; see
3720
- * `contracts/README.md` for the per-test-framework hook recipes.
3721
- */
3722
- reportContractFailure(input) {
3723
- const props = {
3724
- contract_id: input.contractId,
3725
- sdk_version: SDK_VERSION,
3726
- sdk_platform: "web",
3727
- failure_reason: input.failureReason,
3728
- run_context: input.runContext,
3729
- run_id: input.runId
3730
- };
3731
- if (input.testRef) {
3732
- props.test_file = input.testRef.file;
3733
- props.test_name = input.testRef.name;
3734
- }
3735
- if (input.extra) {
3736
- for (const [k, v] of Object.entries(input.extra)) {
3737
- if (props[k] === void 0) props[k] = v;
3738
- }
3739
- }
3740
- this.track("crossdeck.contract_failed", props);
3741
- }
3742
3372
  track(name, properties) {
3743
3373
  const s = this.requireStarted();
3744
3374
  if (!name) {
@@ -3875,24 +3505,11 @@ var CrossdeckClient = class {
3875
3505
  });
3876
3506
  }
3877
3507
  const rail = input.rail ?? "apple";
3878
- const body = { ...input, rail };
3879
- const idempotencyKey = deriveIdempotencyKeyForPurchase(body);
3880
3508
  const result = await s.http.request("POST", "/purchases/sync", {
3881
- body,
3882
- idempotencyKey
3509
+ body: { ...input, rail }
3883
3510
  });
3884
3511
  s.identity.setCrossdeckCustomerId(result.crossdeckCustomerId);
3885
3512
  s.entitlements.setFromList(result.entitlements);
3886
- try {
3887
- const sourceProductId = result.entitlements[0]?.source.productId;
3888
- const sourceSubscriptionId = result.entitlements[0]?.source.subscriptionId;
3889
- const props = { rail };
3890
- if (sourceProductId) props.productId = sourceProductId;
3891
- if (sourceSubscriptionId) props.subscriptionId = sourceSubscriptionId;
3892
- if (result.idempotent_replay) props.idempotent_replay = true;
3893
- this.track("purchase.completed", props);
3894
- } catch {
3895
- }
3896
3513
  s.debug.emit(
3897
3514
  "sdk.purchase_evidence_sent",
3898
3515
  "StoreKit transaction forwarded. Waiting for backend verification.",
@@ -3948,7 +3565,7 @@ var CrossdeckClient = class {
3948
3565
  }
3949
3566
  this.state.autoTracker?.uninstall();
3950
3567
  this.state.identity.reset();
3951
- this.state.entitlements.clearAll();
3568
+ this.state.entitlements.clear();
3952
3569
  this.state.events.reset();
3953
3570
  this.state.superProps.clear();
3954
3571
  this.state.breadcrumbs.clear();
@@ -4223,551 +3840,16 @@ var CROSSDECK_ERROR_CODES = Object.freeze([
4223
3840
  description: "The server returned a 2xx with an unparseable body.",
4224
3841
  resolution: "Likely a transient backend bug. Retry; if it persists, contact support with the requestId.",
4225
3842
  retryable: true
4226
- },
4227
- // ----- Backend-emitted codes (v1.4.0 Phase 6.2 backfill) -----
4228
- // Mirror of backend/src/api/v1-errors.ts ApiErrorCode. A developer
4229
- // hitting any of these on the wire can look them up via
4230
- // getErrorCode(code) for a canonical remediation step instead of
4231
- // hunting through Slack history.
4232
- {
4233
- code: "missing_api_key",
4234
- type: "authentication_error",
4235
- description: "No Authorization header (or Crossdeck-Api-Key header) on the request.",
4236
- 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.",
4237
- retryable: false
4238
- },
4239
- {
4240
- code: "invalid_api_key",
4241
- type: "authentication_error",
4242
- description: "The API key is malformed, unknown, or doesn't resolve to a project.",
4243
- 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.",
4244
- retryable: false
4245
- },
4246
- {
4247
- code: "key_revoked",
4248
- type: "authentication_error",
4249
- description: "The API key was revoked in the Crossdeck dashboard.",
4250
- 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.",
4251
- retryable: false
4252
- },
4253
- {
4254
- code: "identity_token_invalid",
4255
- type: "authentication_error",
4256
- description: "The Firebase / Apple / Google ID token supplied with the request didn't verify against the dashboard's configured signers.",
4257
- 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.",
4258
- retryable: true
4259
- },
4260
- {
4261
- code: "origin_not_allowed",
4262
- type: "permission_error",
4263
- description: "The Origin header isn't in the project's Allowed origins list.",
4264
- resolution: "Add the origin (e.g. https://app.example.com) under dashboard \u2192 Settings \u2192 Allowed origins. Wildcards like https://*.example.com are supported.",
4265
- retryable: false
4266
- },
4267
- {
4268
- code: "bundle_id_not_allowed",
4269
- type: "permission_error",
4270
- description: "The iOS bundle ID sent via X-Crossdeck-Bundle-Id isn't registered under this app's Apple identity lock.",
4271
- resolution: "Add the bundle ID under dashboard \u2192 Apps \u2192 <your app> \u2192 iOS bundle IDs.",
4272
- retryable: false
4273
- },
4274
- {
4275
- code: "package_name_not_allowed",
4276
- type: "permission_error",
4277
- description: "The Android package name sent via X-Crossdeck-Package-Name isn't registered under this app's Android identity lock.",
4278
- resolution: "Add the package name under dashboard \u2192 Apps \u2192 <your app> \u2192 Android package names.",
4279
- retryable: false
4280
- },
4281
- {
4282
- code: "env_mismatch",
4283
- type: "permission_error",
4284
- description: "The request env (inferred from key prefix) doesn't match the resolved app's configured env.",
4285
- 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.",
4286
- retryable: false
4287
- },
4288
- {
4289
- code: "idempotency_key_in_use",
4290
- type: "invalid_request_error",
4291
- description: "An Idempotency-Key was reused for a request with a different body (Stripe-grade contract).",
4292
- 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.",
4293
- retryable: false
4294
- },
4295
- {
4296
- code: "rate_limited",
4297
- type: "rate_limit_error",
4298
- description: "Request rate exceeded the project's per-second cap.",
4299
- 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.",
4300
- retryable: true
4301
- },
4302
- {
4303
- code: "internal_error",
4304
- type: "internal_error",
4305
- description: "Server-side issue. Safe to retry with backoff.",
4306
- resolution: "The SDK retries automatically. If your code paths through to this error, contact support with the requestId from the response envelope.",
4307
- retryable: true
4308
- },
4309
- {
4310
- code: "google_not_supported",
4311
- type: "invalid_request_error",
4312
- description: "POST /purchases/sync with rail=google is gated until the Play Developer API reconciliation worker ships.",
4313
- resolution: "Until v1.5+, Google Play purchases verify via Real-time Developer Notifications. The SDK auto-track path handles this transparently for Android consumers.",
4314
- retryable: false
4315
- },
4316
- {
4317
- code: "stripe_not_supported",
4318
- type: "invalid_request_error",
4319
- description: "POST /purchases/sync with rail=stripe is unsupported \u2014 Stripe Checkout's redirect flow uses platform webhooks instead.",
4320
- resolution: "Wire Stripe via the standard Checkout / Customer Portal flow; Crossdeck reconciles via the platform webhook automatically. No SDK call needed.",
4321
- retryable: false
4322
- },
4323
- {
4324
- code: "missing_required_param",
4325
- type: "invalid_request_error",
4326
- description: "A required field is absent from the request body.",
4327
- 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.",
4328
- retryable: false
4329
- },
4330
- {
4331
- code: "invalid_param_value",
4332
- type: "invalid_request_error",
4333
- description: "A field is present but the value failed validation (wrong shape, wrong length, wrong enum value).",
4334
- resolution: "Read error.message for the specific field + reason. SDK-managed call sites should never emit this \u2014 file a bug if you do.",
4335
- retryable: false
4336
3843
  }
4337
3844
  ]);
4338
3845
  function getErrorCode(code) {
4339
3846
  return CROSSDECK_ERROR_CODES.find((e) => e.code === code);
4340
3847
  }
4341
-
4342
- // src/_contracts-bundled.ts
4343
- var BUNDLED_IN = "@cross-deck/web@1.5.0";
4344
- var SDK_VERSION2 = "1.5.0";
4345
- var BUNDLED_CONTRACTS = Object.freeze([
4346
- {
4347
- "id": "error-envelope-shape",
4348
- "pillar": "errors",
4349
- "status": "enforced",
4350
- "claim": "Every v1 REST endpoint returns errors in a Stripe-shape envelope: `{ error: { type, code, message, request_id } }` where `type` is one of authentication_error / permission_error / invalid_request_error / rate_limit_error / internal_error (the wire vocabulary in backend/src/api/v1-errors.ts ApiErrorType). HTTP status parity: invalid_request_error \u2192 400, authentication_error \u2192 401, permission_error \u2192 403, rate_limit_error \u2192 429, internal_error \u2192 500. SDK-side clients parse this shape via `crossdeckErrorFromResponse` (Web/Node/RN) / `crossdeckErrorFrom(response:)` (Swift) / `crossdeckErrorFromResponse` (Android) and surface the request_id verbatim so support traces are end-to-end joinable. Firebase callable endpoints (managed-keys / dashboard auth) use the Firebase HttpsError envelope instead \u2014 this contract applies to REST /v1/* only.",
4351
- "appliesTo": [
4352
- "web",
4353
- "node",
4354
- "react-native",
4355
- "swift",
4356
- "android",
4357
- "backend"
4358
- ],
4359
- "codeRef": [
4360
- "backend/src/api/v1-errors.ts",
4361
- "sdks/web/src/errors.ts",
4362
- "sdks/node/src/errors.ts",
4363
- "sdks/react-native/src/errors.ts",
4364
- "sdks/swift/Sources/Crossdeck/Errors.swift",
4365
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Errors.kt"
4366
- ],
4367
- "testRef": [
4368
- {
4369
- "file": "sdks/swift/Tests/CrossdeckTests/ErrorsTests.swift",
4370
- "name": "test_errorEnvelope_fallsBackOnGarbageBody"
4371
- },
4372
- {
4373
- "file": "sdks/swift/Tests/CrossdeckTests/ErrorsTests.swift",
4374
- "name": "test_errorEnvelope_reads_XRequestId_fallback"
4375
- },
4376
- {
4377
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/ErrorTypeWireVocabTest.kt",
4378
- "name": "backend 500 response parses to INTERNAL_ERROR"
4379
- }
4380
- ],
4381
- "registeredAt": "2026-05-26",
4382
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 8 (codifies existing contract)",
4383
- "bundledIn": "@cross-deck/web@1.5.0"
4384
- },
4385
- {
4386
- "id": "flush-interval-parity",
4387
- "pillar": "analytics",
4388
- "status": "enforced",
4389
- "claim": "Every Crossdeck SDK defaults its event-queue flush interval to 2000ms \u2014 the Stripe-adjacent industry norm. Pre-v1.4.0 the defaults disagreed (Web/Node 1500ms; RN/Swift/Android 5000ms), so cross-platform funnels saw events landing at different cadences. Per-instance override stays \u2014 call sites can still tune it freely.",
4390
- "appliesTo": [
4391
- "web",
4392
- "node",
4393
- "react-native",
4394
- "swift",
4395
- "android"
4396
- ],
4397
- "codeRef": [
4398
- "sdks/web/src/crossdeck.ts",
4399
- "sdks/node/src/crossdeck-server.ts",
4400
- "sdks/react-native/src/crossdeck.ts",
4401
- "sdks/swift/Sources/Crossdeck/EventQueue.swift",
4402
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EventQueue.kt"
4403
- ],
4404
- "testRef": [
4405
- {
4406
- "file": "sdks/swift/Sources/Crossdeck/EventQueue.swift",
4407
- "name": "flushIntervalMs: Int = 2_000"
4408
- },
4409
- {
4410
- "file": "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EventQueue.kt",
4411
- "name": "flushIntervalMs: Long = 2_000L"
4412
- },
4413
- {
4414
- "file": "sdks/web/src/crossdeck.ts",
4415
- "name": "options.eventFlushIntervalMs ?? 2000"
4416
- },
4417
- {
4418
- "file": "sdks/node/src/crossdeck-server.ts",
4419
- "name": "options.eventFlushIntervalMs ?? 2000"
4420
- },
4421
- {
4422
- "file": "sdks/react-native/src/crossdeck.ts",
4423
- "name": "options.eventFlushIntervalMs ?? 2000"
4424
- }
4425
- ],
4426
- "registeredAt": "2026-05-26",
4427
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 3.3",
4428
- "bundledIn": "@cross-deck/web@1.5.0"
4429
- },
4430
- {
4431
- "id": "idempotency-key-deterministic",
4432
- "pillar": "revenue",
4433
- "status": "enforced",
4434
- "claim": "syncPurchases() on every SDK derives a deterministic Idempotency-Key from the request body (UUID-shaped SHA-256 of `crossdeck:purchases/sync:<rail>:<jws|token>`). Same input -> same key. Backend short-circuits same-key-same-body retries by returning the cached response (status + body) with `idempotent_replay: true` flag in the body AND `Idempotent-Replayed: true` response header. Same-key-different-body returns 400 `idempotency_key_in_use`. 24-hour TTL matches Stripe. Cache only stores 2xx responses \u2014 4xx/5xx pass through so callers can fix bugs and retry. Helper returns nil/throws on missing identifier (no silent random fallback). Cross-SDK parity is CI-pinned: deriveForPurchase('apple', 'eyJ.jws.sig') MUST equal 'a66b1640-efaf-bb4d-1261-6650033bf111' on every SDK.",
4435
- "appliesTo": [
4436
- "web",
4437
- "node",
4438
- "react-native",
4439
- "swift",
4440
- "android",
4441
- "backend"
4442
- ],
4443
- "codeRef": [
4444
- "sdks/web/src/idempotency-key.ts",
4445
- "sdks/web/src/crossdeck.ts",
4446
- "sdks/react-native/src/idempotency-key.ts",
4447
- "sdks/react-native/src/crossdeck.ts",
4448
- "sdks/node/src/idempotency-key.ts",
4449
- "sdks/node/src/crossdeck-server.ts",
4450
- "sdks/swift/Sources/Crossdeck/IdempotencyKey.swift",
4451
- "sdks/swift/Sources/Crossdeck/Crossdeck.swift",
4452
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/IdempotencyKey.kt",
4453
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt",
4454
- "backend/src/lib/idempotency-response-cache.ts",
4455
- "backend/src/api/v1-purchases.ts"
4456
- ],
4457
- "testRef": [
4458
- {
4459
- "file": "sdks/web/tests/idempotency-key.test.ts",
4460
- "name": "cross-SDK oracle \u2014 apple JWS pins canonical vector"
4461
- },
4462
- {
4463
- "file": "sdks/web/tests/idempotency-key.test.ts",
4464
- "name": "is deterministic: same body twice -> identical key"
4465
- },
4466
- {
4467
- "file": "sdks/web/tests/idempotency-key.test.ts",
4468
- "name": "same identifier under different rails -> different keys"
4469
- },
4470
- {
4471
- "file": "sdks/web/tests/idempotency-key.test.ts",
4472
- "name": "never silently falls back to a random key on missing identifier"
4473
- },
4474
- {
4475
- "file": "sdks/react-native/tests/idempotency-key.test.ts",
4476
- "name": "is deterministic"
4477
- },
4478
- {
4479
- "file": "sdks/react-native/tests/idempotency-key.test.ts",
4480
- "name": "cross-SDK oracle \u2014 apple JWS pins canonical vector"
4481
- },
4482
- {
4483
- "file": "sdks/node/tests/idempotency-key.test.ts",
4484
- "name": "is deterministic"
4485
- },
4486
- {
4487
- "file": "sdks/node/tests/idempotency-key.test.ts",
4488
- "name": "rail namespacing prevents cross-rail collisions"
4489
- },
4490
- {
4491
- "file": "sdks/node/tests/idempotency-key.test.ts",
4492
- "name": "apple JWS produces the canonical pinned UUID across all 5 SDKs"
4493
- },
4494
- {
4495
- "file": "backend/tests/unit/idempotency-response-cache.test.ts",
4496
- "name": "is deterministic for the same input"
4497
- },
4498
- {
4499
- "file": "backend/tests/unit/idempotency-response-cache.test.ts",
4500
- "name": "injects idempotent_replay: true into a JSON object body"
4501
- },
4502
- {
4503
- "file": "backend/tests/unit/idempotency-response-cache.test.ts",
4504
- "name": "matches Stripe's 24-hour idempotency window"
4505
- },
4506
- {
4507
- "file": "sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",
4508
- "name": "test_crossSdkOracle_appleJWS"
4509
- },
4510
- {
4511
- "file": "sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",
4512
- "name": "test_railNamespacing_preventsCrossRailCollisions"
4513
- },
4514
- {
4515
- "file": "sdks/swift/Tests/CrossdeckTests/IdempotencyKeyTests.swift",
4516
- "name": "test_missingIdentifier_returnsNil"
4517
- },
4518
- {
4519
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",
4520
- "name": "cross-SDK oracle for apple JWS"
4521
- },
4522
- {
4523
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",
4524
- "name": "rail namespacing prevents cross-rail collisions"
4525
- },
4526
- {
4527
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/IdempotencyKeyTest.kt",
4528
- "name": "missing identifier returns null - never silent random fallback"
4529
- }
4530
- ],
4531
- "registeredAt": "2026-05-26",
4532
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 2.2.a + 2.2.b + 2.2.c",
4533
- "bundledIn": "@cross-deck/web@1.5.0"
4534
- },
4535
- {
4536
- "id": "init-reentry-drains-prior-queue",
4537
- "pillar": "lifecycle",
4538
- "status": "enforced",
4539
- "claim": "Web + RN init() re-entry drains the prior EventQueue's pending setTimeout BEFORE replacing this.state. Pre-v1.4.0 the teardown handled autoTracker/webVitals/errors/unloadFlush but NOT events, so the prior queue's timer would fire AFTER the state swap \u2014 sending old-init events against new-init http + identity references (cross-identity leak during HMR / config swap / multi-tenant SDK shells). The teardown CANNOT call persistent.clear() \u2014 the durable queue belongs to the SDK lifetime, not the init() lifetime, and a survived crash mid-flush re-hydrates on the next init.",
4540
- "appliesTo": [
4541
- "web",
4542
- "react-native"
4543
- ],
4544
- "codeRef": [
4545
- "sdks/web/src/crossdeck.ts",
4546
- "sdks/react-native/src/crossdeck.ts"
4547
- ],
4548
- "testRef": [
4549
- {
4550
- "file": "sdks/web/tests/init-reentry.test.ts",
4551
- "name": "re-init drains the prior queue's pending timer before swapping state"
4552
- },
4553
- {
4554
- "file": "sdks/web/tests/init-reentry.test.ts",
4555
- "name": "re-init does NOT wipe the durable event store"
4556
- }
4557
- ],
4558
- "registeredAt": "2026-05-26",
4559
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 5.5",
4560
- "bundledIn": "@cross-deck/web@1.5.0"
4561
- },
4562
- {
4563
- "id": "per-user-cache-isolation",
4564
- "pillar": "entitlements",
4565
- "status": "enforced",
4566
- "claim": "Every identify(userId) switches the entitlement cache to a physically separate per-user storage slot \u2014 `crossdeck:entitlements:<sha256(userId)>` \u2014 and unconditionally wipes the in-memory snapshot. A user-switch on a shared device CANNOT cross-read a prior user's cached entitlements, even if the in-memory clear is somehow skipped, because the storage keys are physically separate. reset() wipes every per-user slot via the persisted index.",
4567
- "appliesTo": [
4568
- "web",
4569
- "react-native",
4570
- "swift",
4571
- "android"
4572
- ],
4573
- "codeRef": [
4574
- "sdks/web/src/entitlement-cache.ts",
4575
- "sdks/web/src/hash.ts",
4576
- "sdks/web/src/crossdeck.ts",
4577
- "sdks/react-native/src/entitlement-cache.ts",
4578
- "sdks/react-native/src/hash.ts",
4579
- "sdks/react-native/src/crossdeck.ts",
4580
- "sdks/swift/Sources/Crossdeck/EntitlementCache.swift",
4581
- "sdks/swift/Sources/Crossdeck/IdempotencyKey.swift",
4582
- "sdks/swift/Sources/Crossdeck/Crossdeck.swift",
4583
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/EntitlementCache.kt",
4584
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/IdempotencyKey.kt",
4585
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt"
4586
- ],
4587
- "testRef": [
4588
- {
4589
- "file": "sdks/web/tests/entitlement-cache-isolation.test.ts",
4590
- "name": "identify(B) makes A's entitlements unreachable from in-memory"
4591
- },
4592
- {
4593
- "file": "sdks/web/tests/entitlement-cache-isolation.test.ts",
4594
- "name": "clearAll() removes every per-user storage key plus the index"
4595
- },
4596
- {
4597
- "file": "sdks/web/tests/entitlement-cache-isolation.test.ts",
4598
- "name": "a second cache instance reading A's storage suffix CANNOT see B's data"
4599
- },
4600
- {
4601
- "file": "sdks/react-native/tests/entitlement-cache-isolation.test.ts",
4602
- "name": "identify(B) makes A's entitlements unreachable from in-memory"
4603
- },
4604
- {
4605
- "file": "sdks/react-native/tests/entitlement-cache-isolation.test.ts",
4606
- "name": "removes every per-user storage key plus the index"
4607
- },
4608
- {
4609
- "file": "sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",
4610
- "name": "test_identifyB_makesAEntitlementsUnreachable"
4611
- },
4612
- {
4613
- "file": "sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",
4614
- "name": "test_identifiedWritesLandUnderPerUserSha256Key"
4615
- },
4616
- {
4617
- "file": "sdks/swift/Tests/CrossdeckTests/EntitlementCacheIsolationTests.swift",
4618
- "name": "test_clearAll_removesEveryPerUserStorageKeyPlusIndex"
4619
- },
4620
- {
4621
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",
4622
- "name": "identified writes land under per-user sha256 key"
4623
- },
4624
- {
4625
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",
4626
- "name": "identify B makes A entitlements unreachable from in-memory"
4627
- },
4628
- {
4629
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",
4630
- "name": "clearAll removes every per-user storage key plus the index"
4631
- },
4632
- {
4633
- "file": "sdks/android/crossdeck/src/test/kotlin/com/crossdeck/EntitlementCacheIsolationTest.kt",
4634
- "name": "a fresh cache bound to A's key CANNOT read B's blob"
4635
- }
4636
- ],
4637
- "registeredAt": "2026-05-26",
4638
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 1.3 (web/RN) + dogfood-gap fix (swift + android)",
4639
- "bundledIn": "@cross-deck/web@1.5.0"
4640
- },
4641
- {
4642
- "id": "sdk-error-codes-catalogue",
4643
- "pillar": "errors",
4644
- "status": "enforced",
4645
- "claim": "Web + Node SDK error-codes catalogues include EVERY backend-emitted ApiErrorCode with a description + resolution. Pre-v1.4.0 the catalogues documented codes the SDK threw ITSELF but ZERO backend codes \u2014 a developer hitting `invalid_api_key` / `origin_not_allowed` / `bundle_id_not_allowed` / `env_mismatch` / `idempotency_key_in_use` etc. got `undefined` from getErrorCode() and had to hunt for guidance. v1.4.0 backfills the catalogue from backend/src/api/v1-errors.ts so every wire code has a canonical 'what does this mean / what should I do' answer Stripe-style.",
4646
- "appliesTo": [
4647
- "web",
4648
- "node"
4649
- ],
4650
- "codeRef": [
4651
- "sdks/web/src/error-codes.ts",
4652
- "sdks/node/src/error-codes.ts",
4653
- "backend/src/api/v1-errors.ts"
4654
- ],
4655
- "testRef": [
4656
- {
4657
- "file": "sdks/web/tests/error-codes-backfill.test.ts",
4658
- "name": "includes backend code"
4659
- },
4660
- {
4661
- "file": "sdks/web/tests/error-codes-backfill.test.ts",
4662
- "name": "invalid_api_key resolution points at the dashboard"
4663
- },
4664
- {
4665
- "file": "sdks/web/tests/error-codes-backfill.test.ts",
4666
- "name": "idempotency_key_in_use resolution mentions Stripe-grade contract"
4667
- },
4668
- {
4669
- "file": "sdks/web/tests/error-codes-backfill.test.ts",
4670
- "name": "identity-lock codes carry permission_error type"
4671
- },
4672
- {
4673
- "file": "sdks/web/tests/error-codes-backfill.test.ts",
4674
- "name": "no entry has an empty description or resolution"
4675
- }
4676
- ],
4677
- "registeredAt": "2026-05-26",
4678
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 6.2",
4679
- "bundledIn": "@cross-deck/web@1.5.0"
4680
- },
4681
- {
4682
- "id": "sync-purchases-funnel-parity",
4683
- "pillar": "analytics",
4684
- "status": "enforced",
4685
- "claim": "Manual syncPurchases() emits a `purchase.completed` analytics event on success across ALL SDKs (Web / Node / RN / Swift / Android). Pre-v1.4.0 only Swift/Android auto-track emitted it \u2014 Web/Node/RN manual calls + Swift/Android manual calls fired ZERO analytics. Schema mirrors the auto-track event name + rail/productId/subscriptionId so cross-platform funnels reconcile on every payment path. When the backend short-circuits via the v1.4.0 idempotency cache, the event also carries `idempotent_replay: true`.",
4686
- "appliesTo": [
4687
- "web",
4688
- "node",
4689
- "react-native",
4690
- "swift",
4691
- "android"
4692
- ],
4693
- "codeRef": [
4694
- "sdks/web/src/crossdeck.ts",
4695
- "sdks/node/src/crossdeck-server.ts",
4696
- "sdks/react-native/src/crossdeck.ts",
4697
- "sdks/swift/Sources/Crossdeck/Crossdeck.swift",
4698
- "sdks/android/crossdeck/src/main/kotlin/com/crossdeck/Crossdeck.kt"
4699
- ],
4700
- "testRef": [
4701
- {
4702
- "file": "sdks/web/tests/sync-purchases-funnel.test.ts",
4703
- "name": "emits purchase.completed after a successful sync"
4704
- },
4705
- {
4706
- "file": "sdks/web/tests/sync-purchases-funnel.test.ts",
4707
- "name": "carries idempotent_replay=true when backend replied from cache"
4708
- }
4709
- ],
4710
- "registeredAt": "2026-05-26",
4711
- "firstRegisteredIn": "bank-grade reconciliation v1.4.0 \u2014 phase 3.5",
4712
- "bundledIn": "@cross-deck/web@1.5.0"
4713
- }
4714
- ]);
4715
-
4716
- // src/contracts.ts
4717
- var CrossdeckContracts = {
4718
- /** Every contract that applies to this SDK and is currently enforced. */
4719
- all() {
4720
- return BUNDLED_CONTRACTS.filter((c) => c.status === "enforced");
4721
- },
4722
- /**
4723
- * Every contract bundled with this SDK release, including
4724
- * `proposed` and `retired` entries. Use `all()` for the
4725
- * enforced-only view.
4726
- */
4727
- allIncludingHistorical() {
4728
- return BUNDLED_CONTRACTS;
4729
- },
4730
- /** Look up a contract by its stable `id`. */
4731
- byId(id) {
4732
- return BUNDLED_CONTRACTS.find((c) => c.id === id);
4733
- },
4734
- /** Every enforced contract within a pillar. */
4735
- byPillar(pillar) {
4736
- return BUNDLED_CONTRACTS.filter(
4737
- (c) => c.pillar === pillar && c.status === "enforced"
4738
- );
4739
- },
4740
- /** Filter by lifecycle status. */
4741
- withStatus(status) {
4742
- return BUNDLED_CONTRACTS.filter((c) => c.status === status);
4743
- },
4744
- /** Semver of the SDK release these contracts were bundled with. */
4745
- sdkVersion: SDK_VERSION2,
4746
- /** Fully-qualified bundle identifier — e.g. `@cross-deck/web@1.4.2`. */
4747
- bundledIn: BUNDLED_IN,
4748
- /**
4749
- * Resolve a failing test back to the contract it exercises.
4750
- * Used by test-framework hooks (Vitest `afterEach`, XCTest
4751
- * observation, JUnit `TestWatcher`) to find the contract id of
4752
- * a failed contract test so `reportContractFailure(...)` can
4753
- * stamp the right `contract_id` on the emitted event.
4754
- *
4755
- * Match is on `testRef.name` (case-sensitive, exact). Returns
4756
- * the first contract whose `testRef` list contains a matching
4757
- * entry, regardless of pillar or status.
4758
- */
4759
- findByTestName(name) {
4760
- return BUNDLED_CONTRACTS.find(
4761
- (c) => c.testRef.some((ref) => ref.name === name)
4762
- );
4763
- }
4764
- };
4765
3848
  // Annotate the CommonJS export names for ESM import in node:
4766
3849
  0 && (module.exports = {
4767
3850
  CROSSDECK_ERROR_CODES,
4768
3851
  Crossdeck,
4769
3852
  CrossdeckClient,
4770
- CrossdeckContracts,
4771
3853
  CrossdeckError,
4772
3854
  DEFAULT_BASE_URL,
4773
3855
  MemoryStorage,