@akinon/next 1.26.0 → 1.27.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.27.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9b48372: ZERO-2564:fix eslint shortland warning
8
+ - 7e41bdc: BRDG-9158: Remove redirect-three-d page endpoint
9
+ - 1289982: ZERO-2521: Add x-forwarded-for header to requests
10
+ - d6d2533: ZERO-2560: Add installment count to masterpass payment forms
11
+
3
12
  ## 1.26.0
4
13
 
5
14
  ### Minor Changes
package/api/auth.ts CHANGED
@@ -80,14 +80,21 @@ const nextAuthOptions = (req: NextApiRequest, res: NextApiResponse) => {
80
80
  const language = Settings.localization.locales.find(
81
81
  (item) => item.value === credentials.locale
82
82
  ).apiValue;
83
+ const userIp = req.headers['x-forwarded-for']?.toString() ?? '';
83
84
 
84
85
  headers.set('Content-Type', 'application/json');
85
86
  headers.set('cookie', `${req.headers.cookie}`);
86
87
  headers.set('Accept-Language', `${language}`);
87
88
  headers.set('x-currency', req.cookies['pz-currency'] ?? '');
89
+ headers.set('x-forwarded-for', userIp);
90
+ headers.set(
91
+ 'x-app-device',
92
+ req.headers['x-app-device']?.toString() ?? ''
93
+ );
88
94
 
89
95
  logger.debug('Trying to login/register', {
90
- formType: credentials.formType
96
+ formType: credentials.formType,
97
+ userIp
91
98
  });
92
99
 
93
100
  const apiRequest = await fetch(
@@ -99,7 +106,9 @@ const nextAuthOptions = (req: NextApiRequest, res: NextApiResponse) => {
99
106
  }
100
107
  );
101
108
 
102
- logger.info(`Login/Register request result: ${apiRequest.status}`);
109
+ logger.info(`Login/Register request result: ${apiRequest.status}`, {
110
+ userIp
111
+ });
103
112
 
104
113
  const response = (await apiRequest.json()) as {
105
114
  key: string;
package/api/client.ts CHANGED
@@ -51,7 +51,6 @@ async function proxyRequest(...args) {
51
51
 
52
52
  [
53
53
  'x-forwarded-host',
54
- 'x-forwarded-for',
55
54
  'x-forwarded-proto',
56
55
  'x-forwarded-port',
57
56
  'x-requested-with',
@@ -103,7 +103,8 @@ const completeMasterpassPayment = async (
103
103
  merchantId: credentials?.merchant_id ?? null,
104
104
  msisdn,
105
105
  amount: preOrder?.unpaid_amount?.replace('.', '') ?? '',
106
- additionalParams: additionalParams ?? extras?.additionalParams
106
+ additionalParams: additionalParams ?? extras?.additionalParams,
107
+ installmentCount: preOrder?.installment?.installment_count ?? 1
107
108
  };
108
109
 
109
110
  const form = isDirectPurchase
@@ -43,7 +43,8 @@ const withCompleteGpay =
43
43
  'X-Requested-With': 'XMLHttpRequest',
44
44
  'Content-Type': 'application/x-www-form-urlencoded',
45
45
  Cookie: `osessionid=${req.cookies.get('osessionid')?.value ?? ''}`,
46
- 'x-currency': req.cookies.get('pz-currency')?.value ?? ''
46
+ 'x-currency': req.cookies.get('pz-currency')?.value ?? '',
47
+ 'x-forwarded-for': ip
47
48
  };
48
49
 
49
50
  try {
@@ -43,7 +43,8 @@ const withCompleteMasterpass =
43
43
  'X-Requested-With': 'XMLHttpRequest',
44
44
  'Content-Type': 'application/x-www-form-urlencoded',
45
45
  Cookie: `osessionid=${req.cookies.get('osessionid')?.value ?? ''}`,
46
- 'x-currency': req.cookies.get('pz-currency')?.value ?? ''
46
+ 'x-currency': req.cookies.get('pz-currency')?.value ?? '',
47
+ 'x-forwarded-for': ip
47
48
  };
48
49
 
49
50
  try {
@@ -97,6 +97,12 @@ const withPzDefault =
97
97
  );
98
98
  }
99
99
 
100
+ if (req.nextUrl.pathname.includes('/orders/redirect-three-d')) {
101
+ return NextResponse.rewrite(
102
+ new URL(`${encodeURI(Settings.commerceUrl)}/orders/redirect-three-d/`)
103
+ );
104
+ }
105
+
100
106
  // If commerce redirects to /orders/checkout/ without locale
101
107
  if (
102
108
  req.nextUrl.pathname.match(new RegExp('^/orders/checkout/$')) &&
@@ -133,7 +139,8 @@ const withPzDefault =
133
139
  Cookie: req.headers.get('cookie') || '',
134
140
  Accept: 'application/json',
135
141
  'Content-Type': 'application/json',
136
- 'X-Requested-With': 'XMLHttpRequest'
142
+ 'X-Requested-With': 'XMLHttpRequest',
143
+ 'x-forwarded-for': ip
137
144
  }
138
145
  }
139
146
  );
@@ -15,11 +15,13 @@ const withOauthLogin =
15
15
  const loginCallbackUrlMatcherRegex = new RegExp(
16
16
  /^\/(\w+)\/login\/callback\/?$/
17
17
  );
18
+ const ip = req.headers.get('x-forwarded-for') ?? '';
18
19
 
19
20
  const headers = {
20
21
  'x-forwarded-host':
21
22
  req.headers.get('x-forwarded-host') || req.headers.get('host') || '',
22
- 'x-currency': req.cookies.get('pz-currency')?.value ?? ''
23
+ 'x-currency': req.cookies.get('pz-currency')?.value ?? '',
24
+ 'x-forwarded-for': ip
23
25
  };
24
26
 
25
27
  if (loginUrlMatcherRegex.test(url.pathname)) {
@@ -44,7 +44,9 @@ const withRedirectionPayment =
44
44
  'X-Requested-With': 'XMLHttpRequest',
45
45
  'Content-Type': 'application/x-www-form-urlencoded',
46
46
  Cookie: req.headers.get('cookie') ?? '',
47
- 'x-currency': req.cookies.get('pz-currency')?.value ?? ''
47
+ 'x-currency': req.cookies.get('pz-currency')?.value ?? '',
48
+ 'x-forwarded-for': ip
49
+
48
50
  };
49
51
 
50
52
  try {
@@ -43,7 +43,8 @@ const withThreeDRedirection =
43
43
  'X-Requested-With': 'XMLHttpRequest',
44
44
  'Content-Type': 'application/x-www-form-urlencoded',
45
45
  Cookie: `osessionid=${req.cookies.get('osessionid')?.value ?? ''}`,
46
- 'x-currency': req.cookies.get('pz-currency')?.value ?? ''
46
+ 'x-currency': req.cookies.get('pz-currency')?.value ?? '',
47
+ 'x-forwarded-for': ip
47
48
  };
48
49
 
49
50
  try {
@@ -31,6 +31,9 @@ const withUrlRedirection =
31
31
  const request = await fetch(
32
32
  `${settings.commerceUrl}${pathnameWithoutLocale}${url.search}`,
33
33
  {
34
+ headers: {
35
+ 'x-forwarded-for': ip
36
+ },
34
37
  redirect: 'manual',
35
38
  next: {
36
39
  revalidate: 0
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.26.0",
4
+ "version": "1.27.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -36,7 +36,8 @@ const appFetch = async <T>(
36
36
  init.headers = {
37
37
  ...(init.headers ?? {}),
38
38
  'Accept-Language': currentLocale.apiValue,
39
- 'x-currency': ServerVariables.currency
39
+ 'x-currency': ServerVariables.currency,
40
+ 'x-forwarded-for': ip
40
41
  };
41
42
 
42
43
  init.next = {
package/utils/log.ts CHANGED
@@ -85,9 +85,9 @@ function createCustomSpan({ level, message, payload }: Message) {
85
85
  const span = tracer.startSpan('custom-operation-log');
86
86
 
87
87
  span.setAttributes({
88
- level: level,
89
- message: message,
90
- payload: payload
88
+ level,
89
+ message,
90
+ payload
91
91
  });
92
92
 
93
93
  span.end();
@@ -1,74 +0,0 @@
1
- 'use client';
2
-
3
- import { useEffect, useState } from 'react';
4
- import { ROUTES } from 'routes';
5
- import { useGet3dRedirectFormQuery } from '@akinon/next/data/client/checkout';
6
- import { LoaderSpinner } from 'components';
7
- import { useLocalization } from '../../../hooks/use-localization';
8
- import { getUrlPathWithLocale } from '../../../utils/localization';
9
- import { useSearchParams } from 'next/navigation';
10
-
11
- interface RedirectThreeDContentProps {
12
- sessionId: string;
13
- }
14
-
15
- export default function RedirectThreeDContent({
16
- sessionId
17
- }: RedirectThreeDContentProps) {
18
- const searchParams = useSearchParams();
19
- const { data } = useGet3dRedirectFormQuery();
20
- const [error, setError] = useState(null);
21
- const { locale } = useLocalization();
22
-
23
- useEffect(() => {
24
- if (data) {
25
- const fragment = document.createElement('fragment');
26
- fragment.innerHTML = data.result;
27
-
28
- const form = fragment.querySelector('form');
29
-
30
- // a way to determine if response includes a redirection form or not
31
- if (fragment.querySelector('link[rel="canonical"]') || !form) {
32
- setError('Redirecting to checkout page. Please wait...');
33
-
34
- setTimeout(() => {
35
- let checkoutUrl = `${ROUTES.CHECKOUT}`;
36
-
37
- // iframe param is used to prevent header and footer rendering
38
- if (searchParams.get('iframe') === 'true') {
39
- checkoutUrl = `${checkoutUrl}?iframe=true`;
40
- }
41
-
42
- // Use `window.location.href` instead of `router.push`
43
- // to capture the url change event in iframe
44
- location.href = getUrlPathWithLocale(checkoutUrl, locale);
45
- }, 3000);
46
- return;
47
- }
48
-
49
- const pzParamsInput = document.createElement('input');
50
- pzParamsInput.setAttribute('type', 'hidden');
51
- pzParamsInput.setAttribute('name', 'pzparams');
52
- pzParamsInput.setAttribute(
53
- 'value',
54
- encodeURIComponent(
55
- JSON.stringify({
56
- session: sessionId,
57
- locale
58
- })
59
- )
60
- );
61
- form.appendChild(pzParamsInput);
62
-
63
- form.style.display = 'none';
64
- document.body.appendChild(form);
65
- form.submit();
66
- }
67
- }, [data]);
68
-
69
- return (
70
- <div className="flex items-center justify-center py-20">
71
- {error ?? <LoaderSpinner />}
72
- </div>
73
- );
74
- }
@@ -1,17 +0,0 @@
1
- import { cookies } from 'next/headers';
2
- import { redirect } from 'next/navigation';
3
- import RedirectThreeDContent from './content';
4
- import { ROUTES } from 'routes';
5
-
6
- const RedirectThreeD = async () => {
7
- const nextCookies = cookies();
8
- const sessionId = await nextCookies.get('osessionid')?.value;
9
-
10
- if (!sessionId) {
11
- return redirect(ROUTES.CHECKOUT);
12
- }
13
-
14
- return <RedirectThreeDContent sessionId={sessionId} />;
15
- };
16
-
17
- export default RedirectThreeD;