unleash-proxy-client
Advanced tools
Comparing version 0.0.6 to 0.0.7
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
@@ -104,7 +105,10 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var context_1, urlWithQuery_1, response, data; | ||
var context_1, urlWithQuery_1, response, data, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!fetch) return [3 /*break*/, 3]; | ||
if (!fetch) return [3 /*break*/, 5]; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 4, , 5]); | ||
context_1 = this.context; | ||
@@ -121,10 +125,15 @@ urlWithQuery_1 = this.url; | ||
})]; | ||
case 1: | ||
case 2: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.json()]; | ||
case 2: | ||
case 3: | ||
data = _a.sent(); | ||
this.storeToggles(data.toggles); | ||
_a.label = 3; | ||
case 3: return [2 /*return*/]; | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
e_1 = _a.sent(); | ||
// tslint:disable-next-line | ||
console.error('Unleash: unable to fetch feature toggles', e_1); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
} | ||
@@ -131,0 +140,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
var unleash=function(a){'use strict';function b(a,b,c,d){return new(c||(c=Promise))(function(e,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?e(a.value):new c(function(b){b(a.value)}).then(g,h)}i((d=d.apply(a,b||[])).next())})}function c(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}var d=function(){function a(){this.prefix="unleash:repository"}return a.prototype.save=function(a,b){try{var c=JSON.stringify(b),d=this.prefix+":"+a;window.localStorage.setItem(d,c)}catch(a){console.error(a)}},a.prototype.get=function(a){try{var b=this.prefix+":"+a,c=window.localStorage.getItem(b);return c?JSON.parse(c):void 0}catch(a){console.error(a)}},a}(),e={name:"disabled"},f="repo",g=function(){function a(a,b){if(this.toggles=[],this.storage=a.storageProvider||new d,this.refreshInterval=1e3*(a.refreshInterval||30),!a.url)throw new Error("You have to specify the url!");if(!a.clientKey)throw new Error("You have to specify the clientKey!");this.url=new URL(a.url+"/proxy"),this.clientKey=a.clientKey,this.context=b||{},this.toggles=this.storage.get(f)}return a.prototype.isEnabled=function(a){var b=this.toggles.find(function(b){return b.name===a});return!!b&&b.enabled},a.prototype.getVariant=function(a){var b=this.toggles.find(function(b){return b.name===a});return b?b.variant:e},a.prototype.updateContext=function(a){this.context=a},a.prototype.start=function(){return b(this,void 0,void 0,function(){var a,b=this;return c(this,function(c){switch(c.label){case 0:return fetch?(this.stop(),a=this.refreshInterval,[4,this.fetchToggles()]):[3,2];case 1:return c.sent(),this.ref=setInterval(function(){return b.fetchToggles()},a),[3,3];case 2:console.error("Unleash: Client does not support fetch."),c.label=3;case 3:return[2];}})})},a.prototype.stop=function(){this.ref&&clearInterval(this.ref)},a.prototype.storeToggles=function(a){this.toggles=a,this.storage.save(f,a)},a.prototype.fetchToggles=function(){return b(this,void 0,void 0,function(){var a,b,d,e;return c(this,function(c){switch(c.label){case 0:return fetch?(a=this.context,b=this.url,Object.keys(a).forEach(function(c){return b.searchParams.append(c,a[c])}),[4,fetch(b.toString(),{cache:"no-cache",headers:{Authorization:this.clientKey,Accept:"application/json","Content-Type":"application/json"}})]):[3,3];case 1:return d=c.sent(),[4,d.json()];case 2:e=c.sent(),this.storeToggles(e.toggles),c.label=3;case 3:return[2];}})})},a}();return a.UnleashClient=g,a}({}); | ||
var unleash=function(a){'use strict';function b(a,b,c,d){return new(c||(c=Promise))(function(e,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?e(a.value):new c(function(b){b(a.value)}).then(g,h)}i((d=d.apply(a,b||[])).next())})}function c(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}var d=function(){function a(){this.prefix="unleash:repository"}return a.prototype.save=function(a,b){try{var c=JSON.stringify(b),d=this.prefix+":"+a;window.localStorage.setItem(d,c)}catch(a){console.error(a)}},a.prototype.get=function(a){try{var b=this.prefix+":"+a,c=window.localStorage.getItem(b);return c?JSON.parse(c):void 0}catch(a){console.error(a)}},a}(),e={name:"disabled"},f="repo",g=function(){function a(a,b){if(this.toggles=[],this.storage=a.storageProvider||new d,this.refreshInterval=1e3*(a.refreshInterval||30),!a.url)throw new Error("You have to specify the url!");if(!a.clientKey)throw new Error("You have to specify the clientKey!");this.url=new URL(a.url+"/proxy"),this.clientKey=a.clientKey,this.context=b||{},this.toggles=this.storage.get(f)}return a.prototype.isEnabled=function(a){var b=this.toggles.find(function(b){return b.name===a});return!!b&&b.enabled},a.prototype.getVariant=function(a){var b=this.toggles.find(function(b){return b.name===a});return b?b.variant:e},a.prototype.updateContext=function(a){this.context=a},a.prototype.start=function(){return b(this,void 0,void 0,function(){var a,b=this;return c(this,function(c){switch(c.label){case 0:return fetch?(this.stop(),a=this.refreshInterval,[4,this.fetchToggles()]):[3,2];case 1:return c.sent(),this.ref=setInterval(function(){return b.fetchToggles()},a),[3,3];case 2:console.error("Unleash: Client does not support fetch."),c.label=3;case 3:return[2];}})})},a.prototype.stop=function(){this.ref&&clearInterval(this.ref)},a.prototype.storeToggles=function(a){this.toggles=a,this.storage.save(f,a)},a.prototype.fetchToggles=function(){return b(this,void 0,void 0,function(){var a,b,d,e,f;return c(this,function(c){switch(c.label){case 0:if(!fetch)return[3,5];c.label=1;case 1:return c.trys.push([1,4,,5]),a=this.context,b=this.url,Object.keys(a).forEach(function(c){return b.searchParams.append(c,a[c])}),[4,fetch(b.toString(),{cache:"no-cache",headers:{Authorization:this.clientKey,Accept:"application/json","Content-Type":"application/json"}})];case 2:return d=c.sent(),[4,d.json()];case 3:return e=c.sent(),this.storeToggles(e.toggles),[3,5];case 4:return f=c.sent(),console.error("Unleash: unable to fetch feature toggles",f),[3,5];case 5:return[2];}})})},a}();return a.UnleashClient=g,a}({}); |
@@ -9,3 +9,3 @@ { | ||
"react-scripts": "3.1.1", | ||
"unleash-proxy-client": "^0.0.5" | ||
"unleash-proxy-client": "^0.0.6" | ||
}, | ||
@@ -12,0 +12,0 @@ "scripts": { |
{ | ||
"name": "unleash-proxy-client", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A browser client that can be used together with the unleash-proxy.", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
484013
504