11/**
2- * Copyright 2020-2024 , Optimizely
2+ * Copyright 2020-2025 , Optimizely
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -39,8 +39,11 @@ export interface IOptimizelyUserContext {
3939 getAttributes ( ) : UserAttributes ;
4040 setAttribute ( key : string , value : unknown ) : void ;
4141 decide ( key : string , options ?: OptimizelyDecideOption [ ] ) : OptimizelyDecision ;
42+ decideAsync ( key : string , options ?: OptimizelyDecideOption [ ] ) : Promise < OptimizelyDecision > ;
4243 decideForKeys ( keys : string [ ] , options ?: OptimizelyDecideOption [ ] ) : { [ key : string ] : OptimizelyDecision } ;
44+ decideForKeysAsync ( keys : string [ ] , options ?: OptimizelyDecideOption [ ] ) : Promise < Record < string , OptimizelyDecision > > ;
4345 decideAll ( options ?: OptimizelyDecideOption [ ] ) : { [ key : string ] : OptimizelyDecision } ;
46+ decideAllAsync ( options ?: OptimizelyDecideOption [ ] ) : Promise < Record < string , OptimizelyDecision > > ;
4447 trackEvent ( eventName : string , eventTags ?: EventTags ) : void ;
4548 setForcedDecision ( context : OptimizelyDecisionContext , decision : OptimizelyForcedDecision ) : boolean ;
4649 getForcedDecision ( context : OptimizelyDecisionContext ) : OptimizelyForcedDecision | null ;
@@ -60,7 +63,7 @@ export default class OptimizelyUserContext implements IOptimizelyUserContext {
6063 constructor ( { optimizely, userId, attributes } : OptimizelyUserContextConfig ) {
6164 this . optimizely = optimizely ;
6265 this . userId = userId ;
63- this . attributes = { ...attributes } ?? { } ;
66+ this . attributes = { ...attributes } ;
6467 this . forcedDecisionsMap = { } ;
6568 }
6669
@@ -104,6 +107,17 @@ export default class OptimizelyUserContext implements IOptimizelyUserContext {
104107 return this . optimizely . decide ( this . cloneUserContext ( ) , key , options ) ;
105108 }
106109
110+ /**
111+ * Returns a promise that resolves in decision result for a given flag key and a user context, which contains all data required to deliver the flag.
112+ * If the SDK finds an error, it will return a decision with null for variationKey. The decision will include an error message in reasons.
113+ * @param {string } key A flag key for which a decision will be made.
114+ * @param {OptimizelyDecideOption } options An array of options for decision-making.
115+ * @return {Promise<OptimizelyDecision> } A Promise that resolves decision result.
116+ */
117+ decideAsync ( key : string , options ?: OptimizelyDecideOption [ ] ) : Promise < OptimizelyDecision > {
118+ return this . optimizely . decideAsync ( this . cloneUserContext ( ) , key , options ) ;
119+ }
120+
107121 /**
108122 * Returns an object of decision results for multiple flag keys and a user context.
109123 * If the SDK finds an error for a key, the response will include a decision for the key showing reasons for the error.
@@ -116,6 +130,17 @@ export default class OptimizelyUserContext implements IOptimizelyUserContext {
116130 return this . optimizely . decideForKeys ( this . cloneUserContext ( ) , keys , options ) ;
117131 }
118132
133+ /**
134+ * Returns a promise that resolves in an object of decision results for multiple flag keys and a user context.
135+ * If the SDK finds an error for a key, the response will include a decision for the key showing reasons for the error.
136+ * The SDK will always return key-mapped decisions. When it cannot process requests, it will return an empty map after logging the errors.
137+ * @param {string[] } keys An array of flag keys for which decisions will be made.
138+ * @param {OptimizelyDecideOption[] } options An array of options for decision-making.
139+ * @return {Promise<Record<string, OptimizelyDecision>> } A promise that resolves in an object of decision results mapped by flag keys.
140+ */
141+ decideForKeysAsync ( keys : string [ ] , options ?: OptimizelyDecideOption [ ] ) : Promise < Record < string , OptimizelyDecision > > {
142+ return this . optimizely . decideForKeysAsync ( this . cloneUserContext ( ) , keys , options ) ;
143+ }
119144 /**
120145 * Returns an object of decision results for all active flag keys.
121146 * @param {OptimizelyDecideOption[] } options An array of options for decision-making.
@@ -125,6 +150,15 @@ export default class OptimizelyUserContext implements IOptimizelyUserContext {
125150 return this . optimizely . decideAll ( this . cloneUserContext ( ) , options ) ;
126151 }
127152
153+ /**
154+ * Returns a promise that resolves in an object of decision results for all active flag keys.
155+ * @param {OptimizelyDecideOption[] } options An array of options for decision-making.
156+ * @return {Promise<Record<string ,OptimizelyDecision>> } A promise that resolves in an object of all decision results mapped by flag keys.
157+ */
158+ decideAllAsync ( options : OptimizelyDecideOption [ ] = [ ] ) : Promise < Record < string , OptimizelyDecision > > {
159+ return this . optimizely . decideAllAsync ( this . cloneUserContext ( ) , options ) ;
160+ }
161+
128162 /**
129163 * Tracks an event.
130164 * @param {string } eventName The event name.
0 commit comments