From b36f192bd51cb7759578a3ae7d36766305d4d1ca Mon Sep 17 00:00:00 2001 From: Polina Nguen Date: Thu, 12 Nov 2020 16:13:02 -0800 Subject: [PATCH] Refactor index.d.ts imports --- .../lib/core/decision_service/index.d.ts | 9 +++- .../lib/core/notification_center/index.d.ts | 9 +++- .../lib/core/project_config/entities.ts | 52 ------------------- .../lib/core/project_config/index.d.ts | 7 ++- packages/optimizely-sdk/lib/index.d.ts | 4 +- .../optimizely-sdk/lib/optimizely/index.ts | 7 +-- packages/optimizely-sdk/lib/shared_types.ts | 38 ++++++++++++++ 7 files changed, 64 insertions(+), 62 deletions(-) delete mode 100644 packages/optimizely-sdk/lib/core/project_config/entities.ts diff --git a/packages/optimizely-sdk/lib/core/decision_service/index.d.ts b/packages/optimizely-sdk/lib/core/decision_service/index.d.ts index 396d75653..d56be1c6c 100644 --- a/packages/optimizely-sdk/lib/core/decision_service/index.d.ts +++ b/packages/optimizely-sdk/lib/core/decision_service/index.d.ts @@ -15,8 +15,13 @@ */ 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'; +import { + UserAttributes, + UserProfileService, + FeatureFlag, + Experiment, + Variation +} from '../../shared_types'; /** * Creates an instance of the DecisionService. diff --git a/packages/optimizely-sdk/lib/core/notification_center/index.d.ts b/packages/optimizely-sdk/lib/core/notification_center/index.d.ts index 4718f17eb..18416d5f5 100644 --- a/packages/optimizely-sdk/lib/core/notification_center/index.d.ts +++ b/packages/optimizely-sdk/lib/core/notification_center/index.d.ts @@ -15,8 +15,13 @@ * limitations under the License. */ import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging'; -import { EventTags, UserAttributes, Event } from '../../shared_types'; -import { Experiment, Variation } from '../project_config/entities'; +import { + EventTags, + UserAttributes, + Event, + Experiment, + Variation +} from '../../shared_types'; export type NOTIFICATION_TYPES = import('@optimizely/js-sdk-utils').NOTIFICATION_TYPES; diff --git a/packages/optimizely-sdk/lib/core/project_config/entities.ts b/packages/optimizely-sdk/lib/core/project_config/entities.ts deleted file mode 100644 index 67e53f12b..000000000 --- a/packages/optimizely-sdk/lib/core/project_config/entities.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * 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. - */ -export interface FeatureVariable { - type: string; - key: string; - id: string; - defaultValue: string; -} - -export interface FeatureFlag { - rolloutId: string; - key: string; - id: string; - experimentIds: string[], - variables: FeatureVariable[], - variableKeyMap: {[key: string]: FeatureVariable} -} - -export interface FeatureKeyMap { - [key: string]: FeatureFlag -} - -export interface Variation { - id: string; - key: string; - featureEnabled: boolean; - variables: VariationVariable[]; -} - -export interface VariationVariable { - id: string; - value: string; -} - -export interface Experiment { - id: string; - key: string; - variationKeyMap: {[key: string]: Variation} -} diff --git a/packages/optimizely-sdk/lib/core/project_config/index.d.ts b/packages/optimizely-sdk/lib/core/project_config/index.d.ts index 78436ed8b..1eb932971 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.d.ts +++ b/packages/optimizely-sdk/lib/core/project_config/index.d.ts @@ -14,7 +14,12 @@ * limitations under the License. */ import { LogHandler } from '@optimizely/js-sdk-logging'; -import { FeatureFlag, FeatureVariable, Experiment, Variation } from './entities'; +import { + FeatureFlag, + FeatureVariable, + Experiment, + Variation +} from '../../shared_types'; export interface ProjectConfig { revision: string; diff --git a/packages/optimizely-sdk/lib/index.d.ts b/packages/optimizely-sdk/lib/index.d.ts index cdcda3622..74e20c32d 100644 --- a/packages/optimizely-sdk/lib/index.d.ts +++ b/packages/optimizely-sdk/lib/index.d.ts @@ -177,8 +177,8 @@ declare module '@optimizely/optimizely-sdk' { } export interface ActivateListenerPayload extends ListenerPayload { - experiment: import('./core/project_config/entities').Experiment; - variation: import('./core/project_config/entities').Variation; + experiment: import('./shared_types').Experiment; + variation: import('./shared_types').Variation; logEvent: Event; } diff --git a/packages/optimizely-sdk/lib/optimizely/index.ts b/packages/optimizely-sdk/lib/optimizely/index.ts index 75242a594..e477cd351 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.ts +++ b/packages/optimizely-sdk/lib/optimizely/index.ts @@ -15,7 +15,6 @@ ***************************************************************************/ import { sprintf, objectValues } from '@optimizely/js-sdk-utils'; import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging'; -import { FeatureFlag, FeatureVariable } from '../core/project_config/entities'; import { UserAttributes, EventTags, @@ -23,9 +22,11 @@ import { EventDispatcher, OnReadyResult, UserProfileService, - DatafileOptions + DatafileOptions, + Variation, + FeatureFlag, + FeatureVariable } from '../shared_types'; -import { Variation } from '../core/project_config/entities'; import { createProjectConfigManager, ProjectConfigManager } from '../core/project_config/project_config_manager'; import { createNotificationCenter, NotificationCenter } from '../core/notification_center'; import { createDecisionService, DecisionService, DecisionObj } from '../core/decision_service'; diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 289f25fe9..3ec5e3ee4 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -56,6 +56,44 @@ export interface EventDispatcher { dispatchEvent: (event: Event, callback: (response: { statusCode: number; }) => void) => void; } +export interface VariationVariable { + id: string; + value: string; +} + +export interface Variation { + id: string; + key: string; + featureEnabled: boolean; + variables: VariationVariable[]; +} + +export interface Experiment { + id: string; + key: string; + variationKeyMap: {[key: string]: Variation} +} + +export interface FeatureVariable { + type: string; + key: string; + id: string; + defaultValue: string; +} + +export interface FeatureFlag { + rolloutId: string; + key: string; + id: string; + experimentIds: string[], + variables: FeatureVariable[], + variableKeyMap: {[key: string]: FeatureVariable} +} + +export interface FeatureKeyMap { + [key: string]: FeatureFlag +} + export interface OnReadyResult { success: boolean; reason?: string;