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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ldclient-js",
"version": "2.3.1",
"version": "2.4.0",
"description": "LaunchDarkly SDK for JavaScript",
"author": "LaunchDarkly <team@launchdarkly.com>",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/LDClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
35 changes: 16 additions & 19 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,17 +34,17 @@ declare module 'ldclient-js' {
* A map of feature flags from their keys to their values.
*/
export type LDFlagSet = {
[key: string]: LDFlagValue,
[key: string]: LDFlagValue;
};

/**
* A map of feature flag keys to objects holding changes in their values.
*/
export type LDFlagChangeset = {
[key: string]: {
current: LDFlagValue,
previous: LDFlagValue,
},
current: LDFlagValue;
previous: LDFlagValue;
};
};

/**
Expand All @@ -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.
Expand All @@ -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.
*
Expand All @@ -84,7 +85,6 @@ declare module 'ldclient-js' {
*/
baseUrl?: string;


/**
* The url for the LaunchDarkly events server.
*
Expand All @@ -94,7 +94,6 @@ declare module 'ldclient-js' {
*/
eventsUrl?: string;


/**
* The url for the LaunchDarkly stream server.
*
Expand Down Expand Up @@ -192,7 +191,7 @@ declare module 'ldclient-js' {
* Any additional attributes associated with the user.
*/
custom?: {
[key: string]: string | boolean | number | Array<string | boolean | number>,
[key: string]: string | boolean | number | Array<string | boolean | number>;
};
}
/**
Expand All @@ -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
*/
Expand All @@ -226,7 +224,7 @@ declare module 'ldclient-js' {

/**
* Flushes pending events asynchronously.
*
*
* @param onDone
* A callback to invoke after the events were flushed.
*/
Expand Down Expand Up @@ -296,5 +294,4 @@ declare module 'ldclient-js' {
*/
allFlags: () => LDFlagSet;
}

}
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 };