@supabase/storage-js 1.2.2 → 1.5.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.
- package/dist/main/SupabaseStorageClient.d.ts +2 -1
- package/dist/main/SupabaseStorageClient.d.ts.map +1 -1
- package/dist/main/SupabaseStorageClient.js +3 -3
- package/dist/main/SupabaseStorageClient.js.map +1 -1
- package/dist/main/lib/StorageBucketApi.d.ts +3 -1
- package/dist/main/lib/StorageBucketApi.d.ts.map +1 -1
- package/dist/main/lib/StorageBucketApi.js +10 -8
- package/dist/main/lib/StorageBucketApi.js.map +1 -1
- package/dist/main/lib/StorageFileApi.d.ts +29 -9
- package/dist/main/lib/StorageFileApi.d.ts.map +1 -1
- package/dist/main/lib/StorageFileApi.js +63 -50
- package/dist/main/lib/StorageFileApi.js.map +1 -1
- package/dist/main/lib/constants.d.ts +4 -0
- package/dist/main/lib/constants.d.ts.map +1 -0
- package/dist/main/lib/constants.js +6 -0
- package/dist/main/lib/constants.js.map +1 -0
- package/dist/main/lib/fetch.d.ts +5 -4
- package/dist/main/lib/fetch.d.ts.map +1 -1
- package/dist/main/lib/fetch.js +10 -10
- package/dist/main/lib/fetch.js.map +1 -1
- package/dist/main/lib/index.d.ts +1 -0
- package/dist/main/lib/index.d.ts.map +1 -1
- package/dist/main/lib/index.js +1 -0
- package/dist/main/lib/index.js.map +1 -1
- package/dist/main/lib/types.d.ts +2 -1
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/version.d.ts +2 -0
- package/dist/main/lib/version.d.ts.map +1 -0
- package/dist/main/lib/version.js +6 -0
- package/dist/main/lib/version.js.map +1 -0
- package/dist/module/SupabaseStorageClient.d.ts +2 -1
- package/dist/module/SupabaseStorageClient.d.ts.map +1 -1
- package/dist/module/SupabaseStorageClient.js +3 -3
- package/dist/module/SupabaseStorageClient.js.map +1 -1
- package/dist/module/lib/StorageBucketApi.d.ts +3 -1
- package/dist/module/lib/StorageBucketApi.d.ts.map +1 -1
- package/dist/module/lib/StorageBucketApi.js +10 -8
- package/dist/module/lib/StorageBucketApi.js.map +1 -1
- package/dist/module/lib/StorageFileApi.d.ts +29 -9
- package/dist/module/lib/StorageFileApi.d.ts.map +1 -1
- package/dist/module/lib/StorageFileApi.js +59 -49
- package/dist/module/lib/StorageFileApi.js.map +1 -1
- package/dist/module/lib/constants.d.ts +4 -0
- package/dist/module/lib/constants.d.ts.map +1 -0
- package/dist/module/lib/constants.js +3 -0
- package/dist/module/lib/constants.js.map +1 -0
- package/dist/module/lib/fetch.d.ts +5 -4
- package/dist/module/lib/fetch.d.ts.map +1 -1
- package/dist/module/lib/fetch.js +11 -11
- package/dist/module/lib/fetch.js.map +1 -1
- package/dist/module/lib/index.d.ts +1 -0
- package/dist/module/lib/index.d.ts.map +1 -1
- package/dist/module/lib/index.js +1 -0
- package/dist/module/lib/index.js.map +1 -1
- package/dist/module/lib/types.d.ts +2 -1
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/version.d.ts +2 -0
- package/dist/module/lib/version.d.ts.map +1 -0
- package/dist/module/lib/version.js +3 -0
- package/dist/module/lib/version.js.map +1 -0
- package/dist/umd/supabase.js +1 -1
- package/package.json +4 -2
- package/src/SupabaseStorageClient.ts +4 -3
- package/src/lib/StorageBucketApi.ts +22 -7
- package/src/lib/StorageFileApi.ts +103 -51
- package/src/lib/constants.ts +2 -0
- package/src/lib/fetch.ts +13 -6
- package/src/lib/index.ts +1 -0
- package/src/lib/types.ts +2 -1
- package/src/lib/version.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,EAAE,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,MAAM;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;CACb"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,EAAE,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,MAAM;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAGD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/lib/version.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
package/dist/umd/supabase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.supabase=e():t.supabase=e()}(self,(function(){return t={98:function(t,e){var r="undefined"!=typeof self?self:this,n=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function h(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=d(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=d(e)},l.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),h(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),h(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),h(t)},n&&(l.prototype[Symbol.iterator]=l.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function g(t,e){var r,n,o=(e=e||{}).body;if(t instanceof g){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function w(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function _(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}g.prototype.clone=function(){return new g(this,{body:this._bodyInit})},v.call(g.prototype),v.call(_.prototype),_.prototype.clone=function(){return new _(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},_.error=function(){var t=new _(null,{status:0,statusText:""});return t.type="error",t};var O=[301,302,303,307,308];_.redirect=function(t,e){if(-1===O.indexOf(e))throw new RangeError("Invalid status code");return new _(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function j(t,r){return new Promise((function(n,i){var s=new g(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new _(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}j.polyfill=!0,t.fetch||(t.fetch=j,t.Headers=l,t.Request=g,t.Response=_),e.Headers=l,e.Request=g,e.Response=_,e.fetch=j,Object.defineProperty(e,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var o=n;(e=o.fetch).default=o.fetch,e.fetch=o.fetch,e.Headers=o.Headers,e.Request=o.Request,e.Response=o.Response,t.exports=e},215:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const n=r(965);class o extends n.StorageBucketApi{constructor(t,e={}){super(t,e)}from(t){return new n.StorageFileApi(this.url,this.headers,t)}}e.SupabaseStorageClient=o},341:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const i=r(215);Object.defineProperty(e,"SupabaseStorageClient",{enumerable:!0,get:function(){return i.SupabaseStorageClient}}),o(r(717),e)},150:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageBucketApi=void 0;const o=r(716);e.StorageBucketApi=class{constructor(t,e={}){this.url=t,this.headers=e}listBuckets(){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}getBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(`${this.url}/bucket/${t}`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createBucket(t,e={public:!1}){return n(this,void 0,void 0,(function*(){try{return{data:(yield o.post(`${this.url}/bucket`,{id:t,name:t,public:e.public},{headers:this.headers})).name,error:null}}catch(t){return{data:null,error:t}}}))}updateBucket(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield o.put(`${this.url}/bucket/${t}`,{id:t,name:t,public:e.public},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}emptyBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.post(`${this.url}/bucket/${t}/empty`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}deleteBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.remove(`${this.url}/bucket/${t}`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}}},948:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageFileApi=void 0;const o=r(716),i=r(610),s={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},a={cacheControl:"3600",upsert:!1};e.StorageFileApi=class{constructor(t,e={},r){this.url=t,this.headers=e,this.bucketId=r}upload(t,e,r){return n(this,void 0,void 0,(function*(){try{if(!i.isBrowser())throw new Error("No browser detected.");const n=new FormData,o=Object.assign(Object.assign({},a),r);n.append("cacheControl",o.cacheControl),n.append("",e,e.name);const s=this._getFinalPath(t),u=yield fetch(`${this.url}/object/${s}`,{method:"POST",body:n,headers:Object.assign(Object.assign({},this.headers),{"x-upsert":String(null==r?void 0:r.upsert)})});return u.ok?{data:{Key:s},error:null}:{data:null,error:yield u.json()}}catch(t){return{data:null,error:t}}}))}update(t,e,r){return n(this,void 0,void 0,(function*(){try{if(!i.isBrowser())throw new Error("No browser detected.");const n=new FormData,o=Object.assign(Object.assign({},a),r);n.append("cacheControl",o.cacheControl),n.append("",e,e.name);const s=this._getFinalPath(t),u=yield fetch(`${this.url}/object/${s}`,{method:"PUT",body:n,headers:Object.assign({},this.headers)});return u.ok?{data:{Key:s},error:null}:{data:null,error:yield u.json()}}catch(t){return{data:null,error:t}}}))}move(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield o.post(`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createSignedUrl(t,e){return n(this,void 0,void 0,(function*(){try{const r=this._getFinalPath(t);let n=yield o.post(`${this.url}/object/sign/${r}`,{expiresIn:e},{headers:this.headers});const i=`${this.url}${n.signedURL}`;return n={signedURL:i},{data:n,error:null,signedURL:i}}catch(t){return{data:null,error:t,signedURL:null}}}))}download(t){return n(this,void 0,void 0,(function*(){try{const e=this._getFinalPath(t),r=yield o.get(`${this.url}/object/${e}`,{headers:this.headers,noResolveJson:!0});return{data:yield r.blob(),error:null}}catch(t){return{data:null,error:t}}}))}getPublicUrl(t){try{const e=this._getFinalPath(t),r=`${this.url}/object/public/${e}`;return{data:{publicURL:r},error:null,publicURL:r}}catch(t){return{data:null,error:t,publicURL:null}}}remove(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.remove(`${this.url}/object/${this.bucketId}`,{prefixes:t},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}list(t,e,r){return n(this,void 0,void 0,(function*(){try{const n=Object.assign(Object.assign(Object.assign({},s),e),{prefix:t||""});return{data:yield o.post(`${this.url}/object/list/${this.bucketId}`,n,{headers:this.headers},r),error:null}}catch(t){return{data:null,error:t}}}))}_getFinalPath(t){return`${this.bucketId}/${t}`}}},716:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.remove=e.put=e.post=e.get=void 0;const i=o(r(98)),s=t=>t.msg||t.message||t.error_description||t.error||JSON.stringify(t);function a(t,e,r,o,a){return n(this,void 0,void 0,(function*(){return new Promise(((n,u)=>{i.default(e,((t,e,r,n)=>{const o={method:t,headers:(null==e?void 0:e.headers)||{}};return"GET"===t?o:(o.headers=Object.assign({"Content-Type":"application/json"},null==e?void 0:e.headers),o.body=JSON.stringify(n),Object.assign(Object.assign({},o),r))})(t,r,o,a)).then((t=>{if(!t.ok)throw t;return(null==r?void 0:r.noResolveJson)?n(t):t.json()})).then((t=>n(t))).catch((t=>((t,e)=>{if("function"!=typeof t.json)return e(t);t.json().then((r=>e({message:s(r),status:(null==t?void 0:t.status)||500})))})(t,u)))}))}))}e.get=function(t,e,r){return n(this,void 0,void 0,(function*(){return a("GET",t,e,r)}))},e.post=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("POST",t,r,o,e)}))},e.put=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("PUT",t,r,o,e)}))},e.remove=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a("DELETE",t,r,o,e)}))}},610:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isBrowser=void 0,e.isBrowser=()=>"undefined"!=typeof window},965:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(150),e),o(r(948),e),o(r(717),e)},717:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})}},e={},function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(341);var t,e}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.supabase=e():t.supabase=e()}(self,(function(){return t={98:function(t,e){var r="undefined"!=typeof self?self:this,n=function(){function t(){this.fetch=!1,this.DOMException=r.DOMException}return t.prototype=r,new t}();!function(t){!function(e){var r="URLSearchParams"in t,n="Symbol"in t&&"iterator"in Symbol,o="FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),i="FormData"in t,s="ArrayBuffer"in t;if(s)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(t){return t&&a.indexOf(Object.prototype.toString.call(t))>-1};function c(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function h(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return n&&(e[Symbol.iterator]=function(){return e}),e}function l(t){this.map={},t instanceof l?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function p(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function y(t){var e=new FileReader,r=p(e);return e.readAsArrayBuffer(t),r}function b(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:o&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s&&o&&(e=t)&&DataView.prototype.isPrototypeOf(e)?(this._bodyArrayBuffer=b(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s&&(ArrayBuffer.prototype.isPrototypeOf(t)||u(t))?this._bodyArrayBuffer=b(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var t=f(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(y)}),this.text=function(){var t,e,r,n=f(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,r=p(e=new FileReader),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}l.prototype.append=function(t,e){t=c(t),e=h(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},l.prototype.delete=function(t){delete this.map[c(t)]},l.prototype.get=function(t){return t=c(t),this.has(t)?this.map[t]:null},l.prototype.has=function(t){return this.map.hasOwnProperty(c(t))},l.prototype.set=function(t,e){this.map[c(t)]=h(e)},l.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},l.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),d(t)},l.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},l.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),d(t)},n&&(l.prototype[Symbol.iterator]=l.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function g(t,e){var r,n,o=(e=e||{}).body;if(t instanceof g){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new l(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new l(e.headers)),this.method=(n=(r=e.method||this.method||"GET").toUpperCase(),m.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function w(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new l(e.headers),this.url=e.url||"",this._initBody(t)}g.prototype.clone=function(){return new g(this,{body:this._bodyInit})},v.call(g.prototype),v.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new l(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var O=[301,302,303,307,308];w.redirect=function(t,e){if(-1===O.indexOf(e))throw new RangeError("Invalid status code");return new w(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function j(t,r){return new Promise((function(n,i){var s=new g(t,r);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new l,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var o="response"in a?a.response:a.responseText;n(new w(o,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}j.polyfill=!0,t.fetch||(t.fetch=j,t.Headers=l,t.Request=g,t.Response=w),e.Headers=l,e.Request=g,e.Response=w,e.fetch=j,Object.defineProperty(e,"__esModule",{value:!0})}({})}(n),n.fetch.ponyfill=!0,delete n.fetch.polyfill;var o=n;(e=o.fetch).default=o.fetch,e.fetch=o.fetch,e.Headers=o.Headers,e.Request=o.Request,e.Response=o.Response,t.exports=e},215:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const n=r(965);class o extends n.StorageBucketApi{constructor(t,e={},r){super(t,e,r)}from(t){return new n.StorageFileApi(this.url,this.headers,t,this.fetch)}}e.SupabaseStorageClient=o},341:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),e.SupabaseStorageClient=void 0;const i=r(215);Object.defineProperty(e,"SupabaseStorageClient",{enumerable:!0,get:function(){return i.SupabaseStorageClient}}),o(r(717),e)},150:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageBucketApi=void 0;const o=r(716),i=r(678);e.StorageBucketApi=class{constructor(t,e={},r){this.url=t,this.headers=Object.assign(Object.assign({},i.DEFAULT_HEADERS),e),this.fetch=r}listBuckets(){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(this.fetch,`${this.url}/bucket`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}getBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.get(this.fetch,`${this.url}/bucket/${t}`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createBucket(t,e={public:!1}){return n(this,void 0,void 0,(function*(){try{return{data:(yield o.post(this.fetch,`${this.url}/bucket`,{id:t,name:t,public:e.public},{headers:this.headers})).name,error:null}}catch(t){return{data:null,error:t}}}))}updateBucket(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield o.put(this.fetch,`${this.url}/bucket/${t}`,{id:t,name:t,public:e.public},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}emptyBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.post(this.fetch,`${this.url}/bucket/${t}/empty`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}deleteBucket(t){return n(this,void 0,void 0,(function*(){try{return{data:yield o.remove(this.fetch,`${this.url}/bucket/${t}`,{},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}}},948:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.StorageFileApi=void 0;const i=r(716),s=o(r(98)),a={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},u={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};e.StorageFileApi=class{constructor(t,e={},r,n){this.url=t,this.headers=e,this.bucketId=r,this.fetch=n}uploadOrUpdate(t,e,r,o){return n(this,void 0,void 0,(function*(){try{let n;const i=Object.assign(Object.assign({},u),o),a=Object.assign(Object.assign({},this.headers),"POST"===t&&{"x-upsert":String(i.upsert)});"undefined"!=typeof Blob&&r instanceof Blob?(n=new FormData,n.append("cacheControl",i.cacheControl),n.append("",r)):"undefined"!=typeof FormData&&r instanceof FormData?(n=r,n.append("cacheControl",i.cacheControl)):(n=r,a["cache-control"]=`max-age=${i.cacheControl}`,a["content-type"]=i.contentType);const c=this._getFinalPath(e),h=yield s.default(`${this.url}/object/${c}`,{method:t,body:n,headers:a});return h.ok?{data:{Key:c},error:null}:{data:null,error:yield h.json()}}catch(t){return{data:null,error:t}}}))}upload(t,e,r){return n(this,void 0,void 0,(function*(){return this.uploadOrUpdate("POST",t,e,r)}))}update(t,e,r){return n(this,void 0,void 0,(function*(){return this.uploadOrUpdate("PUT",t,e,r)}))}move(t,e){return n(this,void 0,void 0,(function*(){try{return{data:yield i.post(this.fetch,`${this.url}/object/move`,{bucketId:this.bucketId,sourceKey:t,destinationKey:e},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}createSignedUrl(t,e){return n(this,void 0,void 0,(function*(){try{const r=this._getFinalPath(t);let n=yield i.post(this.fetch,`${this.url}/object/sign/${r}`,{expiresIn:e},{headers:this.headers});const o=`${this.url}${n.signedURL}`;return n={signedURL:o},{data:n,error:null,signedURL:o}}catch(t){return{data:null,error:t,signedURL:null}}}))}download(t){return n(this,void 0,void 0,(function*(){try{const e=this._getFinalPath(t),r=yield i.get(this.fetch,`${this.url}/object/${e}`,{headers:this.headers,noResolveJson:!0});return{data:yield r.blob(),error:null}}catch(t){return{data:null,error:t}}}))}getPublicUrl(t){try{const e=this._getFinalPath(t),r=`${this.url}/object/public/${e}`;return{data:{publicURL:r},error:null,publicURL:r}}catch(t){return{data:null,error:t,publicURL:null}}}remove(t){return n(this,void 0,void 0,(function*(){try{return{data:yield i.remove(this.fetch,`${this.url}/object/${this.bucketId}`,{prefixes:t},{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}}))}list(t,e,r){return n(this,void 0,void 0,(function*(){try{const n=Object.assign(Object.assign(Object.assign({},a),e),{prefix:t||""});return{data:yield i.post(this.fetch,`${this.url}/object/list/${this.bucketId}`,n,{headers:this.headers},r),error:null}}catch(t){return{data:null,error:t}}}))}_getFinalPath(t){return`${this.bucketId}/${t}`}}},678:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_HEADERS=void 0;const n=r(506);e.DEFAULT_HEADERS={"X-Client-Info":`storage-js/${n.version}`}},716:function(t,e,r){"use strict";var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.remove=e.put=e.post=e.get=void 0;const i=o(r(98)),s=t=>t.msg||t.message||t.error_description||t.error||JSON.stringify(t);function a(t=i.default,e,r,o,a,u){return n(this,void 0,void 0,(function*(){return new Promise(((n,i)=>{t(r,((t,e,r,n)=>{const o={method:t,headers:(null==e?void 0:e.headers)||{}};return"GET"===t?o:(o.headers=Object.assign({"Content-Type":"application/json"},null==e?void 0:e.headers),o.body=JSON.stringify(n),Object.assign(Object.assign({},o),r))})(e,o,a,u)).then((t=>{if(!t.ok)throw t;return(null==o?void 0:o.noResolveJson)?n(t):t.json()})).then((t=>n(t))).catch((t=>((t,e)=>{if("function"!=typeof t.json)return e(t);t.json().then((r=>e({message:s(r),status:(null==t?void 0:t.status)||500})))})(t,i)))}))}))}e.get=function(t,e,r,o){return n(this,void 0,void 0,(function*(){return a(t,"GET",e,r,o)}))},e.post=function(t,e,r,o,i){return n(this,void 0,void 0,(function*(){return a(t,"POST",e,o,i,r)}))},e.put=function(t,e,r,o,i){return n(this,void 0,void 0,(function*(){return a(t,"PUT",e,o,i,r)}))},e.remove=function(t,e,r,o,i){return n(this,void 0,void 0,(function*(){return a(t,"DELETE",e,o,i,r)}))}},965:function(t,e,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),o=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),o(r(150),e),o(r(948),e),o(r(717),e),o(r(678),e)},717:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},506:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.version=void 0,e.version="0.0.0"}},e={},function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(341);var t,e}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/storage-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Isomorphic storage client for Supabase.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"clean": "rimraf dist docs",
|
|
25
25
|
"format": "prettier --write \"{src,test}/**/*.ts\"",
|
|
26
|
-
"build": "run-s clean format build:*",
|
|
26
|
+
"build": "genversion src/lib/version.ts --es6 && run-s clean format build:*",
|
|
27
27
|
"build:main": "tsc -p tsconfig.json",
|
|
28
28
|
"build:module": "tsc -p tsconfig.module.json",
|
|
29
29
|
"build:umd": "webpack",
|
|
@@ -40,12 +40,14 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "^26.0.13",
|
|
43
|
+
"genversion": "^3.0.1",
|
|
43
44
|
"husky": "^4.3.0",
|
|
44
45
|
"jest": "^26.4.1",
|
|
45
46
|
"npm-run-all": "^4.1.5",
|
|
46
47
|
"prettier": "^2.1.2",
|
|
47
48
|
"pretty-quick": "^3.1.0",
|
|
48
49
|
"rimraf": "^3.0.2",
|
|
50
|
+
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
|
49
51
|
"ts-jest": "^26.3.0",
|
|
50
52
|
"ts-loader": "^8.0.11",
|
|
51
53
|
"typedoc": "^0.19.1",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { StorageBucketApi, StorageFileApi } from './lib'
|
|
2
|
+
import { Fetch } from './lib/fetch'
|
|
2
3
|
|
|
3
4
|
export class SupabaseStorageClient extends StorageBucketApi {
|
|
4
|
-
constructor(url: string, headers: { [key: string]: string } = {}) {
|
|
5
|
-
super(url, headers)
|
|
5
|
+
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
|
|
6
|
+
super(url, headers, fetch)
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -11,6 +12,6 @@ export class SupabaseStorageClient extends StorageBucketApi {
|
|
|
11
12
|
* @param id The bucket id to operate on.
|
|
12
13
|
*/
|
|
13
14
|
from(id: string): StorageFileApi {
|
|
14
|
-
return new StorageFileApi(this.url, this.headers, id)
|
|
15
|
+
return new StorageFileApi(this.url, this.headers, id, this.fetch)
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { get, post, put, remove } from './fetch'
|
|
1
|
+
import { Fetch, get, post, put, remove } from './fetch'
|
|
2
2
|
import { Bucket } from './types'
|
|
3
|
+
import { DEFAULT_HEADERS } from './constants'
|
|
3
4
|
|
|
4
5
|
export class StorageBucketApi {
|
|
5
6
|
protected url: string
|
|
6
7
|
protected headers: { [key: string]: string }
|
|
8
|
+
protected fetch?: Fetch
|
|
7
9
|
|
|
8
|
-
constructor(url: string, headers: { [key: string]: string } = {}) {
|
|
10
|
+
constructor(url: string, headers: { [key: string]: string } = {}, fetch?: Fetch) {
|
|
9
11
|
this.url = url
|
|
10
|
-
this.headers = headers
|
|
12
|
+
this.headers = { ...DEFAULT_HEADERS, ...headers }
|
|
13
|
+
this.fetch = fetch
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
/**
|
|
@@ -15,7 +18,7 @@ export class StorageBucketApi {
|
|
|
15
18
|
*/
|
|
16
19
|
async listBuckets(): Promise<{ data: Bucket[] | null; error: Error | null }> {
|
|
17
20
|
try {
|
|
18
|
-
const data = await get(`${this.url}/bucket`, { headers: this.headers })
|
|
21
|
+
const data = await get(this.fetch, `${this.url}/bucket`, { headers: this.headers })
|
|
19
22
|
return { data, error: null }
|
|
20
23
|
} catch (error) {
|
|
21
24
|
return { data: null, error }
|
|
@@ -29,7 +32,7 @@ export class StorageBucketApi {
|
|
|
29
32
|
*/
|
|
30
33
|
async getBucket(id: string): Promise<{ data: Bucket | null; error: Error | null }> {
|
|
31
34
|
try {
|
|
32
|
-
const data = await get(`${this.url}/bucket/${id}`, { headers: this.headers })
|
|
35
|
+
const data = await get(this.fetch, `${this.url}/bucket/${id}`, { headers: this.headers })
|
|
33
36
|
return { data, error: null }
|
|
34
37
|
} catch (error) {
|
|
35
38
|
return { data: null, error }
|
|
@@ -48,6 +51,7 @@ export class StorageBucketApi {
|
|
|
48
51
|
): Promise<{ data: string | null; error: Error | null }> {
|
|
49
52
|
try {
|
|
50
53
|
const data = await post(
|
|
54
|
+
this.fetch,
|
|
51
55
|
`${this.url}/bucket`,
|
|
52
56
|
{ id, name: id, public: options.public },
|
|
53
57
|
{ headers: this.headers }
|
|
@@ -69,6 +73,7 @@ export class StorageBucketApi {
|
|
|
69
73
|
): Promise<{ data: { message: string } | null; error: Error | null }> {
|
|
70
74
|
try {
|
|
71
75
|
const data = await put(
|
|
76
|
+
this.fetch,
|
|
72
77
|
`${this.url}/bucket/${id}`,
|
|
73
78
|
{ id, name: id, public: options.public },
|
|
74
79
|
{ headers: this.headers }
|
|
@@ -88,7 +93,12 @@ export class StorageBucketApi {
|
|
|
88
93
|
id: string
|
|
89
94
|
): Promise<{ data: { message: string } | null; error: Error | null }> {
|
|
90
95
|
try {
|
|
91
|
-
const data = await post(
|
|
96
|
+
const data = await post(
|
|
97
|
+
this.fetch,
|
|
98
|
+
`${this.url}/bucket/${id}/empty`,
|
|
99
|
+
{},
|
|
100
|
+
{ headers: this.headers }
|
|
101
|
+
)
|
|
92
102
|
return { data, error: null }
|
|
93
103
|
} catch (error) {
|
|
94
104
|
return { data: null, error }
|
|
@@ -105,7 +115,12 @@ export class StorageBucketApi {
|
|
|
105
115
|
id: string
|
|
106
116
|
): Promise<{ data: { message: string } | null; error: Error | null }> {
|
|
107
117
|
try {
|
|
108
|
-
const data = await remove(
|
|
118
|
+
const data = await remove(
|
|
119
|
+
this.fetch,
|
|
120
|
+
`${this.url}/bucket/${id}`,
|
|
121
|
+
{},
|
|
122
|
+
{ headers: this.headers }
|
|
123
|
+
)
|
|
109
124
|
return { data, error: null }
|
|
110
125
|
} catch (error) {
|
|
111
126
|
return { data: null, error }
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { FetchParameters, get, post, remove } from './fetch'
|
|
1
|
+
import { Fetch, FetchParameters, get, post, remove } from './fetch'
|
|
2
2
|
import { isBrowser } from './helpers'
|
|
3
3
|
import { FileObject, FileOptions, SearchOptions } from './types'
|
|
4
|
+
import fetch from 'cross-fetch'
|
|
4
5
|
|
|
5
6
|
const DEFAULT_SEARCH_OPTIONS = {
|
|
6
7
|
limit: 100,
|
|
@@ -13,6 +14,7 @@ const DEFAULT_SEARCH_OPTIONS = {
|
|
|
13
14
|
|
|
14
15
|
const DEFAULT_FILE_OPTIONS: FileOptions = {
|
|
15
16
|
cacheControl: '3600',
|
|
17
|
+
contentType: 'text/plain;charset=UTF-8',
|
|
16
18
|
upsert: false,
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -20,42 +22,73 @@ export class StorageFileApi {
|
|
|
20
22
|
protected url: string
|
|
21
23
|
protected headers: { [key: string]: string }
|
|
22
24
|
protected bucketId?: string
|
|
25
|
+
protected fetch?: Fetch
|
|
23
26
|
|
|
24
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
url: string,
|
|
29
|
+
headers: { [key: string]: string } = {},
|
|
30
|
+
bucketId?: string,
|
|
31
|
+
fetch?: Fetch
|
|
32
|
+
) {
|
|
25
33
|
this.url = url
|
|
26
34
|
this.headers = headers
|
|
27
35
|
this.bucketId = bucketId
|
|
36
|
+
this.fetch = fetch
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
/**
|
|
31
|
-
* Uploads a file to an existing bucket.
|
|
40
|
+
* Uploads a file to an existing bucket or replaces an existing file at the specified path with a new one.
|
|
32
41
|
*
|
|
42
|
+
* @param method HTTP method.
|
|
33
43
|
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
34
|
-
* @param
|
|
35
|
-
* @param fileOptions HTTP headers.
|
|
44
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
45
|
+
* @param fileOptions HTTP headers.
|
|
46
|
+
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
|
|
47
|
+
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
|
|
48
|
+
* `upsert`: boolean, whether to perform an upsert.
|
|
36
49
|
*/
|
|
37
|
-
async
|
|
50
|
+
private async uploadOrUpdate(
|
|
51
|
+
method: 'POST' | 'PUT',
|
|
38
52
|
path: string,
|
|
39
|
-
|
|
53
|
+
fileBody:
|
|
54
|
+
| ArrayBuffer
|
|
55
|
+
| ArrayBufferView
|
|
56
|
+
| Blob
|
|
57
|
+
| Buffer
|
|
58
|
+
| File
|
|
59
|
+
| FormData
|
|
60
|
+
| NodeJS.ReadableStream
|
|
61
|
+
| ReadableStream<Uint8Array>
|
|
62
|
+
| URLSearchParams
|
|
63
|
+
| string,
|
|
40
64
|
fileOptions?: FileOptions
|
|
41
65
|
): Promise<{ data: { Key: string } | null; error: Error | null }> {
|
|
42
66
|
try {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const formData = new FormData()
|
|
46
|
-
|
|
67
|
+
let body
|
|
47
68
|
const options = { ...DEFAULT_FILE_OPTIONS, ...fileOptions }
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
const headers: Record<string, string> = {
|
|
70
|
+
...this.headers,
|
|
71
|
+
...(method === 'POST' && { 'x-upsert': String(options.upsert as boolean) }),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof Blob !== 'undefined' && fileBody instanceof Blob) {
|
|
75
|
+
body = new FormData()
|
|
76
|
+
body.append('cacheControl', options.cacheControl as string)
|
|
77
|
+
body.append('', fileBody)
|
|
78
|
+
} else if (typeof FormData !== 'undefined' && fileBody instanceof FormData) {
|
|
79
|
+
body = fileBody
|
|
80
|
+
body.append('cacheControl', options.cacheControl as string)
|
|
81
|
+
} else {
|
|
82
|
+
body = fileBody
|
|
83
|
+
headers['cache-control'] = `max-age=${options.cacheControl}`
|
|
84
|
+
headers['content-type'] = options.contentType as string
|
|
85
|
+
}
|
|
50
86
|
|
|
51
87
|
const _path = this._getFinalPath(path)
|
|
52
88
|
const res = await fetch(`${this.url}/object/${_path}`, {
|
|
53
|
-
method
|
|
54
|
-
body:
|
|
55
|
-
headers
|
|
56
|
-
...this.headers,
|
|
57
|
-
'x-upsert': String(fileOptions?.upsert),
|
|
58
|
-
},
|
|
89
|
+
method,
|
|
90
|
+
body: body as BodyInit,
|
|
91
|
+
headers,
|
|
59
92
|
})
|
|
60
93
|
|
|
61
94
|
if (res.ok) {
|
|
@@ -71,45 +104,60 @@ export class StorageFileApi {
|
|
|
71
104
|
}
|
|
72
105
|
}
|
|
73
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Uploads a file to an existing bucket.
|
|
109
|
+
*
|
|
110
|
+
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
111
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
112
|
+
* @param fileOptions HTTP headers.
|
|
113
|
+
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
|
|
114
|
+
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
|
|
115
|
+
* `upsert`: boolean, whether to perform an upsert.
|
|
116
|
+
*/
|
|
117
|
+
async upload(
|
|
118
|
+
path: string,
|
|
119
|
+
fileBody:
|
|
120
|
+
| ArrayBuffer
|
|
121
|
+
| ArrayBufferView
|
|
122
|
+
| Blob
|
|
123
|
+
| Buffer
|
|
124
|
+
| File
|
|
125
|
+
| FormData
|
|
126
|
+
| NodeJS.ReadableStream
|
|
127
|
+
| ReadableStream<Uint8Array>
|
|
128
|
+
| URLSearchParams
|
|
129
|
+
| string,
|
|
130
|
+
fileOptions?: FileOptions
|
|
131
|
+
): Promise<{ data: { Key: string } | null; error: Error | null }> {
|
|
132
|
+
return this.uploadOrUpdate('POST', path, fileBody, fileOptions)
|
|
133
|
+
}
|
|
134
|
+
|
|
74
135
|
/**
|
|
75
136
|
* Replaces an existing file at the specified path with a new one.
|
|
76
137
|
*
|
|
77
|
-
* @param path The relative file path. Should be of the format `folder/subfolder`. The bucket already exist before attempting to upload.
|
|
78
|
-
* @param
|
|
79
|
-
* @param fileOptions HTTP headers.
|
|
138
|
+
* @param path The relative file path. Should be of the format `folder/subfolder/filename.png`. The bucket must already exist before attempting to upload.
|
|
139
|
+
* @param fileBody The body of the file to be stored in the bucket.
|
|
140
|
+
* @param fileOptions HTTP headers.
|
|
141
|
+
* `cacheControl`: string, the `Cache-Control: max-age=<seconds>` seconds value.
|
|
142
|
+
* `contentType`: string, the `Content-Type` header value. Should be specified if using a `fileBody` that is neither `Blob` nor `File` nor `FormData`, otherwise will default to `text/plain;charset=UTF-8`.
|
|
143
|
+
* `upsert`: boolean, whether to perform an upsert.
|
|
80
144
|
*/
|
|
81
145
|
async update(
|
|
82
146
|
path: string,
|
|
83
|
-
|
|
147
|
+
fileBody:
|
|
148
|
+
| ArrayBuffer
|
|
149
|
+
| ArrayBufferView
|
|
150
|
+
| Blob
|
|
151
|
+
| Buffer
|
|
152
|
+
| File
|
|
153
|
+
| FormData
|
|
154
|
+
| NodeJS.ReadableStream
|
|
155
|
+
| ReadableStream<Uint8Array>
|
|
156
|
+
| URLSearchParams
|
|
157
|
+
| string,
|
|
84
158
|
fileOptions?: FileOptions
|
|
85
159
|
): Promise<{ data: { Key: string } | null; error: Error | null }> {
|
|
86
|
-
|
|
87
|
-
if (!isBrowser()) throw new Error('No browser detected.')
|
|
88
|
-
|
|
89
|
-
const formData = new FormData()
|
|
90
|
-
|
|
91
|
-
const options = { ...DEFAULT_FILE_OPTIONS, ...fileOptions }
|
|
92
|
-
formData.append('cacheControl', options.cacheControl)
|
|
93
|
-
formData.append('', file, file.name)
|
|
94
|
-
|
|
95
|
-
const _path = this._getFinalPath(path)
|
|
96
|
-
const res = await fetch(`${this.url}/object/${_path}`, {
|
|
97
|
-
method: 'PUT',
|
|
98
|
-
body: formData,
|
|
99
|
-
headers: { ...this.headers },
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
if (res.ok) {
|
|
103
|
-
// const data = await res.json()
|
|
104
|
-
// temporary fix till backend is updated to the latest storage-api version
|
|
105
|
-
return { data: { Key: _path }, error: null }
|
|
106
|
-
} else {
|
|
107
|
-
const error = await res.json()
|
|
108
|
-
return { data: null, error }
|
|
109
|
-
}
|
|
110
|
-
} catch (error) {
|
|
111
|
-
return { data: null, error }
|
|
112
|
-
}
|
|
160
|
+
return this.uploadOrUpdate('PUT', path, fileBody, fileOptions)
|
|
113
161
|
}
|
|
114
162
|
|
|
115
163
|
/**
|
|
@@ -124,6 +172,7 @@ export class StorageFileApi {
|
|
|
124
172
|
): Promise<{ data: { message: string } | null; error: Error | null }> {
|
|
125
173
|
try {
|
|
126
174
|
const data = await post(
|
|
175
|
+
this.fetch,
|
|
127
176
|
`${this.url}/object/move`,
|
|
128
177
|
{ bucketId: this.bucketId, sourceKey: fromPath, destinationKey: toPath },
|
|
129
178
|
{ headers: this.headers }
|
|
@@ -151,6 +200,7 @@ export class StorageFileApi {
|
|
|
151
200
|
try {
|
|
152
201
|
const _path = this._getFinalPath(path)
|
|
153
202
|
let data = await post(
|
|
203
|
+
this.fetch,
|
|
154
204
|
`${this.url}/object/sign/${_path}`,
|
|
155
205
|
{ expiresIn },
|
|
156
206
|
{ headers: this.headers }
|
|
@@ -171,7 +221,7 @@ export class StorageFileApi {
|
|
|
171
221
|
async download(path: string): Promise<{ data: Blob | null; error: Error | null }> {
|
|
172
222
|
try {
|
|
173
223
|
const _path = this._getFinalPath(path)
|
|
174
|
-
const res = await get(`${this.url}/object/${_path}`, {
|
|
224
|
+
const res = await get(this.fetch, `${this.url}/object/${_path}`, {
|
|
175
225
|
headers: this.headers,
|
|
176
226
|
noResolveJson: true,
|
|
177
227
|
})
|
|
@@ -212,6 +262,7 @@ export class StorageFileApi {
|
|
|
212
262
|
async remove(paths: string[]): Promise<{ data: FileObject[] | null; error: Error | null }> {
|
|
213
263
|
try {
|
|
214
264
|
const data = await remove(
|
|
265
|
+
this.fetch,
|
|
215
266
|
`${this.url}/object/${this.bucketId}`,
|
|
216
267
|
{ prefixes: paths },
|
|
217
268
|
{ headers: this.headers }
|
|
@@ -266,6 +317,7 @@ export class StorageFileApi {
|
|
|
266
317
|
try {
|
|
267
318
|
const body = { ...DEFAULT_SEARCH_OPTIONS, ...options, prefix: path || '' }
|
|
268
319
|
const data = await post(
|
|
320
|
+
this.fetch,
|
|
269
321
|
`${this.url}/object/list/${this.bucketId}`,
|
|
270
322
|
body,
|
|
271
323
|
{ headers: this.headers },
|
package/src/lib/fetch.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import crossFetch from 'cross-fetch'
|
|
2
|
+
|
|
3
|
+
export type Fetch = typeof fetch
|
|
2
4
|
|
|
3
5
|
export interface FetchOptions {
|
|
4
6
|
headers?: {
|
|
@@ -46,6 +48,7 @@ const _getRequestParams = (
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
async function _handleRequest(
|
|
51
|
+
fetcher: Fetch = crossFetch,
|
|
49
52
|
method: RequestMethodType,
|
|
50
53
|
url: string,
|
|
51
54
|
options?: FetchOptions,
|
|
@@ -53,7 +56,7 @@ async function _handleRequest(
|
|
|
53
56
|
body?: object
|
|
54
57
|
): Promise<any> {
|
|
55
58
|
return new Promise((resolve, reject) => {
|
|
56
|
-
|
|
59
|
+
fetcher(url, _getRequestParams(method, options, parameters, body))
|
|
57
60
|
.then((result) => {
|
|
58
61
|
if (!result.ok) throw result
|
|
59
62
|
if (options?.noResolveJson) return resolve(result)
|
|
@@ -65,36 +68,40 @@ async function _handleRequest(
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export async function get(
|
|
71
|
+
fetcher: Fetch | undefined,
|
|
68
72
|
url: string,
|
|
69
73
|
options?: FetchOptions,
|
|
70
74
|
parameters?: FetchParameters
|
|
71
75
|
): Promise<any> {
|
|
72
|
-
return _handleRequest('GET', url, options, parameters)
|
|
76
|
+
return _handleRequest(fetcher, 'GET', url, options, parameters)
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
export async function post(
|
|
80
|
+
fetcher: Fetch | undefined,
|
|
76
81
|
url: string,
|
|
77
82
|
body: object,
|
|
78
83
|
options?: FetchOptions,
|
|
79
84
|
parameters?: FetchParameters
|
|
80
85
|
): Promise<any> {
|
|
81
|
-
return _handleRequest('POST', url, options, parameters, body)
|
|
86
|
+
return _handleRequest(fetcher, 'POST', url, options, parameters, body)
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
export async function put(
|
|
90
|
+
fetcher: Fetch | undefined,
|
|
85
91
|
url: string,
|
|
86
92
|
body: object,
|
|
87
93
|
options?: FetchOptions,
|
|
88
94
|
parameters?: FetchParameters
|
|
89
95
|
): Promise<any> {
|
|
90
|
-
return _handleRequest('PUT', url, options, parameters, body)
|
|
96
|
+
return _handleRequest(fetcher, 'PUT', url, options, parameters, body)
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
export async function remove(
|
|
100
|
+
fetcher: Fetch | undefined,
|
|
94
101
|
url: string,
|
|
95
102
|
body: object,
|
|
96
103
|
options?: FetchOptions,
|
|
97
104
|
parameters?: FetchParameters
|
|
98
105
|
): Promise<any> {
|
|
99
|
-
return _handleRequest('DELETE', url, options, parameters, body)
|
|
106
|
+
return _handleRequest(fetcher, 'DELETE', url, options, parameters, body)
|
|
100
107
|
}
|
package/src/lib/index.ts
CHANGED
package/src/lib/types.ts
CHANGED