@unleash/proxy-client-vue 0.0.8 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +429 -1514
- package/dist/index.umd.js +2 -2
- package/dist/useVariant.d.ts +1 -0
- package/package.json +10 -4
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(T,E){typeof exports=="object"&&typeof module!="undefined"?E(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],E):(T=typeof globalThis!="undefined"?globalThis:T||self,E(T["proxy-client-vue"]={},T.Vue))})(this,function(T,E){"use strict";var w=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 K={},J={exports:{}};function X(){}X.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}},J.exports=X,J.exports.TinyEmitter=X;var z={},W={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.urlWithContextAsQuery=t.notNullOrUndefined=void 0;var o=function(n){var a=n[1];return a!=null};t.notNullOrUndefined=o;var e=function(n,a){var r=new URL(n.toString());return Object.entries(a).filter(t.notNullOrUndefined).forEach(function(i){var h=i[0],v=i[1];h==="properties"&&v?Object.entries(v).filter(t.notNullOrUndefined).forEach(function(s){var d=s[0],m=s[1];return r.searchParams.append("properties[".concat(d,"]"),m)}):r.searchParams.append(h,v)}),r};t.urlWithContextAsQuery=e})(W);var F=w&&w.__assign||function(){return F=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},F.apply(this,arguments)},ke=w&&w.__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 h(d){try{s(n.next(d))}catch(m){i(m)}}function v(d){try{s(n.throw(d))}catch(m){i(m)}}function s(d){d.done?r(d.value):a(d.value).then(h,v)}s((n=n.apply(t,o||[])).next())})},Pe=w&&w.__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:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function h(s){return function(d){return v([s,d])}}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(d){s=[6,d],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(z,"__esModule",{value:!0});var Ce=W,Me=function(){},je=function(){function t(o){var e=o.onError,n=o.onSent,a=o.appName,r=o.metricsInterval,i=o.disableMetrics,h=i===void 0?!1:i,v=o.url,s=o.clientKey,d=o.fetch,m=o.headerName,_=o.customHeaders,R=_===void 0?{}:_;this.onError=e,this.onSent=n||Me,this.disabled=h,this.metricsInterval=r*1e3,this.appName=a,this.url=v instanceof URL?v:new URL(v),this.clientKey=s,this.bucket=this.createEmptyBucket(),this.fetch=d,this.headerName=m,this.customHeaders=R}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.getHeaders=function(){var o,e=(o={},o[this.headerName]=this.clientKey,o.Accept="application/json",o["Content-Type"]="application/json",o);return Object.entries(this.customHeaders).filter(Ce.notNullOrUndefined).forEach(function(n){var a=n[0],r=n[1];return e[a]=r}),e},t.prototype.sendMetrics=function(){return ke(this,void 0,void 0,function(){var o,e,n;return Pe(this,function(a){switch(a.label){case 0:if(o="".concat(this.url,"/client/metrics"),e=this.getPayload(),this.bucketIsEmpty(e))return[2];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.fetch(o,{cache:"no-cache",method:"POST",headers:this.getHeaders(),body:JSON.stringify(e)})];case 2:return a.sent(),this.onSent(e),[3,4];case 3:return n=a.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.countVariant=function(o,e){return this.disabled||!this.bucket?!1:(this.assertBucket(o),this.bucket.toggles[o].variants[e]?this.bucket.toggles[o].variants[e]+=1:this.bucket.toggles[o].variants[e]=1,!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,variants:{}})},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=F(F({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:o,appName:this.appName,instanceId:"browser"}},t}();z.default=je;var Z={},ce=w&&w.__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 h(d){try{s(n.next(d))}catch(m){i(m)}}function v(d){try{s(n.throw(d))}catch(m){i(m)}}function s(d){d.done?r(d.value):a(d.value).then(h,v)}s((n=n.apply(t,o||[])).next())})},le=w&&w.__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:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function h(s){return function(d){return v([s,d])}}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(d){s=[6,d],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(Z,"__esModule",{value:!0});var De=function(){function t(){this.store=new Map}return t.prototype.save=function(o,e){return ce(this,void 0,void 0,function(){return le(this,function(n){return this.store.set(o,e),[2]})})},t.prototype.get=function(o){return ce(this,void 0,void 0,function(){return le(this,function(e){return[2,this.store.get(o)]})})},t}();Z.default=De;var ee={},Ve=w&&w.__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 h(d){try{s(n.next(d))}catch(m){i(m)}}function v(d){try{s(n.throw(d))}catch(m){i(m)}}function s(d){d.done?r(d.value):a(d.value).then(h,v)}s((n=n.apply(t,o||[])).next())})},He=w&&w.__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:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function h(s){return function(d){return v([s,d])}}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(d){s=[6,d],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 Le=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(o,e){return Ve(this,void 0,void 0,function(){var n,a;return He(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}();ee.default=Le;var te={},$,Ke=new Uint8Array(16);function de(){if(!$&&($=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!$))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return $(Ke)}var qe=/^(?:[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"&&qe.test(t)}for(var O=[],re=0;re<256;++re)O.push((re+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 he,ne,ae=0,oe=0;function Fe(t,o,e){var n=o&&e||0,a=o||new Array(16);t=t||{};var r=t.node||he,i=t.clockseq!==void 0?t.clockseq:ne;if(r==null||i==null){var h=t.random||(t.rng||de)();r==null&&(r=he=[h[0]|1,h[1],h[2],h[3],h[4],h[5]]),i==null&&(i=ne=(h[6]<<8|h[7])&16383)}var v=t.msecs!==void 0?t.msecs:Date.now(),s=t.nsecs!==void 0?t.nsecs:oe+1,d=v-ae+(s-oe)/1e4;if(d<0&&t.clockseq===void 0&&(i=i+1&16383),(d<0||v>ae)&&t.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");ae=v,oe=s,ne=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 _=v/4294967296*1e4&268435455;a[n++]=_>>>8&255,a[n++]=_&255,a[n++]=_>>>24&15|16,a[n++]=_>>>16&255,a[n++]=i>>>8|128,a[n++]=i&255;for(var R=0;R<6;++R)a[n+R]=r[R];return o||B(a)}function ve(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 $e(t){t=unescape(encodeURIComponent(t));for(var o=[],e=0;e<t.length;++e)o.push(t.charCodeAt(e));return o}var Ge="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Be="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function ye(t,o,e){function n(a,r,i,h){if(typeof a=="string"&&(a=$e(a)),typeof r=="string"&&(r=ve(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){h=h||0;for(var s=0;s<16;++s)i[h+s]=v[s];return i}return B(v)}try{n.name=t}catch{}return n.DNS=Ge,n.URL=Be,n}function Ye(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(Je(Xe(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 pe(t){return(t+64>>>9<<4)+14+1}function Je(t,o){t[o>>5]|=128<<o%32,t[pe(o)-1]=o;for(var e=1732584193,n=-271733879,a=-1732584194,r=271733878,i=0;i<t.length;i+=16){var h=e,v=n,s=a,d=r;e=A(e,n,a,r,t[i],7,-680876936),r=A(r,e,n,a,t[i+1],12,-389564586),a=A(a,r,e,n,t[i+2],17,606105819),n=A(n,a,r,e,t[i+3],22,-1044525330),e=A(e,n,a,r,t[i+4],7,-176418897),r=A(r,e,n,a,t[i+5],12,1200080426),a=A(a,r,e,n,t[i+6],17,-1473231341),n=A(n,a,r,e,t[i+7],22,-45705983),e=A(e,n,a,r,t[i+8],7,1770035416),r=A(r,e,n,a,t[i+9],12,-1958414417),a=A(a,r,e,n,t[i+10],17,-42063),n=A(n,a,r,e,t[i+11],22,-1990404162),e=A(e,n,a,r,t[i+12],7,1804603682),r=A(r,e,n,a,t[i+13],12,-40341101),a=A(a,r,e,n,t[i+14],17,-1502002290),n=A(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=k(e,n,a,r,t[i+5],4,-378558),r=k(r,e,n,a,t[i+8],11,-2022574463),a=k(a,r,e,n,t[i+11],16,1839030562),n=k(n,a,r,e,t[i+14],23,-35309556),e=k(e,n,a,r,t[i+1],4,-1530992060),r=k(r,e,n,a,t[i+4],11,1272893353),a=k(a,r,e,n,t[i+7],16,-155497632),n=k(n,a,r,e,t[i+10],23,-1094730640),e=k(e,n,a,r,t[i+13],4,681279174),r=k(r,e,n,a,t[i],11,-358537222),a=k(a,r,e,n,t[i+3],16,-722521979),n=k(n,a,r,e,t[i+6],23,76029189),e=k(e,n,a,r,t[i+9],4,-640364487),r=k(r,e,n,a,t[i+12],11,-421815835),a=k(a,r,e,n,t[i+15],16,530742520),n=k(n,a,r,e,t[i+2],23,-995338651),e=P(e,n,a,r,t[i],6,-198630844),r=P(r,e,n,a,t[i+7],10,1126891415),a=P(a,r,e,n,t[i+14],15,-1416354905),n=P(n,a,r,e,t[i+5],21,-57434055),e=P(e,n,a,r,t[i+12],6,1700485571),r=P(r,e,n,a,t[i+3],10,-1894986606),a=P(a,r,e,n,t[i+10],15,-1051523),n=P(n,a,r,e,t[i+1],21,-2054922799),e=P(e,n,a,r,t[i+8],6,1873313359),r=P(r,e,n,a,t[i+15],10,-30611744),a=P(a,r,e,n,t[i+6],15,-1560198380),n=P(n,a,r,e,t[i+13],21,1309151649),e=P(e,n,a,r,t[i+4],6,-145523070),r=P(r,e,n,a,t[i+11],10,-1120210379),a=P(a,r,e,n,t[i+2],15,718787259),n=P(n,a,r,e,t[i+9],21,-343485551),e=V(e,h),n=V(n,v),a=V(a,s),r=V(r,d)}return[e,n,a,r]}function Xe(t){if(t.length===0)return[];for(var o=t.length*8,e=new Uint32Array(pe(o)),n=0;n<o;n+=8)e[n>>5]|=(t[n/8]&255)<<n%32;return e}function V(t,o){var e=(t&65535)+(o&65535),n=(t>>16)+(o>>16)+(e>>16);return n<<16|e&65535}function ze(t,o){return t<<o|t>>>32-o}function Y(t,o,e,n,a,r){return V(ze(V(V(o,t),V(n,r)),a),e)}function A(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 k(t,o,e,n,a,r,i){return Y(o^e^n,t,o,a,r,i)}function P(t,o,e,n,a,r,i){return Y(e^(o|~n),t,o,a,r,i)}var We=ye("v3",48,Ye),Ze=We;function et(t,o,e){t=t||{};var n=t.random||(t.rng||de)();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 tt(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 ie(t,o){return t<<o|t>>>32-o}function rt(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),h=new Array(i),v=0;v<i;++v){for(var s=new Uint32Array(16),d=0;d<16;++d)s[d]=t[v*64+d*4]<<24|t[v*64+d*4+1]<<16|t[v*64+d*4+2]<<8|t[v*64+d*4+3];h[v]=s}h[i-1][14]=(t.length-1)*8/Math.pow(2,32),h[i-1][14]=Math.floor(h[i-1][14]),h[i-1][15]=(t.length-1)*8&4294967295;for(var m=0;m<i;++m){for(var _=new Uint32Array(80),R=0;R<16;++R)_[R]=h[m][R];for(var M=16;M<80;++M)_[M]=ie(_[M-3]^_[M-8]^_[M-14]^_[M-16],1);for(var S=e[0],N=e[1],D=e[2],I=e[3],p=e[4],u=0;u<80;++u){var l=Math.floor(u/20),f=ie(S,5)+tt(l,N,D,I)+p+o[l]+_[u]>>>0;p=I,I=D,D=ie(N,30)>>>0,N=S,S=f}e[0]=e[0]+S>>>0,e[1]=e[1]+N>>>0,e[2]=e[2]+D>>>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 nt=ye("v5",80,rt),at=nt,ot="00000000-0000-0000-0000-000000000000";function it(t){if(!G(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}var st=Object.freeze(Object.defineProperty({__proto__:null,v1:Fe,v3:Ze,v4:et,v5:at,NIL:ot,version:it,validate:G,stringify:B,parse:ve},Symbol.toStringTag,{value:"Module"})),ut=xe(st),Q=w&&w.__assign||function(){return Q=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},Q.apply(this,arguments)};Object.defineProperty(te,"__esModule",{value:!0});var ft=ut,ct=function(){function t(){}return t.prototype.generateEventId=function(){return(0,ft.v4)()},t.prototype.createImpressionEvent=function(o,e,n,a,r,i){var h=this.createBaseEvent(o,e,n,a,r);return i?Q(Q({},h),{variant:i}):h},t.prototype.createBaseEvent=function(o,e,n,a,r){return{eventType:a,eventId:this.generateEventId(),context:o,enabled:e,featureName:n,impressionData:r}},t}();te.default=ct,function(t){var o=w&&w.__extends||function(){var I=function(p,u){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(l,f){l.__proto__=f}||function(l,f){for(var c in f)Object.prototype.hasOwnProperty.call(f,c)&&(l[c]=f[c])},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 l(){this.constructor=p}p.prototype=u===null?Object.create(u):(l.prototype=u.prototype,new l)}}(),e=w&&w.__assign||function(){return e=Object.assign||function(I){for(var p,u=1,l=arguments.length;u<l;u++){p=arguments[u];for(var f in p)Object.prototype.hasOwnProperty.call(p,f)&&(I[f]=p[f])}return I},e.apply(this,arguments)},n=w&&w.__awaiter||function(I,p,u,l){function f(c){return c instanceof u?c:new u(function(g){g(c)})}return new(u||(u=Promise))(function(c,g){function U(C){try{y(l.next(C))}catch(q){g(q)}}function j(C){try{y(l.throw(C))}catch(q){g(q)}}function y(C){C.done?c(C.value):f(C.value).then(U,j)}y((l=l.apply(I,p||[])).next())})},a=w&&w.__generator||function(I,p){var u={label:0,sent:function(){if(c[0]&1)throw c[1];return c[1]},trys:[],ops:[]},l,f,c,g;return g={next:U(0),throw:U(1),return:U(2)},typeof Symbol=="function"&&(g[Symbol.iterator]=function(){return this}),g;function U(y){return function(C){return j([y,C])}}function j(y){if(l)throw new TypeError("Generator is already executing.");for(;u;)try{if(l=1,f&&(c=y[0]&2?f.return:y[0]?f.throw||((c=f.return)&&c.call(f),0):f.next)&&!(c=c.call(f,y[1])).done)return c;switch(f=0,c&&(y=[y[0]&2,c.value]),y[0]){case 0:case 1:c=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(c=u.trys,!(c=c.length>0&&c[c.length-1])&&(y[0]===6||y[0]===2)){u=0;continue}if(y[0]===3&&(!c||y[1]>c[0]&&y[1]<c[3])){u.label=y[1];break}if(y[0]===6&&u.label<c[1]){u.label=c[1],c=y;break}if(c&&u.label<c[2]){u.label=c[2],u.ops.push(y);break}c[2]&&u.ops.pop(),u.trys.pop();continue}y=p.call(I,u)}catch(C){y=[6,C],f=0}finally{l=c=0}if(y[0]&5)throw y[1];return{value:y[0]?y[1]:void 0,done:!0}}},r=w&&w.__spreadArray||function(I,p,u){if(u||arguments.length===2)for(var l=0,f=p.length,c;l<f;l++)(c||!(l in p))&&(c||(c=Array.prototype.slice.call(p,0,l)),c[l]=p[l]);return I.concat(c||Array.prototype.slice.call(p))};Object.defineProperty(t,"__esModule",{value:!0}),t.InMemoryStorageProvider=t.LocalStorageProvider=t.UnleashClient=t.resolveFetch=t.EVENTS=void 0;var i=J.exports,h=z,v=Z;t.InMemoryStorageProvider=v.default;var s=ee;t.LocalStorageProvider=s.default;var d=te,m=W,_=["userId","sessionId","remoteAddress"];t.EVENTS={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression",SENT:"sent"};var R={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},M={name:"disabled",enabled:!1},S="repo",N=function(){try{if(typeof window!="undefined"&&"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=N;var D=function(I){o(p,I);function p(u){var l=u.storageProvider,f=u.url,c=u.clientKey,g=u.disableRefresh,U=g===void 0?!1:g,j=u.refreshInterval,y=j===void 0?30:j,C=u.metricsInterval,q=C===void 0?30:C,be=u.disableMetrics,gt=be===void 0?!1:be,ue=u.appName,we=u.environment,mt=we===void 0?"default":we,bt=u.context,Ee=u.fetch,fe=Ee===void 0?(0,t.resolveFetch)():Ee,L=u.bootstrap,Se=u.bootstrapOverride,wt=Se===void 0?!0:Se,Ie=u.headerName,Te=Ie===void 0?"Authorization":Ie,_e=u.customHeaders,Ne=_e===void 0?{}:_e,Oe=u.impressionDataAll,Et=Oe===void 0?!1:Oe,Re=u.usePOSTrequests,St=Re===void 0?!1:Re,b=I.call(this)||this;if(b.toggles=[],b.etag="",b.readyEventEmitted=!1,b.usePOSTrequests=!1,b.started=!1,!f)throw new Error("url is required");if(!c)throw new Error("clientKey is required");if(!ue)throw new Error("appName is required.");return b.eventsHandler=new d.default,b.impressionDataAll=Et,b.toggles=L&&L.length>0?L:[],b.url=f instanceof URL?f:new URL(f),b.clientKey=c,b.headerName=Te,b.customHeaders=Ne,b.storage=l||(typeof window!="undefined"?new s.default:new v.default),b.refreshInterval=U?0:y*1e3,b.context=e({appName:ue,environment:mt},bt),b.usePOSTrequests=St,b.ready=new Promise(function(Ue){b.init().then(Ue).catch(function(Ae){console.error(Ae),b.emit(t.EVENTS.ERROR,Ae),Ue()})}),fe||console.error('Unleash: You must either provide your own "fetch" implementation or run in an environment where "fetch" is available.'),b.fetch=fe,b.bootstrap=L&&L.length>0?L:void 0,b.bootstrapOverride=wt,b.metrics=new h.default({onError:b.emit.bind(b,t.EVENTS.ERROR),onSent:b.emit.bind(b,t.EVENTS.SENT),appName:ue,metricsInterval:q,disableMetrics:gt,url:b.url,clientKey:c,fetch:fe,headerName:Te,customHeaders:Ne}),b}return p.prototype.getAllToggles=function(){return r([],this.toggles,!0)},p.prototype.isEnabled=function(u){var l,f=this.toggles.find(function(U){return U.name===u}),c=f?f.enabled:!1;if(this.metrics.count(u,c),(f==null?void 0:f.impressionData)||this.impressionDataAll){var g=this.eventsHandler.createImpressionEvent(this.context,c,u,R.IS_ENABLED,(l=f==null?void 0:f.impressionData)!==null&&l!==void 0?l:void 0);this.emit(t.EVENTS.IMPRESSION,g)}return c},p.prototype.getVariant=function(u){var l,f=this.toggles.find(function(j){return j.name===u}),c=(f==null?void 0:f.enabled)||!1,g=f?f.variant:M;if(g.name&&this.metrics.countVariant(u,g.name),this.metrics.count(u,c),(f==null?void 0:f.impressionData)||this.impressionDataAll){var U=this.eventsHandler.createImpressionEvent(this.context,c,u,R.GET_VARIANT,(l=f==null?void 0:f.impressionData)!==null&&l!==void 0?l:void 0,g.name);this.emit(t.EVENTS.IMPRESSION,U)}return g},p.prototype.updateContext=function(u){return n(this,void 0,void 0,function(){var l,f=this;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."),l={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=e(e({},l),u),this.timerRef||this.readyEventEmitted?[4,this.fetchToggles()]:[3,2];case 1:return c.sent(),[3,4];case 2:return this.started?[4,new Promise(function(g){var U=function(){f.fetchToggles().then(function(){f.off(t.EVENTS.READY,U),g()})};f.once(t.EVENTS.READY,U)})]:[3,4];case 3:c.sent(),c.label=4;case 4:return[2]}})})},p.prototype.getContext=function(){return e({},this.context)},p.prototype.setContextField=function(u,l){var f,c;if(_.includes(u))this.context=e(e({},this.context),(f={},f[u]=l,f));else{var g=e(e({},this.context.properties),(c={},c[u]=l,c));this.context=e(e({},this.context),{properties:g})}this.timerRef&&this.fetchToggles()},p.prototype.init=function(){return n(this,void 0,void 0,function(){var u,l;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),l=this,[4,this.storage.get(S)];case 2:return l.toggles=f.sent()||[],this.bootstrap&&(this.bootstrapOverride||this.toggles.length===0)?[4,this.storage.save(S,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,l=this;return a(this,function(f){switch(f.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 f.sent(),this.metrics.start(),u=this.refreshInterval,[4,this.fetchToggles()];case 2:return f.sent(),u>0&&(this.timerRef=setInterval(function(){return l.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(l){switch(l.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=l.sent(),u?[3,4]:(u=Math.floor(Math.random()*1e9),[4,this.storage.save("sessionId",u)]);case 3:l.sent(),l.label=4;case 4:return[2,u]}})})},p.prototype.getHeaders=function(){var u,l=(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(f){var c=f[0],g=f[1];return l[c]=g}),l},p.prototype.storeToggles=function(u){return n(this,void 0,void 0,function(){return a(this,function(l){switch(l.label){case 0:return this.toggles=u,this.emit(t.EVENTS.UPDATE),[4,this.storage.save(S,u)];case 1:return l.sent(),[2]}})})},p.prototype.fetchToggles=function(){return n(this,void 0,void 0,function(){var u,l,f,c,g,U,j;return a(this,function(y){switch(y.label){case 0:if(!this.fetch)return[3,8];y.label=1;case 1:return y.trys.push([1,7,,8]),u=this.usePOSTrequests,l=u?this.url:(0,m.urlWithContextAsQuery)(this.url,this.context),f=u?"POST":"GET",c=u?JSON.stringify({context:this.context}):void 0,[4,this.fetch(l.toString(),{method:f,cache:"no-cache",headers:this.getHeaders(),body:c})];case 2:return g=y.sent(),g.ok&&g.status!==304?(this.etag=g.headers.get("ETag")||"",[4,g.json()]):[3,5];case 3:return U=y.sent(),[4,this.storeToggles(U.toggles)];case 4:return y.sent(),!this.bootstrap&&!this.readyEventEmitted&&(this.emit(t.EVENTS.READY),this.readyEventEmitted=!0),[3,6];case 5:!g.ok&&g.status!==304&&(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.emit(t.EVENTS.ERROR,{type:"HttpError",code:g.status})),y.label=6;case 6:return[3,8];case 7:return j=y.sent(),console.error("Unleash: unable to fetch feature toggles",j),this.emit(t.EVENTS.ERROR,j),[3,8];case 8:return[2]}})})},p}(i.TinyEmitter);t.UnleashClient=D}(K);const H=Symbol("Context state identifier"),se=Symbol("Context update identifier");function ge({config:t,unleashClient:o,startClient:e=!0}){var R,M;const n=E.ref(o),a=E.ref(!1),r=E.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.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Vue interface for working with Unleash",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -16,8 +16,14 @@
|
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"import":
|
|
20
|
-
|
|
19
|
+
"import": {
|
|
20
|
+
"default": "./dist/index.es.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"default": "./dist/index.umd.js",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
}
|
|
21
27
|
}
|
|
22
28
|
},
|
|
23
29
|
"scripts": {
|
|
@@ -27,7 +33,7 @@
|
|
|
27
33
|
"preview": "vite preview"
|
|
28
34
|
},
|
|
29
35
|
"dependencies": {
|
|
30
|
-
"unleash-proxy-client": "^2.
|
|
36
|
+
"unleash-proxy-client": "^3.2.0",
|
|
31
37
|
"vue": "^3.2.45"
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|