|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
| 16 | +import { LogHandler } from '@optimizely/js-sdk-logging'; |
| 17 | +import { ProjectConfig } from '../project_config'; |
| 18 | +import { UserAttributes, UserProfileService } from '../../shared_types'; |
| 19 | +import { FeatureFlag, Experiment, Variation } from '../project_config/entities'; |
16 | 20 |
|
17 | | -declare module '@optimizely/optimizely-sdk/lib/core/decision_service' { |
18 | | - import { LogHandler } from '@optimizely/js-sdk-logging'; |
19 | | - import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config'; |
| 21 | +/** |
| 22 | + * Creates an instance of the DecisionService. |
| 23 | + * @param {Options} options Configuration options |
| 24 | + * @return {DecisionService} An instance of the DecisionService |
| 25 | + */ |
| 26 | +export function createDecisionService(options: Options): DecisionService; |
| 27 | + |
| 28 | +export interface DecisionService { |
20 | 29 |
|
21 | 30 | /** |
22 | | - * Creates an instance of the DecisionService. |
23 | | - * @param {Options} options Configuration options |
24 | | - * @return {DecisionService} An instance of the DecisionService |
| 31 | + * Gets variation where visitor will be bucketed. |
| 32 | + * @param {ProjectConfig} configObj The parsed project configuration object |
| 33 | + * @param {string} experimentKey |
| 34 | + * @param {string} userId |
| 35 | + * @param {UserAttributes} attributes |
| 36 | + * @return {string|null} The variation the user is bucketed into. |
25 | 37 | */ |
26 | | - export function createDecisionService(options: Options): DecisionService; |
27 | | - |
28 | | - interface DecisionService { |
| 38 | + getVariation( |
| 39 | + configObj: ProjectConfig, |
| 40 | + experimentKey: string, |
| 41 | + userId: string, |
| 42 | + attributes?: UserAttributes |
| 43 | + ): string | null; |
29 | 44 |
|
30 | | - /** |
31 | | - * Gets variation where visitor will be bucketed. |
32 | | - * @param {ProjectConfig} configObj The parsed project configuration object |
33 | | - * @param {string} experimentKey |
34 | | - * @param {string} userId |
35 | | - * @param {UserAttributes} attributes |
36 | | - * @return {string|null} The variation the user is bucketed into. |
37 | | - */ |
38 | | - getVariation( |
39 | | - configObj: ProjectConfig, |
40 | | - experimentKey: string, |
41 | | - userId: string, |
42 | | - attributes?: import('../../shared_types').UserAttributes |
43 | | - ): string | null; |
44 | | - |
45 | | - /** |
46 | | - * Given a feature, user ID, and attributes, returns an object representing a |
47 | | - * decision. If the user was bucketed into a variation for the given feature |
48 | | - * and attributes, the returned decision object will have variation and |
49 | | - * experiment properties (both objects), as well as a decisionSource property. |
50 | | - * decisionSource indicates whether the decision was due to a rollout or an |
51 | | - * experiment. |
52 | | - * @param {ProjectConfig} configObj The parsed project configuration object |
53 | | - * @param {FeatureFlag} feature A feature flag object from project configuration |
54 | | - * @param {string} userId A string identifying the user, for bucketing |
55 | | - * @param {unknown} attributes Optional user attributes |
56 | | - * @return {Decision} An object with experiment, variation, and decisionSource |
57 | | - * properties. If the user was not bucketed into a variation, the variation |
58 | | - * property is null. |
59 | | - */ |
60 | | - getVariationForFeature( |
61 | | - configObj: ProjectConfig, |
62 | | - feature: import('../project_config/entities').FeatureFlag, |
63 | | - userId: string, |
64 | | - attributes: unknown |
65 | | - ): Decision; |
| 45 | + /** |
| 46 | + * Given a feature, user ID, and attributes, returns an object representing a |
| 47 | + * decision. If the user was bucketed into a variation for the given feature |
| 48 | + * and attributes, the returned decision object will have variation and |
| 49 | + * experiment properties (both objects), as well as a decisionSource property. |
| 50 | + * decisionSource indicates whether the decision was due to a rollout or an |
| 51 | + * experiment. |
| 52 | + * @param {ProjectConfig} configObj The parsed project configuration object |
| 53 | + * @param {FeatureFlag} feature A feature flag object from project configuration |
| 54 | + * @param {string} userId A string identifying the user, for bucketing |
| 55 | + * @param {unknown} attributes Optional user attributes |
| 56 | + * @return {Decision} An object with experiment, variation, and decisionSource |
| 57 | + * properties. If the user was not bucketed into a variation, the variation |
| 58 | + * property is null. |
| 59 | + */ |
| 60 | + getVariationForFeature( |
| 61 | + configObj: ProjectConfig, |
| 62 | + feature: FeatureFlag, |
| 63 | + userId: string, |
| 64 | + attributes: unknown |
| 65 | + ): Decision; |
66 | 66 |
|
67 | | - /** |
68 | | - * Removes forced variation for given userId and experimentKey |
69 | | - * @param {unknown} userId String representing the user id |
70 | | - * @param {string} experimentId Number representing the experiment id |
71 | | - * @param {string} experimentKey Key representing the experiment id |
72 | | - * @throws If the user id is not valid or not in the forced variation map |
73 | | - */ |
74 | | - removeForcedVariation(userId: unknown, experimentId: string, experimentKey: string): void; |
| 67 | + /** |
| 68 | + * Removes forced variation for given userId and experimentKey |
| 69 | + * @param {unknown} userId String representing the user id |
| 70 | + * @param {string} experimentId Number representing the experiment id |
| 71 | + * @param {string} experimentKey Key representing the experiment id |
| 72 | + * @throws If the user id is not valid or not in the forced variation map |
| 73 | + */ |
| 74 | + removeForcedVariation(userId: unknown, experimentId: string, experimentKey: string): void; |
75 | 75 |
|
76 | | - /** |
77 | | - * Gets the forced variation key for the given user and experiment. |
78 | | - * @param {ProjectConfig} configObj Object representing project configuration |
79 | | - * @param {string} experimentKey Key for experiment. |
80 | | - * @param {string} userId The user Id. |
81 | | - * @return {string|null} Variation key that specifies the variation which the given user and experiment should be forced into. |
82 | | - */ |
83 | | - getForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string): string | null; |
| 76 | + /** |
| 77 | + * Gets the forced variation key for the given user and experiment. |
| 78 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 79 | + * @param {string} experimentKey Key for experiment. |
| 80 | + * @param {string} userId The user Id. |
| 81 | + * @return {string|null} Variation key that specifies the variation which the given user and experiment should be forced into. |
| 82 | + */ |
| 83 | + getForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string): string | null; |
84 | 84 |
|
85 | | - /** |
86 | | - * Sets the forced variation for a user in a given experiment |
87 | | - * @param {ProjectConfig} configObj Object representing project configuration |
88 | | - * @param {string} experimentKey Key for experiment. |
89 | | - * @param {string} userId The user Id. |
90 | | - * @param {unknown} variationKey Key for variation. If null, then clear the existing experiment-to-variation mapping |
91 | | - * @return {boolean} A boolean value that indicates if the set completed successfully. |
92 | | - */ |
93 | | - setForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string, variationKey: unknown): boolean; |
94 | | - } |
| 85 | + /** |
| 86 | + * Sets the forced variation for a user in a given experiment |
| 87 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 88 | + * @param {string} experimentKey Key for experiment. |
| 89 | + * @param {string} userId The user Id. |
| 90 | + * @param {unknown} variationKey Key for variation. If null, then clear the existing experiment-to-variation mapping |
| 91 | + * @return {boolean} A boolean value that indicates if the set completed successfully. |
| 92 | + */ |
| 93 | + setForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string, variationKey: unknown): boolean; |
| 94 | +} |
95 | 95 |
|
96 | | - interface Options { |
97 | | - userProfileService: import('../../shared_types').UserProfileService | null; |
98 | | - logger: LogHandler; |
99 | | - UNSTABLE_conditionEvaluators: unknown; |
100 | | - } |
| 96 | +interface Options { |
| 97 | + userProfileService: UserProfileService | null; |
| 98 | + logger: LogHandler; |
| 99 | + UNSTABLE_conditionEvaluators: unknown; |
| 100 | +} |
101 | 101 |
|
102 | | - interface Decision { |
103 | | - experiment: import('../../shared_types').Experiment | null; |
104 | | - variation: import('../../shared_types').Variation | null; |
105 | | - decisionSource: string; |
106 | | - } |
| 102 | +interface Decision { |
| 103 | + experiment: Experiment | null; |
| 104 | + variation: Variation | null; |
| 105 | + decisionSource: string; |
107 | 106 | } |
0 commit comments