H5-contact/node_modules/@dcloudio/uni-cloud/dist/uni-cloud.es.js

2 lines
116 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import e from"@/pages.json";"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 s=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}}(),s={},r=s.lib={},i=r.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)}},o=r.WordArray=i.extend({init:function(e,n){e=this.words=e||[],this.sigBytes=n!=t?n:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes,r=e.sigBytes;if(this.clamp(),s%4)for(var i=0;i<r;i++){var o=n[i>>>2]>>>24-i%4*8&255;t[s+i>>>2]|=o<<24-(s+i)%4*8}else for(i=0;i<r;i+=4)t[s+i>>>2]=n[i>>>2];return this.sigBytes+=r,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=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n,s=[],r=function(t){t=t;var n=987654321,s=4294967295;return function(){var r=((n=36969*(65535&n)+(n>>16)&s)<<16)+(t=18e3*(65535&t)+(t>>16)&s)&s;return r/=4294967296,(r+=.5)*(e.random()>.5?1:-1)}},i=0;i<t;i+=4){var a=r(4294967296*(n||e.random()));n=987654071*a(),s.push(4294967296*a()|0)}return new o.init(s,t)}}),a=s.enc={},c=a.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,s=[],r=0;r<n;r++){var i=t[r>>>2]>>>24-r%4*8&255;s.push((i>>>4).toString(16)),s.push((15&i).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s<t;s+=2)n[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new o.init(n,t/2)}},u=a.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,s=[],r=0;r<n;r++){var i=t[r>>>2]>>>24-r%4*8&255;s.push(String.fromCharCode(i))}return s.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s<t;s++)n[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new o.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)))}},d=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.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,s=n.words,r=n.sigBytes,i=this.blockSize,a=r/(4*i),c=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,u=e.min(4*c,r);if(c){for(var l=0;l<c;l+=i)this._doProcessBlock(s,l);var d=s.splice(0,c);n.sigBytes-=u}return new o.init(d,u)},clone:function(){var e=i.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=d.extend({cfg:i.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){d.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 h.HMAC.init(e,n).finalize(t)}}});var h=s.algo={};return s}(Math),n)})),r=s,i=(n((function(e,t){var n;e.exports=(n=r,function(e){var t=n,s=t.lib,r=s.WordArray,i=s.Hasher,o=t.algo,a=[];!function(){for(var t=0;t<64;t++)a[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=o.MD5=i.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var n=0;n<16;n++){var s=t+n,r=e[s];e[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8)}var i=this._hash.words,o=e[t+0],c=e[t+1],p=e[t+2],f=e[t+3],g=e[t+4],m=e[t+5],y=e[t+6],_=e[t+7],w=e[t+8],v=e[t+9],I=e[t+10],S=e[t+11],k=e[t+12],A=e[t+13],C=e[t+14],T=e[t+15],b=i[0],P=i[1],x=i[2],O=i[3];b=u(b,P,x,O,o,7,a[0]),O=u(O,b,P,x,c,12,a[1]),x=u(x,O,b,P,p,17,a[2]),P=u(P,x,O,b,f,22,a[3]),b=u(b,P,x,O,g,7,a[4]),O=u(O,b,P,x,m,12,a[5]),x=u(x,O,b,P,y,17,a[6]),P=u(P,x,O,b,_,22,a[7]),b=u(b,P,x,O,w,7,a[8]),O=u(O,b,P,x,v,12,a[9]),x=u(x,O,b,P,I,17,a[10]),P=u(P,x,O,b,S,22,a[11]),b=u(b,P,x,O,k,7,a[12]),O=u(O,b,P,x,A,12,a[13]),x=u(x,O,b,P,C,17,a[14]),b=l(b,P=u(P,x,O,b,T,22,a[15]),x,O,c,5,a[16]),O=l(O,b,P,x,y,9,a[17]),x=l(x,O,b,P,S,14,a[18]),P=l(P,x,O,b,o,20,a[19]),b=l(b,P,x,O,m,5,a[20]),O=l(O,b,P,x,I,9,a[21]),x=l(x,O,b,P,T,14,a[22]),P=l(P,x,O,b,g,20,a[23]),b=l(b,P,x,O,v,5,a[24]),O=l(O,b,P,x,C,9,a[25]),x=l(x,O,b,P,f,14,a[26]),P=l(P,x,O,b,w,20,a[27]),b=l(b,P,x,O,A,5,a[28]),O=l(O,b,P,x,p,9,a[29]),x=l(x,O,b,P,_,14,a[30]),b=d(b,P=l(P,x,O,b,k,20,a[31]),x,O,m,4,a[32]),O=d(O,b,P,x,w,11,a[33]),x=d(x,O,b,P,S,16,a[34]),P=d(P,x,O,b,C,23,a[35]),b=d(b,P,x,O,c,4,a[36]),O=d(O,b,P,x,g,11,a[37]),x=d(x,O,b,P,_,16,a[38]),P=d(P,x,O,b,I,23,a[39]),b=d(b,P,x,O,A,4,a[40]),O=d(O,b,P,x,o,11,a[41]),x=d(x,O,b,P,f,16,a[42]),P=d(P,x,O,b,y,23,a[43]),b=d(b,P,x,O,v,4,a[44]),O=d(O,b,P,x,k,11,a[45]),x=d(x,O,b,P,T,16,a[46]),b=h(b,P=d(P,x,O,b,p,23,a[47]),x,O,o,6,a[48]),O=h(O,b,P,x,_,10,a[49]),x=h(x,O,b,P,C,15,a[50]),P=h(P,x,O,b,m,21,a[51]),b=h(b,P,x,O,k,6,a[52]),O=h(O,b,P,x,f,10,a[53]),x=h(x,O,b,P,I,15,a[54]),P=h(P,x,O,b,c,21,a[55]),b=h(b,P,x,O,w,6,a[56]),O=h(O,b,P,x,T,10,a[57]),x=h(x,O,b,P,y,15,a[58]),P=h(P,x,O,b,A,21,a[59]),b=h(b,P,x,O,g,6,a[60]),O=h(O,b,P,x,S,10,a[61]),x=h(x,O,b,P,p,15,a[62]),P=h(P,x,O,b,v,21,a[63]),i[0]=i[0]+b|0,i[1]=i[1]+P|0,i[2]=i[2]+x|0,i[3]=i[3]+O|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296),o=s;n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>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=i.clone.call(this);return e._hash=this._hash.clone(),e}});function u(e,t,n,s,r,i,o){var a=e+(t&n|~t&s)+r+o;return(a<<i|a>>>32-i)+t}function l(e,t,n,s,r,i,o){var a=e+(t&s|n&~s)+r+o;return(a<<i|a>>>32-i)+t}function d(e,t,n,s,r,i,o){var a=e+(t^n^s)+r+o;return(a<<i|a>>>32-i)+t}function h(e,t,n,s,r,i,o){var a=e+(n^(t|~s))+r+o;return(a<<i|a>>>32-i)+t}t.MD5=i._createHelper(c),t.HmacMD5=i._createHmacHelper(c)}(Math),n.MD5)})),n((function(e,t){var n;e.exports=(n=r,void function(){var e=n,t=e.lib.Base,s=e.enc.Utf8;e.algo.HMAC=t.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 i=this._oKey=t.clone(),o=this._iKey=t.clone(),a=i.words,c=o.words,u=0;u<n;u++)a[u]^=1549556828,c[u]^=909522486;i.sigBytes=o.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}))),o=n((function(e,t){e.exports=r.enc.Utf8})),a=n((function(e,t){var n;e.exports=(n=r,function(){var e=n,t=e.lib.WordArray;function s(e,n,s){for(var r=[],i=0,o=0;o<n;o++)if(o%4){var a=s[e.charCodeAt(o-1)]<<o%4*2,c=s[e.charCodeAt(o)]>>>6-o%4*2;r[i>>>2]|=(a|c)<<24-i%4*8,i++}return t.create(r,i)}e.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,s=this._map;e.clamp();for(var r=[],i=0;i<n;i+=3)for(var o=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,a=0;a<4&&i+.75*a<n;a++)r.push(s.charAt(o>>>6*(3-a)&63));var c=s.charAt(64);if(c)for(;r.length%4;)r.push(c);return r.join("")},parse:function(e){var t=e.length,n=this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var i=0;i<n.length;i++)r[n.charCodeAt(i)]=i}var o=n.charAt(64);if(o){var a=e.indexOf(o);-1!==a&&(t=a)}return s(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),n.enc.Base64)})),c=a;const u="FUNCTION",l="OBJECT",d="CLIENT_DB",h="pending",p="fulfilled",f="rejected";function g(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function m(e){return"object"===g(e)}function y(e){return"function"==typeof e}function _(e){return function(){try{return e.apply(e,arguments)}catch(e){console.error(e)}}}const w="REJECTED",v="NOT_PENDING";class I{constructor({createPromise:e,retryRule:t=w}={}){this.createPromise=e,this.status=null,this.promise=null,this.retryRule=t}get needRetry(){if(!this.status)return!0;switch(this.retryRule){case w:return this.status===f;case v:return this.status!==h}}exec(){return this.needRetry?(this.status=h,this.promise=this.createPromise().then((e=>(this.status=p,Promise.resolve(e))),(e=>(this.status=f,Promise.reject(e)))),this.promise):this.promise}}function S(e){return e&&"string"==typeof e?JSON.parse(e):e}const k="development"===process.env.NODE_ENV,A=process.env.UNI_PLATFORM,C="true"===process.env.UNI_SECURE_NETWORK_ENABLE||!0===process.env.UNI_SECURE_NETWORK_ENABLE,T=S(process.env.UNI_SECURE_NETWORK_CONFIG),b="h5"===A?"web":"app-plus"===A||"app-harmony"===A?"app":A,P=S(process.env.UNICLOUD_DEBUG),x=S(process.env.UNI_CLOUD_PROVIDER)||[],O=process.env.RUN_BY_HBUILDERX;let E="";try{E=process.env.UNI_APP_ID||""}catch(e){}let L,R={};if("app"===b&&(R=uni._globalUniCloudObj?uni._globalUniCloudObj:uni._globalUniCloudObj={}),"mp-weixin"===b){const e=N();R=e._globalUniCloudObj?e._globalUniCloudObj:e._globalUniCloudObj={}}function U(e,t={}){var n,s;return n=R,s=e,Object.prototype.hasOwnProperty.call(n,s)||(R[e]=t),R[e]}function N(){return L||(L=function(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;function e(){return this}return void 0!==e()?e():new Function("return this")()}(),L)}const D=["invoke","success","fail","complete"],M=U("_globalUniCloudInterceptor");function q(e,t){M[e]||(M[e]={}),m(t)&&Object.keys(t).forEach((n=>{D.indexOf(n)>-1&&function(e,t,n){let s=M[e][t];s||(s=M[e][t]=[]),-1===s.indexOf(n)&&y(n)&&s.push(n)}(e,n,t[n])}))}function F(e,t){M[e]||(M[e]={}),m(t)?Object.keys(t).forEach((n=>{D.indexOf(n)>-1&&function(e,t,n){const s=M[e][t];if(!s)return;const r=s.indexOf(n);r>-1&&s.splice(r,1)}(e,n,t[n])})):delete M[e]}function K(e,t){return e&&0!==e.length?e.reduce(((e,n)=>e.then((()=>n(t)))),Promise.resolve()):Promise.resolve()}function j(e,t){return M[e]&&M[e][t]||[]}function B(e){q("callObject",e)}const $=U("_globalUniCloudListener"),H="response",W="needLogin",J="refreshToken",z="failover",V="clientdb",G="cloudfunction",Q="cloudobject";function Y(e){return $[e]||($[e]=[]),$[e]}function X(e,t){const n=Y(e);n.includes(t)||n.push(t)}function Z(e,t){const n=Y(e),s=n.indexOf(t);-1!==s&&n.splice(s,1)}function ee(e,t){const n=Y(e);for(let e=0;e<n.length;e++){(0,n[e])(t)}}let te,ne=!1;function se(){return te||(te=new Promise((e=>{ne&&e(),function t(){if("function"==typeof getCurrentPages){const t=getCurrentPages();t&&t[0]&&(ne=!0,e())}ne||setTimeout((()=>{t()}),30)}()})),te)}function re(e){const t={};for(const n in e){const s=e[n];y(s)&&(t[n]=_(s))}return t}class ie extends Error{constructor(e){const t=e.message||e.errMsg||"unknown system error";super(t),this.errMsg=t,this.code=this.errCode=e.code||e.errCode||"SYSTEM_ERROR",this.errSubject=this.subject=e.subject||e.errSubject,this.cause=e.cause,this.requestId=e.requestId}toJson(e=0){if(!(e>=10))return e++,{errCode:this.errCode,errMsg:this.errMsg,errSubject:this.errSubject,cause:this.cause&&this.cause.toJson?this.cause.toJson(e):this.cause}}}var oe={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(),connectSocket:e=>uni.connectSocket(e)};function ae(e){return e&&ae(e.__v_raw)||e}function ce(){return{token:oe.getStorageSync("uni_id_token")||oe.getStorageSync("uniIdToken"),tokenExpired:oe.getStorageSync("uni_id_token_expired")}}function ue({token:e,tokenExpired:t}={}){e&&oe.setStorageSync("uni_id_token",e),t&&oe.setStorageSync("uni_id_token_expired",t)}let le,de;function he(){return le||(le="mp-weixin"===b&&wx.canIUse("getAppBaseInfo")&&wx.canIUse("getDeviceInfo")?{...uni.getAppBaseInfo(),...uni.getDeviceInfo()}:uni.getSystemInfoSync()),le}function pe(){let e,t;try{if(uni.getLaunchOptionsSync){if(uni.getLaunchOptionsSync.toString().indexOf("not yet implemented")>-1)return;const{scene:n,channel:s}=uni.getLaunchOptionsSync();e=s,t=n}}catch(e){}return{channel:e,scene:t}}let fe={};function ge(){const e=uni.getLocale&&uni.getLocale()||"en";if(de)return{...fe,...de,locale:e,LOCALE:e};const t=he(),{deviceId:n,osName:s,uniPlatform:r,appId:i}=t,o=["appId","appLanguage","appName","appVersion","appVersionCode","appWgtVersion","browserName","browserVersion","deviceBrand","deviceId","deviceModel","deviceType","osName","osVersion","romName","romVersion","ua","hostName","hostVersion","uniPlatform","uniRuntimeVersion","uniRuntimeVersionCode","uniCompilerVersion","uniCompilerVersionCode"];for(const e in t)Object.hasOwnProperty.call(t,e)&&-1===o.indexOf(e)&&delete t[e];return de={PLATFORM:r,OS:s,APPID:i,DEVICEID:n,...pe(),...t},{...fe,...de,locale:e,LOCALE:e}}var me={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),i(n,t).toString()},wrappedRequest:function(e,t){return new Promise(((n,s)=>{t(Object.assign(e,{complete(e){e||(e={}),k&&"web"===b&&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){const n=e.data&&e.data.error&&e.data.error.code||"SYS_ERR",r=e.data&&e.data.error&&e.data.error.message||e.errMsg||"request:fail";return s(new ie({code:n,message:r,requestId:t}))}const r=e.data;if(r.error)return s(new ie({code:r.error.code,message:r.error.message,requestId:t}));r.result=r.data,r.requestId=t,delete r.data,n(r)}}))}))},toBase64:function(e){return c.stringify(o.parse(e))}};var ye=class{constructor(e){["spaceId","clientSecret"].forEach((t=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error(`${t} required`)})),this.config=Object.assign({},{endpoint:0===e.spaceId.indexOf("mp-")?"https://api.next.bspapp.com":"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=oe,this._getAccessTokenPromiseHub=new I({createPromise:()=>this.requestAuth(this.setupRequest({method:"serverless.auth.user.anonymousAuthorize",params:"{}"},"auth")).then((e=>{if(!e.result||!e.result.accessToken)throw new ie({code:"AUTH_FAILED",message:"获取accessToken失败"});this.setAccessToken(e.result.accessToken)})),retryRule:v})}get hasAccessToken(){return!!this.accessToken}setAccessToken(e){this.accessToken=e}requestWrapped(e){return me.wrappedRequest(e,this.adapter.request)}requestAuth(e){return this.requestWrapped(e)}request(e,t){return Promise.resolve().then((()=>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"]=me.sign(t.data,this.config.clientSecret),t}setupRequest(e,t){const n=Object.assign({},e,{spaceId:this.config.spaceId,timestamp:Date.now()}),s={"Content-Type":"application/json"};return"auth"!==t&&(n.token=this.accessToken,s["x-basement-token"]=this.accessToken),s["x-serverless-sign"]=me.sign(n,this.config.clientSecret),{url:this.config.requestUrl,method:"POST",data:n,dataType:"json",header:s}}getAccessToken(){return this._getAccessTokenPromiseHub.exec()}async authorize(){await 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),timeout:e.timeout})}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:s,fileType:r,onUploadProgress:i}){return new Promise(((o,a)=>{const c=this.adapter.uploadFile({url:e,formData:t,name:n,filePath:s,fileType:r,header:{"X-OSS-server-side-encrpytion":"AES256"},success(e){e&&e.statusCode<400?o(e):a(new ie({code:"UPLOAD_FAILED",message:"文件上传失败"}))},fail(e){a(new ie({code:e.code||"UPLOAD_FAILED",message:e.message||e.errMsg||"文件上传失败"}))}});"function"==typeof i&&c&&"function"==typeof c.onProgressUpdate&&c.onProgressUpdate((e=>{i({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))}async uploadFile({filePath:e,cloudPath:t,fileType:n="image",cloudPathAsRealPath:s=!1,onUploadProgress:r,config:i}){if("string"!==g(t))throw new ie({code:"INVALID_PARAM",message:"cloudPath必须为字符串类型"});if(!(t=t.trim()))throw new ie({code:"INVALID_PARAM",message:"cloudPath不可为空"});if(/:\/\//.test(t))throw new ie({code:"INVALID_PARAM",message:"cloudPath不合法"});const o=i&&i.envType||this.config.envType;if(s&&("/"!==t[0]&&(t="/"+t),t.indexOf("\\")>-1))throw new ie({code:"INVALID_PARAM",message:"使用cloudPath作为路径时cloudPath不可包含“\\”"});const a=(await this.getOSSUploadOptionsFromPath({env:o,filename:s?t.split("/").pop():t,fileId:s?t:void 0})).result,c="https://"+a.cdnDomain+"/"+a.ossPath,{securityToken:u,accessKeyId:l,signature:d,host:h,ossPath:p,id:f,policy:m,ossCallbackUrl:y}=a,_={"Cache-Control":"max-age=2592000","Content-Disposition":"attachment",OSSAccessKeyId:l,Signature:d,host:h,id:f,key:p,policy:m,success_action_status:200};if(u&&(_["x-oss-security-token"]=u),y){const e=JSON.stringify({callbackUrl:y,callbackBody:JSON.stringify({fileId:f,spaceId:this.config.spaceId}),callbackBodyType:"application/json"});_.callback=me.toBase64(e)}const w={url:"https://"+a.host,formData:_,fileName:"file",name:"file",filePath:e,fileType:n};if(await this.uploadFileToOSS(Object.assign({},w,{onUploadProgress:r})),y)return{success:!0,filePath:e,fileID:c};if((await this.reportOSSUpload({id:f})).success)return{success:!0,filePath:e,fileID:c};throw new ie({code:"UPLOAD_FAILED",message:"文件上传失败"})}getTempFileURL({fileList:e}={}){return new Promise(((t,n)=>{Array.isArray(e)&&0!==e.length||n(new ie({code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"})),this.getFileInfo({fileList:e}).then((n=>{t({fileList:e.map(((e,t)=>{const s=n.fileList[t];return{fileID:e,tempFileURL:s&&s.url||e}}))})}))}))}async getFileInfo({fileList:e}={}){if(!Array.isArray(e)||0===e.length)throw new ie({code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"});const t={method:"serverless.file.resource.info",params:JSON.stringify({id:e.map((e=>e.split("?")[0])).join(",")})};return{fileList:(await this.request(this.setupRequest(t))).result}}};var _e={init(e){const t=new ye(e),n={signInAnonymously:function(){return t.authorize()},getLoginState:function(){return Promise.resolve(!1)}};return t.auth=function(){return n},t.customAuth=t.auth,t}};const we="undefined"!=typeof location&&"http:"===location.protocol?"http:":"https:";var ve;!function(e){e.local="local",e.none="none",e.session="session"}(ve||(ve={}));var Ie=function(){},Se=n((function(e,t){var n;e.exports=(n=r,function(e){var t=n,s=t.lib,r=s.WordArray,i=s.Hasher,o=t.algo,a=[],c=[];!function(){function t(t){for(var n=e.sqrt(t),s=2;s<=n;s++)if(!(t%s))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var s=2,r=0;r<64;)t(s)&&(r<8&&(a[r]=n(e.pow(s,.5))),c[r]=n(e.pow(s,1/3)),r++),s++}();var u=[],l=o.SHA256=i.extend({_doReset:function(){this._hash=new r.init(a.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],a=n[4],l=n[5],d=n[6],h=n[7],p=0;p<64;p++){if(p<16)u[p]=0|e[t+p];else{var f=u[p-15],g=(f<<25|f>>>7)^(f<<14|f>>>18)^f>>>3,m=u[p-2],y=(m<<15|m>>>17)^(m<<13|m>>>19)^m>>>10;u[p]=g+u[p-7]+y+u[p-16]}var _=s&r^s&i^r&i,w=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),v=h+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&l^~a&d)+c[p]+u[p];h=d,d=l,l=a,a=o+v|0,o=i,i=r,r=s,s=v+(w+_)|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+a|0,n[5]=n[5]+l|0,n[6]=n[6]+d|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(l),t.HmacSHA256=i._createHmacHelper(l)}(Math),n.SHA256)})),ke=Se,Ae=n((function(e,t){e.exports=r.HmacSHA256}));const Ce=()=>{let e;if(!Promise){e=()=>{},e.promise={};const t=()=>{throw new ie({message:'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}const t=new Promise(((t,n)=>{e=(e,s)=>e?n(e):t(s)}));return e.promise=t,e};function Te(e){return void 0===e}function be(e){return"[object Null]"===Object.prototype.toString.call(e)}function Pe(e=""){return e.replace(/([\s\S]+)\s+(请前往云开发AI小助手查看问题.*)/,"$1")}function xe(e=32){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n=t.length;let s="";for(let r=0;r<e;r++)s+=t.charAt(Math.floor(Math.random()*n));return s}var Oe;function Ee(e){const t=(n=e,"[object Array]"===Object.prototype.toString.call(n)?e:[e]);var n;for(const e of t){const{isMatch:t,genAdapter:n,runtime:s}=e;if(t())return{adapter:n(),runtime:s}}}!function(e){e.WEB="web",e.WX_MP="wx_mp"}(Oe||(Oe={}));const Le={adapter:null,runtime:void 0},Re=["anonymousUuidKey"];class Ue extends Ie{constructor(){super(),Le.adapter.root.tcbObject||(Le.adapter.root.tcbObject={})}setItem(e,t){Le.adapter.root.tcbObject[e]=t}getItem(e){return Le.adapter.root.tcbObject[e]}removeItem(e){delete Le.adapter.root.tcbObject[e]}clear(){delete Le.adapter.root.tcbObject}}function Ne(e,t){switch(e){case"local":return t.localStorage||new Ue;case"none":return new Ue;default:return t.sessionStorage||new Ue}}class De{constructor(e){if(!this._storage){this._persistence=Le.adapter.primaryStorage||e.persistence,this._storage=Ne(this._persistence,Le.adapter);const t=`access_token_${e.env}`,n=`access_token_expire_${e.env}`,s=`refresh_token_${e.env}`,r=`anonymous_uuid_${e.env}`,i=`login_type_${e.env}`,o="device_id",a=`token_type_${e.env}`,c=`user_info_${e.env}`;this.keys={accessTokenKey:t,accessTokenExpireKey:n,refreshTokenKey:s,anonymousUuidKey:r,loginTypeKey:i,userInfoKey:c,deviceIdKey:o,tokenTypeKey:a}}}updatePersistence(e){if(e===this._persistence)return;const t="local"===this._persistence;this._persistence=e;const n=Ne(e,Le.adapter);for(const e in this.keys){const s=this.keys[e];if(t&&Re.includes(e))continue;const r=this._storage.getItem(s);Te(r)||be(r)||(n.setItem(s,r),this._storage.removeItem(s))}this._storage=n}setStore(e,t,n){if(!this._storage)return;const s={version:n||"localCachev1",content:t},r=JSON.stringify(s);try{this._storage.setItem(e,r)}catch(e){throw e}}getStore(e,t){try{if(!this._storage)return}catch(e){return""}t=t||"localCachev1";const n=this._storage.getItem(e);if(!n)return"";if(n.indexOf(t)>=0){return JSON.parse(n).content}return""}removeStore(e){this._storage.removeItem(e)}}const Me={},qe={};function Fe(e){return Me[e]}class Ke{constructor(e,t){this.data=t||null,this.name=e}}class je extends Ke{constructor(e,t){super("error",{error:e,data:t}),this.error=e}}const Be=new class{constructor(){this._listeners={}}on(e,t){return function(e,t,n){n[e]=n[e]||[],n[e].push(t)}(e,t,this._listeners),this}off(e,t){return function(e,t,n){if(n&&n[e]){const s=n[e].indexOf(t);-1!==s&&n[e].splice(s,1)}}(e,t,this._listeners),this}fire(e,t){if(e instanceof je)return console.error(e.error),this;const n="string"==typeof e?new Ke(e,t||{}):e;const s=n.name;if(this._listens(s)){n.target=this;const e=this._listeners[s]?[...this._listeners[s]]:[];for(const t of e)t.call(this,n)}return this}_listens(e){return this._listeners[e]&&this._listeners[e].length>0}};function $e(e,t){Be.on(e,t)}function He(e,t={}){Be.fire(e,t)}function We(e,t){Be.off(e,t)}const Je="loginStateChanged",ze="loginStateExpire",Ve="loginTypeChanged",Ge="anonymousConverted",Qe="refreshAccessToken";var Ye;!function(e){e.ANONYMOUS="ANONYMOUS",e.WECHAT="WECHAT",e.WECHAT_PUBLIC="WECHAT-PUBLIC",e.WECHAT_OPEN="WECHAT-OPEN",e.CUSTOM="CUSTOM",e.EMAIL="EMAIL",e.USERNAME="USERNAME",e.NULL="NULL"}(Ye||(Ye={}));class Xe{constructor(){this._fnPromiseMap=new Map}async run(e,t){let n=this._fnPromiseMap.get(e);return n||(n=new Promise((async(n,s)=>{try{await this._runIdlePromise();const s=t();n(await s)}catch(e){s(e)}finally{this._fnPromiseMap.delete(e)}})),this._fnPromiseMap.set(e,n)),n}_runIdlePromise(){return Promise.resolve()}}class Ze{constructor(e){this._singlePromise=new Xe,this._cache=Fe(e.env),this._baseURL=`https://${e.env}.ap-shanghai.tcb-api.tencentcloudapi.com`,this._reqClass=new Le.adapter.reqClass({timeout:e.timeout,timeoutMsg:`请求在${e.timeout/1e3}s内未完成已中断`,restrictedMethods:["post"]})}_getDeviceId(){if(this._deviceID)return this._deviceID;const{deviceIdKey:e}=this._cache.keys;let t=this._cache.getStore(e);return"string"==typeof t&&t.length>=16&&t.length<=48||(t=xe(),this._cache.setStore(e,t)),this._deviceID=t,t}async _request(e,t,n={}){const s={"x-request-id":xe(),"x-device-id":this._getDeviceId()};if(n.withAccessToken){const{tokenTypeKey:e}=this._cache.keys,t=await this.getAccessToken(),n=this._cache.getStore(e);s.authorization=`${n} ${t}`}return this._reqClass["get"===n.method?"get":"post"]({url:`${this._baseURL}${e}`,data:t,headers:s})}async _fetchAccessToken(){const{loginTypeKey:e,accessTokenKey:t,accessTokenExpireKey:n,tokenTypeKey:s}=this._cache.keys,r=this._cache.getStore(e);if(r&&r!==Ye.ANONYMOUS)throw new ie({code:"INVALID_OPERATION",message:"非匿名登录不支持刷新 access token"});const i=await this._singlePromise.run("fetchAccessToken",(async()=>(await this._request("/auth/v1/signin/anonymously",{},{method:"post"})).data)),{access_token:o,expires_in:a,token_type:c}=i;return this._cache.setStore(s,c),this._cache.setStore(t,o),this._cache.setStore(n,Date.now()+1e3*a),o}isAccessTokenExpired(e,t){let n=!0;return e&&t&&(n=t<Date.now()),n}async getAccessToken(){const{accessTokenKey:e,accessTokenExpireKey:t}=this._cache.keys,n=this._cache.getStore(e),s=this._cache.getStore(t);return this.isAccessTokenExpired(n,s)?this._fetchAccessToken():n}async refreshAccessToken(){const{accessTokenKey:e,accessTokenExpireKey:t,loginTypeKey:n}=this._cache.keys;return this._cache.removeStore(e),this._cache.removeStore(t),this._cache.setStore(n,Ye.ANONYMOUS),this.getAccessToken()}async getUserInfo(){return this._singlePromise.run("getUserInfo",(async()=>(await this._request("/auth/v1/user/me",{},{withAccessToken:!0,method:"get"})).data))}}const et=["auth.getJwt","auth.logout","auth.signInWithTicket","auth.signInAnonymously","auth.signIn","auth.fetchAccessTokenWithRefreshToken","auth.signUpWithEmailAndPassword","auth.activateEndUserMail","auth.sendPasswordResetEmail","auth.resetPasswordWithToken","auth.isUsernameRegistered"],tt={"X-SDK-Version":"1.3.5"};function nt(e,t,n){const s=e[t];e[t]=function(t){const r={},i={};n.forEach((n=>{const{data:s,headers:o}=n.call(e,t);Object.assign(r,s),Object.assign(i,o)}));const o=t.data;return o&&(()=>{var e;if(e=o,"[object FormData]"!==Object.prototype.toString.call(e))t.data={...o,...r};else for(const e in r)o.append(e,r[e])})(),t.headers={...t.headers||{},...i},s.call(e,t)}}function st(){const e=Math.random().toString(16).slice(2);return{data:{seqId:e},headers:{...tt,"x-seqid":e}}}class rt{constructor(e={}){var t;this.config=e,this._reqClass=new Le.adapter.reqClass({timeout:this.config.timeout,timeoutMsg:`请求在${this.config.timeout/1e3}s内未完成已中断`,restrictedMethods:["post"]}),this._cache=Fe(this.config.env),this._localCache=(t=this.config.env,qe[t]),this.oauth=new Ze(this.config),nt(this._reqClass,"post",[st]),nt(this._reqClass,"upload",[st]),nt(this._reqClass,"download",[st])}async post(e){return await this._reqClass.post(e)}async upload(e){return await this._reqClass.upload(e)}async download(e){return await this._reqClass.download(e)}async refreshAccessToken(){let e,t;this._refreshAccessTokenPromise||(this._refreshAccessTokenPromise=this._refreshAccessToken());try{e=await this._refreshAccessTokenPromise}catch(e){t=e}if(this._refreshAccessTokenPromise=null,this._shouldRefreshAccessTokenHook=null,t)throw t;return e}async _refreshAccessToken(){const{accessTokenKey:e,accessTokenExpireKey:t,refreshTokenKey:n,loginTypeKey:s,anonymousUuidKey:r}=this._cache.keys;this._cache.removeStore(e),this._cache.removeStore(t);let i=this._cache.getStore(n);if(!i)throw new ie({message:"未登录CloudBase"});const o={refresh_token:i},a=await this.request("auth.fetchAccessTokenWithRefreshToken",o);if(a.data.code){const{code:e}=a.data;if("SIGN_PARAM_INVALID"===e||"REFRESH_TOKEN_EXPIRED"===e||"INVALID_REFRESH_TOKEN"===e){if(this._cache.getStore(s)===Ye.ANONYMOUS&&"INVALID_REFRESH_TOKEN"===e){const e=this._cache.getStore(r),t=this._cache.getStore(n),s=await this.send("auth.signInAnonymously",{anonymous_uuid:e,refresh_token:t});return this.setRefreshToken(s.refresh_token),this._refreshAccessToken()}He(ze),this._cache.removeStore(n)}throw new ie({code:a.data.code,message:`刷新access token失败${a.data.code}`})}if(a.data.access_token)return He(Qe),this._cache.setStore(e,a.data.access_token),this._cache.setStore(t,a.data.access_token_expire+Date.now()),{accessToken:a.data.access_token,accessTokenExpire:a.data.access_token_expire};a.data.refresh_token&&(this._cache.removeStore(n),this._cache.setStore(n,a.data.refresh_token),this._refreshAccessToken())}async getAccessToken(){const{accessTokenKey:e,accessTokenExpireKey:t,refreshTokenKey:n}=this._cache.keys;if(!this._cache.getStore(n))throw new ie({message:"refresh token不存在登录状态异常"});let s=this._cache.getStore(e),r=this._cache.getStore(t),i=!0;return this._shouldRefreshAccessTokenHook&&!await this._shouldRefreshAccessTokenHook(s,r)&&(i=!1),(!s||!r||r<Date.now())&&i?this.refreshAccessToken():{accessToken:s,accessTokenExpire:r}}async request(e,t,n){const s=`x-tcb-trace_${this.config.env}`;let r="application/x-www-form-urlencoded";const i={action:e,env:this.config.env,dataVersion:"2019-08-16",...t};let o;if(-1===et.indexOf(e)&&(this._cache.keys,i.access_token=await this.oauth.getAccessToken()),"storage.uploadFile"===e){o=new FormData;for(let e in o)o.hasOwnProperty(e)&&void 0!==o[e]&&o.append(e,i[e]);r="multipart/form-data"}else{r="application/json",o={};for(let e in i)void 0!==i[e]&&(o[e]=i[e])}let a={headers:{"content-type":r}};n&&n.timeout&&(a.timeout=n.timeout),n&&n.onUploadProgress&&(a.onUploadProgress=n.onUploadProgress);const c=this._localCache.getStore(s);c&&(a.headers["X-TCB-Trace"]=c);const{parse:u,inQuery:l,search:d}=t;let h={env:this.config.env};u&&(h.parse=!0),l&&(h={...l,...h});let p=function(e,t,n={}){const s=/\?/.test(t);let r="";for(let e in n)""===r?!s&&(t+="?"):r+="&",r+=`${e}=${encodeURIComponent(n[e])}`;return/^http(s)?\:\/\//.test(t+=r)?t:`${e}${t}`}(we,"//tcb-api.tencentcloudapi.com/web",h);d&&(p+=d);const f=await this.post({url:p,data:o,...a}),g=f.header&&f.header["x-tcb-trace"];if(g&&this._localCache.setStore(s,g),200!==Number(f.status)&&200!==Number(f.statusCode)||!f.data)throw new ie({code:"NETWORK_ERROR",message:"network request error"});return f}async send(e,t={},n={}){const s=await this.request(e,t,{...n,onUploadProgress:t.onUploadProgress});if(("ACCESS_TOKEN_DISABLED"===s.data.code||"ACCESS_TOKEN_EXPIRED"===s.data.code)&&-1===et.indexOf(e)){await this.oauth.refreshAccessToken();const s=await this.request(e,t,{...n,onUploadProgress:t.onUploadProgress});if(s.data.code)throw new ie({code:s.data.code,message:Pe(s.data.message)});return s.data}if(s.data.code)throw new ie({code:s.data.code,message:Pe(s.data.message)});return s.data}setRefreshToken(e){const{accessTokenKey:t,accessTokenExpireKey:n,refreshTokenKey:s}=this._cache.keys;this._cache.removeStore(t),this._cache.removeStore(n),this._cache.setStore(s,e)}}const it={};function ot(e){return it[e]}class at{constructor(e){this.config=e,this._cache=Fe(e.env),this._request=ot(e.env)}setRefreshToken(e){const{accessTokenKey:t,accessTokenExpireKey:n,refreshTokenKey:s}=this._cache.keys;this._cache.removeStore(t),this._cache.removeStore(n),this._cache.setStore(s,e)}setAccessToken(e,t){const{accessTokenKey:n,accessTokenExpireKey:s}=this._cache.keys;this._cache.setStore(n,e),this._cache.setStore(s,t)}async refreshUserInfo(){const{data:e}=await this._request.send("auth.getUserInfo",{});return this.setLocalUserInfo(e),e}setLocalUserInfo(e){const{userInfoKey:t}=this._cache.keys;this._cache.setStore(t,e)}}class ct{constructor(e){if(!e)throw new ie({code:"PARAM_ERROR",message:"envId is not defined"});this._envId=e,this._cache=Fe(this._envId),this._request=ot(this._envId),this.setUserInfo()}linkWithTicket(e){if("string"!=typeof e)throw new ie({code:"PARAM_ERROR",message:"ticket must be string"});return this._request.send("auth.linkWithTicket",{ticket:e})}linkWithRedirect(e){e.signInWithRedirect()}updatePassword(e,t){return this._request.send("auth.updatePassword",{oldPassword:t,newPassword:e})}updateEmail(e){return this._request.send("auth.updateEmail",{newEmail:e})}updateUsername(e){if("string"!=typeof e)throw new ie({code:"PARAM_ERROR",message:"username must be a string"});return this._request.send("auth.updateUsername",{username:e})}async getLinkedUidList(){const{data:e}=await this._request.send("auth.getLinkedUidList",{});let t=!1;const{users:n}=e;return n.forEach((e=>{e.wxOpenId&&e.wxPublicId&&(t=!0)})),{users:n,hasPrimaryUid:t}}setPrimaryUid(e){return this._request.send("auth.setPrimaryUid",{uid:e})}unlink(e){return this._request.send("auth.unlink",{platform:e})}async update(e){const{nickName:t,gender:n,avatarUrl:s,province:r,country:i,city:o}=e,{data:a}=await this._request.send("auth.updateUserInfo",{nickName:t,gender:n,avatarUrl:s,province:r,country:i,city:o});this.setLocalUserInfo(a)}async refresh(){const e=await this._request.oauth.getUserInfo();return this.setLocalUserInfo(e),e}setUserInfo(){const{userInfoKey:e}=this._cache.keys,t=this._cache.getStore(e);["uid","loginType","openid","wxOpenId","wxPublicId","unionId","qqMiniOpenId","email","hasPassword","customUserId","nickName","gender","avatarUrl"].forEach((e=>{this[e]=t[e]})),this.location={country:t.country,province:t.province,city:t.city}}setLocalUserInfo(e){const{userInfoKey:t}=this._cache.keys;this._cache.setStore(t,e),this.setUserInfo()}}class ut{constructor(e){if(!e)throw new ie({code:"PARAM_ERROR",message:"envId is not defined"});this._cache=Fe(e);const{refreshTokenKey:t,accessTokenKey:n,accessTokenExpireKey:s}=this._cache.keys,r=this._cache.getStore(t),i=this._cache.getStore(n),o=this._cache.getStore(s);this.credential={refreshToken:r,accessToken:i,accessTokenExpire:o},this.user=new ct(e)}get isAnonymousAuth(){return this.loginType===Ye.ANONYMOUS}get isCustomAuth(){return this.loginType===Ye.CUSTOM}get isWeixinAuth(){return this.loginType===Ye.WECHAT||this.loginType===Ye.WECHAT_OPEN||this.loginType===Ye.WECHAT_PUBLIC}get loginType(){return this._cache.getStore(this._cache.keys.loginTypeKey)}}class lt extends at{async signIn(){this._cache.updatePersistence("local"),await this._request.oauth.getAccessToken(),He(Je),He(Ve,{env:this.config.env,loginType:Ye.ANONYMOUS,persistence:"local"});const e=new ut(this.config.env);return await e.user.refresh(),e}async linkAndRetrieveDataWithTicket(e){const{anonymousUuidKey:t,refreshTokenKey:n}=this._cache.keys,s=this._cache.getStore(t),r=this._cache.getStore(n),i=await this._request.send("auth.linkAndRetrieveDataWithTicket",{anonymous_uuid:s,refresh_token:r,ticket:e});if(i.refresh_token)return this._clearAnonymousUUID(),this.setRefreshToken(i.refresh_token),await this._request.refreshAccessToken(),He(Ge,{env:this.config.env}),He(Ve,{loginType:Ye.CUSTOM,persistence:"local"}),{credential:{refreshToken:i.refresh_token}};throw new ie({message:"匿名转化失败"})}_setAnonymousUUID(e){const{anonymousUuidKey:t,loginTypeKey:n}=this._cache.keys;this._cache.removeStore(t),this._cache.setStore(t,e),this._cache.setStore(n,Ye.ANONYMOUS)}_clearAnonymousUUID(){this._cache.removeStore(this._cache.keys.anonymousUuidKey)}}class dt extends at{async signIn(e){if("string"!=typeof e)throw new ie({code:"PARAM_ERROR",message:"ticket must be a string"});const{refreshTokenKey:t}=this._cache.keys,n=await this._request.send("auth.signInWithTicket",{ticket:e,refresh_token:this._cache.getStore(t)||""});if(n.refresh_token)return this.setRefreshToken(n.refresh_token),await this._request.refreshAccessToken(),He(Je),He(Ve,{env:this.config.env,loginType:Ye.CUSTOM,persistence:this.config.persistence}),await this.refreshUserInfo(),new ut(this.config.env);throw new ie({message:"自定义登录失败"})}}class ht extends at{async signIn(e,t){if("string"!=typeof e)throw new ie({code:"PARAM_ERROR",message:"email must be a string"});const{refreshTokenKey:n}=this._cache.keys,s=await this._request.send("auth.signIn",{loginType:"EMAIL",email:e,password:t,refresh_token:this._cache.getStore(n)||""}),{refresh_token:r,access_token:i,access_token_expire:o}=s;if(r)return this.setRefreshToken(r),i&&o?this.setAccessToken(i,o):await this._request.refreshAccessToken(),await this.refreshUserInfo(),He(Je),He(Ve,{env:this.config.env,loginType:Ye.EMAIL,persistence:this.config.persistence}),new ut(this.config.env);throw s.code?new ie({code:s.code,message:`邮箱登录失败: ${s.message}`}):new ie({message:"邮箱登录失败"})}async activate(e){return this._request.send("auth.activateEndUserMail",{token:e})}async resetPasswordWithToken(e,t){return this._request.send("auth.resetPasswordWithToken",{token:e,newPassword:t})}}class pt extends at{async signIn(e,t){if("string"!=typeof e)throw new ie({code:"PARAM_ERROR",message:"username must be a string"});"string"!=typeof t&&(t="",console.warn("password is empty"));const{refreshTokenKey:n}=this._cache.keys,s=await this._request.send("auth.signIn",{loginType:Ye.USERNAME,username:e,password:t,refresh_token:this._cache.getStore(n)||""}),{refresh_token:r,access_token_expire:i,access_token:o}=s;if(r)return this.setRefreshToken(r),o&&i?this.setAccessToken(o,i):await this._request.refreshAccessToken(),await this.refreshUserInfo(),He(Je),He(Ve,{env:this.config.env,loginType:Ye.USERNAME,persistence:this.config.persistence}),new ut(this.config.env);throw s.code?new ie({code:s.code,message:`用户名密码登录失败: ${s.message}`}):new ie({message:"用户名密码登录失败"})}}class ft{constructor(e){this.config=e,this._cache=Fe(e.env),this._request=ot(e.env),this._onAnonymousConverted=this._onAnonymousConverted.bind(this),this._onLoginTypeChanged=this._onLoginTypeChanged.bind(this),$e(Ve,this._onLoginTypeChanged)}get currentUser(){const e=this.hasLoginState();return e&&e.user||null}get loginType(){return this._cache.getStore(this._cache.keys.loginTypeKey)}anonymousAuthProvider(){return new lt(this.config)}customAuthProvider(){return new dt(this.config)}emailAuthProvider(){return new ht(this.config)}usernameAuthProvider(){return new pt(this.config)}async signInAnonymously(){return new lt(this.config).signIn()}async signInWithEmailAndPassword(e,t){return new ht(this.config).signIn(e,t)}signInWithUsernameAndPassword(e,t){return new pt(this.config).signIn(e,t)}async linkAndRetrieveDataWithTicket(e){this._anonymousAuthProvider||(this._anonymousAuthProvider=new lt(this.config)),$e(Ge,this._onAnonymousConverted);return await this._anonymousAuthProvider.linkAndRetrieveDataWithTicket(e)}async signOut(){if(this.loginType===Ye.ANONYMOUS)throw new ie({message:"匿名用户不支持登出操作"});const{refreshTokenKey:e,accessTokenKey:t,accessTokenExpireKey:n}=this._cache.keys,s=this._cache.getStore(e);if(!s)return;const r=await this._request.send("auth.logout",{refresh_token:s});return this._cache.removeStore(e),this._cache.removeStore(t),this._cache.removeStore(n),He(Je),He(Ve,{env:this.config.env,loginType:Ye.NULL,persistence:this.config.persistence}),r}async signUpWithEmailAndPassword(e,t){return this._request.send("auth.signUpWithEmailAndPassword",{email:e,password:t})}async sendPasswordResetEmail(e){return this._request.send("auth.sendPasswordResetEmail",{email:e})}onLoginStateChanged(e){$e(Je,(()=>{const t=this.hasLoginState();e.call(this,t)}));const t=this.hasLoginState();e.call(this,t)}onLoginStateExpired(e){$e(ze,e.bind(this))}onAccessTokenRefreshed(e){$e(Qe,e.bind(this))}onAnonymousConverted(e){$e(Ge,e.bind(this))}onLoginTypeChanged(e){$e(Ve,(()=>{const t=this.hasLoginState();e.call(this,t)}))}async getAccessToken(){return{accessToken:(await this._request.getAccessToken()).accessToken,env:this.config.env}}hasLoginState(){const{accessTokenKey:e,accessTokenExpireKey:t}=this._cache.keys,n=this._cache.getStore(e),s=this._cache.getStore(t);return this._request.oauth.isAccessTokenExpired(n,s)?null:new ut(this.config.env)}async isUsernameRegistered(e){if("string"!=typeof e)throw new ie({code:"PARAM_ERROR",message:"username must be a string"});const{data:t}=await this._request.send("auth.isUsernameRegistered",{username:e});return t&&t.isRegistered}getLoginState(){return Promise.resolve(this.hasLoginState())}async signInWithTicket(e){return new dt(this.config).signIn(e)}shouldRefreshAccessToken(e){this._request._shouldRefreshAccessTokenHook=e.bind(this)}getUserInfo(){return this._request.send("auth.getUserInfo",{}).then((e=>e.code?e:{...e.data,requestId:e.seqId}))}getAuthHeader(){const{refreshTokenKey:e,accessTokenKey:t}=this._cache.keys,n=this._cache.getStore(e);return{"x-cloudbase-credentials":this._cache.getStore(t)+"/@@/"+n}}_onAnonymousConverted(e){const{env:t}=e.data;t===this.config.env&&this._cache.updatePersistence(this.config.persistence)}_onLoginTypeChanged(e){const{loginType:t,persistence:n,env:s}=e.data;s===this.config.env&&(this._cache.updatePersistence(n),this._cache.setStore(this._cache.keys.loginTypeKey,t))}}const gt=function(e,t){t=t||Ce();const n=ot(this.config.env),{cloudPath:s,filePath:r,onUploadProgress:i,fileType:o="image"}=e;return n.send("storage.getUploadMetadata",{path:s}).then((e=>{const{data:{url:a,authorization:c,token:u,fileId:l,cosFileId:d},requestId:h}=e,p={key:s,signature:c,"x-cos-meta-fileid":d,success_action_status:"201","x-cos-security-token":u};n.upload({url:a,data:p,file:r,name:s,fileType:o,onUploadProgress:i}).then((e=>{201===e.statusCode?t(null,{fileID:l,requestId:h}):t(new ie({code:"STORAGE_REQUEST_FAIL",message:`STORAGE_REQUEST_FAIL: ${e.data}`}))})).catch((e=>{t(e)}))})).catch((e=>{t(e)})),t.promise},mt=function(e,t){t=t||Ce();const n=ot(this.config.env),{cloudPath:s}=e;return n.send("storage.getUploadMetadata",{path:s}).then((e=>{t(null,e)})).catch((e=>{t(e)})),t.promise},yt=function({fileList:e},t){if(t=t||Ce(),!e||!Array.isArray(e))return{code:"INVALID_PARAM",message:"fileList必须是非空的数组"};for(let t of e)if(!t||"string"!=typeof t)return{code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"};const n={fileid_list:e};return ot(this.config.env).send("storage.batchDeleteFile",n).then((e=>{e.code?t(null,e):t(null,{fileList:e.data.delete_list,requestId:e.requestId})})).catch((e=>{t(e)})),t.promise},_t=function({fileList:e},t){t=t||Ce(),e&&Array.isArray(e)||t(null,{code:"INVALID_PARAM",message:"fileList必须是非空的数组"});let n=[];for(let s of e)"object"==typeof s?(s.hasOwnProperty("fileID")&&s.hasOwnProperty("maxAge")||t(null,{code:"INVALID_PARAM",message:"fileList的元素必须是包含fileID和maxAge的对象"}),n.push({fileid:s.fileID,max_age:s.maxAge})):"string"==typeof s?n.push({fileid:s}):t(null,{code:"INVALID_PARAM",message:"fileList的元素必须是字符串"});const s={file_list:n};return ot(this.config.env).send("storage.batchGetDownloadUrl",s).then((e=>{e.code?t(null,e):t(null,{fileList:e.data.download_list,requestId:e.requestId})})).catch((e=>{t(e)})),t.promise},wt=async function({fileID:e},t){const n=(await _t.call(this,{fileList:[{fileID:e,maxAge:600}]})).fileList[0];if("SUCCESS"!==n.code)return t?t(n):new Promise((e=>{e(n)}));const s=ot(this.config.env);let r=n.download_url;if(r=encodeURI(r),!t)return s.download({url:r});t(await s.download({url:r}))},vt=function({name:e,data:t,query:n,parse:s,search:r,timeout:i},o){const a=o||Ce();let c;try{c=t?JSON.stringify(t):""}catch(e){return Promise.reject(e)}if(!e)return Promise.reject(new ie({code:"PARAM_ERROR",message:"函数名不能为空"}));const u={inQuery:n,parse:s,search:r,function_name:e,request_data:c};return ot(this.config.env).send("functions.invokeFunction",u,{timeout:i}).then((e=>{if(e.code)a(null,e);else{let t=e.data.response_data;if(s)a(null,{result:t,requestId:e.requestId});else try{t=JSON.parse(e.data.response_data),a(null,{result:t,requestId:e.requestId})}catch(e){a(new ie({message:"response data must be json"}))}}return a.promise})).catch((e=>{a(e)})),a.promise},It={timeout:15e3,persistence:"session"},St={};class kt{constructor(e){this.config=e||this.config,this.authObj=void 0}init(e){switch(Le.adapter||(this.requestClient=new Le.adapter.reqClass({timeout:e.timeout||5e3,timeoutMsg:`请求在${(e.timeout||5e3)/1e3}s内未完成已中断`})),this.config={...It,...e},!0){case this.config.timeout>6e5:console.warn("timeout大于可配置上限[10分钟],已重置为上限数值"),this.config.timeout=6e5;break;case this.config.timeout<100:console.warn("timeout小于可配置下限[100ms],已重置为下限数值"),this.config.timeout=100}return new kt(this.config)}auth({persistence:e}={}){if(this.authObj)return this.authObj;const t=e||Le.adapter.primaryStorage||It.persistence;var n;return t!==this.config.persistence&&(this.config.persistence=t),function(e){const{env:t}=e;Me[t]=new De(e),qe[t]=new De({...e,persistence:"local"})}(this.config),n=this.config,it[n.env]=new rt(n),this.authObj=new ft(this.config),this.authObj}on(e,t){return $e.apply(this,[e,t])}off(e,t){return We.apply(this,[e,t])}callFunction(e,t){return vt.apply(this,[e,t])}deleteFile(e,t){return yt.apply(this,[e,t])}getTempFileURL(e,t){return _t.apply(this,[e,t])}downloadFile(e,t){return wt.apply(this,[e,t])}uploadFile(e,t){return gt.apply(this,[e,t])}getUploadMetadata(e,t){return mt.apply(this,[e,t])}registerExtension(e){St[e.name]=e}async invokeExtension(e,t){const n=St[e];if(!n)throw new ie({message:`扩展${e} 必须先注册`});return await n.invoke(t,this)}useAdapters(e){const{adapter:t,runtime:n}=Ee(e)||{};t&&(Le.adapter=t),n&&(Le.runtime=n)}}var At=new kt;function Ct(e,t,n){void 0===n&&(n={});var s=/\?/.test(t),r="";for(var i in n)""===r?!s&&(t+="?"):r+="&",r+=i+"="+encodeURIComponent(n[i]);return/^http(s)?:\/\//.test(t+=r)?t:""+e+t}class Tt{get(e){const{url:t,data:n,headers:s,timeout:r}=e;return new Promise(((e,i)=>{oe.request({url:Ct("https:",t),data:n,method:"GET",header:s,timeout:r,success(t){e(t)},fail(e){i(e)}})}))}post(e){const{url:t,data:n,headers:s,timeout:r}=e;return new Promise(((e,i)=>{oe.request({url:Ct("https:",t),data:n,method:"POST",header:s,timeout:r,success(t){e(t)},fail(e){i(e)}})}))}upload(e){return new Promise(((t,n)=>{const{url:s,file:r,data:i,headers:o,fileType:a}=e,c=oe.uploadFile({url:Ct("https:",s),name:"file",formData:Object.assign({},i),filePath:r,fileType:a,header:o,success(e){const n={statusCode:e.statusCode,data:e.data||{}};200===e.statusCode&&i.success_action_status&&(n.statusCode=parseInt(i.success_action_status,10)),t(n)},fail(e){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 bt={setItem(e,t){oe.setStorageSync(e,t)},getItem:e=>oe.getStorageSync(e),removeItem(e){oe.removeStorageSync(e)},clear(){oe.clearStorageSync()}};var Pt={genAdapter:function(){return{root:{},reqClass:Tt,localStorage:bt,primaryStorage:"local"}},isMatch:function(){return!0},runtime:"uni_app"};At.useAdapters(Pt);const xt=At,Ot=xt.init;xt.init=function(e){e.env=e.spaceId;const t=Ot.call(this,e);t.config.provider="tencent",t.config.spaceId=e.spaceId;const n=t.auth;return t.auth=function(e){const t=n.call(this,e);return["linkAndRetrieveDataWithTicket","signInAnonymously","signOut","getAccessToken","getLoginState","signInWithTicket","getUserInfo"].forEach((e=>{var n;t[e]=(n=t[e],function(e){e=e||{};const{success:t,fail:s,complete:r}=re(e);if(!(t||s||r))return n.call(this,e);n.call(this,e).then((e=>{t&&t(e),r&&r(e)}),(e=>{s&&s(e),r&&r(e)}))}).bind(t)})),t},t.customAuth=t.auth,t};var Et=xt;async function Lt(e,t){const n=`http://${e}:${t}/system/ping`;try{const e=await(s={url:n,timeout:500},new Promise(((e,t)=>{oe.request({...s,success(t){e(t)},fail(e){t(e)}})})));return!(!e.data||0!==e.data.code)}catch(e){return!1}var s}async function Rt(e,t){let n;for(let s=0;s<e.length;s++){const r=e[s];if(await Lt(r,t)){n=r;break}}return{address:n,port:t}}const Ut={"serverless.file.resource.generateProximalSign":"storage/generate-proximal-sign","serverless.file.resource.report":"storage/report","serverless.file.resource.delete":"storage/delete","serverless.file.resource.getTempFileURL":"storage/get-temp-file-url","system/check-storage":"system/check-storage"};var Nt=class{constructor(e){if(["spaceId","clientSecret"].forEach((t=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error(`${t} required`)})),!e.endpoint)throw new Error("集群空间未配置ApiEndpoint配置后需要重新关联服务空间后生效");this.config=Object.assign({},e),this.config.provider="dcloud",this.config.requestUrl=this.config.endpoint+"/client",this.config.envType=this.config.envType||"public",this.adapter=oe}async request(e,t=!0){const n=k&&t;return Promise.resolve().then((()=>n?this.requestLocal(e):me.wrappedRequest(this.setupRequest(e),this.adapter.request)))}async requestLocal(e){const t=await this.setupLocalRequest({method:"system/check-storage",platform:b,provider:this.config.provider,spaceId:this.config.spaceId});return new Promise((e=>{this.adapter.request(Object.assign({},t,{success:t=>{e(t)},fail:()=>{e({data:{code:"NETWORK_ERROR",message:"连接本地调试服务失败,请检查客户端是否和主机在同一局域网下,自动切换为已部署的云函数。"}})}}))})).then((({data:e}={})=>{const{code:t,message:n}=e||{};return{code:0===t?0:t||"SYS_ERR",message:n||"SYS_ERR"}})).then((({code:t,message:n})=>0!==t?(console.error(t,n),me.wrappedRequest(this.setupRequest(e),this.adapter.request)):new Promise(((t,n)=>{this.setupLocalRequest(e).then((e=>{this.adapter.request(Object.assign(e,{complete(e){if(e||(e={}),!e.statusCode||e.statusCode>=400){const t=e.data&&e.data.code||"SYS_ERR",s=e.data&&e.data.message||"request:fail";return n(new ie({code:t,message:s}))}const s=e.data;if(s.error)return n(new ie({code:s.error.code,message:s.error.message}));t({success:!0,result:s})}}))}))}))))}setupRequest(e){const t=Object.assign({},e,{spaceId:this.config.spaceId,timestamp:Date.now()}),n={"Content-Type":"application/json"};n["x-serverless-sign"]=me.sign(t,this.config.clientSecret);const s=ge();n["x-client-info"]=encodeURIComponent(JSON.stringify(s));const{token:r}=ce();return n["x-client-token"]=r,{url:this.config.requestUrl,method:"POST",data:t,dataType:"json",header:JSON.parse(JSON.stringify(n))}}async setupLocalRequest(e){const t=ge(),{token:n}=ce(),s=Object.assign({},e,{spaceId:this.config.spaceId,timestamp:Date.now(),clientInfo:t,token:n}),{address:r,servePort:i}=this.__dev__&&this.__dev__.debugInfo||{},{address:o}=await Rt(r,i);return{url:`http://${o}:${i}/${Ut[e.method]}`,method:"POST",data:s,dataType:"json",header:JSON.parse(JSON.stringify({"Content-Type":"application/json"}))}}callFunction(e){const t={method:"serverless.function.runtime.invoke",params:JSON.stringify({functionTarget:e.name,functionArgs:e.data||{}})};return this.request(t,!1)}getUploadFileOptions(e){const t={method:"serverless.file.resource.generateProximalSign",params:JSON.stringify(e)};return this.request(t)}reportUploadFile(e){const t={method:"serverless.file.resource.report",params:JSON.stringify(e)};return this.request(t)}uploadFile({filePath:e,cloudPath:t,fileType:n="image",onUploadProgress:s}){if(!t)throw new ie({code:"CLOUDPATH_REQUIRED",message:"cloudPath不可为空"});let r;return this.getUploadFileOptions({cloudPath:t}).then((t=>{const{url:i,formData:o,name:a}=t.result;return r=t.result.fileUrl,new Promise(((t,r)=>{const c=this.adapter.uploadFile({url:i,formData:o,name:a,filePath:e,fileType:n,success(e){e&&e.statusCode<400?t(e):r(new ie({code:"UPLOAD_FAILED",message:"文件上传失败"}))},fail(e){r(new ie({code:e.code||"UPLOAD_FAILED",message:e.message||e.errMsg||"文件上传失败"}))}});"function"==typeof s&&c&&"function"==typeof c.onProgressUpdate&&c.onProgressUpdate((e=>{s({loaded:e.totalBytesSent,total:e.totalBytesExpectedToSend})}))}))})).then((()=>this.reportUploadFile({cloudPath:t}))).then((t=>new Promise(((n,s)=>{t.success?n({success:!0,filePath:e,fileID:r}):s(new ie({code:"UPLOAD_FAILED",message:"文件上传失败"}))}))))}deleteFile({fileList:e}){const t={method:"serverless.file.resource.delete",params:JSON.stringify({fileList:e})};return this.request(t).then((e=>{if(e.success)return e.result;throw new ie({code:"DELETE_FILE_FAILED",message:"删除文件失败"})}))}getTempFileURL({fileList:e,maxAge:t}={}){if(!Array.isArray(e)||0===e.length)throw new ie({code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"});const n={method:"serverless.file.resource.getTempFileURL",params:JSON.stringify({fileList:e,maxAge:t})};return this.request(n).then((e=>{if(e.success)return{fileList:e.result.fileList.map((e=>({fileID:e.fileID,tempFileURL:e.tempFileURL})))};throw new ie({code:"GET_TEMP_FILE_URL_FAILED",message:"获取临时文件链接失败"})}))}};var Dt={init(e){const t=new Nt(e),n={signInAnonymously:function(){return Promise.resolve()},getLoginState:function(){return Promise.resolve(!1)}};return t.auth=function(){return n},t.customAuth=t.auth,t}},Mt=n((function(e,t){e.exports=r.enc.Hex}));function qt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}function Ft(e){return`${e}.api-hz.cloudbasefunction.cn`}function Kt(e="",t={}){const{data:n,functionName:s,method:r,headers:i,signHeaderKeys:o=[],endpoint:a,config:c}=t,u=String(Date.now()),l=qt(),d=Object.assign({},i,{"x-from-app-id":c.spaceAppId,"x-from-env-id":c.spaceId,"x-to-env-id":c.spaceId,"x-from-instance-id":u,"x-from-function-name":s,"x-client-timestamp":u,"x-alipay-source":"client","x-request-id":l,"x-alipay-callid":l,"x-trace-id":l}),h=["x-from-app-id","x-from-env-id","x-to-env-id","x-from-instance-id","x-from-function-name","x-client-timestamp"].concat(o),[p="",f=""]=e.split("?")||[],g=function(e){const t=e.signedHeaders.join(";"),n=e.signedHeaders.map((t=>`${t.toLowerCase()}:${e.headers[t]}\n`)).join(""),s=ke(e.body).toString(Mt),r=`${e.method.toUpperCase()}\n${e.path}\n${e.query}\n${n}\n${t}\n${s}\n`,i=ke(r).toString(Mt),o=`HMAC-SHA256\n${e.timestamp}\n${i}\n`,a=Ae(o,e.secretKey).toString(Mt);return`HMAC-SHA256 Credential=${e.secretId}, SignedHeaders=${t}, Signature=${a}`}({path:p,query:f,method:r,headers:d,timestamp:u,body:JSON.stringify(n),secretId:c.accessKey,secretKey:c.secretKey,signedHeaders:h.sort()});return{url:`${a||c.endpoint}${e}`,headers:Object.assign({},d,{Authorization:g})}}function jt({url:e,data:t,method:n="POST",headers:s={},timeout:r}){return new Promise(((i,o)=>{oe.request({url:e,method:n,data:"object"==typeof t?JSON.stringify(t):t,header:s,dataType:"json",timeout:r,complete:(e={})=>{const t=s["x-trace-id"]||"";if(!e.statusCode||e.statusCode>=400){const{message:n,errMsg:s,trace_id:r}=e.data||{};return o(new ie({code:"SYS_ERR",message:n||s||"request:fail",requestId:r||t}))}i({status:e.statusCode,data:e.data,headers:e.header,requestId:t})}})}))}function Bt(e,t){const{path:n,data:s,method:r="GET"}=e,{url:i,headers:o}=Kt(n,{functionName:"",data:s,method:r,headers:{"x-alipay-cloud-mode":"oss","x-data-api-type":"oss","x-expire-timestamp":String(Date.now()+6e4)},signHeaderKeys:["x-data-api-type","x-expire-timestamp"],config:t,endpoint:`https://${Ft(t.spaceId)}`});return jt({url:i,data:s,method:r,headers:o}).then((e=>{const t=e.data||{};if(!t.success)throw new ie({code:e.errCode,message:e.errMsg,requestId:e.requestId});return t.data||{}})).catch((e=>{throw new ie({code:e.errCode,message:e.errMsg,requestId:e.requestId})}))}function $t(e=""){const t=e.trim().replace(/^cloud:\/\//,""),n=t.indexOf("/");if(n<=0)throw new ie({code:"INVALID_PARAM",message:"fileID不合法"});const s=t.substring(0,n),r=t.substring(n+1);return s!==this.config.spaceId&&console.warn("file ".concat(e," does not belong to env ").concat(this.config.spaceId)),r}function Ht(e=""){return"cloud://".concat(this.config.spaceId,"/").concat(e.replace(/^\/+/,""))}class Wt{constructor(e){this.config=e}signedURL(e,t={}){const n=`/ws/function/${e}`,s=this.config.wsEndpoint.replace(/^ws(s)?:\/\//,""),r=Object.assign({},t,{accessKeyId:this.config.accessKey,signatureNonce:qt(),timestamp:""+Date.now()}),i=[n,["accessKeyId","authorization","signatureNonce","timestamp"].sort().map((function(e){return r[e]?"".concat(e,"=").concat(r[e]):null})).filter(Boolean).join("&"),`host:${s}`].join("\n"),o=["HMAC-SHA256",ke(i).toString(Mt)].join("\n"),a=Ae(o,this.config.secretKey).toString(Mt),c=Object.keys(r).map((e=>`${e}=${encodeURIComponent(r[e])}`)).join("&");return`${this.config.wsEndpoint}${n}?${c}&signature=${a}`}}class Jt{constructor(e){this.config=e}signedURL(e,t={}){const n=`/ws/sse/function/${e}`,s=this.config.endpoint.replace(/^http(s)?:\/\//,""),r=Object.assign({},t,{accessKeyId:this.config.accessKey,signatureNonce:qt(),timestamp:""+Date.now()}),i=["accessKeyId","authorization","signatureNonce","timestamp"].sort().map((function(e){return r[e]?"".concat(e,"=").concat(r[e]):null})).filter(Boolean).join("&"),o=[n.replace("/ws",""),i,`host:${s}`].join("\n"),a=["HMAC-SHA256",ke(o).toString(Mt)].join("\n"),c=Ae(a,this.config.secretKey).toString(Mt),u=Object.keys(r).map((e=>`${e}=${encodeURIComponent(r[e])}`)).join("&");return`${this.config.endpoint}${n}?${u}&signature=${c}`}}var zt=class{constructor(e){if(["spaceId","spaceAppId","accessKey","secretKey"].forEach((t=>{if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error(`${t} required`)})),e.endpoint){if("string"!=typeof e.endpoint)throw new Error("endpoint must be string");if(!/^https:\/\//.test(e.endpoint))throw new Error("endpoint must start with https://");e.endpoint=e.endpoint.replace(/\/$/,"")}this.config=Object.assign({},e,{endpoint:e.endpoint||`https://${Ft(e.spaceId)}`,wsEndpoint:e.wsEndpoint||`wss://${Ft(e.spaceId)}`}),this._websocket=new Wt(this.config),this._sse=new Jt(this.config)}callFunction(e){return function(e,t){const{name:n,data:s,async:r=!1,timeout:i}=e,o="POST",a={"x-to-function-name":n};r&&(a["x-function-invoke-type"]="async");const{url:c,headers:u}=Kt("/functions/invokeFunction",{functionName:n,data:s,method:o,headers:a,signHeaderKeys:["x-to-function-name"],config:t});return jt({url:c,data:s,method:o,headers:u,timeout:i}).then((e=>{let t=0;if(r){const n=e.data||{};t="200"===n.errCode?0:n.errCode,e.data=n.data||{},e.errMsg=n.errMsg}if(0!==t)throw new ie({code:t,message:e.errMsg,requestId:e.requestId});return{errCode:t,success:0===t,requestId:e.requestId,result:e.data}})).catch((e=>{throw new ie({code:e.errCode,message:e.errMsg,requestId:e.requestId})}))}(e,this.config)}uploadFileToOSS({url:e,filePath:t,fileType:n,formData:s,onUploadProgress:r}){return new Promise(((i,o)=>{const a=oe.uploadFile({url:e,filePath:t,fileType:n,formData:s,name:"file",success(e){e&&e.statusCode<400?i(e):o(new ie({code:"UPLOAD_FAILED",message:"文件上传失败"}))},fail(e){o(new ie({code:e.code||"UPLOAD_FAILED",message:e.message||e.errMsg||"文件上传失败"}))}});"function"==typeof r&&a&&"function"==typeof a.onProgressUpdate&&a.onProgressUpdate((e=>{r({loaded:e.totalBytesSent,total:e.totalBytesExpectedToSend})}))}))}async uploadFile({filePath:e,cloudPath:t="",fileType:n="image",onUploadProgress:s}){if("string"!==g(t))throw new ie({code:"INVALID_PARAM",message:"cloudPath必须为字符串类型"});if(!(t=t.trim()))throw new ie({code:"INVALID_PARAM",message:"cloudPath不可为空"});if(/:\/\//.test(t))throw new ie({code:"INVALID_PARAM",message:"cloudPath不合法"});const r=await Bt({path:"/".concat(t.replace(/^\//,""),"?post_url")},this.config),{file_id:i,upload_url:o,form_data:a}=r,c=a&&a.reduce(((e,t)=>(e[t.key]=t.value,e)),{});return this.uploadFileToOSS({url:o,filePath:e,fileType:n,formData:c,onUploadProgress:s}).then((()=>({fileID:i})))}async getTempFileURL({fileList:e}){return new Promise(((t,n)=>{(!e||e.length<0)&&t({code:"INVALID_PARAM",message:"fileList不能为空数组"}),e.length>50&&t({code:"INVALID_PARAM",message:"fileList数组长度不能超过50"});const s=[];for(const n of e){let e;"string"!==g(n)&&t({code:"INVALID_PARAM",message:"fileList的元素必须是非空的字符串"});try{e=$t.call(this,n)}catch(t){console.warn(t.errCode,t.errMsg),e=n}s.push({file_id:e,expire:600})}Bt({path:"/?download_url",data:{file_list:s},method:"POST"},this.config).then((e=>{const{file_list:n=[]}=e;t({fileList:n.map((e=>({fileID:Ht.call(this,e.file_id),tempFileURL:e.download_url})))})})).catch((e=>n(e)))}))}async connectWebSocket(e){const{name:t,query:n}=e;return oe.connectSocket({url:this._websocket.signedURL(t,n),complete:()=>{}})}requestSSE(e){const{name:t,data:n}=e;return oe.request({method:"POST",url:this._sse.signedURL(t),data:n,header:{"content-type":"application/json"},dataType:"json"})}};var Vt={init:e=>{e.provider="alipay";const t=new zt(e);return t.auth=function(){return{signInAnonymously:function(){return Promise.resolve()},getLoginState:function(){return Promise.resolve(!0)}}},t}};function Gt({data:e}){let t;t=ge();const n=JSON.parse(JSON.stringify(e||{}));if(Object.assign(n,{clientInfo:t}),!n.uniIdToken){const{token:e}=ce();e&&(n.uniIdToken=e)}return n}const Qt={enable:!1,interval:0,space:{}};let Yt=null,Xt=0,Zt=!1;function en(){return Array.isArray(x)&&x.length?x[0]:{}}function tn(e){return`${e}_${en().spaceId||"default"}`}function nn(){if(Yt)return Yt;try{const e=oe.getStorageSync(tn("UNICLOUD_FAILOVER_CONFIG"));if(m(e))return Yt=e,e}catch(e){}return null}function sn(e){Xt=e;try{oe.setStorageSync(tn("UNICLOUD_FAILOVER_LAST_REQUEST"),e)}catch(e){}}function rn(e){if(null===e||e<0)return!1;if(0===e)return!0;const t=function(){if(Xt)return Xt;try{const e=oe.getStorageSync(tn("UNICLOUD_FAILOVER_LAST_REQUEST"));if(e&&"number"==typeof e)return Xt=e,e}catch(e){}return 0}();if(!t)return!0;return Date.now()-t>=e}async function on(){const e=en(),{failoverEndpoint:t}=e;if(!t)return null;if(Zt)return nn();Zt=!0;try{const e=`${t}/.unicloud/failover-cfg.json`,n=await oe.request({url:e,method:"GET",dataType:"json",timeout:5e3});if(sn(Date.now()),200!==n.statusCode||!m(n.data))return null;const s={...Qt,...n.data},{enable:r=!1,interval:i=0,space:o={}}=s,a=nn(),c=a&&a.enable,u=function(e,t){if(!e)return t.enable;if(e.enable!==t.enable)return!0;if(e.interval!==t.interval)return!0;if(t._lastModifiedAt&&e._lastModifiedAt!==t._lastModifiedAt)return!0;if(JSON.stringify(e.space)!==JSON.stringify(t.space))return!0;return!1}(a,s);return function(e){try{Yt=e,e&&e.enable?oe.setStorageSync(tn("UNICLOUD_FAILOVER_CONFIG"),e):(oe.removeStorageSync(tn("UNICLOUD_FAILOVER_CONFIG")),oe.removeStorageSync(tn("UNICLOUD_FAILOVER_LAST_REQUEST")))}catch(e){}}({enable:r,interval:i,space:o,_lastModifiedAt:n.data._lastModifiedAt||Date.now()}),u&&ee(z,{isEnabled:r,hasStatusChanged:c!==r,failoverSpace:o}),s}catch(e){return nn()}finally{Zt=!1}}async function an(e={}){await this.__dev__.initLocalNetwork();const{localAddress:t,localPort:n}=this.__dev__,s=en(),r={aliyun:"aliyun",tencent:"tcb",alipay:"alipay",dcloud:"dcloud"}[s.provider],i=s.spaceId,o=`http://${t}:${n}/system/check-function`,a=`http://${t}:${n}/cloudfunctions/${e.name}`;return new Promise(((t,n)=>{oe.request({method:"POST",url:o,data:{name:e.name,platform:b,provider:r,spaceId:i},timeout:3e3,success(e){t(e)},fail(){t({data:{code:"NETWORK_ERROR",message:"连接本地调试服务失败,请检查客户端是否和主机在同一局域网下,自动切换为已部署的云函数。"}})}})})).then((({data:e}={})=>{const{code:t,message:n}=e||{};return{code:0===t?0:t||"SYS_ERR",message:n||"SYS_ERR"}})).then((({code:t,message:n})=>{if(0!==t){switch(t){case"MODULE_ENCRYPTED":console.error(`此云函数(${e.name})依赖加密公共模块不可本地调试,自动切换为云端已部署的云函数`);break;case"FUNCTION_ENCRYPTED":console.error(`此云函数(${e.name})已加密不可本地调试,自动切换为云端已部署的云函数`);break;case"ACTION_ENCRYPTED":console.error(n||"需要访问加密的uni-clientDB-action自动切换为云端环境");break;case"NETWORK_ERROR":console.error(n||"连接本地调试服务失败,请检查客户端是否和主机在同一局域网下");break;case"SWITCH_TO_CLOUD":break;default:{const e=`检测本地调试服务出现错误:${n},请检查网络环境或重启客户端再试`;throw console.error(e),new Error(e)}}return this._callCloudFunction(e)}return new Promise(((t,n)=>{const s=Gt.call(this,{data:e.data});oe.request({method:"POST",url:a,data:{provider:r,platform:b,param:s},timeout:e.timeout,success:({statusCode:e,data:s}={})=>!e||e>=400?n(new ie({code:s.code||"SYS_ERR",message:s.message||"request:fail"})):t({result:s}),fail(e){n(new ie({code:e.code||e.errCode||"SYS_ERR",message:e.message||e.errMsg||"request:fail"}))}})}))}))}const cn=[{rule:/fc_function_not_found|FUNCTION_NOT_FOUND/,content:",云函数[{functionName}]在云端不存在,请检查此云函数名称是否正确以及该云函数是否已上传到服务空间",mode:"append"}];var un=/[\\^$.*+?()[\]{}|]/g,ln=RegExp(un.source);function dn(e,t,n){return e.replace(new RegExp((s=t)&&ln.test(s)?s.replace(un,"\\$&"):s,"g"),n);var s}const hn="none",pn="request",fn="response",gn="both",mn={code:2e4,message:"System error"},yn={code:20101,message:"Invalid client"},_n={code:20102,message:"Get encrypt key failed"},wn={10001:"Secure network is not supported on current playground or unimpsdk",10003:"Config missing in current app. If the problem pesist, please contact DCloud.",10009:"Encrypt payload failed",10010:"Decrypt response failed"};function vn(e){const{errSubject:t,subject:n,errCode:s,errMsg:r,code:i,message:o,cause:a}=e||{};return new ie({subject:t||n||"uni-secure-network",code:s||i||mn.code,message:r||o,cause:a})}class In{constructor({secretType:e,uniCloudIns:t}={}){this.clientType="",this.secretType=e||hn,this.uniCloudIns=t;const{provider:n,spaceId:s}=this.uniCloudIns.config;var r;this.provider=n,this.spaceId=s,this.scopedGlobalCache=(r=this.uniCloudIns,U("_globalUniCloudSecureNetworkCache__{spaceId}".replace("{spaceId}",r.config.spaceId)))}getSystemInfo(){return this._systemInfo||(this._systemInfo=he()),this._systemInfo}get appId(){return this.getSystemInfo().appId}get deviceId(){return this.getSystemInfo().deviceId}async encryptData(e){return this.secretType===hn?e:this.platformEncryptData(e)}async decryptResult(e){if(this.secretType===hn)return e;const{errCode:t,errMsg:n,content:s}=e||{};return t||!s?e:this.secretType===pn?s:this.platformDecryptResult(e)}wrapVerifyClientCallFunction(e){const t=this;return async function({name:n,data:s={}}={}){await t.prepare(),(s=JSON.parse(JSON.stringify(s)))._uniCloudOptions=await t.platformGetSignOption();let r=await e({name:n,data:s});return t.isClientKeyNotFound(r)&&(await t.prepare({forceUpdate:!0}),s._uniCloudOptions=await t.platformGetSignOption(),r=await e({name:n,data:s})),r}}wrapEncryptDataCallFunction(e){const t=this;return async function({name:n,data:s={}}={}){await t.prepare();const r=await t.encryptData(s);let i=await e({name:n,data:r});if(t.isClientKeyNotFound(i)){await t.prepare({forceUpdate:!0});const r=await t.encryptData(s);i=await e({name:n,data:r})}return i.result=await t.decryptResult(i.result),i}}}n((function(e,t){var n,s,i,o,a,c,u,l;e.exports=(s=(n=l=r).lib,i=s.WordArray,o=s.Hasher,a=n.algo,c=[],u=a.SHA1=o.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],a=n[4],u=0;u<80;u++){if(u<16)c[u]=0|e[t+u];else{var l=c[u-3]^c[u-8]^c[u-14]^c[u-16];c[u]=l<<1|l>>>31}var d=(s<<5|s>>>27)+a+c[u];d+=u<20?1518500249+(r&i|~r&o):u<40?1859775393+(r^i^o):u<60?(r&i|r&o|i&o)-1894007588:(r^i^o)-899497514,a=o,o=i,i=r<<30|r>>>2,r=s,s=d}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+a|0},_doFinalize:function(){var e=this._data,t=e.words,n=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(n/4294967296),t[15+(s+64>>>9<<4)]=n,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),n.SHA1=o._createHelper(u),n.HmacSHA1=o._createHmacHelper(u),l.SHA1)})),n((function(e,t){var n;e.exports=(n=r,function(){var e=n,t=e.lib,s=t.Base,r=t.WordArray,i=e.algo,o=i.MD5,a=i.EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:o,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=this.cfg,s=n.hasher.create(),i=r.create(),o=i.words,a=n.keySize,c=n.iterations;o.length<a;){u&&s.update(u);var u=s.update(e).finalize(t);s.reset();for(var l=1;l<c;l++)u=s.finalize(u),s.reset();i.concat(u)}return i.sigBytes=4*a,i}});e.EvpKDF=function(e,t,n){return a.create(n).compute(e,t)}}(),n.EvpKDF)})),n((function(e,t){var n;e.exports=void((n=r).lib.Cipher||function(e){var t=n,s=t.lib,r=s.Base,i=s.WordArray,o=s.BufferedBlockAlgorithm,a=t.enc;a.Utf8;var c=a.Base64,u=t.algo.EvpKDF,l=s.Cipher=o.extend({cfg:r.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,n){this.cfg=this.cfg.extend(n),this._xformMode=e,this._key=t,this.reset()},reset:function(){o.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?w:y}return function(t){return{encrypt:function(n,s,r){return e(s).encrypt(t,n,s,r)},decrypt:function(n,s,r){return e(s).decrypt(t,n,s,r)}}}}()});s.StreamCipher=l.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var d=t.mode={},h=s.BlockCipherMode=r.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),p=d.CBC=function(){var t=h.extend();function n(t,n,s){var r=this._iv;if(r){var i=r;this._iv=e}else i=this._prevBlock;for(var o=0;o<s;o++)t[n+o]^=i[o]}return t.Encryptor=t.extend({processBlock:function(e,t){var s=this._cipher,r=s.blockSize;n.call(this,e,t,r),s.encryptBlock(e,t),this._prevBlock=e.slice(t,t+r)}}),t.Decryptor=t.extend({processBlock:function(e,t){var s=this._cipher,r=s.blockSize,i=e.slice(t,t+r);s.decryptBlock(e,t),n.call(this,e,t,r),this._prevBlock=i}}),t}(),f=(t.pad={}).Pkcs7={pad:function(e,t){for(var n=4*t,s=n-e.sigBytes%n,r=s<<24|s<<16|s<<8|s,o=[],a=0;a<s;a+=4)o.push(r);var c=i.create(o,s);e.concat(c)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}};s.BlockCipher=l.extend({cfg:l.cfg.extend({mode:p,padding:f}),reset:function(){l.reset.call(this);var e=this.cfg,t=e.iv,n=e.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=n.createEncryptor;else s=n.createDecryptor,this._minBufferSize=1;this._mode&&this._mode.__creator==s?this._mode.init(this,t&&t.words):(this._mode=s.call(n,this,t&&t.words),this._mode.__creator=s)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var g=s.CipherParams=r.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),m=(t.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,n=e.salt;if(n)var s=i.create([1398893684,1701076831]).concat(n).concat(t);else s=t;return s.toString(c)},parse:function(e){var t=c.parse(e),n=t.words;if(1398893684==n[0]&&1701076831==n[1]){var s=i.create(n.slice(2,4));n.splice(0,4),t.sigBytes-=16}return g.create({ciphertext:t,salt:s})}},y=s.SerializableCipher=r.extend({cfg:r.extend({format:m}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s),i=r.finalize(t),o=r.cfg;return g.create({ciphertext:i,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),_=(t.kdf={}).OpenSSL={execute:function(e,t,n,s){s||(s=i.random(8));var r=u.create({keySize:t+n}).compute(e,s),o=i.create(r.words.slice(t),4*n);return r.sigBytes=4*t,g.create({key:r,iv:o,salt:s})}},w=s.PasswordBasedCipher=y.extend({cfg:y.cfg.extend({kdf:_}),encrypt:function(e,t,n,s){var r=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize);s.iv=r.iv;var i=y.encrypt.call(this,e,t,r.key,s);return i.mixIn(r),i},decrypt:function(e,t,n,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var r=s.kdf.execute(n,e.keySize,e.ivSize,t.salt);return s.iv=r.iv,y.decrypt.call(this,e,t,r.key,s)}})}())}));var Sn=n((function(e,t){var n;e.exports=(n=r,function(){var e=n,t=e.lib.BlockCipher,s=e.algo,r=[],i=[],o=[],a=[],c=[],u=[],l=[],d=[],h=[],p=[];!function(){for(var e=[],t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;var n=0,s=0;for(t=0;t<256;t++){var f=s^s<<1^s<<2^s<<3^s<<4;f=f>>>8^255&f^99,r[n]=f,i[f]=n;var g=e[n],m=e[g],y=e[m],_=257*e[f]^16843008*f;o[n]=_<<24|_>>>8,a[n]=_<<16|_>>>16,c[n]=_<<8|_>>>24,u[n]=_,_=16843009*y^65537*m^257*g^16843008*n,l[f]=_<<24|_>>>8,d[f]=_<<16|_>>>16,h[f]=_<<8|_>>>24,p[f]=_,n?(n=g^e[e[e[y^g]]],s^=e[e[s]]):n=s=1}}();var f=[0,1,2,4,8,16,32,64,128,27,54],g=s.AES=t.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var e=this._keyPriorReset=this._key,t=e.words,n=e.sigBytes/4,s=4*((this._nRounds=n+6)+1),i=this._keySchedule=[],o=0;o<s;o++)if(o<n)i[o]=t[o];else{var a=i[o-1];o%n?n>6&&o%n==4&&(a=r[a>>>24]<<24|r[a>>>16&255]<<16|r[a>>>8&255]<<8|r[255&a]):(a=r[(a=a<<8|a>>>24)>>>24]<<24|r[a>>>16&255]<<16|r[a>>>8&255]<<8|r[255&a],a^=f[o/n|0]<<24),i[o]=i[o-n]^a}for(var c=this._invKeySchedule=[],u=0;u<s;u++)o=s-u,a=u%4?i[o]:i[o-4],c[u]=u<4||o<=4?a:l[r[a>>>24]]^d[r[a>>>16&255]]^h[r[a>>>8&255]]^p[r[255&a]]}},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,o,a,c,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,l,d,h,p,i),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,o,a){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],d=e[t+2]^n[2],h=e[t+3]^n[3],p=4,f=1;f<c;f++){var g=s[u>>>24]^r[l>>>16&255]^i[d>>>8&255]^o[255&h]^n[p++],m=s[l>>>24]^r[d>>>16&255]^i[h>>>8&255]^o[255&u]^n[p++],y=s[d>>>24]^r[h>>>16&255]^i[u>>>8&255]^o[255&l]^n[p++],_=s[h>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&d]^n[p++];u=g,l=m,d=y,h=_}g=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[d>>>8&255]<<8|a[255&h])^n[p++],m=(a[l>>>24]<<24|a[d>>>16&255]<<16|a[h>>>8&255]<<8|a[255&u])^n[p++],y=(a[d>>>24]<<24|a[h>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^n[p++],_=(a[h>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&d])^n[p++],e[t]=g,e[t+1]=m,e[t+2]=y,e[t+3]=_},keySize:8});e.AES=t._createHelper(g)}(),n.AES)})),kn=Sn,An=n((function(e,t){var n;e.exports=((n=r).pad.NoPadding={pad:function(){},unpad:function(){}},n.pad.NoPadding)}));function Cn(e,t){const n=c.parse(e);if(-1===[16,24,32].indexOf(n.sigBytes))throw new Error("invalid key size (must be 16, 24 or 32 bytes)");const s=o.parse(t);if(16!==s.sigBytes)throw new Error("invalid initialation vector size (must be 16 bytes)");return{key:n,ivBuffer:s}}function Tn(e,t){return e.words[t>>>2]>>>24-t%4*8&255}function bn(e,t,n){const{key:s,ivBuffer:r}=Cn(t,n);return kn.encrypt(o.parse(e),s,{iv:r}).ciphertext.toString(c)}function Pn(e,t,n){const s=c.parse(e);if(s.sigBytes%16!=0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");const{key:r,ivBuffer:i}=Cn(t,n);return function(e){if(e.sigBytes<16)throw new Error("PKCS#7 invalid length");const t=Tn(e,e.sigBytes-1);if(t>16)throw new Error("PKCS#7 padding byte out of range");const n=e.sigBytes-t;for(let s=0;s<t;s++)if(Tn(e,n+s)!==t)throw new Error("PKCS#7 invalid padding byte");return e.sigBytes=n,e.clamp(),e}(kn.decrypt({ciphertext:s},r,{iv:i,padding:An})).toString(o)}let xn,On,En=null;class Ln extends In{constructor(e){super(e),this.clientType="mp-weixin",this.userEncryptKey=null}isLogin(){return!!this.scopedGlobalCache.mpWeixinCode||!!this.scopedGlobalCache.mpWeixinOpenid}async prepare(){if(!this.isLogin()){if(!this.scopedGlobalCache.initPromise)throw new Error("`uniCloud.initSecureNetworkByWeixin` has not yet been called");if(await this.scopedGlobalCache.initPromise,!this.isLogin())throw new Error("uniCloud.initSecureNetworkByWeixin` has not yet been called or successfully excuted")}}async getUserEncryptKey(){if(this.userEncryptKey)return this.userEncryptKey;if(En&&En.expireTime){const e=Date.now();if(En.expireTime-e>0)return this.userEncryptKey=En,this.userEncryptKey}return new Promise(((e,t)=>{uni.getUserCryptoManager().getLatestUserKey({success:t=>{En=t,this.userEncryptKey=t,e(this.userEncryptKey)},fail:e=>{t(vn({..._n,cause:e}))}})}))}getWxAppId(){return wx.getAccountInfoSync().miniProgram.appId}async platformGetSignOption(){const{encryptKey:e,iv:t,version:n}=await this.getUserEncryptKey();return{verifyClientSign:bn(JSON.stringify({data:JSON.stringify({}),appId:this.appId,deviceId:this.deviceId,wxAppId:this.getWxAppId(),simulator:"devtools"===he().platform,timestamp:Date.now()}),e,t),encryptKeyId:n,mpWeixinCode:this.scopedGlobalCache.mpWeixinCode,mpWeixinOpenid:this.scopedGlobalCache.mpWeixinOpenid}}async platformEncryptData(e){const{encryptKey:t,iv:n,version:s}=await this.getUserEncryptKey(),r={secretType:this.secretType,encryptKeyId:s,mpWeixinCode:this.scopedGlobalCache.mpWeixinCode,mpWeixinOpenid:this.scopedGlobalCache.mpWeixinOpenid};return this.secretType===fn?{content:e,_uniCloudOptions:r}:{content:bn(JSON.stringify({data:JSON.stringify(e),appId:this.appId,deviceId:this.deviceId,wxAppId:this.getWxAppId(),simulator:"devtools"===he().platform,timestamp:Date.now()}),t,n),_uniCloudOptions:r}}async platformDecryptResult(e){const{content:t}=e,{encryptKey:n,iv:s}=await this.getUserEncryptKey();return JSON.parse(Pn(t,n,s))}isClientKeyNotFound(){return!1}}function Rn(e){const t=["hasClientKey","encryptGetClientKeyPayload","setClientKey","encrypt","decrypt"],n={};for(let s=0;s<t.length;s++){const r=t[s];n[r]=function(...t){return new Promise(((n,s)=>{"function"==typeof e[r]?e[r](...t,(function({type:e,data:t,errCode:r,errMsg:i,errSubject:o,message:a}={}){"success"===e?n(t):s(vn({errCode:r,errMsg:wn[r]||i||a,errSubject:o}))})):s(vn({message:"请检查manifest.json内是否开启安全网络模块另外注意标准基座不支持安全网络模块"}))}))}}return n}class Un extends In{constructor(e){super(e),this.clientType="app",this.appUtils={...Rn(uni.requireNativePlugin("plus"))},this.systemInfo=xn||(xn=he())}async hasClientKey(){return this._hasClientKey=await this.appUtils.hasClientKey({provider:this.provider,spaceId:this.spaceId}),this._hasClientKey}async getAppClientKey(){const{data:e,key:t}=await this.appUtils.encryptGetClientKeyPayload({data:JSON.stringify({})}),n=(await this.uniCloudIns.callFunction({name:"DCloud-clientDB",data:{redirectTo:"encryption",action:"getAppClientKey",data:e,key:t}})).result||{};if(0!==n.errCode)throw function(e){return new ie({subject:e.errSubject||"uni-secure-network",code:e.errCode||e.code||mn.code,message:e.errMsg||e.message||mn.message})}(n);const{clientKey:s,key:r}=n;await this.appUtils.setClientKey({provider:this.provider,spaceId:this.spaceId,clientKey:s,key:r})}async ensureClientKey({forceUpdate:e=!1}={}){if(!0!==await this.hasClientKey()||e)return e&&this.scopedGlobalCache.initPromise&&this.scopedGlobalCache.initStatus===h||!e&&this.scopedGlobalCache.initPromise&&this.scopedGlobalCache.initStatus!==f||(this.scopedGlobalCache.initPromise=this.getAppClientKey(),this.scopedGlobalCache.initPromise.then((e=>{this.scopedGlobalCache.initStatus=p})).catch((e=>{throw this.scopedGlobalCache.initStatus=f,e})),this.scopedGlobalCache.initStatus=h),this.scopedGlobalCache.initPromise}async prepare({forceUpdate:e=!1}={}){await this.ensureClientKey({forceUpdate:e})}async platformGetSignOption(){const{data:e,key:t}=await this.appUtils.encrypt({provider:this.provider,spaceId:this.spaceId,data:JSON.stringify({})});return{verifyClientSign:e,encryptKeyId:t}}async platformEncryptData(e){const{data:t,key:n}=await this.appUtils.encrypt({provider:this.provider,spaceId:this.spaceId,data:JSON.stringify(e)}),s={secretType:this.secretType,encryptKeyId:n};return this.secretType===fn?{content:e,_uniCloudOptions:s}:{content:t,_uniCloudOptions:s}}async platformDecryptResult(e){const{content:t,_uniCloudOptions:n={}}=e,s=n.encryptKeyId,r=await this.appUtils.decrypt({provider:this.provider,spaceId:this.spaceId,data:t,key:s});return JSON.parse(r.data)}isClientKeyNotFound(e={}){const t=e.result||{};return 70009===t.errCode&&"uni-secure-network"===t.errSubject}}function Nn({secretType:e}={}){return e===pn||e===fn||e===gn}function Dn({name:e,data:t={}}={}){return"app"===b&&"DCloud-clientDB"===e&&"encryption"===t.redirectTo&&"getAppClientKey"===t.action}function Mn({provider:e,spaceId:t,functionName:n}={}){const{appId:s,uniPlatform:r,osName:i}=he();let o=r;"app"===r&&(o=i);const a=function({provider:e,spaceId:t}={}){const n=T;if(!n)return{};e=function(e){return"tencent"===e?"tcb":e}(e);const s=n.find((n=>n.provider===e&&n.spaceId===t));return s&&s.config}({provider:e,spaceId:t});if(!a||!a.accessControl||!a.accessControl.enable)return!1;const c=a.accessControl.function||{},u=Object.keys(c);if(0===u.length)return!0;const l=function(e,t){let n,s,r;for(let i=0;i<e.length;i++){const o=e[i];o!==t?"*"!==o?o.split(",").map((e=>e.trim())).indexOf(t)>-1&&(s=o):r=o:n=o}return n||s||r}(u,n);if(!l)return!1;if((c[l]||[]).find(((e={})=>e.appId===s&&(e.platform||"").toLowerCase()===o.toLowerCase())))return!0;throw console.error(`此应用[appId: ${s}, platform: ${o}]不在云端配置的允许访问的应用列表内参考https://uniapp.dcloud.net.cn/uniCloud/secure-network.html#verify-client`),vn(yn)}function qn({functionName:e,result:t,logPvd:n}){if(k&&this.__dev__.debugLog&&t&&t.requestId){const s=JSON.stringify({spaceId:this.config.spaceId,functionName:e,requestId:t.requestId});console.log(`[${n}-request]${s}[/${n}-request]`)}}function Fn(e){const t=e.callFunction,n=function(n){const s=n.name;n.data=Gt.call(e,{data:n.data});const r={aliyun:"aliyun",tencent:"tcb",tcb:"tcb",alipay:"alipay",dcloud:"dcloud"}[this.config.provider],i=Nn(n),o=Dn(n),a=i||o;return t.call(this,n).then((e=>(e.errCode=0,!a&&qn.call(this,{functionName:s,result:e,logPvd:r}),Promise.resolve(e))),(e=>(!a&&qn.call(this,{functionName:s,result:e,logPvd:r}),e&&e.message&&(e.message=function({message:e="",extraInfo:t={},formatter:n=[]}={}){for(let s=0;s<n.length;s++){const{rule:r,content:i,mode:o}=n[s],a=e.match(r);if(!a)continue;let c=i;for(let e=1;e<a.length;e++)c=dn(c,`{$${e}}`,a[e]);for(const e in t)c=dn(c,`{${e}}`,t[e]);return"replace"===o?c:e+c}return e}({message:`[${n.name}]: ${e.message}`,formatter:cn,extraInfo:{functionName:s}})),Promise.reject(e))))};e.callFunction=function(t){const{provider:s,spaceId:r}=e.config,i=t.name;let o,a;if(t.data=t.data||{},k&&e.__dev__.debugInfo&&!e.__dev__.debugInfo.forceRemote&&x&&e._isDefault?(e._callCloudFunction||(e._callCloudFunction=n,e._callLocalFunction=an),o=an):o=n,o=o.bind(e),Dn(t))a=n.call(e,t);else if(function({name:e,data:t={}}){return"mp-weixin"===b&&"uni-id-co"===e&&"secureNetworkHandshakeByWeixin"===t.method}(t))a=o.call(e,t);else if(Nn(t)){a=new On({secretType:t.secretType,uniCloudIns:e}).wrapEncryptDataCallFunction(n.bind(e))(t)}else if(Mn({provider:s,spaceId:r,functionName:i})){a=new On({secretType:t.secretType,uniCloudIns:e}).wrapVerifyClientCallFunction(n.bind(e))(t)}else a=o(t);return Object.defineProperty(a,"result",{get:()=>(console.warn("当前返回结果为Promise类型不可直接访问其result属性详情请参考https://uniapp.dcloud.net.cn/uniCloud/faq?id=promise"),{})}),a.then((e=>e))}}On="mp-weixin"!==b&&"app"!==b?class{constructor(){throw vn({message:`Platform ${b} is not supported by secure network`})}}:C?"mp-weixin"===b?Ln:Un:class{constructor(){throw vn({message:`Platform ${b} is not enabled, please check whether secure network module is enabled in your manifest.json`})}};const Kn=Symbol("CLIENT_DB_INTERNAL");function jn(e,t){return e.then="DoNotReturnProxyWithAFunctionNamedThen",e._internalType=Kn,e.inspect=null,e.__v_raw=void 0,new Proxy(e,{get(e,n,s){if("_uniClient"===n)return null;if("symbol"==typeof n)return e[n];if(n in e||"string"!=typeof n){const t=e[n];return"function"==typeof t?t.bind(e):t}return t.get(e,n,s)}})}function Bn(e){return{on:(t,n)=>{e[t]=e[t]||[],e[t].indexOf(n)>-1||e[t].push(n)},off:(t,n)=>{e[t]=e[t]||[];const s=e[t].indexOf(n);-1!==s&&e[t].splice(s,1)}}}const $n=["db.Geo","db.command","command.aggregate"];function Hn(e,t){return $n.indexOf(`${e}.${t}`)>-1}function Wn(e){switch(g(e=ae(e))){case"array":return e.map((e=>Wn(e)));case"object":return e._internalType===Kn||Object.keys(e).forEach((t=>{e[t]=Wn(e[t])})),e;case"regexp":return{$regexp:{source:e.source,flags:e.flags}};case"date":return{$date:e.toISOString()};default:return e}}function Jn(e){return e&&e.content&&e.content.$method}class zn{constructor(e,t,n){this.content=e,this.prevStage=t||null,this.udb=null,this._database=n}toJSON(){let e=this;const t=[e.content];for(;e.prevStage;)e=e.prevStage,t.push(e.content);return{$db:t.reverse().map((e=>({$method:e.$method,$param:Wn(e.$param)})))}}toString(){return JSON.stringify(this.toJSON())}getAction(){const e=this.toJSON().$db.find((e=>"action"===e.$method));return e&&e.$param&&e.$param[0]}getCommand(){return{$db:this.toJSON().$db.filter((e=>"action"!==e.$method))}}get isAggregate(){let e=this;for(;e;){const t=Jn(e),n=Jn(e.prevStage);if("aggregate"===t&&"collection"===n||"pipeline"===t)return!0;e=e.prevStage}return!1}get isCommand(){let e=this;for(;e;){if("command"===Jn(e))return!0;e=e.prevStage}return!1}get isAggregateCommand(){let e=this;for(;e;){const t=Jn(e),n=Jn(e.prevStage);if("aggregate"===t&&"command"===n)return!0;e=e.prevStage}return!1}getNextStageFn(e){const t=this;return function(){return Vn({$method:e,$param:Wn(Array.from(arguments))},t,t._database)}}get count(){return this.isAggregate?this.getNextStageFn("count"):function(){return this._send("count",Array.from(arguments))}}get remove(){return this.isCommand?this.getNextStageFn("remove"):function(){return this._send("remove",Array.from(arguments))}}get(){return this._send("get",Array.from(arguments))}get add(){return this.isCommand?this.getNextStageFn("add"):function(){return this._send("add",Array.from(arguments))}}update(){return this._send("update",Array.from(arguments))}end(){return this._send("end",Array.from(arguments))}get set(){return this.isCommand?this.getNextStageFn("set"):function(){throw new Error("JQL禁止使用set方法")}}_send(e,t){const n=this.getAction(),s=this.getCommand();if(s.$db.push({$method:e,$param:Wn(t)}),k){const e=s.$db.find((e=>"collection"===e.$method)),t=e&&e.$param;t&&1===t.length&&"string"==typeof e.$param[0]&&e.$param[0].indexOf(",")>-1&&console.warn("检测到使用JQL语法联表查询时未使用getTemp先过滤主表数据在主表数据量大的情况下可能会查询缓慢。\n- 如何优化请参考此文档https://uniapp.dcloud.net.cn/uniCloud/jql?id=lookup-with-temp \n- 如果主表数据量很小请忽略此信息,项目发行时不会出现此提示。")}return this._database._callCloudFunction({action:n,command:s})}}function Vn(e,t,n){return jn(new zn(e,t,n),{get(e,t){let s="db";return e&&e.content&&(s=e.content.$method),Hn(s,t)?Vn({$method:t},e,n):function(){return Vn({$method:t,$param:Wn(Array.from(arguments))},e,n)}}})}function Gn({path:e,method:t}){return class{constructor(){this.param=Array.from(arguments)}toJSON(){return{$newDb:[...e.map((e=>({$method:e}))),{$method:t,$param:this.param}]}}toString(){return JSON.stringify(this.toJSON())}}}function Qn(e,t={}){return jn(new e(t),{get:(e,t)=>Hn("db",t)?Vn({$method:t},null,e):function(){return Vn({$method:t,$param:Wn(Array.from(arguments))},null,e)}})}class Yn extends class{constructor({uniClient:e={},isJQL:t=!1}={}){this._uniClient=e,this._authCallBacks={},this._dbCallBacks={},e._isDefault&&(this._dbCallBacks=U("_globalUniCloudDatabaseCallback")),t||(this.auth=Bn(this._authCallBacks)),this._isJQL=t,Object.assign(this,Bn(this._dbCallBacks)),this.env=jn({},{get:(e,t)=>({$env:t})}),this.Geo=jn({},{get:(e,t)=>Gn({path:["Geo"],method:t})}),this.serverDate=Gn({path:[],method:"serverDate"}),this.RegExp=Gn({path:[],method:"RegExp"})}getCloudEnv(e){if("string"!=typeof e||!e.trim())throw new Error("getCloudEnv参数错误");return{$env:e.replace("$cloudEnv_","")}}_callback(e,t){const n=this._dbCallBacks;n[e]&&n[e].forEach((e=>{e(...t)}))}_callbackAuth(e,t){const n=this._authCallBacks;n[e]&&n[e].forEach((e=>{e(...t)}))}multiSend(){const e=Array.from(arguments),t=e.map((e=>{const t=e.getAction(),n=e.getCommand();if("getTemp"!==n.$db[n.$db.length-1].$method)throw new Error("multiSend只支持子命令内使用getTemp");return{action:t,command:n}}));return this._callCloudFunction({multiCommand:t,queryList:e})}startTransaction(){throw new Error("JQL 事务仅支持在云端使用")}commit(){throw new Error("JQL 事务仅支持在云端使用")}rollback(){throw new Error("JQL 事务仅支持在云端使用")}}{_parseResult(e){return this._isJQL?e.result:e}_callCloudFunction({action:e,command:t,multiCommand:n,queryList:s}){function r(e,t){if(n&&s)for(let n=0;n<s.length;n++){const r=s[n];r.udb&&"function"==typeof r.udb.setResult&&(t?r.udb.setResult(t):r.udb.setResult(e.result.dataList[n]))}}const i=this,o=this._isJQL?"databaseForJQL":"database";function a(e){return i._callback("error",[e]),K(j(o,"fail"),e).then((()=>K(j(o,"complete"),e))).then((()=>(r(null,e),ee(H,{type:V,content:e}),Promise.reject(e))))}const c=K(j(o,"invoke")),u=this._uniClient;return c.then((()=>u.callFunction({name:"DCloud-clientDB",type:d,data:{action:e,command:t,multiCommand:n}}))).then((e=>{const{code:t,message:n,token:s,tokenExpired:c,systemInfo:u=[]}=e.result;if(u)for(let e=0;e<u.length;e++){const{level:t,message:n,detail:s}=u[e],r=console["app"===b&&"warn"===t?"error":t]||console.log;let i="[System Info]"+n;s&&(i=`${i}\n详细信息:${s}`),r(i)}if(t){return a(new ie({code:t,message:n,requestId:e.requestId}))}e.result.errCode=e.result.errCode||e.result.code,e.result.errMsg=e.result.errMsg||e.result.message,s&&c&&(ue({token:s,tokenExpired:c}),this._callbackAuth("refreshToken",[{token:s,tokenExpired:c}]),this._callback("refreshToken",[{token:s,tokenExpired:c}]),ee(J,{token:s,tokenExpired:c}));const l=[{prop:"affectedDocs",tips:"affectedDocs不再推荐使用请使用inserted/deleted/updated/data.length替代"},{prop:"code",tips:"code不再推荐使用请使用errCode替代"},{prop:"message",tips:"message不再推荐使用请使用errMsg替代"}];for(let t=0;t<l.length;t++){const{prop:n,tips:s}=l[t];if(n in e.result){const t=e.result[n];Object.defineProperty(e.result,n,{get:()=>(console.warn(s),t)})}}return function(e){return K(j(o,"success"),e).then((()=>K(j(o,"complete"),e))).then((()=>{r(e,null);const t=i._parseResult(e);return ee(H,{type:V,content:t}),Promise.resolve(t)}))}(e)}),(e=>{/fc_function_not_found|FUNCTION_NOT_FOUND/g.test(e.message)&&console.warn("clientDB未初始化请在web控制台保存一次schema以开启clientDB");return a(new ie({code:e.code||"SYSTEM_ERROR",message:e.message,requestId:e.requestId}))}))}}const Xn="token无效跳转登录页面",Zn="token过期跳转登录页面",es={TOKEN_INVALID_TOKEN_EXPIRED:Zn,TOKEN_INVALID_INVALID_CLIENTID:Xn,TOKEN_INVALID:Xn,TOKEN_INVALID_WRONG_TOKEN:Xn,TOKEN_INVALID_ANONYMOUS_USER:Xn},ts={"uni-id-token-expired":Zn,"uni-id-check-token-failed":Xn,"uni-id-token-not-exist":Xn,"uni-id-check-device-feature-failed":Xn},ns={...es,...ts,default:"用户未登录或登录状态过期,自动跳转登录页面"};function ss(e,t){let n="";return n=e?`${e}/${t}`:t,n.replace(/^\//,"")}function rs(e=[],t=""){const n=[],s=[];return e.forEach((e=>{!0===e.needLogin?n.push(ss(t,e.path)):!1===e.needLogin&&s.push(ss(t,e.path))})),{needLoginPage:n,notNeedLoginPage:s}}function is(e){return e.split("?")[0].replace(/^\//,"")}function os(){return function(e){let t=e&&e.$page&&e.$page.fullPath;return t?("/"!==t.charAt(0)&&(t="/"+t),t):""}(function(){const e=getCurrentPages();return e[e.length-1]}())}function as(){return is(os())}function cs(e="",t={}){if(!e)return!1;if(!(t&&t.list&&t.list.length))return!1;const n=t.list,s=is(e);return n.some((e=>e.pagePath===s))}const us=!!e.uniIdRouter;const{loginPage:ls,routerNeedLogin:ds,resToLogin:hs,needLoginPage:ps,notNeedLoginPage:fs,loginPageInTabBar:gs}=function({pages:t=[],subPackages:n=[],uniIdRouter:s={},tabBar:r={}}=e){const{loginPage:i,needLogin:o=[],resToLogin:a=!0}=s,{needLoginPage:c,notNeedLoginPage:u}=rs(t),{needLoginPage:l,notNeedLoginPage:d}=function(e=[]){const t=[],n=[];return e.forEach((e=>{const{root:s,pages:r=[]}=e,{needLoginPage:i,notNeedLoginPage:o}=rs(r,s);t.push(...i),n.push(...o)})),{needLoginPage:t,notNeedLoginPage:n}}(n);return{loginPage:i,routerNeedLogin:o,resToLogin:a,needLoginPage:[...c,...l],notNeedLoginPage:[...u,...d],loginPageInTabBar:cs(i,r)}}();if(ps.indexOf(ls)>-1)throw new Error(`Login page [${ls}] should not be "needLogin", please check your pages.json`);function ms(e){const t=as();if("/"===e.charAt(0))return e;const[n,s]=e.split("?"),r=n.replace(/^\//,"").split("/"),i=t.split("/");i.pop();for(let e=0;e<r.length;e++){const t=r[e];".."===t?i.pop():"."!==t&&i.push(t)}return""===i[0]&&i.shift(),"/"+i.join("/")+(s?"?"+s:"")}function ys(e,t){return new RegExp(t).test(e)}function _s({redirect:e}){const t=is(e),n=is(ls);return as()!==n&&t!==n}function ws({api:e,redirect:t}={}){if(!t||!_s({redirect:t}))return;const n=function(e,t){return"/"!==e.charAt(0)&&(e="/"+e),t?e.indexOf("?")>-1?e+`&uniIdRedirectUrl=${encodeURIComponent(t)}`:e+`?uniIdRedirectUrl=${encodeURIComponent(t)}`:e}(ls,t);gs?"navigateTo"!==e&&"redirectTo"!==e||(e="switchTab"):"switchTab"===e&&(e="navigateTo");const s={navigateTo:uni.navigateTo,redirectTo:uni.redirectTo,switchTab:uni.switchTab,reLaunch:uni.reLaunch};setTimeout((()=>{s[e]({url:n})}),0)}function vs({url:e}={}){const t={abortLoginPageJump:!1,autoToLoginPage:!1},n=function(){const{token:e,tokenExpired:t}=ce();let n;if(e){if(t<Date.now()){const e="uni-id-token-expired";n={errCode:e,errMsg:ns[e]}}}else{const e="uni-id-check-token-failed";n={errCode:e,errMsg:ns[e]}}return n}();if(function(e){const t=is(ms(e));return!(fs.indexOf(t)>-1)&&(ps.indexOf(t)>-1||ds.some((n=>ys(t,n)||ys(e,n))))}(e)&&n){n.uniIdRedirectUrl=e;if(Y(W).length>0)return setTimeout((()=>{ee(W,n)}),0),t.abortLoginPageJump=!0,t;t.autoToLoginPage=!0}return t}function Is(){const e=os(),{abortLoginPageJump:t,autoToLoginPage:n}=vs({url:e});t||n&&ws({api:"redirectTo",redirect:e})}function Ss(){Is();const e=["navigateTo","redirectTo","reLaunch","switchTab"];for(let t=0;t<e.length;t++){const n=e[t];uni.addInterceptor(n,{invoke(e){const{abortLoginPageJump:t,autoToLoginPage:s}=vs({url:e.url});return t?e:s?(ws({api:n,redirect:ms(e.url)}),!1):e}}),"web"===b&&window.addEventListener("popstate",(()=>{(0===getCurrentPages().length?(ne=!1,te=null,se()):Promise.resolve()).then((()=>{Is()}))}))}}function ks(){this.onResponse((e=>{const{type:t,content:n}=e;let s=!1;switch(t){case"cloudobject":s=function(e){if("object"!=typeof e)return!1;const{errCode:t}=e||{};return t in ns}(n);break;case"clientdb":s=function(e){if("object"!=typeof e)return!1;const{errCode:t}=e||{};return t in es}(n)}s&&function(e={}){const t=Y(W);se().then((()=>{const n=os();if(n&&_s({redirect:n}))return t.length>0?ee(W,Object.assign({uniIdRedirectUrl:n},e)):void(ls&&ws({api:"navigateTo",redirect:n}))}))}(n)}))}function As(e){e.onNeedLogin=function(e){X(W,e)},e.offNeedLogin=function(e){Z(W,e)},us&&(U("_globalUniCloudStatus").needLoginInit||(U("_globalUniCloudStatus").needLoginInit=!0,se().then((()=>{Ss.call(e)})),hs&&ks.call(e)))}function Cs(e){e.onFailover=function(e){X(z,e)},e.offFailover=function(e){Z(z,e)},e.refreshFailoverConfig=function(){return e.config,sn(0),on()},e.clearFailoverConfig=function(){!function(){Yt=null,Xt=0;try{oe.removeStorageSync(tn("UNICLOUD_FAILOVER_CONFIG")),oe.removeStorageSync(tn("UNICLOUD_FAILOVER_LAST_REQUEST"))}catch(e){}}()}}function Ts(e){!function(e){e.onResponse=function(e){X(H,e)},e.offResponse=function(e){Z(H,e)}}(e),As(e),function(e){e.onRefreshToken=function(e){X(J,e)},e.offRefreshToken=function(e){Z(J,e)}}(e),Cs(e)}const bs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Ps=/^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;function xs(e){return decodeURIComponent(function(e){if(e=String(e).replace(/[\t\n\f\r ]+/g,""),!Ps.test(e))throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");var t;e+="==".slice(2-(3&e.length));for(var n,s,r="",i=0;i<e.length;)t=bs.indexOf(e.charAt(i++))<<18|bs.indexOf(e.charAt(i++))<<12|(n=bs.indexOf(e.charAt(i++)))<<6|(s=bs.indexOf(e.charAt(i++))),r+=64===n?String.fromCharCode(t>>16&255):64===s?String.fromCharCode(t>>16&255,t>>8&255):String.fromCharCode(t>>16&255,t>>8&255,255&t);return r}(e).split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""))}function Os(){const e=ce().token||"",t=e.split(".");if(!e||3!==t.length)return{uid:null,role:[],permission:[],tokenExpired:0};let n;try{n=JSON.parse(xs(t[1]))}catch(e){throw new Error("获取当前用户信息出错,详细错误信息为:"+e.message)}return n.tokenExpired=1e3*n.exp,delete n.exp,delete n.iat,n}var Es=n((function(e,t){Object.defineProperty(t,"__esModule",{value:!0});const n="chooseAndUploadFile:ok",s="chooseAndUploadFile:fail";function r(e,t){return e.tempFiles.forEach(((e,n)=>{e.name||(e.name=e.path.substring(e.path.lastIndexOf("/")+1)),t&&(e.fileType=t),e.cloudPath=Date.now()+"_"+n+e.name.substring(e.name.lastIndexOf("."))})),e.tempFilePaths||(e.tempFilePaths=e.tempFiles.map((e=>e.path))),e}function i(e,t,{onChooseFile:s,onUploadProgress:r}){return t.then((e=>{if(s){const t=s(e);if(void 0!==t)return Promise.resolve(t).then((t=>void 0===t?e:t))}return e})).then((t=>!1===t?{errMsg:n,tempFilePaths:[],tempFiles:[]}:function(e,t,s=5,r){(t=Object.assign({},t)).errMsg=n;const i=t.tempFiles,o=i.length;let a=0;return new Promise((n=>{for(;a<s;)c();function c(){const s=a++;if(s>=o)return void(!i.find((e=>!e.url&&!e.errMsg))&&n(t));const u=i[s];e.uploadFile({provider:u.provider,filePath:u.path,cloudPath:u.cloudPath,fileType:u.fileType,cloudPathAsRealPath:u.cloudPathAsRealPath,onUploadProgress(e){e.index=s,e.tempFile=u,e.tempFilePath=u.path,r&&r(e)}}).then((e=>{u.url=e.fileID,s<o&&c()})).catch((e=>{u.errMsg=e.errMsg||e.message,s<o&&c()}))}}))}(e,t,5,r)))}t.initChooseAndUploadFile=function(e){return function(t={type:"all"}){return"image"===t.type?i(e,function(e){const{count:t,sizeType:n,sourceType:i=["album","camera"],extension:o}=e;return new Promise(((e,a)=>{uni.chooseImage({count:t,sizeType:n,sourceType:i,extension:o,success(t){e(r(t,"image"))},fail(e){a({errMsg:e.errMsg.replace("chooseImage:fail",s)})}})}))}(t),t):"video"===t.type?i(e,function(e){const{camera:t,compressed:n,maxDuration:i,sourceType:o=["album","camera"],extension:a}=e;return new Promise(((e,c)=>{uni.chooseVideo({camera:t,compressed:n,maxDuration:i,sourceType:o,extension:a,success(t){const{tempFilePath:n,duration:s,size:i,height:o,width:a}=t;e(r({errMsg:"chooseVideo:ok",tempFilePaths:[n],tempFiles:[{name:t.tempFile&&t.tempFile.name||"",path:n,size:i,type:t.tempFile&&t.tempFile.type||"",width:a,height:o,duration:s,fileType:"video",cloudPath:""}]},"video"))},fail(e){c({errMsg:e.errMsg.replace("chooseVideo:fail",s)})}})}))}(t),t):i(e,function(e){const{count:t,extension:n}=e;return new Promise(((e,i)=>{let o=uni.chooseFile;if("undefined"!=typeof wx&&"function"==typeof wx.chooseMessageFile&&(o=wx.chooseMessageFile),"function"!=typeof o)return i({errMsg:s+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});o({type:"all",count:t,extension:n,success(t){e(r(t))},fail(e){i({errMsg:e.errMsg.replace("chooseFile:fail",s)})}})}))}(t),t)}}})),Ls=t(Es);const Rs="manual";function Us(e){return{props:{localdata:{type:Array,default:()=>[]},options:{type:[Object,Array],default:()=>({})},spaceInfo:{type:Object,default:()=>({})},collection:{type:[String,Array],default:""},action:{type:String,default:""},field:{type:String,default:""},orderby:{type:String,default:""},where:{type:[String,Object],default:""},pageData:{type:String,default:"add"},pageCurrent:{type:Number,default:1},pageSize:{type:Number,default:20},getcount:{type:[Boolean,String],default:!1},gettree:{type:[Boolean,String],default:!1},gettreepath:{type:[Boolean,String],default:!1},startwith:{type:String,default:""},limitlevel:{type:Number,default:10},groupby:{type:String,default:""},groupField:{type:String,default:""},distinct:{type:[Boolean,String],default:!1},foreignKey:{type:String,default:""},loadtime:{type:String,default:"auto"},manual:{type:Boolean,default:!1}},data:()=>({mixinDatacomLoading:!1,mixinDatacomHasMore:!1,mixinDatacomResData:[],mixinDatacomErrorMessage:"",mixinDatacomPage:{},mixinDatacomError:null}),created(){this.mixinDatacomPage={current:this.pageCurrent,size:this.pageSize,count:0},this.$watch((()=>{var e=[];return["pageCurrent","pageSize","localdata","collection","action","field","orderby","where","getont","getcount","gettree","groupby","groupField","distinct"].forEach((t=>{e.push(this[t])})),e}),((e,t)=>{if(this.loadtime===Rs)return;let n=!1;const s=[];for(let r=2;r<e.length;r++)e[r]!==t[r]&&(s.push(e[r]),n=!0);e[0]!==t[0]&&(this.mixinDatacomPage.current=this.pageCurrent),this.mixinDatacomPage.size=this.pageSize,this.onMixinDatacomPropsChange(n,s)}))},methods:{onMixinDatacomPropsChange(e,t){},mixinDatacomEasyGet({getone:e=!1,success:t,fail:n}={}){this.mixinDatacomLoading||(this.mixinDatacomLoading=!0,this.mixinDatacomErrorMessage="",this.mixinDatacomError=null,this.mixinDatacomGet().then((n=>{this.mixinDatacomLoading=!1;const{data:s,count:r}=n.result;this.getcount&&(this.mixinDatacomPage.count=r),this.mixinDatacomHasMore=s.length<this.pageSize;const i=e?s.length?s[0]:void 0:s;this.mixinDatacomResData=i,t&&t(i)})).catch((e=>{this.mixinDatacomLoading=!1,this.mixinDatacomErrorMessage=e,this.mixinDatacomError=e,n&&n(e)})))},mixinDatacomGet(t={}){let n;t=t||{},n="undefined"!=typeof __uniX&&__uniX?e.databaseForJQL(this.spaceInfo):e.database(this.spaceInfo);const s=t.action||this.action;s&&(n=n.action(s));const r=t.collection||this.collection;n=Array.isArray(r)?n.collection(...r):n.collection(r);const i=t.where||this.where;i&&Object.keys(i).length&&(n=n.where(i));const o=t.field||this.field;o&&(n=n.field(o));const a=t.foreignKey||this.foreignKey;a&&(n=n.foreignKey(a));const c=t.groupby||this.groupby;c&&(n=n.groupBy(c));const u=t.groupField||this.groupField;u&&(n=n.groupField(u));!0===(void 0!==t.distinct?t.distinct:this.distinct)&&(n=n.distinct());const l=t.orderby||this.orderby;l&&(n=n.orderBy(l));const d=void 0!==t.pageCurrent?t.pageCurrent:this.mixinDatacomPage.current,h=void 0!==t.pageSize?t.pageSize:this.mixinDatacomPage.size,p=void 0!==t.getcount?t.getcount:this.getcount,f=void 0!==t.gettree?t.gettree:this.gettree,g=void 0!==t.gettreepath?t.gettreepath:this.gettreepath,m={getCount:p},y={limitLevel:void 0!==t.limitlevel?t.limitlevel:this.limitlevel,startWith:void 0!==t.startwith?t.startwith:this.startwith};return f&&(m.getTree=y),g&&(m.getTreePath=y),n=n.skip(h*(d-1)).limit(h).get(m),n}}}}function Ns(e){return function(t,n={}){n=function(e,t={}){return e.customUI=t.customUI||e.customUI,e.parseSystemError=t.parseSystemError||e.parseSystemError,Object.assign(e.loadingOptions,t.loadingOptions),Object.assign(e.errorOptions,t.errorOptions),"object"==typeof t.secretMethods&&(e.secretMethods=t.secretMethods),e}({customUI:!1,loadingOptions:{title:"加载中...",mask:!0},errorOptions:{type:"modal",retry:!1}},n);const{customUI:s,loadingOptions:r,errorOptions:i,parseSystemError:o}=n,a=!s;return new Proxy({},{get(s,c){switch(c){case"toString":return"[object UniCloudObject]";case"toJSON":return{}}return function({fn:e,interceptorName:t,getCallbackArgs:n}={}){return async function(...s){const r=n?n({params:s}):{};let i,o;try{return await K(j(t,"invoke"),{...r}),i=await e(...s),await K(j(t,"success"),{...r,result:i}),i}catch(e){throw o=e,await K(j(t,"fail"),{...r,error:o}),o}finally{await K(j(t,"complete"),o?{...r,error:o}:{...r,result:i})}}}({fn:async function s(...u){let d;a&&uni.showLoading({title:r.title,mask:r.mask});const h={name:t,type:l,data:{method:c,params:u}};"object"==typeof n.secretMethods&&function(e,t){const n=t.data.method,s=e.secretMethods||{},r=s[n]||s["*"];r&&(t.secretType=r)}(n,h);let p=!1;try{d=await e.callFunction(h)}catch(e){p=!0,d={result:new ie(e)}}const{errSubject:f,errCode:g,errMsg:m,newToken:y}=d.result||{};if(a&&uni.hideLoading(),y&&y.token&&y.tokenExpired&&(ue(y),ee(J,{...y})),g){let e=m;if(p&&o){e=(await o({objectName:t,methodName:c,params:u,errSubject:f,errCode:g,errMsg:m})).errMsg||m}if(a)if("toast"===i.type)uni.showToast({title:e,icon:"none"});else{if("modal"!==i.type)throw new Error(`Invalid errorOptions.type: ${i.type}`);{const{confirm:t}=await async function({title:e,content:t,showCancel:n,cancelText:s,confirmText:r}={}){return new Promise(((i,o)=>{uni.showModal({title:e,content:t,showCancel:n,cancelText:s,confirmText:r,success(e){i(e)},fail(){i({confirm:!1,cancel:!0})}})}))}({title:"提示",content:e,showCancel:i.retry,cancelText:"取消",confirmText:i.retry?"重试":"确定"});if(i.retry&&t)return s(...u)}}const n=new ie({subject:f,code:g,message:m,requestId:d.requestId});throw n.detail=d.result,ee(H,{type:Q,content:n}),n}return ee(H,{type:Q,content:d.result}),d.result},interceptorName:"callObject",getCallbackArgs:function({params:e}={}){return{objectName:t,methodName:c,params:e}}})}})}}function Ds(e){return U("_globalUniCloudSecureNetworkCache__{spaceId}".replace("{spaceId}",e.config.spaceId))}async function Ms({openid:e,callLoginByWeixin:t=!1}={}){const n=Ds(this);if("mp-weixin"!==b)throw new Error(`[SecureNetwork] API \`initSecureNetworkByWeixin\` is not supported on platform \`${b}\``);if(e&&t)throw new Error("[SecureNetwork] openid and callLoginByWeixin cannot be passed at the same time");if(e)return n.mpWeixinOpenid=e,{};const s=await new Promise(((e,t)=>{uni.login({success(t){e(t.code)},fail(e){t(new Error(e.errMsg))}})})),r=this.importObject("uni-id-co",{customUI:!0});return await r.secureNetworkHandshakeByWeixin({code:s,callLoginByWeixin:t}),n.mpWeixinCode=s,{code:s}}async function qs(e){const t=Ds(this);return t.initPromise||(t.initPromise=Ms.call(this,e).then((e=>e)).catch((e=>{throw delete t.initPromise,e}))),t.initPromise}function Fs(e){return function({openid:t,callLoginByWeixin:n=!1}={}){return qs.call(e,{openid:t,callLoginByWeixin:n})}}function Ks(e){!function(e){fe=e}(e)}function js(e){const t="mp-weixin"===b&&wx.canIUse("getAppBaseInfo"),n={getAppBaseInfo:t?uni.getAppBaseInfo:uni.getSystemInfo,getPushClientId:uni.getPushClientId};return function(s){return new Promise(((r,i)=>{t&&"getAppBaseInfo"===e?r(n[e]()):n[e]({...s,success(e){r(e)},fail(e){i(e)}})}))}}class Bs extends class{constructor(){this._callback={}}addListener(e,t){this._callback[e]||(this._callback[e]=[]),this._callback[e].push(t)}on(e,t){return this.addListener(e,t)}removeListener(e,t){if(!t)throw new Error('The "listener" argument must be of type function. Received undefined');const n=this._callback[e];if(!n)return;const s=function(e,t){for(let n=e.length-1;n>=0;n--)if(e[n]===t)return n;return-1}(n,t);n.splice(s,1)}off(e,t){return this.removeListener(e,t)}removeAllListener(e){delete this._callback[e]}emit(e,...t){const n=this._callback[e];if(n)for(let e=0;e<n.length;e++)n[e](...t)}}{constructor(){super(),this._uniPushMessageCallback=this._receivePushMessage.bind(this),this._currentMessageId=-1,this._payloadQueue=[]}init(){return Promise.all([js("getAppBaseInfo")(),js("getPushClientId")()]).then((([{appId:e}={},{cid:t}={}]=[])=>{if(!e)throw new Error("Invalid appId, please check the manifest.json file");if(!t)throw new Error("Invalid push client id");this._appId=e,this._pushClientId=t,this._seqId=Date.now()+"-"+Math.floor(9e5*Math.random()+1e5),this.emit("open"),this._initMessageListener()}),(e=>{throw this.emit("error",e),this.close(),e}))}async open(){return this.init()}_isUniCloudSSE(e){if("receive"!==e.type)return!1;const t=e&&e.data&&e.data.payload;return!(!t||"UNI_CLOUD_SSE"!==t.channel||t.seqId!==this._seqId)}_receivePushMessage(e){if(!this._isUniCloudSSE(e))return;const t=e&&e.data&&e.data.payload,{action:n,messageId:s,message:r}=t;this._payloadQueue.push({action:n,messageId:s,message:r}),this._consumMessage()}_consumMessage(){for(;;){const e=this._payloadQueue.find((e=>e.messageId===this._currentMessageId+1));if(!e)break;this._currentMessageId++,this._parseMessagePayload(e)}}_parseMessagePayload(e){const{action:t,messageId:n,message:s}=e;"end"===t?this._end({messageId:n,message:s}):"message"===t&&this._appendMessage({messageId:n,message:s})}_appendMessage({messageId:e,message:t}={}){this.emit("message",t)}_end({messageId:e,message:t}={}){this.emit("end",t),this.close()}_initMessageListener(){uni.onPushMessage(this._uniPushMessageCallback)}_destroy(){uni.offPushMessage(this._uniPushMessageCallback)}toJSON(){return{appId:this._appId,pushClientId:this._pushClientId,seqId:this._seqId}}close(){this._destroy(),this.emit("close")}}async function $s(e){if(!k)return Promise.resolve();if("app"===b){const{osName:e,osVersion:t}=he();"ios"===e&&function(e){if(!e||"string"!=typeof e)return 0;const t=e.match(/^(\d+)./);return t&&t[1]?parseInt(t[1]):0}(t)>=14&&console.warn("iOS 14及以上版本连接uniCloud本地调试服务需要允许客户端查找并连接到本地网络上的设备仅开发期间需要发行后不需要")}const t=e.__dev__;if(!t.debugInfo)return;const{address:n,servePort:s}=t.debugInfo,{address:r}=await Rt(n,s);if(r)return t.localAddress=r,void(t.localPort=s);const i=console["app"===b?"error":"warn"];let o="";if("remote"===t.debugInfo.initialLaunchType?(t.debugInfo.forceRemote=!0,o="当前客户端和HBuilderX不在同一局域网下或其他网络原因无法连接HBuilderXuniCloud本地调试服务不对当前客户端生效。\n- 如果不使用uniCloud本地调试服务请直接忽略此信息。\n- 如需使用uniCloud本地调试服务请将客户端与主机连接到同一局域网下并重新运行到客户端。"):o="无法连接uniCloud本地调试服务请检查当前客户端是否与主机在同一局域网下。\n- 如需使用uniCloud本地调试服务请将客户端与主机连接到同一局域网下并重新运行到客户端。",o+="\n- 如果在HBuilderX开启的状态下切换过网络环境请重启HBuilderX后再试\n- 检查系统防火墙是否拦截了HBuilderX自带的nodejs\n- 检查是否错误的使用拦截器修改uni.request方法的参数","web"===b&&(o+="\n- 部分浏览器开启节流模式之后访问本地地址受限,请检查是否启用了节流模式"),0===b.indexOf("mp-")&&(o+="\n- 小程序中如何使用uniCloud请参考https://uniapp.dcloud.net.cn/uniCloud/publish.html#useinmp"),!t.debugInfo.forceRemote)throw new Error(o);i(o)}function Hs(e){e._initPromiseHub||(e._initPromiseHub=new I({createPromise:function(){let t=Promise.resolve();var n;n=1,t=new Promise((e=>{setTimeout((()=>{e()}),n)}));const s=e.auth();return t.then((()=>s.getLoginState())).then((e=>e?Promise.resolve():s.signInAnonymously()))}}))}const Ws={tcb:Et,tencent:Et,aliyun:_e,private:Dt,dcloud:Dt,alipay:Vt};let Js=new class{init(e){let t={};const n=Ws[e.provider];if(!n)throw new Error("未提供正确的provider参数");t=n.init(e),k&&function(e){if(!k)return;const t={};e.__dev__=t,t.debugLog=k&&("web"===b&&navigator.userAgent.indexOf("HBuilderX")>0||"app"===b||"mp-harmony"===b);const n=P;n&&!n.code&&(t.debugInfo=n);const s=new I({createPromise:function(){return $s(e)}});t.initLocalNetwork=function(){return s.exec()}}(t),Hs(t),Fn(t),function(e){const t=e.uploadFile;e.uploadFile=function(e){return t.call(this,e)}}(t),function(e){e.database=function(t){if(t&&Object.keys(t).length>0)return e.init(t).database();if(this._database)return this._database;const n=Qn(Yn,{uniClient:e});return this._database=n,n},e.databaseForJQL=function(t){if(t&&Object.keys(t).length>0)return e.init(t).databaseForJQL();if(this._databaseForJQL)return this._databaseForJQL;const n=Qn(Yn,{uniClient:e,isJQL:!0});return this._databaseForJQL=n,n}}(t),function(e){e.getCurrentUserInfo=Os,e.chooseAndUploadFile=Ls.initChooseAndUploadFile(e),Object.assign(e,{get mixinDatacom(){return Us(e)}}),e.SSEChannel=Bs,e.initSecureNetworkByWeixin=Fs(e),e.setCustomClientInfo=Ks,e.importObject=Ns(e)}(t);return["callFunction","uploadFile","deleteFile","getTempFileURL","downloadFile","chooseAndUploadFile"].forEach((e=>{if(!t[e])return;const n=t[e];t[e]=function(){return n.apply(t,Array.from(arguments))},t[e]=function(e,t){return function(n){let s=!1;if("callFunction"===t){const e=n&&n.type||u;s=e!==u}const r="callFunction"===t&&!s,i=this._initPromiseHub.exec();n=n||{};const{success:o,fail:a,complete:c}=re(n),l=i.then((()=>s?Promise.resolve():K(j(t,"invoke"),n))).then((()=>e.call(this,n))).then((e=>s?Promise.resolve(e):K(j(t,"success"),e).then((()=>K(j(t,"complete"),e))).then((()=>(r&&ee(H,{type:G,content:e}),Promise.resolve(e))))),(e=>s?Promise.reject(e):K(j(t,"fail"),e).then((()=>K(j(t,"complete"),e))).then((()=>(ee(H,{type:G,content:e}),Promise.reject(e))))));if(!(o||a||c))return l;l.then((e=>{o&&o(e),c&&c(e),r&&ee(H,{type:G,content:e})}),(e=>{a&&a(e),c&&c(e),r&&ee(H,{type:G,content:e})}))}}(t[e],e).bind(t)})),t.init=this.init,t}};(()=>{const e=Array.isArray(x)?x.length:0,t=function(){const e=en(),t=nn();return t&&t.enable&&m(t.space)?t.space:e}();if(1===e)Js=Js.init(t),Js._isDefault=!0;else{const t=["database","getCurrentUserInfo","importObject"];let n;n=e>0?"应用有多个服务空间请通过uniCloud.init方法指定要使用的服务空间":O?"应用未关联服务空间请在uniCloud目录右键关联服务空间":"uni-app cli项目内使用uniCloud需要使用HBuilderX的运行菜单运行项目且需要在uniCloud目录关联服务空间",[...["auth","callFunction","uploadFile","deleteFile","getTempFileURL","downloadFile"],...t].forEach((e=>{Js[e]=function(){if(console.error(n),-1===t.indexOf(e))return Promise.reject(new ie({code:"SYS_ERR",message:n}));console.error(n)}}))}if(Object.assign(Js,{get mixinDatacom(){return Us(Js)}}),Ts(Js),Js.addInterceptor=q,Js.removeInterceptor=F,Js.interceptObject=B,k&&"web"===b&&(window.uniCloud=Js),"app"===b&&(uni.__uniCloud=Js),"app"===b||"web"===b){const e=N();e.uniCloud=Js,e.UniCloudError=ie}if("mp-weixin"===b){const e=N();e.uniCloud=e.uniCloud||Js,e.UniCloudError=e.UniCloudError||ie}!function(){const{failoverEndpoint:e}=en();if(!e)return;on().catch((e=>{console.error("请求故障切换配置失败:",e)}));const t={fail(){const e=nn();rn(e&&e.interval||0)&&on().catch((e=>{console.error("请求故障切换配置失败:",e)}))}};q("callFunction",t),q("database",t),q("uploadFile",t)}()})();let zs=ie;if("mp-weixin"===b){const e=N();Js=e.uniCloud,zs=e.UniCloudError}var Vs=Js;export{zs as UniCloudError,Vs as default,Js as uniCloud};