@akinon/next 1.120.0-rc.4 → 1.120.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 +2 -43
- package/bin/pz-generate-routes.js +1 -10
- package/components/plugin-module.tsx +2 -2
- package/data/client/account.ts +1 -12
- package/data/urls.ts +1 -5
- package/lib/cache-handler.mjs +0 -3
- package/middlewares/default.ts +7 -14
- package/middlewares/index.ts +1 -3
- package/middlewares/masterpass-rest-callback.ts +151 -28
- package/middlewares/oauth-login.ts +40 -100
- package/package.json +2 -2
- package/plugins.d.ts +0 -10
- package/plugins.js +0 -1
- package/redux/middlewares/checkout.ts +1 -11
- package/redux/middlewares/pre-order/installment-option.ts +1 -9
- package/types/index.ts +0 -6
- package/utils/app-fetch.ts +6 -13
- package/utils/index.ts +7 -3
- package/utils/mobile-3d-iframe.ts +2 -8
- package/utils/redirection-iframe.ts +2 -8
- package/with-pz-config.js +4 -1
- package/api/barcode-search.ts +0 -59
- package/middlewares/bfcache-headers.ts +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,56 +1,15 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 1.120.0
|
|
3
|
+
## 1.120.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
## 1.120.0-rc.3
|
|
10
|
-
|
|
11
|
-
### Minor Changes
|
|
12
|
-
|
|
13
|
-
- 760258c1: ZERO-4160: Enhance oauth-login middleware to handle fetch errors and improve response handling
|
|
14
|
-
|
|
15
|
-
## 1.120.0-rc.2
|
|
16
|
-
|
|
17
|
-
### Minor Changes
|
|
18
|
-
|
|
19
|
-
- 8218dafa: ZERO-4160: Refactor oauth-login middleware to use fetch for login and callback responses
|
|
20
|
-
|
|
21
|
-
## 1.120.0-rc.1
|
|
22
|
-
|
|
23
|
-
### Minor Changes
|
|
24
|
-
|
|
25
|
-
- bcaad120: ZERO-4158: Add logging for OAuth login and callback redirects
|
|
26
|
-
|
|
27
|
-
## 1.120.0-rc.0
|
|
28
|
-
|
|
29
|
-
### Minor Changes
|
|
30
|
-
|
|
31
|
-
- 31b4a266: ZERO-4102: Add support for post-checkout redirect in middleware
|
|
32
|
-
- d2c0e759: ZERO-3684: Handle cross-origin iframe access in iframeURLChange function
|
|
7
|
+
- b12527ec: ZERO-4102: Add support for post-checkout redirect in middleware
|
|
33
8
|
- aef81c5d: ZERO-4034: Refactor checkout API to use dynamic store imports for improved performance
|
|
34
|
-
- b55acb76: ZERO-2577: Fix pagination bug and update usePagination hook and ensure pagination controls rendering correctly
|
|
35
|
-
- 8a7fd0f4: ZERO-4065: Add '[segment]' to skipSegments in route generation
|
|
36
|
-
- 36143125: ZERO-3987: Add barcode scanner functionality with modal and button
|
|
37
9
|
- 0754c835: ZERO-4063: Add support for optional Redis password in cache handlers
|
|
38
|
-
- f7e0f646: ZERO-4032: Add bfcache-headers middleware, integrate it into the default chain, and introduce a new environment variable for control.
|
|
39
|
-
- 94a86fcc: ZERO-4065: Expand skipSegments array to include additional segments for route generation
|
|
40
|
-
- 143be2b9: ZERO-3457: Crop styles are customizable and logic improved for rendering similar products modal
|
|
41
|
-
- cd68a97a: ZERO-4126: Enhance error handling in appFetch and related data handlers to throw notFound on 404 and 422 errors
|
|
42
|
-
- 9f8cd3bc: ZERO-3449: AI Search Active Filters & Crop Style changes have been implemented
|
|
43
|
-
- 49c82e1a: ZERO-4047: Remove Sentry configuration from default Next.js config
|
|
44
10
|
- a9f5cdb1: ZERO-4102: Fix post-checkout condition to additionally check for empty search parameters.
|
|
45
|
-
- d99a6a7d: ZERO-3457_1: Fixed the settings prop and made sure everything is customizable.
|
|
46
|
-
- d7e5178b: ZERO-3985: Add query string handling for orders redirection in middleware
|
|
47
|
-
- 591e345e: ZERO-3855: Enhance credit card payment handling in checkout middlewares
|
|
48
11
|
- 01ee41f1: ZERO-4102: Implement a post-checkout flow by dynamically determining checkout paths and managing a pz-post-checkout-flow cookie.
|
|
49
|
-
- 4de5303c: ZERO-2504: add cookie filter to api client request
|
|
50
|
-
- b59fdd1c: ZERO-4009: Add password reset token validation
|
|
51
|
-
- 95b139dc: ZERO-3795: Remove duplicate entry for SavedCard in PluginComponents map
|
|
52
12
|
- c6c5c1cd: ZERO-4128: Use cookies API for pz-pos-error to ensure delivery on 303 redirects
|
|
53
|
-
- 3909d322: Edit the duplicate Plugin.SimilarProducts in the plugin-module.
|
|
54
13
|
|
|
55
14
|
## 1.119.0
|
|
56
15
|
|
|
@@ -25,16 +25,7 @@ const generateRoutes = () => {
|
|
|
25
25
|
const routes = [];
|
|
26
26
|
const excludedDirs = ['api', 'pz-not-found'];
|
|
27
27
|
|
|
28
|
-
const skipSegments = [
|
|
29
|
-
'[commerce]',
|
|
30
|
-
'[locale]',
|
|
31
|
-
'[currency]',
|
|
32
|
-
'[session]',
|
|
33
|
-
'[segment]',
|
|
34
|
-
'[url]',
|
|
35
|
-
'[theme]',
|
|
36
|
-
'[member_type]'
|
|
37
|
-
];
|
|
28
|
+
const skipSegments = ['[commerce]', '[locale]', '[currency]'];
|
|
38
29
|
const skipCatchAllRoutes = ['[...prettyurl]', '[...not_found]'];
|
|
39
30
|
|
|
40
31
|
const walkDirectory = (dir, basePath = '') => {
|
|
@@ -55,7 +55,6 @@ export enum Component {
|
|
|
55
55
|
SavedCard = 'SavedCardOption',
|
|
56
56
|
VirtualTryOnPlugin = 'VirtualTryOnPlugin',
|
|
57
57
|
BasketVirtualTryOn = 'BasketVirtualTryOn',
|
|
58
|
-
BarcodeScannerPlugin = 'BarcodeScannerPlugin',
|
|
59
58
|
IyzicoSavedCard = 'IyzicoSavedCardOption',
|
|
60
59
|
Hepsipay = 'Hepsipay',
|
|
61
60
|
FlowPayment = 'FlowPayment',
|
|
@@ -114,10 +113,11 @@ const PluginComponents = new Map([
|
|
|
114
113
|
]
|
|
115
114
|
],
|
|
116
115
|
[Plugin.SavedCard, [Component.SavedCard, Component.IyzicoSavedCard]],
|
|
116
|
+
[Plugin.SavedCard, [Component.SavedCard]],
|
|
117
117
|
[Plugin.FlowPayment, [Component.FlowPayment]],
|
|
118
118
|
[
|
|
119
119
|
Plugin.VirtualTryOn,
|
|
120
|
-
[Component.VirtualTryOnPlugin, Component.BasketVirtualTryOn
|
|
120
|
+
[Component.VirtualTryOnPlugin, Component.BasketVirtualTryOn]
|
|
121
121
|
],
|
|
122
122
|
[Plugin.Hepsipay, [Component.Hepsipay]],
|
|
123
123
|
[Plugin.MasterpassRest, [Component.MasterpassRest]],
|
package/data/client/account.ts
CHANGED
|
@@ -77,10 +77,6 @@ interface LoyaltyTransactions {
|
|
|
77
77
|
}[];
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
interface PasswordResetValidateResponse {
|
|
81
|
-
validlink: boolean;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
80
|
const accountApi = api.injectEndpoints({
|
|
85
81
|
endpoints: (builder) => ({
|
|
86
82
|
updatePassword: builder.mutation<void, AccountChangePasswordFormType>({
|
|
@@ -225,12 +221,6 @@ const accountApi = api.injectEndpoints({
|
|
|
225
221
|
}),
|
|
226
222
|
getLoyaltyTransactions: builder.query<LoyaltyTransactions, void>({
|
|
227
223
|
query: () => buildClientRequestUrl(account.loyaltyTransactions)
|
|
228
|
-
}),
|
|
229
|
-
getValidatePasswordResetToken: builder.query<
|
|
230
|
-
PasswordResetValidateResponse,
|
|
231
|
-
string
|
|
232
|
-
>({
|
|
233
|
-
query: (slug) => buildClientRequestUrl(account.passwordReset(slug))
|
|
234
224
|
})
|
|
235
225
|
}),
|
|
236
226
|
overrideExisting: true
|
|
@@ -257,6 +247,5 @@ export const {
|
|
|
257
247
|
usePasswordResetMutation,
|
|
258
248
|
useAnonymizeMutation,
|
|
259
249
|
useGetLoyaltyBalanceQuery,
|
|
260
|
-
useGetLoyaltyTransactionsQuery
|
|
261
|
-
useGetValidatePasswordResetTokenQuery
|
|
250
|
+
useGetLoyaltyTransactionsQuery
|
|
262
251
|
} = accountApi;
|
package/data/urls.ts
CHANGED
|
@@ -183,11 +183,7 @@ export const product = {
|
|
|
183
183
|
breadcrumbUrl: (menuitemmodel: string) =>
|
|
184
184
|
`/menus/generate_breadcrumb/?item=${menuitemmodel}&generator_name=menu_item`,
|
|
185
185
|
bundleProduct: (productPk: string, queryString: string) =>
|
|
186
|
-
`/bundle-product/${productPk}/?${queryString}
|
|
187
|
-
similarProducts: (params?: string) =>
|
|
188
|
-
`/similar-products${params ? `?${params}` : ''}`,
|
|
189
|
-
similarProductsList: (params?: string) =>
|
|
190
|
-
`/similar-product-list${params ? `?${params}` : ''}`
|
|
186
|
+
`/bundle-product/${productPk}/?${queryString}`
|
|
191
187
|
};
|
|
192
188
|
|
|
193
189
|
export const wishlist = {
|
package/lib/cache-handler.mjs
CHANGED
|
@@ -302,9 +302,6 @@ async function getRedisClient() {
|
|
|
302
302
|
|
|
303
303
|
const redisClient = createClient({
|
|
304
304
|
url: redisUrl,
|
|
305
|
-
...(process.env.CACHE_PASSWORD && {
|
|
306
|
-
password: process.env.CACHE_PASSWORD
|
|
307
|
-
}),
|
|
308
305
|
socket: {
|
|
309
306
|
reconnectStrategy: (retries) => {
|
|
310
307
|
if (retries > CACHE_CONFIG.redis.reconnectStrategy.maxRetries) {
|
package/middlewares/default.ts
CHANGED
|
@@ -14,8 +14,7 @@ import {
|
|
|
14
14
|
withUrlRedirection,
|
|
15
15
|
withCompleteWallet,
|
|
16
16
|
withWalletCompleteRedirection,
|
|
17
|
-
withMasterpassRestCallback
|
|
18
|
-
withBfcacheHeaders
|
|
17
|
+
withMasterpassRestCallback
|
|
19
18
|
} from '.';
|
|
20
19
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
21
20
|
import withCurrency from './currency';
|
|
@@ -132,13 +131,8 @@ const withPzDefault =
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
|
|
135
|
-
const queryString = searchParams.toString();
|
|
136
134
|
return NextResponse.rewrite(
|
|
137
|
-
new URL(
|
|
138
|
-
`${encodeURI(Settings.commerceUrl)}/orders/redirection/${
|
|
139
|
-
queryString ? `?${queryString}` : ''
|
|
140
|
-
}`
|
|
141
|
-
)
|
|
135
|
+
new URL(`${encodeURI(Settings.commerceUrl)}/orders/redirection/`)
|
|
142
136
|
);
|
|
143
137
|
}
|
|
144
138
|
|
|
@@ -256,11 +250,10 @@ const withPzDefault =
|
|
|
256
250
|
withCompleteWallet(
|
|
257
251
|
withWalletCompleteRedirection(
|
|
258
252
|
withMasterpassRestCallback(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
) => {
|
|
253
|
+
async (
|
|
254
|
+
req: PzNextRequest,
|
|
255
|
+
event: NextFetchEvent
|
|
256
|
+
) => {
|
|
264
257
|
let middlewareResult: NextResponse | void =
|
|
265
258
|
NextResponse.next();
|
|
266
259
|
|
|
@@ -500,7 +493,7 @@ const withPzDefault =
|
|
|
500
493
|
}
|
|
501
494
|
|
|
502
495
|
return middlewareResult;
|
|
503
|
-
}
|
|
496
|
+
}
|
|
504
497
|
)
|
|
505
498
|
)
|
|
506
499
|
)
|
package/middlewares/index.ts
CHANGED
|
@@ -12,7 +12,6 @@ import withSavedCardRedirection from './saved-card-redirection';
|
|
|
12
12
|
import withCompleteWallet from './complete-wallet';
|
|
13
13
|
import withWalletCompleteRedirection from './wallet-complete-redirection';
|
|
14
14
|
import withMasterpassRestCallback from './masterpass-rest-callback';
|
|
15
|
-
import withBfcacheHeaders from './bfcache-headers';
|
|
16
15
|
import { NextRequest } from 'next/server';
|
|
17
16
|
|
|
18
17
|
export {
|
|
@@ -29,8 +28,7 @@ export {
|
|
|
29
28
|
withSavedCardRedirection,
|
|
30
29
|
withCompleteWallet,
|
|
31
30
|
withWalletCompleteRedirection,
|
|
32
|
-
withMasterpassRestCallback
|
|
33
|
-
withBfcacheHeaders
|
|
31
|
+
withMasterpassRestCallback
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
export interface PzNextRequest extends NextRequest {
|
|
@@ -10,23 +10,49 @@ const withMasterpassRestCallback =
|
|
|
10
10
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
11
11
|
const url = req.nextUrl.clone();
|
|
12
12
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
13
|
+
const sessionId = req.cookies.get('osessionid');
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
url.pathname.includes('/orders/checkout') &&
|
|
16
|
-
url.searchParams.get('page') === 'MasterpassRestCompletePage';
|
|
17
|
-
|
|
18
|
-
if (!isMasterpassCompletePage) {
|
|
15
|
+
if (!url.pathname.includes('/orders/masterpass-rest-callback')) {
|
|
19
16
|
return middleware(req, event);
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (req.method !== 'POST') {
|
|
20
|
+
logger.warn('Invalid request method for masterpass REST callback', {
|
|
21
|
+
middleware: 'masterpass-rest-callback',
|
|
22
|
+
method: req.method,
|
|
23
|
+
ip
|
|
24
|
+
});
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
return NextResponse.redirect(
|
|
27
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
28
|
+
'/orders/checkout/',
|
|
29
|
+
req.cookies.get('pz-locale')?.value
|
|
30
|
+
)}`,
|
|
31
|
+
303
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const responseCode = url.searchParams.get('responseCode');
|
|
36
|
+
const token = url.searchParams.get('token');
|
|
37
|
+
|
|
38
|
+
if (!responseCode || !token) {
|
|
39
|
+
logger.warn('Missing required parameters for masterpass REST callback', {
|
|
40
|
+
middleware: 'masterpass-rest-callback',
|
|
41
|
+
responseCode,
|
|
42
|
+
token,
|
|
43
|
+
ip
|
|
28
44
|
});
|
|
29
45
|
|
|
46
|
+
return NextResponse.redirect(
|
|
47
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
48
|
+
'/orders/checkout/',
|
|
49
|
+
req.cookies.get('pz-locale')?.value
|
|
50
|
+
)}`,
|
|
51
|
+
303
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
30
56
|
const formData = await req.formData();
|
|
31
57
|
const body: Record<string, string> = {};
|
|
32
58
|
|
|
@@ -34,6 +60,38 @@ const withMasterpassRestCallback =
|
|
|
34
60
|
body[key] = value.toString();
|
|
35
61
|
});
|
|
36
62
|
|
|
63
|
+
if (!sessionId) {
|
|
64
|
+
logger.warn(
|
|
65
|
+
'Make sure that the SESSION_COOKIE_SAMESITE environment variable is set to None in Commerce.',
|
|
66
|
+
{
|
|
67
|
+
middleware: 'masterpass-rest-callback',
|
|
68
|
+
ip
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return NextResponse.redirect(
|
|
73
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
74
|
+
'/orders/checkout/',
|
|
75
|
+
req.cookies.get('pz-locale')?.value
|
|
76
|
+
)}`,
|
|
77
|
+
303
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const isPostCheckout = req.cookies.get('pz-post-checkout-flow')?.value === 'true';
|
|
82
|
+
const requestUrl = new URL(getCheckoutPath(isPostCheckout), Settings.commerceUrl);
|
|
83
|
+
requestUrl.searchParams.set('page', 'MasterpassRestCompletePage');
|
|
84
|
+
requestUrl.searchParams.set('responseCode', responseCode);
|
|
85
|
+
requestUrl.searchParams.set('token', token);
|
|
86
|
+
requestUrl.searchParams.set(
|
|
87
|
+
'three_d_secure',
|
|
88
|
+
body.transactionType?.includes('3D') ? 'true' : 'false'
|
|
89
|
+
);
|
|
90
|
+
requestUrl.searchParams.set(
|
|
91
|
+
'transactionType',
|
|
92
|
+
body.transactionType || ''
|
|
93
|
+
);
|
|
94
|
+
|
|
37
95
|
const requestHeaders = {
|
|
38
96
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
39
97
|
'X-Requested-With': 'XMLHttpRequest',
|
|
@@ -49,13 +107,33 @@ const withMasterpassRestCallback =
|
|
|
49
107
|
body: new URLSearchParams(body)
|
|
50
108
|
});
|
|
51
109
|
|
|
110
|
+
logger.info('Masterpass REST callback request', {
|
|
111
|
+
requestUrl: requestUrl.toString(),
|
|
112
|
+
status: request.status,
|
|
113
|
+
requestHeaders,
|
|
114
|
+
ip
|
|
115
|
+
});
|
|
116
|
+
|
|
52
117
|
const response = await request.json();
|
|
53
|
-
|
|
118
|
+
|
|
119
|
+
const { context_list: contextList, errors } = response;
|
|
120
|
+
|
|
121
|
+
let redirectUrl = response.redirect_url;
|
|
122
|
+
|
|
123
|
+
if (!redirectUrl && contextList && contextList.length > 0) {
|
|
124
|
+
for (const context of contextList) {
|
|
125
|
+
if (context.page_context && context.page_context.redirect_url) {
|
|
126
|
+
redirectUrl = context.page_context.redirect_url;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
54
131
|
|
|
55
132
|
if (errors && Object.keys(errors).length) {
|
|
56
|
-
logger.error('Error while processing
|
|
57
|
-
middleware: 'masterpass-rest-
|
|
133
|
+
logger.error('Error while processing masterpass REST callback', {
|
|
134
|
+
middleware: 'masterpass-rest-callback',
|
|
58
135
|
errors,
|
|
136
|
+
requestHeaders,
|
|
59
137
|
ip
|
|
60
138
|
});
|
|
61
139
|
|
|
@@ -64,7 +142,12 @@ const withMasterpassRestCallback =
|
|
|
64
142
|
'/orders/checkout/',
|
|
65
143
|
req.cookies.get('pz-locale')?.value
|
|
66
144
|
)}`,
|
|
67
|
-
|
|
145
|
+
{
|
|
146
|
+
status: 303,
|
|
147
|
+
headers: {
|
|
148
|
+
'Set-Cookie': `pz-pos-error=${encodeURIComponent(JSON.stringify(errors))}; path=/;`
|
|
149
|
+
}
|
|
150
|
+
}
|
|
68
151
|
);
|
|
69
152
|
|
|
70
153
|
// Add error cookie
|
|
@@ -75,30 +158,70 @@ const withMasterpassRestCallback =
|
|
|
75
158
|
return errorResponse;
|
|
76
159
|
}
|
|
77
160
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
161
|
+
logger.info('Masterpass REST callback response', {
|
|
162
|
+
middleware: 'masterpass-rest-callback',
|
|
163
|
+
contextList,
|
|
164
|
+
redirectUrl,
|
|
165
|
+
ip
|
|
166
|
+
});
|
|
81
167
|
|
|
82
|
-
if (redirectUrl) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
168
|
+
if (!redirectUrl) {
|
|
169
|
+
logger.warn(
|
|
170
|
+
'No redirection url found in response. Redirecting to checkout page.',
|
|
171
|
+
{
|
|
172
|
+
middleware: 'masterpass-rest-callback',
|
|
173
|
+
requestHeaders,
|
|
174
|
+
response: JSON.stringify(response),
|
|
175
|
+
ip
|
|
176
|
+
}
|
|
86
177
|
);
|
|
178
|
+
|
|
179
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
180
|
+
'/orders/checkout/',
|
|
181
|
+
req.cookies.get('pz-locale')?.value
|
|
182
|
+
)}`;
|
|
183
|
+
|
|
184
|
+
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
87
185
|
}
|
|
88
186
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
)
|
|
187
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
188
|
+
redirectUrl,
|
|
189
|
+
req.cookies.get('pz-locale')?.value
|
|
190
|
+
)}`;
|
|
191
|
+
|
|
192
|
+
logger.info('Redirecting after masterpass REST callback', {
|
|
193
|
+
middleware: 'masterpass-rest-callback',
|
|
194
|
+
redirectUrl: redirectUrlWithLocale,
|
|
195
|
+
ip
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
199
|
+
|
|
200
|
+
// Forward set-cookie headers from the upstream response
|
|
201
|
+
const setCookieHeader = request.headers.get('set-cookie');
|
|
202
|
+
if (setCookieHeader) {
|
|
203
|
+
setCookieHeader.split(',').forEach((cookie) => {
|
|
204
|
+
nextResponse.headers.append('Set-Cookie', cookie.trim());
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return nextResponse;
|
|
93
209
|
} catch (error) {
|
|
94
|
-
logger.error('Error while processing
|
|
95
|
-
middleware: 'masterpass-rest-
|
|
210
|
+
logger.error('Error while processing masterpass REST callback', {
|
|
211
|
+
middleware: 'masterpass-rest-callback',
|
|
96
212
|
error,
|
|
213
|
+
requestHeaders: {
|
|
214
|
+
Cookie: req.headers.get('cookie') ?? '',
|
|
215
|
+
'x-currency': req.cookies.get('pz-currency')?.value ?? ''
|
|
216
|
+
},
|
|
97
217
|
ip
|
|
98
218
|
});
|
|
99
219
|
|
|
100
220
|
return NextResponse.redirect(
|
|
101
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
221
|
+
`${url.origin}${getUrlPathWithLocale(
|
|
222
|
+
'/orders/checkout/',
|
|
223
|
+
req.cookies.get('pz-locale')?.value
|
|
224
|
+
)}`,
|
|
102
225
|
303
|
|
103
226
|
);
|
|
104
227
|
}
|
|
@@ -6,114 +6,55 @@ import {
|
|
|
6
6
|
} from 'next/server';
|
|
7
7
|
import Settings from 'settings';
|
|
8
8
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
9
|
-
import logger from '../utils/log';
|
|
10
|
-
|
|
11
|
-
const LOGIN_URL_REGEX = /^\/(\w+)\/login\/?$/;
|
|
12
|
-
const CALLBACK_URL_REGEX = /^\/(\w+)\/login\/callback\/?$/;
|
|
13
|
-
|
|
14
|
-
function fetchCommerce(url: string, req: NextRequest): Promise<Response> {
|
|
15
|
-
return fetch(url, {
|
|
16
|
-
headers: {
|
|
17
|
-
'x-forwarded-host':
|
|
18
|
-
req.headers.get('x-forwarded-host') || req.headers.get('host') || '',
|
|
19
|
-
'x-forwarded-for': req.headers.get('x-forwarded-for') ?? '',
|
|
20
|
-
'x-forwarded-proto': req.headers.get('x-forwarded-proto') || 'https',
|
|
21
|
-
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
22
|
-
cookie: req.headers.get('cookie') ?? ''
|
|
23
|
-
},
|
|
24
|
-
redirect: 'manual'
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function forwardCookies(from: Response, to: NextResponse): void {
|
|
29
|
-
from.headers.getSetCookie().forEach((cookie) => {
|
|
30
|
-
to.headers.append('set-cookie', cookie);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function commerceRedirect(
|
|
35
|
-
commerceResponse: Response,
|
|
36
|
-
location: string,
|
|
37
|
-
origin: string
|
|
38
|
-
): NextResponse {
|
|
39
|
-
const redirectUrl = new URL(location, origin);
|
|
40
|
-
const response = NextResponse.redirect(redirectUrl);
|
|
41
|
-
forwardCookies(commerceResponse, response);
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function commercePassthrough(commerceResponse: Response): NextResponse {
|
|
46
|
-
return new NextResponse(commerceResponse.body, {
|
|
47
|
-
status: commerceResponse.status,
|
|
48
|
-
headers: commerceResponse.headers
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
9
|
|
|
52
10
|
const withOauthLogin =
|
|
53
11
|
(middleware: NextMiddleware) =>
|
|
54
12
|
async (req: NextRequest, event: NextFetchEvent) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
'set-cookie',
|
|
83
|
-
`pz-oauth-callback-url=${encodeURIComponent(req.headers.get('referer') || '')}; Path=/`
|
|
13
|
+
const url = req.nextUrl.clone();
|
|
14
|
+
const loginUrlMatcherRegex = new RegExp(/^\/(\w+)\/login\/?$/);
|
|
15
|
+
const loginCallbackUrlMatcherRegex = new RegExp(
|
|
16
|
+
/^\/(\w+)\/login\/callback\/?$/
|
|
17
|
+
);
|
|
18
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
19
|
+
|
|
20
|
+
const headers = {
|
|
21
|
+
'x-forwarded-host':
|
|
22
|
+
req.headers.get('x-forwarded-host') || req.headers.get('host') || '',
|
|
23
|
+
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
24
|
+
'x-forwarded-for': ip
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (loginUrlMatcherRegex.test(url.pathname)) {
|
|
28
|
+
const provider = url.pathname.match(loginUrlMatcherRegex)[1];
|
|
29
|
+
const response = NextResponse.rewrite(
|
|
30
|
+
`${Settings.commerceUrl}/${provider}/login/`,
|
|
31
|
+
{
|
|
32
|
+
headers
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (req.headers.get('referer')) {
|
|
37
|
+
response.cookies.set(
|
|
38
|
+
'pz-oauth-callback-url',
|
|
39
|
+
req.headers.get('referer')
|
|
84
40
|
);
|
|
85
|
-
|
|
86
|
-
return response;
|
|
87
|
-
} catch (error) {
|
|
88
|
-
console.error('OAuth login fetch failed:', error);
|
|
89
|
-
return middleware(req, event);
|
|
90
41
|
}
|
|
91
|
-
}
|
|
92
42
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const provider = callbackMatch[1];
|
|
97
|
-
const commerceResponse = await fetchCommerce(
|
|
98
|
-
`${Settings.commerceUrl}/${provider}/login/callback/${search}`,
|
|
99
|
-
req
|
|
100
|
-
);
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
101
45
|
|
|
102
|
-
|
|
103
|
-
|
|
46
|
+
if (loginCallbackUrlMatcherRegex.test(url.pathname)) {
|
|
47
|
+
const provider = url.pathname.match(loginCallbackUrlMatcherRegex)[1];
|
|
104
48
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
console.error('OAuth callback fetch failed:', error);
|
|
112
|
-
return middleware(req, event);
|
|
113
|
-
}
|
|
49
|
+
return NextResponse.rewrite(
|
|
50
|
+
`${Settings.commerceUrl}/${provider}/login/callback/${url.search}`,
|
|
51
|
+
{
|
|
52
|
+
headers
|
|
53
|
+
}
|
|
54
|
+
);
|
|
114
55
|
}
|
|
115
56
|
|
|
116
|
-
if (!pathname.startsWith('/baskets/basket')) {
|
|
57
|
+
if (!url.pathname.startsWith('/baskets/basket')) {
|
|
117
58
|
return middleware(req, event);
|
|
118
59
|
}
|
|
119
60
|
|
|
@@ -123,12 +64,11 @@ const withOauthLogin =
|
|
|
123
64
|
req.cookies.get('messages')?.value.includes('Successfully signed in') ||
|
|
124
65
|
(currentSessionId && req.cookies.get('messages'))
|
|
125
66
|
) {
|
|
126
|
-
let redirectUrlWithLocale = `${
|
|
67
|
+
let redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
127
68
|
'/auth/oauth-login',
|
|
128
69
|
req.cookies.get('pz-locale')?.value
|
|
129
70
|
)}`;
|
|
130
|
-
|
|
131
|
-
req.cookies.get('pz-oauth-callback-url')?.value ?? '';
|
|
71
|
+
let callbackUrl = req.cookies.get('pz-oauth-callback-url')?.value ?? '';
|
|
132
72
|
|
|
133
73
|
if (callbackUrl.length) {
|
|
134
74
|
redirectUrlWithLocale += `?next=${encodeURIComponent(callbackUrl)}`;
|
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.120.0
|
|
4
|
+
"version": "1.120.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"set-cookie-parser": "2.6.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@akinon/eslint-plugin-projectzero": "1.120.0
|
|
38
|
+
"@akinon/eslint-plugin-projectzero": "1.120.0",
|
|
39
39
|
"@babel/core": "7.26.10",
|
|
40
40
|
"@babel/preset-env": "7.26.9",
|
|
41
41
|
"@babel/preset-typescript": "7.27.0",
|
package/plugins.d.ts
CHANGED
|
@@ -37,16 +37,6 @@ declare module '@akinon/pz-cybersource-uc/src/redux/middleware' {
|
|
|
37
37
|
export default middleware as any;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
declare module '@akinon/pz-apple-pay' {}
|
|
41
|
-
|
|
42
|
-
declare module '@akinon/pz-similar-products' {
|
|
43
|
-
export const SimilarProductsModal: any;
|
|
44
|
-
export const SimilarProductsFilterSidebar: any;
|
|
45
|
-
export const SimilarProductsResultsGrid: any;
|
|
46
|
-
export const SimilarProductsPlugin: any;
|
|
47
|
-
export const SimilarProductsButtonPlugin: any;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
40
|
declare module '@akinon/pz-cybersource-uc/src/redux/reducer' {
|
|
51
41
|
export default reducer as any;
|
|
52
42
|
}
|
package/plugins.js
CHANGED
|
@@ -204,25 +204,15 @@ export const contextListMiddleware: Middleware = ({
|
|
|
204
204
|
(ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
|
|
205
205
|
)
|
|
206
206
|
) {
|
|
207
|
-
const isCreditCardPayment =
|
|
208
|
-
preOrder?.payment_option?.payment_type === 'credit_card' ||
|
|
209
|
-
preOrder?.payment_option?.payment_type === 'masterpass';
|
|
210
|
-
|
|
211
207
|
if (context.page_context.card_type) {
|
|
212
208
|
dispatch(setCardType(context.page_context.card_type));
|
|
213
|
-
} else if (isCreditCardPayment) {
|
|
214
|
-
dispatch(setCardType(null));
|
|
215
209
|
}
|
|
216
210
|
|
|
217
211
|
if (
|
|
218
212
|
context.page_context.installments &&
|
|
219
213
|
preOrder?.payment_option?.payment_type !== 'masterpass_rest'
|
|
220
214
|
) {
|
|
221
|
-
|
|
222
|
-
dispatch(
|
|
223
|
-
setInstallmentOptions(context.page_context.installments)
|
|
224
|
-
);
|
|
225
|
-
}
|
|
215
|
+
dispatch(setInstallmentOptions(context.page_context.installments));
|
|
226
216
|
}
|
|
227
217
|
}
|
|
228
218
|
|
|
@@ -14,17 +14,9 @@ export const installmentOptionMiddleware: Middleware = ({
|
|
|
14
14
|
return result;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const { installmentOptions
|
|
17
|
+
const { installmentOptions } = getState().checkout;
|
|
18
18
|
const { endpoints: apiEndpoints } = checkoutApi;
|
|
19
19
|
|
|
20
|
-
const isCreditCardPayment =
|
|
21
|
-
preOrder?.payment_option?.payment_type === 'credit_card' ||
|
|
22
|
-
preOrder?.payment_option?.payment_type === 'masterpass';
|
|
23
|
-
|
|
24
|
-
if (isCreditCardPayment && !cardType) {
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
20
|
if (
|
|
29
21
|
!preOrder?.installment &&
|
|
30
22
|
preOrder?.payment_option?.payment_type !== 'saved_card' &&
|
package/types/index.ts
CHANGED
|
@@ -83,12 +83,6 @@ export interface Settings {
|
|
|
83
83
|
};
|
|
84
84
|
usePrettyUrlRoute?: boolean;
|
|
85
85
|
commerceUrl: string;
|
|
86
|
-
/**
|
|
87
|
-
* This option allows you to track Sentry events on the client side, in addition to server and edge environments.
|
|
88
|
-
*
|
|
89
|
-
* It overrides process.env.NEXT_PUBLIC_SENTRY_DSN and process.env.SENTRY_DSN.
|
|
90
|
-
*/
|
|
91
|
-
sentryDsn?: string;
|
|
92
86
|
redis: {
|
|
93
87
|
defaultExpirationTime: number;
|
|
94
88
|
};
|
package/utils/app-fetch.ts
CHANGED
|
@@ -2,7 +2,6 @@ import Settings from 'settings';
|
|
|
2
2
|
import logger from '../utils/log';
|
|
3
3
|
import { headers, cookies } from 'next/headers';
|
|
4
4
|
import { ServerVariables } from './server-variables';
|
|
5
|
-
import { notFound } from 'next/navigation';
|
|
6
5
|
|
|
7
6
|
export enum FetchResponseType {
|
|
8
7
|
JSON = 'json',
|
|
@@ -61,15 +60,13 @@ const appFetch = async <T>({
|
|
|
61
60
|
status = req.status;
|
|
62
61
|
logger.debug(`FETCH END ${url}`, { status: req.status, ip });
|
|
63
62
|
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
response = (await req.text()) as unknown as T;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
logger.trace(`FETCH RESPONSE`, { url, response, ip });
|
|
63
|
+
if (responseType === FetchResponseType.JSON) {
|
|
64
|
+
response = (await req.json()) as T;
|
|
65
|
+
} else {
|
|
66
|
+
response = (await req.text()) as unknown as T;
|
|
72
67
|
}
|
|
68
|
+
|
|
69
|
+
logger.trace(`FETCH RESPONSE`, { url, response, ip });
|
|
73
70
|
} catch (error) {
|
|
74
71
|
const logType = status === 500 ? 'fatal' : 'error';
|
|
75
72
|
|
|
@@ -78,10 +75,6 @@ const appFetch = async <T>({
|
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
77
|
|
|
81
|
-
if (status === 422) {
|
|
82
|
-
notFound();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
78
|
return response;
|
|
86
79
|
};
|
|
87
80
|
|
package/utils/index.ts
CHANGED
|
@@ -195,9 +195,13 @@ export const urlLocaleMatcherRegex = new RegExp(
|
|
|
195
195
|
|
|
196
196
|
export const getPosError = () => {
|
|
197
197
|
const cookieValue = getCookie('pz-pos-error');
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
let decoded: string;
|
|
199
|
+
try {
|
|
200
|
+
decoded = cookieValue ? decodeURIComponent(cookieValue) : '{}';
|
|
201
|
+
} catch {
|
|
202
|
+
decoded = cookieValue ?? '{}';
|
|
203
|
+
}
|
|
204
|
+
const error = JSON.parse(decoded);
|
|
201
205
|
|
|
202
206
|
// delete 'pz-pos-error' cookie when refreshing or closing page
|
|
203
207
|
window.addEventListener('beforeunload', () => {
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
const iframeURLChange = (iframe, callback) => {
|
|
2
2
|
iframe.addEventListener('load', () => {
|
|
3
3
|
setTimeout(() => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const iframeLocation = iframe.contentWindow.location;
|
|
7
|
-
|
|
8
|
-
callback(iframeLocation);
|
|
9
|
-
}
|
|
10
|
-
} catch (error) {
|
|
11
|
-
// Expected: browser blocks cross-origin iframe access for security
|
|
4
|
+
if (iframe?.contentWindow?.location) {
|
|
5
|
+
callback(iframe.contentWindow.location);
|
|
12
6
|
}
|
|
13
7
|
}, 0);
|
|
14
8
|
});
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
const iframeURLChange = (iframe, callback) => {
|
|
2
2
|
iframe.addEventListener('load', () => {
|
|
3
3
|
setTimeout(() => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const iframeLocation = iframe.contentWindow.location;
|
|
7
|
-
|
|
8
|
-
callback(iframeLocation);
|
|
9
|
-
}
|
|
10
|
-
} catch (error) {
|
|
11
|
-
// Expected: browser blocks cross-origin iframe access for security
|
|
4
|
+
if (iframe?.contentWindow?.location) {
|
|
5
|
+
callback(iframe.contentWindow.location);
|
|
12
6
|
}
|
|
13
7
|
}, 0);
|
|
14
8
|
});
|
package/with-pz-config.js
CHANGED
package/api/barcode-search.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import Settings from 'settings';
|
|
3
|
-
|
|
4
|
-
export async function GET(request: NextRequest) {
|
|
5
|
-
try {
|
|
6
|
-
const { searchParams } = new URL(request.url);
|
|
7
|
-
const barcode = searchParams.get('search_text');
|
|
8
|
-
|
|
9
|
-
if (!barcode) {
|
|
10
|
-
return NextResponse.json(
|
|
11
|
-
{ error: 'Missing search_text parameter (barcode)' },
|
|
12
|
-
{ status: 400 }
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (Settings.commerceUrl === 'default') {
|
|
17
|
-
return NextResponse.json(
|
|
18
|
-
{ error: 'Commerce URL is not configured' },
|
|
19
|
-
{ status: 500 }
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const queryParams = new URLSearchParams();
|
|
24
|
-
queryParams.append('search_text', barcode);
|
|
25
|
-
|
|
26
|
-
searchParams.forEach((value, key) => {
|
|
27
|
-
if (key !== 'search_text') {
|
|
28
|
-
queryParams.append(key, value);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const apiUrl = `${Settings.commerceUrl}/list/?${queryParams.toString()}`;
|
|
33
|
-
|
|
34
|
-
const headers: Record<string, string> = {
|
|
35
|
-
Accept: 'application/json',
|
|
36
|
-
'Content-Type': 'application/json'
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const response = await fetch(apiUrl, {
|
|
40
|
-
method: 'GET',
|
|
41
|
-
headers
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
return NextResponse.json(
|
|
46
|
-
{ error: `API request failed with status: ${response.status}` },
|
|
47
|
-
{ status: response.status }
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const data = await response.json();
|
|
52
|
-
return NextResponse.json(data);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
return NextResponse.json(
|
|
55
|
-
{ error: (error as Error).message },
|
|
56
|
-
{ status: 500 }
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { NextMiddleware } from 'next/server';
|
|
2
|
-
|
|
3
|
-
const withBfcacheHeaders = (middleware: NextMiddleware): NextMiddleware => {
|
|
4
|
-
return async (req, event) => {
|
|
5
|
-
const response = await middleware(req, event);
|
|
6
|
-
|
|
7
|
-
if (process.env.BF_CACHE === 'true' && response) {
|
|
8
|
-
response.headers.set(
|
|
9
|
-
'Cache-Control',
|
|
10
|
-
'private, no-cache, max-age=0, must-revalidate'
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return response;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default withBfcacheHeaders;
|