2 lines
32 KiB
JavaScript
Raw 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.

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.cloud={})}(this,function(e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}))(e,t)};function t(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var d=function(){return(d=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function r(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;0<=s;s--)(o=e[s])&&(a=(i<3?o(a):3<i?o(t,r,a):o(t,r))||a);3<i&&a&&Object.defineProperty(t,r,a)}function c(e,a,s,c){return new(s=s||Promise)(function(r,t){function n(e){try{i(c.next(e))}catch(e){t(e)}}function o(e){try{i(c.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?r(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(n,o)}i((c=c.apply(e,a||[])).next())})}function m(n,o){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(r){return function(e){var t=[r,e];if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))c.label=t[1];else if(6===t[0]&&c.label<s[1])c.label=s[1],s=t;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(t)}}t=o.call(n,c)}catch(e){t=[6,e],a=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}}function o(){return function(e,t,r){var a=r.value;r.value=function(t){var e,t=t||{},r=t.success,n=void 0===r?null:r,r=t.fail,o=void 0===r?null:r,r=t.complete,i=void 0===r?null:r,t=!i&&!o&&!n;try{e=a.apply(this,arguments)}catch(e){return t?Promise.reject(e):(o&&o(e),void(i&&i(e)))}if(e=e.then?e:Promise.resolve(e),t)return e;e.then(function(e){try{n&&n(e),i&&i(e)}catch(e){throw e}}).catch(function(e){o&&o(e),i&&i(e)})}}}function g(e,t,r){t=(t=Array.isArray(t)?t:t.split(".")).reduce(function(e,t){return e?e[t]:null},e);return r?t||r:t}function i(e,t){return e(t={exports:{}},t.exports),t.exports}var u,a,l=i(function(e,t){e.exports=(e=function(u){var r=Object.create||function(e){return t.prototype=e,e=new t,t.prototype=null,e};function t(){}var e={},n=e.lib={},o=n.Base={extend:function(e){var t=r(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).$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)}},l=n.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes,o=e.sigBytes;if(this.clamp(),n%4)for(var i=0;i<o;i++){var a=r[i>>>2]>>>24-i%4*8&255;t[n+i>>>2]|=a<<24-(n+i)%4*8}else for(i=0;i<o;i+=4)t[n+i>>>2]=r[i>>>2];return this.sigBytes+=o,this},clamp:function(){var e=this.words,t=this.sigBytes;e[t>>>2]&=4294967295<<32-t%4*8,e.length=u.ceil(t/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],r=0;r<e;r+=4){var n=function(t){var r=987654321,n=4294967295;return function(){var e=((r=36969*(65535&r)+(r>>16)&n)<<16)+(t=18e3*(65535&t)+(t>>16)&n)&n;return(e/4294967296+.5)*(.5<u.random()?1:-1)}}(4294967296*(o||u.random())),o=987654071*n();t.push(4294967296*n()|0)}return new l.init(t,e)}}),i=e.enc={},a=i.Hex={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o<r;o++){var i=t[o>>>2]>>>24-o%4*8&255;n.push((i>>>4).toString(16)),n.push((15&i).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new l.init(r,t/2)}},s=i.Latin1={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=[],o=0;o<r;o++){var i=t[o>>>2]>>>24-o%4*8&255;n.push(String.fromCharCode(i))}return n.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new l.init(r,t)}},c=i.Utf8={stringify:function(e){try{return decodeURIComponent(escape(s.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return s.parse(unescape(encodeURIComponent(e)))}},d=n.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new l.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=c.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(e){var t=this._data,r=t.words,n=t.sigBytes,o=this.blockSize,i=n/(4*o),a=(i=e?u.ceil(i):u.max((0|i)-this._minBufferSize,0))*o,e=u.min(4*a,n);if(a){for(var s=0;s<a;s+=o)this._doProcessBlock(r,s);var c=r.splice(0,a);t.sigBytes-=e}return new l.init(c,e)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),p=(n.Hasher=d.extend({cfg:o.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(r){return function(e,t){return new r.init(t).finalize(e)}},_createHmacHelper:function(r){return function(e,t){return new p.HMAC.init(r,t).finalize(e)}}}),e.algo={});return e}(Math),e)}),j=(i(function(e,t){e.exports=function(e){var o=Math,t=e,r=t.lib,n=r.WordArray,i=r.Hasher,a=t.algo,s=[],A=[];function c(e){var t=o.sqrt(e);for(var r=2;r<=t;r++)if(!(e%r))return false;return true}function u(e){return(e-(e|0))*4294967296|0}var l=2,d=0;while(d<64){if(c(l)){if(d<8)s[d]=u(o.pow(l,1/2));A[d]=u(o.pow(l,1/3));d++}l++}var x=[],p=a.SHA256=i.extend({_doReset:function(){this._hash=new n.init(s.slice(0))},_doProcessBlock:function(e,t){var r=this._hash.words;var n=r[0];var o=r[1];var i=r[2];var a=r[3];var s=r[4];var c=r[5];var u=r[6];var l=r[7];for(var d=0;d<64;d++){if(d<16)x[d]=e[t+d]|0;else{var p=x[d-15];var h=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3;var f=x[d-2];var v=(f<<15|f>>>17)^(f<<13|f>>>19)^f>>>10;x[d]=h+x[d-7]+v+x[d-16]}var y=s&c^~s&u;var m=n&o^n&i^o&i;var g=(n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22);var b=(s<<26|s>>>6)^(s<<21|s>>>11)^(s<<7|s>>>25);var w=l+b+y+A[d]+x[d];var _=g+m;l=u;u=c;c=s;s=a+w|0;a=i;i=o;o=n;n=w+_|0}r[0]=r[0]+n|0;r[1]=r[1]+o|0;r[2]=r[2]+i|0;r[3]=r[3]+a|0;r[4]=r[4]+s|0;r[5]=r[5]+c|0;r[6]=r[6]+u|0;r[7]=r[7]+l|0},_doFinalize:function(){var e=this._data;var t=e.words;var r=this._nDataBytes*8;var n=e.sigBytes*8;t[n>>>5]|=128<<24-n%32;t[(n+64>>>9<<4)+14]=o.floor(r/4294967296);t[(n+64>>>9<<4)+15]=r;e.sigBytes=t.length*4;this._process();return this._hash},clone:function(){var e=i.clone.call(this);e._hash=this._hash.clone();return e}});return t.SHA256=i._createHelper(p),t.HmacSHA256=i._createHmacHelper(p),e.SHA256}(l)}),i(function(e,t){var r,s;e.exports=(r=(e=l).lib.Base,s=e.enc.Utf8,void(e.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));for(var r=e.blockSize,n=4*r,e=((t=t.sigBytes>n?e.finalize(t):t).clamp(),this._oKey=t.clone()),t=this._iKey=t.clone(),o=e.words,i=t.words,a=0;a<r;a++)o[a]^=1549556828,i[a]^=909522486;e.sigBytes=t.sigBytes=n,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,e=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(e))}})))}),i(function(e,t){e.exports=l.HmacSHA256})),s=i(function(e,t){function a(e,t,r){for(var n,o,i=[],a=0,s=0;s<t;s++)s%4&&(n=r[e.charCodeAt(s-1)]<<s%4*2,o=r[e.charCodeAt(s)]>>>6-s%4*2,i[a>>>2]|=(n|o)<<24-a%4*8,a++);return c.create(i,a)}var c;e.exports=(c=(e=l).lib.WordArray,e.enc.Base64={stringify:function(e){for(var t=e.words,r=e.sigBytes,n=this._map,o=(e.clamp(),[]),i=0;i<r;i+=3)for(var a=(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,s=0;s<4&&i+.75*s<r;s++)o.push(n.charAt(a>>>6*(3-s)&63));var c=n.charAt(64);if(c)for(;o.length%4;)o.push(c);return o.join("")},parse:function(e){var t=e.length,r=this._map;if(!(n=this._reverseMap))for(var n=this._reverseMap=[],o=0;o<r.length;o++)n[r.charCodeAt(o)]=o;var i=r.charAt(64);return i&&-1!==(i=e.indexOf(i))&&(t=i),a(e,t,n)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},e.enc.Base64)}),H=i(function(e,t){e.exports=function(e){for(var l=Math,t=e,r=t.lib,n=r.WordArray,o=r.Hasher,i=t.algo,R=[],a=0;a<64;a++)R[a]=l.abs(l.sin(a+1))*4294967296|0;var s=i.MD5=o.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var r=0;r<16;r++){var n=t+r;var o=e[n];e[n]=(o<<8|o>>>24)&16711935|(o<<24|o>>>8)&4278255360}var i=this._hash.words;var a=e[t+0];var s=e[t+1];var c=e[t+2];var u=e[t+3];var l=e[t+4];var d=e[t+5];var p=e[t+6];var h=e[t+7];var f=e[t+8];var v=e[t+9];var y=e[t+10];var m=e[t+11];var g=e[t+12];var b=e[t+13];var w=e[t+14];var _=e[t+15];var A=i[0];var x=i[1];var q=i[2];var S=i[3];A=M(A,x,q,S,a,7,R[0]);S=M(S,A,x,q,s,12,R[1]);q=M(q,S,A,x,c,17,R[2]);x=M(x,q,S,A,u,22,R[3]);A=M(A,x,q,S,l,7,R[4]);S=M(S,A,x,q,d,12,R[5]);q=M(q,S,A,x,p,17,R[6]);x=M(x,q,S,A,h,22,R[7]);A=M(A,x,q,S,f,7,R[8]);S=M(S,A,x,q,v,12,R[9]);q=M(q,S,A,x,y,17,R[10]);x=M(x,q,S,A,m,22,R[11]);A=M(A,x,q,S,g,7,R[12]);S=M(S,A,x,q,b,12,R[13]);q=M(q,S,A,x,w,17,R[14]);x=M(x,q,S,A,_,22,R[15]);A=O(A,x,q,S,s,5,R[16]);S=O(S,A,x,q,p,9,R[17]);q=O(q,S,A,x,m,14,R[18]);x=O(x,q,S,A,a,20,R[19]);A=O(A,x,q,S,d,5,R[20]);S=O(S,A,x,q,y,9,R[21]);q=O(q,S,A,x,_,14,R[22]);x=O(x,q,S,A,l,20,R[23]);A=O(A,x,q,S,v,5,R[24]);S=O(S,A,x,q,w,9,R[25]);q=O(q,S,A,x,u,14,R[26]);x=O(x,q,S,A,f,20,R[27]);A=O(A,x,q,S,b,5,R[28]);S=O(S,A,x,q,c,9,R[29]);q=O(q,S,A,x,h,14,R[30]);x=O(x,q,S,A,g,20,R[31]);A=I(A,x,q,S,d,4,R[32]);S=I(S,A,x,q,f,11,R[33]);q=I(q,S,A,x,m,16,R[34]);x=I(x,q,S,A,w,23,R[35]);A=I(A,x,q,S,s,4,R[36]);S=I(S,A,x,q,l,11,R[37]);q=I(q,S,A,x,h,16,R[38]);x=I(x,q,S,A,y,23,R[39]);A=I(A,x,q,S,b,4,R[40]);S=I(S,A,x,q,a,11,R[41]);q=I(q,S,A,x,u,16,R[42]);x=I(x,q,S,A,p,23,R[43]);A=I(A,x,q,S,v,4,R[44]);S=I(S,A,x,q,g,11,R[45]);q=I(q,S,A,x,_,16,R[46]);x=I(x,q,S,A,c,23,R[47]);A=E(A,x,q,S,a,6,R[48]);S=E(S,A,x,q,h,10,R[49]);q=E(q,S,A,x,w,15,R[50]);x=E(x,q,S,A,d,21,R[51]);A=E(A,x,q,S,g,6,R[52]);S=E(S,A,x,q,u,10,R[53]);q=E(q,S,A,x,y,15,R[54]);x=E(x,q,S,A,s,21,R[55]);A=E(A,x,q,S,f,6,R[56]);S=E(S,A,x,q,_,10,R[57]);q=E(q,S,A,x,p,15,R[58]);x=E(x,q,S,A,b,21,R[59]);A=E(A,x,q,S,l,6,R[60]);S=E(S,A,x,q,m,10,R[61]);q=E(q,S,A,x,c,15,R[62]);x=E(x,q,S,A,v,21,R[63]);i[0]=i[0]+A|0;i[1]=i[1]+x|0;i[2]=i[2]+q|0;i[3]=i[3]+S|0},_doFinalize:function(){var e=this._data;var t=e.words;var r=this._nDataBytes*8;var n=e.sigBytes*8;t[n>>>5]|=128<<24-n%32;var o=l.floor(r/4294967296);var i=r;t[(n+64>>>9<<4)+15]=(o<<8|o>>>24)&16711935|(o<<24|o>>>8)&4278255360;t[(n+64>>>9<<4)+14]=(i<<8|i>>>24)&16711935|(i<<24|i>>>8)&4278255360;e.sigBytes=(t.length+1)*4;this._process();var a=this._hash;var s=a.words;for(var c=0;c<4;c++){var u=s[c];s[c]=(u<<8|u>>>24)&16711935|(u<<24|u>>>8)&4278255360}return a},clone:function(){var e=o.clone.call(this);e._hash=this._hash.clone();return e}});function M(e,t,r,n,o,i,a){var s=e+(t&r|~t&n)+o+a;return(s<<i|s>>>32-i)+t}function O(e,t,r,n,o,i,a){var s=e+(t&n|r&~n)+o+a;return(s<<i|s>>>32-i)+t}function I(e,t,r,n,o,i,a){var s=e+(t^r^n)+o+a;return(s<<i|s>>>32-i)+t}function E(e,t,r,n,o,i,a){var s=e+(r^(t|~n))+o+a;return(s<<i|s>>>32-i)+t}return t.MD5=o._createHelper(s),t.HmacMD5=o._createHmacHelper(s),e.MD5}(l)}),C=((D=u=u||{})[D.MTOP=1]="MTOP",D[D.MY=2]="MY",D[D.GATEWAY=3]="GATEWAY",t(p,a=Error),p);function p(){return null!==a&&a.apply(this,arguments)||this}function G(e){this.options=e||{},this.options.dataProxyGatewayUrl=this.options.dataProxyGatewayUrl||this.options.gatewayUrl}f.prototype.init=function(t,r){return c(this,void 0,void 0,function(){return m(this,function(e){return this.options=d({},t),this.proxy=r,this.tasks=[],this.inited=!0,[2]})})},f.getRequestType=function(e){return 0===e.indexOf("mtop.")?u.MTOP:0===e.indexOf("my.")?u.MY:u.GATEWAY},f.prototype.verifyResponse=function(t,r,n){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:if(g(n,"mc-code")||g(t,"errCode")||g(t,"error_response.code"),r.__is_retry_task__)return this.tryThrowError(t,n),[2,t];e.label=1;case 1:return e.trys.push([1,3,,4]),this.tryThrowError(t,n),[2,t];case 2:return[2,e.sent()];case 3:throw e.sent();case 4:return[2]}})})},f.prototype.tryThrowError=function(e,t){var r=g(t,"mc-msg")||g(e,"errMsg")||g(e,"error_response.msg"),t=g(t,"mc-code")||g(e,"errCode")||g(e,"error_response.code");if(t&&"200"!=t)throw(e=new C(t+":::"+r)).code=t,e.msg=r,e},f.prototype.sendGatewayRequest=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return r=this.createGatewayRequest(r),[4,this.proxy.apply(d({},r),u.GATEWAY)];case 1:return t=e.sent(),[4,this.verifyResponse(g(t,"data"),r,g(t,"headers"))];case 2:return[2,e.sent()]}})})},f.prototype.exec=function(t,r){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:if(r=r||f.getRequestType(t.url),this.inited)return t.data=t.data||{},r!==u.GATEWAY?[3,2]:[4,this.sendGatewayRequest(t)];throw new Error("请先调用cloud.init()");case 1:return[2,e.sent()];case 2:return[4,this.proxy.apply(t,r)];case 3:return[2,e.sent()]}})})},f.prototype.getHttpRequestSign=function(e,t,r,n,o){if(this.options.signSecret)return o=o,delete n["mc-sign"],t=t+"\n"+s.stringify(H(o))+"\napplication/json\n"+Object.keys(n).filter(function(e){return/^mc-/.test(e)}).sort().map(function(e){return e.toLowerCase()+":"+n[e]}).join("\n")+"\n"+e+(r?"?"+r:""),s.stringify(j(t,this.options.signSecret))},f.prototype.createGatewayRequest=function(e){var t=this.options,r=t.sessionKey,n=t.appKey,o=t.requestId,i=t.miniappId,a=t.openId,s=t.unionId,c=t.cloudId,t=t.sdkVersion,r=(e.method="POST",d(d({},e.headers),{"Content-Type":"application/json","mc-timestamp":""+Date.now(),"mc-session":r})),a=(a&&(r["mc-open-id"]=a),c&&(r["mc-cloud-id"]=c),s&&(r["mc-union-id"]=s),n&&(r["mc-appKey"]=n),i&&(r["mc-miniapp-id"]=i),o&&(r["mc-request-id"]=o),t&&(r["mc-sdk-version"]=t),e.env&&(r["mc-env"]=e.env),r["mc-session"]||delete r["mc-session"],e.rawData=e.rawData||e.data,"object"==typeof e.data&&(e.data=JSON.stringify(e.data)),this.getHttpRequestSign(e.url,e.method,"",r,e.data));return d(d({},e),{url:""+e.url,headers:d(d({},r),{sign:a,"eagleeye-traceid":o})})};var h=f;function f(){this.inited=!1}function v(e,t){this.request=t,this.options=e}new h;t(b,y=v),b.prototype.invoke=function(t,r,n,o){return void 0===n&&(n="main"),c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.fcRequest({fcName:t,handler:n,data:r,options:Object.assign(o||{},this.options)})];case 1:return[2,e.sent()]}})})},b.prototype.fcRequest=function(t){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.request.exec({env:this.options.env||"online",url:"fc",data:t},u.GATEWAY)];case 1:return[2,e.sent()]}})})},r([o()],b.prototype,"invoke",null);var y,U=b;function b(){return null!==y&&y.apply(this,arguments)||this}var w,z="1.5.5",N="mtop.taobao.miniapp.cloud.store.config.get",F="mtop.taobao.miniapp.cloud.store.config.v2.seller.get",W="mtop.taobao.miniapp.cloud.store.file.save",Y="mtop.taobao.miniapp.cloud.store.file.v2.seller.save",K="mtop.taobao.miniapp.cloud.store.file.delete",J="mtop.taobao.miniapp.cloud.store.file.v2.seller.delete",L="mtop.taobao.miniapp.cloud.store.file.list",V="mtop.taobao.miniapp.cloud.store.file.v2.seller.list",X="other",$=(t(_,w=v),_.prototype.parseUploadResult=function(e,t,r){return this.parsePostUploadResult(e,t,r)},_.prototype.parsePostUploadResult=function(e,t,r){var n;if(t.data)if(r)try{var o=(s=JSON.parse(t.data)).fileId,i=s.url,a=s.message}catch(e){console.log(e)}else try{var s=JSON.parse(t.data);switch(e){case"image":case"font":o=s.jsonData.fileId,i=s.jsonData.url,a=s.errorMessage;break;case"video":o=s.fileId,n=s.videoId,i=s.url,a=s.message;break;case"audio":o=s.fileId,n=s.videoId,i=s.url,a=s.message}}catch(e){}return{imageUrl:i,specialId:o,message:a,videoId:n}},_.prototype.uploadFile=function(y){return c(this,void 0,void 0,function(){var n,o,i,a,s,c,u,l,d,p,h,f,v;return m(this,function(e){switch(e.label){case 0:n=y.filePath,o=y.fileType,o=void 0===o?X:o,i=y.fileName,i=void 0===i?"miniappfile":i,a=y.seller,a=void 0!==a&&a,s=y.dirId,e.label=1;case 1:return e.trys.push([1,3,,4]),u=a?F:N,[4,this.storageRequest(u,{newContainer:!0,cloudPath:i,fileType:o,sellerSpace:a,dirId:s})];case 2:return c=e.sent(),[3,4];case 3:throw u=e.sent(),new Error("获取配置错误"+(u.message||u.toString()));case 4:return l=g(c,["data","model",o],{}),p=l.url,p=void 0===p?"":p,d=l.formData,d=void 0===d?null:d,l=l.headers,(p={url:p,fileType:o,header:void 0===l?null:l,formData:d,filePath:n,fileName:"file"}).formData=p.formData||{},p.header&&p.header.Authorization&&(p.formData.Authorization=p.header.Authorization),i&&(p.formData.localFileName=Date.now()+"-"+((t=i)?0<=(r=t.lastIndexOf("/"))?t.substr(r+1):t:"file")),p.header?"image"!==o&&(p.header.origin=p.header.origin||"https://miniapp-cloud.taobao.com",p.header.referer=p.header.referer||"https://miniapp-cloud.taobao.com"):delete p.header,[4,this.storageRequest("my.uploadFile",p)];case 5:if(l=e.sent(),console.log(l),d=this.parseUploadResult(o,l,a),p=d.imageUrl,f=d.specialId,h=d.message,v=d.videoId,(f={fileType:o,specialId:f||g(c,["data","model",o,"formData","key"],""),videoId:v,url:p,cloudPath:i,sellerSpace:a}).specialId)return[4,this.storageRequest(a?Y:W,f)];throw new Error(h||"上传文件失败");case 6:if(g(v=e.sent(),"data.model.fileId"))return[2,g(v,"data.model")];throw new Error(g(v,["result","msgInfo"],"上传文件失败"))}var t,r})})},_.prototype.deleteFile=function(o){return c(this,void 0,void 0,function(){var t,r,n;return m(this,function(e){switch(e.label){case 0:if(r=o.fileId,n=o.fileType,n=void 0===n?X:n,t=o.seller,t=void 0!==t&&t,r=Array.isArray(r)?r:[r],t)throw new Error("商家空间资源不允许使用接口删除");return r=JSON.stringify(r),[4,this.storageRequest(t?J:K,{fileType:n,fileIds:r,sellerSpace:t})];case 1:if(g(n=e.sent(),["data","model"]))return[2,!0];throw new Error(g(n,["data","msgInfo"]))}})})},_.prototype.getTempFileURL=function(n){return c(this,void 0,void 0,function(){var t,r;return m(this,function(e){switch(e.label){case 0:if(t=n.fileId,r=n.seller,r=void 0!==r&&r,t)return t=Array.isArray(t)?t:[t],t=JSON.stringify(t),[4,this.storageRequest(r?V:L,{fileIds:t,sellerSpace:r})];throw new Error("缺少fileId,请检查参数");case 1:if(t=e.sent(),r=g(t,["data","model"]))return[2,r];throw new Error(g(t,["data","msgInfo"]))}})})},_.prototype.downloadByFileId=function(s){return c(this,void 0,void 0,function(){var t,r,n,o,i,a;return m(this,function(e){switch(e.label){case 0:if(r=s.fileId,t=s.cache,r)return r=Array.isArray(r)?r:[r],[4,this.storageRequest(L,{fileIds:JSON.stringify(r)})];throw new Error("缺少fileId,请检查参数");case 1:r=e.sent(),n=g(r,["data","model"])||[],o=[],i=0,e.label=2;case 2:return i<n.length?(a=(n[i]||{}).url,[4,this._downloadByUrl(a,t)]):[3,5];case 3:(a=e.sent())&&o.push(a),e.label=4;case 4:return i++,[3,2];case 5:return[2,o]}})})},_.prototype.storageRequest=function(r,n,o){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t="test"===this.options.env?"test":"online",(n=n||{}).env=t,n.sdkVersion=z,[4,this.request.exec({url:r,data:n},o)];case 1:return[2,e.sent()]}})})},_.prototype._downloadByUrl=function(n,o){return c(this,void 0,void 0,function(){var t,r;return m(this,function(e){switch(e.label){case 0:return n?o?[4,this.request.proxy.apply({url:"my.getStorage",data:{key:n}})]:[3,2]:[2,null];case 1:if(t=e.sent().data)return[2,t];e.label=2;case 2:return[4,this.request.exec({url:"my.downloadFile",data:{url:n}})];case 3:return(r=e.sent().apFilePath,o)?[4,this.request.exec({url:"my.setStorage",data:{key:n,data:r}})]:[3,5];case 4:e.sent(),e.label=5;case 5:return[2,r]}})})},r([o()],_.prototype,"uploadFile",null),r([o()],_.prototype,"deleteFile",null),r([o()],_.prototype,"getTempFileURL",null),r([o()],_.prototype,"downloadByFileId",null),_);function _(){return null!==w&&w.apply(this,arguments)||this}Object.defineProperty(A.prototype,"name",{get:function(){return this._coll},enumerable:!1,configurable:!0}),A.prototype.aggregate=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return Array.isArray(r)||(r=[r]),t={aggregate_pipelines:r,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.aggregate",t)];case 1:return[2,e.sent()]}})})},A.prototype.count=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={filter:r,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.count",t)];case 1:return[2,e.sent()]}})})},A.prototype.deleteMany=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={filter:r,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.remove",t)];case 1:return[2,e.sent()]}})})},A.prototype.find=function(r,n){return void 0===n&&(n={}),c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={displayed_fields:n.projection,order_by:n.sort,skip:n.skip,limit:n.limit,filter:r,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.get",t)];case 1:return[2,e.sent()]}})})},A.prototype.replaceOne=function(r,n){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={filter:r,new_record:n,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.replace",t)];case 1:return[2,e.sent()]}})})},A.prototype.insertOne=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={record:r,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.add",t)];case 1:return[2,e.sent()]}})})},A.prototype.insertMany=function(r){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:if(t={records:r,collection_name:this._coll},Array.isArray(r))return[4,this._db.dbRequest("miniapp.cloud.db.collection.addMany",t)];throw new Error("带插入的数据只能为数组");case 1:return[2,e.sent()]}})})},A.prototype.updateMany=function(r,n,o){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={filter:r,action:n,arrayFilters:o,collection_name:this._coll},[4,this._db.dbRequest("miniapp.cloud.db.collection.update",t)];case 1:return[2,e.sent()]}})})},r([o()],A.prototype,"aggregate",null),r([o()],A.prototype,"count",null),r([o()],A.prototype,"deleteMany",null),r([o()],A.prototype,"find",null),r([o()],A.prototype,"replaceOne",null),r([o()],A.prototype,"insertOne",null),r([o()],A.prototype,"insertMany",null),r([o()],A.prototype,"updateMany",null);var Q=A;function A(e,t){this._db=e,this._coll=t}t(q,x=v),q.prototype.collection=function(e){if(e)return new Q(this,e);throw new Error("集合名称不能为空")},q.prototype.createCollection=function(r,e){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return t={collection_name:r},[4,this.dbRequest("miniapp.cloud.db.collection.create",t)];case 1:return[2,e.sent()]}})})},q.prototype.dbRequest=function(r,n){return c(this,void 0,void 0,function(){var t;return m(this,function(e){switch(e.label){case 0:return("test"!==(t=this.options.env)&&(t="online"),n=d(d({},n),{env:t}),this.options.localDebug)?[4,this.request.exec({env:t,debugAction:"MONGO_INVOKE",url:"db/"+r,data:n},u.GATEWAY)]:[3,2];case 1:return[2,e.sent()];case 2:return[4,this.request.exec({env:t,url:"db/"+r,data:n},u.GATEWAY)];case 3:return[2,e.sent()]}})})},r([o()],q.prototype,"createCollection",null);var x,Z=q;function q(){return null!==x&&x.apply(this,arguments)||this}t(R,S=v),R.prototype.invoke=function(l){return c(this,void 0,void 0,function(){var t,i,a,s,c,u;return m(this,function(e){switch(e.label){case 0:return t=l.data,c=l.headers,i=l.authScope,a=l.api,t=t||{},Object.keys(t).forEach(function(e){t[e]="string"==typeof t[e]?t[e]:JSON.stringify(t[e])}),a={apiName:a,httpHeaders:c,data:t},[4,this.topRequest(a)];case 1:if(s=e.sent(),!g(s,"error_response"))return[2,s];if(c=g(s,"error_response.code"),(u=my&&my.canIUse("qn.cleanToken"))&&!i&&(i="*"),26!=c&&27!=c&&53!=c||!i)return[3,9];e.label=2;case 2:return(e.trys.push([2,8,,9]),u)?(console.log("call my.qn.cleanToken"),[4,my.qn.cleanToken()]):[3,4];case 3:e.sent(),e.label=4;case 4:return[4,(r=my.authorize,n={scopes:i},r?(n=n||{},new Promise(function(e,t){r.call(o||my,d(d({},n),{success:e,fail:t}))})):Promise.reject("未实现my.api"))];case 5:return[4,e.sent()];case 6:return e.sent(),[4,this.topRequest(a)];case 7:return g(s=e.sent(),"error_response")?[3,9]:[2,s];case 8:return e.sent(),[3,9];case 9:throw new Error(""+JSON.stringify(g(s,"error_response")))}var r,n,o})})},R.prototype.topRequest=function(t){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.request.exec({env:this.options.env||"online",url:"top",data:t},u.GATEWAY)];case 1:return[2,e.sent()]}})})},r([o()],R.prototype,"invoke",null);var S,ee=R;function R(){return null!==S&&S.apply(this,arguments)||this}t(O,M=v),O.prototype.invoke=function(i){return c(this,void 0,void 0,function(){var t,r,n,o;return m(this,function(e){switch(e.label){case 0:return t=i.data,r=i.headers,n=i.api,o=i.targetAppKey,[4,this.qimenRequest({apiName:n,httpHeaders:r,targetAppKey:o,data:t})];case 1:return[2,e.sent()]}})})},O.prototype.qimenRequest=function(t){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.request.exec({env:this.options.env||"online",url:"qimen",data:t},u.GATEWAY)];case 1:return[2,e.sent()]}})})},r([o()],O.prototype,"invoke",null);var M,te=O;function O(){return null!==M&&M.apply(this,arguments)||this}t(E,I=v),E.prototype.httpRequest=function(s){return c(this,void 0,void 0,function(){var t,r,n,o,i,a;return m(this,function(e){switch(e.label){case 0:return t=s.body,r=s.params,n=s.headers,o=s.path,i=s.method,a=s.exts,[4,this.innerRequest({path:o,headers:n,body:t,queryString:r,method:i,options:Object.assign(a||{},this.options)})];case 1:return[2,e.sent()]}})})},E.prototype.innerRequest=function(t){return c(this,void 0,void 0,function(){return m(this,function(e){switch(e.label){case 0:return[4,this.request.exec({env:this.options.env||"online",url:"cloudHttp",data:t},u.GATEWAY)];case 1:return[2,e.sent()]}})})},r([o()],E.prototype,"httpRequest",null);var I,re=E;function E(){return null!==I&&I.apply(this,arguments)||this}t(T,P=Error),T.prototype.toString=function(){return(this.code||"")+" "+(this.message||"")};var P,ne=T;function T(){return null!==P&&P.apply(this,arguments)||this}t(B,k=G),B.getMtopErrorMsg=function(e){var t=new ne;if(!e)return t.code="500",t.message="客户端网络错误,请稍后重试",t;var r,n,o=e.ret&&e.ret[0]&&e.ret[0].split("::");if(e.data=e.data||g(e,["err","data"]),e.data&&e.data.errCode&&(r=e.data.errCode,n=e.data.errMessage||e.data.errMsg),e.data&&e.data.errorCode&&(r=e.data.errorCode),e.data&&e.data.errorMessage&&(n=e.data.errorMessage),e.data&&e.data.errorPage)try{if(my&&my.tb&&my.tb.showErrorView)return my.tb.showErrorView({reason:e.data.errorPage.reason,message:e.data.errorPage.message,action:e.data.errorPage.action,icon:e.data.errorPage.icon}),t;delete e.data.errorPage}catch(e){}return e.data&&e.data.success||o&&"SUCCESS"===o[0]&&!r?void 0:(r=r||(o&&"FAIL_SYS_SESSION_EXPIRED"===o[0]?"904":"500"),n=n||o&&o[1]||"客户端网络错误,请稍后重试",t.code=r,t.message=n,t)},B.GATEWAY_APIS={"db/miniapp.cloud.db.collection.create":"mtop.taobao.dataproxy.collection.create","db/miniapp.cloud.db.index.create":"mtop.taobao.dataproxy.index.create","db/miniapp.cloud.db.collection.aggregate":"mtop.taobao.dataproxy.record.aggregate","db/miniapp.cloud.db.collection.count":"mtop.taobao.dataproxy.record.count","db/miniapp.cloud.db.collection.remove":"mtop.taobao.dataproxy.record.delete","db/miniapp.cloud.db.collection.get":"mtop.taobao.dataproxy.record.select","db/miniapp.cloud.db.collection.replace":"mtop.taobao.dataproxy.record.replace","db/miniapp.cloud.db.collection.add":"mtop.taobao.dataproxy.record.insert","db/miniapp.cloud.db.collection.addMany":"mtop.taobao.dataproxy.record.batch.insert","db/miniapp.cloud.db.collection.update":"mtop.taobao.dataproxy.record.update",fc:"mtop.miniapp.cloud.invoke.fc",top:"mtop.miniapp.cloud.invoke.top",qimen:"mtop.miniapp.cloud.invoke.qimen.cloud",cloudHttp:"mtop.miniapp.cloud.application.request"};var k,oe=B;function B(){var e=null!==k&&k.apply(this,arguments)||this;return e.sendMtop=function(t,o,i){return c(e,void 0,void 0,function(){return m(this,function(e){return[2,new Promise(function(r,n){var e;1024e3<=o.length?((e=new ne).code="500",e.message="本次请求内容过长请控制在1M以内",n(e)):(console.log("sendMtop ",o),my.sendMtop(d(d({api:t,v:"1.0",data:o,method:"POST",needLogin:!0,sessionOption:"AutoLoginAndManualLogin"},i),{success:function(e){var t=B.getMtopErrorMsg(e);t?n(t):r(e)},fail:function(e){console.log("sendMtop error",e),n(B.getMtopErrorMsg(e))}})))})]})})},e.invokeMyApi=function(r,n){return c(e,void 0,void 0,function(){return m(this,function(e){return[2,new Promise(function(e,t){return r=r.replace(/^my\./,""),my[r](d(d({},n),{success:e,fail:t}))})]})})},e.apply=function(a,s){return c(e,void 0,void 0,function(){var t,r,n,o,i;return m(this,function(e){switch(e.label){case 0:return t=a.url,r=a.data,n=a.headers,o=a.mtopOptions,s!==u.MTOP?[3,2]:[4,this.sendMtop(t,r,o)];case 1:return[2,e.sent()];case 2:if(s!==u.GATEWAY)return[3,7];e.label=3;case 3:return e.trys.push([3,5,,6]),a.rawData&&Object.keys(a.rawData).forEach(function(e){"object"==typeof a.rawData[e]&&(a.rawData[e]=JSON.stringify(a.rawData[e]))}),[4,this.sendMtop(B.GATEWAY_APIS[t],d(d({},a.rawData),{sdkVersion:z,protocols:JSON.stringify(n)}),o)];case 4:return i=e.sent(),(i=i&&i.data||{}).errCode?[2,{headers:{"mc-code":i.errCode,"mc-msg":i.errMessage},data:{}}]:[2,{headers:{"mc-code":200,"mc-msg":"请求成功"},data:g(i,["data"])||{}}];case 5:return(i=e.sent())&&i.code?[2,{headers:{"mc-code":i.code,"mc-msg":i.message}}]:[2,{headers:{"mc-code":500,"mc-msg":i.message||i}}];case 6:return[3,9];case 7:return[4,this.invokeMyApi(t,r)];case 8:return[2,e.sent()];case 9:return[2]}})})},e}ie.prototype.init=function(o,i){return c(this,void 0,void 0,function(){var r,n;return m(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=o.env,n="string"==typeof(t=t||"online")?{database:t,file:t,function:t,message:t}:(t.database=t.database||"online",t.file=t.file||"online",t.function=t.function||"online",t.message=t.message||"online",t),r=new h,this.db=new Z({env:n.database},r),this.function=new U(d(d({},o),{env:n.function}),r),this.file=new $({env:n.file},r),this.qimenApi=new te({env:n.database},r),this.topApi=new ee({env:n.database},r),this.application=new re(d(d({},o),{env:n.database}),r),[4,r.init(d({},o),i||new oe({gatewayUrl:o.__gatewayUrl}))];case 1:return e.sent(),[2,!0];case 2:return n=e.sent(),console.error("SDK初始化失败 ",n),[3,3];case 3:return[2,!1]}var t})})};var D=ie;function ie(){}var ae=new D;e.Cloud=D,e.default=ae,Object.defineProperty(e,"__esModule",{value:!0})});