UNPKG

@cloudbase/js-sdk

Version:
2 lines 23.2 kB
import*as t from"@cloudbase/adapter-interface";import*as e from"jwt-decode";var n={388:t=>{t.exports={}}},r={};function o(t){var e=r[t];if(void 0!==e)return e.exports;var a=r[t]={exports:{}};return n[t](a,a.exports,o),a.exports}o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var a={};(()=>{o.d(a,{r:()=>B});var n=o(388);function r(){return"@cloudbase/js-sdk"}var c={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"};const i=(s={AbstractSDKRequest:()=>t.AbstractSDKRequest,AbstractStorage:()=>t.AbstractStorage},u={},o.d(u,s),u);var s,u;function l(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var f,p,d=(f=function(t,e){return f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},f(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}f(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),h=function(){return h=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},h.apply(this,arguments)},y=function(t,e,n,r){return new(n||(n=Promise))(function(o,a){function c(t){try{s(r.next(t))}catch(t){a(t)}}function i(t){try{s(r.throw(t))}catch(t){a(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(c,i)}s((r=r.apply(t,e||[])).next())})},v=function(t,e){var n,r,o,a,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,a=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=a||["get","post","upload","download"],n}d(e,t),e.prototype.get=function(t){return this.request(h(h({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(h(h({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(h(h({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,a=t.headers,c=void 0===a?{}:a,i={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",s=new FormData;return"post"===i?(Object.keys(e).forEach(function(t){s.append(t,e[t])}),s.append("key",r),s.append("file",n),this.request(h(h({},t),{data:s,method:i}),this.restrictedMethods.includes("upload"))):this.request(h(h({},t),{method:"put",headers:c,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return y(this,void 0,Promise,function(){var e,n,r,o;return v(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,this.get(h(h({},t),{headers:{},responseType:"blob"}))];case 1:return e=a.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return a.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return y(this,void 0,Promise,function(){var n,r,o,a,c,i,s,u,l,f,p,d,b,m=this;return v(this,function(g){switch(g.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,a=void 0!==o&&o,c=t.stream,i=void 0!==c&&c,s=t.signal,u=t.timeout,l=t.shouldThrowOnError,f=void 0===l||l,p=null!=u?u:this.timeout,s&&(s.aborted&&n.abort(),s.addEventListener("abort",function(){return n.abort()})),d=null,a&&p&&(d=setTimeout(function(){console.warn(m.timeoutMsg),n.abort(new Error(m.timeoutMsg))},p)),[4,fetch(r,h(h({},t),{signal:n.signal})).then(function(t){return y(m,void 0,void 0,function(){var e,n,r;return v(this,function(o){switch(o.label){case 0:return clearTimeout(d),f?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(d),Promise.reject(t)})];case 1:return b=g.sent(),[2,{data:i?b.body:(null===(e=b.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?b.json():b.text(),statusCode:b.status,header:b.headers,response:b}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var a=t.url,c=t.headers,i=void 0===c?{}:c,s=t.data,u=t.responseType,l=t.withCredentials,f=t.body,p=t.onUploadProgress,d=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",a,"get"===r?s:{}),h=new XMLHttpRequest;h.open(r,d),u&&(h.responseType=u);var y,v,b,m=t.signal;m&&(m.aborted?h.abort():m.addEventListener("abort",function(){return h.abort()},{once:!0})),Object.keys(i).forEach(function(t){h.setRequestHeader(t,i[t])}),p&&h.upload.addEventListener("progress",p),h.onreadystatechange=function(){var t={};if(4===h.readyState){var e=h.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=h.status;try{t.data="blob"===u?h.response:JSON.parse(h.responseText)}catch(e){t.data="blob"===u?h.response:h.responseText}clearTimeout(y),o(t)}},e&&n.timeout&&(y=setTimeout(function(){console.warn(n.timeoutMsg),h.abort()},n.timeout)),b=s,v="[object FormData]"===Object.prototype.toString.call(b)?s:"application/x-www-form-urlencoded"===i["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(s):f||(s?JSON.stringify(s):void 0),l&&(h.withCredentials=!0),h.send(v)})}}(i.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(p||(p={}));var b=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),m=function(t,e,n,r){return new(n||(n=Promise))(function(o,a){function c(t){try{s(r.next(t))}catch(t){a(t)}}function i(t){try{s(r.throw(t))}catch(t){a(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(c,i)}s((r=r.apply(t,e||[])).next())})},g=function(t,e){var n,r,o,a,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},w=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return b(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(i.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,a=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(l(c.INVALID_PARAMS,"localStorage is not supported on current platform"),new w(e.root));case"none":return new w(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=a)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:c.OPERATION_FAIL,msg:"[".concat("@cloudbase/js-sdk","][").concat(c.OPERATION_FAIL,"]setStore failed"),info:t}))}}else l(c.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return m(this,void 0,void 0,function(){var r;return g(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}l(c.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return m(this,void 0,void 0,function(){var r;return g(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):l(c.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return m(this,void 0,void 0,function(){return g(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})}}();var O=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),I=function(t,e){this.data=e||null,this.name=t},_=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return O(e,t),e}(I),A=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof _)return console.error(t.error),this;var n="string"==typeof t?new I(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,a=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o<a;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<a.length;o++)a[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new A,new A,"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const S=(t=>{var e={};return o.d(e,t),e})({default:()=>e.default});S.default;var x=function(){return x=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},x.apply(this,arguments)},R=function(t,e,n,r){return new(n||(n=Promise))(function(o,a){function c(t){try{s(r.next(t))}catch(t){a(t)}}function i(t){try{s(r.throw(t))}catch(t){a(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(c,i)}s((r=r.apply(t,e||[])).next())})},j=function(t,e){var n,r,o,a,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},P=c,E="cloudrun";function N(t,e){var n;return R(this,void 0,void 0,function(){var r,o,a,c,i,s,u,l,f,p,d,h,y,v,b;return j(this,function(m){switch(m.label){case 0:if(r=t.name,o=t.data,a=t.path,c=void 0===a?"":a,i=t.method,s=t.header,u=void 0===s?{}:s,l=this.getEndPointWithKey("GATEWAY"),f=l.BASE_URL,p=l.PROTOCOL,d="".concat(p).concat(f,"/cloudrun/").concat(r),h=c.startsWith("/")?c:"/".concat(c),y=["GET","HEAD"].includes(null===(n=null==i?void 0:i.toUpperCase)||void 0===n?void 0:n.call(i)))try{v={};try{v=JSON.parse(o)}catch(t){v=o||{}}h="".concat(h).concat(h.includes("?")?"&":"?").concat(Object.keys(v).map(function(t){return"".concat(t,"=").concat(v[t])}).join("&"))}catch(t){}return[4,this.request.fetch(x(x({method:i||"POST",headers:Object.assign({},{"Content-Type":"application/json; charset=utf-8"},u)},y?{}:{body:o}),{url:"".concat(d).concat(h),customReqOpts:e}))];case 1:return b=m.sent(),"node-sdk"===(null==e?void 0:e.from)?[2,b]:[4,b.data];case 2:return[2,m.sent()]}})})}var C=new(function(){function t(){}return t.prototype.callContainer=function(t,e){return R(this,void 0,void 0,function(){var n,r,o;return j(this,function(a){switch(a.label){case 0:if(n=t.name,r=t.data,!n)throw new Error(JSON.stringify({code:P.INVALID_PARAMS,msg:"[".concat(E,".callContainer] invalid name")}));try{o=r?JSON.stringify(r):""}catch(t){throw new Error(JSON.stringify({code:P.INVALID_PARAMS,msg:"[".concat(E,".callContainer] invalid data")}))}return[4,N.call(this,x(x({},t),{data:o}),e)];case 1:return[2,a.sent()]}})})},t}()),L={name:E,entity:{callContainer:C.callContainer}};try{cloudbase.registerComponent(L)}catch(t){}try{window.registerCloudrun=function(t){try{t.registerComponent(L)}catch(t){console.warn(t)}}}catch(t){}var T=function(){return T=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},T.apply(this,arguments)},k=function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},D=r,M=c,q=function(t,e,n){if(void 0===n&&(n=null),t&&"function"==typeof t)return t(e,n);if(e)throw e;return n},F="functions",U=new(function(){function t(){}var e,r,o,a;return t.prototype.callFunction=function(t,e,n){var r,o,a,c,i,s,u;return c=this,i=void 0,u=function(){var c,i,s,u,l,f,p,d,h,y,v,b,m,g,w,O,I,_,A,S,x,R,j;return function(t,e){var n,r,o,a,c={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(c=0)),c;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,r=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!((o=(o=c.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){c=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){c.label=i[1];break}if(6===i[0]&&c.label<o[1]){c.label=o[1],o=i;break}if(o&&c.label<o[2]){c.label=o[2],c.ops.push(i);break}o[2]&&c.ops.pop(),c.trys.pop();continue}i=e.call(t,c)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}(this,function(P){switch(P.label){case 0:if(c=t.name,i=t.data,s=t.query,u=t.parse,l=t.search,f=t.type,p=t.path,d=void 0===p?"":p,h=t.method,y=t.header,v=void 0===y?{}:y,!c)throw new Error(JSON.stringify({code:M.INVALID_PARAMS,msg:"[".concat(F,".callFunction] invalid function name")}));try{b=i?JSON.stringify(i):""}catch(t){throw new Error(JSON.stringify({code:M.INVALID_PARAMS,msg:"[".concat(F,".callFunction] invalid data")}))}return"cloudrun"!==f?[3,2]:(C=(new Date).getTime(),L=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0,m="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random();return C>0?(e=(C+e)%16|0,C=Math.floor(C/16)):(e=(L+e)%16|0,L=Math.floor(L/16)),("x"===t?e:7&e|8).toString(16)}),[4,N.call(this,{name:c,data:b,path:d,method:h,header:T(T({},v),{"X-Request-Id":m})})]);case 1:return[2,{result:R=P.sent(),requestId:m}];case 2:w=(g=this).request,O=g.config,I="functions.invokeFunction",_={inQuery:s,parse:u,search:l,function_name:c,request_data:b},A={},S=!("GATEWAY"!==O.endPointMode||(E=c,"lcap-common-service"===E||"lcap-datasource-test"===E||E.startsWith("lcap-data")||E.startsWith("lowcode-datasource")||"cloudbase_module"===E)||function(t){return"lowcode-wx-datasource"===t}(c)),P.label=3;case 3:return P.trys.push([3,8,,9]),S?[4,w.gateWay(T(T({},t),{path:"functions"}),n)]:[3,5];case 4:return x=P.sent(),A=T({requestId:x.requestId},(null===(r=x.data)||void 0===r?void 0:r.code)?x.data:{data:{response_data:x.data}}),[3,7];case 5:return[4,w.send(I,_,{endPointMode:"CLOUD_API",defaultQuery:(null===(o=null==i?void 0:i.params)||void 0===o?void 0:o.action)?{action:null===(a=null==i?void 0:i.params)||void 0===a?void 0:a.action}:{}},n)];case 6:A=P.sent(),P.label=7;case 7:if(A.code)return[2,q(e,null,A)];if(R=A.data.response_data,u||S)return[2,q(e,null,{result:R,requestId:A.requestId})];try{return R=JSON.parse(A.data.response_data),[2,q(e,null,{result:R,requestId:A.requestId})]}catch(t){q(e,new Error("[".concat(D(),"][").concat(M.INVALID_PARAMS,"][").concat(F,".callFunction] response data must be json")))}return[3,9];case 8:return j=P.sent(),q(e,j),[3,9];case 9:return[2]}var E,C,L})},new((s=void 0)||(s=Promise))(function(t,e){function n(t){try{o(u.next(t))}catch(t){e(t)}}function r(t){try{o(u.throw(t))}catch(t){e(t)}}function o(e){var o;e.done?t(e.value):(o=e.value,o instanceof s?o:new s(function(t){t(o)})).then(n,r)}o((u=u.apply(c,i||[])).next())})},function(t,e,n,r){var o,a=arguments.length,c=a<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(t,e,n,r);else for(var i=t.length-1;i>=0;i--)(o=t[i])&&(c=(a<3?o(c):a>3?o(e,n,c):o(e,n))||c);a>3&&c&&Object.defineProperty(e,n,c)}([(a={customInfo:{className:"Cloudbase",methodName:"callFunction"},title:"函数调用失败",messages:["请确认以下各项:"," 1 - 调用 callFunction() 的语法或参数是否正确"," 2 - 当前环境下是否存在此函数"," 3 - 函数安全规则是否限制了当前登录状态访问","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat("https://support.qq.com/products/148793")]},a.mode,a.customInfo,a.title,a.messages,function(t,e,n){}),k("design:type",Function),k("design:paramtypes",["function"==typeof(e=void 0!==n.ICallFunctionOptions&&n.ICallFunctionOptions)?e:Object,"function"==typeof(r="undefined"!=typeof Function&&Function)?r:Object,"function"==typeof(o=void 0!==n.ICustomReqOpts&&n.ICustomReqOpts)?o:Object]),k("design:returntype",Promise)],t.prototype,"callFunction",null),t}()),W={name:F,entity:{callFunction:U.callFunction}};try{cloudbase.registerComponent(W)}catch(t){}var B=function(t){try{t.registerComponent(W)}catch(t){console.warn(t)}};try{window.registerFunctions=B}catch(t){}})();var c=a.r;export{c as registerFunctions}; //# sourceMappingURL=index.esm.js.map