Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 7a79fbe

Browse files
authored
add Typescript defs and improve documentation (#3)
1 parent 5ebbe64 commit 7a79fbe

File tree

10 files changed

+105
-18
lines changed

10 files changed

+105
-18
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ node-template: &node-template
1212
- checkout
1313
- run: echo "Node version:" `node --version`
1414
- run: npm install
15+
- run: npm run lint
1516
- run:
1617
command: npm test
1718
environment:
1819
JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml"
1920
- store_test_results:
2021
path: reports/junit
22+
- run: npm run check-typescript
2123
- store_artifacts:
2224
path: reports/junit
2325

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules
22
package-lock.json
33
junit.xml
4-
4+
test-types.js

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
All notable changes to the LaunchDarkly Node.js SDK DynamoDB integration will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
44

5-
## [1.0.0] - 2018-11-15
6-
7-
Initial release.
8-
95
## [1.1.0] - 2018-11-20
106
### Added:
117
- it is now possible to specify a prefix string for the database keys, so that multiple SDK clients can share the same DynamoDB table without interfering with each other's data as long as they use different prefixes.
8+
9+
## [1.0.0] - 2018-11-15
10+
11+
Initial release.

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@ Quick setup
1313

1414
This assumes that you have already installed the LaunchDarkly Node.js SDK.
1515

16-
1. Install this package with `npm`:
16+
1. In DynamoDB, create a table which has the following schema: a partition key called "namespace" and a sort key called "key", both with a string type. The LaunchDarkly library does not create the table automatically, because it has no way of knowing what additional properties (such as permissions and throughput) you would want it to have.
17+
18+
2. Install this package with `npm`:
1719

1820
npm install ldclient-node-dynamodb-store --save
1921

20-
2. Require the package:
22+
3. Require the package:
2123

2224
var DynamoDBFeatureStore = require('ldclient-node-dynamodb-store');
2325

24-
3. When configuring your SDK client, add the DynamoDB feature store:
26+
4. When configuring your SDK client, add the DynamoDB feature store:
2527

2628
var store = DynamoDBFeatureStore('YOUR TABLE NAME');
2729
var config = { featureStore: store };
2830
var client = LaunchDarkly.init('YOUR SDK KEY', config);
2931

30-
The specified table must already exist in DynamoDB. It must have a partition key called "namespace" and a sort key called "key".
31-
32-
By default, the DynamoDB client will try to get your AWS credentials and region name from environment variables and/or local configuration files, as described in the AWS SDK documentation. You can also specify any valid [DynamoDB client options](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#constructor-property) like this:
32+
By default, the DynamoDB client will try to get your AWS credentials and region name from environment variables and/or local configuration files, as described in the AWS SDK documentation. You can also specify any valid [DynamoDB client options](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#constructor-property) like this:
3333

3434
var dynamoDBOptions = { accessKeyId: 'YOUR KEY', secretAccessKey: 'YOUR SECRET' };
3535
var store = DynamoDBFeatureStore('YOUR TABLE NAME', { clientOptions: dynamoDBOptions });
3636

37-
Alternatively, if you already have a fully configured DynamoDB client object, you can tell LaunchDarkly to use that:
37+
Alternatively, if you already have a fully configured DynamoDB client object, you can tell LaunchDarkly to use that:
3838

3939
var store = DynamoDBFeatureStore('YOUR TABLE NAME', { dynamoDBClient: myDynamoDBClientInstance });
4040

41-
4. If you are running a [LaunchDarkly Relay Proxy](https://github.com/launchdarkly/ld-relay) instance, or any other process that will prepopulate the DynamoDB table with feature flags from LaunchDarkly, you can use [daemon mode](https://github.com/launchdarkly/ld-relay#daemon-mode), so that the SDK retrieves flag data only from DynamoDB and does not communicate directly with LaunchDarkly. This is controlled by the SDK's `useLdd` option:
41+
5. If you are running a [LaunchDarkly Relay Proxy](https://github.com/launchdarkly/ld-relay) instance, or any other process that will prepopulate the DynamoDB table with feature flags from LaunchDarkly, you can use [daemon mode](https://github.com/launchdarkly/ld-relay#daemon-mode), so that the SDK retrieves flag data only from DynamoDB and does not communicate directly with LaunchDarkly. This is controlled by the SDK's `useLdd` option:
4242

4343
var config = { featureStore: store, useLdd: true };
4444
var client = LaunchDarkly.init('YOUR SDK KEY', config);
4545

46-
5. If the same DynamoDB table is being shared by SDK clients for different LaunchDarkly environments, set the `prefix` option to a different short string for each one to keep the keys from colliding:
46+
6. If the same DynamoDB table is being shared by SDK clients for different LaunchDarkly environments, set the `prefix` option to a different short string for each one to keep the keys from colliding:
4747

4848
var store = DynamoDBFeatureStore('YOUR TABLE NAME', { prefix: 'env1' });
4949

@@ -55,7 +55,7 @@ To reduce traffic to DynamoDB, there is an optional in-memory cache that retains
5555
var store = DynamoDBFeatureStore('YOUR TABLE NAME', { cacheTTL: 0 });
5656

5757
About LaunchDarkly
58-
-----------
58+
------------------
5959

6060
* 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:
6161
* 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.
@@ -69,6 +69,7 @@ About LaunchDarkly
6969
* [Python](http://docs.launchdarkly.com/docs/python-sdk-reference "LaunchDarkly Python SDK")
7070
* [Go](http://docs.launchdarkly.com/docs/go-sdk-reference "LaunchDarkly Go SDK")
7171
* [Node.JS](http://docs.launchdarkly.com/docs/node-sdk-reference "LaunchDarkly Node SDK")
72+
* [Electron](http://docs.launchdarkly.com/docs/electron-sdk-reference "LaunchDarkly Electron SDK")
7273
* [.NET](http://docs.launchdarkly.com/docs/dotnet-sdk-reference "LaunchDarkly .Net SDK")
7374
* [Ruby](http://docs.launchdarkly.com/docs/ruby-sdk-reference "LaunchDarkly Ruby SDK")
7475
* [iOS](http://docs.launchdarkly.com/docs/ios-sdk-reference "LaunchDarkly iOS SDK")

dynamodb_feature_store.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var AWS = require('aws-sdk');
2-
var dataKind = require('ldclient-node/versioned_data_kind');
32
var winston = require('winston');
43

54
var helpers = require('./dynamodb_helpers');

index.d.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Type definitions for ldclient-node-dynamodb-store
2+
3+
/**
4+
* Interface for the DynamoDB feature store component to be used with the LaunchDarkly SDK.
5+
*
6+
* See: https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store
7+
*/
8+
9+
declare module 'ldclient-node-dynamodb-store' {
10+
import { LDFeatureStore, LDLogger } from 'ldclient-node';
11+
import { DynamoDB } from 'aws-sdk';
12+
13+
/**
14+
* Create a feature flag store backed by DynamoDB.
15+
*/
16+
export function DynamoDBFeatureStore(
17+
/**
18+
* The table name in DynamoDB. This table must already exist (see readme).
19+
*/
20+
tableName: string,
21+
22+
/**
23+
* Options for configuring the feature store.
24+
*/
25+
options?: LDDynamoDBOptions
26+
): LDFeatureStore;
27+
28+
/**
29+
* Options for configuring a DynamoDBFeatureStore.
30+
*/
31+
export interface LDDynamoDBOptions {
32+
/**
33+
* Options to be passed to the DynamoDB client constructor, as defined by the AWS SDK.
34+
*/
35+
clientOptions?: DynamoDB.DocumentClient.DocumentClientOptions & DynamoDB.Types.ClientConfiguration;
36+
37+
/**
38+
* Specifies an existing, already-configured DynamoDB client instance that the feature store
39+
* should use rather than creating one of its own. If you specify an existing client, then the
40+
* clientOptions property is ignored.
41+
*/
42+
dynamoDBClient?: DynamoDB.DocumentClient;
43+
44+
/**
45+
* An optional namespace prefix for all keys stored in DynamoDB. Use this if you are sharing
46+
* the same database table between multiple clients that are for different LaunchDarkly
47+
* environments, to avoid key collisions.
48+
*/
49+
prefix?: string;
50+
51+
/**
52+
* The expiration time for local caching, in seconds. To disable local caching, set this to zero.
53+
* If not specified, the default is 15 seconds.
54+
*/
55+
cacheTTL?: number;
56+
57+
/**
58+
* A logger to be used for warnings and errors generated by the feature store. If not specified,
59+
* the default is an instance of winston.Logger.
60+
*/
61+
logger?: LDLogger;
62+
}
63+
}

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
"main": "dynamodb_feature_store.js",
66
"license": "Apache-2.0",
77
"scripts": {
8-
"test": "jest --ci --forceExit"
8+
"test": "jest --ci --forceExit",
9+
"check-typescript": "node_modules/typescript/bin/tsc",
10+
"lint": "eslint --format 'node_modules/eslint-formatter-pretty' --ignore-path .eslintignore ."
911
},
12+
"types": "./index.d.ts",
1013
"devDependencies": {
1114
"babel-core": "6.26.0",
1215
"babel-jest": "22.4.3",
1316
"babel-preset-env": "1.6.1",
1417
"eslint": "5.8.0",
18+
"eslint-formatter-pretty": "1.3.0",
1519
"jest": "23.6.0",
1620
"jest-junit": "5.2.0",
17-
"ldclient-node": ">= 5.7.0"
21+
"ldclient-node": ">= 5.7.0",
22+
"typescript": "3.0.1"
1823
},
1924
"jest": {
2025
"rootDir": ".",

test-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
// This file exists only so that we can run the TypeScript compiler in the CI build
3+
// to validate our index.d.ts file.

tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"strict": true,
5+
"lib": [
6+
"es6"
7+
]
8+
},
9+
"files": [
10+
"index.d.ts",
11+
"test-types.ts"
12+
]
13+
}

0 commit comments

Comments
 (0)