@launchdarkly/js-client-sdk-common 1.24.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/LDClientImpl.d.ts +19 -8
- package/dist/cjs/LDClientImpl.d.ts.map +1 -1
- package/dist/cjs/api/LDStartOptions.d.ts +19 -0
- package/dist/cjs/api/LDStartOptions.d.ts.map +1 -0
- package/dist/cjs/api/index.d.ts +1 -0
- package/dist/cjs/api/index.d.ts.map +1 -1
- package/dist/cjs/configuration/Configuration.d.ts +10 -0
- package/dist/cjs/configuration/Configuration.d.ts.map +1 -1
- package/dist/cjs/datasource/fdv2/CacheInitializer.d.ts.map +1 -1
- package/dist/cjs/index.cjs +114 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/esm/LDClientImpl.d.ts +19 -8
- package/dist/esm/LDClientImpl.d.ts.map +1 -1
- package/dist/esm/api/LDStartOptions.d.ts +19 -0
- package/dist/esm/api/LDStartOptions.d.ts.map +1 -0
- package/dist/esm/api/index.d.ts +1 -0
- package/dist/esm/api/index.d.ts.map +1 -1
- package/dist/esm/configuration/Configuration.d.ts +10 -0
- package/dist/esm/configuration/Configuration.d.ts.map +1 -1
- package/dist/esm/datasource/fdv2/CacheInitializer.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +114 -55
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.25.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-common-v1.24.0...js-client-sdk-common-v1.25.0) (2026-04-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Add experimental FDv2 support for React Native. ([#1243](https://github.com/launchdarkly/js-core/issues/1243)) ([7ed2c08](https://github.com/launchdarkly/js-core/commit/7ed2c085cd35d35ffd6f48becb5a60f03b07ad1c))
|
|
9
|
+
* adding start() method to common client sdk package ([#1244](https://github.com/launchdarkly/js-core/issues/1244)) ([7f5f468](https://github.com/launchdarkly/js-core/commit/7f5f468f93eaa4655d1432af5e7bf8819104700a))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* FDv2 -- cache initializer returns transfer-none on cache miss ([#1275](https://github.com/launchdarkly/js-core/issues/1275)) ([7bf3c31](https://github.com/launchdarkly/js-core/commit/7bf3c3122dc01146988d3722ff659f011967ea3d))
|
|
15
|
+
|
|
3
16
|
## [1.24.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-common-v1.23.0...js-client-sdk-common-v1.24.0) (2026-04-14)
|
|
4
17
|
|
|
5
18
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AutoEnvAttributes, Context, internal, LDFlagSet, LDFlagValue, LDLogger, LDPluginEnvironmentMetadata, Platform } from '@launchdarkly/js-sdk-common';
|
|
2
|
-
import { Hook, LDClient, LDClientIdentifyResult, LDContext, LDContextStrict, LDIdentifyResult, type LDOptions, LDWaitForInitializationOptions, LDWaitForInitializationResult } from './api';
|
|
2
|
+
import { Hook, LDClient, LDClientIdentifyResult, LDContext, LDContextStrict, LDIdentifyResult, type LDOptions, LDStartOptions, LDWaitForInitializationOptions, LDWaitForInitializationResult } from './api';
|
|
3
3
|
import { LDEvaluationDetail, LDEvaluationDetailTyped } from './api/LDEvaluationDetail';
|
|
4
4
|
import { LDIdentifyOptions } from './api/LDIdentifyOptions';
|
|
5
5
|
import { LDClientInternalOptions } from './configuration';
|
|
6
6
|
import { DataManager, DataManagerFactory } from './DataManager';
|
|
7
|
+
import type { InternalDataSystemOptions } from './datasource/LDClientDataSystemOptions';
|
|
7
8
|
import { LDDebugOverride } from './flag-manager/FlagManager';
|
|
8
9
|
import { ItemDescriptor } from './flag-manager/ItemDescriptor';
|
|
9
10
|
import LDEmitter, { EventName } from './LDEmitter';
|
|
@@ -24,6 +25,8 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
|
|
|
24
25
|
private _eventSendingEnabled;
|
|
25
26
|
private _baseHeaders;
|
|
26
27
|
protected dataManager: DataManager;
|
|
28
|
+
protected readonly isFDv2: boolean;
|
|
29
|
+
protected readonly dataSystemConfig?: InternalDataSystemOptions;
|
|
27
30
|
protected readonly environmentMetadata: LDPluginEnvironmentMetadata;
|
|
28
31
|
private _hookRunner;
|
|
29
32
|
private _inspectorManager;
|
|
@@ -31,6 +34,9 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
|
|
|
31
34
|
protected initializedPromise?: Promise<LDWaitForInitializationResult>;
|
|
32
35
|
protected initResolve?: (result: LDWaitForInitializationResult) => void;
|
|
33
36
|
protected initializeResult?: LDWaitForInitializationResult;
|
|
37
|
+
private _requiresStart;
|
|
38
|
+
protected initialContext?: LDContext;
|
|
39
|
+
protected startPromise?: Promise<LDWaitForInitializationResult>;
|
|
34
40
|
/**
|
|
35
41
|
* Creates the client object synchronously. No async, no network calls.
|
|
36
42
|
*/
|
|
@@ -51,6 +57,15 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
|
|
|
51
57
|
protected presetFlags(newFlags: {
|
|
52
58
|
[key: string]: ItemDescriptor;
|
|
53
59
|
}): void;
|
|
60
|
+
/**
|
|
61
|
+
* Starts the client and returns a promise that resolves to the initialization result.
|
|
62
|
+
*
|
|
63
|
+
* This method is idempotent - calling it multiple times returns the same promise.
|
|
64
|
+
*
|
|
65
|
+
* @param options Optional configuration. See {@link LDStartOptions}.
|
|
66
|
+
* @returns A promise that resolves to the initialization result.
|
|
67
|
+
*/
|
|
68
|
+
start(options?: LDStartOptions): Promise<LDWaitForInitializationResult>;
|
|
54
69
|
/**
|
|
55
70
|
* Identifies a context to LaunchDarkly. See {@link LDClient.identify}.
|
|
56
71
|
*
|
|
@@ -84,18 +99,14 @@ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
|
|
|
84
99
|
protected maybeSetInitializationResult(result: LDWaitForInitializationResult): void;
|
|
85
100
|
waitForInitialization(options?: LDWaitForInitializationOptions): Promise<LDWaitForInitializationResult>;
|
|
86
101
|
/**
|
|
87
|
-
* Apply a timeout promise to a base promise. This is for use with waitForInitialization
|
|
102
|
+
* Apply a timeout promise to a base promise. This is for use with waitForInitialization
|
|
103
|
+
* and start.
|
|
88
104
|
*
|
|
89
105
|
* @param basePromise The promise to race against a timeout.
|
|
90
106
|
* @param timeout The timeout in seconds.
|
|
91
107
|
* @returns A promise that resolves to the initialization result or timeout.
|
|
92
|
-
*
|
|
93
|
-
* @privateRemarks
|
|
94
|
-
* This method is protected because it is used by the browser SDK's `start` method.
|
|
95
|
-
* Eventually, the start method will be moved to this common implementation and this method will
|
|
96
|
-
* be made private.
|
|
97
108
|
*/
|
|
98
|
-
|
|
109
|
+
private _promiseWithTimeout;
|
|
99
110
|
on(eventName: EventName, listener: Function): void;
|
|
100
111
|
off(eventName: EventName, listener: Function): void;
|
|
101
112
|
track(key: string, data?: any, metricValue?: number): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LDClientImpl.d.ts","sourceRoot":"","sources":["../src/LDClientImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAGjB,OAAO,EAEP,QAAQ,EAER,SAAS,EACT,WAAW,EAEX,QAAQ,EACR,2BAA2B,EAE3B,QAAQ,EAET,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,sBAAsB,EACtB,SAAS,EACT,eAAe,EAEf,gBAAgB,EAIhB,KAAK,SAAS,EAGd,8BAA8B,EAC9B,6BAA6B,EAE9B,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,kBAAkB,EAAE,uBAAu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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LDIdentifyOptions } from './LDIdentifyOptions';
|
|
2
|
+
import { LDWaitForInitializationOptions } from './LDWaitForInitialization';
|
|
3
|
+
export interface LDStartOptions extends LDWaitForInitializationOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Optional bootstrap data to use for the identify operation.
|
|
6
|
+
* If {@link LDIdentifyOptions.bootstrap} is provided in identifyOptions, it takes precedence.
|
|
7
|
+
*/
|
|
8
|
+
bootstrap?: unknown;
|
|
9
|
+
/**
|
|
10
|
+
* Optional identify options to use for the identify operation.
|
|
11
|
+
* See {@link LDIdentifyOptions} for more information.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Since the first identify option should never be sheddable, the sheddable option is omitted
|
|
15
|
+
* from the interface to avoid confusion.
|
|
16
|
+
*/
|
|
17
|
+
identifyOptions?: Omit<LDIdentifyOptions, 'sheddable'>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=LDStartOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LDStartOptions.d.ts","sourceRoot":"","sources":["../../src/api/LDStartOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAE3E,MAAM,WAAW,cAAe,SAAQ,8BAA8B;IACpE;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;CACxD"}
|
package/dist/cjs/api/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './LDIdentifyOptions';
|
|
|
8
8
|
export * from './LDInspection';
|
|
9
9
|
export * from './LDIdentifyResult';
|
|
10
10
|
export * from './LDPlugin';
|
|
11
|
+
export * from './LDStartOptions';
|
|
11
12
|
export * from './LDWaitForInitialization';
|
|
12
13
|
export * from './LDContext';
|
|
13
14
|
export * from './datasource';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ApplicationTags, internal, LDFlagSet, LDLogger, LDPluginEnvironmentMetadata, ServiceEndpoints } from '@launchdarkly/js-sdk-common';
|
|
2
2
|
import { Hook, type LDOptions } from '../api';
|
|
3
|
+
import { LDContext } from '../api/LDContext';
|
|
3
4
|
import { LDInspection } from '../api/LDInspection';
|
|
4
5
|
import type { InternalDataSystemOptions, PlatformDataSystemDefaults } from '../datasource/LDClientDataSystemOptions';
|
|
5
6
|
export interface LDClientInternalOptions extends internal.LDInternalOptions {
|
|
@@ -8,6 +9,15 @@ export interface LDClientInternalOptions extends internal.LDInternalOptions {
|
|
|
8
9
|
credentialType: 'clientSideId' | 'mobileKey';
|
|
9
10
|
getLegacyStorageKeys?: () => string[];
|
|
10
11
|
dataSystemDefaults?: PlatformDataSystemDefaults;
|
|
12
|
+
/**
|
|
13
|
+
* When true, the SDK requires `start()` to be called before `identify()`.
|
|
14
|
+
* Set this value to `true` to use the new initialization pattern.
|
|
15
|
+
*/
|
|
16
|
+
requiresStart?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The initial context to use when starting the client.
|
|
19
|
+
*/
|
|
20
|
+
initialContext?: LDContext;
|
|
11
21
|
}
|
|
12
22
|
export interface Configuration {
|
|
13
23
|
readonly logger: LDLogger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Configuration.d.ts","sourceRoot":"","sources":["../../src/configuration/Configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEf,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,2BAA2B,EAE3B,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,yCAAyC,CAAC;AAMjD,MAAM,WAAW,uBAAwB,SAAQ,QAAQ,CAAC,iBAAiB;IACzE,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC;IACrF,sBAAsB,EAAE,CAAC,mBAAmB,EAAE,2BAA2B,KAAK,IAAI,EAAE,C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AE,MAAM,GAAG,GAAG,CAAC;gBAGnB,eAAe,GAAE,SAAc,EAC/B,eAAe,GAAE,uBAGhB;CAoCJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheInitializer.d.ts","sourceRoot":"","sources":["../../../src/datasource/fdv2/CacheInitializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAY,QAAQ,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"CacheInitializer.d.ts","sourceRoot":"","sources":["../../../src/datasource/fdv2/CacheInitializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAY,QAAQ,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAS3F;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,2CAA2C;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB;IACvB,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1017,6 +1017,46 @@ class EventFactory extends jsSdkCommon.internal.EventFactoryBase {
|
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
1019
|
|
|
1020
|
+
function readFlagsFromBootstrap(logger, data) {
|
|
1021
|
+
// If the bootstrap data came from an older server-side SDK, we'll have just a map of keys to values.
|
|
1022
|
+
// Newer SDKs that have an allFlagsState method will provide an extra "$flagsState" key that contains
|
|
1023
|
+
// the rest of the metadata we want. We do it this way for backward compatibility with older JS SDKs.
|
|
1024
|
+
const keys = Object.keys(data);
|
|
1025
|
+
const metadataKey = '$flagsState';
|
|
1026
|
+
const validKey = '$valid';
|
|
1027
|
+
const metadata = data[metadataKey];
|
|
1028
|
+
if (!metadata && keys.length) {
|
|
1029
|
+
logger.warn('LaunchDarkly client was initialized with bootstrap data that did not include flag' +
|
|
1030
|
+
' metadata. Events may not be sent correctly.');
|
|
1031
|
+
}
|
|
1032
|
+
if (data[validKey] === false) {
|
|
1033
|
+
logger.warn('LaunchDarkly bootstrap data is not available because the back end could not read the flags.');
|
|
1034
|
+
}
|
|
1035
|
+
const ret = {};
|
|
1036
|
+
keys.forEach((key) => {
|
|
1037
|
+
if (key !== metadataKey && key !== validKey) {
|
|
1038
|
+
let flag;
|
|
1039
|
+
if (metadata && metadata[key]) {
|
|
1040
|
+
flag = {
|
|
1041
|
+
value: data[key],
|
|
1042
|
+
...metadata[key],
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
else {
|
|
1046
|
+
flag = {
|
|
1047
|
+
value: data[key],
|
|
1048
|
+
version: 0,
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
ret[key] = {
|
|
1052
|
+
version: flag.version,
|
|
1053
|
+
flag,
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
return ret;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1020
1060
|
/**
|
|
1021
1061
|
* Suffix appended to context storage keys to form the freshness storage key.
|
|
1022
1062
|
*/
|
|
@@ -1945,6 +1985,10 @@ class LDClientImpl {
|
|
|
1945
1985
|
this._eventFactoryWithReasons = new EventFactory(true);
|
|
1946
1986
|
this._eventSendingEnabled = false;
|
|
1947
1987
|
this._identifyQueue = createAsyncTaskQueue();
|
|
1988
|
+
// NOTE: this is used to ease the transition to the new initialization pattern.
|
|
1989
|
+
// All client SDKs should set this to true with the exception of React Native which is
|
|
1990
|
+
// still using the deprecated construct + identify pattern.
|
|
1991
|
+
this._requiresStart = false;
|
|
1948
1992
|
if (!sdkKey) {
|
|
1949
1993
|
throw new Error('You must configure the client with a client-side SDK key');
|
|
1950
1994
|
}
|
|
@@ -1953,6 +1997,8 @@ class LDClientImpl {
|
|
|
1953
1997
|
}
|
|
1954
1998
|
this._config = new ConfigurationImpl(options, internalOptions);
|
|
1955
1999
|
this.logger = this._config.logger;
|
|
2000
|
+
this._requiresStart = internalOptions?.requiresStart ?? false;
|
|
2001
|
+
this.initialContext = internalOptions?.initialContext;
|
|
1956
2002
|
this._baseHeaders = jsSdkCommon.defaultHeaders(this.sdkKey, this.platform.info, this._config.tags, this._config.serviceEndpoints.includeAuthorizationHeader, this._config.userAgentHeaderName);
|
|
1957
2003
|
this._flagManager = new DefaultFlagManager(this.platform, sdkKey, this._config.maxCachedContexts, this._config.disableCache ?? false, this._config.logger);
|
|
1958
2004
|
this._diagnosticsManager = createDiagnosticsManager(sdkKey, this._config, platform);
|
|
@@ -1970,6 +2016,8 @@ class LDClientImpl {
|
|
|
1970
2016
|
});
|
|
1971
2017
|
});
|
|
1972
2018
|
this.dataManager = dataManagerFactory(this._flagManager, this._config, this._baseHeaders, this.emitter, this._diagnosticsManager);
|
|
2019
|
+
this.isFDv2 = !!this._config.dataSystem;
|
|
2020
|
+
this.dataSystemConfig = this._config.dataSystem;
|
|
1973
2021
|
const hooks = [...this._config.hooks];
|
|
1974
2022
|
this.environmentMetadata = createPluginEnvironmentMetadata(this.sdkKey, this.platform, this._config);
|
|
1975
2023
|
this._config.getImplementationHooks(this.environmentMetadata).forEach((hook) => {
|
|
@@ -2047,6 +2095,57 @@ class LDClientImpl {
|
|
|
2047
2095
|
presetFlags(newFlags) {
|
|
2048
2096
|
this._flagManager.presetFlags(newFlags);
|
|
2049
2097
|
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Starts the client and returns a promise that resolves to the initialization result.
|
|
2100
|
+
*
|
|
2101
|
+
* This method is idempotent - calling it multiple times returns the same promise.
|
|
2102
|
+
*
|
|
2103
|
+
* @param options Optional configuration. See {@link LDStartOptions}.
|
|
2104
|
+
* @returns A promise that resolves to the initialization result.
|
|
2105
|
+
*/
|
|
2106
|
+
start(options) {
|
|
2107
|
+
if (this.initializeResult) {
|
|
2108
|
+
return Promise.resolve(this.initializeResult);
|
|
2109
|
+
}
|
|
2110
|
+
if (this.startPromise) {
|
|
2111
|
+
return this.startPromise;
|
|
2112
|
+
}
|
|
2113
|
+
if (!this.initialContext) {
|
|
2114
|
+
this.logger.error('Initial context not set');
|
|
2115
|
+
return Promise.resolve({ status: 'failed', error: new Error('Initial context not set') });
|
|
2116
|
+
}
|
|
2117
|
+
const identifyOptions = {
|
|
2118
|
+
...(options?.identifyOptions ?? {}),
|
|
2119
|
+
// Initial identify operations are not sheddable.
|
|
2120
|
+
sheddable: false,
|
|
2121
|
+
};
|
|
2122
|
+
// If the bootstrap data is provided in the start options, and the identify options do not
|
|
2123
|
+
// have bootstrap data, then use the bootstrap data from the start options.
|
|
2124
|
+
if (options?.bootstrap && !identifyOptions.bootstrap) {
|
|
2125
|
+
identifyOptions.bootstrap = options.bootstrap;
|
|
2126
|
+
}
|
|
2127
|
+
if (identifyOptions.bootstrap) {
|
|
2128
|
+
try {
|
|
2129
|
+
if (!identifyOptions.bootstrapParsed) {
|
|
2130
|
+
identifyOptions.bootstrapParsed = readFlagsFromBootstrap(this.logger, identifyOptions.bootstrap);
|
|
2131
|
+
}
|
|
2132
|
+
if (identifyOptions.bootstrapParsed) {
|
|
2133
|
+
this.presetFlags(identifyOptions.bootstrapParsed);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
catch (error) {
|
|
2137
|
+
this.logger.error('Failed to bootstrap data', error);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
if (!this.initializedPromise) {
|
|
2141
|
+
this.initializedPromise = new Promise((resolve) => {
|
|
2142
|
+
this.initResolve = resolve;
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
this.startPromise = this._promiseWithTimeout(this.initializedPromise, options?.timeout ?? 5, 'start');
|
|
2146
|
+
this.identifyResult(this.initialContext, identifyOptions);
|
|
2147
|
+
return this.startPromise;
|
|
2148
|
+
}
|
|
2050
2149
|
/**
|
|
2051
2150
|
* Identifies a context to LaunchDarkly. See {@link LDClient.identify}.
|
|
2052
2151
|
*
|
|
@@ -2084,6 +2183,10 @@ class LDClientImpl {
|
|
|
2084
2183
|
// If completed or shed, then we are done.
|
|
2085
2184
|
}
|
|
2086
2185
|
async identifyResult(pristineContext, identifyOptions) {
|
|
2186
|
+
if (this._requiresStart && !this.startPromise) {
|
|
2187
|
+
this.logger.error('The client must be started before a context can be identified. Call start() prior to identifying a context.');
|
|
2188
|
+
return { status: 'error', error: new Error('Identify called before start') };
|
|
2189
|
+
}
|
|
2087
2190
|
const identifyTimeout = identifyOptions?.timeout ?? DEFAULT_IDENTIFY_TIMEOUT_SECONDS;
|
|
2088
2191
|
const noTimeout = identifyOptions?.timeout === undefined && identifyOptions?.noTimeout === true;
|
|
2089
2192
|
// When noTimeout is specified, and a timeout is not specified, then this condition cannot
|
|
@@ -2193,7 +2296,7 @@ class LDClientImpl {
|
|
|
2193
2296
|
// If waitForInitialization was previously called, then return the promise with a timeout.
|
|
2194
2297
|
// This condition should only be triggered if waitForInitialization was called multiple times.
|
|
2195
2298
|
if (this.initializedPromise) {
|
|
2196
|
-
return this.
|
|
2299
|
+
return this._promiseWithTimeout(this.initializedPromise, timeout);
|
|
2197
2300
|
}
|
|
2198
2301
|
// Create a new promise for tracking initialization
|
|
2199
2302
|
if (!this.initializedPromise) {
|
|
@@ -2201,22 +2304,18 @@ class LDClientImpl {
|
|
|
2201
2304
|
this.initResolve = resolve;
|
|
2202
2305
|
});
|
|
2203
2306
|
}
|
|
2204
|
-
return this.
|
|
2307
|
+
return this._promiseWithTimeout(this.initializedPromise, timeout);
|
|
2205
2308
|
}
|
|
2206
2309
|
/**
|
|
2207
|
-
* Apply a timeout promise to a base promise. This is for use with waitForInitialization
|
|
2310
|
+
* Apply a timeout promise to a base promise. This is for use with waitForInitialization
|
|
2311
|
+
* and start.
|
|
2208
2312
|
*
|
|
2209
2313
|
* @param basePromise The promise to race against a timeout.
|
|
2210
2314
|
* @param timeout The timeout in seconds.
|
|
2211
2315
|
* @returns A promise that resolves to the initialization result or timeout.
|
|
2212
|
-
*
|
|
2213
|
-
* @privateRemarks
|
|
2214
|
-
* This method is protected because it is used by the browser SDK's `start` method.
|
|
2215
|
-
* Eventually, the start method will be moved to this common implementation and this method will
|
|
2216
|
-
* be made private.
|
|
2217
2316
|
*/
|
|
2218
|
-
|
|
2219
|
-
const cancelableTimeout = jsSdkCommon.cancelableTimedPromise(timeout,
|
|
2317
|
+
_promiseWithTimeout(basePromise, timeout, label = 'waitForInitialization') {
|
|
2318
|
+
const cancelableTimeout = jsSdkCommon.cancelableTimedPromise(timeout, label);
|
|
2220
2319
|
return Promise.race([
|
|
2221
2320
|
basePromise.then((res) => {
|
|
2222
2321
|
cancelableTimeout.cancel();
|
|
@@ -2446,46 +2545,6 @@ function safeRegisterDebugOverridePlugins(logger, debugOverride, plugins) {
|
|
|
2446
2545
|
});
|
|
2447
2546
|
}
|
|
2448
2547
|
|
|
2449
|
-
function readFlagsFromBootstrap(logger, data) {
|
|
2450
|
-
// If the bootstrap data came from an older server-side SDK, we'll have just a map of keys to values.
|
|
2451
|
-
// Newer SDKs that have an allFlagsState method will provide an extra "$flagsState" key that contains
|
|
2452
|
-
// the rest of the metadata we want. We do it this way for backward compatibility with older JS SDKs.
|
|
2453
|
-
const keys = Object.keys(data);
|
|
2454
|
-
const metadataKey = '$flagsState';
|
|
2455
|
-
const validKey = '$valid';
|
|
2456
|
-
const metadata = data[metadataKey];
|
|
2457
|
-
if (!metadata && keys.length) {
|
|
2458
|
-
logger.warn('LaunchDarkly client was initialized with bootstrap data that did not include flag' +
|
|
2459
|
-
' metadata. Events may not be sent correctly.');
|
|
2460
|
-
}
|
|
2461
|
-
if (data[validKey] === false) {
|
|
2462
|
-
logger.warn('LaunchDarkly bootstrap data is not available because the back end could not read the flags.');
|
|
2463
|
-
}
|
|
2464
|
-
const ret = {};
|
|
2465
|
-
keys.forEach((key) => {
|
|
2466
|
-
if (key !== metadataKey && key !== validKey) {
|
|
2467
|
-
let flag;
|
|
2468
|
-
if (metadata && metadata[key]) {
|
|
2469
|
-
flag = {
|
|
2470
|
-
value: data[key],
|
|
2471
|
-
...metadata[key],
|
|
2472
|
-
};
|
|
2473
|
-
}
|
|
2474
|
-
else {
|
|
2475
|
-
flag = {
|
|
2476
|
-
value: data[key],
|
|
2477
|
-
version: 0,
|
|
2478
|
-
};
|
|
2479
|
-
}
|
|
2480
|
-
ret[key] = {
|
|
2481
|
-
version: flag.version,
|
|
2482
|
-
flag,
|
|
2483
|
-
};
|
|
2484
|
-
}
|
|
2485
|
-
});
|
|
2486
|
-
return ret;
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
2548
|
/**
|
|
2490
2549
|
* Creates endpoint paths for browser (client-side ID) FDv1 evaluation.
|
|
2491
2550
|
*
|
|
@@ -3208,12 +3267,12 @@ async function loadFromCache(config) {
|
|
|
3208
3267
|
const { storage, crypto, environmentNamespace, context, logger } = config;
|
|
3209
3268
|
if (!storage) {
|
|
3210
3269
|
logger?.debug('No storage available for cache initializer');
|
|
3211
|
-
return
|
|
3270
|
+
return changeSet({ version: 0, type: 'none', updates: [] }, false);
|
|
3212
3271
|
}
|
|
3213
3272
|
const cached = await loadCachedFlags(storage, crypto, environmentNamespace, context, logger);
|
|
3214
3273
|
if (!cached) {
|
|
3215
3274
|
logger?.debug('Cache miss for context');
|
|
3216
|
-
return
|
|
3275
|
+
return changeSet({ version: 0, type: 'none', updates: [] }, false);
|
|
3217
3276
|
}
|
|
3218
3277
|
const updates = Object.entries(cached.flags).map(([key, flag]) => ({
|
|
3219
3278
|
kind: 'flag-eval',
|
|
@@ -4474,16 +4533,16 @@ function createFDv2DataSource(config) {
|
|
|
4474
4533
|
if (closed) {
|
|
4475
4534
|
return;
|
|
4476
4535
|
}
|
|
4477
|
-
if (result.type === 'changeSet') {
|
|
4536
|
+
if (result.type === 'changeSet' && result.payload.type !== 'none') {
|
|
4478
4537
|
applyChangeSet(result);
|
|
4479
4538
|
if (handleFdv1Fallback(result)) {
|
|
4480
|
-
// FDv1 fallback triggered during initialization
|
|
4539
|
+
// FDv1 fallback triggered during initialization -- data was received
|
|
4481
4540
|
// but we should move to synchronizers where the FDv1 adapter will run.
|
|
4482
4541
|
dataReceived = true;
|
|
4483
4542
|
break;
|
|
4484
4543
|
}
|
|
4485
4544
|
if (result.payload.state) {
|
|
4486
|
-
// Got basis data with a selector
|
|
4545
|
+
// Got basis data with a selector -- initialization is complete.
|
|
4487
4546
|
markInitialized();
|
|
4488
4547
|
return;
|
|
4489
4548
|
}
|