launchdarkly-js-sdk-common 5.5.0-beta.1 → 5.5.0-beta.3

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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +10 -0
  3. package/typings.d.ts +109 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launchdarkly-js-sdk-common",
3
- "version": "5.5.0-beta.1",
3
+ "version": "5.5.0-beta.3",
4
4
  "description": "LaunchDarkly SDK for JavaScript - common code",
5
5
  "author": "LaunchDarkly <team@launchdarkly.com>",
6
6
  "license": "Apache-2.0",
package/src/index.js CHANGED
@@ -682,10 +682,16 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) {
682
682
  if (!env) {
683
683
  return Promise.reject(new errors.LDInvalidEnvironmentIdError(messages.environmentNotSpecified()));
684
684
  }
685
+ let afterIdentify;
685
686
  return anonymousContextProcessor
686
687
  .processContext(context)
687
688
  .then(verifyContext)
689
+ .then(context => {
690
+ afterIdentify = hookRunner.identify(context, undefined);
691
+ return context;
692
+ })
688
693
  .then(validatedContext => {
694
+ afterIdentify?.({ status: 'completed' });
689
695
  ident.setContext(validatedContext);
690
696
  if (typeof options.bootstrap === 'object') {
691
697
  // flags have already been set earlier
@@ -695,6 +701,10 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) {
695
701
  } else {
696
702
  return finishInitWithPolling();
697
703
  }
704
+ })
705
+ .catch(err => {
706
+ afterIdentify?.({ status: 'error' });
707
+ throw err;
698
708
  });
699
709
  }
700
710
 
package/typings.d.ts CHANGED
@@ -41,14 +41,28 @@ declare module 'launchdarkly-js-sdk-common' {
41
41
  }
42
42
 
43
43
  /**
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
+ }
52
66
 
53
67
  /**
54
68
  * Implementation specific hook data for evaluation stages.
@@ -63,9 +77,56 @@ export interface EvaluationSeriesContext {
63
77
  * Meta-data about a hook implementation.
64
78
  */
65
79
  export interface HookMetadata {
80
+ /**
81
+ * Name of the hook.
82
+ */
66
83
  readonly name: string;
67
84
  }
68
85
 
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
+
69
130
  /**
70
131
  * Interface for extending SDK functionality via hooks.
71
132
  */
@@ -76,7 +137,7 @@ export interface EvaluationSeriesContext {
76
137
  getMetadata(): HookMetadata;
77
138
 
78
139
  /**
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
80
141
  * before the flag value has been determined. The method is executed synchronously.
81
142
  *
82
143
  * @param hookContext Contains information about the evaluation being performed. This is not
@@ -96,7 +157,7 @@ export interface EvaluationSeriesContext {
96
157
  ): EvaluationSeriesData;
97
158
 
98
159
  /**
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
100
161
  * after the flag value has been determined. The method is executed synchronously.
101
162
  *
102
163
  * @param hookContext Contains read-only information about the evaluation
@@ -117,6 +178,44 @@ export interface EvaluationSeriesContext {
117
178
  data: EvaluationSeriesData,
118
179
  detail: LDEvaluationDetail,
119
180
  ): 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;
120
219
  }
121
220
 
122
221
  /**