@unleash/proxy-client-vue 0.1.6 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(v,f){typeof exports=="object"&&typeof module!="undefined"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(v=typeof globalThis!="undefined"?globalThis:v||self,f(v["proxy-client-vue"]={},v.Vue))})(this,function(v,f){"use strict";var D=function(s,n){return D=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},D(s,n)},p=function(){return p=Object.assign||function(s){for(var n,t=1,r=arguments.length;t<r;t++)for(var e in n=arguments[t])Object.prototype.hasOwnProperty.call(n,e)&&(s[e]=n[e]);return s},p.apply(this,arguments)};function b(s,n,t,r){return new(t||(t=Promise))(function(e,o){function i(h){try{l(r.next(h))}catch(a){o(a)}}function c(h){try{l(r.throw(h))}catch(a){o(a)}}function l(h){var a;h.done?e(h.value):(a=h.value,a instanceof t?a:new t(function(g){g(a)})).then(i,c)}l((r=r.apply(s,n||[])).next())})}function x(s,n){var t,r,e,o={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(l){return function(h){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(o=0)),o;)try{if(t=1,r&&(e=2&a[0]?r.return:a[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,a[1])).done)return e;switch(r=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(e=o.trys,!((e=e.length>0&&e[e.length-1])||a[0]!==6&&a[0]!==2)){o=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]<e[3])){o.label=a[1];break}if(a[0]===6&&o.label<e[1]){o.label=e[1],e=a;break}if(e&&o.label<e[2]){o.label=e[2],o.ops.push(a);break}e[2]&&o.ops.pop(),o.trys.pop();continue}a=n.call(s,o)}catch(g){a=[6,g],r=0}finally{t=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([l,h])}}}typeof SuppressedError=="function"&&SuppressedError;var q={exports:{}};function L(){}L.prototype={on:function(s,n,t){var r=this.e||(this.e={});return(r[s]||(r[s]=[])).push({fn:n,ctx:t}),this},once:function(s,n,t){var r=this;function e(){r.off(s,e),n.apply(t,arguments)}return e._=n,this.on(s,e,t)},emit:function(s){for(var n=[].slice.call(arguments,1),t=((this.e||(this.e={}))[s]||[]).slice(),r=0,e=t.length;r<e;r++)t[r].fn.apply(t[r].ctx,n);return this},off:function(s,n){var t=this.e||(this.e={}),r=t[s],e=[];if(r&&n)for(var o=0,i=r.length;o<i;o++)r[o].fn!==n&&r[o].fn._!==n&&e.push(r[o]);return e.length?t[s]=e:delete t[s],this}},q.exports=L;var at=q.exports.TinyEmitter=L,N=function(s){var n=s[1];return n!=null},ct=function(s){var n=s.properties,t=n===void 0?{}:n,r=function(o,i){var c={};for(var l in o)Object.prototype.hasOwnProperty.call(o,l)&&i.indexOf(l)<0&&(c[l]=o[l]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function"){var h=0;for(l=Object.getOwnPropertySymbols(o);h<l.length;h++)i.indexOf(l[h])<0&&Object.prototype.propertyIsEnumerable.call(o,l[h])&&(c[l[h]]=o[l[h]])}return c}(s,["properties"]),e=function(o){return Object.entries(o).sort(function(i,c){var l=i[0],h=c[0];return l.localeCompare(h,void 0)})};return JSON.stringify([e(r),e(t)])},B=function(s){return b(void 0,void 0,void 0,function(){var n;return x(this,function(t){switch(t.label){case 0:n=ct(s),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,(r=n,b(void 0,void 0,void 0,function(){var e,o,i,c,l;return x(this,function(h){switch(h.label){case 0:if(e=typeof globalThis!="undefined"&&((c=globalThis.crypto)===null||c===void 0?void 0:c.subtle)?(l=globalThis.crypto)===null||l===void 0?void 0:l.subtle:void 0,typeof TextEncoder=="undefined"||!(e!=null&&e.digest)||typeof Uint8Array=="undefined")throw new Error("Hashing function not available");return o=new TextEncoder().encode(r),[4,e.digest("SHA-256",o)];case 1:return i=h.sent(),[2,Array.from(new Uint8Array(i)).map(function(a){return a.toString(16).padStart(2,"0")}).join("")]}})}))];case 2:return[2,t.sent()];case 3:return t.sent(),[2,n];case 4:return[2]}var r})})},K="unleash-js@3.7.2",ut=function(){},lt=function(){function s(n){var t=n.onError,r=n.onSent,e=n.appName,o=n.metricsInterval,i=n.disableMetrics,c=i!==void 0&&i,l=n.url,h=n.clientKey,a=n.fetch,g=n.headerName,E=n.customHeaders,R=E===void 0?{}:E,S=n.metricsIntervalInitial,d=n.connectionId;this.onError=t,this.onSent=r||ut,this.disabled=c,this.metricsInterval=1e3*o,this.metricsIntervalInitial=1e3*S,this.appName=e,this.url=l instanceof URL?l:new URL(l),this.clientKey=h,this.bucket=this.createEmptyBucket(),this.fetch=a,this.headerName=g,this.customHeaders=R,this.connectionId=d}return s.prototype.start=function(){var n=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&(this.metricsIntervalInitial>0?setTimeout(function(){n.startTimer(),n.sendMetrics()},this.metricsIntervalInitial):this.startTimer())},s.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},s.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},s.prototype.getHeaders=function(){var n,t=((n={})[this.headerName]=this.clientKey,n.Accept="application/json",n["Content-Type"]="application/json",n["x-unleash-sdk"]=K,n["x-unleash-connection-id"]=this.connectionId,n["x-unleash-appname"]=this.appName,n);return Object.entries(this.customHeaders).filter(N).forEach(function(r){var e=r[0],o=r[1];return t[e]=o}),t},s.prototype.sendMetrics=function(){return b(this,void 0,void 0,function(){var n,t,r;return x(this,function(e){switch(e.label){case 0:if(n="".concat(this.url,"/client/metrics"),t=this.getPayload(),this.bucketIsEmpty(t))return[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.fetch(n,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(t)})];case 2:return e.sent(),this.onSent(t),[3,4];case 3:return r=e.sent(),console.error("Unleash: unable to send feature metrics",r),this.onError(r),[3,4];case 4:return[2]}})})},s.prototype.count=function(n,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(n),this.bucket.toggles[n][t?"yes":"no"]++,!0)},s.prototype.countVariant=function(n,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(n),this.bucket.toggles[n].variants[t]?this.bucket.toggles[n].variants[t]+=1:this.bucket.toggles[n].variants[t]=1,!0)},s.prototype.assertBucket=function(n){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[n]||(this.bucket.toggles[n]={yes:0,no:0,variants:{}})},s.prototype.startTimer=function(){var n=this;this.timer=setInterval(function(){n.sendMetrics()},this.metricsInterval)},s.prototype.bucketIsEmpty=function(n){return Object.keys(n.bucket.toggles).length===0},s.prototype.getPayload=function(){var n=p(p({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:n,appName:this.appName,instanceId:"browser"}},s}(),Y=function(){function s(){this.store=new Map}return s.prototype.save=function(n,t){return b(this,void 0,void 0,function(){return x(this,function(r){return this.store.set(n,t),[2]})})},s.prototype.get=function(n){return b(this,void 0,void 0,function(){return x(this,function(t){return[2,this.store.get(n)]})})},s}(),J=function(){function s(n){n===void 0&&(n="unleash:repository"),this.prefix=n}return s.prototype.save=function(n,t){return b(this,void 0,void 0,function(){var r,e;return x(this,function(o){r=JSON.stringify(t),e="".concat(this.prefix,":").concat(n);try{window.localStorage.setItem(e,r)}catch(i){console.error(i)}return[2]})})},s.prototype.get=function(n){try{var t="".concat(this.prefix,":").concat(n),r=window.localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(e){console.error(e)}},s}();let A;const ht=new Uint8Array(16);function ft(){if(!A&&(A=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!A))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return A(ht)}const y=[];for(let s=0;s<256;++s)y.push((s+256).toString(16).slice(1));var z={randomUUID:typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function pt(s,n,t){if(z.randomUUID&&!n&&!s)return z.randomUUID();const r=(s=s||{}).random||(s.rng||ft)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=r[e];return n}return function(e,o=0){return y[e[o+0]]+y[e[o+1]]+y[e[o+2]]+y[e[o+3]]+"-"+y[e[o+4]]+y[e[o+5]]+"-"+y[e[o+6]]+y[e[o+7]]+"-"+y[e[o+8]]+y[e[o+9]]+"-"+y[e[o+10]]+y[e[o+11]]+y[e[o+12]]+y[e[o+13]]+y[e[o+14]]+y[e[o+15]]}(r)}var dt=function(){function s(){}return s.prototype.generateEventId=function(){return pt()},s.prototype.createImpressionEvent=function(n,t,r,e,o,i){var c=this.createBaseEvent(n,t,r,e,o);return i?p(p({},c),{variant:i}):c},s.prototype.createBaseEvent=function(n,t,r,e,o){return{eventType:e,eventId:this.generateEventId(),context:n,enabled:t,featureName:r,impressionData:o}},s}(),vt=["userId","sessionId","remoteAddress","currentTime"],G=function(s){return vt.includes(s)},T={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent",RECOVERED:"recovered"},mt="isEnabled",gt="getVariant",yt={name:"disabled",enabled:!1,feature_enabled:!1},_="repo",$="repoLastUpdateTimestamp",bt=function(){try{if(typeof window!="undefined"&&"fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(s){console.error('Unleash failed to resolve "fetch"',s)}},Q=function(s){function n(t){var r=t.storageProvider,e=t.url,o=t.clientKey,i=t.disableRefresh,c=i!==void 0&&i,l=t.refreshInterval,h=l===void 0?30:l,a=t.metricsInterval,g=a===void 0?30:a,E=t.metricsIntervalInitial,R=E===void 0?2:E,S=t.disableMetrics,d=S!==void 0&&S,m=t.appName,I=t.environment,j=I===void 0?"default":I,H=t.context,P=t.fetch,F=P===void 0?bt():P,Z=t.createAbortController,V=Z===void 0?function(){try{if(typeof window!="undefined"&&"AbortController"in window)return function(){return new window.AbortController};if("fetch"in globalThis)return function(){return new globalThis.AbortController}}catch(U){console.error('Unleash failed to resolve "AbortController" factory',U)}}():Z,O=t.bootstrap,tt=t.bootstrapOverride,Ot=tt===void 0||tt,et=t.headerName,rt=et===void 0?"Authorization":et,nt=t.customHeaders,ot=nt===void 0?{}:nt,st=t.impressionDataAll,kt=st!==void 0&&st,it=t.usePOSTrequests,Ut=it!==void 0&&it,k=t.experimental,u=s.call(this)||this;if(u.toggles=[],u.etag="",u.readyEventEmitted=!1,u.fetchedFromServer=!1,u.usePOSTrequests=!1,u.started=!1,!e)throw new Error("url is required");if(!o)throw new Error("clientKey is required");if(!m)throw new Error("appName is required.");return u.eventsHandler=new dt,u.impressionDataAll=kt,u.toggles=O&&O.length>0?O:[],u.url=e instanceof URL?e:new URL(e),u.clientKey=o,u.headerName=rt,u.customHeaders=ot,u.storage=r||(typeof window!="undefined"?new J:new Y),u.refreshInterval=c?0:1e3*h,u.context=p({appName:m,environment:j},H),u.usePOSTrequests=Ut,u.sdkState="initializing",u.experimental=p({},k),(k==null?void 0:k.togglesStorageTTL)&&(k==null?void 0:k.togglesStorageTTL)>0&&(u.experimental.togglesStorageTTL=1e3*k.togglesStorageTTL),u.lastRefreshTimestamp=0,u.ready=new Promise(function(U){u.init().then(U).catch(function(C){console.error(C),u.sdkState="error",u.emit(T.ERROR,C),u.lastError=C,U()})}),F||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),V||console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'),u.fetch=F,u.createAbortController=V,u.bootstrap=O&&O.length>0?O:void 0,u.bootstrapOverride=Ot,u.connectionId="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(U){var C=16*Math.random()|0;return(U==="x"?C:3&C|8).toString(16)}),u.metrics=new lt({onError:u.emit.bind(u,T.ERROR),onSent:u.emit.bind(u,T.SENT),appName:m,metricsInterval:g,disableMetrics:d,url:u.url,clientKey:o,fetch:F,headerName:rt,customHeaders:ot,metricsIntervalInitial:R,connectionId:u.connectionId}),u}return function(t,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}D(t,r),t.prototype=r===null?Object.create(r):(e.prototype=r.prototype,new e)}(n,s),n.prototype.getAllToggles=function(){return function(t,r,e){if(e||arguments.length===2)for(var o,i=0,c=r.length;i<c;i++)!o&&i in r||(o||(o=Array.prototype.slice.call(r,0,i)),o[i]=r[i]);return t.concat(o||Array.prototype.slice.call(r))}([],this.toggles,!0)},n.prototype.isEnabled=function(t){var r,e=this.toggles.find(function(c){return c.name===t}),o=!!e&&e.enabled;if(this.metrics.count(t,o),(e==null?void 0:e.impressionData)||this.impressionDataAll){var i=this.eventsHandler.createImpressionEvent(this.context,o,t,mt,(r=e==null?void 0:e.impressionData)!==null&&r!==void 0?r:void 0);this.emit(T.IMPRESSION,i)}return o},n.prototype.getVariant=function(t){var r,e=this.toggles.find(function(l){return l.name===t}),o=(e==null?void 0:e.enabled)||!1,i=e?e.variant:yt;if(i.name&&this.metrics.countVariant(t,i.name),this.metrics.count(t,o),(e==null?void 0:e.impressionData)||this.impressionDataAll){var c=this.eventsHandler.createImpressionEvent(this.context,o,t,gt,(r=e==null?void 0:e.impressionData)!==null&&r!==void 0?r:void 0,i.name);this.emit(T.IMPRESSION,c)}return p(p({},i),{feature_enabled:o})},n.prototype.updateToggles=function(){return b(this,void 0,void 0,function(){var t=this;return x(this,function(r){switch(r.label){case 0:return this.timerRef||this.fetchedFromServer?[4,this.fetchToggles()]:[3,2];case 1:return r.sent(),[3,4];case 2:return this.started?[4,new Promise(function(e){var o=function(){t.fetchToggles().then(function(){t.off(T.READY,o),e()})};t.once(T.READY,o)})]:[3,4];case 3:r.sent(),r.label=4;case 4:return[2]}})})},n.prototype.updateContext=function(t){return b(this,void 0,void 0,function(){var r;return x(this,function(e){switch(e.label){case 0:return(t.appName||t.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),r={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=p(p({},r),t),[4,this.updateToggles()];case 1:return e.sent(),[2]}})})},n.prototype.getContext=function(){return p({},this.context)},n.prototype.setContextField=function(t,r){var e,o;if(G(t))this.context=p(p({},this.context),((e={})[t]=r,e));else{var i=p(p({},this.context.properties),((o={})[t]=r,o));this.context=p(p({},this.context),{properties:i})}this.updateToggles()},n.prototype.removeContextField=function(t){var r;G(t)?this.context=p(p({},this.context),((r={})[t]=void 0,r)):typeof this.context.properties=="object"&&delete this.context.properties[t],this.updateToggles()},n.prototype.setReady=function(){this.readyEventEmitted=!0,this.emit(T.READY)},n.prototype.init=function(){return b(this,void 0,void 0,function(){var t,r,e;return x(this,function(o){switch(o.label){case 0:return[4,this.resolveSessionId()];case 1:return t=o.sent(),this.context=p({sessionId:t},this.context),r=this,[4,this.storage.get(_)];case 2:return r.toggles=o.sent()||[],e=this,[4,this.getLastRefreshTimestamp()];case 3:return e.lastRefreshTimestamp=o.sent(),!this.bootstrap||!this.bootstrapOverride&&this.toggles.length!==0?[3,6]:[4,this.storage.save(_,this.bootstrap)];case 4:return o.sent(),this.toggles=this.bootstrap,this.sdkState="healthy",[4,this.storeLastRefreshTimestamp()];case 5:o.sent(),this.setReady(),o.label=6;case 6:return this.sdkState="healthy",this.emit(T.INIT),[2]}})})},n.prototype.start=function(){return b(this,void 0,void 0,function(){var t,r=this;return x(this,function(e){switch(e.label){case 0:return this.started=!0,this.timerRef?(console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again."),[2]):[4,this.ready];case 1:return e.sent(),this.metrics.start(),t=this.refreshInterval,[4,this.initialFetchToggles()];case 2:return e.sent(),t>0&&(this.timerRef=setInterval(function(){return r.fetchToggles()},t)),[2]}})})},n.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},n.prototype.isReady=function(){return this.readyEventEmitted},n.prototype.getError=function(){return this.sdkState==="error"?this.lastError:void 0},n.prototype.sendMetrics=function(){return this.metrics.sendMetrics()},n.prototype.resolveSessionId=function(){return b(this,void 0,void 0,function(){var t;return x(this,function(r){switch(r.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[4,this.storage.get("sessionId")];case 1:return(t=r.sent())?[3,3]:(t=Math.floor(1e9*Math.random()),[4,this.storage.save("sessionId",t.toString(10))]);case 2:r.sent(),r.label=3;case 3:return[2,t.toString(10)]}})})},n.prototype.getHeaders=function(){var t,r=this.usePOSTrequests,e=((t={})[this.headerName]=this.clientKey,t.Accept="application/json",t["x-unleash-sdk"]=K,t["x-unleash-connection-id"]=this.connectionId,t["x-unleash-appname"]=this.context.appName,t);return r&&(e["Content-Type"]="application/json"),this.etag&&(e["If-None-Match"]=this.etag),Object.entries(this.customHeaders).filter(N).forEach(function(o){var i=o[0],c=o[1];return e[i]=c}),e},n.prototype.storeToggles=function(t){return b(this,void 0,void 0,function(){return x(this,function(r){switch(r.label){case 0:return this.toggles=t,this.emit(T.UPDATE),[4,this.storage.save(_,t)];case 1:return r.sent(),[2]}})})},n.prototype.isTogglesStorageTTLEnabled=function(){var t;return!!(((t=this.experimental)===null||t===void 0?void 0:t.togglesStorageTTL)&&this.experimental.togglesStorageTTL>0)},n.prototype.isUpToDate=function(){var t;if(!this.isTogglesStorageTTLEnabled())return!1;var r=Date.now(),e=((t=this.experimental)===null||t===void 0?void 0:t.togglesStorageTTL)||0;return this.lastRefreshTimestamp>0&&this.lastRefreshTimestamp<=r&&r-this.lastRefreshTimestamp<=e},n.prototype.getLastRefreshTimestamp=function(){return b(this,void 0,void 0,function(){var t,r;return x(this,function(e){switch(e.label){case 0:return this.isTogglesStorageTTLEnabled()?[4,this.storage.get($)]:[3,3];case 1:return t=e.sent(),[4,B(this.context)];case 2:return r=e.sent(),[2,(t==null?void 0:t.key)===r?t.timestamp:0];case 3:return[2,0]}})})},n.prototype.storeLastRefreshTimestamp=function(){return b(this,void 0,void 0,function(){var t,r;return x(this,function(e){switch(e.label){case 0:return this.isTogglesStorageTTLEnabled()?(this.lastRefreshTimestamp=Date.now(),r={},[4,B(this.context)]):[3,3];case 1:return r.key=e.sent(),r.timestamp=this.lastRefreshTimestamp,t=r,[4,this.storage.save($,t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})},n.prototype.initialFetchToggles=function(){if(!this.isUpToDate())return this.fetchToggles();this.fetchedFromServer||(this.fetchedFromServer=!0,this.setReady())},n.prototype.fetchToggles=function(){return b(this,void 0,void 0,function(){var t,r,e,o,i,c,l,h,a;return x(this,function(g){switch(g.label){case 0:if(!this.fetch)return[3,9];this.abortController&&this.abortController.abort(),this.abortController=(a=this.createAbortController)===null||a===void 0?void 0:a.call(this),t=this.abortController?this.abortController.signal:void 0,g.label=1;case 1:return g.trys.push([1,7,8,9]),r=this.usePOSTrequests,e=r?this.url:function(E,R){var S=new URL(E.toString());return Object.entries(R).filter(N).forEach(function(d){var m=d[0],I=d[1];m==="properties"&&I?Object.entries(I).filter(N).forEach(function(j){var H=j[0],P=j[1];return S.searchParams.append("properties[".concat(H,"]"),P)}):S.searchParams.append(m,I)}),S}(this.url,this.context),o=r?"POST":"GET",i=r?JSON.stringify({context:this.context}):void 0,[4,this.fetch(e.toString(),{method:o,cache:"no-cache",headers:this.getHeaders(),body:i,signal:t})];case 2:return c=g.sent(),this.sdkState==="error"&&c.status<400&&(this.sdkState="healthy",this.emit(T.RECOVERED)),c.ok?(this.etag=c.headers.get("ETag")||"",[4,c.json()]):[3,5];case 3:return l=g.sent(),[4,this.storeToggles(l.toggles)];case 4:return g.sent(),this.sdkState!=="healthy"&&(this.sdkState="healthy"),this.fetchedFromServer||(this.fetchedFromServer=!0,this.setReady()),this.storeLastRefreshTimestamp(),[3,6];case 5:c.status===304?this.storeLastRefreshTimestamp():(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.sdkState="error",this.emit(T.ERROR,{type:"HttpError",code:c.status}),this.lastError={type:"HttpError",code:c.status}),g.label=6;case 6:return[3,9];case 7:return typeof(h=g.sent())=="object"&&h!==null&&"name"in h&&h.name==="AbortError"||(console.error("Unleash: unable to fetch feature toggles",h),this.sdkState="error",this.emit(T.ERROR,h),this.lastError=h),[3,9];case 8:return this.abortController=null,[7];case 9:return[2]}})})},n}(at);const w=Symbol("Context state identifier"),M=Symbol("Context update identifier");function W({config:s,unleashClient:n,startClient:t=!0}){var R,S;const r=f.ref(n),e=f.ref(!1),o=f.ref(null);!s&&!n&&console.warn(`You must provide either a config or an unleash client to the flag provider. If you are initializing the client in useEffect, you can avoid this warning by
2
- checking if the client exists before rendering.`),!r.value&&s&&(r.value=new Q(s)),(R=r.value)==null||R.on("ready",()=>{e.value=!0}),(S=r.value)==null||S.on("error",d=>{o.value=d});const i=async d=>{var m;await((m=r.value)==null?void 0:m.updateContext(d))},c=d=>{var m;return(m=r.value)==null?void 0:m.isEnabled(d)},l=d=>{var m;return(m=r.value)==null?void 0:m.getVariant(d)},h=(d,...m)=>{var I;return(I=r.value)==null?void 0:I.on(d,...m)},a=f.reactive({on:h,updateContext:i,isEnabled:c,getVariant:l,client:r,flagsReady:e,flagsError:o}),g=(d,m)=>{a[d]=m},E=()=>{var d;(t||!n)&&((d=r==null?void 0:r.value)==null||d.start())};return{context:f.toRefs(a),update:g,start:E}}const X=f.defineComponent({__name:"FlagProvider",props:{config:null,unleashClient:null,startClient:{type:Boolean}},setup(s){const{config:n,unleashClient:t,startClient:r=!0}=s,{context:e,start:o,update:i}=W({config:n,unleashClient:t,startClient:r});return f.provide(w,e),f.provide(M,i),f.onMounted(()=>{o()}),(c,l)=>f.renderSlot(c.$slots,"default")}}),xt=s=>{const{isEnabled:n,client:t}=f.inject(w,{}),r=f.ref(Boolean(n==null?void 0:n.value(s)));function e(){const i=n==null?void 0:n.value(s);i!==r.value&&(r.value=!!i)}function o(){r.value=Boolean(n==null?void 0:n.value(s))}return t==null||t.value.on("ready",o),t==null||t.value.on("update",e),f.onUnmounted(()=>{t==null||t.value.off("ready",o),t==null||t.value.off("update",e)}),r},Tt=()=>{const{flagsReady:s,flagsError:n}=f.inject(w,{});return{flagsReady:s,flagsError:n}},St=(s,n)=>{var r,e,o,i;return!((s==null?void 0:s.name)===(n==null?void 0:n.name)&&(s==null?void 0:s.enabled)===(n==null?void 0:n.enabled)&&(s==null?void 0:s.feature_enabled)===(n==null?void 0:n.feature_enabled)&&((r=s==null?void 0:s.payload)==null?void 0:r.type)===((e=n==null?void 0:n.payload)==null?void 0:e.type)&&((o=s==null?void 0:s.payload)==null?void 0:o.value)===((i=n==null?void 0:n.payload)==null?void 0:i.value))},Et=s=>{const{getVariant:n,client:t}=f.inject(w,{}),r=f.ref(n==null?void 0:n.value(s));function e(){const i=n==null?void 0:n.value(s);St(r==null?void 0:r.value,i)&&(r.value=i)}function o(){r.value=n==null?void 0:n.value(s)}return t==null||t.value.on("ready",o),t==null||t.value.on("update",e),f.onUnmounted(()=>{t==null||t.value.off("ready",o),t==null||t.value.off("update",e)}),r||{}},It=()=>{const{updateContext:s}=f.inject(w,{});return s==null?void 0:s.value},wt=()=>{const{client:s}=f.inject(w,{});return s==null?void 0:s.value},Rt={install(s,{config:n,unleashClient:t,startClient:r}){const{context:e,update:o,start:i}=W({config:n,unleashClient:t,startClient:r});s.provide(w,e),s.provide(M,o),i()}};v.ContextStateSymbol=w,v.ContextUpdateSymbol=M,v.FlagProvider=X,v.InMemoryStorageProvider=Y,v.LocalStorageProvider=J,v.UnleashClient=Q,v.default=X,v.plugin=Rt,v.useFlag=xt,v.useFlagsStatus=Tt,v.useUnleashClient=wt,v.useUnleashContext=It,v.useVariant=Et,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(m,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):(m=typeof globalThis<"u"?globalThis:m||self,p(m["proxy-client-vue"]={},m.Vue))})(this,(function(m,p){"use strict";var M=function(o,t){return M=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])},M(o,t)};function q(o,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function e(){this.constructor=o}M(o,t),o.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var d=function(){return d=Object.assign||function(o){for(var t,e=1,r=arguments.length;e<r;e++)for(var n in t=arguments[e])Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n]);return o},d.apply(this,arguments)};function b(o,t,e,r){return new(e||(e=Promise))((function(n,s){function i(u){try{l(r.next(u))}catch(a){s(a)}}function c(u){try{l(r.throw(u))}catch(a){s(a)}}function l(u){var a;u.done?n(u.value):(a=u.value,a instanceof e?a:new e((function(f){f(a)}))).then(i,c)}l((r=r.apply(o,t||[])).next())}))}function x(o,t){var e,r,n,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function c(l){return function(u){return(function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(e=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(n=s.trys,!((n=n.length>0&&n[n.length-1])||a[0]!==6&&a[0]!==2)){s=0;continue}if(a[0]===3&&(!n||a[1]>n[0]&&a[1]<n[3])){s.label=a[1];break}if(a[0]===6&&s.label<n[1]){s.label=n[1],n=a;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(a);break}n[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(o,s)}catch(f){a=[6,f],r=0}finally{e=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}})([l,u])}}}function N(o,t,e){if(e||arguments.length===2)for(var r,n=0,s=t.length;n<s;n++)!r&&n in t||(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return o.concat(r||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var B,A={exports:{}},Y=(function(){if(B)return A.exports;function o(){}return B=1,o.prototype={on:function(t,e,r){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:e,ctx:r}),this},once:function(t,e,r){var n=this;function s(){n.off(t,s),e.apply(r,arguments)}return s._=e,this.on(t,s,r)},emit:function(t){for(var e=[].slice.call(arguments,1),r=((this.e||(this.e={}))[t]||[]).slice(),n=0,s=r.length;n<s;n++)r[n].fn.apply(r[n].ctx,e);return this},off:function(t,e){var r=this.e||(this.e={}),n=r[t],s=[];if(n&&e)for(var i=0,c=n.length;i<c;i++)n[i].fn!==e&&n[i].fn._!==e&&s.push(n[i]);return s.length?r[t]=s:delete r[t],this}},A.exports=o,A.exports.TinyEmitter=o,A.exports})(),L=function(o){var t=o[1];return t!=null},dt=function(o){var t=o.properties,e=t===void 0?{}:t,r=(function(s,i){var c={};for(var l in s)Object.prototype.hasOwnProperty.call(s,l)&&i.indexOf(l)<0&&(c[l]=s[l]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function"){var u=0;for(l=Object.getOwnPropertySymbols(s);u<l.length;u++)i.indexOf(l[u])<0&&Object.prototype.propertyIsEnumerable.call(s,l[u])&&(c[l[u]]=s[l[u]])}return c})(o,["properties"]),n=function(s){return Object.entries(s).sort((function(i,c){var l=i[0],u=c[0];return l.localeCompare(u,void 0)}))};return JSON.stringify([n(r),n(e)])},W=function(o){return b(void 0,void 0,void 0,(function(){var t;return x(this,(function(e){switch(e.label){case 0:t=dt(o),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,(r=t,b(void 0,void 0,void 0,(function(){var n,s,i,c,l;return x(this,(function(u){switch(u.label){case 0:if(n=typeof globalThis<"u"&&(!((c=globalThis.crypto)===null||c===void 0)&&c.subtle)?(l=globalThis.crypto)===null||l===void 0?void 0:l.subtle:void 0,typeof TextEncoder>"u"||!(n!=null&&n.digest)||typeof Uint8Array>"u")throw new Error("Hashing function not available");return s=new TextEncoder().encode(r),[4,n.digest("SHA-256",s)];case 1:return i=u.sent(),[2,Array.from(new Uint8Array(i)).map((function(a){return a.toString(16).padStart(2,"0")})).join("")]}}))})))];case 2:return[2,e.sent()];case 3:return e.sent(),[2,t];case 4:return[2]}var r}))}))},z=function(o){var t,e=o.clientKey,r=o.appName,n=o.connectionId,s=o.customHeaders,i=o.headerName,c=i===void 0?"authorization":i,l=o.etag,u=o.isPost,a=((t={accept:"application/json"})[c.toLocaleLowerCase()]=e,t["unleash-sdk"]="unleash-js-sdk:3.8.2",t["unleash-appname"]=r,t);return u&&(a["content-type"]="application/json"),l&&(a["if-none-match"]=l),Object.entries(s||{}).filter(L).forEach((function(f){var S=f[0],E=f[1];return a[S.toLocaleLowerCase()]=E})),a["unleash-connection-id"]=n,a},vt=function(){},mt=(function(){function o(t){var e=t.onError,r=t.onSent,n=t.appName,s=t.metricsInterval,i=t.disableMetrics,c=i!==void 0&&i,l=t.url,u=t.clientKey,a=t.fetch,f=t.headerName,S=t.customHeaders,E=S===void 0?{}:S,T=t.metricsIntervalInitial,v=t.connectionId,g=t.metricRegistry;this.onError=e,this.onSent=r||vt,this.disabled=c,this.metricsInterval=1e3*s,this.metricsIntervalInitial=1e3*T,this.appName=n,this.url=l instanceof URL?l:new URL(l),this.clientKey=u,this.bucket=this.createEmptyBucket(),this.fetch=a,this.headerName=f,this.customHeaders=E,this.connectionId=v,this.metricRegistry=g}return o.prototype.start=function(){var t=this;if(this.disabled)return!1;this.setupMetricsFlushOnPageUnload(),typeof this.metricsInterval=="number"&&this.metricsInterval>0&&(this.metricsIntervalInitial>0?setTimeout((function(){t.startTimer(),t.sendMetrics()}),this.metricsIntervalInitial):this.startTimer())},o.prototype.stop=function(){this.timer&&(clearInterval(this.timer),delete this.timer),this.removeMetricsFlushOnPageUnload()},o.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},o.prototype.getHeaders=function(){return z({clientKey:this.clientKey,appName:this.appName,connectionId:this.connectionId,customHeaders:this.customHeaders,headerName:this.headerName,isPost:!0})},o.prototype.sendMetrics=function(){return b(this,arguments,void 0,(function(t){var e,r,n,s=(t===void 0?{}:t).fireAndForget,i=s!==void 0&&s;return x(this,(function(c){switch(c.label){case 0:if(e="".concat(this.url.toString().replace(/\/$/,""),"/client/metrics"),r=this.getPayload(),this.bucketIsEmpty(r)&&(!r.impactMetrics||r.impactMetrics.length===0))return[2];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.fetch(e,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(r),keepalive:i})];case 2:return c.sent(),this.onSent(r),[3,4];case 3:return n=c.sent(),console.error("Unleash: unable to send feature metrics",n),this.onError(n),[3,4];case 4:return[2]}}))}))},o.prototype.count=function(t,e){return!(this.disabled||!this.bucket)&&(this.assertBucket(t),this.bucket.toggles[t][e?"yes":"no"]++,!0)},o.prototype.countVariant=function(t,e){return!(this.disabled||!this.bucket)&&(this.assertBucket(t),this.bucket.toggles[t].variants[e]?this.bucket.toggles[t].variants[e]+=1:this.bucket.toggles[t].variants[e]=1,!0)},o.prototype.assertBucket=function(t){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[t]||(this.bucket.toggles[t]={yes:0,no:0,variants:{}})},o.prototype.startTimer=function(){var t=this;this.timer=setInterval((function(){t.sendMetrics()}),this.metricsInterval)},o.prototype.bucketIsEmpty=function(t){return Object.keys(t.bucket.toggles).length===0},o.prototype.getPayload=function(){var t,e=d(d({},this.bucket),{stop:new Date});this.bucket=this.createEmptyBucket();var r={bucket:e,appName:this.appName,instanceId:"browser"},n=((t=this.metricRegistry)===null||t===void 0?void 0:t.collect())||[];return r.impactMetrics=n,r},o.prototype.setupMetricsFlushOnPageUnload=function(){var t=this;typeof document>"u"||typeof window>"u"||typeof document.addEventListener!="function"||document.addEventListener("visibilitychange",this.flushMetricsOnPageUnload=function(){document.visibilityState==="hidden"&&t.sendMetrics({fireAndForget:!0})})},o.prototype.removeMetricsFlushOnPageUnload=function(){this.flushMetricsOnPageUnload&&(document.removeEventListener("visibilitychange",this.flushMetricsOnPageUnload),this.flushMetricsOnPageUnload=void 0)},o})(),J=(function(){function o(){this.store=new Map}return o.prototype.save=function(t,e){return b(this,void 0,void 0,(function(){return x(this,(function(r){return this.store.set(t,e),[2]}))}))},o.prototype.get=function(t){return b(this,void 0,void 0,(function(){return x(this,(function(e){return[2,this.store.get(t)]}))}))},o})(),G=(function(){function o(t){t===void 0&&(t="unleash:repository"),this.prefix=t}return o.prototype.save=function(t,e){return b(this,void 0,void 0,(function(){var r,n;return x(this,(function(s){r=JSON.stringify(e),n="".concat(this.prefix,":").concat(t);try{window.localStorage.setItem(n,r)}catch(i){console.error(i)}return[2]}))}))},o.prototype.get=function(t){try{var e="".concat(this.prefix,":").concat(t),r=window.localStorage.getItem(e);return r?JSON.parse(r):void 0}catch(n){console.error(n)}},o})(),$=function(){var o;return typeof globalThis<"u"&&(!((o=globalThis.crypto)===null||o===void 0)&&o.randomUUID)?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return(t==="x"?e:3&e|8).toString(16)}))},gt=(function(){function o(){}return o.prototype.generateEventId=function(){return $()},o.prototype.createImpressionEvent=function(t,e,r,n,s,i){var c=this.createBaseEvent(t,e,r,n,s);return i?d(d({},c),{variant:i}):c},o.prototype.createBaseEvent=function(t,e,r,n,s){return{eventType:n,eventId:this.generateEventId(),context:t,enabled:e,featureName:r,impressionData:s}},o})();function Q(o){return o!==void 0&&!Number.isFinite(o)}function j(o){return o?Object.keys(o).sort().map((function(t){return"".concat(t,"=").concat(o[t])})).join(","):""}function X(o){var t={};if(!o)return t;for(var e=0,r=o.split(",");e<r.length;e++){var n=r[e].split("="),s=n[0],i=n[1];t[s]=i}return t}var yt=function(o){return"value"in o},Z=function(o){return"buckets"in o},bt=(function(){function o(t){this.opts=t,this.values=new Map}return o.prototype.inc=function(t,e){var r;if(!Q(t)){var n=t??1;if(!(n<=0)){var s=j(e),i=(r=this.values.get(s))!==null&&r!==void 0?r:0;this.values.set(s,i+n)}}},o.prototype.collect=function(){var t=Array.from(this.values.entries()).map((function(e){var r=e[0],n=e[1];return{labels:X(r),value:n}}));return this.values.clear(),t.length===0&&t.push({labels:{},value:0}),{name:this.opts.name,help:this.opts.help,type:"counter",samples:t}},o})(),xt=(function(){function o(t){this.opts=t,this.values=new Map;var e=t.buckets&&t.buckets.length>0?t.buckets:[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],r=Array.from(new Set(e.filter((function(n){return n!==1/0})))).sort((function(n,s){return n-s}));this.buckets=N(N([],r,!0),[1/0],!1)}return o.prototype.restore=function(t){var e=j(t.labels),r={count:t.count,sum:t.sum,buckets:new Map(t.buckets.map((function(n){return[n.le==="+Inf"?1/0:n.le,n.count]})))};this.values.set(e,r)},o.prototype.observe=function(t,e){var r;if(!Q(t)){var n=j(e),s=this.values.get(n);if(!s){for(var i=new Map,c=0,l=this.buckets;c<l.length;c++){var u=l[c];i.set(u,0)}s={count:0,sum:0,buckets:i},this.values.set(n,s)}s.count++,s.sum+=t;for(var a=0,f=this.buckets;a<f.length;a++)if(t<=(u=f[a])){var S=(r=s.buckets.get(u))!==null&&r!==void 0?r:0;s.buckets.set(u,S+1)}}},o.prototype.collect=function(){var t=Array.from(this.values.entries()).map((function(e){var r=e[0],n=e[1];return{labels:X(r),count:n.count,sum:n.sum,buckets:Array.from(n.buckets.entries()).map((function(s){var i=s[0];return{le:i===1/0?"+Inf":i,count:s[1]}}))}}));return this.values.clear(),t.length===0&&t.push({labels:{},count:0,sum:0,buckets:this.buckets.map((function(e){return{le:e===1/0?"+Inf":e,count:0}}))}),{name:this.opts.name,help:this.opts.help,type:"histogram",samples:t}},o})(),Tt=(function(){function o(){this.counters=new Map,this.histograms=new Map}return o.prototype.getCounter=function(t){return this.counters.get(t)},o.prototype.getHistogram=function(t){return this.histograms.get(t)},o.prototype.counter=function(t){var e=t.name,r=this.counters.get(e);return r||(r=new bt(t),this.counters.set(e,r)),r},o.prototype.histogram=function(t){var e=t.name,r=this.histograms.get(e);return r||(r=new xt(t),this.histograms.set(e,r)),r},o.prototype.collect=function(){var t=Array.from(this.counters.values()).map((function(n){return n.collect()})),e=Array.from(this.histograms.values()).map((function(n){return n.collect()})),r=N(N([],t,!0),e,!0).filter((function(n){return n.samples.length>0}));return r.length>0?r:[]},o.prototype.restore=function(t){for(var e=function(i){switch(i.type){case"counter":for(var c=r.counter({name:i.name,help:i.help}),l=0,u=i.samples;l<u.length;l++){var a=u[l];yt(a)&&c.inc(a.value,a.labels)}break;case"histogram":var f=i.samples.find(Z);if(f){var S=f.buckets.map((function(T){return T.le==="+Inf"?1/0:T.le})),E=r.histogram({name:i.name,help:i.help,buckets:S});i.samples.filter(Z).forEach((function(T){E.restore(T)}))}}},r=this,n=0,s=t;n<s.length;n++)e(s[n])},o})(),y={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent",RECOVERED:"recovered",WARN:"warn"},St=(function(o){function t(e,r,n){var s=o.call(this)||this;return s.metricRegistry=e,s.appName=r,s.environment=n,s}return q(t,o),t.prototype.defineCounter=function(e,r){e&&r?this.metricRegistry.counter({name:e,help:r,labelNames:["featureName","appName","environment"]}):this.emit(y.WARN,"Counter name or help cannot be empty: ".concat(e,", ").concat(r,"."))},t.prototype.defineHistogram=function(e,r,n){e&&r?this.metricRegistry.histogram({name:e,help:r,labelNames:["featureName","appName","environment"],buckets:n}):this.emit(y.WARN,"Histogram name or help cannot be empty: ".concat(e,", ").concat(r,"."))},t.prototype.incrementCounter=function(e,r){var n=this.metricRegistry.getCounter(e);if(n){var s={appName:this.appName,environment:this.environment};n.inc(r,s)}else this.emit(y.WARN,"Counter ".concat(e," not defined, this counter will not be incremented."))},t.prototype.observeHistogram=function(e,r){var n=this.metricRegistry.getHistogram(e);if(n){var s={appName:this.appName,environment:this.environment};n.observe(r,s)}else this.emit(y.WARN,"Histogram ".concat(e," not defined, this histogram will not be updated."))},t})(Y.TinyEmitter),Et=["userId","sessionId","remoteAddress","currentTime"],V=function(o){return Et.includes(o)},wt="isEnabled",Rt="getVariant",It={name:"disabled",enabled:!1,feature_enabled:!1},H="repo",tt="repoLastUpdateTimestamp",kt=function(){try{if(typeof window<"u"&&"fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(o){console.error('Unleash failed to resolve "fetch"',o)}},et=(function(o){function t(e){var r,n=e.storageProvider,s=e.url,i=e.clientKey,c=e.disableRefresh,l=c!==void 0&&c,u=e.refreshInterval,a=u===void 0?30:u,f=e.metricsInterval,S=f===void 0?30:f,E=e.metricsIntervalInitial,T=E===void 0?2:E,v=e.disableMetrics,g=v!==void 0&&v,w=e.appName,C=e.environment,P=C===void 0?"default":C,F=e.context,ot=e.fetch,_=ot===void 0?kt():ot,st=e.createAbortController,it=st===void 0?(function(){try{if(typeof window<"u"&&"AbortController"in window)return function(){return new window.AbortController};if("fetch"in globalThis)return function(){return new globalThis.AbortController}}catch(O){console.error('Unleash failed to resolve "AbortController" factory',O)}})():st,k=e.bootstrap,at=e.bootstrapOverride,Lt=at===void 0||at,ct=e.headerName,ut=ct===void 0?"Authorization":ct,lt=e.customHeaders,ht=lt===void 0?{}:lt,ft=e.impressionDataAll,jt=ft!==void 0&&ft,pt=e.usePOSTrequests,Ht=pt!==void 0&&pt,I=e.experimental,h=o.call(this)||this;if(h.toggles=[],h.etag="",h.readyEventEmitted=!1,h.fetchedFromServer=!1,h.usePOSTrequests=!1,h.started=!1,!s)throw new Error("url is required");if(!i)throw new Error("clientKey is required");if(!w)throw new Error("appName is required.");h.eventsHandler=new gt,h.impressionDataAll=jt,h.toggles=k&&k.length>0?k:[],h.url=s instanceof URL?s:new URL(s),h.clientKey=i,h.headerName=ut,h.customHeaders=ht,h.storage=n||(typeof window<"u"?new G:new J),h.refreshInterval=l?0:1e3*a,h.context=d({appName:w,environment:P},F),h.usePOSTrequests=Ht,h.sdkState="initializing";var U=I==null?void 0:I.metricsUrl;!U||U instanceof URL||(U=new URL(U)),h.experimental=d(d({},I),{metricsUrl:U}),I!=null&&I.togglesStorageTTL&&(I==null?void 0:I.togglesStorageTTL)>0&&(h.experimental.togglesStorageTTL=1e3*I.togglesStorageTTL),h.lastRefreshTimestamp=0,h.ready=new Promise((function(O){h.init().then(O).catch((function(K){console.error(K),h.sdkState="error",h.emit(y.ERROR,K),h.lastError=K,O()}))})),_||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),it||console.error('Unleash: You must either provide your own "AbortController" implementation or run in an environment where "AbortController" is available.'),h.fetch=_,h.createAbortController=it,h.bootstrap=k&&k.length>0?k:void 0,h.bootstrapOverride=Lt,h.connectionId=$(),h.metricRegistry=new Tt;var Dt=h.resolveEnvironment(i,P);return h.impactMetrics=new St(h.metricRegistry,w,Dt),h.metrics=new mt({onError:function(O){return h.emit(y.ERROR,{type:"metrics",error:O})},onSent:h.emit.bind(h,y.SENT),appName:w,metricsInterval:S,disableMetrics:g,url:((r=h.experimental)===null||r===void 0?void 0:r.metricsUrl)||h.url,clientKey:i,fetch:_,headerName:ut,customHeaders:ht,metricsIntervalInitial:T,connectionId:h.connectionId,metricRegistry:h.metricRegistry}),h}return q(t,o),t.prototype.getAllToggles=function(){return N([],this.toggles,!0)},t.prototype.isEnabled=function(e){var r,n=this.toggles.find((function(c){return c.name===e})),s=!!n&&n.enabled;if(this.metrics.count(e,s),(n==null?void 0:n.impressionData)||this.impressionDataAll){var i=this.eventsHandler.createImpressionEvent(this.context,s,e,wt,(r=n==null?void 0:n.impressionData)!==null&&r!==void 0?r:void 0);this.emit(y.IMPRESSION,i)}return s},t.prototype.getVariant=function(e){var r,n=this.toggles.find((function(l){return l.name===e})),s=(n==null?void 0:n.enabled)||!1,i=n?n.variant:It;if(i.name&&this.metrics.countVariant(e,i.name),this.metrics.count(e,s),(n==null?void 0:n.impressionData)||this.impressionDataAll){var c=this.eventsHandler.createImpressionEvent(this.context,s,e,Rt,(r=n==null?void 0:n.impressionData)!==null&&r!==void 0?r:void 0,i.name);this.emit(y.IMPRESSION,c)}return d(d({},i),{feature_enabled:s})},t.prototype.updateToggles=function(){return b(this,void 0,void 0,(function(){var e=this;return x(this,(function(r){switch(r.label){case 0:return this.timerRef||this.fetchedFromServer?[4,this.fetchToggles()]:[3,2];case 1:return r.sent(),[3,4];case 2:return this.started?[4,new Promise((function(n){var s=function(){e.fetchToggles().then((function(){e.off(y.READY,s),n()}))};e.once(y.READY,s)}))]:[3,4];case 3:r.sent(),r.label=4;case 4:return[2]}}))}))},t.prototype.updateContext=function(e){return b(this,void 0,void 0,(function(){var r;return x(this,(function(n){switch(n.label){case 0:return(e.appName||e.environment)&&this.emit(y.WARN,"appName and environment are static. They can't be updated with updateContext."),r={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=d(d({},r),e),[4,this.updateToggles()];case 1:return n.sent(),[2]}}))}))},t.prototype.getContext=function(){return d({},this.context)},t.prototype.setContextField=function(e,r){return b(this,void 0,void 0,(function(){var n,s,i;return x(this,(function(c){switch(c.label){case 0:return V(e)?this.context=d(d({},this.context),((s={})[e]=r,s)):(n=d(d({},this.context.properties),((i={})[e]=r,i)),this.context=d(d({},this.context),{properties:n})),[4,this.updateToggles()];case 1:return c.sent(),[2]}}))}))},t.prototype.removeContextField=function(e){return b(this,void 0,void 0,(function(){var r;return x(this,(function(n){switch(n.label){case 0:return V(e)?this.context=d(d({},this.context),((r={})[e]=void 0,r)):typeof this.context.properties=="object"&&delete this.context.properties[e],[4,this.updateToggles()];case 1:return n.sent(),[2]}}))}))},t.prototype.setReady=function(){this.readyEventEmitted=!0,this.emit(y.READY)},t.prototype.init=function(){return b(this,void 0,void 0,(function(){var e,r,n;return x(this,(function(s){switch(s.label){case 0:return[4,this.resolveSessionId()];case 1:return e=s.sent(),this.context=d({sessionId:e},this.context),[4,this.storage.get(H)];case 2:return r=s.sent()||[],n=this,[4,this.getLastRefreshTimestamp()];case 3:return n.lastRefreshTimestamp=s.sent(),!this.bootstrap||!this.bootstrapOverride&&r.length!==0?[3,6]:[4,this.storage.save(H,this.bootstrap)];case 4:return s.sent(),this.toggles=this.bootstrap,this.sdkState="healthy",[4,this.storeLastRefreshTimestamp()];case 5:return s.sent(),this.setReady(),[3,7];case 6:this.toggles=r,s.label=7;case 7:return this.sdkState="healthy",this.emit(y.INIT),[2]}}))}))},t.prototype.start=function(){return b(this,void 0,void 0,(function(){var e,r=this;return x(this,(function(n){switch(n.label){case 0:return this.started=!0,this.timerRef?(console.error("Unleash SDK has already started, if you want to restart the SDK you should call client.stop() before starting again."),[2]):[4,this.ready];case 1:return n.sent(),this.metrics.start(),e=this.refreshInterval,[4,this.initialFetchToggles()];case 2:return n.sent(),e>0&&(this.timerRef=setInterval((function(){return r.fetchToggles()}),e)),[2]}}))}))},t.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},t.prototype.isReady=function(){return this.readyEventEmitted},t.prototype.getError=function(){return this.sdkState==="error"?this.lastError:void 0},t.prototype.sendMetrics=function(){return this.metrics.sendMetrics()},t.prototype.resolveSessionId=function(){return b(this,void 0,void 0,(function(){var e;return x(this,(function(r){switch(r.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[4,this.storage.get("sessionId")];case 1:return(e=r.sent())?[3,3]:(e=Math.floor(1e9*Math.random()),[4,this.storage.save("sessionId",e.toString(10))]);case 2:r.sent(),r.label=3;case 3:return[2,e.toString(10)]}}))}))},t.prototype.getHeaders=function(){return z({clientKey:this.clientKey,connectionId:this.connectionId,appName:this.context.appName,customHeaders:this.customHeaders,headerName:this.headerName,etag:this.etag,isPost:this.usePOSTrequests})},t.prototype.storeToggles=function(e){return b(this,void 0,void 0,(function(){return x(this,(function(r){switch(r.label){case 0:return this.toggles=e,this.emit(y.UPDATE),[4,this.storage.save(H,e)];case 1:return r.sent(),[2]}}))}))},t.prototype.isTogglesStorageTTLEnabled=function(){var e;return!!(!((e=this.experimental)===null||e===void 0)&&e.togglesStorageTTL&&this.experimental.togglesStorageTTL>0)},t.prototype.isUpToDate=function(){var e;if(!this.isTogglesStorageTTLEnabled())return!1;var r=Date.now(),n=((e=this.experimental)===null||e===void 0?void 0:e.togglesStorageTTL)||0;return this.lastRefreshTimestamp>0&&this.lastRefreshTimestamp<=r&&r-this.lastRefreshTimestamp<=n},t.prototype.getLastRefreshTimestamp=function(){return b(this,void 0,void 0,(function(){var e,r;return x(this,(function(n){switch(n.label){case 0:return this.isTogglesStorageTTLEnabled()?[4,this.storage.get(tt)]:[3,3];case 1:return e=n.sent(),[4,W(this.context)];case 2:return r=n.sent(),[2,(e==null?void 0:e.key)===r?e.timestamp:0];case 3:return[2,0]}}))}))},t.prototype.storeLastRefreshTimestamp=function(){return b(this,void 0,void 0,(function(){var e,r;return x(this,(function(n){switch(n.label){case 0:return this.isTogglesStorageTTLEnabled()?(this.lastRefreshTimestamp=Date.now(),r={},[4,W(this.context)]):[3,3];case 1:return r.key=n.sent(),r.timestamp=this.lastRefreshTimestamp,e=r,[4,this.storage.save(tt,e)];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},t.prototype.initialFetchToggles=function(){if(!this.isUpToDate())return this.fetchToggles();this.fetchedFromServer||(this.fetchedFromServer=!0,this.setReady())},t.prototype.fetchToggles=function(){return b(this,void 0,void 0,(function(){var e,r,n,s,i,c,l,u,a;return x(this,(function(f){switch(f.label){case 0:if(!this.fetch)return[3,9];this.abortController&&!this.abortController.signal.aborted&&this.abortController.abort(),this.abortController=(a=this.createAbortController)===null||a===void 0?void 0:a.call(this),e=this.abortController?this.abortController.signal:void 0,f.label=1;case 1:return f.trys.push([1,7,8,9]),r=this.usePOSTrequests,n=r?this.url:(function(S,E){var T=new URL(S.toString());return Object.entries(E).filter(L).forEach((function(v){var g=v[0],w=v[1];g==="properties"&&w?Object.entries(w).filter(L).forEach((function(C){var P=C[0],F=C[1];return T.searchParams.append("properties[".concat(P,"]"),F)})):T.searchParams.append(g,w)})),T})(this.url,this.context),s=r?"POST":"GET",i=r?JSON.stringify({context:this.context}):void 0,[4,this.fetch(n.toString(),{method:s,cache:"no-cache",headers:this.getHeaders(),body:i,signal:e})];case 2:return c=f.sent(),this.sdkState==="error"&&c.status<400&&(this.sdkState="healthy",this.emit(y.RECOVERED)),c.ok?(this.etag=c.headers.get("ETag")||"",[4,c.json()]):[3,5];case 3:return l=f.sent(),[4,this.storeToggles(l.toggles)];case 4:return f.sent(),this.sdkState!=="healthy"&&(this.sdkState="healthy"),this.fetchedFromServer||(this.fetchedFromServer=!0,this.setReady()),this.storeLastRefreshTimestamp(),[3,6];case 5:c.status===304?this.storeLastRefreshTimestamp():(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.sdkState="error",this.emit(y.ERROR,{type:"HttpError",code:c.status}),this.lastError={type:"HttpError",code:c.status}),f.label=6;case 6:return[3,9];case 7:return typeof(u=f.sent())=="object"&&u!==null&&"name"in u&&u.name==="AbortError"||(console.error("Unleash: unable to fetch feature toggles",u),this.sdkState="error",this.emit(y.ERROR,{type:"fetch-toggles",error:u}),this.lastError=u),[3,9];case 8:return this.abortController=null,[7];case 9:return[2]}}))}))},t.prototype.resolveEnvironment=function(e,r){return(function(n){var s=n.indexOf(":");if(s!==-1){var i=n.slice(s+1),c=i.lastIndexOf(".");if(c!==-1)return i.slice(0,c)}})(e)||r},t})(Y.TinyEmitter);const R=Symbol("Context state identifier"),D=Symbol("Context update identifier");function rt({config:o,unleashClient:t,startClient:e=!0}){var E,T;const r=p.ref(t),n=p.ref(!1),s=p.ref(null);!o&&!t&&console.warn(`You must provide either a config or an unleash client to the flag provider. If you are initializing the client in useEffect, you can avoid this warning by
2
+ checking if the client exists before rendering.`),!r.value&&o&&(r.value=new et(o)),(E=r.value)==null||E.on("ready",()=>{n.value=!0}),(T=r.value)==null||T.on("error",v=>{s.value=v});const i=async v=>{var g;await((g=r.value)==null?void 0:g.updateContext(v))},c=v=>{var g;return(g=r.value)==null?void 0:g.isEnabled(v)},l=v=>{var g;return(g=r.value)==null?void 0:g.getVariant(v)},u=(v,...g)=>{var w;return(w=r.value)==null?void 0:w.on(v,...g)},a=p.reactive({on:u,updateContext:i,isEnabled:c,getVariant:l,client:r,flagsReady:n,flagsError:s}),f=(v,g)=>{a[v]=g},S=()=>{var v;(e||!t)&&((v=r==null?void 0:r.value)==null||v.start())};return{context:p.toRefs(a),update:f,start:S}}const nt=p.defineComponent({__name:"FlagProvider",props:{config:{},unleashClient:{},startClient:{type:Boolean,default:!0}},setup(o){const{context:t,start:e,update:r}=rt({config:o.config,unleashClient:o.unleashClient,startClient:o.startClient});return p.provide(R,t),p.provide(D,r),p.onMounted(()=>{e()}),(n,s)=>p.renderSlot(n.$slots,"default")}}),Ot=o=>{const{isEnabled:t,client:e}=p.inject(R,{}),r=p.ref(!!(t!=null&&t.value(o)));function n(){const i=t==null?void 0:t.value(o);i!==r.value&&(r.value=!!i)}function s(){r.value=!!(t!=null&&t.value(o))}return e==null||e.value.on("ready",s),e==null||e.value.on("update",n),p.onUnmounted(()=>{e==null||e.value.off("ready",s),e==null||e.value.off("update",n)}),r},Nt=()=>{const{flagsReady:o,flagsError:t}=p.inject(R,{});return{flagsReady:o,flagsError:t}},Ct=(o,t)=>{var r,n,s,i;return!((o==null?void 0:o.name)===(t==null?void 0:t.name)&&(o==null?void 0:o.enabled)===(t==null?void 0:t.enabled)&&(o==null?void 0:o.feature_enabled)===(t==null?void 0:t.feature_enabled)&&((r=o==null?void 0:o.payload)==null?void 0:r.type)===((n=t==null?void 0:t.payload)==null?void 0:n.type)&&((s=o==null?void 0:o.payload)==null?void 0:s.value)===((i=t==null?void 0:t.payload)==null?void 0:i.value))},Ut=o=>{const{getVariant:t,client:e}=p.inject(R,{}),r=p.ref(t==null?void 0:t.value(o));function n(){const i=t==null?void 0:t.value(o);Ct(r==null?void 0:r.value,i)&&(r.value=i)}function s(){r.value=t==null?void 0:t.value(o)}return e==null||e.value.on("ready",s),e==null||e.value.on("update",n),p.onUnmounted(()=>{e==null||e.value.off("ready",s),e==null||e.value.off("update",n)}),r||{}},At=()=>{const{updateContext:o}=p.inject(R,{});return o==null?void 0:o.value},Pt=()=>{const{client:o}=p.inject(R,{});return o==null?void 0:o.value},Mt={install(o,{config:t,unleashClient:e,startClient:r}){const{context:n,update:s,start:i}=rt({config:t,unleashClient:e,startClient:r});o.provide(R,n),o.provide(D,s),i()}};m.ContextStateSymbol=R,m.ContextUpdateSymbol=D,m.FlagProvider=nt,m.InMemoryStorageProvider=J,m.LocalStorageProvider=G,m.UnleashClient=et,m.default=nt,m.plugin=Mt,m.useFlag=Ot,m.useFlagsStatus=Nt,m.useUnleashClient=Pt,m.useUnleashContext=At,m.useVariant=Ut,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/dist/useFlag.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Ref } from 'vue';
2
- declare const useFlag: (name: string) => Ref<boolean>;
2
+ declare const useFlag: (name: string) => Ref<boolean, boolean>;
3
3
  export default useFlag;
@@ -1,6 +1,6 @@
1
1
  import { Ref } from 'vue';
2
2
  declare const useFlagsStatus: () => {
3
- flagsReady: Ref<boolean> | undefined;
4
- flagsError: Ref<boolean> | undefined;
3
+ flagsReady: Ref<boolean, boolean> | undefined;
4
+ flagsError: Ref<boolean, boolean> | undefined;
5
5
  };
6
6
  export default useFlagsStatus;
@@ -11,6 +11,16 @@ declare function useUnleashProvide({ config, unleashClient, startClient }: IProv
11
11
  isEnabled: (name: string) => boolean | undefined;
12
12
  getVariant: (name: string) => import("unleash-proxy-client").IVariant | undefined;
13
13
  client: {
14
+ impactMetrics: {
15
+ defineCounter: (name: string, help: string) => void;
16
+ defineHistogram: (name: string, help: string, buckets?: number[]) => void;
17
+ incrementCounter: (name: string, value?: number) => void;
18
+ observeHistogram: (name: string, value: number) => void;
19
+ on: (event: string, callback: Function, ctx?: any) => import("unleash-proxy-client/build/cjs/impact-metrics/metric-api").MetricsAPI;
20
+ once: (event: string, callback: Function, ctx?: any) => import("unleash-proxy-client/build/cjs/impact-metrics/metric-api").MetricsAPI;
21
+ emit: (event: string, ...args: any[]) => import("unleash-proxy-client/build/cjs/impact-metrics/metric-api").MetricsAPI;
22
+ off: (event: string, callback?: Function) => import("unleash-proxy-client/build/cjs/impact-metrics/metric-api").MetricsAPI;
23
+ };
14
24
  getAllToggles: () => import("unleash-proxy-client").IToggle[];
15
25
  isEnabled: (toggleName: string) => boolean;
16
26
  getVariant: (toggleName: string) => import("unleash-proxy-client").IVariant;
@@ -18,17 +28,17 @@ declare function useUnleashProvide({ config, unleashClient, startClient }: IProv
18
28
  updateContext: (context: IMutableContext) => Promise<void>;
19
29
  getContext: () => {
20
30
  appName: string;
21
- environment?: string | undefined;
22
- userId?: string | undefined;
23
- sessionId?: string | undefined;
24
- remoteAddress?: string | undefined;
25
- currentTime?: string | undefined;
31
+ environment?: string;
32
+ userId?: string;
33
+ sessionId?: string;
34
+ remoteAddress?: string;
35
+ currentTime?: string;
26
36
  properties?: {
27
37
  [key: string]: string;
28
- } | undefined;
38
+ };
29
39
  };
30
- setContextField: (field: string, value: string) => void;
31
- removeContextField: (field: string) => void;
40
+ setContextField: (field: string, value: string) => Promise<void>;
41
+ removeContextField: (field: string) => Promise<void>;
32
42
  start: () => Promise<void>;
33
43
  stop: () => void;
34
44
  isReady: () => boolean;
@@ -37,7 +47,7 @@ declare function useUnleashProvide({ config, unleashClient, startClient }: IProv
37
47
  on: (event: string, callback: Function, ctx?: any) => UnleashClient;
38
48
  once: (event: string, callback: Function, ctx?: any) => UnleashClient;
39
49
  emit: (event: string, ...args: any[]) => UnleashClient;
40
- off: (event: string, callback?: Function | undefined) => UnleashClient;
50
+ off: (event: string, callback?: Function) => UnleashClient;
41
51
  } | undefined;
42
52
  flagsReady: boolean;
43
53
  flagsError: null;
@@ -1,3 +1,4 @@
1
+ import { IVariant } from 'unleash-proxy-client';
1
2
  import { Ref } from 'vue';
2
3
  declare const useVariant: (name: string) => Ref<{
3
4
  name: string;
@@ -7,5 +8,13 @@ declare const useVariant: (name: string) => Ref<{
7
8
  type: string;
8
9
  value: string;
9
10
  } | undefined;
11
+ } | undefined, IVariant | {
12
+ name: string;
13
+ enabled: boolean;
14
+ feature_enabled?: boolean | undefined;
15
+ payload?: {
16
+ type: string;
17
+ value: string;
18
+ } | undefined;
10
19
  } | undefined>;
11
20
  export default useVariant;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unleash/proxy-client-vue",
3
- "version": "0.1.6",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Vue interface for working with Unleash",
5
5
  "main": "./dist/index.umd.js",
6
6
  "module": "./dist/index.es.js",
@@ -28,23 +28,22 @@
28
28
  },
29
29
  "scripts": {
30
30
  "dev": "vite",
31
- "build": "vue-tsc --noEmit && vite build",
32
- "prepare": "yarn build",
31
+ "build": "vite build && vue-tsc --emitDeclarationOnly",
32
+ "prepare": "npm run build",
33
33
  "preview": "vite preview"
34
34
  },
35
35
  "dependencies": {
36
- "unleash-proxy-client": "^3.7.2"
36
+ "unleash-proxy-client": "^3.8.2"
37
37
  },
38
38
  "peerDependencies": {
39
- "vue": "^3.2.45"
39
+ "vue": "^3.5.46"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/node": "^17.0.24",
43
- "@vitejs/plugin-vue": "^2.3.1",
44
- "typescript": "^4.5.4",
45
- "vite": "^2.9.2",
46
- "vite-plugin-dts": "^1.6.4",
47
- "vue": "^3.2.45",
48
- "vue-tsc": "^1.0.10"
42
+ "@types/node": "^22.0.0",
43
+ "@vitejs/plugin-vue": "^5.2.4",
44
+ "typescript": "^5.9.3",
45
+ "vite": "^6.4.5",
46
+ "vue": "^3.5.46",
47
+ "vue-tsc": "^3.3.14"
49
48
  }
50
49
  }
package/dist/env.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /// <reference types="vite/client" />
2
-
3
- declare module '*.vue' {
4
- import type { DefineComponent } from 'vue'
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6
- const component: DefineComponent<{}, {}, any>
7
- export default component
8
- }