@akinon/next 1.81.0 → 1.82.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.82.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2e0b7ff: ZERO-3226: Refactor checkoutApi to simplify request body structure by removing device_info parameter
8
+ - 778aabf: ZERO-3163: Add frontend ID header to authentication requests and forgot password mutation
9
+ - c0fef07: ZERO-3197: Refetch payment options after loyalty usage
10
+ - 2d2ab44: ZERO-3226: Add device_info param to WalletPaymentPage request
11
+ - 0200d56: ZERO-3163: Add frontendIds property to Settings interface
12
+ - 7d1b5af: ZERO-3206: Encode search parameters in product data URL
13
+ - aa05ed7: ZERO-3170: Add commerceRedirectionIgnoreList to settings and update URL redirection middleware
14
+
3
15
  ## 1.81.0
4
16
 
5
17
  ### Minor Changes
package/api/auth.ts CHANGED
@@ -92,6 +92,8 @@ const nextAuthOptions = (req: NextApiRequest, res: NextApiResponse) => {
92
92
  req.headers['x-app-device']?.toString() ?? ''
93
93
  );
94
94
 
95
+ headers.set('x-frontend-id', req.cookies['pz-frontend-id'] || '');
96
+
95
97
  logger.debug('Trying to login/register', {
96
98
  formType: credentials.formType,
97
99
  userIp
@@ -72,6 +72,7 @@ export const api = createApi({
72
72
  'DraftsB2b',
73
73
  'Product',
74
74
  'Checkout',
75
+ 'PaymentOptions',
75
76
  'Favorite',
76
77
  'Addresses',
77
78
  'Profile',
@@ -2,6 +2,7 @@ import {
2
2
  setBankAccounts,
3
3
  setCardType,
4
4
  setInstallmentOptions,
5
+ setPaymentOptions,
5
6
  setPaymentStepBusy,
6
7
  setSelectedBankAccountPk,
7
8
  setSelectedCreditPaymentPk,
@@ -424,6 +425,12 @@ export const checkoutApi = api.injectEndpoints({
424
425
  }
425
426
  })
426
427
  }),
428
+ fetchPaymentOptions: build.query<CheckoutResponse, void>({
429
+ query: () => ({
430
+ url: buildClientRequestUrl(checkout.setPaymentOption)
431
+ }),
432
+ providesTags: ['PaymentOptions']
433
+ }),
427
434
  setPaymentOption: build.mutation<CheckoutResponse, number>({
428
435
  query: (pk: number) => ({
429
436
  url: buildClientRequestUrl(checkout.setPaymentOption, {
@@ -472,16 +479,15 @@ export const checkoutApi = api.injectEndpoints({
472
479
  CheckoutResponse,
473
480
  {
474
481
  payment_token?: string;
482
+ [key: string]: any;
475
483
  }
476
484
  >({
477
- query: ({ payment_token }) => ({
485
+ query: (requestBody) => ({
478
486
  url: buildClientRequestUrl(checkout.setWalletPaymentPage, {
479
487
  useFormData: true
480
488
  }),
481
489
  method: 'POST',
482
- body: {
483
- payment_token
484
- }
490
+ body: requestBody
485
491
  }),
486
492
  async onQueryStarted(arg, { dispatch, queryFulfilled }) {
487
493
  dispatch(setPaymentStepBusy(true));
@@ -737,7 +743,27 @@ export const checkoutApi = api.injectEndpoints({
737
743
  body: {
738
744
  loyalty_amount_to_use: amount
739
745
  }
740
- })
746
+ }),
747
+ async onQueryStarted(arg, { dispatch, queryFulfilled }) {
748
+ dispatch(setPaymentStepBusy(true));
749
+ dispatch(setPaymentOptions([]));
750
+ await queryFulfilled;
751
+
752
+ const paymentOptionsData = await dispatch(
753
+ checkoutApi.endpoints.fetchPaymentOptions.initiate()
754
+ ).unwrap();
755
+
756
+ const paymentOptions = paymentOptionsData?.context_list?.find(
757
+ (context) => context?.page_name === 'PaymentOptionSelectionPage'
758
+ )?.page_context?.payment_options;
759
+
760
+ if (paymentOptions) {
761
+ dispatch(setPaymentOptions(paymentOptions));
762
+ }
763
+
764
+ dispatch(setPaymentStepBusy(false));
765
+ },
766
+ invalidatesTags: ['PaymentOptions']
741
767
  }),
742
768
  setOrderNote: build.mutation<CheckoutResponse, string>({
743
769
  query: (notes) => ({
@@ -840,6 +866,7 @@ export const {
840
866
  useSetAddressesMutation,
841
867
  useSetShippingOptionMutation,
842
868
  useSetDataSourceShippingOptionsMutation,
869
+ useFetchPaymentOptionsQuery,
843
870
  useSetPaymentOptionMutation,
844
871
  useSetBinNumberMutation,
845
872
  useSetInstallmentOptionMutation,
@@ -1,7 +1,7 @@
1
1
  import { api } from './api';
2
2
  import { user } from '../urls';
3
3
  import { ForgotPasswordFormType, Order } from '../../types';
4
- import { buildClientRequestUrl } from '../../utils';
4
+ import { buildClientRequestUrl, getCookie } from '../../utils';
5
5
 
6
6
  interface GetCaptchaResponse {
7
7
  siteKey: string;
@@ -64,13 +64,21 @@ const userApi = api.injectEndpoints({
64
64
  })
65
65
  }),
66
66
  forgotPassword: build.mutation<void, ForgotPasswordFormType>({
67
- query: (body) => ({
68
- url: buildClientRequestUrl(user.forgotPassword, {
69
- contentType: 'application/json'
70
- }),
71
- method: 'POST',
72
- body
73
- })
67
+ query: (body) => {
68
+ const frontendId = getCookie('pz-frontend-id');
69
+ const headers = frontendId
70
+ ? { 'x-frontend-id': frontendId }
71
+ : undefined;
72
+
73
+ return {
74
+ url: buildClientRequestUrl(user.forgotPassword, {
75
+ contentType: 'application/json'
76
+ }),
77
+ method: 'POST',
78
+ body,
79
+ headers
80
+ };
81
+ }
74
82
  }),
75
83
  otpLogin: build.mutation<void, { phone: string }>({
76
84
  query: ({ phone }) => ({
@@ -31,7 +31,7 @@ const getProductDataHandler = ({
31
31
  url +=
32
32
  '?' +
33
33
  Object.keys(searchParams)
34
- .map((key) => `${key}=${searchParams[key]}`)
34
+ .map((key) => `${key}=${encodeURIComponent(searchParams[key])}`)
35
35
  .join('&');
36
36
  }
37
37
 
@@ -60,6 +60,22 @@ const withUrlRedirection =
60
60
 
61
61
  const setCookies = request.headers.getSetCookie();
62
62
 
63
+ if (settings.commerceRedirectionIgnoreList) {
64
+ const shouldIgnoreRedirect =
65
+ settings.commerceRedirectionIgnoreList.some((ignorePath) =>
66
+ redirectUrl.pathname.startsWith(
67
+ getUrlPathWithLocale(
68
+ ignorePath,
69
+ req.middlewareParams.rewrites.locale
70
+ )
71
+ )
72
+ );
73
+
74
+ if (shouldIgnoreRedirect) {
75
+ return middleware(req, event);
76
+ }
77
+ }
78
+
63
79
  const response = NextResponse.redirect(redirectUrl.toString(), {
64
80
  status: request.status
65
81
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.81.0",
4
+ "version": "1.82.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -30,7 +30,7 @@
30
30
  "set-cookie-parser": "2.6.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@akinon/eslint-plugin-projectzero": "1.81.0",
33
+ "@akinon/eslint-plugin-projectzero": "1.82.0",
34
34
  "@types/react-redux": "7.1.30",
35
35
  "@types/set-cookie-parser": "2.4.7",
36
36
  "@typescript-eslint/eslint-plugin": "6.7.4",
package/types/index.ts CHANGED
@@ -203,11 +203,13 @@ export interface Settings {
203
203
  useOptimizedTranslations?: boolean;
204
204
  plugins?: Record<string, Record<string, any>>;
205
205
  includedProxyHeaders?: string[];
206
+ commerceRedirectionIgnoreList?: string[];
206
207
  /**
207
208
  * By default, the currency will be reset when the currency is changed.
208
209
  * If you want to keep the basket when the currency is changed, you can set this option to `false`.
209
210
  */
210
211
  resetBasketOnCurrencyChange?: boolean;
212
+ frontendIds?: Record<string, number>;
211
213
  }
212
214
 
213
215
  export interface CacheOptions {