Skip to content

Commit

Permalink
prepare 5.8.0 release (launchdarkly#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly authored Apr 26, 2019
1 parent 566dea0 commit 4a0f51c
Show file tree
Hide file tree
Showing 23 changed files with 634 additions and 113 deletions.
8 changes: 0 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ workflows:
jobs:
- oldest-long-term-support-release
- current-release
- audit-dependencies

node-template: &node-template
steps:
Expand Down Expand Up @@ -35,10 +34,3 @@ jobs:
docker:
- image: circleci/node:latest
- image: redis

audit-dependencies:
docker:
- image: circleci/node:latest
steps:
- checkout
- run: npm audit
44 changes: 41 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
Contributing to the LaunchDarkly SDK for Node.js
================================================
# Contributing to the LaunchDarkly Server-Side SDK for Node.js

We encourage pull-requests and other contributions from the community. We've also published an [SDK contributor's guide](http://docs.launchdarkly.com/docs/sdk-contributors-guide) that provides a detailed explanation of how our SDKs work.
LaunchDarkly has published an [SDK contributor's guide](https://docs.launchdarkly.com/docs/sdk-contributors-guide) that provides a detailed explanation of how our SDKs work. See below for additional information on how to contribute to this SDK.

## Submitting bug reports and feature requests

The LaunchDarkly SDK team monitors the [issue tracker](https://github.com/launchdarkly/node-server-sdk/issues) in the SDK repository. Bug reports and feature requests specific to this SDK should be filed in this issue tracker. The SDK team will respond to all newly filed issues within two business days.

## Submitting pull requests

We encourage pull requests and other contributions from the community. Before submitting pull requests, ensure that all temporary or unintended code is removed. Don't worry about adding reviewers to the pull request; the LaunchDarkly SDK team will add themselves. The SDK team will acknowledge all pull requests within two business days.

## Build instructions

### Prerequisites

The project uses `npm`, which is bundled in all supported versions of Node.

### Building

To build, from the project root directory:

```
npm install
npm run build
```

### Testing

To run all unit tests:

```
npm test
```

By default, the full unit test suite includes live tests of the Redis integration. Those tests expect you to have a Redis instance running locally. To skip them, set the environment variable `LD_SKIP_DATABASE_TESTS=1` before running the tests.

To verify that the TypeScript declarations compile correctly (this involves compiling the file `test-types.ts`, so if you have changed any types or interfaces, you will want to update that code):

```
npm run check-typescript
```
101 changes: 22 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,46 @@
LaunchDarkly SDK for Node.js
===========================
# LaunchDarkly Server-Side SDK for Node.js

[![Circle CI](https://circleci.com/gh/launchdarkly/node-client/tree/master.svg?style=svg)](https://circleci.com/gh/launchdarkly/node-client/tree/master)
[![Circle CI](https://circleci.com/gh/launchdarkly/node-server-sdk/tree/master.svg?style=svg)](https://circleci.com/gh/launchdarkly/node-server-sdk/tree/master)

Supported Node versions
-----------------------
## LaunchDarkly overview

This version of the LaunchDarkly SDK has been tested with Node versions 6.14 and up.

Quick setup
-----------

0. Install the Node.js SDK with `npm`

npm install ldclient-node --save

1. Require the LaunchDarkly client:

var LaunchDarkly = require('ldclient-node');


2. Create a new LDClient with your SDK key:

var ld_client = LaunchDarkly.init("YOUR SDK KEY")
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/docs/getting-started) using LaunchDarkly today!

[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)

HTTPS proxy
------------
## Supported Node versions

Node provides built-in support for the use of an HTTPS proxy. You can use NPM to configure Node to proxy all network requests through the URL provided.
```
npm config set https-proxy https://web-proxy.domain.com:8080
```


If your proxy requires authentication then you can prefix the URN with your login information:
```
npm config set https-proxy http://user:[email protected]:8080
```


Your first feature flag
-----------------------

1. Create a new feature flag on your [dashboard](https://app.launchdarkly.com)
2. In your application code, use the feature's key to check whether the flag is on for each user:

ld_client.once('ready', function() {
ld_client.variation("your.flag.key", {"key" : "[email protected]"}, false, function(err, show_feature) {
if (show_feature) {
# application code to show the feature
} else {
# the code to run if the feature is off
}
});
});
This version of the LaunchDarkly SDK has been tested with Node versions 6.14 and up.

Using flag data from a file
---------------------------
## Getting started

For testing purposes, the SDK can be made to read feature flag state from a file or files instead of connecting to LaunchDarkly. See `FileDataSource` in the [TypeScript API documentation](https://github.com/launchdarkly/node-client/blob/master/index.d.ts) for more details.
Refer to the [SDK reference guide](https://docs.launchdarkly.com/docs/node-sdk-reference) for instructions on getting started with using the SDK.

Learn more
-----------
## Learn more

Check out our [documentation](http://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the [complete reference guide for this SDK](http://docs.launchdarkly.com/docs/node-sdk-reference).

Testing
-------
The authoritative description of all properties and methods is in the [TypeScript documentation](https://launchdarkly.github.io/node-server-sdk/).

## Testing

We run integration tests for all our SDKs using a centralized test harness. This approach gives us the ability to test for consistency across SDKs, as well as test networking behavior in a long-running application. These tests cover each method in the SDK, and verify that event sending, flag evaluation, stream reconnection, and other aspects of the SDK all behave correctly.

Contributing
------------
## Contributing

We encourage pull-requests and other contributions from the community. We've also published an [SDK contributor's guide](http://docs.launchdarkly.com/docs/sdk-contributors-guide) that provides a detailed explanation of how our SDKs work.
We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK.

About LaunchDarkly
-----------
## About LaunchDarkly

* LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
* Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
* Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
* Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
* Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
* LaunchDarkly provides feature flag SDKs for
* [Java](http://docs.launchdarkly.com/docs/java-sdk-reference "Java SDK")
* [JavaScript](http://docs.launchdarkly.com/docs/js-sdk-reference "LaunchDarkly JavaScript SDK")
* [PHP](http://docs.launchdarkly.com/docs/php-sdk-reference "LaunchDarkly PHP SDK")
* [Python](http://docs.launchdarkly.com/docs/python-sdk-reference "LaunchDarkly Python SDK")
* [Go](http://docs.launchdarkly.com/docs/go-sdk-reference "LaunchDarkly Go SDK")
* [Node.JS](http://docs.launchdarkly.com/docs/node-sdk-reference "LaunchDarkly Node SDK")
* [Electron](http://docs.launchdarkly.com/docs/electron-sdk-reference "LaunchDarkly Electron SDK")
* [.NET](http://docs.launchdarkly.com/docs/dotnet-sdk-reference "LaunchDarkly .Net SDK")
* [Ruby](http://docs.launchdarkly.com/docs/ruby-sdk-reference "LaunchDarkly Ruby SDK")
* [iOS](http://docs.launchdarkly.com/docs/ios-sdk-reference "LaunchDarkly iOS SDK")
* [Android](http://docs.launchdarkly.com/docs/android-sdk-reference "LaunchDarkly Android SDK")
* LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/docs) for a complete list.
* Explore LaunchDarkly
* [launchdarkly.com](http://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
* [docs.launchdarkly.com](http://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDKs
* [apidocs.launchdarkly.com](http://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
* [blog.launchdarkly.com](http://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
* [launchdarkly.com](https://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
* [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
* [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
* [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
* [Feature Flagging Guide](https://github.com/launchdarkly/featureflags/ "Feature Flagging Guide") for best practices and strategies
8 changes: 7 additions & 1 deletion docs/typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
// the properties are equivalent to the command-line options described here:
// https://typedoc.org/api/

let version = process.env.VERSION;
if (!version) {
const package = require('../package.json');
version = package.version;
}

module.exports = {
out: './docs/build/html',
exclude: [
'**/node_modules/**',
'test-types.ts'
],
name: 'LaunchDarkly Node SDK',
name: 'LaunchDarkly Server-Side Node SDK (' + version + ')',
readme: 'none', // don't add a home page with a copy of README.md
mode: 'file', // don't treat "index.d.ts" itself as a parent module
includeDeclarations: true, // allows it to process a .d.ts file instead of actual TS code
Expand Down
7 changes: 4 additions & 3 deletions event_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ function EventProcessor(sdkKey, config, errorReporter) {
}
}

request({
method: "POST",
var options = Object.assign({}, config.tlsParams, {
method: 'POST',
url: config.eventsUri + '/bulk',
headers: {
'Authorization': sdkKey,
Expand All @@ -208,7 +208,8 @@ function EventProcessor(sdkKey, config, errorReporter) {
body: events,
timeout: config.timeout * 1000,
agent: config.proxyAgent
}).on('response', function(resp, body) {
});
request(options).on('response', function(resp, body) {
if (resp.headers['date']) {
var date = Date.parse(resp.headers['date']);
if (date) {
Expand Down
3 changes: 3 additions & 0 deletions eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ function EventSource(url, eventSourceInitDict) {
}

options.rejectUnauthorized = !(eventSourceInitDict && eventSourceInitDict.rejectUnauthorized == false);
if (eventSourceInitDict && eventSourceInitDict.tlsParams) {
Object.assign(options, eventSourceInitDict.tlsParams); // these options are ignored if we're not using HTTPS
}

req = (isSecure ? https : http).request(options, function (res) {
// Handle HTTP redirects
Expand Down
2 changes: 1 addition & 1 deletion feature_store_event_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function FeatureStoreEventWrapper(featureStore, emitter) {
featureStore.all(dataKind.features, function(oldFlags){
featureStore.init(newData, function(){
var allFlags = {};
var newFlags = newData[dataKind.features] || {};
var newFlags = newData[dataKind.features.namespace] || {};
Object.assign(allFlags, oldFlags, newFlags);
var handledFlags = {};

Expand Down
29 changes: 28 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Type definitions for ldclient-node

/**
* This is the API reference for the LaunchDarkly SDK for Node.js.
* This is the API reference for the LaunchDarkly Server-Side SDK for Node.js.
*
* In typical usage, you will call [[init]] once at startup time to obtain an instance of
* [[LDClient]], which provides access to all of the SDK's functionality.
Expand Down Expand Up @@ -344,6 +344,33 @@ declare module 'ldclient-node' {
* Defaults to 300.
*/
userKeysFlushInterval?: number;

/**
* Additional parameters to pass to the Node HTTPS API for secure requests. These can include any
* of the TLS-related parameters supported by `https.request()`, such as `ca`, `cert`, and `key`.
*
* For more information, see the Node documentation for `https.request()` and `tls.connect()`.
*/
tlsParams?: LDTLSOptions;
}

/**
* Additional parameters to pass to the Node HTTPS API for secure requests. These can include any
* of the TLS-related parameters supported by `https.request()`, such as `ca`, `cert`, and `key`.
*
* For more information, see the Node documentation for `https.request()` and `tls.connect()`.
*/
export interface LDTLSOptions {
ca?: string | string[] | Buffer | Buffer[];
cert?: string | string[] | Buffer | Buffer[];
checkServerIdentity?: (servername: string, cert: any) => Error | undefined;
ciphers?: string;
pfx?: string | string[] | Buffer | Buffer[] | object[];
key?: string | string[] | Buffer | Buffer[] | object[];
passphrase?: string;
rejectUnauthorized?: boolean;
secureProtocol?: string;
servername?: string;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"jest": "24.5.0",
"jest-junit": "3.6.0",
"nock": "9.2.3",
"selfsigned": "1.10.4",
"tmp": "0.0.33",
"typedoc": "0.14.2",
"typescript": "3.0.1"
Expand Down
7 changes: 4 additions & 3 deletions polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ function PollingProcessor(config, requestor) {
startTime = new Date().getTime();
config.logger.debug("Polling LaunchDarkly for feature flag updates");
requestor.requestAllData(function(err, resp) {
elapsed = new Date().getTime() - startTime;
sleepFor = Math.max(config.pollInterval * 1000 - elapsed, 0);
const elapsed = new Date().getTime() - startTime;
const sleepFor = Math.max(config.pollInterval * 1000 - elapsed, 0);
config.logger.debug("Elapsed: %d ms, sleeping for %d ms", elapsed, sleepFor);
if (err) {
cb(new errors.LDPollingError(messages.httpErrorMessage(err.status, 'polling request', 'will retry')));
const message = err.status || err.message;
cb(new errors.LDPollingError(messages.httpErrorMessage(message, 'polling request', 'will retry')));
if (!errors.isHttpErrorRecoverable(err.status)) {
config.logger.error('Received 401 error, no further polling requests will be made since SDK key is invalid');
} else {
Expand Down
4 changes: 2 additions & 2 deletions requestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Requestor(sdkKey, config) {
var requestWithETagCaching = new ETagRequest(cacheConfig);

function makeRequest(resource) {
var requestParams = {
var requestParams = Object.assign({}, config.tlsParams, {
method: "GET",
url: config.baseUri + resource,
headers: {
Expand All @@ -32,7 +32,7 @@ function Requestor(sdkKey, config) {
},
timeout: config.timeout * 1000,
agent: config.proxyAgent
}
});

return function(cb, errCb) {
requestWithETagCaching(requestParams, function(err, resp, body) {
Expand Down
Loading

0 comments on commit 4a0f51c

Please sign in to comment.