Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSSDK-8284] Add allowed types to UserAttributes #886

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 @@
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 @@ -484,7 +484,7 @@

try {
return this.userProfileService.lookup(userId);
} catch (ex: any) {

Check warning on line 487 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 487 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Unexpected any. Specify a different type

Check warning on line 487 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type

Check warning on line 487 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type
this.logger.log(
LOG_LEVEL.ERROR,
ERROR_MESSAGES.USER_PROFILE_LOOKUP_ERROR,
Expand Down Expand Up @@ -532,7 +532,7 @@
experiment.key,
userId,
);
} catch (ex: any) {

Check warning on line 535 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 535 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Unexpected any. Specify a different type

Check warning on line 535 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type

Check warning on line 535 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type
this.logger.log(LOG_LEVEL.ERROR, ERROR_MESSAGES.USER_PROFILE_SAVE_ERROR, MODULE_NAME, userId, ex.message);
}
}
Expand Down Expand Up @@ -766,7 +766,7 @@
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 Expand Up @@ -972,7 +972,7 @@
reasons: decideReasons,
};
}
} catch (ex: any) {

Check warning on line 975 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 975 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Unexpected any. Specify a different type

Check warning on line 975 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type

Check warning on line 975 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type
// catching experiment not in datafile
this.logger.log(LOG_LEVEL.ERROR, ex.message);
decideReasons.push(ex.message);
Expand Down Expand Up @@ -1065,7 +1065,7 @@
);
return false;
}
} catch (ex: any) {

Check warning on line 1068 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 1068 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (14)

Unexpected any. Specify a different type

Check warning on line 1068 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type

Check warning on line 1068 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type
// catching experiment not in datafile
this.logger.log(LOG_LEVEL.ERROR, ex.message);
return false;
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
Loading