Skip to content

Commit

Permalink
[FSSDK-10198] making isOdpIntegrated public (#930)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Mike Chu <[email protected]>
  • Loading branch information
junaed-optimizely and mikechu-optimizely authored May 20, 2024
1 parent 43fea02 commit 01b50a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
17 changes: 8 additions & 9 deletions lib/core/odp/odp_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export abstract class OdpManager implements IOdpManager {
* Promise that returns when the OdpManager is finished initializing
*/
private initPromise: Promise<unknown>;

private ready = false;

/**
Expand Down Expand Up @@ -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();
}
});
Expand All @@ -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) {
Expand Down Expand Up @@ -211,21 +210,21 @@ export abstract class OdpManager implements IOdpManager {
* @returns {Promise<string[] | null>} A promise holding either a list of qualified segments or null.
*/
async fetchQualifiedSegments(userId: string, options: Array<OptimizelySegmentOption> = []): Promise<string[] | null> {
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;
}

if (VuidManager.isVuid(userId)) {
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);
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
19 changes: 9 additions & 10 deletions lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1671,7 +1667,7 @@ export default class Optimizely implements Client {
}

if (this.odpManager) {
this.odpManager.updateSettings(projectConfig.odpIntegrationConfig)
this.odpManager.updateSettings(projectConfig.odpIntegrationConfig);
}
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -1751,7 +1750,7 @@ export default class Optimizely implements Client {
if (!this.odpManager) {
return null;
}

return await this.odpManager.fetchQualifiedSegments(userId, options);
}

Expand Down
8 changes: 7 additions & 1 deletion lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -371,6 +376,7 @@ export interface Client {
close(): Promise<{ success: boolean; reason?: string }>;
sendOdpEvent(action: string, type?: string, identifiers?: Map<string, string>, data?: Map<string, unknown>): void;
getProjectConfig(): ProjectConfig | null;
isOdpIntegrated(): boolean;
}

export interface ActivateListenerPayload extends ListenerPayload {
Expand Down

0 comments on commit 01b50a2

Please sign in to comment.