@sparkvault/sdk-js 8.8.0 → 8.8.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/index.d.ts +11 -2
- package/dist/products/identity/dialog-launcher.d.ts +10 -0
- package/dist/products/identity/index.d.ts +11 -2
- package/dist/sparkvault.cjs.js +76 -21
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +76 -21
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/sparkvault.esm.js
CHANGED
|
@@ -7962,8 +7962,12 @@ class DialogLauncher {
|
|
|
7962
7962
|
if (this.settled)
|
|
7963
7963
|
return;
|
|
7964
7964
|
// Blocked (never opened) or closed (gone) - the popup can't be confirmed,
|
|
7965
|
-
// so surface the warning so the user can reopen it.
|
|
7965
|
+
// so surface the warning so the user can reopen it. Either way the opener
|
|
7966
|
+
// observed the end with no result, so there is nothing for the next-load
|
|
7967
|
+
// self-heal to recover (a late success message still wins: this branch
|
|
7968
|
+
// leaves the flow unsettled, and onSuccess re-clears regardless).
|
|
7966
7969
|
if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
|
|
7970
|
+
this.callbacks.onPopupClosedUnresolved?.();
|
|
7967
7971
|
this.showAlert();
|
|
7968
7972
|
return;
|
|
7969
7973
|
}
|
|
@@ -8018,6 +8022,7 @@ class DialogLauncher {
|
|
|
8018
8022
|
}
|
|
8019
8023
|
/** "Try again": close any current popup and reopen a fresh one. */
|
|
8020
8024
|
retry() {
|
|
8025
|
+
this.callbacks.onPopupReopened?.();
|
|
8021
8026
|
this.hideAlert();
|
|
8022
8027
|
this.closePopup();
|
|
8023
8028
|
this.openPopup();
|
|
@@ -8374,6 +8379,40 @@ function attachClickHandler(selector, onClick) {
|
|
|
8374
8379
|
* sv.products.identity.attach('.login-btn');
|
|
8375
8380
|
*/
|
|
8376
8381
|
const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
8382
|
+
// A sign-in is "pending" from popup open until its result arrives; a marker
|
|
8383
|
+
// that outlives a lost result (a mobile opener-tab discard clears the message
|
|
8384
|
+
// listener but not sessionStorage) is what lets the next load self-heal.
|
|
8385
|
+
const PENDING_KEY = 'sv_signin_pending';
|
|
8386
|
+
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
8387
|
+
/** True when the pending marker is present and still within its TTL. */
|
|
8388
|
+
function hasFreshPendingMarker() {
|
|
8389
|
+
let raw = null;
|
|
8390
|
+
try {
|
|
8391
|
+
raw = sessionStorage.getItem(PENDING_KEY);
|
|
8392
|
+
}
|
|
8393
|
+
catch {
|
|
8394
|
+
return false;
|
|
8395
|
+
}
|
|
8396
|
+
const at = raw ? Number(raw) : NaN;
|
|
8397
|
+
return Number.isFinite(at) && Date.now() - at < PENDING_TTL_MS;
|
|
8398
|
+
}
|
|
8399
|
+
/**
|
|
8400
|
+
* Whether `handleRedirectResult()` has anything to do on this load — a returned
|
|
8401
|
+
* sign-in fragment to consume, or a pending sign-in to self-heal. Public + side
|
|
8402
|
+
* effect-free (peeks, never consumes) so a host that defers SDK init for
|
|
8403
|
+
* performance can cheaply decide whether to boot the SDK on a given page load,
|
|
8404
|
+
* WITHOUT reaching into the SDK's internal storage keys. Exposed as
|
|
8405
|
+
* `SparkVault.isRecoveryPending()`.
|
|
8406
|
+
*/
|
|
8407
|
+
function isSignInRecoveryPending() {
|
|
8408
|
+
if (typeof window === 'undefined') {
|
|
8409
|
+
return false;
|
|
8410
|
+
}
|
|
8411
|
+
if (/[#&](sv_code|sv_error|sso)=/.test(window.location.hash || '')) {
|
|
8412
|
+
return true;
|
|
8413
|
+
}
|
|
8414
|
+
return hasFreshPendingMarker();
|
|
8415
|
+
}
|
|
8377
8416
|
function isTokenClaims(payload) {
|
|
8378
8417
|
if (typeof payload !== 'object' || payload === null) {
|
|
8379
8418
|
return false;
|
|
@@ -8626,6 +8665,11 @@ class IdentityModule {
|
|
|
8626
8665
|
onSuccess: (result) => { this.clearSignInPending(); hostCallbacks.onSuccess(result); },
|
|
8627
8666
|
onError: (error) => { this.clearSignInPending(); hostCallbacks.onError(error); },
|
|
8628
8667
|
onCancel: () => { this.clearSignInPending(); hostCallbacks.onCancel(); },
|
|
8668
|
+
// Self-heal exists for a result the opener never observed. An observed
|
|
8669
|
+
// no-result end retires the marker (no spurious bounce on a reload
|
|
8670
|
+
// while the retry alert is up); "Try again" re-arms it.
|
|
8671
|
+
onPopupClosedUnresolved: () => this.clearSignInPending(),
|
|
8672
|
+
onPopupReopened: () => this.markSignInPending(),
|
|
8629
8673
|
});
|
|
8630
8674
|
this.launcher.start();
|
|
8631
8675
|
return settledPromise;
|
|
@@ -8765,9 +8809,12 @@ class IdentityModule {
|
|
|
8765
8809
|
return this.consumeHandoffFragment(params, options);
|
|
8766
8810
|
}
|
|
8767
8811
|
// A silent-SSO recovery that found no live session returns `#sso=…`; strip
|
|
8768
|
-
// it so the logged-out load is clean,
|
|
8812
|
+
// it so the logged-out load is clean, retire the one-shot state/verifier the
|
|
8813
|
+
// outbound bounce staged (dead now — no code came back), and do not re-bounce
|
|
8814
|
+
// (handled below).
|
|
8769
8815
|
if (params.get('sso')) {
|
|
8770
8816
|
this.clearUrlFragment();
|
|
8817
|
+
this.clearOneShotAuthState();
|
|
8771
8818
|
}
|
|
8772
8819
|
// No returned result. If a sign-in was in flight and its result never
|
|
8773
8820
|
// arrived, self-heal once from the SSO session (mobile opener-tab discard).
|
|
@@ -8792,8 +8839,7 @@ class IdentityModule {
|
|
|
8792
8839
|
try {
|
|
8793
8840
|
expectedState = sessionStorage.getItem('sv_oauth_state');
|
|
8794
8841
|
codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
|
|
8795
|
-
|
|
8796
|
-
sessionStorage.removeItem('sv_pkce_verifier');
|
|
8842
|
+
this.clearOneShotAuthState();
|
|
8797
8843
|
}
|
|
8798
8844
|
catch {
|
|
8799
8845
|
// Storage disabled (private mode): state/verifier were never persisted.
|
|
@@ -8906,7 +8952,7 @@ class IdentityModule {
|
|
|
8906
8952
|
}
|
|
8907
8953
|
markSignInPending() {
|
|
8908
8954
|
try {
|
|
8909
|
-
sessionStorage.setItem(
|
|
8955
|
+
sessionStorage.setItem(PENDING_KEY, String(Date.now()));
|
|
8910
8956
|
}
|
|
8911
8957
|
catch {
|
|
8912
8958
|
// No storage → no self-heal; the popup still delivers when it can.
|
|
@@ -8914,7 +8960,7 @@ class IdentityModule {
|
|
|
8914
8960
|
}
|
|
8915
8961
|
clearSignInPending() {
|
|
8916
8962
|
try {
|
|
8917
|
-
sessionStorage.removeItem(
|
|
8963
|
+
sessionStorage.removeItem(PENDING_KEY);
|
|
8918
8964
|
}
|
|
8919
8965
|
catch {
|
|
8920
8966
|
// Nothing to clear.
|
|
@@ -8922,16 +8968,9 @@ class IdentityModule {
|
|
|
8922
8968
|
}
|
|
8923
8969
|
/** True once (then cleared) if a recent sign-in is still awaiting its result. */
|
|
8924
8970
|
consumeSignInPending() {
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
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;
|
|
8971
|
+
const fresh = hasFreshPendingMarker();
|
|
8972
|
+
this.clearSignInPending();
|
|
8973
|
+
return fresh;
|
|
8935
8974
|
}
|
|
8936
8975
|
/** Remove the result fragment from the URL bar (and history entry). */
|
|
8937
8976
|
clearUrlFragment() {
|
|
@@ -8939,6 +8978,16 @@ class IdentityModule {
|
|
|
8939
8978
|
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
8940
8979
|
}
|
|
8941
8980
|
}
|
|
8981
|
+
/** Drop the one-shot PKCE state/verifier a redirect bounce staged. */
|
|
8982
|
+
clearOneShotAuthState() {
|
|
8983
|
+
try {
|
|
8984
|
+
sessionStorage.removeItem('sv_oauth_state');
|
|
8985
|
+
sessionStorage.removeItem('sv_pkce_verifier');
|
|
8986
|
+
}
|
|
8987
|
+
catch {
|
|
8988
|
+
// Storage disabled: nothing was persisted, nothing to clear.
|
|
8989
|
+
}
|
|
8990
|
+
}
|
|
8942
8991
|
async consumeRedirectResult() {
|
|
8943
8992
|
if (typeof window === 'undefined' || !window.location.hash) {
|
|
8944
8993
|
return null;
|
|
@@ -9064,11 +9113,6 @@ class IdentityModule {
|
|
|
9064
9113
|
return this.runFlow(options);
|
|
9065
9114
|
}
|
|
9066
9115
|
}
|
|
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
9116
|
|
|
9073
9117
|
/**
|
|
9074
9118
|
* Products Module
|
|
@@ -13592,6 +13636,17 @@ class SparkVault {
|
|
|
13592
13636
|
static init(config) {
|
|
13593
13637
|
return new SparkVault(config);
|
|
13594
13638
|
}
|
|
13639
|
+
/**
|
|
13640
|
+
* Whether a sign-in needs completing on this page load — a returned handoff
|
|
13641
|
+
* fragment, or a popup whose result was lost (a mobile opener-tab discard).
|
|
13642
|
+
* Side effect-free and instance-free, so a host that defers SDK init for
|
|
13643
|
+
* performance can cheaply decide whether to boot the SDK and call
|
|
13644
|
+
* `products.identity.handleRedirectResult()` on a given load, without reaching
|
|
13645
|
+
* into the SDK's internal storage keys.
|
|
13646
|
+
*/
|
|
13647
|
+
static isRecoveryPending() {
|
|
13648
|
+
return isSignInRecoveryPending();
|
|
13649
|
+
}
|
|
13595
13650
|
/** Get the SDK version */
|
|
13596
13651
|
static get version() {
|
|
13597
13652
|
return '__VERSION__';
|