@supabase/storage-js 2.98.1-canary.0 → 2.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var supabase=(function(e){var t=class extends Error{constructor(e,t=`storage`,n,r){super(e),this.__isStorageError=!0,this.namespace=t,this.name=t===`vectors`?`StorageVectorsError`:`StorageError`,this.status=n,this.statusCode=r}};function n(e){return typeof e==`object`&&!!e&&`__isStorageError`in e}var r=class extends t{constructor(e,t,n,r=`storage`){super(e,r,t,n),this.name=r===`vectors`?`StorageVectorsApiError`:`StorageApiError`,this.status=t,this.statusCode=n}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},i=class extends t{constructor(e,t,n=`storage`){super(e,n),this.name=n===`vectors`?`StorageVectorsUnknownError`:`StorageUnknownError`,this.originalError=t}},a=class extends t{constructor(e){super(e,`vectors`)}};function o(e){return n(e)&&e.namespace===`vectors`}var s=class extends r{constructor(e,t,n){super(e,t,n,`vectors`)}},c=class extends i{constructor(e,t){super(e,t,`vectors`)}};let l=function(e){return e.InternalError=`InternalError`,e.S3VectorConflictException=`S3VectorConflictException`,e.S3VectorNotFoundException=`S3VectorNotFoundException`,e.S3VectorBucketNotEmpty=`S3VectorBucketNotEmpty`,e.S3VectorMaxBucketsExceeded=`S3VectorMaxBucketsExceeded`,e.S3VectorMaxIndexesExceeded=`S3VectorMaxIndexesExceeded`,e}({}),u=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),d=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},f=e=>{if(Array.isArray(e))return e.map(e=>f(e));if(typeof e==`function`||e!==Object(e))return e;let t={};return Object.entries(e).forEach(([e,n])=>{let r=e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(/[-_]/g,``));t[r]=f(n)}),t},p=e=>!e||typeof e!=`string`||e.length===0||e.length>100||e.trim()!==e||e.includes(`/`)||e.includes(`\\`)?!1:/^[\w!.\*'() &$@=;:+,?-]+$/.test(e),m=e=>e.msg||e.message||e.error_description||(typeof e.error==`string`?e.error:e.error?.message)||JSON.stringify(e),h=async(e,t,n,a)=>{if(e&&typeof e==`object`&&`status`in e&&`ok`in e&&typeof e.status==`number`&&!n?.noResolveJson){let n=e,i=n.status||500;if(typeof n.json==`function`)n.json().then(e=>{let n=e?.statusCode||e?.code||i+``;t(new r(m(e),i,n,a))}).catch(()=>{if(a===`vectors`){let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}else{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}});else{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}}else t(new i(m(e),e,a))},g=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};return e===`GET`||e===`HEAD`||!r?{...i,...n}:(d(r)?(i.headers={"Content-Type":`application/json`,...t?.headers},i.body=JSON.stringify(r)):i.body=r,t?.duplex&&(i.duplex=t.duplex),{...i,...n})};async function _(e,t,n,r,i,a,o){return new Promise((s,c)=>{e(n,g(t,r,i,a)).then(e=>{if(!e.ok)throw e;if(r?.noResolveJson)return e;if(o===`vectors`){let t=e.headers.get(`content-type`);if(e.headers.get(`content-length`)===`0`||e.status===204||!t||!t.includes(`application/json`))return{}}return e.json()}).then(e=>s(e)).catch(e=>h(e,c,r,o))})}function v(e=`storage`){return{get:async(t,n,r,i)=>_(t,`GET`,n,r,i,void 0,e),post:async(t,n,r,i,a)=>_(t,`POST`,n,i,a,r,e),put:async(t,n,r,i,a)=>_(t,`PUT`,n,i,a,r,e),head:async(t,n,r,i)=>_(t,`HEAD`,n,{...r,noResolveJson:!0},i,void 0,e),remove:async(t,n,r,i,a)=>_(t,`DELETE`,n,i,a,r,e)}}let{get:y,post:b,put:x,head:S,remove:C}=v(`storage`),w=v(`vectors`);var T=class{constructor(e,t={},n,r=`storage`){this.shouldThrowOnError=!1,this.url=e,this.headers=t,this.fetch=u(n),this.namespace=r}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers={...this.headers,[e]:t},this}async handleOperation(e){try{return{data:await e(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}},E=class{constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t}then(e,t){return this.execute().then(e,t)}async execute(){try{return{data:(await this.downloadFn()).body,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let D;var O=class{static{D=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[D]=`BlobDownloadBuilder`,this.promise=null}asStream(){return new E(this.downloadFn,this.shouldThrowOnError)}then(e,t){return this.getPromise().then(e,t)}catch(e){return this.getPromise().catch(e)}finally(e){return this.getPromise().finally(e)}getPromise(){return this.promise||=this.execute(),this.promise}async execute(){try{return{data:await(await this.downloadFn()).blob(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let k={limit:100,offset:0,sortBy:{column:`name`,order:`asc`}},A={cacheControl:`3600`,contentType:`text/plain;charset=UTF-8`,upsert:!1};var j=class extends T{constructor(e,t={},n,r){super(e,t,r,`storage`),this.bucketId=n}async uploadOrUpdate(e,t,n,r){return this.handleOperation(async()=>{let i,a={...A,...r},o={...this.headers,...e===`POST`&&{"x-upsert":String(a.upsert)}},s=a.metadata;typeof Blob<`u`&&n instanceof Blob?(i=new FormData,i.append(`cacheControl`,a.cacheControl),s&&i.append(`metadata`,this.encodeMetadata(s)),i.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(i=n,i.has(`cacheControl`)||i.append(`cacheControl`,a.cacheControl),s&&!i.has(`metadata`)&&i.append(`metadata`,this.encodeMetadata(s))):(i=n,o[`cache-control`]=`max-age=${a.cacheControl}`,o[`content-type`]=a.contentType,s&&(o[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&i instanceof ReadableStream||i&&typeof i==`object`&&`pipe`in i&&typeof i.pipe==`function`)&&!a.duplex&&(a.duplex=`half`)),r?.headers&&(o={...o,...r.headers});let c=this._removeEmptyFolders(t),l=this._getFinalPath(c),u=await(e==`PUT`?x:b)(this.fetch,`${this.url}/object/${l}`,i,{headers:o,...a?.duplex?{duplex:a.duplex}:{}});return{path:c,id:u.Id,fullPath:u.Key}})}async upload(e,t,n){return this.uploadOrUpdate(`POST`,e,t,n)}async uploadToSignedUrl(e,t,n,r){let i=this._removeEmptyFolders(e),a=this._getFinalPath(i),o=new URL(this.url+`/object/upload/sign/${a}`);return o.searchParams.set(`token`,t),this.handleOperation(async()=>{let e,t={upsert:A.upsert,...r},a={...this.headers,"x-upsert":String(t.upsert)};return typeof Blob<`u`&&n instanceof Blob?(e=new FormData,e.append(`cacheControl`,t.cacheControl),e.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(e=n,e.append(`cacheControl`,t.cacheControl)):(e=n,a[`cache-control`]=`max-age=${t.cacheControl}`,a[`content-type`]=t.contentType),{path:i,fullPath:(await x(this.fetch,o.toString(),e,{headers:a})).Key}})}async createSignedUploadUrl(e,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i={...this.headers};n?.upsert&&(i[`x-upsert`]=`true`);let a=await b(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:i}),o=new URL(this.url+a.url),s=o.searchParams.get(`token`);if(!s)throw new t(`No token returned by API`);return{signedUrl:o.toString(),path:e,token:s}})}async update(e,t,n){return this.uploadOrUpdate(`PUT`,e,t,n)}async move(e,t,n){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket},{headers:this.headers}))}async copy(e,t,n){return this.handleOperation(async()=>({path:(await b(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket},{headers:this.headers})).Key}))}async createSignedUrl(e,t,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i=await b(this.fetch,`${this.url}/object/sign/${r}`,{expiresIn:t,...n?.transform?{transform:n.transform}:{}},{headers:this.headers}),a=n?.download?`&download=${n.download===!0?``:n.download}`:``;return{signedUrl:encodeURI(`${this.url}${i.signedURL}${a}`)}})}async createSignedUrls(e,t,n){return this.handleOperation(async()=>{let r=await b(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),i=n?.download?`&download=${n.download===!0?``:n.download}`:``;return r.map(e=>({...e,signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${i}`):null}))})}download(e,t,n){let r=t?.transform===void 0?`object`:`render/image/authenticated`,i=this.transformOptsToQueryString(t?.transform||{}),a=i?`?${i}`:``,o=this._getFinalPath(e);return new O(()=>y(this.fetch,`${this.url}/${r}/${o}${a}`,{headers:this.headers,noResolveJson:!0},n),this.shouldThrowOnError)}async info(e){let t=this._getFinalPath(e);return this.handleOperation(async()=>f(await y(this.fetch,`${this.url}/object/info/${t}`,{headers:this.headers})))}async exists(e){let t=this._getFinalPath(e);try{return await S(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e)&&e instanceof i){let t=e.originalError;if([400,404].includes(t?.status))return{data:!1,error:e}}throw e}}getPublicUrl(e,t){let n=this._getFinalPath(e),r=[],i=t?.download?`download=${t.download===!0?``:t.download}`:``;i!==``&&r.push(i);let a=t?.transform===void 0?`object`:`render/image`,o=this.transformOptsToQueryString(t?.transform||{});o!==``&&r.push(o);let s=r.join(`&`);return s!==``&&(s=`?${s}`),{data:{publicUrl:encodeURI(`${this.url}/${a}/public/${n}${s}`)}}}async remove(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}))}async list(e,t,n){return this.handleOperation(async()=>{let r={...k,...t,prefix:e||``};return await b(this.fetch,`${this.url}/object/list/${this.bucketId}`,r,{headers:this.headers},n)})}async listV2(e,t){return this.handleOperation(async()=>{let n={...e};return await b(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,n,{headers:this.headers},t)})}encodeMetadata(e){return JSON.stringify(e)}toBase64(e){return typeof Buffer<`u`?Buffer.from(e).toString(`base64`):btoa(e)}_getFinalPath(e){return`${this.bucketId}/${e.replace(/^\/+/,``)}`}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,``).replace(/\/+/g,`/`)}transformOptsToQueryString(e){let 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(`&`)}};let M={"X-Client-Info":`storage-js/2.98.1-canary.0`};var N=class extends T{constructor(e,t={},n,r){let i=new URL(e);r?.useNewHostname&&/supabase\.(co|in|red)$/.test(i.hostname)&&!i.hostname.includes(`storage.supabase.`)&&(i.hostname=i.hostname.replace(`supabase.`,`storage.supabase.`));let a=i.href.replace(/\/$/,``),o={...M,...t};super(a,o,n,`storage`)}async listBuckets(e){return this.handleOperation(async()=>{let t=this.listBucketOptionsToQueryString(e);return await y(this.fetch,`${this.url}/bucket${t}`,{headers:this.headers})})}async getBucket(e){return this.handleOperation(async()=>await y(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}))}async createBucket(e,t={public:!1}){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/bucket`,{id:e,name:e,type:t.type,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}))}async updateBucket(e,t){return this.handleOperation(async()=>await x(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}))}async emptyBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}listBucketOptionsToQueryString(e){let t={};return e&&(`limit`in e&&(t.limit=String(e.limit)),`offset`in e&&(t.offset=String(e.offset)),e.search&&(t.search=e.search),e.sortColumn&&(t.sortColumn=e.sortColumn),e.sortOrder&&(t.sortOrder=e.sortOrder)),Object.keys(t).length>0?`?`+new URLSearchParams(t).toString():``}},P=class extends Error{constructor(e,t){super(e),this.name=`IcebergError`,this.status=t.status,this.icebergType=t.icebergType,this.icebergCode=t.icebergCode,this.details=t.details,this.isCommitStateUnknown=t.icebergType===`CommitStateUnknownException`||[500,502,504].includes(t.status)&&t.icebergType?.includes(`CommitState`)===!0}isNotFound(){return this.status===404}isConflict(){return this.status===409}isAuthenticationTimeout(){return this.status===419}};function F(e,t,n){let r=new URL(t,e);if(n)for(let[e,t]of Object.entries(n))t!==void 0&&r.searchParams.set(e,t);return r.toString()}async function I(e){return!e||e.type===`none`?{}:e.type===`bearer`?{Authorization:`Bearer ${e.token}`}:e.type===`header`?{[e.name]:e.value}:e.type===`custom`?await e.getHeaders():{}}function L(e){let t=e.fetchImpl??globalThis.fetch;return{async request({method:n,path:r,query:i,body:a,headers:o}){let s=F(e.baseUrl,r,i),c=await I(e.auth),l=await t(s,{method:n,headers:{...a?{"Content-Type":`application/json`}:{},...c,...o},body:a?JSON.stringify(a):void 0}),u=await l.text(),d=(l.headers.get(`content-type`)||``).includes(`application/json`),f=d&&u?JSON.parse(u):u;if(!l.ok){let e=d?f:void 0,t=e?.error;throw new P(t?.message??`Request failed with status ${l.status}`,{status:l.status,icebergType:t?.type,icebergCode:t?.code,details:e})}return{status:l.status,headers:l.headers,data:f}}}}function R(e){return e.join(``)}var z=class{constructor(e,t=``){this.client=e,this.prefix=t}async listNamespaces(e){let t=e?{parent:R(e.namespace)}:void 0;return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces`,query:t})).data.namespaces.map(e=>({namespace:e}))}async createNamespace(e,t){let n={namespace:e.namespace,properties:t?.properties};return(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces`,body:n})).data}async dropNamespace(e){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${R(e.namespace)}`})}async loadNamespaceMetadata(e){return{properties:(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${R(e.namespace)}`})).data.properties}}async namespaceExists(e){try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${R(e.namespace)}`}),!0}catch(e){if(e instanceof P&&e.status===404)return!1;throw e}}async createNamespaceIfNotExists(e,t){try{return await this.createNamespace(e,t)}catch(e){if(e instanceof P&&e.status===409)return;throw e}}};function B(e){return e.join(``)}var V=class{constructor(e,t=``,n){this.client=e,this.prefix=t,this.accessDelegation=n}async listTables(e){return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables`})).data.identifiers}async createTable(e,t){let n={};return this.accessDelegation&&(n[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables`,body:t,headers:n})).data.metadata}async updateTable(e,t){let n=await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,body:t});return{"metadata-location":n.data[`metadata-location`],metadata:n.data.metadata}}async dropTable(e,t){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,query:{purgeRequested:String(t?.purge??!1)}})}async loadTable(e){let t={};return this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,headers:t})).data.metadata}async tableExists(e){let t={};this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation);try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,headers:t}),!0}catch(e){if(e instanceof P&&e.status===404)return!1;throw e}}async createTableIfNotExists(e,t){try{return await this.createTable(e,t)}catch(n){if(n instanceof P&&n.status===409)return await this.loadTable({namespace:e.namespace,name:t.name});throw n}}},H=class{constructor(e){let t=`v1`;e.catalogName&&(t+=`/${e.catalogName}`),this.client=L({baseUrl:e.baseUrl.endsWith(`/`)?e.baseUrl:`${e.baseUrl}/`,auth:e.auth,fetchImpl:e.fetch}),this.accessDelegation=e.accessDelegation?.join(`,`),this.namespaceOps=new z(this.client,t),this.tableOps=new V(this.client,t,this.accessDelegation)}async listNamespaces(e){return this.namespaceOps.listNamespaces(e)}async createNamespace(e,t){return this.namespaceOps.createNamespace(e,t)}async dropNamespace(e){await this.namespaceOps.dropNamespace(e)}async loadNamespaceMetadata(e){return this.namespaceOps.loadNamespaceMetadata(e)}async listTables(e){return this.tableOps.listTables(e)}async createTable(e,t){return this.tableOps.createTable(e,t)}async updateTable(e,t){return this.tableOps.updateTable(e,t)}async dropTable(e,t){await this.tableOps.dropTable(e,t)}async loadTable(e){return this.tableOps.loadTable(e)}async namespaceExists(e){return this.namespaceOps.namespaceExists(e)}async tableExists(e){return this.tableOps.tableExists(e)}async createNamespaceIfNotExists(e,t){return this.namespaceOps.createNamespaceIfNotExists(e,t)}async createTableIfNotExists(e,t){return this.tableOps.createTableIfNotExists(e,t)}},U=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,...t};super(r,i,n,`storage`)}async createBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/bucket`,{name:e},{headers:this.headers}))}async listBuckets(e){return this.handleOperation(async()=>{let t=new URLSearchParams;e?.limit!==void 0&&t.set(`limit`,e.limit.toString()),e?.offset!==void 0&&t.set(`offset`,e.offset.toString()),e?.sortColumn&&t.set(`sortColumn`,e.sortColumn),e?.sortOrder&&t.set(`sortOrder`,e.sortOrder),e?.search&&t.set(`search`,e.search);let n=t.toString(),r=n?`${this.url}/bucket?${n}`:`${this.url}/bucket`;return await y(this.fetch,r,{headers:this.headers})})}async deleteBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}from(e){if(!p(e))throw new t(`Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters.`);let n=new H({baseUrl:this.url,catalogName:e,auth:{type:`custom`,getHeaders:async()=>this.headers},fetch:this.fetch}),r=this.shouldThrowOnError;return new Proxy(n,{get(e,t){let n=e[t];return typeof n==`function`?async(...t)=>{try{return{data:await n.apply(e,t),error:null}}catch(e){if(r)throw e;return{data:null,error:e}}}:n}})}},W=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createIndex(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/CreateIndex`,e,{headers:this.headers})||{})}async getIndex(e,t){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/GetIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers}))}async listIndexes(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/ListIndexes`,e,{headers:this.headers}))}async deleteIndex(e,t){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/DeleteIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers})||{})}},G=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async putVectors(e){if(e.vectors.length<1||e.vectors.length>500)throw Error(`Vector batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/PutVectors`,e,{headers:this.headers})||{})}async getVectors(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/GetVectors`,e,{headers:this.headers}))}async listVectors(e){if(e.segmentCount!==void 0){if(e.segmentCount<1||e.segmentCount>16)throw Error(`segmentCount must be between 1 and 16`);if(e.segmentIndex!==void 0&&(e.segmentIndex<0||e.segmentIndex>=e.segmentCount))throw Error(`segmentIndex must be between 0 and ${e.segmentCount-1}`)}return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/ListVectors`,e,{headers:this.headers}))}async queryVectors(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/QueryVectors`,e,{headers:this.headers}))}async deleteVectors(e){if(e.keys.length<1||e.keys.length>500)throw Error(`Keys batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/DeleteVectors`,e,{headers:this.headers})||{})}},K=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createBucket(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/CreateVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}async getBucket(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/GetVectorBucket`,{vectorBucketName:e},{headers:this.headers}))}async listBuckets(e={}){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/ListVectorBuckets`,e,{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/DeleteVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}},q=class extends K{constructor(e,t={}){super(e,t.headers||{},t.fetch)}from(e){return new J(this.url,this.headers,e,this.fetch)}async createBucket(e){return super.createBucket(e)}async getBucket(e){return super.getBucket(e)}async listBuckets(e={}){return super.listBuckets(e)}async deleteBucket(e){return super.deleteBucket(e)}},J=class extends W{constructor(e,t,n,r){super(e,t,r),this.vectorBucketName=n}async createIndex(e){return super.createIndex({...e,vectorBucketName:this.vectorBucketName})}async listIndexes(e={}){return super.listIndexes({...e,vectorBucketName:this.vectorBucketName})}async getIndex(e){return super.getIndex(this.vectorBucketName,e)}async deleteIndex(e){return super.deleteIndex(this.vectorBucketName,e)}index(e){return new Y(this.url,this.headers,this.vectorBucketName,e,this.fetch)}},Y=class extends G{constructor(e,t,n,r,i){super(e,t,i),this.vectorBucketName=n,this.indexName=r}async putVectors(e){return super.putVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async getVectors(e){return super.getVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async listVectors(e={}){return super.listVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async queryVectors(e){return super.queryVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async deleteVectors(e){return super.deleteVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}},X=class extends N{constructor(e,t={},n,r){super(e,t,n,r)}from(e){return new j(this.url,this.headers,e,this.fetch)}get vectors(){return new q(this.url+`/vector`,{headers:this.headers,fetch:this.fetch})}get analytics(){return new U(this.url+`/iceberg`,this.headers,this.fetch)}};return e.StorageAnalyticsClient=U,e.StorageApiError=r,e.StorageClient=X,e.StorageError=t,e.StorageUnknownError=i,e.StorageVectorsApiError=s,e.StorageVectorsClient=q,e.StorageVectorsError=a,e.StorageVectorsErrorCode=l,e.StorageVectorsUnknownError=c,e.VectorBucketApi=K,e.VectorBucketScope=J,e.VectorDataApi=G,e.VectorIndexApi=W,e.VectorIndexScope=Y,e.isStorageError=n,e.isStorageVectorsError=o,e})({});
1
+ var supabase=(function(e){var t=class extends Error{constructor(e,t=`storage`,n,r){super(e),this.__isStorageError=!0,this.namespace=t,this.name=t===`vectors`?`StorageVectorsError`:`StorageError`,this.status=n,this.statusCode=r}};function n(e){return typeof e==`object`&&!!e&&`__isStorageError`in e}var r=class extends t{constructor(e,t,n,r=`storage`){super(e,r,t,n),this.name=r===`vectors`?`StorageVectorsApiError`:`StorageApiError`,this.status=t,this.statusCode=n}toJSON(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}}},i=class extends t{constructor(e,t,n=`storage`){super(e,n),this.name=n===`vectors`?`StorageVectorsUnknownError`:`StorageUnknownError`,this.originalError=t}},a=class extends t{constructor(e){super(e,`vectors`)}};function o(e){return n(e)&&e.namespace===`vectors`}var s=class extends r{constructor(e,t,n){super(e,t,n,`vectors`)}},c=class extends i{constructor(e,t){super(e,t,`vectors`)}};let l=function(e){return e.InternalError=`InternalError`,e.S3VectorConflictException=`S3VectorConflictException`,e.S3VectorNotFoundException=`S3VectorNotFoundException`,e.S3VectorBucketNotEmpty=`S3VectorBucketNotEmpty`,e.S3VectorMaxBucketsExceeded=`S3VectorMaxBucketsExceeded`,e.S3VectorMaxIndexesExceeded=`S3VectorMaxIndexesExceeded`,e}({}),u=e=>e?(...t)=>e(...t):(...e)=>fetch(...e),d=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},f=e=>{if(Array.isArray(e))return e.map(e=>f(e));if(typeof e==`function`||e!==Object(e))return e;let t={};return Object.entries(e).forEach(([e,n])=>{let r=e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(/[-_]/g,``));t[r]=f(n)}),t},p=e=>!e||typeof e!=`string`||e.length===0||e.length>100||e.trim()!==e||e.includes(`/`)||e.includes(`\\`)?!1:/^[\w!.\*'() &$@=;:+,?-]+$/.test(e),m=e=>e.msg||e.message||e.error_description||(typeof e.error==`string`?e.error:e.error?.message)||JSON.stringify(e),h=async(e,t,n,a)=>{if(e&&typeof e==`object`&&`status`in e&&`ok`in e&&typeof e.status==`number`){let n=e,i=n.status||500;if(typeof n.json==`function`)n.json().then(e=>{let n=e?.statusCode||e?.code||i+``;t(new r(m(e),i,n,a))}).catch(()=>{if(a===`vectors`){let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}else{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}});else{let e=i+``;t(new r(n.statusText||`HTTP ${i} error`,i,e,a))}}else t(new i(m(e),e,a))},g=(e,t,n,r)=>{let i={method:e,headers:t?.headers||{}};return e===`GET`||e===`HEAD`||!r?{...i,...n}:(d(r)?(i.headers={"Content-Type":`application/json`,...t?.headers},i.body=JSON.stringify(r)):i.body=r,t?.duplex&&(i.duplex=t.duplex),{...i,...n})};async function _(e,t,n,r,i,a,o){return new Promise((s,c)=>{e(n,g(t,r,i,a)).then(e=>{if(!e.ok)throw e;if(r?.noResolveJson)return e;if(o===`vectors`){let t=e.headers.get(`content-type`);if(e.headers.get(`content-length`)===`0`||e.status===204||!t||!t.includes(`application/json`))return{}}return e.json()}).then(e=>s(e)).catch(e=>h(e,c,r,o))})}function v(e=`storage`){return{get:async(t,n,r,i)=>_(t,`GET`,n,r,i,void 0,e),post:async(t,n,r,i,a)=>_(t,`POST`,n,i,a,r,e),put:async(t,n,r,i,a)=>_(t,`PUT`,n,i,a,r,e),head:async(t,n,r,i)=>_(t,`HEAD`,n,{...r,noResolveJson:!0},i,void 0,e),remove:async(t,n,r,i,a)=>_(t,`DELETE`,n,i,a,r,e)}}let{get:y,post:b,put:x,head:S,remove:C}=v(`storage`),w=v(`vectors`);var T=class{constructor(e,t={},n,r=`storage`){this.shouldThrowOnError=!1,this.url=e,this.headers=t,this.fetch=u(n),this.namespace=r}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers={...this.headers,[e]:t},this}async handleOperation(e){try{return{data:await e(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}},E=class{constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t}then(e,t){return this.execute().then(e,t)}async execute(){try{return{data:(await this.downloadFn()).body,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let D;var O=class{static{D=Symbol.toStringTag}constructor(e,t){this.downloadFn=e,this.shouldThrowOnError=t,this[D]=`BlobDownloadBuilder`,this.promise=null}asStream(){return new E(this.downloadFn,this.shouldThrowOnError)}then(e,t){return this.getPromise().then(e,t)}catch(e){return this.getPromise().catch(e)}finally(e){return this.getPromise().finally(e)}getPromise(){return this.promise||=this.execute(),this.promise}async execute(){try{return{data:await(await this.downloadFn()).blob(),error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e))return{data:null,error:e};throw e}}};let k={limit:100,offset:0,sortBy:{column:`name`,order:`asc`}},A={cacheControl:`3600`,contentType:`text/plain;charset=UTF-8`,upsert:!1};var j=class extends T{constructor(e,t={},n,r){super(e,t,r,`storage`),this.bucketId=n}async uploadOrUpdate(e,t,n,r){return this.handleOperation(async()=>{let i,a={...A,...r},o={...this.headers,...e===`POST`&&{"x-upsert":String(a.upsert)}},s=a.metadata;typeof Blob<`u`&&n instanceof Blob?(i=new FormData,i.append(`cacheControl`,a.cacheControl),s&&i.append(`metadata`,this.encodeMetadata(s)),i.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(i=n,i.has(`cacheControl`)||i.append(`cacheControl`,a.cacheControl),s&&!i.has(`metadata`)&&i.append(`metadata`,this.encodeMetadata(s))):(i=n,o[`cache-control`]=`max-age=${a.cacheControl}`,o[`content-type`]=a.contentType,s&&(o[`x-metadata`]=this.toBase64(this.encodeMetadata(s))),(typeof ReadableStream<`u`&&i instanceof ReadableStream||i&&typeof i==`object`&&`pipe`in i&&typeof i.pipe==`function`)&&!a.duplex&&(a.duplex=`half`)),r?.headers&&(o={...o,...r.headers});let c=this._removeEmptyFolders(t),l=this._getFinalPath(c),u=await(e==`PUT`?x:b)(this.fetch,`${this.url}/object/${l}`,i,{headers:o,...a?.duplex?{duplex:a.duplex}:{}});return{path:c,id:u.Id,fullPath:u.Key}})}async upload(e,t,n){return this.uploadOrUpdate(`POST`,e,t,n)}async uploadToSignedUrl(e,t,n,r){let i=this._removeEmptyFolders(e),a=this._getFinalPath(i),o=new URL(this.url+`/object/upload/sign/${a}`);return o.searchParams.set(`token`,t),this.handleOperation(async()=>{let e,t={upsert:A.upsert,...r},a={...this.headers,"x-upsert":String(t.upsert)};return typeof Blob<`u`&&n instanceof Blob?(e=new FormData,e.append(`cacheControl`,t.cacheControl),e.append(``,n)):typeof FormData<`u`&&n instanceof FormData?(e=n,e.append(`cacheControl`,t.cacheControl)):(e=n,a[`cache-control`]=`max-age=${t.cacheControl}`,a[`content-type`]=t.contentType),{path:i,fullPath:(await x(this.fetch,o.toString(),e,{headers:a})).Key}})}async createSignedUploadUrl(e,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i={...this.headers};n?.upsert&&(i[`x-upsert`]=`true`);let a=await b(this.fetch,`${this.url}/object/upload/sign/${r}`,{},{headers:i}),o=new URL(this.url+a.url),s=o.searchParams.get(`token`);if(!s)throw new t(`No token returned by API`);return{signedUrl:o.toString(),path:e,token:s}})}async update(e,t,n){return this.uploadOrUpdate(`PUT`,e,t,n)}async move(e,t,n){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket},{headers:this.headers}))}async copy(e,t,n){return this.handleOperation(async()=>({path:(await b(this.fetch,`${this.url}/object/copy`,{bucketId:this.bucketId,sourceKey:e,destinationKey:t,destinationBucket:n?.destinationBucket},{headers:this.headers})).Key}))}async createSignedUrl(e,t,n){return this.handleOperation(async()=>{let r=this._getFinalPath(e),i=await b(this.fetch,`${this.url}/object/sign/${r}`,{expiresIn:t,...n?.transform?{transform:n.transform}:{}},{headers:this.headers}),a=n?.download?`&download=${n.download===!0?``:n.download}`:``,o=n?.transform&&i.signedURL.includes(`/object/sign/`)?i.signedURL.replace(`/object/sign/`,`/render/image/sign/`):i.signedURL;return{signedUrl:encodeURI(`${this.url}${o}${a}`)}})}async createSignedUrls(e,t,n){return this.handleOperation(async()=>{let r=await b(this.fetch,`${this.url}/object/sign/${this.bucketId}`,{expiresIn:t,paths:e},{headers:this.headers}),i=n?.download?`&download=${n.download===!0?``:n.download}`:``;return r.map(e=>({...e,signedUrl:e.signedURL?encodeURI(`${this.url}${e.signedURL}${i}`):null}))})}download(e,t,n){let r=t?.transform===void 0?`object`:`render/image/authenticated`,i=this.transformOptsToQueryString(t?.transform||{}),a=i?`?${i}`:``,o=this._getFinalPath(e);return new O(()=>y(this.fetch,`${this.url}/${r}/${o}${a}`,{headers:this.headers,noResolveJson:!0},n),this.shouldThrowOnError)}async info(e){let t=this._getFinalPath(e);return this.handleOperation(async()=>f(await y(this.fetch,`${this.url}/object/info/${t}`,{headers:this.headers})))}async exists(e){let t=this._getFinalPath(e);try{return await S(this.fetch,`${this.url}/object/${t}`,{headers:this.headers}),{data:!0,error:null}}catch(e){if(this.shouldThrowOnError)throw e;if(n(e)){let t=e instanceof r?e.status:e instanceof i?e.originalError?.status:void 0;if(t!==void 0&&[400,404].includes(t))return{data:!1,error:e}}throw e}}getPublicUrl(e,t){let n=this._getFinalPath(e),r=[],i=t?.download?`download=${t.download===!0?``:t.download}`:``;i!==``&&r.push(i);let a=t?.transform===void 0?`object`:`render/image`,o=this.transformOptsToQueryString(t?.transform||{});o!==``&&r.push(o);let s=r.join(`&`);return s!==``&&(s=`?${s}`),{data:{publicUrl:encodeURI(`${this.url}/${a}/public/${n}${s}`)}}}async remove(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:e},{headers:this.headers}))}async list(e,t,n){return this.handleOperation(async()=>{let r={...k,...t,prefix:e||``};return await b(this.fetch,`${this.url}/object/list/${this.bucketId}`,r,{headers:this.headers},n)})}async listV2(e,t){return this.handleOperation(async()=>{let n={...e};return await b(this.fetch,`${this.url}/object/list-v2/${this.bucketId}`,n,{headers:this.headers},t)})}encodeMetadata(e){return JSON.stringify(e)}toBase64(e){return typeof Buffer<`u`?Buffer.from(e).toString(`base64`):btoa(e)}_getFinalPath(e){return`${this.bucketId}/${e.replace(/^\/+/,``)}`}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,``).replace(/\/+/g,`/`)}transformOptsToQueryString(e){let 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(`&`)}};let M={"X-Client-Info":`storage-js/2.99.0`};var N=class extends T{constructor(e,t={},n,r){let i=new URL(e);r?.useNewHostname&&/supabase\.(co|in|red)$/.test(i.hostname)&&!i.hostname.includes(`storage.supabase.`)&&(i.hostname=i.hostname.replace(`supabase.`,`storage.supabase.`));let a=i.href.replace(/\/$/,``),o={...M,...t};super(a,o,n,`storage`)}async listBuckets(e){return this.handleOperation(async()=>{let t=this.listBucketOptionsToQueryString(e);return await y(this.fetch,`${this.url}/bucket${t}`,{headers:this.headers})})}async getBucket(e){return this.handleOperation(async()=>await y(this.fetch,`${this.url}/bucket/${e}`,{headers:this.headers}))}async createBucket(e,t={public:!1}){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/bucket`,{id:e,name:e,type:t.type,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}))}async updateBucket(e,t){return this.handleOperation(async()=>await x(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}))}async emptyBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/bucket/${e}/empty`,{},{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}listBucketOptionsToQueryString(e){let t={};return e&&(`limit`in e&&(t.limit=String(e.limit)),`offset`in e&&(t.offset=String(e.offset)),e.search&&(t.search=e.search),e.sortColumn&&(t.sortColumn=e.sortColumn),e.sortOrder&&(t.sortOrder=e.sortOrder)),Object.keys(t).length>0?`?`+new URLSearchParams(t).toString():``}},P=class extends Error{constructor(e,t){super(e),this.name=`IcebergError`,this.status=t.status,this.icebergType=t.icebergType,this.icebergCode=t.icebergCode,this.details=t.details,this.isCommitStateUnknown=t.icebergType===`CommitStateUnknownException`||[500,502,504].includes(t.status)&&t.icebergType?.includes(`CommitState`)===!0}isNotFound(){return this.status===404}isConflict(){return this.status===409}isAuthenticationTimeout(){return this.status===419}};function F(e,t,n){let r=new URL(t,e);if(n)for(let[e,t]of Object.entries(n))t!==void 0&&r.searchParams.set(e,t);return r.toString()}async function I(e){return!e||e.type===`none`?{}:e.type===`bearer`?{Authorization:`Bearer ${e.token}`}:e.type===`header`?{[e.name]:e.value}:e.type===`custom`?await e.getHeaders():{}}function L(e){let t=e.fetchImpl??globalThis.fetch;return{async request({method:n,path:r,query:i,body:a,headers:o}){let s=F(e.baseUrl,r,i),c=await I(e.auth),l=await t(s,{method:n,headers:{...a?{"Content-Type":`application/json`}:{},...c,...o},body:a?JSON.stringify(a):void 0}),u=await l.text(),d=(l.headers.get(`content-type`)||``).includes(`application/json`),f=d&&u?JSON.parse(u):u;if(!l.ok){let e=d?f:void 0,t=e?.error;throw new P(t?.message??`Request failed with status ${l.status}`,{status:l.status,icebergType:t?.type,icebergCode:t?.code,details:e})}return{status:l.status,headers:l.headers,data:f}}}}function R(e){return e.join(``)}var z=class{constructor(e,t=``){this.client=e,this.prefix=t}async listNamespaces(e){let t=e?{parent:R(e.namespace)}:void 0;return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces`,query:t})).data.namespaces.map(e=>({namespace:e}))}async createNamespace(e,t){let n={namespace:e.namespace,properties:t?.properties};return(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces`,body:n})).data}async dropNamespace(e){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${R(e.namespace)}`})}async loadNamespaceMetadata(e){return{properties:(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${R(e.namespace)}`})).data.properties}}async namespaceExists(e){try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${R(e.namespace)}`}),!0}catch(e){if(e instanceof P&&e.status===404)return!1;throw e}}async createNamespaceIfNotExists(e,t){try{return await this.createNamespace(e,t)}catch(e){if(e instanceof P&&e.status===409)return;throw e}}};function B(e){return e.join(``)}var V=class{constructor(e,t=``,n){this.client=e,this.prefix=t,this.accessDelegation=n}async listTables(e){return(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables`})).data.identifiers}async createTable(e,t){let n={};return this.accessDelegation&&(n[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables`,body:t,headers:n})).data.metadata}async updateTable(e,t){let n=await this.client.request({method:`POST`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,body:t});return{"metadata-location":n.data[`metadata-location`],metadata:n.data.metadata}}async dropTable(e,t){await this.client.request({method:`DELETE`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,query:{purgeRequested:String(t?.purge??!1)}})}async loadTable(e){let t={};return this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation),(await this.client.request({method:`GET`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,headers:t})).data.metadata}async tableExists(e){let t={};this.accessDelegation&&(t[`X-Iceberg-Access-Delegation`]=this.accessDelegation);try{return await this.client.request({method:`HEAD`,path:`${this.prefix}/namespaces/${B(e.namespace)}/tables/${e.name}`,headers:t}),!0}catch(e){if(e instanceof P&&e.status===404)return!1;throw e}}async createTableIfNotExists(e,t){try{return await this.createTable(e,t)}catch(n){if(n instanceof P&&n.status===409)return await this.loadTable({namespace:e.namespace,name:t.name});throw n}}},H=class{constructor(e){let t=`v1`;e.catalogName&&(t+=`/${e.catalogName}`),this.client=L({baseUrl:e.baseUrl.endsWith(`/`)?e.baseUrl:`${e.baseUrl}/`,auth:e.auth,fetchImpl:e.fetch}),this.accessDelegation=e.accessDelegation?.join(`,`),this.namespaceOps=new z(this.client,t),this.tableOps=new V(this.client,t,this.accessDelegation)}async listNamespaces(e){return this.namespaceOps.listNamespaces(e)}async createNamespace(e,t){return this.namespaceOps.createNamespace(e,t)}async dropNamespace(e){await this.namespaceOps.dropNamespace(e)}async loadNamespaceMetadata(e){return this.namespaceOps.loadNamespaceMetadata(e)}async listTables(e){return this.tableOps.listTables(e)}async createTable(e,t){return this.tableOps.createTable(e,t)}async updateTable(e,t){return this.tableOps.updateTable(e,t)}async dropTable(e,t){await this.tableOps.dropTable(e,t)}async loadTable(e){return this.tableOps.loadTable(e)}async namespaceExists(e){return this.namespaceOps.namespaceExists(e)}async tableExists(e){return this.tableOps.tableExists(e)}async createNamespaceIfNotExists(e,t){return this.namespaceOps.createNamespaceIfNotExists(e,t)}async createTableIfNotExists(e,t){return this.tableOps.createTableIfNotExists(e,t)}},U=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,...t};super(r,i,n,`storage`)}async createBucket(e){return this.handleOperation(async()=>await b(this.fetch,`${this.url}/bucket`,{name:e},{headers:this.headers}))}async listBuckets(e){return this.handleOperation(async()=>{let t=new URLSearchParams;e?.limit!==void 0&&t.set(`limit`,e.limit.toString()),e?.offset!==void 0&&t.set(`offset`,e.offset.toString()),e?.sortColumn&&t.set(`sortColumn`,e.sortColumn),e?.sortOrder&&t.set(`sortOrder`,e.sortOrder),e?.search&&t.set(`search`,e.search);let n=t.toString(),r=n?`${this.url}/bucket?${n}`:`${this.url}/bucket`;return await y(this.fetch,r,{headers:this.headers})})}async deleteBucket(e){return this.handleOperation(async()=>await C(this.fetch,`${this.url}/bucket/${e}`,{},{headers:this.headers}))}from(e){if(!p(e))throw new t(`Invalid bucket name: File, folder, and bucket names must follow AWS object key naming guidelines and should avoid the use of any other characters.`);let n=new H({baseUrl:this.url,catalogName:e,auth:{type:`custom`,getHeaders:async()=>this.headers},fetch:this.fetch}),r=this.shouldThrowOnError;return new Proxy(n,{get(e,t){let n=e[t];return typeof n==`function`?async(...t)=>{try{return{data:await n.apply(e,t),error:null}}catch(e){if(r)throw e;return{data:null,error:e}}}:n}})}},W=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createIndex(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/CreateIndex`,e,{headers:this.headers})||{})}async getIndex(e,t){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/GetIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers}))}async listIndexes(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/ListIndexes`,e,{headers:this.headers}))}async deleteIndex(e,t){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/DeleteIndex`,{vectorBucketName:e,indexName:t},{headers:this.headers})||{})}},G=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async putVectors(e){if(e.vectors.length<1||e.vectors.length>500)throw Error(`Vector batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/PutVectors`,e,{headers:this.headers})||{})}async getVectors(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/GetVectors`,e,{headers:this.headers}))}async listVectors(e){if(e.segmentCount!==void 0){if(e.segmentCount<1||e.segmentCount>16)throw Error(`segmentCount must be between 1 and 16`);if(e.segmentIndex!==void 0&&(e.segmentIndex<0||e.segmentIndex>=e.segmentCount))throw Error(`segmentIndex must be between 0 and ${e.segmentCount-1}`)}return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/ListVectors`,e,{headers:this.headers}))}async queryVectors(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/QueryVectors`,e,{headers:this.headers}))}async deleteVectors(e){if(e.keys.length<1||e.keys.length>500)throw Error(`Keys batch size must be between 1 and 500 items`);return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/DeleteVectors`,e,{headers:this.headers})||{})}},K=class extends T{constructor(e,t={},n){let r=e.replace(/\/$/,``),i={...M,"Content-Type":`application/json`,...t};super(r,i,n,`vectors`)}async createBucket(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/CreateVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}async getBucket(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/GetVectorBucket`,{vectorBucketName:e},{headers:this.headers}))}async listBuckets(e={}){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/ListVectorBuckets`,e,{headers:this.headers}))}async deleteBucket(e){return this.handleOperation(async()=>await w.post(this.fetch,`${this.url}/DeleteVectorBucket`,{vectorBucketName:e},{headers:this.headers})||{})}},q=class extends K{constructor(e,t={}){super(e,t.headers||{},t.fetch)}from(e){return new J(this.url,this.headers,e,this.fetch)}async createBucket(e){return super.createBucket(e)}async getBucket(e){return super.getBucket(e)}async listBuckets(e={}){return super.listBuckets(e)}async deleteBucket(e){return super.deleteBucket(e)}},J=class extends W{constructor(e,t,n,r){super(e,t,r),this.vectorBucketName=n}async createIndex(e){return super.createIndex({...e,vectorBucketName:this.vectorBucketName})}async listIndexes(e={}){return super.listIndexes({...e,vectorBucketName:this.vectorBucketName})}async getIndex(e){return super.getIndex(this.vectorBucketName,e)}async deleteIndex(e){return super.deleteIndex(this.vectorBucketName,e)}index(e){return new Y(this.url,this.headers,this.vectorBucketName,e,this.fetch)}},Y=class extends G{constructor(e,t,n,r,i){super(e,t,i),this.vectorBucketName=n,this.indexName=r}async putVectors(e){return super.putVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async getVectors(e){return super.getVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async listVectors(e={}){return super.listVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async queryVectors(e){return super.queryVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}async deleteVectors(e){return super.deleteVectors({...e,vectorBucketName:this.vectorBucketName,indexName:this.indexName})}},X=class extends N{constructor(e,t={},n,r){super(e,t,n,r)}from(e){return new j(this.url,this.headers,e,this.fetch)}get vectors(){return new q(this.url+`/vector`,{headers:this.headers,fetch:this.fetch})}get analytics(){return new U(this.url+`/iceberg`,this.headers,this.fetch)}};return e.StorageAnalyticsClient=U,e.StorageApiError=r,e.StorageClient=X,e.StorageError=t,e.StorageUnknownError=i,e.StorageVectorsApiError=s,e.StorageVectorsClient=q,e.StorageVectorsError=a,e.StorageVectorsErrorCode=l,e.StorageVectorsUnknownError=c,e.VectorBucketApi=K,e.VectorBucketScope=J,e.VectorDataApi=G,e.VectorIndexApi=W,e.VectorIndexScope=Y,e.isStorageError=n,e.isStorageVectorsError=o,e})({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/storage-js",
3
- "version": "2.98.1-canary.0",
3
+ "version": "2.99.0",
4
4
  "description": "Isomorphic storage client for Supabase.",
5
5
  "keywords": [
6
6
  "javascript",
@@ -54,7 +54,7 @@ const handleError = async (
54
54
  'ok' in error &&
55
55
  typeof (error as any).status === 'number'
56
56
 
57
- if (isResponseLike && !options?.noResolveJson) {
57
+ if (isResponseLike) {
58
58
  const responseError = error as any
59
59
  const status = responseError.status || 500
60
60
 
package/src/lib/types.ts CHANGED
@@ -44,34 +44,98 @@ export interface AnalyticBucket {
44
44
  updated_at: string
45
45
  }
46
46
 
47
+ /**
48
+ * Metadata object returned by the Storage API for files
49
+ * Contains information about file size, type, caching, and HTTP response details
50
+ */
51
+ export interface FileMetadata {
52
+ /** Entity tag for caching and conditional requests */
53
+ eTag: string
54
+ /** File size in bytes */
55
+ size: number
56
+ /** MIME type of the file */
57
+ mimetype: string
58
+ /** Cache control directive (e.g., "max-age=3600") */
59
+ cacheControl: string
60
+ /** Last modification timestamp (ISO 8601) */
61
+ lastModified: string
62
+ /** Content length in bytes (usually same as size) */
63
+ contentLength: number
64
+ /** HTTP status code from the storage backend */
65
+ httpStatusCode: number
66
+ /** Any additional custom metadata stored with the file */
67
+ [key: string]: any
68
+ }
69
+
70
+ /**
71
+ * File object returned by the List V1 API (list() method)
72
+ * Note: Folder entries will have null values for most fields except name
73
+ *
74
+ * Warning: Some fields may not be present in all API responses. Fields like
75
+ * bucket_id, owner, and buckets are not returned by list() operations.
76
+ */
47
77
  export interface FileObject {
78
+ /** File or folder name (relative to the prefix) - always present */
48
79
  name: string
49
- bucket_id: string
50
- owner: string
51
- id: string
52
- updated_at: string
53
- created_at: string
54
- /** @deprecated */
55
- last_accessed_at: string
56
- metadata: Record<string, any>
57
- buckets: Bucket
80
+ /** Unique identifier for the file (null for folders) */
81
+ id: string | null
82
+ /** Last update timestamp (null for folders) */
83
+ updated_at: string | null
84
+ /** Creation timestamp (null for folders) */
85
+ created_at: string | null
86
+ /** @deprecated Last access timestamp (null for folders) */
87
+ last_accessed_at: string | null
88
+ /** File metadata including size, mimetype, etc. (null for folders) */
89
+ metadata: FileMetadata | null
90
+ /**
91
+ * @deprecated Bucket identifier - NOT returned by list() operations.
92
+ * May be present in remove() responses. Do not rely on this field.
93
+ */
94
+ bucket_id?: string
95
+ /**
96
+ * @deprecated Owner identifier - NOT returned by list() or remove() operations.
97
+ * This field should not be relied upon.
98
+ */
99
+ owner?: string
100
+ /**
101
+ * @deprecated Bucket object - NOT returned by list() or remove() operations.
102
+ * This field should not be relied upon.
103
+ */
104
+ buckets?: Bucket
58
105
  }
59
106
 
107
+ /**
108
+ * File object returned by the Info endpoint (info() method)
109
+ * Contains detailed metadata for a specific file
110
+ */
60
111
  export interface FileObjectV2 {
112
+ /** Unique identifier for the file */
61
113
  id: string
114
+ /** File version identifier */
62
115
  version: string
116
+ /** File name */
63
117
  name: string
118
+ /** Bucket identifier */
64
119
  bucket_id: string
65
- updated_at: string
120
+ /** Creation timestamp */
66
121
  created_at: string
67
- /** @deprecated */
68
- last_accessed_at: string
122
+ /** File size in bytes */
69
123
  size?: number
124
+ /** Cache control header value */
70
125
  cache_control?: string
126
+ /** MIME content type */
71
127
  content_type?: string
128
+ /** Entity tag for caching */
72
129
  etag?: string
130
+ /** Last modification timestamp (replaces updated_at) */
73
131
  last_modified?: string
74
- metadata?: Record<string, any>
132
+ /** Custom file metadata */
133
+ metadata?: FileMetadata
134
+ /**
135
+ * @deprecated The API returns last_modified instead.
136
+ * This field may not be present in responses.
137
+ */
138
+ updated_at?: string
75
139
  }
76
140
 
77
141
  export interface SortBy {
@@ -175,20 +239,37 @@ export interface SearchV2Options {
175
239
  sortBy?: SortByV2
176
240
  }
177
241
 
242
+ /**
243
+ * File object returned by the List V2 API (listV2() method)
244
+ * Objects and folders are returned in separate arrays - this type represents
245
+ * actual files only. Use SearchV2Folder for folder entries.
246
+ */
178
247
  export interface SearchV2Object {
179
- id: string
180
- key: string
248
+ /** File name */
181
249
  name: string
250
+ /** Full object key/path */
251
+ key?: string
252
+ /** Unique identifier for the file */
253
+ id: string
254
+ /** Last update timestamp */
182
255
  updated_at: string
256
+ /** Creation timestamp */
183
257
  created_at: string
184
- metadata: Record<string, any>
185
- /**
186
- * @deprecated
187
- */
258
+ /** File metadata including size, mimetype, etc. (null if not yet set) */
259
+ metadata: FileMetadata | null
260
+ /** @deprecated Last access timestamp */
188
261
  last_accessed_at: string
189
262
  }
190
263
 
191
- export type SearchV2Folder = Omit<SearchV2Object, 'id' | 'metadata' | 'last_accessed_at'>
264
+ /**
265
+ * Folder entry returned by the List V2 API (listV2() method) when using with_delimiter: true
266
+ */
267
+ export interface SearchV2Folder {
268
+ /** Folder name/prefix */
269
+ name: string
270
+ /** Full folder key/path */
271
+ key?: string
272
+ }
192
273
 
193
274
  export interface SearchV2Result {
194
275
  hasNext: boolean
@@ -4,4 +4,4 @@
4
4
  // - Debugging and support (identifying which version is running)
5
5
  // - Telemetry and logging (version reporting in errors/analytics)
6
6
  // - Ensuring build artifacts match the published package version
7
- export const version = '2.98.1-canary.0'
7
+ export const version = '2.99.0'
@@ -1,4 +1,9 @@
1
- import { StorageError, StorageUnknownError, isStorageError } from '../lib/common/errors'
1
+ import {
2
+ StorageApiError,
3
+ StorageError,
4
+ StorageUnknownError,
5
+ isStorageError,
6
+ } from '../lib/common/errors'
2
7
  import { get, head, post, put, remove, Fetch } from '../lib/common/fetch'
3
8
  import { recursiveToCamel } from '../lib/common/helpers'
4
9
  import BaseApiClient from '../lib/common/BaseApiClient'
@@ -604,7 +609,14 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
604
609
  const downloadQueryParam = options?.download
605
610
  ? `&download=${options.download === true ? '' : options.download}`
606
611
  : ''
607
- const signedUrl = encodeURI(`${this.url}${data.signedURL}${downloadQueryParam}`)
612
+ // When transforms are requested the signed URL must use the render endpoint.
613
+ // Some storage-api versions return /object/sign/ even for transform requests,
614
+ // so we normalise the path on the client side.
615
+ const returnedPath =
616
+ options?.transform && data.signedURL.includes('/object/sign/')
617
+ ? data.signedURL.replace('/object/sign/', '/render/image/sign/')
618
+ : data.signedURL
619
+ const signedUrl = encodeURI(`${this.url}${returnedPath}${downloadQueryParam}`)
608
620
  return { signedUrl }
609
621
  })
610
622
  }
@@ -765,6 +777,9 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
765
777
  /**
766
778
  * Retrieves the details of an existing file.
767
779
  *
780
+ * Returns detailed file metadata including size, content type, and timestamps.
781
+ * Note: The API returns `last_modified` field, not `updated_at`.
782
+ *
768
783
  * @category File Buckets
769
784
  * @param path The file path, including the file name. For example `folder/image.png`.
770
785
  * @returns Promise with response containing file metadata or error
@@ -775,6 +790,11 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
775
790
  * .storage
776
791
  * .from('avatars')
777
792
  * .info('folder/avatar1.png')
793
+ *
794
+ * if (data) {
795
+ * console.log('Last modified:', data.lastModified)
796
+ * console.log('Size:', data.size)
797
+ * }
778
798
  * ```
779
799
  */
780
800
  async info(path: string): Promise<
@@ -835,10 +855,16 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
835
855
  if (this.shouldThrowOnError) {
836
856
  throw error
837
857
  }
838
- if (isStorageError(error) && error instanceof StorageUnknownError) {
839
- const originalError = error.originalError as unknown as { status: number }
840
-
841
- if ([400, 404].includes(originalError?.status)) {
858
+ if (isStorageError(error)) {
859
+ // HEAD requests produce StorageApiError (via handleError) or StorageUnknownError (legacy)
860
+ const status =
861
+ error instanceof StorageApiError
862
+ ? error.status
863
+ : error instanceof StorageUnknownError
864
+ ? (error.originalError as { status: number })?.status
865
+ : undefined
866
+
867
+ if (status !== undefined && [400, 404].includes(status)) {
842
868
  return { data: false, error }
843
869
  }
844
870
  }
@@ -933,6 +959,9 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
933
959
  /**
934
960
  * Deletes files within the same bucket
935
961
  *
962
+ * Returns an array of FileObject entries for the deleted files. Note that deprecated
963
+ * fields like `bucket_id` may or may not be present in the response - do not rely on them.
964
+ *
936
965
  * @category File Buckets
937
966
  * @param paths An array of files to delete, including the path and file name. For example [`'folder/image.png'`].
938
967
  * @returns Promise with response containing array of deleted file objects or error
@@ -1039,11 +1068,16 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
1039
1068
  /**
1040
1069
  * Lists all the files and folders within a path of the bucket.
1041
1070
  *
1071
+ * **Important:** For folder entries, fields like `id`, `updated_at`, `created_at`,
1072
+ * `last_accessed_at`, and `metadata` will be `null`. Only files have these fields populated.
1073
+ * Additionally, deprecated fields like `bucket_id`, `owner`, and `buckets` are NOT returned
1074
+ * by this method.
1075
+ *
1042
1076
  * @category File Buckets
1043
1077
  * @param path The folder path.
1044
1078
  * @param options Search options including limit (defaults to 100), offset, sortBy, and search
1045
1079
  * @param parameters Optional fetch parameters including signal for cancellation
1046
- * @returns Promise with response containing array of files or error
1080
+ * @returns Promise with response containing array of files/folders or error
1047
1081
  *
1048
1082
  * @example List files in a bucket
1049
1083
  * ```js
@@ -1055,9 +1089,20 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
1055
1089
  * offset: 0,
1056
1090
  * sortBy: { column: 'name', order: 'asc' },
1057
1091
  * })
1092
+ *
1093
+ * // Handle files vs folders
1094
+ * data?.forEach(item => {
1095
+ * if (item.id !== null) {
1096
+ * // It's a file
1097
+ * console.log('File:', item.name, 'Size:', item.metadata?.size)
1098
+ * } else {
1099
+ * // It's a folder
1100
+ * console.log('Folder:', item.name)
1101
+ * }
1102
+ * })
1058
1103
  * ```
1059
1104
  *
1060
- * Response:
1105
+ * Response (file entry):
1061
1106
  * ```json
1062
1107
  * {
1063
1108
  * "data": [
@@ -1122,11 +1167,50 @@ export default class StorageFileApi extends BaseApiClient<StorageError> {
1122
1167
  }
1123
1168
 
1124
1169
  /**
1170
+ * Lists all the files and folders within a bucket using the V2 API with pagination support.
1171
+ *
1172
+ * **Important:** Folder entries in the `folders` array only contain `name` and optionally `key` —
1173
+ * they have no `id`, timestamps, or `metadata` fields. Full file metadata is only available
1174
+ * on entries in the `objects` array.
1175
+ *
1125
1176
  * @experimental this method signature might change in the future
1126
1177
  *
1127
1178
  * @category File Buckets
1128
- * @param options search options
1129
- * @param parameters
1179
+ * @param options Search options including prefix, cursor for pagination, limit, with_delimiter
1180
+ * @param parameters Optional fetch parameters including signal for cancellation
1181
+ * @returns Promise with response containing folders/objects arrays with pagination info or error
1182
+ *
1183
+ * @example List files with pagination
1184
+ * ```js
1185
+ * const { data, error } = await supabase
1186
+ * .storage
1187
+ * .from('avatars')
1188
+ * .listV2({
1189
+ * prefix: 'folder/',
1190
+ * limit: 100,
1191
+ * })
1192
+ *
1193
+ * // Handle pagination
1194
+ * if (data?.hasNext) {
1195
+ * const nextPage = await supabase
1196
+ * .storage
1197
+ * .from('avatars')
1198
+ * .listV2({
1199
+ * prefix: 'folder/',
1200
+ * cursor: data.nextCursor,
1201
+ * })
1202
+ * }
1203
+ *
1204
+ * // Handle files vs folders
1205
+ * data?.objects.forEach(file => {
1206
+ * if (file.id !== null) {
1207
+ * console.log('File:', file.name, 'Size:', file.metadata?.size)
1208
+ * }
1209
+ * })
1210
+ * data?.folders.forEach(folder => {
1211
+ * console.log('Folder:', folder.name)
1212
+ * })
1213
+ * ```
1130
1214
  */
1131
1215
  async listV2(
1132
1216
  options?: SearchV2Options,