@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/errors.d.ts
CHANGED
|
@@ -51,3 +51,14 @@ export declare class UserCancelledError extends SparkVaultError {
|
|
|
51
51
|
export declare class PopupBlockedError extends SparkVaultError {
|
|
52
52
|
constructor();
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* The popup opened but its window handle went dead before the page ever
|
|
56
|
+
* pinged back — the signature of a Cross-Origin-Opener-Policy severance
|
|
57
|
+
* (a host page serving `COOP: same-origin` detaches any cross-origin popup:
|
|
58
|
+
* the popup loses `window.opener`, the opener's handle reports `closed`).
|
|
59
|
+
* postMessage can never work in this state, so retrying the popup is futile;
|
|
60
|
+
* callers should fall back to the redirect flow.
|
|
61
|
+
*/
|
|
62
|
+
export declare class PopupSeveredError extends SparkVaultError {
|
|
63
|
+
constructor();
|
|
64
|
+
}
|
|
@@ -38,6 +38,13 @@ interface LauncherCallbacks {
|
|
|
38
38
|
onPopupClosedUnresolved?: () => void;
|
|
39
39
|
/** "Try again" opened a fresh popup: a sign-in is in flight again, re-arm. */
|
|
40
40
|
onPopupReopened?: () => void;
|
|
41
|
+
/**
|
|
42
|
+
* The popup's handle was severed (COOP) — postMessage can never deliver, so
|
|
43
|
+
* a retry popup is futile. The owner should switch this tab to the redirect
|
|
44
|
+
* flow; resolve `true` when the navigation started (this page is unloading),
|
|
45
|
+
* `false` to fall back to the retry alert (e.g. no session storage).
|
|
46
|
+
*/
|
|
47
|
+
onPopupSevered?: () => Promise<boolean>;
|
|
41
48
|
}
|
|
42
49
|
/**
|
|
43
50
|
* Opens the sign-in popup for dialog-mode `verify()` and bridges its result
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -91,6 +91,21 @@ class PopupBlockedError extends SparkVaultError {
|
|
|
91
91
|
Object.setPrototypeOf(this, PopupBlockedError.prototype);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* The popup opened but its window handle went dead before the page ever
|
|
96
|
+
* pinged back — the signature of a Cross-Origin-Opener-Policy severance
|
|
97
|
+
* (a host page serving `COOP: same-origin` detaches any cross-origin popup:
|
|
98
|
+
* the popup loses `window.opener`, the opener's handle reports `closed`).
|
|
99
|
+
* postMessage can never work in this state, so retrying the popup is futile;
|
|
100
|
+
* callers should fall back to the redirect flow.
|
|
101
|
+
*/
|
|
102
|
+
class PopupSeveredError extends SparkVaultError {
|
|
103
|
+
constructor() {
|
|
104
|
+
super('The sign-in window could not communicate with this page.', 'popup_severed');
|
|
105
|
+
this.name = 'PopupSeveredError';
|
|
106
|
+
Object.setPrototypeOf(this, PopupSeveredError.prototype);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
94
109
|
|
|
95
110
|
/**
|
|
96
111
|
* SparkVault-owned domain registry.
|
|
@@ -1483,6 +1498,16 @@ const DEFAULT_HEIGHT = 640;
|
|
|
1483
1498
|
const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
1484
1499
|
/** How often to check whether the user closed the popup manually. */
|
|
1485
1500
|
const CLOSED_POLL_INTERVAL_MS = 500;
|
|
1501
|
+
/**
|
|
1502
|
+
* Window after opening within which `popup.closed === true` with NO ready ping
|
|
1503
|
+
* is read as a severed handle, not a manual close. A COOP-severed handle
|
|
1504
|
+
* (host page serves `Cross-Origin-Opener-Policy: same-origin`) flips to
|
|
1505
|
+
* `closed` on the first poll while the real window stays open in front of the
|
|
1506
|
+
* user; a human closing a window they asked for takes longer than this. A slow
|
|
1507
|
+
* network can only delay the ready ping — it never makes `closed` true — so a
|
|
1508
|
+
* legitimate popup on a slow connection cannot trip this.
|
|
1509
|
+
*/
|
|
1510
|
+
const SEVERED_DETECT_WINDOW_MS = 2500;
|
|
1486
1511
|
/**
|
|
1487
1512
|
* Open a popup and resolve with the first validated result envelope it posts.
|
|
1488
1513
|
*
|
|
@@ -1508,7 +1533,9 @@ class PopupLauncher {
|
|
|
1508
1533
|
return;
|
|
1509
1534
|
}
|
|
1510
1535
|
options.onOpen?.(popup);
|
|
1536
|
+
const openedAt = Date.now();
|
|
1511
1537
|
let settled = false;
|
|
1538
|
+
let readyReceived = false;
|
|
1512
1539
|
const cleanup = () => {
|
|
1513
1540
|
window.removeEventListener('message', handleMessage);
|
|
1514
1541
|
clearTimeout(timeoutId);
|
|
@@ -1523,6 +1550,7 @@ class PopupLauncher {
|
|
|
1523
1550
|
const data = event.data;
|
|
1524
1551
|
// A "ready" ping confirms the window loaded; notify but don't settle.
|
|
1525
1552
|
if (options.readyType && data?.type === options.readyType) {
|
|
1553
|
+
readyReceived = true;
|
|
1526
1554
|
options.onReady?.();
|
|
1527
1555
|
return;
|
|
1528
1556
|
}
|
|
@@ -1546,6 +1574,14 @@ class PopupLauncher {
|
|
|
1546
1574
|
if (popup.closed && !settled) {
|
|
1547
1575
|
settled = true;
|
|
1548
1576
|
cleanup();
|
|
1577
|
+
// `closed` going true right after open, before the page ever pinged,
|
|
1578
|
+
// is a dead handle (COOP severance — see SEVERED_DETECT_WINDOW_MS),
|
|
1579
|
+
// not a person closing the window: the real window is still open but
|
|
1580
|
+
// can never postMessage back, so retrying the popup can never work.
|
|
1581
|
+
if (!readyReceived && Date.now() - openedAt <= SEVERED_DETECT_WINDOW_MS) {
|
|
1582
|
+
reject(new PopupSeveredError());
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1549
1585
|
reject(new UserCancelledError('Authentication was cancelled.'));
|
|
1550
1586
|
}
|
|
1551
1587
|
}, CLOSED_POLL_INTERVAL_MS);
|
|
@@ -8066,12 +8102,35 @@ class DialogLauncher {
|
|
|
8066
8102
|
handleError(error) {
|
|
8067
8103
|
if (this.settled)
|
|
8068
8104
|
return;
|
|
8105
|
+
// Severed handle (COOP: same-origin on the host page): the popup is open in
|
|
8106
|
+
// front of the person and working, but postMessage can never deliver and a
|
|
8107
|
+
// retry popup severs identically — the ONLY flow that can complete is the
|
|
8108
|
+
// redirect flow, so switch to it. When the owner can't arm the redirect
|
|
8109
|
+
// return leg it resolves false and we degrade to the retry alert.
|
|
8110
|
+
if (error instanceof PopupSeveredError && this.callbacks.onPopupSevered) {
|
|
8111
|
+
this.callbacks.onPopupSevered().then((navigating) => {
|
|
8112
|
+
if (this.settled)
|
|
8113
|
+
return;
|
|
8114
|
+
if (!navigating) {
|
|
8115
|
+
this.callbacks.onPopupClosedUnresolved?.();
|
|
8116
|
+
this.showAlert();
|
|
8117
|
+
}
|
|
8118
|
+
// Navigating: this page is unloading into the redirect flow; keep the
|
|
8119
|
+
// bridge up (mirrors flow:'redirect', whose promise never settles here).
|
|
8120
|
+
}).catch(() => {
|
|
8121
|
+
if (this.settled)
|
|
8122
|
+
return;
|
|
8123
|
+
this.callbacks.onPopupClosedUnresolved?.();
|
|
8124
|
+
this.showAlert();
|
|
8125
|
+
});
|
|
8126
|
+
return;
|
|
8127
|
+
}
|
|
8069
8128
|
// Blocked (never opened) or closed (gone) - the popup can't be confirmed,
|
|
8070
8129
|
// so surface the warning so the user can reopen it. Either way the opener
|
|
8071
8130
|
// observed the end with no result, so there is nothing for the next-load
|
|
8072
8131
|
// self-heal to recover (a late success message still wins: this branch
|
|
8073
8132
|
// leaves the flow unsettled, and onSuccess re-clears regardless).
|
|
8074
|
-
if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
|
|
8133
|
+
if (error instanceof PopupBlockedError || error instanceof UserCancelledError || error instanceof PopupSeveredError) {
|
|
8075
8134
|
this.callbacks.onPopupClosedUnresolved?.();
|
|
8076
8135
|
this.showAlert();
|
|
8077
8136
|
return;
|
|
@@ -8779,6 +8838,10 @@ class IdentityModule {
|
|
|
8779
8838
|
// while the retry alert is up); "Try again" re-arms it.
|
|
8780
8839
|
onPopupClosedUnresolved: () => this.clearSignInPending(),
|
|
8781
8840
|
onPopupReopened: () => this.markSignInPending(),
|
|
8841
|
+
// COOP-severed popup: postMessage can never deliver, so switch this tab
|
|
8842
|
+
// to the redirect flow (returns via handleRedirectResult). The pending
|
|
8843
|
+
// marker stays armed — the returned #sv_code fragment retires it.
|
|
8844
|
+
onPopupSevered: () => this.startRedirectFlow(mergedOptions),
|
|
8782
8845
|
});
|
|
8783
8846
|
this.launcher.start();
|
|
8784
8847
|
return settledPromise;
|