From e09d7ee8d1865221dbb0a76a08407d80792dd4dc Mon Sep 17 00:00:00 2001 From: glo11372 Date: Mon, 6 May 2024 16:59:42 +0530 Subject: [PATCH 1/5] PWA-3236: Change user time to logout --- .../peregrine/lib/store/actions/user/asyncActions.js | 4 ++-- .../__tests__/useCreateAccount.spec.js | 10 ++++++++-- .../OrderConfirmationPage/createAccount.gql.js | 1 + .../OrderConfirmationPage/useCreateAccount.js | 4 +++- .../CreateAccount/__tests__/useCreateAccount.spec.js | 9 ++++++--- .../lib/talons/CreateAccount/createAccount.gql.js | 1 + .../lib/talons/CreateAccount/useCreateAccount.js | 4 +++- .../lib/talons/SignIn/__tests__/useSignIn.spec.js | 7 +++++-- packages/peregrine/lib/talons/SignIn/signIn.gql.js | 1 + packages/peregrine/lib/talons/SignIn/useSignIn.js | 4 +++- 10 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/peregrine/lib/store/actions/user/asyncActions.js b/packages/peregrine/lib/store/actions/user/asyncActions.js index 266183117f..7ea1464349 100755 --- a/packages/peregrine/lib/store/actions/user/asyncActions.js +++ b/packages/peregrine/lib/store/actions/user/asyncActions.js @@ -63,13 +63,13 @@ export const resetPassword = ({ email }) => dispatch(actions.resetPassword.receive()); }; -export const setToken = token => +export const setToken = (token, cookie_lifetime = 3600) => async function thunk(...args) { const [dispatch] = args; // Store token in local storage. // TODO: Get correct token expire time from API - storage.setItem('signin_token', token, 3600); + storage.setItem('signin_token', token, cookie_lifetime); // Persist in store dispatch(actions.setToken(token)); diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js index c8c4cb722a..8f6c48711f 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js @@ -78,13 +78,19 @@ const signInVariables = { password: '123456' }; const authToken = 'auth-token-123'; +const cookieLifetime = 100; const signInMock = { request: { query: defaultOperations.signInMutation, variables: signInVariables }, result: { - data: { generateCustomerToken: { token: authToken } } + data: { + generateCustomerToken: { + token: authToken, + cookie_lifetime: cookieLifetime + } + } } }; @@ -202,7 +208,7 @@ describe('handle submit event', () => { await result.current.handleSubmit(formValues); }); - expect(mockSetToken).toHaveBeenCalledWith('auth-token-123'); + expect(mockSetToken).toHaveBeenCalledWith('auth-token-123', 100); expect(createAccount).toHaveBeenCalled(); expect(mockRemoveCart).toHaveBeenCalled(); expect(mockCreateCart).toHaveBeenCalledWith({ diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js index 0fc86f1063..9aca8e2b70 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js @@ -44,6 +44,7 @@ export const SIGN_IN = gql` mutation SignInAfterCheckout($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token + cookie_lifetime } } `; diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js index e1b45e9297..f5c7796119 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js @@ -117,7 +117,9 @@ export const useCreateAccount = props => { ...recaptchaDataForSignIn }); const token = signInResponse.data.generateCustomerToken.token; - await setToken(token); + const cookie_lifetime = + signInResponse.data.generateCustomerToken.cookie_lifetime; + await setToken(token, cookie_lifetime); // Clear guest cart from redux. await removeCart(); diff --git a/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js b/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js index 4d60520b10..00ab38be23 100644 --- a/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js +++ b/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js @@ -102,7 +102,8 @@ const signInMutationFn = jest.fn().mockReturnValue([ jest.fn().mockReturnValue({ data: { generateCustomerToken: { - token: 'customer token' + token: 'customer token', + cookie_lifetime: 100 } } }), @@ -272,10 +273,12 @@ describe('handleSubmit', () => { test('should signin after account creation', async () => { const token = 'customertoken'; + const cookie_lifetime = 100; const signIn = jest.fn().mockReturnValue({ data: { generateCustomerToken: { - token + token, + cookie_lifetime } } }); @@ -298,7 +301,7 @@ describe('handleSubmit', () => { password: defaultFormValues.password } }); - expect(setToken).toHaveBeenCalledWith(token); + expect(setToken).toHaveBeenCalledWith(token, cookie_lifetime); }); test('should clear cart data from cache', async () => { diff --git a/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js b/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js index 4f4ecf9b26..019b296300 100644 --- a/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js +++ b/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js @@ -45,6 +45,7 @@ export const SIGN_IN = gql` mutation SignInAfterCreate($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token + cookie_lifetime } } `; diff --git a/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js b/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js index cc8953998a..cb49e06404 100644 --- a/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js +++ b/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js @@ -136,7 +136,9 @@ export const useCreateAccount = props => { ...recaptchaDataForSignIn }); const token = signInResponse.data.generateCustomerToken.token; - await setToken(token); + const cookie_lifetime = + signInResponse.data.generateCustomerToken.cookie_lifetime; + await setToken(token, cookie_lifetime); // Clear all cart/customer data from cache and redux. await apolloClient.clearCacheData(apolloClient, 'cart'); diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index 63e35adb8b..fde2088fc5 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -61,6 +61,7 @@ const signInVariables = { password: 'slurm is the best' }; const authToken = 'auth-token-123'; +const cookieLifetime = 100; const signInMock = { request: { @@ -68,7 +69,9 @@ const signInMock = { variables: signInVariables }, result: { - data: { generateCustomerToken: { token: authToken } } + data: { + generateCustomerToken: { token: authToken, cookie_lifetime: 100 } + } } }; @@ -156,7 +159,7 @@ test('handleSubmit triggers waterfall of operations and actions', async () => { await act(() => result.current.handleSubmit(signInVariables)); expect(result.current.isBusy).toBe(true); - expect(setToken).toHaveBeenCalledWith(authToken); + expect(setToken).toHaveBeenCalledWith(authToken, cookieLifetime); expect(getCartDetails).toHaveBeenCalled(); expect(getUserDetails).toHaveBeenCalled(); diff --git a/packages/peregrine/lib/talons/SignIn/signIn.gql.js b/packages/peregrine/lib/talons/SignIn/signIn.gql.js index 4aeb05a536..858c51e445 100644 --- a/packages/peregrine/lib/talons/SignIn/signIn.gql.js +++ b/packages/peregrine/lib/talons/SignIn/signIn.gql.js @@ -17,6 +17,7 @@ export const SIGN_IN = gql` mutation SignIn($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token + cookie_lifetime } } `; diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index 0bf326e531..bb947bc26a 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -86,7 +86,9 @@ export const useSignIn = props => { }); const token = signInResponse.data.generateCustomerToken.token; - await setToken(token); + const cookie_lifetime = + signInResponse.data.generateCustomerToken.cookie_lifetime; + await setToken(token, cookie_lifetime); // Clear all cart/customer data from cache and redux. await apolloClient.clearCacheData(apolloClient, 'cart'); From 4563c54e972ce00d8e249d8aed7f7606c008e1a6 Mon Sep 17 00:00:00 2001 From: glo11372 Date: Fri, 24 May 2024 13:55:03 +0530 Subject: [PATCH 2/5] PWA-3263: Change user logout time --- .../peregrine/lib/store/actions/user/asyncActions.js | 4 ++-- .../__tests__/useCreateAccount.spec.js | 6 +++--- .../OrderConfirmationPage/createAccount.gql.js | 2 +- .../OrderConfirmationPage/useCreateAccount.js | 10 +++++++--- .../CreateAccount/__tests__/useCreateAccount.spec.js | 8 ++++---- .../lib/talons/CreateAccount/createAccount.gql.js | 2 +- .../lib/talons/CreateAccount/useCreateAccount.js | 10 ++++++---- .../lib/talons/SignIn/__tests__/useSignIn.spec.js | 6 +++--- packages/peregrine/lib/talons/SignIn/signIn.gql.js | 2 +- packages/peregrine/lib/talons/SignIn/useSignIn.js | 10 +++++++--- 10 files changed, 35 insertions(+), 25 deletions(-) diff --git a/packages/peregrine/lib/store/actions/user/asyncActions.js b/packages/peregrine/lib/store/actions/user/asyncActions.js index 7ea1464349..d3a2ccdb25 100755 --- a/packages/peregrine/lib/store/actions/user/asyncActions.js +++ b/packages/peregrine/lib/store/actions/user/asyncActions.js @@ -63,13 +63,13 @@ export const resetPassword = ({ email }) => dispatch(actions.resetPassword.receive()); }; -export const setToken = (token, cookie_lifetime = 3600) => +export const setToken = (token, customer_token_lifetime = 3600) => async function thunk(...args) { const [dispatch] = args; // Store token in local storage. // TODO: Get correct token expire time from API - storage.setItem('signin_token', token, cookie_lifetime); + storage.setItem('signin_token', token, customer_token_lifetime); // Persist in store dispatch(actions.setToken(token)); diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js index 8f6c48711f..f84bbc00a8 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/__tests__/useCreateAccount.spec.js @@ -78,7 +78,7 @@ const signInVariables = { password: '123456' }; const authToken = 'auth-token-123'; -const cookieLifetime = 100; +const customerTokenLifetime = 3600; const signInMock = { request: { query: defaultOperations.signInMutation, @@ -88,7 +88,7 @@ const signInMock = { data: { generateCustomerToken: { token: authToken, - cookie_lifetime: cookieLifetime + customer_token_lifetime: customerTokenLifetime } } } @@ -208,7 +208,7 @@ describe('handle submit event', () => { await result.current.handleSubmit(formValues); }); - expect(mockSetToken).toHaveBeenCalledWith('auth-token-123', 100); + expect(mockSetToken).toHaveBeenCalledWith('auth-token-123', 3600); expect(createAccount).toHaveBeenCalled(); expect(mockRemoveCart).toHaveBeenCalled(); expect(mockCreateCart).toHaveBeenCalledWith({ diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js index 9aca8e2b70..6787d4682f 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js @@ -44,7 +44,7 @@ export const SIGN_IN = gql` mutation SignInAfterCheckout($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token - cookie_lifetime + customer_token_lifetime } } `; diff --git a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js index f5c7796119..ef3a6d6169 100644 --- a/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +++ b/packages/peregrine/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js @@ -117,9 +117,13 @@ export const useCreateAccount = props => { ...recaptchaDataForSignIn }); const token = signInResponse.data.generateCustomerToken.token; - const cookie_lifetime = - signInResponse.data.generateCustomerToken.cookie_lifetime; - await setToken(token, cookie_lifetime); + const customerTokenLifetime = + signInResponse.data.generateCustomerToken + .customer_token_lifetime; + + await (customerTokenLifetime + ? setToken(token, customerTokenLifetime) + : setToken(token)); // Clear guest cart from redux. await removeCart(); diff --git a/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js b/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js index 00ab38be23..01dbabe7a7 100644 --- a/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js +++ b/packages/peregrine/lib/talons/CreateAccount/__tests__/useCreateAccount.spec.js @@ -103,7 +103,7 @@ const signInMutationFn = jest.fn().mockReturnValue([ data: { generateCustomerToken: { token: 'customer token', - cookie_lifetime: 100 + customer_token_lifetime: 3600 } } }), @@ -273,12 +273,12 @@ describe('handleSubmit', () => { test('should signin after account creation', async () => { const token = 'customertoken'; - const cookie_lifetime = 100; + const customer_token_lifetime = 3600; const signIn = jest.fn().mockReturnValue({ data: { generateCustomerToken: { token, - cookie_lifetime + customer_token_lifetime } } }); @@ -301,7 +301,7 @@ describe('handleSubmit', () => { password: defaultFormValues.password } }); - expect(setToken).toHaveBeenCalledWith(token, cookie_lifetime); + expect(setToken).toHaveBeenCalledWith(token, customer_token_lifetime); }); test('should clear cart data from cache', async () => { diff --git a/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js b/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js index 019b296300..4eed9375f0 100644 --- a/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js +++ b/packages/peregrine/lib/talons/CreateAccount/createAccount.gql.js @@ -45,7 +45,7 @@ export const SIGN_IN = gql` mutation SignInAfterCreate($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token - cookie_lifetime + customer_token_lifetime } } `; diff --git a/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js b/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js index cb49e06404..5bfca3e6bc 100644 --- a/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js +++ b/packages/peregrine/lib/talons/CreateAccount/useCreateAccount.js @@ -136,10 +136,12 @@ export const useCreateAccount = props => { ...recaptchaDataForSignIn }); const token = signInResponse.data.generateCustomerToken.token; - const cookie_lifetime = - signInResponse.data.generateCustomerToken.cookie_lifetime; - await setToken(token, cookie_lifetime); - + const customerTokenLifetime = + signInResponse.data.generateCustomerToken + .customer_token_lifetime; + await (customerTokenLifetime + ? setToken(token, customerTokenLifetime) + : setToken(token)); // Clear all cart/customer data from cache and redux. await apolloClient.clearCacheData(apolloClient, 'cart'); await apolloClient.clearCacheData(apolloClient, 'customer'); diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index fde2088fc5..e4b81862c4 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -61,7 +61,7 @@ const signInVariables = { password: 'slurm is the best' }; const authToken = 'auth-token-123'; -const cookieLifetime = 100; +const customerTokenLifetime = 3600; const signInMock = { request: { @@ -70,7 +70,7 @@ const signInMock = { }, result: { data: { - generateCustomerToken: { token: authToken, cookie_lifetime: 100 } + generateCustomerToken: { token: authToken, customer_token_lifetime: customerTokenLifetime } } } }; @@ -159,7 +159,7 @@ test('handleSubmit triggers waterfall of operations and actions', async () => { await act(() => result.current.handleSubmit(signInVariables)); expect(result.current.isBusy).toBe(true); - expect(setToken).toHaveBeenCalledWith(authToken, cookieLifetime); + expect(setToken).toHaveBeenCalledWith(authToken, customerTokenLifetime); expect(getCartDetails).toHaveBeenCalled(); expect(getUserDetails).toHaveBeenCalled(); diff --git a/packages/peregrine/lib/talons/SignIn/signIn.gql.js b/packages/peregrine/lib/talons/SignIn/signIn.gql.js index 858c51e445..b960c3452e 100644 --- a/packages/peregrine/lib/talons/SignIn/signIn.gql.js +++ b/packages/peregrine/lib/talons/SignIn/signIn.gql.js @@ -17,7 +17,7 @@ export const SIGN_IN = gql` mutation SignIn($email: String!, $password: String!) { generateCustomerToken(email: $email, password: $password) { token - cookie_lifetime + customer_token_lifetime } } `; diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index bb947bc26a..35d80fe896 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -86,9 +86,13 @@ export const useSignIn = props => { }); const token = signInResponse.data.generateCustomerToken.token; - const cookie_lifetime = - signInResponse.data.generateCustomerToken.cookie_lifetime; - await setToken(token, cookie_lifetime); + const customerTokenLifetime = + signInResponse.data.generateCustomerToken + .customer_token_lifetime; + + await (customerTokenLifetime + ? setToken(token, customerTokenLifetime) + : setToken(token)); // Clear all cart/customer data from cache and redux. await apolloClient.clearCacheData(apolloClient, 'cart'); From f03e1946fa5918a28b0572aa49079e9e1736fb49 Mon Sep 17 00:00:00 2001 From: glo11372 Date: Fri, 24 May 2024 14:21:25 +0530 Subject: [PATCH 3/5] PWA-3263:change user logout time --- .../peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index e4b81862c4..e32b6b1c4f 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -70,7 +70,10 @@ const signInMock = { }, result: { data: { - generateCustomerToken: { token: authToken, customer_token_lifetime: customerTokenLifetime } + generateCustomerToken: { + token: authToken, + customer_token_lifetime: customerTokenLifetime + } } } }; From a0fc454726a6f714bd8d84d206e7ba02402751b9 Mon Sep 17 00:00:00 2001 From: glo11372 Date: Fri, 24 May 2024 14:40:31 +0530 Subject: [PATCH 4/5] increasing the time of build pack --- .../venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js b/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js index 3416d6ef55..2904a118e9 100644 --- a/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js +++ b/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js @@ -15,7 +15,7 @@ const thisDep = { intercept }; -const WEBPACK_BUILD_TIMEOUT = 30000; +const WEBPACK_BUILD_TIMEOUT = 600000; const mockComponent = name => `function ${name}(props) { return
{props.children}
; `; From facd23dc97ef3f9087d8b5d92e5a76a2b7c08e47 Mon Sep 17 00:00:00 2001 From: glo11372 Date: Fri, 24 May 2024 15:06:47 +0530 Subject: [PATCH 5/5] increasing the time of build pack --- .../venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js b/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js index 2904a118e9..d367072695 100644 --- a/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js +++ b/packages/venia-ui/lib/targets/__tests__/venia-ui-targets.spec.js @@ -15,7 +15,7 @@ const thisDep = { intercept }; -const WEBPACK_BUILD_TIMEOUT = 600000; +const WEBPACK_BUILD_TIMEOUT = 800000; const mockComponent = name => `function ${name}(props) { return
{props.children}
; `;