Skip to content

Commit

Permalink
Revert Removed all isDevEnv implementation as well as its definition
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonortiz authored and christian97dd committed Dec 5, 2024
1 parent 9ad066a commit 243cc80
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 44 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [2.5.0] - 2024-12-05

### Changed

- Changed way of controlling debug mode, now you decide whether to show console errors from outside the package. - [APPSRN-346](https://janiscommerce.atlassian.net/browse/APPSRN-346)

## [2.4.0] - 2024-08-15

### Changed
Expand Down
5 changes: 2 additions & 3 deletions lib/actionEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
* @param {string} params.appVersion app version in use
* @param {string} params.screenName screen where the action was called
* @param {string} params.anotherKey... any extra data that you want to be sent will be cataloged as dataEvent
* @param {boolean} isDebugMode a key that defines if the analytics mode is debug or not
* @throws an error when not pass valid params or any of the required parameters are missing
* @returns {boolean}
* @example
Expand All @@ -27,7 +26,7 @@ import {
* actionEvent({actionName:'button press',client: 'client',userEmail: 'janis@janis.im',userId:'123456',appVersion:'1.20.0'})
*/

const actionEvent = async (params, isDebugMode) => {
const actionEvent = async (params) => {
const requiredData = ['actionName'];

try {
Expand All @@ -51,7 +50,7 @@ const actionEvent = async (params, isDebugMode) => {

return true;
} catch (error) {
showErrorInDebug(error, isDebugMode);
showErrorInDebug(error);

return false;
}
Expand Down
19 changes: 10 additions & 9 deletions lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import customEvent from './customEvent';
import userInfoEvent from './userInfoEvent';
import screenViewEvent from './screenViewEvent';
import {
isDevEnv,
formatBasicData,
validObjectWithValues,
promiseWrapper,
Expand Down Expand Up @@ -76,7 +77,7 @@ class Analytics {

return this.eventData;
} catch (error) {
if (this.isDebugMode) {
if (this.isDebugMode || !isDevEnv()) {
console.error(error.message);
}

Expand Down Expand Up @@ -110,8 +111,8 @@ class Analytics {
},
};

if (this.isDebugMode) {
userInfoEvent(userInfoData, this.isDebugMode);
if (this.isDebugMode || !isDevEnv()) {
userInfoEvent(userInfoData);
}
}

Expand All @@ -136,8 +137,8 @@ class Analytics {
actionName,
};

if (this.isDebugMode) {
actionEvent(actionData, this.isDebugMode);
if (this.isDebugMode || !isDevEnv()) {
actionEvent(actionData);
}
}

Expand All @@ -160,8 +161,8 @@ class Analytics {
...formatBasicData(userInfo),
};

if (this.isDebugMode) {
customEvent(customName, customData, requiredParams, this.isDebugMode);
if (this.isDebugMode || !isDevEnv()) {
customEvent(customName, customData, requiredParams);
}
}

Expand All @@ -178,8 +179,8 @@ class Analytics {

if (!includesAllProperties(userInfo)) return null;

if (this.isDebugMode) {
screenViewEvent(screenName, screenClass, userInfo, this.isDebugMode);
if (this.isDebugMode || !isDevEnv()) {
screenViewEvent(screenName, screenClass, userInfo);
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions lib/customEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
* @param {string} params.appVersion app version in use
* @param {string} params.language user app language
* @param {string} params.anotherKey... any extra data that you want to be sent will be cataloged as dataEvent
* @param {boolean} isDebugMode a key that defines if the analytics mode is debug or not
* @argument {string[]} customRequiredParams any extra parameters that may be required for any custom event
* @throws an error when some required params is not passed
* @returns {boolean}
Expand All @@ -26,12 +25,7 @@ import {
* customEvent('event_init',{date:"2011-10-05T14:48:00.000Z"})
*/

const customEvent = async (
eventName,
params,
customRequiredParams = [],
isDebugMode,
) => {
const customEvent = async (eventName, params, customRequiredParams = []) => {
try {
const validParamsArray = Array.isArray(customRequiredParams)
? customRequiredParams
Expand Down Expand Up @@ -63,7 +57,7 @@ const customEvent = async (

return true;
} catch (error) {
showErrorInDebug(error, isDebugMode);
showErrorInDebug(error);

return false;
}
Expand Down
11 changes: 3 additions & 8 deletions lib/screenViewEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import analytics from '@react-native-firebase/analytics';
import {validObjectWithValues} from './utils';
import {isDevEnv, validObjectWithValues} from './utils';

/**
* @function screenViewEvent
Expand All @@ -19,12 +19,7 @@ import {validObjectWithValues} from './utils';
* screenViewEvent('home','class_home')
*/

const screenViewEvent = async (
screenName,
screenClass = '',
params,
isDebugMode,
) => {
const screenViewEvent = async (screenName, screenClass = '', params) => {
try {
if (!screenName) throw new Error('Screen name is required');

Expand All @@ -40,7 +35,7 @@ const screenViewEvent = async (

return true;
} catch (error) {
if (isDebugMode) {
if (isDevEnv()) {
console.error(error.message);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/userInfoEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import analytics from '@react-native-firebase/analytics';
import {
isDevEnv,
splitRequiredAndRemainingParams,
validObjectWithValues,
validateRequiredStringParams,
Expand Down Expand Up @@ -28,7 +29,7 @@ import {
* userInfoEvent({appName:'app_name',appVersion:'1.0.0',device:'samsung a10',os:'android',osVersion:'10',userEmail:'user_name@janis.im',userId:'012345678910', client: 'janis'})
*/

const userInfoEvent = async (params, isDebugMode) => {
const userInfoEvent = async (params) => {
const requiredData = ['appName', 'device', 'osVersion'];

try {
Expand All @@ -54,7 +55,7 @@ const userInfoEvent = async (params, isDebugMode) => {

return true;
} catch (error) {
if (isDebugMode) {
if (isDevEnv()) {
console.error(error.message);
}

Expand Down
15 changes: 13 additions & 2 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import requiredInitialData from '../constant/requiredInitialData';

/* istanbul ignore next */
/**
* @name isDevEnv
* @returns true if node env is development
*/
export const isDevEnv = () => {
const {env} = process;
const {NODE_ENV} = env;
return NODE_ENV !== 'production';
};

/**
* @name updateRequiredParams
* @description returns an array with all the keys that are considered required, updating the default ones with the ones received as arguments
Expand Down Expand Up @@ -68,8 +79,8 @@ export const validateRequiredStringParams = (
* @returns {null}
*/

export const showErrorInDebug = (error, isDebugMode) => {
if (isDebugMode) {
export const showErrorInDebug = (error) => {
if (isDevEnv()) {
console.error(error.message);
}
return null;
Expand Down
4 changes: 4 additions & 0 deletions test/actionEvent.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import actionEvent from '../lib/actionEvent';
import * as utils from '../lib/utils';

describe('actionEvent method', () => {
const mockedDevEnv = jest.spyOn(utils, 'isDevEnv');
const validParams = {
actionName: 'button Press',
client: 'janis',
Expand All @@ -14,10 +16,12 @@ describe('actionEvent method', () => {
};
describe('throws an error when', () => {
it('not pass a valid object as an argument', async () => {
mockedDevEnv.mockReturnValueOnce(false);
expect(await actionEvent({})).toBe(false);
});

it('not pass all required data or this hasnt value', async () => {
mockedDevEnv.mockReturnValueOnce(true);
expect(
await actionEvent({
actionName: 'buttonPress',
Expand Down
Loading

0 comments on commit 243cc80

Please sign in to comment.