Skip to content

Commit 687d620

Browse files
committed
Convert Optimizely Module
1 parent 6cc5495 commit 687d620

File tree

12 files changed

+1728
-1590
lines changed

12 files changed

+1728
-1590
lines changed

packages/optimizely-sdk/lib/core/decision_service/index.d.ts

+80-81
Original file line numberDiff line numberDiff line change
@@ -13,95 +13,94 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { LogHandler } from '@optimizely/js-sdk-logging';
17+
import { ProjectConfig } from '../project_config';
18+
import { UserAttributes, UserProfileService, Experiment, Variation } from '../../shared_types';
19+
import { FeatureFlag } from '../project_config/entities';
1620

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 {
2029

2130
/**
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.
2537
*/
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;
2944

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;
6666

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;
7575

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;
8484

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+
}
9595

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+
}
101101

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;
107106
}

packages/optimizely-sdk/lib/core/project_config/entities.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,20 @@
1616

1717
export interface FeatureVariable {
1818
type: string;
19+
key: string;
20+
id: string;
21+
defaultValue: string;
1922
}
2023

2124
export interface FeatureFlag {
22-
variables: FeatureVariable[];
25+
rolloutId: string;
26+
key: string;
27+
id: string;
28+
experimentIds: string[],
29+
variables: FeatureVariable[],
30+
variableKeyMap?: {[key: string]: FeatureVariable}
2331
}
2432

33+
export interface FeatureKeyMap {
34+
[key: string]: FeatureFlag
35+
}

0 commit comments

Comments
 (0)