diff --git a/CHANGELOG.md b/CHANGELOG.md index f788d7bb..8e621f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,15 @@ # Change log -All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. +All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +## [2.4.0] - 2018-07-12 +### Added: +- Named exports for the `initialize` method and `version` number exports. + +### Deprecated: +- Default exports, use named exports instead. + ## [2.3.1] - 2018-06-29 ### Fixed: - If a polling request has failed due to an invalid environment key, calling `variation` now returns the default value; previously, it sometimes caused a null reference error. diff --git a/package.json b/package.json index 0498be38..81816f04 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ldclient-js", - "version": "2.3.1", + "version": "2.4.0", "description": "LaunchDarkly SDK for JavaScript", "author": "LaunchDarkly ", "license": "Apache-2.0", diff --git a/src/__tests__/LDClient-test.js b/src/__tests__/LDClient-test.js index 227f3880..8dcfe275 100644 --- a/src/__tests__/LDClient-test.js +++ b/src/__tests__/LDClient-test.js @@ -2,7 +2,7 @@ import sinon from 'sinon'; import semverCompare from 'semver-compare'; import EventSource, { sources } from 'eventsourcemock'; -import LDClient from '../index'; +import * as LDClient from '../index'; import * as messages from '../messages'; import { btoa } from '../utils'; diff --git a/src/index.d.ts b/src/index.d.ts index 197687b0..62e2f538 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -8,9 +8,12 @@ * Documentation: http://docs.launchdarkly.com/docs/js-sdk-reference */ declare module 'ldclient-js' { - const LaunchDarkly : { - initialize: (envKey: string, user: LDUser, options?: LDOptions) => LDClient - version: string + export const initialize: (envKey: string, user: LDUser, options?: LDOptions) => LDClient; + export const version: string; + + const LaunchDarkly: { + initialize: (envKey: string, user: LDUser, options?: LDOptions) => LDClient; + version: string; }; export default LaunchDarkly; @@ -31,7 +34,7 @@ declare module 'ldclient-js' { * A map of feature flags from their keys to their values. */ export type LDFlagSet = { - [key: string]: LDFlagValue, + [key: string]: LDFlagValue; }; /** @@ -39,9 +42,9 @@ declare module 'ldclient-js' { */ export type LDFlagChangeset = { [key: string]: { - current: LDFlagValue, - previous: LDFlagValue, - }, + current: LDFlagValue; + previous: LDFlagValue; + }; }; /** @@ -50,10 +53,10 @@ declare module 'ldclient-js' { * See LDClient#on and LDClient#off. */ type LDEventSignature = ( - key: LDEventName, - callback: (current?: LDFlagValue | LDFlagChangeset, previous?: LDFlagValue) => void, - context?: any - ) => void; + key: LDEventName, + callback: (current?: LDFlagValue | LDFlagChangeset, previous?: LDFlagValue) => void, + context?: any + ) => void; /** * LaunchDarkly initialization options. @@ -68,13 +71,11 @@ declare module 'ldclient-js' { */ bootstrap?: 'localStorage' | LDFlagSet; - /** * The signed user key for Secure Mode. */ hash?: string; - /** * The base url for the LaunchDarkly server. * @@ -84,7 +85,6 @@ declare module 'ldclient-js' { */ baseUrl?: string; - /** * The url for the LaunchDarkly events server. * @@ -94,7 +94,6 @@ declare module 'ldclient-js' { */ eventsUrl?: string; - /** * The url for the LaunchDarkly stream server. * @@ -192,7 +191,7 @@ declare module 'ldclient-js' { * Any additional attributes associated with the user. */ custom?: { - [key: string]: string | boolean | number | Array, + [key: string]: string | boolean | number | Array; }; } /** @@ -201,7 +200,6 @@ declare module 'ldclient-js' { * @see http://docs.launchdarkly.com/docs/js-sdk-reference */ export interface LDClient { - /** * @returns a Promise containing the initialization state of the client */ @@ -226,7 +224,7 @@ declare module 'ldclient-js' { /** * Flushes pending events asynchronously. - * + * * @param onDone * A callback to invoke after the events were flushed. */ @@ -296,5 +294,4 @@ declare module 'ldclient-js' { */ allFlags: () => LDFlagSet; } - } diff --git a/src/index.js b/src/index.js index 344cb129..4d1ec0c3 100644 --- a/src/index.js +++ b/src/index.js @@ -14,7 +14,7 @@ const changeEvent = 'change'; const goalsEvent = 'goalsReady'; const locationWatcherInterval = 300; -function initialize(env, user, options = {}) { +export function initialize(env, user, options = {}) { const baseUrl = options.baseUrl || 'https://app.launchdarkly.com'; const eventsUrl = options.eventsUrl || 'https://events.launchdarkly.com'; const streamUrl = options.streamUrl || 'https://clientstream.launchdarkly.com'; @@ -548,6 +548,11 @@ function initialize(env, user, options = {}) { return client; } -const version = VERSION; +export const version = VERSION; -export default { initialize, version }; +function deprecatedInitialize(env, user, options = {}) { + console && console.warn && console.warn(messages.deprecated('default export', 'named LDClient export')); + return initialize(env, user, options); +} + +export default { initialize: deprecatedInitialize, version };