From 49175573328d7b67b66de56db2e4d23b79954a2f Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Fri, 25 Feb 2022 19:59:11 +0500 Subject: [PATCH 01/19] init --- packages/optimizely-sdk/package.json | 2 +- packages/optimizely-sdk/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index 788783124..d78b4a9a4 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -17,7 +17,7 @@ "test-umdbrowser": "npm run build-browser-umd && karma start karma.umd.conf.js --single-run", "test-karma-local": "karma start karma.local_chrome.bs.conf.js && npm run build-browser-umd && karma start karma.local_chrome.umd.conf.js", "prebuild": "npm run clean", - "build": "rollup -c", + "build": "rollup -c && mv dist/index.lite.d.ts dist/optimizely.lite.es.d.ts && rm dist/index*.d.ts", "build-browser-umd": "rollup -c --config-umd", "precover": "nyc npm test", "cover": "nyc report -r lcov", diff --git a/packages/optimizely-sdk/tsconfig.json b/packages/optimizely-sdk/tsconfig.json index d7ec24942..1ce245676 100644 --- a/packages/optimizely-sdk/tsconfig.json +++ b/packages/optimizely-sdk/tsconfig.json @@ -8,7 +8,7 @@ ] }, "allowJs": true, - "declaration": false, + "declaration": true, "module": "esnext", "outDir": "./dist", "sourceMap": true From e80f0a20ddac25a66719ab8d4fc994ddbea2aa87 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Fri, 25 Feb 2022 20:37:02 +0500 Subject: [PATCH 02/19] Event module made public --- .../lib/plugins/event_dispatcher/index.browser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts b/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts index 2c4a979cd..1f2b777b1 100644 --- a/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts +++ b/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts @@ -17,7 +17,7 @@ const POST_METHOD = 'POST'; const GET_METHOD = 'GET'; const READYSTATE_COMPLETE = 4; -interface Event { +export interface Event { url: string; httpVerb: 'POST' | 'GET'; // eslint-disable-next-line @typescript-eslint/no-explicit-any From 5a547fc75b579f48c8a0458885ff247dd903a3c6 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Tue, 8 Mar 2022 23:46:04 +0500 Subject: [PATCH 03/19] typings added in shared types --- packages/optimizely-sdk/lib/index.browser.ts | 4 +- packages/optimizely-sdk/lib/index.lite.ts | 4 +- packages/optimizely-sdk/lib/index.node.ts | 4 +- .../optimizely-sdk/lib/index.react_native.ts | 4 +- packages/optimizely-sdk/lib/shared_types.ts | 93 ++++++++++++++++++- 5 files changed, 100 insertions(+), 9 deletions(-) diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index 59d23e694..e816924cc 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -31,7 +31,7 @@ import Optimizely from './optimizely'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { default as eventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption } from './shared_types'; +import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); @@ -51,7 +51,7 @@ let hasRetriedEvents = false; * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | null { +const createInstance = function(config: SDKOptions): Optimizely | Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel if (config.errorHandler) { diff --git a/packages/optimizely-sdk/lib/index.lite.ts b/packages/optimizely-sdk/lib/index.lite.ts index 86e30876d..9dd26a0fa 100644 --- a/packages/optimizely-sdk/lib/index.lite.ts +++ b/packages/optimizely-sdk/lib/index.lite.ts @@ -29,7 +29,7 @@ import * as loggerPlugin from './plugins/logger'; import Optimizely from './optimizely'; import { createNotificationCenter } from './core/notification_center'; import { createForwardingEventProcessor } from './plugins/event_processor/forwarding_event_processor'; -import { SDKOptions, OptimizelyDecideOption } from './shared_types'; +import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; import { createNoOpDatafileManager } from './plugins/datafile_manager/no_op_datafile_manager'; const logger = getLogger(); @@ -42,7 +42,7 @@ setLogLevel(LogLevel.ERROR); * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | null { +const createInstance = function(config: SDKOptions): Optimizely | Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index 99b5c7cd6..98d7e72fc 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -30,7 +30,7 @@ import defaultEventDispatcher from './plugins/event_dispatcher/index.node'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption } from './shared_types'; +import { SDKOptions, OptimizelyDecideOption, Config, Client } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); @@ -46,7 +46,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | null { +const createInstance = function(config: SDKOptions): Optimizely | Client | null { try { let hasLogger = false; diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index 75c38cdcd..6fc6bee80 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -30,7 +30,7 @@ import defaultEventDispatcher from './plugins/event_dispatcher/index.browser'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption } from './shared_types'; +import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); @@ -47,7 +47,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | null { +const createInstance = function(config: SDKOptions): Optimizely | Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel if (config.errorHandler) { diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 93f955d14..e301b3f2c 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -263,12 +263,103 @@ export interface OptimizelyVariable { value: string; } +export interface Client { + notificationCenter: NotificationCenter; + createUserContext( + userId: string, + attributes?: UserAttributes + ): OptimizelyUserContext | null; + activate( + experimentKey: string, + userId: string, + attributes?: UserAttributes + ): string | null; + track( + eventKey: string, + userId: string, + attributes?: UserAttributes, + eventTags?: EventTags + ): void; + getVariation( + experimentKey: string, + userId: string, + attributes?: UserAttributes + ): string | null; + setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean; + getForcedVariation(experimentKey: string, userId: string): string | null; + isFeatureEnabled( + featureKey: string, + userId: string, + attributes?: UserAttributes + ): boolean; + getEnabledFeatures( + userId: string, + attributes?: UserAttributes + ): string[]; + getFeatureVariable( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): unknown; + getFeatureVariableBoolean( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): boolean | null; + getFeatureVariableDouble( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): number | null; + getFeatureVariableInteger( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): number | null; + getFeatureVariableString( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): string | null; + getFeatureVariableJSON( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): unknown; + getAllFeatureVariables( + featureKey: string, + userId: string, + attributes?: UserAttributes + ): { [variableKey: string]: unknown } | null; + getOptimizelyConfig(): OptimizelyConfig | null; + onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>; + close(): Promise<{ success: boolean; reason?: string }>; +} + +export interface ActivateListenerPayload extends ListenerPayload { + experiment: import('./shared_types').Experiment; + variation: import('./shared_types').Variation; + logEvent: Event; +} + +export interface TrackListenerPayload extends ListenerPayload { + eventKey: string; + eventTags: EventTags; + logEvent: Event; +} + /** * Entry level Config Entities */ export interface SDKOptions { // Datafile string - datafile?: string; + datafile?: object | string; // options for Datafile Manager datafileOptions?: DatafileOptions; // errorHandler object for logging error From c58cda9f4eac882f31a1b06276ac6481f1a34892 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Wed, 9 Mar 2022 10:36:52 +0500 Subject: [PATCH 04/19] lint fix --- packages/optimizely-sdk/lib/core/project_config/index.ts | 2 +- packages/optimizely-sdk/lib/index.node.ts | 2 +- .../plugins/datafile_manager/http_polling_datafile_manager.ts | 2 +- packages/optimizely-sdk/lib/shared_types.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/optimizely-sdk/lib/core/project_config/index.ts b/packages/optimizely-sdk/lib/core/project_config/index.ts index 2ea2b8b41..91a7fa158 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.ts +++ b/packages/optimizely-sdk/lib/core/project_config/index.ts @@ -45,7 +45,7 @@ import { } from '../../shared_types'; interface TryCreatingProjectConfigConfig { - datafile: string; + datafile: string | object; jsonSchemaValidator?: { validate(jsonObject: unknown): boolean, }; diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index 98d7e72fc..5e6dc4b93 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -30,7 +30,7 @@ import defaultEventDispatcher from './plugins/event_dispatcher/index.node'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption, Config, Client } from './shared_types'; +import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); diff --git a/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts b/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts index 5cca10bed..29da61a8a 100644 --- a/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts +++ b/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts @@ -22,7 +22,7 @@ import fns from '../../utils/fns'; export function createHttpPollingDatafileManager( sdkKey: string, logger: LoggerFacade, - datafile?: string, + datafile?: string | object, datafileOptions?: DatafileOptions, ): DatafileManager { const datafileManagerConfig: DatafileManagerConfig = { sdkKey }; diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index e301b3f2c..1037a380c 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -229,7 +229,7 @@ export interface OptimizelyOptions { UNSTABLE_conditionEvaluators?: unknown; clientEngine: string; clientVersion?: string; - datafile?: string; + datafile?: string | object; datafileManager?: DatafileManager; errorHandler: ErrorHandler; eventProcessor: EventProcessor; From 6bb85d0d61bb26069093b2e7e446a6dcd96e185d Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Wed, 9 Mar 2022 10:50:32 +0500 Subject: [PATCH 05/19] ProjectConfigManagerConfig datafile type corrected --- .../lib/core/project_config/project_config_manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts index 174a92c32..2d6e6543b 100644 --- a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts +++ b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts @@ -29,7 +29,7 @@ const logger = getLogger(); const MODULE_NAME = 'PROJECT_CONFIG_MANAGER'; interface ProjectConfigManagerConfig { - datafile?: string, + datafile?: string | object, jsonSchemaValidator?: { validate(jsonObject: unknown): boolean, }; @@ -172,7 +172,7 @@ export class ProjectConfigManager { * @param {string} newDatafile * @returns {Error|null} error or null */ - private handleNewDatafile(newDatafile: string): Error | null { + private handleNewDatafile(newDatafile: string | object): Error | null { const { configObj, error } = tryCreatingProjectConfig({ datafile: newDatafile, jsonSchemaValidator: this.jsonSchemaValidator, From a50e87d9ab19ca1edc74f08207ace8374cb6dff6 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Wed, 9 Mar 2022 11:16:00 +0500 Subject: [PATCH 06/19] object warning suppressed --- packages/optimizely-sdk/lib/core/project_config/index.ts | 2 ++ .../lib/core/project_config/project_config_manager.ts | 4 +++- .../plugins/datafile_manager/http_polling_datafile_manager.ts | 4 +++- packages/optimizely-sdk/lib/shared_types.ts | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/optimizely-sdk/lib/core/project_config/index.ts b/packages/optimizely-sdk/lib/core/project_config/index.ts index 91a7fa158..89599b766 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.ts +++ b/packages/optimizely-sdk/lib/core/project_config/index.ts @@ -45,6 +45,8 @@ import { } from '../../shared_types'; interface TryCreatingProjectConfigConfig { + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types datafile: string | object; jsonSchemaValidator?: { validate(jsonObject: unknown): boolean, diff --git a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts index 2d6e6543b..32430667a 100644 --- a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts +++ b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts @@ -29,6 +29,8 @@ const logger = getLogger(); const MODULE_NAME = 'PROJECT_CONFIG_MANAGER'; interface ProjectConfigManagerConfig { + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types datafile?: string | object, jsonSchemaValidator?: { validate(jsonObject: unknown): boolean, @@ -169,7 +171,7 @@ export class ProjectConfigManager { * the new config object's revision is newer than the current one, sets/updates the project config * and optimizely config object instance variables and returns null for the error. If unsuccessful, * the project config and optimizely config objects will not be updated, and the error is returned. - * @param {string} newDatafile + * @param {string | object} newDatafile * @returns {Error|null} error or null */ private handleNewDatafile(newDatafile: string | object): Error | null { diff --git a/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts b/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts index 29da61a8a..925cead7f 100644 --- a/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts +++ b/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts @@ -21,7 +21,9 @@ import fns from '../../utils/fns'; export function createHttpPollingDatafileManager( sdkKey: string, - logger: LoggerFacade, + logger: LoggerFacade, + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types datafile?: string | object, datafileOptions?: DatafileOptions, ): DatafileManager { diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 1037a380c..6da507b42 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -229,6 +229,8 @@ export interface OptimizelyOptions { UNSTABLE_conditionEvaluators?: unknown; clientEngine: string; clientVersion?: string; + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types datafile?: string | object; datafileManager?: DatafileManager; errorHandler: ErrorHandler; @@ -359,6 +361,8 @@ export interface TrackListenerPayload extends ListenerPayload { */ export interface SDKOptions { // Datafile string + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types datafile?: object | string; // options for Datafile Manager datafileOptions?: DatafileOptions; From d4b3661a8b58875a4ed91782a8f0db76f9b68846 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Wed, 9 Mar 2022 11:25:50 +0500 Subject: [PATCH 07/19] object parameter added in handleNewDatafile --- .../lib/core/project_config/project_config_manager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts index 32430667a..2cec65a4e 100644 --- a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts +++ b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts @@ -174,6 +174,8 @@ export class ProjectConfigManager { * @param {string | object} newDatafile * @returns {Error|null} error or null */ + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types private handleNewDatafile(newDatafile: string | object): Error | null { const { configObj, error } = tryCreatingProjectConfig({ datafile: newDatafile, From b59f8a0a1fee1ef9a9e64a8630d8abe0f5e29ff1 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Thu, 10 Mar 2022 22:01:16 +0500 Subject: [PATCH 08/19] index.d.ts removed --- packages/optimizely-sdk/lib/index.browser.ts | 5 +- packages/optimizely-sdk/lib/index.d.ts | 242 ------------------ packages/optimizely-sdk/lib/index.lite.ts | 5 +- packages/optimizely-sdk/lib/index.node.ts | 5 +- .../optimizely-sdk/lib/index.react_native.ts | 5 +- packages/optimizely-sdk/lib/shared_types.ts | 38 ++- 6 files changed, 48 insertions(+), 252 deletions(-) delete mode 100644 packages/optimizely-sdk/lib/index.d.ts diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index e816924cc..e4d0ebdf5 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -31,7 +31,7 @@ import Optimizely from './optimizely'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { default as eventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; +import { OptimizelyDecideOption, Client, Config } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); @@ -51,7 +51,7 @@ let hasRetriedEvents = false; * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | Client | null { +const createInstance = function(config: Config): Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel if (config.errorHandler) { @@ -125,6 +125,7 @@ const createInstance = function(config: SDKOptions): Optimizely | Client | null errorHandler, datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined, notificationCenter, + isValidInstance: config.isValidInstance }; const optimizely = new Optimizely(optimizelyOptions); diff --git a/packages/optimizely-sdk/lib/index.d.ts b/packages/optimizely-sdk/lib/index.d.ts deleted file mode 100644 index 089d94ca3..000000000 --- a/packages/optimizely-sdk/lib/index.d.ts +++ /dev/null @@ -1,242 +0,0 @@ -/** - * Copyright 2018-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' { - import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging'; - import * as enums from '@optimizely/optimizely-sdk/lib/utils/enums'; - import * as logging from '@optimizely/optimizely-sdk/lib/plugins/logger'; - - export { enums, logging }; - - export function setLogger(logger: LogHandler | null): void; - - export function setLogLevel(level: enums.LOG_LEVEL | string): void; - - export function createInstance(config: Config): Client; - - export const errorHandler: ErrorHandler; - - export const eventDispatcher: EventDispatcher; - - export type UserAttributes = import('./shared_types').UserAttributes; - - export type OptimizelyConfig = import('./shared_types').OptimizelyConfig; - - export type OptimizelyVariable = import('./shared_types').OptimizelyVariable; - - export type OptimizelyVariation = import('./shared_types').OptimizelyVariation; - - export type OptimizelyExperiment = import('./shared_types').OptimizelyExperiment; - - export type OptimizelyFeature = import('./shared_types').OptimizelyFeature; - - export type OptimizelyDecisionContext = import('./shared_types').OptimizelyDecisionContext; - - export type OptimizelyForcedDecision = import('./shared_types').OptimizelyForcedDecision; - - export type EventTags = import('./shared_types').EventTags; - - export type Event = import('./shared_types').Event; - - export type EventDispatcher = import('./shared_types').EventDispatcher; - - export type DatafileOptions = import('./shared_types').DatafileOptions; - - export type SDKOptions = import('./shared_types').SDKOptions; - - export type OptimizelyOptions = import('./shared_types').OptimizelyOptions; - - export type UserProfileService = import('./shared_types').UserProfileService; - - export type UserProfile = import('./shared_types').UserProfile; - - export type ListenerPayload = import('./shared_types').ListenerPayload; - - export type OptimizelyDecision = import('./shared_types').OptimizelyDecision; - - export type OptimizelyUserContext = import('./shared_types').OptimizelyUserContext; - - export enum OptimizelyDecideOption { - DISABLE_DECISION_EVENT = 'DISABLE_DECISION_EVENT', - ENABLED_FLAGS_ONLY = 'ENABLED_FLAGS_ONLY', - IGNORE_USER_PROFILE_SERVICE = 'IGNORE_USER_PROFILE_SERVICE', - INCLUDE_REASONS = 'INCLUDE_REASONS', - EXCLUDE_VARIABLES = 'EXCLUDE_VARIABLES' - } - - export type NotificationListener = import('./shared_types').NotificationListener; - - // The options object given to Optimizely.createInstance. - export interface Config { - // TODO[OASIS-6649]: Don't use object type - // eslint-disable-next-line @typescript-eslint/ban-types - datafile?: object | string; - datafileOptions?: DatafileOptions; - errorHandler?: ErrorHandler; - eventDispatcher?: EventDispatcher; - logger?: LogHandler; - logLevel?: - | string - | enums.LOG_LEVEL.DEBUG - | enums.LOG_LEVEL.ERROR - | enums.LOG_LEVEL.INFO - | enums.LOG_LEVEL.NOTSET - | enums.LOG_LEVEL.WARNING; - jsonSchemaValidator?: { - validate(jsonObject: unknown): boolean, - }; - userProfileService?: UserProfileService | null; - eventBatchSize?: number; - eventFlushInterval?: number; - sdkKey?: string; - defaultDecideOptions?: OptimizelyDecideOption[] - } - - export interface Client { - notificationCenter: NotificationCenter; - createUserContext( - userId: string, - attributes?: UserAttributes - ): OptimizelyUserContext | null; - activate( - experimentKey: string, - userId: string, - attributes?: UserAttributes - ): string | null; - track( - eventKey: string, - userId: string, - attributes?: UserAttributes, - eventTags?: EventTags - ): void; - getVariation( - experimentKey: string, - userId: string, - attributes?: UserAttributes - ): string | null; - setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean; - getForcedVariation(experimentKey: string, userId: string): string | null; - isFeatureEnabled( - featureKey: string, - userId: string, - attributes?: UserAttributes - ): boolean; - getEnabledFeatures( - userId: string, - attributes?: UserAttributes - ): string[]; - getFeatureVariable( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes - ): unknown; - getFeatureVariableBoolean( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes - ): boolean | null; - getFeatureVariableDouble( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes - ): number | null; - getFeatureVariableInteger( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes - ): number | null; - getFeatureVariableString( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes - ): string | null; - getFeatureVariableJSON( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes - ): unknown; - getAllFeatureVariables( - featureKey: string, - userId: string, - attributes?: UserAttributes - ): { [variableKey: string]: unknown } | null; - getOptimizelyConfig(): OptimizelyConfig | null; - onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>; - close(): Promise<{ success: boolean; reason?: string }>; - } - - // NotificationCenter-related types - export interface NotificationCenter { - addNotificationListener( - notificationType: string, - callback: NotificationListener - ): number; - removeNotificationListener(listenerId: number): boolean; - clearAllNotificationListeners(): void; - clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void; - } - - export interface ActivateListenerPayload extends ListenerPayload { - experiment: import('./shared_types').Experiment; - variation: import('./shared_types').Variation; - logEvent: Event; - } - - export interface TrackListenerPayload extends ListenerPayload { - eventKey: string; - eventTags: EventTags; - logEvent: Event; - } -} - -declare module '@optimizely/optimizely-sdk/lib/utils/enums' { - import { LogLevel } from '@optimizely/js-sdk-logging'; - - export { LogLevel as LOG_LEVEL }; - - export enum NOTIFICATION_TYPES { - ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', - DECISION = 'DECISION:type, userId, attributes, decisionInfo', - OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', - TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', - LOG_EVENT = "LOG_EVENT:logEvent" - } -} - -declare module '@optimizely/optimizely-sdk/lib/plugins/logger' { - import * as enums from '@optimizely/optimizely-sdk/lib/utils/enums'; - import { LogHandler } from '@optimizely/js-sdk-logging'; - - export interface LoggerConfig { - logLevel?: enums.LOG_LEVEL | string; - logToConsole?: boolean; - prefix?: string; - } - export function createLogger(config?: LoggerConfig): LogHandler; - export function createNoOpLogger(): LogHandler; -} - -declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher' {} - -declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' {} - -declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' {} diff --git a/packages/optimizely-sdk/lib/index.lite.ts b/packages/optimizely-sdk/lib/index.lite.ts index 9dd26a0fa..1910e8887 100644 --- a/packages/optimizely-sdk/lib/index.lite.ts +++ b/packages/optimizely-sdk/lib/index.lite.ts @@ -29,7 +29,7 @@ import * as loggerPlugin from './plugins/logger'; import Optimizely from './optimizely'; import { createNotificationCenter } from './core/notification_center'; import { createForwardingEventProcessor } from './plugins/event_processor/forwarding_event_processor'; -import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; +import { OptimizelyDecideOption, Client, Config } from './shared_types'; import { createNoOpDatafileManager } from './plugins/datafile_manager/no_op_datafile_manager'; const logger = getLogger(); @@ -42,7 +42,7 @@ setLogLevel(LogLevel.ERROR); * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | Client | null { + const createInstance = function(config: Config): Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel @@ -79,6 +79,7 @@ const createInstance = function(config: SDKOptions): Optimizely | Client | null datafileManager: createNoOpDatafileManager(), eventProcessor, notificationCenter, + isValidInstance: config.isValidInstance, }; const optimizely = new Optimizely(optimizelyOptions); diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index 5e6dc4b93..2e8bcfa73 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -30,7 +30,7 @@ import defaultEventDispatcher from './plugins/event_dispatcher/index.node'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; +import { OptimizelyDecideOption, Client, Config } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); @@ -46,7 +46,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | Client | null { + const createInstance = function(config: Config): Client | null { try { let hasLogger = false; @@ -113,6 +113,7 @@ const createInstance = function(config: SDKOptions): Optimizely | Client | null errorHandler, datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined, notificationCenter, + isValidInstance: config.isValidInstance, }; return new Optimizely(optimizelyOptions); diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index 6fc6bee80..fb0a7977e 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -30,7 +30,7 @@ import defaultEventDispatcher from './plugins/event_dispatcher/index.browser'; import eventProcessorConfigValidator from './utils/event_processor_config_validator'; import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor'; -import { SDKOptions, OptimizelyDecideOption, Client } from './shared_types'; +import { OptimizelyDecideOption, Client, Config } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; const logger = getLogger(); @@ -47,7 +47,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; * @return {Optimizely|null} the Optimizely object * null on error */ -const createInstance = function(config: SDKOptions): Optimizely | Client | null { + const createInstance = function(config: Config): Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel if (config.errorHandler) { @@ -107,6 +107,7 @@ const createInstance = function(config: SDKOptions): Optimizely | Client | null errorHandler, datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined, notificationCenter, + isValidInstance: config.isValidInstance, }; // If client engine is react, convert it to react native. diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 6da507b42..125f08f4d 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -266,7 +266,6 @@ export interface OptimizelyVariable { } export interface Client { - notificationCenter: NotificationCenter; createUserContext( userId: string, attributes?: UserAttributes @@ -377,7 +376,42 @@ export interface SDKOptions { // maximum size for the event queue eventMaxQueueSize?: number; // flag to validate if this instance is valid - isValidInstance: boolean; + isValidInstance?: boolean; + // level of logging i.e debug, info, error, warning etc + logLevel?: LogLevel | string; + // LogHandler object for logging + logger?: LogHandler; + // sdk key + sdkKey?: string; + // user profile that contains user information + userProfileService?: UserProfileService; + // dafault options for decide API + defaultDecideOptions?: OptimizelyDecideOption[]; +} + +/** + * Entry level Config Entities + * For compatibility with the previous declaration file + */ + export interface Config { + // Datafile string + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types + datafile?: object | string; + // options for Datafile Manager + datafileOptions?: DatafileOptions; + // errorHandler object for logging error + errorHandler?: ErrorHandler; + // limit of events to dispatch in a batch + eventBatchSize?: number; + // event dispatcher function + eventDispatcher?: EventDispatcher; + // maximum time for an event to stay in the queue + eventFlushInterval?: number; + // maximum size for the event queue + eventMaxQueueSize?: number; + // flag to validate if this instance is valid + isValidInstance?: boolean; // level of logging i.e debug, info, error, warning etc logLevel?: LogLevel | string; // LogHandler object for logging From c3f628eaf730098e8307dbabc8b38c5e0892d1de Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Wed, 16 Mar 2022 16:14:55 +0500 Subject: [PATCH 09/19] typing synced with index.d.ts --- packages/optimizely-sdk/lib/index.browser.ts | 29 +++++++++++++++++++ packages/optimizely-sdk/lib/index.lite.ts | 29 +++++++++++++++++++ packages/optimizely-sdk/lib/index.node.ts | 29 +++++++++++++++++++ .../optimizely-sdk/lib/index.react_native.ts | 29 +++++++++++++++++++ packages/optimizely-sdk/package.json | 4 +-- 5 files changed, 118 insertions(+), 2 deletions(-) diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index e4d0ebdf5..dca31c511 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -182,3 +182,32 @@ export default { __internalResetRetryState, OptimizelyDecideOption, }; + +export { + UserAttributes, + OptimizelyConfig, + OptimizelyVariable, + OptimizelyVariation, + OptimizelyExperiment, + OptimizelyFeature, + OptimizelyDecisionContext, + OptimizelyForcedDecision, + EventTags, + Event, + EventDispatcher, + DatafileOptions, + SDKOptions, + OptimizelyOptions, + UserProfileService, + UserProfile, + ListenerPayload, + OptimizelyDecision, + OptimizelyUserContext, + NotificationListener, + Config, + Client, + ActivateListenerPayload, + TrackListenerPayload, +} from './shared_types' + +export type {NotificationCenter} from "./core/notification_center" diff --git a/packages/optimizely-sdk/lib/index.lite.ts b/packages/optimizely-sdk/lib/index.lite.ts index 1910e8887..84877f941 100644 --- a/packages/optimizely-sdk/lib/index.lite.ts +++ b/packages/optimizely-sdk/lib/index.lite.ts @@ -111,3 +111,32 @@ export default { createInstance, OptimizelyDecideOption, }; + +export { + UserAttributes, + OptimizelyConfig, + OptimizelyVariable, + OptimizelyVariation, + OptimizelyExperiment, + OptimizelyFeature, + OptimizelyDecisionContext, + OptimizelyForcedDecision, + EventTags, + Event, + EventDispatcher, + DatafileOptions, + SDKOptions, + OptimizelyOptions, + UserProfileService, + UserProfile, + ListenerPayload, + OptimizelyDecision, + OptimizelyUserContext, + NotificationListener, + Config, + Client, + ActivateListenerPayload, + TrackListenerPayload, +} from './shared_types' + +export {NotificationCenter} from "./core/notification_center" diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index 2e8bcfa73..af73c932b 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -147,3 +147,32 @@ export default { createInstance, OptimizelyDecideOption, }; + +export { + UserAttributes, + OptimizelyConfig, + OptimizelyVariable, + OptimizelyVariation, + OptimizelyExperiment, + OptimizelyFeature, + OptimizelyDecisionContext, + OptimizelyForcedDecision, + EventTags, + Event, + EventDispatcher, + DatafileOptions, + SDKOptions, + OptimizelyOptions, + UserProfileService, + UserProfile, + ListenerPayload, + OptimizelyDecision, + OptimizelyUserContext, + NotificationListener, + Config, + Client, + ActivateListenerPayload, + TrackListenerPayload, +} from './shared_types' + +export {NotificationCenter} from "./core/notification_center" diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index fb0a7977e..b57e89b66 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -146,3 +146,32 @@ export default { createInstance, OptimizelyDecideOption, }; + +export { + UserAttributes, + OptimizelyConfig, + OptimizelyVariable, + OptimizelyVariation, + OptimizelyExperiment, + OptimizelyFeature, + OptimizelyDecisionContext, + OptimizelyForcedDecision, + EventTags, + Event, + EventDispatcher, + DatafileOptions, + SDKOptions, + OptimizelyOptions, + UserProfileService, + UserProfile, + ListenerPayload, + OptimizelyDecision, + OptimizelyUserContext, + NotificationListener, + Config, + Client, + ActivateListenerPayload, + TrackListenerPayload, +} from './shared_types' + +export {NotificationCenter} from "./core/notification_center" diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index d78b4a9a4..933c8ed6d 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -6,7 +6,7 @@ "main": "dist/optimizely.node.min.js", "browser": "dist/optimizely.browser.min.js", "react-native": "dist/optimizely.react_native.min.js", - "typings": "lib/index.d.ts", + "typings": "dist/index.node.d.ts", "scripts": { "clean": "rm -rf dist", "lint": "tsc --noEmit && eslint 'lib/**/*.js' 'lib/**/*.ts'", @@ -17,7 +17,7 @@ "test-umdbrowser": "npm run build-browser-umd && karma start karma.umd.conf.js --single-run", "test-karma-local": "karma start karma.local_chrome.bs.conf.js && npm run build-browser-umd && karma start karma.local_chrome.umd.conf.js", "prebuild": "npm run clean", - "build": "rollup -c && mv dist/index.lite.d.ts dist/optimizely.lite.es.d.ts && rm dist/index*.d.ts", + "build": "rollup -c && mv dist/index.lite.d.ts dist/optimizely.lite.es.d.ts", "build-browser-umd": "rollup -c --config-umd", "precover": "nyc npm test", "cover": "nyc report -r lcov", From abf00e5cbb9aee42f89506e2f746a7556005c6fc Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Fri, 18 Mar 2022 11:16:29 +0500 Subject: [PATCH 10/19] export types redundancy removed --- packages/optimizely-sdk/lib/export_types.ts | 28 ++++++++++++++++++ packages/optimizely-sdk/lib/index.browser.ts | 29 +------------------ packages/optimizely-sdk/lib/index.lite.ts | 29 +------------------ packages/optimizely-sdk/lib/index.node.ts | 29 +------------------ .../optimizely-sdk/lib/index.react_native.ts | 29 +------------------ 5 files changed, 32 insertions(+), 112 deletions(-) create mode 100644 packages/optimizely-sdk/lib/export_types.ts diff --git a/packages/optimizely-sdk/lib/export_types.ts b/packages/optimizely-sdk/lib/export_types.ts new file mode 100644 index 000000000..6b250ad4a --- /dev/null +++ b/packages/optimizely-sdk/lib/export_types.ts @@ -0,0 +1,28 @@ +export { + UserAttributes, + OptimizelyConfig, + OptimizelyVariable, + OptimizelyVariation, + OptimizelyExperiment, + OptimizelyFeature, + OptimizelyDecisionContext, + OptimizelyForcedDecision, + EventTags, + Event, + EventDispatcher, + DatafileOptions, + SDKOptions, + OptimizelyOptions, + UserProfileService, + UserProfile, + ListenerPayload, + OptimizelyDecision, + OptimizelyUserContext, + NotificationListener, + Config, + Client, + ActivateListenerPayload, + TrackListenerPayload, +} from './shared_types' + +export {NotificationCenter} from "./core/notification_center" \ No newline at end of file diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index dca31c511..294ce1f94 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -183,31 +183,4 @@ export default { OptimizelyDecideOption, }; -export { - UserAttributes, - OptimizelyConfig, - OptimizelyVariable, - OptimizelyVariation, - OptimizelyExperiment, - OptimizelyFeature, - OptimizelyDecisionContext, - OptimizelyForcedDecision, - EventTags, - Event, - EventDispatcher, - DatafileOptions, - SDKOptions, - OptimizelyOptions, - UserProfileService, - UserProfile, - ListenerPayload, - OptimizelyDecision, - OptimizelyUserContext, - NotificationListener, - Config, - Client, - ActivateListenerPayload, - TrackListenerPayload, -} from './shared_types' - -export type {NotificationCenter} from "./core/notification_center" +export * from './export_types' diff --git a/packages/optimizely-sdk/lib/index.lite.ts b/packages/optimizely-sdk/lib/index.lite.ts index 84877f941..9e425c48c 100644 --- a/packages/optimizely-sdk/lib/index.lite.ts +++ b/packages/optimizely-sdk/lib/index.lite.ts @@ -112,31 +112,4 @@ export default { OptimizelyDecideOption, }; -export { - UserAttributes, - OptimizelyConfig, - OptimizelyVariable, - OptimizelyVariation, - OptimizelyExperiment, - OptimizelyFeature, - OptimizelyDecisionContext, - OptimizelyForcedDecision, - EventTags, - Event, - EventDispatcher, - DatafileOptions, - SDKOptions, - OptimizelyOptions, - UserProfileService, - UserProfile, - ListenerPayload, - OptimizelyDecision, - OptimizelyUserContext, - NotificationListener, - Config, - Client, - ActivateListenerPayload, - TrackListenerPayload, -} from './shared_types' - -export {NotificationCenter} from "./core/notification_center" +export * from './export_types' diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index af73c932b..ce2871dfa 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -148,31 +148,4 @@ export default { OptimizelyDecideOption, }; -export { - UserAttributes, - OptimizelyConfig, - OptimizelyVariable, - OptimizelyVariation, - OptimizelyExperiment, - OptimizelyFeature, - OptimizelyDecisionContext, - OptimizelyForcedDecision, - EventTags, - Event, - EventDispatcher, - DatafileOptions, - SDKOptions, - OptimizelyOptions, - UserProfileService, - UserProfile, - ListenerPayload, - OptimizelyDecision, - OptimizelyUserContext, - NotificationListener, - Config, - Client, - ActivateListenerPayload, - TrackListenerPayload, -} from './shared_types' - -export {NotificationCenter} from "./core/notification_center" +export * from './export_types' diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index b57e89b66..c686ae070 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -147,31 +147,4 @@ export default { OptimizelyDecideOption, }; -export { - UserAttributes, - OptimizelyConfig, - OptimizelyVariable, - OptimizelyVariation, - OptimizelyExperiment, - OptimizelyFeature, - OptimizelyDecisionContext, - OptimizelyForcedDecision, - EventTags, - Event, - EventDispatcher, - DatafileOptions, - SDKOptions, - OptimizelyOptions, - UserProfileService, - UserProfile, - ListenerPayload, - OptimizelyDecision, - OptimizelyUserContext, - NotificationListener, - Config, - Client, - ActivateListenerPayload, - TrackListenerPayload, -} from './shared_types' - -export {NotificationCenter} from "./core/notification_center" +export * from './export_types' From 01c95ebf7248917cc7c369fbda2dd32b9d9346af Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Fri, 18 Mar 2022 22:00:02 +0500 Subject: [PATCH 11/19] notification center set to public --- packages/optimizely-sdk/lib/optimizely/index.ts | 2 +- packages/optimizely-sdk/lib/shared_types.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/optimizely-sdk/lib/optimizely/index.ts b/packages/optimizely-sdk/lib/optimizely/index.ts index 58bc0e712..73e581fd0 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.ts +++ b/packages/optimizely-sdk/lib/optimizely/index.ts @@ -78,10 +78,10 @@ export default class Optimizely { private errorHandler: ErrorHandler; private logger: LoggerFacade; private projectConfigManager: ProjectConfigManager; - private notificationCenter: NotificationCenter; private decisionService: DecisionService; private eventProcessor: EventProcessor; private defaultDecideOptions: { [key: string]: boolean }; + public notificationCenter: NotificationCenter; constructor(config: OptimizelyOptions) { let clientEngine = config.clientEngine; diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 125f08f4d..42bb5e501 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -266,6 +266,7 @@ export interface OptimizelyVariable { } export interface Client { + notificationCenter: NotificationCenter; createUserContext( userId: string, attributes?: UserAttributes From 50039abff6456d864123b844d4220e3c682bc6dc Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Mon, 21 Mar 2022 20:30:05 +0500 Subject: [PATCH 12/19] addNotificationListener type exported in utils package --- packages/utils/src/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index cd7dec342..232d42088 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { ListenerPayload, NotificationListener } from '@optimizely/optimizely-sdk/dist/shared_types'; import { v4 } from 'uuid'; export function generateUUID(): string { @@ -154,4 +155,8 @@ export enum NOTIFICATION_TYPES { export interface NotificationCenter { sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: any): void + addNotificationListener( + notificationType: string, + callback: NotificationListener + ): number; } From 6d9982daeb7eba8195a37a4c69ae227a2d293b25 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Tue, 22 Mar 2022 20:43:48 +0500 Subject: [PATCH 13/19] Notification changes --- packages/optimizely-sdk/lib/export_types.ts | 3 +-- packages/optimizely-sdk/lib/optimizely/index.ts | 3 ++- packages/optimizely-sdk/lib/shared_types.ts | 16 ++++++++++++++-- packages/utils/src/index.ts | 5 ----- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/optimizely-sdk/lib/export_types.ts b/packages/optimizely-sdk/lib/export_types.ts index 6b250ad4a..03e323678 100644 --- a/packages/optimizely-sdk/lib/export_types.ts +++ b/packages/optimizely-sdk/lib/export_types.ts @@ -23,6 +23,5 @@ export { Client, ActivateListenerPayload, TrackListenerPayload, + NotificationCenter } from './shared_types' - -export {NotificationCenter} from "./core/notification_center" \ No newline at end of file diff --git a/packages/optimizely-sdk/lib/optimizely/index.ts b/packages/optimizely-sdk/lib/optimizely/index.ts index 73e581fd0..4696e2d95 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.ts +++ b/packages/optimizely-sdk/lib/optimizely/index.ts @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ -import { find, sprintf, objectValues, NotificationCenter } from '@optimizely/js-sdk-utils'; +import { find, sprintf, objectValues } from '@optimizely/js-sdk-utils'; import { LoggerFacade, ErrorHandler } from '@optimizely/js-sdk-logging'; import { EventProcessor } from '@optimizely/js-sdk-event-processor'; +import {NotificationCenter} from '../core/notification_center' import { UserAttributes, diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 42bb5e501..62780c631 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -16,7 +16,8 @@ import { ErrorHandler, LogHandler, LogLevel, LoggerFacade } from '@optimizely/js-sdk-logging'; import { EventProcessor } from '@optimizely/js-sdk-event-processor'; -import { NotificationCenter } from '@optimizely/js-sdk-utils'; +import { NOTIFICATION_TYPES } from '@optimizely/js-sdk-utils'; +import {NotificationCenter as NotificationCenterImpl} from './core/notification_center' export interface BucketerParams { experimentId: string; @@ -81,6 +82,17 @@ export interface ListenerPayload { export type NotificationListener = (notificationData: T) => void; +// NotificationCenter-related types +export interface NotificationCenter { + addNotificationListener( + notificationType: string, + callback: NotificationListener + ): number; + removeNotificationListener(listenerId: number): boolean; + clearAllNotificationListeners(): void; + clearNotificationListeners(notificationType: NOTIFICATION_TYPES): void; +} + // An event to be submitted to Optimizely, enabling tracking the reach and impact of // tests and feature rollouts. export interface Event { @@ -243,7 +255,7 @@ export interface OptimizelyOptions { sdkKey?: string; userProfileService?: UserProfileService | null; defaultDecideOptions?: OptimizelyDecideOption[]; - notificationCenter: NotificationCenter; + notificationCenter: NotificationCenterImpl; } /** diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 232d42088..cd7dec342 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ListenerPayload, NotificationListener } from '@optimizely/optimizely-sdk/dist/shared_types'; import { v4 } from 'uuid'; export function generateUUID(): string { @@ -155,8 +154,4 @@ export enum NOTIFICATION_TYPES { export interface NotificationCenter { sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: any): void - addNotificationListener( - notificationType: string, - callback: NotificationListener - ): number; } From 49a5246a5c2211654c845623e09013412f4f3c51 Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Thu, 24 Mar 2022 13:23:42 +0500 Subject: [PATCH 14/19] seperate client and type for lite bundles added --- packages/optimizely-sdk/lib/index.browser.ts | 4 +-- packages/optimizely-sdk/lib/index.lite.ts | 8 +++--- packages/optimizely-sdk/lib/index.node.ts | 4 +-- .../optimizely-sdk/lib/index.react_native.ts | 4 +-- packages/optimizely-sdk/lib/shared_types.ts | 27 +++++++++++++++++++ packages/optimizely-sdk/package.json | 2 +- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index 294ce1f94..4c6c71848 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -47,8 +47,8 @@ let hasRetriedEvents = false; /** * Creates an instance of the Optimizely class - * @param {SDKOptions} config - * @return {Optimizely|null} the Optimizely object + * @param {Config} config + * @return {Client|null} the Optimizely client object * null on error */ const createInstance = function(config: Config): Client | null { diff --git a/packages/optimizely-sdk/lib/index.lite.ts b/packages/optimizely-sdk/lib/index.lite.ts index 9e425c48c..1e0e8bf15 100644 --- a/packages/optimizely-sdk/lib/index.lite.ts +++ b/packages/optimizely-sdk/lib/index.lite.ts @@ -29,7 +29,7 @@ import * as loggerPlugin from './plugins/logger'; import Optimizely from './optimizely'; import { createNotificationCenter } from './core/notification_center'; import { createForwardingEventProcessor } from './plugins/event_processor/forwarding_event_processor'; -import { OptimizelyDecideOption, Client, Config } from './shared_types'; +import { OptimizelyDecideOption, Client, ConfigLite } from './shared_types'; import { createNoOpDatafileManager } from './plugins/datafile_manager/no_op_datafile_manager'; const logger = getLogger(); @@ -38,11 +38,11 @@ setLogLevel(LogLevel.ERROR); /** * Creates an instance of the Optimizely class - * @param {SDKOptions} config - * @return {Optimizely|null} the Optimizely object + * @param {ConfigLite} config + * @return {Client|null} the Optimizely client object * null on error */ - const createInstance = function(config: Config): Client | null { + const createInstance = function(config: ConfigLite): Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index ce2871dfa..0f9cadcba 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -42,8 +42,8 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; /** * Creates an instance of the Optimizely class - * @param {SDKOptions} config - * @return {Optimizely|null} the Optimizely object + * @param {Config} config + * @return {Client|null} the Optimizely client object * null on error */ const createInstance = function(config: Config): Client | null { diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index c686ae070..d46a47a92 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -43,8 +43,8 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; /** * Creates an instance of the Optimizely class - * @param {SDKOptions} config - * @return {Optimizely|null} the Optimizely object + * @param {Config} config + * @return {Client|null} the Optimizely client object * null on error */ const createInstance = function(config: Config): Client | null { diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 62780c631..5f8ef8394 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -437,6 +437,33 @@ export interface SDKOptions { defaultDecideOptions?: OptimizelyDecideOption[]; } +/** + * Entry level Config Entities for Lite bundle + * For compatibility with the previous declaration file + */ + export interface ConfigLite { + // Datafile string + // TODO[OASIS-6649]: Don't use object type + // eslint-disable-next-line @typescript-eslint/ban-types + datafile?: object | string; + // options for Datafile Manager + datafileOptions?: DatafileOptions; + // errorHandler object for logging error + errorHandler?: ErrorHandler; + // event dispatcher function + eventDispatcher?: EventDispatcher; + // flag to validate if this instance is valid + isValidInstance?: boolean; + // level of logging i.e debug, info, error, warning etc + logLevel?: LogLevel | string; + // LogHandler object for logging + logger?: LogHandler; + // user profile that contains user information + userProfileService?: UserProfileService; + // dafault options for decide API + defaultDecideOptions?: OptimizelyDecideOption[]; +} + export type OptimizelyExperimentsMap = { [experimentKey: string]: OptimizelyExperiment; } diff --git a/packages/optimizely-sdk/package.json b/packages/optimizely-sdk/package.json index cb0740ee5..6d0f7e9e1 100644 --- a/packages/optimizely-sdk/package.json +++ b/packages/optimizely-sdk/package.json @@ -17,7 +17,7 @@ "test-umdbrowser": "npm run build-browser-umd && karma start karma.umd.conf.js --single-run", "test-karma-local": "karma start karma.local_chrome.bs.conf.js && npm run build-browser-umd && karma start karma.local_chrome.umd.conf.js", "prebuild": "npm run clean", - "build": "rollup -c && mv dist/index.lite.d.ts dist/optimizely.lite.es.d.ts", + "build": "rollup -c && cp dist/index.lite.d.ts dist/optimizely.lite.es.d.ts && cp dist/index.lite.d.ts dist/optimizely.lite.es.min.d.ts && cp dist/index.lite.d.ts dist/optimizely.lite.min.d.ts", "build-browser-umd": "rollup -c --config-umd", "precover": "nyc npm test", "cover": "nyc report -r lcov", From 331644ba44c1f7cbd493df90212a70d6fae56503 Mon Sep 17 00:00:00 2001 From: zashraf1985 Date: Thu, 24 Mar 2022 14:03:51 -0700 Subject: [PATCH 15/19] fixed some more types --- packages/optimizely-sdk/lib/export_types.ts | 1 - packages/optimizely-sdk/lib/shared_types.ts | 30 +++++---------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/packages/optimizely-sdk/lib/export_types.ts b/packages/optimizely-sdk/lib/export_types.ts index 03e323678..531e59787 100644 --- a/packages/optimizely-sdk/lib/export_types.ts +++ b/packages/optimizely-sdk/lib/export_types.ts @@ -11,7 +11,6 @@ export { Event, EventDispatcher, DatafileOptions, - SDKOptions, OptimizelyOptions, UserProfileService, UserProfile, diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index 5f8ef8394..c707c14e4 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -406,35 +406,17 @@ export interface SDKOptions { * Entry level Config Entities * For compatibility with the previous declaration file */ - export interface Config { - // Datafile string - // TODO[OASIS-6649]: Don't use object type - // eslint-disable-next-line @typescript-eslint/ban-types - datafile?: object | string; + export interface Config extends ConfigLite { // options for Datafile Manager datafileOptions?: DatafileOptions; - // errorHandler object for logging error - errorHandler?: ErrorHandler; // limit of events to dispatch in a batch eventBatchSize?: number; - // event dispatcher function - eventDispatcher?: EventDispatcher; // maximum time for an event to stay in the queue eventFlushInterval?: number; // maximum size for the event queue eventMaxQueueSize?: number; - // flag to validate if this instance is valid - isValidInstance?: boolean; - // level of logging i.e debug, info, error, warning etc - logLevel?: LogLevel | string; - // LogHandler object for logging - logger?: LogHandler; // sdk key sdkKey?: string; - // user profile that contains user information - userProfileService?: UserProfileService; - // dafault options for decide API - defaultDecideOptions?: OptimizelyDecideOption[]; } /** @@ -446,8 +428,6 @@ export interface SDKOptions { // TODO[OASIS-6649]: Don't use object type // eslint-disable-next-line @typescript-eslint/ban-types datafile?: object | string; - // options for Datafile Manager - datafileOptions?: DatafileOptions; // errorHandler object for logging error errorHandler?: ErrorHandler; // event dispatcher function @@ -462,6 +442,8 @@ export interface SDKOptions { userProfileService?: UserProfileService; // dafault options for decide API defaultDecideOptions?: OptimizelyDecideOption[]; + clientEngine?: string; + clientVersion?: string; } export type OptimizelyExperimentsMap = { @@ -539,14 +521,14 @@ export interface OptimizelyUserContext { setAttribute(key: string, value: unknown): void; decide( key: string, - options: OptimizelyDecideOption[] + options?: OptimizelyDecideOption[] ): OptimizelyDecision; decideForKeys( keys: string[], - options: OptimizelyDecideOption[], + options?: OptimizelyDecideOption[], ): { [key: string]: OptimizelyDecision }; decideAll( - options: OptimizelyDecideOption[], + options?: OptimizelyDecideOption[], ): { [key: string]: OptimizelyDecision }; trackEvent(eventName: string, eventTags?: EventTags): void; setForcedDecision(context: OptimizelyDecisionContext, decision: OptimizelyForcedDecision): boolean; From 72430fffa4dbe0f070b76fed26b3a301352ee1d8 Mon Sep 17 00:00:00 2001 From: zashraf1985 Date: Thu, 24 Mar 2022 14:16:30 -0700 Subject: [PATCH 16/19] - removed unneeded SDKOptions interface - fixed some lint warnings - Added changelog --- packages/optimizely-sdk/CHANGELOG.md | 5 +-- .../optimizely-sdk/lib/optimizely/index.ts | 3 +- .../lib/optimizely_user_context/index.ts | 8 +---- packages/optimizely-sdk/lib/shared_types.ts | 34 ------------------- 4 files changed, 5 insertions(+), 45 deletions(-) diff --git a/packages/optimizely-sdk/CHANGELOG.md b/packages/optimizely-sdk/CHANGELOG.md index 0fc8b8d25..0c7981edc 100644 --- a/packages/optimizely-sdk/CHANGELOG.md +++ b/packages/optimizely-sdk/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Add package.json script for running Karma tests locally using Chrome ([#651](https://github.com/optimizely/javascript-sdk/pull/651)). +- Replaced explicit typescript typings with auto generated ones ([#745](https://github.com/optimizely/javascript-sdk/pull/745)) ## [4.9.1] - January 18, 2022 @@ -18,13 +19,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [4.9.0] - January 14, 2022 ### New Features -* Add a set of new APIs for overriding and managing user-level flag, experiment and delivery rule decisions. These methods can be used for QA and automated testing purposes. They are an extension of the OptimizelyUserContext interface ([#705](https://github.com/optimizely/javascript-sdk/pull/705), [#727](https://github.com/optimizely/javascript-sdk/pull/727), [#729](https://github.com/optimizely/javascript-sdk/pull/729), [#730](https://github.com/optimizely/javascript-sdk/pull/730)): +- Add a set of new APIs for overriding and managing user-level flag, experiment and delivery rule decisions. These methods can be used for QA and automated testing purposes. They are an extension of the OptimizelyUserContext interface ([#705](https://github.com/optimizely/javascript-sdk/pull/705), [#727](https://github.com/optimizely/javascript-sdk/pull/727), [#729](https://github.com/optimizely/javascript-sdk/pull/729), [#730](https://github.com/optimizely/javascript-sdk/pull/730)): - setForcedDecision - getForcedDecision - removeForcedDecision - removeAllForcedDecisions -* For details, refer to our documentation pages: [OptimizelyUserContext](https://docs.developers.optimizely.com/full-stack/v4.0/docs/optimizelyusercontext-javascript-node) and [Forced Decision methods](https://docs.developers.optimizely.com/full-stack/v4.0/docs/forced-decision-methods-javascript-node). +- For details, refer to our documentation pages: [OptimizelyUserContext](https://docs.developers.optimizely.com/full-stack/v4.0/docs/optimizelyusercontext-javascript-node) and [Forced Decision methods](https://docs.developers.optimizely.com/full-stack/v4.0/docs/forced-decision-methods-javascript-node). ## [4.8.0] - November 29, 2021 diff --git a/packages/optimizely-sdk/lib/optimizely/index.ts b/packages/optimizely-sdk/lib/optimizely/index.ts index 4696e2d95..f677e418d 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.ts +++ b/packages/optimizely-sdk/lib/optimizely/index.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ -import { find, sprintf, objectValues } from '@optimizely/js-sdk-utils'; +import { sprintf, objectValues } from '@optimizely/js-sdk-utils'; import { LoggerFacade, ErrorHandler } from '@optimizely/js-sdk-logging'; import { EventProcessor } from '@optimizely/js-sdk-event-processor'; import {NotificationCenter} from '../core/notification_center' @@ -27,7 +27,6 @@ import { Variation, FeatureFlag, FeatureVariable, - OptimizelyVariation, OptimizelyOptions, OptimizelyDecideOption, OptimizelyDecision diff --git a/packages/optimizely-sdk/lib/optimizely_user_context/index.ts b/packages/optimizely-sdk/lib/optimizely_user_context/index.ts index 2fcf78238..7ab5f0a22 100644 --- a/packages/optimizely-sdk/lib/optimizely_user_context/index.ts +++ b/packages/optimizely-sdk/lib/optimizely_user_context/index.ts @@ -15,20 +15,14 @@ ***************************************************************************/ import Optimizely from '../../lib/optimizely'; import { - DecisionResponse, EventTags, OptimizelyDecideOption, OptimizelyDecision, OptimizelyDecisionContext, OptimizelyForcedDecision, UserAttributes, - Variation } from '../../lib/shared_types'; -import { - getFlagVariationByKey, - ProjectConfig, -} from '../core/project_config'; -import { LOG_MESSAGES, CONTROL_ATTRIBUTES } from '../utils/enums'; +import { CONTROL_ATTRIBUTES } from '../utils/enums'; export default class OptimizelyUserContext { private optimizely: Optimizely; diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index c707c14e4..e0e9b2f34 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -368,40 +368,6 @@ export interface TrackListenerPayload extends ListenerPayload { logEvent: Event; } -/** - * Entry level Config Entities - */ -export interface SDKOptions { - // Datafile string - // TODO[OASIS-6649]: Don't use object type - // eslint-disable-next-line @typescript-eslint/ban-types - datafile?: object | string; - // options for Datafile Manager - datafileOptions?: DatafileOptions; - // errorHandler object for logging error - errorHandler?: ErrorHandler; - // limit of events to dispatch in a batch - eventBatchSize?: number; - // event dispatcher function - eventDispatcher?: EventDispatcher; - // maximum time for an event to stay in the queue - eventFlushInterval?: number; - // maximum size for the event queue - eventMaxQueueSize?: number; - // flag to validate if this instance is valid - isValidInstance?: boolean; - // level of logging i.e debug, info, error, warning etc - logLevel?: LogLevel | string; - // LogHandler object for logging - logger?: LogHandler; - // sdk key - sdkKey?: string; - // user profile that contains user information - userProfileService?: UserProfileService; - // dafault options for decide API - defaultDecideOptions?: OptimizelyDecideOption[]; -} - /** * Entry level Config Entities * For compatibility with the previous declaration file From 90e41497dd8c6f154dcde8ecbd2b9d167673bf1b Mon Sep 17 00:00:00 2001 From: zashraf1985 Date: Thu, 24 Mar 2022 16:19:26 -0700 Subject: [PATCH 17/19] trying to fix testapp --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4d4da030d..e14589d3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: global: - SDK=javascript - SDK_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH + - TESTAPP_BRANCH=zeeshan/fix-types before_install: cd packages/optimizely-sdk install: npm install script: npm test From b1a6e11502715e34dacab63dbc9d1b5ce87c096d Mon Sep 17 00:00:00 2001 From: zashraf1985 Date: Thu, 24 Mar 2022 16:51:42 -0700 Subject: [PATCH 18/19] Revert "trying to fix testapp" This reverts commit 90e41497dd8c6f154dcde8ecbd2b9d167673bf1b. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e14589d3e..4d4da030d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ env: global: - SDK=javascript - SDK_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH - - TESTAPP_BRANCH=zeeshan/fix-types before_install: cd packages/optimizely-sdk install: npm install script: npm test From 10fcd43ce3b935ff53501bef735f62b6b811bd1d Mon Sep 17 00:00:00 2001 From: ozayr-zaviar Date: Thu, 7 Apr 2022 17:46:04 +0500 Subject: [PATCH 19/19] comments addressed --- .../lib/core/project_config/index.ts | 2 +- .../core/project_config/project_config_manager.ts | 2 +- packages/optimizely-sdk/lib/export_types.ts | 15 +++++++++++++++ packages/optimizely-sdk/lib/index.browser.ts | 9 +++++---- packages/optimizely-sdk/lib/index.lite.ts | 9 +++++---- packages/optimizely-sdk/lib/index.node.ts | 8 ++++---- packages/optimizely-sdk/lib/index.react_native.ts | 9 +++++---- .../http_polling_datafile_manager.ts | 2 +- .../lib/plugins/event_dispatcher/index.browser.ts | 2 +- packages/optimizely-sdk/lib/shared_types.ts | 6 ++++-- 10 files changed, 42 insertions(+), 22 deletions(-) diff --git a/packages/optimizely-sdk/lib/core/project_config/index.ts b/packages/optimizely-sdk/lib/core/project_config/index.ts index 89599b766..625838811 100644 --- a/packages/optimizely-sdk/lib/core/project_config/index.ts +++ b/packages/optimizely-sdk/lib/core/project_config/index.ts @@ -1,5 +1,5 @@ /** - * Copyright 2016-2021, Optimizely + * Copyright 2016-2022, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts index 2cec65a4e..861052670 100644 --- a/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts +++ b/packages/optimizely-sdk/lib/core/project_config/project_config_manager.ts @@ -1,5 +1,5 @@ /** - * Copyright 2019-2021, Optimizely + * Copyright 2019-2022, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/packages/optimizely-sdk/lib/export_types.ts b/packages/optimizely-sdk/lib/export_types.ts index 531e59787..17d307ae8 100644 --- a/packages/optimizely-sdk/lib/export_types.ts +++ b/packages/optimizely-sdk/lib/export_types.ts @@ -1,3 +1,18 @@ +/** + * Copyright 2022, 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 { UserAttributes, OptimizelyConfig, diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index 4c6c71848..7411fc22a 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017, 2019-2020 Optimizely + * Copyright 2016-2017, 2019-2022 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,8 @@ let hasRetriedEvents = false; const createInstance = function(config: Config): Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel + let isValidInstance = false + if (config.errorHandler) { setErrorHandler(config.errorHandler); } @@ -68,10 +70,9 @@ const createInstance = function(config: Config): Client | null { try { configValidator.validate(config); - config.isValidInstance = true; + isValidInstance = true; } catch (ex) { logger.error(ex); - config.isValidInstance = false; } let eventDispatcher; @@ -125,7 +126,7 @@ const createInstance = function(config: Config): Client | null { errorHandler, datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined, notificationCenter, - isValidInstance: config.isValidInstance + isValidInstance: isValidInstance }; const optimizely = new Optimizely(optimizelyOptions); diff --git a/packages/optimizely-sdk/lib/index.lite.ts b/packages/optimizely-sdk/lib/index.lite.ts index 1e0e8bf15..3e46b8878 100644 --- a/packages/optimizely-sdk/lib/index.lite.ts +++ b/packages/optimizely-sdk/lib/index.lite.ts @@ -1,5 +1,5 @@ /** - * Copyright 2021, Optimizely + * Copyright 2021-2022, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,8 @@ setLogLevel(LogLevel.ERROR); try { // TODO warn about setting per instance errorHandler / logger / logLevel + let isValidInstance = false; + if (config.errorHandler) { setErrorHandler(config.errorHandler); } @@ -60,10 +62,9 @@ setLogLevel(LogLevel.ERROR); try { configValidator.validate(config); - config.isValidInstance = true; + isValidInstance = true; } catch (ex) { logger.error(ex); - config.isValidInstance = false; } const errorHandler = getErrorHandler(); @@ -79,7 +80,7 @@ setLogLevel(LogLevel.ERROR); datafileManager: createNoOpDatafileManager(), eventProcessor, notificationCenter, - isValidInstance: config.isValidInstance, + isValidInstance: isValidInstance, }; const optimizely = new Optimizely(optimizelyOptions); diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index 0f9cadcba..6c1a71f20 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2017, 2019-2021 Optimizely, Inc. and contributors * + * Copyright 2016-2017, 2019-2022 Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -49,6 +49,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; const createInstance = function(config: Config): Client | null { try { let hasLogger = false; + let isValidInstance = false; // TODO warn about setting per instance errorHandler / logger / logLevel if (config.errorHandler) { @@ -66,14 +67,13 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; } try { configValidator.validate(config); - config.isValidInstance = true; + isValidInstance = true; } catch (ex) { if (hasLogger) { logger.error(ex); } else { console.error(ex.message); } - config.isValidInstance = false; } let eventBatchSize = config.eventBatchSize; @@ -113,7 +113,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; errorHandler, datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined, notificationCenter, - isValidInstance: config.isValidInstance, + isValidInstance: isValidInstance, }; return new Optimizely(optimizelyOptions); diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index d46a47a92..67f7f46be 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -1,5 +1,5 @@ /** - * Copyright 2019-2021 Optimizely + * Copyright 2019-2022 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,8 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; const createInstance = function(config: Config): Client | null { try { // TODO warn about setting per instance errorHandler / logger / logLevel + let isValidInstance = false; + if (config.errorHandler) { setErrorHandler(config.errorHandler); } @@ -64,10 +66,9 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; try { configValidator.validate(config); - config.isValidInstance = true; + isValidInstance = true; } catch (ex) { logger.error(ex); - config.isValidInstance = false; } let eventBatchSize = config.eventBatchSize; @@ -107,7 +108,7 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; errorHandler, datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined, notificationCenter, - isValidInstance: config.isValidInstance, + isValidInstance: isValidInstance, }; // If client engine is react, convert it to react native. diff --git a/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts b/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts index 925cead7f..42f993145 100644 --- a/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts +++ b/packages/optimizely-sdk/lib/plugins/datafile_manager/http_polling_datafile_manager.ts @@ -1,5 +1,5 @@ /** - * Copyright 2021, Optimizely + * Copyright 2021-2022, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts b/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts index 1f2b777b1..9f0da6d0a 100644 --- a/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts +++ b/packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.ts @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017, 2020-2021, Optimizely + * Copyright 2016-2017, 2020-2022, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/packages/optimizely-sdk/lib/shared_types.ts b/packages/optimizely-sdk/lib/shared_types.ts index e0e9b2f34..de4c23bbe 100644 --- a/packages/optimizely-sdk/lib/shared_types.ts +++ b/packages/optimizely-sdk/lib/shared_types.ts @@ -398,8 +398,10 @@ export interface TrackListenerPayload extends ListenerPayload { errorHandler?: ErrorHandler; // event dispatcher function eventDispatcher?: EventDispatcher; - // flag to validate if this instance is valid - isValidInstance?: boolean; + // The object to validate against the schema + jsonSchemaValidator?: { + validate(jsonObject: unknown): boolean, + }; // level of logging i.e debug, info, error, warning etc logLevel?: LogLevel | string; // LogHandler object for logging