@netacea/akamai 6.6.2 → 6.7.1
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.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="akamai-edgeworkers" />
|
|
2
2
|
import { RequestBody, HttpResponse } from 'http-request';
|
|
3
|
-
import { NetaceaMitigationType, NetaceaIngestType, NetaceaCookieV3IssueReason } from '@netacea/netaceaintegrationbase';
|
|
3
|
+
import { NetaceaMitigationType, NetaceaIngestType, NetaceaCookieV3IssueReason, InjectHeaders } from '@netacea/netaceaintegrationbase';
|
|
4
4
|
export { InjectResponse, NetaceaMitigationType } from '@netacea/netaceaintegrationbase';
|
|
5
5
|
import { KinesisIngestConfigArgs } from '@netacea/kinesisingest';
|
|
6
6
|
import { cookie } from '@netacea/integrations-sdk';
|
|
@@ -125,6 +125,7 @@ interface AkamaiMitigateResponse {
|
|
|
125
125
|
bestAction: BestActionResponse | undefined;
|
|
126
126
|
response: ResponseProperties | undefined;
|
|
127
127
|
sessionStatus: string;
|
|
128
|
+
injectHeaders?: InjectHeaders;
|
|
128
129
|
}
|
|
129
130
|
interface UpstreamMitHeaders {
|
|
130
131
|
'X-Netacea-UserId': string;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{httpRequest as e}from"http-request";import*as t from"crypto";import*as i from"encoding";import{v7 as n}from"uuid";var r,
|
|
1
|
+
import{httpRequest as e}from"http-request";import*as t from"crypto";import*as i from"encoding";import{v7 as n}from"uuid";var a,r,o;!function(e){e.ORIGIN="ORIGIN",e.HTTP="HTTP",e.KINESIS="KINESIS",e.NATIVE="NATIVE"}(a||(a={})),function(e){e.MITIGATE="MITIGATE",e.INJECT="INJECT",e.INGEST="INGEST"}(r||(r={})),function(e){e.CAPTCHA_GET="captcha_get",e.CAPTCHA_POST="captcha_post",e.EXPIRED_SESSION="expired_session",e.FORCED_REVALIDATION="forced_revalidation",e.INVALID_SESSION="invalid_session",e.IP_CHANGE="ip_change",e.NO_SESSION="no_session"}(o||(o={}));const s="ignored";function c(e,t){const i=e.split(";").map((e=>e.trim())).filter((e=>e.toLowerCase().startsWith(t.toLowerCase())))[0];return void 0!==i&&i.length>0?i?.replace(`${t}=`,""):void 0}function u(e,t=!1){return"string"!=typeof e&&(e=e.join("; ")),""===e?"":h(e.split(";"),t).join("; ")}function h(e,t=!1){if(t)return h(e.reverse()).reverse();const i=new Set,n=[];for(let t of e){if(t=t.trimStart(),""===t.trim())continue;const e=t.split("=")[0].toUpperCase();i.has(e)||(i.add(e),n.push(t))}return n}function f(e){const t=u([e.otherAttributes??"",`Max-Age=${e.maxAgeAttribute??86400}`,"Path=/"].join("; "));return`${e.cookieName}=${e.cookieValue}; ${t}`}const p={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(e,t){let i=e=u(e??"",!0),n=t=u(t??"",!0);if(void 0!==e&&void 0!==t){const a=c(e,"Domain"),r=c(t,"Domain");void 0!==a&&void 0!==r?n=t.replace(r,a):void 0!==a&&void 0===r?n=t+(""!==t?`; Domain=${a}`:`Domain=${a}`):void 0===a&&void 0!==r&&(i=e+(""!==e?`; Domain=${r}`:`Domain=${r}`))}else if(void 0!==e&&void 0===t){const t=c(e,"Domain");void 0!==t&&(n=`Domain=${t}`)}else if(void 0===e&&void 0!==t){const e=c(t,"Domain");void 0!==e&&(i=`Domain=${e}`)}return{cookieAttributes:""!==i?i:void 0,captchaCookieAttributes:""!==n?n:void 0}},extractAndRemoveCookieAttr:function(e,t){const i=c(e,t);if(void 0!==i){return{extractedAttribute:i,cookieAttributes:e.replace(/ /g,"").replace(`${t}=${i}`,"").split(";").filter((e=>e.length>0)).join("; ")}}return{extractedAttribute:void 0,cookieAttributes:e}},extractCookieAttr:c,removeDuplicateAttrs:u}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(e){return f({...e,cookieName:e.cookieName??"_mitatacaptcha"})},createNetaceaSetCookieString:function(e){return f({...e,cookieName:e.cookieName??"_mitata"})},createSetCookieString:f})}},{configureCookiesDomain:d}=p.cookie.attributes,l="PMUSER_NETACEA_";class g{constructor(e){this.getNumber=(e,t)=>{const i=this.getString(e);try{const e=Number(i);if(!isNaN(e))return e}catch{}return t},this.getBoolean=(e,t)=>{const i=this.getString(e);return void 0!==i?"true"===(i?.toLowerCase()??"false"):t},this.request=e}getString(e,t){e.startsWith(l)&&(e=e.slice(15));const i=`${l}${e}`;return this.request.getVariable(i)??t??t}}class y{constructor(e){this.defaults=e}getMaxErrorLogLength(e){const t=new g(e).getNumber("MAX_ERR_LOG_LEN")??0;return t>0?Math.min(500,t):0}loadConfig(e){const t=new g(e),i=t.getString("MITIGATION_TYPE",this.defaults.mitigationType),n=t.getString("INGEST_TYPE",this.defaults.ingestType),a=t.getString("COOKIE_ATTR"),r=t.getString("CAP_COOKIE_ATTR"),{cookieAttributes:o,captchaCookieAttributes:s}=d(a,r);let c=t.getString("CAPT_PATH");void 0!==c&&c.length>0&&"/"!==c?.[0]&&(c=`/${c}`);const u=t.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=t.getString("INGEST_URL");let f;f=void 0!==h?h:this.defaults.ingestServiceUrl??"https://ingest.netacea.net";const p=t.getString("MITIGATION_URL");let l;l=void 0!==p?p:this.defaults.mitigationServiceUrl??"https://mitigations.netacea.net";const y={...this.defaults,mitigationServiceUrl:l,ingestServiceUrl:f,apiKey:t.getString("API_KEY",this.defaults.apiKey),cookieEncryptionKey:t.getString("ENCRYPTION_KEY",this.defaults.cookieEncryptionKey),ingestType:n,mitigationType:i,altCookieHeaderName:t.getString("ALT_COOKIE_HEADER"),netaceaCaptchaCookieAttributes:s??"",netaceaCaptchaCookieName:t.getString("CAPT_COOKIE_NAME",this.defaults.netaceaCaptchaCookieName)??"_mitatacaptcha",netaceaCookieAttributes:o??"",netaceaCookieExpirySeconds:m(this.defaults,i),netaceaCookieName:t.getString("COOKIE_NAME",this.defaults.netaceaCookieName)??"_mitata",netaceaCaptchaPath:c,netaceaCaptchaHeaderKey:t.getString("CAPT_HEADER_KEY"),netaceaCaptchaHeaderValue:t.getString("CAPT_HEADER_VALUE"),netaceaCaptchaResponseStatus:t.getString("CAPT_STATUS"),netaceaBlockedResponseStatus:t.getString("BLOCK_STATUS"),netaceaBlockedResponseRedirectLocation:t.getString("BLOCK_LOCATION"),captchaContentNegotiation:t.getBoolean("CAPT_CONTENT_NGT",!1)??!1,secretKey:u,useCaptchaRelAssets:t.getBoolean("CAPT_REL_ASSETS",this.defaults.useCaptchaRelAssets)??!1,protoMitataVariableName:"PMUSER_NETACEA_PROTO_MITATA",encryptedCookieNames:[],netaceaCheckpointSignalPath:t.getString("SIGNAL_PATH")};return y.netaceaCookieName=S(y.netaceaCookieName,"_mitata"),y.netaceaCaptchaCookieName=S(y.netaceaCaptchaCookieName,"_mitatacaptcha"),y.encryptedCookieNames.push(y.netaceaCookieName),y.encryptedCookieNames.push(y.netaceaCaptchaCookieName),void 0!==y.netaceaCaptchaHeaderKey&&void 0===y.netaceaCaptchaHeaderValue&&(y.netaceaCaptchaHeaderValue="true"),y}}function m(e,t){const i=e.netaceaCookieExpirySeconds??e.mitataCookieExpirySeconds;return void 0===i?t===r.INGEST?3600:60:i}function S(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}const I=/\.(js|css)$/i;function w(e,t,i){if(!0!==i)return!1;const n=e.toLowerCase();return/\/?mitigations\//.test(n)&&v(e,t)}function v(e,t){const i=e.toLowerCase();return I.test(i)&&"get"===t.toLowerCase()}function C(e,t){return/\/?ataverifycaptcha$/.test(e.toLowerCase())&&"post"===t.toLowerCase()}function b(e,t,i){return void 0!==i&&i.length>0&&e===i&&"get"===t.toLowerCase()}var E=t.crypto??t;const k=i.TextEncoder??global.TextEncoder,A=i.TextDecoder??global.TextDecoder;async function N(e,t){const i=await async function(e){return await E.subtle.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}(function(e){return"string"==typeof e?(new k).encode(e):e}(t));return new Uint8Array(await E.subtle.sign("HMAC",i,e))}for(var _="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},R={},O={byteLength:function(e){var t=M(e),i=t[0],n=t[1];return 3*(i+n)/4-n},toByteArray:function(e){var t,i,n=M(e),a=n[0],r=n[1],o=new x(function(e,t,i){return 3*(t+i)/4-i}(0,a,r)),s=0,c=r>0?a-4:a;for(i=0;i<c;i+=4)t=P[e.charCodeAt(i)]<<18|P[e.charCodeAt(i+1)]<<12|P[e.charCodeAt(i+2)]<<6|P[e.charCodeAt(i+3)],o[s++]=t>>16&255,o[s++]=t>>8&255,o[s++]=255&t;2===r&&(t=P[e.charCodeAt(i)]<<2|P[e.charCodeAt(i+1)]>>4,o[s++]=255&t);1===r&&(t=P[e.charCodeAt(i)]<<10|P[e.charCodeAt(i+1)]<<4|P[e.charCodeAt(i+2)]>>2,o[s++]=t>>8&255,o[s++]=255&t);return o},fromByteArray:function(e){for(var t,i=e.length,n=i%3,a=[],r=16383,o=0,s=i-n;o<s;o+=r)a.push(V(e,o,o+r>s?s:o+r));1===n?(t=e[i-1],a.push(T[t>>2]+T[t<<4&63]+"==")):2===n&&(t=(e[i-2]<<8)+e[i-1],a.push(T[t>>10]+T[t>>4&63]+T[t<<2&63]+"="));return a.join("")}},T=[],P=[],x="undefined"!=typeof Uint8Array?Uint8Array:Array,L="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",B=0;B<64;++B)T[B]=L[B],P[L.charCodeAt(B)]=B;function M(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function V(e,t,i){for(var n,a,r=[],o=t;o<i;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),r.push(T[(a=n)>>18&63]+T[a>>12&63]+T[a>>6&63]+T[63&a]);return r.join("")}P["-".charCodeAt(0)]=62,P["_".charCodeAt(0)]=63;var U={
|
|
2
2
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
3
|
-
read:function(e,t,i,n,
|
|
3
|
+
read:function(e,t,i,n,a){var r,o,s=8*a-n-1,c=(1<<s)-1,u=c>>1,h=-7,f=i?a-1:0,p=i?-1:1,d=e[t+f];for(f+=p,r=d&(1<<-h)-1,d>>=-h,h+=s;h>0;r=256*r+e[t+f],f+=p,h-=8);for(o=r&(1<<-h)-1,r>>=-h,h+=n;h>0;o=256*o+e[t+f],f+=p,h-=8);if(0===r)r=1-u;else{if(r===c)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,n),r-=u}return(d?-1:1)*o*Math.pow(2,r-n)},write:function(e,t,i,n,a,r){var o,s,c,u=8*r-a-1,h=(1<<u)-1,f=h>>1,p=23===a?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:r-1,l=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=h):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),(t+=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=(t*c-1)*Math.pow(2,a),o+=f):(s=t*Math.pow(2,f-1)*Math.pow(2,a),o=0));a>=8;e[i+d]=255&s,d+=l,s/=256,a-=8);for(o=o<<a|s,u+=a;u>0;e[i+d]=255&o,d+=l,o/=256,u-=8);e[i+d-l]|=128*g}};
|
|
4
4
|
/*!
|
|
5
5
|
* The buffer module from node.js, for the browser.
|
|
6
6
|
*
|
|
7
7
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
8
8
|
* @license MIT
|
|
9
9
|
*/
|
|
10
|
-
!function(e){const t=O,i=U,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){+e!=e&&(e=0);return o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const r=2147483647;function a(e){if(e>r)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,i){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return s(e,t,i)}function s(e,t,i){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const i=0|d(e,t);let n=a(i);const r=n.write(e,t);r!==i&&(n=n.slice(0,r));return n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(W(e,Uint8Array)){const t=new Uint8Array(e);return f(t.buffer,t.byteOffset,t.byteLength)}return h(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(W(e,ArrayBuffer)||e&&W(e.buffer,ArrayBuffer))return f(e,t,i);if("undefined"!=typeof SharedArrayBuffer&&(W(e,SharedArrayBuffer)||e&&W(e.buffer,SharedArrayBuffer)))return f(e,t,i);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,i);const r=function(e){if(o.isBuffer(e)){const t=0|p(e.length),i=a(t);return 0===i.length||e.copy(i,0,0,t),i}if(void 0!==e.length)return"number"!=typeof e.length||J(e.length)?a(0):h(e);if("Buffer"===e.type&&Array.isArray(e.data))return h(e.data)}(e);if(r)return r;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,i);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function c(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return c(e),a(e<0?0:0|p(e))}function h(e){const t=e.length<0?0:0|p(e.length),i=a(t);for(let n=0;n<t;n+=1)i[n]=255&e[n];return i}function f(e,t,i){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(i||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,t):new Uint8Array(e,t,i),Object.setPrototypeOf(n,o.prototype),n}function p(e){if(e>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|e}function d(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||W(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const i=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===i)return 0;let r=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":return z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return G(e).length;default:if(r)return n?-1:z(e).length;t=(""+t).toLowerCase(),r=!0}}function l(e,t,i){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return _(this,t,i);case"utf8":case"utf-8":return b(this,t,i);case"ascii":return A(this,t,i);case"latin1":case"binary":return N(this,t,i);case"base64":return E(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,i){const n=e[t];e[t]=e[i],e[i]=n}function y(e,t,i,n,r){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),J(i=+i)&&(i=r?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(r)return-1;i=e.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:m(e,t,i,n,r);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):m(e,[t],i,n,r);throw new TypeError("val must be string, number or Buffer")}function m(e,t,i,n,r){let a,o=1,s=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,s/=2,c/=2,i/=2}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(r){let n=-1;for(a=i;a<s;a++)if(u(e,a)===u(t,-1===n?0:a-n)){if(-1===n&&(n=a),a-n+1===c)return n*o}else-1!==n&&(a-=a-n),n=-1}else for(i+c>s&&(i=s-c),a=i;a>=0;a--){let i=!0;for(let n=0;n<c;n++)if(u(e,a+n)!==u(t,n)){i=!1;break}if(i)return a}return-1}function S(e,t,i,n){i=Number(i)||0;const r=e.length-i;n?(n=Number(n))>r&&(n=r):n=r;const a=t.length;let o;for(n>a/2&&(n=a/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(J(n))return o;e[i+o]=n}return o}function I(e,t,i,n){return X(z(t,e.length-i),e,i,n)}function w(e,t,i,n){return X(function(e){const t=[];for(let i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function v(e,t,i,n){return X(G(t),e,i,n)}function C(e,t,i,n){return X(function(e,t){let i,n,r;const a=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)i=e.charCodeAt(o),n=i>>8,r=i%256,a.push(r),a.push(n);return a}(t,e.length-i),e,i,n)}function E(e,i,n){return 0===i&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(i,n))}function b(e,t,i){i=Math.min(e.length,i);const n=[];let r=t;for(;r<i;){const t=e[r];let a=null,o=t>239?4:t>223?3:t>191?2:1;if(r+o<=i){let i,n,s,c;switch(o){case 1:t<128&&(a=t);break;case 2:i=e[r+1],128==(192&i)&&(c=(31&t)<<6|63&i,c>127&&(a=c));break;case 3:i=e[r+1],n=e[r+2],128==(192&i)&&128==(192&n)&&(c=(15&t)<<12|(63&i)<<6|63&n,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:i=e[r+1],n=e[r+2],s=e[r+3],128==(192&i)&&128==(192&n)&&128==(192&s)&&(c=(15&t)<<18|(63&i)<<12|(63&n)<<6|63&s,c>65535&&c<1114112&&(a=c))}}null===a?(a=65533,o=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|1023&a),n.push(a),r+=o}return function(e){const t=e.length;if(t<=k)return String.fromCharCode.apply(String,e);let i="",n=0;for(;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=k));return i}(n)}e.kMaxLength=r,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,i){return s(e,t,i)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,i){return function(e,t,i){return c(e),e<=0?a(e):void 0!==t?"string"==typeof i?a(e).fill(t,i):a(e).fill(t):a(e)}(e,t,i)},o.allocUnsafe=function(e){return u(e)},o.allocUnsafeSlow=function(e){return u(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),W(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,n=t.length;for(let r=0,a=Math.min(i,n);r<a;++r)if(e[r]!==t[r]){i=e[r],n=t[r];break}return i<n?-1:n<i?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;const n=o.allocUnsafe(t);let r=0;for(i=0;i<e.length;++i){let t=e[i];if(W(t,Uint8Array))r+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,r)):Uint8Array.prototype.set.call(n,t,r);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,r)}r+=t.length}return n},o.byteLength=d,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)g(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?b(this,0,e):l.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const i=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,i).replace(/(.{2})/g,"$1 ").trim(),this.length>i&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,i,n,r){if(W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),t<0||i>e.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&t>=i)return 0;if(n>=r)return-1;if(t>=i)return 1;if(this===e)return 0;let a=(r>>>=0)-(n>>>=0),s=(i>>>=0)-(t>>>=0);const c=Math.min(a,s),u=this.slice(n,r),h=e.slice(t,i);for(let e=0;e<c;++e)if(u[e]!==h[e]){a=u[e],s=h[e];break}return a<s?-1:s<a?1:0},o.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},o.prototype.indexOf=function(e,t,i){return y(this,e,t,i,!0)},o.prototype.lastIndexOf=function(e,t,i){return y(this,e,t,i,!1)},o.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(i)?(i>>>=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}const r=this.length-t;if((void 0===i||i>r)&&(i=r),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let a=!1;for(;;)switch(n){case"hex":return S(this,e,t,i);case"utf8":case"utf-8":return I(this,e,t,i);case"ascii":case"latin1":case"binary":return w(this,e,t,i);case"base64":return v(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,t,i);default:if(a)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),a=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const k=4096;function A(e,t,i){let n="";i=Math.min(e.length,i);for(let r=t;r<i;++r)n+=String.fromCharCode(127&e[r]);return n}function N(e,t,i){let n="";i=Math.min(e.length,i);for(let r=t;r<i;++r)n+=String.fromCharCode(e[r]);return n}function _(e,t,i){const n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);let r="";for(let n=t;n<i;++n)r+=Q[e[n]];return r}function R(e,t,i){const n=e.slice(t,i);let r="";for(let e=0;e<n.length-1;e+=2)r+=String.fromCharCode(n[e]+256*n[e+1]);return r}function T(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,i,n,r,a){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>r||t<a)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function x(e,t,i,n,r){D(t,n,r,e,i,7);let a=Number(t&BigInt(4294967295));e[i++]=a,a>>=8,e[i++]=a,a>>=8,e[i++]=a,a>>=8,e[i++]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[i++]=o,o>>=8,e[i++]=o,o>>=8,e[i++]=o,o>>=8,e[i++]=o,i}function L(e,t,i,n,r){D(t,n,r,e,i,7);let a=Number(t&BigInt(4294967295));e[i+7]=a,a>>=8,e[i+6]=a,a>>=8,e[i+5]=a,a>>=8,e[i+4]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[i+3]=o,o>>=8,e[i+2]=o,o>>=8,e[i+1]=o,o>>=8,e[i]=o,i+8}function B(e,t,i,n,r,a){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function M(e,t,n,r,a){return t=+t,n>>>=0,a||B(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function V(e,t,n,r,a){return t=+t,n>>>=0,a||B(e,0,n,8),i.write(e,t,n,r,52,8),n+8}o.prototype.slice=function(e,t){const i=this.length;(e=~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),(t=void 0===t?i:~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=this[e],r=1,a=0;for(;++a<t&&(r*=256);)n+=this[e+a]*r;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=this[e+--t],r=1;for(;t>0&&(r*=256);)n+=this[e+--t]*r;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||T(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||T(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||T(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,r=this[++e]+256*this[++e]+65536*this[++e]+i*2**24;return BigInt(n)+(BigInt(r)<<BigInt(32))})),o.prototype.readBigUInt64BE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],r=this[++e]*2**24+65536*this[++e]+256*this[++e]+i;return(BigInt(n)<<BigInt(32))+BigInt(r)})),o.prototype.readIntLE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=this[e],r=1,a=0;for(;++a<t&&(r*=256);)n+=this[e+a]*r;return r*=128,n>=r&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=t,r=1,a=this[e+--n];for(;n>0&&(r*=256);)a+=this[e+--n]*r;return r*=128,a>=r&&(a-=Math.pow(2,8*t)),a},o.prototype.readInt8=function(e,t){return e>>>=0,t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||T(e,2,this.length);const i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},o.prototype.readInt16BE=function(e,t){e>>>=0,t||T(e,2,this.length);const i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(i<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+i)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||T(e,4,this.length),i.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||T(e,4,this.length),i.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||T(e,8,this.length),i.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||T(e,8,this.length),i.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,i,n){if(e=+e,t>>>=0,i>>>=0,!n){P(this,e,t,i,Math.pow(2,8*i)-1,0)}let r=1,a=0;for(this[t]=255&e;++a<i&&(r*=256);)this[t+a]=e/r&255;return t+i},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,i,n){if(e=+e,t>>>=0,i>>>=0,!n){P(this,e,t,i,Math.pow(2,8*i)-1,0)}let r=i-1,a=1;for(this[t+r]=255&e;--r>=0&&(a*=256);)this[t+r]=e/a&255;return t+i},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=Y((function(e,t=0){return x(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=Y((function(e,t=0){return L(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*i-1);P(this,e,t,i,n-1,-n)}let r=0,a=1,o=0;for(this[t]=255&e;++r<i&&(a*=256);)e<0&&0===o&&0!==this[t+r-1]&&(o=1),this[t+r]=(e/a|0)-o&255;return t+i},o.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*i-1);P(this,e,t,i,n-1,-n)}let r=i-1,a=1,o=0;for(this[t+r]=255&e;--r>=0&&(a*=256);)e<0&&0===o&&0!==this[t+r+1]&&(o=1),this[t+r]=(e/a|0)-o&255;return t+i},o.prototype.writeInt8=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=Y((function(e,t=0){return x(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=Y((function(e,t=0){return L(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,i){return M(this,e,t,!0,i)},o.prototype.writeFloatBE=function(e,t,i){return M(this,e,t,!1,i)},o.prototype.writeDoubleLE=function(e,t,i){return V(this,e,t,!0,i)},o.prototype.writeDoubleBE=function(e,t,i){return V(this,e,t,!1,i)},o.prototype.copy=function(e,t,i,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);const r=n-i;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,i,n):Uint8Array.prototype.set.call(e,this.subarray(i,n),t),r},o.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;let r;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(r=t;r<i;++r)this[r]=e;else{const a=o.isBuffer(e)?e:o.from(e,n),s=a.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(r=0;r<i-t;++r)this[r+t]=a[r%s]}return this};const K={};function j(e,t,i){K[e]=class extends i{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function H(e){let t="",i=e.length;const n="-"===e[0]?1:0;for(;i>=n+4;i-=3)t=`_${e.slice(i-3,i)}${t}`;return`${e.slice(0,i)}${t}`}function D(e,t,i,n,r,a){if(e>i||e<t){const i="bigint"==typeof t?"n":"";let n;throw n=0===t||t===BigInt(0)?`>= 0${i} and < 2${i} ** ${8*(a+1)}${i}`:`>= -(2${i} ** ${8*(a+1)-1}${i}) and < 2 ** ${8*(a+1)-1}${i}`,new K.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,i){$(t,"offset"),void 0!==e[t]&&void 0!==e[t+i]||F(t,e.length-(i+1))}(n,r,a)}function $(e,t){if("number"!=typeof e)throw new K.ERR_INVALID_ARG_TYPE(t,"number",e)}function F(e,t,i){if(Math.floor(e)!==e)throw $(e,i),new K.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new K.ERR_BUFFER_OUT_OF_BOUNDS;throw new K.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}j("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),j("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),j("ERR_OUT_OF_RANGE",(function(e,t,i){let n=`The value of "${e}" is out of range.`,r=i;return Number.isInteger(i)&&Math.abs(i)>2**32?r=H(String(i)):"bigint"==typeof i&&(r=String(i),(i>BigInt(2)**BigInt(32)||i<-(BigInt(2)**BigInt(32)))&&(r=H(r)),r+="n"),n+=` It must be ${t}. Received ${r}`,n}),RangeError);const q=/[^+/0-9A-Za-z-_]/g;function z(e,t){let i;t=t||1/0;const n=e.length;let r=null;const a=[];for(let o=0;o<n;++o){if(i=e.charCodeAt(o),i>55295&&i<57344){if(!r){if(i>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&a.push(239,191,189);continue}r=i;continue}if(i<56320){(t-=3)>-1&&a.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(t-=3)>-1&&a.push(239,191,189);if(r=null,i<128){if((t-=1)<0)break;a.push(i)}else if(i<2048){if((t-=2)<0)break;a.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;a.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;a.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return a}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function X(e,t,i,n){let r;for(r=0;r<n&&!(r+i>=t.length||r>=e.length);++r)t[r+i]=e[r];return r}function W(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function J(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let i=0;i<16;++i){const n=16*i;for(let r=0;r<16;++r)t[n+r]=e[i]+e[r]}return t}();function Y(e){return"undefined"==typeof BigInt?Z:e}function Z(){throw new Error("BigInt not supported")}}(R);const K="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),j=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function H(e=16,t=K){const i=new Uint16Array(e-1);b.getRandomValues(i);return`c${Array.from(i).map((e=>t[e%t.length])).join("")}`}async function D(e,t,i,n,r,a,o,s=86400){return{clientIP:e,userId:t??H(),match:i,mitigate:n,captcha:r,mitataMaxAge:s,netaceaSettings:o??{},issueReason:a}}const $={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass",monetise:"monetise"},F={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",redirectHost:"x-netacea-redirect-host",redirectLocation:"x-netacea-redirect-location",redirectStatus:"x-netacea-redirect-status"},q={0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},z={0:"",1:"blocked",2:"allow",3:"hardblocked",4:"flagged",5:"monetised"},G={0:"",1:"captcha_serve",2:"captcha_pass",3:"captcha_fail",4:"captcha_cookiepass",5:"captcha_cookiefail",6:"checkpoint_signal",7:"checkpoint_post",a:"checkpoint_serve",b:"checkpoint_pass",c:"checkpoint_fail",d:"checkpoint_cookiepass",e:"checkpoint_cookiefail"},X={"":0,captchaServe:1,captchaPass:2,captchaFail:3,captchaCookiePass:4,captchaCookieFail:5,checkpointSignal:6,checkpointPost:7,checkpointServe:"a",checkpointPass:"b",checkpointFail:"c",checkpointCookiePass:"d",checkpointCookieFail:"e"},W={0:$.none,1:$.block,2:$.none,3:$.block,4:$.block,5:$.monetise},J={1:$.captcha,2:$.captchaPass,3:$.captcha,4:$.allow,5:$.captcha,6:$.allow,7:$.captcha,a:$.captcha,b:$.captchaPass,c:$.captcha,d:$.allow,e:$.captcha},Q={checkAllPostRequests:"checkAllPostRequests"};var Y=Object.freeze({__proto__:null,COOKIEDELIMITER:"_/@#/",bestMitigationCaptchaMap:J,bestMitigationMap:W,captchaMap:G,captchaStatusCodes:X,get dictionary(){return Y},matchMap:q,mitigateMap:z,mitigationTypes:$,netaceaHeaders:F,netaceaSettingsMap:Q});class Z extends Error{static fromResponse(e){let t="Unknown error";switch(e.status){case 403:t="Invalid credentials";break;case 500:t="Server error";break;case 502:t="Bad Gateway";break;case 503:t="Service Unavailable";break;case 400:t="Invalid request"}return new Z(t)}}async function ee(e,t,i,n,r,a,s=o.NO_SESSION,c){if(200!==n.status)throw Z.fromResponse(n);let u=n.headers[F.match],h=n.headers[F.mitigate],f=n.headers[F.captcha];void 0===q[u]&&(u=i?.match??"0"),void 0===h&&(h=i?.mitigate??"0"),void 0===f&&(f=i?.captcha??"0");let p=parseInt(n.headers[F.mitataExpiry]);isNaN(p)&&(p=86400);const d=await D(a,r,u,h,f,s,c),l=await async function(e,t,i){if(Object.prototype.hasOwnProperty.call(i,F.mitataCaptcha)){const n=i[F.mitataCaptcha],r=parseInt(i[F.mitataCaptchaExpiry]),a=await async function(e,t,i,n,r,a="/"){const o=[t.netaceaCookieName,t.netaceaCaptchaCookieName];return void 0!==e.cachedEncryption&&o.includes(i)?`${i}=${await e.cachedEncryption.encrypt(n)}; Max-Age=${r}; Path=${a}`:`${i}=${n}; Max-Age=${r}; Path=${a}`}(e,t,t.netaceaCaptchaCookieName,n,r);if(void 0!==a)return a}}(e,t,n.headers),g=n.headers[F.eventId];return{status:n.status,match:u,mitigate:h,captcha:f,responseNetaceaCookie:d,responseNetaceaCaptchaCookie:l,body:n.body,eventId:g,mitataMaxAge:p,netaceaSettings:c??{},redirectHost:n.headers[F.redirectHost],redirectLocation:n.headers[F.redirectLocation],redirectStatus:n.headers[F.redirectStatus]}}class te{constructor(){this.queries={}}setQuery(e,t){return this.queries[e]=encodeURIComponent(t),this}removeQuery(e){const{[e]:t,...i}=this.queries;return this.queries=i,this}buildQueryString(){const e=Object.entries(this.queries).map((([e,t])=>`${e}=${t}`)).join("&");return e.length>0?`?${e}`:""}}function ie(e){const t=Object.entries(e.getHeaders()),i={};for(const[e,n]of t)i[e]=n[0];return i}async function ne(e,t,i){const{method:n,path:r,headers:a,body:o,timeout:s}=i;let{host:c}=i;c.endsWith("/")&&(c=c.slice(0,-1));const u=c+r,{httpRequest:h}=e,f=await h(u,{body:o,headers:a,method:n,timeout:s??3e3});return{status:f.status,body:await f.text(),headers:ie(f)}}function re(e){return Object.entries(e).filter((([,e])=>void 0!==e)).map((e=>e.join("="))).join("; ")}function ae(e){const t=e?.toLowerCase()??"text/html",i=t?.includes("text/html")||t?.includes("application/html"),n=t?.includes("application/json");return n&&!i?"application/json":"text/html"}function oe(e,t,i){let n;if(void 0===e||""===e)return"";if("string"==typeof e&&(n=JSON.parse(e)),!function(e){if(null==e)return!1;const t=e;return void 0!==t?.captchaSiteKey&&void 0!==t?.trackingId&&void 0!==t?.captchaURL}(n))throw new Error("Body is not a Mitigation Service JSON response!");const r=`${i}?trackingId=${n.trackingId}`,a=`https://${t}${r}`;return JSON.stringify({captchaRelativeURL:r,captchaAbsoluteURL:a})}var se,ce={},ue={},he={},fe={};Object.defineProperty(fe,"__esModule",{value:!0}),fe.NetaceaCookieV3IssueReason=void 0,function(e){e.CAPTCHA_GET="captcha_get",e.CAPTCHA_POST="captcha_post",e.EXPIRED_SESSION="expired_session",e.FORCED_REVALIDATION="forced_revalidation",e.INVALID_SESSION="invalid_session",e.IP_CHANGE="ip_change",e.NO_SESSION="no_session"}(se||(fe.NetaceaCookieV3IssueReason=se={}));var pe={};Object.defineProperty(pe,"__esModule",{value:!0}),pe.netaceaCookieV3OptionalKeyMap=pe.netaceaCookieV3KeyMap=pe.COOKIEDELIMITER=void 0,pe.COOKIEDELIMITER="_/@#/",pe.netaceaCookieV3KeyMap={clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},pe.netaceaCookieV3OptionalKeyMap={checkAllPostRequests:"fCAPR"},Object.defineProperty(he,"__esModule",{value:!0}),he.defaultInvalidResponse=he.matchNetaceaCookieV3=he.checkNetaceaCookieV3=he.objectIsNetaceaCookieV3=he.cookieIsNetaceaV3Format=he.createNetaceaCookieV3=void 0;const de=fe,le=pe;function ge(e){if(void 0===e||""===e)return;const t=e.split("&"),i={clientIP:"",userId:"",cookieId:"",gracePeriod:0,match:"0",mitigate:"0",captcha:"0",issueTimestamp:0,issueReason:"",checkAllPostRequests:void 0};for(const e of t){const[t,n]=e.split("="),r=decodeURIComponent(n);let a,o=Object.keys(le.netaceaCookieV3KeyMap).find((e=>le.netaceaCookieV3KeyMap[e]===t));void 0===o&&(o=Object.keys(le.netaceaCookieV3OptionalKeyMap).find((e=>le.netaceaCookieV3OptionalKeyMap[e]===t))),a=void 0!==o&&["match","mitigate","captcha"].includes(o)?""===r?void 0:r:""===r?void 0:Number(r),void 0!==a&&"string"!=typeof a&&isNaN(a)&&(a=r),i[o]=a}return i}function ye(){return{mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0",issueReason:de.NetaceaCookieV3IssueReason.NO_SESSION}}he.createNetaceaCookieV3=function(e){return Object.entries(e).filter((([e,t])=>void 0!==t)).map((([e,t])=>e in le.netaceaCookieV3OptionalKeyMap?`${le.netaceaCookieV3OptionalKeyMap[e]}=${encodeURIComponent(t)}`:`${le.netaceaCookieV3KeyMap[e]}=${encodeURIComponent(t)}`)).join("&")},he.cookieIsNetaceaV3Format=function(e){if(void 0===e||""===e)return!1;const t=e.split("&").map((e=>e.split("=")[0])).filter((e=>!Object.values(le.netaceaCookieV3OptionalKeyMap).includes(e)));return 0!==t.length&&t.every((e=>Object.values(le.netaceaCookieV3KeyMap).includes(e)))},he.objectIsNetaceaCookieV3=function(e){if("object"!=typeof e||null===e)return!1;for(const t of Object.keys(le.netaceaCookieV3KeyMap)){if(!(t in e))return!1;if(void 0===e[t])return!1}return!0},he.checkNetaceaCookieV3=function(e,t){if(void 0===e||""===e)return ye();let i;try{i=ge(e)}catch{return ye()}if(void 0!==i){const e=Math.floor(Date.now()/1e3),n=i.issueTimestamp+i.gracePeriod<e,r=t===i.clientIP,a=["1","3","5","a","c","e"].includes(i.captcha),o="3"===i.mitigate;return{mitata:i,requiresReissue:n||!r,isExpired:n,shouldExpire:a||o,isSameIP:r,isPrimaryHashValid:!0,match:i.match,mitigate:i.mitigate,captcha:i.captcha,issueReason:i.issueReason}}return ye()},he.matchNetaceaCookieV3=ge,he.defaultInvalidResponse=ye;var me={};Object.defineProperty(me,"__esModule",{value:!0}),me.AbstractCookieFactory=void 0;const Se=fe,Ie=he,we=pe,ve="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),Ce=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;me.AbstractCookieFactory=class{constructor(e){this.config=e}isEncrypted(e){return 5===e.split(".").length}async createCookieValue(e){if(void 0!==this.config.cookieEncryptionKey){const t=(0,Ie.createNetaceaCookieV3)({clientIP:e.clientIP,userId:e.userId??"",match:e.match,mitigate:e.mitigate,captcha:e.captcha,gracePeriod:e.gracePeriod,cookieId:e.cookieId,issueTimestamp:Math.floor(Date.now()/1e3),issueReason:e.issueReason??Se.NetaceaCookieV3IssueReason.NO_SESSION,checkAllPostRequests:e.checkAllPostRequests});return await this.encrypt(t)}if(void 0===this.config.secretKey)throw new Error("Cannot build cookie without secret key.");const t=[e.match,e.mitigate,e.captcha].join(""),i=Math.floor(Date.now()/1e3)+e.gracePeriod;return await this.buildMitataCookie(e.clientIP,e.userId,i,this.config.secretKey,t)}async retrieveCookieInfo(e,t){if(void 0===e||""===e)return(0,Ie.defaultInvalidResponse)();let i=e;return this.isEncrypted(e)&&(i=await this.decrypt(e)),(0,Ie.cookieIsNetaceaV3Format)(i)?(0,Ie.checkNetaceaCookieV3)(i,t):await this.checkMitataCookie(i,t,this.config.secretKey??"")}async buildMitataCookie(e,t,i,n,r){const a=[i,t??this.generateUserId(),await this.hash(`${e}|${String(i)}`,n),r].join(we.COOKIEDELIMITER);return`${await this.hash(a,n)}${we.COOKIEDELIMITER}${a}`}async checkMitataCookie(e,t,i){const n=function(e){const t=e.match(Ce);if(null===t)return;const[,i,n,r,a,o,s,c,u]=t;return{signature:i,expiry:n,userId:r,ipHash:a,mitigationType:o,match:s,mitigate:c,captcha:u}}(e);if(void 0===n)return(0,Ie.defaultInvalidResponse)();const r=Math.floor(Date.now()/1e3),a=parseInt(n.expiry)<r,o=["1","3","5"].includes(n.captcha),s="3"===n.mitigate,c=o||s,u=await this.hash(`${t}|${n.expiry}`,i)===n.ipHash,h=[n.expiry,n.userId,n.ipHash,n.mitigationType].join(we.COOKIEDELIMITER);return{mitata:n,requiresReissue:a||!u,isExpired:a,shouldExpire:c,isSameIP:u,isPrimaryHashValid:await this.hash(h,i)===n.signature,match:n.match,mitigate:n.mitigate,captcha:n.captcha,issueReason:Se.NetaceaCookieV3IssueReason.NO_SESSION}}generateUserId(e=16){const t=new Uint16Array(e-1);this.getRandomValues(t);return`c${Array.from(t).map((e=>ve[e%ve.length])).join("")}`}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.NetaceaCookieV3IssueReason=e.COOKIEDELIMITER=e.netaceaCookieV3OptionalKeyMap=e.netaceaCookieV3KeyMap=e.AbstractCookieFactory=e.defaultInvalidResponse=e.objectIsNetaceaCookieV3=e.cookieIsNetaceaV3Format=e.matchNetaceaCookieV3=e.checkNetaceaCookieV3=e.createNetaceaCookieV3=void 0;var t=he;Object.defineProperty(e,"createNetaceaCookieV3",{enumerable:!0,get:function(){return t.createNetaceaCookieV3}}),Object.defineProperty(e,"checkNetaceaCookieV3",{enumerable:!0,get:function(){return t.checkNetaceaCookieV3}}),Object.defineProperty(e,"matchNetaceaCookieV3",{enumerable:!0,get:function(){return t.matchNetaceaCookieV3}}),Object.defineProperty(e,"cookieIsNetaceaV3Format",{enumerable:!0,get:function(){return t.cookieIsNetaceaV3Format}}),Object.defineProperty(e,"objectIsNetaceaCookieV3",{enumerable:!0,get:function(){return t.objectIsNetaceaCookieV3}}),Object.defineProperty(e,"defaultInvalidResponse",{enumerable:!0,get:function(){return t.defaultInvalidResponse}});var i=me;Object.defineProperty(e,"AbstractCookieFactory",{enumerable:!0,get:function(){return i.AbstractCookieFactory}});var n=pe;Object.defineProperty(e,"netaceaCookieV3KeyMap",{enumerable:!0,get:function(){return n.netaceaCookieV3KeyMap}}),Object.defineProperty(e,"netaceaCookieV3OptionalKeyMap",{enumerable:!0,get:function(){return n.netaceaCookieV3OptionalKeyMap}}),Object.defineProperty(e,"COOKIEDELIMITER",{enumerable:!0,get:function(){return n.COOKIEDELIMITER}});var r=fe;Object.defineProperty(e,"NetaceaCookieV3IssueReason",{enumerable:!0,get:function(){return r.NetaceaCookieV3IssueReason}})}(ue);var Ee={};Object.defineProperty(Ee,"__esModule",{value:!0}),Ee.validateRedirectLocation=void 0,Ee.validateRedirectLocation=function(e){if(""!==(e=e??""))try{return new URL(e).toString()}catch{if(/^https?:\/\//i.test(e))return;return e.startsWith("/")?e:`/${e}`}};var be={},ke={};function Ae(e,t){for(const i of Object.keys(e)){if("cookie"!==i&&"Cookie"!==i)continue;const n=e[i]??"",r=_e("string"==typeof n?n:n.join("; "),t);if(void 0!==r)return r}}function Ne(e,t){const i=[];for(const n of Object.keys(e)){if("cookie"!==n&&"Cookie"!==n)continue;const r=e[n]??"",a="string"==typeof r?r:r.join("; ");i.push(...Re(a,t))}return i}function _e(e,t){const i=t+"=";return e.split(";").map((e=>e.trimStart())).find((e=>e.startsWith(i)))}function Re(e,t){const i=t+"=";return e.split(";").map((e=>e.trimStart())).filter((e=>e.startsWith(i)))}Object.defineProperty(ke,"__esModule",{value:!0}),ke.findAllInCookieString=ke.findFirstInCookieString=ke.findAllInHeaders=ke.findFirstInHeaders=ke.findOnlyValueInHeaders=ke.findAllValuesInHeaders=ke.findFirstValueInHeaders=void 0,ke.findFirstValueInHeaders=function(e,t){const i=Ae(e,t);if(void 0!==i)return i.slice(t.length+1)},ke.findAllValuesInHeaders=function(e,t){return Ne(e,t).map((e=>e.slice(t.length+1)))},ke.findOnlyValueInHeaders=function(e,t){const i=Ne(e,t);if(i.length>1)throw new Error(`Found more than one cookie with name ${t}`);return i[0]?.slice(t.length+1)},ke.findFirstInHeaders=Ae,ke.findAllInHeaders=Ne,ke.findFirstInCookieString=_e,ke.findAllInCookieString=Re;var Oe={};function Te(e){return"set-cookie"===e||"Set-Cookie"===e}function Pe(e,t){const i=t+"=";return e.startsWith(i)}function xe(e,t){if(!Pe(e,t))throw new Error(`Cookie '${t}' not found in '${e}'`);return e.slice(t.length+1).split(";")[0]}function Le(e,t){const i=e[t]??[];return"string"==typeof i?[i]:i}function Be(e,t){for(const i of Object.keys(e)){if(!Te(i))continue;const n=Me(Le(e,i),t);if(void 0!==n)return n}}function Me(e,t){return e.map((e=>e.trimStart())).find((e=>Pe(e,t)))}function Ve(e,t){const i=[];for(const n of Object.keys(e)){if(!Te(n))continue;const r=Le(e,n);i.push(...Ue(r,t))}return i}function Ue(e,t){return e.map((e=>e.trimStart())).filter((e=>Pe(e,t)))}Object.defineProperty(Oe,"__esModule",{value:!0}),Oe.findAllInSetCookieStrings=Oe.findAllInHeaders=Oe.findValueInSetCookieStrings=Oe.findFirstInSetCookieStrings=Oe.findFirstInHeaders=Oe.findOnlyValueInHeaders=Oe.findFirstValueInHeaders=Oe.parseValueFromString=void 0,Oe.parseValueFromString=xe,Oe.findFirstValueInHeaders=function(e,t){const i=Be(e,t);return void 0!==i?xe(i,t):void 0},Oe.findOnlyValueInHeaders=function(e,t){const i=Ve(e,t);if(i.length>1)throw new Error(`Found more than one set-cookie with name ${t}`);return void 0!==i[0]?xe(i[0],t):void 0},Oe.findFirstInHeaders=Be,Oe.findFirstInSetCookieStrings=Me,Oe.findValueInSetCookieStrings=function(e,t){const i=Me(e,t);if(void 0!==i)return xe(i,t)},Oe.findAllInHeaders=Ve,Oe.findAllInSetCookieStrings=Ue;var Ke=_&&_.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,r)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),je=_&&_.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),He=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&Ke(t,e,i);return je(t,e),t};Object.defineProperty(be,"__esModule",{value:!0}),be.setCookie=be.cookie=void 0,be.cookie=He(ke),be.setCookie=He(Oe);var De={},$e={},Fe={};Object.defineProperty(Fe,"__esModule",{value:!0}),Fe.KINESIS_URL=Fe.API_VERSION=Fe.REGION=Fe.PAYLOAD_TYPE=Fe.STATE=void 0,Fe.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},Fe.PAYLOAD_TYPE="string",Fe.REGION="eu-west-1",Fe.API_VERSION="2013-12-02",Fe.KINESIS_URL="https://kinesis.eu-west-1.amazonaws.com";var qe={};Object.defineProperty(qe,"__esModule",{value:!0}),qe.headersToRecord=qe.increaseBatchSize=qe.handleFailedLogs=qe.batchArrayForKinesis=qe.sleep=void 0,qe.sleep=async function(e){await new Promise((t=>{setTimeout(t,e)}))},qe.batchArrayForKinesis=function(e,t,i){const n=[];for(let r=0;r<e.length;r+=t){const a=e.slice(r,r+t);n.push({Data:i.from(JSON.stringify(a)).toString("base64"),PartitionKey:Date.now().toString()})}return n},qe.handleFailedLogs=function(e,t,i){const n=2*i,r=[...e,...t],a=r.length-n;return a>0&&(console.error(`Netacea Error :: failed to send ${a} log(s) to Kinesis ingest.`),r.splice(0,a)),r},qe.increaseBatchSize=function(e,t){return e!==t?Math.min(t,2*e):e},qe.headersToRecord=function(e){const t={};return e.forEach(((e,i)=>{t[i]=e})),t},Object.defineProperty($e,"__esModule",{value:!0}),$e.WebStandardKinesis=void 0;const ze=Fe,Ge=qe;$e.WebStandardKinesis=class{constructor({deps:e,kinesisIngestArgs:t}){if(this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.deps=e,void 0===t.kinesisAccessKey)throw new Error("kinesisAccessKey is required for kinesis ingest");if(void 0===t.kinesisSecretKey)throw new Error("kinesisSecretKey is required for kinesis ingest");this.kinesisStreamName=t.kinesisStreamName,this.kinesisAccessKey=t.kinesisAccessKey,this.kinesisSecretKey=t.kinesisSecretKey,this.maxAwaitTimePerIngestCallMs=t.maxAwaitTimePerIngestCallMs,void 0!==t.maxLogAgeSeconds&&t.maxLogAgeSeconds<this.maxLogAgeSeconds&&t.maxLogAgeSeconds>0&&(this.maxLogAgeSeconds=t.maxLogAgeSeconds),void 0!==t.logBatchSize&&(this.maxLogBatchSize=t.logBatchSize),this.logBatchSize=!0===t.rampUpBatchSize?1:this.maxLogBatchSize}async putToKinesis(){if(0===this.logCache.length)return;const e=[...this.logCache];this.logCache=[];try{const t=new this.deps.AwsClient({accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey}),i=await this.signRequest(t,{streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},e,this.logBatchSize);await this.deps.makeRequest({headers:(0,Ge.headersToRecord)(i.headers),host:ze.KINESIS_URL,method:"POST",path:"/",body:i.body}),this.logBatchSize=(0,Ge.increaseBatchSize)(this.logBatchSize,this.maxLogBatchSize)}catch(t){this.logCache=(0,Ge.handleFailedLogs)(this.logCache,e,this.maxLogBatchSize)}}async ingest(e){if(this.logCache.push(e),this.logCache.length>=this.logBatchSize){const e=[];e.push(this.putToKinesis()),void 0!==this.maxAwaitTimePerIngestCallMs&&e.push((0,Ge.sleep)(this.maxAwaitTimePerIngestCallMs)),await Promise.race(e)}else if(!this.intervalSet){this.intervalSet=!0;const e=(0,Ge.sleep)(1e3*this.maxLogAgeSeconds).then((async()=>{await this.putToKinesis(),this.intervalSet=!1})).catch((()=>{}));void 0===this.maxAwaitTimePerIngestCallMs&&await e}}async signRequest(e,t,i,n){const r={Records:(0,Ge.batchArrayForKinesis)(i,n,this.deps.Buffer),PartitionKey:Date.now().toString(),StreamName:t.streamName};return await e.sign(ze.KINESIS_URL,{body:JSON.stringify(r),method:"POST",headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"}})}};var Xe={};Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.Kinesis=void 0;const We=Fe,Je=qe;Xe.Kinesis=class{constructor({deps:e,kinesisIngestArgs:t}){this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.deps=e,this.kinesisStreamName=t.kinesisStreamName,this.kinesisAccessKey=t.kinesisAccessKey,this.kinesisSecretKey=t.kinesisSecretKey,this.maxAwaitTimePerIngestCallMs=t.maxAwaitTimePerIngestCallMs,void 0!==t.maxLogAgeSeconds&&t.maxLogAgeSeconds<this.maxLogAgeSeconds&&t.maxLogAgeSeconds>0&&(this.maxLogAgeSeconds=t.maxLogAgeSeconds),void 0!==t.logBatchSize&&(this.maxLogBatchSize=t.logBatchSize),this.logBatchSize=!0===t.rampUpBatchSize?1:this.maxLogBatchSize}async putToKinesis(){if(0===this.logCache.length)return;const e=[...this.logCache];this.logCache=[];try{const t=this.signRequest({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},e,this.logBatchSize);if("POST"!==t.method)throw new Error(`Unexpected method. Expected POST but got ${t.method}`);await this.deps.makeRequest({headers:t.headers??{},host:`https://${t.hostname}`,method:t.method,path:t.path??"/",body:t.body}),this.logBatchSize=(0,Je.increaseBatchSize)(this.logBatchSize,this.maxLogBatchSize)}catch(t){this.logCache=(0,Je.handleFailedLogs)(this.logCache,e,this.maxLogBatchSize)}}async ingest(e){if(this.logCache.push(e),this.logCache.length>=this.logBatchSize){const e=[];e.push(this.putToKinesis()),void 0!==this.maxAwaitTimePerIngestCallMs&&e.push((0,Je.sleep)(this.maxAwaitTimePerIngestCallMs)),await Promise.race(e)}else if(!this.intervalSet){this.intervalSet=!0;const e=(0,Je.sleep)(1e3*this.maxLogAgeSeconds).then((async()=>{await this.putToKinesis(),this.intervalSet=!1})).catch((()=>{}));void 0===this.maxAwaitTimePerIngestCallMs&&await e}}signRequest(e,t,i){const{accessKeyId:n,secretAccessKey:r}=e,a={Records:(0,Je.batchArrayForKinesis)(t,i,this.deps.Buffer),PartitionKey:Date.now().toString(),StreamName:e.streamName};return this.deps.aws4.sign({service:"kinesis",body:JSON.stringify(a),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:We.REGION},{accessKeyId:n,secretAccessKey:r})}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Kinesis=e.WebStandardKinesis=void 0;var t=$e;Object.defineProperty(e,"WebStandardKinesis",{enumerable:!0,get:function(){return t.WebStandardKinesis}});var i=Xe;Object.defineProperty(e,"Kinesis",{enumerable:!0,get:function(){return i.Kinesis}})}(De);var Qe={};function Ye(e,t){let i=null;if("number"==typeof e)i=e;else if("string"==typeof e){const t=parseFloat(e);isNaN(t)||(i=t)}if(null===i){if("number"!=typeof t.defaultValue)return t.defaultValue;i=t.defaultValue}return void 0!==t.minValue&&(i=Math.max(t.minValue,i)),void 0!==t.maxValue&&(i=Math.min(t.maxValue,i)),i}Object.defineProperty(Qe,"__esModule",{value:!0}),Qe.parseHttpHeaderName=Qe.stringOrDefault=Qe.parseIntOrDefault=Qe.parseNumberOrDefault=void 0,Qe.parseNumberOrDefault=Ye,Qe.parseIntOrDefault=function(e,t){const i=Ye(e,t);return"number"==typeof i?Math.floor(i):i},Qe.stringOrDefault=function(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t},Qe.parseHttpHeaderName=function(e){if("string"!=typeof e)return;return/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(e)?e:void 0};var Ze={};Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.searchParamsFromRecord=void 0,Ze.searchParamsFromRecord=function(e){const t=new URLSearchParams;for(const[i,n]of Object.entries(e))t.append(i,n);return t};var et={},tt={};Object.defineProperty(tt,"__esModule",{value:!0}),tt.JweFactory=void 0;tt.JweFactory=class{constructor(e){this.jose=e}async encrypt(e,t,i="A128CBC-HS256"){const n=this.jose.base64url.decode(t),r=(new TextEncoder).encode(e);return await new this.jose.CompactEncrypt(r).setProtectedHeader({alg:"dir",enc:i}).encrypt(n)}async decrypt(e,t){const i=this.jose.base64url.decode(t),{plaintext:n}=await this.jose.compactDecrypt(e,i,{keyManagementAlgorithms:["dir"],contentEncryptionAlgorithms:["A256GCM","A128CBC-HS256"]});return(new TextDecoder).decode(n)}static isJweEncrypted(e){return 5===e.split(".").length&&e.includes("..")}};var it=_&&_.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,r)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),nt=_&&_.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),rt=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&it(t,e,i);return nt(t,e),t};Object.defineProperty(et,"__esModule",{value:!0}),et.jwe=void 0,et.jwe=rt(tt);var at,ot={};var st={};Object.defineProperty(st,"__esModule",{value:!0}),st.ProtectorApiResponseView=st.AbstractProtectorApiResponseView=void 0;const ct=Qe;class ut{get redirectHost(){return this.readHeader("x-netacea-redirect-host")?.[0]}get redirectLocation(){return this.readHeader("x-netacea-redirect-location")?.[0]}get redirectStatus(){return this.readHeader("x-netacea-redirect-status")?.[0]}get redirectStatusCode(){const e=this.readHeader("x-netacea-redirect-status")?.[0];if(void 0===e)return;const t=(0,ct.parseIntOrDefault)(e,{defaultValue:0,minValue:0,maxValue:Number.MAX_SAFE_INTEGER});return t>=300&&t<400?t:void 0}get eventId(){return this.readHeader("x-netacea-event-id")?.[0]}get sessionCookieMaxAge(){return(0,ct.parseIntOrDefault)(this.readHeader("x-netacea-mitata-expiry")?.[0],{defaultValue:86400,minValue:0,maxValue:Number.MAX_SAFE_INTEGER})}get captchaCookieMaxAge(){const e=this.readHeader("x-netacea-mitatacaptcha-expiry")?.[0];return(0,ct.parseIntOrDefault)(e,{defaultValue:86400,minValue:0,maxValue:Number.MAX_SAFE_INTEGER})}getProtectorCodes(e){return{match:this.readHeader("x-netacea-match")?.[0]??e?.match??"0",mitigate:this.readHeader("x-netacea-mitigate")?.[0]??e?.mitigate??"0",captcha:this.readHeader("x-netacea-captcha")?.[0]??e?.captcha??"0"}}getMonetisationRedirectLocation(e,t){const i=this.redirectLocation;if(void 0!==i)return i;const n=this.redirectHost;if(void 0!==n){const i=new URL(`https://${n}`);return i.pathname=e,i.search=t,i.toString()}}getMonetisationRedirect(e,t){const i=this.getMonetisationRedirectLocation(e,t);if(void 0!==i)return{location:i,statusCode:this.redirectStatusCode??303}}async getCaptchaJson(e,t){const i=await this.getBody();let n=this.eventId;if(void 0===n&&"string"==typeof i){n=function(e){if(null==e||"object"!=typeof e)throw new Error("Response body is not a valid object!");const{trackingId:t}=e;if("string"!=typeof t||0===t.length)throw new Error("Response body does not contain a valid trackingId!");return t}(JSON.parse(i))}if(void 0===n)throw new Error("Could not resolve Tracking ID for captcha event.");return function(e,t,i){const n=`${e}?trackingId=${i}`,r=void 0!==t?`https://${t}${n}`:void 0;return JSON.stringify({captchaRelativeURL:n,captchaAbsoluteURL:r})}(e,t,n)}}st.AbstractProtectorApiResponseView=ut;var ht;function ft(){return ht||(ht=1,function(e){var t=_&&_.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,r)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),i=_&&_.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&t(n,e,r);return i(n,e),n},r=_&&_.__exportStar||function(e,i){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(i,n)||t(i,e,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.graphql=e.webcrypto=e.url=e.parsing=e.ingest=e.headers=e.configValidation=e.cookie=void 0,e.cookie=n(ue),e.configValidation=n(Ee),e.headers=n(be),e.ingest=n(De),e.parsing=n(Qe),e.url=n(Ze),e.webcrypto=n(et),e.graphql=n(function(){if(at)return ot;at=1,Object.defineProperty(ot,"__esModule",{value:!0}),ot.truncateLongFields=ot.parseGraphQl=ot.parseGraphQlRequestBody=ot.getGraphQLParserConfig=void 0;const e=ft();function t(e,t){const i=e.parserRegex;return t.match(i)?.groups??{}}function i(e,t){const i=e.maxValueLength;for(const e of Object.keys(t)){const a=t[e];t[e]=(r=i,(n=a).length<=r?n:n.slice(0,r)+"…")}var n,r;return t}return ot.getGraphQLParserConfig=function(t){const i={includePaths:[],maxParsableBytes:e.parsing.parseIntOrDefault(t?.maxParsableBytes,{defaultValue:1e6,minValue:1e3}),maxValueLength:e.parsing.parseIntOrDefault(t?.maxValueLength,{defaultValue:256,minValue:8}),parserRegex:/^\s*(?<OpType>query|mutation|subscription)\s+(?<OpName>[_A-Za-z][_0-9A-Za-z]+)?/};if(Array.isArray(t?.includePaths))for(const e of t.includePaths)"string"==typeof e&&i.includePaths.push(e);try{if(t?.parserRegex instanceof RegExp)i.parserRegex=t?.parserRegex;else if("object"==typeof t?.parserRegex){const{regex:e,flags:n}=t?.parserRegex;"string"==typeof e&&(i.parserRegex=new RegExp(e,n))}}catch{}return i},ot.parseGraphQlRequestBody=function(e,n){if(""===n)throw new Error("Netacea Error: Empty GraphQL body received");const r=JSON.parse(n);if("object"!=typeof r)throw new Error("Netacea Error: Invalid GraphQL JSON");const a={...t(e,r?.query??"")},o=(r?.operationName??"").trim();return""!==o&&(a.OpName=o),i(e,a)},ot.parseGraphQl=t,ot.truncateLongFields=i,ot}()),r(st,e)}(ce)),ce}st.ProtectorApiResponseView=class extends ut{constructor(e){super(),this.response=e}get status(){return this.response.status}async getBody(){return void 0===this._body&&(this._body=await this.response.clone().text()??""),this._body}readHeader(e){if("set-cookie"===(e=e.toLowerCase()))return this.response.headers.getSetCookie();const t=this.response.headers.get(e)??void 0;return void 0!==t?[t]:[]}};var pt=ft();function dt(e){const t={},{netaceaSettingsMap:i}=Y;return decodeURIComponent(e).split("&").map((e=>e.split("="))).forEach((([e,n])=>{if(void 0!==n&&e in i){const r=parseInt(n,10);t[i[e]]=isNaN(r)?void 0:r}})),Object.entries(t).reduce(((e,[t,i])=>(void 0!==i&&(e[t]=i),e)),{})}function lt(e){const t={};if(pt.cookie.objectIsNetaceaCookieV3(e)){const{netaceaSettingsMap:i}=Y;for(const n in i){const r=e[i[n]];void 0!==r&&(t[n]=r)}}return t}async function gt(e,t,i,n,r){const a=new te,s=[];for(const e in Q)void 0===i[e]&&s.push(e);return s.length>0&&a.setQuery("getSettings",s.join(",")),void 0!==n.trackingId&&a.setQuery("trackingId",n.trackingId),a.setQuery("netaceaHeaders","User-Agent, Request-ID"),await async function(e,t,i,n,r,a,o,s){const{userId:c,clientIP:u,host:h}=i,{mitigationServiceUrl:f,timeout:p}=t;if(void 0===f)throw new Error("Mitigation Service URL is not defined!");const d=function(e,t){const{apiKey:i,userId:n,userAgent:r,captchaCookie:a,clientIP:o,captchaSiteKey:s,captchaSecretKey:c,accept:u,requestId:h}=t,f={"X-Netacea-API-Key":i,"X-Netacea-Client-IP":o,"X-Netacea-User-Agent":R.Buffer.from(r).toString("base64"),cookie:re({_mitatacaptcha:a}),"X-Netacea-Request-Id":h};void 0!==n&&(f["X-Netacea-UserId"]=n);void 0!==s&&void 0!==c&&(f["X-Netacea-Captcha-Site-Key"]=s,f["X-Netacea-Captcha-Secret-Key"]=c);e.captchaContentNegotiation&&void 0!==e.netaceaCaptchaPath&&(f["X-Netacea-Captcha-Content-Type"]=ae(u));return f}(t,i),l="application/json"===d["X-Netacea-Captcha-Content-Type"],g={host:f,path:n,headers:d,method:r,timeout:p},y=await ne(e,0,g);l&&void 0!==t.netaceaCaptchaPath&&void 0!==h&&(y.body=oe(y.body,h,t.netaceaCaptchaPath));let m={};void 0!==y.headers["x-netacea-settings"]&&(m=dt(y.headers["x-netacea-settings"]));return await ee(e,t,s,y,c,u,a,{...o,...m})}(e,t,n,`/captcha${a.buildQueryString()}`,"GET",o.CAPTCHA_GET,i,r)}async function yt(e,t,i,n){i=mt(i);const r=`${n}=`;for(const o of i){const i=o.split(";")[0].trimStart();if(i.startsWith(r)){const o=i.slice(r.length);if(t.encryptedCookieNames.includes(n)&&(5===(a=o).split(".").length&&a.includes("..")))try{return await(e.cachedEncryption?.decrypt(o))}catch(e){return}return o}}var a}function mt(e){return null==e?[]:"string"==typeof e?e.split(";"):e}function St(e,t,i=""){const n=e.getHeader(t)?.[0]?.trim();return n??i}function It(e,t,i=""){return e.getVariable(t)??i}async function wt(e,t,i){return await e.cookieFactory.retrieveCookieInfo(t,i)}function vt(e,t){const i=e.split("&");for(const e of i){const[i,n]=e.split("=");if(i===t)return n}}function Ct(e,t,i){const{netaceaBlockedResponseStatus:n,netaceaCaptchaResponseStatus:r}=e;let a;return a=Number("block"===t?n:r),(o=a)>=200&&o<600&&!Number.isNaN(o)&&3===o.toString().length?a:i;var o}function Et(e,t){const i=t.getVariable(e.protoMitataVariableName);if(void 0!==i&&""!==i)try{return JSON.parse(i)}catch{return}}async function bt(e,t,i,n){const r=C(i.path,i.method)?function(e,t){const i=e.getHeader("x-netacea-client-ip")?.[0];if(null==i||""===i)throw new Error("Cannot build proto-mitata without Client IP");const n=e.getHeader("x-netacea-userid")?.[0]??"";let r={};const a=e.getHeader("x-netacea-settings")?.[0];return void 0!==a&&(r=JSON.parse(a)),{clientIP:i,userId:""!==n?n:H(),match:t.getHeader("x-netacea-match")?.[0]??"0",mitigate:t.getHeader("x-netacea-mitigate")?.[0]??"0",captcha:t.getHeader("x-netacea-captcha")?.[0]??"0",mitataMaxAge:(s="x-netacea-mitata-expiry",c=86400,Number(t.getHeader(s)?.[0]??c)),netaceaSettings:r,issueReason:o.CAPTCHA_POST};var s,c}(i,n):Et(t,i);if(void 0!==r){const i=t.netaceaCookieName??"_mitata",a=await async function(e,t,{clientIP:i,userId:n,match:r,mitigate:a,captcha:s,netaceaSettings:c,issueReason:u}){const h=t.netaceaCookieExpirySeconds,f=["1","3","5"].includes(s)||"3"===a||"5"===a?-60:h;return await e.cookieFactory.createCookieValue({clientIP:i,userId:n,match:r,mitigate:a,captcha:s,gracePeriod:f,cookieId:H(),issueReason:u??o.NO_SESSION,checkAllPostRequests:c.checkAllPostRequests})}(e,t,{clientIP:r.clientIP,userId:r.userId,match:r.match,mitigate:r.mitigate,captcha:r.captcha,netaceaSettings:r.netaceaSettings,issueReason:r.issueReason??o.NO_SESSION}),s=p.cookie.netaceaSession.createNetaceaSetCookieString({cookieName:i,cookieValue:a,otherAttributes:t.netaceaCookieAttributes});n.addHeader("set-cookie",s)}}async function kt(e,t,i,n){const r=n.getHeader("set-cookie")??void 0;if(n.removeHeader("set-cookie"),200===n.status){const a=F.captcha,o=n.getHeader(a)?.[0]??"";String(o)!==String(X.checkpointPost)&&(await bt(e,t,i,n),await async function(e,t,i,n){const r=n?.find((e=>e.startsWith("_mitatacaptcha=")))?.split(/; ?/)[0];if(void 0===r)return;const a=t.netaceaCaptchaCookieName??"_mitatacaptcha",o=r.indexOf("=");if(o>=0){let n=r.slice(o+1);const s=t.encryptedCookieNames.includes(a);void 0!==e.cachedEncryption&&s&&(n=await e.cachedEncryption.encrypt(n));const c=p.cookie.netaceaSession.createNetaceaCaptchaSetCookieString({cookieName:a,cookieValue:n,otherAttributes:t.netaceaCaptchaCookieAttributes});i.addHeader("set-cookie",c)}}(e,t,n,r)),o===String(X.checkpointPost)?n.status=202:function(e){const t=String(X.captchaPass),i=String(X.checkpointPass);return![t,i].includes(e)}(o)&&(n.status=403)}}function At(e){return R.Buffer.from(e.replace(/-/g,"+").replace(/_/g,"/"),"base64")}function Nt(e,t){if("string"==typeof e&&void 0===t)throw new Error("Encoding should be provided to convert strings.");return function(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}(("string"==typeof e?R.Buffer.from(e,t):R.Buffer.from(e)).toString("base64"))}const _t=128,Rt=Nt(JSON.stringify({alg:"dir",enc:"A128CBC-HS256"}),"utf-8"),Ot=(new k).encode(Rt);async function Tt(e){return await b.subtle.importKey("raw",e,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async function Pt({plaintext:e,secret:t,ivBase64Url:i}){const n=At(t),r=n.subarray(16),a=n.subarray(0,16),o=await Tt(r),s=void 0!==i?At(i):function(){const e=new Uint8Array(16);return b.getRandomValues(e),e}(),c=(new k).encode(e),u=await async function(e,t,i){const n=await b.subtle.encrypt({name:"AES-CBC",length:_t,iv:e},t,i);return new Uint8Array(n)}(s,o,c),h=new Uint8Array(s),f=Bt(Ot,h,u),p=await Lt(f,a);return[Rt,"",Nt(s),Nt(u),Nt(p)].join(".")}async function xt({jwe:e,secret:t}){const i=At(t),n=i.subarray(16),r=i.subarray(0,16),{header:a,iv:o,payload:s,mac:c}=function(e){const t=e.split(".");if(5!==t.length)throw new Error(`JWE should have 5 parts, got ${t.length}`);const[i,n,r,a,o]=t;return{header:i,key:n,iv:r,payload:a,mac:o}}(e);if(a!==Rt)throw new Error("Incorrect JWE header");const u=At(o),h=new Uint8Array(At(s)),f=Bt((new k).encode(a),u,h);if(Nt(await Lt(f,r))!==c)throw new Error("MAC does not match JWE data");const p=await Tt(n),d=await async function(e,t,i){const n=await b.subtle.decrypt({name:"AES-CBC",length:_t,iv:e},t,i);return new Uint8Array(n)}(u,p,h);return(new A).decode(d)}async function Lt(e,t){return(await N(e,t)).slice(0,16)}function Bt(e,t,i){return function(e){const t=e.reduce(((e,{length:t})=>e+t),0),i=new Uint8Array(t);let n=0;return e.forEach((e=>{i.set(e,n),n+=e.length})),i}([e,t,i,Ut(e.length<<3)])}const Mt=2**32;function Vt(e,t,i){if(t<0||t>=Mt)throw new RangeError(`value must be >= 0 and <= ${Mt-1}. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,255&t],i)}function Ut(e){const t=Math.floor(e/Mt),i=e%Mt,n=new Uint8Array(8);return Vt(n,t,0),Vt(n,i,4),n}class Kt{constructor(e){this.maxSize=e,this.cachedItems=[]}getCacheSize(){return this.cachedItems.length}delete(e){this.cachedItems=this.cachedItems.filter((t=>t.key!==e))}add(e,t){this.delete(e),this.cachedItems.push({key:e,value:t}),this.cachedItems.length>this.maxSize&&this.cachedItems.shift()}get(e){return this.cachedItems.find((t=>t.key===e))}}class jt{constructor(e){this.encryptionKey=e.encryptionKey,this.cache=new Kt(e.cacheMaxSize??5)}getCacheSize(){return this.cache.getCacheSize()}async memoizeFn(e,t){const i=this.cache.get(e);if(void 0!==i)return i.value;const n=await t();return this.cache.add(e,n),n}async encrypt(e){const t=`encrypt::${e}`;return await this.memoizeFn(t,(async()=>await Pt({plaintext:e,secret:this.encryptionKey})))}async decrypt(e){const t=`encrypt::${e}`;return await this.memoizeFn(t,(async()=>await xt({jwe:e,secret:this.encryptionKey})))}}function Ht(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,function({ip:e,userAgent:t,status:i,method:n,path:r,protocol:a,referer:o,bytesSent:s,requestTime:c,mitataCookie:u,sessionStatus:h,integrationType:f,integrationVersion:p}){const d=(new Date).toUTCString();return{Request:`${n} ${r} ${a}`,TimeLocal:d,RealIp:e,UserAgent:t,Status:i,RequestTime:c?.toString(),BytesSent:s?.toString(),Referer:""===o?"-":o,NetaceaUserIdCookie:u??"",NetaceaMitigationApplied:h??"",IntegrationType:f??"",IntegrationVersion:p??""}}(e)}async function Dt(e,t,i){const n=Ht(i);if(t.ingestType!==r.KINESIS){const i={"X-Netacea-API-Key":t.apiKey??"","content-type":"application/json"},r=await async function(e,t,i,n){return await ne(e,0,{host:t.ingestServiceUrl,method:"POST",path:"/",headers:i,body:JSON.stringify(n),timeout:t.timeout})}(e,t,i,n);if(200!==r.status)throw Z.fromResponse(r)}}function $t(e,t,i,n,r,o){const s="unknown";r||("2"===n?n="4":"3"===n?n="5":"b"===n?n="d":"c"===n&&(n="e")),o&&(n="6");let c=q[t]??s+"_";c+=z[i]??s;let u=W[i];if("0"!==n){c+=","+(G[n]??s);const e=J[n];void 0!==e&&(u=e)}return e.mitigationType===a.INJECT&&(u=$.none),{sessionStatus:c,mitigation:u,parts:{match:t,mitigate:i,captcha:n}}}function Ft(e){return pt.cookie.cookieIsNetaceaV3Format(e)?pt.cookie.matchNetaceaCookieV3(e):function(e){if(void 0===e)return;const t=e.match(j);if(null!=t){const[,e,i,n,r,a,o,s,c]=t;return{signature:e,expiry:i,userId:n,ipHash:r,mitigationType:a,match:o,mitigate:s,captcha:c}}}(e)}var qt,zt="@netacea/akamai",Gt="6.6.2";async function Xt(e,t,i,n){t.ingestType===r.HTTP&&await async function(e,t,i,n){const r=t.netaceaCookieName??"_mitata",a=n.getHeader("set-cookie")??[],o=0!==a.length?a?.join("; "):St(i,"cookie");let s=await yt(e,t,o,r)??"";if(void 0===s||""===s){const n=St(i,"cookie");s=await yt(e,t,n,r)??""}const{match:c,mitigate:u,captcha:h}=Ft(s)??{match:"0",mitigate:"0",captcha:"0"},{sessionStatus:f}=$t(t,c,u,h,C(i.path,i.method),E(i.path,i.method,t.netaceaCheckpointSignalPath)),p=C(i.path,i.method)&&500===n.status;try{Dt(e,t,{bytesSent:St(n,"content-length","0"),ip:It(i,"PMUSER_CLIENT_IP",""),method:i.method,path:i.url,protocol:St(i,"protocol","HTTP/1.1"),referer:St(i,"referer",""),requestTime:"0",sessionStatus:p?"error_open":f,status:String(n.status),userAgent:St(i,"user-agent","-"),mitataCookie:s,integrationType:zt.replace("@netacea/",""),integrationVersion:Gt})}catch(t){e.logger.error(t)}}(e,t,i,n)}async function Wt(e,t,i,n,r,a){try{const o=void 0!==i?Et(i,t):void 0,s=o?.userId??n?.userId??"",c=void 0!==a?a.sessionStatus:function(e,t,i,n){if(void 0===t)return"error_open";const r=n?.match??i?.match??"0",a=n?.mitigate??i?.mitigate??"0";let o=n?.captcha??i?.captcha??"0";(function(e){if(!C(e.path,e.method))return!1;const t=e.getHeader("Content-Type")?.[0]??"";return"application/json"===t})(e)&&(o=String(X.checkpointPost));const{sessionStatus:s}=$t(t,r,a,o,C(e.path,e.method),E(e.path,e.method,t.netaceaCheckpointSignalPath));return s}(t,i,n,o),{sessionReason:u,sessionStartTime:h,mitigationStatusCode:f}=e.getState(),p=[s,c,Gt,r?.headerFingerprint??"",r?.cookieFingerprint??"",u??"",h??"",i?.mitigationType??"",f??"",t.getVariable("PMUSER_NETACEA_REQUEST_ID")??"",Jt(e,"logging_failure")].join(";");t.setVariable("PMUSER_NETACEA_DS2_CUSTOM_FIELD",p)}catch{}}function Jt(e,t){try{const t=e.flush();return R.Buffer.from(t).toString("base64")}catch{return t}}function Qt(e,t,i){e.setState({sessionReason:t,sessionStartTime:i??Math.floor(Date.now()/1e3)})}function Yt(e,t){t=t??e.query,e.route({origin:"mitigations",path:e.path,query:t})}function Zt(e,t){const i=(new te).setQuery("headerFP",t.headerFingerprint),n=[];for(const t in Q)void 0===e[t]&&n.push(t);return n.length>0&&i.setQuery("getSettings",n.join(",")),i}!function(e){e[e.NO_SESSION=0]="NO_SESSION",e[e.NEW_SESSION=1]="NEW_SESSION",e[e.EXISTING_SESSION=2]="EXISTING_SESSION",e[e.RENEW_SESSION=3]="RENEW_SESSION"}(qt||(qt={}));const{mitigationTypes:ei}=Y,ti=[ei.block,ei.captcha,ei.captchaPass];async function ii(e,t,i,n,r){const{netaceaCookieInfo:a,clientIp:o,netaceaSession:s}=i;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;if(void 0===t.secretKey)throw new Error("Secret key is required to mitigate");if(void 0!==i.netaceaCookieRequiredReissueReason){c=await async function(e,t,i,n,r,a){if(void 0===t.apiKey)throw new Error("An API Key is Required to call the protector API.");const o={"X-Netacea-API-Key":t.apiKey,"X-Netacea-Client-IP":i.clientIp,"X-Netacea-User-Agent":R.Buffer.from(i.userAgent).toString("base64"),cookie:re({_mitatacaptcha:i.netaceaSession.captchaToken}),"X-Netacea-Request-Id":i.requestId};void 0!==i.netaceaSession.userId&&(o["X-Netacea-UserId"]=i.netaceaSession.userId),void 0!==t.captchaSiteKey&&void 0!==t.captchaSecretKey&&(o["X-Netacea-Captcha-Site-Key"]=t.captchaSiteKey,o["X-Netacea-Captcha-Secret-Key"]=t.captchaSecretKey),t.captchaContentNegotiation&&void 0!==t.netaceaCaptchaPath&&(o["X-Netacea-Captcha-Content-Type"]=ae(n));const s=Zt(a,i.fingerprints);s.setQuery("netaceaHeaders","User-Agent, Request-ID");const c="application/json"===o["X-Netacea-Captcha-Content-Type"],u=await ne(e,0,{host:t.mitigationServiceUrl,path:"/"+s.buildQueryString(),headers:o,method:"GET",timeout:t.timeout});var h,f;h=e.logger,f=u.status,h.setState({mitigationStatusCode:f}),c&&void 0!==t.netaceaCaptchaPath&&(u.body=oe(u.body,r,t.netaceaCaptchaPath));let p={};return void 0!==u.headers["x-netacea-settings"]&&(p=dt(u.headers["x-netacea-settings"])),await ee(e,t,void 0,u,i.netaceaSession.userId,i.clientIp,i.netaceaCookieRequiredReissueReason,{...a,...p})}(e,t,i,n,r,i.netaceaSettings),c.responseNetaceaCookie=await D(o,s.userId,c.match,c.mitigate,c.captcha,i.netaceaCookieRequiredReissueReason,c.netaceaSettings,c.mitataMaxAge);const u=void 0===a.mitata?qt.NEW_SESSION:qt.RENEW_SESSION;Qt(e.logger,u)}else{const t=a.mitata;if(void 0!==t){const i=function(e){return pt.cookie.objectIsNetaceaCookieV3(e)?e.issueTimestamp:Number.parseInt(e.expiry,10)-60}(t);Qt(e.logger,qt.EXISTING_SESSION,i)}}const h=$t(t,c.match,c.mitigate,c.captcha,!1,!1),f={statusCode:void 0,body:c.body,apiCallStatus:c.status,responseNetaceaCookie:c?.responseNetaceaCookie,responseNetaceaCaptchaCookie:void 0,sessionStatus:h.sessionStatus,mitigation:h.mitigation,mitigated:ti.includes(h.mitigation),bestMitigation:h,eventId:c.eventId,redirectLocation:void 0};if("5"===h.parts.mitigate){if(f.statusCode=303,void 0!==c.redirectStatus){const e=Number(c.redirectStatus);e>300&&e<400&&(f.statusCode=e)}if(void 0!==c.redirectLocation)f.redirectLocation=c.redirectLocation;else if(void 0!==c.redirectHost){f.redirectLocation=`https://${c.redirectHost}${i.path}`;let e=i.query;""!==e&&(e.startsWith("?")||(e=`?${e}`),f.redirectLocation+=e)}void 0===f.redirectLocation&&(f.statusCode=402)}return f}function ni(e){return{apiCallStatus:0,responseNetaceaCookie:e,responseNetaceaCaptchaCookie:void 0,sessionStatus:"",mitigation:"000",mitigated:!1,bestMitigation:{sessionStatus:"",mitigation:"",parts:{match:"0",mitigate:"0",captcha:"0"}},eventId:void 0,statusCode:0,redirectLocation:void 0}}async function ri(e){return{sessionStatus:"",response:{headers:{},body:void 0,status:0,statusText:"",mitigation:"000"},bestAction:ni(await D(s,e,"0","0","0",o.NO_SESSION,void 0,86400))}}async function ai(e,t,i,n){try{switch(t.mitigationType){case a.MITIGATE:return await async function(e,t,i,n){const r=St(i,"accept","text/html"),a=await ii(e,t,n,r,i.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"),void 0!==a.statusCode&&(c=a.statusCode),void 0!==c&&c>300&&c<400&&void 0!==a.redirectLocation&&(o.Location=a.redirectLocation),{response:{body:s,status:c,statusText:c?.toString(),headers:o,mitigation:a.mitigation},sessionStatus:a.sessionStatus,bestAction:a}}(e,t,i,n);case a.INJECT:return await async function(e,t,i,n){const r=St(i,"accept","text/html"),a=await ii(e,t,n,r,i.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}}(e,t,i,n);case a.INGEST:return await async function(e,t,i){if(void 0===t.secretKey)throw new Error("Secret key is required for ingest");const n=St(i,"cookie"),r=await yt(e,t,n,t.netaceaCookieName??"_mitata"),a=await wt(e,r,s);return a.isPrimaryHashValid?a.requiresReissue?await ri(a.mitata?.userId):{sessionStatus:"",response:void 0,bestAction:ni()}:await ri(void 0)}(e,t,i);default:throw new Error(`Netacea Error: Mitigation type ${t.mitigationType} not recognised`)}}catch(t){return e.logger.error(t),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 oi(e,t,i,n){let o={};if(void 0!==i?.bestAction?.responseNetaceaCookie){const e=i?.bestAction?.responseNetaceaCookie;void 0!==e&&n.setVariable(t.protoMitataVariableName,JSON.stringify(e))}if(t.mitigationType===a.INJECT){o=i.injectHeaders??{}}let s={};t.ingestType===r.ORIGIN&&(s=await async function(e,t,i){const n=St(i,"cookie"),r=Ft(await yt(e,t,n,t.netaceaCookieName)??""),a=Et(t,i),{match:o,mitigate:s,captcha:c,userId:u}=a??r??{match:"0",mitigate:"0",captcha:"0",userId:""},{sessionStatus:h}=$t(t,o,s,c,C(i.path,i.method),!1);return{"X-Netacea-UserId":u,"X-Netacea-BC-Type":h,"X-Netacea-Integration-Type":zt.replace("@netacea/",""),"X-Netacea-Integration-Version":Gt}}(e,t,n));for(const[e,t]of Object.entries({...o,...s}))n.addHeader(e,t)}async function si(e){const t=function(e){return Object.keys(e).filter((e=>{const t=e.toLowerCase();return"cookie"!==t&&"referer"!==t&&!t.startsWith("x-netacea-")})).join(",")}(e);return await ci(t)}async function ci(e){let t="";try{t=await async function(e,t){const i=(new k).encode(t),n=await b.subtle.digest(e,i);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}("SHA-256",e)}catch(e){t=""}return t}async function ui(e){const t=e.getHeaders(),i=await si(t),n=function(e,t){const i=e.getHeader(t);return null==i?[]:i}(e,"cookie").map((e=>e.split(/; ?/).map((e=>e.split("=")[0])))).flat(),r=await async function(e){const t=e.join(",");return await ci(t)}(n);return[""===i?i:`h_${i.substring(1,15)}`,""===r?r:`c_${r.substring(1,15)}`]}async function hi(e,t,i){const r=It(i,"PMUSER_CLIENT_IP"),a=St(i,"user-agent"),s=void 0!==t.altCookieHeaderName?St(i,t.altCookieHeaderName):void 0,c=void 0!==s&&""!==s?s:St(i,"cookie");void 0!==t.altCookieHeaderName&&void 0!==s&&""!==s&&i.setVariable("NETACEA_USES_ALT_COOKIE_HEADER","true");const u=await yt(e,t,c,t.netaceaCookieName),h=await wt(e,u,r),f=function(e,t,i,n,r){if(void 0!==n&&!r.isPrimaryHashValid)return o.INVALID_SESSION;if(void 0===n)return function(e,t){for(const i of mt(e))if(i.startsWith(`${t}=`))return!0;return!1}(t,i)?o.INVALID_SESSION:o.NO_SESSION;if(r.isExpired)return o.EXPIRED_SESSION;if(!r.isSameIP)return o.IP_CHANGE;const a="post"===e.method.toLowerCase(),s=lt(r.mitata);if(a&&1===s.checkAllPostRequests)return o.FORCED_REVALIDATION}(i,c,t.netaceaCookieName,u,h),p=lt(h.mitata),d=await yt(e,t,c,t.netaceaCaptchaCookieName),[l,g]=await ui(i);let y=i.getVariable("PMUSER_NETACEA_REQUEST_ID")??"";if(""===y)try{y=n(),i.setVariable("PMUSER_NETACEA_REQUEST_ID",y)}catch(t){y="",e.logger.error("REQ_ID error")}return{path:i.path,query:i.query,clientIp:r,userAgent:a,method:i.method,netaceaCookieInfo:h,netaceaCookieRequiredReissueReason:f,netaceaSession:{userId:h.mitata?.userId,captchaToken:d,match:h.match,mitigate:h.mitigate,captcha:h.captcha},fingerprints:{headerFingerprint:l,cookieFingerprint:g},requestId:y,netaceaSettings:p}}class fi extends pt.cookie.AbstractCookieFactory{constructor(e,t){super(void 0===t?{...e,cookieEncryptionKey:void 0}:e),this.cachedEncryption=t}async encrypt(e){if(void 0===this.cachedEncryption)throw new Error("AkamaiCookieFactory.encrypt called without a configured encryption adapter");return await this.cachedEncryption.encrypt(e)}async decrypt(e){if(void 0===this.cachedEncryption)throw new Error("AkamaiCookieFactory.decrypt called without a configured encryption adapter");return await this.cachedEncryption.decrypt(e)}async hash(e,t){const i=await N(R.Buffer.from(e),t),n=R.Buffer.from(i).toString("hex");return R.Buffer.from(n).toString("base64")}getRandomValues(e){return crypto.getRandomValues(e)}isEncrypted(e){return 5===e.split(".").length}}class pi{constructor(e){this.errorLog="",this.options=e,this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}getState(){return Object.assign({},this.state)}setState(e){for(const t in this.state)void 0!==e[t]&&(this.state[t]=e[t])}appendErrorLog(e){this.errorLog=function(e,t,i){if(t-e.length<=2)return e;const n=i.trim().slice(0,t).replace(/\n/g,"\\n");return(""===e?n:e+"\n"+n).slice(0,t)}(this.errorLog,this.options.maxErrorLogLength,e)}error(e){try{if(this.options.maxErrorLogLength<=0||null==e||""===e)return;if("string"==typeof e)this.appendErrorLog(e);else{const t=function(e){if(void 0!==e.stack)return e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack;return e.message}(e);this.appendErrorLog(t)}}catch{}}flush(){try{return this.errorLog}finally{this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}}}class di{constructor(t){this.configLoader=new y(t),this.runtimeDeps={httpRequest:e}}initDeps(e,t){const i=void 0===t.cookieEncryptionKey?void 0:new jt({encryptionKey:t.cookieEncryptionKey}),n=new fi({cookieEncryptionKey:t.cookieEncryptionKey,secretKey:t.secretKey,expirySeconds:t.netaceaCookieExpirySeconds},t.ingestType!==r.HTTP?i:void 0);return{...this.runtimeDeps,config:t,logger:e,cachedEncryption:i,cookieFactory:n}}async requestHandler(e){const t=new pi({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(e)});let i,n,r;try{n=this.configLoader.loadConfig(e);const u=this.initDeps(t,n);if(r=await hi(u,n,e),void 0!==r.netaceaCookieRequiredReissueReason&&e.setVariable("PMUSER_NETACEA_ISSUE_REASON",r.netaceaCookieRequiredReissueReason),a=e.path,s=e.method,void 0!==(c=n.netaceaCaptchaPath)&&c.length>0&&a===c&&"get"===s.toLowerCase())await async function(e,t,i,n){const r=St(i,"cookie"),a=await yt(e,t,r,t.netaceaCookieName),s=await yt(e,t,r,t.netaceaCaptchaCookieName),c=It(i,"PMUSER_CLIENT_IP"),u=St(i,"user-agent"),h=await wt(e,a,c),f=Ct(t,"captcha",403),p=await gt(e,t,n.netaceaSettings,{apiKey:t.apiKey??"",clientIP:c,userAgent:u,userId:h.mitata?.userId,captchaCookie:s,trackingId:vt(i.query,"trackingId"),captchaSiteKey:t.captchaSiteKey,captchaSecretKey:t.captchaSecretKey,accept:St(i,"accept","text/html"),host:i.host,requestId:n.requestId},{match:"0",mitigate:"0",captcha:"1"}),d=p.responseNetaceaCookie;void 0!==d&&(void 0===n.netaceaCookieRequiredReissueReason?d.issueReason=o.CAPTCHA_GET:d.issueReason=n.netaceaCookieRequiredReissueReason,i.setVariable(t.protoMitataVariableName,JSON.stringify(d)));const l={};void 0!==t.netaceaCaptchaHeaderKey&&void 0!==t.netaceaCaptchaHeaderValue&&(l[t.netaceaCaptchaHeaderKey]=t.netaceaCaptchaHeaderValue),i.respondWith(f,l,p.body??"")}(u,n,e,r);else if(C(e.path,e.method))await async function(e,t,i,n){if(void 0===t.apiKey)throw new Error("An API Key is Required to Verify Captcha");const r=i.getVariable("PMUSER_CLIENT_IP")??"";i.setHeader("x-netacea-api-key",t.apiKey),i.setHeader("x-netacea-client-ip",r);const a=St(i,"cookie"),o=await yt(e,t,a,t.netaceaCookieName)??"";let s="";const c=await wt(e,o,r);if(pt.cookie.objectIsNetaceaCookieV3(c.mitata)){const e={checkAllPostRequests:c.mitata.checkAllPostRequests};i.setHeader("x-netacea-settings",JSON.stringify(e))}c.isPrimaryHashValid&&(s=c.mitata?.userId??""),i.setHeader("x-netacea-userid",s),i.setHeader("x-netacea-user-agent",R.Buffer.from(n.userAgent).toString("base64")),i.setHeader("x-netacea-request-id",n.requestId);const u=Zt(n.netaceaSettings,n.fingerprints);u.setQuery("netaceaHeaders","User-Agent, Request-ID"),Yt(i,u.buildQueryString())}(u,n,e,r);else if(w(e.path,e.method,n.useCaptchaRelAssets))Yt(e);else if(E(e.path,e.method,n.netaceaCheckpointSignalPath))await async function(e){e.respondWith(200,{},"")}(e);else{const t=function(e,t){if(void 0===t.netaceaBlockedResponseRedirectLocation)return!1;if(t.netaceaBlockedResponseRedirectLocation.startsWith("/"))return t.netaceaBlockedResponseRedirectLocation===e.path;try{const i=new URL(t.netaceaBlockedResponseRedirectLocation);return i.host===e.host&&i.pathname===e.path}catch{return!1}}(e,n);t||(i=await async function(e,t,i,n){const r=await ai(e,t,i,n);if(void 0===r)throw new Error('Mitigation Service response "mitResult" was undefined.');const a=r.response?.mitigation,o=[$.block,$.captcha,$.monetise].includes(a??"");if(void 0!==a&&o){let e=Ct(t,a,r.response?.status??403);const n={};for(const e of Object.keys(r.response?.headers??{})){const t=r.response?.headers[e];void 0!==e&&void 0!==t&&(n[e]=t)}const o=t.netaceaBlockedResponseRedirectLocation;"block"===a&&void 0!==o&&function(e){if("GET"!==e.method?.toUpperCase())return!1;const t=e.getHeader("sec-fetch-mode")??[];return!(t.length>0&&!t.includes("navigate"))&&(e.getHeader("accept")?.map((e=>e.split(/, ?/))).flat()??[]).includes("text/html")}(i)&&(e=303,n.Location=o);const s=r.bestAction?.responseNetaceaCookie;void 0!==s&&i.setVariable(t.protoMitataVariableName,JSON.stringify(s));const c=r.response?.body??"";(function(e){return e.includes("captchaRelativeURL")&&e.includes("captchaAbsoluteURL")})(c)&&(n["content-type"]="application/json"),"captcha"===a&&(void 0===n["content-type"]&&(n["content-type"]="text/html"),void 0!==t.netaceaCaptchaHeaderKey&&void 0!==t.netaceaCaptchaHeaderValue&&(n[t.netaceaCaptchaHeaderKey]=t.netaceaCaptchaHeaderValue)),i.respondWith(e,n,c)}else await oi(e,t,r,i);return r}(u,n,e,r))}}catch(e){t.error(e)}finally{try{await Wt(t,e,n,r?.netaceaSession,r?.fingerprints,i)}catch{}}var a,s,c}async responseHandler(e,t){const i=new pi({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(e)});try{const n=this.configLoader.loadConfig(e),r=this.initDeps(i,n);if(C(e.path,e.method))await kt(r,n,e,t);else if(v(e.path,e.method)&&!w(e.path,e.method,n.useCaptchaRelAssets)){const i=e.getVariable("PMUSER_NETACEA_ISSUE_REASON")!==o.NO_SESSION,a=e.getVariable("NETACEA_USES_ALT_COOKIE_HEADER");i&&"true"!==a&&await bt(r,n,e,t)}else if(!w(e.path,e.method,n.useCaptchaRelAssets)){"true"!==e.getVariable("NETACEA_USES_ALT_COOKIE_HEADER")&&await bt(r,n,e,t)}!function(e){e.removeHeader("x-netacea-match"),e.removeHeader("x-netacea-mitigate"),e.removeHeader("x-netacea-captcha"),e.removeHeader("x-netacea-mitata-expiry"),e.removeHeader("x-netacea-mitata-value"),e.removeHeader("x-netacea-mitatacaptcha-expiry"),e.removeHeader("x-netacea-mitatacaptcha-value"),e.removeHeader("x-netacea-event-id"),e.removeHeader("x-netacea-settings")}(t),await Xt(r,n,e,t)}catch(e){i.error(e)}}}export{a as NetaceaMitigationType,di as default};
|
|
10
|
+
!function(e){const t=O,i=U,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=function(e){+e!=e&&(e=0);return o.alloc(+e)},e.INSPECT_MAX_BYTES=50;const a=2147483647;function r(e){if(e>a)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,i){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return s(e,t,i)}function s(e,t,i){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const i=0|d(e,t);let n=r(i);const a=n.write(e,t);a!==i&&(n=n.slice(0,a));return n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(W(e,Uint8Array)){const t=new Uint8Array(e);return f(t.buffer,t.byteOffset,t.byteLength)}return h(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(W(e,ArrayBuffer)||e&&W(e.buffer,ArrayBuffer))return f(e,t,i);if("undefined"!=typeof SharedArrayBuffer&&(W(e,SharedArrayBuffer)||e&&W(e.buffer,SharedArrayBuffer)))return f(e,t,i);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,i);const a=function(e){if(o.isBuffer(e)){const t=0|p(e.length),i=r(t);return 0===i.length||e.copy(i,0,0,t),i}if(void 0!==e.length)return"number"!=typeof e.length||J(e.length)?r(0):h(e);if("Buffer"===e.type&&Array.isArray(e.data))return h(e.data)}(e);if(a)return a;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,i);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function c(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return c(e),r(e<0?0:0|p(e))}function h(e){const t=e.length<0?0:0|p(e.length),i=r(t);for(let n=0;n<t;n+=1)i[n]=255&e[n];return i}function f(e,t,i){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(i||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,t):new Uint8Array(e,t,i),Object.setPrototypeOf(n,o.prototype),n}function p(e){if(e>=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return 0|e}function d(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||W(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const i=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===i)return 0;let a=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":return z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return G(e).length;default:if(a)return n?-1:z(e).length;t=(""+t).toLowerCase(),a=!0}}function l(e,t,i){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return _(this,t,i);case"utf8":case"utf-8":return E(this,t,i);case"ascii":return A(this,t,i);case"latin1":case"binary":return N(this,t,i);case"base64":return b(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,i){const n=e[t];e[t]=e[i],e[i]=n}function y(e,t,i,n,a){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),J(i=+i)&&(i=a?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(a)return-1;i=e.length-1}else if(i<0){if(!a)return-1;i=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:m(e,t,i,n,a);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?a?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):m(e,[t],i,n,a);throw new TypeError("val must be string, number or Buffer")}function m(e,t,i,n,a){let r,o=1,s=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;o=2,s/=2,c/=2,i/=2}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(a){let n=-1;for(r=i;r<s;r++)if(u(e,r)===u(t,-1===n?0:r-n)){if(-1===n&&(n=r),r-n+1===c)return n*o}else-1!==n&&(r-=r-n),n=-1}else for(i+c>s&&(i=s-c),r=i;r>=0;r--){let i=!0;for(let n=0;n<c;n++)if(u(e,r+n)!==u(t,n)){i=!1;break}if(i)return r}return-1}function S(e,t,i,n){i=Number(i)||0;const a=e.length-i;n?(n=Number(n))>a&&(n=a):n=a;const r=t.length;let o;for(n>r/2&&(n=r/2),o=0;o<n;++o){const n=parseInt(t.substr(2*o,2),16);if(J(n))return o;e[i+o]=n}return o}function I(e,t,i,n){return X(z(t,e.length-i),e,i,n)}function w(e,t,i,n){return X(function(e){const t=[];for(let i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function v(e,t,i,n){return X(G(t),e,i,n)}function C(e,t,i,n){return X(function(e,t){let i,n,a;const r=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)i=e.charCodeAt(o),n=i>>8,a=i%256,r.push(a),r.push(n);return r}(t,e.length-i),e,i,n)}function b(e,i,n){return 0===i&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(i,n))}function E(e,t,i){i=Math.min(e.length,i);const n=[];let a=t;for(;a<i;){const t=e[a];let r=null,o=t>239?4:t>223?3:t>191?2:1;if(a+o<=i){let i,n,s,c;switch(o){case 1:t<128&&(r=t);break;case 2:i=e[a+1],128==(192&i)&&(c=(31&t)<<6|63&i,c>127&&(r=c));break;case 3:i=e[a+1],n=e[a+2],128==(192&i)&&128==(192&n)&&(c=(15&t)<<12|(63&i)<<6|63&n,c>2047&&(c<55296||c>57343)&&(r=c));break;case 4:i=e[a+1],n=e[a+2],s=e[a+3],128==(192&i)&&128==(192&n)&&128==(192&s)&&(c=(15&t)<<18|(63&i)<<12|(63&n)<<6|63&s,c>65535&&c<1114112&&(r=c))}}null===r?(r=65533,o=1):r>65535&&(r-=65536,n.push(r>>>10&1023|55296),r=56320|1023&r),n.push(r),a+=o}return function(e){const t=e.length;if(t<=k)return String.fromCharCode.apply(String,e);let i="",n=0;for(;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=k));return i}(n)}e.kMaxLength=a,o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){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(e,t,i){return s(e,t,i)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,i){return function(e,t,i){return c(e),e<=0?r(e):void 0!==t?"string"==typeof i?r(e).fill(t,i):r(e).fill(t):r(e)}(e,t,i)},o.allocUnsafe=function(e){return u(e)},o.allocUnsafeSlow=function(e){return u(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),W(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,n=t.length;for(let a=0,r=Math.min(i,n);a<r;++a)if(e[a]!==t[a]){i=e[a],n=t[a];break}return i<n?-1:n<i?1:0},o.isEncoding=function(e){switch(String(e).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(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;const n=o.allocUnsafe(t);let a=0;for(i=0;i<e.length;++i){let t=e[i];if(W(t,Uint8Array))a+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,a)):Uint8Array.prototype.set.call(n,t,a);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,a)}a+=t.length}return n},o.byteLength=d,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)g(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)g(this,t,t+3),g(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)g(this,t,t+7),g(this,t+1,t+6),g(this,t+2,t+5),g(this,t+3,t+4);return this},o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?E(this,0,e):l.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let t="";const i=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,i).replace(/(.{2})/g,"$1 ").trim(),this.length>i&&(t+=" ... "),"<Buffer "+t+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,i,n,a){if(W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===a&&(a=this.length),t<0||i>e.length||n<0||a>this.length)throw new RangeError("out of range index");if(n>=a&&t>=i)return 0;if(n>=a)return-1;if(t>=i)return 1;if(this===e)return 0;let r=(a>>>=0)-(n>>>=0),s=(i>>>=0)-(t>>>=0);const c=Math.min(r,s),u=this.slice(n,a),h=e.slice(t,i);for(let e=0;e<c;++e)if(u[e]!==h[e]){r=u[e],s=h[e];break}return r<s?-1:s<r?1:0},o.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},o.prototype.indexOf=function(e,t,i){return y(this,e,t,i,!0)},o.prototype.lastIndexOf=function(e,t,i){return y(this,e,t,i,!1)},o.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(i)?(i>>>=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}const a=this.length-t;if((void 0===i||i>a)&&(i=a),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let r=!1;for(;;)switch(n){case"hex":return S(this,e,t,i);case"utf8":case"utf-8":return I(this,e,t,i);case"ascii":case"latin1":case"binary":return w(this,e,t,i);case"base64":return v(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,t,i);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),r=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const k=4096;function A(e,t,i){let n="";i=Math.min(e.length,i);for(let a=t;a<i;++a)n+=String.fromCharCode(127&e[a]);return n}function N(e,t,i){let n="";i=Math.min(e.length,i);for(let a=t;a<i;++a)n+=String.fromCharCode(e[a]);return n}function _(e,t,i){const n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);let a="";for(let n=t;n<i;++n)a+=Q[e[n]];return a}function R(e,t,i){const n=e.slice(t,i);let a="";for(let e=0;e<n.length-1;e+=2)a+=String.fromCharCode(n[e]+256*n[e+1]);return a}function T(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function P(e,t,i,n,a,r){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>a||t<r)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function x(e,t,i,n,a){D(t,n,a,e,i,7);let r=Number(t&BigInt(4294967295));e[i++]=r,r>>=8,e[i++]=r,r>>=8,e[i++]=r,r>>=8,e[i++]=r;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[i++]=o,o>>=8,e[i++]=o,o>>=8,e[i++]=o,o>>=8,e[i++]=o,i}function L(e,t,i,n,a){D(t,n,a,e,i,7);let r=Number(t&BigInt(4294967295));e[i+7]=r,r>>=8,e[i+6]=r,r>>=8,e[i+5]=r,r>>=8,e[i+4]=r;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[i+3]=o,o>>=8,e[i+2]=o,o>>=8,e[i+1]=o,o>>=8,e[i]=o,i+8}function B(e,t,i,n,a,r){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function M(e,t,n,a,r){return t=+t,n>>>=0,r||B(e,0,n,4),i.write(e,t,n,a,23,4),n+4}function V(e,t,n,a,r){return t=+t,n>>>=0,r||B(e,0,n,8),i.write(e,t,n,a,52,8),n+8}o.prototype.slice=function(e,t){const i=this.length;(e=~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),(t=void 0===t?i:~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),t<e&&(t=e);const n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=this[e],a=1,r=0;for(;++r<t&&(a*=256);)n+=this[e+r]*a;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=this[e+--t],a=1;for(;t>0&&(a*=256);)n+=this[e+--t]*a;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||T(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||T(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||T(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,a=this[++e]+256*this[++e]+65536*this[++e]+i*2**24;return BigInt(n)+(BigInt(a)<<BigInt(32))})),o.prototype.readBigUInt64BE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],a=this[++e]*2**24+65536*this[++e]+256*this[++e]+i;return(BigInt(n)<<BigInt(32))+BigInt(a)})),o.prototype.readIntLE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=this[e],a=1,r=0;for(;++r<t&&(a*=256);)n+=this[e+r]*a;return a*=128,n>=a&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,i){e>>>=0,t>>>=0,i||T(e,t,this.length);let n=t,a=1,r=this[e+--n];for(;n>0&&(a*=256);)r+=this[e+--n]*a;return a*=128,r>=a&&(r-=Math.pow(2,8*t)),r},o.prototype.readInt8=function(e,t){return e>>>=0,t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||T(e,2,this.length);const i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},o.prototype.readInt16BE=function(e,t){e>>>=0,t||T(e,2,this.length);const i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(i<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)})),o.prototype.readBigInt64BE=Y((function(e){$(e>>>=0,"offset");const t=this[e],i=this[e+7];void 0!==t&&void 0!==i||F(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+i)})),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||T(e,4,this.length),i.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||T(e,4,this.length),i.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||T(e,8,this.length),i.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||T(e,8,this.length),i.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,i,n){if(e=+e,t>>>=0,i>>>=0,!n){P(this,e,t,i,Math.pow(2,8*i)-1,0)}let a=1,r=0;for(this[t]=255&e;++r<i&&(a*=256);)this[t+r]=e/a&255;return t+i},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,i,n){if(e=+e,t>>>=0,i>>>=0,!n){P(this,e,t,i,Math.pow(2,8*i)-1,0)}let a=i-1,r=1;for(this[t+a]=255&e;--a>=0&&(r*=256);)this[t+a]=e/r&255;return t+i},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=Y((function(e,t=0){return x(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeBigUInt64BE=Y((function(e,t=0){return L(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),o.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*i-1);P(this,e,t,i,n-1,-n)}let a=0,r=1,o=0;for(this[t]=255&e;++a<i&&(r*=256);)e<0&&0===o&&0!==this[t+a-1]&&(o=1),this[t+a]=(e/r|0)-o&255;return t+i},o.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*i-1);P(this,e,t,i,n-1,-n)}let a=i-1,r=1,o=0;for(this[t+a]=255&e;--a>=0&&(r*=256);)e<0&&0===o&&0!==this[t+a+1]&&(o=1),this[t+a]=(e/r|0)-o&255;return t+i},o.prototype.writeInt8=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,i){return e=+e,t>>>=0,i||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=Y((function(e,t=0){return x(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeBigInt64BE=Y((function(e,t=0){return L(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),o.prototype.writeFloatLE=function(e,t,i){return M(this,e,t,!0,i)},o.prototype.writeFloatBE=function(e,t,i){return M(this,e,t,!1,i)},o.prototype.writeDoubleLE=function(e,t,i){return V(this,e,t,!0,i)},o.prototype.writeDoubleBE=function(e,t,i){return V(this,e,t,!1,i)},o.prototype.copy=function(e,t,i,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);const a=n-i;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,i,n):Uint8Array.prototype.set.call(e,this.subarray(i,n),t),a},o.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){const t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;let a;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(a=t;a<i;++a)this[a]=e;else{const r=o.isBuffer(e)?e:o.from(e,n),s=r.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<i-t;++a)this[a+t]=r[a%s]}return this};const K={};function j(e,t,i){K[e]=class extends i{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function H(e){let t="",i=e.length;const n="-"===e[0]?1:0;for(;i>=n+4;i-=3)t=`_${e.slice(i-3,i)}${t}`;return`${e.slice(0,i)}${t}`}function D(e,t,i,n,a,r){if(e>i||e<t){const i="bigint"==typeof t?"n":"";let n;throw n=0===t||t===BigInt(0)?`>= 0${i} and < 2${i} ** ${8*(r+1)}${i}`:`>= -(2${i} ** ${8*(r+1)-1}${i}) and < 2 ** ${8*(r+1)-1}${i}`,new K.ERR_OUT_OF_RANGE("value",n,e)}!function(e,t,i){$(t,"offset"),void 0!==e[t]&&void 0!==e[t+i]||F(t,e.length-(i+1))}(n,a,r)}function $(e,t){if("number"!=typeof e)throw new K.ERR_INVALID_ARG_TYPE(t,"number",e)}function F(e,t,i){if(Math.floor(e)!==e)throw $(e,i),new K.ERR_OUT_OF_RANGE("offset","an integer",e);if(t<0)throw new K.ERR_BUFFER_OUT_OF_BOUNDS;throw new K.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}j("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),j("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),j("ERR_OUT_OF_RANGE",(function(e,t,i){let n=`The value of "${e}" is out of range.`,a=i;return Number.isInteger(i)&&Math.abs(i)>2**32?a=H(String(i)):"bigint"==typeof i&&(a=String(i),(i>BigInt(2)**BigInt(32)||i<-(BigInt(2)**BigInt(32)))&&(a=H(a)),a+="n"),n+=` It must be ${t}. Received ${a}`,n}),RangeError);const q=/[^+/0-9A-Za-z-_]/g;function z(e,t){let i;t=t||1/0;const n=e.length;let a=null;const r=[];for(let o=0;o<n;++o){if(i=e.charCodeAt(o),i>55295&&i<57344){if(!a){if(i>56319){(t-=3)>-1&&r.push(239,191,189);continue}if(o+1===n){(t-=3)>-1&&r.push(239,191,189);continue}a=i;continue}if(i<56320){(t-=3)>-1&&r.push(239,191,189),a=i;continue}i=65536+(a-55296<<10|i-56320)}else a&&(t-=3)>-1&&r.push(239,191,189);if(a=null,i<128){if((t-=1)<0)break;r.push(i)}else if(i<2048){if((t-=2)<0)break;r.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;r.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;r.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return r}function G(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function X(e,t,i,n){let a;for(a=0;a<n&&!(a+i>=t.length||a>=e.length);++a)t[a+i]=e[a];return a}function W(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function J(e){return e!=e}const Q=function(){const e="0123456789abcdef",t=new Array(256);for(let i=0;i<16;++i){const n=16*i;for(let a=0;a<16;++a)t[n+a]=e[i]+e[a]}return t}();function Y(e){return"undefined"==typeof BigInt?Z:e}function Z(){throw new Error("BigInt not supported")}}(R);const K="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),j=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function H(e=16,t=K){const i=new Uint16Array(e-1);E.getRandomValues(i);return`c${Array.from(i).map((e=>t[e%t.length])).join("")}`}async function D(e,t,i,n,a,r,o,s=86400){return{clientIP:e,userId:t??H(),match:i,mitigate:n,captcha:a,mitataMaxAge:s,netaceaSettings:o??{},issueReason:r}}const $={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass",monetise:"monetise",flag:"flag"},F={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",redirectHost:"x-netacea-redirect-host",redirectLocation:"x-netacea-redirect-location",redirectStatus:"x-netacea-redirect-status"},q={0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},z={0:"",1:"blocked",2:"allow",3:"hardblocked",4:"flagged",5:"monetised"},G={0:"",1:"captcha_serve",2:"captcha_pass",3:"captcha_fail",4:"captcha_cookiepass",5:"captcha_cookiefail",6:"checkpoint_signal",7:"checkpoint_post",a:"checkpoint_serve",b:"checkpoint_pass",c:"checkpoint_fail",d:"checkpoint_cookiepass",e:"checkpoint_cookiefail"},X={"":0,captchaServe:1,captchaPass:2,captchaFail:3,captchaCookiePass:4,captchaCookieFail:5,checkpointSignal:6,checkpointPost:7,checkpointServe:"a",checkpointPass:"b",checkpointFail:"c",checkpointCookiePass:"d",checkpointCookieFail:"e"},W={0:$.none,1:$.block,2:$.none,3:$.block,4:$.flag,5:$.monetise},J={1:$.captcha,2:$.captchaPass,3:$.captcha,4:$.allow,5:$.captcha,6:$.allow,7:$.captcha,a:$.captcha,b:$.captchaPass,c:$.captcha,d:$.allow,e:$.captcha},Q={checkAllPostRequests:"checkAllPostRequests"};var Y=Object.freeze({__proto__:null,COOKIEDELIMITER:"_/@#/",bestMitigationCaptchaMap:J,bestMitigationMap:W,captchaMap:G,captchaStatusCodes:X,get dictionary(){return Y},matchMap:q,mitigateMap:z,mitigationTypes:$,netaceaHeaders:F,netaceaSettingsMap:Q});class Z extends Error{static fromResponse(e){let t="Unknown error";switch(e.status){case 403:t="Invalid credentials";break;case 500:t="Server error";break;case 502:t="Bad Gateway";break;case 503:t="Service Unavailable";break;case 400:t="Invalid request"}return new Z(t)}}async function ee(e,t,i,n,a,r,s=o.NO_SESSION,c){if(200!==n.status)throw Z.fromResponse(n);let u=n.headers[F.match],h=n.headers[F.mitigate],f=n.headers[F.captcha];void 0===q[u]&&(u=i?.match??"0"),void 0===h&&(h=i?.mitigate??"0"),void 0===f&&(f=i?.captcha??"0");let p=parseInt(n.headers[F.mitataExpiry]);isNaN(p)&&(p=86400);const d=await D(r,a,u,h,f,s,c),l=await async function(e,t,i){if(Object.prototype.hasOwnProperty.call(i,F.mitataCaptcha)){const n=i[F.mitataCaptcha],a=parseInt(i[F.mitataCaptchaExpiry]),r=await async function(e,t,i,n,a,r="/"){const o=[t.netaceaCookieName,t.netaceaCaptchaCookieName];return void 0!==e.cachedEncryption&&o.includes(i)?`${i}=${await e.cachedEncryption.encrypt(n)}; Max-Age=${a}; Path=${r}`:`${i}=${n}; Max-Age=${a}; Path=${r}`}(e,t,t.netaceaCaptchaCookieName,n,a);if(void 0!==r)return r}}(e,t,n.headers),g=n.headers[F.eventId];return{status:n.status,match:u,mitigate:h,captcha:f,responseNetaceaCookie:d,responseNetaceaCaptchaCookie:l,body:n.body,eventId:g,mitataMaxAge:p,netaceaSettings:c??{},redirectHost:n.headers[F.redirectHost],redirectLocation:n.headers[F.redirectLocation],redirectStatus:n.headers[F.redirectStatus]}}class te{constructor(){this.queries={}}setQuery(e,t){return this.queries[e]=encodeURIComponent(t),this}removeQuery(e){const{[e]:t,...i}=this.queries;return this.queries=i,this}buildQueryString(){const e=Object.entries(this.queries).map((([e,t])=>`${e}=${t}`)).join("&");return e.length>0?`?${e}`:""}}function ie(e){const t=Object.entries(e.getHeaders()),i={};for(const[e,n]of t)i[e]=n[0];return i}async function ne(e,t,i){const{method:n,path:a,headers:r,body:o,timeout:s}=i;let{host:c}=i;c.endsWith("/")&&(c=c.slice(0,-1));const u=c+a,{httpRequest:h}=e,f=await h(u,{body:o,headers:r,method:n,timeout:s??3e3});return{status:f.status,body:await f.text(),headers:ie(f)}}function ae(e){return Object.entries(e).filter((([,e])=>void 0!==e)).map((e=>e.join("="))).join("; ")}function re(e){const t=e?.toLowerCase()??"text/html",i=t?.includes("text/html")||t?.includes("application/html"),n=t?.includes("application/json");return n&&!i?"application/json":"text/html"}function oe(e,t,i){let n;if(void 0===e||""===e)return"";if("string"==typeof e&&(n=JSON.parse(e)),!function(e){if(null==e)return!1;const t=e;return void 0!==t?.captchaSiteKey&&void 0!==t?.trackingId&&void 0!==t?.captchaURL}(n))throw new Error("Body is not a Mitigation Service JSON response!");const a=`${i}?trackingId=${n.trackingId}`,r=`https://${t}${a}`;return JSON.stringify({captchaRelativeURL:a,captchaAbsoluteURL:r})}var se,ce={},ue={};Object.defineProperty(ue,"__esModule",{value:!0}),ue.NetaceaCookieV3IssueReason=void 0,function(e){e.CAPTCHA_GET="captcha_get",e.CAPTCHA_POST="captcha_post",e.EXPIRED_SESSION="expired_session",e.FORCED_REVALIDATION="forced_revalidation",e.INVALID_SESSION="invalid_session",e.IP_CHANGE="ip_change",e.NO_SESSION="no_session",e.UNKNOWN="unknown"}(se||(ue.NetaceaCookieV3IssueReason=se={}));var he={},fe={},pe={};Object.defineProperty(pe,"__esModule",{value:!0}),pe.netaceaCookieV3OptionalKeyMap=pe.netaceaCookieV3KeyMap=pe.COOKIEDELIMITER=void 0,pe.COOKIEDELIMITER="_/@#/",pe.netaceaCookieV3KeyMap={clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},pe.netaceaCookieV3OptionalKeyMap={checkAllPostRequests:"fCAPR"},Object.defineProperty(fe,"__esModule",{value:!0}),fe.defaultInvalidResponse=fe.matchNetaceaCookieV3=fe.checkNetaceaCookieV3=fe.objectIsNetaceaCookieV3=fe.cookieIsNetaceaV3Format=fe.createNetaceaCookieV3=void 0;const de=ue,le=pe;function ge(e){if(void 0===e||""===e)return;const t=e.split("&"),i={clientIP:"",userId:"",cookieId:"",gracePeriod:0,match:"0",mitigate:"0",captcha:"0",issueTimestamp:0,issueReason:"",checkAllPostRequests:void 0};for(const e of t){const[t,n]=e.split("="),a=decodeURIComponent(n);let r,o=Object.keys(le.netaceaCookieV3KeyMap).find((e=>le.netaceaCookieV3KeyMap[e]===t));void 0===o&&(o=Object.keys(le.netaceaCookieV3OptionalKeyMap).find((e=>le.netaceaCookieV3OptionalKeyMap[e]===t))),r=void 0!==o&&["match","mitigate","captcha"].includes(o)?""===a?void 0:a:""===a?void 0:Number(a),void 0!==r&&"string"!=typeof r&&isNaN(r)&&(r=a),i[o]=r}return i}function ye(){return{mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0",issueReason:de.NetaceaCookieV3IssueReason.NO_SESSION}}fe.createNetaceaCookieV3=function(e){return Object.entries(e).filter((([e,t])=>void 0!==t)).map((([e,t])=>e in le.netaceaCookieV3OptionalKeyMap?`${le.netaceaCookieV3OptionalKeyMap[e]}=${encodeURIComponent(t)}`:`${le.netaceaCookieV3KeyMap[e]}=${encodeURIComponent(t)}`)).join("&")},fe.cookieIsNetaceaV3Format=function(e){if(void 0===e||""===e)return!1;const t=e.split("&").map((e=>e.split("=")[0])).filter((e=>!Object.values(le.netaceaCookieV3OptionalKeyMap).includes(e)));return 0!==t.length&&t.every((e=>Object.values(le.netaceaCookieV3KeyMap).includes(e)))},fe.objectIsNetaceaCookieV3=function(e){if("object"!=typeof e||null===e)return!1;for(const t of Object.keys(le.netaceaCookieV3KeyMap)){if(!(t in e))return!1;if(void 0===e[t])return!1}return!0},fe.checkNetaceaCookieV3=function(e,t){if(void 0===e||""===e)return ye();let i;try{i=ge(e)}catch{return ye()}if(void 0!==i){const e=Math.floor(Date.now()/1e3),n=i.issueTimestamp+i.gracePeriod<e,a=t===i.clientIP,r=["1","3","5","a","c","e"].includes(i.captcha),o="3"===i.mitigate;return{mitata:i,requiresReissue:n||!a,isExpired:n,shouldExpire:r||o,isSameIP:a,isPrimaryHashValid:!0,match:i.match,mitigate:i.mitigate,captcha:i.captcha,issueReason:i.issueReason}}return ye()},fe.matchNetaceaCookieV3=ge,fe.defaultInvalidResponse=ye;var me={};Object.defineProperty(me,"__esModule",{value:!0}),me.AbstractCookieFactory=void 0;const Se=ue,Ie=fe,we=pe,ve="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),Ce=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;me.AbstractCookieFactory=class{constructor(e){this.config=e}isEncrypted(e){return 5===e.split(".").length}async createCookieValue(e){if(void 0!==this.config.cookieEncryptionKey){const t=(0,Ie.createNetaceaCookieV3)({clientIP:e.clientIP,userId:e.userId??"",match:e.match,mitigate:e.mitigate,captcha:e.captcha,gracePeriod:e.gracePeriod,cookieId:e.cookieId,issueTimestamp:Math.floor(Date.now()/1e3),issueReason:e.issueReason??Se.NetaceaCookieV3IssueReason.NO_SESSION,checkAllPostRequests:e.checkAllPostRequests});return await this.encrypt(t)}if(void 0===this.config.secretKey)throw new Error("Cannot build cookie without secret key.");const t=[e.match,e.mitigate,e.captcha].join(""),i=Math.floor(Date.now()/1e3)+e.gracePeriod;return await this.buildMitataCookie(e.clientIP,e.userId,i,this.config.secretKey,t)}async retrieveCookieInfo(e,t){if(void 0===e||""===e)return(0,Ie.defaultInvalidResponse)();let i=e;return this.isEncrypted(e)&&(i=await this.decrypt(e)),(0,Ie.cookieIsNetaceaV3Format)(i)?(0,Ie.checkNetaceaCookieV3)(i,t):await this.checkMitataCookie(i,t,this.config.secretKey??"")}async buildMitataCookie(e,t,i,n,a){const r=[i,t??this.generateUserId(),await this.hash(`${e}|${String(i)}`,n),a].join(we.COOKIEDELIMITER);return`${await this.hash(r,n)}${we.COOKIEDELIMITER}${r}`}async checkMitataCookie(e,t,i){const n=function(e){const t=e.match(Ce);if(null===t)return;const[,i,n,a,r,o,s,c,u]=t;return{signature:i,expiry:n,userId:a,ipHash:r,mitigationType:o,match:s,mitigate:c,captcha:u}}(e);if(void 0===n)return(0,Ie.defaultInvalidResponse)();const a=Math.floor(Date.now()/1e3),r=parseInt(n.expiry)<a,o=["1","3","5"].includes(n.captcha),s="3"===n.mitigate,c=o||s,u=await this.hash(`${t}|${n.expiry}`,i)===n.ipHash,h=[n.expiry,n.userId,n.ipHash,n.mitigationType].join(we.COOKIEDELIMITER);return{mitata:n,requiresReissue:r||!u,isExpired:r,shouldExpire:c,isSameIP:u,isPrimaryHashValid:await this.hash(h,i)===n.signature,match:n.match,mitigate:n.mitigate,captcha:n.captcha,issueReason:Se.NetaceaCookieV3IssueReason.NO_SESSION}}generateUserId(e=16){const t=new Uint16Array(e-1);this.getRandomValues(t);return`c${Array.from(t).map((e=>ve[e%ve.length])).join("")}`}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.NetaceaCookieV3IssueReason=e.COOKIEDELIMITER=e.netaceaCookieV3OptionalKeyMap=e.netaceaCookieV3KeyMap=e.AbstractCookieFactory=e.defaultInvalidResponse=e.objectIsNetaceaCookieV3=e.cookieIsNetaceaV3Format=e.matchNetaceaCookieV3=e.checkNetaceaCookieV3=e.createNetaceaCookieV3=void 0;var t=fe;Object.defineProperty(e,"createNetaceaCookieV3",{enumerable:!0,get:function(){return t.createNetaceaCookieV3}}),Object.defineProperty(e,"checkNetaceaCookieV3",{enumerable:!0,get:function(){return t.checkNetaceaCookieV3}}),Object.defineProperty(e,"matchNetaceaCookieV3",{enumerable:!0,get:function(){return t.matchNetaceaCookieV3}}),Object.defineProperty(e,"cookieIsNetaceaV3Format",{enumerable:!0,get:function(){return t.cookieIsNetaceaV3Format}}),Object.defineProperty(e,"objectIsNetaceaCookieV3",{enumerable:!0,get:function(){return t.objectIsNetaceaCookieV3}}),Object.defineProperty(e,"defaultInvalidResponse",{enumerable:!0,get:function(){return t.defaultInvalidResponse}});var i=me;Object.defineProperty(e,"AbstractCookieFactory",{enumerable:!0,get:function(){return i.AbstractCookieFactory}});var n=pe;Object.defineProperty(e,"netaceaCookieV3KeyMap",{enumerable:!0,get:function(){return n.netaceaCookieV3KeyMap}}),Object.defineProperty(e,"netaceaCookieV3OptionalKeyMap",{enumerable:!0,get:function(){return n.netaceaCookieV3OptionalKeyMap}}),Object.defineProperty(e,"COOKIEDELIMITER",{enumerable:!0,get:function(){return n.COOKIEDELIMITER}});var a=ue;Object.defineProperty(e,"NetaceaCookieV3IssueReason",{enumerable:!0,get:function(){return a.NetaceaCookieV3IssueReason}})}(he);var be={};Object.defineProperty(be,"__esModule",{value:!0}),be.validateRedirectLocation=void 0,be.validateRedirectLocation=function(e){if(""!==(e=e??""))try{return new URL(e).toString()}catch{if(/^https?:\/\//i.test(e))return;return e.startsWith("/")?e:`/${e}`}};var Ee={},ke={};function Ae(e,t){for(const i of Object.keys(e)){if("cookie"!==i&&"Cookie"!==i)continue;const n=e[i]??"",a=_e("string"==typeof n?n:n.join("; "),t);if(void 0!==a)return a}}function Ne(e,t){const i=[];for(const n of Object.keys(e)){if("cookie"!==n&&"Cookie"!==n)continue;const a=e[n]??"",r="string"==typeof a?a:a.join("; ");i.push(...Re(r,t))}return i}function _e(e,t){const i=t+"=";return e.split(";").map((e=>e.trimStart())).find((e=>e.startsWith(i)))}function Re(e,t){const i=t+"=";return e.split(";").map((e=>e.trimStart())).filter((e=>e.startsWith(i)))}Object.defineProperty(ke,"__esModule",{value:!0}),ke.findAllInCookieString=ke.findFirstInCookieString=ke.findAllInHeaders=ke.findFirstInHeaders=ke.findOnlyValueInHeaders=ke.findAllValuesInHeaders=ke.findFirstValueInHeaders=void 0,ke.findFirstValueInHeaders=function(e,t){const i=Ae(e,t);if(void 0!==i)return i.slice(t.length+1)},ke.findAllValuesInHeaders=function(e,t){return Ne(e,t).map((e=>e.slice(t.length+1)))},ke.findOnlyValueInHeaders=function(e,t){const i=Ne(e,t);if(i.length>1)throw new Error(`Found more than one cookie with name ${t}`);return i[0]?.slice(t.length+1)},ke.findFirstInHeaders=Ae,ke.findAllInHeaders=Ne,ke.findFirstInCookieString=_e,ke.findAllInCookieString=Re;var Oe={};function Te(e){return"set-cookie"===e||"Set-Cookie"===e}function Pe(e,t){const i=t+"=";return e.startsWith(i)}function xe(e,t){if(!Pe(e,t))throw new Error(`Cookie '${t}' not found in '${e}'`);return e.slice(t.length+1).split(";")[0]}function Le(e,t){const i=e[t]??[];return"string"==typeof i?[i]:i}function Be(e,t){for(const i of Object.keys(e)){if(!Te(i))continue;const n=Me(Le(e,i),t);if(void 0!==n)return n}}function Me(e,t){return e.map((e=>e.trimStart())).find((e=>Pe(e,t)))}function Ve(e,t){const i=[];for(const n of Object.keys(e)){if(!Te(n))continue;const a=Le(e,n);i.push(...Ue(a,t))}return i}function Ue(e,t){return e.map((e=>e.trimStart())).filter((e=>Pe(e,t)))}Object.defineProperty(Oe,"__esModule",{value:!0}),Oe.findAllInSetCookieStrings=Oe.findAllInHeaders=Oe.findValueInSetCookieStrings=Oe.findFirstInSetCookieStrings=Oe.findFirstInHeaders=Oe.findOnlyValueInHeaders=Oe.findFirstValueInHeaders=Oe.parseValueFromString=void 0,Oe.parseValueFromString=xe,Oe.findFirstValueInHeaders=function(e,t){const i=Be(e,t);return void 0!==i?xe(i,t):void 0},Oe.findOnlyValueInHeaders=function(e,t){const i=Ve(e,t);if(i.length>1)throw new Error(`Found more than one set-cookie with name ${t}`);return void 0!==i[0]?xe(i[0],t):void 0},Oe.findFirstInHeaders=Be,Oe.findFirstInSetCookieStrings=Me,Oe.findValueInSetCookieStrings=function(e,t){const i=Me(e,t);if(void 0!==i)return xe(i,t)},Oe.findAllInHeaders=Ve,Oe.findAllInSetCookieStrings=Ue;var Ke=_&&_.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),je=_&&_.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),He=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&Ke(t,e,i);return je(t,e),t};Object.defineProperty(Ee,"__esModule",{value:!0}),Ee.setCookie=Ee.cookie=void 0,Ee.cookie=He(ke),Ee.setCookie=He(Oe);var De={},$e={},Fe={};Object.defineProperty(Fe,"__esModule",{value:!0}),Fe.KINESIS_URL=Fe.API_VERSION=Fe.REGION=Fe.PAYLOAD_TYPE=Fe.STATE=void 0,Fe.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},Fe.PAYLOAD_TYPE="string",Fe.REGION="eu-west-1",Fe.API_VERSION="2013-12-02",Fe.KINESIS_URL="https://kinesis.eu-west-1.amazonaws.com";var qe={};Object.defineProperty(qe,"__esModule",{value:!0}),qe.headersToRecord=qe.increaseBatchSize=qe.handleFailedLogs=qe.batchArrayForKinesis=qe.sleep=void 0,qe.sleep=async function(e){await new Promise((t=>{setTimeout(t,e)}))},qe.batchArrayForKinesis=function(e,t,i){const n=[];for(let a=0;a<e.length;a+=t){const r=e.slice(a,a+t);n.push({Data:i.from(JSON.stringify(r)).toString("base64"),PartitionKey:Date.now().toString()})}return n},qe.handleFailedLogs=function(e,t,i){const n=2*i,a=[...e,...t],r=a.length-n;return r>0&&(console.error(`Netacea Error :: failed to send ${r} log(s) to Kinesis ingest.`),a.splice(0,r)),a},qe.increaseBatchSize=function(e,t){return e!==t?Math.min(t,2*e):e},qe.headersToRecord=function(e){const t={};return e.forEach(((e,i)=>{t[i]=e})),t},Object.defineProperty($e,"__esModule",{value:!0}),$e.WebStandardKinesis=void 0;const ze=Fe,Ge=qe;$e.WebStandardKinesis=class{constructor({deps:e,kinesisIngestArgs:t}){if(this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.deps=e,void 0===t.kinesisAccessKey)throw new Error("kinesisAccessKey is required for kinesis ingest");if(void 0===t.kinesisSecretKey)throw new Error("kinesisSecretKey is required for kinesis ingest");this.kinesisStreamName=t.kinesisStreamName,this.kinesisAccessKey=t.kinesisAccessKey,this.kinesisSecretKey=t.kinesisSecretKey,this.maxAwaitTimePerIngestCallMs=t.maxAwaitTimePerIngestCallMs,void 0!==t.maxLogAgeSeconds&&t.maxLogAgeSeconds<this.maxLogAgeSeconds&&t.maxLogAgeSeconds>0&&(this.maxLogAgeSeconds=t.maxLogAgeSeconds),void 0!==t.logBatchSize&&(this.maxLogBatchSize=t.logBatchSize),this.logBatchSize=!0===t.rampUpBatchSize?1:this.maxLogBatchSize}async putToKinesis(){if(0===this.logCache.length)return;const e=[...this.logCache];this.logCache=[];try{const t=new this.deps.AwsClient({accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey}),i=await this.signRequest(t,{streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},e,this.logBatchSize);await this.deps.makeRequest({headers:(0,Ge.headersToRecord)(i.headers),host:ze.KINESIS_URL,method:"POST",path:"/",body:i.body}),this.logBatchSize=(0,Ge.increaseBatchSize)(this.logBatchSize,this.maxLogBatchSize)}catch(t){this.logCache=(0,Ge.handleFailedLogs)(this.logCache,e,this.maxLogBatchSize)}}async ingest(e){if(this.logCache.push(e),this.logCache.length>=this.logBatchSize){const e=[];e.push(this.putToKinesis()),void 0!==this.maxAwaitTimePerIngestCallMs&&e.push((0,Ge.sleep)(this.maxAwaitTimePerIngestCallMs)),await Promise.race(e)}else if(!this.intervalSet){this.intervalSet=!0;const e=(0,Ge.sleep)(1e3*this.maxLogAgeSeconds).then((async()=>{await this.putToKinesis(),this.intervalSet=!1})).catch((()=>{}));void 0===this.maxAwaitTimePerIngestCallMs&&await e}}async signRequest(e,t,i,n){const a={Records:(0,Ge.batchArrayForKinesis)(i,n,this.deps.Buffer),PartitionKey:Date.now().toString(),StreamName:t.streamName};return await e.sign(ze.KINESIS_URL,{body:JSON.stringify(a),method:"POST",headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"}})}};var Xe={};Object.defineProperty(Xe,"__esModule",{value:!0}),Xe.Kinesis=void 0;const We=Fe,Je=qe;Xe.Kinesis=class{constructor({deps:e,kinesisIngestArgs:t}){this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.deps=e,this.kinesisStreamName=t.kinesisStreamName,this.kinesisAccessKey=t.kinesisAccessKey,this.kinesisSecretKey=t.kinesisSecretKey,this.maxAwaitTimePerIngestCallMs=t.maxAwaitTimePerIngestCallMs,void 0!==t.maxLogAgeSeconds&&t.maxLogAgeSeconds<this.maxLogAgeSeconds&&t.maxLogAgeSeconds>0&&(this.maxLogAgeSeconds=t.maxLogAgeSeconds),void 0!==t.logBatchSize&&(this.maxLogBatchSize=t.logBatchSize),this.logBatchSize=!0===t.rampUpBatchSize?1:this.maxLogBatchSize}async putToKinesis(){if(0===this.logCache.length)return;const e=[...this.logCache];this.logCache=[];try{const t=this.signRequest({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},e,this.logBatchSize);if("POST"!==t.method)throw new Error(`Unexpected method. Expected POST but got ${t.method}`);await this.deps.makeRequest({headers:t.headers??{},host:`https://${t.hostname}`,method:t.method,path:t.path??"/",body:t.body}),this.logBatchSize=(0,Je.increaseBatchSize)(this.logBatchSize,this.maxLogBatchSize)}catch(t){this.logCache=(0,Je.handleFailedLogs)(this.logCache,e,this.maxLogBatchSize)}}async ingest(e){if(this.logCache.push(e),this.logCache.length>=this.logBatchSize){const e=[];e.push(this.putToKinesis()),void 0!==this.maxAwaitTimePerIngestCallMs&&e.push((0,Je.sleep)(this.maxAwaitTimePerIngestCallMs)),await Promise.race(e)}else if(!this.intervalSet){this.intervalSet=!0;const e=(0,Je.sleep)(1e3*this.maxLogAgeSeconds).then((async()=>{await this.putToKinesis(),this.intervalSet=!1})).catch((()=>{}));void 0===this.maxAwaitTimePerIngestCallMs&&await e}}signRequest(e,t,i){const{accessKeyId:n,secretAccessKey:a}=e,r={Records:(0,Je.batchArrayForKinesis)(t,i,this.deps.Buffer),PartitionKey:Date.now().toString(),StreamName:e.streamName};return this.deps.aws4.sign({service:"kinesis",body:JSON.stringify(r),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:We.REGION},{accessKeyId:n,secretAccessKey:a})}},function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Kinesis=e.WebStandardKinesis=void 0;var t=$e;Object.defineProperty(e,"WebStandardKinesis",{enumerable:!0,get:function(){return t.WebStandardKinesis}});var i=Xe;Object.defineProperty(e,"Kinesis",{enumerable:!0,get:function(){return i.Kinesis}})}(De);var Qe={};function Ye(e,t){let i=null;if("number"==typeof e)i=e;else if("string"==typeof e){const t=parseFloat(e);isNaN(t)||(i=t)}if(null===i){if("number"!=typeof t.defaultValue)return t.defaultValue;i=t.defaultValue}return void 0!==t.minValue&&(i=Math.max(t.minValue,i)),void 0!==t.maxValue&&(i=Math.min(t.maxValue,i)),i}Object.defineProperty(Qe,"__esModule",{value:!0}),Qe.parseHttpHeaderName=Qe.stringOrDefault=Qe.parseIntOrDefault=Qe.parseNumberOrDefault=void 0,Qe.parseNumberOrDefault=Ye,Qe.parseIntOrDefault=function(e,t){const i=Ye(e,t);return"number"==typeof i?Math.floor(i):i},Qe.stringOrDefault=function(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t},Qe.parseHttpHeaderName=function(e){if("string"!=typeof e)return;return/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(e)?e:void 0};var Ze={};Object.defineProperty(Ze,"__esModule",{value:!0}),Ze.searchParamsFromRecord=void 0,Ze.searchParamsFromRecord=function(e){const t=new URLSearchParams;for(const[i,n]of Object.entries(e))t.append(i,n);return t};var et={},tt={};Object.defineProperty(tt,"__esModule",{value:!0}),tt.JweFactory=void 0;tt.JweFactory=class{constructor(e){this.jose=e}async encrypt(e,t,i="A128CBC-HS256"){const n=this.jose.base64url.decode(t),a=(new TextEncoder).encode(e);return await new this.jose.CompactEncrypt(a).setProtectedHeader({alg:"dir",enc:i}).encrypt(n)}async decrypt(e,t){const i=this.jose.base64url.decode(t),{plaintext:n}=await this.jose.compactDecrypt(e,i,{keyManagementAlgorithms:["dir"],contentEncryptionAlgorithms:["A256GCM","A128CBC-HS256"]});return(new TextDecoder).decode(n)}static isJweEncrypted(e){return 5===e.split(".").length&&e.includes("..")}};var it=_&&_.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),nt=_&&_.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),at=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&it(t,e,i);return nt(t,e),t};Object.defineProperty(et,"__esModule",{value:!0}),et.jwe=void 0,et.jwe=at(tt);var rt,ot={};var st={};Object.defineProperty(st,"__esModule",{value:!0}),st.ProtectorApiResponseView=st.AbstractProtectorApiResponseView=void 0;const ct=Qe;class ut{get redirectHost(){return this.readHeader("x-netacea-redirect-host")?.[0]}get redirectLocation(){return this.readHeader("x-netacea-redirect-location")?.[0]}get redirectStatus(){return this.readHeader("x-netacea-redirect-status")?.[0]}get redirectStatusCode(){const e=this.readHeader("x-netacea-redirect-status")?.[0];if(void 0===e)return;const t=(0,ct.parseIntOrDefault)(e,{defaultValue:0,minValue:0,maxValue:Number.MAX_SAFE_INTEGER});return t>=300&&t<400?t:void 0}get eventId(){return this.readHeader("x-netacea-event-id")?.[0]}get sessionCookieMaxAge(){return(0,ct.parseIntOrDefault)(this.readHeader("x-netacea-mitata-expiry")?.[0],{defaultValue:86400,minValue:0,maxValue:Number.MAX_SAFE_INTEGER})}get captchaCookieMaxAge(){const e=this.readHeader("x-netacea-mitatacaptcha-expiry")?.[0];return(0,ct.parseIntOrDefault)(e,{defaultValue:86400,minValue:0,maxValue:Number.MAX_SAFE_INTEGER})}getProtectorCodes(e){return{match:this.readHeader("x-netacea-match")?.[0]??e?.match??"0",mitigate:this.readHeader("x-netacea-mitigate")?.[0]??e?.mitigate??"0",captcha:this.readHeader("x-netacea-captcha")?.[0]??e?.captcha??"0"}}getMonetisationRedirectLocation(e,t){const i=this.redirectLocation;if(void 0!==i)return i;const n=this.redirectHost;if(void 0!==n){const i=new URL(`https://${n}`);return i.pathname=e,i.search=t,i.toString()}}getMonetisationRedirect(e,t){const i=this.getMonetisationRedirectLocation(e,t);if(void 0!==i)return{location:i,statusCode:this.redirectStatusCode??303}}async getCaptchaJson(e,t){const i=await this.getBody();let n=this.eventId;if(void 0===n&&"string"==typeof i){n=function(e){if(null==e||"object"!=typeof e)throw new Error("Response body is not a valid object!");const{trackingId:t}=e;if("string"!=typeof t||0===t.length)throw new Error("Response body does not contain a valid trackingId!");return t}(JSON.parse(i))}if(void 0===n)throw new Error("Could not resolve Tracking ID for captcha event.");return function(e,t,i){const n=`${e}?trackingId=${i}`,a=void 0!==t?`https://${t}${n}`:void 0;return JSON.stringify({captchaRelativeURL:n,captchaAbsoluteURL:a})}(e,t,n)}}st.AbstractProtectorApiResponseView=ut;var ht;function ft(){return ht||(ht=1,function(e){var t=_&&_.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),i=_&&_.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=_&&_.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&t(n,e,a);return i(n,e),n},a=_&&_.__exportStar||function(e,i){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(i,n)||t(i,e,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.graphql=e.webcrypto=e.url=e.parsing=e.ingest=e.headers=e.configValidation=e.cookie=e.NetaceaCookieV3IssueReason=void 0;var r=ue;Object.defineProperty(e,"NetaceaCookieV3IssueReason",{enumerable:!0,get:function(){return r.NetaceaCookieV3IssueReason}}),e.cookie=n(he),e.configValidation=n(be),e.headers=n(Ee),e.ingest=n(De),e.parsing=n(Qe),e.url=n(Ze),e.webcrypto=n(et),e.graphql=n(function(){if(rt)return ot;rt=1,Object.defineProperty(ot,"__esModule",{value:!0}),ot.truncateLongFields=ot.parseGraphQl=ot.parseGraphQlRequestBody=ot.getGraphQLParserConfig=void 0;const e=ft();function t(e,t){const i=e.parserRegex;return t.match(i)?.groups??{}}function i(e,t){const i=e.maxValueLength;for(const e of Object.keys(t)){const r=t[e];t[e]=(a=i,(n=r).length<=a?n:n.slice(0,a)+"…")}var n,a;return t}return ot.getGraphQLParserConfig=function(t){const i={includePaths:[],maxParsableBytes:e.parsing.parseIntOrDefault(t?.maxParsableBytes,{defaultValue:1e6,minValue:1e3}),maxValueLength:e.parsing.parseIntOrDefault(t?.maxValueLength,{defaultValue:256,minValue:8}),parserRegex:/^\s*(?<OpType>query|mutation|subscription)\s+(?<OpName>[_A-Za-z][_0-9A-Za-z]+)?/};if(Array.isArray(t?.includePaths))for(const e of t.includePaths)"string"==typeof e&&i.includePaths.push(e);try{if(t?.parserRegex instanceof RegExp)i.parserRegex=t?.parserRegex;else if("object"==typeof t?.parserRegex){const{regex:e,flags:n}=t?.parserRegex;"string"==typeof e&&(i.parserRegex=new RegExp(e,n))}}catch{}return i},ot.parseGraphQlRequestBody=function(e,n){if(""===n)throw new Error("Netacea Error: Empty GraphQL body received");const a=JSON.parse(n);if("object"!=typeof a)throw new Error("Netacea Error: Invalid GraphQL JSON");const r={...t(e,a?.query??"")},o=(a?.operationName??"").trim();return""!==o&&(r.OpName=o),i(e,r)},ot.parseGraphQl=t,ot.truncateLongFields=i,ot}()),a(st,e)}(ce)),ce}st.ProtectorApiResponseView=class extends ut{constructor(e){super(),this.response=e}get status(){return this.response.status}async getBody(){return void 0===this._body&&(this._body=await this.response.clone().text()??""),this._body}readHeader(e){if("set-cookie"===(e=e.toLowerCase()))return this.response.headers.getSetCookie();const t=this.response.headers.get(e)??void 0;return void 0!==t?[t]:[]}};var pt=ft();function dt(e){const t={},{netaceaSettingsMap:i}=Y;return decodeURIComponent(e).split("&").map((e=>e.split("="))).forEach((([e,n])=>{if(void 0!==n&&e in i){const a=parseInt(n,10);t[i[e]]=isNaN(a)?void 0:a}})),Object.entries(t).reduce(((e,[t,i])=>(void 0!==i&&(e[t]=i),e)),{})}function lt(e){const t={};if(pt.cookie.objectIsNetaceaCookieV3(e)){const{netaceaSettingsMap:i}=Y;for(const n in i){const a=e[i[n]];void 0!==a&&(t[n]=a)}}return t}async function gt(e,t,i,n,a){const r=new te,s=[];for(const e in Q)void 0===i[e]&&s.push(e);return s.length>0&&r.setQuery("getSettings",s.join(",")),void 0!==n.trackingId&&r.setQuery("trackingId",n.trackingId),r.setQuery("netaceaHeaders","User-Agent, Request-ID"),await async function(e,t,i,n,a,r,o,s){const{userId:c,clientIP:u,host:h}=i,{mitigationServiceUrl:f,timeout:p}=t;if(void 0===f)throw new Error("Mitigation Service URL is not defined!");const d=function(e,t){const{apiKey:i,userId:n,userAgent:a,captchaCookie:r,clientIP:o,captchaSiteKey:s,captchaSecretKey:c,accept:u,requestId:h}=t,f={"X-Netacea-API-Key":i,"X-Netacea-Client-IP":o,"X-Netacea-User-Agent":R.Buffer.from(a).toString("base64"),cookie:ae({_mitatacaptcha:r}),"X-Netacea-Request-Id":h};void 0!==n&&(f["X-Netacea-UserId"]=n);void 0!==s&&void 0!==c&&(f["X-Netacea-Captcha-Site-Key"]=s,f["X-Netacea-Captcha-Secret-Key"]=c);e.captchaContentNegotiation&&void 0!==e.netaceaCaptchaPath&&(f["X-Netacea-Captcha-Content-Type"]=re(u));return f}(t,i),l="application/json"===d["X-Netacea-Captcha-Content-Type"],g={host:f,path:n,headers:d,method:a,timeout:p},y=await ne(e,0,g);l&&void 0!==t.netaceaCaptchaPath&&void 0!==h&&(y.body=oe(y.body,h,t.netaceaCaptchaPath));let m={};void 0!==y.headers["x-netacea-settings"]&&(m=dt(y.headers["x-netacea-settings"]));return await ee(e,t,s,y,c,u,r,{...o,...m})}(e,t,n,`/captcha${r.buildQueryString()}`,"GET",o.CAPTCHA_GET,i,a)}async function yt(e,t,i,n){i=mt(i);const a=`${n}=`;for(const o of i){const i=o.split(";")[0].trimStart();if(i.startsWith(a)){const o=i.slice(a.length);if(t.encryptedCookieNames.includes(n)&&(5===(r=o).split(".").length&&r.includes("..")))try{return await(e.cachedEncryption?.decrypt(o))}catch(e){return}return o}}var r}function mt(e){return null==e?[]:"string"==typeof e?e.split(";"):e}function St(e,t,i=""){const n=e.getHeader(t)?.[0]?.trim();return n??i}function It(e,t,i=""){return e.getVariable(t)??i}async function wt(e,t,i){return await e.cookieFactory.retrieveCookieInfo(t,i)}function vt(e,t){const i=e.split("&");for(const e of i){const[i,n]=e.split("=");if(i===t)return n}}function Ct(e,t,i){const{netaceaBlockedResponseStatus:n,netaceaCaptchaResponseStatus:a}=e;let r;return r=Number("block"===t?n:a),(o=r)>=200&&o<600&&!Number.isNaN(o)&&3===o.toString().length?r:i;var o}function bt(e,t){const i=t.getVariable(e.protoMitataVariableName);if(void 0!==i&&""!==i)try{return JSON.parse(i)}catch{return}}async function Et(e,t,i,n){const a=C(i.path,i.method)?function(e,t){const i=e.getHeader("x-netacea-client-ip")?.[0];if(null==i||""===i)throw new Error("Cannot build proto-mitata without Client IP");const n=e.getHeader("x-netacea-userid")?.[0]??"";let a={};const r=e.getHeader("x-netacea-settings")?.[0];return void 0!==r&&(a=JSON.parse(r)),{clientIP:i,userId:""!==n?n:H(),match:t.getHeader("x-netacea-match")?.[0]??"0",mitigate:t.getHeader("x-netacea-mitigate")?.[0]??"0",captcha:t.getHeader("x-netacea-captcha")?.[0]??"0",mitataMaxAge:(s="x-netacea-mitata-expiry",c=86400,Number(t.getHeader(s)?.[0]??c)),netaceaSettings:a,issueReason:o.CAPTCHA_POST};var s,c}(i,n):bt(t,i);if(void 0!==a){const i=t.netaceaCookieName??"_mitata",r=await async function(e,t,{clientIP:i,userId:n,match:a,mitigate:r,captcha:s,netaceaSettings:c,issueReason:u}){const h=t.netaceaCookieExpirySeconds,f=["1","3","5"].includes(s)||"3"===r||"5"===r?-60:h;return await e.cookieFactory.createCookieValue({clientIP:i,userId:n,match:a,mitigate:r,captcha:s,gracePeriod:f,cookieId:H(),issueReason:u??o.NO_SESSION,checkAllPostRequests:c.checkAllPostRequests})}(e,t,{clientIP:a.clientIP,userId:a.userId,match:a.match,mitigate:a.mitigate,captcha:a.captcha,netaceaSettings:a.netaceaSettings,issueReason:a.issueReason??o.NO_SESSION}),s=p.cookie.netaceaSession.createNetaceaSetCookieString({cookieName:i,cookieValue:r,otherAttributes:t.netaceaCookieAttributes});n.addHeader("set-cookie",s)}}async function kt(e,t,i,n){const a=n.getHeader("set-cookie")??void 0;if(n.removeHeader("set-cookie"),200===n.status){const r=F.captcha,o=n.getHeader(r)?.[0]??"";String(o)!==String(X.checkpointPost)&&(await Et(e,t,i,n),await async function(e,t,i,n){const a=n?.find((e=>e.startsWith("_mitatacaptcha=")))?.split(/; ?/)[0];if(void 0===a)return;const r=t.netaceaCaptchaCookieName??"_mitatacaptcha",o=a.indexOf("=");if(o>=0){let n=a.slice(o+1);const s=t.encryptedCookieNames.includes(r);void 0!==e.cachedEncryption&&s&&(n=await e.cachedEncryption.encrypt(n));const c=p.cookie.netaceaSession.createNetaceaCaptchaSetCookieString({cookieName:r,cookieValue:n,otherAttributes:t.netaceaCaptchaCookieAttributes});i.addHeader("set-cookie",c)}}(e,t,n,a)),o===String(X.checkpointPost)?n.status=202:function(e){const t=String(X.captchaPass),i=String(X.checkpointPass);return![t,i].includes(e)}(o)&&(n.status=403)}}function At(e){return R.Buffer.from(e.replace(/-/g,"+").replace(/_/g,"/"),"base64")}function Nt(e,t){if("string"==typeof e&&void 0===t)throw new Error("Encoding should be provided to convert strings.");return function(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}(("string"==typeof e?R.Buffer.from(e,t):R.Buffer.from(e)).toString("base64"))}const _t=128,Rt=Nt(JSON.stringify({alg:"dir",enc:"A128CBC-HS256"}),"utf-8"),Ot=(new k).encode(Rt);async function Tt(e){return await E.subtle.importKey("raw",e,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async function Pt({plaintext:e,secret:t,ivBase64Url:i}){const n=At(t),a=n.subarray(16),r=n.subarray(0,16),o=await Tt(a),s=void 0!==i?At(i):function(){const e=new Uint8Array(16);return E.getRandomValues(e),e}(),c=(new k).encode(e),u=await async function(e,t,i){const n=await E.subtle.encrypt({name:"AES-CBC",length:_t,iv:e},t,i);return new Uint8Array(n)}(s,o,c),h=new Uint8Array(s),f=Bt(Ot,h,u),p=await Lt(f,r);return[Rt,"",Nt(s),Nt(u),Nt(p)].join(".")}async function xt({jwe:e,secret:t}){const i=At(t),n=i.subarray(16),a=i.subarray(0,16),{header:r,iv:o,payload:s,mac:c}=function(e){const t=e.split(".");if(5!==t.length)throw new Error(`JWE should have 5 parts, got ${t.length}`);const[i,n,a,r,o]=t;return{header:i,key:n,iv:a,payload:r,mac:o}}(e);if(r!==Rt)throw new Error("Incorrect JWE header");const u=At(o),h=new Uint8Array(At(s)),f=Bt((new k).encode(r),u,h);if(Nt(await Lt(f,a))!==c)throw new Error("MAC does not match JWE data");const p=await Tt(n),d=await async function(e,t,i){const n=await E.subtle.decrypt({name:"AES-CBC",length:_t,iv:e},t,i);return new Uint8Array(n)}(u,p,h);return(new A).decode(d)}async function Lt(e,t){return(await N(e,t)).slice(0,16)}function Bt(e,t,i){return function(e){const t=e.reduce(((e,{length:t})=>e+t),0),i=new Uint8Array(t);let n=0;return e.forEach((e=>{i.set(e,n),n+=e.length})),i}([e,t,i,Ut(e.length<<3)])}const Mt=2**32;function Vt(e,t,i){if(t<0||t>=Mt)throw new RangeError(`value must be >= 0 and <= ${Mt-1}. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,255&t],i)}function Ut(e){const t=Math.floor(e/Mt),i=e%Mt,n=new Uint8Array(8);return Vt(n,t,0),Vt(n,i,4),n}class Kt{constructor(e){this.maxSize=e,this.cachedItems=[]}getCacheSize(){return this.cachedItems.length}delete(e){this.cachedItems=this.cachedItems.filter((t=>t.key!==e))}add(e,t){this.delete(e),this.cachedItems.push({key:e,value:t}),this.cachedItems.length>this.maxSize&&this.cachedItems.shift()}get(e){return this.cachedItems.find((t=>t.key===e))}}class jt{constructor(e){this.encryptionKey=e.encryptionKey,this.cache=new Kt(e.cacheMaxSize??5)}getCacheSize(){return this.cache.getCacheSize()}async memoizeFn(e,t){const i=this.cache.get(e);if(void 0!==i)return i.value;const n=await t();return this.cache.add(e,n),n}async encrypt(e){const t=`encrypt::${e}`;return await this.memoizeFn(t,(async()=>await Pt({plaintext:e,secret:this.encryptionKey})))}async decrypt(e){const t=`encrypt::${e}`;return await this.memoizeFn(t,(async()=>await xt({jwe:e,secret:this.encryptionKey})))}}function Ht(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,function({ip:e,userAgent:t,status:i,method:n,path:a,protocol:r,referer:o,bytesSent:s,requestTime:c,mitataCookie:u,sessionStatus:h,integrationType:f,integrationVersion:p}){const d=(new Date).toUTCString();return{Request:`${n} ${a} ${r}`,TimeLocal:d,RealIp:e,UserAgent:t,Status:i,RequestTime:c?.toString(),BytesSent:s?.toString(),Referer:""===o?"-":o,NetaceaUserIdCookie:u??"",NetaceaMitigationApplied:h??"",IntegrationType:f??"",IntegrationVersion:p??""}}(e)}async function Dt(e,t,i){const n=Ht(i);if(t.ingestType!==a.KINESIS){const i={"X-Netacea-API-Key":t.apiKey??"","content-type":"application/json"},a=await async function(e,t,i,n){return await ne(e,0,{host:t.ingestServiceUrl,method:"POST",path:"/",headers:i,body:JSON.stringify(n),timeout:t.timeout})}(e,t,i,n);if(200!==a.status)throw Z.fromResponse(a)}}function $t(e,t,i,n,a,o){const s="unknown";a||("2"===n?n="4":"3"===n?n="5":"b"===n?n="d":"c"===n&&(n="e")),o&&(n="6");let c=q[t]??s+"_";c+=z[i]??s;let u=W[i];if("0"!==n){c+=","+(G[n]??s);const e=J[n];void 0!==e&&(u=e)}return e.mitigationType===r.INJECT&&(u=$.none),{sessionStatus:c,mitigation:u,parts:{match:t,mitigate:i,captcha:n}}}function Ft(e){return pt.cookie.cookieIsNetaceaV3Format(e)?pt.cookie.matchNetaceaCookieV3(e):function(e){if(void 0===e)return;const t=e.match(j);if(null!=t){const[,e,i,n,a,r,o,s,c]=t;return{signature:e,expiry:i,userId:n,ipHash:a,mitigationType:r,match:o,mitigate:s,captcha:c}}}(e)}var qt,zt="@netacea/akamai",Gt="6.7.1";async function Xt(e,t,i,n){t.ingestType===a.HTTP&&await async function(e,t,i,n){const a=t.netaceaCookieName??"_mitata",r=n.getHeader("set-cookie")??[],o=0!==r.length?r?.join("; "):St(i,"cookie");let s=await yt(e,t,o,a)??"";if(void 0===s||""===s){const n=St(i,"cookie");s=await yt(e,t,n,a)??""}const{match:c,mitigate:u,captcha:h}=Ft(s)??{match:"0",mitigate:"0",captcha:"0"},{sessionStatus:f}=$t(t,c,u,h,C(i.path,i.method),b(i.path,i.method,t.netaceaCheckpointSignalPath)),p=C(i.path,i.method)&&500===n.status;try{Dt(e,t,{bytesSent:St(n,"content-length","0"),ip:It(i,"PMUSER_CLIENT_IP",""),method:i.method,path:i.url,protocol:St(i,"protocol","HTTP/1.1"),referer:St(i,"referer",""),requestTime:"0",sessionStatus:p?"error_open":f,status:String(n.status),userAgent:St(i,"user-agent","-"),mitataCookie:s,integrationType:zt.replace("@netacea/",""),integrationVersion:Gt})}catch(t){e.logger.error(t)}}(e,t,i,n)}async function Wt(e,t,i,n,a,r){try{const o=void 0!==i?bt(i,t):void 0,s=o?.userId??n?.userId??"",c=void 0!==r?r.sessionStatus:function(e,t,i,n){if(void 0===t)return"error_open";const a=n?.match??i?.match??"0",r=n?.mitigate??i?.mitigate??"0";let o=n?.captcha??i?.captcha??"0";(function(e){if(!C(e.path,e.method))return!1;const t=e.getHeader("Content-Type")?.[0]??"";return"application/json"===t})(e)&&(o=String(X.checkpointPost));const{sessionStatus:s}=$t(t,a,r,o,C(e.path,e.method),b(e.path,e.method,t.netaceaCheckpointSignalPath));return s}(t,i,n,o),{sessionReason:u,sessionStartTime:h,mitigationStatusCode:f}=e.getState(),p=[s,c,Gt,a?.headerFingerprint??"",a?.cookieFingerprint??"",u??"",h??"",i?.mitigationType??"",f??"",t.getVariable("PMUSER_NETACEA_REQUEST_ID")??"",Jt(e,"logging_failure")].join(";");t.setVariable("PMUSER_NETACEA_DS2_CUSTOM_FIELD",p)}catch{}}function Jt(e,t){try{const t=e.flush();return R.Buffer.from(t).toString("base64")}catch{return t}}function Qt(e,t,i){e.setState({sessionReason:t,sessionStartTime:i??Math.floor(Date.now()/1e3)})}function Yt(e,t){t=t??e.query,e.route({origin:"mitigations",path:e.path,query:t})}function Zt(e,t){const i=(new te).setQuery("headerFP",t.headerFingerprint),n=[];for(const t in Q)void 0===e[t]&&n.push(t);return n.length>0&&i.setQuery("getSettings",n.join(",")),i}!function(e){e[e.NO_SESSION=0]="NO_SESSION",e[e.NEW_SESSION=1]="NEW_SESSION",e[e.EXISTING_SESSION=2]="EXISTING_SESSION",e[e.RENEW_SESSION=3]="RENEW_SESSION"}(qt||(qt={}));const{mitigationTypes:ei}=Y,ti=[ei.block,ei.captcha,ei.captchaPass];async function ii(e,t,i,n,a){const{netaceaCookieInfo:r,clientIp:o,netaceaSession:s}=i;let c={status:-1,match:(u=r).match,mitigate:u.mitigate,captcha:u.captcha,mitataMaxAge:86400,netaceaSettings:{},responseNetaceaCookie:void 0,responseNetaceaCaptchaCookie:void 0};var u;if(void 0===t.secretKey)throw new Error("Secret key is required to mitigate");if(void 0!==i.netaceaCookieRequiredReissueReason){c=await async function(e,t,i,n,a,r){if(void 0===t.apiKey)throw new Error("An API Key is Required to call the protector API.");const o={"X-Netacea-API-Key":t.apiKey,"X-Netacea-Client-IP":i.clientIp,"X-Netacea-User-Agent":R.Buffer.from(i.userAgent).toString("base64"),cookie:ae({_mitatacaptcha:i.netaceaSession.captchaToken}),"X-Netacea-Request-Id":i.requestId};void 0!==i.netaceaSession.userId&&(o["X-Netacea-UserId"]=i.netaceaSession.userId),void 0!==t.captchaSiteKey&&void 0!==t.captchaSecretKey&&(o["X-Netacea-Captcha-Site-Key"]=t.captchaSiteKey,o["X-Netacea-Captcha-Secret-Key"]=t.captchaSecretKey),t.captchaContentNegotiation&&void 0!==t.netaceaCaptchaPath&&(o["X-Netacea-Captcha-Content-Type"]=re(n));const s=Zt(r,i.fingerprints);s.setQuery("netaceaHeaders","User-Agent, Request-ID");const c="application/json"===o["X-Netacea-Captcha-Content-Type"],u=await ne(e,0,{host:t.mitigationServiceUrl,path:"/"+s.buildQueryString(),headers:o,method:"GET",timeout:t.timeout});var h,f;h=e.logger,f=u.status,h.setState({mitigationStatusCode:f}),c&&void 0!==t.netaceaCaptchaPath&&(u.body=oe(u.body,a,t.netaceaCaptchaPath));let p={};return void 0!==u.headers["x-netacea-settings"]&&(p=dt(u.headers["x-netacea-settings"])),await ee(e,t,void 0,u,i.netaceaSession.userId,i.clientIp,i.netaceaCookieRequiredReissueReason,{...r,...p})}(e,t,i,n,a,i.netaceaSettings),c.responseNetaceaCookie=await D(o,s.userId,c.match,c.mitigate,c.captcha,i.netaceaCookieRequiredReissueReason,c.netaceaSettings,c.mitataMaxAge);const u=void 0===r.mitata?qt.NEW_SESSION:qt.RENEW_SESSION;Qt(e.logger,u)}else{const t=r.mitata;if(void 0!==t){const i=function(e){return pt.cookie.objectIsNetaceaCookieV3(e)?e.issueTimestamp:Number.parseInt(e.expiry,10)-60}(t);Qt(e.logger,qt.EXISTING_SESSION,i)}}const h=$t(t,c.match,c.mitigate,c.captcha,!1,!1),f={statusCode:void 0,body:c.body,apiCallStatus:c.status,responseNetaceaCookie:c?.responseNetaceaCookie,responseNetaceaCaptchaCookie:void 0,sessionStatus:h.sessionStatus,mitigation:h.mitigation,mitigated:ti.includes(h.mitigation),bestMitigation:h,eventId:c.eventId,redirectLocation:void 0};if("5"===h.parts.mitigate){if(f.statusCode=303,void 0!==c.redirectStatus){const e=Number(c.redirectStatus);e>300&&e<400&&(f.statusCode=e)}if(void 0!==c.redirectLocation)f.redirectLocation=c.redirectLocation;else if(void 0!==c.redirectHost){f.redirectLocation=`https://${c.redirectHost}${i.path}`;let e=i.query;""!==e&&(e.startsWith("?")||(e=`?${e}`),f.redirectLocation+=e)}void 0===f.redirectLocation&&(f.statusCode=402)}return f}function ni(e){return{apiCallStatus:0,responseNetaceaCookie:e,responseNetaceaCaptchaCookie:void 0,sessionStatus:"",mitigation:"000",mitigated:!1,bestMitigation:{sessionStatus:"",mitigation:"",parts:{match:"0",mitigate:"0",captcha:"0"}},eventId:void 0,statusCode:0,redirectLocation:void 0}}async function ai(e){return{sessionStatus:"",response:{headers:{},body:void 0,status:0,statusText:"",mitigation:"000"},bestAction:ni(await D(s,e,"0","0","0",o.NO_SESSION,void 0,86400))}}async function ri(e,t,i,n){try{switch(t.mitigationType){case r.MITIGATE:return await async function(e,t,i,n){const a=St(i,"accept","text/html"),r=await ii(e,t,n,a,i.host),o={};let s,c,u;return r.mitigated&&(c=403,"captcha"===r.mitigation?(o["content-type"]="text/html; charset=UTF-8",s=r.body):s="Forbidden"),void 0!==r.statusCode&&(c=r.statusCode),void 0!==c&&c>300&&c<400&&void 0!==r.redirectLocation&&(o.Location=r.redirectLocation),"flag"===r.mitigation&&(u={"x-netacea-match":r.bestMitigation.parts.match.toString(),"x-netacea-mitigate":r.bestMitigation.parts.mitigate.toString(),"x-netacea-captcha":r.bestMitigation.parts.captcha.toString()}),{response:{body:s,status:c,statusText:c?.toString(),headers:o,mitigation:r.mitigation},sessionStatus:r.sessionStatus,bestAction:r,injectHeaders:u}}(e,t,i,n);case r.INJECT:return await async function(e,t,i,n){const a=St(i,"accept","text/html"),r=await ii(e,t,n,a,i.host),o={"x-netacea-match":r.bestMitigation.parts.match.toString(),"x-netacea-mitigate":r.bestMitigation.parts.mitigate.toString(),"x-netacea-captcha":r.bestMitigation.parts.captcha.toString()};return void 0!==r.eventId&&(o["x-netacea-event-id"]=r.eventId),{injectHeaders:o,sessionStatus:r.sessionStatus,response:{headers:{}},bestAction:r}}(e,t,i,n);case r.INGEST:return await async function(e,t,i){if(void 0===t.secretKey)throw new Error("Secret key is required for ingest");const n=St(i,"cookie"),a=await yt(e,t,n,t.netaceaCookieName??"_mitata"),r=await wt(e,a,s);return r.isPrimaryHashValid?r.requiresReissue?await ai(r.mitata?.userId):{sessionStatus:"",response:void 0,bestAction:ni()}:await ai(void 0)}(e,t,i);default:throw new Error(`Netacea Error: Mitigation type ${t.mitigationType} not recognised`)}}catch(i){e.logger.error(i);const n={injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"}},a=t.mitigationType===r.INJECT;return await Promise.resolve({sessionStatus:"error_open",response:void 0,bestAction:void 0,...a?n:{}})}}async function oi(e,t,i,n){let r={};if(void 0!==i?.bestAction?.responseNetaceaCookie){const e=i?.bestAction?.responseNetaceaCookie;void 0!==e&&n.setVariable(t.protoMitataVariableName,JSON.stringify(e))}if(void 0!==i&&"injectHeaders"in i){r=i.injectHeaders??{}}let o={};t.ingestType===a.ORIGIN&&(o=await async function(e,t,i){const n=St(i,"cookie"),a=Ft(await yt(e,t,n,t.netaceaCookieName)??""),r=bt(t,i),{match:o,mitigate:s,captcha:c,userId:u}=r??a??{match:"0",mitigate:"0",captcha:"0",userId:""},{sessionStatus:h}=$t(t,o,s,c,C(i.path,i.method),!1);return{"X-Netacea-UserId":u,"X-Netacea-BC-Type":h,"X-Netacea-Integration-Type":zt.replace("@netacea/",""),"X-Netacea-Integration-Version":Gt}}(e,t,n));for(const[e,t]of Object.entries({...r,...o}))n.addHeader(e,t)}async function si(e){const t=function(e){return Object.keys(e).filter((e=>{const t=e.toLowerCase();return"cookie"!==t&&"referer"!==t&&!t.startsWith("x-netacea-")})).join(",")}(e);return await ci(t)}async function ci(e){let t="";try{t=await async function(e,t){const i=(new k).encode(t),n=await E.subtle.digest(e,i);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}("SHA-256",e)}catch(e){t=""}return t}async function ui(e){const t=e.getHeaders(),i=await si(t),n=function(e,t){const i=e.getHeader(t);return null==i?[]:i}(e,"cookie").map((e=>e.split(/; ?/).map((e=>e.split("=")[0])))).flat(),a=await async function(e){const t=e.join(",");return await ci(t)}(n);return[""===i?i:`h_${i.substring(1,15)}`,""===a?a:`c_${a.substring(1,15)}`]}async function hi(e,t,i){const a=It(i,"PMUSER_CLIENT_IP"),r=St(i,"user-agent"),s=void 0!==t.altCookieHeaderName?St(i,t.altCookieHeaderName):void 0,c=void 0!==s&&""!==s?s:St(i,"cookie");void 0!==t.altCookieHeaderName&&void 0!==s&&""!==s&&i.setVariable("NETACEA_USES_ALT_COOKIE_HEADER","true");const u=await yt(e,t,c,t.netaceaCookieName),h=await wt(e,u,a),f=function(e,t,i,n,a){if(void 0!==n&&!a.isPrimaryHashValid)return o.INVALID_SESSION;if(void 0===n)return function(e,t){for(const i of mt(e))if(i.startsWith(`${t}=`))return!0;return!1}(t,i)?o.INVALID_SESSION:o.NO_SESSION;if(a.isExpired)return o.EXPIRED_SESSION;if(!a.isSameIP)return o.IP_CHANGE;const r="post"===e.method.toLowerCase(),s=lt(a.mitata);if(r&&1===s.checkAllPostRequests)return o.FORCED_REVALIDATION}(i,c,t.netaceaCookieName,u,h),p=lt(h.mitata),d=await yt(e,t,c,t.netaceaCaptchaCookieName),[l,g]=await ui(i);let y=i.getVariable("PMUSER_NETACEA_REQUEST_ID")??"";if(""===y)try{y=n(),i.setVariable("PMUSER_NETACEA_REQUEST_ID",y)}catch(t){y="",e.logger.error("REQ_ID error")}return{path:i.path,query:i.query,clientIp:a,userAgent:r,method:i.method,netaceaCookieInfo:h,netaceaCookieRequiredReissueReason:f,netaceaSession:{userId:h.mitata?.userId,captchaToken:d,match:h.match,mitigate:h.mitigate,captcha:h.captcha},fingerprints:{headerFingerprint:l,cookieFingerprint:g},requestId:y,netaceaSettings:p}}class fi extends pt.cookie.AbstractCookieFactory{constructor(e,t){super(void 0===t?{...e,cookieEncryptionKey:void 0}:e),this.cachedEncryption=t}async encrypt(e){if(void 0===this.cachedEncryption)throw new Error("AkamaiCookieFactory.encrypt called without a configured encryption adapter");return await this.cachedEncryption.encrypt(e)}async decrypt(e){if(void 0===this.cachedEncryption)throw new Error("AkamaiCookieFactory.decrypt called without a configured encryption adapter");return await this.cachedEncryption.decrypt(e)}async hash(e,t){const i=await N(R.Buffer.from(e),t),n=R.Buffer.from(i).toString("hex");return R.Buffer.from(n).toString("base64")}getRandomValues(e){return crypto.getRandomValues(e)}isEncrypted(e){return 5===e.split(".").length}}class pi{constructor(e){this.errorLog="",this.options=e,this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}getState(){return Object.assign({},this.state)}setState(e){for(const t in this.state)void 0!==e[t]&&(this.state[t]=e[t])}appendErrorLog(e){this.errorLog=function(e,t,i){if(t-e.length<=2)return e;const n=i.trim().slice(0,t).replace(/\n/g,"\\n");return(""===e?n:e+"\n"+n).slice(0,t)}(this.errorLog,this.options.maxErrorLogLength,e)}error(e){try{if(this.options.maxErrorLogLength<=0||null==e||""===e)return;if("string"==typeof e)this.appendErrorLog(e);else{const t=function(e){if(void 0!==e.stack)return e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack;return e.message}(e);this.appendErrorLog(t)}}catch{}}flush(){try{return this.errorLog}finally{this.state={errorLog:"",mitigationStatusCode:void 0,sessionReason:void 0,sessionStartTime:void 0}}}}class di{constructor(t){this.configLoader=new y(t),this.runtimeDeps={httpRequest:e}}initDeps(e,t){const i=void 0===t.cookieEncryptionKey?void 0:new jt({encryptionKey:t.cookieEncryptionKey}),n=new fi({cookieEncryptionKey:t.cookieEncryptionKey,secretKey:t.secretKey,expirySeconds:t.netaceaCookieExpirySeconds},t.ingestType!==a.HTTP?i:void 0);return{...this.runtimeDeps,config:t,logger:e,cachedEncryption:i,cookieFactory:n}}async requestHandler(e){const t=new pi({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(e)});let i,n,a;try{n=this.configLoader.loadConfig(e);const u=this.initDeps(t,n);if(a=await hi(u,n,e),void 0!==a.netaceaCookieRequiredReissueReason&&e.setVariable("PMUSER_NETACEA_ISSUE_REASON",a.netaceaCookieRequiredReissueReason),r=e.path,s=e.method,void 0!==(c=n.netaceaCaptchaPath)&&c.length>0&&r===c&&"get"===s.toLowerCase())await async function(e,t,i,n){const a=St(i,"cookie"),r=await yt(e,t,a,t.netaceaCookieName),s=await yt(e,t,a,t.netaceaCaptchaCookieName),c=It(i,"PMUSER_CLIENT_IP"),u=St(i,"user-agent"),h=await wt(e,r,c),f=Ct(t,"captcha",403),p=await gt(e,t,n.netaceaSettings,{apiKey:t.apiKey??"",clientIP:c,userAgent:u,userId:h.mitata?.userId,captchaCookie:s,trackingId:vt(i.query,"trackingId"),captchaSiteKey:t.captchaSiteKey,captchaSecretKey:t.captchaSecretKey,accept:St(i,"accept","text/html"),host:i.host,requestId:n.requestId},{match:"0",mitigate:"0",captcha:"1"}),d=p.responseNetaceaCookie;void 0!==d&&(void 0===n.netaceaCookieRequiredReissueReason?d.issueReason=o.CAPTCHA_GET:d.issueReason=n.netaceaCookieRequiredReissueReason,i.setVariable(t.protoMitataVariableName,JSON.stringify(d)));const l={};void 0!==t.netaceaCaptchaHeaderKey&&void 0!==t.netaceaCaptchaHeaderValue&&(l[t.netaceaCaptchaHeaderKey]=t.netaceaCaptchaHeaderValue),i.respondWith(f,l,p.body??"")}(u,n,e,a);else if(C(e.path,e.method))await async function(e,t,i,n){if(void 0===t.apiKey)throw new Error("An API Key is Required to Verify Captcha");const a=i.getVariable("PMUSER_CLIENT_IP")??"";i.setHeader("x-netacea-api-key",t.apiKey),i.setHeader("x-netacea-client-ip",a);const r=St(i,"cookie"),o=await yt(e,t,r,t.netaceaCookieName)??"";let s="";const c=await wt(e,o,a);if(pt.cookie.objectIsNetaceaCookieV3(c.mitata)){const e={checkAllPostRequests:c.mitata.checkAllPostRequests};i.setHeader("x-netacea-settings",JSON.stringify(e))}c.isPrimaryHashValid&&(s=c.mitata?.userId??""),i.setHeader("x-netacea-userid",s),i.setHeader("x-netacea-user-agent",R.Buffer.from(n.userAgent).toString("base64")),i.setHeader("x-netacea-request-id",n.requestId);const u=Zt(n.netaceaSettings,n.fingerprints);u.setQuery("netaceaHeaders","User-Agent, Request-ID"),Yt(i,u.buildQueryString())}(u,n,e,a);else if(w(e.path,e.method,n.useCaptchaRelAssets))Yt(e);else if(b(e.path,e.method,n.netaceaCheckpointSignalPath))await async function(e){e.respondWith(200,{},"")}(e);else{const t=function(e,t){if(void 0===t.netaceaBlockedResponseRedirectLocation)return!1;if(t.netaceaBlockedResponseRedirectLocation.startsWith("/"))return t.netaceaBlockedResponseRedirectLocation===e.path;try{const i=new URL(t.netaceaBlockedResponseRedirectLocation);return i.host===e.host&&i.pathname===e.path}catch{return!1}}(e,n);t||(i=await async function(e,t,i,n){const a=await ri(e,t,i,n);if(void 0===a)throw new Error('Mitigation Service response "mitResult" was undefined.');const r=a.response?.mitigation,o=[$.block,$.captcha,$.monetise].includes(r??"");if(void 0!==r&&o){let e=Ct(t,r,a.response?.status??403);const n={};for(const e of Object.keys(a.response?.headers??{})){const t=a.response?.headers[e];void 0!==e&&void 0!==t&&(n[e]=t)}const o=t.netaceaBlockedResponseRedirectLocation;"block"===r&&void 0!==o&&function(e){if("GET"!==e.method?.toUpperCase())return!1;const t=e.getHeader("sec-fetch-mode")??[];return!(t.length>0&&!t.includes("navigate"))&&(e.getHeader("accept")?.map((e=>e.split(/, ?/))).flat()??[]).includes("text/html")}(i)&&(e=303,n.Location=o);const s=a.bestAction?.responseNetaceaCookie;void 0!==s&&i.setVariable(t.protoMitataVariableName,JSON.stringify(s));const c=a.response?.body??"";(function(e){return e.includes("captchaRelativeURL")&&e.includes("captchaAbsoluteURL")})(c)&&(n["content-type"]="application/json"),"captcha"===r&&(void 0===n["content-type"]&&(n["content-type"]="text/html"),void 0!==t.netaceaCaptchaHeaderKey&&void 0!==t.netaceaCaptchaHeaderValue&&(n[t.netaceaCaptchaHeaderKey]=t.netaceaCaptchaHeaderValue)),i.respondWith(e,n,c)}else await oi(e,t,a,i);return a}(u,n,e,a))}}catch(e){t.error(e)}finally{try{await Wt(t,e,n,a?.netaceaSession,a?.fingerprints,i)}catch{}}var r,s,c}async responseHandler(e,t){const i=new pi({maxErrorLogLength:this.configLoader.getMaxErrorLogLength(e)});try{const n=this.configLoader.loadConfig(e),a=this.initDeps(i,n);if(C(e.path,e.method))await kt(a,n,e,t);else if(v(e.path,e.method)&&!w(e.path,e.method,n.useCaptchaRelAssets)){const i=e.getVariable("PMUSER_NETACEA_ISSUE_REASON")!==o.NO_SESSION,r=e.getVariable("NETACEA_USES_ALT_COOKIE_HEADER");i&&"true"!==r&&await Et(a,n,e,t)}else if(!w(e.path,e.method,n.useCaptchaRelAssets)){"true"!==e.getVariable("NETACEA_USES_ALT_COOKIE_HEADER")&&await Et(a,n,e,t)}!function(e){e.removeHeader("x-netacea-match"),e.removeHeader("x-netacea-mitigate"),e.removeHeader("x-netacea-captcha"),e.removeHeader("x-netacea-mitata-expiry"),e.removeHeader("x-netacea-mitata-value"),e.removeHeader("x-netacea-mitatacaptcha-expiry"),e.removeHeader("x-netacea-mitatacaptcha-value"),e.removeHeader("x-netacea-event-id"),e.removeHeader("x-netacea-settings")}(t),await Xt(a,n,e,t)}catch(e){i.error(e)}}}export{r as NetaceaMitigationType,di as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/akamai",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.1",
|
|
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.
|
|
17
|
+
"@netacea/netaceaintegrationbase": "^2.6.1",
|
|
18
18
|
"buffer": "^6.0.3",
|
|
19
19
|
"uuid": "^11.1.0"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "ad1a80dafbba7cc92b98ec5ddaf6bd6d98c99411"
|
|
25
25
|
}
|