UNPKG

@cloudbase/js-sdk

Version:
1 lines 6.87 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_apis",[],t):"object"==typeof exports?exports.cloudbase_apis=t():e.cloudbase_apis=t()}("undefined"!=typeof window?window:this,()=>(()=>{"use strict";var e={378:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,c)}s((r=r.apply(e,t||[])).next())})},i=this&&this.__generator||function(e,t){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=t.call(e,a)}catch(e){c=[6,e],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])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.generateApis=t.generateCallApis=t.callApi=void 0;var a=n(794);function c(e,t){var n,c,s,u;return o(this,void 0,Promise,function(){var o,l,p,f,d,h,v,O,y,b,_,g,A,E,P,w,R,T,m,I,N,S,j;return i(this,function(i){switch(i.label){case 0:l=(o=e||{}).name,p=o.body,f=o.path,d=void 0===f?"":f,h=o.method,v=void 0===h?"POST":h,O=o.headers,y=void 0===O?{}:O,b=(e||{}).token,_={};try{_=JSON.parse(p)}catch(e){_=p||{}}if(!l)throw new Error(JSON.stringify({code:a.ERRORS.INVALID_PARAMS,msg:"[apis] invalid api name"}));return g="",E=(A=this).gatewayOrigin,P=A.getAccessToken,w=A.env,E?g="".concat(E,"/v1"):this.getEndPointWithKey?(R=this.getEndPointWithKey("GATEWAY"),T=R.BASE_URL,m=R.PROTOCOL,g="".concat(m).concat(T)):g="https://".concat(w,".api.tcloudbasegateway.com/v1"),I="".concat(g,"/apis/").concat(l),N=d.startsWith("/")?d:"/".concat(d),P?[4,P()]:[3,2];case 1:S=i.sent().accessToken,y.Authorization="Bearer ".concat(S),i.label=2;case 2:if(j=["GET","HEAD"].includes(null===(n=null==v?void 0:v.toUpperCase)||void 0===n?void 0:n.call(v)))try{N="".concat(N).concat(N.includes("?")?"&":"?").concat(Object.keys(_).map(function(e){return"".concat(e,"=").concat(_[e])}).join("&"))}catch(e){}return[4,this.request.fetch(r(r(r({url:"".concat(I).concat(N),method:v||"POST",headers:r({"Content-Type":"application/json; charset=utf-8"},y)},j?{}:{body:JSON.stringify(_)}),{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}),t))];case 3:return[4,i.sent().data];case 4:return[2,i.sent()]}})})}t.callApi=c;var s=["GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH","REQUEST"];function u(e){var t=this;return new Proxy({},{get:function(n,a){if("string"!=typeof a)throw new Error("[apis] method must be string");var u=a.toLocaleUpperCase();if(!s.includes(u))throw new Error("[apis] invalid method: ".concat(a));return function(n,a){return o(t,void 0,void 0,function(){return i(this,function(t){switch(t.label){case 0:return[4,c.call(this,r({name:e,method:("REQUEST"===u?n.method:u)||"POST"},n),a)];case 1:return[2,t.sent()]}})})}}})}t.generateCallApis=u,t.generateApis=function(e){var t=this;return Object.keys(e||{}).forEach(function(n){void 0!==e[n]&&(t[n]=e[n])}),new Proxy({},{get:function(e,n){if("string"==typeof n)return u.call(t,n)}})}},944:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.registerApis=t.generateApis=void 0;var i=n(378);Object.defineProperty(t,"generateApis",{enumerable:!0,get:function(){return i.generateApis}});var a="apis",c={name:a,IIFE:!0,entity:function(){Object.defineProperty(this.prototype,a,{get:function(){return i.generateApis.call(this)},configurable:!0,enumerable:!0})}};function s(e){try{e.registerComponent(c)}catch(e){console.warn(e)}}t.registerApis=s;try{cloudbase.registerComponent(c)}catch(e){}o(n(26),t);try{window.registerApis=s}catch(e){}},26:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMMUNITY_SITE_URL=t.IS_DEBUG_MODE=t.getProtocol=t.setProtocol=t.getSdkName=t.setSdkName=void 0;var n="@cloudbase/js-sdk";t.setSdkName=function(e){n=e},t.getSdkName=function(){return n};var r="https:";t.setProtocol=function(e){r=e},t.getProtocol=function(){return r},t.IS_DEBUG_MODE=!1,t.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},205:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ERRORS=void 0,t.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(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.OATUH_LOGINTYPE=void 0,o(n(946),t),o(n(205),t),t.OATUH_LOGINTYPE="constants"}},t={};return function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(944)})());