-
Notifications
You must be signed in to change notification settings - Fork 83
feat: Create index.d.ts file for decision_service #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7ea17f3
Create index.d.ts file
yavorona 7b0a28d
Define DecisionService and createDecisionService interfaces
yavorona a9289ff
Clean up
yavorona c83b2d2
index.d.ts added for project_config
a0805d7
Fix imports
yavorona 2b495c5
Fix imports to avoid anti-pattern
yavorona bf13895
Add comments and clean up exports
yavorona 89856e7
Add one more comment
yavorona 3dcda32
Add missing attribute
yavorona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
packages/optimizely-sdk/lib/core/decision_service/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /** | ||
| * Copyright 2020, Optimizely | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| declare module '@optimizely/optimizely-sdk/lib/core/decision_service' { | ||
| import { LogHandler } from '@optimizely/js-sdk-logging'; | ||
| import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config'; | ||
|
|
||
| /** | ||
| * Creates an instance of the DecisionService. | ||
| * @param {Options} options Configuration options | ||
| * @return {DecisionService} An instance of the DecisionService | ||
| */ | ||
| export function createDecisionService(options: Options): DecisionService; | ||
|
|
||
| interface DecisionService { | ||
|
|
||
| /** | ||
| * Gets variation where visitor will be bucketed. | ||
| * @param {ProjectConfig} configObj The parsed project configuration object | ||
| * @param {string} experimentKey | ||
| * @param {string} userId | ||
| * @param {UserAttributes} attributes | ||
| * @return {string|null} The variation the user is bucketed into. | ||
| */ | ||
| getVariation( | ||
| configObj: ProjectConfig, | ||
| experimentKey: string, | ||
| userId: string, | ||
| attributes?: import('../../shared_types').UserAttributes | ||
| ): string | null; | ||
|
|
||
| /** | ||
| * Given a feature, user ID, and attributes, returns an object representing a | ||
| * decision. If the user was bucketed into a variation for the given feature | ||
| * and attributes, the returned decision object will have variation and | ||
| * experiment properties (both objects), as well as a decisionSource property. | ||
| * decisionSource indicates whether the decision was due to a rollout or an | ||
| * experiment. | ||
| * @param {ProjectConfig} configObj The parsed project configuration object | ||
| * @param {FeatureFlag} feature A feature flag object from project configuration | ||
| * @param {string} userId A string identifying the user, for bucketing | ||
| * @param {unknown} attributes Optional user attributes | ||
| * @return {Decision} An object with experiment, variation, and decisionSource | ||
| * properties. If the user was not bucketed into a variation, the variation | ||
| * property is null. | ||
| */ | ||
| getVariationForFeature( | ||
| configObj: ProjectConfig, | ||
| feature: import('../project_config/entities').FeatureFlag, | ||
| userId: string, | ||
| attributes: unknown | ||
| ): Decision; | ||
|
|
||
| /** | ||
| * Removes forced variation for given userId and experimentKey | ||
| * @param {unknown} userId String representing the user id | ||
| * @param {string} experimentId Number representing the experiment id | ||
| * @param {string} experimentKey Key representing the experiment id | ||
| * @throws If the user id is not valid or not in the forced variation map | ||
| */ | ||
| removeForcedVariation(userId: unknown, experimentId: string, experimentKey: string): void; | ||
|
|
||
| /** | ||
| * Gets the forced variation key for the given user and experiment. | ||
| * @param {ProjectConfig} configObj Object representing project configuration | ||
| * @param {string} experimentKey Key for experiment. | ||
| * @param {string} userId The user Id. | ||
| * @return {string|null} Variation key that specifies the variation which the given user and experiment should be forced into. | ||
| */ | ||
| getForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string): string | null; | ||
|
|
||
| /** | ||
| * Sets the forced variation for a user in a given experiment | ||
| * @param {ProjectConfig} configObj Object representing project configuration | ||
| * @param {string} experimentKey Key for experiment. | ||
| * @param {string} userId The user Id. | ||
| * @param {unknown} variationKey Key for variation. If null, then clear the existing experiment-to-variation mapping | ||
| * @return {boolean} A boolean value that indicates if the set completed successfully. | ||
| */ | ||
| setForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string, variationKey: unknown): boolean; | ||
| } | ||
|
|
||
| interface Options { | ||
| userProfileService: import('../../shared_types').UserProfileService | null; | ||
| logger: LogHandler; | ||
| UNSTABLE_conditionEvaluators: unknown; | ||
| } | ||
|
|
||
| interface Decision { | ||
| experiment: import('../../shared_types').Experiment | null; | ||
| variation: import('../../shared_types').Variation | null; | ||
| decisionSource: string; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,41 @@ | ||
| export type UserAttributes = { | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [name: string]: any; | ||
| // TODO[OASIS-6649]: Don't use any type | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [name: string]: any; | ||
| } | ||
|
|
||
| export interface Variation { | ||
| id: string; | ||
| key: string; | ||
| } | ||
|
|
||
| export interface Experiment { | ||
| id: string; | ||
| key: string; | ||
| status: string; | ||
| layerId: string; | ||
| variations: Variation[]; | ||
| trafficAllocation: Array<{ | ||
| entityId: string; | ||
| endOfRange: number; | ||
| }>; | ||
| audienceIds: string[]; | ||
| // TODO[OASIS-6649]: Don't use object type | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| forcedVariations: object; | ||
| } | ||
|
|
||
| // Information about past bucketing decisions for a user. | ||
| export interface UserProfile { | ||
| user_id: string; | ||
| experiment_bucket_map: { | ||
| [experiment_id: string]: { | ||
| variation_id: string; | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| export interface UserProfileService { | ||
| lookup(userId: string): UserProfile; | ||
| save(profile: UserProfile): void; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to use an
enumfor this. Can be updated later if so.