@sparkvault/sdk-js 8.11.3 → 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/index.d.ts +6 -3
- package/dist/products/identity/dialog-launcher.d.ts +7 -0
- package/dist/sparkvault.cjs.js +103 -7
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +103 -7
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/utils/base64url.d.ts +11 -0
- package/dist/vaults/index.d.ts +6 -3
- 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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -968,9 +968,12 @@ declare class VaultsModule {
|
|
|
968
968
|
/**
|
|
969
969
|
* Delete a vault and all its ingots. This action is irreversible!
|
|
970
970
|
*
|
|
971
|
-
* Requires the vault's exact name as confirmation
|
|
972
|
-
* `X-Confirm-Name` header
|
|
973
|
-
* (
|
|
971
|
+
* Requires the vault's exact name as confirmation, matched case-sensitively.
|
|
972
|
+
* The name is sent base64(UTF-8) as the `X-Confirm-Name-B64` header so a vault
|
|
973
|
+
* named with any Unicode (emoji, CJK, the U+202F in macOS-style names) is
|
|
974
|
+
* deletable — an HTTP header value cannot carry non-latin1 characters. The
|
|
975
|
+
* legacy raw `X-Confirm-Name` header is included only for latin1 names, so
|
|
976
|
+
* older API servers keep working.
|
|
974
977
|
*
|
|
975
978
|
* @example
|
|
976
979
|
* await sv.vaults.delete('vlt_abc', 'My Vault');
|
|
@@ -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.
|
|
@@ -718,6 +733,24 @@ function base64urlEncode(data) {
|
|
|
718
733
|
function arrayBufferToBase64url(buffer) {
|
|
719
734
|
return base64urlEncode(new Uint8Array(buffer));
|
|
720
735
|
}
|
|
736
|
+
/**
|
|
737
|
+
* Encode a string as STANDARD base64 (with padding) of its UTF-8 bytes.
|
|
738
|
+
*
|
|
739
|
+
* Unlike base64urlEncode this keeps `+`/`/` and padding, so it round-trips
|
|
740
|
+
* through a server-side standard-base64 decoder. Used to carry arbitrary
|
|
741
|
+
* Unicode through an HTTP header value (which is limited to latin1 bytes).
|
|
742
|
+
*
|
|
743
|
+
* @param value - String to encode
|
|
744
|
+
* @returns Standard base64 string
|
|
745
|
+
*/
|
|
746
|
+
function base64EncodeUtf8(value) {
|
|
747
|
+
const bytes = new TextEncoder().encode(value);
|
|
748
|
+
let binary = '';
|
|
749
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
750
|
+
binary += String.fromCharCode(bytes[i]);
|
|
751
|
+
}
|
|
752
|
+
return btoa(binary);
|
|
753
|
+
}
|
|
721
754
|
/**
|
|
722
755
|
* Decode base64url string to Uint8Array
|
|
723
756
|
*
|
|
@@ -1465,6 +1498,16 @@ const DEFAULT_HEIGHT = 640;
|
|
|
1465
1498
|
const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
1466
1499
|
/** How often to check whether the user closed the popup manually. */
|
|
1467
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;
|
|
1468
1511
|
/**
|
|
1469
1512
|
* Open a popup and resolve with the first validated result envelope it posts.
|
|
1470
1513
|
*
|
|
@@ -1490,7 +1533,9 @@ class PopupLauncher {
|
|
|
1490
1533
|
return;
|
|
1491
1534
|
}
|
|
1492
1535
|
options.onOpen?.(popup);
|
|
1536
|
+
const openedAt = Date.now();
|
|
1493
1537
|
let settled = false;
|
|
1538
|
+
let readyReceived = false;
|
|
1494
1539
|
const cleanup = () => {
|
|
1495
1540
|
window.removeEventListener('message', handleMessage);
|
|
1496
1541
|
clearTimeout(timeoutId);
|
|
@@ -1505,6 +1550,7 @@ class PopupLauncher {
|
|
|
1505
1550
|
const data = event.data;
|
|
1506
1551
|
// A "ready" ping confirms the window loaded; notify but don't settle.
|
|
1507
1552
|
if (options.readyType && data?.type === options.readyType) {
|
|
1553
|
+
readyReceived = true;
|
|
1508
1554
|
options.onReady?.();
|
|
1509
1555
|
return;
|
|
1510
1556
|
}
|
|
@@ -1528,6 +1574,14 @@ class PopupLauncher {
|
|
|
1528
1574
|
if (popup.closed && !settled) {
|
|
1529
1575
|
settled = true;
|
|
1530
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
|
+
}
|
|
1531
1585
|
reject(new UserCancelledError('Authentication was cancelled.'));
|
|
1532
1586
|
}
|
|
1533
1587
|
}, CLOSED_POLL_INTERVAL_MS);
|
|
@@ -8048,12 +8102,35 @@ class DialogLauncher {
|
|
|
8048
8102
|
handleError(error) {
|
|
8049
8103
|
if (this.settled)
|
|
8050
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
|
+
}
|
|
8051
8128
|
// Blocked (never opened) or closed (gone) - the popup can't be confirmed,
|
|
8052
8129
|
// so surface the warning so the user can reopen it. Either way the opener
|
|
8053
8130
|
// observed the end with no result, so there is nothing for the next-load
|
|
8054
8131
|
// self-heal to recover (a late success message still wins: this branch
|
|
8055
8132
|
// leaves the flow unsettled, and onSuccess re-clears regardless).
|
|
8056
|
-
if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
|
|
8133
|
+
if (error instanceof PopupBlockedError || error instanceof UserCancelledError || error instanceof PopupSeveredError) {
|
|
8057
8134
|
this.callbacks.onPopupClosedUnresolved?.();
|
|
8058
8135
|
this.showAlert();
|
|
8059
8136
|
return;
|
|
@@ -8761,6 +8838,10 @@ class IdentityModule {
|
|
|
8761
8838
|
// while the retry alert is up); "Try again" re-arms it.
|
|
8762
8839
|
onPopupClosedUnresolved: () => this.clearSignInPending(),
|
|
8763
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),
|
|
8764
8845
|
});
|
|
8765
8846
|
this.launcher.start();
|
|
8766
8847
|
return settledPromise;
|
|
@@ -12312,6 +12393,14 @@ class VaultUploadModule {
|
|
|
12312
12393
|
* operations live in their own modules; this module owns the vault record,
|
|
12313
12394
|
* its sharing/upload configuration, and the browser upload widget.
|
|
12314
12395
|
*/
|
|
12396
|
+
/** A string every char of which fits in a single header byte (latin1). */
|
|
12397
|
+
function isLatin1(value) {
|
|
12398
|
+
for (let i = 0; i < value.length; i++) {
|
|
12399
|
+
if (value.charCodeAt(i) > 0xff)
|
|
12400
|
+
return false;
|
|
12401
|
+
}
|
|
12402
|
+
return true;
|
|
12403
|
+
}
|
|
12315
12404
|
class VaultsModule {
|
|
12316
12405
|
constructor(config, http) {
|
|
12317
12406
|
this.http = http;
|
|
@@ -12453,9 +12542,12 @@ class VaultsModule {
|
|
|
12453
12542
|
/**
|
|
12454
12543
|
* Delete a vault and all its ingots. This action is irreversible!
|
|
12455
12544
|
*
|
|
12456
|
-
* Requires the vault's exact name as confirmation
|
|
12457
|
-
* `X-Confirm-Name` header
|
|
12458
|
-
* (
|
|
12545
|
+
* Requires the vault's exact name as confirmation, matched case-sensitively.
|
|
12546
|
+
* The name is sent base64(UTF-8) as the `X-Confirm-Name-B64` header so a vault
|
|
12547
|
+
* named with any Unicode (emoji, CJK, the U+202F in macOS-style names) is
|
|
12548
|
+
* deletable — an HTTP header value cannot carry non-latin1 characters. The
|
|
12549
|
+
* legacy raw `X-Confirm-Name` header is included only for latin1 names, so
|
|
12550
|
+
* older API servers keep working.
|
|
12459
12551
|
*
|
|
12460
12552
|
* @example
|
|
12461
12553
|
* await sv.vaults.delete('vlt_abc', 'My Vault');
|
|
@@ -12465,9 +12557,13 @@ class VaultsModule {
|
|
|
12465
12557
|
if (!name) {
|
|
12466
12558
|
throw new ValidationError('Vault name is required to confirm deletion');
|
|
12467
12559
|
}
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
}
|
|
12560
|
+
const headers = {
|
|
12561
|
+
'X-Confirm-Name-B64': base64EncodeUtf8(name),
|
|
12562
|
+
};
|
|
12563
|
+
if (isLatin1(name)) {
|
|
12564
|
+
headers['X-Confirm-Name'] = name;
|
|
12565
|
+
}
|
|
12566
|
+
await this.http.delete(`/v1/vaults/${cleanId}`, { headers });
|
|
12471
12567
|
}
|
|
12472
12568
|
/**
|
|
12473
12569
|
* Get a vault's public-sharing configuration.
|