Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@molassesapp/molasses-server

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@molassesapp/molasses-server

A Node (with TypeScript support) SDK for Molasses. It allows you to evaluate user's status for a feature. It also helps simplify logging events for A/B testing.

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Molasses Node SDK

codecov Build status

It includes the Node (with TypeScript support) SDK for Molasses. It allows you to evaluate user's status for a feature. It also helps simplify logging events for A/B testing.

Molasses-server uses polling to check if you have updated features. Once initialized, it takes microseconds to evaluate if a user is active.

Install

npm install @molassesapp/molasses-server

yarn add @molassesapp/molasses-server

Usage

To Require:

import { MolassesClient } from "@molassesapp/molasses-server"
// or
const { MolassesClient } = require("@molassesapp/molasses-server")

Start by initializing the client with an APIKey. This begins the polling for any feature updates. The updates happen every 15 seconds. This can be overriden with the refreshInterval field. If you decide not to track analytics events (experiment started, experiment success) you can turn them off by setting the sendEvents field to false

// Initialize with your API Key
const client = new MolassesClient({
  APIKey: "testapikey",
})

// Then init which is a promise
await client.init()

Check if feature is active

You can call isActive with the key name and optionally a user's information. The ID field is used to determine whether a user is part of a percentage of users and uniquely identies a user. If you have other user segments based on user parameterss you can pass those in the params field.

// Once initialized you can start calling isActive
client.isActive("FOO_TEST", {
  id: "123",
  params: {
    isBetaUser: "true",
  },
})

You can check if a feature is active for a user who is anonymous by just calling isActive with the key. You won't be able to do percentage roll outs or track that user's behavior.

client.isActive("FOO_TEST")

Experiments

To track whether an experiment was successful you can call ExperimentSuccess. ExperimentSuccess takes the feature's name, the molasses User and any additional parameters for the event.

client.ExperimentSuccess(
  "GOOGLE_SSO",
  {
    id: "baz",
    params: {
      teamId: "12356",
    },
  },
  {
    version: "v2.3.0",
  },
)

Methods

new MolassesClient(options)

Creates a new Molasses client. It takes a set of options.

Options
FieldRequiredTypeDescription
apiKeyrequiredstringThe API Key for the current environment
URLoptionalstringthe base URL for Molasses
sendEventsoptionalbooleanWhether to send analytic events back to Molasses. Defaults to true.
refreshIntervaloptionalnumberHow often Molasses should fetch the updated configuration. Defaults to 15000,

init()

Fetches configuration of features and begins polling

isActive(featureKey: string)

Will check if feature is active for ALL users

isActive(featureKey: string, user: User)

Will check if the feature is active for this particular based on the segment they are in.

experimentSuccess(featureKey: string, additionalInformation: string[string], user: User)

Will send an event success message when a user completes a set goal. This includes, whether user was in the experimental group (control or experiment), the experiment that was being tested and other metadata. If you want to include additional metadata use the additionalInformation argument.

stop()

Stops polling

FAQs

Package last updated on 06 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc