Module launchdarkly-server-sdk

Server-side SDK for LaunchDarkly.

Functions

registerLogger (logLevel, cb) Set the global logger for all SDK operations.
makeUser (fields) Create a new opaque user object.
version () Return SDK version.
makeClient (config, backend[, timeoutMilliseconds]) Initialize a new client, and connect to LaunchDarkly.
boolVariation (user, key, fallback) Evaluate a boolean flag
boolVariationDetail (user, key, fallback) Evaluate a boolean flag and return an explanation
intVariation (user, key, fallback) Evaluate an integer flag
intVariationDetail (user, key, fallback) Evaluate an integer flag and return an explanation
doubleVariation (user, key, fallback) Evaluate a double flag
doubleVariationDetail (user, key, fallback) Evaluate a double flag and return an explanation
stringVariation (user, key, fallback) Evaluate a string flag
stringVariationDetail (user, key, fallback) Evaluate a string flag and return an explanation
jsonVariation (user, key, fallback) Evaluate a json flag
jsonVariationDetail (user, key, fallback) Evaluate a json flag and return an explanation
flush () Immediately flushes queued events.
track (key, user[, data[, metric]]) Reports that a user has performed an event.
alias (currentUser, previousUser) Associates two users for analytics purposes by generating an alias event.
isInitialized () Check if a client has been fully initialized.
identify (user) Generates an identify event for a user.
allFlags (user) Returns a map from feature flag keys to values for a given user.


Functions

registerLogger (logLevel, cb)
Set the global logger for all SDK operations. This function is not thread safe, and if used should be done so before other operations. The default log level is "INFO".

Parameters:

  • logLevel string The level to at. Available options are: "FATAL", "CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE".
  • cb function The logging handler. Callback must be of the form "function (logLevel, logLine) ... end".
makeUser (fields)
Create a new opaque user object.

Parameters:

  • fields list of user fields.
    • key string The user's key
    • anonymous boolean Mark the user as anonymous (optional)
    • ip string Set the user's IP (optional)
    • firstName string Set the user's first name (optional)
    • lastName string Set the user's last name (optional)
    • email string Set the user's email (optional)
    • name string Set the user's name (optional)
    • avatar string Set the user's avatar (optional)
    • country string Set the user's country (optional)
    • secondary string Set the user's secondary key (optional)
    • privateAttributeNames table A list of attributes to redact (optional)
    • custom table Set the user's custom JSON (optional)

Returns:

    an opaque user object
version ()
Return SDK version.

Returns:

    SDK version string.
makeClient (config, backend[, timeoutMilliseconds])
Initialize a new client, and connect to LaunchDarkly.

Parameters:

  • config list of configuration options
    • key string Environment SDK key
    • baseURI string Set the base URI for connecting to LaunchDarkly. You probably don't need to set this unless instructed by LaunchDarkly. (optional)
    • streamURI string Set the streaming URI for connecting to LaunchDarkly. You probably don't need to set this unless instructed by LaunchDarkly. (optional)
    • eventsURI string Set the events URI for connecting to LaunchDarkly. You probably don't need to set this unless instructed by LaunchDarkly. (optional)
    • stream boolean Enables or disables real-time streaming flag updates. When set to false, an efficient caching polling mechanism is used. We do not recommend disabling streaming unless you have been instructed to do so by LaunchDarkly support. Defaults to true. (optional)
    • sendEvents string Sets whether to send analytics events back to LaunchDarkly. By default, the client will send events. This differs from Offline in that it only affects sending events, not streaming or polling. (optional)
    • eventsCapacity int The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded. (optional)
    • timeout int The connection timeout to use when making requests to LaunchDarkly. (optional)
    • flushInterval int he time between flushes of the event buffer. Decreasing the flush interval means that the event buffer is less likely to reach capacity. (optional)
    • pollInterval int The polling interval (when streaming is disabled) in milliseconds. (optional)
    • offline boolean Sets whether this client is offline. An offline client will not make any network connections to LaunchDarkly, and will return default values for all feature flags. (optional)
    • allAttributesPrivate boolean Sets whether or not all user attributes (other than the key) should be hidden from LaunchDarkly. If this is true, all user attribute values will be private, not just the attributes specified in PrivateAttributeNames. (optional)
    • inlineUsersInEvents boolean Set to true if you need to see the full user details in every analytics event. (optional)
    • userKeysCapacity int The number of user keys that the event processor can remember at an one time, so that duplicate user details will not be sent in analytics. (optional)
    • userKeysFlushInterval int The interval at which the event processor will reset its set of known user keys, in milliseconds. (optional)
    • privateAttributeNames table Marks a set of user attribute names private. Any users sent to LaunchDarkly with this configuration active will have attributes with these names removed. (optional)
  • backend config.featureStoreBackend Persistent feature store backend. (optional)
  • timeoutMilliseconds int How long to wait for flags to download. If the timeout is reached a non fully initialized client will be returned.

Returns:

    A fresh client.
boolVariation (user, key, fallback)
Evaluate a boolean flag

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback boolean The value to return on error

Returns:

    boolean The evaluation result, or the fallback value
boolVariationDetail (user, key, fallback)
Evaluate a boolean flag and return an explanation

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback boolean The value to return on error

Returns:

    table The evaluation explanation
intVariation (user, key, fallback)
Evaluate an integer flag

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback int The value to return on error

Returns:

    int The evaluation result, or the fallback value
intVariationDetail (user, key, fallback)
Evaluate an integer flag and return an explanation

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback int The value to return on error

Returns:

    table The evaluation explanation
doubleVariation (user, key, fallback)
Evaluate a double flag

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback number The value to return on error

Returns:

    double The evaluation result, or the fallback value
doubleVariationDetail (user, key, fallback)
Evaluate a double flag and return an explanation

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback number The value to return on error

Returns:

    table The evaluation explanation
stringVariation (user, key, fallback)
Evaluate a string flag

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback string The value to return on error

Returns:

    string The evaluation result, or the fallback value
stringVariationDetail (user, key, fallback)
Evaluate a string flag and return an explanation

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback string The value to return on error

Returns:

    table The evaluation explanation
jsonVariation (user, key, fallback)
Evaluate a json flag

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback table The value to return on error

Returns:

    table The evaluation result, or the fallback value
jsonVariationDetail (user, key, fallback)
Evaluate a json flag and return an explanation

Parameters:

  • user user An opaque user object from makeUser
  • key string The key of the flag to evaluate.
  • fallback table The value to return on error

Returns:

    table The evaluation explanation
flush ()
Immediately flushes queued events.

Returns:

    nil
track (key, user[, data[, metric]])
Reports that a user has performed an event. Custom data, and a metric can be attached to the event as JSON.

Parameters:

  • key string The name of the event
  • user user An opaque user object from makeUser
  • data table A value to be associated with an event (optional)
  • metric number A value to be associated with an event (optional)

Returns:

    nil
alias (currentUser, previousUser)
Associates two users for analytics purposes by generating an alias event.

Parameters:

  • currentUser user An opaque user object from makeUser
  • previousUser user An opaque user object from makeUser

Returns:

    nil
isInitialized ()
Check if a client has been fully initialized. This may be useful if the initialization timeout was reached.

Returns:

    boolean true if fully initialized
identify (user)
Generates an identify event for a user.

Parameters:

  • user user An opaque user object from makeUser

Returns:

    nil
allFlags (user)
Returns a map from feature flag keys to values for a given user. This does not send analytics events back to LaunchDarkly.

Parameters:

  • user user An opaque user object from makeUser

Returns:

    table
generated by LDoc 1.4.6 Last updated 2022-02-08 21:44:44