Skip to content

feat: Convert optimizely module to TS #576

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

Merged
merged 9 commits into from
Oct 5, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Fix indentation and remove unnecessary if statement
  • Loading branch information
yavorona committed Oct 5, 2020
commit 01a9e5d9e4bd3540944d13c2ad3b2bc6cae09f4c
27 changes: 12 additions & 15 deletions packages/optimizely-sdk/lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,19 @@ export default class Optimizely {
eventTags?: unknown
): boolean {
try {
// Null, undefined or non-string user Id is invalid.
if (typeof stringInputs === 'object' && stringInputs !== null) {
if (stringInputs.hasOwnProperty('user_id')) {
const userId = stringInputs['user_id'];
if (typeof userId !== 'string' || userId === null || userId === 'undefined') {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, 'user_id'));
}

delete stringInputs['user_id'];
if (stringInputs.hasOwnProperty('user_id')) {
const userId = stringInputs['user_id'];
if (typeof userId !== 'string' || userId === null || userId === 'undefined') {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, 'user_id'));
}
Object.keys(stringInputs).forEach(key => {
if (!stringValidator.validate(stringInputs[key])) {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, key));
}
})

delete stringInputs['user_id'];
}
Object.keys(stringInputs).forEach(key => {
if (!stringValidator.validate(stringInputs[key])) {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_INPUT_FORMAT, MODULE_NAME, key));
}
})
if (userAttributes) {
validate(userAttributes);
}
Expand Down Expand Up @@ -1343,7 +1340,7 @@ export default class Optimizely {
let resolveTimeoutPromise: (value: OnReadyResult) => void;
const timeoutPromise = new Promise<OnReadyResult>(
(resolve) => {
resolveTimeoutPromise = resolve;
resolveTimeoutPromise = resolve;
}
);

Expand Down