diff --git a/lib/common_exports.ts b/lib/common_exports.ts index c043796df..583f1b455 100644 --- a/lib/common_exports.ts +++ b/lib/common_exports.ts @@ -14,6 +14,5 @@ * limitations under the License. */ -export { LOG_LEVEL } from './utils/enums'; export { createStaticProjectConfigManager } from './project_config/config_manager_factory'; export { PollingConfigManagerConfig } from './project_config/config_manager_factory'; diff --git a/lib/core/audience_evaluator/index.ts b/lib/core/audience_evaluator/index.ts index e110ab569..4ada47bbe 100644 --- a/lib/core/audience_evaluator/index.ts +++ b/lib/core/audience_evaluator/index.ts @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - LOG_LEVEL, -} from '../../utils/enums'; import * as conditionTreeEvaluator from '../condition_tree_evaluator'; import * as customAttributeConditionEvaluator from '../custom_attribute_condition_evaluator'; import * as odpSegmentsConditionEvaluator from './odp_segment_condition_evaluator'; @@ -24,8 +21,6 @@ import { CONDITION_EVALUATOR_ERROR, UNKNOWN_CONDITION_TYPE } from '../../error_m import { AUDIENCE_EVALUATION_RESULT, EVALUATING_AUDIENCE} from '../../log_messages'; import { LoggerFacade } from '../../logging/logger'; -const MODULE_NAME = 'AUDIENCE_EVALUATOR'; - export class AudienceEvaluator { private logger?: LoggerFacade; diff --git a/lib/core/audience_evaluator/odp_segment_condition_evaluator/index.ts b/lib/core/audience_evaluator/odp_segment_condition_evaluator/index.ts index 4984dce51..d97ee9db5 100644 --- a/lib/core/audience_evaluator/odp_segment_condition_evaluator/index.ts +++ b/lib/core/audience_evaluator/odp_segment_condition_evaluator/index.ts @@ -17,8 +17,6 @@ import { UNKNOWN_MATCH_TYPE } from '../../../error_messages'; import { LoggerFacade } from '../../../logging/logger'; import { Condition, OptimizelyUserContext } from '../../../shared_types'; -const MODULE_NAME = 'ODP_SEGMENT_CONDITION_EVALUATOR'; - const QUALIFIED_MATCH_TYPE = 'qualified'; const MATCH_TYPES = [ diff --git a/lib/core/bucketer/index.ts b/lib/core/bucketer/index.ts index b84a36e3a..6d23856e5 100644 --- a/lib/core/bucketer/index.ts +++ b/lib/core/bucketer/index.ts @@ -17,7 +17,6 @@ /** * Bucketer API for determining the variation id from the specified parameters */ -import { sprintf } from '../../utils/fns'; import murmurhash from 'murmurhash'; import { LoggerFacade } from '../../logging/logger'; import { @@ -27,7 +26,6 @@ import { Group, } from '../../shared_types'; -import { LOG_LEVEL } from '../../utils/enums'; import { INVALID_BUCKETING_ID, INVALID_GROUP_ID } from '../../error_messages'; import { OptimizelyError } from '../../error/optimizly_error'; @@ -40,7 +38,6 @@ export const INVALID_VARIATION_ID = 'Bucketed into an invalid variation ID. Retu const HASH_SEED = 1; const MAX_HASH_VALUE = Math.pow(2, 32); const MAX_TRAFFIC_VALUE = 10000; -const MODULE_NAME = 'BUCKETER'; const RANDOM_POLICY = 'random'; /** @@ -86,7 +83,6 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse ); decideReasons.push([ USER_NOT_IN_ANY_EXPERIMENT, - MODULE_NAME, bucketerParams.userId, groupId, ]); @@ -106,7 +102,6 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse ); decideReasons.push([ USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP, - MODULE_NAME, bucketerParams.userId, bucketerParams.experimentKey, groupId, @@ -126,7 +121,6 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse ); decideReasons.push([ USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, - MODULE_NAME, bucketerParams.userId, bucketerParams.experimentKey, groupId, @@ -143,7 +137,6 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse ); decideReasons.push([ USER_ASSIGNED_TO_EXPERIMENT_BUCKET, - MODULE_NAME, bucketValue, bucketerParams.userId, ]); @@ -152,8 +145,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse if (entityId !== null) { if (!bucketerParams.variationIdMap[entityId]) { if (entityId) { - bucketerParams.logger?.warn(INVALID_VARIATION_ID, MODULE_NAME); - decideReasons.push([INVALID_VARIATION_ID, MODULE_NAME]); + bucketerParams.logger?.warn(INVALID_VARIATION_ID); + decideReasons.push([INVALID_VARIATION_ID]); } return { result: null, diff --git a/lib/core/custom_attribute_condition_evaluator/index.ts b/lib/core/custom_attribute_condition_evaluator/index.ts index 0a3c0b0a6..c722c1837 100644 --- a/lib/core/custom_attribute_condition_evaluator/index.ts +++ b/lib/core/custom_attribute_condition_evaluator/index.ts @@ -29,8 +29,6 @@ import { } from '../../error_messages'; import { LoggerFacade } from '../../logging/logger'; -const MODULE_NAME = 'CUSTOM_ATTRIBUTE_CONDITION_EVALUATOR'; - const EXACT_MATCH_TYPE = 'exact'; const EXISTS_MATCH_TYPE = 'exists'; const GREATER_OR_EQUAL_THAN_MATCH_TYPE = 'ge'; diff --git a/lib/core/decision_service/index.tests.js b/lib/core/decision_service/index.tests.js index 39d8889fd..4cfc1a89a 100644 --- a/lib/core/decision_service/index.tests.js +++ b/lib/core/decision_service/index.tests.js @@ -39,27 +39,40 @@ import { getTestProjectConfig, getTestProjectConfigWithFeatures, } from '../../tests/test_data'; + import { - AUDIENCE_EVALUATION_RESULT_COMBINED, - EVALUATING_AUDIENCES_COMBINED, - USER_FORCED_IN_VARIATION, USER_HAS_NO_FORCED_VARIATION, - USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, - USER_NOT_IN_EXPERIMENT, + VALID_BUCKETING_ID, + SAVED_USER_VARIATION, + SAVED_VARIATION_NOT_FOUND, +} from '../../log_messages'; + +import { EXPERIMENT_NOT_RUNNING, RETURNING_STORED_VARIATION, + USER_NOT_IN_EXPERIMENT, + USER_HAS_NO_VARIATION, + USER_HAS_VARIATION, + USER_FORCED_IN_VARIATION, + FORCED_BUCKETING_FAILED, + EVALUATING_AUDIENCES_COMBINED, + AUDIENCE_EVALUATION_RESULT_COMBINED, + USER_IN_ROLLOUT, + USER_NOT_IN_ROLLOUT, FEATURE_HAS_NO_EXPERIMENTS, - NO_ROLLOUT_EXISTS, + USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, + USER_NOT_BUCKETED_INTO_TARGETING_RULE, USER_BUCKETED_INTO_TARGETING_RULE, - USER_IN_ROLLOUT, + NO_ROLLOUT_EXISTS, + INVALID_ROLLOUT_ID, + ROLLOUT_HAS_NO_EXPERIMENTS, + IMPROPERLY_FORMATTED_EXPERIMENT, + USER_HAS_FORCED_VARIATION, USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, USER_NOT_BUCKETED_INTO_TARGETING_RULE, - USER_NOT_IN_ROLLOUT, - VALID_BUCKETING_ID, - SAVED_USER_VARIATION, - SAVED_VARIATION_NOT_FOUND -} from '../../log_messages'; -import { mock } from 'node:test'; + USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, +} from '../decision_service/index'; + import { BUCKETING_ID_NOT_STRING, USER_PROFILE_LOOKUP_ERROR, USER_PROFILE_SAVE_ERROR } from '../../error_messages'; var testData = getTestProjectConfig(); diff --git a/lib/core/decision_service/index.ts b/lib/core/decision_service/index.ts index c58716df4..9867d9b19 100644 --- a/lib/core/decision_service/index.ts +++ b/lib/core/decision_service/index.ts @@ -14,15 +14,11 @@ * limitations under the License. */ import { LoggerFacade } from '../../logging/logger' -import { sprintf } from '../../utils/fns'; - -import fns from '../../utils/fns'; import { bucket } from '../bucketer'; import { AUDIENCE_EVALUATION_TYPES, CONTROL_ATTRIBUTES, DECISION_SOURCES, - LOG_LEVEL, } from '../../utils/enums'; import { getAudiencesById, @@ -53,52 +49,55 @@ import { Variation, } from '../../shared_types'; import { - IMPROPERLY_FORMATTED_EXPERIMENT, - INVALID_ROLLOUT_ID, INVALID_USER_ID, INVALID_VARIATION_KEY, NO_VARIATION_FOR_EXPERIMENT_KEY, USER_NOT_IN_FORCED_VARIATION, USER_PROFILE_LOOKUP_ERROR, USER_PROFILE_SAVE_ERROR, - FORCED_BUCKETING_FAILED, BUCKETING_ID_NOT_STRING, } from '../../error_messages'; import { - AUDIENCE_EVALUATION_RESULT_COMBINED, - EVALUATING_AUDIENCES_COMBINED, - EXPERIMENT_NOT_RUNNING, - FEATURE_HAS_NO_EXPERIMENTS, - NO_ROLLOUT_EXISTS, - RETURNING_STORED_VARIATION, - ROLLOUT_HAS_NO_EXPERIMENTS, SAVED_USER_VARIATION, SAVED_VARIATION_NOT_FOUND, - USER_BUCKETED_INTO_TARGETING_RULE, - USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, - USER_FORCED_IN_VARIATION, USER_HAS_FORCED_DECISION_WITH_NO_RULE_SPECIFIED, USER_HAS_FORCED_DECISION_WITH_NO_RULE_SPECIFIED_BUT_INVALID, USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED, USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED_BUT_INVALID, - USER_HAS_FORCED_VARIATION, USER_HAS_NO_FORCED_VARIATION, - USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, - USER_HAS_NO_VARIATION, - USER_HAS_VARIATION, - USER_IN_ROLLOUT, USER_MAPPED_TO_FORCED_VARIATION, - USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, - USER_NOT_BUCKETED_INTO_TARGETING_RULE, - USER_NOT_IN_EXPERIMENT, - USER_NOT_IN_ROLLOUT, + USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, VALID_BUCKETING_ID, VARIATION_REMOVED_FOR_USER, } from '../../log_messages'; import { OptimizelyError } from '../../error/optimizly_error'; -export const MODULE_NAME = 'DECISION_SERVICE'; +export const EXPERIMENT_NOT_RUNNING = 'Experiment %s is not running.'; +export const RETURNING_STORED_VARIATION = + 'Returning previously activated variation "%s" of experiment "%s" for user "%s" from user profile.'; +export const USER_NOT_IN_EXPERIMENT = 'User %s does not meet conditions to be in experiment %s.'; +export const USER_HAS_NO_VARIATION = 'User %s is in no variation of experiment %s.'; +export const USER_HAS_VARIATION = 'User %s is in variation %s of experiment %s.'; +export const USER_FORCED_IN_VARIATION = 'User %s is forced in variation %s.'; +export const FORCED_BUCKETING_FAILED = 'Variation key %s is not in datafile. Not activating user %s.'; +export const EVALUATING_AUDIENCES_COMBINED = 'Evaluating audiences for %s "%s": %s.'; +export const AUDIENCE_EVALUATION_RESULT_COMBINED = 'Audiences for %s %s collectively evaluated to %s.'; +export const USER_IN_ROLLOUT = 'User %s is in rollout of feature %s.'; +export const USER_NOT_IN_ROLLOUT = 'User %s is not in rollout of feature %s.'; +export const FEATURE_HAS_NO_EXPERIMENTS = 'Feature %s is not attached to any experiments.'; +export const USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE = + 'User %s does not meet conditions for targeting rule %s.'; +export const USER_NOT_BUCKETED_INTO_TARGETING_RULE = +'User %s not bucketed into targeting rule %s due to traffic allocation. Trying everyone rule.'; +export const USER_BUCKETED_INTO_TARGETING_RULE = 'User %s bucketed into targeting rule %s.'; +export const NO_ROLLOUT_EXISTS = 'There is no rollout of feature %s.'; +export const INVALID_ROLLOUT_ID = 'Invalid rollout ID %s attached to feature %s'; +export const ROLLOUT_HAS_NO_EXPERIMENTS = 'Rollout of feature %s has no experiments'; +export const IMPROPERLY_FORMATTED_EXPERIMENT = 'Experiment key %s is improperly formatted.'; +export const USER_HAS_FORCED_VARIATION = + 'Variation %s is mapped to experiment %s and user %s in the forced variation map.'; +export const USER_MEETS_CONDITIONS_FOR_TARGETING_RULE = 'User %s meets conditions for targeting rule %s.'; export interface DecisionObj { experiment: Experiment | null; @@ -173,7 +172,7 @@ export class DecisionService { const experimentKey = experiment.key; if (!this.checkIfExperimentIsActive(configObj, experimentKey)) { this.logger?.info(EXPERIMENT_NOT_RUNNING, experimentKey); - decideReasons.push([EXPERIMENT_NOT_RUNNING, MODULE_NAME, experimentKey]); + decideReasons.push([EXPERIMENT_NOT_RUNNING, experimentKey]); return { result: null, reasons: decideReasons, @@ -212,7 +211,6 @@ export class DecisionService { ); decideReasons.push([ RETURNING_STORED_VARIATION, - MODULE_NAME, variation.key, experimentKey, userId, @@ -241,7 +239,6 @@ export class DecisionService { ); decideReasons.push([ USER_NOT_IN_EXPERIMENT, - MODULE_NAME, userId, experimentKey, ]); @@ -266,7 +263,6 @@ export class DecisionService { ); decideReasons.push([ USER_HAS_NO_VARIATION, - MODULE_NAME, userId, experimentKey, ]); @@ -284,7 +280,6 @@ export class DecisionService { ); decideReasons.push([ USER_HAS_VARIATION, - MODULE_NAME, userId, variation.key, experimentKey, @@ -382,7 +377,6 @@ export class DecisionService { ); decideReasons.push([ USER_FORCED_IN_VARIATION, - MODULE_NAME, userId, forcedVariationKey, ]); @@ -393,13 +387,11 @@ export class DecisionService { } else { this.logger?.error( FORCED_BUCKETING_FAILED, - MODULE_NAME, forcedVariationKey, userId, ); decideReasons.push([ FORCED_BUCKETING_FAILED, - MODULE_NAME, forcedVariationKey, userId, ]); @@ -445,7 +437,6 @@ export class DecisionService { ); decideReasons.push([ EVALUATING_AUDIENCES_COMBINED, - MODULE_NAME, evaluationAttribute, loggingKey || experiment.key, JSON.stringify(experimentAudienceConditions), @@ -459,7 +450,6 @@ export class DecisionService { ); decideReasons.push([ AUDIENCE_EVALUATION_RESULT_COMBINED, - MODULE_NAME, evaluationAttribute, loggingKey || experiment.key, result.toString().toUpperCase(), @@ -654,10 +644,10 @@ export class DecisionService { if (rolloutDecision.variation) { this.logger?.debug(USER_IN_ROLLOUT, userId, feature.key); - decideReasons.push([USER_IN_ROLLOUT, MODULE_NAME, userId, feature.key]); + decideReasons.push([USER_IN_ROLLOUT, userId, feature.key]); } else { this.logger?.debug(USER_NOT_IN_ROLLOUT, userId, feature.key); - decideReasons.push([USER_NOT_IN_ROLLOUT, MODULE_NAME, userId, feature.key]); + decideReasons.push([USER_NOT_IN_ROLLOUT, userId, feature.key]); } decisions.push({ @@ -742,7 +732,7 @@ export class DecisionService { } } else { this.logger?.debug(FEATURE_HAS_NO_EXPERIMENTS, feature.key); - decideReasons.push([FEATURE_HAS_NO_EXPERIMENTS, MODULE_NAME, feature.key]); + decideReasons.push([FEATURE_HAS_NO_EXPERIMENTS, feature.key]); } variationForFeatureExperiment = { @@ -766,7 +756,7 @@ export class DecisionService { let decisionObj: DecisionObj; if (!feature.rolloutId) { this.logger?.debug(NO_ROLLOUT_EXISTS, feature.key); - decideReasons.push([NO_ROLLOUT_EXISTS, MODULE_NAME, feature.key]); + decideReasons.push([NO_ROLLOUT_EXISTS, feature.key]); decisionObj = { experiment: null, variation: null, @@ -786,7 +776,7 @@ export class DecisionService { feature.rolloutId, feature.key, ); - decideReasons.push([INVALID_ROLLOUT_ID, MODULE_NAME, feature.rolloutId, feature.key]); + decideReasons.push([INVALID_ROLLOUT_ID, feature.rolloutId, feature.key]); decisionObj = { experiment: null, variation: null, @@ -804,7 +794,7 @@ export class DecisionService { ROLLOUT_HAS_NO_EXPERIMENTS, feature.rolloutId, ); - decideReasons.push([ROLLOUT_HAS_NO_EXPERIMENTS, MODULE_NAME, feature.rolloutId]); + decideReasons.push([ROLLOUT_HAS_NO_EXPERIMENTS, feature.rolloutId]); decisionObj = { experiment: null, variation: null, @@ -1050,12 +1040,10 @@ export class DecisionService { // catching improperly formatted experiments this.logger?.error( IMPROPERLY_FORMATTED_EXPERIMENT, - MODULE_NAME, experimentKey, ); decideReasons.push([ IMPROPERLY_FORMATTED_EXPERIMENT, - MODULE_NAME, experimentKey, ]); @@ -1079,7 +1067,6 @@ export class DecisionService { if (!variationId) { this.logger?.debug( USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, - MODULE_NAME, experimentKey, userId, ); @@ -1099,7 +1086,6 @@ export class DecisionService { ); decideReasons.push([ USER_HAS_FORCED_VARIATION, - MODULE_NAME, variationKey, experimentKey, userId, @@ -1267,7 +1253,6 @@ export class DecisionService { ); decideReasons.push([ USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, - MODULE_NAME, userId, loggingKey ]); @@ -1287,7 +1272,6 @@ export class DecisionService { ); decideReasons.push([ USER_BUCKETED_INTO_TARGETING_RULE, - MODULE_NAME, userId, loggingKey]); } else if (!everyoneElse) { @@ -1299,7 +1283,6 @@ export class DecisionService { ); decideReasons.push([ USER_NOT_BUCKETED_INTO_TARGETING_RULE, - MODULE_NAME, userId, loggingKey ]); @@ -1315,7 +1298,6 @@ export class DecisionService { ); decideReasons.push([ USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, - MODULE_NAME, userId, loggingKey ]); diff --git a/lib/error_messages.ts b/lib/error_messages.ts index 0730ed41c..7ef14178d 100644 --- a/lib/error_messages.ts +++ b/lib/error_messages.ts @@ -22,7 +22,6 @@ export const EXPERIMENT_KEY_NOT_IN_DATAFILE = 'Experiment key %s is not in dataf export const FEATURE_NOT_IN_DATAFILE = 'Feature key %s is not in datafile.'; export const FETCH_SEGMENTS_FAILED_NETWORK_ERROR = '%s: Audience segments fetch failed. (network error)'; export const FETCH_SEGMENTS_FAILED_DECODE_ERROR = '%s: Audience segments fetch failed. (decode error)'; -export const IMPROPERLY_FORMATTED_EXPERIMENT = 'Experiment key %s is improperly formatted.'; export const INVALID_ATTRIBUTES = 'Provided attributes are in an invalid format.'; export const INVALID_BUCKETING_ID = 'Unable to generate hash for bucketing ID %s: %s'; export const INVALID_DATAFILE = 'Datafile is invalid - property %s: %s'; @@ -37,7 +36,6 @@ export const INVALID_EXPERIMENT_KEY = export const INVALID_EXPERIMENT_ID = 'Experiment ID %s is not in datafile.'; export const INVALID_GROUP_ID = 'Group ID %s is not in datafile.'; export const INVALID_LOGGER = 'Provided "logger" is in an invalid format.'; -export const INVALID_ROLLOUT_ID = 'Invalid rollout ID %s attached to feature %s'; export const INVALID_USER_ID = 'Provided user ID is in an invalid format.'; export const INVALID_USER_PROFILE_SERVICE = 'Provided user profile service instance is in an invalid format: %s.'; export const LOCAL_STORAGE_DOES_NOT_EXIST = 'Error accessing window localStorage.'; @@ -114,7 +112,6 @@ export const VARIABLE_REQUESTED_WITH_WRONG_TYPE = 'Requested variable type "%s", but variable is of type "%s". Use correct API to retrieve value. Returning None.'; export const UNEXPECTED_RESERVED_ATTRIBUTE_PREFIX = 'Attribute %s unexpectedly has reserved prefix %s; using attribute ID instead of reserved attribute name.'; -export const FORCED_BUCKETING_FAILED = 'Variation key %s is not in datafile. Not activating user %s.'; export const BUCKETING_ID_NOT_STRING = 'BucketingID attribute is not a string. Defaulted to userId'; export const UNEXPECTED_CONDITION_VALUE = 'Audience condition %s evaluated to UNKNOWN because the condition value is not supported.'; diff --git a/lib/exception_messages.ts b/lib/exception_messages.ts deleted file mode 100644 index 2ce6c03f8..000000000 --- a/lib/exception_messages.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright 2024, 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 - * - * https://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. - */ - - diff --git a/lib/index.browser.tests.js b/lib/index.browser.tests.js index cc6c34cd0..5fb84a30f 100644 --- a/lib/index.browser.tests.js +++ b/lib/index.browser.tests.js @@ -22,8 +22,6 @@ import optimizelyFactory from './index.browser'; import configValidator from './utils/config_validator'; import { getMockProjectConfigManager } from './tests/mock/mock_project_config_manager'; import { createProjectConfig } from './project_config/project_config'; -import { INVALID_CONFIG_OR_SOMETHING } from './exception_messages'; - class MockLocalStorage { store = {}; @@ -134,7 +132,7 @@ describe('javascript-sdk (Browser)', function() { // }); it('should not throw if the provided config is not valid', function() { - configValidator.validate.throws(new Error(INVALID_CONFIG_OR_SOMETHING)); + configValidator.validate.throws(new Error('INVALID_CONFIG_OR_SOMETHING')); assert.doesNotThrow(function() { var optlyInstance = optimizelyFactory.createInstance({ projectConfigManager: getMockProjectConfigManager(), diff --git a/lib/index.browser.ts b/lib/index.browser.ts index 054c584d8..c25971393 100644 --- a/lib/index.browser.ts +++ b/lib/index.browser.ts @@ -19,7 +19,6 @@ import defaultErrorHandler from './plugins/error_handler'; import defaultEventDispatcher from './event_processor/event_dispatcher/default_dispatcher.browser'; import sendBeaconEventDispatcher from './event_processor/event_dispatcher/send_beacon_dispatcher.browser'; import * as enums from './utils/enums'; -import { createNotificationCenter } from './notification_center'; import { OptimizelyDecideOption, Client, Config, OptimizelyOptions } from './shared_types'; import Optimizely from './optimizely'; import { UserAgentParser } from './odp/ua_parser/user_agent_parser'; @@ -37,7 +36,6 @@ import { LoggerFacade } from './logging/logger'; import { Maybe } from './utils/type'; -const MODULE_NAME = 'INDEX_BROWSER'; const DEFAULT_EVENT_BATCH_SIZE = 10; const DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; diff --git a/lib/index.node.tests.js b/lib/index.node.tests.js index 6d2bba594..f35903418 100644 --- a/lib/index.node.tests.js +++ b/lib/index.node.tests.js @@ -21,7 +21,6 @@ import testData from './tests/test_data'; import optimizelyFactory from './index.node'; import configValidator from './utils/config_validator'; import { getMockProjectConfigManager } from './tests/mock/mock_project_config_manager'; -import { INVALID_CONFIG_OR_SOMETHING } from './exception_messages'; var createLogger = () => ({ debug: () => {}, @@ -70,7 +69,7 @@ describe('optimizelyFactory', function() { // }); it('should not throw if the provided config is not valid', function() { - configValidator.validate.throws(new Error(INVALID_CONFIG_OR_SOMETHING)); + configValidator.validate.throws(new Error('INVALID_CONFIG_OR_SOMETHING')); assert.doesNotThrow(function() { var optlyInstance = optimizelyFactory.createInstance({ projectConfigManager: getMockProjectConfigManager(), diff --git a/lib/log_messages.ts b/lib/log_messages.ts index d5830cba7..6123adc74 100644 --- a/lib/log_messages.ts +++ b/lib/log_messages.ts @@ -18,16 +18,13 @@ export const ACTIVATE_USER = '%s: Activating user %s in experiment %s.'; export const DISPATCH_CONVERSION_EVENT = '%s: Dispatching conversion event to URL %s with params %s.'; export const DISPATCH_IMPRESSION_EVENT = '%s: Dispatching impression event to URL %s with params %s.'; export const DEPRECATED_EVENT_VALUE = '%s: Event value is deprecated in %s call.'; -export const EXPERIMENT_NOT_RUNNING = 'Experiment %s is not running.'; export const FEATURE_ENABLED_FOR_USER = 'Feature %s is enabled for user %s.'; export const FEATURE_NOT_ENABLED_FOR_USER = 'Feature %s is not enabled for user %s.'; -export const FEATURE_HAS_NO_EXPERIMENTS = 'Feature %s is not attached to any experiments.'; export const FAILED_TO_PARSE_VALUE = '%s: Failed to parse event value "%s" from event tags.'; export const FAILED_TO_PARSE_REVENUE = 'Failed to parse revenue value "%s" from event tags.'; export const INVALID_CLIENT_ENGINE = 'Invalid client engine passed: %s. Defaulting to node-sdk.'; export const INVALID_DEFAULT_DECIDE_OPTIONS = '%s: Provided default decide options is not an array.'; export const INVALID_DECIDE_OPTIONS = 'Provided decide options is not an array. Using default decide options.'; -export const NO_ROLLOUT_EXISTS = 'There is no rollout of feature %s.'; export const NOT_ACTIVATING_USER = 'Not activating user %s for experiment %s.'; export const ODP_DISABLED = 'ODP Disabled.'; export const ODP_IDENTIFY_FAILED_ODP_DISABLED = '%s: ODP identify event for user %s is not dispatched (ODP disabled).'; @@ -37,9 +34,6 @@ export const ODP_SEND_EVENT_IDENTIFIER_CONVERSION_FAILED = '%s: sendOdpEvent failed to parse through and convert fs_user_id aliases'; export const PARSED_REVENUE_VALUE = 'Parsed revenue value "%s" from event tags.'; export const PARSED_NUMERIC_VALUE = 'Parsed event value "%s" from event tags.'; -export const RETURNING_STORED_VARIATION = - 'Returning previously activated variation "%s" of experiment "%s" for user "%s" from user profile.'; -export const ROLLOUT_HAS_NO_EXPERIMENTS = 'Rollout of feature %s has no experiments'; export const SAVED_USER_VARIATION = 'Saved user profile for user "%s".'; export const UPDATED_USER_VARIATION = '%s: Updated variation "%s" of experiment "%s" for user "%s".'; export const SAVED_VARIATION_NOT_FOUND = @@ -47,21 +41,12 @@ export const SAVED_VARIATION_NOT_FOUND = export const SHOULD_NOT_DISPATCH_ACTIVATE = 'Experiment %s is not in "Running" state. Not activating user.'; export const SKIPPING_JSON_VALIDATION = 'Skipping JSON schema validation.'; export const TRACK_EVENT = 'Tracking event %s for user %s.'; -export const USER_BUCKETED_INTO_TARGETING_RULE = 'User %s bucketed into targeting rule %s.'; export const USER_IN_FEATURE_EXPERIMENT = '%s: User %s is in variation %s of experiment %s on the feature %s.'; -export const USER_IN_ROLLOUT = 'User %s is in rollout of feature %s.'; export const USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE = '%s: User %s not bucketed into everyone targeting rule due to traffic allocation.'; export const USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP = '%s: User %s is not in any experiment of group %s.'; -export const USER_NOT_BUCKETED_INTO_TARGETING_RULE = - 'User %s not bucketed into targeting rule %s due to traffic allocation. Trying everyone rule.'; -export const USER_FORCED_IN_VARIATION = 'User %s is forced in variation %s.'; export const USER_MAPPED_TO_FORCED_VARIATION = 'Set variation %s for experiment %s and user %s in the forced variation map.'; -export const USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE = - 'User %s does not meet conditions for targeting rule %s.'; -export const USER_MEETS_CONDITIONS_FOR_TARGETING_RULE = 'User %s meets conditions for targeting rule %s.'; -export const USER_HAS_VARIATION = 'User %s is in variation %s of experiment %s.'; export const USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED = 'Variation (%s) is mapped to flag (%s), rule (%s) and user (%s) in the forced decision map.'; export const USER_HAS_FORCED_DECISION_WITH_NO_RULE_SPECIFIED = @@ -70,14 +55,7 @@ export const USER_HAS_FORCED_DECISION_WITH_RULE_SPECIFIED_BUT_INVALID = 'Invalid variation is mapped to flag (%s), rule (%s) and user (%s) in the forced decision map.'; export const USER_HAS_FORCED_DECISION_WITH_NO_RULE_SPECIFIED_BUT_INVALID = 'Invalid variation is mapped to flag (%s) and user (%s) in the forced decision map.'; -export const USER_HAS_FORCED_VARIATION = - 'Variation %s is mapped to experiment %s and user %s in the forced variation map.'; -export const USER_HAS_NO_VARIATION = 'User %s is in no variation of experiment %s.'; export const USER_HAS_NO_FORCED_VARIATION = 'User %s is not in the forced variation map.'; -export const USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT = - 'No experiment %s mapped to user %s in the forced variation map.'; -export const USER_NOT_IN_EXPERIMENT = 'User %s does not meet conditions to be in experiment %s.'; -export const USER_NOT_IN_ROLLOUT = 'User %s is not in rollout of feature %s.'; export const USER_RECEIVED_DEFAULT_VARIABLE_VALUE = 'User "%s" is not in any variation or rollout rule. Returning default value for variable "%s" of feature flag "%s".'; export const FEATURE_NOT_ENABLED_RETURN_DEFAULT_VARIABLE_VALUE = @@ -91,9 +69,7 @@ export const VARIATION_REMOVED_FOR_USER = 'Variation mapped to experiment %s has export const VALID_BUCKETING_ID = 'BucketingId is valid: "%s"'; export const EVALUATING_AUDIENCE = 'Starting to evaluate audience "%s" with conditions: %s.'; -export const EVALUATING_AUDIENCES_COMBINED = 'Evaluating audiences for %s "%s": %s.'; export const AUDIENCE_EVALUATION_RESULT = 'Audience "%s" evaluated to %s.'; -export const AUDIENCE_EVALUATION_RESULT_COMBINED = 'Audiences for %s %s collectively evaluated to %s.'; export const MISSING_ATTRIBUTE_VALUE = 'Audience condition %s evaluated to UNKNOWN because no value was passed for user attribute "%s".'; export const UNEXPECTED_TYPE_NULL = @@ -104,6 +80,8 @@ export const UNABLE_TO_PARSE_AND_SKIPPED_HEADER = 'Unable to parse & skipped hea export const ADDING_AUTHORIZATION_HEADER_WITH_BEARER_TOKEN = 'Adding Authorization header with Bearer Token'; export const MAKING_DATAFILE_REQ_TO_URL_WITH_HEADERS = 'Making datafile request to url %s with headers: %s'; export const RESPONSE_STATUS_CODE = 'Response status code: %s'; -export const SAVED_LAST_MODIFIED_HEADER_VALUE_FROM_RESPONSE = 'Saved last modified header value from response: %s'; +export const SAVED_LAST_MODIFIED_HEADER_VALUE_FROM_RESPONSE = 'Saved last modified header value from response: %s'; +export const USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT = + 'No experiment %s mapped to user %s in the forced variation map.'; export const messages: string[] = []; diff --git a/lib/notification_center/index.ts b/lib/notification_center/index.ts index 15886fde3..2db4d36d7 100644 --- a/lib/notification_center/index.ts +++ b/lib/notification_center/index.ts @@ -14,13 +14,8 @@ * limitations under the License. */ import { LoggerFacade } from '../logging/logger'; -import { ErrorHandler } from '../error/error_handler'; import { objectValues } from '../utils/fns'; -import { - LOG_LEVEL, -} from '../utils/enums'; - import { NOTIFICATION_TYPES } from './type'; import { NotificationType, NotificationPayload } from './type'; import { Consumer, Fn } from '../utils/type'; @@ -29,8 +24,6 @@ import { NOTIFICATION_LISTENER_EXCEPTION } from '../error_messages'; import { ErrorReporter } from '../error/error_reporter'; import { ErrorNotifier } from '../error/error_notifier'; -const MODULE_NAME = 'NOTIFICATION_CENTER'; - interface NotificationCenterOptions { logger?: LoggerFacade; errorNotifier?: ErrorNotifier; diff --git a/lib/optimizely/index.tests.js b/lib/optimizely/index.tests.js index 9f453bf1e..30d67cd72 100644 --- a/lib/optimizely/index.tests.js +++ b/lib/optimizely/index.tests.js @@ -36,27 +36,14 @@ import { createProjectConfig } from '../project_config/project_config'; import { getMockProjectConfigManager } from '../tests/mock/mock_project_config_manager'; import { DECISION_NOTIFICATION_TYPES } from '../notification_center/type'; import { - AUDIENCE_EVALUATION_RESULT_COMBINED, - EXPERIMENT_NOT_RUNNING, - FEATURE_HAS_NO_EXPERIMENTS, FEATURE_NOT_ENABLED_FOR_USER, INVALID_CLIENT_ENGINE, INVALID_DEFAULT_DECIDE_OPTIONS, INVALID_OBJECT, NOT_ACTIVATING_USER, - RETURNING_STORED_VARIATION, - USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, - USER_FORCED_IN_VARIATION, - USER_HAS_FORCED_VARIATION, USER_HAS_NO_FORCED_VARIATION, USER_HAS_NO_FORCED_VARIATION_FOR_EXPERIMENT, - USER_HAS_NO_VARIATION, - USER_HAS_VARIATION, - USER_IN_ROLLOUT, USER_MAPPED_TO_FORCED_VARIATION, - USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, - USER_NOT_BUCKETED_INTO_TARGETING_RULE, - USER_NOT_IN_EXPERIMENT, USER_RECEIVED_DEFAULT_VARIABLE_VALUE, VALID_USER_PROFILE_SERVICE, VARIATION_REMOVED_FOR_USER, @@ -70,13 +57,28 @@ import { INVALID_INPUT_FORMAT, NO_VARIATION_FOR_EXPERIMENT_KEY, USER_NOT_IN_FORCED_VARIATION, - FORCED_BUCKETING_FAILED, INSTANCE_CLOSED, ONREADY_TIMEOUT_EXPIRED, } from '../error_messages'; -import { FAILED_TO_STOP, PROMISE_SHOULD_NOT_HAVE_RESOLVED } from '../exception_messages'; + +import { + AUDIENCE_EVALUATION_RESULT_COMBINED, + USER_NOT_IN_EXPERIMENT, + FEATURE_HAS_NO_EXPERIMENTS, + USER_HAS_NO_VARIATION, + USER_HAS_VARIATION, + USER_NOT_BUCKETED_INTO_TARGETING_RULE, + USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, + USER_IN_ROLLOUT, + USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, + FORCED_BUCKETING_FAILED, + USER_HAS_FORCED_VARIATION, + USER_FORCED_IN_VARIATION, + RETURNING_STORED_VARIATION, + EXPERIMENT_NOT_RUNNING, +} from '../core/decision_service'; + import { USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP } from '../core/bucketer'; -import { error } from 'console'; var LOG_LEVEL = enums.LOG_LEVEL; var DECISION_SOURCES = enums.DECISION_SOURCES; @@ -5069,7 +5071,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(EXPERIMENT_NOT_RUNNING, 'DECISION_SERVICE', 'exp_with_audience') + sprintf(EXPERIMENT_NOT_RUNNING, 'exp_with_audience') ); }); @@ -5114,7 +5116,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstanceWithUserProfile.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(RETURNING_STORED_VARIATION, 'DECISION_SERVICE', variationKey2, experimentKey, userId) + sprintf(RETURNING_STORED_VARIATION, variationKey2, experimentKey, userId) ); }); @@ -5130,7 +5132,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_FORCED_IN_VARIATION, 'DECISION_SERVICE', userId, variationKey) + sprintf(USER_FORCED_IN_VARIATION, userId, variationKey) ); }); @@ -5148,7 +5150,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_HAS_FORCED_VARIATION, 'DECISION_SERVICE', variationKey, experimentKey, userId) + sprintf(USER_HAS_FORCED_VARIATION, variationKey, experimentKey, userId) ); }); @@ -5165,7 +5167,7 @@ describe('lib/optimizely', function() { var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(FORCED_BUCKETING_FAILED, 'DECISION_SERVICE', variationKey, userId) + sprintf(FORCED_BUCKETING_FAILED, variationKey, userId) ); }); @@ -5178,7 +5180,7 @@ describe('lib/optimizely', function() { user.setAttribute('country', 'US'); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, 'DECISION_SERVICE', userId, '1') + sprintf(USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, userId, '1') ); }); @@ -5191,7 +5193,7 @@ describe('lib/optimizely', function() { user.setAttribute('country', 'CA'); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, 'DECISION_SERVICE', userId, '1') + sprintf(USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE, userId, '1') ); }); @@ -5204,7 +5206,7 @@ describe('lib/optimizely', function() { user.setAttribute('country', 'US'); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_IN_ROLLOUT, 'DECISION_SERVICE', userId, flagKey) + sprintf(USER_IN_ROLLOUT, userId, flagKey) ); }); @@ -5217,7 +5219,7 @@ describe('lib/optimizely', function() { user.setAttribute('country', 'KO'); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, 'DECISION_SERVICE', userId, 'Everyone Else') + sprintf(USER_MEETS_CONDITIONS_FOR_TARGETING_RULE, userId, 'Everyone Else') ); }); @@ -5230,7 +5232,7 @@ describe('lib/optimizely', function() { user.setAttribute('browser', 'safari'); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_NOT_BUCKETED_INTO_TARGETING_RULE, 'DECISION_SERVICE', userId, '2') + sprintf(USER_NOT_BUCKETED_INTO_TARGETING_RULE, userId, '2') ); }); @@ -5244,7 +5246,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_HAS_VARIATION, 'DECISION_SERVICE', userId, variationKey, experimentKey) + sprintf(USER_HAS_VARIATION, userId, variationKey, experimentKey) ); }); @@ -5262,7 +5264,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_HAS_NO_VARIATION, 'DECISION_SERVICE', userId, experimentKey) + sprintf(USER_HAS_NO_VARIATION, userId, experimentKey) ); }); @@ -5280,7 +5282,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, 'BUCKETER', userId, experimentKey, groupId) + sprintf(USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP, userId, experimentKey, groupId) ); }); @@ -5295,7 +5297,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(FEATURE_HAS_NO_EXPERIMENTS, 'DECISION_SERVICE', flagKey) + sprintf(FEATURE_HAS_NO_EXPERIMENTS, flagKey) ); }); @@ -5308,7 +5310,7 @@ describe('lib/optimizely', function() { }); var decision = optlyInstance.decide(user, flagKey); expect(decision.reasons).to.include( - sprintf(USER_NOT_IN_EXPERIMENT, 'DECISION_SERVICE', userId, experimentKey) + sprintf(USER_NOT_IN_EXPERIMENT, userId, experimentKey) ); }); @@ -5328,7 +5330,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5353,7 +5354,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5378,7 +5378,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5403,7 +5402,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5428,7 +5426,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5453,7 +5450,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5478,7 +5474,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -5502,7 +5497,6 @@ describe('lib/optimizely', function() { expect(decision.reasons).to.include( sprintf( AUDIENCE_EVALUATION_RESULT_COMBINED, - 'DECISION_SERVICE', 'experiment', experimentKey, 'FALSE' @@ -9288,7 +9282,7 @@ describe('lib/optimizely', function() { describe('when the event processor onTerminated() method returns a promise that rejects', function() { beforeEach(function() { - eventProcessorStopPromise = Promise.reject(new Error(FAILED_TO_STOP)); + eventProcessorStopPromise = Promise.reject(new Error('FAILED_TO_STOP')); eventProcessorStopPromise.catch(() => {}); mockEventProcessor.onTerminated.returns(eventProcessorStopPromise); const mockConfigManager = getMockProjectConfigManager({ @@ -9470,7 +9464,7 @@ describe('lib/optimizely', function() { var readyPromise = optlyInstance.onReady({ timeout: 500 }); clock.tick(501); return readyPromise.then(() => { - return Promise.reject(new Error(PROMISE_SHOULD_NOT_HAVE_RESOLVED)); + return Promise.reject(new Error('PROMISE_SHOULD_NOT_HAVE_RESOLVED')); }, (err) => { assert.equal(err.baseMessage, ONREADY_TIMEOUT_EXPIRED); assert.deepEqual(err.params, [ 500 ]); diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index 901adde9b..87da57af7 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -52,7 +52,6 @@ import * as stringValidator from '../utils/string_value_validator'; import * as decision from '../core/decision'; import { - LOG_LEVEL, DECISION_SOURCES, DECISION_MESSAGES, FEATURE_VARIABLE_TYPES, @@ -103,8 +102,6 @@ import { ErrorNotifier } from '../error/error_notifier'; import { ErrorReporter } from '../error/error_reporter'; import { OptimizelyError } from '../error/optimizly_error'; -const MODULE_NAME = 'OPTIMIZELY'; - const DEFAULT_ONREADY_TIMEOUT = 30000; // TODO: Make feature_key, user_id, variable_key, experiment_key, event_key camelCase @@ -378,7 +375,7 @@ export default class Optimizely implements Client { } if (!this.isValidInstance()) { - this.logger?.error(INVALID_OBJECT, MODULE_NAME, 'track'); + this.logger?.error(INVALID_OBJECT, 'track'); return; } @@ -1046,7 +1043,7 @@ export default class Optimizely implements Client { ): string | null { try { if (!this.isValidInstance()) { - this.logger?.error(INVALID_OBJECT, MODULE_NAME, 'getFeatureVariableString'); + this.logger?.error(INVALID_OBJECT, 'getFeatureVariableString'); return null; } return this.getFeatureVariableForType( @@ -1574,7 +1571,7 @@ export default class Optimizely implements Client { if (!feature) { this.logger?.error(FEATURE_NOT_IN_DATAFILE, key); decisionMap[key] = newErrorDecision(key, user, [sprintf(DECISION_MESSAGES.FLAG_KEY_INVALID, key)]); - continue + continue; } validKeys.push(key); @@ -1626,7 +1623,7 @@ export default class Optimizely implements Client { const configObj = this.projectConfigManager.getConfig(); const decisionMap: { [key: string]: OptimizelyDecision } = {}; if (!this.isValidInstance() || !configObj) { - this.logger?.error(INVALID_OBJECT, MODULE_NAME, 'decideAll'); + this.logger?.error(INVALID_OBJECT, 'decideAll'); return decisionMap; } diff --git a/lib/project_config/project_config.ts b/lib/project_config/project_config.ts index a45cc5dae..1a7ad4313 100644 --- a/lib/project_config/project_config.ts +++ b/lib/project_config/project_config.ts @@ -110,7 +110,6 @@ export interface ProjectConfig { const EXPERIMENT_RUNNING_STATUS = 'Running'; const RESERVED_ATTRIBUTE_PREFIX = '$opt_'; -const MODULE_NAME = 'PROJECT_CONFIG'; // eslint-disable-next-line @typescript-eslint/no-explicit-any function createMutationSafeDatafileCopy(datafile: any): ProjectConfig { @@ -837,7 +836,7 @@ export const tryCreatingProjectConfig = function( config.jsonSchemaValidator(newDatafileObj); config.logger?.info(VALID_DATAFILE); } else { - config.logger?.info(SKIPPING_JSON_VALIDATION, MODULE_NAME); + config.logger?.info(SKIPPING_JSON_VALIDATION); } const createProjectConfigArgs = [newDatafileObj]; diff --git a/lib/utils/attributes_validator/index.ts b/lib/utils/attributes_validator/index.ts index f3d887304..adbe70bdb 100644 --- a/lib/utils/attributes_validator/index.ts +++ b/lib/utils/attributes_validator/index.ts @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { sprintf } from '../../utils/fns'; import { ObjectWithUnknownProperties } from '../../shared_types'; import fns from '../../utils/fns'; import { INVALID_ATTRIBUTES, UNDEFINED_ATTRIBUTE } from '../../error_messages'; import { OptimizelyError } from '../../error/optimizly_error'; -const MODULE_NAME = 'ATTRIBUTES_VALIDATOR'; - /** * Validates user's provided attributes * @param {unknown} attributes diff --git a/lib/utils/config_validator/index.ts b/lib/utils/config_validator/index.ts index a005476e9..a61d4f1cf 100644 --- a/lib/utils/config_validator/index.ts +++ b/lib/utils/config_validator/index.ts @@ -29,7 +29,6 @@ import { } from '../../error_messages'; import { OptimizelyError } from '../../error/optimizly_error'; -const MODULE_NAME = 'CONFIG_VALIDATOR'; const SUPPORTED_VERSIONS = [DATAFILE_VERSIONS.V2, DATAFILE_VERSIONS.V3, DATAFILE_VERSIONS.V4]; /** diff --git a/lib/utils/event_tag_utils/index.ts b/lib/utils/event_tag_utils/index.ts index c8fc9835f..8819086a9 100644 --- a/lib/utils/event_tag_utils/index.ts +++ b/lib/utils/event_tag_utils/index.ts @@ -23,14 +23,12 @@ import { EventTags } from '../../event_processor/event_builder/user_event'; import { LoggerFacade } from '../../logging/logger'; import { - LOG_LEVEL, RESERVED_EVENT_KEYWORDS, } from '../enums'; /** * Provides utility method for parsing event tag values */ -const MODULE_NAME = 'EVENT_TAG_UTILS'; const REVENUE_EVENT_METRIC_NAME = RESERVED_EVENT_KEYWORDS.REVENUE; const VALUE_EVENT_METRIC_NAME = RESERVED_EVENT_KEYWORDS.VALUE; diff --git a/lib/utils/http_request_handler/request_handler.node.ts b/lib/utils/http_request_handler/request_handler.node.ts index e399221fc..cf0a620db 100644 --- a/lib/utils/http_request_handler/request_handler.node.ts +++ b/lib/utils/http_request_handler/request_handler.node.ts @@ -20,7 +20,6 @@ import { AbortableRequest, Headers, RequestHandler, Response } from './http'; import decompressResponse from 'decompress-response'; import { LoggerFacade } from '../../logging/logger'; import { REQUEST_TIMEOUT_MS } from '../enums'; -import { sprintf } from '../fns'; import { NO_STATUS_CODE_IN_RESPONSE, REQUEST_ERROR, REQUEST_TIMEOUT, UNSUPPORTED_PROTOCOL } from '../../error_messages'; import { OptimizelyError } from '../../error/optimizly_error'; @@ -49,7 +48,7 @@ export class NodeRequestHandler implements RequestHandler { if (parsedUrl.protocol !== 'https:') { return { - responsePromise: Promise.reject(new Error(sprintf(UNSUPPORTED_PROTOCOL, parsedUrl.protocol))), + responsePromise: Promise.reject(new OptimizelyError(UNSUPPORTED_PROTOCOL, parsedUrl.protocol)), abort: () => {}, }; } @@ -167,7 +166,7 @@ export class NodeRequestHandler implements RequestHandler { } if (!incomingMessage.statusCode) { - reject(new Error(NO_STATUS_CODE_IN_RESPONSE)); + reject(new OptimizelyError(NO_STATUS_CODE_IN_RESPONSE)); return; } diff --git a/lib/utils/json_schema_validator/index.ts b/lib/utils/json_schema_validator/index.ts index 3e4809cd8..f5824931c 100644 --- a/lib/utils/json_schema_validator/index.ts +++ b/lib/utils/json_schema_validator/index.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { sprintf } from '../fns'; import { JSONSchema4, validate as jsonSchemaValidator } from 'json-schema'; import schema from '../../project_config/project_config_schema'; diff --git a/lib/utils/semantic_version/index.ts b/lib/utils/semantic_version/index.ts index ecd7bb804..2e5e02e47 100644 --- a/lib/utils/semantic_version/index.ts +++ b/lib/utils/semantic_version/index.ts @@ -17,8 +17,6 @@ import { UNKNOWN_MATCH_TYPE } from '../../error_messages'; import { LoggerFacade } from '../../logging/logger'; import { VERSION_TYPE } from '../enums'; -const MODULE_NAME = 'SEMANTIC VERSION'; - /** * Evaluate if provided string is number only * @param {unknown} content