0.0.6 • Published 3 years ago
@flagbase/js-client-sdk v0.0.6
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-sdkUsing yarn:
yarn add @flagbase/js-client-sdkUsage
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): voidgetAllTraits(): Identity["traits"]getTrait(traitKey: string): string | numbersetTrait(traitKey: string, traitValue: string | number): voidgetAllFlags(): FlagsetgetInternalData(): InternalDataon(eventName: EventType, listenerFn: ListenerFn): voidoff(eventName: EventType, listenerFn?: ListenerFn): voidclear(): voiddestroy(): 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.