@akinon/next 1.120.0 → 1.121.0-rc.1
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 +33 -0
- package/api/barcode-search.ts +59 -0
- package/bin/pz-generate-routes.js +10 -1
- package/components/plugin-module.tsx +2 -2
- package/data/client/account.ts +12 -1
- package/data/urls.ts +5 -1
- package/middlewares/bfcache-headers.ts +18 -0
- package/middlewares/default.ts +14 -7
- package/middlewares/index.ts +3 -1
- package/middlewares/oauth-login.ts +200 -57
- package/package.json +2 -2
- package/plugins.d.ts +10 -0
- package/plugins.js +1 -0
- package/redux/middlewares/checkout.ts +11 -1
- package/redux/middlewares/pre-order/installment-option.ts +9 -1
- package/types/index.ts +6 -0
- package/utils/app-fetch.ts +13 -6
- package/utils/mobile-3d-iframe.ts +8 -2
- package/utils/redirection-iframe.ts +8 -2
- package/with-pz-config.js +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
+
## 1.121.0-rc.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ZERO-4160: Enhance oauth-login middleware with improved request handling and logging
|
|
8
|
+
|
|
9
|
+
## 1.121.0-rc.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 8218dafa: ZERO-4160: Refactor oauth-login middleware to use fetch for login and callback responses
|
|
14
|
+
- d2c0e759: ZERO-3684: Handle cross-origin iframe access in iframeURLChange function
|
|
15
|
+
- b55acb76: ZERO-2577: Fix pagination bug and update usePagination hook and ensure pagination controls rendering correctly
|
|
16
|
+
- 8a7fd0f4: ZERO-4065: Add '[segment]' to skipSegments in route generation
|
|
17
|
+
- 760258c1: ZERO-4160: Enhance oauth-login middleware to handle fetch errors and improve response handling
|
|
18
|
+
- 36143125: ZERO-3987: Add barcode scanner functionality with modal and button
|
|
19
|
+
- f7e0f646: ZERO-4032: Add bfcache-headers middleware, integrate it into the default chain, and introduce a new environment variable for control.
|
|
20
|
+
- 94a86fcc: ZERO-4065: Expand skipSegments array to include additional segments for route generation
|
|
21
|
+
- 143be2b9: ZERO-3457: Crop styles are customizable and logic improved for rendering similar products modal
|
|
22
|
+
- bcaad120: ZERO-4158: Add logging for OAuth login and callback redirects
|
|
23
|
+
- cd68a97a: ZERO-4126: Enhance error handling in appFetch and related data handlers to throw notFound on 404 and 422 errors
|
|
24
|
+
- 9f8cd3bc: ZERO-3449: AI Search Active Filters & Crop Style changes have been implemented
|
|
25
|
+
- bfafa3f4: ZERO-4160: Refactor oauth-login middleware to use fetchCommerce for API calls and improve cookie handling
|
|
26
|
+
- 49c82e1a: ZERO-4047: Remove Sentry configuration from default Next.js config
|
|
27
|
+
- d99a6a7d: ZERO-3457_1: Fixed the settings prop and made sure everything is customizable.
|
|
28
|
+
- d7e5178b: ZERO-3985: Add query string handling for orders redirection in middleware
|
|
29
|
+
- 591e345e: ZERO-3855: Enhance credit card payment handling in checkout middlewares
|
|
30
|
+
- 4de5303c: ZERO-2504: add cookie filter to api client request
|
|
31
|
+
- b59fdd1c: ZERO-4009: Add password reset token validation
|
|
32
|
+
- 95b139dc: ZERO-3795: Remove duplicate entry for SavedCard in PluginComponents map
|
|
33
|
+
- 3909d322: Edit the duplicate Plugin.SimilarProducts in the plugin-module.
|
|
34
|
+
- e18836b2: ZERO-4160: Restore scope in Sentry addon configuration in akinon.json
|
|
35
|
+
|
|
3
36
|
## 1.120.0
|
|
4
37
|
|
|
5
38
|
### Minor Changes
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
|
@@ -25,7 +25,16 @@ const generateRoutes = () => {
|
|
|
25
25
|
const routes = [];
|
|
26
26
|
const excludedDirs = ['api', 'pz-not-found'];
|
|
27
27
|
|
|
28
|
-
const skipSegments = [
|
|
28
|
+
const skipSegments = [
|
|
29
|
+
'[commerce]',
|
|
30
|
+
'[locale]',
|
|
31
|
+
'[currency]',
|
|
32
|
+
'[session]',
|
|
33
|
+
'[segment]',
|
|
34
|
+
'[url]',
|
|
35
|
+
'[theme]',
|
|
36
|
+
'[member_type]'
|
|
37
|
+
];
|
|
29
38
|
const skipCatchAllRoutes = ['[...prettyurl]', '[...not_found]'];
|
|
30
39
|
|
|
31
40
|
const walkDirectory = (dir, basePath = '') => {
|
|
@@ -55,6 +55,7 @@ export enum Component {
|
|
|
55
55
|
SavedCard = 'SavedCardOption',
|
|
56
56
|
VirtualTryOnPlugin = 'VirtualTryOnPlugin',
|
|
57
57
|
BasketVirtualTryOn = 'BasketVirtualTryOn',
|
|
58
|
+
BarcodeScannerPlugin = 'BarcodeScannerPlugin',
|
|
58
59
|
IyzicoSavedCard = 'IyzicoSavedCardOption',
|
|
59
60
|
Hepsipay = 'Hepsipay',
|
|
60
61
|
FlowPayment = 'FlowPayment',
|
|
@@ -113,11 +114,10 @@ const PluginComponents = new Map([
|
|
|
113
114
|
]
|
|
114
115
|
],
|
|
115
116
|
[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, Component.BarcodeScannerPlugin]
|
|
121
121
|
],
|
|
122
122
|
[Plugin.Hepsipay, [Component.Hepsipay]],
|
|
123
123
|
[Plugin.MasterpassRest, [Component.MasterpassRest]],
|
package/data/client/account.ts
CHANGED
|
@@ -77,6 +77,10 @@ interface LoyaltyTransactions {
|
|
|
77
77
|
}[];
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
interface PasswordResetValidateResponse {
|
|
81
|
+
validlink: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
80
84
|
const accountApi = api.injectEndpoints({
|
|
81
85
|
endpoints: (builder) => ({
|
|
82
86
|
updatePassword: builder.mutation<void, AccountChangePasswordFormType>({
|
|
@@ -221,6 +225,12 @@ const accountApi = api.injectEndpoints({
|
|
|
221
225
|
}),
|
|
222
226
|
getLoyaltyTransactions: builder.query<LoyaltyTransactions, void>({
|
|
223
227
|
query: () => buildClientRequestUrl(account.loyaltyTransactions)
|
|
228
|
+
}),
|
|
229
|
+
getValidatePasswordResetToken: builder.query<
|
|
230
|
+
PasswordResetValidateResponse,
|
|
231
|
+
string
|
|
232
|
+
>({
|
|
233
|
+
query: (slug) => buildClientRequestUrl(account.passwordReset(slug))
|
|
224
234
|
})
|
|
225
235
|
}),
|
|
226
236
|
overrideExisting: true
|
|
@@ -247,5 +257,6 @@ export const {
|
|
|
247
257
|
usePasswordResetMutation,
|
|
248
258
|
useAnonymizeMutation,
|
|
249
259
|
useGetLoyaltyBalanceQuery,
|
|
250
|
-
useGetLoyaltyTransactionsQuery
|
|
260
|
+
useGetLoyaltyTransactionsQuery,
|
|
261
|
+
useGetValidatePasswordResetTokenQuery
|
|
251
262
|
} = accountApi;
|
package/data/urls.ts
CHANGED
|
@@ -183,7 +183,11 @@ 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}
|
|
186
|
+
`/bundle-product/${productPk}/?${queryString}`,
|
|
187
|
+
similarProducts: (params?: string) =>
|
|
188
|
+
`/similar-products${params ? `?${params}` : ''}`,
|
|
189
|
+
similarProductsList: (params?: string) =>
|
|
190
|
+
`/similar-product-list${params ? `?${params}` : ''}`
|
|
187
191
|
};
|
|
188
192
|
|
|
189
193
|
export const wishlist = {
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
package/middlewares/default.ts
CHANGED
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
withUrlRedirection,
|
|
15
15
|
withCompleteWallet,
|
|
16
16
|
withWalletCompleteRedirection,
|
|
17
|
-
withMasterpassRestCallback
|
|
17
|
+
withMasterpassRestCallback,
|
|
18
|
+
withBfcacheHeaders
|
|
18
19
|
} from '.';
|
|
19
20
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
20
21
|
import withCurrency from './currency';
|
|
@@ -131,8 +132,13 @@ const withPzDefault =
|
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
|
|
135
|
+
const queryString = searchParams.toString();
|
|
134
136
|
return NextResponse.rewrite(
|
|
135
|
-
new URL(
|
|
137
|
+
new URL(
|
|
138
|
+
`${encodeURI(Settings.commerceUrl)}/orders/redirection/${
|
|
139
|
+
queryString ? `?${queryString}` : ''
|
|
140
|
+
}`
|
|
141
|
+
)
|
|
136
142
|
);
|
|
137
143
|
}
|
|
138
144
|
|
|
@@ -250,10 +256,11 @@ const withPzDefault =
|
|
|
250
256
|
withCompleteWallet(
|
|
251
257
|
withWalletCompleteRedirection(
|
|
252
258
|
withMasterpassRestCallback(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
withBfcacheHeaders(
|
|
260
|
+
async (
|
|
261
|
+
req: PzNextRequest,
|
|
262
|
+
event: NextFetchEvent
|
|
263
|
+
) => {
|
|
257
264
|
let middlewareResult: NextResponse | void =
|
|
258
265
|
NextResponse.next();
|
|
259
266
|
|
|
@@ -493,7 +500,7 @@ const withPzDefault =
|
|
|
493
500
|
}
|
|
494
501
|
|
|
495
502
|
return middlewareResult;
|
|
496
|
-
}
|
|
503
|
+
})
|
|
497
504
|
)
|
|
498
505
|
)
|
|
499
506
|
)
|
package/middlewares/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ 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';
|
|
15
16
|
import { NextRequest } from 'next/server';
|
|
16
17
|
|
|
17
18
|
export {
|
|
@@ -28,7 +29,8 @@ export {
|
|
|
28
29
|
withSavedCardRedirection,
|
|
29
30
|
withCompleteWallet,
|
|
30
31
|
withWalletCompleteRedirection,
|
|
31
|
-
withMasterpassRestCallback
|
|
32
|
+
withMasterpassRestCallback,
|
|
33
|
+
withBfcacheHeaders
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
export interface PzNextRequest extends NextRequest {
|
|
@@ -6,78 +6,221 @@ 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';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
const LOGIN_URL_REGEX = /^\/(\w+)\/login\/?$/;
|
|
12
|
+
const CALLBACK_URL_REGEX = /^\/(\w+)\/login\/callback\/?$/;
|
|
13
|
+
|
|
14
|
+
function buildCommerceHeaders(req: NextRequest): Record<string, string> {
|
|
15
|
+
return {
|
|
16
|
+
'x-forwarded-host':
|
|
17
|
+
req.headers.get('x-forwarded-host') || req.headers.get('host') || '',
|
|
18
|
+
'x-forwarded-for': req.headers.get('x-forwarded-for') ?? '',
|
|
19
|
+
'x-forwarded-proto': req.headers.get('x-forwarded-proto') || 'https',
|
|
20
|
+
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
21
|
+
cookie: req.headers.get('cookie') ?? ''
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function getRequestBody(
|
|
26
|
+
req: NextRequest
|
|
27
|
+
): Promise<{ content: string; contentType: string } | undefined> {
|
|
28
|
+
if (req.method !== 'POST') return undefined;
|
|
29
|
+
|
|
30
|
+
const content = await req.text();
|
|
31
|
+
if (!content.length) return undefined;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
content,
|
|
35
|
+
contentType:
|
|
36
|
+
req.headers.get('content-type') ?? 'application/x-www-form-urlencoded'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function fetchCommerce(
|
|
41
|
+
url: string,
|
|
42
|
+
req: NextRequest,
|
|
43
|
+
body?: { content: string; contentType: string }
|
|
44
|
+
): Promise<Response> {
|
|
45
|
+
const headers = buildCommerceHeaders(req);
|
|
46
|
+
|
|
47
|
+
if (body) {
|
|
48
|
+
headers['content-type'] = body.contentType;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return fetch(url, {
|
|
52
|
+
method: body ? 'POST' : 'GET',
|
|
53
|
+
headers,
|
|
54
|
+
body: body?.content,
|
|
55
|
+
redirect: 'manual'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function forwardCookies(from: Response, to: NextResponse): void {
|
|
60
|
+
from.headers.getSetCookie().forEach((cookie) => {
|
|
61
|
+
to.headers.append('set-cookie', cookie);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function buildRedirectResponse(
|
|
66
|
+
commerceResponse: Response,
|
|
67
|
+
location: string,
|
|
68
|
+
origin: string
|
|
69
|
+
): NextResponse {
|
|
70
|
+
const response = NextResponse.redirect(new URL(location, origin));
|
|
71
|
+
forwardCookies(commerceResponse, response);
|
|
72
|
+
return response;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function commercePassthrough(commerceResponse: Response): NextResponse {
|
|
76
|
+
return new NextResponse(commerceResponse.body, {
|
|
77
|
+
status: commerceResponse.status,
|
|
78
|
+
headers: commerceResponse.headers
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function buildOAuthCallbackCookie(referer: string): string {
|
|
83
|
+
return `pz-oauth-callback-url=${encodeURIComponent(referer)}; Path=/`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function handleLogin(
|
|
87
|
+
req: NextRequest,
|
|
88
|
+
provider: string
|
|
89
|
+
): Promise<{ response: NextResponse; redirected: boolean }> {
|
|
90
|
+
const commerceResponse = await fetchCommerce(
|
|
91
|
+
`${Settings.commerceUrl}/${provider}/login/`,
|
|
92
|
+
req
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const location = commerceResponse.headers.get('location');
|
|
96
|
+
if (!location) {
|
|
97
|
+
return {
|
|
98
|
+
response: commercePassthrough(commerceResponse),
|
|
99
|
+
redirected: false
|
|
25
100
|
};
|
|
101
|
+
}
|
|
26
102
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
headers
|
|
33
|
-
}
|
|
34
|
-
);
|
|
103
|
+
const response = buildRedirectResponse(
|
|
104
|
+
commerceResponse,
|
|
105
|
+
location,
|
|
106
|
+
req.nextUrl.origin
|
|
107
|
+
);
|
|
35
108
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
}
|
|
109
|
+
response.headers.append(
|
|
110
|
+
'set-cookie',
|
|
111
|
+
buildOAuthCallbackCookie(req.headers.get('referer') || '')
|
|
112
|
+
);
|
|
42
113
|
|
|
43
|
-
|
|
44
|
-
|
|
114
|
+
return { response, redirected: true };
|
|
115
|
+
}
|
|
45
116
|
|
|
46
|
-
|
|
47
|
-
|
|
117
|
+
async function handleCallback(
|
|
118
|
+
req: NextRequest,
|
|
119
|
+
provider: string,
|
|
120
|
+
search: string
|
|
121
|
+
): Promise<{ response: NextResponse; redirected: boolean }> {
|
|
122
|
+
const body = await getRequestBody(req);
|
|
123
|
+
const commerceResponse = await fetchCommerce(
|
|
124
|
+
`${Settings.commerceUrl}/${provider}/login/callback/${search}`,
|
|
125
|
+
req,
|
|
126
|
+
body
|
|
127
|
+
);
|
|
48
128
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
129
|
+
const location = commerceResponse.headers.get('location');
|
|
130
|
+
if (!location) {
|
|
131
|
+
return {
|
|
132
|
+
response: commercePassthrough(commerceResponse),
|
|
133
|
+
redirected: false
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
response: buildRedirectResponse(
|
|
139
|
+
commerceResponse,
|
|
140
|
+
location,
|
|
141
|
+
req.nextUrl.origin
|
|
142
|
+
),
|
|
143
|
+
redirected: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function handleBasketRedirect(req: NextRequest): NextResponse | null {
|
|
148
|
+
const hasSession = req.cookies.get('osessionid');
|
|
149
|
+
const messages = req.cookies.get('messages')?.value;
|
|
150
|
+
|
|
151
|
+
if (!messages) return null;
|
|
152
|
+
if (!messages.includes('Successfully signed in') && !hasSession) return null;
|
|
153
|
+
|
|
154
|
+
let redirectUrl = `${req.nextUrl.origin}${getUrlPathWithLocale(
|
|
155
|
+
'/auth/oauth-login',
|
|
156
|
+
req.cookies.get('pz-locale')?.value
|
|
157
|
+
)}`;
|
|
158
|
+
|
|
159
|
+
const callbackUrl = req.cookies.get('pz-oauth-callback-url')?.value ?? '';
|
|
160
|
+
if (callbackUrl.length) {
|
|
161
|
+
redirectUrl += `?next=${encodeURIComponent(callbackUrl)}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const response = NextResponse.redirect(redirectUrl);
|
|
165
|
+
response.cookies.delete('messages');
|
|
166
|
+
response.cookies.delete('pz-oauth-callback-url');
|
|
167
|
+
return response;
|
|
168
|
+
}
|
|
56
169
|
|
|
57
|
-
|
|
170
|
+
const withOauthLogin =
|
|
171
|
+
(middleware: NextMiddleware) =>
|
|
172
|
+
async (req: NextRequest, event: NextFetchEvent) => {
|
|
173
|
+
const { pathname, search } = req.nextUrl;
|
|
174
|
+
|
|
175
|
+
if (!pathname.includes('/login') && !pathname.startsWith('/baskets/basket')) {
|
|
58
176
|
return middleware(req, event);
|
|
59
177
|
}
|
|
60
178
|
|
|
61
|
-
|
|
179
|
+
logger.info('OAuth login redirect', {
|
|
180
|
+
host: req.headers.get('host'),
|
|
181
|
+
'x-forwarded-host': req.headers.get('x-forwarded-host'),
|
|
182
|
+
'x-forwarded-for': req.headers.get('x-forwarded-for')
|
|
183
|
+
});
|
|
62
184
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
185
|
+
const loginMatch = LOGIN_URL_REGEX.exec(pathname);
|
|
186
|
+
if (loginMatch) {
|
|
187
|
+
try {
|
|
188
|
+
const { response, redirected } = await handleLogin(req, loginMatch[1]);
|
|
189
|
+
if (!redirected) {
|
|
190
|
+
logger.warn('OAuth login: no redirect from commerce', {
|
|
191
|
+
provider: loginMatch[1]
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return response;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
logger.error('OAuth login fetch failed', { error });
|
|
197
|
+
return middleware(req, event);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
72
200
|
|
|
73
|
-
|
|
74
|
-
|
|
201
|
+
const callbackMatch = CALLBACK_URL_REGEX.exec(pathname);
|
|
202
|
+
if (callbackMatch) {
|
|
203
|
+
try {
|
|
204
|
+
const { response, redirected } = await handleCallback(
|
|
205
|
+
req,
|
|
206
|
+
callbackMatch[1],
|
|
207
|
+
search
|
|
208
|
+
);
|
|
209
|
+
if (!redirected) {
|
|
210
|
+
logger.warn('OAuth callback: no redirect from commerce', {
|
|
211
|
+
provider: callbackMatch[1]
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return response;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
logger.error('OAuth callback fetch failed', { error });
|
|
217
|
+
return middleware(req, event);
|
|
75
218
|
}
|
|
219
|
+
}
|
|
76
220
|
|
|
77
|
-
|
|
78
|
-
response
|
|
79
|
-
response
|
|
80
|
-
return response;
|
|
221
|
+
if (pathname.startsWith('/baskets/basket')) {
|
|
222
|
+
const response = handleBasketRedirect(req);
|
|
223
|
+
if (response) return response;
|
|
81
224
|
}
|
|
82
225
|
|
|
83
226
|
return middleware(req, event);
|
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.
|
|
4
|
+
"version": "1.121.0-rc.1",
|
|
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.
|
|
38
|
+
"@akinon/eslint-plugin-projectzero": "1.121.0-rc.1",
|
|
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,6 +37,16 @@ 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
|
+
|
|
40
50
|
declare module '@akinon/pz-cybersource-uc/src/redux/reducer' {
|
|
41
51
|
export default reducer as any;
|
|
42
52
|
}
|
package/plugins.js
CHANGED
|
@@ -204,15 +204,25 @@ 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
|
+
|
|
207
211
|
if (context.page_context.card_type) {
|
|
208
212
|
dispatch(setCardType(context.page_context.card_type));
|
|
213
|
+
} else if (isCreditCardPayment) {
|
|
214
|
+
dispatch(setCardType(null));
|
|
209
215
|
}
|
|
210
216
|
|
|
211
217
|
if (
|
|
212
218
|
context.page_context.installments &&
|
|
213
219
|
preOrder?.payment_option?.payment_type !== 'masterpass_rest'
|
|
214
220
|
) {
|
|
215
|
-
|
|
221
|
+
if (!isCreditCardPayment || context.page_context.card_type) {
|
|
222
|
+
dispatch(
|
|
223
|
+
setInstallmentOptions(context.page_context.installments)
|
|
224
|
+
);
|
|
225
|
+
}
|
|
216
226
|
}
|
|
217
227
|
}
|
|
218
228
|
|
|
@@ -14,9 +14,17 @@ export const installmentOptionMiddleware: Middleware = ({
|
|
|
14
14
|
return result;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const { installmentOptions } = getState().checkout;
|
|
17
|
+
const { installmentOptions, cardType } = 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
|
+
|
|
20
28
|
if (
|
|
21
29
|
!preOrder?.installment &&
|
|
22
30
|
preOrder?.payment_option?.payment_type !== 'saved_card' &&
|
package/types/index.ts
CHANGED
|
@@ -83,6 +83,12 @@ 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;
|
|
86
92
|
redis: {
|
|
87
93
|
defaultExpirationTime: number;
|
|
88
94
|
};
|
package/utils/app-fetch.ts
CHANGED
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
|
|
6
7
|
export enum FetchResponseType {
|
|
7
8
|
JSON = 'json',
|
|
@@ -60,13 +61,15 @@ const appFetch = async <T>({
|
|
|
60
61
|
status = req.status;
|
|
61
62
|
logger.debug(`FETCH END ${url}`, { status: req.status, ip });
|
|
62
63
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
if (req.ok) {
|
|
65
|
+
if (responseType === FetchResponseType.JSON) {
|
|
66
|
+
response = (await req.json()) as T;
|
|
67
|
+
} else {
|
|
68
|
+
response = (await req.text()) as unknown as T;
|
|
69
|
+
}
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
logger.trace(`FETCH RESPONSE`, { url, response, ip });
|
|
72
|
+
}
|
|
70
73
|
} catch (error) {
|
|
71
74
|
const logType = status === 500 ? 'fatal' : 'error';
|
|
72
75
|
|
|
@@ -75,6 +78,10 @@ const appFetch = async <T>({
|
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
|
|
81
|
+
if (status === 422) {
|
|
82
|
+
notFound();
|
|
83
|
+
}
|
|
84
|
+
|
|
78
85
|
return response;
|
|
79
86
|
};
|
|
80
87
|
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
const iframeURLChange = (iframe, callback) => {
|
|
2
2
|
iframe.addEventListener('load', () => {
|
|
3
3
|
setTimeout(() => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
try {
|
|
5
|
+
if (iframe?.contentWindow?.location) {
|
|
6
|
+
const iframeLocation = iframe.contentWindow.location;
|
|
7
|
+
|
|
8
|
+
callback(iframeLocation);
|
|
9
|
+
}
|
|
10
|
+
} catch (error) {
|
|
11
|
+
// Expected: browser blocks cross-origin iframe access for security
|
|
6
12
|
}
|
|
7
13
|
}, 0);
|
|
8
14
|
});
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
const iframeURLChange = (iframe, callback) => {
|
|
2
2
|
iframe.addEventListener('load', () => {
|
|
3
3
|
setTimeout(() => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
try {
|
|
5
|
+
if (iframe?.contentWindow?.location) {
|
|
6
|
+
const iframeLocation = iframe.contentWindow.location;
|
|
7
|
+
|
|
8
|
+
callback(iframeLocation);
|
|
9
|
+
}
|
|
10
|
+
} catch (error) {
|
|
11
|
+
// Expected: browser blocks cross-origin iframe access for security
|
|
6
12
|
}
|
|
7
13
|
}, 0);
|
|
8
14
|
});
|
package/with-pz-config.js
CHANGED