You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
63 KiB
1 lines
63 KiB
var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function n(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var r=n((function(e,t){var n;e.exports=(n=n||function(e,t){var n=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),r={},o=r.lib={},s=o.Base={extend:function(e){var t=n(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=o.WordArray=s.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,o=e.sigBytes;if(this.clamp(),r%4)for(var s=0;s<o;s++){var i=n[s>>>2]>>>24-s%4*8&255;t[r+s>>>2]|=i<<24-(r+s)%4*8}else for(s=0;s<o;s+=4)t[r+s>>>2]=n[s>>>2];return this.sigBytes+=o,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=s.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,r=[],o=function(t){t=t;var n=987654321,r=4294967295;return function(){var o=((n=36969*(65535&n)+(n>>16)&r)<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r;return o/=4294967296,(o+=.5)*(e.random()>.5?1:-1)}},s=0;s<t;s+=4){var a=o(4294967296*(n||e.random()));n=987654071*a(),r.push(4294967296*a()|0)}return new i.init(r,t)}}),a=r.enc={},c=a.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o<n;o++){var s=t[o>>>2]>>>24-o%4*8&255;r.push((s>>>4).toString(16)),r.push((15&s).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new i.init(n,t/2)}},u=a.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o<n;o++){var s=t[o>>>2]>>>24-o%4*8&255;r.push(String.fromCharCode(s))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new i.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=o.BufferedBlockAlgorithm=s.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,s=this.blockSize,a=o/(4*s),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*s,u=e.min(4*c,o);if(c){for(var l=0;l<c;l+=s)this._doProcessBlock(r,l);var h=r.splice(0,c);n.sigBytes-=u}return new i.init(h,u)},clone:function(){var e=s.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),f=(o.Hasher=h.extend({cfg:s.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){h.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new f.HMAC.init(e,n).finalize(t)}}}),r.algo={});return r}(Math),n)})),o=(n((function(e,t){var n;e.exports=(n=r,function(e){var t=n,r=t.lib,o=r.WordArray,s=r.Hasher,i=t.algo,a=[];!function(){for(var t=0;t<64;t++)a[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=i.MD5=s.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var n=0;n<16;n++){var r=t+n,o=e[r];e[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}var s=this._hash.words,i=e[t+0],c=e[t+1],p=e[t+2],d=e[t+3],y=e[t+4],g=e[t+5],v=e[t+6],_=e[t+7],m=e[t+8],b=e[t+9],w=e[t+10],T=e[t+11],S=e[t+12],E=e[t+13],k=e[t+14],O=e[t+15],A=s[0],P=s[1],I=s[2],N=s[3];A=u(A,P,I,N,i,7,a[0]),N=u(N,A,P,I,c,12,a[1]),I=u(I,N,A,P,p,17,a[2]),P=u(P,I,N,A,d,22,a[3]),A=u(A,P,I,N,y,7,a[4]),N=u(N,A,P,I,g,12,a[5]),I=u(I,N,A,P,v,17,a[6]),P=u(P,I,N,A,_,22,a[7]),A=u(A,P,I,N,m,7,a[8]),N=u(N,A,P,I,b,12,a[9]),I=u(I,N,A,P,w,17,a[10]),P=u(P,I,N,A,T,22,a[11]),A=u(A,P,I,N,S,7,a[12]),N=u(N,A,P,I,E,12,a[13]),I=u(I,N,A,P,k,17,a[14]),A=l(A,P=u(P,I,N,A,O,22,a[15]),I,N,c,5,a[16]),N=l(N,A,P,I,v,9,a[17]),I=l(I,N,A,P,T,14,a[18]),P=l(P,I,N,A,i,20,a[19]),A=l(A,P,I,N,g,5,a[20]),N=l(N,A,P,I,w,9,a[21]),I=l(I,N,A,P,O,14,a[22]),P=l(P,I,N,A,y,20,a[23]),A=l(A,P,I,N,b,5,a[24]),N=l(N,A,P,I,k,9,a[25]),I=l(I,N,A,P,d,14,a[26]),P=l(P,I,N,A,m,20,a[27]),A=l(A,P,I,N,E,5,a[28]),N=l(N,A,P,I,p,9,a[29]),I=l(I,N,A,P,_,14,a[30]),A=h(A,P=l(P,I,N,A,S,20,a[31]),I,N,g,4,a[32]),N=h(N,A,P,I,m,11,a[33]),I=h(I,N,A,P,T,16,a[34]),P=h(P,I,N,A,k,23,a[35]),A=h(A,P,I,N,c,4,a[36]),N=h(N,A,P,I,y,11,a[37]),I=h(I,N,A,P,_,16,a[38]),P=h(P,I,N,A,w,23,a[39]),A=h(A,P,I,N,E,4,a[40]),N=h(N,A,P,I,i,11,a[41]),I=h(I,N,A,P,d,16,a[42]),P=h(P,I,N,A,v,23,a[43]),A=h(A,P,I,N,b,4,a[44]),N=h(N,A,P,I,S,11,a[45]),I=h(I,N,A,P,O,16,a[46]),A=f(A,P=h(P,I,N,A,p,23,a[47]),I,N,i,6,a[48]),N=f(N,A,P,I,_,10,a[49]),I=f(I,N,A,P,k,15,a[50]),P=f(P,I,N,A,g,21,a[51]),A=f(A,P,I,N,S,6,a[52]),N=f(N,A,P,I,d,10,a[53]),I=f(I,N,A,P,w,15,a[54]),P=f(P,I,N,A,c,21,a[55]),A=f(A,P,I,N,m,6,a[56]),N=f(N,A,P,I,O,10,a[57]),I=f(I,N,A,P,v,15,a[58]),P=f(P,I,N,A,E,21,a[59]),A=f(A,P,I,N,y,6,a[60]),N=f(N,A,P,I,T,10,a[61]),I=f(I,N,A,P,p,15,a[62]),P=f(P,I,N,A,b,21,a[63]),s[0]=s[0]+A|0,s[1]=s[1]+P|0,s[2]=s[2]+I|0,s[3]=s[3]+N|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var s=e.floor(r/4294967296),i=r;n[15+(o+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),n[14+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),t.sigBytes=4*(n.length+1),this._process();for(var a=this._hash,c=a.words,u=0;u<4;u++){var l=c[u];c[u]=16711935&(l<<8|l>>>24)|4278255360&(l<<24|l>>>8)}return a},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,n,r,o,s,i){var a=e+(t&n|~t&r)+o+i;return(a<<s|a>>>32-s)+t}function l(e,t,n,r,o,s,i){var a=e+(t&r|n&~r)+o+i;return(a<<s|a>>>32-s)+t}function h(e,t,n,r,o,s,i){var a=e+(t^n^r)+o+i;return(a<<s|a>>>32-s)+t}function f(e,t,n,r,o,s,i){var a=e+(n^(t|~r))+o+i;return(a<<s|a>>>32-s)+t}t.MD5=s._createHelper(c),t.HmacMD5=s._createHmacHelper(c)}(Math),n.MD5)})),n((function(e,t){var n,o,s;e.exports=(o=(n=r).lib.Base,s=n.enc.Utf8,void(n.algo.HMAC=o.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),a=o.words,c=i.words,u=0;u<n;u++)a[u]^=1549556828,c[u]^=909522486;o.sigBytes=i.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(n))}})))})),n((function(e,t){e.exports=r.HmacMD5})));function s(e){return function(t){if(!((t=t||{}).success||t.fail||t.complete))return e.call(this,t);e.call(this,t).then(e=>{t.success&&t.success(e),t.complete&&t.complete(e)}).catch(e=>{t.fail&&t.fail(e),t.complete&&t.complete(e)})}}class i extends Error{constructor(e){super(e.message),this.errMsg=e.message||"",Object.defineProperties(this,{code:{get:()=>e.code},requestId:{get:()=>e.requestId},message:{get(){return this.errMsg},set(e){this.errMsg=e}}})}}let a;try{a=require("uni-stat-config").default||require("uni-stat-config")}catch(e){a={appid:""}}let c,u;function l(e=8){let t="";for(;t.length<e;)t+=Math.random().toString(32).substring(2);return t.substring(0,e)}function h(){if("n"===f()){try{c=plus.runtime.getDCloudId()}catch(e){c=""}return c}return c||(c=l(32),uni.setStorage({key:"__DC_CLOUD_UUID",data:c})),c}function f(){return{"app-plus":"n",h5:"h5","mp-weixin":"wx","mp-alipay":"ali","mp-baidu":"bd","mp-toutiao":"tt","mp-qq":"qq","quickapp-native":"qn"}[process.env.VUE_APP_PLATFORM]}var p={sign:function(e,t){let n="";return Object.keys(e).sort().forEach((function(t){e[t]&&(n=n+"&"+t+"="+e[t])})),n=n.slice(1),o(n,t).toString()},wrappedRequest:function(e,t){return new Promise((n,r)=>{t(Object.assign(e,{complete(e){e||(e={}),"h5"===process.env.VUE_APP_PLATFORM&&"development"===process.env.NODE_ENV&&e.errMsg&&0===e.errMsg.indexOf("request:fail")&&console.warn("发布H5,需要在uniCloud后台操作,绑定安全域名,否则会因为跨域问题而无法访问。教程参考:https://uniapp.dcloud.io/uniCloud/quickstart?id=useinh5");const t=e.data&&e.data.header&&e.data.header["x-serverless-request-id"]||e.header&&e.header["request-id"];if(!e.statusCode||e.statusCode>=400)return r(new i({code:"SYS_ERR",message:e.errMsg||"request:fail",requestId:t}));const o=e.data;if(o.error)return r(new i({code:o.error.code,message:o.error.message,requestId:t}));o.result=o.data,o.requestId=t,delete o.data,n(o)}}))})}};const d={request:e=>uni.request(e),uploadFile:e=>uni.uploadFile(e),setStorageSync:(e,t)=>uni.setStorageSync(e,t),getStorageSync:e=>uni.getStorageSync(e),removeStorageSync:e=>uni.removeStorageSync(e),clearStorageSync:()=>uni.clearStorageSync()};class y{constructor(e){["spaceId","clientSecret"].forEach(t=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("缺少参数"+t)}),this.config=Object.assign({},{endpoint:"https://api.bspapp.com"},e),this.config.provider="aliyun",this.config.requestUrl=this.config.endpoint+"/client",this.config.envType=this.config.envType||"public",this.config.accessTokenKey="access_token_"+this.config.spaceId,this.adapter=d}get hasAccessToken(){return!!this.accessToken}setAccessToken(e){this.accessToken=e}requestWrapped(e){return p.wrappedRequest(e,this.adapter.request)}requestAuth(e){return this.requestWrapped(e)}request(e,t){return this.hasAccessToken?t?this.requestWrapped(e):this.requestWrapped(e).catch(t=>new Promise((e,n)=>{!t||"GATEWAY_INVALID_TOKEN"!==t.code&&"InvalidParameter.InvalidToken"!==t.code?n(t):e()}).then(()=>this.getAccessToken()).then(()=>{const t=this.rebuildRequest(e);return this.request(t,!0)})):this.getAccessToken().then(()=>{const t=this.rebuildRequest(e);return this.request(t,!0)})}rebuildRequest(e){const t=Object.assign({},e);return t.data.token=this.accessToken,t.header["x-basement-token"]=this.accessToken,t.header["x-serverless-sign"]=p.sign(t.data,this.config.clientSecret),t}setupRequest(e,t){const n=Object.assign({},e,{spaceId:this.config.spaceId,timestamp:Date.now()}),r={"Content-Type":"application/json"};return"auth"!==t&&(n.token=this.accessToken,r["x-basement-token"]=this.accessToken),r["x-serverless-sign"]=p.sign(n,this.config.clientSecret),{url:this.config.requestUrl,method:"POST",data:n,dataType:"json",header:r}}getAccessToken(){return this.requestAuth(this.setupRequest({method:"serverless.auth.user.anonymousAuthorize",params:"{}"},"auth")).then(e=>new Promise((t,n)=>{e.result&&e.result.accessToken?(this.setAccessToken(e.result.accessToken),t(this.accessToken)):n(new i({code:"AUTH_FAILED",message:"获取accessToken失败"}))}))}authorize(){this.getAccessToken()}callFunction(e){const t={method:"serverless.function.runtime.invoke",params:JSON.stringify({functionTarget:e.name,functionArgs:e.data||{}})};return this.request(this.setupRequest(t))}getOSSUploadOptionsFromPath(e){const t={method:"serverless.file.resource.generateProximalSign",params:JSON.stringify(e)};return this.request(this.setupRequest(t))}uploadFileToOSS({url:e,formData:t,name:n,filePath:r,fileType:o,onUploadProgress:s}){return new Promise((a,c)=>{const u=this.adapter.uploadFile({url:e,formData:t,name:n,filePath:r,fileType:o,header:{"X-OSS-server-side-encrpytion":"AES256"},success(e){e&&e.statusCode<400?a(e):c(new i({code:"UPLOAD_FAILED",message:"文件上传失败"}))},fail(e){c(e)}});"function"==typeof s&&u&&"function"==typeof u.onProgressUpdate&&u.onProgressUpdate(e=>{s({loaded:e.totalBytesSent,total:e.totalBytesExpectedToSend})})})}reportOSSUpload(e){const t={method:"serverless.file.resource.report",params:JSON.stringify(e)};return this.request(this.setupRequest(t))}uploadFile({filePath:e,cloudPath:t,fileType:n="image",onUploadProgress:r,config:o}){if(!t)throw new i({code:"CLOUDPATH_REQUIRED",message:"cloudPath不可为空"});const s=o&&o.envType||this.config.envType;let a,c;return this.getOSSUploadOptionsFromPath({env:s,filename:t}).then(t=>{const o=t.result;a=o.id,c="https://"+o.cdnDomain+"/"+o.ossPath;const s={url:"https://"+o.host,formData:{"Cache-Control":"max-age=2592000","Content-Disposition":"attachment",OSSAccessKeyId:o.accessKeyId,Signature:o.signature,host:o.host,id:a,key:o.ossPath,policy:o.policy,success_action_status:200},fileName:"file",name:"file",filePath:e,fileType:n};return this.uploadFileToOSS(Object.assign({},s,{onUploadProgress:r}))}).then(()=>this.reportOSSUpload({id:a})).then(t=>new Promise((n,r)=>{t.success?n({success:!0,filePath:e,fileID:c}):r(new i({code:"UPLOAD_FAILED",message:"文件上传失败"}))}))}deleteFile({fileList:e}){const t={method:"serverless.file.resource.delete",params:JSON.stringify({id:e[0]})};return this.request(this.setupRequest(t))}}const g={init(e){const t=new y(e);["deleteFile"].forEach(e=>{t[e]=s(t[e]).bind(t)});const n={signInAnonymously:function(){return t.authorize()},getLoginState:function(){return Promise.resolve(!1)}};return t.auth=function(){return n},t}};var v,_,m=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.getQuery=function(e,t){if("undefined"==typeof window)return!1;var n=t||window.location.search,r=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},t.getHash=function(e){var t=window.location.hash.match(new RegExp("[#?&/]"+e+"=([^&#]*)"));return t?t[1]:""},t.removeParam=function(e,t){var n=t.split("?")[0],r=[],o=-1!==t.indexOf("?")?t.split("?")[1]:"";if(""!==o){for(var s=(r=o.split("&")).length-1;s>=0;s-=1)r[s].split("=")[0]===e&&r.splice(s,1);n=n+"?"+r.join("&")}return n},t.createPromiseCallback=function(){var e;if(!Promise){(e=function(){}).promise={};var t=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(e.promise,"then",{get:t}),Object.defineProperty(e.promise,"catch",{get:t}),e}var n=new Promise((function(t,n){e=function(e,r){return e?n(e):t(r)}}));return e.promise=n,e},t.getWeixinCode=function(){return t.getQuery("code")||t.getHash("code")},t.getMiniAppCode=function(){return new Promise((function(e,t){wx.login({success:function(t){e(t.code)},fail:function(e){t(e)}})}))},t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isUndefined=function(e){return void 0===e},t.isInstanceOf=function(e,t){return e instanceof t},t.isFormData=function(e){return"[object FormData]"===Object.prototype.toString.call(e)},t.genSeqId=function(){return Math.random().toString(16).slice(2)},t.getArgNames=function(e){var t=e.toString();return t.slice(t.indexOf("(")+1,t.indexOf(")")).match(/([^\s,]+)/g)},t.formatUrl=function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}})),b="dist/index.js",w="./dist/index.d.ts",T={build:"npm run tsc && webpack",tsc:"tsc -p tsconfig.json","tsc:w":"tsc -p tsconfig.json -w",test:"jest --verbose false -i",e2e:'NODE_ENV=e2e webpack && jest --config="./jest.e2e.config.js" --verbose false -i "e2e"',start:"webpack-dev-server --hot --open",eslint:'eslint "./**/*.js" "./**/*.ts"',"eslint-fix":'eslint --fix "./**/*.js" "./**/*.ts"',test_web:"npm run tsc && webpack-dev-server --devtool eval-source-map --progress --colors --hot --inline --content-base ./dist --host jimmytest-088bef.tcb.qcloud.la --port 80 --disableHostCheck true --mode development --config webpack.test.js"},S={type:"git",url:"https://github.com/TencentCloudBase/tcb-js-sdk"},E=["tcb","js-sdk"],k={"@cloudbase/adapter-interface":"^0.2.0","@cloudbase/adapter-wx_mp":"^0.2.1","@cloudbase/database":"^0.9.8"},O={"@babel/core":"^7.6.2","@babel/plugin-proposal-class-properties":"^7.5.5","@babel/plugin-proposal-object-rest-spread":"^7.6.2","@babel/plugin-transform-runtime":"^7.6.2","@babel/preset-env":"^7.6.2","@babel/preset-typescript":"^7.6.0","@babel/runtime":"^7.6.2","@types/jest":"^23.1.4","@types/node":"^10.14.4","@types/superagent":"^4.1.4",axios:"^0.19.0","babel-eslint":"^10.0.1","babel-loader":"^8.0.6","babel-polyfill":"^6.26.0",eslint:"^5.16.0","eslint-config-alloy":"^1.4.2","eslint-config-prettier":"^4.1.0","eslint-plugin-prettier":"^3.0.1","eslint-plugin-typescript":"^1.0.0-rc.3",express:"^4.17.1",husky:"^3.1.0",jest:"^24.7.1","jest-puppeteer":"^4.3.0","lint-staged":"^9.5.0","power-assert":"^1.6.1",puppeteer:"^1.20.0","serve-static":"^1.14.1","ts-jest":"^23.10.4","ts-loader":"^6.2.1",typescript:"^3.4.3","typescript-eslint-parser":"^22.0.0",webpack:"^4.41.3","webpack-bundle-analyzer":"^3.4.1","webpack-cli":"^3.3.0","webpack-dev-server":"^3.3.1","webpack-merge":"^4.2.2","webpack-visualizer-plugin":"^0.1.11"},A={hooks:{"pre-commit":"lint-staged"}},P={name:"tcb-js-sdk",version:"1.3.5",description:"js sdk for tcb",main:b,types:w,scripts:T,repository:S,keywords:E,author:"jimmyjzhang",license:"ISC",dependencies:k,devDependencies:O,husky:A,"lint-staged":{"*.{js,ts}":["eslint --fix","git add"]}},I=(v=Object.freeze({__proto__:null,name:"tcb-js-sdk",version:"1.3.5",description:"js sdk for tcb",main:b,types:w,scripts:T,repository:S,keywords:E,author:"jimmyjzhang",license:"ISC",dependencies:k,devDependencies:O,husky:A,default:P}))&&v.default||v,N=n((function(t,n){var r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var o=r(I);n.SDK_VERISON=o.version,n.ACCESS_TOKEN="access_token",n.ACCESS_TOKEN_Expire="access_token_expire",n.REFRESH_TOKEN="refresh_token",n.ANONYMOUS_UUID="anonymous_uuid",n.LOGIN_TYPE_KEY="login_type",n.protocol="undefined"!=typeof location&&"http:"===location.protocol?"http:":"https:",n.BASE_URL="e2e"===process.env.NODE_ENV&&"pre"===process.env.END_POINT?"//tcb-pre.tencentcloudapi.com/web":"//tcb-api.tencentcloudapi.com/web"}));!function(e){e.local="local",e.none="none",e.session="session"}(_||(_={}));var C=function(){},x=function(){};var R=Object.freeze({__proto__:null,get StorageType(){return _},AbstractSDKRequest:C,AbstractStorage:x,formatUrl:function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}}),q=n((function(t,n){var r,o=e&&e.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},i=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},a=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};Object.defineProperty(n,"__esModule",{value:!0});var c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.get=function(e){return this._request(s(s({},e),{method:"get"}))},t.prototype.post=function(e){return this._request(s(s({},e),{method:"post"}))},t.prototype.upload=function(e){var t=e.data,n=e.file,r=e.name,o=new FormData;for(var i in t)o.append(i,t[i]);return o.append("key",r),o.append("file",n),this._request(s(s({},e),{data:o,method:"post"}))},t.prototype.download=function(e){return i(this,void 0,void 0,(function(){var t,n;return a(this,(function(r){return t=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(n=document.createElement("a")).href=e.url,n.setAttribute("download",t),n.setAttribute("target","_blank"),document.body.appendChild(n),n.click(),[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}))}))},t.prototype._request=function(e){var t=String(e.method).toLowerCase()||"get";return new Promise((function(n){var r=e.url,o=e.headers,s=void 0===o?{}:o,i=e.data,a=e.responseType,c=m.formatUrl(N.protocol,r,"get"===t?i:{}),u=new XMLHttpRequest;for(var l in u.open(t,c),a&&(u.responseType=a),s)u.setRequestHeader(l,s[l]);u.onreadystatechange=function(){if(4===u.readyState){var e={statusCode:u.status};try{e.data=JSON.parse(u.responseText)}catch(e){}n(e)}},u.send("post"===t&&m.isFormData(i)?i:JSON.stringify(i||{}))}))},t}(R.AbstractSDKRequest);n.WebRequest=c,n.genAdapter=function(){return{root:window,reqClass:c,wsClass:WebSocket,localStorage:localStorage,sessionStorage:sessionStorage}}})),U=n((function(t,n){var r=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var o,s=r(q);!function(e){e.WEB="web",e.WX_MP="wx_mp"}(o=n.RUNTIME||(n.RUNTIME={})),n.useAdapters=function(e){for(var t=0,n=m.isArray(e)?e:[e];t<n.length;t++){var r=n[t],o=r.isMatch,s=r.genAdapter,i=r.runtime;if(o())return{adapter:s(),runtime:i}}},n.useDefaultAdapter=function(){return{adapter:s.genAdapter(),runtime:o.WEB}},n.Adapter={adapter:null,runtime:void 0}})),j=n((function(t,n){var r,o=e&&e.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(n,"__esModule",{value:!0});var s=function(){function e(e){switch(U.Adapter.adapter.primaryStorage||e){case"local":this.storageClass=U.Adapter.adapter.localStorage||new i;break;case"none":this.storageClass=new i;break;default:this.storageClass=U.Adapter.adapter.sessionStorage||new i}}return e.prototype.setStore=function(e,t,n){try{if(!this.storageClass)return}catch(e){return}var r,o={};o.version=n||"localCachev1",o.content=t,r=JSON.stringify(o);try{this.storageClass.setItem(e,r)}catch(e){return}},e.prototype.getStore=function(e,t){try{if(!this.storageClass)return}catch(e){return""}t=t||"localCachev1";var n=this.storageClass.getItem(e);return n&&n.indexOf(t)>=0?JSON.parse(n).content:""},e.prototype.removeStore=function(e){this.storageClass.removeItem(e)},e}();n.Cache=s;var i=function(e){function t(){var t=e.call(this)||this;return U.Adapter.adapter.root.tcbObject||(U.Adapter.adapter.root.tcbObject={}),t}return o(t,e),t.prototype.setItem=function(e,t){U.Adapter.adapter.root.tcbObject[e]=t},t.prototype.getItem=function(e){return U.Adapter.adapter.root.tcbObject[e]},t.prototype.removeItem=function(e){delete U.Adapter.adapter.root.tcbObject[e]},t.prototype.clear=function(){delete U.Adapter.adapter.root.tcbObject},t}(R.AbstractStorage)})),L=n((function(t,n){var r,o=e&&e.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var s=arguments[t],i=0,a=s.length;i<a;i++,o++)r[o]=s[i];return r};Object.defineProperty(n,"__esModule",{value:!0});var i=function(e,t){this.data=t||null,this.name=e};n.IEvent=i;var a=function(e){function t(t,n){var r=e.call(this,"error",{error:t,data:n})||this;return r.error=t,r}return o(t,e),t}(i);n.IErrorEvent=a;var c=function(){function e(){this._listeners={}}return e.prototype.on=function(e,t){return function(e,t,n){n[e]=n[e]||[],n[e].push(t)}(e,t,this._listeners),this},e.prototype.off=function(e,t){return function(e,t,n){if(n&&n[e]){var r=n[e].indexOf(t);-1!==r&&n[e].splice(r,1)}}(e,t,this._listeners),this},e.prototype.fire=function(e,t){if(m.isInstanceOf(e,a))return console.error(e.error),this;var n=m.isString(e)?new i(e,t||{}):e,r=n.name;if(this._listens(r)){n.target=this;for(var o=0,c=this._listeners[r]?s(this._listeners[r]):[];o<c.length;o++){c[o].call(this,n)}}return this},e.prototype._listens=function(e){return this._listeners[e]&&this._listeners[e].length>0},e}();n.IEventEmitter=c;var u=new c;n.addEventListener=function(e,t){u.on(e,t)},n.activateEvent=function(e,t){void 0===t&&(t={}),u.fire(e,t)},n.removeEventListener=function(e,t){u.off(e,t)},n.EVENTS={LOGIN_STATE_CHANGED:"loginStateChanged",LOGIN_STATE_EXPIRE:"loginStateExpire",LOGIN_TYPE_CHANGE:"loginTypeChanged",ANONYMOUS_CONVERTED:"anonymousConverted",REFRESH_ACCESS_TOKEN:"refreshAccessToken"}})),D=n((function(t,n){var r=e&&e.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},o=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},s=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};Object.defineProperty(n,"__esModule",{value:!0});var i=["auth.getJwt","auth.logout","auth.signInWithTicket","auth.signInAnonymously"],a={"X-SDK-Version":N.SDK_VERISON};function c(e,t,n){var o=e[t];e[t]=function(t){var s={},i={};n.forEach((function(n){var r=n.call(e,t),o=r.data,a=r.headers;Object.assign(s,o),Object.assign(i,a)}));var a=t.data;return a&&function(){if(m.isFormData(a))for(var e in s)a.append(e,s[e]);else t.data=r(r({},a),s)}(),t.headers=r(r({},t.headers||{}),i),o.call(e,t)}}function u(){var e=m.genSeqId();return{data:{seqId:e},headers:r(r({},a),{"x-seqid":e})}}var l=function(){function e(e){void 0===e&&(e={}),this.config=e,this.cache=new j.Cache(e.persistence),this.accessTokenKey=N.ACCESS_TOKEN+"_"+e.env,this.accessTokenExpireKey=N.ACCESS_TOKEN_Expire+"_"+e.env,this.refreshTokenKey=N.REFRESH_TOKEN+"_"+e.env,this.anonymousUuidKey=N.ANONYMOUS_UUID+"_"+e.env,this.loginTypeKey=N.LOGIN_TYPE_KEY+"_"+e.env,this._reqClass=new U.Adapter.adapter.reqClass,c(this._reqClass,"post",[u]),c(this._reqClass,"upload",[u]),c(this._reqClass,"download",[u])}return e.prototype.post=function(e){return o(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this._reqClass.post(e)];case 1:return[2,t.sent()]}}))}))},e.prototype.upload=function(e){return o(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this._reqClass.upload(e)];case 1:return[2,t.sent()]}}))}))},e.prototype.download=function(e){return o(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this._reqClass.download(e)];case 1:return[2,t.sent()]}}))}))},e.prototype.refreshAccessToken=function(){return o(this,void 0,void 0,(function(){var e,t,n;return s(this,(function(r){switch(r.label){case 0:this._refreshAccessTokenPromise||(this._refreshAccessTokenPromise=this._refreshAccessToken()),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this._refreshAccessTokenPromise];case 2:return e=r.sent(),[3,4];case 3:return n=r.sent(),t=n,[3,4];case 4:if(this._refreshAccessTokenPromise=null,this._shouldRefreshAccessTokenHook=null,t)throw t;return[2,e]}}))}))},e.prototype._refreshAccessToken=function(){return o(this,void 0,void 0,(function(){var e,t,n,r;return s(this,(function(o){switch(o.label){case 0:if(this.cache.removeStore(this.accessTokenKey),this.cache.removeStore(this.accessTokenExpireKey),!(e=this.cache.getStore(this.refreshTokenKey)))throw new Error("[tcb-js-sdk] 未登录CloudBase");return t={refresh_token:e},this.cache.getStore(this.loginTypeKey)===M.LOGINTYPE.ANONYMOUS&&(t.anonymous_uuid=this.cache.getStore(this.anonymousUuidKey)),[4,this.request("auth.getJwt",t)];case 1:if((n=o.sent()).data.code)throw"SIGN_PARAM_INVALID"!==(r=n.data.code)&&"REFRESH_TOKEN_EXPIRED"!==r&&"INVALID_REFRESH_TOKEN"!==r||(L.activateEvent(L.EVENTS.LOGIN_STATE_EXPIRE),this.cache.removeStore(this.refreshTokenKey)),new Error("[tcb-js-sdk] 刷新access token失败:"+n.data.code);return n.data.access_token?(L.activateEvent(L.EVENTS.REFRESH_ACCESS_TOKEN),this.cache.setStore(this.accessTokenKey,n.data.access_token),this.cache.setStore(this.accessTokenExpireKey,n.data.access_token_expire+Date.now()),L.activateEvent(L.EVENTS.LOGIN_TYPE_CHANGE,n.data.login_type),[2,{accessToken:n.data.access_token,accessTokenExpire:n.data.access_token_expire}]):(n.data.refresh_token&&(this.cache.removeStore(this.refreshTokenKey),this.cache.setStore(this.refreshTokenKey,n.data.refresh_token),this._refreshAccessToken()),[2])}}))}))},e.prototype.getAccessToken=function(){return o(this,void 0,void 0,(function(){var e,t,n,r;return s(this,(function(o){switch(o.label){case 0:return e=this.cache.getStore(this.accessTokenKey),t=this.cache.getStore(this.accessTokenExpireKey),n=!0,(r=this._shouldRefreshAccessTokenHook)?[4,this._shouldRefreshAccessTokenHook(e,t)]:[3,2];case 1:r=!o.sent(),o.label=2;case 2:return r&&(n=!1),(!e||!t||t<Date.now())&&n?[2,this.refreshAccessToken()]:[2,{accessToken:e,accessTokenExpire:t}]}}))}))},e.prototype.request=function(e,t,n){return o(this,void 0,void 0,(function(){var o,a,c,u,l,h,f,p,d,y,g,v;return s(this,(function(s){switch(s.label){case 0:return o="application/x-www-form-urlencoded",a=r({action:e,env:this.config.env,dataVersion:"2019-08-16"},t),-1!==i.indexOf(e)?[3,2]:(c=a,[4,this.getAccessToken()]);case 1:c.access_token=s.sent().accessToken,s.label=2;case 2:if("storage.uploadFile"===e){for(l in u=new FormData)u.hasOwnProperty(l)&&void 0!==u[l]&&u.append(l,a[l]);o="multipart/form-data"}else o="application/json;charset=UTF-8",u=a;return h={headers:{"content-type":o}},n&&n.onUploadProgress&&(h.onUploadProgress=n.onUploadProgress),f=t.parse,p=t.query,d=t.search,y={env:this.config.env},f&&(y.parse=!0),p&&(y=r(r({},p),y)),g=m.formatUrl(N.protocol,N.BASE_URL,y),d&&(g+=d),[4,this.post(r({url:g,data:u},h))];case 3:if(v=s.sent(),200!==Number(v.status)&&200!==Number(v.statusCode)||!v.data)throw new Error("network request error");return[2,v]}}))}))},e.prototype.send=function(e,t){return void 0===t&&(t={}),o(this,void 0,void 0,(function(){var n,r,o;return s(this,(function(s){switch(s.label){case 0:return n=setTimeout((function(){console.warn("Database operation is longer than 3s. Please check query performance and your network environment.")}),3e3),[4,this.request(e,t,{onUploadProgress:t.onUploadProgress})];case 1:return r=s.sent(),clearTimeout(n),"ACCESS_TOKEN_EXPIRED"!==r.data.code||-1!==i.indexOf(e)?[3,4]:[4,this.refreshAccessToken()];case 2:return s.sent(),[4,this.request(e,t,{onUploadProgress:t.onUploadProgress})];case 3:if((o=s.sent()).data.code)throw new Error("["+o.data.code+"] "+o.data.message);return[2,o.data];case 4:if(r.data.code)throw new Error("["+r.data.code+"] "+r.data.message);return[2,r.data]}}))}))},e}();n.Request=l})),M=n((function(t,n){var r,o=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},s=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};Object.defineProperty(n,"__esModule",{value:!0}),function(e){e.ANONYMOUS="ANONYMOUS",e.WECHAT="WECHAT",e.CUSTOM="CUSTOM",e.NULL="NULL"}(r=n.LOGINTYPE||(n.LOGINTYPE={}));var i=function(){function e(e){this._loginType=r.NULL,this.config=e,this.onLoginTypeChanged=this.onLoginTypeChanged.bind(this),L.addEventListener(L.EVENTS.LOGIN_TYPE_CHANGE,this.onLoginTypeChanged)}return e.prototype.init=function(){this.httpRequest=new D.Request(this.config),this.cache=new j.Cache(this.config.persistence),this.accessTokenKey=N.ACCESS_TOKEN+"_"+this.config.env,this.accessTokenExpireKey=N.ACCESS_TOKEN_Expire+"_"+this.config.env,this.refreshTokenKey=N.REFRESH_TOKEN+"_"+this.config.env,this.loginTypeKey=N.LOGIN_TYPE_KEY+"_"+this.config.env},e.prototype.onLoginTypeChanged=function(e){this._loginType=e.data,this.cache.setStore(this.loginTypeKey,this._loginType)},Object.defineProperty(e.prototype,"loginType",{get:function(){return this._loginType},enumerable:!0,configurable:!0}),e.prototype.setRefreshToken=function(e){this.cache.removeStore(this.accessTokenKey),this.cache.removeStore(this.accessTokenExpireKey),this.cache.setStore(this.refreshTokenKey,e)},e.prototype.getRefreshTokenByWXCode=function(e,t,n){return o(this,void 0,void 0,(function(){var r;return s(this,(function(o){return"auth.getJwt",r=U.Adapter.runtime===U.RUNTIME.WX_MP?"1":"0",[2,this.httpRequest.send("auth.getJwt",{appid:e,loginType:t,code:n,hybridMiniapp:r}).then((function(e){if(e.code)throw new Error("[tcb-js-sdk] 微信登录失败: "+e.code);if(e.refresh_token)return{refreshToken:e.refresh_token,accessToken:e.access_token,accessTokenExpire:e.access_token_expire};throw new Error("[tcb-js-sdk] getJwt未返回refreshToken")}))]}))}))},e}();n.default=i})),K=n((function(t,n){var r,o=e&&e.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},i=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},a=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var c,u,l=a(m),h=a(M);!function(e){e.snsapi_base="snsapi_base",e.snsapi_userinfo="snsapi_userinfo",e.snsapi_login="snsapi_login"}(c||(c={})),function(e){e.redirect="redirect",e.prompt="prompt"}(u||(u={}));var f={},p=function(e){function t(t,n,r,o,s){var i=e.call(this,t)||this;return i.config=t,i.appid=n,i.scope=U.Adapter.runtime===U.RUNTIME.WX_MP?"snsapi_base":r,i.state=s||"weixin",i.loginMode=o||"redirect",i}return o(t,e),t.prototype.signIn=function(){return s(this,void 0,void 0,(function(){var e,t,n;return i(this,(function(r){switch(r.label){case 0:f[this.config.env]||(f[this.config.env]=this._signIn()),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,f[this.config.env]];case 2:return e=r.sent(),[3,4];case 3:return n=r.sent(),t=n,[3,4];case 4:if(f[this.config.env]=null,t)throw t;return[2,e]}}))}))},t.prototype._signIn=function(){return s(this,void 0,void 0,(function(){var e,t,n,r,o,s;return i(this,(function(i){switch(i.label){case 0:if(e=this.cache.getStore(this.accessTokenKey),t=this.cache.getStore(this.accessTokenExpireKey),e){if(t&&t>Date.now())return[2,{credential:{accessToken:e,refreshToken:this.cache.getStore(this.refreshTokenKey)}}];this.cache.removeStore(this.accessTokenKey),this.cache.removeStore(this.accessTokenExpireKey)}if(!1===Object.values(c).includes(c[this.scope]))throw new Error("错误的scope类型");return U.Adapter.runtime!==U.RUNTIME.WX_MP?[3,2]:[4,l.getMiniAppCode()];case 1:return n=i.sent(),[3,4];case 2:return[4,l.getWeixinCode()];case 3:if(!(n=i.sent()))return[2,this.redirect()];i.label=4;case 4:return r=function(e){switch(e){case c.snsapi_login:return"WECHAT-OPEN";default:return"WECHAT-PUBLIC"}}(this.scope),[4,this.getRefreshTokenByWXCode(this.appid,r,n)];case 5:return o=i.sent(),s=o.refreshToken,this.cache.setStore(this.refreshTokenKey,s),o.accessToken&&this.cache.setStore(this.accessTokenKey,o.accessToken),o.accessTokenExpire&&this.cache.setStore(this.accessTokenExpireKey,o.accessTokenExpire+Date.now()),L.activateEvent(L.EVENTS.LOGIN_STATE_CHANGED),L.activateEvent(L.EVENTS.LOGIN_TYPE_CHANGE,h.LOGINTYPE.WECHAT),[2,{credential:{refreshToken:s}}]}}))}))},t.prototype.redirect=function(){var e=l.removeParam("code",location.href);e=l.removeParam("state",e),e=encodeURIComponent(e);var t="//open.weixin.qq.com/connect/oauth2/authorize";"snsapi_login"===this.scope&&(t="//open.weixin.qq.com/connect/qrconnect"),"redirect"===u[this.loginMode]&&(location.href=t+"?appid="+this.appid+"&redirect_uri="+e+"&response_type=code&scope="+this.scope+"&state="+this.state+"#wechat_redirect")},t}(h.default);n.default=p})),F=n((function(t,n){var r,o=e&&e.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},i=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},a=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},c=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var u=c(M),l=function(e){function t(t){var n=e.call(this,s(s({},t),{persistence:"local"}))||this;return n._anonymousUuidKey=N.ANONYMOUS_UUID+"_"+n.config.env,n._loginTypeKey=N.LOGIN_TYPE_KEY+"_"+n.config.env,n}return o(t,e),t.prototype.init=function(){e.prototype.init.call(this)},t.prototype.signIn=function(){return i(this,void 0,void 0,(function(){var e,t,n;return a(this,(function(r){switch(r.label){case 0:return e=this.cache.getStore(this._anonymousUuidKey)||void 0,t=this.cache.getStore(this.refreshTokenKey)||void 0,[4,this.httpRequest.send("auth.signInAnonymously",{anonymous_uuid:e,refresh_token:t})];case 1:return(n=r.sent()).uuid&&n.refresh_token?(this._setAnonymousUUID(n.uuid),this.setRefreshToken(n.refresh_token),[4,this.httpRequest.refreshAccessToken()]):[3,3];case 2:return r.sent(),L.activateEvent(L.EVENTS.LOGIN_STATE_CHANGED),L.activateEvent(L.EVENTS.LOGIN_TYPE_CHANGE,u.LOGINTYPE.ANONYMOUS),[2,{credential:{refreshToken:n.refresh_token}}];case 3:throw new Error("[tcb-js-sdk] 匿名登录失败")}}))}))},t.prototype.linkAndRetrieveDataWithTicket=function(e){return i(this,void 0,void 0,(function(){var t,n,r;return a(this,(function(o){switch(o.label){case 0:return t=this.cache.getStore(this._anonymousUuidKey),n=this.cache.getStore(this.refreshTokenKey),[4,this.httpRequest.send("auth.linkAndRetrieveDataWithTicket",{anonymous_uuid:t,refresh_token:n,ticket:e})];case 1:return(r=o.sent()).refresh_token?(this._clearAnonymousUUID(),this.setRefreshToken(r.refresh_token),[4,this.httpRequest.refreshAccessToken()]):[3,3];case 2:return o.sent(),L.activateEvent(L.EVENTS.ANONYMOUS_CONVERTED,{refresh_token:r.refresh_token}),L.activateEvent(L.EVENTS.LOGIN_TYPE_CHANGE,u.LOGINTYPE.CUSTOM),[2,{credential:{refreshToken:r.refresh_token}}];case 3:throw new Error("[tcb-js-sdk] 匿名转化失败")}}))}))},t.prototype.getAllStore=function(){var e={};return e[this.refreshTokenKey]=this.cache.getStore(this.refreshTokenKey)||"",e[this._loginTypeKey]=this.cache.getStore(this._loginTypeKey)||"",e[this.accessTokenKey]=this.cache.getStore(this.accessTokenKey)||"",e[this.accessTokenExpireKey]=this.cache.getStore(this.accessTokenExpireKey)||"",e},t.prototype._setAnonymousUUID=function(e){this.cache.removeStore(this._anonymousUuidKey),this.cache.setStore(this._anonymousUuidKey,e),this.cache.setStore(this._loginTypeKey,u.LOGINTYPE.ANONYMOUS)},t.prototype._clearAnonymousUUID=function(){this.cache.removeStore(this._anonymousUuidKey)},t}(u.default);n.AnonymousAuthProvider=l})),G=n((function(t,n){var r,o=e&&e.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),s=e&&e.__assign||function(){return(s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},i=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},a=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},c=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},u=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t};Object.defineProperty(n,"__esModule",{value:!0});var l=c(K),h=u(M),f=function(e){function t(t){var n=e.call(this,t)||this;return n.config=t,n}return o(t,e),t.prototype.init=function(){e.prototype.init.call(this),this.customAuthProvider=new h.default(this.config),this.customAuthProvider.init()},t.prototype.weixinAuthProvider=function(e){var t=e.appid,n=e.scope,r=e.loginMode,o=e.state,s=new l.default(this.config,t,n,r,o);return s.init(),s},t.prototype.signInAnonymously=function(){return i(this,void 0,void 0,(function(){var e=this;return a(this,(function(t){switch(t.label){case 0:return this._anonymousAuthProvider||(this._anonymousAuthProvider=new F.AnonymousAuthProvider(this.config),this._anonymousAuthProvider.init()),L.addEventListener(L.EVENTS.LOGIN_TYPE_CHANGE,(function(t){if(t&&t.data===h.LOGINTYPE.ANONYMOUS){var n=e._anonymousAuthProvider.getAllStore();for(var r in n)n[r]&&e.httpRequest.cache.setStore(r,n[r])}})),[4,this._anonymousAuthProvider.signIn()];case 1:return[2,t.sent()]}}))}))},t.prototype.linkAndRetrieveDataWithTicket=function(e){return i(this,void 0,void 0,(function(){var t=this;return a(this,(function(n){switch(n.label){case 0:return this._anonymousAuthProvider||(this._anonymousAuthProvider=new F.AnonymousAuthProvider(this.config),this._anonymousAuthProvider.init()),L.addEventListener(L.EVENTS.ANONYMOUS_CONVERTED,(function(e){var n=e.data.refresh_token;n&&t.httpRequest.cache.setStore(t.refreshTokenKey,n)})),[4,this._anonymousAuthProvider.linkAndRetrieveDataWithTicket(e)];case 1:return[2,n.sent()]}}))}))},t.prototype.signOut=function(){return i(this,void 0,void 0,(function(){var e,t,n,r,o,s,i;return a(this,(function(a){switch(a.label){case 0:if(this.loginType===h.LOGINTYPE.ANONYMOUS)throw new Error("[tcb-js-sdk] 匿名用户不支持登出操作");return e=this.httpRequest,t=e.cache,n=e.refreshTokenKey,r=e.accessTokenKey,o=e.accessTokenExpireKey,"auth.logout",(s=t.getStore(n))?[4,this.httpRequest.send("auth.logout",{refresh_token:s})]:[2];case 1:return i=a.sent(),t.removeStore(n),t.removeStore(r),t.removeStore(o),L.activateEvent(L.EVENTS.LOGIN_STATE_CHANGED),L.activateEvent(L.EVENTS.LOGIN_TYPE_CHANGE,h.LOGINTYPE.NULL),[2,i]}}))}))},t.prototype.getAccessToken=function(){return i(this,void 0,void 0,(function(){var e;return a(this,(function(t){switch(t.label){case 0:return e={},[4,this.httpRequest.getAccessToken()];case 1:return[2,(e.accessToken=t.sent().accessToken,e.env=this.config.env,e)]}}))}))},t.prototype.onLoginStateExpire=function(e){L.addEventListener("loginStateExpire",e)},t.prototype.getLoginState=function(){return i(this,void 0,void 0,(function(){var e,t,n,r,o;return a(this,(function(s){switch(s.label){case 0:if(e=this.httpRequest,t=e.cache,n=e.refreshTokenKey,r=e.accessTokenKey,!(o=t.getStore(n)))return[3,5];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.httpRequest.refreshAccessToken()];case 2:return s.sent(),[3,4];case 3:return s.sent(),[2,null];case 4:return[2,{isAnonymous:this.loginType===h.LOGINTYPE.ANONYMOUS,credential:{refreshToken:o,accessToken:t.getStore(r)}}];case 5:return[2,null]}}))}))},t.prototype.signInWithTicket=function(e){return i(this,void 0,void 0,(function(){var t,n,r,o;return a(this,(function(s){switch(s.label){case 0:if("string"!=typeof e)throw new Error("ticket must be a string");return t=this.httpRequest,n=t.cache,r=t.refreshTokenKey,[4,this.httpRequest.send("auth.signInWithTicket",{ticket:e,refresh_token:n.getStore(r)||""})];case 1:return(o=s.sent()).refresh_token?(this.customAuthProvider.setRefreshToken(o.refresh_token),[4,this.httpRequest.refreshAccessToken()]):[3,3];case 2:return s.sent(),L.activateEvent(L.EVENTS.LOGIN_STATE_CHANGED),L.activateEvent(L.EVENTS.LOGIN_TYPE_CHANGE,h.LOGINTYPE.CUSTOM),[2,{credential:{refreshToken:o.refresh_token}}];case 3:throw new Error("[tcb-js-sdk] 自定义登录失败")}}))}))},t.prototype.shouldRefreshAccessToken=function(e){this.httpRequest._shouldRefreshAccessTokenHook=e.bind(this)},t.prototype.getUserInfo=function(){return this.httpRequest.send("auth.getUserInfo",{}).then((function(e){return e.code?e:s(s({},e.data),{requestId:e.seqId})}))},t}(h.default);n.default=f})),H=n((function(t,n){var r=e&&e.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))},o=e&&e.__generator||function(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i;)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 i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}};Object.defineProperty(n,"__esModule",{value:!0}),n.uploadFile=function(e,t){t=t||m.createPromiseCallback();var n=new D.Request(this.config),r=e.cloudPath,o=e.filePath,s=e.onUploadProgress,i=e.fileType||"image";return n.send("storage.getUploadMetadata",{path:r}).then((function(e){var a=e.data,c=a.url,u=a.authorization,l=a.token,h=a.fileId,f=a.cosFileId,p=e.requestId,d={key:r,signature:u,"x-cos-meta-fileid":f,success_action_status:"201","x-cos-security-token":l};n.upload({url:c,data:d,file:o,name:r,fileType:i,onUploadProgress:s}).then((function(e){201===e.statusCode?t(null,{fileID:h,requestId:p}):t(new Error("STORAGE_REQUEST_FAIL: "+e.data))})).catch((function(e){t(e)}))})).catch((function(e){t(e)})),t.promise},n.deleteFile=function(e,t){var n=e.fileList;if(t=t||m.createPromiseCallback(),!n||!Array.isArray(n))return{code:"INVALID_PARAM",message:"fileList必须是非空的数组"};for(var r=0,o=n;r<o.length;r++){var s=o[r];if(!s||"string"!=typeof s)return{code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"}}var i={fileid_list:n};return new D.Request(this.config).send("storage.batchDeleteFile",i).then((function(e){e.code?t(null,e):t(null,{fileList:e.data.delete_list,requestId:e.requestId})})).catch((function(e){t(e)})),t.promise},n.getTempFileURL=function(e,t){var n=e.fileList;t=t||m.createPromiseCallback(),n&&Array.isArray(n)||t(null,{code:"INVALID_PARAM",message:"fileList必须是非空的数组"});for(var r=[],o=0,s=n;o<s.length;o++){var i=s[o];"object"==typeof i?(i.hasOwnProperty("fileID")&&i.hasOwnProperty("maxAge")||t(null,{code:"INVALID_PARAM",message:"fileList的元素必须是包含fileID和maxAge的对象"}),r.push({fileid:i.fileID,max_age:i.maxAge})):"string"==typeof i?r.push({fileid:i}):t(null,{code:"INVALID_PARAM",message:"fileList的元素必须是字符串"})}var a={file_list:r};return new D.Request(this.config).send("storage.batchGetDownloadUrl",a).then((function(e){e.code?t(null,e):t(null,{fileList:e.data.download_list,requestId:e.requestId})})).catch((function(e){t(e)})),t.promise},n.downloadFile=function(e,t){var s=e.fileID;return r(this,void 0,void 0,(function(){var e,r,i,a,c;return o(this,(function(o){switch(o.label){case 0:return[4,n.getTempFileURL.call(this,{fileList:[{fileID:s,maxAge:600}]})];case 1:return e=o.sent(),"SUCCESS"!==(r=e.fileList[0]).code?[2,t?t(r):new Promise((function(e){e(r)}))]:(i=r.download_url,i=encodeURI(i),a=new D.Request(this.config),t?[4,a.download({url:i})]:[3,3]);case 2:return c=o.sent(),t(c),[3,4];case 3:return[2,a.download({url:i})];case 4:return[2]}}))}))}})),Y=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.callFunction=function(e,t){var n,r=e.name,o=e.data,s=e.query,i=e.parse,a=e.search,c=t||m.createPromiseCallback();try{n=o?JSON.stringify(o):""}catch(e){return Promise.reject(e)}if(!r)return Promise.reject(new Error("函数名不能为空"));var u={query:s,parse:i,search:a,function_name:r,request_data:n};return new D.Request(this.config).send("functions.invokeFunction",u).then((function(e){if(e.code)c(null,e);else{var t=e.data.response_data;if(i)c(null,{result:t,requestId:e.requestId});else try{t=JSON.parse(e.data.response_data),c(null,{result:t,requestId:e.requestId})}catch(e){c(new Error("response data must be json"))}}return c.promise})).catch((function(e){c(e)})),c.promise}})),V=t(n((function(t){var n=e&&e.__assign||function(){return(n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},r=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},o=e&&e.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t},s=r(G),i=o(H),a=o(Y),c={timeout:15e3},u=new(function(){function e(e){var t=this;this.config=e||this.config,this.authObj=void 0,L.addEventListener(L.EVENTS.LOGIN_TYPE_CHANGE,(function(e){e.data===M.LOGINTYPE.ANONYMOUS&&(t.config.persistence="local")}))}return e.prototype.init=function(t){return this.config=n(n({},c),t),U.Adapter.adapter||this._useDefaultAdapter(),new e(this.config)},e.prototype.auth=function(e){var t=(void 0===e?{}:e).persistence;return this.authObj||(this.config=n(n({},this.config),{persistence:t||U.Adapter.adapter.primaryStorage||"session"}),this.authObj=new s.default(this.config),this.authObj.init()),this.authObj},e.prototype.on=function(e,t){return L.addEventListener.apply(this,[e,t])},e.prototype.off=function(e,t){return L.removeEventListener.apply(this,[e,t])},e.prototype.callFunction=function(e,t){return a.callFunction.apply(this,[e,t])},e.prototype.deleteFile=function(e,t){return i.deleteFile.apply(this,[e,t])},e.prototype.getTempFileURL=function(e,t){return i.getTempFileURL.apply(this,[e,t])},e.prototype.downloadFile=function(e,t){return i.downloadFile.apply(this,[e,t])},e.prototype.uploadFile=function(e,t){return i.uploadFile.apply(this,[e,t])},e.prototype.useAdapters=function(e){var t=U.useAdapters(e)||{},n=t.adapter,r=t.runtime;n&&(U.Adapter.adapter=n),r&&(U.Adapter.runtime=r)},e.prototype._useDefaultAdapter=function(){var e=U.useDefaultAdapter(),t=e.adapter,n=e.runtime;U.Adapter.adapter=t,U.Adapter.runtime=n},e}());try{window.tcb=u}catch(e){}t.exports=u})));function B(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var s in n)""===o?!r&&(t+="?"):o+="&",o+=s+"="+encodeURIComponent(n[s]);return/^http(s)?:\/\//.test(t+=o)?t:""+e+t}class W{post(e){const{url:t,data:n,headers:r}=e;return new Promise((e,o)=>{d.request({url:B("https:",t),data:n,method:"POST",header:r,success(t){e(t)},fail(e){o(e)}})})}upload(e){return new Promise((t,n)=>{const{url:r,file:o,data:s,headers:i,fileType:a}=e,c=d.uploadFile({url:B("https:",r),name:"file",formData:Object.assign({},s),filePath:o,fileType:a,header:i,success(e){const n={statusCode:e.statusCode,data:e.data||{}};200===e.statusCode&&s.success_action_status&&(n.statusCode=parseInt(s.success_action_status,10)),t(n)},fail(e){"mp-alipay"===process.env.VUE_APP_PLATFORM&&"development"===process.env.NODE_ENV&&console.warn("支付宝小程序开发工具上传腾讯云时无法准确判断是否上传成功,请使用真机测试"),n(new Error(e.errMsg||"uploadFile:fail"))}});"function"==typeof e.onUploadProgress&&c&&"function"==typeof c.onProgressUpdate&&c.onProgressUpdate(t=>{e.onUploadProgress({loaded:t.totalBytesSent,total:t.totalBytesExpectedToSend})})})}}const z={setItem(e,t){d.setStorageSync(e,t)},getItem:e=>d.getStorageSync(e),removeItem(e){d.removeStorageSync(e)},clear(){d.clearStorageSync()}};const J={genAdapter:function(){return{root:{},reqClass:W,localStorage:z,primaryStorage:"local"}},isMatch:function(){return!0},runtime:"uni_app"};V.useAdapters(J);const X=V,$=X.init;X.init=function(e){e.env=e.spaceId;const t=$.call(this,e);t.config.provider="tencent",t.config.spaceId=e.spaceId;const n=t.auth;t.auth=function(e){const t=n.call(this,e);return["linkAndRetrieveDataWithTicket","signInAnonymously","signOut","getAccessToken","getLoginState","signInWithTicket","getUserInfo"].forEach(e=>{t[e]=s(t[e]).bind(t)}),t};return["deleteFile","getTempFileURL","downloadFile"].forEach(e=>{t[e]=s(t[e]).bind(t)}),t};let Q,Z;function ee(e){Q||(Q={PLATFORM:process.env.VUE_APP_PLATFORM,OS:u,APPID:a.appid,CLIENT_SDK_VERSION:"1.0.0"},Z={ak:a.appid,p:"android"===u?"a":"i",ut:f(),uuid:h()});const t=JSON.parse(JSON.stringify(e.data||{})),n=e.name,r=this.config.spaceId,o={tencent:"t",aliyun:"a"}[this.config.provider],s=Object.assign({},Z,{fn:n,sid:r,pvd:o});Object.assign(t,{clientInfo:Q,uniCloudClientInfo:encodeURIComponent(JSON.stringify(s))});const i=d.getStorageSync("uni_id_token")||d.getStorageSync("uniIdToken");return i&&(t.uniIdToken=i),e.data=t,e}let te=new class{init(e){let t={};const n=!1!==e.debugFunction&&"development"===process.env.NODE_ENV&&("h5"===process.env.VUE_APP_PLATFORM&&navigator.userAgent.indexOf("HBuilderX")>0||"app-plus"===process.env.VUE_APP_PLATFORM);switch(e.provider){case"tencent":t=X.init(Object.assign(e,{useDebugFunction:n}));break;case"aliyun":t=g.init(Object.assign(e,{useDebugFunction:n}));break;default:throw new Error("未提供正确的provider参数")}t.isReady=!1;const r=t.auth();return t.initSignIn=r.getLoginState().then(e=>e?Promise.resolve():r.signInAnonymously()).then(()=>new Promise(e=>{"quickapp-native"===process.env.VUE_APP_PLATFORM?(u="android",uni.getStorage({key:"__DC_CLOUD_UUID",success(t){c=t.data?t.data:l(32),e()}})):setTimeout(()=>{u=uni.getSystemInfoSync().platform,c=uni.getStorageSync("__DC_CLOUD_UUID")||l(32),e()},0)})).then(()=>{t.isReady=!0}),function(e){const t=e.callFunction;e.callFunction=function(e){let n;return n=this.isReady?Promise.resolve():this.initSignIn,n.then(()=>{const n=ee.call(this,e),r={aliyun:"aliyun",tencent:"tcb"}[this.config.provider];return new Promise((o,s)=>{t.call(this,n).then(t=>{if(this.config.useDebugFunction&&t&&t.requestId){const n=JSON.stringify({spaceId:this.config.spaceId,functionName:e.name,requestId:t.requestId});console.log(`[${r}-request]${n}[/${r}-request]`)}o(t)}).catch(t=>{if(this.config.useDebugFunction&&t&&t.requestId){const n=JSON.stringify({spaceId:this.config.spaceId,functionName:e.name,requestId:t.requestId});console.log(`[${r}-request]${n}[/${r}-request]`)}t&&t.message&&(t.message=`[${e.name}]: ${t.message}`),s(t)})})})};const n=e.callFunction;e.callFunction=function(e){return s(n).call(this,e)}}(t),function(e){const t=e.uploadFile;e.uploadFile=function(e){let n;return n=this.isReady?Promise.resolve():this.initSignIn,n.then(()=>t.call(this,e))};const n=e.uploadFile;e.uploadFile=function(e){return s(n).call(this,e)}}(t),t.init=this.init,t}};try{let e={};1===process.env.UNI_CLOUD_PROVIDER.length&&(e=process.env.UNI_CLOUD_PROVIDER[0]),te=te.init(e)}catch(e){["auth","callFunction","uploadFile","deleteFile","getTempFileURL","downloadFile"].forEach(e=>{te[e]=function(){const e=process.env.UNI_CLOUD_PROVIDER.length>0?"应用有多个服务空间,请通过uniCloud.init方法指定要使用的服务空间":"应用未关联服务空间,请在cloudfunctions目录右键关联服务空间";return console.error(e),Promise.reject(new i({code:"SYS_ERR",message:e}))}})}var ne=te;export default ne;
|
|
|