@unleash/proxy-client-vue 0.0.7 → 0.1.0
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 +18 -20
- package/dist/index.es.js +429 -1439
- package/dist/index.umd.js +2 -2
- package/dist/useVariant.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(_,b){typeof exports=="object"&&typeof module!="undefined"?b(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],b):(_=typeof globalThis!="undefined"?globalThis:_||self,b(_["proxy-client-vue"]={},_.Vue))})(this,function(_,b){"use strict";var g=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function xe(t){if(t.__esModule)return t;var o=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach(function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(o,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}),o}var F={},z={exports:{}};function Z(){}Z.prototype={on:function(t,o,e){var n=this.e||(this.e={});return(n[t]||(n[t]=[])).push({fn:o,ctx:e}),this},once:function(t,o,e){var n=this;function a(){n.off(t,a),o.apply(e,arguments)}return a._=o,this.on(t,a,e)},emit:function(t){var o=[].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,o);return this},off:function(t,o){var e=this.e||(this.e={}),n=e[t],a=[];if(n&&o)for(var r=0,i=n.length;r<i;r++)n[r].fn!==o&&n[r].fn._!==o&&a.push(n[r]);return a.length?e[t]=a:delete e[t],this}},z.exports=Z,z.exports.TinyEmitter=Z;var W={},$=g&&g.__assign||function(){return $=Object.assign||function(t){for(var o,e=1,n=arguments.length;e<n;e++){o=arguments[e];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(t[a]=o[a])}return t},$.apply(this,arguments)},Re=g&&g.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function d(h){try{s(n.next(h))}catch(m){i(m)}}function v(h){try{s(n.throw(h))}catch(m){i(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,o||[])).next())})},Me=g&&g.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;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=o.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(W,"__esModule",{value:!0});var Ae=function(){function t(o){var e=o.onError,n=o.appName,a=o.metricsInterval,r=o.disableMetrics,i=r===void 0?!1:r,d=o.url,v=o.clientKey,s=o.fetch,h=o.headerName;this.onError=e,this.disabled=i,this.metricsInterval=a*1e3,this.appName=n,this.url=d instanceof URL?d:new URL(d),this.clientKey=v,this.bucket=this.createEmptyBucket(),this.fetch=s,this.headerName=h}return t.prototype.start=function(){var o=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){o.startTimer(),o.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 Re(this,void 0,void 0,function(){var o,e,n,a;return Me(this,function(r){switch(r.label){case 0:if(o="".concat(this.url,"/client/metrics"),e=this.getPayload(),this.bucketIsEmpty(e))return[2];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.fetch(o,{cache:"no-cache",method:"POST",headers:(a={},a[this.headerName]=this.clientKey,a.Accept="application/json",a["Content-Type"]="application/json",a),body:JSON.stringify(e)})];case 2:return r.sent(),[3,4];case 3:return n=r.sent(),console.error("Unleash: unable to send feature metrics",n),this.onError(n),[3,4];case 4:return[2]}})})},t.prototype.count=function(o,e){return this.disabled||!this.bucket?!1:(this.assertBucket(o),this.bucket.toggles[o][e?"yes":"no"]++,!0)},t.prototype.assertBucket=function(o){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[o]||(this.bucket.toggles[o]={yes:0,no:0})},t.prototype.startTimer=function(){var o=this;this.timer=setInterval(function(){o.sendMetrics()},this.metricsInterval)},t.prototype.bucketIsEmpty=function(o){return Object.keys(o.bucket.toggles).length===0},t.prototype.getPayload=function(){var o=$($({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:o,appName:this.appName,instanceId:"browser"}},t}();W.default=Ae;var ee={},he=g&&g.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function d(h){try{s(n.next(h))}catch(m){i(m)}}function v(h){try{s(n.throw(h))}catch(m){i(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,o||[])).next())})},de=g&&g.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;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=o.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(ee,"__esModule",{value:!0});var ke=function(){function t(){this.store=new Map}return t.prototype.save=function(o,e){return he(this,void 0,void 0,function(){return de(this,function(n){return this.store.set(o,e),[2]})})},t.prototype.get=function(o){return he(this,void 0,void 0,function(){return de(this,function(e){return[2,this.store.get(o)]})})},t}();ee.default=ke;var te={},Ce=g&&g.__awaiter||function(t,o,e,n){function a(r){return r instanceof e?r:new e(function(i){i(r)})}return new(e||(e=Promise))(function(r,i){function d(h){try{s(n.next(h))}catch(m){i(m)}}function v(h){try{s(n.throw(h))}catch(m){i(m)}}function s(h){h.done?r(h.value):a(h.value).then(d,v)}s((n=n.apply(t,o||[])).next())})},Pe=g&&g.__generator||function(t,o){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,a,r,i;return i={next:d(0),throw:d(1),return:d(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;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=o.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 je=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(o,e){return Ce(this,void 0,void 0,function(){var n,a;return Pe(this,function(r){n=JSON.stringify(e),a="".concat(this.prefix,":").concat(o);try{window.localStorage.setItem(a,n)}catch(i){console.error(i)}return[2]})})},t.prototype.get=function(o){try{var e="".concat(this.prefix,":").concat(o),n=window.localStorage.getItem(e);return n?JSON.parse(n):void 0}catch(a){console.error(a)}},t}();te.default=je;var re={},q,De=new Uint8Array(16);function ve(){if(!q&&(q=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!q))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return q(De)}var Le=/^(?:[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 G(t){return typeof t=="string"&&Le.test(t)}for(var O=[],ne=0;ne<256;++ne)O.push((ne+256).toString(16).substr(1));function B(t){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,e=(O[t[o+0]]+O[t[o+1]]+O[t[o+2]]+O[t[o+3]]+"-"+O[t[o+4]]+O[t[o+5]]+"-"+O[t[o+6]]+O[t[o+7]]+"-"+O[t[o+8]]+O[t[o+9]]+"-"+O[t[o+10]]+O[t[o+11]]+O[t[o+12]]+O[t[o+13]]+O[t[o+14]]+O[t[o+15]]).toLowerCase();if(!G(e))throw TypeError("Stringified UUID is invalid");return e}var ye,ae,oe=0,ie=0;function Ve(t,o,e){var n=o&&e||0,a=o||new Array(16);t=t||{};var r=t.node||ye,i=t.clockseq!==void 0?t.clockseq:ae;if(r==null||i==null){var d=t.random||(t.rng||ve)();r==null&&(r=ye=[d[0]|1,d[1],d[2],d[3],d[4],d[5]]),i==null&&(i=ae=(d[6]<<8|d[7])&16383)}var v=t.msecs!==void 0?t.msecs:Date.now(),s=t.nsecs!==void 0?t.nsecs:ie+1,h=v-oe+(s-ie)/1e4;if(h<0&&t.clockseq===void 0&&(i=i+1&16383),(h<0||v>oe)&&t.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");oe=v,ie=s,ae=i,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 A=v/4294967296*1e4&268435455;a[n++]=A>>>8&255,a[n++]=A&255,a[n++]=A>>>24&15|16,a[n++]=A>>>16&255,a[n++]=i>>>8|128,a[n++]=i&255;for(var C=0;C<6;++C)a[n+C]=r[C];return o||B(a)}function pe(t){if(!G(t))throw TypeError("Invalid UUID");var o,e=new Uint8Array(16);return e[0]=(o=parseInt(t.slice(0,8),16))>>>24,e[1]=o>>>16&255,e[2]=o>>>8&255,e[3]=o&255,e[4]=(o=parseInt(t.slice(9,13),16))>>>8,e[5]=o&255,e[6]=(o=parseInt(t.slice(14,18),16))>>>8,e[7]=o&255,e[8]=(o=parseInt(t.slice(19,23),16))>>>8,e[9]=o&255,e[10]=(o=parseInt(t.slice(24,36),16))/1099511627776&255,e[11]=o/4294967296&255,e[12]=o>>>24&255,e[13]=o>>>16&255,e[14]=o>>>8&255,e[15]=o&255,e}function Ke(t){t=unescape(encodeURIComponent(t));for(var o=[],e=0;e<t.length;++e)o.push(t.charCodeAt(e));return o}var He="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Fe="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function ge(t,o,e){function n(a,r,i,d){if(typeof a=="string"&&(a=Ke(a)),typeof r=="string"&&(r=pe(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|o,v[8]=v[8]&63|128,i){d=d||0;for(var s=0;s<16;++s)i[d+s]=v[s];return i}return B(v)}try{n.name=t}catch{}return n.DNS=He,n.URL=Fe,n}function $e(t){if(typeof t=="string"){var o=unescape(encodeURIComponent(t));t=new Uint8Array(o.length);for(var e=0;e<o.length;++e)t[e]=o.charCodeAt(e)}return qe(Ge(Be(t),t.length*8))}function qe(t){for(var o=[],e=t.length*32,n="0123456789abcdef",a=0;a<e;a+=8){var r=t[a>>5]>>>a%32&255,i=parseInt(n.charAt(r>>>4&15)+n.charAt(r&15),16);o.push(i)}return o}function me(t){return(t+64>>>9<<4)+14+1}function Ge(t,o){t[o>>5]|=128<<o%32,t[me(o)-1]=o;for(var e=1732584193,n=-271733879,a=-1732584194,r=271733878,i=0;i<t.length;i+=16){var d=e,v=n,s=a,h=r;e=U(e,n,a,r,t[i],7,-680876936),r=U(r,e,n,a,t[i+1],12,-389564586),a=U(a,r,e,n,t[i+2],17,606105819),n=U(n,a,r,e,t[i+3],22,-1044525330),e=U(e,n,a,r,t[i+4],7,-176418897),r=U(r,e,n,a,t[i+5],12,1200080426),a=U(a,r,e,n,t[i+6],17,-1473231341),n=U(n,a,r,e,t[i+7],22,-45705983),e=U(e,n,a,r,t[i+8],7,1770035416),r=U(r,e,n,a,t[i+9],12,-1958414417),a=U(a,r,e,n,t[i+10],17,-42063),n=U(n,a,r,e,t[i+11],22,-1990404162),e=U(e,n,a,r,t[i+12],7,1804603682),r=U(r,e,n,a,t[i+13],12,-40341101),a=U(a,r,e,n,t[i+14],17,-1502002290),n=U(n,a,r,e,t[i+15],22,1236535329),e=x(e,n,a,r,t[i+1],5,-165796510),r=x(r,e,n,a,t[i+6],9,-1069501632),a=x(a,r,e,n,t[i+11],14,643717713),n=x(n,a,r,e,t[i],20,-373897302),e=x(e,n,a,r,t[i+5],5,-701558691),r=x(r,e,n,a,t[i+10],9,38016083),a=x(a,r,e,n,t[i+15],14,-660478335),n=x(n,a,r,e,t[i+4],20,-405537848),e=x(e,n,a,r,t[i+9],5,568446438),r=x(r,e,n,a,t[i+14],9,-1019803690),a=x(a,r,e,n,t[i+3],14,-187363961),n=x(n,a,r,e,t[i+8],20,1163531501),e=x(e,n,a,r,t[i+13],5,-1444681467),r=x(r,e,n,a,t[i+2],9,-51403784),a=x(a,r,e,n,t[i+7],14,1735328473),n=x(n,a,r,e,t[i+12],20,-1926607734),e=R(e,n,a,r,t[i+5],4,-378558),r=R(r,e,n,a,t[i+8],11,-2022574463),a=R(a,r,e,n,t[i+11],16,1839030562),n=R(n,a,r,e,t[i+14],23,-35309556),e=R(e,n,a,r,t[i+1],4,-1530992060),r=R(r,e,n,a,t[i+4],11,1272893353),a=R(a,r,e,n,t[i+7],16,-155497632),n=R(n,a,r,e,t[i+10],23,-1094730640),e=R(e,n,a,r,t[i+13],4,681279174),r=R(r,e,n,a,t[i],11,-358537222),a=R(a,r,e,n,t[i+3],16,-722521979),n=R(n,a,r,e,t[i+6],23,76029189),e=R(e,n,a,r,t[i+9],4,-640364487),r=R(r,e,n,a,t[i+12],11,-421815835),a=R(a,r,e,n,t[i+15],16,530742520),n=R(n,a,r,e,t[i+2],23,-995338651),e=M(e,n,a,r,t[i],6,-198630844),r=M(r,e,n,a,t[i+7],10,1126891415),a=M(a,r,e,n,t[i+14],15,-1416354905),n=M(n,a,r,e,t[i+5],21,-57434055),e=M(e,n,a,r,t[i+12],6,1700485571),r=M(r,e,n,a,t[i+3],10,-1894986606),a=M(a,r,e,n,t[i+10],15,-1051523),n=M(n,a,r,e,t[i+1],21,-2054922799),e=M(e,n,a,r,t[i+8],6,1873313359),r=M(r,e,n,a,t[i+15],10,-30611744),a=M(a,r,e,n,t[i+6],15,-1560198380),n=M(n,a,r,e,t[i+13],21,1309151649),e=M(e,n,a,r,t[i+4],6,-145523070),r=M(r,e,n,a,t[i+11],10,-1120210379),a=M(a,r,e,n,t[i+2],15,718787259),n=M(n,a,r,e,t[i+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 Be(t){if(t.length===0)return[];for(var o=t.length*8,e=new Uint32Array(me(o)),n=0;n<o;n+=8)e[n>>5]|=(t[n/8]&255)<<n%32;return e}function L(t,o){var e=(t&65535)+(o&65535),n=(t>>16)+(o>>16)+(e>>16);return n<<16|e&65535}function Ye(t,o){return t<<o|t>>>32-o}function Y(t,o,e,n,a,r){return L(Ye(L(L(o,t),L(n,r)),a),e)}function U(t,o,e,n,a,r,i){return Y(o&e|~o&n,t,o,a,r,i)}function x(t,o,e,n,a,r,i){return Y(o&n|e&~n,t,o,a,r,i)}function R(t,o,e,n,a,r,i){return Y(o^e^n,t,o,a,r,i)}function M(t,o,e,n,a,r,i){return Y(e^(o|~n),t,o,a,r,i)}var Je=ge("v3",48,$e),Qe=Je;function Xe(t,o,e){t=t||{};var n=t.random||(t.rng||ve)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,o){e=e||0;for(var a=0;a<16;++a)o[e+a]=n[a];return o}return B(n)}function ze(t,o,e,n){switch(t){case 0:return o&e^~o&n;case 1:return o^e^n;case 2:return o&e^o&n^e&n;case 3:return o^e^n}}function se(t,o){return t<<o|t>>>32-o}function Ze(t){var o=[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,i=Math.ceil(r/16),d=new Array(i),v=0;v<i;++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[i-1][14]=(t.length-1)*8/Math.pow(2,32),d[i-1][14]=Math.floor(d[i-1][14]),d[i-1][15]=(t.length-1)*8&4294967295;for(var m=0;m<i;++m){for(var A=new Uint32Array(80),C=0;C<16;++C)A[C]=d[m][C];for(var P=16;P<80;++P)A[P]=se(A[P-3]^A[P-8]^A[P-14]^A[P-16],1);for(var w=e[0],T=e[1],j=e[2],I=e[3],y=e[4],u=0;u<80;++u){var f=Math.floor(u/20),c=se(w,5)+ze(f,T,j,I)+y+o[f]+A[u]>>>0;y=I,I=j,j=se(T,30)>>>0,T=w,w=c}e[0]=e[0]+w>>>0,e[1]=e[1]+T>>>0,e[2]=e[2]+j>>>0,e[3]=e[3]+I>>>0,e[4]=e[4]+y>>>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 We=ge("v5",80,Ze),et=We,tt="00000000-0000-0000-0000-000000000000";function rt(t){if(!G(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}var nt=Object.freeze(Object.defineProperty({__proto__:null,v1:Ve,v3:Qe,v4:Xe,v5:et,NIL:tt,version:rt,validate:G,stringify:B,parse:pe},Symbol.toStringTag,{value:"Module"})),at=xe(nt),J=g&&g.__assign||function(){return J=Object.assign||function(t){for(var o,e=1,n=arguments.length;e<n;e++){o=arguments[e];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(t[a]=o[a])}return t},J.apply(this,arguments)};Object.defineProperty(re,"__esModule",{value:!0});var ot=at,it=function(){function t(){}return t.prototype.generateEventId=function(){return(0,ot.v4)()},t.prototype.createImpressionEvent=function(o,e,n,a,r){var i=this.createBaseEvent(o,e,n,a);return r?J(J({},i),{variant:r}):i},t.prototype.createBaseEvent=function(o,e,n,a){return{eventType:a,eventId:this.generateEventId(),context:o,enabled:e,featureName:n}},t}();re.default=it;var Q={};Object.defineProperty(Q,"__esModule",{value:!0}),Q.notNullOrUndefined=void 0;var st=function(t){var o=t[1];return o!=null};Q.notNullOrUndefined=st,function(t){var o=g&&g.__extends||function(){var I=function(y,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(y,u)};return function(y,u){if(typeof u!="function"&&u!==null)throw new TypeError("Class extends value "+String(u)+" is not a constructor or null");I(y,u);function f(){this.constructor=y}y.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 y,u=1,f=arguments.length;u<f;u++){y=arguments[u];for(var c in y)Object.prototype.hasOwnProperty.call(y,c)&&(I[c]=y[c])}return I},e.apply(this,arguments)},n=g&&g.__awaiter||function(I,y,u,f){function c(l){return l instanceof u?l:new u(function(S){S(l)})}return new(u||(u=Promise))(function(l,S){function k(N){try{p(f.next(N))}catch(K){S(K)}}function D(N){try{p(f.throw(N))}catch(K){S(K)}}function p(N){N.done?l(N.value):c(N.value).then(k,D)}p((f=f.apply(I,y||[])).next())})},a=g&&g.__generator||function(I,y){var u={label:0,sent:function(){if(l[0]&1)throw l[1];return l[1]},trys:[],ops:[]},f,c,l,S;return S={next:k(0),throw:k(1),return:k(2)},typeof Symbol=="function"&&(S[Symbol.iterator]=function(){return this}),S;function k(p){return function(N){return D([p,N])}}function D(p){if(f)throw new TypeError("Generator is already executing.");for(;u;)try{if(f=1,c&&(l=p[0]&2?c.return:p[0]?c.throw||((l=c.return)&&l.call(c),0):c.next)&&!(l=l.call(c,p[1])).done)return l;switch(c=0,l&&(p=[p[0]&2,l.value]),p[0]){case 0:case 1:l=p;break;case 4:return u.label++,{value:p[1],done:!1};case 5:u.label++,c=p[1],p=[0];continue;case 7:p=u.ops.pop(),u.trys.pop();continue;default:if(l=u.trys,!(l=l.length>0&&l[l.length-1])&&(p[0]===6||p[0]===2)){u=0;continue}if(p[0]===3&&(!l||p[1]>l[0]&&p[1]<l[3])){u.label=p[1];break}if(p[0]===6&&u.label<l[1]){u.label=l[1],l=p;break}if(l&&u.label<l[2]){u.label=l[2],u.ops.push(p);break}l[2]&&u.ops.pop(),u.trys.pop();continue}p=y.call(I,u)}catch(N){p=[6,N],c=0}finally{f=l=0}if(p[0]&5)throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}},r=g&&g.__spreadArray||function(I,y,u){if(u||arguments.length===2)for(var f=0,c=y.length,l;f<c;f++)(l||!(f in y))&&(l||(l=Array.prototype.slice.call(y,0,f)),l[f]=y[f]);return I.concat(l||Array.prototype.slice.call(y))};Object.defineProperty(t,"__esModule",{value:!0}),t.InMemoryStorageProvider=t.LocalStorageProvider=t.UnleashClient=t.resolveFetch=t.EVENTS=void 0;var i=z.exports,d=W,v=ee;t.InMemoryStorageProvider=v.default;var s=te;t.LocalStorageProvider=s.default;var h=re,m=Q,A=["userId","sessionId","remoteAddress"];t.EVENTS={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression"};var C={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},P={name:"disabled",enabled:!1},w="repo",T=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=T;var j=function(I){o(y,I);function y(u){var f=u.storageProvider,c=u.url,l=u.clientKey,S=u.disableRefresh,k=S===void 0?!1:S,D=u.refreshInterval,p=D===void 0?30:D,N=u.metricsInterval,K=N===void 0?30:N,X=u.disableMetrics,fe=X===void 0?!1:X,ce=u.appName,Ee=u.environment,vt=Ee===void 0?"default":Ee,yt=u.context,Ie=u.fetch,le=Ie===void 0?(0,t.resolveFetch)():Ie,H=u.bootstrap,Se=u.bootstrapOverride,pt=Se===void 0?!0:Se,_e=u.headerName,Te=_e===void 0?"Authorization":_e,Ne=u.customHeaders,gt=Ne===void 0?{}:Ne,E=I.call(this)||this;if(E.toggles=[],E.etag="",E.readyEventEmitted=!1,!c)throw new Error("url is required");if(!l)throw new Error("clientKey is required");if(!ce)throw new Error("appName is required.");return E.eventsHandler=new h.default,E.toggles=H&&H.length>0?H:[],E.url=c instanceof URL?c:new URL(c),E.clientKey=l,E.headerName=Te,E.customHeaders=gt,E.storage=f||new s.default,E.refreshInterval=k?0:p*1e3,E.context=e({appName:ce,environment:vt},yt),E.ready=new Promise(function(Oe){E.init().then(Oe).catch(function(Ue){console.error(Ue),E.emit(t.EVENTS.ERROR,Ue),Oe()})}),le||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),E.fetch=le,E.bootstrap=H&&H.length>0?H:void 0,E.bootstrapOverride=pt,E.metrics=new d.default({onError:E.emit.bind(E,t.EVENTS.ERROR),appName:ce,metricsInterval:K,disableMetrics:fe,url:E.url,clientKey:l,fetch:le,headerName:Te}),E}return y.prototype.getAllToggles=function(){return r([],this.toggles,!0)},y.prototype.isEnabled=function(u){var f=this.toggles.find(function(S){return S.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,C.IS_ENABLED);this.emit(t.EVENTS.IMPRESSION,l)}return c},y.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,C.GET_VARIANT,f.variant.name);this.emit(t.EVENTS.IMPRESSION,c)}return f.variant}else return this.metrics.count(u,!1),P},y.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]}})})},y.prototype.getContext=function(){return e({},this.context)},y.prototype.setContextField=function(u,f){var c,l;if(A.includes(u))this.context=e(e({},this.context),(c={},c[u]=f,c));else{var S=e(e({},this.context.properties),(l={},l[u]=f,l));this.context=e(e({},this.context),{properties:S})}this.timerRef&&this.fetchToggles()},y.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]}})})},y.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(),u>0&&(this.timerRef=setInterval(function(){return f.fetchToggles()},u)),[2]}})})},y.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},y.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]}})})},y.prototype.getHeaders=function(){var u,f=(u={},u[this.headerName]=this.clientKey,u.Accept="application/json",u["Content-Type"]="application/json",u["If-None-Match"]=this.etag,u);return Object.entries(this.customHeaders).filter(m.notNullOrUndefined).forEach(function(c){var l=c[0],S=c[1];return f[l]=S}),f},y.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]}})})},y.prototype.fetchToggles=function(){return n(this,void 0,void 0,function(){var u,f,c,l,S;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(D){var p=D[0],N=D[1];p==="properties"&&N?Object.entries(N).filter(m.notNullOrUndefined).forEach(function(K){var X=K[0],fe=K[1];return f.searchParams.append("properties[".concat(X,"]"),fe)}):f.searchParams.append(p,N)}),[4,this.fetch(f.toString(),{cache:"no-cache",headers:this.getHeaders()})];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(),!this.bootstrap&&!this.readyEventEmitted&&(this.emit(t.EVENTS.READY),this.readyEventEmitted=!0),k.label=5;case 5:return[3,7];case 6:return S=k.sent(),console.error("Unleash: unable to fetch feature toggles",S),this.emit(t.EVENTS.ERROR,S),[3,7];case 7:return[2]}})})},y}(i.TinyEmitter);t.UnleashClient=j}(F);const V=Symbol("Context state identifier"),ue=Symbol("Context update identifier");function be({config:t,unleashClient:o,startClient:e=!0}){var C,P;const n=b.ref(o),a=b.ref(!1),r=b.ref(null);!t&&!o&&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.`),!n.value&&
|
|
1
|
+
(function(d,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],h):(d=typeof globalThis!="undefined"?globalThis:d||self,h(d["proxy-client-vue"]={},d.Vue))})(this,function(d,h){"use strict";var P=function(o,r){return P=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])},P(o,r)},v=function(){return v=Object.assign||function(o){for(var r,t=1,n=arguments.length;t<n;t++)for(var e in r=arguments[t])Object.prototype.hasOwnProperty.call(r,e)&&(o[e]=r[e]);return o},v.apply(this,arguments)};function I(o,r,t,n){return new(t||(t=Promise))(function(e,s){function i(l){try{f(n.next(l))}catch(a){s(a)}}function c(l){try{f(n.throw(l))}catch(a){s(a)}}function f(l){var a;l.done?e(l.value):(a=l.value,a instanceof t?a:new t(function(b){b(a)})).then(i,c)}f((n=n.apply(o,r||[])).next())})}function S(o,r){var t,n,e,s,i={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function c(f){return function(l){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(t=1,n&&(e=2&a[0]?n.return:a[0]?n.throw||((e=n.return)&&e.call(n),0):n.next)&&!(e=e.call(n,a[1])).done)return e;switch(n=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,n=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(e=i.trys,!((e=e.length>0&&e[e.length-1])||a[0]!==6&&a[0]!==2)){i=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]<e[3])){i.label=a[1];break}if(a[0]===6&&i.label<e[1]){i.label=e[1],e=a;break}if(e&&i.label<e[2]){i.label=e[2],i.ops.push(a);break}e[2]&&i.ops.pop(),i.trys.pop();continue}a=r.call(o,i)}catch(b){a=[6,b],n=0}finally{t=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([f,l])}}}typeof SuppressedError=="function"&&SuppressedError;var _={exports:{}};function D(){}D.prototype={on:function(o,r,t){var n=this.e||(this.e={});return(n[o]||(n[o]=[])).push({fn:r,ctx:t}),this},once:function(o,r,t){var n=this;function e(){n.off(o,e),r.apply(t,arguments)}return e._=r,this.on(o,e,t)},emit:function(o){for(var r=[].slice.call(arguments,1),t=((this.e||(this.e={}))[o]||[]).slice(),n=0,e=t.length;n<e;n++)t[n].fn.apply(t[n].ctx,r);return this},off:function(o,r){var t=this.e||(this.e={}),n=t[o],e=[];if(n&&r)for(var s=0,i=n.length;s<i;s++)n[s].fn!==r&&n[s].fn._!==r&&e.push(n[s]);return e.length?t[o]=e:delete t[o],this}},_.exports=D;var Z=_.exports.TinyEmitter=D,O=function(o){var r=o[1];return r!=null},V=function(){},tt=function(){function o(r){var t=r.onError,n=r.onSent,e=r.appName,s=r.metricsInterval,i=r.disableMetrics,c=i!==void 0&&i,f=r.url,l=r.clientKey,a=r.fetch,b=r.headerName,E=r.customHeaders,x=E===void 0?{}:E;this.onError=t,this.onSent=n||V,this.disabled=c,this.metricsInterval=1e3*s,this.appName=e,this.url=f instanceof URL?f:new URL(f),this.clientKey=l,this.bucket=this.createEmptyBucket(),this.fetch=a,this.headerName=b,this.customHeaders=x}return o.prototype.start=function(){var r=this;if(this.disabled)return!1;typeof this.metricsInterval=="number"&&this.metricsInterval>0&&setTimeout(function(){r.startTimer(),r.sendMetrics()},2e3)},o.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},o.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},o.prototype.getHeaders=function(){var r,t=((r={})[this.headerName]=this.clientKey,r.Accept="application/json",r["Content-Type"]="application/json",r);return Object.entries(this.customHeaders).filter(O).forEach(function(n){var e=n[0],s=n[1];return t[e]=s}),t},o.prototype.sendMetrics=function(){return I(this,void 0,void 0,function(){var r,t,n;return S(this,function(e){switch(e.label){case 0:if(r="".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(r,{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 n=e.sent(),console.error("Unleash: unable to send feature metrics",n),this.onError(n),[3,4];case 4:return[2]}})})},o.prototype.count=function(r,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(r),this.bucket.toggles[r][t?"yes":"no"]++,!0)},o.prototype.countVariant=function(r,t){return!(this.disabled||!this.bucket)&&(this.assertBucket(r),this.bucket.toggles[r].variants[t]?this.bucket.toggles[r].variants[t]+=1:this.bucket.toggles[r].variants[t]=1,!0)},o.prototype.assertBucket=function(r){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[r]||(this.bucket.toggles[r]={yes:0,no:0,variants:{}})},o.prototype.startTimer=function(){var r=this;this.timer=setInterval(function(){r.sendMetrics()},this.metricsInterval)},o.prototype.bucketIsEmpty=function(r){return Object.keys(r.bucket.toggles).length===0},o.prototype.getPayload=function(){var r=v(v({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:r,appName:this.appName,instanceId:"browser"}},o}(),M=function(){function o(){this.store=new Map}return o.prototype.save=function(r,t){return I(this,void 0,void 0,function(){return S(this,function(n){return this.store.set(r,t),[2]})})},o.prototype.get=function(r){return I(this,void 0,void 0,function(){return S(this,function(t){return[2,this.store.get(r)]})})},o}(),H=function(){function o(){this.prefix="unleash:repository"}return o.prototype.save=function(r,t){return I(this,void 0,void 0,function(){var n,e;return S(this,function(s){n=JSON.stringify(t),e="".concat(this.prefix,":").concat(r);try{window.localStorage.setItem(e,n)}catch(i){console.error(i)}return[2]})})},o.prototype.get=function(r){try{var t="".concat(this.prefix,":").concat(r),n=window.localStorage.getItem(t);return n?JSON.parse(n):void 0}catch(e){console.error(e)}},o}();let N;const et=new Uint8Array(16);function nt(){if(!N&&(N=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!N))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return N(et)}const y=[];for(let o=0;o<256;++o)y.push((o+256).toString(16).slice(1));var B={randomUUID:typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function rt(o,r,t){if(B.randomUUID&&!r&&!o)return B.randomUUID();const n=(o=o||{}).random||(o.rng||nt)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,r){t=t||0;for(let e=0;e<16;++e)r[t+e]=n[e];return r}return function(e,s=0){return y[e[s+0]]+y[e[s+1]]+y[e[s+2]]+y[e[s+3]]+"-"+y[e[s+4]]+y[e[s+5]]+"-"+y[e[s+6]]+y[e[s+7]]+"-"+y[e[s+8]]+y[e[s+9]]+"-"+y[e[s+10]]+y[e[s+11]]+y[e[s+12]]+y[e[s+13]]+y[e[s+14]]+y[e[s+15]]}(n)}var ot=function(){function o(){}return o.prototype.generateEventId=function(){return rt()},o.prototype.createImpressionEvent=function(r,t,n,e,s,i){var c=this.createBaseEvent(r,t,n,e,s);return i?v(v({},c),{variant:i}):c},o.prototype.createBaseEvent=function(r,t,n,e,s){return{eventType:e,eventId:this.generateEventId(),context:r,enabled:t,featureName:n,impressionData:s}},o}(),st=["userId","sessionId","remoteAddress"],g={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent"},it="isEnabled",at="getVariant",ut={name:"disabled",enabled:!1,feature_enabled:!1},j="repo",ct=function(){try{if(typeof window!="undefined"&&"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)}},q=function(o){function r(t){var n=t.storageProvider,e=t.url,s=t.clientKey,i=t.disableRefresh,c=i!==void 0&&i,f=t.refreshInterval,l=f===void 0?30:f,a=t.metricsInterval,b=a===void 0?30:a,E=t.disableMetrics,x=E!==void 0&&E,R=t.appName,p=t.environment,m=p===void 0?"default":p,T=t.context,k=t.fetch,C=k===void 0?ct():k,U=t.bootstrap,Y=t.bootstrapOverride,mt=Y===void 0||Y,L=t.headerName,J=L===void 0?"Authorization":L,z=t.customHeaders,G=z===void 0?{}:z,$=t.impressionDataAll,gt=$!==void 0&&$,Q=t.usePOSTrequests,bt=Q!==void 0&&Q,u=o.call(this)||this;if(u.toggles=[],u.etag="",u.readyEventEmitted=!1,u.usePOSTrequests=!1,u.started=!1,!e)throw new Error("url is required");if(!s)throw new Error("clientKey is required");if(!R)throw new Error("appName is required.");return u.eventsHandler=new ot,u.impressionDataAll=gt,u.toggles=U&&U.length>0?U:[],u.url=e instanceof URL?e:new URL(e),u.clientKey=s,u.headerName=J,u.customHeaders=G,u.storage=n||(typeof window!="undefined"?new H:new M),u.refreshInterval=c?0:1e3*l,u.context=v({appName:R,environment:m},T),u.usePOSTrequests=bt,u.ready=new Promise(function(W){u.init().then(W).catch(function(X){console.error(X),u.emit(g.ERROR,X),W()})}),C||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),u.fetch=C,u.bootstrap=U&&U.length>0?U:void 0,u.bootstrapOverride=mt,u.metrics=new tt({onError:u.emit.bind(u,g.ERROR),onSent:u.emit.bind(u,g.SENT),appName:R,metricsInterval:b,disableMetrics:x,url:u.url,clientKey:s,fetch:C,headerName:J,customHeaders:G}),u}return function(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function e(){this.constructor=t}P(t,n),t.prototype=n===null?Object.create(n):(e.prototype=n.prototype,new e)}(r,o),r.prototype.getAllToggles=function(){return function(t,n,e){if(e||arguments.length===2)for(var s,i=0,c=n.length;i<c;i++)!s&&i in n||(s||(s=Array.prototype.slice.call(n,0,i)),s[i]=n[i]);return t.concat(s||Array.prototype.slice.call(n))}([],this.toggles,!0)},r.prototype.isEnabled=function(t){var n,e=this.toggles.find(function(c){return c.name===t}),s=!!e&&e.enabled;if(this.metrics.count(t,s),(e==null?void 0:e.impressionData)||this.impressionDataAll){var i=this.eventsHandler.createImpressionEvent(this.context,s,t,it,(n=e==null?void 0:e.impressionData)!==null&&n!==void 0?n:void 0);this.emit(g.IMPRESSION,i)}return s},r.prototype.getVariant=function(t){var n,e=this.toggles.find(function(f){return f.name===t}),s=(e==null?void 0:e.enabled)||!1,i=e?e.variant:ut;if(i.name&&this.metrics.countVariant(t,i.name),this.metrics.count(t,s),(e==null?void 0:e.impressionData)||this.impressionDataAll){var c=this.eventsHandler.createImpressionEvent(this.context,s,t,at,(n=e==null?void 0:e.impressionData)!==null&&n!==void 0?n:void 0,i.name);this.emit(g.IMPRESSION,c)}return v(v({},i),{feature_enabled:s})},r.prototype.updateContext=function(t){return I(this,void 0,void 0,function(){var n,e=this;return S(this,function(s){switch(s.label){case 0:return(t.appName||t.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),n={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=v(v({},n),t),this.timerRef||this.readyEventEmitted?[4,this.fetchToggles()]:[3,2];case 1:return s.sent(),[3,4];case 2:return this.started?[4,new Promise(function(i){var c=function(){e.fetchToggles().then(function(){e.off(g.READY,c),i()})};e.once(g.READY,c)})]:[3,4];case 3:s.sent(),s.label=4;case 4:return[2]}})})},r.prototype.getContext=function(){return v({},this.context)},r.prototype.setContextField=function(t,n){var e,s;if(st.includes(t))this.context=v(v({},this.context),((e={})[t]=n,e));else{var i=v(v({},this.context.properties),((s={})[t]=n,s));this.context=v(v({},this.context),{properties:i})}this.timerRef&&this.fetchToggles()},r.prototype.init=function(){return I(this,void 0,void 0,function(){var t,n;return S(this,function(e){switch(e.label){case 0:return[4,this.resolveSessionId()];case 1:return t=e.sent(),this.context=v({sessionId:t},this.context),n=this,[4,this.storage.get(j)];case 2:return n.toggles=e.sent()||[],!this.bootstrap||!this.bootstrapOverride&&this.toggles.length!==0?[3,4]:[4,this.storage.save(j,this.bootstrap)];case 3:e.sent(),this.toggles=this.bootstrap,this.emit(g.READY),e.label=4;case 4:return this.emit(g.INIT),[2]}})})},r.prototype.start=function(){return I(this,void 0,void 0,function(){var t,n=this;return S(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.fetchToggles()];case 2:return e.sent(),t>0&&(this.timerRef=setInterval(function(){return n.fetchToggles()},t)),[2]}})})},r.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},r.prototype.resolveSessionId=function(){return I(this,void 0,void 0,function(){var t;return S(this,function(n){switch(n.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return(t=n.sent())?[3,4]:(t=Math.floor(1e9*Math.random()),[4,this.storage.save("sessionId",t)]);case 3:n.sent(),n.label=4;case 4:return[2,t]}})})},r.prototype.getHeaders=function(){var t,n=((t={})[this.headerName]=this.clientKey,t.Accept="application/json",t["Content-Type"]="application/json",t["If-None-Match"]=this.etag,t);return Object.entries(this.customHeaders).filter(O).forEach(function(e){var s=e[0],i=e[1];return n[s]=i}),n},r.prototype.storeToggles=function(t){return I(this,void 0,void 0,function(){return S(this,function(n){switch(n.label){case 0:return this.toggles=t,this.emit(g.UPDATE),[4,this.storage.save(j,t)];case 1:return n.sent(),[2]}})})},r.prototype.fetchToggles=function(){return I(this,void 0,void 0,function(){var t,n,e,s,i,c,f;return S(this,function(l){switch(l.label){case 0:if(!this.fetch)return[3,8];l.label=1;case 1:return l.trys.push([1,7,,8]),t=this.usePOSTrequests,n=t?this.url:function(a,b){var E=new URL(a.toString());return Object.entries(b).filter(O).forEach(function(x){var R=x[0],p=x[1];R==="properties"&&p?Object.entries(p).filter(O).forEach(function(m){var T=m[0],k=m[1];return E.searchParams.append("properties[".concat(T,"]"),k)}):E.searchParams.append(R,p)}),E}(this.url,this.context),e=t?"POST":"GET",s=t?JSON.stringify({context:this.context}):void 0,[4,this.fetch(n.toString(),{method:e,cache:"no-cache",headers:this.getHeaders(),body:s})];case 2:return(i=l.sent()).ok&&i.status!==304?(this.etag=i.headers.get("ETag")||"",[4,i.json()]):[3,5];case 3:return c=l.sent(),[4,this.storeToggles(c.toggles)];case 4:return l.sent(),this.bootstrap||this.readyEventEmitted||(this.emit(g.READY),this.readyEventEmitted=!0),[3,6];case 5:i.ok||i.status===304||(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.emit(g.ERROR,{type:"HttpError",code:i.status})),l.label=6;case 6:return[3,8];case 7:return f=l.sent(),console.error("Unleash: unable to fetch feature toggles",f),this.emit(g.ERROR,f),[3,8];case 8:return[2]}})})},r}(Z);const w=Symbol("Context state identifier"),A=Symbol("Context update identifier");function K({config:o,unleashClient:r,startClient:t=!0}){var x,R;const n=h.ref(r),e=h.ref(!1),s=h.ref(null);!o&&!r&&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.`),!n.value&&o&&(n.value=new q(o)),(x=n.value)==null||x.on("ready",()=>{e.value=!0}),(R=n.value)==null||R.on("error",p=>{s.value=p});const i=async p=>{var m;await((m=n.value)==null?void 0:m.updateContext(p))},c=p=>{var m;return(m=n.value)==null?void 0:m.isEnabled(p)},f=p=>{var m;return(m=n.value)==null?void 0:m.getVariant(p)},l=(p,...m)=>{var T;return(T=n.value)==null?void 0:T.on(p,...m)},a=h.reactive({on:l,updateContext:i,isEnabled:c,getVariant:f,client:n,flagsReady:e,flagsError:s}),b=(p,m)=>{a[p]=m},E=()=>{var p;(t||!r)&&((p=n==null?void 0:n.value)==null||p.start())};return{context:h.toRefs(a),update:b,start:E}}const F=h.defineComponent({__name:"FlagProvider",props:{config:null,unleashClient:null,startClient:{type:Boolean}},setup(o){const{config:r,unleashClient:t,startClient:n=!0}=o,{context:e,start:s,update:i}=K({config:r,unleashClient:t,startClient:n});return h.provide(w,e),h.provide(A,i),h.onMounted(()=>{s()}),(c,f)=>h.renderSlot(c.$slots,"default")}}),lt=o=>{const{isEnabled:r,client:t}=h.inject(w,{}),n=h.ref(Boolean(r==null?void 0:r.value(o)));function e(){const i=r==null?void 0:r.value(o);i!==n.value&&(n.value=!!i)}function s(){n.value=Boolean(r==null?void 0:r.value(o))}return t==null||t.value.on("ready",s),t==null||t.value.on("update",e),h.onUnmounted(()=>{t==null||t.value.off("ready",s),t==null||t.value.off("update",e)}),n},ht=()=>{const{flagsReady:o,flagsError:r}=h.inject(w,{});return{flagsReady:o,flagsError:r}},ft=(o,r)=>{var n,e,s,i;return!((o==null?void 0:o.name)===(r==null?void 0:r.name)&&(o==null?void 0:o.enabled)===(r==null?void 0:r.enabled)&&(o==null?void 0:o.feature_enabled)===(r==null?void 0:r.feature_enabled)&&((n=o==null?void 0:o.payload)==null?void 0:n.type)===((e=r==null?void 0:r.payload)==null?void 0:e.type)&&((s=o==null?void 0:o.payload)==null?void 0:s.value)===((i=r==null?void 0:r.payload)==null?void 0:i.value))},pt=o=>{const{getVariant:r,client:t}=h.inject(w,{}),n=h.ref(r==null?void 0:r.value(o));function e(){const i=r==null?void 0:r.value(o);ft(n==null?void 0:n.value,i)&&(n.value=i)}function s(){n.value=r==null?void 0:r.value(o)}return t==null||t.value.on("ready",s),t==null||t.value.on("update",e),h.onUnmounted(()=>{t==null||t.value.off("ready",s),t==null||t.value.off("update",e)}),n||{}},dt=()=>{const{updateContext:o}=h.inject(w,{});return o==null?void 0:o.value},vt=()=>{const{client:o}=h.inject(w,{});return o==null?void 0:o.value},yt={install(o,{config:r,unleashClient:t,startClient:n}){const{context:e,update:s,start:i}=K({config:r,unleashClient:t,startClient:n});o.provide(w,e),o.provide(A,s),i()}};d.ContextStateSymbol=w,d.ContextUpdateSymbol=A,d.FlagProvider=F,d.InMemoryStorageProvider=M,d.LocalStorageProvider=H,d.UnleashClient=q,d.default=F,d.plugin=yt,d.useFlag=lt,d.useFlagsStatus=ht,d.useUnleashClient=vt,d.useUnleashContext=dt,d.useVariant=pt,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/useVariant.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unleash/proxy-client-vue",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Vue interface for working with Unleash",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"preview": "vite preview"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"unleash-proxy-client": "^2.
|
|
30
|
+
"unleash-proxy-client": "^3.2.0",
|
|
31
31
|
"vue": "^3.2.45"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|