@harnessio/ff-nodejs-server-sdk
Advanced tools
Comparing version 1.3.7-rc.1 to 1.3.7
@@ -1,2 +0,2 @@ | ||
"use strict";var Ht=Object.create;var ie=Object.defineProperty;var Wt=Object.getOwnPropertyDescriptor;var Yt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,Jt=Object.prototype.hasOwnProperty;var Q=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Ne=(s,e)=>{for(var t in e)ie(s,t,{get:e[t],enumerable:!0})},Ue=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Yt(e))!Jt.call(s,r)&&r!==t&&ie(s,r,{get:()=>e[r],enumerable:!(i=Wt(e,r))||i.enumerable});return s};var P=(s,e,t)=>(t=s!=null?Ht(Qt(s)):{},Ue(e||!s||!s.__esModule?ie(t,"default",{value:s,enumerable:!0}):t,s)),Xt=s=>Ue(ie({},"__esModule",{value:!0}),s);var qe=Q((_i,ze)=>{"use strict";function ve(s){this.message=s}ve.prototype=new Error,ve.prototype.name="InvalidCharacterError";var Ve=typeof window<"u"&&window.atob&&window.atob.bind(window)||function(s){var e=String(s).replace(/=+$/,"");if(e.length%4==1)throw new ve("'atob' failed: The string to be decoded is not correctly encoded.");for(var t,i,r=0,n=0,o="";i=e.charAt(n++);~i&&(t=r%4?64*t+i:i,r++%4)?o+=String.fromCharCode(255&t>>(-2*r&6)):0)i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(i);return o};function Zt(s){var e=s.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Ve(t).replace(/(.)/g,function(i,r){var n=r.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}))}(e)}catch{return Ve(e)}}function J(s){this.message=s}function Be(s,e){if(typeof s!="string")throw new J("Invalid token specified");var t=(e=e||{}).header===!0?0:1;try{return JSON.parse(Zt(s.split(".")[t]))}catch(i){throw new J("Invalid token specified: "+i.message)}}J.prototype=new Error,J.prototype.name="InvalidTokenError";var me=Be;me.default=Be,me.InvalidTokenError=J,ze.exports=me});var Ge=Q((Ci,Ke)=>{"use strict";var ei=["ETIMEDOUT","ECONNRESET","EADDRINUSE","ESOCKETTIMEDOUT","ECONNREFUSED","EPIPE","EHOSTUNREACH","EAI_AGAIN"],ti=["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED"];Ke.exports=function(s){return!s||!s.code||ei.indexOf(s.code)!==-1?!0:ti.indexOf(s.code)===-1}});var Ye=Q(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});var ii=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s};L.isNetworkError=Ee;L.isRetryableError=re;L.isSafeRequestError=He;L.isIdempotentRequestError=Se;L.isNetworkOrIdempotentRequestError=Te;L.exponentialDelay=We;L.default=q;var ri=Ge(),si=ni(ri);function ni(s){return s&&s.__esModule?s:{default:s}}var ye="axios-retry";function Ee(s){return!s.response&&!!s.code&&s.code!=="ECONNABORTED"&&(0,si.default)(s)}var $e=["get","head","options"],oi=$e.concat(["put","delete"]);function re(s){return s.code!=="ECONNABORTED"&&(!s.response||s.response.status>=500&&s.response.status<=599)}function He(s){return s.config?re(s)&&$e.indexOf(s.config.method)!==-1:!1}function Se(s){return s.config?re(s)&&oi.indexOf(s.config.method)!==-1:!1}function Te(s){return Ee(s)||Se(s)}function ai(){return 0}function We(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=Math.pow(2,s)*100,t=e*.2*Math.random();return e+t}function je(s){var e=s[ye]||{};return e.retryCount=e.retryCount||0,s[ye]=e,e}function li(s,e){return Object.assign({},e,s[ye])}function ci(s,e){s.defaults.agent===e.agent&&delete e.agent,s.defaults.httpAgent===e.httpAgent&&delete e.httpAgent,s.defaults.httpsAgent===e.httpsAgent&&delete e.httpsAgent}async function hi(s,e,t,i){var r=t.retryCount<s&&e(i);if((typeof r>"u"?"undefined":ii(r))==="object")try{return await r,!0}catch{return!1}return r}function q(s,e){s.interceptors.request.use(function(t){var i=je(t);return i.lastRequestTime=Date.now(),t}),s.interceptors.response.use(null,async function(t){var i=t.config;if(!i)return Promise.reject(t);var r=li(i,e),n=r.retries,o=n===void 0?3:n,l=r.retryCondition,h=l===void 0?Te:l,c=r.retryDelay,a=c===void 0?ai:c,f=r.shouldResetTimeout,g=f===void 0?!1:f,p=je(i);if(await hi(o,h,p,t)){p.retryCount+=1;var v=a(p.retryCount,t);if(ci(s,i),!g&&i.timeout&&p.lastRequestTime){var T=Date.now()-p.lastRequestTime;i.timeout=Math.max(i.timeout-T-v,1)}return i.transformRequest=[function(u){return u}],new Promise(function(u){return setTimeout(function(){return u(s(i))},v)})}return Promise.reject(t)})}q.isNetworkError=Ee;q.isSafeRequestError=He;q.isIdempotentRequestError=Se;q.isNetworkOrIdempotentRequestError=Te;q.exponentialDelay=We;q.isRetryableError=re});var Je=Q((Oi,Qe)=>{"use strict";Qe.exports=Ye().default});var zt=Q((Er,Fe)=>{"use strict";(function(){var s=this;let e=o=>new TextEncoder().encode(o);function t(o,l){typeof o=="string"&&(o=e(o));for(var h=o.length,c=l^h,a=0,f;h>=4;)f=o[a]&255|(o[++a]&255)<<8|(o[++a]&255)<<16|(o[++a]&255)<<24,f=(f&65535)*1540483477+(((f>>>16)*1540483477&65535)<<16),f^=f>>>24,f=(f&65535)*1540483477+(((f>>>16)*1540483477&65535)<<16),c=(c&65535)*1540483477+(((c>>>16)*1540483477&65535)<<16)^f,h-=4,++a;switch(h){case 3:c^=(o[a+2]&255)<<16;case 2:c^=(o[a+1]&255)<<8;case 1:c^=o[a]&255,c=(c&65535)*1540483477+(((c>>>16)*1540483477&65535)<<16)}return c^=c>>>13,c=(c&65535)*1540483477+(((c>>>16)*1540483477&65535)<<16),c^=c>>>15,c>>>0}function i(o,l){typeof o=="string"&&(o=e(o));var h,c,a,f,g,p,v,T,u,d;for(h=o.length&3,c=o.length-h,a=l,g=3432918353,v=461845907,d=0;d<c;)u=o[d]&255|(o[++d]&255)<<8|(o[++d]&255)<<16|(o[++d]&255)<<24,++d,u=(u&65535)*g+(((u>>>16)*g&65535)<<16)&4294967295,u=u<<15|u>>>17,u=(u&65535)*v+(((u>>>16)*v&65535)<<16)&4294967295,a^=u,a=a<<13|a>>>19,f=(a&65535)*5+(((a>>>16)*5&65535)<<16)&4294967295,a=(f&65535)+27492+(((f>>>16)+58964&65535)<<16);switch(u=0,h){case 3:u^=(o[d+2]&255)<<16;case 2:u^=(o[d+1]&255)<<8;case 1:u^=o[d]&255,u=(u&65535)*g+(((u>>>16)*g&65535)<<16)&4294967295,u=u<<15|u>>>17,u=(u&65535)*v+(((u>>>16)*v&65535)<<16)&4294967295,a^=u}return a^=o.length,a^=a>>>16,a=(a&65535)*2246822507+(((a>>>16)*2246822507&65535)<<16)&4294967295,a^=a>>>13,a=(a&65535)*3266489909+(((a>>>16)*3266489909&65535)<<16)&4294967295,a^=a>>>16,a>>>0}var r=i;if(r.v2=t,r.v3=i,typeof Fe<"u")Fe.exports=r;else{var n=s.murmur;r.noConflict=function(){return s.murmur=n,r},s.murmur=r}})()});var xi={};Ne(xi,{Client:()=>W,Event:()=>pe,FileStore:()=>H,LRU:()=>Oe,default:()=>wi});module.exports=Xt(xi);var Gt=P(require("events")),jt=P(qe()),ke=P(require("axios")),Le=P(Je());var F=P(require("axios"));var Xe=P(require("axios")),x="http://localhost/api/1.0".replace(/\/+$/,"");var X=class{constructor(e,t=x,i=Xe.default){this.basePath=t;this.axios=i;e&&(this.configuration=e,this.basePath=e.basePath||this.basePath)}},se=class extends Error{constructor(t,i){super(i);this.field=t;this.name="RequiredError"}};var _="https://example.com",R=function(s,e,t){if(t==null)throw new se(e,`Required parameter ${e} was null or undefined when calling ${s}.`)};var k=async function(s,e){if(e&&e.accessToken){let t=typeof e.accessToken=="function"?await e.accessToken():await e.accessToken;s.Authorization="Bearer "+t}};var C=function(s,...e){let t=new URLSearchParams(s.search);for(let i of e)for(let r in i)if(Array.isArray(i[r])){t.delete(r);for(let n of i[r])t.append(r,n)}else t.set(r,i[r]);s.search=t.toString()},Ae=function(s,e,t){let i=typeof s!="string";return(i&&t&&t.isJsonMime?t.isJsonMime(e.headers["Content-Type"]):i)?JSON.stringify(s!==void 0?s:{}):s||""},I=function(s){return s.pathname+s.search+s.hash},O=function(s,e,t,i){return(r=e,n=t)=>{let o={...s.options,url:((i==null?void 0:i.basePath)||n)+s.url};return r.request(o)}};var ui=function(s){return{authenticate:async(e,t={})=>{let i="/client/auth",r=new URL(i,_),n;s&&(n=s.baseOptions);let o={method:"POST",...n,...t},l={},h={};l["Content-Type"]="application/json",C(r,h,t.query);let c=n&&n.headers?n.headers:{};return o.headers={...l,...c,...t.headers},o.data=Ae(e,o,s),{url:I(r),options:o}},getAllSegments:async(e,t,i={})=>{R("getAllSegments","environmentUUID",e);let r="/client/env/{environmentUUID}/target-segments".replace("{environmentUUID}",encodeURIComponent(String(e))),n=new URL(r,_),o;s&&(o=s.baseOptions);let l={method:"GET",...o,...i},h={},c={};await k(h,s),t!==void 0&&(c.cluster=t),C(n,c,i.query);let a=o&&o.headers?o.headers:{};return l.headers={...h,...a,...i.headers},{url:I(n),options:l}},getEvaluationByIdentifier:async(e,t,i,r,n={})=>{R("getEvaluationByIdentifier","environmentUUID",e),R("getEvaluationByIdentifier","feature",t),R("getEvaluationByIdentifier","target",i);let o="/client/env/{environmentUUID}/target/{target}/evaluations/{feature}".replace("{environmentUUID}",encodeURIComponent(String(e))).replace("{feature}",encodeURIComponent(String(t))).replace("{target}",encodeURIComponent(String(i))),l=new URL(o,_),h;s&&(h=s.baseOptions);let c={method:"GET",...h,...n},a={},f={};await k(a,s),r!==void 0&&(f.cluster=r),C(l,f,n.query);let g=h&&h.headers?h.headers:{};return c.headers={...a,...g,...n.headers},{url:I(l),options:c}},getEvaluations:async(e,t,i,r={})=>{R("getEvaluations","environmentUUID",e),R("getEvaluations","target",t);let n="/client/env/{environmentUUID}/target/{target}/evaluations".replace("{environmentUUID}",encodeURIComponent(String(e))).replace("{target}",encodeURIComponent(String(t))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"GET",...l,...r},c={},a={};await k(c,s),i!==void 0&&(a.cluster=i),C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},{url:I(o),options:h}},getFeatureConfig:async(e,t,i={})=>{R("getFeatureConfig","environmentUUID",e);let r="/client/env/{environmentUUID}/feature-configs".replace("{environmentUUID}",encodeURIComponent(String(e))),n=new URL(r,_),o;s&&(o=s.baseOptions);let l={method:"GET",...o,...i},h={},c={};await k(h,s),t!==void 0&&(c.cluster=t),C(n,c,i.query);let a=o&&o.headers?o.headers:{};return l.headers={...h,...a,...i.headers},{url:I(n),options:l}},getFeatureConfigByIdentifier:async(e,t,i,r={})=>{R("getFeatureConfigByIdentifier","identifier",e),R("getFeatureConfigByIdentifier","environmentUUID",t);let n="/client/env/{environmentUUID}/feature-configs/{identifier}".replace("{identifier}",encodeURIComponent(String(e))).replace("{environmentUUID}",encodeURIComponent(String(t))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"GET",...l,...r},c={},a={};await k(c,s),i!==void 0&&(a.cluster=i),C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},{url:I(o),options:h}},getSegmentByIdentifier:async(e,t,i,r={})=>{R("getSegmentByIdentifier","identifier",e),R("getSegmentByIdentifier","environmentUUID",t);let n="/client/env/{environmentUUID}/target-segments/{identifier}".replace("{identifier}",encodeURIComponent(String(e))).replace("{environmentUUID}",encodeURIComponent(String(t))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"GET",...l,...r},c={},a={};await k(c,s),i!==void 0&&(a.cluster=i),C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},{url:I(o),options:h}},stream:async(e,t,i={})=>{R("stream","aPIKey",e);let r="/stream",n=new URL(r,_),o;s&&(o=s.baseOptions);let l={method:"GET",...o,...i},h={},c={};await k(h,s),t!==void 0&&(c.cluster=t),e!=null&&(h["API-Key"]=String(e)),C(n,c,i.query);let a=o&&o.headers?o.headers:{};return l.headers={...h,...a,...i.headers},{url:I(n),options:l}}}},N=function(s){let e=ui(s);return{async authenticate(t,i){let r=await e.authenticate(t,i);return O(r,F.default,x,s)},async getAllSegments(t,i,r){let n=await e.getAllSegments(t,i,r);return O(n,F.default,x,s)},async getEvaluationByIdentifier(t,i,r,n,o){let l=await e.getEvaluationByIdentifier(t,i,r,n,o);return O(l,F.default,x,s)},async getEvaluations(t,i,r,n){let o=await e.getEvaluations(t,i,r,n);return O(o,F.default,x,s)},async getFeatureConfig(t,i,r){let n=await e.getFeatureConfig(t,i,r);return O(n,F.default,x,s)},async getFeatureConfigByIdentifier(t,i,r,n){let o=await e.getFeatureConfigByIdentifier(t,i,r,n);return O(o,F.default,x,s)},async getSegmentByIdentifier(t,i,r,n){let o=await e.getSegmentByIdentifier(t,i,r,n);return O(o,F.default,x,s)},async stream(t,i,r){let n=await e.stream(t,i,r);return O(n,F.default,x,s)}}};var ne=class extends X{authenticate(e,t){return N(this.configuration).authenticate(e,t).then(i=>i(this.axios,this.basePath))}getAllSegments(e,t,i){return N(this.configuration).getAllSegments(e,t,i).then(r=>r(this.axios,this.basePath))}getEvaluationByIdentifier(e,t,i,r,n){return N(this.configuration).getEvaluationByIdentifier(e,t,i,r,n).then(o=>o(this.axios,this.basePath))}getEvaluations(e,t,i,r){return N(this.configuration).getEvaluations(e,t,i,r).then(n=>n(this.axios,this.basePath))}getFeatureConfig(e,t,i){return N(this.configuration).getFeatureConfig(e,t,i).then(r=>r(this.axios,this.basePath))}getFeatureConfigByIdentifier(e,t,i,r){return N(this.configuration).getFeatureConfigByIdentifier(e,t,i,r).then(n=>n(this.axios,this.basePath))}getSegmentByIdentifier(e,t,i,r){return N(this.configuration).getSegmentByIdentifier(e,t,i,r).then(n=>n(this.axios,this.basePath))}stream(e,t,i){return N(this.configuration).stream(e,t,i).then(r=>r(this.axios,this.basePath))}},fi=function(s){return{postMetrics:async(e,t,i,r={})=>{R("postMetrics","environment",e);let n="/metrics/{environment}".replace("{environment}",encodeURIComponent(String(e))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"POST",...l,...r},c={},a={};await k(c,s),t!==void 0&&(a.cluster=t),c["Content-Type"]="application/json",C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},h.data=Ae(i,h,s),{url:I(o),options:h}}}},gi=function(s){let e=fi(s);return{async postMetrics(t,i,r,n){let o=await e.postMetrics(t,i,r,n);return O(o,F.default,x,s)}}};var oe=class extends X{postMetrics(e,t,i,r){return gi(this.configuration).postMetrics(e,t,i,r).then(n=>n(this.axios,this.basePath))}};var G=class{constructor(e={}){this.apiKey=e.apiKey,this.username=e.username,this.password=e.password,this.accessToken=e.accessToken,this.basePath=e.basePath,this.baseOptions=e.baseOptions,this.formDataCtor=e.formDataCtor}isJsonMime(e){let t=new RegExp("^(application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(;.*)?$","i");return e!==null&&(t.test(e)||e.toLowerCase()==="application/json-patch+json")}};var ae="1.3.7-rc.1";var Ze={1e3:"The SDK has successfully initialized",1001:"The SDK has failed to initialize due to an authentication error - defaults will be served",1002:"The SDK has failed to initialize due to a missing or empty API key - defaults will be served",2e3:"Authentication was successful",2001:"Authentication failed with a non-recoverable error",2002:"Authentication attempt failed:",2003:"Authentication failed and max retries have been exceeded",3e3:"Closing SDK",3001:"SDK Closed successfully",4e3:"Polling started, interval:",4001:"Polling stopped",5e3:"SSE stream successfully connected",5001:"SSE stream disconnected, reason:",5002:"SSE event received",5003:"SSE retrying to connect in",5004:"SSE stopped",6e3:"Evaluation successful: ",6001:"Evaluation Failed, returning default variation: ",7e3:"Metrics thread started with request interval:",7001:"Metrics stopped",7002:"Posting metrics failed, reason:",7003:"Metrics posted successfully"};function di(s){return s in Ze?Ze[s]:"Unknown SDK code"}function S(s,e=""){return`SDKCODE:${s}: ${di(s)} ${e}`}function et(s){s.warn(S(1002))}function tt(s,e){e.info(S(4e3,s/1e3+" seconds"))}function be(s){s.info(S(1e3))}function it(s){s.info(S(3e3))}function rt(s){s.info(S(3001))}function Re(s){s.info(S(4001))}function st(s){s.info(S(5e3))}function nt(s){s.debug(S(5002))}function ot(s){s.info(S(5004))}function at(s,e){e.info(S(7e3,s/1e3+" seconds"))}function lt(s){s.info(S(7003))}function ct(s){s.info(S(7001))}function Z(s,e,t,i){i.debug(S(6e3,`result=${s}, flag identifier=${e}, target=${JSON.stringify(t)}`))}function ht(s){s.warn(S(2001))}function ut(s){s.warn(S(1001))}function ft(s,e){e.warn(S(5001,s))}function gt(s,e){e.warn(S(5003,`${s}`))}function dt(s,e){e.warn(S(7002,s))}function D(s,e,t,i){i.warn(S(6001,`default variation used=${t}, flag=${s}, target=${JSON.stringify(e)}`))}var le=class{constructor(e,t,i,r,n,o){this.stopped=!0;this.initialized=!1;this.lastPollTime=0;this.api=i,this.options=r,this.environment=e,this.cluster=t,this.repository=o,this.eventBus=n,this.log=r.logger}poll(){if(this.stopped){this.log.info("PollingProcessor stopped"),Re(this.log);return}let e=new Date().getTime(),t=()=>{let i=new Date().getTime()-e,r=Math.max(this.options.pollInterval-i,0);this.timeout=setTimeout(()=>this.poll(),r)};if(this.lastPollTime>Date.now()-this.options.pollInterval){this.log.info(`Last poll was ${Math.round((Date.now()-this.lastPollTime)/1e3)} seconds ago, skipping flag refresh`),t();return}this.lastPollTime=Date.now(),Promise.all([this.retrieveFlags(),this.retrieveSegments()]).then(()=>{this.initialized||setTimeout(()=>{this.initialized=!0,this.eventBus.emit("poller_ready")},0)}).catch(i=>{this.eventBus.emit("poller_error",{error:i})}).finally(()=>{if(this.stopped){this.log.info("PollingProcessor stopped"),Re(this.log);return}t()})}async retrieveFlags(){try{this.log.debug("Fetching flags started");let e=await this.api.getFeatureConfig(this.environment,this.cluster);this.log.debug("Fetching flags finished"),e.data.forEach(t=>this.repository.setFlag(t.feature,t))}catch(e){throw this.log.error("Error loading flags",e),e}}async retrieveSegments(){try{this.log.debug("Fetching segments started");let e=await this.api.getAllSegments(this.environment,this.cluster);this.log.debug("Fetching segments finished"),e.data.forEach(t=>this.repository.setSegment(t.identifier,t))}catch(e){throw this.log.error("Error loading segments",e),e}}start(){if(!this.stopped){this.log.info("PollingProcessor already started");return}this.log.info("Starting PollingProcessor with request interval: ",this.options.pollInterval),this.stopped=!1,this.poll()}stop(){this.log.info("Stopping PollingProcessor"),this.stopped=!0}close(){this.log.info("Closing PollingProcessor"),this.stop(),clearTimeout(this.timeout),this.log.info("PollingProcessor closed")}};var pt=P(require("https")),mt=P(require("http"));var b=class b{constructor(e,t,i,r,n,o,l,h){this.retryAttempt=0;this.api=e,this.apiKey=t,this.environment=i,this.jwtToken=r,this.options=n,this.cluster=o,this.eventBus=l,this.repository=h,this.log=this.options.logger;let c=5e3,a=1e4;this.retryDelayMs=Math.floor(Math.random()*(a-c)+c)}start(){this.log.info("Starting new StreamProcessor");let e=`${this.options.baseUrl}/stream?cluster=${this.cluster}`,t={headers:{"Cache-Control":"no-cache",Accept:"text/event-stream",Authorization:`Bearer ${this.jwtToken}`,"API-Key":this.apiKey}},i=()=>{this.log.info(`SSE stream connected OK: ${e}`),this.retryAttempt=0,this.readyState=b.CONNECTED,this.eventBus.emit("stream_connected")},r=n=>{if(this.readyState!==b.CLOSED){this.retryAttempt+=1;let o=this.getRandomRetryDelayMs();ft(n,this.log),gt(o,this.log),this.readyState=b.RETRYING,this.eventBus.emit("stream_retrying"),setTimeout(()=>{this.log.info("SSE retrying to connect"),this.connect(e,t,i,r)},o)}};this.connect(e,t,i,r),this.eventBus.emit("stream_ready")}getRandomRetryDelayMs(){let e=this.retryDelayMs*this.retryAttempt;return Math.min(e,6e4)}connect(e,t,i,r){if(this.readyState===b.CONNECTED){this.log.debug("SSE already connected, skip retry");return}let n=e.startsWith("https:");this.log.debug("SSE HTTP start request",e),this.request=(n?pt.default:mt.default).request(e,t,o=>{if(this.log.debug("SSE got HTTP response code",o.statusCode),o.statusCode>=400&&o.statusCode<=599){r(`HTTP code ${o.statusCode}`);return}i(),o.on("data",l=>{nt(this.log),this.processData(l)}).on("close",()=>{r("SSE stream closed")})}).on("error",o=>{r("SSE request failed "+o.message)}).on("timeout",()=>{r("SSE request timed out after "+b.SSE_TIMEOUT_MS+"ms")}).setTimeout(b.SSE_TIMEOUT_MS),this.request.end()}processData(e){e.toString().split(/\r?\n/).forEach(i=>this.processLine(i))}processLine(e){if(e.startsWith("data:")){this.log.debug("SSE GOT:",e.substring(5));let t=JSON.parse(e.substring(5));t.domain==="flag"?this.msgProcessor(t,this.api.getFeatureConfigByIdentifier.bind(this.api),this.repository.setFlag.bind(this.repository),this.repository.deleteFlag.bind(this.repository)):t.domain==="target-segment"&&this.msgProcessor(t,this.api.getSegmentByIdentifier.bind(this.api),this.repository.setSegment.bind(this.repository),this.repository.deleteSegment.bind(this.repository))}}async msgProcessor(e,t,i,r){this.log.info("Processing message",e);try{if(e.event==="create"||e.event==="patch"){let{data:n}=await t(e.identifier,this.environment,this.cluster);i(e.identifier,n)}else e.event==="delete"&&r(e.identifier)}catch(n){throw this.log.error("Error while fetching data with identifier:",e.identifier,n),n}this.log.info("Processing message finished",e)}connected(){return this.readyState===b.CONNECTED}close(){if(this.readyState===b.CLOSED){this.log.info("SteamProcessor already closed");return}this.readyState=b.CLOSED,this.log.info("Closing StreamProcessor"),this.request.destroy(),this.request=void 0,this.eventBus.emit("stream_disconnected"),this.log.info("StreamProcessor closed"),ot(this.log)}};b.CONNECTED=1,b.RETRYING=2,b.CLOSED=3,b.SSE_TIMEOUT_MS=3e4;var ce=b;var Oe={};Ne(Oe,{default:()=>Ie});var ee=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,mi=typeof AbortController=="function",he=mi?AbortController:class{constructor(){this.signal=new vt}abort(e=new Error("This operation was aborted")){this.signal.reason=this.signal.reason||e,this.signal.aborted=!0,this.signal.dispatchEvent({type:"abort",target:this.signal})}},vi=typeof AbortSignal=="function",yi=typeof he.AbortSignal=="function",vt=vi?AbortSignal:yi?he.AbortController:class{constructor(){this.reason=void 0,this.aborted=!1,this._listeners=[]}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,this.onabort(e),this._listeners.forEach(t=>t(e),this))}onabort(){}addEventListener(e,t){e==="abort"&&this._listeners.push(t)}removeEventListener(e,t){e==="abort"&&(this._listeners=this._listeners.filter(i=>i!==t))}},_e=new Set,we=(s,e)=>{let t=`LRU_CACHE_OPTION_${s}`;ue(t)&&Ce(t,`${s} option`,`options.${e}`,$)},xe=(s,e)=>{let t=`LRU_CACHE_METHOD_${s}`;if(ue(t)){let{prototype:i}=$,{get:r}=Object.getOwnPropertyDescriptor(i,s);Ce(t,`${s} method`,`cache.${e}()`,r)}},Ei=(s,e)=>{let t=`LRU_CACHE_PROPERTY_${s}`;if(ue(t)){let{prototype:i}=$,{get:r}=Object.getOwnPropertyDescriptor(i,s);Ce(t,`${s} property`,`cache.${e}`,r)}},yt=(...s)=>{typeof process=="object"&&process&&typeof process.emitWarning=="function"?process.emitWarning(...s):console.error(...s)},ue=s=>!_e.has(s),Ce=(s,e,t,i)=>{_e.add(s);let r=`The ${e} is deprecated. Please use ${t} instead.`;yt(r,"DeprecationWarning",s,i)},U=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),Et=s=>U(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?j:null:null,j=class extends Array{constructor(e){super(e),this.fill(0)}},Pe=class{constructor(e){if(e===0)return[];let t=Et(e);this.heap=new t(e),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},$=class s{constructor(e={}){let{max:t=0,ttl:i,ttlResolution:r=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:l,allowStale:h,dispose:c,disposeAfter:a,noDisposeOnSet:f,noUpdateTTL:g,maxSize:p=0,maxEntrySize:v=0,sizeCalculation:T,fetchMethod:u,fetchContext:d,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:A,allowStaleOnFetchRejection:y,allowStaleOnFetchAbort:w,ignoreFetchAbort:m}=e,{length:B,maxAge:z,stale:M}=e instanceof s?{}:e;if(t!==0&&!U(t))throw new TypeError("max option must be a nonnegative integer");let K=t?Et(t):Array;if(!K)throw new Error("invalid max value: "+t);if(this.max=t,this.maxSize=p,this.maxEntrySize=v||this.maxSize,this.sizeCalculation=T||B,this.sizeCalculation){if(!this.maxSize&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=u||null,this.fetchMethod&&typeof this.fetchMethod!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=d,!this.fetchMethod&&d!==void 0)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(t).fill(null),this.valList=new Array(t).fill(null),this.next=new K(t),this.prev=new K(t),this.head=0,this.tail=0,this.free=new Pe(t),this.initialFill=1,this.size=0,typeof c=="function"&&(this.dispose=c),typeof a=="function"?(this.disposeAfter=a,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!f,this.noUpdateTTL=!!g,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!y,this.allowStaleOnFetchAbort=!!w,this.ignoreFetchAbort=!!m,this.maxEntrySize!==0){if(this.maxSize!==0&&!U(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!U(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!h||!!M,this.noDeleteOnStaleGet=!!A,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!l,this.ttlResolution=U(r)||r===0?r:1,this.ttlAutopurge=!!n,this.ttl=i||z||0,this.ttl){if(!U(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(this.max===0&&this.ttl===0&&this.maxSize===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){let Y="LRU_CACHE_UNBOUNDED";ue(Y)&&(_e.add(Y),yt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Y,s))}M&&we("stale","allowStale"),z&&we("maxAge","ttl"),B&&we("length","sizeCalculation")}getRemainingTTL(e){return this.has(e,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new j(this.max),this.starts=new j(this.max),this.setItemTTL=(i,r,n=ee.now())=>{if(this.starts[i]=r!==0?n:0,this.ttls[i]=r,r!==0&&this.ttlAutopurge){let o=setTimeout(()=>{this.isStale(i)&&this.delete(this.keyList[i])},r+1);o.unref&&o.unref()}},this.updateItemAge=i=>{this.starts[i]=this.ttls[i]!==0?ee.now():0},this.statusTTL=(i,r)=>{i&&(i.ttl=this.ttls[r],i.start=this.starts[r],i.now=e||t(),i.remainingTTL=i.now+i.ttl-i.start)};let e=0,t=()=>{let i=ee.now();if(this.ttlResolution>0){e=i;let r=setTimeout(()=>e=0,this.ttlResolution);r.unref&&r.unref()}return i};this.getRemainingTTL=i=>{let r=this.keyMap.get(i);return r===void 0?0:this.ttls[r]===0||this.starts[r]===0?1/0:this.starts[r]+this.ttls[r]-(e||t())},this.isStale=i=>this.ttls[i]!==0&&this.starts[i]!==0&&(e||t())-this.starts[i]>this.ttls[i]}updateItemAge(e){}statusTTL(e,t){}setItemTTL(e,t,i){}isStale(e){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new j(this.max),this.removeItemSize=e=>{this.calculatedSize-=this.sizes[e],this.sizes[e]=0},this.requireSize=(e,t,i,r)=>{if(this.isBackgroundFetch(t))return 0;if(!U(i))if(r){if(typeof r!="function")throw new TypeError("sizeCalculation must be a function");if(i=r(t,e),!U(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i},this.addItemSize=(e,t,i)=>{if(this.sizes[e]=t,this.maxSize){let r=this.maxSize-this.sizes[e];for(;this.calculatedSize>r;)this.evict(!0)}this.calculatedSize+=this.sizes[e],i&&(i.entrySize=t,i.totalCalculatedSize=this.calculatedSize)}}removeItemSize(e){}addItemSize(e,t){}requireSize(e,t,i,r){if(i||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache")}*indexes({allowStale:e=this.allowStale}={}){if(this.size)for(let t=this.tail;!(!this.isValidIndex(t)||((e||!this.isStale(t))&&(yield t),t===this.head));)t=this.prev[t]}*rindexes({allowStale:e=this.allowStale}={}){if(this.size)for(let t=this.head;!(!this.isValidIndex(t)||((e||!this.isStale(t))&&(yield t),t===this.tail));)t=this.next[t]}isValidIndex(e){return e!==void 0&&this.keyMap.get(this.keyList[e])===e}*entries(){for(let e of this.indexes())this.valList[e]!==void 0&&this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield[this.keyList[e],this.valList[e]])}*rentries(){for(let e of this.rindexes())this.valList[e]!==void 0&&this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield[this.keyList[e],this.valList[e]])}*keys(){for(let e of this.indexes())this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.keyList[e])}*rkeys(){for(let e of this.rindexes())this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.keyList[e])}*values(){for(let e of this.indexes())this.valList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.valList[e])}*rvalues(){for(let e of this.rindexes())this.valList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.valList[e])}[Symbol.iterator](){return this.entries()}find(e,t){for(let i of this.indexes()){let r=this.valList[i],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;if(n!==void 0&&e(n,this.keyList[i],this))return this.get(this.keyList[i],t)}}forEach(e,t=this){for(let i of this.indexes()){let r=this.valList[i],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;n!==void 0&&e.call(t,n,this.keyList[i],this)}}rforEach(e,t=this){for(let i of this.rindexes()){let r=this.valList[i],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;n!==void 0&&e.call(t,n,this.keyList[i],this)}}get prune(){return xe("prune","purgeStale"),this.purgeStale}purgeStale(){let e=!1;for(let t of this.rindexes({allowStale:!0}))this.isStale(t)&&(this.delete(this.keyList[t]),e=!0);return e}dump(){let e=[];for(let t of this.indexes({allowStale:!0})){let i=this.keyList[t],r=this.valList[t],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;if(n===void 0)continue;let o={value:n};if(this.ttls){o.ttl=this.ttls[t];let l=ee.now()-this.starts[t];o.start=Math.floor(Date.now()-l)}this.sizes&&(o.size=this.sizes[t]),e.unshift([i,o])}return e}load(e){this.clear();for(let[t,i]of e){if(i.start){let r=Date.now()-i.start;i.start=ee.now()-r}this.set(t,i.value,i)}}dispose(e,t,i){}set(e,t,{ttl:i=this.ttl,start:r,noDisposeOnSet:n=this.noDisposeOnSet,size:o=0,sizeCalculation:l=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,status:c}={}){if(o=this.requireSize(e,t,o,l),this.maxEntrySize&&o>this.maxEntrySize)return c&&(c.set="miss",c.maxEntrySizeExceeded=!0),this.delete(e),this;let a=this.size===0?void 0:this.keyMap.get(e);if(a===void 0)a=this.newIndex(),this.keyList[a]=e,this.valList[a]=t,this.keyMap.set(e,a),this.next[this.tail]=a,this.prev[a]=this.tail,this.tail=a,this.size++,this.addItemSize(a,o,c),c&&(c.set="add"),h=!1;else{this.moveToTail(a);let f=this.valList[a];if(t!==f){if(this.isBackgroundFetch(f)?f.__abortController.abort(new Error("replaced")):n||(this.dispose(f,e,"set"),this.disposeAfter&&this.disposed.push([f,e,"set"])),this.removeItemSize(a),this.valList[a]=t,this.addItemSize(a,o,c),c){c.set="replace";let g=f&&this.isBackgroundFetch(f)?f.__staleWhileFetching:f;g!==void 0&&(c.oldValue=g)}}else c&&(c.set="update")}if(i!==0&&this.ttl===0&&!this.ttls&&this.initializeTTLTracking(),h||this.setItemTTL(a,i,r),this.statusTTL(c,a),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return this.size===0?this.tail:this.size===this.max&&this.max!==0?this.evict(!1):this.free.length!==0?this.free.pop():this.initialFill++}pop(){if(this.size){let e=this.valList[this.head];return this.evict(!0),e}}evict(e){let t=this.head,i=this.keyList[t],r=this.valList[t];return this.isBackgroundFetch(r)?r.__abortController.abort(new Error("evicted")):(this.dispose(r,i,"evict"),this.disposeAfter&&this.disposed.push([r,i,"evict"])),this.removeItemSize(t),e&&(this.keyList[t]=null,this.valList[t]=null,this.free.push(t)),this.head=this.next[t],this.keyMap.delete(i),this.size--,t}has(e,{updateAgeOnHas:t=this.updateAgeOnHas,status:i}={}){let r=this.keyMap.get(e);if(r!==void 0)if(this.isStale(r))i&&(i.has="stale",this.statusTTL(i,r));else return t&&this.updateItemAge(r),i&&(i.has="hit"),this.statusTTL(i,r),!0;else i&&(i.has="miss");return!1}peek(e,{allowStale:t=this.allowStale}={}){let i=this.keyMap.get(e);if(i!==void 0&&(t||!this.isStale(i))){let r=this.valList[i];return this.isBackgroundFetch(r)?r.__staleWhileFetching:r}}backgroundFetch(e,t,i,r){let n=t===void 0?void 0:this.valList[t];if(this.isBackgroundFetch(n))return n;let o=new he;i.signal&&i.signal.addEventListener("abort",()=>o.abort(i.signal.reason));let l={signal:o.signal,options:i,context:r},h=(p,v=!1)=>{let{aborted:T}=o.signal,u=i.ignoreFetchAbort&&p!==void 0;return i.status&&(T&&!v?(i.status.fetchAborted=!0,i.status.fetchError=o.signal.reason,u&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),T&&!u&&!v?a(o.signal.reason):(this.valList[t]===g&&(p===void 0?g.__staleWhileFetching?this.valList[t]=g.__staleWhileFetching:this.delete(e):(i.status&&(i.status.fetchUpdated=!0),this.set(e,p,l.options))),p)},c=p=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=p),a(p)),a=p=>{let{aborted:v}=o.signal,T=v&&i.allowStaleOnFetchAbort,u=T||i.allowStaleOnFetchRejection,d=u||i.noDeleteOnFetchRejection;if(this.valList[t]===g&&(!d||g.__staleWhileFetching===void 0?this.delete(e):T||(this.valList[t]=g.__staleWhileFetching)),u)return i.status&&g.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),g.__staleWhileFetching;if(g.__returned===g)throw p},f=(p,v)=>{this.fetchMethod(e,n,l).then(T=>p(T),v),o.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(p(),i.allowStaleOnFetchAbort&&(p=T=>h(T,!0)))})};i.status&&(i.status.fetchDispatched=!0);let g=new Promise(f).then(h,c);return g.__abortController=o,g.__staleWhileFetching=n,g.__returned=null,t===void 0?(this.set(e,g,{...l.options,status:void 0}),t=this.keyMap.get(e)):this.valList[t]=g,g}isBackgroundFetch(e){return e&&typeof e=="object"&&typeof e.then=="function"&&Object.prototype.hasOwnProperty.call(e,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(e,"__returned")&&(e.__returned===e||e.__returned===null)}async fetch(e,{allowStale:t=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:l=0,sizeCalculation:h=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:a=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:f=this.allowStaleOnFetchRejection,ignoreFetchAbort:g=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,fetchContext:v=this.fetchContext,forceRefresh:T=!1,status:u,signal:d}={}){if(!this.fetchMethod)return u&&(u.fetch="get"),this.get(e,{allowStale:t,updateAgeOnGet:i,noDeleteOnStaleGet:r,status:u});let E={allowStale:t,updateAgeOnGet:i,noDeleteOnStaleGet:r,ttl:n,noDisposeOnSet:o,size:l,sizeCalculation:h,noUpdateTTL:c,noDeleteOnFetchRejection:a,allowStaleOnFetchRejection:f,allowStaleOnFetchAbort:p,ignoreFetchAbort:g,status:u,signal:d},A=this.keyMap.get(e);if(A===void 0){u&&(u.fetch="miss");let y=this.backgroundFetch(e,A,E,v);return y.__returned=y}else{let y=this.valList[A];if(this.isBackgroundFetch(y)){let M=t&&y.__staleWhileFetching!==void 0;return u&&(u.fetch="inflight",M&&(u.returnedStale=!0)),M?y.__staleWhileFetching:y.__returned=y}let w=this.isStale(A);if(!T&&!w)return u&&(u.fetch="hit"),this.moveToTail(A),i&&this.updateItemAge(A),this.statusTTL(u,A),y;let m=this.backgroundFetch(e,A,E,v),B=m.__staleWhileFetching!==void 0,z=B&&t;return u&&(u.fetch=B&&w?"stale":"refresh",z&&w&&(u.returnedStale=!0)),z?m.__staleWhileFetching:m.__returned=m}}get(e,{allowStale:t=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,status:n}={}){let o=this.keyMap.get(e);if(o!==void 0){let l=this.valList[o],h=this.isBackgroundFetch(l);return this.statusTTL(n,o),this.isStale(o)?(n&&(n.get="stale"),h?(n&&(n.returnedStale=t&&l.__staleWhileFetching!==void 0),t?l.__staleWhileFetching:void 0):(r||this.delete(e),n&&(n.returnedStale=t),t?l:void 0)):(n&&(n.get="hit"),h?l.__staleWhileFetching:(this.moveToTail(o),i&&this.updateItemAge(o),l))}else n&&(n.get="miss")}connect(e,t){this.prev[t]=e,this.next[e]=t}moveToTail(e){e!==this.tail&&(e===this.head?this.head=this.next[e]:this.connect(this.prev[e],this.next[e]),this.connect(this.tail,e),this.tail=e)}get del(){return xe("del","delete"),this.delete}delete(e){let t=!1;if(this.size!==0){let i=this.keyMap.get(e);if(i!==void 0)if(t=!0,this.size===1)this.clear();else{this.removeItemSize(i);let r=this.valList[i];this.isBackgroundFetch(r)?r.__abortController.abort(new Error("deleted")):(this.dispose(r,e,"delete"),this.disposeAfter&&this.disposed.push([r,e,"delete"])),this.keyMap.delete(e),this.keyList[i]=null,this.valList[i]=null,i===this.tail?this.tail=this.prev[i]:i===this.head?this.head=this.next[i]:(this.next[this.prev[i]]=this.next[i],this.prev[this.next[i]]=this.prev[i]),this.size--,this.free.push(i)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return t}clear(){for(let e of this.rindexes({allowStale:!0})){let t=this.valList[e];if(this.isBackgroundFetch(t))t.__abortController.abort(new Error("deleted"));else{let i=this.keyList[e];this.dispose(t,i,"delete"),this.disposeAfter&&this.disposed.push([t,i,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return xe("reset","clear"),this.clear}get length(){return Ei("length","size"),this.size}static get AbortController(){return he}static get AbortSignal(){return vt}},Ie=$;var fe=class{trace(e,...t){console.trace(e,...t)}debug(e,...t){console.debug(e,...t)}info(e,...t){console.info(e,...t)}warn(e,...t){console.warn(e,...t)}error(e,...t){console.error(e,...t)}};var St=P(require("keyv")),Tt=require("keyv-file"),H=class{constructor(e={}){this.keyvFile=new Tt.KeyvFile(e),this.keyv=new St.default({store:this.keyvFile})}set(e,t){return this.keyv.set(e,t)}get(e){return this.keyv.get(e)}del(e){return this.keyv.delete(e)}keys(){return Promise.resolve(function*(e){for(let t of e)yield t}(this.keyvFile.keys()))}};var At=100;var bt="featureIdentifier",Rt="featureName",wt="variationIdentifier";var xt="target",Pt="SDK_VERSION",_t="SDK_TYPE",Ct="server",It="SDK_LANGUAGE",Ot="javascript",Ft="global",te="segmentMatch",Dt="in",Lt="equal",kt="gt",Mt="starts_with",Nt="ends_with",Ut="contains",Vt="equal_sensitive",Si="https://config.ff.harness.io/api/1.0",Ti="https://events.ff.harness.io/api/1.0",Ai=1e3,Bt=60*Ai,bi=1*Bt,Ri=1*Bt,V={baseUrl:Si,eventsUrl:Ti,pollInterval:bi,eventsSyncInterval:Ri,enableStream:!0,enableAnalytics:!0,cache:new Ie({max:100}),store:new H,logger:new fe};var qt=P(zt());var ge=class{constructor(e,t){this.query=e,this.log=t}getAttrValue(e,t){var i;return e[t]||((i=e.attributes)==null?void 0:i[t])}findVariation(e,t){return e.find(i=>i.identifier===t)}getNormalizedNumberWithNormalizer(e,t,i){let r=[t,e].join(":");return parseInt((0,qt.default)(r).toString())%i+1}getNormalizedNumber(e,t){return this.getNormalizedNumberWithNormalizer(e,t,At)}isEnabled(e,t,i){let r=this.getAttrValue(e,t);if(!r)return!1;let n=this.getNormalizedNumber(r,t);return i>0&&n<=i}evaluateDistribution(e,t){if(!e)return;let i="",r=0;for(let n of e.variations)if(i=n.variation,r+=n.weight,this.isEnabled(t,e.bucketBy,r))return n.variation;return i}async isTargetIncludedOrExcludedInSegment(e,t){var i,r;for(let n of e){let o=await this.query.getSegment(n);if(o){if((i=o.excluded)!=null&&i.find(l=>l.identifier===t.identifier))return this.log.debug(`Target %s excluded from segment %s via exclude list | ||
"use strict";var Ht=Object.create;var ie=Object.defineProperty;var Wt=Object.getOwnPropertyDescriptor;var Yt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,Jt=Object.prototype.hasOwnProperty;var Q=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Ne=(s,e)=>{for(var t in e)ie(s,t,{get:e[t],enumerable:!0})},Ue=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Yt(e))!Jt.call(s,r)&&r!==t&&ie(s,r,{get:()=>e[r],enumerable:!(i=Wt(e,r))||i.enumerable});return s};var P=(s,e,t)=>(t=s!=null?Ht(Qt(s)):{},Ue(e||!s||!s.__esModule?ie(t,"default",{value:s,enumerable:!0}):t,s)),Xt=s=>Ue(ie({},"__esModule",{value:!0}),s);var qe=Q((_i,ze)=>{"use strict";function ve(s){this.message=s}ve.prototype=new Error,ve.prototype.name="InvalidCharacterError";var Ve=typeof window<"u"&&window.atob&&window.atob.bind(window)||function(s){var e=String(s).replace(/=+$/,"");if(e.length%4==1)throw new ve("'atob' failed: The string to be decoded is not correctly encoded.");for(var t,i,r=0,n=0,o="";i=e.charAt(n++);~i&&(t=r%4?64*t+i:i,r++%4)?o+=String.fromCharCode(255&t>>(-2*r&6)):0)i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(i);return o};function Zt(s){var e=s.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(Ve(t).replace(/(.)/g,function(i,r){var n=r.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n}))}(e)}catch{return Ve(e)}}function J(s){this.message=s}function Be(s,e){if(typeof s!="string")throw new J("Invalid token specified");var t=(e=e||{}).header===!0?0:1;try{return JSON.parse(Zt(s.split(".")[t]))}catch(i){throw new J("Invalid token specified: "+i.message)}}J.prototype=new Error,J.prototype.name="InvalidTokenError";var me=Be;me.default=Be,me.InvalidTokenError=J,ze.exports=me});var Ge=Q((Ci,Ke)=>{"use strict";var ei=["ETIMEDOUT","ECONNRESET","EADDRINUSE","ESOCKETTIMEDOUT","ECONNREFUSED","EPIPE","EHOSTUNREACH","EAI_AGAIN"],ti=["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED"];Ke.exports=function(s){return!s||!s.code||ei.indexOf(s.code)!==-1?!0:ti.indexOf(s.code)===-1}});var Ye=Q(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});var ii=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s};L.isNetworkError=Ee;L.isRetryableError=re;L.isSafeRequestError=He;L.isIdempotentRequestError=Se;L.isNetworkOrIdempotentRequestError=Te;L.exponentialDelay=We;L.default=q;var ri=Ge(),si=ni(ri);function ni(s){return s&&s.__esModule?s:{default:s}}var ye="axios-retry";function Ee(s){return!s.response&&!!s.code&&s.code!=="ECONNABORTED"&&(0,si.default)(s)}var $e=["get","head","options"],oi=$e.concat(["put","delete"]);function re(s){return s.code!=="ECONNABORTED"&&(!s.response||s.response.status>=500&&s.response.status<=599)}function He(s){return s.config?re(s)&&$e.indexOf(s.config.method)!==-1:!1}function Se(s){return s.config?re(s)&&oi.indexOf(s.config.method)!==-1:!1}function Te(s){return Ee(s)||Se(s)}function ai(){return 0}function We(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=Math.pow(2,s)*100,t=e*.2*Math.random();return e+t}function je(s){var e=s[ye]||{};return e.retryCount=e.retryCount||0,s[ye]=e,e}function li(s,e){return Object.assign({},e,s[ye])}function ci(s,e){s.defaults.agent===e.agent&&delete e.agent,s.defaults.httpAgent===e.httpAgent&&delete e.httpAgent,s.defaults.httpsAgent===e.httpsAgent&&delete e.httpsAgent}async function hi(s,e,t,i){var r=t.retryCount<s&&e(i);if((typeof r>"u"?"undefined":ii(r))==="object")try{return await r,!0}catch{return!1}return r}function q(s,e){s.interceptors.request.use(function(t){var i=je(t);return i.lastRequestTime=Date.now(),t}),s.interceptors.response.use(null,async function(t){var i=t.config;if(!i)return Promise.reject(t);var r=li(i,e),n=r.retries,o=n===void 0?3:n,l=r.retryCondition,h=l===void 0?Te:l,c=r.retryDelay,a=c===void 0?ai:c,f=r.shouldResetTimeout,g=f===void 0?!1:f,p=je(i);if(await hi(o,h,p,t)){p.retryCount+=1;var v=a(p.retryCount,t);if(ci(s,i),!g&&i.timeout&&p.lastRequestTime){var T=Date.now()-p.lastRequestTime;i.timeout=Math.max(i.timeout-T-v,1)}return i.transformRequest=[function(u){return u}],new Promise(function(u){return setTimeout(function(){return u(s(i))},v)})}return Promise.reject(t)})}q.isNetworkError=Ee;q.isSafeRequestError=He;q.isIdempotentRequestError=Se;q.isNetworkOrIdempotentRequestError=Te;q.exponentialDelay=We;q.isRetryableError=re});var Je=Q((Oi,Qe)=>{"use strict";Qe.exports=Ye().default});var zt=Q((Er,Fe)=>{"use strict";(function(){var s=this;let e=o=>new TextEncoder().encode(o);function t(o,l){typeof o=="string"&&(o=e(o));for(var h=o.length,c=l^h,a=0,f;h>=4;)f=o[a]&255|(o[++a]&255)<<8|(o[++a]&255)<<16|(o[++a]&255)<<24,f=(f&65535)*1540483477+(((f>>>16)*1540483477&65535)<<16),f^=f>>>24,f=(f&65535)*1540483477+(((f>>>16)*1540483477&65535)<<16),c=(c&65535)*1540483477+(((c>>>16)*1540483477&65535)<<16)^f,h-=4,++a;switch(h){case 3:c^=(o[a+2]&255)<<16;case 2:c^=(o[a+1]&255)<<8;case 1:c^=o[a]&255,c=(c&65535)*1540483477+(((c>>>16)*1540483477&65535)<<16)}return c^=c>>>13,c=(c&65535)*1540483477+(((c>>>16)*1540483477&65535)<<16),c^=c>>>15,c>>>0}function i(o,l){typeof o=="string"&&(o=e(o));var h,c,a,f,g,p,v,T,u,d;for(h=o.length&3,c=o.length-h,a=l,g=3432918353,v=461845907,d=0;d<c;)u=o[d]&255|(o[++d]&255)<<8|(o[++d]&255)<<16|(o[++d]&255)<<24,++d,u=(u&65535)*g+(((u>>>16)*g&65535)<<16)&4294967295,u=u<<15|u>>>17,u=(u&65535)*v+(((u>>>16)*v&65535)<<16)&4294967295,a^=u,a=a<<13|a>>>19,f=(a&65535)*5+(((a>>>16)*5&65535)<<16)&4294967295,a=(f&65535)+27492+(((f>>>16)+58964&65535)<<16);switch(u=0,h){case 3:u^=(o[d+2]&255)<<16;case 2:u^=(o[d+1]&255)<<8;case 1:u^=o[d]&255,u=(u&65535)*g+(((u>>>16)*g&65535)<<16)&4294967295,u=u<<15|u>>>17,u=(u&65535)*v+(((u>>>16)*v&65535)<<16)&4294967295,a^=u}return a^=o.length,a^=a>>>16,a=(a&65535)*2246822507+(((a>>>16)*2246822507&65535)<<16)&4294967295,a^=a>>>13,a=(a&65535)*3266489909+(((a>>>16)*3266489909&65535)<<16)&4294967295,a^=a>>>16,a>>>0}var r=i;if(r.v2=t,r.v3=i,typeof Fe<"u")Fe.exports=r;else{var n=s.murmur;r.noConflict=function(){return s.murmur=n,r},s.murmur=r}})()});var xi={};Ne(xi,{Client:()=>W,Event:()=>pe,FileStore:()=>H,LRU:()=>Oe,default:()=>wi});module.exports=Xt(xi);var Gt=P(require("events")),jt=P(qe()),ke=P(require("axios")),Le=P(Je());var F=P(require("axios"));var Xe=P(require("axios")),x="http://localhost/api/1.0".replace(/\/+$/,"");var X=class{constructor(e,t=x,i=Xe.default){this.basePath=t;this.axios=i;e&&(this.configuration=e,this.basePath=e.basePath||this.basePath)}},se=class extends Error{constructor(t,i){super(i);this.field=t;this.name="RequiredError"}};var _="https://example.com",R=function(s,e,t){if(t==null)throw new se(e,`Required parameter ${e} was null or undefined when calling ${s}.`)};var k=async function(s,e){if(e&&e.accessToken){let t=typeof e.accessToken=="function"?await e.accessToken():await e.accessToken;s.Authorization="Bearer "+t}};var C=function(s,...e){let t=new URLSearchParams(s.search);for(let i of e)for(let r in i)if(Array.isArray(i[r])){t.delete(r);for(let n of i[r])t.append(r,n)}else t.set(r,i[r]);s.search=t.toString()},Ae=function(s,e,t){let i=typeof s!="string";return(i&&t&&t.isJsonMime?t.isJsonMime(e.headers["Content-Type"]):i)?JSON.stringify(s!==void 0?s:{}):s||""},I=function(s){return s.pathname+s.search+s.hash},O=function(s,e,t,i){return(r=e,n=t)=>{let o={...s.options,url:((i==null?void 0:i.basePath)||n)+s.url};return r.request(o)}};var ui=function(s){return{authenticate:async(e,t={})=>{let i="/client/auth",r=new URL(i,_),n;s&&(n=s.baseOptions);let o={method:"POST",...n,...t},l={},h={};l["Content-Type"]="application/json",C(r,h,t.query);let c=n&&n.headers?n.headers:{};return o.headers={...l,...c,...t.headers},o.data=Ae(e,o,s),{url:I(r),options:o}},getAllSegments:async(e,t,i={})=>{R("getAllSegments","environmentUUID",e);let r="/client/env/{environmentUUID}/target-segments".replace("{environmentUUID}",encodeURIComponent(String(e))),n=new URL(r,_),o;s&&(o=s.baseOptions);let l={method:"GET",...o,...i},h={},c={};await k(h,s),t!==void 0&&(c.cluster=t),C(n,c,i.query);let a=o&&o.headers?o.headers:{};return l.headers={...h,...a,...i.headers},{url:I(n),options:l}},getEvaluationByIdentifier:async(e,t,i,r,n={})=>{R("getEvaluationByIdentifier","environmentUUID",e),R("getEvaluationByIdentifier","feature",t),R("getEvaluationByIdentifier","target",i);let o="/client/env/{environmentUUID}/target/{target}/evaluations/{feature}".replace("{environmentUUID}",encodeURIComponent(String(e))).replace("{feature}",encodeURIComponent(String(t))).replace("{target}",encodeURIComponent(String(i))),l=new URL(o,_),h;s&&(h=s.baseOptions);let c={method:"GET",...h,...n},a={},f={};await k(a,s),r!==void 0&&(f.cluster=r),C(l,f,n.query);let g=h&&h.headers?h.headers:{};return c.headers={...a,...g,...n.headers},{url:I(l),options:c}},getEvaluations:async(e,t,i,r={})=>{R("getEvaluations","environmentUUID",e),R("getEvaluations","target",t);let n="/client/env/{environmentUUID}/target/{target}/evaluations".replace("{environmentUUID}",encodeURIComponent(String(e))).replace("{target}",encodeURIComponent(String(t))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"GET",...l,...r},c={},a={};await k(c,s),i!==void 0&&(a.cluster=i),C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},{url:I(o),options:h}},getFeatureConfig:async(e,t,i={})=>{R("getFeatureConfig","environmentUUID",e);let r="/client/env/{environmentUUID}/feature-configs".replace("{environmentUUID}",encodeURIComponent(String(e))),n=new URL(r,_),o;s&&(o=s.baseOptions);let l={method:"GET",...o,...i},h={},c={};await k(h,s),t!==void 0&&(c.cluster=t),C(n,c,i.query);let a=o&&o.headers?o.headers:{};return l.headers={...h,...a,...i.headers},{url:I(n),options:l}},getFeatureConfigByIdentifier:async(e,t,i,r={})=>{R("getFeatureConfigByIdentifier","identifier",e),R("getFeatureConfigByIdentifier","environmentUUID",t);let n="/client/env/{environmentUUID}/feature-configs/{identifier}".replace("{identifier}",encodeURIComponent(String(e))).replace("{environmentUUID}",encodeURIComponent(String(t))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"GET",...l,...r},c={},a={};await k(c,s),i!==void 0&&(a.cluster=i),C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},{url:I(o),options:h}},getSegmentByIdentifier:async(e,t,i,r={})=>{R("getSegmentByIdentifier","identifier",e),R("getSegmentByIdentifier","environmentUUID",t);let n="/client/env/{environmentUUID}/target-segments/{identifier}".replace("{identifier}",encodeURIComponent(String(e))).replace("{environmentUUID}",encodeURIComponent(String(t))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"GET",...l,...r},c={},a={};await k(c,s),i!==void 0&&(a.cluster=i),C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},{url:I(o),options:h}},stream:async(e,t,i={})=>{R("stream","aPIKey",e);let r="/stream",n=new URL(r,_),o;s&&(o=s.baseOptions);let l={method:"GET",...o,...i},h={},c={};await k(h,s),t!==void 0&&(c.cluster=t),e!=null&&(h["API-Key"]=String(e)),C(n,c,i.query);let a=o&&o.headers?o.headers:{};return l.headers={...h,...a,...i.headers},{url:I(n),options:l}}}},N=function(s){let e=ui(s);return{async authenticate(t,i){let r=await e.authenticate(t,i);return O(r,F.default,x,s)},async getAllSegments(t,i,r){let n=await e.getAllSegments(t,i,r);return O(n,F.default,x,s)},async getEvaluationByIdentifier(t,i,r,n,o){let l=await e.getEvaluationByIdentifier(t,i,r,n,o);return O(l,F.default,x,s)},async getEvaluations(t,i,r,n){let o=await e.getEvaluations(t,i,r,n);return O(o,F.default,x,s)},async getFeatureConfig(t,i,r){let n=await e.getFeatureConfig(t,i,r);return O(n,F.default,x,s)},async getFeatureConfigByIdentifier(t,i,r,n){let o=await e.getFeatureConfigByIdentifier(t,i,r,n);return O(o,F.default,x,s)},async getSegmentByIdentifier(t,i,r,n){let o=await e.getSegmentByIdentifier(t,i,r,n);return O(o,F.default,x,s)},async stream(t,i,r){let n=await e.stream(t,i,r);return O(n,F.default,x,s)}}};var ne=class extends X{authenticate(e,t){return N(this.configuration).authenticate(e,t).then(i=>i(this.axios,this.basePath))}getAllSegments(e,t,i){return N(this.configuration).getAllSegments(e,t,i).then(r=>r(this.axios,this.basePath))}getEvaluationByIdentifier(e,t,i,r,n){return N(this.configuration).getEvaluationByIdentifier(e,t,i,r,n).then(o=>o(this.axios,this.basePath))}getEvaluations(e,t,i,r){return N(this.configuration).getEvaluations(e,t,i,r).then(n=>n(this.axios,this.basePath))}getFeatureConfig(e,t,i){return N(this.configuration).getFeatureConfig(e,t,i).then(r=>r(this.axios,this.basePath))}getFeatureConfigByIdentifier(e,t,i,r){return N(this.configuration).getFeatureConfigByIdentifier(e,t,i,r).then(n=>n(this.axios,this.basePath))}getSegmentByIdentifier(e,t,i,r){return N(this.configuration).getSegmentByIdentifier(e,t,i,r).then(n=>n(this.axios,this.basePath))}stream(e,t,i){return N(this.configuration).stream(e,t,i).then(r=>r(this.axios,this.basePath))}},fi=function(s){return{postMetrics:async(e,t,i,r={})=>{R("postMetrics","environment",e);let n="/metrics/{environment}".replace("{environment}",encodeURIComponent(String(e))),o=new URL(n,_),l;s&&(l=s.baseOptions);let h={method:"POST",...l,...r},c={},a={};await k(c,s),t!==void 0&&(a.cluster=t),c["Content-Type"]="application/json",C(o,a,r.query);let f=l&&l.headers?l.headers:{};return h.headers={...c,...f,...r.headers},h.data=Ae(i,h,s),{url:I(o),options:h}}}},gi=function(s){let e=fi(s);return{async postMetrics(t,i,r,n){let o=await e.postMetrics(t,i,r,n);return O(o,F.default,x,s)}}};var oe=class extends X{postMetrics(e,t,i,r){return gi(this.configuration).postMetrics(e,t,i,r).then(n=>n(this.axios,this.basePath))}};var G=class{constructor(e={}){this.apiKey=e.apiKey,this.username=e.username,this.password=e.password,this.accessToken=e.accessToken,this.basePath=e.basePath,this.baseOptions=e.baseOptions,this.formDataCtor=e.formDataCtor}isJsonMime(e){let t=new RegExp("^(application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(;.*)?$","i");return e!==null&&(t.test(e)||e.toLowerCase()==="application/json-patch+json")}};var ae="1.3.7";var Ze={1e3:"The SDK has successfully initialized",1001:"The SDK has failed to initialize due to an authentication error - defaults will be served",1002:"The SDK has failed to initialize due to a missing or empty API key - defaults will be served",2e3:"Authentication was successful",2001:"Authentication failed with a non-recoverable error",2002:"Authentication attempt failed:",2003:"Authentication failed and max retries have been exceeded",3e3:"Closing SDK",3001:"SDK Closed successfully",4e3:"Polling started, interval:",4001:"Polling stopped",5e3:"SSE stream successfully connected",5001:"SSE stream disconnected, reason:",5002:"SSE event received",5003:"SSE retrying to connect in",5004:"SSE stopped",6e3:"Evaluation successful: ",6001:"Evaluation Failed, returning default variation: ",7e3:"Metrics thread started with request interval:",7001:"Metrics stopped",7002:"Posting metrics failed, reason:",7003:"Metrics posted successfully"};function di(s){return s in Ze?Ze[s]:"Unknown SDK code"}function S(s,e=""){return`SDKCODE:${s}: ${di(s)} ${e}`}function et(s){s.warn(S(1002))}function tt(s,e){e.info(S(4e3,s/1e3+" seconds"))}function be(s){s.info(S(1e3))}function it(s){s.info(S(3e3))}function rt(s){s.info(S(3001))}function Re(s){s.info(S(4001))}function st(s){s.info(S(5e3))}function nt(s){s.debug(S(5002))}function ot(s){s.info(S(5004))}function at(s,e){e.info(S(7e3,s/1e3+" seconds"))}function lt(s){s.info(S(7003))}function ct(s){s.info(S(7001))}function Z(s,e,t,i){i.debug(S(6e3,`result=${s}, flag identifier=${e}, target=${JSON.stringify(t)}`))}function ht(s){s.warn(S(2001))}function ut(s){s.warn(S(1001))}function ft(s,e){e.warn(S(5001,s))}function gt(s,e){e.warn(S(5003,`${s}`))}function dt(s,e){e.warn(S(7002,s))}function D(s,e,t,i){i.warn(S(6001,`default variation used=${t}, flag=${s}, target=${JSON.stringify(e)}`))}var le=class{constructor(e,t,i,r,n,o){this.stopped=!0;this.initialized=!1;this.lastPollTime=0;this.api=i,this.options=r,this.environment=e,this.cluster=t,this.repository=o,this.eventBus=n,this.log=r.logger}poll(){if(this.stopped){this.log.info("PollingProcessor stopped"),Re(this.log);return}let e=new Date().getTime(),t=()=>{let i=new Date().getTime()-e,r=Math.max(this.options.pollInterval-i,0);this.timeout=setTimeout(()=>this.poll(),r)};if(this.lastPollTime>Date.now()-this.options.pollInterval){this.log.info(`Last poll was ${Math.round((Date.now()-this.lastPollTime)/1e3)} seconds ago, skipping flag refresh`),t();return}this.lastPollTime=Date.now(),Promise.all([this.retrieveFlags(),this.retrieveSegments()]).then(()=>{this.initialized||setTimeout(()=>{this.initialized=!0,this.eventBus.emit("poller_ready")},0)}).catch(i=>{this.eventBus.emit("poller_error",{error:i})}).finally(()=>{if(this.stopped){this.log.info("PollingProcessor stopped"),Re(this.log);return}t()})}async retrieveFlags(){try{this.log.debug("Fetching flags started");let e=await this.api.getFeatureConfig(this.environment,this.cluster);this.log.debug("Fetching flags finished"),e.data.forEach(t=>this.repository.setFlag(t.feature,t))}catch(e){throw this.log.error("Error loading flags",e),e}}async retrieveSegments(){try{this.log.debug("Fetching segments started");let e=await this.api.getAllSegments(this.environment,this.cluster);this.log.debug("Fetching segments finished"),e.data.forEach(t=>this.repository.setSegment(t.identifier,t))}catch(e){throw this.log.error("Error loading segments",e),e}}start(){if(!this.stopped){this.log.info("PollingProcessor already started");return}this.log.info("Starting PollingProcessor with request interval: ",this.options.pollInterval),this.stopped=!1,this.poll()}stop(){this.log.info("Stopping PollingProcessor"),this.stopped=!0}close(){this.log.info("Closing PollingProcessor"),this.stop(),clearTimeout(this.timeout),this.log.info("PollingProcessor closed")}};var pt=P(require("https")),mt=P(require("http"));var b=class b{constructor(e,t,i,r,n,o,l,h){this.retryAttempt=0;this.api=e,this.apiKey=t,this.environment=i,this.jwtToken=r,this.options=n,this.cluster=o,this.eventBus=l,this.repository=h,this.log=this.options.logger;let c=5e3,a=1e4;this.retryDelayMs=Math.floor(Math.random()*(a-c)+c)}start(){this.log.info("Starting new StreamProcessor");let e=`${this.options.baseUrl}/stream?cluster=${this.cluster}`,t={headers:{"Cache-Control":"no-cache",Accept:"text/event-stream",Authorization:`Bearer ${this.jwtToken}`,"API-Key":this.apiKey}},i=()=>{this.log.info(`SSE stream connected OK: ${e}`),this.retryAttempt=0,this.readyState=b.CONNECTED,this.eventBus.emit("stream_connected")},r=n=>{if(this.readyState!==b.CLOSED){this.retryAttempt+=1;let o=this.getRandomRetryDelayMs();ft(n,this.log),gt(o,this.log),this.readyState=b.RETRYING,this.eventBus.emit("stream_retrying"),setTimeout(()=>{this.log.info("SSE retrying to connect"),this.connect(e,t,i,r)},o)}};this.connect(e,t,i,r),this.eventBus.emit("stream_ready")}getRandomRetryDelayMs(){let e=this.retryDelayMs*this.retryAttempt;return Math.min(e,6e4)}connect(e,t,i,r){if(this.readyState===b.CONNECTED){this.log.debug("SSE already connected, skip retry");return}let n=e.startsWith("https:");this.log.debug("SSE HTTP start request",e),this.request=(n?pt.default:mt.default).request(e,t,o=>{if(this.log.debug("SSE got HTTP response code",o.statusCode),o.statusCode>=400&&o.statusCode<=599){r(`HTTP code ${o.statusCode}`);return}i(),o.on("data",l=>{nt(this.log),this.processData(l)}).on("close",()=>{r("SSE stream closed")})}).on("error",o=>{r("SSE request failed "+o.message)}).on("timeout",()=>{r("SSE request timed out after "+b.SSE_TIMEOUT_MS+"ms")}).setTimeout(b.SSE_TIMEOUT_MS),this.request.end()}processData(e){e.toString().split(/\r?\n/).forEach(i=>this.processLine(i))}processLine(e){if(e.startsWith("data:")){this.log.debug("SSE GOT:",e.substring(5));let t=JSON.parse(e.substring(5));t.domain==="flag"?this.msgProcessor(t,this.api.getFeatureConfigByIdentifier.bind(this.api),this.repository.setFlag.bind(this.repository),this.repository.deleteFlag.bind(this.repository)):t.domain==="target-segment"&&this.msgProcessor(t,this.api.getSegmentByIdentifier.bind(this.api),this.repository.setSegment.bind(this.repository),this.repository.deleteSegment.bind(this.repository))}}async msgProcessor(e,t,i,r){this.log.info("Processing message",e);try{if(e.event==="create"||e.event==="patch"){let{data:n}=await t(e.identifier,this.environment,this.cluster);i(e.identifier,n)}else e.event==="delete"&&r(e.identifier)}catch(n){throw this.log.error("Error while fetching data with identifier:",e.identifier,n),n}this.log.info("Processing message finished",e)}connected(){return this.readyState===b.CONNECTED}close(){if(this.readyState===b.CLOSED){this.log.info("SteamProcessor already closed");return}this.readyState=b.CLOSED,this.log.info("Closing StreamProcessor"),this.request.destroy(),this.request=void 0,this.eventBus.emit("stream_disconnected"),this.log.info("StreamProcessor closed"),ot(this.log)}};b.CONNECTED=1,b.RETRYING=2,b.CLOSED=3,b.SSE_TIMEOUT_MS=3e4;var ce=b;var Oe={};Ne(Oe,{default:()=>Ie});var ee=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,mi=typeof AbortController=="function",he=mi?AbortController:class{constructor(){this.signal=new vt}abort(e=new Error("This operation was aborted")){this.signal.reason=this.signal.reason||e,this.signal.aborted=!0,this.signal.dispatchEvent({type:"abort",target:this.signal})}},vi=typeof AbortSignal=="function",yi=typeof he.AbortSignal=="function",vt=vi?AbortSignal:yi?he.AbortController:class{constructor(){this.reason=void 0,this.aborted=!1,this._listeners=[]}dispatchEvent(e){e.type==="abort"&&(this.aborted=!0,this.onabort(e),this._listeners.forEach(t=>t(e),this))}onabort(){}addEventListener(e,t){e==="abort"&&this._listeners.push(t)}removeEventListener(e,t){e==="abort"&&(this._listeners=this._listeners.filter(i=>i!==t))}},_e=new Set,we=(s,e)=>{let t=`LRU_CACHE_OPTION_${s}`;ue(t)&&Ce(t,`${s} option`,`options.${e}`,$)},xe=(s,e)=>{let t=`LRU_CACHE_METHOD_${s}`;if(ue(t)){let{prototype:i}=$,{get:r}=Object.getOwnPropertyDescriptor(i,s);Ce(t,`${s} method`,`cache.${e}()`,r)}},Ei=(s,e)=>{let t=`LRU_CACHE_PROPERTY_${s}`;if(ue(t)){let{prototype:i}=$,{get:r}=Object.getOwnPropertyDescriptor(i,s);Ce(t,`${s} property`,`cache.${e}`,r)}},yt=(...s)=>{typeof process=="object"&&process&&typeof process.emitWarning=="function"?process.emitWarning(...s):console.error(...s)},ue=s=>!_e.has(s),Ce=(s,e,t,i)=>{_e.add(s);let r=`The ${e} is deprecated. Please use ${t} instead.`;yt(r,"DeprecationWarning",s,i)},U=s=>s&&s===Math.floor(s)&&s>0&&isFinite(s),Et=s=>U(s)?s<=Math.pow(2,8)?Uint8Array:s<=Math.pow(2,16)?Uint16Array:s<=Math.pow(2,32)?Uint32Array:s<=Number.MAX_SAFE_INTEGER?j:null:null,j=class extends Array{constructor(e){super(e),this.fill(0)}},Pe=class{constructor(e){if(e===0)return[];let t=Et(e);this.heap=new t(e),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},$=class s{constructor(e={}){let{max:t=0,ttl:i,ttlResolution:r=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:l,allowStale:h,dispose:c,disposeAfter:a,noDisposeOnSet:f,noUpdateTTL:g,maxSize:p=0,maxEntrySize:v=0,sizeCalculation:T,fetchMethod:u,fetchContext:d,noDeleteOnFetchRejection:E,noDeleteOnStaleGet:A,allowStaleOnFetchRejection:y,allowStaleOnFetchAbort:w,ignoreFetchAbort:m}=e,{length:B,maxAge:z,stale:M}=e instanceof s?{}:e;if(t!==0&&!U(t))throw new TypeError("max option must be a nonnegative integer");let K=t?Et(t):Array;if(!K)throw new Error("invalid max value: "+t);if(this.max=t,this.maxSize=p,this.maxEntrySize=v||this.maxSize,this.sizeCalculation=T||B,this.sizeCalculation){if(!this.maxSize&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(this.fetchMethod=u||null,this.fetchMethod&&typeof this.fetchMethod!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.fetchContext=d,!this.fetchMethod&&d!==void 0)throw new TypeError("cannot set fetchContext without fetchMethod");if(this.keyMap=new Map,this.keyList=new Array(t).fill(null),this.valList=new Array(t).fill(null),this.next=new K(t),this.prev=new K(t),this.head=0,this.tail=0,this.free=new Pe(t),this.initialFill=1,this.size=0,typeof c=="function"&&(this.dispose=c),typeof a=="function"?(this.disposeAfter=a,this.disposed=[]):(this.disposeAfter=null,this.disposed=null),this.noDisposeOnSet=!!f,this.noUpdateTTL=!!g,this.noDeleteOnFetchRejection=!!E,this.allowStaleOnFetchRejection=!!y,this.allowStaleOnFetchAbort=!!w,this.ignoreFetchAbort=!!m,this.maxEntrySize!==0){if(this.maxSize!==0&&!U(this.maxSize))throw new TypeError("maxSize must be a positive integer if specified");if(!U(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.initializeSizeTracking()}if(this.allowStale=!!h||!!M,this.noDeleteOnStaleGet=!!A,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!l,this.ttlResolution=U(r)||r===0?r:1,this.ttlAutopurge=!!n,this.ttl=i||z||0,this.ttl){if(!U(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.initializeTTLTracking()}if(this.max===0&&this.ttl===0&&this.maxSize===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.max&&!this.maxSize){let Y="LRU_CACHE_UNBOUNDED";ue(Y)&&(_e.add(Y),yt("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Y,s))}M&&we("stale","allowStale"),z&&we("maxAge","ttl"),B&&we("length","sizeCalculation")}getRemainingTTL(e){return this.has(e,{updateAgeOnHas:!1})?1/0:0}initializeTTLTracking(){this.ttls=new j(this.max),this.starts=new j(this.max),this.setItemTTL=(i,r,n=ee.now())=>{if(this.starts[i]=r!==0?n:0,this.ttls[i]=r,r!==0&&this.ttlAutopurge){let o=setTimeout(()=>{this.isStale(i)&&this.delete(this.keyList[i])},r+1);o.unref&&o.unref()}},this.updateItemAge=i=>{this.starts[i]=this.ttls[i]!==0?ee.now():0},this.statusTTL=(i,r)=>{i&&(i.ttl=this.ttls[r],i.start=this.starts[r],i.now=e||t(),i.remainingTTL=i.now+i.ttl-i.start)};let e=0,t=()=>{let i=ee.now();if(this.ttlResolution>0){e=i;let r=setTimeout(()=>e=0,this.ttlResolution);r.unref&&r.unref()}return i};this.getRemainingTTL=i=>{let r=this.keyMap.get(i);return r===void 0?0:this.ttls[r]===0||this.starts[r]===0?1/0:this.starts[r]+this.ttls[r]-(e||t())},this.isStale=i=>this.ttls[i]!==0&&this.starts[i]!==0&&(e||t())-this.starts[i]>this.ttls[i]}updateItemAge(e){}statusTTL(e,t){}setItemTTL(e,t,i){}isStale(e){return!1}initializeSizeTracking(){this.calculatedSize=0,this.sizes=new j(this.max),this.removeItemSize=e=>{this.calculatedSize-=this.sizes[e],this.sizes[e]=0},this.requireSize=(e,t,i,r)=>{if(this.isBackgroundFetch(t))return 0;if(!U(i))if(r){if(typeof r!="function")throw new TypeError("sizeCalculation must be a function");if(i=r(t,e),!U(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i},this.addItemSize=(e,t,i)=>{if(this.sizes[e]=t,this.maxSize){let r=this.maxSize-this.sizes[e];for(;this.calculatedSize>r;)this.evict(!0)}this.calculatedSize+=this.sizes[e],i&&(i.entrySize=t,i.totalCalculatedSize=this.calculatedSize)}}removeItemSize(e){}addItemSize(e,t){}requireSize(e,t,i,r){if(i||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache")}*indexes({allowStale:e=this.allowStale}={}){if(this.size)for(let t=this.tail;!(!this.isValidIndex(t)||((e||!this.isStale(t))&&(yield t),t===this.head));)t=this.prev[t]}*rindexes({allowStale:e=this.allowStale}={}){if(this.size)for(let t=this.head;!(!this.isValidIndex(t)||((e||!this.isStale(t))&&(yield t),t===this.tail));)t=this.next[t]}isValidIndex(e){return e!==void 0&&this.keyMap.get(this.keyList[e])===e}*entries(){for(let e of this.indexes())this.valList[e]!==void 0&&this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield[this.keyList[e],this.valList[e]])}*rentries(){for(let e of this.rindexes())this.valList[e]!==void 0&&this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield[this.keyList[e],this.valList[e]])}*keys(){for(let e of this.indexes())this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.keyList[e])}*rkeys(){for(let e of this.rindexes())this.keyList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.keyList[e])}*values(){for(let e of this.indexes())this.valList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.valList[e])}*rvalues(){for(let e of this.rindexes())this.valList[e]!==void 0&&!this.isBackgroundFetch(this.valList[e])&&(yield this.valList[e])}[Symbol.iterator](){return this.entries()}find(e,t){for(let i of this.indexes()){let r=this.valList[i],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;if(n!==void 0&&e(n,this.keyList[i],this))return this.get(this.keyList[i],t)}}forEach(e,t=this){for(let i of this.indexes()){let r=this.valList[i],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;n!==void 0&&e.call(t,n,this.keyList[i],this)}}rforEach(e,t=this){for(let i of this.rindexes()){let r=this.valList[i],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;n!==void 0&&e.call(t,n,this.keyList[i],this)}}get prune(){return xe("prune","purgeStale"),this.purgeStale}purgeStale(){let e=!1;for(let t of this.rindexes({allowStale:!0}))this.isStale(t)&&(this.delete(this.keyList[t]),e=!0);return e}dump(){let e=[];for(let t of this.indexes({allowStale:!0})){let i=this.keyList[t],r=this.valList[t],n=this.isBackgroundFetch(r)?r.__staleWhileFetching:r;if(n===void 0)continue;let o={value:n};if(this.ttls){o.ttl=this.ttls[t];let l=ee.now()-this.starts[t];o.start=Math.floor(Date.now()-l)}this.sizes&&(o.size=this.sizes[t]),e.unshift([i,o])}return e}load(e){this.clear();for(let[t,i]of e){if(i.start){let r=Date.now()-i.start;i.start=ee.now()-r}this.set(t,i.value,i)}}dispose(e,t,i){}set(e,t,{ttl:i=this.ttl,start:r,noDisposeOnSet:n=this.noDisposeOnSet,size:o=0,sizeCalculation:l=this.sizeCalculation,noUpdateTTL:h=this.noUpdateTTL,status:c}={}){if(o=this.requireSize(e,t,o,l),this.maxEntrySize&&o>this.maxEntrySize)return c&&(c.set="miss",c.maxEntrySizeExceeded=!0),this.delete(e),this;let a=this.size===0?void 0:this.keyMap.get(e);if(a===void 0)a=this.newIndex(),this.keyList[a]=e,this.valList[a]=t,this.keyMap.set(e,a),this.next[this.tail]=a,this.prev[a]=this.tail,this.tail=a,this.size++,this.addItemSize(a,o,c),c&&(c.set="add"),h=!1;else{this.moveToTail(a);let f=this.valList[a];if(t!==f){if(this.isBackgroundFetch(f)?f.__abortController.abort(new Error("replaced")):n||(this.dispose(f,e,"set"),this.disposeAfter&&this.disposed.push([f,e,"set"])),this.removeItemSize(a),this.valList[a]=t,this.addItemSize(a,o,c),c){c.set="replace";let g=f&&this.isBackgroundFetch(f)?f.__staleWhileFetching:f;g!==void 0&&(c.oldValue=g)}}else c&&(c.set="update")}if(i!==0&&this.ttl===0&&!this.ttls&&this.initializeTTLTracking(),h||this.setItemTTL(a,i,r),this.statusTTL(c,a),this.disposeAfter)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return this}newIndex(){return this.size===0?this.tail:this.size===this.max&&this.max!==0?this.evict(!1):this.free.length!==0?this.free.pop():this.initialFill++}pop(){if(this.size){let e=this.valList[this.head];return this.evict(!0),e}}evict(e){let t=this.head,i=this.keyList[t],r=this.valList[t];return this.isBackgroundFetch(r)?r.__abortController.abort(new Error("evicted")):(this.dispose(r,i,"evict"),this.disposeAfter&&this.disposed.push([r,i,"evict"])),this.removeItemSize(t),e&&(this.keyList[t]=null,this.valList[t]=null,this.free.push(t)),this.head=this.next[t],this.keyMap.delete(i),this.size--,t}has(e,{updateAgeOnHas:t=this.updateAgeOnHas,status:i}={}){let r=this.keyMap.get(e);if(r!==void 0)if(this.isStale(r))i&&(i.has="stale",this.statusTTL(i,r));else return t&&this.updateItemAge(r),i&&(i.has="hit"),this.statusTTL(i,r),!0;else i&&(i.has="miss");return!1}peek(e,{allowStale:t=this.allowStale}={}){let i=this.keyMap.get(e);if(i!==void 0&&(t||!this.isStale(i))){let r=this.valList[i];return this.isBackgroundFetch(r)?r.__staleWhileFetching:r}}backgroundFetch(e,t,i,r){let n=t===void 0?void 0:this.valList[t];if(this.isBackgroundFetch(n))return n;let o=new he;i.signal&&i.signal.addEventListener("abort",()=>o.abort(i.signal.reason));let l={signal:o.signal,options:i,context:r},h=(p,v=!1)=>{let{aborted:T}=o.signal,u=i.ignoreFetchAbort&&p!==void 0;return i.status&&(T&&!v?(i.status.fetchAborted=!0,i.status.fetchError=o.signal.reason,u&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),T&&!u&&!v?a(o.signal.reason):(this.valList[t]===g&&(p===void 0?g.__staleWhileFetching?this.valList[t]=g.__staleWhileFetching:this.delete(e):(i.status&&(i.status.fetchUpdated=!0),this.set(e,p,l.options))),p)},c=p=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=p),a(p)),a=p=>{let{aborted:v}=o.signal,T=v&&i.allowStaleOnFetchAbort,u=T||i.allowStaleOnFetchRejection,d=u||i.noDeleteOnFetchRejection;if(this.valList[t]===g&&(!d||g.__staleWhileFetching===void 0?this.delete(e):T||(this.valList[t]=g.__staleWhileFetching)),u)return i.status&&g.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),g.__staleWhileFetching;if(g.__returned===g)throw p},f=(p,v)=>{this.fetchMethod(e,n,l).then(T=>p(T),v),o.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(p(),i.allowStaleOnFetchAbort&&(p=T=>h(T,!0)))})};i.status&&(i.status.fetchDispatched=!0);let g=new Promise(f).then(h,c);return g.__abortController=o,g.__staleWhileFetching=n,g.__returned=null,t===void 0?(this.set(e,g,{...l.options,status:void 0}),t=this.keyMap.get(e)):this.valList[t]=g,g}isBackgroundFetch(e){return e&&typeof e=="object"&&typeof e.then=="function"&&Object.prototype.hasOwnProperty.call(e,"__staleWhileFetching")&&Object.prototype.hasOwnProperty.call(e,"__returned")&&(e.__returned===e||e.__returned===null)}async fetch(e,{allowStale:t=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:l=0,sizeCalculation:h=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:a=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:f=this.allowStaleOnFetchRejection,ignoreFetchAbort:g=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,fetchContext:v=this.fetchContext,forceRefresh:T=!1,status:u,signal:d}={}){if(!this.fetchMethod)return u&&(u.fetch="get"),this.get(e,{allowStale:t,updateAgeOnGet:i,noDeleteOnStaleGet:r,status:u});let E={allowStale:t,updateAgeOnGet:i,noDeleteOnStaleGet:r,ttl:n,noDisposeOnSet:o,size:l,sizeCalculation:h,noUpdateTTL:c,noDeleteOnFetchRejection:a,allowStaleOnFetchRejection:f,allowStaleOnFetchAbort:p,ignoreFetchAbort:g,status:u,signal:d},A=this.keyMap.get(e);if(A===void 0){u&&(u.fetch="miss");let y=this.backgroundFetch(e,A,E,v);return y.__returned=y}else{let y=this.valList[A];if(this.isBackgroundFetch(y)){let M=t&&y.__staleWhileFetching!==void 0;return u&&(u.fetch="inflight",M&&(u.returnedStale=!0)),M?y.__staleWhileFetching:y.__returned=y}let w=this.isStale(A);if(!T&&!w)return u&&(u.fetch="hit"),this.moveToTail(A),i&&this.updateItemAge(A),this.statusTTL(u,A),y;let m=this.backgroundFetch(e,A,E,v),B=m.__staleWhileFetching!==void 0,z=B&&t;return u&&(u.fetch=B&&w?"stale":"refresh",z&&w&&(u.returnedStale=!0)),z?m.__staleWhileFetching:m.__returned=m}}get(e,{allowStale:t=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,status:n}={}){let o=this.keyMap.get(e);if(o!==void 0){let l=this.valList[o],h=this.isBackgroundFetch(l);return this.statusTTL(n,o),this.isStale(o)?(n&&(n.get="stale"),h?(n&&(n.returnedStale=t&&l.__staleWhileFetching!==void 0),t?l.__staleWhileFetching:void 0):(r||this.delete(e),n&&(n.returnedStale=t),t?l:void 0)):(n&&(n.get="hit"),h?l.__staleWhileFetching:(this.moveToTail(o),i&&this.updateItemAge(o),l))}else n&&(n.get="miss")}connect(e,t){this.prev[t]=e,this.next[e]=t}moveToTail(e){e!==this.tail&&(e===this.head?this.head=this.next[e]:this.connect(this.prev[e],this.next[e]),this.connect(this.tail,e),this.tail=e)}get del(){return xe("del","delete"),this.delete}delete(e){let t=!1;if(this.size!==0){let i=this.keyMap.get(e);if(i!==void 0)if(t=!0,this.size===1)this.clear();else{this.removeItemSize(i);let r=this.valList[i];this.isBackgroundFetch(r)?r.__abortController.abort(new Error("deleted")):(this.dispose(r,e,"delete"),this.disposeAfter&&this.disposed.push([r,e,"delete"])),this.keyMap.delete(e),this.keyList[i]=null,this.valList[i]=null,i===this.tail?this.tail=this.prev[i]:i===this.head?this.head=this.next[i]:(this.next[this.prev[i]]=this.next[i],this.prev[this.next[i]]=this.prev[i]),this.size--,this.free.push(i)}}if(this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift());return t}clear(){for(let e of this.rindexes({allowStale:!0})){let t=this.valList[e];if(this.isBackgroundFetch(t))t.__abortController.abort(new Error("deleted"));else{let i=this.keyList[e];this.dispose(t,i,"delete"),this.disposeAfter&&this.disposed.push([t,i,"delete"])}}if(this.keyMap.clear(),this.valList.fill(null),this.keyList.fill(null),this.ttls&&(this.ttls.fill(0),this.starts.fill(0)),this.sizes&&this.sizes.fill(0),this.head=0,this.tail=0,this.initialFill=1,this.free.length=0,this.calculatedSize=0,this.size=0,this.disposed)for(;this.disposed.length;)this.disposeAfter(...this.disposed.shift())}get reset(){return xe("reset","clear"),this.clear}get length(){return Ei("length","size"),this.size}static get AbortController(){return he}static get AbortSignal(){return vt}},Ie=$;var fe=class{trace(e,...t){console.trace(e,...t)}debug(e,...t){console.debug(e,...t)}info(e,...t){console.info(e,...t)}warn(e,...t){console.warn(e,...t)}error(e,...t){console.error(e,...t)}};var St=P(require("keyv")),Tt=require("keyv-file"),H=class{constructor(e={}){this.keyvFile=new Tt.KeyvFile(e),this.keyv=new St.default({store:this.keyvFile})}set(e,t){return this.keyv.set(e,t)}get(e){return this.keyv.get(e)}del(e){return this.keyv.delete(e)}keys(){return Promise.resolve(function*(e){for(let t of e)yield t}(this.keyvFile.keys()))}};var At=100;var bt="featureIdentifier",Rt="featureName",wt="variationIdentifier";var xt="target",Pt="SDK_VERSION",_t="SDK_TYPE",Ct="server",It="SDK_LANGUAGE",Ot="javascript",Ft="global",te="segmentMatch",Dt="in",Lt="equal",kt="gt",Mt="starts_with",Nt="ends_with",Ut="contains",Vt="equal_sensitive",Si="https://config.ff.harness.io/api/1.0",Ti="https://events.ff.harness.io/api/1.0",Ai=1e3,Bt=60*Ai,bi=1*Bt,Ri=1*Bt,V={baseUrl:Si,eventsUrl:Ti,pollInterval:bi,eventsSyncInterval:Ri,enableStream:!0,enableAnalytics:!0,cache:new Ie({max:100}),store:new H,logger:new fe};var qt=P(zt());var ge=class{constructor(e,t){this.query=e,this.log=t}getAttrValue(e,t){var i;return e[t]||((i=e.attributes)==null?void 0:i[t])}findVariation(e,t){return e.find(i=>i.identifier===t)}getNormalizedNumberWithNormalizer(e,t,i){let r=[t,e].join(":");return parseInt((0,qt.default)(r).toString())%i+1}getNormalizedNumber(e,t){return this.getNormalizedNumberWithNormalizer(e,t,At)}isEnabled(e,t,i){let r=this.getAttrValue(e,t);if(!r)return!1;let n=this.getNormalizedNumber(r,t);return i>0&&n<=i}evaluateDistribution(e,t){if(!e)return;let i="",r=0;for(let n of e.variations)if(i=n.variation,r+=n.weight,this.isEnabled(t,e.bucketBy,r))return n.variation;return i}async isTargetIncludedOrExcludedInSegment(e,t){var i,r;for(let n of e){let o=await this.query.getSegment(n);if(o){if((i=o.excluded)!=null&&i.find(l=>l.identifier===t.identifier))return this.log.debug(`Target %s excluded from segment %s via exclude list | ||
`,t.name,o.name),!1;if((r=o.included)!=null&&r.find(l=>l.identifier===t.identifier))return this.log.debug(`Target %s included in segment %s via include list | ||
@@ -3,0 +3,0 @@ `,t.name,o.name),!0;if(o.rules&&await this.evaluateClauses(o.rules,t))return this.log.debug(`Target %s included in segment %s via rules |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "1.3.7-rc.1"; | ||
export declare const VERSION = "1.3.7"; |
{ | ||
"name": "@harnessio/ff-nodejs-server-sdk", | ||
"version": "1.3.7-rc.1", | ||
"version": "1.3.7", | ||
"description": "Feature flags SDK for NodeJS environments", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3157038
288
1
12