diff --git a/packages/sdk/browser/__tests__/compat/imports.test.ts b/packages/sdk/browser/__tests__/compat/imports.test.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/sdk/browser/src/common.ts b/packages/sdk/browser/src/common.ts new file mode 100644 index 000000000..b6a422537 --- /dev/null +++ b/packages/sdk/browser/src/common.ts @@ -0,0 +1,86 @@ +import { BasicLogger, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common'; + +import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions'; +import { BrowserOptions as LDOptions } from './options'; + +// The exported LDIdentifyOptions and LDOptions are the browser specific implementations. +// These shadow the common implementations. +export type { LDIdentifyOptions, LDOptions }; + +export type { + AutoEnvAttributes, + BasicLogger, + BasicLoggerOptions, + EvaluationSeriesContext, + EvaluationSeriesData, + Hook, + HookMetadata, + IdentifySeriesContext, + IdentifySeriesData, + IdentifySeriesResult, + IdentifySeriesStatus, + LDContext, + LDContextCommon, + LDContextMeta, + LDEvaluationDetail, + LDEvaluationDetailTyped, + LDEvaluationReason, + LDFlagSet, + LDInspection, + LDLogger, + LDLogLevel, + LDMultiKindContext, + LDSingleKindContext, +} from '@launchdarkly/js-client-sdk-common'; + +/** + * Provides a basic {@link LDLogger} implementation. + * + * This logging implementation uses a basic format that includes only the log level + * and the message text. By default this uses log level 'info' and the output is + * written to `console.error`. + * + * To use the logger created by this function, put it into {@link LDOptions.logger}. If + * you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger + * that will log "info" level and higher priorty messages and it will log messages to + * console.info, console.warn, and console.error. + * + * @param options Configuration for the logger. If no options are specified, the + * logger uses `{ level: 'info' }`. + * + * @example + * This example shows how to use `basicLogger` in your SDK options to enable console + * logging only at `warn` and `error` levels. + * ```javascript + * const ldOptions = { + * logger: basicLogger({ level: 'warn' }), + * }; + * ``` + * + * @example + * This example shows how to use `basicLogger` in your SDK options to cause all + * log output to go to `console.log` + * ```javascript + * const ldOptions = { + * logger: basicLogger({ destination: console.log }), + * }; + * ``` + * + * * @example + * The configuration also allows you to control the destination for each log level. + * ```javascript + * const ldOptions = { + * logger: basicLogger({ + * destination: { + * debug: console.debug, + * info: console.info, + * warn: console.warn, + * error:console.error + * } + * }), + * }; + * ``` + */ +export function basicLogger(options: BasicLoggerOptions): LDLogger { + return new BasicLogger(options); +} diff --git a/packages/sdk/browser/src/compat/index.ts b/packages/sdk/browser/src/compat/index.ts index 73b0052a8..d960dd6c5 100644 --- a/packages/sdk/browser/src/compat/index.ts +++ b/packages/sdk/browser/src/compat/index.ts @@ -5,58 +5,13 @@ * Some code changes may still be required, for example {@link LDOptions} removes * support for some previously available options. */ -import { - basicLogger, - EvaluationSeriesContext, - EvaluationSeriesData, - Hook, - HookMetadata, - IdentifySeriesContext, - IdentifySeriesData, - IdentifySeriesResult, - IdentifySeriesStatus, - LDContext, - LDContextCommon, - LDContextMeta, - LDEvaluationDetail, - LDEvaluationDetailTyped, - LDEvaluationReason, - LDFlagSet, - LDIdentifyOptions, - LDLogger, - LDLogLevel, - LDMultiKindContext, - LDOptions, - LDSingleKindContext, -} from '..'; +import { LDContext, LDOptions } from '@launchdarkly/js-client-sdk-common'; + import { LDClient } from './LDClientCompat'; import LDClientCompatImpl from './LDClientCompatImpl'; -export type { - LDClient, - LDFlagSet, - LDContext, - LDContextCommon, - LDContextMeta, - LDMultiKindContext, - LDSingleKindContext, - LDLogLevel, - LDLogger, - LDOptions, - LDEvaluationDetail, - LDEvaluationDetailTyped, - LDEvaluationReason, - LDIdentifyOptions, - Hook, - HookMetadata, - EvaluationSeriesContext, - EvaluationSeriesData, - IdentifySeriesContext, - IdentifySeriesData, - IdentifySeriesResult, - IdentifySeriesStatus, - basicLogger, -}; +export * from '../common'; +export type { LDClient }; /** * Creates an instance of the LaunchDarkly client. This version of initialization is for diff --git a/packages/sdk/browser/src/index.ts b/packages/sdk/browser/src/index.ts index 045fafb84..fb9fca306 100644 --- a/packages/sdk/browser/src/index.ts +++ b/packages/sdk/browser/src/index.ts @@ -10,63 +10,13 @@ * * @packageDocumentation */ -import { - AutoEnvAttributes, - BasicLogger, - BasicLoggerOptions, - EvaluationSeriesContext, - EvaluationSeriesData, - Hook, - HookMetadata, - IdentifySeriesContext, - IdentifySeriesData, - IdentifySeriesResult, - IdentifySeriesStatus, - LDContext, - LDContextCommon, - LDContextMeta, - LDEvaluationDetail, - LDEvaluationDetailTyped, - LDEvaluationReason, - LDFlagSet, - LDInspection, - LDLogger, - LDLogLevel, - LDMultiKindContext, - LDSingleKindContext, -} from '@launchdarkly/js-client-sdk-common'; +import { AutoEnvAttributes } from '@launchdarkly/js-client-sdk-common'; -// The exported LDClient and LDOptions are the browser specific implementations. -// These shadow the common implementations. import { BrowserClient, LDClient } from './BrowserClient'; -import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions'; -import { BrowserOptions as LDOptions } from './options'; +import { LDOptions } from './common'; -export type { - LDClient, - LDFlagSet, - LDContext, - LDContextCommon, - LDContextMeta, - LDMultiKindContext, - LDSingleKindContext, - LDLogLevel, - LDLogger, - LDOptions, - LDEvaluationDetail, - LDEvaluationDetailTyped, - LDEvaluationReason, - LDIdentifyOptions, - Hook, - HookMetadata, - EvaluationSeriesContext, - EvaluationSeriesData, - IdentifySeriesContext, - IdentifySeriesData, - IdentifySeriesResult, - IdentifySeriesStatus, - LDInspection, -}; +export * from './common'; +export type { LDClient }; /** * Creates an instance of the LaunchDarkly client. @@ -88,55 +38,3 @@ export function initialize(clientSideId: string, options?: LDOptions): LDClient // AutoEnvAttributes are not supported yet in the browser SDK. return new BrowserClient(clientSideId, AutoEnvAttributes.Disabled, options); } - -/** - * Provides a basic {@link LDLogger} implementation. - * - * This logging implementation uses a basic format that includes only the log level - * and the message text. By default this uses log level 'info' and the output is - * written to `console.error`. - * - * To use the logger created by this function, put it into {@link LDOptions.logger}. If - * you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger - * that will log "info" level and higher priorty messages and it will log messages to - * console.info, console.warn, and console.error. - * - * @param options Configuration for the logger. If no options are specified, the - * logger uses `{ level: 'info' }`. - * - * @example - * This example shows how to use `basicLogger` in your SDK options to enable console - * logging only at `warn` and `error` levels. - * ```javascript - * const ldOptions = { - * logger: basicLogger({ level: 'warn' }), - * }; - * ``` - * - * @example - * This example shows how to use `basicLogger` in your SDK options to cause all - * log output to go to `console.log` - * ```javascript - * const ldOptions = { - * logger: basicLogger({ destination: console.log }), - * }; - * ``` - * - * * @example - * The configuration also allows you to control the destination for each log level. - * ```javascript - * const ldOptions = { - * logger: basicLogger({ - * destination: { - * debug: console.debug, - * info: console.info, - * warn: console.warn, - * error:console.error - * } - * }), - * }; - * ``` - */ -export function basicLogger(options: BasicLoggerOptions): LDLogger { - return new BasicLogger(options); -}