"use strict";var __importDefault=this&&this.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenapiCaller=void 0;const faas_common_sdk_1=require("@alipay/faas-common-sdk"),snakecase_keys_1=__importDefault(require("snakecase-keys")),constant_1=require("../constant"),errors_1=require("../errors"),requester_1=require("../requester"),formData_1=require("./formData");class OpenapiCaller{#e;#s;#t;constructor({config:t,version:e,sandbox:a}){this.#e=e||constant_1.OPENAPI_VERSION,this.#s=!!a,this.#t=requester_1.Httpclient.createOpenapiHttpclient(t)}async requestRaw(t,e,a,n){const{res:o}=await this.#t.requestRaw({method:t,path:e,data:a,headers:n});return o}async request(t,e){const a="POST",n="/functions/invokeOpenapi",{callbackFunction:o,...c}=e||{},u=this.#r(c),p=this.#a(t,o),s=await this.#t.request({method:a,path:n,data:u,headers:p});if(s.status!==200){const{code:_,message:d,errCode:h,errMsg:f}=s.data;throw faas_common_sdk_1.FaasError.SERVER_ERR(_||h,d||f,s.requestID,s.status)}const l=`${t.replace(/\./g,"_")}_response`,i=s.data?.[l];if(!i)throw errors_1.errors.INVALID_OPENAPI_RESPONSE_ERR(s.requestID,s.data||"");return i}async sdkExecute(t,e){const a="POST",n="/functions/invokeOpenapi/sdkExecute",{callbackFunction:o,...c}=e||{},u=this.#r(c),p=this.#a(t,o),s=await this.#t.request({method:a,path:n,data:u,headers:p});if(s.status!==200){const{code:l,message:i,errCode:_,errMsg:d}=s.data;throw faas_common_sdk_1.FaasError.SERVER_ERR(l||_,i||d,s.requestID,s.status)}return s.data.sign}#a(t,e){return{"x-openapi":t,"x-openapi-version":this.#e,"x-openapi-env":this.#s?"sandbox":"","x-openapi-callback-function":e}}#r(t){if(t.formData&&t.formData instanceof formData_1.AlipayFormData)return formData_1.FormDataBody.createFromAlipayFormData(t.formData);const e=(0,snakecase_keys_1.default)(Object.assign({},t),{deep:!0});return e.biz_content&&typeof e.biz_content!="string"&&(e.biz_content=JSON.stringify(e.biz_content)),e}}exports.OpenapiCaller=OpenapiCaller;