@akinon/next 2.0.0-beta.12 → 2.0.0-beta.13
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 +282 -29
- package/api/auth.ts +99 -77
- package/api/cache.ts +41 -5
- package/api/client.ts +3 -3
- package/api/form.ts +85 -0
- package/api/image-proxy.ts +75 -0
- package/api/product-categories.ts +53 -0
- package/api/similar-product-list.ts +63 -0
- package/api/similar-products.ts +111 -0
- package/api/virtual-try-on.ts +382 -0
- package/bin/pz-generate-routes.js +105 -0
- package/bin/pz-prebuild.js +1 -1
- package/bin/pz-predev.js +1 -0
- package/components/accordion.tsx +21 -6
- package/components/button.tsx +1 -1
- package/components/file-input.tsx +65 -3
- package/components/input.tsx +2 -2
- package/components/modal.tsx +32 -16
- package/components/plugin-module.tsx +61 -3
- package/components/select.tsx +2 -2
- package/components/selected-payment-option-view.tsx +21 -0
- package/data/client/checkout.ts +130 -74
- package/data/server/category.ts +11 -9
- package/data/server/flatpage.ts +4 -1
- package/data/server/form.ts +4 -1
- package/data/server/landingpage.ts +4 -1
- package/data/server/list.ts +5 -4
- package/data/server/menu.ts +4 -1
- package/data/server/product.ts +97 -52
- package/data/server/seo.ts +4 -1
- package/data/server/special-page.ts +5 -4
- package/data/server/widget.ts +4 -1
- package/data/urls.ts +3 -2
- package/hocs/client/with-segment-defaults.tsx +2 -2
- package/hocs/server/with-segment-defaults.tsx +65 -20
- package/hooks/index.ts +1 -0
- package/hooks/use-loyalty-availability.ts +21 -0
- package/hooks/use-payment-options.ts +2 -1
- package/hooks/use-pz-params.ts +37 -0
- package/instrumentation/index.ts +0 -1
- package/instrumentation/node.ts +2 -20
- package/jest.config.js +7 -1
- package/lib/cache-handler.mjs +527 -15
- package/lib/cache.ts +260 -31
- package/localization/provider.tsx +2 -5
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/complete-gpay.ts +33 -26
- package/middlewares/complete-masterpass.ts +34 -26
- package/middlewares/complete-wallet.ts +183 -0
- package/middlewares/default.ts +346 -235
- package/middlewares/index.ts +8 -2
- package/middlewares/locale.ts +0 -1
- package/middlewares/masterpass-rest-callback.ts +220 -0
- package/middlewares/pretty-url.ts +21 -8
- package/middlewares/redirection-payment.ts +33 -26
- package/middlewares/saved-card-redirection.ts +34 -26
- package/middlewares/three-d-redirection.ts +33 -26
- package/middlewares/url-redirection.ts +9 -15
- package/middlewares/wallet-complete-redirection.ts +207 -0
- package/package.json +20 -11
- package/plugins.d.ts +19 -4
- package/plugins.js +9 -1
- package/redux/actions.ts +47 -0
- package/redux/middlewares/checkout.ts +20 -8
- package/redux/middlewares/index.ts +12 -10
- package/redux/middlewares/pre-order/address.ts +1 -1
- package/redux/middlewares/pre-order/attribute-based-shipping-option.ts +1 -1
- package/redux/middlewares/pre-order/data-source-shipping-option.ts +1 -1
- package/redux/middlewares/pre-order/delivery-option.ts +1 -1
- package/redux/middlewares/pre-order/index.ts +3 -1
- package/redux/middlewares/pre-order/installment-option.ts +2 -1
- package/redux/middlewares/pre-order/payment-option-reset.ts +37 -0
- package/redux/middlewares/pre-order/payment-option.ts +1 -1
- package/redux/middlewares/pre-order/pre-order-validation.ts +4 -3
- package/redux/middlewares/pre-order/redirection.ts +2 -2
- package/redux/middlewares/pre-order/set-pre-order.ts +2 -2
- package/redux/middlewares/pre-order/shipping-option.ts +1 -1
- package/redux/middlewares/pre-order/shipping-step.ts +1 -1
- package/redux/reducers/checkout.ts +9 -1
- package/redux/reducers/index.ts +5 -1
- package/sentry/index.ts +54 -17
- package/types/commerce/checkout.ts +11 -1
- package/types/index.ts +96 -6
- package/types/next-auth.d.ts +2 -2
- package/utils/app-fetch.ts +2 -2
- package/utils/generate-commerce-search-params.ts +3 -2
- package/utils/get-checkout-path.ts +3 -0
- package/utils/index.ts +38 -11
- package/utils/override-middleware.ts +1 -0
- package/utils/pz-segments.ts +92 -0
- package/utils/redirect-ignore.ts +35 -0
- package/utils/redirect.ts +9 -3
- package/with-pz-config.js +10 -4
|
@@ -4,6 +4,7 @@ import { PzNextRequest } from '.';
|
|
|
4
4
|
import logger from '../utils/log';
|
|
5
5
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
6
6
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
7
|
+
import { shouldIgnoreRedirect } from '../utils/redirect-ignore';
|
|
7
8
|
import { ROUTES } from 'routes';
|
|
8
9
|
|
|
9
10
|
// This middleware is used to handle url redirections set in Omnitron
|
|
@@ -50,7 +51,7 @@ const withUrlRedirection =
|
|
|
50
51
|
const location = request.headers.get('location');
|
|
51
52
|
const redirectUrl = new URL(
|
|
52
53
|
request.headers.get('location'),
|
|
53
|
-
location.startsWith('http') ? '' :
|
|
54
|
+
location.startsWith('http') ? '' : url.origin
|
|
54
55
|
);
|
|
55
56
|
|
|
56
57
|
redirectUrl.pathname = getUrlPathWithLocale(
|
|
@@ -60,20 +61,13 @@ const withUrlRedirection =
|
|
|
60
61
|
|
|
61
62
|
const setCookies = request.headers.getSetCookie();
|
|
62
63
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
if (shouldIgnoreRedirect) {
|
|
75
|
-
return middleware(req, event);
|
|
76
|
-
}
|
|
64
|
+
if (
|
|
65
|
+
shouldIgnoreRedirect(
|
|
66
|
+
url.pathname,
|
|
67
|
+
req.middlewareParams.rewrites.locale
|
|
68
|
+
)
|
|
69
|
+
) {
|
|
70
|
+
return middleware(req, event);
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
const response = NextResponse.redirect(redirectUrl.toString(), {
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';
|
|
2
|
+
import Settings from 'settings';
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import logger from '../utils/log';
|
|
5
|
+
import { getUrlPathWithLocale } from '../utils/localization';
|
|
6
|
+
import { PzNextRequest } from '.';
|
|
7
|
+
import { getCheckoutPath } from '../utils';
|
|
8
|
+
|
|
9
|
+
const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
|
|
10
|
+
if (stream) {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
let result = '';
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
for await (const chunk of stream as any) {
|
|
16
|
+
chunks.push(Buffer.from(chunk));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
result = Buffer.concat(chunks).toString('utf-8');
|
|
20
|
+
} catch (error) {
|
|
21
|
+
logger.error('Error while reading body stream', {
|
|
22
|
+
middleware: 'wallet-complete-redirection',
|
|
23
|
+
error
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const withWalletCompleteRedirection =
|
|
33
|
+
(middleware: NextMiddleware) =>
|
|
34
|
+
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
35
|
+
const url = req.nextUrl.clone();
|
|
36
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
37
|
+
const sessionId = req.cookies.get('osessionid');
|
|
38
|
+
|
|
39
|
+
if (url.search.indexOf('WalletCompletePage') === -1) {
|
|
40
|
+
return middleware(req, event);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
|
|
44
|
+
const requestUrl = `${Settings.commerceUrl}${getCheckoutPath(isPostCheckout)}${url.search}`;
|
|
45
|
+
const requestHeaders = {
|
|
46
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
47
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
48
|
+
Cookie: req.headers.get('cookie') ?? '',
|
|
49
|
+
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
50
|
+
'x-forwarded-for': ip
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const existingBody = await streamToString(req.body);
|
|
55
|
+
const queryParams = new URLSearchParams(url.search);
|
|
56
|
+
const bodyParams = new URLSearchParams();
|
|
57
|
+
|
|
58
|
+
if (existingBody) {
|
|
59
|
+
try {
|
|
60
|
+
const existingParams = new URLSearchParams(existingBody);
|
|
61
|
+
|
|
62
|
+
existingParams.forEach((value, key) => {
|
|
63
|
+
bodyParams.append(key, value);
|
|
64
|
+
});
|
|
65
|
+
} catch {
|
|
66
|
+
logger.error('Error parsing existing body as URL-encoded data', {
|
|
67
|
+
middleware: 'wallet-complete-redirection',
|
|
68
|
+
existingBody,
|
|
69
|
+
ip
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
queryParams.forEach((value, key) => {
|
|
75
|
+
bodyParams.append(key, value);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const body = bodyParams.toString();
|
|
79
|
+
|
|
80
|
+
if (!sessionId) {
|
|
81
|
+
logger.warn(
|
|
82
|
+
'Make sure that the SESSION_COOKIE_SAMESITE environment variable is set to None in Commerce.',
|
|
83
|
+
{
|
|
84
|
+
middleware: 'wallet-complete-redirection',
|
|
85
|
+
ip
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const fetchResponse = await fetch(requestUrl, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: requestHeaders,
|
|
93
|
+
body
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
logger.info('Complete wallet payment request', {
|
|
97
|
+
requestUrl,
|
|
98
|
+
status: fetchResponse.status,
|
|
99
|
+
requestHeaders,
|
|
100
|
+
ip
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const responseData = await fetchResponse.json();
|
|
104
|
+
|
|
105
|
+
const { context_list: contextList, errors } = responseData;
|
|
106
|
+
const redirectionContext = contextList?.find(
|
|
107
|
+
(context) => context.page_context?.redirect_url
|
|
108
|
+
);
|
|
109
|
+
const redirectUrl = redirectionContext?.page_context?.redirect_url;
|
|
110
|
+
|
|
111
|
+
if (errors && Object.keys(errors).length) {
|
|
112
|
+
logger.error('Error while completing wallet payment', {
|
|
113
|
+
middleware: 'wallet-complete-redirection',
|
|
114
|
+
errors,
|
|
115
|
+
requestHeaders,
|
|
116
|
+
ip
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const errorResponse = NextResponse.redirect(
|
|
120
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
121
|
+
'/orders/checkout/',
|
|
122
|
+
req.cookies.get('pz-locale')?.value
|
|
123
|
+
)}`,
|
|
124
|
+
303
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// Forward set-cookie headers from the upstream response
|
|
128
|
+
const setCookies = fetchResponse.headers.getSetCookie?.() ?? [];
|
|
129
|
+
setCookies.forEach((cookie) => {
|
|
130
|
+
errorResponse.headers.append('Set-Cookie', cookie);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Add error cookie
|
|
134
|
+
errorResponse.headers.append(
|
|
135
|
+
'Set-Cookie',
|
|
136
|
+
`pz-pos-error=${JSON.stringify(errors)}; path=/;`
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return errorResponse;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
logger.info('Order success page context list', {
|
|
143
|
+
middleware: 'wallet-complete-redirection',
|
|
144
|
+
contextList,
|
|
145
|
+
ip
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
if (!redirectUrl) {
|
|
149
|
+
logger.warn(
|
|
150
|
+
'No redirection url for order success page found in page_context. Redirecting to checkout page.',
|
|
151
|
+
{
|
|
152
|
+
middleware: 'wallet-complete-redirection',
|
|
153
|
+
requestHeaders,
|
|
154
|
+
response: JSON.stringify(responseData),
|
|
155
|
+
ip
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
160
|
+
'/orders/checkout/',
|
|
161
|
+
req.cookies.get('pz-locale')?.value
|
|
162
|
+
)}`;
|
|
163
|
+
|
|
164
|
+
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
168
|
+
redirectUrl,
|
|
169
|
+
req.cookies.get('pz-locale')?.value
|
|
170
|
+
)}`;
|
|
171
|
+
|
|
172
|
+
logger.info('Redirecting to order success page', {
|
|
173
|
+
middleware: 'wallet-complete-redirection',
|
|
174
|
+
redirectUrlWithLocale,
|
|
175
|
+
ip
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Using POST method while redirecting causes an error,
|
|
179
|
+
// So we use 303 status code to change the method to GET
|
|
180
|
+
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
181
|
+
|
|
182
|
+
// Forward all set-cookie headers from the upstream response
|
|
183
|
+
const setCookies = fetchResponse.headers.getSetCookie?.() ?? [];
|
|
184
|
+
setCookies.forEach((cookie) => {
|
|
185
|
+
nextResponse.headers.append('Set-Cookie', cookie);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
return nextResponse;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
logger.error('Error while completing wallet payment', {
|
|
191
|
+
middleware: 'wallet-complete-redirection',
|
|
192
|
+
error,
|
|
193
|
+
requestHeaders,
|
|
194
|
+
ip
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return NextResponse.redirect(
|
|
198
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
199
|
+
'/orders/checkout/',
|
|
200
|
+
req.cookies.get('pz-locale')?.value
|
|
201
|
+
)}`,
|
|
202
|
+
303
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export default withWalletCompleteRedirection;
|
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": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.13",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -17,30 +17,39 @@
|
|
|
17
17
|
"test": "jest"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
20
|
+
"@mongodb-js/zstd": "^2.0.1",
|
|
21
|
+
"@neshca/cache-handler": "1.9.0",
|
|
21
22
|
"@opentelemetry/exporter-trace-otlp-http": "0.46.0",
|
|
22
23
|
"@opentelemetry/resources": "1.19.0",
|
|
23
24
|
"@opentelemetry/sdk-node": "0.46.0",
|
|
24
25
|
"@opentelemetry/sdk-trace-node": "1.19.0",
|
|
25
26
|
"@opentelemetry/semantic-conventions": "1.19.0",
|
|
26
|
-
"@reduxjs/toolkit": "
|
|
27
|
-
"@sentry/nextjs": "
|
|
27
|
+
"@reduxjs/toolkit": "2.11.2",
|
|
28
|
+
"@sentry/nextjs": "10.39.0",
|
|
28
29
|
"cross-spawn": "7.0.3",
|
|
29
30
|
"generic-pool": "3.9.0",
|
|
30
|
-
"react-redux": "
|
|
31
|
+
"react-redux": "9.2.0",
|
|
31
32
|
"react-string-replace": "1.1.1",
|
|
32
33
|
"redis": "4.6.13",
|
|
33
34
|
"semver": "7.6.2",
|
|
34
35
|
"set-cookie-parser": "2.6.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@akinon/eslint-plugin-projectzero": "2.0.0-beta.
|
|
38
|
+
"@akinon/eslint-plugin-projectzero": "2.0.0-beta.13",
|
|
39
|
+
"@babel/core": "7.26.10",
|
|
40
|
+
"@babel/preset-env": "7.26.9",
|
|
41
|
+
"@babel/preset-typescript": "7.27.0",
|
|
42
|
+
"@types/jest": "29.5.14",
|
|
38
43
|
"@types/react-redux": "7.1.30",
|
|
39
44
|
"@types/set-cookie-parser": "2.4.7",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "
|
|
41
|
-
"@typescript-eslint/parser": "
|
|
42
|
-
"
|
|
43
|
-
"eslint
|
|
44
|
-
"eslint-config-
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
46
|
+
"@typescript-eslint/parser": "6.7.4",
|
|
47
|
+
"babel-jest": "29.7.0",
|
|
48
|
+
"eslint": "8.56.0",
|
|
49
|
+
"eslint-config-next": "16.1.6",
|
|
50
|
+
"eslint-config-prettier": "8.5.0",
|
|
51
|
+
"jest": "29.7.0",
|
|
52
|
+
"ts-jest": "29.3.2",
|
|
53
|
+
"typescript": "5.9.3"
|
|
45
54
|
}
|
|
46
55
|
}
|
package/plugins.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ declare module '@akinon/pz-masterpass/src/redux/reducer' {
|
|
|
13
13
|
export const setError: any;
|
|
14
14
|
export const setOtpModalVisible: any;
|
|
15
15
|
export const setCvcRequired: any;
|
|
16
|
+
export const resetMasterpassState: any;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
declare module '@akinon/pz-otp' {
|
|
@@ -30,9 +31,23 @@ declare module '@akinon/pz-saved-card' {
|
|
|
30
31
|
export const SavedCardOption: any;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
declare module '@akinon/pz-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
declare module '@akinon/pz-apple-pay' {}
|
|
35
|
+
|
|
36
|
+
declare module '@akinon/pz-cybersource-uc/src/redux/middleware' {
|
|
37
|
+
export default middleware as any;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
declare module '@akinon/pz-
|
|
40
|
+
declare module '@akinon/pz-cybersource-uc/src/redux/reducer' {
|
|
41
|
+
export default reducer as any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module '@akinon/pz-cybersource-uc' {
|
|
45
|
+
export const CyberSourceUcPaymentOption: any;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare module '@akinon/pz-flow-payment' {}
|
|
49
|
+
|
|
50
|
+
declare module '@akinon/pz-masterpass-rest' {
|
|
51
|
+
export const MasterpassRestOption: React.FC;
|
|
52
|
+
export const masterpassRestReducer: any;
|
|
53
|
+
}
|
package/plugins.js
CHANGED
|
@@ -15,5 +15,13 @@ module.exports = [
|
|
|
15
15
|
'pz-saved-card',
|
|
16
16
|
'pz-tabby-extension',
|
|
17
17
|
'pz-apple-pay',
|
|
18
|
-
'pz-tamara-extension'
|
|
18
|
+
'pz-tamara-extension',
|
|
19
|
+
'pz-cybersource-uc',
|
|
20
|
+
'pz-hepsipay',
|
|
21
|
+
'pz-flow-payment',
|
|
22
|
+
'pz-virtual-try-on',
|
|
23
|
+
'pz-masterpass-rest',
|
|
24
|
+
'pz-similar-products',
|
|
25
|
+
'pz-haso',
|
|
26
|
+
'pz-google-pay'
|
|
19
27
|
];
|
package/redux/actions.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Re-export all action creators from slice modules
|
|
2
|
+
export * from './reducers/root';
|
|
3
|
+
export * from './reducers/header';
|
|
4
|
+
export * from './reducers/checkout';
|
|
5
|
+
export * from './reducers/config';
|
|
6
|
+
|
|
7
|
+
// Import RTK Query APIs
|
|
8
|
+
import { basketApi } from '../data/client/basket';
|
|
9
|
+
import { productApi } from '../data/client/product';
|
|
10
|
+
import { miscApi } from '../data/client/misc';
|
|
11
|
+
import { checkoutApi } from '../data/client/checkout';
|
|
12
|
+
import { wishlistApi } from '../data/client/wishlist';
|
|
13
|
+
|
|
14
|
+
// Create RTK Query action creators
|
|
15
|
+
export const rtkApiActionCreators = {
|
|
16
|
+
// RTK Query API endpoints
|
|
17
|
+
...Object.fromEntries(
|
|
18
|
+
Object.entries(basketApi.endpoints).map(([key, endpoint]) => [
|
|
19
|
+
`api_basket_${key}`,
|
|
20
|
+
endpoint.initiate
|
|
21
|
+
])
|
|
22
|
+
),
|
|
23
|
+
...Object.fromEntries(
|
|
24
|
+
Object.entries(productApi.endpoints).map(([key, endpoint]) => [
|
|
25
|
+
`api_product_${key}`,
|
|
26
|
+
endpoint.initiate
|
|
27
|
+
])
|
|
28
|
+
),
|
|
29
|
+
...Object.fromEntries(
|
|
30
|
+
Object.entries(miscApi.endpoints).map(([key, endpoint]) => [
|
|
31
|
+
`api_misc_${key}`,
|
|
32
|
+
endpoint.initiate
|
|
33
|
+
])
|
|
34
|
+
),
|
|
35
|
+
...Object.fromEntries(
|
|
36
|
+
Object.entries(checkoutApi.endpoints).map(([key, endpoint]) => [
|
|
37
|
+
`api_checkout_${key}`,
|
|
38
|
+
endpoint.initiate
|
|
39
|
+
])
|
|
40
|
+
),
|
|
41
|
+
...Object.fromEntries(
|
|
42
|
+
Object.entries(wishlistApi.endpoints).map(([key, endpoint]) => [
|
|
43
|
+
`api_wishlist_${key}`,
|
|
44
|
+
endpoint.initiate
|
|
45
|
+
])
|
|
46
|
+
)
|
|
47
|
+
} as any;
|
|
@@ -20,7 +20,8 @@ import {
|
|
|
20
20
|
setShippingOptions,
|
|
21
21
|
setHepsipayAvailability,
|
|
22
22
|
setWalletPaymentData,
|
|
23
|
-
setPayOnDeliveryOtpModalActive
|
|
23
|
+
setPayOnDeliveryOtpModalActive,
|
|
24
|
+
setUnavailablePaymentOptions
|
|
24
25
|
} from '../../redux/reducers/checkout';
|
|
25
26
|
import { RootState, TypedDispatch } from 'redux/store';
|
|
26
27
|
import { checkoutApi } from '../../data/client/checkout';
|
|
@@ -47,7 +48,7 @@ interface MiddlewareParams {
|
|
|
47
48
|
|
|
48
49
|
export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
|
|
49
50
|
return (next) => (action) => {
|
|
50
|
-
const result
|
|
51
|
+
const result = next(action) as CheckoutResult;
|
|
51
52
|
const errors = result?.payload?.errors;
|
|
52
53
|
|
|
53
54
|
if (errors) {
|
|
@@ -60,7 +61,7 @@ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
|
|
|
60
61
|
|
|
61
62
|
export const redirectUrlMiddleware: Middleware = () => {
|
|
62
63
|
return (next) => (action) => {
|
|
63
|
-
const result
|
|
64
|
+
const result = next(action) as CheckoutResult;
|
|
64
65
|
const redirectUrl = result?.payload?.redirect_url;
|
|
65
66
|
|
|
66
67
|
if (redirectUrl) {
|
|
@@ -91,13 +92,13 @@ export const contextListMiddleware: Middleware = ({
|
|
|
91
92
|
}: MiddlewareParams) => {
|
|
92
93
|
return (next) => (action) => {
|
|
93
94
|
const { isMobileApp, userPhoneNumber } = getState().root;
|
|
94
|
-
const result
|
|
95
|
+
const result = next(action) as CheckoutResult;
|
|
95
96
|
const preOrder = result?.payload?.pre_order;
|
|
96
97
|
|
|
97
98
|
if (result?.payload?.context_list) {
|
|
98
99
|
result.payload.context_list.forEach((context) => {
|
|
99
100
|
const redirectUrl = context.page_context.redirect_url;
|
|
100
|
-
const isIframe = context.page_context.
|
|
101
|
+
const isIframe = context.page_context.is_iframe ?? false;
|
|
101
102
|
|
|
102
103
|
if (redirectUrl) {
|
|
103
104
|
const currentLocale = getCookie('pz-locale');
|
|
@@ -176,6 +177,14 @@ export const contextListMiddleware: Middleware = ({
|
|
|
176
177
|
dispatch(setPaymentOptions(context.page_context.payment_options));
|
|
177
178
|
}
|
|
178
179
|
|
|
180
|
+
if (context.page_context.unavailable_options) {
|
|
181
|
+
dispatch(
|
|
182
|
+
setUnavailablePaymentOptions(
|
|
183
|
+
context.page_context.unavailable_options
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
179
188
|
if (context.page_context.credit_payment_options) {
|
|
180
189
|
dispatch(
|
|
181
190
|
setCreditPaymentOptions(context.page_context.credit_payment_options)
|
|
@@ -199,7 +208,10 @@ export const contextListMiddleware: Middleware = ({
|
|
|
199
208
|
dispatch(setCardType(context.page_context.card_type));
|
|
200
209
|
}
|
|
201
210
|
|
|
202
|
-
if (
|
|
211
|
+
if (
|
|
212
|
+
context.page_context.installments &&
|
|
213
|
+
preOrder?.payment_option?.payment_type !== 'masterpass_rest'
|
|
214
|
+
) {
|
|
203
215
|
dispatch(setInstallmentOptions(context.page_context.installments));
|
|
204
216
|
}
|
|
205
217
|
}
|
|
@@ -235,7 +247,7 @@ export const hepsiPayMiddleware: Middleware = ({
|
|
|
235
247
|
dispatch
|
|
236
248
|
}: MiddlewareParams) => {
|
|
237
249
|
return (next) => (action) => {
|
|
238
|
-
const result
|
|
250
|
+
const result = next(action) as CheckoutResult;
|
|
239
251
|
const { payload } = result;
|
|
240
252
|
const preOrder = payload?.pre_order;
|
|
241
253
|
const contextList = payload?.context_list;
|
|
@@ -289,7 +301,7 @@ export const walletPaymentMiddleware: Middleware = ({
|
|
|
289
301
|
dispatch
|
|
290
302
|
}: MiddlewareParams) => {
|
|
291
303
|
return (next) => (action) => {
|
|
292
|
-
const result
|
|
304
|
+
const result = next(action) as CheckoutResult;
|
|
293
305
|
const { payload } = result;
|
|
294
306
|
const preOrder = payload?.pre_order;
|
|
295
307
|
const contextList = payload?.context_list;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { signOut } from 'next-auth/react';
|
|
4
4
|
import { ROUTES } from 'routes';
|
|
5
5
|
import type { Middleware } from '@reduxjs/toolkit';
|
|
6
|
+
import type { MiddlewareAction } from '../../types';
|
|
6
7
|
import {
|
|
7
8
|
errorMiddleware,
|
|
8
9
|
redirectUrlMiddleware,
|
|
@@ -18,17 +19,17 @@ import logger from '@akinon/next/utils/log';
|
|
|
18
19
|
|
|
19
20
|
// Plugin middlewares
|
|
20
21
|
import { savedCardMiddleware } from '@akinon/pz-saved-card';
|
|
22
|
+
import cyberSourceUcMiddleware from '@akinon/pz-cybersource-uc/src/redux/middleware';
|
|
21
23
|
|
|
22
|
-
export const rtkQueryResponseHandler: Middleware =
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
(action) => {
|
|
26
|
-
return next(action);
|
|
27
|
-
};
|
|
24
|
+
export const rtkQueryResponseHandler: Middleware = () => (next) => (action) => {
|
|
25
|
+
return next(action);
|
|
26
|
+
};
|
|
28
27
|
|
|
29
28
|
export const rtkQueryErrorHandler: Middleware =
|
|
30
29
|
() => (next) => async (action) => {
|
|
31
|
-
|
|
30
|
+
const act = action as MiddlewareAction;
|
|
31
|
+
|
|
32
|
+
if (act?.payload?.status === 401) {
|
|
32
33
|
await signOut({
|
|
33
34
|
callbackUrl: `${ROUTES.AUTH}?callbackUrl=${window.location.pathname}`
|
|
34
35
|
});
|
|
@@ -37,9 +38,9 @@ export const rtkQueryErrorHandler: Middleware =
|
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
if (
|
|
41
|
+
if (act?.payload?.status === 404) {
|
|
41
42
|
logger.warn(
|
|
42
|
-
`404 - Not Found. Endpoint: ${
|
|
43
|
+
`404 - Not Found. Endpoint: ${act.meta.arg.endpointName}, url: ${act.meta.baseQueryMeta.request.url}`
|
|
43
44
|
);
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -56,7 +57,8 @@ const middlewares = [
|
|
|
56
57
|
contextListMiddleware,
|
|
57
58
|
hepsiPayMiddleware,
|
|
58
59
|
walletPaymentMiddleware,
|
|
59
|
-
savedCardMiddleware
|
|
60
|
+
savedCardMiddleware,
|
|
61
|
+
cyberSourceUcMiddleware
|
|
60
62
|
];
|
|
61
63
|
|
|
62
64
|
// Filter out any non-function middleware to ensure all middlewares are valid and executable
|
|
@@ -7,7 +7,7 @@ export const setAddressMiddleware: Middleware = ({
|
|
|
7
7
|
dispatch
|
|
8
8
|
}: MiddlewareParams) => {
|
|
9
9
|
return (next) => (action) => {
|
|
10
|
-
const result
|
|
10
|
+
const result = next(action) as CheckoutResult;
|
|
11
11
|
const preOrder = result?.payload?.pre_order;
|
|
12
12
|
|
|
13
13
|
if (!preOrder) {
|
|
@@ -7,7 +7,7 @@ export const attributeBasedShippingOptionMiddleware: Middleware = ({
|
|
|
7
7
|
dispatch
|
|
8
8
|
}: MiddlewareParams) => {
|
|
9
9
|
return (next) => (action) => {
|
|
10
|
-
const result
|
|
10
|
+
const result = next(action) as CheckoutResult;
|
|
11
11
|
const preOrder = result?.payload?.pre_order;
|
|
12
12
|
|
|
13
13
|
if (!preOrder) {
|
|
@@ -7,7 +7,7 @@ export const dataSourceShippingOptionMiddleware: Middleware = ({
|
|
|
7
7
|
dispatch
|
|
8
8
|
}: MiddlewareParams) => {
|
|
9
9
|
return (next) => (action) => {
|
|
10
|
-
const result
|
|
10
|
+
const result = next(action) as CheckoutResult;
|
|
11
11
|
const preOrder = result?.payload?.pre_order;
|
|
12
12
|
|
|
13
13
|
if (!preOrder) {
|
|
@@ -7,7 +7,7 @@ export const deliveryOptionMiddleware: Middleware = ({
|
|
|
7
7
|
dispatch
|
|
8
8
|
}: MiddlewareParams) => {
|
|
9
9
|
return (next) => (action) => {
|
|
10
|
-
const result
|
|
10
|
+
const result = next(action) as CheckoutResult;
|
|
11
11
|
const preOrder = result?.payload?.pre_order;
|
|
12
12
|
|
|
13
13
|
if (!preOrder) {
|
|
@@ -8,15 +8,17 @@ import { dataSourceShippingOptionMiddleware } from './data-source-shipping-optio
|
|
|
8
8
|
import { attributeBasedShippingOptionMiddleware } from './attribute-based-shipping-option';
|
|
9
9
|
import { paymentOptionMiddleware } from './payment-option';
|
|
10
10
|
import { installmentOptionMiddleware } from './installment-option';
|
|
11
|
+
import { paymentOptionResetMiddleware } from './payment-option-reset';
|
|
11
12
|
import { shippingStepMiddleware } from './shipping-step';
|
|
12
13
|
|
|
13
14
|
// ⚠️ WARNING: Redux Toolkit applies middlewares in reverse order (from last to first).
|
|
14
|
-
// This list is written **in reverse execution order** to ensure they run in the correct sequence.
|
|
15
|
+
// This list is written **in reverse execution order** to ensure they run in the correct sequence.
|
|
15
16
|
// If you add a new middleware, make sure to insert it **in reverse order** based on execution priority.
|
|
16
17
|
|
|
17
18
|
export const preOrderMiddlewares = [
|
|
18
19
|
shippingStepMiddleware,
|
|
19
20
|
installmentOptionMiddleware,
|
|
21
|
+
paymentOptionResetMiddleware,
|
|
20
22
|
paymentOptionMiddleware,
|
|
21
23
|
attributeBasedShippingOptionMiddleware,
|
|
22
24
|
dataSourceShippingOptionMiddleware,
|
|
@@ -7,7 +7,7 @@ export const installmentOptionMiddleware: Middleware = ({
|
|
|
7
7
|
dispatch
|
|
8
8
|
}: MiddlewareParams) => {
|
|
9
9
|
return (next) => (action) => {
|
|
10
|
-
const result
|
|
10
|
+
const result = next(action) as CheckoutResult;
|
|
11
11
|
const preOrder = result?.payload?.pre_order;
|
|
12
12
|
|
|
13
13
|
if (!preOrder) {
|
|
@@ -20,6 +20,7 @@ export const installmentOptionMiddleware: Middleware = ({
|
|
|
20
20
|
if (
|
|
21
21
|
!preOrder?.installment &&
|
|
22
22
|
preOrder?.payment_option?.payment_type !== 'saved_card' &&
|
|
23
|
+
preOrder?.payment_option?.payment_type !== 'masterpass_rest' &&
|
|
23
24
|
installmentOptions.length > 0
|
|
24
25
|
) {
|
|
25
26
|
const firstInstallmentOptionPk = installmentOptions[0]?.pk;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Middleware } from '@reduxjs/toolkit';
|
|
2
|
+
import { CheckoutResult, MiddlewareAction, MiddlewareParams } from '../../../types';
|
|
3
|
+
import {
|
|
4
|
+
setBankAccounts,
|
|
5
|
+
setCardType,
|
|
6
|
+
setInstallmentOptions,
|
|
7
|
+
setSelectedBankAccountPk
|
|
8
|
+
} from '../../reducers/checkout';
|
|
9
|
+
import { resetMasterpassState } from '@akinon/pz-masterpass/src/redux/reducer';
|
|
10
|
+
|
|
11
|
+
export const paymentOptionResetMiddleware: Middleware = ({
|
|
12
|
+
dispatch
|
|
13
|
+
}: MiddlewareParams) => {
|
|
14
|
+
return (next) => (action) => {
|
|
15
|
+
const result = next(action) as CheckoutResult;
|
|
16
|
+
const act = action as MiddlewareAction;
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
act.type === 'api/executeMutation/fulfilled' &&
|
|
20
|
+
act.meta?.arg?.endpointName === 'setPaymentOption'
|
|
21
|
+
) {
|
|
22
|
+
dispatch(setInstallmentOptions([]));
|
|
23
|
+
dispatch(setBankAccounts([]));
|
|
24
|
+
dispatch(setSelectedBankAccountPk(null));
|
|
25
|
+
dispatch(setCardType(null));
|
|
26
|
+
if(resetMasterpassState){
|
|
27
|
+
dispatch(resetMasterpassState());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Object.defineProperty(paymentOptionResetMiddleware, 'name', {
|
|
36
|
+
value: 'paymentOptionResetMiddleware'
|
|
37
|
+
});
|
|
@@ -7,7 +7,7 @@ export const paymentOptionMiddleware: Middleware = ({
|
|
|
7
7
|
dispatch
|
|
8
8
|
}: MiddlewareParams) => {
|
|
9
9
|
return (next) => (action) => {
|
|
10
|
-
const result
|
|
10
|
+
const result = next(action) as CheckoutResult;
|
|
11
11
|
const preOrder = result?.payload?.pre_order;
|
|
12
12
|
|
|
13
13
|
if (!preOrder) {
|