UNPKG

@cloudbase/js-sdk

Version:
1 lines 72.7 kB
import*as t from"@cloudbase/adapter-interface";import*as e from"jwt-decode";var n={388:t=>{t.exports={}}},r={};function o(t){var e=r[t];if(void 0!==e)return e.exports;var i=r[t]={exports:{}};return n[t](i,i.exports,o),i.exports}o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var i={};(()=>{o.d(i,{v:()=>qt});var n,r=(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),a=function(t){function e(e){var n=t.call(this,e)||this;return n.__isStorageError=!0,n.name="StorageError",n}return r(e,t),e}(Error);function s(t){return"object"==typeof t&&null!==t&&"__isStorageError"in t}var c,u=function(t){function e(e,n,r){var o=t.call(this,e)||this;return o.name="StorageApiError",o.status=n,o.statusCode=r,o}return r(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,status:this.status,statusCode:this.statusCode}},e}(a);function l(){return globalThis.Buffer}function d(t){var e=l();return e?e.from(t).toString("base64"):btoa(t)}function h(t){return t.split("/").map(function(t){return encodeURIComponent(t)}).join("/")}r(function(t,e){var n=c.call(this,t)||this;return n.name="StorageUnknownError",n.originalError=e,n},c=a);var f=function(){return f=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},f.apply(this,arguments)},p=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},y=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},v="/v1/storages";function m(t,e){return p(this,void 0,Promise,function(){var n;return y(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t()];case 1:return[2,{data:r.sent(),error:null}];case 2:if(n=r.sent(),e)throw n;return s(n)?[2,{data:null,error:n}]:[2,{data:null,error:new a((null==n?void 0:n.message)||String(n))}];case 3:return[2]}})})}var b=function(){function t(t){this.ctx=t}return Object.defineProperty(t.prototype,"request",{get:function(){return this.ctx.request},enumerable:!1,configurable:!0}),t.prototype.gatewayOrigin=function(){return this.request.getBaseEndPoint("GATEWAY")},t.prototype.buildUrl=function(t,e){var n="".concat(this.gatewayOrigin()).concat(v).concat(t),r=function(t){if(!t)return"";var e=[];return Object.keys(t).forEach(function(n){var r=t[n];null!=r&&e.push("".concat(encodeURIComponent(n),"=").concat(encodeURIComponent(String(r))))}),e.join("&")}(e);return r&&(n+=(n.includes("?")?"&":"?")+r),n},t.prototype.toFullUrl=function(t){return t?/^https?:\/\//.test(t)||t.startsWith("//")?t:"".concat(this.gatewayOrigin()).concat(v).concat(t.startsWith("/")?"":"/").concat(t):t},t.prototype.send=function(t){return p(this,void 0,Promise,function(){var e,n,r,o,i,a;return y(this,function(s){switch(s.label){case 0:return e=this.buildUrl(t.path,t.query),n=t.method.toUpperCase(),r=["GET","HEAD"].includes(n),o=f({},t.headers||{}),r||(void 0!==t.rawBody?i=t.rawBody:void 0!==t.json&&(o["Content-Type"]=o["Content-Type"]||"application/json",i=JSON.stringify(t.json))),[4,this.request.fetch(f(f(f(f({url:e,method:n,headers:o},void 0!==i?{body:i}:{}),{withCredentials:!1!==t.withCredentials,shouldThrowOnError:!1}),t.signal?{signal:t.signal}:{}),t.cache?{cache:t.cache}:{}))];case 1:return a=s.sent(),[2,this.unwrap(a,e)]}})})},t.prototype.download=function(t){var e,n;return p(this,void 0,Promise,function(){var r,o,i,a;return y(this,function(s){switch(s.label){case 0:return r=this.buildUrl(t.path,t.query),[4,this.request.fetch(f(f({url:r,method:"GET",headers:f({},t.headers||{}),stream:!0,withCredentials:!1!==t.withCredentials,shouldThrowOnError:!1},t.signal?{signal:t.signal}:{}),t.cache?{cache:t.cache}:{}))];case 1:if(o=s.sent(),null===(e=t.signal)||void 0===e?void 0:e.aborted)throw new u("The download was aborted",0,"STORAGE_PG_ABORTED");if(304===(i=Number(null!==(n=null==o?void 0:o.statusCode)&&void 0!==n?n:200)))throw new u("Not Modified",i,"STORAGE_PG_NOT_MODIFIED");if(i>=400)throw new u("Download failed with status ".concat(i),i,"STORAGE_PG_REQUEST_FAIL");if(!(a=null==o?void 0:o.response))throw new u("Underlying adapter did not expose the raw Response",i,"STORAGE_PG_NO_RESPONSE");return[2,{response:a,status:i,header:null==o?void 0:o.header}]}})})},t.prototype.unwrap=function(t,e){var n,r;return p(this,void 0,Promise,function(){var o,i,a,s;return y(this,function(c){switch(c.label){case 0:o=Number(null!==(r=null!==(n=null==t?void 0:t.statusCode)&&void 0!==n?n:null==t?void 0:t.status)&&void 0!==r?r:200),i=null==t?void 0:t.data,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,i];case 2:return i=c.sent(),[3,4];case 3:return c.sent(),i=void 0,[3,4];case 4:if(o>=200&&o<300)return[2,i];throw a=(null==i?void 0:i.code)||(null==i?void 0:i.error)||"STORAGE_PG_REQUEST_FAIL",s=(null==i?void 0:i.message)||"Storage request failed with status ".concat(o,": ").concat(e),new u(s,o,a)}})})},t}(),g=function(){return g=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},g.apply(this,arguments)},w=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},O=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};function I(t){return s(t)?t:new a((null==t?void 0:t.message)||String(t))}function P(t){var e={};return void 0!==(null==t?void 0:t.download)&&(e.download=!0===t.download?"":t.download),void 0!==(null==t?void 0:t.cacheNonce)&&(e.cacheNonce=String(t.cacheNonce)),{headers:{},query:e}}var S=function(){function t(t){this.ctx=t}return t.prototype.then=function(t,e){return this.execute().then(t,e)},t.prototype.execute=function(){var t,e;return w(this,void 0,Promise,function(){var n,r,o,i,a;return O(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),n=P(this.ctx.options),r=n.headers,o=n.query,[4,this.ctx.http.download({path:"/object/".concat(this.ctx.bucketId,"/").concat(h(this.ctx.cleanName)),headers:g(g({},this.ctx.headers),r),query:o,signal:null===(t=this.ctx.parameters)||void 0===t?void 0:t.signal,cache:null===(e=this.ctx.parameters)||void 0===e?void 0:e.cache})];case 1:if(!(i=s.sent().response).body)throw new u("Response body is empty",i.status,"STORAGE_PG_EMPTY_BODY");return[2,{data:i.body,error:null}];case 2:if(a=s.sent(),this.ctx.shouldThrowOnError)throw a;return[2,{data:null,error:I(a)}];case 3:return[2]}})})},t}(),E=function(){function t(t){this.ctx=t}return t.prototype.asStream=function(){return new S(this.ctx)},t.prototype.then=function(t,e){return this.execute().then(t,e)},t.prototype.execute=function(){var t,e;return w(this,void 0,Promise,function(){var n,r,o,i,a,s;return O(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),n=P(this.ctx.options),r=n.headers,o=n.query,[4,this.ctx.http.download({path:"/object/".concat(this.ctx.bucketId,"/").concat(h(this.ctx.cleanName)),headers:g(g({},this.ctx.headers),r),query:o,signal:null===(t=this.ctx.parameters)||void 0===t?void 0:t.signal,cache:null===(e=this.ctx.parameters)||void 0===e?void 0:e.cache})];case 1:return i=c.sent().response,s={},[4,i.blob()];case 2:return[2,(s.data=c.sent(),s.error=null,s)];case 3:if(a=c.sent(),this.ctx.shouldThrowOnError)throw a;return[2,{data:null,error:I(a)}];case 4:return[2]}})})},t}(),_=function(){return _=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},_.apply(this,arguments)},T=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},j=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},F="3600",L=function(){function t(t,e,n){void 0===n&&(n=!1),this.headers={},this.http=t,this.bucketId=e,this.shouldThrowOnError=n}return t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.setHeader=function(t,e){var n;if("string"!=typeof t||""===t.trim())throw new a("setHeader requires a non-empty header name");if(/[\r\n]/.test(t)||"string"==typeof e&&/[\r\n]/.test(e))throw new a("setHeader does not allow CR/LF characters in header name or value");return this.headers=_(_({},this.headers),((n={})[t]=String(e),n)),this},t.prototype.upload=function(t,e,n){return T(this,void 0,Promise,function(){return j(this,function(r){return[2,this.uploadOrUpdate("POST",t,e,n)]})})},t.prototype.update=function(t,e,n){return T(this,void 0,Promise,function(){return j(this,function(r){return[2,this.uploadOrUpdate("PUT",t,e,n)]})})},t.prototype.download=function(t,e,n){return new E({http:this.http,bucketId:this.bucketId,cleanName:this.cleanPath(t),options:e,parameters:n,headers:this.headers,shouldThrowOnError:this.shouldThrowOnError})},t.prototype.list=function(t,e,n){return T(this,void 0,Promise,function(){var r=this;return j(this,function(o){return[2,m(function(){return T(r,void 0,void 0,function(){var r;return j(this,function(o){return r={prefix:t||""},void 0!==(null==e?void 0:e.limit)&&(r.limit=e.limit),void 0!==(null==e?void 0:e.cursor)&&(r.cursor=e.cursor),void 0!==(null==e?void 0:e.withDelimiter)&&(r.with_delimiter=e.withDelimiter),void 0!==(null==e?void 0:e.sortBy)&&(r.sortBy=e.sortBy),[2,this.send({method:"POST",path:"/object/list/".concat(this.bucketId),json:r,signal:null==n?void 0:n.signal,cache:null==n?void 0:n.cache})]})})},this.shouldThrowOnError)]})})},t.prototype.remove=function(t){return T(this,void 0,Promise,function(){var e=this;return j(this,function(n){return[2,m(function(){return T(e,void 0,void 0,function(){var e,n,r,o,i,a=this;return j(this,function(s){switch(s.label){case 0:e=t.map(function(t){return a.cleanPath(t)}),n=[],r=0,s.label=1;case 1:return r<e.length?(o=e.slice(r,r+100),[4,this.send({method:"DELETE",path:"/object/".concat(this.bucketId),json:{prefixes:o}})]):[3,4];case 2:i=s.sent(),Array.isArray(i)&&n.push.apply(n,i),s.label=3;case 3:return r+=100,[3,1];case 4:return[2,n]}})})},this.shouldThrowOnError)]})})},t.prototype.copy=function(t,e,n){return T(this,void 0,Promise,function(){var r=this;return j(this,function(o){return[2,m(function(){return T(r,void 0,void 0,function(){var r;return j(this,function(o){switch(o.label){case 0:return r=this.buildCopyMoveHeaders(n),[4,this.send({method:"POST",path:"/object/copy",json:{bucketId:this.bucketId,sourceKey:this.cleanPath(t),destinationKey:this.cleanPath(e),destinationBucket:null==n?void 0:n.destinationBucket,copyMetadata:null==n?void 0:n.copyMetadata,metadata:null==n?void 0:n.metadata},headers:r})];case 1:return[2,{path:o.sent().Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.move=function(t,e,n){return T(this,void 0,Promise,function(){var r=this;return j(this,function(o){return[2,m(function(){return T(r,void 0,void 0,function(){return j(this,function(r){switch(r.label){case 0:return[4,this.send({method:"POST",path:"/object/move",json:{bucketId:this.bucketId,sourceKey:this.cleanPath(t),destinationKey:this.cleanPath(e),destinationBucket:null==n?void 0:n.destinationBucket}})];case 1:return[2,{message:r.sent().message||"Successfully moved"}]}})})},this.shouldThrowOnError)]})})},t.prototype.info=function(t){return T(this,void 0,Promise,function(){var e=this;return j(this,function(n){return[2,m(function(){return T(e,void 0,void 0,function(){var e,n;return j(this,function(r){switch(r.label){case 0:return e=this.cleanPath(t),[4,this.send({method:"GET",path:"/object/info/".concat(this.bucketId,"/").concat(this.encodePath(e))})];case 1:return[2,{id:(n=r.sent()).id,name:n.name,version:n.version,bucketId:n.bucket_id,size:n.size,contentType:n.content_type,cacheControl:n.cache_control,etag:n.etag,metadata:n.metadata,lastModified:n.last_modified,createdAt:n.created_at}]}})})},this.shouldThrowOnError)]})})},t.prototype.exists=function(t){return T(this,void 0,Promise,function(){var e,n,r;return j(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.cleanPath(t),[4,this.send({method:"GET",path:"/object/info/".concat(this.bucketId,"/").concat(this.encodePath(e))})];case 1:return o.sent(),[2,{data:!0,error:null}];case 2:if(n=o.sent(),void 0!==(r=null==n?void 0:n.status)&&[400,404].includes(Number(r)))return[2,{data:!1,error:null}];if(this.shouldThrowOnError)throw n;return[2,{data:null,error:n instanceof a?n:new a((null==n?void 0:n.message)||String(n))}];case 3:return[2]}})})},t.prototype.createSignedUrl=function(t,e,n){return T(this,void 0,Promise,function(){var r=this;return j(this,function(o){return[2,m(function(){return T(r,void 0,void 0,function(){var r,o,i;return j(this,function(a){switch(a.label){case 0:return r=this.cleanPath(t),[4,this.send({method:"POST",path:"/object/sign/".concat(this.bucketId,"/").concat(this.encodePath(r)),json:{expiresIn:e}})];case 1:return o=a.sent(),i=o.fullSignedURL||this.http.toFullUrl(o.signedURL||""),[2,{fullSignedURL:this.appendUrlOptions(i,n)}]}})})},this.shouldThrowOnError)]})})},t.prototype.createSignedUrls=function(t,e,n){return T(this,void 0,Promise,function(){var r=this;return j(this,function(o){return[2,m(function(){return T(r,void 0,void 0,function(){var r,o,i,a,s=this;return j(this,function(c){switch(c.label){case 0:r=t.map(function(t){return s.cleanPath(t)}),o=[],i=0,c.label=1;case 1:return i<r.length?(a=r.slice(i,i+500),[4,this.send({method:"POST",path:"/object/sign/".concat(this.bucketId),json:{expiresIn:e,paths:a}})]):[3,4];case 2:c.sent().forEach(function(t){var e,r=t.fullSignedURL||(t.signedURL?s.http.toFullUrl(t.signedURL):null);o.push({path:t.path,fullSignedURL:r?s.appendUrlOptions(r,n):null,error:null!==(e=t.error)&&void 0!==e?e:null})}),c.label=3;case 3:return i+=500,[3,1];case 4:return[2,o]}})})},this.shouldThrowOnError)]})})},t.prototype.createSignedUploadUrl=function(t,e){return T(this,void 0,Promise,function(){var n=this;return j(this,function(r){return[2,m(function(){return T(n,void 0,void 0,function(){var n,r,o;return j(this,function(i){switch(i.label){case 0:return n=this.cleanPath(t),r={},(null==e?void 0:e.upsert)&&(r["x-upsert"]="true"),[4,this.send({method:"POST",path:"/object/upload/sign/".concat(this.bucketId,"/").concat(this.encodePath(n)),headers:r})];case 1:return[2,{fullSignedURL:(o=i.sent()).fullURL||this.http.toFullUrl(o.url||""),path:n,token:o.token}]}})})},this.shouldThrowOnError)]})})},t.prototype.uploadToSignedUrl=function(t,e,n,r){return T(this,void 0,Promise,function(){var o=this;return j(this,function(i){return[2,m(function(){return T(o,void 0,void 0,function(){var o,i,a,s,c;return j(this,function(u){switch(u.label){case 0:return o=this.cleanPath(t),i=this.buildUploadBody(n,r),a=i.body,s=i.headers,[4,this.send({method:"PUT",path:"/object/upload/sign/".concat(this.bucketId,"/").concat(this.encodePath(o)),query:{token:e},rawBody:a,headers:s,withCredentials:!1})];case 1:return c=u.sent(),[2,{path:o,fullPath:c.Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.getPublicUrl=function(t,e){var n=this.cleanPath(t),r=this.http.buildUrl("/object/public/".concat(this.bucketId,"/").concat(this.encodePath(n)));return{data:{publicUrl:this.appendUrlOptions(r,e)}}},t.prototype.send=function(t){return this.http.send(_(_({},t),{headers:_(_({},this.headers),t.headers||{})}))},t.prototype.uploadOrUpdate=function(t,e,n,r){return T(this,void 0,Promise,function(){var o=this;return j(this,function(i){return[2,m(function(){return T(o,void 0,void 0,function(){var o,i,a,s,c;return j(this,function(u){switch(u.label){case 0:return o=this.cleanPath(e),i=this.buildUploadBody(n,r),a=i.body,s=i.headers,"POST"===t&&(s["x-upsert"]=String(Boolean(null==r?void 0:r.upsert))),[4,this.send({method:t,path:"/object/".concat(this.bucketId,"/").concat(this.encodePath(o)),rawBody:a,headers:s})];case 1:return[2,{id:(c=u.sent()).Id,path:o,fullPath:c.Key}]}})})},this.shouldThrowOnError)]})})},t.prototype.cleanPath=function(t){var e=t.replace(/^\/+|\/+$/g,"").replace(/\/+/g,"/");if(e.split("/").some(function(t){return".."===t}))throw new a('invalid path: ".." segment is not allowed');return e},t.prototype.encodePath=function(t){return h(t)},t.prototype.buildUploadBody=function(t,e){var n,r,o,i,a,s=_({},(null==e?void 0:e.headers)||{}),c=t,u="undefined"!=typeof FormData&&t instanceof FormData;if("undefined"!=typeof Blob&&t instanceof Blob||u){var l=void 0,d={};if(u){var h=this.extractFromFormData(t);l=h.file,d=h.fields}else l=t;var f=null!==(r=null!==(n=null==e?void 0:e.cacheControl)&&void 0!==n?n:d.cacheControl)&&void 0!==r?r:F,p=null!==(o=null==e?void 0:e.contentType)&&void 0!==o?o:d.contentType,y=void 0!==(null==e?void 0:e.metadata)?JSON.stringify(e.metadata):d.metadata,v=new FormData;void 0!==f&&v.append("cacheControl",String(f)),void 0!==p&&v.append("contentType",p),void 0!==y&&v.append("metadata",y),v.append("",l),c=v}else c=t,f=null!==(i=null==e?void 0:e.cacheControl)&&void 0!==i?i:F,p=null!==(a=null==e?void 0:e.contentType)&&void 0!==a?a:"text/plain;charset=UTF-8",s["cache-control"]="max-age=".concat(f),p&&(s["content-type"]=p),(null==e?void 0:e.metadata)&&(s["x-metadata"]=this.toBase64(JSON.stringify(e.metadata)));return{body:c,headers:s}},t.prototype.extractFromFormData=function(t){var e,n={},r=0,o=[];if(t.forEach(function(t,i){if("undefined"!=typeof Blob&&t instanceof Blob)return e=t,void(r+=1);"cacheControl"!==i&&"contentType"!==i&&"metadata"!==i?o.push(i):n[i]=String(t)}),o.length>0&&console.warn("Ignored unsupported FormData field(s): [".concat(o.join(", "),"]. Only file, cacheControl, contentType and metadata are supported")),0===r||!e)throw new a("FormData must contain a file");if(r>1)throw new a("FormData must contain exactly one file");return{file:e,fields:n}},t.prototype.buildCopyMoveHeaders=function(t){var e={};return(null==t?void 0:t.upsert)&&(e["x-upsert"]="true"),!1===(null==t?void 0:t.copyMetadata)&&(null==t?void 0:t.metadata)&&(e["x-metadata"]=this.toBase64(JSON.stringify(t.metadata))),e},t.prototype.appendUrlOptions=function(t,e){var n=[];if(void 0!==(null==e?void 0:e.download)){var r=!0===e.download?"":String(e.download);n.push("download=".concat(encodeURIComponent(r)))}if(void 0!==(null==e?void 0:e.cacheNonce)&&n.push("cacheNonce=".concat(encodeURIComponent(String(e.cacheNonce)))),0===n.length)return t;var o=t.includes("?")?"&":"?";return"".concat(t).concat(o).concat(n.join("&"))},t.prototype.toBase64=function(t){return d(t)},t}(),x=/[\x00-\x20\x7f/\\?#%]/;function U(t,e){if("string"!=typeof t||0===t.length)throw new a("[storage.".concat(e,"] bucketId is required"));if(t.length>256)throw new a("[storage.".concat(e,"] invalid bucketId: length must be 1-").concat(256));var n=x.exec(t);if(n){var r="[storage.".concat(e,'] invalid bucketId "').concat(t,'": ')+"contains forbidden character ".concat(JSON.stringify(n[0]),"; ")+'must not contain whitespace, control chars, "/", "\\", "?", "#" or "%"';throw new a(r)}}var R=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},C=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},A=function(){function t(t,e){void 0===e&&(e=!1),this.http=new b(t),this.shouldThrowOnError=e}return t.prototype.throwOnError=function(){return this.shouldThrowOnError=!0,this},t.prototype.listBuckets=function(t){return R(this,void 0,Promise,function(){var e=this;return C(this,function(n){return[2,m(function(){var n={};return void 0!==(null==t?void 0:t.limit)&&(n.limit=t.limit),void 0!==(null==t?void 0:t.offset)&&(n.offset=t.offset),(null==t?void 0:t.sortColumn)&&(n.sortColumn=t.sortColumn),(null==t?void 0:t.sortOrder)&&(n.sortOrder=t.sortOrder),(null==t?void 0:t.search)&&(n.search=t.search),e.http.send({method:"GET",path:"/bucket/",query:n})},this.shouldThrowOnError)]})})},t.prototype.getBucket=function(t){return R(this,void 0,Promise,function(){var e=this;return C(this,function(n){return[2,m(function(){return U(t,"getBucket"),e.http.send({method:"GET",path:"/bucket/".concat(t)})},this.shouldThrowOnError)]})})},t.prototype.createBucket=function(t,e){return R(this,void 0,Promise,function(){var n=this;return C(this,function(r){return[2,m(function(){var r;return U(t,"createBucket"),n.http.send({method:"POST",path:"/bucket/",json:{id:t,name:t,public:null!==(r=null==e?void 0:e.public)&&void 0!==r&&r,type:null==e?void 0:e.type,file_size_limit:null==e?void 0:e.fileSizeLimit,allowed_mime_types:null==e?void 0:e.allowedMimeTypes}})},this.shouldThrowOnError)]})})},t.prototype.updateBucket=function(t,e){return R(this,void 0,Promise,function(){var n=this;return C(this,function(r){return[2,m(function(){return U(t,"updateBucket"),n.http.send({method:"PUT",path:"/bucket/".concat(t),json:{public:e.public,file_size_limit:e.fileSizeLimit,allowed_mime_types:e.allowedMimeTypes}})},this.shouldThrowOnError)]})})},t.prototype.deleteBucket=function(t){return R(this,void 0,Promise,function(){var e=this;return C(this,function(n){return[2,m(function(){return U(t,"deleteBucket"),e.http.send({method:"DELETE",path:"/bucket/".concat(t)})},this.shouldThrowOnError)]})})},t}();function k(){return"@cloudbase/js-sdk"}var N={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"};const D=(q={AbstractSDKRequest:()=>t.AbstractSDKRequest,AbstractStorage:()=>t.AbstractStorage},B={},o.d(B,q),B);var q,B;function M(t){return"string"==typeof t}function G(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var z,W=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),J=function(){return J=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},J.apply(this,arguments)},V=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},H=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}W(e,t),e.prototype.get=function(t){return this.request(J(J({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(J(J({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(J(J({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,i=t.headers,a=void 0===i?{}:i,s={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",c=new FormData;return"post"===s?(Object.keys(e).forEach(function(t){c.append(t,e[t])}),c.append("key",r),c.append("file",n),this.request(J(J({},t),{data:c,method:s}),this.restrictedMethods.includes("upload"))):this.request(J(J({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return V(this,void 0,Promise,function(){var e,n,r,o;return H(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(J(J({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return V(this,void 0,Promise,function(){var n,r,o,i,a,s,c,u,l,d,h,f,p,y=this;return H(this,function(v){switch(v.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,a=t.stream,s=void 0!==a&&a,c=t.signal,u=t.timeout,l=t.shouldThrowOnError,d=void 0===l||l,h=null!=u?u:this.timeout,c&&(c.aborted&&n.abort(),c.addEventListener("abort",function(){return n.abort()})),f=null,i&&h&&(f=setTimeout(function(){console.warn(y.timeoutMsg),n.abort(new Error(y.timeoutMsg))},h)),[4,fetch(r,J(J({},t),{signal:n.signal})).then(function(t){return V(y,void 0,void 0,function(){var e,n,r;return H(this,function(o){switch(o.label){case 0:return clearTimeout(f),d?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(f),Promise.reject(t)})];case 1:return p=v.sent(),[2,{data:s?p.body:(null===(e=p.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?p.json():p.text(),statusCode:p.status,header:p.headers,response:p}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,a=t.headers,s=void 0===a?{}:a,c=t.data,u=t.responseType,l=t.withCredentials,d=t.body,h=t.onUploadProgress,f=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",i,"get"===r?c:{}),p=new XMLHttpRequest;p.open(r,f),u&&(p.responseType=u);var y,v,m,b=t.signal;b&&(b.aborted?p.abort():b.addEventListener("abort",function(){return p.abort()},{once:!0})),Object.keys(s).forEach(function(t){p.setRequestHeader(t,s[t])}),h&&p.upload.addEventListener("progress",h),p.onreadystatechange=function(){var t={};if(4===p.readyState){var e=p.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=p.status;try{t.data="blob"===u?p.response:JSON.parse(p.responseText)}catch(e){t.data="blob"===u?p.response:p.responseText}clearTimeout(y),o(t)}},e&&n.timeout&&(y=setTimeout(function(){console.warn(n.timeoutMsg),p.abort()},n.timeout)),m=c,v="[object FormData]"===Object.prototype.toString.call(m)?c:"application/x-www-form-urlencoded"===s["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(c):d||(c?JSON.stringify(c):void 0),l&&(p.withCredentials=!0),p.send(v)})}}(D.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(z||(z={}));var K=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Y=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},Q=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},X=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return K(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(D.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(G(N.INVALID_PARAMS,"localStorage is not supported on current platform"),new X(e.root));case"none":return new X(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:N.OPERATION_FAIL,msg:"[".concat("@cloudbase/js-sdk","][").concat(N.OPERATION_FAIL,"]setStore failed"),info:t}))}}else G(N.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return Y(this,void 0,void 0,function(){var r;return Q(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}G(N.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return Y(this,void 0,void 0,function(){var r;return Q(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):G(N.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return Y(this,void 0,void 0,function(){return Q(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})}}();var $=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Z=function(t,e){this.data=e||null,this.name=t},tt=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return $(e,t),e}(Z),et=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof tt)return console.error(t.error),this;var n=M(t)?new Z(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new et,new et,"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const nt=(t=>{var e={};return o.d(e,t),e})({default:()=>e.default});nt.default;var rt,ot=o(388),it=function(){return it=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},it.apply(this,arguments)},at=function(t,e,n,r){var o,i=arguments.length,a=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(o=t[s])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a},st=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},ct=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,s)}c((r=r.apply(t,e||[])).next())})},ut=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};!function(t){t.put="put",t.post="post"}(rt||(rt={}));var lt=k,dt=N,ht="https://support.qq.com/products/148793",ft=function(t){return"[object Array]"===Object.prototype.toString.call(t)},pt=M,yt=function(t){return"[object Object]"===Object.prototype.toString.call(t)},vt=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},mt=function(t){return t.mode,t.customInfo,t.title,t.messages,function(t,e,n){}},bt="storage",gt=function(t,e,n){return ct(void 0,void 0,void 0,function(){var r,o,i;return ut(this,function(a){switch(a.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-upload-info",data:[it({objectId:e.path},e.signedHeader?{signedHeader:e.signedHeader}:{})]},n)];case 1:return r=a.sent(),o=(null===(i=r.data)||void 0===i?void 0:i[0])||{},[2,it(it({},r),{data:it(it({},o.code?it({},o):{}),{authorization:o.authorization,token:o.token,url:o.uploadUrl,fileId:o.cloudObjectId,cosFileId:o.cloudObjectMeta,download_url:o.downloadUrl})})]}})})},wt=function(t,e,n){return ct(void 0,void 0,void 0,function(){var r,o;return ut(this,function(i){switch(i.label){case 0:return[4,t.gateWay({path:"storages",name:"get-objects-download-info",data:e.convertedFileList.map(function(t){return{cloudObjectId:t.fileid}})},n)];case 1:return r=i.sent(),[2,it(it({},r),{data:{download_list:null===(o=r.data)||void 0===o?void 0:o.map(function(t){return{code:t.code||"SUCCESS",message:t.message,fileid:t.cloudObjectId,download_url:t.downloadUrl,fileID:t.cloudObjectId,tempFileURL:t.downloadUrl}})}})]}})})},Ot=function(t,e,n){return ct(void 0,void 0,void 0,function(){var r,o;return ut(this,function(i){switch(i.label){case 0:return[4,t.gateWay({path:"storages",name:"delete-objects",data:e.fileList.map(function(t){return{cloudObjectId:t}})},n)];case 1:return r=i.sent(),[2,it(it({},r),{data:{delete_list:null===(o=r.data)||void 0===o?void 0:o.map(function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}})}})]}})})},It=function(t,e,n){return ct(void 0,void 0,void 0,function(){var r,o;return ut(this,function(i){switch(i.label){case 0:return[4,t.gateWay({path:"storages",name:"copy-objects",data:e.convertedFileList.map(function(t){return{srcPath:t.src_path,dstPath:t.dst_path,overwrite:t.overwrite,removeOriginal:t.remove_original}})},n)];case 1:return r=i.sent(),[2,it(it({},r),{data:{copy_list:null===(o=r.data)||void 0===o?void 0:o.map(function(t){return{code:t.code||"SUCCESS",fileID:t.cloudObjectId,message:t.message}})}})]}})})},Pt={txt:"text/plain",json:"application/json",html:"text/html",htm:"text/html",css:"text/css",js:"application/javascript",csv:"text/csv",xml:"application/xml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",mp4:"video/mp4",webm:"video/webm",mp3:"audio/mpeg",wav:"audio/wav"};function St(t,e){if("undefined"!=typeof Blob&&t instanceof Blob&&t.type)return t.type;var n=/\.([a-zA-Z0-9]+)$/.exec(e||""),r=n?n[1].toLowerCase():"";return Pt[r]||"application/octet-stream"}function Et(t,e){var n=e.toLowerCase();return Object.keys(t).some(function(t){return t.toLowerCase()===n})}function _t(t){return Object.keys(t).reduce(function(e,n){var r;return it(it({},e),((r={})[n]=[t[n]],r))},{})}var Tt=function(){function t(t){this.context=t}var e,n,r,o,i,a,s,c,u,d,h,f,p,y,v,m;return Object.defineProperty(t.prototype,"config",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.config},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"request",{get:function(){var t;return null===(t=this.context)||void 0===t?void 0:t.request},enumerable:!1,configurable:!0}),t.prototype.isGateWay=function(){return"GATEWAY"===(this.config.endPointMode||"CLOUD_API")},t.prototype.uploadFile=function(t,e){return ct(this,void 0,Promise,function(){var n,r,o,i,a,s,c,u,d,h,f,p,y,v,m,b,g,w,O,I,P,S,E,_,T,j,F,L,x,U,R;return ut(this,function(C){switch(C.label){case 0:if(n=t.cloudPath,r=t.filePath,o=t.onUploadProgress,x=t.method,i=void 0===x?"put":x,U=t.headers,a=void 0===U?{}:U,s=t.fileContent,!pt(n)||!r&&!s)throw new Error(JSON.stringify({code:dt.INVALID_PARAMS,msg:"[".concat(bt,".uploadFile] invalid params")}));return c={put:rt.put,post:rt.post}[i.toLocaleLowerCase()]||rt.put,u=this.isGateWay(),d=it({},a),h=Object.keys(a).reduce(function(t,e){return"content-length"!==e.toLowerCase()&&(t[e]=a[e]),t},{}),c===rt.put&&u&&(Et(d,"content-length")||"number"==typeof(f=function(t,e){var n=null!=t?t:e;if(null!==n){if("undefined"!=typeof Blob&&n instanceof Blob)return n.size;if("undefined"!=typeof ArrayBuffer){if(n instanceof ArrayBuffer)return n.byteLength;if("function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(n))return n.byteLength}if("string"==typeof n){if("undefined"!=typeof Blob)return new Blob([n]).size;var r=(o=n,null===(i=l())||void 0===i?void 0:i.byteLength(o));return"number"==typeof r?r:n.length}var o,i;return"object"==typeof n&&"number"==typeof n.size?n.size:void 0}}(r,s))&&(d["content-length"]=String(f)),Et(d,"content-type")||(d["content-type"]=St(r,n)),Et(h,"content-type")||(h["content-type"]=St(r,n))),[4,this.getUploadMetadata({cloudPath:n,method:c,headers:c!==rt.put||u?void 0:h,signedHeader:c===rt.put&&u?_t(d):void 0,customReqOpts:t.customReqOpts})];case 1:return p=C.sent(),y=p.data,v=p.requestId,(null==(m=y)?void 0:m.code)||!(null==m?void 0:m.url)?(b=(null==m?void 0:m.code)||dt.OPERATION_FAIL,g=(null==m?void 0:m.message)||"get upload info failed",[2,vt(e,new Error("[".concat(lt(),"][").concat(b,"][").concat(bt,"]:").concat(g)))]):(w=y.url,O=y.authorization,I=y.token,P=y.fileId,S=y.cosFileId,E=y.download_url,T=it(it({},_={url:w,file:r,name:n,onUploadProgress:o,fileContent:s,fileId:P,requestId:v}),{method:rt.put,headers:it(it({},h),{authorization:O,"x-cos-meta-fileid":S,"x-cos-security-token":I})}),j=it(it({},_),{method:rt.post,data:{key:n,signature:O,"x-cos-meta-fileid":S,success_action_status:"201","x-cos-security-token":I}}),(R={})[rt.put]={params:T,isSuccess:function(t){return t>=200&&t<300}},R[rt.post]={params:j,isSuccess:function(t){return 201===t}},F=R,[4,this.request.upload(F[c].params)]);case 2:return L=C.sent(),F[c].isSuccess(L.statusCode)?[2,vt(e,null,{fileID:P,download_url:E,requestId:v})]:[2,vt(e,new Error("[".concat(lt(),"][").concat(dt.OPERATION_FAIL,"][").concat(bt,"]:").concat(L.data)))]}})})},t.prototype.getUploadMetadata=function(t,e){return ct(this,void 0,Promise,function(){var n,r,o,i,a,s,c,u,l,d;return ut(this,function(h){switch(h.label){case 0:if(n=t.cloudPath,r=t.method,o=t.headers,i=t.signedHeader,!pt(n))throw new Error(JSON.stringify({code:dt.INVALID_PARAMS,msg:"[".concat(bt,".getUploadMetadata] invalid cloudPath")}));a=this.request,s="storage.getUploadMetadata",h.label=1;case 1:return h.trys.push([1,6,,7]),c=void 0,u={path:n},l=this.isGateWay(),r&&(u.method=r),r===rt.put&&(l&&i?u.signedHeader=i:!l&&o&&(u.headers=o)),l?[4,gt(a,u,t.customReqOpts)]:[3,3];case 2:return c=h.sent(),[3,5];case 3:return[4,a.send(s,u,t.customReqOpts)];case 4:c=h.sent(),h.label=5;case 5:return[2,vt(e,null,c)];case 6:return d=h.sent(),[2,vt(e,d)];case 7:return[2]}})})},t.prototype.deleteFile=function(t,e){return ct(this,void 0,Promise,function(){var n,r,o,i,a,s,c,u;return ut(this,function(l){switch(l.label){case 0:if(!(n=t.fileList)||!ft(n)||0===n.length)throw new Error(JSON.stringify({code:dt.INVALID_PARAMS,msg:"[".concat(bt,".deleteFile] fileList must not be empty")}));for(r=0,o=n;r<o.length;r++)if(!(i=o[r])||!pt(i))throw new Error(JSON.stringify({code:dt.INVALID_PARAMS,msg:"[".concat(bt,".deleteFile] fileID must be string")}));return a="storage.batchDeleteFile",s=this.request,c={},this.isGateWay()?[4,Ot(s,{fileList:n},t.customReqOpts)]:[3,2];c