@supabase/storage-js 3.0.0-next.2 → 3.0.0-next.20

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/README.md CHANGED
@@ -67,7 +67,7 @@ If you're already using `@supabase/supabase-js`, access storage through the clie
67
67
  ```js
68
68
  import { createClient } from '@supabase/supabase-js'
69
69
 
70
- // Use publishable/anon key for frontend applications
70
+ // Use publishable key for frontend applications
71
71
  const supabase = createClient('https://<project_ref>.supabase.co', '<your-publishable-key>')
72
72
 
73
73
  // Access storage
package/dist/index.cjs CHANGED
@@ -285,8 +285,18 @@ const isValidBucketName = (bucketName) => {
285
285
  * @returns Human-readable error message
286
286
  */
287
287
  const _getErrorMessage = (err) => {
288
- var _err$error;
289
- return err.msg || err.message || err.error_description || (typeof err.error === "string" ? err.error : (_err$error = err.error) === null || _err$error === void 0 ? void 0 : _err$error.message) || JSON.stringify(err);
288
+ if (typeof err === "object" && err !== null) {
289
+ const e = err;
290
+ if (typeof e.msg === "string") return e.msg;
291
+ if (typeof e.message === "string") return e.message;
292
+ if (typeof e.error_description === "string") return e.error_description;
293
+ if (typeof e.error === "string") return e.error;
294
+ if (typeof e.error === "object" && e.error !== null) {
295
+ const nested = e.error;
296
+ if (typeof nested.message === "string") return nested.message;
297
+ }
298
+ }
299
+ return JSON.stringify(err);
290
300
  };
291
301
  /**
292
302
  * Handles fetch errors and converts them to Storage error types
@@ -296,9 +306,9 @@ const _getErrorMessage = (err) => {
296
306
  * @param namespace - Error namespace ('storage' or 'vectors')
297
307
  */
298
308
  const handleError = async (error, reject, options, namespace) => {
299
- if (error !== null && typeof error === "object" && typeof error.json === "function") {
309
+ if (error !== null && typeof error === "object" && "json" in error && typeof error.json === "function") {
300
310
  const responseError = error;
301
- let status = parseInt(responseError.status, 10);
311
+ let status = parseInt(String(responseError.status), 10);
302
312
  if (!Number.isFinite(status)) status = 500;
303
313
  responseError.json().then((err) => {
304
314
  const statusCode = (err === null || err === void 0 ? void 0 : err.statusCode) || (err === null || err === void 0 ? void 0 : err.code) || status + "";
@@ -710,22 +720,28 @@ var StorageFileApi = class extends BaseApiClient {
710
720
  return _this3.handleOperation(async () => {
711
721
  let body;
712
722
  const options = _objectSpread2(_objectSpread2({}, DEFAULT_FILE_OPTIONS), fileOptions);
713
- const headers = _objectSpread2(_objectSpread2({}, _this3.headers), { "x-upsert": String(options.upsert) });
723
+ let headers = _objectSpread2(_objectSpread2({}, _this3.headers), { "x-upsert": String(options.upsert) });
724
+ const metadata = options.metadata;
714
725
  if (typeof Blob !== "undefined" && fileBody instanceof Blob) {
715
726
  body = new FormData();
716
727
  body.append("cacheControl", options.cacheControl);
728
+ if (metadata) body.append("metadata", _this3.encodeMetadata(metadata));
717
729
  body.append("", fileBody);
718
730
  } else if (typeof FormData !== "undefined" && fileBody instanceof FormData) {
719
731
  body = fileBody;
720
- body.append("cacheControl", options.cacheControl);
732
+ if (!body.has("cacheControl")) body.append("cacheControl", options.cacheControl);
733
+ if (metadata && !body.has("metadata")) body.append("metadata", _this3.encodeMetadata(metadata));
721
734
  } else {
722
735
  body = fileBody;
723
736
  headers["cache-control"] = `max-age=${options.cacheControl}`;
724
737
  headers["content-type"] = options.contentType;
738
+ if (metadata) headers["x-metadata"] = _this3.toBase64(_this3.encodeMetadata(metadata));
739
+ if ((typeof ReadableStream !== "undefined" && body instanceof ReadableStream || body && typeof body === "object" && "pipe" in body && typeof body.pipe === "function") && !options.duplex) options.duplex = "half";
725
740
  }
741
+ if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) for (const [key, value] of Object.entries(fileOptions.headers)) headers = setHeader(headers, key, value);
726
742
  return {
727
743
  path: cleanPath,
728
- fullPath: (await put(_this3.fetch, url.toString(), body, { headers })).Key
744
+ fullPath: (await put(_this3.fetch, url.toString(), body, _objectSpread2({ headers }, (options === null || options === void 0 ? void 0 : options.duplex) ? { duplex: options.duplex } : {}))).Key
729
745
  };
730
746
  });
731
747
  }
@@ -788,7 +804,10 @@ var StorageFileApi = class extends BaseApiClient {
788
804
  * @category File Buckets
789
805
  * @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to update.
790
806
  * @param fileBody The body of the file to be stored in the bucket.
791
- * @param fileOptions Optional file upload options including cacheControl, contentType, upsert, and metadata.
807
+ * @param fileOptions Optional file upload options including cacheControl, contentType, and metadata.
808
+ * **Note:** The `upsert` option has no effect here. `update()` always replaces the
809
+ * file at the given path, so the `x-upsert` header is not sent. To control upsert
810
+ * behavior, use `upload()` instead.
792
811
  * @returns Promise with response containing file path, id, and fullPath or error
793
812
  *
794
813
  * @example Update file
@@ -798,8 +817,7 @@ var StorageFileApi = class extends BaseApiClient {
798
817
  * .storage
799
818
  * .from('avatars')
800
819
  * .update('public/avatar1.png', avatarFile, {
801
- * cacheControl: '3600',
802
- * upsert: true
820
+ * cacheControl: '3600'
803
821
  * })
804
822
  * ```
805
823
  *
@@ -830,6 +848,7 @@ var StorageFileApi = class extends BaseApiClient {
830
848
  * - RLS policy permissions required:
831
849
  * - `buckets` table permissions: none
832
850
  * - `objects` table permissions: `update` and `select`
851
+ * - `update()` always replaces the file at the given path regardless of the `upsert` option.
833
852
  * - Refer to the [Storage guide](/docs/guides/storage/security/access-control) on how access control works
834
853
  * - For React Native, using either `Blob`, `File` or `FormData` does not work as intended. Update file using `ArrayBuffer` from base64 file data instead, see example below.
835
854
  */
@@ -1167,7 +1186,7 @@ var StorageFileApi = class extends BaseApiClient {
1167
1186
  *
1168
1187
  * @category File Buckets
1169
1188
  * @param path The file path, including the file name. For example `folder/image.png`.
1170
- * @returns Promise with response containing boolean indicating file existence or error
1189
+ * @returns `{ data: true, error: null }` when the file exists, `{ data: false, error: null }` when it does not (HTTP 400 or 404), or throws/returns a `StorageError` for any other failure.
1171
1190
  *
1172
1191
  * @example Check file existence
1173
1192
  * ```js
@@ -1193,7 +1212,7 @@ var StorageFileApi = class extends BaseApiClient {
1193
1212
  const status = error instanceof StorageApiError ? error.status : error instanceof StorageUnknownError ? (_error$originalError = error.originalError) === null || _error$originalError === void 0 ? void 0 : _error$originalError.status : void 0;
1194
1213
  if (status !== void 0 && [400, 404].includes(status)) return {
1195
1214
  data: false,
1196
- error
1215
+ error: null
1197
1216
  };
1198
1217
  }
1199
1218
  throw error;
@@ -1481,7 +1500,7 @@ var StorageFileApi = class extends BaseApiClient {
1481
1500
 
1482
1501
  //#endregion
1483
1502
  //#region src/lib/version.ts
1484
- const version = "3.0.0-next.2";
1503
+ const version = "3.0.0-next.20";
1485
1504
 
1486
1505
  //#endregion
1487
1506
  //#region src/lib/constants.ts
@@ -1807,7 +1826,7 @@ var StorageAnalyticsClient = class extends BaseApiClient {
1807
1826
  * ```typescript
1808
1827
  * import { createClient } from '@supabase/supabase-js'
1809
1828
  *
1810
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
1829
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
1811
1830
  * const { data, error } = await supabase.storage.analytics.listBuckets()
1812
1831
  * ```
1813
1832
  *
@@ -2342,7 +2361,7 @@ var StorageVectorsClient = class extends VectorBucketApi {
2342
2361
  * ```typescript
2343
2362
  * import { createClient } from '@supabase/supabase-js'
2344
2363
  *
2345
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
2364
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
2346
2365
  * const bucket = supabase.storage.vectors.from('embeddings-prod')
2347
2366
  * ```
2348
2367
  *
@@ -2839,7 +2858,7 @@ var StorageClient = class extends StorageBucketApi {
2839
2858
  * ```ts
2840
2859
  * import { createClient } from '@supabase/supabase-js'
2841
2860
  *
2842
- * const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-or-anon-key')
2861
+ * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
2843
2862
  * const avatars = supabase.storage.from('avatars')
2844
2863
  * ```
2845
2864
  *
@@ -2848,7 +2867,7 @@ var StorageClient = class extends StorageBucketApi {
2848
2867
  * import { StorageClient } from '@supabase/storage-js'
2849
2868
  *
2850
2869
  * const storage = new StorageClient('https://xyzcompany.supabase.co/storage/v1', {
2851
- * apikey: 'publishable-or-anon-key',
2870
+ * apikey: 'your-publishable-key',
2852
2871
  * })
2853
2872
  * const avatars = storage.from('avatars')
2854
2873
  * ```