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

chore: review validation checks #1991

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Amplitude/constants';
import { isDefinedAndNotNullAndNotEmpty } from '../../utils/commonUtils';
import { isDefinedAndNotNull, isDefinedAndNotNullAndNotEmpty } from '../../utils/commonUtils';
import Logger from '../../utils/logger';
import { loadNativeSdk } from './nativeSdkLoader';
import {
Expand Down Expand Up @@ -328,16 +328,16 @@ class Amplitude {
// else send price and quantity from properties to amplitude
// If price not present set price as revenue's value and force quantity to be 1.
// Ultimately set quantity to 1 if not already present from above logic.
if (!revenue && !price) {
if (!isDefinedAndNotNull(revenue) && !isDefinedAndNotNull(price)) {
logger.error('Neither "revenue" nor "price" is available. Hence, aborting');
return;
}

if (!price) {
if (!isDefinedAndNotNull(price)) {
price = revenue;
quantity = 1;
}
if (!quantity) {
if (!isDefinedAndNotNull(quantity)) {
quantity = 1;
}
const amplitudeRevenue = new window.amplitude.Revenue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Fullstory/constants';
import {
isDefined,
isDefinedAndNotNull,
isFunction,
isString,
} from '@rudderstack/analytics-js-common/utilities/checks';
import Logger from '../../utils/logger';
import camelcase from '../../utils/camelcase';
import { getDestinationOptions } from './utils';
Expand Down Expand Up @@ -88,7 +94,7 @@ class Fullstory {

(function () {
function fs(api) {
if (!window._fs_namespace) {
if (!isDefined(window._fs_namespace)) {
logger.error(`FullStory unavailable, window["_fs_namespace"] must be defined`);
return undefined;
}
Expand All @@ -115,9 +121,9 @@ class Fullstory {
const timeout = fullstoryIntgConfig.timeout || 2000;

function identify() {
if (typeof window._fs_identity === 'function') {
if (isFunction(window._fs_identity)) {
const userVars = window._fs_identity();
if (typeof userVars === 'object' && typeof userVars.uid === 'string') {
if (typeof userVars === 'object' && isString(userVars.uid)) {
fs('setUserVars')(userVars);
fs('restart')();
} else {
Expand Down Expand Up @@ -157,7 +163,7 @@ class Fullstory {
const { context, anonymousId } = rudderElement.message;
const { traits } = context;

if (!userId) userId = anonymousId;
if (!isDefinedAndNotNull(userId)) userId = anonymousId;
if (Object.keys(traits).length === 0 && traits.constructor === Object)
window.FS.identify(userId);
else window.FS.identify(userId, Fullstory.getFSProperties(traits));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NAME,
DISPLAY_NAME,
} from '@rudderstack/analytics-js-common/constants/integrations/Hotjar/constants';
import { isDefinedAndNotNull } from '@rudderstack/analytics-js-common/utilities/checks';
import Logger from '../../utils/logger';
import { loadNativeSdk } from './nativeSdkLoader';

Expand Down Expand Up @@ -40,7 +41,7 @@ class Hotjar {

identify(rudderElement) {
const userId = rudderElement.message.userId || rudderElement.message.anonymousId;
if (!userId) {
if (!isDefinedAndNotNull(userId)) {
logger.error('user id is required for an identify call');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ class Mixpanel {
*/
group(rudderElement) {
const { userId, groupId, traits } = rudderElement.message;
if (!userId) {
if (!isDefinedAndNotNull(userId)) {
logger.error('valid userId is required for group');
return;
}
if (!groupId) {
if (!isDefinedAndNotNull(groupId)) {
logger.error('valid groupId is required for group');
return;
}
Expand Down Expand Up @@ -373,11 +373,11 @@ class Mixpanel {

const { previousId, userId } = rudderElement.message;
const newId = userId;
if (!previousId) {
if (!isDefinedAndNotNull(previousId)) {
logger.error('previousId is required for alias call');
return;
}
if (!newId) {
if (!isDefinedAndNotNull(newId)) {
logger.error('userId is required for alias call');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const formatTraits = (message, setOnceProperties) => {
};

const parseConfigArray = (arr, key) => {
if (!arr) {
if (!isDefinedAndNotNull(arr)) {
logger.error('arr is undefined or null');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Posthog {
groupType = get(traits, 'groupType');
delete traits.groupType;
}
if (!groupType || !groupKey) {
if (!isDefinedAndNotNull(groupType) || !isDefinedAndNotNull(groupKey)) {
logger.error('groupType and groupKey is required for group call');
return;
}
Expand Down
Loading