@akinon/next 2.0.32-beta.0 → 2.0.32
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 +2 -2
- package/middlewares/default.ts +72 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 2.0.32
|
|
3
|
+
## 2.0.32
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 239aa9d0: ZERO-4169: Add instore source parameter and forward set-cookie headers in checkout-with-token redirect
|
|
8
8
|
|
|
9
9
|
## 2.0.31
|
|
10
10
|
|
package/middlewares/default.ts
CHANGED
|
@@ -102,9 +102,79 @@ const withPzDefault =
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
if (req.nextUrl.pathname.includes('/orders/checkout-with-token/')) {
|
|
106
|
+
const queryString = searchParams.toString();
|
|
107
|
+
const currency = searchParams.get('currency')?.toLowerCase();
|
|
108
|
+
const commercePath = req.nextUrl.pathname.replace(
|
|
109
|
+
urlLocaleMatcherRegex,
|
|
110
|
+
''
|
|
111
|
+
);
|
|
112
|
+
const targetUrl = `${Settings.commerceUrl}${commercePath}${
|
|
113
|
+
queryString ? `?${queryString}` : ''
|
|
114
|
+
}`;
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const commerceResponse = await fetch(targetUrl, {
|
|
118
|
+
redirect: 'manual',
|
|
119
|
+
headers: {
|
|
120
|
+
cookie: req.headers.get('cookie') || ''
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const location = commerceResponse.headers.get('location');
|
|
125
|
+
|
|
126
|
+
if (location) {
|
|
127
|
+
const locationUrl = new URL(location, Settings.commerceUrl);
|
|
128
|
+
locationUrl.searchParams.set('source', 'instore');
|
|
129
|
+
const redirectTarget = `${req.nextUrl.origin}${locationUrl.pathname}${locationUrl.search}`;
|
|
130
|
+
const response = NextResponse.redirect(redirectTarget);
|
|
131
|
+
|
|
132
|
+
// Set pz-currency FIRST via cookies API — NextResponse.cookies.set()
|
|
133
|
+
// overwrites manually appended Set-Cookie headers, so it must run
|
|
134
|
+
// before headers.append('Set-Cookie', ...) calls.
|
|
135
|
+
if (currency) {
|
|
136
|
+
response.cookies.set('pz-currency', currency, {
|
|
137
|
+
sameSite: 'none',
|
|
138
|
+
secure: true,
|
|
139
|
+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Forward set-cookie headers from the upstream response
|
|
144
|
+
const setCookies =
|
|
145
|
+
commerceResponse.headers.getSetCookie?.() ?? [];
|
|
146
|
+
setCookies.forEach((cookie) => {
|
|
147
|
+
response.headers.append('Set-Cookie', cookie);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return response;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
logger.warn('checkout-with-token: no redirect from commerce', {
|
|
154
|
+
ip,
|
|
155
|
+
url: targetUrl
|
|
156
|
+
});
|
|
157
|
+
} catch {
|
|
158
|
+
logger.warn(
|
|
159
|
+
'checkout-with-token: fetch failed, falling back to rewrite',
|
|
160
|
+
{ ip, url: targetUrl }
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const response = NextResponse.rewrite(new URL(targetUrl));
|
|
164
|
+
|
|
165
|
+
if (currency) {
|
|
166
|
+
response.cookies.set('pz-currency', currency, {
|
|
167
|
+
sameSite: 'none',
|
|
168
|
+
secure: true,
|
|
169
|
+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7)
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return response;
|
|
174
|
+
}
|
|
175
|
+
|
|
105
176
|
if (
|
|
106
177
|
req.nextUrl.pathname.includes('/orders/hooks/') ||
|
|
107
|
-
req.nextUrl.pathname.includes('/orders/checkout-with-token/') ||
|
|
108
178
|
req.nextUrl.pathname.includes('/orders/post-checkout-redirect/') ||
|
|
109
179
|
req.nextUrl.pathname.includes('/hooks/cash_register/complete/') ||
|
|
110
180
|
req.nextUrl.pathname.includes('/hooks/cash_register/pre_order/')
|
|
@@ -510,9 +580,7 @@ const withPzDefault =
|
|
|
510
580
|
}
|
|
511
581
|
|
|
512
582
|
if (
|
|
513
|
-
req.cookies.get(
|
|
514
|
-
'pz-post-checkout-flow'
|
|
515
|
-
)
|
|
583
|
+
req.cookies.get('pz-post-checkout-flow')
|
|
516
584
|
) {
|
|
517
585
|
if (
|
|
518
586
|
pathnameWithoutLocale.startsWith(
|
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": "2.0.32
|
|
4
|
+
"version": "2.0.32",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"set-cookie-parser": "2.6.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@akinon/eslint-plugin-projectzero": "2.0.32
|
|
39
|
+
"@akinon/eslint-plugin-projectzero": "2.0.32",
|
|
40
40
|
"@babel/core": "7.26.10",
|
|
41
41
|
"@babel/preset-env": "7.26.9",
|
|
42
42
|
"@babel/preset-typescript": "7.27.0",
|