@akinon/next 1.116.0-rc.1 → 1.116.0-rc.11
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 +36 -0
- package/components/plugin-module.tsx +8 -6
- package/middlewares/default.ts +6 -1
- package/middlewares/masterpass-rest-callback.ts +26 -142
- package/package.json +2 -2
- package/plugins.js +2 -1
- package/utils/index.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
+
## 1.116.0-rc.11
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 726491df: ZERO-3988: Add google pay integration
|
|
8
|
+
|
|
9
|
+
## 1.116.0-rc.10
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d7e5178b: ZERO-3985: Add query string handling for orders redirection in middleware
|
|
14
|
+
|
|
15
|
+
## 1.116.0-rc.9
|
|
16
|
+
|
|
17
|
+
## 1.116.0-rc.8
|
|
18
|
+
|
|
19
|
+
## 1.116.0-rc.7
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 729fe756: ZERO-3895: improve non-3D payment handling and error display
|
|
24
|
+
|
|
25
|
+
## 1.116.0-rc.6
|
|
26
|
+
|
|
27
|
+
## 1.116.0-rc.5
|
|
28
|
+
|
|
29
|
+
## 1.116.0-rc.4
|
|
30
|
+
|
|
31
|
+
## 1.116.0-rc.3
|
|
32
|
+
|
|
33
|
+
## 1.116.0-rc.2
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- 3909d322: Edit the duplicate Plugin.SimilarProducts in the plugin-module.
|
|
38
|
+
|
|
3
39
|
## 1.116.0-rc.1
|
|
4
40
|
|
|
5
41
|
## 1.116.0-rc.0
|
|
@@ -26,7 +26,8 @@ enum Plugin {
|
|
|
26
26
|
Hepsipay = 'pz-hepsipay',
|
|
27
27
|
MasterpassRest = 'pz-masterpass-rest',
|
|
28
28
|
SimilarProducts = 'pz-similar-products',
|
|
29
|
-
Haso = 'pz-haso'
|
|
29
|
+
Haso = 'pz-haso',
|
|
30
|
+
GooglePay = 'pz-google-pay'
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export enum Component {
|
|
@@ -65,7 +66,8 @@ export enum Component {
|
|
|
65
66
|
ProductImageSearchFeature = 'ProductImageSearchFeature',
|
|
66
67
|
ImageSearchButton = 'ImageSearchButton',
|
|
67
68
|
HeaderImageSearchFeature = 'HeaderImageSearchFeature',
|
|
68
|
-
HasoPaymentGateway = 'HasoPaymentGateway'
|
|
69
|
+
HasoPaymentGateway = 'HasoPaymentGateway',
|
|
70
|
+
GooglePay = 'GooglePay'
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
const PluginComponents = new Map([
|
|
@@ -117,9 +119,9 @@ const PluginComponents = new Map([
|
|
|
117
119
|
[Component.VirtualTryOnPlugin, Component.BasketVirtualTryOn]
|
|
118
120
|
],
|
|
119
121
|
[Plugin.Hepsipay, [Component.Hepsipay]],
|
|
120
|
-
[Plugin.Hepsipay, [Component.Hepsipay]],
|
|
121
122
|
[Plugin.MasterpassRest, [Component.MasterpassRest]],
|
|
122
|
-
[Plugin.Haso, [Component.HasoPaymentGateway]]
|
|
123
|
+
[Plugin.Haso, [Component.HasoPaymentGateway]],
|
|
124
|
+
[Plugin.GooglePay, [Component.GooglePay]]
|
|
123
125
|
]);
|
|
124
126
|
|
|
125
127
|
const getPlugin = (component: Component) => {
|
|
@@ -184,8 +186,6 @@ export default function PluginModule({
|
|
|
184
186
|
promise = import(`${'@akinon/pz-multi-basket'}`);
|
|
185
187
|
} else if (plugin === Plugin.SavedCard) {
|
|
186
188
|
promise = import(`${'@akinon/pz-saved-card'}`);
|
|
187
|
-
} else if (plugin === Plugin.SimilarProducts) {
|
|
188
|
-
promise = import(`${'@akinon/pz-similar-products'}`);
|
|
189
189
|
} else if (plugin === Plugin.Hepsipay) {
|
|
190
190
|
promise = import(`${'@akinon/pz-hepsipay'}`);
|
|
191
191
|
} else if (plugin === Plugin.FlowPayment) {
|
|
@@ -198,6 +198,8 @@ export default function PluginModule({
|
|
|
198
198
|
promise = import(`${'@akinon/pz-similar-products'}`);
|
|
199
199
|
} else if (plugin === Plugin.Haso) {
|
|
200
200
|
promise = import(`${'@akinon/pz-haso'}`);
|
|
201
|
+
} else if (plugin === Plugin.GooglePay) {
|
|
202
|
+
promise = import(`${'@akinon/pz-google-pay'}`);
|
|
201
203
|
}
|
|
202
204
|
} catch (error) {
|
|
203
205
|
logger.error(error);
|
package/middlewares/default.ts
CHANGED
|
@@ -128,8 +128,13 @@ const withPzDefault =
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
if (req.nextUrl.pathname.startsWith('/orders/redirection/')) {
|
|
131
|
+
const queryString = searchParams.toString();
|
|
131
132
|
return NextResponse.rewrite(
|
|
132
|
-
new URL(
|
|
133
|
+
new URL(
|
|
134
|
+
`${encodeURI(Settings.commerceUrl)}/orders/redirection/${
|
|
135
|
+
queryString ? `?${queryString}` : ''
|
|
136
|
+
}`
|
|
137
|
+
)
|
|
133
138
|
);
|
|
134
139
|
}
|
|
135
140
|
|
|
@@ -9,49 +9,21 @@ const withMasterpassRestCallback =
|
|
|
9
9
|
async (req: PzNextRequest, event: NextFetchEvent) => {
|
|
10
10
|
const url = req.nextUrl.clone();
|
|
11
11
|
const ip = req.headers.get('x-forwarded-for') ?? '';
|
|
12
|
-
const sessionId = req.cookies.get('osessionid');
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (req.method !== 'POST') {
|
|
19
|
-
logger.warn('Invalid request method for masterpass REST callback', {
|
|
20
|
-
middleware: 'masterpass-rest-callback',
|
|
21
|
-
method: req.method,
|
|
22
|
-
ip
|
|
23
|
-
});
|
|
13
|
+
const isMasterpassCompletePage =
|
|
14
|
+
url.pathname.includes('/orders/checkout') &&
|
|
15
|
+
url.searchParams.get('page') === 'MasterpassRestCompletePage';
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'/orders/checkout/',
|
|
28
|
-
req.cookies.get('pz-locale')?.value
|
|
29
|
-
)}`,
|
|
30
|
-
303
|
|
31
|
-
);
|
|
17
|
+
if (!isMasterpassCompletePage) {
|
|
18
|
+
return middleware(req, event);
|
|
32
19
|
}
|
|
33
20
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
logger.warn('Missing required parameters for masterpass REST callback', {
|
|
39
|
-
middleware: 'masterpass-rest-callback',
|
|
40
|
-
responseCode,
|
|
41
|
-
token,
|
|
42
|
-
ip
|
|
21
|
+
try {
|
|
22
|
+
const requestUrl = new URL('/orders/checkout/', Settings.commerceUrl);
|
|
23
|
+
url.searchParams.forEach((value, key) => {
|
|
24
|
+
requestUrl.searchParams.set(key, value);
|
|
43
25
|
});
|
|
44
26
|
|
|
45
|
-
return NextResponse.redirect(
|
|
46
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
47
|
-
'/orders/checkout/',
|
|
48
|
-
req.cookies.get('pz-locale')?.value
|
|
49
|
-
)}`,
|
|
50
|
-
303
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
27
|
const formData = await req.formData();
|
|
56
28
|
const body: Record<string, string> = {};
|
|
57
29
|
|
|
@@ -59,37 +31,6 @@ const withMasterpassRestCallback =
|
|
|
59
31
|
body[key] = value.toString();
|
|
60
32
|
});
|
|
61
33
|
|
|
62
|
-
if (!sessionId) {
|
|
63
|
-
logger.warn(
|
|
64
|
-
'Make sure that the SESSION_COOKIE_SAMESITE environment variable is set to None in Commerce.',
|
|
65
|
-
{
|
|
66
|
-
middleware: 'masterpass-rest-callback',
|
|
67
|
-
ip
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return NextResponse.redirect(
|
|
72
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
73
|
-
'/orders/checkout/',
|
|
74
|
-
req.cookies.get('pz-locale')?.value
|
|
75
|
-
)}`,
|
|
76
|
-
303
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const requestUrl = new URL('/orders/checkout/', Settings.commerceUrl);
|
|
81
|
-
requestUrl.searchParams.set('page', 'MasterpassRestCompletePage');
|
|
82
|
-
requestUrl.searchParams.set('responseCode', responseCode);
|
|
83
|
-
requestUrl.searchParams.set('token', token);
|
|
84
|
-
requestUrl.searchParams.set(
|
|
85
|
-
'three_d_secure',
|
|
86
|
-
body.transactionType?.includes('3D') ? 'true' : 'false'
|
|
87
|
-
);
|
|
88
|
-
requestUrl.searchParams.set(
|
|
89
|
-
'transactionType',
|
|
90
|
-
body.transactionType || ''
|
|
91
|
-
);
|
|
92
|
-
|
|
93
34
|
const requestHeaders = {
|
|
94
35
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
95
36
|
'X-Requested-With': 'XMLHttpRequest',
|
|
@@ -105,33 +46,13 @@ const withMasterpassRestCallback =
|
|
|
105
46
|
body: new URLSearchParams(body)
|
|
106
47
|
});
|
|
107
48
|
|
|
108
|
-
logger.info('Masterpass REST callback request', {
|
|
109
|
-
requestUrl: requestUrl.toString(),
|
|
110
|
-
status: request.status,
|
|
111
|
-
requestHeaders,
|
|
112
|
-
ip
|
|
113
|
-
});
|
|
114
|
-
|
|
115
49
|
const response = await request.json();
|
|
116
|
-
|
|
117
|
-
const { context_list: contextList, errors } = response;
|
|
118
|
-
|
|
119
|
-
let redirectUrl = response.redirect_url;
|
|
120
|
-
|
|
121
|
-
if (!redirectUrl && contextList && contextList.length > 0) {
|
|
122
|
-
for (const context of contextList) {
|
|
123
|
-
if (context.page_context && context.page_context.redirect_url) {
|
|
124
|
-
redirectUrl = context.page_context.redirect_url;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
50
|
+
const { errors } = response;
|
|
129
51
|
|
|
130
52
|
if (errors && Object.keys(errors).length) {
|
|
131
|
-
logger.error('Error while processing
|
|
132
|
-
middleware: 'masterpass-rest-
|
|
53
|
+
logger.error('Error while processing MasterpassRestCompletePage', {
|
|
54
|
+
middleware: 'masterpass-rest-complete',
|
|
133
55
|
errors,
|
|
134
|
-
requestHeaders,
|
|
135
56
|
ip
|
|
136
57
|
});
|
|
137
58
|
|
|
@@ -143,73 +64,36 @@ const withMasterpassRestCallback =
|
|
|
143
64
|
{
|
|
144
65
|
status: 303,
|
|
145
66
|
headers: {
|
|
146
|
-
'Set-Cookie': `pz-pos-error=${JSON.stringify(errors)}; path=/;`
|
|
67
|
+
'Set-Cookie': `pz-pos-error=${encodeURIComponent(JSON.stringify(errors))}; path=/;`
|
|
147
68
|
}
|
|
148
69
|
}
|
|
149
70
|
);
|
|
150
71
|
}
|
|
151
72
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
redirectUrl,
|
|
156
|
-
ip
|
|
157
|
-
});
|
|
73
|
+
const redirectUrl =
|
|
74
|
+
response.redirect_url ||
|
|
75
|
+
response.context_list?.[0]?.page_context?.redirect_url;
|
|
158
76
|
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
middleware: 'masterpass-rest-callback',
|
|
164
|
-
requestHeaders,
|
|
165
|
-
response: JSON.stringify(response),
|
|
166
|
-
ip
|
|
167
|
-
}
|
|
77
|
+
if (redirectUrl) {
|
|
78
|
+
return NextResponse.redirect(
|
|
79
|
+
`${url.origin}${getUrlPathWithLocale(redirectUrl, req.cookies.get('pz-locale')?.value)}`,
|
|
80
|
+
303
|
|
168
81
|
);
|
|
169
|
-
|
|
170
|
-
const redirectUrlWithLocale = `${url.origin}${getUrlPathWithLocale(
|
|
171
|
-
'/orders/checkout/',
|
|
172
|
-
req.cookies.get('pz-locale')?.value
|
|
173
|
-
)}`;
|
|
174
|
-
|
|
175
|
-
return NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
176
82
|
}
|
|
177
83
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
)}`;
|
|
182
|
-
|
|
183
|
-
logger.info('Redirecting after masterpass REST callback', {
|
|
184
|
-
middleware: 'masterpass-rest-callback',
|
|
185
|
-
redirectUrlWithLocale,
|
|
186
|
-
ip
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const nextResponse = NextResponse.redirect(redirectUrlWithLocale, 303);
|
|
190
|
-
|
|
191
|
-
nextResponse.headers.set(
|
|
192
|
-
'Set-Cookie',
|
|
193
|
-
request.headers.get('set-cookie') ?? ''
|
|
84
|
+
return NextResponse.redirect(
|
|
85
|
+
`${url.origin}${getUrlPathWithLocale('/orders/checkout/', req.cookies.get('pz-locale')?.value)}`,
|
|
86
|
+
303
|
|
194
87
|
);
|
|
195
|
-
|
|
196
|
-
return nextResponse;
|
|
197
88
|
} catch (error) {
|
|
198
|
-
logger.error('Error while processing
|
|
199
|
-
middleware: 'masterpass-rest-
|
|
89
|
+
logger.error('Error while processing MasterpassRestCompletePage', {
|
|
90
|
+
middleware: 'masterpass-rest-complete',
|
|
200
91
|
error,
|
|
201
|
-
requestHeaders: {
|
|
202
|
-
Cookie: req.headers.get('cookie') ?? '',
|
|
203
|
-
'x-currency': req.cookies.get('pz-currency')?.value ?? ''
|
|
204
|
-
},
|
|
205
92
|
ip
|
|
206
93
|
});
|
|
207
94
|
|
|
208
95
|
return NextResponse.redirect(
|
|
209
|
-
`${url.origin}${getUrlPathWithLocale(
|
|
210
|
-
'/orders/checkout/',
|
|
211
|
-
req.cookies.get('pz-locale')?.value
|
|
212
|
-
)}`,
|
|
96
|
+
`${url.origin}${getUrlPathWithLocale('/orders/checkout/', req.cookies.get('pz-locale')?.value)}`,
|
|
213
97
|
303
|
|
214
98
|
);
|
|
215
99
|
}
|
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.116.0-rc.
|
|
4
|
+
"version": "1.116.0-rc.11",
|
|
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.116.0-rc.
|
|
38
|
+
"@akinon/eslint-plugin-projectzero": "1.116.0-rc.11",
|
|
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.js
CHANGED
package/utils/index.ts
CHANGED
|
@@ -193,7 +193,8 @@ export const urlLocaleMatcherRegex = new RegExp(
|
|
|
193
193
|
);
|
|
194
194
|
|
|
195
195
|
export const getPosError = () => {
|
|
196
|
-
const
|
|
196
|
+
const cookieValue = getCookie('pz-pos-error');
|
|
197
|
+
const error = JSON.parse(cookieValue ? decodeURIComponent(cookieValue) : '{}');
|
|
197
198
|
|
|
198
199
|
// delete 'pz-pos-error' cookie when refreshing or closing page
|
|
199
200
|
window.addEventListener('beforeunload', () => {
|