From 68d3556aab8c76fa9a54ec5f44644c134154654e Mon Sep 17 00:00:00 2001 From: Arnold Trakhtenberg Date: Wed, 11 Jul 2018 10:55:23 -0700 Subject: [PATCH 1/4] Make things prettier, add RedisFeatureStore to toplevel ts declarations, fix LDFeatureStore.close return value --- index.d.ts | 58 ++++++++++++++++++++++++++++++++++------------- package-lock.json | 23 +++++++++++++++++-- package.json | 1 + 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/index.d.ts b/index.d.ts index e37f8e4..ae0704a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,13 +6,17 @@ * Documentation: http://docs.launchdarkly.com/docs/node-sdk-reference */ -declare module "ldclient-node" { +declare module 'ldclient-node' { import { EventEmitter } from 'events'; - + import { ClientOpts } from 'redis'; + namespace errors { export const LDPollingError: ErrorConstructor; export const LDStreamingError: ErrorConstructor; export const LDClientError: ErrorConstructor; + export const LDUnexpectedResponseError: ErrorConstructor; + export const LDInvalidSDKKeyError: ErrorConstructor; + export function isHttpErrorRecoverable(status: number): boolean; } /** @@ -20,6 +24,16 @@ declare module "ldclient-node" { */ export function init(key: string, options?: LDOptions): LDClient; + /** + * Create a feature flag store backed by a Redis instance + */ + export function RedisFeatureStore( + redisOpts: ClientOpts, + cacheTTL: number, + prefix: string, + logger: LDLogger | object + ): LDFeatureStore; + /** * The types of values a feature flag can have. * @@ -31,7 +45,7 @@ declare module "ldclient-node" { * A map of feature flags from their keys to their values. */ export type LDFlagSet = { - [key: string]: LDFlagValue, + [key: string]: LDFlagValue; }; /** @@ -79,7 +93,6 @@ declare module "ldclient-node" { */ logger?: LDLogger | object; - /** * Feature store used by the LaunchDarkly client, defaults to in memory storage. * @@ -131,7 +144,7 @@ declare module "ldclient-node" { /** * Whether to send events back to LaunchDarkly - */ + */ sendEvents?: boolean; /** @@ -165,7 +178,6 @@ declare module "ldclient-node" { * Defaults to 300. */ userKeysFlushInterval?: number; - } /** @@ -230,7 +242,11 @@ declare module "ldclient-node" { * Any additional attributes associated with the user. */ custom?: { - [key: string]: string | boolean | number | Array, + [key: string]: + | string + | boolean + | number + | Array; }; } @@ -358,10 +374,8 @@ declare module "ldclient-node" { /** * Close the feature store. * - * @returns - * The store instance. */ - close: () => LDFeatureStore; + close: () => void; } /** @@ -412,12 +426,22 @@ declare module "ldclient-node" { * * @param callback * The callback to receive the variation result. - * + * * @returns a Promise containing the flag value */ - variation: (key: string, user: LDUser, defaultValue: LDFlagValue, callback?: (err: any, res: LDFlagValue) => void) => Promise; + variation: ( + key: string, + user: LDUser, + defaultValue: LDFlagValue, + callback?: (err: any, res: LDFlagValue) => void + ) => Promise; - toggle: (key: string, user: LDUser, defaultValue: LDFlagValue, callback?: (err: any, res: LDFlagValue) => void) => Promise; + toggle: ( + key: string, + user: LDUser, + defaultValue: LDFlagValue, + callback?: (err: any, res: LDFlagValue) => void + ) => Promise; /** * Retrieves the set of all flag values for a user. @@ -429,7 +453,10 @@ declare module "ldclient-node" { * The node style callback to receive the variation result. * @returns a Promise containing the set of all flag values for a user */ - allFlags: (user: LDUser, callback?: (err: any, res: LDFlagSet) => void) => Promise; + allFlags: ( + user: LDUser, + callback?: (err: any, res: LDFlagSet) => void + ) => Promise; /** * @@ -449,7 +476,6 @@ declare module "ldclient-node" { */ close: () => void; - /** * * @returns Whether the client is configured in offline mode. @@ -491,7 +517,7 @@ declare module "ldclient-node" { * Internally, the LaunchDarkly SDK keeps an event queue for track and identify calls. * These are flushed periodically (see configuration option: flushInterval) * and when the queue size limit (see configuration option: capacity) is reached. - * + * * @returns a Promise which resolves once flushing is finished */ flush: (callback?: (err: any, res: boolean) => void) => Promise; diff --git a/package-lock.json b/package-lock.json index d29d597..3d9a264 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ldclient-node", - "version": "5.0.1", + "version": "5.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -24,6 +24,25 @@ "js-tokens": "3.0.2" } }, + "@types/events": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", + "integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==" + }, + "@types/node": { + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.5.2.tgz", + "integrity": "sha512-m9zXmifkZsMHZBOyxZWilMwmTlpC8x5Ty360JKTiXvlXZfBWYpsg9ZZvP/Ye+iZUh+Q+MxDLjItVTWIsfwz+8Q==" + }, + "@types/redis": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/@types/redis/-/redis-2.8.6.tgz", + "integrity": "sha512-kaSI4XQwCfJtPiuyCXvLxCaw2N0fMZesdob3Jh01W20vNFct+3lfvJ/4yCJxbSopXOBOzpg+pGxkW6uWZrPZHA==", + "requires": { + "@types/events": "1.2.0", + "@types/node": "10.5.2" + } + }, "abab": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/abab/-/abab-1.0.4.tgz", @@ -5708,7 +5727,7 @@ }, "tunnel": { "version": "https://github.com/launchdarkly/node-tunnel/tarball/d860e57650cce1ea655d00854c81babe6b47e02c", - "integrity": "sha512-prl+yIntUTIhkHoz2YtT7xtcAoMEgfsm+RL2bUGFI6e229NTICfo+jFKj1UFCDqc1wm/SQK7TM2U06sgeoO9jQ==" + "integrity": "sha1-DxkgfzcgRtPUaCGDy+INSgR8zdk=" }, "tunnel-agent": { "version": "0.6.0", diff --git a/package.json b/package.json index 279ccaa..0a582c4 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ }, "homepage": "https://github.com/launchdarkly/node-client", "dependencies": { + "@types/redis": "2.8.6", "async": "2.6.0", "crypto": "0.0.3", "hoek": "4.2.1", From c5c665fc98d1ecb86acc6dde5797c518367c75b6 Mon Sep 17 00:00:00 2001 From: Arnold Trakhtenberg Date: Wed, 11 Jul 2018 10:58:36 -0700 Subject: [PATCH 2/4] Add modules for ldclient StreamProcessor, Requestor, and FeatureStore --- index.d.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/index.d.ts b/index.d.ts index ae0704a..f3e456c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -378,6 +378,32 @@ declare module 'ldclient-node' { close: () => void; } + /** + * The LaunchDarkly client stream processor + * + * The client uses this internally to retrieve updates from LaunchDarkly. + */ + export interface LDStreamProcessor { + start: (fn?: (err?: any) => void) => void; + stop: () => void; + close: () => void; + } + + /** + * The LaunchDarkly client feature flag requetor + * + * The client uses this internally to retrieve feature + * flags from LaunchDarkly. + */ + export interface LDFeatureRequestor { + requestObject: ( + kind: any, + key: string, + cb: (err: any, body: any) => void + ) => void; + requestAllData: (cb: (err: any, body: any) => void) => void; + } + /** * The LaunchDarkly client's instance interface. * @@ -523,3 +549,31 @@ declare module 'ldclient-node' { flush: (callback?: (err: any, res: boolean) => void) => Promise; } } + +declare module 'ldclient-node/streaming' { + import { + LDOptions, + LDFeatureRequestor, + LDStreamProcessor + } from 'ldclient-node'; + + function StreamProcessor( + sdkKey: string, + options: LDOptions, + requestor: LDFeatureRequestor + ): LDStreamProcessor; + export = StreamProcessor; +} +declare module 'ldclient-node/requestor' { + import { LDOptions, LDFeatureRequestor } from 'ldclient-node'; + + function Requestor(sdkKey: string, options: LDOptions): LDFeatureRequestor; + export = Requestor; +} + +declare module 'ldclient-node/feature_store' { + import { LDFeatureStore } from 'ldclient-node'; + + function InMemoryFeatureStore(): LDFeatureStore; + export = InMemoryFeatureStore; +} From 407e6ce8ba5604bc0dc0678a1d5ffe61d90a6115 Mon Sep 17 00:00:00 2001 From: Arnold Trakhtenberg Date: Wed, 11 Jul 2018 13:57:22 -0700 Subject: [PATCH 3/4] address review --- index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index f3e456c..2805344 100644 --- a/index.d.ts +++ b/index.d.ts @@ -16,7 +16,6 @@ declare module 'ldclient-node' { export const LDClientError: ErrorConstructor; export const LDUnexpectedResponseError: ErrorConstructor; export const LDInvalidSDKKeyError: ErrorConstructor; - export function isHttpErrorRecoverable(status: number): boolean; } /** @@ -390,7 +389,7 @@ declare module 'ldclient-node' { } /** - * The LaunchDarkly client feature flag requetor + * The LaunchDarkly client feature flag requestor * * The client uses this internally to retrieve feature * flags from LaunchDarkly. From 762b1c8deb3423d22957fbccc09eece9f412588e Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Thu, 19 Jul 2018 16:03:35 +0000 Subject: [PATCH 4/4] fix: package.json to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/npm:cryptiles:20180710 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a582c4..278c2ef 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "node-cache": "^3.2.1", "node-sha1": "0.0.1", "redis": "^2.6.0-2", - "request": "2.85.0", + "request": "2.87.0", "request-etag": "^2.0.3", "semver": "5.5.0", "tunnel": "https://github.com/launchdarkly/node-tunnel/tarball/d860e57650cce1ea655d00854c81babe6b47e02c",