@netacea/f5 4.3.140 → 4.3.142
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.js +1 -1
- package/package.json +2 -2
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(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,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 o(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 s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){c(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function c(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */u=function(){return r};var t,r={},a=Object.prototype,n=a.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",h=o.toStringTag||"@@toStringTag";function p(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{p({},"")}catch(t){p=function(e,t,r){return e[t]=r}}function l(e,t,r,a){var n=t&&t.prototype instanceof k?t:k,o=Object.create(n.prototype),s=new _(a||[]);return i(o,"_invoke",{value:T(e,r,s)}),o}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=l;var d="suspendedStart",y="suspendedYield",v="executing",m="completed",g={};function k(){}function b(){}function x(){}var w={};p(w,s,(function(){return this}));var S=Object.getPrototypeOf,C=S&&S(S(j([])));C&&C!==a&&n.call(C,s)&&(w=C);var I=x.prototype=k.prototype=Object.create(w);function A(e){["next","throw","return"].forEach((function(t){p(e,t,(function(e){return this._invoke(t,e)}))}))}function E(t,r){function a(i,o,s,c){var u=f(t[i],t,o);if("throw"!==u.type){var h=u.arg,p=h.value;return p&&"object"==e(p)&&n.call(p,"__await")?r.resolve(p.__await).then((function(e){a("next",e,s,c)}),(function(e){a("throw",e,s,c)})):r.resolve(p).then((function(e){h.value=e,s(h)}),(function(e){return a("throw",e,s,c)}))}c(u.arg)}var o;i(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){a(e,t,r,n)}))}return o=o?o.then(n,n):n()}})}function T(e,r,a){var n=d;return function(i,o){if(n===v)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 s=a.delegate;if(s){var c=O(s,a);if(c){if(c===g)continue;return c}}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=v;var u=f(e,r,a);if("normal"===u.type){if(n=a.done?m:y,u.arg===g)continue;return{value:u.arg,done:a.done}}"throw"===u.type&&(n=m,a.method="throw",a.arg=u.arg)}}}function O(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,O(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 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 N(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,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=x,i(I,"constructor",{value:x,configurable:!0}),i(x,"constructor",{value:b,configurable:!0}),b.displayName=p(x,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,x):(e.__proto__=x,p(e,h,"GeneratorFunction")),e.prototype=Object.create(I),e},r.awrap=function(e){return{__await:e}},A(E.prototype),p(E.prototype,c,(function(){return this})),r.AsyncIterator=E,r.async=function(e,t,a,n,i){void 0===i&&(i=Promise);var o=new E(l(e,t,a,n),i);return r.isGeneratorFunction(t)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},A(I),p(I,h,"Generator"),p(I,s,(function(){return this})),p(I,"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(N),!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 s.type="throw",s.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],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,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),N(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;N(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 h(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 p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(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,d(a.key),a)}}function f(e,t,r){return t&&l(e.prototype,t),r&&l(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(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,r,a,n,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(a,n)}function v(e){return function(){var t=this,r=arguments;return new Promise((function(a,n){var i=e.apply(t,r);function o(e){y(i,a,n,o,s,"next",e)}function s(e){y(i,a,n,o,s,"throw",e)}o(void 0)}))}}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,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=(a=i.call(r)).done)&&(s.push(a.value),s.length!==t);c=!0);}catch(e){u=!0,n=e}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw n}}return s}}(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"),x=require("buffer"),w=require("https"),S=require("aws4");function C(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,A,E,T=C(w);!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"}(A||(A={})),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||(E={}));var O=3e3;var P="_/@#/",N={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},_={0:N.none,1:N.block,2:N.none,3:N.block,4:N.none},j={1:N.captcha,2:N.captchaPass,3:N.captcha,4:N.allow,5:N.captcha,6:N.allow,7:N.captcha,a:N.captcha,b:N.captchaPass,c:N.captcha,d:N.allow,e:N.captcha},K=Object.freeze({__proto__:null,COOKIEDELIMITER:P,bestMitigationCaptchaMap:j,bestMitigationMap:_,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"},mitigationTypes:N,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"}}),M="ignored",R="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),L=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function V(e){if(void 0!==e){var t=e.match(L);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 H(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]:R,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,D(e+"|"+String(r),a),n].join(P),o=D(i,a);return"".concat(o).concat(P).concat(i)}function D(e,t){var r=b.createHmac("sha256",t);return r.update(e),x.Buffer.from(r.digest("hex")).toString("base64")}function q(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=V(e);if(void 0!==n){var i=[n.expiry,n.userId,n.ipHash,n.mitigationType].join(P),o=Math.floor(Date.now()/1e3),s=parseInt(n.expiry)<o,c=["1","3","5","a","c","e"].includes(n.captcha),u="3"===n.mitigate,h=c||u,p=D(t+"|"+n.expiry,r),l=n.ipHash===p;return{mitata:n,requiresReissue:s||!l,isExpired:s,shouldExpire:h,isSameIP:l,isPrimaryHashValid:n.signature===D(i,r),match:n.match,mitigate:n.mitigate,captcha:n.captcha,userId:n.userId}}return a}var G={},B={},F={},U={};Object.defineProperty(U,"__esModule",{value:!0}),U.API_VERSION=U.REGION=U.PAYLOAD_TYPE=U.STATE=void 0,U.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},U.PAYLOAD_TYPE="string",U.REGION="eu-west-1",U.API_VERSION="2013-12-02",Object.defineProperty(F,"__esModule",{value:!0}),F.signRequest=void 0;var z=S,X=U;function J(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}F.signRequest=function(e,t,r){var a=e.accessKeyId,n=e.secretAccessKey,i={Records:J(t,r),PartitionKey:Date.now().toString(),StreamName:e.streamName};return z.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:X.REGION},{accessKeyId:a,secretAccessKey:n})},Object.defineProperty(B,"__esModule",{value:!0});var W=F;function Y(e){return $.apply(this,arguments)}function $(){return($=v(u().mark((function e(t){return u().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 Q=function(){return f((function e(t){var r=t.kinesisStreamName,a=t.kinesisAccessKey,n=t.kinesisSecretKey,i=t.maxLogAgeSeconds,o=t.logBatchSize,s=t.rampUpBatchSize,c=t.maxAwaitTimePerIngestCallMs;p(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=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=v(u().mark((function e(t){var r,a,n,i;return u().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=h(this.logCache),this.logCache=[],e.prev=2,a=(0,W.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,i=e.catch(2),(n=this.logCache).push.apply(n,h(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=v(u().mark((function e(t,r){var a,n,i=this;return u().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(Y(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=Y(1e3*this.maxLogAgeSeconds).then(v(u().mark((function e(){return u().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,n;case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e,t}();B.default=Q,Object.defineProperty(G,"__esModule",{value:!0});var Z=B,ee=G.default=Z.default,te=function(){return f((function e(t){var r=t.apiKey,a=t.secretKey,n=t.timeout,i=void 0===n?3e3:n,o=t.mitigationServiceUrl,u=void 0===o?"https://mitigations.netacea.net":o,h=t.ingestServiceUrl,l=void 0===h?"https://ingest.netacea.net":h,f=t.mitigationType,d=void 0===f?A.INGEST:f,y=t.captchaSiteKey,v=t.captchaSecretKey,m=t.ingestType,g=void 0===m?I.HTTP:m,k=t.kinesis,b=t.mitataCookieExpirySeconds,x=t.netaceaCookieExpirySeconds,w=t.netaceaCookieName,S=t.netaceaCaptchaCookieName;if(p(this,e),c(this,"mitataCookieExpirySeconds",void 0),c(this,"apiKey",void 0),c(this,"secretKey",void 0),c(this,"mitigationServiceUrl",void 0),c(this,"ingestServiceUrl",void 0),c(this,"timeout",void 0),c(this,"captchaSiteKey",void 0),c(this,"captchaSecretKey",void 0),c(this,"ingestType",void 0),c(this,"kinesis",void 0),c(this,"mitigationType",void 0),c(this,"encryptedCookies",[]),c(this,"netaceaCookieName",void 0),c(this,"netaceaCaptchaCookieName",void 0),null==r)throw new Error("apiKey is a required parameter");this.apiKey=r,this.secretKey=a,this.mitigationServiceUrl=u,this.ingestServiceUrl=l,this.mitigationType=d,this.ingestType=null!=g?g:I.HTTP,this.ingestType===I.KINESIS&&(void 0===k?console.warn("NETACEA WARN: no kinesis args provided, when ingestType is ".concat(this.ingestType)):this.kinesis=new ee(s(s({},k),{},{apiKey:this.apiKey}))),void 0===y&&void 0===v||(this.captchaSiteKey=y,this.captchaSecretKey=v),this.timeout=function(e){return e<=0?O:e}(i),this.netaceaCookieName=ae(w,"_mitata"),this.netaceaCaptchaCookieName=ae(S,"_mitatacaptcha"),this.encryptedCookies=[this.netaceaCookieName,this.netaceaCaptchaCookieName],this.mitataCookieExpirySeconds=function(e,t){return void 0===t?e===A.INGEST?3600:60:t}(d,null!=x?x:b)}),[{key:"runMitigation",value:(S=v(u().mark((function e(t){var r,a,n,i,o;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,i=this.mitigationType,e.next=i===A.MITIGATE?1:i===A.INJECT?3:i===A.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,a=this.isUrlCaptchaPost(r.url,r.method),n=this.mitigationType===A.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 S.apply(this,arguments)})},{key:"readCookie",value:(w=v(u().mark((function e(t,r){var a,n,o,s,c,h,p;return u().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=i(r),e.prev=4,n.s();case 5:if((o=n.n()).done){e.next=11;break}if(s=o.value,!(c=s.split(";")[0].trimStart()).startsWith(a)){e.next=10;break}if(h=c.slice(a.length),!this.encryptedCookies.includes(t)){e.next=9;break}return e.prev=6,e.next=7,this.decryptCookieValue(h);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",h);case 10:e.next=5;break;case 11:e.next=13;break;case 12:e.prev=12,p=e.catch(4),n.e(p);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 w.apply(this,arguments)})},{key:"callIngest",value:(x=v(u().mark((function e(t){var r,a,n,i;return u().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(s(s({},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 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 x.apply(this,arguments)})},{key:"makeIngestApiCall",value:(b=v(u().mark((function e(t,r){return u().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 b.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,s=e.referer,c=e.bytesSent,u=e.requestTime,h=e.mitataCookie,p=e.sessionStatus,l=e.integrationType,f=e.integrationVersion,d=(new Date).toUTCString();return{Request:"".concat(n," ").concat(i," ").concat(o),TimeLocal:d,RealIp:t,UserAgent:r,Status:a,RequestTime:null==u?void 0:u.toString(),BytesSent:null==c?void 0:c.toString(),Referer:""===s?"-":s,NetaceaUserIdCookie:null!=h?h:"",NetaceaMitigationApplied:null!=p?p:"",IntegrationType:null!=l?l:"",IntegrationVersion:null!=f?f:""}}},{key:"constructWebLog",value:function(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,this.constructV1WebLog(e)}},{key:"check",value:(k=v(u().mark((function e(t,r,a,n){var i,o,s,c,h,p,l,f,d,y,v,m;return u().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((f=q(t,r,this.secretKey)).isPrimaryHashValid&&!f.requiresReissue){e.next=4;break}return e.next=2,this.makeMitigateAPICall(null===(d=f.mitata)||void 0===d?void 0:d.userId,r,a,n);case 2:return v=e.sent,i=v.status,o=v.match,s=v.mitigate,c=v.captcha,h=v.body,e.next=3,this.createMitata(r,null===(y=f.mitata)||void 0===y?void 0:y.userId,o,s,c,v.mitataMaxAge);case 3:m=e.sent,p=[m],l=v.eventId,e.next=5;break;case 4:i=-1,o=f.match,s=f.mitigate,c=f.captcha,h=void 0,p=[];case 5:return e.abrupt("return",this.composeResult(h,p,i,o,s,c,!1,l));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return k.apply(this,arguments)})},{key:"createMitata",value:(g=v(u().mark((function e(t,r,a,n,i){var o,s,c,h,p,l,f,d,y=arguments;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=y.length>5&&void 0!==y[5]?y[5]:86400,s=y.length>6&&void 0!==y[6]?y[6]:void 0,c=["1","3","5"].includes(i),h="3"===n,p=c||h?-60:this.mitataCookieExpirySeconds,l=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 f=[a,n,i].join(""),d=H(t,r,l,this.secretKey,f),e.next=2,this.buildCookieFromValues(this.netaceaCookieName,d,o,"/");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return g.apply(this,arguments)})},{key:"processCaptcha",value:(m=v(u().mark((function e(t,r,a,n){var i,o,s,c,h,p,l;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeCaptchaAPICall(t,r,a,n);case 1:return i=e.sent,o=i.status,s=i.match,c=i.mitigate,h=i.captcha,p=i.body,l=i.setCookie,e.abrupt("return",this.composeResult(p,l,o,s,c,h,!0));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return m.apply(this,arguments)})},{key:"getMitataCaptchaFromHeaders",value:(y=v(u().mark((function e(t){var r,a,n;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Object.prototype.hasOwnProperty.call(t,K.netaceaHeaders.mitataCaptcha)){e.next=2;break}return r=t[K.netaceaHeaders.mitataCaptcha],a=parseInt(t[K.netaceaHeaders.mitataCaptchaExpiry]),e.next=1,this.buildCookieFromValues(this.netaceaCaptchaCookieName,r,a);case 1:if(void 0===(n=e.sent)){e.next=2;break}return e.abrupt("return",n);case 2:return e.abrupt("return",void 0);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"makeCaptchaAPICall",value:(d=v(u().mark((function e(t,r,a,n){var i,o,s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={"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!==(o=V(t))&&(i["X-Netacea-UserId"]=o.userId),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(i["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,i["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/AtaVerifyCaptcha",headers:i,method:"POST",body:n,timeout:this.timeout});case 1:return s=e.sent,e.next=2,this.getApiCallResponseFromResponse(s,null==o?void 0:o.userId,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return d.apply(this,arguments)})},{key:"getApiCallResponseFromResponse",value:(l=v(u().mark((function e(t,r,a){var n,i,o,s,c,h,p,l,f,d,y,v,m,g;return u().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 p=null!==(n=null===(i=t.headers[K.netaceaHeaders.match])||void 0===i?void 0:i.toString())&&void 0!==n?n:"0",l=null!==(o=null===(s=t.headers[K.netaceaHeaders.mitigate])||void 0===s?void 0:s.toString())&&void 0!==o?o:"0",f=null!==(c=null===(h=t.headers[K.netaceaHeaders.captcha])||void 0===h?void 0:h.toString())&&void 0!==c?c:"0",d=parseInt(t.headers[K.netaceaHeaders.mitataExpiry]),isNaN(d)&&(d=86400),e.next=2,this.createMitata(a,r,p,l,f);case 2:return y=e.sent,e.next=3,this.getMitataCaptchaFromHeaders(t.headers);case 3:return v=e.sent,m=[y,v].filter((function(e){return void 0!==e})),g=t.headers[K.netaceaHeaders.eventId],e.abrupt("return",{status:t.status,match:p,mitigate:l,captcha:f,setCookie:m,body:t.body,eventId:g,mitataMaxAge:d});case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return l.apply(this,arguments)})},{key:"buildCookieFromValues",value:(h=v(u().mark((function e(t,r,a){var n,i,o=arguments;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=o.length>3&&void 0!==o[3]?o[3]:"/",!this.encryptedCookies.includes(t)){e.next=2;break}return e.next=1,this.encryptCookieValue(r);case 1:return i=e.sent,e.abrupt("return","".concat(t,"=").concat(i,"; Max-Age=").concat(a,"; Path=").concat(n));case 2:return e.abrupt("return","".concat(t,"=").concat(r,"; Max-Age=").concat(a,"; Path=").concat(n));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return h.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=v(u().mark((function e(t,r,a,n){var i,o;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":a,cookie:this.buildCookieHeader({_mitatacaptcha:n})},void 0!==t&&(i["X-Netacea-UserId"]=t),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(i["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,i["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/",headers:i,method:"GET",timeout:this.timeout});case 1:return o=e.sent,e.next=2,this.getApiCallResponseFromResponse(o,t,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return o.apply(this,arguments)})},{key:"composeResult",value:function(e,t,r,a,n,i,o,s){var c=this.findBestMitigation(a,n,i,o),u={body:e,apiCallStatus:r,setCookie:t,sessionStatus:c.sessionStatus,mitigation:c.mitigation,mitigated:[K.mitigationTypes.block,K.mitigationTypes.captcha,K.mitigationTypes.captchaPass].includes(c.mitigation)};if(this.mitigationType===A.INJECT){var h={"x-netacea-match":c.parts.match.toString(),"x-netacea-mitigate":c.parts.mitigate.toString(),"x-netacea-captcha":c.parts.captcha.toString()};void 0!==s&&(h["x-netacea-event-id"]=s),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 s=null!==(n=K.matchMap[e])&&void 0!==n?n:o+"_";s+=null!==(i=K.mitigateMap[t])&&void 0!==i?i:o;var c=K.bestMitigationMap[t];if("0"!==r){var u;s+=","+(null!==(u=K.captchaMap[r])&&void 0!==u?u:o);var h=K.bestMitigationCaptchaMap[r];void 0!==h&&(c=h)}return this.mitigationType===A.INJECT&&(c=K.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:(n=v(u().mark((function e(t){var r,a,n,i,o,s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isUrlCaptchaPost(t.url,t.method)){e.next=2;break}return a=this,n=t.mitata,i=t.clientIp,o=t.userAgent,e.next=1,t.getBodyFn();case 1:s=e.sent,r=a.processCaptcha.call(a,n,i,o,s),e.next=3;break;case 2:r=this.check(t.mitata,t.clientIp,t.userAgent,t.mitataCaptcha);case 3:return e.next=4,r;case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setIngestOnlyMitataCookie",value:(a=v(u().mark((function e(t){var r;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.createMitata(M,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=v(u().mark((function e(t){var r,a,n,i;return u().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=q(a,M,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===(i=n.mitata)||void 0===i?void 0:i.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=v(u().mark((function e(t){return u().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=v(u().mark((function e(t){return u().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,h,l,d,y,m,g,k,b,x,w,S}(),re=function(){function e(r){var a,n,i,o;return p(this,e),c(o=t(this,e,[r]),"httpsAgent",void 0),c(o,"mitataCookieName",void 0),c(o,"mitataCaptchaCookieName",void 0),o.httpsAgent=new T.Agent({timeout:o.timeout,keepAlive:!0,maxSockets:null!==(a=r.maxSockets)&&void 0!==a?a:25}),o.mitataCookieName=null!==(n=r.netaceaCookieName)&&void 0!==n?n:"_mitata",o.mitataCaptchaCookieName=null!==(i=r.netaceaCaptchaCookieName)&&void 0!==i?i:"_mitatacaptcha",o}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,te),f(e,[{key:"getInjectHeaders",value:function(e){if(this.mitigationType===A.INJECT){var t,r,a,n,i=e;if(void 0!==i.injectHeaders)return[null!==(t=i.injectHeaders["x-netacea-match"])&&void 0!==t?t:"0",null!==(r=i.injectHeaders["x-netacea-mitigate"])&&void 0!==r?r:"0",null!==(a=i.injectHeaders["x-netacea-captcha"])&&void 0!==a?a:"0",null!==(n=i.injectHeaders["x-netacea-event-id"])&&void 0!==n?n:""]}return[]}},{key:"registerMitigateHandler",value:function(e){var t=this;e.addMethod("handleRequest",function(){var e=v(u().mark((function e(r,a){var n,i,o,s,c,h,p,l,f,d,y,v,g,k,b,x,w,S,C;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.params(),i=m(n,5),o=i[0],s=i[1],c=i[2],h=i[3],p=i[4],l=6===n.length?t.getArrayValueOrDefault(n,5,void 0):void 0,e.prev=1,f=t.getMitataCookies(p),d=m(f,2),y=d[0],v=d[1],e.next=2,t.runMitigation({ip:o,method:c,url:h,mitataCaptchaCookie:v,mitataCookie:y,userAgent:s,body:l});case 2:if("error_open"!==(null==(g=e.sent)?void 0:g.sessionStatus)){e.next=3;break}return a.reply(["",500,[],"error_open",!0,"",[]]),e.abrupt("return");case 3:if(void 0!==g){e.next=4;break}return a.reply(["",0,[],"",!1,"",[]]),e.abrupt("return");case 4:k="",b=0,x=!1,w=t.getValueOrDefault(y,""),void 0!==g.setCookie&&g.setCookie.length>0&&void 0!==(S=g.setCookie.find((function(e){return e.includes("".concat(t.netaceaCookieName,"="))})))&&(w=S.split(";")[0].replace("".concat(t.netaceaCookieName,"="),"")),void 0!==g.response&&(b=g.response.apiCallStatus,k=t.getValueOrDefault(g.response.body,"Forbidden"),x=t.getValueOrDefault(g.response.mitigated,x)),a.reply([k,b,t.getValueOrDefault(g.setCookie,[]),g.sessionStatus,x,t.getValueOrDefault(w,""),t.getInjectHeaders(g)]),e.next=6;break;case 5:e.prev=5,C=e.catch(1),console.error("Could not reach Netacea mitigation API: ",C.message),a.reply(["",0,[],"",!1,"",[]]);case 6:case"end":return e.stop()}}),e,null,[[1,5]])})));return function(t,r){return e.apply(this,arguments)}}())}},{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:function(e){var t=null==e?void 0:e.split("; ");return[this.getCookie(this.mitataCookieName,t),this.getCookie(this.mitataCaptchaCookieName,t)]}},{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(e,r){var a=e.params(),n=t.getArrayValueOrDefault(a,0,""),i=t.getArrayValueOrDefault(a,1,""),o=t.getArrayValueOrDefault(a,2,"-1"),s=t.getArrayValueOrDefault(a,3,""),c=t.getArrayValueOrDefault(a,4,""),u=t.getArrayValueOrDefault(a,5,""),h=t.getArrayValueOrDefault(a,6,""),p=t.getArrayValueOrDefault(a,7,"0"),l=t.getArrayValueOrDefault(a,8,"0"),f=t.getArrayValueOrDefault(a,9,""),d=t.getArrayValueOrDefault(a,10,"");t.ingest({ip:n,userAgent:i,status:o,method:s,path:c,protocol:u,referer:h,bytesSent:p,requestTime:l,mitataCookie:f,sessionStatus:d}).catch((function(e){console.error("Could not reach Netacea ingest API: "+e.message)})),r.reply("done")}))}},{key:"makeRequest",value:(s=v(u().mark((function e(t){var r=this;return u().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://","");for(var n=T.request({agent:r.httpsAgent,host:t.host,path:t.path,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})}))})),i=0,o=["error","abort","timeout"];i<o.length;i++){var s=o[i];n.on(s,(function(e){a(e),n.destroyed||n.destroy()}))}"post"===t.method.toLowerCase()&&n.write(t.body),n.end()}));case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"mitigate",value:(o=v(u().mark((function e(t){var r,a,n,i;return u().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:403,apiCallStatus:null!==(i=r.apiCallStatus)&&void 0!==i?i:-1,mitigation:r.mitigation,mitigated:r.mitigated}),e.abrupt("return",a);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"inject",value:(i=v(u().mark((function e(t){var r;return u().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:(a=v(u().mark((function e(t){var r,a,n,i,o,s,c;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.url,i=t.method,o=t.mitataCookie,s=t.mitataCaptchaCookie,c=t.body,e.next=1,this.processMitigateRequest({clientIp:r,getBodyFn:function(){var e=v(u().mark((function e(){return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Promise.resolve(c);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:s,url:n,userAgent:a});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"ingest",value:(r=v(u().mark((function e(t){var r,a,n,i,o,s,c,h,p,l,f;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.status,i=t.method,o=t.path,s=t.protocol,c=t.referer,h=t.bytesSent,p=t.requestTime,l=t.mitataCookie,f=t.sessionStatus,e.next=1,this.callIngest({ip:r,userAgent:a,status:n,method:i,bytesSent:h,path:o,protocol:s,referer:c,requestTime:p,mitataCookie:l,sessionStatus:f,integrationType:"@netacea/f5".replace("@netacea/",""),integrationVersion:"4.3.140"});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,i,o,s}();function ae(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}module.exports=re;
|
|
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(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,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 o(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 s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){c(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function c(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */u=function(){return r};var t,r={},a=Object.prototype,n=a.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",h=o.toStringTag||"@@toStringTag";function p(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{p({},"")}catch(t){p=function(e,t,r){return e[t]=r}}function l(e,t,r,a){var n=t&&t.prototype instanceof k?t:k,o=Object.create(n.prototype),s=new _(a||[]);return i(o,"_invoke",{value:T(e,r,s)}),o}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=l;var d="suspendedStart",y="suspendedYield",v="executing",m="completed",g={};function k(){}function b(){}function x(){}var w={};p(w,s,(function(){return this}));var S=Object.getPrototypeOf,C=S&&S(S(j([])));C&&C!==a&&n.call(C,s)&&(w=C);var I=x.prototype=k.prototype=Object.create(w);function A(e){["next","throw","return"].forEach((function(t){p(e,t,(function(e){return this._invoke(t,e)}))}))}function E(t,r){function a(i,o,s,c){var u=f(t[i],t,o);if("throw"!==u.type){var h=u.arg,p=h.value;return p&&"object"==e(p)&&n.call(p,"__await")?r.resolve(p.__await).then((function(e){a("next",e,s,c)}),(function(e){a("throw",e,s,c)})):r.resolve(p).then((function(e){h.value=e,s(h)}),(function(e){return a("throw",e,s,c)}))}c(u.arg)}var o;i(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){a(e,t,r,n)}))}return o=o?o.then(n,n):n()}})}function T(e,r,a){var n=d;return function(i,o){if(n===v)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 s=a.delegate;if(s){var c=O(s,a);if(c){if(c===g)continue;return c}}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=v;var u=f(e,r,a);if("normal"===u.type){if(n=a.done?m:y,u.arg===g)continue;return{value:u.arg,done:a.done}}"throw"===u.type&&(n=m,a.method="throw",a.arg=u.arg)}}}function O(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,O(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 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 N(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,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=x,i(I,"constructor",{value:x,configurable:!0}),i(x,"constructor",{value:b,configurable:!0}),b.displayName=p(x,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,x):(e.__proto__=x,p(e,h,"GeneratorFunction")),e.prototype=Object.create(I),e},r.awrap=function(e){return{__await:e}},A(E.prototype),p(E.prototype,c,(function(){return this})),r.AsyncIterator=E,r.async=function(e,t,a,n,i){void 0===i&&(i=Promise);var o=new E(l(e,t,a,n),i);return r.isGeneratorFunction(t)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},A(I),p(I,h,"Generator"),p(I,s,(function(){return this})),p(I,"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(N),!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 s.type="throw",s.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],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,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),N(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;N(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 h(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 p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(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,d(a.key),a)}}function f(e,t,r){return t&&l(e.prototype,t),r&&l(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(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,r,a,n,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(a,n)}function v(e){return function(){var t=this,r=arguments;return new Promise((function(a,n){var i=e.apply(t,r);function o(e){y(i,a,n,o,s,"next",e)}function s(e){y(i,a,n,o,s,"throw",e)}o(void 0)}))}}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,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=(a=i.call(r)).done)&&(s.push(a.value),s.length!==t);c=!0);}catch(e){u=!0,n=e}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw n}}return s}}(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"),x=require("buffer"),w=require("https"),S=require("aws4");function C(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,A,E,T=C(w);!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"}(A||(A={})),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||(E={}));var O=3e3;var P="_/@#/",N={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},_={0:N.none,1:N.block,2:N.none,3:N.block,4:N.none},j={1:N.captcha,2:N.captchaPass,3:N.captcha,4:N.allow,5:N.captcha,6:N.allow,7:N.captcha,a:N.captcha,b:N.captchaPass,c:N.captcha,d:N.allow,e:N.captcha},K=Object.freeze({__proto__:null,COOKIEDELIMITER:P,bestMitigationCaptchaMap:j,bestMitigationMap:_,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"},mitigationTypes:N,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"}}),M="ignored",R="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),L=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function V(e){if(void 0!==e){var t=e.match(L);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 H(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]:R,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,D(e+"|"+String(r),a),n].join(P),o=D(i,a);return"".concat(o).concat(P).concat(i)}function D(e,t){var r=b.createHmac("sha256",t);return r.update(e),x.Buffer.from(r.digest("hex")).toString("base64")}function q(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=V(e);if(void 0!==n){var i=[n.expiry,n.userId,n.ipHash,n.mitigationType].join(P),o=Math.floor(Date.now()/1e3),s=parseInt(n.expiry)<o,c=["1","3","5","a","c","e"].includes(n.captcha),u="3"===n.mitigate,h=c||u,p=D(t+"|"+n.expiry,r),l=n.ipHash===p;return{mitata:n,requiresReissue:s||!l,isExpired:s,shouldExpire:h,isSameIP:l,isPrimaryHashValid:n.signature===D(i,r),match:n.match,mitigate:n.mitigate,captcha:n.captcha,userId:n.userId}}return a}var G={},B={},F={},U={};Object.defineProperty(U,"__esModule",{value:!0}),U.API_VERSION=U.REGION=U.PAYLOAD_TYPE=U.STATE=void 0,U.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},U.PAYLOAD_TYPE="string",U.REGION="eu-west-1",U.API_VERSION="2013-12-02",Object.defineProperty(F,"__esModule",{value:!0}),F.signRequest=void 0;var z=S,X=U;function J(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}F.signRequest=function(e,t,r){var a=e.accessKeyId,n=e.secretAccessKey,i={Records:J(t,r),PartitionKey:Date.now().toString(),StreamName:e.streamName};return z.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:X.REGION},{accessKeyId:a,secretAccessKey:n})},Object.defineProperty(B,"__esModule",{value:!0});var W=F;function Y(e){return $.apply(this,arguments)}function $(){return($=v(u().mark((function e(t){return u().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 Q=function(){return f((function e(t){var r=t.kinesisStreamName,a=t.kinesisAccessKey,n=t.kinesisSecretKey,i=t.maxLogAgeSeconds,o=t.logBatchSize,s=t.rampUpBatchSize,c=t.maxAwaitTimePerIngestCallMs;p(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=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=v(u().mark((function e(t){var r,a,n,i;return u().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=h(this.logCache),this.logCache=[],e.prev=2,a=(0,W.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,i=e.catch(2),(n=this.logCache).push.apply(n,h(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=v(u().mark((function e(t,r){var a,n,i=this;return u().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(Y(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=Y(1e3*this.maxLogAgeSeconds).then(v(u().mark((function e(){return u().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,n;case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e,t}();B.default=Q,Object.defineProperty(G,"__esModule",{value:!0});var Z=B,ee=G.default=Z.default,te=function(){return f((function e(t){var r=t.apiKey,a=t.secretKey,n=t.timeout,i=void 0===n?3e3:n,o=t.mitigationServiceUrl,u=void 0===o?"https://mitigations.netacea.net":o,h=t.ingestServiceUrl,l=void 0===h?"https://ingest.netacea.net":h,f=t.mitigationType,d=void 0===f?A.INGEST:f,y=t.captchaSiteKey,v=t.captchaSecretKey,m=t.ingestType,g=void 0===m?I.HTTP:m,k=t.kinesis,b=t.mitataCookieExpirySeconds,x=t.netaceaCookieExpirySeconds,w=t.netaceaCookieName,S=t.netaceaCaptchaCookieName;if(p(this,e),c(this,"mitataCookieExpirySeconds",void 0),c(this,"apiKey",void 0),c(this,"secretKey",void 0),c(this,"mitigationServiceUrl",void 0),c(this,"ingestServiceUrl",void 0),c(this,"timeout",void 0),c(this,"captchaSiteKey",void 0),c(this,"captchaSecretKey",void 0),c(this,"ingestType",void 0),c(this,"kinesis",void 0),c(this,"mitigationType",void 0),c(this,"encryptedCookies",[]),c(this,"netaceaCookieName",void 0),c(this,"netaceaCaptchaCookieName",void 0),null==r)throw new Error("apiKey is a required parameter");this.apiKey=r,this.secretKey=a,this.mitigationServiceUrl=u,this.ingestServiceUrl=l,this.mitigationType=d,this.ingestType=null!=g?g:I.HTTP,this.ingestType===I.KINESIS&&(void 0===k?console.warn("NETACEA WARN: no kinesis args provided, when ingestType is ".concat(this.ingestType)):this.kinesis=new ee(s(s({},k),{},{apiKey:this.apiKey}))),void 0===y&&void 0===v||(this.captchaSiteKey=y,this.captchaSecretKey=v),this.timeout=function(e){return e<=0?O:e}(i),this.netaceaCookieName=ae(w,"_mitata"),this.netaceaCaptchaCookieName=ae(S,"_mitatacaptcha"),this.encryptedCookies=[this.netaceaCookieName,this.netaceaCaptchaCookieName],this.mitataCookieExpirySeconds=function(e,t){return void 0===t?e===A.INGEST?3600:60:t}(d,null!=x?x:b)}),[{key:"runMitigation",value:(S=v(u().mark((function e(t){var r,a,n,i,o;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,i=this.mitigationType,e.next=i===A.MITIGATE?1:i===A.INJECT?3:i===A.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,a=this.isUrlCaptchaPost(r.url,r.method),n=this.mitigationType===A.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 S.apply(this,arguments)})},{key:"readCookie",value:(w=v(u().mark((function e(t,r){var a,n,o,s,c,h,p;return u().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=i(r),e.prev=4,n.s();case 5:if((o=n.n()).done){e.next=11;break}if(s=o.value,!(c=s.split(";")[0].trimStart()).startsWith(a)){e.next=10;break}if(h=c.slice(a.length),!this.encryptedCookies.includes(t)){e.next=9;break}return e.prev=6,e.next=7,this.decryptCookieValue(h);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",h);case 10:e.next=5;break;case 11:e.next=13;break;case 12:e.prev=12,p=e.catch(4),n.e(p);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 w.apply(this,arguments)})},{key:"callIngest",value:(x=v(u().mark((function e(t){var r,a,n,i;return u().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(s(s({},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 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 x.apply(this,arguments)})},{key:"makeIngestApiCall",value:(b=v(u().mark((function e(t,r){return u().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 b.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,s=e.referer,c=e.bytesSent,u=e.requestTime,h=e.mitataCookie,p=e.sessionStatus,l=e.integrationType,f=e.integrationVersion,d=(new Date).toUTCString();return{Request:"".concat(n," ").concat(i," ").concat(o),TimeLocal:d,RealIp:t,UserAgent:r,Status:a,RequestTime:null==u?void 0:u.toString(),BytesSent:null==c?void 0:c.toString(),Referer:""===s?"-":s,NetaceaUserIdCookie:null!=h?h:"",NetaceaMitigationApplied:null!=p?p:"",IntegrationType:null!=l?l:"",IntegrationVersion:null!=f?f:""}}},{key:"constructWebLog",value:function(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,this.constructV1WebLog(e)}},{key:"check",value:(k=v(u().mark((function e(t,r,a,n){var i,o,s,c,h,p,l,f,d,y,v,m;return u().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((f=q(t,r,this.secretKey)).isPrimaryHashValid&&!f.requiresReissue){e.next=4;break}return e.next=2,this.makeMitigateAPICall(null===(d=f.mitata)||void 0===d?void 0:d.userId,r,a,n);case 2:return v=e.sent,i=v.status,o=v.match,s=v.mitigate,c=v.captcha,h=v.body,e.next=3,this.createMitata(r,null===(y=f.mitata)||void 0===y?void 0:y.userId,o,s,c,v.mitataMaxAge);case 3:m=e.sent,p=[m],l=v.eventId,e.next=5;break;case 4:i=-1,o=f.match,s=f.mitigate,c=f.captcha,h=void 0,p=[];case 5:return e.abrupt("return",this.composeResult(h,p,i,o,s,c,!1,l));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return k.apply(this,arguments)})},{key:"createMitata",value:(g=v(u().mark((function e(t,r,a,n,i){var o,s,c,h,p,l,f,d,y=arguments;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=y.length>5&&void 0!==y[5]?y[5]:86400,s=y.length>6&&void 0!==y[6]?y[6]:void 0,c=["1","3","5"].includes(i),h="3"===n,p=c||h?-60:this.mitataCookieExpirySeconds,l=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 f=[a,n,i].join(""),d=H(t,r,l,this.secretKey,f),e.next=2,this.buildCookieFromValues(this.netaceaCookieName,d,o,"/");case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return g.apply(this,arguments)})},{key:"processCaptcha",value:(m=v(u().mark((function e(t,r,a,n){var i,o,s,c,h,p,l;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeCaptchaAPICall(t,r,a,n);case 1:return i=e.sent,o=i.status,s=i.match,c=i.mitigate,h=i.captcha,p=i.body,l=i.setCookie,e.abrupt("return",this.composeResult(p,l,o,s,c,h,!0));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return m.apply(this,arguments)})},{key:"getMitataCaptchaFromHeaders",value:(y=v(u().mark((function e(t){var r,a,n;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Object.prototype.hasOwnProperty.call(t,K.netaceaHeaders.mitataCaptcha)){e.next=2;break}return r=t[K.netaceaHeaders.mitataCaptcha],a=parseInt(t[K.netaceaHeaders.mitataCaptchaExpiry]),e.next=1,this.buildCookieFromValues(this.netaceaCaptchaCookieName,r,a);case 1:if(void 0===(n=e.sent)){e.next=2;break}return e.abrupt("return",n);case 2:return e.abrupt("return",void 0);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"makeCaptchaAPICall",value:(d=v(u().mark((function e(t,r,a,n){var i,o,s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={"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!==(o=V(t))&&(i["X-Netacea-UserId"]=o.userId),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(i["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,i["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/AtaVerifyCaptcha",headers:i,method:"POST",body:n,timeout:this.timeout});case 1:return s=e.sent,e.next=2,this.getApiCallResponseFromResponse(s,null==o?void 0:o.userId,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return d.apply(this,arguments)})},{key:"getApiCallResponseFromResponse",value:(l=v(u().mark((function e(t,r,a){var n,i,o,s,c,h,p,l,f,d,y,v,m,g;return u().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 p=null!==(n=null===(i=t.headers[K.netaceaHeaders.match])||void 0===i?void 0:i.toString())&&void 0!==n?n:"0",l=null!==(o=null===(s=t.headers[K.netaceaHeaders.mitigate])||void 0===s?void 0:s.toString())&&void 0!==o?o:"0",f=null!==(c=null===(h=t.headers[K.netaceaHeaders.captcha])||void 0===h?void 0:h.toString())&&void 0!==c?c:"0",d=parseInt(t.headers[K.netaceaHeaders.mitataExpiry]),isNaN(d)&&(d=86400),e.next=2,this.createMitata(a,r,p,l,f);case 2:return y=e.sent,e.next=3,this.getMitataCaptchaFromHeaders(t.headers);case 3:return v=e.sent,m=[y,v].filter((function(e){return void 0!==e})),g=t.headers[K.netaceaHeaders.eventId],e.abrupt("return",{status:t.status,match:p,mitigate:l,captcha:f,setCookie:m,body:t.body,eventId:g,mitataMaxAge:d});case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return l.apply(this,arguments)})},{key:"buildCookieFromValues",value:(h=v(u().mark((function e(t,r,a){var n,i,o=arguments;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=o.length>3&&void 0!==o[3]?o[3]:"/",!this.encryptedCookies.includes(t)){e.next=2;break}return e.next=1,this.encryptCookieValue(r);case 1:return i=e.sent,e.abrupt("return","".concat(t,"=").concat(i,"; Max-Age=").concat(a,"; Path=").concat(n));case 2:return e.abrupt("return","".concat(t,"=").concat(r,"; Max-Age=").concat(a,"; Path=").concat(n));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return h.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=v(u().mark((function e(t,r,a,n){var i,o;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":a,cookie:this.buildCookieHeader({_mitatacaptcha:n})},void 0!==t&&(i["X-Netacea-UserId"]=t),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(i["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,i["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/",headers:i,method:"GET",timeout:this.timeout});case 1:return o=e.sent,e.next=2,this.getApiCallResponseFromResponse(o,t,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return o.apply(this,arguments)})},{key:"composeResult",value:function(e,t,r,a,n,i,o,s){var c=this.findBestMitigation(a,n,i,o),u={body:e,apiCallStatus:r,setCookie:t,sessionStatus:c.sessionStatus,mitigation:c.mitigation,mitigated:[K.mitigationTypes.block,K.mitigationTypes.captcha,K.mitigationTypes.captchaPass].includes(c.mitigation)};if(this.mitigationType===A.INJECT){var h={"x-netacea-match":c.parts.match.toString(),"x-netacea-mitigate":c.parts.mitigate.toString(),"x-netacea-captcha":c.parts.captcha.toString()};void 0!==s&&(h["x-netacea-event-id"]=s),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 s=null!==(n=K.matchMap[e])&&void 0!==n?n:o+"_";s+=null!==(i=K.mitigateMap[t])&&void 0!==i?i:o;var c=K.bestMitigationMap[t];if("0"!==r){var u;s+=","+(null!==(u=K.captchaMap[r])&&void 0!==u?u:o);var h=K.bestMitigationCaptchaMap[r];void 0!==h&&(c=h)}return this.mitigationType===A.INJECT&&(c=K.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:(n=v(u().mark((function e(t){var r,a,n,i,o,s;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isUrlCaptchaPost(t.url,t.method)){e.next=2;break}return a=this,n=t.mitata,i=t.clientIp,o=t.userAgent,e.next=1,t.getBodyFn();case 1:s=e.sent,r=a.processCaptcha.call(a,n,i,o,s),e.next=3;break;case 2:r=this.check(t.mitata,t.clientIp,t.userAgent,t.mitataCaptcha);case 3:return e.next=4,r;case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setIngestOnlyMitataCookie",value:(a=v(u().mark((function e(t){var r;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.createMitata(M,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=v(u().mark((function e(t){var r,a,n,i;return u().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=q(a,M,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===(i=n.mitata)||void 0===i?void 0:i.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=v(u().mark((function e(t){return u().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=v(u().mark((function e(t){return u().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,h,l,d,y,m,g,k,b,x,w,S}(),re=function(){function e(r){var a,n,i,o;return p(this,e),c(o=t(this,e,[r]),"httpsAgent",void 0),c(o,"mitataCookieName",void 0),c(o,"mitataCaptchaCookieName",void 0),o.httpsAgent=new T.Agent({timeout:o.timeout,keepAlive:!0,maxSockets:null!==(a=r.maxSockets)&&void 0!==a?a:25}),o.mitataCookieName=null!==(n=r.netaceaCookieName)&&void 0!==n?n:"_mitata",o.mitataCaptchaCookieName=null!==(i=r.netaceaCaptchaCookieName)&&void 0!==i?i:"_mitatacaptcha",o}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,te),f(e,[{key:"getInjectHeaders",value:function(e){if(this.mitigationType===A.INJECT){var t,r,a,n,i=e;if(void 0!==i.injectHeaders)return[null!==(t=i.injectHeaders["x-netacea-match"])&&void 0!==t?t:"0",null!==(r=i.injectHeaders["x-netacea-mitigate"])&&void 0!==r?r:"0",null!==(a=i.injectHeaders["x-netacea-captcha"])&&void 0!==a?a:"0",null!==(n=i.injectHeaders["x-netacea-event-id"])&&void 0!==n?n:""]}return[]}},{key:"registerMitigateHandler",value:function(e){var t=this;e.addMethod("handleRequest",function(){var e=v(u().mark((function e(r,a){var n,i,o,s,c,h,p,l,f,d,y,v,g,k,b,x,w,S,C;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.params(),i=m(n,5),o=i[0],s=i[1],c=i[2],h=i[3],p=i[4],l=6===n.length?t.getArrayValueOrDefault(n,5,void 0):void 0,e.prev=1,f=t.getMitataCookies(p),d=m(f,2),y=d[0],v=d[1],e.next=2,t.runMitigation({ip:o,method:c,url:h,mitataCaptchaCookie:v,mitataCookie:y,userAgent:s,body:l});case 2:if("error_open"!==(null==(g=e.sent)?void 0:g.sessionStatus)){e.next=3;break}return a.reply(["",500,[],"error_open",!0,"",[]]),e.abrupt("return");case 3:if(void 0!==g){e.next=4;break}return a.reply(["",0,[],"",!1,"",[]]),e.abrupt("return");case 4:k="",b=0,x=!1,w=t.getValueOrDefault(y,""),void 0!==g.setCookie&&g.setCookie.length>0&&void 0!==(S=g.setCookie.find((function(e){return e.includes("".concat(t.netaceaCookieName,"="))})))&&(w=S.split(";")[0].replace("".concat(t.netaceaCookieName,"="),"")),void 0!==g.response&&(b=g.response.apiCallStatus,k=t.getValueOrDefault(g.response.body,"Forbidden"),x=t.getValueOrDefault(g.response.mitigated,x)),a.reply([k,b,t.getValueOrDefault(g.setCookie,[]),g.sessionStatus,x,t.getValueOrDefault(w,""),t.getInjectHeaders(g)]),e.next=6;break;case 5:e.prev=5,C=e.catch(1),console.error("Could not reach Netacea mitigation API: ",C.message),a.reply(["",0,[],"",!1,"",[]]);case 6:case"end":return e.stop()}}),e,null,[[1,5]])})));return function(t,r){return e.apply(this,arguments)}}())}},{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:function(e){var t=null==e?void 0:e.split("; ");return[this.getCookie(this.mitataCookieName,t),this.getCookie(this.mitataCaptchaCookieName,t)]}},{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(e,r){var a=e.params(),n=t.getArrayValueOrDefault(a,0,""),i=t.getArrayValueOrDefault(a,1,""),o=t.getArrayValueOrDefault(a,2,"-1"),s=t.getArrayValueOrDefault(a,3,""),c=t.getArrayValueOrDefault(a,4,""),u=t.getArrayValueOrDefault(a,5,""),h=t.getArrayValueOrDefault(a,6,""),p=t.getArrayValueOrDefault(a,7,"0"),l=t.getArrayValueOrDefault(a,8,"0"),f=t.getArrayValueOrDefault(a,9,""),d=t.getArrayValueOrDefault(a,10,"");t.ingest({ip:n,userAgent:i,status:o,method:s,path:c,protocol:u,referer:h,bytesSent:p,requestTime:l,mitataCookie:f,sessionStatus:d}).catch((function(e){console.error("Could not reach Netacea ingest API: "+e.message)})),r.reply("done")}))}},{key:"makeRequest",value:(s=v(u().mark((function e(t){var r=this;return u().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://","");for(var n=T.request({agent:r.httpsAgent,host:t.host,path:t.path,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})}))})),i=0,o=["error","abort","timeout"];i<o.length;i++){var s=o[i];n.on(s,(function(e){a(e),n.destroyed||n.destroy()}))}"post"===t.method.toLowerCase()&&n.write(t.body),n.end()}));case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"mitigate",value:(o=v(u().mark((function e(t){var r,a,n,i;return u().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:403,apiCallStatus:null!==(i=r.apiCallStatus)&&void 0!==i?i:-1,mitigation:r.mitigation,mitigated:r.mitigated}),e.abrupt("return",a);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"inject",value:(i=v(u().mark((function e(t){var r;return u().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:(a=v(u().mark((function e(t){var r,a,n,i,o,s,c;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.url,i=t.method,o=t.mitataCookie,s=t.mitataCaptchaCookie,c=t.body,e.next=1,this.processMitigateRequest({clientIp:r,getBodyFn:function(){var e=v(u().mark((function e(){return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Promise.resolve(c);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:s,url:n,userAgent:a});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"ingest",value:(r=v(u().mark((function e(t){var r,a,n,i,o,s,c,h,p,l,f;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.status,i=t.method,o=t.path,s=t.protocol,c=t.referer,h=t.bytesSent,p=t.requestTime,l=t.mitataCookie,f=t.sessionStatus,e.next=1,this.callIngest({ip:r,userAgent:a,status:n,method:i,bytesSent:h,path:o,protocol:s,referer:c,requestTime:p,mitataCookie:l,sessionStatus:f,integrationType:"@netacea/f5".replace("@netacea/",""),integrationVersion:"4.3.142"});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,i,o,s}();function ae(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}module.exports=re;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/f5",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.142",
|
|
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": "7ab0a06c2d83d18eb5f850e2ee36043b183d3f35"
|
|
25
25
|
}
|