@netacea/f5 5.6.4 → 5.7.0
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 +90 -7
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ declare enum NetaceaMitigationType {
|
|
|
47
47
|
*/
|
|
48
48
|
INGEST = "INGEST"
|
|
49
49
|
}
|
|
50
|
+
declare enum NetaceaCookieV3IssueReason$1 {
|
|
51
|
+
CAPTCHA_GET = "captcha_get",
|
|
52
|
+
CAPTCHA_POST = "captcha_post",
|
|
53
|
+
EXPIRED_SESSION = "expired_session",
|
|
54
|
+
FORCED_REVALIDATION = "forced_revalidation",
|
|
55
|
+
INVALID_SESSION = "invalid_session",
|
|
56
|
+
IP_CHANGE = "ip_change",
|
|
57
|
+
NO_SESSION = "no_session"
|
|
58
|
+
}
|
|
50
59
|
|
|
51
60
|
interface KinesisIngestConfigArgs$1 {
|
|
52
61
|
kinesisStreamName: string;
|
|
@@ -344,6 +353,84 @@ interface ProcessMitigateRequestArgs {
|
|
|
344
353
|
getBodyFn: () => Promise<string>;
|
|
345
354
|
}
|
|
346
355
|
|
|
356
|
+
interface NetaceaCookieV3OptionalFeatures {
|
|
357
|
+
checkAllPostRequests: number | undefined;
|
|
358
|
+
}
|
|
359
|
+
interface NetaceaCookieV3 extends NetaceaCookieV3OptionalFeatures {
|
|
360
|
+
clientIP: string;
|
|
361
|
+
userId: string;
|
|
362
|
+
cookieId: string;
|
|
363
|
+
gracePeriod: number;
|
|
364
|
+
match: string;
|
|
365
|
+
mitigate: string;
|
|
366
|
+
captcha: string;
|
|
367
|
+
issueTimestamp: number;
|
|
368
|
+
issueReason: string;
|
|
369
|
+
}
|
|
370
|
+
interface MitataCookie {
|
|
371
|
+
signature: string;
|
|
372
|
+
expiry: string;
|
|
373
|
+
userId: string;
|
|
374
|
+
ipHash: string;
|
|
375
|
+
mitigationType: string;
|
|
376
|
+
match: string;
|
|
377
|
+
mitigate: string;
|
|
378
|
+
captcha: string;
|
|
379
|
+
}
|
|
380
|
+
declare enum NetaceaCookieV3IssueReason {
|
|
381
|
+
CAPTCHA_GET = "captcha_get",
|
|
382
|
+
CAPTCHA_POST = "captcha_post",
|
|
383
|
+
EXPIRED_SESSION = "expired_session",
|
|
384
|
+
FORCED_REVALIDATION = "forced_revalidation",
|
|
385
|
+
INVALID_SESSION = "invalid_session",
|
|
386
|
+
IP_CHANGE = "ip_change",
|
|
387
|
+
NO_SESSION = "no_session",
|
|
388
|
+
UNKNOWN = "unknown"
|
|
389
|
+
}
|
|
390
|
+
interface CheckCookieResponse {
|
|
391
|
+
mitata: MitataCookie | NetaceaCookieV3 | undefined;
|
|
392
|
+
requiresReissue: boolean;
|
|
393
|
+
isExpired: boolean;
|
|
394
|
+
shouldExpire: boolean;
|
|
395
|
+
isSameIP: boolean;
|
|
396
|
+
isPrimaryHashValid: boolean;
|
|
397
|
+
match: string;
|
|
398
|
+
mitigate: string;
|
|
399
|
+
captcha: string;
|
|
400
|
+
issueReason: NetaceaCookieV3IssueReason;
|
|
401
|
+
}
|
|
402
|
+
interface CreateCookieOptions {
|
|
403
|
+
clientIP: string;
|
|
404
|
+
userId?: string;
|
|
405
|
+
match: string;
|
|
406
|
+
mitigate: string;
|
|
407
|
+
captcha: string;
|
|
408
|
+
gracePeriod: number;
|
|
409
|
+
cookieId: string;
|
|
410
|
+
issueReason?: NetaceaCookieV3IssueReason;
|
|
411
|
+
checkAllPostRequests?: number;
|
|
412
|
+
}
|
|
413
|
+
interface CookieFactoryConfig {
|
|
414
|
+
cookieEncryptionKey?: string;
|
|
415
|
+
secretKey?: string;
|
|
416
|
+
expirySeconds: number;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
declare abstract class AbstractCookieFactory {
|
|
420
|
+
protected readonly config: Readonly<CookieFactoryConfig>;
|
|
421
|
+
constructor(config: Readonly<CookieFactoryConfig>);
|
|
422
|
+
protected abstract encrypt(plaintext: string): Promise<string>;
|
|
423
|
+
protected abstract decrypt(ciphertext: string): Promise<string>;
|
|
424
|
+
protected abstract hash(data: string, key: string): Promise<string>;
|
|
425
|
+
protected abstract getRandomValues(buffer: Uint16Array): Uint16Array;
|
|
426
|
+
protected isEncrypted(value: string): boolean;
|
|
427
|
+
createCookieValue(options: CreateCookieOptions): Promise<string>;
|
|
428
|
+
retrieveCookieInfo(cookie: string | undefined, clientIP: string): Promise<CheckCookieResponse>;
|
|
429
|
+
private buildMitataCookie;
|
|
430
|
+
private checkMitataCookie;
|
|
431
|
+
private generateUserId;
|
|
432
|
+
}
|
|
433
|
+
|
|
347
434
|
type KinesisMakeRequest = (args: {
|
|
348
435
|
headers: Record<string, string>;
|
|
349
436
|
method: 'POST' | 'GET';
|
|
@@ -515,6 +602,7 @@ declare abstract class NetaceaBase<RequestArgs = unknown, Response = unknown> im
|
|
|
515
602
|
protected readonly netaceaCaptchaCookieName: string;
|
|
516
603
|
protected readonly netaceaCookieAttributes: string;
|
|
517
604
|
protected readonly netaceaCaptchaCookieAttributes: string;
|
|
605
|
+
protected cookieFactory?: AbstractCookieFactory;
|
|
518
606
|
protected abstract makeRequest(args: MakeRequestArgs): Promise<MakeRequestResponse>;
|
|
519
607
|
protected abstract mitigate(args: RequestArgs): Promise<MitigateResponse<Response>>;
|
|
520
608
|
protected abstract inject(args: RequestArgs): Promise<InjectResponse>;
|
|
@@ -538,7 +626,7 @@ declare abstract class NetaceaBase<RequestArgs = unknown, Response = unknown> im
|
|
|
538
626
|
protected constructWebLog(args: IngestArgs): WebLog;
|
|
539
627
|
protected check(netaceaCookie: string | undefined, clientIP: string, userAgent: string, captchaCookie?: string, headerFingerprint?: string, captchaPageContentType?: string, requestUrl?: string): Promise<F5ComposeResultResponse>;
|
|
540
628
|
private computeMonetisationRedirect;
|
|
541
|
-
protected createMitata(clientIP: string, userId: string | undefined, match: string, mitigate: string, captcha: string, maxAge?: number, expiry?: number | undefined): Promise<string>;
|
|
629
|
+
protected createMitata(clientIP: string, userId: string | undefined, match: string, mitigate: string, captcha: string, maxAge?: number, expiry?: number | undefined, issueReason?: NetaceaCookieV3IssueReason$1): Promise<string>;
|
|
542
630
|
private processCaptcha;
|
|
543
631
|
private getMitataCaptchaFromHeaders;
|
|
544
632
|
private makeCaptchaAPICall;
|
|
@@ -550,7 +638,7 @@ declare abstract class NetaceaBase<RequestArgs = unknown, Response = unknown> im
|
|
|
550
638
|
protected APIError(response: APICallResponse): Error;
|
|
551
639
|
protected isUrlCaptchaPost(url: string, method: string): boolean;
|
|
552
640
|
protected processMitigateRequest(args: ProcessMitigateRequestArgs, headerFingerprint?: string, captchaPageContentType?: string): Promise<F5ComposeResultResponse>;
|
|
553
|
-
protected setIngestOnlyMitataCookie(userId: string | undefined): Promise<NetaceaResponseBase>;
|
|
641
|
+
protected setIngestOnlyMitataCookie(userId: string | undefined, issueReason?: NetaceaCookieV3IssueReason$1): Promise<NetaceaResponseBase>;
|
|
554
642
|
protected processIngest(args: RequestArgs): Promise<NetaceaResponseBase>;
|
|
555
643
|
protected encryptCookieValue(cookieValue: string): Promise<string>;
|
|
556
644
|
protected decryptCookieValue(encryptedCookieValue: string): Promise<string>;
|
|
@@ -578,11 +666,6 @@ declare class F5 extends NetaceaBase<F5MitigateArgs | F5IngestArgs, F5Response>
|
|
|
578
666
|
* Decrypts a JWE-encrypted cookie value if encryption is enabled.
|
|
579
667
|
*/
|
|
580
668
|
protected decryptCookieValue(encryptedCookieValue: string): Promise<string>;
|
|
581
|
-
/**
|
|
582
|
-
* Creates the Netacea session cookie with optional encryption.
|
|
583
|
-
* Overrides base class to encrypt the cookie value before creating the Set-Cookie string.
|
|
584
|
-
*/
|
|
585
|
-
protected createMitata(clientIP: string, userId: string | undefined, match: string, mitigate: string, captcha: string, maxAge?: number, expiry?: number | undefined): Promise<string>;
|
|
586
669
|
private getInjectHeaders;
|
|
587
670
|
registerPolicyHandler(ilx: IlxServer): void;
|
|
588
671
|
private encodeHeadersAsKeyValueList;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t,n,i){return n=a(n),function(t,r){if(r&&("object"==e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(t,r()?Reflect.construct(n,i||[],a(t).constructor):n.apply(t,i))}function r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(r=function(){return!!e})()}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function i(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */i=function(){return r};var t,r={},a=Object.prototype,n=a.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",h=c.toStringTag||"@@toStringTag";function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(t){l=function(e,t,r){return e[t]=r}}function p(e,t,r,a){var n=t&&t.prototype instanceof k?t:k,i=Object.create(n.prototype),c=new _(a||[]);return o(i,"_invoke",{value:N(e,r,c)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=p;var d="suspendedStart",v="suspendedYield",y="executing",m="completed",g={};function k(){}function b(){}function C(){}var x={};l(x,s,(function(){return this}));var S=Object.getPrototypeOf,w=S&&S(S(j([])));w&&w!==a&&n.call(w,s)&&(x=w);var A=C.prototype=k.prototype=Object.create(x);function I(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function E(t,r){function a(i,o,c,s){var u=f(t[i],t,o);if("throw"!==u.type){var h=u.arg,l=h.value;return l&&"object"==e(l)&&n.call(l,"__await")?r.resolve(l.__await).then((function(e){a("next",e,c,s)}),(function(e){a("throw",e,c,s)})):r.resolve(l).then((function(e){h.value=e,c(h)}),(function(e){return a("throw",e,c,s)}))}s(u.arg)}var i;o(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){a(e,t,r,n)}))}return i=i?i.then(n,n):n()}})}function N(e,r,a){var n=d;return function(i,o){if(n===y)throw Error("Generator is already running");if(n===m){if("throw"===i)throw o;return{value:t,done:!0}}for(a.method=i,a.arg=o;;){var c=a.delegate;if(c){var s=P(c,a);if(s){if(s===g)continue;return s}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(n===d)throw n=m,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);n=y;var u=f(e,r,a);if("normal"===u.type){if(n=a.done?m:v,u.arg===g)continue;return{value:u.arg,done:a.done}}"throw"===u.type&&(n=m,a.method="throw",a.arg=u.arg)}}}function P(e,r){var a=r.method,n=e.iterator[a];if(n===t)return r.delegate=null,"throw"===a&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==a&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+a+"' method")),g;var i=f(n,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var o=i.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function j(r){if(r||""===r){var a=r[s];if(a)return a.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function e(){for(;++i<r.length;)if(n.call(r,i))return e.value=r[i],e.done=!1,e;return e.value=t,e.done=!0,e};return o.next=o}}throw new TypeError(e(r)+" is not iterable")}return b.prototype=C,o(A,"constructor",{value:C,configurable:!0}),o(C,"constructor",{value:b,configurable:!0}),b.displayName=l(C,h,"GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,C):(e.__proto__=C,l(e,h,"GeneratorFunction")),e.prototype=Object.create(A),e},r.awrap=function(e){return{__await:e}},I(E.prototype),l(E.prototype,u,(function(){return this})),r.AsyncIterator=E,r.async=function(e,t,a,n,i){void 0===i&&(i=Promise);var o=new E(p(e,t,a,n),i);return r.isGeneratorFunction(t)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},I(A),l(A,h,"Generator"),l(A,s,(function(){return this})),l(A,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var a in t)r.push(a);return r.reverse(),function e(){for(;r.length;){var a=r.pop();if(a in t)return e.value=a,e.done=!1,e}return e.done=!0,e}},r.values=j,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function a(a,n){return c.type="throw",c.arg=e,r.next=a,n&&(r.method="next",r.arg=t),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],c=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var s=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),g},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),g}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var a=r.completion;if("throw"===a.type){var n=a.arg;T(r)}return n}}throw Error("illegal catch attempt")},delegateYield:function(e,r,a){return this.delegate={iterator:j(e),resultName:r,nextLoc:a},"next"===this.method&&(this.arg=t),g}},r}function o(e){return function(e){if(Array.isArray(e))return k(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t,r,a,n,i,o){try{var c=e[i](o),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(a,n)}function s(e){return function(){var t=this,r=arguments;return new Promise((function(a,n){var i=e.apply(t,r);function o(e){c(i,a,n,o,s,"next",e)}function s(e){c(i,a,n,o,s,"throw",e)}o(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,v(a.key),a)}}function l(e,t,r){return t&&h(e.prototype,t),r&&h(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function d(e,t,r){return(t=v(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var a=t[Symbol.toPrimitive];if(void 0!==a){var n=a.call(t,r||"default");if("object"!=e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function y(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=g(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var a=0,n=function(){};return{s:n,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){c=!0,i=e},f:function(){try{o||null==r.return||r.return()}finally{if(c)throw i}}}}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var a,n,i,o,c=[],s=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(a=i.call(r)).done)&&(c.push(a.value),c.length!==t);s=!0);}catch(e){u=!0,n=e}finally{try{if(!s&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw n}}return c}}(e,t)||g(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){if(e){if("string"==typeof e)return k(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?k(e,t):void 0}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);r<t;r++)a[r]=e[r];return a}var b=require("crypto"),C=require("buffer"),x=require("https"),S=require("querystring"),w=require("aws4");function A(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var I,E,N,P=A(b),O=A(x),T=A(S);!function(e){e.ORIGIN="ORIGIN",e.HTTP="HTTP",e.KINESIS="KINESIS",e.NATIVE="NATIVE"}(I||(I={})),function(e){e.MITIGATE="MITIGATE",e.INJECT="INJECT",e.INGEST="INGEST"}(E||(E={})),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"}(N||(N={}));var _=3e3;var j="_/@#/",K={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},M={0:K.none,1:K.block,2:K.none,3:K.block,4:K.none,5:K.block},H={1:K.captcha,2:K.captchaPass,3:K.captcha,4:K.allow,5:K.captcha,6:K.allow,7:K.captcha,a:K.captcha,b:K.captchaPass,c:K.captcha,d:K.allow,e:K.captcha},L=Object.freeze({__proto__:null,COOKIEDELIMITER:j,bestMitigationCaptchaMap:H,bestMitigationMap:M,captchaMap:{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"},captchaStatusCodes:{"":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"},matchMap:{0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},mitigateMap:{0:"",1:"blocked",2:"allow",3:"hardblocked",4:"flagged",5:"monetised"},mitigationTypes:K,netaceaCookieV3KeyMap:{clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},netaceaCookieV3OptionalKeyMap:{checkAllPostRequests:"fCAPR"},netaceaHeaders:{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"},netaceaSettingsMap:{checkAllPostRequests:"checkAllPostRequests"}}),R="ignored",V="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),D=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function B(e){if(void 0!==e){var t=e.match(D);if(null!=t){var r=m(t,9);return{signature:r[1],expiry:r[2],userId:r[3],ipHash:r[4],mitigationType:r[5],match:r[6],mitigate:r[7],captcha:r[8]}}}}function q(e,t,r,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"000";void 0===t&&(t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:V,r=b.randomBytes(e-1),a=Array.from(r).map((function(e){return t[e%t.length]})).join("");return"c".concat(a)}());var i=[r,t,G(e+"|"+String(r),a),n].join(j),o=G(i,a);return"".concat(o).concat(j).concat(i)}function G(e,t){var r=b.createHmac("sha256",t);return r.update(e),C.Buffer.from(r.digest("hex")).toString("base64")}function U(e,t,r){var a={mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0"};if("string"!=typeof e||""===e)return a;var n=B(e);if(void 0!==n){var i=[n.expiry,n.userId,n.ipHash,n.mitigationType].join(j),o=Math.floor(Date.now()/1e3),c=parseInt(n.expiry)<o,s=["1","3","5","a","c","e"].includes(n.captcha),u="3"===n.mitigate,h=s||u,l=G(t+"|"+n.expiry,r),p=n.ipHash===l;return{mitata:n,requiresReissue:c||!p,isExpired:c,shouldExpire:h,isSameIP:p,isPrimaryHashValid:n.signature===G(i,r),match:n.match,mitigate:n.mitigate,captcha:n.captcha,userId:n.userId}}return a}function F(e,t){var r=e.split(";").map((function(e){return e.trim()})).filter((function(e){return e.toLowerCase().startsWith(t.toLowerCase())}))[0];return void 0!==r&&r.length>0?null==r?void 0:r.replace("".concat(t,"="),""):void 0}function z(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof e&&(e=e.join("; ")),""===e?"":X(e.split(";"),t).join("; ")}function X(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])return X(e.reverse()).reverse();var t,r=new Set,a=[],n=y(e);try{for(n.s();!(t=n.n()).done;){var i=t.value;if(""!==(i=i.trimStart()).trim()){var o=i.split("=")[0].toUpperCase();r.has(o)||(r.add(o),a.push(i))}}}catch(e){n.e(e)}finally{n.f()}return a}function J(e){var t,r,a=z([null!==(t=e.otherAttributes)&&void 0!==t?t:"","Max-Age=".concat(null!==(r=e.maxAgeAttribute)&&void 0!==r?r:86400),"Path=/"].join("; "));return"".concat(e.cookieName,"=").concat(e.cookieValue,"; ").concat(a)}var W={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(e,t){var r=e=z(null!=e?e:"",!0),a=t=z(null!=t?t:"",!0);if(void 0!==e&&void 0!==t){var n=F(e,"Domain"),i=F(t,"Domain");void 0!==n&&void 0!==i?a=t.replace(i,n):void 0!==n&&void 0===i?a=t+(""!==t?"; Domain=".concat(n):"Domain=".concat(n)):void 0===n&&void 0!==i&&(r=e+(""!==e?"; Domain=".concat(i):"Domain=".concat(i)))}else if(void 0!==e&&void 0===t){var o=F(e,"Domain");void 0!==o&&(a="Domain=".concat(o))}else if(void 0===e&&void 0!==t){var c=F(t,"Domain");void 0!==c&&(r="Domain=".concat(c))}return{cookieAttributes:""!==r?r:void 0,captchaCookieAttributes:""!==a?a:void 0}},extractAndRemoveCookieAttr:function(e,t){var r=F(e,t);return void 0!==r?{extractedAttribute:r,cookieAttributes:e.replace(/ /g,"").replace("".concat(t,"=").concat(r),"").split(";").filter((function(e){return e.length>0})).join("; ")}:{extractedAttribute:void 0,cookieAttributes:e}},extractCookieAttr:F,removeDuplicateAttrs:z}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(e){var t;return J(f(f({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitatacaptcha"}))},createNetaceaSetCookieString:function(e){var t;return J(f(f({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitata"}))},createSetCookieString:J})}},Y=function(){function e(t,r){u(this,e),this.crypto=t,this.TextEncoder=r}return l(e,[{key:"hashString",value:(r=s(i().mark((function e(t,r){var a,n,c,s,u,h,l=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=(a=l.length>2&&void 0!==l[2]&&l[2])?o(r).sort():o(r),c=(new this.TextEncoder).encode(n.join(",")),e.next=1,this.crypto.subtle.digest(t,c);case 1:return s=e.sent,u=Array.from(new Uint8Array(s)),h=u.map((function(e){return e.toString(16).padStart(2,"0")})).join("").substring(0,12),e.abrupt("return","h"+(a?"s":"")+"_".concat(r.length,"_").concat(h));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"hashHeaders",value:(t=s(i().mark((function t(r){var a,n,o,c=arguments;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a=c.length>1&&void 0!==c[1]&&c[1],0!==(n=e.filterHeaderNames(r)).length){t.next=1;break}return t.abrupt("return","");case 1:return t.prev=1,t.next=2,this.hashString("SHA-256",n,a);case 2:return t.abrupt("return",t.sent);case 3:return t.prev=3,o=t.catch(1),console.error(o),t.abrupt("return","");case 4:case"end":return t.stop()}}),t,this,[[1,3]])}))),function(e){return t.apply(this,arguments)})}],[{key:"filterHeaderNames",value:function(e){return e.filter((function(e){var t=e.toLowerCase();return!["","cookie","referer"].includes(t)&&null===t.match(/^(x-netacea-|cloudfront-)/i)}))}}]);var t,r}();function $(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Z(e){var t=(e+"===".slice(0,(4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/");return Buffer.from(t,"base64")}var Q="eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0";function ee(e,t){var r=b.randomBytes(12),a=b.createCipheriv("aes-256-gcm",t,r),n=Buffer.from(Q,"ascii");a.setAAD(n);var i=a.update(e,"utf8");i=Buffer.concat([i,a.final()]);var o=a.getAuthTag();return[Q,"",$(r),$(i),$(o)].join(".")}function te(e,t){var r=e.split(".");if(5!==r.length)throw new Error("JWE should have 5 parts, got ".concat(r.length));var a=m(r,5),n=a[0],i=a[1],o=a[2],c=a[3],s=a[4];if(n!==Q)throw new Error("Incorrect JWE header");if(""!==i)throw new Error("Expected empty encrypted key for direct encryption");var u=Z(o),h=Z(c),l=Z(s);if(12!==u.length)throw new Error("IV must be ".concat(12," bytes, got ").concat(u.length));if(16!==l.length)throw new Error("Auth tag must be ".concat(16," bytes, got ").concat(l.length));var p=b.createDecipheriv("aes-256-gcm",t,u),f=Buffer.from(n,"ascii");p.setAAD(f),p.setAuthTag(l);var d=p.update(h);return(d=Buffer.concat([d,p.final()])).toString("utf8")}var re={},ae={},ne={},ie={};Object.defineProperty(ie,"__esModule",{value:!0}),ie.API_VERSION=ie.REGION=ie.PAYLOAD_TYPE=ie.STATE=void 0,ie.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},ie.PAYLOAD_TYPE="string",ie.REGION="eu-west-1",ie.API_VERSION="2013-12-02",Object.defineProperty(ne,"__esModule",{value:!0}),ne.signRequest=void 0;var oe=w,ce=ie;function se(e,t){for(var r=[],a=0;a<e.length;a+=t){var n=e.slice(a,a+t);r.push({Data:Buffer.from(JSON.stringify(n)).toString("base64"),PartitionKey:Date.now().toString()})}return r}ne.signRequest=function(e,t,r){var a=e.accessKeyId,n=e.secretAccessKey,i={Records:se(t,r),PartitionKey:Date.now().toString(),StreamName:e.streamName};return oe.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:ce.REGION},{accessKeyId:a,secretAccessKey:n})},Object.defineProperty(ae,"__esModule",{value:!0});var ue=ne;function he(e){return le.apply(this,arguments)}function le(){return(le=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e){setTimeout(e,t)}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var pe=function(){return l((function e(t){var r=t.kinesisStreamName,a=t.kinesisAccessKey,n=t.kinesisSecretKey,i=t.maxLogAgeSeconds,o=t.logBatchSize,c=t.rampUpBatchSize,s=t.maxAwaitTimePerIngestCallMs;u(this,e),this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.kinesisStreamName=r,this.kinesisAccessKey=a,this.kinesisSecretKey=n,this.maxAwaitTimePerIngestCallMs=s,void 0!==i&&i<this.maxLogAgeSeconds&&i>0&&(this.maxLogAgeSeconds=i),void 0!==o&&(this.maxLogBatchSize=o),this.logBatchSize=!0===c?1:this.maxLogBatchSize}),[{key:"putToKinesis",value:(t=s(i().mark((function e(t){var r,a,n,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==this.logCache.length){e.next=1;break}return e.abrupt("return");case 1:return r=o(this.logCache),this.logCache=[],e.prev=2,a=(0,ue.signRequest)({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},r,this.logBatchSize),e.next=3,t({headers:a.headers,host:"https://".concat(a.hostname),method:a.method,path:a.path,body:a.body});case 3:this.logBatchSize!==this.maxLogBatchSize&&(this.logBatchSize=Math.min(this.maxLogBatchSize,2*this.logBatchSize)),e.next=5;break;case 4:e.prev=4,c=e.catch(2),(n=this.logCache).push.apply(n,o(r)),console.error(c);case 5:case"end":return e.stop()}}),e,this,[[2,4]])}))),function(e){return t.apply(this,arguments)})},{key:"ingest",value:(e=s(i().mark((function e(t,r){var a,n,o=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logCache.push(t),!(this.logCache.length>=this.logBatchSize)){e.next=2;break}return(a=[]).push(this.putToKinesis(r)),void 0!==this.maxAwaitTimePerIngestCallMs&&a.push(he(this.maxAwaitTimePerIngestCallMs)),e.next=1,Promise.race(a);case 1:e.next=3;break;case 2:if(this.intervalSet){e.next=3;break}if(this.intervalSet=!0,n=he(1e3*this.maxLogAgeSeconds).then(s(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,o.putToKinesis(r);case 1:o.intervalSet=!1;case 2:case"end":return e.stop()}}),e)})))).catch((function(){})),void 0!==this.maxAwaitTimePerIngestCallMs){e.next=3;break}return e.next=3,n;case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e,t}();ae.default=pe,Object.defineProperty(re,"__esModule",{value:!0});var fe,de=ae,ve=re.default=de.default,ye={subtle:{digest:(fe=s(i().mark((function e(t,r){var a,n,o,c,s;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null!==(a={"SHA-256":"sha256","SHA-1":"sha1","SHA-384":"sha384","SHA-512":"sha512"}[t])&&void 0!==a?a:t.toLowerCase().replace("-",""),o=r instanceof ArrayBuffer?Buffer.from(r):Buffer.from(r.buffer,r.byteOffset,r.byteLength),c=new Uint8Array(o),s=P.createHash(n).update(c).digest(),e.abrupt("return",s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength));case 1:case"end":return e.stop()}}),e)}))),function(e,t){return fe.apply(this,arguments)})}},me=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ge=/^\/[a-zA-Z0-9/]*$/;function ke(e,t,r){return void 0!==r&&""!==r&&(function(e){var t=e,r=t.indexOf("//");if(-1!==r){var a=(t=t.substring(r+2)).indexOf("/");if(-1===a)return"/";t=t.substring(a)}var n=t.indexOf("?");return-1!==n&&(t=t.substring(0,n)),t}(e)===r&&"get"===t.toLowerCase())}function be(e){var t=function(e,t){var r=e.indexOf("?");if(-1!==r)for(var a=e.substring(r+1).split("&"),n=0;n<a.length;n++){var i=a[n].split("=");if(i[0]===t)return void 0!==i[1]?decodeURIComponent(i[1]):void 0}}(e,"trackingId");return void 0!==t&&me.test(t)?t:null}function Ce(e){if(void 0===e)return"text/html";var t=e.toLowerCase(),r=t.includes("text/html")||t.includes("application/html"),a=t.includes("application/json");return!r&&a?"application/json":"text/html"}function xe(e,t,r){if(void 0===e||""===e)return"";var a;try{a=JSON.parse(e)}catch(e){return""}if(!function(e){if(null==e)return!1;var t=e;return void 0!==t.captchaSiteKey&&void 0!==t.trackingId&&void 0!==t.captchaURL}(a))return"";var n=r+"?trackingId="+a.trackingId,i="https://"+t+n;return JSON.stringify({captchaRelativeURL:n,captchaAbsoluteURL:i})}var Se=W.cookie.attributes.configureCookiesDomain,we=W.cookie.netaceaSession,Ae=we.createNetaceaSetCookieString,Ie=we.createNetaceaCaptchaSetCookieString,Ee=function(){return l((function e(t){var r,a,n=t.apiKey,i=t.secretKey,o=t.timeout,c=void 0===o?3e3:o,s=t.mitigationServiceUrl,h=void 0===s?"https://mitigations.netacea.net":s,l=t.ingestServiceUrl,p=void 0===l?"https://ingest.netacea.net":l,v=t.mitigationType,y=void 0===v?E.INGEST:v,m=t.captchaSiteKey,g=t.captchaSecretKey,k=t.ingestType,b=void 0===k?I.HTTP:k,C=t.kinesis,x=t.mitataCookieExpirySeconds,S=t.netaceaCookieExpirySeconds,w=t.netaceaCookieName,A=t.netaceaCaptchaCookieName,N=t.netaceaCookieAttributes,P=t.netaceaCaptchaCookieAttributes;if(u(this,e),d(this,"mitataCookieExpirySeconds",void 0),d(this,"apiKey",void 0),d(this,"secretKey",void 0),d(this,"mitigationServiceUrl",void 0),d(this,"ingestServiceUrl",void 0),d(this,"timeout",void 0),d(this,"captchaSiteKey",void 0),d(this,"captchaSecretKey",void 0),d(this,"ingestType",void 0),d(this,"kinesis",void 0),d(this,"mitigationType",void 0),d(this,"encryptedCookies",[]),d(this,"netaceaCookieName",void 0),d(this,"netaceaCaptchaCookieName",void 0),d(this,"netaceaCookieAttributes",void 0),d(this,"netaceaCaptchaCookieAttributes",void 0),null==n)throw new Error("apiKey is a required parameter");this.apiKey=n,this.secretKey=i,this.mitigationServiceUrl=h,this.ingestServiceUrl=p,this.mitigationType=y,this.ingestType=null!=b?b:I.HTTP,this.ingestType===I.KINESIS&&(void 0===C?console.warn("NETACEA WARN: no kinesis args provided, when ingestType is ".concat(this.ingestType)):this.kinesis=new ve(f(f({},C),{},{apiKey:this.apiKey}))),void 0===m&&void 0===g||(this.captchaSiteKey=m,this.captchaSecretKey=g),this.timeout=function(e){return e<=0?_:e}(c),this.netaceaCookieName=Pe(w,"_mitata"),this.netaceaCaptchaCookieName=Pe(A,"_mitatacaptcha"),this.encryptedCookies=[this.netaceaCookieName,this.netaceaCaptchaCookieName],this.mitataCookieExpirySeconds=function(e,t){return void 0===t?e===E.INGEST?3600:60:t}(y,null!=S?S:x);var O=Se(null!=N?N:"",null!=P?P:"");this.netaceaCookieAttributes=null!==(r=O.cookieAttributes)&&void 0!==r?r:"",this.netaceaCaptchaCookieAttributes=null!==(a=O.captchaCookieAttributes)&&void 0!==a?a:""}),[{key:"runMitigation",value:(x=s(i().mark((function e(t){var r,a,n,o,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=this.mitigationType,e.next=o===E.MITIGATE?1:o===E.INJECT?3:o===E.INGEST?5:7;break;case 1:return e.next=2,this.mitigate(t);case 2:case 4:case 6:return e.abrupt("return",e.sent);case 3:return e.next=4,this.inject(t);case 5:return e.next=6,this.processIngest(t);case 7:throw new Error("Netacea Error: Mitigation type ".concat(this.mitigationType," not recognised"));case 8:e.next=10;break;case 9:return e.prev=9,c=e.catch(0),console.error("Netacea FAILOPEN Error:",c),r=t,a=this.isUrlCaptchaPost(r.url,r.method),n=this.mitigationType===E.MITIGATE,e.abrupt("return",{injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"},sessionStatus:n&&a?"error_open":""});case 10:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e){return x.apply(this,arguments)})},{key:"readCookie",value:(C=s(i().mark((function e(t,r){var a,n,o,c,s,u,h;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=r){e.next=1;break}return e.abrupt("return",void 0);case 1:if("string"!=typeof r){e.next=3;break}return e.next=2,this.readCookie(t,r.split(";"));case 2:return e.abrupt("return",e.sent);case 3:a="".concat(t,"="),n=y(r),e.prev=4,n.s();case 5:if((o=n.n()).done){e.next=11;break}if(c=o.value,!(s=c.split(";")[0].trimStart()).startsWith(a)){e.next=10;break}if(u=s.slice(a.length),!this.encryptedCookies.includes(t)){e.next=9;break}return e.prev=6,e.next=7,this.decryptCookieValue(u);case 7:return e.abrupt("return",e.sent);case 8:return e.prev=8,e.catch(6),e.abrupt("return",void 0);case 9:return e.abrupt("return",u);case 10:e.next=5;break;case 11:e.next=13;break;case 12:e.prev=12,h=e.catch(4),n.e(h);case 13:return e.prev=13,n.f(),e.finish(13);case 14:return e.abrupt("return",void 0);case 15:case"end":return e.stop()}}),e,this,[[4,12,13,14],[6,8]])}))),function(e,t){return C.apply(this,arguments)})},{key:"callIngest",value:(b=s(i().mark((function e(t){var r,a,n,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.constructWebLog(t),this.ingestType!==I.KINESIS){e.next=5;break}if(void 0!==this.kinesis){e.next=1;break}return console.error("Netacea Error: Unable to log as Kinesis has not been defined."),e.abrupt("return");case 1:return e.prev=1,e.next=2,this.kinesis.ingest(f(f({},r),{},{apiKey:this.apiKey}),this.makeRequest.bind(this));case 2:e.next=4;break;case 3:e.prev=3,o=e.catch(1),console.error("NETACEA Error: ",o.message);case 4:e.next=7;break;case 5:return a={"X-Netacea-API-Key":this.apiKey,"content-type":"application/json"},e.next=6,this.makeIngestApiCall(a,r);case 6:if(200===(n=e.sent).status){e.next=7;break}throw this.APIError(n);case 7:case"end":return e.stop()}}),e,this,[[1,3]])}))),function(e){return b.apply(this,arguments)})},{key:"makeIngestApiCall",value:(k=s(i().mark((function e(t,r){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeRequest({host:this.ingestServiceUrl,method:"POST",path:"/",headers:t,body:JSON.stringify(r),timeout:this.timeout});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return k.apply(this,arguments)})},{key:"constructV1WebLog",value:function(e){var t=e.ip,r=e.userAgent,a=e.status,n=e.method,i=e.path,o=e.protocol,c=e.referer,s=e.bytesSent,u=e.requestTime,h=e.mitataCookie,l=e.sessionStatus,p=e.integrationType,f=e.integrationVersion,d=e.headerFingerprint,v=(new Date).toUTCString();return{Request:"".concat(n," ").concat(i," ").concat(o),TimeLocal:v,RealIp:t,UserAgent:r,Status:a,RequestTime:null==u?void 0:u.toString(),BytesSent:null==s?void 0:s.toString(),Referer:""===c?"-":c,NetaceaUserIdCookie:null!=h?h:"",NetaceaMitigationApplied:null!=l?l:"",IntegrationType:null!=p?p:"",IntegrationVersion:null!=f?f:"",HeaderHash:null!=d?d:""}}},{key:"constructWebLog",value:function(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,this.constructV1WebLog(e)}},{key:"check",value:(g=s(i().mark((function e(t,r,a,n,o,c,s){var u,h,l,p,d,v,y,m,g,k,b,C,x;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.secretKey){e.next=1;break}throw new Error("Secret key is required to mitigate");case 1:if((g=U(t,r,this.secretKey)).isPrimaryHashValid&&!g.requiresReissue){e.next=4;break}return e.next=2,this.makeMitigateAPICall(null===(k=g.mitata)||void 0===k?void 0:k.userId,r,a,n,o,c);case 2:return C=e.sent,u=C.status,h=C.match,l=C.mitigate,p=C.captcha,d=C.body,e.next=3,this.createMitata(r,null===(b=g.mitata)||void 0===b?void 0:b.userId,h,l,p,C.mitataMaxAge);case 3:x=e.sent,v=[x],y=C.eventId,"5"===l&&void 0!==s&&(m=this.computeMonetisationRedirect(s,C.redirectHost,C.redirectLocation,C.redirectStatus)),e.next=5;break;case 4:u=-1,h=g.match,l=g.mitigate,p=g.captcha,d=void 0,v=[];case 5:return e.abrupt("return",f(f({},this.composeResult(d,v,u,h,l,p,!1,y)),{},{redirect:m}));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n,i,o){return g.apply(this,arguments)})},{key:"computeMonetisationRedirect",value:function(e,t,r,a){var n=void 0!==a?parseInt(a,10):NaN,i=!isNaN(n)&&n>=300&&n<400?n:303;if(void 0!==r)return{location:r,statusCode:i};if(void 0!==t){var o=e.replace(/^https?:\/\/[^/]+/,"");return{location:"https://".concat(t).concat(""!==o?o:"/"),statusCode:i}}}},{key:"createMitata",value:(m=s(i().mark((function e(t,r,a,n,o){var c,s,u,h,l,p,f,d,v,y=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=y.length>5&&void 0!==y[5]?y[5]:86400,s=y.length>6&&void 0!==y[6]?y[6]:void 0,u=["1","3","5"].includes(o),h="3"===n,l="5"===n,p=u||h||l?-60:this.mitataCookieExpirySeconds,f=null!=s?s:Math.floor(Date.now()/1e3)+p,void 0!==this.secretKey){e.next=1;break}throw new Error("Cannot build cookie without secret key.");case 1:return d=[a,n,o].join(""),v=q(t,r,f,this.secretKey,d),e.abrupt("return",Ae({cookieName:this.netaceaCookieName,cookieValue:v,maxAgeAttribute:String(c),otherAttributes:this.netaceaCookieAttributes}));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return m.apply(this,arguments)})},{key:"processCaptcha",value:(v=s(i().mark((function e(t,r,a,n,o){var c,s,u,h,l,p,f;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeCaptchaAPICall(t,r,a,n,o);case 1:return c=e.sent,s=c.status,u=c.match,h=c.mitigate,l=c.captcha,p=c.body,f=c.setCookie,e.abrupt("return",this.composeResult(p,f,s,u,h,l,!0));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return v.apply(this,arguments)})},{key:"getMitataCaptchaFromHeaders",value:(p=s(i().mark((function e(t){var r,a,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Object.prototype.hasOwnProperty.call(t,L.netaceaHeaders.mitataCaptcha)){e.next=3;break}if(r=t[L.netaceaHeaders.mitataCaptcha],Array.isArray(r)&&(r=r[0]),null!=r&&""!==r){e.next=1;break}return e.abrupt("return",void 0);case 1:return a=parseInt(t[L.netaceaHeaders.mitataCaptchaExpiry]),e.next=2,this.encryptCookieValue(r);case 2:return n=e.sent,e.abrupt("return",Ie({cookieName:this.netaceaCaptchaCookieName,cookieValue:n,maxAgeAttribute:String(isNaN(a)?86400:a),otherAttributes:this.netaceaCaptchaCookieAttributes}));case 3:return e.abrupt("return",void 0);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"makeCaptchaAPICall",value:(h=s(i().mark((function e(t,r,a,n,o){var c,s,u,h;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":a,"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},void 0!==(s=B(t))&&(c["X-Netacea-UserId"]=s.userId),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(c["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,c["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),u={},"string"==typeof o&&""!==o&&(u.headerFP=o),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/AtaVerifyCaptcha",headers:c,method:"POST",body:n,timeout:this.timeout,params:u});case 1:return h=e.sent,e.next=2,this.getApiCallResponseFromResponse(h,null==s?void 0:s.userId,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return h.apply(this,arguments)})},{key:"getApiCallResponseFromResponse",value:(c=s(i().mark((function e(t,r,a){var n,o,c,s,u,h,l,p,f,d,v,y,m,g,k,b,C,x,S,w,A;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(200===t.status){e.next=1;break}throw this.APIError(t);case 1:return d=null!==(n=null===(o=t.headers[L.netaceaHeaders.match])||void 0===o?void 0:o.toString())&&void 0!==n?n:"0",v=null!==(c=null===(s=t.headers[L.netaceaHeaders.mitigate])||void 0===s?void 0:s.toString())&&void 0!==c?c:"0",y=null!==(u=null===(h=t.headers[L.netaceaHeaders.captcha])||void 0===h?void 0:h.toString())&&void 0!==u?u:"0",m=parseInt(t.headers[L.netaceaHeaders.mitataExpiry]),isNaN(m)&&(m=86400),e.next=2,this.createMitata(a,r,d,v,y);case 2:return g=e.sent,e.next=3,this.getMitataCaptchaFromHeaders(t.headers);case 3:return k=e.sent,b=[g,k].filter((function(e){return void 0!==e})),C=t.body,x=t.headers[L.netaceaHeaders.eventId],S=null===(l=t.headers["x-netacea-redirect-host"])||void 0===l?void 0:l.toString(),w=null===(p=t.headers["x-netacea-redirect-location"])||void 0===p?void 0:p.toString(),A=null===(f=t.headers["x-netacea-redirect-status"])||void 0===f?void 0:f.toString(),e.abrupt("return",{status:t.status,match:d,mitigate:v,captcha:y,setCookie:b,body:C,eventId:x,mitataMaxAge:m,redirectHost:S,redirectLocation:w,redirectStatus:A});case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return c.apply(this,arguments)})},{key:"buildCookieHeader",value:function(e){var t="",r="";for(var a in e){var n=e[a];void 0!==n&&(t="".concat(t).concat(r).concat(a,"=").concat(n),r="; ")}return t}},{key:"makeMitigateAPICall",value:(o=s(i().mark((function e(t,r,a,n,o,c){var s,u,h;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":a,cookie:this.buildCookieHeader({_mitatacaptcha:n})},void 0!==t&&(s["X-Netacea-UserId"]=t),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(s["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,s["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),void 0!==c&&(s["X-Netacea-Captcha-Content-Type"]=c),u={},"string"==typeof o&&""!==o&&(u.headerFP=o),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/",headers:s,method:"GET",timeout:this.timeout,params:u});case 1:return h=e.sent,e.next=2,this.getApiCallResponseFromResponse(h,t,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n,i){return o.apply(this,arguments)})},{key:"composeResult",value:function(e,t,r,a,n,i,o,c){var s=this.findBestMitigation(a,n,i,o),u={body:e,apiCallStatus:r,setCookie:t,sessionStatus:s.sessionStatus,mitigation:s.mitigation,mitigated:[L.mitigationTypes.block,L.mitigationTypes.captcha,L.mitigationTypes.captchaPass].includes(s.mitigation)};if(this.mitigationType===E.INJECT){var h={"x-netacea-match":s.parts.match.toString(),"x-netacea-mitigate":s.parts.mitigate.toString(),"x-netacea-captcha":s.parts.captcha.toString()};void 0!==c&&(h["x-netacea-event-id"]=c),u.injectHeaders=h}return u}},{key:"findBestMitigation",value:function(e,t,r,a){var n,i,o="unknown";a||("2"===r?r="4":"3"===r&&(r="5"));var c=null!==(n=L.matchMap[e])&&void 0!==n?n:o+"_";c+=null!==(i=L.mitigateMap[t])&&void 0!==i?i:o;var s=L.bestMitigationMap[t];if("0"!==r){var u;c+=","+(null!==(u=L.captchaMap[r])&&void 0!==u?u:o);var h=L.bestMitigationCaptchaMap[r];void 0!==h&&(s=h)}return this.mitigationType===E.INJECT&&(s=L.mitigationTypes.none),{sessionStatus:c,mitigation:s,parts:{match:e,mitigate:t,captcha:r}}}},{key:"APIError",value:function(e){var 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 Error("Error reaching Netacea API (".concat(t,"), status: ").concat(e.status))}},{key:"isUrlCaptchaPost",value:function(e,t){return e.includes("/AtaVerifyCaptcha")&&"post"===t.toLowerCase()}},{key:"processMitigateRequest",value:(n=s(i().mark((function e(t,r,a){var n,o,c,s,u,h,l;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isUrlCaptchaPost(t.url,t.method)){e.next=2;break}return o=this,c=t.mitata,s=t.clientIp,u=t.userAgent,e.next=1,t.getBodyFn();case 1:h=e.sent,l=r,n=o.processCaptcha.call(o,c,s,u,h,l),e.next=3;break;case 2:n=this.check(t.mitata,t.clientIp,t.userAgent,t.mitataCaptcha,r,a,t.url);case 3:return e.next=4,n;case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"setIngestOnlyMitataCookie",value:(a=s(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.createMitata(R,t,"0","0","0",86400);case 1:return r=e.sent,e.abrupt("return",{sessionStatus:"",setCookie:[r]});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"processIngest",value:(r=s(i().mark((function e(t){var r,a,n,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.secretKey){e.next=1;break}throw new Error("Secret key is required for ingest");case 1:return r=this.getCookieHeader(t),e.next=2,this.readCookie(this.netaceaCookieName,r);case 2:if(a=e.sent,(n=U(a,R,this.secretKey)).isPrimaryHashValid){e.next=4;break}return e.next=3,this.setIngestOnlyMitataCookie(void 0);case 3:case 5:return e.abrupt("return",e.sent);case 4:if(!n.requiresReissue){e.next=6;break}return e.next=5,this.setIngestOnlyMitataCookie(null===(o=n.mitata)||void 0===o?void 0:o.userId);case 6:return e.abrupt("return",{sessionStatus:"",setCookie:[]});case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"encryptCookieValue",value:(t=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"decryptCookieValue",value:(e=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(t){return e.apply(this,arguments)})}]);var e,t,r,a,n,o,c,h,p,v,m,g,k,b,C,x}(),Ne=function(){function e(r){var a,n,i,o,c;u(this,e),d(c=t(this,e,[r]),"httpsAgent",void 0),d(c,"mitataCookieName",void 0),d(c,"mitataCaptchaCookieName",void 0),d(c,"hashGenerator",void 0),d(c,"debugMode",void 0),d(c,"encryptionEnabled",!1),d(c,"encryptionKeyBuffer",void 0),d(c,"mitigationHeaders",["cookie","user-agent","accept","host"]),d(c,"netaceaCaptchaPath",void 0),d(c,"captchaHost",void 0),d(c,"enableCaptchaContentNegotiation",void 0),c.httpsAgent=new O.Agent({timeout:c.timeout,keepAlive:!0,maxSockets:null!==(a=r.maxSockets)&&void 0!==a?a:25}),c.mitataCookieName=null!==(n=r.netaceaCookieName)&&void 0!==n?n:"_mitata",c.mitataCaptchaCookieName=null!==(i=r.netaceaCaptchaCookieName)&&void 0!==i?i:"_mitatacaptcha";var s=function(){return l((function e(){u(this,e)}),[{key:"encode",value:function(e){return new Uint8Array(Buffer.from(e,"utf8"))}}])}();if(c.hashGenerator=new Y(ye,s),c.debugMode=null!==(o=r.debugMode)&&void 0!==o&&o,c.netaceaCaptchaPath=function(e){if(null!=e&&""!==e)return"/"!==e[0]&&(e="/"+e),ge.test(e)?e:void 0}(r.netaceaCaptchaPath),c.captchaHost=r.captchaHost,c.enableCaptchaContentNegotiation=!0===r.enableCaptchaContentNegotiation,void 0!==r.cookieEncryptionKey){var h=function(e){if(null==e||""===e)return{valid:!1,error:"key is empty"};if(!/^[A-Za-z0-9_-]+$/.test(e))return{valid:!1,error:"key contains invalid base64url characters"};var t;try{t=Z(e)}catch(e){return{valid:!1,error:"key is not valid base64url"}}return 32!==t.length?{valid:!1,error:"key must be ".concat(32," bytes (256 bits), got ").concat(t.length," bytes")}:{valid:!0,keyBuffer:t}}(r.cookieEncryptionKey);h.valid&&void 0!==h.keyBuffer?(c.encryptionKeyBuffer=h.keyBuffer,c.encryptionEnabled=!0):console.warn("NETACEA WARN: Invalid cookieEncryptionKey - ".concat(h.error,". Cookies will not be encrypted."))}return c}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&n(e,t)}(e,Ee),l(e,[{key:"computeHeaderFingerprint",value:(b=s(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t&&""!==t){e.next=1;break}return e.abrupt("return","");case 1:return r=t.split(","),e.next=2,this.hashGenerator.hashHeaders(r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return b.apply(this,arguments)})},{key:"handleGetCaptchaRequest",value:(k=s(i().mark((function e(t,r,a,n,o,c,s){var u,h,l,p,f,d,v,y,m;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return u=be(c),h=this.enableCaptchaContentNegotiation?Ce(o):"text/html",l={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":t,"user-agent":r,cookie:void 0!==a?"_mitatacaptcha="+a:"","X-Netacea-Captcha-Content-Type":h},void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(l["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,l["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),p={netaceaHeaders:"request-id"},"string"==typeof n&&""!==n&&(p.headerFP=n),null!==u&&(p.trackingId=u),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/captcha",headers:l,method:"GET",timeout:this.timeout,params:p});case 1:if(200===(f=e.sent).status){e.next=2;break}throw this.APIError(f);case 2:return d=f.body,"application/json"===h&&void 0!==this.netaceaCaptchaPath&&void 0!==d&&(m=null!==(v=null!==(y=this.captchaHost)&&void 0!==y?y:s)&&void 0!==v?v:"",d=xe(d,m,this.netaceaCaptchaPath)),e.abrupt("return",{body:d,apiCallStatus:f.status,setCookie:[],sessionStatus:",captcha_serve",mitigation:"captcha",mitigated:!0});case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n,i,o){return k.apply(this,arguments)})},{key:"encryptCookieValue",value:(g=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:return e.abrupt("return",ee(t,this.encryptionKeyBuffer));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"decryptCookieValue",value:(v=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:if(5===(r=t).split(".").length&&r.includes("..")){e.next=2;break}throw new Error("Cookie is not JWE encrypted");case 2:return e.abrupt("return",te(t,this.encryptionKeyBuffer));case 3:case"end":return e.stop()}var r}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"createMitata",value:(f=s(i().mark((function e(t,r,a,n,o){var c,s,u,h,l,p,f,d,v,y,m=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=m.length>5&&void 0!==m[5]?m[5]:86400,s=m.length>6&&void 0!==m[6]?m[6]:void 0,u=["1","3","5"].includes(o),h="3"===n,l="5"===n,p=u||h||l?-60:this.mitataCookieExpirySeconds,f=null!=s?s:Math.floor(Date.now()/1e3)+p,void 0!==this.secretKey){e.next=1;break}throw new Error("Cannot build cookie without secret key.");case 1:return d=[a,n,o].join(""),v=q(t,r,f,this.secretKey,d),e.next=2,this.encryptCookieValue(v);case 2:return y=e.sent,e.abrupt("return",Ae({cookieName:this.netaceaCookieName,cookieValue:y,maxAgeAttribute:String(c),otherAttributes:this.netaceaCookieAttributes}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return f.apply(this,arguments)})},{key:"getInjectHeaders",value:function(e){if(this.mitigationType===E.INJECT){var t=e;if(void 0!==t.injectHeaders){var r={},a=t.injectHeaders;return r["x-netacea-match"]=a["x-netacea-match"],r["x-netacea-mitigate"]=a["x-netacea-mitigate"],r["x-netacea-captcha"]=a["x-netacea-captcha"],void 0!==a["x-netacea-event-id"]&&(r["x-netacea-event-id"]=a["x-netacea-event-id"]),this.encodeHeadersAsKeyValueList(r)}}return[]}},{key:"registerPolicyHandler",value:function(e){var t=this;e.addMethod("getMitigationHeaderPolicy",(function(e,r){var a=t.mitigationHeaders.join(",");console.info('level=info component=f5 handler=getMitigationHeaderPolicy policy="'.concat(a,'"')),r.reply(a)}))}},{key:"encodeHeadersAsKeyValueList",value:function(e){for(var t=[],r=0,a=Object.entries(e);r<a.length;r++){var n=m(a[r],2),i=n[0],o=n[1];if(Array.isArray(o)){var c,s=y(o);try{for(s.s();!(c=s.n()).done;){var u=c.value;t.push(i,Buffer.from(u).toString("base64"))}}catch(e){s.e(e)}finally{s.f()}}else t.push(i,Buffer.from(o).toString("base64"))}return t}},{key:"registerMitigateHandler",value:function(e){var t=this;e.addMethod("handleRequest",function(){var e=s(i().mark((function e(r,a){var n,o,c,s,u,h,l,p,f,d,v,y,g,k,b,C,x,S,w,A,I,E,N,P,O,T,_,j,K,M,H,L,R;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c=r.params(),s=m(c,3),u=s[0],h=s[1],l=s[2],p=t.getArrayValueOrDefault(c,3,void 0),f=t.getArrayValueOrDefault(c,4,void 0),d=t.getArrayValueOrDefault(c,5,void 0),v=t.parseHeaderValues(d),y=null!==(n=v.cookie)&&void 0!==n?n:null,g=null!==(o=v["user-agent"])&&void 0!==o?o:"",k=v.accept,e.prev=1,e.next=2,t.computeHeaderFingerprint(f);case 2:return x=e.sent,t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=header_fingerprint method="'.concat(h,'" path="').concat(l,'" headers="').concat(null!=f?f:"",'" header_count=').concat(null!==(S=null==f?void 0:f.split(",").length)&&void 0!==S?S:0,' fingerprint="').concat(x,'"')),e.next=3,t.getMitataCookies(y);case 3:return w=e.sent,A=m(w,2),I=A[0],E=A[1],t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=mitigation_request headerFP="'.concat(x,'"')),e.next=4,t.runMitigation({ip:u,method:h,url:l,mitataCaptchaCookie:E,mitataCookie:I,userAgent:g,body:p,headerFingerprint:x,acceptHeader:k,hostHeader:v.host});case 4:if(N=e.sent,P="",(ke(l,h,t.netaceaCaptchaPath)||void 0!==t.netaceaCaptchaPath&&"captcha"===(null==N||null===(b=N.response)||void 0===b?void 0:b.mitigation))&&(P=t.enableCaptchaContentNegotiation&&"application/json"===Ce(k)?"application/json":"text/html; charset=UTF-8"),"error_open"!==(null==N?void 0:N.sessionStatus)){e.next=5;break}return a.reply(["",500,"error_open",!0,"",x,[],[],500]),e.abrupt("return");case 5:if(void 0!==N){e.next=6;break}return a.reply(["",0,"",!1,"",x,[],[],0]),e.abrupt("return");case 6:O="",T=0,_=!1,j=0,K=t.getValueOrDefault(I,""),void 0!==N.setCookie&&N.setCookie.length>0&&void 0!==(M=N.setCookie.find((function(e){return e.includes("".concat(t.netaceaCookieName,"="))})))&&(K=M.split(";")[0].replace("".concat(t.netaceaCookieName,"="),"")),void 0!==N.response&&(T=t.getValueOrDefault(N.response.apiCallStatus,0),O=t.getValueOrDefault(N.response.body,"Forbidden"),_=t.getValueOrDefault(N.response.mitigated,_),j=t.getValueOrDefault(N.response.status,403)),H={},void 0!==N.setCookie&&N.setCookie.length>0&&(H["Set-Cookie"]=N.setCookie),""!==P&&(H["Content-Type"]=P),void 0!==(L=null===(C=N.response)||void 0===C?void 0:C.redirect)&&(H.Location=L.location),a.reply([O,T,t.getValueOrDefault(N.sessionStatus,""),_,t.getValueOrDefault(K,""),x,t.getInjectHeaders(N),t.encodeHeadersAsKeyValueList(H),j]),e.next=8;break;case 7:e.prev=7,R=e.catch(1),console.error("Could not reach Netacea mitigation API: ",R.message),a.reply(["",0,"",!1,"","",[],[],0]);case 8:case"end":return e.stop()}}),e,null,[[1,7]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"parseHeaderValues",value:function(e){var t={};if(void 0===e||""===e)return t;for(var r=e.split(","),a=0;a<this.mitigationHeaders.length&&a<r.length;a++)t[this.mitigationHeaders[a].toLowerCase()]=Buffer.from(r[a],"base64").toString("utf8");return t}},{key:"getValueOrDefault",value:function(e,t){return null!=e?e:t}},{key:"getArrayValueOrDefault",value:function(e,t,r){var a;return null!==(a=e[t])&&void 0!==a?a:r}},{key:"getMitataCookies",value:(p=s(i().mark((function e(t){var r,a,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=null==t?void 0:t.split("; "),a=this.getCookie(this.mitataCookieName,r),n=this.getCookie(this.mitataCaptchaCookieName,r),void 0===a){e.next=4;break}return e.prev=1,e.next=2,this.decryptCookieValue(a);case 2:a=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),a=void 0;case 4:if(void 0===n){e.next=8;break}return e.prev=5,e.next=6,this.decryptCookieValue(n);case 6:n=e.sent,e.next=8;break;case 7:e.prev=7,e.catch(5),n=void 0;case 8:return e.abrupt("return",[a,n]);case 9:case"end":return e.stop()}}),e,this,[[1,3],[5,7]])}))),function(e){return p.apply(this,arguments)})},{key:"getCookie",value:function(e,t){var r;return null==t||null===(r=t.find((function(t){return t.includes("".concat(e,"="))})))||void 0===r?void 0:r.replace("".concat(e,"="),"")}},{key:"registerIngestHandler",value:function(e){var t=this;e.addMethod("ingest",function(){var e=s(i().mark((function e(r,a){var n,o,c,s,u,h,l,p,f,d,v,y,m;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=r.params(),c=t.getArrayValueOrDefault(o,0,""),s=t.getArrayValueOrDefault(o,1,""),u=t.getArrayValueOrDefault(o,2,"-1"),h=t.getArrayValueOrDefault(o,3,""),l=t.getArrayValueOrDefault(o,4,""),p=t.getArrayValueOrDefault(o,5,""),f=t.getArrayValueOrDefault(o,6,""),d=t.getArrayValueOrDefault(o,7,"0"),v=t.getArrayValueOrDefault(o,8,"0"),n=t.getArrayValueOrDefault(o,9,""),y=t.getArrayValueOrDefault(o,10,""),m=t.getArrayValueOrDefault(o,11,""),t.debugMode&&console.info('level=debug component=f5 handler=ingest event=ingest_request ingestType="'.concat(t.ingestType,'" headerFingerprint="').concat(m,'"')),void 0===n){e.next=4;break}return e.prev=1,e.next=2,t.decryptCookieValue(n);case 2:n=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),n=void 0;case 4:t.ingest({ip:c,userAgent:s,status:u,method:h,path:l,protocol:p,referer:f,bytesSent:d,requestTime:v,mitataCookie:n,sessionStatus:y,headerFingerprint:m}).catch((function(e){console.error("Could not reach Netacea ingest API: "+e.message)})),a.reply("done");case 5:case"end":return e.stop()}}),e,null,[[1,3]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"makeRequest",value:(h=s(i().mark((function e(t){var r=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e,a){t.host=t.host.replace("https://","");var n=t.path;if(void 0!==t.params){var i=t.params instanceof URLSearchParams?t.params.toString():T.stringify(t.params);""!==i&&(n+=(n.includes("?")?"&":"?")+i)}for(var o=O.request({agent:r.httpsAgent,host:t.host,path:n,headers:t.headers,method:t.method,body:t.body},(function(t){var r="";t.on("data",(function(e){r+=e})),t.on("end",(function(){var a;e({headers:t.headers,status:null!==(a=t.statusCode)&&void 0!==a?a:0,body:""===r?void 0:r})}))})),c=0,s=["error","abort","timeout"];c<s.length;c++){var u=s[c];o.on(u,(function(e){a(e),o.destroyed||o.destroy()}))}"post"===t.method.toLowerCase()&&o.write(t.body),o.end()}));case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)}))),function(e){return h.apply(this,arguments)})},{key:"mitigate",value:(c=s(i().mark((function e(t){var r,a,n,o,c,s;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,a={sessionStatus:r.sessionStatus,setCookie:r.setCookie},r.mitigated&&(a.response={body:null!==(n=r.body)&&void 0!==n?n:"Forbidden",status:null!==(o=null===(c=r.redirect)||void 0===c?void 0:c.statusCode)&&void 0!==o?o:r.sessionStatus.includes("monetised")?402:403,apiCallStatus:null!==(s=r.apiCallStatus)&&void 0!==s?s:-1,mitigation:r.mitigation,mitigated:r.mitigated,redirect:r.redirect}),e.abrupt("return",a);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"inject",value:(o=s(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,e.abrupt("return",{injectHeaders:r.injectHeaders,sessionStatus:r.sessionStatus,setCookie:r.setCookie});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"getMitigationResponse",value:(a=s(i().mark((function e(t){var r,a,n,o,c,u,h,l,p,f,d,v,y,m;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.ip,a=t.userAgent,n=t.url,o=t.method,c=t.mitataCookie,u=t.mitataCaptchaCookie,h=t.body,l=t.headerFingerprint,p=t.acceptHeader,f=t.hostHeader,!ke(n,o,this.netaceaCaptchaPath)){e.next=2;break}return e.next=1,this.handleGetCaptchaRequest(r,a,u,null!=l?l:"",p,n,f);case 1:return e.abrupt("return",e.sent);case 2:return d=this.enableCaptchaContentNegotiation&&void 0!==this.netaceaCaptchaPath?Ce(p):void 0,e.next=3,this.processMitigateRequest({clientIp:r,getBodyFn:function(){var e=s(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Promise.resolve(h);case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),method:o,mitata:c,mitataCaptcha:u,url:n,userAgent:a},l,d);case 3:return v=e.sent,"application/json"===d&&void 0!==this.netaceaCaptchaPath&&void 0!==v.body&&"captcha"===v.mitigation&&(v.body=xe(v.body,null!==(y=null!==(m=this.captchaHost)&&void 0!==m?m:f)&&void 0!==y?y:"",this.netaceaCaptchaPath)),e.abrupt("return",v);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"ingest",value:(r=s(i().mark((function e(t){var r,a,n,o,c,s,u,h,l,p,f,d;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.status,o=t.method,c=t.path,s=t.protocol,u=t.referer,h=t.bytesSent,l=t.requestTime,p=t.mitataCookie,f=t.sessionStatus,d=t.headerFingerprint,e.next=1,this.callIngest({ip:r,userAgent:a,status:n,method:o,bytesSent:h,path:c,protocol:s,referer:u,requestTime:l,mitataCookie:p,sessionStatus:f,headerFingerprint:d,integrationType:"@netacea/f5".replace("@netacea/",""),integrationVersion:"5.6.4"});case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getCookieHeader",value:function(e){if(void 0!==e.mitataCookie)return"".concat(this.mitataCookieName,"=").concat(e.mitataCookie)}}]);var r,a,o,c,h,p,f,v,g,k,b}();function Pe(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}module.exports=Ne;
|
|
1
|
+
"use strict";function e(e,n,a){return n=r(n),function(e,t){if(t&&("object"==o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,t()?Reflect.construct(n,a||[],r(e).constructor):n.apply(e,a))}function t(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(t=function(){return!!e})()}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function n(){n=function(e,t){return new r(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function r(e,n,a){var o=RegExp(e,n);return t.set(o,a||t.get(e)),i(o,r.prototype)}function s(e,r){var n=t.get(r);return Object.keys(n).reduce((function(t,r){var a=n[r];if("number"==typeof a)t[r]=e[a];else{for(var i=0;void 0===e[a[i]]&&i+1<a.length;)i++;t[r]=e[a[i]]}return t}),Object.create(null))}return a(r,RegExp),r.prototype.exec=function(t){var r=e.exec.call(this,t);if(r){r.groups=s(r,this);var n=r.indices;n&&(n.groups=s(n,this))}return r},r.prototype[Symbol.replace]=function(r,n){if("string"==typeof n){var a=t.get(this);return e[Symbol.replace].call(this,r,n.replace(/\$<([^>]+)(>|$)/g,(function(e,t,r){if(""===r)return e;var n=a[t];return Array.isArray(n)?"$"+n.join("$"):"number"==typeof n?"$"+n:""})))}if("function"==typeof n){var i=this;return e[Symbol.replace].call(this,r,(function(){var e=arguments;return"object"!=o(e[e.length-1])&&(e=[].slice.call(e)).push(s(e,i)),n.apply(this,e)}))}return e[Symbol.replace].call(this,r,n)},n.apply(this,arguments)}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function s(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */s=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},c=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",l=i.toStringTag||"@@toStringTag";function h(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{h({},"")}catch(e){h=function(e,t,r){return e[t]=r}}function p(e,t,r,n){var i=t&&t.prototype instanceof k?t:k,o=Object.create(i.prototype),s=new T(n||[]);return a(o,"_invoke",{value:N(e,r,s)}),o}function d(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=p;var f="suspendedStart",v="suspendedYield",y="executing",g="completed",m={};function k(){}function b(){}function x(){}var S={};h(S,c,(function(){return this}));var C=Object.getPrototypeOf,w=C&&C(C(K([])));w&&w!==r&&n.call(w,c)&&(S=w);var I=x.prototype=k.prototype=Object.create(S);function A(e){["next","throw","return"].forEach((function(t){h(e,t,(function(e){return this._invoke(t,e)}))}))}function O(e,t){function r(a,i,s,c){var u=d(e[a],e,i);if("throw"!==u.type){var l=u.arg,h=l.value;return h&&"object"==o(h)&&n.call(h,"__await")?t.resolve(h.__await).then((function(e){r("next",e,s,c)}),(function(e){r("throw",e,s,c)})):t.resolve(h).then((function(e){l.value=e,s(l)}),(function(e){return r("throw",e,s,c)}))}c(u.arg)}var i;a(this,"_invoke",{value:function(e,n){function a(){return new t((function(t,a){r(e,n,t,a)}))}return i=i?i.then(a,a):a()}})}function N(t,r,n){var a=f;return function(i,o){if(a===y)throw Error("Generator is already running");if(a===g){if("throw"===i)throw o;return{value:e,done:!0}}for(n.method=i,n.arg=o;;){var s=n.delegate;if(s){var c=E(s,n);if(c){if(c===m)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===f)throw a=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=y;var u=d(t,r,n);if("normal"===u.type){if(a=n.done?g:v,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=g,n.method="throw",n.arg=u.arg)}}}function E(t,r){var n=r.method,a=t.iterator[n];if(a===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,E(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=d(a,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,m;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,m):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function P(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function _(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,this),this.reset(!0)}function K(t){if(t||""===t){var r=t[c];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,i=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(o(t)+" is not iterable")}return b.prototype=x,a(I,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:b,configurable:!0}),b.displayName=h(x,l,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,h(e,l,"GeneratorFunction")),e.prototype=Object.create(I),e},t.awrap=function(e){return{__await:e}},A(O.prototype),h(O.prototype,u,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new O(p(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},A(I),h(I,l,"Generator"),h(I,c,(function(){return this})),h(I,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=K,T.prototype={constructor:T,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(_),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next",r.arg=e),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),_(r),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;_(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:K(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),m}},t}function c(e){return function(e){if(Array.isArray(e))return x(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||b(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t,r,n,a,i,o){try{var s=e[i](o),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,a)}function l(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function o(e){u(i,n,a,o,s,"next",e)}function s(e){u(i,n,a,o,s,"throw",e)}o(void 0)}))}}function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,g(n.key),n)}}function d(e,t,r){return t&&p(e.prototype,t),r&&p(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(e,t,r){return(t=g(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(e){var t=function(e,t){if("object"!=o(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==o(t)?t:t+""}function m(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=b(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,i=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)throw i}}}}function k(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,i,o,s=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(s.push(n.value),s.length!==t);c=!0);}catch(e){u=!0,a=e}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw a}}return s}}(e,t)||b(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(e,t){if(e){if("string"==typeof e)return x(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?x(e,t):void 0}}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var S=require("crypto"),C=require("buffer"),w=require("https"),I=require("querystring"),A=require("aws4");function O(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var N,E,P,_=O(S),T=O(w),K=O(I);!function(e){e.ORIGIN="ORIGIN",e.HTTP="HTTP",e.KINESIS="KINESIS",e.NATIVE="NATIVE"}(N||(N={})),function(e){e.MITIGATE="MITIGATE",e.INJECT="INJECT",e.INGEST="INGEST"}(E||(E={})),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"}(P||(P={}));var j=3e3;var R="_/@#/",V={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},M={0:V.none,1:V.block,2:V.none,3:V.block,4:V.none,5:V.block},L={1:V.captcha,2:V.captchaPass,3:V.captcha,4:V.allow,5:V.captcha,6:V.allow,7:V.captcha,a:V.captcha,b:V.captchaPass,c:V.captcha,d:V.allow,e:V.captcha},H=Object.freeze({__proto__:null,COOKIEDELIMITER:R,bestMitigationCaptchaMap:L,bestMitigationMap:M,captchaMap:{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"},captchaStatusCodes:{"":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"},matchMap:{0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_",c:"vendorFamily_",d:"vendorName_",e:"vendor_",f:"vendorCrawlerClassification_"},mitigateMap:{0:"",1:"blocked",2:"allow",3:"hardblocked",4:"flagged",5:"monetised"},mitigationTypes:V,netaceaCookieV3KeyMap:{clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},netaceaCookieV3OptionalKeyMap:{checkAllPostRequests:"fCAPR"},netaceaHeaders:{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"},netaceaSettingsMap:{checkAllPostRequests:"checkAllPostRequests"}}),D="ignored",B="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),F=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function z(e){if(void 0!==e){var t=e.match(F);if(null!=t){var r=k(t,9);return{signature:r[1],expiry:r[2],userId:r[3],ipHash:r[4],mitigationType:r[5],match:r[6],mitigate:r[7],captcha:r[8]}}}}function G(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:B,r=S.randomBytes(e-1),n=Array.from(r).map((function(e){return t[e%t.length]})).join("");return"c".concat(n)}function q(e,t,r,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"000";void 0===t&&(t=G());var i=[r,t,U(e+"|"+String(r),n),a].join(R),o=U(i,n);return"".concat(o).concat(R).concat(i)}function U(e,t){var r=S.createHmac("sha256",t);return r.update(e),C.Buffer.from(r.digest("hex")).toString("base64")}function J(e,t,r){var n={mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0"};if("string"!=typeof e||""===e)return n;var a=z(e);if(void 0!==a){var i=[a.expiry,a.userId,a.ipHash,a.mitigationType].join(R),o=Math.floor(Date.now()/1e3),s=parseInt(a.expiry)<o,c=["1","3","5","a","c","e"].includes(a.captcha),u="3"===a.mitigate,l=c||u,h=U(t+"|"+a.expiry,r),p=a.ipHash===h;return{mitata:a,requiresReissue:s||!p,isExpired:s,shouldExpire:l,isSameIP:p,isPrimaryHashValid:a.signature===U(i,r),match:a.match,mitigate:a.mitigate,captcha:a.captcha,userId:a.userId}}return n}function X(e,t){var r=e.split(";").map((function(e){return e.trim()})).filter((function(e){return e.toLowerCase().startsWith(t.toLowerCase())}))[0];return void 0!==r&&r.length>0?null==r?void 0:r.replace("".concat(t,"="),""):void 0}function W(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof e&&(e=e.join("; ")),""===e?"":$(e.split(";"),t).join("; ")}function $(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])return $(e.reverse()).reverse();var t,r=new Set,n=[],a=m(e);try{for(a.s();!(t=a.n()).done;){var i=t.value;if(""!==(i=i.trimStart()).trim()){var o=i.split("=")[0].toUpperCase();r.has(o)||(r.add(o),n.push(i))}}}catch(e){a.e(e)}finally{a.f()}return n}function Y(e){var t,r,n=W([null!==(t=e.otherAttributes)&&void 0!==t?t:"","Max-Age=".concat(null!==(r=e.maxAgeAttribute)&&void 0!==r?r:86400),"Path=/"].join("; "));return"".concat(e.cookieName,"=").concat(e.cookieValue,"; ").concat(n)}var Q={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(e,t){var r=e=W(null!=e?e:"",!0),n=t=W(null!=t?t:"",!0);if(void 0!==e&&void 0!==t){var a=X(e,"Domain"),i=X(t,"Domain");void 0!==a&&void 0!==i?n=t.replace(i,a):void 0!==a&&void 0===i?n=t+(""!==t?"; Domain=".concat(a):"Domain=".concat(a)):void 0===a&&void 0!==i&&(r=e+(""!==e?"; Domain=".concat(i):"Domain=".concat(i)))}else if(void 0!==e&&void 0===t){var o=X(e,"Domain");void 0!==o&&(n="Domain=".concat(o))}else if(void 0===e&&void 0!==t){var s=X(t,"Domain");void 0!==s&&(r="Domain=".concat(s))}return{cookieAttributes:""!==r?r:void 0,captchaCookieAttributes:""!==n?n:void 0}},extractAndRemoveCookieAttr:function(e,t){var r=X(e,t);return void 0!==r?{extractedAttribute:r,cookieAttributes:e.replace(/ /g,"").replace("".concat(t,"=").concat(r),"").split(";").filter((function(e){return e.length>0})).join("; ")}:{extractedAttribute:void 0,cookieAttributes:e}},extractCookieAttr:X,removeDuplicateAttrs:W}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(e){var t;return Y(v(v({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitatacaptcha"}))},createNetaceaSetCookieString:function(e){var t;return Y(v(v({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitata"}))},createSetCookieString:Y})}},Z=function(){function e(t,r){h(this,e),this.crypto=t,this.TextEncoder=r}return d(e,[{key:"hashString",value:(r=l(s().mark((function e(t,r){var n,a,i,o,u,l,h=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=(n=h.length>2&&void 0!==h[2]&&h[2])?c(r).sort():c(r),i=(new this.TextEncoder).encode(a.join(",")),e.next=1,this.crypto.subtle.digest(t,i);case 1:return o=e.sent,u=Array.from(new Uint8Array(o)),l=u.map((function(e){return e.toString(16).padStart(2,"0")})).join("").substring(0,12),e.abrupt("return","h"+(n?"s":"")+"_".concat(r.length,"_").concat(l));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"hashHeaders",value:(t=l(s().mark((function t(r){var n,a,i,o=arguments;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=o.length>1&&void 0!==o[1]&&o[1],0!==(a=e.filterHeaderNames(r)).length){t.next=1;break}return t.abrupt("return","");case 1:return t.prev=1,t.next=2,this.hashString("SHA-256",a,n);case 2:return t.abrupt("return",t.sent);case 3:return t.prev=3,i=t.catch(1),console.error(i),t.abrupt("return","");case 4:case"end":return t.stop()}}),t,this,[[1,3]])}))),function(e){return t.apply(this,arguments)})}],[{key:"filterHeaderNames",value:function(e){return e.filter((function(e){var t=e.toLowerCase();return!["","cookie","referer"].includes(t)&&null===t.match(/^(x-netacea-|cloudfront-)/i)}))}}]);var t,r}();function ee(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function te(e){var t=(e+"===".slice(0,(4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/");return Buffer.from(t,"base64")}var re="eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0";function ne(e){return 5===e.split(".").length&&e.includes("..")}function ae(e,t){var r=S.randomBytes(12),n=S.createCipheriv("aes-256-gcm",t,r),a=Buffer.from(re,"ascii");n.setAAD(a);var i=n.update(e,"utf8");i=Buffer.concat([i,n.final()]);var o=n.getAuthTag();return[re,"",ee(r),ee(i),ee(o)].join(".")}function ie(e,t){var r=e.split(".");if(5!==r.length)throw new Error("JWE should have 5 parts, got ".concat(r.length));var n=k(r,5),a=n[0],i=n[1],o=n[2],s=n[3],c=n[4];if(a!==re)throw new Error("Incorrect JWE header");if(""!==i)throw new Error("Expected empty encrypted key for direct encryption");var u=te(o),l=te(s),h=te(c);if(12!==u.length)throw new Error("IV must be ".concat(12," bytes, got ").concat(u.length));if(16!==h.length)throw new Error("Auth tag must be ".concat(16," bytes, got ").concat(h.length));var p=S.createDecipheriv("aes-256-gcm",t,u),d=Buffer.from(a,"ascii");p.setAAD(d),p.setAuthTag(h);var f=p.update(l);return(f=Buffer.concat([f,p.final()])).toString("utf8")}var oe,se="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},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"}(oe||(ue.NetaceaCookieV3IssueReason=oe={}));var le={},he={},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;var de=ue,fe=pe;function ve(e){if(void 0!==e&&""!==e){var t,r=e.split("&"),n={clientIP:"",userId:"",cookieId:"",gracePeriod:0,match:"0",mitigate:"0",captcha:"0",issueTimestamp:0,issueReason:"",checkAllPostRequests:void 0},a=m(r);try{var i=function(){var e,r=k(t.value.split("="),2),a=r[0],i=r[1],o=decodeURIComponent(i),s=Object.keys(fe.netaceaCookieV3KeyMap).find((function(e){return fe.netaceaCookieV3KeyMap[e]===a}));void 0===s&&(s=Object.keys(fe.netaceaCookieV3OptionalKeyMap).find((function(e){return fe.netaceaCookieV3OptionalKeyMap[e]===a}))),void 0!==(e=void 0!==s&&["match","mitigate","captcha"].includes(s)?""===o?void 0:o:""===o?void 0:Number(o))&&"string"!=typeof e&&isNaN(e)&&(e=o),n[s]=e};for(a.s();!(t=a.n()).done;)i()}catch(e){a.e(e)}finally{a.f()}return n}}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((function(e){var t=k(e,2);t[0];return void 0!==t[1]})).map((function(e){var t=k(e,2),r=t[0],n=t[1];return r in fe.netaceaCookieV3OptionalKeyMap?"".concat(fe.netaceaCookieV3OptionalKeyMap[r],"=").concat(encodeURIComponent(n)):"".concat(fe.netaceaCookieV3KeyMap[r],"=").concat(encodeURIComponent(n))})).join("&")},he.cookieIsNetaceaV3Format=function(e){if(void 0===e||""===e)return!1;var t=e.split("&").map((function(e){return e.split("=")[0]})).filter((function(e){return!Object.values(fe.netaceaCookieV3OptionalKeyMap).includes(e)}));return 0!==t.length&&t.every((function(e){return Object.values(fe.netaceaCookieV3KeyMap).includes(e)}))},he.objectIsNetaceaCookieV3=function(e){if("object"!==o(e)||null===e)return!1;for(var t=0,r=Object.keys(fe.netaceaCookieV3KeyMap);t<r.length;t++){var n=r[t];if(!(n in e))return!1;if(void 0===e[n])return!1}return!0},he.checkNetaceaCookieV3=function(e,t){if(void 0===e||""===e)return ye();var r;try{r=ve(e)}catch(e){return ye()}if(void 0!==r){var n=Math.floor(Date.now()/1e3),a=r.issueTimestamp+r.gracePeriod<n,i=t===r.clientIP,o=["1","3","5","a","c","e"].includes(r.captcha),s="3"===r.mitigate;return{mitata:r,requiresReissue:a||!i,isExpired:a,shouldExpire:o||s,isSameIP:i,isPrimaryHashValid:!0,match:r.match,mitigate:r.mitigate,captcha:r.captcha,issueReason:r.issueReason}}return ye()},he.matchNetaceaCookieV3=ve,he.defaultInvalidResponse=ye;var ge={};Object.defineProperty(ge,"__esModule",{value:!0}),ge.AbstractCookieFactory=void 0;var me=ue,ke=he,be=pe,xe="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),Se=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i,Ce=function(){return d((function e(t){h(this,e),this.config=t}),[{key:"isEncrypted",value:function(e){return 5===e.split(".").length}},{key:"createCookieValue",value:(n=l(s().mark((function e(t){var r,n,a,i,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===this.config.cookieEncryptionKey){e.next=2;break}return a=(0,ke.createNetaceaCookieV3)({clientIP:t.clientIP,userId:null!==(r=t.userId)&&void 0!==r?r:"",match:t.match,mitigate:t.mitigate,captcha:t.captcha,gracePeriod:t.gracePeriod,cookieId:t.cookieId,issueTimestamp:Math.floor(Date.now()/1e3),issueReason:null!==(n=t.issueReason)&&void 0!==n?n:me.NetaceaCookieV3IssueReason.NO_SESSION,checkAllPostRequests:t.checkAllPostRequests}),e.next=1,this.encrypt(a);case 1:case 4:return e.abrupt("return",e.sent);case 2:if(void 0!==this.config.secretKey){e.next=3;break}throw new Error("Cannot build cookie without secret key.");case 3:return i=[t.match,t.mitigate,t.captcha].join(""),o=Math.floor(Date.now()/1e3)+t.gracePeriod,e.next=4,this.buildMitataCookie(t.clientIP,t.userId,o,this.config.secretKey,i);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"retrieveCookieInfo",value:(r=l(s().mark((function e(t,r){var n,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t&&""!==t){e.next=1;break}return e.abrupt("return",(0,ke.defaultInvalidResponse)());case 1:if(a=t,!this.isEncrypted(t)){e.next=3;break}return e.next=2,this.decrypt(t);case 2:a=e.sent;case 3:if(!(0,ke.cookieIsNetaceaV3Format)(a)){e.next=4;break}return e.abrupt("return",(0,ke.checkNetaceaCookieV3)(a,r));case 4:return e.next=5,this.checkMitataCookie(a,r,null!==(n=this.config.secretKey)&&void 0!==n?n:"");case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"buildMitataCookie",value:(t=l(s().mark((function e(t,r,n,a,i){var o,c,u,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=null!=r?r:this.generateUserId(),e.next=1,this.hash("".concat(t,"|").concat(String(n)),a);case 1:return c=e.sent,u=[n,o,c,i].join(be.COOKIEDELIMITER),e.next=2,this.hash(u,a);case 2:return l=e.sent,e.abrupt("return","".concat(l).concat(be.COOKIEDELIMITER).concat(u));case 3:case"end":return e.stop()}}),e,this)}))),function(e,r,n,a,i){return t.apply(this,arguments)})},{key:"checkMitataCookie",value:(e=l(s().mark((function e(t,r,n){var a,i,o,c,u,l,h,p,d,f,v;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==(a=we(t))){e.next=1;break}return e.abrupt("return",(0,ke.defaultInvalidResponse)());case 1:return i=Math.floor(Date.now()/1e3),o=parseInt(a.expiry)<i,c=["1","3","5"].includes(a.captcha),u="3"===a.mitigate,l=c||u,e.next=2,this.hash("".concat(r,"|").concat(a.expiry),n);case 2:return h=e.sent,p=h===a.ipHash,d=[a.expiry,a.userId,a.ipHash,a.mitigationType].join(be.COOKIEDELIMITER),e.next=3,this.hash(d,n);case 3:return f=e.sent,v=f===a.signature,e.abrupt("return",{mitata:a,requiresReissue:o||!p,isExpired:o,shouldExpire:l,isSameIP:p,isPrimaryHashValid:v,match:a.match,mitigate:a.mitigate,captcha:a.captcha,issueReason:me.NetaceaCookieV3IssueReason.NO_SESSION});case 4:case"end":return e.stop()}}),e,this)}))),function(t,r,n){return e.apply(this,arguments)})},{key:"generateUserId",value:function(){var e=new Uint16Array((arguments.length>0&&void 0!==arguments[0]?arguments[0]:16)-1);this.getRandomValues(e);var t=Array.from(e).map((function(e){return xe[e%xe.length]})).join("");return"c".concat(t)}}]);var e,t,r,n}();function we(e){var t=e.match(Se);if(null!==t){var r=k(t,9);return{signature:r[1],expiry:r[2],userId:r[3],ipHash:r[4],mitigationType:r[5],match:r[6],mitigate:r[7],captcha:r[8]}}}ge.AbstractCookieFactory=Ce,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 r=ge;Object.defineProperty(e,"AbstractCookieFactory",{enumerable:!0,get:function(){return r.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}})}(le);var Ie={};Object.defineProperty(Ie,"__esModule",{value:!0}),Ie.validateRedirectLocation=void 0,Ie.validateRedirectLocation=function(e){if(""!==(e=null!=e?e:""))try{return new URL(e).toString()}catch(t){if(/^https?:\/\//i.test(e))return;return e.startsWith("/")?e:"/".concat(e)}};var Ae={},Oe={};function Ne(e,t){for(var r=0,n=Object.keys(e);r<n.length;r++){var a,i=n[r];if("cookie"===i||"Cookie"===i){var o=null!==(a=e[i])&&void 0!==a?a:"",s=Pe("string"==typeof o?o:o.join("; "),t);if(void 0!==s)return s}}}function Ee(e,t){for(var r=[],n=0,a=Object.keys(e);n<a.length;n++){var i,o=a[n];if("cookie"===o||"Cookie"===o){var s=null!==(i=e[o])&&void 0!==i?i:"",u="string"==typeof s?s:s.join("; ");r.push.apply(r,c(_e(u,t)))}}return r}function Pe(e,t){var r=t+"=";return e.split(";").map((function(e){return e.trimStart()})).find((function(e){return e.startsWith(r)}))}function _e(e,t){var r=t+"=";return e.split(";").map((function(e){return e.trimStart()})).filter((function(e){return e.startsWith(r)}))}Object.defineProperty(Oe,"__esModule",{value:!0}),Oe.findAllInCookieString=Oe.findFirstInCookieString=Oe.findAllInHeaders=Oe.findFirstInHeaders=Oe.findOnlyValueInHeaders=Oe.findAllValuesInHeaders=Oe.findFirstValueInHeaders=void 0,Oe.findFirstValueInHeaders=function(e,t){var r=Ne(e,t);if(void 0!==r)return r.slice(t.length+1)},Oe.findAllValuesInHeaders=function(e,t){return Ee(e,t).map((function(e){return e.slice(t.length+1)}))},Oe.findOnlyValueInHeaders=function(e,t){var r,n=Ee(e,t);if(n.length>1)throw new Error("Found more than one cookie with name ".concat(t));return null===(r=n[0])||void 0===r?void 0:r.slice(t.length+1)},Oe.findFirstInHeaders=Ne,Oe.findAllInHeaders=Ee,Oe.findFirstInCookieString=Pe,Oe.findAllInCookieString=_e;var Te={};function Ke(e){return"set-cookie"===e||"Set-Cookie"===e}function je(e,t){var r=t+"=";return e.startsWith(r)}function Re(e,t){if(!je(e,t))throw new Error("Cookie '".concat(t,"' not found in '").concat(e,"'"));return e.slice(t.length+1).split(";")[0]}function Ve(e,t){var r,n=null!==(r=e[t])&&void 0!==r?r:[];return"string"==typeof n?[n]:n}function Me(e,t){for(var r=0,n=Object.keys(e);r<n.length;r++){var a=n[r];if(Ke(a)){var i=Le(Ve(e,a),t);if(void 0!==i)return i}}}function Le(e,t){return e.map((function(e){return e.trimStart()})).find((function(e){return je(e,t)}))}function He(e,t){for(var r=[],n=0,a=Object.keys(e);n<a.length;n++){var i=a[n];if(Ke(i)){var o=Ve(e,i);r.push.apply(r,c(De(o,t)))}}return r}function De(e,t){return e.map((function(e){return e.trimStart()})).filter((function(e){return je(e,t)}))}Object.defineProperty(Te,"__esModule",{value:!0}),Te.findAllInSetCookieStrings=Te.findAllInHeaders=Te.findValueInSetCookieStrings=Te.findFirstInSetCookieStrings=Te.findFirstInHeaders=Te.findOnlyValueInHeaders=Te.findFirstValueInHeaders=Te.parseValueFromString=void 0,Te.parseValueFromString=Re,Te.findFirstValueInHeaders=function(e,t){var r=Me(e,t);return void 0!==r?Re(r,t):void 0},Te.findOnlyValueInHeaders=function(e,t){var r=He(e,t);if(r.length>1)throw new Error("Found more than one set-cookie with name ".concat(t));return void 0!==r[0]?Re(r[0],t):void 0},Te.findFirstInHeaders=Me,Te.findFirstInSetCookieStrings=Le,Te.findValueInSetCookieStrings=function(e,t){var r=Le(e,t);if(void 0!==r)return Re(r,t)},Te.findAllInHeaders=He,Te.findAllInSetCookieStrings=De;var Be=se&&se.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,a)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),Fe=se&&se.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),ze=se&&se.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&Be(t,e,r);return Fe(t,e),t};Object.defineProperty(Ae,"__esModule",{value:!0}),Ae.setCookie=Ae.cookie=void 0,Ae.cookie=ze(Oe),Ae.setCookie=ze(Te);var Ge={},qe={},Ue={};Object.defineProperty(Ue,"__esModule",{value:!0}),Ue.KINESIS_URL=Ue.API_VERSION=Ue.REGION=Ue.PAYLOAD_TYPE=Ue.STATE=void 0,Ue.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},Ue.PAYLOAD_TYPE="string",Ue.REGION="eu-west-1",Ue.API_VERSION="2013-12-02",Ue.KINESIS_URL="https://kinesis.eu-west-1.amazonaws.com";var Je={};function Xe(){return(Xe=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e){setTimeout(e,t)}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}Object.defineProperty(Je,"__esModule",{value:!0}),Je.headersToRecord=Je.increaseBatchSize=Je.handleFailedLogs=Je.batchArrayForKinesis=Je.sleep=void 0,Je.sleep=function(e){return Xe.apply(this,arguments)},Je.batchArrayForKinesis=function(e,t,r){for(var n=[],a=0;a<e.length;a+=t){var i=e.slice(a,a+t);n.push({Data:r.from(JSON.stringify(i)).toString("base64"),PartitionKey:Date.now().toString()})}return n},Je.handleFailedLogs=function(e,t,r){var n=2*r,a=[].concat(c(e),c(t)),i=a.length-n;return i>0&&(console.error("Netacea Error :: failed to send ".concat(i," log(s) to Kinesis ingest.")),a.splice(0,i)),a},Je.increaseBatchSize=function(e,t){return e!==t?Math.min(t,2*e):e},Je.headersToRecord=function(e){var t={};return e.forEach((function(e,r){t[r]=e})),t},Object.defineProperty(qe,"__esModule",{value:!0}),qe.WebStandardKinesis=void 0;var We=Ue,$e=Je,Ye=function(){return d((function e(t){var r=t.deps,n=t.kinesisIngestArgs;if(h(this,e),this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.deps=r,void 0===n.kinesisAccessKey)throw new Error("kinesisAccessKey is required for kinesis ingest");if(void 0===n.kinesisSecretKey)throw new Error("kinesisSecretKey is required for kinesis ingest");this.kinesisStreamName=n.kinesisStreamName,this.kinesisAccessKey=n.kinesisAccessKey,this.kinesisSecretKey=n.kinesisSecretKey,this.maxAwaitTimePerIngestCallMs=n.maxAwaitTimePerIngestCallMs,void 0!==n.maxLogAgeSeconds&&n.maxLogAgeSeconds<this.maxLogAgeSeconds&&n.maxLogAgeSeconds>0&&(this.maxLogAgeSeconds=n.maxLogAgeSeconds),void 0!==n.logBatchSize&&(this.maxLogBatchSize=n.logBatchSize),this.logBatchSize=!0===n.rampUpBatchSize?1:this.maxLogBatchSize}),[{key:"putToKinesis",value:(r=l(s().mark((function e(){var t,r,n;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==this.logCache.length){e.next=1;break}return e.abrupt("return");case 1:return t=c(this.logCache),this.logCache=[],e.prev=2,r=new this.deps.AwsClient({accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey}),e.next=3,this.signRequest(r,{streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},t,this.logBatchSize);case 3:return n=e.sent,e.next=4,this.deps.makeRequest({headers:(0,$e.headersToRecord)(n.headers),host:We.KINESIS_URL,method:"POST",path:"/",body:n.body});case 4:this.logBatchSize=(0,$e.increaseBatchSize)(this.logBatchSize,this.maxLogBatchSize),e.next=6;break;case 5:e.prev=5,e.catch(2),this.logCache=(0,$e.handleFailedLogs)(this.logCache,t,this.maxLogBatchSize);case 6:case"end":return e.stop()}}),e,this,[[2,5]])}))),function(){return r.apply(this,arguments)})},{key:"ingest",value:(t=l(s().mark((function e(t){var r,n,a=this;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logCache.push(t),!(this.logCache.length>=this.logBatchSize)){e.next=2;break}return(r=[]).push(this.putToKinesis()),void 0!==this.maxAwaitTimePerIngestCallMs&&r.push((0,$e.sleep)(this.maxAwaitTimePerIngestCallMs)),e.next=1,Promise.race(r);case 1:e.next=3;break;case 2:if(this.intervalSet){e.next=3;break}if(this.intervalSet=!0,n=(0,$e.sleep)(1e3*this.maxLogAgeSeconds).then(l(s().mark((function e(){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,a.putToKinesis();case 1:a.intervalSet=!1;case 2:case"end":return e.stop()}}),e)})))).catch((function(){})),void 0!==this.maxAwaitTimePerIngestCallMs){e.next=3;break}return e.next=3,n;case 3:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"signRequest",value:(e=l(s().mark((function e(t,r,n,a){var i,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={Records:(0,$e.batchArrayForKinesis)(n,a,this.deps.Buffer),PartitionKey:Date.now().toString(),StreamName:r.streamName},e.next=1,t.sign(We.KINESIS_URL,{body:JSON.stringify(i),method:"POST",headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"}});case 1:return o=e.sent,e.abrupt("return",o);case 2:case"end":return e.stop()}}),e,this)}))),function(t,r,n,a){return e.apply(this,arguments)})}]);var e,t,r}();qe.WebStandardKinesis=Ye;var Qe={};Object.defineProperty(Qe,"__esModule",{value:!0}),Qe.Kinesis=void 0;var Ze=Ue,et=Je,tt=function(){return d((function e(t){var r=t.deps,n=t.kinesisIngestArgs;h(this,e),this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.deps=r,this.kinesisStreamName=n.kinesisStreamName,this.kinesisAccessKey=n.kinesisAccessKey,this.kinesisSecretKey=n.kinesisSecretKey,this.maxAwaitTimePerIngestCallMs=n.maxAwaitTimePerIngestCallMs,void 0!==n.maxLogAgeSeconds&&n.maxLogAgeSeconds<this.maxLogAgeSeconds&&n.maxLogAgeSeconds>0&&(this.maxLogAgeSeconds=n.maxLogAgeSeconds),void 0!==n.logBatchSize&&(this.maxLogBatchSize=n.logBatchSize),this.logBatchSize=!0===n.rampUpBatchSize?1:this.maxLogBatchSize}),[{key:"putToKinesis",value:(t=l(s().mark((function e(){var t,r,n,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==this.logCache.length){e.next=1;break}return e.abrupt("return");case 1:if(t=c(this.logCache),this.logCache=[],e.prev=2,"POST"===(a=this.signRequest({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},t,this.logBatchSize)).method){e.next=3;break}throw new Error("Unexpected method. Expected POST but got ".concat(a.method));case 3:return e.next=4,this.deps.makeRequest({headers:null!==(r=a.headers)&&void 0!==r?r:{},host:"https://".concat(a.hostname),method:a.method,path:null!==(n=a.path)&&void 0!==n?n:"/",body:a.body});case 4:this.logBatchSize=(0,et.increaseBatchSize)(this.logBatchSize,this.maxLogBatchSize),e.next=6;break;case 5:e.prev=5,e.catch(2),this.logCache=(0,et.handleFailedLogs)(this.logCache,t,this.maxLogBatchSize);case 6:case"end":return e.stop()}}),e,this,[[2,5]])}))),function(){return t.apply(this,arguments)})},{key:"ingest",value:(e=l(s().mark((function e(t){var r,n,a=this;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logCache.push(t),!(this.logCache.length>=this.logBatchSize)){e.next=2;break}return(r=[]).push(this.putToKinesis()),void 0!==this.maxAwaitTimePerIngestCallMs&&r.push((0,et.sleep)(this.maxAwaitTimePerIngestCallMs)),e.next=1,Promise.race(r);case 1:e.next=3;break;case 2:if(this.intervalSet){e.next=3;break}if(this.intervalSet=!0,n=(0,et.sleep)(1e3*this.maxLogAgeSeconds).then(l(s().mark((function e(){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,a.putToKinesis();case 1:a.intervalSet=!1;case 2:case"end":return e.stop()}}),e)})))).catch((function(){})),void 0!==this.maxAwaitTimePerIngestCallMs){e.next=3;break}return e.next=3,n;case 3:case"end":return e.stop()}}),e,this)}))),function(t){return e.apply(this,arguments)})},{key:"signRequest",value:function(e,t,r){var n=e.accessKeyId,a=e.secretAccessKey,i={Records:(0,et.batchArrayForKinesis)(t,r,this.deps.Buffer),PartitionKey:Date.now().toString(),StreamName:e.streamName};return this.deps.aws4.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:Ze.REGION},{accessKeyId:n,secretAccessKey:a})}}]);var e,t}();Qe.Kinesis=tt,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Kinesis=e.WebStandardKinesis=void 0;var t=qe;Object.defineProperty(e,"WebStandardKinesis",{enumerable:!0,get:function(){return t.WebStandardKinesis}});var r=Qe;Object.defineProperty(e,"Kinesis",{enumerable:!0,get:function(){return r.Kinesis}})}(Ge);var rt={};function nt(e,t){var r=null;if("number"==typeof e)r=e;else if("string"==typeof e){var n=parseFloat(e);isNaN(n)||(r=n)}if(null===r){if("number"!=typeof t.defaultValue)return t.defaultValue;r=t.defaultValue}return void 0!==t.minValue&&(r=Math.max(t.minValue,r)),void 0!==t.maxValue&&(r=Math.min(t.maxValue,r)),r}Object.defineProperty(rt,"__esModule",{value:!0}),rt.parseHttpHeaderName=rt.stringOrDefault=rt.parseIntOrDefault=rt.parseNumberOrDefault=void 0,rt.parseNumberOrDefault=nt,rt.parseIntOrDefault=function(e,t){var r=nt(e,t);return"number"==typeof r?Math.floor(r):r},rt.stringOrDefault=function(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t},rt.parseHttpHeaderName=function(e){if("string"==typeof e){return/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(e)?e:void 0}};var at={};Object.defineProperty(at,"__esModule",{value:!0}),at.searchParamsFromRecord=void 0,at.searchParamsFromRecord=function(e){for(var t=new URLSearchParams,r=0,n=Object.entries(e);r<n.length;r++){var a=k(n[r],2),i=a[0],o=a[1];t.append(i,o)}return t};var it={},ot={};Object.defineProperty(ot,"__esModule",{value:!0}),ot.JweFactory=void 0;var st=function(){return d((function e(t){h(this,e),this.jose=t}),[{key:"encrypt",value:(t=l(s().mark((function e(t,r){var n,a,i,o,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=c.length>2&&void 0!==c[2]?c[2]:"A128CBC-HS256",a=this.jose.base64url.decode(r),i=(new TextEncoder).encode(t),e.next=1,new this.jose.CompactEncrypt(i).setProtectedHeader({alg:"dir",enc:n}).encrypt(a);case 1:return o=e.sent,e.abrupt("return",o);case 2:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})},{key:"decrypt",value:(e=l(s().mark((function e(t,r){var n,a,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.jose.base64url.decode(r),e.next=1,this.jose.compactDecrypt(t,n,{keyManagementAlgorithms:["dir"],contentEncryptionAlgorithms:["A256GCM","A128CBC-HS256"]});case 1:return a=e.sent,i=a.plaintext,e.abrupt("return",(new TextDecoder).decode(i));case 2:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}],[{key:"isJweEncrypted",value:function(e){return 5===e.split(".").length&&e.includes("..")}}]);var e,t}();ot.JweFactory=st;var ct=se&&se.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,a)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),ut=se&&se.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),lt=se&&se.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&ct(t,e,r);return ut(t,e),t};Object.defineProperty(it,"__esModule",{value:!0}),it.jwe=void 0,it.jwe=lt(ot);var ht,pt={};var dt={};Object.defineProperty(dt,"__esModule",{value:!0}),dt.ProtectorApiResponseView=dt.AbstractProtectorApiResponseView=void 0;var ft=rt,vt=function(){return d((function e(){h(this,e)}),[{key:"redirectHost",get:function(){var e;return null===(e=this.readHeader("x-netacea-redirect-host"))||void 0===e?void 0:e[0]}},{key:"redirectLocation",get:function(){var e;return null===(e=this.readHeader("x-netacea-redirect-location"))||void 0===e?void 0:e[0]}},{key:"redirectStatus",get:function(){var e;return null===(e=this.readHeader("x-netacea-redirect-status"))||void 0===e?void 0:e[0]}},{key:"redirectStatusCode",get:function(){var e,t=null===(e=this.readHeader("x-netacea-redirect-status"))||void 0===e?void 0:e[0];if(void 0!==t){var r=(0,ft.parseIntOrDefault)(t,{defaultValue:0,minValue:0,maxValue:Number.MAX_SAFE_INTEGER});return r>=300&&r<400?r:void 0}}},{key:"eventId",get:function(){var e;return null===(e=this.readHeader("x-netacea-event-id"))||void 0===e?void 0:e[0]}},{key:"sessionCookieMaxAge",get:function(){var e;return(0,ft.parseIntOrDefault)(null===(e=this.readHeader("x-netacea-mitata-expiry"))||void 0===e?void 0:e[0],{defaultValue:86400,minValue:0,maxValue:Number.MAX_SAFE_INTEGER})}},{key:"captchaCookieMaxAge",get:function(){var e,t=null===(e=this.readHeader("x-netacea-mitatacaptcha-expiry"))||void 0===e?void 0:e[0];return(0,ft.parseIntOrDefault)(t,{defaultValue:86400,minValue:0,maxValue:Number.MAX_SAFE_INTEGER})}},{key:"getProtectorCodes",value:function(e){var t,r,n,a,i,o,s,c,u;return{match:null!==(t=null!==(r=null===(n=this.readHeader("x-netacea-match"))||void 0===n?void 0:n[0])&&void 0!==r?r:null==e?void 0:e.match)&&void 0!==t?t:"0",mitigate:null!==(a=null!==(i=null===(o=this.readHeader("x-netacea-mitigate"))||void 0===o?void 0:o[0])&&void 0!==i?i:null==e?void 0:e.mitigate)&&void 0!==a?a:"0",captcha:null!==(s=null!==(c=null===(u=this.readHeader("x-netacea-captcha"))||void 0===u?void 0:u[0])&&void 0!==c?c:null==e?void 0:e.captcha)&&void 0!==s?s:"0"}}},{key:"getMonetisationRedirectLocation",value:function(e,t){var r=this.redirectLocation;if(void 0!==r)return r;var n=this.redirectHost;if(void 0!==n){var a=new URL("https://".concat(n));return a.pathname=e,a.search=t,a.toString()}}},{key:"getMonetisationRedirect",value:function(e,t){var r,n=this.getMonetisationRedirectLocation(e,t);if(void 0!==n)return{location:n,statusCode:null!==(r=this.redirectStatusCode)&&void 0!==r?r:303}}},{key:"getCaptchaJson",value:(e=l(s().mark((function e(t,r){var n,a,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getBody();case 1:if(n=e.sent,void 0===(a=this.eventId)&&"string"==typeof n&&(i=JSON.parse(n),a=kt(i)),void 0!==a){e.next=2;break}throw new Error("Could not resolve Tracking ID for captcha event.");case 2:return e.abrupt("return",mt(t,r,a));case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e}();dt.AbstractProtectorApiResponseView=vt;var yt,gt=function(){function t(r){var n;return h(this,t),(n=e(this,t)).response=r,n}return a(t,vt),d(t,[{key:"status",get:function(){return this.response.status}},{key:"getBody",value:(r=l(s().mark((function e(){var t,r,n,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this._body){e.next=5;break}return e.next=1,this.response.clone().text();case 1:if(n=t=e.sent,!(r=null!==n)){e.next=2;break}r=void 0!==t;case 2:if(!r){e.next=3;break}a=t,e.next=4;break;case 3:a="";case 4:this._body=a;case 5:return e.abrupt("return",this._body);case 6:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"readHeader",value:function(e){var t;if("set-cookie"===(e=e.toLowerCase()))return this.response.headers.getSetCookie();var r=null!==(t=this.response.headers.get(e))&&void 0!==t?t:void 0;return void 0!==r?[r]:[]}}]);var r}();function mt(e,t,r){var n="".concat(e,"?trackingId=").concat(r),a=void 0!==t?"https://".concat(t).concat(n):void 0;return JSON.stringify({captchaRelativeURL:n,captchaAbsoluteURL:a})}function kt(e){if(null==e||"object"!==o(e))throw new Error("Response body is not a valid object!");var t=e.trackingId;if("string"!=typeof t||0===t.length)throw new Error("Response body does not contain a valid trackingId!");return t}function bt(){return yt||(yt=1,function(e){var t=se&&se.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,a)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),r=se&&se.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=se&&se.__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 r(n,e),n},i=se&&se.__exportStar||function(e,r){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(r,n)||t(r,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 s=ue;Object.defineProperty(e,"NetaceaCookieV3IssueReason",{enumerable:!0,get:function(){return s.NetaceaCookieV3IssueReason}}),e.cookie=a(le),e.configValidation=a(Ie),e.headers=a(Ae),e.ingest=a(Ge),e.parsing=a(rt),e.url=a(at),e.webcrypto=a(it),e.graphql=a(function(){if(ht)return pt;ht=1,Object.defineProperty(pt,"__esModule",{value:!0}),pt.truncateLongFields=pt.parseGraphQl=pt.parseGraphQlRequestBody=pt.getGraphQLParserConfig=void 0;var e=bt();function t(e,t){var r,n,a=e.parserRegex;return null!==(r=null===(n=t.match(a))||void 0===n?void 0:n.groups)&&void 0!==r?r:{}}function r(e,t){for(var r,n,a=e.maxValueLength,i=0,o=Object.keys(t);i<o.length;i++){var s=o[i],c=t[s];t[s]=(n=a,(r=c).length<=n?r:r.slice(0,n)+"…")}return t}return pt.getGraphQLParserConfig=function(t){var r={includePaths:[],maxParsableBytes:e.parsing.parseIntOrDefault(null==t?void 0:t.maxParsableBytes,{defaultValue:1e6,minValue:1e3}),maxValueLength:e.parsing.parseIntOrDefault(null==t?void 0:t.maxValueLength,{defaultValue:256,minValue:8}),parserRegex:n(/^\s*(query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]+)?/,{OpType:1,OpName:2})};if(Array.isArray(null==t?void 0:t.includePaths)){var a,i=m(t.includePaths);try{for(i.s();!(a=i.n()).done;){var s=a.value;"string"==typeof s&&r.includePaths.push(s)}}catch(e){i.e(e)}finally{i.f()}}try{if((null==t?void 0:t.parserRegex)instanceof RegExp)r.parserRegex=null==t?void 0:t.parserRegex;else if("object"===o(null==t?void 0:t.parserRegex)){var c=null==t?void 0:t.parserRegex,u=c.regex,l=c.flags;"string"==typeof u&&(r.parserRegex=new RegExp(u,l))}}catch(e){}return r},pt.parseGraphQlRequestBody=function(e,n){var a,i;if(""===n)throw new Error("Netacea Error: Empty GraphQL body received");var s=JSON.parse(n);if("object"!==o(s))throw new Error("Netacea Error: Invalid GraphQL JSON");var c=v({},t(e,null!==(a=null==s?void 0:s.query)&&void 0!==a?a:"")),u=(null!==(i=null==s?void 0:s.operationName)&&void 0!==i?i:"").trim();return""!==u&&(c.OpName=u),r(e,c)},pt.parseGraphQl=t,pt.truncateLongFields=r,pt}()),i(dt,e)}(ce)),ce}dt.ProtectorApiResponseView=gt;var xt=bt(),St=function(){function t(r,n){var a;return h(this,t),y(a=e(this,t,[void 0===n?v(v({},r),{},{cookieEncryptionKey:void 0}):r]),"encryptionKeyBuffer",void 0),a.encryptionKeyBuffer=n,a}return a(t,xt.cookie.AbstractCookieFactory),d(t,[{key:"encrypt",value:(i=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.encryptionKeyBuffer){e.next=1;break}throw new Error("F5CookieFactory.encrypt called without a configured encryption key");case 1:return e.abrupt("return",ae(t,this.encryptionKeyBuffer));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"decrypt",value:(n=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.encryptionKeyBuffer){e.next=1;break}throw new Error("F5CookieFactory.decrypt called without a configured encryption key");case 1:return e.abrupt("return",ie(t,this.encryptionKeyBuffer));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"hash",value:(r=l(s().mark((function e(t,r){var n;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(n=S.createHmac("sha256",r)).update(t),e.abrupt("return",C.Buffer.from(n.digest("hex")).toString("base64"));case 1:case"end":return e.stop()}}),e)}))),function(e,t){return r.apply(this,arguments)})},{key:"getRandomValues",value:function(e){return crypto.getRandomValues(e)}},{key:"isEncrypted",value:function(e){return ne(e)}}]);var r,n,i}(),Ct={},wt={},It={},At={};Object.defineProperty(At,"__esModule",{value:!0}),At.API_VERSION=At.REGION=At.PAYLOAD_TYPE=At.STATE=void 0,At.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},At.PAYLOAD_TYPE="string",At.REGION="eu-west-1",At.API_VERSION="2013-12-02",Object.defineProperty(It,"__esModule",{value:!0}),It.signRequest=void 0;var Ot=A,Nt=At;function Et(e,t){for(var r=[],n=0;n<e.length;n+=t){var a=e.slice(n,n+t);r.push({Data:Buffer.from(JSON.stringify(a)).toString("base64"),PartitionKey:Date.now().toString()})}return r}It.signRequest=function(e,t,r){var n=e.accessKeyId,a=e.secretAccessKey,i={Records:Et(t,r),PartitionKey:Date.now().toString(),StreamName:e.streamName};return Ot.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:Nt.REGION},{accessKeyId:n,secretAccessKey:a})},Object.defineProperty(wt,"__esModule",{value:!0});var Pt=It;function _t(e){return Tt.apply(this,arguments)}function Tt(){return(Tt=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e){setTimeout(e,t)}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Kt=function(){return d((function e(t){var r=t.kinesisStreamName,n=t.kinesisAccessKey,a=t.kinesisSecretKey,i=t.maxLogAgeSeconds,o=t.logBatchSize,s=t.rampUpBatchSize,c=t.maxAwaitTimePerIngestCallMs;h(this,e),this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.kinesisStreamName=r,this.kinesisAccessKey=n,this.kinesisSecretKey=a,this.maxAwaitTimePerIngestCallMs=c,void 0!==i&&i<this.maxLogAgeSeconds&&i>0&&(this.maxLogAgeSeconds=i),void 0!==o&&(this.maxLogBatchSize=o),this.logBatchSize=!0===s?1:this.maxLogBatchSize}),[{key:"putToKinesis",value:(t=l(s().mark((function e(t){var r,n,a,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==this.logCache.length){e.next=1;break}return e.abrupt("return");case 1:return r=c(this.logCache),this.logCache=[],e.prev=2,n=(0,Pt.signRequest)({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},r,this.logBatchSize),e.next=3,t({headers:n.headers,host:"https://".concat(n.hostname),method:n.method,path:n.path,body:n.body});case 3:this.logBatchSize!==this.maxLogBatchSize&&(this.logBatchSize=Math.min(this.maxLogBatchSize,2*this.logBatchSize)),e.next=5;break;case 4:e.prev=4,i=e.catch(2),(a=this.logCache).push.apply(a,c(r)),console.error(i);case 5:case"end":return e.stop()}}),e,this,[[2,4]])}))),function(e){return t.apply(this,arguments)})},{key:"ingest",value:(e=l(s().mark((function e(t,r){var n,a,i=this;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logCache.push(t),!(this.logCache.length>=this.logBatchSize)){e.next=2;break}return(n=[]).push(this.putToKinesis(r)),void 0!==this.maxAwaitTimePerIngestCallMs&&n.push(_t(this.maxAwaitTimePerIngestCallMs)),e.next=1,Promise.race(n);case 1:e.next=3;break;case 2:if(this.intervalSet){e.next=3;break}if(this.intervalSet=!0,a=_t(1e3*this.maxLogAgeSeconds).then(l(s().mark((function e(){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,i.putToKinesis(r);case 1:i.intervalSet=!1;case 2:case"end":return e.stop()}}),e)})))).catch((function(){})),void 0!==this.maxAwaitTimePerIngestCallMs){e.next=3;break}return e.next=3,a;case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e,t}();wt.default=Kt,Object.defineProperty(Ct,"__esModule",{value:!0});var jt,Rt=wt,Vt=Ct.default=Rt.default,Mt={subtle:{digest:(jt=l(s().mark((function e(t,r){var n,a,i,o,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=null!==(n={"SHA-256":"sha256","SHA-1":"sha1","SHA-384":"sha384","SHA-512":"sha512"}[t])&&void 0!==n?n:t.toLowerCase().replace("-",""),i=r instanceof ArrayBuffer?Buffer.from(r):Buffer.from(r.buffer,r.byteOffset,r.byteLength),o=new Uint8Array(i),c=_.createHash(a).update(o).digest(),e.abrupt("return",c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength));case 1:case"end":return e.stop()}}),e)}))),function(e,t){return jt.apply(this,arguments)})}},Lt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Ht=/^\/[a-zA-Z0-9/]*$/;function Dt(e,t,r){return void 0!==r&&""!==r&&(function(e){var t=e,r=t.indexOf("//");if(-1!==r){var n=(t=t.substring(r+2)).indexOf("/");if(-1===n)return"/";t=t.substring(n)}var a=t.indexOf("?");return-1!==a&&(t=t.substring(0,a)),t}(e)===r&&"get"===t.toLowerCase())}function Bt(e){var t=function(e,t){var r=e.indexOf("?");if(-1!==r)for(var n=e.substring(r+1).split("&"),a=0;a<n.length;a++){var i=n[a].split("=");if(i[0]===t)return void 0!==i[1]?decodeURIComponent(i[1]):void 0}}(e,"trackingId");return void 0!==t&&Lt.test(t)?t:null}function Ft(e){if(void 0===e)return"text/html";var t=e.toLowerCase(),r=t.includes("text/html")||t.includes("application/html"),n=t.includes("application/json");return!r&&n?"application/json":"text/html"}function zt(e,t,r){if(void 0===e||""===e)return"";var n;try{n=JSON.parse(e)}catch(e){return""}if(!function(e){if(null==e)return!1;var t=e;return void 0!==t.captchaSiteKey&&void 0!==t.trackingId&&void 0!==t.captchaURL}(n))return"";var a=r+"?trackingId="+n.trackingId,i="https://"+t+a;return JSON.stringify({captchaRelativeURL:a,captchaAbsoluteURL:i})}var Gt=Q.cookie.attributes.configureCookiesDomain,qt=Q.cookie.netaceaSession,Ut=qt.createNetaceaSetCookieString,Jt=qt.createNetaceaCaptchaSetCookieString,Xt=function(){return d((function e(t){var r,n,a=t.apiKey,i=t.secretKey,o=t.timeout,s=void 0===o?3e3:o,c=t.mitigationServiceUrl,u=void 0===c?"https://mitigations.netacea.net":c,l=t.ingestServiceUrl,p=void 0===l?"https://ingest.netacea.net":l,d=t.mitigationType,f=void 0===d?E.INGEST:d,g=t.captchaSiteKey,m=t.captchaSecretKey,k=t.ingestType,b=void 0===k?N.HTTP:k,x=t.kinesis,S=t.mitataCookieExpirySeconds,C=t.netaceaCookieExpirySeconds,w=t.netaceaCookieName,I=t.netaceaCaptchaCookieName,A=t.netaceaCookieAttributes,O=t.netaceaCaptchaCookieAttributes;if(h(this,e),y(this,"mitataCookieExpirySeconds",void 0),y(this,"apiKey",void 0),y(this,"secretKey",void 0),y(this,"mitigationServiceUrl",void 0),y(this,"ingestServiceUrl",void 0),y(this,"timeout",void 0),y(this,"captchaSiteKey",void 0),y(this,"captchaSecretKey",void 0),y(this,"ingestType",void 0),y(this,"kinesis",void 0),y(this,"mitigationType",void 0),y(this,"encryptedCookies",[]),y(this,"netaceaCookieName",void 0),y(this,"netaceaCaptchaCookieName",void 0),y(this,"netaceaCookieAttributes",void 0),y(this,"netaceaCaptchaCookieAttributes",void 0),y(this,"cookieFactory",void 0),null==a)throw new Error("apiKey is a required parameter");this.apiKey=a,this.secretKey=i,this.mitigationServiceUrl=u,this.ingestServiceUrl=p,this.mitigationType=f,this.ingestType=null!=b?b:N.HTTP,this.ingestType===N.KINESIS&&(void 0===x?console.warn("NETACEA WARN: no kinesis args provided, when ingestType is ".concat(this.ingestType)):this.kinesis=new Vt(v(v({},x),{},{apiKey:this.apiKey}))),void 0===g&&void 0===m||(this.captchaSiteKey=g,this.captchaSecretKey=m),this.timeout=function(e){return e<=0?j:e}(s),this.netaceaCookieName=Yt(w,"_mitata"),this.netaceaCaptchaCookieName=Yt(I,"_mitatacaptcha"),this.encryptedCookies=[this.netaceaCookieName,this.netaceaCaptchaCookieName],this.mitataCookieExpirySeconds=function(e,t){return void 0===t?e===E.INGEST?3600:60:t}(f,null!=C?C:S);var P=Gt(null!=A?A:"",null!=O?O:"");this.netaceaCookieAttributes=null!==(r=P.cookieAttributes)&&void 0!==r?r:"",this.netaceaCaptchaCookieAttributes=null!==(n=P.captchaCookieAttributes)&&void 0!==n?n:""}),[{key:"runMitigation",value:(S=l(s().mark((function e(t){var r,n,a,i,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,i=this.mitigationType,e.next=i===E.MITIGATE?1:i===E.INJECT?3:i===E.INGEST?5:7;break;case 1:return e.next=2,this.mitigate(t);case 2:case 4:case 6:return e.abrupt("return",e.sent);case 3:return e.next=4,this.inject(t);case 5:return e.next=6,this.processIngest(t);case 7:throw new Error("Netacea Error: Mitigation type ".concat(this.mitigationType," not recognised"));case 8:e.next=10;break;case 9:return e.prev=9,o=e.catch(0),console.error("Netacea FAILOPEN Error:",o),r=t,n=this.isUrlCaptchaPost(r.url,r.method),a=this.mitigationType===E.MITIGATE,e.abrupt("return",{injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"},sessionStatus:a&&n?"error_open":""});case 10:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e){return S.apply(this,arguments)})},{key:"readCookie",value:(x=l(s().mark((function e(t,r){var n,a,i,o,c,u,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=r){e.next=1;break}return e.abrupt("return",void 0);case 1:if("string"!=typeof r){e.next=3;break}return e.next=2,this.readCookie(t,r.split(";"));case 2:return e.abrupt("return",e.sent);case 3:n="".concat(t,"="),a=m(r),e.prev=4,a.s();case 5:if((i=a.n()).done){e.next=11;break}if(o=i.value,!(c=o.split(";")[0].trimStart()).startsWith(n)){e.next=10;break}if(u=c.slice(n.length),!this.encryptedCookies.includes(t)){e.next=9;break}return e.prev=6,e.next=7,this.decryptCookieValue(u);case 7:return e.abrupt("return",e.sent);case 8:return e.prev=8,e.catch(6),e.abrupt("return",void 0);case 9:return e.abrupt("return",u);case 10:e.next=5;break;case 11:e.next=13;break;case 12:e.prev=12,l=e.catch(4),a.e(l);case 13:return e.prev=13,a.f(),e.finish(13);case 14:return e.abrupt("return",void 0);case 15:case"end":return e.stop()}}),e,this,[[4,12,13,14],[6,8]])}))),function(e,t){return x.apply(this,arguments)})},{key:"callIngest",value:(b=l(s().mark((function e(t){var r,n,a,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.constructWebLog(t),this.ingestType!==N.KINESIS){e.next=5;break}if(void 0!==this.kinesis){e.next=1;break}return console.error("Netacea Error: Unable to log as Kinesis has not been defined."),e.abrupt("return");case 1:return e.prev=1,e.next=2,this.kinesis.ingest(v(v({},r),{},{apiKey:this.apiKey}),this.makeRequest.bind(this));case 2:e.next=4;break;case 3:e.prev=3,i=e.catch(1),console.error("NETACEA Error: ",i.message);case 4:e.next=7;break;case 5:return n={"X-Netacea-API-Key":this.apiKey,"content-type":"application/json"},e.next=6,this.makeIngestApiCall(n,r);case 6:if(200===(a=e.sent).status){e.next=7;break}throw this.APIError(a);case 7:case"end":return e.stop()}}),e,this,[[1,3]])}))),function(e){return b.apply(this,arguments)})},{key:"makeIngestApiCall",value:(k=l(s().mark((function e(t,r){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeRequest({host:this.ingestServiceUrl,method:"POST",path:"/",headers:t,body:JSON.stringify(r),timeout:this.timeout});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return k.apply(this,arguments)})},{key:"constructV1WebLog",value:function(e){var t=e.ip,r=e.userAgent,n=e.status,a=e.method,i=e.path,o=e.protocol,s=e.referer,c=e.bytesSent,u=e.requestTime,l=e.mitataCookie,h=e.sessionStatus,p=e.integrationType,d=e.integrationVersion,f=e.headerFingerprint,v=(new Date).toUTCString();return{Request:"".concat(a," ").concat(i," ").concat(o),TimeLocal:v,RealIp:t,UserAgent:r,Status:n,RequestTime:null==u?void 0:u.toString(),BytesSent:null==c?void 0:c.toString(),Referer:""===s?"-":s,NetaceaUserIdCookie:null!=l?l:"",NetaceaMitigationApplied:null!=h?h:"",IntegrationType:null!=p?p:"",IntegrationVersion:null!=d?d:"",HeaderHash:null!=f?f:""}}},{key:"constructWebLog",value:function(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,this.constructV1WebLog(e)}},{key:"check",value:(g=l(s().mark((function e(t,r,n,a,i,o,c){var u,l,h,p,d,f,y,g,m,k,b,x,S,C,w;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===this.cookieFactory){e.next=2;break}return e.next=1,this.cookieFactory.retrieveCookieInfo(t,r);case 1:C=e.sent,e.next=3;break;case 2:C=J(t,r,null!==(u=this.secretKey)&&void 0!==u?u:"");case 3:if((k=C).isPrimaryHashValid&&!k.requiresReissue){e.next=6;break}return b=void 0!==k.mitata?k.mitata.userId:void 0,x=$t(k),e.next=4,this.makeMitigateAPICall(b,r,n,a,i,o,x);case 4:return S=e.sent,l=S.status,h=S.match,p=S.mitigate,d=S.captcha,f=S.body,e.next=5,this.createMitata(r,b,h,p,d,S.mitataMaxAge,void 0,x);case 5:w=e.sent,y=[w],g=S.eventId,"5"===p&&void 0!==c&&(m=this.computeMonetisationRedirect(c,S.redirectHost,S.redirectLocation,S.redirectStatus)),e.next=7;break;case 6:l=-1,h=k.match,p=k.mitigate,d=k.captcha,f=void 0,y=[];case 7:return e.abrupt("return",v(v({},this.composeResult(f,y,l,h,p,d,!1,g)),{},{redirect:m}));case 8:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a,i,o){return g.apply(this,arguments)})},{key:"computeMonetisationRedirect",value:function(e,t,r,n){var a=void 0!==n?parseInt(n,10):NaN,i=!isNaN(a)&&a>=300&&a<400?a:303;if(void 0!==r)return{location:r,statusCode:i};if(void 0!==t){var o=e.replace(/^https?:\/\/[^/]+/,"");return{location:"https://".concat(t).concat(""!==o?o:"/"),statusCode:i}}}},{key:"createMitata",value:(f=l(s().mark((function e(t,r,n,a,i){var o,c,u,l,h,p,d,f,v,y,g=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=g.length>5&&void 0!==g[5]?g[5]:86400,c=g.length>6&&void 0!==g[6]?g[6]:void 0,u=g.length>7&&void 0!==g[7]?g[7]:P.NO_SESSION,l=["1","3","5"].includes(i),h="3"===a,p="5"===a,d=l||h||p?-60:this.mitataCookieExpirySeconds,void 0===this.cookieFactory){e.next=2;break}return e.next=1,this.cookieFactory.createCookieValue({clientIP:t,userId:r,match:n,mitigate:a,captcha:i,gracePeriod:d,cookieId:G(),issueReason:u});case 1:f=e.sent,e.next=4;break;case 2:if(void 0!==this.secretKey){e.next=3;break}throw new Error("Cannot build cookie without secret key.");case 3:v=null!=c?c:Math.floor(Date.now()/1e3)+d,y=[n,a,i].join(""),f=q(t,r,v,this.secretKey,y);case 4:return e.abrupt("return",Ut({cookieName:this.netaceaCookieName,cookieValue:f,maxAgeAttribute:String(o),otherAttributes:this.netaceaCookieAttributes}));case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return f.apply(this,arguments)})},{key:"processCaptcha",value:(p=l(s().mark((function e(t,r,n,a,i){var o,c,u,l,h,p,d,f,v,y;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===this.cookieFactory){e.next=2;break}return e.next=1,this.cookieFactory.retrieveCookieInfo(t,r);case 1:y=e.sent,e.next=3;break;case 2:y=J(t,r,null!==(o=this.secretKey)&&void 0!==o?o:"");case 3:return c=$t(y),e.next=4,this.makeCaptchaAPICall(t,r,n,a,i,c);case 4:return u=e.sent,l=u.status,h=u.match,p=u.mitigate,d=u.captcha,f=u.body,v=u.setCookie,e.abrupt("return",this.composeResult(f,v,l,h,p,d,!0));case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return p.apply(this,arguments)})},{key:"getMitataCaptchaFromHeaders",value:(u=l(s().mark((function e(t){var r,n,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Object.prototype.hasOwnProperty.call(t,H.netaceaHeaders.mitataCaptcha)){e.next=3;break}if(r=t[H.netaceaHeaders.mitataCaptcha],Array.isArray(r)&&(r=r[0]),null!=r&&""!==r){e.next=1;break}return e.abrupt("return",void 0);case 1:return n=parseInt(t[H.netaceaHeaders.mitataCaptchaExpiry]),e.next=2,this.encryptCookieValue(r);case 2:return a=e.sent,e.abrupt("return",Jt({cookieName:this.netaceaCaptchaCookieName,cookieValue:a,maxAgeAttribute:String(isNaN(n)?86400:n),otherAttributes:this.netaceaCaptchaCookieAttributes}));case 3:return e.abrupt("return",void 0);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"makeCaptchaAPICall",value:(c=l(s().mark((function e(t,r,n,a,i){var o,c,u,l,h,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=p.length>5&&void 0!==p[5]?p[5]:P.NO_SESSION,c={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":n,"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},void 0!==(u=z(t))&&(c["X-Netacea-UserId"]=u.userId),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(c["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,c["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),l={},"string"==typeof i&&""!==i&&(l.headerFP=i),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/AtaVerifyCaptcha",headers:c,method:"POST",body:a,timeout:this.timeout,params:l});case 1:return h=e.sent,e.next=2,this.getApiCallResponseFromResponse(h,null==u?void 0:u.userId,r,o);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return c.apply(this,arguments)})},{key:"getApiCallResponseFromResponse",value:(o=l(s().mark((function e(t,r,n){var a,i,o,c,u,l,h,p,d,f,v,y,g,m,k,b,x,S,C,w,I,A,O=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(f=O.length>3&&void 0!==O[3]?O[3]:P.NO_SESSION,200===t.status){e.next=1;break}throw this.APIError(t);case 1:return v=null!==(a=null===(i=t.headers[H.netaceaHeaders.match])||void 0===i?void 0:i.toString())&&void 0!==a?a:"0",y=null!==(o=null===(c=t.headers[H.netaceaHeaders.mitigate])||void 0===c?void 0:c.toString())&&void 0!==o?o:"0",g=null!==(u=null===(l=t.headers[H.netaceaHeaders.captcha])||void 0===l?void 0:l.toString())&&void 0!==u?u:"0",m=parseInt(t.headers[H.netaceaHeaders.mitataExpiry]),isNaN(m)&&(m=86400),e.next=2,this.createMitata(n,r,v,y,g,86400,void 0,f);case 2:return k=e.sent,e.next=3,this.getMitataCaptchaFromHeaders(t.headers);case 3:return b=e.sent,x=[k,b].filter((function(e){return void 0!==e})),S=t.body,C=t.headers[H.netaceaHeaders.eventId],w=null===(h=t.headers["x-netacea-redirect-host"])||void 0===h?void 0:h.toString(),I=null===(p=t.headers["x-netacea-redirect-location"])||void 0===p?void 0:p.toString(),A=null===(d=t.headers["x-netacea-redirect-status"])||void 0===d?void 0:d.toString(),e.abrupt("return",{status:t.status,match:v,mitigate:y,captcha:g,setCookie:x,body:S,eventId:C,mitataMaxAge:m,redirectHost:w,redirectLocation:I,redirectStatus:A});case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return o.apply(this,arguments)})},{key:"buildCookieHeader",value:function(e){var t="",r="";for(var n in e){var a=e[n];void 0!==a&&(t="".concat(t).concat(r).concat(n,"=").concat(a),r="; ")}return t}},{key:"makeMitigateAPICall",value:(i=l(s().mark((function e(t,r,n,a,i,o){var c,u,l,h,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c=p.length>6&&void 0!==p[6]?p[6]:P.NO_SESSION,u={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":n,cookie:this.buildCookieHeader({_mitatacaptcha:a})},void 0!==t&&(u["X-Netacea-UserId"]=t),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(u["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,u["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),void 0!==o&&(u["X-Netacea-Captcha-Content-Type"]=o),l={},"string"==typeof i&&""!==i&&(l.headerFP=i),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/",headers:u,method:"GET",timeout:this.timeout,params:l});case 1:return h=e.sent,e.next=2,this.getApiCallResponseFromResponse(h,t,r,c);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a,o){return i.apply(this,arguments)})},{key:"composeResult",value:function(e,t,r,n,a,i,o,s){var c=this.findBestMitigation(n,a,i,o),u={body:e,apiCallStatus:r,setCookie:t,sessionStatus:c.sessionStatus,mitigation:c.mitigation,mitigated:[H.mitigationTypes.block,H.mitigationTypes.captcha,H.mitigationTypes.captchaPass].includes(c.mitigation)};if(this.mitigationType===E.INJECT){var l={"x-netacea-match":c.parts.match.toString(),"x-netacea-mitigate":c.parts.mitigate.toString(),"x-netacea-captcha":c.parts.captcha.toString()};void 0!==s&&(l["x-netacea-event-id"]=s),u.injectHeaders=l}return u}},{key:"findBestMitigation",value:function(e,t,r,n){var a,i,o="unknown";n||("2"===r?r="4":"3"===r&&(r="5"));var s=null!==(a=H.matchMap[e])&&void 0!==a?a:o+"_";s+=null!==(i=H.mitigateMap[t])&&void 0!==i?i:o;var c=H.bestMitigationMap[t];if("0"!==r){var u;s+=","+(null!==(u=H.captchaMap[r])&&void 0!==u?u:o);var l=H.bestMitigationCaptchaMap[r];void 0!==l&&(c=l)}return this.mitigationType===E.INJECT&&(c=H.mitigationTypes.none),{sessionStatus:s,mitigation:c,parts:{match:e,mitigate:t,captcha:r}}}},{key:"APIError",value:function(e){var 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 Error("Error reaching Netacea API (".concat(t,"), status: ").concat(e.status))}},{key:"isUrlCaptchaPost",value:function(e,t){return e.includes("/AtaVerifyCaptcha")&&"post"===t.toLowerCase()}},{key:"processMitigateRequest",value:(a=l(s().mark((function e(t,r,n){var a,i,o,c,u,l,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isUrlCaptchaPost(t.url,t.method)){e.next=2;break}return i=this,o=t.mitata,c=t.clientIp,u=t.userAgent,e.next=1,t.getBodyFn();case 1:l=e.sent,h=r,a=i.processCaptcha.call(i,o,c,u,l,h),e.next=3;break;case 2:a=this.check(t.mitata,t.clientIp,t.userAgent,t.mitataCaptcha,r,n,t.url);case 3:return e.next=4,a;case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return a.apply(this,arguments)})},{key:"setIngestOnlyMitataCookie",value:(n=l(s().mark((function e(t){var r,n,a=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=a.length>1&&void 0!==a[1]?a[1]:P.NO_SESSION,e.next=1,this.createMitata(D,t,"0","0","0",86400,void 0,r);case 1:return n=e.sent,e.abrupt("return",{sessionStatus:"",setCookie:[n]});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"processIngest",value:(r=l(s().mark((function e(t){var r,n,a,i,o,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.getCookieHeader(t),e.next=1,this.readCookie(this.netaceaCookieName,n);case 1:if(a=e.sent,void 0===this.cookieFactory){e.next=3;break}return e.next=2,this.cookieFactory.retrieveCookieInfo(a,D);case 2:c=e.sent,e.next=4;break;case 3:c=J(a,D,null!==(r=this.secretKey)&&void 0!==r?r:"");case 4:if((i=c).isPrimaryHashValid){e.next=6;break}return e.next=5,this.setIngestOnlyMitataCookie(void 0,$t(i));case 5:return e.abrupt("return",e.sent);case 6:if(!i.requiresReissue){e.next=8;break}return o=void 0!==i.mitata?i.mitata.userId:void 0,e.next=7,this.setIngestOnlyMitataCookie(o,$t(i));case 7:return e.abrupt("return",e.sent);case 8:return e.abrupt("return",{sessionStatus:"",setCookie:[]});case 9:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"encryptCookieValue",value:(t=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"decryptCookieValue",value:(e=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(t){return e.apply(this,arguments)})}]);var e,t,r,n,a,i,o,c,u,p,f,g,k,b,x,S}(),Wt=function(){function t(r){var n,a,i,o,s;h(this,t),y(s=e(this,t,[r]),"httpsAgent",void 0),y(s,"mitataCookieName",void 0),y(s,"mitataCaptchaCookieName",void 0),y(s,"hashGenerator",void 0),y(s,"debugMode",void 0),y(s,"encryptionEnabled",!1),y(s,"encryptionKeyBuffer",void 0),y(s,"mitigationHeaders",["cookie","user-agent","accept","host"]),y(s,"netaceaCaptchaPath",void 0),y(s,"captchaHost",void 0),y(s,"enableCaptchaContentNegotiation",void 0),s.httpsAgent=new T.Agent({timeout:s.timeout,keepAlive:!0,maxSockets:null!==(n=r.maxSockets)&&void 0!==n?n:25}),s.mitataCookieName=null!==(a=r.netaceaCookieName)&&void 0!==a?a:"_mitata",s.mitataCaptchaCookieName=null!==(i=r.netaceaCaptchaCookieName)&&void 0!==i?i:"_mitatacaptcha";var c=function(){return d((function e(){h(this,e)}),[{key:"encode",value:function(e){return new Uint8Array(Buffer.from(e,"utf8"))}}])}();if(s.hashGenerator=new Z(Mt,c),s.debugMode=null!==(o=r.debugMode)&&void 0!==o&&o,s.netaceaCaptchaPath=function(e){if(null!=e&&""!==e)return"/"!==e[0]&&(e="/"+e),Ht.test(e)?e:void 0}(r.netaceaCaptchaPath),s.captchaHost=r.captchaHost,s.enableCaptchaContentNegotiation=!0===r.enableCaptchaContentNegotiation,void 0!==r.cookieEncryptionKey){var u=function(e){if(null==e||""===e)return{valid:!1,error:"key is empty"};if(!/^[A-Za-z0-9_-]+$/.test(e))return{valid:!1,error:"key contains invalid base64url characters"};var t;try{t=te(e)}catch(e){return{valid:!1,error:"key is not valid base64url"}}return 32!==t.length?{valid:!1,error:"key must be ".concat(32," bytes (256 bits), got ").concat(t.length," bytes")}:{valid:!0,keyBuffer:t}}(r.cookieEncryptionKey);u.valid&&void 0!==u.keyBuffer?(s.encryptionKeyBuffer=u.keyBuffer,s.encryptionEnabled=!0):console.warn("NETACEA WARN: Invalid cookieEncryptionKey - ".concat(u.error,". Cookies will not be encrypted."))}return s.cookieFactory=new St({cookieEncryptionKey:r.cookieEncryptionKey,secretKey:r.secretKey,expirySeconds:s.mitataCookieExpirySeconds},s.encryptionEnabled&&void 0!==s.encryptionKeyBuffer?s.encryptionKeyBuffer:void 0),s}return a(t,Xt),d(t,[{key:"computeHeaderFingerprint",value:(g=l(s().mark((function e(t){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t&&""!==t){e.next=1;break}return e.abrupt("return","");case 1:return r=t.split(","),e.next=2,this.hashGenerator.hashHeaders(r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"handleGetCaptchaRequest",value:(v=l(s().mark((function e(t,r,n,a,i,o,c){var u,l,h,p,d,f,v,y,g;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return u=Bt(o),l=this.enableCaptchaContentNegotiation?Ft(i):"text/html",h={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":t,"user-agent":r,cookie:void 0!==n?"_mitatacaptcha="+n:"","X-Netacea-Captcha-Content-Type":l},void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(h["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,h["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),p={netaceaHeaders:"request-id"},"string"==typeof a&&""!==a&&(p.headerFP=a),null!==u&&(p.trackingId=u),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/captcha",headers:h,method:"GET",timeout:this.timeout,params:p});case 1:if(200===(d=e.sent).status){e.next=2;break}throw this.APIError(d);case 2:return f=d.body,"application/json"===l&&void 0!==this.netaceaCaptchaPath&&void 0!==f&&(g=null!==(v=null!==(y=this.captchaHost)&&void 0!==y?y:c)&&void 0!==v?v:"",f=zt(f,g,this.netaceaCaptchaPath)),e.abrupt("return",{body:f,apiCallStatus:d.status,setCookie:[],sessionStatus:",captcha_serve",mitigation:"captcha",mitigated:!0});case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a,i,o){return v.apply(this,arguments)})},{key:"encryptCookieValue",value:(f=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:return e.abrupt("return",ae(t,this.encryptionKeyBuffer));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return f.apply(this,arguments)})},{key:"decryptCookieValue",value:(p=l(s().mark((function e(t){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:if(ne(t)){e.next=2;break}throw new Error("Cookie is not JWE encrypted");case 2:return e.abrupt("return",ie(t,this.encryptionKeyBuffer));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"getInjectHeaders",value:function(e){if(this.mitigationType===E.INJECT){var t=e;if(void 0!==t.injectHeaders){var r={},n=t.injectHeaders;return r["x-netacea-match"]=n["x-netacea-match"],r["x-netacea-mitigate"]=n["x-netacea-mitigate"],r["x-netacea-captcha"]=n["x-netacea-captcha"],void 0!==n["x-netacea-event-id"]&&(r["x-netacea-event-id"]=n["x-netacea-event-id"]),this.encodeHeadersAsKeyValueList(r)}}return[]}},{key:"registerPolicyHandler",value:function(e){var t=this;e.addMethod("getMitigationHeaderPolicy",(function(e,r){var n=t.mitigationHeaders.join(",");console.info('level=info component=f5 handler=getMitigationHeaderPolicy policy="'.concat(n,'"')),r.reply(n)}))}},{key:"encodeHeadersAsKeyValueList",value:function(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var a=k(n[r],2),i=a[0],o=a[1];if(Array.isArray(o)){var s,c=m(o);try{for(c.s();!(s=c.n()).done;){var u=s.value;t.push(i,Buffer.from(u).toString("base64"))}}catch(e){c.e(e)}finally{c.f()}}else t.push(i,Buffer.from(o).toString("base64"))}return t}},{key:"registerMitigateHandler",value:function(e){var t=this;e.addMethod("handleRequest",function(){var e=l(s().mark((function e(r,n){var a,i,o,c,u,l,h,p,d,f,v,y,g,m,b,x,S,C,w,I,A,O,N,E,P,_,T,K,j,R,V,M,L;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=r.params(),c=k(o,3),u=c[0],l=c[1],h=c[2],p=t.getArrayValueOrDefault(o,3,void 0),d=t.getArrayValueOrDefault(o,4,void 0),f=t.getArrayValueOrDefault(o,5,void 0),v=t.parseHeaderValues(f),y=null!==(a=v.cookie)&&void 0!==a?a:null,g=null!==(i=v["user-agent"])&&void 0!==i?i:"",m=v.accept,e.prev=1,e.next=2,t.computeHeaderFingerprint(d);case 2:return S=e.sent,t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=header_fingerprint method="'.concat(l,'" path="').concat(h,'" headers="').concat(null!=d?d:"",'" header_count=').concat(null!==(C=null==d?void 0:d.split(",").length)&&void 0!==C?C:0,' fingerprint="').concat(S,'"')),e.next=3,t.getMitataCookies(y);case 3:return w=e.sent,I=k(w,2),A=I[0],O=I[1],t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=mitigation_request headerFP="'.concat(S,'"')),e.next=4,t.runMitigation({ip:u,method:l,url:h,mitataCaptchaCookie:O,mitataCookie:A,userAgent:g,body:p,headerFingerprint:S,acceptHeader:m,hostHeader:v.host});case 4:if(N=e.sent,E="",(Dt(h,l,t.netaceaCaptchaPath)||void 0!==t.netaceaCaptchaPath&&"captcha"===(null==N||null===(b=N.response)||void 0===b?void 0:b.mitigation))&&(E=t.enableCaptchaContentNegotiation&&"application/json"===Ft(m)?"application/json":"text/html; charset=UTF-8"),"error_open"!==(null==N?void 0:N.sessionStatus)){e.next=5;break}return n.reply(["",500,"error_open",!0,"",S,[],[],500]),e.abrupt("return");case 5:if(void 0!==N){e.next=6;break}return n.reply(["",0,"",!1,"",S,[],[],0]),e.abrupt("return");case 6:P="",_=0,T=!1,K=0,j=t.getValueOrDefault(A,""),void 0!==N.setCookie&&N.setCookie.length>0&&void 0!==(R=N.setCookie.find((function(e){return e.includes("".concat(t.netaceaCookieName,"="))})))&&(j=R.split(";")[0].replace("".concat(t.netaceaCookieName,"="),"")),void 0!==N.response&&(_=t.getValueOrDefault(N.response.apiCallStatus,0),P=t.getValueOrDefault(N.response.body,"Forbidden"),T=t.getValueOrDefault(N.response.mitigated,T),K=t.getValueOrDefault(N.response.status,403)),V={},void 0!==N.setCookie&&N.setCookie.length>0&&(V["Set-Cookie"]=N.setCookie),""!==E&&(V["Content-Type"]=E),void 0!==(M=null===(x=N.response)||void 0===x?void 0:x.redirect)&&(V.Location=M.location),n.reply([P,_,t.getValueOrDefault(N.sessionStatus,""),T,t.getValueOrDefault(j,""),S,t.getInjectHeaders(N),t.encodeHeadersAsKeyValueList(V),K]),e.next=8;break;case 7:e.prev=7,L=e.catch(1),console.error("Could not reach Netacea mitigation API: ",L.message),n.reply(["",0,"",!1,"","",[],[],0]);case 8:case"end":return e.stop()}}),e,null,[[1,7]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"parseHeaderValues",value:function(e){var t={};if(void 0===e||""===e)return t;for(var r=e.split(","),n=0;n<this.mitigationHeaders.length&&n<r.length;n++)t[this.mitigationHeaders[n].toLowerCase()]=Buffer.from(r[n],"base64").toString("utf8");return t}},{key:"getValueOrDefault",value:function(e,t){return null!=e?e:t}},{key:"getArrayValueOrDefault",value:function(e,t,r){var n;return null!==(n=e[t])&&void 0!==n?n:r}},{key:"getMitataCookies",value:(u=l(s().mark((function e(t){var r,n,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=null==t?void 0:t.split("; "),n=this.getCookie(this.mitataCookieName,r),a=this.getCookie(this.mitataCaptchaCookieName,r),void 0===n){e.next=4;break}return e.prev=1,e.next=2,this.decryptCookieValue(n);case 2:n=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),n=void 0;case 4:if(void 0===a){e.next=8;break}return e.prev=5,e.next=6,this.decryptCookieValue(a);case 6:a=e.sent,e.next=8;break;case 7:e.prev=7,e.catch(5),a=void 0;case 8:return e.abrupt("return",[n,a]);case 9:case"end":return e.stop()}}),e,this,[[1,3],[5,7]])}))),function(e){return u.apply(this,arguments)})},{key:"getCookie",value:function(e,t){var r;return null==t||null===(r=t.find((function(t){return t.includes("".concat(e,"="))})))||void 0===r?void 0:r.replace("".concat(e,"="),"")}},{key:"registerIngestHandler",value:function(e){var t=this;e.addMethod("ingest",function(){var e=l(s().mark((function e(r,n){var a,i,o,c,u,l,h,p,d,f,v,y,g;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=r.params(),o=t.getArrayValueOrDefault(i,0,""),c=t.getArrayValueOrDefault(i,1,""),u=t.getArrayValueOrDefault(i,2,"-1"),l=t.getArrayValueOrDefault(i,3,""),h=t.getArrayValueOrDefault(i,4,""),p=t.getArrayValueOrDefault(i,5,""),d=t.getArrayValueOrDefault(i,6,""),f=t.getArrayValueOrDefault(i,7,"0"),v=t.getArrayValueOrDefault(i,8,"0"),a=t.getArrayValueOrDefault(i,9,""),y=t.getArrayValueOrDefault(i,10,""),g=t.getArrayValueOrDefault(i,11,""),t.debugMode&&console.info('level=debug component=f5 handler=ingest event=ingest_request ingestType="'.concat(t.ingestType,'" headerFingerprint="').concat(g,'"')),void 0===a){e.next=4;break}return e.prev=1,e.next=2,t.decryptCookieValue(a);case 2:a=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),a=void 0;case 4:t.ingest({ip:o,userAgent:c,status:u,method:l,path:h,protocol:p,referer:d,bytesSent:f,requestTime:v,mitataCookie:a,sessionStatus:y,headerFingerprint:g}).catch((function(e){console.error("Could not reach Netacea ingest API: "+e.message)})),n.reply("done");case 5:case"end":return e.stop()}}),e,null,[[1,3]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"makeRequest",value:(c=l(s().mark((function e(t){var r=this;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e,n){t.host=t.host.replace("https://","");var a=t.path;if(void 0!==t.params){var i=t.params instanceof URLSearchParams?t.params.toString():K.stringify(t.params);""!==i&&(a+=(a.includes("?")?"&":"?")+i)}for(var o=T.request({agent:r.httpsAgent,host:t.host,path:a,headers:t.headers,method:t.method,body:t.body},(function(t){var r="";t.on("data",(function(e){r+=e})),t.on("end",(function(){var n;e({headers:t.headers,status:null!==(n=t.statusCode)&&void 0!==n?n:0,body:""===r?void 0:r})}))})),s=0,c=["error","abort","timeout"];s<c.length;s++){var u=c[s];o.on(u,(function(e){n(e),o.destroyed||o.destroy()}))}"post"===t.method.toLowerCase()&&o.write(t.body),o.end()}));case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"mitigate",value:(o=l(s().mark((function e(t){var r,n,a,i,o,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,n={sessionStatus:r.sessionStatus,setCookie:r.setCookie},r.mitigated&&(n.response={body:null!==(a=r.body)&&void 0!==a?a:"Forbidden",status:null!==(i=null===(o=r.redirect)||void 0===o?void 0:o.statusCode)&&void 0!==i?i:r.sessionStatus.includes("monetised")?402:403,apiCallStatus:null!==(c=r.apiCallStatus)&&void 0!==c?c:-1,mitigation:r.mitigation,mitigated:r.mitigated,redirect:r.redirect}),e.abrupt("return",n);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"inject",value:(i=l(s().mark((function e(t){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,e.abrupt("return",{injectHeaders:r.injectHeaders,sessionStatus:r.sessionStatus,setCookie:r.setCookie});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"getMitigationResponse",value:(n=l(s().mark((function e(t){var r,n,a,i,o,c,u,h,p,d,f,v,y,g;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.ip,n=t.userAgent,a=t.url,i=t.method,o=t.mitataCookie,c=t.mitataCaptchaCookie,u=t.body,h=t.headerFingerprint,p=t.acceptHeader,d=t.hostHeader,!Dt(a,i,this.netaceaCaptchaPath)){e.next=2;break}return e.next=1,this.handleGetCaptchaRequest(r,n,c,null!=h?h:"",p,a,d);case 1:return e.abrupt("return",e.sent);case 2:return f=this.enableCaptchaContentNegotiation&&void 0!==this.netaceaCaptchaPath?Ft(p):void 0,e.next=3,this.processMitigateRequest({clientIp:r,getBodyFn:function(){var e=l(s().mark((function e(){return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Promise.resolve(u);case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),method:i,mitata:o,mitataCaptcha:c,url:a,userAgent:n},h,f);case 3:return v=e.sent,"application/json"===f&&void 0!==this.netaceaCaptchaPath&&void 0!==v.body&&"captcha"===v.mitigation&&(v.body=zt(v.body,null!==(y=null!==(g=this.captchaHost)&&void 0!==g?g:d)&&void 0!==y?y:"",this.netaceaCaptchaPath)),e.abrupt("return",v);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"ingest",value:(r=l(s().mark((function e(t){var r,n,a,i,o,c,u,l,h,p,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,n=t.userAgent,a=t.status,i=t.method,o=t.path,c=t.protocol,u=t.referer,l=t.bytesSent,h=t.requestTime,p=t.mitataCookie,d=t.sessionStatus,f=t.headerFingerprint,e.next=1,this.callIngest({ip:r,userAgent:n,status:a,method:i,bytesSent:l,path:o,protocol:c,referer:u,requestTime:h,mitataCookie:p,sessionStatus:d,headerFingerprint:f,integrationType:"@netacea/f5".replace("@netacea/",""),integrationVersion:"5.7.0"});case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getCookieHeader",value:function(e){if(void 0!==e.mitataCookie)return"".concat(this.mitataCookieName,"=").concat(e.mitataCookie)}}]);var r,n,i,o,c,u,p,f,v,g}();function $t(e){return e.isPrimaryHashValid?e.isSameIP?e.isExpired?P.EXPIRED_SESSION:P.NO_SESSION:P.IP_CHANGE:P.NO_SESSION}function Yt(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}module.exports=Wt;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/f5",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "Netacea F5 CDN integration",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/index.js",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"aws4": "^1.13.2",
|
|
22
22
|
"f5-nodejs": "^1.0.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "a6065f9db3b21332b57316df19bfe0c1aa21c8bc"
|
|
25
25
|
}
|