Skip to content

Commit

Permalink
[FSSDK-8284] Add allowed types to UserAttributes (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
raju-opti authored Dec 22, 2023
1 parent 01b099b commit 2b40193
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/core/custom_attribute_condition_evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function greaterThanEvaluator(condition: Condition, user: OptimizelyUserContext)
if (!validateValuesForNumericCondition(condition, user) || conditionValue === null) {
return null;
}
return userValue > conditionValue;
return userValue! > conditionValue;

Check warning on line 244 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 244 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Forbidden non-null assertion

Check warning on line 244 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Forbidden non-null assertion

Check warning on line 244 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Forbidden non-null assertion
}

/**
Expand All @@ -262,7 +262,7 @@ function greaterThanOrEqualEvaluator(condition: Condition, user: OptimizelyUserC
return null;
}

return userValue >= conditionValue;
return userValue! >= conditionValue;

Check warning on line 265 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 265 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Forbidden non-null assertion

Check warning on line 265 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Forbidden non-null assertion

Check warning on line 265 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Forbidden non-null assertion
}

/**
Expand All @@ -283,7 +283,7 @@ function lessThanEvaluator(condition: Condition, user: OptimizelyUserContext): b
return null;
}

return userValue < conditionValue;
return userValue! < conditionValue;

Check warning on line 286 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 286 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Forbidden non-null assertion

Check warning on line 286 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Forbidden non-null assertion

Check warning on line 286 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Forbidden non-null assertion
}

/**
Expand All @@ -304,7 +304,7 @@ function lessThanOrEqualEvaluator(condition: Condition, user: OptimizelyUserCont
return null;
}

return userValue <= conditionValue;
return userValue! <= conditionValue;

Check warning on line 307 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion

Check warning on line 307 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Forbidden non-null assertion

Check warning on line 307 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Forbidden non-null assertion

Check warning on line 307 in lib/core/custom_attribute_condition_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Forbidden non-null assertion
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/core/decision_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ export class DecisionService {
attributes.hasOwnProperty(CONTROL_ATTRIBUTES.BUCKETING_ID)
) {
if (typeof attributes[CONTROL_ATTRIBUTES.BUCKETING_ID] === 'string') {
bucketingId = attributes[CONTROL_ATTRIBUTES.BUCKETING_ID];
bucketingId = String(attributes[CONTROL_ATTRIBUTES.BUCKETING_ID]);
this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.VALID_BUCKETING_ID, MODULE_NAME, bucketingId);
} else {
this.logger.log(LOG_LEVEL.WARNING, LOG_MESSAGES.BUCKETING_ID_NOT_STRING, MODULE_NAME);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/event_builder/event_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function buildVisitorAttributes(
builtAttributes.push({
entityId: attributeId,
key: attributeKey,
value: attributes[attributeKey],
value: attributeValue!,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/event_builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function getCommonEventParams({
entity_id: attributeId,
key: attributeKey,
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
value: attributes[attributeKey],
value: attributeValue!,
});
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/export_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

export {
UserAttributeValue,
UserAttributes,
OptimizelyConfig,
OptimizelyVariable,
Expand Down
3 changes: 2 additions & 1 deletion lib/optimizely_user_context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
OptimizelyDecision,
OptimizelyDecisionContext,
OptimizelyForcedDecision,
UserAttributeValue,
UserAttributes,
} from '../shared_types';
import { CONTROL_ATTRIBUTES } from '../utils/enums';
Expand Down Expand Up @@ -80,7 +81,7 @@ export default class OptimizelyUserContext implements IOptimizelyUserContext {
* @param {string} key An attribute key
* @param {any} value An attribute value
*/
setAttribute(key: string, value: unknown): void {
setAttribute(key: string, value: UserAttributeValue): void {
this.attributes[key] = value;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export interface DecisionResponse<T> {
readonly reasons: (string | number)[][];
}

export type UserAttributeValue = string | number | boolean | null;

export type UserAttributes = {
// TODO[OASIS-6649]: Don't use any type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[name: string]: any;
[name: string]: UserAttributeValue;
};

export interface ExperimentBucketMap {
Expand Down

0 comments on commit 2b40193

Please sign in to comment.