@supabase/storage-js 2.103.0-canary.0 → 2.103.0-canary.2

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
@@ -288,12 +288,22 @@ const _getRequestParams = (method, options, parameters, body) => {
288
288
  };
289
289
  if (method === "GET" || method === "HEAD" || !body) return _objectSpread2(_objectSpread2({}, params), parameters);
290
290
  if (isPlainObject(body)) {
291
- params.headers = _objectSpread2({ "Content-Type": "application/json" }, options === null || options === void 0 ? void 0 : options.headers);
291
+ var _contentType;
292
+ const headers = (options === null || options === void 0 ? void 0 : options.headers) || {};
293
+ let contentType;
294
+ for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === "content-type") contentType = value;
295
+ params.headers = setRequestHeader(headers, "Content-Type", (_contentType = contentType) !== null && _contentType !== void 0 ? _contentType : "application/json");
292
296
  params.body = JSON.stringify(body);
293
297
  } else params.body = body;
294
298
  if (options === null || options === void 0 ? void 0 : options.duplex) params.duplex = options.duplex;
295
299
  return _objectSpread2(_objectSpread2({}, params), parameters);
296
300
  };
301
+ function setRequestHeader(headers, name, value) {
302
+ const nextHeaders = _objectSpread2({}, headers);
303
+ for (const key of Object.keys(nextHeaders)) if (key.toLowerCase() === name.toLowerCase()) delete nextHeaders[key];
304
+ nextHeaders[name] = value;
305
+ return nextHeaders;
306
+ }
297
307
  /**
298
308
  * Internal request handler that wraps fetch with error handling
299
309
  * @param fetcher - Fetch function to use
@@ -367,7 +377,7 @@ var BaseApiClient = class {
367
377
  constructor(url, headers = {}, fetch$1, namespace = "storage") {
368
378
  this.shouldThrowOnError = false;
369
379
  this.url = url;
370
- this.headers = headers;
380
+ this.headers = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));
371
381
  this.fetch = resolveFetch(fetch$1);
372
382
  this.namespace = namespace;
373
383
  }
@@ -390,7 +400,7 @@ var BaseApiClient = class {
390
400
  * @returns this - For method chaining
391
401
  */
392
402
  setHeader(name, value) {
393
- this.headers = _objectSpread2(_objectSpread2({}, this.headers), {}, { [name]: value });
403
+ this.headers = _objectSpread2(_objectSpread2({}, this.headers), {}, { [name.toLowerCase()]: value });
394
404
  return this;
395
405
  }
396
406
  /**
@@ -892,6 +902,7 @@ var StorageFileApi = class extends BaseApiClient {
892
902
  * @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
893
903
  * @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
894
904
  * @param options.transform Transform the asset before serving it to the client.
905
+ * @param options.cacheNonce Append a cache nonce parameter to the URL to invalidate the cache.
895
906
  * @returns Promise with response containing signed URL or error
896
907
  *
897
908
  * @example Create Signed URL
@@ -947,9 +958,12 @@ var StorageFileApi = class extends BaseApiClient {
947
958
  let _path = _this8._getFinalPath(path);
948
959
  const hasTransform = typeof (options === null || options === void 0 ? void 0 : options.transform) === "object" && options.transform !== null && Object.keys(options.transform).length > 0;
949
960
  let data = await post(_this8.fetch, `${_this8.url}/object/sign/${_path}`, _objectSpread2({ expiresIn }, hasTransform ? { transform: options.transform } : {}), { headers: _this8.headers });
950
- const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `&download=${options.download === true ? "" : options.download}` : "";
961
+ const query = new URLSearchParams();
962
+ if (options === null || options === void 0 ? void 0 : options.download) query.set("download", options.download === true ? "" : options.download);
963
+ if ((options === null || options === void 0 ? void 0 : options.cacheNonce) != null) query.set("cacheNonce", String(options.cacheNonce));
964
+ const queryString = query.toString();
951
965
  const returnedPath = hasTransform && data.signedURL.includes("/object/sign/") ? data.signedURL.replace("/object/sign/", "/render/image/sign/") : data.signedURL;
952
- return { signedUrl: encodeURI(`${_this8.url}${returnedPath}${downloadQueryParam}`) };
966
+ return { signedUrl: encodeURI(`${_this8.url}${returnedPath}${queryString ? `&${queryString}` : ""}`) };
953
967
  });
954
968
  }
955
969
  /**
@@ -959,6 +973,7 @@ var StorageFileApi = class extends BaseApiClient {
959
973
  * @param paths The file paths to be downloaded, including the current file names. For example `['folder/image.png', 'folder2/image2.png']`.
960
974
  * @param expiresIn The number of seconds until the signed URLs expire. For example, `60` for URLs which are valid for one minute.
961
975
  * @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
976
+ * @param options.cacheNonce Append a cache nonce parameter to the URL to invalidate the cache.
962
977
  * @returns Promise with response containing array of objects with signedUrl, path, and error or error
963
978
  *
964
979
  * @example Create Signed URLs
@@ -1003,8 +1018,11 @@ var StorageFileApi = class extends BaseApiClient {
1003
1018
  expiresIn,
1004
1019
  paths
1005
1020
  }, { headers: _this9.headers });
1006
- const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `&download=${options.download === true ? "" : options.download}` : "";
1007
- return data.map((datum) => _objectSpread2(_objectSpread2({}, datum), {}, { signedUrl: datum.signedURL ? encodeURI(`${_this9.url}${datum.signedURL}${downloadQueryParam}`) : null }));
1021
+ const query = new URLSearchParams();
1022
+ if (options === null || options === void 0 ? void 0 : options.download) query.set("download", options.download === true ? "" : options.download);
1023
+ if ((options === null || options === void 0 ? void 0 : options.cacheNonce) != null) query.set("cacheNonce", String(options.cacheNonce));
1024
+ const queryString = query.toString();
1025
+ return data.map((datum) => _objectSpread2(_objectSpread2({}, datum), {}, { signedUrl: datum.signedURL ? encodeURI(`${_this9.url}${datum.signedURL}${queryString ? `&${queryString}` : ""}`) : null }));
1008
1026
  });
1009
1027
  }
1010
1028
  /**
@@ -1013,6 +1031,7 @@ var StorageFileApi = class extends BaseApiClient {
1013
1031
  * @category File Buckets
1014
1032
  * @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
1015
1033
  * @param options.transform Transform the asset before serving it to the client.
1034
+ * @param options.cacheNonce Append a cache nonce parameter to the URL to invalidate the cache.
1016
1035
  * @param parameters Additional fetch parameters like signal for cancellation. Supports standard fetch options including cache control.
1017
1036
  * @returns BlobDownloadBuilder instance for downloading the file
1018
1037
  *
@@ -1073,10 +1092,12 @@ var StorageFileApi = class extends BaseApiClient {
1073
1092
  */
1074
1093
  download(path, options, parameters) {
1075
1094
  const renderPath = typeof (options === null || options === void 0 ? void 0 : options.transform) !== "undefined" ? "render/image/authenticated" : "object";
1076
- const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
1077
- const queryString = transformationQuery ? `?${transformationQuery}` : "";
1095
+ const query = new URLSearchParams();
1096
+ if (options === null || options === void 0 ? void 0 : options.transform) this.applyTransformOptsToQuery(query, options.transform);
1097
+ if ((options === null || options === void 0 ? void 0 : options.cacheNonce) != null) query.set("cacheNonce", String(options.cacheNonce));
1098
+ const queryString = query.toString();
1078
1099
  const _path = this._getFinalPath(path);
1079
- const downloadFn = () => get(this.fetch, `${this.url}/${renderPath}/${_path}${queryString}`, {
1100
+ const downloadFn = () => get(this.fetch, `${this.url}/${renderPath}/${_path}${queryString ? `?${queryString}` : ""}`, {
1080
1101
  headers: this.headers,
1081
1102
  noResolveJson: true
1082
1103
  }, parameters);
@@ -1157,6 +1178,7 @@ var StorageFileApi = class extends BaseApiClient {
1157
1178
  * @param path The path and name of the file to generate the public URL for. For example `folder/image.png`.
1158
1179
  * @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
1159
1180
  * @param options.transform Transform the asset before serving it to the client.
1181
+ * @param options.cacheNonce Append a cache nonce parameter to the URL to invalidate the cache.
1160
1182
  * @returns Object with public URL
1161
1183
  *
1162
1184
  * @example Returns the URL for an asset in a public bucket
@@ -1208,15 +1230,13 @@ var StorageFileApi = class extends BaseApiClient {
1208
1230
  */
1209
1231
  getPublicUrl(path, options) {
1210
1232
  const _path = this._getFinalPath(path);
1211
- const _queryString = [];
1212
- const downloadQueryParam = (options === null || options === void 0 ? void 0 : options.download) ? `download=${options.download === true ? "" : options.download}` : "";
1213
- if (downloadQueryParam !== "") _queryString.push(downloadQueryParam);
1233
+ const query = new URLSearchParams();
1234
+ if (options === null || options === void 0 ? void 0 : options.download) query.set("download", options.download === true ? "" : options.download);
1235
+ if (options === null || options === void 0 ? void 0 : options.transform) this.applyTransformOptsToQuery(query, options.transform);
1236
+ if ((options === null || options === void 0 ? void 0 : options.cacheNonce) != null) query.set("cacheNonce", String(options.cacheNonce));
1237
+ const queryString = query.toString();
1214
1238
  const renderPath = typeof (options === null || options === void 0 ? void 0 : options.transform) !== "undefined" ? "render/image" : "object";
1215
- const transformationQuery = this.transformOptsToQueryString((options === null || options === void 0 ? void 0 : options.transform) || {});
1216
- if (transformationQuery !== "") _queryString.push(transformationQuery);
1217
- let queryString = _queryString.join("&");
1218
- if (queryString !== "") queryString = `?${queryString}`;
1219
- return { data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}${queryString}`) } };
1239
+ return { data: { publicUrl: encodeURI(`${this.url}/${renderPath}/public/${_path}`) + (queryString ? `?${queryString}` : "") } };
1220
1240
  }
1221
1241
  /**
1222
1242
  * Deletes files within the same bucket
@@ -1419,20 +1439,20 @@ var StorageFileApi = class extends BaseApiClient {
1419
1439
  _removeEmptyFolders(path) {
1420
1440
  return path.replace(/^\/|\/$/g, "").replace(/\/+/g, "/");
1421
1441
  }
1422
- transformOptsToQueryString(transform) {
1423
- const params = [];
1424
- if (transform.width) params.push(`width=${transform.width}`);
1425
- if (transform.height) params.push(`height=${transform.height}`);
1426
- if (transform.resize) params.push(`resize=${transform.resize}`);
1427
- if (transform.format) params.push(`format=${transform.format}`);
1428
- if (transform.quality) params.push(`quality=${transform.quality}`);
1429
- return params.join("&");
1442
+ /** Modifies the `query`, appending values the from `transform` */
1443
+ applyTransformOptsToQuery(query, transform) {
1444
+ if (transform.width) query.set("width", transform.width.toString());
1445
+ if (transform.height) query.set("height", transform.height.toString());
1446
+ if (transform.resize) query.set("resize", transform.resize);
1447
+ if (transform.format) query.set("format", transform.format);
1448
+ if (transform.quality) query.set("quality", transform.quality.toString());
1449
+ return query;
1430
1450
  }
1431
1451
  };
1432
1452
 
1433
1453
  //#endregion
1434
1454
  //#region src/lib/version.ts
1435
- const version = "2.103.0-canary.0";
1455
+ const version = "2.103.0-canary.2";
1436
1456
 
1437
1457
  //#endregion
1438
1458
  //#region src/lib/constants.ts