aliyun-product-js-sdk
Version:
aliyun third party product
2 lines (1 loc) • 11.9 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("url"),require("crypto"),require("uuid"),require("querystring")):"function"==typeof define&&define.amd?define(["url","crypto","uuid","querystring"],e):(t=t||self).AliyunOssProSdk=e(t.urlParse,t.crypto,t.uuid,t.querystring)}(this,function(t,e,r,n){"use strict";var o="default"in t?t.default:t;e=e&&e.hasOwnProperty("default")?e.default:e,r=r&&r.hasOwnProperty("default")?r.default:r,n=n&&n.hasOwnProperty("default")?n.default:n;var i,a=(function(t){!function(e){var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag",c=e.regeneratorRuntime;if(c)t.exports=c;else{(c=e.regeneratorRuntime=t.exports).wrap=w;var h="suspendedStart",f="suspendedYield",p="executing",l="completed",d={},y={};y[a]=function(){return this};var g=Object.getPrototypeOf,v=g&&g(g(H([])));v&&v!==n&&o.call(v,a)&&(y=v);var m=j.prototype=b.prototype=Object.create(y);O.prototype=m.constructor=j,j.constructor=O,j[s]=O.displayName="GeneratorFunction",c.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===O||"GeneratorFunction"===(e.displayName||e.name))},c.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,j):(t.__proto__=j,s in t||(t[s]="GeneratorFunction")),t.prototype=Object.create(m),t},c.awrap=function(t){return{__await:t}},L(q.prototype),q.prototype[u]=function(){return this},c.AsyncIterator=q,c.async=function(t,e,r,n){var o=new q(w(t,e,r,n));return c.isGeneratorFunction(e)?o:o.next().then(function(t){return t.done?t.value:o.next()})},L(m),m[s]="Generator",m[a]=function(){return this},m.toString=function(){return"[object Generator]"},c.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},c.values=H,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return u.type="throw",u.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(this.prev>=a.tryLoc){var s=o.call(a,"catchLoc"),c=o.call(a,"finallyLoc");if(s&&c){if(a.catchLoc>this.prev)return n(a.catchLoc,!0);if(a.finallyLoc>this.prev)return n(a.finallyLoc)}else if(s){if(a.catchLoc>this.prev)return n(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(a.finallyLoc>this.prev)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(this.prev>=n.tryLoc&&o.call(n,"finallyLoc")&&n.finallyLoc>this.prev){var i=n;break}}!i||"break"!==t&&"continue"!==t||i.tryLoc>e||e>i.finallyLoc||(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:H(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),d}}}function w(t,e,r,n){var o=Object.create((e&&e.prototype instanceof b?e:b).prototype),i=new _(n||[]);return o._invoke=function(t,e,r){var n=h;return function(o,i){if(n===p)throw Error("Generator is already running");if(n===l){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=E(a,r);if(u){if(u===d)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===h)throw n=l,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=x(t,e,r);if("normal"===s.type){if(n=r.done?l:f,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=l,r.method="throw",r.arg=s.arg)}}}(t,r,i),o}function x(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function b(){}function O(){}function j(){}function L(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function q(t){var e;this._invoke=function(r,n){function i(){return new Promise(function(e,i){!function e(r,n,i,a){var u=x(t[r],t,n);if("throw"!==u.type){var s=u.arg,c=s.value;return c&&"object"==typeof c&&o.call(c,"__await")?Promise.resolve(c.__await).then(function(t){e("next",t,i,a)},function(t){e("throw",t,i,a)}):Promise.resolve(c).then(function(t){s.value=t,i(s)},function(t){return e("throw",t,i,a)})}a(u.arg)}(r,n,e,i)})}return e=e?e.then(i,i):i()}}function E(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,E(t,e),"throw"===e.method))return d;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=x(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function S(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function H(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:k}}function k(){return{value:r,done:!0}}}(function(){return this||"object"==typeof self&&self}()||Function("return this")())}(i={exports:{}},i.exports),i.exports),u=function(){return this||"object"==typeof self&&self}()||Function("return this")(),s=u.regeneratorRuntime&&Object.getOwnPropertyNames(u).indexOf("regeneratorRuntime")>=0,c=s&&u.regeneratorRuntime;u.regeneratorRuntime=void 0;var h=a;if(s)u.regeneratorRuntime=c;else try{delete u.regeneratorRuntime}catch(t){u.regeneratorRuntime=void 0}var f=h;function p(t,e,r,n,o,i,a){try{var u=t[i](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,o)}var l=function(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){p(i,n,o,a,u,"next",t)}function u(t){p(i,n,o,a,u,"throw",t)}a(void 0)})}};var d=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e};function y(t){void 0===t&&(t={});for(var e={},r=Object.keys(t),n=0;r.length>n;n++){var o=r[n];e[o.toLowerCase()]=t[o]}return e}var g=o.parse,v="application/x-www-form-urlencoded",m=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};return function(t){function n(e,r,n){var o;return void 0===n&&(n="RELEASE"),(o=t.call(this)||this).appKey=e,o.appSecret=Buffer.from(r,"utf8"),o.stage=n,o}d(n,t);var o=n.prototype;return o.buildStringToSign=function(t,e,r,n,o){var i="\n",a=[t,i],u=e.accept;u&&a.push(u),a.push(i);var s=e["content-md5"];s&&a.push(s),a.push(i);var c=e["content-type"]||"";c&&a.push(c),a.push(i);var h=e.date;return h&&a.push(h),a.push(i),r&&(a.push(r),a.push(i)),c.startsWith(v)?a.push(this.buildUrl(n,o)):a.push(this.buildUrl(n)),a.join("")},o.sign=function(t){return e.createHmac("sha256",this.appSecret).update(t,"utf8").digest("base64")},o.md5=function(t){return e.createHash("md5").update(t,"utf8").digest("base64")},o.getSignHeaderKeys=function(t,e){for(var r=Object.keys(t).sort(),n=[],o=0;r.length>o;o++){var i=r[o];(i.startsWith("x-ca-")||m(e,i))&&n.push(i)}return n.sort()},o.buildUrl=function(t,e){var r=Object.assign(t.query,e),n=t.pathname;if(Object.keys(r).length){for(var o=Object.keys(r).sort(),i=Array(o.length),a=0;o.length>a;a++){var u=o[a];i[a]=r[u]&&""+r[u]?u+"="+r[u]:""+u}n+="?"+i.join("&")}return n},o.buildHeaders=function(t,e){return void 0===t&&(t={}),Object.assign({"x-ca-timestamp":Date.now(),"x-ca-key":this.appKey,"x-ca-nonce":r.v4(),"x-ca-stage":this.stage,accept:"application/json"},t,e)},o.getSignedHeadersString=function(t,e){for(var r=[],n=0;t.length>n;n++){var o=t[n];r.push(o+":"+e[o])}return r.join("\n")},o.request=function(){var t=l(f.mark(function t(e,r,n,o){var i,a,u,s,c,h,p,l,d;return f.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return a=this.buildHeaders(n.headers,i=n.signHeaders),u=a["content-type"]||"","POST"!==e||u.startsWith(v)||(a["content-md5"]=this.md5(n.data)),s=this.getSignHeaderKeys(a,i),a["x-ca-signature-headers"]=s.join(","),c=this.getSignedHeadersString(s,a),h=g(r,!0),p=this.buildStringToSign(e,a,c,h,o),a["x-ca-signature"]=this.sign(p),l=new Request(h.href,{method:e,body:n.data,headers:a}),d=new Promise(function(t,e){fetch(l).then(function(t){if(200!==t.status)throw t.status+", "+t.statusText;return t.json()}).then(function(e){return t(e)}).catch(function(t){return e(t)})}),t.next=14,d.then(function(t){return t});case 14:return t.abrupt("return",t.sent);case 16:case"end":return t.stop()}},t,this)}));return function(e,r,n,o){return t.apply(this,arguments)}}(),n}(function(){function e(){}var r=e.prototype;return r.get=function(e,r){void 0===r&&(r={});var o=t.parse(e,!0),i=r.query||r.data;return i&&(Object.assign(o.query,i),o.path=o.pathname+"?"+n.stringify(o.query),r.data=null,r.query=null),r.headers=y(r.headers),r.signHeaders=y(r.signHeaders),this.request("GET",o,r)},r.post=function(e,r){void 0===r&&(r={});var o=t.parse(e,!0),i=r.query;i&&(Object.assign(o.query,i),o.path=o.pathname+"?"+n.stringify(o.query),r.query=null),r.headers=y(r.headers),r.signHeaders=y(r.signHeaders);var a=r.headers,u=a["content-type"]||a["Content-Type"];u||(a["content-type"]="application/json",u=a["content-type"]);var s=r.data;return u.startsWith("application/x-www-form-urlencoded")?r.data=n.stringify(r.data):u.startsWith("application/json")?r.data=JSON.stringify(r.data):Buffer.isBuffer(r.data)||"string"==typeof r.data||(r.data=JSON.stringify(r.data)),this.request("POST",o,r,s)},r.put=function(e,r){void 0===r&&(r={});var o=t.parse(e,!0),i=r.query;i&&(Object.assign(o.query,i),o.path=o.pathname+"?"+n.stringify(o.query),r.query=null),r.headers=y(r.headers),r.signHeaders=y(r.signHeaders);var a=r.headers,u=a["content-type"]||a["Content-Type"];u||(a["content-type"]="application/json",u=a["content-type"]);var s=r.data;return u.startsWith("application/x-www-form-urlencoded")?r.data=n.stringify(r.data):u.startsWith("application/json")?r.data=JSON.stringify(r.data):Buffer.isBuffer(r.data)||"string"==typeof r.data||(r.data=JSON.stringify(r.data)),this.request("PUT",o,r,s)},r.delete=function(e,r){var o=t.parse(e,!0),i=r.query||r.data;return i&&(Object.assign(o.query,i),o.path=o.pathname+"?"+n.stringify(o.query),r.data=null,r.query=null),r.headers=y(r.headers),r.signHeaders=y(r.signHeaders),this.request("DELETE",o,r)},e}())});