diff --git a/index.d.ts b/index.d.ts index e37f8e4..2805344 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,13 +6,16 @@ * 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; } /** @@ -20,6 +23,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 +44,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 +92,6 @@ declare module "ldclient-node" { */ logger?: LDLogger | object; - /** * Feature store used by the LaunchDarkly client, defaults to in memory storage. * @@ -131,7 +143,7 @@ declare module "ldclient-node" { /** * Whether to send events back to LaunchDarkly - */ + */ sendEvents?: boolean; /** @@ -165,7 +177,6 @@ declare module "ldclient-node" { * Defaults to 300. */ userKeysFlushInterval?: number; - } /** @@ -230,7 +241,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 +373,34 @@ declare module "ldclient-node" { /** * Close the feature store. * - * @returns - * The store instance. */ - close: () => LDFeatureStore; + 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 requestor + * + * 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; } /** @@ -412,12 +451,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 +478,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 +501,6 @@ declare module "ldclient-node" { */ close: () => void; - /** * * @returns Whether the client is configured in offline mode. @@ -491,9 +542,37 @@ 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; } } + +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; +} 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..278c2ef 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", @@ -29,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",