Skip to content

feat: Converted index.browser.js to TS #585

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/optimizely-sdk/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Bug fixes

- Fixed return type of `getAllFeatureVariables` method in TypeScript type definitions ([#576](https://github.com/optimizely/javascript-sdk/pull/576))

## [4.2.1] - August 10, 2020

### Bug fixes
Expand Down
161 changes: 80 additions & 81 deletions packages/optimizely-sdk/lib/core/decision_service/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,94 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LogHandler } from '@optimizely/js-sdk-logging';
import { ProjectConfig } from '../project_config';
import { UserAttributes, UserProfileService } from '../../shared_types';
import { FeatureFlag, Experiment, Variation } from '../project_config/entities';

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;

export interface DecisionService {

/**
* Creates an instance of the DecisionService.
* @param {Options} options Configuration options
* @return {DecisionService} An instance of the 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.
*/
export function createDecisionService(options: Options): DecisionService;

interface DecisionService {
getVariation(
configObj: ProjectConfig,
experimentKey: string,
userId: string,
attributes?: UserAttributes
): string | null;

/**
* 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;
/**
* 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: 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;
/**
* 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;
/**
* 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;
}
/**
* 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 Options {
userProfileService: UserProfileService | null;
logger: LogHandler;
UNSTABLE_conditionEvaluators: unknown;
}

interface Decision {
experiment: import('../../shared_types').Experiment | null;
variation: import('../../shared_types').Variation | null;
decisionSource: string;
}
interface Decision {
experiment: Experiment | null;
variation: Variation | null;
decisionSource: string;
}
122 changes: 89 additions & 33 deletions packages/optimizely-sdk/lib/core/event_builder/event_helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,97 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ProjectConfig } from '../project_config';
import { EventTags, UserAttributes } from '../../shared_types';

declare module '@optimizely/optimizely-sdk/lib/core/event_builder' {
import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config';

interface ImpressionConfig {
experimentKey: string;
variationKey: string;
userId: string;
userAttributes: import('../../shared_types').UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
}
interface ImpressionConfig {
experimentKey: string;
variationKey: string;
userId: string;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
}
type VisitorAttribute = {
entityId: string;
key: string;
value: string | number | boolean;
}
type EventContext = {
accountId: string;
projectId: string;
revision: string;
clientName: string;
clientVersion: string;
anonymizeIP: boolean;
botFiltering: boolean | undefined;
}

interface ConversionConfig {
eventKey: string;
eventTags: import('../../shared_types').EventTags;
userId: string;
userAttributes: import('../../shared_types').UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
}
interface ImpressionEvent {
type: 'impression';
timestamp: number;
uuid: string;
user: {
id: string;
attributes: VisitorAttribute[];
};
context: EventContext;
layer: {
id: string;
};
experiment: {
id: string;
key: string;
} | null;
variation: {
id: string;
key: string;
} | null;
}

/**
* Creates an ImpressionEvent object from decision data
* @param {ImpressionConfig} config
* @return {ImpressionEvent} an ImpressionEvent object
*/
export function buildImpressionEvent(config: ImpressionConfig): import('@optimizely/js-sdk-event-processor').ImpressionEvent;
interface ConversionConfig {
eventKey: string;
eventTags?: EventTags;
userId: string;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
}

/**
* Creates a ConversionEvent object from track
* @param {ConversionConfig} config
* @return {ConversionEvent} a ConversionEvent object
*/
export function buildConversionEvent(config: ConversionConfig): import('@optimizely/js-sdk-event-processor').ConversionEvent;
interface ConversionEvent {
type: 'conversion';
timestamp: number;
uuid: string;
user: {
id: string;
attributes: VisitorAttribute[];
};
context: EventContext;
experiment: {
id: string;
key: string;
};
event: {
id: string;
key: string;
};
revenue: number | null;
value: number | null;
tags: EventTags;
}

/**
* Creates an ImpressionEvent object from decision data
* @param {ImpressionConfig} config
* @return {ImpressionEvent} an ImpressionEvent object
*/
export function buildImpressionEvent(config: ImpressionConfig): ImpressionEvent;

/**
* Creates a ConversionEvent object from track
* @param {ConversionConfig} config
* @return {ConversionEvent} a ConversionEvent object
*/
export function buildConversionEvent(config: ConversionConfig): ConversionEvent;
Loading