nextjs-cms 0.9.42 → 0.10.1
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/dist/api/actions/pages.d.ts +3 -3
- package/dist/api/trpc/root.d.ts +3 -3
- package/dist/api/trpc/routers/navigation.d.ts +3 -3
- package/dist/api/trpc/server.d.ts +9 -9
- package/dist/core/config/config-loader.d.ts +2 -2
- package/dist/core/fields/date-range.d.ts +4 -4
- package/dist/core/fields/inline-image.d.ts +45 -0
- package/dist/core/fields/inline-image.d.ts.map +1 -0
- package/dist/core/fields/inline-image.js +30 -0
- package/dist/core/fields/photo.d.ts.map +1 -1
- package/dist/core/fields/photo.js +1 -9
- package/dist/core/fields/richText.d.ts +162 -42
- package/dist/core/fields/richText.d.ts.map +1 -1
- package/dist/core/fields/richText.js +104 -35
- package/dist/core/fields/select.d.ts +1 -1
- package/dist/core/helpers/background.d.ts +18 -0
- package/dist/core/helpers/background.d.ts.map +1 -0
- package/dist/core/helpers/background.js +18 -0
- package/dist/core/helpers/index.d.ts +5 -1
- package/dist/core/helpers/index.d.ts.map +1 -1
- package/dist/core/helpers/index.js +3 -1
- package/dist/core/helpers/inline-image.d.ts +46 -0
- package/dist/core/helpers/inline-image.d.ts.map +1 -0
- package/dist/core/helpers/inline-image.js +30 -0
- package/dist/core/sections/category.d.ts +4 -4
- package/dist/core/sections/hasItems.d.ts +4 -4
- package/dist/core/sections/section.d.ts +3 -3
- package/dist/core/sections/simple.d.ts +4 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/utils.d.ts +13 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +15 -0
- package/dist/validators/richText.d.ts.map +1 -1
- package/dist/validators/richText.js +35 -1
- package/package.json +3 -3
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import CpanelAPI from './CpanelApi.js';
|
|
2
|
-
export { sanitizeFileName, sanitizeFolderOrFileName, humanReadableFileSize, capitalizeWords, base64ToBlob, displayDateFromString, formatNumber, } from './utils.js';
|
|
2
|
+
export { sanitizeFileName, sanitizeFolderOrFileName, humanReadableFileSize, maxFileSizeToBytes, base64ByteLength, capitalizeWords, base64ToBlob, displayDateFromString, formatNumber, } from './utils.js';
|
|
3
3
|
export { CpanelAPI };
|
|
4
4
|
export { responseHeaders } from './constants.js';
|
|
5
5
|
export { logWarn, logError, logInfo } from './console-log.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EACH,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,YAAY,GACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EACH,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,YAAY,GACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import CpanelAPI from './CpanelApi.js';
|
|
2
|
-
export { sanitizeFileName, sanitizeFolderOrFileName, humanReadableFileSize, capitalizeWords, base64ToBlob, displayDateFromString, formatNumber, } from './utils.js';
|
|
2
|
+
export { sanitizeFileName, sanitizeFolderOrFileName, humanReadableFileSize, maxFileSizeToBytes, base64ByteLength, capitalizeWords, base64ToBlob, displayDateFromString, formatNumber, } from './utils.js';
|
|
3
3
|
export { CpanelAPI };
|
|
4
4
|
export { responseHeaders } from './constants.js';
|
|
5
5
|
export { logWarn, logError, logInfo } from './console-log.js';
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -50,5 +50,18 @@ export declare function capitalizeWords(input: string, allWords?: boolean): stri
|
|
|
50
50
|
* Function to display a file size in a human-readable format
|
|
51
51
|
* @param sizeInBytes
|
|
52
52
|
*/
|
|
53
|
+
/**
|
|
54
|
+
* Byte budget for a `{ size, unit }` file-size limit, so every enforcement site converts it the
|
|
55
|
+
* same way.
|
|
56
|
+
*/
|
|
57
|
+
export declare function maxFileSizeToBytes(limit: {
|
|
58
|
+
size: number;
|
|
59
|
+
unit: 'kb' | 'mb';
|
|
60
|
+
}): number;
|
|
61
|
+
/**
|
|
62
|
+
* Decoded byte length of a base64 payload, without allocating the buffer — lets an oversized
|
|
63
|
+
* image be rejected before anything is decoded.
|
|
64
|
+
*/
|
|
65
|
+
export declare function base64ByteLength(base64: string): number;
|
|
53
66
|
export declare function humanReadableFileSize(sizeInBytes: number, decimals?: number): string;
|
|
54
67
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,WAGtD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,WAG9C,CAAA;AAED;;;GA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AAA;CACxB,GAAG,IAAI,CAmBP;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,EAAE,MAAM,MAAM,EAAE,gBAAgB,OAAO,EAAE,WAAW,GAAG,GAAG,GAAG,WAGhH,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC5B,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,gBAAgB,OAAO,EACvB,WAAW,GAAG,GAAG,GAAG,KACrB,MAkBF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAc,GAAG,MAAM,CAW/E;AAED;;;GAGG;AACH;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CAErF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAoBvF"}
|
package/dist/utils/utils.js
CHANGED
|
@@ -104,6 +104,21 @@ export function capitalizeWords(input, allWords = true) {
|
|
|
104
104
|
* Function to display a file size in a human-readable format
|
|
105
105
|
* @param sizeInBytes
|
|
106
106
|
*/
|
|
107
|
+
/**
|
|
108
|
+
* Byte budget for a `{ size, unit }` file-size limit, so every enforcement site converts it the
|
|
109
|
+
* same way.
|
|
110
|
+
*/
|
|
111
|
+
export function maxFileSizeToBytes(limit) {
|
|
112
|
+
return limit.size * (limit.unit === 'kb' ? 1024 : 1024 * 1024);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Decoded byte length of a base64 payload, without allocating the buffer — lets an oversized
|
|
116
|
+
* image be rejected before anything is decoded.
|
|
117
|
+
*/
|
|
118
|
+
export function base64ByteLength(base64) {
|
|
119
|
+
const padding = base64.endsWith('==') ? 2 : base64.endsWith('=') ? 1 : 0;
|
|
120
|
+
return Math.floor((base64.length * 3) / 4) - padding;
|
|
121
|
+
}
|
|
107
122
|
export function humanReadableFileSize(sizeInBytes, decimals = 2) {
|
|
108
123
|
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
109
124
|
let index = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"richText.d.ts","sourceRoot":"","sources":["../../src/validators/richText.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"richText.d.ts","sourceRoot":"","sources":["../../src/validators/richText.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAKxE,eAAO,MAAM,mBAAmB,GAAI,OAAO,yBAAyB,EAAE,iBAAe,sFAiDpF,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
import { DEFAULT_MAX_FILE_SIZE, INLINE_IMAGE_REGEX } from '../core/helpers/inline-image.js';
|
|
2
3
|
import getString from '../translations/index.js';
|
|
4
|
+
import { base64ByteLength, maxFileSizeToBytes } from '../utils/utils.js';
|
|
3
5
|
export const richTextFieldSchema = (field, language = 'en') => {
|
|
4
6
|
const requiredMessage = getString('requiredField', language);
|
|
5
7
|
const minLength = field.minLength ?? 1;
|
|
@@ -12,5 +14,37 @@ export const richTextFieldSchema = (field, language = 'en') => {
|
|
|
12
14
|
if (Number.isFinite(maxLength)) {
|
|
13
15
|
base = base.max(maxLength, { message: getString('maxLength', language, { max: maxLength }) });
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Reject oversized inline images during validation, so the editor reports it while the admin is
|
|
19
|
+
* still looking at the content rather than after a failed save.
|
|
20
|
+
*
|
|
21
|
+
* This schema is environment-neutral: the admin form runs it in the browser, and a consumer may
|
|
22
|
+
* also run it server-side. Neither is the authority — `RichTextField.extractInlineImages` repeats
|
|
23
|
+
* the check on every submit, which is what a browser-side bypass would still hit.
|
|
24
|
+
*/
|
|
25
|
+
const allowImageUploads = field.allowImageUploads;
|
|
26
|
+
const checked = allowImageUploads
|
|
27
|
+
? base.superRefine((value, ctx) => {
|
|
28
|
+
const maxFileSize = allowImageUploads.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;
|
|
29
|
+
const maxBytes = maxFileSizeToBytes(maxFileSize);
|
|
30
|
+
for (const match of value.matchAll(INLINE_IMAGE_REGEX)) {
|
|
31
|
+
const payload = match[1]?.split(',')[1] ?? '';
|
|
32
|
+
if (base64ByteLength(payload) <= maxBytes)
|
|
33
|
+
continue;
|
|
34
|
+
ctx.addIssue({
|
|
35
|
+
code: 'too_big',
|
|
36
|
+
maximum: maxBytes,
|
|
37
|
+
inclusive: true,
|
|
38
|
+
type: 'number',
|
|
39
|
+
origin: 'number',
|
|
40
|
+
message: getString('fileSizeExceeded', language, {
|
|
41
|
+
size: maxFileSize.size,
|
|
42
|
+
unit: maxFileSize.unit,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
return; // one message is enough — every oversized image has the same fix
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
: base;
|
|
49
|
+
return field.required ? checked : z.union([z.literal(''), checked], requiredMessage).optional();
|
|
16
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextjs-cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -226,9 +226,9 @@
|
|
|
226
226
|
"prettier": "^3.3.3",
|
|
227
227
|
"tsx": "^4.20.6",
|
|
228
228
|
"typescript": "^5.9.2",
|
|
229
|
-
"@lzcms/
|
|
229
|
+
"@lzcms/tsconfig": "0.1.0",
|
|
230
230
|
"@lzcms/prettier-config": "0.1.0",
|
|
231
|
-
"@lzcms/
|
|
231
|
+
"@lzcms/eslint-config": "0.3.0"
|
|
232
232
|
},
|
|
233
233
|
"license": "MIT",
|
|
234
234
|
"keywords": [
|