Skip to content

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

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 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7b02917
added declaration file for event builder
Sep 22, 2020
3920a66
added declaration file for notification center
Sep 22, 2020
d3db6d3
comments addressed: imports moved inside module and errorHandler corr…
Sep 23, 2020
143379e
comment addressed: seperate declaration file for event_helper event_h…
Sep 23, 2020
51ad50b
event_helpers module name and declaration file name corrected
Sep 23, 2020
e9d9ce6
event helper functions and interfaces removed from event builder module
Sep 23, 2020
5ed0fe5
EOL in event_helpers.d.ts
Sep 23, 2020
ade1028
event_helper.d.ts linting fixed
Sep 23, 2020
fdc2193
Merge branch 'master' into uzair/eb_declaration
msohailhussain Sep 23, 2020
fcc31fd
Merge branch 'master' into uzair/nc_declaration
msohailhussain Sep 23, 2020
600ea36
Merge branch 'uzair/nc_declaration' into pnguen/optimizely-module-to-ts
yavorona Sep 24, 2020
59b7ce6
Fix imports`
yavorona Sep 24, 2020
1ee33b1
Merge branch 'uzair/eb_declaration' into pnguen/optimizely-module-to-ts
yavorona Sep 24, 2020
2f4a24e
Fix imports
yavorona Sep 24, 2020
b7aa82c
Draft: Convert optimizely module to ts
yavorona Sep 25, 2020
e6eb70f
Change ProjectConfigManager method to create ProjectConfigManager to …
yavorona Sep 25, 2020
9555710
Convert more methods
yavorona Sep 25, 2020
dd5fb2a
Convert onReady
yavorona Sep 25, 2020
615ab27
Fix imports and got to a working state
yavorona Sep 26, 2020
f7803d6
Fix lint
yavorona Sep 26, 2020
36d72c9
Update tests
yavorona Sep 26, 2020
fc56d82
Add missing types
yavorona Sep 26, 2020
1569d17
Fix maxQueueSize
yavorona Sep 26, 2020
6ebe2f9
Temporary move LogTierV1EventProcessorConfig to shared_types to avoid…
yavorona Sep 26, 2020
e08bfab
fix Lint
yavorona Sep 26, 2020
170b26e
index.browser.js converted to ts
Sep 28, 2020
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
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, Experiment, Variation } from '../../shared_types';
import { FeatureFlag } 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;
}
58 changes: 58 additions & 0 deletions packages/optimizely-sdk/lib/core/event_builder/event_helpers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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.
*/

import { ProjectConfig } from '../project_config';
import { EventTags, UserAttributes } from '../../shared_types';

interface ImpressionConfig {
experimentKey: string;
variationKey: string;
userId: string;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface ImpressionEvent {}

interface ConversionConfig {
eventKey: string;
eventTags?: EventTags;
userId: string;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface ConversionEvent {}

/**
* 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;
56 changes: 56 additions & 0 deletions packages/optimizely-sdk/lib/core/event_builder/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* 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.
*/
import { ProjectConfig } from '../project_config';
import { LogHandler } from '@optimizely/js-sdk-logging';
import { EventTags, UserAttributes } from '../../shared_types';
import { Event as EventLoggingEndpoint } from '../../shared_types';

interface ImpressionOptions {
attributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
experimentId: string;
eventKey?: string;
variationId: string;
logger?: LogHandler;
userId: string;
}

interface ConversionEventOptions {
attributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
eventKey: string;
logger: LogHandler;
userId: string;
eventTags?: EventTags;
}

/**
* Create impression event params to be sent to the logging endpoint
* @param {ImpressionOptions} options Object containing values needed to build impression event
* @return {EventLoggingEndpoint} Params to be used in impression event logging endpoint call
*/
export function getImpressionEvent(options: ImpressionOptions): EventLoggingEndpoint;

/**
* Create conversion event params to be sent to the logging endpoint
* @param {ConversionEventOptions} options Object containing values needed to build conversion event
* @return {EventLoggingEndpoint} Params to be used in conversion event logging endpoint call
*/
export function getConversionEvent(options: ConversionEventOptions): EventLoggingEndpoint;
97 changes: 97 additions & 0 deletions packages/optimizely-sdk/lib/core/notification_center/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-disable no-shadow */
/**
* 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.
*/
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
import {
Event,
EventTags,
UserAttributes,
Experiment,
Variation
} from '../../shared_types';

export enum NOTIFICATION_TYPES {
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
LOG_EVENT = 'LOG_EVENT:logEvent',
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
}

export enum DECISION_NOTIFICATION_TYPES {
AB_TEST = 'ab-test',
FEATURE = 'feature',
FEATURE_TEST = 'feature-test',
FEATURE_VARIABLE = 'feature-variable',
ALL_FEATURE_VARIABLES = 'all-feature-variables',
}

export type Options = {
logger: LogHandler;
errorHandler: ErrorHandler;
};

export type SourceInfo = {
experimentKey?: string;
variationKey?: string;
};

export type VariableValues = {
[name: string]: unknown;
};

export type DecisionInfo = {
experimentKey?: string;
variationKey?: string | null;
featureKey?: string;
featureEnabled?: boolean;
source?: string;
sourceInfo?: SourceInfo;
variableKey?: string;
variableValue?: unknown;
variableValues?: VariableValues;
variableType?: string;
};

export interface NotificationData {
// type?: DECISION_NOTIFICATION_TYPES;
type?: string;
userId?: string;
attributes?: UserAttributes;
decisionInfo?: DecisionInfo;
experiment?: Experiment;
variation?: Variation;
logEvent?: Event;
eventKey?: string;
eventTags?: EventTags;
}

export interface NotificationCenter {
/**
* Fires notifications for the argument type. All registered callbacks for this type will be
* called. The notificationData object will be passed on to callbacks called.
* @param {NOTIFICATION_TYPES} notificationType One of NOTIFICATION_TYPES
* @param {NotificationData} notificationData Will be passed to callbacks called
*/
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: NotificationData): void;
}

/**
* Create an instance of NotificationCenter
* @param {Options} options
* @returns {NotificationCenter} An instance of NotificationCenter
*/
export function createNotificationCenter(options: Options): NotificationCenter;
Loading