@cloudbase/js-sdk
Version:
cloudbase javascript sdk
2 lines • 5.87 kB
JavaScript
var t={946:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.COMMUNITY_SITE_URL=e.IS_DEBUG_MODE=e.getProtocol=e.setProtocol=e.getSdkName=e.setSdkName=void 0;var n="@cloudbase/js-sdk";e.setSdkName=function(t){n=t},e.getSdkName=function(){return n};var r="https:";e.setProtocol=function(t){r=t},e.getProtocol=function(){return r},e.IS_DEBUG_MODE=!1,e.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},205:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ERRORS=void 0,e.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},794:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(e,n);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,o)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.OATUH_LOGINTYPE=void 0,o(n(946),e),o(n(205),e),e.OATUH_LOGINTYPE="constants"}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};(()=>{n.d(r,{m:()=>u,J:()=>p});var t=n(794),e=function(){return e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},e.apply(this,arguments)},o=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,c)}s((r=r.apply(t,e||[])).next())})},i=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}};function a(n,r){var a,c,s,u;return o(this,void 0,Promise,function(){var o,l,f,p,d,h,v,O,y,b,E,P,g,R,_,A,T,m,I,N,w,S,j;return i(this,function(i){switch(i.label){case 0:l=(o=n||{}).name,f=o.body,p=o.path,d=void 0===p?"":p,h=o.method,v=void 0===h?"POST":h,O=o.headers,y=void 0===O?{}:O,b=(n||{}).token,E={};try{E=JSON.parse(f)}catch(t){E=f||{}}if(!l)throw new Error(JSON.stringify({code:t.ERRORS.INVALID_PARAMS,msg:"[apis] invalid api name"}));return P="",R=(g=this).gatewayOrigin,_=g.getAccessToken,A=g.env,R?P="".concat(R,"/v1"):this.getEndPointWithKey?(T=this.getEndPointWithKey("GATEWAY"),m=T.BASE_URL,I=T.PROTOCOL,P="".concat(I).concat(m)):P="https://".concat(A,".api.tcloudbasegateway.com/v1"),N="".concat(P,"/apis/").concat(l),w=d.startsWith("/")?d:"/".concat(d),_?[4,_()]:[3,2];case 1:S=i.sent().accessToken,y.Authorization="Bearer ".concat(S),i.label=2;case 2:if(j=["GET","HEAD"].includes(null===(a=null==v?void 0:v.toUpperCase)||void 0===a?void 0:a.call(v)))try{w="".concat(w).concat(w.includes("?")?"&":"?").concat(Object.keys(E).map(function(t){return"".concat(t,"=").concat(E[t])}).join("&"))}catch(t){}return[4,this.request.fetch(e(e(e({url:"".concat(N).concat(w),method:v||"POST",headers:e({"Content-Type":"application/json; charset=utf-8"},y)},j?{}:{body:JSON.stringify(E)}),{token:(null===(c=null==b?void 0:b.trim)||void 0===c?void 0:c.call(b))||(null===(u=null===(s=y.Authorization)||void 0===s?void 0:s.replace)||void 0===u?void 0:u.call(s,/^Bearer /,""))||null}),r))];case 3:return[4,i.sent().data];case 4:return[2,i.sent()]}})})}var c=["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH","REQUEST"];function s(t){var n=this;return new Proxy({},{get:function(r,s){if("string"!=typeof s)throw new Error("[apis] method must be string");var u=s.toLocaleUpperCase();if(!c.includes(u))throw new Error("[apis] invalid method: ".concat(s));return function(r,c){return o(n,void 0,void 0,function(){return i(this,function(n){switch(n.label){case 0:return[4,a.call(this,e({name:t,method:("REQUEST"===u?r.method:u)||"POST"},r),c)];case 1:return[2,n.sent()]}})})}}})}function u(t){var e=this;return Object.keys(t||{}).forEach(function(n){void 0!==t[n]&&(e[n]=t[n])}),new Proxy({},{get:function(t,n){if("string"==typeof n)return s.call(e,n)}})}var l="apis",f={name:l,IIFE:!0,entity:function(){Object.defineProperty(this.prototype,l,{get:function(){return u.call(this)},configurable:!0,enumerable:!0})}};function p(t){try{t.registerComponent(f)}catch(t){console.warn(t)}}try{cloudbase.registerComponent(f)}catch(t){}try{window.registerApis=p}catch(t){}})();var o=r.m,i=r.J;export{o as generateApis,i as registerApis};
//# sourceMappingURL=index.esm.js.map