@akinon/next 1.93.0 → 1.95.0-rc.54
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 +1252 -24
- package/__tests__/next-config.test.ts +1 -10
- package/__tests__/redirect.test.ts +319 -0
- package/api/image-proxy.ts +75 -0
- package/api/similar-product-list.ts +84 -0
- package/api/similar-products.ts +120 -0
- package/components/accordion.tsx +20 -5
- package/components/file-input.tsx +65 -3
- package/components/input.tsx +2 -0
- package/components/link.tsx +16 -12
- package/components/modal.tsx +32 -16
- package/components/plugin-module.tsx +35 -3
- package/components/selected-payment-option-view.tsx +11 -0
- package/data/client/checkout.ts +25 -4
- package/data/server/basket.ts +72 -0
- package/data/server/category.ts +48 -28
- package/data/server/flatpage.ts +16 -12
- package/data/server/landingpage.ts +16 -12
- package/data/server/list.ts +23 -13
- package/data/server/product.ts +66 -39
- package/data/server/special-page.ts +16 -12
- package/data/urls.ts +7 -2
- package/hocs/server/with-segment-defaults.tsx +5 -2
- package/hooks/use-localization.ts +2 -3
- package/hooks/use-loyalty-availability.ts +21 -0
- package/instrumentation/node.ts +15 -13
- package/jest.config.js +7 -1
- package/lib/cache.ts +2 -0
- package/middlewares/checkout-provider.ts +1 -1
- package/middlewares/complete-gpay.ts +6 -2
- package/middlewares/complete-masterpass.ts +7 -2
- package/middlewares/default.ts +232 -183
- package/middlewares/index.ts +3 -1
- package/middlewares/locale.ts +9 -1
- package/middlewares/redirection-payment.ts +6 -2
- package/middlewares/saved-card-redirection.ts +7 -2
- package/middlewares/three-d-redirection.ts +7 -2
- package/middlewares/url-redirection.ts +9 -15
- package/middlewares/wallet-complete-redirection.ts +203 -0
- package/package.json +3 -3
- package/plugins.d.ts +10 -0
- package/plugins.js +4 -1
- package/redux/middlewares/checkout.ts +15 -2
- package/redux/reducers/checkout.ts +9 -1
- package/sentry/index.ts +54 -17
- package/types/commerce/order.ts +1 -0
- package/types/index.ts +42 -1
- package/utils/app-fetch.ts +7 -2
- package/utils/index.ts +34 -10
- package/utils/redirect-ignore.ts +35 -0
- package/utils/redirect.ts +31 -6
- package/with-pz-config.js +1 -5
package/middlewares/default.ts
CHANGED
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
withRedirectionPayment,
|
|
12
12
|
withSavedCardRedirection,
|
|
13
13
|
withThreeDRedirection,
|
|
14
|
-
withUrlRedirection
|
|
14
|
+
withUrlRedirection,
|
|
15
|
+
withWalletCompleteRedirection
|
|
15
16
|
} from '.';
|
|
16
17
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
17
18
|
import withCurrency from './currency';
|
|
@@ -228,144 +229,173 @@ const withPzDefault =
|
|
|
228
229
|
withCompleteGpay(
|
|
229
230
|
withCompleteMasterpass(
|
|
230
231
|
withSavedCardRedirection(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
let customRewriteUrlDiff = '';
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
middlewareResult instanceof NextResponse &&
|
|
253
|
-
middlewareResult.headers.get(
|
|
254
|
-
'pz-override-response'
|
|
255
|
-
) &&
|
|
256
|
-
middlewareResult.headers.get(
|
|
257
|
-
'x-middleware-rewrite'
|
|
258
|
-
)
|
|
259
|
-
) {
|
|
260
|
-
const rewriteUrl = new URL(
|
|
261
|
-
middlewareResult.headers.get(
|
|
262
|
-
'x-middleware-rewrite'
|
|
263
|
-
)
|
|
264
|
-
);
|
|
265
|
-
const originalUrl = new URL(req.url);
|
|
266
|
-
customRewriteUrlDiff =
|
|
267
|
-
rewriteUrl.pathname.replace(
|
|
268
|
-
originalUrl.pathname,
|
|
232
|
+
withWalletCompleteRedirection(
|
|
233
|
+
async (
|
|
234
|
+
req: PzNextRequest,
|
|
235
|
+
event: NextFetchEvent
|
|
236
|
+
) => {
|
|
237
|
+
let middlewareResult: NextResponse | void =
|
|
238
|
+
NextResponse.next();
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
const { locale, prettyUrl, currency } =
|
|
242
|
+
req.middlewareParams.rewrites;
|
|
243
|
+
const { defaultLocaleValue } =
|
|
244
|
+
Settings.localization;
|
|
245
|
+
const url = req.nextUrl.clone();
|
|
246
|
+
const pathnameWithoutLocale =
|
|
247
|
+
url.pathname.replace(
|
|
248
|
+
urlLocaleMatcherRegex,
|
|
269
249
|
''
|
|
270
250
|
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
url.basePath = `/${commerceUrl}`;
|
|
274
|
-
url.pathname = `/${
|
|
275
|
-
locale.length ? `${locale}/` : ''
|
|
276
|
-
}${currency}/${customRewriteUrlDiff}${
|
|
277
|
-
prettyUrl ?? pathnameWithoutLocale
|
|
278
|
-
}`.replace(/\/+/g, '/');
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
Settings.usePrettyUrlRoute &&
|
|
282
|
-
url.searchParams.toString().length > 0 &&
|
|
283
|
-
!Object.entries(ROUTES).find(([, value]) =>
|
|
284
|
-
new RegExp(`^${value}/?$`).test(
|
|
285
|
-
pathnameWithoutLocale
|
|
286
|
-
)
|
|
287
|
-
)
|
|
288
|
-
) {
|
|
289
|
-
url.pathname =
|
|
290
|
-
url.pathname +
|
|
291
|
-
(/\/$/.test(url.pathname) ? '' : '/') +
|
|
292
|
-
`searchparams|${encodeURIComponent(
|
|
293
|
-
url.searchParams.toString()
|
|
294
|
-
)}`;
|
|
295
|
-
}
|
|
296
251
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const pathname = url.pathname
|
|
302
|
-
.replace(/\/+$/, '')
|
|
303
|
-
.split('/');
|
|
304
|
-
url.pathname = url.pathname.replace(
|
|
305
|
-
pathname.pop(),
|
|
306
|
-
'pz-not-found'
|
|
307
|
-
);
|
|
308
|
-
}
|
|
252
|
+
middlewareResult = (await middleware(
|
|
253
|
+
req,
|
|
254
|
+
event
|
|
255
|
+
)) as NextResponse | void;
|
|
309
256
|
|
|
310
|
-
|
|
311
|
-
url.pathname = url.pathname.replace(
|
|
312
|
-
rewrite.source,
|
|
313
|
-
rewrite.destination
|
|
314
|
-
);
|
|
315
|
-
});
|
|
257
|
+
let customRewriteUrlDiff = '';
|
|
316
258
|
|
|
317
|
-
// if middleware.ts has a return value for current url
|
|
318
|
-
if (middlewareResult instanceof NextResponse) {
|
|
319
|
-
// pz-override-response header is used to prevent 404 page for custom responses.
|
|
320
259
|
if (
|
|
260
|
+
middlewareResult instanceof NextResponse &&
|
|
321
261
|
middlewareResult.headers.get(
|
|
322
262
|
'pz-override-response'
|
|
323
|
-
) !== 'true'
|
|
324
|
-
) {
|
|
325
|
-
middlewareResult.headers.set(
|
|
326
|
-
'x-middleware-rewrite',
|
|
327
|
-
url.href
|
|
328
|
-
);
|
|
329
|
-
} else if (
|
|
330
|
-
middlewareResult.headers.get(
|
|
331
|
-
'x-middleware-rewrite'
|
|
332
263
|
) &&
|
|
333
264
|
middlewareResult.headers.get(
|
|
334
|
-
'
|
|
335
|
-
)
|
|
265
|
+
'x-middleware-rewrite'
|
|
266
|
+
)
|
|
267
|
+
) {
|
|
268
|
+
const rewriteUrl = new URL(
|
|
269
|
+
middlewareResult.headers.get(
|
|
270
|
+
'x-middleware-rewrite'
|
|
271
|
+
)
|
|
272
|
+
);
|
|
273
|
+
const originalUrl = new URL(req.url);
|
|
274
|
+
customRewriteUrlDiff =
|
|
275
|
+
rewriteUrl.pathname.replace(
|
|
276
|
+
originalUrl.pathname,
|
|
277
|
+
''
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
url.basePath = `/${commerceUrl}`;
|
|
282
|
+
url.pathname = `/${
|
|
283
|
+
locale.length ? `${locale}/` : ''
|
|
284
|
+
}${currency}/${customRewriteUrlDiff}${
|
|
285
|
+
prettyUrl ?? pathnameWithoutLocale
|
|
286
|
+
}`.replace(/\/+/g, '/');
|
|
287
|
+
|
|
288
|
+
if (
|
|
289
|
+
Settings.usePrettyUrlRoute &&
|
|
290
|
+
url.searchParams.toString().length > 0 &&
|
|
291
|
+
!Object.entries(ROUTES).find(([, value]) =>
|
|
292
|
+
new RegExp(`^${value}/?$`).test(
|
|
293
|
+
pathnameWithoutLocale
|
|
294
|
+
)
|
|
295
|
+
)
|
|
336
296
|
) {
|
|
297
|
+
url.pathname =
|
|
298
|
+
url.pathname +
|
|
299
|
+
(/\/$/.test(url.pathname) ? '' : '/') +
|
|
300
|
+
`searchparams|${encodeURIComponent(
|
|
301
|
+
url.searchParams.toString()
|
|
302
|
+
)}`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
Settings.rewrites.forEach((rewrite) => {
|
|
306
|
+
url.pathname = url.pathname.replace(
|
|
307
|
+
rewrite.source,
|
|
308
|
+
rewrite.destination
|
|
309
|
+
);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// if middleware.ts has a return value for current url
|
|
313
|
+
if (middlewareResult instanceof NextResponse) {
|
|
314
|
+
// pz-override-response header is used to prevent 404 page for custom responses.
|
|
315
|
+
if (
|
|
316
|
+
middlewareResult.headers.get(
|
|
317
|
+
'pz-override-response'
|
|
318
|
+
) !== 'true'
|
|
319
|
+
) {
|
|
320
|
+
middlewareResult.headers.set(
|
|
321
|
+
'x-middleware-rewrite',
|
|
322
|
+
url.href
|
|
323
|
+
);
|
|
324
|
+
} else if (
|
|
325
|
+
middlewareResult.headers.get(
|
|
326
|
+
'x-middleware-rewrite'
|
|
327
|
+
) &&
|
|
328
|
+
middlewareResult.headers.get(
|
|
329
|
+
'pz-override-response'
|
|
330
|
+
) === 'true'
|
|
331
|
+
) {
|
|
332
|
+
middlewareResult =
|
|
333
|
+
NextResponse.rewrite(url);
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
// if middleware.ts doesn't have a return value.
|
|
337
|
+
// e.g. NextResponse.next() doesn't exist in middleware.ts
|
|
338
|
+
|
|
337
339
|
middlewareResult = NextResponse.rewrite(url);
|
|
338
340
|
}
|
|
339
|
-
} else {
|
|
340
|
-
// if middleware.ts doesn't have a return value.
|
|
341
|
-
// e.g. NextResponse.next() doesn't exist in middleware.ts
|
|
342
341
|
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
if (
|
|
343
|
+
!req.middlewareParams.found &&
|
|
344
|
+
Settings.customNotFoundEnabled
|
|
345
|
+
) {
|
|
346
|
+
const pathSegments = url.pathname
|
|
347
|
+
.replace(/\/+$/, '')
|
|
348
|
+
.split('/');
|
|
349
|
+
if (pathSegments.length >= 3) {
|
|
350
|
+
url.pathname = `/${pathSegments[1]}/${pathSegments[2]}/pz-not-found`;
|
|
351
|
+
} else {
|
|
352
|
+
url.pathname = '/pz-not-found';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
middlewareResult = NextResponse.rewrite(url, {
|
|
356
|
+
status: 404
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const { localeUrlStrategy } =
|
|
361
|
+
Settings.localization;
|
|
362
|
+
|
|
363
|
+
const fallbackHost =
|
|
364
|
+
req.headers.get('x-forwarded-host') ||
|
|
365
|
+
req.headers.get('host');
|
|
366
|
+
const hostname =
|
|
367
|
+
process.env.NEXT_PUBLIC_URL ||
|
|
368
|
+
`https://${fallbackHost}`;
|
|
369
|
+
const rootHostname =
|
|
370
|
+
localeUrlStrategy ===
|
|
371
|
+
LocaleUrlStrategy.Subdomain
|
|
372
|
+
? getRootHostname(hostname)
|
|
373
|
+
: null;
|
|
374
|
+
|
|
375
|
+
if (
|
|
376
|
+
!url.pathname.startsWith(
|
|
377
|
+
`/${currency}/orders`
|
|
378
|
+
)
|
|
379
|
+
) {
|
|
380
|
+
middlewareResult.cookies.set(
|
|
381
|
+
'pz-locale',
|
|
382
|
+
locale?.length > 0
|
|
383
|
+
? locale
|
|
384
|
+
: defaultLocaleValue,
|
|
385
|
+
{
|
|
386
|
+
domain: rootHostname,
|
|
387
|
+
sameSite: 'none',
|
|
388
|
+
secure: true,
|
|
389
|
+
expires: new Date(
|
|
390
|
+
Date.now() + 1000 * 60 * 60 * 24 * 7
|
|
391
|
+
) // 7 days
|
|
392
|
+
}
|
|
393
|
+
);
|
|
394
|
+
}
|
|
345
395
|
|
|
346
|
-
const { localeUrlStrategy } =
|
|
347
|
-
Settings.localization;
|
|
348
|
-
|
|
349
|
-
const fallbackHost =
|
|
350
|
-
req.headers.get('x-forwarded-host') ||
|
|
351
|
-
req.headers.get('host');
|
|
352
|
-
const hostname =
|
|
353
|
-
process.env.NEXT_PUBLIC_URL ||
|
|
354
|
-
`https://${fallbackHost}`;
|
|
355
|
-
const rootHostname =
|
|
356
|
-
localeUrlStrategy ===
|
|
357
|
-
LocaleUrlStrategy.Subdomain
|
|
358
|
-
? getRootHostname(hostname)
|
|
359
|
-
: null;
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
!url.pathname.startsWith(`/${currency}/orders`)
|
|
363
|
-
) {
|
|
364
396
|
middlewareResult.cookies.set(
|
|
365
|
-
'pz-
|
|
366
|
-
|
|
367
|
-
? locale
|
|
368
|
-
: defaultLocaleValue,
|
|
397
|
+
'pz-currency',
|
|
398
|
+
currency,
|
|
369
399
|
{
|
|
370
400
|
domain: rootHostname,
|
|
371
401
|
sameSite: 'none',
|
|
@@ -375,82 +405,101 @@ const withPzDefault =
|
|
|
375
405
|
) // 7 days
|
|
376
406
|
}
|
|
377
407
|
);
|
|
378
|
-
}
|
|
379
408
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
409
|
+
if (
|
|
410
|
+
!url.pathname.startsWith(
|
|
411
|
+
`/${currency}/orders`
|
|
412
|
+
)
|
|
413
|
+
) {
|
|
414
|
+
const currentCookieLocale =
|
|
415
|
+
req.cookies.get('pz-locale')?.value;
|
|
416
|
+
|
|
417
|
+
const urlHasExplicitLocale =
|
|
418
|
+
url.pathname.match(urlLocaleMatcherRegex);
|
|
419
|
+
const shouldUpdateCookie =
|
|
420
|
+
!currentCookieLocale ||
|
|
421
|
+
urlHasExplicitLocale;
|
|
422
|
+
|
|
423
|
+
if (shouldUpdateCookie) {
|
|
424
|
+
middlewareResult.cookies.set(
|
|
425
|
+
'pz-locale',
|
|
426
|
+
locale?.length > 0
|
|
427
|
+
? locale
|
|
428
|
+
: defaultLocaleValue,
|
|
429
|
+
{
|
|
430
|
+
domain: rootHostname,
|
|
431
|
+
sameSite: 'none',
|
|
432
|
+
secure: true,
|
|
433
|
+
expires: new Date(
|
|
434
|
+
Date.now() + 1000 * 60 * 60 * 24 * 7
|
|
435
|
+
) // 7 days
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
}
|
|
390
439
|
}
|
|
391
|
-
);
|
|
392
|
-
|
|
393
|
-
if (
|
|
394
|
-
req.cookies.get('pz-locale') &&
|
|
395
|
-
req.cookies.get('pz-locale').value !== locale
|
|
396
|
-
) {
|
|
397
|
-
logger.debug('Locale changed', {
|
|
398
|
-
locale,
|
|
399
|
-
oldLocale:
|
|
400
|
-
req.cookies.get('pz-locale')?.value,
|
|
401
|
-
ip
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
440
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
441
|
+
if (
|
|
442
|
+
req.cookies.get('pz-locale') &&
|
|
443
|
+
req.cookies.get('pz-locale').value !== locale
|
|
444
|
+
) {
|
|
445
|
+
logger.debug('Locale changed', {
|
|
446
|
+
locale,
|
|
447
|
+
oldLocale:
|
|
448
|
+
req.cookies.get('pz-locale')?.value,
|
|
449
|
+
ip
|
|
450
|
+
});
|
|
451
|
+
}
|
|
415
452
|
|
|
416
|
-
if (process.env.ACC_APP_VERSION) {
|
|
417
453
|
middlewareResult.headers.set(
|
|
418
|
-
'
|
|
419
|
-
|
|
454
|
+
'pz-url',
|
|
455
|
+
req.nextUrl.toString()
|
|
420
456
|
);
|
|
421
|
-
}
|
|
422
457
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
458
|
+
if (req.cookies.get('pz-set-currency')) {
|
|
459
|
+
middlewareResult.cookies.delete(
|
|
460
|
+
'pz-set-currency'
|
|
461
|
+
);
|
|
462
|
+
}
|
|
426
463
|
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
middlewareResult.cookies.set(
|
|
432
|
-
'csrftoken',
|
|
433
|
-
csrf_token,
|
|
434
|
-
{
|
|
435
|
-
domain: rootHostname
|
|
436
|
-
}
|
|
464
|
+
if (process.env.ACC_APP_VERSION) {
|
|
465
|
+
middlewareResult.headers.set(
|
|
466
|
+
'acc-app-version',
|
|
467
|
+
process.env.ACC_APP_VERSION
|
|
437
468
|
);
|
|
438
469
|
}
|
|
470
|
+
|
|
471
|
+
// Set CSRF token if not set
|
|
472
|
+
try {
|
|
473
|
+
const url = `${Settings.commerceUrl}${user.csrfToken}`;
|
|
474
|
+
|
|
475
|
+
if (!req.cookies.get('csrftoken')) {
|
|
476
|
+
const { csrf_token } = await (
|
|
477
|
+
await fetch(url)
|
|
478
|
+
).json();
|
|
479
|
+
middlewareResult.cookies.set(
|
|
480
|
+
'csrftoken',
|
|
481
|
+
csrf_token,
|
|
482
|
+
{
|
|
483
|
+
domain: rootHostname
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
} catch (error) {
|
|
488
|
+
logger.error('CSRF Error', {
|
|
489
|
+
error,
|
|
490
|
+
ip
|
|
491
|
+
});
|
|
492
|
+
}
|
|
439
493
|
} catch (error) {
|
|
440
|
-
logger.error('
|
|
494
|
+
logger.error('withPzDefault Error', {
|
|
441
495
|
error,
|
|
442
496
|
ip
|
|
443
497
|
});
|
|
444
498
|
}
|
|
445
|
-
} catch (error) {
|
|
446
|
-
logger.error('withPzDefault Error', {
|
|
447
|
-
error,
|
|
448
|
-
ip
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
499
|
|
|
452
|
-
|
|
453
|
-
|
|
500
|
+
return middlewareResult;
|
|
501
|
+
}
|
|
502
|
+
)
|
|
454
503
|
)
|
|
455
504
|
)
|
|
456
505
|
)
|
package/middlewares/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import withCompleteGpay from './complete-gpay';
|
|
|
9
9
|
import withCompleteMasterpass from './complete-masterpass';
|
|
10
10
|
import withCheckoutProvider from './checkout-provider';
|
|
11
11
|
import withSavedCardRedirection from './saved-card-redirection';
|
|
12
|
+
import withWalletCompleteRedirection from './wallet-complete-redirection';
|
|
12
13
|
import { NextRequest } from 'next/server';
|
|
13
14
|
|
|
14
15
|
export {
|
|
@@ -22,7 +23,8 @@ export {
|
|
|
22
23
|
withCompleteGpay,
|
|
23
24
|
withCompleteMasterpass,
|
|
24
25
|
withCheckoutProvider,
|
|
25
|
-
withSavedCardRedirection
|
|
26
|
+
withSavedCardRedirection,
|
|
27
|
+
withWalletCompleteRedirection
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export interface PzNextRequest extends NextRequest {
|
package/middlewares/locale.ts
CHANGED
|
@@ -23,7 +23,15 @@ const getMatchedLocale = (pathname: string, req: PzNextRequest) => {
|
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
if (subDomainLocaleMatched && subDomainLocaleMatched[0]) {
|
|
26
|
-
|
|
26
|
+
const subdomainLocale = subDomainLocaleMatched[0].slice(1);
|
|
27
|
+
|
|
28
|
+
const isValidSubdomainLocale = settings.localization.locales.find(
|
|
29
|
+
(l) => l.value === subdomainLocale
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (isValidSubdomainLocale) {
|
|
33
|
+
matchedLocale = subdomainLocale;
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
}
|
|
29
37
|
}
|
|
@@ -35,6 +35,7 @@ const withRedirectionPayment =
|
|
|
35
35
|
const searchParams = new URLSearchParams(url.search);
|
|
36
36
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
37
37
|
const sessionId = req.cookies.get('osessionid');
|
|
38
|
+
const currentLocale = req.middlewareParams?.rewrites?.locale;
|
|
38
39
|
|
|
39
40
|
if (searchParams.get('page') !== 'RedirectionPageCompletePage') {
|
|
40
41
|
return middleware(req, event);
|
|
@@ -46,7 +47,9 @@ const withRedirectionPayment =
|
|
|
46
47
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
47
48
|
Cookie: req.headers.get('cookie') ?? '',
|
|
48
49
|
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
49
|
-
'x-forwarded-for': ip
|
|
50
|
+
'x-forwarded-for': ip,
|
|
51
|
+
'Accept-Language':
|
|
52
|
+
currentLocale ?? req.cookies.get('pz-locale')?.value ?? ''
|
|
50
53
|
};
|
|
51
54
|
|
|
52
55
|
try {
|
|
@@ -146,7 +149,8 @@ const withRedirectionPayment =
|
|
|
146
149
|
logger.info('Redirecting to order success page', {
|
|
147
150
|
middleware: 'redirection-payment',
|
|
148
151
|
redirectUrlWithLocale,
|
|
149
|
-
ip
|
|
152
|
+
ip,
|
|
153
|
+
setCookie: request.headers.get('set-cookie')
|
|
150
154
|
});
|
|
151
155
|
|
|
152
156
|
// Using POST method while redirecting causes an error,
|
|
@@ -4,6 +4,7 @@ import { Buffer } from 'buffer';
|
|
|
4
4
|
import logger from '../utils/log';
|
|
5
5
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
6
6
|
import { PzNextRequest } from '.';
|
|
7
|
+
import { ServerVariables } from '../utils/server-variables';
|
|
7
8
|
|
|
8
9
|
const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
|
|
9
10
|
if (stream) {
|
|
@@ -34,6 +35,7 @@ const withSavedCardRedirection =
|
|
|
34
35
|
const url = req.nextUrl.clone();
|
|
35
36
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
36
37
|
const sessionId = req.cookies.get('osessionid');
|
|
38
|
+
const currentLocale = req.middlewareParams?.rewrites?.locale;
|
|
37
39
|
|
|
38
40
|
if (url.search.indexOf('SavedCardThreeDSecurePage') === -1) {
|
|
39
41
|
return middleware(req, event);
|
|
@@ -45,7 +47,9 @@ const withSavedCardRedirection =
|
|
|
45
47
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
48
|
Cookie: req.headers.get('cookie') ?? '',
|
|
47
49
|
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
48
|
-
'x-forwarded-for': ip
|
|
50
|
+
'x-forwarded-for': ip,
|
|
51
|
+
'Accept-Language':
|
|
52
|
+
currentLocale ?? req.cookies.get('pz-locale')?.value ?? ''
|
|
49
53
|
};
|
|
50
54
|
|
|
51
55
|
try {
|
|
@@ -145,7 +149,8 @@ const withSavedCardRedirection =
|
|
|
145
149
|
logger.info('Redirecting to order success page', {
|
|
146
150
|
middleware: 'saved-card-redirection',
|
|
147
151
|
redirectUrlWithLocale,
|
|
148
|
-
ip
|
|
152
|
+
ip,
|
|
153
|
+
setCookie: request.headers.get('set-cookie')
|
|
149
154
|
});
|
|
150
155
|
|
|
151
156
|
// Using POST method while redirecting causes an error,
|
|
@@ -4,6 +4,7 @@ import { Buffer } from 'buffer';
|
|
|
4
4
|
import logger from '../utils/log';
|
|
5
5
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
6
6
|
import { PzNextRequest } from '.';
|
|
7
|
+
import { ServerVariables } from '../utils/server-variables';
|
|
7
8
|
|
|
8
9
|
const streamToString = async (stream: ReadableStream<Uint8Array> | null) => {
|
|
9
10
|
if (stream) {
|
|
@@ -34,6 +35,7 @@ const withThreeDRedirection =
|
|
|
34
35
|
const url = req.nextUrl.clone();
|
|
35
36
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
36
37
|
const sessionId = req.cookies.get('osessionid');
|
|
38
|
+
const currentLocale = req.middlewareParams?.rewrites?.locale;
|
|
37
39
|
|
|
38
40
|
if (url.search.indexOf('CreditCardThreeDSecurePage') === -1) {
|
|
39
41
|
return middleware(req, event);
|
|
@@ -45,7 +47,9 @@ const withThreeDRedirection =
|
|
|
45
47
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
46
48
|
Cookie: req.headers.get('cookie') ?? '',
|
|
47
49
|
'x-currency': req.cookies.get('pz-currency')?.value ?? '',
|
|
48
|
-
'x-forwarded-for': ip
|
|
50
|
+
'x-forwarded-for': ip,
|
|
51
|
+
'Accept-Language':
|
|
52
|
+
currentLocale ?? req.cookies.get('pz-locale')?.value ?? ''
|
|
49
53
|
};
|
|
50
54
|
|
|
51
55
|
try {
|
|
@@ -145,7 +149,8 @@ const withThreeDRedirection =
|
|
|
145
149
|
logger.info('Redirecting to order success page', {
|
|
146
150
|
middleware: 'three-d-redirection',
|
|
147
151
|
redirectUrlWithLocale,
|
|
148
|
-
ip
|
|
152
|
+
ip,
|
|
153
|
+
setCookie: request.headers.get('set-cookie')
|
|
149
154
|
});
|
|
150
155
|
|
|
151
156
|
// Using POST method while redirecting causes an error,
|
|
@@ -4,6 +4,7 @@ import { PzNextRequest } from '.';
|
|
|
4
4
|
import logger from '../utils/log';
|
|
5
5
|
import { urlLocaleMatcherRegex } from '../utils';
|
|
6
6
|
import { getUrlPathWithLocale } from '../utils/localization';
|
|
7
|
+
import { shouldIgnoreRedirect } from '../utils/redirect-ignore';
|
|
7
8
|
import { ROUTES } from 'routes';
|
|
8
9
|
|
|
9
10
|
// This middleware is used to handle url redirections set in Omnitron
|
|
@@ -50,7 +51,7 @@ const withUrlRedirection =
|
|
|
50
51
|
const location = request.headers.get('location');
|
|
51
52
|
const redirectUrl = new URL(
|
|
52
53
|
request.headers.get('location'),
|
|
53
|
-
location.startsWith('http') ? '' :
|
|
54
|
+
location.startsWith('http') ? '' : url.origin
|
|
54
55
|
);
|
|
55
56
|
|
|
56
57
|
redirectUrl.pathname = getUrlPathWithLocale(
|
|
@@ -60,20 +61,13 @@ const withUrlRedirection =
|
|
|
60
61
|
|
|
61
62
|
const setCookies = request.headers.getSetCookie();
|
|
62
63
|
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
if (shouldIgnoreRedirect) {
|
|
75
|
-
return middleware(req, event);
|
|
76
|
-
}
|
|
64
|
+
if (
|
|
65
|
+
shouldIgnoreRedirect(
|
|
66
|
+
url.pathname,
|
|
67
|
+
req.middlewareParams.rewrites.locale
|
|
68
|
+
)
|
|
69
|
+
) {
|
|
70
|
+
return middleware(req, event);
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
const response = NextResponse.redirect(redirectUrl.toString(), {
|