@launchdarkly/js-client-sdk-common 0.1.0-alpha

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.
Files changed (75) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +1 -0
  3. package/dist/LDClientImpl.d.ts +65 -0
  4. package/dist/LDClientImpl.d.ts.map +1 -0
  5. package/dist/LDClientImpl.js +304 -0
  6. package/dist/LDClientImpl.js.map +1 -0
  7. package/dist/api/LDClient.d.ts +285 -0
  8. package/dist/api/LDClient.d.ts.map +1 -0
  9. package/dist/api/LDClient.js +3 -0
  10. package/dist/api/LDClient.js.map +1 -0
  11. package/dist/api/LDEmitter.d.ts +37 -0
  12. package/dist/api/LDEmitter.d.ts.map +1 -0
  13. package/dist/api/LDEmitter.js +88 -0
  14. package/dist/api/LDEmitter.js.map +1 -0
  15. package/dist/api/LDInspection.d.ts +88 -0
  16. package/dist/api/LDInspection.d.ts.map +1 -0
  17. package/dist/api/LDInspection.js +3 -0
  18. package/dist/api/LDInspection.js.map +1 -0
  19. package/dist/api/LDOptions.d.ts +172 -0
  20. package/dist/api/LDOptions.d.ts.map +1 -0
  21. package/dist/api/LDOptions.js +3 -0
  22. package/dist/api/LDOptions.js.map +1 -0
  23. package/dist/api/index.d.ts +3 -0
  24. package/dist/api/index.d.ts.map +1 -0
  25. package/dist/api/index.js +19 -0
  26. package/dist/api/index.js.map +1 -0
  27. package/dist/configuration/Configuration.d.ts +39 -0
  28. package/dist/configuration/Configuration.d.ts.map +1 -0
  29. package/dist/configuration/Configuration.js +69 -0
  30. package/dist/configuration/Configuration.js.map +1 -0
  31. package/dist/configuration/index.d.ts +3 -0
  32. package/dist/configuration/index.d.ts.map +1 -0
  33. package/dist/configuration/index.js +5 -0
  34. package/dist/configuration/index.js.map +1 -0
  35. package/dist/configuration/validators.d.ts +5 -0
  36. package/dist/configuration/validators.d.ts.map +1 -0
  37. package/dist/configuration/validators.js +38 -0
  38. package/dist/configuration/validators.js.map +1 -0
  39. package/dist/diagnostics/createDiagnosticsInitConfig.d.ts +16 -0
  40. package/dist/diagnostics/createDiagnosticsInitConfig.d.ts.map +1 -0
  41. package/dist/diagnostics/createDiagnosticsInitConfig.js +18 -0
  42. package/dist/diagnostics/createDiagnosticsInitConfig.js.map +1 -0
  43. package/dist/diagnostics/createDiagnosticsManager.d.ts +5 -0
  44. package/dist/diagnostics/createDiagnosticsManager.d.ts.map +1 -0
  45. package/dist/diagnostics/createDiagnosticsManager.js +12 -0
  46. package/dist/diagnostics/createDiagnosticsManager.js.map +1 -0
  47. package/dist/evaluation/fetchFlags.d.ts +6 -0
  48. package/dist/evaluation/fetchFlags.d.ts.map +1 -0
  49. package/dist/evaluation/fetchFlags.js +12 -0
  50. package/dist/evaluation/fetchFlags.js.map +1 -0
  51. package/dist/evaluation/fetchUtils.d.ts +7 -0
  52. package/dist/evaluation/fetchUtils.d.ts.map +1 -0
  53. package/dist/evaluation/fetchUtils.js +46 -0
  54. package/dist/evaluation/fetchUtils.js.map +1 -0
  55. package/dist/events/EventFactory.d.ts +2 -0
  56. package/dist/events/EventFactory.d.ts.map +1 -0
  57. package/dist/events/EventFactory.js +25 -0
  58. package/dist/events/EventFactory.js.map +1 -0
  59. package/dist/events/createEventProcessor.d.ts +5 -0
  60. package/dist/events/createEventProcessor.d.ts.map +1 -0
  61. package/dist/events/createEventProcessor.js +8 -0
  62. package/dist/events/createEventProcessor.js.map +1 -0
  63. package/dist/index.d.ts +6 -0
  64. package/dist/index.d.ts.map +1 -0
  65. package/dist/index.js +23 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/types/index.d.ts +20 -0
  68. package/dist/types/index.d.ts.map +1 -0
  69. package/dist/types/index.js +3 -0
  70. package/dist/types/index.js.map +1 -0
  71. package/dist/utils/index.d.ts +3 -0
  72. package/dist/utils/index.d.ts.map +1 -0
  73. package/dist/utils/index.js +24 -0
  74. package/dist/utils/index.js.map +1 -0
  75. package/package.json +58 -0
@@ -0,0 +1,285 @@
1
+ import { LDContext, LDEvaluationDetail, LDEvaluationDetailTyped, LDFlagSet, LDFlagValue, LDLogger } from '@launchdarkly/js-sdk-common';
2
+ /**
3
+ * The basic interface for the LaunchDarkly client. Platform-specific SDKs may add some methods of their own.
4
+ *
5
+ * @see https://docs.launchdarkly.com/sdk/client-side/javascript
6
+ *
7
+ * @ignore (don't need to show this separately in TypeDoc output; all methods will be shown in LDClient)
8
+ */
9
+ export interface LDClient {
10
+ /**
11
+ * Returns a map of all available flags to the current context's values.
12
+ *
13
+ * @returns
14
+ * An object in which each key is a feature flag key and each value is the flag value.
15
+ * Note that there is no way to specify a default value for each flag as there is with
16
+ * {@link variation}, so any flag that cannot be evaluated will be undefined.
17
+ */
18
+ allFlags(): LDFlagSet;
19
+ /**
20
+ * Determines the boolean variation of a feature flag.
21
+ *
22
+ * If the flag variation does not have a boolean value, defaultValue is returned.
23
+ *
24
+ * @param key The unique key of the feature flag.
25
+ * @param defaultValue The default value of the flag, to be used if the value is not available
26
+ * from LaunchDarkly.
27
+ * @returns
28
+ * The boolean value.
29
+ */
30
+ boolVariation(key: string, defaultValue: boolean): boolean;
31
+ /**
32
+ * Determines the boolean variation of a feature flag, along with information about
33
+ * how it was calculated.
34
+ *
35
+ * The `reason` property of the result will also be included in analytics events, if you are
36
+ * capturing detailed event data for this flag.
37
+ *
38
+ * If the flag variation does not have a boolean value, defaultValue is returned. The reason will
39
+ * indicate an error of the type `WRONG_KIND` in this case.
40
+ *
41
+ * For more information, see the [SDK reference
42
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
43
+ *
44
+ * @param key The unique key of the feature flag.
45
+ * @param defaultValue The default value of the flag, to be used if the value is not available
46
+ * from LaunchDarkly.
47
+ * @returns
48
+ * The result (as an {@link LDEvaluationDetailTyped<boolean>}).
49
+ */
50
+ boolVariationDetail(key: string, defaultValue: boolean): LDEvaluationDetailTyped<boolean>;
51
+ /**
52
+ * Shuts down the client and releases its resources, after delivering any pending analytics
53
+ * events. After the client is closed, all calls to {@link variation} will return default values,
54
+ * and it will not make any requests to LaunchDarkly.
55
+ */
56
+ close(): void;
57
+ /**
58
+ * Flushes all pending analytics events.
59
+ *
60
+ * Normally, batches of events are delivered in the background at intervals determined by the
61
+ * `flushInterval` property of {@link LDOptions}. Calling `flush()` triggers an immediate delivery.
62
+ *
63
+ * @returns
64
+ * A Promise which resolves once
65
+ * flushing is finished. You can inspect the result of the flush for errors.
66
+ */
67
+ flush(): Promise<{
68
+ error?: Error;
69
+ result: boolean;
70
+ }>;
71
+ /**
72
+ * Returns the client's current context.
73
+ *
74
+ * This is the context that was most recently passed to {@link identify}, or, if {@link identify} has never
75
+ * been called, this will be undefined.
76
+ */
77
+ getContext(): LDContext | undefined;
78
+ /**
79
+ * Identifies a context to LaunchDarkly.
80
+ *
81
+ * Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state,
82
+ * which is set when you call `identify()`.
83
+ *
84
+ * Changing the current context also causes all feature flag values to be reloaded. Until that has
85
+ * finished, calls to {@link variation} will still return flag values for the previous context. You can
86
+ * await the Promise to determine when the new flag values are available.
87
+ *
88
+ * @param context
89
+ * The LDContext object.
90
+ * @param hash
91
+ * The signed context key if you are using [Secure Mode](https://docs.launchdarkly.com/sdk/features/secure-mode#configuring-secure-mode-in-the-javascript-client-side-sdk).
92
+ * @returns
93
+ * A Promise which resolves when the flag values for the specified context are available.
94
+ */
95
+ identify(context: LDContext, hash?: string): Promise<void>;
96
+ /**
97
+ * Determines the json variation of a feature flag.
98
+ *
99
+ * This version may be favored in TypeScript versus `variation` because it returns
100
+ * an `unknown` type instead of `any`. `unknown` will require a cast before usage.
101
+ *
102
+ * @param key The unique key of the feature flag.
103
+ * @param defaultValue The default value of the flag, to be used if the value is not available
104
+ * from LaunchDarkly.
105
+ * @returns
106
+ * The json value.
107
+ */
108
+ jsonVariation(key: string, defaultValue: unknown): unknown;
109
+ /**
110
+ * Determines the json variation of a feature flag, along with information about how it
111
+ * was calculated.
112
+ *
113
+ * The `reason` property of the result will also be included in analytics events, if you are
114
+ * capturing detailed event data for this flag.
115
+ *
116
+ * This version may be favored in TypeScript versus `variation` because it returns
117
+ * an `unknown` type instead of `any`. `unknown` will require a cast before usage.
118
+ *
119
+ * For more information, see the [SDK reference
120
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
121
+ *
122
+ * @param key The unique key of the feature flag.
123
+ * @param defaultValue The default value of the flag, to be used if the value is not available
124
+ * from LaunchDarkly.
125
+ * @returns
126
+ * The result (as an {@link LDEvaluationDetailTyped<unknown>}).
127
+ */
128
+ jsonVariationDetail(key: string, defaultValue: unknown): LDEvaluationDetailTyped<unknown>;
129
+ /**
130
+ * Returns the logger configured as part of LDOptions during construction.
131
+ *
132
+ * For more, read {@link LDOptions.logger}.
133
+ */
134
+ logger: LDLogger;
135
+ /**
136
+ * Determines the numeric variation of a feature flag.
137
+ *
138
+ * If the flag variation does not have a numeric value, defaultValue is returned.
139
+ *
140
+ * @param key The unique key of the feature flag.
141
+ * @param defaultValue The default value of the flag, to be used if the value is not available
142
+ * from LaunchDarkly.
143
+ * @returns
144
+ * The numeric value.
145
+ */
146
+ numberVariation(key: string, defaultValue: number): number;
147
+ /**
148
+ * Determines the numeric variation of a feature flag for a context, along with information about
149
+ * how it was calculated.
150
+ *
151
+ * The `reason` property of the result will also be included in analytics events, if you are
152
+ * capturing detailed event data for this flag.
153
+ *
154
+ * If the flag variation does not have a numeric value, defaultValue is returned. The reason will
155
+ * indicate an error of the type `WRONG_KIND` in this case.
156
+ *
157
+ * For more information, see the [SDK reference
158
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
159
+ *
160
+ * @param key The unique key of the feature flag.
161
+ * @param defaultValue The default value of the flag, to be used if the value is not available
162
+ * from LaunchDarkly.
163
+ * @returns
164
+ * The result (as an {@link LDEvaluationDetailTyped<number>}).
165
+ */
166
+ numberVariationDetail(key: string, defaultValue: number): LDEvaluationDetailTyped<number>;
167
+ /**
168
+ * Removes an event listener. See {@link on} for the available event types.
169
+ *
170
+ * @param key
171
+ * The name of the event for which to stop listening.
172
+ * @param callback
173
+ * The function to deregister.
174
+ */
175
+ off(key: string, callback: (...args: any[]) => void): void;
176
+ /**
177
+ * Registers an event listener.
178
+ *
179
+ * The following event names (keys) are used by the client:
180
+ *
181
+ * - `"identifying"`: The client starts to fetch feature flags.
182
+ * - `"error"`: General event for any kind of error condition during client operation.
183
+ * The callback parameter is an Error object. If you do not listen for "error"
184
+ * events, then the errors will be logged with `console.log()`.
185
+ * - `"change"`: The client has received new feature flag data. This can happen either
186
+ * because you have switched contexts with {@link identify}, or because the client has a
187
+ * stream connection and has received a live change to a flag value (see below).
188
+ * The callback parameters are the context and an array of flag keys that have changed.
189
+ *
190
+ * @param key
191
+ * The name of the event for which to listen.
192
+ * @param callback
193
+ * The function to execute when the event fires. The callback may or may not
194
+ * receive parameters, depending on the type of event.
195
+ */
196
+ on(key: string, callback: (...args: any[]) => void): void;
197
+ /**
198
+ * Determines the string variation of a feature flag.
199
+ *
200
+ * If the flag variation does not have a string value, defaultValue is returned.
201
+ *
202
+ * @param key The unique key of the feature flag.
203
+ * @param defaultValue The default value of the flag, to be used if the value is not available
204
+ * from LaunchDarkly.
205
+ * @returns
206
+ * The string value.
207
+ */
208
+ stringVariation(key: string, defaultValue: string): string;
209
+ /**
210
+ * Determines the string variation of a feature flag for a context, along with information about
211
+ * how it was calculated.
212
+ *
213
+ * The `reason` property of the result will also be included in analytics events, if you are
214
+ * capturing detailed event data for this flag.
215
+ *
216
+ * If the flag variation does not have a string value, defaultValue is returned. The reason will
217
+ * indicate an error of the type `WRONG_KIND` in this case.
218
+ *
219
+ * For more information, see the [SDK reference
220
+ * guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native).
221
+ *
222
+ * @param key The unique key of the feature flag.
223
+ * @param defaultValue The default value of the flag, to be used if the value is not available
224
+ * from LaunchDarkly.
225
+ * @returns
226
+ * The result (as an {@link LDEvaluationDetailTyped<string>}).
227
+ */
228
+ stringVariationDetail(key: string, defaultValue: string): LDEvaluationDetailTyped<string>;
229
+ /**
230
+ * Track events for experiments.
231
+ *
232
+ * @param key
233
+ * The name of the event, which may correspond to a goal in an experiment.
234
+ * @param data
235
+ * Additional information to associate with the event.
236
+ * @param metricValue
237
+ * An optional numeric value that can be used by the LaunchDarkly experimentation
238
+ * feature in numeric custom metrics. Can be omitted if this event is used by only
239
+ * non-numeric metrics. This field will also be returned as part of the custom event
240
+ * for Data Export.
241
+ */
242
+ track(key: string, data?: any, metricValue?: number): void;
243
+ /**
244
+ * We recommend using strongly typed variation methods which perform
245
+ * type checks and handle type errors.
246
+ *
247
+ * Determines the variation of a feature flag.
248
+ *
249
+ * In the client-side JavaScript SDKs, this is always a fast synchronous operation because all of
250
+ * the feature flag values for the current context have already been loaded into memory.
251
+ *
252
+ * @param key
253
+ * The unique key of the feature flag.
254
+ * @param defaultValue
255
+ * The default value of the flag, to be used if the value is not available from LaunchDarkly.
256
+ * @returns
257
+ * The flag's value.
258
+ */
259
+ variation(key: string, defaultValue?: LDFlagValue): LDFlagValue;
260
+ /**
261
+ * We recommend using strongly typed variation detail methods which perform
262
+ * type checks and handle type errors.
263
+ *
264
+ * Determines the variation of a feature flag for a context, along with information about how it was
265
+ * calculated.
266
+ *
267
+ * Note that this will only work if you have set `evaluationExplanations` to true in {@link LDOptions}.
268
+ * Otherwise, the `reason` property of the result will be null.
269
+ *
270
+ * The `reason` property of the result will also be included in analytics events, if you are
271
+ * capturing detailed event data for this flag.
272
+ *
273
+ * For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#javascript).
274
+ *
275
+ * @param key
276
+ * The unique key of the feature flag.
277
+ * @param defaultValue
278
+ * The default value of the flag, to be used if the value is not available from LaunchDarkly.
279
+ *
280
+ * @returns
281
+ * An {@link LDEvaluationDetail} object containing the value and explanation.
282
+ */
283
+ variationDetail(key: string, defaultValue?: LDFlagValue): LDEvaluationDet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ingURL=LDClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDClient.js","sourceRoot":"","sources":["../../src/api/LDClient.ts"],"names":[],"mappings":""}
@@ -0,0 +1,37 @@
1
+ export type EventName = 'identifying' | 'error' | 'change';
2
+ /**
3
+ * Native api usage: EventTarget.
4
+ *
5
+ * This is an event emitter using the standard built-in EventTarget web api.
6
+ * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
7
+ *
8
+ * In react-native use event-target-shim to polyfill EventTarget. This is safe
9
+ * because the react-native repo uses it too.
10
+ * https://github.com/mysticatea/event-target-shim
11
+ */
12
+ export default class LDEmitter {
13
+ private et;
14
+ private listeners;
15
+ /**
16
+ * Cache all listeners in a Map so we can remove them later
17
+ * @param name string event name
18
+ * @param originalListener pointer to the original function as specified by
19
+ * the consumer
20
+ * @param customListener pointer to the custom function based on original
21
+ * listener. This is needed to allow for CustomEvents.
22
+ * @private
23
+ */
24
+ private saveListener;
25
+ on(name: EventName, listener: Function): void;
26
+ /**
27
+ * Unsubscribe one or all events.
28
+ *
29
+ * @param name
30
+ * @param listener Optional. If unspecified, all listeners for the event will be removed.
31
+ */
32
+ off(name: EventName, listener?: Function): void;
33
+ emit(name: EventName, ...detail: any[]): void;
34
+ eventNames(): string[];
35
+ listenerCount(name: EventName): number;
36
+ }
37
+ //# sourceMappingURL=LDEmitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDEmitter.d.ts","sourceRoot":"","sources":["../../src/api/LDEmitter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,QAAQ,CAAC;AAM3D;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,EAAE,CAAkC;IAE5C,OAAO,CAAC,SAAS,CAAqD;IAEtE;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;IASpB,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ;IAWtC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ;IA2BxC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;IAItC,UAAU,IAAI,MAAM,EAAE;IAItB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM;CAGvC"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Native api usage: EventTarget.
5
+ *
6
+ * This is an event emitter using the standard built-in EventTarget web api.
7
+ * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
8
+ *
9
+ * In react-native use event-target-shim to polyfill EventTarget. This is safe
10
+ * because the react-native repo uses it too.
11
+ * https://github.com/mysticatea/event-target-shim
12
+ */
13
+ class LDEmitter {
14
+ constructor() {
15
+ this.et = new EventTarget();
16
+ this.listeners = new Map();
17
+ }
18
+ /**
19
+ * Cache all listeners in a Map so we can remove them later
20
+ * @param name string event name
21
+ * @param originalListener pointer to the original function as specified by
22
+ * the consumer
23
+ * @param customListener pointer to the custom function based on original
24
+ * listener. This is needed to allow for CustomEvents.
25
+ * @private
26
+ */
27
+ saveListener(name, originalListener, customListener) {
28
+ var _a;
29
+ const listener = { original: originalListener, custom: customListener };
30
+ if (!this.listeners.has(name)) {
31
+ this.listeners.set(name, [listener]);
32
+ }
33
+ else {
34
+ (_a = this.listeners.get(name)) === null || _a === void 0 ? void 0 : _a.push(listener);
35
+ }
36
+ }
37
+ on(name, listener) {
38
+ const customListener = (e) => {
39
+ const { detail } = e;
40
+ // invoke listener with args from CustomEvent
41
+ listener(...detail);
42
+ };
43
+ this.saveListener(name, listener, customListener);
44
+ this.et.addEventListener(name, customListener);
45
+ }
46
+ /**
47
+ * Unsubscribe one or all events.
48
+ *
49
+ * @param name
50
+ * @param listener Optional. If unspecified, all listeners for the event will be removed.
51
+ */
52
+ off(name, listener) {
53
+ const existingListeners = this.listeners.get(name);
54
+ if (!existingListeners) {
55
+ return;
56
+ }
57
+ if (listener) {
58
+ const toBeRemoved = existingListeners.find((c) => c.original === listener);
59
+ this.et.removeEventListener(name, toBeRemoved === null || toBeRemoved === void 0 ? void 0 : toBeRemoved.custom);
60
+ // remove from internal cache
61
+ const updated = existingListeners.filter((l) => l.original !== listener);
62
+ if (updated.length === 0) {
63
+ this.listeners.delete(name);
64
+ }
65
+ else {
66
+ this.listeners.set(name, updated);
67
+ }
68
+ return;
69
+ }
70
+ // remove all listeners
71
+ existingListeners.forEach((l) => {
72
+ this.et.removeEventListener(name, l.custom);
73
+ });
74
+ this.listeners.delete(name);
75
+ }
76
+ emit(name, ...detail) {
77
+ this.et.dispatchEvent(new CustomEvent(name, { detail }));
78
+ }
79
+ eventNames() {
80
+ return [...this.listeners.keys()];
81
+ }
82
+ listenerCount(name) {
83
+ var _a, _b;
84
+ return (_b = (_a = this.listeners.get(name)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
85
+ }
86
+ }
87
+ exports.default = LDEmitter;
88
+ //# sourceMappingURL=LDEmitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDEmitter.js","sourceRoot":"","sources":["../../src/api/LDEmitter.ts"],"names":[],"mappings":";;AAMA;;;;;;;;;GASG;AACH,MAAqB,SAAS;IAA9B;QACU,OAAE,GAAgB,IAAI,WAAW,EAAE,CAAC;QAEpC,cAAS,GAA2C,IAAI,GAAG,EAAE,CAAC;IA2ExE,CAAC;IAzEC;;;;;;;;OAQG;IACK,YAAY,CAAC,IAAe,EAAE,gBAA0B,EAAE,cAAwB;;QACxF,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;QACxE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,SAAS,CAAC,GAAG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,CAAC,CAAC;aAC7B;iBAAM;gBACL,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;aACnC;YACD,OAAO;SACR;QAED,uBAAuB;QACvB,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9B,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,MAAa,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,CAAC,IAAe,EAAE,GAAG,MAAa;QACpC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,aAAa,CAAC,IAAe;;QAC3B,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,0CAAE,MAAM,mCAAI,CAAC,CAAC;IAC/C,CAAC;CACF;AA9ED,4BA8EC"}
@@ -0,0 +1,88 @@
1
+ import { LDContext, LDEvaluationDetail } from '@launchdarkly/js-sdk-common';
2
+ /**
3
+ * Callback interface for collecting information about the SDK at runtime.
4
+ *
5
+ * This interface is used to collect information about flag usage.
6
+ *
7
+ * This interface should not be used by the application to access flags for the purpose of controlling application
8
+ * flow. It is intended for monitoring, analytics, or debugging purposes.
9
+ */
10
+ export interface LDInspectionFlagUsedHandler {
11
+ type: 'flag-used';
12
+ /**
13
+ * Name of the inspector. Will be used for logging issues with the inspector.
14
+ */
15
+ name: string;
16
+ /**
17
+ * This method is called when a flag is accessed via a variation method, or it can be called based on actions in
18
+ * wrapper SDKs which have different methods of tracking when a flag was accessed. It is not called when a call is made
19
+ * to allFlags.
20
+ */
21
+ method: (flagKey: string, flagDetail: LDEvaluationDetail, context: LDContext) => void;
22
+ }
23
+ /**
24
+ * Callback interface for collecting information about the SDK at runtime.
25
+ *
26
+ * This interface is used to collect information about flag data. In order to understand the
27
+ * current flag state it should be combined with {@link LDInspectionFlagValueChangedHandler}.
28
+ * This interface will get the initial flag information, and
29
+ * {@link LDInspectionFlagValueChangedHandler} will provide changes to individual flags.
30
+ *
31
+ * This interface should not be used by the application to access flags for the purpose of controlling application
32
+ * flow. It is intended for monitoring, analytics, or debugging purposes.
33
+ */
34
+ export interface LDInspectionFlagDetailsChangedHandler {
35
+ type: 'flag-details-changed';
36
+ /**
37
+ * Name of the inspector. Will be used for logging issues with the inspector.
38
+ */
39
+ name: string;
40
+ /**
41
+ * This method is called when the flags in the store are replaced with new flags. It will contain all flags
42
+ * regardless of if they have been evaluated.
43
+ */
44
+ method: (details: Record<string, LDEvaluationDetail>) => void;
45
+ }
46
+ /**
47
+ * Callback interface for collecting information about the SDK at runtime.
48
+ *
49
+ * This interface is used to collect changes to flag data, but does not provide the initial
50
+ * data. It can be combined with {@link LDInspectionFlagValuesChangedHandler} to track the
51
+ * entire flag state.
52
+ *
53
+ * This interface should not be used by the application to access flags for the purpose of controlling application
54
+ * flow. It is intended for monitoring, analytics, or debugging purposes.
55
+ */
56
+ export interface LDInspectionFlagDetailChangedHandler {
57
+ type: 'flag-detail-changed';
58
+ /**
59
+ * Name of the inspector. Will be used for logging issues with the inspector.
60
+ */
61
+ name: string;
62
+ /**
63
+ * This method is called when a flag is updated. It will not be called
64
+ * when all flags are updated.
65
+ */
66
+ method: (flagKey: string, detail: LDEvaluationDetail) => void;
67
+ }
68
+ /**
69
+ * Callback interface for collecting information about the SDK at runtime.
70
+ *
71
+ * This interface is used to track current identity state of the SDK.
72
+ *
73
+ * This interface should not be used by the application to access flags for the purpose of controlling application
74
+ * flow. It is intended for monitoring, analytics, or debugging purposes.
75
+ */
76
+ export interface LDInspectionIdentifyHandler {
77
+ type: 'client-identity-changed';
78
+ /**
79
+ * Name of the inspector. Will be used for logging issues with the inspector.
80
+ */
81
+ name: string;
82
+ /**
83
+ * This method will be called when an identify operation completes.
84
+ */
85
+ method: (context: LDContext) => void;
86
+ }
87
+ export type LDInspection = LDInspectionFlagUsedHandler | LDInspectionFlagDetailsChangedHandler | LDInspectionFlagDetailChangedHandler | LDInspectionIdentifyHandler;
88
+ //# sourceMappingURL=LDInspection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDInspection.d.ts","sourceRoot":"","sources":["../../src/api/LDInspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAE5E;;;;;;;GAOG;AAEH,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,WAAW,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC;CACvF;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,qCAAqC;IACpD,IAAI,EAAE,sBAAsB,CAAC;IAE7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,IAAI,CAAC;CAC/D;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,oCAAoC;IACnD,IAAI,EAAE,qBAAqB,CAAC;IAE5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAC/D;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,yBAAyB,CAAC;IAEhC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,IAAI,CAAC;CACtC;AAED,MAAM,MAAM,YAAY,GACpB,2BAA2B,GAC3B,qCAAqC,GACrC,oCAAoC,GACpC,2BAA2B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=LDInspection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDInspection.js","sourceRoot":"","sources":["../../src/api/LDInspection.ts"],"names":[],"mappings":""}