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

@supabase/storage-js

Package Overview
Dependencies
Maintainers
9
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 2.6.0 to 2.7.0

3

dist/main/lib/fetch.d.ts

@@ -9,7 +9,8 @@ import { FetchParameters } from './types';

}
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE';
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
export declare function get(fetcher: Fetch, url: string, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function post(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function put(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function head(fetcher: Fetch, url: string, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function remove(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
//# sourceMappingURL=fetch.d.ts.map

@@ -12,9 +12,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.remove = exports.put = exports.post = exports.get = void 0;
exports.remove = exports.head = exports.put = exports.post = exports.get = void 0;
const errors_1 = require("./errors");
const helpers_1 = require("./helpers");
const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
const handleError = (error, reject) => __awaiter(void 0, void 0, void 0, function* () {
const handleError = (error, reject, options) => __awaiter(void 0, void 0, void 0, function* () {
const Res = yield (0, helpers_1.resolveResponse)();
if (error instanceof Res) {
if (error instanceof Res && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) {
error

@@ -39,3 +39,5 @@ .json()

params.headers = Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers);
params.body = JSON.stringify(body);
if (body) {
params.body = JSON.stringify(body);
}
return Object.assign(Object.assign({}, params), parameters);

@@ -55,3 +57,3 @@ };

.then((data) => resolve(data))
.catch((error) => handleError(error, reject));
.catch((error) => handleError(error, reject, options));
});

@@ -78,2 +80,8 @@ });

exports.put = put;
function head(fetcher, url, options, parameters) {
return __awaiter(this, void 0, void 0, function* () {
return _handleRequest(fetcher, 'HEAD', url, Object.assign(Object.assign({}, options), { noResolveJson: true }), parameters);
});
}
exports.head = head;
function remove(fetcher, url, body, options, parameters) {

@@ -80,0 +88,0 @@ return __awaiter(this, void 0, void 0, function* () {

declare type Fetch = typeof fetch;
export declare const resolveFetch: (customFetch?: typeof fetch | undefined) => Fetch;
export declare const resolveResponse: () => Promise<typeof Response>;
export declare const recursiveToCamel: (item: Record<string, any>) => unknown;
export {};
//# sourceMappingURL=helpers.d.ts.map

@@ -35,3 +35,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveResponse = exports.resolveFetch = void 0;
exports.recursiveToCamel = exports.resolveResponse = exports.resolveFetch = void 0;
const resolveFetch = (customFetch) => {

@@ -59,2 +59,17 @@ let _fetch;

exports.resolveResponse = resolveResponse;
const recursiveToCamel = (item) => {
if (Array.isArray(item)) {
return item.map((el) => (0, exports.recursiveToCamel)(el));
}
else if (typeof item === 'function' || item !== Object(item)) {
return item;
}
const result = {};
Object.entries(item).forEach(([key, value]) => {
const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ''));
result[newKey] = (0, exports.recursiveToCamel)(value);
});
return result;
};
exports.recursiveToCamel = recursiveToCamel;
//# sourceMappingURL=helpers.js.map

@@ -22,2 +22,17 @@ export interface Bucket {

}
export interface FileObjectV2 {
id: string;
version: string;
name: string;
bucket_id: string;
updated_at: string;
created_at: string;
last_accessed_at: string;
size?: number;
cache_control?: string;
content_type?: string;
etag?: string;
last_modified?: string;
metadata?: Record<string, any>;
}
export interface SortBy {

@@ -44,2 +59,10 @@ column?: string;

duplex?: string;
/**
* The metadata option is an object that allows you to store additional information about the file. This information can be used to filter and search for files. The metadata object can contain any key-value pairs you want to store.
*/
metadata?: Record<string, any>;
/**
* Optionally add extra headers
*/
headers?: Record<string, string>;
}

@@ -106,2 +129,7 @@ export interface DestinationOptions {

}
declare type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : S;
export declare type Camelize<T> = {
[K in keyof T as CamelCase<Extract<K, string>>]: T[K];
};
export {};
//# sourceMappingURL=types.d.ts.map

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

export declare const version = "2.6.0";
export declare const version = "2.7.0";
//# sourceMappingURL=version.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

// generated by genversion
exports.version = '2.6.0';
exports.version = '2.7.0';
//# sourceMappingURL=version.js.map
/// <reference types="node" />
import { StorageError } from '../lib/errors';
import { Fetch } from '../lib/fetch';
import { FileObject, FileOptions, SearchOptions, FetchParameters, TransformOptions, DestinationOptions } from '../lib/types';
import { FileObject, FileOptions, SearchOptions, FetchParameters, TransformOptions, DestinationOptions, FileObjectV2, Camelize } from '../lib/types';
declare type FileBody = ArrayBuffer | ArrayBufferView | Blob | Buffer | File | FormData | NodeJS.ReadableStream | ReadableStream<Uint8Array> | URLSearchParams | string;

@@ -182,2 +182,24 @@ export default class StorageFileApi {

/**
* Retrieves the details of an existing file.
* @param path
*/
info(path: string): Promise<{
data: Camelize<FileObjectV2>;
error: null;
} | {
data: null;
error: StorageError;
}>;
/**
* Checks the existence of a file.
* @param path
*/
exists(path: string): Promise<{
data: boolean;
error: null;
} | {
data: boolean;
error: StorageError;
}>;
/**
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

@@ -230,2 +252,4 @@ * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.

}>;
protected encodeMetadata(metadata: Record<string, any>): string;
toBase64(data: string): string;
private _getFinalPath;

@@ -232,0 +256,0 @@ private _removeEmptyFolders;

@@ -47,3 +47,4 @@ "use strict";

const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
const headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
let headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
const metadata = options.metadata;
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {

@@ -53,2 +54,5 @@ body = new FormData();

body.append('', fileBody);
if (metadata) {
body.append('metadata', this.encodeMetadata(metadata));
}
}

@@ -58,2 +62,5 @@ else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {

body.append('cacheControl', options.cacheControl);
if (metadata) {
body.append('metadata', this.encodeMetadata(metadata));
}
}

@@ -64,3 +71,9 @@ else {

headers['content-type'] = options.contentType;
if (metadata) {
headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata));
}
}
if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) {
headers = Object.assign(Object.assign({}, headers), fileOptions.headers);
}
const cleanPath = this._removeEmptyFolders(path);

@@ -336,2 +349,47 @@ const _path = this._getFinalPath(cleanPath);

/**
* Retrieves the details of an existing file.
* @param path
*/
info(path) {
return __awaiter(this, void 0, void 0, function* () {
const _path = this._getFinalPath(path);
try {
const data = yield (0, fetch_1.get)(this.fetch, `${this.url}/object/info/${_path}`, {
headers: this.headers,
});
return { data: (0, helpers_1.recursiveToCamel)(data), error: null };
}
catch (error) {
if ((0, errors_1.isStorageError)(error)) {
return { data: null, error };
}
throw error;
}
});
}
/**
* Checks the existence of a file.
* @param path
*/
exists(path) {
return __awaiter(this, void 0, void 0, function* () {
const _path = this._getFinalPath(path);
try {
yield (0, fetch_1.head)(this.fetch, `${this.url}/object/${_path}`, {
headers: this.headers,
});
return { data: true, error: null };
}
catch (error) {
if ((0, errors_1.isStorageError)(error) && error instanceof errors_1.StorageUnknownError) {
const originalError = error.originalError;
if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) {
return { data: false, error };
}
}
throw error;
}
});
}
/**
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

@@ -464,2 +522,11 @@ * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.

}
encodeMetadata(metadata) {
return JSON.stringify(metadata);
}
toBase64(data) {
if (typeof Buffer !== 'undefined') {
return Buffer.from(data).toString('base64');
}
return btoa(data);
}
_getFinalPath(path) {

@@ -466,0 +533,0 @@ return `${this.bucketId}/${path}`;

@@ -9,7 +9,8 @@ import { FetchParameters } from './types';

}
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE';
export declare type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
export declare function get(fetcher: Fetch, url: string, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function post(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function put(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function head(fetcher: Fetch, url: string, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
export declare function remove(fetcher: Fetch, url: string, body: object, options?: FetchOptions, parameters?: FetchParameters): Promise<any>;
//# sourceMappingURL=fetch.d.ts.map

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

const _getErrorMessage = (err) => err.msg || err.message || err.error_description || err.error || JSON.stringify(err);
const handleError = (error, reject) => __awaiter(void 0, void 0, void 0, function* () {
const handleError = (error, reject, options) => __awaiter(void 0, void 0, void 0, function* () {
const Res = yield resolveResponse();
if (error instanceof Res) {
if (error instanceof Res && !(options === null || options === void 0 ? void 0 : options.noResolveJson)) {
error

@@ -36,3 +36,5 @@ .json()

params.headers = Object.assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers);
params.body = JSON.stringify(body);
if (body) {
params.body = JSON.stringify(body);
}
return Object.assign(Object.assign({}, params), parameters);

@@ -52,3 +54,3 @@ };

.then((data) => resolve(data))
.catch((error) => handleError(error, reject));
.catch((error) => handleError(error, reject, options));
});

@@ -72,2 +74,7 @@ });

}
export function head(fetcher, url, options, parameters) {
return __awaiter(this, void 0, void 0, function* () {
return _handleRequest(fetcher, 'HEAD', url, Object.assign(Object.assign({}, options), { noResolveJson: true }), parameters);
});
}
export function remove(fetcher, url, body, options, parameters) {

@@ -74,0 +81,0 @@ return __awaiter(this, void 0, void 0, function* () {

declare type Fetch = typeof fetch;
export declare const resolveFetch: (customFetch?: typeof fetch | undefined) => Fetch;
export declare const resolveResponse: () => Promise<typeof Response>;
export declare const recursiveToCamel: (item: Record<string, any>) => unknown;
export {};
//# sourceMappingURL=helpers.d.ts.map

@@ -30,2 +30,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

});
export const recursiveToCamel = (item) => {
if (Array.isArray(item)) {
return item.map((el) => recursiveToCamel(el));
}
else if (typeof item === 'function' || item !== Object(item)) {
return item;
}
const result = {};
Object.entries(item).forEach(([key, value]) => {
const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ''));
result[newKey] = recursiveToCamel(value);
});
return result;
};
//# sourceMappingURL=helpers.js.map

@@ -22,2 +22,17 @@ export interface Bucket {

}
export interface FileObjectV2 {
id: string;
version: string;
name: string;
bucket_id: string;
updated_at: string;
created_at: string;
last_accessed_at: string;
size?: number;
cache_control?: string;
content_type?: string;
etag?: string;
last_modified?: string;
metadata?: Record<string, any>;
}
export interface SortBy {

@@ -44,2 +59,10 @@ column?: string;

duplex?: string;
/**
* The metadata option is an object that allows you to store additional information about the file. This information can be used to filter and search for files. The metadata object can contain any key-value pairs you want to store.
*/
metadata?: Record<string, any>;
/**
* Optionally add extra headers
*/
headers?: Record<string, string>;
}

@@ -106,2 +129,7 @@ export interface DestinationOptions {

}
declare type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : S;
export declare type Camelize<T> = {
[K in keyof T as CamelCase<Extract<K, string>>]: T[K];
};
export {};
//# sourceMappingURL=types.d.ts.map

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

export declare const version = "2.6.0";
export declare const version = "2.7.0";
//# sourceMappingURL=version.d.ts.map
// generated by genversion
export const version = '2.6.0';
export const version = '2.7.0';
//# sourceMappingURL=version.js.map
/// <reference types="node" />
import { StorageError } from '../lib/errors';
import { Fetch } from '../lib/fetch';
import { FileObject, FileOptions, SearchOptions, FetchParameters, TransformOptions, DestinationOptions } from '../lib/types';
import { FileObject, FileOptions, SearchOptions, FetchParameters, TransformOptions, DestinationOptions, FileObjectV2, Camelize } from '../lib/types';
declare type FileBody = ArrayBuffer | ArrayBufferView | Blob | Buffer | File | FormData | NodeJS.ReadableStream | ReadableStream<Uint8Array> | URLSearchParams | string;

@@ -182,2 +182,24 @@ export default class StorageFileApi {

/**
* Retrieves the details of an existing file.
* @param path
*/
info(path: string): Promise<{
data: Camelize<FileObjectV2>;
error: null;
} | {
data: null;
error: StorageError;
}>;
/**
* Checks the existence of a file.
* @param path
*/
exists(path: string): Promise<{
data: boolean;
error: null;
} | {
data: boolean;
error: StorageError;
}>;
/**
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

@@ -230,2 +252,4 @@ * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.

}>;
protected encodeMetadata(metadata: Record<string, any>): string;
toBase64(data: string): string;
private _getFinalPath;

@@ -232,0 +256,0 @@ private _removeEmptyFolders;

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

};
import { isStorageError, StorageError } from '../lib/errors';
import { get, post, remove } from '../lib/fetch';
import { resolveFetch } from '../lib/helpers';
import { isStorageError, StorageError, StorageUnknownError } from '../lib/errors';
import { get, head, post, remove } from '../lib/fetch';
import { recursiveToCamel, resolveFetch } from '../lib/helpers';
const DEFAULT_SEARCH_OPTIONS = {

@@ -46,3 +46,4 @@ limit: 100,

const options = Object.assign(Object.assign({}, DEFAULT_FILE_OPTIONS), fileOptions);
const headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
let headers = Object.assign(Object.assign({}, this.headers), (method === 'POST' && { 'x-upsert': String(options.upsert) }));
const metadata = options.metadata;
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {

@@ -52,2 +53,5 @@ body = new FormData();

body.append('', fileBody);
if (metadata) {
body.append('metadata', this.encodeMetadata(metadata));
}
}

@@ -57,2 +61,5 @@ else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {

body.append('cacheControl', options.cacheControl);
if (metadata) {
body.append('metadata', this.encodeMetadata(metadata));
}
}

@@ -63,3 +70,9 @@ else {

headers['content-type'] = options.contentType;
if (metadata) {
headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata));
}
}
if (fileOptions === null || fileOptions === void 0 ? void 0 : fileOptions.headers) {
headers = Object.assign(Object.assign({}, headers), fileOptions.headers);
}
const cleanPath = this._removeEmptyFolders(path);

@@ -335,2 +348,47 @@ const _path = this._getFinalPath(cleanPath);

/**
* Retrieves the details of an existing file.
* @param path
*/
info(path) {
return __awaiter(this, void 0, void 0, function* () {
const _path = this._getFinalPath(path);
try {
const data = yield get(this.fetch, `${this.url}/object/info/${_path}`, {
headers: this.headers,
});
return { data: recursiveToCamel(data), error: null };
}
catch (error) {
if (isStorageError(error)) {
return { data: null, error };
}
throw error;
}
});
}
/**
* Checks the existence of a file.
* @param path
*/
exists(path) {
return __awaiter(this, void 0, void 0, function* () {
const _path = this._getFinalPath(path);
try {
yield head(this.fetch, `${this.url}/object/${_path}`, {
headers: this.headers,
});
return { data: true, error: null };
}
catch (error) {
if (isStorageError(error) && error instanceof StorageUnknownError) {
const originalError = error.originalError;
if ([400, 404].includes(originalError === null || originalError === void 0 ? void 0 : originalError.status)) {
return { data: false, error };
}
}
throw error;
}
});
}
/**
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

@@ -463,2 +521,11 @@ * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.

}
encodeMetadata(metadata) {
return JSON.stringify(metadata);
}
toBase64(data) {
if (typeof Buffer !== 'undefined') {
return Buffer.from(data).toString('base64');
}
return btoa(data);
}
_getFinalPath(path) {

@@ -465,0 +532,0 @@ return `${this.bucketId}/${path}`;

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.supabase=t():e.supabase=t()}(self,(()=>(()=>{"use strict";var e={743:(e,t,r)=>{var o=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r.g)return r.g;throw new Error("unable to locate global object")}();e.exports=t=o.fetch,o.fetch&&(t.default=o.fetch.bind(o)),t.Headers=o.Headers,t.Request=o.Request,t.Response=o.Response},274:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.StorageClient=void 0;const n=o(r(981)),i=o(r(436));class s extends i.default{constructor(e,t={},r){super(e,t,r)}from(e){return new n.default(this.url,this.headers,e,this.fetch)}}t.StorageClient=s},341:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.StorageClient=void 0;var i=r(274);Object.defineProperty(t,"StorageClient",{enumerable:!0,get:function(){return i.StorageClient}}),n(r(717),t),n(r(752),t)},678:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_HEADERS=void 0;const o=r(506);t.DEFAULT_HEADERS={"X-Client-Info":`storage-js/${o.version}`}},752:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StorageUnknownError=t.StorageApiError=t.isStorageError=t.StorageError=void 0;class r extends Error{constructor(e){super(e),this.__isStorageError=!0,this.name="StorageError"}}t.StorageError=r,t.isStorageError=function(e){return"object"==typeof e&&null!==e&&"__isStorageError"in e},t.StorageApiError=class extends r{constructor(e,t){super(e),this.name="StorageApiError",this.status=t}toJSON(){return{name:this.name,message:this.message,status:this.status}}},t.StorageUnknownError=class extends r{constructor(e,t){super(e),this.name="StorageUnknownError",this.originalError=t}}},716:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.remove=t.put=t.post=t.get=void 0;const n=r(752),i=r(610),s=e=>e.msg||e.message||e.error_description||e.error||JSON.stringify(e);function a(e,t,r,a,u,c){return o(this,void 0,void 0,(function*(){return new Promise(((d,l)=>{e(r,((e,t,r,o)=>{const n={method:e,headers:(null==t?void 0:t.headers)||{}};return"GET"===e?n:(n.headers=Object.assign({"Content-Type":"application/json"},null==t?void 0:t.headers),n.body=JSON.stringify(o),Object.assign(Object.assign({},n),r))})(t,a,u,c)).then((e=>{if(!e.ok)throw e;return(null==a?void 0:a.noResolveJson)?e:e.json()})).then((e=>d(e))).catch((e=>((e,t)=>o(void 0,void 0,void 0,(function*(){const r=yield(0,i.resolveResponse)();e instanceof r?e.json().then((r=>{t(new n.StorageApiError(s(r),e.status||500))})).catch((e=>{t(new n.StorageUnknownError(s(e),e))})):t(new n.StorageUnknownError(s(e),e))})))(e,l)))}))}))}t.get=function(e,t,r,n){return o(this,void 0,void 0,(function*(){return a(e,"GET",t,r,n)}))},t.post=function(e,t,r,n,i){return o(this,void 0,void 0,(function*(){return a(e,"POST",t,n,i,r)}))},t.put=function(e,t,r,n,i){return o(this,void 0,void 0,(function*(){return a(e,"PUT",t,n,i,r)}))},t.remove=function(e,t,r,n,i){return o(this,void 0,void 0,(function*(){return a(e,"DELETE",t,n,i,r)}))}},610:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.resolveResponse=t.resolveFetch=void 0,t.resolveFetch=e=>{let t;return t=e||("undefined"==typeof fetch?(...e)=>Promise.resolve().then((()=>i(r(743)))).then((({default:t})=>t(...e))):fetch),(...e)=>t(...e)},t.resolveResponse=()=>s(void 0,void 0,void 0,(function*(){return"undefined"==typeof Response?(yield Promise.resolve().then((()=>i(r(743))))).Response:Response}))},717:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},506:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.version=void 0,t.version="0.0.0"},436:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=r(678),i=r(752),s=r(716),a=r(610);t.default=class{constructor(e,t={},r){this.url=e,this.headers=Object.assign(Object.assign({},n.DEFAULT_HEADERS),t),this.fetch=(0,a.resolveFetch)(r)}listBuckets(){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}getBucket(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}createBucket(e,t={public:!1}){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket`,{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}updateBucket(e,t){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.put)(this.fetch,`${this.url}/bucket/${e}`,{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}emptyBucket(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}deleteBucket(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.remove)(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}}},981:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=r(752),i=r(716),s=r(610),a={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},u={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};t.default=class{constructor(e,t={},r,o){this.url=e,this.headers=t,this.bucketId=r,this.fetch=(0,s.resolveFetch)(o)}uploadOrUpdate(e,t,r,i){return o(this,void 0,void 0,(function*(){try{let o;const n=Object.assign(Object.assign({},u),i),s=Object.assign(Object.assign({},this.headers),"POST"===e&&{"x-upsert":String(n.upsert)});"undefined"!=typeof Blob&&r instanceof Blob?(o=new FormData,o.append("cacheControl",n.cacheControl),o.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(o=r,o.append("cacheControl",n.cacheControl)):(o=r,s["cache-control"]=`max-age=${n.cacheControl}`,s["content-type"]=n.contentType);const a=this._removeEmptyFolders(t),c=this._getFinalPath(a),d=yield this.fetch(`${this.url}/object/${c}`,Object.assign({method:e,body:o,headers:s},(null==n?void 0:n.duplex)?{duplex:n.duplex}:{})),l=yield d.json();return d.ok?{data:{path:a,id:l.Id,fullPath:l.Key},error:null}:{data:null,error:l}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}upload(e,t,r){return o(this,void 0,void 0,(function*(){return this.uploadOrUpdate("POST",e,t,r)}))}uploadToSignedUrl(e,t,r,i){return o(this,void 0,void 0,(function*(){const o=this._removeEmptyFolders(e),s=this._getFinalPath(o),a=new URL(this.url+`/object/upload/sign/${s}`);a.searchParams.set("token",t);try{let e;const t=Object.assign({upsert:u.upsert},i),n=Object.assign(Object.assign({},this.headers),{"x-upsert":String(t.upsert)});"undefined"!=typeof Blob&&r instanceof Blob?(e=new FormData,e.append("cacheControl",t.cacheControl),e.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(e=r,e.append("cacheControl",t.cacheControl)):(e=r,n["cache-control"]=`max-age=${t.cacheControl}`,n["content-type"]=t.contentType);const s=yield this.fetch(a.toString(),{method:"PUT",body:e,headers:n}),c=yield s.json();return s.ok?{data:{path:o,fullPath:c.Key},error:null}:{data:null,error:c}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}createSignedUploadUrl(e,t){return o(this,void 0,void 0,(function*(){try{let r=this._getFinalPath(e);const o=Object.assign({},this.headers);(null==t?void 0:t.upsert)&&(o["x-upsert"]="true");const s=yield(0,i.post)(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:o}),a=new URL(this.url+s.url),u=a.searchParams.get("token");if(!u)throw new n.StorageError("No token returned by API");return{data:{signedUrl:a.toString(),path:e,token:u},error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}update(e,t,r){return o(this,void 0,void 0,(function*(){return this.uploadOrUpdate("PUT",e,t,r)}))}move(e,t,r){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,i.post)(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers}),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}copy(e,t,r){return o(this,void 0,void 0,(function*(){try{return{data:{path:(yield(0,i.post)(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers})).Key},error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}createSignedUrl(e,t,r){return o(this,void 0,void 0,(function*(){try{let o=this._getFinalPath(e),n=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${o}`,Object.assign({expiresIn:t},(null==r?void 0:r.transform)?{transform:r.transform}:{}),{headers:this.headers});const s=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return n={signedUrl:encodeURI(`${this.url}${n.signedURL}${s}`)},{data:n,error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}createSignedUrls(e,t,r){return o(this,void 0,void 0,(function*(){try{const o=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),n=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return{data:o.map((e=>Object.assign(Object.assign({},e),{signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${n}`):null}))),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}download(e,t){return o(this,void 0,void 0,(function*(){const r=void 0!==(null==t?void 0:t.transform)?"render/image/authenticated":"object",o=this.transformOptsToQueryString((null==t?void 0:t.transform)||{}),s=o?`?${o}`:"";try{const t=this._getFinalPath(e),o=yield(0,i.get)(this.fetch,`${this.url}/${r}/${t}${s}`,{headers:this.headers,noResolveJson:!0});return{data:yield o.blob(),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}getPublicUrl(e,t){const r=this._getFinalPath(e),o=[],n=(null==t?void 0:t.download)?`download=${!0===t.download?"":t.download}`:"";""!==n&&o.push(n);const i=void 0!==(null==t?void 0:t.transform)?"render/image":"object",s=this.transformOptsToQueryString((null==t?void 0:t.transform)||{});""!==s&&o.push(s);let a=o.join("&");return""!==a&&(a=`?${a}`),{data:{publicUrl:encodeURI(`${this.url}/${i}/public/${r}${a}`)}}}remove(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,i.remove)(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}list(e,t,r){return o(this,void 0,void 0,(function*(){try{const o=Object.assign(Object.assign(Object.assign({},a),t),{prefix:e||""});return{data:yield(0,i.post)(this.fetch,`${this.url}/object/list/${this.bucketId}`,o,{headers:this.headers},r),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}_getFinalPath(e){return`${this.bucketId}/${e}`}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")}transformOptsToQueryString(e){const t=[];return e.width&&t.push(`width=${e.width}`),e.height&&t.push(`height=${e.height}`),e.resize&&t.push(`resize=${e.resize}`),e.format&&t.push(`format=${e.format}`),e.quality&&t.push(`quality=${e.quality}`),t.join("&")}}}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}return r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r(341)})()));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.supabase=t():e.supabase=t()}(self,(()=>(()=>{"use strict";var e={743:(e,t,r)=>{var o=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if(void 0!==r.g)return r.g;throw new Error("unable to locate global object")}();e.exports=t=o.fetch,o.fetch&&(t.default=o.fetch.bind(o)),t.Headers=o.Headers,t.Request=o.Request,t.Response=o.Response},274:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.StorageClient=void 0;const n=o(r(981)),i=o(r(436));class s extends i.default{constructor(e,t={},r){super(e,t,r)}from(e){return new n.default(this.url,this.headers,e,this.fetch)}}t.StorageClient=s},341:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.StorageClient=void 0;var i=r(274);Object.defineProperty(t,"StorageClient",{enumerable:!0,get:function(){return i.StorageClient}}),n(r(717),t),n(r(752),t)},678:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_HEADERS=void 0;const o=r(506);t.DEFAULT_HEADERS={"X-Client-Info":`storage-js/${o.version}`}},752:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StorageUnknownError=t.StorageApiError=t.isStorageError=t.StorageError=void 0;class r extends Error{constructor(e){super(e),this.__isStorageError=!0,this.name="StorageError"}}t.StorageError=r,t.isStorageError=function(e){return"object"==typeof e&&null!==e&&"__isStorageError"in e},t.StorageApiError=class extends r{constructor(e,t){super(e),this.name="StorageApiError",this.status=t}toJSON(){return{name:this.name,message:this.message,status:this.status}}},t.StorageUnknownError=class extends r{constructor(e,t){super(e),this.name="StorageUnknownError",this.originalError=t}}},716:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.remove=t.head=t.put=t.post=t.get=void 0;const n=r(752),i=r(610),s=e=>e.msg||e.message||e.error_description||e.error||JSON.stringify(e);function a(e,t,r,a,u,c){return o(this,void 0,void 0,(function*(){return new Promise(((d,l)=>{e(r,((e,t,r,o)=>{const n={method:e,headers:(null==t?void 0:t.headers)||{}};return"GET"===e?n:(n.headers=Object.assign({"Content-Type":"application/json"},null==t?void 0:t.headers),o&&(n.body=JSON.stringify(o)),Object.assign(Object.assign({},n),r))})(t,a,u,c)).then((e=>{if(!e.ok)throw e;return(null==a?void 0:a.noResolveJson)?e:e.json()})).then((e=>d(e))).catch((e=>((e,t,r)=>o(void 0,void 0,void 0,(function*(){const o=yield(0,i.resolveResponse)();e instanceof o&&!(null==r?void 0:r.noResolveJson)?e.json().then((r=>{t(new n.StorageApiError(s(r),e.status||500))})).catch((e=>{t(new n.StorageUnknownError(s(e),e))})):t(new n.StorageUnknownError(s(e),e))})))(e,l,a)))}))}))}t.get=function(e,t,r,n){return o(this,void 0,void 0,(function*(){return a(e,"GET",t,r,n)}))},t.post=function(e,t,r,n,i){return o(this,void 0,void 0,(function*(){return a(e,"POST",t,n,i,r)}))},t.put=function(e,t,r,n,i){return o(this,void 0,void 0,(function*(){return a(e,"PUT",t,n,i,r)}))},t.head=function(e,t,r,n){return o(this,void 0,void 0,(function*(){return a(e,"HEAD",t,Object.assign(Object.assign({},r),{noResolveJson:!0}),n)}))},t.remove=function(e,t,r,n,i){return o(this,void 0,void 0,(function*(){return a(e,"DELETE",t,n,i,r)}))}},610:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&o(t,e,r);return n(t,e),t},s=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.recursiveToCamel=t.resolveResponse=t.resolveFetch=void 0,t.resolveFetch=e=>{let t;return t=e||("undefined"==typeof fetch?(...e)=>Promise.resolve().then((()=>i(r(743)))).then((({default:t})=>t(...e))):fetch),(...e)=>t(...e)},t.resolveResponse=()=>s(void 0,void 0,void 0,(function*(){return"undefined"==typeof Response?(yield Promise.resolve().then((()=>i(r(743))))).Response:Response})),t.recursiveToCamel=e=>{if(Array.isArray(e))return e.map((e=>(0,t.recursiveToCamel)(e)));if("function"==typeof e||e!==Object(e))return e;const r={};return Object.entries(e).forEach((([e,o])=>{const n=e.replace(/([-_][a-z])/gi,(e=>e.toUpperCase().replace(/[-_]/g,"")));r[n]=(0,t.recursiveToCamel)(o)})),r}},717:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},506:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.version=void 0,t.version="0.0.0"},436:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=r(678),i=r(752),s=r(716),a=r(610);t.default=class{constructor(e,t={},r){this.url=e,this.headers=Object.assign(Object.assign({},n.DEFAULT_HEADERS),t),this.fetch=(0,a.resolveFetch)(r)}listBuckets(){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}getBucket(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.get)(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}createBucket(e,t={public:!1}){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket`,{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}updateBucket(e,t){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.put)(this.fetch,`${this.url}/bucket/${e}`,{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}emptyBucket(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.post)(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}deleteBucket(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,s.remove)(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}),error:null}}catch(e){if((0,i.isStorageError)(e))return{data:null,error:e};throw e}}))}}},981:function(e,t,r){var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=r(752),i=r(716),s=r(610),a={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},u={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};t.default=class{constructor(e,t={},r,o){this.url=e,this.headers=t,this.bucketId=r,this.fetch=(0,s.resolveFetch)(o)}uploadOrUpdate(e,t,r,i){return o(this,void 0,void 0,(function*(){try{let o;const n=Object.assign(Object.assign({},u),i);let s=Object.assign(Object.assign({},this.headers),"POST"===e&&{"x-upsert":String(n.upsert)});const a=n.metadata;"undefined"!=typeof Blob&&r instanceof Blob?(o=new FormData,o.append("cacheControl",n.cacheControl),o.append("",r),a&&o.append("metadata",this.encodeMetadata(a))):"undefined"!=typeof FormData&&r instanceof FormData?(o=r,o.append("cacheControl",n.cacheControl),a&&o.append("metadata",this.encodeMetadata(a))):(o=r,s["cache-control"]=`max-age=${n.cacheControl}`,s["content-type"]=n.contentType,a&&(s["x-metadata"]=this.toBase64(this.encodeMetadata(a)))),(null==i?void 0:i.headers)&&(s=Object.assign(Object.assign({},s),i.headers));const c=this._removeEmptyFolders(t),d=this._getFinalPath(c),l=yield this.fetch(`${this.url}/object/${d}`,Object.assign({method:e,body:o,headers:s},(null==n?void 0:n.duplex)?{duplex:n.duplex}:{})),h=yield l.json();return l.ok?{data:{path:c,id:h.Id,fullPath:h.Key},error:null}:{data:null,error:h}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}upload(e,t,r){return o(this,void 0,void 0,(function*(){return this.uploadOrUpdate("POST",e,t,r)}))}uploadToSignedUrl(e,t,r,i){return o(this,void 0,void 0,(function*(){const o=this._removeEmptyFolders(e),s=this._getFinalPath(o),a=new URL(this.url+`/object/upload/sign/${s}`);a.searchParams.set("token",t);try{let e;const t=Object.assign({upsert:u.upsert},i),n=Object.assign(Object.assign({},this.headers),{"x-upsert":String(t.upsert)});"undefined"!=typeof Blob&&r instanceof Blob?(e=new FormData,e.append("cacheControl",t.cacheControl),e.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(e=r,e.append("cacheControl",t.cacheControl)):(e=r,n["cache-control"]=`max-age=${t.cacheControl}`,n["content-type"]=t.contentType);const s=yield this.fetch(a.toString(),{method:"PUT",body:e,headers:n}),c=yield s.json();return s.ok?{data:{path:o,fullPath:c.Key},error:null}:{data:null,error:c}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}createSignedUploadUrl(e,t){return o(this,void 0,void 0,(function*(){try{let r=this._getFinalPath(e);const o=Object.assign({},this.headers);(null==t?void 0:t.upsert)&&(o["x-upsert"]="true");const s=yield(0,i.post)(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:o}),a=new URL(this.url+s.url),u=a.searchParams.get("token");if(!u)throw new n.StorageError("No token returned by API");return{data:{signedUrl:a.toString(),path:e,token:u},error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}update(e,t,r){return o(this,void 0,void 0,(function*(){return this.uploadOrUpdate("PUT",e,t,r)}))}move(e,t,r){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,i.post)(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers}),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}copy(e,t,r){return o(this,void 0,void 0,(function*(){try{return{data:{path:(yield(0,i.post)(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:null==r?void 0:r.destinationBucket},{headers:this.headers})).Key},error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}createSignedUrl(e,t,r){return o(this,void 0,void 0,(function*(){try{let o=this._getFinalPath(e),n=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${o}`,Object.assign({expiresIn:t},(null==r?void 0:r.transform)?{transform:r.transform}:{}),{headers:this.headers});const s=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return n={signedUrl:encodeURI(`${this.url}${n.signedURL}${s}`)},{data:n,error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}createSignedUrls(e,t,r){return o(this,void 0,void 0,(function*(){try{const o=yield(0,i.post)(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),n=(null==r?void 0:r.download)?`&download=${!0===r.download?"":r.download}`:"";return{data:o.map((e=>Object.assign(Object.assign({},e),{signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${n}`):null}))),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}download(e,t){return o(this,void 0,void 0,(function*(){const r=void 0!==(null==t?void 0:t.transform)?"render/image/authenticated":"object",o=this.transformOptsToQueryString((null==t?void 0:t.transform)||{}),s=o?`?${o}`:"";try{const t=this._getFinalPath(e),o=yield(0,i.get)(this.fetch,`${this.url}/${r}/${t}${s}`,{headers:this.headers,noResolveJson:!0});return{data:yield o.blob(),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}info(e){return o(this,void 0,void 0,(function*(){const t=this._getFinalPath(e);try{const e=yield(0,i.get)(this.fetch,`${this.url}/object/info/${t}`,{headers:this.headers});return{data:(0,s.recursiveToCamel)(e),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}exists(e){return o(this,void 0,void 0,(function*(){const t=this._getFinalPath(e);try{return yield(0,i.head)(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if((0,n.isStorageError)(e)&&e instanceof n.StorageUnknownError){const t=e.originalError;if([400,404].includes(null==t?void 0:t.status))return{data:!1,error:e}}throw e}}))}getPublicUrl(e,t){const r=this._getFinalPath(e),o=[],n=(null==t?void 0:t.download)?`download=${!0===t.download?"":t.download}`:"";""!==n&&o.push(n);const i=void 0!==(null==t?void 0:t.transform)?"render/image":"object",s=this.transformOptsToQueryString((null==t?void 0:t.transform)||{});""!==s&&o.push(s);let a=o.join("&");return""!==a&&(a=`?${a}`),{data:{publicUrl:encodeURI(`${this.url}/${i}/public/${r}${a}`)}}}remove(e){return o(this,void 0,void 0,(function*(){try{return{data:yield(0,i.remove)(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}list(e,t,r){return o(this,void 0,void 0,(function*(){try{const o=Object.assign(Object.assign(Object.assign({},a),t),{prefix:e||""});return{data:yield(0,i.post)(this.fetch,`${this.url}/object/list/${this.bucketId}`,o,{headers:this.headers},r),error:null}}catch(e){if((0,n.isStorageError)(e))return{data:null,error:e};throw e}}))}encodeMetadata(e){return JSON.stringify(e)}toBase64(e){return"undefined"!=typeof Buffer?Buffer.from(e).toString("base64"):btoa(e)}_getFinalPath(e){return`${this.bucketId}/${e}`}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")}transformOptsToQueryString(e){const t=[];return e.width&&t.push(`width=${e.width}`),e.height&&t.push(`height=${e.height}`),e.resize&&t.push(`resize=${e.resize}`),e.format&&t.push(`format=${e.format}`),e.quality&&t.push(`quality=${e.quality}`),t.join("&")}}}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}return r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r(341)})()));
{
"name": "@supabase/storage-js",
"version": "2.6.0",
"version": "2.7.0",
"description": "Isomorphic storage client for Supabase.",

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

@@ -14,3 +14,3 @@ import { StorageApiError, StorageUnknownError } from './errors'

export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE'
export type RequestMethodType = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD'

@@ -20,6 +20,10 @@ const _getErrorMessage = (err: any): string =>

const handleError = async (error: unknown, reject: (reason?: any) => void) => {
const handleError = async (
error: unknown,
reject: (reason?: any) => void,
options?: FetchOptions
) => {
const Res = await resolveResponse()
if (error instanceof Res) {
if (error instanceof Res && !options?.noResolveJson) {
error

@@ -51,3 +55,6 @@ .json()

params.headers = { 'Content-Type': 'application/json', ...options?.headers }
params.body = JSON.stringify(body)
if (body) {
params.body = JSON.stringify(body)
}
return { ...params, ...parameters }

@@ -72,3 +79,3 @@ }

.then((data) => resolve(data))
.catch((error) => handleError(error, reject))
.catch((error) => handleError(error, reject, options))
})

@@ -106,2 +113,20 @@ }

export async function head(
fetcher: Fetch,
url: string,
options?: FetchOptions,
parameters?: FetchParameters
): Promise<any> {
return _handleRequest(
fetcher,
'HEAD',
url,
{
...options,
noResolveJson: true,
},
parameters
)
}
export async function remove(

@@ -108,0 +133,0 @@ fetcher: Fetch,

@@ -24,1 +24,17 @@ type Fetch = typeof fetch

}
export const recursiveToCamel = (item: Record<string, any>): unknown => {
if (Array.isArray(item)) {
return item.map((el) => recursiveToCamel(el))
} else if (typeof item === 'function' || item !== Object(item)) {
return item
}
const result: Record<string, any> = {}
Object.entries(item).forEach(([key, value]) => {
const newKey = key.replace(/([-_][a-z])/gi, (c) => c.toUpperCase().replace(/[-_]/g, ''))
result[newKey] = recursiveToCamel(value)
})
return result
}

@@ -24,2 +24,18 @@ export interface Bucket {

export interface FileObjectV2 {
id: string
version: string
name: string
bucket_id: string
updated_at: string
created_at: string
last_accessed_at: string
size?: number
cache_control?: string
content_type?: string
etag?: string
last_modified?: string
metadata?: Record<string, any>
}
export interface SortBy {

@@ -47,2 +63,12 @@ column?: string

duplex?: string
/**
* The metadata option is an object that allows you to store additional information about the file. This information can be used to filter and search for files. The metadata object can contain any key-value pairs you want to store.
*/
metadata?: Record<string, any>
/**
* Optionally add extra headers
*/
headers?: Record<string, string>
}

@@ -118,1 +144,9 @@

}
type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: S
export type Camelize<T> = {
[K in keyof T as CamelCase<Extract<K, string>>]: T[K]
}
// generated by genversion
export const version = '2.6.0'
export const version = '2.7.0'

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

import { isStorageError, StorageError } from '../lib/errors'
import { Fetch, get, post, remove } from '../lib/fetch'
import { resolveFetch } from '../lib/helpers'
import { isStorageError, StorageError, StorageUnknownError } from '../lib/errors'
import { Fetch, get, head, post, remove } from '../lib/fetch'
import { recursiveToCamel, resolveFetch } from '../lib/helpers'
import {

@@ -11,2 +11,4 @@ FileObject,

DestinationOptions,
FileObjectV2,
Camelize,
} from '../lib/types'

@@ -84,3 +86,3 @@

const options = { ...DEFAULT_FILE_OPTIONS, ...fileOptions }
const headers: Record<string, string> = {
let headers: Record<string, string> = {
...this.headers,

@@ -90,2 +92,4 @@ ...(method === 'POST' && { 'x-upsert': String(options.upsert as boolean) }),

const metadata = options.metadata
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {

@@ -95,5 +99,12 @@ body = new FormData()

body.append('', fileBody)
if (metadata) {
body.append('metadata', this.encodeMetadata(metadata))
}
} else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
body = fileBody
body.append('cacheControl', options.cacheControl as string)
if (metadata) {
body.append('metadata', this.encodeMetadata(metadata))
}
} else {

@@ -103,4 +114,12 @@ body = fileBody

headers['content-type'] = options.contentType as string
if (metadata) {
headers['x-metadata'] = this.toBase64(this.encodeMetadata(metadata))
}
}
if (fileOptions?.headers) {
headers = { ...headers, ...fileOptions.headers }
}
const cleanPath = this._removeEmptyFolders(path)

@@ -534,2 +553,72 @@ const _path = this._getFinalPath(cleanPath)

/**
* Retrieves the details of an existing file.
* @param path
*/
async info(
path: string
): Promise<
| {
data: Camelize<FileObjectV2>
error: null
}
| {
data: null
error: StorageError
}
> {
const _path = this._getFinalPath(path)
try {
const data = await get(this.fetch, `${this.url}/object/info/${_path}`, {
headers: this.headers,
})
return { data: recursiveToCamel(data) as Camelize<FileObjectV2>, error: null }
} catch (error) {
if (isStorageError(error)) {
return { data: null, error }
}
throw error
}
}
/**
* Checks the existence of a file.
* @param path
*/
async exists(
path: string
): Promise<
| {
data: boolean
error: null
}
| {
data: boolean
error: StorageError
}
> {
const _path = this._getFinalPath(path)
try {
await head(this.fetch, `${this.url}/object/${_path}`, {
headers: this.headers,
})
return { data: true, error: null }
} catch (error) {
if (isStorageError(error) && error instanceof StorageUnknownError) {
const originalError = (error.originalError as unknown) as { status: number }
if ([400, 404].includes(originalError?.status)) {
return { data: false, error }
}
}
throw error
}
}
/**
* A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset.

@@ -709,2 +798,13 @@ * This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.

protected encodeMetadata(metadata: Record<string, any>) {
return JSON.stringify(metadata)
}
toBase64(data: string) {
if (typeof Buffer !== 'undefined') {
return Buffer.from(data).toString('base64')
}
return btoa(data)
}
private _getFinalPath(path: string) {

@@ -711,0 +811,0 @@ return `${this.bucketId}/${path}`

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

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

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