@akinon/next 1.6.0 → 1.8.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 +13 -0
- package/middlewares/currency.ts +15 -4
- package/middlewares/default.ts +35 -5
- package/middlewares/locale.ts +9 -2
- package/middlewares/pretty-url.ts +31 -27
- package/middlewares/redirection-payment.ts +81 -56
- package/middlewares/three-d-redirection.ts +11 -5
- package/middlewares/url-redirection.ts +5 -1
- package/package.json +1 -1
- package/redux/middlewares/checkout.ts +15 -0
- package/types/commerce/checkout.ts +1 -0
- package/utils/app-fetch.ts +9 -4
- package/utils/deep-merge.js +24 -0
- package/with-pz-config.js +94 -0
package/CHANGELOG.md
CHANGED
package/middlewares/currency.ts
CHANGED
|
@@ -20,6 +20,8 @@ const resetBasket = async (req: PzNextRequest) => {
|
|
|
20
20
|
const withCurrency =
|
|
21
21
|
(middleware: NextMiddleware) =>
|
|
22
22
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
23
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
24
|
+
|
|
23
25
|
try {
|
|
24
26
|
const { currencies, defaultCurrencyCode, defaultLocaleValue } =
|
|
25
27
|
settings.localization;
|
|
@@ -27,7 +29,9 @@ const withCurrency =
|
|
|
27
29
|
const url = req.nextUrl.clone();
|
|
28
30
|
|
|
29
31
|
if (!defaultCurrencyCode) {
|
|
30
|
-
logger.error('Default currency code is not defined in settings.'
|
|
32
|
+
logger.error('Default currency code is not defined in settings.', {
|
|
33
|
+
ip
|
|
34
|
+
});
|
|
31
35
|
throw new Error(
|
|
32
36
|
'Default currency code is not defined. Use `defaultCurrencyCode` property in `localization` object in `settings.js` file.'
|
|
33
37
|
);
|
|
@@ -57,7 +61,10 @@ const withCurrency =
|
|
|
57
61
|
!currencies.find((c) => c.code === activeCurrency)
|
|
58
62
|
) {
|
|
59
63
|
logger.warn(
|
|
60
|
-
`Currency ${activeCurrency} is not defined in settings. Using default currency ${defaultCurrencyCode} instead
|
|
64
|
+
`Currency ${activeCurrency} is not defined in settings. Using default currency ${defaultCurrencyCode} instead.`,
|
|
65
|
+
{
|
|
66
|
+
ip
|
|
67
|
+
}
|
|
61
68
|
);
|
|
62
69
|
activeCurrency = defaultCurrencyCode;
|
|
63
70
|
}
|
|
@@ -72,7 +79,8 @@ const withCurrency =
|
|
|
72
79
|
logger.info('Currency changed. Resetting basket...', {
|
|
73
80
|
sessionid: req.cookies.get('osessionid')?.value ?? '',
|
|
74
81
|
oldCurrency: req.cookies.get('pz-currency')?.value,
|
|
75
|
-
newCurrency: activeCurrency
|
|
82
|
+
newCurrency: activeCurrency,
|
|
83
|
+
ip
|
|
76
84
|
});
|
|
77
85
|
|
|
78
86
|
resetBasket(req);
|
|
@@ -80,7 +88,10 @@ const withCurrency =
|
|
|
80
88
|
|
|
81
89
|
req.middlewareParams.rewrites.currency = activeCurrency;
|
|
82
90
|
} catch (error) {
|
|
83
|
-
logger.error('withCurrency error',
|
|
91
|
+
logger.error('withCurrency error', {
|
|
92
|
+
error,
|
|
93
|
+
ip
|
|
94
|
+
});
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
return middleware(req, event);
|
package/middlewares/default.ts
CHANGED
|
@@ -13,6 +13,7 @@ import withCurrency from './currency';
|
|
|
13
13
|
import withLocale from './locale';
|
|
14
14
|
import logger from '../utils/log';
|
|
15
15
|
import { user } from '../data/urls';
|
|
16
|
+
import { getUrlPathWithLocale } from '../utils/localization';
|
|
16
17
|
|
|
17
18
|
const withPzDefault =
|
|
18
19
|
(middleware: NextMiddleware) =>
|
|
@@ -20,10 +21,12 @@ const withPzDefault =
|
|
|
20
21
|
const url = req.nextUrl.clone();
|
|
21
22
|
const commerceUrl = encodeURIComponent(decodeURI(Settings.commerceUrl)); // encodeURI doesn't work as expected in middleware
|
|
22
23
|
const searchParams = new URLSearchParams(url.search);
|
|
24
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
23
25
|
|
|
24
26
|
logger.debug('withPzDefault', {
|
|
25
27
|
url: url.href,
|
|
26
|
-
middlewareParams: req.middlewareParams
|
|
28
|
+
middlewareParams: req.middlewareParams,
|
|
29
|
+
ip
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
// Support legacy ?format=json query param
|
|
@@ -50,7 +53,10 @@ const withPzDefault =
|
|
|
50
53
|
|
|
51
54
|
return NextResponse.json(await request.json());
|
|
52
55
|
} catch (error) {
|
|
53
|
-
logger.error('?format=json error',
|
|
56
|
+
logger.error('?format=json error', {
|
|
57
|
+
error,
|
|
58
|
+
ip
|
|
59
|
+
});
|
|
54
60
|
return NextResponse.next();
|
|
55
61
|
}
|
|
56
62
|
}
|
|
@@ -87,6 +93,23 @@ const withPzDefault =
|
|
|
87
93
|
);
|
|
88
94
|
}
|
|
89
95
|
|
|
96
|
+
// If commerce redirects to /orders/checkout/ without locale
|
|
97
|
+
if (
|
|
98
|
+
req.nextUrl.pathname.match(new RegExp('^/orders/checkout/$')) &&
|
|
99
|
+
req.nextUrl.searchParams.size === 0 &&
|
|
100
|
+
getUrlPathWithLocale(
|
|
101
|
+
'/orders/checkout/',
|
|
102
|
+
req.cookies.get('pz-locale')?.value
|
|
103
|
+
) !== req.nextUrl.pathname
|
|
104
|
+
) {
|
|
105
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
106
|
+
'/orders/checkout/',
|
|
107
|
+
req.cookies.get('pz-locale')?.value
|
|
108
|
+
)}`;
|
|
109
|
+
|
|
110
|
+
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
111
|
+
}
|
|
112
|
+
|
|
90
113
|
req.middlewareParams = {
|
|
91
114
|
commerceUrl,
|
|
92
115
|
rewrites: {}
|
|
@@ -175,7 +198,8 @@ const withPzDefault =
|
|
|
175
198
|
) {
|
|
176
199
|
logger.debug('Locale changed', {
|
|
177
200
|
locale,
|
|
178
|
-
oldLocale: req.cookies.get('pz-locale')?.value
|
|
201
|
+
oldLocale: req.cookies.get('pz-locale')?.value,
|
|
202
|
+
ip
|
|
179
203
|
});
|
|
180
204
|
}
|
|
181
205
|
|
|
@@ -206,10 +230,16 @@ const withPzDefault =
|
|
|
206
230
|
middlewareResult.cookies.set('csrftoken', csrf_token);
|
|
207
231
|
}
|
|
208
232
|
} catch (error) {
|
|
209
|
-
logger.error('CSRF Error',
|
|
233
|
+
logger.error('CSRF Error', {
|
|
234
|
+
error,
|
|
235
|
+
ip
|
|
236
|
+
});
|
|
210
237
|
}
|
|
211
238
|
} catch (error) {
|
|
212
|
-
logger.error('withPzDefault Error',
|
|
239
|
+
logger.error('withPzDefault Error', {
|
|
240
|
+
error,
|
|
241
|
+
ip
|
|
242
|
+
});
|
|
213
243
|
}
|
|
214
244
|
|
|
215
245
|
return middlewareResult;
|
package/middlewares/locale.ts
CHANGED
|
@@ -24,6 +24,8 @@ const getMatchedLocale = (pathname: string) => {
|
|
|
24
24
|
const withLocale =
|
|
25
25
|
(middleware: NextMiddleware) =>
|
|
26
26
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
27
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
28
|
+
|
|
27
29
|
try {
|
|
28
30
|
const url = req.nextUrl.clone();
|
|
29
31
|
const matchedLocale = getMatchedLocale(url.pathname);
|
|
@@ -34,7 +36,9 @@ const withLocale =
|
|
|
34
36
|
localeUrlStrategy ?? LocaleUrlStrategy.HideDefaultLocale;
|
|
35
37
|
|
|
36
38
|
if (!defaultLocaleValue) {
|
|
37
|
-
logger.error('Default locale value is not defined in settings.'
|
|
39
|
+
logger.error('Default locale value is not defined in settings.', {
|
|
40
|
+
ip
|
|
41
|
+
});
|
|
38
42
|
throw new Error(
|
|
39
43
|
'Default locale value is not defined. Use `defaultLocaleValue` property in `localization` object in `settings.js` file.'
|
|
40
44
|
);
|
|
@@ -52,7 +56,10 @@ const withLocale =
|
|
|
52
56
|
|
|
53
57
|
req.middlewareParams.rewrites.locale = matchedLocale;
|
|
54
58
|
} catch (error) {
|
|
55
|
-
logger.error('withLocale error',
|
|
59
|
+
logger.error('withLocale error', {
|
|
60
|
+
error,
|
|
61
|
+
ip
|
|
62
|
+
});
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
return middleware(req, event);
|
|
@@ -12,40 +12,41 @@ type PrettyUrlResult = {
|
|
|
12
12
|
path?: string;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const resolvePrettyUrlHandler =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const resolvePrettyUrlHandler =
|
|
16
|
+
(pathname: string, ip: string | null) => async () => {
|
|
17
|
+
let results = <{ old_path: string }[]>[];
|
|
18
|
+
let prettyUrlResult: PrettyUrlResult = {
|
|
19
|
+
matched: false
|
|
20
|
+
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
try {
|
|
23
|
+
const requestUrl = URLS.misc.prettyUrls(pathname);
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
logger.debug(`Resolving pretty url`, { pathname, requestUrl, ip });
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const apiResponse = await fetch(requestUrl);
|
|
28
|
+
const data = await apiResponse.json();
|
|
29
|
+
({ results } = data);
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const matched = results.length > 0;
|
|
32
|
+
const [{ old_path: path } = { old_path: '' }] = results;
|
|
33
|
+
prettyUrlResult = {
|
|
34
|
+
matched,
|
|
35
|
+
path
|
|
36
|
+
};
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
logger.trace('Pretty url result', { prettyUrlResult, ip });
|
|
39
|
+
} catch (error) {
|
|
40
|
+
logger.error('Error resolving pretty url', { error, pathname, ip });
|
|
41
|
+
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
};
|
|
43
|
+
return prettyUrlResult;
|
|
44
|
+
};
|
|
44
45
|
|
|
45
|
-
const resolvePrettyUrl = async (pathname: string) => {
|
|
46
|
+
const resolvePrettyUrl = async (pathname: string, ip: string | null) => {
|
|
46
47
|
return Cache.wrap(
|
|
47
48
|
CacheKey.PrettyUrl(pathname),
|
|
48
|
-
resolvePrettyUrlHandler(pathname),
|
|
49
|
+
resolvePrettyUrlHandler(pathname, ip),
|
|
49
50
|
{
|
|
50
51
|
useProxy: true
|
|
51
52
|
}
|
|
@@ -68,6 +69,7 @@ const withPrettyUrl =
|
|
|
68
69
|
)
|
|
69
70
|
);
|
|
70
71
|
};
|
|
72
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
71
73
|
|
|
72
74
|
if (
|
|
73
75
|
!isValidPrettyUrlPath(prettyUrlPathname) ||
|
|
@@ -81,14 +83,16 @@ const withPrettyUrl =
|
|
|
81
83
|
prettyUrlPathname
|
|
82
84
|
)
|
|
83
85
|
? url.pathname
|
|
84
|
-
: prettyUrlPathname
|
|
86
|
+
: prettyUrlPathname,
|
|
87
|
+
ip
|
|
85
88
|
);
|
|
86
89
|
|
|
87
90
|
if (prettyUrlResult.matched) {
|
|
88
91
|
req.middlewareParams.rewrites.prettyUrl = prettyUrlResult.path;
|
|
89
92
|
logger.debug('Resolved pretty url', {
|
|
90
93
|
source: prettyUrlPathname,
|
|
91
|
-
dest: prettyUrlResult.path
|
|
94
|
+
dest: prettyUrlResult.path,
|
|
95
|
+
ip
|
|
92
96
|
});
|
|
93
97
|
|
|
94
98
|
return middleware(req, event);
|
|
@@ -38,81 +38,106 @@ const withRedirectionPayment =
|
|
|
38
38
|
''
|
|
39
39
|
);
|
|
40
40
|
const searchParams = new URLSearchParams(url.search);
|
|
41
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
41
42
|
|
|
42
|
-
if (
|
|
43
|
-
!pathnameWithoutLocale.startsWith('/orders') ||
|
|
44
|
-
searchParams.get('page') !== 'RedirectionPageCompletePage' ||
|
|
45
|
-
req.method !== 'POST'
|
|
46
|
-
) {
|
|
43
|
+
if (searchParams.get('page') !== 'RedirectionPageCompletePage') {
|
|
47
44
|
return middleware(req, event);
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
const body = await streamToString(req.body);
|
|
51
47
|
const requestUrl = `${Settings.commerceUrl}/orders/checkout/${url.search}`;
|
|
48
|
+
const requestHeaders = {
|
|
49
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
50
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
51
|
+
Cookie: req.headers.get('cookie') ?? '',
|
|
52
|
+
'x-currency': req.cookies.get('pz-currency')?.value ?? ''
|
|
53
|
+
};
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
try {
|
|
56
|
+
const body = await streamToString(req.body);
|
|
57
|
+
|
|
58
|
+
const request = await fetch(requestUrl, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: requestHeaders,
|
|
61
|
+
body
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
logger.info('Complete redirection payment request', {
|
|
65
|
+
requestUrl,
|
|
66
|
+
status: request.status,
|
|
67
|
+
requestHeaders,
|
|
68
|
+
ip
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const response = await request.json();
|
|
72
|
+
|
|
73
|
+
const { context_list: contextList } = response;
|
|
74
|
+
const redirectionContext = contextList?.find(
|
|
75
|
+
(context) => context.page_context?.redirect_url
|
|
76
|
+
);
|
|
77
|
+
const redirectUrl = redirectionContext?.page_context?.redirect_url;
|
|
76
78
|
|
|
77
|
-
if (!redirectUrl) {
|
|
78
79
|
logger.info('Order success page context list', {
|
|
79
80
|
middleware: 'redirection-payment',
|
|
80
|
-
contextList
|
|
81
|
+
contextList,
|
|
82
|
+
ip
|
|
81
83
|
});
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
if (!redirectUrl) {
|
|
86
|
+
logger.warn(
|
|
87
|
+
'No redirection url for order success page found in page_context',
|
|
88
|
+
{
|
|
89
|
+
middleware: 'redirection-payment',
|
|
90
|
+
requestHeaders,
|
|
91
|
+
response: JSON.stringify(response),
|
|
92
|
+
ip
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
97
|
+
'/orders/checkout/',
|
|
98
|
+
req.cookies.get('pz-locale')?.value
|
|
99
|
+
)}`;
|
|
100
|
+
|
|
101
|
+
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
105
|
+
redirectUrl,
|
|
106
|
+
req.cookies.get('pz-locale')?.value
|
|
107
|
+
)}`;
|
|
108
|
+
|
|
109
|
+
logger.info('Redirecting to order success page', {
|
|
110
|
+
middleware: 'redirection-payment',
|
|
111
|
+
redirectUrlWithLocale,
|
|
112
|
+
ip
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Using POST method while redirecting causes an error,
|
|
116
|
+
// So we use 303 status code to change the method to GET
|
|
117
|
+
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
118
|
+
|
|
119
|
+
nextResponse.headers.set(
|
|
120
|
+
'Set-Cookie',
|
|
121
|
+
request.headers.get('set-cookie') ?? ''
|
|
86
122
|
);
|
|
123
|
+
|
|
124
|
+
return nextResponse;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
logger.error('Error while completing redirection payment', {
|
|
127
|
+
middleware: 'redirection-payment',
|
|
128
|
+
error,
|
|
129
|
+
requestHeaders,
|
|
130
|
+
ip
|
|
131
|
+
});
|
|
132
|
+
|
|
87
133
|
return NextResponse.redirect(
|
|
88
134
|
`${url.origin}${getUrlPathWithLocale(
|
|
89
|
-
|
|
135
|
+
'/orders/checkout/',
|
|
90
136
|
req.cookies.get('pz-locale')?.value
|
|
91
137
|
)}`,
|
|
92
138
|
303
|
|
93
139
|
);
|
|
94
140
|
}
|
|
95
|
-
|
|
96
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
97
|
-
redirectUrl,
|
|
98
|
-
req.cookies.get('pz-locale')?.value
|
|
99
|
-
)}`;
|
|
100
|
-
|
|
101
|
-
logger.info('Redirecting to order success page', {
|
|
102
|
-
middleware: 'redirection-payment',
|
|
103
|
-
redirectUrlWithLocale
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Using POST method while redirecting causes an error,
|
|
107
|
-
// So we use 303 status code to change the method to GET
|
|
108
|
-
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
109
|
-
|
|
110
|
-
nextResponse.headers.set(
|
|
111
|
-
'Set-Cookie',
|
|
112
|
-
request.headers.get('set-cookie') ?? ''
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return nextResponse;
|
|
116
141
|
};
|
|
117
142
|
|
|
118
143
|
export default withRedirectionPayment;
|
|
@@ -32,6 +32,7 @@ const withThreeDRedirection =
|
|
|
32
32
|
(middleware: NextMiddleware) =>
|
|
33
33
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
34
34
|
const url = req.nextUrl.clone();
|
|
35
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
35
36
|
|
|
36
37
|
if (url.search.indexOf('CreditCardThreeDSecurePage') === -1) {
|
|
37
38
|
return middleware(req, event);
|
|
@@ -57,7 +58,8 @@ const withThreeDRedirection =
|
|
|
57
58
|
logger.info('Complete 3D payment request', {
|
|
58
59
|
requestUrl,
|
|
59
60
|
status: request.status,
|
|
60
|
-
requestHeaders
|
|
61
|
+
requestHeaders,
|
|
62
|
+
ip
|
|
61
63
|
});
|
|
62
64
|
|
|
63
65
|
const response = await request.json();
|
|
@@ -70,7 +72,8 @@ const withThreeDRedirection =
|
|
|
70
72
|
|
|
71
73
|
logger.info('Order success page context list', {
|
|
72
74
|
middleware: 'three-d-redirection',
|
|
73
|
-
contextList
|
|
75
|
+
contextList,
|
|
76
|
+
ip
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
if (!redirectUrl) {
|
|
@@ -79,7 +82,8 @@ const withThreeDRedirection =
|
|
|
79
82
|
{
|
|
80
83
|
middleware: 'three-d-redirection',
|
|
81
84
|
requestHeaders,
|
|
82
|
-
response: JSON.stringify(response)
|
|
85
|
+
response: JSON.stringify(response),
|
|
86
|
+
ip
|
|
83
87
|
}
|
|
84
88
|
);
|
|
85
89
|
|
|
@@ -98,7 +102,8 @@ const withThreeDRedirection =
|
|
|
98
102
|
|
|
99
103
|
logger.info('Redirecting to order success page', {
|
|
100
104
|
middleware: 'three-d-redirection',
|
|
101
|
-
redirectUrlWithLocale
|
|
105
|
+
redirectUrlWithLocale,
|
|
106
|
+
ip
|
|
102
107
|
});
|
|
103
108
|
|
|
104
109
|
// Using POST method while redirecting causes an error,
|
|
@@ -115,7 +120,8 @@ const withThreeDRedirection =
|
|
|
115
120
|
logger.error('Error while completing 3D payment', {
|
|
116
121
|
middleware: 'three-d-redirection',
|
|
117
122
|
error,
|
|
118
|
-
requestHeaders
|
|
123
|
+
requestHeaders,
|
|
124
|
+
ip
|
|
119
125
|
});
|
|
120
126
|
|
|
121
127
|
return NextResponse.redirect(
|
|
@@ -12,6 +12,7 @@ const withUrlRedirection =
|
|
|
12
12
|
(middleware: NextMiddleware) =>
|
|
13
13
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
14
14
|
const url = req.nextUrl.clone();
|
|
15
|
+
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
15
16
|
const pathnameWithoutLocale = url.pathname.replace(
|
|
16
17
|
urlLocaleMatcherRegex,
|
|
17
18
|
''
|
|
@@ -52,7 +53,10 @@ const withUrlRedirection =
|
|
|
52
53
|
return Response.redirect(redirectUrl.toString(), request.status);
|
|
53
54
|
}
|
|
54
55
|
} catch (error) {
|
|
55
|
-
logger.error('withUrlRedirection error',
|
|
56
|
+
logger.error('withUrlRedirection error', {
|
|
57
|
+
error,
|
|
58
|
+
ip
|
|
59
|
+
});
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
return middleware(req, event);
|
package/package.json
CHANGED
|
@@ -77,6 +77,21 @@ export const preOrderMiddleware: Middleware = ({
|
|
|
77
77
|
} = getState().checkout;
|
|
78
78
|
const { endpoints: apiEndpoints } = checkoutApi;
|
|
79
79
|
|
|
80
|
+
if (preOrder.is_redirected) {
|
|
81
|
+
const contextList = result?.payload?.context_list;
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
contextList.find(
|
|
85
|
+
(ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
|
|
86
|
+
)
|
|
87
|
+
) {
|
|
88
|
+
dispatch(
|
|
89
|
+
apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
|
|
90
|
+
);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
80
95
|
dispatch(setPreOrder(preOrder));
|
|
81
96
|
|
|
82
97
|
if (!preOrder.delivery_option && deliveryOptions.length > 0) {
|
package/utils/app-fetch.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Settings from 'settings';
|
|
2
2
|
import { ServerVariables } from './server-variables';
|
|
3
3
|
import logger from '../utils/log';
|
|
4
|
+
import { headers } from 'next/headers';
|
|
4
5
|
|
|
5
6
|
export enum FetchResponseType {
|
|
6
7
|
JSON = 'json',
|
|
@@ -14,8 +15,12 @@ const appFetch = async <T>(
|
|
|
14
15
|
) => {
|
|
15
16
|
let response: T;
|
|
16
17
|
let status: number;
|
|
18
|
+
let ip = '';
|
|
17
19
|
|
|
18
20
|
try {
|
|
21
|
+
const nextHeaders = headers();
|
|
22
|
+
ip = nextHeaders.get('x-forwarded-for') ?? '';
|
|
23
|
+
|
|
19
24
|
const commerceUrl = Settings.commerceUrl;
|
|
20
25
|
const currentLocale = Settings.localization.locales.find(
|
|
21
26
|
(locale) => locale.value === ServerVariables.locale
|
|
@@ -38,10 +43,10 @@ const appFetch = async <T>(
|
|
|
38
43
|
revalidate: 60
|
|
39
44
|
};
|
|
40
45
|
|
|
41
|
-
logger.debug(`FETCH START ${url}`, { requestURL, init });
|
|
46
|
+
logger.debug(`FETCH START ${url}`, { requestURL, init, ip });
|
|
42
47
|
const req = await fetch(requestURL, init);
|
|
43
48
|
status = req.status;
|
|
44
|
-
logger.debug(`FETCH END ${url}`, { status: req.status });
|
|
49
|
+
logger.debug(`FETCH END ${url}`, { status: req.status, ip });
|
|
45
50
|
|
|
46
51
|
const rawData = await req.text();
|
|
47
52
|
|
|
@@ -51,9 +56,9 @@ const appFetch = async <T>(
|
|
|
51
56
|
response = rawData as unknown as T;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
logger.trace(`FETCH RESPONSE`, { url, response });
|
|
59
|
+
logger.trace(`FETCH RESPONSE`, { url, response, ip });
|
|
55
60
|
} catch (error) {
|
|
56
|
-
logger.error(`FETCH FAILED`, { url, status, error });
|
|
61
|
+
logger.error(`FETCH FAILED`, { url, status, error, ip });
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
return response;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function isObject(item) {
|
|
2
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function deepMerge(target, ...sources) {
|
|
6
|
+
if (!sources.length) return target;
|
|
7
|
+
|
|
8
|
+
const source = sources.shift();
|
|
9
|
+
|
|
10
|
+
if (isObject(target) && isObject(source)) {
|
|
11
|
+
for (const key in source) {
|
|
12
|
+
if (isObject(source[key])) {
|
|
13
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
14
|
+
deepMerge(target[key], source[key]);
|
|
15
|
+
} else {
|
|
16
|
+
Object.assign(target, { [key]: source[key] });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return deepMerge(target, ...sources);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = deepMerge;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const pzPlugins = require('./plugins');
|
|
2
|
+
const deepMerge = require('./utils/deep-merge');
|
|
3
|
+
|
|
4
|
+
/** @type {import('next').NextConfig} */
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
experimental: { serverActions: true },
|
|
7
|
+
reactStrictMode: true,
|
|
8
|
+
transpilePackages: ['@akinon/next', ...pzPlugins],
|
|
9
|
+
skipTrailingSlashRedirect: true,
|
|
10
|
+
poweredByHeader: false,
|
|
11
|
+
env: {
|
|
12
|
+
NEXT_PUBLIC_SENTRY_DSN: process.env.SENTRY_DSN
|
|
13
|
+
},
|
|
14
|
+
images: {
|
|
15
|
+
remotePatterns: [
|
|
16
|
+
{
|
|
17
|
+
protocol: 'https',
|
|
18
|
+
hostname: '**.akinoncloud.com'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
protocol: 'https',
|
|
22
|
+
hostname: '**.akinoncdn.com'
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
modularizeImports: {
|
|
27
|
+
components: {
|
|
28
|
+
transform: 'components/{{ kebabCase member }}',
|
|
29
|
+
skipDefaultConversion: true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
async headers() {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
source: '/(.*)',
|
|
36
|
+
headers: [
|
|
37
|
+
{
|
|
38
|
+
key: 'X-Content-Type-Options',
|
|
39
|
+
value: 'nosniff'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: 'Strict-Transport-Security',
|
|
43
|
+
value: 'max-age=63072000; includeSubDomains; preload'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: 'X-Frame-Options',
|
|
47
|
+
value: 'SAMEORIGIN'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
},
|
|
53
|
+
webpack: (config, options) => {
|
|
54
|
+
config.resolve.fallback = {
|
|
55
|
+
...config.resolve.fallback,
|
|
56
|
+
...pzPlugins.reduce((acc, plugin) => {
|
|
57
|
+
acc[plugin] = false;
|
|
58
|
+
return acc;
|
|
59
|
+
}, {})
|
|
60
|
+
};
|
|
61
|
+
return config;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const withPzConfig = (myNextConfig = {}) => {
|
|
66
|
+
let extendedConfig = deepMerge({}, defaultConfig, myNextConfig);
|
|
67
|
+
|
|
68
|
+
const originalPzHeadersFunction = defaultConfig.headers;
|
|
69
|
+
extendedConfig.headers = async () => {
|
|
70
|
+
const pzHeaders = (await originalPzHeadersFunction?.()) ?? [];
|
|
71
|
+
const myHeaders = (await myNextConfig.headers?.()) ?? [];
|
|
72
|
+
return [...pzHeaders, ...myHeaders];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const originalPzWebpack = defaultConfig.webpack;
|
|
76
|
+
extendedConfig.webpack = (config, options) => {
|
|
77
|
+
let modifiedConfig = originalPzWebpack(config, options);
|
|
78
|
+
if (myNextConfig.webpack) {
|
|
79
|
+
modifiedConfig = myNextConfig.webpack(modifiedConfig, options);
|
|
80
|
+
}
|
|
81
|
+
return modifiedConfig;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const originalPzRewrites = defaultConfig.rewrites;
|
|
85
|
+
extendedConfig.rewrites = async () => {
|
|
86
|
+
const pzRewrites = (await originalPzRewrites?.()) ?? [];
|
|
87
|
+
const myRewrites = (await myNextConfig.rewrites?.()) ?? [];
|
|
88
|
+
return [...pzRewrites, ...myRewrites];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return extendedConfig;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
module.exports = withPzConfig;
|