### Bucket CLI MCP Setup Source: https://docs.bucket.co/api/mcp This command initiates the setup process for the Model Context Protocol (MCP) using the Bucket Command Line Interface (CLI). It guides the user through selecting options to connect their project to Bucket data. ```bash npx @bucketco/cli@latest mcp ``` -------------------------------- ### Install Node.js SDK with deno Source: https://docs.bucket.co/supported-languages/node-sdk Installs the Bucket.co Node.js SDK for Deno environments using `deno add`. This command fetches the package from npm. ```sh deno add npm:@bucketco/node-sdk ``` -------------------------------- ### Bucket Configuration File Example Source: https://docs.bucket.co/supported-languages/node-sdk An example JSON file demonstrating how to configure the Bucket Node.js SDK, including settings for secret key, log level, offline mode, API base URL, and feature overrides. ```json { "secretKey": "...", "logLevel": "warn", "offline": true, "apiBaseUrl": "https://proxy.slick-demo.com", "featureOverrides": { "huddles": true, "voiceChat": { "isEnabled": false }, "aiAssist": { "isEnabled": true, "config": { "key": "gpt-4.0", "payload": { "maxTokens": 50000 } } } } } ``` -------------------------------- ### Install Node.js SDK with bun Source: https://docs.bucket.co/supported-languages/node-sdk Installs the Bucket.co Node.js SDK using the bun package manager. Bun offers a fast alternative for JavaScript development. ```sh bun add @bucketco/node-sdk ``` -------------------------------- ### Install Bucket CLI Source: https://docs.bucket.co/api/cli Installs the Bucket CLI as a development dependency in your project using either npm or yarn. ```bash # npm npm install --save-dev @bucketco/cli ``` ```bash # yarn yarn add --dev @bucketco/cli ``` -------------------------------- ### TypeScript: Basic Bucket Client Setup Source: https://docs.bucket.co/supported-languages/node-sdk A minimal setup for the Bucket Node.js SDK client, typically placed in a dedicated file for easy import in tests or application code. ```typescript import { BucketClient } from "@bucketco/node-sdk"; export const bucket = new BucketClient(); ``` -------------------------------- ### Install Node.js SDK with pnpm Source: https://docs.bucket.co/supported-languages/node-sdk Installs the Bucket.co Node.js SDK using the pnpm package manager. pnpm is known for its efficient disk space usage and fast installation. ```sh pnpm add @bucketco/node-sdk ``` -------------------------------- ### Install Bucket React SDK Source: https://docs.bucket.co/supported-languages/react-sdk Installs the Bucket.co React SDK package using npm. This is the first step to integrate Bucket features into your React application. ```shell npm i @bucketco/react-sdk ``` -------------------------------- ### Initialize Bucket SDK and Get Features (JavaScript) Source: https://docs.bucket.co/integrations/mixpanel Demonstrates how to initialize the Bucket Browser SDK with a publishable key and user information. It then shows how to retrieve all available features for the authenticated user. ```javascript const bucket = new BucketBrowserSDK.BucketClient({ publishableKey: "pub_prod_5eS0G5hX4ZOpwoAw1CKTeP", user: { id: "u1234", name: "Rasmus Makwarth" }, }); const features = bucket.getFeatures(); ``` ```json { "features": { "export-to-csv": { "isEnabled": true, "key": "export-to-csv", "targetingVersion": 2 }, ... } } ``` -------------------------------- ### Install Bucket CLI Source: https://docs.bucket.co/supported-languages/react-sdk Installs the Bucket CLI as a development dependency. The CLI is used for managing features, signing into Bucket, and generating type definitions for your project. ```shell npm i --save-dev @bucketco/cli ``` -------------------------------- ### Create New Feature via CLI Source: https://docs.bucket.co/welcome/readme This command initiates the creation of a new feature within the Bucket platform using the command-line interface. It requires Node.js and npx to be installed. The command generates a new feature entry that can then be configured in the Bucket dashboard. ```cli npx @bucketco/cli new ``` -------------------------------- ### Install Bucket React SDK Source: https://docs.bucket.co/guides/release-beta-features Installs the Bucket React SDK using npm. This is a prerequisite for integrating Bucket features into your React application. ```bash npm i @bucketco/react-sdk ``` -------------------------------- ### React SDK: Check Feature Flag Status Source: https://docs.bucket.co/guides/create-your-first-feature Demonstrates using the `@bucketco/react-sdk` to check if a feature flag is enabled. It handles loading states and conditionally renders UI components based on the feature's status. Requires the `@bucketco/react-sdk` package. ```tsx import { useFeature } from "@bucketco/react-sdk"; function StartHuddleButton() { const { isLoading, isEnabled } = useFeature("huddle"); if (isLoading) { return ; } if (!isEnabled) { return null; } return (
Huddles feature...
); } ``` -------------------------------- ### Install Node.js SDK with npm Source: https://docs.bucket.co/supported-languages/node-sdk Installs the Bucket.co Node.js SDK using the npm package manager. This is the first step to integrate Bucket.co features into your Node.js application. ```sh npm i @bucketco/node-sdk ``` -------------------------------- ### Initialize Bucket SDK and Get Features (JavaScript) Source: https://docs.bucket.co/integrations/amplitude This snippet shows how to initialize the Bucket Browser SDK with a publishable key and user details. It then demonstrates fetching all available features for the authenticated user. The output is a JSON object containing feature states. ```javascript const bucket = new BucketBrowserSDK.BucketClient({ publishableKey: "pub_prod_5eS0G5hX4ZOpwoAw1CKTeP", user: { id: "u1234", name: "Rasmus Makwarth" }, }); const features = bucket.getFeatures(); ``` ```json { "features": { "export-to-csv": { "isEnabled": true, "key": "export-to-csv", "targetingVersion": 2 }, ... } } ``` -------------------------------- ### Default Export with Install Method Source: https://docs.bucket.co/supported-languages/vue-sdk/globals Defines the default export of the SDK, which includes an `install` method. ```typescript default: { install: void; }; Type declaration for install method: `install()`: `void` ``` -------------------------------- ### Install Bucket CLI Source: https://docs.bucket.co/supported-languages/node-sdk Installs the Bucket CLI tool as a development dependency using npm. This tool is essential for generating type definitions for your feature flags. ```bash npm i --save-dev @bucketco/cli ``` -------------------------------- ### Install Node.js SDK with yarn Source: https://docs.bucket.co/supported-languages/node-sdk Installs the Bucket.co Node.js SDK using the yarn package manager. This is an alternative to npm for managing project dependencies. ```sh yarn add @bucketco/node-sdk ``` -------------------------------- ### Install Bucket Vue SDK Source: https://docs.bucket.co/supported-languages/vue-sdk Installs the Bucket Vue SDK using npm. This is the first step to integrate Bucket.co's feature flagging and remote configuration into your Vue application. ```shell npm i @bucketco/vue-sdk ``` -------------------------------- ### Run Bucket CLI for Feature Setup Source: https://docs.bucket.co/supported-languages/react-sdk Executes the Bucket CLI to create new features and generate type-safe definitions. This process involves logging into the Bucket service and configuring project-specific settings. ```shell ❯ npx bucket new Opened web browser to facilitate login: https://app.bucket.co/api/oauth/cli/authorize Welcome to Bucket! ? Where should we generate the types? gen/features.d.ts ? What is the output format? react ✔ Configuration created at bucket.config.json. Creating feature for app Slick app. ? New feature name: Huddle ? New feature key: huddle ✔ Created feature Huddle with key huddle (https://app.bucket.co/features/huddles) ✔ Generated react types in gen/features.d.ts. ``` -------------------------------- ### EdgeClient Usage Example Source: https://docs.bucket.co/supported-languages/node-sdk/globals Example demonstrating how to instantiate and use the EdgeClient for evaluating feature flags in edge runtimes. The BUCKET_SECRET_KEY environment variable should be set or passed in the constructor. ```TypeScript const client = new EdgeClient(); const context = { user: { id: "user-id" }, company: { id: "company-id" }, }; const { isEnabled } = client.getFeature(context, "feature-flag-key"); ``` -------------------------------- ### Initialize Bucket Browser SDK via Script Tag Source: https://docs.bucket.co/supported-languages/browser-sdk Shows how to include the Bucket Browser SDK directly in an HTML file using a script tag. It covers initialization and basic event handling for a button click, referencing an external example file. ```html Loading... ``` -------------------------------- ### Initialize and Use Bucket Browser SDK Client Source: https://docs.bucket.co/supported-languages/browser-sdk Demonstrates how to import and initialize the Bucket Browser SDK client with user and company data. It shows how to get feature flags, track usage, and request feedback for a specific feature. ```typescript import { BucketClient } from "@bucketco/browser-sdk"; const user = { id: 42, role: "manager", }; const company = { id: 99, plan: "enterprise", }; const bucketClient = new BucketClient({ publishableKey, user, company }); await bucketClient.initialize(); const { isEnabled, config: { payload: question }, track, requestFeedback, } = bucketClient.getFeature("huddle"); if (isEnabled) { // Show feature. When retrieving `isEnabled` the client automatically // sends a "check" event for the "huddle" feature which is shown in the // Bucket UI. // On usage, call `track` to let Bucket know that a user interacted with the feature track(); // The `payload` is a user-supplied JSON in Bucket that is dynamically picked // out depending on the user/company. const question = payload?.question ?? "Tell us what you think of Huddles"; // Use `requestFeedback` to create "Send feedback" buttons easily for specific // features. This is not related to `track` and you can call them individually. requestFeedback({ title: question }); } // `track` just calls `bucketClient.track()` to send an event using the same feature key // You can also use `track` on the client directly to send any custom event. bucketClient.track("huddle"); // similarly, `requestFeedback` just calls `bucketClient.requestFeedback({featureKey: })` // which you can also call directly: bucketClient.requestFeedback({ featureKey: "huddle" }); ``` -------------------------------- ### VS Code MCP Server Setup Command Source: https://docs.bucket.co/api/mcp Instructions for setting up a Bucket MCP server within Visual Studio Code. This involves using the MCP: Add Server command and providing the mcp-remote command string with your App ID. It supports both user and workspace settings. ```APIDOC VS Code MCP Server Setup: 1. Open VS Code. 2. Open the command palette (CMD + SHIFT + P or CTRL + SHIFT + P). 3. Type and select 'MCP: Add Server...'. 4. Select 'Command (stdio)'. 5. Enter the following command string, replacing '' with your actual App ID: npx mcp-remote@latest https://app.bucket.co/api/mcp?appId= 6. Enter 'Bucket' as the server ID. 7. Select either 'User Settings' or 'Workspace Settings'. 8. Ensure Copilot agent mode is enabled for MCP functionality. ``` -------------------------------- ### BucketProvider Component Usage Source: https://docs.bucket.co/supported-languages/vue-sdk Example of how to use the component in a Vue application, including essential props and slot usage for loading states. It initializes the SDK and fetches features. ```vue ``` -------------------------------- ### Bucket Client Feedback Popover Button Example Source: https://docs.bucket.co/supported-languages/browser-sdk/feedback Illustrates how to trigger the feedback popover by attaching an event listener to a button element. This allows users to initiate feedback directly from a custom UI component. ```html ``` -------------------------------- ### Linear Agent @-mention Commands Source: https://docs.bucket.co/integrations/linear Examples of using the @bucket command within Linear to create features, manage access, and link issues to features. These commands are part of the Agent integration for direct interaction within Linear. ```APIDOC @bucket create feature flag for this issue - Description: Creates a new feature flag in Bucket based on the context of the Linear issue. - Usage: Use this command within a Linear issue to initiate feature creation. ``` ```APIDOC @bucket release to everyone and bump stage to GA - Description: Manages feature access by releasing it to everyone and advancing its stage to General Availability (GA). - Usage: Apply this command to control the rollout and lifecycle stage of a feature directly from Linear. ``` ```APIDOC @bucket link to - Description: Links an existing Linear issue to a specific feature in Bucket using its name or key. - Usage: Establish a connection between a Linear issue and a Bucket feature for better traceability. ``` -------------------------------- ### Initialize Bucket Node SDK for SSR Source: https://docs.bucket.co/supported-languages/next.js Sets up the BucketClient for server-side operations in Next.js. It initializes the client with a secret key and logger, and provides functions to get user context and fetch feature flags. Requires `BUCKET_SECRET_KEY` environment variable. ```typescript import { BucketClient } from "@bucketco/node-sdk"; import { auth } from "@/auth"; export let bucketClient: BucketClient; async function initBucket() { bucketClient = new BucketClient({ secretKey: process.env.BUCKET_SECRET_KEY ?? "", logger: console, }); await bucketClient.initialize(); } export async function getContext() { // get the logged-in session const session = await auth(); const user = session?.user; if (!user || !user.id) { return {}; } const userId = user.id; return { user: { id: userId, ...user, }, company: session.company, }; } export async function getFeature(key: string) { if (!bucketClient) { await initBucket(); } return bucketClient.getFeature(await getContext(), key); } ``` -------------------------------- ### Bucket API GET /features/enabled Endpoint Example Source: https://docs.bucket.co/api/http-api Fetches features that are enabled for a specific user or company. The context for evaluation is provided as flattened query parameters. This endpoint is optimized for low latency by using GET requests. ```http GET https://front.bucket.co/features/enabled?context.company.id=42&context.user.id=99&publishableKey=pub_prod_Cqx4DGo1lk3Lcct5NHLjWy ``` ```APIDOC GET /features/enabled - Description: Retrieve features that are enabled for the provided user/company. - Authentication: Requires a publishable or secret key. - Parameters (Query String): - context.company.id: Identifier for the company. - context.user.id: Identifier for the user. - publishableKey: Your publishable API key. - Example Response: { "success": true, "features": { "huddles": { "isEnabled": true, "key": "huddles", "targetingVersion": 42 } } } ``` -------------------------------- ### Bucket SDK API Reference Source: https://docs.bucket.co/supported-languages/browser-sdk/globals Comprehensive documentation for the Bucket SDK methods. This includes functions for initializing the SDK, managing user feedback, retrieving configuration and feature flags, tracking events, and handling listeners. Each method details its purpose, parameters, return values, and any specific requirements or behaviors. ```APIDOC feedback(payload: Feedback): Promise - Submits user feedback to Bucket. Requires either 'score' or 'comment', or both. - Parameters: - payload: The feedback details to submit. - Returns: A Promise resolving to undefined or a Response object. getConfig(): Config - Retrieves the current SDK configuration. - Returns: The current Config object. getFeature(key: string): Feature - Returns a specific feature by its key. Accessing 'isEnabled' or 'config' on the returned Feature object automatically sends a 'check' event. - Parameters: - key: The unique identifier for the feature. - Returns: A Feature object. getFeatures(): RawFeatures - Returns a map of all enabled features. Accessing a feature via this map does not send a 'check' event, and 'isEnabled' does not consider feature overrides. - Returns: A RawFeatures map. initialize(): Promise - Initializes the Bucket SDK. This method must be called before any other SDK methods. - Returns: A Promise that resolves when initialization is complete. off(type: THookType, handler: (args0: HookArgs[THookType]) => void): void - Removes an event listener previously added with the 'on' method. - Type Parameters: - THookType: The type of event to remove the listener from, extending keyof HookArgs. - Parameters: - type: The type of event to remove. - handler: The specific function handler to remove. - Returns: void. on(type: THookType, handler: (args0: HookArgs[THookType]) => void): () => void - Adds an event listener to the SDK. - Type Parameters: - THookType: The type of event to listen for, extending keyof HookArgs. - Parameters: - type: The type of event to listen for. - handler: The function to execute when the event is triggered. - Returns: A function that can be called to remove the listener. requestFeedback(options: RequestFeedbackData): void - Programmatically displays the Bucket feedback form UI. Useful for collecting feedback outside of automated surveys. - Parameters: - options: Data required to display the feedback form. - Returns: void. stop(): Promise - Stops the Bucket SDK, including any automated feedback surveys. - Returns: A Promise that resolves when the SDK has stopped. track(eventName: string, attributes?: null | Record): Promise - Tracks a specific event within Bucket. - Parameters: - eventName: The name of the event to track. - attributes: Optional additional data associated with the event. - Returns: A Promise resolving to undefined or a Response object. ``` -------------------------------- ### Initialize Bucket Client Source: https://docs.bucket.co/supported-languages/browser-sdk Demonstrates initializing the BucketClient with essential configuration. The constructor accepts a publishable key and optional user and company objects. User and company objects must include an 'id' and can contain additional attributes like 'name', 'email', and 'avatar' for feature targeting and UI display. ```ts const bucketClient = new BucketClient({ publishableKey, user: { id: "user_123", name: "John Doe", email: "john@acme.com" avatar: "https://example.com/images/udsy6363" }, company: { id: "company_123", name: "Acme, Inc", avatar: "https://example.com/images/31232ds" }, }); ``` -------------------------------- ### React SDK: Check Feature Enablement Source: https://docs.bucket.co/welcome/readme Demonstrates how to use the Bucket React SDK to check if a specific feature is enabled for the current user session. It utilizes the `useFeature` hook, which returns an `isEnabled` boolean. This is fundamental for implementing feature gating in React applications. ```jsx import { useFeature } from "@bucketco/react-sdk"; const MyFeature = () => { const { isEnabled } = useFeature("my-new-feature"); return isEnabled ? "You have access!" : null; }; ``` -------------------------------- ### Bucket CLI Commands Overview Source: https://docs.bucket.co/api/cli Provides an overview of the primary Bucket CLI commands for initialization, feature management, and authentication. ```APIDOC Bucket CLI Commands: bucket init [--overwrite] [--app-id ] [--key-format ] Initializes a new Bucket configuration in your project, creating a `bucket.config.json` file. Options: --overwrite: Overwrite existing configuration file. --app-id : Set the application ID. --key-format : Set the key format for features (e.g., custom, snake, camel). bucket new [featureName] [--app-id ap123456789] [--key my-feature] [--key-format custom] [--out gen/features.ts] [--format react] All-in-one command to initialize, create a feature, and generate types. Parameters: featureName: Optional name for the new feature. Options: --app-id: App ID to use. --key: Specific key for the feature. --key-format: Format for feature keys. --out: Path to generate TypeScript types. --format: Format of the generated types (react or node). bucket login Logs in to your Bucket account, authenticating the CLI and storing credentials securely. bucket logout Logs out from your Bucket account, removing stored credentials. bucket features Manages your Bucket features with subcommands like `create` and `types`. ``` -------------------------------- ### React SDK: Request Feedback Source: https://docs.bucket.co/welcome/readme Shows how to integrate a feedback mechanism into your application using the Bucket React SDK. The `requestFeedback` function, obtained from the `useFeature` hook, can be called to prompt users for input on a feature. It accepts an optional configuration object, such as a title for the feedback prompt. ```jsx import { useFeature } from "@bucketco/react-sdk"; const MyFeature = () => { const { isEnabled, requestFeedback } = useFeature("my-new-feature"); if (!isEnabled) { return null; } return ( <> ); } ``` -------------------------------- ### React SDK: Track Feature Adoption Source: https://docs.bucket.co/welcome/readme Illustrates how to track user interaction with a feature using the Bucket React SDK. The `track` function, available via the `useFeature` hook, can be invoked when a user engages with the feature, such as clicking a button. This helps in monitoring feature adoption rates. ```jsx import { useFeature } from "@bucketco/react-sdk"; const MyFeature = () => { const { isEnabled, requestFeedback, track } = useFeature("my-new-feature"); if (!isEnabled) { return null; } return ( <> ); } ``` -------------------------------- ### Bucket SDK Initialization and Feedback Customization Source: https://docs.bucket.co/product-handbook/feature-analysis/automated-feedback-surveys Details on initializing the Bucket SDK and requesting feedback, including options for language customization and overriding global configurations. The SDK can be configured via `bucket.init(options)` and `bucket.requestFeedback(options)`. ```APIDOC Bucket SDK Configuration and Feedback Customize the feedback widget's behavior, language, positioning, content, and design. Global Defaults: - Positioning: Lower right-hand corner of the viewport - Language: English - Theme: Light mode Methods: bucket.init(options) Initializes the Bucket SDK. Parameters: options (object): Configuration options. language (object, optional): Object containing translations to replace default English strings. Example: { "feedback_title": "Your feedback", "submit_button": "Send" } ... other initialization options ... bucket.requestFeedback(options) Requests feedback from the user. Parameters: options (object): Configuration options for the feedback request. language (object, optional): Object containing translations to replace default English strings. Example: { "feedback_title": "Your feedback", "submit_button": "Send" } ... other feedback request options ... Usage: // Initialize with custom language strings bucket.init({ language: { "feedback_title": "Tell us what you think!", "submit_button": "Send Feedback" } }); // Request feedback with custom language strings bucket.requestFeedback({ language: { "feedback_title": "Your opinion matters!", "submit_button": "Submit" } }); Related: - Custom styling via CSS :root scope. - Positioning options (Modal, Dialog, Pushover). - Overriding global configurations during initialization. ``` -------------------------------- ### Run Bucket CLI (New Project) Source: https://docs.bucket.co/api/cli Initializes the Bucket CLI, creates a new feature, and generates TypeScript types in a single command using npx or yarn. ```bash # npm npx bucket new ``` ```bash # yarn yarn bucket new ``` -------------------------------- ### Configure Browser/Node SDK for EU Data Residency Source: https://docs.bucket.co/product-handbook/data-residency Demonstrates how to initialize the BucketClient for the Browser and Node.js SDKs, specifying the `apiBaseUrl` to `front-eu.bucket.co` for EU data residency. ```ts // Browser SDK + Node SDK const bucketClient = new BucketClient({ publishableKey: "{YOUR_PUBLISHABLE_KEY}", apiBaseUrl: "https://front-eu.bucket.co", ... }); ``` -------------------------------- ### Initialize BucketProvider and useFeature Hook Source: https://docs.bucket.co/guides/release-beta-features Demonstrates how to initialize the BucketProvider with your publishable key and user/company details. It also shows how to use the useFeature hook to conditionally render components based on feature flags. ```typescript import { BucketProvider, useFeature } from "@bucketco/react-sdk"; const App = () => ( ); const newFeature = () => { const { isEnabled } = useFeature("new-feature"); if (!isEnabled) return null; return
Hello, World
; } ``` -------------------------------- ### BucketClient Constructor Source: https://docs.bucket.co/supported-languages/browser-sdk/globals Creates a new BucketClient instance. Requires InitOptions. Returns a BucketClient instance. ```ts new BucketClient(opts: InitOptions): BucketClient - Creates a new BucketClient instance. - Parameters: - opts: InitOptions - Returns: - BucketClient ``` -------------------------------- ### BucketClient API Source: https://docs.bucket.co/supported-languages/node-sdk/globals API documentation for the BucketClient class, including its constructor and methods for feature management, event tracking, and client context binding. ```APIDOC BucketClient API Documentation BucketClient The SDK client. Remarks: This is the main class for interacting with Bucket. It is used to evaluate feature flags, update user and company contexts, and track events. Example: ```ts // set the BUCKET_SECRET_KEY environment variable or pass the secret key to the constructor const client = new BucketClient(); // evaluate a feature flag const isFeatureEnabled = client.getFeature("feature-flag-key", { user: { id: "user-id" }, company: { id: "company-id" }, }); ``` Extended by: * EdgeClient Constructors: new BucketClient(options: ClientOptions): BucketClient Creates a new SDK client. See README for configuration options. Parameters: options: The options for the client or an existing client to clone. Returns: BucketClient Throws: An error if the options are invalid. Methods: bindClient(context: ContextWithTracking): BoundBucketClient Create a new client bound with the additional context. Note: This performs a shallow merge for user/company/other individually. Parameters: context: The context to bind the client to. Returns: BoundBucketClient: new client bound with the additional context flush(): Promise Flushes the batch buffer. Returns: Promise getFeature(key: TKey): Feature Get a specific feature for the user/company/other context bound to this client. Using the `isEnabled` property sends a `check` event to Bucket. Type Parameters: TKey extends string: The key of the feature to get. Parameters: key: The key of the feature to get. Returns: Feature: Features for the given user/company and whether each one is enabled or not getFeatureRemote(key: string): Promise Get remotely evaluated feature for the user/company/other context bound to this client. Parameters: key: The key of the feature to get. Returns: Promise: Feature for the given user/company and key and whether it's enabled or not getFeatures(): Record Get features for the user/company/other context bound to this client. Meant for use in serialization of features for transferring to the client-side/browser. Returns: Record: Features for the given user/company and whether each one is enabled or not getFeaturesRemote(): Promise> Get remotely evaluated feature for the user/company/other context bound to this client. Returns: Promise>: Features for the given user/company and whether each one is enabled or not track(event: string, options?: TrackOptions & { companyId: string; }): Promise Track an event in Bucket. Parameters: event: The event to track. options?: The options for the event. Returns: Promise Throws: An error if the event is invalid or the options are invalid. ``` -------------------------------- ### Get All Features Source: https://docs.bucket.co/supported-languages/node-sdk Retrieves a map of all available features based on the currently bound user, company, and custom context. This allows checking the status of multiple features simultaneously. ```typescript // get the current features (uses company, user and custom context to // evaluate the features). const features = boundClient.getFeatures(); const bothEnabled = features.huddle?.isEnabled && features.voiceHuddle?.isEnabled; ``` -------------------------------- ### Get Features from Bucket (JavaScript) Source: https://docs.bucket.co/integrations/posthog Retrieves all available features for the currently authenticated user from the Bucket client. The output is a JSON object detailing each feature's status. ```javascript const features = bucket.getFeatures(); ``` -------------------------------- ### HttpClient Interface and Methods Source: https://docs.bucket.co/supported-languages/node-sdk/globals Defines the contract for an HTTP client, abstracting away the underlying implementation. It includes methods for sending GET and POST requests with detailed parameter and response specifications. ```APIDOC HttpClient: // Interface for an HTTP client. // Remarks: Used to abstract HTTP client implementation. get( url: string, headers: Record, timeoutMs: number ): Promise> // Sends a GET request to the specified URL. // Type Parameters: // TResponse: The expected type of the response body. // Parameters: // url: The URL to send the request to. // headers: Key-value pairs for request headers. // timeoutMs: The timeout for the request in milliseconds. // Returns: A Promise resolving to HttpClientResponse containing the server's response. post( url: string, headers: Record, body: TBody ): Promise> // Sends a POST request to the specified URL. // Type Parameters: // TBody: The type of the request body. // TResponse: The expected type of the response body. // Parameters: // url: The URL to send the request to. // headers: Key-value pairs for request headers. // body: The data payload for the request. // Returns: A Promise resolving to HttpClientResponse containing the server's response. ``` -------------------------------- ### Initialize BucketProvider Context Source: https://docs.bucket.co/supported-languages/react-sdk Demonstrates how to wrap your React application with the BucketProvider. This component initializes the SDK, requiring a publishable key and optionally accepting user, company, and loading component configurations. ```tsx import { BucketProvider } from "@bucketco/react-sdk"; } > {/* children here are shown when loading finishes or immediately if no `loadingComponent` is given */} ``` -------------------------------- ### Bucket API GET /features Endpoint Source: https://docs.bucket.co/api/http-api Retrieves the complete list of features and their associated access rules. This endpoint is primarily intended for backend SDKs to fetch rules for local evaluation. ```APIDOC GET /features - Description: Retrieve all features with their respective access rules. - Authentication: Requires a secret key. - Example Request: GET /features Authorization: Bearer - Example Response: { "success": true, "features": [ { "key": "huddle", "targeting": { "version": 42, "rules": [ { "filter": { "type": "group", "operator": "and", "filters": [ { "type": "context", "field": "company.id", "operator": "IS", "values": ["acme_inc"] }, { "type": "rolloutPercentage", "partialRolloutAttribute": "company.id", "partialRolloutThreshold": 100000 } ] } } ] } } ] } - Related: See [API reference](../api-reference#features). ``` -------------------------------- ### Hash User ID for Zero PII Source: https://docs.bucket.co/supported-languages/browser-sdk Illustrates how to hash sensitive user identifiers (like email addresses) before sending them to Bucket to maintain Zero PII compliance. This example uses `sha256` for hashing. ```typescript import bucket from "@bucketco/browser-sdk"; import { sha256 } from "crypto-hash"; bucket.user(await sha256("john_doe")); ``` -------------------------------- ### Wrap App with BucketProvider Source: https://docs.bucket.co/supported-languages/vue-sdk Wraps the root of your Vue application with `BucketProvider` to initialize the SDK. It requires a `publishableKey` and optionally accepts `user` and `company` objects for feature targeting. Ensure to wrap with `` if using Nuxt. ```vue ``` -------------------------------- ### Bucket SDK Configuration Options Source: https://docs.bucket.co/supported-languages/node-sdk Details the configuration options available for the Bucket Node.js SDK, including their types, descriptions, environment variable mappings, and precedence order. Supports configuration via constructor, environment variables, and JSON files. ```APIDOC Bucket SDK Configuration: This section outlines the parameters for configuring the Bucket Node.js SDK. Configuration can be managed through the BucketClient constructor, environment variables, or a JSON configuration file (defaulting to `bucketConfig.json`). Configuration Precedence (Highest to Lowest): 1. Constructor Options 2. Environment Variables 3. Configuration File Configuration Options: secretKey: Type: string Description: The secret key used for authentication with Bucket's servers. Env Var: BUCKET_SECRET_KEY logLevel: Type: string Description: The log level for the SDK (e.g., "DEBUG", "INFO", "WARN", "ERROR"). Defaults to "INFO". Env Var: BUCKET_LOG_LEVEL offline: Type: boolean Description: Operate in offline mode. Defaults to `false`, but `true` in tests if the `TEST` env var is set. Env Var: BUCKET_OFFLINE apiBaseUrl: Type: string Description: The base API URL for the Bucket servers. Env Var: BUCKET_API_BASE_URL featureOverrides: Type: Record Description: An object specifying feature overrides for testing or local development. See examples for usage. Env Var: BUCKET_FEATURES_ENABLED, BUCKET_FEATURES_DISABLED configFile: Type: string Description: Path to the configuration file to load from disk. Defaults to `bucketConfig.json`. Env Var: BUCKET_CONFIG_FILE ``` -------------------------------- ### Get Feature Status with Context Source: https://docs.bucket.co/supported-languages/node-sdk Binds user and company context to the client to evaluate feature targeting. It retrieves a specific feature's targeting status, along with tracking and configuration details. ```typescript // configure the client const boundClient = bucketClient.bindClient({ user: { id: "john_doe", name: "John Doe", email: "john@acme.com", avatar: "https://example.com/users/jdoe", }, company: { id: "acme_inc", name: "Acme, Inc.", avatar: "https://example.com/companies/acme", }, }); // get the huddle feature using company, user and custom context to // evaluate the targeting. const { isEnabled, track, config } = boundClient.getFeature("huddle"); if (isEnabled) { // this is your feature gated code ... // send an event when the feature is used: track(); if (config?.key === "zoom") { // this code will run if a given remote configuration // is set up. } // CAUTION: if you plan to use the event for automated feedback surveys // call `flush` immediately after `track`. It can optionally be awaited // to guarantee the sent happened. boundClient.flush(); } ``` -------------------------------- ### EdgeClient Constructor Source: https://docs.bucket.co/supported-languages/node-sdk/globals Initializes a new instance of the EdgeClient class. It accepts an options object and overrides the constructor from the base BucketClient class. ```typescript new EdgeClient(options: EdgeClientOptions): EdgeClient Parameters: options: EdgeClientOptions - The options for the EdgeClient. Returns: EdgeClient - An instance of EdgeClient. Overrides: BucketClient.constructor ``` -------------------------------- ### Initialize Bucket SDK Source: https://docs.bucket.co/product-handbook/feature-entitlements Demonstrates initializing the Bucket SDK by identifying a user and associating them with a company. It includes setting company attributes such as the subscription plan, which is crucial for feature entitlement management. ```tsx // identify user bucket.user(userId1356, { name: “Rasmus Makwarth”, }); // associate user with company bucket.company(companyId51, { name: “Acme Inc.”, plan: “business”, }); ``` -------------------------------- ### Get Features (Local Context) - TypeScript Source: https://docs.bucket.co/supported-languages/node-sdk/globals Retrieves evaluated features for the current context, including user, company, and custom context. Requires `initialize` to be called first. Features are not returned if initialization is skipped. ```APIDOC getFeatures(options?: { context?: ContextWithTracking; }): Record Gets the evaluated features for the current context which includes the user, company, and custom context. Parameters: options: The options for the context. context: [`ContextWithTracking`](#contextwithtracking) Returns: Record The evaluated features. Remarks: Call `initialize` before calling this method to ensure the feature definitions are cached, no features will be returned otherwise. Inherited from: BucketClient.getFeatures ``` -------------------------------- ### Bucket.co Features API Endpoint Source: https://docs.bucket.co/api/api-reference Documentation for the GET request to the /features endpoint of the Bucket.co API. This entry is derived from an OpenAPI specification, providing details on the endpoint's functionality and expected interactions. ```APIDOC GET /features description: Fetches features from the Bucket.co API. parameters: - name: expanded in: query schema: type: boolean description: If true, returns expanded feature details. responses: '200': description: A list of features. content: application/json: schema: type: object properties: features: type: array items: type: object properties: id: type: string name: type: string description: type: string enabled: type: boolean '400': description: Bad Request '500': description: Internal Server Error ``` -------------------------------- ### Initialize Bucket Client Source: https://docs.bucket.co/supported-languages/node-sdk Creates a new instance of the BucketClient and initializes it. This client is used to fetch feature targeting definitions and should ideally be a single global instance. ```typescript import { BucketClient } from "@bucketco/node-sdk"; // Create a new instance of the client with the secret key. Additional options // are available, such as supplying a logger and other custom properties. // // We recommend that only one global instance of `client` should be created // to avoid multiple round-trips to our servers. export const bucketClient = new BucketClient(); // Initialize the client and begin fetching feature targeting definitions. // You must call this method prior to any calls to `getFeatures()`, // otherwise an empty object will be returned. bucketClient.initialize().then({ console.log("Bucket initialized!") }) ``` -------------------------------- ### Get Feature Status with useFeature Source: https://docs.bucket.co/supported-languages/vue-sdk Uses the `useFeature` hook to retrieve the enabled status of a feature. Accessing `isEnabled` automatically generates a `check` event. The hook returns an object with `isEnabled` and `config` properties. ```vue ```