Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bucketco/openfeature-browser-provider

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bucketco/openfeature-browser-provider

The official OpenFeature Browser provider for [Bucket](https://bucket.co) feature management service.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Bucket Browser OpenFeature Provider

The official OpenFeature Browser provider for Bucket feature management service.

It uses the Bucket Browser SDK internally and thus allow you to collect automated feedback surveys when people use your features as well as tracking which customers use which features.

If you're using React, you'll be better off with the Bucket React SDK or the OpenFeature React SDK.

See the example folder for how to use the OpenFeature React SDK with Next.js.

Installation

The OpenFeature SDK is required as peer dependency.

The minimum required version of @openfeature/web-sdk currently is 1.0.

$ npm install @openfeature/web-sdk @bucketco/openfeature-browser-provider

Sample initialization

import { BucketBrowserProvider } from "@bucketco/openfeature-browser-provider";
import { OpenFeature } from "@openfeature/web-sdk";

// initialize provider
const publishableKey = "<your-bucket-publishable-key>";

const bucketProvider = new BucketBrowserProvider({ publishableKey });

// set open feature provider and get client
await OpenFeature.setProviderAndWait(bucketProvider);
const client = OpenFeature.getClient();

// use client
const boolValue = client.getBooleanValue("huddles", false);

Bucket only supports boolean values.

Initializing the Bucket Browser Provider will also initialize automatic feedback surveys.

Context

To convert the OpenFeature context to a Bucket appropriate context pass a translation function along to the BucketBrowserProvider constructor like so:

import { BucketBrowserProvider } from "@bucketco/openfeature-browser-provider";
import { EvaluationContext, OpenFeature } from "@openfeature/web-sdk";

// initialize provider
const publishableKey = "<your-bucket-publishable-key>";

const contextTranslator = (context?: EvaluationContext) => {
  return {
    user: { id: context.userId, name: context.name, email: context.email },
    company: { id: context.orgId, name: context.orgName },
  };
};

const bucketOpenFeatureProvider = new BucketBrowserProvider({
  publishableKey,
  contextTranslator,
});

To update the context, call OpenFeature.setContext(myNewContext);

await OpenFeature.setContext({ userId: "my-key" });

Tracking feature usage

To track feature usage, use the track method on the client. By default you can use the flag/feature key as the event name as the first argument to designate feature usage when calling the track method:

import { EvaluationContext, OpenFeature } from "@openfeature/web-sdk";
import { BucketBrowserProvider } from "@bucketco/openfeature-browser-provider";

const bucketOpenFeatureProvider = new BucketBrowserProvider({
  publishableKey,
});

bucketOpenFeatureProvider.client.track("huddle", { voiceHuddle: true });

License

MIT License

Copyright (c) 2024 Bucket ApS

FAQs

Package last updated on 16 Sep 2024

Did you know?

Socket

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.

Install

Related posts

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