@kontent-ai/mcp-server 0.23.0 → 0.23.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.
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { referenceObjectSchema } from "./referenceObjectSchema.js";
|
|
3
|
-
|
|
3
|
+
// Recursive schema for rich text elements within components
|
|
4
|
+
const richTextElementInComponentSchema = z.lazy(() => z.object({
|
|
4
5
|
element: referenceObjectSchema,
|
|
5
|
-
value: z.
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
value: z.string().nullable(),
|
|
7
|
+
components: z.array(richTextComponentSchema).nullable().optional(),
|
|
8
|
+
}));
|
|
9
|
+
// Recursive schema for rich text components
|
|
10
|
+
const richTextComponentSchema = z.lazy(() => z.object({
|
|
8
11
|
id: z.string(),
|
|
9
12
|
type: referenceObjectSchema,
|
|
10
|
-
elements: z.array(
|
|
11
|
-
});
|
|
13
|
+
elements: z.array(richTextElementInComponentSchema),
|
|
14
|
+
}));
|
|
12
15
|
const assetInVariantElementSchema = z.object({
|
|
13
16
|
element: referenceObjectSchema,
|
|
14
17
|
value: z.array(referenceObjectSchema).nullable(),
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as assert from "node:assert";
|
|
2
|
+
import { describe, it } from "mocha";
|
|
3
|
+
import { languageVariantElementSchema } from "../../schemas/contentItemSchemas.js";
|
|
4
|
+
describe("languageVariantElementSchema", () => {
|
|
5
|
+
describe("nested rich text components", () => {
|
|
6
|
+
it("validates rich text element with deeply nested components", () => {
|
|
7
|
+
const nestedRichTextElement = {
|
|
8
|
+
element: { id: "1fefb369-53b9-4108-9ca3-837c99010c29" },
|
|
9
|
+
value: '<p>rich1</p>\n<object type="application/kenticocloud" data-type="component" data-id="20a941ec-91bf-4a40-89c8-90b5e31dae27"></object>',
|
|
10
|
+
components: [
|
|
11
|
+
{
|
|
12
|
+
id: "20a941ec-91bf-4a40-89c8-90b5e31dae27",
|
|
13
|
+
type: { id: "da3871d1-f942-4d8c-b518-f4c6c97c5174" },
|
|
14
|
+
elements: [
|
|
15
|
+
{
|
|
16
|
+
element: { id: "1fefb369-53b9-4108-9ca3-837c99010c29" },
|
|
17
|
+
value: '<p>rich2 nested</p>\n<object type="application/kenticocloud" data-type="component" data-id="5dd61cc6-d375-49d7-a8e3-e4dcd029be1a"></object>',
|
|
18
|
+
components: [
|
|
19
|
+
{
|
|
20
|
+
id: "5dd61cc6-d375-49d7-a8e3-e4dcd029be1a",
|
|
21
|
+
type: { id: "da3871d1-f942-4d8c-b518-f4c6c97c5174" },
|
|
22
|
+
elements: [
|
|
23
|
+
{
|
|
24
|
+
value: "<p>rich3 nested nested</p>",
|
|
25
|
+
element: { id: "1fefb369-53b9-4108-9ca3-837c99010c29" },
|
|
26
|
+
components: [],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
const result = languageVariantElementSchema.safeParse(nestedRichTextElement);
|
|
37
|
+
assert.strictEqual(result.success, true, `Schema validation failed: ${result.success ? "" : JSON.stringify(result.error.issues, null, 2)}`);
|
|
38
|
+
if (result.success) {
|
|
39
|
+
assert.deepStrictEqual(result.data, nestedRichTextElement, "Parsed data should match input exactly");
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
it("validates rich text element with single level components", () => {
|
|
43
|
+
const richTextElement = {
|
|
44
|
+
element: { id: "1849f877-cd37-4ed0-8df6-3173748a126f" },
|
|
45
|
+
value: "<p>Some content</p>",
|
|
46
|
+
components: [
|
|
47
|
+
{
|
|
48
|
+
id: "af87f9d1-a448-489b-a5bd-9ab3e5e5f2e2",
|
|
49
|
+
type: { id: "924daea8-5d87-4e7c-8c22-7b66044593c3" },
|
|
50
|
+
elements: [
|
|
51
|
+
{
|
|
52
|
+
element: { id: "924daea8-5d87-4e7c-8c22-7b66044593c3" },
|
|
53
|
+
value: "Nested value",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
const result = languageVariantElementSchema.safeParse(richTextElement);
|
|
60
|
+
assert.strictEqual(result.success, true);
|
|
61
|
+
});
|
|
62
|
+
it("validates rich text element with empty components array", () => {
|
|
63
|
+
const richTextElement = {
|
|
64
|
+
element: { id: "c0021332-250b-46d0-a283-c114c85f6062" },
|
|
65
|
+
value: "<p>Some content</p>",
|
|
66
|
+
components: [],
|
|
67
|
+
};
|
|
68
|
+
const result = languageVariantElementSchema.safeParse(richTextElement);
|
|
69
|
+
assert.strictEqual(result.success, true);
|
|
70
|
+
});
|
|
71
|
+
it("validates rich text element with null components", () => {
|
|
72
|
+
const richTextElement = {
|
|
73
|
+
element: { id: "1ae5d294-5861-4555-881c-9279343443a5" },
|
|
74
|
+
value: "<p>Some content</p>",
|
|
75
|
+
components: null,
|
|
76
|
+
};
|
|
77
|
+
const result = languageVariantElementSchema.safeParse(richTextElement);
|
|
78
|
+
assert.strictEqual(result.success, true);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|