@sparkvault/sdk-js 9.2.3 → 9.3.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/dist/index.cjs +59 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +59 -6
- package/dist/index.mjs.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/index.d.ts +5 -1
- package/dist/vaults/upload/api.d.ts +24 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2015,11 +2015,15 @@ declare class VaultsModule {
|
|
|
2015
2015
|
* Unseal a vault to access its contents.
|
|
2016
2016
|
* Returns a short-lived Vault Access Token (VAT).
|
|
2017
2017
|
*
|
|
2018
|
+
* @param vaultId - The vault to unseal.
|
|
2019
|
+
* @param key - The vault's VMK, or a DVAK token issued for it.
|
|
2020
|
+
*
|
|
2018
2021
|
* @example
|
|
2019
2022
|
* const unsealed = await sv.vaults.unseal('vlt_abc', vmk);
|
|
2023
|
+
* const delegated = await sv.vaults.unseal('vlt_abc', 'dvak_...');
|
|
2020
2024
|
* console.log('Token:', unsealed.vatToken);
|
|
2021
2025
|
*/
|
|
2022
|
-
unseal(vaultId: string,
|
|
2026
|
+
unseal(vaultId: string, key: string): Promise<UnsealedVault>;
|
|
2023
2027
|
/**
|
|
2024
2028
|
* List vaults for the account. Results are paginated (server default 100 per
|
|
2025
2029
|
* page, max 500); follow `nextCursor` to fetch subsequent pages.
|
package/dist/index.mjs
CHANGED
|
@@ -10055,6 +10055,15 @@ const FINALIZATION_CHECK = {
|
|
|
10055
10055
|
class UploadApi extends SparkVaultApi {
|
|
10056
10056
|
constructor(config) {
|
|
10057
10057
|
super(config.timeout);
|
|
10058
|
+
/**
|
|
10059
|
+
* Vault upload info by vault id, memoized for the life of this client.
|
|
10060
|
+
*
|
|
10061
|
+
* The client is built once with the SDK and the map dies with the page, so
|
|
10062
|
+
* the memo cannot outlive the page it decorates — which is why there is no
|
|
10063
|
+
* TTL and no invalidation API to get wrong. It deliberately survives
|
|
10064
|
+
* `resetSession()`, alongside the other long-lived per-client state.
|
|
10065
|
+
*/
|
|
10066
|
+
this.vaultInfoMemo = new Map();
|
|
10058
10067
|
this.config = config;
|
|
10059
10068
|
}
|
|
10060
10069
|
makeError(message, code, statusCode, details) {
|
|
@@ -10071,9 +10080,47 @@ class UploadApi extends SparkVaultApi {
|
|
|
10071
10080
|
return { data, status };
|
|
10072
10081
|
}
|
|
10073
10082
|
/**
|
|
10074
|
-
* Get vault upload info (public endpoint).
|
|
10083
|
+
* Get vault upload info (public endpoint), fetched at most once per vault.
|
|
10084
|
+
*
|
|
10085
|
+
* Every widget interaction — `upload()`, `pop()`, `render()`, and each click
|
|
10086
|
+
* an `attach()` handler serves — starts by asking for this, and the answer is
|
|
10087
|
+
* pure display and geometry: the vault's name, its branding, and the size it
|
|
10088
|
+
* advertises. It authorizes nothing. The server re-validates the vault, its
|
|
10089
|
+
* upload source, the request origin, and the file size on the POST that
|
|
10090
|
+
* actually creates the upload, and that re-validation is the correctness
|
|
10091
|
+
* backstop for this whole flow — a memoized answer can never widen what an
|
|
10092
|
+
* upload is allowed to do, and the backstop must stay in place.
|
|
10093
|
+
*
|
|
10094
|
+
* Only a successful answer is kept: a rejection evicts its entry so the next
|
|
10095
|
+
* open retries against the server, and an entry whose request was aborted by
|
|
10096
|
+
* a closing widget is never handed to the widget that replaces it.
|
|
10075
10097
|
*/
|
|
10076
10098
|
async getVaultUploadInfo(vaultId) {
|
|
10099
|
+
const memoized = this.vaultInfoMemo.get(vaultId);
|
|
10100
|
+
if (memoized && !memoized.pendingSignal?.aborted) {
|
|
10101
|
+
return memoized.promise;
|
|
10102
|
+
}
|
|
10103
|
+
const entry = {
|
|
10104
|
+
pendingSignal: this.getAbortSignal(),
|
|
10105
|
+
promise: this.fetchVaultUploadInfo(vaultId),
|
|
10106
|
+
};
|
|
10107
|
+
this.vaultInfoMemo.set(vaultId, entry);
|
|
10108
|
+
try {
|
|
10109
|
+
const config = await entry.promise;
|
|
10110
|
+
entry.pendingSignal = null;
|
|
10111
|
+
return config;
|
|
10112
|
+
}
|
|
10113
|
+
catch (error) {
|
|
10114
|
+
// Identity guard: a widget that reopened while this request was failing
|
|
10115
|
+
// has its own entry in the map, and evicting by key alone would throw
|
|
10116
|
+
// away its in-flight fetch.
|
|
10117
|
+
if (this.vaultInfoMemo.get(vaultId) === entry) {
|
|
10118
|
+
this.vaultInfoMemo.delete(vaultId);
|
|
10119
|
+
}
|
|
10120
|
+
throw error;
|
|
10121
|
+
}
|
|
10122
|
+
}
|
|
10123
|
+
async fetchVaultUploadInfo(vaultId) {
|
|
10077
10124
|
const url = `${this.config.apiBaseUrl}/v1/files/in/${vaultId}`;
|
|
10078
10125
|
const response = await this.request(url, { method: 'GET' });
|
|
10079
10126
|
if (!isVaultUploadInfoResponse(response.data)) {
|
|
@@ -13208,6 +13255,8 @@ class VaultUploadModule {
|
|
|
13208
13255
|
* operations live in their own modules; this module owns the vault record,
|
|
13209
13256
|
* its sharing/upload configuration, and the browser upload widget.
|
|
13210
13257
|
*/
|
|
13258
|
+
/** Marks a Delegated Vault Access Key token apart from a Vault Master Key. */
|
|
13259
|
+
const DVAK_TOKEN_PREFIX = 'dvak_';
|
|
13211
13260
|
/** A string every char of which fits in a single header byte (latin1). */
|
|
13212
13261
|
function isLatin1(value) {
|
|
13213
13262
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -13252,16 +13301,20 @@ class VaultsModule {
|
|
|
13252
13301
|
* Unseal a vault to access its contents.
|
|
13253
13302
|
* Returns a short-lived Vault Access Token (VAT).
|
|
13254
13303
|
*
|
|
13304
|
+
* @param vaultId - The vault to unseal.
|
|
13305
|
+
* @param key - The vault's VMK, or a DVAK token issued for it.
|
|
13306
|
+
*
|
|
13255
13307
|
* @example
|
|
13256
13308
|
* const unsealed = await sv.vaults.unseal('vlt_abc', vmk);
|
|
13309
|
+
* const delegated = await sv.vaults.unseal('vlt_abc', 'dvak_...');
|
|
13257
13310
|
* console.log('Token:', unsealed.vatToken);
|
|
13258
13311
|
*/
|
|
13259
|
-
async unseal(vaultId,
|
|
13312
|
+
async unseal(vaultId, key) {
|
|
13260
13313
|
const cleanId = this.normalizeVaultId(vaultId);
|
|
13261
|
-
if (!
|
|
13262
|
-
throw new ValidationError('VMK is required');
|
|
13314
|
+
if (!key) {
|
|
13315
|
+
throw new ValidationError('A VMK or DVAK token is required');
|
|
13263
13316
|
}
|
|
13264
|
-
const response = await this.http.post(`/v1/vaults/${cleanId}/unseal`, { vmk });
|
|
13317
|
+
const response = await this.http.post(`/v1/vaults/${cleanId}/unseal`, key.startsWith(DVAK_TOKEN_PREFIX) ? { dvak_token: key } : { vmk: key });
|
|
13265
13318
|
if (!response.data.vat) {
|
|
13266
13319
|
throw new ValidationError('Unseal response did not include a vault access token');
|
|
13267
13320
|
}
|
|
@@ -15057,7 +15110,7 @@ class SparkVault {
|
|
|
15057
15110
|
}
|
|
15058
15111
|
/** Get the SDK version */
|
|
15059
15112
|
static get version() {
|
|
15060
|
-
return '9.
|
|
15113
|
+
return '9.3.0';
|
|
15061
15114
|
}
|
|
15062
15115
|
}
|
|
15063
15116
|
if (typeof window !== 'undefined') {
|