2 lines
35 KiB
JavaScript
2 lines
35 KiB
JavaScript
"use strict";(self.webpackChunkgrafana_lokiexplore_app=self.webpackChunkgrafana_lokiexplore_app||[]).push([[909],{77909:(e,t,r)=>{r.d(t,{S:()=>R});var n=r(79319);class o extends Error{constructor(e,t,r,n){super(r,n),this.error=e,this.response=t,Object.setPrototypeOf(this,o.prototype),this.name=o.name}}class s extends o{constructor(e,t,r){super(e,void 0,t,r),Object.setPrototypeOf(this,s.prototype),this.name=s.name}}class i extends o{constructor(e,t,r){super(void 0,e,t,r),Object.setPrototypeOf(this,i.prototype),this.name=i.name}}class a extends o{constructor(e,t,r){super(void 0,e,t,r),Object.setPrototypeOf(this,a.prototype),this.name=a.name,this.message=null!=t?t:"OFREP request failed: unauthorized"}}class l extends o{constructor(e,t,r){super(void 0,e,t,r),Object.setPrototypeOf(this,l.prototype),this.name=l.name,this.message=null!=t?t:"OFREP request failed: forbidden"}}class u extends o{constructor(e,t,r){super(void 0,e,t,r),this.response=e,Object.setPrototypeOf(this,u.prototype),this.name=u.name,this.requestTime=new Date,this.message=(null!=t?t:this.retryAfterDate)?`rate limit exceeded, try again after ${this.retryAfterDate}`:"rate limit exceeded, try again later"}get retryAfterHeader(){return this.response.headers.get("Retry-After")}get retryAfterSeconds(){if(!this.retryAfterHeader)return null;const e=Number.parseInt(this.retryAfterHeader,10);return Number.isFinite(e)?e:null}get retryAfterDate(){if(!this.retryAfterHeader)return null;if(this.retryAfterSeconds){return this.retryAfterSeconds?new Date(this.requestTime.getTime()+1e3*this.retryAfterSeconds):null}const e=new Date(this.retryAfterHeader);return isNaN(e.valueOf())?null:e}}function c(e,t,r,n){return new(r||(r=Promise))(function(o,s){function i(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}l((n=n.apply(e,t||[])).next())})}function d(e){return!(!e||"object"!=typeof e)&&("key"in e&&"string"==typeof e.key&&"errorCode"in e&&"string"==typeof e.errorCode)}"function"==typeof SuppressedError&&SuppressedError;const h=[400,404,500],v=[200];function p(e){return c(this,arguments,void 0,function*(e,t=null){var r;return new Headers([["Content-Type","application/json; charset=utf-8"],...(null==e?void 0:e.headers)||[],...(yield null===(r=null==e?void 0:e.headersFactory)||void 0===r?void 0:r.call(e))||[],...t?[["If-None-Match",t]]:[]])})}const g={[n.O4.FLAG_NOT_FOUND]:"Flag was not found",[n.O4.GENERAL]:"General error",[n.O4.INVALID_CONTEXT]:"Context is invalid or could be parsed",[n.O4.PARSE_ERROR]:"Flag or flag configuration could not be parsed",[n.O4.PROVIDER_FATAL]:"Provider is in a fatal error state",[n.O4.PROVIDER_NOT_READY]:"Provider is not yet ready",[n.O4.TARGETING_KEY_MISSING]:"Targeting key is missing",[n.O4.TYPE_MISMATCH]:"Flag is not of expected type"};class f{constructor(e,t=function(){return globalThis?globalThis.fetch.bind(globalThis):window?window.fetch.bind(window):(self&&self.fetch.bind(self),fetch)}()){this.baseOptions=e,this.fetchImplementation=t}isJsonMime(e){const t=e.headers.get("Content-Type");return!!t&&f.jsonRegex.test(t)}static isOFREFErrorHttpStatus(e){return h.includes(e)}static isOFREFSuccessHttpStatus(e){return v.includes(e)}doFetchRequest(e){return c(this,void 0,void 0,function*(){var t;let r;try{const n=null!==(t=this.baseOptions.timeoutMs)&&void 0!==t?t:1e4,o=new AbortController;setTimeout(()=>o.abort(new DOMException(`This signal is timeout in ${n}ms`,"TimeoutError")),n),r=yield this.fetchImplementation(e,{signal:o.signal})}catch(e){throw new s(e,"The OFREP request failed.",{cause:e})}if(401===r.status)throw new a(r);if(403===r.status)throw new l(r);if(429===r.status)throw new u(r);if(200===r.status&&!this.isJsonMime(r))throw new i(r,"OFREP did not respond with expected MIME application/json");try{return{response:r,body:yield r.json()}}catch(e){return{response:r}}})}postEvaluateFlag(e,t){return c(this,void 0,void 0,function*(){let r=`${this.baseOptions.baseUrl}/ofrep/v1/evaluate/flags/${e}`;this.baseOptions.query&&(r+=`?${this.baseOptions.query.toString()}`);const n=new Request(r,{headers:yield p(this.baseOptions),method:"POST",body:JSON.stringify(null!=t?t:{})}),{response:o,body:s}=yield this.doFetchRequest(n);if(200===o.status&&s&&!d(s))return{httpStatus:o.status,value:s,httpResponse:o};if(f.isOFREFErrorHttpStatus(o.status)&&d(s))return{httpStatus:o.status,value:s,httpResponse:o};throw new i(o,"The OFREP response does not match the expected format")})}postBulkEvaluateFlags(e){return c(this,arguments,void 0,function*(e,t=null){let r=`${this.baseOptions.baseUrl}/ofrep/v1/evaluate/flags`;this.baseOptions.query&&(r+=`?${this.baseOptions.query.toString()}`);const n=new Request(r,{headers:yield p(this.baseOptions,t),method:"POST",body:JSON.stringify(null!=e?e:{})}),{response:o,body:s}=yield this.doFetchRequest(n);if(200===o.status&&function(e){return!(!e||"object"!=typeof e)&&"flags"in e}(s))return{httpStatus:o.status,value:s,httpResponse:o};if(304===o.status)return{httpStatus:o.status,value:void 0,httpResponse:o};if(f.isOFREFErrorHttpStatus(o.status)&&function(e){return!(!e||"object"!=typeof e)&&"errorCode"in e}(s))return{httpStatus:o.status,value:s,httpResponse:o};throw new i(o,"The OFREP response does not match the expected format")})}}function _(e){if(!e)return;const t=Object.entries(e).filter(([,e])=>["string","number","boolean"].includes(typeof e));return Object.fromEntries(t)}f.jsonRegex=new RegExp(/application\/[^+]*[+]?(json);?.*/,"i");var m,E=r(75561);function O(e,t,r,n){return new(r||(r=Promise))(function(o,s){function i(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(i,a)}l((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError,function(e){e.SUCCESS_NO_CHANGES="SUCCESS_NO_CHANGES",e.SUCCESS_WITH_CHANGES="SUCCESS_WITH_CHANGES"}(m||(m={}));class R{constructor(e,t){var r;this.DEFAULT_POLL_INTERVAL=3e4,this.metadata={name:"OpenFeature Remote Evaluation Protocol Web Provider"},this.runsOn="client",this.events=new E.by,this._flagCache={},this._options=e,this._logger=t,this._etag=null,this._ofrepAPI=new f(this._options,this._options.fetchImplementation),this._pollingInterval=null!==(r=this._options.pollInterval)&&void 0!==r?r:this.DEFAULT_POLL_INTERVAL}get flagCache(){return Object.assign({},this._flagCache)}initialize(e){return O(this,void 0,void 0,function*(){var t;try{this._context=e,yield this._fetchFlags(e),this._pollingInterval>0&&this.startPolling(),null===(t=this._logger)||void 0===t||t.debug(`${this.metadata.name} initialized successfully`)}catch(e){if(e instanceof a||e instanceof l)throw new E.wh("Initialization failed",{cause:e});throw e}})}resolveBooleanEvaluation(e,t,r){return this._resolve(e,t)}resolveStringEvaluation(e,t,r){return this._resolve(e,t)}resolveNumberEvaluation(e,t,r){return this._resolve(e,t)}resolveObjectEvaluation(e,t,r){return this._resolve(e,t)}onContextChange(e,t){return O(this,void 0,void 0,function*(){var e,r,n;try{this._context=t;const e=new Date;if(void 0!==this._retryPollingAfter&&this._retryPollingAfter>e)return;yield this._fetchFlags(t)}catch(t){if(t instanceof u)return void(null===(e=this.events)||void 0===e||e.emit(E.Uc.Stale,{message:`${t.name}: ${t.message}`}));if(t instanceof E.Lh||t instanceof s||t instanceof a||t instanceof l)return void(null===(r=this.events)||void 0===r||r.emit(E.Uc.Error,{message:`${t.name}: ${t.message}`}));null===(n=this.events)||void 0===n||n.emit(E.Uc.Error,{message:`Unknown error: ${t}`})}})}onClose(){return this.stopPolling(),Promise.resolve()}_fetchFlags(e){return O(this,void 0,void 0,function*(){var t;try{const r={context:e},n=yield this._ofrepAPI.postBulkEvaluateFlags(r,this._etag);if(304===n.httpStatus)return{status:m.SUCCESS_NO_CHANGES,flags:[]};if(200!==n.httpStatus)throw new E.$g(`Failed OFREP bulk evaluation request, status: ${n.httpStatus}`);const o=n.value;if(!("flags"in o)||!Array.isArray(o.flags))throw new Error("No flags in OFREP bulk evaluation response");const s=o.flags.reduce((e,t)=>(t.key&&(e[t.key]=t),e),{}),i=this._getListUpdatedFlags(this._flagCache,s);return this._flagCache=s,this._etag=null===(t=n.httpResponse)||void 0===t?void 0:t.headers.get("etag"),this._flagSetMetadataCache=_("object"==typeof o.metadata?o.metadata:{}),{status:m.SUCCESS_WITH_CHANGES,flags:i}}catch(e){throw e instanceof u&&null!==e.retryAfterDate&&(this._retryPollingAfter=e.retryAfterDate),e}})}_getListUpdatedFlags(e,t){const r=[],n=Object.keys(e),o=Object.keys(t);for(const o in t)-1!==n.indexOf(o)&&JSON.stringify(e[o])===JSON.stringify(t[o])||r.push(o);for(const t in e)-1===o.indexOf(t)&&r.push(t);return r}_resolve(e,t){const r=this._flagCache[e];return r?this.responseToResolutionDetails(r,t):{value:t,flagMetadata:this._flagSetMetadataCache,reason:E.$W.ERROR,errorCode:E.O4.FLAG_NOT_FOUND,errorMessage:g[E.O4.FLAG_NOT_FOUND]}}responseToResolutionDetails(e,t){return d(e)?function(e,t,r){var o,s,i;if(null==r||r(e),"errorCode"in e){const r=null!==(o=e.errorCode)&&void 0!==o?o:n.O4.GENERAL,a=null!==(i=null!==(s=e.errorDetails)&&void 0!==s?s:g[e.errorCode])&&void 0!==i?i:e.errorCode,l=_(e.metadata);return{value:t,reason:n.$W.ERROR,flagMetadata:l,errorCode:r,errorMessage:a}}throw e}(e,t):function(e,t){return void 0===e.value?{value:t,variant:e.variant,flagMetadata:e.metadata,reason:e.reason||n.$W.DEFAULT}:typeof e.value!=typeof t?{value:t,reason:n.$W.ERROR,flagMetadata:e.metadata,errorCode:n.O4.TYPE_MISMATCH,errorMessage:g[n.O4.TYPE_MISMATCH]}:{value:e.value,variant:e.variant,reason:e.reason,flagMetadata:_(e.metadata)}}(e,t)}startPolling(){this._pollingIntervalId=setInterval(()=>O(this,void 0,void 0,function*(){var e,t;try{const t=new Date;if(void 0!==this._retryPollingAfter&&this._retryPollingAfter>t)return;const r=yield this._fetchFlags(this._context);r.status===m.SUCCESS_WITH_CHANGES&&(null===(e=this.events)||void 0===e||e.emit(E.Uc.ConfigurationChanged,{message:"Flags updated",flagsChanged:r.flags}))}catch(e){null===(t=this.events)||void 0===t||t.emit(E.Uc.Stale,{message:`Error while polling: ${e}`})}}),this._pollingInterval)}stopPolling(){this._pollingIntervalId&&clearInterval(this._pollingIntervalId)}}},79319:(e,t,r)=>{r.d(t,{$W:()=>p,$g:()=>m,$l:()=>b,Lh:()=>f,O4:()=>g,Uc:()=>N,VL:()=>F,XD:()=>H,_V:()=>y,_e:()=>w,eD:()=>v,g7:()=>j,j:()=>L,l6:()=>P,qM:()=>I,sN:()=>x,wh:()=>R});var n=Object.defineProperty,o=Object.defineProperties,s=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,u=(e,t,r)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,c=(e,t)=>{for(var r in t||(t={}))a.call(t,r)&&u(e,r,t[r]);if(i)for(var r of i(t))l.call(t,r)&&u(e,r,t[r]);return e},d=(e,t)=>o(e,s(t)),h=(e,t,r)=>new Promise((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}),v=class{constructor(){this.data=new Map}set(e,t){this.data.set(e,t)}get(e){return this.data.get(e)}has(e){return this.data.has(e)}delete(e){return this.data.delete(e)}clear(){this.data.clear()}},p={STATIC:"STATIC",DEFAULT:"DEFAULT",TARGETING_MATCH:"TARGETING_MATCH",SPLIT:"SPLIT",CACHED:"CACHED",DISABLED:"DISABLED",UNKNOWN:"UNKNOWN",STALE:"STALE",ERROR:"ERROR"},g=(e=>(e.PROVIDER_NOT_READY="PROVIDER_NOT_READY",e.PROVIDER_FATAL="PROVIDER_FATAL",e.FLAG_NOT_FOUND="FLAG_NOT_FOUND",e.PARSE_ERROR="PARSE_ERROR",e.TYPE_MISMATCH="TYPE_MISMATCH",e.TARGETING_KEY_MISSING="TARGETING_KEY_MISSING",e.INVALID_CONTEXT="INVALID_CONTEXT",e.GENERAL="GENERAL",e))(g||{}),f=class e extends Error{constructor(t,r){super(t),Object.setPrototypeOf(this,e.prototype),this.name="OpenFeatureError",this.cause=null==r?void 0:r.cause}},_=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="FlagNotFoundError",this.code="FLAG_NOT_FOUND"}},m=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="GeneralError",this.code="GENERAL"}},E=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="InvalidContextError",this.code="INVALID_CONTEXT"}},O=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="ParseError",this.code="PARSE_ERROR"}},R=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="ProviderFatalError",this.code="PROVIDER_FATAL"}},y=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="ProviderNotReadyError",this.code="PROVIDER_NOT_READY"}},A=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="TargetingKeyMissingError",this.code="TARGETING_KEY_MISSING"}},C=class e extends f{constructor(t,r){super(t,r),Object.setPrototypeOf(this,e.prototype),this.name="TypeMismatchError",this.code="TYPE_MISMATCH"}},P=(e,t)=>{switch(e){case"FLAG_NOT_FOUND":return new _(t);case"PARSE_ERROR":return new O(t);case"TYPE_MISMATCH":return new C(t);case"TARGETING_KEY_MISSING":return new A(t);case"INVALID_CONTEXT":return new E(t);case"PROVIDER_NOT_READY":return new y(t);case"PROVIDER_FATAL":return new R(t);default:return new m(t)}},b=(e=>(e.NOT_READY="NOT_READY",e.READY="READY",e.ERROR="ERROR",e.STALE="STALE",e.FATAL="FATAL",e.RECONCILING="RECONCILING",e))(b||{}),N=(e=>(e.Ready="PROVIDER_READY",e.Error="PROVIDER_ERROR",e.ConfigurationChanged="PROVIDER_CONFIGURATION_CHANGED",e.ContextChanged="PROVIDER_CONTEXT_CHANGED",e.Reconciling="PROVIDER_RECONCILING",e.Stale="PROVIDER_STALE",e))(N||{}),S={READY:"PROVIDER_READY",ERROR:"PROVIDER_ERROR",FATAL:"PROVIDER_ERROR",STALE:"PROVIDER_STALE",RECONCILING:"PROVIDER_RECONCILING",NOT_READY:void 0},w=(e,t)=>!t&&"PROVIDER_READY"===e||S[t]===e,T=class{error(...e){console.error(...e)}warn(...e){console.warn(...e)}info(){}debug(){}},D=["error","warn","info","debug"],I=class{constructor(e){this.fallbackLogger=new T;try{for(const t of D)if(!e[t]||"function"!=typeof e[t])throw new Error(`The provided logger is missing the ${t} method.`);this.logger=e}catch(e){console.error(e),console.error("Falling back to the default logger."),this.logger=this.fallbackLogger}}error(...e){this.log("error",...e)}warn(...e){this.log("warn",...e)}info(...e){this.log("info",...e)}debug(...e){this.log("debug",...e)}log(e,...t){try{this.logger[e](...t)}catch(r){this.fallbackLogger[e](...t)}}},x=class{constructor(e){this.globalLogger=e,this._handlers={PROVIDER_CONFIGURATION_CHANGED:new WeakMap,PROVIDER_CONTEXT_CHANGED:new WeakMap,PROVIDER_READY:new WeakMap,PROVIDER_ERROR:new WeakMap,PROVIDER_STALE:new WeakMap,PROVIDER_RECONCILING:new WeakMap}}emit(e,t){this.eventEmitter.emit(e,t)}addHandler(e,t){const r=e=>h(this,null,function*(){var r;try{yield t(e)}catch(e){null==(r=this._logger)||r.error("Error running event handler:",e)}}),n=this._handlers[e].get(t);this._handlers[e].set(t,[...n||[],r]),this.eventEmitter.on(e,r)}removeHandler(e,t){const r=this._handlers[e].get(t);if(r){const t=r.pop();t&&this.eventEmitter.removeListener(e,t)}}removeAllHandlers(e){e?this.eventEmitter.removeAllListeners(e):this.eventEmitter.removeAllListeners()}getHandlers(e){return this.eventEmitter.listeners(e)}setLogger(e){return this._eventLogger=new I(e),this}get _logger(){var e,t;return null!=(t=this._eventLogger)?t:null==(e=this.globalLogger)?void 0:e.call(this)}};function L(e){return function(e){return"string"==typeof e}(e)?e:void 0}function H(e){return function(e){return"object"==typeof e}(e)?e:void 0}function k(e){return null!=e}var F=class{constructor(e,t,r){var n,o,s;this._provider=e,this._status=t,this._pendingContextChanges=0,null==(n=e.events)||n.addHandler("PROVIDER_READY",()=>{this._status=r.READY}),null==(o=e.events)||o.addHandler("PROVIDER_STALE",()=>{this._status=r.STALE}),null==(s=e.events)||s.addHandler("PROVIDER_ERROR",e=>{"PROVIDER_FATAL"===(null==e?void 0:e.errorCode)?this._status=r.FATAL:this._status=r.ERROR})}get provider(){return this._provider}set provider(e){this._provider=e}get status(){return this._status}set status(e){this._status=e}get allContextChangesSettled(){return 0===this._pendingContextChanges}incrementPendingContextChanges(){this._pendingContextChanges++}decrementPendingContextChanges(){this._pendingContextChanges--}},j=class{constructor(e){this._hooks=[],this._context={},this._logger=new T,this._clientEventHandlers=new Map,this._domainScopedContext=new Map,this._clientEvents=new Map,this._runsOn=e}addHooks(...e){return this._hooks=[...this._hooks,...e],this}getHooks(){return this._hooks}clearHooks(){return this._hooks=[],this}setLogger(e){return this._logger=new I(e),this}get providerMetadata(){return this.getProviderMetadata()}getProviderMetadata(e){return this.getProviderForClient(e).metadata}addHandler(e,t,r){[...new Map([[void 0,this._defaultProvider]]),...this._domainScopedProviders].forEach(r=>{var n;const o=r[0],s=r[1].provider,i=r[1].status;if(w(e,i))try{t({domain:o,providerName:s.metadata.name})}catch(e){null==(n=this._logger)||n.error("Error running event handler:",e)}}),this._apiEmitter.addHandler(e,t),(null==r?void 0:r.signal)&&"function"==typeof r.signal.addEventListener&&r.signal.addEventListener("abort",()=>{this.removeHandler(e,t)})}removeHandler(e,t){this._apiEmitter.removeHandler(e,t)}clearHandlers(){this._apiEmitter.removeAllHandlers()}getHandlers(e){return this._apiEmitter.getHandlers(e)}setAwaitableProvider(e,t){var r,n,o,s,i,a,l,u;const c=L(e),d=null!=(r=H(e))?r:H(t);if(!d)return void this._logger.debug("No provider defined, ignoring setProvider call");const h=this.getProviderForClient(c),v=d.metadata.name;if(h===d)return void this._logger.debug("Provider is already set, ignoring setProvider call");if(d.runsOn){if(d.runsOn!==this._runsOn)throw new m(`Provider '${d.metadata.name}' is intended for use on the ${d.runsOn}.`)}else this._logger.debug(`Provider '${d.metadata.name}' has not defined its intended use.`);const p=this.getAssociatedEventEmitters(c);let g;const f=new F(d,this._statusEnumType.NOT_READY,this._statusEnumType);return"function"!=typeof d.initialize||this.allProviders.includes(d)?(f.status=this._statusEnumType.READY,p.forEach(e=>{null==e||e.emit("PROVIDER_READY",{clientName:c,domain:c,providerName:v})}),null==(a=this._apiEmitter)||a.emit("PROVIDER_READY",{clientName:c,domain:c,providerName:v})):g=null==(i=null==(s=null==(o=d.initialize)?void 0:o.call(d,c&&null!=(n=this._domainScopedContext.get(c))?n:this._context))?void 0:s.then(()=>{var e;f.status=this._statusEnumType.READY,this.getAssociatedEventEmitters(c).forEach(e=>{null==e||e.emit("PROVIDER_READY",{clientName:c,domain:c,providerName:v})}),null==(e=this._apiEmitter)||e.emit("PROVIDER_READY",{clientName:c,domain:c,providerName:v})}))?void 0:i.catch(e=>{var t;throw"PROVIDER_FATAL"===(null==e?void 0:e.code)?f.status=this._statusEnumType.FATAL:f.status=this._statusEnumType.ERROR,this.getAssociatedEventEmitters(c).forEach(t=>{null==t||t.emit("PROVIDER_ERROR",{clientName:c,domain:c,providerName:v,message:null==e?void 0:e.message})}),null==(t=this._apiEmitter)||t.emit("PROVIDER_ERROR",{clientName:c,domain:c,providerName:v,message:null==e?void 0:e.message}),e}),c?this._domainScopedProviders.set(c,f):this._defaultProvider=f,this.transferListeners(h,d,c,p),this.allProviders.includes(h)||null==(u=null==(l=null==h?void 0:h.onClose)?void 0:l.call(h))||u.catch(e=>{this._logger.error(`error closing provider: ${null==e?void 0:e.message}, ${null==e?void 0:e.stack}`)}),g}getProviderForClient(e){var t,r;return e&&null!=(r=null==(t=this._domainScopedProviders.get(e))?void 0:t.provider)?r:this._defaultProvider.provider}buildAndCacheEventEmitterForClient(e){const t=this._clientEvents.get(e);if(t)return t;const r=this._createEventEmitter();this._clientEvents.set(e,r);const n=this.getProviderForClient(e);return Object.values(N).forEach(t=>{var o;return null==(o=n.events)?void 0:o.addHandler(t,o=>h(this,null,function*(){r.emit(t,d(c({},o),{clientName:e,domain:e,providerName:n.metadata.name}))}))}),r}getUnboundEmitters(){const e=[...this._domainScopedProviders.keys()];return[...[...this._clientEvents.keys()].filter(k).filter(t=>!e.includes(t)).map(e=>this._clientEvents.get(e)),this._clientEvents.get(void 0)].filter(k)}getAssociatedEventEmitters(e){return e?[this.buildAndCacheEventEmitterForClient(e)]:this.getUnboundEmitters()}transferListeners(e,t,r,n){var o;null==(o=this._clientEventHandlers.get(r))||o.forEach(t=>{var r;return null==(r=e.events)?void 0:r.removeHandler(...t)});const s=Object.values(N).map(e=>[e,o=>h(this,null,function*(){n.forEach(n=>{null==n||n.emit(e,d(c({},o),{clientName:r,domain:r,providerName:t.metadata.name}))}),this._apiEmitter.emit(e,d(c({},o),{clientName:r,domain:r,providerName:t.metadata.name}))})]);this._clientEventHandlers.set(r,s),s.forEach(e=>{var r;return null==(r=t.events)?void 0:r.addHandler(...e)})}close(){return h(this,null,function*(){var e,t;try{yield null==(t=null==(e=null==this?void 0:this._defaultProvider.provider)?void 0:e.onClose)?void 0:t.call(e)}catch(e){this.handleShutdownError(this._defaultProvider.provider,e)}const r=Array.from(this._domainScopedProviders);yield Promise.all(r.map(e=>h(this,[e],function*([,e]){var t,r;try{yield null==(r=null==e?void 0:(t=e.provider).onClose)?void 0:r.call(t)}catch(t){this.handleShutdownError(null==e?void 0:e.provider,t)}})))})}clearProvidersAndSetDefault(e){return h(this,null,function*(){try{yield this.close()}catch(e){this._logger.error("Unable to cleanly close providers. Resetting to the default configuration.")}finally{this._domainScopedProviders.clear(),this._defaultProvider=new F(e,this._statusEnumType.NOT_READY,this._statusEnumType)}})}get allProviders(){return[...[...this._domainScopedProviders.values()].map(e=>e.provider),this._defaultProvider.provider]}handleShutdownError(e,t){this._logger.error(`Error during shutdown of provider ${e.metadata.name}: ${t}`),this._logger.error(null==t?void 0:t.stack)}}},75561:(e,t,r)=>{r.d(t,{$W:()=>s.$W,$g:()=>s.$g,$l:()=>s.$l,B0:()=>S,Lh:()=>s.Lh,Nm:()=>s.Uc,O4:()=>s.O4,Uc:()=>s.Uc,by:()=>C,wh:()=>s.wh});var n,o,s=r(79319),i=Object.create,a=Object.defineProperty,l=Object.defineProperties,u=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyDescriptors,d=Object.getOwnPropertyNames,h=Object.getOwnPropertySymbols,v=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,f=Reflect.get,_=(e,t,r)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,m=(e,t)=>{for(var r in t||(t={}))p.call(t,r)&&_(e,r,t[r]);if(h)for(var r of h(t))g.call(t,r)&&_(e,r,t[r]);return e},E=(e,t)=>l(e,c(t)),O=(e,t,r)=>new Promise((n,o)=>{var s=e=>{try{a(r.next(e))}catch(e){o(e)}},i=e=>{try{a(r.throw(e))}catch(e){o(e)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())}),R=(n={"../../node_modules/eventemitter3/index.js"(e,t){var r=Object.prototype.hasOwnProperty,n="~";function o(){}function s(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function i(e,t,r,o,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new s(r,o||e,i),l=n?n+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],a]:e._events[l].push(a):(e._events[l]=a,e._eventsCount++),e}function a(e,t){0===--e._eventsCount?e._events=new o:delete e._events[t]}function l(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),l.prototype.eventNames=function(){var e,t,o=[];if(0===this._eventsCount)return o;for(t in e=this._events)r.call(e,t)&&o.push(n?t.slice(1):t);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},l.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,s=r.length,i=new Array(s);o<s;o++)i[o]=r[o].fn;return i},l.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},l.prototype.emit=function(e,t,r,o,s,i){var a=n?n+e:e;if(!this._events[a])return!1;var l,u,c=this._events[a],d=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),d){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,r),!0;case 4:return c.fn.call(c.context,t,r,o),!0;case 5:return c.fn.call(c.context,t,r,o,s),!0;case 6:return c.fn.call(c.context,t,r,o,s,i),!0}for(u=1,l=new Array(d-1);u<d;u++)l[u-1]=arguments[u];c.fn.apply(c.context,l)}else{var h,v=c.length;for(u=0;u<v;u++)switch(c[u].once&&this.removeListener(e,c[u].fn,void 0,!0),d){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,t);break;case 3:c[u].fn.call(c[u].context,t,r);break;case 4:c[u].fn.call(c[u].context,t,r,o);break;default:if(!l)for(h=1,l=new Array(d-1);h<d;h++)l[h-1]=arguments[h];c[u].fn.apply(c[u].context,l)}}return!0},l.prototype.on=function(e,t,r){return i(this,e,t,r,!1)},l.prototype.once=function(e,t,r){return i(this,e,t,r,!0)},l.prototype.removeListener=function(e,t,r,o){var s=n?n+e:e;if(!this._events[s])return this;if(!t)return a(this,s),this;var i=this._events[s];if(i.fn)i.fn!==t||o&&!i.once||r&&i.context!==r||a(this,s);else{for(var l=0,u=[],c=i.length;l<c;l++)(i[l].fn!==t||o&&!i[l].once||r&&i[l].context!==r)&&u.push(i[l]);u.length?this._events[s]=1===u.length?u[0]:u:a(this,s)}return this},l.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&a(this,t)):(this._events=new o,this._eventsCount=0),this},l.prototype.off=l.prototype.removeListener,l.prototype.addListener=l.prototype.on,l.prefixed=n,l.EventEmitter=l,void 0!==t&&(t.exports=l)}},function(){return o||(0,n[d(n)[0]])((o={exports:{}}).exports,o),o.exports}),y=new class{constructor(){this.metadata={name:"No-op Provider"}}resolveBooleanEvaluation(e,t){return this.noOp(t)}resolveStringEvaluation(e,t){return this.noOp(t)}resolveNumberEvaluation(e,t){return this.noOp(t)}resolveObjectEvaluation(e,t){return this.noOp(t)}noOp(e){return{value:e,reason:"No-op"}}},A=((e,t,r)=>(r=null!=e?i(v(e)):{},((e,t,r,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let o of d(t))p.call(e,o)||o===r||a(e,o,{get:()=>t[o],enumerable:!(n=u(t,o))||n.enumerable});return e})(!t&&e&&e.__esModule?r:a(r,"default",{value:e,enumerable:!0}),e)))(R(),1),C=class extends s.sN{constructor(){super(),this.eventEmitter=new A.default}},P=(s.Lh,s.Lh,s.$g,class{constructor(e,t,r,n,o,s,i){this.providerAccessor=e,this.providerStatusAccessor=t,this.emitterAccessor=r,this.apiContextAccessor=n,this.apiHooksAccessor=o,this.globalLogger=s,this.options=i,this._hooks=[]}get metadata(){var e,t;return{name:null!=(e=this.options.domain)?e:this.options.name,domain:null!=(t=this.options.domain)?t:this.options.name,version:this.options.version,providerMetadata:this.providerAccessor().metadata}}get providerStatus(){return this.providerStatusAccessor()}addHandler(e,t,r){var n;this.emitterAccessor().addHandler(e,t);if((0,s._e)(e,this.providerStatus))try{t({clientName:this.metadata.name,domain:this.metadata.domain,providerName:this._provider.metadata.name})}catch(e){null==(n=this._logger)||n.error("Error running event handler:",e)}(null==r?void 0:r.signal)&&"function"==typeof r.signal.addEventListener&&r.signal.addEventListener("abort",()=>{this.removeHandler(e,t)})}removeHandler(e,t){this.emitterAccessor().removeHandler(e,t)}getHandlers(e){return this.emitterAccessor().getHandlers(e)}setLogger(e){return this._clientLogger=new s.qM(e),this}addHooks(...e){return this._hooks=[...this._hooks,...e],this}getHooks(){return this._hooks}clearHooks(){return this._hooks=[],this}getBooleanValue(e,t,r){return this.getBooleanDetails(e,t,r).value}getBooleanDetails(e,t,r){return this.evaluate(e,this._provider.resolveBooleanEvaluation,t,"boolean",r)}getStringValue(e,t,r){return this.getStringDetails(e,t,r).value}getStringDetails(e,t,r){return this.evaluate(e,this._provider.resolveStringEvaluation,t,"string",r)}getNumberValue(e,t,r){return this.getNumberDetails(e,t,r).value}getNumberDetails(e,t,r){return this.evaluate(e,this._provider.resolveNumberEvaluation,t,"number",r)}getObjectValue(e,t,r){return this.getObjectDetails(e,t,r).value}getObjectDetails(e,t,r){return this.evaluate(e,this._provider.resolveObjectEvaluation,t,"object",r)}track(e,t={}){var r,n,o;try{if(this.shortCircuitIfNotReady(),"function"==typeof this._provider.track){const s=Object.freeze(m({},this.apiContextAccessor(null==(r=null==this?void 0:this.options)?void 0:r.domain)));return null==(o=(n=this._provider).track)?void 0:o.call(n,e,s,t)}this._logger.debug("Provider does not support the track function; will no-op.")}catch(e){this._logger.debug("Error recording tracking event.",e)}}evaluate(e,t,r,n,o={}){var i,a;const l=[...this.apiHooksAccessor(),...this.getHooks(),...o.hooks||[],...this._provider.hooks||[]],u=[...l].reverse(),c=m({},this.apiContextAccessor(null==(i=null==this?void 0:this.options)?void 0:i.domain)),d=u.map(()=>Object.freeze({flagKey:e,defaultValue:r,flagValueType:n,clientMetadata:this.metadata,providerMetadata:this._provider.metadata,context:c,logger:this._logger,hookData:new s.eD}));let h;try{this.beforeHooks(l,d,o),this.shortCircuitIfNotReady();const n=t.call(this._provider,e,r,c,this._logger),i=E(m({},n),{flagMetadata:Object.freeze(null!=(a=n.flagMetadata)?a:{}),flagKey:e});if(i.errorCode){const t=(0,s.l6)(i.errorCode,i.errorMessage);this.errorHooks(u,d,t,o),h=this.getErrorEvaluationDetails(e,r,t,i.flagMetadata)}else this.afterHooks(u,d,i,o),h=i}catch(t){this.errorHooks(u,d,t,o),h=this.getErrorEvaluationDetails(e,r,t)}return this.finallyHooks(u,d,h,o),h}beforeHooks(e,t,r){var n;for(const[o,s]of e.entries()){const i=t[e.length-1-o];Object.freeze(i),Object.freeze(i.context),null==(n=null==s?void 0:s.before)||n.call(s,i,Object.freeze(r.hookHints))}}afterHooks(e,t,r,n){var o;for(const[s,i]of e.entries()){const e=t[s];null==(o=null==i?void 0:i.after)||o.call(i,e,r,n.hookHints)}}errorHooks(e,t,r,n){var o;for(const[s,i]of e.entries())try{const e=t[s];null==(o=null==i?void 0:i.error)||o.call(i,e,r,n.hookHints)}catch(e){this._logger.error(`Unhandled error during 'error' hook: ${e}`),e instanceof Error&&this._logger.error(e.stack),this._logger.error(null==e?void 0:e.stack)}}finallyHooks(e,t,r,n){var o;for(const[s,i]of e.entries())try{const e=t[s];null==(o=null==i?void 0:i.finally)||o.call(i,e,r,n.hookHints)}catch(e){this._logger.error(`Unhandled error during 'finally' hook: ${e}`),e instanceof Error&&this._logger.error(e.stack),this._logger.error(null==e?void 0:e.stack)}}get _provider(){return this.providerAccessor()}get _logger(){return this._clientLogger||this.globalLogger()}shortCircuitIfNotReady(){if(this.providerStatus===s.$l.NOT_READY)throw new s._V("provider has not yet initialized");if(this.providerStatus===s.$l.FATAL)throw new s.wh("provider is in an irrecoverable error state")}getErrorEvaluationDetails(e,t,r,n={}){const o=null==r?void 0:r.message;return{errorCode:(null==r?void 0:r.code)||s.O4.GENERAL,errorMessage:o,value:t,reason:s.$W.ERROR,flagMetadata:Object.freeze(n),flagKey:e}}}),b=Symbol.for("@openfeature/web-sdk/api"),N=globalThis,S=class e extends s.g7{constructor(){super("client"),this._statusEnumType=s.$l,this._apiEmitter=new C,this._defaultProvider=new s.VL(y,s.$l.NOT_READY,this._statusEnumType),this._domainScopedProviders=new Map,this._createEventEmitter=()=>new C}static getInstance(){const t=N[b];if(t)return t;const r=new e;return N[b]=r,r}getProviderStatus(e){var t,r;return e&&null!=(r=null==(t=this._domainScopedProviders.get(e))?void 0:t.status)?r:this._defaultProvider.status}setProviderAndWait(e,t,r){return O(this,null,function*(){const n=(0,s.j)(e),o=n?(0,s.XD)(t):(0,s.XD)(e),i=n?(0,s.XD)(r):(0,s.XD)(t);i&&(n?this._domainScopedContext.set(n,i):this._context=i),yield this.setAwaitableProvider(n,o)})}setProvider(e,t,r){const n=(0,s.j)(e),o=n?(0,s.XD)(t):(0,s.XD)(e),i=n?(0,s.XD)(r):(0,s.XD)(t);i&&(n?this._domainScopedContext.set(n,i):this._context=i);const a=this.setAwaitableProvider(n,o);return Promise.resolve(a).catch(e=>{this._logger.error("Error during provider initialization:",e)}),this}getProvider(e){return this.getProviderForClient(e)}setContext(e,t){return O(this,null,function*(){var r,n;const o=(0,s.j)(e),i=null!=(n=null!=(r=(0,s.XD)(e))?r:(0,s.XD)(t))?n:{};if(o){const e=this._domainScopedProviders.get(o);if(e){const t=this.getContext(o);this._domainScopedContext.set(o,i),yield this.runProviderContextChangeHandler(o,e,t,i)}else this._domainScopedContext.set(o,i)}else{const e=this._context;this._context=i;const t=Array.from(this._domainScopedProviders.entries()).filter(([e])=>!this._domainScopedContext.has(e)).reduce((e,[t,r])=>(e.push({domain:t,wrapper:r}),e),[]),r=[{domain:void 0,wrapper:this._defaultProvider},...t];yield Promise.all(r.map(t=>this.runProviderContextChangeHandler(t.domain,t.wrapper,e,i)))}})}getContext(e){const t=(0,s.j)(e);if(t){const e=this._domainScopedContext.get(t);if(e)return e;this._logger.debug(`Unable to find context for '${t}'.`)}return this._context}clearContext(e){return O(this,null,function*(){const t=(0,s.j)(e);if(!t)return this.setContext({});{const e=this._domainScopedProviders.get(t);if(e){const r=this.getContext(t);this._domainScopedContext.delete(t);const n=this.getContext();yield this.runProviderContextChangeHandler(t,e,r,n)}else this._domainScopedContext.delete(t)}})}clearContexts(){return O(this,null,function*(){yield this.clearContext(),yield Promise.allSettled(Array.from(this._domainScopedProviders.keys()).map(e=>this.clearContext(e)))})}getClient(e,t){return new P(()=>this.getProviderForClient(e),()=>this.getProviderStatus(e),()=>this.buildAndCacheEventEmitterForClient(e),e=>this.getContext(e),()=>this.getHooks(),()=>this._logger,{domain:e,version:t})}clearProviders(){return O(this,null,function*(){var t,r,n;yield(t=e.prototype,r=this,n="clearProvidersAndSetDefault",f(v(t),n,r)).call(this,y),this._domainScopedContext.clear()})}runProviderContextChangeHandler(e,t,r,n){return O(this,null,function*(){var o,i,a,l,u,c;const d=(null==(i=null==(o=t.provider)?void 0:o.metadata)?void 0:i.name)||"unnamed-provider";try{if("function"==typeof t.provider.onContextChange){const o=t.provider.onContextChange(r,n);o&&"function"==typeof(null==o?void 0:o.then)&&(t.incrementPendingContextChanges(),t.status=this._statusEnumType.RECONCILING,this.getAssociatedEventEmitters(e).forEach(t=>{null==t||t.emit(s.Uc.Reconciling,{domain:e,providerName:d})}),null==(a=this._apiEmitter)||a.emit(s.Uc.Reconciling,{domain:e,providerName:d}),yield o,t.decrementPendingContextChanges())}t.status=this._statusEnumType.READY,t.allContextChangesSettled&&(this.getAssociatedEventEmitters(e).forEach(t=>{null==t||t.emit(s.Uc.ContextChanged,{clientName:e,domain:e,providerName:d})}),null==(l=this._apiEmitter)||l.emit(s.Uc.ContextChanged,{clientName:e,domain:e,providerName:d}))}catch(r){if(t.decrementPendingContextChanges(),t.status=this._statusEnumType.ERROR,t.allContextChangesSettled){const t=`Error running ${d}'s context change handler: ${null==r?void 0:r.message}`;null==(u=this._logger)||u.error(`${t}`,r),this.getAssociatedEventEmitters(e).forEach(r=>{null==r||r.emit(s.Uc.Error,{clientName:e,domain:e,providerName:d,message:t})}),null==(c=this._apiEmitter)||c.emit(s.Uc.Error,{clientName:e,domain:e,providerName:d,message:t})}}})}}.getInstance()}}]);
|
|
//# sourceMappingURL=909.js.map?_cache=4726e3110ce00b46080c
|