From baa3f7cf1f0e41c91f9a84326e8c1d05623e7022 Mon Sep 17 00:00:00 2001 From: Mitch Prewitt <44011584+mprew97@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:16:57 -0400 Subject: [PATCH] [MOB-10091]: AUT Pre-Bash Updates (#475) * update var, some error cleanup in sample app * remove endpoint from list * fix spec --- .../src/components/LoginFormWithoutJWT.tsx | 8 +++- react-example/src/index.tsx | 2 +- react-example/src/indexWithoutJWT.tsx | 2 +- .../tests/userMergeScenarios.test.ts | 47 ++++++++++--------- .../tests/userUpdate.test.ts | 2 +- .../validateCustomEventUserUpdateAPI.test.ts | 8 ++-- src/authorization/authorization.ts | 10 ++-- src/index.ts | 2 +- src/request.ts | 2 - src/utils/commonFunctions.ts | 2 +- src/utils/config.ts | 4 +- 11 files changed, 48 insertions(+), 41 deletions(-) diff --git a/react-example/src/components/LoginFormWithoutJWT.tsx b/react-example/src/components/LoginFormWithoutJWT.tsx index 5fd49ca7..f1e6c206 100644 --- a/react-example/src/components/LoginFormWithoutJWT.tsx +++ b/react-example/src/components/LoginFormWithoutJWT.tsx @@ -2,6 +2,7 @@ import { ChangeEvent, FC, FormEvent, useState } from 'react'; import styled from 'styled-components'; +import { IdentityResolution } from '@iterable/web-sdk'; import { TextField as _TextField } from './TextField'; import { Button as _Button } from './Button'; @@ -39,7 +40,10 @@ const Error = styled.div` interface Props { setEmail: (email: string) => Promise; - setUserId: (userId: string, merge?: boolean) => Promise; + setUserId: ( + userId: string, + identityResolution?: IdentityResolution + ) => Promise; logout: () => void; } @@ -62,7 +66,7 @@ export const LoginFormWithoutJWT: FC = ({ const setUser = useEmail ? setEmail : setUserId; - setUser(user, true) + setUser(user) .then(() => { setEditingUser(false); setLoggedInUser({ type: 'user_update', data: user }); diff --git a/react-example/src/index.tsx b/react-example/src/index.tsx index 7f801e45..831ec707 100644 --- a/react-example/src/index.tsx +++ b/react-example/src/index.tsx @@ -47,7 +47,7 @@ const HomeLink = styled(Link)` configOptions: { isEuIterableService: false, dangerouslyAllowJsPopups: true, - enableAnonTracking: true + enableAnonActivation: true }, generateJWT: ({ email, userID }) => axios diff --git a/react-example/src/indexWithoutJWT.tsx b/react-example/src/indexWithoutJWT.tsx index 81f744ea..427ce25d 100644 --- a/react-example/src/indexWithoutJWT.tsx +++ b/react-example/src/indexWithoutJWT.tsx @@ -46,7 +46,7 @@ const HomeLink = styled(Link)` configOptions: { isEuIterableService: false, dangerouslyAllowJsPopups: true, - enableAnonTracking: true, + enableAnonActivation: true, onAnonUserCreated: (userId: string) => { console.log('onAnonUserCreated', userId); } diff --git a/src/anonymousUserTracking/tests/userMergeScenarios.test.ts b/src/anonymousUserTracking/tests/userMergeScenarios.test.ts index ec139aaa..39eee7fb 100644 --- a/src/anonymousUserTracking/tests/userMergeScenarios.test.ts +++ b/src/anonymousUserTracking/tests/userMergeScenarios.test.ts @@ -16,6 +16,7 @@ import { track } from '../../events'; import { getInAppMessages } from '../../inapp'; import { baseAxiosRequest } from '../../request'; import { USER_MERGE_SCENARIO_CRITERIA } from './constants'; +import { setTypeOfAuth } from '../../utils/typeOfAuth'; jest.setTimeout(20000); // Set the timeout to 10 seconds @@ -108,7 +109,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: false, mergeOnAnonymousToKnown: false @@ -147,7 +148,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -188,7 +189,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: false @@ -241,7 +242,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: false @@ -288,7 +289,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -325,6 +326,7 @@ describe('UserMergeScenariosTests', () => { }); it('criteria is met with merge default with setUserId', async () => { + const anonId = '123e4567-e89b-12d3-a456-426614174000'; (localStorage.getItem as jest.Mock).mockImplementation((key) => { if (key === SHARED_PREFS_EVENT_LIST_KEY) { return JSON.stringify([eventDataMatched]); @@ -336,14 +338,14 @@ describe('UserMergeScenariosTests', () => { return JSON.stringify(initialAnonSessionInfo); } if (key === SHARED_PREF_ANON_USER_ID) { - return '123e4567-e89b-12d3-a456-426614174000'; + return anonId; } return null; }); const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true + enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test @@ -360,6 +362,7 @@ describe('UserMergeScenariosTests', () => { } catch (e) { console.log(e); } + setTypeOfAuth('userID'); await setUserID('testuser123'); expect(localStorageMock.removeItem).toHaveBeenCalledWith( SHARED_PREF_ANON_USER_ID @@ -378,7 +381,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: false @@ -416,7 +419,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -449,7 +452,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -510,7 +513,7 @@ describe('UserMergeScenariosTests', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: false @@ -545,7 +548,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: false, mergeOnAnonymousToKnown: false @@ -584,7 +587,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -625,7 +628,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true + enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test @@ -677,7 +680,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -712,6 +715,7 @@ describe('UserMergeScenariosTests', () => { }); it('criteria is met with merge default with setEmail', async () => { + const anonId = '123e4567-e89b-12d3-a456-426614174000'; (localStorage.getItem as jest.Mock).mockImplementation((key) => { if (key === SHARED_PREFS_EVENT_LIST_KEY) { return JSON.stringify([eventDataMatched]); @@ -723,14 +727,14 @@ describe('UserMergeScenariosTests', () => { return JSON.stringify(initialAnonSessionInfo); } if (key === SHARED_PREF_ANON_USER_ID) { - return '123e4567-e89b-12d3-a456-426614174000'; + return anonId; } return null; }); const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true + enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test @@ -747,6 +751,7 @@ describe('UserMergeScenariosTests', () => { } catch (e) { console.log(e); } + setTypeOfAuth('userID'); await setEmail('testuser123@test.com'); expect(localStorageMock.removeItem).toHaveBeenCalledWith( SHARED_PREF_ANON_USER_ID @@ -765,7 +770,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: false @@ -805,7 +810,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true @@ -845,7 +850,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: false @@ -885,7 +890,7 @@ describe('UserMergeScenariosTests', () => { const { setEmail, logout } = initializeWithConfig({ authToken: '123', configOptions: { - enableAnonTracking: true, + enableAnonActivation: true, identityResolution: { replayOnVisitorToKnown: true, mergeOnAnonymousToKnown: true diff --git a/src/anonymousUserTracking/tests/userUpdate.test.ts b/src/anonymousUserTracking/tests/userUpdate.test.ts index 6d1f84c8..579cffb6 100644 --- a/src/anonymousUserTracking/tests/userUpdate.test.ts +++ b/src/anonymousUserTracking/tests/userUpdate.test.ts @@ -104,7 +104,7 @@ describe('UserUpdate', () => { const { logout } = initializeWithConfig({ authToken: '123', - configOptions: { enableAnonTracking: true } + configOptions: { enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test diff --git a/src/anonymousUserTracking/tests/validateCustomEventUserUpdateAPI.test.ts b/src/anonymousUserTracking/tests/validateCustomEventUserUpdateAPI.test.ts index 0acbceb4..c8e625dd 100644 --- a/src/anonymousUserTracking/tests/validateCustomEventUserUpdateAPI.test.ts +++ b/src/anonymousUserTracking/tests/validateCustomEventUserUpdateAPI.test.ts @@ -159,7 +159,7 @@ describe('validateCustomEventUserUpdateAPI', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', - configOptions: { enableAnonTracking: true } + configOptions: { enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test @@ -246,7 +246,7 @@ describe('validateCustomEventUserUpdateAPI', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', - configOptions: { enableAnonTracking: true } + configOptions: { enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test @@ -316,7 +316,7 @@ describe('validateCustomEventUserUpdateAPI', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', - configOptions: { enableAnonTracking: true } + configOptions: { enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test @@ -390,7 +390,7 @@ describe('validateCustomEventUserUpdateAPI', () => { const { setUserID, logout } = initializeWithConfig({ authToken: '123', - configOptions: { enableAnonTracking: true } + configOptions: { enableAnonActivation: true } }); logout(); // logout to remove logged in users before this test diff --git a/src/authorization/authorization.ts b/src/authorization/authorization.ts index 0cd6c0be..e07389b4 100644 --- a/src/authorization/authorization.ts +++ b/src/authorization/authorization.ts @@ -99,7 +99,7 @@ const clearAnonymousUser = () => { }; const getAnonUserId = () => { - if (config.getConfig('enableAnonTracking')) { + if (config.getConfig('enableAnonActivation')) { const anonUser = localStorage.getItem(SHARED_PREF_ANON_USER_ID); return anonUser === undefined ? null : anonUser; } else { @@ -213,7 +213,7 @@ const initializeEmailUser = (email: string) => { }; const syncEvents = () => { - if (config.getConfig('enableAnonTracking')) { + if (config.getConfig('enableAnonActivation')) { anonUserManager.syncEvents(); } }; @@ -396,7 +396,7 @@ export function initialize( const enableAnonymousTracking = () => { try { - if (config.getConfig('enableAnonTracking')) { + if (config.getConfig('enableAnonActivation')) { anonUserManager.getAnonCriteria(); anonUserManager.updateAnonSession(); const anonymousUserId = getAnonUserId(); @@ -416,7 +416,7 @@ export function initialize( merge?: boolean ): Promise => { const typeOfAuth = getTypeOfAuth(); - const enableAnonTracking = config.getConfig('enableAnonTracking'); + const enableAnonActivation = config.getConfig('enableAnonActivation'); const sourceUserIdOrEmail = authIdentifier === null ? getAnonUserId() : authIdentifier; const sourceUserId = typeOfAuth === 'email' ? null : sourceUserIdOrEmail; @@ -427,7 +427,7 @@ export function initialize( if ( (getAnonUserId() !== null || authIdentifier !== null) && merge && - enableAnonTracking + enableAnonActivation ) { const anonymousUserMerge = new AnonymousUserMerge(); try { diff --git a/src/index.ts b/src/index.ts index e5169ad6..e6deee64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ export * from './embedded'; export * from './components/card'; export * from './components/banner'; export * from './components/notification'; -export { config } from './utils/config'; +export { config, IdentityResolution } from './utils/config'; export { IterableConfig } from './utils/IterableConfig'; export interface TextParentStyles { diff --git a/src/request.ts b/src/request.ts index 20f1677c..6efa8cb8 100644 --- a/src/request.ts +++ b/src/request.ts @@ -7,7 +7,6 @@ import { EU_ITERABLE_API, GET_CRITERIA_PATH, INITIALIZE_ERROR, - ENDPOINT_MERGE_USER, ENDPOINT_TRACK_ANON_SESSION } from './constants'; import { IterablePromise, IterableResponse } from './types'; @@ -32,7 +31,6 @@ interface ClientError extends IterableResponse { const ENDPOINTS_NOT_REQUIRING_TYPE_OF_AUTH = [ GET_CRITERIA_PATH, - ENDPOINT_MERGE_USER, ENDPOINT_TRACK_ANON_SESSION ]; diff --git a/src/utils/commonFunctions.ts b/src/utils/commonFunctions.ts index ecf94eab..46471516 100644 --- a/src/utils/commonFunctions.ts +++ b/src/utils/commonFunctions.ts @@ -2,4 +2,4 @@ import config from './config'; import { getTypeOfAuth } from './typeOfAuth'; export const canTrackAnonUser = (): boolean => - config.getConfig('enableAnonTracking') && getTypeOfAuth() === null; + config.getConfig('enableAnonActivation') && getTypeOfAuth() === null; diff --git a/src/utils/config.ts b/src/utils/config.ts index 5cc7e65e..42c74969 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -8,7 +8,7 @@ export type IdentityResolution = { export type Options = { logLevel: 'none' | 'verbose'; baseURL: string; - enableAnonTracking: boolean; + enableAnonActivation: boolean; isEuIterableService: boolean; dangerouslyAllowJsPopups: boolean; eventThresholdLimit?: number; @@ -20,7 +20,7 @@ const _config = () => { let options: Options = { logLevel: 'none', baseURL: BASE_URL, - enableAnonTracking: false, + enableAnonActivation: false, isEuIterableService: false, dangerouslyAllowJsPopups: false, eventThresholdLimit: DEFAULT_EVENT_THRESHOLD_LIMIT,