launchdarkly-node-client-sdk 1.5.2 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +1,53 @@
1
1
  version: 2.1
2
2
 
3
3
  orbs:
4
- win: circleci/windows@1.0.0
4
+ win: circleci/windows@2.4.0
5
5
 
6
6
  workflows:
7
7
  test:
8
8
  jobs:
9
- - build-test:
10
- name: current Node
11
- docker-image: circleci/node:latest
12
- with-lint: true
13
- - build-test:
14
- name: oldest supported Node
15
- docker-image: circleci/node:6
16
- with-lint: false
9
+ # CircleCI's current generation of Node images, cimg/node, allow you to leave the
10
+ # patch version unpinned, but require you to specify the minor version. The one
11
+ # exception is cimg/node:current, which will always give us the latest release in
12
+ # the latest major version-- and the latest major version is where it's most likely
13
+ # that there would be a new minor version, anyway.
14
+ - build-test-linux:
15
+ name: latest Node version
16
+ docker-image: cimg/node:current
17
+ run-lint: true
18
+ - build-test-linux:
19
+ name: Node 16.3
20
+ docker-image: cimg/node:16.3
21
+ - build-test-linux:
22
+ name: Node 15.14
23
+ docker-image: cimg/node:15.14
24
+ - build-test-linux:
25
+ name: Node 14.17
26
+ docker-image: cimg/node:14.17
27
+ - build-test-linux:
28
+ name: Node 13.14
29
+ docker-image: cimg/node:13.14
30
+ - build-test-linux:
31
+ name: Node 12.22
32
+ docker-image: cimg/node:12.22
33
+ - build-test-windows:
34
+ name: Windows
17
35
 
18
36
  jobs:
19
- build-test:
37
+ build-test-linux:
20
38
  parameters:
21
39
  docker-image:
22
40
  type: string
23
- with-lint:
41
+ run-lint:
24
42
  type: boolean
25
43
  default: false
26
44
 
27
45
  docker:
28
46
  - image: <<parameters.docker-image>>
29
47
 
48
+ environment:
49
+ NODE_ENV: test
50
+
30
51
  steps:
31
52
  - checkout
32
53
  - run: echo "Node version:" `node --version`
@@ -39,7 +60,7 @@ jobs:
39
60
  JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml"
40
61
 
41
62
  - when:
42
- condition: <<parameters.with-lint>>
63
+ condition: <<parameters.run-lint>>
43
64
  steps:
44
65
  - run: npm run lint:all
45
66
  - run: npm run check-typescript
@@ -52,3 +73,17 @@ jobs:
52
73
  path: reports/junit
53
74
  - store_artifacts:
54
75
  path: reports/junit
76
+
77
+ build-test-windows:
78
+ executor:
79
+ name: win/default
80
+ shell: powershell.exe
81
+
82
+ environment:
83
+ NODE_ENV: test
84
+
85
+ steps:
86
+ - checkout
87
+ - run: node --version
88
+ - run: npm install
89
+ - run: npm test
@@ -1,3 +1,5 @@
1
+ version: 2
2
+
1
3
  repo:
2
4
  public: node-client-sdk
3
5
  private: node-client-sdk-private
@@ -6,11 +8,14 @@ publications:
6
8
  - url: https://www.npmjs.com/package/launchdarkly-node-client-sdk
7
9
  description: npm
8
10
 
9
- template:
10
- name: npm
11
+ jobs:
12
+ - docker:
13
+ image: node:12-buster
14
+ template:
15
+ name: npm
11
16
 
12
17
  documentation:
13
- githubPages: true
18
+ gitHubPages: true
14
19
  title: LaunchDarkly Client-Side Node SDK
15
20
 
16
21
  sdk:
package/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  All notable changes to the LaunchDarkly Client-Side SDK for Node.js will be documented in this file.
4
4
 
5
+ ## [2.0.1] - 2022-02-17
6
+ ### Fixed:
7
+ - If the SDK receives invalid JSON data from a streaming connection (possibly as a result of the connection being cut off), it now uses its regular error-handling logic: the error is emitted as an `error` event or, if there are no `error` event listeners, it is logged. Previously, the error would be thrown as an unhandled exception.
8
+
9
+ ## [2.0.0] - 2022-01-26
10
+ This major version release is for updating Node.js compatibility, simplifying the SDK's dependencies, and removing deprecated names.
11
+
12
+ Except for the dependency changes described below which may require minor changes in your build, and a minor new logging feature, usage of the SDK has not changed in this release. For more details about changes that may be necessary, see the [1.x to 2.0 migration guide](https://docs.launchdarkly.com/sdk/client-side/node-js/migration-1-to-2).
13
+
14
+ Dropping support for obsolete Node.js versions makes it easier to maintain the SDK and keep its dependencies up to date. See LaunchDarkly's [End of Life Policy](https://launchdarkly.com/policies/end-of-life-policy/) regarding platform version support.
15
+
16
+ Simplifying dependencies reduces the size of the SDK bundle, as well as reducing potential compatibility problems and vulnerabilities.
17
+
18
+ ### Added:
19
+ - Added `basicLogger`, allowing customization of the SDK's default logging behavior without having to use Winston or provide a full `LDLogger` implementation.
20
+
21
+ ### Changed:
22
+ - The minimum Node.js version is now 12.0.
23
+ - Updated dependencies to newer versions and/or more actively maintained packages.
24
+ - In TypeScript, the property `LDEvaluationDetail.reason` now has a type of `LDEvaluationReason | undefined`, which correctly reflects the fact that evaluation reasons may not always be available.
25
+
26
+ ### Fixed:
27
+ - If the platform local storage mechanism throws an exception (for instance, if file permissions do not allow the data to be saved), the SDK now correctly catches the exception and logs a message about the failure. It will only log this message once during the lifetime of the SDK client.
28
+
29
+ ### Removed:
30
+ - Removed the dependency on [Winston](https://www.npmjs.com/package/winston). You can still tell the SDK to use a Winston logger instance that you have created, just as before, so this change should not affect any applications that are using Winston. But the SDK no longer uses Winston to create a default logger if the application does not specify a logger; instead, it uses the `basicLogger` implementation, which uses the same format as the previous default Winston configuration, so again there should be no visible difference.
31
+ - Removed `createConsoleLogger`, which is replaced by the more flexible `basicLogger`.
32
+ - Removed the type `NonNullableLDEvaluationReason`, which was a side effect of `LDEvaluationDetail.reason` being incorrectly defined before.
33
+ - Removed all types, properties, and functions that were deprecated as of the last 1.x release.
34
+
5
35
  ## [1.5.2] - 2021-06-10
6
36
  ### Fixed:
7
37
  - Events for the [LaunchDarkly debugger](https://docs.launchdarkly.com/home/flags/debugger) are now properly pre-processed to omit private user attributes, as well as enforce only expected top level attributes are sent.
package/CONTRIBUTING.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Contributing to the LaunchDarkly Client-Side SDK for Node.js
2
2
 
3
- 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.
3
+ LaunchDarkly has published an [SDK contributor's guide](https://docs.launchdarkly.com/sdk/concepts/contributors-guide) that provides a detailed explanation of how our SDKs work. See below for additional information on how to contribute to this SDK.
4
4
 
5
5
  ## Submitting bug reports and feature requests
6
6
 
@@ -14,7 +14,7 @@ We encourage pull requests and other contributions from the community. Before su
14
14
 
15
15
  ### Prerequisites
16
16
 
17
- The project uses `npm`, which is bundled in all supported versions of Node.
17
+ The project should be built and tested against the lowest compatible version, Node 12. It uses `npm`, which is bundled in all supported versions of Node.
18
18
 
19
19
  Note that much of the basic SDK logic, which is common to all of the LaunchDarkly client-side JavaScript-based SDKs, is in the `launchdarkly-js-sdk-common` package within [js-client-sdk](https://github.com/launchdarkly/js-client-sdk). This is pulled in automatically by `npm` when you build the SDK, but if you are planning to make changes that affect the common code, you will need to check out that repository as well.
20
20
 
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # LaunchDarkly Client-Side SDK for Node.js
2
2
 
3
- [![Circle CI](https://circleci.com/gh/launchdarkly/node-client-sdk.svg?style=svg)](https://circleci.com/gh/launchdarkly/node-client-sdk)
3
+ [![NPM](https://img.shields.io/npm/v/launchdarkly-node-client-sdk.svg?style=flat-square)](https://www.npmjs.com/package/launchdarkly-node-client-sdk)
4
+ [![CircleCI](https://circleci.com/gh/launchdarkly/node-client-sdk.svg?style=svg)](https://circleci.com/gh/launchdarkly/node-client-sdk)
5
+ [![Documentation](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://launchdarkly.github.io/node-client-sdk)
4
6
 
5
7
  The LaunchDarkly Client-Side SDK for Node.js is designed primarily for use by code that is deployed to an end user, such as in a desktop application or a smart device. It follows the client-side LaunchDarkly model for single-user contexts (much like our mobile or JavaScript SDKs). It is not intended for use in multi-user systems such as web servers and applications.
6
8
 
@@ -8,21 +10,21 @@ For using LaunchDarkly in *server-side* Node.js applications, refer to our [Serv
8
10
 
9
11
  ## LaunchDarkly overview
10
12
 
11
- [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!
13
+ [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/home/getting-started) using LaunchDarkly today!
12
14
 
13
15
  [![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
14
16
 
15
17
  ## Supported Node versions
16
18
 
17
- This version of the LaunchDarkly SDK has been tested with Node 6.14 and up.
19
+ This version of the LaunchDarkly SDK is compatible with Node.js versions 12 and above.
18
20
 
19
21
  ## Getting started
20
22
 
21
- Refer to the [SDK documentation](https://docs.launchdarkly.com/docs/node-client-sdk-reference#section-getting-started) for instructions on getting started with using the SDK.
23
+ Refer to the [SDK documentation](https://docs.launchdarkly.com/sdk/client-side/node-js#getting-started) for instructions on getting started with using the SDK.
22
24
 
23
25
  ## Learn more
24
26
 
25
- Check out our [documentation](https://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](https://docs.launchdarkly.com/docs/node-client-sdk-reference).
27
+ Read our [documentation](https://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](https://docs.launchdarkly.com/docs/node-client-sdk-reference).
26
28
 
27
29
  The authoritative description of all properties and methods is in the [TypeScript documentation](https://launchdarkly.github.io/node-client-sdk/).
28
30
 
@@ -41,7 +43,7 @@ We encourage pull requests and other contributions from the community. Check out
41
43
  * 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?).
42
44
  * 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.
43
45
  * 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.
44
- * 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.
46
+ * LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
45
47
  * Explore LaunchDarkly
46
48
  * [launchdarkly.com](https://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
47
49
  * [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launchdarkly-node-client-sdk",
3
- "version": "1.5.2",
3
+ "version": "2.0.2",
4
4
  "description": "LaunchDarkly Client-Side SDK for Node.js",
5
5
  "author": "LaunchDarkly <team@launchdarkly.com>",
6
6
  "license": "Apache-2.0",
@@ -14,10 +14,13 @@
14
14
  "scripts": {
15
15
  "lint": "eslint --format 'node_modules/eslint-formatter-pretty' --ignore-path .eslintignore",
16
16
  "lint:all": "eslint --format 'node_modules/eslint-formatter-pretty' --ignore-path .eslintignore src",
17
- "test": "NODE_ENV=test jest",
18
- "test:junit": "NODE_ENV=test jest --testResultsProcessor jest-junit",
17
+ "test": "jest",
18
+ "test:junit": "jest --testResultsProcessor jest-junit",
19
19
  "check-typescript": "node_modules/typescript/bin/tsc"
20
20
  },
21
+ "engines": {
22
+ "node": ">= 12.0.0"
23
+ },
21
24
  "devDependencies": {
22
25
  "@babel/core": "^7.9.6",
23
26
  "@babel/preset-env": "^7.9.6",
@@ -32,8 +35,8 @@
32
35
  "eslint-formatter-pretty": "^3.0.1",
33
36
  "eslint-plugin-babel": "^5.3.0",
34
37
  "eslint-plugin-prettier": "^3.1.3",
35
- "jest": "^24.7.3",
36
- "jest-junit": "^10.0.0",
38
+ "jest": "^27.4.7",
39
+ "jest-junit": "^13.0.0",
37
40
  "launchdarkly-js-test-helpers": "1.2.1",
38
41
  "prettier": "^2.0.5",
39
42
  "readline-sync": "^1.4.9",
@@ -42,11 +45,10 @@
42
45
  "typescript": "^3.8.3"
43
46
  },
44
47
  "dependencies": {
45
- "launchdarkly-eventsource": "1.4.1",
46
- "launchdarkly-js-sdk-common": "3.3.2",
48
+ "launchdarkly-eventsource": "1.4.3",
49
+ "launchdarkly-js-sdk-common": "4.0.3",
47
50
  "node-localstorage": "^1.3.1",
48
- "original": "^1.0.0",
49
- "winston": "^3.2.1"
51
+ "original": "^1.0.0"
50
52
  },
51
53
  "repository": {
52
54
  "type": "git",
@@ -35,7 +35,7 @@ describe('LDClient', () => {
35
35
 
36
36
  expect(server.requestCount()).toEqual(1);
37
37
  const req = await server.nextRequest();
38
- expect(req.headers['x-launchdarkly-user-agent']).toMatch(/^NodeClientSide\//);
38
+ expect(req.headers['user-agent']).toMatch(/^NodeClientSide\//);
39
39
  });
40
40
  });
41
41
  });
@@ -47,7 +47,7 @@ describe('LDClient TLS configuration', () => {
47
47
  diagnosticOptOut: true,
48
48
  };
49
49
  await withCloseable(LDClient.initialize(envName, user, config), async client => {
50
- await expect(client.waitForInitialization()).rejects.toThrow(/network error.*self signed/);
50
+ await expect(client.waitForInitialization()).rejects.toThrow(/network error.*self[- ]signed/);
51
51
  });
52
52
  });
53
53
  });
@@ -0,0 +1,10 @@
1
+ const { commonBasicLogger } = require('launchdarkly-js-sdk-common');
2
+ const { format } = require('util');
3
+
4
+ function basicLogger(options) {
5
+ return commonBasicLogger({ destination: console.log, ...options }, format);
6
+ }
7
+
8
+ module.exports = {
9
+ basicLogger,
10
+ };
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const common = require('launchdarkly-js-sdk-common');
2
- const winston = require('winston');
2
+ const { basicLogger } = require('./basicLogger');
3
3
  const nodePlatform = require('./nodePlatform');
4
4
  const packageJson = require('../package.json');
5
5
 
@@ -12,7 +12,7 @@ function initialize(env, user, options = {}) {
12
12
  tlsParams: { type: 'object' },
13
13
  };
14
14
  if (!options.logger) {
15
- extraOptionDefs.logger = { default: createDefaultLogger() };
15
+ extraOptionDefs.logger = { default: basicLogger() };
16
16
  }
17
17
  const clientVars = common.initialize(env, user, options, platform, extraOptionDefs);
18
18
 
@@ -21,25 +21,8 @@ function initialize(env, user, options = {}) {
21
21
  return clientVars.client;
22
22
  }
23
23
 
24
- function createDefaultLogger() {
25
- const prefixFormat = winston.format(info => {
26
- // eslint-disable-next-line no-param-reassign
27
- info.message = `[LaunchDarkly] ${info.message ? info.message : ''}`;
28
- return info;
29
- });
30
-
31
- return winston.createLogger({
32
- level: 'info',
33
- transports: [
34
- new winston.transports.Console({
35
- format: winston.format.combine(prefixFormat(), winston.format.simple()),
36
- }),
37
- ],
38
- });
39
- }
40
-
41
24
  module.exports = {
42
- initialize: initialize,
43
- createConsoleLogger: common.createConsoleLogger,
25
+ initialize,
26
+ basicLogger,
44
27
  version: packageJson.version,
45
28
  };
package/test-types.ts CHANGED
@@ -4,8 +4,10 @@
4
4
 
5
5
  import * as ld from 'launchdarkly-node-client-sdk';
6
6
 
7
+ var ver: string = ld.version;
8
+
7
9
  var emptyOptions: ld.LDOptions = {};
8
- var logger: ld.LDLogger = ld.createConsoleLogger('info');
10
+ var logger: ld.LDLogger = ld.basicLogger({ level: 'info' });
9
11
  var allOptions: ld.LDOptions = {
10
12
  bootstrap: { },
11
13
  baseUrl: '',
@@ -22,7 +24,6 @@ var allOptions: ld.LDOptions = {
22
24
  allowFrequentDuplicateEvents: true,
23
25
  sendEventsOnlyForVariation: true,
24
26
  flushInterval: 1,
25
- samplingInterval: 1,
26
27
  streamReconnectDelay: 1,
27
28
  logger: logger,
28
29
  autoAliasingOptOut: true
@@ -72,7 +73,7 @@ var stringFlagValue: ld.LDFlagValue = client.variation('key', 'default');
72
73
  var detail: ld.LDEvaluationDetail = client.variationDetail('key', 'default');
73
74
  var detailValue: ld.LDFlagValue = detail.value;
74
75
  var detailIndex: number | undefined = detail.variationIndex;
75
- var detailReason: ld.LDEvaluationReason = detail.reason;
76
+ var detailReason: ld.LDEvaluationReason | undefined = detail.reason;
76
77
 
77
78
  client.setStreaming(true);
78
79
  client.setStreaming();
package/typings.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * In typical usage, you will call [[initialize]] in the main process at startup time to obtain an
5
5
  * an instance of [[LDClient]].
6
6
  *
7
- * For more information, see the [SDK reference guide](http://docs.launchdarkly.com/docs/node-client-sdk-reference).
7
+ * For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/client-side/node-js).
8
8
  */
9
9
  declare module 'launchdarkly-node-client-sdk' {
10
10
 
@@ -12,16 +12,23 @@ declare module 'launchdarkly-node-client-sdk' {
12
12
  export * from 'launchdarkly-js-sdk-common';
13
13
 
14
14
  import {
15
+ BasicLoggerOptions,
15
16
  LDEvaluationDetail,
16
17
  LDEvaluationReason,
17
18
  LDFlagSet,
18
19
  LDFlagValue,
19
20
  LDClientBase,
21
+ LDLogger,
20
22
  LDOptionsBase,
21
23
  LDUser
22
24
  } from 'launchdarkly-js-sdk-common';
23
25
  //// DOCBUILD-END-REPLACE
24
26
 
27
+ /**
28
+ * The current version string of the SDK.
29
+ */
30
+ export const version: string;
31
+
25
32
  /**
26
33
  * Creates an instance of the LaunchDarkly client.
27
34
  *
@@ -84,8 +91,44 @@ declare module 'launchdarkly-node-client-sdk' {
84
91
  *
85
92
  * Applications should configure the client at startup time with [[initialize]], and reuse the same instance.
86
93
  *
87
- * For more information, see the [SDK Reference Guide](http://docs.launchdarkly.com/docs/node-client-sdk-reference).
94
+ * For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/node-js).
88
95
  */
89
96
  export interface LDClient extends LDClientBase {
90
97
  }
98
+
99
+ /**
100
+ * Provides a simple [[LDLogger]] implementation.
101
+ *
102
+ * This logging implementation uses a simple format that includes only the log level
103
+ * and the message text. Output is written to the standard error stream (`console.error`).
104
+ * You can filter by log level as described in [[BasicLoggerOptions.level]].
105
+ *
106
+ * To use the logger created by this function, put it into [[LDOptions.logger]]. If
107
+ * you do not set [[LDOptions.logger]] to anything, the SDK uses a default logger
108
+ * that is equivalent to `ld.basicLogger({ level: 'info' })`.
109
+ *
110
+ * @param options Configuration for the logger. If no options are specified, the
111
+ * logger uses `{ level: 'info' }`.
112
+ *
113
+ * @example
114
+ * This example shows how to use `basicLogger` in your SDK options to enable console
115
+ * logging only at `warn` and `error` levels.
116
+ * ```javascript
117
+ * const ldOptions = {
118
+ * logger: ld.basicLogger({ level: 'warn' }),
119
+ * };
120
+ * ```
121
+ *
122
+ * @example
123
+ * This example shows how to use `basicLogger` in your SDK options to cause log
124
+ * output to go to `console.log` instead of `console.error`.
125
+ * ```javascript
126
+ * const ldOptions = {
127
+ * logger: ld.basicLogger({ destination: console.log }),
128
+ * };
129
+ * ```
130
+ */
131
+ export function basicLogger(
132
+ options?: BasicLoggerOptions
133
+ ): LDLogger;
91
134
  }