Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@supabase/storage-js

Package Overview
Dependencies
Maintainers
4
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supabase/storage-js - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

32

dist/main/lib/StorageFileApi.d.ts

@@ -13,9 +13,24 @@ import { FetchParameters } from './fetch';

/**
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
*
* @param method HTTP method.
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
private uploadOrUpdate;
/**
* Uploads a file to an existing bucket.
*
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param file The File object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
upload(path: string, file: File, fileOptions?: FileOptions): Promise<{
upload(path: string, fileBody: ArrayBuffer | ArrayBufferView | Blob | File | FormData | ReadableStream<Uint8Array> | URLSearchParams | string, fileOptions?: FileOptions): Promise<{
data: {

@@ -29,7 +44,10 @@ Key: string;

*
* @param path The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
* @param file The file object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
update(path: string, file: File, fileOptions?: FileOptions): Promise<{
update(path: string, fileBody: ArrayBuffer | ArrayBufferView | Blob | File | FormData | ReadableStream<Uint8Array> | URLSearchParams | string, fileOptions?: FileOptions): Promise<{
data: {

@@ -36,0 +54,0 @@ Key: string;

@@ -11,6 +11,9 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageFileApi = void 0;
const fetch_1 = require("./fetch");
const helpers_1 = require("./helpers");
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const DEFAULT_SEARCH_OPTIONS = {

@@ -26,2 +29,3 @@ limit: 100,

cacheControl: '3600',
contentType: 'text/plain;charset=UTF-8',
upsert: false,

@@ -36,22 +40,37 @@ };

/**
* Uploads a file to an existing bucket.
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
*
* @param method HTTP method.
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param file The File object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
upload(path, file, fileOptions) {
uploadOrUpdate(method, path, fileBody, fileOptions) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!helpers_1.isBrowser())
throw new Error('No browser detected.');
const formData = new FormData();
let body;
const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
formData.append('cacheControl', options.cacheControl);
formData.append('', file, file.name);
const headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
body = new FormData();
body.append('cacheControl', options.cacheControl);
body.append('', fileBody);
}
else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
body = fileBody;
body.append('cacheControl', options.cacheControl);
}
else {
body = fileBody;
headers['cache-control'] = `max-age=${options.cacheControl}`;
headers['content-type'] = options.contentType;
}
const _path = this._getFinalPath(path);
const res = yield fetch(`${this.url}/object/${_path}`, {
method: 'POST',
body: formData,
headers: Object.assign(Object.assign({}, this.headers), { 'x-upsert': String(fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.upsert) }),
const res = yield cross_fetch_1.default(`${this.url}/object/${_path}`, {
method,
body,
headers,
});

@@ -74,36 +93,29 @@ if (res.ok) {

/**
* Uploads a file to an existing bucket.
*
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
upload(path, fileBody, fileOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.uploadOrUpdate('POST', path, fileBody, fileOptions);
});
}
/**
* Replaces an existing file at the specified path with a new one.
*
* @param path The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
* @param file The file object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
update(path, file, fileOptions) {
update(path, fileBody, fileOptions) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!helpers_1.isBrowser())
throw new Error('No browser detected.');
const formData = new FormData();
const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
formData.append('cacheControl', options.cacheControl);
formData.append('', file, file.name);
const _path = this._getFinalPath(path);
const res = yield fetch(`${this.url}/object/${_path}`, {
method: 'PUT',
body: formData,
headers: Object.assign({}, this.headers),
});
if (res.ok) {
// const data = await res.json()
// temporary fix till backend is updated to the latest storage-api version
return { data: { Key: _path }, error: null };
}
else {
const error = yield res.json();
return { data: null, error };
}
}
catch (error) {
return { data: null, error };
}
return this.uploadOrUpdate('PUT', path, fileBody, fileOptions);
});

@@ -110,0 +122,0 @@ }

@@ -25,3 +25,4 @@ export interface Bucket {

export interface FileOptions {
cacheControl: string;
cacheControl?: string;
contentType?: string;
upsert?: boolean;

@@ -28,0 +29,0 @@ }

@@ -13,9 +13,24 @@ import { FetchParameters } from './fetch';

/**
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
*
* @param method HTTP method.
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
private uploadOrUpdate;
/**
* Uploads a file to an existing bucket.
*
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param file The File object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
upload(path: string, file: File, fileOptions?: FileOptions): Promise<{
upload(path: string, fileBody: ArrayBuffer | ArrayBufferView | Blob | File | FormData | ReadableStream<Uint8Array> | URLSearchParams | string, fileOptions?: FileOptions): Promise<{
data: {

@@ -29,7 +44,10 @@ Key: string;

*
* @param path The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
* @param file The file object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
update(path: string, file: File, fileOptions?: FileOptions): Promise<{
update(path: string, fileBody: ArrayBuffer | ArrayBufferView | Blob | File | FormData | ReadableStream<Uint8Array> | URLSearchParams | string, fileOptions?: FileOptions): Promise<{
data: {

@@ -36,0 +54,0 @@ Key: string;

@@ -11,3 +11,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { get, post, remove } from './fetch';
import { isBrowser } from './helpers';
import fetch from 'cross-fetch';
const DEFAULT_SEARCH_OPTIONS = {

@@ -23,2 +23,3 @@ limit: 100,

cacheControl: '3600',
contentType: 'text/plain;charset=UTF-8',
upsert: false,

@@ -33,22 +34,37 @@ };

/**
* Uploads a file to an existing bucket.
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
*
* @param method HTTP method.
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param file The File object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
upload(path, file, fileOptions) {
uploadOrUpdate(method, path, fileBody, fileOptions) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!isBrowser())
throw new Error('No browser detected.');
const formData = new FormData();
let body;
const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
formData.append('cacheControl', options.cacheControl);
formData.append('', file, file.name);
const headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
body = new FormData();
body.append('cacheControl', options.cacheControl);
body.append('', fileBody);
}
else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
body = fileBody;
body.append('cacheControl', options.cacheControl);
}
else {
body = fileBody;
headers['cache-control'] = `max-age=${options.cacheControl}`;
headers['content-type'] = options.contentType;
}
const _path = this._getFinalPath(path);
const res = yield fetch(`${this.url}/object/${_path}`, {
method: 'POST',
body: formData,
headers: Object.assign(Object.assign({}, this.headers), { 'x-upsert': String(fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.upsert) }),
method,
body,
headers,
});

@@ -71,36 +87,29 @@ if (res.ok) {

/**
* Uploads a file to an existing bucket.
*
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
upload(path, fileBody, fileOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.uploadOrUpdate('POST', path, fileBody, fileOptions);
});
}
/**
* Replaces an existing file at the specified path with a new one.
*
* @param path The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
* @param file The file object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
update(path, file, fileOptions) {
update(path, fileBody, fileOptions) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!isBrowser())
throw new Error('No browser detected.');
const formData = new FormData();
const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
formData.append('cacheControl', options.cacheControl);
formData.append('', file, file.name);
const _path = this._getFinalPath(path);
const res = yield fetch(`${this.url}/object/${_path}`, {
method: 'PUT',
body: formData,
headers: Object.assign({}, this.headers),
});
if (res.ok) {
// const data = await res.json()
// temporary fix till backend is updated to the latest storage-api version
return { data: { Key: _path }, error: null };
}
else {
const error = yield res.json();
return { data: null, error };
}
}
catch (error) {
return { data: null, error };
}
return this.uploadOrUpdate('PUT', path, fileBody, fileOptions);
});

@@ -107,0 +116,0 @@ }

@@ -25,3 +25,4 @@ export interface Bucket {

export interface FileOptions {
cacheControl: string;
cacheControl?: string;
contentType?: string;
upsert?: boolean;

@@ -28,0 +29,0 @@ }

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.supabase=e():t.supabase=e()}(self,(function(){return t={98:function(t,e){var r="undefined"!=typeof self?self:this,n=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=d(e)},l.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},n&&(l.prototype[Symbol.iterator]=l.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function g(t,e){var r,n,o=(e=e||{}).body;if(t instanceof g){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function w(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function _(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}g.prototype.clone=function(){return new g(this,{body:this._bodyInit})},v.call(g.prototype),v.call(_.prototype),_.prototype.clone=function(){return new _(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},_.error=function(){var t=new _(null,{status:0,statusText:""});return t.type="error",t};var O=[301,302,303,307,308];_.redirect=function(t,e){if(-1===O.indexOf(e))throw new RangeError("Invalid status code");return new _(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function j(t,r){return new Promise((function(n,i){var s=new g(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new _(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}j.polyfill=!0,t.fetch||(t.fetch=j,t.Headers=l,t.Request=g,t.Response=_),e.Headers=l,e.Request=g,e.Response=_,e.fetch=j,Object.defineProperty(e,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var o=n;(e=o.fetch).default=o.fetch,e.fetch=o.fetch,e.Headers=o.Headers,e.Request=o.Request,e.Response=o.Response,t.exports=e},215:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const n=r(965);class o extends n.StorageBucketApi{constructor(t,e={}){super(t,e)}from(t){return new n.StorageFileApi(this.url,this.headers,t)}}e.SupabaseStorageClient=o},341:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const i=r(215);Object.defineProperty(e,"SupabaseStorageClient",{enumerable:!0,get:function(){return i.SupabaseStorageClient}}),o(r(717),e)},150:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageBucketApi=void 0;const o=r(716);e.StorageBucketApi=class{constructor(t,e={}){this.url=t,this.headers=e}listBuckets(){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}getBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(`${this.url}/bucket/${t}`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createBucket(t,e={public:!1}){return n(this,void 0,void 0,(function*(){try{return{data:(yield o.post(`${this.url}/bucket`,{id:t,name:t,public:e.public},{headers:this.headers})).name,error:null}}catch(t){return{data:null,error:t}}}))}updateBucket(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield o.put(`${this.url}/bucket/${t}`,{id:t,name:t,public:e.public},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}emptyBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.post(`${this.url}/bucket/${t}/empty`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}deleteBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.remove(`${this.url}/bucket/${t}`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}}},948:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageFileApi=void 0;const o=r(716),i=r(610),s={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},a={cacheControl:"3600",upsert:!1};e.StorageFileApi=class{constructor(t,e={},r){this.url=t,this.headers=e,this.bucketId=r}upload(t,e,r){return n(this,void 0,void 0,(function*(){try{if(!i.isBrowser())throw new Error("No browser detected.");const n=new FormData,o=Object.assign(Object.assign({},a),r);n.append("cacheControl",o.cacheControl),n.append("",e,e.name);const s=this._getFinalPath(t),u=yield fetch(`${this.url}/object/${s}`,{method:"POST",body:n,headers:Object.assign(Object.assign({},this.headers),{"x-upsert":String(null==r?void 0:r.upsert)})});return u.ok?{data:{Key:s},error:null}:{data:null,error:yield u.json()}}catch(t){return{data:null,error:t}}}))}update(t,e,r){return n(this,void 0,void 0,(function*(){try{if(!i.isBrowser())throw new Error("No browser detected.");const n=new FormData,o=Object.assign(Object.assign({},a),r);n.append("cacheControl",o.cacheControl),n.append("",e,e.name);const s=this._getFinalPath(t),u=yield fetch(`${this.url}/object/${s}`,{method:"PUT",body:n,headers:Object.assign({},this.headers)});return u.ok?{data:{Key:s},error:null}:{data:null,error:yield u.json()}}catch(t){return{data:null,error:t}}}))}move(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield o.post(`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createSignedUrl(t,e){return n(this,void 0,void 0,(function*(){try{const r=this._getFinalPath(t);let n=yield o.post(`${this.url}/object/sign/${r}`,{expiresIn:e},{headers:this.headers});const i=`${this.url}${n.signedURL}`;return n={signedURL:i},{data:n,error:null,signedURL:i}}catch(t){return{data:null,error:t,signedURL:null}}}))}download(t){return n(this,void 0,void 0,(function*(){try{const e=this._getFinalPath(t),r=yield o.get(`${this.url}/object/${e}`,{headers:this.headers,noResolveJson:!0});return{data:yield r.blob(),error:null}}catch(t){return{data:null,error:t}}}))}getPublicUrl(t){try{const e=this._getFinalPath(t),r=`${this.url}/object/public/${e}`;return{data:{publicURL:r},error:null,publicURL:r}}catch(t){return{data:null,error:t,publicURL:null}}}remove(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.remove(`${this.url}/object/${this.bucketId}`,{prefixes:t},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}list(t,e,r){return n(this,void 0,void 0,(function*(){try{const n=Object.assign(Object.assign(Object.assign({},s),e),{prefix:t||""});return{data:yield o.post(`${this.url}/object/list/${this.bucketId}`,n,{headers:this.headers},r),error:null}}catch(t){return{data:null,error:t}}}))}_getFinalPath(t){return`${this.bucketId}/${t}`}}},716:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.remove=e.put=e.post=e.get=void 0;const i=o(r(98)),s=t=>t.msg||t.message||t.error_description||t.error||JSON.stringify(t);function a(t,e,r,o,a){return n(this,void 0,void 0,(function*(){return new Promise(((n,u)=>{i.default(e,((t,e,r,n)=>{const o={method:t,headers:(null==e?void 0:e.headers)||{}};return"GET"===t?o:(o.headers=Object.assign({"Content-Type":"application/json"},null==e?void 0:e.headers),o.body=JSON.stringify(n),Object.assign(Object.assign({},o),r))})(t,r,o,a)).then((t=>{if(!t.ok)throw t;return(null==r?void 0:r.noResolveJson)?n(t):t.json()})).then((t=>n(t))).catch((t=>((t,e)=>{if("function"!=typeof t.json)return e(t);t.json().then((r=>e({message:s(r),status:(null==t?void 0:t.status)||500})))})(t,u)))}))}))}e.get=function(t,e,r){return n(this,void 0,void 0,(function*(){return a("GET",t,e,r)}))},e.post=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("POST",t,r,o,e)}))},e.put=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("PUT",t,r,o,e)}))},e.remove=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("DELETE",t,r,o,e)}))}},610:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isBrowser=void 0,e.isBrowser=()=>"undefined"!=typeof window},965:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(150),e),o(r(948),e),o(r(717),e)},717:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})}},e={},function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(341);var t,e}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.supabase=e():t.supabase=e()}(self,(function(){return t={98:function(t,e){var r="undefined"!=typeof self?self:this,n=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=d(e)},l.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},n&&(l.prototype[Symbol.iterator]=l.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function g(t,e){var r,n,o=(e=e||{}).body;if(t instanceof g){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function w(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}g.prototype.clone=function(){return new g(this,{body:this._bodyInit})},v.call(g.prototype),v.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var O=[301,302,303,307,308];w.redirect=function(t,e){if(-1===O.indexOf(e))throw new RangeError("Invalid status code");return new w(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function x(t,r){return new Promise((function(n,i){var s=new g(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new w(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}x.polyfill=!0,t.fetch||(t.fetch=x,t.Headers=l,t.Request=g,t.Response=w),e.Headers=l,e.Request=g,e.Response=w,e.fetch=x,Object.defineProperty(e,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var o=n;(e=o.fetch).default=o.fetch,e.fetch=o.fetch,e.Headers=o.Headers,e.Request=o.Request,e.Response=o.Response,t.exports=e},215:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const n=r(965);class o extends n.StorageBucketApi{constructor(t,e={}){super(t,e)}from(t){return new n.StorageFileApi(this.url,this.headers,t)}}e.SupabaseStorageClient=o},341:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const i=r(215);Object.defineProperty(e,"SupabaseStorageClient",{enumerable:!0,get:function(){return i.SupabaseStorageClient}}),o(r(717),e)},150:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageBucketApi=void 0;const o=r(716);e.StorageBucketApi=class{constructor(t,e={}){this.url=t,this.headers=e}listBuckets(){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}getBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(`${this.url}/bucket/${t}`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createBucket(t,e={public:!1}){return n(this,void 0,void 0,(function*(){try{return{data:(yield o.post(`${this.url}/bucket`,{id:t,name:t,public:e.public},{headers:this.headers})).name,error:null}}catch(t){return{data:null,error:t}}}))}updateBucket(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield o.put(`${this.url}/bucket/${t}`,{id:t,name:t,public:e.public},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}emptyBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.post(`${this.url}/bucket/${t}/empty`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}deleteBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.remove(`${this.url}/bucket/${t}`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}}},948:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageFileApi=void 0;const i=r(716),s=o(r(98)),a={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},u={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};e.StorageFileApi=class{constructor(t,e={},r){this.url=t,this.headers=e,this.bucketId=r}uploadOrUpdate(t,e,r,o){return n(this,void 0,void 0,(function*(){try{let n;const i=Object.assign(Object.assign({},u),o),a=Object.assign(Object.assign({},this.headers),"POST"===t&&{"x-upsert":String(i.upsert)});"undefined"!=typeof Blob&&r instanceof Blob?(n=new FormData,n.append("cacheControl",i.cacheControl),n.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(n=r,n.append("cacheControl",i.cacheControl)):(n=r,a["cache-control"]=`max-age=${i.cacheControl}`,a["content-type"]=i.contentType);const c=this._getFinalPath(e),d=yield s.default(`${this.url}/object/${c}`,{method:t,body:n,headers:a});return d.ok?{data:{Key:c},error:null}:{data:null,error:yield d.json()}}catch(t){return{data:null,error:t}}}))}upload(t,e,r){return n(this,void 0,void 0,(function*(){return this.uploadOrUpdate("POST",t,e,r)}))}update(t,e,r){return n(this,void 0,void 0,(function*(){return this.uploadOrUpdate("PUT",t,e,r)}))}move(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield i.post(`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createSignedUrl(t,e){return n(this,void 0,void 0,(function*(){try{const r=this._getFinalPath(t);let n=yield i.post(`${this.url}/object/sign/${r}`,{expiresIn:e},{headers:this.headers});const o=`${this.url}${n.signedURL}`;return n={signedURL:o},{data:n,error:null,signedURL:o}}catch(t){return{data:null,error:t,signedURL:null}}}))}download(t){return n(this,void 0,void 0,(function*(){try{const e=this._getFinalPath(t),r=yield i.get(`${this.url}/object/${e}`,{headers:this.headers,noResolveJson:!0});return{data:yield r.blob(),error:null}}catch(t){return{data:null,error:t}}}))}getPublicUrl(t){try{const e=this._getFinalPath(t),r=`${this.url}/object/public/${e}`;return{data:{publicURL:r},error:null,publicURL:r}}catch(t){return{data:null,error:t,publicURL:null}}}remove(t){return n(this,void 0,void 0,(function*(){try{return{data:yield i.remove(`${this.url}/object/${this.bucketId}`,{prefixes:t},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}list(t,e,r){return n(this,void 0,void 0,(function*(){try{const n=Object.assign(Object.assign(Object.assign({},a),e),{prefix:t||""});return{data:yield i.post(`${this.url}/object/list/${this.bucketId}`,n,{headers:this.headers},r),error:null}}catch(t){return{data:null,error:t}}}))}_getFinalPath(t){return`${this.bucketId}/${t}`}}},716:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.remove=e.put=e.post=e.get=void 0;const i=o(r(98)),s=t=>t.msg||t.message||t.error_description||t.error||JSON.stringify(t);function a(t,e,r,o,a){return n(this,void 0,void 0,(function*(){return new Promise(((n,u)=>{i.default(e,((t,e,r,n)=>{const o={method:t,headers:(null==e?void 0:e.headers)||{}};return"GET"===t?o:(o.headers=Object.assign({"Content-Type":"application/json"},null==e?void 0:e.headers),o.body=JSON.stringify(n),Object.assign(Object.assign({},o),r))})(t,r,o,a)).then((t=>{if(!t.ok)throw t;return(null==r?void 0:r.noResolveJson)?n(t):t.json()})).then((t=>n(t))).catch((t=>((t,e)=>{if("function"!=typeof t.json)return e(t);t.json().then((r=>e({message:s(r),status:(null==t?void 0:t.status)||500})))})(t,u)))}))}))}e.get=function(t,e,r){return n(this,void 0,void 0,(function*(){return a("GET",t,e,r)}))},e.post=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("POST",t,r,o,e)}))},e.put=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("PUT",t,r,o,e)}))},e.remove=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("DELETE",t,r,o,e)}))}},965:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(150),e),o(r(948),e),o(r(717),e)},717:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})}},e={},function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(341);var t,e}));
{
"name": "@supabase/storage-js",
"version": "1.2.2",
"version": "1.3.0",
"description": "Isomorphic storage client for Supabase.",

@@ -5,0 +5,0 @@ "keywords": [

import { FetchParameters, get, post, remove } from './fetch'
import { isBrowser } from './helpers'
import { FileObject, FileOptions, SearchOptions } from './types'
import fetch from 'cross-fetch'

@@ -16,2 +17,3 @@ const DEFAULT_SEARCH_OPTIONS = {

cacheControl: '3600',
contentType: 'text/plain;charset=UTF-8',
upsert: false,

@@ -32,30 +34,52 @@ }

/**
* Uploads a file to an existing bucket.
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
*
* @param method HTTP method.
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param file The File object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
async upload(
private async uploadOrUpdate(
method: 'POST' | 'PUT',
path: string,
file: File,
fileBody:
| ArrayBuffer
| ArrayBufferView
| Blob
| File
| FormData
| ReadableStream<Uint8Array>
| URLSearchParams
| string,
fileOptions?: FileOptions
): Promise<{ data: { Key: string } | null; error: Error | null }> {
try {
if (!isBrowser()) throw new Error('No browser detected.')
let body
const options = { ...DEFAULT_FILE_OPTIONS, ...fileOptions }
const headers: Record<string, string> = {
...this.headers,
...(method === 'POST' && { 'x-upsert': String(options.upsert as boolean) }),
}
const formData = new FormData()
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
body = new FormData()
body.append('cacheControl', options.cacheControl as string)
body.append('', fileBody)
} else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
body = fileBody
body.append('cacheControl', options.cacheControl as string)
} else {
body = fileBody
headers['cache-control'] = `max-age=${options.cacheControl}`
headers['content-type'] = options.contentType as string
}
const options = { ...DEFAULT_FILE_OPTIONS, ...fileOptions }
formData.append('cacheControl', options.cacheControl)
formData.append('', file, file.name)
const _path = this._getFinalPath(path)
const res = await fetch(`${this.url}/object/${_path}`, {
method: 'POST',
body: formData,
headers: {
...this.headers,
'x-upsert': String(fileOptions?.upsert),
},
method,
body,
headers,
})

@@ -77,40 +101,51 @@

/**
* Uploads a file to an existing bucket.
*
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
async upload(
path: string,
fileBody:
| ArrayBuffer
| ArrayBufferView
| Blob
| File
| FormData
| ReadableStream<Uint8Array>
| URLSearchParams
| string,
fileOptions?: FileOptions
): Promise<{ data: { Key: string } | null; error: Error | null }> {
return this.uploadOrUpdate('POST', path, fileBody, fileOptions)
}
/**
* Replaces an existing file at the specified path with a new one.
*
* @param path The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
* @param file The file object to be stored in the bucket.
* @param fileOptions HTTP headers. For example `cacheControl`
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
* @param fileBody The body of the file to be stored in the bucket.
* @param fileOptions HTTP headers.
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
* `upsert`: boolean, whether to perform an upsert.
*/
async update(
path: string,
file: File,
fileBody:
| ArrayBuffer
| ArrayBufferView
| Blob
| File
| FormData
| ReadableStream<Uint8Array>
| URLSearchParams
| string,
fileOptions?: FileOptions
): Promise<{ data: { Key: string } | null; error: Error | null }> {
try {
if (!isBrowser()) throw new Error('No browser detected.')
const formData = new FormData()
const options = { ...DEFAULT_FILE_OPTIONS, ...fileOptions }
formData.append('cacheControl', options.cacheControl)
formData.append('', file, file.name)
const _path = this._getFinalPath(path)
const res = await fetch(`${this.url}/object/${_path}`, {
method: 'PUT',
body: formData,
headers: { ...this.headers },
})
if (res.ok) {
// const data = await res.json()
// temporary fix till backend is updated to the latest storage-api version
return { data: { Key: _path }, error: null }
} else {
const error = await res.json()
return { data: null, error }
}
} catch (error) {
return { data: null, error }
}
return this.uploadOrUpdate('PUT', path, fileBody, fileOptions)
}

@@ -117,0 +152,0 @@

@@ -28,3 +28,4 @@ export interface Bucket {

export interface FileOptions {
cacheControl: string
cacheControl?: string
contentType?: string
upsert?: boolean

@@ -31,0 +32,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc