nextjs-cms 0.10.0 → 0.10.2

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.
Files changed (36) hide show
  1. package/dist/api/actions/pages.d.ts +3 -3
  2. package/dist/api/trpc/root.d.ts +3 -3
  3. package/dist/api/trpc/routers/navigation.d.ts +3 -3
  4. package/dist/api/trpc/server.d.ts +9 -9
  5. package/dist/core/config/config-loader.d.ts +2 -2
  6. package/dist/core/fields/date-range.d.ts +4 -4
  7. package/dist/core/fields/inline-image.d.ts +45 -0
  8. package/dist/core/fields/inline-image.d.ts.map +1 -0
  9. package/dist/core/fields/inline-image.js +30 -0
  10. package/dist/core/fields/photo.d.ts +6 -6
  11. package/dist/core/fields/richText.d.ts +8 -8
  12. package/dist/core/fields/richText.d.ts.map +1 -1
  13. package/dist/core/fields/richText.js +4 -35
  14. package/dist/core/fields/select.d.ts +1 -1
  15. package/dist/core/helpers/index.d.ts +2 -0
  16. package/dist/core/helpers/index.d.ts.map +1 -1
  17. package/dist/core/helpers/index.js +1 -0
  18. package/dist/core/helpers/inline-image.d.ts +46 -0
  19. package/dist/core/helpers/inline-image.d.ts.map +1 -0
  20. package/dist/core/helpers/inline-image.js +30 -0
  21. package/dist/core/sections/category.d.ts +4 -4
  22. package/dist/core/sections/hasItems.d.ts +10 -10
  23. package/dist/core/sections/section.d.ts +3 -3
  24. package/dist/core/sections/simple.d.ts +4 -4
  25. package/dist/core/security/dom.d.ts +4 -0
  26. package/dist/core/security/dom.d.ts.map +1 -1
  27. package/dist/core/security/dom.js +5 -1
  28. package/dist/utils/index.d.ts +1 -1
  29. package/dist/utils/index.d.ts.map +1 -1
  30. package/dist/utils/index.js +1 -1
  31. package/dist/utils/utils.d.ts +13 -0
  32. package/dist/utils/utils.d.ts.map +1 -1
  33. package/dist/utils/utils.js +15 -0
  34. package/dist/validators/richText.d.ts.map +1 -1
  35. package/dist/validators/richText.js +35 -1
  36. package/package.json +2 -2
@@ -6,6 +6,10 @@ export declare function escapeHTML(value: string | undefined | null): string | u
6
6
  /**
7
7
  * Sanitize rich-text/HTML content using DOMPurify with a restrictive allow-list.
8
8
  * Always returns a string (empty string when value is undefined or null).
9
+ *
10
+ * Uses `isomorphic-dompurify` rather than `dompurify` directly: this runs during submission,
11
+ * which is server-side, and bare `dompurify` returns a factory (no `sanitize` method) when it
12
+ * cannot find a `document`. The isomorphic wrapper supplies a jsdom window on the server.
9
13
  */
10
14
  export declare function sanitizeRichText(value: string | undefined | null): Promise<string>;
11
15
  //# sourceMappingURL=dom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../../src/core/security/dom.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAU/E;AA+DD;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxF"}
1
+ {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../../src/core/security/dom.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAU/E;AA+DD;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAOxF"}
@@ -82,11 +82,15 @@ const RICH_TEXT_SANITIZE_CONFIG = {
82
82
  /**
83
83
  * Sanitize rich-text/HTML content using DOMPurify with a restrictive allow-list.
84
84
  * Always returns a string (empty string when value is undefined or null).
85
+ *
86
+ * Uses `isomorphic-dompurify` rather than `dompurify` directly: this runs during submission,
87
+ * which is server-side, and bare `dompurify` returns a factory (no `sanitize` method) when it
88
+ * cannot find a `document`. The isomorphic wrapper supplies a jsdom window on the server.
85
89
  */
86
90
  export async function sanitizeRichText(value) {
87
91
  if (value === undefined || value === null || value.trim().length === 0) {
88
92
  return '';
89
93
  }
90
- const { default: DOMPurify } = await import('dompurify');
94
+ const { default: DOMPurify } = await import('isomorphic-dompurify');
91
95
  return DOMPurify.sanitize(value, RICH_TEXT_SANITIZE_CONFIG);
92
96
  }
@@ -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"}
@@ -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';
@@ -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;AA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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"}
@@ -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;AAGxE,eAAO,MAAM,mBAAmB,GAAI,OAAO,yBAAyB,EAAE,iBAAe,sFAepF,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
- return field.required ? base : z.union([z.literal(''), base], requiredMessage).optional();
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.10.0",
3
+ "version": "0.10.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -185,7 +185,6 @@
185
185
  "chokidar": "3.6.0",
186
186
  "commander": "^14.0.2",
187
187
  "dayjs": "^1.11.19",
188
- "dompurify": "^3.3.3",
189
188
  "dotenv": "^17.2.3",
190
189
  "drizzle-orm": "^0.45.1",
191
190
  "esbuild": "0.27.2",
@@ -195,6 +194,7 @@
195
194
  "glob": "^10.4.5",
196
195
  "gradient-string": "^3.0.0",
197
196
  "international-types": "^0.8.1",
197
+ "isomorphic-dompurify": "^3.19.0",
198
198
  "jiti": "^2.6.1",
199
199
  "jose": "^6.0.11",
200
200
  "jsonwebtoken": "^9.0.2",