Skip to content

feat: Convert user_profile_service_validator module to TS #526

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
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
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { buildConversionEvent, buildImpressionEvent } from '../core/event_builde
import eventTagsValidator from '../utils/event_tags_validator';
import notificationCenter from '../core/notification_center';
import projectConfig from '../core/project_config';
import userProfileServiceValidator from '../utils/user_profile_service_validator';
import * as userProfileServiceValidator from '../utils/user_profile_service_validator';
import * as stringValidator from '../utils/string_value_validator';
import projectConfigManager from '../core/project_config/project_config_manager';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@
import { sprintf } from '@optimizely/js-sdk-utils';

import { ERROR_MESSAGES } from '../enums';
var MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR';

const MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR';

/**
* Validates user's provided user profile service instance
* @param {Object} userProfileServiceInstance
* @return {boolean} True if the instance is valid
* @param {object} userProfileServiceInstance
* @return {boolean} true if the instance is valid
* @throws If the instance is not valid
*/
export var validate = function(userProfileServiceInstance) {
export function validate(userProfileServiceInstance: Record<string, unknown>): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be a Record! We should define an interface for UserProfileService instead

Copy link
Contributor Author

@yavorona yavorona Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserProfileService interface has been declared in index.d.ts, so I tried importing it with
{ UserProfileService } from '@optimizely/optimizely-sdk' and import { UserProfileService } from '../../index', which did not work. Any suggestions on how to import it would be much appreciated! @mjc1283 @mikeng13

if (typeof userProfileServiceInstance.lookup !== 'function') {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'lookup'"));
} else if (typeof userProfileServiceInstance.save !== 'function') {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'save'"));
}
return true;
};

export default {
validate: validate,
};
}