From 85bd3d0cbcc215c7aa72f1a305ad1e52cd839bf4 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Mon, 13 Apr 2020 14:42:53 +0500 Subject: [PATCH 01/11] converted fns --- .../lib/optimizely/index.tests.js | 2 +- .../optimizely-sdk/lib/utils/fns/index.js | 98 +++++++++++-------- .../lib/utils/fns/index.tests.js | 7 +- 3 files changed, 61 insertions(+), 46 deletions(-) diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index 917820493..e3268f345 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -29,7 +29,7 @@ import enums from '../utils/enums'; import eventBuilder from '../core/event_builder/index.js'; import eventDispatcher from '../plugins/event_dispatcher/index.node'; import errorHandler from '../plugins/error_handler'; -import fns from '../utils/fns'; +import * as fns from '../utils/fns'; import logger from '../plugins/logger'; import decisionService from '../core/decision_service'; import jsonSchemaValidator from '../utils/json_schema_validator'; diff --git a/packages/optimizely-sdk/lib/utils/fns/index.js b/packages/optimizely-sdk/lib/utils/fns/index.js index 3483019eb..aa3c6fe48 100644 --- a/packages/optimizely-sdk/lib/utils/fns/index.js +++ b/packages/optimizely-sdk/lib/utils/fns/index.js @@ -1,5 +1,5 @@ /** - * Copyright 2017, 2019-2020, Optimizely + * Copyright 2017, 2019-2020 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,48 +13,64 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var uuid = require('uuid'); +import { keyBy as keyByUtil } from '@optimizely/js-sdk-utils'; + +import uid from 'uuid'; + var MAX_SAFE_INTEGER_LIMIT = Math.pow(2, 53); -var keyBy = require('@optimizely/js-sdk-utils').keyBy; -module.exports = { - assign: function(target) { - if (!target) { - return {}; - } - if (typeof Object.assign === 'function') { - return Object.assign.apply(Object, arguments); - } else { - var to = Object(target); - for (var index = 1; index < arguments.length; index++) { - var nextSource = arguments[index]; - if (nextSource !== null && nextSource !== undefined) { - for (var nextKey in nextSource) { - // Avoid bugs when hasOwnProperty is shadowed - if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { - to[nextKey] = nextSource[nextKey]; - } + +export var assign = function(target) { + if (!target) { + return {}; + } + if (typeof Object.assign === 'function') { + return Object.assign.apply(Object, arguments); + } else { + var to = Object(target); + for (var index = 1; index < arguments.length; index++) { + var nextSource = arguments[index]; + if (nextSource !== null && nextSource !== undefined) { + for (var nextKey in nextSource) { + // Avoid bugs when hasOwnProperty is shadowed + if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { + to[nextKey] = nextSource[nextKey]; } } } - return to; } - }, - currentTimestamp: function() { - return Math.round(new Date().getTime()); - }, - isSafeInteger: function(number) { - return typeof number == 'number' && Math.abs(number) <= MAX_SAFE_INTEGER_LIMIT; - }, - keyBy: function(arr, key) { - if (!arr) return {}; - return keyBy(arr, function(item) { - return item[key]; - }); - }, - uuid: function() { - return uuid.v4(); - }, - isNumber: function(value) { - return typeof value === 'number'; - }, -}; + return to; + } +} + +export var currentTimestamp = function() { + console.log('Calling Actual Method'); + return Math.round(new Date().getTime()); +} + +export var isSafeInteger = function(number) { + return typeof number == 'number' && Math.abs(number) <= MAX_SAFE_INTEGER_LIMIT; +} + +export var keyBy = function(arr, key) { + if (!arr) return {}; + return keyByUtil(arr, function(item) { + return item[key]; + }); +} + +export var uuid = function() { + return uid.v4(); +} + +export var isNumber = function(value) { + return typeof value === 'number'; +} + +export default { + assign: assign, + currentTimestamp: currentTimestamp, + isSafeInteger: isSafeInteger, + keyBy: keyBy, + uuid: uuid, + isNumber: isNumber, +} diff --git a/packages/optimizely-sdk/lib/utils/fns/index.tests.js b/packages/optimizely-sdk/lib/utils/fns/index.tests.js index 84286ddfd..b2efb0e06 100644 --- a/packages/optimizely-sdk/lib/utils/fns/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/fns/index.tests.js @@ -1,5 +1,5 @@ /** - * Copyright 2019, Optimizely + * Copyright 2019-2020 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { assert } from 'chai'; -var chai = require('chai'); -var assert = chai.assert; -var fns = require('./'); +import fns from './'; describe('lib/utils/fns', function() { describe('APIs', function() { From 732c568a966dee5abc86c8a3d6541300787d8c17 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Mon, 13 Apr 2020 14:51:51 +0500 Subject: [PATCH 02/11] converted utils/user_profile_service_validator --- .../user_profile_service_validator/index.js | 40 ++++++++++--------- .../index.tests.js | 21 +++++----- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js index 61e7f6172..eee931559 100644 --- a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js +++ b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2017, Optimizely, Inc. and contributors * + * Copyright 2017, 2020 Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -18,24 +18,26 @@ * Provides utility method for validating that the given user profile service implementation is valid. */ -var sprintf = require('@optimizely/js-sdk-utils').sprintf; +import { sprintf } from '@optimizely/js-sdk-utils'; -var ERROR_MESSAGES = require('../enums').ERROR_MESSAGES; +import { ERROR_MESSAGES } from '../enums'; var MODULE_NAME = 'USER_PROFILE_SERVICE_VALIDATOR'; -module.exports = { - /** - * Validates user's provided user profile service instance - * @param {Object} userProfileServiceInstance - * @return {boolean} True if the instance is valid - * @throws If the instance is not valid - */ - validate: function(userProfileServiceInstance) { - 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; - }, -}; +/** + * Validates user's provided user profile service instance + * @param {Object} userProfileServiceInstance + * @return {boolean} True if the instance is valid + * @throws If the instance is not valid + */ +export var validate = function(userProfileServiceInstance) { + 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, +} diff --git a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js index 90d36df2d..529a82ad3 100644 --- a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2017, Optimizely, Inc. and contributors * + * Copyright 2017, 2020 Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -14,12 +14,11 @@ * limitations under the License. * ***************************************************************************/ -var chai = require('chai'); -var assert = chai.assert; -var sprintf = require('@optimizely/js-sdk-utils').sprintf; -var userProfileServiceValidator = require('./'); +import { assert } from 'chai'; +import { sprintf } from '@optimizely/js-sdk-utils'; -var ERROR_MESSAGES = require('../enums').ERROR_MESSAGES; +import { validate } from './'; +import { ERROR_MESSAGES } from '../enums'; describe('lib/utils/user_profile_service_validator', function() { describe('APIs', function() { @@ -29,7 +28,7 @@ describe('lib/utils/user_profile_service_validator', function() { save: function() {}, }; assert.throws(function() { - userProfileServiceValidator.validate(missingLookupFunction); + validate(missingLookupFunction); }, sprintf( ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, 'USER_PROFILE_SERVICE_VALIDATOR', @@ -43,7 +42,7 @@ describe('lib/utils/user_profile_service_validator', function() { lookup: 'notGonnaWork', }; assert.throws(function() { - userProfileServiceValidator.validate(lookupNotFunction); + validate(lookupNotFunction); }, sprintf( ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, 'USER_PROFILE_SERVICE_VALIDATOR', @@ -56,7 +55,7 @@ describe('lib/utils/user_profile_service_validator', function() { lookup: function() {}, }; assert.throws(function() { - userProfileServiceValidator.validate(missingSaveFunction); + validate(missingSaveFunction); }, sprintf( ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, 'USER_PROFILE_SERVICE_VALIDATOR', @@ -70,7 +69,7 @@ describe('lib/utils/user_profile_service_validator', function() { save: 'notGonnaWork', }; assert.throws(function() { - userProfileServiceValidator.validate(saveNotFunction); + validate(saveNotFunction); }, sprintf( ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, 'USER_PROFILE_SERVICE_VALIDATOR', @@ -83,7 +82,7 @@ describe('lib/utils/user_profile_service_validator', function() { save: function() {}, lookup: function() {}, }; - assert.isTrue(userProfileServiceValidator.validate(validInstance)); + assert.isTrue(validate(validInstance)); }); }); }); From d5c6e0dd00bfa4f57e12fff0363b7cb0337080a1 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Mon, 13 Apr 2020 14:58:49 +0500 Subject: [PATCH 03/11] converted utils/string_value_validator --- .../lib/utils/string_value_validator/index.js | 23 ++++++++++--------- .../string_value_validator/index.tests.js | 21 ++++++++--------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/string_value_validator/index.js b/packages/optimizely-sdk/lib/utils/string_value_validator/index.js index e2cd063e6..011926211 100644 --- a/packages/optimizely-sdk/lib/utils/string_value_validator/index.js +++ b/packages/optimizely-sdk/lib/utils/string_value_validator/index.js @@ -1,5 +1,5 @@ /** - * Copyright 2018, Optimizely + * Copyright 2018, 2020 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,14 @@ * limitations under the License. */ -module.exports = { - /** - * Validates provided value is a non-empty string - * @param {string} input - * @return {boolean} True for non-empty string, false otherwise - */ - validate: function(input) { - return typeof input === 'string' && input !== ''; - }, -}; +/** + * Validates provided value is a non-empty string + * @param {string} input + * @return {boolean} True for non-empty string, false otherwise + */ +export var validate = function(input) { + return typeof input === 'string' && input !== ''; +} +export default { + validate: validate, +} diff --git a/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js b/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js index 0937d0dc3..ca63d8ee3 100644 --- a/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js @@ -1,5 +1,5 @@ /** - * Copyright 2018, Optimizely + * Copyright 2018, 2020 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,24 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var chai = require('chai'); -var assert = chai.assert; -var stringInputValidator = require('./'); +import { assert } from 'chai'; +import { validate } from './'; describe('lib/utils/string_input_validator', function() { describe('APIs', function() { describe('validate', function() { it('should validate the given value is valid string', function() { - assert.isTrue(stringInputValidator.validate('validStringValue')); + assert.isTrue(validate('validStringValue')); }); it('should return false if given value is invalid string', function() { - assert.isFalse(stringInputValidator.validate(null)); - assert.isFalse(stringInputValidator.validate(undefined)); - assert.isFalse(stringInputValidator.validate('')); - assert.isFalse(stringInputValidator.validate(5)); - assert.isFalse(stringInputValidator.validate(true)); - assert.isFalse(stringInputValidator.validate([])); + assert.isFalse(validate(null)); + assert.isFalse(validate(undefined)); + assert.isFalse(validate('')); + assert.isFalse(validate(5)); + assert.isFalse(validate(true)); + assert.isFalse(validate([])); }); }); }); From 8135efca07321bbe29145212f31e0790c13aece5 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Mon, 13 Apr 2020 15:03:52 +0500 Subject: [PATCH 04/11] converted utils/json_schema_validator --- .../lib/utils/json_schema_validator/index.js | 58 ++++++++++--------- .../json_schema_validator/index.tests.js | 20 +++---- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js b/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js index 69876c6e4..78ce63ea8 100644 --- a/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js +++ b/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017, Optimizely + * Copyright 2016-2017, 2020 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,35 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var validate = require('json-schema').validate; -var sprintf = require('@optimizely/js-sdk-utils').sprintf; -var projectConfigSchema = require('../../core/project_config/project_config_schema'); +import { sprintf } from '@optimizely/js-sdk-utils'; + +import { validate as jsonSchemaValidator } from 'json-schema'; +import { ERROR_MESSAGES } from '../enums'; +import projectConfigSchema from '../../core/project_config/project_config_schema'; -var ERROR_MESSAGES = require('../enums').ERROR_MESSAGES; var MODULE_NAME = 'JSON_SCHEMA_VALIDATOR'; -module.exports = { - /** - * Validate the given json object against the specified schema - * @param {Object} jsonSchema The json schema to validate against - * @param {Object} jsonObject The object to validate against the schema - * @return {Boolean} True if the given object is valid - */ - validate: function(jsonObject) { - if (!jsonObject) { - throw new Error(sprintf(ERROR_MESSAGES.NO_JSON_PROVIDED, MODULE_NAME)); - } +/** + * Validate the given json object against the specified schema + * @param {Object} jsonObject The object to validate against the schema + * @return {Boolean} True if the given object is valid + */ +export var validate = function(jsonObject) { + if (!jsonObject) { + throw new Error(sprintf(ERROR_MESSAGES.NO_JSON_PROVIDED, MODULE_NAME)); + } - var result = validate(jsonObject, projectConfigSchema); - if (result.valid) { - return true; - } else { - if (Array.isArray(result.errors)) { - throw new Error( - sprintf(ERROR_MESSAGES.INVALID_DATAFILE, MODULE_NAME, result.errors[0].property, result.errors[0].message) - ); - } - throw new Error(sprintf(ERROR_MESSAGES.INVALID_JSON, MODULE_NAME)); + var result = jsonSchemaValidator(jsonObject, projectConfigSchema); + if (result.valid) { + return true; + } else { + if (Array.isArray(result.errors)) { + throw new Error( + sprintf(ERROR_MESSAGES.INVALID_DATAFILE, MODULE_NAME, result.errors[0].property, result.errors[0].message) + ); } - }, -}; + throw new Error(sprintf(ERROR_MESSAGES.INVALID_JSON, MODULE_NAME)); + } +} + +export default { + validate: validate, +} diff --git a/packages/optimizely-sdk/lib/utils/json_schema_validator/index.tests.js b/packages/optimizely-sdk/lib/utils/json_schema_validator/index.tests.js index caf2b5284..58b550a7e 100644 --- a/packages/optimizely-sdk/lib/utils/json_schema_validator/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/json_schema_validator/index.tests.js @@ -1,5 +1,5 @@ /** - * Copyright 2016-2019, Optimizely + * Copyright 2016-2020, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,31 +13,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -var chai = require('chai'); -var assert = chai.assert; -var jsonSchemaValidator = require('./'); -var sprintf = require('@optimizely/js-sdk-utils').sprintf; -var testData = require('../../tests/test_data.js'); +import { sprintf } from '@optimizely/js-sdk-utils'; +import { assert } from 'chai'; + +import { validate } from './'; +import { ERROR_MESSAGES } from '../enums'; +import testData from '../../tests/test_data.js'; -var ERROR_MESSAGES = require('../enums').ERROR_MESSAGES; describe('lib/utils/json_schema_validator', function() { describe('APIs', function() { describe('validate', function() { it('should throw an error if the object is not valid', function() { assert.throws(function() { - jsonSchemaValidator.validate({}); + validate({}); }); }); it('should throw an error if no json object is passed in', function() { assert.throws(function() { - jsonSchemaValidator.validate(); + validate(); }, sprintf(ERROR_MESSAGES.NO_JSON_PROVIDED, 'JSON_SCHEMA_VALIDATOR')); }); it('should validate specified Optimizely datafile', function() { - assert.isTrue(jsonSchemaValidator.validate(testData.getTestProjectConfig())); + assert.isTrue(validate(testData.getTestProjectConfig())); }); }); }); From 54bf1d0552dfc4ffb367fd7b8a9f5bb461337dc3 Mon Sep 17 00:00:00 2001 From: fayyazarshad Date: Mon, 13 Apr 2020 19:09:13 +0500 Subject: [PATCH 05/11] added default export in enums --- .../optimizely-sdk/lib/utils/enums/index.js | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/enums/index.js b/packages/optimizely-sdk/lib/utils/enums/index.js index 743aed808..0e4286453 100644 --- a/packages/optimizely-sdk/lib/utils/enums/index.js +++ b/packages/optimizely-sdk/lib/utils/enums/index.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2019, Optimizely, Inc. and contributors * + * Copyright 2016-2020, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -14,12 +14,12 @@ * limitations under the License. * ***************************************************************************/ -var jsSdkUtils = require('@optimizely/js-sdk-utils'); +import { NOTIFICATION_TYPES as notificationTypesEnum } from '@optimizely/js-sdk-utils'; /** * Contains global enums used throughout the library */ -exports.LOG_LEVEL = { +export var LOG_LEVEL = { NOTSET: 0, DEBUG: 1, INFO: 2, @@ -27,7 +27,7 @@ exports.LOG_LEVEL = { ERROR: 4, }; -exports.ERROR_MESSAGES = { +export var ERROR_MESSAGES = { CONDITION_EVALUATOR_ERROR: '%s: Error evaluating audience condition of type %s: %s', DATAFILE_AND_SDK_KEY_MISSING: '%s: You must provide at least one of sdkKey or datafile. Cannot start Optimizely', EXPERIMENT_KEY_NOT_IN_DATAFILE: '%s: Experiment key %s is not in datafile.', @@ -65,7 +65,7 @@ exports.ERROR_MESSAGES = { INVALID_VARIATION_KEY: '%s: Provided variation key is in an invalid format.', }; -exports.LOG_MESSAGES = { +export var LOG_MESSAGES = { ACTIVATE_USER: '%s: Activating user %s in experiment %s.', DISPATCH_CONVERSION_EVENT: '%s: Dispatching conversion event to URL %s with params %s.', DISPATCH_IMPRESSION_EVENT: '%s: Dispatching impression event to URL %s with params %s.', @@ -158,36 +158,36 @@ exports.LOG_MESSAGES = { UNABLE_TO_ATTACH_UNLOAD: '%s: unable to bind optimizely.close() to page unload event: "%s"', }; -exports.RESERVED_EVENT_KEYWORDS = { +export var RESERVED_EVENT_KEYWORDS = { REVENUE: 'revenue', VALUE: 'value', }; -exports.CONTROL_ATTRIBUTES = { +export var CONTROL_ATTRIBUTES = { BOT_FILTERING: '$opt_bot_filtering', BUCKETING_ID: '$opt_bucketing_id', STICKY_BUCKETING_KEY: '$opt_experiment_bucket_map', USER_AGENT: '$opt_user_agent', }; -exports.JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk'; -exports.NODE_CLIENT_ENGINE = 'node-sdk'; -exports.REACT_CLIENT_ENGINE = 'react-sdk'; -exports.REACT_NATIVE_CLIENT_ENGINE = 'react-native-sdk'; -exports.REACT_NATIVE_JS_CLIENT_ENGINE = 'react-native-js-sdk'; -exports.NODE_CLIENT_VERSION = '4.0.0-alpha.1'; +export var JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk'; +export var NODE_CLIENT_ENGINE = 'node-sdk'; +export var REACT_CLIENT_ENGINE = 'react-sdk'; +export var REACT_NATIVE_CLIENT_ENGINE = 'react-native-sdk'; +export var REACT_NATIVE_JS_CLIENT_ENGINE = 'react-native-js-sdk'; +export var NODE_CLIENT_VERSION = '4.0.0-alpha.1'; -exports.VALID_CLIENT_ENGINES = [ - exports.NODE_CLIENT_ENGINE, - exports.REACT_CLIENT_ENGINE, - exports.JAVASCRIPT_CLIENT_ENGINE, - exports.REACT_NATIVE_CLIENT_ENGINE, - exports.REACT_NATIVE_JS_CLIENT_ENGINE, +export var VALID_CLIENT_ENGINES = [ + NODE_CLIENT_ENGINE, + REACT_CLIENT_ENGINE, + JAVASCRIPT_CLIENT_ENGINE, + REACT_NATIVE_CLIENT_ENGINE, + REACT_NATIVE_JS_CLIENT_ENGINE, ]; -exports.NOTIFICATION_TYPES = jsSdkUtils.NOTIFICATION_TYPES; +export var NOTIFICATION_TYPES = notificationTypesEnum; -exports.DECISION_NOTIFICATION_TYPES = { +export var DECISION_NOTIFICATION_TYPES = { AB_TEST: 'ab-test', FEATURE: 'feature', FEATURE_TEST: 'feature-test', @@ -200,7 +200,7 @@ exports.DECISION_NOTIFICATION_TYPES = { * source is used to decide whether to dispatch an impression event to * Optimizely. */ -exports.DECISION_SOURCES = { +export var DECISION_SOURCES = { FEATURE_TEST: 'feature-test', ROLLOUT: 'rollout', }; @@ -208,7 +208,7 @@ exports.DECISION_SOURCES = { /* * Possible types of variables attached to features */ -exports.FEATURE_VARIABLE_TYPES = { +export var FEATURE_VARIABLE_TYPES = { BOOLEAN: 'boolean', DOUBLE: 'double', INTEGER: 'integer', @@ -218,8 +218,28 @@ exports.FEATURE_VARIABLE_TYPES = { /* * Supported datafile versions */ -exports.DATAFILE_VERSIONS = { +export var DATAFILE_VERSIONS = { V2: '2', V3: '3', V4: '4', }; + +export default { + LOG_LEVEL: LOG_LEVEL, + ERROR_MESSAGES: ERROR_MESSAGES, + LOG_MESSAGES: LOG_MESSAGES, + RESERVED_EVENT_KEYWORDS: RESERVED_EVENT_KEYWORDS, + CONTROL_ATTRIBUTES: CONTROL_ATTRIBUTES, + JAVASCRIPT_CLIENT_ENGINE: JAVASCRIPT_CLIENT_ENGINE, + NODE_CLIENT_ENGINE: NODE_CLIENT_ENGINE, + REACT_CLIENT_ENGINE: REACT_CLIENT_ENGINE, + REACT_NATIVE_CLIENT_ENGINE: REACT_NATIVE_CLIENT_ENGINE, + REACT_NATIVE_JS_CLIENT_ENGINE: REACT_NATIVE_JS_CLIENT_ENGINE, + NODE_CLIENT_VERSION: NODE_CLIENT_VERSION, + VALID_CLIENT_ENGINES: VALID_CLIENT_ENGINES, + NOTIFICATION_TYPES: NOTIFICATION_TYPES, + DECISION_NOTIFICATION_TYPES: DECISION_NOTIFICATION_TYPES, + DECISION_SOURCES: DECISION_SOURCES, + FEATURE_VARIABLE_TYPES: FEATURE_VARIABLE_TYPES, + DATAFILE_VERSIONS: DATAFILE_VERSIONS, +} From 16cfe886b0da94246f47f20d52b2f4f763c0df09 Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Mon, 13 Apr 2020 14:44:03 -0700 Subject: [PATCH 06/11] trying a fix in test app --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ed28d782..5a30db3e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,8 +70,8 @@ jobs: before_script: - mkdir $HOME/travisci-tools && pushd $HOME/travisci-tools && git init && git pull https://$CI_USER_TOKEN@github.com/optimizely/travisci-tools.git && popd script: - - CLIENT=node $HOME/travisci-tools/trigger-script-with-status-update.sh - - CLIENT=browser $HOME/travisci-tools/trigger-script-with-status-update.sh + - CLIENT=node TESTAPP_BRANCH=zeeshan/fix-enums-import $HOME/travisci-tools/trigger-script-with-status-update.sh + - CLIENT=browser TESTAPP_BRANCH=zeeshan/fix-enums-import $HOME/travisci-tools/trigger-script-with-status-update.sh after_success: travis_terminate 0 - <<: *integrationtest stage: 'Benchmarking tests' From f00ed0afec12e755f7aa59c7e011cafef5684bc2 Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Mon, 13 Apr 2020 15:06:29 -0700 Subject: [PATCH 07/11] Revert "trying a fix in test app" This reverts commit 16cfe886b0da94246f47f20d52b2f4f763c0df09. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a30db3e7..7ed28d782 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,8 +70,8 @@ jobs: before_script: - mkdir $HOME/travisci-tools && pushd $HOME/travisci-tools && git init && git pull https://$CI_USER_TOKEN@github.com/optimizely/travisci-tools.git && popd script: - - CLIENT=node TESTAPP_BRANCH=zeeshan/fix-enums-import $HOME/travisci-tools/trigger-script-with-status-update.sh - - CLIENT=browser TESTAPP_BRANCH=zeeshan/fix-enums-import $HOME/travisci-tools/trigger-script-with-status-update.sh + - CLIENT=node $HOME/travisci-tools/trigger-script-with-status-update.sh + - CLIENT=browser $HOME/travisci-tools/trigger-script-with-status-update.sh after_success: travis_terminate 0 - <<: *integrationtest stage: 'Benchmarking tests' From 96ea92686fafed5d3f145341887e6d878ddd6cdc Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Mon, 13 Apr 2020 16:22:13 -0700 Subject: [PATCH 08/11] some cleanup --- .../optimizely-sdk/lib/utils/fns/index.js | 22 +++++++++---------- .../lib/utils/json_schema_validator/index.js | 4 ++-- .../lib/utils/string_value_validator/index.js | 7 +++--- .../string_value_validator/index.tests.js | 2 +- .../user_profile_service_validator/index.js | 6 ++--- .../index.tests.js | 2 +- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/fns/index.js b/packages/optimizely-sdk/lib/utils/fns/index.js index aa3c6fe48..3d45ff058 100644 --- a/packages/optimizely-sdk/lib/utils/fns/index.js +++ b/packages/optimizely-sdk/lib/utils/fns/index.js @@ -1,5 +1,5 @@ /** - * Copyright 2017, 2019-2020 Optimizely + * Copyright 2017, 2019-2020, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { v4 } from 'uuid'; import { keyBy as keyByUtil } from '@optimizely/js-sdk-utils'; -import uid from 'uuid'; - var MAX_SAFE_INTEGER_LIMIT = Math.pow(2, 53); export var assign = function(target) { @@ -40,31 +39,30 @@ export var assign = function(target) { } return to; } -} +}; export var currentTimestamp = function() { - console.log('Calling Actual Method'); return Math.round(new Date().getTime()); -} +}; export var isSafeInteger = function(number) { return typeof number == 'number' && Math.abs(number) <= MAX_SAFE_INTEGER_LIMIT; -} +}; export var keyBy = function(arr, key) { if (!arr) return {}; return keyByUtil(arr, function(item) { return item[key]; }); -} +}; export var uuid = function() { - return uid.v4(); -} + return v4(); +}; export var isNumber = function(value) { return typeof value === 'number'; -} +}; export default { assign: assign, @@ -73,4 +71,4 @@ export default { keyBy: keyBy, uuid: uuid, isNumber: isNumber, -} +}; diff --git a/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js b/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js index 78ce63ea8..232bc2af8 100644 --- a/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js +++ b/packages/optimizely-sdk/lib/utils/json_schema_validator/index.js @@ -42,8 +42,8 @@ export var validate = function(jsonObject) { } throw new Error(sprintf(ERROR_MESSAGES.INVALID_JSON, MODULE_NAME)); } -} +}; export default { validate: validate, -} +}; diff --git a/packages/optimizely-sdk/lib/utils/string_value_validator/index.js b/packages/optimizely-sdk/lib/utils/string_value_validator/index.js index 011926211..bde3ed2f9 100644 --- a/packages/optimizely-sdk/lib/utils/string_value_validator/index.js +++ b/packages/optimizely-sdk/lib/utils/string_value_validator/index.js @@ -1,5 +1,5 @@ /** - * Copyright 2018, 2020 Optimizely + * Copyright 2018, 2020, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,8 @@ */ export var validate = function(input) { return typeof input === 'string' && input !== ''; -} +}; + export default { validate: validate, -} +}; diff --git a/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js b/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js index ca63d8ee3..51b9413bd 100644 --- a/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/string_value_validator/index.tests.js @@ -1,5 +1,5 @@ /** - * Copyright 2018, 2020 Optimizely + * Copyright 2018, 2020, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js index eee931559..b8dacb41e 100644 --- a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js +++ b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2017, 2020 Optimizely, Inc. and contributors * + * Copyright 2017, 2020, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -36,8 +36,8 @@ export var validate = function(userProfileServiceInstance) { throw new Error(sprintf(ERROR_MESSAGES.INVALID_USER_PROFILE_SERVICE, MODULE_NAME, "Missing function 'save'")); } return true; -} +}; export default { validate: validate, -} +}; diff --git a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js index 529a82ad3..33aaa077c 100644 --- a/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/user_profile_service_validator/index.tests.js @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2017, 2020 Optimizely, Inc. and contributors * + * Copyright 2017, 2020, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * From accbafb2a62479cdc0691c02f1a6175f6630e2bd Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Mon, 13 Apr 2020 16:33:47 -0700 Subject: [PATCH 09/11] fix --- packages/optimizely-sdk/lib/utils/fns/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/fns/index.js b/packages/optimizely-sdk/lib/utils/fns/index.js index 3d45ff058..a446f76d8 100644 --- a/packages/optimizely-sdk/lib/utils/fns/index.js +++ b/packages/optimizely-sdk/lib/utils/fns/index.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { v4 } from 'uuid'; +import uuidLib from 'uuid'; import { keyBy as keyByUtil } from '@optimizely/js-sdk-utils'; var MAX_SAFE_INTEGER_LIMIT = Math.pow(2, 53); @@ -57,7 +57,7 @@ export var keyBy = function(arr, key) { }; export var uuid = function() { - return v4(); + return uuidLib.v4(); }; export var isNumber = function(value) { From b5090ffc8b484b07b107df61fcee591bea352532 Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Mon, 13 Apr 2020 18:10:15 -0700 Subject: [PATCH 10/11] fixed unit tests --- packages/optimizely-sdk/lib/optimizely/index.tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/optimizely-sdk/lib/optimizely/index.tests.js b/packages/optimizely-sdk/lib/optimizely/index.tests.js index e3268f345..917820493 100644 --- a/packages/optimizely-sdk/lib/optimizely/index.tests.js +++ b/packages/optimizely-sdk/lib/optimizely/index.tests.js @@ -29,7 +29,7 @@ import enums from '../utils/enums'; import eventBuilder from '../core/event_builder/index.js'; import eventDispatcher from '../plugins/event_dispatcher/index.node'; import errorHandler from '../plugins/error_handler'; -import * as fns from '../utils/fns'; +import fns from '../utils/fns'; import logger from '../plugins/logger'; import decisionService from '../core/decision_service'; import jsonSchemaValidator from '../utils/json_schema_validator'; From dc83e382f18317aa60f14dd24ebb49ee933680a8 Mon Sep 17 00:00:00 2001 From: Zeeshan Ashraf Date: Mon, 13 Apr 2020 18:21:16 -0700 Subject: [PATCH 11/11] converted the last file --- packages/optimizely-sdk/lib/utils/enums/index.tests.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/optimizely-sdk/lib/utils/enums/index.tests.js b/packages/optimizely-sdk/lib/utils/enums/index.tests.js index 5e464247c..6915db572 100644 --- a/packages/optimizely-sdk/lib/utils/enums/index.tests.js +++ b/packages/optimizely-sdk/lib/utils/enums/index.tests.js @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * * limitations under the License. * ***************************************************************************/ - -var chai = require('chai') -var enums = require('./') -var assert = chai.assert; +import { assert } from 'chai'; +import { VALID_CLIENT_ENGINES } from './'; describe('lib/utils/enums', function() { describe('valid client engines', function() { it('all valid client engines should end with "-sdk"', function() { - enums.VALID_CLIENT_ENGINES.forEach(function(clientEngine) { + VALID_CLIENT_ENGINES.forEach(function(clientEngine) { assert.isTrue(clientEngine.endsWith('-sdk')) }); });