8000 feat: Added project_config_manager interface by yavorona · Pull Request #572 · optimizely/javascript-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: Added project_config_manager interface #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright 2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare module '@optimizely/optimizely-sdk/lib/core/projet_config_manager' {
import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config';

/**
* ProjectConfigManager provides project config objects via its methods
* getConfig and onUpdate. It uses a DatafileManager to fetch datafiles. It is
* responsible for parsing and validating datafiles, and converting datafile
* JSON objects into project config objects.
* @param {ProjectConfig} config
* @param {Object|string} config.datafile
* @param {Object} config.datafileOptions
* @param {Object} config.jsonSchemaValidator
* @param {string} config.sdkKey
*/
export function ProjectConfigManager(config: ProjectConfig): ProjectConfigManager;

interface ProjectConfigManager {

/**
* Returns the current project config object, or null if no project config object
* is available
* @return {ProjectConfig|null}
*/
getConfig(): ProjectConfig | null;

/**
* Add a listener for project config updates. The listener will be called
* whenever this instance has a new project config object available.
* Returns a dispose function that removes the subscription
* @param {Function} listener
* @return {Function}
*/
onUpdate(): (listener: (config: ProjectConfig) => void) => () => void;

/**
* Returns a Promise that fulfills when this ProjectConfigManager is ready to
* use (meaning it has a valid project config object), or has failed to become
* ready.
*
* Failure can be caused by the following:
* - At least one of sdkKey or datafile is not provided in the constructor argument
* - The provided datafile was invalid
* - The datafile provided by the datafile manager was invalid
* - The datafile manager failed to fetch a datafile
*
* The returned Promise is fulfilled with a result object containing these
* properties:
* - success (boolean): True if this instance is ready to use with a valid
* project config object, or false if it failed to
* become ready
* - reason (string=): If success is false, this is a string property with
* an explanatory message.
* @return {Promise}
*/
onReady(): Promise<{ success: boolean; reason?: string }>;

/**
* Returns the optimizely config object
* @return {OptimizelyConfig}
*/
getOptimizelyConfig(): import('../../shared_types').OptimizelyConfig;

/**
* Stop the internal datafile manager and remove all update listeners
* @return {void}
*/
stop(): void;
}
}
51 changes: 1 addition & 50 deletions packages/optimizely-sdk/lib/index.d.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ declare module '@optimizely/optimizely-sdk' {
userId: string,
attributes?: import('./shared_types').UserAttributes
): { [variableKey: string]: unknown };
getOptimizelyConfig(): OptimizelyConfig | null;
getOptimizelyConfig(): import('./shared_types').OptimizelyConfig | null;
onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>;
close(): Promise<{ success: boolean; reason?: string }>;
}
Expand Down Expand Up @@ -193,55 +193,6 @@ declare module '@optimizely/optimizely-sdk' {
eventTags: EventTags;
logEvent: Event;
}

/**
* Optimizely Config Entities
*/
export interface OptimizelyVariable {
id: string;
key: string;
type: string;
value: string;
}

export interface OptimizelyVariation {
id: string;
key: string;
featureEnabled?: boolean;
variablesMap: {
[variableKey: string]: OptimizelyVariable;
};
}

export interface OptimizelyExperiment {
id: string;
key: string;
variationsMap: {
[variationKey: string]: OptimizelyVariation;
};
}

export interface OptimizelyFeature {
id: string;
key: string;
experimentsMap: {
[experimentKey: string]: OptimizelyExperiment;
};
variablesMap: {
[variableKey: string]: OptimizelyVariable;
};
}

export interface OptimizelyConfig {
experimentsMap: {
[experimentKey: string]: OptimizelyExperiment;
};
featuresMap: {
[featureKey: string]: OptimizelyFeature;
};
revision: string;
getDatafile(): string;
}
}

declare module '@optimizely/optimizely-sdk/lib/utils/enums' {
Expand Down
49 changes: 49 additions & 0 deletions packages/optimizely-sdk/lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,52 @@ export interface UserProfileService {
lookup(userId: string): UserProfile;
save(profile: UserProfile): void;
}

export interface OptimizelyExperiment {
id: string;
key: string;
variationsMap: {
[variationKey: string]: OptimizelyVariation;
};
}

/**
* Optimizely Config Entities
*/
export interface OptimizelyVariable {
id: string;
key: string;
type: string;
value: string;
}

export interface OptimizelyFeature {
id: string;
key: string;
experimentsMap: {
[experimentKey: string]: OptimizelyExperiment;
};
variablesMap: {
[variableKey: string]: OptimizelyVariable;
};
}

export interface OptimizelyVariation {
id: string;
key: string;
featureEnabled?: boolean;
variablesMap: {
[variableKey: string]: OptimizelyVariable;
};
}

export interface OptimizelyConfig {
experimentsMap: {
[experimentKey: string]: OptimizelyExperiment;
};
featuresMap: {
[featureKey: string]: OptimizelyFeature;
};
revision: string;
getDatafile(): string;
}
0