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

Commit

Permalink
remove deprecated things for 6.0 (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly authored Jun 14, 2021
1 parent ecf5135 commit 19cc663
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 241 deletions.
17 changes: 1 addition & 16 deletions configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,13 @@ module.exports = (function() {
proxyPort: 'number',
proxyScheme: 'string',
tlsParams: 'object', // LDTLSOptions
streamInitialReconnectDelayMillis: 'number', // deprecated - overridden by streamInitialReconnectDelay
updateProcessor: 'factory', // gets special handling in validation
wrapperName: 'string',
wrapperVersion: 'string',
};

/* eslint-disable camelcase */
const deprecatedOptions = {
base_uri: 'baseUri',
stream_uri: 'streamUri',
events_uri: 'eventsUri',
send_events: 'sendEvents',
flush_interval: 'flushInterval',
poll_interval: 'pollInterval',
proxy_host: 'proxyHost',
proxy_port: 'proxyPort',
proxy_auth: 'proxyAuth',
feature_store: 'featureStore',
use_ldd: 'useLdd',
all_attributes_private: 'allAttributesPrivate',
private_attribute_names: 'privateAttributeNames',
};
const deprecatedOptions = {};
/* eslint-enable camelcase */

function checkDeprecatedOptions(configIn) {
Expand Down
3 changes: 1 addition & 2 deletions diagnostic_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ function makeConfigData(config) {
pollingIntervalMillis: secondsToMillis(config.pollInterval),
// startWaitMillis: n/a (Node SDK does not have this feature)
// samplingInterval: n/a (Node SDK does not have this feature)
reconnectTimeMillis:
config.streamInitialReconnectDelayMillis || secondsToMillis(config.streamInitialReconnectDelay),
reconnectTimeMillis: secondsToMillis(config.streamInitialReconnectDelay),
streamingDisabled: !config.stream,
usingRelayDaemon: !!config.useLdd,
offline: !!config.offline,
Expand Down
51 changes: 0 additions & 51 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,6 @@ declare module 'launchdarkly-node-server-sdk' {
*/
streamInitialReconnectDelay?: number;

/**
* Deprecated alternative to `streamInitialReconnectDelay`.
*
* @deprecated Use `streamInitialReconnectDelay` instead, which is measured in seconds like the other
* time interval properties.
*/
streamInitialReconnectDelayMillis?: number;

/**
* Whether you are using the LaunchDarkly relay proxy in daemon mode.
*
Expand Down Expand Up @@ -753,17 +745,6 @@ declare module 'launchdarkly-node-server-sdk' {
*/
initialized(): boolean;

/**
* Returns a Promise that tracks the client's initialization state.
*
* @deprecated Please use [[waitForInitialization]] instead. The difference between that method
* and this one is that `waitUntilReady` never rejects the Promise, even if initialization fails.
*
* @returns
* A Promise that will be resolved if the client initializes successfully.
*/
waitUntilReady(): Promise<void>;

/**
* Returns a Promise that tracks the client's initialization state.
*
Expand Down Expand Up @@ -862,38 +843,6 @@ declare module 'launchdarkly-node-server-sdk' {
callback?: (err: any, res: LDEvaluationDetail) => void
): Promise<LDEvaluationDetail>;

/**
* Synonym for [[variation]].
*
* @deprecated Please use [[variation]] instead.
*/
toggle(
key: string,
user: LDUser,
defaultValue: LDFlagValue,
callback?: (err: any, res: LDFlagValue) => void
): Promise<LDFlagValue>;

/**
* Retrieves the set of all flag values for a user.
*
* @deprecated Use [[allFlagsState]] instead. Current versions of the client-side SDK will
* not generate analytics events correctly if you pass the result of `allFlags()`.
*
* @param user
* The end user requesting the feature flags.
* @param callback
* A Node-style callback to receive the result (as an [[LDFlagSet]]). If omitted, you
* will receive a Promise instead.
* @returns
* If you provided a callback, then nothing. Otherwise, a Promise which will be resolved
* with the result as an [[LDFlagSet]].
*/
allFlags(
user: LDUser,
callback?: (err: Error, res: LDFlagSet) => void
): Promise<LDFlagSet>;

/**
* Builds an object that encapsulates the state of all feature flags for a given user.
* This includes the flag values and also metadata that can be used on the front end. This
Expand Down
29 changes: 4 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,6 @@ const newClient = function(sdkKey, originalConfig) {

client.initialized = () => initComplete;

client.waitUntilReady = () => {
config.logger.warn(messages.deprecated('waitUntilReady', 'waitForInitialization'));

if (initComplete) {
return Promise.resolve();
}

return new Promise(resolve => {
client.once('ready', resolve);
});
};

client.waitForInitialization = () => {
if (waitForInitializationPromise) {
return waitForInitializationPromise;
Expand Down Expand Up @@ -283,14 +271,6 @@ const newClient = function(sdkKey, originalConfig) {
});
}

client.allFlags = (user, callback) => {
config.logger.warn('allFlags() is deprecated. Call allFlagsState() instead and call toJSON() on the result');
return wrapPromiseCallback(
client.allFlagsState(user).then(state => state.allValues()),
callback
);
};

client.allFlagsState = (user, specifiedOptions, specifiedCallback) => {
let callback = specifiedCallback,
options = specifiedOptions;
Expand Down Expand Up @@ -399,17 +379,16 @@ const newClient = function(sdkKey, originalConfig) {
return false;
}

/* eslint-disable no-unused-vars */
// We may not currently have any deprecated methods, but if we do, we should
// use this logic.
function deprecatedMethod(oldName, newName) {
client[oldName] = (...args) => {
config.logger.warn(messages.deprecated(oldName, newName));
return client[newName].apply(client, args);
};
}

deprecatedMethod('all_flags', 'allFlags');
deprecatedMethod('is_offline', 'isOffline');
deprecatedMethod('secure_mode_hash', 'secureModeHash');
deprecatedMethod('toggle', 'variation');
/* eslint-enable no-unused-vars */

return client;
};
Expand Down
8 changes: 4 additions & 4 deletions requestor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const httpUtils = require('./utils/httpUtils');

/**
* Creates a new Requestor object, which handles remote requests to fetch feature flags or segments for LaunchDarkly.
* This is never called synchronously when requesting a feature flag for a user (e.g. via the toggle) call.
* This is never called synchronously when requesting a feature flag for a user (e.g. via the variation method).
*
* It will be called once per second in polling mode (i.e. when streaming is disabled), or for extremely large
* feature flag representations if streaming is enabled (the stream may contain a pointer to a large representation,
* which will be polled by the requestor)
* It will be called at the configured polling interval in polling mode. Older versions of the SDK also
* could use the Requestor to make a polling request even in streaming mode, for very large data sets,
* but the LD infrastructure no longer uses that behavior.
*
* @param {String} the SDK key
* @param {Object} the LaunchDarkly client configuration object
Expand Down
4 changes: 1 addition & 3 deletions streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ function StreamProcessor(sdkKey, config, requestor, diagnosticsManager, specifie
agent: config.proxyAgent,
errorFilter: handleError,
headers,
initialRetryDelayMillis: config.streamInitialReconnectDelayMillis
? config.streamInitialReconnectDelayMillis
: 1000 * config.streamInitialReconnectDelay,
initialRetryDelayMillis: 1000 * config.streamInitialReconnectDelay,
readTimeoutMillis: streamReadTimeoutMillis,
retryResetIntervalMillis: 60000,
tlsParams: config.tlsParams,
Expand Down
6 changes: 2 additions & 4 deletions test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ client.variationDetail('key', user, 'default', (detail: ld.LDEvaluationDetail) =
var detailIndex: number | undefined = detail.variationIndex;
var detailReason: ld.LDEvaluationReason = detail.reason;
});
client.allFlags(user, (flagSet: ld.LDFlagSet) => {
var flagSetValue: ld.LDFlagValue = flagSet['key'];
});
client.allFlagsState(user, {}, (err: Error, flagSet: ld.LDFlagsState) => { });

// evaluation methods with promises
client.variation('key', user, false).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 2).then((value: ld.LDFlagValue) => { });
client.variation('key', user, 'default').then((value: ld.LDFlagValue) => { });
client.variationDetail('key', user, 'default').then((detail: ld.LDEvaluationDetail) => { });
client.allFlags(user).then((flagSet: ld.LDFlagSet) => { });
client.allFlagsState(user).then((flagSet: ld.LDFlagsState) => { });

// basicLogger
var logger1: ld.LDLogger = ld.basicLogger();
Expand Down
108 changes: 18 additions & 90 deletions test/LDClient-evaluation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,6 @@ describe('LDClient', () => {
expect(result).toEqual('default');
});

it('allows deprecated method toggle()', done => {
var flag = {
key: 'flagkey',
on: false,
offVariation: 0,
variations: [true]
};
var logger = stubs.stubLogger();
var client = stubs.createClient({ logger: logger }, { flagkey: flag });
client.on('ready', () => {
client.toggle(flag.key, defaultUser, false, (err, result) => {
expect(err).toBeNull();
expect(result).toEqual(true);
expect(logger.warn).toHaveBeenCalled();
done();
});
});
});

it('can use a callback instead of a Promise', done => {
var client = stubs.createClient({}, {});
client.on('ready', () => {
Expand Down Expand Up @@ -242,77 +223,6 @@ describe('LDClient', () => {
});
});

describe('allFlags()', () => {
it('evaluates flags', async () => {
var flag = {
key: 'feature',
version: 1,
offVariation: 1,
variations: ['a', 'b']
};
var logger = stubs.stubLogger();
var client = stubs.createClient({ logger: logger }, { feature: flag });
await client.waitForInitialization();
var result = await client.allFlags(defaultUser);
expect(result).toEqual({feature: 'b'});
expect(logger.warn).toHaveBeenCalledTimes(1); // deprecation warning
});

it('returns empty map in offline mode and logs a message', async () => {
var flag = {
key: 'flagkey',
on: false,
offVariation: null
};
var logger = stubs.stubLogger();
var client = stubs.createClient({ offline: true, logger: logger }, { flagkey: flag });
await client.waitForInitialization();
var result = await client.allFlags(defaultUser);
expect(result).toEqual({});
expect(logger.info).toHaveBeenCalledTimes(1);
});

it('allows deprecated method all_flags', done => {
var logger = stubs.stubLogger();
var client = stubs.createClient({ logger: logger }, {});
client.on('ready', () => {
client.all_flags(defaultUser, (err, result) => {
expect(result).toEqual({});
expect(logger.warn).toHaveBeenCalledWith(messages.deprecated('all_flags', 'allFlags'));
done();
});
});
});

it('does not overflow the call stack when evaluating a huge number of flags', async () => {
var flagCount = 5000;
var flags = {};
for (var i = 0; i < flagCount; i++) {
var key = 'feature' + i;
var flag = {
key: key,
version: 1,
on: false
};
flags[key] = flag;
}
var client = stubs.createClient({}, flags);
await client.waitForInitialization();
var result = await client.allFlags(defaultUser);
expect(Object.keys(result).length).toEqual(flagCount);
});

it('can use a callback instead of a Promise', done => {
var client = stubs.createClient({ offline: true }, { });
client.on('ready', () => {
client.allFlags(defaultUser, (err, result) => {
expect(result).toEqual({});
done();
});
});
});
});

describe('allFlagsState()', () => {
it('captures flag state', async () => {
var flag = {
Expand Down Expand Up @@ -455,6 +365,24 @@ describe('LDClient', () => {
expect(logger.info).toHaveBeenCalledTimes(1);
});

it('does not overflow the call stack when evaluating a huge number of flags', async () => {
var flagCount = 5000;
var flags = {};
for (var i = 0; i < flagCount; i++) {
var key = 'feature' + i;
var flag = {
key: key,
version: 1,
on: false
};
flags[key] = flag;
}
var client = stubs.createClient({}, flags);
await client.waitForInitialization();
var state = await client.allFlagsState(defaultUser);
expect(Object.keys(state.allValues()).length).toEqual(flagCount);
});

it('can use a callback instead of a Promise', done => {
var client = stubs.createClient({ offline: true }, { });
client.on('ready', () => {
Expand Down
31 changes: 0 additions & 31 deletions test/LDClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ describe('LDClient', () => {
done();
});
});

it('allows deprecated method is_offline', done => {
var logger = stubs.stubLogger();
var client = LDClient.init('sdk_key', {offline: true, logger: logger});
client.on('ready', () => {
expect(client.is_offline()).toEqual(true);
expect(logger.warn).toHaveBeenCalledWith(messages.deprecated('is_offline', 'isOffline'));
done();
});
});
});

describe('secureModeHash()', () => {
Expand All @@ -52,27 +42,6 @@ describe('LDClient', () => {
var hash = client.secureModeHash({"key": "Message"});
expect(hash).toEqual("aa747c502a898200f9e4fa21bac68136f886a0e27aec70ba06daf2e2a5cb5597");
});

it('allows deprecated method secure_mode_hash', () => {
var logger = stubs.stubLogger();
var client = LDClient.init('secret', {offline: true, logger: logger});
var hash = client.secure_mode_hash({"key": "Message"});
expect(hash).toEqual("aa747c502a898200f9e4fa21bac68136f886a0e27aec70ba06daf2e2a5cb5597");
expect(logger.warn).toHaveBeenCalledWith(messages.deprecated('secure_mode_hash', 'secureModeHash'));
});
});

describe('waitUntilReady()', () => {
it('resolves when ready', async () => {
var client = stubs.createClient({}, {});
await client.waitUntilReady();
});

it('resolves immediately if the client is already ready', async () => {
var client = stubs.createClient({}, {});
await client.waitUntilReady();
await client.waitUntilReady();
});
});

describe('waitForInitialization()', () => {
Expand Down
Loading

0 comments on commit 19cc663

Please sign in to comment.