From 01b50a2c50da24258105225d4802b09d7b704415 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Mon, 20 May 2024 22:06:53 +0600 Subject: [PATCH] [FSSDK-10198] making isOdpIntegrated public (#930) * odp not integrated log level change from error to info * odp not integrated log level back to prev state, except identifyUser * making isOdpIntegrated public * Adding JSDoc to newly exposed isODPIntegrated method * registerVuid method ODP integration log change from error to info * Update lib/optimizely/index.ts Co-authored-by: Mike Chu <104384559+mikechu-optimizely@users.noreply.github.com> --------- Co-authored-by: Mike Chu <104384559+mikechu-optimizely@users.noreply.github.com> --- lib/core/odp/odp_manager.ts | 17 ++++++++--------- lib/optimizely/index.ts | 19 +++++++++---------- lib/shared_types.ts | 8 +++++++- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/core/odp/odp_manager.ts b/lib/core/odp/odp_manager.ts index 4da2f6191..54278358d 100644 --- a/lib/core/odp/odp_manager.ts +++ b/lib/core/odp/odp_manager.ts @@ -65,7 +65,6 @@ export abstract class OdpManager implements IOdpManager { * Promise that returns when the OdpManager is finished initializing */ private initPromise: Promise; - private ready = false; /** @@ -126,7 +125,7 @@ export abstract class OdpManager implements IOdpManager { this.onReady().then(() => { this.ready = true; - if(this.isVuidEnabled() && this.status === Status.Running) { + if (this.isVuidEnabled() && this.status === Status.Running) { this.registerVuid(); } }); @@ -146,7 +145,7 @@ export abstract class OdpManager implements IOdpManager { } if (!this.odpIntegrationConfig) { - return Promise.reject(new Error('cannot start without ODP config')); + return Promise.reject(new Error('cannot start without ODP config')); } if (!this.odpIntegrationConfig.integrated) { @@ -211,13 +210,13 @@ export abstract class OdpManager implements IOdpManager { * @returns {Promise} A promise holding either a list of qualified segments or null. */ async fetchQualifiedSegments(userId: string, options: Array = []): Promise { - if (!this.odpIntegrationConfig) { - this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE); + if (!this.odpIntegrationConfig) { + this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE); return null; } if (!this.odpIntegrationConfig.integrated) { - this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_NOT_INTEGRATED); + this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_NOT_INTEGRATED); return null; } @@ -225,7 +224,7 @@ export abstract class OdpManager implements IOdpManager { return this.segmentManager.fetchQualifiedSegments(ODP_USER_KEY.VUID, userId, options); } - return this.segmentManager.fetchQualifiedSegments(ODP_USER_KEY.FS_USER_ID, userId, options); + return this.segmentManager.fetchQualifiedSegments(ODP_USER_KEY.FS_USER_ID, userId, options); } /** @@ -241,7 +240,7 @@ export abstract class OdpManager implements IOdpManager { } if (!this.odpIntegrationConfig.integrated) { - this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_NOT_INTEGRATED); + this.logger.log(LogLevel.INFO, ERROR_MESSAGES.ODP_NOT_INTEGRATED); return; } @@ -306,7 +305,7 @@ export abstract class OdpManager implements IOdpManager { } if (!this.odpIntegrationConfig.integrated) { - this.logger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_NOT_INTEGRATED); + this.logger.log(LogLevel.INFO, ERROR_MESSAGES.ODP_NOT_INTEGRATED); return; } diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index e29d04daa..2a3eb5a0d 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -188,9 +188,8 @@ export default class Optimizely implements Client { this.nextReadyTimeoutId = 0; } - /** - * Returns the project configuration retrieved from projectConfigManager + * Returns the project configuration retrieved from projectConfigManager * @return {projectConfig.ProjectConfig} */ getProjectConfig(): projectConfig.ProjectConfig | null { @@ -1444,10 +1443,7 @@ export default class Optimizely implements Client { createUserContext(userId?: string, attributes?: UserAttributes): OptimizelyUserContext | null { const userIdentifier = userId ?? this.odpManager?.getVuid(); - if ( - userIdentifier === undefined || - !this.validateInputs({ user_id: userIdentifier }, attributes) - ) { + if (userIdentifier === undefined || !this.validateInputs({ user_id: userIdentifier }, attributes)) { return null; } @@ -1671,7 +1667,7 @@ export default class Optimizely implements Client { } if (this.odpManager) { - this.odpManager.updateSettings(projectConfig.odpIntegrationConfig) + this.odpManager.updateSettings(projectConfig.odpIntegrationConfig); } } @@ -1722,8 +1718,11 @@ export default class Optimizely implements Client { this.logger.error(ERROR_MESSAGES.ODP_EVENT_FAILED, e); } } - - private isOdpIntegrated(): boolean { + /** + * Checks if ODP (Optimizely Data Platform) is integrated into the project. + * @returns { boolean } `true` if ODP settings were found in the datafile otherwise `false` + */ + public isOdpIntegrated(): boolean { return this.projectConfigManager.getConfig()?.odpIntegrationConfig?.integrated ?? false; } @@ -1751,7 +1750,7 @@ export default class Optimizely implements Client { if (!this.odpManager) { return null; } - + return await this.odpManager.fetchQualifiedSegments(userId, options); } diff --git a/lib/shared_types.ts b/lib/shared_types.ts index 361f293d5..08291ecf2 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -335,7 +335,12 @@ export interface Client { 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): FeatureVariableValue; + getFeatureVariable( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): FeatureVariableValue; getFeatureVariableBoolean( featureKey: string, variableKey: string, @@ -371,6 +376,7 @@ export interface Client { close(): Promise<{ success: boolean; reason?: string }>; sendOdpEvent(action: string, type?: string, identifiers?: Map, data?: Map): void; getProjectConfig(): ProjectConfig | null; + isOdpIntegrated(): boolean; } export interface ActivateListenerPayload extends ListenerPayload {