@akinon/next 1.26.0-rc.4 → 1.26.0-rc.6
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 +16 -0
- package/api/client.ts +15 -3
- package/package.json +5 -3
- package/utils/format-cookie-string.ts +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
+
## 1.26.0-rc.6
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 40ad73e: ZERO-2504: add cookie filter to api client request
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @akinon/eslint-plugin-projectzero@1.26.0-rc.6
|
|
12
|
+
|
|
13
|
+
## 1.26.0-rc.5
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- @akinon/eslint-plugin-projectzero@1.26.0-rc.5
|
|
18
|
+
|
|
3
19
|
## 1.26.0-rc.4
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/api/client.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { ClientRequestOptions } from '../types';
|
|
|
2
2
|
import { NextResponse } from 'next/server';
|
|
3
3
|
import settings from 'settings';
|
|
4
4
|
import logger from '../utils/log';
|
|
5
|
+
import formatCookieString from '../utils/format-cookie-string';
|
|
6
|
+
import cookieParser from 'set-cookie-parser';
|
|
5
7
|
|
|
6
8
|
interface RouteParams {
|
|
7
9
|
params: {
|
|
@@ -131,11 +133,21 @@ async function proxyRequest(...args) {
|
|
|
131
133
|
);
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
const
|
|
136
|
+
const setCookieHeaders = req.headers.getSetCookie();
|
|
137
|
+
const exceptCookieKeys = ['pz-locale', 'pz-currency'];
|
|
138
|
+
|
|
139
|
+
const isExcludedCookie = (name: string) => exceptCookieKeys.includes(name);
|
|
140
|
+
|
|
141
|
+
const filteredCookies = cookieParser
|
|
142
|
+
.parse(setCookieHeaders)
|
|
143
|
+
.filter((cookie) => !isExcludedCookie(cookie.name));
|
|
144
|
+
|
|
135
145
|
const responseHeaders: any = {};
|
|
136
146
|
|
|
137
|
-
if (
|
|
138
|
-
responseHeaders['set-cookie'] =
|
|
147
|
+
if (filteredCookies.length > 0) {
|
|
148
|
+
responseHeaders['set-cookie'] = filteredCookies
|
|
149
|
+
.map(formatCookieString)
|
|
150
|
+
.join(', ');
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
const statusCode = new RegExp(/^20./).test(request.status.toString())
|
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-rc.
|
|
4
|
+
"version": "1.26.0-rc.6",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -25,14 +25,16 @@
|
|
|
25
25
|
"react-redux": "8.1.3",
|
|
26
26
|
"react-string-replace": "1.1.1",
|
|
27
27
|
"redis": "4.5.1",
|
|
28
|
-
"semver": "7.5.4"
|
|
28
|
+
"semver": "7.5.4",
|
|
29
|
+
"set-cookie-parser": "2.6.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@akinon/eslint-plugin-projectzero": "1.24.0",
|
|
31
33
|
"@types/react-redux": "7.1.30",
|
|
34
|
+
"@types/set-cookie-parser": "2.4.7",
|
|
32
35
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
33
36
|
"@typescript-eslint/parser": "6.7.4",
|
|
34
37
|
"eslint": "^8.14.0",
|
|
35
|
-
"@akinon/eslint-plugin-projectzero": "1.24.0",
|
|
36
38
|
"eslint-config-prettier": "8.5.0"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default function formatCookieString(cookieObj: Record<string, any>) {
|
|
2
|
+
const cookieParts = [`${cookieObj.name}=${cookieObj.value}`];
|
|
3
|
+
|
|
4
|
+
if (cookieObj.expires) {
|
|
5
|
+
cookieParts.push(`Expires=${cookieObj.expires.toUTCString()}`);
|
|
6
|
+
}
|
|
7
|
+
if (cookieObj.maxAge) {
|
|
8
|
+
cookieParts.push(`Max-Age=${cookieObj.maxAge}`);
|
|
9
|
+
}
|
|
10
|
+
if (cookieObj.path) {
|
|
11
|
+
cookieParts.push(`Path=${cookieObj.path}`);
|
|
12
|
+
}
|
|
13
|
+
if (cookieObj.domain) {
|
|
14
|
+
cookieParts.push(`Domain=${cookieObj.domain}`);
|
|
15
|
+
}
|
|
16
|
+
if (cookieObj.secure) {
|
|
17
|
+
cookieParts.push('Secure');
|
|
18
|
+
}
|
|
19
|
+
if (cookieObj.httpOnly) {
|
|
20
|
+
cookieParts.push('HttpOnly');
|
|
21
|
+
}
|
|
22
|
+
if (cookieObj.sameSite) {
|
|
23
|
+
cookieParts.push(`SameSite=${cookieObj.sameSite}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return cookieParts.join('; ');
|
|
27
|
+
}
|