New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@unleash/proxy-client-react

Package Overview
Dependencies
Maintainers
4
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unleash/proxy-client-react - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

2

dist/index.js

@@ -1,1 +0,1 @@

(()=>{var t={560:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>u,useAsyncStorage:()=>c});var r=n(178),o=n.n(r);const i=(t,e)=>new Promise(((n,r)=>{try{const r=t();e&&e(null,r),n(r)}catch(t){e&&e(t),r(t)}})),s=(t,e,n)=>Promise.all(t).then((t=>{const r=n?n(t):null;return e&&e(null,r),Promise.resolve(r)}),(t=>(e&&e(t),Promise.reject(t))));class a{static getItem(t,e){return i((()=>window.localStorage.getItem(t)),e)}static setItem(t,e,n){return i((()=>{window.localStorage.setItem(t,e)}),n)}static removeItem(t,e){return i((()=>window.localStorage.removeItem(t)),e)}static mergeItem(t,e,n){return i((()=>{((t,e)=>{const n=window.localStorage.getItem(t),r=JSON.parse(n),i=JSON.parse(e),s=JSON.stringify(o()({},r,i));window.localStorage.setItem(t,s)})(t,e)}),n)}static clear(t){return i((()=>{window.localStorage.clear()}),t)}static getAllKeys(t){return i((()=>{const t=window.localStorage.length,e=[];for(let n=0;n<t;n+=1){const t=window.localStorage.key(n);e.push(t)}return e}),t)}static flushGetRequests(){}static multiGet(t,e){const n=t.map((t=>a.getItem(t)));return s(n,e,(e=>e.map(((e,n)=>[t[n],e]))))}static multiSet(t,e){const n=t.map((t=>a.setItem(t[0],t[1])));return s(n,e)}static multiRemove(t,e){const n=t.map((t=>a.removeItem(t)));return s(n,e)}static multiMerge(t,e){const n=t.map((t=>a.mergeItem(t[0],t[1])));return s(n,e)}}function c(t){return{getItem:(...e)=>a.getItem(t,...e),setItem:(...e)=>a.setItem(t,...e),mergeItem:(...e)=>a.mergeItem(t,...e),removeItem:(...e)=>a.removeItem(t,...e)}}const u=a},178:(t,e,n)=>{"use strict";var r=n(290),o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;function s(t){if(null==t)throw new TypeError("Sources cannot be null or undefined");return Object(t)}function a(t,e,n){var i=e[n];if(null!=i){if(o.call(t,n)&&(void 0===t[n]||null===t[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");o.call(t,n)&&r(i)?t[n]=c(Object(t[n]),e[n]):t[n]=i}}function c(t,e){if(t===e)return t;for(var n in e=Object(e))o.call(e,n)&&a(t,e,n);if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),s=0;s<r.length;s++)i.call(e,r[s])&&a(t,e,r[s]);return t}t.exports=function(t){t=s(t);for(var e=1;e<arguments.length;e++)c(t,arguments[e]);return t}},290:t=>{"use strict";t.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},279:t=>{function e(){}e.prototype={on:function(t,e,n){var r=this.e||(this.e={});return(r[t]||(r[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){var r=this;function o(){r.off(t,o),e.apply(n,arguments)}return o._=e,this.on(t,o,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),r=0,o=n.length;r<o;r++)n[r].fn.apply(n[r].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),r=n[t],o=[];if(r&&e)for(var i=0,s=r.length;i<s;i++)r[i].fn!==e&&r[i].fn._!==e&&o.push(r[i]);return o.length?n[t]=o:delete n[t],this}},t.exports=e,t.exports.TinyEmitter=e},9:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.UnleashClient=e.EVENTS=void 0;var c=n(279),u=n(524),l=n(432);e.EVENTS={READY:"ready",UPDATE:"update"};var f={name:"disabled"},h=function(t){function n(e){var n=e.storageProvider,r=e.url,o=e.clientKey,s=e.refreshInterval,a=void 0===s?30:s,c=e.metricsInterval,f=void 0===c?30:c,h=e.disableMetrics,p=void 0!==h&&h,d=e.appName,v=e.environment,y=void 0===v?"default":v,m=e.context,b=t.call(this)||this;if(b.toggles=[],b.etag="",!r)throw new Error("url is required");if(!o)throw new Error("clientKey is required");if(!d)throw new Error("appName is required.");return b.url=new URL(""+r),b.clientKey=o,b.storage=n||new l.default,b.refreshInterval=1e3*a,b.context=i({appName:d,environment:y},m),b.metrics=new u.default({appName:d,metricsInterval:f,disableMetrics:p,url:r,clientKey:o}),b}return o(n,t),n.prototype.isEnabled=function(t){var e=this.toggles.find((function(e){return e.name===t})),n=!!e&&e.enabled;return this.metrics.count(t,n),n},n.prototype.getVariant=function(t){var e=this.toggles.find((function(e){return e.name===t}));return e?(this.metrics.count(t,!0),e.variant):(this.metrics.count(t,!1),f)},n.prototype.updateContext=function(t){(t.appName||t.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext.");var e={environment:this.context.environment,appName:this.context.appName};this.context=i(i({},e),t),this.timerRef&&this.fetchToggles()},n.prototype.start=function(){return s(this,void 0,void 0,(function(){var t,n=this;return a(this,(function(r){switch(r.label){case 0:return"fetch"in window?(this.stop(),t=this.refreshInterval,[4,this.fetchToggles()]):[3,2];case 1:return r.sent(),this.emit(e.EVENTS.READY),this.timerRef=setInterval((function(){return n.fetchToggles()}),t),[3,3];case 2:console.error("Unleash: Client does not support fetch."),r.label=3;case 3:return[2]}}))}))},n.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0)},n.prototype.storeToggles=function(t){return s(this,void 0,void 0,(function(){return a(this,(function(n){return this.toggles=t,this.emit(e.EVENTS.UPDATE),this.storage.save("repo",t),[2]}))}))},n.prototype.fetchToggles=function(){return s(this,void 0,void 0,(function(){var t,e,n,r,o;return a(this,(function(i){switch(i.label){case 0:if(!fetch)return[3,7];i.label=1;case 1:return i.trys.push([1,6,,7]),t=this.context,e=new URL(this.url.toString()),Object.entries(t).forEach((function(t){var n=t[0],r=t[1];"properties"===n&&r?Object.entries(r).forEach((function(t){var n=t[0],r=t[1];return e.searchParams.append("properties["+n+"]",r)})):e.searchParams.append(n,r)})),[4,fetch(e.toString(),{cache:"no-cache",headers:{Authorization:this.clientKey,Accept:"application/json","Content-Type":"application/json","If-None-Match":this.etag}})];case 2:return(n=i.sent()).ok&&304!==n.status?(this.etag=n.headers.get("ETag")||"",[4,n.json()]):[3,5];case 3:return r=i.sent(),[4,this.storeToggles(r.toggles)];case 4:i.sent(),i.label=5;case 5:return[3,7];case 6:return o=i.sent(),console.error("Unleash: unable to fetch feature toggles",o),[3,7];case 7:return[2]}}))}))},n}(c.TinyEmitter);e.UnleashClient=h},524:function(t,e){"use strict";var n=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},r=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t){var e=t.appName,n=t.metricsInterval,r=t.disableMetrics,o=void 0!==r&&r,i=t.url,s=t.clientKey;this.disabled=o,this.metricsInterval=1e3*n,this.appName=e,this.url=i,this.started=new Date,this.clientKey=s,this.resetBucket(),"number"==typeof this.metricsInterval&&this.metricsInterval>0&&this.startTimer(2e3)}return t.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer),this.disabled=!0},t.prototype.sendMetrics=function(){return n(this,void 0,void 0,(function(){var t,e;return r(this,(function(n){switch(n.label){case 0:return this.disabled?[2,!1]:this.bucketIsEmpty()?(this.resetBucket(),this.startTimer(),[2,!0]):(t=this.url+"/client/metrics",e=this.getPayload(),[4,fetch(t,{cache:"no-cache",method:"POST",headers:{Authorization:this.clientKey,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)})]);case 1:return n.sent(),[2,!0]}}))}))},t.prototype.count=function(t,e){return!(this.disabled||!this.bucket||(this.assertBucket(t),this.bucket.toggles[t][e?"yes":"no"]++,0))},t.prototype.assertBucket=function(t){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[t]||(this.bucket.toggles[t]={yes:0,no:0})},t.prototype.startTimer=function(t){var e=this;return!this.disabled&&(this.timer=setTimeout((function(){e.sendMetrics()}),t||this.metricsInterval),!0)},t.prototype.bucketIsEmpty=function(){return!!this.bucket&&0===Object.keys(this.bucket.toggles).length},t.prototype.resetBucket=function(){var t={start:new Date,stop:null,toggles:{}};this.bucket=t},t.prototype.closeBucket=function(){this.bucket&&(this.bucket.stop=new Date)},t.prototype.getPayload=function(){this.closeBucket();var t=this.getMetricsData();return this.resetBucket(),t},t.prototype.getMetricsData=function(){return{appName:this.appName,instanceId:"browser",bucket:this.bucket}},t}();e.default=o},432:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(560),s=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(t,e){return r(this,void 0,void 0,(function(){var n,r,s;return o(this,(function(o){switch(o.label){case 0:n=JSON.stringify(e),r=this.prefix+":"+t,o.label=1;case 1:return o.trys.push([1,3,,4]),[4,i.default.setItem(r,n)];case 2:return o.sent(),[3,4];case 3:return s=o.sent(),console.error(s),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t){return r(this,void 0,void 0,(function(){var e,n,r;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.prefix+":"+t,[4,i.default.getItem(e)];case 1:return[2,(n=o.sent())?JSON.parse(n):void 0];case 2:return r=o.sent(),console.error(r),[3,3];case 3:return[2]}}))}))},t}();e.default=s}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{FlagProvider:()=>i,default:()=>u,useFlag:()=>s,useUnleashContext:()=>c,useVariant:()=>a});const t=require("react"),e=n.n(t)().createContext(null);var o=n(9);const i=function(n){var r=n.config,i=n.children,s=new o.UnleashClient(r);s.start();var a={updateContext:function(t){s&&s.updateContext(t)},isEnabled:function(t){if(s)return s.isEnabled(t)},getVariant:function(t){if(s)return s.getVariant(t)},client:s};return t.createElement(e.Provider,{value:a},i)},s=function(n){var r=(0,t.useContext)(e),o=r.isEnabled,i=r.client,s=(0,t.useState)(o(n)),a=s[0],c=s[1];return(0,t.useEffect)((function(){i&&(i.on("update",(function(){var t=o(n);t!==a&&c(t)})),i.on("ready",(function(){var t=o(n);c(t)})))}),[i]),a},a=function(n){var r=(0,t.useContext)(e),o=r.getVariant,i=r.client,s=(0,t.useState)(o(n)),a=s[0],c=s[1],u=(0,t.useRef)();return u.current=a,(0,t.useEffect)((function(){i&&(i.on("update",(function(){var t=o(n);u.current.name===t.name&&u.current.enabled===t.enabled||c(t)})),i.on("ready",(function(){var t=o(n);c(t)})))}),[i]),a},c=function(){return(0,t.useContext)(e).updateContext},u=i})(),module.exports=r})();
(()=>{var t={560:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>u,useAsyncStorage:()=>c});var r=n(178),o=n.n(r);const i=(t,e)=>new Promise(((n,r)=>{try{const r=t();e&&e(null,r),n(r)}catch(t){e&&e(t),r(t)}})),s=(t,e,n)=>Promise.all(t).then((t=>{const r=n?n(t):null;return e&&e(null,r),Promise.resolve(r)}),(t=>(e&&e(t),Promise.reject(t))));class a{static getItem(t,e){return i((()=>window.localStorage.getItem(t)),e)}static setItem(t,e,n){return i((()=>{window.localStorage.setItem(t,e)}),n)}static removeItem(t,e){return i((()=>window.localStorage.removeItem(t)),e)}static mergeItem(t,e,n){return i((()=>{((t,e)=>{const n=window.localStorage.getItem(t),r=JSON.parse(n),i=JSON.parse(e),s=JSON.stringify(o()({},r,i));window.localStorage.setItem(t,s)})(t,e)}),n)}static clear(t){return i((()=>{window.localStorage.clear()}),t)}static getAllKeys(t){return i((()=>{const t=window.localStorage.length,e=[];for(let n=0;n<t;n+=1){const t=window.localStorage.key(n);e.push(t)}return e}),t)}static flushGetRequests(){}static multiGet(t,e){const n=t.map((t=>a.getItem(t)));return s(n,e,(e=>e.map(((e,n)=>[t[n],e]))))}static multiSet(t,e){const n=t.map((t=>a.setItem(t[0],t[1])));return s(n,e)}static multiRemove(t,e){const n=t.map((t=>a.removeItem(t)));return s(n,e)}static multiMerge(t,e){const n=t.map((t=>a.mergeItem(t[0],t[1])));return s(n,e)}}function c(t){return{getItem:(...e)=>a.getItem(t,...e),setItem:(...e)=>a.setItem(t,...e),mergeItem:(...e)=>a.mergeItem(t,...e),removeItem:(...e)=>a.removeItem(t,...e)}}const u=a},178:(t,e,n)=>{"use strict";var r=n(290),o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;function s(t){if(null==t)throw new TypeError("Sources cannot be null or undefined");return Object(t)}function a(t,e,n){var i=e[n];if(null!=i){if(o.call(t,n)&&(void 0===t[n]||null===t[n]))throw new TypeError("Cannot convert undefined or null to object ("+n+")");o.call(t,n)&&r(i)?t[n]=c(Object(t[n]),e[n]):t[n]=i}}function c(t,e){if(t===e)return t;for(var n in e=Object(e))o.call(e,n)&&a(t,e,n);if(Object.getOwnPropertySymbols)for(var r=Object.getOwnPropertySymbols(e),s=0;s<r.length;s++)i.call(e,r[s])&&a(t,e,r[s]);return t}t.exports=function(t){t=s(t);for(var e=1;e<arguments.length;e++)c(t,arguments[e]);return t}},290:t=>{"use strict";t.exports=function(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}},279:t=>{function e(){}e.prototype={on:function(t,e,n){var r=this.e||(this.e={});return(r[t]||(r[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){var r=this;function o(){r.off(t,o),e.apply(n,arguments)}return o._=e,this.on(t,o,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),r=0,o=n.length;r<o;r++)n[r].fn.apply(n[r].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),r=n[t],o=[];if(r&&e)for(var i=0,s=r.length;i<s;i++)r[i].fn!==e&&r[i].fn._!==e&&o.push(r[i]);return o.length?n[t]=o:delete n[t],this}},t.exports=e,t.exports.TinyEmitter=e},9:function(t,e,n){"use strict";var r,o=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},function(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),i=this&&this.__assign||function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},s=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},a=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.UnleashClient=e.EVENTS=void 0;var c=n(279),u=n(524),l=n(432);e.EVENTS={READY:"ready",UPDATE:"update"};var f={name:"disabled"},h=function(t){function n(e){var n=e.storageProvider,r=e.url,o=e.clientKey,s=e.refreshInterval,a=void 0===s?30:s,c=e.metricsInterval,f=void 0===c?30:c,h=e.disableMetrics,p=void 0!==h&&h,d=e.appName,v=e.environment,y=void 0===v?"default":v,m=e.context,b=t.call(this)||this;if(b.toggles=[],b.etag="",!r)throw new Error("url is required");if(!o)throw new Error("clientKey is required");if(!d)throw new Error("appName is required.");return b.url=new URL(""+r),b.clientKey=o,b.storage=n||new l.default,b.refreshInterval=1e3*a,b.context=i({appName:d,environment:y},m),b.metrics=new u.default({appName:d,metricsInterval:f,disableMetrics:p,url:r,clientKey:o}),b}return o(n,t),n.prototype.isEnabled=function(t){var e=this.toggles.find((function(e){return e.name===t})),n=!!e&&e.enabled;return this.metrics.count(t,n),n},n.prototype.getVariant=function(t){var e=this.toggles.find((function(e){return e.name===t}));return e?(this.metrics.count(t,!0),e.variant):(this.metrics.count(t,!1),f)},n.prototype.updateContext=function(t){(t.appName||t.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext.");var e={environment:this.context.environment,appName:this.context.appName};this.context=i(i({},e),t),this.timerRef&&this.fetchToggles()},n.prototype.start=function(){return s(this,void 0,void 0,(function(){var t,n=this;return a(this,(function(r){switch(r.label){case 0:return"fetch"in window?(this.stop(),t=this.refreshInterval,[4,this.fetchToggles()]):[3,2];case 1:return r.sent(),this.emit(e.EVENTS.READY),this.timerRef=setInterval((function(){return n.fetchToggles()}),t),[3,3];case 2:console.error("Unleash: Client does not support fetch."),r.label=3;case 3:return[2]}}))}))},n.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0)},n.prototype.storeToggles=function(t){return s(this,void 0,void 0,(function(){return a(this,(function(n){return this.toggles=t,this.emit(e.EVENTS.UPDATE),this.storage.save("repo",t),[2]}))}))},n.prototype.fetchToggles=function(){return s(this,void 0,void 0,(function(){var t,e,n,r,o;return a(this,(function(i){switch(i.label){case 0:if(!fetch)return[3,7];i.label=1;case 1:return i.trys.push([1,6,,7]),t=this.context,e=new URL(this.url.toString()),Object.entries(t).forEach((function(t){var n=t[0],r=t[1];"properties"===n&&r?Object.entries(r).forEach((function(t){var n=t[0],r=t[1];return e.searchParams.append("properties["+n+"]",r)})):e.searchParams.append(n,r)})),[4,fetch(e.toString(),{cache:"no-cache",headers:{Authorization:this.clientKey,Accept:"application/json","Content-Type":"application/json","If-None-Match":this.etag}})];case 2:return(n=i.sent()).ok&&304!==n.status?(this.etag=n.headers.get("ETag")||"",[4,n.json()]):[3,5];case 3:return r=i.sent(),[4,this.storeToggles(r.toggles)];case 4:i.sent(),i.label=5;case 5:return[3,7];case 6:return o=i.sent(),console.error("Unleash: unable to fetch feature toggles",o),[3,7];case 7:return[2]}}))}))},n}(c.TinyEmitter);e.UnleashClient=h},524:function(t,e){"use strict";var n=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},r=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var o=function(){function t(t){var e=t.appName,n=t.metricsInterval,r=t.disableMetrics,o=void 0!==r&&r,i=t.url,s=t.clientKey;this.disabled=o,this.metricsInterval=1e3*n,this.appName=e,this.url=i,this.started=new Date,this.clientKey=s,this.resetBucket(),"number"==typeof this.metricsInterval&&this.metricsInterval>0&&this.startTimer(2e3)}return t.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer),this.disabled=!0},t.prototype.sendMetrics=function(){return n(this,void 0,void 0,(function(){var t,e;return r(this,(function(n){switch(n.label){case 0:return this.disabled?[2,!1]:this.bucketIsEmpty()?(this.resetBucket(),this.startTimer(),[2,!0]):(t=this.url+"/client/metrics",e=this.getPayload(),[4,fetch(t,{cache:"no-cache",method:"POST",headers:{Authorization:this.clientKey,Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)})]);case 1:return n.sent(),[2,!0]}}))}))},t.prototype.count=function(t,e){return!(this.disabled||!this.bucket||(this.assertBucket(t),this.bucket.toggles[t][e?"yes":"no"]++,0))},t.prototype.assertBucket=function(t){if(this.disabled||!this.bucket)return!1;this.bucket.toggles[t]||(this.bucket.toggles[t]={yes:0,no:0})},t.prototype.startTimer=function(t){var e=this;return!this.disabled&&(this.timer=setTimeout((function(){e.sendMetrics()}),t||this.metricsInterval),!0)},t.prototype.bucketIsEmpty=function(){return!!this.bucket&&0===Object.keys(this.bucket.toggles).length},t.prototype.resetBucket=function(){var t={start:new Date,stop:null,toggles:{}};this.bucket=t},t.prototype.closeBucket=function(){this.bucket&&(this.bucket.stop=new Date)},t.prototype.getPayload=function(){this.closeBucket();var t=this.getMetricsData();return this.resetBucket(),t},t.prototype.getMetricsData=function(){return{appName:this.appName,instanceId:"browser",bucket:this.bucket}},t}();e.default=o},432:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(e,"__esModule",{value:!0});var i=n(560),s=function(){function t(){this.prefix="unleash:repository"}return t.prototype.save=function(t,e){return r(this,void 0,void 0,(function(){var n,r,s;return o(this,(function(o){switch(o.label){case 0:n=JSON.stringify(e),r=this.prefix+":"+t,o.label=1;case 1:return o.trys.push([1,3,,4]),[4,i.default.setItem(r,n)];case 2:return o.sent(),[3,4];case 3:return s=o.sent(),console.error(s),[3,4];case 4:return[2]}}))}))},t.prototype.get=function(t){return r(this,void 0,void 0,(function(){var e,n,r;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),e=this.prefix+":"+t,[4,i.default.getItem(e)];case 1:return[2,(n=o.sent())?JSON.parse(n):void 0];case 2:return r=o.sent(),console.error(r),[3,3];case 3:return[2]}}))}))},t}();e.default=s}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{FlagProvider:()=>i,default:()=>u,useFlag:()=>s,useUnleashContext:()=>c,useVariant:()=>a});const t=require("react"),e=n.n(t)().createContext(null);var o=n(9);const i=function(n){var r=n.config,i=n.children,s=t.useState(null),a=s[0],c=s[1];t.useEffect((function(){var t=new o.UnleashClient(r);t.start(),c(t)}),[]);var u={updateContext:function(t){a&&a.updateContext(t)},isEnabled:function(t){if(a)return a.isEnabled(t)},getVariant:function(t){if(a)return a.getVariant(t)},client:a};return t.createElement(e.Provider,{value:u},i)},s=function(n){var r=(0,t.useContext)(e),o=r.isEnabled,i=r.client,s=(0,t.useState)(!!o(n)),a=s[0],c=s[1],u=(0,t.useRef)();return u.current=a,(0,t.useEffect)((function(){i&&(i.on("update",(function(){var t=o(n);t!==u.current&&(u.current=t,c(!!t))})),i.on("ready",(function(){var t=o(n);c(t)})))}),[i]),a},a=function(n){var r=(0,t.useContext)(e),o=r.getVariant,i=r.client,s=(0,t.useState)(o(n)),a=s[0],c=s[1],u=(0,t.useRef)();return u.current=a,(0,t.useEffect)((function(){i&&(i.on("update",(function(){var t=o(n);u.current.name===t.name&&u.current.enabled===t.enabled||c(t)})),i.on("ready",(function(){var t=o(n);c(t)})))}),[i]),a},c=function(){return(0,t.useContext)(e).updateContext},u=i})(),module.exports=r})();

@@ -1,2 +0,2 @@

declare const useFlag: (name: string) => any;
declare const useFlag: (name: string) => boolean;
export default useFlag;
{
"name": "@unleash/proxy-client-react",
"version": "0.0.5",
"version": "0.0.6",
"description": "React interface for working with unleash",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc