@unleash/proxy-client-vue 0.0.1 → 0.0.2
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/README.md +8 -10
- package/dist/index.es.js +19 -7
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
PoC for a Vue SDK for [Unleash](https://www.getunleash.io/) based on the official [proxy-client-react](https://github.com/Unleash/proxy-client-react).
|
|
4
4
|
|
|
5
|
-
Check out a demo here: [proxy-client-vue-demo](https://github.com/nunogois/proxy-client-vue-demo).
|
|
6
|
-
|
|
7
5
|
# DISCLAIMER:
|
|
8
6
|
|
|
9
7
|
This library is meant to be used with the [unleash-proxy](https://github.com/Unleash/unleash-proxy). The proxy application layer will sit between your unleash instance and your client applications, and provides performance and security benefits. DO NOT TRY to connect this library directly to the unleash instance, as the datasets follow different formats because the proxy only returns evaluated toggle information.
|
|
@@ -11,9 +9,9 @@ This library is meant to be used with the [unleash-proxy](https://github.com/Unl
|
|
|
11
9
|
# Installation
|
|
12
10
|
|
|
13
11
|
```bash
|
|
14
|
-
npm install @
|
|
12
|
+
npm install @unleash/proxy-client-vue
|
|
15
13
|
// or
|
|
16
|
-
yarn add @
|
|
14
|
+
yarn add @unleash/proxy-client-vue
|
|
17
15
|
```
|
|
18
16
|
|
|
19
17
|
# Initialization
|
|
@@ -21,7 +19,7 @@ yarn add @nunogois/proxy-client-vue
|
|
|
21
19
|
Import the provider like this in your entrypoint file (typically App.vue):
|
|
22
20
|
|
|
23
21
|
```jsx
|
|
24
|
-
import FlagProvider from '@
|
|
22
|
+
import { FlagProvider } from '@unleash/proxy-client-vue'
|
|
25
23
|
|
|
26
24
|
const config = {
|
|
27
25
|
url: 'https://HOSTNAME/proxy',
|
|
@@ -41,7 +39,7 @@ const config = {
|
|
|
41
39
|
Alternatively, you can pass your own client in to the FlagProvider:
|
|
42
40
|
|
|
43
41
|
```jsx
|
|
44
|
-
import FlagProvider,
|
|
42
|
+
import { FlagProvider, UnleashClient } from '@unleash/proxy-client-vue'
|
|
45
43
|
|
|
46
44
|
const config = {
|
|
47
45
|
url: 'https://HOSTNAME/proxy',
|
|
@@ -107,7 +105,7 @@ To check if a feature is enabled:
|
|
|
107
105
|
|
|
108
106
|
```jsx
|
|
109
107
|
<script setup>
|
|
110
|
-
import { useFlag } from '@
|
|
108
|
+
import { useFlag } from '@unleash/proxy-client-vue'
|
|
111
109
|
|
|
112
110
|
const enabled = useFlag('travel.landing')
|
|
113
111
|
</script>
|
|
@@ -124,7 +122,7 @@ To check variants:
|
|
|
124
122
|
|
|
125
123
|
```jsx
|
|
126
124
|
<script setup>
|
|
127
|
-
import { useVariant } from '@
|
|
125
|
+
import { useVariant } from '@unleash/proxy-client-vue'
|
|
128
126
|
|
|
129
127
|
const variant = useVariant('travel.landing')
|
|
130
128
|
</script>
|
|
@@ -142,7 +140,7 @@ useFlagsStatus retrieves the ready state and error events.
|
|
|
142
140
|
Follow the following steps in order to delay rendering until the flags have been fetched.
|
|
143
141
|
|
|
144
142
|
```jsx
|
|
145
|
-
import { useFlagsStatus } from '@
|
|
143
|
+
import { useFlagsStatus } from '@unleash/proxy-client-vue'
|
|
146
144
|
|
|
147
145
|
const { flagsReady, flagsError } = useFlagsStatus()
|
|
148
146
|
|
|
@@ -155,7 +153,7 @@ const { flagsReady, flagsError } = useFlagsStatus()
|
|
|
155
153
|
Follow the following steps in order to update the unleash context:
|
|
156
154
|
|
|
157
155
|
```jsx
|
|
158
|
-
import { useUnleashContext, useFlag } from '@
|
|
156
|
+
import { useUnleashContext, useFlag } from '@unleash/proxy-client-vue'
|
|
159
157
|
|
|
160
158
|
const props = defineProps<{
|
|
161
159
|
userId: string
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, ref, onMounted, reactive, provide, toRefs, renderSlot, inject } from "vue";
|
|
1
|
+
import { defineComponent, ref, onMounted, reactive, provide, toRefs, renderSlot, inject, onUnmounted } from "vue";
|
|
2
2
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
3
3
|
function getAugmentedNamespace(n) {
|
|
4
4
|
if (n.__esModule)
|
|
@@ -1549,14 +1549,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1549
1549
|
const useFlag = (name) => {
|
|
1550
1550
|
const { isEnabled, client } = inject(ContextStateSymbol) || {};
|
|
1551
1551
|
const flag = ref(!!isEnabled.value(name));
|
|
1552
|
-
|
|
1552
|
+
function onUpdate() {
|
|
1553
1553
|
const enabled = isEnabled.value(name);
|
|
1554
1554
|
if (enabled !== flag.value) {
|
|
1555
1555
|
flag.value = !!enabled;
|
|
1556
1556
|
}
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1557
|
+
}
|
|
1558
|
+
function onReady() {
|
|
1559
1559
|
flag.value = isEnabled.value(name);
|
|
1560
|
+
}
|
|
1561
|
+
client.value.on("ready", onReady);
|
|
1562
|
+
client.value.on("update", onUpdate);
|
|
1563
|
+
onUnmounted(() => {
|
|
1564
|
+
client.value.off("ready", onReady);
|
|
1565
|
+
client.value.off("update", onUpdate);
|
|
1560
1566
|
});
|
|
1561
1567
|
return flag;
|
|
1562
1568
|
};
|
|
@@ -1567,14 +1573,20 @@ const useFlagsStatus = () => {
|
|
|
1567
1573
|
const useVariant = (name) => {
|
|
1568
1574
|
const { getVariant, client } = inject(ContextStateSymbol) || {};
|
|
1569
1575
|
const variant = ref(getVariant.value(name));
|
|
1570
|
-
|
|
1576
|
+
function onUpdate() {
|
|
1571
1577
|
const newVariant = getVariant.value(name);
|
|
1572
1578
|
if (newVariant.name !== variant.value.name || newVariant.enabled !== variant.value.enabled) {
|
|
1573
1579
|
variant.value = newVariant;
|
|
1574
1580
|
}
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1581
|
+
}
|
|
1582
|
+
function onReady() {
|
|
1577
1583
|
variant.value = getVariant.value(name);
|
|
1584
|
+
}
|
|
1585
|
+
client.value.on("ready", onReady);
|
|
1586
|
+
client.value.on("update", onUpdate);
|
|
1587
|
+
onUnmounted(() => {
|
|
1588
|
+
client.value.off("ready", onReady);
|
|
1589
|
+
client.value.off("update", onUpdate);
|
|
1578
1590
|
});
|
|
1579
1591
|
return variant || {};
|
|
1580
1592
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(x,I){typeof exports=="object"&&typeof module!="undefined"?I(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],I):(x=typeof globalThis!="undefined"?globalThis:x||self,I(x["proxy-client-vue"]={},x.Vue))})(this,function(x,I){"use strict";var g=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function Ne(t){if(t.__esModule)return t;var i=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach(function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}),i}var $={},W={exports:{}};function ee(){}ee.prototype={on:function(t,i,e){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:i,ctx:e}),this},once:function(t,i,e){var n=this;function a(){n.off(t,a),i.apply(e,arguments)}return a._=i,this.on(t,a,e)},emit:function(t){var i=[].slice.call(arguments,1),e=((this.e||(this.e={}))[t]||[]).slice(),n=0,a=e.length;for(n;n<a;n++)e[n].fn.apply(e[n].ctx,i);return this},off:function(t,i){var e=this.e||(this.e={}),n=e[t],a=[];if(n&&i)for(var r=0,o=n.length;r<o;r++)n[r].fn!==i&&n[r].fn._!==i&&a.push(n[r]);return a.length?e[t]=a:delete e[t],this}},W.exports=ee,W.exports.TinyEmitter=ee;var te={},G=g&&g.__assign||function(){return G=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++){i=arguments[e];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},G.apply(this,arguments)},xe=g&&g.__awaiter||function(t,i,e,n){function a(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function d(h){try{s(n.next(h))}catch(m){o(m)}}function v(h){try{s(n.throw(h))}catch(m){o(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,i||[])).next())})},Oe=g&&g.__generator||function(t,i){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,o;return o={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=i.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(te,"__esModule",{value:!0});var Re=function(){function t(i){var e=i.appName,n=i.metricsInterval,a=i.disableMetrics,r=a===void 0?!1:a,o=i.url,d=i.clientKey,v=i.fetch,s=i.headerName;this.disabled=r,this.metricsInterval=n*1e3,this.appName=e,this.url=o,this.clientKey=d,this.bucket=this.createEmptyBucket(),this.fetch=v,this.headerName=s}return t.prototype.start=function(){var i=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){i.startTimer(),i.sendMetrics()},2e3)},t.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},t.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},t.prototype.sendMetrics=function(){return xe(this,void 0,void 0,function(){var i,e,n;return Oe(this,function(a){switch(a.label){case 0:return i="".concat(this.url,"/client/metrics"),e=this.getPayload(),this.bucketIsEmpty(e)?[2]:[4,this.fetch(i,{cache:"no-cache",method:"POST",headers:(n={},n[this.headerName]=this.clientKey,n.Accept="application/json",n["Content-Type"]="application/json",n),body:JSON.stringify(e)})];case 1:return a.sent(),[2]}})})},t.prototype.count=function(i,e){return this.disabled||!this.bucket?!1:(this.assertBucket(i),this.bucket.toggles[i][e?"yes":"no"]++,!0)},t.prototype.assertBucket=function(i){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[i]||(this.bucket.toggles[i]={yes:0,no:0})},t.prototype.startTimer=function(){var i=this;this.timer=setInterval(function(){i.sendMetrics()},this.metricsInterval)},t.prototype.bucketIsEmpty=function(i){return Object.keys(i.bucket.toggles).length===0},t.prototype.getPayload=function(){var i=G(G({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:i,appName:this.appName,instanceId:"browser"}},t}();te.default=Re;var re={},de=g&&g.__awaiter||function(t,i,e,n){function a(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function d(h){try{s(n.next(h))}catch(m){o(m)}}function v(h){try{s(n.throw(h))}catch(m){o(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,i||[])).next())})},ve=g&&g.__generator||function(t,i){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,o;return o={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=i.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(re,"__esModule",{value:!0});var Ce=function(){function t(){this.store=new Map}return t.prototype.save=function(i,e){return de(this,void 0,void 0,function(){return ve(this,function(n){return this.store.set(i,e),[2]})})},t.prototype.get=function(i){return de(this,void 0,void 0,function(){return ve(this,function(e){return[2,this.store.get(i)]})})},t}();re.default=Ce;var ne={},Ue=g&&g.__awaiter||function(t,i,e,n){function a(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function d(h){try{s(n.next(h))}catch(m){o(m)}}function v(h){try{s(n.throw(h))}catch(m){o(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,i||[])).next())})},Me=g&&g.__generator||function(t,i){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,o;return o={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=i.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(ne,"__esModule",{value:!0});var Ae=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(i,e){return Ue(this,void 0,void 0,function(){var n,a;return Me(this,function(r){n=JSON.stringify(e),a="".concat(this.prefix,":").concat(i);try{window.localStorage.setItem(a,n)}catch(o){console.error(o)}return[2]})})},t.prototype.get=function(i){try{var e="".concat(this.prefix,":").concat(i),n=window.localStorage.getItem(e);return n?JSON.parse(n):void 0}catch(a){console.error(a)}},t}();ne.default=Ae;var ae={},B,ke=new Uint8Array(16);function pe(){if(!B&&(B=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!B))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return B(ke)}var Pe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Y(t){return typeof t=="string"&&Pe.test(t)}for(var S=[],ie=0;ie<256;++ie)S.push((ie+256).toString(16).substr(1));function J(t){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(S[t[i+0]]+S[t[i+1]]+S[t[i+2]]+S[t[i+3]]+"-"+S[t[i+4]]+S[t[i+5]]+"-"+S[t[i+6]]+S[t[i+7]]+"-"+S[t[i+8]]+S[t[i+9]]+"-"+S[t[i+10]]+S[t[i+11]]+S[t[i+12]]+S[t[i+13]]+S[t[i+14]]+S[t[i+15]]).toLowerCase();if(!Y(e))throw TypeError("Stringified UUID is invalid");return e}var ye,oe,se=0,ue=0;function je(t,i,e){var n=i&&e||0,a=i||new Array(16);t=t||{};var r=t.node||ye,o=t.clockseq!==void 0?t.clockseq:oe;if(r==null||o==null){var d=t.random||(t.rng||pe)();r==null&&(r=ye=[d[0]|1,d[1],d[2],d[3],d[4],d[5]]),o==null&&(o=oe=(d[6]<<8|d[7])&16383)}var v=t.msecs!==void 0?t.msecs:Date.now(),s=t.nsecs!==void 0?t.nsecs:ue+1,h=v-se+(s-ue)/1e4;if(h<0&&t.clockseq===void 0&&(o=o+1&16383),(h<0||v>se)&&t.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");se=v,ue=s,oe=o,v+=122192928e5;var m=((v&268435455)*1e4+s)%4294967296;a[n++]=m>>>24&255,a[n++]=m>>>16&255,a[n++]=m>>>8&255,a[n++]=m&255;var M=v/4294967296*1e4&268435455;a[n++]=M>>>8&255,a[n++]=M&255,a[n++]=M>>>24&15|16,a[n++]=M>>>16&255,a[n++]=o>>>8|128,a[n++]=o&255;for(var A=0;A<6;++A)a[n+A]=r[A];return i||J(a)}function ge(t){if(!Y(t))throw TypeError("Invalid UUID");var i,e=new Uint8Array(16);return e[0]=(i=parseInt(t.slice(0,8),16))>>>24,e[1]=i>>>16&255,e[2]=i>>>8&255,e[3]=i&255,e[4]=(i=parseInt(t.slice(9,13),16))>>>8,e[5]=i&255,e[6]=(i=parseInt(t.slice(14,18),16))>>>8,e[7]=i&255,e[8]=(i=parseInt(t.slice(19,23),16))>>>8,e[9]=i&255,e[10]=(i=parseInt(t.slice(24,36),16))/1099511627776&255,e[11]=i/4294967296&255,e[12]=i>>>24&255,e[13]=i>>>16&255,e[14]=i>>>8&255,e[15]=i&255,e}function Ve(t){t=unescape(encodeURIComponent(t));for(var i=[],e=0;e<t.length;++e)i.push(t.charCodeAt(e));return i}var De="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Le="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function me(t,i,e){function n(a,r,o,d){if(typeof a=="string"&&(a=Ve(a)),typeof r=="string"&&(r=ge(r)),r.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var v=new Uint8Array(16+a.length);if(v.set(r),v.set(a,r.length),v=e(v),v[6]=v[6]&15|i,v[8]=v[8]&63|128,o){d=d||0;for(var s=0;s<16;++s)o[d+s]=v[s];return o}return J(v)}try{n.name=t}catch{}return n.DNS=De,n.URL=Le,n}function Ke(t){if(typeof t=="string"){var i=unescape(encodeURIComponent(t));t=new Uint8Array(i.length);for(var e=0;e<i.length;++e)t[e]=i.charCodeAt(e)}return Fe($e(qe(t),t.length*8))}function Fe(t){for(var i=[],e=t.length*32,n="0123456789abcdef",a=0;a<e;a+=8){var r=t[a>>5]>>>a%32&255,o=parseInt(n.charAt(r>>>4&15)+n.charAt(r&15),16);i.push(o)}return i}function be(t){return(t+64>>>9<<4)+14+1}function $e(t,i){t[i>>5]|=128<<i%32,t[be(i)-1]=i;for(var e=1732584193,n=-271733879,a=-1732584194,r=271733878,o=0;o<t.length;o+=16){var d=e,v=n,s=a,h=r;e=O(e,n,a,r,t[o],7,-680876936),r=O(r,e,n,a,t[o+1],12,-389564586),a=O(a,r,e,n,t[o+2],17,606105819),n=O(n,a,r,e,t[o+3],22,-1044525330),e=O(e,n,a,r,t[o+4],7,-176418897),r=O(r,e,n,a,t[o+5],12,1200080426),a=O(a,r,e,n,t[o+6],17,-1473231341),n=O(n,a,r,e,t[o+7],22,-45705983),e=O(e,n,a,r,t[o+8],7,1770035416),r=O(r,e,n,a,t[o+9],12,-1958414417),a=O(a,r,e,n,t[o+10],17,-42063),n=O(n,a,r,e,t[o+11],22,-1990404162),e=O(e,n,a,r,t[o+12],7,1804603682),r=O(r,e,n,a,t[o+13],12,-40341101),a=O(a,r,e,n,t[o+14],17,-1502002290),n=O(n,a,r,e,t[o+15],22,1236535329),e=R(e,n,a,r,t[o+1],5,-165796510),r=R(r,e,n,a,t[o+6],9,-1069501632),a=R(a,r,e,n,t[o+11],14,643717713),n=R(n,a,r,e,t[o],20,-373897302),e=R(e,n,a,r,t[o+5],5,-701558691),r=R(r,e,n,a,t[o+10],9,38016083),a=R(a,r,e,n,t[o+15],14,-660478335),n=R(n,a,r,e,t[o+4],20,-405537848),e=R(e,n,a,r,t[o+9],5,568446438),r=R(r,e,n,a,t[o+14],9,-1019803690),a=R(a,r,e,n,t[o+3],14,-187363961),n=R(n,a,r,e,t[o+8],20,1163531501),e=R(e,n,a,r,t[o+13],5,-1444681467),r=R(r,e,n,a,t[o+2],9,-51403784),a=R(a,r,e,n,t[o+7],14,1735328473),n=R(n,a,r,e,t[o+12],20,-1926607734),e=C(e,n,a,r,t[o+5],4,-378558),r=C(r,e,n,a,t[o+8],11,-2022574463),a=C(a,r,e,n,t[o+11],16,1839030562),n=C(n,a,r,e,t[o+14],23,-35309556),e=C(e,n,a,r,t[o+1],4,-1530992060),r=C(r,e,n,a,t[o+4],11,1272893353),a=C(a,r,e,n,t[o+7],16,-155497632),n=C(n,a,r,e,t[o+10],23,-1094730640),e=C(e,n,a,r,t[o+13],4,681279174),r=C(r,e,n,a,t[o],11,-358537222),a=C(a,r,e,n,t[o+3],16,-722521979),n=C(n,a,r,e,t[o+6],23,76029189),e=C(e,n,a,r,t[o+9],4,-640364487),r=C(r,e,n,a,t[o+12],11,-421815835),a=C(a,r,e,n,t[o+15],16,530742520),n=C(n,a,r,e,t[o+2],23,-995338651),e=U(e,n,a,r,t[o],6,-198630844),r=U(r,e,n,a,t[o+7],10,1126891415),a=U(a,r,e,n,t[o+14],15,-1416354905),n=U(n,a,r,e,t[o+5],21,-57434055),e=U(e,n,a,r,t[o+12],6,1700485571),r=U(r,e,n,a,t[o+3],10,-1894986606),a=U(a,r,e,n,t[o+10],15,-1051523),n=U(n,a,r,e,t[o+1],21,-2054922799),e=U(e,n,a,r,t[o+8],6,1873313359),r=U(r,e,n,a,t[o+15],10,-30611744),a=U(a,r,e,n,t[o+6],15,-1560198380),n=U(n,a,r,e,t[o+13],21,1309151649),e=U(e,n,a,r,t[o+4],6,-145523070),r=U(r,e,n,a,t[o+11],10,-1120210379),a=U(a,r,e,n,t[o+2],15,718787259),n=U(n,a,r,e,t[o+9],21,-343485551),e=L(e,d),n=L(n,v),a=L(a,s),r=L(r,h)}return[e,n,a,r]}function qe(t){if(t.length===0)return[];for(var i=t.length*8,e=new Uint32Array(be(i)),n=0;n<i;n+=8)e[n>>5]|=(t[n/8]&255)<<n%32;return e}function L(t,i){var e=(t&65535)+(i&65535),n=(t>>16)+(i>>16)+(e>>16);return n<<16|e&65535}function He(t,i){return t<<i|t>>>32-i}function Q(t,i,e,n,a,r){return L(He(L(L(i,t),L(n,r)),a),e)}function O(t,i,e,n,a,r,o){return Q(i&e|~i&n,t,i,a,r,o)}function R(t,i,e,n,a,r,o){return Q(i&n|e&~n,t,i,a,r,o)}function C(t,i,e,n,a,r,o){return Q(i^e^n,t,i,a,r,o)}function U(t,i,e,n,a,r,o){return Q(e^(i|~n),t,i,a,r,o)}var Ge=me("v3",48,Ke),Be=Ge;function Ye(t,i,e){t=t||{};var n=t.random||(t.rng||pe)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,i){e=e||0;for(var a=0;a<16;++a)i[e+a]=n[a];return i}return J(n)}function Je(t,i,e,n){switch(t){case 0:return i&e^~i&n;case 1:return i^e^n;case 2:return i&e^i&n^e&n;case 3:return i^e^n}}function ce(t,i){return t<<i|t>>>32-i}function Qe(t){var i=[1518500249,1859775393,2400959708,3395469782],e=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof t=="string"){var n=unescape(encodeURIComponent(t));t=[];for(var a=0;a<n.length;++a)t.push(n.charCodeAt(a))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var r=t.length/4+2,o=Math.ceil(r/16),d=new Array(o),v=0;v<o;++v){for(var s=new Uint32Array(16),h=0;h<16;++h)s[h]=t[v*64+h*4]<<24|t[v*64+h*4+1]<<16|t[v*64+h*4+2]<<8|t[v*64+h*4+3];d[v]=s}d[o-1][14]=(t.length-1)*8/Math.pow(2,32),d[o-1][14]=Math.floor(d[o-1][14]),d[o-1][15]=(t.length-1)*8&4294967295;for(var m=0;m<o;++m){for(var M=new Uint32Array(80),A=0;A<16;++A)M[A]=d[m][A];for(var j=16;j<80;++j)M[j]=ce(M[j-3]^M[j-8]^M[j-14]^M[j-16],1);for(var b=e[0],w=e[1],V=e[2],E=e[3],p=e[4],u=0;u<80;++u){var c=Math.floor(u/20),f=ce(b,5)+Je(c,w,V,E)+p+i[c]+M[u]>>>0;p=E,E=V,V=ce(w,30)>>>0,w=b,b=f}e[0]=e[0]+b>>>0,e[1]=e[1]+w>>>0,e[2]=e[2]+V>>>0,e[3]=e[3]+E>>>0,e[4]=e[4]+p>>>0}return[e[0]>>24&255,e[0]>>16&255,e[0]>>8&255,e[0]&255,e[1]>>24&255,e[1]>>16&255,e[1]>>8&255,e[1]&255,e[2]>>24&255,e[2]>>16&255,e[2]>>8&255,e[2]&255,e[3]>>24&255,e[3]>>16&255,e[3]>>8&255,e[3]&255,e[4]>>24&255,e[4]>>16&255,e[4]>>8&255,e[4]&255]}var Xe=me("v5",80,Qe),ze=Xe,Ze="00000000-0000-0000-0000-000000000000";function We(t){if(!Y(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}var et=Object.freeze(Object.defineProperty({__proto__:null,v1:je,v3:Be,v4:Ye,v5:ze,NIL:Ze,version:We,validate:Y,stringify:J,parse:ge},Symbol.toStringTag,{value:"Module"})),tt=Ne(et),X=g&&g.__assign||function(){return X=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++){i=arguments[e];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},X.apply(this,arguments)};Object.defineProperty(ae,"__esModule",{value:!0});var rt=tt,nt=function(){function t(){}return t.prototype.generateEventId=function(){return(0,rt.v4)()},t.prototype.createImpressionEvent=function(i,e,n,a,r){var o=this.createBaseEvent(i,e,n,a);return r?X(X({},o),{variant:r}):o},t.prototype.createBaseEvent=function(i,e,n,a){return{eventType:a,eventId:this.generateEventId(),context:i,enabled:e,featureName:n}},t}();ae.default=nt;var z={};Object.defineProperty(z,"__esModule",{value:!0}),z.notNullOrUndefined=void 0;var at=function(t){var i=t[1];return i!=null};z.notNullOrUndefined=at,function(t){var i=g&&g.__extends||function(){var E=function(p,u){return E=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(c,f){c.__proto__=f}||function(c,f){for(var l in f)Object.prototype.hasOwnProperty.call(f,l)&&(c[l]=f[l])},E(p,u)};return function(p,u){if(typeof u!="function"&&u!==null)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");E(p,u);function c(){this.constructor=p}p.prototype=u===null?Object.create(u):(c.prototype=u.prototype,new c)}}(),e=g&&g.__assign||function(){return e=Object.assign||function(E){for(var p,u=1,c=arguments.length;u<c;u++){p=arguments[u];for(var f in p)Object.prototype.hasOwnProperty.call(p,f)&&(E[f]=p[f])}return E},e.apply(this,arguments)},n=g&&g.__awaiter||function(E,p,u,c){function f(l){return l instanceof u?l:new u(function(_){_(l)})}return new(u||(u=Promise))(function(l,_){function P(T){try{y(c.next(T))}catch(D){_(D)}}function k(T){try{y(c.throw(T))}catch(D){_(D)}}function y(T){T.done?l(T.value):f(T.value).then(P,k)}y((c=c.apply(E,p||[])).next())})},a=g&&g.__generator||function(E,p){var u={label:0,sent:function(){if(l[0]&1)throw l[1];return l[1]},trys:[],ops:[]},c,f,l,_;return _={next:P(0),throw:P(1),return:P(2)},typeof Symbol=="function"&&(_[Symbol.iterator]=function(){return this}),_;function P(y){return function(T){return k([y,T])}}function k(y){if(c)throw new TypeError("Generator is already executing.");for(;u;)try{if(c=1,f&&(l=y[0]&2?f.return:y[0]?f.throw||((l=f.return)&&l.call(f),0):f.next)&&!(l=l.call(f,y[1])).done)return l;switch(f=0,l&&(y=[y[0]&2,l.value]),y[0]){case 0:case 1:l=y;break;case 4:return u.label++,{value:y[1],done:!1};case 5:u.label++,f=y[1],y=[0];continue;case 7:y=u.ops.pop(),u.trys.pop();continue;default:if(l=u.trys,!(l=l.length>0&&l[l.length-1])&&(y[0]===6||y[0]===2)){u=0;continue}if(y[0]===3&&(!l||y[1]>l[0]&&y[1]<l[3])){u.label=y[1];break}if(y[0]===6&&u.label<l[1]){u.label=l[1],l=y;break}if(l&&u.label<l[2]){u.label=l[2],u.ops.push(y);break}l[2]&&u.ops.pop(),u.trys.pop();continue}y=p.call(E,u)}catch(T){y=[6,T],f=0}finally{c=l=0}if(y[0]&5)throw y[1];return{value:y[0]?y[1]:void 0,done:!0}}},r=g&&g.__spreadArray||function(E,p,u){if(u||arguments.length===2)for(var c=0,f=p.length,l;c<f;c++)(l||!(c in p))&&(l||(l=Array.prototype.slice.call(p,0,c)),l[c]=p[c]);return E.concat(l||Array.prototype.slice.call(p))};Object.defineProperty(t,"__esModule",{value:!0}),t.InMemoryStorageProvider=t.LocalStorageProvider=t.UnleashClient=t.resolveFetch=t.EVENTS=void 0;var o=W.exports,d=te,v=re;t.InMemoryStorageProvider=v.default;var s=ne;t.LocalStorageProvider=s.default;var h=ae,m=z,M=["userId","sessionId","remoteAddress"];t.EVENTS={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression"};var A={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},j={name:"disabled",enabled:!1},b="repo",w=function(){try{if("fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(E){console.error('Unleash failed to resolve "fetch"',E)}};t.resolveFetch=w;var V=function(E){i(p,E);function p(u){var c=u.storageProvider,f=u.url,l=u.clientKey,_=u.disableRefresh,P=_===void 0?!1:_,k=u.refreshInterval,y=k===void 0?30:k,T=u.metricsInterval,D=T===void 0?30:T,q=u.disableMetrics,fe=q===void 0?!1:q,H=u.appName,Ee=u.environment,lt=Ee===void 0?"default":Ee,ht=u.context,Ie=u.fetch,le=Ie===void 0?(0,t.resolveFetch)():Ie,F=u.bootstrap,_e=u.bootstrapOverride,dt=_e===void 0?!0:_e,Se=u.headerName,Te=Se===void 0?"Authorization":Se,N=E.call(this)||this;if(N.toggles=[],N.etag="",!f)throw new Error("url is required");if(!l)throw new Error("clientKey is required");if(!H)throw new Error("appName is required.");return N.eventsHandler=new h.default,N.toggles=F&&F.length>0?F:[],N.url=new URL("".concat(f)),N.clientKey=l,N.headerName=Te,N.storage=c||new s.default,N.refreshInterval=P?0:y*1e3,N.context=e({appName:H,environment:lt},ht),N.ready=new Promise(function(vt){return n(N,void 0,void 0,function(){var he;return a(this,function(Z){switch(Z.label){case 0:return Z.trys.push([0,2,,3]),[4,this.init()];case 1:return Z.sent(),[3,3];case 2:return he=Z.sent(),console.error(he),this.emit(t.EVENTS.ERROR,he),[3,3];case 3:return vt(),[2]}})})}),le||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),N.fetch=le,N.bootstrap=F&&F.length>0?F:void 0,N.bootstrapOverride=dt,N.metrics=new d.default({appName:H,metricsInterval:D,disableMetrics:fe,url:f,clientKey:l,fetch:le,headerName:Te}),N}return p.prototype.getAllToggles=function(){return r([],this.toggles,!0)},p.prototype.isEnabled=function(u){var c=this.toggles.find(function(_){return _.name===u}),f=c?c.enabled:!1;if(this.metrics.count(u,f),c!=null&&c.impressionData){var l=this.eventsHandler.createImpressionEvent(this.context,f,u,A.IS_ENABLED);this.emit(t.EVENTS.IMPRESSION,l)}return f},p.prototype.getVariant=function(u){var c=this.toggles.find(function(l){return l.name===u});if(c){if(this.metrics.count(u,!0),c.impressionData){var f=this.eventsHandler.createImpressionEvent(this.context,c.enabled,u,A.GET_VARIANT,c.variant.name);this.emit(t.EVENTS.IMPRESSION,f)}return c.variant}else return this.metrics.count(u,!1),j},p.prototype.updateContext=function(u){return n(this,void 0,void 0,function(){var c;return a(this,function(f){switch(f.label){case 0:return(u.appName||u.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),c={environment:this.context.environment,appName:this.context.appName},this.context=e(e({},c),u),this.timerRef?[4,this.fetchToggles()]:[3,2];case 1:f.sent(),f.label=2;case 2:return[2]}})})},p.prototype.getContext=function(){return e({},this.context)},p.prototype.setContextField=function(u,c){var f,l;if(M.includes(u))this.context=e(e({},this.context),(f={},f[u]=c,f));else{var _=e(e({},this.context.properties),(l={},l[u]=c,l));this.context=e(e({},this.context),{properties:_})}this.timerRef&&this.fetchToggles()},p.prototype.init=function(){return n(this,void 0,void 0,function(){var u,c;return a(this,function(f){switch(f.label){case 0:return[4,this.resolveSessionId()];case 1:return u=f.sent(),this.context=e({sessionId:u},this.context),c=this,[4,this.storage.get(b)];case 2:return c.toggles=f.sent()||[],this.bootstrap&&(this.bootstrapOverride||this.toggles.length===0)?[4,this.storage.save(b,this.bootstrap)]:[3,4];case 3:f.sent(),this.toggles=this.bootstrap,this.emit(t.EVENTS.READY),f.label=4;case 4:return this.emit(t.EVENTS.INIT),[2]}})})},p.prototype.start=function(){return n(this,void 0,void 0,function(){var u,c=this;return a(this,function(f){switch(f.label){case 0:return 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 f.sent(),this.metrics.start(),u=this.refreshInterval,[4,this.fetchToggles()];case 2:return f.sent(),this.bootstrap||this.emit(t.EVENTS.READY),u>0&&(this.timerRef=setInterval(function(){return c.fetchToggles()},u)),[2]}})})},p.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},p.prototype.resolveSessionId=function(){return n(this,void 0,void 0,function(){var u;return a(this,function(c){switch(c.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return u=c.sent(),u?[3,4]:(u=Math.floor(Math.random()*1e9),[4,this.storage.save("sessionId",u)]);case 3:c.sent(),c.label=4;case 4:return[2,u]}})})},p.prototype.storeToggles=function(u){return n(this,void 0,void 0,function(){return a(this,function(c){switch(c.label){case 0:return this.toggles=u,this.emit(t.EVENTS.UPDATE),[4,this.storage.save(b,u)];case 1:return c.sent(),[2]}})})},p.prototype.fetchToggles=function(){return n(this,void 0,void 0,function(){var u,c,f,l,_,P;return a(this,function(k){switch(k.label){case 0:if(!this.fetch)return[3,7];k.label=1;case 1:return k.trys.push([1,6,,7]),u=this.context,c=new URL(this.url.toString()),Object.entries(u).filter(m.notNullOrUndefined).forEach(function(y){var T=y[0],D=y[1];T==="properties"&&D?Object.entries(D).filter(m.notNullOrUndefined).forEach(function(q){var fe=q[0],H=q[1];return c.searchParams.append("properties[".concat(fe,"]"),H)}):c.searchParams.append(T,D)}),[4,this.fetch(c.toString(),{cache:"no-cache",headers:(P={},P[this.headerName]=this.clientKey,P.Accept="application/json",P["Content-Type"]="application/json",P["If-None-Match"]=this.etag,P)})];case 2:return f=k.sent(),f.ok&&f.status!==304?(this.etag=f.headers.get("ETag")||"",[4,f.json()]):[3,5];case 3:return l=k.sent(),[4,this.storeToggles(l.toggles)];case 4:k.sent(),k.label=5;case 5:return[3,7];case 6:return _=k.sent(),console.error("Unleash: unable to fetch feature toggles",_),this.emit(t.EVENTS.ERROR,_),[3,7];case 7:return[2]}})})},p}(o.TinyEmitter);t.UnleashClient=V}($);const K=Symbol("Context state identifier"),it=Symbol("Context update identifier"),we=I.defineComponent({props:{config:null,unleashClient:null,startClient:{type:Boolean}},setup(t){var A,j;const{config:i,unleashClient:e,startClient:n=!0}=t,a=I.ref(e),r=I.ref(!1),o=I.ref(null);!i&&!e&&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.`),!a.value&&i&&(a.value=new $.UnleashClient(i)),(A=a.value)==null||A.on("ready",()=>{r.value=!0}),(j=a.value)==null||j.on("error",
|
|
1
|
+
(function(x,b){typeof exports=="object"&&typeof module!="undefined"?b(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],b):(x=typeof globalThis!="undefined"?globalThis:x||self,b(x["proxy-client-vue"]={},x.Vue))})(this,function(x,b){"use strict";var g=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function Ne(t){if(t.__esModule)return t;var i=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach(function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}),i}var $={},W={exports:{}};function ee(){}ee.prototype={on:function(t,i,e){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:i,ctx:e}),this},once:function(t,i,e){var n=this;function a(){n.off(t,a),i.apply(e,arguments)}return a._=i,this.on(t,a,e)},emit:function(t){var i=[].slice.call(arguments,1),e=((this.e||(this.e={}))[t]||[]).slice(),n=0,a=e.length;for(n;n<a;n++)e[n].fn.apply(e[n].ctx,i);return this},off:function(t,i){var e=this.e||(this.e={}),n=e[t],a=[];if(n&&i)for(var r=0,o=n.length;r<o;r++)n[r].fn!==i&&n[r].fn._!==i&&a.push(n[r]);return a.length?e[t]=a:delete e[t],this}},W.exports=ee,W.exports.TinyEmitter=ee;var te={},G=g&&g.__assign||function(){return G=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++){i=arguments[e];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},G.apply(this,arguments)},xe=g&&g.__awaiter||function(t,i,e,n){function a(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function d(h){try{s(n.next(h))}catch(m){o(m)}}function v(h){try{s(n.throw(h))}catch(m){o(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,i||[])).next())})},Oe=g&&g.__generator||function(t,i){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,o;return o={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=i.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(te,"__esModule",{value:!0});var Ue=function(){function t(i){var e=i.appName,n=i.metricsInterval,a=i.disableMetrics,r=a===void 0?!1:a,o=i.url,d=i.clientKey,v=i.fetch,s=i.headerName;this.disabled=r,this.metricsInterval=n*1e3,this.appName=e,this.url=o,this.clientKey=d,this.bucket=this.createEmptyBucket(),this.fetch=v,this.headerName=s}return t.prototype.start=function(){var i=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){i.startTimer(),i.sendMetrics()},2e3)},t.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},t.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},t.prototype.sendMetrics=function(){return xe(this,void 0,void 0,function(){var i,e,n;return Oe(this,function(a){switch(a.label){case 0:return i="".concat(this.url,"/client/metrics"),e=this.getPayload(),this.bucketIsEmpty(e)?[2]:[4,this.fetch(i,{cache:"no-cache",method:"POST",headers:(n={},n[this.headerName]=this.clientKey,n.Accept="application/json",n["Content-Type"]="application/json",n),body:JSON.stringify(e)})];case 1:return a.sent(),[2]}})})},t.prototype.count=function(i,e){return this.disabled||!this.bucket?!1:(this.assertBucket(i),this.bucket.toggles[i][e?"yes":"no"]++,!0)},t.prototype.assertBucket=function(i){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[i]||(this.bucket.toggles[i]={yes:0,no:0})},t.prototype.startTimer=function(){var i=this;this.timer=setInterval(function(){i.sendMetrics()},this.metricsInterval)},t.prototype.bucketIsEmpty=function(i){return Object.keys(i.bucket.toggles).length===0},t.prototype.getPayload=function(){var i=G(G({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:i,appName:this.appName,instanceId:"browser"}},t}();te.default=Ue;var re={},de=g&&g.__awaiter||function(t,i,e,n){function a(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function d(h){try{s(n.next(h))}catch(m){o(m)}}function v(h){try{s(n.throw(h))}catch(m){o(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,i||[])).next())})},ve=g&&g.__generator||function(t,i){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,o;return o={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=i.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(re,"__esModule",{value:!0});var Re=function(){function t(){this.store=new Map}return t.prototype.save=function(i,e){return de(this,void 0,void 0,function(){return ve(this,function(n){return this.store.set(i,e),[2]})})},t.prototype.get=function(i){return de(this,void 0,void 0,function(){return ve(this,function(e){return[2,this.store.get(i)]})})},t}();re.default=Re;var ne={},Ce=g&&g.__awaiter||function(t,i,e,n){function a(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function d(h){try{s(n.next(h))}catch(m){o(m)}}function v(h){try{s(n.throw(h))}catch(m){o(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,i||[])).next())})},Me=g&&g.__generator||function(t,i){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,o;return o={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function d(s){return function(h){return v([s,h])}}function v(s){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,a&&(r=s[0]&2?a.return:s[0]?a.throw||((r=a.return)&&r.call(a),0):a.next)&&!(r=r.call(a,s[1])).done)return r;switch(a=0,r&&(s=[s[0]&2,r.value]),s[0]){case 0:case 1:r=s;break;case 4:return e.label++,{value:s[1],done:!1};case 5:e.label++,a=s[1],s=[0];continue;case 7:s=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!r||s[1]>r[0]&&s[1]<r[3])){e.label=s[1];break}if(s[0]===6&&e.label<r[1]){e.label=r[1],r=s;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(s);break}r[2]&&e.ops.pop(),e.trys.pop();continue}s=i.call(t,e)}catch(h){s=[6,h],a=0}finally{n=r=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}};Object.defineProperty(ne,"__esModule",{value:!0});var Ae=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(i,e){return Ce(this,void 0,void 0,function(){var n,a;return Me(this,function(r){n=JSON.stringify(e),a="".concat(this.prefix,":").concat(i);try{window.localStorage.setItem(a,n)}catch(o){console.error(o)}return[2]})})},t.prototype.get=function(i){try{var e="".concat(this.prefix,":").concat(i),n=window.localStorage.getItem(e);return n?JSON.parse(n):void 0}catch(a){console.error(a)}},t}();ne.default=Ae;var ae={},B,ke=new Uint8Array(16);function pe(){if(!B&&(B=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!B))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return B(ke)}var Pe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Y(t){return typeof t=="string"&&Pe.test(t)}for(var S=[],ie=0;ie<256;++ie)S.push((ie+256).toString(16).substr(1));function J(t){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(S[t[i+0]]+S[t[i+1]]+S[t[i+2]]+S[t[i+3]]+"-"+S[t[i+4]]+S[t[i+5]]+"-"+S[t[i+6]]+S[t[i+7]]+"-"+S[t[i+8]]+S[t[i+9]]+"-"+S[t[i+10]]+S[t[i+11]]+S[t[i+12]]+S[t[i+13]]+S[t[i+14]]+S[t[i+15]]).toLowerCase();if(!Y(e))throw TypeError("Stringified UUID is invalid");return e}var ye,oe,se=0,ue=0;function je(t,i,e){var n=i&&e||0,a=i||new Array(16);t=t||{};var r=t.node||ye,o=t.clockseq!==void 0?t.clockseq:oe;if(r==null||o==null){var d=t.random||(t.rng||pe)();r==null&&(r=ye=[d[0]|1,d[1],d[2],d[3],d[4],d[5]]),o==null&&(o=oe=(d[6]<<8|d[7])&16383)}var v=t.msecs!==void 0?t.msecs:Date.now(),s=t.nsecs!==void 0?t.nsecs:ue+1,h=v-se+(s-ue)/1e4;if(h<0&&t.clockseq===void 0&&(o=o+1&16383),(h<0||v>se)&&t.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");se=v,ue=s,oe=o,v+=122192928e5;var m=((v&268435455)*1e4+s)%4294967296;a[n++]=m>>>24&255,a[n++]=m>>>16&255,a[n++]=m>>>8&255,a[n++]=m&255;var M=v/4294967296*1e4&268435455;a[n++]=M>>>8&255,a[n++]=M&255,a[n++]=M>>>24&15|16,a[n++]=M>>>16&255,a[n++]=o>>>8|128,a[n++]=o&255;for(var A=0;A<6;++A)a[n+A]=r[A];return i||J(a)}function ge(t){if(!Y(t))throw TypeError("Invalid UUID");var i,e=new Uint8Array(16);return e[0]=(i=parseInt(t.slice(0,8),16))>>>24,e[1]=i>>>16&255,e[2]=i>>>8&255,e[3]=i&255,e[4]=(i=parseInt(t.slice(9,13),16))>>>8,e[5]=i&255,e[6]=(i=parseInt(t.slice(14,18),16))>>>8,e[7]=i&255,e[8]=(i=parseInt(t.slice(19,23),16))>>>8,e[9]=i&255,e[10]=(i=parseInt(t.slice(24,36),16))/1099511627776&255,e[11]=i/4294967296&255,e[12]=i>>>24&255,e[13]=i>>>16&255,e[14]=i>>>8&255,e[15]=i&255,e}function Ve(t){t=unescape(encodeURIComponent(t));for(var i=[],e=0;e<t.length;++e)i.push(t.charCodeAt(e));return i}var De="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Le="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function me(t,i,e){function n(a,r,o,d){if(typeof a=="string"&&(a=Ve(a)),typeof r=="string"&&(r=ge(r)),r.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var v=new Uint8Array(16+a.length);if(v.set(r),v.set(a,r.length),v=e(v),v[6]=v[6]&15|i,v[8]=v[8]&63|128,o){d=d||0;for(var s=0;s<16;++s)o[d+s]=v[s];return o}return J(v)}try{n.name=t}catch{}return n.DNS=De,n.URL=Le,n}function Ke(t){if(typeof t=="string"){var i=unescape(encodeURIComponent(t));t=new Uint8Array(i.length);for(var e=0;e<i.length;++e)t[e]=i.charCodeAt(e)}return Fe($e(qe(t),t.length*8))}function Fe(t){for(var i=[],e=t.length*32,n="0123456789abcdef",a=0;a<e;a+=8){var r=t[a>>5]>>>a%32&255,o=parseInt(n.charAt(r>>>4&15)+n.charAt(r&15),16);i.push(o)}return i}function be(t){return(t+64>>>9<<4)+14+1}function $e(t,i){t[i>>5]|=128<<i%32,t[be(i)-1]=i;for(var e=1732584193,n=-271733879,a=-1732584194,r=271733878,o=0;o<t.length;o+=16){var d=e,v=n,s=a,h=r;e=O(e,n,a,r,t[o],7,-680876936),r=O(r,e,n,a,t[o+1],12,-389564586),a=O(a,r,e,n,t[o+2],17,606105819),n=O(n,a,r,e,t[o+3],22,-1044525330),e=O(e,n,a,r,t[o+4],7,-176418897),r=O(r,e,n,a,t[o+5],12,1200080426),a=O(a,r,e,n,t[o+6],17,-1473231341),n=O(n,a,r,e,t[o+7],22,-45705983),e=O(e,n,a,r,t[o+8],7,1770035416),r=O(r,e,n,a,t[o+9],12,-1958414417),a=O(a,r,e,n,t[o+10],17,-42063),n=O(n,a,r,e,t[o+11],22,-1990404162),e=O(e,n,a,r,t[o+12],7,1804603682),r=O(r,e,n,a,t[o+13],12,-40341101),a=O(a,r,e,n,t[o+14],17,-1502002290),n=O(n,a,r,e,t[o+15],22,1236535329),e=U(e,n,a,r,t[o+1],5,-165796510),r=U(r,e,n,a,t[o+6],9,-1069501632),a=U(a,r,e,n,t[o+11],14,643717713),n=U(n,a,r,e,t[o],20,-373897302),e=U(e,n,a,r,t[o+5],5,-701558691),r=U(r,e,n,a,t[o+10],9,38016083),a=U(a,r,e,n,t[o+15],14,-660478335),n=U(n,a,r,e,t[o+4],20,-405537848),e=U(e,n,a,r,t[o+9],5,568446438),r=U(r,e,n,a,t[o+14],9,-1019803690),a=U(a,r,e,n,t[o+3],14,-187363961),n=U(n,a,r,e,t[o+8],20,1163531501),e=U(e,n,a,r,t[o+13],5,-1444681467),r=U(r,e,n,a,t[o+2],9,-51403784),a=U(a,r,e,n,t[o+7],14,1735328473),n=U(n,a,r,e,t[o+12],20,-1926607734),e=R(e,n,a,r,t[o+5],4,-378558),r=R(r,e,n,a,t[o+8],11,-2022574463),a=R(a,r,e,n,t[o+11],16,1839030562),n=R(n,a,r,e,t[o+14],23,-35309556),e=R(e,n,a,r,t[o+1],4,-1530992060),r=R(r,e,n,a,t[o+4],11,1272893353),a=R(a,r,e,n,t[o+7],16,-155497632),n=R(n,a,r,e,t[o+10],23,-1094730640),e=R(e,n,a,r,t[o+13],4,681279174),r=R(r,e,n,a,t[o],11,-358537222),a=R(a,r,e,n,t[o+3],16,-722521979),n=R(n,a,r,e,t[o+6],23,76029189),e=R(e,n,a,r,t[o+9],4,-640364487),r=R(r,e,n,a,t[o+12],11,-421815835),a=R(a,r,e,n,t[o+15],16,530742520),n=R(n,a,r,e,t[o+2],23,-995338651),e=C(e,n,a,r,t[o],6,-198630844),r=C(r,e,n,a,t[o+7],10,1126891415),a=C(a,r,e,n,t[o+14],15,-1416354905),n=C(n,a,r,e,t[o+5],21,-57434055),e=C(e,n,a,r,t[o+12],6,1700485571),r=C(r,e,n,a,t[o+3],10,-1894986606),a=C(a,r,e,n,t[o+10],15,-1051523),n=C(n,a,r,e,t[o+1],21,-2054922799),e=C(e,n,a,r,t[o+8],6,1873313359),r=C(r,e,n,a,t[o+15],10,-30611744),a=C(a,r,e,n,t[o+6],15,-1560198380),n=C(n,a,r,e,t[o+13],21,1309151649),e=C(e,n,a,r,t[o+4],6,-145523070),r=C(r,e,n,a,t[o+11],10,-1120210379),a=C(a,r,e,n,t[o+2],15,718787259),n=C(n,a,r,e,t[o+9],21,-343485551),e=L(e,d),n=L(n,v),a=L(a,s),r=L(r,h)}return[e,n,a,r]}function qe(t){if(t.length===0)return[];for(var i=t.length*8,e=new Uint32Array(be(i)),n=0;n<i;n+=8)e[n>>5]|=(t[n/8]&255)<<n%32;return e}function L(t,i){var e=(t&65535)+(i&65535),n=(t>>16)+(i>>16)+(e>>16);return n<<16|e&65535}function He(t,i){return t<<i|t>>>32-i}function Q(t,i,e,n,a,r){return L(He(L(L(i,t),L(n,r)),a),e)}function O(t,i,e,n,a,r,o){return Q(i&e|~i&n,t,i,a,r,o)}function U(t,i,e,n,a,r,o){return Q(i&n|e&~n,t,i,a,r,o)}function R(t,i,e,n,a,r,o){return Q(i^e^n,t,i,a,r,o)}function C(t,i,e,n,a,r,o){return Q(e^(i|~n),t,i,a,r,o)}var Ge=me("v3",48,Ke),Be=Ge;function Ye(t,i,e){t=t||{};var n=t.random||(t.rng||pe)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,i){e=e||0;for(var a=0;a<16;++a)i[e+a]=n[a];return i}return J(n)}function Je(t,i,e,n){switch(t){case 0:return i&e^~i&n;case 1:return i^e^n;case 2:return i&e^i&n^e&n;case 3:return i^e^n}}function fe(t,i){return t<<i|t>>>32-i}function Qe(t){var i=[1518500249,1859775393,2400959708,3395469782],e=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof t=="string"){var n=unescape(encodeURIComponent(t));t=[];for(var a=0;a<n.length;++a)t.push(n.charCodeAt(a))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var r=t.length/4+2,o=Math.ceil(r/16),d=new Array(o),v=0;v<o;++v){for(var s=new Uint32Array(16),h=0;h<16;++h)s[h]=t[v*64+h*4]<<24|t[v*64+h*4+1]<<16|t[v*64+h*4+2]<<8|t[v*64+h*4+3];d[v]=s}d[o-1][14]=(t.length-1)*8/Math.pow(2,32),d[o-1][14]=Math.floor(d[o-1][14]),d[o-1][15]=(t.length-1)*8&4294967295;for(var m=0;m<o;++m){for(var M=new Uint32Array(80),A=0;A<16;++A)M[A]=d[m][A];for(var j=16;j<80;++j)M[j]=fe(M[j-3]^M[j-8]^M[j-14]^M[j-16],1);for(var w=e[0],E=e[1],V=e[2],I=e[3],p=e[4],u=0;u<80;++u){var f=Math.floor(u/20),c=fe(w,5)+Je(f,E,V,I)+p+i[f]+M[u]>>>0;p=I,I=V,V=fe(E,30)>>>0,E=w,w=c}e[0]=e[0]+w>>>0,e[1]=e[1]+E>>>0,e[2]=e[2]+V>>>0,e[3]=e[3]+I>>>0,e[4]=e[4]+p>>>0}return[e[0]>>24&255,e[0]>>16&255,e[0]>>8&255,e[0]&255,e[1]>>24&255,e[1]>>16&255,e[1]>>8&255,e[1]&255,e[2]>>24&255,e[2]>>16&255,e[2]>>8&255,e[2]&255,e[3]>>24&255,e[3]>>16&255,e[3]>>8&255,e[3]&255,e[4]>>24&255,e[4]>>16&255,e[4]>>8&255,e[4]&255]}var Xe=me("v5",80,Qe),ze=Xe,Ze="00000000-0000-0000-0000-000000000000";function We(t){if(!Y(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}var et=Object.freeze(Object.defineProperty({__proto__:null,v1:je,v3:Be,v4:Ye,v5:ze,NIL:Ze,version:We,validate:Y,stringify:J,parse:ge},Symbol.toStringTag,{value:"Module"})),tt=Ne(et),X=g&&g.__assign||function(){return X=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++){i=arguments[e];for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a])}return t},X.apply(this,arguments)};Object.defineProperty(ae,"__esModule",{value:!0});var rt=tt,nt=function(){function t(){}return t.prototype.generateEventId=function(){return(0,rt.v4)()},t.prototype.createImpressionEvent=function(i,e,n,a,r){var o=this.createBaseEvent(i,e,n,a);return r?X(X({},o),{variant:r}):o},t.prototype.createBaseEvent=function(i,e,n,a){return{eventType:a,eventId:this.generateEventId(),context:i,enabled:e,featureName:n}},t}();ae.default=nt;var z={};Object.defineProperty(z,"__esModule",{value:!0}),z.notNullOrUndefined=void 0;var at=function(t){var i=t[1];return i!=null};z.notNullOrUndefined=at,function(t){var i=g&&g.__extends||function(){var I=function(p,u){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(f,c){f.__proto__=c}||function(f,c){for(var l in c)Object.prototype.hasOwnProperty.call(c,l)&&(f[l]=c[l])},I(p,u)};return function(p,u){if(typeof u!="function"&&u!==null)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");I(p,u);function f(){this.constructor=p}p.prototype=u===null?Object.create(u):(f.prototype=u.prototype,new f)}}(),e=g&&g.__assign||function(){return e=Object.assign||function(I){for(var p,u=1,f=arguments.length;u<f;u++){p=arguments[u];for(var c in p)Object.prototype.hasOwnProperty.call(p,c)&&(I[c]=p[c])}return I},e.apply(this,arguments)},n=g&&g.__awaiter||function(I,p,u,f){function c(l){return l instanceof u?l:new u(function(_){_(l)})}return new(u||(u=Promise))(function(l,_){function P(T){try{y(f.next(T))}catch(D){_(D)}}function k(T){try{y(f.throw(T))}catch(D){_(D)}}function y(T){T.done?l(T.value):c(T.value).then(P,k)}y((f=f.apply(I,p||[])).next())})},a=g&&g.__generator||function(I,p){var u={label:0,sent:function(){if(l[0]&1)throw l[1];return l[1]},trys:[],ops:[]},f,c,l,_;return _={next:P(0),throw:P(1),return:P(2)},typeof Symbol=="function"&&(_[Symbol.iterator]=function(){return this}),_;function P(y){return function(T){return k([y,T])}}function k(y){if(f)throw new TypeError("Generator is already executing.");for(;u;)try{if(f=1,c&&(l=y[0]&2?c.return:y[0]?c.throw||((l=c.return)&&l.call(c),0):c.next)&&!(l=l.call(c,y[1])).done)return l;switch(c=0,l&&(y=[y[0]&2,l.value]),y[0]){case 0:case 1:l=y;break;case 4:return u.label++,{value:y[1],done:!1};case 5:u.label++,c=y[1],y=[0];continue;case 7:y=u.ops.pop(),u.trys.pop();continue;default:if(l=u.trys,!(l=l.length>0&&l[l.length-1])&&(y[0]===6||y[0]===2)){u=0;continue}if(y[0]===3&&(!l||y[1]>l[0]&&y[1]<l[3])){u.label=y[1];break}if(y[0]===6&&u.label<l[1]){u.label=l[1],l=y;break}if(l&&u.label<l[2]){u.label=l[2],u.ops.push(y);break}l[2]&&u.ops.pop(),u.trys.pop();continue}y=p.call(I,u)}catch(T){y=[6,T],c=0}finally{f=l=0}if(y[0]&5)throw y[1];return{value:y[0]?y[1]:void 0,done:!0}}},r=g&&g.__spreadArray||function(I,p,u){if(u||arguments.length===2)for(var f=0,c=p.length,l;f<c;f++)(l||!(f in p))&&(l||(l=Array.prototype.slice.call(p,0,f)),l[f]=p[f]);return I.concat(l||Array.prototype.slice.call(p))};Object.defineProperty(t,"__esModule",{value:!0}),t.InMemoryStorageProvider=t.LocalStorageProvider=t.UnleashClient=t.resolveFetch=t.EVENTS=void 0;var o=W.exports,d=te,v=re;t.InMemoryStorageProvider=v.default;var s=ne;t.LocalStorageProvider=s.default;var h=ae,m=z,M=["userId","sessionId","remoteAddress"];t.EVENTS={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression"};var A={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},j={name:"disabled",enabled:!1},w="repo",E=function(){try{if("fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(I){console.error('Unleash failed to resolve "fetch"',I)}};t.resolveFetch=E;var V=function(I){i(p,I);function p(u){var f=u.storageProvider,c=u.url,l=u.clientKey,_=u.disableRefresh,P=_===void 0?!1:_,k=u.refreshInterval,y=k===void 0?30:k,T=u.metricsInterval,D=T===void 0?30:T,q=u.disableMetrics,ce=q===void 0?!1:q,H=u.appName,Ee=u.environment,lt=Ee===void 0?"default":Ee,ht=u.context,Ie=u.fetch,le=Ie===void 0?(0,t.resolveFetch)():Ie,F=u.bootstrap,_e=u.bootstrapOverride,dt=_e===void 0?!0:_e,Se=u.headerName,Te=Se===void 0?"Authorization":Se,N=I.call(this)||this;if(N.toggles=[],N.etag="",!c)throw new Error("url is required");if(!l)throw new Error("clientKey is required");if(!H)throw new Error("appName is required.");return N.eventsHandler=new h.default,N.toggles=F&&F.length>0?F:[],N.url=new URL("".concat(c)),N.clientKey=l,N.headerName=Te,N.storage=f||new s.default,N.refreshInterval=P?0:y*1e3,N.context=e({appName:H,environment:lt},ht),N.ready=new Promise(function(vt){return n(N,void 0,void 0,function(){var he;return a(this,function(Z){switch(Z.label){case 0:return Z.trys.push([0,2,,3]),[4,this.init()];case 1:return Z.sent(),[3,3];case 2:return he=Z.sent(),console.error(he),this.emit(t.EVENTS.ERROR,he),[3,3];case 3:return vt(),[2]}})})}),le||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),N.fetch=le,N.bootstrap=F&&F.length>0?F:void 0,N.bootstrapOverride=dt,N.metrics=new d.default({appName:H,metricsInterval:D,disableMetrics:ce,url:c,clientKey:l,fetch:le,headerName:Te}),N}return p.prototype.getAllToggles=function(){return r([],this.toggles,!0)},p.prototype.isEnabled=function(u){var f=this.toggles.find(function(_){return _.name===u}),c=f?f.enabled:!1;if(this.metrics.count(u,c),f!=null&&f.impressionData){var l=this.eventsHandler.createImpressionEvent(this.context,c,u,A.IS_ENABLED);this.emit(t.EVENTS.IMPRESSION,l)}return c},p.prototype.getVariant=function(u){var f=this.toggles.find(function(l){return l.name===u});if(f){if(this.metrics.count(u,!0),f.impressionData){var c=this.eventsHandler.createImpressionEvent(this.context,f.enabled,u,A.GET_VARIANT,f.variant.name);this.emit(t.EVENTS.IMPRESSION,c)}return f.variant}else return this.metrics.count(u,!1),j},p.prototype.updateContext=function(u){return n(this,void 0,void 0,function(){var f;return a(this,function(c){switch(c.label){case 0:return(u.appName||u.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),f={environment:this.context.environment,appName:this.context.appName},this.context=e(e({},f),u),this.timerRef?[4,this.fetchToggles()]:[3,2];case 1:c.sent(),c.label=2;case 2:return[2]}})})},p.prototype.getContext=function(){return e({},this.context)},p.prototype.setContextField=function(u,f){var c,l;if(M.includes(u))this.context=e(e({},this.context),(c={},c[u]=f,c));else{var _=e(e({},this.context.properties),(l={},l[u]=f,l));this.context=e(e({},this.context),{properties:_})}this.timerRef&&this.fetchToggles()},p.prototype.init=function(){return n(this,void 0,void 0,function(){var u,f;return a(this,function(c){switch(c.label){case 0:return[4,this.resolveSessionId()];case 1:return u=c.sent(),this.context=e({sessionId:u},this.context),f=this,[4,this.storage.get(w)];case 2:return f.toggles=c.sent()||[],this.bootstrap&&(this.bootstrapOverride||this.toggles.length===0)?[4,this.storage.save(w,this.bootstrap)]:[3,4];case 3:c.sent(),this.toggles=this.bootstrap,this.emit(t.EVENTS.READY),c.label=4;case 4:return this.emit(t.EVENTS.INIT),[2]}})})},p.prototype.start=function(){return n(this,void 0,void 0,function(){var u,f=this;return a(this,function(c){switch(c.label){case 0:return 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 c.sent(),this.metrics.start(),u=this.refreshInterval,[4,this.fetchToggles()];case 2:return c.sent(),this.bootstrap||this.emit(t.EVENTS.READY),u>0&&(this.timerRef=setInterval(function(){return f.fetchToggles()},u)),[2]}})})},p.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},p.prototype.resolveSessionId=function(){return n(this,void 0,void 0,function(){var u;return a(this,function(f){switch(f.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return u=f.sent(),u?[3,4]:(u=Math.floor(Math.random()*1e9),[4,this.storage.save("sessionId",u)]);case 3:f.sent(),f.label=4;case 4:return[2,u]}})})},p.prototype.storeToggles=function(u){return n(this,void 0,void 0,function(){return a(this,function(f){switch(f.label){case 0:return this.toggles=u,this.emit(t.EVENTS.UPDATE),[4,this.storage.save(w,u)];case 1:return f.sent(),[2]}})})},p.prototype.fetchToggles=function(){return n(this,void 0,void 0,function(){var u,f,c,l,_,P;return a(this,function(k){switch(k.label){case 0:if(!this.fetch)return[3,7];k.label=1;case 1:return k.trys.push([1,6,,7]),u=this.context,f=new URL(this.url.toString()),Object.entries(u).filter(m.notNullOrUndefined).forEach(function(y){var T=y[0],D=y[1];T==="properties"&&D?Object.entries(D).filter(m.notNullOrUndefined).forEach(function(q){var ce=q[0],H=q[1];return f.searchParams.append("properties[".concat(ce,"]"),H)}):f.searchParams.append(T,D)}),[4,this.fetch(f.toString(),{cache:"no-cache",headers:(P={},P[this.headerName]=this.clientKey,P.Accept="application/json",P["Content-Type"]="application/json",P["If-None-Match"]=this.etag,P)})];case 2:return c=k.sent(),c.ok&&c.status!==304?(this.etag=c.headers.get("ETag")||"",[4,c.json()]):[3,5];case 3:return l=k.sent(),[4,this.storeToggles(l.toggles)];case 4:k.sent(),k.label=5;case 5:return[3,7];case 6:return _=k.sent(),console.error("Unleash: unable to fetch feature toggles",_),this.emit(t.EVENTS.ERROR,_),[3,7];case 7:return[2]}})})},p}(o.TinyEmitter);t.UnleashClient=V}($);const K=Symbol("Context state identifier"),it=Symbol("Context update identifier"),we=b.defineComponent({props:{config:null,unleashClient:null,startClient:{type:Boolean}},setup(t){var A,j;const{config:i,unleashClient:e,startClient:n=!0}=t,a=b.ref(e),r=b.ref(!1),o=b.ref(null);!i&&!e&&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.`),!a.value&&i&&(a.value=new $.UnleashClient(i)),(A=a.value)==null||A.on("ready",()=>{r.value=!0}),(j=a.value)==null||j.on("error",w=>{o.value=w}),b.onMounted(()=>{var E;(n||!e)&&((E=a.value)==null||E.start())});const d=async w=>{var E;await((E=a.value)==null?void 0:E.updateContext(w))},v=w=>{var E;return(E=a.value)==null?void 0:E.isEnabled(w)},s=w=>{var E;return(E=a.value)==null?void 0:E.getVariant(w)},h=(w,...E)=>{var V;return(V=a.value)==null?void 0:V.on(w,...E)},m=b.reactive({on:h,updateContext:d,isEnabled:v,getVariant:s,client:a,flagsReady:r,flagsError:o});b.provide(K,b.toRefs(m));const M=(w,E)=>{m[w]=E};return b.provide(it,M),(w,E)=>b.renderSlot(w.$slots,"default")}}),ot=t=>{const{isEnabled:i,client:e}=b.inject(K)||{},n=b.ref(!!i.value(t));function a(){const o=i.value(t);o!==n.value&&(n.value=!!o)}function r(){n.value=i.value(t)}return e.value.on("ready",r),e.value.on("update",a),b.onUnmounted(()=>{e.value.off("ready",r),e.value.off("update",a)}),n},st=()=>{const{flagsReady:t,flagsError:i}=b.inject(K)||{};return{flagsReady:t,flagsError:i}},ut=t=>{const{getVariant:i,client:e}=b.inject(K)||{},n=b.ref(i.value(t));function a(){const o=i.value(t);(o.name!==n.value.name||o.enabled!==n.value.enabled)&&(n.value=o)}function r(){n.value=i.value(t)}return e.value.on("ready",r),e.value.on("update",a),b.onUnmounted(()=>{e.value.off("ready",r),e.value.off("update",a)}),n||{}},ft=()=>{const{updateContext:t}=b.inject(K)||{};return t.value},ct=()=>{const{client:t}=b.inject(K)||{};return t.value};x.FlagProvider=we,x.InMemoryStorageProvider=$.InMemoryStorageProvider,x.LocalStorageProvider=$.LocalStorageProvider,x.UnleashClient=$.UnleashClient,x.default=we,x.useFlag=ot,x.useFlagsStatus=st,x.useUnleashClient=ct,x.useUnleashContext=ft,x.useVariant=ut,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|