@umbraco-cms/mcp-editor 17.6.0-beta.6 → 17.6.0-beta.7
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/collections.js +812 -652
- package/dist/collections.js.map +1 -1
- package/dist/index.js +820 -661
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/dist/collections.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { createMcpClientManager, withStandardDecorators, baseSliceNames, createToolResult, createToolResultError, extractChainedResult,
|
|
2
|
+
import { createMcpClientManager, withStandardDecorators, baseSliceNames, createToolResult, createToolResultError, extractChainedResult, requestApproval, UmbracoManagementClient, encodeCursor } from '@umbraco-cms/mcp-server-sdk';
|
|
3
3
|
import { statSync, readFileSync } from 'fs';
|
|
4
4
|
import { resolve } from 'path';
|
|
5
|
-
import { randomUUID } from 'crypto';
|
|
6
5
|
|
|
7
6
|
// src/umbraco-api/tools/content/get/search-content.ts
|
|
8
7
|
|
|
@@ -88,6 +87,12 @@ function extractInnerProblemDetails(result) {
|
|
|
88
87
|
return parsed;
|
|
89
88
|
}
|
|
90
89
|
} catch {
|
|
90
|
+
return {
|
|
91
|
+
type: "Error",
|
|
92
|
+
title: "Chained tool error",
|
|
93
|
+
status: 500,
|
|
94
|
+
detail: `Chained CMS tool returned a non-JSON error: ${text}`
|
|
95
|
+
};
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
}
|
|
@@ -98,12 +103,28 @@ function extractInnerProblemDetails(result) {
|
|
|
98
103
|
detail: "Chained CMS tool returned an error with no structured details."
|
|
99
104
|
};
|
|
100
105
|
}
|
|
106
|
+
function truncateAvailableTools(message) {
|
|
107
|
+
const availableToolsIndex = message.indexOf(". Available tools");
|
|
108
|
+
if (availableToolsIndex === -1 || !message.includes("Tool not found:")) {
|
|
109
|
+
return message;
|
|
110
|
+
}
|
|
111
|
+
return message.slice(0, availableToolsIndex + 1);
|
|
112
|
+
}
|
|
113
|
+
async function isCmsToolAvailable(toolName) {
|
|
114
|
+
try {
|
|
115
|
+
const { tools } = await mcpClientManager.listTools("cms");
|
|
116
|
+
return (tools ?? []).some((t) => t.name === toolName);
|
|
117
|
+
} catch {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
101
121
|
async function chainCms(toolName, args) {
|
|
102
122
|
let result;
|
|
103
123
|
try {
|
|
104
124
|
result = await mcpClientManager.callTool("cms", toolName, args);
|
|
105
125
|
} catch (error) {
|
|
106
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
126
|
+
const message = truncateAvailableTools(error instanceof Error ? error.message : String(error));
|
|
127
|
+
console.warn(`Chained CMS tool "${toolName}" failed: ${message}`);
|
|
107
128
|
return {
|
|
108
129
|
ok: false,
|
|
109
130
|
errorResult: createToolResultError({
|
|
@@ -458,6 +479,19 @@ var tool3 = {
|
|
|
458
479
|
}
|
|
459
480
|
};
|
|
460
481
|
var list_children_default = withStandardDecorators(tool3);
|
|
482
|
+
|
|
483
|
+
// src/auth/auth-policies.ts
|
|
484
|
+
var sections = {
|
|
485
|
+
settings: "Umb.Section.Settings"};
|
|
486
|
+
|
|
487
|
+
// src/umbraco-api/tools/helpers/settings-access.ts
|
|
488
|
+
async function checkSettingsAccess() {
|
|
489
|
+
const result = await chainCms("get-user-current", {});
|
|
490
|
+
if (!result.ok) return result;
|
|
491
|
+
return { ok: true, hasAccess: result.data.allowedSections?.includes(sections.settings) ?? false };
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/umbraco-api/tools/content/get/list-document-types.ts
|
|
461
495
|
var inputSchema4 = {
|
|
462
496
|
take: z.number().optional().default(50).describe("Number of results to return"),
|
|
463
497
|
skip: z.number().optional().default(0).describe("Number of results to skip")
|
|
@@ -480,11 +514,14 @@ async function collectDocumentTypeIds() {
|
|
|
480
514
|
let result;
|
|
481
515
|
while (true) {
|
|
482
516
|
result = parentId ? await chainCms("get-document-type-children", { parentId, cursor }) : await chainCms("get-document-type-root", { cursor });
|
|
483
|
-
if (!result.ok) return;
|
|
517
|
+
if (!result.ok) return { ok: false, errorResult: result.errorResult };
|
|
484
518
|
const items = result.data.items ?? [];
|
|
485
519
|
for (const item of items) {
|
|
486
520
|
if (item.isFolder) {
|
|
487
|
-
if (item.hasChildren)
|
|
521
|
+
if (item.hasChildren) {
|
|
522
|
+
const childResult = await walk(item.id);
|
|
523
|
+
if (childResult && !childResult.ok) return childResult;
|
|
524
|
+
}
|
|
488
525
|
} else {
|
|
489
526
|
collected.push(item);
|
|
490
527
|
}
|
|
@@ -493,26 +530,35 @@ async function collectDocumentTypeIds() {
|
|
|
493
530
|
if (!nextCursor) break;
|
|
494
531
|
cursor = nextCursor;
|
|
495
532
|
}
|
|
533
|
+
return void 0;
|
|
496
534
|
}
|
|
497
|
-
await walk(void 0);
|
|
498
|
-
return
|
|
535
|
+
const failure = await walk(void 0);
|
|
536
|
+
if (failure && !failure.ok) return failure;
|
|
537
|
+
return { ok: true, nodes: collected };
|
|
499
538
|
}
|
|
500
539
|
async function resolveDocTypeDetails(nodes) {
|
|
501
540
|
const results = await Promise.all(
|
|
502
541
|
nodes.map(async (node) => {
|
|
503
542
|
const detailResult = await chainCms("get-document-type-by-id", { id: node.id });
|
|
504
|
-
if (!detailResult.ok) return
|
|
543
|
+
if (!detailResult.ok) return { ok: false, errorResult: detailResult.errorResult, node };
|
|
505
544
|
const d = detailResult.data;
|
|
506
545
|
return {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
546
|
+
ok: true,
|
|
547
|
+
details: [{
|
|
548
|
+
id: node.id,
|
|
549
|
+
alias: d.alias ?? "",
|
|
550
|
+
name: d.name ?? node.name,
|
|
551
|
+
description: d.description ?? void 0,
|
|
552
|
+
icon: d.icon ?? node.icon
|
|
553
|
+
}],
|
|
554
|
+
node
|
|
512
555
|
};
|
|
513
556
|
})
|
|
514
557
|
);
|
|
515
|
-
|
|
558
|
+
const failed = results.find((r) => !r.ok);
|
|
559
|
+
if (failed && !failed.ok) return { ok: false, errorResult: failed.errorResult };
|
|
560
|
+
const details = results.flatMap((r) => r.ok ? r.details : []);
|
|
561
|
+
return { ok: true, details };
|
|
516
562
|
}
|
|
517
563
|
var tool4 = {
|
|
518
564
|
name: "list-document-types",
|
|
@@ -522,9 +568,22 @@ var tool4 = {
|
|
|
522
568
|
slices: ["list"],
|
|
523
569
|
annotations: { readOnlyHint: true },
|
|
524
570
|
handler: async ({ take, skip }) => {
|
|
525
|
-
const
|
|
571
|
+
const accessCheck = await checkSettingsAccess();
|
|
572
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
573
|
+
if (!accessCheck.hasAccess) {
|
|
574
|
+
return createToolResultError({
|
|
575
|
+
status: 403,
|
|
576
|
+
title: "Settings access required",
|
|
577
|
+
detail: "Listing document types requires the signed-in Umbraco user to have access to the Settings section. Grant Settings-section access to the user's group in the Umbraco backoffice (Users \u2192 [group] \u2192 Sections), then retry."
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
const treeResult = await collectDocumentTypeIds();
|
|
581
|
+
if (!treeResult.ok) return treeResult.errorResult;
|
|
582
|
+
const { nodes } = treeResult;
|
|
526
583
|
const sliced = nodes.slice(skip, skip + take);
|
|
527
|
-
const
|
|
584
|
+
const detailsResult = await resolveDocTypeDetails(sliced);
|
|
585
|
+
if (!detailsResult.ok) return detailsResult.errorResult;
|
|
586
|
+
const { details } = detailsResult;
|
|
528
587
|
return createToolResult({
|
|
529
588
|
items: details.map((d) => ({
|
|
530
589
|
id: d.id,
|
|
@@ -538,6 +597,73 @@ var tool4 = {
|
|
|
538
597
|
}
|
|
539
598
|
};
|
|
540
599
|
var list_document_types_default = withStandardDecorators(tool4);
|
|
600
|
+
|
|
601
|
+
// src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
|
|
602
|
+
async function resolveDocumentTypeProperties(documentTypeId) {
|
|
603
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
604
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
605
|
+
const data = docTypeResult.data;
|
|
606
|
+
const collected = /* @__PURE__ */ new Map();
|
|
607
|
+
function addProperties(props) {
|
|
608
|
+
for (const p of props) {
|
|
609
|
+
if (p.alias && !collected.has(p.alias)) {
|
|
610
|
+
collected.set(p.alias, p);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function compositionIdsOf(d) {
|
|
615
|
+
return Array.from(
|
|
616
|
+
new Set(
|
|
617
|
+
(d.compositions ?? []).map((c) => c.documentType?.id).filter((id) => typeof id === "string")
|
|
618
|
+
)
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
function describeFailure(errorResult) {
|
|
622
|
+
const text = errorResult.content?.[0]?.type === "text" ? errorResult.content[0].text : void 0;
|
|
623
|
+
if (!text) return "unknown error";
|
|
624
|
+
try {
|
|
625
|
+
const parsed = JSON.parse(text);
|
|
626
|
+
const detail = parsed?.detail;
|
|
627
|
+
return typeof detail === "string" ? detail : text;
|
|
628
|
+
} catch {
|
|
629
|
+
return text;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
633
|
+
const visited = /* @__PURE__ */ new Set([documentTypeId]);
|
|
634
|
+
const failedCompositionIds = [];
|
|
635
|
+
const failedCompositionDetails = [];
|
|
636
|
+
let frontier = compositionIdsOf(data).filter((id) => !visited.has(id));
|
|
637
|
+
frontier.forEach((id) => visited.add(id));
|
|
638
|
+
while (frontier.length > 0) {
|
|
639
|
+
const results = await Promise.all(frontier.map((id) => chainCms("get-document-type-by-id", { id })));
|
|
640
|
+
const nextFrontier = [];
|
|
641
|
+
results.forEach((r, i) => {
|
|
642
|
+
if (!r.ok) {
|
|
643
|
+
failedCompositionIds.push(frontier[i]);
|
|
644
|
+
failedCompositionDetails.push(describeFailure(r.errorResult));
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
if (Array.isArray(r.data.properties)) addProperties(r.data.properties);
|
|
648
|
+
for (const id of compositionIdsOf(r.data)) {
|
|
649
|
+
if (!visited.has(id)) {
|
|
650
|
+
visited.add(id);
|
|
651
|
+
nextFrontier.push(id);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
frontier = nextFrontier;
|
|
656
|
+
}
|
|
657
|
+
return {
|
|
658
|
+
ok: true,
|
|
659
|
+
documentType: data,
|
|
660
|
+
properties: Array.from(collected.values()),
|
|
661
|
+
failedCompositionIds,
|
|
662
|
+
failedCompositionDetails
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/umbraco-api/tools/content/get/get-document-type.ts
|
|
541
667
|
var inputSchema5 = {
|
|
542
668
|
id: z.string().uuid().describe("UUID of the document type to retrieve")
|
|
543
669
|
};
|
|
@@ -565,30 +691,9 @@ var tool5 = {
|
|
|
565
691
|
slices: ["read"],
|
|
566
692
|
annotations: { readOnlyHint: true },
|
|
567
693
|
handler: async ({ id }) => {
|
|
568
|
-
const result = await
|
|
694
|
+
const result = await resolveDocumentTypeProperties(id);
|
|
569
695
|
if (!result.ok) return result.errorResult;
|
|
570
|
-
const data = result
|
|
571
|
-
const collected = /* @__PURE__ */ new Map();
|
|
572
|
-
function addProperties(props) {
|
|
573
|
-
for (const p of props) {
|
|
574
|
-
if (p.alias && !collected.has(p.alias)) {
|
|
575
|
-
collected.set(p.alias, p);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
580
|
-
const compositionIds = (data.compositions ?? []).map((c) => c.document?.id ?? c.documentType?.id ?? c.id).filter((cid) => typeof cid === "string");
|
|
581
|
-
if (compositionIds.length > 0) {
|
|
582
|
-
const compositions = await Promise.all(
|
|
583
|
-
compositionIds.map(async (cid) => {
|
|
584
|
-
const r = await chainCms("get-document-type-by-id", { id: cid });
|
|
585
|
-
return r.ok ? r.data : null;
|
|
586
|
-
})
|
|
587
|
-
);
|
|
588
|
-
for (const comp of compositions) {
|
|
589
|
-
if (comp && Array.isArray(comp.properties)) addProperties(comp.properties);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
696
|
+
const { documentType: data, properties } = result;
|
|
592
697
|
return createToolResult({
|
|
593
698
|
id: data.id ?? id,
|
|
594
699
|
alias: data.alias ?? "",
|
|
@@ -596,7 +701,7 @@ var tool5 = {
|
|
|
596
701
|
description: data.description || void 0,
|
|
597
702
|
variesByCulture: data.variesByCulture || void 0,
|
|
598
703
|
variesBySegment: data.variesBySegment || void 0,
|
|
599
|
-
properties:
|
|
704
|
+
properties: properties.map((p) => ({
|
|
600
705
|
alias: p.alias ?? "",
|
|
601
706
|
name: p.name ?? p.alias ?? "",
|
|
602
707
|
description: p.description || void 0,
|
|
@@ -608,6 +713,228 @@ var tool5 = {
|
|
|
608
713
|
}
|
|
609
714
|
};
|
|
610
715
|
var get_document_type_default = withStandardDecorators(tool5);
|
|
716
|
+
var validationErrorSchema = z.object({
|
|
717
|
+
propertyAlias: z.string().describe(
|
|
718
|
+
"The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
|
|
719
|
+
),
|
|
720
|
+
culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
|
|
721
|
+
segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
|
|
722
|
+
message: z.string().describe("Human-readable validation error message.")
|
|
723
|
+
});
|
|
724
|
+
var validationResultSchema = z.object({
|
|
725
|
+
valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
|
|
726
|
+
errors: z.array(validationErrorSchema).describe(
|
|
727
|
+
"Property-level validation errors. Empty when `valid` is true. Each entry names the offending propertyAlias/culture/segment and a human message \u2014 surface these back to the editor so they know what to fix before publishing."
|
|
728
|
+
)
|
|
729
|
+
}).describe(
|
|
730
|
+
"Server-side validation outcome for the saved document. A 200 OK on save does NOT imply publishability \u2014 Umbraco only enforces required fields, regex, length, etc. via this validation endpoint. When `valid` is false the changes ARE persisted as a draft but the document cannot be published until the listed errors are resolved."
|
|
731
|
+
);
|
|
732
|
+
async function validateDocumentState(id, doc) {
|
|
733
|
+
let target = null;
|
|
734
|
+
if (!target) {
|
|
735
|
+
const docResult = await chainCms("get-document-by-id", { id });
|
|
736
|
+
if (!docResult.ok) {
|
|
737
|
+
return {
|
|
738
|
+
valid: false,
|
|
739
|
+
errors: [
|
|
740
|
+
{
|
|
741
|
+
propertyAlias: "__document__",
|
|
742
|
+
message: "Could not refetch document to run validation."
|
|
743
|
+
}
|
|
744
|
+
]
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
target = docResult.data;
|
|
748
|
+
}
|
|
749
|
+
const values = (target.values ?? []).map((v) => ({
|
|
750
|
+
alias: v.alias,
|
|
751
|
+
value: v.value,
|
|
752
|
+
culture: v.culture ?? null,
|
|
753
|
+
segment: v.segment ?? null
|
|
754
|
+
}));
|
|
755
|
+
const variants = (target.variants ?? []).map((v) => ({
|
|
756
|
+
name: v.name,
|
|
757
|
+
culture: v.culture ?? null,
|
|
758
|
+
segment: v.segment ?? null
|
|
759
|
+
}));
|
|
760
|
+
const ancestorsResult = await chainCms("get-document-ancestors", { descendantId: id });
|
|
761
|
+
const parent = ancestorsResult.ok ? (ancestorsResult.data.items ?? []).find((item) => item.id === id)?.parent ?? null : null;
|
|
762
|
+
const result = await chainCms("validate-document", {
|
|
763
|
+
id,
|
|
764
|
+
documentType: { id: target.documentType.id },
|
|
765
|
+
template: target.template ? { id: target.template.id } : null,
|
|
766
|
+
parent,
|
|
767
|
+
values,
|
|
768
|
+
variants
|
|
769
|
+
});
|
|
770
|
+
if (result.ok) {
|
|
771
|
+
return { valid: true, errors: [] };
|
|
772
|
+
}
|
|
773
|
+
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
774
|
+
}
|
|
775
|
+
function parseValidationErrors(errorResult, requestValues) {
|
|
776
|
+
const structured = extractStructured(errorResult);
|
|
777
|
+
if (!structured) {
|
|
778
|
+
return [
|
|
779
|
+
{
|
|
780
|
+
propertyAlias: "__document__",
|
|
781
|
+
message: stringifyErrorFallback(errorResult)
|
|
782
|
+
}
|
|
783
|
+
];
|
|
784
|
+
}
|
|
785
|
+
const errors = structured.errors;
|
|
786
|
+
if (!errors || typeof errors !== "object") {
|
|
787
|
+
return [
|
|
788
|
+
{
|
|
789
|
+
propertyAlias: "__document__",
|
|
790
|
+
message: stringifyFromProblemDetails(structured)
|
|
791
|
+
}
|
|
792
|
+
];
|
|
793
|
+
}
|
|
794
|
+
const out = [];
|
|
795
|
+
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
796
|
+
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
797
|
+
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
798
|
+
for (const message of messageList) {
|
|
799
|
+
out.push({
|
|
800
|
+
propertyAlias: resolved.propertyAlias,
|
|
801
|
+
culture: resolved.culture,
|
|
802
|
+
segment: resolved.segment,
|
|
803
|
+
message: String(message)
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (out.length === 0) {
|
|
808
|
+
out.push({
|
|
809
|
+
propertyAlias: "__document__",
|
|
810
|
+
message: stringifyFromProblemDetails(structured)
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
return out;
|
|
814
|
+
}
|
|
815
|
+
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
816
|
+
function resolveJsonPath(jsonPath, requestValues) {
|
|
817
|
+
const match = jsonPath.match(VALUES_PATH);
|
|
818
|
+
if (match) {
|
|
819
|
+
const index = Number(match[1]);
|
|
820
|
+
const entry = requestValues[index];
|
|
821
|
+
if (entry) {
|
|
822
|
+
const trailing = match[2]?.replace(/^\./, "");
|
|
823
|
+
return {
|
|
824
|
+
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
825
|
+
culture: entry.culture,
|
|
826
|
+
segment: entry.segment
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
831
|
+
}
|
|
832
|
+
function extractStructured(errorResult) {
|
|
833
|
+
if (!errorResult || typeof errorResult !== "object") return null;
|
|
834
|
+
const r = errorResult;
|
|
835
|
+
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
836
|
+
return r.structuredContent;
|
|
837
|
+
}
|
|
838
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
839
|
+
if (text) {
|
|
840
|
+
try {
|
|
841
|
+
const parsed = JSON.parse(text);
|
|
842
|
+
if (parsed && typeof parsed === "object") {
|
|
843
|
+
return parsed;
|
|
844
|
+
}
|
|
845
|
+
} catch {
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return null;
|
|
849
|
+
}
|
|
850
|
+
function stringifyFromProblemDetails(pd) {
|
|
851
|
+
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
852
|
+
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
853
|
+
return "Document failed validation but no detail was returned.";
|
|
854
|
+
}
|
|
855
|
+
function stringifyErrorFallback(errorResult) {
|
|
856
|
+
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
857
|
+
const r = errorResult;
|
|
858
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
859
|
+
return text ? text : "Document failed validation.";
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
863
|
+
async function toBlockProperties(elementTypeKey, values, culture, segment) {
|
|
864
|
+
if (values.length === 0) return { ok: true, properties: [] };
|
|
865
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: elementTypeKey });
|
|
866
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
867
|
+
const definitions = new Map(docTypeResult.data.properties.map((p) => [p.alias, p]));
|
|
868
|
+
return {
|
|
869
|
+
ok: true,
|
|
870
|
+
properties: values.map((v) => {
|
|
871
|
+
const def = definitions.get(v.alias);
|
|
872
|
+
return {
|
|
873
|
+
alias: v.alias,
|
|
874
|
+
value: v.value,
|
|
875
|
+
culture: def?.variesByCulture ? culture : null,
|
|
876
|
+
segment: def?.variesBySegment ? segment : null
|
|
877
|
+
};
|
|
878
|
+
})
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
async function toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, culture, segment) {
|
|
882
|
+
const content = await toBlockProperties(contentTypeKey, values, culture, segment);
|
|
883
|
+
if (!content.ok) return content;
|
|
884
|
+
if (!settingsTypeKey || !settingsValues) return { ok: true, properties: content.properties };
|
|
885
|
+
const settings = await toBlockProperties(settingsTypeKey, settingsValues, culture, segment);
|
|
886
|
+
if (!settings.ok) return settings;
|
|
887
|
+
return { ok: true, properties: content.properties, settings: { properties: settings.properties } };
|
|
888
|
+
}
|
|
889
|
+
function toPlacement(position) {
|
|
890
|
+
return position.mode === "before" || position.mode === "after" ? { position: position.mode, contentKey: position.anchorContentKey } : { position: position.mode };
|
|
891
|
+
}
|
|
892
|
+
async function buildBlockWriteResult(id, pageName, contentKey, baseMessage) {
|
|
893
|
+
const validation = await validateDocumentState(id);
|
|
894
|
+
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
895
|
+
return createToolResult({
|
|
896
|
+
message,
|
|
897
|
+
id,
|
|
898
|
+
name: pageName,
|
|
899
|
+
contentKey,
|
|
900
|
+
previewUrl: await fetchPreviewUrl(id),
|
|
901
|
+
validation
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
function isBlockListOrGridValue(value) {
|
|
905
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
906
|
+
}
|
|
907
|
+
function isRteWithBlocks(value) {
|
|
908
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
|
|
909
|
+
}
|
|
910
|
+
function findSettingsKey(container, contentKey) {
|
|
911
|
+
const layout = container?.layout;
|
|
912
|
+
if (!layout || typeof layout !== "object") return void 0;
|
|
913
|
+
return searchLayout(Object.values(layout), contentKey);
|
|
914
|
+
}
|
|
915
|
+
function searchLayout(entries, contentKey) {
|
|
916
|
+
for (const entry of entries) {
|
|
917
|
+
if (Array.isArray(entry)) {
|
|
918
|
+
const found = searchLayout(entry, contentKey);
|
|
919
|
+
if (found) return found;
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (!entry || typeof entry !== "object") continue;
|
|
923
|
+
const candidate = entry;
|
|
924
|
+
if (candidate.contentKey === contentKey) {
|
|
925
|
+
return typeof candidate.settingsKey === "string" && candidate.settingsKey.length > 0 ? candidate.settingsKey : void 0;
|
|
926
|
+
}
|
|
927
|
+
for (const nested of [candidate.areas, candidate.items]) {
|
|
928
|
+
if (Array.isArray(nested)) {
|
|
929
|
+
const found = searchLayout(nested, contentKey);
|
|
930
|
+
if (found) return found;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return void 0;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/umbraco-api/tools/content/get/inspect-blocks.ts
|
|
611
938
|
var inputSchema6 = {
|
|
612
939
|
id: z.string().uuid().describe("The ID of the page to inspect"),
|
|
613
940
|
propertyAlias: z.string().optional().describe("Specific property alias to inspect. If omitted, all block-based properties are shown.")
|
|
@@ -622,6 +949,7 @@ var outputSchema6 = z.object({
|
|
|
622
949
|
blocks: z.array(z.object({
|
|
623
950
|
contentKey: z.string().describe("The block's unique key \u2014 use this with edit-block"),
|
|
624
951
|
contentTypeKey: z.string().describe("The block's element type ID"),
|
|
952
|
+
settingsKey: z.string().optional().describe("The key of the block's settings entry. Absent when the block has no settings."),
|
|
625
953
|
properties: z.array(z.object({
|
|
626
954
|
alias: z.string(),
|
|
627
955
|
value: z.any()
|
|
@@ -629,18 +957,23 @@ var outputSchema6 = z.object({
|
|
|
629
957
|
}))
|
|
630
958
|
}))
|
|
631
959
|
});
|
|
632
|
-
function
|
|
960
|
+
function isBlockListOrGridValue2(value) {
|
|
633
961
|
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
634
962
|
}
|
|
635
|
-
function
|
|
963
|
+
function isRteWithBlocks2(value) {
|
|
636
964
|
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
|
|
637
965
|
}
|
|
638
|
-
function extractBlocks(contentData) {
|
|
639
|
-
return contentData.map((block) =>
|
|
640
|
-
contentKey
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
966
|
+
function extractBlocks(contentData, container) {
|
|
967
|
+
return contentData.map((block) => {
|
|
968
|
+
const contentKey = block.key ?? "";
|
|
969
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
970
|
+
return {
|
|
971
|
+
contentKey,
|
|
972
|
+
contentTypeKey: block.contentTypeKey ?? "",
|
|
973
|
+
...settingsKey ? { settingsKey } : {},
|
|
974
|
+
properties: Array.isArray(block.values) ? block.values.map((v) => ({ alias: v.alias ?? "", value: v.value })) : []
|
|
975
|
+
};
|
|
976
|
+
});
|
|
644
977
|
}
|
|
645
978
|
var tool6 = {
|
|
646
979
|
name: "inspect-blocks",
|
|
@@ -655,19 +988,19 @@ var tool6 = {
|
|
|
655
988
|
const doc = result.data;
|
|
656
989
|
const allValues = doc.values ?? [];
|
|
657
990
|
const filtered = propertyAlias ? allValues.filter((v) => v.alias === propertyAlias) : allValues;
|
|
658
|
-
const blockProperties = filtered.filter((v) =>
|
|
991
|
+
const blockProperties = filtered.filter((v) => isBlockListOrGridValue2(v.value) || isRteWithBlocks2(v.value)).map((v) => {
|
|
659
992
|
const value = v.value;
|
|
660
|
-
if (
|
|
993
|
+
if (isRteWithBlocks2(value)) {
|
|
661
994
|
return {
|
|
662
995
|
propertyAlias: v.alias,
|
|
663
996
|
editorAlias: "Umbraco.RichText",
|
|
664
|
-
blocks: extractBlocks(value.blocks.contentData)
|
|
997
|
+
blocks: extractBlocks(value.blocks.contentData, value.blocks)
|
|
665
998
|
};
|
|
666
999
|
}
|
|
667
1000
|
return {
|
|
668
1001
|
propertyAlias: v.alias,
|
|
669
1002
|
editorAlias: v.editorAlias ?? void 0,
|
|
670
|
-
blocks: extractBlocks(value.contentData)
|
|
1003
|
+
blocks: extractBlocks(value.contentData, value)
|
|
671
1004
|
};
|
|
672
1005
|
});
|
|
673
1006
|
return createToolResult({
|
|
@@ -1008,150 +1341,76 @@ ${aliases.join("\n")}`
|
|
|
1008
1341
|
}
|
|
1009
1342
|
};
|
|
1010
1343
|
var get_property_value_template_default = withStandardDecorators(tool10);
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
)
|
|
1024
|
-
})
|
|
1025
|
-
|
|
1026
|
-
)
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
if (!target) {
|
|
1030
|
-
const docResult = await chainCms("get-document-by-id", { id });
|
|
1031
|
-
if (!docResult.ok) {
|
|
1032
|
-
return {
|
|
1033
|
-
valid: false,
|
|
1034
|
-
errors: [
|
|
1035
|
-
{
|
|
1036
|
-
propertyAlias: "__document__",
|
|
1037
|
-
message: "Could not refetch document to run validation."
|
|
1038
|
-
}
|
|
1039
|
-
]
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
target = docResult.data;
|
|
1043
|
-
}
|
|
1044
|
-
const values = (target.values ?? []).map((v) => ({
|
|
1045
|
-
alias: v.alias,
|
|
1046
|
-
value: v.value,
|
|
1047
|
-
culture: v.culture ?? null,
|
|
1048
|
-
segment: v.segment ?? null
|
|
1049
|
-
}));
|
|
1050
|
-
const variants = (target.variants ?? []).map((v) => ({
|
|
1051
|
-
name: v.name,
|
|
1052
|
-
culture: v.culture ?? null,
|
|
1053
|
-
segment: v.segment ?? null
|
|
1054
|
-
}));
|
|
1055
|
-
const ancestorsResult = await chainCms("get-document-ancestors", { descendantId: id });
|
|
1056
|
-
const parent = ancestorsResult.ok ? (ancestorsResult.data.items ?? []).find((item) => item.id === id)?.parent ?? null : null;
|
|
1057
|
-
const result = await chainCms("validate-document", {
|
|
1058
|
-
id,
|
|
1059
|
-
documentType: { id: target.documentType.id },
|
|
1060
|
-
template: target.template ? { id: target.template.id } : null,
|
|
1061
|
-
parent,
|
|
1062
|
-
values,
|
|
1063
|
-
variants
|
|
1064
|
-
});
|
|
1065
|
-
if (result.ok) {
|
|
1066
|
-
return { valid: true, errors: [] };
|
|
1067
|
-
}
|
|
1068
|
-
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
1069
|
-
}
|
|
1070
|
-
function parseValidationErrors(errorResult, requestValues) {
|
|
1071
|
-
const structured = extractStructured(errorResult);
|
|
1072
|
-
if (!structured) {
|
|
1073
|
-
return [
|
|
1074
|
-
{
|
|
1075
|
-
propertyAlias: "__document__",
|
|
1076
|
-
message: stringifyErrorFallback(errorResult)
|
|
1077
|
-
}
|
|
1078
|
-
];
|
|
1079
|
-
}
|
|
1080
|
-
const errors = structured.errors;
|
|
1081
|
-
if (!errors || typeof errors !== "object") {
|
|
1082
|
-
return [
|
|
1083
|
-
{
|
|
1084
|
-
propertyAlias: "__document__",
|
|
1085
|
-
message: stringifyFromProblemDetails(structured)
|
|
1086
|
-
}
|
|
1087
|
-
];
|
|
1088
|
-
}
|
|
1089
|
-
const out = [];
|
|
1090
|
-
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
1091
|
-
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
1092
|
-
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
1093
|
-
for (const message of messageList) {
|
|
1094
|
-
out.push({
|
|
1095
|
-
propertyAlias: resolved.propertyAlias,
|
|
1096
|
-
culture: resolved.culture,
|
|
1097
|
-
segment: resolved.segment,
|
|
1098
|
-
message: String(message)
|
|
1099
|
-
});
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
if (out.length === 0) {
|
|
1103
|
-
out.push({
|
|
1104
|
-
propertyAlias: "__document__",
|
|
1105
|
-
message: stringifyFromProblemDetails(structured)
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
return out;
|
|
1109
|
-
}
|
|
1110
|
-
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
1111
|
-
function resolveJsonPath(jsonPath, requestValues) {
|
|
1112
|
-
const match = jsonPath.match(VALUES_PATH);
|
|
1113
|
-
if (match) {
|
|
1114
|
-
const index = Number(match[1]);
|
|
1115
|
-
const entry = requestValues[index];
|
|
1116
|
-
if (entry) {
|
|
1117
|
-
const trailing = match[2]?.replace(/^\./, "");
|
|
1118
|
-
return {
|
|
1119
|
-
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
1120
|
-
culture: entry.culture,
|
|
1121
|
-
segment: entry.segment
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
1126
|
-
}
|
|
1127
|
-
function extractStructured(errorResult) {
|
|
1128
|
-
if (!errorResult || typeof errorResult !== "object") return null;
|
|
1129
|
-
const r = errorResult;
|
|
1130
|
-
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
1131
|
-
return r.structuredContent;
|
|
1344
|
+
async function resolveEditorAliases(documentTypeId, values) {
|
|
1345
|
+
if (!values || values.length === 0) {
|
|
1346
|
+
return { ok: true, values: [] };
|
|
1347
|
+
}
|
|
1348
|
+
const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
|
|
1349
|
+
if (!docTypeResult.ok) return docTypeResult;
|
|
1350
|
+
const dataTypeIds = Array.from(
|
|
1351
|
+
new Set(
|
|
1352
|
+
docTypeResult.properties.map((p) => p.dataType?.id).filter((id) => typeof id === "string")
|
|
1353
|
+
)
|
|
1354
|
+
);
|
|
1355
|
+
const editorAliasByDataTypeId = /* @__PURE__ */ new Map();
|
|
1356
|
+
if (dataTypeIds.length > 0) {
|
|
1357
|
+
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1358
|
+
if (!dataTypesResult.ok) return dataTypesResult;
|
|
1359
|
+
for (const dt of dataTypesResult.data.items) {
|
|
1360
|
+
if (dt.id && dt.editorAlias) editorAliasByDataTypeId.set(dt.id, dt.editorAlias);
|
|
1361
|
+
}
|
|
1132
1362
|
}
|
|
1133
|
-
const
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1363
|
+
const propertyAliases = new Set(
|
|
1364
|
+
docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
|
|
1365
|
+
);
|
|
1366
|
+
const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
|
|
1367
|
+
for (const prop of docTypeResult.properties) {
|
|
1368
|
+
const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
|
|
1369
|
+
if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1370
|
+
}
|
|
1371
|
+
const notAProperty = /* @__PURE__ */ new Set();
|
|
1372
|
+
const missingEditorAlias = /* @__PURE__ */ new Set();
|
|
1373
|
+
const resolved = values.map((v) => {
|
|
1374
|
+
const editorAlias = editorAliasByPropertyAlias.get(v.alias);
|
|
1375
|
+
if (!editorAlias) {
|
|
1376
|
+
if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
|
|
1377
|
+
else notAProperty.add(v.alias);
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
alias: v.alias,
|
|
1381
|
+
value: v.value,
|
|
1382
|
+
culture: v.culture ?? null,
|
|
1383
|
+
segment: v.segment ?? null,
|
|
1384
|
+
editorAlias: editorAlias ?? ""
|
|
1385
|
+
};
|
|
1386
|
+
});
|
|
1387
|
+
if (notAProperty.size > 0 || missingEditorAlias.size > 0) {
|
|
1388
|
+
const messages = [];
|
|
1389
|
+
if (notAProperty.size > 0) {
|
|
1390
|
+
if (docTypeResult.failedCompositionIds.length > 0) {
|
|
1391
|
+
const failures = docTypeResult.failedCompositionIds.map((id, i) => `${id} (${docTypeResult.failedCompositionDetails[i]})`).join(", ");
|
|
1392
|
+
messages.push(
|
|
1393
|
+
`not found among the resolvable properties on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")} \u2014 but ${docTypeResult.failedCompositionIds.length} composition(s) could not be loaded: ${failures}, so one of these aliases may actually be valid and just unverifiable right now. Resolve the composition failure(s) above and retry`
|
|
1394
|
+
);
|
|
1395
|
+
} else {
|
|
1396
|
+
messages.push(
|
|
1397
|
+
`not a property on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")}`
|
|
1398
|
+
);
|
|
1139
1399
|
}
|
|
1140
|
-
} catch {
|
|
1141
1400
|
}
|
|
1401
|
+
if (missingEditorAlias.size > 0) {
|
|
1402
|
+
messages.push(
|
|
1403
|
+
`a property on this document type, but its data type has no resolvable editor alias: ${Array.from(missingEditorAlias).join(", ")}`
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1406
|
+
return {
|
|
1407
|
+
ok: false,
|
|
1408
|
+
errorResult: createToolResultError(
|
|
1409
|
+
`The following value alias(es) could not be resolved \u2014 ${messages.join("; ")}. Call get-document-type to see the valid property aliases for this document type.`
|
|
1410
|
+
)
|
|
1411
|
+
};
|
|
1142
1412
|
}
|
|
1143
|
-
return
|
|
1144
|
-
}
|
|
1145
|
-
function stringifyFromProblemDetails(pd) {
|
|
1146
|
-
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
1147
|
-
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
1148
|
-
return "Document failed validation but no detail was returned.";
|
|
1149
|
-
}
|
|
1150
|
-
function stringifyErrorFallback(errorResult) {
|
|
1151
|
-
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
1152
|
-
const r = errorResult;
|
|
1153
|
-
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
1154
|
-
return text ? text : "Document failed validation.";
|
|
1413
|
+
return { ok: true, values: resolved };
|
|
1155
1414
|
}
|
|
1156
1415
|
|
|
1157
1416
|
// src/umbraco-api/tools/content/post/create-page.ts
|
|
@@ -1181,31 +1440,12 @@ var tool11 = {
|
|
|
1181
1440
|
slices: ["create"],
|
|
1182
1441
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1183
1442
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1184
|
-
const
|
|
1185
|
-
if (
|
|
1186
|
-
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
1187
|
-
if (!docTypeResult.ok) return docTypeResult.errorResult;
|
|
1188
|
-
const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
|
|
1189
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1190
|
-
if (!dataTypesResult.ok) return dataTypesResult.errorResult;
|
|
1191
|
-
const editorAliasByDataTypeId = new Map(
|
|
1192
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
1193
|
-
);
|
|
1194
|
-
for (const prop of docTypeResult.data.properties) {
|
|
1195
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
1196
|
-
if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1443
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1444
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1199
1445
|
const createResult = await chainCms("create-document", {
|
|
1200
1446
|
documentTypeId,
|
|
1201
1447
|
name,
|
|
1202
|
-
values:
|
|
1203
|
-
alias: v.alias,
|
|
1204
|
-
value: v.value,
|
|
1205
|
-
culture: v.culture ?? null,
|
|
1206
|
-
segment: v.segment ?? null,
|
|
1207
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
1208
|
-
})),
|
|
1448
|
+
values: resolved.values,
|
|
1209
1449
|
...parentId ? { parentId } : {}
|
|
1210
1450
|
});
|
|
1211
1451
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -1242,41 +1482,50 @@ var outputSchema12 = z.object({
|
|
|
1242
1482
|
});
|
|
1243
1483
|
var tool12 = {
|
|
1244
1484
|
name: "create-and-publish-page",
|
|
1245
|
-
description: "Create a new content page and publish it
|
|
1485
|
+
description: "Create a new content page and publish it \u2014 mirrors clicking 'Save and publish' (instead of 'Save') on the create screen in the Umbraco backoffice. This is a single atomic operation when the connected Umbraco instance supports it (17.6+); otherwise a two-call create-then-publish sequence is used. Call list-document-types first to find a valid documentTypeId. Use this as a starting point: pass `name`, `documentTypeId`, optional `parentId`, and at most a small number of simple initial values. Required-property validation runs at publish time, not create time: on the atomic path a validation failure leaves no page behind, but on the fallback path the draft can already have been created before publish fails, leaving an unpublished draft. Either way, check the response `message` before retrying \u2014 don't retry blindly, or you may pile up duplicate drafts. Use create-page followed by save-and-publish instead when you need to build up content across multiple calls before publishing.",
|
|
1246
1486
|
inputSchema: inputSchema12,
|
|
1247
1487
|
outputSchema: outputSchema12,
|
|
1248
1488
|
slices: ["create", "publish"],
|
|
1249
1489
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1250
1490
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1251
|
-
const
|
|
1252
|
-
if (
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
);
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1491
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1492
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1493
|
+
if (await isCmsToolAvailable("create-and-publish-document")) {
|
|
1494
|
+
const createResult = await chainCms("create-and-publish-document", {
|
|
1495
|
+
documentTypeId,
|
|
1496
|
+
name,
|
|
1497
|
+
values: resolved.values,
|
|
1498
|
+
...parentId ? { parentId } : {}
|
|
1499
|
+
});
|
|
1500
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1501
|
+
const createdId2 = createResult.data.id;
|
|
1502
|
+
return createToolResult({
|
|
1503
|
+
message: `Created and published "${name}"`,
|
|
1504
|
+
id: createdId2,
|
|
1505
|
+
name,
|
|
1506
|
+
publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
|
|
1507
|
+
});
|
|
1265
1508
|
}
|
|
1266
|
-
const
|
|
1509
|
+
const createDocumentResult = await chainCms("create-document", {
|
|
1267
1510
|
documentTypeId,
|
|
1268
1511
|
name,
|
|
1269
|
-
values:
|
|
1270
|
-
alias: v.alias,
|
|
1271
|
-
value: v.value,
|
|
1272
|
-
culture: v.culture ?? null,
|
|
1273
|
-
segment: v.segment ?? null,
|
|
1274
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
1275
|
-
})),
|
|
1512
|
+
values: resolved.values,
|
|
1276
1513
|
...parentId ? { parentId } : {}
|
|
1277
1514
|
});
|
|
1278
|
-
if (!
|
|
1279
|
-
const createdId =
|
|
1515
|
+
if (!createDocumentResult.ok) return createDocumentResult.errorResult;
|
|
1516
|
+
const createdId = createDocumentResult.data.id;
|
|
1517
|
+
const publishResult = await chainCms("publish-document", {
|
|
1518
|
+
id: createdId,
|
|
1519
|
+
data: { publishSchedules: [{ culture: null }] }
|
|
1520
|
+
});
|
|
1521
|
+
if (!publishResult.ok) {
|
|
1522
|
+
return createToolResult({
|
|
1523
|
+
message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
1524
|
+
id: createdId,
|
|
1525
|
+
name,
|
|
1526
|
+
publishedUrls: []
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1280
1529
|
return createToolResult({
|
|
1281
1530
|
message: `Created and published "${name}"`,
|
|
1282
1531
|
id: createdId,
|
|
@@ -1329,70 +1578,6 @@ var tool13 = {
|
|
|
1329
1578
|
}
|
|
1330
1579
|
};
|
|
1331
1580
|
var duplicate_page_default = withStandardDecorators(tool13);
|
|
1332
|
-
|
|
1333
|
-
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
1334
|
-
async function resolveBlockEditorAliases(contentTypeKey) {
|
|
1335
|
-
const docTypeResult = await chainCms("get-document-type-by-id", { id: contentTypeKey });
|
|
1336
|
-
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
1337
|
-
const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
|
|
1338
|
-
if (dataTypeIds.length === 0) {
|
|
1339
|
-
return { ok: true, editorAliasByAlias: /* @__PURE__ */ new Map() };
|
|
1340
|
-
}
|
|
1341
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1342
|
-
if (!dataTypesResult.ok) return { ok: false, errorResult: dataTypesResult.errorResult };
|
|
1343
|
-
const editorAliasByDataTypeId = new Map(
|
|
1344
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
1345
|
-
);
|
|
1346
|
-
const editorAliasByAlias = /* @__PURE__ */ new Map();
|
|
1347
|
-
for (const prop of docTypeResult.data.properties) {
|
|
1348
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
1349
|
-
if (editorAlias) editorAliasByAlias.set(prop.alias, editorAlias);
|
|
1350
|
-
}
|
|
1351
|
-
return { ok: true, editorAliasByAlias };
|
|
1352
|
-
}
|
|
1353
|
-
function buildBlockEntry(contentKey, contentTypeKey, values, editorAliasByAlias, culture, segment) {
|
|
1354
|
-
return {
|
|
1355
|
-
key: contentKey,
|
|
1356
|
-
contentTypeKey,
|
|
1357
|
-
values: values.map((v) => ({
|
|
1358
|
-
editorAlias: editorAliasByAlias.get(v.alias) ?? "",
|
|
1359
|
-
culture,
|
|
1360
|
-
segment,
|
|
1361
|
-
alias: v.alias,
|
|
1362
|
-
value: v.value
|
|
1363
|
-
}))
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
function insertAtPosition(list, item, position, matchAnchor) {
|
|
1367
|
-
if (position.mode === "append") return { ok: true, list: [...list, item] };
|
|
1368
|
-
if (position.mode === "prepend") return { ok: true, list: [item, ...list] };
|
|
1369
|
-
const anchorIndex = list.findIndex(matchAnchor);
|
|
1370
|
-
if (anchorIndex === -1) return { ok: false, reason: "anchor-not-found" };
|
|
1371
|
-
const insertIndex = position.mode === "before" ? anchorIndex : anchorIndex + 1;
|
|
1372
|
-
const next = [...list];
|
|
1373
|
-
next.splice(insertIndex, 0, item);
|
|
1374
|
-
return { ok: true, list: next };
|
|
1375
|
-
}
|
|
1376
|
-
function isBlockListOrGridValue2(value) {
|
|
1377
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
1378
|
-
}
|
|
1379
|
-
function isRteWithBlocks2(value) {
|
|
1380
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.markup === "string" && value.blocks !== null && typeof value.blocks === "object" && Array.isArray(value.blocks?.contentData);
|
|
1381
|
-
}
|
|
1382
|
-
function exposeEntry(contentKey, culture, segment) {
|
|
1383
|
-
return { contentKey, culture, segment };
|
|
1384
|
-
}
|
|
1385
|
-
function removeBlockFromContainer(container, contentKey, layoutKey, newLayoutList, doomedSettingsKey) {
|
|
1386
|
-
return {
|
|
1387
|
-
...container,
|
|
1388
|
-
layout: { ...container.layout ?? {}, [layoutKey]: [...newLayoutList] },
|
|
1389
|
-
contentData: (container.contentData ?? []).filter((entry) => entry.key !== contentKey),
|
|
1390
|
-
settingsData: doomedSettingsKey ? (container.settingsData ?? []).filter((entry) => entry.key !== doomedSettingsKey) : container.settingsData ?? [],
|
|
1391
|
-
expose: (container.expose ?? []).filter((entry) => entry.contentKey !== contentKey)
|
|
1392
|
-
};
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
// src/umbraco-api/tools/content/post/add-blocklist-block.ts
|
|
1396
1581
|
var positionSchema = z.object({
|
|
1397
1582
|
mode: z.enum(["append", "prepend", "before", "after"]).describe("Where to place the new block relative to existing blocks"),
|
|
1398
1583
|
anchorContentKey: z.string().uuid().optional().describe("Required for 'before' or 'after' \u2014 the contentKey of the anchor block")
|
|
@@ -1445,64 +1630,25 @@ var tool14 = {
|
|
|
1445
1630
|
const existingProp = (doc.values ?? []).find(
|
|
1446
1631
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1447
1632
|
);
|
|
1448
|
-
|
|
1449
|
-
layout: { "Umbraco.BlockList": [] },
|
|
1450
|
-
contentData: [],
|
|
1451
|
-
settingsData: [],
|
|
1452
|
-
expose: []
|
|
1453
|
-
};
|
|
1454
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1633
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1455
1634
|
return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a BlockList. Use inspect-blocks to confirm the editor type, or add-rte-block / add-blockgrid-block as appropriate.` }], isError: true });
|
|
1456
1635
|
}
|
|
1457
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1458
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1459
|
-
let settingsEditorAliases = null;
|
|
1460
|
-
if (settingsTypeKey) {
|
|
1461
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1462
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1463
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1464
|
-
}
|
|
1465
|
-
const newContentKey = randomUUID();
|
|
1466
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1467
1636
|
const cultureValue = culture ?? null;
|
|
1468
1637
|
const segmentValue = segment ?? null;
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1471
|
-
const
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
layout: { ...propValue.layout ?? {}, [layoutKey]: insertResult.list },
|
|
1481
|
-
contentData: [...propValue.contentData ?? [], newContentEntry],
|
|
1482
|
-
settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
|
|
1483
|
-
expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1484
|
-
};
|
|
1485
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1486
|
-
id,
|
|
1487
|
-
properties: [{
|
|
1488
|
-
alias: propertyAlias,
|
|
1489
|
-
value: newValue,
|
|
1490
|
-
culture: cultureValue,
|
|
1491
|
-
segment: segmentValue
|
|
1492
|
-
}]
|
|
1493
|
-
});
|
|
1494
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1495
|
-
const validation = await validateDocumentState(id);
|
|
1496
|
-
const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
|
|
1497
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1498
|
-
return createToolResult({
|
|
1499
|
-
message,
|
|
1500
|
-
id,
|
|
1501
|
-
name: pageName,
|
|
1502
|
-
contentKey: newContentKey,
|
|
1503
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1504
|
-
validation
|
|
1638
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1639
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1640
|
+
const createResult = await chainCms("create-document-block", {
|
|
1641
|
+
documentId: id,
|
|
1642
|
+
propertyAlias,
|
|
1643
|
+
culture: cultureValue,
|
|
1644
|
+
segment: segmentValue,
|
|
1645
|
+
contentTypeKey,
|
|
1646
|
+
properties: blockProperties.properties,
|
|
1647
|
+
settings: blockProperties.settings,
|
|
1648
|
+
placement: toPlacement(resolvedPosition)
|
|
1505
1649
|
});
|
|
1650
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1651
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1506
1652
|
}
|
|
1507
1653
|
};
|
|
1508
1654
|
var add_blocklist_block_default = withStandardDecorators(tool14);
|
|
@@ -1565,100 +1711,30 @@ var tool15 = {
|
|
|
1565
1711
|
const existingProp = (doc.values ?? []).find(
|
|
1566
1712
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1567
1713
|
);
|
|
1568
|
-
|
|
1569
|
-
layout: { "Umbraco.BlockGrid": [] },
|
|
1570
|
-
contentData: [],
|
|
1571
|
-
settingsData: [],
|
|
1572
|
-
expose: []
|
|
1573
|
-
};
|
|
1574
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1714
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1575
1715
|
return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a BlockGrid. Use inspect-blocks to confirm the editor type, or add-blocklist-block / add-rte-block as appropriate.` }], isError: true });
|
|
1576
1716
|
}
|
|
1577
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1578
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1579
|
-
let settingsEditorAliases = null;
|
|
1580
|
-
if (settingsTypeKey) {
|
|
1581
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1582
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1583
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1584
|
-
}
|
|
1585
|
-
const newContentKey = randomUUID();
|
|
1586
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1587
1717
|
const cultureValue = culture ?? null;
|
|
1588
1718
|
const segmentValue = segment ?? null;
|
|
1589
|
-
const
|
|
1590
|
-
|
|
1591
|
-
const
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
let nextTopLayout;
|
|
1605
|
-
if (areaKey) {
|
|
1606
|
-
const parentIndex = topLayout.findIndex((item) => item.contentKey === parentContentKey);
|
|
1607
|
-
if (parentIndex === -1) {
|
|
1608
|
-
return createToolResultError({ content: [{ type: "text", text: `Parent block '${parentContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
|
|
1609
|
-
}
|
|
1610
|
-
const parent = topLayout[parentIndex];
|
|
1611
|
-
const areas = Array.isArray(parent.areas) ? parent.areas : [];
|
|
1612
|
-
const areaIndex = areas.findIndex((area2) => area2.key === areaKey);
|
|
1613
|
-
if (areaIndex === -1) {
|
|
1614
|
-
return createToolResultError({ content: [{ type: "text", text: `Area '${areaKey}' was not found on parent block '${parentContentKey}'.` }], isError: true });
|
|
1615
|
-
}
|
|
1616
|
-
const area = areas[areaIndex];
|
|
1617
|
-
const insertResult = insertAtPosition(area.items ?? [], layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
|
|
1618
|
-
if (!insertResult.ok) {
|
|
1619
|
-
return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in area '${areaKey}'.` }], isError: true });
|
|
1620
|
-
}
|
|
1621
|
-
const updatedArea = { ...area, items: insertResult.list };
|
|
1622
|
-
const updatedAreas = areas.slice();
|
|
1623
|
-
updatedAreas[areaIndex] = updatedArea;
|
|
1624
|
-
const updatedParent = { ...parent, areas: updatedAreas };
|
|
1625
|
-
nextTopLayout = topLayout.slice();
|
|
1626
|
-
nextTopLayout[parentIndex] = updatedParent;
|
|
1627
|
-
} else {
|
|
1628
|
-
const insertResult = insertAtPosition(topLayout, layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
|
|
1629
|
-
if (!insertResult.ok) {
|
|
1630
|
-
return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
|
|
1719
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1720
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1721
|
+
const createResult = await chainCms("create-document-block", {
|
|
1722
|
+
documentId: id,
|
|
1723
|
+
propertyAlias,
|
|
1724
|
+
culture: cultureValue,
|
|
1725
|
+
segment: segmentValue,
|
|
1726
|
+
contentTypeKey,
|
|
1727
|
+
properties: blockProperties.properties,
|
|
1728
|
+
settings: blockProperties.settings,
|
|
1729
|
+
placement: toPlacement(resolvedPosition),
|
|
1730
|
+
grid: {
|
|
1731
|
+
columnSpan: columnSpan ?? 12,
|
|
1732
|
+
rowSpan: rowSpan ?? 1,
|
|
1733
|
+
...areaKey && parentContentKey ? { areaKey, parentContentKey } : {}
|
|
1631
1734
|
}
|
|
1632
|
-
nextTopLayout = insertResult.list;
|
|
1633
|
-
}
|
|
1634
|
-
const newValue = {
|
|
1635
|
-
...propValue,
|
|
1636
|
-
layout: { ...propValue.layout ?? {}, [layoutKey]: nextTopLayout },
|
|
1637
|
-
contentData: [...propValue.contentData ?? [], newContentEntry],
|
|
1638
|
-
settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
|
|
1639
|
-
expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1640
|
-
};
|
|
1641
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1642
|
-
id,
|
|
1643
|
-
properties: [{
|
|
1644
|
-
alias: propertyAlias,
|
|
1645
|
-
value: newValue,
|
|
1646
|
-
culture: cultureValue,
|
|
1647
|
-
segment: segmentValue
|
|
1648
|
-
}]
|
|
1649
|
-
});
|
|
1650
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1651
|
-
const validation = await validateDocumentState(id);
|
|
1652
|
-
const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
|
|
1653
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1654
|
-
return createToolResult({
|
|
1655
|
-
message,
|
|
1656
|
-
id,
|
|
1657
|
-
name: pageName,
|
|
1658
|
-
contentKey: newContentKey,
|
|
1659
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1660
|
-
validation
|
|
1661
1735
|
});
|
|
1736
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1737
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1662
1738
|
}
|
|
1663
1739
|
};
|
|
1664
1740
|
var add_blockgrid_block_default = withStandardDecorators(tool15);
|
|
@@ -1689,26 +1765,6 @@ var outputSchema16 = z.object({
|
|
|
1689
1765
|
previewUrl: previewUrlSchema,
|
|
1690
1766
|
validation: validationResultSchema
|
|
1691
1767
|
});
|
|
1692
|
-
function buildBlockTag(contentKey) {
|
|
1693
|
-
return `<umb-rte-block data-content-key="${contentKey}"></umb-rte-block>`;
|
|
1694
|
-
}
|
|
1695
|
-
function findAnchorTagRange(markup, anchorKey) {
|
|
1696
|
-
const re = new RegExp(`<umb-rte-block[^>]*data-content-key="${anchorKey}"[^>]*>\\s*</umb-rte-block>`, "i");
|
|
1697
|
-
const match = markup.match(re);
|
|
1698
|
-
if (!match || match.index === void 0) return null;
|
|
1699
|
-
return { start: match.index, end: match.index + match[0].length };
|
|
1700
|
-
}
|
|
1701
|
-
function insertMarkup(markup, newTag, mode, anchorKey) {
|
|
1702
|
-
if (mode === "append") return { ok: true, markup: `${markup}${newTag}` };
|
|
1703
|
-
if (mode === "prepend") return { ok: true, markup: `${newTag}${markup}` };
|
|
1704
|
-
if (!anchorKey) return { ok: false, reason: "missing anchor" };
|
|
1705
|
-
const range = findAnchorTagRange(markup, anchorKey);
|
|
1706
|
-
if (!range) return { ok: false, reason: "anchor not found" };
|
|
1707
|
-
if (mode === "before") {
|
|
1708
|
-
return { ok: true, markup: `${markup.slice(0, range.start)}${newTag}${markup.slice(range.start)}` };
|
|
1709
|
-
}
|
|
1710
|
-
return { ok: true, markup: `${markup.slice(0, range.end)}${newTag}${markup.slice(range.end)}` };
|
|
1711
|
-
}
|
|
1712
1768
|
var tool16 = {
|
|
1713
1769
|
name: "add-rte-block",
|
|
1714
1770
|
description: "Add a new block inside a Rich Text property on a page. Inserts the umb-rte-block tag in the markup at the chosen position and adds the matching content/settings entries. Use inspect-blocks first to find the propertyAlias and a sample contentTypeKey. For non-string property values inside the block (media pickers, content pickers, image cropper, slider, color, date, etc.) call get-property-value-template with the editor alias first to see the expected JSON shape. For BlockList use add-blocklist-block; for BlockGrid use add-blockgrid-block. Changes are saved as a draft, NOT published.",
|
|
@@ -1734,71 +1790,25 @@ var tool16 = {
|
|
|
1734
1790
|
const existingProp = (doc.values ?? []).find(
|
|
1735
1791
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1736
1792
|
);
|
|
1737
|
-
|
|
1738
|
-
markup: "",
|
|
1739
|
-
blocks: { layout: {}, contentData: [], settingsData: [], expose: [] }
|
|
1740
|
-
};
|
|
1741
|
-
if (existingProp && !isRteWithBlocks2(propValue)) {
|
|
1793
|
+
if (existingProp?.value && !isRteWithBlocks(existingProp.value)) {
|
|
1742
1794
|
return createToolResultError({ content: [{ type: "text", text: `Property '${propertyAlias}' on '${pageName}' is not a rich text with blocks. Use inspect-blocks to confirm the editor type, or add-blocklist-block / add-blockgrid-block as appropriate.` }], isError: true });
|
|
1743
1795
|
}
|
|
1744
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1745
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1746
|
-
let settingsEditorAliases = null;
|
|
1747
|
-
if (settingsTypeKey) {
|
|
1748
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1749
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1750
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1751
|
-
}
|
|
1752
|
-
const newContentKey = randomUUID();
|
|
1753
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1754
1796
|
const cultureValue = culture ?? null;
|
|
1755
1797
|
const segmentValue = segment ?? null;
|
|
1756
|
-
const
|
|
1757
|
-
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
if (!markupResult.ok) {
|
|
1768
|
-
return createToolResultError({ content: [{ type: "text", text: `Could not insert into markup \u2014 ${markupResult.reason}.` }], isError: true });
|
|
1769
|
-
}
|
|
1770
|
-
const newValue = {
|
|
1771
|
-
...propValue,
|
|
1772
|
-
markup: markupResult.markup,
|
|
1773
|
-
blocks: {
|
|
1774
|
-
...blocks,
|
|
1775
|
-
layout: { ...blocks.layout ?? {}, [layoutKey]: insertLayoutResult.list },
|
|
1776
|
-
contentData: [...blocks.contentData ?? [], newContentEntry],
|
|
1777
|
-
settingsData: newSettingsEntry ? [...blocks.settingsData ?? [], newSettingsEntry] : blocks.settingsData ?? [],
|
|
1778
|
-
expose: [...blocks.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1779
|
-
}
|
|
1780
|
-
};
|
|
1781
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1782
|
-
id,
|
|
1783
|
-
properties: [{
|
|
1784
|
-
alias: propertyAlias,
|
|
1785
|
-
value: newValue,
|
|
1786
|
-
culture: cultureValue,
|
|
1787
|
-
segment: segmentValue
|
|
1788
|
-
}]
|
|
1789
|
-
});
|
|
1790
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1791
|
-
const validation = await validateDocumentState(id);
|
|
1792
|
-
const baseMessage = `Added a new block to "${pageName}" rich text (saved, not published)`;
|
|
1793
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1794
|
-
return createToolResult({
|
|
1795
|
-
message,
|
|
1796
|
-
id,
|
|
1797
|
-
name: pageName,
|
|
1798
|
-
contentKey: newContentKey,
|
|
1799
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1800
|
-
validation
|
|
1798
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1799
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1800
|
+
const createResult = await chainCms("create-document-block", {
|
|
1801
|
+
documentId: id,
|
|
1802
|
+
propertyAlias,
|
|
1803
|
+
culture: cultureValue,
|
|
1804
|
+
segment: segmentValue,
|
|
1805
|
+
contentTypeKey,
|
|
1806
|
+
properties: blockProperties.properties,
|
|
1807
|
+
settings: blockProperties.settings,
|
|
1808
|
+
placement: toPlacement(resolvedPosition)
|
|
1801
1809
|
});
|
|
1810
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1811
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" rich text (saved, not published)`);
|
|
1802
1812
|
}
|
|
1803
1813
|
};
|
|
1804
1814
|
var add_rte_block_default = withStandardDecorators(tool16);
|
|
@@ -1853,12 +1863,84 @@ var tool17 = {
|
|
|
1853
1863
|
}
|
|
1854
1864
|
};
|
|
1855
1865
|
var edit_page_default = withStandardDecorators(tool17);
|
|
1866
|
+
var MAX_ENRICHED_BLOCKS = 50;
|
|
1867
|
+
var MAX_BLOCK_WALK_DEPTH = 20;
|
|
1868
|
+
function enrichBlockNotFoundError(errorResult, values, options = {}) {
|
|
1869
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
1870
|
+
const availableBlocks = problem.availableBlocks;
|
|
1871
|
+
if (!Array.isArray(availableBlocks)) return errorResult;
|
|
1872
|
+
const { propertyAlias, note } = options;
|
|
1873
|
+
const filtered = propertyAlias ? values.filter((v) => v.alias === propertyAlias) : values;
|
|
1874
|
+
const typeByKey = /* @__PURE__ */ new Map();
|
|
1875
|
+
for (const v of filtered) {
|
|
1876
|
+
const container = isRteWithBlocks(v.value) ? v.value.blocks : v.value;
|
|
1877
|
+
if (isBlockListOrGridValue(container)) {
|
|
1878
|
+
collectBlockEntryTypes(container, typeByKey, 0);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
const truncated = availableBlocks.length > MAX_ENRICHED_BLOCKS;
|
|
1882
|
+
const limitedBlocks = truncated ? availableBlocks.slice(0, MAX_ENRICHED_BLOCKS) : availableBlocks;
|
|
1883
|
+
const enrichedBlocks = limitedBlocks.map(
|
|
1884
|
+
(b) => b && typeof b === "object" && typeof b.key === "string" ? { ...b, contentTypeKey: typeByKey.get(b.key) ?? null } : b
|
|
1885
|
+
);
|
|
1886
|
+
return createToolResultError({
|
|
1887
|
+
...problem,
|
|
1888
|
+
availableBlocks: enrichedBlocks,
|
|
1889
|
+
...truncated ? { availableBlocksNote: `Showing ${MAX_ENRICHED_BLOCKS} of ${availableBlocks.length} available blocks \u2014 use inspect-blocks for the full list.` } : {},
|
|
1890
|
+
...note ? { note } : {}
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
function collectBlockEntryTypes(container, into, depth) {
|
|
1894
|
+
if (depth > MAX_BLOCK_WALK_DEPTH) return;
|
|
1895
|
+
for (const list of [container.contentData, container.settingsData]) {
|
|
1896
|
+
if (!Array.isArray(list)) continue;
|
|
1897
|
+
for (const block of list) {
|
|
1898
|
+
if (!block || typeof block !== "object") continue;
|
|
1899
|
+
const key = block.key;
|
|
1900
|
+
const contentTypeKey = block.contentTypeKey;
|
|
1901
|
+
if (typeof key === "string" && typeof contentTypeKey === "string") into.set(key, contentTypeKey);
|
|
1902
|
+
const nestedValues = block.values;
|
|
1903
|
+
if (!Array.isArray(nestedValues)) continue;
|
|
1904
|
+
for (const nested of nestedValues) {
|
|
1905
|
+
const nestedRaw = nested?.value;
|
|
1906
|
+
const nestedContainer = isRteWithBlocks(nestedRaw) ? nestedRaw.blocks : nestedRaw;
|
|
1907
|
+
if (isBlockListOrGridValue(nestedContainer)) {
|
|
1908
|
+
collectBlockEntryTypes(nestedContainer, into, depth + 1);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
var blockPropertyAliasSchema = z.string().regex(
|
|
1915
|
+
/^[A-Za-z_][A-Za-z0-9_]*$/,
|
|
1916
|
+
"Property alias must be a valid identifier (letters, digits, underscore; not starting with a digit)"
|
|
1917
|
+
);
|
|
1918
|
+
function classifyBlockUpdateResults(results, requestedCount, requestedAliases = [], expectedEntryCount = 1) {
|
|
1919
|
+
const list = results ?? [];
|
|
1920
|
+
const processedCount = list.reduce((sum, r) => sum + (r.updatedCount ?? 0) + (r.addedCount ?? 0), 0);
|
|
1921
|
+
const updatedEntryCount = list.filter((r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) > 0).length;
|
|
1922
|
+
const errors = list.flatMap((r) => r.errors ?? []);
|
|
1923
|
+
const warnings = list.flatMap((r) => r.warnings ?? []);
|
|
1924
|
+
const failureText = [...errors, ...warnings].join("; ");
|
|
1925
|
+
const unresolvedEntries = list.filter(
|
|
1926
|
+
(r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) === 0 && !r.errors?.length && !r.warnings?.length
|
|
1927
|
+
);
|
|
1928
|
+
const missingEntryCount = Math.max(0, expectedEntryCount - list.length);
|
|
1929
|
+
const unresolvedBlockCount = unresolvedEntries.length + missingEntryCount;
|
|
1930
|
+
const detail = [...errors, ...warnings, ...unresolvedEntries.map((r) => r.message).filter(Boolean)].join("; ") || list.map((r) => r.message).filter(Boolean).join("; ") || "no detail returned";
|
|
1931
|
+
const outcome = processedCount === 0 ? "failed" : processedCount < requestedCount ? "partial" : "clean";
|
|
1932
|
+
const failedFields = requestedAliases.filter((alias) => failureText.includes(`'${alias}'`));
|
|
1933
|
+
const savedFields = unresolvedBlockCount > 0 ? [] : requestedAliases.filter((alias) => !failedFields.includes(alias));
|
|
1934
|
+
return { outcome, processedCount, updatedEntryCount, detail, warnings, savedFields, failedFields, unresolvedBlockCount };
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
// src/umbraco-api/tools/content/put/edit-block.ts
|
|
1856
1938
|
var inputSchema18 = {
|
|
1857
1939
|
id: z.string().uuid().describe("The ID of the page containing the block"),
|
|
1858
1940
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'mainContent'). Use inspect-blocks to find this."),
|
|
1859
1941
|
contentKey: z.string().uuid().describe("The unique key of the block to edit. Use inspect-blocks to find this."),
|
|
1860
1942
|
values: z.array(z.object({
|
|
1861
|
-
alias:
|
|
1943
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
1862
1944
|
value: z.any().describe("The new value for the property")
|
|
1863
1945
|
})).describe("Properties to update within the block"),
|
|
1864
1946
|
blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
|
|
@@ -1872,7 +1954,8 @@ var outputSchema18 = z.object({
|
|
|
1872
1954
|
contentKey: z.string(),
|
|
1873
1955
|
updatedFields: z.array(z.string()),
|
|
1874
1956
|
previewUrl: previewUrlSchema,
|
|
1875
|
-
validation: validationResultSchema
|
|
1957
|
+
validation: validationResultSchema,
|
|
1958
|
+
warnings: z.array(z.string()).optional()
|
|
1876
1959
|
});
|
|
1877
1960
|
var tool18 = {
|
|
1878
1961
|
name: "edit-block",
|
|
@@ -1887,6 +1970,20 @@ var tool18 = {
|
|
|
1887
1970
|
const pageName = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
1888
1971
|
const fieldNames = values.map((v) => v.alias);
|
|
1889
1972
|
const resolvedBlockType = blockType ?? "content";
|
|
1973
|
+
let targetKey = contentKey;
|
|
1974
|
+
if (resolvedBlockType === "settings") {
|
|
1975
|
+
const rawValue = (docResult.data.values ?? []).find(
|
|
1976
|
+
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1977
|
+
)?.value;
|
|
1978
|
+
const container = isRteWithBlocks(rawValue) ? rawValue.blocks : rawValue;
|
|
1979
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
1980
|
+
if (!settingsKey) {
|
|
1981
|
+
return createToolResultError(
|
|
1982
|
+
`Block ${contentKey} in property "${propertyAlias}" has no settings entry, so its settings cannot be edited. Use inspect-blocks to check for a settingsKey, or omit blockType to edit the block's content.`
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
targetKey = settingsKey;
|
|
1986
|
+
}
|
|
1890
1987
|
const propsTuple = values.map((v) => ({ alias: v.alias, value: v.value }));
|
|
1891
1988
|
const updateResult = await chainCms("update-block-property", {
|
|
1892
1989
|
documentId: id,
|
|
@@ -1894,12 +1991,41 @@ var tool18 = {
|
|
|
1894
1991
|
culture: culture ?? null,
|
|
1895
1992
|
segment: segment ?? null,
|
|
1896
1993
|
updates: [{
|
|
1897
|
-
contentKey,
|
|
1994
|
+
contentKey: targetKey,
|
|
1898
1995
|
blockType: resolvedBlockType,
|
|
1899
1996
|
properties: propsTuple
|
|
1900
1997
|
}]
|
|
1901
1998
|
});
|
|
1902
|
-
if (!updateResult.ok)
|
|
1999
|
+
if (!updateResult.ok) {
|
|
2000
|
+
return enrichBlockNotFoundError(updateResult.errorResult, docResult.data.values ?? [], {
|
|
2001
|
+
propertyAlias,
|
|
2002
|
+
note: `A block's settingsKey (reported by inspect-blocks) is not a valid contentKey \u2014 pass the block's contentKey together with blockType: "settings" to edit its settings instead.`
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
const results = updateResult.data.results;
|
|
2006
|
+
if (!results || results.length === 0) {
|
|
2007
|
+
return createToolResultError(
|
|
2008
|
+
"update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
|
|
2012
|
+
if (classification.outcome === "failed") {
|
|
2013
|
+
return createToolResultError(
|
|
2014
|
+
`Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
if (classification.outcome === "partial") {
|
|
2018
|
+
return createToolResultError({
|
|
2019
|
+
message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
|
|
2020
|
+
savedFields: classification.savedFields,
|
|
2021
|
+
failedFields: classification.failedFields,
|
|
2022
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {},
|
|
2023
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {},
|
|
2024
|
+
validation: await validateDocumentState(id),
|
|
2025
|
+
previewUrl: await fetchPreviewUrl(id)
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
const warnings = classification.warnings;
|
|
1903
2029
|
const validation = await validateDocumentState(id);
|
|
1904
2030
|
const target = resolvedBlockType === "settings" ? "settings" : "content";
|
|
1905
2031
|
const baseMessage = `Updated ${fieldNames.length} field(s) in block ${target} on "${pageName}" (saved, not published)`;
|
|
@@ -1911,7 +2037,8 @@ var tool18 = {
|
|
|
1911
2037
|
contentKey,
|
|
1912
2038
|
updatedFields: fieldNames,
|
|
1913
2039
|
previewUrl: await fetchPreviewUrl(id),
|
|
1914
|
-
validation
|
|
2040
|
+
validation,
|
|
2041
|
+
...warnings.length ? { warnings } : {}
|
|
1915
2042
|
});
|
|
1916
2043
|
}
|
|
1917
2044
|
};
|
|
@@ -1964,10 +2091,9 @@ var tool19 = {
|
|
|
1964
2091
|
});
|
|
1965
2092
|
}
|
|
1966
2093
|
const cultureLabel = targetCulture ? ` (${targetCulture})` : "";
|
|
1967
|
-
const confirmed = await
|
|
2094
|
+
const confirmed = await requestApproval(
|
|
1968
2095
|
extra,
|
|
1969
|
-
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish
|
|
1970
|
-
{ title: "Confirm rename" }
|
|
2096
|
+
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`
|
|
1971
2097
|
);
|
|
1972
2098
|
if (!confirmed) {
|
|
1973
2099
|
return createToolResult({
|
|
@@ -2254,68 +2380,26 @@ var outputSchema24 = z.object({
|
|
|
2254
2380
|
previewUrl: previewUrlSchema,
|
|
2255
2381
|
validation: validationResultSchema
|
|
2256
2382
|
});
|
|
2257
|
-
function
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
}
|
|
2262
|
-
for (let i = 0; i < items.length; i++) {
|
|
2263
|
-
const item = items[i];
|
|
2264
|
-
if (!Array.isArray(item.areas)) continue;
|
|
2265
|
-
for (let aIdx = 0; aIdx < item.areas.length; aIdx++) {
|
|
2266
|
-
const inner = findAndRemoveGridItem(item.areas[aIdx].items ?? [], contentKey);
|
|
2267
|
-
if (inner.found) {
|
|
2268
|
-
const updatedAreas = item.areas.slice();
|
|
2269
|
-
updatedAreas[aIdx] = { ...item.areas[aIdx], items: inner.nextItems };
|
|
2270
|
-
const nextItems = items.slice();
|
|
2271
|
-
nextItems[i] = { ...item, areas: updatedAreas };
|
|
2272
|
-
return { found: true, doomedSettingsKey: inner.doomedSettingsKey, nextItems };
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
}
|
|
2276
|
-
return { found: false };
|
|
2383
|
+
function gridContainsBlock(items, contentKey) {
|
|
2384
|
+
return items.some(
|
|
2385
|
+
(item) => item.contentKey === contentKey || (item.areas ?? []).some((area) => gridContainsBlock(area.items ?? [], contentKey))
|
|
2386
|
+
);
|
|
2277
2387
|
}
|
|
2278
|
-
function
|
|
2388
|
+
function locateBlock(propValue, editorAlias, propertyAlias, contentKey, pageName) {
|
|
2279
2389
|
const notFound = { ok: false, errorText: `Block '${contentKey}' was not found in property '${propertyAlias}'.` };
|
|
2280
2390
|
const draftSuffix = "Will be saved as a draft, not published.";
|
|
2281
|
-
if (
|
|
2282
|
-
const
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
if (!doomed) return notFound;
|
|
2286
|
-
return {
|
|
2287
|
-
ok: true,
|
|
2288
|
-
newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomed.settingsKey),
|
|
2289
|
-
confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}`
|
|
2290
|
-
};
|
|
2391
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockList") {
|
|
2392
|
+
const layoutList = propValue.layout?.["Umbraco.BlockList"] ?? [];
|
|
2393
|
+
if (!layoutList.some((e) => e.contentKey === contentKey)) return notFound;
|
|
2394
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}` };
|
|
2291
2395
|
}
|
|
2292
|
-
if (
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
if (!removed.found) return notFound;
|
|
2296
|
-
return {
|
|
2297
|
-
ok: true,
|
|
2298
|
-
newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, removed.nextItems, removed.doomedSettingsKey),
|
|
2299
|
-
confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}`
|
|
2300
|
-
};
|
|
2396
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockGrid") {
|
|
2397
|
+
if (!gridContainsBlock(propValue.layout?.["Umbraco.BlockGrid"] ?? [], contentKey)) return notFound;
|
|
2398
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}` };
|
|
2301
2399
|
}
|
|
2302
|
-
if (
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
const layoutList = blocks.layout?.[layoutKey] ?? [];
|
|
2306
|
-
const inContent = (blocks.contentData ?? []).some((e) => e.key === contentKey);
|
|
2307
|
-
if (!inContent) return notFound;
|
|
2308
|
-
const doomedSettingsKey = layoutList.find((e) => e.contentKey === contentKey)?.settingsKey;
|
|
2309
|
-
const tagRe = new RegExp(`<umb-rte-block[^>]*data-content-key="${contentKey}"[^>]*>\\s*</umb-rte-block>`, "gi");
|
|
2310
|
-
return {
|
|
2311
|
-
ok: true,
|
|
2312
|
-
newValue: {
|
|
2313
|
-
...propValue,
|
|
2314
|
-
markup: (propValue.markup ?? "").replace(tagRe, ""),
|
|
2315
|
-
blocks: removeBlockFromContainer(blocks, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomedSettingsKey)
|
|
2316
|
-
},
|
|
2317
|
-
confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}`
|
|
2318
|
-
};
|
|
2400
|
+
if (isRteWithBlocks(propValue)) {
|
|
2401
|
+
if (!(propValue.blocks.contentData ?? []).some((e) => e.key === contentKey)) return notFound;
|
|
2402
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}` };
|
|
2319
2403
|
}
|
|
2320
2404
|
return { ok: false, errorText: `Property '${propertyAlias}' on '${pageName}' is not a block-bearing property (BlockList, BlockGrid, or Rich Text with blocks). Use inspect-blocks to confirm.` };
|
|
2321
2405
|
}
|
|
@@ -2340,29 +2424,22 @@ var tool24 = {
|
|
|
2340
2424
|
isError: true
|
|
2341
2425
|
});
|
|
2342
2426
|
}
|
|
2343
|
-
const
|
|
2344
|
-
if (!
|
|
2345
|
-
return createToolResultError({ content: [{ type: "text", text:
|
|
2427
|
+
const location = locateBlock(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
|
|
2428
|
+
if (!location.ok) {
|
|
2429
|
+
return createToolResultError({ content: [{ type: "text", text: location.errorText }], isError: true });
|
|
2346
2430
|
}
|
|
2347
|
-
if (!await requestApproval(extra,
|
|
2431
|
+
if (!await requestApproval(extra, location.confirmMessage)) {
|
|
2348
2432
|
return createToolResultError({ content: [{ type: "text", text: "Cancelled by user." }], isError: true });
|
|
2349
2433
|
}
|
|
2350
|
-
const
|
|
2351
|
-
id,
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
const baseMessage = `Removed block from "${pageName}" (saved, not published)`;
|
|
2357
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
2358
|
-
return createToolResult({
|
|
2359
|
-
message,
|
|
2360
|
-
id,
|
|
2361
|
-
name: pageName,
|
|
2362
|
-
contentKey,
|
|
2363
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
2364
|
-
validation
|
|
2434
|
+
const deleteResult = await chainCms("delete-document-block", {
|
|
2435
|
+
documentId: id,
|
|
2436
|
+
propertyAlias,
|
|
2437
|
+
culture: culture ?? null,
|
|
2438
|
+
segment: segment ?? null,
|
|
2439
|
+
contentKey
|
|
2365
2440
|
});
|
|
2441
|
+
if (!deleteResult.ok) return deleteResult.errorResult;
|
|
2442
|
+
return buildBlockWriteResult(id, pageName, contentKey, `Removed block from "${pageName}" (saved, not published)`);
|
|
2366
2443
|
}
|
|
2367
2444
|
};
|
|
2368
2445
|
var delete_block_default = withStandardDecorators(tool24);
|
|
@@ -2519,7 +2596,7 @@ function mergeValues(existing, updates) {
|
|
|
2519
2596
|
}
|
|
2520
2597
|
var tool27 = {
|
|
2521
2598
|
name: "save-and-publish",
|
|
2522
|
-
description: "Save property changes and publish a content page
|
|
2599
|
+
description: "Save property changes and publish a content page \u2014 mirrors the 'Save and publish' button in the Umbraco backoffice. If `values` is provided the changes are saved first; then the page is published. This is a single atomic operation when the connected Umbraco instance supports it (17.6+), otherwise a two-call save-then-publish sequence is used. Optionally publish descendants. Call get-page or get-document-type first to discover valid property aliases.",
|
|
2523
2600
|
inputSchema: inputSchema27,
|
|
2524
2601
|
outputSchema: outputSchema27,
|
|
2525
2602
|
slices: ["publish", "update"],
|
|
@@ -2579,20 +2656,53 @@ var tool27 = {
|
|
|
2579
2656
|
}
|
|
2580
2657
|
} else {
|
|
2581
2658
|
const mergedValues = mergeValues(doc.values ?? [], values ?? []);
|
|
2582
|
-
const
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2659
|
+
const variants = (doc.variants ?? []).map((v) => ({
|
|
2660
|
+
culture: v.culture ?? null,
|
|
2661
|
+
segment: v.segment ?? null,
|
|
2662
|
+
name: v.name
|
|
2663
|
+
}));
|
|
2664
|
+
if (await isCmsToolAvailable("update-and-publish-document")) {
|
|
2665
|
+
const updateAndPublishResult = await chainCms("update-and-publish-document", {
|
|
2666
|
+
id,
|
|
2667
|
+
data: {
|
|
2668
|
+
values: mergedValues,
|
|
2669
|
+
variants,
|
|
2670
|
+
template: doc.template ?? null,
|
|
2671
|
+
culturesToPublish: variantCultures.filter((c) => c !== null)
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2675
|
+
} else {
|
|
2676
|
+
const updateResult = await chainCms("update-document", {
|
|
2677
|
+
id,
|
|
2678
|
+
data: {
|
|
2679
|
+
values: mergedValues,
|
|
2680
|
+
variants,
|
|
2681
|
+
template: doc.template ?? null
|
|
2682
|
+
}
|
|
2683
|
+
});
|
|
2684
|
+
if (!updateResult.ok) return updateResult.errorResult;
|
|
2685
|
+
const publishResult = await chainCms("publish-document", {
|
|
2686
|
+
id,
|
|
2687
|
+
data: {
|
|
2688
|
+
publishSchedules: variantCultures.map((c) => ({ culture: c }))
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
if (!publishResult.ok) {
|
|
2692
|
+
if (saved) {
|
|
2693
|
+
return createToolResult({
|
|
2694
|
+
message: `Saved ${fieldNames.length} field(s) on "${pageName}" but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
2695
|
+
id,
|
|
2696
|
+
name: pageName,
|
|
2697
|
+
saved: true,
|
|
2698
|
+
published: false,
|
|
2699
|
+
updatedFields: fieldNames,
|
|
2700
|
+
publishedUrls: []
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
return publishResult.errorResult;
|
|
2593
2704
|
}
|
|
2594
|
-
}
|
|
2595
|
-
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2705
|
+
}
|
|
2596
2706
|
}
|
|
2597
2707
|
if (!includeDescendants) {
|
|
2598
2708
|
const verifyError = await verifyDocumentPublished(id, variantCultures);
|
|
@@ -3444,12 +3554,7 @@ function validateBulkIds(ids) {
|
|
|
3444
3554
|
function parseBulkError(err) {
|
|
3445
3555
|
if (err === null || err === void 0) return "Unknown error";
|
|
3446
3556
|
if (typeof err === "object") {
|
|
3447
|
-
|
|
3448
|
-
const sc = asRecord.structuredContent;
|
|
3449
|
-
if (sc !== null && sc !== void 0 && typeof sc === "object") {
|
|
3450
|
-
return sc;
|
|
3451
|
-
}
|
|
3452
|
-
return err;
|
|
3557
|
+
return extractInnerProblemDetails(err);
|
|
3453
3558
|
}
|
|
3454
3559
|
if (typeof err === "string") {
|
|
3455
3560
|
try {
|
|
@@ -3718,6 +3823,15 @@ var tool46 = {
|
|
|
3718
3823
|
slices: ["list"],
|
|
3719
3824
|
annotations: { readOnlyHint: true },
|
|
3720
3825
|
handler: async ({ parentId, take, skip }) => {
|
|
3826
|
+
const accessCheck = await checkSettingsAccess();
|
|
3827
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
3828
|
+
if (!accessCheck.hasAccess) {
|
|
3829
|
+
return createToolResultError({
|
|
3830
|
+
status: 403,
|
|
3831
|
+
title: "Settings access required",
|
|
3832
|
+
detail: "Listing blueprints requires the signed-in Umbraco user to have access to the Settings section. Grant Settings-section access to the user's group in the Umbraco backoffice (Users \u2192 [group] \u2192 Sections), then retry."
|
|
3833
|
+
});
|
|
3834
|
+
}
|
|
3721
3835
|
const cursor = buildChainedCursor(skip, take);
|
|
3722
3836
|
const result = parentId ? await chainCms("get-document-blueprint-children", { parentId, cursor }) : await chainCms("get-document-blueprint-root", { cursor });
|
|
3723
3837
|
if (!result.ok) return result.errorResult;
|
|
@@ -5251,7 +5365,7 @@ var inputSchema73 = {
|
|
|
5251
5365
|
contentTypeKey: z.string().uuid().describe("The block element type key to target. Use inspect-blocks to find this."),
|
|
5252
5366
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'contentRows'). Use inspect-blocks to find this."),
|
|
5253
5367
|
values: z.array(z.object({
|
|
5254
|
-
alias:
|
|
5368
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
5255
5369
|
value: z.any().describe("The new value for the property")
|
|
5256
5370
|
})).min(1).describe("Properties to update on every matching block"),
|
|
5257
5371
|
culture: z.string().nullable().optional().describe("Culture code if the document property is variant"),
|
|
@@ -5267,7 +5381,8 @@ var outputSchema73 = z.object({
|
|
|
5267
5381
|
previousVersionId: z.string().optional(),
|
|
5268
5382
|
error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
|
|
5269
5383
|
previewUrl: previewUrlSchema.optional(),
|
|
5270
|
-
validation: validationResultSchema.optional()
|
|
5384
|
+
validation: validationResultSchema.optional(),
|
|
5385
|
+
warnings: z.array(z.string()).optional()
|
|
5271
5386
|
})),
|
|
5272
5387
|
successCount: z.number(),
|
|
5273
5388
|
failureCount: z.number(),
|
|
@@ -5311,6 +5426,7 @@ var tool73 = {
|
|
|
5311
5426
|
});
|
|
5312
5427
|
const items = [];
|
|
5313
5428
|
const pageBlocks = /* @__PURE__ */ new Map();
|
|
5429
|
+
const docValuesByItem = /* @__PURE__ */ new Map();
|
|
5314
5430
|
for (const id of ids) {
|
|
5315
5431
|
const docResult = await chainCms("get-document-by-id", { id });
|
|
5316
5432
|
if (!docResult.ok) continue;
|
|
@@ -5324,6 +5440,7 @@ var tool73 = {
|
|
|
5324
5440
|
const currentVersionId = versionData?.items?.[0]?.id ?? "";
|
|
5325
5441
|
items.push({ id, name, currentVersionId });
|
|
5326
5442
|
pageBlocks.set(id, findMatchingBlocks(doc, propertyAlias, contentTypeKey));
|
|
5443
|
+
docValuesByItem.set(id, doc.values ?? []);
|
|
5327
5444
|
}
|
|
5328
5445
|
if (items.length === 0) {
|
|
5329
5446
|
return createToolResult({
|
|
@@ -5396,28 +5513,68 @@ Changes will be saved but not published.`;
|
|
|
5396
5513
|
updates
|
|
5397
5514
|
});
|
|
5398
5515
|
if (!updateResult.ok) {
|
|
5516
|
+
const enriched = enrichBlockNotFoundError(
|
|
5517
|
+
updateResult.errorResult,
|
|
5518
|
+
docValuesByItem.get(item.id) ?? [],
|
|
5519
|
+
{ propertyAlias }
|
|
5520
|
+
);
|
|
5399
5521
|
results.push({
|
|
5400
5522
|
id: item.id,
|
|
5401
5523
|
name: item.name,
|
|
5402
5524
|
success: false,
|
|
5403
5525
|
blocksUpdated: 0,
|
|
5404
5526
|
previousVersionId: item.currentVersionId || void 0,
|
|
5405
|
-
error: parseBulkError(
|
|
5527
|
+
error: parseBulkError(enriched)
|
|
5406
5528
|
});
|
|
5407
5529
|
stopped = true;
|
|
5408
5530
|
} else {
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5531
|
+
const blockResults = updateResult.data.results;
|
|
5532
|
+
if (!blockResults || blockResults.length === 0) {
|
|
5533
|
+
results.push({
|
|
5534
|
+
id: item.id,
|
|
5535
|
+
name: item.name,
|
|
5536
|
+
success: false,
|
|
5537
|
+
blocksUpdated: 0,
|
|
5538
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5539
|
+
error: "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
5540
|
+
});
|
|
5541
|
+
stopped = true;
|
|
5542
|
+
} else {
|
|
5543
|
+
const classification = classifyBlockUpdateResults(blockResults, blocks.length * values.length, fieldNames, blocks.length);
|
|
5544
|
+
if (classification.outcome === "clean") {
|
|
5545
|
+
totalBlocksUpdated += blocks.length;
|
|
5546
|
+
results.push({
|
|
5547
|
+
id: item.id,
|
|
5548
|
+
name: item.name,
|
|
5549
|
+
success: true,
|
|
5550
|
+
blocksUpdated: blocks.length,
|
|
5551
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5552
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5553
|
+
});
|
|
5554
|
+
} else {
|
|
5555
|
+
totalBlocksUpdated += classification.updatedEntryCount;
|
|
5556
|
+
const totalProperties = blocks.length * values.length;
|
|
5557
|
+
results.push({
|
|
5558
|
+
id: item.id,
|
|
5559
|
+
name: item.name,
|
|
5560
|
+
success: false,
|
|
5561
|
+
blocksUpdated: classification.updatedEntryCount,
|
|
5562
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5563
|
+
error: classification.outcome === "failed" ? `Block update failed: ${classification.detail}` : {
|
|
5564
|
+
message: `Block update partially failed: ${classification.processedCount} of ${totalProperties} propert${totalProperties === 1 ? "y" : "ies"} saved, across ${classification.updatedEntryCount} of ${blockResults.length} block(s)` + (classification.unresolvedBlockCount > 0 ? ` (${classification.unresolvedBlockCount} matched block(s) could not be located \u2014 likely changed concurrently; rerun this tool to retarget them)` : "") + ` \u2014 ${classification.detail}`,
|
|
5565
|
+
savedFields: classification.savedFields,
|
|
5566
|
+
failedFields: classification.failedFields,
|
|
5567
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {}
|
|
5568
|
+
},
|
|
5569
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5570
|
+
});
|
|
5571
|
+
stopped = true;
|
|
5572
|
+
}
|
|
5573
|
+
}
|
|
5417
5574
|
}
|
|
5418
5575
|
}
|
|
5419
5576
|
for (const row of results) {
|
|
5420
|
-
if (
|
|
5577
|
+
if (row.blocksUpdated === 0) continue;
|
|
5421
5578
|
row.validation = await validateDocumentState(row.id);
|
|
5422
5579
|
row.previewUrl = await fetchPreviewUrl(row.id);
|
|
5423
5580
|
}
|
|
@@ -5502,12 +5659,10 @@ var tool74 = {
|
|
|
5502
5659
|
var search_members_default = withStandardDecorators(tool74);
|
|
5503
5660
|
|
|
5504
5661
|
// src/umbraco-api/tools/member/sensitive-data-access.ts
|
|
5505
|
-
|
|
5506
|
-
async function hasSensitiveDataAccess() {
|
|
5507
|
-
if (cachedAccess !== void 0) return cachedAccess;
|
|
5662
|
+
async function checkSensitiveDataAccess() {
|
|
5508
5663
|
const result = await chainCms("get-user-current", {});
|
|
5509
|
-
|
|
5510
|
-
return
|
|
5664
|
+
if (!result.ok) return result;
|
|
5665
|
+
return { ok: true, hasAccess: result.data.hasAccessToSensitiveData ?? false };
|
|
5511
5666
|
}
|
|
5512
5667
|
|
|
5513
5668
|
// src/umbraco-api/tools/member/get/get-member.ts
|
|
@@ -5545,7 +5700,8 @@ var tool75 = {
|
|
|
5545
5700
|
const result = await chainCms("get-member", { id });
|
|
5546
5701
|
if (!result.ok) return result.errorResult;
|
|
5547
5702
|
const data = result.data;
|
|
5548
|
-
const
|
|
5703
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5704
|
+
const accessible = accessCheck.ok && accessCheck.hasAccess;
|
|
5549
5705
|
return createToolResult({
|
|
5550
5706
|
id: data.id ?? id,
|
|
5551
5707
|
name: data.variants?.[0]?.name ?? "Unknown",
|
|
@@ -5704,12 +5860,16 @@ var tool78 = {
|
|
|
5704
5860
|
slices: ["update"],
|
|
5705
5861
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
5706
5862
|
handler: async ({ id, name, email, username, newPassword, isTwoFactorEnabled, isApproved, isLockedOut, groups, values }, extra) => {
|
|
5707
|
-
if (
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5863
|
+
if (isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) {
|
|
5864
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5865
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
5866
|
+
if (!accessCheck.hasAccess) {
|
|
5867
|
+
return createToolResultError({
|
|
5868
|
+
status: 403,
|
|
5869
|
+
title: "Sensitive Data access required",
|
|
5870
|
+
detail: "Updating isApproved, isLockedOut, or isTwoFactorEnabled requires the signed-in Umbraco user to be in the built-in Sensitive Data user group (group key 8C6AD70F-D307-4E4A-AF58-72C2E4E9439D). In the Umbraco backoffice, edit the user's User group under Users and add the Sensitive Data group, then retry. Other update-member fields (name, email, username, groups, values, newPassword) are not affected."
|
|
5871
|
+
});
|
|
5872
|
+
}
|
|
5713
5873
|
}
|
|
5714
5874
|
const memberResult = await chainCms("get-member", { id });
|
|
5715
5875
|
if (!memberResult.ok) return memberResult.errorResult;
|