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

unleash-proxy-client

Package Overview
Dependencies
Maintainers
3
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unleash-proxy-client - npm Package Compare versions

Comparing version 2.4.0-beta.0 to 2.4.0-beta.1

2

build/main.min.js

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

(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.unleash={}))})(this,function(a){"use strict";function b(a,c){function b(){this.constructor=a}if("function"!=typeof c&&null!==c)throw new TypeError("Class extends value "+(c+"")+" is not a constructor or null");k(a,c),a.prototype=null===c?Object.create(c):(b.prototype=c.prototype,new b)}function c(a,b,c,d){function e(a){return a instanceof c?a:new c(function(b){b(a)})}return new(c||(c=Promise))(function(c,f){function g(a){try{i(d.next(a))}catch(a){f(a)}}function h(a){try{i(d["throw"](a))}catch(a){f(a)}}function i(a){a.done?c(a.value):e(a.value).then(g,h)}i((d=d.apply(a,b||[])).next())})}function d(a,b){function c(a){return function(b){return d([a,b])}}function d(c){if(e)throw new TypeError("Generator is already executing.");for(;k;)try{if(e=1,h&&(i=2&c[0]?h["return"]:c[0]?h["throw"]||((i=h["return"])&&i.call(h),0):h.next)&&!(i=i.call(h,c[1])).done)return i;switch((h=0,i)&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return k.label++,{value:c[1],done:!1};case 5:k.label++,h=c[1],c=[0];continue;case 7:c=k.ops.pop(),k.trys.pop();continue;default:if((i=k.trys,!(i=0<i.length&&i[i.length-1]))&&(6===c[0]||2===c[0])){k=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){k.label=c[1];break}if(6===c[0]&&k.label<i[1]){k.label=i[1],i=c;break}if(i&&k.label<i[2]){k.label=i[2],k.ops.push(c);break}i[2]&&k.ops.pop(),k.trys.pop();continue;}c=b.call(a,k)}catch(a){c=[6,a],h=0}finally{e=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}var e,h,i,j,k={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return j={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(j[Symbol.iterator]=function(){return this}),j}function e(a,b,c){if(c||2===arguments.length)for(var d,e=0,f=b.length;e<f;e++)(d||!(e in b))&&(d||(d=Array.prototype.slice.call(b,0,e)),d[e]=b[e]);return a.concat(d||Array.prototype.slice.call(b))}function f(){}function g(){return s>r.length-16&&(q.randomFillSync(r),s=0),r.slice(s,s+=16)}function h(a){return"string"==typeof a&&t.test(a)}function i(a,b=0){const c=(u[a[b+0]]+u[a[b+1]]+u[a[b+2]]+u[a[b+3]]+"-"+u[a[b+4]]+u[a[b+5]]+"-"+u[a[b+6]]+u[a[b+7]]+"-"+u[a[b+8]]+u[a[b+9]]+"-"+u[a[b+10]]+u[a[b+11]]+u[a[b+12]]+u[a[b+13]]+u[a[b+14]]+u[a[b+15]]).toLowerCase();if(!h(c))throw TypeError("Stringified UUID is invalid");return c}function j(a,b,c){a=a||{};const d=a.random||(a.rng||g)();if(d[6]=64|15&d[6],d[8]=128|63&d[8],b){c=c||0;for(let a=0;16>a;++a)b[c+a]=d[a];return b}return i(d)}var k=function(a,c){return k=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var b in c)Object.prototype.hasOwnProperty.call(c,b)&&(a[b]=c[b])},k(a,c)},l=function(){return l=Object.assign||function(a){for(var b,c=1,d=arguments.length;c<d;c++)for(var e in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,e)&&(a[e]=b[e]);return a},l.apply(this,arguments)};f.prototype={on:function(a,b,c){var d=this.e||(this.e={});return(d[a]||(d[a]=[])).push({fn:b,ctx:c}),this},once:function(a,b,c){function d(){e.off(a,d),b.apply(c,arguments)}var e=this;return d._=b,this.on(a,d,c)},emit:function(a){var b=[].slice.call(arguments,1),c=((this.e||(this.e={}))[a]||[]).slice(),d=0,e=c.length;for(d;d<e;d++)c[d].fn.apply(c[d].ctx,b);return this},off:function(a,b){var c=this.e||(this.e={}),d=c[a],e=[];if(d&&b)for(var f=0,g=d.length;f<g;f++)d[f].fn!==b&&d[f].fn._!==b&&e.push(d[f]);return e.length?c[a]=e:delete c[a],this}};var m=f;f.TinyEmitter=m;var n=function(){function a(a){var b=a.onError,c=a.appName,d=a.metricsInterval,e=a.disableMetrics,f=a.url,g=a.clientKey,h=a.fetch,i=a.headerName;this.onError=b,this.disabled=void 0!==e&&e,this.metricsInterval=1e3*d,this.appName=c,this.url=f instanceof URL?f:new URL(f),this.clientKey=g,this.bucket=this.createEmptyBucket(),this.fetch=h,this.headerName=i}return a.prototype.start=function(){var a=this;return!this.disabled&&void("number"==typeof this.metricsInterval&&0<this.metricsInterval&&setTimeout(function(){a.startTimer(),a.sendMetrics()},2e3))},a.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},a.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},a.prototype.sendMetrics=function(){return c(this,void 0,void 0,function(){var a,b,c,e;return d(this,function(d){switch(d.label){case 0:if(a="".concat(this.url,"/client/metrics"),b=this.getPayload(),this.bucketIsEmpty(b))return[2];d.label=1;case 1:return d.trys.push([1,3,,4]),[4,this.fetch(a,{cache:"no-cache",method:"POST",headers:(e={},e[this.headerName]=this.clientKey,e.Accept="application/json",e["Content-Type"]="application/json",e),body:JSON.stringify(b)})];case 2:return d.sent(),[3,4];case 3:return c=d.sent(),console.error("Unleash: unable to send feature metrics",c),this.onError(c),[3,4];case 4:return[2];}})})},a.prototype.count=function(a,b){return!this.disabled&&this.bucket&&(this.assertBucket(a),this.bucket.toggles[a][b?"yes":"no"]++,!0)},a.prototype.assertBucket=function(a){return!this.disabled&&this.bucket&&void(!this.bucket.toggles[a]&&(this.bucket.toggles[a]={yes:0,no:0}))},a.prototype.startTimer=function(){var a=this;this.timer=setInterval(function(){a.sendMetrics()},this.metricsInterval)},a.prototype.bucketIsEmpty=function(a){return 0===Object.keys(a.bucket.toggles).length},a.prototype.getPayload=function(){var a=l(l({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:a,appName:this.appName,instanceId:"browser"}},a}(),o=function(){function a(){this.store=new Map}return a.prototype.save=function(a,b){return c(this,void 0,void 0,function(){return d(this,function(){return this.store.set(a,b),[2]})})},a.prototype.get=function(a){return c(this,void 0,void 0,function(){return d(this,function(){return[2,this.store.get(a)]})})},a}(),p=function(){function a(){this.prefix="unleash:repository"}return a.prototype.save=function(a,b){return c(this,void 0,void 0,function(){var c,e;return d(this,function(){c=JSON.stringify(b),e="".concat(this.prefix,":").concat(a);try{window.localStorage.setItem(e,c)}catch(a){console.error(a)}return[2]})})},a.prototype.get=function(a){try{var b="".concat(this.prefix,":").concat(a),c=window.localStorage.getItem(b);return c?JSON.parse(c):void 0}catch(a){console.error(a)}},a}(),q={};const r=new Uint8Array(256);let s=r.length;var t=/^(?:[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;const u=[];for(let b=0;256>b;++b)u.push((b+256).toString(16).substr(1));var v=function(){function a(){}return a.prototype.generateEventId=function(){return j()},a.prototype.createImpressionEvent=function(a,b,c,d,e,f){var g=this.createBaseEvent(a,b,c,d,e);return f?l(l({},g),{variant:f}):g},a.prototype.createBaseEvent=function(a,b,c,d,e){return{eventType:d,eventId:this.generateEventId(),context:a,enabled:b,featureName:c,impressionData:e}},a}(),w=function(a){var b=a[1];return b!==void 0&&null!==b},x=function(a,b){var c=new URL(a.toString());return Object.entries(b).filter(w).forEach(function(a){var b=a[0],d=a[1];"properties"===b&&d?Object.entries(d).filter(w).forEach(function(a){var b=a[0],d=a[1];return c.searchParams.append("properties[".concat(b,"]"),d)}):c.searchParams.append(b,d)}),c},y=["userId","sessionId","remoteAddress"],z={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression"},A={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},B={name:"disabled",enabled:!1},C="repo",D=function(){try{if("fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(a){console.error("Unleash failed to resolve \"fetch\"",a)}},E=function(a){function f(b){var c=b.storageProvider,d=b.url,e=b.clientKey,f=b.disableRefresh,g=b.refreshInterval,h=void 0===g?30:g,i=b.metricsInterval,j=void 0===i?30:i,k=b.disableMetrics,m=b.appName,o=b.environment,q=void 0===o?"default":o,r=b.context,s=b.fetch,t=void 0===s?D():s,u=b.bootstrap,w=b.bootstrapOverride,x=b.headerName,y=void 0===x?"Authorization":x,A=b.customHeaders,B=void 0===A?{}:A,C=b.impressionDataAll,E=b.usePOSTrequests,F=a.call(this)||this;if(F.toggles=[],F.etag="",F.readyEventEmitted=!1,F.usePOSTrequests=!1,!d)throw new Error("url is required");if(!e)throw new Error("clientKey is required");if(!m)throw new Error("appName is required.");return F.eventsHandler=new v,F.impressionDataAll=void 0!==C&&C,F.toggles=u&&0<u.length?u:[],F.url=d instanceof URL?d:new URL(d),F.clientKey=e,F.headerName=y,F.customHeaders=B,F.storage=c||new p,F.refreshInterval=void 0!==f&&f?0:1e3*h,F.context=l({appName:m,environment:q},r),F.usePOSTrequests=void 0!==E&&E,F.ready=new Promise(function(a){F.init().then(a).catch(function(b){console.error(b),F.emit(z.ERROR,b),a()})}),t||console.error("Unleash: You must either provide your own \"fetch\" implementation or run in an environment where \"fetch\" is available."),F.fetch=t,F.bootstrap=u&&0<u.length?u:void 0,F.bootstrapOverride=void 0===w||w,F.metrics=new n({onError:F.emit.bind(F,z.ERROR),appName:m,metricsInterval:j,disableMetrics:void 0!==k&&k,url:F.url,clientKey:e,fetch:t,headerName:y}),F}return b(f,a),f.prototype.getAllToggles=function(){return e([],this.toggles,!0)},f.prototype.isEnabled=function(a){var b,c=this.toggles.find(function(b){return b.name===a}),d=!!c&&c.enabled;if(this.metrics.count(a,d),(null===c||void 0===c?void 0:c.impressionData)||this.impressionDataAll){var e=this.eventsHandler.createImpressionEvent(this.context,d,a,A.IS_ENABLED,null!==(b=null===c||void 0===c?void 0:c.impressionData)&&void 0!==b?b:void 0);this.emit(z.IMPRESSION,e)}return d},f.prototype.getVariant=function(a){var b,c=this.toggles.find(function(b){return b.name===a}),d=(null===c||void 0===c?void 0:c.enabled)||!1,e=c?c.variant:B;if(this.metrics.count(a,!0),(null===c||void 0===c?void 0:c.impressionData)||this.impressionDataAll){var f=this.eventsHandler.createImpressionEvent(this.context,d,a,A.GET_VARIANT,null!==(b=null===c||void 0===c?void 0:c.impressionData)&&void 0!==b?b:void 0,e.name);this.emit(z.IMPRESSION,f)}return e},f.prototype.updateContext=function(a){return c(this,void 0,void 0,function(){var b;return d(this,function(c){switch(c.label){case 0:return(a.appName||a.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),b={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=l(l({},b),a),this.timerRef?[4,this.fetchToggles()]:[3,2];case 1:c.sent(),c.label=2;case 2:return[2];}})})},f.prototype.getContext=function(){return l({},this.context)},f.prototype.setContextField=function(a,b){var c,d;if(y.includes(a))this.context=l(l({},this.context),(c={},c[a]=b,c));else{var e=l(l({},this.context.properties),(d={},d[a]=b,d));this.context=l(l({},this.context),{properties:e})}this.timerRef&&this.fetchToggles()},f.prototype.init=function(){return c(this,void 0,void 0,function(){var a,b;return d(this,function(c){switch(c.label){case 0:return[4,this.resolveSessionId()];case 1:return a=c.sent(),this.context=l({sessionId:a},this.context),b=this,[4,this.storage.get(C)];case 2:return b.toggles=c.sent()||[],this.bootstrap&&(this.bootstrapOverride||0===this.toggles.length)?[4,this.storage.save(C,this.bootstrap)]:[3,4];case 3:c.sent(),this.toggles=this.bootstrap,this.emit(z.READY),c.label=4;case 4:return this.emit(z.INIT),[2];}})})},f.prototype.start=function(){return c(this,void 0,void 0,function(){var a,b=this;return d(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(),a=this.refreshInterval,[4,this.fetchToggles()];case 2:return c.sent(),0<a&&(this.timerRef=setInterval(function(){return b.fetchToggles()},a)),[2];}})})},f.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},f.prototype.resolveSessionId=function(){return c(this,void 0,void 0,function(){var a;return d(this,function(b){var c=Math.floor;switch(b.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return(a=b.sent(),!!a)?[3,4]:(a=c(1e9*Math.random()),[4,this.storage.save("sessionId",a)]);case 3:b.sent(),b.label=4;case 4:return[2,a];}})})},f.prototype.getHeaders=function(){var a,b=(a={},a[this.headerName]=this.clientKey,a.Accept="application/json",a["Content-Type"]="application/json",a["If-None-Match"]=this.etag,a);return Object.entries(this.customHeaders).filter(w).forEach(function(a){var c=a[0],d=a[1];return b[c]=d}),b},f.prototype.storeToggles=function(a){return c(this,void 0,void 0,function(){return d(this,function(b){switch(b.label){case 0:return this.toggles=a,this.emit(z.UPDATE),[4,this.storage.save(C,a)];case 1:return b.sent(),[2];}})})},f.prototype.fetchToggles=function(){return c(this,void 0,void 0,function(){var a,b,c,e,f,g,h;return d(this,function(d){switch(d.label){case 0:if(!this.fetch)return[3,8];d.label=1;case 1:return d.trys.push([1,7,,8]),a=this.usePOSTrequests,b=a?this.url:x(this.url,this.context),c=a?"POST":"GET",e=a?JSON.stringify({context:this.context}):void 0,[4,this.fetch(b.toString(),{method:c,cache:"no-cache",headers:this.getHeaders(),body:e})];case 2:return(f=d.sent(),!(f.ok&&304!==f.status))?[3,5]:(this.etag=f.headers.get("ETag")||"",[4,f.json()]);case 3:return g=d.sent(),[4,this.storeToggles(g.toggles)];case 4:return d.sent(),this.bootstrap||this.readyEventEmitted||(this.emit(z.READY),this.readyEventEmitted=!0),[3,6];case 5:f.ok||304===f.status||(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.emit(z.ERROR,{type:"HttpError",code:f.status})),d.label=6;case 6:return[3,8];case 7:return h=d.sent(),console.error("Unleash: unable to fetch feature toggles",h),this.emit(z.ERROR,h),[3,8];case 8:return[2];}})})},f}(m);a.EVENTS=z,a.InMemoryStorageProvider=o,a.LocalStorageProvider=p,a.UnleashClient=E,a.resolveFetch=D,Object.defineProperty(a,"__esModule",{value:!0})});
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.unleash={}))})(this,function(a){"use strict";function b(a,c){function b(){this.constructor=a}if("function"!=typeof c&&null!==c)throw new TypeError("Class extends value "+(c+"")+" is not a constructor or null");l(a,c),a.prototype=null===c?Object.create(c):(b.prototype=c.prototype,new b)}function c(a,b,c,d){function e(a){return a instanceof c?a:new c(function(b){b(a)})}return new(c||(c=Promise))(function(c,f){function g(a){try{i(d.next(a))}catch(a){f(a)}}function h(a){try{i(d["throw"](a))}catch(a){f(a)}}function i(a){a.done?c(a.value):e(a.value).then(g,h)}i((d=d.apply(a,b||[])).next())})}function d(a,b){function c(a){return function(b){return d([a,b])}}function d(c){if(e)throw new TypeError("Generator is already executing.");for(;k;)try{if(e=1,h&&(i=2&c[0]?h["return"]:c[0]?h["throw"]||((i=h["return"])&&i.call(h),0):h.next)&&!(i=i.call(h,c[1])).done)return i;switch((h=0,i)&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return k.label++,{value:c[1],done:!1};case 5:k.label++,h=c[1],c=[0];continue;case 7:c=k.ops.pop(),k.trys.pop();continue;default:if((i=k.trys,!(i=0<i.length&&i[i.length-1]))&&(6===c[0]||2===c[0])){k=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){k.label=c[1];break}if(6===c[0]&&k.label<i[1]){k.label=i[1],i=c;break}if(i&&k.label<i[2]){k.label=i[2],k.ops.push(c);break}i[2]&&k.ops.pop(),k.trys.pop();continue;}c=b.call(a,k)}catch(a){c=[6,a],h=0}finally{e=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}var e,h,i,j,k={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return j={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(j[Symbol.iterator]=function(){return this}),j}function e(a,b,c){if(c||2===arguments.length)for(var d,e=0,f=b.length;e<f;e++)(d||!(e in b))&&(d||(d=Array.prototype.slice.call(b,0,e)),d[e]=b[e]);return a.concat(d||Array.prototype.slice.call(b))}function f(){}function g(){if(!o&&(o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),!o))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return o(s)}function h(a){return"string"==typeof a&&t.test(a)}function j(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0,c=(u[a[b+0]]+u[a[b+1]]+u[a[b+2]]+u[a[b+3]]+"-"+u[a[b+4]]+u[a[b+5]]+"-"+u[a[b+6]]+u[a[b+7]]+"-"+u[a[b+8]]+u[a[b+9]]+"-"+u[a[b+10]]+u[a[b+11]]+u[a[b+12]]+u[a[b+13]]+u[a[b+14]]+u[a[b+15]]).toLowerCase();if(!h(c))throw TypeError("Stringified UUID is invalid");return c}function k(a,b,c){a=a||{};var d=a.random||(a.rng||g)();if(d[6]=64|15&d[6],d[8]=128|63&d[8],b){c=c||0;for(var e=0;16>e;++e)b[c+e]=d[e];return b}return j(d)}var l=function(a,c){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var b in c)Object.prototype.hasOwnProperty.call(c,b)&&(a[b]=c[b])},l(a,c)},m=function(){return m=Object.assign||function(a){for(var b,c=1,d=arguments.length;c<d;c++)for(var e in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,e)&&(a[e]=b[e]);return a},m.apply(this,arguments)};f.prototype={on:function(a,b,c){var d=this.e||(this.e={});return(d[a]||(d[a]=[])).push({fn:b,ctx:c}),this},once:function(a,b,c){function d(){e.off(a,d),b.apply(c,arguments)}var e=this;return d._=b,this.on(a,d,c)},emit:function(a){var b=[].slice.call(arguments,1),c=((this.e||(this.e={}))[a]||[]).slice(),d=0,e=c.length;for(d;d<e;d++)c[d].fn.apply(c[d].ctx,b);return this},off:function(a,b){var c=this.e||(this.e={}),d=c[a],e=[];if(d&&b)for(var f=0,g=d.length;f<g;f++)d[f].fn!==b&&d[f].fn._!==b&&e.push(d[f]);return e.length?c[a]=e:delete c[a],this}};var n=f;f.TinyEmitter=n;for(var o,p=function(){function a(a){var b=a.onError,c=a.appName,d=a.metricsInterval,e=a.disableMetrics,f=a.url,g=a.clientKey,h=a.fetch,i=a.headerName;this.onError=b,this.disabled=void 0!==e&&e,this.metricsInterval=1e3*d,this.appName=c,this.url=f instanceof URL?f:new URL(f),this.clientKey=g,this.bucket=this.createEmptyBucket(),this.fetch=h,this.headerName=i}return a.prototype.start=function(){var a=this;return!this.disabled&&void("number"==typeof this.metricsInterval&&0<this.metricsInterval&&setTimeout(function(){a.startTimer(),a.sendMetrics()},2e3))},a.prototype.stop=function(){this.timer&&(clearTimeout(this.timer),delete this.timer)},a.prototype.createEmptyBucket=function(){return{start:new Date,stop:null,toggles:{}}},a.prototype.sendMetrics=function(){return c(this,void 0,void 0,function(){var a,b,c,e;return d(this,function(d){switch(d.label){case 0:if(a="".concat(this.url,"/client/metrics"),b=this.getPayload(),this.bucketIsEmpty(b))return[2];d.label=1;case 1:return d.trys.push([1,3,,4]),[4,this.fetch(a,{cache:"no-cache",method:"POST",headers:(e={},e[this.headerName]=this.clientKey,e.Accept="application/json",e["Content-Type"]="application/json",e),body:JSON.stringify(b)})];case 2:return d.sent(),[3,4];case 3:return c=d.sent(),console.error("Unleash: unable to send feature metrics",c),this.onError(c),[3,4];case 4:return[2];}})})},a.prototype.count=function(a,b){return!this.disabled&&this.bucket&&(this.assertBucket(a),this.bucket.toggles[a][b?"yes":"no"]++,!0)},a.prototype.assertBucket=function(a){return!this.disabled&&this.bucket&&void(!this.bucket.toggles[a]&&(this.bucket.toggles[a]={yes:0,no:0}))},a.prototype.startTimer=function(){var a=this;this.timer=setInterval(function(){a.sendMetrics()},this.metricsInterval)},a.prototype.bucketIsEmpty=function(a){return 0===Object.keys(a.bucket.toggles).length},a.prototype.getPayload=function(){var a=m(m({},this.bucket),{stop:new Date});return this.bucket=this.createEmptyBucket(),{bucket:a,appName:this.appName,instanceId:"browser"}},a}(),q=function(){function a(){this.store=new Map}return a.prototype.save=function(a,b){return c(this,void 0,void 0,function(){return d(this,function(){return this.store.set(a,b),[2]})})},a.prototype.get=function(a){return c(this,void 0,void 0,function(){return d(this,function(){return[2,this.store.get(a)]})})},a}(),r=function(){function a(){this.prefix="unleash:repository"}return a.prototype.save=function(a,b){return c(this,void 0,void 0,function(){var c,e;return d(this,function(){c=JSON.stringify(b),e="".concat(this.prefix,":").concat(a);try{window.localStorage.setItem(e,c)}catch(a){console.error(a)}return[2]})})},a.prototype.get=function(a){try{var b="".concat(this.prefix,":").concat(a),c=window.localStorage.getItem(b);return c?JSON.parse(c):void 0}catch(a){console.error(a)}},a}(),s=new Uint8Array(16),t=/^(?:[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,u=[],v=0;256>v;++v)u.push((v+256).toString(16).substr(1));var w=function(){function a(){}return a.prototype.generateEventId=function(){return k()},a.prototype.createImpressionEvent=function(a,b,c,d,e,f){var g=this.createBaseEvent(a,b,c,d,e);return f?m(m({},g),{variant:f}):g},a.prototype.createBaseEvent=function(a,b,c,d,e){return{eventType:d,eventId:this.generateEventId(),context:a,enabled:b,featureName:c,impressionData:e}},a}(),x=function(a){var b=a[1];return b!==void 0&&null!==b},y=function(a,b){var c=new URL(a.toString());return Object.entries(b).filter(x).forEach(function(a){var b=a[0],d=a[1];"properties"===b&&d?Object.entries(d).filter(x).forEach(function(a){var b=a[0],d=a[1];return c.searchParams.append("properties[".concat(b,"]"),d)}):c.searchParams.append(b,d)}),c},z=["userId","sessionId","remoteAddress"],A={INIT:"initialized",ERROR:"error",READY:"ready",UPDATE:"update",IMPRESSION:"impression"},B={IS_ENABLED:"isEnabled",GET_VARIANT:"getVariant"},C={name:"disabled",enabled:!1},D="repo",E=function(){try{if("fetch"in window)return fetch.bind(window);if("fetch"in globalThis)return fetch.bind(globalThis)}catch(a){console.error("Unleash failed to resolve \"fetch\"",a)}},F=function(a){function f(b){var c=b.storageProvider,d=b.url,e=b.clientKey,f=b.disableRefresh,g=b.refreshInterval,h=void 0===g?30:g,i=b.metricsInterval,j=void 0===i?30:i,k=b.disableMetrics,l=b.appName,n=b.environment,o=void 0===n?"default":n,q=b.context,s=b.fetch,t=void 0===s?E():s,u=b.bootstrap,v=b.bootstrapOverride,x=b.headerName,y=void 0===x?"Authorization":x,z=b.customHeaders,B=void 0===z?{}:z,C=b.impressionDataAll,D=b.usePOSTrequests,F=a.call(this)||this;if(F.toggles=[],F.etag="",F.readyEventEmitted=!1,F.usePOSTrequests=!1,!d)throw new Error("url is required");if(!e)throw new Error("clientKey is required");if(!l)throw new Error("appName is required.");return F.eventsHandler=new w,F.impressionDataAll=void 0!==C&&C,F.toggles=u&&0<u.length?u:[],F.url=d instanceof URL?d:new URL(d),F.clientKey=e,F.headerName=y,F.customHeaders=B,F.storage=c||new r,F.refreshInterval=void 0!==f&&f?0:1e3*h,F.context=m({appName:l,environment:o},q),F.usePOSTrequests=void 0!==D&&D,F.ready=new Promise(function(a){F.init().then(a).catch(function(b){console.error(b),F.emit(A.ERROR,b),a()})}),t||console.error("Unleash: You must either provide your own \"fetch\" implementation or run in an environment where \"fetch\" is available."),F.fetch=t,F.bootstrap=u&&0<u.length?u:void 0,F.bootstrapOverride=void 0===v||v,F.metrics=new p({onError:F.emit.bind(F,A.ERROR),appName:l,metricsInterval:j,disableMetrics:void 0!==k&&k,url:F.url,clientKey:e,fetch:t,headerName:y}),F}return b(f,a),f.prototype.getAllToggles=function(){return e([],this.toggles,!0)},f.prototype.isEnabled=function(a){var b,c=this.toggles.find(function(b){return b.name===a}),d=!!c&&c.enabled;if(this.metrics.count(a,d),(null===c||void 0===c?void 0:c.impressionData)||this.impressionDataAll){var e=this.eventsHandler.createImpressionEvent(this.context,d,a,B.IS_ENABLED,null!==(b=null===c||void 0===c?void 0:c.impressionData)&&void 0!==b?b:void 0);this.emit(A.IMPRESSION,e)}return d},f.prototype.getVariant=function(a){var b,c=this.toggles.find(function(b){return b.name===a}),d=(null===c||void 0===c?void 0:c.enabled)||!1,e=c?c.variant:C;if(this.metrics.count(a,!0),(null===c||void 0===c?void 0:c.impressionData)||this.impressionDataAll){var f=this.eventsHandler.createImpressionEvent(this.context,d,a,B.GET_VARIANT,null!==(b=null===c||void 0===c?void 0:c.impressionData)&&void 0!==b?b:void 0,e.name);this.emit(A.IMPRESSION,f)}return e},f.prototype.updateContext=function(a){return c(this,void 0,void 0,function(){var b;return d(this,function(c){switch(c.label){case 0:return(a.appName||a.environment)&&console.warn("appName and environment are static. They can't be updated with updateContext."),b={environment:this.context.environment,appName:this.context.appName,sessionId:this.context.sessionId},this.context=m(m({},b),a),this.timerRef?[4,this.fetchToggles()]:[3,2];case 1:c.sent(),c.label=2;case 2:return[2];}})})},f.prototype.getContext=function(){return m({},this.context)},f.prototype.setContextField=function(a,b){var c,d;if(z.includes(a))this.context=m(m({},this.context),(c={},c[a]=b,c));else{var e=m(m({},this.context.properties),(d={},d[a]=b,d));this.context=m(m({},this.context),{properties:e})}this.timerRef&&this.fetchToggles()},f.prototype.init=function(){return c(this,void 0,void 0,function(){var a,b;return d(this,function(c){switch(c.label){case 0:return[4,this.resolveSessionId()];case 1:return a=c.sent(),this.context=m({sessionId:a},this.context),b=this,[4,this.storage.get(D)];case 2:return b.toggles=c.sent()||[],this.bootstrap&&(this.bootstrapOverride||0===this.toggles.length)?[4,this.storage.save(D,this.bootstrap)]:[3,4];case 3:c.sent(),this.toggles=this.bootstrap,this.emit(A.READY),c.label=4;case 4:return this.emit(A.INIT),[2];}})})},f.prototype.start=function(){return c(this,void 0,void 0,function(){var a,b=this;return d(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(),a=this.refreshInterval,[4,this.fetchToggles()];case 2:return c.sent(),0<a&&(this.timerRef=setInterval(function(){return b.fetchToggles()},a)),[2];}})})},f.prototype.stop=function(){this.timerRef&&(clearInterval(this.timerRef),this.timerRef=void 0),this.metrics.stop()},f.prototype.resolveSessionId=function(){return c(this,void 0,void 0,function(){var a;return d(this,function(b){var c=Math.floor;switch(b.label){case 0:return this.context.sessionId?[2,this.context.sessionId]:[3,1];case 1:return[4,this.storage.get("sessionId")];case 2:return(a=b.sent(),!!a)?[3,4]:(a=c(1e9*Math.random()),[4,this.storage.save("sessionId",a)]);case 3:b.sent(),b.label=4;case 4:return[2,a];}})})},f.prototype.getHeaders=function(){var a,b=(a={},a[this.headerName]=this.clientKey,a.Accept="application/json",a["Content-Type"]="application/json",a["If-None-Match"]=this.etag,a);return Object.entries(this.customHeaders).filter(x).forEach(function(a){var c=a[0],d=a[1];return b[c]=d}),b},f.prototype.storeToggles=function(a){return c(this,void 0,void 0,function(){return d(this,function(b){switch(b.label){case 0:return this.toggles=a,this.emit(A.UPDATE),[4,this.storage.save(D,a)];case 1:return b.sent(),[2];}})})},f.prototype.fetchToggles=function(){return c(this,void 0,void 0,function(){var a,b,c,e,f,g,h;return d(this,function(d){switch(d.label){case 0:if(!this.fetch)return[3,8];d.label=1;case 1:return d.trys.push([1,7,,8]),a=this.usePOSTrequests,b=a?this.url:y(this.url,this.context),c=a?"POST":"GET",e=a?JSON.stringify({context:this.context}):void 0,[4,this.fetch(b.toString(),{method:c,cache:"no-cache",headers:this.getHeaders(),body:e})];case 2:return(f=d.sent(),!(f.ok&&304!==f.status))?[3,5]:(this.etag=f.headers.get("ETag")||"",[4,f.json()]);case 3:return g=d.sent(),[4,this.storeToggles(g.toggles)];case 4:return d.sent(),this.bootstrap||this.readyEventEmitted||(this.emit(A.READY),this.readyEventEmitted=!0),[3,6];case 5:f.ok||304===f.status||(console.error("Unleash: Fetching feature toggles did not have an ok response"),this.emit(A.ERROR,{type:"HttpError",code:f.status})),d.label=6;case 6:return[3,8];case 7:return h=d.sent(),console.error("Unleash: unable to fetch feature toggles",h),this.emit(A.ERROR,h),[3,8];case 8:return[2];}})})},f}(n);a.EVENTS=A,a.InMemoryStorageProvider=q,a.LocalStorageProvider=r,a.UnleashClient=F,a.resolveFetch=E,Object.defineProperty(a,"__esModule",{value:!0})});
{
"name": "unleash-proxy-client",
"version": "2.4.0-beta.0",
"version": "2.4.0-beta.1",
"description": "A browser client that can be used together with the unleash-proxy.",

@@ -5,0 +5,0 @@ "main": "./build/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