@cross-deck/web 1.6.1 → 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.6.1";
95
+ var SDK_VERSION = "1.6.2";
96
96
  var SDK_NAME = "@cross-deck/web";
97
97
 
98
98
  // src/http.ts
@@ -1517,6 +1517,13 @@ var AutoTracker = class {
1517
1517
  markActivity() {
1518
1518
  if (!this.session) return;
1519
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
+ }
1520
1527
  this.session.lastActivityAt = now;
1521
1528
  if (now - this.lastPersistAt >= ACTIVITY_PERSIST_THROTTLE_MS) {
1522
1529
  this.persistSession();
@@ -1570,7 +1577,6 @@ var AutoTracker = class {
1570
1577
  } else if (doc2.visibilityState === "visible") {
1571
1578
  const idleFor = Date.now() - this.session.lastActivityAt;
1572
1579
  if (idleFor >= SESSION_RESUME_THRESHOLD_MS) {
1573
- this.emitSessionEnd();
1574
1580
  this.pageviewId = null;
1575
1581
  this.session = this.startNewSession();
1576
1582
  this.persistSession();
@@ -2632,6 +2638,210 @@ function sendDiagnosticTelemetry(payload) {
2632
2638
  }
2633
2639
  }
2634
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
+
2635
2845
  // src/_contract-verifiers.ts
2636
2846
  function buildVerifierContext(opts) {
2637
2847
  return {
@@ -3156,13 +3366,64 @@ var VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK = {
3156
3366
  );
3157
3367
  }
3158
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
+ };
3159
3419
  var STATIC_VERIFIERS = Object.freeze([
3160
3420
  VERIFIER_PER_USER_CACHE_ISOLATION,
3161
3421
  VERIFIER_IDEMPOTENCY_KEY_DETERMINISTIC,
3162
3422
  VERIFIER_ERROR_ENVELOPE_SHAPE,
3163
3423
  VERIFIER_FLUSH_INTERVAL_PARITY,
3164
3424
  VERIFIER_SUPER_PROPERTY_MERGE_PRECEDENCE,
3165
- VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK
3425
+ VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK,
3426
+ VERIFIER_SDK_ERROR_CODES_CATALOGUE
3166
3427
  ]);
3167
3428
  async function runBootSelfTest(verifiers, reporter, ctx) {
3168
3429
  if (ctx.disableContractAssertions) {