8000 [FSSDK-8284] Add allowed types to UserAttributes (#886) · optimizely/javascript-sdk@2b40193 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b40193

Browse files
authored
[FSSDK-8284] Add allowed types to UserAttributes (#886)
1 parent 01b099b commit 2b40193

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

lib/core/custom_attribute_condition_evaluator/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function greaterThanEvaluator(condition: Condition, user: OptimizelyUserContext)
241241
if (!validateValuesForNumericCondition(condition, user) || conditionValue === null) {
242242
return null;
243243
}
244-
return userValue > conditionValue;
244+
return userValue! > conditionValue;
245245
}
246246

247247
/**
@@ -262,7 +262,7 @@ function greaterThanOrEqualEvaluator(condition: Condition, user: OptimizelyUserC
262262
return null;
263263
}
264264

265-
return userValue >= conditionValue;
265+
return userValue! >= conditionValue;
266266
}
267267

268268
/**
@@ -283,7 +283,7 @@ function lessThanEvaluator(condition: Condition, user: OptimizelyUserContext): b
283283
return null;
284284
}
285285

286-
return userValue < conditionValue;
286+
return userValue! < conditionValue;
287287
}
288288

289289
/**
@@ -304,7 +304,7 @@ function lessThanOrEqualEvaluator(condition: Condition, user: OptimizelyUserCont
304304
return null;
305305
}
306306

307-
return userValue <= conditionValue;
307+
return userValue! <= conditionValue;
308308
}
309309

310310
/**

lib/core/decision_service/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ export class DecisionService {
766766
attributes.hasOwnProperty(CONTROL_ATTRIBUTES.BUCKETING_ID)
767767
) {
768768
if (typeof attributes[CONTROL_ATTRIBUTES.BUCKETING_ID] === 'string') {
769-
bucketingId = attributes[CONTROL_ATTRIBUTES.BUCKETING_ID];
769+
bucketingId = String(attributes[CONTROL_ATTRIBUTES.BUCKETING_ID]);
770770
this.logger.log(LOG_LEVEL.DEBUG, LOG_MESSAGES.VALID_BUCKETING_ID, MODULE_NAME, bucketingId);
771771
} else {
772772
this.logger.log(LOG_LEVEL.WARNING, LOG_MESSAGES.BUCKETING_ID_NOT_STRING, MODULE_NAME);

lib/core/event_builder/event_helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function buildVisitorAttributes(
245245
builtAttributes.push({
246246
entityId: attributeId,
247247
key: attributeKey,
248-
value: attributes[attributeKey],
248+
value: attributeValue!,
249249
});
250250
}
251251
}

lib/core/event_builder/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function getCommonEventParams({
157157
entity_id: attributeId,
158158
key: attributeKey,
159159
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
160-
value: attributes[attributeKey],
160+
value: attributeValue!,
161161
});
162162
}
163163
}

lib/export_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
export {
22+
UserAttributeValue,
2223
UserAttributes,
2324
OptimizelyConfig,
2425
OptimizelyVariable,

lib/optimizely_user_context/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
OptimizelyDecision,
2121
OptimizelyDecisionContext,
2222
OptimizelyForcedDecision,
23+
UserAttributeValue,
2324
UserAttributes,
2425
} from '../shared_types';
2526
import { CONTROL_ATTRIBUTES } from '../utils/enums';
@@ -80,7 +81,7 @@ export default class OptimizelyUserContext implements IOptimizelyUserContext {
8081
* @param {string} key An attribute key
8182
* @param {any} value An attribute value
8283
*/
83-
setAttribute(key: string, value: unknown): void {
84+
setAttribute(key: string, value: UserAttributeValue): void {
8485
this.attributes[key] = value;
8586
}
8687

lib/shared_types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export interface DecisionResponse<T> {
5555
readonly reasons: (string | number)[][];
5656
}
5757

58+
export type UserAttributeValue = string | number | boolean | null;
59+
5860
export type UserAttributes = {
59-
// TODO[OASIS-6649]: Don't use any type
60-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
61-
[name: string]: any;
61+
[name: string]: UserAttributeValue;
6262
};
6363

6464
export interface ExperimentBucketMap {

0 commit comments

Comments
 (0)
0