Skip to content

Commit 345a4c3

Browse files
committed
fix build
1 parent cf87023 commit 345a4c3

File tree

15 files changed

+140
-270
lines changed

15 files changed

+140
-270
lines changed

lib/core/audience_evaluator/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class AudienceEvaluator {
4747
this.logger = logger;
4848
this.typeToEvaluatorMap = {
4949
...UNSTABLE_conditionEvaluators as any,
50-
custom_attribute: customAttributeConditionEvaluator,
51-
third_party_dimension: odpSegmentsConditionEvaluator,
50+
custom_attribute: customAttributeConditionEvaluator.getEvaluator(this.logger),
51+
third_party_dimension: odpSegmentsConditionEvaluator.getEvaluator(this.logger),
5252
};
5353
}
5454

lib/core/audience_evaluator/odp_segment_condition_evaluator/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,31 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616
import { UNKNOWN_MATCH_TYPE } from '../../../error_messages';
17-
import { getLogger } from '../../../modules/logging';
17+
import { LoggerFacade } from '../../../logging/logger';
1818
import { Condition, OptimizelyUserContext } from '../../../shared_types';
1919

2020
const MODULE_NAME = 'ODP_SEGMENT_CONDITION_EVALUATOR';
2121

22-
const logger = getLogger();
23-
2422
const QUALIFIED_MATCH_TYPE = 'qualified';
2523

2624
const MATCH_TYPES = [
2725
QUALIFIED_MATCH_TYPE,
2826
];
2927

3028
type ConditionEvaluator = (condition: Condition, user: OptimizelyUserContext) => boolean | null;
29+
type Evaluator = { evaluate: (condition: Condition, user: OptimizelyUserContext) => boolean | null; }
3130

3231
const EVALUATORS_BY_MATCH_TYPE: { [conditionType: string]: ConditionEvaluator | undefined } = {};
3332
EVALUATORS_BY_MATCH_TYPE[QUALIFIED_MATCH_TYPE] = qualifiedEvaluator;
3433

34+
export const getEvaluator = (logger?: LoggerFacade): Evaluator => {
35+
return {
36+
evaluate(condition: Condition, user: OptimizelyUserContext): boolean | null {
37+
return evaluate(condition, user, logger);
38+
}
39+
};
40+
}
41+
3542
/**
3643
* Given a custom attribute audience condition and user attributes, evaluate the
3744
* condition against the attributes.
@@ -41,10 +48,10 @@ EVALUATORS_BY_MATCH_TYPE[QUALIFIED_MATCH_TYPE] = qualifiedEvaluator;
4148
* null if the given user attributes and condition can't be evaluated
4249
* TODO: Change to accept and object with named properties
4350
*/
44-
export function evaluate(condition: Condition, user: OptimizelyUserContext): boolean | null {
51+
function evaluate(condition: Condition, user: OptimizelyUserContext, logger?: LoggerFacade): boolean | null {
4552
const conditionMatch = condition.match;
4653
if (typeof conditionMatch !== 'undefined' && MATCH_TYPES.indexOf(conditionMatch) === -1) {
47-
logger.warn(UNKNOWN_MATCH_TYPE, MODULE_NAME, JSON.stringify(condition));
54+
logger?.warn(UNKNOWN_MATCH_TYPE, JSON.stringify(condition));
4855
return null;
4956
}
5057

lib/core/bucketer/index.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
import { sprintf } from '../../utils/fns';
2121
import murmurhash from 'murmurhash';
22-
import { LogHandler } from '../../modules/logging';
22+
import { LoggerFacade } from '../../logging/logger';
2323
import {
2424
DecisionResponse,
2525
BucketerParams,
@@ -30,11 +30,11 @@ import {
3030
import { LOG_LEVEL } from '../../utils/enums';
3131
import { INVALID_BUCKETING_ID, INVALID_GROUP_ID } from '../../error_messages';
3232

33-
export const USER_NOT_IN_ANY_EXPERIMENT = '%s: User %s is not in any experiment of group %s.';
34-
export const USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP = '%s: User %s is not in experiment %s of group %s.';
35-
export const USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP = '%s: User %s is in experiment %s of group %s.';
36-
export const USER_ASSIGNED_TO_EXPERIMENT_BUCKET = '%s: Assigned bucket %s to user with bucketing ID %s.';
37-
export const INVALID_VARIATION_ID = '%s: Bucketed into an invalid variation ID. Returning null.';
33+
export const USER_NOT_IN_ANY_EXPERIMENT = 'User %s is not in any experiment of group %s.';
34+
export const USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP = 'User %s is not in experiment %s of group %s.';
35+
export const USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP = 'User %s is in experiment %s of group %s.';
36+
export const USER_ASSIGNED_TO_EXPERIMENT_BUCKET = 'Assigned bucket %s to user with bucketing ID %s.';
37+
export const INVALID_VARIATION_ID = 'Bucketed into an invalid variation ID. Returning null.';
3838

3939
const HASH_SEED = 1;
4040
const MAX_HASH_VALUE = Math.pow(2, 32);
@@ -78,8 +78,7 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
7878

7979
// Return if user is not bucketed into any experiment
8080
if (bucketedExperimentId === null) {
81-
bucketerParams.logger.log(
82-
LOG_LEVEL.INFO,
81+
bucketerParams.logger?.info(
8382
USER_NOT_IN_ANY_EXPERIMENT,
8483
MODULE_NAME,
8584
bucketerParams.userId,
@@ -99,10 +98,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
9998

10099
// Return if user is bucketed into a different experiment than the one specified
101100
if (bucketedExperimentId !== bucketerParams.experimentId) {
102-
bucketerParams.logger.log(
103-
LOG_LEVEL.INFO,
101+
bucketerParams.logger?.info(
104102
USER_NOT_BUCKETED_INTO_EXPERIMENT_IN_GROUP,
105-
MODULE_NAME,
106103
bucketerParams.userId,
107104
bucketerParams.experimentKey,
108105
groupId,
@@ -121,10 +118,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
121118
}
122119

123120
// Continue bucketing if user is bucketed into specified experiment
124-
bucketerParams.logger.log(
125-
LOG_LEVEL.INFO,
121+
bucketerParams.logger?.info(
126122
USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP,
127-
MODULE_NAME,
128123
bucketerParams.userId,
129124
bucketerParams.experimentKey,
130125
groupId,
@@ -141,10 +136,8 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
141136
const bucketingId = `${bucketerParams.bucketingId}${bucketerParams.experimentId}`;
142137
const bucketValue = _generateBucketValue(bucketingId);
143138

144-
bucketerParams.logger.log(
145-
LOG_LEVEL.DEBUG,
139+
bucketerParams.logger?.debug(
146140
USER_ASSIGNED_TO_EXPERIMENT_BUCKET,
147-
MODULE_NAME,
148141
bucketValue,
149142
bucketerParams.userId,
150143
);
@@ -159,7 +152,7 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
159152
if (entityId !== null) {
160153
if (!bucketerParams.variationIdMap[entityId]) {
161154
if (entityId) {
162-
bucketerParams.logger.log(LOG_LEVEL.WARNING, INVALID_VARIATION_ID, MODULE_NAME);
155+
bucketerParams.logger?.warn(INVALID_VARIATION_ID, MODULE_NAME);
163156
decideReasons.push([INVALID_VARIATION_ID, MODULE_NAME]);
164157
}
165158
return {
@@ -180,21 +173,19 @@ export const bucket = function(bucketerParams: BucketerParams): DecisionResponse
180173
* @param {Group} group Group that experiment is in
181174
* @param {string} bucketingId Bucketing ID
182175
* @param {string} userId ID of user to be bucketed into experiment
183-
* @param {LogHandler} logger Logger implementation
176+
* @param {LoggerFacade} logger Logger implementation
184177
* @return {string|null} ID of experiment if user is bucketed into experiment within the group, null otherwise
185178
*/
186179
export const bucketUserIntoExperiment = function(
187180
group: Group,
188181
bucketingId: string,
189182
userId: string,
190-
logger: LogHandler
183+
logger?: LoggerFacade
191184
): string | null {
192185
const bucketingKey = `${bucketingId}${group.id}`;
193186
const bucketValue = _generateBucketValue(bucketingKey);
194-
logger.log(
195-
LOG_LEVEL.DEBUG,
187+
logger?.debug(
196188
USER_ASSIGNED_TO_EXPERIMENT_BUCKET,
197-
MODULE_NAME,
198189
bucketValue,
199190
userId,
200191
);

0 commit comments

Comments
 (0)