Skip to content

Commit 364b25d

Browse files
committed
fix: Consolidate common exports between base package and compat package.
1 parent d42ffc0 commit 364b25d

File tree

3 files changed

+95
-155
lines changed

3 files changed

+95
-155
lines changed

packages/sdk/browser/src/common.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { BasicLogger, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
2+
3+
import { LDClient } from './BrowserClient';
4+
import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions';
5+
import { BrowserOptions as LDOptions } from './options';
6+
7+
// The exported LDIdentifyOptions and LDOptions are the browser specific implementations.
8+
// These shadow the common implementations.
9+
export type { LDIdentifyOptions, LDOptions };
10+
11+
export type {
12+
AutoEnvAttributes,
13+
BasicLogger,
14+
BasicLoggerOptions,
15+
EvaluationSeriesContext,
16+
EvaluationSeriesData,
17+
Hook,
18+
HookMetadata,
19+
IdentifySeriesContext,
20+
IdentifySeriesData,
21+
IdentifySeriesResult,
22+
IdentifySeriesStatus,
23+
LDContext,
24+
LDContextCommon,
25+
LDContextMeta,
26+
LDEvaluationDetail,
27+
LDEvaluationDetailTyped,
28+
LDEvaluationReason,
29+
LDFlagSet,
30+
LDInspection,
31+
LDLogger,
32+
LDLogLevel,
33+
LDMultiKindContext,
34+
LDSingleKindContext,
35+
} from '@launchdarkly/js-client-sdk-common';
36+
37+
/**
38+
* Provides a basic {@link LDLogger} implementation.
39+
*
40+
* This logging implementation uses a basic format that includes only the log level
41+
* and the message text. By default this uses log level 'info' and the output is
42+
* written to `console.error`.
43+
*
44+
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
45+
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
46+
* that will log "info" level and higher priorty messages and it will log messages to
47+
* console.info, console.warn, and console.error.
48+
*
49+
* @param options Configuration for the logger. If no options are specified, the
50+
* logger uses `{ level: 'info' }`.
51+
*
52+
* @example
53+
* This example shows how to use `basicLogger` in your SDK options to enable console
54+
* logging only at `warn` and `error` levels.
55+
* ```javascript
56+
* const ldOptions = {
57+
* logger: basicLogger({ level: 'warn' }),
58+
* };
59+
* ```
60+
*
61+
* @example
62+
* This example shows how to use `basicLogger` in your SDK options to cause all
63+
* log output to go to `console.log`
64+
* ```javascript
65+
* const ldOptions = {
66+
* logger: basicLogger({ destination: console.log }),
67+
* };
68+
* ```
69+
*
70+
* * @example
71+
* The configuration also allows you to control the destination for each log level.
72+
* ```javascript
73+
* const ldOptions = {
74+
* logger: basicLogger({
75+
* destination: {
76+
* debug: console.debug,
77+
* info: console.info,
78+
* warn: console.warn,
79+
* error:console.error
80+
* }
81+
* }),
82+
* };
83+
* ```
84+
*/
85+
export function basicLogger(options: BasicLoggerOptions): LDLogger {
86+
return new BasicLogger(options);
87+
}

packages/sdk/browser/src/compat/index.ts

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,13 @@
55
* Some code changes may still be required, for example {@link LDOptions} removes
66
* support for some previously available options.
77
*/
8-
import {
9-
basicLogger,
10-
EvaluationSeriesContext,
11-
EvaluationSeriesData,
12-
Hook,
13-
HookMetadata,
14-
IdentifySeriesContext,
15-
IdentifySeriesData,
16-
IdentifySeriesResult,
17-
IdentifySeriesStatus,
18-
LDContext,
19-
LDContextCommon,
20-
LDContextMeta,
21-
LDEvaluationDetail,
22-
LDEvaluationDetailTyped,
23-
LDEvaluationReason,
24-
LDFlagSet,
25-
LDIdentifyOptions,
26-
LDLogger,
27-
LDLogLevel,
28-
LDMultiKindContext,
29-
LDOptions,
30-
LDSingleKindContext,
31-
} from '..';
8+
import { LDContext, LDOptions } from '@launchdarkly/js-client-sdk-common';
9+
3210
import { LDClient } from './LDClientCompat';
3311
import LDClientCompatImpl from './LDClientCompatImpl';
3412

35-
export type {
36-
LDClient,
37-
LDFlagSet,
38-
LDContext,
39-
LDContextCommon,
40-
LDContextMeta,
41-
LDMultiKindContext,
42-
LDSingleKindContext,
43-
LDLogLevel,
44-
LDLogger,
45-
LDOptions,
46-
LDEvaluationDetail,
47-
LDEvaluationDetailTyped,
48-
LDEvaluationReason,
49-
LDIdentifyOptions,
50-
Hook,
51-
HookMetadata,
52-
EvaluationSeriesContext,
53-
EvaluationSeriesData,
54-
IdentifySeriesContext,
55-
IdentifySeriesData,
56-
IdentifySeriesResult,
57-
IdentifySeriesStatus,
58-
basicLogger,
59-
};
13+
export * from '../common';
14+
export type { LDClient };
6015

6116
/**
6217
* Creates an instance of the LaunchDarkly client. This version of initialization is for

packages/sdk/browser/src/index.ts

Lines changed: 4 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,13 @@
1010
*
1111
* @packageDocumentation
1212
*/
13-
import {
14-
AutoEnvAttributes,
15-
BasicLogger,
16-
BasicLoggerOptions,
17-
EvaluationSeriesContext,
18-
EvaluationSeriesData,
19-
Hook,
20-
HookMetadata,
21-
IdentifySeriesContext,
22-
IdentifySeriesData,
23-
IdentifySeriesResult,
24-
IdentifySeriesStatus,
25-
LDContext,
26-
LDContextCommon,
27-
LDContextMeta,
28-
LDEvaluationDetail,
29-
LDEvaluationDetailTyped,
30-
LDEvaluationReason,
31-
LDFlagSet,
32-
LDInspection,
33-
LDLogger,
34-
LDLogLevel,
35-
LDMultiKindContext,
36-
LDSingleKindContext,
37-
} from '@launchdarkly/js-client-sdk-common';
13+
import { AutoEnvAttributes } from '@launchdarkly/js-client-sdk-common';
3814

39-
// The exported LDClient and LDOptions are the browser specific implementations.
40-
// These shadow the common implementations.
4115
import { BrowserClient, LDClient } from './BrowserClient';
42-
import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions';
43-
import { BrowserOptions as LDOptions } from './options';
16+
import { LDOptions } from './common';
4417

45-
export type {
46-
LDClient,
47-
LDFlagSet,
48-
LDContext,
49-
LDContextCommon,
50-
LDContextMeta,
51-
LDMultiKindContext,
52-
LDSingleKindContext,
53-
LDLogLevel,
54-
LDLogger,
55-
LDOptions,
56-
LDEvaluationDetail,
57-
LDEvaluationDetailTyped,
58-
LDEvaluationReason,
59-
LDIdentifyOptions,
60-
Hook,
61-
HookMetadata,
62-
EvaluationSeriesContext,
63-
EvaluationSeriesData,
64-
IdentifySeriesContext,
65-
IdentifySeriesData,
66-
IdentifySeriesResult,
67-
IdentifySeriesStatus,
68-
LDInspection,
69-
};
18+
export * from './common';
19+
export type { LDClient };
7020

7121
/**
7222
* Creates an instance of the LaunchDarkly client.
@@ -88,55 +38,3 @@ export function initialize(clientSideId: string, options?: LDOptions): LDClient
8838
// AutoEnvAttributes are not supported yet in the browser SDK.
8939
return new BrowserClient(clientSideId, AutoEnvAttributes.Disabled, options);
9040
}
91-
92-
/**
93-
* Provides a basic {@link LDLogger} implementation.
94-
*
95-
* This logging implementation uses a basic format that includes only the log level
96-
* and the message text. By default this uses log level 'info' and the output is
97-
* written to `console.error`.
98-
*
99-
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
100-
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
101-
* that will log "info" level and higher priorty messages and it will log messages to
102-
* console.info, console.warn, and console.error.
103-
*
104-
* @param options Configuration for the logger. If no options are specified, the
105-
* logger uses `{ level: 'info' }`.
106-
*
107-
* @example
108-
* This example shows how to use `basicLogger` in your SDK options to enable console
109-
* logging only at `warn` and `error` levels.
110-
* ```javascript
111-
* const ldOptions = {
112-
* logger: basicLogger({ level: 'warn' }),
113-
* };
114-
* ```
115-
*
116-
* @example
117-
* This example shows how to use `basicLogger` in your SDK options to cause all
118-
* log output to go to `console.log`
119-
* ```javascript
120-
* const ldOptions = {
121-
* logger: basicLogger({ destination: console.log }),
122-
* };
123-
* ```
124-
*
125-
* * @example
126-
* The configuration also allows you to control the destination for each log level.
127-
* ```javascript
128-
* const ldOptions = {
129-
* logger: basicLogger({
130-
* destination: {
131-
* debug: console.debug,
132-
* info: console.info,
133-
* warn: console.warn,
134-
* error:console.error
135-
* }
136-
* }),
137-
* };
138-
* ```
139-
*/
140-
export function basicLogger(options: BasicLoggerOptions): LDLogger {
141-
return new BasicLogger(options);
142-
}

0 commit comments

Comments
 (0)