/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@workablehr/riviere@1.22.0/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const defaultsDeep=require("lodash/defaultsDeep"),Counter=require("passthrough-counter"),Loggable=require("./lib/loggable"),defaultOptions=require("./lib/options"),utils=require("./lib/utils"),httpProxy=require("./lib/proxies/http").proxy,httpsProxy=require("./lib/proxies/https").proxy,{EVENT:EVENT}=Loggable;function buildRiviere(e={}){const{errors:t={},logger:r,inbound:o,outbound:l,traceHeaderName:a,headersRegex:i,headerValueCallback:s,hostFieldName:n}=defaultsDeep(e,defaultOptions(e)),d=new Loggable(e);if(l.enabled){const t=e.adapter.requestProxy({level:l.level,logger:r,traceHeaderName:a,opts:{headersRegex:i,bodyKeys:e.bodyKeys,bodyKeysRegex:e.bodyKeysRegex,bodyKeysCallback:e.bodyKeysCallback,hostFieldName:n,headerValueCallback:s,...l}});httpProxy(t),l.https&&httpsProxy(t)}return async function(e,l){e.state.riviereStartedAt=(new Date).getTime(),o.enabled&&o.request.enabled&&utils.safeExec((()=>d.emit(EVENT.INBOUND_REQUEST,{ctx:e})),r);try{await l()}catch(i){t.enabled&&utils.safeExec((()=>d.emit(EVENT.UNEXPECTED_ERROR,{ctx:e,err:i})),r),"function"==typeof t.callback&&await t.callback(i,e)}finally{if(o.enabled){const s=e.response.length;let n;!s&&e.body&&e.body.readable&&(e.body=e.body.pipe(n=Counter()).on("error",e.onerror));const u=e.res;function a(t){u.removeListener("finish",a),u.removeListener("close",a),e.state.calculatedContentLength=n?n.length:s,utils.safeExec((()=>d.emit(EVENT.OUTBOUND_RESPONSE,{ctx:e})),r)}u.once("finish",a),u.once("close",a)}}}}buildRiviere.riviere=buildRiviere,module.exports=buildRiviere;
//# sourceMappingURL=/sm/5a1ab75599fe4452cf7a51b8341d7e103d0c497e1e3f531d6af80793cbe8b289.map