🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

unleash-proxy-client

Package Overview
Dependencies
Maintainers
1
Versions
98
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

to
0.0.3

examples/cdn-app/index.html

21

build/index.js

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

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -36,3 +37,7 @@ return new (P || (P = Promise))(function (resolve, reject) {

};
import LocalStorageProvider from './storage-provider-local';
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var storage_provider_local_1 = __importDefault(require("./storage-provider-local"));
var defaultVariant = { name: 'disabled' };

@@ -43,3 +48,3 @@ var storeKey = 'repo';

this.toggles = [];
this.storage = config.storageProvider || new LocalStorageProvider();
this.storage = config.storageProvider || new storage_provider_local_1.default();
this.refreshInterval = (config.refreshInterval || 30) * 1000;

@@ -53,3 +58,3 @@ // Validations

}
this.url = config.url + "/proxy";
this.url = new URL(config.url + "/proxy");
this.clientKey = config.clientKey;

@@ -105,3 +110,3 @@ this.context = context || {};

return __awaiter(this, void 0, void 0, function () {
var context_1, u_1, response, data;
var context_1, urlWithQuery_1, response, data;
return __generator(this, function (_a) {

@@ -112,5 +117,5 @@ switch (_a.label) {

context_1 = this.context;
u_1 = new URL(this.url);
Object.keys(context_1).forEach(function (key) { return u_1.searchParams.append(key, context_1[key]); });
return [4 /*yield*/, fetch(u_1.toString(), {
urlWithQuery_1 = this.url;
Object.keys(context_1).forEach(function (key) { return urlWithQuery_1.searchParams.append(key, context_1[key]); });
return [4 /*yield*/, fetch(urlWithQuery_1.toString(), {
cache: 'no-cache',

@@ -137,3 +142,3 @@ headers: {

}());
export { UnleashClient };
exports.UnleashClient = UnleashClient;
//# sourceMappingURL=index.js.map

@@ -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=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=new URL(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;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}({});

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var LocalStorageProvider = /** @class */ (function () {

@@ -29,3 +31,3 @@ function LocalStorageProvider() {

}());
export default LocalStorageProvider;
exports.default = LocalStorageProvider;
//# sourceMappingURL=storage-provider-local.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=storage-provider.js.map
{
"name": "unleash-proxy-client",
"version": "0.0.2",
"version": "0.0.3",
"description": "A browser client that can be used together with the unleash-proxy.",

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

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

# unleash-proxy-client-js
A browser client that can be used together with the unleash-proxy.
# Unleash Proxy Client for the browser (js)
This is a client that your can use in the browser together with the
unleash-proxy, available for unleash-hosted customers.
## How to use as a module.
**Step 1: Install**
```js
npm install unleash-proxy-client --save
```
**Step 2: Initialize**
```js
const client = require('unleash-proxy-client');
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet