Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
env: {
node: true,
},
extends: [
'airbnb-base',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used the airbnb style as the base. It is very popular and so will produce a style very familiar to many developers.

'airbnb-typescript/base'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.eslint.json'
},
plugins: [
'@typescript-eslint',
],
ignorePatterns: ["**/dist/**"],
rules: {
},
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package-lock.json
dist/
node_modules/
**/*.tsbuildinfo
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contributing to the LaunchDarkly Server-Side SDK for Node.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left the contributing and readme as node specific for now.


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.

## 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 should be built and tested against the lowest compatible version, Node 12. It uses `npm`, which is bundled in all supported versions of Node.

### Setup

To install project dependencies, from the project root directory:

```
npm install
```

### Testing

To run all unit tests:

```
npm test
```

To run the SDK contract test suite (see [`contract-tests/README.md`](./contract-tests/README.md)):

```bash
npm run contract-tests
```

### Auditing package dependencies

The `npm audit` tool compares all dependencies and transitive dependencies to a database of package versions with known vulnerabilities. However, the output of this tool includes both runtime and development dependencies.

Runtime dependencies can affect applications using the SDK; they can only be fixed by updating one of the explicit dependencies in `package.json`. Development dependencies cannot affect applications, but will still cause `npm audit` to flag the project; they can be fixed by running `npm audit fix` to add overrides for transitive dependencies in `package-lock.json`.

It is important _not_ to run `npm audit fix` if there are any bad _runtime_ dependencies, because it will hide the problem in our own build, without actually fixing the vulnerability when an application uses the SDK.

The script `scripts/better-audit.sh`, which is run in the CI build and can also be run manually, processes the output of `npm audit` to eliminate all duplicate entries and then determines whether each entry is coming from a runtime dependency or a development dependency. If there are any runtime ones, it terminates with an error code so the build will fail.
13 changes: 13 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2022 Catamorphic, Co.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# LaunchDarkly Server-Side SDK for JavaScript

<!--
These will need updated. Likely the NPM packge for node will be the same.

[![NPM](https://img.shields.io/npm/v/launchdarkly-node-server-sdk.svg?style=flat-square)](https://www.npmjs.com/package/launchdarkly-node-server-sdk)
[![CircleCI](https://circleci.com/gh/launchdarkly/node-server-sdk.svg?style=svg)](https://circleci.com/gh/launchdarkly/node-server-sdk)
[![Documentation](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://launchdarkly.github.io/node-server-sdk) -->

The LaunchDarkly Server-Side SDK for Node.js is designed primarily for use in multi-user systems such as web servers and applications. It follows the server-side LaunchDarkly model for multi-user contexts. It is not intended for use in desktop and embedded systems applications.

For using LaunchDarkly in *client-side* Node.js applications, refer to our [Client-side Node.js SDK](https://github.com/launchdarkly/node-client-sdk).

## LaunchDarkly overview

[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!

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

## Supported Node versions

This version of the LaunchDarkly SDK is compatible with Node.js versions 12 and above.

## Getting started

Refer to the [SDK reference guide](https://docs.launchdarkly.com/sdk/server-side/node-js) for instructions on getting started with using the SDK.

## 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](https://docs.launchdarkly.com/sdk/server-side/node-js).

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

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

* 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 a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
* Explore LaunchDarkly
* [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
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a workspace package.json. Which allows sharing dependencies, dependencies between packages in this repository, and for everything to be built at the top level.

"name": "@launchdarkly/js-server-sdk",
"workspaces": [
"sdk-common",
"server-sdk-common",
"platform-node"
],
"scripts": {
"clean": "tsc --build --clean",
"build": "tsc --build",
"lint": "eslint . --ext .ts",
"lint:fix": "npm run lint -- --fix"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint": "^8.14.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-plugin-import": "^2.26.0"
}
}
27 changes: 27 additions & 0 deletions platform-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@launchdarkly/js-server-sdk-platform-node",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used organization prefixes for these names, but we can change them to whatever we want before we publish them.
This would likely just be the launchdarkly-node-server-sdk for continuity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the application teams have been using @launchdarkly to publish our internal packages.

"version": "1.0.0",
"description": "Node platform for the JS Server SDK",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"keywords": [
"launchdarkly",
"analytics",
"client"
],
"scripts": {
"test": "jest --ci",
"build": "tsc"
},
"license": "Apache-2.0",
"dependencies": {
"@launchdarkly/js-server-sdk-common": "@launchdarkly/js-server-sdk-common"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
}
}
3 changes: 3 additions & 0 deletions platform-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import doesItWork from '@launchdarkly/js-server-sdk-common';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index files just contain some code to make sure things are linking together correctly.


doesItWork();
18 changes: 18 additions & 0 deletions platform-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good starting point, but we may want to change things for compatibility as we work through things. This should be good for node.

"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es6",
"lib": [
"es6"
],
"module": "commonjs",
"strict": true,
"noImplicitOverride": true,
// Needed for CommonJS modules: markdown-it, fs-extra
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true, // enables importers to jump to source
}
}
7 changes: 7 additions & 0 deletions platform-node/tsconfig.ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
"composite": true,
},
}
26 changes: 26 additions & 0 deletions sdk-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@launchdarkly/js-sdk-common",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"description": "LaunchDarkly SDK for JavaScript - common code",
"files": [
"/dist"
],
"keywords": [
"launchdarkly",
"analytics",
"client"
],
"scripts": {
"test": "jest --ci",
"build": "tsc"
},
"license": "Apache-2.0",
"devDependencies": {
"@types/jest": "^27.4.1",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
}
}
Empty file added sdk-common/src/index.ts
Empty file.
18 changes: 18 additions & 0 deletions sdk-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es6",
"lib": [
"es6",
],
"module": "commonjs",
"strict": true,
"noImplicitOverride": true,
// Needed for CommonJS modules: markdown-it, fs-extra
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true, // enables importers to jump to source
}
}
7 changes: 7 additions & 0 deletions sdk-common/tsconfig.ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
"composite": true,
},
}
26 changes: 26 additions & 0 deletions server-sdk-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@launchdarkly/js-server-sdk-common",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"description": "LaunchDarkly Server SDK for JavaScript - common code",
"files": [
"/dist"
],
"keywords": [
"launchdarkly",
"analytics",
"client"
],
"scripts": {
"test": "jest --ci",
"build": "tsc"
},
"license": "Apache-2.0",
"devDependencies": {
"@types/jest": "^27.4.1",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
}
}
3 changes: 3 additions & 0 deletions server-sdk-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function doesItWork() {
console.log('yes');
}
18 changes: 18 additions & 0 deletions server-sdk-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"target": "es6",
"lib": [
"es6",
],
"module": "commonjs",
"strict": true,
"noImplicitOverride": true,
// Needed for CommonJS modules: markdown-it, fs-extra
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true, // enables importers to jump to source
}
}
7 changes: 7 additions & 0 deletions server-sdk-common/tsconfig.ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
"composite": true,
},
}
5 changes: 5 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file exists so the linter can lint all the TS. Otherwise it will get confused about TS files outside the 'project'.

"extends": "./tsconfig.json",
"include": ["/**/*.ts"],
"exclude": ["node_modules"]
}
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This references the other tsconfigs and allows building the entire project at once. Each project will have its own 'dist' output.

"files": [],
"references": [
{
"path": "./sdk-common/tsconfig.ref.json"
},
{
"path": "./server-sdk-common/tsconfig.ref.json"
},
{
"path": "./platform-node/tsconfig.ref.json"
},
],
}