npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unrevealed/node

v0.3.8

Published

Unrevealed SDK for Node

Downloads

477

Readme

Node SDK

The Node SDK helps you integrate Unrevealed in a Node server.

For Node.js in a serverless environment, check the serverless SDK instead.

Getting Started

npm install @unrevealed/node
yarn add @unrevealed/node
pnpm install @unrevealed/node

Usage

UnrevealedClient

The Unrevealed client takes an UnrevealedClientOptions object as a parameter:

const client = new UnrevealedClient({
  apiKey: UNREVEALED_API_KEY,
  logger: customLogger,
  defaults: {
    'feature-key': true,
  },
});

| Option | Type | Note | | ---------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------- | | apiKey* | string | Generate a Server API key on Unrevealed | | logger | UnrevealedLogger | An optional custom logger (compatible with winston loggers) | | defaults | Record<string, boolean> | An optional map of default value for your feature flags. Used if the connection gets lost with the Unrevealed API |

connect

await client.connect();

Call this once when initializing your server. The SDK will open a connection to our servers that will receive the rules for your feature flags, and real-time updates when any of those rules change. Rules are stored and evaluated locally, so evaluating feature flags is fast and synchronous.

close

client.close();

Closes the connection with the Unrevealed API.

isFeatureEnabled

client.isFeatureEnabled('feature-key', { user: { id: 'user-id', traits: {...} }, team: { id: 'team-id', traits: {...} } });

Returns true if a feature is enabled for a certain user in a certain team, false otherwise.

| Parameter | Type | Note | | -------------- | -------------------------------- | ---------------------------------------- | | featureKey* | string | The key of the feature you want to check | | options.user | { id: string, traits: object } | An optional user | | options.team | { id: string, traits: object } | An optional team |

getEnabledFeatures

client.getEnabledFeatures({ user: { id: 'user-id', traits: {...} }, team: { id: 'team-id', traits: {...} } });

Returns an array of the keys of all the features enabled for a certain user in a certain team.

| Parameter | Type | Note | | -------------- | -------------------------------- | ---------------- | | options.user | { id: string, traits: object } | An optional user | | options.team | { id: string, traits: object } | An optional team |

getFeatureAccess

client.getFeatureAccess('feature-key');

Returns a FeatureAccess object with the current access rules for the given feature:

interface FeatureAccess {
  fullAccess: boolean;
  userAccess: string[];
  teamAccess: string[];
  userPercentageAccess: number;
  teamPercentageAccess: number;
}
  • fullAccess is true if the feature is enabled for every user
  • userAccess is a list of user ids who have access to the feature
  • teamAccess is a list of team ids who have access to the feature
  • userPercentageAccess is a the percentage of users who have access to the feature if relevant
  • teamPercentageAccess is a the percentage of teams who have access to the feature if relevant

Percentages are always between 0 and 100 and are 0 if no progressive rollout is in use for the given feature.

identify

await client.identify({ user: { id: 'user-id', traits: {...} }, team: { id: 'team-id', traits: {...} } });

Identifies a user and its current team. This will make the user and its team show up in the Unrevealed app, allowing you to select them for a beta for example.

Type safety

You can make the identify and isFeatureEnabled functions type safe by using the code generator, and defining the traits of your users and teams in the app.