@launchdarkly/js-client-sdk-common 1.14.1 → 1.15.0

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 (38) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/LDClientImpl.d.ts +11 -2
  3. package/dist/cjs/LDClientImpl.d.ts.map +1 -1
  4. package/dist/cjs/api/LDClient.d.ts +37 -0
  5. package/dist/cjs/api/LDClient.d.ts.map +1 -1
  6. package/dist/cjs/api/LDIdentifyOptions.d.ts +10 -0
  7. package/dist/cjs/api/LDIdentifyOptions.d.ts.map +1 -1
  8. package/dist/cjs/api/LDIdentifyResult.d.ts +28 -0
  9. package/dist/cjs/api/LDIdentifyResult.d.ts.map +1 -0
  10. package/dist/cjs/api/index.d.ts +1 -0
  11. package/dist/cjs/api/index.d.ts.map +1 -1
  12. package/dist/cjs/api/integrations/Hooks.d.ts +10 -1
  13. package/dist/cjs/api/integrations/Hooks.d.ts.map +1 -1
  14. package/dist/cjs/async/AsyncTaskQueue.d.ts +28 -9
  15. package/dist/cjs/async/AsyncTaskQueue.d.ts.map +1 -1
  16. package/dist/cjs/index.cjs +228 -37
  17. package/dist/cjs/index.cjs.map +1 -1
  18. package/dist/cjs/index.d.ts +1 -1
  19. package/dist/cjs/index.d.ts.map +1 -1
  20. package/dist/esm/LDClientImpl.d.ts +11 -2
  21. package/dist/esm/LDClientImpl.d.ts.map +1 -1
  22. package/dist/esm/api/LDClient.d.ts +37 -0
  23. package/dist/esm/api/LDClient.d.ts.map +1 -1
  24. package/dist/esm/api/LDIdentifyOptions.d.ts +10 -0
  25. package/dist/esm/api/LDIdentifyOptions.d.ts.map +1 -1
  26. package/dist/esm/api/LDIdentifyResult.d.ts +28 -0
  27. package/dist/esm/api/LDIdentifyResult.d.ts.map +1 -0
  28. package/dist/esm/api/index.d.ts +1 -0
  29. package/dist/esm/api/index.d.ts.map +1 -1
  30. package/dist/esm/api/integrations/Hooks.d.ts +10 -1
  31. package/dist/esm/api/integrations/Hooks.d.ts.map +1 -1
  32. package/dist/esm/async/AsyncTaskQueue.d.ts +28 -9
  33. package/dist/esm/async/AsyncTaskQueue.d.ts.map +1 -1
  34. package/dist/esm/index.d.ts +1 -1
  35. package/dist/esm/index.d.ts.map +1 -1
  36. package/dist/esm/index.mjs +229 -38
  37. package/dist/esm/index.mjs.map +1 -1
  38. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.15.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-common-v1.14.1...js-client-sdk-common-v1.15.0) (2025-06-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add support for an identify queue. ([#842](https://github.com/launchdarkly/js-core/issues/842)) ([78e9a5e](https://github.com/launchdarkly/js-core/commit/78e9a5e93cb4c06a19c0d7d63307dfd3407d4505))
9
+
3
10
  ## [1.14.1](https://github.com/launchdarkly/js-core/compare/js-client-sdk-common-v1.14.0...js-client-sdk-common-v1.14.1) (2025-06-03)
4
11
 
5
12
 
@@ -1,11 +1,11 @@
1
1
  import { AutoEnvAttributes, Context, internal, LDContext, LDFlagSet, LDFlagValue, LDLogger, LDPluginEnvironmentMetadata, Platform } from '@launchdarkly/js-sdk-common';
2
- import { Hook, LDClient, type LDOptions } from './api';
2
+ import { Hook, LDClient, LDClientIdentifyResult, LDIdentifyResult, type LDOptions } from './api';
3
3
  import { LDEvaluationDetail, LDEvaluationDetailTyped } from './api/LDEvaluationDetail';
4
4
  import { LDIdentifyOptions } from './api/LDIdentifyOptions';
5
5
  import { LDClientInternalOptions } from './configuration';
6
6
  import { DataManager, DataManagerFactory } from './DataManager';
7
7
  import LDEmitter, { EventName } from './LDEmitter';
8
- export default class LDClientImpl implements LDClient {
8
+ export default class LDClientImpl implements LDClient, LDClientIdentifyResult {
9
9
  readonly sdkKey: string;
10
10
  readonly autoEnvAttributes: AutoEnvAttributes;
11
11
  readonly platform: Platform;
@@ -26,6 +26,7 @@ export default class LDClientImpl implements LDClient {
26
26
  protected readonly environmentMetadata: LDPluginEnvironmentMetadata;
27
27
  private _hookRunner;
28
28
  private _inspectorManager;
29
+ private _identifyQueue;
29
30
  /**
30
31
  * Creates the client object synchronously. No async, no network calls.
31
32
  */
@@ -42,6 +43,13 @@ export default class LDClientImpl implements LDClient {
42
43
  /**
43
44
  * Identifies a context to LaunchDarkly. See {@link LDClient.identify}.
44
45
  *
46
+ * If used with the `sheddable` option set to true, then the identify operation will be sheddable. This means that if
47
+ * multiple identify operations are done, without waiting for the previous one to complete, then intermediate
48
+ * operations may be discarded.
49
+ *
50
+ * It is recommended to use the `identifyResult` method instead when the operation is sheddable. In a future release,
51
+ * all identify operations will default to being sheddable.
52
+ *
45
53
  * @param pristineContext The LDContext object to be identified.
46
54
  * @param identifyOptions Optional configuration. See {@link LDIdentifyOptions}.
47
55
  * @returns A Promise which resolves when the flag values for the specified
@@ -55,6 +63,7 @@ export default class LDClientImpl implements LDClient {
55
63
  * 3. A network error is encountered during initialization.
56
64
  */
57
65
  identify(pristineContext: LDContext, identifyOptions?: LDIdentifyOptions): Promise<void>;
66
+ identifyResult(pristineContext: LDContext, identifyOptions?: LDIdentifyOptions): Promise<LDIdentifyResult>;
58
67
  on(eventName: EventName, listener: Function): void;
59
68
  off(eventName: EventName, listener: Function): void;
60
69
  track(key: string, data?: any, metricValue?: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"LDClientImpl.d.ts","sourceRoot":"","sources":["../src/LDClientImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAEjB,OAAO,EAEP,QAAQ,EAER,SAAS,EACT,SAAS,EACT,WAAW,EAEX,QAAQ,EACR,2BAA2B,EAC3B,QAAQ,EAGT,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,uBAAu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AAC;IAOzF,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC;IAOzF,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,uBAAuB,CAAC,MAAM,CAAC;IAOzF,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,uBAAuB,CAAC,OAAO,CAAC;IAIzF,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIzB;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IA2BxE,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,GAAG,IAAI;IAIrD,OAAO,CAAC,wBAAwB;CA6BjC"}
@@ -2,6 +2,7 @@ import { LDContext, LDFlagSet, LDFlagValue, LDLogger } from '@launchdarkly/js-sd
2
2
  import { Hook } from './integrations/Hooks';
3
3
  import { LDEvaluationDetail, LDEvaluationDetailTyped } from './LDEvaluationDetail';
4
4
  import { LDIdentifyOptions } from './LDIdentifyOptions';
5
+ import { LDIdentifyResult } from './LDIdentifyResult';
5
6
  /**
6
7
  * The basic interface for the LaunchDarkly client. Platform-specific SDKs may add some methods of their own.
7
8
  *
@@ -87,6 +88,10 @@ export interface LDClient {
87
88
  * finished, calls to {@link variation} will still return flag values for the previous context. You can
88
89
  * await the Promise to determine when the new flag values are available.
89
90
  *
91
+ * If used with the `sheddable` option set to true, then the identify operation will be sheddable. This means that if
92
+ * multiple identify operations are done, without waiting for the previous one to complete, then intermediate
93
+ * operations may be discarded.
94
+ *
90
95
  * @param context
91
96
  * The LDContext object.
92
97
  * @param identifyOptions
@@ -311,4 +316,36 @@ export interface LDClient {
311
316
  */
312
317
  addHook(hook: Hook): void;
313
318
  }
319
+ /**
320
+ * Interface that extends the LDClient interface to include the identifyResult method.
321
+ *
322
+ * This is an independent interface for backwards compatibility. Adding this to the LDClient interface would require
323
+ * a breaking change.
324
+ */
325
+ export interface LDClientIdentifyResult {
326
+ /**
327
+ * Identifies a context to LaunchDarkly and returns a promise which resolves to an object containing the result of
328
+ * the identify operation.
329
+ *
330
+ * Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state,
331
+ * which is set when you call `identify()`.
332
+ *
333
+ * Changing the current context also causes all feature flag values to be reloaded. Until that has
334
+ * finished, calls to {@link variation} will still return flag values for the previous context. You can
335
+ * await the Promise to determine when the new flag values are available.
336
+ *
337
+ * If used with the `sheddable` option set to true, then the identify operation will be sheddable. This means that if
338
+ * multiple identify operations are done, without waiting for the previous one to complete, then intermediate
339
+ * operations may be discarded.
340
+ *
341
+ * @param context
342
+ * The LDContext object.
343
+ * @param identifyOptions
344
+ * Optional configuration. Please see {@link LDIdentifyOptions}.
345
+ * @returns
346
+ * A promise which resolves to an object containing the result of the identify operation.
347
+ * The promise returned from this method will not be rejected.
348
+ */
349
+ identifyResult(context: LDContext, identifyOptions?: LDIdentifyOptions): Promise<LDIdentifyResult>;
350
+ }
314
351
  //# sourceMappingURL=LDClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LDClient.d.ts","sourceRoot":"","sources":["../../src/api/LDClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAE1F,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;OAOG;IACH,QAAQ,IAAI,SAAS,CAAC;IAEtB;;;;;;;;;;OAUG;IACH,aAAa,CAAC,GAAG,EAAE,M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AiB,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9B"}
@@ -31,5 +31,15 @@ export interface LDIdentifyOptions {
31
31
  * not be required.
32
32
  */
33
33
  noTimeout?: boolean;
34
+ /**
35
+ * If true, the identify operation will be sheddable. This means that if multiple identify operations are started without
36
+ * waiting for the previous one to complete, then intermediate results will be discarded. When false, identify
37
+ * operations will be queued and completed sequentially.
38
+ *
39
+ * By default operations will be queued and completed sequentially.
40
+ *
41
+ * Defaults to false.
42
+ */
43
+ sheddable?: boolean;
34
44
  }
35
45
  //# sourceMappingURL=LDIdentifyOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LDIdentifyOptions.d.ts","sourceRoot":"","sources":["../../src/api/LDIdentifyOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;OASG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
1
+ {"version":3,"file":"LDIdentifyOptions.d.ts","sourceRoot":"","sources":["../../src/api/LDIdentifyOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;OASG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The identify operation completed successfully.
3
+ */
4
+ export interface LDIdentifySuccess {
5
+ status: 'completed';
6
+ }
7
+ /**
8
+ * The identify operation encountered an error. This could include a malformed context, or a network error.
9
+ */
10
+ export interface LDIdentifyError {
11
+ status: 'error';
12
+ error: Error;
13
+ }
14
+ /**
15
+ * The identify operation timed out.
16
+ */
17
+ export interface LDIdentifyTimeout {
18
+ status: 'timeout';
19
+ timeout: number;
20
+ }
21
+ /**
22
+ * The identify operation was shed.
23
+ */
24
+ export interface LDIdentifyShed {
25
+ status: 'shed';
26
+ }
27
+ export type LDIdentifyResult = LDIdentifySuccess | LDIdentifyError | LDIdentifyTimeout | LDIdentifyShed;
28
+ //# sourceMappingURL=LDIdentifyResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LDIdentifyResult.d.ts","sourceRoot":"","sources":["../../src/api/LDIdentifyResult.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,gBAAgB,GACxB,iBAAiB,GACjB,eAAe,GACf,iBAAiB,GACjB,cAAc,CAAC"}
@@ -6,4 +6,5 @@ export * from './integrations';
6
6
  export { ConnectionMode };
7
7
  export * from './LDIdentifyOptions';
8
8
  export * from './LDInspection';
9
+ export * from './LDIdentifyResult';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
@@ -60,8 +60,12 @@ export interface IdentifySeriesData {
60
60
  *
61
61
  * An example in which an error may occur is lack of network connectivity
62
62
  * preventing the SDK from functioning.
63
+ *
64
+ * The SDK may also shed an identify operation if it is not needed. In which case
65
+ * the status will be 'shed'. For SDKs that default to non-sheddable, the status
66
+ * will only ever be 'shed' if the user has opted into a sheddable identify.
63
67
  */
64
- export type IdentifySeriesStatus = 'completed' | 'error';
68
+ export type IdentifySeriesStatus = 'completed' | 'error' | 'shed';
65
69
  /**
66
70
  * The result applies to a single identify operation. An operation may complete
67
71
  * with an error and then later complete successfully. Only the first completion
@@ -157,6 +161,11 @@ export interface Hook {
157
161
  * This method is called during the execution of the identify process, after the operation
158
162
  * completes.
159
163
  *
164
+ * The beforeIdentify methods will be called in the order of the identify calls to the SDK,
165
+ * but afterIdentify may not be in the same order. This is because the SDK may shed an identify
166
+ * operation if it is not needed. This will result in the afterIdentify method potentially being
167
+ * called in a different order than beforeIdentify.
168
+ *
160
169
  * @param hookContext Contains information about the evaluation being performed. This is not
161
170
  * mutable.
162
171
  * @param data A record associated with each stage of hook invocations. Each stage is called with
@@ -1 +1 @@
1
- {"version":3,"file":"Hooks.d.ts","sourceRoot":"","sources":["../../../src/api/integrations/Hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6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ACH,aAAa,CAAC,CACZ,WAAW,EAAE,qBAAqB,EAClC,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,oBAAoB,GAC3B,kBAAkB,CAAC;IAEtB;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACpD"}
@@ -24,6 +24,22 @@ export interface ErroredTask {
24
24
  * Represents the result of a task.
25
25
  */
26
26
  export type TaskResult<TTaskResult> = CompletedTask<TTaskResult> | ErroredTask | ShedTask;
27
+ export interface Task<TTaskResult, TBeforeResult> {
28
+ /**
29
+ * Method ran before the task is executed or shed.
30
+ */
31
+ before?: () => Promise<TBeforeResult>;
32
+ /**
33
+ * Execute the task. This is not ran if the task is shed.
34
+ * @returns The result of the task.
35
+ */
36
+ execute: (beforeResult?: TBeforeResult) => Promise<TTaskResult>;
37
+ /**
38
+ * Method ran after the task is executed or shed.
39
+ * @param result The result of the task.
40
+ */
41
+ after?: (result: TaskResult<TTaskResult>, beforeResult?: TBeforeResult) => void;
42
+ }
27
43
  /**
28
44
  * An asynchronous task queue with the ability to replace pending tasks.
29
45
  *
@@ -33,7 +49,7 @@ export type TaskResult<TTaskResult> = CompletedTask<TTaskResult> | ErroredTask |
33
49
  * For instance, the SDK can only have one active context at a time, if you request identification of many contexts,
34
50
  * then the ultimate state will be based on the last request. The intermediate identifies can be discarded.
35
51
  *
36
- * This class will always begin execution of the first item added to the queue, at that point the item itself is not
52
+ * This queue will always begin execution of the first item added to the queue, at that point the item itself is not
37
53
  * queued, but active. If another request is made while that item is still active, then it is added to the queue.
38
54
  * A third request would then replace the second request if the second request had not yet become active, and it was
39
55
  * sheddable.
@@ -49,11 +65,7 @@ export type TaskResult<TTaskResult> = CompletedTask<TTaskResult> | ErroredTask |
49
65
  * Queue management should be done synchronously. There should not be asynchronous operations between checking the queue
50
66
  * and acting on the results of said check.
51
67
  */
52
- export declare class AsyncTaskQueue<TTaskResult> {
53
- private readonly _logger?;
54
- private _activeTask?;
55
- private _queue;
56
- constructor(_logger?: LDLogger | undefined);
68
+ export declare function createAsyncTaskQueue<TTaskResult>(logger?: LDLogger): {
57
69
  /**
58
70
  * Execute a task using the queue.
59
71
  *
@@ -61,7 +73,14 @@ export declare class AsyncTaskQueue<TTaskResult> {
61
73
  * @param sheddable Whether the task can be shed from the queue.
62
74
  * @returns A promise that resolves to the result of the task.
63
75
  */
64
- execute(task: () => Promise<TTaskResult>, sheddable?: boolean): Promise<TaskResult<TTaskResult>>;
65
- private _checkPending;
66
- }
76
+ execute<TBeforeResult>(task: Task<TTaskResult, TBeforeResult>, sheddable?: boolean): Promise<TaskResult<TTaskResult>>;
77
+ /**
78
+ * Returns the number of pending tasks in the queue.
79
+ * Intended for testing purposes only.
80
+ *
81
+ * @internal
82
+ * @returns The number of pending tasks in the queue.
83
+ */
84
+ pendingCount(): number;
85
+ };
67
86
  //# sourceMappingURL=AsyncTaskQueue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsyncTaskQueue.d.ts","sourceRoot":"","sources":["../../src/async/AsyncTaskQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,WAAW;IACxC,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,WAAW,IAAI,aAAa,CAAC,WAAW,CAAC,GAAG,WAAW,GAAG,QAAQ,CAAC;AA2D1F;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,cAAc,CAAC,WAAW;IAIzB,OAAO,CAAC,QAA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;;;;GAwBG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,QAAQ;IAwB/D;;;;;;OAMG;+EAGU,OAAO,GACjB,QAAQ,WAAW,WAAW,CAAC,CAAC;IAoBnC;;;;;;OAMG;oBACa,MAAM;EAIzB"}
@@ -98,6 +98,143 @@ function makeRequestor(plainContextString, serviceEndpoints, paths, requests, en
98
98
  return new Requestor(requests, uri, headers, method, body);
99
99
  }
100
100
 
101
+ const duplicateExecutionError = new Error('Task has already been executed or shed. This is likely an implementation error. The task will not be executed again.');
102
+ /**
103
+ * Creates a pending task.
104
+ * @param task The async function to execute.
105
+ * @param sheddable Whether the task can be shed from the queue.
106
+ * @returns A pending task.
107
+ */
108
+ function makePending(task, _logger, sheddable = false) {
109
+ let resolveTask;
110
+ const promise = new Promise((resolve) => {
111
+ resolveTask = (result, beforeResult) => {
112
+ try {
113
+ task.after?.(result, beforeResult);
114
+ }
115
+ catch (error) {
116
+ _logger?.error(`Error in after callback: ${error}`);
117
+ }
118
+ resolve(result);
119
+ };
120
+ });
121
+ const beforePromise = task.before ? task.before() : Promise.resolve(undefined);
122
+ let executedOrShed = false;
123
+ return {
124
+ execute: () => {
125
+ if (executedOrShed) {
126
+ // This should never happen. If it does, then it represents an implementation error in the SDK.
127
+ _logger?.error(duplicateExecutionError);
128
+ }
129
+ executedOrShed = true;
130
+ beforePromise
131
+ .then((beforeResult) => {
132
+ task
133
+ .execute(beforeResult)
134
+ .then((result) => resolveTask({ status: 'complete', result }, beforeResult))
135
+ .catch((error) => resolveTask({ status: 'error', error }, beforeResult));
136
+ })
137
+ .catch((error) => {
138
+ _logger?.error(error);
139
+ resolveTask({ status: 'error', error }, undefined);
140
+ });
141
+ },
142
+ shed: () => {
143
+ if (executedOrShed) {
144
+ // This should never happen. If it does, then it represents an implementation error in the SDK.
145
+ _logger?.error(duplicateExecutionError);
146
+ }
147
+ executedOrShed = true;
148
+ beforePromise.then((beforeResult) => {
149
+ resolveTask({ status: 'shed' }, beforeResult);
150
+ });
151
+ },
152
+ promise,
153
+ sheddable,
154
+ };
155
+ }
156
+ /**
157
+ * An asynchronous task queue with the ability to replace pending tasks.
158
+ *
159
+ * This is useful when you have asynchronous operations which much execute in order, and for cases where intermediate
160
+ * operations can be discarded.
161
+ *
162
+ * For instance, the SDK can only have one active context at a time, if you request identification of many contexts,
163
+ * then the ultimate state will be based on the last request. The intermediate identifies can be discarded.
164
+ *
165
+ * This queue will always begin execution of the first item added to the queue, at that point the item itself is not
166
+ * queued, but active. If another request is made while that item is still active, then it is added to the queue.
167
+ * A third request would then replace the second request if the second request had not yet become active, and it was
168
+ * sheddable.
169
+ *
170
+ * Once a task is active the queue will complete it. It doesn't cancel tasks that it has started, but it can shed tasks
171
+ * that have not started.
172
+ *
173
+ * TTaskResult Is the return type of the task to be executed. Tasks accept no parameters. So if you need parameters
174
+ * you should use a lambda to capture them.
175
+ *
176
+ * Exceptions from tasks are always handled and the execute method will never reject a promise.
177
+ *
178
+ * Queue management should be done synchronously. There should not be asynchronous operations between checking the queue
179
+ * and acting on the results of said check.
180
+ */
181
+ function createAsyncTaskQueue(logger) {
182
+ let activeTask;
183
+ const queue = [];
184
+ function checkPending() {
185
+ // There is an existing active task, so we don't need to do anything.
186
+ if (activeTask) {
187
+ return;
188
+ }
189
+ // There are pending tasks, so we need to execute the next one.
190
+ if (queue.length > 0) {
191
+ const nextTask = queue.shift();
192
+ activeTask = nextTask.promise.finally(() => {
193
+ activeTask = undefined;
194
+ checkPending();
195
+ });
196
+ nextTask.execute();
197
+ }
198
+ }
199
+ return {
200
+ /**
201
+ * Execute a task using the queue.
202
+ *
203
+ * @param task The async function to execute.
204
+ * @param sheddable Whether the task can be shed from the queue.
205
+ * @returns A promise that resolves to the result of the task.
206
+ */
207
+ execute(task, sheddable = false) {
208
+ const pending = makePending(task, logger, sheddable);
209
+ if (!activeTask) {
210
+ activeTask = pending.promise.finally(() => {
211
+ activeTask = undefined;
212
+ checkPending();
213
+ });
214
+ pending.execute();
215
+ }
216
+ else {
217
+ // If the last pending task is sheddable, we need to shed it before adding the new task.
218
+ if (queue[queue.length - 1]?.sheddable) {
219
+ queue.pop()?.shed();
220
+ }
221
+ queue.push(pending);
222
+ }
223
+ return pending.promise;
224
+ },
225
+ /**
226
+ * Returns the number of pending tasks in the queue.
227
+ * Intended for testing purposes only.
228
+ *
229
+ * @internal
230
+ * @returns The number of pending tasks in the queue.
231
+ */
232
+ pendingCount() {
233
+ return queue.length;
234
+ },
235
+ };
236
+ }
237
+
101
238
  // eslint-disable-next-line max-classes-per-file
102
239
  const validators = {
103
240
  logger: jsSdkCommon.TypeValidators.Object,
@@ -1212,6 +1349,7 @@ class LDClientImpl {
1212
1349
  this._eventFactoryDefault = new EventFactory(false);
1213
1350
  this._eventFactoryWithReasons = new EventFactory(true);
1214
1351
  this._eventSendingEnabled = false;
1352
+ this._identifyQueue = createAsyncTaskQueue();
1215
1353
  if (!sdkKey) {
1216
1354
  throw new Error('You must configure the client with a client-side SDK key');
1217
1355
  }
@@ -1277,7 +1415,7 @@ class LDClientImpl {
1277
1415
  }
1278
1416
  getContext() {
1279
1417
  // The LDContext returned here may have been modified by the SDK (for example: adding auto env attributes).
1280
- // We are returning an LDContext here to maintain a consistent represetnation of context to the consuming
1418
+ // We are returning an LDContext here to maintain a consistent representation of context to the consuming
1281
1419
  // code. We are returned the unchecked context so that if a consumer identifies with an invalid context
1282
1420
  // and then calls getContext, they get back the same context they provided, without any assertion about
1283
1421
  // validity.
@@ -1286,28 +1424,25 @@ class LDClientImpl {
1286
1424
  getInternalContext() {
1287
1425
  return this._checkedContext;
1288
1426
  }
1289
- _createIdentifyPromise(timeout, noTimeout) {
1427
+ _createIdentifyPromise() {
1290
1428
  let res;
1291
1429
  let rej;
1292
1430
  const basePromise = new Promise((resolve, reject) => {
1293
1431
  res = resolve;
1294
1432
  rej = reject;
1295
1433
  });
1296
- if (noTimeout) {
1297
- return { identifyPromise: basePromise, identifyResolve: res, identifyReject: rej };
1298
- }
1299
- const timed = jsSdkCommon.timedPromise(timeout, 'identify');
1300
- const raced = Promise.race([timed, basePromise]).catch((e) => {
1301
- if (e.message.includes('timed out')) {
1302
- this.logger.error(`identify error: ${e}`);
1303
- }
1304
- throw e;
1305
- });
1306
- return { identifyPromise: raced, identifyResolve: res, identifyReject: rej };
1434
+ return { identifyPromise: basePromise, identifyResolve: res, identifyReject: rej };
1307
1435
  }
1308
1436
  /**
1309
1437
  * Identifies a context to LaunchDarkly. See {@link LDClient.identify}.
1310
1438
  *
1439
+ * If used with the `sheddable` option set to true, then the identify operation will be sheddable. This means that if
1440
+ * multiple identify operations are done, without waiting for the previous one to complete, then intermediate
1441
+ * operations may be discarded.
1442
+ *
1443
+ * It is recommended to use the `identifyResult` method instead when the operation is sheddable. In a future release,
1444
+ * all identify operations will default to being sheddable.
1445
+ *
1311
1446
  * @param pristineContext The LDContext object to be identified.
1312
1447
  * @param identifyOptions Optional configuration. See {@link LDIdentifyOptions}.
1313
1448
  * @returns A Promise which resolves when the flag values for the specified
@@ -1321,39 +1456,95 @@ class LDClientImpl {
1321
1456
  * 3. A network error is encountered during initialization.
1322
1457
  */
1323
1458
  async identify(pristineContext, identifyOptions) {
1459
+ // In order to manage customization in the derived classes it is important that `identify` MUST be implemented in
1460
+ // terms of `identifyResult`. So that the logic of the identification process can be extended in one place.
1461
+ const result = await this.identifyResult(pristineContext, identifyOptions);
1462
+ if (result.status === 'error') {
1463
+ throw result.error;
1464
+ }
1465
+ else if (result.status === 'timeout') {
1466
+ const timeoutError = new jsSdkCommon.LDTimeoutError(`identify timed out after ${result.timeout} seconds.`);
1467
+ this.logger.error(timeoutError.message);
1468
+ throw timeoutError;
1469
+ }
1470
+ // If completed or shed, then we are done.
1471
+ }
1472
+ async identifyResult(pristineContext, identifyOptions) {
1324
1473
  const identifyTimeout = identifyOptions?.timeout ?? DEFAULT_IDENTIFY_TIMEOUT_SECONDS;
1325
1474
  const noTimeout = identifyOptions?.timeout === undefined && identifyOptions?.noTimeout === true;
1326
- // When noTimeout is specified, and a timeout is not secified, then this condition cannot
1475
+ // When noTimeout is specified, and a timeout is not specified, then this condition cannot
1327
1476
  // be encountered. (Our default would need to be greater)
1328
1477
  if (identifyTimeout > this._highTimeoutThreshold) {
1329
1478
  this.logger.warn('The identify function was called with a timeout greater than ' +
1330
1479
  `${this._highTimeoutThreshold} seconds. We recommend a timeout of less than ` +
1331
1480
  `${this._highTimeoutThreshold} seconds.`);
1332
1481
  }
1333
- let context = await ensureKey(pristineContext, this.platform);
1334
- if (this.autoEnvAttributes === jsSdkCommon.AutoEnvAttributes.Enabled) {
1335
- context = await addAutoEnv(context, this.platform, this._config);
1336
- }
1337
- const checkedContext = jsSdkCommon.Context.fromLDContext(context);
1338
- if (!checkedContext.valid) {
1339
- const error = new Error('Context was unspecified or had no key');
1340
- this.emitter.emit('error', context, error);
1341
- return Promise.reject(error);
1342
- }
1343
- this._uncheckedContext = context;
1344
- this._checkedContext = checkedContext;
1345
- this._eventProcessor?.sendEvent(this._eventFactoryDefault.identifyEvent(this._checkedContext));
1346
- const { identifyPromise, identifyResolve, identifyReject } = this._createIdentifyPromise(identifyTimeout, noTimeout);
1347
- this.logger.debug(`Identifying ${JSON.stringify(this._checkedContext)}`);
1348
- const afterIdentify = this._hookRunner.identify(context, identifyOptions?.timeout);
1349
- await this.dataManager.identify(identifyResolve, identifyReject, checkedContext, identifyOptions);
1350
- return identifyPromise.then((res) => {
1351
- afterIdentify({ status: 'completed' });
1352
- return res;
1353
- }, (e) => {
1354
- afterIdentify({ status: 'error' });
1355
- throw e;
1482
+ const callSitePromise = this._identifyQueue
1483
+ .execute({
1484
+ before: async () => {
1485
+ let context = await ensureKey(pristineContext, this.platform);
1486
+ if (this.autoEnvAttributes === jsSdkCommon.AutoEnvAttributes.Enabled) {
1487
+ context = await addAutoEnv(context, this.platform, this._config);
1488
+ }
1489
+ const checkedContext = jsSdkCommon.Context.fromLDContext(context);
1490
+ if (checkedContext.valid) {
1491
+ const afterIdentify = this._hookRunner.identify(context, identifyOptions?.timeout);
1492
+ return {
1493
+ context,
1494
+ checkedContext,
1495
+ afterIdentify,
1496
+ };
1497
+ }
1498
+ return {
1499
+ context,
1500
+ checkedContext,
1501
+ };
1502
+ },
1503
+ execute: async (beforeResult) => {
1504
+ const { context, checkedContext } = beforeResult;
1505
+ if (!checkedContext.valid) {
1506
+ const error = new Error('Context was unspecified or had no key');
1507
+ this.emitter.emit('error', context, error);
1508
+ return Promise.reject(error);
1509
+ }
1510
+ this._uncheckedContext = context;
1511
+ this._checkedContext = checkedContext;
1512
+ this._eventProcessor?.sendEvent(this._eventFactoryDefault.identifyEvent(this._checkedContext));
1513
+ const { identifyPromise, identifyResolve, identifyReject } = this._createIdentifyPromise();
1514
+ this.logger.debug(`Identifying ${JSON.stringify(this._checkedContext)}`);
1515
+ await this.dataManager.identify(identifyResolve, identifyReject, checkedContext, identifyOptions);
1516
+ return identifyPromise;
1517
+ },
1518
+ after: async (res, beforeResult) => {
1519
+ if (res.status === 'complete') {
1520
+ beforeResult?.afterIdentify?.({ status: 'completed' });
1521
+ }
1522
+ else if (res.status === 'shed') {
1523
+ beforeResult?.afterIdentify?.({ status: 'shed' });
1524
+ }
1525
+ else if (res.status === 'error') {
1526
+ beforeResult?.afterIdentify?.({ status: 'error' });
1527
+ }
1528
+ },
1529
+ }, identifyOptions?.sheddable ?? false)
1530
+ .then((res) => {
1531
+ if (res.status === 'error') {
1532
+ return { status: 'error', error: res.error };
1533
+ }
1534
+ if (res.status === 'shed') {
1535
+ return { status: 'shed' };
1536
+ }
1537
+ return { status: 'completed' };
1538
+ });
1539
+ if (noTimeout) {
1540
+ return callSitePromise;
1541
+ }
1542
+ const timeoutPromise = new Promise((resolve) => {
1543
+ setTimeout(() => {
1544
+ resolve({ status: 'timeout', timeout: identifyTimeout });
1545
+ }, identifyTimeout * 1000);
1356
1546
  });
1547
+ return Promise.race([callSitePromise, timeoutPromise]);
1357
1548
  }
1358
1549
  on(eventName, listener) {
1359
1550
  this.emitter.on(eventName, listener);