@netacea/akamai 6.1.128 → 6.1.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{httpRequest as t}from"http-request";import*as e from"crypto";import*as n from"encoding";import{v7 as i}from"uuid";var r,a,o;!function(t){t.ORIGIN="ORIGIN",t.HTTP="HTTP",t.KINESIS="KINESIS",t.NATIVE="NATIVE"}(r||(r={})),function(t){t.MITIGATE="MITIGATE",t.INJECT="INJECT",t.INGEST="INGEST"}(a||(a={})),function(t){t.CAPTCHA_GET="captcha_get",t.CAPTCHA_POST="captcha_post",t.EXPIRED_SESSION="expired_session",t.FORCED_REVALIDATION="forced_revalidation",t.INVALID_SESSION="invalid_session",t.IP_CHANGE="ip_change",t.NO_SESSION="no_session"}(o||(o={}));const s="ignored";function c(){return{mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0",issueReason:o.NO_SESSION}}function u(t,e){const n=t.split(";").map((t=>t.trim())).filter((t=>t.toLowerCase().startsWith(e.toLowerCase())))[0];return void 0!==n&&n.length>0?n?.replace(`${e}=`,""):void 0}function h(t,e=!1){return"string"!=typeof t&&(t=t.join("; ")),""===t?"":f(t.split(";"),e).join("; ")}function f(t,e=!1){if(e)return f(t.reverse()).reverse();const n=new Set,i=[];for(let e of t){if(e=e.trimStart(),""===e.trim())continue;const t=e.split("=")[0].toUpperCase();n.has(t)||(n.add(t),i.push(e))}return i}function p(t){const e=h([t.otherAttributes??"",`Max-Age=${t.maxAgeAttribute??86400}`,"Path=/"].join("; "));return`${t.cookieName}=${t.cookieValue}; ${e}`}const l={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(t,e){let n=t=h(t??"",!0),i=e=h(e??"",!0);if(void 0!==t&&void 0!==e){const r=u(t,"Domain"),a=u(e,"Domain");void 0!==r&&void 0!==a?i=e.replace(a,r):void 0!==r&&void 0===a?i=e+(""!==e?`; Domain=${r}`:`Domain=${r}`):void 0===r&&void 0!==a&&(n=t+(""!==t?`; Domain=${a}`:`Domain=${a}`))}else if(void 0!==t&&void 0===e){const e=u(t,"Domain");void 0!==e&&(i=`Domain=${e}`)}else if(void 0===t&&void 0!==e){const t=u(e,"Domain");void 0!==t&&(n=`Domain=${t}`)}return{cookieAttributes:""!==n?n:void 0,captchaCookieAttributes:""!==i?i:void 0}},extractAndRemoveCookieAttr:function(t,e){const n=u(t,e);if(void 0!==n){return{extractedAttribute:n,cookieAttributes:t.replace(/ /g,"").replace(`${e}=${n}`,"").split(";").filter((t=>t.length>0)).join("; ")}}return{extractedAttribute:void 0,cookieAttributes:t}},extractCookieAttr:u,removeDuplicateAttrs:h}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(t){return p({...t,cookieName:t.cookieName??"_mitatacaptcha"})},createNetaceaSetCookieString:function(t){return p({...t,cookieName:t.cookieName??"_mitata"})},createSetCookieString:p})}},{configureCookiesDomain:d}=l.cookie.attributes,g="PMUSER_NETACEA_";class y{constructor(t){this.getNumber=(t,e)=>{const n=this.getString(t);try{const t=Number(n);if(!isNaN(t))return t}catch{}return e},this.getBoolean=(t,e)=>{const n=this.getString(t);return void 0!==n?"true"===(n?.toLowerCase()??"false"):e},this.request=t}getString(t,e){t.startsWith(g)&&(t=t.slice(15));const n=`${g}${t}`;return this.request.getVariable(n)??e??e}}class m{constructor(t){this.defaults=t}getMaxErrorLogLength(t){const e=new y(t).getNumber("MAX_ERR_LOG_LEN")??0;return e>0?Math.min(500,e):0}loadConfig(t){const e=new y(t),n=e.getString("MITIGATION_TYPE",this.defaults.mitigationType),i=e.getString("INGEST_TYPE",this.defaults.ingestType),r=e.getString("COOKIE_ATTR"),a=e.getString("CAP_COOKIE_ATTR"),{cookieAttributes:o,captchaCookieAttributes:s}=d(r,a);let c=e.getString("CAPT_PATH");void 0!==c&&c.length>0&&"/"!==c?.[0]&&(c=`/${c}`);const u=e.getString("SECRET_KEY",this.defaults.secretKey);if(void 0===u||""===u)throw new Error("A secret key is required to configure this integration.");const h=e.getString("INGEST_URL");let f;f=void 0!==h?h:this.defaults.ingestServiceUrl??"https://ingest.netacea.net";const p=e.getString("MITIGATION_URL");let l;l=void 0!==p?p:this.defaults.mitigationServiceUrl??"https://mitigations.netacea.net";const g={...this.defaults,mitigationServiceUrl:l,ingestServiceUrl:f,apiKey:e.getString("API_KEY",this.defaults.apiKey),cookieEncryptionKey:e.getString("ENCRYPTION_KEY",this.defaults.cookieEncryptionKey),ingestType:i,mitigationType:n,altCookieHeaderName:e.getString("ALT_COOKIE_HEADER"),netaceaCaptchaCookieAttributes:s??"",netaceaCaptchaCookieName:e.getString("CAPT_COOKIE_NAME",this.defaults.netaceaCaptchaCookieName)??"_mitatacaptcha",netaceaCookieAttributes:o??"",netaceaCookieExpirySeconds:w(this.defaults,n),netaceaCookieName:e.getString("COOKIE_NAME",this.defaults.netaceaCookieName)??"_mitata",netaceaCaptchaPath:c,netaceaCaptchaHeaderKey:e.getString("CAPT_HEADER_KEY"),netaceaCaptchaHeaderValue:e.getString("CAPT_HEADER_VALUE"),netaceaCaptchaResponseStatus:e.getString("CAPT_STATUS"),netaceaBlockedResponseStatus:e.getString("BLOCK_STATUS"),netaceaBlockedResponseRedirectLocation:e.getString("BLOCK_LOCATION"),captchaContentNegotiation:e.getBoolean("CAPT_CONTENT_NGT",!1)??!1,secretKey:u,useCaptchaRelAssets:e.getBoolean("CAPT_REL_ASSETS",this.defaults.useCaptchaRelAssets)??!1,protoMitataVariableName:"PMUSER_NETACEA_PROTO_MITATA",encryptedCookieNames:[],netaceaCheckpointSignalPath:e.getString("SIGNAL_PATH")};return void 0===g.netaceaCookieName&&(g.netaceaCookieName="_mitata"),void 0===g.netaceaCaptchaCookieName&&(g.netaceaCaptchaCookieName="_mitatacaptcha"),g.encryptedCookieNames.push(g.netaceaCookieName),g.encryptedCookieNames.push(g.netaceaCaptchaCookieName),void 0!==g.netaceaCaptchaHeaderKey&&void 0===g.netaceaCaptchaHeaderValue&&(g.netaceaCaptchaHeaderValue="true"),g}}function w(t,e){const n=t.netaceaCookieExpirySeconds??t.mitataCookieExpirySeconds;return void 0===n?e===a.INGEST?3600:60:n}const S=/\.(js|css)$/i;function E(t,e,n){if(!0!==n)return!1;const i=t.toLowerCase();return/\/?mitigations\//.test(i)&&I(t,e)}function I(t,e){const n=t.toLowerCase();return S.test(n)&&"get"===e.toLowerCase()}function C(t,e){return/\/?ataverifycaptcha$/.test(t.toLowerCase())&&"post"===e.toLowerCase()}function v(t,e,n){return void 0!==n&&n.length>0&&t===n&&"get"===e.toLowerCase()}var b=e.crypto??e;const A=n.TextEncoder??global.TextEncoder,N=n.TextDecoder??global.TextDecoder;function k(t){return"string"==typeof t?(new A).encode(t):t}async function R(t,e){const n=await _(k(e));return new Uint8Array(await b.subtle.sign("HMAC",n,t))}async function _(t){return await b.subtle.importKey("raw",t,{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}for(var T={},B={byteLength:function(t){var e=M(t),n=e[0],i=e[1];return 3*(n+i)/4-i},toByteArray:function(t){var e,n,i=M(t),r=i[0],a=i[1],o=new x(function(t,e,n){return 3*(e+n)/4-n}(0,r,a)),s=0,c=a>0?r-4:r;for(n=0;n<c;n+=4)e=U[t.charCodeAt(n)]<<18|U[t.charCodeAt(n+1)]<<12|U[t.charCodeAt(n+2)]<<6|U[t.charCodeAt(n+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=255&e;2===a&&(e=U[t.charCodeAt(n)]<<2|U[t.charCodeAt(n+1)]>>4,o[s++]=255&e);1===a&&(e=U[t.charCodeAt(n)]<<10|U[t.charCodeAt(n+1)]<<4|U[t.charCodeAt(n+2)]>>2,o[s++]=e>>8&255,o[s++]=255&e);return o},fromByteArray:function(t){for(var e,n=t.length,i=n%3,r=[],a=16383,o=0,s=n-i;o<s;o+=a)r.push(H(t,o,o+a>s?s:o+a));1===i?(e=t[n-1],r.push(O[e>>2]+O[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],r.push(O[e>>10]+O[e>>4&63]+O[e<<2&63]+"="));return r.join("")}},O=[],U=[],x="undefined"!=typeof Uint8Array?Uint8Array:Array,P="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",L=0;L<64;++L)O[L]=P[L],U[P.charCodeAt(L)]=L;function M(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function H(t,e,n){for(var i,r,a=[],o=e;o<n;o+=3)i=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),a.push(O[(r=i)>>18&63]+O[r>>12&63]+O[r>>6&63]+O[63&r]);return a.join("")}U["-".charCodeAt(0)]=62,U["_".charCodeAt(0)]=63;var $={
1
+ import{httpRequest as t}from"http-request";import*as e from"crypto";import*as n from"encoding";import{v7 as i}from"uuid";var r,a,o;!function(t){t.ORIGIN="ORIGIN",t.HTTP="HTTP",t.KINESIS="KINESIS",t.NATIVE="NATIVE"}(r||(r={})),function(t){t.MITIGATE="MITIGATE",t.INJECT="INJECT",t.INGEST="INGEST"}(a||(a={})),function(t){t.CAPTCHA_GET="captcha_get",t.CAPTCHA_POST="captcha_post",t.EXPIRED_SESSION="expired_session",t.FORCED_REVALIDATION="forced_revalidation",t.INVALID_SESSION="invalid_session",t.IP_CHANGE="ip_change",t.NO_SESSION="no_session"}(o||(o={}));const s="ignored";function c(){return{mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0",issueReason:o.NO_SESSION}}function u(t,e){const n=t.split(";").map((t=>t.trim())).filter((t=>t.toLowerCase().startsWith(e.toLowerCase())))[0];return void 0!==n&&n.length>0?n?.replace(`${e}=`,""):void 0}function h(t,e=!1){return"string"!=typeof t&&(t=t.join("; ")),""===t?"":f(t.split(";"),e).join("; ")}function f(t,e=!1){if(e)return f(t.reverse()).reverse();const n=new Set,i=[];for(let e of t){if(e=e.trimStart(),""===e.trim())continue;const t=e.split("=")[0].toUpperCase();n.has(t)||(n.add(t),i.push(e))}return i}function p(t){const e=h([t.otherAttributes??"",`Max-Age=${t.maxAgeAttribute??86400}`,"Path=/"].join("; "));return`${t.cookieName}=${t.cookieValue}; ${e}`}const l={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(t,e){let n=t=h(t??"",!0),i=e=h(e??"",!0);if(void 0!==t&&void 0!==e){const r=u(t,"Domain"),a=u(e,"Domain");void 0!==r&&void 0!==a?i=e.replace(a,r):void 0!==r&&void 0===a?i=e+(""!==e?`; Domain=${r}`:`Domain=${r}`):void 0===r&&void 0!==a&&(n=t+(""!==t?`; Domain=${a}`:`Domain=${a}`))}else if(void 0!==t&&void 0===e){const e=u(t,"Domain");void 0!==e&&(i=`Domain=${e}`)}else if(void 0===t&&void 0!==e){const t=u(e,"Domain");void 0!==t&&(n=`Domain=${t}`)}return{cookieAttributes:""!==n?n:void 0,captchaCookieAttributes:""!==i?i:void 0}},extractAndRemoveCookieAttr:function(t,e){const n=u(t,e);if(void 0!==n){return{extractedAttribute:n,cookieAttributes:t.replace(/ /g,"").replace(`${e}=${n}`,"").split(";").filter((t=>t.length>0)).join("; ")}}return{extractedAttribute:void 0,cookieAttributes:t}},extractCookieAttr:u,removeDuplicateAttrs:h}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(t){return p({...t,cookieName:t.cookieName??"_mitatacaptcha"})},createNetaceaSetCookieString:function(t){return p({...t,cookieName:t.cookieName??"_mitata"})},createSetCookieString:p})}},{configureCookiesDomain:d}=l.cookie.attributes,g="PMUSER_NETACEA_";class y{constructor(t){this.getNumber=(t,e)=>{const n=this.getString(t);try{const t=Number(n);if(!isNaN(t))return t}catch{}return e},this.getBoolean=(t,e)=>{const n=this.getString(t);return void 0!==n?"true"===(n?.toLowerCase()??"false"):e},this.request=t}getString(t,e){t.startsWith(g)&&(t=t.slice(15));const n=`${g}${t}`;return this.request.getVariable(n)??e??e}}class m{constructor(t){this.defaults=t}getMaxErrorLogLength(t){const e=new y(t).getNumber("MAX_ERR_LOG_LEN")??0;return e>0?Math.min(500,e):0}loadConfig(t){const e=new y(t),n=e.getString("MITIGATION_TYPE",this.defaults.mitigationType),i=e.getString("INGEST_TYPE",this.defaults.ingestType),r=e.getString("COOKIE_ATTR"),a=e.getString("CAP_COOKIE_ATTR"),{cookieAttributes:o,captchaCookieAttributes:s}=d(r,a);let c=e.getString("CAPT_PATH");void 0!==c&&c.length>0&&"/"!==c?.[0]&&(c=`/${c}`);const u=e.getString("SECRET_KEY",this.defaults.secretKey);if(void 0===u||""===u)throw new Error("A secret key is required to configure this integration.");const h=e.getString("INGEST_URL");let f;f=void 0!==h?h:this.defaults.ingestServiceUrl??"https://ingest.netacea.net";const p=e.getString("MITIGATION_URL");let l;l=void 0!==p?p:this.defaults.mitigationServiceUrl??"https://mitigations.netacea.net";const g={...this.defaults,mitigationServiceUrl:l,ingestServiceUrl:f,apiKey:e.getString("API_KEY",this.defaults.apiKey),cookieEncryptionKey:e.getString("ENCRYPTION_KEY",this.defaults.cookieEncryptionKey),ingestType:i,mitigationType:n,altCookieHeaderName:e.getString("ALT_COOKIE_HEADER"),netaceaCaptchaCookieAttributes:s??"",netaceaCaptchaCookieName:e.getString("CAPT_COOKIE_NAME",this.defaults.netaceaCaptchaCookieName)??"_mitatacaptcha",netaceaCookieAttributes:o??"",netaceaCookieExpirySeconds:w(this.defaults,n),netaceaCookieName:e.getString("COOKIE_NAME",this.defaults.netaceaCookieName)??"_mitata",netaceaCaptchaPath:c,netaceaCaptchaHeaderKey:e.getString("CAPT_HEADER_KEY"),netaceaCaptchaHeaderValue:e.getString("CAPT_HEADER_VALUE"),netaceaCaptchaResponseStatus:e.getString("CAPT_STATUS"),netaceaBlockedResponseStatus:e.getString("BLOCK_STATUS"),netaceaBlockedResponseRedirectLocation:e.getString("BLOCK_LOCATION"),captchaContentNegotiation:e.getBoolean("CAPT_CONTENT_NGT",!1)??!1,secretKey:u,useCaptchaRelAssets:e.getBoolean("CAPT_REL_ASSETS",this.defaults.useCaptchaRelAssets)??!1,protoMitataVariableName:"PMUSER_NETACEA_PROTO_MITATA",encryptedCookieNames:[],netaceaCheckpointSignalPath:e.getString("SIGNAL_PATH")};return g.netaceaCookieName=S(g.netaceaCookieName,"_mitata"),g.netaceaCaptchaCookieName=S(g.netaceaCaptchaCookieName,"_mitatacaptcha"),g.encryptedCookieNames.push(g.netaceaCookieName),g.encryptedCookieNames.push(g.netaceaCaptchaCookieName),void 0!==g.netaceaCaptchaHeaderKey&&void 0===g.netaceaCaptchaHeaderValue&&(g.netaceaCaptchaHeaderValue="true"),g}}function w(t,e){const n=t.netaceaCookieExpirySeconds??t.mitataCookieExpirySeconds;return void 0===n?e===a.INGEST?3600:60:n}function S(t,e){return"string"==typeof t&&""!==t?t:"number"==typeof t?t.toString():e}const E=/\.(js|css)$/i;function I(t,e,n){if(!0!==n)return!1;const i=t.toLowerCase();return/\/?mitigations\//.test(i)&&C(t,e)}function C(t,e){const n=t.toLowerCase();return E.test(n)&&"get"===e.toLowerCase()}function b(t,e){return/\/?ataverifycaptcha$/.test(t.toLowerCase())&&"post"===e.toLowerCase()}function v(t,e,n){return void 0!==n&&n.length>0&&t===n&&"get"===e.toLowerCase()}var A=e.crypto??e;const N=n.TextEncoder??global.TextEncoder,k=n.TextDecoder??global.TextDecoder;function R(t){return"string"==typeof t?(new N).encode(t):t}async function _(t,e){const n=await T(R(e));return new Uint8Array(await A.subtle.sign("HMAC",n,t))}async function T(t){return await A.subtle.importKey("raw",t,{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}for(var B={},O={byteLength:function(t){var e=H(t),n=e[0],i=e[1];return 3*(n+i)/4-i},toByteArray:function(t){var e,n,i=H(t),r=i[0],a=i[1],o=new P(function(t,e,n){return 3*(e+n)/4-n}(0,r,a)),s=0,c=a>0?r-4:r;for(n=0;n<c;n+=4)e=x[t.charCodeAt(n)]<<18|x[t.charCodeAt(n+1)]<<12|x[t.charCodeAt(n+2)]<<6|x[t.charCodeAt(n+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=255&e;2===a&&(e=x[t.charCodeAt(n)]<<2|x[t.charCodeAt(n+1)]>>4,o[s++]=255&e);1===a&&(e=x[t.charCodeAt(n)]<<10|x[t.charCodeAt(n+1)]<<4|x[t.charCodeAt(n+2)]>>2,o[s++]=e>>8&255,o[s++]=255&e);return o},fromByteArray:function(t){for(var e,n=t.length,i=n%3,r=[],a=16383,o=0,s=n-i;o<s;o+=a)r.push($(t,o,o+a>s?s:o+a));1===i?(e=t[n-1],r.push(U[e>>2]+U[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],r.push(U[e>>10]+U[e>>4&63]+U[e<<2&63]+"="));return r.join("")}},U=[],x=[],P="undefined"!=typeof Uint8Array?Uint8Array:Array,L="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",M=0;M<64;++M)U[M]=L[M],x[L.charCodeAt(M)]=M;function H(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function $(t,e,n){for(var i,r,a=[],o=e;o<n;o+=3)i=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(255&t[o+2]),a.push(U[(r=i)>>18&63]+U[r>>12&63]+U[r>>6&63]+U[63&r]);return a.join("")}x["-".charCodeAt(0)]=62,x["_".charCodeAt(0)]=63;var K={
2
2
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
3
3
  read:function(t,e,n,i,r){var a,o,s=8*r-i-1,c=(1<<s)-1,u=c>>1,h=-7,f=n?r-1:0,p=n?-1:1,l=t[e+f];for(f+=p,a=l&(1<<-h)-1,l>>=-h,h+=s;h>0;a=256*a+t[e+f],f+=p,h-=8);for(o=a&(1<<-h)-1,a>>=-h,h+=i;h>0;o=256*o+t[e+f],f+=p,h-=8);if(0===a)a=1-u;else{if(a===c)return o?NaN:1/0*(l?-1:1);o+=Math.pow(2,i),a-=u}return(l?-1:1)*o*Math.pow(2,a-i)},write:function(t,e,n,i,r,a){var o,s,c,u=8*a-r-1,h=(1<<u)-1,f=h>>1,p=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,l=i?0:a-1,d=i?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,o=h):(o=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-o))<1&&(o--,c*=2),(e+=o+f>=1?p/c:p*Math.pow(2,1-f))*c>=2&&(o++,c/=2),o+f>=h?(s=0,o=h):o+f>=1?(s=(e*c-1)*Math.pow(2,r),o+=f):(s=e*Math.pow(2,f-1)*Math.pow(2,r),o=0));r>=8;t[n+l]=255&s,l+=d,s/=256,r-=8);for(o=o<<r|s,u+=r;u>0;t[n+l]=255&o,l+=d,o/=256,u-=8);t[n+l-d]|=128*g}};
4
4
  /*!
@@ -7,4 +7,4 @@ read:function(t,e,n,i,r){var a,o,s=8*r-i-1,c=(1<<s)-1,u=c>>1,h=-7,f=n?r-1:0,p=n?
7
7
  * @author Feross Aboukhadijeh <https://feross.org>
8
8
  * @license MIT
9
9
  */
10
- !function(t){const e=B,n=$,i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=function(t){+t!=t&&(t=0);return o.alloc(+t)},t.INSPECT_MAX_BYTES=50;const r=2147483647;function a(t){if(t>r)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,o.prototype),e}function o(t,e,n){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return u(t)}return s(t,e,n)}function s(t,e,n){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const n=0|l(t,e);let i=a(n);const r=i.write(t,e);r!==n&&(i=i.slice(0,r));return i}(t,e);if(ArrayBuffer.isView(t))return function(t){if(W(t,Uint8Array)){const e=new Uint8Array(t);return f(e.buffer,e.byteOffset,e.byteLength)}return h(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(W(t,ArrayBuffer)||t&&W(t.buffer,ArrayBuffer))return f(t,e,n);if("undefined"!=typeof SharedArrayBuffer&&(W(t,SharedArrayBuffer)||t&&W(t.buffer,SharedArrayBuffer)))return f(t,e,n);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const i=t.valueOf&&t.valueOf();if(null!=i&&i!==t)return o.from(i,e,n);const r=function(t){if(o.isBuffer(t)){const e=0|p(t.length),n=a(e);return 0===n.length||t.copy(n,0,0,e),n}if(void 0!==t.length)return"number"!=typeof t.length||J(t.length)?a(0):h(t);if("Buffer"===t.type&&Array.isArray(t.data))return h(t.data)}(t);if(r)return r;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return o.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function u(t){return c(t),a(t<0?0:0|p(t))}function h(t){const e=t.length<0?0:0|p(t.length),n=a(e);for(let i=0;i<e;i+=1)n[i]=255&t[i];return n}function f(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let i;return i=void 0===e&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,e):new Uint8Array(t,e,n),Object.setPrototypeOf(i,o.prototype),i}function p(t){if(t>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|t}function l(t,e){if(o.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||W(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const n=t.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===n)return 0;let r=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return F(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return X(t).length;default:if(r)return i?-1:F(t).length;e=(""+e).toLowerCase(),r=!0}}function d(t,e,n){let i=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,n);case"utf8":case"utf-8":return b(this,e,n);case"ascii":return N(this,e,n);case"latin1":case"binary":return k(this,e,n);case"base64":return v(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,e,n);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}function g(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function y(t,e,n,i,r){if(0===t.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),J(n=+n)&&(n=r?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(r)return-1;n=t.length-1}else if(n<0){if(!r)return-1;n=0}if("string"==typeof e&&(e=o.from(e,i)),o.isBuffer(e))return 0===e.length?-1:m(t,e,n,i,r);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):m(t,[e],n,i,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,n,i,r){let a,o=1,s=t.length,c=e.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(t.length<2||e.length<2)return-1;o=2,s/=2,c/=2,n/=2}function u(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(r){let i=-1;for(a=n;a<s;a++)if(u(t,a)===u(e,-1===i?0:a-i)){if(-1===i&&(i=a),a-i+1===c)return i*o}else-1!==i&&(a-=a-i),i=-1}else for(n+c>s&&(n=s-c),a=n;a>=0;a--){let n=!0;for(let i=0;i<c;i++)if(u(t,a+i)!==u(e,i)){n=!1;break}if(n)return a}return-1}function w(t,e,n,i){n=Number(n)||0;const r=t.length-n;i?(i=Number(i))>r&&(i=r):i=r;const a=e.length;let o;for(i>a/2&&(i=a/2),o=0;o<i;++o){const i=parseInt(e.substr(2*o,2),16);if(J(i))return o;t[n+o]=i}return o}function S(t,e,n,i){return z(F(e,t.length-n),t,n,i)}function E(t,e,n,i){return z(function(t){const e=[];for(let n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,i)}function I(t,e,n,i){return z(X(e),t,n,i)}function C(t,e,n,i){return z(function(t,e){let n,i,r;const a=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)n=t.charCodeAt(o),i=n>>8,r=n%256,a.push(r),a.push(i);return a}(e,t.length-n),t,n,i)}function v(t,n,i){return 0===n&&i===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(n,i))}function b(t,e,n){n=Math.min(t.length,n);const i=[];let r=e;for(;r<n;){const e=t[r];let a=null,o=e>239?4:e>223?3:e>191?2:1;if(r+o<=n){let n,i,s,c;switch(o){case 1:e<128&&(a=e);break;case 2:n=t[r+1],128==(192&n)&&(c=(31&e)<<6|63&n,c>127&&(a=c));break;case 3:n=t[r+1],i=t[r+2],128==(192&n)&&128==(192&i)&&(c=(15&e)<<12|(63&n)<<6|63&i,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:n=t[r+1],i=t[r+2],s=t[r+3],128==(192&n)&&128==(192&i)&&128==(192&s)&&(c=(15&e)<<18|(63&n)<<12|(63&i)<<6|63&s,c>65535&&c<1114112&&(a=c))}}null===a?(a=65533,o=1):a>65535&&(a-=65536,i.push(a>>>10&1023|55296),a=56320|1023&a),i.push(a),r+=o}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let n="",i=0;for(;i<e;)n+=String.fromCharCode.apply(String,t.slice(i,i+=A));return n}(i)}t.kMaxLength=r,o.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(t,e,n){return s(t,e,n)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(t,e,n){return function(t,e,n){return c(t),t<=0?a(t):void 0!==e?"string"==typeof n?a(t).fill(e,n):a(t).fill(e):a(t)}(t,e,n)},o.allocUnsafe=function(t){return u(t)},o.allocUnsafeSlow=function(t){return u(t)},o.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==o.prototype},o.compare=function(t,e){if(W(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,i=e.length;for(let r=0,a=Math.min(n,i);r<a;++r)if(t[r]!==e[r]){n=t[r],i=e[r];break}return n<i?-1:i<n?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return o.alloc(0);let n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;const i=o.allocUnsafe(e);let r=0;for(n=0;n<t.length;++n){let e=t[n];if(W(e,Uint8Array))r+e.length>i.length?(o.isBuffer(e)||(e=o.from(e)),e.copy(i,r)):Uint8Array.prototype.set.call(i,e,r);else{if(!o.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(i,r)}r+=e.length}return i},o.byteLength=l,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},o.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},o.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},o.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?b(this,0,t):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===o.compare(this,t)},o.prototype.inspect=function(){let e="";const n=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"},i&&(o.prototype[i]=o.prototype.inspect),o.prototype.compare=function(t,e,n,i,r){if(W(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===i&&(i=0),void 0===r&&(r=this.length),e<0||n>t.length||i<0||r>this.length)throw new RangeError("out of range index");if(i>=r&&e>=n)return 0;if(i>=r)return-1;if(e>=n)return 1;if(this===t)return 0;let a=(r>>>=0)-(i>>>=0),s=(n>>>=0)-(e>>>=0);const c=Math.min(a,s),u=this.slice(i,r),h=t.slice(e,n);for(let t=0;t<c;++t)if(u[t]!==h[t]){a=u[t],s=h[t];break}return a<s?-1:s<a?1:0},o.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},o.prototype.indexOf=function(t,e,n){return y(this,t,e,n,!0)},o.prototype.lastIndexOf=function(t,e,n){return y(this,t,e,n,!1)},o.prototype.write=function(t,e,n,i){if(void 0===e)i="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)i=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(n)?(n>>>=0,void 0===i&&(i="utf8")):(i=n,n=void 0)}const r=this.length-e;if((void 0===n||n>r)&&(n=r),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let a=!1;for(;;)switch(i){case"hex":return w(this,t,e,n);case"utf8":case"utf-8":return S(this,t,e,n);case"ascii":case"latin1":case"binary":return E(this,t,e,n);case"base64":return I(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,n);default:if(a)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),a=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function N(t,e,n){let i="";n=Math.min(t.length,n);for(let r=e;r<n;++r)i+=String.fromCharCode(127&t[r]);return i}function k(t,e,n){let i="";n=Math.min(t.length,n);for(let r=e;r<n;++r)i+=String.fromCharCode(t[r]);return i}function R(t,e,n){const i=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>i)&&(n=i);let r="";for(let i=e;i<n;++i)r+=Q[t[i]];return r}function _(t,e,n){const i=t.slice(e,n);let r="";for(let t=0;t<i.length-1;t+=2)r+=String.fromCharCode(i[t]+256*i[t+1]);return r}function T(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function O(t,e,n,i,r,a){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||e<a)throw new RangeError('"value" argument is out of bounds');if(n+i>t.length)throw new RangeError("Index out of range")}function U(t,e,n,i,r){D(e,i,r,t,n,7);let a=Number(e&BigInt(4294967295));t[n++]=a,a>>=8,t[n++]=a,a>>=8,t[n++]=a,a>>=8,t[n++]=a;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,n}function x(t,e,n,i,r){D(e,i,r,t,n,7);let a=Number(e&BigInt(4294967295));t[n+7]=a,a>>=8,t[n+6]=a,a>>=8,t[n+5]=a,a>>=8,t[n+4]=a;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=o,o>>=8,t[n+2]=o,o>>=8,t[n+1]=o,o>>=8,t[n]=o,n+8}function P(t,e,n,i,r,a){if(n+i>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(t,e,i,r,a){return e=+e,i>>>=0,a||P(t,0,i,4),n.write(t,e,i,r,23,4),i+4}function M(t,e,i,r,a){return e=+e,i>>>=0,a||P(t,0,i,8),n.write(t,e,i,r,52,8),i+8}o.prototype.slice=function(t,e){const n=this.length;(t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t);const i=this.subarray(t,e);return Object.setPrototypeOf(i,o.prototype),i},o.prototype.readUintLE=o.prototype.readUIntLE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=this[t],r=1,a=0;for(;++a<e&&(r*=256);)i+=this[t+a]*r;return i},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=this[t+--e],r=1;for(;e>0&&(r*=256);)i+=this[t+--e]*r;return i},o.prototype.readUint8=o.prototype.readUInt8=function(t,e){return t>>>=0,e||T(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,e){return t>>>=0,e||T(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,e){return t>>>=0,e||T(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,e){return t>>>=0,e||T(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,e){return t>>>=0,e||T(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readBigUInt64LE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,r=this[++t]+256*this[++t]+65536*this[++t]+n*2**24;return BigInt(i)+(BigInt(r)<<BigInt(32))})),o.prototype.readBigUInt64BE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=e*2**24+65536*this[++t]+256*this[++t]+this[++t],r=this[++t]*2**24+65536*this[++t]+256*this[++t]+n;return(BigInt(i)<<BigInt(32))+BigInt(r)})),o.prototype.readIntLE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=this[t],r=1,a=0;for(;++a<e&&(r*=256);)i+=this[t+a]*r;return r*=128,i>=r&&(i-=Math.pow(2,8*e)),i},o.prototype.readIntBE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=e,r=1,a=this[t+--i];for(;i>0&&(r*=256);)a+=this[t+--i]*r;return r*=128,a>=r&&(a-=Math.pow(2,8*e)),a},o.prototype.readInt8=function(t,e){return t>>>=0,e||T(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){t>>>=0,e||T(t,2,this.length);const n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(t,e){t>>>=0,e||T(t,2,this.length);const n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(t,e){return t>>>=0,e||T(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return t>>>=0,e||T(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readBigInt64LE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=this[t+4]+256*this[t+5]+65536*this[t+6]+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),o.prototype.readBigInt64BE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(i)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+n)})),o.prototype.readFloatLE=function(t,e){return t>>>=0,e||T(t,4,this.length),n.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return t>>>=0,e||T(t,4,this.length),n.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return t>>>=0,e||T(t,8,this.length),n.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return t>>>=0,e||T(t,8,this.length),n.read(this,t,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,e,n,i){if(t=+t,e>>>=0,n>>>=0,!i){O(this,t,e,n,Math.pow(2,8*n)-1,0)}let r=1,a=0;for(this[e]=255&t;++a<n&&(r*=256);)this[e+a]=t/r&255;return e+n},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,e,n,i){if(t=+t,e>>>=0,n>>>=0,!i){O(this,t,e,n,Math.pow(2,8*n)-1,0)}let r=n-1,a=1;for(this[e+r]=255&t;--r>=0&&(a*=256);)this[e+r]=t/a&255;return e+n},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,1,255,0),this[e]=255&t,e+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigUInt64LE=Y((function(t,e=0){return U(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=Y((function(t,e=0){return x(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(t,e,n,i){if(t=+t,e>>>=0,!i){const i=Math.pow(2,8*n-1);O(this,t,e,n,i-1,-i)}let r=0,a=1,o=0;for(this[e]=255&t;++r<n&&(a*=256);)t<0&&0===o&&0!==this[e+r-1]&&(o=1),this[e+r]=(t/a|0)-o&255;return e+n},o.prototype.writeIntBE=function(t,e,n,i){if(t=+t,e>>>=0,!i){const i=Math.pow(2,8*n-1);O(this,t,e,n,i-1,-i)}let r=n-1,a=1,o=0;for(this[e+r]=255&t;--r>=0&&(a*=256);)t<0&&0===o&&0!==this[e+r+1]&&(o=1),this[e+r]=(t/a|0)-o&255;return e+n},o.prototype.writeInt8=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeInt16BE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeInt32LE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},o.prototype.writeInt32BE=function(t,e,n){return t=+t,e>>>=0,n||O(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigInt64LE=Y((function(t,e=0){return U(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=Y((function(t,e=0){return x(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(t,e,n){return L(this,t,e,!0,n)},o.prototype.writeFloatBE=function(t,e,n){return L(this,t,e,!1,n)},o.prototype.writeDoubleLE=function(t,e,n){return M(this,t,e,!0,n)},o.prototype.writeDoubleBE=function(t,e,n){return M(this,t,e,!1,n)},o.prototype.copy=function(t,e,n,i){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),i||0===i||(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<n&&(i=n),i===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-e<i-n&&(i=t.length-e+n);const r=i-n;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,n,i):Uint8Array.prototype.set.call(t,this.subarray(n,i),e),r},o.prototype.fill=function(t,e,n,i){if("string"==typeof t){if("string"==typeof e?(i=e,e=0,n=this.length):"string"==typeof n&&(i=n,n=this.length),void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!o.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(1===t.length){const e=t.charCodeAt(0);("utf8"===i&&e<128||"latin1"===i)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;let r;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(r=e;r<n;++r)this[r]=t;else{const a=o.isBuffer(t)?t:o.from(t,i),s=a.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(r=0;r<n-e;++r)this[r+e]=a[r%s]}return this};const H={};function K(t,e,n){H[t]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function j(t){let e="",n=t.length;const i="-"===t[0]?1:0;for(;n>=i+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function D(t,e,n,i,r,a){if(t>n||t<e){const n="bigint"==typeof e?"n":"";let i;throw i=0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(a+1)}${n}`:`>= -(2${n} ** ${8*(a+1)-1}${n}) and < 2 ** ${8*(a+1)-1}${n}`,new H.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,n){q(e,"offset"),void 0!==t[e]&&void 0!==t[e+n]||V(e,t.length-(n+1))}(i,r,a)}function q(t,e){if("number"!=typeof t)throw new H.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,n){if(Math.floor(t)!==t)throw q(t,n),new H.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new H.ERR_BUFFER_OUT_OF_BOUNDS;throw new H.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}K("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),K("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),K("ERR_OUT_OF_RANGE",(function(t,e,n){let i=`The value of "${t}" is out of range.`,r=n;return Number.isInteger(n)&&Math.abs(n)>2**32?r=j(String(n)):"bigint"==typeof n&&(r=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(r=j(r)),r+="n"),i+=` It must be ${e}. Received ${r}`,i}),RangeError);const G=/[^+/0-9A-Za-z-_]/g;function F(t,e){let n;e=e||1/0;const i=t.length;let r=null;const a=[];for(let o=0;o<i;++o){if(n=t.charCodeAt(o),n>55295&&n<57344){if(!r){if(n>56319){(e-=3)>-1&&a.push(239,191,189);continue}if(o+1===i){(e-=3)>-1&&a.push(239,191,189);continue}r=n;continue}if(n<56320){(e-=3)>-1&&a.push(239,191,189),r=n;continue}n=65536+(r-55296<<10|n-56320)}else r&&(e-=3)>-1&&a.push(239,191,189);if(r=null,n<128){if((e-=1)<0)break;a.push(n)}else if(n<2048){if((e-=2)<0)break;a.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;a.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return a}function X(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(G,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function z(t,e,n,i){let r;for(r=0;r<i&&!(r+n>=e.length||r>=t.length);++r)e[r+n]=t[r];return r}function W(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){const i=16*n;for(let r=0;r<16;++r)e[i+r]=t[n]+t[r]}return e}();function Y(t){return"undefined"==typeof BigInt?Z:t}function Z(){throw new Error("BigInt not supported")}}(T);const K="_/@#/",j="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),D=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(([a-zA-Z\d])(\d)(\d))$/;function q(t){if(void 0===t)return;const e=t.match(D);if(null!=e){const[,t,n,i,r,a,o,s,c]=e;return{signature:t,expiry:n,userId:i,ipHash:r,mitigationType:a,match:o,mitigate:s,captcha:c}}}function V(t=16,e=j){const n=new Uint16Array(t-1);b.getRandomValues(n);return`c${Array.from(n).map((t=>e[t%e.length])).join("")}`}async function G(t,e){const n=await R(T.Buffer.from(t),e),i=T.Buffer.from(n).toString("hex");return T.Buffer.from(i).toString("base64")}async function F(t,e,n){const i=T.Buffer.from(t,"base64").toString("utf-8"),r=T.Buffer.from(i,"hex");return await async function(t,e,n){const i=await _(k(n));return await b.subtle.verify("HMAC",i,t,e)}(r,T.Buffer.from(e),n)}async function X(t,e,n,i,r,a,o,s=86400){return{clientIP:t,userId:e??V(),match:n,mitigate:i,captcha:r,mitataMaxAge:s,netaceaSettings:o??{},issueReason:a}}const z={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},W={match:"x-netacea-match",mitigate:"x-netacea-mitigate",captcha:"x-netacea-captcha",mitata:"x-netacea-mitata-value",mitataExpiry:"x-netacea-mitata-expiry",mitataCaptcha:"x-netacea-mitatacaptcha-value",mitataCaptchaExpiry:"x-netacea-mitatacaptcha-expiry",eventId:"x-netacea-event-id"},J={0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},Q={0:"",1:"blocked",2:"allow",3:"hardblocked",4:"block"},Y={0:"",1:"captcha_serve",2:"captcha_pass",3:"captcha_fail",4:"captcha_cookiepass",5:"captcha_cookiefail",6:"checkpoint_signal",7:"checkpoint_post"},Z={"":0,captchaServe:1,captchaPass:2,captchaFail:3,captchaCookiePass:4,captchaCookieFail:5,checkpointSignal:6,checkpointPost:7},tt={0:z.none,1:z.block,2:z.none,3:z.block,4:z.block},et={1:z.captcha,2:z.captchaPass,3:z.captcha,4:z.allow,5:z.captcha,6:z.captcha,7:z.captcha},nt={checkAllPostRequests:"checkAllPostRequests"};var it=Object.freeze({__proto__:null,COOKIEDELIMITER:"_/@#/",bestMitigationCaptchaMap:et,bestMitigationMap:tt,captchaMap:Y,captchaStatusCodes:Z,get dictionary(){return it},matchMap:J,mitigateMap:Q,mitigationTypes:z,netaceaCookieV3KeyMap:{clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},netaceaCookieV3OptionalKeyMap:{checkAllPostRequests:"fCAPR"},netaceaHeaders:W,netaceaSettingsMap:nt});class rt extends Error{static fromResponse(t){let e="Unknown error";switch(t.status){case 403:e="Invalid credentials";break;case 500:e="Server error";break;case 502:e="Bad Gateway";break;case 503:e="Service Unavailable";break;case 400:e="Invalid request"}return new rt(e)}}async function at(t,e,n,i,r,a,s=o.NO_SESSION,c){if(200!==i.status)throw rt.fromResponse(i);let u=i.headers[W.match],h=i.headers[W.mitigate],f=i.headers[W.captcha];void 0===J[u]&&(u=n?.match??"0"),void 0===h&&(h=n?.mitigate??"0"),void 0===f&&(f=n?.captcha??"0");let p=parseInt(i.headers[W.mitataExpiry]);isNaN(p)&&(p=86400);const l=await X(a,r,u,h,f,s,c),d=await async function(t,e,n){if(Object.prototype.hasOwnProperty.call(n,W.mitataCaptcha)){const i=n[W.mitataCaptcha],r=parseInt(n[W.mitataCaptchaExpiry]),a=await async function(t,e,n,i,r,a="/"){const o=[e.netaceaCookieName,e.netaceaCaptchaCookieName];return void 0!==t.cachedEncryption&&o.includes(n)?`${n}=${await t.cachedEncryption.encrypt(i)}; Max-Age=${r}; Path=${a}`:`${n}=${i}; Max-Age=${r}; Path=${a}`}(t,e,e.netaceaCaptchaCookieName,i,r);if(void 0!==a)return a}}(t,e,i.headers),g=i.headers[W.eventId];return{status:i.status,match:u,mitigate:h,captcha:f,responseNetaceaCookie:l,responseNetaceaCaptchaCookie:d,body:i.body,eventId:g,mitataMaxAge:p,netaceaSettings:c??{}}}class ot{constructor(){this.queries={}}setQuery(t,e){return this.queries[t]=encodeURIComponent(e),this}removeQuery(t){const{[t]:e,...n}=this.queries;return this.queries=n,this}buildQueryString(){const t=Object.entries(this.queries).map((([t,e])=>`${t}=${e}`)).join("&");return t.length>0?`?${t}`:""}}function st(t){const e=Object.entries(t.getHeaders()),n={};for(const[t,i]of e)n[t]=i[0];return n}async function ct(t,e,n){const{method:i,path:r,headers:a,body:o,timeout:s}=n;let{host:c}=n;c.endsWith("/")&&(c=c.slice(0,-1));const u=c+r,{httpRequest:h}=t,f=await h(u,{body:o,headers:a,method:i,timeout:s??3e3});return{status:f.status,body:await f.text(),headers:st(f)}}function ut(t){return Object.entries(t).filter((([,t])=>void 0!==t)).map((t=>t.join("="))).join("; ")}function ht(t){const e=t?.toLowerCase()??"text/html",n=e?.includes("text/html")||e?.includes("application/html"),i=e?.includes("application/json");return i&&!n?"application/json":"text/html"}function ft(t,e,n){let i;if(void 0===t||""===t)return"";if("string"==typeof t&&(i=JSON.parse(t)),!function(t){if(null==t)return!1;const e=t;return void 0!==e?.captchaSiteKey&&void 0!==e?.trackingId&&void 0!==e?.captchaURL}(i))throw new Error("Body is not a Mitigation Service JSON response!");const r=`${n}?trackingId=${i.trackingId}`,a=`https://${e}${r}`;return JSON.stringify({captchaRelativeURL:r,captchaAbsoluteURL:a})}const{netaceaCookieV3KeyMap:pt,netaceaCookieV3OptionalKeyMap:lt}=it;function dt(t){if("object"!=typeof t||null===t)return!1;for(const e of Object.keys(pt)){if(!(e in t))return!1;if(void 0===t[e])return!1}return!0}function gt(t){return void 0!==t&&t.split("&").map((t=>t.split("=")[0])).filter((t=>!Object.values(lt).includes(t))).every((t=>Object.values(pt).includes(t)))}function yt(t){if(void 0===t||""===t)return;const e=t.split("&"),n={clientIP:"",userId:"",cookieId:"",gracePeriod:0,match:0,mitigate:0,captcha:0,issueTimestamp:0,issueReason:"",checkAllPostRequests:void 0};for(const t of e){const[e,i]=t.split("="),r=decodeURIComponent(i);let a=Object.keys(pt).find((t=>pt[t]===e));void 0===a&&(a=Object.keys(lt).find((t=>lt[t]===e)));let o=""===r?void 0:Number(r);void 0!==o&&isNaN(o)&&(o=r),n[a]=o}return n}function mt(t){const e={},{netaceaSettingsMap:n}=it;return decodeURIComponent(t).split("&").map((t=>t.split("="))).forEach((([t,i])=>{if(void 0!==i&&t in n){const r=parseInt(i,10);e[n[t]]=isNaN(r)?void 0:r}})),Object.entries(e).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=n),t)),{})}function wt(t){const e={};if(dt(t)){const{netaceaSettingsMap:n}=it;for(const i in n){const r=t[n[i]];void 0!==r&&(e[i]=r)}}return e}async function St(t,e,n,i,r){const a=new ot,s=[];for(const t in nt)void 0===n[t]&&s.push(t);return s.length>0&&a.setQuery("getSettings",s.join(",")),void 0!==i.trackingId&&a.setQuery("trackingId",i.trackingId),a.setQuery("netaceaHeaders","User-Agent, Request-ID"),await async function(t,e,n,i,r,a,o,s){const{userId:c,clientIP:u,host:h}=n,{mitigationServiceUrl:f,timeout:p}=e;if(void 0===f)throw new Error("Mitigation Service URL is not defined!");const l=function(t,e){const{apiKey:n,userId:i,userAgent:r,captchaCookie:a,clientIP:o,captchaSiteKey:s,captchaSecretKey:c,accept:u,requestId:h}=e,f={"X-Netacea-API-Key":n,"X-Netacea-Client-IP":o,"X-Netacea-User-Agent":T.Buffer.from(r).toString("base64"),cookie:ut({_mitatacaptcha:a}),"X-Netacea-Request-Id":h};void 0!==i&&(f["X-Netacea-UserId"]=i);void 0!==s&&void 0!==c&&(f["X-Netacea-Captcha-Site-Key"]=s,f["X-Netacea-Captcha-Secret-Key"]=c);t.captchaContentNegotiation&&void 0!==t.netaceaCaptchaPath&&(f["X-Netacea-Captcha-Content-Type"]=ht(u));return f}(e,n),d="application/json"===l["X-Netacea-Captcha-Content-Type"],g={host:f,path:i,headers:l,method:r,timeout:p},y=await ct(t,0,g);d&&void 0!==e.netaceaCaptchaPath&&void 0!==h&&(y.body=ft(y.body,h,e.netaceaCaptchaPath));let m={};void 0!==y.headers["x-netacea-settings"]&&(m=mt(y.headers["x-netacea-settings"]));return await at(t,e,s,y,c,u,a,{...o,...m})}(t,e,i,`/captcha${a.buildQueryString()}`,"GET",o.CAPTCHA_GET,n,r)}async function Et(t,e,n,i){n=It(n);const r=`${i}=`;for(const o of n){const n=o.split(";")[0].trimStart();if(n.startsWith(r)){const o=n.slice(r.length);if(e.encryptedCookieNames.includes(i)&&(5===(a=o).split(".").length&&a.includes("..")))try{return await(t.cachedEncryption?.decrypt(o))}catch(t){return}return o}}var a}function It(t){return null==t?[]:"string"==typeof t?t.split(";"):t}function Ct(t,e,n=""){const i=t.getHeader(e)?.[0]?.trim();return i??n}function vt(t,e,n=""){return t.getVariable(e)??n}async function bt(t,e,n){return gt(t)?function(t,e){if(void 0===t||""===t)return c();const n=yt(t);if(void 0!==n){const t=Math.floor(Date.now()/1e3),i=n.issueTimestamp+n.gracePeriod<t,r=e===n.clientIP,a=["1","3","5"].includes(n.captcha),o="3"===n.mitigate;return{mitata:n,requiresReissue:i||!r,isExpired:i,shouldExpire:a||o,isSameIP:r,isPrimaryHashValid:!0,match:n.match,mitigate:n.mitigate,captcha:n.captcha}}return c()}(t,e):await async function(t,e,n){if("string"!=typeof t||""===t)return c();const i=q(t);if(void 0!==i){const t=Math.floor(Date.now()/1e3),r=parseInt(i.expiry)<t,a=["1","3","5"].includes(i.captcha),o="3"===i.mitigate,s=a||o,c=e+"|"+i.expiry,u=await F(i.ipHash,c,n),h=[i.expiry,i.userId,i.ipHash,i.mitigationType].join(K);return{mitata:i,requiresReissue:r||!u,isExpired:r,shouldExpire:s,isSameIP:u,isPrimaryHashValid:await F(i.signature,h,n),match:i.match,mitigate:i.mitigate,captcha:i.captcha}}return c()}(t,e,n??"")}function At(t,e){const n=t.split("&");for(const t of n){const[n,i]=t.split("=");if(n===e)return i}}function Nt(t,e,n){const{netaceaBlockedResponseStatus:i,netaceaCaptchaResponseStatus:r}=t;let a;return a=Number("block"===e?i:r),(o=a)>=200&&o<600&&!Number.isNaN(o)&&3===o.toString().length?a:n;var o}async function kt(t,e,{clientIP:n,userId:i,match:a,mitigate:s,captcha:c,netaceaSettings:u,issueReason:h,expiry:f}){const p=e.netaceaCookieExpirySeconds,l=["1","3","5"].includes(c)||"3"===s?-60:p,d=f??Math.floor(Date.now()/1e3)+l,g=e.ingestType!==r.HTTP&&void 0!==t.cachedEncryption;if(!g&&void 0===e.secretKey)throw new Error("Cannot build cookie without secret key.");if(g)return y={clientIP:n,userId:i??"",match:a,mitigate:s,captcha:c,gracePeriod:l,cookieId:V(),issueTimestamp:Math.floor(Date.now()/1e3),issueReason:h??o.NO_SESSION,checkAllPostRequests:u.checkAllPostRequests},Object.entries(y).filter((([t,e])=>void 0!==e)).map((([t,e])=>t in lt?`${lt[t]}=${encodeURIComponent(e)}`:`${pt[t]}=${encodeURIComponent(e)}`)).join("&");var y;const m=[a,s,c].join("");return await async function(t,e,n,i,r="000"){void 0===e&&(e=V());const a=[n,e,await G(t+"|"+String(n),i),r].join(K);return`${await G(a,i)}${K}${a}`}(n,i,d,e.secretKey,m)}function Rt(t,e){const n=e.getVariable(t.protoMitataVariableName);if(void 0!==n&&""!==n)try{return JSON.parse(n)}catch{return}}async function _t(t,e,n,i){const r=C(n.path,n.method)?function(t,e){const n=t.getHeader("x-netacea-client-ip")?.[0];if(null==n||""===n)throw new Error("Cannot build proto-mitata without Client IP");const i=t.getHeader("x-netacea-userid")?.[0]??"";let r={};const a=t.getHeader("x-netacea-settings")?.[0];return void 0!==a&&(r=JSON.parse(a)),{clientIP:n,userId:""!==i?i:V(),match:e.getHeader("x-netacea-match")?.[0]??"0",mitigate:e.getHeader("x-netacea-mitigate")?.[0]??"0",captcha:e.getHeader("x-netacea-captcha")?.[0]??"0",mitataMaxAge:(s="x-netacea-mitata-expiry",c=86400,Number(e.getHeader(s)?.[0]??c)),netaceaSettings:r,issueReason:o.CAPTCHA_POST};var s,c}(n,i):Rt(e,n);if(void 0!==r){const n=e.netaceaCookieName??"_mitata";let a=await kt(t,e,{clientIP:r.clientIP,userId:r.userId,match:r.match,mitigate:r.mitigate,captcha:r.captcha,netaceaSettings:r.netaceaSettings,issueReason:r.issueReason??o.NO_SESSION});const s=e.encryptedCookieNames.includes(n);void 0!==t.cachedEncryption&&s&&(a=await t.cachedEncryption.encrypt(a));const c=l.cookie.netaceaSession.createNetaceaSetCookieString({cookieName:n,cookieValue:a,otherAttributes:e.netaceaCookieAttributes});i.addHeader("set-cookie",c)}}async function Tt(t,e,n,i){const r=i.getHeader("set-cookie")??void 0;if(i.removeHeader("set-cookie"),200===i.status){const a=W.captcha,o=i.getHeader(a)?.[0],s=String(Z.captchaPass);String(o)!==String(Z.checkpointPost)&&(await _t(t,e,n,i),await async function(t,e,n,i){const r=i?.find((t=>t.startsWith("_mitatacaptcha=")))?.split(/; ?/)[0];if(void 0===r)return;const a=e.netaceaCaptchaCookieName??"_mitatacaptcha",o=r.indexOf("=");if(o>=0){let i=r.slice(o+1);const s=e.encryptedCookieNames.includes(a);void 0!==t.cachedEncryption&&s&&(i=await t.cachedEncryption.encrypt(i));const c=l.cookie.netaceaSession.createNetaceaCaptchaSetCookieString({cookieName:a,cookieValue:i,otherAttributes:e.netaceaCaptchaCookieAttributes});n.addHeader("set-cookie",c)}}(t,e,i,r)),o===String(Z.checkpointPost)?i.status=202:o!==s&&(i.status=403)}}function Bt(t){return T.Buffer.from(t.replace(/-/g,"+").replace(/_/g,"/"),"base64")}function Ot(t,e){if("string"==typeof t&&void 0===e)throw new Error("Encoding should be provided to convert strings.");return function(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}(("string"==typeof t?T.Buffer.from(t,e):T.Buffer.from(t)).toString("base64"))}const Ut=128,xt=Ot(JSON.stringify({alg:"dir",enc:"A128CBC-HS256"}),"utf-8"),Pt=(new A).encode(xt);async function Lt(t){return await b.subtle.importKey("raw",t,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async function Mt({plaintext:t,secret:e,ivBase64Url:n}){const i=Bt(e),r=i.subarray(16),a=i.subarray(0,16),o=await Lt(r),s=void 0!==n?Bt(n):function(){const t=new Uint8Array(16);return b.getRandomValues(t),t}(),c=(new A).encode(t),u=await async function(t,e,n){const i=await b.subtle.encrypt({name:"AES-CBC",length:Ut,iv:t},e,n);return new Uint8Array(i)}(s,o,c),h=new Uint8Array(s),f=Kt(Pt,h,u),p=await $t(f,a);return[xt,"",Ot(s),Ot(u),Ot(p)].join(".")}async function Ht({jwe:t,secret:e}){const n=Bt(e),i=n.subarray(16),r=n.subarray(0,16),{header:a,iv:o,payload:s,mac:c}=function(t){const e=t.split(".");if(5!==e.length)throw new Error(`JWE should have 5 parts, got ${e.length}`);const[n,i,r,a,o]=e;return{header:n,key:i,iv:r,payload:a,mac:o}}(t);if(a!==xt)throw new Error("Incorrect JWE header");const u=Bt(o),h=new Uint8Array(Bt(s)),f=Kt((new A).encode(a),u,h);if(Ot(await $t(f,r))!==c)throw new Error("MAC does not match JWE data");const p=await Lt(i),l=await async function(t,e,n){const i=await b.subtle.decrypt({name:"AES-CBC",length:Ut,iv:t},e,n);return new Uint8Array(i)}(u,p,h);return(new N).decode(l)}async function $t(t,e){return(await R(t,e)).slice(0,16)}function Kt(t,e,n){return function(t){const e=t.reduce(((t,{length:e})=>t+e),0),n=new Uint8Array(e);let i=0;return t.forEach((t=>{n.set(t,i),i+=t.length})),n}([t,e,n,qt(t.length<<3)])}const jt=2**32;function Dt(t,e,n){if(e<0||e>=jt)throw new RangeError(`value must be >= 0 and <= ${jt-1}. Received ${e}`);t.set([e>>>24,e>>>16,e>>>8,255&e],n)}function qt(t){const e=Math.floor(t/jt),n=t%jt,i=new Uint8Array(8);return Dt(i,e,0),Dt(i,n,4),i}class Vt{constructor(t){this.maxSize=t,this.cachedItems=[]}getCacheSize(){return this.cachedItems.length}delete(t){this.cachedItems=this.cachedItems.filter((e=>e.key!==t))}add(t,e){this.delete(t),this.cachedItems.push({key:t,value:e}),this.cachedItems.length>this.maxSize&&this.cachedItems.shift()}get(t){return this.cachedItems.find((e=>e.key===t))}}class Gt{constructor(t){this.encryptionKey=t.encryptionKey,this.cache=new Vt(t.cacheMaxSize??5)}getCacheSize(){return this.cache.getCacheSize()}async memoizeFn(t,e){const n=this.cache.get(t);if(void 0!==n)return n.value;const i=await e();return this.cache.add(t,i),i}async encrypt(t){const e=`encrypt::${t}`;return await this.memoizeFn(e,(async()=>await Mt({plaintext:t,secret:this.encryptionKey})))}async decrypt(t){const e=`encrypt::${t}`;return await this.memoizeFn(e,(async()=>await Ht({jwe:t,secret:this.encryptionKey})))}}function Ft(t){return t.bytesSent=""===t.bytesSent?"0":t.bytesSent,function({ip:t,userAgent:e,status:n,method:i,path:r,protocol:a,referer:o,bytesSent:s,requestTime:c,mitataCookie:u,sessionStatus:h,integrationType:f,integrationVersion:p}){const l=(new Date).toUTCString();return{Request:`${i} ${r} ${a}`,TimeLocal:l,RealIp:t,UserAgent:e,Status:n,RequestTime:c?.toString(),BytesSent:s?.toString(),Referer:""===o?"-":o,NetaceaUserIdCookie:u??"",NetaceaMitigationApplied:h??"",IntegrationType:f??"",IntegrationVersion:p??""}}(t)}async function Xt(t,e,n){const i=Ft(n);if(e.ingestType!==r.KINESIS){const n={"X-Netacea-API-Key":e.apiKey??"","content-type":"application/json"},r=await async function(t,e,n,i){return await ct(t,0,{host:e.ingestServiceUrl,method:"POST",path:"/",headers:n,body:JSON.stringify(i),timeout:e.timeout})}(t,e,n,i);if(200!==r.status)throw rt.fromResponse(r)}}function zt(t,e,n,i,r,o){const s="unknown";r||("2"===i?i="4":"3"===i&&(i="5")),o&&(i="6");let c=J[e]??s+"_";c+=Q[n]??s;let u=tt[n];if("0"!==i){c+=","+(Y[i]??s);const t=et[i];void 0!==t&&(u=t)}return t.mitigationType===a.INJECT&&(u=z.none),{sessionStatus:c,mitigation:u,parts:{match:e,mitigate:n,captcha:i}}}function Wt(t){return gt(t)?yt(t):q(t)}var Jt,Qt="@netacea/akamai",Yt="6.1.128";async function Zt(t,e,n,i){e.ingestType===r.HTTP&&await async function(t,e,n,i){const r=e.netaceaCookieName??"_mitata",a=i.getHeader("set-cookie")??[],o=0!==a.length?a?.join("; "):Ct(n,"cookie");let s=await Et(t,e,o,r)??"";if(void 0===s||""===s){const i=Ct(n,"cookie");s=await Et(t,e,i,r)??""}const{match:c,mitigate:u,captcha:h}=Wt(s)??{match:"0",mitigate:"0",captcha:"0"},{sessionStatus:f}=zt(e,c,u,h,C(n.path,n.method),v(n.path,n.method,e.netaceaCheckpointSignalPath)),p=C(n.path,n.method)&&500===i.status;try{Xt(t,e,{bytesSent:Ct(i,"content-length","0"),ip:vt(n,"PMUSER_CLIENT_IP",""),method:n.method,path:n.url,protocol:Ct(n,"protocol","HTTP/1.1"),referer:Ct(n,"referer",""),requestTime:"0",sessionStatus:p?"error_open":f,status:String(i.status),userAgent:Ct(n,"user-agent","-"),mitataCookie:s,integrationType:Qt.replace("@netacea/",""),integrationVersion:Yt})}catch(e){t.logger.error(e)}}(t,e,n,i)}async function te(t,e,n,i,r,a){try{const o=void 0!==n?Rt(n,e):void 0,s=o?.userId??i?.userId??"",c=void 0!==a?a.sessionStatus:function(t,e,n,i){if(void 0===e)return"error_open";const r=i?.match??n?.match??"0",a=i?.mitigate??n?.mitigate??"0",o=i?.captcha??n?.captcha??"0",{sessionStatus:s}=zt(e,r,a,o,C(t.path,t.method),v(t.path,t.method,e.netaceaCheckpointSignalPath));return s}(e,n,i,o),{sessionReason:u,sessionStartTime:h,mitigationStatusCode:f}=t.getState(),p=[s,c,Yt,r?.headerFingerprint??"",r?.cookieFingerprint??"",u??"",h??"",n?.mitigationType??"",f??"",e.getVariable("PMUSER_NETACEA_REQUEST_ID")??"",ee(t,"logging_failure")].join(";");e.setVariable("PMUSER_NETACEA_DS2_CUSTOM_FIELD",p)}catch{}}function ee(t,e){try{const e=t.flush();return T.Buffer.from(e).toString("base64")}catch{return e}}function ne(t,e,n){t.setState({sessionReason:e,sessionStartTime:n??Math.floor(Date.now()/1e3)})}function ie(t,e){e=e??t.query,t.route({origin:"mitigations",path:t.path,query:e})}function re(t,e){const n=(new ot).setQuery("headerFP",e.headerFingerprint),i=[];for(const e in nt)void 0===t[e]&&i.push(e);return i.length>0&&n.setQuery("getSettings",i.join(",")),n}!function(t){t[t.NO_SESSION=0]="NO_SESSION",t[t.NEW_SESSION=1]="NEW_SESSION",t[t.EXISTING_SESSION=2]="EXISTING_SESSION",t[t.RENEW_SESSION=3]="RENEW_SESSION"}(Jt||(Jt={}));const{mitigationTypes:ae}=it,oe=[ae.block,ae.captcha,ae.captchaPass];async function se(t,e,n,i,r){const{netaceaCookieInfo:a,clientIp:o,netaceaSession:s}=n;let c={status:-1,match:(u=a).match,mitigate:u.mitigate,captcha:u.captcha,mitataMaxAge:86400,netaceaSettings:{},responseNetaceaCookie:void 0,responseNetaceaCaptchaCookie:void 0};var u,h;if(void 0===e.secretKey)throw new Error("Secret key is required to mitigate");if(void 0!==n.netaceaCookieRequiredReissueReason){c=await async function(t,e,n,i,r,a){if(void 0===e.apiKey)throw new Error("An API Key is Required to call the protector API.");const o={"X-Netacea-API-Key":e.apiKey,"X-Netacea-Client-IP":n.clientIp,"X-Netacea-User-Agent":T.Buffer.from(n.userAgent).toString("base64"),cookie:ut({_mitatacaptcha:n.netaceaSession.captchaToken}),"X-Netacea-Request-Id":n.requestId};void 0!==n.netaceaSession.userId&&(o["X-Netacea-UserId"]=n.netaceaSession.userId),void 0!==e.captchaSiteKey&&void 0!==e.captchaSecretKey&&(o["X-Netacea-Captcha-Site-Key"]=e.captchaSiteKey,o["X-Netacea-Captcha-Secret-Key"]=e.captchaSecretKey),e.captchaContentNegotiation&&void 0!==e.netaceaCaptchaPath&&(o["X-Netacea-Captcha-Content-Type"]=ht(i));const s=re(a,n.fingerprints);s.setQuery("netaceaHeaders","User-Agent, Request-ID");const c="application/json"===o["X-Netacea-Captcha-Content-Type"],u=await ct(t,0,{host:e.mitigationServiceUrl,path:"/"+s.buildQueryString(),headers:o,method:"GET",timeout:e.timeout});var h,f;h=t.logger,f=u.status,h.setState({mitigationStatusCode:f}),c&&void 0!==e.netaceaCaptchaPath&&(u.body=ft(u.body,r,e.netaceaCaptchaPath));let p={};return void 0!==u.headers["x-netacea-settings"]&&(p=mt(u.headers["x-netacea-settings"])),await at(t,e,void 0,u,n.netaceaSession.userId,n.clientIp,n.netaceaCookieRequiredReissueReason,{...a,...p})}(t,e,n,i,r,n.netaceaSettings),c.responseNetaceaCookie=await X(o,s.userId,c.match,c.mitigate,c.captcha,n.netaceaCookieRequiredReissueReason,c.netaceaSettings,c.mitataMaxAge);const u=void 0===a.mitata?Jt.NEW_SESSION:Jt.RENEW_SESSION;ne(t.logger,u)}else{const e=a.mitata;if(void 0!==e){const n=dt(h=e)?h.issueTimestamp:Number.parseInt(h.expiry,10)-60;ne(t.logger,Jt.EXISTING_SESSION,n)}}const f=zt(e,c.match,c.mitigate,c.captcha,!1,!1);return{body:c.body,apiCallStatus:c.status,responseNetaceaCookie:c?.responseNetaceaCookie,responseNetaceaCaptchaCookie:void 0,sessionStatus:f.sessionStatus,mitigation:f.mitigation,mitigated:oe.includes(f.mitigation),bestMitigation:f,eventId:c.eventId}}function ce(t){return{apiCallStatus:0,responseNetaceaCookie:t,responseNetaceaCaptchaCookie:void 0,sessionStatus:"",mitigation:"000",mitigated:!1,bestMitigation:{sessionStatus:"",mitigation:"",parts:{match:"0",mitigate:"0",captcha:"0"}},eventId:void 0}}async function ue(t){return{sessionStatus:"",response:{headers:{},body:void 0,status:0,statusText:"",mitigation:"000"},bestAction:ce(await X(s,t,"0","0","0",o.NO_SESSION,void 0,86400))}}async function he(t,e,n,i){try{switch(e.mitigationType){case a.MITIGATE:return await async function(t,e,n,i){const r=Ct(n,"accept","text/html"),a=await se(t,e,i,r,n.host),o={};let s,c;return a.mitigated&&(c=403,"captcha"===a.mitigation?(o["content-type"]="text/html; charset=UTF-8",s=a.body):s="Forbidden"),{response:{body:s,status:c,statusText:c?.toString(),headers:o,mitigation:a.mitigation},sessionStatus:a.sessionStatus,bestAction:a}}(t,e,n,i);case a.INJECT:return await async function(t,e,n,i){const r=Ct(n,"accept","text/html"),a=await se(t,e,i,r,n.host),o={"x-netacea-match":a.bestMitigation.parts.match.toString(),"x-netacea-mitigate":a.bestMitigation.parts.mitigate.toString(),"x-netacea-captcha":a.bestMitigation.parts.captcha.toString()};return void 0!==a.eventId&&(o["x-netacea-event-id"]=a.eventId),{injectHeaders:o,sessionStatus:a.sessionStatus,response:{headers:{}},bestAction:a}}(t,e,n,i);case a.INGEST:return await async function(t,e,n){if(void 0===e.secretKey)throw new Error("Secret key is required for ingest");const i=Ct(n,"cookie"),r=await Et(t,e,i,e.netaceaCookieName??"_mitata"),a=await bt(r,s,e.secretKey);return a.isPrimaryHashValid?a.requiresReissue?await ue(a.mitata?.userId):{sessionStatus:"",response:void 0,bestAction:ce()}:await ue(void 0)}(t,e,n);default:throw new Error(`Netacea Error: Mitigation type ${e.mitigationType} not recognised`)}}catch(e){return t.logger.error(e),await Promise.resolve({injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"},sessionStatus:"error_open",response:void 0,bestAction:void 0})}}async function fe(t,e,n,i){let o={};if(void 0!==n?.bestAction?.responseNetaceaCookie){const t=n?.bestAction?.responseNetaceaCookie;void 0!==t&&i.setVariable(e.protoMitataVariableName,JSON.stringify(t))}if(e.mitigationType===a.INJECT){o=n.injectHeaders??{}}let s={};e.ingestType===r.ORIGIN&&(s=await async function(t,e,n){const i=Ct(n,"cookie"),r=Wt(await Et(t,e,i,e.netaceaCookieName)??""),a=Rt(e,n),{match:o,mitigate:s,captcha:c,userId:u}=a??r??{match:"0",mitigate:"0",captcha:"0",userId:""},{sessionStatus:h}=zt(e,o,s,c,C(n.path,n.method),!1);return{"X-Netacea-UserId":u,"X-Netacea-BC-Type":h,"X-Netacea-Integration-Type":Qt.replace("@netacea/",""),"X-Netacea-Integration-Version":Yt}}(t,e,i));for(const[t,e]of Object.entries({...o,...s}))i.addHeader(t,e)}async function pe(t){const e=function(t){return Object.keys(t).filter((t=>{const e=t.toLowerCase();return"cookie"!==e&&"referer"!==e&&!e.startsWith("x-netacea-")})).join(",")}(t);return await le(e)}async function le(t){let e="";try{e=await async function(t,e){const n=(new A).encode(e),i=await b.subtle.digest(t,n);return Array.from(new Uint8Array(i)).map((t=>t.toString(16).padStart(2,"0"))).join("")}("SHA-256",t)}catch(t){e=""}return e}async function de(t){const e=t.getHeaders(),n=await pe(e),i=function(t,e){const n=t.getHeader(e);return null==n?[]:n}(t,"cookie").map((t=>t.split(/; ?/).map((t=>t.split("=")[0])))).flat(),r=await async function(t){const e=t.join(",");return await le(e)}(i);return[""===n?n:`h_${n.substring(1,15)}`,""===r?r:`c_${r.substring(1,15)}`]}async function ge(t,e,n){const r=vt(n,"PMUSER_CLIENT_IP"),a=Ct(n,"user-agent"),s=void 0!==e.altCookieHeaderName?Ct(n,e.altCookieHeaderName):void 0,c=void 0!==s&&""!==s?s:Ct(n,"cookie");void 0!==e.altCookieHeaderName&&void 0!==s&&""!==s&&n.setVariable("NETACEA_USES_ALT_COOKIE_HEADER","true");const u=await Et(t,e,c,e.netaceaCookieName),h=await bt(u,r,e.secretKey),f=function(t,e,n,i,r){if(void 0!==i&&!r.isPrimaryHashValid)return o.INVALID_SESSION;if(void 0===i)return function(t,e){for(const n of It(t))if(n.startsWith(`${e}=`))return!0;return!1}(e,n)?o.INVALID_SESSION:o.NO_SESSION;if(r.isExpired)return o.EXPIRED_SESSION;if(!r.isSameIP)return o.IP_CHANGE;const a="post"===t.method.toLowerCase(),s=wt(r.mitata);if(a&&1===s.checkAllPostRequests)return o.FORCED_REVALIDATION}(n,c,e.netaceaCookieName,u,h),p=wt(h.mitata),l=await Et(t,e,c,e.netaceaCaptchaCookieName),[d,g]=await de(n);let y=n.getVariable("PMUSER_NETACEA_REQUEST_ID")??"";if(""===y)try{y=i(),n.setVariable("PMUSER_NETACEA_REQUEST_ID",y)}catch(e){y="",t.logger.error("REQ_ID error")}return{clientIp:r,userAgent:a,method:n.method,netaceaCookieInfo:h,netaceaCookieRequiredReissueReason:f,netaceaSession:{userId:h.mitata?.userId,captchaToken:l,match:h.match,mitigate:h.mitigate,captcha:h.captcha},fingerprints:{headerFingerprint:d,cookieFingerprint:g},requestId:y,netaceaSettings:p}}class ye{constructor(t){this.errorLog="",this.options=t,this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}getState(){return Object.assign({},this.state)}setState(t){for(const e in this.state)void 0!==t[e]&&(this.state[e]=t[e])}appendErrorLog(t){this.errorLog=function(t,e,n){if(e-t.length<=2)return t;const i=n.trim().slice(0,e).replace(/\n/g,"\\n");return(""===t?i:t+"\n"+i).slice(0,e)}(this.errorLog,this.options.maxErrorLogLength,t)}error(t){try{if(this.options.maxErrorLogLength<=0||null==t||""===t)return;if("string"==typeof t)this.appendErrorLog(t);else{const e=function(t){if(void 0!==t.stack)return t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack;return t.message}(t);this.appendErrorLog(e)}}catch{}}flush(){try{return this.errorLog}finally{this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}}}class me{constructor(e){this.configLoader=new m(e),this.runtimeDeps={httpRequest:t}}initDeps(t,e){const n=void 0===e.cookieEncryptionKey?void 0:new Gt({encryptionKey:e.cookieEncryptionKey});return{...this.runtimeDeps,config:e,logger:t,cachedEncryption:n}}async requestHandler(t){const e=new ye({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(t)});let n,i,r;try{i=this.configLoader.loadConfig(t);const u=this.initDeps(e,i);r=await ge(u,i,t),void 0!==r.netaceaCookieRequiredReissueReason&&t.setVariable("PMUSER_NETACEA_ISSUE_REASON",r.netaceaCookieRequiredReissueReason),a=t.path,s=t.method,void 0!==(c=i.netaceaCaptchaPath)&&c.length>0&&a===c&&"get"===s.toLowerCase()?await async function(t,e,n,i){const r=Ct(n,"cookie"),a=await Et(t,e,r,e.netaceaCookieName),s=await Et(t,e,r,e.netaceaCaptchaCookieName),c=vt(n,"PMUSER_CLIENT_IP"),u=Ct(n,"user-agent"),h=await bt(a,c,e.secretKey),f=Nt(e,"captcha",403),p=await St(t,e,i.netaceaSettings,{apiKey:e.apiKey??"",clientIP:c,userAgent:u,userId:h.mitata?.userId,captchaCookie:s,trackingId:At(n.query,"trackingId"),captchaSiteKey:e.captchaSiteKey,captchaSecretKey:e.captchaSecretKey,accept:Ct(n,"accept","text/html"),host:n.host,requestId:i.requestId},{match:"0",mitigate:"0",captcha:"1"}),l=p.responseNetaceaCookie;void 0!==l&&(void 0===i.netaceaCookieRequiredReissueReason?l.issueReason=o.CAPTCHA_GET:l.issueReason=i.netaceaCookieRequiredReissueReason,n.setVariable(e.protoMitataVariableName,JSON.stringify(l)));const d={};void 0!==e.netaceaCaptchaHeaderKey&&void 0!==e.netaceaCaptchaHeaderValue&&(d[e.netaceaCaptchaHeaderKey]=e.netaceaCaptchaHeaderValue),n.respondWith(f,d,p.body??"")}(u,i,t,r):C(t.path,t.method)?await async function(t,e,n,i){if(void 0===e.apiKey)throw new Error("An API Key is Required to Verify Captcha");const r=n.getVariable("PMUSER_CLIENT_IP")??"";n.setHeader("x-netacea-api-key",e.apiKey),n.setHeader("x-netacea-client-ip",r);const a=Ct(n,"cookie"),o=await Et(t,e,a,e.netaceaCookieName)??"";let s="";const c=await bt(o,r,e.secretKey??"");if(dt(c.mitata)){const t={checkAllPostRequests:c.mitata.checkAllPostRequests};n.setHeader("x-netacea-settings",JSON.stringify(t))}c.isPrimaryHashValid&&(s=c.mitata?.userId??""),n.setHeader("x-netacea-userid",s),n.setHeader("x-netacea-user-agent",T.Buffer.from(i.userAgent).toString("base64")),n.setHeader("x-netacea-request-id",i.requestId);const u=re(i.netaceaSettings,i.fingerprints);u.setQuery("netaceaHeaders","User-Agent, Request-ID"),ie(n,u.buildQueryString())}(u,i,t,r):E(t.path,t.method,i.useCaptchaRelAssets)?ie(t):v(t.path,t.method,i.netaceaCheckpointSignalPath)?await async function(t){t.respondWith(200,{},"")}(t):function(t,e){if(void 0===e.netaceaBlockedResponseRedirectLocation)return!1;if(e.netaceaBlockedResponseRedirectLocation.startsWith("/"))return e.netaceaBlockedResponseRedirectLocation===t.path;try{const n=new URL(e.netaceaBlockedResponseRedirectLocation);return n.host===t.host&&n.pathname===t.path}catch{return!1}}(t,i)||(n=await async function(t,e,n,i){const r=await he(t,e,n,i);if(void 0===r)throw new Error('Mitigation Service response "mitResult" was undefined.');const a=r.response?.mitigation;if("block"===a||"captcha"===a){let t=Nt(e,a,r.response?.status??403);const i={},o=e.netaceaBlockedResponseRedirectLocation;"block"===a&&void 0!==o&&function(t){if("GET"!==t.method?.toUpperCase())return!1;const e=t.getHeader("sec-fetch-mode")??[];return!(e.length>0&&!e.includes("navigate"))&&(t.getHeader("accept")?.map((t=>t.split(/, ?/))).flat()??[]).includes("text/html")}(n)&&(t=303,i.Location=o);const s=r.bestAction?.responseNetaceaCookie;void 0!==s&&n.setVariable(e.protoMitataVariableName,JSON.stringify(s));const c=r.response?.body??"";(function(t){return t.includes("captchaRelativeURL")&&t.includes("captchaAbsoluteURL")})(c)&&(i["content-type"]="application/json"),"captcha"===a&&(void 0===i["content-type"]&&(i["content-type"]="text/html"),void 0!==e.netaceaCaptchaHeaderKey&&void 0!==e.netaceaCaptchaHeaderValue&&(i[e.netaceaCaptchaHeaderKey]=e.netaceaCaptchaHeaderValue)),n.respondWith(t,i,c)}else await fe(t,e,r,n);return r}(u,i,t,r))}catch(t){e.error(t)}finally{try{await te(e,t,i,r?.netaceaSession,r?.fingerprints,n)}catch{}}var a,s,c}async responseHandler(t,e){const n=new ye({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(t)});try{const i=this.configLoader.loadConfig(t),r=this.initDeps(n,i);if(C(t.path,t.method))await Tt(r,i,t,e);else if(I(t.path,t.method)&&!E(t.path,t.method,i.useCaptchaRelAssets)){const n=t.getVariable("PMUSER_NETACEA_ISSUE_REASON")!==o.NO_SESSION,a=t.getVariable("NETACEA_USES_ALT_COOKIE_HEADER");n&&"true"!==a&&await _t(r,i,t,e)}else if(!E(t.path,t.method,i.useCaptchaRelAssets)){"true"!==t.getVariable("NETACEA_USES_ALT_COOKIE_HEADER")&&await _t(r,i,t,e)}!function(t){t.removeHeader("x-netacea-match"),t.removeHeader("x-netacea-mitigate"),t.removeHeader("x-netacea-captcha"),t.removeHeader("x-netacea-mitata-expiry"),t.removeHeader("x-netacea-mitata-value"),t.removeHeader("x-netacea-mitatacaptcha-expiry"),t.removeHeader("x-netacea-mitatacaptcha-value"),t.removeHeader("x-netacea-event-id"),t.removeHeader("x-netacea-settings")}(e),await Zt(r,i,t,e)}catch(t){n.error(t)}}}export{a as NetaceaMitigationType,me as default};
10
+ !function(t){const e=O,n=K,i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=function(t){+t!=t&&(t=0);return o.alloc(+t)},t.INSPECT_MAX_BYTES=50;const r=2147483647;function a(t){if(t>r)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,o.prototype),e}function o(t,e,n){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return u(t)}return s(t,e,n)}function s(t,e,n){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const n=0|l(t,e);let i=a(n);const r=i.write(t,e);r!==n&&(i=i.slice(0,r));return i}(t,e);if(ArrayBuffer.isView(t))return function(t){if(W(t,Uint8Array)){const e=new Uint8Array(t);return f(e.buffer,e.byteOffset,e.byteLength)}return h(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(W(t,ArrayBuffer)||t&&W(t.buffer,ArrayBuffer))return f(t,e,n);if("undefined"!=typeof SharedArrayBuffer&&(W(t,SharedArrayBuffer)||t&&W(t.buffer,SharedArrayBuffer)))return f(t,e,n);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const i=t.valueOf&&t.valueOf();if(null!=i&&i!==t)return o.from(i,e,n);const r=function(t){if(o.isBuffer(t)){const e=0|p(t.length),n=a(e);return 0===n.length||t.copy(n,0,0,e),n}if(void 0!==t.length)return"number"!=typeof t.length||J(t.length)?a(0):h(t);if("Buffer"===t.type&&Array.isArray(t.data))return h(t.data)}(t);if(r)return r;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return o.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function u(t){return c(t),a(t<0?0:0|p(t))}function h(t){const e=t.length<0?0:0|p(t.length),n=a(e);for(let i=0;i<e;i+=1)n[i]=255&t[i];return n}function f(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let i;return i=void 0===e&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,e):new Uint8Array(t,e,n),Object.setPrototypeOf(i,o.prototype),i}function p(t){if(t>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|t}function l(t,e){if(o.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||W(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const n=t.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===n)return 0;let r=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return F(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return X(t).length;default:if(r)return i?-1:F(t).length;e=(""+e).toLowerCase(),r=!0}}function d(t,e,n){let i=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,n);case"utf8":case"utf-8":return v(this,e,n);case"ascii":return N(this,e,n);case"latin1":case"binary":return k(this,e,n);case"base64":return b(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,e,n);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}function g(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function y(t,e,n,i,r){if(0===t.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),J(n=+n)&&(n=r?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(r)return-1;n=t.length-1}else if(n<0){if(!r)return-1;n=0}if("string"==typeof e&&(e=o.from(e,i)),o.isBuffer(e))return 0===e.length?-1:m(t,e,n,i,r);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):m(t,[e],n,i,r);throw new TypeError("val must be string, number or Buffer")}function m(t,e,n,i,r){let a,o=1,s=t.length,c=e.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(t.length<2||e.length<2)return-1;o=2,s/=2,c/=2,n/=2}function u(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(r){let i=-1;for(a=n;a<s;a++)if(u(t,a)===u(e,-1===i?0:a-i)){if(-1===i&&(i=a),a-i+1===c)return i*o}else-1!==i&&(a-=a-i),i=-1}else for(n+c>s&&(n=s-c),a=n;a>=0;a--){let n=!0;for(let i=0;i<c;i++)if(u(t,a+i)!==u(e,i)){n=!1;break}if(n)return a}return-1}function w(t,e,n,i){n=Number(n)||0;const r=t.length-n;i?(i=Number(i))>r&&(i=r):i=r;const a=e.length;let o;for(i>a/2&&(i=a/2),o=0;o<i;++o){const i=parseInt(e.substr(2*o,2),16);if(J(i))return o;t[n+o]=i}return o}function S(t,e,n,i){return z(F(e,t.length-n),t,n,i)}function E(t,e,n,i){return z(function(t){const e=[];for(let n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,i)}function I(t,e,n,i){return z(X(e),t,n,i)}function C(t,e,n,i){return z(function(t,e){let n,i,r;const a=[];for(let o=0;o<t.length&&!((e-=2)<0);++o)n=t.charCodeAt(o),i=n>>8,r=n%256,a.push(r),a.push(i);return a}(e,t.length-n),t,n,i)}function b(t,n,i){return 0===n&&i===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(n,i))}function v(t,e,n){n=Math.min(t.length,n);const i=[];let r=e;for(;r<n;){const e=t[r];let a=null,o=e>239?4:e>223?3:e>191?2:1;if(r+o<=n){let n,i,s,c;switch(o){case 1:e<128&&(a=e);break;case 2:n=t[r+1],128==(192&n)&&(c=(31&e)<<6|63&n,c>127&&(a=c));break;case 3:n=t[r+1],i=t[r+2],128==(192&n)&&128==(192&i)&&(c=(15&e)<<12|(63&n)<<6|63&i,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:n=t[r+1],i=t[r+2],s=t[r+3],128==(192&n)&&128==(192&i)&&128==(192&s)&&(c=(15&e)<<18|(63&n)<<12|(63&i)<<6|63&s,c>65535&&c<1114112&&(a=c))}}null===a?(a=65533,o=1):a>65535&&(a-=65536,i.push(a>>>10&1023|55296),a=56320|1023&a),i.push(a),r+=o}return function(t){const e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);let n="",i=0;for(;i<e;)n+=String.fromCharCode.apply(String,t.slice(i,i+=A));return n}(i)}t.kMaxLength=r,o.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),o.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(t,e,n){return s(t,e,n)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(t,e,n){return function(t,e,n){return c(t),t<=0?a(t):void 0!==e?"string"==typeof n?a(t).fill(e,n):a(t).fill(e):a(t)}(t,e,n)},o.allocUnsafe=function(t){return u(t)},o.allocUnsafeSlow=function(t){return u(t)},o.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==o.prototype},o.compare=function(t,e){if(W(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,i=e.length;for(let r=0,a=Math.min(n,i);r<a;++r)if(t[r]!==e[r]){n=t[r],i=e[r];break}return n<i?-1:i<n?1:0},o.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return o.alloc(0);let n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;const i=o.allocUnsafe(e);let r=0;for(n=0;n<t.length;++n){let e=t[n];if(W(e,Uint8Array))r+e.length>i.length?(o.isBuffer(e)||(e=o.from(e)),e.copy(i,r)):Uint8Array.prototype.set.call(i,e,r);else{if(!o.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(i,r)}r+=e.length}return i},o.byteLength=l,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)g(this,e,e+1);return this},o.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)g(this,e,e+3),g(this,e+1,e+2);return this},o.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)g(this,e,e+7),g(this,e+1,e+6),g(this,e+2,e+5),g(this,e+3,e+4);return this},o.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?v(this,0,t):d.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(t){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===o.compare(this,t)},o.prototype.inspect=function(){let e="";const n=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"},i&&(o.prototype[i]=o.prototype.inspect),o.prototype.compare=function(t,e,n,i,r){if(W(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===i&&(i=0),void 0===r&&(r=this.length),e<0||n>t.length||i<0||r>this.length)throw new RangeError("out of range index");if(i>=r&&e>=n)return 0;if(i>=r)return-1;if(e>=n)return 1;if(this===t)return 0;let a=(r>>>=0)-(i>>>=0),s=(n>>>=0)-(e>>>=0);const c=Math.min(a,s),u=this.slice(i,r),h=t.slice(e,n);for(let t=0;t<c;++t)if(u[t]!==h[t]){a=u[t],s=h[t];break}return a<s?-1:s<a?1:0},o.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},o.prototype.indexOf=function(t,e,n){return y(this,t,e,n,!0)},o.prototype.lastIndexOf=function(t,e,n){return y(this,t,e,n,!1)},o.prototype.write=function(t,e,n,i){if(void 0===e)i="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)i=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(n)?(n>>>=0,void 0===i&&(i="utf8")):(i=n,n=void 0)}const r=this.length-e;if((void 0===n||n>r)&&(n=r),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let a=!1;for(;;)switch(i){case"hex":return w(this,t,e,n);case"utf8":case"utf-8":return S(this,t,e,n);case"ascii":case"latin1":case"binary":return E(this,t,e,n);case"base64":return I(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,n);default:if(a)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),a=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const A=4096;function N(t,e,n){let i="";n=Math.min(t.length,n);for(let r=e;r<n;++r)i+=String.fromCharCode(127&t[r]);return i}function k(t,e,n){let i="";n=Math.min(t.length,n);for(let r=e;r<n;++r)i+=String.fromCharCode(t[r]);return i}function R(t,e,n){const i=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>i)&&(n=i);let r="";for(let i=e;i<n;++i)r+=Q[t[i]];return r}function _(t,e,n){const i=t.slice(e,n);let r="";for(let t=0;t<i.length-1;t+=2)r+=String.fromCharCode(i[t]+256*i[t+1]);return r}function T(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,n,i,r,a){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||e<a)throw new RangeError('"value" argument is out of bounds');if(n+i>t.length)throw new RangeError("Index out of range")}function U(t,e,n,i,r){D(e,i,r,t,n,7);let a=Number(e&BigInt(4294967295));t[n++]=a,a>>=8,t[n++]=a,a>>=8,t[n++]=a,a>>=8,t[n++]=a;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,n}function x(t,e,n,i,r){D(e,i,r,t,n,7);let a=Number(e&BigInt(4294967295));t[n+7]=a,a>>=8,t[n+6]=a,a>>=8,t[n+5]=a,a>>=8,t[n+4]=a;let o=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=o,o>>=8,t[n+2]=o,o>>=8,t[n+1]=o,o>>=8,t[n]=o,n+8}function P(t,e,n,i,r,a){if(n+i>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function L(t,e,i,r,a){return e=+e,i>>>=0,a||P(t,0,i,4),n.write(t,e,i,r,23,4),i+4}function M(t,e,i,r,a){return e=+e,i>>>=0,a||P(t,0,i,8),n.write(t,e,i,r,52,8),i+8}o.prototype.slice=function(t,e){const n=this.length;(t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t);const i=this.subarray(t,e);return Object.setPrototypeOf(i,o.prototype),i},o.prototype.readUintLE=o.prototype.readUIntLE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=this[t],r=1,a=0;for(;++a<e&&(r*=256);)i+=this[t+a]*r;return i},o.prototype.readUintBE=o.prototype.readUIntBE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=this[t+--e],r=1;for(;e>0&&(r*=256);)i+=this[t+--e]*r;return i},o.prototype.readUint8=o.prototype.readUInt8=function(t,e){return t>>>=0,e||T(t,1,this.length),this[t]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(t,e){return t>>>=0,e||T(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(t,e){return t>>>=0,e||T(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(t,e){return t>>>=0,e||T(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(t,e){return t>>>=0,e||T(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readBigUInt64LE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,r=this[++t]+256*this[++t]+65536*this[++t]+n*2**24;return BigInt(i)+(BigInt(r)<<BigInt(32))})),o.prototype.readBigUInt64BE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=e*2**24+65536*this[++t]+256*this[++t]+this[++t],r=this[++t]*2**24+65536*this[++t]+256*this[++t]+n;return(BigInt(i)<<BigInt(32))+BigInt(r)})),o.prototype.readIntLE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=this[t],r=1,a=0;for(;++a<e&&(r*=256);)i+=this[t+a]*r;return r*=128,i>=r&&(i-=Math.pow(2,8*e)),i},o.prototype.readIntBE=function(t,e,n){t>>>=0,e>>>=0,n||T(t,e,this.length);let i=e,r=1,a=this[t+--i];for(;i>0&&(r*=256);)a+=this[t+--i]*r;return r*=128,a>=r&&(a-=Math.pow(2,8*e)),a},o.prototype.readInt8=function(t,e){return t>>>=0,e||T(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){t>>>=0,e||T(t,2,this.length);const n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(t,e){t>>>=0,e||T(t,2,this.length);const n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(t,e){return t>>>=0,e||T(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return t>>>=0,e||T(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readBigInt64LE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=this[t+4]+256*this[t+5]+65536*this[t+6]+(n<<24);return(BigInt(i)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),o.prototype.readBigInt64BE=Y((function(t){q(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const i=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(i)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+n)})),o.prototype.readFloatLE=function(t,e){return t>>>=0,e||T(t,4,this.length),n.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return t>>>=0,e||T(t,4,this.length),n.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return t>>>=0,e||T(t,8,this.length),n.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return t>>>=0,e||T(t,8,this.length),n.read(this,t,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(t,e,n,i){if(t=+t,e>>>=0,n>>>=0,!i){B(this,t,e,n,Math.pow(2,8*n)-1,0)}let r=1,a=0;for(this[e]=255&t;++a<n&&(r*=256);)this[e+a]=t/r&255;return e+n},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(t,e,n,i){if(t=+t,e>>>=0,n>>>=0,!i){B(this,t,e,n,Math.pow(2,8*n)-1,0)}let r=n-1,a=1;for(this[e+r]=255&t;--r>=0&&(a*=256);)this[e+r]=t/a&255;return e+n},o.prototype.writeUint8=o.prototype.writeUInt8=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,1,255,0),this[e]=255&t,e+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigUInt64LE=Y((function(t,e=0){return U(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=Y((function(t,e=0){return x(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(t,e,n,i){if(t=+t,e>>>=0,!i){const i=Math.pow(2,8*n-1);B(this,t,e,n,i-1,-i)}let r=0,a=1,o=0;for(this[e]=255&t;++r<n&&(a*=256);)t<0&&0===o&&0!==this[e+r-1]&&(o=1),this[e+r]=(t/a|0)-o&255;return e+n},o.prototype.writeIntBE=function(t,e,n,i){if(t=+t,e>>>=0,!i){const i=Math.pow(2,8*n-1);B(this,t,e,n,i-1,-i)}let r=n-1,a=1,o=0;for(this[e+r]=255&t;--r>=0&&(a*=256);)t<0&&0===o&&0!==this[e+r+1]&&(o=1),this[e+r]=(t/a|0)-o&255;return e+n},o.prototype.writeInt8=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},o.prototype.writeInt16BE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},o.prototype.writeInt32LE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},o.prototype.writeInt32BE=function(t,e,n){return t=+t,e>>>=0,n||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},o.prototype.writeBigInt64LE=Y((function(t,e=0){return U(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=Y((function(t,e=0){return x(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(t,e,n){return L(this,t,e,!0,n)},o.prototype.writeFloatBE=function(t,e,n){return L(this,t,e,!1,n)},o.prototype.writeDoubleLE=function(t,e,n){return M(this,t,e,!0,n)},o.prototype.writeDoubleBE=function(t,e,n){return M(this,t,e,!1,n)},o.prototype.copy=function(t,e,n,i){if(!o.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),i||0===i||(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<n&&(i=n),i===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-e<i-n&&(i=t.length-e+n);const r=i-n;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,n,i):Uint8Array.prototype.set.call(t,this.subarray(n,i),e),r},o.prototype.fill=function(t,e,n,i){if("string"==typeof t){if("string"==typeof e?(i=e,e=0,n=this.length):"string"==typeof n&&(i=n,n=this.length),void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!o.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(1===t.length){const e=t.charCodeAt(0);("utf8"===i&&e<128||"latin1"===i)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;let r;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(r=e;r<n;++r)this[r]=t;else{const a=o.isBuffer(t)?t:o.from(t,i),s=a.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(r=0;r<n-e;++r)this[r+e]=a[r%s]}return this};const H={};function $(t,e,n){H[t]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function j(t){let e="",n=t.length;const i="-"===t[0]?1:0;for(;n>=i+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function D(t,e,n,i,r,a){if(t>n||t<e){const n="bigint"==typeof e?"n":"";let i;throw i=0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(a+1)}${n}`:`>= -(2${n} ** ${8*(a+1)-1}${n}) and < 2 ** ${8*(a+1)-1}${n}`,new H.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,n){q(e,"offset"),void 0!==t[e]&&void 0!==t[e+n]||V(e,t.length-(n+1))}(i,r,a)}function q(t,e){if("number"!=typeof t)throw new H.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,n){if(Math.floor(t)!==t)throw q(t,n),new H.ERR_OUT_OF_RANGE("offset","an integer",t);if(e<0)throw new H.ERR_BUFFER_OUT_OF_BOUNDS;throw new H.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${e}`,t)}$("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),$("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),$("ERR_OUT_OF_RANGE",(function(t,e,n){let i=`The value of "${t}" is out of range.`,r=n;return Number.isInteger(n)&&Math.abs(n)>2**32?r=j(String(n)):"bigint"==typeof n&&(r=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(r=j(r)),r+="n"),i+=` It must be ${e}. Received ${r}`,i}),RangeError);const G=/[^+/0-9A-Za-z-_]/g;function F(t,e){let n;e=e||1/0;const i=t.length;let r=null;const a=[];for(let o=0;o<i;++o){if(n=t.charCodeAt(o),n>55295&&n<57344){if(!r){if(n>56319){(e-=3)>-1&&a.push(239,191,189);continue}if(o+1===i){(e-=3)>-1&&a.push(239,191,189);continue}r=n;continue}if(n<56320){(e-=3)>-1&&a.push(239,191,189),r=n;continue}n=65536+(r-55296<<10|n-56320)}else r&&(e-=3)>-1&&a.push(239,191,189);if(r=null,n<128){if((e-=1)<0)break;a.push(n)}else if(n<2048){if((e-=2)<0)break;a.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;a.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return a}function X(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(G,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function z(t,e,n,i){let r;for(r=0;r<i&&!(r+n>=e.length||r>=t.length);++r)e[r+n]=t[r];return r}function W(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Q=function(){const t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){const i=16*n;for(let r=0;r<16;++r)e[i+r]=t[n]+t[r]}return e}();function Y(t){return"undefined"==typeof BigInt?Z:t}function Z(){throw new Error("BigInt not supported")}}(B);const j="_/@#/",D="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),q=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(([a-zA-Z\d])(\d)(\d))$/;function V(t){if(void 0===t)return;const e=t.match(q);if(null!=e){const[,t,n,i,r,a,o,s,c]=e;return{signature:t,expiry:n,userId:i,ipHash:r,mitigationType:a,match:o,mitigate:s,captcha:c}}}function G(t=16,e=D){const n=new Uint16Array(t-1);A.getRandomValues(n);return`c${Array.from(n).map((t=>e[t%e.length])).join("")}`}async function F(t,e){const n=await _(B.Buffer.from(t),e),i=B.Buffer.from(n).toString("hex");return B.Buffer.from(i).toString("base64")}async function X(t,e,n){const i=B.Buffer.from(t,"base64").toString("utf-8"),r=B.Buffer.from(i,"hex");return await async function(t,e,n){const i=await T(R(n));return await A.subtle.verify("HMAC",i,t,e)}(r,B.Buffer.from(e),n)}async function z(t,e,n,i,r,a,o,s=86400){return{clientIP:t,userId:e??G(),match:n,mitigate:i,captcha:r,mitataMaxAge:s,netaceaSettings:o??{},issueReason:a}}const W={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},J={match:"x-netacea-match",mitigate:"x-netacea-mitigate",captcha:"x-netacea-captcha",mitata:"x-netacea-mitata-value",mitataExpiry:"x-netacea-mitata-expiry",mitataCaptcha:"x-netacea-mitatacaptcha-value",mitataCaptchaExpiry:"x-netacea-mitatacaptcha-expiry",eventId:"x-netacea-event-id"},Q={0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},Y={0:"",1:"blocked",2:"allow",3:"hardblocked",4:"block"},Z={0:"",1:"captcha_serve",2:"captcha_pass",3:"captcha_fail",4:"captcha_cookiepass",5:"captcha_cookiefail",6:"checkpoint_signal",7:"checkpoint_post"},tt={"":0,captchaServe:1,captchaPass:2,captchaFail:3,captchaCookiePass:4,captchaCookieFail:5,checkpointSignal:6,checkpointPost:7},et={0:W.none,1:W.block,2:W.none,3:W.block,4:W.block},nt={1:W.captcha,2:W.captchaPass,3:W.captcha,4:W.allow,5:W.captcha,6:W.captcha,7:W.captcha},it={checkAllPostRequests:"checkAllPostRequests"};var rt=Object.freeze({__proto__:null,COOKIEDELIMITER:"_/@#/",bestMitigationCaptchaMap:nt,bestMitigationMap:et,captchaMap:Z,captchaStatusCodes:tt,get dictionary(){return rt},matchMap:Q,mitigateMap:Y,mitigationTypes:W,netaceaCookieV3KeyMap:{clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},netaceaCookieV3OptionalKeyMap:{checkAllPostRequests:"fCAPR"},netaceaHeaders:J,netaceaSettingsMap:it});class at extends Error{static fromResponse(t){let e="Unknown error";switch(t.status){case 403:e="Invalid credentials";break;case 500:e="Server error";break;case 502:e="Bad Gateway";break;case 503:e="Service Unavailable";break;case 400:e="Invalid request"}return new at(e)}}async function ot(t,e,n,i,r,a,s=o.NO_SESSION,c){if(200!==i.status)throw at.fromResponse(i);let u=i.headers[J.match],h=i.headers[J.mitigate],f=i.headers[J.captcha];void 0===Q[u]&&(u=n?.match??"0"),void 0===h&&(h=n?.mitigate??"0"),void 0===f&&(f=n?.captcha??"0");let p=parseInt(i.headers[J.mitataExpiry]);isNaN(p)&&(p=86400);const l=await z(a,r,u,h,f,s,c),d=await async function(t,e,n){if(Object.prototype.hasOwnProperty.call(n,J.mitataCaptcha)){const i=n[J.mitataCaptcha],r=parseInt(n[J.mitataCaptchaExpiry]),a=await async function(t,e,n,i,r,a="/"){const o=[e.netaceaCookieName,e.netaceaCaptchaCookieName];return void 0!==t.cachedEncryption&&o.includes(n)?`${n}=${await t.cachedEncryption.encrypt(i)}; Max-Age=${r}; Path=${a}`:`${n}=${i}; Max-Age=${r}; Path=${a}`}(t,e,e.netaceaCaptchaCookieName,i,r);if(void 0!==a)return a}}(t,e,i.headers),g=i.headers[J.eventId];return{status:i.status,match:u,mitigate:h,captcha:f,responseNetaceaCookie:l,responseNetaceaCaptchaCookie:d,body:i.body,eventId:g,mitataMaxAge:p,netaceaSettings:c??{}}}class st{constructor(){this.queries={}}setQuery(t,e){return this.queries[t]=encodeURIComponent(e),this}removeQuery(t){const{[t]:e,...n}=this.queries;return this.queries=n,this}buildQueryString(){const t=Object.entries(this.queries).map((([t,e])=>`${t}=${e}`)).join("&");return t.length>0?`?${t}`:""}}function ct(t){const e=Object.entries(t.getHeaders()),n={};for(const[t,i]of e)n[t]=i[0];return n}async function ut(t,e,n){const{method:i,path:r,headers:a,body:o,timeout:s}=n;let{host:c}=n;c.endsWith("/")&&(c=c.slice(0,-1));const u=c+r,{httpRequest:h}=t,f=await h(u,{body:o,headers:a,method:i,timeout:s??3e3});return{status:f.status,body:await f.text(),headers:ct(f)}}function ht(t){return Object.entries(t).filter((([,t])=>void 0!==t)).map((t=>t.join("="))).join("; ")}function ft(t){const e=t?.toLowerCase()??"text/html",n=e?.includes("text/html")||e?.includes("application/html"),i=e?.includes("application/json");return i&&!n?"application/json":"text/html"}function pt(t,e,n){let i;if(void 0===t||""===t)return"";if("string"==typeof t&&(i=JSON.parse(t)),!function(t){if(null==t)return!1;const e=t;return void 0!==e?.captchaSiteKey&&void 0!==e?.trackingId&&void 0!==e?.captchaURL}(i))throw new Error("Body is not a Mitigation Service JSON response!");const r=`${n}?trackingId=${i.trackingId}`,a=`https://${e}${r}`;return JSON.stringify({captchaRelativeURL:r,captchaAbsoluteURL:a})}const{netaceaCookieV3KeyMap:lt,netaceaCookieV3OptionalKeyMap:dt}=rt;function gt(t){if("object"!=typeof t||null===t)return!1;for(const e of Object.keys(lt)){if(!(e in t))return!1;if(void 0===t[e])return!1}return!0}function yt(t){return void 0!==t&&t.split("&").map((t=>t.split("=")[0])).filter((t=>!Object.values(dt).includes(t))).every((t=>Object.values(lt).includes(t)))}function mt(t){if(void 0===t||""===t)return;const e=t.split("&"),n={clientIP:"",userId:"",cookieId:"",gracePeriod:0,match:0,mitigate:0,captcha:0,issueTimestamp:0,issueReason:"",checkAllPostRequests:void 0};for(const t of e){const[e,i]=t.split("="),r=decodeURIComponent(i);let a=Object.keys(lt).find((t=>lt[t]===e));void 0===a&&(a=Object.keys(dt).find((t=>dt[t]===e)));let o=""===r?void 0:Number(r);void 0!==o&&isNaN(o)&&(o=r),n[a]=o}return n}function wt(t){const e={},{netaceaSettingsMap:n}=rt;return decodeURIComponent(t).split("&").map((t=>t.split("="))).forEach((([t,i])=>{if(void 0!==i&&t in n){const r=parseInt(i,10);e[n[t]]=isNaN(r)?void 0:r}})),Object.entries(e).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=n),t)),{})}function St(t){const e={};if(gt(t)){const{netaceaSettingsMap:n}=rt;for(const i in n){const r=t[n[i]];void 0!==r&&(e[i]=r)}}return e}async function Et(t,e,n,i,r){const a=new st,s=[];for(const t in it)void 0===n[t]&&s.push(t);return s.length>0&&a.setQuery("getSettings",s.join(",")),void 0!==i.trackingId&&a.setQuery("trackingId",i.trackingId),a.setQuery("netaceaHeaders","User-Agent, Request-ID"),await async function(t,e,n,i,r,a,o,s){const{userId:c,clientIP:u,host:h}=n,{mitigationServiceUrl:f,timeout:p}=e;if(void 0===f)throw new Error("Mitigation Service URL is not defined!");const l=function(t,e){const{apiKey:n,userId:i,userAgent:r,captchaCookie:a,clientIP:o,captchaSiteKey:s,captchaSecretKey:c,accept:u,requestId:h}=e,f={"X-Netacea-API-Key":n,"X-Netacea-Client-IP":o,"X-Netacea-User-Agent":B.Buffer.from(r).toString("base64"),cookie:ht({_mitatacaptcha:a}),"X-Netacea-Request-Id":h};void 0!==i&&(f["X-Netacea-UserId"]=i);void 0!==s&&void 0!==c&&(f["X-Netacea-Captcha-Site-Key"]=s,f["X-Netacea-Captcha-Secret-Key"]=c);t.captchaContentNegotiation&&void 0!==t.netaceaCaptchaPath&&(f["X-Netacea-Captcha-Content-Type"]=ft(u));return f}(e,n),d="application/json"===l["X-Netacea-Captcha-Content-Type"],g={host:f,path:i,headers:l,method:r,timeout:p},y=await ut(t,0,g);d&&void 0!==e.netaceaCaptchaPath&&void 0!==h&&(y.body=pt(y.body,h,e.netaceaCaptchaPath));let m={};void 0!==y.headers["x-netacea-settings"]&&(m=wt(y.headers["x-netacea-settings"]));return await ot(t,e,s,y,c,u,a,{...o,...m})}(t,e,i,`/captcha${a.buildQueryString()}`,"GET",o.CAPTCHA_GET,n,r)}async function It(t,e,n,i){n=Ct(n);const r=`${i}=`;for(const o of n){const n=o.split(";")[0].trimStart();if(n.startsWith(r)){const o=n.slice(r.length);if(e.encryptedCookieNames.includes(i)&&(5===(a=o).split(".").length&&a.includes("..")))try{return await(t.cachedEncryption?.decrypt(o))}catch(t){return}return o}}var a}function Ct(t){return null==t?[]:"string"==typeof t?t.split(";"):t}function bt(t,e,n=""){const i=t.getHeader(e)?.[0]?.trim();return i??n}function vt(t,e,n=""){return t.getVariable(e)??n}async function At(t,e,n){return yt(t)?function(t,e){if(void 0===t||""===t)return c();const n=mt(t);if(void 0!==n){const t=Math.floor(Date.now()/1e3),i=n.issueTimestamp+n.gracePeriod<t,r=e===n.clientIP,a=["1","3","5"].includes(n.captcha),o="3"===n.mitigate;return{mitata:n,requiresReissue:i||!r,isExpired:i,shouldExpire:a||o,isSameIP:r,isPrimaryHashValid:!0,match:n.match,mitigate:n.mitigate,captcha:n.captcha}}return c()}(t,e):await async function(t,e,n){if("string"!=typeof t||""===t)return c();const i=V(t);if(void 0!==i){const t=Math.floor(Date.now()/1e3),r=parseInt(i.expiry)<t,a=["1","3","5"].includes(i.captcha),o="3"===i.mitigate,s=a||o,c=e+"|"+i.expiry,u=await X(i.ipHash,c,n),h=[i.expiry,i.userId,i.ipHash,i.mitigationType].join(j);return{mitata:i,requiresReissue:r||!u,isExpired:r,shouldExpire:s,isSameIP:u,isPrimaryHashValid:await X(i.signature,h,n),match:i.match,mitigate:i.mitigate,captcha:i.captcha}}return c()}(t,e,n??"")}function Nt(t,e){const n=t.split("&");for(const t of n){const[n,i]=t.split("=");if(n===e)return i}}function kt(t,e,n){const{netaceaBlockedResponseStatus:i,netaceaCaptchaResponseStatus:r}=t;let a;return a=Number("block"===e?i:r),(o=a)>=200&&o<600&&!Number.isNaN(o)&&3===o.toString().length?a:n;var o}async function Rt(t,e,{clientIP:n,userId:i,match:a,mitigate:s,captcha:c,netaceaSettings:u,issueReason:h,expiry:f}){const p=e.netaceaCookieExpirySeconds,l=["1","3","5"].includes(c)||"3"===s?-60:p,d=f??Math.floor(Date.now()/1e3)+l,g=e.ingestType!==r.HTTP&&void 0!==t.cachedEncryption;if(!g&&void 0===e.secretKey)throw new Error("Cannot build cookie without secret key.");if(g)return y={clientIP:n,userId:i??"",match:a,mitigate:s,captcha:c,gracePeriod:l,cookieId:G(),issueTimestamp:Math.floor(Date.now()/1e3),issueReason:h??o.NO_SESSION,checkAllPostRequests:u.checkAllPostRequests},Object.entries(y).filter((([t,e])=>void 0!==e)).map((([t,e])=>t in dt?`${dt[t]}=${encodeURIComponent(e)}`:`${lt[t]}=${encodeURIComponent(e)}`)).join("&");var y;const m=[a,s,c].join("");return await async function(t,e,n,i,r="000"){void 0===e&&(e=G());const a=[n,e,await F(t+"|"+String(n),i),r].join(j);return`${await F(a,i)}${j}${a}`}(n,i,d,e.secretKey,m)}function _t(t,e){const n=e.getVariable(t.protoMitataVariableName);if(void 0!==n&&""!==n)try{return JSON.parse(n)}catch{return}}async function Tt(t,e,n,i){const r=b(n.path,n.method)?function(t,e){const n=t.getHeader("x-netacea-client-ip")?.[0];if(null==n||""===n)throw new Error("Cannot build proto-mitata without Client IP");const i=t.getHeader("x-netacea-userid")?.[0]??"";let r={};const a=t.getHeader("x-netacea-settings")?.[0];return void 0!==a&&(r=JSON.parse(a)),{clientIP:n,userId:""!==i?i:G(),match:e.getHeader("x-netacea-match")?.[0]??"0",mitigate:e.getHeader("x-netacea-mitigate")?.[0]??"0",captcha:e.getHeader("x-netacea-captcha")?.[0]??"0",mitataMaxAge:(s="x-netacea-mitata-expiry",c=86400,Number(e.getHeader(s)?.[0]??c)),netaceaSettings:r,issueReason:o.CAPTCHA_POST};var s,c}(n,i):_t(e,n);if(void 0!==r){const n=e.netaceaCookieName??"_mitata";let a=await Rt(t,e,{clientIP:r.clientIP,userId:r.userId,match:r.match,mitigate:r.mitigate,captcha:r.captcha,netaceaSettings:r.netaceaSettings,issueReason:r.issueReason??o.NO_SESSION});const s=e.encryptedCookieNames.includes(n);void 0!==t.cachedEncryption&&s&&(a=await t.cachedEncryption.encrypt(a));const c=l.cookie.netaceaSession.createNetaceaSetCookieString({cookieName:n,cookieValue:a,otherAttributes:e.netaceaCookieAttributes});i.addHeader("set-cookie",c)}}async function Bt(t,e,n,i){const r=i.getHeader("set-cookie")??void 0;if(i.removeHeader("set-cookie"),200===i.status){const a=J.captcha,o=i.getHeader(a)?.[0],s=String(tt.captchaPass);String(o)!==String(tt.checkpointPost)&&(await Tt(t,e,n,i),await async function(t,e,n,i){const r=i?.find((t=>t.startsWith("_mitatacaptcha=")))?.split(/; ?/)[0];if(void 0===r)return;const a=e.netaceaCaptchaCookieName??"_mitatacaptcha",o=r.indexOf("=");if(o>=0){let i=r.slice(o+1);const s=e.encryptedCookieNames.includes(a);void 0!==t.cachedEncryption&&s&&(i=await t.cachedEncryption.encrypt(i));const c=l.cookie.netaceaSession.createNetaceaCaptchaSetCookieString({cookieName:a,cookieValue:i,otherAttributes:e.netaceaCaptchaCookieAttributes});n.addHeader("set-cookie",c)}}(t,e,i,r)),o===String(tt.checkpointPost)?i.status=202:o!==s&&(i.status=403)}}function Ot(t){return B.Buffer.from(t.replace(/-/g,"+").replace(/_/g,"/"),"base64")}function Ut(t,e){if("string"==typeof t&&void 0===e)throw new Error("Encoding should be provided to convert strings.");return function(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}(("string"==typeof t?B.Buffer.from(t,e):B.Buffer.from(t)).toString("base64"))}const xt=128,Pt=Ut(JSON.stringify({alg:"dir",enc:"A128CBC-HS256"}),"utf-8"),Lt=(new N).encode(Pt);async function Mt(t){return await A.subtle.importKey("raw",t,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async function Ht({plaintext:t,secret:e,ivBase64Url:n}){const i=Ot(e),r=i.subarray(16),a=i.subarray(0,16),o=await Mt(r),s=void 0!==n?Ot(n):function(){const t=new Uint8Array(16);return A.getRandomValues(t),t}(),c=(new N).encode(t),u=await async function(t,e,n){const i=await A.subtle.encrypt({name:"AES-CBC",length:xt,iv:t},e,n);return new Uint8Array(i)}(s,o,c),h=new Uint8Array(s),f=jt(Lt,h,u),p=await Kt(f,a);return[Pt,"",Ut(s),Ut(u),Ut(p)].join(".")}async function $t({jwe:t,secret:e}){const n=Ot(e),i=n.subarray(16),r=n.subarray(0,16),{header:a,iv:o,payload:s,mac:c}=function(t){const e=t.split(".");if(5!==e.length)throw new Error(`JWE should have 5 parts, got ${e.length}`);const[n,i,r,a,o]=e;return{header:n,key:i,iv:r,payload:a,mac:o}}(t);if(a!==Pt)throw new Error("Incorrect JWE header");const u=Ot(o),h=new Uint8Array(Ot(s)),f=jt((new N).encode(a),u,h);if(Ut(await Kt(f,r))!==c)throw new Error("MAC does not match JWE data");const p=await Mt(i),l=await async function(t,e,n){const i=await A.subtle.decrypt({name:"AES-CBC",length:xt,iv:t},e,n);return new Uint8Array(i)}(u,p,h);return(new k).decode(l)}async function Kt(t,e){return(await _(t,e)).slice(0,16)}function jt(t,e,n){return function(t){const e=t.reduce(((t,{length:e})=>t+e),0),n=new Uint8Array(e);let i=0;return t.forEach((t=>{n.set(t,i),i+=t.length})),n}([t,e,n,Vt(t.length<<3)])}const Dt=2**32;function qt(t,e,n){if(e<0||e>=Dt)throw new RangeError(`value must be >= 0 and <= ${Dt-1}. Received ${e}`);t.set([e>>>24,e>>>16,e>>>8,255&e],n)}function Vt(t){const e=Math.floor(t/Dt),n=t%Dt,i=new Uint8Array(8);return qt(i,e,0),qt(i,n,4),i}class Gt{constructor(t){this.maxSize=t,this.cachedItems=[]}getCacheSize(){return this.cachedItems.length}delete(t){this.cachedItems=this.cachedItems.filter((e=>e.key!==t))}add(t,e){this.delete(t),this.cachedItems.push({key:t,value:e}),this.cachedItems.length>this.maxSize&&this.cachedItems.shift()}get(t){return this.cachedItems.find((e=>e.key===t))}}class Ft{constructor(t){this.encryptionKey=t.encryptionKey,this.cache=new Gt(t.cacheMaxSize??5)}getCacheSize(){return this.cache.getCacheSize()}async memoizeFn(t,e){const n=this.cache.get(t);if(void 0!==n)return n.value;const i=await e();return this.cache.add(t,i),i}async encrypt(t){const e=`encrypt::${t}`;return await this.memoizeFn(e,(async()=>await Ht({plaintext:t,secret:this.encryptionKey})))}async decrypt(t){const e=`encrypt::${t}`;return await this.memoizeFn(e,(async()=>await $t({jwe:t,secret:this.encryptionKey})))}}function Xt(t){return t.bytesSent=""===t.bytesSent?"0":t.bytesSent,function({ip:t,userAgent:e,status:n,method:i,path:r,protocol:a,referer:o,bytesSent:s,requestTime:c,mitataCookie:u,sessionStatus:h,integrationType:f,integrationVersion:p}){const l=(new Date).toUTCString();return{Request:`${i} ${r} ${a}`,TimeLocal:l,RealIp:t,UserAgent:e,Status:n,RequestTime:c?.toString(),BytesSent:s?.toString(),Referer:""===o?"-":o,NetaceaUserIdCookie:u??"",NetaceaMitigationApplied:h??"",IntegrationType:f??"",IntegrationVersion:p??""}}(t)}async function zt(t,e,n){const i=Xt(n);if(e.ingestType!==r.KINESIS){const n={"X-Netacea-API-Key":e.apiKey??"","content-type":"application/json"},r=await async function(t,e,n,i){return await ut(t,0,{host:e.ingestServiceUrl,method:"POST",path:"/",headers:n,body:JSON.stringify(i),timeout:e.timeout})}(t,e,n,i);if(200!==r.status)throw at.fromResponse(r)}}function Wt(t,e,n,i,r,o){const s="unknown";r||("2"===i?i="4":"3"===i&&(i="5")),o&&(i="6");let c=Q[e]??s+"_";c+=Y[n]??s;let u=et[n];if("0"!==i){c+=","+(Z[i]??s);const t=nt[i];void 0!==t&&(u=t)}return t.mitigationType===a.INJECT&&(u=W.none),{sessionStatus:c,mitigation:u,parts:{match:e,mitigate:n,captcha:i}}}function Jt(t){return yt(t)?mt(t):V(t)}var Qt,Yt="@netacea/akamai",Zt="6.1.129";async function te(t,e,n,i){e.ingestType===r.HTTP&&await async function(t,e,n,i){const r=e.netaceaCookieName??"_mitata",a=i.getHeader("set-cookie")??[],o=0!==a.length?a?.join("; "):bt(n,"cookie");let s=await It(t,e,o,r)??"";if(void 0===s||""===s){const i=bt(n,"cookie");s=await It(t,e,i,r)??""}const{match:c,mitigate:u,captcha:h}=Jt(s)??{match:"0",mitigate:"0",captcha:"0"},{sessionStatus:f}=Wt(e,c,u,h,b(n.path,n.method),v(n.path,n.method,e.netaceaCheckpointSignalPath)),p=b(n.path,n.method)&&500===i.status;try{zt(t,e,{bytesSent:bt(i,"content-length","0"),ip:vt(n,"PMUSER_CLIENT_IP",""),method:n.method,path:n.url,protocol:bt(n,"protocol","HTTP/1.1"),referer:bt(n,"referer",""),requestTime:"0",sessionStatus:p?"error_open":f,status:String(i.status),userAgent:bt(n,"user-agent","-"),mitataCookie:s,integrationType:Yt.replace("@netacea/",""),integrationVersion:Zt})}catch(e){t.logger.error(e)}}(t,e,n,i)}async function ee(t,e,n,i,r,a){try{const o=void 0!==n?_t(n,e):void 0,s=o?.userId??i?.userId??"",c=void 0!==a?a.sessionStatus:function(t,e,n,i){if(void 0===e)return"error_open";const r=i?.match??n?.match??"0",a=i?.mitigate??n?.mitigate??"0",o=i?.captcha??n?.captcha??"0",{sessionStatus:s}=Wt(e,r,a,o,b(t.path,t.method),v(t.path,t.method,e.netaceaCheckpointSignalPath));return s}(e,n,i,o),{sessionReason:u,sessionStartTime:h,mitigationStatusCode:f}=t.getState(),p=[s,c,Zt,r?.headerFingerprint??"",r?.cookieFingerprint??"",u??"",h??"",n?.mitigationType??"",f??"",e.getVariable("PMUSER_NETACEA_REQUEST_ID")??"",ne(t,"logging_failure")].join(";");e.setVariable("PMUSER_NETACEA_DS2_CUSTOM_FIELD",p)}catch{}}function ne(t,e){try{const e=t.flush();return B.Buffer.from(e).toString("base64")}catch{return e}}function ie(t,e,n){t.setState({sessionReason:e,sessionStartTime:n??Math.floor(Date.now()/1e3)})}function re(t,e){e=e??t.query,t.route({origin:"mitigations",path:t.path,query:e})}function ae(t,e){const n=(new st).setQuery("headerFP",e.headerFingerprint),i=[];for(const e in it)void 0===t[e]&&i.push(e);return i.length>0&&n.setQuery("getSettings",i.join(",")),n}!function(t){t[t.NO_SESSION=0]="NO_SESSION",t[t.NEW_SESSION=1]="NEW_SESSION",t[t.EXISTING_SESSION=2]="EXISTING_SESSION",t[t.RENEW_SESSION=3]="RENEW_SESSION"}(Qt||(Qt={}));const{mitigationTypes:oe}=rt,se=[oe.block,oe.captcha,oe.captchaPass];async function ce(t,e,n,i,r){const{netaceaCookieInfo:a,clientIp:o,netaceaSession:s}=n;let c={status:-1,match:(u=a).match,mitigate:u.mitigate,captcha:u.captcha,mitataMaxAge:86400,netaceaSettings:{},responseNetaceaCookie:void 0,responseNetaceaCaptchaCookie:void 0};var u,h;if(void 0===e.secretKey)throw new Error("Secret key is required to mitigate");if(void 0!==n.netaceaCookieRequiredReissueReason){c=await async function(t,e,n,i,r,a){if(void 0===e.apiKey)throw new Error("An API Key is Required to call the protector API.");const o={"X-Netacea-API-Key":e.apiKey,"X-Netacea-Client-IP":n.clientIp,"X-Netacea-User-Agent":B.Buffer.from(n.userAgent).toString("base64"),cookie:ht({_mitatacaptcha:n.netaceaSession.captchaToken}),"X-Netacea-Request-Id":n.requestId};void 0!==n.netaceaSession.userId&&(o["X-Netacea-UserId"]=n.netaceaSession.userId),void 0!==e.captchaSiteKey&&void 0!==e.captchaSecretKey&&(o["X-Netacea-Captcha-Site-Key"]=e.captchaSiteKey,o["X-Netacea-Captcha-Secret-Key"]=e.captchaSecretKey),e.captchaContentNegotiation&&void 0!==e.netaceaCaptchaPath&&(o["X-Netacea-Captcha-Content-Type"]=ft(i));const s=ae(a,n.fingerprints);s.setQuery("netaceaHeaders","User-Agent, Request-ID");const c="application/json"===o["X-Netacea-Captcha-Content-Type"],u=await ut(t,0,{host:e.mitigationServiceUrl,path:"/"+s.buildQueryString(),headers:o,method:"GET",timeout:e.timeout});var h,f;h=t.logger,f=u.status,h.setState({mitigationStatusCode:f}),c&&void 0!==e.netaceaCaptchaPath&&(u.body=pt(u.body,r,e.netaceaCaptchaPath));let p={};return void 0!==u.headers["x-netacea-settings"]&&(p=wt(u.headers["x-netacea-settings"])),await ot(t,e,void 0,u,n.netaceaSession.userId,n.clientIp,n.netaceaCookieRequiredReissueReason,{...a,...p})}(t,e,n,i,r,n.netaceaSettings),c.responseNetaceaCookie=await z(o,s.userId,c.match,c.mitigate,c.captcha,n.netaceaCookieRequiredReissueReason,c.netaceaSettings,c.mitataMaxAge);const u=void 0===a.mitata?Qt.NEW_SESSION:Qt.RENEW_SESSION;ie(t.logger,u)}else{const e=a.mitata;if(void 0!==e){const n=gt(h=e)?h.issueTimestamp:Number.parseInt(h.expiry,10)-60;ie(t.logger,Qt.EXISTING_SESSION,n)}}const f=Wt(e,c.match,c.mitigate,c.captcha,!1,!1);return{body:c.body,apiCallStatus:c.status,responseNetaceaCookie:c?.responseNetaceaCookie,responseNetaceaCaptchaCookie:void 0,sessionStatus:f.sessionStatus,mitigation:f.mitigation,mitigated:se.includes(f.mitigation),bestMitigation:f,eventId:c.eventId}}function ue(t){return{apiCallStatus:0,responseNetaceaCookie:t,responseNetaceaCaptchaCookie:void 0,sessionStatus:"",mitigation:"000",mitigated:!1,bestMitigation:{sessionStatus:"",mitigation:"",parts:{match:"0",mitigate:"0",captcha:"0"}},eventId:void 0}}async function he(t){return{sessionStatus:"",response:{headers:{},body:void 0,status:0,statusText:"",mitigation:"000"},bestAction:ue(await z(s,t,"0","0","0",o.NO_SESSION,void 0,86400))}}async function fe(t,e,n,i){try{switch(e.mitigationType){case a.MITIGATE:return await async function(t,e,n,i){const r=bt(n,"accept","text/html"),a=await ce(t,e,i,r,n.host),o={};let s,c;return a.mitigated&&(c=403,"captcha"===a.mitigation?(o["content-type"]="text/html; charset=UTF-8",s=a.body):s="Forbidden"),{response:{body:s,status:c,statusText:c?.toString(),headers:o,mitigation:a.mitigation},sessionStatus:a.sessionStatus,bestAction:a}}(t,e,n,i);case a.INJECT:return await async function(t,e,n,i){const r=bt(n,"accept","text/html"),a=await ce(t,e,i,r,n.host),o={"x-netacea-match":a.bestMitigation.parts.match.toString(),"x-netacea-mitigate":a.bestMitigation.parts.mitigate.toString(),"x-netacea-captcha":a.bestMitigation.parts.captcha.toString()};return void 0!==a.eventId&&(o["x-netacea-event-id"]=a.eventId),{injectHeaders:o,sessionStatus:a.sessionStatus,response:{headers:{}},bestAction:a}}(t,e,n,i);case a.INGEST:return await async function(t,e,n){if(void 0===e.secretKey)throw new Error("Secret key is required for ingest");const i=bt(n,"cookie"),r=await It(t,e,i,e.netaceaCookieName??"_mitata"),a=await At(r,s,e.secretKey);return a.isPrimaryHashValid?a.requiresReissue?await he(a.mitata?.userId):{sessionStatus:"",response:void 0,bestAction:ue()}:await he(void 0)}(t,e,n);default:throw new Error(`Netacea Error: Mitigation type ${e.mitigationType} not recognised`)}}catch(e){return t.logger.error(e),await Promise.resolve({injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"},sessionStatus:"error_open",response:void 0,bestAction:void 0})}}async function pe(t,e,n,i){let o={};if(void 0!==n?.bestAction?.responseNetaceaCookie){const t=n?.bestAction?.responseNetaceaCookie;void 0!==t&&i.setVariable(e.protoMitataVariableName,JSON.stringify(t))}if(e.mitigationType===a.INJECT){o=n.injectHeaders??{}}let s={};e.ingestType===r.ORIGIN&&(s=await async function(t,e,n){const i=bt(n,"cookie"),r=Jt(await It(t,e,i,e.netaceaCookieName)??""),a=_t(e,n),{match:o,mitigate:s,captcha:c,userId:u}=a??r??{match:"0",mitigate:"0",captcha:"0",userId:""},{sessionStatus:h}=Wt(e,o,s,c,b(n.path,n.method),!1);return{"X-Netacea-UserId":u,"X-Netacea-BC-Type":h,"X-Netacea-Integration-Type":Yt.replace("@netacea/",""),"X-Netacea-Integration-Version":Zt}}(t,e,i));for(const[t,e]of Object.entries({...o,...s}))i.addHeader(t,e)}async function le(t){const e=function(t){return Object.keys(t).filter((t=>{const e=t.toLowerCase();return"cookie"!==e&&"referer"!==e&&!e.startsWith("x-netacea-")})).join(",")}(t);return await de(e)}async function de(t){let e="";try{e=await async function(t,e){const n=(new N).encode(e),i=await A.subtle.digest(t,n);return Array.from(new Uint8Array(i)).map((t=>t.toString(16).padStart(2,"0"))).join("")}("SHA-256",t)}catch(t){e=""}return e}async function ge(t){const e=t.getHeaders(),n=await le(e),i=function(t,e){const n=t.getHeader(e);return null==n?[]:n}(t,"cookie").map((t=>t.split(/; ?/).map((t=>t.split("=")[0])))).flat(),r=await async function(t){const e=t.join(",");return await de(e)}(i);return[""===n?n:`h_${n.substring(1,15)}`,""===r?r:`c_${r.substring(1,15)}`]}async function ye(t,e,n){const r=vt(n,"PMUSER_CLIENT_IP"),a=bt(n,"user-agent"),s=void 0!==e.altCookieHeaderName?bt(n,e.altCookieHeaderName):void 0,c=void 0!==s&&""!==s?s:bt(n,"cookie");void 0!==e.altCookieHeaderName&&void 0!==s&&""!==s&&n.setVariable("NETACEA_USES_ALT_COOKIE_HEADER","true");const u=await It(t,e,c,e.netaceaCookieName),h=await At(u,r,e.secretKey),f=function(t,e,n,i,r){if(void 0!==i&&!r.isPrimaryHashValid)return o.INVALID_SESSION;if(void 0===i)return function(t,e){for(const n of Ct(t))if(n.startsWith(`${e}=`))return!0;return!1}(e,n)?o.INVALID_SESSION:o.NO_SESSION;if(r.isExpired)return o.EXPIRED_SESSION;if(!r.isSameIP)return o.IP_CHANGE;const a="post"===t.method.toLowerCase(),s=St(r.mitata);if(a&&1===s.checkAllPostRequests)return o.FORCED_REVALIDATION}(n,c,e.netaceaCookieName,u,h),p=St(h.mitata),l=await It(t,e,c,e.netaceaCaptchaCookieName),[d,g]=await ge(n);let y=n.getVariable("PMUSER_NETACEA_REQUEST_ID")??"";if(""===y)try{y=i(),n.setVariable("PMUSER_NETACEA_REQUEST_ID",y)}catch(e){y="",t.logger.error("REQ_ID error")}return{clientIp:r,userAgent:a,method:n.method,netaceaCookieInfo:h,netaceaCookieRequiredReissueReason:f,netaceaSession:{userId:h.mitata?.userId,captchaToken:l,match:h.match,mitigate:h.mitigate,captcha:h.captcha},fingerprints:{headerFingerprint:d,cookieFingerprint:g},requestId:y,netaceaSettings:p}}class me{constructor(t){this.errorLog="",this.options=t,this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}getState(){return Object.assign({},this.state)}setState(t){for(const e in this.state)void 0!==t[e]&&(this.state[e]=t[e])}appendErrorLog(t){this.errorLog=function(t,e,n){if(e-t.length<=2)return t;const i=n.trim().slice(0,e).replace(/\n/g,"\\n");return(""===t?i:t+"\n"+i).slice(0,e)}(this.errorLog,this.options.maxErrorLogLength,t)}error(t){try{if(this.options.maxErrorLogLength<=0||null==t||""===t)return;if("string"==typeof t)this.appendErrorLog(t);else{const e=function(t){if(void 0!==t.stack)return t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack;return t.message}(t);this.appendErrorLog(e)}}catch{}}flush(){try{return this.errorLog}finally{this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}}}class we{constructor(e){this.configLoader=new m(e),this.runtimeDeps={httpRequest:t}}initDeps(t,e){const n=void 0===e.cookieEncryptionKey?void 0:new Ft({encryptionKey:e.cookieEncryptionKey});return{...this.runtimeDeps,config:e,logger:t,cachedEncryption:n}}async requestHandler(t){const e=new me({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(t)});let n,i,r;try{i=this.configLoader.loadConfig(t);const u=this.initDeps(e,i);r=await ye(u,i,t),void 0!==r.netaceaCookieRequiredReissueReason&&t.setVariable("PMUSER_NETACEA_ISSUE_REASON",r.netaceaCookieRequiredReissueReason),a=t.path,s=t.method,void 0!==(c=i.netaceaCaptchaPath)&&c.length>0&&a===c&&"get"===s.toLowerCase()?await async function(t,e,n,i){const r=bt(n,"cookie"),a=await It(t,e,r,e.netaceaCookieName),s=await It(t,e,r,e.netaceaCaptchaCookieName),c=vt(n,"PMUSER_CLIENT_IP"),u=bt(n,"user-agent"),h=await At(a,c,e.secretKey),f=kt(e,"captcha",403),p=await Et(t,e,i.netaceaSettings,{apiKey:e.apiKey??"",clientIP:c,userAgent:u,userId:h.mitata?.userId,captchaCookie:s,trackingId:Nt(n.query,"trackingId"),captchaSiteKey:e.captchaSiteKey,captchaSecretKey:e.captchaSecretKey,accept:bt(n,"accept","text/html"),host:n.host,requestId:i.requestId},{match:"0",mitigate:"0",captcha:"1"}),l=p.responseNetaceaCookie;void 0!==l&&(void 0===i.netaceaCookieRequiredReissueReason?l.issueReason=o.CAPTCHA_GET:l.issueReason=i.netaceaCookieRequiredReissueReason,n.setVariable(e.protoMitataVariableName,JSON.stringify(l)));const d={};void 0!==e.netaceaCaptchaHeaderKey&&void 0!==e.netaceaCaptchaHeaderValue&&(d[e.netaceaCaptchaHeaderKey]=e.netaceaCaptchaHeaderValue),n.respondWith(f,d,p.body??"")}(u,i,t,r):b(t.path,t.method)?await async function(t,e,n,i){if(void 0===e.apiKey)throw new Error("An API Key is Required to Verify Captcha");const r=n.getVariable("PMUSER_CLIENT_IP")??"";n.setHeader("x-netacea-api-key",e.apiKey),n.setHeader("x-netacea-client-ip",r);const a=bt(n,"cookie"),o=await It(t,e,a,e.netaceaCookieName)??"";let s="";const c=await At(o,r,e.secretKey??"");if(gt(c.mitata)){const t={checkAllPostRequests:c.mitata.checkAllPostRequests};n.setHeader("x-netacea-settings",JSON.stringify(t))}c.isPrimaryHashValid&&(s=c.mitata?.userId??""),n.setHeader("x-netacea-userid",s),n.setHeader("x-netacea-user-agent",B.Buffer.from(i.userAgent).toString("base64")),n.setHeader("x-netacea-request-id",i.requestId);const u=ae(i.netaceaSettings,i.fingerprints);u.setQuery("netaceaHeaders","User-Agent, Request-ID"),re(n,u.buildQueryString())}(u,i,t,r):I(t.path,t.method,i.useCaptchaRelAssets)?re(t):v(t.path,t.method,i.netaceaCheckpointSignalPath)?await async function(t){t.respondWith(200,{},"")}(t):function(t,e){if(void 0===e.netaceaBlockedResponseRedirectLocation)return!1;if(e.netaceaBlockedResponseRedirectLocation.startsWith("/"))return e.netaceaBlockedResponseRedirectLocation===t.path;try{const n=new URL(e.netaceaBlockedResponseRedirectLocation);return n.host===t.host&&n.pathname===t.path}catch{return!1}}(t,i)||(n=await async function(t,e,n,i){const r=await fe(t,e,n,i);if(void 0===r)throw new Error('Mitigation Service response "mitResult" was undefined.');const a=r.response?.mitigation;if("block"===a||"captcha"===a){let t=kt(e,a,r.response?.status??403);const i={},o=e.netaceaBlockedResponseRedirectLocation;"block"===a&&void 0!==o&&function(t){if("GET"!==t.method?.toUpperCase())return!1;const e=t.getHeader("sec-fetch-mode")??[];return!(e.length>0&&!e.includes("navigate"))&&(t.getHeader("accept")?.map((t=>t.split(/, ?/))).flat()??[]).includes("text/html")}(n)&&(t=303,i.Location=o);const s=r.bestAction?.responseNetaceaCookie;void 0!==s&&n.setVariable(e.protoMitataVariableName,JSON.stringify(s));const c=r.response?.body??"";(function(t){return t.includes("captchaRelativeURL")&&t.includes("captchaAbsoluteURL")})(c)&&(i["content-type"]="application/json"),"captcha"===a&&(void 0===i["content-type"]&&(i["content-type"]="text/html"),void 0!==e.netaceaCaptchaHeaderKey&&void 0!==e.netaceaCaptchaHeaderValue&&(i[e.netaceaCaptchaHeaderKey]=e.netaceaCaptchaHeaderValue)),n.respondWith(t,i,c)}else await pe(t,e,r,n);return r}(u,i,t,r))}catch(t){e.error(t)}finally{try{await ee(e,t,i,r?.netaceaSession,r?.fingerprints,n)}catch{}}var a,s,c}async responseHandler(t,e){const n=new me({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(t)});try{const i=this.configLoader.loadConfig(t),r=this.initDeps(n,i);if(b(t.path,t.method))await Bt(r,i,t,e);else if(C(t.path,t.method)&&!I(t.path,t.method,i.useCaptchaRelAssets)){const n=t.getVariable("PMUSER_NETACEA_ISSUE_REASON")!==o.NO_SESSION,a=t.getVariable("NETACEA_USES_ALT_COOKIE_HEADER");n&&"true"!==a&&await Tt(r,i,t,e)}else if(!I(t.path,t.method,i.useCaptchaRelAssets)){"true"!==t.getVariable("NETACEA_USES_ALT_COOKIE_HEADER")&&await Tt(r,i,t,e)}!function(t){t.removeHeader("x-netacea-match"),t.removeHeader("x-netacea-mitigate"),t.removeHeader("x-netacea-captcha"),t.removeHeader("x-netacea-mitata-expiry"),t.removeHeader("x-netacea-mitata-value"),t.removeHeader("x-netacea-mitatacaptcha-expiry"),t.removeHeader("x-netacea-mitatacaptcha-value"),t.removeHeader("x-netacea-event-id"),t.removeHeader("x-netacea-settings")}(e),await te(r,i,t,e)}catch(t){n.error(t)}}}export{a as NetaceaMitigationType,we as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netacea/akamai",
3
- "version": "6.1.128",
3
+ "version": "6.1.129",
4
4
  "description": "Netacea Akamai CDN Integration",
5
5
  "author": "Netacea <integrations@netacea.com> (https://netacea.com)",
6
6
  "main": "dist/index.js",
@@ -14,12 +14,12 @@
14
14
  },
15
15
  "license": "UNLICENSED",
16
16
  "dependencies": {
17
- "@netacea/netaceaintegrationbase": "^2.0.109",
17
+ "@netacea/netaceaintegrationbase": "^2.0.110",
18
18
  "buffer": "^6.0.3",
19
19
  "uuid": "^11.1.0"
20
20
  },
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
- "gitHead": "19b3f8558d6065d02653194ccbe9364b7580bf9e"
24
+ "gitHead": "7ad71d9a046211ec589e080d0ce555fe8b091785"
25
25
  }