@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.mjs CHANGED
@@ -67,7 +67,7 @@ function typeMapForStatus(status) {
67
67
  }
68
68
 
69
69
  // src/_version.ts
70
- var SDK_VERSION = "1.6.1";
70
+ var SDK_VERSION = "1.6.2";
71
71
  var SDK_NAME = "@cross-deck/web";
72
72
 
73
73
  // src/http.ts
@@ -1492,6 +1492,13 @@ var AutoTracker = class {
1492
1492
  markActivity() {
1493
1493
  if (!this.session) return;
1494
1494
  const now = Date.now();
1495
+ if (now - this.session.lastActivityAt >= SESSION_RESUME_THRESHOLD_MS) {
1496
+ this.pageviewId = null;
1497
+ this.session = this.startNewSession();
1498
+ this.persistSession();
1499
+ this.emitSessionStart();
1500
+ return;
1501
+ }
1495
1502
  this.session.lastActivityAt = now;
1496
1503
  if (now - this.lastPersistAt >= ACTIVITY_PERSIST_THROTTLE_MS) {
1497
1504
  this.persistSession();
@@ -1545,7 +1552,6 @@ var AutoTracker = class {
1545
1552
  } else if (doc2.visibilityState === "visible") {
1546
1553
  const idleFor = Date.now() - this.session.lastActivityAt;
1547
1554
  if (idleFor >= SESSION_RESUME_THRESHOLD_MS) {
1548
- this.emitSessionEnd();
1549
1555
  this.pageviewId = null;
1550
1556
  this.session = this.startNewSession();
1551
1557
  this.persistSession();
@@ -2607,6 +2613,210 @@ function sendDiagnosticTelemetry(payload) {
2607
2613
  }
2608
2614
  }
2609
2615
 
2616
+ // src/error-codes.ts
2617
+ var CROSSDECK_ERROR_CODES = Object.freeze([
2618
+ // ----- Configuration -----
2619
+ {
2620
+ code: "invalid_public_key",
2621
+ type: "configuration_error",
2622
+ description: "The publishable key passed to Crossdeck.init() doesn't start with cd_pub_.",
2623
+ resolution: "Copy the key from your Crossdeck dashboard \u2192 API keys page.",
2624
+ retryable: false
2625
+ },
2626
+ {
2627
+ code: "missing_app_id",
2628
+ type: "configuration_error",
2629
+ description: "Crossdeck.init() was called without an appId.",
2630
+ resolution: "Add appId to your init options \u2014 find it in the dashboard's Apps page.",
2631
+ retryable: false
2632
+ },
2633
+ {
2634
+ code: "invalid_environment",
2635
+ type: "configuration_error",
2636
+ description: "Crossdeck.init() requires environment: 'production' | 'sandbox'.",
2637
+ resolution: 'Pass the literal string "production" or "sandbox" \u2014 no other values are accepted.',
2638
+ retryable: false
2639
+ },
2640
+ {
2641
+ code: "environment_mismatch",
2642
+ type: "configuration_error",
2643
+ description: "The publishable key's env prefix doesn't match the declared environment option.",
2644
+ 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.",
2645
+ retryable: false
2646
+ },
2647
+ {
2648
+ code: "not_initialized",
2649
+ type: "configuration_error",
2650
+ description: "An SDK method was called before Crossdeck.init().",
2651
+ resolution: "Call Crossdeck.init({ appId, publicKey, environment }) once at app startup before any other method.",
2652
+ retryable: false
2653
+ },
2654
+ // ----- Identify / track / purchase argument validation -----
2655
+ {
2656
+ code: "missing_user_id",
2657
+ type: "invalid_request_error",
2658
+ description: "identify() was called with an empty userId.",
2659
+ resolution: "Pass a stable, non-empty user identifier from your auth layer \u2014 never a hardcoded placeholder.",
2660
+ retryable: false
2661
+ },
2662
+ {
2663
+ code: "missing_event_name",
2664
+ type: "invalid_request_error",
2665
+ description: "track() was called without an event name.",
2666
+ resolution: "Pass a non-empty string as the first argument.",
2667
+ retryable: false
2668
+ },
2669
+ {
2670
+ code: "missing_group_type",
2671
+ type: "invalid_request_error",
2672
+ description: "group() was called without a group type.",
2673
+ resolution: 'Pass a non-empty type (e.g. "org", "team") as the first argument.',
2674
+ retryable: false
2675
+ },
2676
+ {
2677
+ code: "missing_signed_transaction_info",
2678
+ type: "invalid_request_error",
2679
+ description: "syncPurchases() was called without StoreKit 2 signed transaction info.",
2680
+ resolution: "Pass the JWS string from Transaction.currentEntitlements / Transaction.updates.",
2681
+ retryable: false
2682
+ },
2683
+ // ----- Network / transport -----
2684
+ {
2685
+ code: "fetch_failed",
2686
+ type: "network_error",
2687
+ description: "The underlying fetch() call failed (typically a network outage or DNS issue).",
2688
+ resolution: "Check the user's network. The SDK will retry automatically with exponential backoff.",
2689
+ retryable: true
2690
+ },
2691
+ {
2692
+ code: "request_timeout",
2693
+ type: "network_error",
2694
+ description: "A request was aborted after the configured timeoutMs (default 15s).",
2695
+ resolution: "Check the user's connection. Increase timeoutMs in init options if the user is on a known-slow network.",
2696
+ retryable: true
2697
+ },
2698
+ {
2699
+ code: "invalid_json_response",
2700
+ type: "internal_error",
2701
+ description: "The server returned a 2xx with an unparseable body.",
2702
+ resolution: "Likely a transient backend bug. Retry; if it persists, contact support with the requestId.",
2703
+ retryable: true
2704
+ },
2705
+ // ----- Backend-emitted codes (v1.4.0 Phase 6.2 backfill) -----
2706
+ // Mirror of backend/src/api/v1-errors.ts ApiErrorCode. A developer
2707
+ // hitting any of these on the wire can look them up via
2708
+ // getErrorCode(code) for a canonical remediation step instead of
2709
+ // hunting through Slack history.
2710
+ {
2711
+ code: "missing_api_key",
2712
+ type: "authentication_error",
2713
+ description: "No Authorization header (or Crossdeck-Api-Key header) on the request.",
2714
+ 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.",
2715
+ retryable: false
2716
+ },
2717
+ {
2718
+ code: "invalid_api_key",
2719
+ type: "authentication_error",
2720
+ description: "The API key is malformed, unknown, or doesn't resolve to a project.",
2721
+ 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.",
2722
+ retryable: false
2723
+ },
2724
+ {
2725
+ code: "key_revoked",
2726
+ type: "authentication_error",
2727
+ description: "The API key was revoked in the Crossdeck dashboard.",
2728
+ 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.",
2729
+ retryable: false
2730
+ },
2731
+ {
2732
+ code: "identity_token_invalid",
2733
+ type: "authentication_error",
2734
+ description: "The Firebase / Apple / Google ID token supplied with the request didn't verify against the dashboard's configured signers.",
2735
+ 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.",
2736
+ retryable: true
2737
+ },
2738
+ {
2739
+ code: "origin_not_allowed",
2740
+ type: "permission_error",
2741
+ description: "The Origin header isn't in the project's Allowed origins list.",
2742
+ resolution: "Add the origin (e.g. https://app.example.com) under dashboard \u2192 Settings \u2192 Allowed origins. Wildcards like https://*.example.com are supported.",
2743
+ retryable: false
2744
+ },
2745
+ {
2746
+ code: "bundle_id_not_allowed",
2747
+ type: "permission_error",
2748
+ description: "The iOS bundle ID sent via X-Crossdeck-Bundle-Id isn't registered under this app's Apple identity lock.",
2749
+ resolution: "Add the bundle ID under dashboard \u2192 Apps \u2192 <your app> \u2192 iOS bundle IDs.",
2750
+ retryable: false
2751
+ },
2752
+ {
2753
+ code: "package_name_not_allowed",
2754
+ type: "permission_error",
2755
+ description: "The Android package name sent via X-Crossdeck-Package-Name isn't registered under this app's Android identity lock.",
2756
+ resolution: "Add the package name under dashboard \u2192 Apps \u2192 <your app> \u2192 Android package names.",
2757
+ retryable: false
2758
+ },
2759
+ {
2760
+ code: "env_mismatch",
2761
+ type: "permission_error",
2762
+ description: "The request env (inferred from key prefix) doesn't match the resolved app's configured env.",
2763
+ 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.",
2764
+ retryable: false
2765
+ },
2766
+ {
2767
+ code: "idempotency_key_in_use",
2768
+ type: "invalid_request_error",
2769
+ description: "An Idempotency-Key was reused for a request with a different body (Stripe-grade contract).",
2770
+ 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.",
2771
+ retryable: false
2772
+ },
2773
+ {
2774
+ code: "rate_limited",
2775
+ type: "rate_limit_error",
2776
+ description: "Request rate exceeded the project's per-second cap.",
2777
+ 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.",
2778
+ retryable: true
2779
+ },
2780
+ {
2781
+ code: "internal_error",
2782
+ type: "internal_error",
2783
+ description: "Server-side issue. Safe to retry with backoff.",
2784
+ resolution: "The SDK retries automatically. If your code paths through to this error, contact support with the requestId from the response envelope.",
2785
+ retryable: true
2786
+ },
2787
+ {
2788
+ code: "google_not_supported",
2789
+ type: "invalid_request_error",
2790
+ description: "POST /purchases/sync with rail=google is gated until the Play Developer API reconciliation worker ships.",
2791
+ resolution: "Until v1.5+, Google Play purchases verify via Real-time Developer Notifications. The SDK auto-track path handles this transparently for Android consumers.",
2792
+ retryable: false
2793
+ },
2794
+ {
2795
+ code: "stripe_not_supported",
2796
+ type: "invalid_request_error",
2797
+ description: "POST /purchases/sync with rail=stripe is unsupported \u2014 Stripe Checkout's redirect flow uses platform webhooks instead.",
2798
+ resolution: "Wire Stripe via the standard Checkout / Customer Portal flow; Crossdeck reconciles via the platform webhook automatically. No SDK call needed.",
2799
+ retryable: false
2800
+ },
2801
+ {
2802
+ code: "missing_required_param",
2803
+ type: "invalid_request_error",
2804
+ description: "A required field is absent from the request body.",
2805
+ 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.",
2806
+ retryable: false
2807
+ },
2808
+ {
2809
+ code: "invalid_param_value",
2810
+ type: "invalid_request_error",
2811
+ description: "A field is present but the value failed validation (wrong shape, wrong length, wrong enum value).",
2812
+ resolution: "Read error.message for the specific field + reason. SDK-managed call sites should never emit this \u2014 file a bug if you do.",
2813
+ retryable: false
2814
+ }
2815
+ ]);
2816
+ function getErrorCode(code) {
2817
+ return CROSSDECK_ERROR_CODES.find((e) => e.code === code);
2818
+ }
2819
+
2610
2820
  // src/_contract-verifiers.ts
2611
2821
  function buildVerifierContext(opts) {
2612
2822
  return {
@@ -3131,13 +3341,64 @@ var VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK = {
3131
3341
  );
3132
3342
  }
3133
3343
  };
3344
+ var BACKEND_WIRE_CODES = Object.freeze([
3345
+ "missing_api_key",
3346
+ "invalid_api_key",
3347
+ "key_revoked",
3348
+ "identity_token_invalid",
3349
+ "origin_not_allowed",
3350
+ "bundle_id_not_allowed",
3351
+ "package_name_not_allowed",
3352
+ "env_mismatch",
3353
+ "idempotency_key_in_use",
3354
+ "rate_limited",
3355
+ "internal_error",
3356
+ "google_not_supported",
3357
+ "stripe_not_supported",
3358
+ "missing_required_param",
3359
+ "invalid_param_value"
3360
+ ]);
3361
+ var VERIFIER_SDK_ERROR_CODES_CATALOGUE = {
3362
+ contractId: "sdk-error-codes-catalogue",
3363
+ bootTest() {
3364
+ const t0 = nowMs();
3365
+ try {
3366
+ const missing = [];
3367
+ for (const code of BACKEND_WIRE_CODES) {
3368
+ const entry = getErrorCode(code);
3369
+ if (!entry || !entry.description || entry.description.trim().length === 0 || !entry.resolution || entry.resolution.trim().length === 0) {
3370
+ missing.push(code);
3371
+ }
3372
+ }
3373
+ if (missing.length > 0) {
3374
+ return fail(
3375
+ "sdk-error-codes-catalogue",
3376
+ `catalogue missing description+resolution for backend code(s): ${missing.join(", ")}`,
3377
+ nowMs() - t0
3378
+ );
3379
+ }
3380
+ return pass(
3381
+ "sdk-error-codes-catalogue",
3382
+ `all ${BACKEND_WIRE_CODES.length} backend wire codes carry description + resolution`,
3383
+ nowMs() - t0
3384
+ );
3385
+ } catch (err) {
3386
+ return fail(
3387
+ "sdk-error-codes-catalogue",
3388
+ `boot test threw: ${err.message?.slice(0, 80) ?? "unknown error"}`,
3389
+ nowMs() - t0
3390
+ );
3391
+ }
3392
+ }
3393
+ };
3134
3394
  var STATIC_VERIFIERS = Object.freeze([
3135
3395
  VERIFIER_PER_USER_CACHE_ISOLATION,
3136
3396
  VERIFIER_IDEMPOTENCY_KEY_DETERMINISTIC,
3137
3397
  VERIFIER_ERROR_ENVELOPE_SHAPE,
3138
3398
  VERIFIER_FLUSH_INTERVAL_PARITY,
3139
3399
  VERIFIER_SUPER_PROPERTY_MERGE_PRECEDENCE,
3140
- VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK
3400
+ VERIFIER_CONTRACT_FAILED_PAYLOAD_SCHEMA_LOCK,
3401
+ VERIFIER_SDK_ERROR_CODES_CATALOGUE
3141
3402
  ]);
3142
3403
  async function runBootSelfTest(verifiers, reporter, ctx) {
3143
3404
  if (ctx.disableContractAssertions) {