From f993d3f72a25812a8b31a529ebe336248d8a8dcc Mon Sep 17 00:00:00 2001 From: Steven Zhang Date: Thu, 18 Dec 2025 15:43:08 -0600 Subject: [PATCH] fix: update initialization method in combined browser SDK to createClient - Updated the `@launchdarkly/js-client-sdk` dependency from 0.7.0 to 0.11.0. - Refactored the SDK's initialization flow by replacing the `initialize` method with `createClient`, which now requires an initial context parameter. - Adjusted usage examples and documentation to reflect the new client creation and initialization process. --- packages/sdk/combined-browser/package.json | 2 +- packages/sdk/combined-browser/src/index.ts | 28 +++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/sdk/combined-browser/package.json b/packages/sdk/combined-browser/package.json index c68af3b5db..9aa6de2e44 100644 --- a/packages/sdk/combined-browser/package.json +++ b/packages/sdk/combined-browser/package.json @@ -45,7 +45,7 @@ "check": "yarn prettier && yarn lint && yarn build && yarn test" }, "dependencies": { - "@launchdarkly/js-client-sdk": "0.7.0", + "@launchdarkly/js-client-sdk": "0.11.0", "@launchdarkly/observability": "0.2.0", "@launchdarkly/session-replay": "0.2.0" }, diff --git a/packages/sdk/combined-browser/src/index.ts b/packages/sdk/combined-browser/src/index.ts index 59b4c0d782..9bfd844c04 100644 --- a/packages/sdk/combined-browser/src/index.ts +++ b/packages/sdk/combined-browser/src/index.ts @@ -3,14 +3,19 @@ * * This SDK is intended for use in browser environments. It includes the observability and session replay plugins. * - * In typical usage, you will call {@link initialize} once at startup time to obtain an instance of + * In typical usage, you will call {@link createClient} once at startup time to obtain an instance of * {@link LDClient}, which provides access to all of the SDK's functionality. * * For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/javascript). * * @packageDocumentation */ -import { initialize as initializeJsClient, LDClient, LDOptions } from '@launchdarkly/js-client-sdk'; +import { + createClient as createClientJs, + LDClient, + LDContext, + LDOptions, +} from '@launchdarkly/js-client-sdk'; import Observability, { ObserveOptions } from '@launchdarkly/observability'; import SessionReplay, { RecordOptions } from '@launchdarkly/session-replay'; @@ -42,18 +47,29 @@ export interface LDBrowserOptions extends LDOptions { * * Usage: * ``` - * import { initialize } from '@launchdarkly/browser'; - * const client = initialize(clientSideId, context, options); + * import { createClient } from '@launchdarkly/browser'; + * const client = createClient(clientSideId, context, options); + * + * // Attach event listeners and add any additional initialization logic here + * + * // Then start the client + * client.start(); * ``` * * @param clientSideId * The client-side ID, also known as the environment ID. + * @param context + * The initial context used to identify the user. @see {@link LDContext} * @param options * Optional configuration settings. * @return * The new client instance. */ -export function initialize(clientSideId: string, options?: LDBrowserOptions): LDClient { +export function createClient( + clientSideId: string, + context: LDContext, + options?: LDBrowserOptions, +): LDClient { const optionsWithPlugins = { ...options, plugins: [ @@ -62,5 +78,5 @@ export function initialize(clientSideId: string, options?: LDBrowserOptions): LD new SessionReplay(options?.tmpProjectId ?? '1', options?.sessionReplay), ], }; - return initializeJsClient(clientSideId, optionsWithPlugins); + return createClientJs(clientSideId, context, optionsWithPlugins); }