@akinon/next 1.34.0 → 1.35.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 +10 -0
- package/api/client.ts +9 -5
- package/bin/pz-install-extensions.js +27 -0
- package/bin/pz-install-plugins.js +1 -7
- package/bin/pz-install-theme.js +1 -10
- package/bin/pz-predev.js +2 -0
- package/hooks/use-pagination.ts +21 -14
- package/middlewares/default.ts +14 -0
- package/middlewares/index.ts +1 -0
- package/middlewares/pretty-url.ts +2 -0
- package/package.json +2 -2
- package/types/index.ts +1 -0
- package/utils/find-base-dir.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
+
## 1.35.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d09b677: ZERO-2577: Fix pagination bug and update usePagination hook and ensure pagination controls rendering correctly
|
|
8
|
+
- 6d4aadb: ZERO-2476: Auto install recommendenent extension
|
|
9
|
+
- f0c23bc: ZERO-2135: add custom not found page
|
|
10
|
+
- f488ea8: ZERO-2505: findBaseDir function is united and move on to the utils
|
|
11
|
+
- 6b2972b: ZERO-2514: Fix handling of status 204 and return Commerce status code in client proxy API.
|
|
12
|
+
|
|
3
13
|
## 1.34.0
|
|
4
14
|
|
|
5
15
|
## 1.33.2
|
package/api/client.ts
CHANGED
|
@@ -113,6 +113,14 @@ async function proxyRequest(...args) {
|
|
|
113
113
|
|
|
114
114
|
try {
|
|
115
115
|
const request = await fetch(url, fetchOptions);
|
|
116
|
+
|
|
117
|
+
// Using NextResponse.json with status 204 will cause an error
|
|
118
|
+
if (request.status === 204) {
|
|
119
|
+
return new Response(null, {
|
|
120
|
+
status: 204
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
116
124
|
let response = {} as any;
|
|
117
125
|
|
|
118
126
|
try {
|
|
@@ -138,13 +146,9 @@ async function proxyRequest(...args) {
|
|
|
138
146
|
responseHeaders['set-cookie'] = setCookieHeader;
|
|
139
147
|
}
|
|
140
148
|
|
|
141
|
-
const statusCode = new RegExp(/^20./).test(request.status.toString())
|
|
142
|
-
? 200
|
|
143
|
-
: request.status;
|
|
144
|
-
|
|
145
149
|
return NextResponse.json(
|
|
146
150
|
options.responseType === 'text' ? { result: response } : response,
|
|
147
|
-
{ status:
|
|
151
|
+
{ status: request.status, headers: responseHeaders }
|
|
148
152
|
);
|
|
149
153
|
} catch (error) {
|
|
150
154
|
logger.error('Client proxy request failed', error);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { execSync } = require('child_process');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
function findBaseDir() {
|
|
6
|
+
let currentDir = __dirname;
|
|
7
|
+
while (currentDir !== path.resolve(currentDir, '..')) {
|
|
8
|
+
if (fs.existsSync(path.join(currentDir, 'turbo.json'))) {
|
|
9
|
+
return currentDir;
|
|
10
|
+
}
|
|
11
|
+
currentDir = path.resolve(currentDir, '..');
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const BASE_DIR = findBaseDir();
|
|
17
|
+
|
|
18
|
+
if (BASE_DIR) {
|
|
19
|
+
const extensions = ['bilal-akinon.pznext'];
|
|
20
|
+
extensions.forEach((extension) => {
|
|
21
|
+
try {
|
|
22
|
+
execSync(`code --install-extension ${extension}`, { stdio: 'inherit' });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error(`Error installing ${extension}:`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { execSync } = require('child_process');
|
|
4
|
-
|
|
5
|
-
function findBaseDir() {
|
|
6
|
-
const insideNodeModules = __dirname.includes('node_modules');
|
|
7
|
-
return insideNodeModules
|
|
8
|
-
? process.cwd()
|
|
9
|
-
: path.resolve(__dirname, '../../../apps/projectzeronext');
|
|
10
|
-
}
|
|
4
|
+
const findBaseDir = require('../utils/find-base-dir');
|
|
11
5
|
|
|
12
6
|
const BASE_DIR = findBaseDir();
|
|
13
7
|
const getFullPath = (relativePath) => path.join(BASE_DIR, relativePath);
|
package/bin/pz-install-theme.js
CHANGED
|
@@ -3,16 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const spawn = require('cross-spawn');
|
|
6
|
-
|
|
7
|
-
function findBaseDir() {
|
|
8
|
-
const insideNodeModules = __dirname.includes('node_modules');
|
|
9
|
-
|
|
10
|
-
if (insideNodeModules) {
|
|
11
|
-
return path.resolve(__dirname, '../../../../');
|
|
12
|
-
} else {
|
|
13
|
-
return path.resolve(__dirname, '../../../apps/projectzeronext');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
6
|
+
const findBaseDir = require('../utils/find-base-dir');
|
|
16
7
|
|
|
17
8
|
const BASE_DIR = findBaseDir();
|
|
18
9
|
|
package/bin/pz-predev.js
CHANGED
package/hooks/use-pagination.ts
CHANGED
|
@@ -28,7 +28,11 @@ function reducer(state: InitialState, action: ACTIONTYPE) {
|
|
|
28
28
|
case 'setPage':
|
|
29
29
|
return { ...state, page: action.payload };
|
|
30
30
|
case 'setLimit':
|
|
31
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
limit: action.payload,
|
|
34
|
+
last: Math.ceil(state.total / action.payload)
|
|
35
|
+
};
|
|
32
36
|
default:
|
|
33
37
|
throw new Error();
|
|
34
38
|
}
|
|
@@ -46,10 +50,11 @@ export default function usePagination(
|
|
|
46
50
|
() => new URLSearchParams(searchParams.toString()),
|
|
47
51
|
[searchParams]
|
|
48
52
|
);
|
|
53
|
+
|
|
49
54
|
const { page, limit } = useMemo(
|
|
50
55
|
() => ({
|
|
51
56
|
page: _page || Number(searchParams.get('page')) || 1,
|
|
52
|
-
limit: _limit || Number(searchParams.get('limit'))
|
|
57
|
+
limit: _limit || Number(searchParams.get('limit')) || 12
|
|
53
58
|
}),
|
|
54
59
|
[searchParams, _page, _limit]
|
|
55
60
|
);
|
|
@@ -60,6 +65,7 @@ export default function usePagination(
|
|
|
60
65
|
last: _last || Math.ceil(_total / limit) || 1,
|
|
61
66
|
total: _total
|
|
62
67
|
};
|
|
68
|
+
|
|
63
69
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
64
70
|
|
|
65
71
|
useEffect(() => {
|
|
@@ -93,23 +99,24 @@ export default function usePagination(
|
|
|
93
99
|
[dispatch]
|
|
94
100
|
);
|
|
95
101
|
|
|
96
|
-
const pageList = useMemo(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const pageList = useMemo(
|
|
103
|
+
() =>
|
|
104
|
+
Array.from({ length: state.last }, (_, i) => {
|
|
105
|
+
urlSearchParams.set('page', (i + 1).toString());
|
|
106
|
+
return {
|
|
107
|
+
page: i + 1,
|
|
108
|
+
url: `${pathname}?${urlSearchParams.toString()}`
|
|
109
|
+
};
|
|
110
|
+
}),
|
|
111
|
+
[state.last, pathname, urlSearchParams]
|
|
112
|
+
);
|
|
106
113
|
|
|
107
114
|
const prev = useMemo(() => {
|
|
108
115
|
if (state.page > 1) {
|
|
109
116
|
urlSearchParams.set('page', (Number(state.page) - 1).toString());
|
|
110
117
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
111
118
|
}
|
|
112
|
-
return
|
|
119
|
+
return '#';
|
|
113
120
|
}, [state.page, pathname, urlSearchParams]);
|
|
114
121
|
|
|
115
122
|
const next = useMemo(() => {
|
|
@@ -117,7 +124,7 @@ export default function usePagination(
|
|
|
117
124
|
urlSearchParams.set('page', (Number(state.page) + 1).toString());
|
|
118
125
|
return `${pathname}?${urlSearchParams.toString()}`;
|
|
119
126
|
}
|
|
120
|
-
return
|
|
127
|
+
return '#';
|
|
121
128
|
}, [state.page, state.last, pathname, urlSearchParams]);
|
|
122
129
|
|
|
123
130
|
return {
|
package/middlewares/default.ts
CHANGED
|
@@ -153,6 +153,7 @@ const withPzDefault =
|
|
|
153
153
|
|
|
154
154
|
req.middlewareParams = {
|
|
155
155
|
commerceUrl,
|
|
156
|
+
found: true,
|
|
156
157
|
rewrites: {}
|
|
157
158
|
};
|
|
158
159
|
|
|
@@ -186,6 +187,19 @@ const withPzDefault =
|
|
|
186
187
|
locale.length ? `${locale}/` : ''
|
|
187
188
|
}${currency}${prettyUrl ?? pathnameWithoutLocale}`;
|
|
188
189
|
|
|
190
|
+
if (
|
|
191
|
+
!req.middlewareParams.found &&
|
|
192
|
+
Settings.customNotFoundEnabled
|
|
193
|
+
) {
|
|
194
|
+
let pathname = url.pathname
|
|
195
|
+
.replace(/\/+$/, '')
|
|
196
|
+
.split('/');
|
|
197
|
+
url.pathname = url.pathname.replace(
|
|
198
|
+
pathname.pop(),
|
|
199
|
+
'pz-not-found'
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
189
203
|
Settings.rewrites.forEach((rewrite) => {
|
|
190
204
|
url.pathname = url.pathname.replace(
|
|
191
205
|
rewrite.source,
|
package/middlewares/index.ts
CHANGED
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.
|
|
4
|
+
"version": "1.35.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
33
33
|
"@typescript-eslint/parser": "6.7.4",
|
|
34
34
|
"eslint": "^8.14.0",
|
|
35
|
-
"@akinon/eslint-plugin-projectzero": "1.
|
|
35
|
+
"@akinon/eslint-plugin-projectzero": "1.35.0",
|
|
36
36
|
"eslint-config-prettier": "8.5.0"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/types/index.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
function findBaseDir() {
|
|
4
|
+
const insideNodeModules = __dirname.includes('node_modules');
|
|
5
|
+
|
|
6
|
+
if (insideNodeModules) {
|
|
7
|
+
return path.resolve(__dirname, '../../../../');
|
|
8
|
+
} else {
|
|
9
|
+
return path.resolve(__dirname, '../../../apps/projectzeronext');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = findBaseDir;
|