Skip to content

Commit 1d4d1b4

Browse files
committed
External configuration
1 parent de79828 commit 1d4d1b4

7 files changed

Lines changed: 81 additions & 48 deletions

File tree

packages/sdk/browser/example/src/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ statusBox.appendChild(document.createTextNode('Initializing...'));
2525

2626
const main = async () => {
2727
const ldclient = createClient(clientSideID, context, {
28-
useFDv2: true,
28+
// @ts-ignore dataSystem is @internal — experimental FDv2 opt-in
29+
dataSystem: {},
2930
});
3031
const render = () => {
3132
const flagValue = ldclient.variation(flagKey, false);

packages/sdk/browser/src/BrowserClient.ts

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import {
22
AutoEnvAttributes,
33
BasicLogger,
4+
BROWSER_DATA_SYSTEM_DEFAULTS,
45
browserFdv1Endpoints,
56
Configuration,
7+
dataSystemValidators,
68
FlagManager,
79
Hook,
810
internal,
11+
LDClientDataSystemOptions,
912
LDClientImpl,
1013
LDContext,
1114
LDEmitter,
@@ -19,6 +22,7 @@ import {
1922
Platform,
2023
readFlagsFromBootstrap,
2124
safeRegisterDebugOverridePlugins,
25+
validateOptions,
2226
} from '@launchdarkly/js-client-sdk-common';
2327

2428
import { getHref } from './BrowserApi';
@@ -78,41 +82,53 @@ class BrowserClientImpl extends LDClientImpl {
7882
const { eventUrlTransformer } = validatedBrowserOptions;
7983
const endpoints = browserFdv1Endpoints(clientSideId);
8084

81-
const dataManagerFactory = validatedBrowserOptions.useFDv2
82-
? (
83-
flagManager: FlagManager,
84-
configuration: Configuration,
85-
baseHeaders: LDHeaders,
86-
emitter: LDEmitter,
87-
_diagnosticsManager?: internal.DiagnosticsManager,
88-
) =>
89-
new BrowserFDv2DataManager(
90-
platform,
91-
flagManager,
92-
clientSideId,
93-
configuration,
94-
baseHeaders,
95-
emitter,
96-
)
97-
: (
98-
flagManager: FlagManager,
99-
configuration: Configuration,
100-
baseHeaders: LDHeaders,
101-
emitter: LDEmitter,
102-
diagnosticsManager?: internal.DiagnosticsManager,
103-
) =>
104-
new BrowserDataManager(
105-
platform,
106-
flagManager,
107-
clientSideId,
108-
configuration,
109-
validatedBrowserOptions,
110-
endpoints.polling,
111-
endpoints.streaming,
112-
baseHeaders,
113-
emitter,
114-
diagnosticsManager,
115-
);
85+
const validatedDataSystem =
86+
options.dataSystem !== undefined
87+
? (validateOptions(
88+
options.dataSystem,
89+
dataSystemValidators,
90+
BROWSER_DATA_SYSTEM_DEFAULTS as unknown as Record<string, unknown>,
91+
logger,
92+
'dataSystem',
93+
) as unknown as LDClientDataSystemOptions)
94+
: undefined;
95+
96+
const dataManagerFactory =
97+
validatedDataSystem !== undefined
98+
? (
99+
flagManager: FlagManager,
100+
configuration: Configuration,
101+
baseHeaders: LDHeaders,
102+
emitter: LDEmitter,
103+
_diagnosticsManager?: internal.DiagnosticsManager,
104+
) =>
105+
new BrowserFDv2DataManager(
106+
platform,
107+
flagManager,
108+
clientSideId,
109+
configuration,
110+
baseHeaders,
111+
emitter,
112+
)
113+
: (
114+
flagManager: FlagManager,
115+
configuration: Configuration,
116+
baseHeaders: LDHeaders,
117+
emitter: LDEmitter,
118+
diagnosticsManager?: internal.DiagnosticsManager,
119+
) =>
120+
new BrowserDataManager(
121+
platform,
122+
flagManager,
123+
clientSideId,
124+
configuration,
125+
validatedBrowserOptions,
126+
endpoints.polling,
127+
endpoints.streaming,
128+
baseHeaders,
129+
emitter,
130+
diagnosticsManager,
131+
);
116132

117133
super(clientSideId, autoEnvAttributes, platform, baseOptionsWithDefaults, dataManagerFactory, {
118134
// This logic is derived from https://github.com/launchdarkly/js-sdk-common/blob/main/src/PersistentFlagStore.js

packages/sdk/browser/src/options.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ export interface BrowserOptions extends Omit<LDOptionsBase, 'initialConnectionMo
5959
* A list of plugins to be used with the SDK.
6060
*/
6161
plugins?: LDPlugin[];
62-
63-
/**
64-
* Opt-in to the FDv2 data delivery protocol. When enabled, the SDK uses
65-
* the new `/sdk/poll/eval` and `/sdk/stream/eval` endpoints with the
66-
* FDv2 protocol handler and orchestrator.
67-
*
68-
* Default: false
69-
*/
70-
useFDv2?: boolean;
7162
}
7263

7364
export interface ValidatedOptions {
@@ -76,23 +67,20 @@ export interface ValidatedOptions {
7667
streaming?: boolean;
7768
automaticBackgroundHandling?: boolean;
7869
plugins: LDPlugin[];
79-
useFDv2: boolean;
8070
}
8171

8272
const optDefaults = {
8373
fetchGoals: true,
8474
eventUrlTransformer: (url: string) => url,
8575
streaming: undefined,
8676
plugins: [],
87-
useFDv2: false,
8877
};
8978

9079
const validators: { [Property in keyof BrowserOptions]: TypeValidator | undefined } = {
9180
fetchGoals: TypeValidators.Boolean,
9281
eventUrlTransformer: TypeValidators.Function,
9382
streaming: TypeValidators.Boolean,
9483
plugins: TypeValidators.createTypeArray('LDPlugin', {}),
95-
useFDv2: TypeValidators.Boolean,
9684
};
9785

9886
function withBrowserDefaults(opts: BrowserOptions): BrowserOptions {

packages/shared/sdk-client/src/api/LDOptions.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LDLogger } from '@launchdarkly/js-sdk-common';
22

3+
import { LDClientDataSystemOptions } from './datasource/LDClientDataSystemOptions';
34
import { Hook } from './integrations/Hooks';
45
import { LDInspection } from './LDInspection';
56

@@ -279,4 +280,19 @@ export interface LDOptions {
279280
* @defaultValue false.
280281
*/
281282
cleanOldPersistentData?: boolean;
283+
284+
/**
285+
* @internal
286+
*
287+
* WARNING: This option is EXPERIMENTAL and UNSUPPORTED. It is subject to
288+
* change or removal without notice. Do not use in production applications.
289+
* Using this option may result in unexpected behavior, data loss, or
290+
* breaking changes in future SDK versions. LaunchDarkly does not provide
291+
* support for configurations using this option.
292+
*
293+
* Configuration for the FDv2 data system. When present, the SDK uses
294+
* the FDv2 protocol for flag delivery instead of the default FDv1
295+
* protocol.
296+
*/
297+
dataSystem?: LDClientDataSystemOptions;
282298
}

packages/shared/sdk-client/src/configuration/Configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@launchdarkly/js-sdk-common';
1111

1212
import { Hook, type LDOptions } from '../api';
13+
import type { LDClientDataSystemOptions } from '../api/datasource/LDClientDataSystemOptions';
1314
import { LDInspection } from '../api/LDInspection';
1415
import validateOptions from './validateOptions';
1516
import validators from './validators';
@@ -59,6 +60,7 @@ export interface Configuration {
5960
readonly inspectors: LDInspection[];
6061
readonly credentialType: 'clientSideId' | 'mobileKey';
6162
readonly getImplementationHooks: (environmentMetadata: LDPluginEnvironmentMetadata) => Hook[];
63+
readonly dataSystem?: LDClientDataSystemOptions;
6264
}
6365

6466
const DEFAULT_POLLING: string = 'https://clientsdk.launchdarkly.com';
@@ -138,6 +140,7 @@ export default class ConfigurationImpl implements Configuration {
138140
public readonly getImplementationHooks: (
139141
environmentMetadata: LDPluginEnvironmentMetadata,
140142
) => Hook[];
143+
public readonly dataSystem?: LDClientDataSystemOptions;
141144

142145
// Allow indexing Configuration by a string
143146
[index: string]: any;

packages/shared/sdk-client/src/configuration/validators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const validators: Record<keyof LDOptions, TypeValidator> = {
3535
hooks: TypeValidators.createTypeArray('Hook[]', {}),
3636
inspectors: TypeValidators.createTypeArray('LDInspection', {}),
3737
cleanOldPersistentData: TypeValidators.Boolean,
38+
dataSystem: TypeValidators.Object,
3839
};
3940

4041
export default validators;

packages/shared/sdk-client/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ export { flagEvalPayloadToItemDescriptors } from './datasource/flagEvalMapper';
116116
export { createDataSourceStatusManager } from './datasource/DataSourceStatusManager';
117117
export type { DataSourceStatusManager } from './datasource/DataSourceStatusManager';
118118

119+
// FDv2 data system validators and platform defaults.
120+
export {
121+
dataSystemValidators,
122+
BROWSER_DATA_SYSTEM_DEFAULTS,
123+
MOBILE_DATA_SYSTEM_DEFAULTS,
124+
DESKTOP_DATA_SYSTEM_DEFAULTS,
125+
} from './datasource/LDClientDataSystemOptions';
126+
119127
// FDv2 connection mode type system — internal implementation.
120128
export type { ModeTable } from './datasource/ConnectionModeConfig';
121129
export {

0 commit comments

Comments
 (0)