File tree Expand file tree Collapse file tree 3 files changed +16
-16
lines changed
packages/optimizely-sdk/lib
user_profile_service_validator Expand file tree Collapse file tree 3 files changed +16
-16
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import decisionService from '../core/decision_service';
22
22
import enums from '../utils/enums' ;
23
23
import { getImpressionEvent , getConversionEvent } from '../core/event_builder/index.js' ;
24
24
import { buildConversionEvent , buildImpressionEvent } from '../core/event_builder/event_helpers' ;
25
- import eventTagsValidator from '../utils/event_tags_validator' ;
25
+ import * as eventTagsValidator from '../utils/event_tags_validator' ;
26
26
import notificationCenter from '../core/notification_center' ;
27
27
import projectConfig from '../core/project_config' ;
28
28
import * as userProfileServiceValidator from '../utils/user_profile_service_validator' ;
Original file line number Diff line number Diff line change @@ -21,22 +21,18 @@ import { sprintf } from '@optimizely/js-sdk-utils';
21
21
22
22
import { ERROR_MESSAGES } from '../enums' ;
23
23
24
- var MODULE_NAME = 'EVENT_TAGS_VALIDATOR' ;
24
+ const MODULE_NAME = 'EVENT_TAGS_VALIDATOR' ;
25
25
26
26
/**
27
27
* Validates user's provided event tags
28
- * @param {Object } event tags
29
- * @return {boolean } True if event tags are valid
28
+ * @param {unknown } eventTags
29
+ * @return {boolean } true if event tags are valid
30
30
* @throws If event tags are not valid
31
31
*/
32
- export var validate = function ( eventTags ) {
32
+ export function validate ( eventTags : unknown ) : boolean {
33
33
if ( typeof eventTags === 'object' && ! Array . isArray ( eventTags ) && eventTags !== null ) {
34
34
return true ;
35
35
} else {
36
36
throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_EVENT_TAGS , MODULE_NAME ) ) ;
37
37
}
38
38
}
39
-
40
- export default {
41
- validate : validate ,
42
- }
Original file line number Diff line number Diff line change @@ -26,15 +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
- export function validate ( userProfileServiceInstance : Record < string , unknown > ) : boolean {
34
- if ( typeof userProfileServiceInstance . lookup !== 'function' ) {
35
- throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME , "Missing function 'lookup'" ) ) ;
36
- } else if ( typeof userProfileServiceInstance . save !== 'function' ) {
37
- throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME , "Missing function 'save'" ) ) ;
33
+
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 ;
38
42
}
39
- return true ;
43
+ throw new Error ( sprintf ( ERROR_MESSAGES . INVALID_USER_PROFILE_SERVICE , MODULE_NAME ) ) ;
40
44
}
You can’t perform that action at this time.
0 commit comments