@@ -26,17 +26,19 @@ const MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR';
26
26
27
27
/**
28
28
* Validates user's provided user profile service instance
29
- * @param {object } userProfileServiceInstance
29
+ * @param {unknown } userProfileServiceInstance
30
30
* @return {boolean } true if the instance is valid
31
31
* @throws If the instance is not valid
32
32
*/
33
33
34
- //TODO: Use defined UserProfileService interface instead of 'Record<string, unknown>'
35
- export function validate ( userProfileServiceInstance : Record < string , unknown > ) : boolean {
36
- if ( typeof userProfileServiceInstance . lookup !== 'function' ) {
37
- throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME , "Missing function 'lookup'" ) ) ;
38
- } else if ( typeof userProfileServiceInstance . save !== 'function' ) {
39
- throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME , "Missing function 'save'" ) ) ;
34
+ export function validate ( userProfileServiceInstance : unknown ) : boolean {
35
+ if ( typeof userProfileServiceInstance === 'object' && userProfileServiceInstance !== null ) {
36
+ if ( typeof userProfileServiceInstance [ 'lookup' ] !== 'function' ) {
37
+ throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME , "Missing function 'lookup'" ) ) ;
38
+ } else if ( typeof userProfileServiceInstance [ 'save' ] !== 'function' ) {
39
+ throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME , "Missing function 'save'" ) ) ;
40
+ }
41
+ return true ;
40
42
}
41
- return true ;
43
+ throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME ) ) ;
42
44
}
0 commit comments