"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.innerRequest=innerRequest,exports.getGamePkgList=getGamePkgList,exports.getGamePkgUrl=getGamePkgUrl,exports.checkGamePkgUserVersion=checkGamePkgUserVersion;const tslib_1=require("tslib"),url_config_1=require("../../config/url.config"),log=tslib_1.__importStar(require("../../utils/log")),request_1=require("../../utils/request"),sign_1=require("../../utils/sign");async function innerRequest(e,r){const s=await(0,request_1.request)({url:e,method:"post",body:r,headers:{"content-type":"application/json"}});let i;try{i=JSON.parse(s.body)}catch(r){const s=`request ${e} failed: resp body is not a valid json`;throw log.error(s),new Error(s)}if(0!==i.errCode){const e=`request failed, errCode: ${i.errCode}, errMsg: ${i.errMsg}`;throw log.error(e),new Error(e)}return i.data}async function getGamePkgList(e){var r,s;const i=await(0,sign_1.getSignature)(e.privateKey,e.appid),t=await innerRequest(""+url_config_1.GET_PLUG_PKG_GET_LIST,JSON.stringify({appid:e.appid,signature:i}));return{success:0===(null===(r=null==t?void 0:t.baseresponse)||void 0===r?void 0:r.errcode),errmsg:null===(s=null==t?void 0:t.baseresponse)||void 0===s?void 0:s.errmsg,list:t.commit_list||[]}}async function getGamePkgUrl(e,r){var s,i;const t=await(0,sign_1.getSignature)(e.privateKey,e.appid),n=await innerRequest(""+url_config_1.GET_PLUG_PKG_GET_URL,JSON.stringify({appid:e.appid,signature:t,user_version:r}));return{success:0===(null===(s=null==n?void 0:n.baseresponse)||void 0===s?void 0:s.errcode),errmsg:null===(i=null==n?void 0:n.baseresponse)||void 0===i?void 0:i.errmsg,url:n.url||"url not found"}}async function checkGamePkgUserVersion(e,r){var s,i;const t=await(0,sign_1.getSignature)(e.privateKey,e.appid),n=await innerRequest(""+url_config_1.GET_PLUG_PKG_CHECK_USERVERSION,JSON.stringify({appid:e.appid,signature:t,user_version:r}));return{success:0===(null===(s=null==n?void 0:n.baseresponse)||void 0===s?void 0:s.errcode),errmsg:null===(i=null==n?void 0:n.baseresponse)||void 0===i?void 0:i.errmsg}}