"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ciSimpleRequest=ciSimpleRequest,exports.ciCustomRequest=ciCustomRequest;const request_1=require("../../utils/request"),sign_1=require("../../utils/sign"),jsonParse_1=require("../../utils/jsonParse");async function ciSimpleRequest({privateKey:e,appid:r,cgi:t,robot:s},o={}){let i;try{const a=await(0,sign_1.getSignature)(e,r),{body:n}=await(0,request_1.request)({url:t,method:"post",body:JSON.stringify(Object.assign({appid:r,signature:a,robot:s},o)),headers:{"content-type":"application/json"}});i=(0,jsonParse_1.jsonRespParse)(n,t)}catch(e){throw new Error(`${t} fail ${e}`)}if(0===i.errCode)return i.data;throw new Error(`${t} fail errCode: ${i.errCode}, errMsg: ${i.errMsg}`)}async function ciCustomRequest(e,r,t){const s=await(0,request_1.request)({url:e,method:"post",body:r,headers:t||{"content-type":"application/json"}});let o;try{o=JSON.parse(s.body)}catch(r){throw new Error(`request ${e} failed: resp body is not a valid json`)}if(0!==o.errCode)throw new Error(`request failed, errCode: ${o.errCode}, errMsg: ${o.errMsg}`);return o.data}