@akinon/next 1.99.0-snapshot-ZERO-3640-20250919140935 → 1.99.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 +7 -1
- package/api/cache.ts +41 -5
- package/bin/pz-generate-routes.js +105 -0
- package/bin/pz-prebuild.js +1 -0
- package/bin/pz-predev.js +1 -0
- package/data/server/category.ts +4 -2
- package/data/server/flatpage.ts +4 -1
- package/data/server/form.ts +4 -1
- package/data/server/landingpage.ts +4 -1
- package/data/server/list.ts +2 -1
- package/data/server/menu.ts +4 -1
- package/data/server/product.ts +2 -1
- package/data/server/seo.ts +4 -1
- package/data/server/special-page.ts +2 -1
- package/data/server/widget.ts +4 -1
- package/lib/cache-handler.mjs +365 -87
- package/lib/cache.ts +254 -25
- package/middlewares/pretty-url.ts +21 -6
- package/package.json +4 -3
- package/types/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# @akinon/next
|
|
2
2
|
|
|
3
|
-
## 1.99.0
|
|
3
|
+
## 1.99.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cf90355: ZERO-3586_2: Enhance caching functionality by adding support for compressed data storage and retrieval, along with a new method for setting multiple key-value pairs.
|
|
8
|
+
- d58538b: ZERO-3638: Enhance RC pipeline: add fetch, merge, and pre-release setup with conditional commit
|
|
9
|
+
- 95a4cd1: ZERO-3631: add automatic route generation
|
|
4
10
|
|
|
5
11
|
## 1.98.0
|
|
6
12
|
|
package/api/cache.ts
CHANGED
|
@@ -21,20 +21,56 @@ async function handleRequest(...args) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const formData = await req.formData();
|
|
24
|
-
const body = {} as {
|
|
24
|
+
const body = {} as {
|
|
25
|
+
key: string;
|
|
26
|
+
value?: string;
|
|
27
|
+
expire?: number;
|
|
28
|
+
keyValuePairs?: string;
|
|
29
|
+
compressed?: string;
|
|
30
|
+
};
|
|
25
31
|
|
|
26
32
|
formData.forEach((value, key) => {
|
|
27
33
|
body[key] = value;
|
|
28
34
|
});
|
|
29
35
|
|
|
30
|
-
const { key, value, expire } = body;
|
|
31
|
-
let response:
|
|
36
|
+
const { key, value, expire, keyValuePairs, compressed } = body;
|
|
37
|
+
let response: any;
|
|
32
38
|
|
|
33
39
|
try {
|
|
34
40
|
if (req.method === 'POST') {
|
|
35
|
-
|
|
41
|
+
// GET request - check if compressed flag is set
|
|
42
|
+
if (compressed === 'true') {
|
|
43
|
+
response = await Cache.getCompressed(key);
|
|
44
|
+
} else {
|
|
45
|
+
response = await Cache.get(key);
|
|
46
|
+
}
|
|
36
47
|
} else if (req.method === 'PUT') {
|
|
37
|
-
|
|
48
|
+
if (keyValuePairs) {
|
|
49
|
+
try {
|
|
50
|
+
const parsedKeyValuePairs = JSON.parse(keyValuePairs);
|
|
51
|
+
if (
|
|
52
|
+
typeof parsedKeyValuePairs !== 'object' ||
|
|
53
|
+
parsedKeyValuePairs === null ||
|
|
54
|
+
Array.isArray(parsedKeyValuePairs)
|
|
55
|
+
) {
|
|
56
|
+
throw new Error('Invalid keyValuePairs format - must be an object');
|
|
57
|
+
}
|
|
58
|
+
response = await Cache.mset(parsedKeyValuePairs, expire);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
logger.error('Invalid keyValuePairs in mset request', { error });
|
|
61
|
+
return NextResponse.json(
|
|
62
|
+
{ error: 'Invalid keyValuePairs format' },
|
|
63
|
+
{ status: 400 }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
// SET request - check if compressed flag is set
|
|
68
|
+
if (compressed === 'true') {
|
|
69
|
+
response = await Cache.setCompressed(key, value, expire);
|
|
70
|
+
} else {
|
|
71
|
+
response = await Cache.set(key, value, expire);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
38
74
|
}
|
|
39
75
|
} catch (error) {
|
|
40
76
|
logger.error(error);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const findBaseDir = require('../utils/find-base-dir');
|
|
6
|
+
|
|
7
|
+
const generateRoutes = () => {
|
|
8
|
+
const baseDir = findBaseDir();
|
|
9
|
+
const srcDir = path.join(baseDir, 'src');
|
|
10
|
+
const appDir = path.join(srcDir, 'app');
|
|
11
|
+
|
|
12
|
+
const routesDir = path.join(srcDir, 'routes');
|
|
13
|
+
const jsOutputPath = path.join(routesDir, 'generated-routes.js');
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(routesDir)) {
|
|
16
|
+
fs.mkdirSync(routesDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!fs.existsSync(appDir)) {
|
|
20
|
+
console.error(`Error: app directory not found at ${appDir}`);
|
|
21
|
+
console.error('Make sure you have an app directory in your project');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const routes = [];
|
|
26
|
+
const excludedDirs = ['api', 'pz-not-found'];
|
|
27
|
+
|
|
28
|
+
const skipSegments = ['[commerce]', '[locale]', '[currency]'];
|
|
29
|
+
const skipCatchAllRoutes = ['[...prettyurl]'];
|
|
30
|
+
|
|
31
|
+
const walkDirectory = (dir, basePath = '') => {
|
|
32
|
+
const files = fs.readdirSync(dir);
|
|
33
|
+
|
|
34
|
+
files.forEach((file) => {
|
|
35
|
+
const filePath = path.join(dir, file);
|
|
36
|
+
const stat = fs.statSync(filePath);
|
|
37
|
+
|
|
38
|
+
if (stat.isDirectory()) {
|
|
39
|
+
if (excludedDirs.includes(file)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (skipCatchAllRoutes.includes(file.toLowerCase())) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let routePath = basePath;
|
|
48
|
+
if (skipSegments.includes(file.toLowerCase())) {
|
|
49
|
+
routePath = basePath;
|
|
50
|
+
} else if (file.startsWith('[') && file.endsWith(']')) {
|
|
51
|
+
if (file.startsWith('[...')) {
|
|
52
|
+
routePath = `${basePath}/.+`;
|
|
53
|
+
} else {
|
|
54
|
+
routePath = `${basePath}/[^/]+`;
|
|
55
|
+
}
|
|
56
|
+
} else if (file.startsWith('(') && file.endsWith(')')) {
|
|
57
|
+
routePath = basePath;
|
|
58
|
+
} else {
|
|
59
|
+
routePath = `${basePath}/${file}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const pageFiles = ['page.tsx'];
|
|
63
|
+
const hasPage = pageFiles.some((pageFile) =>
|
|
64
|
+
fs.existsSync(path.join(filePath, pageFile))
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (hasPage && routePath) {
|
|
68
|
+
routes.push(routePath === '' ? '/' : routePath);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
walkDirectory(filePath, routePath);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
walkDirectory(appDir);
|
|
77
|
+
|
|
78
|
+
routes.push('/');
|
|
79
|
+
|
|
80
|
+
const cleanedRoutes = routes
|
|
81
|
+
.map((route) => {
|
|
82
|
+
return route.replace(/\/+/g, '/');
|
|
83
|
+
})
|
|
84
|
+
.filter((route, index, self) => {
|
|
85
|
+
return self.indexOf(route) === index;
|
|
86
|
+
})
|
|
87
|
+
.sort();
|
|
88
|
+
|
|
89
|
+
const jsContent = `// Generated by pz-generate-routes script
|
|
90
|
+
// Do not edit manually
|
|
91
|
+
module.exports = ${JSON.stringify(cleanedRoutes, null, 2)};`;
|
|
92
|
+
|
|
93
|
+
fs.writeFileSync(jsOutputPath, jsContent);
|
|
94
|
+
|
|
95
|
+
console.info(
|
|
96
|
+
`Routes generated successfully. (Found ${cleanedRoutes.length} routes)`
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
generateRoutes();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error('Error generating routes:', error);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
package/bin/pz-prebuild.js
CHANGED
package/bin/pz-predev.js
CHANGED
package/data/server/category.ts
CHANGED
|
@@ -98,7 +98,8 @@ export const getCategoryData = ({
|
|
|
98
98
|
locale,
|
|
99
99
|
getCategoryDataHandler(pk, locale, currency, searchParams, headers),
|
|
100
100
|
{
|
|
101
|
-
expire: 300
|
|
101
|
+
expire: 300,
|
|
102
|
+
compressed: true
|
|
102
103
|
}
|
|
103
104
|
);
|
|
104
105
|
};
|
|
@@ -158,7 +159,8 @@ export const getCategoryBySlugData = async ({
|
|
|
158
159
|
locale,
|
|
159
160
|
getCategoryBySlugDataHandler(slug, locale, currency),
|
|
160
161
|
{
|
|
161
|
-
expire: 300
|
|
162
|
+
expire: 300,
|
|
163
|
+
compressed: true
|
|
162
164
|
}
|
|
163
165
|
);
|
|
164
166
|
};
|
package/data/server/flatpage.ts
CHANGED
package/data/server/form.ts
CHANGED
package/data/server/list.ts
CHANGED
package/data/server/menu.ts
CHANGED
|
@@ -48,6 +48,9 @@ export const getMenu = async (params?: MenuHandlerParams) => {
|
|
|
48
48
|
return Cache.wrap(
|
|
49
49
|
CacheKey.Menu(params?.depth ?? DEFAULT_DEPTH, params?.parent),
|
|
50
50
|
params?.locale ?? ServerVariables.locale,
|
|
51
|
-
getMenuHandler(params)
|
|
51
|
+
getMenuHandler(params),
|
|
52
|
+
{
|
|
53
|
+
compressed: true
|
|
54
|
+
}
|
|
52
55
|
);
|
|
53
56
|
};
|
package/data/server/product.ts
CHANGED
package/data/server/seo.ts
CHANGED