0.0.6 • Published 1 year ago

@flagbase/js-client-sdk v0.0.6

Weekly downloads
-
License
Mozilla Public Li...
Repository
-
Last release
1 year ago

Flagbase JavaScript Client SDK

The Flagbase JavaScript Client-side SDK is a lightweight library that enables your web applications to use feature flags easily and efficiently.

Features

  • Efficient and fast feature flag evaluations
  • Client-side API for accessing and manipulating flags, traits, and identifiers
  • Event-driven architecture with support for custom event listeners
  • Extensible, easy-to-use API for flag management

Installation

Using npm:

npm install @flagbase/js-client-sdk

Using yarn:

yarn add @flagbase/js-client-sdk

Usage

First, import the SDK:

import Client from "@flagbase/js-client-sdk";

Then, initialize the client:

const client = Client("your-client-key", {
  identifier: "your-identifier",
  traits: {
    "your-trait-key": "your-trait-value",
  },
});

Now, you can use the SDK to evaluate feature flags and manage user traits. Evaluating Feature Flags

const variation = client.variation("your-flag-key", "default-variation-key");

if (variation === "enabled") {
  // Execute the feature flag enabled code
} else {
  // Execute the feature flag disabled code
}

Managing User Traits

Get user traits:

const allTraits = client.getAllTraits();
const specificTrait = client.getTrait("your-trait-key");

Set user traits:

client.setTrait("your-trait-key", "new-trait-value");

Listening to Events

client.on("CONTEXT_CHANGE", (eventMessage, eventContext) => {
  console.log("Event:", eventMessage, eventContext);
});

client.off("CONTEXT_CHANGE");

API Reference Client

  • Client(clientKey: string, identity: Identity, opts?: ClientOptions): IClient

IClient

  • variation(flagKey: string, defaultVariationKey: string): Flag["variationKey"]
  • getIdentifier(): Identity["identifier"]
  • setIdentifier(identifier: string): void
  • getAllTraits(): Identity["traits"]
  • getTrait(traitKey: string): string | number
  • setTrait(traitKey: string, traitValue: string | number): void
  • getAllFlags(): Flagset
  • getInternalData(): InternalData
  • on(eventName: EventType, listenerFn: ListenerFn): void
  • off(eventName: EventType, listenerFn?: ListenerFn): void
  • clear(): void
  • destroy(): void

Contributing

Contributions are welcome! Please read our Contributing Guidelines for more information.

License

This project is licensed under the Mozilla Public License 2.0. See the LICENSE file for more details.

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago