@sparkvault/sdk-js 8.11.4 → 8.11.5
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/errors.d.ts +11 -0
- package/dist/products/identity/dialog-launcher.d.ts +7 -0
- package/dist/sparkvault.cjs.js +64 -1
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +64 -1
- 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
|
@@ -87,6 +87,21 @@ class PopupBlockedError extends SparkVaultError {
|
|
|
87
87
|
Object.setPrototypeOf(this, PopupBlockedError.prototype);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* The popup opened but its window handle went dead before the page ever
|
|
92
|
+
* pinged back — the signature of a Cross-Origin-Opener-Policy severance
|
|
93
|
+
* (a host page serving `COOP: same-origin` detaches any cross-origin popup:
|
|
94
|
+
* the popup loses `window.opener`, the opener's handle reports `closed`).
|
|
95
|
+
* postMessage can never work in this state, so retrying the popup is futile;
|
|
96
|
+
* callers should fall back to the redirect flow.
|
|
97
|
+
*/
|
|
98
|
+
class PopupSeveredError extends SparkVaultError {
|
|
99
|
+
constructor() {
|
|
100
|
+
super('The sign-in window could not communicate with this page.', 'popup_severed');
|
|
101
|
+
this.name = 'PopupSeveredError';
|
|
102
|
+
Object.setPrototypeOf(this, PopupSeveredError.prototype);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
90
105
|
|
|
91
106
|
/**
|
|
92
107
|
* SparkVault-owned domain registry.
|
|
@@ -1479,6 +1494,16 @@ const DEFAULT_HEIGHT = 640;
|
|
|
1479
1494
|
const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
1480
1495
|
/** How often to check whether the user closed the popup manually. */
|
|
1481
1496
|
const CLOSED_POLL_INTERVAL_MS = 500;
|
|
1497
|
+
/**
|
|
1498
|
+
* Window after opening within which `popup.closed === true` with NO ready ping
|
|
1499
|
+
* is read as a severed handle, not a manual close. A COOP-severed handle
|
|
1500
|
+
* (host page serves `Cross-Origin-Opener-Policy: same-origin`) flips to
|
|
1501
|
+
* `closed` on the first poll while the real window stays open in front of the
|
|
1502
|
+
* user; a human closing a window they asked for takes longer than this. A slow
|
|
1503
|
+
* network can only delay the ready ping — it never makes `closed` true — so a
|
|
1504
|
+
* legitimate popup on a slow connection cannot trip this.
|
|
1505
|
+
*/
|
|
1506
|
+
const SEVERED_DETECT_WINDOW_MS = 2500;
|
|
1482
1507
|
/**
|
|
1483
1508
|
* Open a popup and resolve with the first validated result envelope it posts.
|
|
1484
1509
|
*
|
|
@@ -1504,7 +1529,9 @@ class PopupLauncher {
|
|
|
1504
1529
|
return;
|
|
1505
1530
|
}
|
|
1506
1531
|
options.onOpen?.(popup);
|
|
1532
|
+
const openedAt = Date.now();
|
|
1507
1533
|
let settled = false;
|
|
1534
|
+
let readyReceived = false;
|
|
1508
1535
|
const cleanup = () => {
|
|
1509
1536
|
window.removeEventListener('message', handleMessage);
|
|
1510
1537
|
clearTimeout(timeoutId);
|
|
@@ -1519,6 +1546,7 @@ class PopupLauncher {
|
|
|
1519
1546
|
const data = event.data;
|
|
1520
1547
|
// A "ready" ping confirms the window loaded; notify but don't settle.
|
|
1521
1548
|
if (options.readyType && data?.type === options.readyType) {
|
|
1549
|
+
readyReceived = true;
|
|
1522
1550
|
options.onReady?.();
|
|
1523
1551
|
return;
|
|
1524
1552
|
}
|
|
@@ -1542,6 +1570,14 @@ class PopupLauncher {
|
|
|
1542
1570
|
if (popup.closed && !settled) {
|
|
1543
1571
|
settled = true;
|
|
1544
1572
|
cleanup();
|
|
1573
|
+
// `closed` going true right after open, before the page ever pinged,
|
|
1574
|
+
// is a dead handle (COOP severance — see SEVERED_DETECT_WINDOW_MS),
|
|
1575
|
+
// not a person closing the window: the real window is still open but
|
|
1576
|
+
// can never postMessage back, so retrying the popup can never work.
|
|
1577
|
+
if (!readyReceived && Date.now() - openedAt <= SEVERED_DETECT_WINDOW_MS) {
|
|
1578
|
+
reject(new PopupSeveredError());
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1545
1581
|
reject(new UserCancelledError('Authentication was cancelled.'));
|
|
1546
1582
|
}
|
|
1547
1583
|
}, CLOSED_POLL_INTERVAL_MS);
|
|
@@ -8062,12 +8098,35 @@ class DialogLauncher {
|
|
|
8062
8098
|
handleError(error) {
|
|
8063
8099
|
if (this.settled)
|
|
8064
8100
|
return;
|
|
8101
|
+
// Severed handle (COOP: same-origin on the host page): the popup is open in
|
|
8102
|
+
// front of the person and working, but postMessage can never deliver and a
|
|
8103
|
+
// retry popup severs identically — the ONLY flow that can complete is the
|
|
8104
|
+
// redirect flow, so switch to it. When the owner can't arm the redirect
|
|
8105
|
+
// return leg it resolves false and we degrade to the retry alert.
|
|
8106
|
+
if (error instanceof PopupSeveredError && this.callbacks.onPopupSevered) {
|
|
8107
|
+
this.callbacks.onPopupSevered().then((navigating) => {
|
|
8108
|
+
if (this.settled)
|
|
8109
|
+
return;
|
|
8110
|
+
if (!navigating) {
|
|
8111
|
+
this.callbacks.onPopupClosedUnresolved?.();
|
|
8112
|
+
this.showAlert();
|
|
8113
|
+
}
|
|
8114
|
+
// Navigating: this page is unloading into the redirect flow; keep the
|
|
8115
|
+
// bridge up (mirrors flow:'redirect', whose promise never settles here).
|
|
8116
|
+
}).catch(() => {
|
|
8117
|
+
if (this.settled)
|
|
8118
|
+
return;
|
|
8119
|
+
this.callbacks.onPopupClosedUnresolved?.();
|
|
8120
|
+
this.showAlert();
|
|
8121
|
+
});
|
|
8122
|
+
return;
|
|
8123
|
+
}
|
|
8065
8124
|
// Blocked (never opened) or closed (gone) - the popup can't be confirmed,
|
|
8066
8125
|
// so surface the warning so the user can reopen it. Either way the opener
|
|
8067
8126
|
// observed the end with no result, so there is nothing for the next-load
|
|
8068
8127
|
// self-heal to recover (a late success message still wins: this branch
|
|
8069
8128
|
// leaves the flow unsettled, and onSuccess re-clears regardless).
|
|
8070
|
-
if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
|
|
8129
|
+
if (error instanceof PopupBlockedError || error instanceof UserCancelledError || error instanceof PopupSeveredError) {
|
|
8071
8130
|
this.callbacks.onPopupClosedUnresolved?.();
|
|
8072
8131
|
this.showAlert();
|
|
8073
8132
|
return;
|
|
@@ -8775,6 +8834,10 @@ class IdentityModule {
|
|
|
8775
8834
|
// while the retry alert is up); "Try again" re-arms it.
|
|
8776
8835
|
onPopupClosedUnresolved: () => this.clearSignInPending(),
|
|
8777
8836
|
onPopupReopened: () => this.markSignInPending(),
|
|
8837
|
+
// COOP-severed popup: postMessage can never deliver, so switch this tab
|
|
8838
|
+
// to the redirect flow (returns via handleRedirectResult). The pending
|
|
8839
|
+
// marker stays armed — the returned #sv_code fragment retires it.
|
|
8840
|
+
onPopupSevered: () => this.startRedirectFlow(mergedOptions),
|
|
8778
8841
|
});
|
|
8779
8842
|
this.launcher.start();
|
|
8780
8843
|
return settledPromise;
|