@sparkvault/sdk-js 8.8.0 → 8.8.1

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.
@@ -8374,6 +8374,40 @@ function attachClickHandler(selector, onClick) {
8374
8374
  * sv.products.identity.attach('.login-btn');
8375
8375
  */
8376
8376
  const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
8377
+ // A sign-in is "pending" from popup open until its result arrives; a marker
8378
+ // that outlives a lost result (a mobile opener-tab discard clears the message
8379
+ // listener but not sessionStorage) is what lets the next load self-heal.
8380
+ const PENDING_KEY = 'sv_signin_pending';
8381
+ const PENDING_TTL_MS = 10 * 60 * 1000;
8382
+ /** True when the pending marker is present and still within its TTL. */
8383
+ function hasFreshPendingMarker() {
8384
+ let raw = null;
8385
+ try {
8386
+ raw = sessionStorage.getItem(PENDING_KEY);
8387
+ }
8388
+ catch {
8389
+ return false;
8390
+ }
8391
+ const at = raw ? Number(raw) : NaN;
8392
+ return Number.isFinite(at) && Date.now() - at < PENDING_TTL_MS;
8393
+ }
8394
+ /**
8395
+ * Whether `handleRedirectResult()` has anything to do on this load — a returned
8396
+ * sign-in fragment to consume, or a pending sign-in to self-heal. Public + side
8397
+ * effect-free (peeks, never consumes) so a host that defers SDK init for
8398
+ * performance can cheaply decide whether to boot the SDK on a given page load,
8399
+ * WITHOUT reaching into the SDK's internal storage keys. Exposed as
8400
+ * `SparkVault.isRecoveryPending()`.
8401
+ */
8402
+ function isSignInRecoveryPending() {
8403
+ if (typeof window === 'undefined') {
8404
+ return false;
8405
+ }
8406
+ if (/[#&](sv_code|sv_error|sso)=/.test(window.location.hash || '')) {
8407
+ return true;
8408
+ }
8409
+ return hasFreshPendingMarker();
8410
+ }
8377
8411
  function isTokenClaims(payload) {
8378
8412
  if (typeof payload !== 'object' || payload === null) {
8379
8413
  return false;
@@ -8765,9 +8799,12 @@ class IdentityModule {
8765
8799
  return this.consumeHandoffFragment(params, options);
8766
8800
  }
8767
8801
  // A silent-SSO recovery that found no live session returns `#sso=…`; strip
8768
- // it so the logged-out load is clean, and do not re-bounce (handled below).
8802
+ // it so the logged-out load is clean, retire the one-shot state/verifier the
8803
+ // outbound bounce staged (dead now — no code came back), and do not re-bounce
8804
+ // (handled below).
8769
8805
  if (params.get('sso')) {
8770
8806
  this.clearUrlFragment();
8807
+ this.clearOneShotAuthState();
8771
8808
  }
8772
8809
  // No returned result. If a sign-in was in flight and its result never
8773
8810
  // arrived, self-heal once from the SSO session (mobile opener-tab discard).
@@ -8792,8 +8829,7 @@ class IdentityModule {
8792
8829
  try {
8793
8830
  expectedState = sessionStorage.getItem('sv_oauth_state');
8794
8831
  codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
8795
- sessionStorage.removeItem('sv_oauth_state');
8796
- sessionStorage.removeItem('sv_pkce_verifier');
8832
+ this.clearOneShotAuthState();
8797
8833
  }
8798
8834
  catch {
8799
8835
  // Storage disabled (private mode): state/verifier were never persisted.
@@ -8906,7 +8942,7 @@ class IdentityModule {
8906
8942
  }
8907
8943
  markSignInPending() {
8908
8944
  try {
8909
- sessionStorage.setItem(IdentityModule.PENDING_KEY, String(Date.now()));
8945
+ sessionStorage.setItem(PENDING_KEY, String(Date.now()));
8910
8946
  }
8911
8947
  catch {
8912
8948
  // No storage → no self-heal; the popup still delivers when it can.
@@ -8914,7 +8950,7 @@ class IdentityModule {
8914
8950
  }
8915
8951
  clearSignInPending() {
8916
8952
  try {
8917
- sessionStorage.removeItem(IdentityModule.PENDING_KEY);
8953
+ sessionStorage.removeItem(PENDING_KEY);
8918
8954
  }
8919
8955
  catch {
8920
8956
  // Nothing to clear.
@@ -8922,16 +8958,9 @@ class IdentityModule {
8922
8958
  }
8923
8959
  /** True once (then cleared) if a recent sign-in is still awaiting its result. */
8924
8960
  consumeSignInPending() {
8925
- let raw = null;
8926
- try {
8927
- raw = sessionStorage.getItem(IdentityModule.PENDING_KEY);
8928
- sessionStorage.removeItem(IdentityModule.PENDING_KEY);
8929
- }
8930
- catch {
8931
- return false;
8932
- }
8933
- const at = raw ? Number(raw) : NaN;
8934
- return Number.isFinite(at) && Date.now() - at < IdentityModule.PENDING_TTL_MS;
8961
+ const fresh = hasFreshPendingMarker();
8962
+ this.clearSignInPending();
8963
+ return fresh;
8935
8964
  }
8936
8965
  /** Remove the result fragment from the URL bar (and history entry). */
8937
8966
  clearUrlFragment() {
@@ -8939,6 +8968,16 @@ class IdentityModule {
8939
8968
  window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
8940
8969
  }
8941
8970
  }
8971
+ /** Drop the one-shot PKCE state/verifier a redirect bounce staged. */
8972
+ clearOneShotAuthState() {
8973
+ try {
8974
+ sessionStorage.removeItem('sv_oauth_state');
8975
+ sessionStorage.removeItem('sv_pkce_verifier');
8976
+ }
8977
+ catch {
8978
+ // Storage disabled: nothing was persisted, nothing to clear.
8979
+ }
8980
+ }
8942
8981
  async consumeRedirectResult() {
8943
8982
  if (typeof window === 'undefined' || !window.location.hash) {
8944
8983
  return null;
@@ -9064,11 +9103,6 @@ class IdentityModule {
9064
9103
  return this.runFlow(options);
9065
9104
  }
9066
9105
  }
9067
- // A sign-in is "pending" from popup open until its result arrives; a marker
9068
- // that outlives a lost result (mobile opener-tab discard clears the message
9069
- // listener but not sessionStorage) is what lets the next load self-heal.
9070
- IdentityModule.PENDING_KEY = 'sv_signin_pending';
9071
- IdentityModule.PENDING_TTL_MS = 10 * 60 * 1000;
9072
9106
 
9073
9107
  /**
9074
9108
  * Products Module
@@ -13592,6 +13626,17 @@ class SparkVault {
13592
13626
  static init(config) {
13593
13627
  return new SparkVault(config);
13594
13628
  }
13629
+ /**
13630
+ * Whether a sign-in needs completing on this page load — a returned handoff
13631
+ * fragment, or a popup whose result was lost (a mobile opener-tab discard).
13632
+ * Side effect-free and instance-free, so a host that defers SDK init for
13633
+ * performance can cheaply decide whether to boot the SDK and call
13634
+ * `products.identity.handleRedirectResult()` on a given load, without reaching
13635
+ * into the SDK's internal storage keys.
13636
+ */
13637
+ static isRecoveryPending() {
13638
+ return isSignInRecoveryPending();
13639
+ }
13595
13640
  /** Get the SDK version */
13596
13641
  static get version() {
13597
13642
  return '__VERSION__';