@launchdarkly/js-client-sdk 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +2 -2
- package/dist/common-DPjctgS7.d.cts +174 -0
- package/dist/common-DPjctgS7.d.ts +174 -0
- package/dist/compat.cjs +1 -1
- package/dist/compat.d.cts +20 -5
- package/dist/compat.d.ts +20 -5
- package/dist/compat.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -186
- package/dist/index.d.ts +4 -186
- package/dist/index.js +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.2](https://github.com/launchdarkly/js-core/compare/js-client-sdk-v0.3.1...js-client-sdk-v0.3.2) (2024-11-13)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* Export correct options for compat. ([#678](https://github.com/launchdarkly/js-core/issues/678)) ([8d8250c](https://github.com/launchdarkly/js-core/commit/8d8250cafb20b60e45ac3661fd8b079cb62fb83e))
|
|
9
|
+
|
|
10
|
+
## [0.3.1](https://github.com/launchdarkly/js-core/compare/js-client-sdk-v0.3.0...js-client-sdk-v0.3.1) (2024-11-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* Consolidate common exports between base package and compat package. ([#674](https://github.com/launchdarkly/js-core/issues/674)) ([f692050](https://github.com/launchdarkly/js-core/commit/f69205082d83318e2772d027d6ea533de3ce5eb1))
|
|
16
|
+
|
|
3
17
|
## [0.3.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-v0.2.0...js-client-sdk-v0.3.0) (2024-11-04)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# LaunchDarkly JavaScript SDK for Browsers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
[![NPM][browser-sdk-npm-badge]][browser-sdk-npm-link]
|
|
5
5
|
[![Actions Status][browser-sdk-ci-badge]][browser-sdk-ci]
|
|
6
6
|
[![Documentation][browser-sdk-ghp-badge]][browser-sdk-ghp-link]
|
|
7
7
|
[![NPM][browser-sdk-dm-badge]][browser-sdk-npm-link]
|
|
8
8
|
[![NPM][browser-sdk-dt-badge]][browser-sdk-npm-link]
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
|
|
11
11
|
# ⛔️⛔️⛔️⛔️
|
|
12
12
|
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { LDIdentifyOptions, LDOptions, LDClient as LDClient$1, LDContext, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
|
|
2
|
+
|
|
3
|
+
interface BrowserIdentifyOptions extends Omit<LDIdentifyOptions, 'waitForNetworkResults'> {
|
|
4
|
+
/**
|
|
5
|
+
* The signed context key if you are using [Secure Mode]
|
|
6
|
+
* (https://docs.launchdarkly.com/sdk/features/secure-mode#configuring-secure-mode-in-the-javascript-client-side-sdk).
|
|
7
|
+
*/
|
|
8
|
+
hash?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The initial set of flags to use until the remote set is retrieved.
|
|
11
|
+
*
|
|
12
|
+
* Bootstrap data can be generated by server SDKs. When bootstrap data is provided the SDK the
|
|
13
|
+
* identification operation will complete without waiting for any values from LaunchDarkly and
|
|
14
|
+
* the variation calls can be used immediately.
|
|
15
|
+
*
|
|
16
|
+
* If streaming is activated, either it is configured to always be used, or is activated
|
|
17
|
+
* via setStreaming, or via the addition of change handlers, then a streaming connection will
|
|
18
|
+
* subsequently be established.
|
|
19
|
+
*
|
|
20
|
+
* For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/features/bootstrapping#javascript).
|
|
21
|
+
*/
|
|
22
|
+
bootstrap?: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initialization options for the LaunchDarkly browser SDK.
|
|
27
|
+
*/
|
|
28
|
+
interface BrowserOptions extends Omit<LDOptions, 'initialConnectionMode'> {
|
|
29
|
+
/**
|
|
30
|
+
* Whether the client should make a request to LaunchDarkly for Experimentation metrics (goals).
|
|
31
|
+
*
|
|
32
|
+
* This is true by default, meaning that this request will be made on every page load.
|
|
33
|
+
* Set it to false if you are not using Experimentation and want to skip the request.
|
|
34
|
+
*/
|
|
35
|
+
fetchGoals?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* A function which, if present, can change the URL in analytics events to something other
|
|
38
|
+
* than the actual browser URL. It will be called with the current browser URL as a parameter,
|
|
39
|
+
* and returns the value that should be stored in the event's `url` property.
|
|
40
|
+
*
|
|
41
|
+
* It may be useful to customize the `url` to provide specific meaning, incorporate
|
|
42
|
+
* client-side routing concerns, or redact tokens or other info.
|
|
43
|
+
*/
|
|
44
|
+
eventUrlTransformer?: (url: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Whether or not to open a streaming connection to LaunchDarkly for live flag updates.
|
|
47
|
+
*
|
|
48
|
+
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
49
|
+
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
50
|
+
* connection if you subscribe to `"change"` or `"change:flag-key"` events.
|
|
51
|
+
*
|
|
52
|
+
* This is equivalent to calling `client.setStreaming()` with the same value.
|
|
53
|
+
*/
|
|
54
|
+
streaming?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Determines if the SDK responds to entering different visibility states, such as foreground and background.
|
|
57
|
+
* An example is flushing buffered events when going to the background.
|
|
58
|
+
*
|
|
59
|
+
* This is true by default. Generally speaking the SDK will be able to most reliably deliver
|
|
60
|
+
* events with this setting on.
|
|
61
|
+
*
|
|
62
|
+
* It may be useful to disable for environments where not all window/document objects are
|
|
63
|
+
* available, such as when running the SDK in a browser extension.
|
|
64
|
+
*/
|
|
65
|
+
automaticBackgroundHandling?: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* The LaunchDarkly SDK client object.
|
|
71
|
+
*
|
|
72
|
+
* Applications should configure the client at page load time and reuse the same instance.
|
|
73
|
+
*
|
|
74
|
+
* For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/javascript).
|
|
75
|
+
*/
|
|
76
|
+
type LDClient = Omit<LDClient$1, 'setConnectionMode' | 'getConnectionMode' | 'getOffline' | 'identify'> & {
|
|
77
|
+
/**
|
|
78
|
+
* @ignore
|
|
79
|
+
* Implementation Note: We are not supporting dynamically setting the connection mode on the LDClient.
|
|
80
|
+
* Implementation Note: The SDK does not support offline mode. Instead bootstrap data can be used.
|
|
81
|
+
* Implementation Note: The browser SDK has different identify options, so omits the base implementation
|
|
82
|
+
* from the interface.
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* Specifies whether or not to open a streaming connection to LaunchDarkly for live flag updates.
|
|
86
|
+
*
|
|
87
|
+
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
88
|
+
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
89
|
+
* connection if you subscribe to `"change"` or `"change:flag-key"` events (see {@link LDClient.on}).
|
|
90
|
+
*
|
|
91
|
+
* This can also be set as the `streaming` property of {@link LDOptions}.
|
|
92
|
+
*/
|
|
93
|
+
setStreaming(streaming?: boolean): void;
|
|
94
|
+
/**
|
|
95
|
+
* Identifies a context to LaunchDarkly.
|
|
96
|
+
*
|
|
97
|
+
* Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state,
|
|
98
|
+
* which is set when you call `identify()`.
|
|
99
|
+
*
|
|
100
|
+
* Changing the current context also causes all feature flag values to be reloaded. Until that has
|
|
101
|
+
* finished, calls to {@link variation} will still return flag values for the previous context. You can
|
|
102
|
+
* await the Promise to determine when the new flag values are available.
|
|
103
|
+
*
|
|
104
|
+
* @param context
|
|
105
|
+
* The LDContext object.
|
|
106
|
+
* @param identifyOptions
|
|
107
|
+
* Optional configuration. Please see {@link LDIdentifyOptions}.
|
|
108
|
+
* @returns
|
|
109
|
+
* A Promise which resolves when the flag values for the specified
|
|
110
|
+
* context are available. It rejects when:
|
|
111
|
+
*
|
|
112
|
+
* 1. The context is unspecified or has no key.
|
|
113
|
+
*
|
|
114
|
+
* 2. The identify timeout is exceeded. In client SDKs this defaults to 5s.
|
|
115
|
+
* You can customize this timeout with {@link LDIdentifyOptions | identifyOptions}.
|
|
116
|
+
*
|
|
117
|
+
* 3. A network error is encountered during initialization.
|
|
118
|
+
*
|
|
119
|
+
* @ignore Implementation Note: Browser implementation has different options.
|
|
120
|
+
*/
|
|
121
|
+
identify(context: LDContext, identifyOptions?: BrowserIdentifyOptions): Promise<void>;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Provides a basic {@link LDLogger} implementation.
|
|
126
|
+
*
|
|
127
|
+
* This logging implementation uses a basic format that includes only the log level
|
|
128
|
+
* and the message text. By default this uses log level 'info' and the output is
|
|
129
|
+
* written to `console.error`.
|
|
130
|
+
*
|
|
131
|
+
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
|
|
132
|
+
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
|
|
133
|
+
* that will log "info" level and higher priorty messages and it will log messages to
|
|
134
|
+
* console.info, console.warn, and console.error.
|
|
135
|
+
*
|
|
136
|
+
* @param options Configuration for the logger. If no options are specified, the
|
|
137
|
+
* logger uses `{ level: 'info' }`.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* This example shows how to use `basicLogger` in your SDK options to enable console
|
|
141
|
+
* logging only at `warn` and `error` levels.
|
|
142
|
+
* ```javascript
|
|
143
|
+
* const ldOptions = {
|
|
144
|
+
* logger: basicLogger({ level: 'warn' }),
|
|
145
|
+
* };
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* This example shows how to use `basicLogger` in your SDK options to cause all
|
|
150
|
+
* log output to go to `console.log`
|
|
151
|
+
* ```javascript
|
|
152
|
+
* const ldOptions = {
|
|
153
|
+
* logger: basicLogger({ destination: console.log }),
|
|
154
|
+
* };
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* * @example
|
|
158
|
+
* The configuration also allows you to control the destination for each log level.
|
|
159
|
+
* ```javascript
|
|
160
|
+
* const ldOptions = {
|
|
161
|
+
* logger: basicLogger({
|
|
162
|
+
* destination: {
|
|
163
|
+
* debug: console.debug,
|
|
164
|
+
* info: console.info,
|
|
165
|
+
* warn: console.warn,
|
|
166
|
+
* error:console.error
|
|
167
|
+
* }
|
|
168
|
+
* }),
|
|
169
|
+
* };
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function basicLogger(options: BasicLoggerOptions): LDLogger;
|
|
173
|
+
|
|
174
|
+
export { type BrowserOptions as B, type LDClient as L, type BrowserIdentifyOptions as a, basicLogger as b };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { LDIdentifyOptions, LDOptions, LDClient as LDClient$1, LDContext, BasicLoggerOptions, LDLogger } from '@launchdarkly/js-client-sdk-common';
|
|
2
|
+
|
|
3
|
+
interface BrowserIdentifyOptions extends Omit<LDIdentifyOptions, 'waitForNetworkResults'> {
|
|
4
|
+
/**
|
|
5
|
+
* The signed context key if you are using [Secure Mode]
|
|
6
|
+
* (https://docs.launchdarkly.com/sdk/features/secure-mode#configuring-secure-mode-in-the-javascript-client-side-sdk).
|
|
7
|
+
*/
|
|
8
|
+
hash?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The initial set of flags to use until the remote set is retrieved.
|
|
11
|
+
*
|
|
12
|
+
* Bootstrap data can be generated by server SDKs. When bootstrap data is provided the SDK the
|
|
13
|
+
* identification operation will complete without waiting for any values from LaunchDarkly and
|
|
14
|
+
* the variation calls can be used immediately.
|
|
15
|
+
*
|
|
16
|
+
* If streaming is activated, either it is configured to always be used, or is activated
|
|
17
|
+
* via setStreaming, or via the addition of change handlers, then a streaming connection will
|
|
18
|
+
* subsequently be established.
|
|
19
|
+
*
|
|
20
|
+
* For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/features/bootstrapping#javascript).
|
|
21
|
+
*/
|
|
22
|
+
bootstrap?: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initialization options for the LaunchDarkly browser SDK.
|
|
27
|
+
*/
|
|
28
|
+
interface BrowserOptions extends Omit<LDOptions, 'initialConnectionMode'> {
|
|
29
|
+
/**
|
|
30
|
+
* Whether the client should make a request to LaunchDarkly for Experimentation metrics (goals).
|
|
31
|
+
*
|
|
32
|
+
* This is true by default, meaning that this request will be made on every page load.
|
|
33
|
+
* Set it to false if you are not using Experimentation and want to skip the request.
|
|
34
|
+
*/
|
|
35
|
+
fetchGoals?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* A function which, if present, can change the URL in analytics events to something other
|
|
38
|
+
* than the actual browser URL. It will be called with the current browser URL as a parameter,
|
|
39
|
+
* and returns the value that should be stored in the event's `url` property.
|
|
40
|
+
*
|
|
41
|
+
* It may be useful to customize the `url` to provide specific meaning, incorporate
|
|
42
|
+
* client-side routing concerns, or redact tokens or other info.
|
|
43
|
+
*/
|
|
44
|
+
eventUrlTransformer?: (url: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Whether or not to open a streaming connection to LaunchDarkly for live flag updates.
|
|
47
|
+
*
|
|
48
|
+
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
49
|
+
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
50
|
+
* connection if you subscribe to `"change"` or `"change:flag-key"` events.
|
|
51
|
+
*
|
|
52
|
+
* This is equivalent to calling `client.setStreaming()` with the same value.
|
|
53
|
+
*/
|
|
54
|
+
streaming?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Determines if the SDK responds to entering different visibility states, such as foreground and background.
|
|
57
|
+
* An example is flushing buffered events when going to the background.
|
|
58
|
+
*
|
|
59
|
+
* This is true by default. Generally speaking the SDK will be able to most reliably deliver
|
|
60
|
+
* events with this setting on.
|
|
61
|
+
*
|
|
62
|
+
* It may be useful to disable for environments where not all window/document objects are
|
|
63
|
+
* available, such as when running the SDK in a browser extension.
|
|
64
|
+
*/
|
|
65
|
+
automaticBackgroundHandling?: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* The LaunchDarkly SDK client object.
|
|
71
|
+
*
|
|
72
|
+
* Applications should configure the client at page load time and reuse the same instance.
|
|
73
|
+
*
|
|
74
|
+
* For more information, see the [SDK Reference Guide](https://docs.launchdarkly.com/sdk/client-side/javascript).
|
|
75
|
+
*/
|
|
76
|
+
type LDClient = Omit<LDClient$1, 'setConnectionMode' | 'getConnectionMode' | 'getOffline' | 'identify'> & {
|
|
77
|
+
/**
|
|
78
|
+
* @ignore
|
|
79
|
+
* Implementation Note: We are not supporting dynamically setting the connection mode on the LDClient.
|
|
80
|
+
* Implementation Note: The SDK does not support offline mode. Instead bootstrap data can be used.
|
|
81
|
+
* Implementation Note: The browser SDK has different identify options, so omits the base implementation
|
|
82
|
+
* from the interface.
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* Specifies whether or not to open a streaming connection to LaunchDarkly for live flag updates.
|
|
86
|
+
*
|
|
87
|
+
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
88
|
+
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
89
|
+
* connection if you subscribe to `"change"` or `"change:flag-key"` events (see {@link LDClient.on}).
|
|
90
|
+
*
|
|
91
|
+
* This can also be set as the `streaming` property of {@link LDOptions}.
|
|
92
|
+
*/
|
|
93
|
+
setStreaming(streaming?: boolean): void;
|
|
94
|
+
/**
|
|
95
|
+
* Identifies a context to LaunchDarkly.
|
|
96
|
+
*
|
|
97
|
+
* Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state,
|
|
98
|
+
* which is set when you call `identify()`.
|
|
99
|
+
*
|
|
100
|
+
* Changing the current context also causes all feature flag values to be reloaded. Until that has
|
|
101
|
+
* finished, calls to {@link variation} will still return flag values for the previous context. You can
|
|
102
|
+
* await the Promise to determine when the new flag values are available.
|
|
103
|
+
*
|
|
104
|
+
* @param context
|
|
105
|
+
* The LDContext object.
|
|
106
|
+
* @param identifyOptions
|
|
107
|
+
* Optional configuration. Please see {@link LDIdentifyOptions}.
|
|
108
|
+
* @returns
|
|
109
|
+
* A Promise which resolves when the flag values for the specified
|
|
110
|
+
* context are available. It rejects when:
|
|
111
|
+
*
|
|
112
|
+
* 1. The context is unspecified or has no key.
|
|
113
|
+
*
|
|
114
|
+
* 2. The identify timeout is exceeded. In client SDKs this defaults to 5s.
|
|
115
|
+
* You can customize this timeout with {@link LDIdentifyOptions | identifyOptions}.
|
|
116
|
+
*
|
|
117
|
+
* 3. A network error is encountered during initialization.
|
|
118
|
+
*
|
|
119
|
+
* @ignore Implementation Note: Browser implementation has different options.
|
|
120
|
+
*/
|
|
121
|
+
identify(context: LDContext, identifyOptions?: BrowserIdentifyOptions): Promise<void>;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Provides a basic {@link LDLogger} implementation.
|
|
126
|
+
*
|
|
127
|
+
* This logging implementation uses a basic format that includes only the log level
|
|
128
|
+
* and the message text. By default this uses log level 'info' and the output is
|
|
129
|
+
* written to `console.error`.
|
|
130
|
+
*
|
|
131
|
+
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
|
|
132
|
+
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
|
|
133
|
+
* that will log "info" level and higher priorty messages and it will log messages to
|
|
134
|
+
* console.info, console.warn, and console.error.
|
|
135
|
+
*
|
|
136
|
+
* @param options Configuration for the logger. If no options are specified, the
|
|
137
|
+
* logger uses `{ level: 'info' }`.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* This example shows how to use `basicLogger` in your SDK options to enable console
|
|
141
|
+
* logging only at `warn` and `error` levels.
|
|
142
|
+
* ```javascript
|
|
143
|
+
* const ldOptions = {
|
|
144
|
+
* logger: basicLogger({ level: 'warn' }),
|
|
145
|
+
* };
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* This example shows how to use `basicLogger` in your SDK options to cause all
|
|
150
|
+
* log output to go to `console.log`
|
|
151
|
+
* ```javascript
|
|
152
|
+
* const ldOptions = {
|
|
153
|
+
* logger: basicLogger({ destination: console.log }),
|
|
154
|
+
* };
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* * @example
|
|
158
|
+
* The configuration also allows you to control the destination for each log level.
|
|
159
|
+
* ```javascript
|
|
160
|
+
* const ldOptions = {
|
|
161
|
+
* logger: basicLogger({
|
|
162
|
+
* destination: {
|
|
163
|
+
* debug: console.debug,
|
|
164
|
+
* info: console.info,
|
|
165
|
+
* warn: console.warn,
|
|
166
|
+
* error:console.error
|
|
167
|
+
* }
|
|
168
|
+
* }),
|
|
169
|
+
* };
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function basicLogger(options: BasicLoggerOptions): LDLogger;
|
|
173
|
+
|
|
174
|
+
export { type BrowserOptions as B, type LDClient as L, type BrowserIdentifyOptions as a, basicLogger as b };
|