|
| 1 | +/** |
| 2 | + * This is the API reference for the LaunchDarkly Client-Side SDK for JavaScript. |
| 3 | + * |
| 4 | + * This SDK is intended for use in browser environments. |
| 5 | + * |
| 6 | + * In typical usage, you will call {@link initialize} once at startup time to obtain an instance of |
| 7 | + * {@link LDClient}, which provides access to all of the SDK's functionality. |
| 8 | + * |
| 9 | + * For more information, see the SDK reference guide. |
| 10 | + * |
| 11 | + * @packageDocumentation |
| 12 | + */ |
1 | 13 | import { |
2 | 14 | AutoEnvAttributes, |
| 15 | + BasicLogger, |
3 | 16 | EvaluationSeriesContext, |
4 | 17 | EvaluationSeriesData, |
5 | 18 | Hook, |
@@ -52,7 +65,57 @@ export type { |
52 | 65 | IdentifySeriesStatus, |
53 | 66 | }; |
54 | 67 |
|
55 | | -export function init(clientSideId: string, options?: LDOptions): LDClient { |
| 68 | +/** |
| 69 | + * Creates an instance of the LaunchDarkly client. |
| 70 | + * |
| 71 | + * The client will begin attempting to connect to LaunchDarkly as soon as it is created. To |
| 72 | + * determine when it is ready to use, call [[LDClient.waitForInitialization]], or register an |
| 73 | + * event listener for the `"ready"` event using [[LDClient.on]]. |
| 74 | + * |
| 75 | + * Usage: |
| 76 | + * ``` |
| 77 | + * import { initialize } from 'launchdarkly-js-client-sdk'; |
| 78 | + * const client = initialize(envKey, context, options); |
| 79 | + * ``` |
| 80 | + * |
| 81 | + * @param clientSideId |
| 82 | + * The client-side id, also known as the environment ID. |
| 83 | + * @param options |
| 84 | + * Optional configuration settings. |
| 85 | + * @return |
| 86 | + * The new client instance. |
| 87 | + */ |
| 88 | +export function initialize(clientSideId: string, options?: LDOptions): LDClient { |
56 | 89 | // AutoEnvAttributes are not supported yet in the browser SDK. |
57 | 90 | return new BrowserClient(clientSideId, AutoEnvAttributes.Disabled, options); |
58 | 91 | } |
| 92 | + |
| 93 | +/** |
| 94 | + * Provides a simple {@link LDLogger} implementation. |
| 95 | + * |
| 96 | + * This logging implementation uses a simple format that includes only the log level |
| 97 | + * and the message text. By default, output is written to `console` methods (`console.info` |
| 98 | + * for normal informational messages, `console.warn` for warnings, `console.error` for |
| 99 | + * errors, and `console.log` for debug output) and the default minimum level is `info` |
| 100 | + * (that is, debug output is suppressed). You can filter by log level or change the output |
| 101 | + * destination with [[BasicLoggerOptions]]. |
| 102 | + * |
| 103 | + * To use the logger created by this function, put it into [[LDOptions.logger]]. If |
| 104 | + * you do not set [[LDOptions.logger]] to anything, the SDK uses a default logger |
| 105 | + * that is equivalent to `ld.basicLogger({ level: 'info' })`. |
| 106 | + * |
| 107 | + * @param options Configuration for the logger. If no options are specified, the |
| 108 | + * logger uses `{ level: 'info' }`. |
| 109 | + * |
| 110 | + * @example |
| 111 | + * This example shows how to use `basicLogger` in your SDK options to enable console |
| 112 | + * logging only at `warn` and `error` levels. |
| 113 | + * ```javascript |
| 114 | + * const ldOptions = { |
| 115 | + * logger: ld.basicLogger({ level: 'warn' }), |
| 116 | + * }; |
| 117 | + * ``` |
| 118 | + */ |
| 119 | +export function basicLogger(options: BasicLoggerOptions): LDLogger { |
| 120 | + return new BasicLogger(options); |
| 121 | +} |
0 commit comments