@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/index.d.ts
CHANGED
|
@@ -469,14 +469,14 @@ declare class IdentityModule {
|
|
|
469
469
|
* session storage or WebCrypto is unavailable so callers can degrade.
|
|
470
470
|
*/
|
|
471
471
|
private prepareHandoffNavigation;
|
|
472
|
-
private static readonly PENDING_KEY;
|
|
473
|
-
private static readonly PENDING_TTL_MS;
|
|
474
472
|
private markSignInPending;
|
|
475
473
|
private clearSignInPending;
|
|
476
474
|
/** True once (then cleared) if a recent sign-in is still awaiting its result. */
|
|
477
475
|
private consumeSignInPending;
|
|
478
476
|
/** Remove the result fragment from the URL bar (and history entry). */
|
|
479
477
|
private clearUrlFragment;
|
|
478
|
+
/** Drop the one-shot PKCE state/verifier a redirect bounce staged. */
|
|
479
|
+
private clearOneShotAuthState;
|
|
480
480
|
private consumeRedirectResult;
|
|
481
481
|
/**
|
|
482
482
|
* Close the identity dialog/inline UI if open.
|
|
@@ -1909,6 +1909,15 @@ declare class SparkVault {
|
|
|
1909
1909
|
* });
|
|
1910
1910
|
*/
|
|
1911
1911
|
static init(config: SparkVaultConfig): SparkVault;
|
|
1912
|
+
/**
|
|
1913
|
+
* Whether a sign-in needs completing on this page load — a returned handoff
|
|
1914
|
+
* fragment, or a popup whose result was lost (a mobile opener-tab discard).
|
|
1915
|
+
* Side effect-free and instance-free, so a host that defers SDK init for
|
|
1916
|
+
* performance can cheaply decide whether to boot the SDK and call
|
|
1917
|
+
* `products.identity.handleRedirectResult()` on a given load, without reaching
|
|
1918
|
+
* into the SDK's internal storage keys.
|
|
1919
|
+
*/
|
|
1920
|
+
static isRecoveryPending(): boolean;
|
|
1912
1921
|
/** Get the SDK version */
|
|
1913
1922
|
static get version(): string;
|
|
1914
1923
|
}
|
|
@@ -28,6 +28,16 @@ interface LauncherCallbacks {
|
|
|
28
28
|
onSuccess: (result: VerifyResult) => void;
|
|
29
29
|
onError: (error: Error) => void;
|
|
30
30
|
onCancel: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* The opener OBSERVED the popup end with no result (window closed, or it
|
|
33
|
+
* never opened) while the retry alert keeps the flow alive. There is no lost
|
|
34
|
+
* result to self-heal, so the owner retires its pending sign-in marker —
|
|
35
|
+
* without this, a reload while the alert is up fires a spurious recovery
|
|
36
|
+
* bounce. Deliberately NOT onCancel: the flow is unsettled, retry may follow.
|
|
37
|
+
*/
|
|
38
|
+
onPopupClosedUnresolved?: () => void;
|
|
39
|
+
/** "Try again" opened a fresh popup: a sign-in is in flight again, re-arm. */
|
|
40
|
+
onPopupReopened?: () => void;
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
33
43
|
* Opens the sign-in popup for dialog-mode `verify()` and bridges its result
|
|
@@ -12,6 +12,15 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import type { ResolvedConfig } from '../../config';
|
|
14
14
|
import type { VerifyOptions, VerifyResult, SignInOptions, SignInResult, TokenClaims, AttachOptions, PortalUrlOptions, RedirectResultOptions } from './types';
|
|
15
|
+
/**
|
|
16
|
+
* Whether `handleRedirectResult()` has anything to do on this load — a returned
|
|
17
|
+
* sign-in fragment to consume, or a pending sign-in to self-heal. Public + side
|
|
18
|
+
* effect-free (peeks, never consumes) so a host that defers SDK init for
|
|
19
|
+
* performance can cheaply decide whether to boot the SDK on a given page load,
|
|
20
|
+
* WITHOUT reaching into the SDK's internal storage keys. Exposed as
|
|
21
|
+
* `SparkVault.isRecoveryPending()`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isSignInRecoveryPending(): boolean;
|
|
15
24
|
export declare class IdentityModule {
|
|
16
25
|
private readonly config;
|
|
17
26
|
private readonly api;
|
|
@@ -170,14 +179,14 @@ export declare class IdentityModule {
|
|
|
170
179
|
* session storage or WebCrypto is unavailable so callers can degrade.
|
|
171
180
|
*/
|
|
172
181
|
private prepareHandoffNavigation;
|
|
173
|
-
private static readonly PENDING_KEY;
|
|
174
|
-
private static readonly PENDING_TTL_MS;
|
|
175
182
|
private markSignInPending;
|
|
176
183
|
private clearSignInPending;
|
|
177
184
|
/** True once (then cleared) if a recent sign-in is still awaiting its result. */
|
|
178
185
|
private consumeSignInPending;
|
|
179
186
|
/** Remove the result fragment from the URL bar (and history entry). */
|
|
180
187
|
private clearUrlFragment;
|
|
188
|
+
/** Drop the one-shot PKCE state/verifier a redirect bounce staged. */
|
|
189
|
+
private clearOneShotAuthState;
|
|
181
190
|
private consumeRedirectResult;
|
|
182
191
|
/**
|
|
183
192
|
* Close the identity dialog/inline UI if open.
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -7966,8 +7966,12 @@ class DialogLauncher {
|
|
|
7966
7966
|
if (this.settled)
|
|
7967
7967
|
return;
|
|
7968
7968
|
// Blocked (never opened) or closed (gone) - the popup can't be confirmed,
|
|
7969
|
-
// so surface the warning so the user can reopen it.
|
|
7969
|
+
// so surface the warning so the user can reopen it. Either way the opener
|
|
7970
|
+
// observed the end with no result, so there is nothing for the next-load
|
|
7971
|
+
// self-heal to recover (a late success message still wins: this branch
|
|
7972
|
+
// leaves the flow unsettled, and onSuccess re-clears regardless).
|
|
7970
7973
|
if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
|
|
7974
|
+
this.callbacks.onPopupClosedUnresolved?.();
|
|
7971
7975
|
this.showAlert();
|
|
7972
7976
|
return;
|
|
7973
7977
|
}
|
|
@@ -8022,6 +8026,7 @@ class DialogLauncher {
|
|
|
8022
8026
|
}
|
|
8023
8027
|
/** "Try again": close any current popup and reopen a fresh one. */
|
|
8024
8028
|
retry() {
|
|
8029
|
+
this.callbacks.onPopupReopened?.();
|
|
8025
8030
|
this.hideAlert();
|
|
8026
8031
|
this.closePopup();
|
|
8027
8032
|
this.openPopup();
|
|
@@ -8378,6 +8383,40 @@ function attachClickHandler(selector, onClick) {
|
|
|
8378
8383
|
* sv.products.identity.attach('.login-btn');
|
|
8379
8384
|
*/
|
|
8380
8385
|
const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
8386
|
+
// A sign-in is "pending" from popup open until its result arrives; a marker
|
|
8387
|
+
// that outlives a lost result (a mobile opener-tab discard clears the message
|
|
8388
|
+
// listener but not sessionStorage) is what lets the next load self-heal.
|
|
8389
|
+
const PENDING_KEY = 'sv_signin_pending';
|
|
8390
|
+
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
8391
|
+
/** True when the pending marker is present and still within its TTL. */
|
|
8392
|
+
function hasFreshPendingMarker() {
|
|
8393
|
+
let raw = null;
|
|
8394
|
+
try {
|
|
8395
|
+
raw = sessionStorage.getItem(PENDING_KEY);
|
|
8396
|
+
}
|
|
8397
|
+
catch {
|
|
8398
|
+
return false;
|
|
8399
|
+
}
|
|
8400
|
+
const at = raw ? Number(raw) : NaN;
|
|
8401
|
+
return Number.isFinite(at) && Date.now() - at < PENDING_TTL_MS;
|
|
8402
|
+
}
|
|
8403
|
+
/**
|
|
8404
|
+
* Whether `handleRedirectResult()` has anything to do on this load — a returned
|
|
8405
|
+
* sign-in fragment to consume, or a pending sign-in to self-heal. Public + side
|
|
8406
|
+
* effect-free (peeks, never consumes) so a host that defers SDK init for
|
|
8407
|
+
* performance can cheaply decide whether to boot the SDK on a given page load,
|
|
8408
|
+
* WITHOUT reaching into the SDK's internal storage keys. Exposed as
|
|
8409
|
+
* `SparkVault.isRecoveryPending()`.
|
|
8410
|
+
*/
|
|
8411
|
+
function isSignInRecoveryPending() {
|
|
8412
|
+
if (typeof window === 'undefined') {
|
|
8413
|
+
return false;
|
|
8414
|
+
}
|
|
8415
|
+
if (/[#&](sv_code|sv_error|sso)=/.test(window.location.hash || '')) {
|
|
8416
|
+
return true;
|
|
8417
|
+
}
|
|
8418
|
+
return hasFreshPendingMarker();
|
|
8419
|
+
}
|
|
8381
8420
|
function isTokenClaims(payload) {
|
|
8382
8421
|
if (typeof payload !== 'object' || payload === null) {
|
|
8383
8422
|
return false;
|
|
@@ -8630,6 +8669,11 @@ class IdentityModule {
|
|
|
8630
8669
|
onSuccess: (result) => { this.clearSignInPending(); hostCallbacks.onSuccess(result); },
|
|
8631
8670
|
onError: (error) => { this.clearSignInPending(); hostCallbacks.onError(error); },
|
|
8632
8671
|
onCancel: () => { this.clearSignInPending(); hostCallbacks.onCancel(); },
|
|
8672
|
+
// Self-heal exists for a result the opener never observed. An observed
|
|
8673
|
+
// no-result end retires the marker (no spurious bounce on a reload
|
|
8674
|
+
// while the retry alert is up); "Try again" re-arms it.
|
|
8675
|
+
onPopupClosedUnresolved: () => this.clearSignInPending(),
|
|
8676
|
+
onPopupReopened: () => this.markSignInPending(),
|
|
8633
8677
|
});
|
|
8634
8678
|
this.launcher.start();
|
|
8635
8679
|
return settledPromise;
|
|
@@ -8769,9 +8813,12 @@ class IdentityModule {
|
|
|
8769
8813
|
return this.consumeHandoffFragment(params, options);
|
|
8770
8814
|
}
|
|
8771
8815
|
// A silent-SSO recovery that found no live session returns `#sso=…`; strip
|
|
8772
|
-
// it so the logged-out load is clean,
|
|
8816
|
+
// it so the logged-out load is clean, retire the one-shot state/verifier the
|
|
8817
|
+
// outbound bounce staged (dead now — no code came back), and do not re-bounce
|
|
8818
|
+
// (handled below).
|
|
8773
8819
|
if (params.get('sso')) {
|
|
8774
8820
|
this.clearUrlFragment();
|
|
8821
|
+
this.clearOneShotAuthState();
|
|
8775
8822
|
}
|
|
8776
8823
|
// No returned result. If a sign-in was in flight and its result never
|
|
8777
8824
|
// arrived, self-heal once from the SSO session (mobile opener-tab discard).
|
|
@@ -8796,8 +8843,7 @@ class IdentityModule {
|
|
|
8796
8843
|
try {
|
|
8797
8844
|
expectedState = sessionStorage.getItem('sv_oauth_state');
|
|
8798
8845
|
codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
|
|
8799
|
-
|
|
8800
|
-
sessionStorage.removeItem('sv_pkce_verifier');
|
|
8846
|
+
this.clearOneShotAuthState();
|
|
8801
8847
|
}
|
|
8802
8848
|
catch {
|
|
8803
8849
|
// Storage disabled (private mode): state/verifier were never persisted.
|
|
@@ -8910,7 +8956,7 @@ class IdentityModule {
|
|
|
8910
8956
|
}
|
|
8911
8957
|
markSignInPending() {
|
|
8912
8958
|
try {
|
|
8913
|
-
sessionStorage.setItem(
|
|
8959
|
+
sessionStorage.setItem(PENDING_KEY, String(Date.now()));
|
|
8914
8960
|
}
|
|
8915
8961
|
catch {
|
|
8916
8962
|
// No storage → no self-heal; the popup still delivers when it can.
|
|
@@ -8918,7 +8964,7 @@ class IdentityModule {
|
|
|
8918
8964
|
}
|
|
8919
8965
|
clearSignInPending() {
|
|
8920
8966
|
try {
|
|
8921
|
-
sessionStorage.removeItem(
|
|
8967
|
+
sessionStorage.removeItem(PENDING_KEY);
|
|
8922
8968
|
}
|
|
8923
8969
|
catch {
|
|
8924
8970
|
// Nothing to clear.
|
|
@@ -8926,16 +8972,9 @@ class IdentityModule {
|
|
|
8926
8972
|
}
|
|
8927
8973
|
/** True once (then cleared) if a recent sign-in is still awaiting its result. */
|
|
8928
8974
|
consumeSignInPending() {
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
sessionStorage.removeItem(IdentityModule.PENDING_KEY);
|
|
8933
|
-
}
|
|
8934
|
-
catch {
|
|
8935
|
-
return false;
|
|
8936
|
-
}
|
|
8937
|
-
const at = raw ? Number(raw) : NaN;
|
|
8938
|
-
return Number.isFinite(at) && Date.now() - at < IdentityModule.PENDING_TTL_MS;
|
|
8975
|
+
const fresh = hasFreshPendingMarker();
|
|
8976
|
+
this.clearSignInPending();
|
|
8977
|
+
return fresh;
|
|
8939
8978
|
}
|
|
8940
8979
|
/** Remove the result fragment from the URL bar (and history entry). */
|
|
8941
8980
|
clearUrlFragment() {
|
|
@@ -8943,6 +8982,16 @@ class IdentityModule {
|
|
|
8943
8982
|
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
8944
8983
|
}
|
|
8945
8984
|
}
|
|
8985
|
+
/** Drop the one-shot PKCE state/verifier a redirect bounce staged. */
|
|
8986
|
+
clearOneShotAuthState() {
|
|
8987
|
+
try {
|
|
8988
|
+
sessionStorage.removeItem('sv_oauth_state');
|
|
8989
|
+
sessionStorage.removeItem('sv_pkce_verifier');
|
|
8990
|
+
}
|
|
8991
|
+
catch {
|
|
8992
|
+
// Storage disabled: nothing was persisted, nothing to clear.
|
|
8993
|
+
}
|
|
8994
|
+
}
|
|
8946
8995
|
async consumeRedirectResult() {
|
|
8947
8996
|
if (typeof window === 'undefined' || !window.location.hash) {
|
|
8948
8997
|
return null;
|
|
@@ -9068,11 +9117,6 @@ class IdentityModule {
|
|
|
9068
9117
|
return this.runFlow(options);
|
|
9069
9118
|
}
|
|
9070
9119
|
}
|
|
9071
|
-
// A sign-in is "pending" from popup open until its result arrives; a marker
|
|
9072
|
-
// that outlives a lost result (mobile opener-tab discard clears the message
|
|
9073
|
-
// listener but not sessionStorage) is what lets the next load self-heal.
|
|
9074
|
-
IdentityModule.PENDING_KEY = 'sv_signin_pending';
|
|
9075
|
-
IdentityModule.PENDING_TTL_MS = 10 * 60 * 1000;
|
|
9076
9120
|
|
|
9077
9121
|
/**
|
|
9078
9122
|
* Products Module
|
|
@@ -13596,6 +13640,17 @@ class SparkVault {
|
|
|
13596
13640
|
static init(config) {
|
|
13597
13641
|
return new SparkVault(config);
|
|
13598
13642
|
}
|
|
13643
|
+
/**
|
|
13644
|
+
* Whether a sign-in needs completing on this page load — a returned handoff
|
|
13645
|
+
* fragment, or a popup whose result was lost (a mobile opener-tab discard).
|
|
13646
|
+
* Side effect-free and instance-free, so a host that defers SDK init for
|
|
13647
|
+
* performance can cheaply decide whether to boot the SDK and call
|
|
13648
|
+
* `products.identity.handleRedirectResult()` on a given load, without reaching
|
|
13649
|
+
* into the SDK's internal storage keys.
|
|
13650
|
+
*/
|
|
13651
|
+
static isRecoveryPending() {
|
|
13652
|
+
return isSignInRecoveryPending();
|
|
13653
|
+
}
|
|
13599
13654
|
/** Get the SDK version */
|
|
13600
13655
|
static get version() {
|
|
13601
13656
|
return '__VERSION__';
|