0.3.8 • Published 5 months ago

@unrevealed/node v0.3.8

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

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,
  },
});
OptionTypeNote
apiKey*stringGenerate a Server API key on Unrevealed
loggerUnrevealedLoggerAn optional custom logger (compatible with winston loggers)
defaultsRecord<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.

ParameterTypeNote
featureKey*stringThe 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.

ParameterTypeNote
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.

0.3.1-rc.3

8 months ago

0.3.1-rc.2

8 months ago

0.3.1-rc.1

8 months ago

0.3.0

9 months ago

0.2.1

10 months ago

0.3.6

5 months ago

0.3.5

5 months ago

0.3.8

5 months ago

0.3.7

5 months ago

0.3.2

6 months ago

0.3.4

5 months ago

0.3.3

6 months ago

0.2.0

11 months ago

0.2.0-rc.1

11 months ago

0.1.1

12 months ago

0.1.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6-rc.1

1 year ago

0.0.6-rc.2

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.2-rc.1

1 year ago

0.0.1

1 year ago