@magento/peregrine 14.4.1-alpha.1 → 14.4.1-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,13 +63,17 @@ export const resetPassword = ({ email }) =>
63
63
  dispatch(actions.resetPassword.receive());
64
64
  };
65
65
 
66
- export const setToken = (token, customer_token_lifetime = 3600) =>
66
+ export const setToken = (token, customerAccessTokenLifetime = 1) =>
67
67
  async function thunk(...args) {
68
68
  const [dispatch] = args;
69
69
 
70
70
  // Store token in local storage.
71
71
  // TODO: Get correct token expire time from API
72
- storage.setItem('signin_token', token, customer_token_lifetime);
72
+ storage.setItem(
73
+ 'signin_token',
74
+ token,
75
+ customerAccessTokenLifetime * 3600
76
+ );
73
77
 
74
78
  // Persist in store
75
79
  dispatch(actions.setToken(token));
@@ -1,4 +1,5 @@
1
1
  import { gql } from '@apollo/client';
2
+ import { GET_STORE_CONFIG_DATA } from '../../CreateAccount/createAccount.gql';
2
3
 
3
4
  export const CREATE_ACCOUNT = gql`
4
5
  mutation CreateAccountAfterCheckout(
@@ -44,7 +45,6 @@ export const SIGN_IN = gql`
44
45
  mutation SignInAfterCheckout($email: String!, $password: String!) {
45
46
  generateCustomerToken(email: $email, password: $password) {
46
47
  token
47
- customer_token_lifetime
48
48
  }
49
49
  }
50
50
  `;
@@ -111,5 +111,6 @@ export default {
111
111
  createCartMutation: CREATE_CART,
112
112
  getCartDetailsQuery: GET_CART_DETAILS,
113
113
  getCustomerQuery: GET_CUSTOMER,
114
- signInMutation: SIGN_IN
114
+ signInMutation: SIGN_IN,
115
+ getStoreConfigQuery: GET_STORE_CONFIG_DATA
115
116
  };
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useMemo, useState } from 'react';
2
- import { useMutation } from '@apollo/client';
2
+ import { useMutation, useQuery } from '@apollo/client';
3
3
 
4
4
  import mergeOperations from '../../../util/shallowMerge';
5
5
  import { useUserContext } from '../../../context/user';
@@ -39,7 +39,8 @@ export const useCreateAccount = props => {
39
39
  createCartMutation,
40
40
  getCartDetailsQuery,
41
41
  getCustomerQuery,
42
- signInMutation
42
+ signInMutation,
43
+ getStoreConfigQuery
43
44
  } = operations;
44
45
  const [isSubmitting, setIsSubmitting] = useState(false);
45
46
  const [, { createCart, getCartDetails, removeCart }] = useCartContext();
@@ -65,6 +66,23 @@ export const useCreateAccount = props => {
65
66
  fetchPolicy: 'no-cache'
66
67
  });
67
68
 
69
+ const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
70
+ fetchPolicy: 'cache-and-network',
71
+ nextFetchPolicy: 'cache-first'
72
+ });
73
+
74
+ const {
75
+ minimumPasswordLength,
76
+ customerAccessTokenLifetime
77
+ } = useMemo(() => {
78
+ const storeConfig = storeConfigData?.storeConfig || {};
79
+
80
+ return {
81
+ minimumPasswordLength: storeConfig.minimum_password_length,
82
+ customerAccessTokenLifetime:
83
+ storeConfig.customer_access_token_lifetime
84
+ };
85
+ }, [storeConfigData]);
68
86
  const fetchUserDetails = useAwaitQuery(getCustomerQuery);
69
87
  const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);
70
88
 
@@ -117,12 +135,8 @@ export const useCreateAccount = props => {
117
135
  ...recaptchaDataForSignIn
118
136
  });
119
137
  const token = signInResponse.data.generateCustomerToken.token;
120
- const customerTokenLifetime =
121
- signInResponse.data.generateCustomerToken
122
- .customer_token_lifetime;
123
-
124
- await (customerTokenLifetime
125
- ? setToken(token, customerTokenLifetime)
138
+ await (customerAccessTokenLifetime
139
+ ? setToken(token, customerAccessTokenLifetime)
126
140
  : setToken(token));
127
141
 
128
142
  // Clear guest cart from redux.
@@ -152,6 +166,7 @@ export const useCreateAccount = props => {
152
166
  }
153
167
  },
154
168
  [
169
+ customerAccessTokenLifetime,
155
170
  createAccount,
156
171
  createCart,
157
172
  fetchCartDetails,
@@ -200,6 +215,7 @@ export const useCreateAccount = props => {
200
215
  handleEnterKeyPress,
201
216
  isDisabled: isSubmitting || isGettingDetails || recaptchaLoading,
202
217
  initialValues: sanitizedInitialValues,
203
- recaptchaWidgetProps
218
+ recaptchaWidgetProps,
219
+ minimumPasswordLength
204
220
  };
205
221
  };
@@ -45,7 +45,6 @@ export const SIGN_IN = gql`
45
45
  mutation SignInAfterCreate($email: String!, $password: String!) {
46
46
  generateCustomerToken(email: $email, password: $password) {
47
47
  token
48
- customer_token_lifetime
49
48
  }
50
49
  }
51
50
  `;
@@ -126,6 +125,16 @@ export const MERGE_CARTS = gql`
126
125
  }
127
126
  ${CheckoutPageFragment}
128
127
  `;
128
+ export const GET_STORE_CONFIG_DATA = gql`
129
+ query GetStoreConfigData {
130
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
131
+ storeConfig {
132
+ store_code
133
+ minimum_password_length
134
+ customer_access_token_lifetime
135
+ }
136
+ }
137
+ `;
129
138
 
130
139
  export default {
131
140
  createAccountMutation: CREATE_ACCOUNT,
@@ -133,5 +142,6 @@ export default {
133
142
  getCartDetailsQuery: GET_CART_DETAILS,
134
143
  getCustomerQuery: GET_CUSTOMER,
135
144
  mergeCartsMutation: MERGE_CARTS,
136
- signInMutation: SIGN_IN
145
+ signInMutation: SIGN_IN,
146
+ getStoreConfigQuery: GET_STORE_CONFIG_DATA
137
147
  };
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useMemo, useState } from 'react';
2
- import { useApolloClient, useMutation } from '@apollo/client';
2
+ import { useApolloClient, useMutation, useQuery } from '@apollo/client';
3
3
 
4
4
  import mergeOperations from '../../util/shallowMerge';
5
5
  import { useUserContext } from '../../context/user';
@@ -37,7 +37,8 @@ export const useCreateAccount = props => {
37
37
  getCartDetailsQuery,
38
38
  getCustomerQuery,
39
39
  mergeCartsMutation,
40
- signInMutation
40
+ signInMutation,
41
+ getStoreConfigQuery
41
42
  } = operations;
42
43
  const apolloClient = useApolloClient();
43
44
  const [isSubmitting, setIsSubmitting] = useState(false);
@@ -69,6 +70,24 @@ export const useCreateAccount = props => {
69
70
  fetchPolicy: 'no-cache'
70
71
  });
71
72
 
73
+ const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
74
+ fetchPolicy: 'cache-and-network',
75
+ nextFetchPolicy: 'cache-first'
76
+ });
77
+
78
+ const {
79
+ minimumPasswordLength,
80
+ customerAccessTokenLifetime
81
+ } = useMemo(() => {
82
+ const storeConfig = storeConfigData?.storeConfig || {};
83
+
84
+ return {
85
+ minimumPasswordLength: storeConfig.minimum_password_length,
86
+ customerAccessTokenLifetime:
87
+ storeConfig.customer_access_token_lifetime
88
+ };
89
+ }, [storeConfigData]);
90
+
72
91
  const fetchUserDetails = useAwaitQuery(getCustomerQuery);
73
92
  const fetchCartDetails = useAwaitQuery(getCartDetailsQuery);
74
93
 
@@ -136,11 +155,8 @@ export const useCreateAccount = props => {
136
155
  ...recaptchaDataForSignIn
137
156
  });
138
157
  const token = signInResponse.data.generateCustomerToken.token;
139
- const customerTokenLifetime =
140
- signInResponse.data.generateCustomerToken
141
- .customer_token_lifetime;
142
- await (customerTokenLifetime
143
- ? setToken(token, customerTokenLifetime)
158
+ await (customerAccessTokenLifetime
159
+ ? setToken(token, customerAccessTokenLifetime)
144
160
  : setToken(token));
145
161
  // Clear all cart/customer data from cache and redux.
146
162
  await apolloClient.clearCacheData(apolloClient, 'cart');
@@ -181,6 +197,7 @@ export const useCreateAccount = props => {
181
197
  },
182
198
 
183
199
  [
200
+ customerAccessTokenLifetime,
184
201
  cartId,
185
202
  generateReCaptchaData,
186
203
  createAccount,
@@ -225,7 +242,8 @@ export const useCreateAccount = props => {
225
242
  handleCancelKeyPress,
226
243
  initialValues: sanitizedInitialValues,
227
244
  isDisabled: isSubmitting || isGettingDetails || recaptchaLoading,
228
- recaptchaWidgetProps
245
+ recaptchaWidgetProps,
246
+ minimumPasswordLength
229
247
  };
230
248
  };
231
249
 
@@ -239,6 +257,7 @@ export const useCreateAccount = props => {
239
257
  *
240
258
  * @property {GraphQLAST} customerQuery query to fetch customer details
241
259
  * @property {GraphQLAST} getCartDetailsQuery query to get cart details
260
+ * @property {GraphQLAST} getStoreConfigQuery query to get store config
242
261
  */
243
262
 
244
263
  /**
@@ -1,5 +1,6 @@
1
1
  import { gql } from '@apollo/client';
2
2
  import { CheckoutPageFragment } from '../CheckoutPage/checkoutPageFragments.gql';
3
+ import { GET_STORE_CONFIG_DATA } from '../CreateAccount/createAccount.gql';
3
4
 
4
5
  export const GET_CUSTOMER = gql`
5
6
  query GetCustomerAfterSignIn {
@@ -17,7 +18,6 @@ export const SIGN_IN = gql`
17
18
  mutation SignIn($email: String!, $password: String!) {
18
19
  generateCustomerToken(email: $email, password: $password) {
19
20
  token
20
- customer_token_lifetime
21
21
  }
22
22
  }
23
23
  `;
@@ -52,5 +52,6 @@ export default {
52
52
  createCartMutation: CREATE_CART,
53
53
  getCustomerQuery: GET_CUSTOMER,
54
54
  mergeCartsMutation: MERGE_CARTS,
55
- signInMutation: SIGN_IN
55
+ signInMutation: SIGN_IN,
56
+ getStoreConfigQuery: GET_STORE_CONFIG_DATA
56
57
  };
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useRef, useState, useMemo } from 'react';
2
- import { useApolloClient, useMutation } from '@apollo/client';
2
+ import { useApolloClient, useMutation, useQuery } from '@apollo/client';
3
3
 
4
4
  import { useGoogleReCaptcha } from '../../hooks/useGoogleReCaptcha/useGoogleReCaptcha';
5
5
  import mergeOperations from '../../util/shallowMerge';
@@ -25,7 +25,8 @@ export const useSignIn = props => {
25
25
  createCartMutation,
26
26
  getCustomerQuery,
27
27
  mergeCartsMutation,
28
- signInMutation
28
+ signInMutation,
29
+ getStoreConfigQuery
29
30
  } = operations;
30
31
 
31
32
  const apolloClient = useApolloClient();
@@ -61,6 +62,19 @@ export const useSignIn = props => {
61
62
  recaptchaWidgetProps
62
63
  } = googleReCaptcha;
63
64
 
65
+ const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
66
+ fetchPolicy: 'cache-and-network',
67
+ nextFetchPolicy: 'cache-first'
68
+ });
69
+
70
+ const { customerAccessTokenLifetime } = useMemo(() => {
71
+ const storeConfig = storeConfigData?.storeConfig || {};
72
+
73
+ return {
74
+ customerAccessTokenLifetime:
75
+ storeConfig.customer_access_token_lifetime
76
+ };
77
+ }, [storeConfigData]);
64
78
  const [fetchCartId] = useMutation(createCartMutation);
65
79
  const [mergeCarts] = useMutation(mergeCartsMutation);
66
80
  const fetchUserDetails = useAwaitQuery(getCustomerQuery);
@@ -91,12 +105,8 @@ export const useSignIn = props => {
91
105
  });
92
106
 
93
107
  const token = signInResponse.data.generateCustomerToken.token;
94
- const customerTokenLifetime =
95
- signInResponse.data.generateCustomerToken
96
- .customer_token_lifetime;
97
-
98
- await (customerTokenLifetime
99
- ? setToken(token, customerTokenLifetime)
108
+ await (customerAccessTokenLifetime
109
+ ? setToken(token, customerAccessTokenLifetime)
100
110
  : setToken(token));
101
111
 
102
112
  // Clear all cart/customer data from cache and redux.
@@ -143,6 +153,7 @@ export const useSignIn = props => {
143
153
  }
144
154
  },
145
155
  [
156
+ customerAccessTokenLifetime,
146
157
  cartId,
147
158
  generateReCaptchaData,
148
159
  signIn,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magento/peregrine",
3
- "version": "14.4.1-alpha.1",
3
+ "version": "14.4.1-alpha.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },