GitHub

Bucket

The Bucket provider contains support for Bucket's feature management tools.

Currently only feature toggling is supported. Remote Config, Adoption tracking and automatic feedback surveys are currently not supported in the Bucket Flags SDK provider.

Bucket is feature flagging for teams that want to move fast.

The @flags-sdk/bucket provider package exports

Learn more about Adapters

Learn more about the Flags Explorer

Deploy the Bucket template


Setup

The Bucket provider is available in the @flags-sdk/bucket module. Install it with

npm install @flags-sdk/bucket

Provider Instance

Import the default adapter instance bucketAdapter from @flags-sdk/bucket:

import { bucketAdapter } from "@flags-sdk/bucket";

If you need a customized setup, you can import createBucketAdapter from @flags-sdk/bucket and create an adapter instance with your settings:

import { createBucketAdapter } from "@flags-sdk/bucket";
 
const bucketAdapter = createBucketAdapter({
  secretKey: process.env.BUCKET_SECRET_KEY,
});

See the Bucket NodeSDK documentation for the full list of options.


Identify Users and Companies

The Bucket provider uses the identify property to identify users and companies. The identify function is called for every request to determine the user and company context.

Bucket relies on a setting a user/company to evaluate flags for a given request.

Set the identify property to a function which returns a Bucket Context containing user/company properties:

import { dedupe, flag } from "flags/next";
import type { Identify } from "flags";
import { bucketAdapter, type Context } from "@flags-sdk/bucket";
 
const identify = dedupe((async ({ headers, cookies }) => {
  // Your own logic to identify the user
  // Identifying the user should rely on reading cookies and headers only, and
  // not make any network requests, as it's important to keep latency low here.
  const user = await getUser(headers, cookies);
 
  return {
    user: {
      id: user.id,
      name: user.name,
      email: user.email,
    },
    company: {
      id: user.companyId,
    },
  } satisfies Context;
}) satisfies Identify<Context>);
 
export const myFeature = flag<boolean, Context>({
  key: "my_feature",
  identify,
  adapter: bucketAdapter.featureIsEnabled(),
});

Learn more about dedupe

Learn more about identify


Methods

Feature toggling

Through the featureIsEnabled method, the Bucket provider supports determining if features are enabled/disabled.

export const myFeature = flag<boolean, Context>({
  key: "my_feature",
  adapter: bucketAdapter.featureIsEnabled(),
  identify,
});

Remote Config, Adoption tracking and automatic feedback surveys are currently not supported in the Bucket Flags SDK provider.


"Checks" events

Check events are used to log when a user is exposed to a feature. Because middleware and server components are evaluated when routes are prefetched, check events are not supported in the Bucket Provider.

See the Bucket React SDK documentation for more information on how to use check events in the client.


Flags Explorer

View and override your Bucket feature toggles using the Flags Explorer.

To make Flags Explorer aware of your Bucket features, you need to provide a route which Flags Explorer will load your experiment metadata from.

Use the getProviderData function in your Flags API endpoint to load and emit your Bucket data. getProviderData takes a BucketClient in the options object:

app/.well-known/vercel/flags/route.ts
import { createFlagsDiscoveryEndpoint } from 'flags/next';
import { bucketAdapter, getProviderData } from "@flags-sdk/bucket";
import * as flags from '../../../../flags';
 
export const GET = createFlagsDiscoveryEndpoint(async () => {
  return getProviderData({
    bucketClient: await bucketAdapter.bucketClient(),
  });
});

Read More

Read more about Bucket, Flags SDK, and the Bucket adapter.