-
Notifications
You must be signed in to change notification settings - Fork 66
/
typings.d.ts
157 lines (146 loc) · 6.3 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* This is the API reference for the LaunchDarkly SDK for browser JavaScript.
*
* In typical usage, you will call {@link initialize} 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
*/
declare module 'launchdarkly-js-client-sdk' {
export * from 'launchdarkly-js-sdk-common';
import {
BasicLoggerOptions,
LDClientBase,
LDContext,
LDLogger,
LDOptionsBase,
} from 'launchdarkly-js-sdk-common';
/**
* Creates an instance of the LaunchDarkly client.
*
* The client will begin attempting to connect to LaunchDarkly as soon as it is created. To
* determine when it is ready to use, call [[LDClient.waitForInitialization]], or register an
* event listener for the `"ready"` event using [[LDClient.on]].
*
* Note that you can either import this as a named export or as part of the default exports,
* although the latter is deprecated:
*
* // Preferred usage:
* import { initialize } from 'launchdarkly-js-client-sdk';
* const client = initialize(envKey, context, options);
*
* // Deprecated usage:
* import LaunchDarkly from 'launchdarkly-js-client-sdk';
* const client = LaunchDarkly.initialize(envKey, user, options);
*
* @param envKey
* The environment ID.
* @param context
* The initial context properties. These can be changed later with [[LDClient.identify]].
* @param options
* Optional configuration settings.
* @return
* The new client instance.
*/
export function initialize(envKey: string, context: LDContext, options?: LDOptions): LDClient;
// This is @ignored because TypeDoc does not show default exports correctly. We'll just explain
// the export situation in the comment for initialize().
/** @ignore */
const LaunchDarkly: {
initialize: (envKey: string, context: LDContext, options?: LDOptions) => LDClient;
version: string;
};
/** @ignore */ // see above
export default LaunchDarkly;
/**
* Initialization options for the LaunchDarkly browser SDK.
*/
export interface LDOptions extends LDOptionsBase {
/**
* The signed context key for Secure Mode.
*
* For more information, see the JavaScript SDK Reference Guide on
* [Secure mode](https://docs.launchdarkly.com/sdk/features/secure-mode#configuring-secure-mode-in-the-javascript-client-side-sdk).
*/
hash?: string;
/**
* Whether the client should make a request to LaunchDarkly for Experimentation metrics (goals).
*
* This is true by default, meaning that this request will be made on every page load.
* Set it to false if you are not using Experimentation and want to skip the request.
*/
fetchGoals?: boolean;
/**
* A function which, if present, can change the URL in analytics events to something other
* than the actual browser URL. It will be called with the current browser URL as a parameter,
* and returns the value that should be stored in the event's `url` property.
*/
eventUrlTransformer?: (url: string) => string;
/**
* If set to true, this prevents the SDK from trying to use a synchronous HTTP request to deliver
* analytics events if the page is being closed. Not all browsers allow such requests; the SDK
* normally tries to avoid making them if not allowed, by using browser detection, but sometimes
* browser detection may not work so if you are seeing errors like "synchronous XHR request
* during page dismissal", you may want to set this option. Since currently the SDK does not have
* a better way to deliver events in this scenario, some events may be lost.
*/
disableSyncEventPost?: boolean;
}
/**
* The LaunchDarkly SDK client object.
*
* Applications should configure the client at page load time and reuse the same instance.
*
* For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/javascript).
*/
export interface LDClient extends LDClientBase {
/**
* Allows you to wait until the client has received metrics (goals) data from LaunchDarkly.
*
* This is only relevant if you are using Experimentation features like click events and
* pageview events. Until the client has received the configuration for these, which
* happens immediately after the initial request for feature flags, click events and
* pageview events will not work, so you may wish to wait using this method before
* doing anything that you expect to generate those events.
*
* The returned Promise will be resolved once the client has received metrics data. If
* you prefer to use event handlers rather than Promises, you can listen on the client
* for a `"goalsReady"` event instead.
*
* @returns
* A Promise containing the initialization state of the client.
*/
waitUntilGoalsReady(): Promise<void>;
}
/**
* Provides a simple [[LDLogger]] implementation.
*
* This logging implementation uses a simple format that includes only the log level
* and the message text. By default, output is written to `console` methods (`console.info`
* for normal informational messages, `console.warn` for warnings, `console.error` for
* errors, and `console.log` for debug output) and the default minimum level is `info`
* (that is, debug output is suppressed). You can filter by log level or change the output
* destination with [[BasicLoggerOptions]].
*
* To use the logger created by this function, put it into [[LDOptions.logger]]. If
* you do not set [[LDOptions.logger]] to anything, the SDK uses a default logger
* that is equivalent to `ld.basicLogger({ level: 'info' })`.
*
* @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: ld.basicLogger({ level: 'warn' }),
* };
* ```
*/
export function basicLogger(
options?: BasicLoggerOptions
): LDLogger;
}