From e557f80a813ad34f39d228bfb573faa92e7858d7 Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 22 Dec 2023 22:38:19 +0600 Subject: [PATCH 1/2] [FSSDK-8284] Add allowed types to UserAttributes --- lib/core/custom_attribute_condition_evaluator/index.ts | 8 ++++---- lib/core/decision_service/index.ts | 2 +- lib/core/event_builder/event_helpers.ts | 2 +- lib/core/event_builder/index.ts | 2 +- lib/export_types.ts | 1 + lib/optimizely_user_context/index.ts | 3 ++- lib/shared_types.ts | 4 +++- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/core/custom_attribute_condition_evaluator/index.ts b/lib/core/custom_attribute_condition_evaluator/index.ts index 775be8ad7..a887a2633 100644 --- a/lib/core/custom_attribute_condition_evaluator/index.ts +++ b/lib/core/custom_attribute_condition_evaluator/index.ts @@ -241,7 +241,7 @@ function greaterThanEvaluator(condition: Condition, user: OptimizelyUserContext) if (!validateValuesForNumericCondition(condition, user) || conditionValue === null) { return null; } - return userValue > conditionValue; + return userValue! > conditionValue; } /** @@ -262,7 +262,7 @@ function greaterThanOrEqualEvaluator(condition: Condition, user: OptimizelyUserC return null; } - return userValue >= conditionValue; + return userValue! >= conditionValue; } /** @@ -283,7 +283,7 @@ function lessThanEvaluator(condition: Condition, user: OptimizelyUserContext): b return null; } - return userValue < conditionValue; + return userValue! < conditionValue; } /** @@ -304,7 +304,7 @@ function lessThanOrEqualEvaluator(condition: Condition, user: OptimizelyUserCont return null; } - return userValue <= conditionValue; + return userValue! <= conditionValue; } /** diff --git a/lib/core/decision_service/index.ts b/lib/core/decision_service/index.ts index 2c126c04a..28f97a09e 100644 --- a/lib/core/decision_service/index.ts +++ b/lib/core/decision_service/index.ts @@ -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); diff --git a/lib/core/event_builder/event_helpers.ts b/lib/core/event_builder/event_helpers.ts index e6f57fdbd..071a1427a 100644 --- a/lib/core/event_builder/event_helpers.ts +++ b/lib/core/event_builder/event_helpers.ts @@ -245,7 +245,7 @@ function buildVisitorAttributes( builtAttributes.push({ entityId: attributeId, key: attributeKey, - value: attributes[attributeKey], + value: attributeValue!, }); } } diff --git a/lib/core/event_builder/index.ts b/lib/core/event_builder/index.ts index 093994aa0..cd6781529 100644 --- a/lib/core/event_builder/index.ts +++ b/lib/core/event_builder/index.ts @@ -157,7 +157,7 @@ function getCommonEventParams({ entity_id: attributeId, key: attributeKey, type: CUSTOM_ATTRIBUTE_FEATURE_TYPE, - value: attributes[attributeKey], + value: attributeValue!, }); } } diff --git a/lib/export_types.ts b/lib/export_types.ts index a41272060..cfd498591 100644 --- a/lib/export_types.ts +++ b/lib/export_types.ts @@ -19,6 +19,7 @@ */ export { + UserAttributeValue, UserAttributes, OptimizelyConfig, OptimizelyVariable, diff --git a/lib/optimizely_user_context/index.ts b/lib/optimizely_user_context/index.ts index a60cb7cf7..96f6bc3c2 100644 --- a/lib/optimizely_user_context/index.ts +++ b/lib/optimizely_user_context/index.ts @@ -20,6 +20,7 @@ import { OptimizelyDecision, OptimizelyDecisionContext, OptimizelyForcedDecision, + UserAttributeValue, UserAttributes, } from '../shared_types'; import { CONTROL_ATTRIBUTES } from '../utils/enums'; @@ -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; } diff --git a/lib/shared_types.ts b/lib/shared_types.ts index d62c0b1c9..c5785f3e1 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -55,10 +55,12 @@ export interface DecisionResponse { 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 { From 468dfef2fb30200a1963e568ac63814a47ccf7cd Mon Sep 17 00:00:00 2001 From: Raju Ahmed Date: Fri, 22 Dec 2023 23:45:17 +0600 Subject: [PATCH 2/2] remove comment --- lib/shared_types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/shared_types.ts b/lib/shared_types.ts index c5785f3e1..5caf705f9 100644 --- a/lib/shared_types.ts +++ b/lib/shared_types.ts @@ -58,8 +58,6 @@ export interface DecisionResponse { 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]: UserAttributeValue; };