@sparkvault/sdk-js 9.2.3 → 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.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)) {
@@ -15057,7 +15104,7 @@ class SparkVault {
15057
15104
  }
15058
15105
  /** Get the SDK version */
15059
15106
  static get version() {
15060
- return '9.2.3';
15107
+ return '9.2.4';
15061
15108
  }
15062
15109
  }
15063
15110
  if (typeof window !== 'undefined') {