Flagsmith / flagsmith-nodejs-client

Flagsmith Node JS Client. Flagsmith lets you manage features flags across web, mobile and server side applications. Get builds out faster. Control who has access to new features.

Home Page:https://flagsmith.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Have Typescript Module Support

raryson opened this issue · comments

Hi, I have started to use bullet-train-nodejs and I dont find Types module support. With this, I have created my own module type abstracting the bullet-train docs.

I think that can be extremely helpful if have natively in this module.
Here is the code:
https://gist.github.com/raryson/1c8e1345a7183209c9739a63361c5e6f

or

/**
 * Initialise the sdk against a particular environment
 */
export function init(config: {
  environmentID: string
  onError?: Function
  defaultFlags?: string[]
  api?: string
}): void

/**
 * Get the value of a particular feature e.g. bulletTrain.hasFeature("powerUserFeature")
 */
export function hasFeature(key: string): Promise<boolean>

/**
 * Get the value of a particular feature for a user e.g. bulletTrain.hasFeature("powerUserFeature", 1234)
 */
export function hasFeature(key: string, userId: string): Promise<boolean>

/**
 * Get the value of a particular feature e.g. bulletTrain.getValue("font_size")
 */
export function getValue(key: string): Promise<string>

/**
 * Get the value of a particular feature for a specificed user e.g. bulletTrain.getValue("font_size", 1234)
 */
export function getValue(key: string, userId: string): Promise<string>

/**
 * Trigger a manual fetch of the environment features
 */
export function getFlags(): Promise<IFlags>

/**
 * Trigger a manual fetch of the environment features for a given user id
 */
export function getFlagsForUser(userId: string): Promise<IFlags>

/**
 * Trigger a manual fetch of both the environment features and users' traits for a given user id
 */
export function getUserIdentity(userId: string): Promise<IUserIdentity>

/**
 * Trigger a manual fetch of a specific trait for a given user id
 */
export function getTrait(userId: string, key: string): Promise<ITraits>

/**
 * Set a specific trait for a given user id
 */
export function setTrait(
  userId: string,
  key: string,
  value: string
): IUserIdentity

interface IBulletTrainFeature {
  enabled: boolean
  value?: string
}

interface IFlags {
  [key: string]: IBulletTrainFeature
}

interface ITraits {
  [key: string]: string
}

interface IUserIdentity {
  flags: IBulletTrainFeature
  traits: ITraits
}

Hey, thanks very much for this. This was on my todo for the JS client too. I’ll take a look and get this into the module!

Published under 1.0.4, thank you so much for this!

Edit: improved some typings in 1.0.5