
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
@anttiviljami/unleash-proxy-client
Advanced tools
A browser client that can be used together with the unleash-proxy.
This is a tiny Unleash Client SDK you can use together with the Unleash Proxy. This makes it super simple to use Unleash from any single page app.
This client expect fetch
to be available. If you need to support older
browsers you should probably use the fetch polyfill.
This package is not tied to any framework, but can be used together most popular frameworks, examples:
Step 1: Install
npm install unleash-proxy-client --save
Step 2: Initialize the SDK
You need to have a Unleash-hosted instance, and the proxy need to be enabled. In addition you will need a proxy-specific clientKey
in order to connect to the Unleash-hosted Proxy.
import { UnleashClient } from 'unleash-proxy-client';
const unleash = new UnleashClient({
url: 'https://eu.unleash-hosted.com/hosted/proxy',
clientKey: 'your-proxy-key',
appName: 'my-webapp'
});
// Used to set the context fields, shared with the Unleash Proxy
unleash.updateContext({userId: '1233'});
// Start the background polling
unleash.start();
Step 3: Check if feature toggle is enabled
unleash.isEnabled('proxy.demo');
Step 4: Get toggle variant
const variant = unleash.getVariant('proxy.demo');
if(variant.name === 'blue') {
// something with variant blue...
}
Listen for updates via the EventEmitter The client is also an event emitter. This means that your code can subscribe to updates from the client. This is a neat way to update a single page app when toggle state updates.
unleash.on('update', () => {
const myToggle = unleash.isEnabled('proxy.demo');
//do something useful
});
You may provide a custom session id via the "context". If you do not provide a sessionId this SDK will create a random session id, which will also be stored in the provided storage (local storage). By always having a consistent sessionId available ensures that even "anonymous" users will get a consistent experience when feature toggles is evaluated, in combination with a gradual (percentage based) rollout.
This SDK will use @react-native-async-storage/async-storage to backup feature toggles locally. This is useful for bootstrapping the SDK the next time the user comes back to your application.
You can provide your own storage implementation.
Example:
import SharedPreferences from 'react-native-shared-preferences';
import { UnleashClient } from 'unleash-proxy-client';
const unleash = new UnleashClient({
url: 'https://eu.unleash-hosted.com/hosted/proxy',
clientKey: 'your-proxy-key',
appName: 'my-webapp',
storage: {
save: (name: string, data: any) => SharedPreferences.setItem(name, data),
get: (name: string) => SharedPreferences.getItem(name, (val) => val)
},
});
<html>
<head>
<script src="https://unpkg.com/unleash-proxy-client@latest/build/main.min.js" type="text/javascript"></script>
<script type="text/javascript">
var config = {url: 'https://app.unleash-hosted.com/demo/proxy', clientKey: 'proxy-123', appName: 'web'};
var client = new unleash.UnleashClient(config);
client.updateContext({userId: '1233'})
client.on('update', () => {
console.log(client.isEnabled('proxy.demo'));
});
client.start();
</script>
</head>
</html>
FAQs
A browser client that can be used together with the unleash-proxy.
We found that @anttiviljami/unleash-proxy-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.