@akinon/next 1.60.0-rc.9 → 1.60.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 +9 -666
- package/api/client.ts +2 -23
- package/assets/styles/index.scss +26 -50
- package/bin/pz-prebuild.js +0 -1
- package/bin/pz-predev.js +0 -1
- package/components/index.ts +0 -1
- package/components/input.tsx +7 -21
- package/components/link.tsx +13 -17
- package/components/plugin-module.tsx +3 -8
- package/components/price.tsx +4 -11
- package/components/pz-root.tsx +3 -15
- package/components/selected-payment-option-view.tsx +1 -2
- package/data/client/api.ts +1 -1
- package/data/client/b2b.ts +2 -35
- package/data/client/basket.ts +5 -6
- package/data/client/checkout.ts +10 -55
- package/data/client/user.ts +2 -3
- package/data/server/category.ts +19 -43
- package/data/server/flatpage.ts +7 -29
- package/data/server/form.ts +11 -29
- package/data/server/landingpage.ts +7 -26
- package/data/server/list.ts +6 -16
- package/data/server/menu.ts +2 -15
- package/data/server/product.ts +13 -33
- package/data/server/seo.ts +24 -17
- package/data/server/special-page.ts +5 -16
- package/data/server/widget.ts +7 -14
- package/data/urls.ts +1 -8
- package/hocs/server/with-segment-defaults.tsx +1 -4
- package/hooks/index.ts +1 -2
- package/hooks/use-pagination.ts +2 -2
- package/hooks/use-payment-options.ts +1 -2
- package/lib/cache.ts +6 -4
- package/middlewares/currency.ts +1 -1
- package/middlewares/default.ts +167 -226
- package/middlewares/index.ts +1 -3
- package/middlewares/oauth-login.ts +1 -6
- package/middlewares/pretty-url.ts +1 -7
- package/package.json +2 -2
- package/plugins.d.ts +0 -6
- package/plugins.js +1 -2
- package/redux/middlewares/checkout.ts +14 -78
- package/redux/reducers/checkout.ts +3 -23
- package/redux/reducers/index.ts +1 -3
- package/routes/pretty-url.tsx +9 -7
- package/types/commerce/address.ts +1 -1
- package/types/commerce/b2b.ts +2 -12
- package/types/commerce/checkout.ts +0 -30
- package/types/commerce/order.ts +0 -1
- package/types/index.ts +7 -16
- package/utils/app-fetch.ts +7 -15
- package/utils/index.ts +6 -27
- package/utils/server-translation.ts +1 -11
- package/with-pz-config.js +1 -2
- package/assets/styles/index.css +0 -49
- package/assets/styles/index.css.map +0 -1
- package/bin/pz-generate-translations.js +0 -41
- package/components/file-input.tsx +0 -8
- package/hooks/use-message-listener.ts +0 -24
- package/middlewares/saved-card-redirection.ts +0 -179
- package/utils/redirection-iframe.ts +0 -85
|
@@ -2,6 +2,7 @@ import settings from 'settings';
|
|
|
2
2
|
import { LayoutProps, PageProps, RootLayoutProps } from '../../types';
|
|
3
3
|
import { redirect } from 'next/navigation';
|
|
4
4
|
import { ServerVariables } from '../../utils/server-variables';
|
|
5
|
+
import { getTranslations } from '../../utils/server-translation';
|
|
5
6
|
import { ROUTES } from 'routes';
|
|
6
7
|
import logger from '../../utils/log';
|
|
7
8
|
|
|
@@ -49,11 +50,7 @@ const addRootLayoutProps = async (componentProps: RootLayoutProps) => {
|
|
|
49
50
|
return redirect(ROUTES.HOME);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
const { getTranslations } = settings.useOptimizedTranslations
|
|
53
|
-
? require('translations')
|
|
54
|
-
: require('../../utils/server-translation');
|
|
55
53
|
const translations = await getTranslations(params.locale);
|
|
56
|
-
|
|
57
54
|
componentProps.translations = translations;
|
|
58
55
|
|
|
59
56
|
const locale = settings.localization.locales.find(
|
package/hooks/index.ts
CHANGED
|
@@ -8,5 +8,4 @@ export * from './use-media-query';
|
|
|
8
8
|
export * from './use-on-click-outside';
|
|
9
9
|
export * from './use-mobile-iframe-handler';
|
|
10
10
|
export * from './use-payment-options';
|
|
11
|
-
export * from './use-pagination';
|
|
12
|
-
export * from './use-message-listener';
|
|
11
|
+
export * from './use-pagination';
|
package/hooks/use-pagination.ts
CHANGED
|
@@ -116,7 +116,7 @@ export default function usePagination(
|
|
|
116
116
|
urlSearchParams.set('page', (Number(state.page) - 1).toString());
|
|
117
117
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
118
118
|
}
|
|
119
|
-
return
|
|
119
|
+
return '#';
|
|
120
120
|
}, [state.page, pathname, urlSearchParams]);
|
|
121
121
|
|
|
122
122
|
const next = useMemo(() => {
|
|
@@ -124,7 +124,7 @@ export default function usePagination(
|
|
|
124
124
|
urlSearchParams.set('page', (Number(state.page) + 1).toString());
|
|
125
125
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
126
126
|
}
|
|
127
|
-
return
|
|
127
|
+
return '#';
|
|
128
128
|
}, [state.page, state.last, pathname, urlSearchParams]);
|
|
129
129
|
|
|
130
130
|
return {
|
|
@@ -19,8 +19,7 @@ export const usePaymentOptions = () => {
|
|
|
19
19
|
bkm_express: 'pz-bkm',
|
|
20
20
|
credit_payment: 'pz-credit-payment',
|
|
21
21
|
masterpass: 'pz-masterpass',
|
|
22
|
-
gpay: 'pz-gpay'
|
|
23
|
-
saved_card: 'pz-saved-card'
|
|
22
|
+
gpay: 'pz-gpay'
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
const isInitialTypeIncluded = (type: string) => initialTypes.has(type);
|
package/lib/cache.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { RedisClientType } from 'redis';
|
|
|
3
3
|
import Settings from 'settings';
|
|
4
4
|
import { CacheOptions } from '../types';
|
|
5
5
|
import logger from '../utils/log';
|
|
6
|
+
import { ServerVariables } from '../utils/server-variables';
|
|
6
7
|
|
|
7
8
|
const hashCacheKey = (object?: Record<string, string>) => {
|
|
8
9
|
if (!object) {
|
|
@@ -58,8 +59,10 @@ export const CacheKey = {
|
|
|
58
59
|
export class Cache {
|
|
59
60
|
static PROXY_URL = `${process.env.NEXT_PUBLIC_URL}/api/cache`;
|
|
60
61
|
|
|
61
|
-
static formatKey(key: string
|
|
62
|
-
return encodeURIComponent(
|
|
62
|
+
static formatKey(key: string) {
|
|
63
|
+
return encodeURIComponent(
|
|
64
|
+
`${Settings.commerceUrl}_${ServerVariables.locale}_${key}`
|
|
65
|
+
);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
static clientPool: Pool<RedisClientType> = createPool(
|
|
@@ -152,7 +155,6 @@ export class Cache {
|
|
|
152
155
|
|
|
153
156
|
static async wrap<T = any>(
|
|
154
157
|
key: string,
|
|
155
|
-
locale: string,
|
|
156
158
|
handler: () => Promise<T>,
|
|
157
159
|
options?: CacheOptions
|
|
158
160
|
): Promise<T> {
|
|
@@ -176,7 +178,7 @@ export class Cache {
|
|
|
176
178
|
};
|
|
177
179
|
|
|
178
180
|
const _options = Object.assign(defaultOptions, options);
|
|
179
|
-
const formattedKey = Cache.formatKey(key
|
|
181
|
+
const formattedKey = Cache.formatKey(key);
|
|
180
182
|
|
|
181
183
|
logger.debug('Cache wrap', { key, formattedKey, _options });
|
|
182
184
|
|
package/middlewares/currency.ts
CHANGED
|
@@ -75,7 +75,7 @@ const withCurrency =
|
|
|
75
75
|
url.pathname.match(urlLocaleMatcherRegex) &&
|
|
76
76
|
!url.search.includes('mobile_app=true') &&
|
|
77
77
|
!url.search.includes('page=CreditCardThreeDSecurePage') &&
|
|
78
|
-
|
|
78
|
+
settings.resetBasketOnCurrencyChange !== false
|
|
79
79
|
) {
|
|
80
80
|
logger.info('Currency changed. Resetting basket...', {
|
|
81
81
|
sessionid: req.cookies.get('osessionid')?.value ?? '',
|
package/middlewares/default.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
withOauthLogin,
|
|
10
10
|
withPrettyUrl,
|
|
11
11
|
withRedirectionPayment,
|
|
12
|
-
withSavedCardRedirection,
|
|
13
12
|
withThreeDRedirection,
|
|
14
13
|
withUrlRedirection
|
|
15
14
|
} from '.';
|
|
@@ -97,44 +96,14 @@ const withPzDefault =
|
|
|
97
96
|
req.nextUrl.pathname.includes('/orders/hooks/') ||
|
|
98
97
|
req.nextUrl.pathname.includes('/orders/checkout-with-token/')
|
|
99
98
|
) {
|
|
100
|
-
|
|
101
|
-
const currency = url.searchParams.get('currency')?.toLowerCase();
|
|
102
|
-
|
|
103
|
-
const headers = {};
|
|
104
|
-
|
|
105
|
-
if (segment) {
|
|
106
|
-
headers['X-Segment-Id'] = segment;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (currency) {
|
|
110
|
-
headers['x-currency'] = currency;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const response = NextResponse.rewrite(
|
|
99
|
+
return NextResponse.rewrite(
|
|
114
100
|
new URL(
|
|
115
101
|
`${Settings.commerceUrl}${req.nextUrl.pathname.replace(
|
|
116
102
|
urlLocaleMatcherRegex,
|
|
117
103
|
''
|
|
118
104
|
)}`
|
|
119
|
-
)
|
|
120
|
-
{
|
|
121
|
-
headers
|
|
122
|
-
}
|
|
105
|
+
)
|
|
123
106
|
);
|
|
124
|
-
|
|
125
|
-
if (segment) {
|
|
126
|
-
response.cookies.set('pz-segment', segment);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (currency) {
|
|
130
|
-
response.cookies.set('pz-currency', currency, {
|
|
131
|
-
sameSite: 'none',
|
|
132
|
-
secure: true,
|
|
133
|
-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7) // 7 days
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return response;
|
|
138
107
|
}
|
|
139
108
|
|
|
140
109
|
if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
|
|
@@ -149,14 +118,6 @@ const withPzDefault =
|
|
|
149
118
|
);
|
|
150
119
|
}
|
|
151
120
|
|
|
152
|
-
if (req.nextUrl.pathname.includes('/orders/saved-card-redirect')) {
|
|
153
|
-
return NextResponse.rewrite(
|
|
154
|
-
new URL(
|
|
155
|
-
`${encodeURI(Settings.commerceUrl)}/orders/saved-card-redirect/`
|
|
156
|
-
)
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
121
|
// If commerce redirects to /orders/checkout/ without locale
|
|
161
122
|
if (
|
|
162
123
|
req.nextUrl.pathname.match(new RegExp('^/orders/checkout/$')) &&
|
|
@@ -174,25 +135,6 @@ const withPzDefault =
|
|
|
174
135
|
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
175
136
|
}
|
|
176
137
|
|
|
177
|
-
// Dynamically handle any payment gateway without specifying names
|
|
178
|
-
const paymentGatewayRegex = new RegExp('^/payment-gateway/([^/]+)/$');
|
|
179
|
-
const gatewayMatch = req.nextUrl.pathname.match(paymentGatewayRegex);
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
gatewayMatch && // Check if the URL matches the /payment-gateway/<gateway> pattern
|
|
183
|
-
getUrlPathWithLocale(
|
|
184
|
-
`/payment-gateway/${gatewayMatch[1]}/`,
|
|
185
|
-
req.cookies.get('pz-locale')?.value
|
|
186
|
-
) !== req.nextUrl.pathname
|
|
187
|
-
) {
|
|
188
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
189
|
-
`/payment-gateway/${gatewayMatch[1]}/`,
|
|
190
|
-
req.cookies.get('pz-locale')?.value
|
|
191
|
-
)}?${req.nextUrl.searchParams.toString()}`;
|
|
192
|
-
|
|
193
|
-
return NextResponse.redirect(redirectUrlWithLocale);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
138
|
if (req.nextUrl.pathname.startsWith('/orders/checkout-provider/')) {
|
|
197
139
|
try {
|
|
198
140
|
const data = await req.json();
|
|
@@ -240,141 +182,129 @@ const withPzDefault =
|
|
|
240
182
|
withUrlRedirection(
|
|
241
183
|
withCompleteGpay(
|
|
242
184
|
withCompleteMasterpass(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
185
|
+
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
186
|
+
let middlewareResult: NextResponse | void =
|
|
187
|
+
NextResponse.next();
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
const { locale, prettyUrl, currency } =
|
|
191
|
+
req.middlewareParams.rewrites;
|
|
192
|
+
const { defaultLocaleValue } =
|
|
193
|
+
Settings.localization;
|
|
194
|
+
const url = req.nextUrl.clone();
|
|
195
|
+
const pathnameWithoutLocale = url.pathname.replace(
|
|
196
|
+
urlLocaleMatcherRegex,
|
|
197
|
+
''
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
middlewareResult = (await middleware(
|
|
201
|
+
req,
|
|
202
|
+
event
|
|
203
|
+
)) as NextResponse | void;
|
|
204
|
+
|
|
205
|
+
let customRewriteUrlDiff = '';
|
|
206
|
+
|
|
207
|
+
if (
|
|
208
|
+
middlewareResult instanceof NextResponse &&
|
|
209
|
+
middlewareResult.headers.get(
|
|
210
|
+
'pz-override-response'
|
|
211
|
+
) &&
|
|
212
|
+
middlewareResult.headers.get(
|
|
213
|
+
'x-middleware-rewrite'
|
|
214
|
+
)
|
|
215
|
+
) {
|
|
216
|
+
const rewriteUrl = new URL(
|
|
271
217
|
middlewareResult.headers.get(
|
|
272
218
|
'x-middleware-rewrite'
|
|
273
219
|
)
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const originalUrl = new URL(req.url);
|
|
281
|
-
customRewriteUrlDiff =
|
|
282
|
-
rewriteUrl.pathname.replace(
|
|
283
|
-
originalUrl.pathname,
|
|
284
|
-
''
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
url.basePath = `/${commerceUrl}`;
|
|
289
|
-
url.pathname = `/${
|
|
290
|
-
locale.length ? `${locale}/` : ''
|
|
291
|
-
}${currency}/${customRewriteUrlDiff}${
|
|
292
|
-
prettyUrl ?? pathnameWithoutLocale
|
|
293
|
-
}`.replace(/\/+/g, '/');
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
!req.middlewareParams.found &&
|
|
297
|
-
Settings.customNotFoundEnabled
|
|
298
|
-
) {
|
|
299
|
-
let pathname = url.pathname
|
|
300
|
-
.replace(/\/+$/, '')
|
|
301
|
-
.split('/');
|
|
302
|
-
url.pathname = url.pathname.replace(
|
|
303
|
-
pathname.pop(),
|
|
304
|
-
'pz-not-found'
|
|
220
|
+
);
|
|
221
|
+
const originalUrl = new URL(req.url);
|
|
222
|
+
customRewriteUrlDiff =
|
|
223
|
+
rewriteUrl.pathname.replace(
|
|
224
|
+
originalUrl.pathname,
|
|
225
|
+
''
|
|
305
226
|
);
|
|
306
|
-
|
|
227
|
+
}
|
|
307
228
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
229
|
+
url.basePath = `/${commerceUrl}`;
|
|
230
|
+
url.pathname = `/${
|
|
231
|
+
locale.length ? `${locale}/` : ''
|
|
232
|
+
}${currency}/${customRewriteUrlDiff}${
|
|
233
|
+
prettyUrl ?? pathnameWithoutLocale
|
|
234
|
+
}`.replace(/\/+/g, '/');
|
|
235
|
+
|
|
236
|
+
if (
|
|
237
|
+
Settings.usePrettyUrlRoute &&
|
|
238
|
+
url.searchParams.toString().length > 0 &&
|
|
239
|
+
!Object.entries(ROUTES).find(([, value]) =>
|
|
240
|
+
new RegExp(`^${value}/?$`).test(
|
|
241
|
+
pathnameWithoutLocale
|
|
315
242
|
)
|
|
316
|
-
)
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
url.pathname = url.pathname.replace(
|
|
324
|
-
rewrite.source,
|
|
325
|
-
rewrite.destination
|
|
326
|
-
);
|
|
327
|
-
});
|
|
243
|
+
)
|
|
244
|
+
) {
|
|
245
|
+
url.pathname =
|
|
246
|
+
url.pathname +
|
|
247
|
+
(/\/$/.test(url.pathname) ? '' : '/') +
|
|
248
|
+
`searchparams|${url.searchParams.toString()}`;
|
|
249
|
+
}
|
|
328
250
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
} else if (
|
|
342
|
-
middlewareResult.headers.get(
|
|
343
|
-
'x-middleware-rewrite'
|
|
344
|
-
) &&
|
|
345
|
-
middlewareResult.headers.get(
|
|
346
|
-
'pz-override-response'
|
|
347
|
-
) === 'true'
|
|
348
|
-
) {
|
|
349
|
-
middlewareResult = NextResponse.rewrite(url);
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
// if middleware.ts doesn't have a return value.
|
|
353
|
-
// e.g. NextResponse.next() doesn't exist in middleware.ts
|
|
251
|
+
if (
|
|
252
|
+
!req.middlewareParams.found &&
|
|
253
|
+
Settings.customNotFoundEnabled
|
|
254
|
+
) {
|
|
255
|
+
let pathname = url.pathname
|
|
256
|
+
.replace(/\/+$/, '')
|
|
257
|
+
.split('/');
|
|
258
|
+
url.pathname = url.pathname.replace(
|
|
259
|
+
pathname.pop(),
|
|
260
|
+
'pz-not-found'
|
|
261
|
+
);
|
|
262
|
+
}
|
|
354
263
|
|
|
355
|
-
|
|
356
|
-
|
|
264
|
+
Settings.rewrites.forEach((rewrite) => {
|
|
265
|
+
url.pathname = url.pathname.replace(
|
|
266
|
+
rewrite.source,
|
|
267
|
+
rewrite.destination
|
|
268
|
+
);
|
|
269
|
+
});
|
|
357
270
|
|
|
271
|
+
// if middleware.ts has a return value for current url
|
|
272
|
+
if (middlewareResult instanceof NextResponse) {
|
|
273
|
+
// pz-override-response header is used to prevent 404 page for custom responses.
|
|
358
274
|
if (
|
|
359
|
-
|
|
275
|
+
middlewareResult.headers.get(
|
|
276
|
+
'pz-override-response'
|
|
277
|
+
) !== 'true'
|
|
360
278
|
) {
|
|
361
|
-
middlewareResult.
|
|
362
|
-
'
|
|
363
|
-
|
|
364
|
-
? locale
|
|
365
|
-
: defaultLocaleValue,
|
|
366
|
-
{
|
|
367
|
-
sameSite: 'none',
|
|
368
|
-
secure: true,
|
|
369
|
-
expires: new Date(
|
|
370
|
-
Date.now() + 1000 * 60 * 60 * 24 * 7
|
|
371
|
-
) // 7 days
|
|
372
|
-
}
|
|
279
|
+
middlewareResult.headers.set(
|
|
280
|
+
'x-middleware-rewrite',
|
|
281
|
+
url.href
|
|
373
282
|
);
|
|
283
|
+
} else if (
|
|
284
|
+
middlewareResult.headers.get(
|
|
285
|
+
'x-middleware-rewrite'
|
|
286
|
+
) &&
|
|
287
|
+
middlewareResult.headers.get(
|
|
288
|
+
'pz-override-response'
|
|
289
|
+
) === 'true'
|
|
290
|
+
) {
|
|
291
|
+
middlewareResult = NextResponse.rewrite(url);
|
|
374
292
|
}
|
|
293
|
+
} else {
|
|
294
|
+
// if middleware.ts doesn't have a return value.
|
|
295
|
+
// e.g. NextResponse.next() doesn't exist in middleware.ts
|
|
296
|
+
|
|
297
|
+
middlewareResult = NextResponse.rewrite(url);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (
|
|
301
|
+
!url.pathname.startsWith(`/${currency}/orders`)
|
|
302
|
+
) {
|
|
375
303
|
middlewareResult.cookies.set(
|
|
376
|
-
'pz-
|
|
377
|
-
|
|
304
|
+
'pz-locale',
|
|
305
|
+
locale?.length > 0
|
|
306
|
+
? locale
|
|
307
|
+
: defaultLocaleValue,
|
|
378
308
|
{
|
|
379
309
|
sameSite: 'none',
|
|
380
310
|
secure: true,
|
|
@@ -383,65 +313,76 @@ const withPzDefault =
|
|
|
383
313
|
) // 7 days
|
|
384
314
|
}
|
|
385
315
|
);
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
316
|
+
}
|
|
317
|
+
middlewareResult.cookies.set(
|
|
318
|
+
'pz-currency',
|
|
319
|
+
currency,
|
|
320
|
+
{
|
|
321
|
+
sameSite: 'none',
|
|
322
|
+
secure: true,
|
|
323
|
+
expires: new Date(
|
|
324
|
+
Date.now() + 1000 * 60 * 60 * 24 * 7
|
|
325
|
+
) // 7 days
|
|
396
326
|
}
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
if (
|
|
330
|
+
req.cookies.get('pz-locale') &&
|
|
331
|
+
req.cookies.get('pz-locale').value !== locale
|
|
332
|
+
) {
|
|
333
|
+
logger.debug('Locale changed', {
|
|
334
|
+
locale,
|
|
335
|
+
oldLocale: req.cookies.get('pz-locale')?.value,
|
|
336
|
+
ip
|
|
337
|
+
});
|
|
338
|
+
}
|
|
397
339
|
|
|
340
|
+
middlewareResult.headers.set(
|
|
341
|
+
'pz-url',
|
|
342
|
+
req.nextUrl.toString()
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
if (req.cookies.get('pz-set-currency')) {
|
|
346
|
+
middlewareResult.cookies.delete(
|
|
347
|
+
'pz-set-currency'
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (process.env.ACC_APP_VERSION) {
|
|
398
352
|
middlewareResult.headers.set(
|
|
399
|
-
'
|
|
400
|
-
|
|
353
|
+
'acc-app-version',
|
|
354
|
+
process.env.ACC_APP_VERSION
|
|
401
355
|
);
|
|
356
|
+
}
|
|
402
357
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
);
|
|
407
|
-
}
|
|
358
|
+
// Set CSRF token if not set
|
|
359
|
+
try {
|
|
360
|
+
const url = `${Settings.commerceUrl}${user.csrfToken}`;
|
|
408
361
|
|
|
409
|
-
if (
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
362
|
+
if (!req.cookies.get('csrftoken')) {
|
|
363
|
+
const { csrf_token } = await (
|
|
364
|
+
await fetch(url)
|
|
365
|
+
).json();
|
|
366
|
+
middlewareResult.cookies.set(
|
|
367
|
+
'csrftoken',
|
|
368
|
+
csrf_token
|
|
413
369
|
);
|
|
414
370
|
}
|
|
415
|
-
|
|
416
|
-
// Set CSRF token if not set
|
|
417
|
-
try {
|
|
418
|
-
const url = `${Settings.commerceUrl}${user.csrfToken}`;
|
|
419
|
-
|
|
420
|
-
if (!req.cookies.get('csrftoken')) {
|
|
421
|
-
const { csrf_token } = await (
|
|
422
|
-
await fetch(url)
|
|
423
|
-
).json();
|
|
424
|
-
middlewareResult.cookies.set(
|
|
425
|
-
'csrftoken',
|
|
426
|
-
csrf_token
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
} catch (error) {
|
|
430
|
-
logger.error('CSRF Error', {
|
|
431
|
-
error,
|
|
432
|
-
ip
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
371
|
} catch (error) {
|
|
436
|
-
logger.error('
|
|
372
|
+
logger.error('CSRF Error', {
|
|
437
373
|
error,
|
|
438
374
|
ip
|
|
439
375
|
});
|
|
440
376
|
}
|
|
441
|
-
|
|
442
|
-
|
|
377
|
+
} catch (error) {
|
|
378
|
+
logger.error('withPzDefault Error', {
|
|
379
|
+
error,
|
|
380
|
+
ip
|
|
381
|
+
});
|
|
443
382
|
}
|
|
444
|
-
|
|
383
|
+
|
|
384
|
+
return middlewareResult;
|
|
385
|
+
}
|
|
445
386
|
)
|
|
446
387
|
)
|
|
447
388
|
)
|
package/middlewares/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import withUrlRedirection from './url-redirection';
|
|
|
8
8
|
import withCompleteGpay from './complete-gpay';
|
|
9
9
|
import withCompleteMasterpass from './complete-masterpass';
|
|
10
10
|
import withCheckoutProvider from './checkout-provider';
|
|
11
|
-
import withSavedCardRedirection from './saved-card-redirection';
|
|
12
11
|
import { NextRequest } from 'next/server';
|
|
13
12
|
|
|
14
13
|
export {
|
|
@@ -21,8 +20,7 @@ export {
|
|
|
21
20
|
withUrlRedirection,
|
|
22
21
|
withCompleteGpay,
|
|
23
22
|
withCompleteMasterpass,
|
|
24
|
-
withCheckoutProvider
|
|
25
|
-
withSavedCardRedirection
|
|
23
|
+
withCheckoutProvider
|
|
26
24
|
};
|
|
27
25
|
|
|
28
26
|
export interface PzNextRequest extends NextRequest {
|
|
@@ -58,12 +58,7 @@ const withOauthLogin =
|
|
|
58
58
|
return middleware(req, event);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
req.cookies.get('messages')?.value.includes('Successfully signed in') ||
|
|
65
|
-
(currentSessionId && req.cookies.get('messages'))
|
|
66
|
-
) {
|
|
61
|
+
if (req.cookies.get('messages')?.value.includes('Successfully signed in')) {
|
|
67
62
|
let redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
68
63
|
'/auth/oauth-login',
|
|
69
64
|
req.cookies.get('pz-locale')?.value
|
|
@@ -43,14 +43,9 @@ const resolvePrettyUrlHandler =
|
|
|
43
43
|
return prettyUrlResult;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const resolvePrettyUrl = async (
|
|
47
|
-
pathname: string,
|
|
48
|
-
locale: string,
|
|
49
|
-
ip: string | null
|
|
50
|
-
) => {
|
|
46
|
+
const resolvePrettyUrl = async (pathname: string, ip: string | null) => {
|
|
51
47
|
return Cache.wrap(
|
|
52
48
|
CacheKey.PrettyUrl(pathname),
|
|
53
|
-
locale,
|
|
54
49
|
resolvePrettyUrlHandler(pathname, ip),
|
|
55
50
|
{
|
|
56
51
|
useProxy: true
|
|
@@ -93,7 +88,6 @@ const withPrettyUrl =
|
|
|
93
88
|
)
|
|
94
89
|
? url.pathname
|
|
95
90
|
: prettyUrlPathname,
|
|
96
|
-
matchedLanguagePrefix,
|
|
97
91
|
ip
|
|
98
92
|
);
|
|
99
93
|
|
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.60.0
|
|
4
|
+
"version": "1.60.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"set-cookie-parser": "2.6.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@akinon/eslint-plugin-projectzero": "1.60.0
|
|
33
|
+
"@akinon/eslint-plugin-projectzero": "1.60.0",
|
|
34
34
|
"@types/react-redux": "7.1.30",
|
|
35
35
|
"@types/set-cookie-parser": "2.4.7",
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
package/plugins.d.ts
CHANGED
|
@@ -21,10 +21,4 @@ declare module '@akinon/pz-otp' {
|
|
|
21
21
|
|
|
22
22
|
declare module '@akinon/pz-otp/src/redux/reducer' {
|
|
23
23
|
export const showPopup: any;
|
|
24
|
-
export const hidePopup: any;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare module '@akinon/pz-saved-card' {
|
|
28
|
-
export const savedCardReducer: any;
|
|
29
|
-
export const SavedCardOption: any;
|
|
30
24
|
}
|