@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.cjs CHANGED
@@ -10059,6 +10059,15 @@ const FINALIZATION_CHECK = {
10059
10059
  class UploadApi extends SparkVaultApi {
10060
10060
  constructor(config) {
10061
10061
  super(config.timeout);
10062
+ /**
10063
+ * Vault upload info by vault id, memoized for the life of this client.
10064
+ *
10065
+ * The client is built once with the SDK and the map dies with the page, so
10066
+ * the memo cannot outlive the page it decorates — which is why there is no
10067
+ * TTL and no invalidation API to get wrong. It deliberately survives
10068
+ * `resetSession()`, alongside the other long-lived per-client state.
10069
+ */
10070
+ this.vaultInfoMemo = new Map();
10062
10071
  this.config = config;
10063
10072
  }
10064
10073
  makeError(message, code, statusCode, details) {
@@ -10075,9 +10084,47 @@ class UploadApi extends SparkVaultApi {
10075
10084
  return { data, status };
10076
10085
  }
10077
10086
  /**
10078
- * Get vault upload info (public endpoint).
10087
+ * Get vault upload info (public endpoint), fetched at most once per vault.
10088
+ *
10089
+ * Every widget interaction — `upload()`, `pop()`, `render()`, and each click
10090
+ * an `attach()` handler serves — starts by asking for this, and the answer is
10091
+ * pure display and geometry: the vault's name, its branding, and the size it
10092
+ * advertises. It authorizes nothing. The server re-validates the vault, its
10093
+ * upload source, the request origin, and the file size on the POST that
10094
+ * actually creates the upload, and that re-validation is the correctness
10095
+ * backstop for this whole flow — a memoized answer can never widen what an
10096
+ * upload is allowed to do, and the backstop must stay in place.
10097
+ *
10098
+ * Only a successful answer is kept: a rejection evicts its entry so the next
10099
+ * open retries against the server, and an entry whose request was aborted by
10100
+ * a closing widget is never handed to the widget that replaces it.
10079
10101
  */
10080
10102
  async getVaultUploadInfo(vaultId) {
10103
+ const memoized = this.vaultInfoMemo.get(vaultId);
10104
+ if (memoized && !memoized.pendingSignal?.aborted) {
10105
+ return memoized.promise;
10106
+ }
10107
+ const entry = {
10108
+ pendingSignal: this.getAbortSignal(),
10109
+ promise: this.fetchVaultUploadInfo(vaultId),
10110
+ };
10111
+ this.vaultInfoMemo.set(vaultId, entry);
10112
+ try {
10113
+ const config = await entry.promise;
10114
+ entry.pendingSignal = null;
10115
+ return config;
10116
+ }
10117
+ catch (error) {
10118
+ // Identity guard: a widget that reopened while this request was failing
10119
+ // has its own entry in the map, and evicting by key alone would throw
10120
+ // away its in-flight fetch.
10121
+ if (this.vaultInfoMemo.get(vaultId) === entry) {
10122
+ this.vaultInfoMemo.delete(vaultId);
10123
+ }
10124
+ throw error;
10125
+ }
10126
+ }
10127
+ async fetchVaultUploadInfo(vaultId) {
10081
10128
  const url = `${this.config.apiBaseUrl}/v1/files/in/${vaultId}`;
10082
10129
  const response = await this.request(url, { method: 'GET' });
10083
10130
  if (!isVaultUploadInfoResponse(response.data)) {
@@ -15061,7 +15108,7 @@ class SparkVault {
15061
15108
  }
15062
15109
  /** Get the SDK version */
15063
15110
  static get version() {
15064
- return '9.2.3';
15111
+ return '9.2.4';
15065
15112
  }
15066
15113
  }
15067
15114
  if (typeof window !== 'undefined') {