"use strict";var __assign=this&&this.__assign||function(){__assign=Object.assign||function(s){for(var o,r=1,a=arguments.length;r<a;r++){o=arguments[r];for(var n in o)if(Object.prototype.hasOwnProperty.call(o,n))s[n]=o[n]}return s};return __assign.apply(this,arguments)};var __awaiter=this&&this.__awaiter||function(s,o,r,a){function n(t){return t instanceof r?t:new r(function(u){u(t)})}return new(r||(r=Promise))(function(t,u){function c(i){try{e(a.next(i))}catch(f){u(f)}}function l(i){try{e(a["throw"](i))}catch(f){u(f)}}function e(i){i.done?t(i.value):n(i.value).then(c,l)}e((a=a.apply(s,o||[])).next())})};var __generator=this&&this.__generator||function(s,o){var r={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},a,n,t,u=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return u.next=c(0),u["throw"]=c(1),u["return"]=c(2),typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function c(e){return function(i){return l([e,i])}}function l(e){if(a)throw new TypeError("Generator is already executing.");while(u&&(u=0,e[0]&&(r=0)),r)try{if(a=1,n&&(t=e[0]&2?n["return"]:e[0]?n["throw"]||((t=n["return"])&&t.call(n),0):n.next)&&!(t=t.call(n,e[1])).done)return t;if(n=0,t)e=[e[0]&2,t.value];switch(e[0]){case 0:case 1:t=e;break;case 4:r.label++;return{value:e[1],done:false};case 5:r.label++;n=e[1];e=[0];continue;case 7:e=r.ops.pop();r.trys.pop();continue;default:if(!(t=r.trys,t=t.length>0&&t[t.length-1])&&(e[0]===6||e[0]===2)){r=0;continue}if(e[0]===3&&(!t||e[1]>t[0]&&e[1]<t[3])){r.label=e[1];break}if(e[0]===6&&r.label<t[1]){r.label=t[1];t=e;break}if(t&&r.label<t[2]){r.label=t[2];r.ops.push(e);break}if(t[2])r.ops.pop();r.trys.pop();continue}e=o.call(s,r)}catch(i){e=[6,i];n=0}finally{a=t=0}if(e[0]&5)throw e[1];return{value:e[0]?e[1]:void 0,done:true}}};Object.defineProperty(exports,"__esModule",{value:true});exports.createCallFunction=void 0;var error_1=require("./error");var utils_1=require("./utils");var createCallFunction=function(s){var o=s.httpclient;var r=function(a){return __awaiter(void 0,void 0,void 0,function(){var n,t,u,c,l,e,i;return __generator(this,function(f){switch(f.label){case 0:if(!a.name){throw error_1.FaasError.INVALID_PARAM_ERR("name","\u7F3A\u5931")}n=__assign(__assign({},a.headers),{"x-to-function-name":a.name,"x-alipay-cloud-mode":"function"});if(a.async){n["x-function-invoke-type"]="async"}t="POST";u="/functions/invokeFunction";return[4,o.request({method:t,path:u,data:a.data,headers:n,responseDataType:a.resultDataType,timeout:a.timeout})];case 1:c=f.sent();if(c.status!==200){l=-1;e="";i=c.data;if(i){l=i.errCode,e=i.errMsg;if(i.errDetail){e+="\uFF0C\u8BE6\u60C5\uFF1A".concat(i.errDetail)}}throw error_1.FaasError.SERVER_ERR(l,e,c.requestID,c.status)}return[2,{requestID:c.requestID,result:c.data,headers:c.headers}]}})})};return(0,utils_1.wrapCallback)(r)};exports.createCallFunction=createCallFunction;