Skip to content

Commit be99f3c

Browse files
committed
Add correct client-side typing.
1 parent d691d70 commit be99f3c

File tree

2 files changed

+110
-11
lines changed

2 files changed

+110
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "launchdarkly-js-sdk-common",
3-
"version": "5.5.0-beta.1",
3+
"version": "5.5.0-beta.2",
44
"description": "LaunchDarkly SDK for JavaScript - common code",
55
"author": "LaunchDarkly <[email protected]>",
66
"license": "Apache-2.0",

typings.d.ts

Lines changed: 109 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,28 @@ declare module 'launchdarkly-js-sdk-common' {
4141
}
4242

4343
/**
44-
* Contextual information provided to evaluation stages.
45-
*/
46-
export interface EvaluationSeriesContext {
47-
readonly flagKey: string;
48-
readonly context: LDContext;
49-
readonly defaultValue: unknown;
50-
readonly method: string;
51-
}
44+
* Contextual information provided to evaluation stages.
45+
*/
46+
export interface EvaluationSeriesContext {
47+
/**
48+
* The flag key the evaluation is for.
49+
*/
50+
readonly flagKey: string;
51+
/**
52+
* Optional in case evaluations are performed before a context is set.
53+
*/
54+
readonly context?: LDContext;
55+
/**
56+
* The default value that was provided.
57+
*/
58+
readonly defaultValue: unknown;
59+
60+
/**
61+
* Implementation note: Omitting method name because of the associated size.
62+
* If we need this functionality, then we may want to consider adding it and
63+
* taking the associated size hit.
64+
*/
65+
}
5266

5367
/**
5468
* Implementation specific hook data for evaluation stages.
@@ -63,9 +77,56 @@ export interface EvaluationSeriesContext {
6377
* Meta-data about a hook implementation.
6478
*/
6579
export interface HookMetadata {
80+
/**
81+
* Name of the hook.
82+
*/
6683
readonly name: string;
6784
}
6885

86+
/**
87+
* Contextual information provided to identify stages.
88+
*/
89+
export interface IdentifySeriesContext {
90+
/**
91+
* The context associated with the identify operation.
92+
*/
93+
readonly context: LDContext;
94+
/**
95+
* The timeout, in seconds, associated with the identify operation.
96+
*/
97+
readonly timeout?: number;
98+
}
99+
100+
/**
101+
* Implementation specific hook data for identify stages.
102+
*
103+
* Hook implementations can use this to store data needed between stages.
104+
*/
105+
export interface IdentifySeriesData {
106+
readonly [index: string]: unknown;
107+
}
108+
109+
/**
110+
* The status an identify operation completed with.
111+
*
112+
* An example in which an error may occur is lack of network connectivity
113+
* preventing the SDK from functioning.
114+
*/
115+
export type IdentifySeriesStatus = 'completed' | 'error';
116+
117+
/**
118+
* The result applies to a single identify operation. An operation may complete
119+
* with an error and then later complete successfully. Only the first completion
120+
* will be executed in the identify series.
121+
*
122+
* For example, a network issue may cause an identify to error since the SDK
123+
* can't refresh its cached data from the cloud at that moment, but then later
124+
* the when the network issue is resolved, the SDK will refresh cached data.
125+
*/
126+
export interface IdentifySeriesResult {
127+
status: IdentifySeriesStatus;
128+
}
129+
69130
/**
70131
* Interface for extending SDK functionality via hooks.
71132
*/
@@ -76,7 +137,7 @@ export interface EvaluationSeriesContext {
76137
getMetadata(): HookMetadata;
77138

78139
/**
79-
* The before method is called during the execution of a variation method
140+
* This method is called during the execution of a variation method
80141
* before the flag value has been determined. The method is executed synchronously.
81142
*
82143
* @param hookContext Contains information about the evaluation being performed. This is not
@@ -96,7 +157,7 @@ export interface EvaluationSeriesContext {
96157
): EvaluationSeriesData;
97158

98159
/**
99-
* The after method is called during the execution of the variation method
160+
* This method is called during the execution of the variation method
100161
* after the flag value has been determined. The method is executed synchronously.
101162
*
102163
* @param hookContext Contains read-only information about the evaluation
@@ -117,6 +178,44 @@ export interface EvaluationSeriesContext {
117178
data: EvaluationSeriesData,
118179
detail: LDEvaluationDetail,
119180
): EvaluationSeriesData;
181+
182+
/**
183+
* This method is called during the execution of the identify process before the operation
184+
* completes, but after any context modifications are performed.
185+
*
186+
* @param hookContext Contains information about the evaluation being performed. This is not
187+
* mutable.
188+
* @param data A record associated with each stage of hook invocations. Each stage is called with
189+
* the data of the previous stage for a series. The input record should not be modified.
190+
* @returns Data to use when executing the next state of the hook in the evaluation series. It is
191+
* recommended to expand the previous input into the return. This helps ensure your stage remains
192+
* compatible moving forward as more stages are added.
193+
* ```js
194+
* return {...data, "my-new-field": /*my data/*}
195+
* ```
196+
*/
197+
beforeIdentify?(hookContext: IdentifySeriesContext, data: IdentifySeriesData): IdentifySeriesData;
198+
199+
/**
200+
* This method is called during the execution of the identify process before the operation
201+
* completes, but after any context modifications are performed.
202+
*
203+
* @param hookContext Contains information about the evaluation being performed. This is not
204+
* mutable.
205+
* @param data A record associated with each stage of hook invocations. Each stage is called with
206+
* the data of the previous stage for a series. The input record should not be modified.
207+
* @returns Data to use when executing the next state of the hook in the evaluation series. It is
208+
* recommended to expand the previous input into the return. This helps ensure your stage remains
209+
* compatible moving forward as more stages are added.
210+
* ```js
211+
* return {...data, "my-new-field": /*my data/*}
212+
* ```
213+
*/
214+
afterIdentify?(
215+
hookContext: IdentifySeriesContext,
216+
data: IdentifySeriesData,
217+
result: IdentifySeriesResult,
218+
): IdentifySeriesData;
120219
}
121220

122221
/**

0 commit comments

Comments
 (0)