@sparkvault/sdk-js 8.14.0 → 8.15.0
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/README.md +2 -0
- package/dist/index.d.ts +21 -2
- package/dist/products/identity/index.d.ts +13 -2
- package/dist/products/identity/types.d.ts +8 -0
- package/dist/sparkvault.cjs.js +133 -17
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +133 -17
- 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
|
@@ -862,6 +862,12 @@ function buildSigninUrl(config, options, extras) {
|
|
|
862
862
|
params.set('mode', 'simple');
|
|
863
863
|
params.set('session', authContext.simpleMode.sessionId);
|
|
864
864
|
}
|
|
865
|
+
// `prompt` is validated here, the single serialization point: only the exact
|
|
866
|
+
// literal reaches the sign-in page; anything else is silently dropped, so a
|
|
867
|
+
// plain-JS caller passing junk degrades to the default behavior.
|
|
868
|
+
if (options.prompt === 'select_account') {
|
|
869
|
+
params.set('prompt', 'select_account');
|
|
870
|
+
}
|
|
865
871
|
if (extras) {
|
|
866
872
|
params.set('redirect_uri', extras.redirectUri);
|
|
867
873
|
params.set('state', extras.state);
|
|
@@ -8562,17 +8568,67 @@ const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
|
8562
8568
|
// listener but not sessionStorage) is what lets the next load self-heal.
|
|
8563
8569
|
const PENDING_KEY = 'sv_signin_pending';
|
|
8564
8570
|
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
8565
|
-
|
|
8566
|
-
|
|
8571
|
+
// One-shot: the identifier the recovery bounce is re-minting for. Written only
|
|
8572
|
+
// by the recovery bounce; the return leg consumes it to verify the redeemed
|
|
8573
|
+
// result is for that same account (see consumeHandoffFragment).
|
|
8574
|
+
const RECOVERY_HINT_KEY = 'sv_recovery_hint';
|
|
8575
|
+
/**
|
|
8576
|
+
* Normalize an identifier for equality, mirroring the server: trim, and
|
|
8577
|
+
* lowercase emails (a value containing '@'). Phones compare trimmed-exact.
|
|
8578
|
+
*/
|
|
8579
|
+
function normalizeIdentity(value) {
|
|
8580
|
+
const trimmed = value.trim();
|
|
8581
|
+
return trimmed.includes('@') ? trimmed.toLowerCase() : trimmed;
|
|
8582
|
+
}
|
|
8583
|
+
/**
|
|
8584
|
+
* Read and parse the pending marker — JSON `{ at, hint }`, where `hint` is the
|
|
8585
|
+
* email or phone the sign-in was started with (null when the flow collects the
|
|
8586
|
+
* identifier itself). A bare-timestamp value is accepted as `{ at, hint: null }`:
|
|
8587
|
+
* markers live at most 10 minutes in sessionStorage, so any such value
|
|
8588
|
+
* disappears within one deploy window of this parser going live — the fallback
|
|
8589
|
+
* is bounded and never grows. Anything unreadable yields null.
|
|
8590
|
+
*/
|
|
8591
|
+
function readPendingMarker() {
|
|
8567
8592
|
let raw = null;
|
|
8568
8593
|
try {
|
|
8569
8594
|
raw = sessionStorage.getItem(PENDING_KEY);
|
|
8570
8595
|
}
|
|
8571
8596
|
catch {
|
|
8572
|
-
return
|
|
8597
|
+
return null;
|
|
8598
|
+
}
|
|
8599
|
+
if (!raw) {
|
|
8600
|
+
return null;
|
|
8573
8601
|
}
|
|
8574
|
-
|
|
8575
|
-
|
|
8602
|
+
let at = NaN;
|
|
8603
|
+
let hint = null;
|
|
8604
|
+
try {
|
|
8605
|
+
const parsed = JSON.parse(raw);
|
|
8606
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
8607
|
+
const marker = parsed;
|
|
8608
|
+
if (typeof marker.at === 'number') {
|
|
8609
|
+
at = marker.at;
|
|
8610
|
+
}
|
|
8611
|
+
if (typeof marker.hint === 'string' && marker.hint) {
|
|
8612
|
+
hint = marker.hint;
|
|
8613
|
+
}
|
|
8614
|
+
}
|
|
8615
|
+
else if (typeof parsed === 'number') {
|
|
8616
|
+
// A bare timestamp parses as a JSON number.
|
|
8617
|
+
at = parsed;
|
|
8618
|
+
}
|
|
8619
|
+
}
|
|
8620
|
+
catch {
|
|
8621
|
+
at = Number(raw);
|
|
8622
|
+
}
|
|
8623
|
+
return Number.isFinite(at) ? { at, hint } : null;
|
|
8624
|
+
}
|
|
8625
|
+
/** True while a marker is within the self-heal TTL. */
|
|
8626
|
+
function isFreshPendingMarker(marker) {
|
|
8627
|
+
return marker !== null && Date.now() - marker.at < PENDING_TTL_MS;
|
|
8628
|
+
}
|
|
8629
|
+
/** True when the pending marker is present and still within its TTL. */
|
|
8630
|
+
function hasFreshPendingMarker() {
|
|
8631
|
+
return isFreshPendingMarker(readPendingMarker());
|
|
8576
8632
|
}
|
|
8577
8633
|
/**
|
|
8578
8634
|
* Whether `handleRedirectResult()` has anything to do on this load — a returned
|
|
@@ -8842,7 +8898,8 @@ class IdentityModule {
|
|
|
8842
8898
|
// the backgrounded opener tab, killing the postMessage listener),
|
|
8843
8899
|
// handleRedirectResult() can silently self-heal on the next load from
|
|
8844
8900
|
// the SSO session the popup login established.
|
|
8845
|
-
|
|
8901
|
+
const pendingHint = mergedOptions.email || mergedOptions.phone || null;
|
|
8902
|
+
this.markSignInPending(pendingHint);
|
|
8846
8903
|
this.launcher = new DialogLauncher(this.config, this.api, mergedOptions, {
|
|
8847
8904
|
onSuccess: (result) => { this.clearSignInPending(); hostCallbacks.onSuccess(result); },
|
|
8848
8905
|
onError: (error) => { this.clearSignInPending(); hostCallbacks.onError(error); },
|
|
@@ -8851,7 +8908,7 @@ class IdentityModule {
|
|
|
8851
8908
|
// no-result end retires the marker (no spurious bounce on a reload
|
|
8852
8909
|
// while the retry alert is up); "Try again" re-arms it.
|
|
8853
8910
|
onPopupClosedUnresolved: () => this.clearSignInPending(),
|
|
8854
|
-
onPopupReopened: () => this.markSignInPending(),
|
|
8911
|
+
onPopupReopened: () => this.markSignInPending(pendingHint),
|
|
8855
8912
|
// COOP-severed popup: postMessage can never deliver, so switch this tab
|
|
8856
8913
|
// to the redirect flow (returns via handleRedirectResult). The pending
|
|
8857
8914
|
// marker stays armed — the returned #sv_code fragment retires it.
|
|
@@ -8889,6 +8946,7 @@ class IdentityModule {
|
|
|
8889
8946
|
email: options.email,
|
|
8890
8947
|
phone: options.phone,
|
|
8891
8948
|
authContext: options.authContext,
|
|
8949
|
+
prompt: options.prompt,
|
|
8892
8950
|
onSuccess: options.onSuccess,
|
|
8893
8951
|
onError: options.onError,
|
|
8894
8952
|
onCancel: options.onCancel,
|
|
@@ -9004,8 +9062,9 @@ class IdentityModule {
|
|
|
9004
9062
|
}
|
|
9005
9063
|
// No returned result. If a sign-in was in flight and its result never
|
|
9006
9064
|
// arrived, self-heal once from the SSO session (mobile opener-tab discard).
|
|
9007
|
-
|
|
9008
|
-
|
|
9065
|
+
const pending = this.consumeSignInPending();
|
|
9066
|
+
if (pending.fresh) {
|
|
9067
|
+
await this.startRecoveryBounce(pending.hint);
|
|
9009
9068
|
}
|
|
9010
9069
|
return null;
|
|
9011
9070
|
}
|
|
@@ -9022,9 +9081,11 @@ class IdentityModule {
|
|
|
9022
9081
|
// (and a StrictMode double-invocation finds an empty hash and no-ops).
|
|
9023
9082
|
let expectedState = null;
|
|
9024
9083
|
let codeVerifier = null;
|
|
9084
|
+
let expectedRecoveryIdentity = null;
|
|
9025
9085
|
try {
|
|
9026
9086
|
expectedState = sessionStorage.getItem('sv_oauth_state');
|
|
9027
9087
|
codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
|
|
9088
|
+
expectedRecoveryIdentity = sessionStorage.getItem(RECOVERY_HINT_KEY);
|
|
9028
9089
|
this.clearOneShotAuthState();
|
|
9029
9090
|
}
|
|
9030
9091
|
catch {
|
|
@@ -9054,6 +9115,18 @@ class IdentityModule {
|
|
|
9054
9115
|
sessionId: raw.session_id ?? undefined,
|
|
9055
9116
|
refreshToken: raw.refresh_token ?? undefined,
|
|
9056
9117
|
};
|
|
9118
|
+
// A recovery bounce carries the identifier the interrupted sign-in was
|
|
9119
|
+
// addressing, but /sso treats a hint matching no hub session like no hint
|
|
9120
|
+
// at all (anti-oracle) — so the bounce can come back holding a DIFFERENT
|
|
9121
|
+
// single-eligible account. The client is the one place that knows which
|
|
9122
|
+
// account the person was signing in to: a mismatched result is discarded,
|
|
9123
|
+
// never handed to the host (a wrong-account handoff). Silent — no
|
|
9124
|
+
// onError — falling through to interactive sign-in, matching the recovery
|
|
9125
|
+
// flow's non-oracle posture.
|
|
9126
|
+
if (expectedRecoveryIdentity &&
|
|
9127
|
+
normalizeIdentity(expectedRecoveryIdentity) !== normalizeIdentity(result.identity)) {
|
|
9128
|
+
return null;
|
|
9129
|
+
}
|
|
9057
9130
|
options.onSuccess?.(result);
|
|
9058
9131
|
return result;
|
|
9059
9132
|
}
|
|
@@ -9072,11 +9145,41 @@ class IdentityModule {
|
|
|
9072
9145
|
* so a hostile/degraded environment simply never recovers rather than
|
|
9073
9146
|
* erroring.
|
|
9074
9147
|
*/
|
|
9075
|
-
async startRecoveryBounce() {
|
|
9076
|
-
const
|
|
9148
|
+
async startRecoveryBounce(loginHint) {
|
|
9149
|
+
const sso = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/sso`);
|
|
9150
|
+
// With several hub sessions, login_hint tells /sso which account the
|
|
9151
|
+
// interrupted sign-in was addressing, so recovery never re-mints another.
|
|
9152
|
+
// Also stash it one-shot: a hint matching no hub session deliberately
|
|
9153
|
+
// behaves server-side like no hint at all (anti-oracle), so the return leg
|
|
9154
|
+
// must verify the redeemed identity is the one this sign-in was for.
|
|
9155
|
+
try {
|
|
9156
|
+
if (loginHint) {
|
|
9157
|
+
sessionStorage.setItem(RECOVERY_HINT_KEY, loginHint);
|
|
9158
|
+
}
|
|
9159
|
+
else {
|
|
9160
|
+
sessionStorage.removeItem(RECOVERY_HINT_KEY);
|
|
9161
|
+
}
|
|
9162
|
+
}
|
|
9163
|
+
catch {
|
|
9164
|
+
// No storage → prepareHandoffNavigation bails below; nothing to verify.
|
|
9165
|
+
}
|
|
9166
|
+
if (loginHint) {
|
|
9167
|
+
sso.searchParams.set('login_hint', loginHint);
|
|
9168
|
+
}
|
|
9169
|
+
const nav = await this.prepareHandoffNavigation(sso.toString());
|
|
9077
9170
|
if (nav) {
|
|
9078
9171
|
window.location.assign(nav);
|
|
9079
9172
|
}
|
|
9173
|
+
else {
|
|
9174
|
+
// The bounce never left (no storage or WebCrypto) — retire the stash so
|
|
9175
|
+
// it cannot linger into an unrelated later return leg.
|
|
9176
|
+
try {
|
|
9177
|
+
sessionStorage.removeItem(RECOVERY_HINT_KEY);
|
|
9178
|
+
}
|
|
9179
|
+
catch {
|
|
9180
|
+
// Storage disabled: nothing was persisted, nothing to clear.
|
|
9181
|
+
}
|
|
9182
|
+
}
|
|
9080
9183
|
}
|
|
9081
9184
|
/**
|
|
9082
9185
|
* Explicit `flow: 'redirect'` — navigate this tab to the interactive sign-in
|
|
@@ -9136,9 +9239,16 @@ class IdentityModule {
|
|
|
9136
9239
|
url.searchParams.set('code_challenge', codeChallenge);
|
|
9137
9240
|
return url.toString();
|
|
9138
9241
|
}
|
|
9139
|
-
|
|
9242
|
+
/**
|
|
9243
|
+
* Arm the self-heal marker for an in-flight sign-in. `hint` is the identifier
|
|
9244
|
+
* (email or phone) the sign-in was started with, when the caller supplied
|
|
9245
|
+
* one — the recovery bounce forwards it as the /sso `login_hint`, so with
|
|
9246
|
+
* several hub sessions recovery re-mints the account this sign-in was for,
|
|
9247
|
+
* never a different one.
|
|
9248
|
+
*/
|
|
9249
|
+
markSignInPending(hint) {
|
|
9140
9250
|
try {
|
|
9141
|
-
sessionStorage.setItem(PENDING_KEY,
|
|
9251
|
+
sessionStorage.setItem(PENDING_KEY, JSON.stringify({ at: Date.now(), hint }));
|
|
9142
9252
|
}
|
|
9143
9253
|
catch {
|
|
9144
9254
|
// No storage → no self-heal; the popup still delivers when it can.
|
|
@@ -9152,11 +9262,16 @@ class IdentityModule {
|
|
|
9152
9262
|
// Nothing to clear.
|
|
9153
9263
|
}
|
|
9154
9264
|
}
|
|
9155
|
-
/**
|
|
9265
|
+
/**
|
|
9266
|
+
* Consume the pending marker: `fresh` is true once (then cleared) if a recent
|
|
9267
|
+
* sign-in is still awaiting its result; `hint` is the identifier that sign-in
|
|
9268
|
+
* carried, for the recovery bounce's `login_hint`.
|
|
9269
|
+
*/
|
|
9156
9270
|
consumeSignInPending() {
|
|
9157
|
-
const
|
|
9271
|
+
const marker = readPendingMarker();
|
|
9272
|
+
const fresh = isFreshPendingMarker(marker);
|
|
9158
9273
|
this.clearSignInPending();
|
|
9159
|
-
return fresh;
|
|
9274
|
+
return { fresh, hint: fresh ? marker.hint : null };
|
|
9160
9275
|
}
|
|
9161
9276
|
/** Remove the result fragment from the URL bar (and history entry). */
|
|
9162
9277
|
clearUrlFragment() {
|
|
@@ -9164,11 +9279,12 @@ class IdentityModule {
|
|
|
9164
9279
|
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
9165
9280
|
}
|
|
9166
9281
|
}
|
|
9167
|
-
/** Drop the one-shot PKCE state/verifier a
|
|
9282
|
+
/** Drop the one-shot PKCE state/verifier (+ recovery hint) a bounce staged. */
|
|
9168
9283
|
clearOneShotAuthState() {
|
|
9169
9284
|
try {
|
|
9170
9285
|
sessionStorage.removeItem('sv_oauth_state');
|
|
9171
9286
|
sessionStorage.removeItem('sv_pkce_verifier');
|
|
9287
|
+
sessionStorage.removeItem(RECOVERY_HINT_KEY);
|
|
9172
9288
|
}
|
|
9173
9289
|
catch {
|
|
9174
9290
|
// Storage disabled: nothing was persisted, nothing to clear.
|