@sparkvault/sdk-js 9.2.2 → 9.2.4
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 +53 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +53 -20
- package/dist/index.mjs.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/api.d.ts +24 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10043,32 +10043,27 @@ function summarizeErrorBody(body) {
|
|
|
10043
10043
|
const RESUME_CHECK = {
|
|
10044
10044
|
name: 'Upload resume check',
|
|
10045
10045
|
code: 'resume_check_failed',
|
|
10046
|
+
serverFailureMessage: 'Upload could not be resumed: the server no longer recognizes this upload session.',
|
|
10046
10047
|
networkMessage: 'Unable to resume upload. Please check your connection and try again.',
|
|
10047
10048
|
};
|
|
10048
10049
|
const FINALIZATION_CHECK = {
|
|
10049
10050
|
name: 'Upload finalization check',
|
|
10050
10051
|
code: 'finalization_check_failed',
|
|
10052
|
+
serverFailureMessage: 'Upload could not be confirmed: the server did not finalize the file.',
|
|
10051
10053
|
networkMessage: 'Unable to confirm upload. Please check your connection and try again.',
|
|
10052
10054
|
};
|
|
10053
|
-
/**
|
|
10054
|
-
* Turn a terminal confirmation failure into something a person can read.
|
|
10055
|
-
*
|
|
10056
|
-
* The upload widget prints `error.message` verbatim, and a bare status line
|
|
10057
|
-
* ("Upload finalization check failed: 500") tells the user nothing about their
|
|
10058
|
-
* file. Only the status-carrying failure is rewritten: a timeout or a
|
|
10059
|
-
* connection failure already explains itself in the user's terms, and its code
|
|
10060
|
-
* is load-bearing taxonomy. The status and the server's own detail move into
|
|
10061
|
-
* `details`, where support can still read them.
|
|
10062
|
-
*/
|
|
10063
|
-
function asFinalizationFailure(error) {
|
|
10064
|
-
if (!(error instanceof UploadApiError) || error.code !== FINALIZATION_CHECK.code) {
|
|
10065
|
-
return error;
|
|
10066
|
-
}
|
|
10067
|
-
return new UploadApiError('Upload could not be confirmed: the server did not finalize the file.', error.code, error.statusCode ?? 0, { ...error.details, status: error.statusCode ?? 0 });
|
|
10068
|
-
}
|
|
10069
10055
|
class UploadApi extends SparkVaultApi {
|
|
10070
10056
|
constructor(config) {
|
|
10071
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();
|
|
10072
10067
|
this.config = config;
|
|
10073
10068
|
}
|
|
10074
10069
|
makeError(message, code, statusCode, details) {
|
|
@@ -10085,9 +10080,47 @@ class UploadApi extends SparkVaultApi {
|
|
|
10085
10080
|
return { data, status };
|
|
10086
10081
|
}
|
|
10087
10082
|
/**
|
|
10088
|
-
* 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.
|
|
10089
10097
|
*/
|
|
10090
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) {
|
|
10091
10124
|
const url = `${this.config.apiBaseUrl}/v1/files/in/${vaultId}`;
|
|
10092
10125
|
const response = await this.request(url, { method: 'GET' });
|
|
10093
10126
|
if (!isVaultUploadInfoResponse(response.data)) {
|
|
@@ -10278,7 +10311,7 @@ class UploadApi extends SparkVaultApi {
|
|
|
10278
10311
|
if (attempt >= FINALIZE_MAX_ATTEMPTS ||
|
|
10279
10312
|
consecutiveTimeouts >= FINALIZE_MAX_CONSECUTIVE_TIMEOUTS ||
|
|
10280
10313
|
!isRetryableTransferFailure(error)) {
|
|
10281
|
-
throw
|
|
10314
|
+
throw error;
|
|
10282
10315
|
}
|
|
10283
10316
|
await abortableDelay(FINALIZE_RETRY_MS, this.getAbortSignal());
|
|
10284
10317
|
}
|
|
@@ -10484,7 +10517,7 @@ class UploadApi extends SparkVaultApi {
|
|
|
10484
10517
|
// attempt. What it says is the only server-side detail this client
|
|
10485
10518
|
// ever sees, so it rides along in `details` for support.
|
|
10486
10519
|
const detail = summarizeErrorBody(await response.text().catch(() => ''));
|
|
10487
|
-
throw new UploadApiError(
|
|
10520
|
+
throw new UploadApiError(check.serverFailureMessage, check.code, response.status, { status: response.status, ...(detail ? { serverDetail: detail } : {}) });
|
|
10488
10521
|
}
|
|
10489
10522
|
return response;
|
|
10490
10523
|
}
|
|
@@ -15071,7 +15104,7 @@ class SparkVault {
|
|
|
15071
15104
|
}
|
|
15072
15105
|
/** Get the SDK version */
|
|
15073
15106
|
static get version() {
|
|
15074
|
-
return '9.2.
|
|
15107
|
+
return '9.2.4';
|
|
15075
15108
|
}
|
|
15076
15109
|
}
|
|
15077
15110
|
if (typeof window !== 'undefined') {
|